diff --git "a/partition_77.json" "b/partition_77.json" new file mode 100644--- /dev/null +++ "b/partition_77.json" @@ -0,0 +1,67289 @@ +[ + { + "hash": "606c857c8e5c9ee844a58dd5919d14a6eaff191e", + "msg": "Prefer xxx/setup.py file over xxx/setup_xxx.py when both exist.", + "author": { + "name": "Pearu Peterson", + "email": "pearu.peterson@gmail.com" + }, + "committer": { + "name": "Pearu Peterson", + "email": "pearu.peterson@gmail.com" + }, + "author_date": "2006-01-26T22:17:44+00:00", + "author_timezone": 0, + "committer_date": "2006-01-26T22:17:44+00:00", + "committer_timezone": 0, + "branches": [ + "main" + ], + "in_main_branch": true, + "merge": false, + "parents": [ + "e59bb826219298274ca8c2a87f94e83b52a6175c" + ], + "project_name": "repo_copy", + "project_path": "/tmp/tmppy2o86q9/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/distutils/misc_util.py", + "new_path": "numpy/distutils/misc_util.py", + "filename": "misc_util.py", + "extension": "py", + "change_type": "MODIFY", + "diff": "@@ -381,9 +381,10 @@ def get_subpackage(self,subpackage_name,subpackage_path=None):\n subpackage_path = os.path.join(*([subpackage_path]+l[:-1]))\n subpackage_path = self._fix_paths([subpackage_path])[0]\n \n- setup_py = os.path.join(subpackage_path,'setup_%s.py' % (subpackage_name))\n+ setup_py = os.path.join(subpackage_path,'setup.py')\n if not os.path.isfile(setup_py):\n- setup_py = os.path.join(subpackage_path,'setup.py')\n+ setup_py = os.path.join(subpackage_path,'setup_%s.py' % (subpackage_name))\n+\n if not os.path.isfile(setup_py):\n print 'Assuming default configuration '\\\n '(%s/{setup_%s,setup}.py was not found)' \\\n", + "added_lines": 3, + "deleted_lines": 2, + "source_code": "import os\nimport re\nimport sys\nimport imp\nimport copy\nimport types\nimport glob\n\n__all__ = ['Configuration', 'get_numpy_include_dirs', 'default_config_dict',\n 'dict_append', 'appendpath', 'generate_config_py',\n 'generate_svn_version_py', 'get_cmd', 'allpath',\n 'terminal_has_colors', 'red_text', 'green_text', 'yellow_text',\n 'blue_text', 'cyan_text', 'cyg2win32', 'all_strings',\n 'has_f_sources', 'has_cxx_sources', 'filter_sources',\n 'get_dependencies', 'is_local_src_dir', 'get_ext_source_files',\n 'get_script_files', 'get_lib_source_files', 'get_data_files',\n 'dot_join', 'get_frame']\n\ndef allpath(name):\n \"Convert a /-separated pathname to one using the OS's path separator.\"\n splitted = name.split('/')\n return os.path.join(*splitted)\n\ndef get_path(mod_name,parent_path=None):\n \"\"\" Return path of the module.\n\n Returned path is relative to parent_path when given,\n otherwise it is absolute path.\n \"\"\"\n if mod_name == '__main__':\n d = os.path.abspath('.')\n elif mod_name == '__builtin__':\n #builtin if/then added by Pearu for use in core.run_setup. \n d = os.path.dirname(os.path.abspath(sys.argv[0]))\n else:\n __import__(mod_name)\n mod = sys.modules[mod_name]\n file = mod.__file__\n d = os.path.dirname(os.path.abspath(file))\n if parent_path is not None:\n pd = os.path.abspath(parent_path)\n if pd==d[:len(pd)]:\n d = d[len(pd)+1:]\n return d or '.'\n\n# Hooks for colored terminal output.\n# See also http://www.livinglogic.de/Python/ansistyle\ndef terminal_has_colors():\n if sys.platform=='cygwin' and not os.environ.has_key('USE_COLOR'):\n # Avoid importing curses that causes illegal operation\n # with a message:\n # PYTHON2 caused an invalid page fault in\n # module CYGNURSES7.DLL as 015f:18bbfc28\n # Details: Python 2.3.3 [GCC 3.3.1 (cygming special)]\n # ssh to Win32 machine from debian\n # curses.version is 2.2\n # CYGWIN_98-4.10, release 1.5.7(0.109/3/2))\n return 0\n if hasattr(sys.stdout,'isatty') and sys.stdout.isatty(): \n try:\n import curses\n curses.setupterm()\n if (curses.tigetnum(\"colors\") >= 0\n and curses.tigetnum(\"pairs\") >= 0\n and ((curses.tigetstr(\"setf\") is not None \n and curses.tigetstr(\"setb\") is not None) \n or (curses.tigetstr(\"setaf\") is not None\n and curses.tigetstr(\"setab\") is not None)\n or curses.tigetstr(\"scp\") is not None)):\n return 1\n except Exception,msg:\n pass\n return 0\n\nif terminal_has_colors():\n def red_text(s): return '\\x1b[31m%s\\x1b[0m'%s\n def green_text(s): return '\\x1b[32m%s\\x1b[0m'%s\n def yellow_text(s): return '\\x1b[33m%s\\x1b[0m'%s\n def blue_text(s): return '\\x1b[34m%s\\x1b[0m'%s\n def cyan_text(s): return '\\x1b[35m%s\\x1b[0m'%s\nelse:\n def red_text(s): return s\n def green_text(s): return s\n def yellow_text(s): return s\n def cyan_text(s): return s\n def blue_text(s): return s\n\n#########################\n\ndef cyg2win32(path):\n if sys.platform=='cygwin' and path.startswith('/cygdrive'):\n path = path[10] + ':' + os.path.normcase(path[11:])\n return path\n\n#########################\n\n#XXX need support for .C that is also C++\ncxx_ext_match = re.compile(r'.*[.](cpp|cxx|cc)\\Z',re.I).match\nfortran_ext_match = re.compile(r'.*[.](f90|f95|f77|for|ftn|f)\\Z',re.I).match\nf90_ext_match = re.compile(r'.*[.](f90|f95)\\Z',re.I).match\nf90_module_name_match = re.compile(r'\\s*module\\s*(?P[\\w_]+)',re.I).match\ndef _get_f90_modules(source):\n \"\"\" Return a list of Fortran f90 module names that\n given source file defines.\n \"\"\"\n if not f90_ext_match(source):\n return []\n modules = []\n f = open(source,'r')\n f_readlines = getattr(f,'xreadlines',f.readlines)\n for line in f_readlines():\n m = f90_module_name_match(line)\n if m:\n name = m.group('name')\n modules.append(name)\n # break # XXX can we assume that there is one module per file?\n f.close()\n return modules\n\ndef all_strings(lst):\n \"\"\" Return True if all items in lst are string objects. \"\"\"\n for item in lst:\n if type(item) is not types.StringType:\n return False\n return True\n\ndef has_f_sources(sources):\n \"\"\" Return True if sources contains Fortran files \"\"\"\n for source in sources:\n if fortran_ext_match(source):\n return True\n return False\n\ndef has_cxx_sources(sources):\n \"\"\" Return True if sources contains C++ files \"\"\"\n for source in sources:\n if cxx_ext_match(source):\n return True\n return False\n\ndef filter_sources(sources):\n \"\"\" Return four lists of filenames containing\n C, C++, Fortran, and Fortran 90 module sources,\n respectively.\n \"\"\"\n c_sources = []\n cxx_sources = []\n f_sources = []\n fmodule_sources = []\n for source in sources:\n if fortran_ext_match(source):\n modules = _get_f90_modules(source)\n if modules:\n fmodule_sources.append(source)\n else:\n f_sources.append(source)\n elif cxx_ext_match(source):\n cxx_sources.append(source)\n else:\n c_sources.append(source) \n return c_sources, cxx_sources, f_sources, fmodule_sources\n\n\ndef _get_headers(directory_list):\n # get *.h files from list of directories\n headers = []\n for dir in directory_list:\n head = glob.glob(os.path.join(dir,\"*.h\")) #XXX: *.hpp files??\n headers.extend(head)\n return headers\n\ndef _get_directories(list_of_sources):\n # get unique directories from list of sources.\n direcs = []\n for file in list_of_sources:\n dir = os.path.split(file)\n if dir[0] != '' and not dir[0] in direcs:\n direcs.append(dir[0])\n return direcs\n\ndef get_dependencies(sources):\n #XXX scan sources for include statements\n return _get_headers(_get_directories(sources))\n\ndef is_local_src_dir(directory):\n \"\"\" Return true if directory is local directory.\n \"\"\"\n if type(directory) is not type(''):\n return False\n abs_dir = os.path.abspath(directory)\n c = os.path.commonprefix([os.getcwd(),abs_dir])\n new_dir = abs_dir[len(c):].split(os.sep)\n if new_dir and not new_dir[0]:\n new_dir = new_dir[1:]\n if new_dir and new_dir[0]=='build':\n return False\n new_dir = os.sep.join(new_dir)\n return os.path.isdir(new_dir)\n\ndef _gsf_visit_func(filenames,dirname,names):\n if os.path.basename(dirname) in ['CVS','.svn','build']:\n names[:] = []\n return\n for name in names:\n if name[-1] in \"~#\":\n continue\n fullname = os.path.join(dirname,name)\n ext = os.path.splitext(fullname)[1]\n if ext and ext in ['.pyc','.o']:\n continue\n if os.path.isfile(fullname):\n filenames.append(fullname)\n\ndef get_ext_source_files(ext):\n # Get sources and any include files in the same directory.\n filenames = []\n sources = filter(lambda s:type(s) is types.StringType,ext.sources)\n filenames.extend(sources)\n filenames.extend(get_dependencies(sources))\n for d in ext.depends:\n if is_local_src_dir(d):\n os.path.walk(d,_gsf_visit_func,filenames)\n elif os.path.isfile(d):\n filenames.append(d)\n return filenames\n\ndef get_script_files(scripts):\n scripts = filter(lambda s:type(s) is types.StringType,scripts)\n return scripts\n\ndef get_lib_source_files(lib):\n filenames = []\n sources = lib[1].get('sources',[])\n sources = filter(lambda s:type(s) is types.StringType,sources)\n filenames.extend(sources)\n filenames.extend(get_dependencies(sources))\n depends = lib[1].get('depends',[])\n for d in depends:\n if is_local_src_dir(d):\n os.path.walk(d,_gsf_visit_func,filenames)\n elif os.path.isfile(d):\n filenames.append(d)\n return filenames\n\ndef get_data_files(data):\n if type(data) is types.StringType:\n return [data]\n sources = data[1]\n filenames = []\n for s in sources:\n if callable(s):\n s = s()\n if s is None:\n continue\n if is_local_src_dir(s):\n os.path.walk(s,_gsf_visit_func,filenames)\n elif type(s) is type(''):\n if os.path.isfile(s):\n filenames.append(s)\n else:\n print 'Not existing data file:',s\n else:\n raise TypeError,`s`\n return filenames\n\ndef dot_join(*args):\n return '.'.join(filter(None,args))\n\ndef get_frame(level=0):\n try:\n return sys._getframe(level+1)\n except AttributeError:\n frame = sys.exc_info()[2].tb_frame\n for i in range(level+1):\n frame = frame.f_back\n return frame\n\n######################\n\nclass Configuration:\n\n _list_keys = ['packages','ext_modules','data_files','include_dirs',\n 'libraries','headers','scripts','py_modules']\n _dict_keys = ['package_dir']\n\n numpy_include_dirs = []\n\n def __init__(self,\n package_name=None,\n parent_name=None,\n top_path=None,\n package_path=None,\n **attrs):\n \"\"\" Construct configuration instance of a package.\n \"\"\"\n self.name = dot_join(parent_name, package_name)\n\n caller_frame = get_frame(1)\n caller_name = eval('__name__',caller_frame.f_globals,caller_frame.f_locals)\n \n self.local_path = get_path(caller_name, top_path)\n if top_path is None:\n top_path = self.local_path\n if package_path is None:\n package_path = self.local_path\n elif os.path.isdir(os.path.join(self.local_path,package_path)):\n package_path = os.path.join(self.local_path,package_path)\n assert os.path.isdir(package_path),`package_path`\n self.top_path = top_path\n\n self.list_keys = copy.copy(self._list_keys)\n self.dict_keys = copy.copy(self._dict_keys)\n\n for n in self.list_keys:\n setattr(self,n,copy.copy(attrs.get(n,[])))\n\n for n in self.dict_keys:\n setattr(self,n,copy.copy(attrs.get(n,{})))\n\n known_keys = self.list_keys + self.dict_keys\n self.extra_keys = []\n for n in attrs.keys():\n if n in known_keys:\n continue\n a = attrs[n]\n setattr(self,n,a)\n if type(a) is types.ListType:\n self.list_keys.append(n)\n elif type(a) is types.DictType:\n self.dict_keys.append(n)\n else:\n self.extra_keys.append(n)\n\n if os.path.exists(os.path.join(package_path,'__init__.py')):\n self.packages.append(self.name)\n self.package_dir[self.name] = package_path \n return\n\n def todict(self):\n \"\"\" Return configuration distionary suitable for passing\n to distutils.core.setup() function.\n \"\"\"\n d = {}\n for n in self.list_keys + self.dict_keys + self.extra_keys:\n a = getattr(self,n)\n if a:\n d[n] = a\n if self.name:\n d['name'] = self.name\n return d\n\n def __dict__(self):\n return self.todict()\n\n def get_distribution(self):\n import distutils.core\n dist = distutils.core._setup_distribution \n return dist\n\n def get_subpackage(self,subpackage_name,subpackage_path=None):\n \"\"\" Return subpackage configuration.\n \"\"\"\n if subpackage_name is None:\n assert subpackage_path is not None\n subpackage_name = os.path.basename(subpackage_path)\n l = subpackage_name.split('.')\n if subpackage_path is None:\n subpackage_path = os.path.join(*([self.local_path]+l))\n if '*' in subpackage_name:\n dirs = filter(os.path.isdir,glob.glob(subpackage_path))\n config_list = []\n for d in dirs:\n if not os.path.isfile(os.path.join(d,'__init__.py')):\n continue\n n = '.'.join(d.split(os.sep)[-len(l):])\n c = self.get_subpackage(n)\n if c:\n config_list.append(c)\n return config_list\n else:\n subpackage_path = os.path.join(*([subpackage_path]+l[:-1]))\n subpackage_path = self._fix_paths([subpackage_path])[0]\n\n setup_py = os.path.join(subpackage_path,'setup.py')\n if not os.path.isfile(setup_py):\n setup_py = os.path.join(subpackage_path,'setup_%s.py' % (subpackage_name))\n\n if not os.path.isfile(setup_py):\n print 'Assuming default configuration '\\\n '(%s/{setup_%s,setup}.py was not found)' \\\n % (os.path.dirname(setup_py),subpackage_name)\n config = Configuration(subpackage_name,self.name,\n self.top_path,subpackage_path)\n else:\n # In case setup_py imports local modules:\n sys.path.insert(0,os.path.dirname(setup_py))\n try:\n info = (open(setup_py),setup_py,('.py','U',1))\n setup_name = os.path.splitext(os.path.basename(setup_py))[0]\n n = dot_join(self.name,setup_name)\n setup_module = imp.load_module('_'.join(n.split('.')),*info)\n\n if not hasattr(setup_module,'configuration'):\n print 'Assuming default configuration '\\\n '(%s does not define configuration())' % (setup_module)\n config = Configuration(subpackage_name,self.name,\n self.top_path,subpackage_path)\n else:\n args = (self.name,)\n if setup_module.configuration.func_code.co_argcount>1:\n args = args + (self.top_path,)\n config = setup_module.configuration(*args)\n\n finally:\n del sys.path[0]\n\n return config\n\n def add_subpackage(self,subpackage_name,subpackage_path=None):\n \"\"\" Add subpackage to configuration.\n \"\"\"\n config = self.get_subpackage(subpackage_name,subpackage_path)\n if not isinstance(config, list):\n config_list = [config]\n else:\n config_list = config\n for config in config_list:\n if not config:\n print 'No configuration returned, assuming unavailable.'\n else:\n if isinstance(config,Configuration):\n print 'Appending %s configuration to %s' % (config.name,self.name)\n self.dict_append(**config.todict())\n else:\n print 'Appending %s configuration to %s' % (config.get('name'),self.name)\n self.dict_append(**config)\n\n dist = self.get_distribution()\n if dist is not None:\n print 'distutils distribution has been initialized, it may be too late to add a subpackage', subpackage_name\n return\n\n def add_data_dir(self,data_path):\n \"\"\" Recursively add files under data_path to data_files list.\n Argument can be either\n - 2-sequence (,)\n - path to data directory where python datadir suffix defaults\n to package dir.\n If path is not absolute then it's datadir suffix is\n package dir + subdirname of the path.\n \"\"\"\n if type(data_path) is type(()):\n assert len(data_path)==2,`data_path`\n d,data_path = data_path\n else:\n d = None\n assert type(data_path) is type(''),`data_path`\n for path in self.paths(data_path):\n if not os.path.exists(path):\n print 'Not existing data path',path\n continue\n filenames = []\n os.path.walk(path, _gsf_visit_func,filenames)\n if not os.path.isabs(path):\n if d is None:\n ds = os.path.join(*(self.name.split('.')+[data_path]))\n else:\n ds = os.path.join(d,data_path)\n self.add_data_files((ds,filenames))\n else:\n if d is None:\n self.add_data_files(*filenames)\n else:\n self.add_data_files((d,filenames))\n return\n\n def add_data_files(self,*files):\n \"\"\" Add data files to configuration data_files.\n Argument(s) can be either\n - 2-sequence (,)\n - paths to data files where python datadir prefix defaults\n to package dir.\n If path is not absolute then it's datadir prefix is\n package dir + dirname of the path.\n \"\"\"\n data_dict = {}\n new_files = []\n for p in files:\n if type(p) is not type(()):\n d = os.path.join(*(self.name.split('.')))\n if type(p) is type('') and not os.path.isabs(p):\n d = appendpath(d,os.path.dirname(p))\n p = (d,p)\n new_files.append(p)\n files = []\n for prefix,filepattern in new_files:\n if type(filepattern) is type(''):\n file_list = self.paths(filepattern)\n elif callable(filepattern):\n file_list = [filepattern]\n else:\n file_list = self.paths(*filepattern)\n\n nof_path_components = [len(f.split(os.sep)) \\\n for f in file_list if type(f) is type('')]\n if nof_path_components:\n min_path_components = min(nof_path_components)-1\n else:\n min_path_components = 0\n\n for f in file_list:\n if type(f) is type(''):\n extra_path_components = f.split(os.sep)[min_path_components:-1]\n p = os.path.join(*([prefix]+extra_path_components))\n else:\n p = prefix\n if not data_dict.has_key(p):\n data_dict[p] = [f]\n else:\n data_dict[p].append(f)\n\n dist = self.get_distribution()\n if dist is not None:\n dist.data_files.extend(data_dict.items())\n else:\n self.data_files.extend(data_dict.items())\n return \n\n ### XXX Implement add_py_modules\n \n def add_include_dirs(self,*paths):\n \"\"\" Add paths to configuration include directories.\n \"\"\"\n include_dirs = self._fix_paths(paths)\n dist = self.get_distribution()\n if dist is not None:\n dist.include_dirs.extend(include_dirs)\n else:\n self.include_dirs.extend(include_dirs)\n return\n\n def add_headers(self,*files):\n \"\"\" Add installable headers to configuration.\n Argument(s) can be either\n - 2-sequence (,)\n - path(s) to header file(s) where python includedir suffix will default\n to package name.\n \"\"\"\n headers = []\n for path in files:\n if type(path) is type(''):\n [headers.append((self.name,p)) for p in self.paths(path)]\n else:\n assert type(path) in [type(()),type([])] and len(path)==2,`path`\n [headers.append((path[0],p)) for p in self.paths(path[1])]\n dist = self.get_distribution()\n if dist is not None:\n dist.headers.extend(headers)\n else:\n self.headers.extend(headers)\n return\n\n def _fix_paths(self,paths):\n new_paths = []\n for n in paths:\n if isinstance(n,str):\n if '*' in n or '?' in n:\n p = glob.glob(n)\n p2 = glob.glob(os.path.join(self.local_path,n))\n if p2:\n new_paths.extend(p2)\n elif p:\n new_paths.extend(p)\n else:\n new_paths.append(n)\n else:\n n2 = os.path.join(self.local_path,n)\n if os.path.exists(n2):\n new_paths.append(n2)\n else:\n new_paths.append(n)\n else:\n new_paths.append(n)\n return new_paths\n\n def paths(self,*paths):\n \"\"\" Apply glob to paths and prepend local_path if needed.\n \"\"\"\n return self._fix_paths(paths)\n\n def add_extension(self,name,sources,**kw):\n \"\"\" Add extension to configuration.\n\n Keywords:\n include_dirs, define_macros, undef_macros,\n library_dirs, libraries, runtime_library_dirs,\n extra_objects, extra_compile_args, extra_link_args,\n export_symbols, swig_opts, depends, language,\n f2py_options, module_dirs\n extra_info - dict or list of dict of keywords to be\n appended to keywords.\n \"\"\"\n ext_args = copy.copy(kw)\n ext_args['name'] = dot_join(self.name,name)\n ext_args['sources'] = sources\n\n if ext_args.has_key('extra_info'):\n extra_info = ext_args['extra_info']\n del ext_args['extra_info']\n if type(extra_info) is type({}):\n extra_info = [extra_info]\n for info in extra_info:\n assert type(info) is type({}),`info`\n dict_append(ext_args,**info)\n\n for k in ext_args.keys():\n v = ext_args[k]\n if k in ['sources','depends','include_dirs','library_dirs',\n 'module_dirs','extra_objects']:\n new_v = self._fix_paths(v)\n ext_args[k] = new_v\n\n # Resolve out-of-tree dependencies\n libraries = ext_args.get('libraries',[])\n libnames = []\n ext_args['libraries'] = []\n for libname in libraries:\n if '@' in libname:\n lname,lpath = libname.split('@',1)\n lpath = os.path.abspath(os.path.join(self.local_path,lpath))\n if os.path.isdir(lpath):\n c = self.get_subpackage(None,lpath)\n if isinstance(c,Configuration):\n c = c.todict()\n for l in [l[0] for l in c.get('libraries',[])]:\n llname = l.split('__OF__',1)[0]\n if llname == lname:\n c.pop('name',None)\n dict_append(ext_args,**c)\n break\n continue\n libnames.append(libname)\n\n ext_args['libraries'] = libnames + ext_args['libraries']\n\n from numpy.distutils.core import Extension\n ext = Extension(**ext_args)\n self.ext_modules.append(ext)\n\n dist = self.get_distribution()\n if dist is not None:\n print 'distutils distribution has been initialized, it may be too late to add an extension', name\n return ext\n\n def add_library(self,name,sources,**build_info):\n \"\"\" Add library to configuration.\n \n Valid keywords for build_info:\n depends\n macros\n include_dirs\n extra_compiler_args\n f2py_options\n \"\"\"\n build_info = copy.copy(build_info)\n name = name #+ '__OF__' + self.name\n build_info['sources'] = sources\n\n for k in build_info.keys():\n v = build_info[k]\n if k in ['sources','depends']:\n new_v = self._fix_paths(v)\n build_info[k] = new_v\n self.libraries.append((name,build_info))\n\n dist = self.get_distribution()\n if dist is not None:\n print 'distutils distribution has been initialized, it may be too late to add a library', name\n return\n\n def add_scripts(self,*files):\n \"\"\" Add scripts to configuration.\n \"\"\"\n scripts = self._fix_paths(files)\n dist = self.get_distribution()\n if dist is not None:\n dist.scripts.extend(scripts)\n else:\n self.scripts.extend(scripts)\n return\n\n def dict_append(self,**dict):\n for key in self.list_keys:\n a = getattr(self,key)\n a.extend(dict.get(key,[]))\n for key in self.dict_keys:\n a = getattr(self,key)\n a.update(dict.get(key,{}))\n known_keys = self.list_keys + self.dict_keys + self.extra_keys\n for key in dict.keys():\n if key not in known_keys and not hasattr(self,key):\n print 'Inheriting attribute %r from %r' \\\n % (key,dict.get('name','?'))\n setattr(self,key,dict[key])\n self.extra_keys.append(key)\n return\n\n def __str__(self):\n known_keys = self.list_keys + self.dict_keys + self.extra_keys\n s = '<'+5*'-' + '\\n'\n s += 'Configuration of '+self.name+':\\n'\n for k in known_keys:\n a = getattr(self,k,None)\n if a:\n s += '%s = %r\\n' % (k,a)\n s += 5*'-' + '>'\n return s\n\n def get_config_cmd(self):\n cmd = get_cmd('config')\n cmd.ensure_finalized()\n cmd.dump_source = 0\n cmd.noisy = 0\n old_path = os.environ.get('PATH')\n if old_path:\n path = os.pathsep.join(['.',old_path])\n os.environ['PATH'] = path\n return cmd\n\n def get_build_temp_dir(self):\n cmd = get_cmd('build')\n cmd.ensure_finalized()\n return cmd.build_temp\n\n def have_f77c(self):\n \"\"\" Check for availability of Fortran 77 compiler.\n Use it inside source generating function to ensure that\n setup distribution instance has been initialized.\n \"\"\"\n simple_fortran_subroutine = '''\n subroutine simple\n end\n '''\n config_cmd = self.get_config_cmd()\n flag = config_cmd.try_compile(simple_fortran_subroutine,lang='f77')\n return flag\n\n def have_f90c(self):\n \"\"\" Check for availability of Fortran 90 compiler.\n Use it inside source generating function to ensure that\n setup distribution instance has been initialized.\n \"\"\"\n simple_fortran_subroutine = '''\n subroutine simple\n end\n '''\n config_cmd = self.get_config_cmd()\n flag = config_cmd.try_compile(simple_fortran_subroutine,lang='f90')\n return flag\n\n def append_to(self, extlib):\n \"\"\" Append libraries, include_dirs to extension or library item.\n \"\"\"\n if type(extlib) is type(()):\n lib_name, build_info = extlib\n dict_append(build_info,\n libraries=self.libraries,\n include_dirs=self.include_dirs)\n else:\n from numpy.distutils.core import Extension\n assert isinstance(extlib,Extension),`extlib`\n extlib.libraries.extend(self.libraries)\n extlib.include_dirs.extend(self.include_dirs)\n return\n\n def _get_svn_revision(self,path):\n \"\"\" Return path's SVN revision number.\n \"\"\"\n entries = os.path.join(path,'.svn','entries')\n revision = None\n if os.path.isfile(entries):\n f = open(entries)\n m = re.search(r'revision=\"(?P\\d+)\"',f.read())\n f.close()\n if m:\n revision = int(m.group('revision'))\n return revision\n\n def get_version(self):\n \"\"\" Try to get version string of a package.\n \"\"\"\n version = getattr(self,'version',None)\n if version is not None:\n return version\n\n # Get version from version file.\n files = ['__version__.py',\n self.name.split('.')[-1]+'_version.py',\n 'version.py',\n '__svn_version__.py']\n version_vars = ['version',\n '__version__',\n self.name.split('.')[-1]+'_version']\n for f in files:\n fn = os.path.join(self.local_path,f)\n if os.path.isfile(fn):\n info = (open(fn),fn,('.py','U',1))\n name = os.path.splitext(os.path.basename(fn))[0]\n n = dot_join(self.name,name)\n try:\n version_module = imp.load_module('_'.join(n.split('.')),*info)\n except ImportError,msg:\n print msg\n version_module = None\n if version_module is None:\n continue\n\n for a in version_vars:\n version = getattr(version_module,a,None)\n if version is not None:\n break\n if version is not None:\n break\n\n if version is not None:\n self.version = version\n return version\n\n # Get version as SVN revision number\n revision = self._get_svn_revision(self.local_path)\n if revision is not None:\n version = str(revision)\n self.version = version\n\n return version\n\n def make_svn_version_py(self):\n \"\"\" Generate package __svn_version__.py file from SVN revision number,\n it will be removed after python exits but will be available\n when sdist, etc commands are executed.\n\n If __svn_version__.py existed before, nothing is done.\n \"\"\"\n target = os.path.join(self.local_path,'__svn_version__.py')\n if os.path.isfile(target):\n return\n\n def generate_svn_version_py():\n if not os.path.isfile(target):\n revision = self._get_svn_revision(self.local_path)\n assert revision is not None,'hmm, why I am not inside SVN tree???'\n version = str(revision)\n print 'Creating %s (version=%r)' % (target,version)\n f = open(target,'w')\n f.write('version = %r\\n' % (version))\n f.close()\n \n import atexit\n def rm_file(f=target):\n try: os.remove(f); print 'removed',f\n except OSError: pass\n try: os.remove(f+'c'); print 'removed',f+'c'\n except OSError: pass\n atexit.register(rm_file)\n\n return target\n\n d = os.path.join(*(self.name.split('.')))\n self.add_data_files((d, generate_svn_version_py()))\n return\n\n def make_config_py(self,name='__config__'):\n \"\"\" Generate package __config__.py file containing system_info\n information used during building the package.\n \"\"\"\n self.py_modules.append((self.name,name,generate_config_py))\n return\n\n def get_info(self,*names):\n \"\"\" Get resources information.\n \"\"\"\n from system_info import get_info, dict_append\n info_dict = {}\n for a in names:\n dict_append(info_dict,**get_info(a))\n return info_dict\n\ndef get_cmd(cmdname,_cache={}):\n if not _cache.has_key(cmdname):\n import distutils.core\n dist = distutils.core._setup_distribution\n if dist is None:\n from distutils.errors import DistutilsInternalError\n raise DistutilsInternalError,\\\n 'setup distribution instance not initialized'\n cmd = dist.get_command_obj(cmdname)\n _cache[cmdname] = cmd\n return _cache[cmdname]\n\ndef get_numpy_include_dirs():\n # numpy_include_dirs are set by numpy/core/setup.py, otherwise []\n include_dirs = Configuration.numpy_include_dirs[:]\n if not include_dirs:\n import numpy\n if numpy.show_config is None:\n # running from numpy_core source directory\n include_dirs.append(os.path.join(os.path.dirname(numpy.__file__),\n 'core','include'))\n else:\n # using installed numpy core headers\n import numpy.core as core\n include_dirs.append(os.path.join(os.path.dirname(core.__file__),'include'))\n # else running numpy/core/setup.py\n return include_dirs\n\n#########################\n\ndef default_config_dict(name = None, parent_name = None, local_path=None):\n \"\"\" Return a configuration dictionary for usage in\n configuration() function defined in file setup_.py.\n \"\"\"\n import warnings\n warnings.warn('Use Configuration(%s,%s,top_path=%s) instead of '\\\n 'deprecated default_config_dict(%s,%s,%s)' \\\n % (`name`,`parent_name`,`local_path`,\n `name`,`parent_name`,`local_path`,\n ))\n c = Configuration(name, parent_name, local_path)\n return c.todict()\n\n\ndef dict_append(d,**kws):\n for k,v in kws.items():\n if d.has_key(k):\n d[k].extend(v)\n else:\n d[k] = v\n\ndef appendpath(prefix,path):\n if not ('/' == os.path.sep):\n prefix = prefix.replace('/',os.path.sep)\n path = path.replace('/',os.path.sep)\n drive = ''\n if os.path.isabs(path):\n drive = os.path.splitdrive(prefix)[0]\n absprefix = os.path.splitdrive(os.path.abspath(prefix))[1]\n pathdrive,path = os.path.splitdrive(path)\n d = os.path.commonprefix([absprefix,path])\n if os.path.join(absprefix[:len(d)],absprefix[len(d):])!=absprefix \\\n or os.path.join(path[:len(d)],path[len(d):])!=path:\n # Handle invalid paths\n d = os.path.dirname(d)\n subpath = path[len(d):]\n if os.path.isabs(subpath):\n subpath = subpath[1:]\n else:\n subpath = path\n return os.path.normpath(os.path.join(drive + prefix, subpath))\n\ndef generate_config_py(target):\n \"\"\" Generate config.py file containing system_info information\n used during building the package.\n\n Usage:\\\n config['py_modules'].append((packagename, '__config__',generate_config_py))\n \"\"\"\n from numpy.distutils.system_info import system_info\n from distutils.dir_util import mkpath\n mkpath(os.path.dirname(target))\n f = open(target,'w')\n f.write('# This file is generated by %s\\n' % (os.path.abspath(sys.argv[0])))\n f.write('# It contains system_info results at the time of building this package.\\n')\n f.write('__all__ = [\"get_info\",\"show\"]\\n\\n')\n for k,i in system_info.saved_results.items():\n f.write('%s=%r\\n' % (k,i))\n f.write('\\ndef get_info(name): g=globals(); return g.get(name,g.get(name+\"_info\",{}))\\n')\n f.write('''\ndef show():\n for name,info_dict in globals().items():\n if name[0]==\"_\" or type(info_dict) is not type({}): continue\n print name+\":\"\n if not info_dict:\n print \" NOT AVAILABLE\"\n for k,v in info_dict.items():\n v = str(v)\n if k==\\'sources\\' and len(v)>200: v = v[:60]+\\' ...\\\\n... \\'+v[-60:]\n print \\' %s = %s\\'%(k,v)\n print\n return\n ''')\n\n f.close()\n return target\n\ndef generate_svn_version_py(extension, build_dir):\n \"\"\" Generate __svn_version__.py file containing SVN\n revision number of a module.\n \n To use, add the following codelet to setup\n configuration(..) function\n\n ext = Extension(dot_join(config['name'],'__svn_version__'),\n sources=[generate_svn_version_py])\n ext.local_path = local_path\n config['ext_modules'].append(ext)\n\n \"\"\"\n from distutils import dep_util\n local_path = extension.local_path\n target = os.path.join(build_dir, '__svn_version__.py')\n entries = os.path.join(local_path,'.svn','entries')\n if os.path.isfile(entries):\n if not dep_util.newer(entries, target):\n return target\n elif os.path.isfile(target):\n return target\n\n revision = get_svn_revision(local_path)\n f = open(target,'w')\n f.write('revision=%s\\n' % (revision))\n f.close()\n return target\n", + "source_code_before": "import os\nimport re\nimport sys\nimport imp\nimport copy\nimport types\nimport glob\n\n__all__ = ['Configuration', 'get_numpy_include_dirs', 'default_config_dict',\n 'dict_append', 'appendpath', 'generate_config_py',\n 'generate_svn_version_py', 'get_cmd', 'allpath',\n 'terminal_has_colors', 'red_text', 'green_text', 'yellow_text',\n 'blue_text', 'cyan_text', 'cyg2win32', 'all_strings',\n 'has_f_sources', 'has_cxx_sources', 'filter_sources',\n 'get_dependencies', 'is_local_src_dir', 'get_ext_source_files',\n 'get_script_files', 'get_lib_source_files', 'get_data_files',\n 'dot_join', 'get_frame']\n\ndef allpath(name):\n \"Convert a /-separated pathname to one using the OS's path separator.\"\n splitted = name.split('/')\n return os.path.join(*splitted)\n\ndef get_path(mod_name,parent_path=None):\n \"\"\" Return path of the module.\n\n Returned path is relative to parent_path when given,\n otherwise it is absolute path.\n \"\"\"\n if mod_name == '__main__':\n d = os.path.abspath('.')\n elif mod_name == '__builtin__':\n #builtin if/then added by Pearu for use in core.run_setup. \n d = os.path.dirname(os.path.abspath(sys.argv[0]))\n else:\n __import__(mod_name)\n mod = sys.modules[mod_name]\n file = mod.__file__\n d = os.path.dirname(os.path.abspath(file))\n if parent_path is not None:\n pd = os.path.abspath(parent_path)\n if pd==d[:len(pd)]:\n d = d[len(pd)+1:]\n return d or '.'\n\n# Hooks for colored terminal output.\n# See also http://www.livinglogic.de/Python/ansistyle\ndef terminal_has_colors():\n if sys.platform=='cygwin' and not os.environ.has_key('USE_COLOR'):\n # Avoid importing curses that causes illegal operation\n # with a message:\n # PYTHON2 caused an invalid page fault in\n # module CYGNURSES7.DLL as 015f:18bbfc28\n # Details: Python 2.3.3 [GCC 3.3.1 (cygming special)]\n # ssh to Win32 machine from debian\n # curses.version is 2.2\n # CYGWIN_98-4.10, release 1.5.7(0.109/3/2))\n return 0\n if hasattr(sys.stdout,'isatty') and sys.stdout.isatty(): \n try:\n import curses\n curses.setupterm()\n if (curses.tigetnum(\"colors\") >= 0\n and curses.tigetnum(\"pairs\") >= 0\n and ((curses.tigetstr(\"setf\") is not None \n and curses.tigetstr(\"setb\") is not None) \n or (curses.tigetstr(\"setaf\") is not None\n and curses.tigetstr(\"setab\") is not None)\n or curses.tigetstr(\"scp\") is not None)):\n return 1\n except Exception,msg:\n pass\n return 0\n\nif terminal_has_colors():\n def red_text(s): return '\\x1b[31m%s\\x1b[0m'%s\n def green_text(s): return '\\x1b[32m%s\\x1b[0m'%s\n def yellow_text(s): return '\\x1b[33m%s\\x1b[0m'%s\n def blue_text(s): return '\\x1b[34m%s\\x1b[0m'%s\n def cyan_text(s): return '\\x1b[35m%s\\x1b[0m'%s\nelse:\n def red_text(s): return s\n def green_text(s): return s\n def yellow_text(s): return s\n def cyan_text(s): return s\n def blue_text(s): return s\n\n#########################\n\ndef cyg2win32(path):\n if sys.platform=='cygwin' and path.startswith('/cygdrive'):\n path = path[10] + ':' + os.path.normcase(path[11:])\n return path\n\n#########################\n\n#XXX need support for .C that is also C++\ncxx_ext_match = re.compile(r'.*[.](cpp|cxx|cc)\\Z',re.I).match\nfortran_ext_match = re.compile(r'.*[.](f90|f95|f77|for|ftn|f)\\Z',re.I).match\nf90_ext_match = re.compile(r'.*[.](f90|f95)\\Z',re.I).match\nf90_module_name_match = re.compile(r'\\s*module\\s*(?P[\\w_]+)',re.I).match\ndef _get_f90_modules(source):\n \"\"\" Return a list of Fortran f90 module names that\n given source file defines.\n \"\"\"\n if not f90_ext_match(source):\n return []\n modules = []\n f = open(source,'r')\n f_readlines = getattr(f,'xreadlines',f.readlines)\n for line in f_readlines():\n m = f90_module_name_match(line)\n if m:\n name = m.group('name')\n modules.append(name)\n # break # XXX can we assume that there is one module per file?\n f.close()\n return modules\n\ndef all_strings(lst):\n \"\"\" Return True if all items in lst are string objects. \"\"\"\n for item in lst:\n if type(item) is not types.StringType:\n return False\n return True\n\ndef has_f_sources(sources):\n \"\"\" Return True if sources contains Fortran files \"\"\"\n for source in sources:\n if fortran_ext_match(source):\n return True\n return False\n\ndef has_cxx_sources(sources):\n \"\"\" Return True if sources contains C++ files \"\"\"\n for source in sources:\n if cxx_ext_match(source):\n return True\n return False\n\ndef filter_sources(sources):\n \"\"\" Return four lists of filenames containing\n C, C++, Fortran, and Fortran 90 module sources,\n respectively.\n \"\"\"\n c_sources = []\n cxx_sources = []\n f_sources = []\n fmodule_sources = []\n for source in sources:\n if fortran_ext_match(source):\n modules = _get_f90_modules(source)\n if modules:\n fmodule_sources.append(source)\n else:\n f_sources.append(source)\n elif cxx_ext_match(source):\n cxx_sources.append(source)\n else:\n c_sources.append(source) \n return c_sources, cxx_sources, f_sources, fmodule_sources\n\n\ndef _get_headers(directory_list):\n # get *.h files from list of directories\n headers = []\n for dir in directory_list:\n head = glob.glob(os.path.join(dir,\"*.h\")) #XXX: *.hpp files??\n headers.extend(head)\n return headers\n\ndef _get_directories(list_of_sources):\n # get unique directories from list of sources.\n direcs = []\n for file in list_of_sources:\n dir = os.path.split(file)\n if dir[0] != '' and not dir[0] in direcs:\n direcs.append(dir[0])\n return direcs\n\ndef get_dependencies(sources):\n #XXX scan sources for include statements\n return _get_headers(_get_directories(sources))\n\ndef is_local_src_dir(directory):\n \"\"\" Return true if directory is local directory.\n \"\"\"\n if type(directory) is not type(''):\n return False\n abs_dir = os.path.abspath(directory)\n c = os.path.commonprefix([os.getcwd(),abs_dir])\n new_dir = abs_dir[len(c):].split(os.sep)\n if new_dir and not new_dir[0]:\n new_dir = new_dir[1:]\n if new_dir and new_dir[0]=='build':\n return False\n new_dir = os.sep.join(new_dir)\n return os.path.isdir(new_dir)\n\ndef _gsf_visit_func(filenames,dirname,names):\n if os.path.basename(dirname) in ['CVS','.svn','build']:\n names[:] = []\n return\n for name in names:\n if name[-1] in \"~#\":\n continue\n fullname = os.path.join(dirname,name)\n ext = os.path.splitext(fullname)[1]\n if ext and ext in ['.pyc','.o']:\n continue\n if os.path.isfile(fullname):\n filenames.append(fullname)\n\ndef get_ext_source_files(ext):\n # Get sources and any include files in the same directory.\n filenames = []\n sources = filter(lambda s:type(s) is types.StringType,ext.sources)\n filenames.extend(sources)\n filenames.extend(get_dependencies(sources))\n for d in ext.depends:\n if is_local_src_dir(d):\n os.path.walk(d,_gsf_visit_func,filenames)\n elif os.path.isfile(d):\n filenames.append(d)\n return filenames\n\ndef get_script_files(scripts):\n scripts = filter(lambda s:type(s) is types.StringType,scripts)\n return scripts\n\ndef get_lib_source_files(lib):\n filenames = []\n sources = lib[1].get('sources',[])\n sources = filter(lambda s:type(s) is types.StringType,sources)\n filenames.extend(sources)\n filenames.extend(get_dependencies(sources))\n depends = lib[1].get('depends',[])\n for d in depends:\n if is_local_src_dir(d):\n os.path.walk(d,_gsf_visit_func,filenames)\n elif os.path.isfile(d):\n filenames.append(d)\n return filenames\n\ndef get_data_files(data):\n if type(data) is types.StringType:\n return [data]\n sources = data[1]\n filenames = []\n for s in sources:\n if callable(s):\n s = s()\n if s is None:\n continue\n if is_local_src_dir(s):\n os.path.walk(s,_gsf_visit_func,filenames)\n elif type(s) is type(''):\n if os.path.isfile(s):\n filenames.append(s)\n else:\n print 'Not existing data file:',s\n else:\n raise TypeError,`s`\n return filenames\n\ndef dot_join(*args):\n return '.'.join(filter(None,args))\n\ndef get_frame(level=0):\n try:\n return sys._getframe(level+1)\n except AttributeError:\n frame = sys.exc_info()[2].tb_frame\n for i in range(level+1):\n frame = frame.f_back\n return frame\n\n######################\n\nclass Configuration:\n\n _list_keys = ['packages','ext_modules','data_files','include_dirs',\n 'libraries','headers','scripts','py_modules']\n _dict_keys = ['package_dir']\n\n numpy_include_dirs = []\n\n def __init__(self,\n package_name=None,\n parent_name=None,\n top_path=None,\n package_path=None,\n **attrs):\n \"\"\" Construct configuration instance of a package.\n \"\"\"\n self.name = dot_join(parent_name, package_name)\n\n caller_frame = get_frame(1)\n caller_name = eval('__name__',caller_frame.f_globals,caller_frame.f_locals)\n \n self.local_path = get_path(caller_name, top_path)\n if top_path is None:\n top_path = self.local_path\n if package_path is None:\n package_path = self.local_path\n elif os.path.isdir(os.path.join(self.local_path,package_path)):\n package_path = os.path.join(self.local_path,package_path)\n assert os.path.isdir(package_path),`package_path`\n self.top_path = top_path\n\n self.list_keys = copy.copy(self._list_keys)\n self.dict_keys = copy.copy(self._dict_keys)\n\n for n in self.list_keys:\n setattr(self,n,copy.copy(attrs.get(n,[])))\n\n for n in self.dict_keys:\n setattr(self,n,copy.copy(attrs.get(n,{})))\n\n known_keys = self.list_keys + self.dict_keys\n self.extra_keys = []\n for n in attrs.keys():\n if n in known_keys:\n continue\n a = attrs[n]\n setattr(self,n,a)\n if type(a) is types.ListType:\n self.list_keys.append(n)\n elif type(a) is types.DictType:\n self.dict_keys.append(n)\n else:\n self.extra_keys.append(n)\n\n if os.path.exists(os.path.join(package_path,'__init__.py')):\n self.packages.append(self.name)\n self.package_dir[self.name] = package_path \n return\n\n def todict(self):\n \"\"\" Return configuration distionary suitable for passing\n to distutils.core.setup() function.\n \"\"\"\n d = {}\n for n in self.list_keys + self.dict_keys + self.extra_keys:\n a = getattr(self,n)\n if a:\n d[n] = a\n if self.name:\n d['name'] = self.name\n return d\n\n def __dict__(self):\n return self.todict()\n\n def get_distribution(self):\n import distutils.core\n dist = distutils.core._setup_distribution \n return dist\n\n def get_subpackage(self,subpackage_name,subpackage_path=None):\n \"\"\" Return subpackage configuration.\n \"\"\"\n if subpackage_name is None:\n assert subpackage_path is not None\n subpackage_name = os.path.basename(subpackage_path)\n l = subpackage_name.split('.')\n if subpackage_path is None:\n subpackage_path = os.path.join(*([self.local_path]+l))\n if '*' in subpackage_name:\n dirs = filter(os.path.isdir,glob.glob(subpackage_path))\n config_list = []\n for d in dirs:\n if not os.path.isfile(os.path.join(d,'__init__.py')):\n continue\n n = '.'.join(d.split(os.sep)[-len(l):])\n c = self.get_subpackage(n)\n if c:\n config_list.append(c)\n return config_list\n else:\n subpackage_path = os.path.join(*([subpackage_path]+l[:-1]))\n subpackage_path = self._fix_paths([subpackage_path])[0]\n\n setup_py = os.path.join(subpackage_path,'setup_%s.py' % (subpackage_name))\n if not os.path.isfile(setup_py):\n setup_py = os.path.join(subpackage_path,'setup.py')\n if not os.path.isfile(setup_py):\n print 'Assuming default configuration '\\\n '(%s/{setup_%s,setup}.py was not found)' \\\n % (os.path.dirname(setup_py),subpackage_name)\n config = Configuration(subpackage_name,self.name,\n self.top_path,subpackage_path)\n else:\n # In case setup_py imports local modules:\n sys.path.insert(0,os.path.dirname(setup_py))\n try:\n info = (open(setup_py),setup_py,('.py','U',1))\n setup_name = os.path.splitext(os.path.basename(setup_py))[0]\n n = dot_join(self.name,setup_name)\n setup_module = imp.load_module('_'.join(n.split('.')),*info)\n\n if not hasattr(setup_module,'configuration'):\n print 'Assuming default configuration '\\\n '(%s does not define configuration())' % (setup_module)\n config = Configuration(subpackage_name,self.name,\n self.top_path,subpackage_path)\n else:\n args = (self.name,)\n if setup_module.configuration.func_code.co_argcount>1:\n args = args + (self.top_path,)\n config = setup_module.configuration(*args)\n\n finally:\n del sys.path[0]\n\n return config\n\n def add_subpackage(self,subpackage_name,subpackage_path=None):\n \"\"\" Add subpackage to configuration.\n \"\"\"\n config = self.get_subpackage(subpackage_name,subpackage_path)\n if not isinstance(config, list):\n config_list = [config]\n else:\n config_list = config\n for config in config_list:\n if not config:\n print 'No configuration returned, assuming unavailable.'\n else:\n if isinstance(config,Configuration):\n print 'Appending %s configuration to %s' % (config.name,self.name)\n self.dict_append(**config.todict())\n else:\n print 'Appending %s configuration to %s' % (config.get('name'),self.name)\n self.dict_append(**config)\n\n dist = self.get_distribution()\n if dist is not None:\n print 'distutils distribution has been initialized, it may be too late to add a subpackage', subpackage_name\n return\n\n def add_data_dir(self,data_path):\n \"\"\" Recursively add files under data_path to data_files list.\n Argument can be either\n - 2-sequence (,)\n - path to data directory where python datadir suffix defaults\n to package dir.\n If path is not absolute then it's datadir suffix is\n package dir + subdirname of the path.\n \"\"\"\n if type(data_path) is type(()):\n assert len(data_path)==2,`data_path`\n d,data_path = data_path\n else:\n d = None\n assert type(data_path) is type(''),`data_path`\n for path in self.paths(data_path):\n if not os.path.exists(path):\n print 'Not existing data path',path\n continue\n filenames = []\n os.path.walk(path, _gsf_visit_func,filenames)\n if not os.path.isabs(path):\n if d is None:\n ds = os.path.join(*(self.name.split('.')+[data_path]))\n else:\n ds = os.path.join(d,data_path)\n self.add_data_files((ds,filenames))\n else:\n if d is None:\n self.add_data_files(*filenames)\n else:\n self.add_data_files((d,filenames))\n return\n\n def add_data_files(self,*files):\n \"\"\" Add data files to configuration data_files.\n Argument(s) can be either\n - 2-sequence (,)\n - paths to data files where python datadir prefix defaults\n to package dir.\n If path is not absolute then it's datadir prefix is\n package dir + dirname of the path.\n \"\"\"\n data_dict = {}\n new_files = []\n for p in files:\n if type(p) is not type(()):\n d = os.path.join(*(self.name.split('.')))\n if type(p) is type('') and not os.path.isabs(p):\n d = appendpath(d,os.path.dirname(p))\n p = (d,p)\n new_files.append(p)\n files = []\n for prefix,filepattern in new_files:\n if type(filepattern) is type(''):\n file_list = self.paths(filepattern)\n elif callable(filepattern):\n file_list = [filepattern]\n else:\n file_list = self.paths(*filepattern)\n\n nof_path_components = [len(f.split(os.sep)) \\\n for f in file_list if type(f) is type('')]\n if nof_path_components:\n min_path_components = min(nof_path_components)-1\n else:\n min_path_components = 0\n\n for f in file_list:\n if type(f) is type(''):\n extra_path_components = f.split(os.sep)[min_path_components:-1]\n p = os.path.join(*([prefix]+extra_path_components))\n else:\n p = prefix\n if not data_dict.has_key(p):\n data_dict[p] = [f]\n else:\n data_dict[p].append(f)\n\n dist = self.get_distribution()\n if dist is not None:\n dist.data_files.extend(data_dict.items())\n else:\n self.data_files.extend(data_dict.items())\n return \n\n ### XXX Implement add_py_modules\n \n def add_include_dirs(self,*paths):\n \"\"\" Add paths to configuration include directories.\n \"\"\"\n include_dirs = self._fix_paths(paths)\n dist = self.get_distribution()\n if dist is not None:\n dist.include_dirs.extend(include_dirs)\n else:\n self.include_dirs.extend(include_dirs)\n return\n\n def add_headers(self,*files):\n \"\"\" Add installable headers to configuration.\n Argument(s) can be either\n - 2-sequence (,)\n - path(s) to header file(s) where python includedir suffix will default\n to package name.\n \"\"\"\n headers = []\n for path in files:\n if type(path) is type(''):\n [headers.append((self.name,p)) for p in self.paths(path)]\n else:\n assert type(path) in [type(()),type([])] and len(path)==2,`path`\n [headers.append((path[0],p)) for p in self.paths(path[1])]\n dist = self.get_distribution()\n if dist is not None:\n dist.headers.extend(headers)\n else:\n self.headers.extend(headers)\n return\n\n def _fix_paths(self,paths):\n new_paths = []\n for n in paths:\n if isinstance(n,str):\n if '*' in n or '?' in n:\n p = glob.glob(n)\n p2 = glob.glob(os.path.join(self.local_path,n))\n if p2:\n new_paths.extend(p2)\n elif p:\n new_paths.extend(p)\n else:\n new_paths.append(n)\n else:\n n2 = os.path.join(self.local_path,n)\n if os.path.exists(n2):\n new_paths.append(n2)\n else:\n new_paths.append(n)\n else:\n new_paths.append(n)\n return new_paths\n\n def paths(self,*paths):\n \"\"\" Apply glob to paths and prepend local_path if needed.\n \"\"\"\n return self._fix_paths(paths)\n\n def add_extension(self,name,sources,**kw):\n \"\"\" Add extension to configuration.\n\n Keywords:\n include_dirs, define_macros, undef_macros,\n library_dirs, libraries, runtime_library_dirs,\n extra_objects, extra_compile_args, extra_link_args,\n export_symbols, swig_opts, depends, language,\n f2py_options, module_dirs\n extra_info - dict or list of dict of keywords to be\n appended to keywords.\n \"\"\"\n ext_args = copy.copy(kw)\n ext_args['name'] = dot_join(self.name,name)\n ext_args['sources'] = sources\n\n if ext_args.has_key('extra_info'):\n extra_info = ext_args['extra_info']\n del ext_args['extra_info']\n if type(extra_info) is type({}):\n extra_info = [extra_info]\n for info in extra_info:\n assert type(info) is type({}),`info`\n dict_append(ext_args,**info)\n\n for k in ext_args.keys():\n v = ext_args[k]\n if k in ['sources','depends','include_dirs','library_dirs',\n 'module_dirs','extra_objects']:\n new_v = self._fix_paths(v)\n ext_args[k] = new_v\n\n # Resolve out-of-tree dependencies\n libraries = ext_args.get('libraries',[])\n libnames = []\n ext_args['libraries'] = []\n for libname in libraries:\n if '@' in libname:\n lname,lpath = libname.split('@',1)\n lpath = os.path.abspath(os.path.join(self.local_path,lpath))\n if os.path.isdir(lpath):\n c = self.get_subpackage(None,lpath)\n if isinstance(c,Configuration):\n c = c.todict()\n for l in [l[0] for l in c.get('libraries',[])]:\n llname = l.split('__OF__',1)[0]\n if llname == lname:\n c.pop('name',None)\n dict_append(ext_args,**c)\n break\n continue\n libnames.append(libname)\n\n ext_args['libraries'] = libnames + ext_args['libraries']\n\n from numpy.distutils.core import Extension\n ext = Extension(**ext_args)\n self.ext_modules.append(ext)\n\n dist = self.get_distribution()\n if dist is not None:\n print 'distutils distribution has been initialized, it may be too late to add an extension', name\n return ext\n\n def add_library(self,name,sources,**build_info):\n \"\"\" Add library to configuration.\n \n Valid keywords for build_info:\n depends\n macros\n include_dirs\n extra_compiler_args\n f2py_options\n \"\"\"\n build_info = copy.copy(build_info)\n name = name #+ '__OF__' + self.name\n build_info['sources'] = sources\n\n for k in build_info.keys():\n v = build_info[k]\n if k in ['sources','depends']:\n new_v = self._fix_paths(v)\n build_info[k] = new_v\n self.libraries.append((name,build_info))\n\n dist = self.get_distribution()\n if dist is not None:\n print 'distutils distribution has been initialized, it may be too late to add a library', name\n return\n\n def add_scripts(self,*files):\n \"\"\" Add scripts to configuration.\n \"\"\"\n scripts = self._fix_paths(files)\n dist = self.get_distribution()\n if dist is not None:\n dist.scripts.extend(scripts)\n else:\n self.scripts.extend(scripts)\n return\n\n def dict_append(self,**dict):\n for key in self.list_keys:\n a = getattr(self,key)\n a.extend(dict.get(key,[]))\n for key in self.dict_keys:\n a = getattr(self,key)\n a.update(dict.get(key,{}))\n known_keys = self.list_keys + self.dict_keys + self.extra_keys\n for key in dict.keys():\n if key not in known_keys and not hasattr(self,key):\n print 'Inheriting attribute %r from %r' \\\n % (key,dict.get('name','?'))\n setattr(self,key,dict[key])\n self.extra_keys.append(key)\n return\n\n def __str__(self):\n known_keys = self.list_keys + self.dict_keys + self.extra_keys\n s = '<'+5*'-' + '\\n'\n s += 'Configuration of '+self.name+':\\n'\n for k in known_keys:\n a = getattr(self,k,None)\n if a:\n s += '%s = %r\\n' % (k,a)\n s += 5*'-' + '>'\n return s\n\n def get_config_cmd(self):\n cmd = get_cmd('config')\n cmd.ensure_finalized()\n cmd.dump_source = 0\n cmd.noisy = 0\n old_path = os.environ.get('PATH')\n if old_path:\n path = os.pathsep.join(['.',old_path])\n os.environ['PATH'] = path\n return cmd\n\n def get_build_temp_dir(self):\n cmd = get_cmd('build')\n cmd.ensure_finalized()\n return cmd.build_temp\n\n def have_f77c(self):\n \"\"\" Check for availability of Fortran 77 compiler.\n Use it inside source generating function to ensure that\n setup distribution instance has been initialized.\n \"\"\"\n simple_fortran_subroutine = '''\n subroutine simple\n end\n '''\n config_cmd = self.get_config_cmd()\n flag = config_cmd.try_compile(simple_fortran_subroutine,lang='f77')\n return flag\n\n def have_f90c(self):\n \"\"\" Check for availability of Fortran 90 compiler.\n Use it inside source generating function to ensure that\n setup distribution instance has been initialized.\n \"\"\"\n simple_fortran_subroutine = '''\n subroutine simple\n end\n '''\n config_cmd = self.get_config_cmd()\n flag = config_cmd.try_compile(simple_fortran_subroutine,lang='f90')\n return flag\n\n def append_to(self, extlib):\n \"\"\" Append libraries, include_dirs to extension or library item.\n \"\"\"\n if type(extlib) is type(()):\n lib_name, build_info = extlib\n dict_append(build_info,\n libraries=self.libraries,\n include_dirs=self.include_dirs)\n else:\n from numpy.distutils.core import Extension\n assert isinstance(extlib,Extension),`extlib`\n extlib.libraries.extend(self.libraries)\n extlib.include_dirs.extend(self.include_dirs)\n return\n\n def _get_svn_revision(self,path):\n \"\"\" Return path's SVN revision number.\n \"\"\"\n entries = os.path.join(path,'.svn','entries')\n revision = None\n if os.path.isfile(entries):\n f = open(entries)\n m = re.search(r'revision=\"(?P\\d+)\"',f.read())\n f.close()\n if m:\n revision = int(m.group('revision'))\n return revision\n\n def get_version(self):\n \"\"\" Try to get version string of a package.\n \"\"\"\n version = getattr(self,'version',None)\n if version is not None:\n return version\n\n # Get version from version file.\n files = ['__version__.py',\n self.name.split('.')[-1]+'_version.py',\n 'version.py',\n '__svn_version__.py']\n version_vars = ['version',\n '__version__',\n self.name.split('.')[-1]+'_version']\n for f in files:\n fn = os.path.join(self.local_path,f)\n if os.path.isfile(fn):\n info = (open(fn),fn,('.py','U',1))\n name = os.path.splitext(os.path.basename(fn))[0]\n n = dot_join(self.name,name)\n try:\n version_module = imp.load_module('_'.join(n.split('.')),*info)\n except ImportError,msg:\n print msg\n version_module = None\n if version_module is None:\n continue\n\n for a in version_vars:\n version = getattr(version_module,a,None)\n if version is not None:\n break\n if version is not None:\n break\n\n if version is not None:\n self.version = version\n return version\n\n # Get version as SVN revision number\n revision = self._get_svn_revision(self.local_path)\n if revision is not None:\n version = str(revision)\n self.version = version\n\n return version\n\n def make_svn_version_py(self):\n \"\"\" Generate package __svn_version__.py file from SVN revision number,\n it will be removed after python exits but will be available\n when sdist, etc commands are executed.\n\n If __svn_version__.py existed before, nothing is done.\n \"\"\"\n target = os.path.join(self.local_path,'__svn_version__.py')\n if os.path.isfile(target):\n return\n\n def generate_svn_version_py():\n if not os.path.isfile(target):\n revision = self._get_svn_revision(self.local_path)\n assert revision is not None,'hmm, why I am not inside SVN tree???'\n version = str(revision)\n print 'Creating %s (version=%r)' % (target,version)\n f = open(target,'w')\n f.write('version = %r\\n' % (version))\n f.close()\n \n import atexit\n def rm_file(f=target):\n try: os.remove(f); print 'removed',f\n except OSError: pass\n try: os.remove(f+'c'); print 'removed',f+'c'\n except OSError: pass\n atexit.register(rm_file)\n\n return target\n\n d = os.path.join(*(self.name.split('.')))\n self.add_data_files((d, generate_svn_version_py()))\n return\n\n def make_config_py(self,name='__config__'):\n \"\"\" Generate package __config__.py file containing system_info\n information used during building the package.\n \"\"\"\n self.py_modules.append((self.name,name,generate_config_py))\n return\n\n def get_info(self,*names):\n \"\"\" Get resources information.\n \"\"\"\n from system_info import get_info, dict_append\n info_dict = {}\n for a in names:\n dict_append(info_dict,**get_info(a))\n return info_dict\n\ndef get_cmd(cmdname,_cache={}):\n if not _cache.has_key(cmdname):\n import distutils.core\n dist = distutils.core._setup_distribution\n if dist is None:\n from distutils.errors import DistutilsInternalError\n raise DistutilsInternalError,\\\n 'setup distribution instance not initialized'\n cmd = dist.get_command_obj(cmdname)\n _cache[cmdname] = cmd\n return _cache[cmdname]\n\ndef get_numpy_include_dirs():\n # numpy_include_dirs are set by numpy/core/setup.py, otherwise []\n include_dirs = Configuration.numpy_include_dirs[:]\n if not include_dirs:\n import numpy\n if numpy.show_config is None:\n # running from numpy_core source directory\n include_dirs.append(os.path.join(os.path.dirname(numpy.__file__),\n 'core','include'))\n else:\n # using installed numpy core headers\n import numpy.core as core\n include_dirs.append(os.path.join(os.path.dirname(core.__file__),'include'))\n # else running numpy/core/setup.py\n return include_dirs\n\n#########################\n\ndef default_config_dict(name = None, parent_name = None, local_path=None):\n \"\"\" Return a configuration dictionary for usage in\n configuration() function defined in file setup_.py.\n \"\"\"\n import warnings\n warnings.warn('Use Configuration(%s,%s,top_path=%s) instead of '\\\n 'deprecated default_config_dict(%s,%s,%s)' \\\n % (`name`,`parent_name`,`local_path`,\n `name`,`parent_name`,`local_path`,\n ))\n c = Configuration(name, parent_name, local_path)\n return c.todict()\n\n\ndef dict_append(d,**kws):\n for k,v in kws.items():\n if d.has_key(k):\n d[k].extend(v)\n else:\n d[k] = v\n\ndef appendpath(prefix,path):\n if not ('/' == os.path.sep):\n prefix = prefix.replace('/',os.path.sep)\n path = path.replace('/',os.path.sep)\n drive = ''\n if os.path.isabs(path):\n drive = os.path.splitdrive(prefix)[0]\n absprefix = os.path.splitdrive(os.path.abspath(prefix))[1]\n pathdrive,path = os.path.splitdrive(path)\n d = os.path.commonprefix([absprefix,path])\n if os.path.join(absprefix[:len(d)],absprefix[len(d):])!=absprefix \\\n or os.path.join(path[:len(d)],path[len(d):])!=path:\n # Handle invalid paths\n d = os.path.dirname(d)\n subpath = path[len(d):]\n if os.path.isabs(subpath):\n subpath = subpath[1:]\n else:\n subpath = path\n return os.path.normpath(os.path.join(drive + prefix, subpath))\n\ndef generate_config_py(target):\n \"\"\" Generate config.py file containing system_info information\n used during building the package.\n\n Usage:\\\n config['py_modules'].append((packagename, '__config__',generate_config_py))\n \"\"\"\n from numpy.distutils.system_info import system_info\n from distutils.dir_util import mkpath\n mkpath(os.path.dirname(target))\n f = open(target,'w')\n f.write('# This file is generated by %s\\n' % (os.path.abspath(sys.argv[0])))\n f.write('# It contains system_info results at the time of building this package.\\n')\n f.write('__all__ = [\"get_info\",\"show\"]\\n\\n')\n for k,i in system_info.saved_results.items():\n f.write('%s=%r\\n' % (k,i))\n f.write('\\ndef get_info(name): g=globals(); return g.get(name,g.get(name+\"_info\",{}))\\n')\n f.write('''\ndef show():\n for name,info_dict in globals().items():\n if name[0]==\"_\" or type(info_dict) is not type({}): continue\n print name+\":\"\n if not info_dict:\n print \" NOT AVAILABLE\"\n for k,v in info_dict.items():\n v = str(v)\n if k==\\'sources\\' and len(v)>200: v = v[:60]+\\' ...\\\\n... \\'+v[-60:]\n print \\' %s = %s\\'%(k,v)\n print\n return\n ''')\n\n f.close()\n return target\n\ndef generate_svn_version_py(extension, build_dir):\n \"\"\" Generate __svn_version__.py file containing SVN\n revision number of a module.\n \n To use, add the following codelet to setup\n configuration(..) function\n\n ext = Extension(dot_join(config['name'],'__svn_version__'),\n sources=[generate_svn_version_py])\n ext.local_path = local_path\n config['ext_modules'].append(ext)\n\n \"\"\"\n from distutils import dep_util\n local_path = extension.local_path\n target = os.path.join(build_dir, '__svn_version__.py')\n entries = os.path.join(local_path,'.svn','entries')\n if os.path.isfile(entries):\n if not dep_util.newer(entries, target):\n return target\n elif os.path.isfile(target):\n return target\n\n revision = get_svn_revision(local_path)\n f = open(target,'w')\n f.write('revision=%s\\n' % (revision))\n f.close()\n return target\n", + "methods": [ + { + "name": "allpath", + "long_name": "allpath( name )", + "filename": "misc_util.py", + "nloc": 4, + "complexity": 1, + "token_count": 24, + "parameters": [ + "name" + ], + "start_line": 19, + "end_line": 22, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 4, + "top_nesting_level": 0 + }, + { + "name": "get_path", + "long_name": "get_path( mod_name , parent_path = None )", + "filename": "misc_util.py", + "nloc": 15, + "complexity": 6, + "token_count": 132, + "parameters": [ + "mod_name", + "parent_path" + ], + "start_line": 24, + "end_line": 44, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 21, + "top_nesting_level": 0 + }, + { + "name": "terminal_has_colors", + "long_name": "terminal_has_colors( )", + "filename": "misc_util.py", + "nloc": 18, + "complexity": 13, + "token_count": 137, + "parameters": [], + "start_line": 48, + "end_line": 73, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 26, + "top_nesting_level": 0 + }, + { + "name": "cyg2win32", + "long_name": "cyg2win32( path )", + "filename": "misc_util.py", + "nloc": 4, + "complexity": 3, + "token_count": 42, + "parameters": [ + "path" + ], + "start_line": 90, + "end_line": 93, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 4, + "top_nesting_level": 0 + }, + { + "name": "_get_f90_modules", + "long_name": "_get_f90_modules( source )", + "filename": "misc_util.py", + "nloc": 13, + "complexity": 4, + "token_count": 77, + "parameters": [ + "source" + ], + "start_line": 102, + "end_line": 118, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 17, + "top_nesting_level": 0 + }, + { + "name": "all_strings", + "long_name": "all_strings( lst )", + "filename": "misc_util.py", + "nloc": 5, + "complexity": 3, + "token_count": 26, + "parameters": [ + "lst" + ], + "start_line": 120, + "end_line": 125, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 6, + "top_nesting_level": 0 + }, + { + "name": "has_f_sources", + "long_name": "has_f_sources( sources )", + "filename": "misc_util.py", + "nloc": 5, + "complexity": 3, + "token_count": 21, + "parameters": [ + "sources" + ], + "start_line": 127, + "end_line": 132, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 6, + "top_nesting_level": 0 + }, + { + "name": "has_cxx_sources", + "long_name": "has_cxx_sources( sources )", + "filename": "misc_util.py", + "nloc": 5, + "complexity": 3, + "token_count": 21, + "parameters": [ + "sources" + ], + "start_line": 134, + "end_line": 139, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 6, + "top_nesting_level": 0 + }, + { + "name": "filter_sources", + "long_name": "filter_sources( sources )", + "filename": "misc_util.py", + "nloc": 17, + "complexity": 5, + "token_count": 84, + "parameters": [ + "sources" + ], + "start_line": 141, + "end_line": 161, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 21, + "top_nesting_level": 0 + }, + { + "name": "_get_headers", + "long_name": "_get_headers( directory_list )", + "filename": "misc_util.py", + "nloc": 6, + "complexity": 2, + "token_count": 39, + "parameters": [ + "directory_list" + ], + "start_line": 164, + "end_line": 170, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 7, + "top_nesting_level": 0 + }, + { + "name": "_get_directories", + "long_name": "_get_directories( list_of_sources )", + "filename": "misc_util.py", + "nloc": 7, + "complexity": 4, + "token_count": 51, + "parameters": [ + "list_of_sources" + ], + "start_line": 172, + "end_line": 179, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 8, + "top_nesting_level": 0 + }, + { + "name": "get_dependencies", + "long_name": "get_dependencies( sources )", + "filename": "misc_util.py", + "nloc": 2, + "complexity": 1, + "token_count": 13, + "parameters": [ + "sources" + ], + "start_line": 181, + "end_line": 183, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 3, + "top_nesting_level": 0 + }, + { + "name": "is_local_src_dir", + "long_name": "is_local_src_dir( directory )", + "filename": "misc_util.py", + "nloc": 12, + "complexity": 6, + "token_count": 112, + "parameters": [ + "directory" + ], + "start_line": 185, + "end_line": 198, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 14, + "top_nesting_level": 0 + }, + { + "name": "_gsf_visit_func", + "long_name": "_gsf_visit_func( filenames , dirname , names )", + "filename": "misc_util.py", + "nloc": 13, + "complexity": 7, + "token_count": 103, + "parameters": [ + "filenames", + "dirname", + "names" + ], + "start_line": 200, + "end_line": 212, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 13, + "top_nesting_level": 0 + }, + { + "name": "get_ext_source_files", + "long_name": "get_ext_source_files( ext )", + "filename": "misc_util.py", + "nloc": 11, + "complexity": 4, + "token_count": 87, + "parameters": [ + "ext" + ], + "start_line": 214, + "end_line": 225, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 12, + "top_nesting_level": 0 + }, + { + "name": "get_script_files", + "long_name": "get_script_files( scripts )", + "filename": "misc_util.py", + "nloc": 3, + "complexity": 1, + "token_count": 25, + "parameters": [ + "scripts" + ], + "start_line": 227, + "end_line": 229, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 3, + "top_nesting_level": 0 + }, + { + "name": "get_lib_source_files", + "long_name": "get_lib_source_files( lib )", + "filename": "misc_util.py", + "nloc": 13, + "complexity": 4, + "token_count": 111, + "parameters": [ + "lib" + ], + "start_line": 231, + "end_line": 243, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 13, + "top_nesting_level": 0 + }, + { + "name": "get_data_files", + "long_name": "get_data_files( data )", + "filename": "misc_util.py", + "nloc": 20, + "complexity": 8, + "token_count": 112, + "parameters": [ + "data" + ], + "start_line": 245, + "end_line": 264, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 20, + "top_nesting_level": 0 + }, + { + "name": "dot_join", + "long_name": "dot_join( * args )", + "filename": "misc_util.py", + "nloc": 2, + "complexity": 1, + "token_count": 18, + "parameters": [ + "args" + ], + "start_line": 266, + "end_line": 267, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 2, + "top_nesting_level": 0 + }, + { + "name": "get_frame", + "long_name": "get_frame( level = 0 )", + "filename": "misc_util.py", + "nloc": 8, + "complexity": 3, + "token_count": 50, + "parameters": [ + "level" + ], + "start_line": 269, + "end_line": 276, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 8, + "top_nesting_level": 0 + }, + { + "name": "__init__", + "long_name": "__init__( self , package_name = None , parent_name = None , top_path = None , package_path = None , ** attrs )", + "filename": "misc_util.py", + "nloc": 41, + "complexity": 11, + "token_count": 348, + "parameters": [ + "self", + "package_name", + "parent_name", + "top_path", + "package_path", + "attrs" + ], + "start_line": 288, + "end_line": 337, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 50, + "top_nesting_level": 1 + }, + { + "name": "todict", + "long_name": "todict( self )", + "filename": "misc_util.py", + "nloc": 9, + "complexity": 4, + "token_count": 57, + "parameters": [ + "self" + ], + "start_line": 339, + "end_line": 350, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 12, + "top_nesting_level": 1 + }, + { + "name": "__dict__", + "long_name": "__dict__( self )", + "filename": "misc_util.py", + "nloc": 2, + "complexity": 1, + "token_count": 11, + "parameters": [ + "self" + ], + "start_line": 352, + "end_line": 353, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 2, + "top_nesting_level": 1 + }, + { + "name": "get_distribution", + "long_name": "get_distribution( self )", + "filename": "misc_util.py", + "nloc": 4, + "complexity": 1, + "token_count": 18, + "parameters": [ + "self" + ], + "start_line": 355, + "end_line": 358, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 4, + "top_nesting_level": 1 + }, + { + "name": "get_subpackage", + "long_name": "get_subpackage( self , subpackage_name , subpackage_path = None )", + "filename": "misc_util.py", + "nloc": 50, + "complexity": 12, + "token_count": 453, + "parameters": [ + "self", + "subpackage_name", + "subpackage_path" + ], + "start_line": 360, + "end_line": 417, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 58, + "top_nesting_level": 1 + }, + { + "name": "add_subpackage", + "long_name": "add_subpackage( self , subpackage_name , subpackage_path = None )", + "filename": "misc_util.py", + "nloc": 20, + "complexity": 6, + "token_count": 127, + "parameters": [ + "self", + "subpackage_name", + "subpackage_path" + ], + "start_line": 419, + "end_line": 441, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 23, + "top_nesting_level": 1 + }, + { + "name": "add_data_dir", + "long_name": "add_data_dir( self , data_path )", + "filename": "misc_util.py", + "nloc": 25, + "complexity": 7, + "token_count": 188, + "parameters": [ + "self", + "data_path" + ], + "start_line": 443, + "end_line": 475, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 33, + "top_nesting_level": 1 + }, + { + "name": "add_data_files", + "long_name": "add_data_files( self , * files )", + "filename": "misc_util.py", + "nloc": 40, + "complexity": 15, + "token_count": 324, + "parameters": [ + "self", + "files" + ], + "start_line": 477, + "end_line": 527, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 51, + "top_nesting_level": 1 + }, + { + "name": "add_include_dirs", + "long_name": "add_include_dirs( self , * paths )", + "filename": "misc_util.py", + "nloc": 8, + "complexity": 2, + "token_count": 49, + "parameters": [ + "self", + "paths" + ], + "start_line": 531, + "end_line": 540, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 10, + "top_nesting_level": 1 + }, + { + "name": "add_headers", + "long_name": "add_headers( self , * files )", + "filename": "misc_util.py", + "nloc": 14, + "complexity": 7, + "token_count": 143, + "parameters": [ + "self", + "files" + ], + "start_line": 542, + "end_line": 561, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 20, + "top_nesting_level": 1 + }, + { + "name": "_fix_paths", + "long_name": "_fix_paths( self , paths )", + "filename": "misc_util.py", + "nloc": 22, + "complexity": 8, + "token_count": 136, + "parameters": [ + "self", + "paths" + ], + "start_line": 563, + "end_line": 584, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 22, + "top_nesting_level": 1 + }, + { + "name": "paths", + "long_name": "paths( self , * paths )", + "filename": "misc_util.py", + "nloc": 2, + "complexity": 1, + "token_count": 16, + "parameters": [ + "self", + "paths" + ], + "start_line": 586, + "end_line": 589, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 4, + "top_nesting_level": 1 + }, + { + "name": "add_extension", + "long_name": "add_extension( self , name , sources , ** kw )", + "filename": "misc_util.py", + "nloc": 45, + "complexity": 14, + "token_count": 365, + "parameters": [ + "self", + "name", + "sources", + "kw" + ], + "start_line": 591, + "end_line": 653, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 63, + "top_nesting_level": 1 + }, + { + "name": "add_library", + "long_name": "add_library( self , name , sources , ** build_info )", + "filename": "misc_util.py", + "nloc": 14, + "complexity": 4, + "token_count": 98, + "parameters": [ + "self", + "name", + "sources", + "build_info" + ], + "start_line": 655, + "end_line": 679, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 25, + "top_nesting_level": 1 + }, + { + "name": "add_scripts", + "long_name": "add_scripts( self , * files )", + "filename": "misc_util.py", + "nloc": 8, + "complexity": 2, + "token_count": 49, + "parameters": [ + "self", + "files" + ], + "start_line": 681, + "end_line": 690, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 10, + "top_nesting_level": 1 + }, + { + "name": "dict_append", + "long_name": "dict_append( self , ** dict )", + "filename": "misc_util.py", + "nloc": 15, + "complexity": 6, + "token_count": 138, + "parameters": [ + "self", + "dict" + ], + "start_line": 692, + "end_line": 706, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 15, + "top_nesting_level": 1 + }, + { + "name": "__str__", + "long_name": "__str__( self )", + "filename": "misc_util.py", + "nloc": 10, + "complexity": 3, + "token_count": 72, + "parameters": [ + "self" + ], + "start_line": 708, + "end_line": 717, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 10, + "top_nesting_level": 1 + }, + { + "name": "get_config_cmd", + "long_name": "get_config_cmd( self )", + "filename": "misc_util.py", + "nloc": 10, + "complexity": 2, + "token_count": 63, + "parameters": [ + "self" + ], + "start_line": 719, + "end_line": 728, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 10, + "top_nesting_level": 1 + }, + { + "name": "get_build_temp_dir", + "long_name": "get_build_temp_dir( self )", + "filename": "misc_util.py", + "nloc": 4, + "complexity": 1, + "token_count": 20, + "parameters": [ + "self" + ], + "start_line": 730, + "end_line": 733, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 4, + "top_nesting_level": 1 + }, + { + "name": "have_f77c", + "long_name": "have_f77c( self )", + "filename": "misc_util.py", + "nloc": 8, + "complexity": 1, + "token_count": 30, + "parameters": [ + "self" + ], + "start_line": 735, + "end_line": 746, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 12, + "top_nesting_level": 1 + }, + { + "name": "have_f90c", + "long_name": "have_f90c( self )", + "filename": "misc_util.py", + "nloc": 8, + "complexity": 1, + "token_count": 30, + "parameters": [ + "self" + ], + "start_line": 748, + "end_line": 759, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 12, + "top_nesting_level": 1 + }, + { + "name": "append_to", + "long_name": "append_to( self , extlib )", + "filename": "misc_util.py", + "nloc": 12, + "complexity": 2, + "token_count": 83, + "parameters": [ + "self", + "extlib" + ], + "start_line": 761, + "end_line": 774, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 14, + "top_nesting_level": 1 + }, + { + "name": "_get_svn_revision", + "long_name": "_get_svn_revision( self , path )", + "filename": "misc_util.py", + "nloc": 10, + "complexity": 3, + "token_count": 77, + "parameters": [ + "self", + "path" + ], + "start_line": 776, + "end_line": 787, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 12, + "top_nesting_level": 1 + }, + { + "name": "get_version", + "long_name": "get_version( self )", + "filename": "misc_util.py", + "nloc": 38, + "complexity": 11, + "token_count": 257, + "parameters": [ + "self" + ], + "start_line": 789, + "end_line": 835, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 47, + "top_nesting_level": 1 + }, + { + "name": "make_svn_version_py.make_svn_version_py.generate_svn_version_py.rm_file", + "long_name": "make_svn_version_py.make_svn_version_py.generate_svn_version_py.rm_file( f = target )", + "filename": "misc_util.py", + "nloc": 5, + "complexity": 3, + "token_count": 45, + "parameters": [ + "f" + ], + "start_line": 859, + "end_line": 863, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 5, + "top_nesting_level": 3 + }, + { + "name": "make_svn_version_py.generate_svn_version_py", + "long_name": "make_svn_version_py.generate_svn_version_py( )", + "filename": "misc_util.py", + "nloc": 13, + "complexity": 2, + "token_count": 81, + "parameters": [], + "start_line": 848, + "end_line": 866, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 19, + "top_nesting_level": 2 + }, + { + "name": "make_svn_version_py", + "long_name": "make_svn_version_py( self )", + "filename": "misc_util.py", + "nloc": 8, + "complexity": 2, + "token_count": 66, + "parameters": [ + "self" + ], + "start_line": 837, + "end_line": 870, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 34, + "top_nesting_level": 1 + }, + { + "name": "make_config_py", + "long_name": "make_config_py( self , name = '__config__' )", + "filename": "misc_util.py", + "nloc": 3, + "complexity": 1, + "token_count": 27, + "parameters": [ + "self", + "name" + ], + "start_line": 872, + "end_line": 877, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 6, + "top_nesting_level": 1 + }, + { + "name": "get_info", + "long_name": "get_info( self , * names )", + "filename": "misc_util.py", + "nloc": 6, + "complexity": 2, + "token_count": 36, + "parameters": [ + "self", + "names" + ], + "start_line": 879, + "end_line": 886, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 8, + "top_nesting_level": 1 + }, + { + "name": "get_cmd", + "long_name": "get_cmd( cmdname , _cache = { } )", + "filename": "misc_util.py", + "nloc": 11, + "complexity": 3, + "token_count": 65, + "parameters": [ + "cmdname", + "_cache" + ], + "start_line": 888, + "end_line": 898, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 11, + "top_nesting_level": 0 + }, + { + "name": "get_numpy_include_dirs", + "long_name": "get_numpy_include_dirs( )", + "filename": "misc_util.py", + "nloc": 11, + "complexity": 3, + "token_count": 85, + "parameters": [], + "start_line": 900, + "end_line": 914, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 15, + "top_nesting_level": 0 + }, + { + "name": "default_config_dict", + "long_name": "default_config_dict( name = None , parent_name = None , local_path = None )", + "filename": "misc_util.py", + "nloc": 9, + "complexity": 1, + "token_count": 70, + "parameters": [ + "name", + "parent_name", + "local_path" + ], + "start_line": 918, + "end_line": 929, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 12, + "top_nesting_level": 0 + }, + { + "name": "dict_append", + "long_name": "dict_append( d , ** kws )", + "filename": "misc_util.py", + "nloc": 6, + "complexity": 3, + "token_count": 44, + "parameters": [ + "d", + "kws" + ], + "start_line": 932, + "end_line": 937, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 6, + "top_nesting_level": 0 + }, + { + "name": "appendpath", + "long_name": "appendpath( prefix , path )", + "filename": "misc_util.py", + "nloc": 19, + "complexity": 6, + "token_count": 237, + "parameters": [ + "prefix", + "path" + ], + "start_line": 939, + "end_line": 958, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 20, + "top_nesting_level": 0 + }, + { + "name": "generate_config_py", + "long_name": "generate_config_py( target )", + "filename": "misc_util.py", + "nloc": 27, + "complexity": 2, + "token_count": 117, + "parameters": [ + "target" + ], + "start_line": 960, + "end_line": 993, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 34, + "top_nesting_level": 0 + }, + { + "name": "generate_svn_version_py", + "long_name": "generate_svn_version_py( extension , build_dir )", + "filename": "misc_util.py", + "nloc": 15, + "complexity": 4, + "token_count": 109, + "parameters": [ + "extension", + "build_dir" + ], + "start_line": 995, + "end_line": 1022, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 28, + "top_nesting_level": 0 + } + ], + "methods_before": [ + { + "name": "allpath", + "long_name": "allpath( name )", + "filename": "misc_util.py", + "nloc": 4, + "complexity": 1, + "token_count": 24, + "parameters": [ + "name" + ], + "start_line": 19, + "end_line": 22, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 4, + "top_nesting_level": 0 + }, + { + "name": "get_path", + "long_name": "get_path( mod_name , parent_path = None )", + "filename": "misc_util.py", + "nloc": 15, + "complexity": 6, + "token_count": 132, + "parameters": [ + "mod_name", + "parent_path" + ], + "start_line": 24, + "end_line": 44, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 21, + "top_nesting_level": 0 + }, + { + "name": "terminal_has_colors", + "long_name": "terminal_has_colors( )", + "filename": "misc_util.py", + "nloc": 18, + "complexity": 13, + "token_count": 137, + "parameters": [], + "start_line": 48, + "end_line": 73, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 26, + "top_nesting_level": 0 + }, + { + "name": "cyg2win32", + "long_name": "cyg2win32( path )", + "filename": "misc_util.py", + "nloc": 4, + "complexity": 3, + "token_count": 42, + "parameters": [ + "path" + ], + "start_line": 90, + "end_line": 93, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 4, + "top_nesting_level": 0 + }, + { + "name": "_get_f90_modules", + "long_name": "_get_f90_modules( source )", + "filename": "misc_util.py", + "nloc": 13, + "complexity": 4, + "token_count": 77, + "parameters": [ + "source" + ], + "start_line": 102, + "end_line": 118, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 17, + "top_nesting_level": 0 + }, + { + "name": "all_strings", + "long_name": "all_strings( lst )", + "filename": "misc_util.py", + "nloc": 5, + "complexity": 3, + "token_count": 26, + "parameters": [ + "lst" + ], + "start_line": 120, + "end_line": 125, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 6, + "top_nesting_level": 0 + }, + { + "name": "has_f_sources", + "long_name": "has_f_sources( sources )", + "filename": "misc_util.py", + "nloc": 5, + "complexity": 3, + "token_count": 21, + "parameters": [ + "sources" + ], + "start_line": 127, + "end_line": 132, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 6, + "top_nesting_level": 0 + }, + { + "name": "has_cxx_sources", + "long_name": "has_cxx_sources( sources )", + "filename": "misc_util.py", + "nloc": 5, + "complexity": 3, + "token_count": 21, + "parameters": [ + "sources" + ], + "start_line": 134, + "end_line": 139, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 6, + "top_nesting_level": 0 + }, + { + "name": "filter_sources", + "long_name": "filter_sources( sources )", + "filename": "misc_util.py", + "nloc": 17, + "complexity": 5, + "token_count": 84, + "parameters": [ + "sources" + ], + "start_line": 141, + "end_line": 161, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 21, + "top_nesting_level": 0 + }, + { + "name": "_get_headers", + "long_name": "_get_headers( directory_list )", + "filename": "misc_util.py", + "nloc": 6, + "complexity": 2, + "token_count": 39, + "parameters": [ + "directory_list" + ], + "start_line": 164, + "end_line": 170, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 7, + "top_nesting_level": 0 + }, + { + "name": "_get_directories", + "long_name": "_get_directories( list_of_sources )", + "filename": "misc_util.py", + "nloc": 7, + "complexity": 4, + "token_count": 51, + "parameters": [ + "list_of_sources" + ], + "start_line": 172, + "end_line": 179, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 8, + "top_nesting_level": 0 + }, + { + "name": "get_dependencies", + "long_name": "get_dependencies( sources )", + "filename": "misc_util.py", + "nloc": 2, + "complexity": 1, + "token_count": 13, + "parameters": [ + "sources" + ], + "start_line": 181, + "end_line": 183, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 3, + "top_nesting_level": 0 + }, + { + "name": "is_local_src_dir", + "long_name": "is_local_src_dir( directory )", + "filename": "misc_util.py", + "nloc": 12, + "complexity": 6, + "token_count": 112, + "parameters": [ + "directory" + ], + "start_line": 185, + "end_line": 198, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 14, + "top_nesting_level": 0 + }, + { + "name": "_gsf_visit_func", + "long_name": "_gsf_visit_func( filenames , dirname , names )", + "filename": "misc_util.py", + "nloc": 13, + "complexity": 7, + "token_count": 103, + "parameters": [ + "filenames", + "dirname", + "names" + ], + "start_line": 200, + "end_line": 212, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 13, + "top_nesting_level": 0 + }, + { + "name": "get_ext_source_files", + "long_name": "get_ext_source_files( ext )", + "filename": "misc_util.py", + "nloc": 11, + "complexity": 4, + "token_count": 87, + "parameters": [ + "ext" + ], + "start_line": 214, + "end_line": 225, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 12, + "top_nesting_level": 0 + }, + { + "name": "get_script_files", + "long_name": "get_script_files( scripts )", + "filename": "misc_util.py", + "nloc": 3, + "complexity": 1, + "token_count": 25, + "parameters": [ + "scripts" + ], + "start_line": 227, + "end_line": 229, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 3, + "top_nesting_level": 0 + }, + { + "name": "get_lib_source_files", + "long_name": "get_lib_source_files( lib )", + "filename": "misc_util.py", + "nloc": 13, + "complexity": 4, + "token_count": 111, + "parameters": [ + "lib" + ], + "start_line": 231, + "end_line": 243, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 13, + "top_nesting_level": 0 + }, + { + "name": "get_data_files", + "long_name": "get_data_files( data )", + "filename": "misc_util.py", + "nloc": 20, + "complexity": 8, + "token_count": 112, + "parameters": [ + "data" + ], + "start_line": 245, + "end_line": 264, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 20, + "top_nesting_level": 0 + }, + { + "name": "dot_join", + "long_name": "dot_join( * args )", + "filename": "misc_util.py", + "nloc": 2, + "complexity": 1, + "token_count": 18, + "parameters": [ + "args" + ], + "start_line": 266, + "end_line": 267, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 2, + "top_nesting_level": 0 + }, + { + "name": "get_frame", + "long_name": "get_frame( level = 0 )", + "filename": "misc_util.py", + "nloc": 8, + "complexity": 3, + "token_count": 50, + "parameters": [ + "level" + ], + "start_line": 269, + "end_line": 276, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 8, + "top_nesting_level": 0 + }, + { + "name": "__init__", + "long_name": "__init__( self , package_name = None , parent_name = None , top_path = None , package_path = None , ** attrs )", + "filename": "misc_util.py", + "nloc": 41, + "complexity": 11, + "token_count": 348, + "parameters": [ + "self", + "package_name", + "parent_name", + "top_path", + "package_path", + "attrs" + ], + "start_line": 288, + "end_line": 337, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 50, + "top_nesting_level": 1 + }, + { + "name": "todict", + "long_name": "todict( self )", + "filename": "misc_util.py", + "nloc": 9, + "complexity": 4, + "token_count": 57, + "parameters": [ + "self" + ], + "start_line": 339, + "end_line": 350, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 12, + "top_nesting_level": 1 + }, + { + "name": "__dict__", + "long_name": "__dict__( self )", + "filename": "misc_util.py", + "nloc": 2, + "complexity": 1, + "token_count": 11, + "parameters": [ + "self" + ], + "start_line": 352, + "end_line": 353, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 2, + "top_nesting_level": 1 + }, + { + "name": "get_distribution", + "long_name": "get_distribution( self )", + "filename": "misc_util.py", + "nloc": 4, + "complexity": 1, + "token_count": 18, + "parameters": [ + "self" + ], + "start_line": 355, + "end_line": 358, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 4, + "top_nesting_level": 1 + }, + { + "name": "get_subpackage", + "long_name": "get_subpackage( self , subpackage_name , subpackage_path = None )", + "filename": "misc_util.py", + "nloc": 50, + "complexity": 12, + "token_count": 453, + "parameters": [ + "self", + "subpackage_name", + "subpackage_path" + ], + "start_line": 360, + "end_line": 416, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 57, + "top_nesting_level": 1 + }, + { + "name": "add_subpackage", + "long_name": "add_subpackage( self , subpackage_name , subpackage_path = None )", + "filename": "misc_util.py", + "nloc": 20, + "complexity": 6, + "token_count": 127, + "parameters": [ + "self", + "subpackage_name", + "subpackage_path" + ], + "start_line": 418, + "end_line": 440, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 23, + "top_nesting_level": 1 + }, + { + "name": "add_data_dir", + "long_name": "add_data_dir( self , data_path )", + "filename": "misc_util.py", + "nloc": 25, + "complexity": 7, + "token_count": 188, + "parameters": [ + "self", + "data_path" + ], + "start_line": 442, + "end_line": 474, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 33, + "top_nesting_level": 1 + }, + { + "name": "add_data_files", + "long_name": "add_data_files( self , * files )", + "filename": "misc_util.py", + "nloc": 40, + "complexity": 15, + "token_count": 324, + "parameters": [ + "self", + "files" + ], + "start_line": 476, + "end_line": 526, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 51, + "top_nesting_level": 1 + }, + { + "name": "add_include_dirs", + "long_name": "add_include_dirs( self , * paths )", + "filename": "misc_util.py", + "nloc": 8, + "complexity": 2, + "token_count": 49, + "parameters": [ + "self", + "paths" + ], + "start_line": 530, + "end_line": 539, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 10, + "top_nesting_level": 1 + }, + { + "name": "add_headers", + "long_name": "add_headers( self , * files )", + "filename": "misc_util.py", + "nloc": 14, + "complexity": 7, + "token_count": 143, + "parameters": [ + "self", + "files" + ], + "start_line": 541, + "end_line": 560, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 20, + "top_nesting_level": 1 + }, + { + "name": "_fix_paths", + "long_name": "_fix_paths( self , paths )", + "filename": "misc_util.py", + "nloc": 22, + "complexity": 8, + "token_count": 136, + "parameters": [ + "self", + "paths" + ], + "start_line": 562, + "end_line": 583, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 22, + "top_nesting_level": 1 + }, + { + "name": "paths", + "long_name": "paths( self , * paths )", + "filename": "misc_util.py", + "nloc": 2, + "complexity": 1, + "token_count": 16, + "parameters": [ + "self", + "paths" + ], + "start_line": 585, + "end_line": 588, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 4, + "top_nesting_level": 1 + }, + { + "name": "add_extension", + "long_name": "add_extension( self , name , sources , ** kw )", + "filename": "misc_util.py", + "nloc": 45, + "complexity": 14, + "token_count": 365, + "parameters": [ + "self", + "name", + "sources", + "kw" + ], + "start_line": 590, + "end_line": 652, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 63, + "top_nesting_level": 1 + }, + { + "name": "add_library", + "long_name": "add_library( self , name , sources , ** build_info )", + "filename": "misc_util.py", + "nloc": 14, + "complexity": 4, + "token_count": 98, + "parameters": [ + "self", + "name", + "sources", + "build_info" + ], + "start_line": 654, + "end_line": 678, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 25, + "top_nesting_level": 1 + }, + { + "name": "add_scripts", + "long_name": "add_scripts( self , * files )", + "filename": "misc_util.py", + "nloc": 8, + "complexity": 2, + "token_count": 49, + "parameters": [ + "self", + "files" + ], + "start_line": 680, + "end_line": 689, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 10, + "top_nesting_level": 1 + }, + { + "name": "dict_append", + "long_name": "dict_append( self , ** dict )", + "filename": "misc_util.py", + "nloc": 15, + "complexity": 6, + "token_count": 138, + "parameters": [ + "self", + "dict" + ], + "start_line": 691, + "end_line": 705, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 15, + "top_nesting_level": 1 + }, + { + "name": "__str__", + "long_name": "__str__( self )", + "filename": "misc_util.py", + "nloc": 10, + "complexity": 3, + "token_count": 72, + "parameters": [ + "self" + ], + "start_line": 707, + "end_line": 716, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 10, + "top_nesting_level": 1 + }, + { + "name": "get_config_cmd", + "long_name": "get_config_cmd( self )", + "filename": "misc_util.py", + "nloc": 10, + "complexity": 2, + "token_count": 63, + "parameters": [ + "self" + ], + "start_line": 718, + "end_line": 727, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 10, + "top_nesting_level": 1 + }, + { + "name": "get_build_temp_dir", + "long_name": "get_build_temp_dir( self )", + "filename": "misc_util.py", + "nloc": 4, + "complexity": 1, + "token_count": 20, + "parameters": [ + "self" + ], + "start_line": 729, + "end_line": 732, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 4, + "top_nesting_level": 1 + }, + { + "name": "have_f77c", + "long_name": "have_f77c( self )", + "filename": "misc_util.py", + "nloc": 8, + "complexity": 1, + "token_count": 30, + "parameters": [ + "self" + ], + "start_line": 734, + "end_line": 745, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 12, + "top_nesting_level": 1 + }, + { + "name": "have_f90c", + "long_name": "have_f90c( self )", + "filename": "misc_util.py", + "nloc": 8, + "complexity": 1, + "token_count": 30, + "parameters": [ + "self" + ], + "start_line": 747, + "end_line": 758, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 12, + "top_nesting_level": 1 + }, + { + "name": "append_to", + "long_name": "append_to( self , extlib )", + "filename": "misc_util.py", + "nloc": 12, + "complexity": 2, + "token_count": 83, + "parameters": [ + "self", + "extlib" + ], + "start_line": 760, + "end_line": 773, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 14, + "top_nesting_level": 1 + }, + { + "name": "_get_svn_revision", + "long_name": "_get_svn_revision( self , path )", + "filename": "misc_util.py", + "nloc": 10, + "complexity": 3, + "token_count": 77, + "parameters": [ + "self", + "path" + ], + "start_line": 775, + "end_line": 786, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 12, + "top_nesting_level": 1 + }, + { + "name": "get_version", + "long_name": "get_version( self )", + "filename": "misc_util.py", + "nloc": 38, + "complexity": 11, + "token_count": 257, + "parameters": [ + "self" + ], + "start_line": 788, + "end_line": 834, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 47, + "top_nesting_level": 1 + }, + { + "name": "make_svn_version_py.make_svn_version_py.generate_svn_version_py.rm_file", + "long_name": "make_svn_version_py.make_svn_version_py.generate_svn_version_py.rm_file( f = target )", + "filename": "misc_util.py", + "nloc": 5, + "complexity": 3, + "token_count": 45, + "parameters": [ + "f" + ], + "start_line": 858, + "end_line": 862, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 5, + "top_nesting_level": 3 + }, + { + "name": "make_svn_version_py.generate_svn_version_py", + "long_name": "make_svn_version_py.generate_svn_version_py( )", + "filename": "misc_util.py", + "nloc": 13, + "complexity": 2, + "token_count": 81, + "parameters": [], + "start_line": 847, + "end_line": 865, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 19, + "top_nesting_level": 2 + }, + { + "name": "make_svn_version_py", + "long_name": "make_svn_version_py( self )", + "filename": "misc_util.py", + "nloc": 8, + "complexity": 2, + "token_count": 66, + "parameters": [ + "self" + ], + "start_line": 836, + "end_line": 869, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 34, + "top_nesting_level": 1 + }, + { + "name": "make_config_py", + "long_name": "make_config_py( self , name = '__config__' )", + "filename": "misc_util.py", + "nloc": 3, + "complexity": 1, + "token_count": 27, + "parameters": [ + "self", + "name" + ], + "start_line": 871, + "end_line": 876, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 6, + "top_nesting_level": 1 + }, + { + "name": "get_info", + "long_name": "get_info( self , * names )", + "filename": "misc_util.py", + "nloc": 6, + "complexity": 2, + "token_count": 36, + "parameters": [ + "self", + "names" + ], + "start_line": 878, + "end_line": 885, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 8, + "top_nesting_level": 1 + }, + { + "name": "get_cmd", + "long_name": "get_cmd( cmdname , _cache = { } )", + "filename": "misc_util.py", + "nloc": 11, + "complexity": 3, + "token_count": 65, + "parameters": [ + "cmdname", + "_cache" + ], + "start_line": 887, + "end_line": 897, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 11, + "top_nesting_level": 0 + }, + { + "name": "get_numpy_include_dirs", + "long_name": "get_numpy_include_dirs( )", + "filename": "misc_util.py", + "nloc": 11, + "complexity": 3, + "token_count": 85, + "parameters": [], + "start_line": 899, + "end_line": 913, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 15, + "top_nesting_level": 0 + }, + { + "name": "default_config_dict", + "long_name": "default_config_dict( name = None , parent_name = None , local_path = None )", + "filename": "misc_util.py", + "nloc": 9, + "complexity": 1, + "token_count": 70, + "parameters": [ + "name", + "parent_name", + "local_path" + ], + "start_line": 917, + "end_line": 928, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 12, + "top_nesting_level": 0 + }, + { + "name": "dict_append", + "long_name": "dict_append( d , ** kws )", + "filename": "misc_util.py", + "nloc": 6, + "complexity": 3, + "token_count": 44, + "parameters": [ + "d", + "kws" + ], + "start_line": 931, + "end_line": 936, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 6, + "top_nesting_level": 0 + }, + { + "name": "appendpath", + "long_name": "appendpath( prefix , path )", + "filename": "misc_util.py", + "nloc": 19, + "complexity": 6, + "token_count": 237, + "parameters": [ + "prefix", + "path" + ], + "start_line": 938, + "end_line": 957, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 20, + "top_nesting_level": 0 + }, + { + "name": "generate_config_py", + "long_name": "generate_config_py( target )", + "filename": "misc_util.py", + "nloc": 27, + "complexity": 2, + "token_count": 117, + "parameters": [ + "target" + ], + "start_line": 959, + "end_line": 992, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 34, + "top_nesting_level": 0 + }, + { + "name": "generate_svn_version_py", + "long_name": "generate_svn_version_py( extension , build_dir )", + "filename": "misc_util.py", + "nloc": 15, + "complexity": 4, + "token_count": 109, + "parameters": [ + "extension", + "build_dir" + ], + "start_line": 994, + "end_line": 1021, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 28, + "top_nesting_level": 0 + } + ], + "changed_methods": [ + { + "name": "get_subpackage", + "long_name": "get_subpackage( self , subpackage_name , subpackage_path = None )", + "filename": "misc_util.py", + "nloc": 50, + "complexity": 12, + "token_count": 453, + "parameters": [ + "self", + "subpackage_name", + "subpackage_path" + ], + "start_line": 360, + "end_line": 417, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 58, + "top_nesting_level": 1 + } + ], + "nloc": 770, + "complexity": 239, + "token_count": 5732, + "diff_parsed": { + "added": [ + " setup_py = os.path.join(subpackage_path,'setup.py')", + " setup_py = os.path.join(subpackage_path,'setup_%s.py' % (subpackage_name))", + "" + ], + "deleted": [ + " setup_py = os.path.join(subpackage_path,'setup_%s.py' % (subpackage_name))", + " setup_py = os.path.join(subpackage_path,'setup.py')" + ] + } + } + ] + }, + { + "hash": "b7cc1f63d4bd51ea8df16305d8213a10d7493f3a", + "msg": "Add ndindex iterator to complement ndenumerate iterator.", + "author": { + "name": "Travis Oliphant", + "email": "oliphant@enthought.com" + }, + "committer": { + "name": "Travis Oliphant", + "email": "oliphant@enthought.com" + }, + "author_date": "2006-01-27T01:00:48+00:00", + "author_timezone": 0, + "committer_date": "2006-01-27T01:00:48+00:00", + "committer_timezone": 0, + "branches": [ + "main" + ], + "in_main_branch": true, + "merge": false, + "parents": [ + "606c857c8e5c9ee844a58dd5919d14a6eaff191e" + ], + "project_name": "repo_copy", + "project_path": "/tmp/tmppy2o86q9/repo_copy", + "deletions": 1, + "insertions": 51, + "lines": 52, + "files": 1, + "dmm_unit_size": 1.0, + "dmm_unit_complexity": 1.0, + "dmm_unit_interfacing": 1.0, + "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": "@@ -1,6 +1,6 @@\n ## Automatically adapted for numpy Sep 19, 2005 by convertcode.py\n \n-__all__ = ['mgrid','ogrid','r_', 'c_', 'index_exp', 'ix_','ndenumerate']\n+__all__ = ['mgrid','ogrid','r_', 'c_', 'index_exp', 'ix_','ndenumerate','ndindex']\n \n import sys\n import types\n@@ -265,6 +265,56 @@ def next(self):\n def __iter__(self):\n return self\n \n+class 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", + "added_lines": 51, + "deleted_lines": 1, + "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 twodim_base as matrix_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\nr_=concatenator(0)\nr_.__doc__ = \"\"\"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\"\"\"\nc_=concatenator(-1)\nc_.__doc__ = \"\"\"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#row = concatenator(0,1)\n#col = concatenator(-1,1)\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\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']\n\nimport sys\nimport types\nimport numpy.core.numeric as _nx\nfrom numpy.core.numeric import asarray, ScalarType\n\nimport function_base\nimport twodim_base as matrix_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\nr_=concatenator(0)\nr_.__doc__ = \"\"\"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\"\"\"\nc_=concatenator(-1)\nc_.__doc__ = \"\"\"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#row = concatenator(0,1)\n#col = concatenator(-1,1)\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\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\n", + "methods": [ + { + "name": "ix_", + "long_name": "ix_( * args )", + "filename": "index_tricks.py", + "nloc": 13, + "complexity": 3, + "token_count": 91, + "parameters": [ + "args" + ], + "start_line": 15, + "end_line": 43, + "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": 83, + "end_line": 84, + "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": 85, + "end_line": 135, + "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": 137, + "end_line": 138, + "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": 140, + "end_line": 141, + "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": 149, + "end_line": 158, + "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": 160, + "end_line": 165, + "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": 167, + "end_line": 217, + "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": 219, + "end_line": 221, + "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": 223, + "end_line": 224, + "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": 259, + "end_line": 260, + "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": 262, + "end_line": 263, + "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": 265, + "end_line": 266, + "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": 285, + "end_line": 293, + "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": 295, + "end_line": 302, + "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": 304, + "end_line": 305, + "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": 307, + "end_line": 313, + "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": 315, + "end_line": 316, + "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": 345, + "end_line": 349, + "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": 351, + "end_line": 352, + "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": 354, + "end_line": 357, + "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": 91, + "parameters": [ + "args" + ], + "start_line": 15, + "end_line": 43, + "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": 83, + "end_line": 84, + "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": 85, + "end_line": 135, + "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": 137, + "end_line": 138, + "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": 140, + "end_line": 141, + "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": 149, + "end_line": 158, + "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": 160, + "end_line": 165, + "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": 167, + "end_line": 217, + "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": 219, + "end_line": 221, + "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": 223, + "end_line": 224, + "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": 259, + "end_line": 260, + "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": 262, + "end_line": 263, + "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": 265, + "end_line": 266, + "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": 295, + "end_line": 299, + "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": 301, + "end_line": 302, + "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": 304, + "end_line": 307, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 4, + "top_nesting_level": 1 + } + ], + "changed_methods": [ + { + "name": "__iter__", + "long_name": "__iter__( self )", + "filename": "index_tricks.py", + "nloc": 2, + "complexity": 1, + "token_count": 7, + "parameters": [ + "self" + ], + "start_line": 315, + "end_line": 316, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 2, + "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": 304, + "end_line": 305, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 2, + "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": 295, + "end_line": 302, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 8, + "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": 285, + "end_line": 293, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 9, + "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": 307, + "end_line": 313, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 7, + "top_nesting_level": 1 + } + ], + "nloc": 296, + "complexity": 66, + "token_count": 1563, + "diff_parsed": { + "added": [ + "__all__ = ['mgrid','ogrid','r_', 'c_', 'index_exp', 'ix_','ndenumerate','ndindex']", + "class ndindex(object):", + " \"\"\"Pass in a sequence of integers corresponding", + " to the number of dimensions in the counter. This iterator", + " will then return an N-dimensional counter.", + "", + " Example:", + " >>> for index in ndindex(4,3,2):", + " print index", + " (0,0,0)", + " (0,0,1)", + " (0,1,0)", + " ...", + " (3,1,1)", + " (3,2,0)", + " (3,2,1)", + " \"\"\"", + "", + " def __init__(self, *args):", + " self.nd = len(args)", + " self.ind = [0]*self.nd", + " self.index = 0", + " self.maxvals = args", + " tot = 1", + " for k in range(self.nd):", + " tot *= args[k]", + " self.total = tot", + "", + " def _incrementone(self, axis):", + " if (axis < 0): # base case", + " return", + " if (self.ind[axis] < self.maxvals[axis]-1):", + " self.ind[axis]+=1", + " else:", + " self.ind[axis] = 0", + " self._incrementone(axis-1)", + "", + " def ndincr(self):", + " self._incrementone(self.nd-1)", + "", + " def next(self):", + " if (self.index >= self.total):", + " raise StopIteration", + " val = tuple(self.ind)", + " self.index+=1", + " self.ndincr()", + " return val", + "", + " def __iter__(self):", + " return self", + "" + ], + "deleted": [ + "__all__ = ['mgrid','ogrid','r_', 'c_', 'index_exp', 'ix_','ndenumerate']" + ] + } + } + ] + }, + { + "hash": "6bf1820ba23583a96331dedc07338dc2ee78564b", + "msg": "Added data_files generator support - removed a piece of core.setup function.", + "author": { + "name": "Pearu Peterson", + "email": "pearu.peterson@gmail.com" + }, + "committer": { + "name": "Pearu Peterson", + "email": "pearu.peterson@gmail.com" + }, + "author_date": "2006-01-27T12:21:07+00:00", + "author_timezone": 0, + "committer_date": "2006-01-27T12:21:07+00:00", + "committer_timezone": 0, + "branches": [ + "main" + ], + "in_main_branch": true, + "merge": false, + "parents": [ + "b7cc1f63d4bd51ea8df16305d8213a10d7493f3a" + ], + "project_name": "repo_copy", + "project_path": "/tmp/tmppy2o86q9/repo_copy", + "deletions": 13, + "insertions": 39, + "lines": 52, + "files": 3, + "dmm_unit_size": 0.038461538461538464, + "dmm_unit_complexity": 0.038461538461538464, + "dmm_unit_interfacing": 1.0, + "modified_files": [ + { + "old_path": "numpy/distutils/command/build_src.py", + "new_path": "numpy/distutils/command/build_src.py", + "filename": "build_src.py", + "extension": "py", + "change_type": "MODIFY", + "diff": "@@ -61,6 +61,7 @@ def finalize_options(self):\n self.extensions = self.distribution.ext_modules\n self.libraries = self.distribution.libraries or []\n self.py_modules = self.distribution.py_modules or []\n+ self.data_files = self.distribution.data_files or []\n \n if self.build_src is None:\n self.build_src = os.path.join(self.build_base, 'src')\n@@ -102,9 +103,46 @@ def build_sources(self):\n for ext in self.extensions:\n self.build_extension_sources(ext)\n \n+ self.build_data_files_sources()\n+\n+ return\n+\n+ def build_data_files_sources(self):\n+ if not self.data_files:\n+ return\n+ log.info('building data_files sources')\n+ from numpy.distutils.misc_util import get_data_files\n+ new_data_files = []\n+ for data in self.data_files:\n+ if isinstance(data,str):\n+ new_data_files.append(data)\n+ elif isinstance(data,tuple):\n+ d,files = data\n+ funcs = filter(callable,files)\n+ files = filter(lambda f:not callable(f), files)\n+ for f in funcs:\n+ if f.func_code.co_argcount==1:\n+ s = f(os.path.join(self.build_src,d))\n+ else:\n+ s = f()\n+ if s is not None:\n+ if isinstance(s,list):\n+ files.extend(s)\n+ elif isinstance(s,str):\n+ files.append(s)\n+ else:\n+ raise TypeError,`s`\n+ filenames = get_data_files((d,files))\n+ new_data_files.append((d, filenames))\n+ else:\n+ raise\n+ self.data_files[:] = new_data_files\n return\n \n def build_py_modules_sources(self):\n+ if not self.py_modules:\n+ return\n+ log.info('building py_modules sources')\n new_py_modules = []\n for source in self.py_modules:\n if type(source) is type(()) and len(source)==3:\n", + "added_lines": 38, + "deleted_lines": 0, + "source_code": "\"\"\" Build swig, f2py, weave, sources.\n\"\"\"\n\nimport os\nimport re\nimport copy\n\nfrom distutils.cmd import Command\nfrom distutils.command import build_ext, build_py\nfrom distutils.util import convert_path\nfrom distutils.dep_util import newer_group, newer\n\nfrom numpy.distutils import log\nfrom numpy.distutils.misc_util import fortran_ext_match, all_strings, dot_join,\\\n appendpath\nfrom numpy.distutils.from_template import process_file as process_f_file\nfrom numpy.distutils.conv_template import process_file as process_c_file\nfrom numpy.distutils.extension import Extension\nfrom numpy.distutils.system_info import get_info, dict_append\n\nclass build_src(build_ext.build_ext):\n\n description = \"build sources from SWIG, F2PY files or a function\"\n\n user_options = [\n ('build-src=', 'd', \"directory to \\\"build\\\" sources to\"),\n ('f2pyflags=', None, \"additonal flags to f2py\"),\n ('swigflags=', None, \"additional flags to swig\"),\n ('force', 'f', \"forcibly build everything (ignore file timestamps)\"),\n ('inplace', 'i',\n \"ignore build-lib and put compiled extensions into the source \" +\n \"directory alongside your pure Python modules\"),\n ]\n\n boolean_options = ['force','inplace']\n\n help_options = []\n\n def initialize_options(self):\n self.extensions = None\n self.package = None\n self.py_modules = None\n self.py_modules_dict = None\n self.build_src = None\n self.build_lib = None\n self.build_base = None\n self.force = None\n self.inplace = None\n self.package_dir = None\n self.f2pyflags = None\n self.swigflags = None\n return\n\n def finalize_options(self):\n self.set_undefined_options('build',\n ('build_base', 'build_base'),\n ('build_lib', 'build_lib'),\n ('force', 'force'))\n if self.package is None:\n self.package = self.distribution.ext_package\n self.extensions = self.distribution.ext_modules\n self.libraries = self.distribution.libraries or []\n self.py_modules = self.distribution.py_modules or []\n self.data_files = self.distribution.data_files or []\n\n if self.build_src is None:\n self.build_src = os.path.join(self.build_base, 'src')\n if self.inplace is None:\n build_ext = self.get_finalized_command('build_ext')\n self.inplace = build_ext.inplace\n\n # py_modules_dict is used in build_py.find_package_modules\n self.py_modules_dict = {}\n\n if self.f2pyflags is None:\n self.f2pyflags = []\n else:\n self.f2pyflags = self.f2pyflags.split() # XXX spaces??\n\n if self.swigflags is None:\n self.swigflags = []\n else:\n self.swigflags = self.swigflags.split() # XXX spaces??\n return\n\n def run(self):\n if not (self.extensions or self.libraries):\n return\n self.build_sources()\n\n return\n \n def build_sources(self):\n\n self.build_py_modules_sources()\n\n for libname_info in self.libraries:\n self.build_library_sources(*libname_info)\n\n if self.extensions:\n self.check_extensions_list(self.extensions)\n\n for ext in self.extensions:\n self.build_extension_sources(ext)\n\n self.build_data_files_sources()\n\n return\n\n def build_data_files_sources(self):\n if not self.data_files:\n return\n log.info('building data_files sources')\n from numpy.distutils.misc_util import get_data_files\n new_data_files = []\n for data in self.data_files:\n if isinstance(data,str):\n new_data_files.append(data)\n elif isinstance(data,tuple):\n d,files = data\n funcs = filter(callable,files)\n files = filter(lambda f:not callable(f), files)\n for f in funcs:\n if f.func_code.co_argcount==1:\n s = f(os.path.join(self.build_src,d))\n else:\n s = f()\n if s is not None:\n if isinstance(s,list):\n files.extend(s)\n elif isinstance(s,str):\n files.append(s)\n else:\n raise TypeError,`s`\n filenames = get_data_files((d,files))\n new_data_files.append((d, filenames))\n else:\n raise\n self.data_files[:] = new_data_files\n return\n\n def build_py_modules_sources(self):\n if not self.py_modules:\n return\n log.info('building py_modules sources')\n new_py_modules = []\n for source in self.py_modules:\n if type(source) is type(()) and len(source)==3:\n package, module_base, source = source\n if callable(source):\n target = os.path.join(*([self.build_src]+\\\n package.split('.')+\\\n [module_base + '.py']))\n source = source(target)\n if source is None:\n continue\n modules = [(package, module_base, source)]\n if not self.py_modules_dict.has_key(package):\n self.py_modules_dict[package] = []\n self.py_modules_dict[package] += modules\n else:\n new_py_modules.append(source)\n self.py_modules[:] = new_py_modules\n return\n\n def build_library_sources(self, lib_name, build_info):\n sources = list(build_info.get('sources',[]))\n\n if not sources:\n return\n\n log.info('building library \"%s\" sources' % (lib_name))\n\n sources = self.generate_sources(sources, (lib_name, build_info))\n\n sources = self.template_sources(sources, (lib_name, build_info))\n\n sources, h_files = self.filter_h_files(sources)\n\n if h_files:\n print self.package,'- nothing done with h_files=',h_files\n\n #for f in h_files:\n # self.distribution.headers.append((lib_name,f))\n\n build_info['sources'] = sources\n return\n\n def build_extension_sources(self, ext):\n\n sources = list(ext.sources)\n\n log.info('building extension \"%s\" sources' % (ext.name))\n\n fullname = self.get_ext_fullname(ext.name)\n\n modpath = fullname.split('.')\n package = '.'.join(modpath[0:-1])\n\n\n if self.inplace:\n build_py = self.get_finalized_command('build_py')\n self.ext_target_dir = build_py.get_package_dir(package)\n\n\n sources = self.generate_sources(sources, ext)\n\n sources = self.template_sources(sources, ext)\n \n sources = self.swig_sources(sources, ext)\n\n sources = self.f2py_sources(sources, ext)\n\n sources, py_files = self.filter_py_files(sources)\n\n if not self.py_modules_dict.has_key(package):\n self.py_modules_dict[package] = []\n modules = []\n for f in py_files:\n module = os.path.splitext(os.path.basename(f))[0]\n modules.append((package, module, f))\n self.py_modules_dict[package] += modules\n\n sources, h_files = self.filter_h_files(sources)\n\n if h_files:\n print package,'- nothing done with h_files=',h_files\n #for f in h_files:\n # self.distribution.headers.append((package,f))\n\n ext.sources = sources\n\n return\n\n def generate_sources(self, sources, extension):\n new_sources = []\n func_sources = []\n for source in sources:\n if type(source) is type(''):\n new_sources.append(source)\n else:\n func_sources.append(source)\n if not func_sources:\n return new_sources\n if self.inplace:\n build_dir = self.ext_target_dir\n else:\n if type(extension) is type(()):\n name = extension[0]\n # if not extension[1].has_key('include_dirs'):\n # extension[1]['include_dirs'] = []\n # incl_dirs = extension[1]['include_dirs']\n else:\n name = extension.name\n # incl_dirs = extension.include_dirs\n #if self.build_src not in incl_dirs:\n # incl_dirs.append(self.build_src)\n build_dir = os.path.join(*([self.build_src]\\\n +name.split('.')[:-1]))\n self.mkpath(build_dir)\n for func in func_sources:\n source = func(extension, build_dir)\n if not source:\n continue\n if type(source) is type([]):\n [log.info(\" adding '%s' to sources.\" % (s)) for s in source]\n new_sources.extend(source)\n else:\n log.info(\" adding '%s' to sources.\" % (source))\n new_sources.append(source)\n\n return new_sources\n\n def filter_py_files(self, sources):\n return self.filter_files(sources,['.py'])\n\n def filter_h_files(self, sources):\n return self.filter_files(sources,['.h','.hpp','.inc'])\n\n def filter_files(self, sources, exts = []):\n new_sources = []\n files = []\n for source in sources:\n (base, ext) = os.path.splitext(source)\n if ext in exts: \n files.append(source)\n else:\n new_sources.append(source)\n return new_sources, files\n\n def template_sources(self, sources, extension):\n new_sources = []\n if type(extension) is type(()):\n depends = extension[1].get('depends')\n include_dirs = extension[1].get('include_dirs')\n else: \n depends = extension.depends\n include_dirs = extension.include_dirs\n for source in sources:\n (base, ext) = os.path.splitext(source)\n if ext == '.src': # Template file\n if self.inplace:\n target_dir = os.path.dirname(base)\n else:\n target_dir = appendpath(self.build_src, os.path.dirname(base))\n self.mkpath(target_dir)\n target_file = os.path.join(target_dir,os.path.basename(base))\n if (self.force or newer_group([source] + depends, target_file)):\n if _f_pyf_ext_match(base):\n log.info(\"from_template:> %s\" % (target_file))\n outstr = process_f_file(source)\n else:\n log.info(\"conv_template:> %s\" % (target_file))\n outstr = process_c_file(source)\n fid = open(target_file,'w')\n fid.write(outstr)\n fid.close()\n if _header_ext_match(target_file):\n d = os.path.dirname(target_file)\n if d not in include_dirs:\n log.info(\" adding '%s' to include_dirs.\" % (d))\n include_dirs.append(d)\n new_sources.append(target_file)\n else:\n new_sources.append(source)\n return new_sources \n \n def f2py_sources(self, sources, extension):\n new_sources = []\n f2py_sources = []\n f_sources = []\n f2py_targets = {}\n target_dirs = []\n ext_name = extension.name.split('.')[-1]\n skip_f2py = 0\n\n for source in sources:\n (base, ext) = os.path.splitext(source)\n if ext == '.pyf': # F2PY interface file\n if self.inplace:\n target_dir = os.path.dirname(base)\n else:\n target_dir = appendpath(self.build_src, os.path.dirname(base))\n if os.path.isfile(source):\n name = get_f2py_modulename(source)\n assert name==ext_name,'mismatch of extension names: '\\\n +source+' provides'\\\n ' '+`name`+' but expected '+`ext_name`\n target_file = os.path.join(target_dir,name+'module.c')\n else:\n log.debug(' source %s does not exist: skipping f2py\\'ing.' \\\n % (source))\n name = ext_name\n skip_f2py = 1\n target_file = os.path.join(target_dir,name+'module.c')\n if not os.path.isfile(target_file):\n log.debug(' target %s does not exist:\\n '\\\n 'Assuming %smodule.c was generated with '\\\n '\"build_src --inplace\" command.' \\\n % (target_file, name))\n target_dir = os.path.dirname(base)\n target_file = os.path.join(target_dir,name+'module.c')\n assert os.path.isfile(target_file),`target_file`+' missing'\n log.debug(' Yes! Using %s as up-to-date target.' \\\n % (target_file))\n target_dirs.append(target_dir)\n f2py_sources.append(source)\n f2py_targets[source] = target_file\n new_sources.append(target_file)\n elif fortran_ext_match(ext):\n f_sources.append(source)\n else:\n new_sources.append(source)\n\n if not (f2py_sources or f_sources):\n return new_sources\n\n map(self.mkpath, target_dirs)\n\n f2py_options = extension.f2py_options + self.f2pyflags\n\n if self.distribution.libraries:\n for name,build_info in self.distribution.libraries:\n if name in extension.libraries:\n f2py_options.extend(build_info.get('f2py_options',[]))\n\n log.info(\"f2py options: %s\" % (f2py_options))\n\n if f2py_sources:\n assert len(f2py_sources)==1,\\\n 'only one .pyf file is allowed per extension module but got'\\\n ' more:'+`f2py_sources`\n source = f2py_sources[0]\n target_file = f2py_targets[source]\n target_dir = os.path.dirname(target_file) or '.'\n depends = [source] + extension.depends\n if (self.force or newer_group(depends, target_file,'newer')) \\\n and not skip_f2py:\n log.info(\"f2py: %s\" % (source))\n import numpy.f2py as f2py2e\n f2py2e.run_main(f2py_options + ['--build-dir',target_dir,source])\n else:\n log.debug(\" skipping '%s' f2py interface (up-to-date)\" % (source))\n else:\n #XXX TODO: --inplace support for sdist command\n if type(extension) is type(()): name = extension[0]\n else: name = extension.name\n target_dir = os.path.join(*([self.build_src]\\\n +name.split('.')[:-1]))\n target_file = os.path.join(target_dir,ext_name + 'module.c')\n new_sources.append(target_file)\n depends = f_sources + extension.depends\n if (self.force or newer_group(depends, target_file, 'newer')) \\\n and not skip_f2py:\n import numpy.f2py as f2py2e\n log.info(\"f2py:> %s\" % (target_file))\n self.mkpath(target_dir)\n f2py2e.run_main(f2py_options + ['--lower',\n '--build-dir',target_dir]+\\\n ['-m',ext_name]+f_sources)\n else:\n log.debug(\" skipping f2py fortran files for '%s' (up-to-date)\"\\\n % (target_file))\n\n assert os.path.isfile(target_file),`target_file`+' missing'\n\n target_c = os.path.join(self.build_src,'fortranobject.c')\n target_h = os.path.join(self.build_src,'fortranobject.h')\n log.info(\" adding '%s' to sources.\" % (target_c))\n new_sources.append(target_c)\n if self.build_src not in extension.include_dirs:\n log.info(\" adding '%s' to include_dirs.\" \\\n % (self.build_src))\n extension.include_dirs.append(self.build_src)\n\n if not skip_f2py:\n import numpy.f2py as f2py2e\n d = os.path.dirname(f2py2e.__file__)\n source_c = os.path.join(d,'src','fortranobject.c')\n source_h = os.path.join(d,'src','fortranobject.h')\n if newer(source_c,target_c) or newer(source_h,target_h):\n self.mkpath(os.path.dirname(target_c))\n self.copy_file(source_c,target_c)\n self.copy_file(source_h,target_h)\n else:\n assert os.path.isfile(target_c),`target_c` + ' missing'\n assert os.path.isfile(target_h),`target_h` + ' missing'\n \n for name_ext in ['-f2pywrappers.f','-f2pywrappers2.f90']:\n filename = os.path.join(target_dir,ext_name + name_ext)\n if os.path.isfile(filename):\n log.info(\" adding '%s' to sources.\" % (filename))\n f_sources.append(filename)\n\n return new_sources + f_sources\n\n def swig_sources(self, sources, extension):\n # Assuming SWIG 1.3.14 or later. See compatibility note in\n # http://www.swig.org/Doc1.3/Python.html#Python_nn6\n\n new_sources = []\n swig_sources = []\n swig_targets = {}\n target_dirs = []\n py_files = [] # swig generated .py files\n target_ext = '.c'\n typ = None\n is_cpp = 0\n skip_swig = 0\n ext_name = extension.name.split('.')[-1]\n\n for source in sources:\n (base, ext) = os.path.splitext(source)\n if ext == '.i': # SWIG interface file\n if self.inplace:\n target_dir = os.path.dirname(base)\n py_target_dir = self.ext_target_dir\n else:\n target_dir = appendpath(self.build_src, os.path.dirname(base))\n py_target_dir = target_dir\n if os.path.isfile(source):\n name = get_swig_modulename(source)\n assert name==ext_name[1:],'mismatch of extension names: '\\\n +source+' provides'\\\n ' '+`name`+' but expected '+`ext_name[1:]`\n if typ is None:\n typ = get_swig_target(source)\n is_cpp = typ=='c++'\n if is_cpp:\n target_ext = '.cpp'\n else:\n assert typ == get_swig_target(source),`typ`\n target_file = os.path.join(target_dir,'%s_wrap%s' \\\n % (name, target_ext))\n else:\n log.debug(' source %s does not exist: skipping swig\\'ing.' \\\n % (source))\n name = ext_name[1:]\n skip_swig = 1\n target_file = _find_swig_target(target_dir, name)\n if not os.path.isfile(target_file):\n log.debug(' target %s does not exist:\\n '\\\n 'Assuming %s_wrap.{c,cpp} was generated with '\\\n '\"build_src --inplace\" command.' \\\n % (target_file, name))\n target_dir = os.path.dirname(base)\n target_file = _find_swig_target(target_dir, name)\n assert os.path.isfile(target_file),`target_file`+' missing'\n log.debug(' Yes! Using %s as up-to-date target.' \\\n % (target_file))\n target_dirs.append(target_dir)\n new_sources.append(target_file)\n py_files.append(os.path.join(py_target_dir, name+'.py'))\n swig_sources.append(source)\n swig_targets[source] = new_sources[-1]\n else:\n new_sources.append(source)\n\n if not swig_sources:\n return new_sources\n\n if skip_swig:\n return new_sources + py_files\n\n map(self.mkpath, target_dirs)\n swig = self.find_swig()\n swig_cmd = [swig, \"-python\"]\n if is_cpp:\n swig_cmd.append('-c++')\n for d in extension.include_dirs:\n swig_cmd.append('-I'+d)\n for source in swig_sources:\n target = swig_targets[source]\n depends = [source] + extension.depends\n if self.force or newer_group(depends, target, 'newer'):\n log.info(\"%s: %s\" % (os.path.basename(swig) \\\n + (is_cpp and '++' or ''), source))\n self.spawn(swig_cmd + self.swigflags \\\n + [\"-o\", target, '-outdir', py_target_dir, source])\n else:\n log.debug(\" skipping '%s' swig interface (up-to-date)\" \\\n % (source))\n\n return new_sources + py_files\n\n_f_pyf_ext_match = re.compile(r'.*[.](f90|f95|f77|for|ftn|f|pyf)\\Z',re.I).match\n_header_ext_match = re.compile(r'.*[.](inc|h|hpp)\\Z',re.I).match\n\n#### SWIG related auxiliary functions ####\n_swig_module_name_match = re.compile(r'\\s*%module\\s*(?P[\\w_]+)',\n re.I).match\n_has_c_header = re.compile(r'-[*]-\\s*c\\s*-[*]-',re.I).search\n_has_cpp_header = re.compile(r'-[*]-\\s*c[+][+]\\s*-[*]-',re.I).search\n\ndef get_swig_target(source):\n f = open(source,'r')\n result = 'c'\n line = f.readline()\n if _has_cpp_header(line):\n result = 'c++'\n if _has_c_header(line):\n result = 'c'\n f.close()\n return result\n\ndef get_swig_modulename(source):\n f = open(source,'r')\n f_readlines = getattr(f,'xreadlines',f.readlines)\n for line in f_readlines():\n m = _swig_module_name_match(line)\n if m:\n name = m.group('name')\n break\n f.close()\n return name\n\ndef _find_swig_target(target_dir,name):\n for ext in ['.cpp','.c']:\n target = os.path.join(target_dir,'%s_wrap%s' % (name, ext))\n if os.path.isfile(target):\n break\n return target\n\n#### F2PY related auxiliary functions ####\n\n_f2py_module_name_match = re.compile(r'\\s*python\\s*module\\s*(?P[\\w_]+)',\n re.I).match\n_f2py_user_module_name_match = re.compile(r'\\s*python\\s*module\\s*(?P[\\w_]*?'\\\n '__user__[\\w_]*)',re.I).match\n\ndef get_f2py_modulename(source):\n name = None\n f = open(source)\n f_readlines = getattr(f,'xreadlines',f.readlines)\n for line in f_readlines():\n m = _f2py_module_name_match(line)\n if m:\n if _f2py_user_module_name_match(line): # skip *__user__* names\n continue\n name = m.group('name')\n break\n f.close()\n return name\n\n##########################################\n", + "source_code_before": "\"\"\" Build swig, f2py, weave, sources.\n\"\"\"\n\nimport os\nimport re\nimport copy\n\nfrom distutils.cmd import Command\nfrom distutils.command import build_ext, build_py\nfrom distutils.util import convert_path\nfrom distutils.dep_util import newer_group, newer\n\nfrom numpy.distutils import log\nfrom numpy.distutils.misc_util import fortran_ext_match, all_strings, dot_join,\\\n appendpath\nfrom numpy.distutils.from_template import process_file as process_f_file\nfrom numpy.distutils.conv_template import process_file as process_c_file\nfrom numpy.distutils.extension import Extension\nfrom numpy.distutils.system_info import get_info, dict_append\n\nclass build_src(build_ext.build_ext):\n\n description = \"build sources from SWIG, F2PY files or a function\"\n\n user_options = [\n ('build-src=', 'd', \"directory to \\\"build\\\" sources to\"),\n ('f2pyflags=', None, \"additonal flags to f2py\"),\n ('swigflags=', None, \"additional flags to swig\"),\n ('force', 'f', \"forcibly build everything (ignore file timestamps)\"),\n ('inplace', 'i',\n \"ignore build-lib and put compiled extensions into the source \" +\n \"directory alongside your pure Python modules\"),\n ]\n\n boolean_options = ['force','inplace']\n\n help_options = []\n\n def initialize_options(self):\n self.extensions = None\n self.package = None\n self.py_modules = None\n self.py_modules_dict = None\n self.build_src = None\n self.build_lib = None\n self.build_base = None\n self.force = None\n self.inplace = None\n self.package_dir = None\n self.f2pyflags = None\n self.swigflags = None\n return\n\n def finalize_options(self):\n self.set_undefined_options('build',\n ('build_base', 'build_base'),\n ('build_lib', 'build_lib'),\n ('force', 'force'))\n if self.package is None:\n self.package = self.distribution.ext_package\n self.extensions = self.distribution.ext_modules\n self.libraries = self.distribution.libraries or []\n self.py_modules = self.distribution.py_modules or []\n\n if self.build_src is None:\n self.build_src = os.path.join(self.build_base, 'src')\n if self.inplace is None:\n build_ext = self.get_finalized_command('build_ext')\n self.inplace = build_ext.inplace\n\n # py_modules_dict is used in build_py.find_package_modules\n self.py_modules_dict = {}\n\n if self.f2pyflags is None:\n self.f2pyflags = []\n else:\n self.f2pyflags = self.f2pyflags.split() # XXX spaces??\n\n if self.swigflags is None:\n self.swigflags = []\n else:\n self.swigflags = self.swigflags.split() # XXX spaces??\n return\n\n def run(self):\n if not (self.extensions or self.libraries):\n return\n self.build_sources()\n\n return\n \n def build_sources(self):\n\n self.build_py_modules_sources()\n\n for libname_info in self.libraries:\n self.build_library_sources(*libname_info)\n\n if self.extensions:\n self.check_extensions_list(self.extensions)\n\n for ext in self.extensions:\n self.build_extension_sources(ext)\n\n return\n\n def build_py_modules_sources(self):\n new_py_modules = []\n for source in self.py_modules:\n if type(source) is type(()) and len(source)==3:\n package, module_base, source = source\n if callable(source):\n target = os.path.join(*([self.build_src]+\\\n package.split('.')+\\\n [module_base + '.py']))\n source = source(target)\n if source is None:\n continue\n modules = [(package, module_base, source)]\n if not self.py_modules_dict.has_key(package):\n self.py_modules_dict[package] = []\n self.py_modules_dict[package] += modules\n else:\n new_py_modules.append(source)\n self.py_modules[:] = new_py_modules\n return\n\n def build_library_sources(self, lib_name, build_info):\n sources = list(build_info.get('sources',[]))\n\n if not sources:\n return\n\n log.info('building library \"%s\" sources' % (lib_name))\n\n sources = self.generate_sources(sources, (lib_name, build_info))\n\n sources = self.template_sources(sources, (lib_name, build_info))\n\n sources, h_files = self.filter_h_files(sources)\n\n if h_files:\n print self.package,'- nothing done with h_files=',h_files\n\n #for f in h_files:\n # self.distribution.headers.append((lib_name,f))\n\n build_info['sources'] = sources\n return\n\n def build_extension_sources(self, ext):\n\n sources = list(ext.sources)\n\n log.info('building extension \"%s\" sources' % (ext.name))\n\n fullname = self.get_ext_fullname(ext.name)\n\n modpath = fullname.split('.')\n package = '.'.join(modpath[0:-1])\n\n\n if self.inplace:\n build_py = self.get_finalized_command('build_py')\n self.ext_target_dir = build_py.get_package_dir(package)\n\n\n sources = self.generate_sources(sources, ext)\n\n sources = self.template_sources(sources, ext)\n \n sources = self.swig_sources(sources, ext)\n\n sources = self.f2py_sources(sources, ext)\n\n sources, py_files = self.filter_py_files(sources)\n\n if not self.py_modules_dict.has_key(package):\n self.py_modules_dict[package] = []\n modules = []\n for f in py_files:\n module = os.path.splitext(os.path.basename(f))[0]\n modules.append((package, module, f))\n self.py_modules_dict[package] += modules\n\n sources, h_files = self.filter_h_files(sources)\n\n if h_files:\n print package,'- nothing done with h_files=',h_files\n #for f in h_files:\n # self.distribution.headers.append((package,f))\n\n ext.sources = sources\n\n return\n\n def generate_sources(self, sources, extension):\n new_sources = []\n func_sources = []\n for source in sources:\n if type(source) is type(''):\n new_sources.append(source)\n else:\n func_sources.append(source)\n if not func_sources:\n return new_sources\n if self.inplace:\n build_dir = self.ext_target_dir\n else:\n if type(extension) is type(()):\n name = extension[0]\n # if not extension[1].has_key('include_dirs'):\n # extension[1]['include_dirs'] = []\n # incl_dirs = extension[1]['include_dirs']\n else:\n name = extension.name\n # incl_dirs = extension.include_dirs\n #if self.build_src not in incl_dirs:\n # incl_dirs.append(self.build_src)\n build_dir = os.path.join(*([self.build_src]\\\n +name.split('.')[:-1]))\n self.mkpath(build_dir)\n for func in func_sources:\n source = func(extension, build_dir)\n if not source:\n continue\n if type(source) is type([]):\n [log.info(\" adding '%s' to sources.\" % (s)) for s in source]\n new_sources.extend(source)\n else:\n log.info(\" adding '%s' to sources.\" % (source))\n new_sources.append(source)\n\n return new_sources\n\n def filter_py_files(self, sources):\n return self.filter_files(sources,['.py'])\n\n def filter_h_files(self, sources):\n return self.filter_files(sources,['.h','.hpp','.inc'])\n\n def filter_files(self, sources, exts = []):\n new_sources = []\n files = []\n for source in sources:\n (base, ext) = os.path.splitext(source)\n if ext in exts: \n files.append(source)\n else:\n new_sources.append(source)\n return new_sources, files\n\n def template_sources(self, sources, extension):\n new_sources = []\n if type(extension) is type(()):\n depends = extension[1].get('depends')\n include_dirs = extension[1].get('include_dirs')\n else: \n depends = extension.depends\n include_dirs = extension.include_dirs\n for source in sources:\n (base, ext) = os.path.splitext(source)\n if ext == '.src': # Template file\n if self.inplace:\n target_dir = os.path.dirname(base)\n else:\n target_dir = appendpath(self.build_src, os.path.dirname(base))\n self.mkpath(target_dir)\n target_file = os.path.join(target_dir,os.path.basename(base))\n if (self.force or newer_group([source] + depends, target_file)):\n if _f_pyf_ext_match(base):\n log.info(\"from_template:> %s\" % (target_file))\n outstr = process_f_file(source)\n else:\n log.info(\"conv_template:> %s\" % (target_file))\n outstr = process_c_file(source)\n fid = open(target_file,'w')\n fid.write(outstr)\n fid.close()\n if _header_ext_match(target_file):\n d = os.path.dirname(target_file)\n if d not in include_dirs:\n log.info(\" adding '%s' to include_dirs.\" % (d))\n include_dirs.append(d)\n new_sources.append(target_file)\n else:\n new_sources.append(source)\n return new_sources \n \n def f2py_sources(self, sources, extension):\n new_sources = []\n f2py_sources = []\n f_sources = []\n f2py_targets = {}\n target_dirs = []\n ext_name = extension.name.split('.')[-1]\n skip_f2py = 0\n\n for source in sources:\n (base, ext) = os.path.splitext(source)\n if ext == '.pyf': # F2PY interface file\n if self.inplace:\n target_dir = os.path.dirname(base)\n else:\n target_dir = appendpath(self.build_src, os.path.dirname(base))\n if os.path.isfile(source):\n name = get_f2py_modulename(source)\n assert name==ext_name,'mismatch of extension names: '\\\n +source+' provides'\\\n ' '+`name`+' but expected '+`ext_name`\n target_file = os.path.join(target_dir,name+'module.c')\n else:\n log.debug(' source %s does not exist: skipping f2py\\'ing.' \\\n % (source))\n name = ext_name\n skip_f2py = 1\n target_file = os.path.join(target_dir,name+'module.c')\n if not os.path.isfile(target_file):\n log.debug(' target %s does not exist:\\n '\\\n 'Assuming %smodule.c was generated with '\\\n '\"build_src --inplace\" command.' \\\n % (target_file, name))\n target_dir = os.path.dirname(base)\n target_file = os.path.join(target_dir,name+'module.c')\n assert os.path.isfile(target_file),`target_file`+' missing'\n log.debug(' Yes! Using %s as up-to-date target.' \\\n % (target_file))\n target_dirs.append(target_dir)\n f2py_sources.append(source)\n f2py_targets[source] = target_file\n new_sources.append(target_file)\n elif fortran_ext_match(ext):\n f_sources.append(source)\n else:\n new_sources.append(source)\n\n if not (f2py_sources or f_sources):\n return new_sources\n\n map(self.mkpath, target_dirs)\n\n f2py_options = extension.f2py_options + self.f2pyflags\n\n if self.distribution.libraries:\n for name,build_info in self.distribution.libraries:\n if name in extension.libraries:\n f2py_options.extend(build_info.get('f2py_options',[]))\n\n log.info(\"f2py options: %s\" % (f2py_options))\n\n if f2py_sources:\n assert len(f2py_sources)==1,\\\n 'only one .pyf file is allowed per extension module but got'\\\n ' more:'+`f2py_sources`\n source = f2py_sources[0]\n target_file = f2py_targets[source]\n target_dir = os.path.dirname(target_file) or '.'\n depends = [source] + extension.depends\n if (self.force or newer_group(depends, target_file,'newer')) \\\n and not skip_f2py:\n log.info(\"f2py: %s\" % (source))\n import numpy.f2py as f2py2e\n f2py2e.run_main(f2py_options + ['--build-dir',target_dir,source])\n else:\n log.debug(\" skipping '%s' f2py interface (up-to-date)\" % (source))\n else:\n #XXX TODO: --inplace support for sdist command\n if type(extension) is type(()): name = extension[0]\n else: name = extension.name\n target_dir = os.path.join(*([self.build_src]\\\n +name.split('.')[:-1]))\n target_file = os.path.join(target_dir,ext_name + 'module.c')\n new_sources.append(target_file)\n depends = f_sources + extension.depends\n if (self.force or newer_group(depends, target_file, 'newer')) \\\n and not skip_f2py:\n import numpy.f2py as f2py2e\n log.info(\"f2py:> %s\" % (target_file))\n self.mkpath(target_dir)\n f2py2e.run_main(f2py_options + ['--lower',\n '--build-dir',target_dir]+\\\n ['-m',ext_name]+f_sources)\n else:\n log.debug(\" skipping f2py fortran files for '%s' (up-to-date)\"\\\n % (target_file))\n\n assert os.path.isfile(target_file),`target_file`+' missing'\n\n target_c = os.path.join(self.build_src,'fortranobject.c')\n target_h = os.path.join(self.build_src,'fortranobject.h')\n log.info(\" adding '%s' to sources.\" % (target_c))\n new_sources.append(target_c)\n if self.build_src not in extension.include_dirs:\n log.info(\" adding '%s' to include_dirs.\" \\\n % (self.build_src))\n extension.include_dirs.append(self.build_src)\n\n if not skip_f2py:\n import numpy.f2py as f2py2e\n d = os.path.dirname(f2py2e.__file__)\n source_c = os.path.join(d,'src','fortranobject.c')\n source_h = os.path.join(d,'src','fortranobject.h')\n if newer(source_c,target_c) or newer(source_h,target_h):\n self.mkpath(os.path.dirname(target_c))\n self.copy_file(source_c,target_c)\n self.copy_file(source_h,target_h)\n else:\n assert os.path.isfile(target_c),`target_c` + ' missing'\n assert os.path.isfile(target_h),`target_h` + ' missing'\n \n for name_ext in ['-f2pywrappers.f','-f2pywrappers2.f90']:\n filename = os.path.join(target_dir,ext_name + name_ext)\n if os.path.isfile(filename):\n log.info(\" adding '%s' to sources.\" % (filename))\n f_sources.append(filename)\n\n return new_sources + f_sources\n\n def swig_sources(self, sources, extension):\n # Assuming SWIG 1.3.14 or later. See compatibility note in\n # http://www.swig.org/Doc1.3/Python.html#Python_nn6\n\n new_sources = []\n swig_sources = []\n swig_targets = {}\n target_dirs = []\n py_files = [] # swig generated .py files\n target_ext = '.c'\n typ = None\n is_cpp = 0\n skip_swig = 0\n ext_name = extension.name.split('.')[-1]\n\n for source in sources:\n (base, ext) = os.path.splitext(source)\n if ext == '.i': # SWIG interface file\n if self.inplace:\n target_dir = os.path.dirname(base)\n py_target_dir = self.ext_target_dir\n else:\n target_dir = appendpath(self.build_src, os.path.dirname(base))\n py_target_dir = target_dir\n if os.path.isfile(source):\n name = get_swig_modulename(source)\n assert name==ext_name[1:],'mismatch of extension names: '\\\n +source+' provides'\\\n ' '+`name`+' but expected '+`ext_name[1:]`\n if typ is None:\n typ = get_swig_target(source)\n is_cpp = typ=='c++'\n if is_cpp:\n target_ext = '.cpp'\n else:\n assert typ == get_swig_target(source),`typ`\n target_file = os.path.join(target_dir,'%s_wrap%s' \\\n % (name, target_ext))\n else:\n log.debug(' source %s does not exist: skipping swig\\'ing.' \\\n % (source))\n name = ext_name[1:]\n skip_swig = 1\n target_file = _find_swig_target(target_dir, name)\n if not os.path.isfile(target_file):\n log.debug(' target %s does not exist:\\n '\\\n 'Assuming %s_wrap.{c,cpp} was generated with '\\\n '\"build_src --inplace\" command.' \\\n % (target_file, name))\n target_dir = os.path.dirname(base)\n target_file = _find_swig_target(target_dir, name)\n assert os.path.isfile(target_file),`target_file`+' missing'\n log.debug(' Yes! Using %s as up-to-date target.' \\\n % (target_file))\n target_dirs.append(target_dir)\n new_sources.append(target_file)\n py_files.append(os.path.join(py_target_dir, name+'.py'))\n swig_sources.append(source)\n swig_targets[source] = new_sources[-1]\n else:\n new_sources.append(source)\n\n if not swig_sources:\n return new_sources\n\n if skip_swig:\n return new_sources + py_files\n\n map(self.mkpath, target_dirs)\n swig = self.find_swig()\n swig_cmd = [swig, \"-python\"]\n if is_cpp:\n swig_cmd.append('-c++')\n for d in extension.include_dirs:\n swig_cmd.append('-I'+d)\n for source in swig_sources:\n target = swig_targets[source]\n depends = [source] + extension.depends\n if self.force or newer_group(depends, target, 'newer'):\n log.info(\"%s: %s\" % (os.path.basename(swig) \\\n + (is_cpp and '++' or ''), source))\n self.spawn(swig_cmd + self.swigflags \\\n + [\"-o\", target, '-outdir', py_target_dir, source])\n else:\n log.debug(\" skipping '%s' swig interface (up-to-date)\" \\\n % (source))\n\n return new_sources + py_files\n\n_f_pyf_ext_match = re.compile(r'.*[.](f90|f95|f77|for|ftn|f|pyf)\\Z',re.I).match\n_header_ext_match = re.compile(r'.*[.](inc|h|hpp)\\Z',re.I).match\n\n#### SWIG related auxiliary functions ####\n_swig_module_name_match = re.compile(r'\\s*%module\\s*(?P[\\w_]+)',\n re.I).match\n_has_c_header = re.compile(r'-[*]-\\s*c\\s*-[*]-',re.I).search\n_has_cpp_header = re.compile(r'-[*]-\\s*c[+][+]\\s*-[*]-',re.I).search\n\ndef get_swig_target(source):\n f = open(source,'r')\n result = 'c'\n line = f.readline()\n if _has_cpp_header(line):\n result = 'c++'\n if _has_c_header(line):\n result = 'c'\n f.close()\n return result\n\ndef get_swig_modulename(source):\n f = open(source,'r')\n f_readlines = getattr(f,'xreadlines',f.readlines)\n for line in f_readlines():\n m = _swig_module_name_match(line)\n if m:\n name = m.group('name')\n break\n f.close()\n return name\n\ndef _find_swig_target(target_dir,name):\n for ext in ['.cpp','.c']:\n target = os.path.join(target_dir,'%s_wrap%s' % (name, ext))\n if os.path.isfile(target):\n break\n return target\n\n#### F2PY related auxiliary functions ####\n\n_f2py_module_name_match = re.compile(r'\\s*python\\s*module\\s*(?P[\\w_]+)',\n re.I).match\n_f2py_user_module_name_match = re.compile(r'\\s*python\\s*module\\s*(?P[\\w_]*?'\\\n '__user__[\\w_]*)',re.I).match\n\ndef get_f2py_modulename(source):\n name = None\n f = open(source)\n f_readlines = getattr(f,'xreadlines',f.readlines)\n for line in f_readlines():\n m = _f2py_module_name_match(line)\n if m:\n if _f2py_user_module_name_match(line): # skip *__user__* names\n continue\n name = m.group('name')\n break\n f.close()\n return name\n\n##########################################\n", + "methods": [ + { + "name": "initialize_options", + "long_name": "initialize_options( self )", + "filename": "build_src.py", + "nloc": 14, + "complexity": 1, + "token_count": 66, + "parameters": [ + "self" + ], + "start_line": 39, + "end_line": 52, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 14, + "top_nesting_level": 1 + }, + { + "name": "finalize_options", + "long_name": "finalize_options( self )", + "filename": "build_src.py", + "nloc": 26, + "complexity": 9, + "token_count": 194, + "parameters": [ + "self" + ], + "start_line": 54, + "end_line": 84, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 31, + "top_nesting_level": 1 + }, + { + "name": "run", + "long_name": "run( self )", + "filename": "build_src.py", + "nloc": 5, + "complexity": 3, + "token_count": 24, + "parameters": [ + "self" + ], + "start_line": 86, + "end_line": 91, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 6, + "top_nesting_level": 1 + }, + { + "name": "build_sources", + "long_name": "build_sources( self )", + "filename": "build_src.py", + "nloc": 10, + "complexity": 4, + "token_count": 56, + "parameters": [ + "self" + ], + "start_line": 93, + "end_line": 108, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 16, + "top_nesting_level": 1 + }, + { + "name": "build_data_files_sources", + "long_name": "build_data_files_sources( self )", + "filename": "build_src.py", + "nloc": 31, + "complexity": 10, + "token_count": 199, + "parameters": [ + "self" + ], + "start_line": 110, + "end_line": 140, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 31, + "top_nesting_level": 1 + }, + { + "name": "build_py_modules_sources", + "long_name": "build_py_modules_sources( self )", + "filename": "build_src.py", + "nloc": 23, + "complexity": 8, + "token_count": 161, + "parameters": [ + "self" + ], + "start_line": 142, + "end_line": 164, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 23, + "top_nesting_level": 1 + }, + { + "name": "build_library_sources", + "long_name": "build_library_sources( self , lib_name , build_info )", + "filename": "build_src.py", + "nloc": 12, + "complexity": 3, + "token_count": 94, + "parameters": [ + "self", + "lib_name", + "build_info" + ], + "start_line": 166, + "end_line": 187, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 22, + "top_nesting_level": 1 + }, + { + "name": "build_extension_sources", + "long_name": "build_extension_sources( self , ext )", + "filename": "build_src.py", + "nloc": 26, + "complexity": 5, + "token_count": 226, + "parameters": [ + "self", + "ext" + ], + "start_line": 189, + "end_line": 233, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 45, + "top_nesting_level": 1 + }, + { + "name": "generate_sources", + "long_name": "generate_sources( self , sources , extension )", + "filename": "build_src.py", + "nloc": 31, + "complexity": 10, + "token_count": 198, + "parameters": [ + "self", + "sources", + "extension" + ], + "start_line": 235, + "end_line": 272, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 38, + "top_nesting_level": 1 + }, + { + "name": "filter_py_files", + "long_name": "filter_py_files( self , sources )", + "filename": "build_src.py", + "nloc": 2, + "complexity": 1, + "token_count": 18, + "parameters": [ + "self", + "sources" + ], + "start_line": 274, + "end_line": 275, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 2, + "top_nesting_level": 1 + }, + { + "name": "filter_h_files", + "long_name": "filter_h_files( self , sources )", + "filename": "build_src.py", + "nloc": 2, + "complexity": 1, + "token_count": 22, + "parameters": [ + "self", + "sources" + ], + "start_line": 277, + "end_line": 278, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 2, + "top_nesting_level": 1 + }, + { + "name": "filter_files", + "long_name": "filter_files( self , sources , exts = [ ] )", + "filename": "build_src.py", + "nloc": 10, + "complexity": 3, + "token_count": 62, + "parameters": [ + "self", + "sources", + "exts" + ], + "start_line": 280, + "end_line": 289, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 10, + "top_nesting_level": 1 + }, + { + "name": "template_sources", + "long_name": "template_sources( self , sources , extension )", + "filename": "build_src.py", + "nloc": 36, + "complexity": 10, + "token_count": 273, + "parameters": [ + "self", + "sources", + "extension" + ], + "start_line": 291, + "end_line": 326, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 36, + "top_nesting_level": 1 + }, + { + "name": "f2py_sources", + "long_name": "f2py_sources( self , sources , extension )", + "filename": "build_src.py", + "nloc": 115, + "complexity": 27, + "token_count": 935, + "parameters": [ + "self", + "sources", + "extension" + ], + "start_line": 328, + "end_line": 455, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 128, + "top_nesting_level": 1 + }, + { + "name": "swig_sources", + "long_name": "swig_sources( self , sources , extension )", + "filename": "build_src.py", + "nloc": 80, + "complexity": 17, + "token_count": 539, + "parameters": [ + "self", + "sources", + "extension" + ], + "start_line": 457, + "end_line": 544, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 88, + "top_nesting_level": 1 + }, + { + "name": "get_swig_target", + "long_name": "get_swig_target( source )", + "filename": "build_src.py", + "nloc": 10, + "complexity": 3, + "token_count": 48, + "parameters": [ + "source" + ], + "start_line": 555, + "end_line": 564, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 10, + "top_nesting_level": 0 + }, + { + "name": "get_swig_modulename", + "long_name": "get_swig_modulename( source )", + "filename": "build_src.py", + "nloc": 10, + "complexity": 3, + "token_count": 57, + "parameters": [ + "source" + ], + "start_line": 566, + "end_line": 575, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 10, + "top_nesting_level": 0 + }, + { + "name": "_find_swig_target", + "long_name": "_find_swig_target( target_dir , name )", + "filename": "build_src.py", + "nloc": 6, + "complexity": 3, + "token_count": 47, + "parameters": [ + "target_dir", + "name" + ], + "start_line": 577, + "end_line": 582, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 6, + "top_nesting_level": 0 + }, + { + "name": "get_f2py_modulename", + "long_name": "get_f2py_modulename( source )", + "filename": "build_src.py", + "nloc": 13, + "complexity": 4, + "token_count": 65, + "parameters": [ + "source" + ], + "start_line": 591, + "end_line": 603, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 13, + "top_nesting_level": 0 + } + ], + "methods_before": [ + { + "name": "initialize_options", + "long_name": "initialize_options( self )", + "filename": "build_src.py", + "nloc": 14, + "complexity": 1, + "token_count": 66, + "parameters": [ + "self" + ], + "start_line": 39, + "end_line": 52, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 14, + "top_nesting_level": 1 + }, + { + "name": "finalize_options", + "long_name": "finalize_options( self )", + "filename": "build_src.py", + "nloc": 25, + "complexity": 8, + "token_count": 182, + "parameters": [ + "self" + ], + "start_line": 54, + "end_line": 83, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 30, + "top_nesting_level": 1 + }, + { + "name": "run", + "long_name": "run( self )", + "filename": "build_src.py", + "nloc": 5, + "complexity": 3, + "token_count": 24, + "parameters": [ + "self" + ], + "start_line": 85, + "end_line": 90, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 6, + "top_nesting_level": 1 + }, + { + "name": "build_sources", + "long_name": "build_sources( self )", + "filename": "build_src.py", + "nloc": 9, + "complexity": 4, + "token_count": 51, + "parameters": [ + "self" + ], + "start_line": 92, + "end_line": 105, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 14, + "top_nesting_level": 1 + }, + { + "name": "build_py_modules_sources", + "long_name": "build_py_modules_sources( self )", + "filename": "build_src.py", + "nloc": 20, + "complexity": 7, + "token_count": 148, + "parameters": [ + "self" + ], + "start_line": 107, + "end_line": 126, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 20, + "top_nesting_level": 1 + }, + { + "name": "build_library_sources", + "long_name": "build_library_sources( self , lib_name , build_info )", + "filename": "build_src.py", + "nloc": 12, + "complexity": 3, + "token_count": 94, + "parameters": [ + "self", + "lib_name", + "build_info" + ], + "start_line": 128, + "end_line": 149, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 22, + "top_nesting_level": 1 + }, + { + "name": "build_extension_sources", + "long_name": "build_extension_sources( self , ext )", + "filename": "build_src.py", + "nloc": 26, + "complexity": 5, + "token_count": 226, + "parameters": [ + "self", + "ext" + ], + "start_line": 151, + "end_line": 195, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 45, + "top_nesting_level": 1 + }, + { + "name": "generate_sources", + "long_name": "generate_sources( self , sources , extension )", + "filename": "build_src.py", + "nloc": 31, + "complexity": 10, + "token_count": 198, + "parameters": [ + "self", + "sources", + "extension" + ], + "start_line": 197, + "end_line": 234, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 38, + "top_nesting_level": 1 + }, + { + "name": "filter_py_files", + "long_name": "filter_py_files( self , sources )", + "filename": "build_src.py", + "nloc": 2, + "complexity": 1, + "token_count": 18, + "parameters": [ + "self", + "sources" + ], + "start_line": 236, + "end_line": 237, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 2, + "top_nesting_level": 1 + }, + { + "name": "filter_h_files", + "long_name": "filter_h_files( self , sources )", + "filename": "build_src.py", + "nloc": 2, + "complexity": 1, + "token_count": 22, + "parameters": [ + "self", + "sources" + ], + "start_line": 239, + "end_line": 240, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 2, + "top_nesting_level": 1 + }, + { + "name": "filter_files", + "long_name": "filter_files( self , sources , exts = [ ] )", + "filename": "build_src.py", + "nloc": 10, + "complexity": 3, + "token_count": 62, + "parameters": [ + "self", + "sources", + "exts" + ], + "start_line": 242, + "end_line": 251, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 10, + "top_nesting_level": 1 + }, + { + "name": "template_sources", + "long_name": "template_sources( self , sources , extension )", + "filename": "build_src.py", + "nloc": 36, + "complexity": 10, + "token_count": 273, + "parameters": [ + "self", + "sources", + "extension" + ], + "start_line": 253, + "end_line": 288, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 36, + "top_nesting_level": 1 + }, + { + "name": "f2py_sources", + "long_name": "f2py_sources( self , sources , extension )", + "filename": "build_src.py", + "nloc": 115, + "complexity": 27, + "token_count": 935, + "parameters": [ + "self", + "sources", + "extension" + ], + "start_line": 290, + "end_line": 417, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 128, + "top_nesting_level": 1 + }, + { + "name": "swig_sources", + "long_name": "swig_sources( self , sources , extension )", + "filename": "build_src.py", + "nloc": 80, + "complexity": 17, + "token_count": 539, + "parameters": [ + "self", + "sources", + "extension" + ], + "start_line": 419, + "end_line": 506, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 88, + "top_nesting_level": 1 + }, + { + "name": "get_swig_target", + "long_name": "get_swig_target( source )", + "filename": "build_src.py", + "nloc": 10, + "complexity": 3, + "token_count": 48, + "parameters": [ + "source" + ], + "start_line": 517, + "end_line": 526, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 10, + "top_nesting_level": 0 + }, + { + "name": "get_swig_modulename", + "long_name": "get_swig_modulename( source )", + "filename": "build_src.py", + "nloc": 10, + "complexity": 3, + "token_count": 57, + "parameters": [ + "source" + ], + "start_line": 528, + "end_line": 537, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 10, + "top_nesting_level": 0 + }, + { + "name": "_find_swig_target", + "long_name": "_find_swig_target( target_dir , name )", + "filename": "build_src.py", + "nloc": 6, + "complexity": 3, + "token_count": 47, + "parameters": [ + "target_dir", + "name" + ], + "start_line": 539, + "end_line": 544, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 6, + "top_nesting_level": 0 + }, + { + "name": "get_f2py_modulename", + "long_name": "get_f2py_modulename( source )", + "filename": "build_src.py", + "nloc": 13, + "complexity": 4, + "token_count": 65, + "parameters": [ + "source" + ], + "start_line": 553, + "end_line": 565, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 13, + "top_nesting_level": 0 + } + ], + "changed_methods": [ + { + "name": "build_sources", + "long_name": "build_sources( self )", + "filename": "build_src.py", + "nloc": 10, + "complexity": 4, + "token_count": 56, + "parameters": [ + "self" + ], + "start_line": 93, + "end_line": 108, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 16, + "top_nesting_level": 1 + }, + { + "name": "build_py_modules_sources", + "long_name": "build_py_modules_sources( self )", + "filename": "build_src.py", + "nloc": 23, + "complexity": 8, + "token_count": 161, + "parameters": [ + "self" + ], + "start_line": 142, + "end_line": 164, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 23, + "top_nesting_level": 1 + }, + { + "name": "build_data_files_sources", + "long_name": "build_data_files_sources( self )", + "filename": "build_src.py", + "nloc": 31, + "complexity": 10, + "token_count": 199, + "parameters": [ + "self" + ], + "start_line": 110, + "end_line": 140, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 31, + "top_nesting_level": 1 + }, + { + "name": "finalize_options", + "long_name": "finalize_options( self )", + "filename": "build_src.py", + "nloc": 26, + "complexity": 9, + "token_count": 194, + "parameters": [ + "self" + ], + "start_line": 54, + "end_line": 84, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 31, + "top_nesting_level": 1 + } + ], + "nloc": 501, + "complexity": 125, + "token_count": 3572, + "diff_parsed": { + "added": [ + " self.data_files = self.distribution.data_files or []", + " self.build_data_files_sources()", + "", + " return", + "", + " def build_data_files_sources(self):", + " if not self.data_files:", + " return", + " log.info('building data_files sources')", + " from numpy.distutils.misc_util import get_data_files", + " new_data_files = []", + " for data in self.data_files:", + " if isinstance(data,str):", + " new_data_files.append(data)", + " elif isinstance(data,tuple):", + " d,files = data", + " funcs = filter(callable,files)", + " files = filter(lambda f:not callable(f), files)", + " for f in funcs:", + " if f.func_code.co_argcount==1:", + " s = f(os.path.join(self.build_src,d))", + " else:", + " s = f()", + " if s is not None:", + " if isinstance(s,list):", + " files.extend(s)", + " elif isinstance(s,str):", + " files.append(s)", + " else:", + " raise TypeError,`s`", + " filenames = get_data_files((d,files))", + " new_data_files.append((d, filenames))", + " else:", + " raise", + " self.data_files[:] = new_data_files", + " if not self.py_modules:", + " return", + " log.info('building py_modules sources')" + ], + "deleted": [] + } + }, + { + "old_path": "numpy/distutils/core.py", + "new_path": "numpy/distutils/core.py", + "filename": "core.py", + "extension": "py", + "change_type": "MODIFY", + "diff": "@@ -80,16 +80,6 @@ def setup(**attr):\n and not new_attr.has_key('headers'):\n new_attr['headers'] = []\n \n- # Expand directories in data_files to files\n- if new_attr.has_key('data_files'):\n- new_data_files = []\n- for data in new_attr['data_files']:\n- if type(data) is types.StringType:\n- new_data_files.append(get_data_files(data)[0])\n- else:\n- new_data_files.append((data[0],get_data_files(data)))\n- new_attr['data_files'] = new_data_files\n-\n return old_setup(**new_attr)\n \n def _check_append_library(libraries, item):\n", + "added_lines": 0, + "deleted_lines": 10, + "source_code": "\nimport types\nfrom distutils.core import *\ntry:\n from setuptools import setup as old_setup\n # very old setuptools don't have this\n from setuptools.command import bdist_egg\n have_setuptools = 1\nexcept ImportError:\n from distutils.core import setup as old_setup\n have_setuptools = 0\n\nfrom numpy.distutils.extension import Extension\nfrom numpy.distutils.command import config\nfrom numpy.distutils.command import build\nfrom numpy.distutils.command import build_py\nfrom numpy.distutils.command import config_compiler\nfrom numpy.distutils.command import build_ext\nfrom numpy.distutils.command import build_clib\nfrom numpy.distutils.command import build_src\nfrom numpy.distutils.command import build_scripts\nfrom numpy.distutils.command import sdist\nfrom numpy.distutils.command import install_data\nfrom numpy.distutils.command import install_headers\nfrom numpy.distutils.command import install\nfrom numpy.distutils.command import bdist_rpm\nfrom numpy.distutils.misc_util import get_data_files\n\nnumpy_cmdclass = {'build': build.build,\n 'build_src': build_src.build_src,\n 'build_scripts': build_scripts.build_scripts,\n 'config_fc': config_compiler.config_fc,\n 'config': config.config,\n 'build_ext': build_ext.build_ext,\n 'build_py': build_py.build_py,\n 'build_clib': build_clib.build_clib,\n 'sdist': sdist.sdist,\n 'install_data': install_data.install_data,\n 'install_headers': install_headers.install_headers,\n 'install': install.install,\n 'bdist_rpm': bdist_rpm.bdist_rpm,\n }\nif have_setuptools:\n from setuptools.command import bdist_egg, develop, easy_install, egg_info\n numpy_cmdclass['bdist_egg'] = bdist_egg.bdist_egg\n numpy_cmdclass['develop'] = develop.develop\n numpy_cmdclass['easy_install'] = easy_install.easy_install\n numpy_cmdclass['egg_info'] = egg_info.egg_info\n\ndef setup(**attr):\n\n cmdclass = numpy_cmdclass.copy()\n\n new_attr = attr.copy()\n if new_attr.has_key('cmdclass'):\n cmdclass.update(new_attr['cmdclass'])\n new_attr['cmdclass'] = cmdclass\n\n # Move extension source libraries to libraries\n libraries = []\n for ext in new_attr.get('ext_modules',[]):\n new_libraries = []\n for item in ext.libraries:\n if type(item) is type(()):\n lib_name,build_info = item\n _check_append_ext_library(libraries, item)\n new_libraries.append(lib_name)\n else:\n assert type(item) is type(''),`item`\n new_libraries.append(item)\n ext.libraries = new_libraries\n if libraries:\n if not new_attr.has_key('libraries'):\n new_attr['libraries'] = []\n for item in libraries:\n _check_append_library(new_attr['libraries'], item)\n\n # sources in ext_modules or libraries may contain header files\n if (new_attr.has_key('ext_modules') or new_attr.has_key('libraries')) \\\n and not new_attr.has_key('headers'):\n new_attr['headers'] = []\n\n return old_setup(**new_attr)\n\ndef _check_append_library(libraries, item):\n import warnings\n for libitem in libraries:\n if type(libitem) is type(()):\n if type(item) is type(()):\n if item[0]==libitem[0]:\n if item[1] is libitem[1]:\n return\n warnings.warn(\"[0] libraries list contains '%s' with\"\\\n \" different build_info\" % (item[0]))\n break\n else:\n if item==libitem[0]:\n warnings.warn(\"[1] libraries list contains '%s' with\"\\\n \" no build_info\" % (item[0]))\n break\n else:\n if type(item) is type(()):\n if item[0]==libitem:\n warnings.warn(\"[2] libraries list contains '%s' with\"\\\n \" no build_info\" % (item[0]))\n break\n else:\n if item==libitem:\n return\n libraries.append(item)\n return\n\ndef _check_append_ext_library(libraries, (lib_name,build_info)):\n import warnings\n for item in libraries:\n if type(item) is type(()):\n if item[0]==lib_name:\n if item[1] is build_info:\n return\n warnings.warn(\"[3] libraries list contains '%s' with\"\\\n \" different build_info\" % (lib_name))\n break\n elif item==lib_name:\n warnings.warn(\"[4] libraries list contains '%s' with\"\\\n \" no build_info\" % (lib_name))\n break\n libraries.append((lib_name,build_info))\n return\n", + "source_code_before": "\nimport types\nfrom distutils.core import *\ntry:\n from setuptools import setup as old_setup\n # very old setuptools don't have this\n from setuptools.command import bdist_egg\n have_setuptools = 1\nexcept ImportError:\n from distutils.core import setup as old_setup\n have_setuptools = 0\n\nfrom numpy.distutils.extension import Extension\nfrom numpy.distutils.command import config\nfrom numpy.distutils.command import build\nfrom numpy.distutils.command import build_py\nfrom numpy.distutils.command import config_compiler\nfrom numpy.distutils.command import build_ext\nfrom numpy.distutils.command import build_clib\nfrom numpy.distutils.command import build_src\nfrom numpy.distutils.command import build_scripts\nfrom numpy.distutils.command import sdist\nfrom numpy.distutils.command import install_data\nfrom numpy.distutils.command import install_headers\nfrom numpy.distutils.command import install\nfrom numpy.distutils.command import bdist_rpm\nfrom numpy.distutils.misc_util import get_data_files\n\nnumpy_cmdclass = {'build': build.build,\n 'build_src': build_src.build_src,\n 'build_scripts': build_scripts.build_scripts,\n 'config_fc': config_compiler.config_fc,\n 'config': config.config,\n 'build_ext': build_ext.build_ext,\n 'build_py': build_py.build_py,\n 'build_clib': build_clib.build_clib,\n 'sdist': sdist.sdist,\n 'install_data': install_data.install_data,\n 'install_headers': install_headers.install_headers,\n 'install': install.install,\n 'bdist_rpm': bdist_rpm.bdist_rpm,\n }\nif have_setuptools:\n from setuptools.command import bdist_egg, develop, easy_install, egg_info\n numpy_cmdclass['bdist_egg'] = bdist_egg.bdist_egg\n numpy_cmdclass['develop'] = develop.develop\n numpy_cmdclass['easy_install'] = easy_install.easy_install\n numpy_cmdclass['egg_info'] = egg_info.egg_info\n\ndef setup(**attr):\n\n cmdclass = numpy_cmdclass.copy()\n\n new_attr = attr.copy()\n if new_attr.has_key('cmdclass'):\n cmdclass.update(new_attr['cmdclass'])\n new_attr['cmdclass'] = cmdclass\n\n # Move extension source libraries to libraries\n libraries = []\n for ext in new_attr.get('ext_modules',[]):\n new_libraries = []\n for item in ext.libraries:\n if type(item) is type(()):\n lib_name,build_info = item\n _check_append_ext_library(libraries, item)\n new_libraries.append(lib_name)\n else:\n assert type(item) is type(''),`item`\n new_libraries.append(item)\n ext.libraries = new_libraries\n if libraries:\n if not new_attr.has_key('libraries'):\n new_attr['libraries'] = []\n for item in libraries:\n _check_append_library(new_attr['libraries'], item)\n\n # sources in ext_modules or libraries may contain header files\n if (new_attr.has_key('ext_modules') or new_attr.has_key('libraries')) \\\n and not new_attr.has_key('headers'):\n new_attr['headers'] = []\n\n # Expand directories in data_files to files\n if new_attr.has_key('data_files'):\n new_data_files = []\n for data in new_attr['data_files']:\n if type(data) is types.StringType:\n new_data_files.append(get_data_files(data)[0])\n else:\n new_data_files.append((data[0],get_data_files(data)))\n new_attr['data_files'] = new_data_files\n\n return old_setup(**new_attr)\n\ndef _check_append_library(libraries, item):\n import warnings\n for libitem in libraries:\n if type(libitem) is type(()):\n if type(item) is type(()):\n if item[0]==libitem[0]:\n if item[1] is libitem[1]:\n return\n warnings.warn(\"[0] libraries list contains '%s' with\"\\\n \" different build_info\" % (item[0]))\n break\n else:\n if item==libitem[0]:\n warnings.warn(\"[1] libraries list contains '%s' with\"\\\n \" no build_info\" % (item[0]))\n break\n else:\n if type(item) is type(()):\n if item[0]==libitem:\n warnings.warn(\"[2] libraries list contains '%s' with\"\\\n \" no build_info\" % (item[0]))\n break\n else:\n if item==libitem:\n return\n libraries.append(item)\n return\n\ndef _check_append_ext_library(libraries, (lib_name,build_info)):\n import warnings\n for item in libraries:\n if type(item) is type(()):\n if item[0]==lib_name:\n if item[1] is build_info:\n return\n warnings.warn(\"[3] libraries list contains '%s' with\"\\\n \" different build_info\" % (lib_name))\n break\n elif item==lib_name:\n warnings.warn(\"[4] libraries list contains '%s' with\"\\\n \" no build_info\" % (lib_name))\n break\n libraries.append((lib_name,build_info))\n return\n", + "methods": [ + { + "name": "setup", + "long_name": "setup( ** attr )", + "filename": "core.py", + "nloc": 27, + "complexity": 11, + "token_count": 199, + "parameters": [ + "attr" + ], + "start_line": 50, + "end_line": 83, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 34, + "top_nesting_level": 0 + }, + { + "name": "_check_append_library", + "long_name": "_check_append_library( libraries , item )", + "filename": "core.py", + "nloc": 27, + "complexity": 10, + "token_count": 156, + "parameters": [ + "libraries", + "item" + ], + "start_line": 85, + "end_line": 111, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 27, + "top_nesting_level": 0 + }, + { + "name": "_check_append_ext_library", + "long_name": "_check_append_ext_library( libraries , ( lib_name , build_info )", + "filename": "core.py", + "nloc": 16, + "complexity": 6, + "token_count": 89, + "parameters": [ + "libraries", + "lib_name", + "build_info" + ], + "start_line": 113, + "end_line": 128, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 16, + "top_nesting_level": 0 + } + ], + "methods_before": [ + { + "name": "setup", + "long_name": "setup( ** attr )", + "filename": "core.py", + "nloc": 35, + "complexity": 14, + "token_count": 265, + "parameters": [ + "attr" + ], + "start_line": 50, + "end_line": 93, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 44, + "top_nesting_level": 0 + }, + { + "name": "_check_append_library", + "long_name": "_check_append_library( libraries , item )", + "filename": "core.py", + "nloc": 27, + "complexity": 10, + "token_count": 156, + "parameters": [ + "libraries", + "item" + ], + "start_line": 95, + "end_line": 121, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 27, + "top_nesting_level": 0 + }, + { + "name": "_check_append_ext_library", + "long_name": "_check_append_ext_library( libraries , ( lib_name , build_info )", + "filename": "core.py", + "nloc": 16, + "complexity": 6, + "token_count": 89, + "parameters": [ + "libraries", + "lib_name", + "build_info" + ], + "start_line": 123, + "end_line": 138, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 16, + "top_nesting_level": 0 + } + ], + "changed_methods": [ + { + "name": "setup", + "long_name": "setup( ** attr )", + "filename": "core.py", + "nloc": 35, + "complexity": 14, + "token_count": 265, + "parameters": [ + "attr" + ], + "start_line": 50, + "end_line": 93, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 44, + "top_nesting_level": 0 + } + ], + "nloc": 114, + "complexity": 27, + "token_count": 735, + "diff_parsed": { + "added": [], + "deleted": [ + " # Expand directories in data_files to files", + " if new_attr.has_key('data_files'):", + " new_data_files = []", + " for data in new_attr['data_files']:", + " if type(data) is types.StringType:", + " new_data_files.append(get_data_files(data)[0])", + " else:", + " new_data_files.append((data[0],get_data_files(data)))", + " new_attr['data_files'] = new_data_files", + "" + ] + } + }, + { + "old_path": "numpy/distutils/misc_util.py", + "new_path": "numpy/distutils/misc_util.py", + "filename": "misc_util.py", + "extension": "py", + "change_type": "MODIFY", + "diff": "@@ -249,9 +249,7 @@ def get_data_files(data):\n filenames = []\n for s in sources:\n if callable(s):\n- s = s()\n- if s is None:\n- continue\n+ continue\n if is_local_src_dir(s):\n os.path.walk(s,_gsf_visit_func,filenames)\n elif type(s) is type(''):\n", + "added_lines": 1, + "deleted_lines": 3, + "source_code": "import os\nimport re\nimport sys\nimport imp\nimport copy\nimport types\nimport glob\n\n__all__ = ['Configuration', 'get_numpy_include_dirs', 'default_config_dict',\n 'dict_append', 'appendpath', 'generate_config_py',\n 'generate_svn_version_py', 'get_cmd', 'allpath',\n 'terminal_has_colors', 'red_text', 'green_text', 'yellow_text',\n 'blue_text', 'cyan_text', 'cyg2win32', 'all_strings',\n 'has_f_sources', 'has_cxx_sources', 'filter_sources',\n 'get_dependencies', 'is_local_src_dir', 'get_ext_source_files',\n 'get_script_files', 'get_lib_source_files', 'get_data_files',\n 'dot_join', 'get_frame']\n\ndef allpath(name):\n \"Convert a /-separated pathname to one using the OS's path separator.\"\n splitted = name.split('/')\n return os.path.join(*splitted)\n\ndef get_path(mod_name,parent_path=None):\n \"\"\" Return path of the module.\n\n Returned path is relative to parent_path when given,\n otherwise it is absolute path.\n \"\"\"\n if mod_name == '__main__':\n d = os.path.abspath('.')\n elif mod_name == '__builtin__':\n #builtin if/then added by Pearu for use in core.run_setup. \n d = os.path.dirname(os.path.abspath(sys.argv[0]))\n else:\n __import__(mod_name)\n mod = sys.modules[mod_name]\n file = mod.__file__\n d = os.path.dirname(os.path.abspath(file))\n if parent_path is not None:\n pd = os.path.abspath(parent_path)\n if pd==d[:len(pd)]:\n d = d[len(pd)+1:]\n return d or '.'\n\n# Hooks for colored terminal output.\n# See also http://www.livinglogic.de/Python/ansistyle\ndef terminal_has_colors():\n if sys.platform=='cygwin' and not os.environ.has_key('USE_COLOR'):\n # Avoid importing curses that causes illegal operation\n # with a message:\n # PYTHON2 caused an invalid page fault in\n # module CYGNURSES7.DLL as 015f:18bbfc28\n # Details: Python 2.3.3 [GCC 3.3.1 (cygming special)]\n # ssh to Win32 machine from debian\n # curses.version is 2.2\n # CYGWIN_98-4.10, release 1.5.7(0.109/3/2))\n return 0\n if hasattr(sys.stdout,'isatty') and sys.stdout.isatty(): \n try:\n import curses\n curses.setupterm()\n if (curses.tigetnum(\"colors\") >= 0\n and curses.tigetnum(\"pairs\") >= 0\n and ((curses.tigetstr(\"setf\") is not None \n and curses.tigetstr(\"setb\") is not None) \n or (curses.tigetstr(\"setaf\") is not None\n and curses.tigetstr(\"setab\") is not None)\n or curses.tigetstr(\"scp\") is not None)):\n return 1\n except Exception,msg:\n pass\n return 0\n\nif terminal_has_colors():\n def red_text(s): return '\\x1b[31m%s\\x1b[0m'%s\n def green_text(s): return '\\x1b[32m%s\\x1b[0m'%s\n def yellow_text(s): return '\\x1b[33m%s\\x1b[0m'%s\n def blue_text(s): return '\\x1b[34m%s\\x1b[0m'%s\n def cyan_text(s): return '\\x1b[35m%s\\x1b[0m'%s\nelse:\n def red_text(s): return s\n def green_text(s): return s\n def yellow_text(s): return s\n def cyan_text(s): return s\n def blue_text(s): return s\n\n#########################\n\ndef cyg2win32(path):\n if sys.platform=='cygwin' and path.startswith('/cygdrive'):\n path = path[10] + ':' + os.path.normcase(path[11:])\n return path\n\n#########################\n\n#XXX need support for .C that is also C++\ncxx_ext_match = re.compile(r'.*[.](cpp|cxx|cc)\\Z',re.I).match\nfortran_ext_match = re.compile(r'.*[.](f90|f95|f77|for|ftn|f)\\Z',re.I).match\nf90_ext_match = re.compile(r'.*[.](f90|f95)\\Z',re.I).match\nf90_module_name_match = re.compile(r'\\s*module\\s*(?P[\\w_]+)',re.I).match\ndef _get_f90_modules(source):\n \"\"\" Return a list of Fortran f90 module names that\n given source file defines.\n \"\"\"\n if not f90_ext_match(source):\n return []\n modules = []\n f = open(source,'r')\n f_readlines = getattr(f,'xreadlines',f.readlines)\n for line in f_readlines():\n m = f90_module_name_match(line)\n if m:\n name = m.group('name')\n modules.append(name)\n # break # XXX can we assume that there is one module per file?\n f.close()\n return modules\n\ndef all_strings(lst):\n \"\"\" Return True if all items in lst are string objects. \"\"\"\n for item in lst:\n if type(item) is not types.StringType:\n return False\n return True\n\ndef has_f_sources(sources):\n \"\"\" Return True if sources contains Fortran files \"\"\"\n for source in sources:\n if fortran_ext_match(source):\n return True\n return False\n\ndef has_cxx_sources(sources):\n \"\"\" Return True if sources contains C++ files \"\"\"\n for source in sources:\n if cxx_ext_match(source):\n return True\n return False\n\ndef filter_sources(sources):\n \"\"\" Return four lists of filenames containing\n C, C++, Fortran, and Fortran 90 module sources,\n respectively.\n \"\"\"\n c_sources = []\n cxx_sources = []\n f_sources = []\n fmodule_sources = []\n for source in sources:\n if fortran_ext_match(source):\n modules = _get_f90_modules(source)\n if modules:\n fmodule_sources.append(source)\n else:\n f_sources.append(source)\n elif cxx_ext_match(source):\n cxx_sources.append(source)\n else:\n c_sources.append(source) \n return c_sources, cxx_sources, f_sources, fmodule_sources\n\n\ndef _get_headers(directory_list):\n # get *.h files from list of directories\n headers = []\n for dir in directory_list:\n head = glob.glob(os.path.join(dir,\"*.h\")) #XXX: *.hpp files??\n headers.extend(head)\n return headers\n\ndef _get_directories(list_of_sources):\n # get unique directories from list of sources.\n direcs = []\n for file in list_of_sources:\n dir = os.path.split(file)\n if dir[0] != '' and not dir[0] in direcs:\n direcs.append(dir[0])\n return direcs\n\ndef get_dependencies(sources):\n #XXX scan sources for include statements\n return _get_headers(_get_directories(sources))\n\ndef is_local_src_dir(directory):\n \"\"\" Return true if directory is local directory.\n \"\"\"\n if type(directory) is not type(''):\n return False\n abs_dir = os.path.abspath(directory)\n c = os.path.commonprefix([os.getcwd(),abs_dir])\n new_dir = abs_dir[len(c):].split(os.sep)\n if new_dir and not new_dir[0]:\n new_dir = new_dir[1:]\n if new_dir and new_dir[0]=='build':\n return False\n new_dir = os.sep.join(new_dir)\n return os.path.isdir(new_dir)\n\ndef _gsf_visit_func(filenames,dirname,names):\n if os.path.basename(dirname) in ['CVS','.svn','build']:\n names[:] = []\n return\n for name in names:\n if name[-1] in \"~#\":\n continue\n fullname = os.path.join(dirname,name)\n ext = os.path.splitext(fullname)[1]\n if ext and ext in ['.pyc','.o']:\n continue\n if os.path.isfile(fullname):\n filenames.append(fullname)\n\ndef get_ext_source_files(ext):\n # Get sources and any include files in the same directory.\n filenames = []\n sources = filter(lambda s:type(s) is types.StringType,ext.sources)\n filenames.extend(sources)\n filenames.extend(get_dependencies(sources))\n for d in ext.depends:\n if is_local_src_dir(d):\n os.path.walk(d,_gsf_visit_func,filenames)\n elif os.path.isfile(d):\n filenames.append(d)\n return filenames\n\ndef get_script_files(scripts):\n scripts = filter(lambda s:type(s) is types.StringType,scripts)\n return scripts\n\ndef get_lib_source_files(lib):\n filenames = []\n sources = lib[1].get('sources',[])\n sources = filter(lambda s:type(s) is types.StringType,sources)\n filenames.extend(sources)\n filenames.extend(get_dependencies(sources))\n depends = lib[1].get('depends',[])\n for d in depends:\n if is_local_src_dir(d):\n os.path.walk(d,_gsf_visit_func,filenames)\n elif os.path.isfile(d):\n filenames.append(d)\n return filenames\n\ndef get_data_files(data):\n if type(data) is types.StringType:\n return [data]\n sources = data[1]\n filenames = []\n for s in sources:\n if callable(s):\n continue\n if is_local_src_dir(s):\n os.path.walk(s,_gsf_visit_func,filenames)\n elif type(s) is type(''):\n if os.path.isfile(s):\n filenames.append(s)\n else:\n print 'Not existing data file:',s\n else:\n raise TypeError,`s`\n return filenames\n\ndef dot_join(*args):\n return '.'.join(filter(None,args))\n\ndef get_frame(level=0):\n try:\n return sys._getframe(level+1)\n except AttributeError:\n frame = sys.exc_info()[2].tb_frame\n for i in range(level+1):\n frame = frame.f_back\n return frame\n\n######################\n\nclass Configuration:\n\n _list_keys = ['packages','ext_modules','data_files','include_dirs',\n 'libraries','headers','scripts','py_modules']\n _dict_keys = ['package_dir']\n\n numpy_include_dirs = []\n\n def __init__(self,\n package_name=None,\n parent_name=None,\n top_path=None,\n package_path=None,\n **attrs):\n \"\"\" Construct configuration instance of a package.\n \"\"\"\n self.name = dot_join(parent_name, package_name)\n\n caller_frame = get_frame(1)\n caller_name = eval('__name__',caller_frame.f_globals,caller_frame.f_locals)\n \n self.local_path = get_path(caller_name, top_path)\n if top_path is None:\n top_path = self.local_path\n if package_path is None:\n package_path = self.local_path\n elif os.path.isdir(os.path.join(self.local_path,package_path)):\n package_path = os.path.join(self.local_path,package_path)\n assert os.path.isdir(package_path),`package_path`\n self.top_path = top_path\n\n self.list_keys = copy.copy(self._list_keys)\n self.dict_keys = copy.copy(self._dict_keys)\n\n for n in self.list_keys:\n setattr(self,n,copy.copy(attrs.get(n,[])))\n\n for n in self.dict_keys:\n setattr(self,n,copy.copy(attrs.get(n,{})))\n\n known_keys = self.list_keys + self.dict_keys\n self.extra_keys = []\n for n in attrs.keys():\n if n in known_keys:\n continue\n a = attrs[n]\n setattr(self,n,a)\n if type(a) is types.ListType:\n self.list_keys.append(n)\n elif type(a) is types.DictType:\n self.dict_keys.append(n)\n else:\n self.extra_keys.append(n)\n\n if os.path.exists(os.path.join(package_path,'__init__.py')):\n self.packages.append(self.name)\n self.package_dir[self.name] = package_path \n return\n\n def todict(self):\n \"\"\" Return configuration distionary suitable for passing\n to distutils.core.setup() function.\n \"\"\"\n d = {}\n for n in self.list_keys + self.dict_keys + self.extra_keys:\n a = getattr(self,n)\n if a:\n d[n] = a\n if self.name:\n d['name'] = self.name\n return d\n\n def __dict__(self):\n return self.todict()\n\n def get_distribution(self):\n import distutils.core\n dist = distutils.core._setup_distribution \n return dist\n\n def get_subpackage(self,subpackage_name,subpackage_path=None):\n \"\"\" Return subpackage configuration.\n \"\"\"\n if subpackage_name is None:\n assert subpackage_path is not None\n subpackage_name = os.path.basename(subpackage_path)\n l = subpackage_name.split('.')\n if subpackage_path is None:\n subpackage_path = os.path.join(*([self.local_path]+l))\n if '*' in subpackage_name:\n dirs = filter(os.path.isdir,glob.glob(subpackage_path))\n config_list = []\n for d in dirs:\n if not os.path.isfile(os.path.join(d,'__init__.py')):\n continue\n n = '.'.join(d.split(os.sep)[-len(l):])\n c = self.get_subpackage(n)\n if c:\n config_list.append(c)\n return config_list\n else:\n subpackage_path = os.path.join(*([subpackage_path]+l[:-1]))\n subpackage_path = self._fix_paths([subpackage_path])[0]\n\n setup_py = os.path.join(subpackage_path,'setup.py')\n if not os.path.isfile(setup_py):\n setup_py = os.path.join(subpackage_path,'setup_%s.py' % (subpackage_name))\n\n if not os.path.isfile(setup_py):\n print 'Assuming default configuration '\\\n '(%s/{setup_%s,setup}.py was not found)' \\\n % (os.path.dirname(setup_py),subpackage_name)\n config = Configuration(subpackage_name,self.name,\n self.top_path,subpackage_path)\n else:\n # In case setup_py imports local modules:\n sys.path.insert(0,os.path.dirname(setup_py))\n try:\n info = (open(setup_py),setup_py,('.py','U',1))\n setup_name = os.path.splitext(os.path.basename(setup_py))[0]\n n = dot_join(self.name,setup_name)\n setup_module = imp.load_module('_'.join(n.split('.')),*info)\n\n if not hasattr(setup_module,'configuration'):\n print 'Assuming default configuration '\\\n '(%s does not define configuration())' % (setup_module)\n config = Configuration(subpackage_name,self.name,\n self.top_path,subpackage_path)\n else:\n args = (self.name,)\n if setup_module.configuration.func_code.co_argcount>1:\n args = args + (self.top_path,)\n config = setup_module.configuration(*args)\n\n finally:\n del sys.path[0]\n\n return config\n\n def add_subpackage(self,subpackage_name,subpackage_path=None):\n \"\"\" Add subpackage to configuration.\n \"\"\"\n config = self.get_subpackage(subpackage_name,subpackage_path)\n if not isinstance(config, list):\n config_list = [config]\n else:\n config_list = config\n for config in config_list:\n if not config:\n print 'No configuration returned, assuming unavailable.'\n else:\n if isinstance(config,Configuration):\n print 'Appending %s configuration to %s' % (config.name,self.name)\n self.dict_append(**config.todict())\n else:\n print 'Appending %s configuration to %s' % (config.get('name'),self.name)\n self.dict_append(**config)\n\n dist = self.get_distribution()\n if dist is not None:\n print 'distutils distribution has been initialized, it may be too late to add a subpackage', subpackage_name\n return\n\n def add_data_dir(self,data_path):\n \"\"\" Recursively add files under data_path to data_files list.\n Argument can be either\n - 2-sequence (,)\n - path to data directory where python datadir suffix defaults\n to package dir.\n If path is not absolute then it's datadir suffix is\n package dir + subdirname of the path.\n \"\"\"\n if type(data_path) is type(()):\n assert len(data_path)==2,`data_path`\n d,data_path = data_path\n else:\n d = None\n assert type(data_path) is type(''),`data_path`\n for path in self.paths(data_path):\n if not os.path.exists(path):\n print 'Not existing data path',path\n continue\n filenames = []\n os.path.walk(path, _gsf_visit_func,filenames)\n if not os.path.isabs(path):\n if d is None:\n ds = os.path.join(*(self.name.split('.')+[data_path]))\n else:\n ds = os.path.join(d,data_path)\n self.add_data_files((ds,filenames))\n else:\n if d is None:\n self.add_data_files(*filenames)\n else:\n self.add_data_files((d,filenames))\n return\n\n def add_data_files(self,*files):\n \"\"\" Add data files to configuration data_files.\n Argument(s) can be either\n - 2-sequence (,)\n - paths to data files where python datadir prefix defaults\n to package dir.\n If path is not absolute then it's datadir prefix is\n package dir + dirname of the path.\n \"\"\"\n data_dict = {}\n new_files = []\n for p in files:\n if type(p) is not type(()):\n d = os.path.join(*(self.name.split('.')))\n if type(p) is type('') and not os.path.isabs(p):\n d = appendpath(d,os.path.dirname(p))\n p = (d,p)\n new_files.append(p)\n files = []\n for prefix,filepattern in new_files:\n if type(filepattern) is type(''):\n file_list = self.paths(filepattern)\n elif callable(filepattern):\n file_list = [filepattern]\n else:\n file_list = self.paths(*filepattern)\n\n nof_path_components = [len(f.split(os.sep)) \\\n for f in file_list if type(f) is type('')]\n if nof_path_components:\n min_path_components = min(nof_path_components)-1\n else:\n min_path_components = 0\n\n for f in file_list:\n if type(f) is type(''):\n extra_path_components = f.split(os.sep)[min_path_components:-1]\n p = os.path.join(*([prefix]+extra_path_components))\n else:\n p = prefix\n if not data_dict.has_key(p):\n data_dict[p] = [f]\n else:\n data_dict[p].append(f)\n\n dist = self.get_distribution()\n if dist is not None:\n dist.data_files.extend(data_dict.items())\n else:\n self.data_files.extend(data_dict.items())\n return \n\n ### XXX Implement add_py_modules\n \n def add_include_dirs(self,*paths):\n \"\"\" Add paths to configuration include directories.\n \"\"\"\n include_dirs = self._fix_paths(paths)\n dist = self.get_distribution()\n if dist is not None:\n dist.include_dirs.extend(include_dirs)\n else:\n self.include_dirs.extend(include_dirs)\n return\n\n def add_headers(self,*files):\n \"\"\" Add installable headers to configuration.\n Argument(s) can be either\n - 2-sequence (,)\n - path(s) to header file(s) where python includedir suffix will default\n to package name.\n \"\"\"\n headers = []\n for path in files:\n if type(path) is type(''):\n [headers.append((self.name,p)) for p in self.paths(path)]\n else:\n assert type(path) in [type(()),type([])] and len(path)==2,`path`\n [headers.append((path[0],p)) for p in self.paths(path[1])]\n dist = self.get_distribution()\n if dist is not None:\n dist.headers.extend(headers)\n else:\n self.headers.extend(headers)\n return\n\n def _fix_paths(self,paths):\n new_paths = []\n for n in paths:\n if isinstance(n,str):\n if '*' in n or '?' in n:\n p = glob.glob(n)\n p2 = glob.glob(os.path.join(self.local_path,n))\n if p2:\n new_paths.extend(p2)\n elif p:\n new_paths.extend(p)\n else:\n new_paths.append(n)\n else:\n n2 = os.path.join(self.local_path,n)\n if os.path.exists(n2):\n new_paths.append(n2)\n else:\n new_paths.append(n)\n else:\n new_paths.append(n)\n return new_paths\n\n def paths(self,*paths):\n \"\"\" Apply glob to paths and prepend local_path if needed.\n \"\"\"\n return self._fix_paths(paths)\n\n def add_extension(self,name,sources,**kw):\n \"\"\" Add extension to configuration.\n\n Keywords:\n include_dirs, define_macros, undef_macros,\n library_dirs, libraries, runtime_library_dirs,\n extra_objects, extra_compile_args, extra_link_args,\n export_symbols, swig_opts, depends, language,\n f2py_options, module_dirs\n extra_info - dict or list of dict of keywords to be\n appended to keywords.\n \"\"\"\n ext_args = copy.copy(kw)\n ext_args['name'] = dot_join(self.name,name)\n ext_args['sources'] = sources\n\n if ext_args.has_key('extra_info'):\n extra_info = ext_args['extra_info']\n del ext_args['extra_info']\n if type(extra_info) is type({}):\n extra_info = [extra_info]\n for info in extra_info:\n assert type(info) is type({}),`info`\n dict_append(ext_args,**info)\n\n for k in ext_args.keys():\n v = ext_args[k]\n if k in ['sources','depends','include_dirs','library_dirs',\n 'module_dirs','extra_objects']:\n new_v = self._fix_paths(v)\n ext_args[k] = new_v\n\n # Resolve out-of-tree dependencies\n libraries = ext_args.get('libraries',[])\n libnames = []\n ext_args['libraries'] = []\n for libname in libraries:\n if '@' in libname:\n lname,lpath = libname.split('@',1)\n lpath = os.path.abspath(os.path.join(self.local_path,lpath))\n if os.path.isdir(lpath):\n c = self.get_subpackage(None,lpath)\n if isinstance(c,Configuration):\n c = c.todict()\n for l in [l[0] for l in c.get('libraries',[])]:\n llname = l.split('__OF__',1)[0]\n if llname == lname:\n c.pop('name',None)\n dict_append(ext_args,**c)\n break\n continue\n libnames.append(libname)\n\n ext_args['libraries'] = libnames + ext_args['libraries']\n\n from numpy.distutils.core import Extension\n ext = Extension(**ext_args)\n self.ext_modules.append(ext)\n\n dist = self.get_distribution()\n if dist is not None:\n print 'distutils distribution has been initialized, it may be too late to add an extension', name\n return ext\n\n def add_library(self,name,sources,**build_info):\n \"\"\" Add library to configuration.\n \n Valid keywords for build_info:\n depends\n macros\n include_dirs\n extra_compiler_args\n f2py_options\n \"\"\"\n build_info = copy.copy(build_info)\n name = name #+ '__OF__' + self.name\n build_info['sources'] = sources\n\n for k in build_info.keys():\n v = build_info[k]\n if k in ['sources','depends']:\n new_v = self._fix_paths(v)\n build_info[k] = new_v\n self.libraries.append((name,build_info))\n\n dist = self.get_distribution()\n if dist is not None:\n print 'distutils distribution has been initialized, it may be too late to add a library', name\n return\n\n def add_scripts(self,*files):\n \"\"\" Add scripts to configuration.\n \"\"\"\n scripts = self._fix_paths(files)\n dist = self.get_distribution()\n if dist is not None:\n dist.scripts.extend(scripts)\n else:\n self.scripts.extend(scripts)\n return\n\n def dict_append(self,**dict):\n for key in self.list_keys:\n a = getattr(self,key)\n a.extend(dict.get(key,[]))\n for key in self.dict_keys:\n a = getattr(self,key)\n a.update(dict.get(key,{}))\n known_keys = self.list_keys + self.dict_keys + self.extra_keys\n for key in dict.keys():\n if key not in known_keys and not hasattr(self,key):\n print 'Inheriting attribute %r from %r' \\\n % (key,dict.get('name','?'))\n setattr(self,key,dict[key])\n self.extra_keys.append(key)\n return\n\n def __str__(self):\n known_keys = self.list_keys + self.dict_keys + self.extra_keys\n s = '<'+5*'-' + '\\n'\n s += 'Configuration of '+self.name+':\\n'\n for k in known_keys:\n a = getattr(self,k,None)\n if a:\n s += '%s = %r\\n' % (k,a)\n s += 5*'-' + '>'\n return s\n\n def get_config_cmd(self):\n cmd = get_cmd('config')\n cmd.ensure_finalized()\n cmd.dump_source = 0\n cmd.noisy = 0\n old_path = os.environ.get('PATH')\n if old_path:\n path = os.pathsep.join(['.',old_path])\n os.environ['PATH'] = path\n return cmd\n\n def get_build_temp_dir(self):\n cmd = get_cmd('build')\n cmd.ensure_finalized()\n return cmd.build_temp\n\n def have_f77c(self):\n \"\"\" Check for availability of Fortran 77 compiler.\n Use it inside source generating function to ensure that\n setup distribution instance has been initialized.\n \"\"\"\n simple_fortran_subroutine = '''\n subroutine simple\n end\n '''\n config_cmd = self.get_config_cmd()\n flag = config_cmd.try_compile(simple_fortran_subroutine,lang='f77')\n return flag\n\n def have_f90c(self):\n \"\"\" Check for availability of Fortran 90 compiler.\n Use it inside source generating function to ensure that\n setup distribution instance has been initialized.\n \"\"\"\n simple_fortran_subroutine = '''\n subroutine simple\n end\n '''\n config_cmd = self.get_config_cmd()\n flag = config_cmd.try_compile(simple_fortran_subroutine,lang='f90')\n return flag\n\n def append_to(self, extlib):\n \"\"\" Append libraries, include_dirs to extension or library item.\n \"\"\"\n if type(extlib) is type(()):\n lib_name, build_info = extlib\n dict_append(build_info,\n libraries=self.libraries,\n include_dirs=self.include_dirs)\n else:\n from numpy.distutils.core import Extension\n assert isinstance(extlib,Extension),`extlib`\n extlib.libraries.extend(self.libraries)\n extlib.include_dirs.extend(self.include_dirs)\n return\n\n def _get_svn_revision(self,path):\n \"\"\" Return path's SVN revision number.\n \"\"\"\n entries = os.path.join(path,'.svn','entries')\n revision = None\n if os.path.isfile(entries):\n f = open(entries)\n m = re.search(r'revision=\"(?P\\d+)\"',f.read())\n f.close()\n if m:\n revision = int(m.group('revision'))\n return revision\n\n def get_version(self):\n \"\"\" Try to get version string of a package.\n \"\"\"\n version = getattr(self,'version',None)\n if version is not None:\n return version\n\n # Get version from version file.\n files = ['__version__.py',\n self.name.split('.')[-1]+'_version.py',\n 'version.py',\n '__svn_version__.py']\n version_vars = ['version',\n '__version__',\n self.name.split('.')[-1]+'_version']\n for f in files:\n fn = os.path.join(self.local_path,f)\n if os.path.isfile(fn):\n info = (open(fn),fn,('.py','U',1))\n name = os.path.splitext(os.path.basename(fn))[0]\n n = dot_join(self.name,name)\n try:\n version_module = imp.load_module('_'.join(n.split('.')),*info)\n except ImportError,msg:\n print msg\n version_module = None\n if version_module is None:\n continue\n\n for a in version_vars:\n version = getattr(version_module,a,None)\n if version is not None:\n break\n if version is not None:\n break\n\n if version is not None:\n self.version = version\n return version\n\n # Get version as SVN revision number\n revision = self._get_svn_revision(self.local_path)\n if revision is not None:\n version = str(revision)\n self.version = version\n\n return version\n\n def make_svn_version_py(self):\n \"\"\" Generate package __svn_version__.py file from SVN revision number,\n it will be removed after python exits but will be available\n when sdist, etc commands are executed.\n\n If __svn_version__.py existed before, nothing is done.\n \"\"\"\n target = os.path.join(self.local_path,'__svn_version__.py')\n if os.path.isfile(target):\n return\n\n def generate_svn_version_py():\n if not os.path.isfile(target):\n revision = self._get_svn_revision(self.local_path)\n assert revision is not None,'hmm, why I am not inside SVN tree???'\n version = str(revision)\n print 'Creating %s (version=%r)' % (target,version)\n f = open(target,'w')\n f.write('version = %r\\n' % (version))\n f.close()\n \n import atexit\n def rm_file(f=target):\n try: os.remove(f); print 'removed',f\n except OSError: pass\n try: os.remove(f+'c'); print 'removed',f+'c'\n except OSError: pass\n atexit.register(rm_file)\n\n return target\n\n d = os.path.join(*(self.name.split('.')))\n self.add_data_files((d, generate_svn_version_py()))\n return\n\n def make_config_py(self,name='__config__'):\n \"\"\" Generate package __config__.py file containing system_info\n information used during building the package.\n \"\"\"\n self.py_modules.append((self.name,name,generate_config_py))\n return\n\n def get_info(self,*names):\n \"\"\" Get resources information.\n \"\"\"\n from system_info import get_info, dict_append\n info_dict = {}\n for a in names:\n dict_append(info_dict,**get_info(a))\n return info_dict\n\ndef get_cmd(cmdname,_cache={}):\n if not _cache.has_key(cmdname):\n import distutils.core\n dist = distutils.core._setup_distribution\n if dist is None:\n from distutils.errors import DistutilsInternalError\n raise DistutilsInternalError,\\\n 'setup distribution instance not initialized'\n cmd = dist.get_command_obj(cmdname)\n _cache[cmdname] = cmd\n return _cache[cmdname]\n\ndef get_numpy_include_dirs():\n # numpy_include_dirs are set by numpy/core/setup.py, otherwise []\n include_dirs = Configuration.numpy_include_dirs[:]\n if not include_dirs:\n import numpy\n if numpy.show_config is None:\n # running from numpy_core source directory\n include_dirs.append(os.path.join(os.path.dirname(numpy.__file__),\n 'core','include'))\n else:\n # using installed numpy core headers\n import numpy.core as core\n include_dirs.append(os.path.join(os.path.dirname(core.__file__),'include'))\n # else running numpy/core/setup.py\n return include_dirs\n\n#########################\n\ndef default_config_dict(name = None, parent_name = None, local_path=None):\n \"\"\" Return a configuration dictionary for usage in\n configuration() function defined in file setup_.py.\n \"\"\"\n import warnings\n warnings.warn('Use Configuration(%s,%s,top_path=%s) instead of '\\\n 'deprecated default_config_dict(%s,%s,%s)' \\\n % (`name`,`parent_name`,`local_path`,\n `name`,`parent_name`,`local_path`,\n ))\n c = Configuration(name, parent_name, local_path)\n return c.todict()\n\n\ndef dict_append(d,**kws):\n for k,v in kws.items():\n if d.has_key(k):\n d[k].extend(v)\n else:\n d[k] = v\n\ndef appendpath(prefix,path):\n if not ('/' == os.path.sep):\n prefix = prefix.replace('/',os.path.sep)\n path = path.replace('/',os.path.sep)\n drive = ''\n if os.path.isabs(path):\n drive = os.path.splitdrive(prefix)[0]\n absprefix = os.path.splitdrive(os.path.abspath(prefix))[1]\n pathdrive,path = os.path.splitdrive(path)\n d = os.path.commonprefix([absprefix,path])\n if os.path.join(absprefix[:len(d)],absprefix[len(d):])!=absprefix \\\n or os.path.join(path[:len(d)],path[len(d):])!=path:\n # Handle invalid paths\n d = os.path.dirname(d)\n subpath = path[len(d):]\n if os.path.isabs(subpath):\n subpath = subpath[1:]\n else:\n subpath = path\n return os.path.normpath(os.path.join(drive + prefix, subpath))\n\ndef generate_config_py(target):\n \"\"\" Generate config.py file containing system_info information\n used during building the package.\n\n Usage:\\\n config['py_modules'].append((packagename, '__config__',generate_config_py))\n \"\"\"\n from numpy.distutils.system_info import system_info\n from distutils.dir_util import mkpath\n mkpath(os.path.dirname(target))\n f = open(target,'w')\n f.write('# This file is generated by %s\\n' % (os.path.abspath(sys.argv[0])))\n f.write('# It contains system_info results at the time of building this package.\\n')\n f.write('__all__ = [\"get_info\",\"show\"]\\n\\n')\n for k,i in system_info.saved_results.items():\n f.write('%s=%r\\n' % (k,i))\n f.write('\\ndef get_info(name): g=globals(); return g.get(name,g.get(name+\"_info\",{}))\\n')\n f.write('''\ndef show():\n for name,info_dict in globals().items():\n if name[0]==\"_\" or type(info_dict) is not type({}): continue\n print name+\":\"\n if not info_dict:\n print \" NOT AVAILABLE\"\n for k,v in info_dict.items():\n v = str(v)\n if k==\\'sources\\' and len(v)>200: v = v[:60]+\\' ...\\\\n... \\'+v[-60:]\n print \\' %s = %s\\'%(k,v)\n print\n return\n ''')\n\n f.close()\n return target\n\ndef generate_svn_version_py(extension, build_dir):\n \"\"\" Generate __svn_version__.py file containing SVN\n revision number of a module.\n \n To use, add the following codelet to setup\n configuration(..) function\n\n ext = Extension(dot_join(config['name'],'__svn_version__'),\n sources=[generate_svn_version_py])\n ext.local_path = local_path\n config['ext_modules'].append(ext)\n\n \"\"\"\n from distutils import dep_util\n local_path = extension.local_path\n target = os.path.join(build_dir, '__svn_version__.py')\n entries = os.path.join(local_path,'.svn','entries')\n if os.path.isfile(entries):\n if not dep_util.newer(entries, target):\n return target\n elif os.path.isfile(target):\n return target\n\n revision = get_svn_revision(local_path)\n f = open(target,'w')\n f.write('revision=%s\\n' % (revision))\n f.close()\n return target\n", + "source_code_before": "import os\nimport re\nimport sys\nimport imp\nimport copy\nimport types\nimport glob\n\n__all__ = ['Configuration', 'get_numpy_include_dirs', 'default_config_dict',\n 'dict_append', 'appendpath', 'generate_config_py',\n 'generate_svn_version_py', 'get_cmd', 'allpath',\n 'terminal_has_colors', 'red_text', 'green_text', 'yellow_text',\n 'blue_text', 'cyan_text', 'cyg2win32', 'all_strings',\n 'has_f_sources', 'has_cxx_sources', 'filter_sources',\n 'get_dependencies', 'is_local_src_dir', 'get_ext_source_files',\n 'get_script_files', 'get_lib_source_files', 'get_data_files',\n 'dot_join', 'get_frame']\n\ndef allpath(name):\n \"Convert a /-separated pathname to one using the OS's path separator.\"\n splitted = name.split('/')\n return os.path.join(*splitted)\n\ndef get_path(mod_name,parent_path=None):\n \"\"\" Return path of the module.\n\n Returned path is relative to parent_path when given,\n otherwise it is absolute path.\n \"\"\"\n if mod_name == '__main__':\n d = os.path.abspath('.')\n elif mod_name == '__builtin__':\n #builtin if/then added by Pearu for use in core.run_setup. \n d = os.path.dirname(os.path.abspath(sys.argv[0]))\n else:\n __import__(mod_name)\n mod = sys.modules[mod_name]\n file = mod.__file__\n d = os.path.dirname(os.path.abspath(file))\n if parent_path is not None:\n pd = os.path.abspath(parent_path)\n if pd==d[:len(pd)]:\n d = d[len(pd)+1:]\n return d or '.'\n\n# Hooks for colored terminal output.\n# See also http://www.livinglogic.de/Python/ansistyle\ndef terminal_has_colors():\n if sys.platform=='cygwin' and not os.environ.has_key('USE_COLOR'):\n # Avoid importing curses that causes illegal operation\n # with a message:\n # PYTHON2 caused an invalid page fault in\n # module CYGNURSES7.DLL as 015f:18bbfc28\n # Details: Python 2.3.3 [GCC 3.3.1 (cygming special)]\n # ssh to Win32 machine from debian\n # curses.version is 2.2\n # CYGWIN_98-4.10, release 1.5.7(0.109/3/2))\n return 0\n if hasattr(sys.stdout,'isatty') and sys.stdout.isatty(): \n try:\n import curses\n curses.setupterm()\n if (curses.tigetnum(\"colors\") >= 0\n and curses.tigetnum(\"pairs\") >= 0\n and ((curses.tigetstr(\"setf\") is not None \n and curses.tigetstr(\"setb\") is not None) \n or (curses.tigetstr(\"setaf\") is not None\n and curses.tigetstr(\"setab\") is not None)\n or curses.tigetstr(\"scp\") is not None)):\n return 1\n except Exception,msg:\n pass\n return 0\n\nif terminal_has_colors():\n def red_text(s): return '\\x1b[31m%s\\x1b[0m'%s\n def green_text(s): return '\\x1b[32m%s\\x1b[0m'%s\n def yellow_text(s): return '\\x1b[33m%s\\x1b[0m'%s\n def blue_text(s): return '\\x1b[34m%s\\x1b[0m'%s\n def cyan_text(s): return '\\x1b[35m%s\\x1b[0m'%s\nelse:\n def red_text(s): return s\n def green_text(s): return s\n def yellow_text(s): return s\n def cyan_text(s): return s\n def blue_text(s): return s\n\n#########################\n\ndef cyg2win32(path):\n if sys.platform=='cygwin' and path.startswith('/cygdrive'):\n path = path[10] + ':' + os.path.normcase(path[11:])\n return path\n\n#########################\n\n#XXX need support for .C that is also C++\ncxx_ext_match = re.compile(r'.*[.](cpp|cxx|cc)\\Z',re.I).match\nfortran_ext_match = re.compile(r'.*[.](f90|f95|f77|for|ftn|f)\\Z',re.I).match\nf90_ext_match = re.compile(r'.*[.](f90|f95)\\Z',re.I).match\nf90_module_name_match = re.compile(r'\\s*module\\s*(?P[\\w_]+)',re.I).match\ndef _get_f90_modules(source):\n \"\"\" Return a list of Fortran f90 module names that\n given source file defines.\n \"\"\"\n if not f90_ext_match(source):\n return []\n modules = []\n f = open(source,'r')\n f_readlines = getattr(f,'xreadlines',f.readlines)\n for line in f_readlines():\n m = f90_module_name_match(line)\n if m:\n name = m.group('name')\n modules.append(name)\n # break # XXX can we assume that there is one module per file?\n f.close()\n return modules\n\ndef all_strings(lst):\n \"\"\" Return True if all items in lst are string objects. \"\"\"\n for item in lst:\n if type(item) is not types.StringType:\n return False\n return True\n\ndef has_f_sources(sources):\n \"\"\" Return True if sources contains Fortran files \"\"\"\n for source in sources:\n if fortran_ext_match(source):\n return True\n return False\n\ndef has_cxx_sources(sources):\n \"\"\" Return True if sources contains C++ files \"\"\"\n for source in sources:\n if cxx_ext_match(source):\n return True\n return False\n\ndef filter_sources(sources):\n \"\"\" Return four lists of filenames containing\n C, C++, Fortran, and Fortran 90 module sources,\n respectively.\n \"\"\"\n c_sources = []\n cxx_sources = []\n f_sources = []\n fmodule_sources = []\n for source in sources:\n if fortran_ext_match(source):\n modules = _get_f90_modules(source)\n if modules:\n fmodule_sources.append(source)\n else:\n f_sources.append(source)\n elif cxx_ext_match(source):\n cxx_sources.append(source)\n else:\n c_sources.append(source) \n return c_sources, cxx_sources, f_sources, fmodule_sources\n\n\ndef _get_headers(directory_list):\n # get *.h files from list of directories\n headers = []\n for dir in directory_list:\n head = glob.glob(os.path.join(dir,\"*.h\")) #XXX: *.hpp files??\n headers.extend(head)\n return headers\n\ndef _get_directories(list_of_sources):\n # get unique directories from list of sources.\n direcs = []\n for file in list_of_sources:\n dir = os.path.split(file)\n if dir[0] != '' and not dir[0] in direcs:\n direcs.append(dir[0])\n return direcs\n\ndef get_dependencies(sources):\n #XXX scan sources for include statements\n return _get_headers(_get_directories(sources))\n\ndef is_local_src_dir(directory):\n \"\"\" Return true if directory is local directory.\n \"\"\"\n if type(directory) is not type(''):\n return False\n abs_dir = os.path.abspath(directory)\n c = os.path.commonprefix([os.getcwd(),abs_dir])\n new_dir = abs_dir[len(c):].split(os.sep)\n if new_dir and not new_dir[0]:\n new_dir = new_dir[1:]\n if new_dir and new_dir[0]=='build':\n return False\n new_dir = os.sep.join(new_dir)\n return os.path.isdir(new_dir)\n\ndef _gsf_visit_func(filenames,dirname,names):\n if os.path.basename(dirname) in ['CVS','.svn','build']:\n names[:] = []\n return\n for name in names:\n if name[-1] in \"~#\":\n continue\n fullname = os.path.join(dirname,name)\n ext = os.path.splitext(fullname)[1]\n if ext and ext in ['.pyc','.o']:\n continue\n if os.path.isfile(fullname):\n filenames.append(fullname)\n\ndef get_ext_source_files(ext):\n # Get sources and any include files in the same directory.\n filenames = []\n sources = filter(lambda s:type(s) is types.StringType,ext.sources)\n filenames.extend(sources)\n filenames.extend(get_dependencies(sources))\n for d in ext.depends:\n if is_local_src_dir(d):\n os.path.walk(d,_gsf_visit_func,filenames)\n elif os.path.isfile(d):\n filenames.append(d)\n return filenames\n\ndef get_script_files(scripts):\n scripts = filter(lambda s:type(s) is types.StringType,scripts)\n return scripts\n\ndef get_lib_source_files(lib):\n filenames = []\n sources = lib[1].get('sources',[])\n sources = filter(lambda s:type(s) is types.StringType,sources)\n filenames.extend(sources)\n filenames.extend(get_dependencies(sources))\n depends = lib[1].get('depends',[])\n for d in depends:\n if is_local_src_dir(d):\n os.path.walk(d,_gsf_visit_func,filenames)\n elif os.path.isfile(d):\n filenames.append(d)\n return filenames\n\ndef get_data_files(data):\n if type(data) is types.StringType:\n return [data]\n sources = data[1]\n filenames = []\n for s in sources:\n if callable(s):\n s = s()\n if s is None:\n continue\n if is_local_src_dir(s):\n os.path.walk(s,_gsf_visit_func,filenames)\n elif type(s) is type(''):\n if os.path.isfile(s):\n filenames.append(s)\n else:\n print 'Not existing data file:',s\n else:\n raise TypeError,`s`\n return filenames\n\ndef dot_join(*args):\n return '.'.join(filter(None,args))\n\ndef get_frame(level=0):\n try:\n return sys._getframe(level+1)\n except AttributeError:\n frame = sys.exc_info()[2].tb_frame\n for i in range(level+1):\n frame = frame.f_back\n return frame\n\n######################\n\nclass Configuration:\n\n _list_keys = ['packages','ext_modules','data_files','include_dirs',\n 'libraries','headers','scripts','py_modules']\n _dict_keys = ['package_dir']\n\n numpy_include_dirs = []\n\n def __init__(self,\n package_name=None,\n parent_name=None,\n top_path=None,\n package_path=None,\n **attrs):\n \"\"\" Construct configuration instance of a package.\n \"\"\"\n self.name = dot_join(parent_name, package_name)\n\n caller_frame = get_frame(1)\n caller_name = eval('__name__',caller_frame.f_globals,caller_frame.f_locals)\n \n self.local_path = get_path(caller_name, top_path)\n if top_path is None:\n top_path = self.local_path\n if package_path is None:\n package_path = self.local_path\n elif os.path.isdir(os.path.join(self.local_path,package_path)):\n package_path = os.path.join(self.local_path,package_path)\n assert os.path.isdir(package_path),`package_path`\n self.top_path = top_path\n\n self.list_keys = copy.copy(self._list_keys)\n self.dict_keys = copy.copy(self._dict_keys)\n\n for n in self.list_keys:\n setattr(self,n,copy.copy(attrs.get(n,[])))\n\n for n in self.dict_keys:\n setattr(self,n,copy.copy(attrs.get(n,{})))\n\n known_keys = self.list_keys + self.dict_keys\n self.extra_keys = []\n for n in attrs.keys():\n if n in known_keys:\n continue\n a = attrs[n]\n setattr(self,n,a)\n if type(a) is types.ListType:\n self.list_keys.append(n)\n elif type(a) is types.DictType:\n self.dict_keys.append(n)\n else:\n self.extra_keys.append(n)\n\n if os.path.exists(os.path.join(package_path,'__init__.py')):\n self.packages.append(self.name)\n self.package_dir[self.name] = package_path \n return\n\n def todict(self):\n \"\"\" Return configuration distionary suitable for passing\n to distutils.core.setup() function.\n \"\"\"\n d = {}\n for n in self.list_keys + self.dict_keys + self.extra_keys:\n a = getattr(self,n)\n if a:\n d[n] = a\n if self.name:\n d['name'] = self.name\n return d\n\n def __dict__(self):\n return self.todict()\n\n def get_distribution(self):\n import distutils.core\n dist = distutils.core._setup_distribution \n return dist\n\n def get_subpackage(self,subpackage_name,subpackage_path=None):\n \"\"\" Return subpackage configuration.\n \"\"\"\n if subpackage_name is None:\n assert subpackage_path is not None\n subpackage_name = os.path.basename(subpackage_path)\n l = subpackage_name.split('.')\n if subpackage_path is None:\n subpackage_path = os.path.join(*([self.local_path]+l))\n if '*' in subpackage_name:\n dirs = filter(os.path.isdir,glob.glob(subpackage_path))\n config_list = []\n for d in dirs:\n if not os.path.isfile(os.path.join(d,'__init__.py')):\n continue\n n = '.'.join(d.split(os.sep)[-len(l):])\n c = self.get_subpackage(n)\n if c:\n config_list.append(c)\n return config_list\n else:\n subpackage_path = os.path.join(*([subpackage_path]+l[:-1]))\n subpackage_path = self._fix_paths([subpackage_path])[0]\n\n setup_py = os.path.join(subpackage_path,'setup.py')\n if not os.path.isfile(setup_py):\n setup_py = os.path.join(subpackage_path,'setup_%s.py' % (subpackage_name))\n\n if not os.path.isfile(setup_py):\n print 'Assuming default configuration '\\\n '(%s/{setup_%s,setup}.py was not found)' \\\n % (os.path.dirname(setup_py),subpackage_name)\n config = Configuration(subpackage_name,self.name,\n self.top_path,subpackage_path)\n else:\n # In case setup_py imports local modules:\n sys.path.insert(0,os.path.dirname(setup_py))\n try:\n info = (open(setup_py),setup_py,('.py','U',1))\n setup_name = os.path.splitext(os.path.basename(setup_py))[0]\n n = dot_join(self.name,setup_name)\n setup_module = imp.load_module('_'.join(n.split('.')),*info)\n\n if not hasattr(setup_module,'configuration'):\n print 'Assuming default configuration '\\\n '(%s does not define configuration())' % (setup_module)\n config = Configuration(subpackage_name,self.name,\n self.top_path,subpackage_path)\n else:\n args = (self.name,)\n if setup_module.configuration.func_code.co_argcount>1:\n args = args + (self.top_path,)\n config = setup_module.configuration(*args)\n\n finally:\n del sys.path[0]\n\n return config\n\n def add_subpackage(self,subpackage_name,subpackage_path=None):\n \"\"\" Add subpackage to configuration.\n \"\"\"\n config = self.get_subpackage(subpackage_name,subpackage_path)\n if not isinstance(config, list):\n config_list = [config]\n else:\n config_list = config\n for config in config_list:\n if not config:\n print 'No configuration returned, assuming unavailable.'\n else:\n if isinstance(config,Configuration):\n print 'Appending %s configuration to %s' % (config.name,self.name)\n self.dict_append(**config.todict())\n else:\n print 'Appending %s configuration to %s' % (config.get('name'),self.name)\n self.dict_append(**config)\n\n dist = self.get_distribution()\n if dist is not None:\n print 'distutils distribution has been initialized, it may be too late to add a subpackage', subpackage_name\n return\n\n def add_data_dir(self,data_path):\n \"\"\" Recursively add files under data_path to data_files list.\n Argument can be either\n - 2-sequence (,)\n - path to data directory where python datadir suffix defaults\n to package dir.\n If path is not absolute then it's datadir suffix is\n package dir + subdirname of the path.\n \"\"\"\n if type(data_path) is type(()):\n assert len(data_path)==2,`data_path`\n d,data_path = data_path\n else:\n d = None\n assert type(data_path) is type(''),`data_path`\n for path in self.paths(data_path):\n if not os.path.exists(path):\n print 'Not existing data path',path\n continue\n filenames = []\n os.path.walk(path, _gsf_visit_func,filenames)\n if not os.path.isabs(path):\n if d is None:\n ds = os.path.join(*(self.name.split('.')+[data_path]))\n else:\n ds = os.path.join(d,data_path)\n self.add_data_files((ds,filenames))\n else:\n if d is None:\n self.add_data_files(*filenames)\n else:\n self.add_data_files((d,filenames))\n return\n\n def add_data_files(self,*files):\n \"\"\" Add data files to configuration data_files.\n Argument(s) can be either\n - 2-sequence (,)\n - paths to data files where python datadir prefix defaults\n to package dir.\n If path is not absolute then it's datadir prefix is\n package dir + dirname of the path.\n \"\"\"\n data_dict = {}\n new_files = []\n for p in files:\n if type(p) is not type(()):\n d = os.path.join(*(self.name.split('.')))\n if type(p) is type('') and not os.path.isabs(p):\n d = appendpath(d,os.path.dirname(p))\n p = (d,p)\n new_files.append(p)\n files = []\n for prefix,filepattern in new_files:\n if type(filepattern) is type(''):\n file_list = self.paths(filepattern)\n elif callable(filepattern):\n file_list = [filepattern]\n else:\n file_list = self.paths(*filepattern)\n\n nof_path_components = [len(f.split(os.sep)) \\\n for f in file_list if type(f) is type('')]\n if nof_path_components:\n min_path_components = min(nof_path_components)-1\n else:\n min_path_components = 0\n\n for f in file_list:\n if type(f) is type(''):\n extra_path_components = f.split(os.sep)[min_path_components:-1]\n p = os.path.join(*([prefix]+extra_path_components))\n else:\n p = prefix\n if not data_dict.has_key(p):\n data_dict[p] = [f]\n else:\n data_dict[p].append(f)\n\n dist = self.get_distribution()\n if dist is not None:\n dist.data_files.extend(data_dict.items())\n else:\n self.data_files.extend(data_dict.items())\n return \n\n ### XXX Implement add_py_modules\n \n def add_include_dirs(self,*paths):\n \"\"\" Add paths to configuration include directories.\n \"\"\"\n include_dirs = self._fix_paths(paths)\n dist = self.get_distribution()\n if dist is not None:\n dist.include_dirs.extend(include_dirs)\n else:\n self.include_dirs.extend(include_dirs)\n return\n\n def add_headers(self,*files):\n \"\"\" Add installable headers to configuration.\n Argument(s) can be either\n - 2-sequence (,)\n - path(s) to header file(s) where python includedir suffix will default\n to package name.\n \"\"\"\n headers = []\n for path in files:\n if type(path) is type(''):\n [headers.append((self.name,p)) for p in self.paths(path)]\n else:\n assert type(path) in [type(()),type([])] and len(path)==2,`path`\n [headers.append((path[0],p)) for p in self.paths(path[1])]\n dist = self.get_distribution()\n if dist is not None:\n dist.headers.extend(headers)\n else:\n self.headers.extend(headers)\n return\n\n def _fix_paths(self,paths):\n new_paths = []\n for n in paths:\n if isinstance(n,str):\n if '*' in n or '?' in n:\n p = glob.glob(n)\n p2 = glob.glob(os.path.join(self.local_path,n))\n if p2:\n new_paths.extend(p2)\n elif p:\n new_paths.extend(p)\n else:\n new_paths.append(n)\n else:\n n2 = os.path.join(self.local_path,n)\n if os.path.exists(n2):\n new_paths.append(n2)\n else:\n new_paths.append(n)\n else:\n new_paths.append(n)\n return new_paths\n\n def paths(self,*paths):\n \"\"\" Apply glob to paths and prepend local_path if needed.\n \"\"\"\n return self._fix_paths(paths)\n\n def add_extension(self,name,sources,**kw):\n \"\"\" Add extension to configuration.\n\n Keywords:\n include_dirs, define_macros, undef_macros,\n library_dirs, libraries, runtime_library_dirs,\n extra_objects, extra_compile_args, extra_link_args,\n export_symbols, swig_opts, depends, language,\n f2py_options, module_dirs\n extra_info - dict or list of dict of keywords to be\n appended to keywords.\n \"\"\"\n ext_args = copy.copy(kw)\n ext_args['name'] = dot_join(self.name,name)\n ext_args['sources'] = sources\n\n if ext_args.has_key('extra_info'):\n extra_info = ext_args['extra_info']\n del ext_args['extra_info']\n if type(extra_info) is type({}):\n extra_info = [extra_info]\n for info in extra_info:\n assert type(info) is type({}),`info`\n dict_append(ext_args,**info)\n\n for k in ext_args.keys():\n v = ext_args[k]\n if k in ['sources','depends','include_dirs','library_dirs',\n 'module_dirs','extra_objects']:\n new_v = self._fix_paths(v)\n ext_args[k] = new_v\n\n # Resolve out-of-tree dependencies\n libraries = ext_args.get('libraries',[])\n libnames = []\n ext_args['libraries'] = []\n for libname in libraries:\n if '@' in libname:\n lname,lpath = libname.split('@',1)\n lpath = os.path.abspath(os.path.join(self.local_path,lpath))\n if os.path.isdir(lpath):\n c = self.get_subpackage(None,lpath)\n if isinstance(c,Configuration):\n c = c.todict()\n for l in [l[0] for l in c.get('libraries',[])]:\n llname = l.split('__OF__',1)[0]\n if llname == lname:\n c.pop('name',None)\n dict_append(ext_args,**c)\n break\n continue\n libnames.append(libname)\n\n ext_args['libraries'] = libnames + ext_args['libraries']\n\n from numpy.distutils.core import Extension\n ext = Extension(**ext_args)\n self.ext_modules.append(ext)\n\n dist = self.get_distribution()\n if dist is not None:\n print 'distutils distribution has been initialized, it may be too late to add an extension', name\n return ext\n\n def add_library(self,name,sources,**build_info):\n \"\"\" Add library to configuration.\n \n Valid keywords for build_info:\n depends\n macros\n include_dirs\n extra_compiler_args\n f2py_options\n \"\"\"\n build_info = copy.copy(build_info)\n name = name #+ '__OF__' + self.name\n build_info['sources'] = sources\n\n for k in build_info.keys():\n v = build_info[k]\n if k in ['sources','depends']:\n new_v = self._fix_paths(v)\n build_info[k] = new_v\n self.libraries.append((name,build_info))\n\n dist = self.get_distribution()\n if dist is not None:\n print 'distutils distribution has been initialized, it may be too late to add a library', name\n return\n\n def add_scripts(self,*files):\n \"\"\" Add scripts to configuration.\n \"\"\"\n scripts = self._fix_paths(files)\n dist = self.get_distribution()\n if dist is not None:\n dist.scripts.extend(scripts)\n else:\n self.scripts.extend(scripts)\n return\n\n def dict_append(self,**dict):\n for key in self.list_keys:\n a = getattr(self,key)\n a.extend(dict.get(key,[]))\n for key in self.dict_keys:\n a = getattr(self,key)\n a.update(dict.get(key,{}))\n known_keys = self.list_keys + self.dict_keys + self.extra_keys\n for key in dict.keys():\n if key not in known_keys and not hasattr(self,key):\n print 'Inheriting attribute %r from %r' \\\n % (key,dict.get('name','?'))\n setattr(self,key,dict[key])\n self.extra_keys.append(key)\n return\n\n def __str__(self):\n known_keys = self.list_keys + self.dict_keys + self.extra_keys\n s = '<'+5*'-' + '\\n'\n s += 'Configuration of '+self.name+':\\n'\n for k in known_keys:\n a = getattr(self,k,None)\n if a:\n s += '%s = %r\\n' % (k,a)\n s += 5*'-' + '>'\n return s\n\n def get_config_cmd(self):\n cmd = get_cmd('config')\n cmd.ensure_finalized()\n cmd.dump_source = 0\n cmd.noisy = 0\n old_path = os.environ.get('PATH')\n if old_path:\n path = os.pathsep.join(['.',old_path])\n os.environ['PATH'] = path\n return cmd\n\n def get_build_temp_dir(self):\n cmd = get_cmd('build')\n cmd.ensure_finalized()\n return cmd.build_temp\n\n def have_f77c(self):\n \"\"\" Check for availability of Fortran 77 compiler.\n Use it inside source generating function to ensure that\n setup distribution instance has been initialized.\n \"\"\"\n simple_fortran_subroutine = '''\n subroutine simple\n end\n '''\n config_cmd = self.get_config_cmd()\n flag = config_cmd.try_compile(simple_fortran_subroutine,lang='f77')\n return flag\n\n def have_f90c(self):\n \"\"\" Check for availability of Fortran 90 compiler.\n Use it inside source generating function to ensure that\n setup distribution instance has been initialized.\n \"\"\"\n simple_fortran_subroutine = '''\n subroutine simple\n end\n '''\n config_cmd = self.get_config_cmd()\n flag = config_cmd.try_compile(simple_fortran_subroutine,lang='f90')\n return flag\n\n def append_to(self, extlib):\n \"\"\" Append libraries, include_dirs to extension or library item.\n \"\"\"\n if type(extlib) is type(()):\n lib_name, build_info = extlib\n dict_append(build_info,\n libraries=self.libraries,\n include_dirs=self.include_dirs)\n else:\n from numpy.distutils.core import Extension\n assert isinstance(extlib,Extension),`extlib`\n extlib.libraries.extend(self.libraries)\n extlib.include_dirs.extend(self.include_dirs)\n return\n\n def _get_svn_revision(self,path):\n \"\"\" Return path's SVN revision number.\n \"\"\"\n entries = os.path.join(path,'.svn','entries')\n revision = None\n if os.path.isfile(entries):\n f = open(entries)\n m = re.search(r'revision=\"(?P\\d+)\"',f.read())\n f.close()\n if m:\n revision = int(m.group('revision'))\n return revision\n\n def get_version(self):\n \"\"\" Try to get version string of a package.\n \"\"\"\n version = getattr(self,'version',None)\n if version is not None:\n return version\n\n # Get version from version file.\n files = ['__version__.py',\n self.name.split('.')[-1]+'_version.py',\n 'version.py',\n '__svn_version__.py']\n version_vars = ['version',\n '__version__',\n self.name.split('.')[-1]+'_version']\n for f in files:\n fn = os.path.join(self.local_path,f)\n if os.path.isfile(fn):\n info = (open(fn),fn,('.py','U',1))\n name = os.path.splitext(os.path.basename(fn))[0]\n n = dot_join(self.name,name)\n try:\n version_module = imp.load_module('_'.join(n.split('.')),*info)\n except ImportError,msg:\n print msg\n version_module = None\n if version_module is None:\n continue\n\n for a in version_vars:\n version = getattr(version_module,a,None)\n if version is not None:\n break\n if version is not None:\n break\n\n if version is not None:\n self.version = version\n return version\n\n # Get version as SVN revision number\n revision = self._get_svn_revision(self.local_path)\n if revision is not None:\n version = str(revision)\n self.version = version\n\n return version\n\n def make_svn_version_py(self):\n \"\"\" Generate package __svn_version__.py file from SVN revision number,\n it will be removed after python exits but will be available\n when sdist, etc commands are executed.\n\n If __svn_version__.py existed before, nothing is done.\n \"\"\"\n target = os.path.join(self.local_path,'__svn_version__.py')\n if os.path.isfile(target):\n return\n\n def generate_svn_version_py():\n if not os.path.isfile(target):\n revision = self._get_svn_revision(self.local_path)\n assert revision is not None,'hmm, why I am not inside SVN tree???'\n version = str(revision)\n print 'Creating %s (version=%r)' % (target,version)\n f = open(target,'w')\n f.write('version = %r\\n' % (version))\n f.close()\n \n import atexit\n def rm_file(f=target):\n try: os.remove(f); print 'removed',f\n except OSError: pass\n try: os.remove(f+'c'); print 'removed',f+'c'\n except OSError: pass\n atexit.register(rm_file)\n\n return target\n\n d = os.path.join(*(self.name.split('.')))\n self.add_data_files((d, generate_svn_version_py()))\n return\n\n def make_config_py(self,name='__config__'):\n \"\"\" Generate package __config__.py file containing system_info\n information used during building the package.\n \"\"\"\n self.py_modules.append((self.name,name,generate_config_py))\n return\n\n def get_info(self,*names):\n \"\"\" Get resources information.\n \"\"\"\n from system_info import get_info, dict_append\n info_dict = {}\n for a in names:\n dict_append(info_dict,**get_info(a))\n return info_dict\n\ndef get_cmd(cmdname,_cache={}):\n if not _cache.has_key(cmdname):\n import distutils.core\n dist = distutils.core._setup_distribution\n if dist is None:\n from distutils.errors import DistutilsInternalError\n raise DistutilsInternalError,\\\n 'setup distribution instance not initialized'\n cmd = dist.get_command_obj(cmdname)\n _cache[cmdname] = cmd\n return _cache[cmdname]\n\ndef get_numpy_include_dirs():\n # numpy_include_dirs are set by numpy/core/setup.py, otherwise []\n include_dirs = Configuration.numpy_include_dirs[:]\n if not include_dirs:\n import numpy\n if numpy.show_config is None:\n # running from numpy_core source directory\n include_dirs.append(os.path.join(os.path.dirname(numpy.__file__),\n 'core','include'))\n else:\n # using installed numpy core headers\n import numpy.core as core\n include_dirs.append(os.path.join(os.path.dirname(core.__file__),'include'))\n # else running numpy/core/setup.py\n return include_dirs\n\n#########################\n\ndef default_config_dict(name = None, parent_name = None, local_path=None):\n \"\"\" Return a configuration dictionary for usage in\n configuration() function defined in file setup_.py.\n \"\"\"\n import warnings\n warnings.warn('Use Configuration(%s,%s,top_path=%s) instead of '\\\n 'deprecated default_config_dict(%s,%s,%s)' \\\n % (`name`,`parent_name`,`local_path`,\n `name`,`parent_name`,`local_path`,\n ))\n c = Configuration(name, parent_name, local_path)\n return c.todict()\n\n\ndef dict_append(d,**kws):\n for k,v in kws.items():\n if d.has_key(k):\n d[k].extend(v)\n else:\n d[k] = v\n\ndef appendpath(prefix,path):\n if not ('/' == os.path.sep):\n prefix = prefix.replace('/',os.path.sep)\n path = path.replace('/',os.path.sep)\n drive = ''\n if os.path.isabs(path):\n drive = os.path.splitdrive(prefix)[0]\n absprefix = os.path.splitdrive(os.path.abspath(prefix))[1]\n pathdrive,path = os.path.splitdrive(path)\n d = os.path.commonprefix([absprefix,path])\n if os.path.join(absprefix[:len(d)],absprefix[len(d):])!=absprefix \\\n or os.path.join(path[:len(d)],path[len(d):])!=path:\n # Handle invalid paths\n d = os.path.dirname(d)\n subpath = path[len(d):]\n if os.path.isabs(subpath):\n subpath = subpath[1:]\n else:\n subpath = path\n return os.path.normpath(os.path.join(drive + prefix, subpath))\n\ndef generate_config_py(target):\n \"\"\" Generate config.py file containing system_info information\n used during building the package.\n\n Usage:\\\n config['py_modules'].append((packagename, '__config__',generate_config_py))\n \"\"\"\n from numpy.distutils.system_info import system_info\n from distutils.dir_util import mkpath\n mkpath(os.path.dirname(target))\n f = open(target,'w')\n f.write('# This file is generated by %s\\n' % (os.path.abspath(sys.argv[0])))\n f.write('# It contains system_info results at the time of building this package.\\n')\n f.write('__all__ = [\"get_info\",\"show\"]\\n\\n')\n for k,i in system_info.saved_results.items():\n f.write('%s=%r\\n' % (k,i))\n f.write('\\ndef get_info(name): g=globals(); return g.get(name,g.get(name+\"_info\",{}))\\n')\n f.write('''\ndef show():\n for name,info_dict in globals().items():\n if name[0]==\"_\" or type(info_dict) is not type({}): continue\n print name+\":\"\n if not info_dict:\n print \" NOT AVAILABLE\"\n for k,v in info_dict.items():\n v = str(v)\n if k==\\'sources\\' and len(v)>200: v = v[:60]+\\' ...\\\\n... \\'+v[-60:]\n print \\' %s = %s\\'%(k,v)\n print\n return\n ''')\n\n f.close()\n return target\n\ndef generate_svn_version_py(extension, build_dir):\n \"\"\" Generate __svn_version__.py file containing SVN\n revision number of a module.\n \n To use, add the following codelet to setup\n configuration(..) function\n\n ext = Extension(dot_join(config['name'],'__svn_version__'),\n sources=[generate_svn_version_py])\n ext.local_path = local_path\n config['ext_modules'].append(ext)\n\n \"\"\"\n from distutils import dep_util\n local_path = extension.local_path\n target = os.path.join(build_dir, '__svn_version__.py')\n entries = os.path.join(local_path,'.svn','entries')\n if os.path.isfile(entries):\n if not dep_util.newer(entries, target):\n return target\n elif os.path.isfile(target):\n return target\n\n revision = get_svn_revision(local_path)\n f = open(target,'w')\n f.write('revision=%s\\n' % (revision))\n f.close()\n return target\n", + "methods": [ + { + "name": "allpath", + "long_name": "allpath( name )", + "filename": "misc_util.py", + "nloc": 4, + "complexity": 1, + "token_count": 24, + "parameters": [ + "name" + ], + "start_line": 19, + "end_line": 22, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 4, + "top_nesting_level": 0 + }, + { + "name": "get_path", + "long_name": "get_path( mod_name , parent_path = None )", + "filename": "misc_util.py", + "nloc": 15, + "complexity": 6, + "token_count": 132, + "parameters": [ + "mod_name", + "parent_path" + ], + "start_line": 24, + "end_line": 44, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 21, + "top_nesting_level": 0 + }, + { + "name": "terminal_has_colors", + "long_name": "terminal_has_colors( )", + "filename": "misc_util.py", + "nloc": 18, + "complexity": 13, + "token_count": 137, + "parameters": [], + "start_line": 48, + "end_line": 73, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 26, + "top_nesting_level": 0 + }, + { + "name": "cyg2win32", + "long_name": "cyg2win32( path )", + "filename": "misc_util.py", + "nloc": 4, + "complexity": 3, + "token_count": 42, + "parameters": [ + "path" + ], + "start_line": 90, + "end_line": 93, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 4, + "top_nesting_level": 0 + }, + { + "name": "_get_f90_modules", + "long_name": "_get_f90_modules( source )", + "filename": "misc_util.py", + "nloc": 13, + "complexity": 4, + "token_count": 77, + "parameters": [ + "source" + ], + "start_line": 102, + "end_line": 118, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 17, + "top_nesting_level": 0 + }, + { + "name": "all_strings", + "long_name": "all_strings( lst )", + "filename": "misc_util.py", + "nloc": 5, + "complexity": 3, + "token_count": 26, + "parameters": [ + "lst" + ], + "start_line": 120, + "end_line": 125, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 6, + "top_nesting_level": 0 + }, + { + "name": "has_f_sources", + "long_name": "has_f_sources( sources )", + "filename": "misc_util.py", + "nloc": 5, + "complexity": 3, + "token_count": 21, + "parameters": [ + "sources" + ], + "start_line": 127, + "end_line": 132, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 6, + "top_nesting_level": 0 + }, + { + "name": "has_cxx_sources", + "long_name": "has_cxx_sources( sources )", + "filename": "misc_util.py", + "nloc": 5, + "complexity": 3, + "token_count": 21, + "parameters": [ + "sources" + ], + "start_line": 134, + "end_line": 139, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 6, + "top_nesting_level": 0 + }, + { + "name": "filter_sources", + "long_name": "filter_sources( sources )", + "filename": "misc_util.py", + "nloc": 17, + "complexity": 5, + "token_count": 84, + "parameters": [ + "sources" + ], + "start_line": 141, + "end_line": 161, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 21, + "top_nesting_level": 0 + }, + { + "name": "_get_headers", + "long_name": "_get_headers( directory_list )", + "filename": "misc_util.py", + "nloc": 6, + "complexity": 2, + "token_count": 39, + "parameters": [ + "directory_list" + ], + "start_line": 164, + "end_line": 170, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 7, + "top_nesting_level": 0 + }, + { + "name": "_get_directories", + "long_name": "_get_directories( list_of_sources )", + "filename": "misc_util.py", + "nloc": 7, + "complexity": 4, + "token_count": 51, + "parameters": [ + "list_of_sources" + ], + "start_line": 172, + "end_line": 179, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 8, + "top_nesting_level": 0 + }, + { + "name": "get_dependencies", + "long_name": "get_dependencies( sources )", + "filename": "misc_util.py", + "nloc": 2, + "complexity": 1, + "token_count": 13, + "parameters": [ + "sources" + ], + "start_line": 181, + "end_line": 183, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 3, + "top_nesting_level": 0 + }, + { + "name": "is_local_src_dir", + "long_name": "is_local_src_dir( directory )", + "filename": "misc_util.py", + "nloc": 12, + "complexity": 6, + "token_count": 112, + "parameters": [ + "directory" + ], + "start_line": 185, + "end_line": 198, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 14, + "top_nesting_level": 0 + }, + { + "name": "_gsf_visit_func", + "long_name": "_gsf_visit_func( filenames , dirname , names )", + "filename": "misc_util.py", + "nloc": 13, + "complexity": 7, + "token_count": 103, + "parameters": [ + "filenames", + "dirname", + "names" + ], + "start_line": 200, + "end_line": 212, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 13, + "top_nesting_level": 0 + }, + { + "name": "get_ext_source_files", + "long_name": "get_ext_source_files( ext )", + "filename": "misc_util.py", + "nloc": 11, + "complexity": 4, + "token_count": 87, + "parameters": [ + "ext" + ], + "start_line": 214, + "end_line": 225, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 12, + "top_nesting_level": 0 + }, + { + "name": "get_script_files", + "long_name": "get_script_files( scripts )", + "filename": "misc_util.py", + "nloc": 3, + "complexity": 1, + "token_count": 25, + "parameters": [ + "scripts" + ], + "start_line": 227, + "end_line": 229, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 3, + "top_nesting_level": 0 + }, + { + "name": "get_lib_source_files", + "long_name": "get_lib_source_files( lib )", + "filename": "misc_util.py", + "nloc": 13, + "complexity": 4, + "token_count": 111, + "parameters": [ + "lib" + ], + "start_line": 231, + "end_line": 243, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 13, + "top_nesting_level": 0 + }, + { + "name": "get_data_files", + "long_name": "get_data_files( data )", + "filename": "misc_util.py", + "nloc": 18, + "complexity": 7, + "token_count": 102, + "parameters": [ + "data" + ], + "start_line": 245, + "end_line": 262, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 18, + "top_nesting_level": 0 + }, + { + "name": "dot_join", + "long_name": "dot_join( * args )", + "filename": "misc_util.py", + "nloc": 2, + "complexity": 1, + "token_count": 18, + "parameters": [ + "args" + ], + "start_line": 264, + "end_line": 265, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 2, + "top_nesting_level": 0 + }, + { + "name": "get_frame", + "long_name": "get_frame( level = 0 )", + "filename": "misc_util.py", + "nloc": 8, + "complexity": 3, + "token_count": 50, + "parameters": [ + "level" + ], + "start_line": 267, + "end_line": 274, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 8, + "top_nesting_level": 0 + }, + { + "name": "__init__", + "long_name": "__init__( self , package_name = None , parent_name = None , top_path = None , package_path = None , ** attrs )", + "filename": "misc_util.py", + "nloc": 41, + "complexity": 11, + "token_count": 348, + "parameters": [ + "self", + "package_name", + "parent_name", + "top_path", + "package_path", + "attrs" + ], + "start_line": 286, + "end_line": 335, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 50, + "top_nesting_level": 1 + }, + { + "name": "todict", + "long_name": "todict( self )", + "filename": "misc_util.py", + "nloc": 9, + "complexity": 4, + "token_count": 57, + "parameters": [ + "self" + ], + "start_line": 337, + "end_line": 348, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 12, + "top_nesting_level": 1 + }, + { + "name": "__dict__", + "long_name": "__dict__( self )", + "filename": "misc_util.py", + "nloc": 2, + "complexity": 1, + "token_count": 11, + "parameters": [ + "self" + ], + "start_line": 350, + "end_line": 351, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 2, + "top_nesting_level": 1 + }, + { + "name": "get_distribution", + "long_name": "get_distribution( self )", + "filename": "misc_util.py", + "nloc": 4, + "complexity": 1, + "token_count": 18, + "parameters": [ + "self" + ], + "start_line": 353, + "end_line": 356, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 4, + "top_nesting_level": 1 + }, + { + "name": "get_subpackage", + "long_name": "get_subpackage( self , subpackage_name , subpackage_path = None )", + "filename": "misc_util.py", + "nloc": 50, + "complexity": 12, + "token_count": 453, + "parameters": [ + "self", + "subpackage_name", + "subpackage_path" + ], + "start_line": 358, + "end_line": 415, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 58, + "top_nesting_level": 1 + }, + { + "name": "add_subpackage", + "long_name": "add_subpackage( self , subpackage_name , subpackage_path = None )", + "filename": "misc_util.py", + "nloc": 20, + "complexity": 6, + "token_count": 127, + "parameters": [ + "self", + "subpackage_name", + "subpackage_path" + ], + "start_line": 417, + "end_line": 439, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 23, + "top_nesting_level": 1 + }, + { + "name": "add_data_dir", + "long_name": "add_data_dir( self , data_path )", + "filename": "misc_util.py", + "nloc": 25, + "complexity": 7, + "token_count": 188, + "parameters": [ + "self", + "data_path" + ], + "start_line": 441, + "end_line": 473, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 33, + "top_nesting_level": 1 + }, + { + "name": "add_data_files", + "long_name": "add_data_files( self , * files )", + "filename": "misc_util.py", + "nloc": 40, + "complexity": 15, + "token_count": 324, + "parameters": [ + "self", + "files" + ], + "start_line": 475, + "end_line": 525, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 51, + "top_nesting_level": 1 + }, + { + "name": "add_include_dirs", + "long_name": "add_include_dirs( self , * paths )", + "filename": "misc_util.py", + "nloc": 8, + "complexity": 2, + "token_count": 49, + "parameters": [ + "self", + "paths" + ], + "start_line": 529, + "end_line": 538, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 10, + "top_nesting_level": 1 + }, + { + "name": "add_headers", + "long_name": "add_headers( self , * files )", + "filename": "misc_util.py", + "nloc": 14, + "complexity": 7, + "token_count": 143, + "parameters": [ + "self", + "files" + ], + "start_line": 540, + "end_line": 559, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 20, + "top_nesting_level": 1 + }, + { + "name": "_fix_paths", + "long_name": "_fix_paths( self , paths )", + "filename": "misc_util.py", + "nloc": 22, + "complexity": 8, + "token_count": 136, + "parameters": [ + "self", + "paths" + ], + "start_line": 561, + "end_line": 582, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 22, + "top_nesting_level": 1 + }, + { + "name": "paths", + "long_name": "paths( self , * paths )", + "filename": "misc_util.py", + "nloc": 2, + "complexity": 1, + "token_count": 16, + "parameters": [ + "self", + "paths" + ], + "start_line": 584, + "end_line": 587, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 4, + "top_nesting_level": 1 + }, + { + "name": "add_extension", + "long_name": "add_extension( self , name , sources , ** kw )", + "filename": "misc_util.py", + "nloc": 45, + "complexity": 14, + "token_count": 365, + "parameters": [ + "self", + "name", + "sources", + "kw" + ], + "start_line": 589, + "end_line": 651, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 63, + "top_nesting_level": 1 + }, + { + "name": "add_library", + "long_name": "add_library( self , name , sources , ** build_info )", + "filename": "misc_util.py", + "nloc": 14, + "complexity": 4, + "token_count": 98, + "parameters": [ + "self", + "name", + "sources", + "build_info" + ], + "start_line": 653, + "end_line": 677, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 25, + "top_nesting_level": 1 + }, + { + "name": "add_scripts", + "long_name": "add_scripts( self , * files )", + "filename": "misc_util.py", + "nloc": 8, + "complexity": 2, + "token_count": 49, + "parameters": [ + "self", + "files" + ], + "start_line": 679, + "end_line": 688, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 10, + "top_nesting_level": 1 + }, + { + "name": "dict_append", + "long_name": "dict_append( self , ** dict )", + "filename": "misc_util.py", + "nloc": 15, + "complexity": 6, + "token_count": 138, + "parameters": [ + "self", + "dict" + ], + "start_line": 690, + "end_line": 704, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 15, + "top_nesting_level": 1 + }, + { + "name": "__str__", + "long_name": "__str__( self )", + "filename": "misc_util.py", + "nloc": 10, + "complexity": 3, + "token_count": 72, + "parameters": [ + "self" + ], + "start_line": 706, + "end_line": 715, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 10, + "top_nesting_level": 1 + }, + { + "name": "get_config_cmd", + "long_name": "get_config_cmd( self )", + "filename": "misc_util.py", + "nloc": 10, + "complexity": 2, + "token_count": 63, + "parameters": [ + "self" + ], + "start_line": 717, + "end_line": 726, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 10, + "top_nesting_level": 1 + }, + { + "name": "get_build_temp_dir", + "long_name": "get_build_temp_dir( self )", + "filename": "misc_util.py", + "nloc": 4, + "complexity": 1, + "token_count": 20, + "parameters": [ + "self" + ], + "start_line": 728, + "end_line": 731, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 4, + "top_nesting_level": 1 + }, + { + "name": "have_f77c", + "long_name": "have_f77c( self )", + "filename": "misc_util.py", + "nloc": 8, + "complexity": 1, + "token_count": 30, + "parameters": [ + "self" + ], + "start_line": 733, + "end_line": 744, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 12, + "top_nesting_level": 1 + }, + { + "name": "have_f90c", + "long_name": "have_f90c( self )", + "filename": "misc_util.py", + "nloc": 8, + "complexity": 1, + "token_count": 30, + "parameters": [ + "self" + ], + "start_line": 746, + "end_line": 757, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 12, + "top_nesting_level": 1 + }, + { + "name": "append_to", + "long_name": "append_to( self , extlib )", + "filename": "misc_util.py", + "nloc": 12, + "complexity": 2, + "token_count": 83, + "parameters": [ + "self", + "extlib" + ], + "start_line": 759, + "end_line": 772, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 14, + "top_nesting_level": 1 + }, + { + "name": "_get_svn_revision", + "long_name": "_get_svn_revision( self , path )", + "filename": "misc_util.py", + "nloc": 10, + "complexity": 3, + "token_count": 77, + "parameters": [ + "self", + "path" + ], + "start_line": 774, + "end_line": 785, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 12, + "top_nesting_level": 1 + }, + { + "name": "get_version", + "long_name": "get_version( self )", + "filename": "misc_util.py", + "nloc": 38, + "complexity": 11, + "token_count": 257, + "parameters": [ + "self" + ], + "start_line": 787, + "end_line": 833, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 47, + "top_nesting_level": 1 + }, + { + "name": "make_svn_version_py.make_svn_version_py.generate_svn_version_py.rm_file", + "long_name": "make_svn_version_py.make_svn_version_py.generate_svn_version_py.rm_file( f = target )", + "filename": "misc_util.py", + "nloc": 5, + "complexity": 3, + "token_count": 45, + "parameters": [ + "f" + ], + "start_line": 857, + "end_line": 861, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 5, + "top_nesting_level": 3 + }, + { + "name": "make_svn_version_py.generate_svn_version_py", + "long_name": "make_svn_version_py.generate_svn_version_py( )", + "filename": "misc_util.py", + "nloc": 13, + "complexity": 2, + "token_count": 81, + "parameters": [], + "start_line": 846, + "end_line": 864, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 19, + "top_nesting_level": 2 + }, + { + "name": "make_svn_version_py", + "long_name": "make_svn_version_py( self )", + "filename": "misc_util.py", + "nloc": 8, + "complexity": 2, + "token_count": 66, + "parameters": [ + "self" + ], + "start_line": 835, + "end_line": 868, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 34, + "top_nesting_level": 1 + }, + { + "name": "make_config_py", + "long_name": "make_config_py( self , name = '__config__' )", + "filename": "misc_util.py", + "nloc": 3, + "complexity": 1, + "token_count": 27, + "parameters": [ + "self", + "name" + ], + "start_line": 870, + "end_line": 875, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 6, + "top_nesting_level": 1 + }, + { + "name": "get_info", + "long_name": "get_info( self , * names )", + "filename": "misc_util.py", + "nloc": 6, + "complexity": 2, + "token_count": 36, + "parameters": [ + "self", + "names" + ], + "start_line": 877, + "end_line": 884, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 8, + "top_nesting_level": 1 + }, + { + "name": "get_cmd", + "long_name": "get_cmd( cmdname , _cache = { } )", + "filename": "misc_util.py", + "nloc": 11, + "complexity": 3, + "token_count": 65, + "parameters": [ + "cmdname", + "_cache" + ], + "start_line": 886, + "end_line": 896, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 11, + "top_nesting_level": 0 + }, + { + "name": "get_numpy_include_dirs", + "long_name": "get_numpy_include_dirs( )", + "filename": "misc_util.py", + "nloc": 11, + "complexity": 3, + "token_count": 85, + "parameters": [], + "start_line": 898, + "end_line": 912, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 15, + "top_nesting_level": 0 + }, + { + "name": "default_config_dict", + "long_name": "default_config_dict( name = None , parent_name = None , local_path = None )", + "filename": "misc_util.py", + "nloc": 9, + "complexity": 1, + "token_count": 70, + "parameters": [ + "name", + "parent_name", + "local_path" + ], + "start_line": 916, + "end_line": 927, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 12, + "top_nesting_level": 0 + }, + { + "name": "dict_append", + "long_name": "dict_append( d , ** kws )", + "filename": "misc_util.py", + "nloc": 6, + "complexity": 3, + "token_count": 44, + "parameters": [ + "d", + "kws" + ], + "start_line": 930, + "end_line": 935, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 6, + "top_nesting_level": 0 + }, + { + "name": "appendpath", + "long_name": "appendpath( prefix , path )", + "filename": "misc_util.py", + "nloc": 19, + "complexity": 6, + "token_count": 237, + "parameters": [ + "prefix", + "path" + ], + "start_line": 937, + "end_line": 956, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 20, + "top_nesting_level": 0 + }, + { + "name": "generate_config_py", + "long_name": "generate_config_py( target )", + "filename": "misc_util.py", + "nloc": 27, + "complexity": 2, + "token_count": 117, + "parameters": [ + "target" + ], + "start_line": 958, + "end_line": 991, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 34, + "top_nesting_level": 0 + }, + { + "name": "generate_svn_version_py", + "long_name": "generate_svn_version_py( extension , build_dir )", + "filename": "misc_util.py", + "nloc": 15, + "complexity": 4, + "token_count": 109, + "parameters": [ + "extension", + "build_dir" + ], + "start_line": 993, + "end_line": 1020, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 28, + "top_nesting_level": 0 + } + ], + "methods_before": [ + { + "name": "allpath", + "long_name": "allpath( name )", + "filename": "misc_util.py", + "nloc": 4, + "complexity": 1, + "token_count": 24, + "parameters": [ + "name" + ], + "start_line": 19, + "end_line": 22, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 4, + "top_nesting_level": 0 + }, + { + "name": "get_path", + "long_name": "get_path( mod_name , parent_path = None )", + "filename": "misc_util.py", + "nloc": 15, + "complexity": 6, + "token_count": 132, + "parameters": [ + "mod_name", + "parent_path" + ], + "start_line": 24, + "end_line": 44, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 21, + "top_nesting_level": 0 + }, + { + "name": "terminal_has_colors", + "long_name": "terminal_has_colors( )", + "filename": "misc_util.py", + "nloc": 18, + "complexity": 13, + "token_count": 137, + "parameters": [], + "start_line": 48, + "end_line": 73, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 26, + "top_nesting_level": 0 + }, + { + "name": "cyg2win32", + "long_name": "cyg2win32( path )", + "filename": "misc_util.py", + "nloc": 4, + "complexity": 3, + "token_count": 42, + "parameters": [ + "path" + ], + "start_line": 90, + "end_line": 93, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 4, + "top_nesting_level": 0 + }, + { + "name": "_get_f90_modules", + "long_name": "_get_f90_modules( source )", + "filename": "misc_util.py", + "nloc": 13, + "complexity": 4, + "token_count": 77, + "parameters": [ + "source" + ], + "start_line": 102, + "end_line": 118, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 17, + "top_nesting_level": 0 + }, + { + "name": "all_strings", + "long_name": "all_strings( lst )", + "filename": "misc_util.py", + "nloc": 5, + "complexity": 3, + "token_count": 26, + "parameters": [ + "lst" + ], + "start_line": 120, + "end_line": 125, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 6, + "top_nesting_level": 0 + }, + { + "name": "has_f_sources", + "long_name": "has_f_sources( sources )", + "filename": "misc_util.py", + "nloc": 5, + "complexity": 3, + "token_count": 21, + "parameters": [ + "sources" + ], + "start_line": 127, + "end_line": 132, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 6, + "top_nesting_level": 0 + }, + { + "name": "has_cxx_sources", + "long_name": "has_cxx_sources( sources )", + "filename": "misc_util.py", + "nloc": 5, + "complexity": 3, + "token_count": 21, + "parameters": [ + "sources" + ], + "start_line": 134, + "end_line": 139, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 6, + "top_nesting_level": 0 + }, + { + "name": "filter_sources", + "long_name": "filter_sources( sources )", + "filename": "misc_util.py", + "nloc": 17, + "complexity": 5, + "token_count": 84, + "parameters": [ + "sources" + ], + "start_line": 141, + "end_line": 161, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 21, + "top_nesting_level": 0 + }, + { + "name": "_get_headers", + "long_name": "_get_headers( directory_list )", + "filename": "misc_util.py", + "nloc": 6, + "complexity": 2, + "token_count": 39, + "parameters": [ + "directory_list" + ], + "start_line": 164, + "end_line": 170, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 7, + "top_nesting_level": 0 + }, + { + "name": "_get_directories", + "long_name": "_get_directories( list_of_sources )", + "filename": "misc_util.py", + "nloc": 7, + "complexity": 4, + "token_count": 51, + "parameters": [ + "list_of_sources" + ], + "start_line": 172, + "end_line": 179, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 8, + "top_nesting_level": 0 + }, + { + "name": "get_dependencies", + "long_name": "get_dependencies( sources )", + "filename": "misc_util.py", + "nloc": 2, + "complexity": 1, + "token_count": 13, + "parameters": [ + "sources" + ], + "start_line": 181, + "end_line": 183, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 3, + "top_nesting_level": 0 + }, + { + "name": "is_local_src_dir", + "long_name": "is_local_src_dir( directory )", + "filename": "misc_util.py", + "nloc": 12, + "complexity": 6, + "token_count": 112, + "parameters": [ + "directory" + ], + "start_line": 185, + "end_line": 198, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 14, + "top_nesting_level": 0 + }, + { + "name": "_gsf_visit_func", + "long_name": "_gsf_visit_func( filenames , dirname , names )", + "filename": "misc_util.py", + "nloc": 13, + "complexity": 7, + "token_count": 103, + "parameters": [ + "filenames", + "dirname", + "names" + ], + "start_line": 200, + "end_line": 212, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 13, + "top_nesting_level": 0 + }, + { + "name": "get_ext_source_files", + "long_name": "get_ext_source_files( ext )", + "filename": "misc_util.py", + "nloc": 11, + "complexity": 4, + "token_count": 87, + "parameters": [ + "ext" + ], + "start_line": 214, + "end_line": 225, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 12, + "top_nesting_level": 0 + }, + { + "name": "get_script_files", + "long_name": "get_script_files( scripts )", + "filename": "misc_util.py", + "nloc": 3, + "complexity": 1, + "token_count": 25, + "parameters": [ + "scripts" + ], + "start_line": 227, + "end_line": 229, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 3, + "top_nesting_level": 0 + }, + { + "name": "get_lib_source_files", + "long_name": "get_lib_source_files( lib )", + "filename": "misc_util.py", + "nloc": 13, + "complexity": 4, + "token_count": 111, + "parameters": [ + "lib" + ], + "start_line": 231, + "end_line": 243, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 13, + "top_nesting_level": 0 + }, + { + "name": "get_data_files", + "long_name": "get_data_files( data )", + "filename": "misc_util.py", + "nloc": 20, + "complexity": 8, + "token_count": 112, + "parameters": [ + "data" + ], + "start_line": 245, + "end_line": 264, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 20, + "top_nesting_level": 0 + }, + { + "name": "dot_join", + "long_name": "dot_join( * args )", + "filename": "misc_util.py", + "nloc": 2, + "complexity": 1, + "token_count": 18, + "parameters": [ + "args" + ], + "start_line": 266, + "end_line": 267, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 2, + "top_nesting_level": 0 + }, + { + "name": "get_frame", + "long_name": "get_frame( level = 0 )", + "filename": "misc_util.py", + "nloc": 8, + "complexity": 3, + "token_count": 50, + "parameters": [ + "level" + ], + "start_line": 269, + "end_line": 276, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 8, + "top_nesting_level": 0 + }, + { + "name": "__init__", + "long_name": "__init__( self , package_name = None , parent_name = None , top_path = None , package_path = None , ** attrs )", + "filename": "misc_util.py", + "nloc": 41, + "complexity": 11, + "token_count": 348, + "parameters": [ + "self", + "package_name", + "parent_name", + "top_path", + "package_path", + "attrs" + ], + "start_line": 288, + "end_line": 337, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 50, + "top_nesting_level": 1 + }, + { + "name": "todict", + "long_name": "todict( self )", + "filename": "misc_util.py", + "nloc": 9, + "complexity": 4, + "token_count": 57, + "parameters": [ + "self" + ], + "start_line": 339, + "end_line": 350, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 12, + "top_nesting_level": 1 + }, + { + "name": "__dict__", + "long_name": "__dict__( self )", + "filename": "misc_util.py", + "nloc": 2, + "complexity": 1, + "token_count": 11, + "parameters": [ + "self" + ], + "start_line": 352, + "end_line": 353, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 2, + "top_nesting_level": 1 + }, + { + "name": "get_distribution", + "long_name": "get_distribution( self )", + "filename": "misc_util.py", + "nloc": 4, + "complexity": 1, + "token_count": 18, + "parameters": [ + "self" + ], + "start_line": 355, + "end_line": 358, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 4, + "top_nesting_level": 1 + }, + { + "name": "get_subpackage", + "long_name": "get_subpackage( self , subpackage_name , subpackage_path = None )", + "filename": "misc_util.py", + "nloc": 50, + "complexity": 12, + "token_count": 453, + "parameters": [ + "self", + "subpackage_name", + "subpackage_path" + ], + "start_line": 360, + "end_line": 417, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 58, + "top_nesting_level": 1 + }, + { + "name": "add_subpackage", + "long_name": "add_subpackage( self , subpackage_name , subpackage_path = None )", + "filename": "misc_util.py", + "nloc": 20, + "complexity": 6, + "token_count": 127, + "parameters": [ + "self", + "subpackage_name", + "subpackage_path" + ], + "start_line": 419, + "end_line": 441, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 23, + "top_nesting_level": 1 + }, + { + "name": "add_data_dir", + "long_name": "add_data_dir( self , data_path )", + "filename": "misc_util.py", + "nloc": 25, + "complexity": 7, + "token_count": 188, + "parameters": [ + "self", + "data_path" + ], + "start_line": 443, + "end_line": 475, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 33, + "top_nesting_level": 1 + }, + { + "name": "add_data_files", + "long_name": "add_data_files( self , * files )", + "filename": "misc_util.py", + "nloc": 40, + "complexity": 15, + "token_count": 324, + "parameters": [ + "self", + "files" + ], + "start_line": 477, + "end_line": 527, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 51, + "top_nesting_level": 1 + }, + { + "name": "add_include_dirs", + "long_name": "add_include_dirs( self , * paths )", + "filename": "misc_util.py", + "nloc": 8, + "complexity": 2, + "token_count": 49, + "parameters": [ + "self", + "paths" + ], + "start_line": 531, + "end_line": 540, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 10, + "top_nesting_level": 1 + }, + { + "name": "add_headers", + "long_name": "add_headers( self , * files )", + "filename": "misc_util.py", + "nloc": 14, + "complexity": 7, + "token_count": 143, + "parameters": [ + "self", + "files" + ], + "start_line": 542, + "end_line": 561, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 20, + "top_nesting_level": 1 + }, + { + "name": "_fix_paths", + "long_name": "_fix_paths( self , paths )", + "filename": "misc_util.py", + "nloc": 22, + "complexity": 8, + "token_count": 136, + "parameters": [ + "self", + "paths" + ], + "start_line": 563, + "end_line": 584, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 22, + "top_nesting_level": 1 + }, + { + "name": "paths", + "long_name": "paths( self , * paths )", + "filename": "misc_util.py", + "nloc": 2, + "complexity": 1, + "token_count": 16, + "parameters": [ + "self", + "paths" + ], + "start_line": 586, + "end_line": 589, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 4, + "top_nesting_level": 1 + }, + { + "name": "add_extension", + "long_name": "add_extension( self , name , sources , ** kw )", + "filename": "misc_util.py", + "nloc": 45, + "complexity": 14, + "token_count": 365, + "parameters": [ + "self", + "name", + "sources", + "kw" + ], + "start_line": 591, + "end_line": 653, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 63, + "top_nesting_level": 1 + }, + { + "name": "add_library", + "long_name": "add_library( self , name , sources , ** build_info )", + "filename": "misc_util.py", + "nloc": 14, + "complexity": 4, + "token_count": 98, + "parameters": [ + "self", + "name", + "sources", + "build_info" + ], + "start_line": 655, + "end_line": 679, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 25, + "top_nesting_level": 1 + }, + { + "name": "add_scripts", + "long_name": "add_scripts( self , * files )", + "filename": "misc_util.py", + "nloc": 8, + "complexity": 2, + "token_count": 49, + "parameters": [ + "self", + "files" + ], + "start_line": 681, + "end_line": 690, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 10, + "top_nesting_level": 1 + }, + { + "name": "dict_append", + "long_name": "dict_append( self , ** dict )", + "filename": "misc_util.py", + "nloc": 15, + "complexity": 6, + "token_count": 138, + "parameters": [ + "self", + "dict" + ], + "start_line": 692, + "end_line": 706, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 15, + "top_nesting_level": 1 + }, + { + "name": "__str__", + "long_name": "__str__( self )", + "filename": "misc_util.py", + "nloc": 10, + "complexity": 3, + "token_count": 72, + "parameters": [ + "self" + ], + "start_line": 708, + "end_line": 717, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 10, + "top_nesting_level": 1 + }, + { + "name": "get_config_cmd", + "long_name": "get_config_cmd( self )", + "filename": "misc_util.py", + "nloc": 10, + "complexity": 2, + "token_count": 63, + "parameters": [ + "self" + ], + "start_line": 719, + "end_line": 728, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 10, + "top_nesting_level": 1 + }, + { + "name": "get_build_temp_dir", + "long_name": "get_build_temp_dir( self )", + "filename": "misc_util.py", + "nloc": 4, + "complexity": 1, + "token_count": 20, + "parameters": [ + "self" + ], + "start_line": 730, + "end_line": 733, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 4, + "top_nesting_level": 1 + }, + { + "name": "have_f77c", + "long_name": "have_f77c( self )", + "filename": "misc_util.py", + "nloc": 8, + "complexity": 1, + "token_count": 30, + "parameters": [ + "self" + ], + "start_line": 735, + "end_line": 746, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 12, + "top_nesting_level": 1 + }, + { + "name": "have_f90c", + "long_name": "have_f90c( self )", + "filename": "misc_util.py", + "nloc": 8, + "complexity": 1, + "token_count": 30, + "parameters": [ + "self" + ], + "start_line": 748, + "end_line": 759, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 12, + "top_nesting_level": 1 + }, + { + "name": "append_to", + "long_name": "append_to( self , extlib )", + "filename": "misc_util.py", + "nloc": 12, + "complexity": 2, + "token_count": 83, + "parameters": [ + "self", + "extlib" + ], + "start_line": 761, + "end_line": 774, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 14, + "top_nesting_level": 1 + }, + { + "name": "_get_svn_revision", + "long_name": "_get_svn_revision( self , path )", + "filename": "misc_util.py", + "nloc": 10, + "complexity": 3, + "token_count": 77, + "parameters": [ + "self", + "path" + ], + "start_line": 776, + "end_line": 787, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 12, + "top_nesting_level": 1 + }, + { + "name": "get_version", + "long_name": "get_version( self )", + "filename": "misc_util.py", + "nloc": 38, + "complexity": 11, + "token_count": 257, + "parameters": [ + "self" + ], + "start_line": 789, + "end_line": 835, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 47, + "top_nesting_level": 1 + }, + { + "name": "make_svn_version_py.make_svn_version_py.generate_svn_version_py.rm_file", + "long_name": "make_svn_version_py.make_svn_version_py.generate_svn_version_py.rm_file( f = target )", + "filename": "misc_util.py", + "nloc": 5, + "complexity": 3, + "token_count": 45, + "parameters": [ + "f" + ], + "start_line": 859, + "end_line": 863, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 5, + "top_nesting_level": 3 + }, + { + "name": "make_svn_version_py.generate_svn_version_py", + "long_name": "make_svn_version_py.generate_svn_version_py( )", + "filename": "misc_util.py", + "nloc": 13, + "complexity": 2, + "token_count": 81, + "parameters": [], + "start_line": 848, + "end_line": 866, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 19, + "top_nesting_level": 2 + }, + { + "name": "make_svn_version_py", + "long_name": "make_svn_version_py( self )", + "filename": "misc_util.py", + "nloc": 8, + "complexity": 2, + "token_count": 66, + "parameters": [ + "self" + ], + "start_line": 837, + "end_line": 870, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 34, + "top_nesting_level": 1 + }, + { + "name": "make_config_py", + "long_name": "make_config_py( self , name = '__config__' )", + "filename": "misc_util.py", + "nloc": 3, + "complexity": 1, + "token_count": 27, + "parameters": [ + "self", + "name" + ], + "start_line": 872, + "end_line": 877, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 6, + "top_nesting_level": 1 + }, + { + "name": "get_info", + "long_name": "get_info( self , * names )", + "filename": "misc_util.py", + "nloc": 6, + "complexity": 2, + "token_count": 36, + "parameters": [ + "self", + "names" + ], + "start_line": 879, + "end_line": 886, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 8, + "top_nesting_level": 1 + }, + { + "name": "get_cmd", + "long_name": "get_cmd( cmdname , _cache = { } )", + "filename": "misc_util.py", + "nloc": 11, + "complexity": 3, + "token_count": 65, + "parameters": [ + "cmdname", + "_cache" + ], + "start_line": 888, + "end_line": 898, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 11, + "top_nesting_level": 0 + }, + { + "name": "get_numpy_include_dirs", + "long_name": "get_numpy_include_dirs( )", + "filename": "misc_util.py", + "nloc": 11, + "complexity": 3, + "token_count": 85, + "parameters": [], + "start_line": 900, + "end_line": 914, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 15, + "top_nesting_level": 0 + }, + { + "name": "default_config_dict", + "long_name": "default_config_dict( name = None , parent_name = None , local_path = None )", + "filename": "misc_util.py", + "nloc": 9, + "complexity": 1, + "token_count": 70, + "parameters": [ + "name", + "parent_name", + "local_path" + ], + "start_line": 918, + "end_line": 929, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 12, + "top_nesting_level": 0 + }, + { + "name": "dict_append", + "long_name": "dict_append( d , ** kws )", + "filename": "misc_util.py", + "nloc": 6, + "complexity": 3, + "token_count": 44, + "parameters": [ + "d", + "kws" + ], + "start_line": 932, + "end_line": 937, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 6, + "top_nesting_level": 0 + }, + { + "name": "appendpath", + "long_name": "appendpath( prefix , path )", + "filename": "misc_util.py", + "nloc": 19, + "complexity": 6, + "token_count": 237, + "parameters": [ + "prefix", + "path" + ], + "start_line": 939, + "end_line": 958, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 20, + "top_nesting_level": 0 + }, + { + "name": "generate_config_py", + "long_name": "generate_config_py( target )", + "filename": "misc_util.py", + "nloc": 27, + "complexity": 2, + "token_count": 117, + "parameters": [ + "target" + ], + "start_line": 960, + "end_line": 993, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 34, + "top_nesting_level": 0 + }, + { + "name": "generate_svn_version_py", + "long_name": "generate_svn_version_py( extension , build_dir )", + "filename": "misc_util.py", + "nloc": 15, + "complexity": 4, + "token_count": 109, + "parameters": [ + "extension", + "build_dir" + ], + "start_line": 995, + "end_line": 1022, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 28, + "top_nesting_level": 0 + } + ], + "changed_methods": [ + { + "name": "get_data_files", + "long_name": "get_data_files( data )", + "filename": "misc_util.py", + "nloc": 18, + "complexity": 7, + "token_count": 102, + "parameters": [ + "data" + ], + "start_line": 245, + "end_line": 262, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 18, + "top_nesting_level": 0 + } + ], + "nloc": 768, + "complexity": 238, + "token_count": 5722, + "diff_parsed": { + "added": [ + " continue" + ], + "deleted": [ + " s = s()", + " if s is None:", + " continue" + ] + } + } + ] + }, + { + "hash": "f94d937892c7d82bdb35115968f6fa0d2d8d67cc", + "msg": "Resolve paths in add_library include_dirs..", + "author": { + "name": "Pearu Peterson", + "email": "pearu.peterson@gmail.com" + }, + "committer": { + "name": "Pearu Peterson", + "email": "pearu.peterson@gmail.com" + }, + "author_date": "2006-01-27T19:10:43+00:00", + "author_timezone": 0, + "committer_date": "2006-01-27T19:10:43+00:00", + "committer_timezone": 0, + "branches": [ + "main" + ], + "in_main_branch": true, + "merge": false, + "parents": [ + "6bf1820ba23583a96331dedc07338dc2ee78564b" + ], + "project_name": "repo_copy", + "project_path": "/tmp/tmppy2o86q9/repo_copy", + "deletions": 1, + "insertions": 2, + "lines": 3, + "files": 1, + "dmm_unit_size": 1.0, + "dmm_unit_complexity": 1.0, + "dmm_unit_interfacing": 0.0, + "modified_files": [ + { + "old_path": "numpy/distutils/misc_util.py", + "new_path": "numpy/distutils/misc_util.py", + "filename": "misc_util.py", + "extension": "py", + "change_type": "MODIFY", + "diff": "@@ -666,7 +666,8 @@ def add_library(self,name,sources,**build_info):\n \n for k in build_info.keys():\n v = build_info[k]\n- if k in ['sources','depends']:\n+ if k in ['sources','depends','include_dirs','library_dirs',\n+ 'module_dirs','extra_objects']:\n new_v = self._fix_paths(v)\n build_info[k] = new_v\n self.libraries.append((name,build_info))\n", + "added_lines": 2, + "deleted_lines": 1, + "source_code": "import os\nimport re\nimport sys\nimport imp\nimport copy\nimport types\nimport glob\n\n__all__ = ['Configuration', 'get_numpy_include_dirs', 'default_config_dict',\n 'dict_append', 'appendpath', 'generate_config_py',\n 'generate_svn_version_py', 'get_cmd', 'allpath',\n 'terminal_has_colors', 'red_text', 'green_text', 'yellow_text',\n 'blue_text', 'cyan_text', 'cyg2win32', 'all_strings',\n 'has_f_sources', 'has_cxx_sources', 'filter_sources',\n 'get_dependencies', 'is_local_src_dir', 'get_ext_source_files',\n 'get_script_files', 'get_lib_source_files', 'get_data_files',\n 'dot_join', 'get_frame']\n\ndef allpath(name):\n \"Convert a /-separated pathname to one using the OS's path separator.\"\n splitted = name.split('/')\n return os.path.join(*splitted)\n\ndef get_path(mod_name,parent_path=None):\n \"\"\" Return path of the module.\n\n Returned path is relative to parent_path when given,\n otherwise it is absolute path.\n \"\"\"\n if mod_name == '__main__':\n d = os.path.abspath('.')\n elif mod_name == '__builtin__':\n #builtin if/then added by Pearu for use in core.run_setup. \n d = os.path.dirname(os.path.abspath(sys.argv[0]))\n else:\n __import__(mod_name)\n mod = sys.modules[mod_name]\n file = mod.__file__\n d = os.path.dirname(os.path.abspath(file))\n if parent_path is not None:\n pd = os.path.abspath(parent_path)\n if pd==d[:len(pd)]:\n d = d[len(pd)+1:]\n return d or '.'\n\n# Hooks for colored terminal output.\n# See also http://www.livinglogic.de/Python/ansistyle\ndef terminal_has_colors():\n if sys.platform=='cygwin' and not os.environ.has_key('USE_COLOR'):\n # Avoid importing curses that causes illegal operation\n # with a message:\n # PYTHON2 caused an invalid page fault in\n # module CYGNURSES7.DLL as 015f:18bbfc28\n # Details: Python 2.3.3 [GCC 3.3.1 (cygming special)]\n # ssh to Win32 machine from debian\n # curses.version is 2.2\n # CYGWIN_98-4.10, release 1.5.7(0.109/3/2))\n return 0\n if hasattr(sys.stdout,'isatty') and sys.stdout.isatty(): \n try:\n import curses\n curses.setupterm()\n if (curses.tigetnum(\"colors\") >= 0\n and curses.tigetnum(\"pairs\") >= 0\n and ((curses.tigetstr(\"setf\") is not None \n and curses.tigetstr(\"setb\") is not None) \n or (curses.tigetstr(\"setaf\") is not None\n and curses.tigetstr(\"setab\") is not None)\n or curses.tigetstr(\"scp\") is not None)):\n return 1\n except Exception,msg:\n pass\n return 0\n\nif terminal_has_colors():\n def red_text(s): return '\\x1b[31m%s\\x1b[0m'%s\n def green_text(s): return '\\x1b[32m%s\\x1b[0m'%s\n def yellow_text(s): return '\\x1b[33m%s\\x1b[0m'%s\n def blue_text(s): return '\\x1b[34m%s\\x1b[0m'%s\n def cyan_text(s): return '\\x1b[35m%s\\x1b[0m'%s\nelse:\n def red_text(s): return s\n def green_text(s): return s\n def yellow_text(s): return s\n def cyan_text(s): return s\n def blue_text(s): return s\n\n#########################\n\ndef cyg2win32(path):\n if sys.platform=='cygwin' and path.startswith('/cygdrive'):\n path = path[10] + ':' + os.path.normcase(path[11:])\n return path\n\n#########################\n\n#XXX need support for .C that is also C++\ncxx_ext_match = re.compile(r'.*[.](cpp|cxx|cc)\\Z',re.I).match\nfortran_ext_match = re.compile(r'.*[.](f90|f95|f77|for|ftn|f)\\Z',re.I).match\nf90_ext_match = re.compile(r'.*[.](f90|f95)\\Z',re.I).match\nf90_module_name_match = re.compile(r'\\s*module\\s*(?P[\\w_]+)',re.I).match\ndef _get_f90_modules(source):\n \"\"\" Return a list of Fortran f90 module names that\n given source file defines.\n \"\"\"\n if not f90_ext_match(source):\n return []\n modules = []\n f = open(source,'r')\n f_readlines = getattr(f,'xreadlines',f.readlines)\n for line in f_readlines():\n m = f90_module_name_match(line)\n if m:\n name = m.group('name')\n modules.append(name)\n # break # XXX can we assume that there is one module per file?\n f.close()\n return modules\n\ndef all_strings(lst):\n \"\"\" Return True if all items in lst are string objects. \"\"\"\n for item in lst:\n if type(item) is not types.StringType:\n return False\n return True\n\ndef has_f_sources(sources):\n \"\"\" Return True if sources contains Fortran files \"\"\"\n for source in sources:\n if fortran_ext_match(source):\n return True\n return False\n\ndef has_cxx_sources(sources):\n \"\"\" Return True if sources contains C++ files \"\"\"\n for source in sources:\n if cxx_ext_match(source):\n return True\n return False\n\ndef filter_sources(sources):\n \"\"\" Return four lists of filenames containing\n C, C++, Fortran, and Fortran 90 module sources,\n respectively.\n \"\"\"\n c_sources = []\n cxx_sources = []\n f_sources = []\n fmodule_sources = []\n for source in sources:\n if fortran_ext_match(source):\n modules = _get_f90_modules(source)\n if modules:\n fmodule_sources.append(source)\n else:\n f_sources.append(source)\n elif cxx_ext_match(source):\n cxx_sources.append(source)\n else:\n c_sources.append(source) \n return c_sources, cxx_sources, f_sources, fmodule_sources\n\n\ndef _get_headers(directory_list):\n # get *.h files from list of directories\n headers = []\n for dir in directory_list:\n head = glob.glob(os.path.join(dir,\"*.h\")) #XXX: *.hpp files??\n headers.extend(head)\n return headers\n\ndef _get_directories(list_of_sources):\n # get unique directories from list of sources.\n direcs = []\n for file in list_of_sources:\n dir = os.path.split(file)\n if dir[0] != '' and not dir[0] in direcs:\n direcs.append(dir[0])\n return direcs\n\ndef get_dependencies(sources):\n #XXX scan sources for include statements\n return _get_headers(_get_directories(sources))\n\ndef is_local_src_dir(directory):\n \"\"\" Return true if directory is local directory.\n \"\"\"\n if type(directory) is not type(''):\n return False\n abs_dir = os.path.abspath(directory)\n c = os.path.commonprefix([os.getcwd(),abs_dir])\n new_dir = abs_dir[len(c):].split(os.sep)\n if new_dir and not new_dir[0]:\n new_dir = new_dir[1:]\n if new_dir and new_dir[0]=='build':\n return False\n new_dir = os.sep.join(new_dir)\n return os.path.isdir(new_dir)\n\ndef _gsf_visit_func(filenames,dirname,names):\n if os.path.basename(dirname) in ['CVS','.svn','build']:\n names[:] = []\n return\n for name in names:\n if name[-1] in \"~#\":\n continue\n fullname = os.path.join(dirname,name)\n ext = os.path.splitext(fullname)[1]\n if ext and ext in ['.pyc','.o']:\n continue\n if os.path.isfile(fullname):\n filenames.append(fullname)\n\ndef get_ext_source_files(ext):\n # Get sources and any include files in the same directory.\n filenames = []\n sources = filter(lambda s:type(s) is types.StringType,ext.sources)\n filenames.extend(sources)\n filenames.extend(get_dependencies(sources))\n for d in ext.depends:\n if is_local_src_dir(d):\n os.path.walk(d,_gsf_visit_func,filenames)\n elif os.path.isfile(d):\n filenames.append(d)\n return filenames\n\ndef get_script_files(scripts):\n scripts = filter(lambda s:type(s) is types.StringType,scripts)\n return scripts\n\ndef get_lib_source_files(lib):\n filenames = []\n sources = lib[1].get('sources',[])\n sources = filter(lambda s:type(s) is types.StringType,sources)\n filenames.extend(sources)\n filenames.extend(get_dependencies(sources))\n depends = lib[1].get('depends',[])\n for d in depends:\n if is_local_src_dir(d):\n os.path.walk(d,_gsf_visit_func,filenames)\n elif os.path.isfile(d):\n filenames.append(d)\n return filenames\n\ndef get_data_files(data):\n if type(data) is types.StringType:\n return [data]\n sources = data[1]\n filenames = []\n for s in sources:\n if callable(s):\n continue\n if is_local_src_dir(s):\n os.path.walk(s,_gsf_visit_func,filenames)\n elif type(s) is type(''):\n if os.path.isfile(s):\n filenames.append(s)\n else:\n print 'Not existing data file:',s\n else:\n raise TypeError,`s`\n return filenames\n\ndef dot_join(*args):\n return '.'.join(filter(None,args))\n\ndef get_frame(level=0):\n try:\n return sys._getframe(level+1)\n except AttributeError:\n frame = sys.exc_info()[2].tb_frame\n for i in range(level+1):\n frame = frame.f_back\n return frame\n\n######################\n\nclass Configuration:\n\n _list_keys = ['packages','ext_modules','data_files','include_dirs',\n 'libraries','headers','scripts','py_modules']\n _dict_keys = ['package_dir']\n\n numpy_include_dirs = []\n\n def __init__(self,\n package_name=None,\n parent_name=None,\n top_path=None,\n package_path=None,\n **attrs):\n \"\"\" Construct configuration instance of a package.\n \"\"\"\n self.name = dot_join(parent_name, package_name)\n\n caller_frame = get_frame(1)\n caller_name = eval('__name__',caller_frame.f_globals,caller_frame.f_locals)\n \n self.local_path = get_path(caller_name, top_path)\n if top_path is None:\n top_path = self.local_path\n if package_path is None:\n package_path = self.local_path\n elif os.path.isdir(os.path.join(self.local_path,package_path)):\n package_path = os.path.join(self.local_path,package_path)\n assert os.path.isdir(package_path),`package_path`\n self.top_path = top_path\n\n self.list_keys = copy.copy(self._list_keys)\n self.dict_keys = copy.copy(self._dict_keys)\n\n for n in self.list_keys:\n setattr(self,n,copy.copy(attrs.get(n,[])))\n\n for n in self.dict_keys:\n setattr(self,n,copy.copy(attrs.get(n,{})))\n\n known_keys = self.list_keys + self.dict_keys\n self.extra_keys = []\n for n in attrs.keys():\n if n in known_keys:\n continue\n a = attrs[n]\n setattr(self,n,a)\n if type(a) is types.ListType:\n self.list_keys.append(n)\n elif type(a) is types.DictType:\n self.dict_keys.append(n)\n else:\n self.extra_keys.append(n)\n\n if os.path.exists(os.path.join(package_path,'__init__.py')):\n self.packages.append(self.name)\n self.package_dir[self.name] = package_path \n return\n\n def todict(self):\n \"\"\" Return configuration distionary suitable for passing\n to distutils.core.setup() function.\n \"\"\"\n d = {}\n for n in self.list_keys + self.dict_keys + self.extra_keys:\n a = getattr(self,n)\n if a:\n d[n] = a\n if self.name:\n d['name'] = self.name\n return d\n\n def __dict__(self):\n return self.todict()\n\n def get_distribution(self):\n import distutils.core\n dist = distutils.core._setup_distribution \n return dist\n\n def get_subpackage(self,subpackage_name,subpackage_path=None):\n \"\"\" Return subpackage configuration.\n \"\"\"\n if subpackage_name is None:\n assert subpackage_path is not None\n subpackage_name = os.path.basename(subpackage_path)\n l = subpackage_name.split('.')\n if subpackage_path is None:\n subpackage_path = os.path.join(*([self.local_path]+l))\n if '*' in subpackage_name:\n dirs = filter(os.path.isdir,glob.glob(subpackage_path))\n config_list = []\n for d in dirs:\n if not os.path.isfile(os.path.join(d,'__init__.py')):\n continue\n n = '.'.join(d.split(os.sep)[-len(l):])\n c = self.get_subpackage(n)\n if c:\n config_list.append(c)\n return config_list\n else:\n subpackage_path = os.path.join(*([subpackage_path]+l[:-1]))\n subpackage_path = self._fix_paths([subpackage_path])[0]\n\n setup_py = os.path.join(subpackage_path,'setup.py')\n if not os.path.isfile(setup_py):\n setup_py = os.path.join(subpackage_path,'setup_%s.py' % (subpackage_name))\n\n if not os.path.isfile(setup_py):\n print 'Assuming default configuration '\\\n '(%s/{setup_%s,setup}.py was not found)' \\\n % (os.path.dirname(setup_py),subpackage_name)\n config = Configuration(subpackage_name,self.name,\n self.top_path,subpackage_path)\n else:\n # In case setup_py imports local modules:\n sys.path.insert(0,os.path.dirname(setup_py))\n try:\n info = (open(setup_py),setup_py,('.py','U',1))\n setup_name = os.path.splitext(os.path.basename(setup_py))[0]\n n = dot_join(self.name,setup_name)\n setup_module = imp.load_module('_'.join(n.split('.')),*info)\n\n if not hasattr(setup_module,'configuration'):\n print 'Assuming default configuration '\\\n '(%s does not define configuration())' % (setup_module)\n config = Configuration(subpackage_name,self.name,\n self.top_path,subpackage_path)\n else:\n args = (self.name,)\n if setup_module.configuration.func_code.co_argcount>1:\n args = args + (self.top_path,)\n config = setup_module.configuration(*args)\n\n finally:\n del sys.path[0]\n\n return config\n\n def add_subpackage(self,subpackage_name,subpackage_path=None):\n \"\"\" Add subpackage to configuration.\n \"\"\"\n config = self.get_subpackage(subpackage_name,subpackage_path)\n if not isinstance(config, list):\n config_list = [config]\n else:\n config_list = config\n for config in config_list:\n if not config:\n print 'No configuration returned, assuming unavailable.'\n else:\n if isinstance(config,Configuration):\n print 'Appending %s configuration to %s' % (config.name,self.name)\n self.dict_append(**config.todict())\n else:\n print 'Appending %s configuration to %s' % (config.get('name'),self.name)\n self.dict_append(**config)\n\n dist = self.get_distribution()\n if dist is not None:\n print 'distutils distribution has been initialized, it may be too late to add a subpackage', subpackage_name\n return\n\n def add_data_dir(self,data_path):\n \"\"\" Recursively add files under data_path to data_files list.\n Argument can be either\n - 2-sequence (,)\n - path to data directory where python datadir suffix defaults\n to package dir.\n If path is not absolute then it's datadir suffix is\n package dir + subdirname of the path.\n \"\"\"\n if type(data_path) is type(()):\n assert len(data_path)==2,`data_path`\n d,data_path = data_path\n else:\n d = None\n assert type(data_path) is type(''),`data_path`\n for path in self.paths(data_path):\n if not os.path.exists(path):\n print 'Not existing data path',path\n continue\n filenames = []\n os.path.walk(path, _gsf_visit_func,filenames)\n if not os.path.isabs(path):\n if d is None:\n ds = os.path.join(*(self.name.split('.')+[data_path]))\n else:\n ds = os.path.join(d,data_path)\n self.add_data_files((ds,filenames))\n else:\n if d is None:\n self.add_data_files(*filenames)\n else:\n self.add_data_files((d,filenames))\n return\n\n def add_data_files(self,*files):\n \"\"\" Add data files to configuration data_files.\n Argument(s) can be either\n - 2-sequence (,)\n - paths to data files where python datadir prefix defaults\n to package dir.\n If path is not absolute then it's datadir prefix is\n package dir + dirname of the path.\n \"\"\"\n data_dict = {}\n new_files = []\n for p in files:\n if type(p) is not type(()):\n d = os.path.join(*(self.name.split('.')))\n if type(p) is type('') and not os.path.isabs(p):\n d = appendpath(d,os.path.dirname(p))\n p = (d,p)\n new_files.append(p)\n files = []\n for prefix,filepattern in new_files:\n if type(filepattern) is type(''):\n file_list = self.paths(filepattern)\n elif callable(filepattern):\n file_list = [filepattern]\n else:\n file_list = self.paths(*filepattern)\n\n nof_path_components = [len(f.split(os.sep)) \\\n for f in file_list if type(f) is type('')]\n if nof_path_components:\n min_path_components = min(nof_path_components)-1\n else:\n min_path_components = 0\n\n for f in file_list:\n if type(f) is type(''):\n extra_path_components = f.split(os.sep)[min_path_components:-1]\n p = os.path.join(*([prefix]+extra_path_components))\n else:\n p = prefix\n if not data_dict.has_key(p):\n data_dict[p] = [f]\n else:\n data_dict[p].append(f)\n\n dist = self.get_distribution()\n if dist is not None:\n dist.data_files.extend(data_dict.items())\n else:\n self.data_files.extend(data_dict.items())\n return \n\n ### XXX Implement add_py_modules\n \n def add_include_dirs(self,*paths):\n \"\"\" Add paths to configuration include directories.\n \"\"\"\n include_dirs = self._fix_paths(paths)\n dist = self.get_distribution()\n if dist is not None:\n dist.include_dirs.extend(include_dirs)\n else:\n self.include_dirs.extend(include_dirs)\n return\n\n def add_headers(self,*files):\n \"\"\" Add installable headers to configuration.\n Argument(s) can be either\n - 2-sequence (,)\n - path(s) to header file(s) where python includedir suffix will default\n to package name.\n \"\"\"\n headers = []\n for path in files:\n if type(path) is type(''):\n [headers.append((self.name,p)) for p in self.paths(path)]\n else:\n assert type(path) in [type(()),type([])] and len(path)==2,`path`\n [headers.append((path[0],p)) for p in self.paths(path[1])]\n dist = self.get_distribution()\n if dist is not None:\n dist.headers.extend(headers)\n else:\n self.headers.extend(headers)\n return\n\n def _fix_paths(self,paths):\n new_paths = []\n for n in paths:\n if isinstance(n,str):\n if '*' in n or '?' in n:\n p = glob.glob(n)\n p2 = glob.glob(os.path.join(self.local_path,n))\n if p2:\n new_paths.extend(p2)\n elif p:\n new_paths.extend(p)\n else:\n new_paths.append(n)\n else:\n n2 = os.path.join(self.local_path,n)\n if os.path.exists(n2):\n new_paths.append(n2)\n else:\n new_paths.append(n)\n else:\n new_paths.append(n)\n return new_paths\n\n def paths(self,*paths):\n \"\"\" Apply glob to paths and prepend local_path if needed.\n \"\"\"\n return self._fix_paths(paths)\n\n def add_extension(self,name,sources,**kw):\n \"\"\" Add extension to configuration.\n\n Keywords:\n include_dirs, define_macros, undef_macros,\n library_dirs, libraries, runtime_library_dirs,\n extra_objects, extra_compile_args, extra_link_args,\n export_symbols, swig_opts, depends, language,\n f2py_options, module_dirs\n extra_info - dict or list of dict of keywords to be\n appended to keywords.\n \"\"\"\n ext_args = copy.copy(kw)\n ext_args['name'] = dot_join(self.name,name)\n ext_args['sources'] = sources\n\n if ext_args.has_key('extra_info'):\n extra_info = ext_args['extra_info']\n del ext_args['extra_info']\n if type(extra_info) is type({}):\n extra_info = [extra_info]\n for info in extra_info:\n assert type(info) is type({}),`info`\n dict_append(ext_args,**info)\n\n for k in ext_args.keys():\n v = ext_args[k]\n if k in ['sources','depends','include_dirs','library_dirs',\n 'module_dirs','extra_objects']:\n new_v = self._fix_paths(v)\n ext_args[k] = new_v\n\n # Resolve out-of-tree dependencies\n libraries = ext_args.get('libraries',[])\n libnames = []\n ext_args['libraries'] = []\n for libname in libraries:\n if '@' in libname:\n lname,lpath = libname.split('@',1)\n lpath = os.path.abspath(os.path.join(self.local_path,lpath))\n if os.path.isdir(lpath):\n c = self.get_subpackage(None,lpath)\n if isinstance(c,Configuration):\n c = c.todict()\n for l in [l[0] for l in c.get('libraries',[])]:\n llname = l.split('__OF__',1)[0]\n if llname == lname:\n c.pop('name',None)\n dict_append(ext_args,**c)\n break\n continue\n libnames.append(libname)\n\n ext_args['libraries'] = libnames + ext_args['libraries']\n\n from numpy.distutils.core import Extension\n ext = Extension(**ext_args)\n self.ext_modules.append(ext)\n\n dist = self.get_distribution()\n if dist is not None:\n print 'distutils distribution has been initialized, it may be too late to add an extension', name\n return ext\n\n def add_library(self,name,sources,**build_info):\n \"\"\" Add library to configuration.\n \n Valid keywords for build_info:\n depends\n macros\n include_dirs\n extra_compiler_args\n f2py_options\n \"\"\"\n build_info = copy.copy(build_info)\n name = name #+ '__OF__' + self.name\n build_info['sources'] = sources\n\n for k in build_info.keys():\n v = build_info[k]\n if k in ['sources','depends','include_dirs','library_dirs',\n 'module_dirs','extra_objects']:\n new_v = self._fix_paths(v)\n build_info[k] = new_v\n self.libraries.append((name,build_info))\n\n dist = self.get_distribution()\n if dist is not None:\n print 'distutils distribution has been initialized, it may be too late to add a library', name\n return\n\n def add_scripts(self,*files):\n \"\"\" Add scripts to configuration.\n \"\"\"\n scripts = self._fix_paths(files)\n dist = self.get_distribution()\n if dist is not None:\n dist.scripts.extend(scripts)\n else:\n self.scripts.extend(scripts)\n return\n\n def dict_append(self,**dict):\n for key in self.list_keys:\n a = getattr(self,key)\n a.extend(dict.get(key,[]))\n for key in self.dict_keys:\n a = getattr(self,key)\n a.update(dict.get(key,{}))\n known_keys = self.list_keys + self.dict_keys + self.extra_keys\n for key in dict.keys():\n if key not in known_keys and not hasattr(self,key):\n print 'Inheriting attribute %r from %r' \\\n % (key,dict.get('name','?'))\n setattr(self,key,dict[key])\n self.extra_keys.append(key)\n return\n\n def __str__(self):\n known_keys = self.list_keys + self.dict_keys + self.extra_keys\n s = '<'+5*'-' + '\\n'\n s += 'Configuration of '+self.name+':\\n'\n for k in known_keys:\n a = getattr(self,k,None)\n if a:\n s += '%s = %r\\n' % (k,a)\n s += 5*'-' + '>'\n return s\n\n def get_config_cmd(self):\n cmd = get_cmd('config')\n cmd.ensure_finalized()\n cmd.dump_source = 0\n cmd.noisy = 0\n old_path = os.environ.get('PATH')\n if old_path:\n path = os.pathsep.join(['.',old_path])\n os.environ['PATH'] = path\n return cmd\n\n def get_build_temp_dir(self):\n cmd = get_cmd('build')\n cmd.ensure_finalized()\n return cmd.build_temp\n\n def have_f77c(self):\n \"\"\" Check for availability of Fortran 77 compiler.\n Use it inside source generating function to ensure that\n setup distribution instance has been initialized.\n \"\"\"\n simple_fortran_subroutine = '''\n subroutine simple\n end\n '''\n config_cmd = self.get_config_cmd()\n flag = config_cmd.try_compile(simple_fortran_subroutine,lang='f77')\n return flag\n\n def have_f90c(self):\n \"\"\" Check for availability of Fortran 90 compiler.\n Use it inside source generating function to ensure that\n setup distribution instance has been initialized.\n \"\"\"\n simple_fortran_subroutine = '''\n subroutine simple\n end\n '''\n config_cmd = self.get_config_cmd()\n flag = config_cmd.try_compile(simple_fortran_subroutine,lang='f90')\n return flag\n\n def append_to(self, extlib):\n \"\"\" Append libraries, include_dirs to extension or library item.\n \"\"\"\n if type(extlib) is type(()):\n lib_name, build_info = extlib\n dict_append(build_info,\n libraries=self.libraries,\n include_dirs=self.include_dirs)\n else:\n from numpy.distutils.core import Extension\n assert isinstance(extlib,Extension),`extlib`\n extlib.libraries.extend(self.libraries)\n extlib.include_dirs.extend(self.include_dirs)\n return\n\n def _get_svn_revision(self,path):\n \"\"\" Return path's SVN revision number.\n \"\"\"\n entries = os.path.join(path,'.svn','entries')\n revision = None\n if os.path.isfile(entries):\n f = open(entries)\n m = re.search(r'revision=\"(?P\\d+)\"',f.read())\n f.close()\n if m:\n revision = int(m.group('revision'))\n return revision\n\n def get_version(self):\n \"\"\" Try to get version string of a package.\n \"\"\"\n version = getattr(self,'version',None)\n if version is not None:\n return version\n\n # Get version from version file.\n files = ['__version__.py',\n self.name.split('.')[-1]+'_version.py',\n 'version.py',\n '__svn_version__.py']\n version_vars = ['version',\n '__version__',\n self.name.split('.')[-1]+'_version']\n for f in files:\n fn = os.path.join(self.local_path,f)\n if os.path.isfile(fn):\n info = (open(fn),fn,('.py','U',1))\n name = os.path.splitext(os.path.basename(fn))[0]\n n = dot_join(self.name,name)\n try:\n version_module = imp.load_module('_'.join(n.split('.')),*info)\n except ImportError,msg:\n print msg\n version_module = None\n if version_module is None:\n continue\n\n for a in version_vars:\n version = getattr(version_module,a,None)\n if version is not None:\n break\n if version is not None:\n break\n\n if version is not None:\n self.version = version\n return version\n\n # Get version as SVN revision number\n revision = self._get_svn_revision(self.local_path)\n if revision is not None:\n version = str(revision)\n self.version = version\n\n return version\n\n def make_svn_version_py(self):\n \"\"\" Generate package __svn_version__.py file from SVN revision number,\n it will be removed after python exits but will be available\n when sdist, etc commands are executed.\n\n If __svn_version__.py existed before, nothing is done.\n \"\"\"\n target = os.path.join(self.local_path,'__svn_version__.py')\n if os.path.isfile(target):\n return\n\n def generate_svn_version_py():\n if not os.path.isfile(target):\n revision = self._get_svn_revision(self.local_path)\n assert revision is not None,'hmm, why I am not inside SVN tree???'\n version = str(revision)\n print 'Creating %s (version=%r)' % (target,version)\n f = open(target,'w')\n f.write('version = %r\\n' % (version))\n f.close()\n \n import atexit\n def rm_file(f=target):\n try: os.remove(f); print 'removed',f\n except OSError: pass\n try: os.remove(f+'c'); print 'removed',f+'c'\n except OSError: pass\n atexit.register(rm_file)\n\n return target\n\n d = os.path.join(*(self.name.split('.')))\n self.add_data_files((d, generate_svn_version_py()))\n return\n\n def make_config_py(self,name='__config__'):\n \"\"\" Generate package __config__.py file containing system_info\n information used during building the package.\n \"\"\"\n self.py_modules.append((self.name,name,generate_config_py))\n return\n\n def get_info(self,*names):\n \"\"\" Get resources information.\n \"\"\"\n from system_info import get_info, dict_append\n info_dict = {}\n for a in names:\n dict_append(info_dict,**get_info(a))\n return info_dict\n\ndef get_cmd(cmdname,_cache={}):\n if not _cache.has_key(cmdname):\n import distutils.core\n dist = distutils.core._setup_distribution\n if dist is None:\n from distutils.errors import DistutilsInternalError\n raise DistutilsInternalError,\\\n 'setup distribution instance not initialized'\n cmd = dist.get_command_obj(cmdname)\n _cache[cmdname] = cmd\n return _cache[cmdname]\n\ndef get_numpy_include_dirs():\n # numpy_include_dirs are set by numpy/core/setup.py, otherwise []\n include_dirs = Configuration.numpy_include_dirs[:]\n if not include_dirs:\n import numpy\n if numpy.show_config is None:\n # running from numpy_core source directory\n include_dirs.append(os.path.join(os.path.dirname(numpy.__file__),\n 'core','include'))\n else:\n # using installed numpy core headers\n import numpy.core as core\n include_dirs.append(os.path.join(os.path.dirname(core.__file__),'include'))\n # else running numpy/core/setup.py\n return include_dirs\n\n#########################\n\ndef default_config_dict(name = None, parent_name = None, local_path=None):\n \"\"\" Return a configuration dictionary for usage in\n configuration() function defined in file setup_.py.\n \"\"\"\n import warnings\n warnings.warn('Use Configuration(%s,%s,top_path=%s) instead of '\\\n 'deprecated default_config_dict(%s,%s,%s)' \\\n % (`name`,`parent_name`,`local_path`,\n `name`,`parent_name`,`local_path`,\n ))\n c = Configuration(name, parent_name, local_path)\n return c.todict()\n\n\ndef dict_append(d,**kws):\n for k,v in kws.items():\n if d.has_key(k):\n d[k].extend(v)\n else:\n d[k] = v\n\ndef appendpath(prefix,path):\n if not ('/' == os.path.sep):\n prefix = prefix.replace('/',os.path.sep)\n path = path.replace('/',os.path.sep)\n drive = ''\n if os.path.isabs(path):\n drive = os.path.splitdrive(prefix)[0]\n absprefix = os.path.splitdrive(os.path.abspath(prefix))[1]\n pathdrive,path = os.path.splitdrive(path)\n d = os.path.commonprefix([absprefix,path])\n if os.path.join(absprefix[:len(d)],absprefix[len(d):])!=absprefix \\\n or os.path.join(path[:len(d)],path[len(d):])!=path:\n # Handle invalid paths\n d = os.path.dirname(d)\n subpath = path[len(d):]\n if os.path.isabs(subpath):\n subpath = subpath[1:]\n else:\n subpath = path\n return os.path.normpath(os.path.join(drive + prefix, subpath))\n\ndef generate_config_py(target):\n \"\"\" Generate config.py file containing system_info information\n used during building the package.\n\n Usage:\\\n config['py_modules'].append((packagename, '__config__',generate_config_py))\n \"\"\"\n from numpy.distutils.system_info import system_info\n from distutils.dir_util import mkpath\n mkpath(os.path.dirname(target))\n f = open(target,'w')\n f.write('# This file is generated by %s\\n' % (os.path.abspath(sys.argv[0])))\n f.write('# It contains system_info results at the time of building this package.\\n')\n f.write('__all__ = [\"get_info\",\"show\"]\\n\\n')\n for k,i in system_info.saved_results.items():\n f.write('%s=%r\\n' % (k,i))\n f.write('\\ndef get_info(name): g=globals(); return g.get(name,g.get(name+\"_info\",{}))\\n')\n f.write('''\ndef show():\n for name,info_dict in globals().items():\n if name[0]==\"_\" or type(info_dict) is not type({}): continue\n print name+\":\"\n if not info_dict:\n print \" NOT AVAILABLE\"\n for k,v in info_dict.items():\n v = str(v)\n if k==\\'sources\\' and len(v)>200: v = v[:60]+\\' ...\\\\n... \\'+v[-60:]\n print \\' %s = %s\\'%(k,v)\n print\n return\n ''')\n\n f.close()\n return target\n\ndef generate_svn_version_py(extension, build_dir):\n \"\"\" Generate __svn_version__.py file containing SVN\n revision number of a module.\n \n To use, add the following codelet to setup\n configuration(..) function\n\n ext = Extension(dot_join(config['name'],'__svn_version__'),\n sources=[generate_svn_version_py])\n ext.local_path = local_path\n config['ext_modules'].append(ext)\n\n \"\"\"\n from distutils import dep_util\n local_path = extension.local_path\n target = os.path.join(build_dir, '__svn_version__.py')\n entries = os.path.join(local_path,'.svn','entries')\n if os.path.isfile(entries):\n if not dep_util.newer(entries, target):\n return target\n elif os.path.isfile(target):\n return target\n\n revision = get_svn_revision(local_path)\n f = open(target,'w')\n f.write('revision=%s\\n' % (revision))\n f.close()\n return target\n", + "source_code_before": "import os\nimport re\nimport sys\nimport imp\nimport copy\nimport types\nimport glob\n\n__all__ = ['Configuration', 'get_numpy_include_dirs', 'default_config_dict',\n 'dict_append', 'appendpath', 'generate_config_py',\n 'generate_svn_version_py', 'get_cmd', 'allpath',\n 'terminal_has_colors', 'red_text', 'green_text', 'yellow_text',\n 'blue_text', 'cyan_text', 'cyg2win32', 'all_strings',\n 'has_f_sources', 'has_cxx_sources', 'filter_sources',\n 'get_dependencies', 'is_local_src_dir', 'get_ext_source_files',\n 'get_script_files', 'get_lib_source_files', 'get_data_files',\n 'dot_join', 'get_frame']\n\ndef allpath(name):\n \"Convert a /-separated pathname to one using the OS's path separator.\"\n splitted = name.split('/')\n return os.path.join(*splitted)\n\ndef get_path(mod_name,parent_path=None):\n \"\"\" Return path of the module.\n\n Returned path is relative to parent_path when given,\n otherwise it is absolute path.\n \"\"\"\n if mod_name == '__main__':\n d = os.path.abspath('.')\n elif mod_name == '__builtin__':\n #builtin if/then added by Pearu for use in core.run_setup. \n d = os.path.dirname(os.path.abspath(sys.argv[0]))\n else:\n __import__(mod_name)\n mod = sys.modules[mod_name]\n file = mod.__file__\n d = os.path.dirname(os.path.abspath(file))\n if parent_path is not None:\n pd = os.path.abspath(parent_path)\n if pd==d[:len(pd)]:\n d = d[len(pd)+1:]\n return d or '.'\n\n# Hooks for colored terminal output.\n# See also http://www.livinglogic.de/Python/ansistyle\ndef terminal_has_colors():\n if sys.platform=='cygwin' and not os.environ.has_key('USE_COLOR'):\n # Avoid importing curses that causes illegal operation\n # with a message:\n # PYTHON2 caused an invalid page fault in\n # module CYGNURSES7.DLL as 015f:18bbfc28\n # Details: Python 2.3.3 [GCC 3.3.1 (cygming special)]\n # ssh to Win32 machine from debian\n # curses.version is 2.2\n # CYGWIN_98-4.10, release 1.5.7(0.109/3/2))\n return 0\n if hasattr(sys.stdout,'isatty') and sys.stdout.isatty(): \n try:\n import curses\n curses.setupterm()\n if (curses.tigetnum(\"colors\") >= 0\n and curses.tigetnum(\"pairs\") >= 0\n and ((curses.tigetstr(\"setf\") is not None \n and curses.tigetstr(\"setb\") is not None) \n or (curses.tigetstr(\"setaf\") is not None\n and curses.tigetstr(\"setab\") is not None)\n or curses.tigetstr(\"scp\") is not None)):\n return 1\n except Exception,msg:\n pass\n return 0\n\nif terminal_has_colors():\n def red_text(s): return '\\x1b[31m%s\\x1b[0m'%s\n def green_text(s): return '\\x1b[32m%s\\x1b[0m'%s\n def yellow_text(s): return '\\x1b[33m%s\\x1b[0m'%s\n def blue_text(s): return '\\x1b[34m%s\\x1b[0m'%s\n def cyan_text(s): return '\\x1b[35m%s\\x1b[0m'%s\nelse:\n def red_text(s): return s\n def green_text(s): return s\n def yellow_text(s): return s\n def cyan_text(s): return s\n def blue_text(s): return s\n\n#########################\n\ndef cyg2win32(path):\n if sys.platform=='cygwin' and path.startswith('/cygdrive'):\n path = path[10] + ':' + os.path.normcase(path[11:])\n return path\n\n#########################\n\n#XXX need support for .C that is also C++\ncxx_ext_match = re.compile(r'.*[.](cpp|cxx|cc)\\Z',re.I).match\nfortran_ext_match = re.compile(r'.*[.](f90|f95|f77|for|ftn|f)\\Z',re.I).match\nf90_ext_match = re.compile(r'.*[.](f90|f95)\\Z',re.I).match\nf90_module_name_match = re.compile(r'\\s*module\\s*(?P[\\w_]+)',re.I).match\ndef _get_f90_modules(source):\n \"\"\" Return a list of Fortran f90 module names that\n given source file defines.\n \"\"\"\n if not f90_ext_match(source):\n return []\n modules = []\n f = open(source,'r')\n f_readlines = getattr(f,'xreadlines',f.readlines)\n for line in f_readlines():\n m = f90_module_name_match(line)\n if m:\n name = m.group('name')\n modules.append(name)\n # break # XXX can we assume that there is one module per file?\n f.close()\n return modules\n\ndef all_strings(lst):\n \"\"\" Return True if all items in lst are string objects. \"\"\"\n for item in lst:\n if type(item) is not types.StringType:\n return False\n return True\n\ndef has_f_sources(sources):\n \"\"\" Return True if sources contains Fortran files \"\"\"\n for source in sources:\n if fortran_ext_match(source):\n return True\n return False\n\ndef has_cxx_sources(sources):\n \"\"\" Return True if sources contains C++ files \"\"\"\n for source in sources:\n if cxx_ext_match(source):\n return True\n return False\n\ndef filter_sources(sources):\n \"\"\" Return four lists of filenames containing\n C, C++, Fortran, and Fortran 90 module sources,\n respectively.\n \"\"\"\n c_sources = []\n cxx_sources = []\n f_sources = []\n fmodule_sources = []\n for source in sources:\n if fortran_ext_match(source):\n modules = _get_f90_modules(source)\n if modules:\n fmodule_sources.append(source)\n else:\n f_sources.append(source)\n elif cxx_ext_match(source):\n cxx_sources.append(source)\n else:\n c_sources.append(source) \n return c_sources, cxx_sources, f_sources, fmodule_sources\n\n\ndef _get_headers(directory_list):\n # get *.h files from list of directories\n headers = []\n for dir in directory_list:\n head = glob.glob(os.path.join(dir,\"*.h\")) #XXX: *.hpp files??\n headers.extend(head)\n return headers\n\ndef _get_directories(list_of_sources):\n # get unique directories from list of sources.\n direcs = []\n for file in list_of_sources:\n dir = os.path.split(file)\n if dir[0] != '' and not dir[0] in direcs:\n direcs.append(dir[0])\n return direcs\n\ndef get_dependencies(sources):\n #XXX scan sources for include statements\n return _get_headers(_get_directories(sources))\n\ndef is_local_src_dir(directory):\n \"\"\" Return true if directory is local directory.\n \"\"\"\n if type(directory) is not type(''):\n return False\n abs_dir = os.path.abspath(directory)\n c = os.path.commonprefix([os.getcwd(),abs_dir])\n new_dir = abs_dir[len(c):].split(os.sep)\n if new_dir and not new_dir[0]:\n new_dir = new_dir[1:]\n if new_dir and new_dir[0]=='build':\n return False\n new_dir = os.sep.join(new_dir)\n return os.path.isdir(new_dir)\n\ndef _gsf_visit_func(filenames,dirname,names):\n if os.path.basename(dirname) in ['CVS','.svn','build']:\n names[:] = []\n return\n for name in names:\n if name[-1] in \"~#\":\n continue\n fullname = os.path.join(dirname,name)\n ext = os.path.splitext(fullname)[1]\n if ext and ext in ['.pyc','.o']:\n continue\n if os.path.isfile(fullname):\n filenames.append(fullname)\n\ndef get_ext_source_files(ext):\n # Get sources and any include files in the same directory.\n filenames = []\n sources = filter(lambda s:type(s) is types.StringType,ext.sources)\n filenames.extend(sources)\n filenames.extend(get_dependencies(sources))\n for d in ext.depends:\n if is_local_src_dir(d):\n os.path.walk(d,_gsf_visit_func,filenames)\n elif os.path.isfile(d):\n filenames.append(d)\n return filenames\n\ndef get_script_files(scripts):\n scripts = filter(lambda s:type(s) is types.StringType,scripts)\n return scripts\n\ndef get_lib_source_files(lib):\n filenames = []\n sources = lib[1].get('sources',[])\n sources = filter(lambda s:type(s) is types.StringType,sources)\n filenames.extend(sources)\n filenames.extend(get_dependencies(sources))\n depends = lib[1].get('depends',[])\n for d in depends:\n if is_local_src_dir(d):\n os.path.walk(d,_gsf_visit_func,filenames)\n elif os.path.isfile(d):\n filenames.append(d)\n return filenames\n\ndef get_data_files(data):\n if type(data) is types.StringType:\n return [data]\n sources = data[1]\n filenames = []\n for s in sources:\n if callable(s):\n continue\n if is_local_src_dir(s):\n os.path.walk(s,_gsf_visit_func,filenames)\n elif type(s) is type(''):\n if os.path.isfile(s):\n filenames.append(s)\n else:\n print 'Not existing data file:',s\n else:\n raise TypeError,`s`\n return filenames\n\ndef dot_join(*args):\n return '.'.join(filter(None,args))\n\ndef get_frame(level=0):\n try:\n return sys._getframe(level+1)\n except AttributeError:\n frame = sys.exc_info()[2].tb_frame\n for i in range(level+1):\n frame = frame.f_back\n return frame\n\n######################\n\nclass Configuration:\n\n _list_keys = ['packages','ext_modules','data_files','include_dirs',\n 'libraries','headers','scripts','py_modules']\n _dict_keys = ['package_dir']\n\n numpy_include_dirs = []\n\n def __init__(self,\n package_name=None,\n parent_name=None,\n top_path=None,\n package_path=None,\n **attrs):\n \"\"\" Construct configuration instance of a package.\n \"\"\"\n self.name = dot_join(parent_name, package_name)\n\n caller_frame = get_frame(1)\n caller_name = eval('__name__',caller_frame.f_globals,caller_frame.f_locals)\n \n self.local_path = get_path(caller_name, top_path)\n if top_path is None:\n top_path = self.local_path\n if package_path is None:\n package_path = self.local_path\n elif os.path.isdir(os.path.join(self.local_path,package_path)):\n package_path = os.path.join(self.local_path,package_path)\n assert os.path.isdir(package_path),`package_path`\n self.top_path = top_path\n\n self.list_keys = copy.copy(self._list_keys)\n self.dict_keys = copy.copy(self._dict_keys)\n\n for n in self.list_keys:\n setattr(self,n,copy.copy(attrs.get(n,[])))\n\n for n in self.dict_keys:\n setattr(self,n,copy.copy(attrs.get(n,{})))\n\n known_keys = self.list_keys + self.dict_keys\n self.extra_keys = []\n for n in attrs.keys():\n if n in known_keys:\n continue\n a = attrs[n]\n setattr(self,n,a)\n if type(a) is types.ListType:\n self.list_keys.append(n)\n elif type(a) is types.DictType:\n self.dict_keys.append(n)\n else:\n self.extra_keys.append(n)\n\n if os.path.exists(os.path.join(package_path,'__init__.py')):\n self.packages.append(self.name)\n self.package_dir[self.name] = package_path \n return\n\n def todict(self):\n \"\"\" Return configuration distionary suitable for passing\n to distutils.core.setup() function.\n \"\"\"\n d = {}\n for n in self.list_keys + self.dict_keys + self.extra_keys:\n a = getattr(self,n)\n if a:\n d[n] = a\n if self.name:\n d['name'] = self.name\n return d\n\n def __dict__(self):\n return self.todict()\n\n def get_distribution(self):\n import distutils.core\n dist = distutils.core._setup_distribution \n return dist\n\n def get_subpackage(self,subpackage_name,subpackage_path=None):\n \"\"\" Return subpackage configuration.\n \"\"\"\n if subpackage_name is None:\n assert subpackage_path is not None\n subpackage_name = os.path.basename(subpackage_path)\n l = subpackage_name.split('.')\n if subpackage_path is None:\n subpackage_path = os.path.join(*([self.local_path]+l))\n if '*' in subpackage_name:\n dirs = filter(os.path.isdir,glob.glob(subpackage_path))\n config_list = []\n for d in dirs:\n if not os.path.isfile(os.path.join(d,'__init__.py')):\n continue\n n = '.'.join(d.split(os.sep)[-len(l):])\n c = self.get_subpackage(n)\n if c:\n config_list.append(c)\n return config_list\n else:\n subpackage_path = os.path.join(*([subpackage_path]+l[:-1]))\n subpackage_path = self._fix_paths([subpackage_path])[0]\n\n setup_py = os.path.join(subpackage_path,'setup.py')\n if not os.path.isfile(setup_py):\n setup_py = os.path.join(subpackage_path,'setup_%s.py' % (subpackage_name))\n\n if not os.path.isfile(setup_py):\n print 'Assuming default configuration '\\\n '(%s/{setup_%s,setup}.py was not found)' \\\n % (os.path.dirname(setup_py),subpackage_name)\n config = Configuration(subpackage_name,self.name,\n self.top_path,subpackage_path)\n else:\n # In case setup_py imports local modules:\n sys.path.insert(0,os.path.dirname(setup_py))\n try:\n info = (open(setup_py),setup_py,('.py','U',1))\n setup_name = os.path.splitext(os.path.basename(setup_py))[0]\n n = dot_join(self.name,setup_name)\n setup_module = imp.load_module('_'.join(n.split('.')),*info)\n\n if not hasattr(setup_module,'configuration'):\n print 'Assuming default configuration '\\\n '(%s does not define configuration())' % (setup_module)\n config = Configuration(subpackage_name,self.name,\n self.top_path,subpackage_path)\n else:\n args = (self.name,)\n if setup_module.configuration.func_code.co_argcount>1:\n args = args + (self.top_path,)\n config = setup_module.configuration(*args)\n\n finally:\n del sys.path[0]\n\n return config\n\n def add_subpackage(self,subpackage_name,subpackage_path=None):\n \"\"\" Add subpackage to configuration.\n \"\"\"\n config = self.get_subpackage(subpackage_name,subpackage_path)\n if not isinstance(config, list):\n config_list = [config]\n else:\n config_list = config\n for config in config_list:\n if not config:\n print 'No configuration returned, assuming unavailable.'\n else:\n if isinstance(config,Configuration):\n print 'Appending %s configuration to %s' % (config.name,self.name)\n self.dict_append(**config.todict())\n else:\n print 'Appending %s configuration to %s' % (config.get('name'),self.name)\n self.dict_append(**config)\n\n dist = self.get_distribution()\n if dist is not None:\n print 'distutils distribution has been initialized, it may be too late to add a subpackage', subpackage_name\n return\n\n def add_data_dir(self,data_path):\n \"\"\" Recursively add files under data_path to data_files list.\n Argument can be either\n - 2-sequence (,)\n - path to data directory where python datadir suffix defaults\n to package dir.\n If path is not absolute then it's datadir suffix is\n package dir + subdirname of the path.\n \"\"\"\n if type(data_path) is type(()):\n assert len(data_path)==2,`data_path`\n d,data_path = data_path\n else:\n d = None\n assert type(data_path) is type(''),`data_path`\n for path in self.paths(data_path):\n if not os.path.exists(path):\n print 'Not existing data path',path\n continue\n filenames = []\n os.path.walk(path, _gsf_visit_func,filenames)\n if not os.path.isabs(path):\n if d is None:\n ds = os.path.join(*(self.name.split('.')+[data_path]))\n else:\n ds = os.path.join(d,data_path)\n self.add_data_files((ds,filenames))\n else:\n if d is None:\n self.add_data_files(*filenames)\n else:\n self.add_data_files((d,filenames))\n return\n\n def add_data_files(self,*files):\n \"\"\" Add data files to configuration data_files.\n Argument(s) can be either\n - 2-sequence (,)\n - paths to data files where python datadir prefix defaults\n to package dir.\n If path is not absolute then it's datadir prefix is\n package dir + dirname of the path.\n \"\"\"\n data_dict = {}\n new_files = []\n for p in files:\n if type(p) is not type(()):\n d = os.path.join(*(self.name.split('.')))\n if type(p) is type('') and not os.path.isabs(p):\n d = appendpath(d,os.path.dirname(p))\n p = (d,p)\n new_files.append(p)\n files = []\n for prefix,filepattern in new_files:\n if type(filepattern) is type(''):\n file_list = self.paths(filepattern)\n elif callable(filepattern):\n file_list = [filepattern]\n else:\n file_list = self.paths(*filepattern)\n\n nof_path_components = [len(f.split(os.sep)) \\\n for f in file_list if type(f) is type('')]\n if nof_path_components:\n min_path_components = min(nof_path_components)-1\n else:\n min_path_components = 0\n\n for f in file_list:\n if type(f) is type(''):\n extra_path_components = f.split(os.sep)[min_path_components:-1]\n p = os.path.join(*([prefix]+extra_path_components))\n else:\n p = prefix\n if not data_dict.has_key(p):\n data_dict[p] = [f]\n else:\n data_dict[p].append(f)\n\n dist = self.get_distribution()\n if dist is not None:\n dist.data_files.extend(data_dict.items())\n else:\n self.data_files.extend(data_dict.items())\n return \n\n ### XXX Implement add_py_modules\n \n def add_include_dirs(self,*paths):\n \"\"\" Add paths to configuration include directories.\n \"\"\"\n include_dirs = self._fix_paths(paths)\n dist = self.get_distribution()\n if dist is not None:\n dist.include_dirs.extend(include_dirs)\n else:\n self.include_dirs.extend(include_dirs)\n return\n\n def add_headers(self,*files):\n \"\"\" Add installable headers to configuration.\n Argument(s) can be either\n - 2-sequence (,)\n - path(s) to header file(s) where python includedir suffix will default\n to package name.\n \"\"\"\n headers = []\n for path in files:\n if type(path) is type(''):\n [headers.append((self.name,p)) for p in self.paths(path)]\n else:\n assert type(path) in [type(()),type([])] and len(path)==2,`path`\n [headers.append((path[0],p)) for p in self.paths(path[1])]\n dist = self.get_distribution()\n if dist is not None:\n dist.headers.extend(headers)\n else:\n self.headers.extend(headers)\n return\n\n def _fix_paths(self,paths):\n new_paths = []\n for n in paths:\n if isinstance(n,str):\n if '*' in n or '?' in n:\n p = glob.glob(n)\n p2 = glob.glob(os.path.join(self.local_path,n))\n if p2:\n new_paths.extend(p2)\n elif p:\n new_paths.extend(p)\n else:\n new_paths.append(n)\n else:\n n2 = os.path.join(self.local_path,n)\n if os.path.exists(n2):\n new_paths.append(n2)\n else:\n new_paths.append(n)\n else:\n new_paths.append(n)\n return new_paths\n\n def paths(self,*paths):\n \"\"\" Apply glob to paths and prepend local_path if needed.\n \"\"\"\n return self._fix_paths(paths)\n\n def add_extension(self,name,sources,**kw):\n \"\"\" Add extension to configuration.\n\n Keywords:\n include_dirs, define_macros, undef_macros,\n library_dirs, libraries, runtime_library_dirs,\n extra_objects, extra_compile_args, extra_link_args,\n export_symbols, swig_opts, depends, language,\n f2py_options, module_dirs\n extra_info - dict or list of dict of keywords to be\n appended to keywords.\n \"\"\"\n ext_args = copy.copy(kw)\n ext_args['name'] = dot_join(self.name,name)\n ext_args['sources'] = sources\n\n if ext_args.has_key('extra_info'):\n extra_info = ext_args['extra_info']\n del ext_args['extra_info']\n if type(extra_info) is type({}):\n extra_info = [extra_info]\n for info in extra_info:\n assert type(info) is type({}),`info`\n dict_append(ext_args,**info)\n\n for k in ext_args.keys():\n v = ext_args[k]\n if k in ['sources','depends','include_dirs','library_dirs',\n 'module_dirs','extra_objects']:\n new_v = self._fix_paths(v)\n ext_args[k] = new_v\n\n # Resolve out-of-tree dependencies\n libraries = ext_args.get('libraries',[])\n libnames = []\n ext_args['libraries'] = []\n for libname in libraries:\n if '@' in libname:\n lname,lpath = libname.split('@',1)\n lpath = os.path.abspath(os.path.join(self.local_path,lpath))\n if os.path.isdir(lpath):\n c = self.get_subpackage(None,lpath)\n if isinstance(c,Configuration):\n c = c.todict()\n for l in [l[0] for l in c.get('libraries',[])]:\n llname = l.split('__OF__',1)[0]\n if llname == lname:\n c.pop('name',None)\n dict_append(ext_args,**c)\n break\n continue\n libnames.append(libname)\n\n ext_args['libraries'] = libnames + ext_args['libraries']\n\n from numpy.distutils.core import Extension\n ext = Extension(**ext_args)\n self.ext_modules.append(ext)\n\n dist = self.get_distribution()\n if dist is not None:\n print 'distutils distribution has been initialized, it may be too late to add an extension', name\n return ext\n\n def add_library(self,name,sources,**build_info):\n \"\"\" Add library to configuration.\n \n Valid keywords for build_info:\n depends\n macros\n include_dirs\n extra_compiler_args\n f2py_options\n \"\"\"\n build_info = copy.copy(build_info)\n name = name #+ '__OF__' + self.name\n build_info['sources'] = sources\n\n for k in build_info.keys():\n v = build_info[k]\n if k in ['sources','depends']:\n new_v = self._fix_paths(v)\n build_info[k] = new_v\n self.libraries.append((name,build_info))\n\n dist = self.get_distribution()\n if dist is not None:\n print 'distutils distribution has been initialized, it may be too late to add a library', name\n return\n\n def add_scripts(self,*files):\n \"\"\" Add scripts to configuration.\n \"\"\"\n scripts = self._fix_paths(files)\n dist = self.get_distribution()\n if dist is not None:\n dist.scripts.extend(scripts)\n else:\n self.scripts.extend(scripts)\n return\n\n def dict_append(self,**dict):\n for key in self.list_keys:\n a = getattr(self,key)\n a.extend(dict.get(key,[]))\n for key in self.dict_keys:\n a = getattr(self,key)\n a.update(dict.get(key,{}))\n known_keys = self.list_keys + self.dict_keys + self.extra_keys\n for key in dict.keys():\n if key not in known_keys and not hasattr(self,key):\n print 'Inheriting attribute %r from %r' \\\n % (key,dict.get('name','?'))\n setattr(self,key,dict[key])\n self.extra_keys.append(key)\n return\n\n def __str__(self):\n known_keys = self.list_keys + self.dict_keys + self.extra_keys\n s = '<'+5*'-' + '\\n'\n s += 'Configuration of '+self.name+':\\n'\n for k in known_keys:\n a = getattr(self,k,None)\n if a:\n s += '%s = %r\\n' % (k,a)\n s += 5*'-' + '>'\n return s\n\n def get_config_cmd(self):\n cmd = get_cmd('config')\n cmd.ensure_finalized()\n cmd.dump_source = 0\n cmd.noisy = 0\n old_path = os.environ.get('PATH')\n if old_path:\n path = os.pathsep.join(['.',old_path])\n os.environ['PATH'] = path\n return cmd\n\n def get_build_temp_dir(self):\n cmd = get_cmd('build')\n cmd.ensure_finalized()\n return cmd.build_temp\n\n def have_f77c(self):\n \"\"\" Check for availability of Fortran 77 compiler.\n Use it inside source generating function to ensure that\n setup distribution instance has been initialized.\n \"\"\"\n simple_fortran_subroutine = '''\n subroutine simple\n end\n '''\n config_cmd = self.get_config_cmd()\n flag = config_cmd.try_compile(simple_fortran_subroutine,lang='f77')\n return flag\n\n def have_f90c(self):\n \"\"\" Check for availability of Fortran 90 compiler.\n Use it inside source generating function to ensure that\n setup distribution instance has been initialized.\n \"\"\"\n simple_fortran_subroutine = '''\n subroutine simple\n end\n '''\n config_cmd = self.get_config_cmd()\n flag = config_cmd.try_compile(simple_fortran_subroutine,lang='f90')\n return flag\n\n def append_to(self, extlib):\n \"\"\" Append libraries, include_dirs to extension or library item.\n \"\"\"\n if type(extlib) is type(()):\n lib_name, build_info = extlib\n dict_append(build_info,\n libraries=self.libraries,\n include_dirs=self.include_dirs)\n else:\n from numpy.distutils.core import Extension\n assert isinstance(extlib,Extension),`extlib`\n extlib.libraries.extend(self.libraries)\n extlib.include_dirs.extend(self.include_dirs)\n return\n\n def _get_svn_revision(self,path):\n \"\"\" Return path's SVN revision number.\n \"\"\"\n entries = os.path.join(path,'.svn','entries')\n revision = None\n if os.path.isfile(entries):\n f = open(entries)\n m = re.search(r'revision=\"(?P\\d+)\"',f.read())\n f.close()\n if m:\n revision = int(m.group('revision'))\n return revision\n\n def get_version(self):\n \"\"\" Try to get version string of a package.\n \"\"\"\n version = getattr(self,'version',None)\n if version is not None:\n return version\n\n # Get version from version file.\n files = ['__version__.py',\n self.name.split('.')[-1]+'_version.py',\n 'version.py',\n '__svn_version__.py']\n version_vars = ['version',\n '__version__',\n self.name.split('.')[-1]+'_version']\n for f in files:\n fn = os.path.join(self.local_path,f)\n if os.path.isfile(fn):\n info = (open(fn),fn,('.py','U',1))\n name = os.path.splitext(os.path.basename(fn))[0]\n n = dot_join(self.name,name)\n try:\n version_module = imp.load_module('_'.join(n.split('.')),*info)\n except ImportError,msg:\n print msg\n version_module = None\n if version_module is None:\n continue\n\n for a in version_vars:\n version = getattr(version_module,a,None)\n if version is not None:\n break\n if version is not None:\n break\n\n if version is not None:\n self.version = version\n return version\n\n # Get version as SVN revision number\n revision = self._get_svn_revision(self.local_path)\n if revision is not None:\n version = str(revision)\n self.version = version\n\n return version\n\n def make_svn_version_py(self):\n \"\"\" Generate package __svn_version__.py file from SVN revision number,\n it will be removed after python exits but will be available\n when sdist, etc commands are executed.\n\n If __svn_version__.py existed before, nothing is done.\n \"\"\"\n target = os.path.join(self.local_path,'__svn_version__.py')\n if os.path.isfile(target):\n return\n\n def generate_svn_version_py():\n if not os.path.isfile(target):\n revision = self._get_svn_revision(self.local_path)\n assert revision is not None,'hmm, why I am not inside SVN tree???'\n version = str(revision)\n print 'Creating %s (version=%r)' % (target,version)\n f = open(target,'w')\n f.write('version = %r\\n' % (version))\n f.close()\n \n import atexit\n def rm_file(f=target):\n try: os.remove(f); print 'removed',f\n except OSError: pass\n try: os.remove(f+'c'); print 'removed',f+'c'\n except OSError: pass\n atexit.register(rm_file)\n\n return target\n\n d = os.path.join(*(self.name.split('.')))\n self.add_data_files((d, generate_svn_version_py()))\n return\n\n def make_config_py(self,name='__config__'):\n \"\"\" Generate package __config__.py file containing system_info\n information used during building the package.\n \"\"\"\n self.py_modules.append((self.name,name,generate_config_py))\n return\n\n def get_info(self,*names):\n \"\"\" Get resources information.\n \"\"\"\n from system_info import get_info, dict_append\n info_dict = {}\n for a in names:\n dict_append(info_dict,**get_info(a))\n return info_dict\n\ndef get_cmd(cmdname,_cache={}):\n if not _cache.has_key(cmdname):\n import distutils.core\n dist = distutils.core._setup_distribution\n if dist is None:\n from distutils.errors import DistutilsInternalError\n raise DistutilsInternalError,\\\n 'setup distribution instance not initialized'\n cmd = dist.get_command_obj(cmdname)\n _cache[cmdname] = cmd\n return _cache[cmdname]\n\ndef get_numpy_include_dirs():\n # numpy_include_dirs are set by numpy/core/setup.py, otherwise []\n include_dirs = Configuration.numpy_include_dirs[:]\n if not include_dirs:\n import numpy\n if numpy.show_config is None:\n # running from numpy_core source directory\n include_dirs.append(os.path.join(os.path.dirname(numpy.__file__),\n 'core','include'))\n else:\n # using installed numpy core headers\n import numpy.core as core\n include_dirs.append(os.path.join(os.path.dirname(core.__file__),'include'))\n # else running numpy/core/setup.py\n return include_dirs\n\n#########################\n\ndef default_config_dict(name = None, parent_name = None, local_path=None):\n \"\"\" Return a configuration dictionary for usage in\n configuration() function defined in file setup_.py.\n \"\"\"\n import warnings\n warnings.warn('Use Configuration(%s,%s,top_path=%s) instead of '\\\n 'deprecated default_config_dict(%s,%s,%s)' \\\n % (`name`,`parent_name`,`local_path`,\n `name`,`parent_name`,`local_path`,\n ))\n c = Configuration(name, parent_name, local_path)\n return c.todict()\n\n\ndef dict_append(d,**kws):\n for k,v in kws.items():\n if d.has_key(k):\n d[k].extend(v)\n else:\n d[k] = v\n\ndef appendpath(prefix,path):\n if not ('/' == os.path.sep):\n prefix = prefix.replace('/',os.path.sep)\n path = path.replace('/',os.path.sep)\n drive = ''\n if os.path.isabs(path):\n drive = os.path.splitdrive(prefix)[0]\n absprefix = os.path.splitdrive(os.path.abspath(prefix))[1]\n pathdrive,path = os.path.splitdrive(path)\n d = os.path.commonprefix([absprefix,path])\n if os.path.join(absprefix[:len(d)],absprefix[len(d):])!=absprefix \\\n or os.path.join(path[:len(d)],path[len(d):])!=path:\n # Handle invalid paths\n d = os.path.dirname(d)\n subpath = path[len(d):]\n if os.path.isabs(subpath):\n subpath = subpath[1:]\n else:\n subpath = path\n return os.path.normpath(os.path.join(drive + prefix, subpath))\n\ndef generate_config_py(target):\n \"\"\" Generate config.py file containing system_info information\n used during building the package.\n\n Usage:\\\n config['py_modules'].append((packagename, '__config__',generate_config_py))\n \"\"\"\n from numpy.distutils.system_info import system_info\n from distutils.dir_util import mkpath\n mkpath(os.path.dirname(target))\n f = open(target,'w')\n f.write('# This file is generated by %s\\n' % (os.path.abspath(sys.argv[0])))\n f.write('# It contains system_info results at the time of building this package.\\n')\n f.write('__all__ = [\"get_info\",\"show\"]\\n\\n')\n for k,i in system_info.saved_results.items():\n f.write('%s=%r\\n' % (k,i))\n f.write('\\ndef get_info(name): g=globals(); return g.get(name,g.get(name+\"_info\",{}))\\n')\n f.write('''\ndef show():\n for name,info_dict in globals().items():\n if name[0]==\"_\" or type(info_dict) is not type({}): continue\n print name+\":\"\n if not info_dict:\n print \" NOT AVAILABLE\"\n for k,v in info_dict.items():\n v = str(v)\n if k==\\'sources\\' and len(v)>200: v = v[:60]+\\' ...\\\\n... \\'+v[-60:]\n print \\' %s = %s\\'%(k,v)\n print\n return\n ''')\n\n f.close()\n return target\n\ndef generate_svn_version_py(extension, build_dir):\n \"\"\" Generate __svn_version__.py file containing SVN\n revision number of a module.\n \n To use, add the following codelet to setup\n configuration(..) function\n\n ext = Extension(dot_join(config['name'],'__svn_version__'),\n sources=[generate_svn_version_py])\n ext.local_path = local_path\n config['ext_modules'].append(ext)\n\n \"\"\"\n from distutils import dep_util\n local_path = extension.local_path\n target = os.path.join(build_dir, '__svn_version__.py')\n entries = os.path.join(local_path,'.svn','entries')\n if os.path.isfile(entries):\n if not dep_util.newer(entries, target):\n return target\n elif os.path.isfile(target):\n return target\n\n revision = get_svn_revision(local_path)\n f = open(target,'w')\n f.write('revision=%s\\n' % (revision))\n f.close()\n return target\n", + "methods": [ + { + "name": "allpath", + "long_name": "allpath( name )", + "filename": "misc_util.py", + "nloc": 4, + "complexity": 1, + "token_count": 24, + "parameters": [ + "name" + ], + "start_line": 19, + "end_line": 22, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 4, + "top_nesting_level": 0 + }, + { + "name": "get_path", + "long_name": "get_path( mod_name , parent_path = None )", + "filename": "misc_util.py", + "nloc": 15, + "complexity": 6, + "token_count": 132, + "parameters": [ + "mod_name", + "parent_path" + ], + "start_line": 24, + "end_line": 44, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 21, + "top_nesting_level": 0 + }, + { + "name": "terminal_has_colors", + "long_name": "terminal_has_colors( )", + "filename": "misc_util.py", + "nloc": 18, + "complexity": 13, + "token_count": 137, + "parameters": [], + "start_line": 48, + "end_line": 73, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 26, + "top_nesting_level": 0 + }, + { + "name": "cyg2win32", + "long_name": "cyg2win32( path )", + "filename": "misc_util.py", + "nloc": 4, + "complexity": 3, + "token_count": 42, + "parameters": [ + "path" + ], + "start_line": 90, + "end_line": 93, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 4, + "top_nesting_level": 0 + }, + { + "name": "_get_f90_modules", + "long_name": "_get_f90_modules( source )", + "filename": "misc_util.py", + "nloc": 13, + "complexity": 4, + "token_count": 77, + "parameters": [ + "source" + ], + "start_line": 102, + "end_line": 118, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 17, + "top_nesting_level": 0 + }, + { + "name": "all_strings", + "long_name": "all_strings( lst )", + "filename": "misc_util.py", + "nloc": 5, + "complexity": 3, + "token_count": 26, + "parameters": [ + "lst" + ], + "start_line": 120, + "end_line": 125, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 6, + "top_nesting_level": 0 + }, + { + "name": "has_f_sources", + "long_name": "has_f_sources( sources )", + "filename": "misc_util.py", + "nloc": 5, + "complexity": 3, + "token_count": 21, + "parameters": [ + "sources" + ], + "start_line": 127, + "end_line": 132, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 6, + "top_nesting_level": 0 + }, + { + "name": "has_cxx_sources", + "long_name": "has_cxx_sources( sources )", + "filename": "misc_util.py", + "nloc": 5, + "complexity": 3, + "token_count": 21, + "parameters": [ + "sources" + ], + "start_line": 134, + "end_line": 139, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 6, + "top_nesting_level": 0 + }, + { + "name": "filter_sources", + "long_name": "filter_sources( sources )", + "filename": "misc_util.py", + "nloc": 17, + "complexity": 5, + "token_count": 84, + "parameters": [ + "sources" + ], + "start_line": 141, + "end_line": 161, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 21, + "top_nesting_level": 0 + }, + { + "name": "_get_headers", + "long_name": "_get_headers( directory_list )", + "filename": "misc_util.py", + "nloc": 6, + "complexity": 2, + "token_count": 39, + "parameters": [ + "directory_list" + ], + "start_line": 164, + "end_line": 170, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 7, + "top_nesting_level": 0 + }, + { + "name": "_get_directories", + "long_name": "_get_directories( list_of_sources )", + "filename": "misc_util.py", + "nloc": 7, + "complexity": 4, + "token_count": 51, + "parameters": [ + "list_of_sources" + ], + "start_line": 172, + "end_line": 179, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 8, + "top_nesting_level": 0 + }, + { + "name": "get_dependencies", + "long_name": "get_dependencies( sources )", + "filename": "misc_util.py", + "nloc": 2, + "complexity": 1, + "token_count": 13, + "parameters": [ + "sources" + ], + "start_line": 181, + "end_line": 183, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 3, + "top_nesting_level": 0 + }, + { + "name": "is_local_src_dir", + "long_name": "is_local_src_dir( directory )", + "filename": "misc_util.py", + "nloc": 12, + "complexity": 6, + "token_count": 112, + "parameters": [ + "directory" + ], + "start_line": 185, + "end_line": 198, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 14, + "top_nesting_level": 0 + }, + { + "name": "_gsf_visit_func", + "long_name": "_gsf_visit_func( filenames , dirname , names )", + "filename": "misc_util.py", + "nloc": 13, + "complexity": 7, + "token_count": 103, + "parameters": [ + "filenames", + "dirname", + "names" + ], + "start_line": 200, + "end_line": 212, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 13, + "top_nesting_level": 0 + }, + { + "name": "get_ext_source_files", + "long_name": "get_ext_source_files( ext )", + "filename": "misc_util.py", + "nloc": 11, + "complexity": 4, + "token_count": 87, + "parameters": [ + "ext" + ], + "start_line": 214, + "end_line": 225, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 12, + "top_nesting_level": 0 + }, + { + "name": "get_script_files", + "long_name": "get_script_files( scripts )", + "filename": "misc_util.py", + "nloc": 3, + "complexity": 1, + "token_count": 25, + "parameters": [ + "scripts" + ], + "start_line": 227, + "end_line": 229, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 3, + "top_nesting_level": 0 + }, + { + "name": "get_lib_source_files", + "long_name": "get_lib_source_files( lib )", + "filename": "misc_util.py", + "nloc": 13, + "complexity": 4, + "token_count": 111, + "parameters": [ + "lib" + ], + "start_line": 231, + "end_line": 243, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 13, + "top_nesting_level": 0 + }, + { + "name": "get_data_files", + "long_name": "get_data_files( data )", + "filename": "misc_util.py", + "nloc": 18, + "complexity": 7, + "token_count": 102, + "parameters": [ + "data" + ], + "start_line": 245, + "end_line": 262, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 18, + "top_nesting_level": 0 + }, + { + "name": "dot_join", + "long_name": "dot_join( * args )", + "filename": "misc_util.py", + "nloc": 2, + "complexity": 1, + "token_count": 18, + "parameters": [ + "args" + ], + "start_line": 264, + "end_line": 265, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 2, + "top_nesting_level": 0 + }, + { + "name": "get_frame", + "long_name": "get_frame( level = 0 )", + "filename": "misc_util.py", + "nloc": 8, + "complexity": 3, + "token_count": 50, + "parameters": [ + "level" + ], + "start_line": 267, + "end_line": 274, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 8, + "top_nesting_level": 0 + }, + { + "name": "__init__", + "long_name": "__init__( self , package_name = None , parent_name = None , top_path = None , package_path = None , ** attrs )", + "filename": "misc_util.py", + "nloc": 41, + "complexity": 11, + "token_count": 348, + "parameters": [ + "self", + "package_name", + "parent_name", + "top_path", + "package_path", + "attrs" + ], + "start_line": 286, + "end_line": 335, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 50, + "top_nesting_level": 1 + }, + { + "name": "todict", + "long_name": "todict( self )", + "filename": "misc_util.py", + "nloc": 9, + "complexity": 4, + "token_count": 57, + "parameters": [ + "self" + ], + "start_line": 337, + "end_line": 348, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 12, + "top_nesting_level": 1 + }, + { + "name": "__dict__", + "long_name": "__dict__( self )", + "filename": "misc_util.py", + "nloc": 2, + "complexity": 1, + "token_count": 11, + "parameters": [ + "self" + ], + "start_line": 350, + "end_line": 351, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 2, + "top_nesting_level": 1 + }, + { + "name": "get_distribution", + "long_name": "get_distribution( self )", + "filename": "misc_util.py", + "nloc": 4, + "complexity": 1, + "token_count": 18, + "parameters": [ + "self" + ], + "start_line": 353, + "end_line": 356, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 4, + "top_nesting_level": 1 + }, + { + "name": "get_subpackage", + "long_name": "get_subpackage( self , subpackage_name , subpackage_path = None )", + "filename": "misc_util.py", + "nloc": 50, + "complexity": 12, + "token_count": 453, + "parameters": [ + "self", + "subpackage_name", + "subpackage_path" + ], + "start_line": 358, + "end_line": 415, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 58, + "top_nesting_level": 1 + }, + { + "name": "add_subpackage", + "long_name": "add_subpackage( self , subpackage_name , subpackage_path = None )", + "filename": "misc_util.py", + "nloc": 20, + "complexity": 6, + "token_count": 127, + "parameters": [ + "self", + "subpackage_name", + "subpackage_path" + ], + "start_line": 417, + "end_line": 439, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 23, + "top_nesting_level": 1 + }, + { + "name": "add_data_dir", + "long_name": "add_data_dir( self , data_path )", + "filename": "misc_util.py", + "nloc": 25, + "complexity": 7, + "token_count": 188, + "parameters": [ + "self", + "data_path" + ], + "start_line": 441, + "end_line": 473, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 33, + "top_nesting_level": 1 + }, + { + "name": "add_data_files", + "long_name": "add_data_files( self , * files )", + "filename": "misc_util.py", + "nloc": 40, + "complexity": 15, + "token_count": 324, + "parameters": [ + "self", + "files" + ], + "start_line": 475, + "end_line": 525, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 51, + "top_nesting_level": 1 + }, + { + "name": "add_include_dirs", + "long_name": "add_include_dirs( self , * paths )", + "filename": "misc_util.py", + "nloc": 8, + "complexity": 2, + "token_count": 49, + "parameters": [ + "self", + "paths" + ], + "start_line": 529, + "end_line": 538, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 10, + "top_nesting_level": 1 + }, + { + "name": "add_headers", + "long_name": "add_headers( self , * files )", + "filename": "misc_util.py", + "nloc": 14, + "complexity": 7, + "token_count": 143, + "parameters": [ + "self", + "files" + ], + "start_line": 540, + "end_line": 559, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 20, + "top_nesting_level": 1 + }, + { + "name": "_fix_paths", + "long_name": "_fix_paths( self , paths )", + "filename": "misc_util.py", + "nloc": 22, + "complexity": 8, + "token_count": 136, + "parameters": [ + "self", + "paths" + ], + "start_line": 561, + "end_line": 582, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 22, + "top_nesting_level": 1 + }, + { + "name": "paths", + "long_name": "paths( self , * paths )", + "filename": "misc_util.py", + "nloc": 2, + "complexity": 1, + "token_count": 16, + "parameters": [ + "self", + "paths" + ], + "start_line": 584, + "end_line": 587, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 4, + "top_nesting_level": 1 + }, + { + "name": "add_extension", + "long_name": "add_extension( self , name , sources , ** kw )", + "filename": "misc_util.py", + "nloc": 45, + "complexity": 14, + "token_count": 365, + "parameters": [ + "self", + "name", + "sources", + "kw" + ], + "start_line": 589, + "end_line": 651, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 63, + "top_nesting_level": 1 + }, + { + "name": "add_library", + "long_name": "add_library( self , name , sources , ** build_info )", + "filename": "misc_util.py", + "nloc": 15, + "complexity": 4, + "token_count": 106, + "parameters": [ + "self", + "name", + "sources", + "build_info" + ], + "start_line": 653, + "end_line": 678, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 26, + "top_nesting_level": 1 + }, + { + "name": "add_scripts", + "long_name": "add_scripts( self , * files )", + "filename": "misc_util.py", + "nloc": 8, + "complexity": 2, + "token_count": 49, + "parameters": [ + "self", + "files" + ], + "start_line": 680, + "end_line": 689, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 10, + "top_nesting_level": 1 + }, + { + "name": "dict_append", + "long_name": "dict_append( self , ** dict )", + "filename": "misc_util.py", + "nloc": 15, + "complexity": 6, + "token_count": 138, + "parameters": [ + "self", + "dict" + ], + "start_line": 691, + "end_line": 705, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 15, + "top_nesting_level": 1 + }, + { + "name": "__str__", + "long_name": "__str__( self )", + "filename": "misc_util.py", + "nloc": 10, + "complexity": 3, + "token_count": 72, + "parameters": [ + "self" + ], + "start_line": 707, + "end_line": 716, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 10, + "top_nesting_level": 1 + }, + { + "name": "get_config_cmd", + "long_name": "get_config_cmd( self )", + "filename": "misc_util.py", + "nloc": 10, + "complexity": 2, + "token_count": 63, + "parameters": [ + "self" + ], + "start_line": 718, + "end_line": 727, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 10, + "top_nesting_level": 1 + }, + { + "name": "get_build_temp_dir", + "long_name": "get_build_temp_dir( self )", + "filename": "misc_util.py", + "nloc": 4, + "complexity": 1, + "token_count": 20, + "parameters": [ + "self" + ], + "start_line": 729, + "end_line": 732, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 4, + "top_nesting_level": 1 + }, + { + "name": "have_f77c", + "long_name": "have_f77c( self )", + "filename": "misc_util.py", + "nloc": 8, + "complexity": 1, + "token_count": 30, + "parameters": [ + "self" + ], + "start_line": 734, + "end_line": 745, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 12, + "top_nesting_level": 1 + }, + { + "name": "have_f90c", + "long_name": "have_f90c( self )", + "filename": "misc_util.py", + "nloc": 8, + "complexity": 1, + "token_count": 30, + "parameters": [ + "self" + ], + "start_line": 747, + "end_line": 758, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 12, + "top_nesting_level": 1 + }, + { + "name": "append_to", + "long_name": "append_to( self , extlib )", + "filename": "misc_util.py", + "nloc": 12, + "complexity": 2, + "token_count": 83, + "parameters": [ + "self", + "extlib" + ], + "start_line": 760, + "end_line": 773, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 14, + "top_nesting_level": 1 + }, + { + "name": "_get_svn_revision", + "long_name": "_get_svn_revision( self , path )", + "filename": "misc_util.py", + "nloc": 10, + "complexity": 3, + "token_count": 77, + "parameters": [ + "self", + "path" + ], + "start_line": 775, + "end_line": 786, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 12, + "top_nesting_level": 1 + }, + { + "name": "get_version", + "long_name": "get_version( self )", + "filename": "misc_util.py", + "nloc": 38, + "complexity": 11, + "token_count": 257, + "parameters": [ + "self" + ], + "start_line": 788, + "end_line": 834, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 47, + "top_nesting_level": 1 + }, + { + "name": "make_svn_version_py.make_svn_version_py.generate_svn_version_py.rm_file", + "long_name": "make_svn_version_py.make_svn_version_py.generate_svn_version_py.rm_file( f = target )", + "filename": "misc_util.py", + "nloc": 5, + "complexity": 3, + "token_count": 45, + "parameters": [ + "f" + ], + "start_line": 858, + "end_line": 862, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 5, + "top_nesting_level": 3 + }, + { + "name": "make_svn_version_py.generate_svn_version_py", + "long_name": "make_svn_version_py.generate_svn_version_py( )", + "filename": "misc_util.py", + "nloc": 13, + "complexity": 2, + "token_count": 81, + "parameters": [], + "start_line": 847, + "end_line": 865, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 19, + "top_nesting_level": 2 + }, + { + "name": "make_svn_version_py", + "long_name": "make_svn_version_py( self )", + "filename": "misc_util.py", + "nloc": 8, + "complexity": 2, + "token_count": 66, + "parameters": [ + "self" + ], + "start_line": 836, + "end_line": 869, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 34, + "top_nesting_level": 1 + }, + { + "name": "make_config_py", + "long_name": "make_config_py( self , name = '__config__' )", + "filename": "misc_util.py", + "nloc": 3, + "complexity": 1, + "token_count": 27, + "parameters": [ + "self", + "name" + ], + "start_line": 871, + "end_line": 876, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 6, + "top_nesting_level": 1 + }, + { + "name": "get_info", + "long_name": "get_info( self , * names )", + "filename": "misc_util.py", + "nloc": 6, + "complexity": 2, + "token_count": 36, + "parameters": [ + "self", + "names" + ], + "start_line": 878, + "end_line": 885, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 8, + "top_nesting_level": 1 + }, + { + "name": "get_cmd", + "long_name": "get_cmd( cmdname , _cache = { } )", + "filename": "misc_util.py", + "nloc": 11, + "complexity": 3, + "token_count": 65, + "parameters": [ + "cmdname", + "_cache" + ], + "start_line": 887, + "end_line": 897, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 11, + "top_nesting_level": 0 + }, + { + "name": "get_numpy_include_dirs", + "long_name": "get_numpy_include_dirs( )", + "filename": "misc_util.py", + "nloc": 11, + "complexity": 3, + "token_count": 85, + "parameters": [], + "start_line": 899, + "end_line": 913, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 15, + "top_nesting_level": 0 + }, + { + "name": "default_config_dict", + "long_name": "default_config_dict( name = None , parent_name = None , local_path = None )", + "filename": "misc_util.py", + "nloc": 9, + "complexity": 1, + "token_count": 70, + "parameters": [ + "name", + "parent_name", + "local_path" + ], + "start_line": 917, + "end_line": 928, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 12, + "top_nesting_level": 0 + }, + { + "name": "dict_append", + "long_name": "dict_append( d , ** kws )", + "filename": "misc_util.py", + "nloc": 6, + "complexity": 3, + "token_count": 44, + "parameters": [ + "d", + "kws" + ], + "start_line": 931, + "end_line": 936, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 6, + "top_nesting_level": 0 + }, + { + "name": "appendpath", + "long_name": "appendpath( prefix , path )", + "filename": "misc_util.py", + "nloc": 19, + "complexity": 6, + "token_count": 237, + "parameters": [ + "prefix", + "path" + ], + "start_line": 938, + "end_line": 957, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 20, + "top_nesting_level": 0 + }, + { + "name": "generate_config_py", + "long_name": "generate_config_py( target )", + "filename": "misc_util.py", + "nloc": 27, + "complexity": 2, + "token_count": 117, + "parameters": [ + "target" + ], + "start_line": 959, + "end_line": 992, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 34, + "top_nesting_level": 0 + }, + { + "name": "generate_svn_version_py", + "long_name": "generate_svn_version_py( extension , build_dir )", + "filename": "misc_util.py", + "nloc": 15, + "complexity": 4, + "token_count": 109, + "parameters": [ + "extension", + "build_dir" + ], + "start_line": 994, + "end_line": 1021, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 28, + "top_nesting_level": 0 + } + ], + "methods_before": [ + { + "name": "allpath", + "long_name": "allpath( name )", + "filename": "misc_util.py", + "nloc": 4, + "complexity": 1, + "token_count": 24, + "parameters": [ + "name" + ], + "start_line": 19, + "end_line": 22, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 4, + "top_nesting_level": 0 + }, + { + "name": "get_path", + "long_name": "get_path( mod_name , parent_path = None )", + "filename": "misc_util.py", + "nloc": 15, + "complexity": 6, + "token_count": 132, + "parameters": [ + "mod_name", + "parent_path" + ], + "start_line": 24, + "end_line": 44, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 21, + "top_nesting_level": 0 + }, + { + "name": "terminal_has_colors", + "long_name": "terminal_has_colors( )", + "filename": "misc_util.py", + "nloc": 18, + "complexity": 13, + "token_count": 137, + "parameters": [], + "start_line": 48, + "end_line": 73, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 26, + "top_nesting_level": 0 + }, + { + "name": "cyg2win32", + "long_name": "cyg2win32( path )", + "filename": "misc_util.py", + "nloc": 4, + "complexity": 3, + "token_count": 42, + "parameters": [ + "path" + ], + "start_line": 90, + "end_line": 93, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 4, + "top_nesting_level": 0 + }, + { + "name": "_get_f90_modules", + "long_name": "_get_f90_modules( source )", + "filename": "misc_util.py", + "nloc": 13, + "complexity": 4, + "token_count": 77, + "parameters": [ + "source" + ], + "start_line": 102, + "end_line": 118, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 17, + "top_nesting_level": 0 + }, + { + "name": "all_strings", + "long_name": "all_strings( lst )", + "filename": "misc_util.py", + "nloc": 5, + "complexity": 3, + "token_count": 26, + "parameters": [ + "lst" + ], + "start_line": 120, + "end_line": 125, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 6, + "top_nesting_level": 0 + }, + { + "name": "has_f_sources", + "long_name": "has_f_sources( sources )", + "filename": "misc_util.py", + "nloc": 5, + "complexity": 3, + "token_count": 21, + "parameters": [ + "sources" + ], + "start_line": 127, + "end_line": 132, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 6, + "top_nesting_level": 0 + }, + { + "name": "has_cxx_sources", + "long_name": "has_cxx_sources( sources )", + "filename": "misc_util.py", + "nloc": 5, + "complexity": 3, + "token_count": 21, + "parameters": [ + "sources" + ], + "start_line": 134, + "end_line": 139, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 6, + "top_nesting_level": 0 + }, + { + "name": "filter_sources", + "long_name": "filter_sources( sources )", + "filename": "misc_util.py", + "nloc": 17, + "complexity": 5, + "token_count": 84, + "parameters": [ + "sources" + ], + "start_line": 141, + "end_line": 161, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 21, + "top_nesting_level": 0 + }, + { + "name": "_get_headers", + "long_name": "_get_headers( directory_list )", + "filename": "misc_util.py", + "nloc": 6, + "complexity": 2, + "token_count": 39, + "parameters": [ + "directory_list" + ], + "start_line": 164, + "end_line": 170, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 7, + "top_nesting_level": 0 + }, + { + "name": "_get_directories", + "long_name": "_get_directories( list_of_sources )", + "filename": "misc_util.py", + "nloc": 7, + "complexity": 4, + "token_count": 51, + "parameters": [ + "list_of_sources" + ], + "start_line": 172, + "end_line": 179, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 8, + "top_nesting_level": 0 + }, + { + "name": "get_dependencies", + "long_name": "get_dependencies( sources )", + "filename": "misc_util.py", + "nloc": 2, + "complexity": 1, + "token_count": 13, + "parameters": [ + "sources" + ], + "start_line": 181, + "end_line": 183, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 3, + "top_nesting_level": 0 + }, + { + "name": "is_local_src_dir", + "long_name": "is_local_src_dir( directory )", + "filename": "misc_util.py", + "nloc": 12, + "complexity": 6, + "token_count": 112, + "parameters": [ + "directory" + ], + "start_line": 185, + "end_line": 198, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 14, + "top_nesting_level": 0 + }, + { + "name": "_gsf_visit_func", + "long_name": "_gsf_visit_func( filenames , dirname , names )", + "filename": "misc_util.py", + "nloc": 13, + "complexity": 7, + "token_count": 103, + "parameters": [ + "filenames", + "dirname", + "names" + ], + "start_line": 200, + "end_line": 212, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 13, + "top_nesting_level": 0 + }, + { + "name": "get_ext_source_files", + "long_name": "get_ext_source_files( ext )", + "filename": "misc_util.py", + "nloc": 11, + "complexity": 4, + "token_count": 87, + "parameters": [ + "ext" + ], + "start_line": 214, + "end_line": 225, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 12, + "top_nesting_level": 0 + }, + { + "name": "get_script_files", + "long_name": "get_script_files( scripts )", + "filename": "misc_util.py", + "nloc": 3, + "complexity": 1, + "token_count": 25, + "parameters": [ + "scripts" + ], + "start_line": 227, + "end_line": 229, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 3, + "top_nesting_level": 0 + }, + { + "name": "get_lib_source_files", + "long_name": "get_lib_source_files( lib )", + "filename": "misc_util.py", + "nloc": 13, + "complexity": 4, + "token_count": 111, + "parameters": [ + "lib" + ], + "start_line": 231, + "end_line": 243, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 13, + "top_nesting_level": 0 + }, + { + "name": "get_data_files", + "long_name": "get_data_files( data )", + "filename": "misc_util.py", + "nloc": 18, + "complexity": 7, + "token_count": 102, + "parameters": [ + "data" + ], + "start_line": 245, + "end_line": 262, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 18, + "top_nesting_level": 0 + }, + { + "name": "dot_join", + "long_name": "dot_join( * args )", + "filename": "misc_util.py", + "nloc": 2, + "complexity": 1, + "token_count": 18, + "parameters": [ + "args" + ], + "start_line": 264, + "end_line": 265, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 2, + "top_nesting_level": 0 + }, + { + "name": "get_frame", + "long_name": "get_frame( level = 0 )", + "filename": "misc_util.py", + "nloc": 8, + "complexity": 3, + "token_count": 50, + "parameters": [ + "level" + ], + "start_line": 267, + "end_line": 274, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 8, + "top_nesting_level": 0 + }, + { + "name": "__init__", + "long_name": "__init__( self , package_name = None , parent_name = None , top_path = None , package_path = None , ** attrs )", + "filename": "misc_util.py", + "nloc": 41, + "complexity": 11, + "token_count": 348, + "parameters": [ + "self", + "package_name", + "parent_name", + "top_path", + "package_path", + "attrs" + ], + "start_line": 286, + "end_line": 335, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 50, + "top_nesting_level": 1 + }, + { + "name": "todict", + "long_name": "todict( self )", + "filename": "misc_util.py", + "nloc": 9, + "complexity": 4, + "token_count": 57, + "parameters": [ + "self" + ], + "start_line": 337, + "end_line": 348, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 12, + "top_nesting_level": 1 + }, + { + "name": "__dict__", + "long_name": "__dict__( self )", + "filename": "misc_util.py", + "nloc": 2, + "complexity": 1, + "token_count": 11, + "parameters": [ + "self" + ], + "start_line": 350, + "end_line": 351, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 2, + "top_nesting_level": 1 + }, + { + "name": "get_distribution", + "long_name": "get_distribution( self )", + "filename": "misc_util.py", + "nloc": 4, + "complexity": 1, + "token_count": 18, + "parameters": [ + "self" + ], + "start_line": 353, + "end_line": 356, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 4, + "top_nesting_level": 1 + }, + { + "name": "get_subpackage", + "long_name": "get_subpackage( self , subpackage_name , subpackage_path = None )", + "filename": "misc_util.py", + "nloc": 50, + "complexity": 12, + "token_count": 453, + "parameters": [ + "self", + "subpackage_name", + "subpackage_path" + ], + "start_line": 358, + "end_line": 415, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 58, + "top_nesting_level": 1 + }, + { + "name": "add_subpackage", + "long_name": "add_subpackage( self , subpackage_name , subpackage_path = None )", + "filename": "misc_util.py", + "nloc": 20, + "complexity": 6, + "token_count": 127, + "parameters": [ + "self", + "subpackage_name", + "subpackage_path" + ], + "start_line": 417, + "end_line": 439, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 23, + "top_nesting_level": 1 + }, + { + "name": "add_data_dir", + "long_name": "add_data_dir( self , data_path )", + "filename": "misc_util.py", + "nloc": 25, + "complexity": 7, + "token_count": 188, + "parameters": [ + "self", + "data_path" + ], + "start_line": 441, + "end_line": 473, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 33, + "top_nesting_level": 1 + }, + { + "name": "add_data_files", + "long_name": "add_data_files( self , * files )", + "filename": "misc_util.py", + "nloc": 40, + "complexity": 15, + "token_count": 324, + "parameters": [ + "self", + "files" + ], + "start_line": 475, + "end_line": 525, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 51, + "top_nesting_level": 1 + }, + { + "name": "add_include_dirs", + "long_name": "add_include_dirs( self , * paths )", + "filename": "misc_util.py", + "nloc": 8, + "complexity": 2, + "token_count": 49, + "parameters": [ + "self", + "paths" + ], + "start_line": 529, + "end_line": 538, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 10, + "top_nesting_level": 1 + }, + { + "name": "add_headers", + "long_name": "add_headers( self , * files )", + "filename": "misc_util.py", + "nloc": 14, + "complexity": 7, + "token_count": 143, + "parameters": [ + "self", + "files" + ], + "start_line": 540, + "end_line": 559, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 20, + "top_nesting_level": 1 + }, + { + "name": "_fix_paths", + "long_name": "_fix_paths( self , paths )", + "filename": "misc_util.py", + "nloc": 22, + "complexity": 8, + "token_count": 136, + "parameters": [ + "self", + "paths" + ], + "start_line": 561, + "end_line": 582, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 22, + "top_nesting_level": 1 + }, + { + "name": "paths", + "long_name": "paths( self , * paths )", + "filename": "misc_util.py", + "nloc": 2, + "complexity": 1, + "token_count": 16, + "parameters": [ + "self", + "paths" + ], + "start_line": 584, + "end_line": 587, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 4, + "top_nesting_level": 1 + }, + { + "name": "add_extension", + "long_name": "add_extension( self , name , sources , ** kw )", + "filename": "misc_util.py", + "nloc": 45, + "complexity": 14, + "token_count": 365, + "parameters": [ + "self", + "name", + "sources", + "kw" + ], + "start_line": 589, + "end_line": 651, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 63, + "top_nesting_level": 1 + }, + { + "name": "add_library", + "long_name": "add_library( self , name , sources , ** build_info )", + "filename": "misc_util.py", + "nloc": 14, + "complexity": 4, + "token_count": 98, + "parameters": [ + "self", + "name", + "sources", + "build_info" + ], + "start_line": 653, + "end_line": 677, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 25, + "top_nesting_level": 1 + }, + { + "name": "add_scripts", + "long_name": "add_scripts( self , * files )", + "filename": "misc_util.py", + "nloc": 8, + "complexity": 2, + "token_count": 49, + "parameters": [ + "self", + "files" + ], + "start_line": 679, + "end_line": 688, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 10, + "top_nesting_level": 1 + }, + { + "name": "dict_append", + "long_name": "dict_append( self , ** dict )", + "filename": "misc_util.py", + "nloc": 15, + "complexity": 6, + "token_count": 138, + "parameters": [ + "self", + "dict" + ], + "start_line": 690, + "end_line": 704, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 15, + "top_nesting_level": 1 + }, + { + "name": "__str__", + "long_name": "__str__( self )", + "filename": "misc_util.py", + "nloc": 10, + "complexity": 3, + "token_count": 72, + "parameters": [ + "self" + ], + "start_line": 706, + "end_line": 715, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 10, + "top_nesting_level": 1 + }, + { + "name": "get_config_cmd", + "long_name": "get_config_cmd( self )", + "filename": "misc_util.py", + "nloc": 10, + "complexity": 2, + "token_count": 63, + "parameters": [ + "self" + ], + "start_line": 717, + "end_line": 726, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 10, + "top_nesting_level": 1 + }, + { + "name": "get_build_temp_dir", + "long_name": "get_build_temp_dir( self )", + "filename": "misc_util.py", + "nloc": 4, + "complexity": 1, + "token_count": 20, + "parameters": [ + "self" + ], + "start_line": 728, + "end_line": 731, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 4, + "top_nesting_level": 1 + }, + { + "name": "have_f77c", + "long_name": "have_f77c( self )", + "filename": "misc_util.py", + "nloc": 8, + "complexity": 1, + "token_count": 30, + "parameters": [ + "self" + ], + "start_line": 733, + "end_line": 744, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 12, + "top_nesting_level": 1 + }, + { + "name": "have_f90c", + "long_name": "have_f90c( self )", + "filename": "misc_util.py", + "nloc": 8, + "complexity": 1, + "token_count": 30, + "parameters": [ + "self" + ], + "start_line": 746, + "end_line": 757, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 12, + "top_nesting_level": 1 + }, + { + "name": "append_to", + "long_name": "append_to( self , extlib )", + "filename": "misc_util.py", + "nloc": 12, + "complexity": 2, + "token_count": 83, + "parameters": [ + "self", + "extlib" + ], + "start_line": 759, + "end_line": 772, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 14, + "top_nesting_level": 1 + }, + { + "name": "_get_svn_revision", + "long_name": "_get_svn_revision( self , path )", + "filename": "misc_util.py", + "nloc": 10, + "complexity": 3, + "token_count": 77, + "parameters": [ + "self", + "path" + ], + "start_line": 774, + "end_line": 785, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 12, + "top_nesting_level": 1 + }, + { + "name": "get_version", + "long_name": "get_version( self )", + "filename": "misc_util.py", + "nloc": 38, + "complexity": 11, + "token_count": 257, + "parameters": [ + "self" + ], + "start_line": 787, + "end_line": 833, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 47, + "top_nesting_level": 1 + }, + { + "name": "make_svn_version_py.make_svn_version_py.generate_svn_version_py.rm_file", + "long_name": "make_svn_version_py.make_svn_version_py.generate_svn_version_py.rm_file( f = target )", + "filename": "misc_util.py", + "nloc": 5, + "complexity": 3, + "token_count": 45, + "parameters": [ + "f" + ], + "start_line": 857, + "end_line": 861, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 5, + "top_nesting_level": 3 + }, + { + "name": "make_svn_version_py.generate_svn_version_py", + "long_name": "make_svn_version_py.generate_svn_version_py( )", + "filename": "misc_util.py", + "nloc": 13, + "complexity": 2, + "token_count": 81, + "parameters": [], + "start_line": 846, + "end_line": 864, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 19, + "top_nesting_level": 2 + }, + { + "name": "make_svn_version_py", + "long_name": "make_svn_version_py( self )", + "filename": "misc_util.py", + "nloc": 8, + "complexity": 2, + "token_count": 66, + "parameters": [ + "self" + ], + "start_line": 835, + "end_line": 868, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 34, + "top_nesting_level": 1 + }, + { + "name": "make_config_py", + "long_name": "make_config_py( self , name = '__config__' )", + "filename": "misc_util.py", + "nloc": 3, + "complexity": 1, + "token_count": 27, + "parameters": [ + "self", + "name" + ], + "start_line": 870, + "end_line": 875, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 6, + "top_nesting_level": 1 + }, + { + "name": "get_info", + "long_name": "get_info( self , * names )", + "filename": "misc_util.py", + "nloc": 6, + "complexity": 2, + "token_count": 36, + "parameters": [ + "self", + "names" + ], + "start_line": 877, + "end_line": 884, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 8, + "top_nesting_level": 1 + }, + { + "name": "get_cmd", + "long_name": "get_cmd( cmdname , _cache = { } )", + "filename": "misc_util.py", + "nloc": 11, + "complexity": 3, + "token_count": 65, + "parameters": [ + "cmdname", + "_cache" + ], + "start_line": 886, + "end_line": 896, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 11, + "top_nesting_level": 0 + }, + { + "name": "get_numpy_include_dirs", + "long_name": "get_numpy_include_dirs( )", + "filename": "misc_util.py", + "nloc": 11, + "complexity": 3, + "token_count": 85, + "parameters": [], + "start_line": 898, + "end_line": 912, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 15, + "top_nesting_level": 0 + }, + { + "name": "default_config_dict", + "long_name": "default_config_dict( name = None , parent_name = None , local_path = None )", + "filename": "misc_util.py", + "nloc": 9, + "complexity": 1, + "token_count": 70, + "parameters": [ + "name", + "parent_name", + "local_path" + ], + "start_line": 916, + "end_line": 927, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 12, + "top_nesting_level": 0 + }, + { + "name": "dict_append", + "long_name": "dict_append( d , ** kws )", + "filename": "misc_util.py", + "nloc": 6, + "complexity": 3, + "token_count": 44, + "parameters": [ + "d", + "kws" + ], + "start_line": 930, + "end_line": 935, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 6, + "top_nesting_level": 0 + }, + { + "name": "appendpath", + "long_name": "appendpath( prefix , path )", + "filename": "misc_util.py", + "nloc": 19, + "complexity": 6, + "token_count": 237, + "parameters": [ + "prefix", + "path" + ], + "start_line": 937, + "end_line": 956, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 20, + "top_nesting_level": 0 + }, + { + "name": "generate_config_py", + "long_name": "generate_config_py( target )", + "filename": "misc_util.py", + "nloc": 27, + "complexity": 2, + "token_count": 117, + "parameters": [ + "target" + ], + "start_line": 958, + "end_line": 991, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 34, + "top_nesting_level": 0 + }, + { + "name": "generate_svn_version_py", + "long_name": "generate_svn_version_py( extension , build_dir )", + "filename": "misc_util.py", + "nloc": 15, + "complexity": 4, + "token_count": 109, + "parameters": [ + "extension", + "build_dir" + ], + "start_line": 993, + "end_line": 1020, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 28, + "top_nesting_level": 0 + } + ], + "changed_methods": [ + { + "name": "add_library", + "long_name": "add_library( self , name , sources , ** build_info )", + "filename": "misc_util.py", + "nloc": 15, + "complexity": 4, + "token_count": 106, + "parameters": [ + "self", + "name", + "sources", + "build_info" + ], + "start_line": 653, + "end_line": 678, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 26, + "top_nesting_level": 1 + } + ], + "nloc": 769, + "complexity": 238, + "token_count": 5730, + "diff_parsed": { + "added": [ + " if k in ['sources','depends','include_dirs','library_dirs',", + " 'module_dirs','extra_objects']:" + ], + "deleted": [ + " if k in ['sources','depends']:" + ] + } + } + ] + }, + { + "hash": "c3761a4940346ef33976f87879c9842110f0a968", + "msg": "Add UnsignedInt32", + "author": { + "name": "Travis Oliphant", + "email": "oliphant@enthought.com" + }, + "committer": { + "name": "Travis Oliphant", + "email": "oliphant@enthought.com" + }, + "author_date": "2006-01-27T19:28:52+00:00", + "author_timezone": 0, + "committer_date": "2006-01-27T19:28:52+00:00", + "committer_timezone": 0, + "branches": [ + "main" + ], + "in_main_branch": true, + "merge": false, + "parents": [ + "f94d937892c7d82bdb35115968f6fa0d2d8d67cc" + ], + "project_name": "repo_copy", + "project_path": "/tmp/tmppy2o86q9/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/oldnumeric.py", + "new_path": "numpy/core/oldnumeric.py", + "filename": "oldnumeric.py", + "extension": "py", + "change_type": "MODIFY", + "diff": "@@ -5,7 +5,7 @@\n 'UFuncType', 'UfuncType', 'ArrayType', 'arraytype',\n 'LittleEndian', 'Bool', \n 'Character', 'UnsignedInt8', 'UnsignedInt16', 'UnsignedInt',\n- 'UInt8','UInt16','UInt32',\n+ 'UInt8','UInt16','UInt32', 'UnsignedInt32',\n # UnsignedInt64 and Unsigned128 added below if possible\n # same for Int64 and Int128, Float128, and Complex128\n 'Int8', 'Int16', 'Int32',\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',\n # UnsignedInt64 and Unsigned128 added below if possible\n # same for Int64 and Int128, Float128, and Complex128\n 'Int8', 'Int16', 'Int32',\n 'Int0', 'Int', 'Float0', 'Float', 'Complex0', 'Complex',\n 'PyObject', 'Float32', 'Float64',\n 'Complex32', 'Complex64',\n 'typecodes', 'sarray', 'arrayrange', 'cross_correlate',\n 'matrixmultiply', 'outerproduct', 'innerproduct',\n # from cPickle\n 'dump', 'dumps',\n # functions that are now methods\n 'take', 'reshape', 'choose', 'repeat', 'put', 'putmask',\n 'swapaxes', 'transpose', 'sort', 'argsort', 'argmax', 'argmin',\n 'searchsorted', 'alen', \n 'resize', 'diagonal', 'trace', 'ravel', 'nonzero', 'shape',\n 'compress', 'clip', 'sum', 'product', 'prod', 'sometrue', 'alltrue',\n 'any', 'all', 'cumsum', 'cumproduct', 'cumprod', 'ptp', 'ndim',\n 'rank', 'size', 'around', 'round_', 'mean', 'std', 'var', 'squeeze',\n 'amax', 'amin',\n ]\n\nimport multiarray as mu\nimport umath as um\nimport numerictypes as nt\nfrom numeric import asarray, array, correlate, outer, concatenate\nfrom umath import sign, absolute, multiply\nimport numeric as _nx\nimport sys\n_dt_ = nt.arrtype2char\n\nimport types\n\ntry:\n _gentype = types.GeneratorType\nexcept AttributeError:\n _gentype = types.NoneType\n#Use this to add a new axis to an array\n#compatibility only\nNewAxis = None\n\n#deprecated\nUFuncType = type(um.sin)\nUfuncType = type(um.sin)\nArrayType = mu.ndarray\narraytype = mu.ndarray\n\nLittleEndian = (sys.byteorder == 'little')\n\n# save away Python sum\n_sum_ = sum\n\n# backward compatible names from old Precision.py\n\nCharacter = 'S1'\nUnsignedInt8 = _dt_(nt.uint8)\nUInt8 = UnsignedInt8\nUnsignedInt16 = _dt_(nt.uint16)\nUInt16 = UnsignedInt16\nUnsignedInt32 = _dt_(nt.uint32)\nUInt32 = UnsignedInt32\nUnsignedInt = _dt_(nt.uint)\n\ntry:\n UnsignedInt64 = _dt_(nt.uint64)\nexcept AttributeError:\n pass\nelse:\n UInt64 = UnsignedInt64\n __all__ += ['UnsignedInt64', 'UInt64']\ntry:\n UnsignedInt128 = _dt_(nt.uint128)\nexcept AttributeError:\n pass\nelse:\n UInt128 = UnsignedInt128\n __all__ += ['UnsignedInt128','UInt128']\n\nInt8 = _dt_(nt.int8)\nInt16 = _dt_(nt.int16)\nInt32 = _dt_(nt.int32)\n\ntry:\n Int64 = _dt_(nt.int64)\nexcept AttributeError:\n pass\nelse:\n __all__ += ['Int64']\n\ntry:\n Int128 = _dt_(nt.int128)\nexcept AttributeError:\n pass\nelse:\n __all__ += ['Int128']\n\nBool = _dt_(bool)\nInt0 = _dt_(int)\nInt = _dt_(int)\nFloat0 = _dt_(float)\nFloat = _dt_(float)\nComplex0 = _dt_(complex)\nComplex = _dt_(complex)\nPyObject = _dt_(nt.object_)\nFloat32 = _dt_(nt.float32)\nFloat64 = _dt_(nt.float64)\n\ntry:\n Float128 = _dt_(nt.float128)\nexcept AttributeError:\n pass\nelse:\n __all__ += ['Float128']\n\nComplex32 = _dt_(nt.complex64)\nComplex64 = _dt_(nt.complex128)\n\ntry:\n Complex128 = _dt_(nt.complex256)\nexcept AttributeError:\n pass\nelse:\n __all__ += ['Complex128']\n\ntypecodes = {'Character':'S1',\n 'Integer':'bhilqp',\n 'UnsignedInteger':'BHILQP',\n 'Float':'fdg',\n 'Complex':'FDG',\n 'AllInteger':'bBhHiIlLqQpP',\n 'AllFloat':'fdgFDG',\n 'All':'?bhilqpBHILQPfdgFDGSUVO'}\n\ndef sarray(a, dtype=None, copy=False):\n return array(a, dtype, copy)\n\n# backward compatibility\narrayrange = mu.arange\ncross_correlate = correlate\n\n# deprecated names\nmatrixmultiply = mu.dot\nouterproduct = outer\ninnerproduct = mu.inner\n\nfrom cPickle import dump, dumps\n\n# functions that are now methods\n\ndef take(a, indices, axis=0):\n a = asarray(a)\n return a.take(indices, axis)\n\ndef reshape(a, newshape):\n \"\"\"Change the shape of a to newshape. Return a new view object.\n \"\"\"\n return asarray(a).reshape(newshape)\n\ndef choose(a, choices):\n a = asarray(a)\n return a.choose(choices)\n\ndef repeat(a, repeats, axis=0):\n \"\"\"repeat elements of a repeats times along axis\n repeats is a sequence of length a.shape[axis]\n telling how many times to repeat each element.\n If repeats is an integer, it is interpreted as\n a tuple of length a.shape[axis] containing repeats.\n The argument a can be anything array(a) will accept.\n \"\"\"\n a = array(a, copy=False)\n return a.repeat(repeats, axis)\n\ndef put (a, ind, v):\n \"\"\"put(a, ind, v) results in a[n] = v[n] for all n in ind\n If v is shorter than mask it will be repeated as necessary.\n In particular v can be a scalar or length 1 array.\n The routine put is the equivalent of the following (although the loop\n is in C for speed):\n\n ind = array(indices, copy=False)\n v = array(values, copy=False).astype(a, a.dtype)\n for i in ind: a.flat[i] = v[i]\n a must be a contiguous Numeric array.\n \"\"\"\n return a.put(v,ind)\n\ndef putmask (a, mask, v):\n \"\"\"putmask(a, mask, v) results in a = v for all places mask is true.\n If v is shorter than mask it will be repeated as necessary.\n In particular v can be a scalar or length 1 array.\n \"\"\"\n return a.putmask(v, mask)\n\ndef swapaxes(a, axis1, axis2):\n \"\"\"swapaxes(a, axis1, axis2) returns array a with axis1 and axis2\n interchanged.\n \"\"\"\n a = array(a, copy=False)\n return a.swapaxes(axis1, axis2)\n\ndef transpose(a, axes=None):\n \"\"\"transpose(a, axes=None) returns array with dimensions permuted\n according to axes. If axes is None (default) returns array with\n dimensions reversed.\n \"\"\"\n a = array(a,copy=False)\n return a.transpose(axes)\n\ndef sort(a, axis=-1):\n \"\"\"sort(a,axis=-1) returns array with elements sorted along given axis.\n \"\"\"\n a = array(a, copy=True)\n a.sort(axis)\n return a\n\ndef argsort(a, axis=-1):\n \"\"\"argsort(a,axis=-1) return the indices into a of the sorted array\n along the given axis, so that take(a,result,axis) is the sorted array.\n \"\"\"\n a = array(a, copy=False)\n return a.argsort(axis)\n\ndef argmax(a, axis=-1):\n \"\"\"argmax(a,axis=-1) returns the indices to the maximum value of the\n 1-D arrays along the given axis.\n \"\"\"\n a = array(a, copy=False)\n return a.argmax(axis)\n\ndef argmin(a, axis=-1):\n \"\"\"argmin(a,axis=-1) returns the indices to the minimum value of the\n 1-D arrays along the given axis.\n \"\"\"\n a = array(a,copy=False)\n return a.argmin(axis)\n\ndef searchsorted(a, v):\n \"\"\"searchsorted(a, v)\n \"\"\"\n a = array(a,copy=False)\n return a.searchsorted(v)\n\ndef resize(a, new_shape):\n \"\"\"resize(a,new_shape) returns a new array with the specified shape.\n The original array's total size can be any size. It\n fills the new array with repeated copies of a.\n\n Note that a.resize(new_shape) will fill array with 0's\n beyond current definition of a.\n \"\"\"\n\n if isinstance(new_shape, (int, nt.integer)):\n new_shape = (new_shape,)\n a = ravel(a)\n Na = len(a)\n if not Na: return mu.zeros(new_shape, a.dtype.char)\n total_size = um.multiply.reduce(new_shape)\n n_copies = int(total_size / Na)\n extra = total_size % Na\n\n if total_size == 0:\n return a[:0]\n\n if extra != 0:\n n_copies = n_copies+1\n extra = Na-extra\n\n a = concatenate( (a,)*n_copies)\n if extra > 0:\n a = a[:-extra]\n\n return reshape(a, new_shape)\n\ndef squeeze(a):\n \"Returns a with any ones from the shape of a removed\"\n return asarray(a).squeeze()\n\ndef diagonal(a, offset=0, axis1=0, axis2=1):\n \"\"\"diagonal(a, offset=0, axis1=0, axis2=1) returns the given diagonals\n defined by the last two dimensions of the array.\n \"\"\"\n return asarray(a).diagonal(offset, axis1, axis2)\n\ndef trace(a, offset=0, axis1=0, axis2=1, dtype=None):\n \"\"\"trace(a,offset=0, axis1=0, axis2=1) returns the sum along diagonals\n (defined by the last two dimenions) of the array.\n \"\"\"\n return asarray(a).trace(offset, axis1, axis2, dtype)\n\ndef ravel(m):\n \"\"\"ravel(m) returns a 1d array corresponding to all the elements of it's\n argument.\n \"\"\"\n return asarray(m).ravel()\n\ndef nonzero(a):\n \"\"\"nonzero(a) returns the indices of the elements of a which are not zero,\n a must be 1d\n \"\"\"\n return asarray(a).nonzero()\n\ndef shape(a):\n \"\"\"shape(a) returns the shape of a (as a function call which\n also works on nested sequences).\n \"\"\"\n try:\n return a.shape\n except AttributeError:\n return asarray(a).shape\n\ndef compress(condition, m, axis=-1):\n \"\"\"compress(condition, x, axis=-1) = those elements of x corresponding \n to those elements of condition that are \"true\". condition must be the\n same size as the given dimension of x.\"\"\"\n return asarray(m).compress(condition, axis)\n\ndef clip(m, m_min, m_max):\n \"\"\"clip(m, m_min, m_max) = every entry in m that is less than m_min is\n replaced by m_min, and every entry greater than m_max is replaced by\n m_max.\n \"\"\"\n return asarray(m).clip(m_min, m_max)\n\ndef sum(x, axis=0, dtype=None):\n \"\"\"Sum the array over the given axis. The optional dtype argument\n is the data type for intermediate calculations.\n\n The default is to upcast (promote) smaller integer types to the\n platform-dependent Int. For example, on 32-bit platforms:\n\n x.dtype default sum() dtype\n ---------------------------------------------------\n bool, Int8, Int16, Int32 Int32\n\n Examples:\n >>> sum([0.5, 1.5])\n 2.0\n >>> sum([0.5, 1.5], dtype=Int32)\n 1\n >>> sum([[0, 1], [0, 5]])\n array([0, 6])\n >>> sum([[0, 1], [0, 5]], axis=1)\n array([1, 5])\n \"\"\"\n if isinstance(x, _gentype):\n return _sum_(x)\n return asarray(x).sum(axis, dtype)\n\ndef product (x, axis=0, dtype=None):\n \"\"\"Product of the array elements over the given axis.\"\"\"\n return asarray(x).prod(axis, dtype)\n\ndef sometrue (x, axis=0):\n \"\"\"Perform a logical_or over the given axis.\"\"\"\n return asarray(x).any(axis)\n\ndef alltrue (x, axis=0):\n \"\"\"Perform a logical_and over the given axis.\"\"\"\n return asarray(x).all(axis)\n\ndef any(x,axis=None):\n \"\"\"Return true if any elements of x are true: sometrue(ravel(x))\n \"\"\"\n return ravel(x).any(axis)\n\ndef all(x,axis=None):\n \"\"\"Return true if all elements of x are true: alltrue(ravel(x))\n \"\"\"\n return ravel(x).all(axis)\n\ndef cumsum (x, axis=0, dtype=None):\n \"\"\"Sum the array over the given axis.\"\"\"\n return asarray(x).cumsum(axis, dtype)\n\ndef cumproduct (x, axis=0, dtype=None):\n \"\"\"Sum the array over the given axis.\"\"\"\n return asarray(x).cumprod(axis, dtype)\n\ndef ptp(a, axis=0):\n \"\"\"Return maximum - minimum along the the given dimension\n \"\"\"\n return asarray(a).ptp(axis)\n\ndef amax(a, axis=0):\n \"\"\"Return the maximum of 'a' along dimension axis.\n \"\"\"\n return asarray(a).max(axis)\n\ndef amin(a, axis=0):\n \"\"\"Return the minimum of a along dimension axis.\n \"\"\"\n return asarray(a).min(axis)\n\ndef alen(a):\n \"\"\"Return the length of a Python object interpreted as an array\n \"\"\"\n return len(asarray(a))\n\ndef prod(a, axis=0):\n \"\"\"Return the product of the elements along the given axis\n \"\"\"\n return asarray(a).prod(axis)\n\ndef cumprod(a, axis=0):\n \"\"\"Return the cumulative product of the elments along the given axis\n \"\"\"\n return asarray(a).cumprod(axis)\n\ndef ndim(a):\n try:\n return a.ndim\n except AttributeError:\n return asarray(a).ndim\n\ndef rank (a):\n \"\"\"Get the rank of sequence a (the number of dimensions, not a matrix rank)\n The rank of a scalar is zero.\n \"\"\"\n try:\n return a.ndim\n except AttributeError:\n return asarray(a).ndim\n\ndef size (a, axis=None):\n \"Get the number of elements in sequence a, or along a certain axis.\"\n if axis is None:\n try:\n return a.size\n except AttributeError:\n return asarray(a).size\n else:\n try:\n return a.shape[axis]\n except AttributeError:\n return asarray(a).shape[axis]\n\ndef round_(a, decimals=0):\n \"\"\"Round 'a' to the given number of decimal places. Rounding\n behaviour is equivalent to Python.\n\n Return 'a' if the array is not floating point. Round both the real\n and imaginary parts separately if the array is complex.\n \"\"\"\n a = asarray(a)\n if not issubclass(a.dtype.type, _nx.inexact):\n return a\n if issubclass(a.dtype.type, _nx.complexfloating):\n return round_(a.real, decimals) + 1j*round_(a.imag, decimals)\n if decimals is not 0:\n decimals = asarray(decimals)\n s = sign(a)\n if decimals is not 0:\n a = absolute(multiply(a, 10.**decimals))\n else:\n a = absolute(a)\n rem = a-asarray(a).astype(_nx.intp)\n a = _nx.where(_nx.less(rem, 0.5), _nx.floor(a), _nx.ceil(a))\n # convert back\n if decimals is not 0:\n return multiply(a, s/(10.**decimals))\n else:\n return multiply(a, s)\n\naround = round_\n\ndef mean(a, axis=0, dtype=None):\n return asarray(a).mean(axis, dtype)\n\ndef std(a, axis=0, dtype=None):\n return asarray(a).std(axis, dtype)\n\ndef var(a, axis=0, dtype=None):\n return asarray(a).var(axis, dtype)\n", + "source_code_before": "# Compatibility module containing deprecated names\n\n__all__ = ['asarray', 'array', 'concatenate',\n 'NewAxis',\n 'UFuncType', 'UfuncType', 'ArrayType', 'arraytype',\n 'LittleEndian', 'Bool', \n 'Character', 'UnsignedInt8', 'UnsignedInt16', 'UnsignedInt',\n 'UInt8','UInt16','UInt32',\n # UnsignedInt64 and Unsigned128 added below if possible\n # same for Int64 and Int128, Float128, and Complex128\n 'Int8', 'Int16', 'Int32',\n 'Int0', 'Int', 'Float0', 'Float', 'Complex0', 'Complex',\n 'PyObject', 'Float32', 'Float64',\n 'Complex32', 'Complex64',\n 'typecodes', 'sarray', 'arrayrange', 'cross_correlate',\n 'matrixmultiply', 'outerproduct', 'innerproduct',\n # from cPickle\n 'dump', 'dumps',\n # functions that are now methods\n 'take', 'reshape', 'choose', 'repeat', 'put', 'putmask',\n 'swapaxes', 'transpose', 'sort', 'argsort', 'argmax', 'argmin',\n 'searchsorted', 'alen', \n 'resize', 'diagonal', 'trace', 'ravel', 'nonzero', 'shape',\n 'compress', 'clip', 'sum', 'product', 'prod', 'sometrue', 'alltrue',\n 'any', 'all', 'cumsum', 'cumproduct', 'cumprod', 'ptp', 'ndim',\n 'rank', 'size', 'around', 'round_', 'mean', 'std', 'var', 'squeeze',\n 'amax', 'amin',\n ]\n\nimport multiarray as mu\nimport umath as um\nimport numerictypes as nt\nfrom numeric import asarray, array, correlate, outer, concatenate\nfrom umath import sign, absolute, multiply\nimport numeric as _nx\nimport sys\n_dt_ = nt.arrtype2char\n\nimport types\n\ntry:\n _gentype = types.GeneratorType\nexcept AttributeError:\n _gentype = types.NoneType\n#Use this to add a new axis to an array\n#compatibility only\nNewAxis = None\n\n#deprecated\nUFuncType = type(um.sin)\nUfuncType = type(um.sin)\nArrayType = mu.ndarray\narraytype = mu.ndarray\n\nLittleEndian = (sys.byteorder == 'little')\n\n# save away Python sum\n_sum_ = sum\n\n# backward compatible names from old Precision.py\n\nCharacter = 'S1'\nUnsignedInt8 = _dt_(nt.uint8)\nUInt8 = UnsignedInt8\nUnsignedInt16 = _dt_(nt.uint16)\nUInt16 = UnsignedInt16\nUnsignedInt32 = _dt_(nt.uint32)\nUInt32 = UnsignedInt32\nUnsignedInt = _dt_(nt.uint)\n\ntry:\n UnsignedInt64 = _dt_(nt.uint64)\nexcept AttributeError:\n pass\nelse:\n UInt64 = UnsignedInt64\n __all__ += ['UnsignedInt64', 'UInt64']\ntry:\n UnsignedInt128 = _dt_(nt.uint128)\nexcept AttributeError:\n pass\nelse:\n UInt128 = UnsignedInt128\n __all__ += ['UnsignedInt128','UInt128']\n\nInt8 = _dt_(nt.int8)\nInt16 = _dt_(nt.int16)\nInt32 = _dt_(nt.int32)\n\ntry:\n Int64 = _dt_(nt.int64)\nexcept AttributeError:\n pass\nelse:\n __all__ += ['Int64']\n\ntry:\n Int128 = _dt_(nt.int128)\nexcept AttributeError:\n pass\nelse:\n __all__ += ['Int128']\n\nBool = _dt_(bool)\nInt0 = _dt_(int)\nInt = _dt_(int)\nFloat0 = _dt_(float)\nFloat = _dt_(float)\nComplex0 = _dt_(complex)\nComplex = _dt_(complex)\nPyObject = _dt_(nt.object_)\nFloat32 = _dt_(nt.float32)\nFloat64 = _dt_(nt.float64)\n\ntry:\n Float128 = _dt_(nt.float128)\nexcept AttributeError:\n pass\nelse:\n __all__ += ['Float128']\n\nComplex32 = _dt_(nt.complex64)\nComplex64 = _dt_(nt.complex128)\n\ntry:\n Complex128 = _dt_(nt.complex256)\nexcept AttributeError:\n pass\nelse:\n __all__ += ['Complex128']\n\ntypecodes = {'Character':'S1',\n 'Integer':'bhilqp',\n 'UnsignedInteger':'BHILQP',\n 'Float':'fdg',\n 'Complex':'FDG',\n 'AllInteger':'bBhHiIlLqQpP',\n 'AllFloat':'fdgFDG',\n 'All':'?bhilqpBHILQPfdgFDGSUVO'}\n\ndef sarray(a, dtype=None, copy=False):\n return array(a, dtype, copy)\n\n# backward compatibility\narrayrange = mu.arange\ncross_correlate = correlate\n\n# deprecated names\nmatrixmultiply = mu.dot\nouterproduct = outer\ninnerproduct = mu.inner\n\nfrom cPickle import dump, dumps\n\n# functions that are now methods\n\ndef take(a, indices, axis=0):\n a = asarray(a)\n return a.take(indices, axis)\n\ndef reshape(a, newshape):\n \"\"\"Change the shape of a to newshape. Return a new view object.\n \"\"\"\n return asarray(a).reshape(newshape)\n\ndef choose(a, choices):\n a = asarray(a)\n return a.choose(choices)\n\ndef repeat(a, repeats, axis=0):\n \"\"\"repeat elements of a repeats times along axis\n repeats is a sequence of length a.shape[axis]\n telling how many times to repeat each element.\n If repeats is an integer, it is interpreted as\n a tuple of length a.shape[axis] containing repeats.\n The argument a can be anything array(a) will accept.\n \"\"\"\n a = array(a, copy=False)\n return a.repeat(repeats, axis)\n\ndef put (a, ind, v):\n \"\"\"put(a, ind, v) results in a[n] = v[n] for all n in ind\n If v is shorter than mask it will be repeated as necessary.\n In particular v can be a scalar or length 1 array.\n The routine put is the equivalent of the following (although the loop\n is in C for speed):\n\n ind = array(indices, copy=False)\n v = array(values, copy=False).astype(a, a.dtype)\n for i in ind: a.flat[i] = v[i]\n a must be a contiguous Numeric array.\n \"\"\"\n return a.put(v,ind)\n\ndef putmask (a, mask, v):\n \"\"\"putmask(a, mask, v) results in a = v for all places mask is true.\n If v is shorter than mask it will be repeated as necessary.\n In particular v can be a scalar or length 1 array.\n \"\"\"\n return a.putmask(v, mask)\n\ndef swapaxes(a, axis1, axis2):\n \"\"\"swapaxes(a, axis1, axis2) returns array a with axis1 and axis2\n interchanged.\n \"\"\"\n a = array(a, copy=False)\n return a.swapaxes(axis1, axis2)\n\ndef transpose(a, axes=None):\n \"\"\"transpose(a, axes=None) returns array with dimensions permuted\n according to axes. If axes is None (default) returns array with\n dimensions reversed.\n \"\"\"\n a = array(a,copy=False)\n return a.transpose(axes)\n\ndef sort(a, axis=-1):\n \"\"\"sort(a,axis=-1) returns array with elements sorted along given axis.\n \"\"\"\n a = array(a, copy=True)\n a.sort(axis)\n return a\n\ndef argsort(a, axis=-1):\n \"\"\"argsort(a,axis=-1) return the indices into a of the sorted array\n along the given axis, so that take(a,result,axis) is the sorted array.\n \"\"\"\n a = array(a, copy=False)\n return a.argsort(axis)\n\ndef argmax(a, axis=-1):\n \"\"\"argmax(a,axis=-1) returns the indices to the maximum value of the\n 1-D arrays along the given axis.\n \"\"\"\n a = array(a, copy=False)\n return a.argmax(axis)\n\ndef argmin(a, axis=-1):\n \"\"\"argmin(a,axis=-1) returns the indices to the minimum value of the\n 1-D arrays along the given axis.\n \"\"\"\n a = array(a,copy=False)\n return a.argmin(axis)\n\ndef searchsorted(a, v):\n \"\"\"searchsorted(a, v)\n \"\"\"\n a = array(a,copy=False)\n return a.searchsorted(v)\n\ndef resize(a, new_shape):\n \"\"\"resize(a,new_shape) returns a new array with the specified shape.\n The original array's total size can be any size. It\n fills the new array with repeated copies of a.\n\n Note that a.resize(new_shape) will fill array with 0's\n beyond current definition of a.\n \"\"\"\n\n if isinstance(new_shape, (int, nt.integer)):\n new_shape = (new_shape,)\n a = ravel(a)\n Na = len(a)\n if not Na: return mu.zeros(new_shape, a.dtype.char)\n total_size = um.multiply.reduce(new_shape)\n n_copies = int(total_size / Na)\n extra = total_size % Na\n\n if total_size == 0:\n return a[:0]\n\n if extra != 0:\n n_copies = n_copies+1\n extra = Na-extra\n\n a = concatenate( (a,)*n_copies)\n if extra > 0:\n a = a[:-extra]\n\n return reshape(a, new_shape)\n\ndef squeeze(a):\n \"Returns a with any ones from the shape of a removed\"\n return asarray(a).squeeze()\n\ndef diagonal(a, offset=0, axis1=0, axis2=1):\n \"\"\"diagonal(a, offset=0, axis1=0, axis2=1) returns the given diagonals\n defined by the last two dimensions of the array.\n \"\"\"\n return asarray(a).diagonal(offset, axis1, axis2)\n\ndef trace(a, offset=0, axis1=0, axis2=1, dtype=None):\n \"\"\"trace(a,offset=0, axis1=0, axis2=1) returns the sum along diagonals\n (defined by the last two dimenions) of the array.\n \"\"\"\n return asarray(a).trace(offset, axis1, axis2, dtype)\n\ndef ravel(m):\n \"\"\"ravel(m) returns a 1d array corresponding to all the elements of it's\n argument.\n \"\"\"\n return asarray(m).ravel()\n\ndef nonzero(a):\n \"\"\"nonzero(a) returns the indices of the elements of a which are not zero,\n a must be 1d\n \"\"\"\n return asarray(a).nonzero()\n\ndef shape(a):\n \"\"\"shape(a) returns the shape of a (as a function call which\n also works on nested sequences).\n \"\"\"\n try:\n return a.shape\n except AttributeError:\n return asarray(a).shape\n\ndef compress(condition, m, axis=-1):\n \"\"\"compress(condition, x, axis=-1) = those elements of x corresponding \n to those elements of condition that are \"true\". condition must be the\n same size as the given dimension of x.\"\"\"\n return asarray(m).compress(condition, axis)\n\ndef clip(m, m_min, m_max):\n \"\"\"clip(m, m_min, m_max) = every entry in m that is less than m_min is\n replaced by m_min, and every entry greater than m_max is replaced by\n m_max.\n \"\"\"\n return asarray(m).clip(m_min, m_max)\n\ndef sum(x, axis=0, dtype=None):\n \"\"\"Sum the array over the given axis. The optional dtype argument\n is the data type for intermediate calculations.\n\n The default is to upcast (promote) smaller integer types to the\n platform-dependent Int. For example, on 32-bit platforms:\n\n x.dtype default sum() dtype\n ---------------------------------------------------\n bool, Int8, Int16, Int32 Int32\n\n Examples:\n >>> sum([0.5, 1.5])\n 2.0\n >>> sum([0.5, 1.5], dtype=Int32)\n 1\n >>> sum([[0, 1], [0, 5]])\n array([0, 6])\n >>> sum([[0, 1], [0, 5]], axis=1)\n array([1, 5])\n \"\"\"\n if isinstance(x, _gentype):\n return _sum_(x)\n return asarray(x).sum(axis, dtype)\n\ndef product (x, axis=0, dtype=None):\n \"\"\"Product of the array elements over the given axis.\"\"\"\n return asarray(x).prod(axis, dtype)\n\ndef sometrue (x, axis=0):\n \"\"\"Perform a logical_or over the given axis.\"\"\"\n return asarray(x).any(axis)\n\ndef alltrue (x, axis=0):\n \"\"\"Perform a logical_and over the given axis.\"\"\"\n return asarray(x).all(axis)\n\ndef any(x,axis=None):\n \"\"\"Return true if any elements of x are true: sometrue(ravel(x))\n \"\"\"\n return ravel(x).any(axis)\n\ndef all(x,axis=None):\n \"\"\"Return true if all elements of x are true: alltrue(ravel(x))\n \"\"\"\n return ravel(x).all(axis)\n\ndef cumsum (x, axis=0, dtype=None):\n \"\"\"Sum the array over the given axis.\"\"\"\n return asarray(x).cumsum(axis, dtype)\n\ndef cumproduct (x, axis=0, dtype=None):\n \"\"\"Sum the array over the given axis.\"\"\"\n return asarray(x).cumprod(axis, dtype)\n\ndef ptp(a, axis=0):\n \"\"\"Return maximum - minimum along the the given dimension\n \"\"\"\n return asarray(a).ptp(axis)\n\ndef amax(a, axis=0):\n \"\"\"Return the maximum of 'a' along dimension axis.\n \"\"\"\n return asarray(a).max(axis)\n\ndef amin(a, axis=0):\n \"\"\"Return the minimum of a along dimension axis.\n \"\"\"\n return asarray(a).min(axis)\n\ndef alen(a):\n \"\"\"Return the length of a Python object interpreted as an array\n \"\"\"\n return len(asarray(a))\n\ndef prod(a, axis=0):\n \"\"\"Return the product of the elements along the given axis\n \"\"\"\n return asarray(a).prod(axis)\n\ndef cumprod(a, axis=0):\n \"\"\"Return the cumulative product of the elments along the given axis\n \"\"\"\n return asarray(a).cumprod(axis)\n\ndef ndim(a):\n try:\n return a.ndim\n except AttributeError:\n return asarray(a).ndim\n\ndef rank (a):\n \"\"\"Get the rank of sequence a (the number of dimensions, not a matrix rank)\n The rank of a scalar is zero.\n \"\"\"\n try:\n return a.ndim\n except AttributeError:\n return asarray(a).ndim\n\ndef size (a, axis=None):\n \"Get the number of elements in sequence a, or along a certain axis.\"\n if axis is None:\n try:\n return a.size\n except AttributeError:\n return asarray(a).size\n else:\n try:\n return a.shape[axis]\n except AttributeError:\n return asarray(a).shape[axis]\n\ndef round_(a, decimals=0):\n \"\"\"Round 'a' to the given number of decimal places. Rounding\n behaviour is equivalent to Python.\n\n Return 'a' if the array is not floating point. Round both the real\n and imaginary parts separately if the array is complex.\n \"\"\"\n a = asarray(a)\n if not issubclass(a.dtype.type, _nx.inexact):\n return a\n if issubclass(a.dtype.type, _nx.complexfloating):\n return round_(a.real, decimals) + 1j*round_(a.imag, decimals)\n if decimals is not 0:\n decimals = asarray(decimals)\n s = sign(a)\n if decimals is not 0:\n a = absolute(multiply(a, 10.**decimals))\n else:\n a = absolute(a)\n rem = a-asarray(a).astype(_nx.intp)\n a = _nx.where(_nx.less(rem, 0.5), _nx.floor(a), _nx.ceil(a))\n # convert back\n if decimals is not 0:\n return multiply(a, s/(10.**decimals))\n else:\n return multiply(a, s)\n\naround = round_\n\ndef mean(a, axis=0, dtype=None):\n return asarray(a).mean(axis, dtype)\n\ndef std(a, axis=0, dtype=None):\n return asarray(a).std(axis, dtype)\n\ndef var(a, axis=0, dtype=None):\n return asarray(a).var(axis, dtype)\n", + "methods": [ + { + "name": "sarray", + "long_name": "sarray( a , dtype = None , copy = False )", + "filename": "oldnumeric.py", + "nloc": 2, + "complexity": 1, + "token_count": 22, + "parameters": [ + "a", + "dtype", + "copy" + ], + "start_line": 141, + "end_line": 142, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 2, + "top_nesting_level": 0 + }, + { + "name": "take", + "long_name": "take( a , indices , axis = 0 )", + "filename": "oldnumeric.py", + "nloc": 3, + "complexity": 1, + "token_count": 26, + "parameters": [ + "a", + "indices", + "axis" + ], + "start_line": 157, + "end_line": 159, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 3, + "top_nesting_level": 0 + }, + { + "name": "reshape", + "long_name": "reshape( a , newshape )", + "filename": "oldnumeric.py", + "nloc": 2, + "complexity": 1, + "token_count": 18, + "parameters": [ + "a", + "newshape" + ], + "start_line": 161, + "end_line": 164, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 4, + "top_nesting_level": 0 + }, + { + "name": "choose", + "long_name": "choose( a , choices )", + "filename": "oldnumeric.py", + "nloc": 3, + "complexity": 1, + "token_count": 20, + "parameters": [ + "a", + "choices" + ], + "start_line": 166, + "end_line": 168, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 3, + "top_nesting_level": 0 + }, + { + "name": "repeat", + "long_name": "repeat( a , repeats , axis = 0 )", + "filename": "oldnumeric.py", + "nloc": 3, + "complexity": 1, + "token_count": 31, + "parameters": [ + "a", + "repeats", + "axis" + ], + "start_line": 170, + "end_line": 179, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 10, + "top_nesting_level": 0 + }, + { + "name": "put", + "long_name": "put( a , ind , v )", + "filename": "oldnumeric.py", + "nloc": 2, + "complexity": 1, + "token_count": 19, + "parameters": [ + "a", + "ind", + "v" + ], + "start_line": 181, + "end_line": 193, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 13, + "top_nesting_level": 0 + }, + { + "name": "putmask", + "long_name": "putmask( a , mask , v )", + "filename": "oldnumeric.py", + "nloc": 2, + "complexity": 1, + "token_count": 19, + "parameters": [ + "a", + "mask", + "v" + ], + "start_line": 195, + "end_line": 200, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 6, + "top_nesting_level": 0 + }, + { + "name": "swapaxes", + "long_name": "swapaxes( a , axis1 , axis2 )", + "filename": "oldnumeric.py", + "nloc": 3, + "complexity": 1, + "token_count": 29, + "parameters": [ + "a", + "axis1", + "axis2" + ], + "start_line": 202, + "end_line": 207, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 6, + "top_nesting_level": 0 + }, + { + "name": "transpose", + "long_name": "transpose( a , axes = None )", + "filename": "oldnumeric.py", + "nloc": 3, + "complexity": 1, + "token_count": 27, + "parameters": [ + "a", + "axes" + ], + "start_line": 209, + "end_line": 215, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 7, + "top_nesting_level": 0 + }, + { + "name": "sort", + "long_name": "sort( a , axis = - 1 )", + "filename": "oldnumeric.py", + "nloc": 4, + "complexity": 1, + "token_count": 29, + "parameters": [ + "a", + "axis" + ], + "start_line": 217, + "end_line": 222, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 6, + "top_nesting_level": 0 + }, + { + "name": "argsort", + "long_name": "argsort( a , axis = - 1 )", + "filename": "oldnumeric.py", + "nloc": 3, + "complexity": 1, + "token_count": 28, + "parameters": [ + "a", + "axis" + ], + "start_line": 224, + "end_line": 229, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 6, + "top_nesting_level": 0 + }, + { + "name": "argmax", + "long_name": "argmax( a , axis = - 1 )", + "filename": "oldnumeric.py", + "nloc": 3, + "complexity": 1, + "token_count": 28, + "parameters": [ + "a", + "axis" + ], + "start_line": 231, + "end_line": 236, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 6, + "top_nesting_level": 0 + }, + { + "name": "argmin", + "long_name": "argmin( a , axis = - 1 )", + "filename": "oldnumeric.py", + "nloc": 3, + "complexity": 1, + "token_count": 28, + "parameters": [ + "a", + "axis" + ], + "start_line": 238, + "end_line": 243, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 6, + "top_nesting_level": 0 + }, + { + "name": "searchsorted", + "long_name": "searchsorted( a , v )", + "filename": "oldnumeric.py", + "nloc": 3, + "complexity": 1, + "token_count": 25, + "parameters": [ + "a", + "v" + ], + "start_line": 245, + "end_line": 249, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 5, + "top_nesting_level": 0 + }, + { + "name": "resize", + "long_name": "resize( a , new_shape )", + "filename": "oldnumeric.py", + "nloc": 18, + "complexity": 6, + "token_count": 137, + "parameters": [ + "a", + "new_shape" + ], + "start_line": 251, + "end_line": 280, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 30, + "top_nesting_level": 0 + }, + { + "name": "squeeze", + "long_name": "squeeze( a )", + "filename": "oldnumeric.py", + "nloc": 3, + "complexity": 1, + "token_count": 15, + "parameters": [ + "a" + ], + "start_line": 282, + "end_line": 284, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 3, + "top_nesting_level": 0 + }, + { + "name": "diagonal", + "long_name": "diagonal( a , offset = 0 , axis1 = 0 , axis2 = 1 )", + "filename": "oldnumeric.py", + "nloc": 2, + "complexity": 1, + "token_count": 32, + "parameters": [ + "a", + "offset", + "axis1", + "axis2" + ], + "start_line": 286, + "end_line": 290, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 5, + "top_nesting_level": 0 + }, + { + "name": "trace", + "long_name": "trace( a , offset = 0 , axis1 = 0 , axis2 = 1 , dtype = None )", + "filename": "oldnumeric.py", + "nloc": 2, + "complexity": 1, + "token_count": 38, + "parameters": [ + "a", + "offset", + "axis1", + "axis2", + "dtype" + ], + "start_line": 292, + "end_line": 296, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 5, + "top_nesting_level": 0 + }, + { + "name": "ravel", + "long_name": "ravel( m )", + "filename": "oldnumeric.py", + "nloc": 2, + "complexity": 1, + "token_count": 15, + "parameters": [ + "m" + ], + "start_line": 298, + "end_line": 302, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 5, + "top_nesting_level": 0 + }, + { + "name": "nonzero", + "long_name": "nonzero( a )", + "filename": "oldnumeric.py", + "nloc": 2, + "complexity": 1, + "token_count": 15, + "parameters": [ + "a" + ], + "start_line": 304, + "end_line": 308, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 5, + "top_nesting_level": 0 + }, + { + "name": "shape", + "long_name": "shape( a )", + "filename": "oldnumeric.py", + "nloc": 5, + "complexity": 2, + "token_count": 22, + "parameters": [ + "a" + ], + "start_line": 310, + "end_line": 317, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 8, + "top_nesting_level": 0 + }, + { + "name": "compress", + "long_name": "compress( condition , m , axis = - 1 )", + "filename": "oldnumeric.py", + "nloc": 2, + "complexity": 1, + "token_count": 25, + "parameters": [ + "condition", + "m", + "axis" + ], + "start_line": 319, + "end_line": 323, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 5, + "top_nesting_level": 0 + }, + { + "name": "clip", + "long_name": "clip( m , m_min , m_max )", + "filename": "oldnumeric.py", + "nloc": 2, + "complexity": 1, + "token_count": 22, + "parameters": [ + "m", + "m_min", + "m_max" + ], + "start_line": 325, + "end_line": 330, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 6, + "top_nesting_level": 0 + }, + { + "name": "sum", + "long_name": "sum( x , axis = 0 , dtype = None )", + "filename": "oldnumeric.py", + "nloc": 4, + "complexity": 2, + "token_count": 39, + "parameters": [ + "x", + "axis", + "dtype" + ], + "start_line": 332, + "end_line": 355, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 24, + "top_nesting_level": 0 + }, + { + "name": "product", + "long_name": "product( x , axis = 0 , dtype = None )", + "filename": "oldnumeric.py", + "nloc": 2, + "complexity": 1, + "token_count": 26, + "parameters": [ + "x", + "axis", + "dtype" + ], + "start_line": 357, + "end_line": 359, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 3, + "top_nesting_level": 0 + }, + { + "name": "sometrue", + "long_name": "sometrue( x , axis = 0 )", + "filename": "oldnumeric.py", + "nloc": 2, + "complexity": 1, + "token_count": 20, + "parameters": [ + "x", + "axis" + ], + "start_line": 361, + "end_line": 363, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 3, + "top_nesting_level": 0 + }, + { + "name": "alltrue", + "long_name": "alltrue( x , axis = 0 )", + "filename": "oldnumeric.py", + "nloc": 2, + "complexity": 1, + "token_count": 20, + "parameters": [ + "x", + "axis" + ], + "start_line": 365, + "end_line": 367, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 3, + "top_nesting_level": 0 + }, + { + "name": "any", + "long_name": "any( x , axis = None )", + "filename": "oldnumeric.py", + "nloc": 2, + "complexity": 1, + "token_count": 20, + "parameters": [ + "x", + "axis" + ], + "start_line": 369, + "end_line": 372, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 4, + "top_nesting_level": 0 + }, + { + "name": "all", + "long_name": "all( x , axis = None )", + "filename": "oldnumeric.py", + "nloc": 2, + "complexity": 1, + "token_count": 20, + "parameters": [ + "x", + "axis" + ], + "start_line": 374, + "end_line": 377, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 4, + "top_nesting_level": 0 + }, + { + "name": "cumsum", + "long_name": "cumsum( x , axis = 0 , dtype = None )", + "filename": "oldnumeric.py", + "nloc": 2, + "complexity": 1, + "token_count": 26, + "parameters": [ + "x", + "axis", + "dtype" + ], + "start_line": 379, + "end_line": 381, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 3, + "top_nesting_level": 0 + }, + { + "name": "cumproduct", + "long_name": "cumproduct( x , axis = 0 , dtype = None )", + "filename": "oldnumeric.py", + "nloc": 2, + "complexity": 1, + "token_count": 26, + "parameters": [ + "x", + "axis", + "dtype" + ], + "start_line": 383, + "end_line": 385, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 3, + "top_nesting_level": 0 + }, + { + "name": "ptp", + "long_name": "ptp( a , axis = 0 )", + "filename": "oldnumeric.py", + "nloc": 2, + "complexity": 1, + "token_count": 20, + "parameters": [ + "a", + "axis" + ], + "start_line": 387, + "end_line": 390, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 4, + "top_nesting_level": 0 + }, + { + "name": "amax", + "long_name": "amax( a , axis = 0 )", + "filename": "oldnumeric.py", + "nloc": 2, + "complexity": 1, + "token_count": 20, + "parameters": [ + "a", + "axis" + ], + "start_line": 392, + "end_line": 395, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 4, + "top_nesting_level": 0 + }, + { + "name": "amin", + "long_name": "amin( a , axis = 0 )", + "filename": "oldnumeric.py", + "nloc": 2, + "complexity": 1, + "token_count": 20, + "parameters": [ + "a", + "axis" + ], + "start_line": 397, + "end_line": 400, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 4, + "top_nesting_level": 0 + }, + { + "name": "alen", + "long_name": "alen( a )", + "filename": "oldnumeric.py", + "nloc": 2, + "complexity": 1, + "token_count": 14, + "parameters": [ + "a" + ], + "start_line": 402, + "end_line": 405, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 4, + "top_nesting_level": 0 + }, + { + "name": "prod", + "long_name": "prod( a , axis = 0 )", + "filename": "oldnumeric.py", + "nloc": 2, + "complexity": 1, + "token_count": 20, + "parameters": [ + "a", + "axis" + ], + "start_line": 407, + "end_line": 410, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 4, + "top_nesting_level": 0 + }, + { + "name": "cumprod", + "long_name": "cumprod( a , axis = 0 )", + "filename": "oldnumeric.py", + "nloc": 2, + "complexity": 1, + "token_count": 20, + "parameters": [ + "a", + "axis" + ], + "start_line": 412, + "end_line": 415, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 4, + "top_nesting_level": 0 + }, + { + "name": "ndim", + "long_name": "ndim( a )", + "filename": "oldnumeric.py", + "nloc": 5, + "complexity": 2, + "token_count": 21, + "parameters": [ + "a" + ], + "start_line": 417, + "end_line": 421, + "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": 423, + "end_line": 430, + "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": 432, + "end_line": 443, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 12, + "top_nesting_level": 0 + }, + { + "name": "round_", + "long_name": "round_( a , decimals = 0 )", + "filename": "oldnumeric.py", + "nloc": 19, + "complexity": 6, + "token_count": 188, + "parameters": [ + "a", + "decimals" + ], + "start_line": 445, + "end_line": 470, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 26, + "top_nesting_level": 0 + }, + { + "name": "mean", + "long_name": "mean( a , axis = 0 , dtype = None )", + "filename": "oldnumeric.py", + "nloc": 2, + "complexity": 1, + "token_count": 25, + "parameters": [ + "a", + "axis", + "dtype" + ], + "start_line": 474, + "end_line": 475, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 2, + "top_nesting_level": 0 + }, + { + "name": "std", + "long_name": "std( a , axis = 0 , dtype = None )", + "filename": "oldnumeric.py", + "nloc": 2, + "complexity": 1, + "token_count": 25, + "parameters": [ + "a", + "axis", + "dtype" + ], + "start_line": 477, + "end_line": 478, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 2, + "top_nesting_level": 0 + }, + { + "name": "var", + "long_name": "var( a , axis = 0 , dtype = None )", + "filename": "oldnumeric.py", + "nloc": 2, + "complexity": 1, + "token_count": 25, + "parameters": [ + "a", + "axis", + "dtype" + ], + "start_line": 480, + "end_line": 481, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 2, + "top_nesting_level": 0 + } + ], + "methods_before": [ + { + "name": "sarray", + "long_name": "sarray( a , dtype = None , copy = False )", + "filename": "oldnumeric.py", + "nloc": 2, + "complexity": 1, + "token_count": 22, + "parameters": [ + "a", + "dtype", + "copy" + ], + "start_line": 141, + "end_line": 142, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 2, + "top_nesting_level": 0 + }, + { + "name": "take", + "long_name": "take( a , indices , axis = 0 )", + "filename": "oldnumeric.py", + "nloc": 3, + "complexity": 1, + "token_count": 26, + "parameters": [ + "a", + "indices", + "axis" + ], + "start_line": 157, + "end_line": 159, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 3, + "top_nesting_level": 0 + }, + { + "name": "reshape", + "long_name": "reshape( a , newshape )", + "filename": "oldnumeric.py", + "nloc": 2, + "complexity": 1, + "token_count": 18, + "parameters": [ + "a", + "newshape" + ], + "start_line": 161, + "end_line": 164, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 4, + "top_nesting_level": 0 + }, + { + "name": "choose", + "long_name": "choose( a , choices )", + "filename": "oldnumeric.py", + "nloc": 3, + "complexity": 1, + "token_count": 20, + "parameters": [ + "a", + "choices" + ], + "start_line": 166, + "end_line": 168, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 3, + "top_nesting_level": 0 + }, + { + "name": "repeat", + "long_name": "repeat( a , repeats , axis = 0 )", + "filename": "oldnumeric.py", + "nloc": 3, + "complexity": 1, + "token_count": 31, + "parameters": [ + "a", + "repeats", + "axis" + ], + "start_line": 170, + "end_line": 179, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 10, + "top_nesting_level": 0 + }, + { + "name": "put", + "long_name": "put( a , ind , v )", + "filename": "oldnumeric.py", + "nloc": 2, + "complexity": 1, + "token_count": 19, + "parameters": [ + "a", + "ind", + "v" + ], + "start_line": 181, + "end_line": 193, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 13, + "top_nesting_level": 0 + }, + { + "name": "putmask", + "long_name": "putmask( a , mask , v )", + "filename": "oldnumeric.py", + "nloc": 2, + "complexity": 1, + "token_count": 19, + "parameters": [ + "a", + "mask", + "v" + ], + "start_line": 195, + "end_line": 200, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 6, + "top_nesting_level": 0 + }, + { + "name": "swapaxes", + "long_name": "swapaxes( a , axis1 , axis2 )", + "filename": "oldnumeric.py", + "nloc": 3, + "complexity": 1, + "token_count": 29, + "parameters": [ + "a", + "axis1", + "axis2" + ], + "start_line": 202, + "end_line": 207, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 6, + "top_nesting_level": 0 + }, + { + "name": "transpose", + "long_name": "transpose( a , axes = None )", + "filename": "oldnumeric.py", + "nloc": 3, + "complexity": 1, + "token_count": 27, + "parameters": [ + "a", + "axes" + ], + "start_line": 209, + "end_line": 215, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 7, + "top_nesting_level": 0 + }, + { + "name": "sort", + "long_name": "sort( a , axis = - 1 )", + "filename": "oldnumeric.py", + "nloc": 4, + "complexity": 1, + "token_count": 29, + "parameters": [ + "a", + "axis" + ], + "start_line": 217, + "end_line": 222, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 6, + "top_nesting_level": 0 + }, + { + "name": "argsort", + "long_name": "argsort( a , axis = - 1 )", + "filename": "oldnumeric.py", + "nloc": 3, + "complexity": 1, + "token_count": 28, + "parameters": [ + "a", + "axis" + ], + "start_line": 224, + "end_line": 229, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 6, + "top_nesting_level": 0 + }, + { + "name": "argmax", + "long_name": "argmax( a , axis = - 1 )", + "filename": "oldnumeric.py", + "nloc": 3, + "complexity": 1, + "token_count": 28, + "parameters": [ + "a", + "axis" + ], + "start_line": 231, + "end_line": 236, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 6, + "top_nesting_level": 0 + }, + { + "name": "argmin", + "long_name": "argmin( a , axis = - 1 )", + "filename": "oldnumeric.py", + "nloc": 3, + "complexity": 1, + "token_count": 28, + "parameters": [ + "a", + "axis" + ], + "start_line": 238, + "end_line": 243, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 6, + "top_nesting_level": 0 + }, + { + "name": "searchsorted", + "long_name": "searchsorted( a , v )", + "filename": "oldnumeric.py", + "nloc": 3, + "complexity": 1, + "token_count": 25, + "parameters": [ + "a", + "v" + ], + "start_line": 245, + "end_line": 249, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 5, + "top_nesting_level": 0 + }, + { + "name": "resize", + "long_name": "resize( a , new_shape )", + "filename": "oldnumeric.py", + "nloc": 18, + "complexity": 6, + "token_count": 137, + "parameters": [ + "a", + "new_shape" + ], + "start_line": 251, + "end_line": 280, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 30, + "top_nesting_level": 0 + }, + { + "name": "squeeze", + "long_name": "squeeze( a )", + "filename": "oldnumeric.py", + "nloc": 3, + "complexity": 1, + "token_count": 15, + "parameters": [ + "a" + ], + "start_line": 282, + "end_line": 284, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 3, + "top_nesting_level": 0 + }, + { + "name": "diagonal", + "long_name": "diagonal( a , offset = 0 , axis1 = 0 , axis2 = 1 )", + "filename": "oldnumeric.py", + "nloc": 2, + "complexity": 1, + "token_count": 32, + "parameters": [ + "a", + "offset", + "axis1", + "axis2" + ], + "start_line": 286, + "end_line": 290, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 5, + "top_nesting_level": 0 + }, + { + "name": "trace", + "long_name": "trace( a , offset = 0 , axis1 = 0 , axis2 = 1 , dtype = None )", + "filename": "oldnumeric.py", + "nloc": 2, + "complexity": 1, + "token_count": 38, + "parameters": [ + "a", + "offset", + "axis1", + "axis2", + "dtype" + ], + "start_line": 292, + "end_line": 296, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 5, + "top_nesting_level": 0 + }, + { + "name": "ravel", + "long_name": "ravel( m )", + "filename": "oldnumeric.py", + "nloc": 2, + "complexity": 1, + "token_count": 15, + "parameters": [ + "m" + ], + "start_line": 298, + "end_line": 302, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 5, + "top_nesting_level": 0 + }, + { + "name": "nonzero", + "long_name": "nonzero( a )", + "filename": "oldnumeric.py", + "nloc": 2, + "complexity": 1, + "token_count": 15, + "parameters": [ + "a" + ], + "start_line": 304, + "end_line": 308, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 5, + "top_nesting_level": 0 + }, + { + "name": "shape", + "long_name": "shape( a )", + "filename": "oldnumeric.py", + "nloc": 5, + "complexity": 2, + "token_count": 22, + "parameters": [ + "a" + ], + "start_line": 310, + "end_line": 317, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 8, + "top_nesting_level": 0 + }, + { + "name": "compress", + "long_name": "compress( condition , m , axis = - 1 )", + "filename": "oldnumeric.py", + "nloc": 2, + "complexity": 1, + "token_count": 25, + "parameters": [ + "condition", + "m", + "axis" + ], + "start_line": 319, + "end_line": 323, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 5, + "top_nesting_level": 0 + }, + { + "name": "clip", + "long_name": "clip( m , m_min , m_max )", + "filename": "oldnumeric.py", + "nloc": 2, + "complexity": 1, + "token_count": 22, + "parameters": [ + "m", + "m_min", + "m_max" + ], + "start_line": 325, + "end_line": 330, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 6, + "top_nesting_level": 0 + }, + { + "name": "sum", + "long_name": "sum( x , axis = 0 , dtype = None )", + "filename": "oldnumeric.py", + "nloc": 4, + "complexity": 2, + "token_count": 39, + "parameters": [ + "x", + "axis", + "dtype" + ], + "start_line": 332, + "end_line": 355, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 24, + "top_nesting_level": 0 + }, + { + "name": "product", + "long_name": "product( x , axis = 0 , dtype = None )", + "filename": "oldnumeric.py", + "nloc": 2, + "complexity": 1, + "token_count": 26, + "parameters": [ + "x", + "axis", + "dtype" + ], + "start_line": 357, + "end_line": 359, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 3, + "top_nesting_level": 0 + }, + { + "name": "sometrue", + "long_name": "sometrue( x , axis = 0 )", + "filename": "oldnumeric.py", + "nloc": 2, + "complexity": 1, + "token_count": 20, + "parameters": [ + "x", + "axis" + ], + "start_line": 361, + "end_line": 363, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 3, + "top_nesting_level": 0 + }, + { + "name": "alltrue", + "long_name": "alltrue( x , axis = 0 )", + "filename": "oldnumeric.py", + "nloc": 2, + "complexity": 1, + "token_count": 20, + "parameters": [ + "x", + "axis" + ], + "start_line": 365, + "end_line": 367, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 3, + "top_nesting_level": 0 + }, + { + "name": "any", + "long_name": "any( x , axis = None )", + "filename": "oldnumeric.py", + "nloc": 2, + "complexity": 1, + "token_count": 20, + "parameters": [ + "x", + "axis" + ], + "start_line": 369, + "end_line": 372, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 4, + "top_nesting_level": 0 + }, + { + "name": "all", + "long_name": "all( x , axis = None )", + "filename": "oldnumeric.py", + "nloc": 2, + "complexity": 1, + "token_count": 20, + "parameters": [ + "x", + "axis" + ], + "start_line": 374, + "end_line": 377, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 4, + "top_nesting_level": 0 + }, + { + "name": "cumsum", + "long_name": "cumsum( x , axis = 0 , dtype = None )", + "filename": "oldnumeric.py", + "nloc": 2, + "complexity": 1, + "token_count": 26, + "parameters": [ + "x", + "axis", + "dtype" + ], + "start_line": 379, + "end_line": 381, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 3, + "top_nesting_level": 0 + }, + { + "name": "cumproduct", + "long_name": "cumproduct( x , axis = 0 , dtype = None )", + "filename": "oldnumeric.py", + "nloc": 2, + "complexity": 1, + "token_count": 26, + "parameters": [ + "x", + "axis", + "dtype" + ], + "start_line": 383, + "end_line": 385, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 3, + "top_nesting_level": 0 + }, + { + "name": "ptp", + "long_name": "ptp( a , axis = 0 )", + "filename": "oldnumeric.py", + "nloc": 2, + "complexity": 1, + "token_count": 20, + "parameters": [ + "a", + "axis" + ], + "start_line": 387, + "end_line": 390, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 4, + "top_nesting_level": 0 + }, + { + "name": "amax", + "long_name": "amax( a , axis = 0 )", + "filename": "oldnumeric.py", + "nloc": 2, + "complexity": 1, + "token_count": 20, + "parameters": [ + "a", + "axis" + ], + "start_line": 392, + "end_line": 395, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 4, + "top_nesting_level": 0 + }, + { + "name": "amin", + "long_name": "amin( a , axis = 0 )", + "filename": "oldnumeric.py", + "nloc": 2, + "complexity": 1, + "token_count": 20, + "parameters": [ + "a", + "axis" + ], + "start_line": 397, + "end_line": 400, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 4, + "top_nesting_level": 0 + }, + { + "name": "alen", + "long_name": "alen( a )", + "filename": "oldnumeric.py", + "nloc": 2, + "complexity": 1, + "token_count": 14, + "parameters": [ + "a" + ], + "start_line": 402, + "end_line": 405, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 4, + "top_nesting_level": 0 + }, + { + "name": "prod", + "long_name": "prod( a , axis = 0 )", + "filename": "oldnumeric.py", + "nloc": 2, + "complexity": 1, + "token_count": 20, + "parameters": [ + "a", + "axis" + ], + "start_line": 407, + "end_line": 410, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 4, + "top_nesting_level": 0 + }, + { + "name": "cumprod", + "long_name": "cumprod( a , axis = 0 )", + "filename": "oldnumeric.py", + "nloc": 2, + "complexity": 1, + "token_count": 20, + "parameters": [ + "a", + "axis" + ], + "start_line": 412, + "end_line": 415, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 4, + "top_nesting_level": 0 + }, + { + "name": "ndim", + "long_name": "ndim( a )", + "filename": "oldnumeric.py", + "nloc": 5, + "complexity": 2, + "token_count": 21, + "parameters": [ + "a" + ], + "start_line": 417, + "end_line": 421, + "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": 423, + "end_line": 430, + "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": 432, + "end_line": 443, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 12, + "top_nesting_level": 0 + }, + { + "name": "round_", + "long_name": "round_( a , decimals = 0 )", + "filename": "oldnumeric.py", + "nloc": 19, + "complexity": 6, + "token_count": 188, + "parameters": [ + "a", + "decimals" + ], + "start_line": 445, + "end_line": 470, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 26, + "top_nesting_level": 0 + }, + { + "name": "mean", + "long_name": "mean( a , axis = 0 , dtype = None )", + "filename": "oldnumeric.py", + "nloc": 2, + "complexity": 1, + "token_count": 25, + "parameters": [ + "a", + "axis", + "dtype" + ], + "start_line": 474, + "end_line": 475, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 2, + "top_nesting_level": 0 + }, + { + "name": "std", + "long_name": "std( a , axis = 0 , dtype = None )", + "filename": "oldnumeric.py", + "nloc": 2, + "complexity": 1, + "token_count": 25, + "parameters": [ + "a", + "axis", + "dtype" + ], + "start_line": 477, + "end_line": 478, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 2, + "top_nesting_level": 0 + }, + { + "name": "var", + "long_name": "var( a , axis = 0 , dtype = None )", + "filename": "oldnumeric.py", + "nloc": 2, + "complexity": 1, + "token_count": 25, + "parameters": [ + "a", + "axis", + "dtype" + ], + "start_line": 480, + "end_line": 481, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 2, + "top_nesting_level": 0 + } + ], + "changed_methods": [], + "nloc": 272, + "complexity": 61, + "token_count": 2012, + "diff_parsed": { + "added": [ + " 'UInt8','UInt16','UInt32', 'UnsignedInt32'," + ], + "deleted": [ + " 'UInt8','UInt16','UInt32'," + ] + } + } + ] + }, + { + "hash": "c6c45c053488a63057e7758dc9531f91d86cc5ce", + "msg": "More missing names from Numeric.", + "author": { + "name": "Travis Oliphant", + "email": "oliphant@enthought.com" + }, + "committer": { + "name": "Travis Oliphant", + "email": "oliphant@enthought.com" + }, + "author_date": "2006-01-27T19:52:01+00:00", + "author_timezone": 0, + "committer_date": "2006-01-27T19:52:01+00:00", + "committer_timezone": 0, + "branches": [ + "main" + ], + "in_main_branch": true, + "merge": false, + "parents": [ + "c3761a4940346ef33976f87879c9842110f0a968" + ], + "project_name": "repo_copy", + "project_path": "/tmp/tmppy2o86q9/repo_copy", + "deletions": 3, + "insertions": 9, + "lines": 12, + "files": 1, + "dmm_unit_size": null, + "dmm_unit_complexity": null, + "dmm_unit_interfacing": null, + "modified_files": [ + { + "old_path": "numpy/core/oldnumeric.py", + "new_path": "numpy/core/oldnumeric.py", + "filename": "oldnumeric.py", + "extension": "py", + "change_type": "MODIFY", + "diff": "@@ -5,13 +5,13 @@\n 'UFuncType', 'UfuncType', 'ArrayType', 'arraytype',\n 'LittleEndian', 'Bool', \n 'Character', 'UnsignedInt8', 'UnsignedInt16', 'UnsignedInt',\n- 'UInt8','UInt16','UInt32', 'UnsignedInt32',\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',\n- 'Complex32', 'Complex64',\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@@ -112,6 +112,12 @@\n Float32 = _dt_(nt.float32)\n Float64 = _dt_(nt.float64)\n \n+Float16='f'\n+Float8='f'\n+UnsignedInteger='L'\n+Complex8='F'\n+Complex16='F'\n+\n try:\n Float128 = _dt_(nt.float128)\n except AttributeError:\n", + "added_lines": 9, + "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, correlate, outer, concatenate\nfrom umath import sign, absolute, multiply\nimport numeric as _nx\nimport sys\n_dt_ = nt.arrtype2char\n\nimport types\n\ntry:\n _gentype = types.GeneratorType\nexcept AttributeError:\n _gentype = types.NoneType\n#Use this to add a new axis to an array\n#compatibility only\nNewAxis = None\n\n#deprecated\nUFuncType = type(um.sin)\nUfuncType = type(um.sin)\nArrayType = mu.ndarray\narraytype = mu.ndarray\n\nLittleEndian = (sys.byteorder == 'little')\n\n# save away Python sum\n_sum_ = sum\n\n# backward compatible names from old Precision.py\n\nCharacter = 'S1'\nUnsignedInt8 = _dt_(nt.uint8)\nUInt8 = UnsignedInt8\nUnsignedInt16 = _dt_(nt.uint16)\nUInt16 = UnsignedInt16\nUnsignedInt32 = _dt_(nt.uint32)\nUInt32 = UnsignedInt32\nUnsignedInt = _dt_(nt.uint)\n\ntry:\n UnsignedInt64 = _dt_(nt.uint64)\nexcept AttributeError:\n pass\nelse:\n UInt64 = UnsignedInt64\n __all__ += ['UnsignedInt64', 'UInt64']\ntry:\n UnsignedInt128 = _dt_(nt.uint128)\nexcept AttributeError:\n pass\nelse:\n UInt128 = UnsignedInt128\n __all__ += ['UnsignedInt128','UInt128']\n\nInt8 = _dt_(nt.int8)\nInt16 = _dt_(nt.int16)\nInt32 = _dt_(nt.int32)\n\ntry:\n Int64 = _dt_(nt.int64)\nexcept AttributeError:\n pass\nelse:\n __all__ += ['Int64']\n\ntry:\n Int128 = _dt_(nt.int128)\nexcept AttributeError:\n pass\nelse:\n __all__ += ['Int128']\n\nBool = _dt_(bool)\nInt0 = _dt_(int)\nInt = _dt_(int)\nFloat0 = _dt_(float)\nFloat = _dt_(float)\nComplex0 = _dt_(complex)\nComplex = _dt_(complex)\nPyObject = _dt_(nt.object_)\nFloat32 = _dt_(nt.float32)\nFloat64 = _dt_(nt.float64)\n\nFloat16='f'\nFloat8='f'\nUnsignedInteger='L'\nComplex8='F'\nComplex16='F'\n\ntry:\n Float128 = _dt_(nt.float128)\nexcept AttributeError:\n pass\nelse:\n __all__ += ['Float128']\n\nComplex32 = _dt_(nt.complex64)\nComplex64 = _dt_(nt.complex128)\n\ntry:\n Complex128 = _dt_(nt.complex256)\nexcept AttributeError:\n pass\nelse:\n __all__ += ['Complex128']\n\ntypecodes = {'Character':'S1',\n 'Integer':'bhilqp',\n 'UnsignedInteger':'BHILQP',\n 'Float':'fdg',\n 'Complex':'FDG',\n 'AllInteger':'bBhHiIlLqQpP',\n 'AllFloat':'fdgFDG',\n 'All':'?bhilqpBHILQPfdgFDGSUVO'}\n\ndef sarray(a, dtype=None, copy=False):\n return array(a, dtype, copy)\n\n# backward compatibility\narrayrange = mu.arange\ncross_correlate = correlate\n\n# deprecated names\nmatrixmultiply = mu.dot\nouterproduct = outer\ninnerproduct = mu.inner\n\nfrom cPickle import dump, dumps\n\n# functions that are now methods\n\ndef take(a, indices, axis=0):\n a = asarray(a)\n return a.take(indices, axis)\n\ndef reshape(a, newshape):\n \"\"\"Change the shape of a to newshape. Return a new view object.\n \"\"\"\n return asarray(a).reshape(newshape)\n\ndef choose(a, choices):\n a = asarray(a)\n return a.choose(choices)\n\ndef repeat(a, repeats, axis=0):\n \"\"\"repeat elements of a repeats times along axis\n repeats is a sequence of length a.shape[axis]\n telling how many times to repeat each element.\n If repeats is an integer, it is interpreted as\n a tuple of length a.shape[axis] containing repeats.\n The argument a can be anything array(a) will accept.\n \"\"\"\n a = array(a, copy=False)\n return a.repeat(repeats, axis)\n\ndef put (a, ind, v):\n \"\"\"put(a, ind, v) results in a[n] = v[n] for all n in ind\n If v is shorter than mask it will be repeated as necessary.\n In particular v can be a scalar or length 1 array.\n The routine put is the equivalent of the following (although the loop\n is in C for speed):\n\n ind = array(indices, copy=False)\n v = array(values, copy=False).astype(a, a.dtype)\n for i in ind: a.flat[i] = v[i]\n a must be a contiguous Numeric array.\n \"\"\"\n return a.put(v,ind)\n\ndef putmask (a, mask, v):\n \"\"\"putmask(a, mask, v) results in a = v for all places mask is true.\n If v is shorter than mask it will be repeated as necessary.\n In particular v can be a scalar or length 1 array.\n \"\"\"\n return a.putmask(v, mask)\n\ndef swapaxes(a, axis1, axis2):\n \"\"\"swapaxes(a, axis1, axis2) returns array a with axis1 and axis2\n interchanged.\n \"\"\"\n a = array(a, copy=False)\n return a.swapaxes(axis1, axis2)\n\ndef transpose(a, axes=None):\n \"\"\"transpose(a, axes=None) returns array with dimensions permuted\n according to axes. If axes is None (default) returns array with\n dimensions reversed.\n \"\"\"\n a = array(a,copy=False)\n return a.transpose(axes)\n\ndef sort(a, axis=-1):\n \"\"\"sort(a,axis=-1) returns array with elements sorted along given axis.\n \"\"\"\n a = array(a, copy=True)\n a.sort(axis)\n return a\n\ndef argsort(a, axis=-1):\n \"\"\"argsort(a,axis=-1) return the indices into a of the sorted array\n along the given axis, so that take(a,result,axis) is the sorted array.\n \"\"\"\n a = array(a, copy=False)\n return a.argsort(axis)\n\ndef argmax(a, axis=-1):\n \"\"\"argmax(a,axis=-1) returns the indices to the maximum value of the\n 1-D arrays along the given axis.\n \"\"\"\n a = array(a, copy=False)\n return a.argmax(axis)\n\ndef argmin(a, axis=-1):\n \"\"\"argmin(a,axis=-1) returns the indices to the minimum value of the\n 1-D arrays along the given axis.\n \"\"\"\n a = array(a,copy=False)\n return a.argmin(axis)\n\ndef searchsorted(a, v):\n \"\"\"searchsorted(a, v)\n \"\"\"\n a = array(a,copy=False)\n return a.searchsorted(v)\n\ndef resize(a, new_shape):\n \"\"\"resize(a,new_shape) returns a new array with the specified shape.\n The original array's total size can be any size. It\n fills the new array with repeated copies of a.\n\n Note that a.resize(new_shape) will fill array with 0's\n beyond current definition of a.\n \"\"\"\n\n if isinstance(new_shape, (int, nt.integer)):\n new_shape = (new_shape,)\n a = ravel(a)\n Na = len(a)\n if not Na: return mu.zeros(new_shape, a.dtype.char)\n total_size = um.multiply.reduce(new_shape)\n n_copies = int(total_size / Na)\n extra = total_size % Na\n\n if total_size == 0:\n return a[:0]\n\n if extra != 0:\n n_copies = n_copies+1\n extra = Na-extra\n\n a = concatenate( (a,)*n_copies)\n if extra > 0:\n a = a[:-extra]\n\n return reshape(a, new_shape)\n\ndef squeeze(a):\n \"Returns a with any ones from the shape of a removed\"\n return asarray(a).squeeze()\n\ndef diagonal(a, offset=0, axis1=0, axis2=1):\n \"\"\"diagonal(a, offset=0, axis1=0, axis2=1) returns the given diagonals\n defined by the last two dimensions of the array.\n \"\"\"\n return asarray(a).diagonal(offset, axis1, axis2)\n\ndef trace(a, offset=0, axis1=0, axis2=1, dtype=None):\n \"\"\"trace(a,offset=0, axis1=0, axis2=1) returns the sum along diagonals\n (defined by the last two dimenions) of the array.\n \"\"\"\n return asarray(a).trace(offset, axis1, axis2, dtype)\n\ndef ravel(m):\n \"\"\"ravel(m) returns a 1d array corresponding to all the elements of it's\n argument.\n \"\"\"\n return asarray(m).ravel()\n\ndef nonzero(a):\n \"\"\"nonzero(a) returns the indices of the elements of a which are not zero,\n a must be 1d\n \"\"\"\n return asarray(a).nonzero()\n\ndef shape(a):\n \"\"\"shape(a) returns the shape of a (as a function call which\n also works on nested sequences).\n \"\"\"\n try:\n return a.shape\n except AttributeError:\n return asarray(a).shape\n\ndef compress(condition, m, axis=-1):\n \"\"\"compress(condition, x, axis=-1) = those elements of x corresponding \n to those elements of condition that are \"true\". condition must be the\n same size as the given dimension of x.\"\"\"\n return asarray(m).compress(condition, axis)\n\ndef clip(m, m_min, m_max):\n \"\"\"clip(m, m_min, m_max) = every entry in m that is less than m_min is\n replaced by m_min, and every entry greater than m_max is replaced by\n m_max.\n \"\"\"\n return asarray(m).clip(m_min, m_max)\n\ndef sum(x, axis=0, dtype=None):\n \"\"\"Sum the array over the given axis. The optional dtype argument\n is the data type for intermediate calculations.\n\n The default is to upcast (promote) smaller integer types to the\n platform-dependent Int. For example, on 32-bit platforms:\n\n x.dtype default sum() dtype\n ---------------------------------------------------\n bool, Int8, Int16, Int32 Int32\n\n Examples:\n >>> sum([0.5, 1.5])\n 2.0\n >>> sum([0.5, 1.5], dtype=Int32)\n 1\n >>> sum([[0, 1], [0, 5]])\n array([0, 6])\n >>> sum([[0, 1], [0, 5]], axis=1)\n array([1, 5])\n \"\"\"\n if isinstance(x, _gentype):\n return _sum_(x)\n return asarray(x).sum(axis, dtype)\n\ndef product (x, axis=0, dtype=None):\n \"\"\"Product of the array elements over the given axis.\"\"\"\n return asarray(x).prod(axis, dtype)\n\ndef sometrue (x, axis=0):\n \"\"\"Perform a logical_or over the given axis.\"\"\"\n return asarray(x).any(axis)\n\ndef alltrue (x, axis=0):\n \"\"\"Perform a logical_and over the given axis.\"\"\"\n return asarray(x).all(axis)\n\ndef any(x,axis=None):\n \"\"\"Return true if any elements of x are true: sometrue(ravel(x))\n \"\"\"\n return ravel(x).any(axis)\n\ndef all(x,axis=None):\n \"\"\"Return true if all elements of x are true: alltrue(ravel(x))\n \"\"\"\n return ravel(x).all(axis)\n\ndef cumsum (x, axis=0, dtype=None):\n \"\"\"Sum the array over the given axis.\"\"\"\n return asarray(x).cumsum(axis, dtype)\n\ndef cumproduct (x, axis=0, dtype=None):\n \"\"\"Sum the array over the given axis.\"\"\"\n return asarray(x).cumprod(axis, dtype)\n\ndef ptp(a, axis=0):\n \"\"\"Return maximum - minimum along the the given dimension\n \"\"\"\n return asarray(a).ptp(axis)\n\ndef amax(a, axis=0):\n \"\"\"Return the maximum of 'a' along dimension axis.\n \"\"\"\n return asarray(a).max(axis)\n\ndef amin(a, axis=0):\n \"\"\"Return the minimum of a along dimension axis.\n \"\"\"\n return asarray(a).min(axis)\n\ndef alen(a):\n \"\"\"Return the length of a Python object interpreted as an array\n \"\"\"\n return len(asarray(a))\n\ndef prod(a, axis=0):\n \"\"\"Return the product of the elements along the given axis\n \"\"\"\n return asarray(a).prod(axis)\n\ndef cumprod(a, axis=0):\n \"\"\"Return the cumulative product of the elments along the given axis\n \"\"\"\n return asarray(a).cumprod(axis)\n\ndef ndim(a):\n try:\n return a.ndim\n except AttributeError:\n return asarray(a).ndim\n\ndef rank (a):\n \"\"\"Get the rank of sequence a (the number of dimensions, not a matrix rank)\n The rank of a scalar is zero.\n \"\"\"\n try:\n return a.ndim\n except AttributeError:\n return asarray(a).ndim\n\ndef size (a, axis=None):\n \"Get the number of elements in sequence a, or along a certain axis.\"\n if axis is None:\n try:\n return a.size\n except AttributeError:\n return asarray(a).size\n else:\n try:\n return a.shape[axis]\n except AttributeError:\n return asarray(a).shape[axis]\n\ndef round_(a, decimals=0):\n \"\"\"Round 'a' to the given number of decimal places. Rounding\n behaviour is equivalent to Python.\n\n Return 'a' if the array is not floating point. Round both the real\n and imaginary parts separately if the array is complex.\n \"\"\"\n a = asarray(a)\n if not issubclass(a.dtype.type, _nx.inexact):\n return a\n if issubclass(a.dtype.type, _nx.complexfloating):\n return round_(a.real, decimals) + 1j*round_(a.imag, decimals)\n if decimals is not 0:\n decimals = asarray(decimals)\n s = sign(a)\n if decimals is not 0:\n a = absolute(multiply(a, 10.**decimals))\n else:\n a = absolute(a)\n rem = a-asarray(a).astype(_nx.intp)\n a = _nx.where(_nx.less(rem, 0.5), _nx.floor(a), _nx.ceil(a))\n # convert back\n if decimals is not 0:\n return multiply(a, s/(10.**decimals))\n else:\n return multiply(a, s)\n\naround = round_\n\ndef mean(a, axis=0, dtype=None):\n return asarray(a).mean(axis, dtype)\n\ndef std(a, axis=0, dtype=None):\n return asarray(a).std(axis, dtype)\n\ndef var(a, axis=0, dtype=None):\n return asarray(a).var(axis, dtype)\n", + "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',\n # UnsignedInt64 and Unsigned128 added below if possible\n # same for Int64 and Int128, Float128, and Complex128\n 'Int8', 'Int16', 'Int32',\n 'Int0', 'Int', 'Float0', 'Float', 'Complex0', 'Complex',\n 'PyObject', 'Float32', 'Float64',\n 'Complex32', 'Complex64',\n 'typecodes', 'sarray', 'arrayrange', 'cross_correlate',\n 'matrixmultiply', 'outerproduct', 'innerproduct',\n # from cPickle\n 'dump', 'dumps',\n # functions that are now methods\n 'take', 'reshape', 'choose', 'repeat', 'put', 'putmask',\n 'swapaxes', 'transpose', 'sort', 'argsort', 'argmax', 'argmin',\n 'searchsorted', 'alen', \n 'resize', 'diagonal', 'trace', 'ravel', 'nonzero', 'shape',\n 'compress', 'clip', 'sum', 'product', 'prod', 'sometrue', 'alltrue',\n 'any', 'all', 'cumsum', 'cumproduct', 'cumprod', 'ptp', 'ndim',\n 'rank', 'size', 'around', 'round_', 'mean', 'std', 'var', 'squeeze',\n 'amax', 'amin',\n ]\n\nimport multiarray as mu\nimport umath as um\nimport numerictypes as nt\nfrom numeric import asarray, array, correlate, outer, concatenate\nfrom umath import sign, absolute, multiply\nimport numeric as _nx\nimport sys\n_dt_ = nt.arrtype2char\n\nimport types\n\ntry:\n _gentype = types.GeneratorType\nexcept AttributeError:\n _gentype = types.NoneType\n#Use this to add a new axis to an array\n#compatibility only\nNewAxis = None\n\n#deprecated\nUFuncType = type(um.sin)\nUfuncType = type(um.sin)\nArrayType = mu.ndarray\narraytype = mu.ndarray\n\nLittleEndian = (sys.byteorder == 'little')\n\n# save away Python sum\n_sum_ = sum\n\n# backward compatible names from old Precision.py\n\nCharacter = 'S1'\nUnsignedInt8 = _dt_(nt.uint8)\nUInt8 = UnsignedInt8\nUnsignedInt16 = _dt_(nt.uint16)\nUInt16 = UnsignedInt16\nUnsignedInt32 = _dt_(nt.uint32)\nUInt32 = UnsignedInt32\nUnsignedInt = _dt_(nt.uint)\n\ntry:\n UnsignedInt64 = _dt_(nt.uint64)\nexcept AttributeError:\n pass\nelse:\n UInt64 = UnsignedInt64\n __all__ += ['UnsignedInt64', 'UInt64']\ntry:\n UnsignedInt128 = _dt_(nt.uint128)\nexcept AttributeError:\n pass\nelse:\n UInt128 = UnsignedInt128\n __all__ += ['UnsignedInt128','UInt128']\n\nInt8 = _dt_(nt.int8)\nInt16 = _dt_(nt.int16)\nInt32 = _dt_(nt.int32)\n\ntry:\n Int64 = _dt_(nt.int64)\nexcept AttributeError:\n pass\nelse:\n __all__ += ['Int64']\n\ntry:\n Int128 = _dt_(nt.int128)\nexcept AttributeError:\n pass\nelse:\n __all__ += ['Int128']\n\nBool = _dt_(bool)\nInt0 = _dt_(int)\nInt = _dt_(int)\nFloat0 = _dt_(float)\nFloat = _dt_(float)\nComplex0 = _dt_(complex)\nComplex = _dt_(complex)\nPyObject = _dt_(nt.object_)\nFloat32 = _dt_(nt.float32)\nFloat64 = _dt_(nt.float64)\n\ntry:\n Float128 = _dt_(nt.float128)\nexcept AttributeError:\n pass\nelse:\n __all__ += ['Float128']\n\nComplex32 = _dt_(nt.complex64)\nComplex64 = _dt_(nt.complex128)\n\ntry:\n Complex128 = _dt_(nt.complex256)\nexcept AttributeError:\n pass\nelse:\n __all__ += ['Complex128']\n\ntypecodes = {'Character':'S1',\n 'Integer':'bhilqp',\n 'UnsignedInteger':'BHILQP',\n 'Float':'fdg',\n 'Complex':'FDG',\n 'AllInteger':'bBhHiIlLqQpP',\n 'AllFloat':'fdgFDG',\n 'All':'?bhilqpBHILQPfdgFDGSUVO'}\n\ndef sarray(a, dtype=None, copy=False):\n return array(a, dtype, copy)\n\n# backward compatibility\narrayrange = mu.arange\ncross_correlate = correlate\n\n# deprecated names\nmatrixmultiply = mu.dot\nouterproduct = outer\ninnerproduct = mu.inner\n\nfrom cPickle import dump, dumps\n\n# functions that are now methods\n\ndef take(a, indices, axis=0):\n a = asarray(a)\n return a.take(indices, axis)\n\ndef reshape(a, newshape):\n \"\"\"Change the shape of a to newshape. Return a new view object.\n \"\"\"\n return asarray(a).reshape(newshape)\n\ndef choose(a, choices):\n a = asarray(a)\n return a.choose(choices)\n\ndef repeat(a, repeats, axis=0):\n \"\"\"repeat elements of a repeats times along axis\n repeats is a sequence of length a.shape[axis]\n telling how many times to repeat each element.\n If repeats is an integer, it is interpreted as\n a tuple of length a.shape[axis] containing repeats.\n The argument a can be anything array(a) will accept.\n \"\"\"\n a = array(a, copy=False)\n return a.repeat(repeats, axis)\n\ndef put (a, ind, v):\n \"\"\"put(a, ind, v) results in a[n] = v[n] for all n in ind\n If v is shorter than mask it will be repeated as necessary.\n In particular v can be a scalar or length 1 array.\n The routine put is the equivalent of the following (although the loop\n is in C for speed):\n\n ind = array(indices, copy=False)\n v = array(values, copy=False).astype(a, a.dtype)\n for i in ind: a.flat[i] = v[i]\n a must be a contiguous Numeric array.\n \"\"\"\n return a.put(v,ind)\n\ndef putmask (a, mask, v):\n \"\"\"putmask(a, mask, v) results in a = v for all places mask is true.\n If v is shorter than mask it will be repeated as necessary.\n In particular v can be a scalar or length 1 array.\n \"\"\"\n return a.putmask(v, mask)\n\ndef swapaxes(a, axis1, axis2):\n \"\"\"swapaxes(a, axis1, axis2) returns array a with axis1 and axis2\n interchanged.\n \"\"\"\n a = array(a, copy=False)\n return a.swapaxes(axis1, axis2)\n\ndef transpose(a, axes=None):\n \"\"\"transpose(a, axes=None) returns array with dimensions permuted\n according to axes. If axes is None (default) returns array with\n dimensions reversed.\n \"\"\"\n a = array(a,copy=False)\n return a.transpose(axes)\n\ndef sort(a, axis=-1):\n \"\"\"sort(a,axis=-1) returns array with elements sorted along given axis.\n \"\"\"\n a = array(a, copy=True)\n a.sort(axis)\n return a\n\ndef argsort(a, axis=-1):\n \"\"\"argsort(a,axis=-1) return the indices into a of the sorted array\n along the given axis, so that take(a,result,axis) is the sorted array.\n \"\"\"\n a = array(a, copy=False)\n return a.argsort(axis)\n\ndef argmax(a, axis=-1):\n \"\"\"argmax(a,axis=-1) returns the indices to the maximum value of the\n 1-D arrays along the given axis.\n \"\"\"\n a = array(a, copy=False)\n return a.argmax(axis)\n\ndef argmin(a, axis=-1):\n \"\"\"argmin(a,axis=-1) returns the indices to the minimum value of the\n 1-D arrays along the given axis.\n \"\"\"\n a = array(a,copy=False)\n return a.argmin(axis)\n\ndef searchsorted(a, v):\n \"\"\"searchsorted(a, v)\n \"\"\"\n a = array(a,copy=False)\n return a.searchsorted(v)\n\ndef resize(a, new_shape):\n \"\"\"resize(a,new_shape) returns a new array with the specified shape.\n The original array's total size can be any size. It\n fills the new array with repeated copies of a.\n\n Note that a.resize(new_shape) will fill array with 0's\n beyond current definition of a.\n \"\"\"\n\n if isinstance(new_shape, (int, nt.integer)):\n new_shape = (new_shape,)\n a = ravel(a)\n Na = len(a)\n if not Na: return mu.zeros(new_shape, a.dtype.char)\n total_size = um.multiply.reduce(new_shape)\n n_copies = int(total_size / Na)\n extra = total_size % Na\n\n if total_size == 0:\n return a[:0]\n\n if extra != 0:\n n_copies = n_copies+1\n extra = Na-extra\n\n a = concatenate( (a,)*n_copies)\n if extra > 0:\n a = a[:-extra]\n\n return reshape(a, new_shape)\n\ndef squeeze(a):\n \"Returns a with any ones from the shape of a removed\"\n return asarray(a).squeeze()\n\ndef diagonal(a, offset=0, axis1=0, axis2=1):\n \"\"\"diagonal(a, offset=0, axis1=0, axis2=1) returns the given diagonals\n defined by the last two dimensions of the array.\n \"\"\"\n return asarray(a).diagonal(offset, axis1, axis2)\n\ndef trace(a, offset=0, axis1=0, axis2=1, dtype=None):\n \"\"\"trace(a,offset=0, axis1=0, axis2=1) returns the sum along diagonals\n (defined by the last two dimenions) of the array.\n \"\"\"\n return asarray(a).trace(offset, axis1, axis2, dtype)\n\ndef ravel(m):\n \"\"\"ravel(m) returns a 1d array corresponding to all the elements of it's\n argument.\n \"\"\"\n return asarray(m).ravel()\n\ndef nonzero(a):\n \"\"\"nonzero(a) returns the indices of the elements of a which are not zero,\n a must be 1d\n \"\"\"\n return asarray(a).nonzero()\n\ndef shape(a):\n \"\"\"shape(a) returns the shape of a (as a function call which\n also works on nested sequences).\n \"\"\"\n try:\n return a.shape\n except AttributeError:\n return asarray(a).shape\n\ndef compress(condition, m, axis=-1):\n \"\"\"compress(condition, x, axis=-1) = those elements of x corresponding \n to those elements of condition that are \"true\". condition must be the\n same size as the given dimension of x.\"\"\"\n return asarray(m).compress(condition, axis)\n\ndef clip(m, m_min, m_max):\n \"\"\"clip(m, m_min, m_max) = every entry in m that is less than m_min is\n replaced by m_min, and every entry greater than m_max is replaced by\n m_max.\n \"\"\"\n return asarray(m).clip(m_min, m_max)\n\ndef sum(x, axis=0, dtype=None):\n \"\"\"Sum the array over the given axis. The optional dtype argument\n is the data type for intermediate calculations.\n\n The default is to upcast (promote) smaller integer types to the\n platform-dependent Int. For example, on 32-bit platforms:\n\n x.dtype default sum() dtype\n ---------------------------------------------------\n bool, Int8, Int16, Int32 Int32\n\n Examples:\n >>> sum([0.5, 1.5])\n 2.0\n >>> sum([0.5, 1.5], dtype=Int32)\n 1\n >>> sum([[0, 1], [0, 5]])\n array([0, 6])\n >>> sum([[0, 1], [0, 5]], axis=1)\n array([1, 5])\n \"\"\"\n if isinstance(x, _gentype):\n return _sum_(x)\n return asarray(x).sum(axis, dtype)\n\ndef product (x, axis=0, dtype=None):\n \"\"\"Product of the array elements over the given axis.\"\"\"\n return asarray(x).prod(axis, dtype)\n\ndef sometrue (x, axis=0):\n \"\"\"Perform a logical_or over the given axis.\"\"\"\n return asarray(x).any(axis)\n\ndef alltrue (x, axis=0):\n \"\"\"Perform a logical_and over the given axis.\"\"\"\n return asarray(x).all(axis)\n\ndef any(x,axis=None):\n \"\"\"Return true if any elements of x are true: sometrue(ravel(x))\n \"\"\"\n return ravel(x).any(axis)\n\ndef all(x,axis=None):\n \"\"\"Return true if all elements of x are true: alltrue(ravel(x))\n \"\"\"\n return ravel(x).all(axis)\n\ndef cumsum (x, axis=0, dtype=None):\n \"\"\"Sum the array over the given axis.\"\"\"\n return asarray(x).cumsum(axis, dtype)\n\ndef cumproduct (x, axis=0, dtype=None):\n \"\"\"Sum the array over the given axis.\"\"\"\n return asarray(x).cumprod(axis, dtype)\n\ndef ptp(a, axis=0):\n \"\"\"Return maximum - minimum along the the given dimension\n \"\"\"\n return asarray(a).ptp(axis)\n\ndef amax(a, axis=0):\n \"\"\"Return the maximum of 'a' along dimension axis.\n \"\"\"\n return asarray(a).max(axis)\n\ndef amin(a, axis=0):\n \"\"\"Return the minimum of a along dimension axis.\n \"\"\"\n return asarray(a).min(axis)\n\ndef alen(a):\n \"\"\"Return the length of a Python object interpreted as an array\n \"\"\"\n return len(asarray(a))\n\ndef prod(a, axis=0):\n \"\"\"Return the product of the elements along the given axis\n \"\"\"\n return asarray(a).prod(axis)\n\ndef cumprod(a, axis=0):\n \"\"\"Return the cumulative product of the elments along the given axis\n \"\"\"\n return asarray(a).cumprod(axis)\n\ndef ndim(a):\n try:\n return a.ndim\n except AttributeError:\n return asarray(a).ndim\n\ndef rank (a):\n \"\"\"Get the rank of sequence a (the number of dimensions, not a matrix rank)\n The rank of a scalar is zero.\n \"\"\"\n try:\n return a.ndim\n except AttributeError:\n return asarray(a).ndim\n\ndef size (a, axis=None):\n \"Get the number of elements in sequence a, or along a certain axis.\"\n if axis is None:\n try:\n return a.size\n except AttributeError:\n return asarray(a).size\n else:\n try:\n return a.shape[axis]\n except AttributeError:\n return asarray(a).shape[axis]\n\ndef round_(a, decimals=0):\n \"\"\"Round 'a' to the given number of decimal places. Rounding\n behaviour is equivalent to Python.\n\n Return 'a' if the array is not floating point. Round both the real\n and imaginary parts separately if the array is complex.\n \"\"\"\n a = asarray(a)\n if not issubclass(a.dtype.type, _nx.inexact):\n return a\n if issubclass(a.dtype.type, _nx.complexfloating):\n return round_(a.real, decimals) + 1j*round_(a.imag, decimals)\n if decimals is not 0:\n decimals = asarray(decimals)\n s = sign(a)\n if decimals is not 0:\n a = absolute(multiply(a, 10.**decimals))\n else:\n a = absolute(a)\n rem = a-asarray(a).astype(_nx.intp)\n a = _nx.where(_nx.less(rem, 0.5), _nx.floor(a), _nx.ceil(a))\n # convert back\n if decimals is not 0:\n return multiply(a, s/(10.**decimals))\n else:\n return multiply(a, s)\n\naround = round_\n\ndef mean(a, axis=0, dtype=None):\n return asarray(a).mean(axis, dtype)\n\ndef std(a, axis=0, dtype=None):\n return asarray(a).std(axis, dtype)\n\ndef var(a, axis=0, dtype=None):\n return asarray(a).var(axis, dtype)\n", + "methods": [ + { + "name": "sarray", + "long_name": "sarray( a , dtype = None , copy = False )", + "filename": "oldnumeric.py", + "nloc": 2, + "complexity": 1, + "token_count": 22, + "parameters": [ + "a", + "dtype", + "copy" + ], + "start_line": 147, + "end_line": 148, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 2, + "top_nesting_level": 0 + }, + { + "name": "take", + "long_name": "take( a , indices , axis = 0 )", + "filename": "oldnumeric.py", + "nloc": 3, + "complexity": 1, + "token_count": 26, + "parameters": [ + "a", + "indices", + "axis" + ], + "start_line": 163, + "end_line": 165, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 3, + "top_nesting_level": 0 + }, + { + "name": "reshape", + "long_name": "reshape( a , newshape )", + "filename": "oldnumeric.py", + "nloc": 2, + "complexity": 1, + "token_count": 18, + "parameters": [ + "a", + "newshape" + ], + "start_line": 167, + "end_line": 170, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 4, + "top_nesting_level": 0 + }, + { + "name": "choose", + "long_name": "choose( a , choices )", + "filename": "oldnumeric.py", + "nloc": 3, + "complexity": 1, + "token_count": 20, + "parameters": [ + "a", + "choices" + ], + "start_line": 172, + "end_line": 174, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 3, + "top_nesting_level": 0 + }, + { + "name": "repeat", + "long_name": "repeat( a , repeats , axis = 0 )", + "filename": "oldnumeric.py", + "nloc": 3, + "complexity": 1, + "token_count": 31, + "parameters": [ + "a", + "repeats", + "axis" + ], + "start_line": 176, + "end_line": 185, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 10, + "top_nesting_level": 0 + }, + { + "name": "put", + "long_name": "put( a , ind , v )", + "filename": "oldnumeric.py", + "nloc": 2, + "complexity": 1, + "token_count": 19, + "parameters": [ + "a", + "ind", + "v" + ], + "start_line": 187, + "end_line": 199, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 13, + "top_nesting_level": 0 + }, + { + "name": "putmask", + "long_name": "putmask( a , mask , v )", + "filename": "oldnumeric.py", + "nloc": 2, + "complexity": 1, + "token_count": 19, + "parameters": [ + "a", + "mask", + "v" + ], + "start_line": 201, + "end_line": 206, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 6, + "top_nesting_level": 0 + }, + { + "name": "swapaxes", + "long_name": "swapaxes( a , axis1 , axis2 )", + "filename": "oldnumeric.py", + "nloc": 3, + "complexity": 1, + "token_count": 29, + "parameters": [ + "a", + "axis1", + "axis2" + ], + "start_line": 208, + "end_line": 213, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 6, + "top_nesting_level": 0 + }, + { + "name": "transpose", + "long_name": "transpose( a , axes = None )", + "filename": "oldnumeric.py", + "nloc": 3, + "complexity": 1, + "token_count": 27, + "parameters": [ + "a", + "axes" + ], + "start_line": 215, + "end_line": 221, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 7, + "top_nesting_level": 0 + }, + { + "name": "sort", + "long_name": "sort( a , axis = - 1 )", + "filename": "oldnumeric.py", + "nloc": 4, + "complexity": 1, + "token_count": 29, + "parameters": [ + "a", + "axis" + ], + "start_line": 223, + "end_line": 228, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 6, + "top_nesting_level": 0 + }, + { + "name": "argsort", + "long_name": "argsort( a , axis = - 1 )", + "filename": "oldnumeric.py", + "nloc": 3, + "complexity": 1, + "token_count": 28, + "parameters": [ + "a", + "axis" + ], + "start_line": 230, + "end_line": 235, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 6, + "top_nesting_level": 0 + }, + { + "name": "argmax", + "long_name": "argmax( a , axis = - 1 )", + "filename": "oldnumeric.py", + "nloc": 3, + "complexity": 1, + "token_count": 28, + "parameters": [ + "a", + "axis" + ], + "start_line": 237, + "end_line": 242, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 6, + "top_nesting_level": 0 + }, + { + "name": "argmin", + "long_name": "argmin( a , axis = - 1 )", + "filename": "oldnumeric.py", + "nloc": 3, + "complexity": 1, + "token_count": 28, + "parameters": [ + "a", + "axis" + ], + "start_line": 244, + "end_line": 249, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 6, + "top_nesting_level": 0 + }, + { + "name": "searchsorted", + "long_name": "searchsorted( a , v )", + "filename": "oldnumeric.py", + "nloc": 3, + "complexity": 1, + "token_count": 25, + "parameters": [ + "a", + "v" + ], + "start_line": 251, + "end_line": 255, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 5, + "top_nesting_level": 0 + }, + { + "name": "resize", + "long_name": "resize( a , new_shape )", + "filename": "oldnumeric.py", + "nloc": 18, + "complexity": 6, + "token_count": 137, + "parameters": [ + "a", + "new_shape" + ], + "start_line": 257, + "end_line": 286, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 30, + "top_nesting_level": 0 + }, + { + "name": "squeeze", + "long_name": "squeeze( a )", + "filename": "oldnumeric.py", + "nloc": 3, + "complexity": 1, + "token_count": 15, + "parameters": [ + "a" + ], + "start_line": 288, + "end_line": 290, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 3, + "top_nesting_level": 0 + }, + { + "name": "diagonal", + "long_name": "diagonal( a , offset = 0 , axis1 = 0 , axis2 = 1 )", + "filename": "oldnumeric.py", + "nloc": 2, + "complexity": 1, + "token_count": 32, + "parameters": [ + "a", + "offset", + "axis1", + "axis2" + ], + "start_line": 292, + "end_line": 296, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 5, + "top_nesting_level": 0 + }, + { + "name": "trace", + "long_name": "trace( a , offset = 0 , axis1 = 0 , axis2 = 1 , dtype = None )", + "filename": "oldnumeric.py", + "nloc": 2, + "complexity": 1, + "token_count": 38, + "parameters": [ + "a", + "offset", + "axis1", + "axis2", + "dtype" + ], + "start_line": 298, + "end_line": 302, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 5, + "top_nesting_level": 0 + }, + { + "name": "ravel", + "long_name": "ravel( m )", + "filename": "oldnumeric.py", + "nloc": 2, + "complexity": 1, + "token_count": 15, + "parameters": [ + "m" + ], + "start_line": 304, + "end_line": 308, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 5, + "top_nesting_level": 0 + }, + { + "name": "nonzero", + "long_name": "nonzero( a )", + "filename": "oldnumeric.py", + "nloc": 2, + "complexity": 1, + "token_count": 15, + "parameters": [ + "a" + ], + "start_line": 310, + "end_line": 314, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 5, + "top_nesting_level": 0 + }, + { + "name": "shape", + "long_name": "shape( a )", + "filename": "oldnumeric.py", + "nloc": 5, + "complexity": 2, + "token_count": 22, + "parameters": [ + "a" + ], + "start_line": 316, + "end_line": 323, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 8, + "top_nesting_level": 0 + }, + { + "name": "compress", + "long_name": "compress( condition , m , axis = - 1 )", + "filename": "oldnumeric.py", + "nloc": 2, + "complexity": 1, + "token_count": 25, + "parameters": [ + "condition", + "m", + "axis" + ], + "start_line": 325, + "end_line": 329, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 5, + "top_nesting_level": 0 + }, + { + "name": "clip", + "long_name": "clip( m , m_min , m_max )", + "filename": "oldnumeric.py", + "nloc": 2, + "complexity": 1, + "token_count": 22, + "parameters": [ + "m", + "m_min", + "m_max" + ], + "start_line": 331, + "end_line": 336, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 6, + "top_nesting_level": 0 + }, + { + "name": "sum", + "long_name": "sum( x , axis = 0 , dtype = None )", + "filename": "oldnumeric.py", + "nloc": 4, + "complexity": 2, + "token_count": 39, + "parameters": [ + "x", + "axis", + "dtype" + ], + "start_line": 338, + "end_line": 361, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 24, + "top_nesting_level": 0 + }, + { + "name": "product", + "long_name": "product( x , axis = 0 , dtype = None )", + "filename": "oldnumeric.py", + "nloc": 2, + "complexity": 1, + "token_count": 26, + "parameters": [ + "x", + "axis", + "dtype" + ], + "start_line": 363, + "end_line": 365, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 3, + "top_nesting_level": 0 + }, + { + "name": "sometrue", + "long_name": "sometrue( x , axis = 0 )", + "filename": "oldnumeric.py", + "nloc": 2, + "complexity": 1, + "token_count": 20, + "parameters": [ + "x", + "axis" + ], + "start_line": 367, + "end_line": 369, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 3, + "top_nesting_level": 0 + }, + { + "name": "alltrue", + "long_name": "alltrue( x , axis = 0 )", + "filename": "oldnumeric.py", + "nloc": 2, + "complexity": 1, + "token_count": 20, + "parameters": [ + "x", + "axis" + ], + "start_line": 371, + "end_line": 373, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 3, + "top_nesting_level": 0 + }, + { + "name": "any", + "long_name": "any( x , axis = None )", + "filename": "oldnumeric.py", + "nloc": 2, + "complexity": 1, + "token_count": 20, + "parameters": [ + "x", + "axis" + ], + "start_line": 375, + "end_line": 378, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 4, + "top_nesting_level": 0 + }, + { + "name": "all", + "long_name": "all( x , axis = None )", + "filename": "oldnumeric.py", + "nloc": 2, + "complexity": 1, + "token_count": 20, + "parameters": [ + "x", + "axis" + ], + "start_line": 380, + "end_line": 383, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 4, + "top_nesting_level": 0 + }, + { + "name": "cumsum", + "long_name": "cumsum( x , axis = 0 , dtype = None )", + "filename": "oldnumeric.py", + "nloc": 2, + "complexity": 1, + "token_count": 26, + "parameters": [ + "x", + "axis", + "dtype" + ], + "start_line": 385, + "end_line": 387, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 3, + "top_nesting_level": 0 + }, + { + "name": "cumproduct", + "long_name": "cumproduct( x , axis = 0 , dtype = None )", + "filename": "oldnumeric.py", + "nloc": 2, + "complexity": 1, + "token_count": 26, + "parameters": [ + "x", + "axis", + "dtype" + ], + "start_line": 389, + "end_line": 391, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 3, + "top_nesting_level": 0 + }, + { + "name": "ptp", + "long_name": "ptp( a , axis = 0 )", + "filename": "oldnumeric.py", + "nloc": 2, + "complexity": 1, + "token_count": 20, + "parameters": [ + "a", + "axis" + ], + "start_line": 393, + "end_line": 396, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 4, + "top_nesting_level": 0 + }, + { + "name": "amax", + "long_name": "amax( a , axis = 0 )", + "filename": "oldnumeric.py", + "nloc": 2, + "complexity": 1, + "token_count": 20, + "parameters": [ + "a", + "axis" + ], + "start_line": 398, + "end_line": 401, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 4, + "top_nesting_level": 0 + }, + { + "name": "amin", + "long_name": "amin( a , axis = 0 )", + "filename": "oldnumeric.py", + "nloc": 2, + "complexity": 1, + "token_count": 20, + "parameters": [ + "a", + "axis" + ], + "start_line": 403, + "end_line": 406, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 4, + "top_nesting_level": 0 + }, + { + "name": "alen", + "long_name": "alen( a )", + "filename": "oldnumeric.py", + "nloc": 2, + "complexity": 1, + "token_count": 14, + "parameters": [ + "a" + ], + "start_line": 408, + "end_line": 411, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 4, + "top_nesting_level": 0 + }, + { + "name": "prod", + "long_name": "prod( a , axis = 0 )", + "filename": "oldnumeric.py", + "nloc": 2, + "complexity": 1, + "token_count": 20, + "parameters": [ + "a", + "axis" + ], + "start_line": 413, + "end_line": 416, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 4, + "top_nesting_level": 0 + }, + { + "name": "cumprod", + "long_name": "cumprod( a , axis = 0 )", + "filename": "oldnumeric.py", + "nloc": 2, + "complexity": 1, + "token_count": 20, + "parameters": [ + "a", + "axis" + ], + "start_line": 418, + "end_line": 421, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 4, + "top_nesting_level": 0 + }, + { + "name": "ndim", + "long_name": "ndim( a )", + "filename": "oldnumeric.py", + "nloc": 5, + "complexity": 2, + "token_count": 21, + "parameters": [ + "a" + ], + "start_line": 423, + "end_line": 427, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 5, + "top_nesting_level": 0 + }, + { + "name": "rank", + "long_name": "rank( a )", + "filename": "oldnumeric.py", + "nloc": 5, + "complexity": 2, + "token_count": 22, + "parameters": [ + "a" + ], + "start_line": 429, + "end_line": 436, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 8, + "top_nesting_level": 0 + }, + { + "name": "size", + "long_name": "size( a , axis = None )", + "filename": "oldnumeric.py", + "nloc": 12, + "complexity": 4, + "token_count": 55, + "parameters": [ + "a", + "axis" + ], + "start_line": 438, + "end_line": 449, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 12, + "top_nesting_level": 0 + }, + { + "name": "round_", + "long_name": "round_( a , decimals = 0 )", + "filename": "oldnumeric.py", + "nloc": 19, + "complexity": 6, + "token_count": 188, + "parameters": [ + "a", + "decimals" + ], + "start_line": 451, + "end_line": 476, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 26, + "top_nesting_level": 0 + }, + { + "name": "mean", + "long_name": "mean( a , axis = 0 , dtype = None )", + "filename": "oldnumeric.py", + "nloc": 2, + "complexity": 1, + "token_count": 25, + "parameters": [ + "a", + "axis", + "dtype" + ], + "start_line": 480, + "end_line": 481, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 2, + "top_nesting_level": 0 + }, + { + "name": "std", + "long_name": "std( a , axis = 0 , dtype = None )", + "filename": "oldnumeric.py", + "nloc": 2, + "complexity": 1, + "token_count": 25, + "parameters": [ + "a", + "axis", + "dtype" + ], + "start_line": 483, + "end_line": 484, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 2, + "top_nesting_level": 0 + }, + { + "name": "var", + "long_name": "var( a , axis = 0 , dtype = None )", + "filename": "oldnumeric.py", + "nloc": 2, + "complexity": 1, + "token_count": 25, + "parameters": [ + "a", + "axis", + "dtype" + ], + "start_line": 486, + "end_line": 487, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 2, + "top_nesting_level": 0 + } + ], + "methods_before": [ + { + "name": "sarray", + "long_name": "sarray( a , dtype = None , copy = False )", + "filename": "oldnumeric.py", + "nloc": 2, + "complexity": 1, + "token_count": 22, + "parameters": [ + "a", + "dtype", + "copy" + ], + "start_line": 141, + "end_line": 142, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 2, + "top_nesting_level": 0 + }, + { + "name": "take", + "long_name": "take( a , indices , axis = 0 )", + "filename": "oldnumeric.py", + "nloc": 3, + "complexity": 1, + "token_count": 26, + "parameters": [ + "a", + "indices", + "axis" + ], + "start_line": 157, + "end_line": 159, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 3, + "top_nesting_level": 0 + }, + { + "name": "reshape", + "long_name": "reshape( a , newshape )", + "filename": "oldnumeric.py", + "nloc": 2, + "complexity": 1, + "token_count": 18, + "parameters": [ + "a", + "newshape" + ], + "start_line": 161, + "end_line": 164, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 4, + "top_nesting_level": 0 + }, + { + "name": "choose", + "long_name": "choose( a , choices )", + "filename": "oldnumeric.py", + "nloc": 3, + "complexity": 1, + "token_count": 20, + "parameters": [ + "a", + "choices" + ], + "start_line": 166, + "end_line": 168, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 3, + "top_nesting_level": 0 + }, + { + "name": "repeat", + "long_name": "repeat( a , repeats , axis = 0 )", + "filename": "oldnumeric.py", + "nloc": 3, + "complexity": 1, + "token_count": 31, + "parameters": [ + "a", + "repeats", + "axis" + ], + "start_line": 170, + "end_line": 179, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 10, + "top_nesting_level": 0 + }, + { + "name": "put", + "long_name": "put( a , ind , v )", + "filename": "oldnumeric.py", + "nloc": 2, + "complexity": 1, + "token_count": 19, + "parameters": [ + "a", + "ind", + "v" + ], + "start_line": 181, + "end_line": 193, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 13, + "top_nesting_level": 0 + }, + { + "name": "putmask", + "long_name": "putmask( a , mask , v )", + "filename": "oldnumeric.py", + "nloc": 2, + "complexity": 1, + "token_count": 19, + "parameters": [ + "a", + "mask", + "v" + ], + "start_line": 195, + "end_line": 200, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 6, + "top_nesting_level": 0 + }, + { + "name": "swapaxes", + "long_name": "swapaxes( a , axis1 , axis2 )", + "filename": "oldnumeric.py", + "nloc": 3, + "complexity": 1, + "token_count": 29, + "parameters": [ + "a", + "axis1", + "axis2" + ], + "start_line": 202, + "end_line": 207, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 6, + "top_nesting_level": 0 + }, + { + "name": "transpose", + "long_name": "transpose( a , axes = None )", + "filename": "oldnumeric.py", + "nloc": 3, + "complexity": 1, + "token_count": 27, + "parameters": [ + "a", + "axes" + ], + "start_line": 209, + "end_line": 215, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 7, + "top_nesting_level": 0 + }, + { + "name": "sort", + "long_name": "sort( a , axis = - 1 )", + "filename": "oldnumeric.py", + "nloc": 4, + "complexity": 1, + "token_count": 29, + "parameters": [ + "a", + "axis" + ], + "start_line": 217, + "end_line": 222, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 6, + "top_nesting_level": 0 + }, + { + "name": "argsort", + "long_name": "argsort( a , axis = - 1 )", + "filename": "oldnumeric.py", + "nloc": 3, + "complexity": 1, + "token_count": 28, + "parameters": [ + "a", + "axis" + ], + "start_line": 224, + "end_line": 229, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 6, + "top_nesting_level": 0 + }, + { + "name": "argmax", + "long_name": "argmax( a , axis = - 1 )", + "filename": "oldnumeric.py", + "nloc": 3, + "complexity": 1, + "token_count": 28, + "parameters": [ + "a", + "axis" + ], + "start_line": 231, + "end_line": 236, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 6, + "top_nesting_level": 0 + }, + { + "name": "argmin", + "long_name": "argmin( a , axis = - 1 )", + "filename": "oldnumeric.py", + "nloc": 3, + "complexity": 1, + "token_count": 28, + "parameters": [ + "a", + "axis" + ], + "start_line": 238, + "end_line": 243, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 6, + "top_nesting_level": 0 + }, + { + "name": "searchsorted", + "long_name": "searchsorted( a , v )", + "filename": "oldnumeric.py", + "nloc": 3, + "complexity": 1, + "token_count": 25, + "parameters": [ + "a", + "v" + ], + "start_line": 245, + "end_line": 249, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 5, + "top_nesting_level": 0 + }, + { + "name": "resize", + "long_name": "resize( a , new_shape )", + "filename": "oldnumeric.py", + "nloc": 18, + "complexity": 6, + "token_count": 137, + "parameters": [ + "a", + "new_shape" + ], + "start_line": 251, + "end_line": 280, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 30, + "top_nesting_level": 0 + }, + { + "name": "squeeze", + "long_name": "squeeze( a )", + "filename": "oldnumeric.py", + "nloc": 3, + "complexity": 1, + "token_count": 15, + "parameters": [ + "a" + ], + "start_line": 282, + "end_line": 284, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 3, + "top_nesting_level": 0 + }, + { + "name": "diagonal", + "long_name": "diagonal( a , offset = 0 , axis1 = 0 , axis2 = 1 )", + "filename": "oldnumeric.py", + "nloc": 2, + "complexity": 1, + "token_count": 32, + "parameters": [ + "a", + "offset", + "axis1", + "axis2" + ], + "start_line": 286, + "end_line": 290, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 5, + "top_nesting_level": 0 + }, + { + "name": "trace", + "long_name": "trace( a , offset = 0 , axis1 = 0 , axis2 = 1 , dtype = None )", + "filename": "oldnumeric.py", + "nloc": 2, + "complexity": 1, + "token_count": 38, + "parameters": [ + "a", + "offset", + "axis1", + "axis2", + "dtype" + ], + "start_line": 292, + "end_line": 296, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 5, + "top_nesting_level": 0 + }, + { + "name": "ravel", + "long_name": "ravel( m )", + "filename": "oldnumeric.py", + "nloc": 2, + "complexity": 1, + "token_count": 15, + "parameters": [ + "m" + ], + "start_line": 298, + "end_line": 302, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 5, + "top_nesting_level": 0 + }, + { + "name": "nonzero", + "long_name": "nonzero( a )", + "filename": "oldnumeric.py", + "nloc": 2, + "complexity": 1, + "token_count": 15, + "parameters": [ + "a" + ], + "start_line": 304, + "end_line": 308, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 5, + "top_nesting_level": 0 + }, + { + "name": "shape", + "long_name": "shape( a )", + "filename": "oldnumeric.py", + "nloc": 5, + "complexity": 2, + "token_count": 22, + "parameters": [ + "a" + ], + "start_line": 310, + "end_line": 317, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 8, + "top_nesting_level": 0 + }, + { + "name": "compress", + "long_name": "compress( condition , m , axis = - 1 )", + "filename": "oldnumeric.py", + "nloc": 2, + "complexity": 1, + "token_count": 25, + "parameters": [ + "condition", + "m", + "axis" + ], + "start_line": 319, + "end_line": 323, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 5, + "top_nesting_level": 0 + }, + { + "name": "clip", + "long_name": "clip( m , m_min , m_max )", + "filename": "oldnumeric.py", + "nloc": 2, + "complexity": 1, + "token_count": 22, + "parameters": [ + "m", + "m_min", + "m_max" + ], + "start_line": 325, + "end_line": 330, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 6, + "top_nesting_level": 0 + }, + { + "name": "sum", + "long_name": "sum( x , axis = 0 , dtype = None )", + "filename": "oldnumeric.py", + "nloc": 4, + "complexity": 2, + "token_count": 39, + "parameters": [ + "x", + "axis", + "dtype" + ], + "start_line": 332, + "end_line": 355, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 24, + "top_nesting_level": 0 + }, + { + "name": "product", + "long_name": "product( x , axis = 0 , dtype = None )", + "filename": "oldnumeric.py", + "nloc": 2, + "complexity": 1, + "token_count": 26, + "parameters": [ + "x", + "axis", + "dtype" + ], + "start_line": 357, + "end_line": 359, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 3, + "top_nesting_level": 0 + }, + { + "name": "sometrue", + "long_name": "sometrue( x , axis = 0 )", + "filename": "oldnumeric.py", + "nloc": 2, + "complexity": 1, + "token_count": 20, + "parameters": [ + "x", + "axis" + ], + "start_line": 361, + "end_line": 363, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 3, + "top_nesting_level": 0 + }, + { + "name": "alltrue", + "long_name": "alltrue( x , axis = 0 )", + "filename": "oldnumeric.py", + "nloc": 2, + "complexity": 1, + "token_count": 20, + "parameters": [ + "x", + "axis" + ], + "start_line": 365, + "end_line": 367, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 3, + "top_nesting_level": 0 + }, + { + "name": "any", + "long_name": "any( x , axis = None )", + "filename": "oldnumeric.py", + "nloc": 2, + "complexity": 1, + "token_count": 20, + "parameters": [ + "x", + "axis" + ], + "start_line": 369, + "end_line": 372, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 4, + "top_nesting_level": 0 + }, + { + "name": "all", + "long_name": "all( x , axis = None )", + "filename": "oldnumeric.py", + "nloc": 2, + "complexity": 1, + "token_count": 20, + "parameters": [ + "x", + "axis" + ], + "start_line": 374, + "end_line": 377, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 4, + "top_nesting_level": 0 + }, + { + "name": "cumsum", + "long_name": "cumsum( x , axis = 0 , dtype = None )", + "filename": "oldnumeric.py", + "nloc": 2, + "complexity": 1, + "token_count": 26, + "parameters": [ + "x", + "axis", + "dtype" + ], + "start_line": 379, + "end_line": 381, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 3, + "top_nesting_level": 0 + }, + { + "name": "cumproduct", + "long_name": "cumproduct( x , axis = 0 , dtype = None )", + "filename": "oldnumeric.py", + "nloc": 2, + "complexity": 1, + "token_count": 26, + "parameters": [ + "x", + "axis", + "dtype" + ], + "start_line": 383, + "end_line": 385, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 3, + "top_nesting_level": 0 + }, + { + "name": "ptp", + "long_name": "ptp( a , axis = 0 )", + "filename": "oldnumeric.py", + "nloc": 2, + "complexity": 1, + "token_count": 20, + "parameters": [ + "a", + "axis" + ], + "start_line": 387, + "end_line": 390, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 4, + "top_nesting_level": 0 + }, + { + "name": "amax", + "long_name": "amax( a , axis = 0 )", + "filename": "oldnumeric.py", + "nloc": 2, + "complexity": 1, + "token_count": 20, + "parameters": [ + "a", + "axis" + ], + "start_line": 392, + "end_line": 395, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 4, + "top_nesting_level": 0 + }, + { + "name": "amin", + "long_name": "amin( a , axis = 0 )", + "filename": "oldnumeric.py", + "nloc": 2, + "complexity": 1, + "token_count": 20, + "parameters": [ + "a", + "axis" + ], + "start_line": 397, + "end_line": 400, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 4, + "top_nesting_level": 0 + }, + { + "name": "alen", + "long_name": "alen( a )", + "filename": "oldnumeric.py", + "nloc": 2, + "complexity": 1, + "token_count": 14, + "parameters": [ + "a" + ], + "start_line": 402, + "end_line": 405, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 4, + "top_nesting_level": 0 + }, + { + "name": "prod", + "long_name": "prod( a , axis = 0 )", + "filename": "oldnumeric.py", + "nloc": 2, + "complexity": 1, + "token_count": 20, + "parameters": [ + "a", + "axis" + ], + "start_line": 407, + "end_line": 410, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 4, + "top_nesting_level": 0 + }, + { + "name": "cumprod", + "long_name": "cumprod( a , axis = 0 )", + "filename": "oldnumeric.py", + "nloc": 2, + "complexity": 1, + "token_count": 20, + "parameters": [ + "a", + "axis" + ], + "start_line": 412, + "end_line": 415, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 4, + "top_nesting_level": 0 + }, + { + "name": "ndim", + "long_name": "ndim( a )", + "filename": "oldnumeric.py", + "nloc": 5, + "complexity": 2, + "token_count": 21, + "parameters": [ + "a" + ], + "start_line": 417, + "end_line": 421, + "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": 423, + "end_line": 430, + "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": 432, + "end_line": 443, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 12, + "top_nesting_level": 0 + }, + { + "name": "round_", + "long_name": "round_( a , decimals = 0 )", + "filename": "oldnumeric.py", + "nloc": 19, + "complexity": 6, + "token_count": 188, + "parameters": [ + "a", + "decimals" + ], + "start_line": 445, + "end_line": 470, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 26, + "top_nesting_level": 0 + }, + { + "name": "mean", + "long_name": "mean( a , axis = 0 , dtype = None )", + "filename": "oldnumeric.py", + "nloc": 2, + "complexity": 1, + "token_count": 25, + "parameters": [ + "a", + "axis", + "dtype" + ], + "start_line": 474, + "end_line": 475, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 2, + "top_nesting_level": 0 + }, + { + "name": "std", + "long_name": "std( a , axis = 0 , dtype = None )", + "filename": "oldnumeric.py", + "nloc": 2, + "complexity": 1, + "token_count": 25, + "parameters": [ + "a", + "axis", + "dtype" + ], + "start_line": 477, + "end_line": 478, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 2, + "top_nesting_level": 0 + }, + { + "name": "var", + "long_name": "var( a , axis = 0 , dtype = None )", + "filename": "oldnumeric.py", + "nloc": 2, + "complexity": 1, + "token_count": 25, + "parameters": [ + "a", + "axis", + "dtype" + ], + "start_line": 480, + "end_line": 481, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 2, + "top_nesting_level": 0 + } + ], + "changed_methods": [], + "nloc": 277, + "complexity": 61, + "token_count": 2037, + "diff_parsed": { + "added": [ + " 'UInt8','UInt16','UInt32', 'UnsignedInt32', 'UnsignedInteger',", + " 'PyObject', 'Float32', 'Float64', 'Float16', 'Float8',", + " 'Complex32', 'Complex64', 'Complex8', 'Complex16',", + "Float16='f'", + "Float8='f'", + "UnsignedInteger='L'", + "Complex8='F'", + "Complex16='F'", + "" + ], + "deleted": [ + " 'UInt8','UInt16','UInt32', 'UnsignedInt32',", + " 'PyObject', 'Float32', 'Float64',", + " 'Complex32', 'Complex64'," + ] + } + } + ] + }, + { + "hash": "ebb9354ecc7a06bdbdc033340e45511bfd110085", + "msg": "Cleanups of numpy.distutils.misc_util\nMostly covers replacing typechecks using type() with two routines: is_sequence and is_string.", + "author": { + "name": "cookedm", + "email": "cookedm@localhost" + }, + "committer": { + "name": "cookedm", + "email": "cookedm@localhost" + }, + "author_date": "2006-01-27T20:57:25+00:00", + "author_timezone": 0, + "committer_date": "2006-01-27T20:57:25+00:00", + "committer_timezone": 0, + "branches": [ + "main" + ], + "in_main_branch": true, + "merge": false, + "parents": [ + "c6c45c053488a63057e7758dc9531f91d86cc5ce" + ], + "project_name": "repo_copy", + "project_path": "/tmp/tmppy2o86q9/repo_copy", + "deletions": 29, + "insertions": 52, + "lines": 81, + "files": 1, + "dmm_unit_size": 0.9166666666666666, + "dmm_unit_complexity": 0.8333333333333334, + "dmm_unit_interfacing": 0.8333333333333334, + "modified_files": [ + { + "old_path": "numpy/distutils/misc_util.py", + "new_path": "numpy/distutils/misc_util.py", + "filename": "misc_util.py", + "extension": "py", + "change_type": "MODIFY", + "diff": "@@ -3,7 +3,6 @@\n import sys\n import imp\n import copy\n-import types\n import glob\n \n __all__ = ['Configuration', 'get_numpy_include_dirs', 'default_config_dict',\n@@ -117,13 +116,25 @@ def _get_f90_modules(source):\n f.close()\n return modules\n \n+def is_string(s):\n+ return isinstance(s, str)\n+\n def all_strings(lst):\n \"\"\" Return True if all items in lst are string objects. \"\"\"\n for item in lst:\n- if type(item) is not types.StringType:\n+ if not is_string(item):\n return False\n return True\n \n+def is_sequence(seq):\n+ if is_string(seq):\n+ return False\n+ try:\n+ len(seq)\n+ except:\n+ return False\n+ return True\n+\n def has_f_sources(sources):\n \"\"\" Return True if sources contains Fortran files \"\"\"\n for source in sources:\n@@ -185,7 +196,7 @@ def get_dependencies(sources):\n def is_local_src_dir(directory):\n \"\"\" Return true if directory is local directory.\n \"\"\"\n- if type(directory) is not type(''):\n+ if not is_string(directory):\n return False\n abs_dir = os.path.abspath(directory)\n c = os.path.commonprefix([os.getcwd(),abs_dir])\n@@ -214,7 +225,7 @@ def _gsf_visit_func(filenames,dirname,names):\n def get_ext_source_files(ext):\n # Get sources and any include files in the same directory.\n filenames = []\n- sources = filter(lambda s:type(s) is types.StringType,ext.sources)\n+ sources = filter(is_string, ext.sources)\n filenames.extend(sources)\n filenames.extend(get_dependencies(sources))\n for d in ext.depends:\n@@ -225,13 +236,13 @@ def get_ext_source_files(ext):\n return filenames\n \n def get_script_files(scripts):\n- scripts = filter(lambda s:type(s) is types.StringType,scripts)\n+ scripts = filter(is_string, scripts)\n return scripts\n \n def get_lib_source_files(lib):\n filenames = []\n sources = lib[1].get('sources',[])\n- sources = filter(lambda s:type(s) is types.StringType,sources)\n+ sources = filter(is_string, sources)\n filenames.extend(sources)\n filenames.extend(get_dependencies(sources))\n depends = lib[1].get('depends',[])\n@@ -243,7 +254,7 @@ def get_lib_source_files(lib):\n return filenames\n \n def get_data_files(data):\n- if type(data) is types.StringType:\n+ if is_string(data):\n return [data]\n sources = data[1]\n filenames = []\n@@ -252,13 +263,13 @@ def get_data_files(data):\n continue\n if is_local_src_dir(s):\n os.path.walk(s,_gsf_visit_func,filenames)\n- elif type(s) is type(''):\n+ elif is_string(s):\n if os.path.isfile(s):\n filenames.append(s)\n else:\n print 'Not existing data file:',s\n else:\n- raise TypeError,`s`\n+ raise TypeError,repr(s)\n return filenames\n \n def dot_join(*args):\n@@ -290,12 +301,22 @@ def __init__(self,\n package_path=None,\n **attrs):\n \"\"\" Construct configuration instance of a package.\n+\n+ package_name -- name of the package\n+ Ex.: 'distutils'\n+ parent_name -- name of the parent package\n+ Ex.: 'numpy'\n+ top_path -- directory of the toplevel package\n+ Ex.: the directory where the numpy package source sits\n+ package_path -- directory of package. Will be computed by magic from the\n+ directory of the caller module if not specified\n+ Ex.: the directory where numpy.distutils is\n \"\"\"\n self.name = dot_join(parent_name, package_name)\n \n caller_frame = get_frame(1)\n caller_name = eval('__name__',caller_frame.f_globals,caller_frame.f_locals)\n- \n+\n self.local_path = get_path(caller_name, top_path)\n if top_path is None:\n top_path = self.local_path\n@@ -303,8 +324,10 @@ def __init__(self,\n package_path = self.local_path\n elif os.path.isdir(os.path.join(self.local_path,package_path)):\n package_path = os.path.join(self.local_path,package_path)\n- assert os.path.isdir(package_path),`package_path`\n+ if not os.path.isdir(package_path):\n+ raise ValueError(\"%r is not a directory\" % (package_path,))\n self.top_path = top_path\n+ self.package_path = package_path\n \n self.list_keys = copy.copy(self._list_keys)\n self.dict_keys = copy.copy(self._dict_keys)\n@@ -322,16 +345,16 @@ def __init__(self,\n continue\n a = attrs[n]\n setattr(self,n,a)\n- if type(a) is types.ListType:\n+ if isinstance(a, list):\n self.list_keys.append(n)\n- elif type(a) is types.DictType:\n+ elif isinstance(a, dict):\n self.dict_keys.append(n)\n else:\n self.extra_keys.append(n)\n \n if os.path.exists(os.path.join(package_path,'__init__.py')):\n self.packages.append(self.name)\n- self.package_dir[self.name] = package_path \n+ self.package_dir[self.name] = package_path\n return\n \n def todict(self):\n@@ -352,7 +375,7 @@ def __dict__(self):\n \n def get_distribution(self):\n import distutils.core\n- dist = distutils.core._setup_distribution \n+ dist = distutils.core._setup_distribution\n return dist\n \n def get_subpackage(self,subpackage_name,subpackage_path=None):\n@@ -447,12 +470,12 @@ def add_data_dir(self,data_path):\n If path is not absolute then it's datadir suffix is\n package dir + subdirname of the path.\n \"\"\"\n- if type(data_path) is type(()):\n- assert len(data_path)==2,`data_path`\n- d,data_path = data_path\n+ if is_sequence(data_path):\n+ d, data_path = data_path\n else:\n d = None\n- assert type(data_path) is type(''),`data_path`\n+ if not is_string(data_path):\n+ raise TypeError(\"not a string: %r\" % (data_path,))\n for path in self.paths(data_path):\n if not os.path.exists(path):\n print 'Not existing data path',path\n@@ -484,30 +507,30 @@ def add_data_files(self,*files):\n data_dict = {}\n new_files = []\n for p in files:\n- if type(p) is not type(()):\n+ if not is_sequence(p):\n d = os.path.join(*(self.name.split('.')))\n- if type(p) is type('') and not os.path.isabs(p):\n+ if is_string(p) and not os.path.isabs(p):\n d = appendpath(d,os.path.dirname(p))\n p = (d,p)\n new_files.append(p)\n files = []\n for prefix,filepattern in new_files:\n- if type(filepattern) is type(''):\n+ if is_string(filepattern):\n file_list = self.paths(filepattern)\n elif callable(filepattern):\n file_list = [filepattern]\n else:\n file_list = self.paths(*filepattern)\n \n- nof_path_components = [len(f.split(os.sep)) \\\n- for f in file_list if type(f) is type('')]\n+ nof_path_components = [len(f.split(os.sep))\n+ for f in file_list if is_string(f)]\n if nof_path_components:\n min_path_components = min(nof_path_components)-1\n else:\n min_path_components = 0\n \n for f in file_list:\n- if type(f) is type(''):\n+ if is_string(f):\n extra_path_components = f.split(os.sep)[min_path_components:-1]\n p = os.path.join(*([prefix]+extra_path_components))\n else:\n@@ -522,7 +545,6 @@ def add_data_files(self,*files):\n dist.data_files.extend(data_dict.items())\n else:\n self.data_files.extend(data_dict.items())\n- return \n \n ### XXX Implement add_py_modules\n \n@@ -546,10 +568,11 @@ def add_headers(self,*files):\n \"\"\"\n headers = []\n for path in files:\n- if type(path) is type(''):\n+ if is_string(path):\n [headers.append((self.name,p)) for p in self.paths(path)]\n else:\n- assert type(path) in [type(()),type([])] and len(path)==2,`path`\n+ if not isinstance(path, (tuple, list)) or len(path) != 2:\n+ raise TypeError(repr(path))\n [headers.append((path[0],p)) for p in self.paths(path[1])]\n dist = self.get_distribution()\n if dist is not None:\n@@ -760,7 +783,7 @@ def have_f90c(self):\n def append_to(self, extlib):\n \"\"\" Append libraries, include_dirs to extension or library item.\n \"\"\"\n- if type(extlib) is type(()):\n+ if is_sequence(extlib):\n lib_name, build_info = extlib\n dict_append(build_info,\n libraries=self.libraries,\n", + "added_lines": 52, + "deleted_lines": 29, + "source_code": "import os\nimport re\nimport sys\nimport imp\nimport copy\nimport glob\n\n__all__ = ['Configuration', 'get_numpy_include_dirs', 'default_config_dict',\n 'dict_append', 'appendpath', 'generate_config_py',\n 'generate_svn_version_py', 'get_cmd', 'allpath',\n 'terminal_has_colors', 'red_text', 'green_text', 'yellow_text',\n 'blue_text', 'cyan_text', 'cyg2win32', 'all_strings',\n 'has_f_sources', 'has_cxx_sources', 'filter_sources',\n 'get_dependencies', 'is_local_src_dir', 'get_ext_source_files',\n 'get_script_files', 'get_lib_source_files', 'get_data_files',\n 'dot_join', 'get_frame']\n\ndef allpath(name):\n \"Convert a /-separated pathname to one using the OS's path separator.\"\n splitted = name.split('/')\n return os.path.join(*splitted)\n\ndef get_path(mod_name,parent_path=None):\n \"\"\" Return path of the module.\n\n Returned path is relative to parent_path when given,\n otherwise it is absolute path.\n \"\"\"\n if mod_name == '__main__':\n d = os.path.abspath('.')\n elif mod_name == '__builtin__':\n #builtin if/then added by Pearu for use in core.run_setup. \n d = os.path.dirname(os.path.abspath(sys.argv[0]))\n else:\n __import__(mod_name)\n mod = sys.modules[mod_name]\n file = mod.__file__\n d = os.path.dirname(os.path.abspath(file))\n if parent_path is not None:\n pd = os.path.abspath(parent_path)\n if pd==d[:len(pd)]:\n d = d[len(pd)+1:]\n return d or '.'\n\n# Hooks for colored terminal output.\n# See also http://www.livinglogic.de/Python/ansistyle\ndef terminal_has_colors():\n if sys.platform=='cygwin' and not os.environ.has_key('USE_COLOR'):\n # Avoid importing curses that causes illegal operation\n # with a message:\n # PYTHON2 caused an invalid page fault in\n # module CYGNURSES7.DLL as 015f:18bbfc28\n # Details: Python 2.3.3 [GCC 3.3.1 (cygming special)]\n # ssh to Win32 machine from debian\n # curses.version is 2.2\n # CYGWIN_98-4.10, release 1.5.7(0.109/3/2))\n return 0\n if hasattr(sys.stdout,'isatty') and sys.stdout.isatty(): \n try:\n import curses\n curses.setupterm()\n if (curses.tigetnum(\"colors\") >= 0\n and curses.tigetnum(\"pairs\") >= 0\n and ((curses.tigetstr(\"setf\") is not None \n and curses.tigetstr(\"setb\") is not None) \n or (curses.tigetstr(\"setaf\") is not None\n and curses.tigetstr(\"setab\") is not None)\n or curses.tigetstr(\"scp\") is not None)):\n return 1\n except Exception,msg:\n pass\n return 0\n\nif terminal_has_colors():\n def red_text(s): return '\\x1b[31m%s\\x1b[0m'%s\n def green_text(s): return '\\x1b[32m%s\\x1b[0m'%s\n def yellow_text(s): return '\\x1b[33m%s\\x1b[0m'%s\n def blue_text(s): return '\\x1b[34m%s\\x1b[0m'%s\n def cyan_text(s): return '\\x1b[35m%s\\x1b[0m'%s\nelse:\n def red_text(s): return s\n def green_text(s): return s\n def yellow_text(s): return s\n def cyan_text(s): return s\n def blue_text(s): return s\n\n#########################\n\ndef cyg2win32(path):\n if sys.platform=='cygwin' and path.startswith('/cygdrive'):\n path = path[10] + ':' + os.path.normcase(path[11:])\n return path\n\n#########################\n\n#XXX need support for .C that is also C++\ncxx_ext_match = re.compile(r'.*[.](cpp|cxx|cc)\\Z',re.I).match\nfortran_ext_match = re.compile(r'.*[.](f90|f95|f77|for|ftn|f)\\Z',re.I).match\nf90_ext_match = re.compile(r'.*[.](f90|f95)\\Z',re.I).match\nf90_module_name_match = re.compile(r'\\s*module\\s*(?P[\\w_]+)',re.I).match\ndef _get_f90_modules(source):\n \"\"\" Return a list of Fortran f90 module names that\n given source file defines.\n \"\"\"\n if not f90_ext_match(source):\n return []\n modules = []\n f = open(source,'r')\n f_readlines = getattr(f,'xreadlines',f.readlines)\n for line in f_readlines():\n m = f90_module_name_match(line)\n if m:\n name = m.group('name')\n modules.append(name)\n # break # XXX can we assume that there is one module per file?\n f.close()\n return modules\n\ndef is_string(s):\n return isinstance(s, str)\n\ndef all_strings(lst):\n \"\"\" Return True if all items in lst are string objects. \"\"\"\n for item in lst:\n if not is_string(item):\n return False\n return True\n\ndef is_sequence(seq):\n if is_string(seq):\n return False\n try:\n len(seq)\n except:\n return False\n return True\n\ndef has_f_sources(sources):\n \"\"\" Return True if sources contains Fortran files \"\"\"\n for source in sources:\n if fortran_ext_match(source):\n return True\n return False\n\ndef has_cxx_sources(sources):\n \"\"\" Return True if sources contains C++ files \"\"\"\n for source in sources:\n if cxx_ext_match(source):\n return True\n return False\n\ndef filter_sources(sources):\n \"\"\" Return four lists of filenames containing\n C, C++, Fortran, and Fortran 90 module sources,\n respectively.\n \"\"\"\n c_sources = []\n cxx_sources = []\n f_sources = []\n fmodule_sources = []\n for source in sources:\n if fortran_ext_match(source):\n modules = _get_f90_modules(source)\n if modules:\n fmodule_sources.append(source)\n else:\n f_sources.append(source)\n elif cxx_ext_match(source):\n cxx_sources.append(source)\n else:\n c_sources.append(source) \n return c_sources, cxx_sources, f_sources, fmodule_sources\n\n\ndef _get_headers(directory_list):\n # get *.h files from list of directories\n headers = []\n for dir in directory_list:\n head = glob.glob(os.path.join(dir,\"*.h\")) #XXX: *.hpp files??\n headers.extend(head)\n return headers\n\ndef _get_directories(list_of_sources):\n # get unique directories from list of sources.\n direcs = []\n for file in list_of_sources:\n dir = os.path.split(file)\n if dir[0] != '' and not dir[0] in direcs:\n direcs.append(dir[0])\n return direcs\n\ndef get_dependencies(sources):\n #XXX scan sources for include statements\n return _get_headers(_get_directories(sources))\n\ndef is_local_src_dir(directory):\n \"\"\" Return true if directory is local directory.\n \"\"\"\n if not is_string(directory):\n return False\n abs_dir = os.path.abspath(directory)\n c = os.path.commonprefix([os.getcwd(),abs_dir])\n new_dir = abs_dir[len(c):].split(os.sep)\n if new_dir and not new_dir[0]:\n new_dir = new_dir[1:]\n if new_dir and new_dir[0]=='build':\n return False\n new_dir = os.sep.join(new_dir)\n return os.path.isdir(new_dir)\n\ndef _gsf_visit_func(filenames,dirname,names):\n if os.path.basename(dirname) in ['CVS','.svn','build']:\n names[:] = []\n return\n for name in names:\n if name[-1] in \"~#\":\n continue\n fullname = os.path.join(dirname,name)\n ext = os.path.splitext(fullname)[1]\n if ext and ext in ['.pyc','.o']:\n continue\n if os.path.isfile(fullname):\n filenames.append(fullname)\n\ndef get_ext_source_files(ext):\n # Get sources and any include files in the same directory.\n filenames = []\n sources = filter(is_string, ext.sources)\n filenames.extend(sources)\n filenames.extend(get_dependencies(sources))\n for d in ext.depends:\n if is_local_src_dir(d):\n os.path.walk(d,_gsf_visit_func,filenames)\n elif os.path.isfile(d):\n filenames.append(d)\n return filenames\n\ndef get_script_files(scripts):\n scripts = filter(is_string, scripts)\n return scripts\n\ndef get_lib_source_files(lib):\n filenames = []\n sources = lib[1].get('sources',[])\n sources = filter(is_string, sources)\n filenames.extend(sources)\n filenames.extend(get_dependencies(sources))\n depends = lib[1].get('depends',[])\n for d in depends:\n if is_local_src_dir(d):\n os.path.walk(d,_gsf_visit_func,filenames)\n elif os.path.isfile(d):\n filenames.append(d)\n return filenames\n\ndef get_data_files(data):\n if is_string(data):\n return [data]\n sources = data[1]\n filenames = []\n for s in sources:\n if callable(s):\n continue\n if is_local_src_dir(s):\n os.path.walk(s,_gsf_visit_func,filenames)\n elif is_string(s):\n if os.path.isfile(s):\n filenames.append(s)\n else:\n print 'Not existing data file:',s\n else:\n raise TypeError,repr(s)\n return filenames\n\ndef dot_join(*args):\n return '.'.join(filter(None,args))\n\ndef get_frame(level=0):\n try:\n return sys._getframe(level+1)\n except AttributeError:\n frame = sys.exc_info()[2].tb_frame\n for i in range(level+1):\n frame = frame.f_back\n return frame\n\n######################\n\nclass Configuration:\n\n _list_keys = ['packages','ext_modules','data_files','include_dirs',\n 'libraries','headers','scripts','py_modules']\n _dict_keys = ['package_dir']\n\n numpy_include_dirs = []\n\n def __init__(self,\n package_name=None,\n parent_name=None,\n top_path=None,\n package_path=None,\n **attrs):\n \"\"\" Construct configuration instance of a package.\n\n package_name -- name of the package\n Ex.: 'distutils'\n parent_name -- name of the parent package\n Ex.: 'numpy'\n top_path -- directory of the toplevel package\n Ex.: the directory where the numpy package source sits\n package_path -- directory of package. Will be computed by magic from the\n directory of the caller module if not specified\n Ex.: the directory where numpy.distutils is\n \"\"\"\n self.name = dot_join(parent_name, package_name)\n\n caller_frame = get_frame(1)\n caller_name = eval('__name__',caller_frame.f_globals,caller_frame.f_locals)\n\n self.local_path = get_path(caller_name, top_path)\n if top_path is None:\n top_path = self.local_path\n if package_path is None:\n package_path = self.local_path\n elif os.path.isdir(os.path.join(self.local_path,package_path)):\n package_path = os.path.join(self.local_path,package_path)\n if not os.path.isdir(package_path):\n raise ValueError(\"%r is not a directory\" % (package_path,))\n self.top_path = top_path\n self.package_path = package_path\n\n self.list_keys = copy.copy(self._list_keys)\n self.dict_keys = copy.copy(self._dict_keys)\n\n for n in self.list_keys:\n setattr(self,n,copy.copy(attrs.get(n,[])))\n\n for n in self.dict_keys:\n setattr(self,n,copy.copy(attrs.get(n,{})))\n\n known_keys = self.list_keys + self.dict_keys\n self.extra_keys = []\n for n in attrs.keys():\n if n in known_keys:\n continue\n a = attrs[n]\n setattr(self,n,a)\n if isinstance(a, list):\n self.list_keys.append(n)\n elif isinstance(a, dict):\n self.dict_keys.append(n)\n else:\n self.extra_keys.append(n)\n\n if os.path.exists(os.path.join(package_path,'__init__.py')):\n self.packages.append(self.name)\n self.package_dir[self.name] = package_path\n return\n\n def todict(self):\n \"\"\" Return configuration distionary suitable for passing\n to distutils.core.setup() function.\n \"\"\"\n d = {}\n for n in self.list_keys + self.dict_keys + self.extra_keys:\n a = getattr(self,n)\n if a:\n d[n] = a\n if self.name:\n d['name'] = self.name\n return d\n\n def __dict__(self):\n return self.todict()\n\n def get_distribution(self):\n import distutils.core\n dist = distutils.core._setup_distribution\n return dist\n\n def get_subpackage(self,subpackage_name,subpackage_path=None):\n \"\"\" Return subpackage configuration.\n \"\"\"\n if subpackage_name is None:\n assert subpackage_path is not None\n subpackage_name = os.path.basename(subpackage_path)\n l = subpackage_name.split('.')\n if subpackage_path is None:\n subpackage_path = os.path.join(*([self.local_path]+l))\n if '*' in subpackage_name:\n dirs = filter(os.path.isdir,glob.glob(subpackage_path))\n config_list = []\n for d in dirs:\n if not os.path.isfile(os.path.join(d,'__init__.py')):\n continue\n n = '.'.join(d.split(os.sep)[-len(l):])\n c = self.get_subpackage(n)\n if c:\n config_list.append(c)\n return config_list\n else:\n subpackage_path = os.path.join(*([subpackage_path]+l[:-1]))\n subpackage_path = self._fix_paths([subpackage_path])[0]\n\n setup_py = os.path.join(subpackage_path,'setup.py')\n if not os.path.isfile(setup_py):\n setup_py = os.path.join(subpackage_path,'setup_%s.py' % (subpackage_name))\n\n if not os.path.isfile(setup_py):\n print 'Assuming default configuration '\\\n '(%s/{setup_%s,setup}.py was not found)' \\\n % (os.path.dirname(setup_py),subpackage_name)\n config = Configuration(subpackage_name,self.name,\n self.top_path,subpackage_path)\n else:\n # In case setup_py imports local modules:\n sys.path.insert(0,os.path.dirname(setup_py))\n try:\n info = (open(setup_py),setup_py,('.py','U',1))\n setup_name = os.path.splitext(os.path.basename(setup_py))[0]\n n = dot_join(self.name,setup_name)\n setup_module = imp.load_module('_'.join(n.split('.')),*info)\n\n if not hasattr(setup_module,'configuration'):\n print 'Assuming default configuration '\\\n '(%s does not define configuration())' % (setup_module)\n config = Configuration(subpackage_name,self.name,\n self.top_path,subpackage_path)\n else:\n args = (self.name,)\n if setup_module.configuration.func_code.co_argcount>1:\n args = args + (self.top_path,)\n config = setup_module.configuration(*args)\n\n finally:\n del sys.path[0]\n\n return config\n\n def add_subpackage(self,subpackage_name,subpackage_path=None):\n \"\"\" Add subpackage to configuration.\n \"\"\"\n config = self.get_subpackage(subpackage_name,subpackage_path)\n if not isinstance(config, list):\n config_list = [config]\n else:\n config_list = config\n for config in config_list:\n if not config:\n print 'No configuration returned, assuming unavailable.'\n else:\n if isinstance(config,Configuration):\n print 'Appending %s configuration to %s' % (config.name,self.name)\n self.dict_append(**config.todict())\n else:\n print 'Appending %s configuration to %s' % (config.get('name'),self.name)\n self.dict_append(**config)\n\n dist = self.get_distribution()\n if dist is not None:\n print 'distutils distribution has been initialized, it may be too late to add a subpackage', subpackage_name\n return\n\n def add_data_dir(self,data_path):\n \"\"\" Recursively add files under data_path to data_files list.\n Argument can be either\n - 2-sequence (,)\n - path to data directory where python datadir suffix defaults\n to package dir.\n If path is not absolute then it's datadir suffix is\n package dir + subdirname of the path.\n \"\"\"\n if is_sequence(data_path):\n d, data_path = data_path\n else:\n d = None\n if not is_string(data_path):\n raise TypeError(\"not a string: %r\" % (data_path,))\n for path in self.paths(data_path):\n if not os.path.exists(path):\n print 'Not existing data path',path\n continue\n filenames = []\n os.path.walk(path, _gsf_visit_func,filenames)\n if not os.path.isabs(path):\n if d is None:\n ds = os.path.join(*(self.name.split('.')+[data_path]))\n else:\n ds = os.path.join(d,data_path)\n self.add_data_files((ds,filenames))\n else:\n if d is None:\n self.add_data_files(*filenames)\n else:\n self.add_data_files((d,filenames))\n return\n\n def add_data_files(self,*files):\n \"\"\" Add data files to configuration data_files.\n Argument(s) can be either\n - 2-sequence (,)\n - paths to data files where python datadir prefix defaults\n to package dir.\n If path is not absolute then it's datadir prefix is\n package dir + dirname of the path.\n \"\"\"\n data_dict = {}\n new_files = []\n for p in files:\n if not is_sequence(p):\n d = os.path.join(*(self.name.split('.')))\n if is_string(p) and not os.path.isabs(p):\n d = appendpath(d,os.path.dirname(p))\n p = (d,p)\n new_files.append(p)\n files = []\n for prefix,filepattern in new_files:\n if is_string(filepattern):\n file_list = self.paths(filepattern)\n elif callable(filepattern):\n file_list = [filepattern]\n else:\n file_list = self.paths(*filepattern)\n\n nof_path_components = [len(f.split(os.sep))\n for f in file_list if is_string(f)]\n if nof_path_components:\n min_path_components = min(nof_path_components)-1\n else:\n min_path_components = 0\n\n for f in file_list:\n if is_string(f):\n extra_path_components = f.split(os.sep)[min_path_components:-1]\n p = os.path.join(*([prefix]+extra_path_components))\n else:\n p = prefix\n if not data_dict.has_key(p):\n data_dict[p] = [f]\n else:\n data_dict[p].append(f)\n\n dist = self.get_distribution()\n if dist is not None:\n dist.data_files.extend(data_dict.items())\n else:\n self.data_files.extend(data_dict.items())\n\n ### XXX Implement add_py_modules\n \n def add_include_dirs(self,*paths):\n \"\"\" Add paths to configuration include directories.\n \"\"\"\n include_dirs = self._fix_paths(paths)\n dist = self.get_distribution()\n if dist is not None:\n dist.include_dirs.extend(include_dirs)\n else:\n self.include_dirs.extend(include_dirs)\n return\n\n def add_headers(self,*files):\n \"\"\" Add installable headers to configuration.\n Argument(s) can be either\n - 2-sequence (,)\n - path(s) to header file(s) where python includedir suffix will default\n to package name.\n \"\"\"\n headers = []\n for path in files:\n if is_string(path):\n [headers.append((self.name,p)) for p in self.paths(path)]\n else:\n if not isinstance(path, (tuple, list)) or len(path) != 2:\n raise TypeError(repr(path))\n [headers.append((path[0],p)) for p in self.paths(path[1])]\n dist = self.get_distribution()\n if dist is not None:\n dist.headers.extend(headers)\n else:\n self.headers.extend(headers)\n return\n\n def _fix_paths(self,paths):\n new_paths = []\n for n in paths:\n if isinstance(n,str):\n if '*' in n or '?' in n:\n p = glob.glob(n)\n p2 = glob.glob(os.path.join(self.local_path,n))\n if p2:\n new_paths.extend(p2)\n elif p:\n new_paths.extend(p)\n else:\n new_paths.append(n)\n else:\n n2 = os.path.join(self.local_path,n)\n if os.path.exists(n2):\n new_paths.append(n2)\n else:\n new_paths.append(n)\n else:\n new_paths.append(n)\n return new_paths\n\n def paths(self,*paths):\n \"\"\" Apply glob to paths and prepend local_path if needed.\n \"\"\"\n return self._fix_paths(paths)\n\n def add_extension(self,name,sources,**kw):\n \"\"\" Add extension to configuration.\n\n Keywords:\n include_dirs, define_macros, undef_macros,\n library_dirs, libraries, runtime_library_dirs,\n extra_objects, extra_compile_args, extra_link_args,\n export_symbols, swig_opts, depends, language,\n f2py_options, module_dirs\n extra_info - dict or list of dict of keywords to be\n appended to keywords.\n \"\"\"\n ext_args = copy.copy(kw)\n ext_args['name'] = dot_join(self.name,name)\n ext_args['sources'] = sources\n\n if ext_args.has_key('extra_info'):\n extra_info = ext_args['extra_info']\n del ext_args['extra_info']\n if type(extra_info) is type({}):\n extra_info = [extra_info]\n for info in extra_info:\n assert type(info) is type({}),`info`\n dict_append(ext_args,**info)\n\n for k in ext_args.keys():\n v = ext_args[k]\n if k in ['sources','depends','include_dirs','library_dirs',\n 'module_dirs','extra_objects']:\n new_v = self._fix_paths(v)\n ext_args[k] = new_v\n\n # Resolve out-of-tree dependencies\n libraries = ext_args.get('libraries',[])\n libnames = []\n ext_args['libraries'] = []\n for libname in libraries:\n if '@' in libname:\n lname,lpath = libname.split('@',1)\n lpath = os.path.abspath(os.path.join(self.local_path,lpath))\n if os.path.isdir(lpath):\n c = self.get_subpackage(None,lpath)\n if isinstance(c,Configuration):\n c = c.todict()\n for l in [l[0] for l in c.get('libraries',[])]:\n llname = l.split('__OF__',1)[0]\n if llname == lname:\n c.pop('name',None)\n dict_append(ext_args,**c)\n break\n continue\n libnames.append(libname)\n\n ext_args['libraries'] = libnames + ext_args['libraries']\n\n from numpy.distutils.core import Extension\n ext = Extension(**ext_args)\n self.ext_modules.append(ext)\n\n dist = self.get_distribution()\n if dist is not None:\n print 'distutils distribution has been initialized, it may be too late to add an extension', name\n return ext\n\n def add_library(self,name,sources,**build_info):\n \"\"\" Add library to configuration.\n \n Valid keywords for build_info:\n depends\n macros\n include_dirs\n extra_compiler_args\n f2py_options\n \"\"\"\n build_info = copy.copy(build_info)\n name = name #+ '__OF__' + self.name\n build_info['sources'] = sources\n\n for k in build_info.keys():\n v = build_info[k]\n if k in ['sources','depends','include_dirs','library_dirs',\n 'module_dirs','extra_objects']:\n new_v = self._fix_paths(v)\n build_info[k] = new_v\n self.libraries.append((name,build_info))\n\n dist = self.get_distribution()\n if dist is not None:\n print 'distutils distribution has been initialized, it may be too late to add a library', name\n return\n\n def add_scripts(self,*files):\n \"\"\" Add scripts to configuration.\n \"\"\"\n scripts = self._fix_paths(files)\n dist = self.get_distribution()\n if dist is not None:\n dist.scripts.extend(scripts)\n else:\n self.scripts.extend(scripts)\n return\n\n def dict_append(self,**dict):\n for key in self.list_keys:\n a = getattr(self,key)\n a.extend(dict.get(key,[]))\n for key in self.dict_keys:\n a = getattr(self,key)\n a.update(dict.get(key,{}))\n known_keys = self.list_keys + self.dict_keys + self.extra_keys\n for key in dict.keys():\n if key not in known_keys and not hasattr(self,key):\n print 'Inheriting attribute %r from %r' \\\n % (key,dict.get('name','?'))\n setattr(self,key,dict[key])\n self.extra_keys.append(key)\n return\n\n def __str__(self):\n known_keys = self.list_keys + self.dict_keys + self.extra_keys\n s = '<'+5*'-' + '\\n'\n s += 'Configuration of '+self.name+':\\n'\n for k in known_keys:\n a = getattr(self,k,None)\n if a:\n s += '%s = %r\\n' % (k,a)\n s += 5*'-' + '>'\n return s\n\n def get_config_cmd(self):\n cmd = get_cmd('config')\n cmd.ensure_finalized()\n cmd.dump_source = 0\n cmd.noisy = 0\n old_path = os.environ.get('PATH')\n if old_path:\n path = os.pathsep.join(['.',old_path])\n os.environ['PATH'] = path\n return cmd\n\n def get_build_temp_dir(self):\n cmd = get_cmd('build')\n cmd.ensure_finalized()\n return cmd.build_temp\n\n def have_f77c(self):\n \"\"\" Check for availability of Fortran 77 compiler.\n Use it inside source generating function to ensure that\n setup distribution instance has been initialized.\n \"\"\"\n simple_fortran_subroutine = '''\n subroutine simple\n end\n '''\n config_cmd = self.get_config_cmd()\n flag = config_cmd.try_compile(simple_fortran_subroutine,lang='f77')\n return flag\n\n def have_f90c(self):\n \"\"\" Check for availability of Fortran 90 compiler.\n Use it inside source generating function to ensure that\n setup distribution instance has been initialized.\n \"\"\"\n simple_fortran_subroutine = '''\n subroutine simple\n end\n '''\n config_cmd = self.get_config_cmd()\n flag = config_cmd.try_compile(simple_fortran_subroutine,lang='f90')\n return flag\n\n def append_to(self, extlib):\n \"\"\" Append libraries, include_dirs to extension or library item.\n \"\"\"\n if is_sequence(extlib):\n lib_name, build_info = extlib\n dict_append(build_info,\n libraries=self.libraries,\n include_dirs=self.include_dirs)\n else:\n from numpy.distutils.core import Extension\n assert isinstance(extlib,Extension),`extlib`\n extlib.libraries.extend(self.libraries)\n extlib.include_dirs.extend(self.include_dirs)\n return\n\n def _get_svn_revision(self,path):\n \"\"\" Return path's SVN revision number.\n \"\"\"\n entries = os.path.join(path,'.svn','entries')\n revision = None\n if os.path.isfile(entries):\n f = open(entries)\n m = re.search(r'revision=\"(?P\\d+)\"',f.read())\n f.close()\n if m:\n revision = int(m.group('revision'))\n return revision\n\n def get_version(self):\n \"\"\" Try to get version string of a package.\n \"\"\"\n version = getattr(self,'version',None)\n if version is not None:\n return version\n\n # Get version from version file.\n files = ['__version__.py',\n self.name.split('.')[-1]+'_version.py',\n 'version.py',\n '__svn_version__.py']\n version_vars = ['version',\n '__version__',\n self.name.split('.')[-1]+'_version']\n for f in files:\n fn = os.path.join(self.local_path,f)\n if os.path.isfile(fn):\n info = (open(fn),fn,('.py','U',1))\n name = os.path.splitext(os.path.basename(fn))[0]\n n = dot_join(self.name,name)\n try:\n version_module = imp.load_module('_'.join(n.split('.')),*info)\n except ImportError,msg:\n print msg\n version_module = None\n if version_module is None:\n continue\n\n for a in version_vars:\n version = getattr(version_module,a,None)\n if version is not None:\n break\n if version is not None:\n break\n\n if version is not None:\n self.version = version\n return version\n\n # Get version as SVN revision number\n revision = self._get_svn_revision(self.local_path)\n if revision is not None:\n version = str(revision)\n self.version = version\n\n return version\n\n def make_svn_version_py(self):\n \"\"\" Generate package __svn_version__.py file from SVN revision number,\n it will be removed after python exits but will be available\n when sdist, etc commands are executed.\n\n If __svn_version__.py existed before, nothing is done.\n \"\"\"\n target = os.path.join(self.local_path,'__svn_version__.py')\n if os.path.isfile(target):\n return\n\n def generate_svn_version_py():\n if not os.path.isfile(target):\n revision = self._get_svn_revision(self.local_path)\n assert revision is not None,'hmm, why I am not inside SVN tree???'\n version = str(revision)\n print 'Creating %s (version=%r)' % (target,version)\n f = open(target,'w')\n f.write('version = %r\\n' % (version))\n f.close()\n \n import atexit\n def rm_file(f=target):\n try: os.remove(f); print 'removed',f\n except OSError: pass\n try: os.remove(f+'c'); print 'removed',f+'c'\n except OSError: pass\n atexit.register(rm_file)\n\n return target\n\n d = os.path.join(*(self.name.split('.')))\n self.add_data_files((d, generate_svn_version_py()))\n return\n\n def make_config_py(self,name='__config__'):\n \"\"\" Generate package __config__.py file containing system_info\n information used during building the package.\n \"\"\"\n self.py_modules.append((self.name,name,generate_config_py))\n return\n\n def get_info(self,*names):\n \"\"\" Get resources information.\n \"\"\"\n from system_info import get_info, dict_append\n info_dict = {}\n for a in names:\n dict_append(info_dict,**get_info(a))\n return info_dict\n\ndef get_cmd(cmdname,_cache={}):\n if not _cache.has_key(cmdname):\n import distutils.core\n dist = distutils.core._setup_distribution\n if dist is None:\n from distutils.errors import DistutilsInternalError\n raise DistutilsInternalError,\\\n 'setup distribution instance not initialized'\n cmd = dist.get_command_obj(cmdname)\n _cache[cmdname] = cmd\n return _cache[cmdname]\n\ndef get_numpy_include_dirs():\n # numpy_include_dirs are set by numpy/core/setup.py, otherwise []\n include_dirs = Configuration.numpy_include_dirs[:]\n if not include_dirs:\n import numpy\n if numpy.show_config is None:\n # running from numpy_core source directory\n include_dirs.append(os.path.join(os.path.dirname(numpy.__file__),\n 'core','include'))\n else:\n # using installed numpy core headers\n import numpy.core as core\n include_dirs.append(os.path.join(os.path.dirname(core.__file__),'include'))\n # else running numpy/core/setup.py\n return include_dirs\n\n#########################\n\ndef default_config_dict(name = None, parent_name = None, local_path=None):\n \"\"\" Return a configuration dictionary for usage in\n configuration() function defined in file setup_.py.\n \"\"\"\n import warnings\n warnings.warn('Use Configuration(%s,%s,top_path=%s) instead of '\\\n 'deprecated default_config_dict(%s,%s,%s)' \\\n % (`name`,`parent_name`,`local_path`,\n `name`,`parent_name`,`local_path`,\n ))\n c = Configuration(name, parent_name, local_path)\n return c.todict()\n\n\ndef dict_append(d,**kws):\n for k,v in kws.items():\n if d.has_key(k):\n d[k].extend(v)\n else:\n d[k] = v\n\ndef appendpath(prefix,path):\n if not ('/' == os.path.sep):\n prefix = prefix.replace('/',os.path.sep)\n path = path.replace('/',os.path.sep)\n drive = ''\n if os.path.isabs(path):\n drive = os.path.splitdrive(prefix)[0]\n absprefix = os.path.splitdrive(os.path.abspath(prefix))[1]\n pathdrive,path = os.path.splitdrive(path)\n d = os.path.commonprefix([absprefix,path])\n if os.path.join(absprefix[:len(d)],absprefix[len(d):])!=absprefix \\\n or os.path.join(path[:len(d)],path[len(d):])!=path:\n # Handle invalid paths\n d = os.path.dirname(d)\n subpath = path[len(d):]\n if os.path.isabs(subpath):\n subpath = subpath[1:]\n else:\n subpath = path\n return os.path.normpath(os.path.join(drive + prefix, subpath))\n\ndef generate_config_py(target):\n \"\"\" Generate config.py file containing system_info information\n used during building the package.\n\n Usage:\\\n config['py_modules'].append((packagename, '__config__',generate_config_py))\n \"\"\"\n from numpy.distutils.system_info import system_info\n from distutils.dir_util import mkpath\n mkpath(os.path.dirname(target))\n f = open(target,'w')\n f.write('# This file is generated by %s\\n' % (os.path.abspath(sys.argv[0])))\n f.write('# It contains system_info results at the time of building this package.\\n')\n f.write('__all__ = [\"get_info\",\"show\"]\\n\\n')\n for k,i in system_info.saved_results.items():\n f.write('%s=%r\\n' % (k,i))\n f.write('\\ndef get_info(name): g=globals(); return g.get(name,g.get(name+\"_info\",{}))\\n')\n f.write('''\ndef show():\n for name,info_dict in globals().items():\n if name[0]==\"_\" or type(info_dict) is not type({}): continue\n print name+\":\"\n if not info_dict:\n print \" NOT AVAILABLE\"\n for k,v in info_dict.items():\n v = str(v)\n if k==\\'sources\\' and len(v)>200: v = v[:60]+\\' ...\\\\n... \\'+v[-60:]\n print \\' %s = %s\\'%(k,v)\n print\n return\n ''')\n\n f.close()\n return target\n\ndef generate_svn_version_py(extension, build_dir):\n \"\"\" Generate __svn_version__.py file containing SVN\n revision number of a module.\n \n To use, add the following codelet to setup\n configuration(..) function\n\n ext = Extension(dot_join(config['name'],'__svn_version__'),\n sources=[generate_svn_version_py])\n ext.local_path = local_path\n config['ext_modules'].append(ext)\n\n \"\"\"\n from distutils import dep_util\n local_path = extension.local_path\n target = os.path.join(build_dir, '__svn_version__.py')\n entries = os.path.join(local_path,'.svn','entries')\n if os.path.isfile(entries):\n if not dep_util.newer(entries, target):\n return target\n elif os.path.isfile(target):\n return target\n\n revision = get_svn_revision(local_path)\n f = open(target,'w')\n f.write('revision=%s\\n' % (revision))\n f.close()\n return target\n", + "source_code_before": "import os\nimport re\nimport sys\nimport imp\nimport copy\nimport types\nimport glob\n\n__all__ = ['Configuration', 'get_numpy_include_dirs', 'default_config_dict',\n 'dict_append', 'appendpath', 'generate_config_py',\n 'generate_svn_version_py', 'get_cmd', 'allpath',\n 'terminal_has_colors', 'red_text', 'green_text', 'yellow_text',\n 'blue_text', 'cyan_text', 'cyg2win32', 'all_strings',\n 'has_f_sources', 'has_cxx_sources', 'filter_sources',\n 'get_dependencies', 'is_local_src_dir', 'get_ext_source_files',\n 'get_script_files', 'get_lib_source_files', 'get_data_files',\n 'dot_join', 'get_frame']\n\ndef allpath(name):\n \"Convert a /-separated pathname to one using the OS's path separator.\"\n splitted = name.split('/')\n return os.path.join(*splitted)\n\ndef get_path(mod_name,parent_path=None):\n \"\"\" Return path of the module.\n\n Returned path is relative to parent_path when given,\n otherwise it is absolute path.\n \"\"\"\n if mod_name == '__main__':\n d = os.path.abspath('.')\n elif mod_name == '__builtin__':\n #builtin if/then added by Pearu for use in core.run_setup. \n d = os.path.dirname(os.path.abspath(sys.argv[0]))\n else:\n __import__(mod_name)\n mod = sys.modules[mod_name]\n file = mod.__file__\n d = os.path.dirname(os.path.abspath(file))\n if parent_path is not None:\n pd = os.path.abspath(parent_path)\n if pd==d[:len(pd)]:\n d = d[len(pd)+1:]\n return d or '.'\n\n# Hooks for colored terminal output.\n# See also http://www.livinglogic.de/Python/ansistyle\ndef terminal_has_colors():\n if sys.platform=='cygwin' and not os.environ.has_key('USE_COLOR'):\n # Avoid importing curses that causes illegal operation\n # with a message:\n # PYTHON2 caused an invalid page fault in\n # module CYGNURSES7.DLL as 015f:18bbfc28\n # Details: Python 2.3.3 [GCC 3.3.1 (cygming special)]\n # ssh to Win32 machine from debian\n # curses.version is 2.2\n # CYGWIN_98-4.10, release 1.5.7(0.109/3/2))\n return 0\n if hasattr(sys.stdout,'isatty') and sys.stdout.isatty(): \n try:\n import curses\n curses.setupterm()\n if (curses.tigetnum(\"colors\") >= 0\n and curses.tigetnum(\"pairs\") >= 0\n and ((curses.tigetstr(\"setf\") is not None \n and curses.tigetstr(\"setb\") is not None) \n or (curses.tigetstr(\"setaf\") is not None\n and curses.tigetstr(\"setab\") is not None)\n or curses.tigetstr(\"scp\") is not None)):\n return 1\n except Exception,msg:\n pass\n return 0\n\nif terminal_has_colors():\n def red_text(s): return '\\x1b[31m%s\\x1b[0m'%s\n def green_text(s): return '\\x1b[32m%s\\x1b[0m'%s\n def yellow_text(s): return '\\x1b[33m%s\\x1b[0m'%s\n def blue_text(s): return '\\x1b[34m%s\\x1b[0m'%s\n def cyan_text(s): return '\\x1b[35m%s\\x1b[0m'%s\nelse:\n def red_text(s): return s\n def green_text(s): return s\n def yellow_text(s): return s\n def cyan_text(s): return s\n def blue_text(s): return s\n\n#########################\n\ndef cyg2win32(path):\n if sys.platform=='cygwin' and path.startswith('/cygdrive'):\n path = path[10] + ':' + os.path.normcase(path[11:])\n return path\n\n#########################\n\n#XXX need support for .C that is also C++\ncxx_ext_match = re.compile(r'.*[.](cpp|cxx|cc)\\Z',re.I).match\nfortran_ext_match = re.compile(r'.*[.](f90|f95|f77|for|ftn|f)\\Z',re.I).match\nf90_ext_match = re.compile(r'.*[.](f90|f95)\\Z',re.I).match\nf90_module_name_match = re.compile(r'\\s*module\\s*(?P[\\w_]+)',re.I).match\ndef _get_f90_modules(source):\n \"\"\" Return a list of Fortran f90 module names that\n given source file defines.\n \"\"\"\n if not f90_ext_match(source):\n return []\n modules = []\n f = open(source,'r')\n f_readlines = getattr(f,'xreadlines',f.readlines)\n for line in f_readlines():\n m = f90_module_name_match(line)\n if m:\n name = m.group('name')\n modules.append(name)\n # break # XXX can we assume that there is one module per file?\n f.close()\n return modules\n\ndef all_strings(lst):\n \"\"\" Return True if all items in lst are string objects. \"\"\"\n for item in lst:\n if type(item) is not types.StringType:\n return False\n return True\n\ndef has_f_sources(sources):\n \"\"\" Return True if sources contains Fortran files \"\"\"\n for source in sources:\n if fortran_ext_match(source):\n return True\n return False\n\ndef has_cxx_sources(sources):\n \"\"\" Return True if sources contains C++ files \"\"\"\n for source in sources:\n if cxx_ext_match(source):\n return True\n return False\n\ndef filter_sources(sources):\n \"\"\" Return four lists of filenames containing\n C, C++, Fortran, and Fortran 90 module sources,\n respectively.\n \"\"\"\n c_sources = []\n cxx_sources = []\n f_sources = []\n fmodule_sources = []\n for source in sources:\n if fortran_ext_match(source):\n modules = _get_f90_modules(source)\n if modules:\n fmodule_sources.append(source)\n else:\n f_sources.append(source)\n elif cxx_ext_match(source):\n cxx_sources.append(source)\n else:\n c_sources.append(source) \n return c_sources, cxx_sources, f_sources, fmodule_sources\n\n\ndef _get_headers(directory_list):\n # get *.h files from list of directories\n headers = []\n for dir in directory_list:\n head = glob.glob(os.path.join(dir,\"*.h\")) #XXX: *.hpp files??\n headers.extend(head)\n return headers\n\ndef _get_directories(list_of_sources):\n # get unique directories from list of sources.\n direcs = []\n for file in list_of_sources:\n dir = os.path.split(file)\n if dir[0] != '' and not dir[0] in direcs:\n direcs.append(dir[0])\n return direcs\n\ndef get_dependencies(sources):\n #XXX scan sources for include statements\n return _get_headers(_get_directories(sources))\n\ndef is_local_src_dir(directory):\n \"\"\" Return true if directory is local directory.\n \"\"\"\n if type(directory) is not type(''):\n return False\n abs_dir = os.path.abspath(directory)\n c = os.path.commonprefix([os.getcwd(),abs_dir])\n new_dir = abs_dir[len(c):].split(os.sep)\n if new_dir and not new_dir[0]:\n new_dir = new_dir[1:]\n if new_dir and new_dir[0]=='build':\n return False\n new_dir = os.sep.join(new_dir)\n return os.path.isdir(new_dir)\n\ndef _gsf_visit_func(filenames,dirname,names):\n if os.path.basename(dirname) in ['CVS','.svn','build']:\n names[:] = []\n return\n for name in names:\n if name[-1] in \"~#\":\n continue\n fullname = os.path.join(dirname,name)\n ext = os.path.splitext(fullname)[1]\n if ext and ext in ['.pyc','.o']:\n continue\n if os.path.isfile(fullname):\n filenames.append(fullname)\n\ndef get_ext_source_files(ext):\n # Get sources and any include files in the same directory.\n filenames = []\n sources = filter(lambda s:type(s) is types.StringType,ext.sources)\n filenames.extend(sources)\n filenames.extend(get_dependencies(sources))\n for d in ext.depends:\n if is_local_src_dir(d):\n os.path.walk(d,_gsf_visit_func,filenames)\n elif os.path.isfile(d):\n filenames.append(d)\n return filenames\n\ndef get_script_files(scripts):\n scripts = filter(lambda s:type(s) is types.StringType,scripts)\n return scripts\n\ndef get_lib_source_files(lib):\n filenames = []\n sources = lib[1].get('sources',[])\n sources = filter(lambda s:type(s) is types.StringType,sources)\n filenames.extend(sources)\n filenames.extend(get_dependencies(sources))\n depends = lib[1].get('depends',[])\n for d in depends:\n if is_local_src_dir(d):\n os.path.walk(d,_gsf_visit_func,filenames)\n elif os.path.isfile(d):\n filenames.append(d)\n return filenames\n\ndef get_data_files(data):\n if type(data) is types.StringType:\n return [data]\n sources = data[1]\n filenames = []\n for s in sources:\n if callable(s):\n continue\n if is_local_src_dir(s):\n os.path.walk(s,_gsf_visit_func,filenames)\n elif type(s) is type(''):\n if os.path.isfile(s):\n filenames.append(s)\n else:\n print 'Not existing data file:',s\n else:\n raise TypeError,`s`\n return filenames\n\ndef dot_join(*args):\n return '.'.join(filter(None,args))\n\ndef get_frame(level=0):\n try:\n return sys._getframe(level+1)\n except AttributeError:\n frame = sys.exc_info()[2].tb_frame\n for i in range(level+1):\n frame = frame.f_back\n return frame\n\n######################\n\nclass Configuration:\n\n _list_keys = ['packages','ext_modules','data_files','include_dirs',\n 'libraries','headers','scripts','py_modules']\n _dict_keys = ['package_dir']\n\n numpy_include_dirs = []\n\n def __init__(self,\n package_name=None,\n parent_name=None,\n top_path=None,\n package_path=None,\n **attrs):\n \"\"\" Construct configuration instance of a package.\n \"\"\"\n self.name = dot_join(parent_name, package_name)\n\n caller_frame = get_frame(1)\n caller_name = eval('__name__',caller_frame.f_globals,caller_frame.f_locals)\n \n self.local_path = get_path(caller_name, top_path)\n if top_path is None:\n top_path = self.local_path\n if package_path is None:\n package_path = self.local_path\n elif os.path.isdir(os.path.join(self.local_path,package_path)):\n package_path = os.path.join(self.local_path,package_path)\n assert os.path.isdir(package_path),`package_path`\n self.top_path = top_path\n\n self.list_keys = copy.copy(self._list_keys)\n self.dict_keys = copy.copy(self._dict_keys)\n\n for n in self.list_keys:\n setattr(self,n,copy.copy(attrs.get(n,[])))\n\n for n in self.dict_keys:\n setattr(self,n,copy.copy(attrs.get(n,{})))\n\n known_keys = self.list_keys + self.dict_keys\n self.extra_keys = []\n for n in attrs.keys():\n if n in known_keys:\n continue\n a = attrs[n]\n setattr(self,n,a)\n if type(a) is types.ListType:\n self.list_keys.append(n)\n elif type(a) is types.DictType:\n self.dict_keys.append(n)\n else:\n self.extra_keys.append(n)\n\n if os.path.exists(os.path.join(package_path,'__init__.py')):\n self.packages.append(self.name)\n self.package_dir[self.name] = package_path \n return\n\n def todict(self):\n \"\"\" Return configuration distionary suitable for passing\n to distutils.core.setup() function.\n \"\"\"\n d = {}\n for n in self.list_keys + self.dict_keys + self.extra_keys:\n a = getattr(self,n)\n if a:\n d[n] = a\n if self.name:\n d['name'] = self.name\n return d\n\n def __dict__(self):\n return self.todict()\n\n def get_distribution(self):\n import distutils.core\n dist = distutils.core._setup_distribution \n return dist\n\n def get_subpackage(self,subpackage_name,subpackage_path=None):\n \"\"\" Return subpackage configuration.\n \"\"\"\n if subpackage_name is None:\n assert subpackage_path is not None\n subpackage_name = os.path.basename(subpackage_path)\n l = subpackage_name.split('.')\n if subpackage_path is None:\n subpackage_path = os.path.join(*([self.local_path]+l))\n if '*' in subpackage_name:\n dirs = filter(os.path.isdir,glob.glob(subpackage_path))\n config_list = []\n for d in dirs:\n if not os.path.isfile(os.path.join(d,'__init__.py')):\n continue\n n = '.'.join(d.split(os.sep)[-len(l):])\n c = self.get_subpackage(n)\n if c:\n config_list.append(c)\n return config_list\n else:\n subpackage_path = os.path.join(*([subpackage_path]+l[:-1]))\n subpackage_path = self._fix_paths([subpackage_path])[0]\n\n setup_py = os.path.join(subpackage_path,'setup.py')\n if not os.path.isfile(setup_py):\n setup_py = os.path.join(subpackage_path,'setup_%s.py' % (subpackage_name))\n\n if not os.path.isfile(setup_py):\n print 'Assuming default configuration '\\\n '(%s/{setup_%s,setup}.py was not found)' \\\n % (os.path.dirname(setup_py),subpackage_name)\n config = Configuration(subpackage_name,self.name,\n self.top_path,subpackage_path)\n else:\n # In case setup_py imports local modules:\n sys.path.insert(0,os.path.dirname(setup_py))\n try:\n info = (open(setup_py),setup_py,('.py','U',1))\n setup_name = os.path.splitext(os.path.basename(setup_py))[0]\n n = dot_join(self.name,setup_name)\n setup_module = imp.load_module('_'.join(n.split('.')),*info)\n\n if not hasattr(setup_module,'configuration'):\n print 'Assuming default configuration '\\\n '(%s does not define configuration())' % (setup_module)\n config = Configuration(subpackage_name,self.name,\n self.top_path,subpackage_path)\n else:\n args = (self.name,)\n if setup_module.configuration.func_code.co_argcount>1:\n args = args + (self.top_path,)\n config = setup_module.configuration(*args)\n\n finally:\n del sys.path[0]\n\n return config\n\n def add_subpackage(self,subpackage_name,subpackage_path=None):\n \"\"\" Add subpackage to configuration.\n \"\"\"\n config = self.get_subpackage(subpackage_name,subpackage_path)\n if not isinstance(config, list):\n config_list = [config]\n else:\n config_list = config\n for config in config_list:\n if not config:\n print 'No configuration returned, assuming unavailable.'\n else:\n if isinstance(config,Configuration):\n print 'Appending %s configuration to %s' % (config.name,self.name)\n self.dict_append(**config.todict())\n else:\n print 'Appending %s configuration to %s' % (config.get('name'),self.name)\n self.dict_append(**config)\n\n dist = self.get_distribution()\n if dist is not None:\n print 'distutils distribution has been initialized, it may be too late to add a subpackage', subpackage_name\n return\n\n def add_data_dir(self,data_path):\n \"\"\" Recursively add files under data_path to data_files list.\n Argument can be either\n - 2-sequence (,)\n - path to data directory where python datadir suffix defaults\n to package dir.\n If path is not absolute then it's datadir suffix is\n package dir + subdirname of the path.\n \"\"\"\n if type(data_path) is type(()):\n assert len(data_path)==2,`data_path`\n d,data_path = data_path\n else:\n d = None\n assert type(data_path) is type(''),`data_path`\n for path in self.paths(data_path):\n if not os.path.exists(path):\n print 'Not existing data path',path\n continue\n filenames = []\n os.path.walk(path, _gsf_visit_func,filenames)\n if not os.path.isabs(path):\n if d is None:\n ds = os.path.join(*(self.name.split('.')+[data_path]))\n else:\n ds = os.path.join(d,data_path)\n self.add_data_files((ds,filenames))\n else:\n if d is None:\n self.add_data_files(*filenames)\n else:\n self.add_data_files((d,filenames))\n return\n\n def add_data_files(self,*files):\n \"\"\" Add data files to configuration data_files.\n Argument(s) can be either\n - 2-sequence (,)\n - paths to data files where python datadir prefix defaults\n to package dir.\n If path is not absolute then it's datadir prefix is\n package dir + dirname of the path.\n \"\"\"\n data_dict = {}\n new_files = []\n for p in files:\n if type(p) is not type(()):\n d = os.path.join(*(self.name.split('.')))\n if type(p) is type('') and not os.path.isabs(p):\n d = appendpath(d,os.path.dirname(p))\n p = (d,p)\n new_files.append(p)\n files = []\n for prefix,filepattern in new_files:\n if type(filepattern) is type(''):\n file_list = self.paths(filepattern)\n elif callable(filepattern):\n file_list = [filepattern]\n else:\n file_list = self.paths(*filepattern)\n\n nof_path_components = [len(f.split(os.sep)) \\\n for f in file_list if type(f) is type('')]\n if nof_path_components:\n min_path_components = min(nof_path_components)-1\n else:\n min_path_components = 0\n\n for f in file_list:\n if type(f) is type(''):\n extra_path_components = f.split(os.sep)[min_path_components:-1]\n p = os.path.join(*([prefix]+extra_path_components))\n else:\n p = prefix\n if not data_dict.has_key(p):\n data_dict[p] = [f]\n else:\n data_dict[p].append(f)\n\n dist = self.get_distribution()\n if dist is not None:\n dist.data_files.extend(data_dict.items())\n else:\n self.data_files.extend(data_dict.items())\n return \n\n ### XXX Implement add_py_modules\n \n def add_include_dirs(self,*paths):\n \"\"\" Add paths to configuration include directories.\n \"\"\"\n include_dirs = self._fix_paths(paths)\n dist = self.get_distribution()\n if dist is not None:\n dist.include_dirs.extend(include_dirs)\n else:\n self.include_dirs.extend(include_dirs)\n return\n\n def add_headers(self,*files):\n \"\"\" Add installable headers to configuration.\n Argument(s) can be either\n - 2-sequence (,)\n - path(s) to header file(s) where python includedir suffix will default\n to package name.\n \"\"\"\n headers = []\n for path in files:\n if type(path) is type(''):\n [headers.append((self.name,p)) for p in self.paths(path)]\n else:\n assert type(path) in [type(()),type([])] and len(path)==2,`path`\n [headers.append((path[0],p)) for p in self.paths(path[1])]\n dist = self.get_distribution()\n if dist is not None:\n dist.headers.extend(headers)\n else:\n self.headers.extend(headers)\n return\n\n def _fix_paths(self,paths):\n new_paths = []\n for n in paths:\n if isinstance(n,str):\n if '*' in n or '?' in n:\n p = glob.glob(n)\n p2 = glob.glob(os.path.join(self.local_path,n))\n if p2:\n new_paths.extend(p2)\n elif p:\n new_paths.extend(p)\n else:\n new_paths.append(n)\n else:\n n2 = os.path.join(self.local_path,n)\n if os.path.exists(n2):\n new_paths.append(n2)\n else:\n new_paths.append(n)\n else:\n new_paths.append(n)\n return new_paths\n\n def paths(self,*paths):\n \"\"\" Apply glob to paths and prepend local_path if needed.\n \"\"\"\n return self._fix_paths(paths)\n\n def add_extension(self,name,sources,**kw):\n \"\"\" Add extension to configuration.\n\n Keywords:\n include_dirs, define_macros, undef_macros,\n library_dirs, libraries, runtime_library_dirs,\n extra_objects, extra_compile_args, extra_link_args,\n export_symbols, swig_opts, depends, language,\n f2py_options, module_dirs\n extra_info - dict or list of dict of keywords to be\n appended to keywords.\n \"\"\"\n ext_args = copy.copy(kw)\n ext_args['name'] = dot_join(self.name,name)\n ext_args['sources'] = sources\n\n if ext_args.has_key('extra_info'):\n extra_info = ext_args['extra_info']\n del ext_args['extra_info']\n if type(extra_info) is type({}):\n extra_info = [extra_info]\n for info in extra_info:\n assert type(info) is type({}),`info`\n dict_append(ext_args,**info)\n\n for k in ext_args.keys():\n v = ext_args[k]\n if k in ['sources','depends','include_dirs','library_dirs',\n 'module_dirs','extra_objects']:\n new_v = self._fix_paths(v)\n ext_args[k] = new_v\n\n # Resolve out-of-tree dependencies\n libraries = ext_args.get('libraries',[])\n libnames = []\n ext_args['libraries'] = []\n for libname in libraries:\n if '@' in libname:\n lname,lpath = libname.split('@',1)\n lpath = os.path.abspath(os.path.join(self.local_path,lpath))\n if os.path.isdir(lpath):\n c = self.get_subpackage(None,lpath)\n if isinstance(c,Configuration):\n c = c.todict()\n for l in [l[0] for l in c.get('libraries',[])]:\n llname = l.split('__OF__',1)[0]\n if llname == lname:\n c.pop('name',None)\n dict_append(ext_args,**c)\n break\n continue\n libnames.append(libname)\n\n ext_args['libraries'] = libnames + ext_args['libraries']\n\n from numpy.distutils.core import Extension\n ext = Extension(**ext_args)\n self.ext_modules.append(ext)\n\n dist = self.get_distribution()\n if dist is not None:\n print 'distutils distribution has been initialized, it may be too late to add an extension', name\n return ext\n\n def add_library(self,name,sources,**build_info):\n \"\"\" Add library to configuration.\n \n Valid keywords for build_info:\n depends\n macros\n include_dirs\n extra_compiler_args\n f2py_options\n \"\"\"\n build_info = copy.copy(build_info)\n name = name #+ '__OF__' + self.name\n build_info['sources'] = sources\n\n for k in build_info.keys():\n v = build_info[k]\n if k in ['sources','depends','include_dirs','library_dirs',\n 'module_dirs','extra_objects']:\n new_v = self._fix_paths(v)\n build_info[k] = new_v\n self.libraries.append((name,build_info))\n\n dist = self.get_distribution()\n if dist is not None:\n print 'distutils distribution has been initialized, it may be too late to add a library', name\n return\n\n def add_scripts(self,*files):\n \"\"\" Add scripts to configuration.\n \"\"\"\n scripts = self._fix_paths(files)\n dist = self.get_distribution()\n if dist is not None:\n dist.scripts.extend(scripts)\n else:\n self.scripts.extend(scripts)\n return\n\n def dict_append(self,**dict):\n for key in self.list_keys:\n a = getattr(self,key)\n a.extend(dict.get(key,[]))\n for key in self.dict_keys:\n a = getattr(self,key)\n a.update(dict.get(key,{}))\n known_keys = self.list_keys + self.dict_keys + self.extra_keys\n for key in dict.keys():\n if key not in known_keys and not hasattr(self,key):\n print 'Inheriting attribute %r from %r' \\\n % (key,dict.get('name','?'))\n setattr(self,key,dict[key])\n self.extra_keys.append(key)\n return\n\n def __str__(self):\n known_keys = self.list_keys + self.dict_keys + self.extra_keys\n s = '<'+5*'-' + '\\n'\n s += 'Configuration of '+self.name+':\\n'\n for k in known_keys:\n a = getattr(self,k,None)\n if a:\n s += '%s = %r\\n' % (k,a)\n s += 5*'-' + '>'\n return s\n\n def get_config_cmd(self):\n cmd = get_cmd('config')\n cmd.ensure_finalized()\n cmd.dump_source = 0\n cmd.noisy = 0\n old_path = os.environ.get('PATH')\n if old_path:\n path = os.pathsep.join(['.',old_path])\n os.environ['PATH'] = path\n return cmd\n\n def get_build_temp_dir(self):\n cmd = get_cmd('build')\n cmd.ensure_finalized()\n return cmd.build_temp\n\n def have_f77c(self):\n \"\"\" Check for availability of Fortran 77 compiler.\n Use it inside source generating function to ensure that\n setup distribution instance has been initialized.\n \"\"\"\n simple_fortran_subroutine = '''\n subroutine simple\n end\n '''\n config_cmd = self.get_config_cmd()\n flag = config_cmd.try_compile(simple_fortran_subroutine,lang='f77')\n return flag\n\n def have_f90c(self):\n \"\"\" Check for availability of Fortran 90 compiler.\n Use it inside source generating function to ensure that\n setup distribution instance has been initialized.\n \"\"\"\n simple_fortran_subroutine = '''\n subroutine simple\n end\n '''\n config_cmd = self.get_config_cmd()\n flag = config_cmd.try_compile(simple_fortran_subroutine,lang='f90')\n return flag\n\n def append_to(self, extlib):\n \"\"\" Append libraries, include_dirs to extension or library item.\n \"\"\"\n if type(extlib) is type(()):\n lib_name, build_info = extlib\n dict_append(build_info,\n libraries=self.libraries,\n include_dirs=self.include_dirs)\n else:\n from numpy.distutils.core import Extension\n assert isinstance(extlib,Extension),`extlib`\n extlib.libraries.extend(self.libraries)\n extlib.include_dirs.extend(self.include_dirs)\n return\n\n def _get_svn_revision(self,path):\n \"\"\" Return path's SVN revision number.\n \"\"\"\n entries = os.path.join(path,'.svn','entries')\n revision = None\n if os.path.isfile(entries):\n f = open(entries)\n m = re.search(r'revision=\"(?P\\d+)\"',f.read())\n f.close()\n if m:\n revision = int(m.group('revision'))\n return revision\n\n def get_version(self):\n \"\"\" Try to get version string of a package.\n \"\"\"\n version = getattr(self,'version',None)\n if version is not None:\n return version\n\n # Get version from version file.\n files = ['__version__.py',\n self.name.split('.')[-1]+'_version.py',\n 'version.py',\n '__svn_version__.py']\n version_vars = ['version',\n '__version__',\n self.name.split('.')[-1]+'_version']\n for f in files:\n fn = os.path.join(self.local_path,f)\n if os.path.isfile(fn):\n info = (open(fn),fn,('.py','U',1))\n name = os.path.splitext(os.path.basename(fn))[0]\n n = dot_join(self.name,name)\n try:\n version_module = imp.load_module('_'.join(n.split('.')),*info)\n except ImportError,msg:\n print msg\n version_module = None\n if version_module is None:\n continue\n\n for a in version_vars:\n version = getattr(version_module,a,None)\n if version is not None:\n break\n if version is not None:\n break\n\n if version is not None:\n self.version = version\n return version\n\n # Get version as SVN revision number\n revision = self._get_svn_revision(self.local_path)\n if revision is not None:\n version = str(revision)\n self.version = version\n\n return version\n\n def make_svn_version_py(self):\n \"\"\" Generate package __svn_version__.py file from SVN revision number,\n it will be removed after python exits but will be available\n when sdist, etc commands are executed.\n\n If __svn_version__.py existed before, nothing is done.\n \"\"\"\n target = os.path.join(self.local_path,'__svn_version__.py')\n if os.path.isfile(target):\n return\n\n def generate_svn_version_py():\n if not os.path.isfile(target):\n revision = self._get_svn_revision(self.local_path)\n assert revision is not None,'hmm, why I am not inside SVN tree???'\n version = str(revision)\n print 'Creating %s (version=%r)' % (target,version)\n f = open(target,'w')\n f.write('version = %r\\n' % (version))\n f.close()\n \n import atexit\n def rm_file(f=target):\n try: os.remove(f); print 'removed',f\n except OSError: pass\n try: os.remove(f+'c'); print 'removed',f+'c'\n except OSError: pass\n atexit.register(rm_file)\n\n return target\n\n d = os.path.join(*(self.name.split('.')))\n self.add_data_files((d, generate_svn_version_py()))\n return\n\n def make_config_py(self,name='__config__'):\n \"\"\" Generate package __config__.py file containing system_info\n information used during building the package.\n \"\"\"\n self.py_modules.append((self.name,name,generate_config_py))\n return\n\n def get_info(self,*names):\n \"\"\" Get resources information.\n \"\"\"\n from system_info import get_info, dict_append\n info_dict = {}\n for a in names:\n dict_append(info_dict,**get_info(a))\n return info_dict\n\ndef get_cmd(cmdname,_cache={}):\n if not _cache.has_key(cmdname):\n import distutils.core\n dist = distutils.core._setup_distribution\n if dist is None:\n from distutils.errors import DistutilsInternalError\n raise DistutilsInternalError,\\\n 'setup distribution instance not initialized'\n cmd = dist.get_command_obj(cmdname)\n _cache[cmdname] = cmd\n return _cache[cmdname]\n\ndef get_numpy_include_dirs():\n # numpy_include_dirs are set by numpy/core/setup.py, otherwise []\n include_dirs = Configuration.numpy_include_dirs[:]\n if not include_dirs:\n import numpy\n if numpy.show_config is None:\n # running from numpy_core source directory\n include_dirs.append(os.path.join(os.path.dirname(numpy.__file__),\n 'core','include'))\n else:\n # using installed numpy core headers\n import numpy.core as core\n include_dirs.append(os.path.join(os.path.dirname(core.__file__),'include'))\n # else running numpy/core/setup.py\n return include_dirs\n\n#########################\n\ndef default_config_dict(name = None, parent_name = None, local_path=None):\n \"\"\" Return a configuration dictionary for usage in\n configuration() function defined in file setup_.py.\n \"\"\"\n import warnings\n warnings.warn('Use Configuration(%s,%s,top_path=%s) instead of '\\\n 'deprecated default_config_dict(%s,%s,%s)' \\\n % (`name`,`parent_name`,`local_path`,\n `name`,`parent_name`,`local_path`,\n ))\n c = Configuration(name, parent_name, local_path)\n return c.todict()\n\n\ndef dict_append(d,**kws):\n for k,v in kws.items():\n if d.has_key(k):\n d[k].extend(v)\n else:\n d[k] = v\n\ndef appendpath(prefix,path):\n if not ('/' == os.path.sep):\n prefix = prefix.replace('/',os.path.sep)\n path = path.replace('/',os.path.sep)\n drive = ''\n if os.path.isabs(path):\n drive = os.path.splitdrive(prefix)[0]\n absprefix = os.path.splitdrive(os.path.abspath(prefix))[1]\n pathdrive,path = os.path.splitdrive(path)\n d = os.path.commonprefix([absprefix,path])\n if os.path.join(absprefix[:len(d)],absprefix[len(d):])!=absprefix \\\n or os.path.join(path[:len(d)],path[len(d):])!=path:\n # Handle invalid paths\n d = os.path.dirname(d)\n subpath = path[len(d):]\n if os.path.isabs(subpath):\n subpath = subpath[1:]\n else:\n subpath = path\n return os.path.normpath(os.path.join(drive + prefix, subpath))\n\ndef generate_config_py(target):\n \"\"\" Generate config.py file containing system_info information\n used during building the package.\n\n Usage:\\\n config['py_modules'].append((packagename, '__config__',generate_config_py))\n \"\"\"\n from numpy.distutils.system_info import system_info\n from distutils.dir_util import mkpath\n mkpath(os.path.dirname(target))\n f = open(target,'w')\n f.write('# This file is generated by %s\\n' % (os.path.abspath(sys.argv[0])))\n f.write('# It contains system_info results at the time of building this package.\\n')\n f.write('__all__ = [\"get_info\",\"show\"]\\n\\n')\n for k,i in system_info.saved_results.items():\n f.write('%s=%r\\n' % (k,i))\n f.write('\\ndef get_info(name): g=globals(); return g.get(name,g.get(name+\"_info\",{}))\\n')\n f.write('''\ndef show():\n for name,info_dict in globals().items():\n if name[0]==\"_\" or type(info_dict) is not type({}): continue\n print name+\":\"\n if not info_dict:\n print \" NOT AVAILABLE\"\n for k,v in info_dict.items():\n v = str(v)\n if k==\\'sources\\' and len(v)>200: v = v[:60]+\\' ...\\\\n... \\'+v[-60:]\n print \\' %s = %s\\'%(k,v)\n print\n return\n ''')\n\n f.close()\n return target\n\ndef generate_svn_version_py(extension, build_dir):\n \"\"\" Generate __svn_version__.py file containing SVN\n revision number of a module.\n \n To use, add the following codelet to setup\n configuration(..) function\n\n ext = Extension(dot_join(config['name'],'__svn_version__'),\n sources=[generate_svn_version_py])\n ext.local_path = local_path\n config['ext_modules'].append(ext)\n\n \"\"\"\n from distutils import dep_util\n local_path = extension.local_path\n target = os.path.join(build_dir, '__svn_version__.py')\n entries = os.path.join(local_path,'.svn','entries')\n if os.path.isfile(entries):\n if not dep_util.newer(entries, target):\n return target\n elif os.path.isfile(target):\n return target\n\n revision = get_svn_revision(local_path)\n f = open(target,'w')\n f.write('revision=%s\\n' % (revision))\n f.close()\n return target\n", + "methods": [ + { + "name": "allpath", + "long_name": "allpath( name )", + "filename": "misc_util.py", + "nloc": 4, + "complexity": 1, + "token_count": 24, + "parameters": [ + "name" + ], + "start_line": 18, + "end_line": 21, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 4, + "top_nesting_level": 0 + }, + { + "name": "get_path", + "long_name": "get_path( mod_name , parent_path = None )", + "filename": "misc_util.py", + "nloc": 15, + "complexity": 6, + "token_count": 132, + "parameters": [ + "mod_name", + "parent_path" + ], + "start_line": 23, + "end_line": 43, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 21, + "top_nesting_level": 0 + }, + { + "name": "terminal_has_colors", + "long_name": "terminal_has_colors( )", + "filename": "misc_util.py", + "nloc": 18, + "complexity": 13, + "token_count": 137, + "parameters": [], + "start_line": 47, + "end_line": 72, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 26, + "top_nesting_level": 0 + }, + { + "name": "cyg2win32", + "long_name": "cyg2win32( path )", + "filename": "misc_util.py", + "nloc": 4, + "complexity": 3, + "token_count": 42, + "parameters": [ + "path" + ], + "start_line": 89, + "end_line": 92, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 4, + "top_nesting_level": 0 + }, + { + "name": "_get_f90_modules", + "long_name": "_get_f90_modules( source )", + "filename": "misc_util.py", + "nloc": 13, + "complexity": 4, + "token_count": 77, + "parameters": [ + "source" + ], + "start_line": 101, + "end_line": 117, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 17, + "top_nesting_level": 0 + }, + { + "name": "is_string", + "long_name": "is_string( s )", + "filename": "misc_util.py", + "nloc": 2, + "complexity": 1, + "token_count": 12, + "parameters": [ + "s" + ], + "start_line": 119, + "end_line": 120, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 2, + "top_nesting_level": 0 + }, + { + "name": "all_strings", + "long_name": "all_strings( lst )", + "filename": "misc_util.py", + "nloc": 5, + "complexity": 3, + "token_count": 22, + "parameters": [ + "lst" + ], + "start_line": 122, + "end_line": 127, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 6, + "top_nesting_level": 0 + }, + { + "name": "is_sequence", + "long_name": "is_sequence( seq )", + "filename": "misc_util.py", + "nloc": 8, + "complexity": 3, + "token_count": 25, + "parameters": [ + "seq" + ], + "start_line": 129, + "end_line": 136, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 8, + "top_nesting_level": 0 + }, + { + "name": "has_f_sources", + "long_name": "has_f_sources( sources )", + "filename": "misc_util.py", + "nloc": 5, + "complexity": 3, + "token_count": 21, + "parameters": [ + "sources" + ], + "start_line": 138, + "end_line": 143, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 6, + "top_nesting_level": 0 + }, + { + "name": "has_cxx_sources", + "long_name": "has_cxx_sources( sources )", + "filename": "misc_util.py", + "nloc": 5, + "complexity": 3, + "token_count": 21, + "parameters": [ + "sources" + ], + "start_line": 145, + "end_line": 150, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 6, + "top_nesting_level": 0 + }, + { + "name": "filter_sources", + "long_name": "filter_sources( sources )", + "filename": "misc_util.py", + "nloc": 17, + "complexity": 5, + "token_count": 84, + "parameters": [ + "sources" + ], + "start_line": 152, + "end_line": 172, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 21, + "top_nesting_level": 0 + }, + { + "name": "_get_headers", + "long_name": "_get_headers( directory_list )", + "filename": "misc_util.py", + "nloc": 6, + "complexity": 2, + "token_count": 39, + "parameters": [ + "directory_list" + ], + "start_line": 175, + "end_line": 181, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 7, + "top_nesting_level": 0 + }, + { + "name": "_get_directories", + "long_name": "_get_directories( list_of_sources )", + "filename": "misc_util.py", + "nloc": 7, + "complexity": 4, + "token_count": 51, + "parameters": [ + "list_of_sources" + ], + "start_line": 183, + "end_line": 190, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 8, + "top_nesting_level": 0 + }, + { + "name": "get_dependencies", + "long_name": "get_dependencies( sources )", + "filename": "misc_util.py", + "nloc": 2, + "complexity": 1, + "token_count": 13, + "parameters": [ + "sources" + ], + "start_line": 192, + "end_line": 194, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 3, + "top_nesting_level": 0 + }, + { + "name": "is_local_src_dir", + "long_name": "is_local_src_dir( directory )", + "filename": "misc_util.py", + "nloc": 12, + "complexity": 6, + "token_count": 107, + "parameters": [ + "directory" + ], + "start_line": 196, + "end_line": 209, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 14, + "top_nesting_level": 0 + }, + { + "name": "_gsf_visit_func", + "long_name": "_gsf_visit_func( filenames , dirname , names )", + "filename": "misc_util.py", + "nloc": 13, + "complexity": 7, + "token_count": 103, + "parameters": [ + "filenames", + "dirname", + "names" + ], + "start_line": 211, + "end_line": 223, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 13, + "top_nesting_level": 0 + }, + { + "name": "get_ext_source_files", + "long_name": "get_ext_source_files( ext )", + "filename": "misc_util.py", + "nloc": 11, + "complexity": 4, + "token_count": 77, + "parameters": [ + "ext" + ], + "start_line": 225, + "end_line": 236, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 12, + "top_nesting_level": 0 + }, + { + "name": "get_script_files", + "long_name": "get_script_files( scripts )", + "filename": "misc_util.py", + "nloc": 3, + "complexity": 1, + "token_count": 15, + "parameters": [ + "scripts" + ], + "start_line": 238, + "end_line": 240, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 3, + "top_nesting_level": 0 + }, + { + "name": "get_lib_source_files", + "long_name": "get_lib_source_files( lib )", + "filename": "misc_util.py", + "nloc": 13, + "complexity": 4, + "token_count": 101, + "parameters": [ + "lib" + ], + "start_line": 242, + "end_line": 254, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 13, + "top_nesting_level": 0 + }, + { + "name": "get_data_files", + "long_name": "get_data_files( data )", + "filename": "misc_util.py", + "nloc": 18, + "complexity": 7, + "token_count": 94, + "parameters": [ + "data" + ], + "start_line": 256, + "end_line": 273, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 18, + "top_nesting_level": 0 + }, + { + "name": "dot_join", + "long_name": "dot_join( * args )", + "filename": "misc_util.py", + "nloc": 2, + "complexity": 1, + "token_count": 18, + "parameters": [ + "args" + ], + "start_line": 275, + "end_line": 276, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 2, + "top_nesting_level": 0 + }, + { + "name": "get_frame", + "long_name": "get_frame( level = 0 )", + "filename": "misc_util.py", + "nloc": 8, + "complexity": 3, + "token_count": 50, + "parameters": [ + "level" + ], + "start_line": 278, + "end_line": 285, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 8, + "top_nesting_level": 0 + }, + { + "name": "__init__", + "long_name": "__init__( self , package_name = None , parent_name = None , top_path = None , package_path = None , ** attrs )", + "filename": "misc_util.py", + "nloc": 43, + "complexity": 12, + "token_count": 357, + "parameters": [ + "self", + "package_name", + "parent_name", + "top_path", + "package_path", + "attrs" + ], + "start_line": 297, + "end_line": 358, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 62, + "top_nesting_level": 1 + }, + { + "name": "todict", + "long_name": "todict( self )", + "filename": "misc_util.py", + "nloc": 9, + "complexity": 4, + "token_count": 57, + "parameters": [ + "self" + ], + "start_line": 360, + "end_line": 371, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 12, + "top_nesting_level": 1 + }, + { + "name": "__dict__", + "long_name": "__dict__( self )", + "filename": "misc_util.py", + "nloc": 2, + "complexity": 1, + "token_count": 11, + "parameters": [ + "self" + ], + "start_line": 373, + "end_line": 374, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 2, + "top_nesting_level": 1 + }, + { + "name": "get_distribution", + "long_name": "get_distribution( self )", + "filename": "misc_util.py", + "nloc": 4, + "complexity": 1, + "token_count": 18, + "parameters": [ + "self" + ], + "start_line": 376, + "end_line": 379, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 4, + "top_nesting_level": 1 + }, + { + "name": "get_subpackage", + "long_name": "get_subpackage( self , subpackage_name , subpackage_path = None )", + "filename": "misc_util.py", + "nloc": 50, + "complexity": 12, + "token_count": 453, + "parameters": [ + "self", + "subpackage_name", + "subpackage_path" + ], + "start_line": 381, + "end_line": 438, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 58, + "top_nesting_level": 1 + }, + { + "name": "add_subpackage", + "long_name": "add_subpackage( self , subpackage_name , subpackage_path = None )", + "filename": "misc_util.py", + "nloc": 20, + "complexity": 6, + "token_count": 127, + "parameters": [ + "self", + "subpackage_name", + "subpackage_path" + ], + "start_line": 440, + "end_line": 462, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 23, + "top_nesting_level": 1 + }, + { + "name": "add_data_dir", + "long_name": "add_data_dir( self , data_path )", + "filename": "misc_util.py", + "nloc": 25, + "complexity": 8, + "token_count": 174, + "parameters": [ + "self", + "data_path" + ], + "start_line": 464, + "end_line": 496, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 33, + "top_nesting_level": 1 + }, + { + "name": "add_data_files", + "long_name": "add_data_files( self , * files )", + "filename": "misc_util.py", + "nloc": 39, + "complexity": 15, + "token_count": 296, + "parameters": [ + "self", + "files" + ], + "start_line": 498, + "end_line": 547, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 50, + "top_nesting_level": 1 + }, + { + "name": "add_include_dirs", + "long_name": "add_include_dirs( self , * paths )", + "filename": "misc_util.py", + "nloc": 8, + "complexity": 2, + "token_count": 49, + "parameters": [ + "self", + "paths" + ], + "start_line": 551, + "end_line": 560, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 10, + "top_nesting_level": 1 + }, + { + "name": "add_headers", + "long_name": "add_headers( self , * files )", + "filename": "misc_util.py", + "nloc": 15, + "complexity": 8, + "token_count": 136, + "parameters": [ + "self", + "files" + ], + "start_line": 562, + "end_line": 582, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 21, + "top_nesting_level": 1 + }, + { + "name": "_fix_paths", + "long_name": "_fix_paths( self , paths )", + "filename": "misc_util.py", + "nloc": 22, + "complexity": 8, + "token_count": 136, + "parameters": [ + "self", + "paths" + ], + "start_line": 584, + "end_line": 605, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 22, + "top_nesting_level": 1 + }, + { + "name": "paths", + "long_name": "paths( self , * paths )", + "filename": "misc_util.py", + "nloc": 2, + "complexity": 1, + "token_count": 16, + "parameters": [ + "self", + "paths" + ], + "start_line": 607, + "end_line": 610, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 4, + "top_nesting_level": 1 + }, + { + "name": "add_extension", + "long_name": "add_extension( self , name , sources , ** kw )", + "filename": "misc_util.py", + "nloc": 45, + "complexity": 14, + "token_count": 365, + "parameters": [ + "self", + "name", + "sources", + "kw" + ], + "start_line": 612, + "end_line": 674, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 63, + "top_nesting_level": 1 + }, + { + "name": "add_library", + "long_name": "add_library( self , name , sources , ** build_info )", + "filename": "misc_util.py", + "nloc": 15, + "complexity": 4, + "token_count": 106, + "parameters": [ + "self", + "name", + "sources", + "build_info" + ], + "start_line": 676, + "end_line": 701, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 26, + "top_nesting_level": 1 + }, + { + "name": "add_scripts", + "long_name": "add_scripts( self , * files )", + "filename": "misc_util.py", + "nloc": 8, + "complexity": 2, + "token_count": 49, + "parameters": [ + "self", + "files" + ], + "start_line": 703, + "end_line": 712, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 10, + "top_nesting_level": 1 + }, + { + "name": "dict_append", + "long_name": "dict_append( self , ** dict )", + "filename": "misc_util.py", + "nloc": 15, + "complexity": 6, + "token_count": 138, + "parameters": [ + "self", + "dict" + ], + "start_line": 714, + "end_line": 728, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 15, + "top_nesting_level": 1 + }, + { + "name": "__str__", + "long_name": "__str__( self )", + "filename": "misc_util.py", + "nloc": 10, + "complexity": 3, + "token_count": 72, + "parameters": [ + "self" + ], + "start_line": 730, + "end_line": 739, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 10, + "top_nesting_level": 1 + }, + { + "name": "get_config_cmd", + "long_name": "get_config_cmd( self )", + "filename": "misc_util.py", + "nloc": 10, + "complexity": 2, + "token_count": 63, + "parameters": [ + "self" + ], + "start_line": 741, + "end_line": 750, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 10, + "top_nesting_level": 1 + }, + { + "name": "get_build_temp_dir", + "long_name": "get_build_temp_dir( self )", + "filename": "misc_util.py", + "nloc": 4, + "complexity": 1, + "token_count": 20, + "parameters": [ + "self" + ], + "start_line": 752, + "end_line": 755, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 4, + "top_nesting_level": 1 + }, + { + "name": "have_f77c", + "long_name": "have_f77c( self )", + "filename": "misc_util.py", + "nloc": 8, + "complexity": 1, + "token_count": 30, + "parameters": [ + "self" + ], + "start_line": 757, + "end_line": 768, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 12, + "top_nesting_level": 1 + }, + { + "name": "have_f90c", + "long_name": "have_f90c( self )", + "filename": "misc_util.py", + "nloc": 8, + "complexity": 1, + "token_count": 30, + "parameters": [ + "self" + ], + "start_line": 770, + "end_line": 781, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 12, + "top_nesting_level": 1 + }, + { + "name": "append_to", + "long_name": "append_to( self , extlib )", + "filename": "misc_util.py", + "nloc": 12, + "complexity": 2, + "token_count": 77, + "parameters": [ + "self", + "extlib" + ], + "start_line": 783, + "end_line": 796, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 14, + "top_nesting_level": 1 + }, + { + "name": "_get_svn_revision", + "long_name": "_get_svn_revision( self , path )", + "filename": "misc_util.py", + "nloc": 10, + "complexity": 3, + "token_count": 77, + "parameters": [ + "self", + "path" + ], + "start_line": 798, + "end_line": 809, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 12, + "top_nesting_level": 1 + }, + { + "name": "get_version", + "long_name": "get_version( self )", + "filename": "misc_util.py", + "nloc": 38, + "complexity": 11, + "token_count": 257, + "parameters": [ + "self" + ], + "start_line": 811, + "end_line": 857, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 47, + "top_nesting_level": 1 + }, + { + "name": "make_svn_version_py.make_svn_version_py.generate_svn_version_py.rm_file", + "long_name": "make_svn_version_py.make_svn_version_py.generate_svn_version_py.rm_file( f = target )", + "filename": "misc_util.py", + "nloc": 5, + "complexity": 3, + "token_count": 45, + "parameters": [ + "f" + ], + "start_line": 881, + "end_line": 885, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 5, + "top_nesting_level": 3 + }, + { + "name": "make_svn_version_py.generate_svn_version_py", + "long_name": "make_svn_version_py.generate_svn_version_py( )", + "filename": "misc_util.py", + "nloc": 13, + "complexity": 2, + "token_count": 81, + "parameters": [], + "start_line": 870, + "end_line": 888, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 19, + "top_nesting_level": 2 + }, + { + "name": "make_svn_version_py", + "long_name": "make_svn_version_py( self )", + "filename": "misc_util.py", + "nloc": 8, + "complexity": 2, + "token_count": 66, + "parameters": [ + "self" + ], + "start_line": 859, + "end_line": 892, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 34, + "top_nesting_level": 1 + }, + { + "name": "make_config_py", + "long_name": "make_config_py( self , name = '__config__' )", + "filename": "misc_util.py", + "nloc": 3, + "complexity": 1, + "token_count": 27, + "parameters": [ + "self", + "name" + ], + "start_line": 894, + "end_line": 899, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 6, + "top_nesting_level": 1 + }, + { + "name": "get_info", + "long_name": "get_info( self , * names )", + "filename": "misc_util.py", + "nloc": 6, + "complexity": 2, + "token_count": 36, + "parameters": [ + "self", + "names" + ], + "start_line": 901, + "end_line": 908, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 8, + "top_nesting_level": 1 + }, + { + "name": "get_cmd", + "long_name": "get_cmd( cmdname , _cache = { } )", + "filename": "misc_util.py", + "nloc": 11, + "complexity": 3, + "token_count": 65, + "parameters": [ + "cmdname", + "_cache" + ], + "start_line": 910, + "end_line": 920, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 11, + "top_nesting_level": 0 + }, + { + "name": "get_numpy_include_dirs", + "long_name": "get_numpy_include_dirs( )", + "filename": "misc_util.py", + "nloc": 11, + "complexity": 3, + "token_count": 85, + "parameters": [], + "start_line": 922, + "end_line": 936, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 15, + "top_nesting_level": 0 + }, + { + "name": "default_config_dict", + "long_name": "default_config_dict( name = None , parent_name = None , local_path = None )", + "filename": "misc_util.py", + "nloc": 9, + "complexity": 1, + "token_count": 70, + "parameters": [ + "name", + "parent_name", + "local_path" + ], + "start_line": 940, + "end_line": 951, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 12, + "top_nesting_level": 0 + }, + { + "name": "dict_append", + "long_name": "dict_append( d , ** kws )", + "filename": "misc_util.py", + "nloc": 6, + "complexity": 3, + "token_count": 44, + "parameters": [ + "d", + "kws" + ], + "start_line": 954, + "end_line": 959, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 6, + "top_nesting_level": 0 + }, + { + "name": "appendpath", + "long_name": "appendpath( prefix , path )", + "filename": "misc_util.py", + "nloc": 19, + "complexity": 6, + "token_count": 237, + "parameters": [ + "prefix", + "path" + ], + "start_line": 961, + "end_line": 980, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 20, + "top_nesting_level": 0 + }, + { + "name": "generate_config_py", + "long_name": "generate_config_py( target )", + "filename": "misc_util.py", + "nloc": 27, + "complexity": 2, + "token_count": 117, + "parameters": [ + "target" + ], + "start_line": 982, + "end_line": 1015, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 34, + "top_nesting_level": 0 + }, + { + "name": "generate_svn_version_py", + "long_name": "generate_svn_version_py( extension , build_dir )", + "filename": "misc_util.py", + "nloc": 15, + "complexity": 4, + "token_count": 109, + "parameters": [ + "extension", + "build_dir" + ], + "start_line": 1017, + "end_line": 1044, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 28, + "top_nesting_level": 0 + } + ], + "methods_before": [ + { + "name": "allpath", + "long_name": "allpath( name )", + "filename": "misc_util.py", + "nloc": 4, + "complexity": 1, + "token_count": 24, + "parameters": [ + "name" + ], + "start_line": 19, + "end_line": 22, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 4, + "top_nesting_level": 0 + }, + { + "name": "get_path", + "long_name": "get_path( mod_name , parent_path = None )", + "filename": "misc_util.py", + "nloc": 15, + "complexity": 6, + "token_count": 132, + "parameters": [ + "mod_name", + "parent_path" + ], + "start_line": 24, + "end_line": 44, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 21, + "top_nesting_level": 0 + }, + { + "name": "terminal_has_colors", + "long_name": "terminal_has_colors( )", + "filename": "misc_util.py", + "nloc": 18, + "complexity": 13, + "token_count": 137, + "parameters": [], + "start_line": 48, + "end_line": 73, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 26, + "top_nesting_level": 0 + }, + { + "name": "cyg2win32", + "long_name": "cyg2win32( path )", + "filename": "misc_util.py", + "nloc": 4, + "complexity": 3, + "token_count": 42, + "parameters": [ + "path" + ], + "start_line": 90, + "end_line": 93, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 4, + "top_nesting_level": 0 + }, + { + "name": "_get_f90_modules", + "long_name": "_get_f90_modules( source )", + "filename": "misc_util.py", + "nloc": 13, + "complexity": 4, + "token_count": 77, + "parameters": [ + "source" + ], + "start_line": 102, + "end_line": 118, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 17, + "top_nesting_level": 0 + }, + { + "name": "all_strings", + "long_name": "all_strings( lst )", + "filename": "misc_util.py", + "nloc": 5, + "complexity": 3, + "token_count": 26, + "parameters": [ + "lst" + ], + "start_line": 120, + "end_line": 125, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 6, + "top_nesting_level": 0 + }, + { + "name": "has_f_sources", + "long_name": "has_f_sources( sources )", + "filename": "misc_util.py", + "nloc": 5, + "complexity": 3, + "token_count": 21, + "parameters": [ + "sources" + ], + "start_line": 127, + "end_line": 132, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 6, + "top_nesting_level": 0 + }, + { + "name": "has_cxx_sources", + "long_name": "has_cxx_sources( sources )", + "filename": "misc_util.py", + "nloc": 5, + "complexity": 3, + "token_count": 21, + "parameters": [ + "sources" + ], + "start_line": 134, + "end_line": 139, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 6, + "top_nesting_level": 0 + }, + { + "name": "filter_sources", + "long_name": "filter_sources( sources )", + "filename": "misc_util.py", + "nloc": 17, + "complexity": 5, + "token_count": 84, + "parameters": [ + "sources" + ], + "start_line": 141, + "end_line": 161, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 21, + "top_nesting_level": 0 + }, + { + "name": "_get_headers", + "long_name": "_get_headers( directory_list )", + "filename": "misc_util.py", + "nloc": 6, + "complexity": 2, + "token_count": 39, + "parameters": [ + "directory_list" + ], + "start_line": 164, + "end_line": 170, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 7, + "top_nesting_level": 0 + }, + { + "name": "_get_directories", + "long_name": "_get_directories( list_of_sources )", + "filename": "misc_util.py", + "nloc": 7, + "complexity": 4, + "token_count": 51, + "parameters": [ + "list_of_sources" + ], + "start_line": 172, + "end_line": 179, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 8, + "top_nesting_level": 0 + }, + { + "name": "get_dependencies", + "long_name": "get_dependencies( sources )", + "filename": "misc_util.py", + "nloc": 2, + "complexity": 1, + "token_count": 13, + "parameters": [ + "sources" + ], + "start_line": 181, + "end_line": 183, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 3, + "top_nesting_level": 0 + }, + { + "name": "is_local_src_dir", + "long_name": "is_local_src_dir( directory )", + "filename": "misc_util.py", + "nloc": 12, + "complexity": 6, + "token_count": 112, + "parameters": [ + "directory" + ], + "start_line": 185, + "end_line": 198, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 14, + "top_nesting_level": 0 + }, + { + "name": "_gsf_visit_func", + "long_name": "_gsf_visit_func( filenames , dirname , names )", + "filename": "misc_util.py", + "nloc": 13, + "complexity": 7, + "token_count": 103, + "parameters": [ + "filenames", + "dirname", + "names" + ], + "start_line": 200, + "end_line": 212, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 13, + "top_nesting_level": 0 + }, + { + "name": "get_ext_source_files", + "long_name": "get_ext_source_files( ext )", + "filename": "misc_util.py", + "nloc": 11, + "complexity": 4, + "token_count": 87, + "parameters": [ + "ext" + ], + "start_line": 214, + "end_line": 225, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 12, + "top_nesting_level": 0 + }, + { + "name": "get_script_files", + "long_name": "get_script_files( scripts )", + "filename": "misc_util.py", + "nloc": 3, + "complexity": 1, + "token_count": 25, + "parameters": [ + "scripts" + ], + "start_line": 227, + "end_line": 229, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 3, + "top_nesting_level": 0 + }, + { + "name": "get_lib_source_files", + "long_name": "get_lib_source_files( lib )", + "filename": "misc_util.py", + "nloc": 13, + "complexity": 4, + "token_count": 111, + "parameters": [ + "lib" + ], + "start_line": 231, + "end_line": 243, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 13, + "top_nesting_level": 0 + }, + { + "name": "get_data_files", + "long_name": "get_data_files( data )", + "filename": "misc_util.py", + "nloc": 18, + "complexity": 7, + "token_count": 102, + "parameters": [ + "data" + ], + "start_line": 245, + "end_line": 262, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 18, + "top_nesting_level": 0 + }, + { + "name": "dot_join", + "long_name": "dot_join( * args )", + "filename": "misc_util.py", + "nloc": 2, + "complexity": 1, + "token_count": 18, + "parameters": [ + "args" + ], + "start_line": 264, + "end_line": 265, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 2, + "top_nesting_level": 0 + }, + { + "name": "get_frame", + "long_name": "get_frame( level = 0 )", + "filename": "misc_util.py", + "nloc": 8, + "complexity": 3, + "token_count": 50, + "parameters": [ + "level" + ], + "start_line": 267, + "end_line": 274, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 8, + "top_nesting_level": 0 + }, + { + "name": "__init__", + "long_name": "__init__( self , package_name = None , parent_name = None , top_path = None , package_path = None , ** attrs )", + "filename": "misc_util.py", + "nloc": 41, + "complexity": 11, + "token_count": 348, + "parameters": [ + "self", + "package_name", + "parent_name", + "top_path", + "package_path", + "attrs" + ], + "start_line": 286, + "end_line": 335, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 50, + "top_nesting_level": 1 + }, + { + "name": "todict", + "long_name": "todict( self )", + "filename": "misc_util.py", + "nloc": 9, + "complexity": 4, + "token_count": 57, + "parameters": [ + "self" + ], + "start_line": 337, + "end_line": 348, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 12, + "top_nesting_level": 1 + }, + { + "name": "__dict__", + "long_name": "__dict__( self )", + "filename": "misc_util.py", + "nloc": 2, + "complexity": 1, + "token_count": 11, + "parameters": [ + "self" + ], + "start_line": 350, + "end_line": 351, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 2, + "top_nesting_level": 1 + }, + { + "name": "get_distribution", + "long_name": "get_distribution( self )", + "filename": "misc_util.py", + "nloc": 4, + "complexity": 1, + "token_count": 18, + "parameters": [ + "self" + ], + "start_line": 353, + "end_line": 356, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 4, + "top_nesting_level": 1 + }, + { + "name": "get_subpackage", + "long_name": "get_subpackage( self , subpackage_name , subpackage_path = None )", + "filename": "misc_util.py", + "nloc": 50, + "complexity": 12, + "token_count": 453, + "parameters": [ + "self", + "subpackage_name", + "subpackage_path" + ], + "start_line": 358, + "end_line": 415, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 58, + "top_nesting_level": 1 + }, + { + "name": "add_subpackage", + "long_name": "add_subpackage( self , subpackage_name , subpackage_path = None )", + "filename": "misc_util.py", + "nloc": 20, + "complexity": 6, + "token_count": 127, + "parameters": [ + "self", + "subpackage_name", + "subpackage_path" + ], + "start_line": 417, + "end_line": 439, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 23, + "top_nesting_level": 1 + }, + { + "name": "add_data_dir", + "long_name": "add_data_dir( self , data_path )", + "filename": "misc_util.py", + "nloc": 25, + "complexity": 7, + "token_count": 188, + "parameters": [ + "self", + "data_path" + ], + "start_line": 441, + "end_line": 473, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 33, + "top_nesting_level": 1 + }, + { + "name": "add_data_files", + "long_name": "add_data_files( self , * files )", + "filename": "misc_util.py", + "nloc": 40, + "complexity": 15, + "token_count": 324, + "parameters": [ + "self", + "files" + ], + "start_line": 475, + "end_line": 525, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 51, + "top_nesting_level": 1 + }, + { + "name": "add_include_dirs", + "long_name": "add_include_dirs( self , * paths )", + "filename": "misc_util.py", + "nloc": 8, + "complexity": 2, + "token_count": 49, + "parameters": [ + "self", + "paths" + ], + "start_line": 529, + "end_line": 538, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 10, + "top_nesting_level": 1 + }, + { + "name": "add_headers", + "long_name": "add_headers( self , * files )", + "filename": "misc_util.py", + "nloc": 14, + "complexity": 7, + "token_count": 143, + "parameters": [ + "self", + "files" + ], + "start_line": 540, + "end_line": 559, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 20, + "top_nesting_level": 1 + }, + { + "name": "_fix_paths", + "long_name": "_fix_paths( self , paths )", + "filename": "misc_util.py", + "nloc": 22, + "complexity": 8, + "token_count": 136, + "parameters": [ + "self", + "paths" + ], + "start_line": 561, + "end_line": 582, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 22, + "top_nesting_level": 1 + }, + { + "name": "paths", + "long_name": "paths( self , * paths )", + "filename": "misc_util.py", + "nloc": 2, + "complexity": 1, + "token_count": 16, + "parameters": [ + "self", + "paths" + ], + "start_line": 584, + "end_line": 587, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 4, + "top_nesting_level": 1 + }, + { + "name": "add_extension", + "long_name": "add_extension( self , name , sources , ** kw )", + "filename": "misc_util.py", + "nloc": 45, + "complexity": 14, + "token_count": 365, + "parameters": [ + "self", + "name", + "sources", + "kw" + ], + "start_line": 589, + "end_line": 651, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 63, + "top_nesting_level": 1 + }, + { + "name": "add_library", + "long_name": "add_library( self , name , sources , ** build_info )", + "filename": "misc_util.py", + "nloc": 15, + "complexity": 4, + "token_count": 106, + "parameters": [ + "self", + "name", + "sources", + "build_info" + ], + "start_line": 653, + "end_line": 678, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 26, + "top_nesting_level": 1 + }, + { + "name": "add_scripts", + "long_name": "add_scripts( self , * files )", + "filename": "misc_util.py", + "nloc": 8, + "complexity": 2, + "token_count": 49, + "parameters": [ + "self", + "files" + ], + "start_line": 680, + "end_line": 689, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 10, + "top_nesting_level": 1 + }, + { + "name": "dict_append", + "long_name": "dict_append( self , ** dict )", + "filename": "misc_util.py", + "nloc": 15, + "complexity": 6, + "token_count": 138, + "parameters": [ + "self", + "dict" + ], + "start_line": 691, + "end_line": 705, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 15, + "top_nesting_level": 1 + }, + { + "name": "__str__", + "long_name": "__str__( self )", + "filename": "misc_util.py", + "nloc": 10, + "complexity": 3, + "token_count": 72, + "parameters": [ + "self" + ], + "start_line": 707, + "end_line": 716, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 10, + "top_nesting_level": 1 + }, + { + "name": "get_config_cmd", + "long_name": "get_config_cmd( self )", + "filename": "misc_util.py", + "nloc": 10, + "complexity": 2, + "token_count": 63, + "parameters": [ + "self" + ], + "start_line": 718, + "end_line": 727, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 10, + "top_nesting_level": 1 + }, + { + "name": "get_build_temp_dir", + "long_name": "get_build_temp_dir( self )", + "filename": "misc_util.py", + "nloc": 4, + "complexity": 1, + "token_count": 20, + "parameters": [ + "self" + ], + "start_line": 729, + "end_line": 732, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 4, + "top_nesting_level": 1 + }, + { + "name": "have_f77c", + "long_name": "have_f77c( self )", + "filename": "misc_util.py", + "nloc": 8, + "complexity": 1, + "token_count": 30, + "parameters": [ + "self" + ], + "start_line": 734, + "end_line": 745, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 12, + "top_nesting_level": 1 + }, + { + "name": "have_f90c", + "long_name": "have_f90c( self )", + "filename": "misc_util.py", + "nloc": 8, + "complexity": 1, + "token_count": 30, + "parameters": [ + "self" + ], + "start_line": 747, + "end_line": 758, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 12, + "top_nesting_level": 1 + }, + { + "name": "append_to", + "long_name": "append_to( self , extlib )", + "filename": "misc_util.py", + "nloc": 12, + "complexity": 2, + "token_count": 83, + "parameters": [ + "self", + "extlib" + ], + "start_line": 760, + "end_line": 773, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 14, + "top_nesting_level": 1 + }, + { + "name": "_get_svn_revision", + "long_name": "_get_svn_revision( self , path )", + "filename": "misc_util.py", + "nloc": 10, + "complexity": 3, + "token_count": 77, + "parameters": [ + "self", + "path" + ], + "start_line": 775, + "end_line": 786, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 12, + "top_nesting_level": 1 + }, + { + "name": "get_version", + "long_name": "get_version( self )", + "filename": "misc_util.py", + "nloc": 38, + "complexity": 11, + "token_count": 257, + "parameters": [ + "self" + ], + "start_line": 788, + "end_line": 834, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 47, + "top_nesting_level": 1 + }, + { + "name": "make_svn_version_py.make_svn_version_py.generate_svn_version_py.rm_file", + "long_name": "make_svn_version_py.make_svn_version_py.generate_svn_version_py.rm_file( f = target )", + "filename": "misc_util.py", + "nloc": 5, + "complexity": 3, + "token_count": 45, + "parameters": [ + "f" + ], + "start_line": 858, + "end_line": 862, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 5, + "top_nesting_level": 3 + }, + { + "name": "make_svn_version_py.generate_svn_version_py", + "long_name": "make_svn_version_py.generate_svn_version_py( )", + "filename": "misc_util.py", + "nloc": 13, + "complexity": 2, + "token_count": 81, + "parameters": [], + "start_line": 847, + "end_line": 865, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 19, + "top_nesting_level": 2 + }, + { + "name": "make_svn_version_py", + "long_name": "make_svn_version_py( self )", + "filename": "misc_util.py", + "nloc": 8, + "complexity": 2, + "token_count": 66, + "parameters": [ + "self" + ], + "start_line": 836, + "end_line": 869, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 34, + "top_nesting_level": 1 + }, + { + "name": "make_config_py", + "long_name": "make_config_py( self , name = '__config__' )", + "filename": "misc_util.py", + "nloc": 3, + "complexity": 1, + "token_count": 27, + "parameters": [ + "self", + "name" + ], + "start_line": 871, + "end_line": 876, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 6, + "top_nesting_level": 1 + }, + { + "name": "get_info", + "long_name": "get_info( self , * names )", + "filename": "misc_util.py", + "nloc": 6, + "complexity": 2, + "token_count": 36, + "parameters": [ + "self", + "names" + ], + "start_line": 878, + "end_line": 885, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 8, + "top_nesting_level": 1 + }, + { + "name": "get_cmd", + "long_name": "get_cmd( cmdname , _cache = { } )", + "filename": "misc_util.py", + "nloc": 11, + "complexity": 3, + "token_count": 65, + "parameters": [ + "cmdname", + "_cache" + ], + "start_line": 887, + "end_line": 897, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 11, + "top_nesting_level": 0 + }, + { + "name": "get_numpy_include_dirs", + "long_name": "get_numpy_include_dirs( )", + "filename": "misc_util.py", + "nloc": 11, + "complexity": 3, + "token_count": 85, + "parameters": [], + "start_line": 899, + "end_line": 913, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 15, + "top_nesting_level": 0 + }, + { + "name": "default_config_dict", + "long_name": "default_config_dict( name = None , parent_name = None , local_path = None )", + "filename": "misc_util.py", + "nloc": 9, + "complexity": 1, + "token_count": 70, + "parameters": [ + "name", + "parent_name", + "local_path" + ], + "start_line": 917, + "end_line": 928, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 12, + "top_nesting_level": 0 + }, + { + "name": "dict_append", + "long_name": "dict_append( d , ** kws )", + "filename": "misc_util.py", + "nloc": 6, + "complexity": 3, + "token_count": 44, + "parameters": [ + "d", + "kws" + ], + "start_line": 931, + "end_line": 936, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 6, + "top_nesting_level": 0 + }, + { + "name": "appendpath", + "long_name": "appendpath( prefix , path )", + "filename": "misc_util.py", + "nloc": 19, + "complexity": 6, + "token_count": 237, + "parameters": [ + "prefix", + "path" + ], + "start_line": 938, + "end_line": 957, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 20, + "top_nesting_level": 0 + }, + { + "name": "generate_config_py", + "long_name": "generate_config_py( target )", + "filename": "misc_util.py", + "nloc": 27, + "complexity": 2, + "token_count": 117, + "parameters": [ + "target" + ], + "start_line": 959, + "end_line": 992, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 34, + "top_nesting_level": 0 + }, + { + "name": "generate_svn_version_py", + "long_name": "generate_svn_version_py( extension , build_dir )", + "filename": "misc_util.py", + "nloc": 15, + "complexity": 4, + "token_count": 109, + "parameters": [ + "extension", + "build_dir" + ], + "start_line": 994, + "end_line": 1021, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 28, + "top_nesting_level": 0 + } + ], + "changed_methods": [ + { + "name": "is_local_src_dir", + "long_name": "is_local_src_dir( directory )", + "filename": "misc_util.py", + "nloc": 12, + "complexity": 6, + "token_count": 107, + "parameters": [ + "directory" + ], + "start_line": 196, + "end_line": 209, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 14, + "top_nesting_level": 0 + }, + { + "name": "add_data_dir", + "long_name": "add_data_dir( self , data_path )", + "filename": "misc_util.py", + "nloc": 25, + "complexity": 8, + "token_count": 174, + "parameters": [ + "self", + "data_path" + ], + "start_line": 464, + "end_line": 496, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 33, + "top_nesting_level": 1 + }, + { + "name": "get_ext_source_files", + "long_name": "get_ext_source_files( ext )", + "filename": "misc_util.py", + "nloc": 11, + "complexity": 4, + "token_count": 77, + "parameters": [ + "ext" + ], + "start_line": 225, + "end_line": 236, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 12, + "top_nesting_level": 0 + }, + { + "name": "add_data_files", + "long_name": "add_data_files( self , * files )", + "filename": "misc_util.py", + "nloc": 39, + "complexity": 15, + "token_count": 296, + "parameters": [ + "self", + "files" + ], + "start_line": 498, + "end_line": 547, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 50, + "top_nesting_level": 1 + }, + { + "name": "get_script_files", + "long_name": "get_script_files( scripts )", + "filename": "misc_util.py", + "nloc": 3, + "complexity": 1, + "token_count": 15, + "parameters": [ + "scripts" + ], + "start_line": 238, + "end_line": 240, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 3, + "top_nesting_level": 0 + }, + { + "name": "get_lib_source_files", + "long_name": "get_lib_source_files( lib )", + "filename": "misc_util.py", + "nloc": 13, + "complexity": 4, + "token_count": 101, + "parameters": [ + "lib" + ], + "start_line": 242, + "end_line": 254, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 13, + "top_nesting_level": 0 + }, + { + "name": "add_headers", + "long_name": "add_headers( self , * files )", + "filename": "misc_util.py", + "nloc": 15, + "complexity": 8, + "token_count": 136, + "parameters": [ + "self", + "files" + ], + "start_line": 562, + "end_line": 582, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 21, + "top_nesting_level": 1 + }, + { + "name": "is_sequence", + "long_name": "is_sequence( seq )", + "filename": "misc_util.py", + "nloc": 8, + "complexity": 3, + "token_count": 25, + "parameters": [ + "seq" + ], + "start_line": 129, + "end_line": 136, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 8, + "top_nesting_level": 0 + }, + { + "name": "all_strings", + "long_name": "all_strings( lst )", + "filename": "misc_util.py", + "nloc": 5, + "complexity": 3, + "token_count": 22, + "parameters": [ + "lst" + ], + "start_line": 122, + "end_line": 127, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 6, + "top_nesting_level": 0 + }, + { + "name": "is_string", + "long_name": "is_string( s )", + "filename": "misc_util.py", + "nloc": 2, + "complexity": 1, + "token_count": 12, + "parameters": [ + "s" + ], + "start_line": 119, + "end_line": 120, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 2, + "top_nesting_level": 0 + }, + { + "name": "get_distribution", + "long_name": "get_distribution( self )", + "filename": "misc_util.py", + "nloc": 4, + "complexity": 1, + "token_count": 18, + "parameters": [ + "self" + ], + "start_line": 376, + "end_line": 379, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 4, + "top_nesting_level": 1 + }, + { + "name": "get_data_files", + "long_name": "get_data_files( data )", + "filename": "misc_util.py", + "nloc": 18, + "complexity": 7, + "token_count": 94, + "parameters": [ + "data" + ], + "start_line": 256, + "end_line": 273, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 18, + "top_nesting_level": 0 + }, + { + "name": "append_to", + "long_name": "append_to( self , extlib )", + "filename": "misc_util.py", + "nloc": 12, + "complexity": 2, + "token_count": 77, + "parameters": [ + "self", + "extlib" + ], + "start_line": 783, + "end_line": 796, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 14, + "top_nesting_level": 1 + }, + { + "name": "__init__", + "long_name": "__init__( self , package_name = None , parent_name = None , top_path = None , package_path = None , ** attrs )", + "filename": "misc_util.py", + "nloc": 43, + "complexity": 12, + "token_count": 357, + "parameters": [ + "self", + "package_name", + "parent_name", + "top_path", + "package_path", + "attrs" + ], + "start_line": 297, + "end_line": 358, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 62, + "top_nesting_level": 1 + } + ], + "nloc": 780, + "complexity": 245, + "token_count": 5674, + "diff_parsed": { + "added": [ + "def is_string(s):", + " return isinstance(s, str)", + "", + " if not is_string(item):", + "def is_sequence(seq):", + " if is_string(seq):", + " return False", + " try:", + " len(seq)", + " except:", + " return False", + " return True", + "", + " if not is_string(directory):", + " sources = filter(is_string, ext.sources)", + " scripts = filter(is_string, scripts)", + " sources = filter(is_string, sources)", + " if is_string(data):", + " elif is_string(s):", + " raise TypeError,repr(s)", + "", + " package_name -- name of the package", + " Ex.: 'distutils'", + " parent_name -- name of the parent package", + " Ex.: 'numpy'", + " top_path -- directory of the toplevel package", + " Ex.: the directory where the numpy package source sits", + " package_path -- directory of package. Will be computed by magic from the", + " directory of the caller module if not specified", + " Ex.: the directory where numpy.distutils is", + "", + " if not os.path.isdir(package_path):", + " raise ValueError(\"%r is not a directory\" % (package_path,))", + " self.package_path = package_path", + " if isinstance(a, list):", + " elif isinstance(a, dict):", + " self.package_dir[self.name] = package_path", + " dist = distutils.core._setup_distribution", + " if is_sequence(data_path):", + " d, data_path = data_path", + " if not is_string(data_path):", + " raise TypeError(\"not a string: %r\" % (data_path,))", + " if not is_sequence(p):", + " if is_string(p) and not os.path.isabs(p):", + " if is_string(filepattern):", + " nof_path_components = [len(f.split(os.sep))", + " for f in file_list if is_string(f)]", + " if is_string(f):", + " if is_string(path):", + " if not isinstance(path, (tuple, list)) or len(path) != 2:", + " raise TypeError(repr(path))", + " if is_sequence(extlib):" + ], + "deleted": [ + "import types", + " if type(item) is not types.StringType:", + " if type(directory) is not type(''):", + " sources = filter(lambda s:type(s) is types.StringType,ext.sources)", + " scripts = filter(lambda s:type(s) is types.StringType,scripts)", + " sources = filter(lambda s:type(s) is types.StringType,sources)", + " if type(data) is types.StringType:", + " elif type(s) is type(''):", + " raise TypeError,`s`", + "", + " assert os.path.isdir(package_path),`package_path`", + " if type(a) is types.ListType:", + " elif type(a) is types.DictType:", + " self.package_dir[self.name] = package_path", + " dist = distutils.core._setup_distribution", + " if type(data_path) is type(()):", + " assert len(data_path)==2,`data_path`", + " d,data_path = data_path", + " assert type(data_path) is type(''),`data_path`", + " if type(p) is not type(()):", + " if type(p) is type('') and not os.path.isabs(p):", + " if type(filepattern) is type(''):", + " nof_path_components = [len(f.split(os.sep)) \\", + " for f in file_list if type(f) is type('')]", + " if type(f) is type(''):", + " return", + " if type(path) is type(''):", + " assert type(path) in [type(()),type([])] and len(path)==2,`path`", + " if type(extlib) is type(()):" + ] + } + } + ] + }, + { + "hash": "ee0533b791d62c87bee0e7b7a174840917bc7d9d", + "msg": "Add site.cfg to datafiles installed for numpy.distutils.", + "author": { + "name": "cookedm", + "email": "cookedm@localhost" + }, + "committer": { + "name": "cookedm", + "email": "cookedm@localhost" + }, + "author_date": "2006-01-27T22:03:10+00:00", + "author_timezone": 0, + "committer_date": "2006-01-27T22:03:10+00:00", + "committer_timezone": 0, + "branches": [ + "main" + ], + "in_main_branch": true, + "merge": false, + "parents": [ + "ebb9354ecc7a06bdbdc033340e45511bfd110085" + ], + "project_name": "repo_copy", + "project_path": "/tmp/tmppy2o86q9/repo_copy", + "deletions": 0, + "insertions": 1, + "lines": 1, + "files": 1, + "dmm_unit_size": 1.0, + "dmm_unit_complexity": 1.0, + "dmm_unit_interfacing": 1.0, + "modified_files": [ + { + "old_path": "numpy/distutils/setup.py", + "new_path": "numpy/distutils/setup.py", + "filename": "setup.py", + "extension": "py", + "change_type": "MODIFY", + "diff": "@@ -7,6 +7,7 @@ def configuration(parent_package='',top_path=None):\n config.add_subpackage('command')\n config.add_subpackage('fcompiler')\n config.add_data_dir('tests')\n+ config.add_data_files('site.cfg')\n config.make_config_py()\n return config.todict()\n \n", + "added_lines": 1, + "deleted_lines": 0, + "source_code": "#!/usr/bin/env python\nfrom numpy.distutils.core import setup\nfrom numpy.distutils.misc_util import Configuration\n\ndef configuration(parent_package='',top_path=None):\n config = Configuration('distutils',parent_package,top_path)\n config.add_subpackage('command')\n config.add_subpackage('fcompiler')\n config.add_data_dir('tests')\n config.add_data_files('site.cfg')\n config.make_config_py()\n return config.todict()\n\nif __name__ == '__main__':\n setup(**configuration(top_path=''))\n", + "source_code_before": "#!/usr/bin/env python\nfrom numpy.distutils.core import setup\nfrom numpy.distutils.misc_util import Configuration\n\ndef configuration(parent_package='',top_path=None):\n config = Configuration('distutils',parent_package,top_path)\n config.add_subpackage('command')\n config.add_subpackage('fcompiler')\n config.add_data_dir('tests')\n config.make_config_py()\n return config.todict()\n\nif __name__ == '__main__':\n setup(**configuration(top_path=''))\n", + "methods": [ + { + "name": "configuration", + "long_name": "configuration( parent_package = '' , top_path = None )", + "filename": "setup.py", + "nloc": 8, + "complexity": 1, + "token_count": 56, + "parameters": [ + "parent_package", + "top_path" + ], + "start_line": 5, + "end_line": 12, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 8, + "top_nesting_level": 0 + } + ], + "methods_before": [ + { + "name": "configuration", + "long_name": "configuration( parent_package = '' , top_path = None )", + "filename": "setup.py", + "nloc": 7, + "complexity": 1, + "token_count": 50, + "parameters": [ + "parent_package", + "top_path" + ], + "start_line": 5, + "end_line": 11, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 7, + "top_nesting_level": 0 + } + ], + "changed_methods": [ + { + "name": "configuration", + "long_name": "configuration( parent_package = '' , top_path = None )", + "filename": "setup.py", + "nloc": 8, + "complexity": 1, + "token_count": 56, + "parameters": [ + "parent_package", + "top_path" + ], + "start_line": 5, + "end_line": 12, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 8, + "top_nesting_level": 0 + } + ], + "nloc": 12, + "complexity": 1, + "token_count": 88, + "diff_parsed": { + "added": [ + " config.add_data_files('site.cfg')" + ], + "deleted": [] + } + } + ] + }, + { + "hash": "b8e4a5f019da3020939407e447b0631db5e17371", + "msg": "Store the relative path inside the installed package as part of the Configuration instance (instead of recalculating each time)", + "author": { + "name": "cookedm", + "email": "cookedm@localhost" + }, + "committer": { + "name": "cookedm", + "email": "cookedm@localhost" + }, + "author_date": "2006-01-27T22:04:23+00:00", + "author_timezone": 0, + "committer_date": "2006-01-27T22:04:23+00:00", + "committer_timezone": 0, + "branches": [ + "main" + ], + "in_main_branch": true, + "merge": false, + "parents": [ + "ee0533b791d62c87bee0e7b7a174840917bc7d9d" + ], + "project_name": "repo_copy", + "project_path": "/tmp/tmppy2o86q9/repo_copy", + "deletions": 15, + "insertions": 15, + "lines": 30, + "files": 1, + "dmm_unit_size": 0.0, + "dmm_unit_complexity": 0.0, + "dmm_unit_interfacing": 0.0, + "modified_files": [ + { + "old_path": "numpy/distutils/misc_util.py", + "new_path": "numpy/distutils/misc_util.py", + "filename": "misc_util.py", + "extension": "py", + "change_type": "MODIFY", + "diff": "@@ -29,7 +29,7 @@ def get_path(mod_name,parent_path=None):\n if mod_name == '__main__':\n d = os.path.abspath('.')\n elif mod_name == '__builtin__':\n- #builtin if/then added by Pearu for use in core.run_setup. \n+ #builtin if/then added by Pearu for use in core.run_setup.\n d = os.path.dirname(os.path.abspath(sys.argv[0]))\n else:\n __import__(mod_name)\n@@ -55,14 +55,14 @@ def terminal_has_colors():\n # curses.version is 2.2\n # CYGWIN_98-4.10, release 1.5.7(0.109/3/2))\n return 0\n- if hasattr(sys.stdout,'isatty') and sys.stdout.isatty(): \n+ if hasattr(sys.stdout,'isatty') and sys.stdout.isatty():\n try:\n import curses\n curses.setupterm()\n if (curses.tigetnum(\"colors\") >= 0\n and curses.tigetnum(\"pairs\") >= 0\n- and ((curses.tigetstr(\"setf\") is not None \n- and curses.tigetstr(\"setb\") is not None) \n+ and ((curses.tigetstr(\"setf\") is not None\n+ and curses.tigetstr(\"setb\") is not None)\n or (curses.tigetstr(\"setaf\") is not None\n and curses.tigetstr(\"setab\") is not None)\n or curses.tigetstr(\"scp\") is not None)):\n@@ -168,7 +168,7 @@ def filter_sources(sources):\n elif cxx_ext_match(source):\n cxx_sources.append(source)\n else:\n- c_sources.append(source) \n+ c_sources.append(source)\n return c_sources, cxx_sources, f_sources, fmodule_sources\n \n \n@@ -328,6 +328,8 @@ def __init__(self,\n raise ValueError(\"%r is not a directory\" % (package_path,))\n self.top_path = top_path\n self.package_path = package_path\n+ # this is the relative path in the installed package\n+ self.path_in_package = os.path.join(*self.name.split('.'))\n \n self.list_keys = copy.copy(self._list_keys)\n self.dict_keys = copy.copy(self._dict_keys)\n@@ -484,9 +486,8 @@ def add_data_dir(self,data_path):\n os.path.walk(path, _gsf_visit_func,filenames)\n if not os.path.isabs(path):\n if d is None:\n- ds = os.path.join(*(self.name.split('.')+[data_path]))\n- else:\n- ds = os.path.join(d,data_path)\n+ d = self.path_in_package\n+ ds = os.path.join(d, data_path)\n self.add_data_files((ds,filenames))\n else:\n if d is None:\n@@ -508,7 +509,7 @@ def add_data_files(self,*files):\n new_files = []\n for p in files:\n if not is_sequence(p):\n- d = os.path.join(*(self.name.split('.')))\n+ d = self.path_in_package\n if is_string(p) and not os.path.isabs(p):\n d = appendpath(d,os.path.dirname(p))\n p = (d,p)\n@@ -547,7 +548,7 @@ def add_data_files(self,*files):\n self.data_files.extend(data_dict.items())\n \n ### XXX Implement add_py_modules\n- \n+\n def add_include_dirs(self,*paths):\n \"\"\" Add paths to configuration include directories.\n \"\"\"\n@@ -675,7 +676,7 @@ def add_extension(self,name,sources,**kw):\n \n def add_library(self,name,sources,**build_info):\n \"\"\" Add library to configuration.\n- \n+\n Valid keywords for build_info:\n depends\n macros\n@@ -876,7 +877,7 @@ def generate_svn_version_py():\n f = open(target,'w')\n f.write('version = %r\\n' % (version))\n f.close()\n- \n+\n import atexit\n def rm_file(f=target):\n try: os.remove(f); print 'removed',f\n@@ -887,8 +888,7 @@ def rm_file(f=target):\n \n return target\n \n- d = os.path.join(*(self.name.split('.')))\n- self.add_data_files((d, generate_svn_version_py()))\n+ self.add_data_files(generate_svn_version_py())\n return\n \n def make_config_py(self,name='__config__'):\n@@ -1017,7 +1017,7 @@ def show():\n def generate_svn_version_py(extension, build_dir):\n \"\"\" Generate __svn_version__.py file containing SVN\n revision number of a module.\n- \n+\n To use, add the following codelet to setup\n configuration(..) function\n \n", + "added_lines": 15, + "deleted_lines": 15, + "source_code": "import os\nimport re\nimport sys\nimport imp\nimport copy\nimport glob\n\n__all__ = ['Configuration', 'get_numpy_include_dirs', 'default_config_dict',\n 'dict_append', 'appendpath', 'generate_config_py',\n 'generate_svn_version_py', 'get_cmd', 'allpath',\n 'terminal_has_colors', 'red_text', 'green_text', 'yellow_text',\n 'blue_text', 'cyan_text', 'cyg2win32', 'all_strings',\n 'has_f_sources', 'has_cxx_sources', 'filter_sources',\n 'get_dependencies', 'is_local_src_dir', 'get_ext_source_files',\n 'get_script_files', 'get_lib_source_files', 'get_data_files',\n 'dot_join', 'get_frame']\n\ndef allpath(name):\n \"Convert a /-separated pathname to one using the OS's path separator.\"\n splitted = name.split('/')\n return os.path.join(*splitted)\n\ndef get_path(mod_name,parent_path=None):\n \"\"\" Return path of the module.\n\n Returned path is relative to parent_path when given,\n otherwise it is absolute path.\n \"\"\"\n if mod_name == '__main__':\n d = os.path.abspath('.')\n elif mod_name == '__builtin__':\n #builtin if/then added by Pearu for use in core.run_setup.\n d = os.path.dirname(os.path.abspath(sys.argv[0]))\n else:\n __import__(mod_name)\n mod = sys.modules[mod_name]\n file = mod.__file__\n d = os.path.dirname(os.path.abspath(file))\n if parent_path is not None:\n pd = os.path.abspath(parent_path)\n if pd==d[:len(pd)]:\n d = d[len(pd)+1:]\n return d or '.'\n\n# Hooks for colored terminal output.\n# See also http://www.livinglogic.de/Python/ansistyle\ndef terminal_has_colors():\n if sys.platform=='cygwin' and not os.environ.has_key('USE_COLOR'):\n # Avoid importing curses that causes illegal operation\n # with a message:\n # PYTHON2 caused an invalid page fault in\n # module CYGNURSES7.DLL as 015f:18bbfc28\n # Details: Python 2.3.3 [GCC 3.3.1 (cygming special)]\n # ssh to Win32 machine from debian\n # curses.version is 2.2\n # CYGWIN_98-4.10, release 1.5.7(0.109/3/2))\n return 0\n if hasattr(sys.stdout,'isatty') and sys.stdout.isatty():\n try:\n import curses\n curses.setupterm()\n if (curses.tigetnum(\"colors\") >= 0\n and curses.tigetnum(\"pairs\") >= 0\n and ((curses.tigetstr(\"setf\") is not None\n and curses.tigetstr(\"setb\") is not None)\n or (curses.tigetstr(\"setaf\") is not None\n and curses.tigetstr(\"setab\") is not None)\n or curses.tigetstr(\"scp\") is not None)):\n return 1\n except Exception,msg:\n pass\n return 0\n\nif terminal_has_colors():\n def red_text(s): return '\\x1b[31m%s\\x1b[0m'%s\n def green_text(s): return '\\x1b[32m%s\\x1b[0m'%s\n def yellow_text(s): return '\\x1b[33m%s\\x1b[0m'%s\n def blue_text(s): return '\\x1b[34m%s\\x1b[0m'%s\n def cyan_text(s): return '\\x1b[35m%s\\x1b[0m'%s\nelse:\n def red_text(s): return s\n def green_text(s): return s\n def yellow_text(s): return s\n def cyan_text(s): return s\n def blue_text(s): return s\n\n#########################\n\ndef cyg2win32(path):\n if sys.platform=='cygwin' and path.startswith('/cygdrive'):\n path = path[10] + ':' + os.path.normcase(path[11:])\n return path\n\n#########################\n\n#XXX need support for .C that is also C++\ncxx_ext_match = re.compile(r'.*[.](cpp|cxx|cc)\\Z',re.I).match\nfortran_ext_match = re.compile(r'.*[.](f90|f95|f77|for|ftn|f)\\Z',re.I).match\nf90_ext_match = re.compile(r'.*[.](f90|f95)\\Z',re.I).match\nf90_module_name_match = re.compile(r'\\s*module\\s*(?P[\\w_]+)',re.I).match\ndef _get_f90_modules(source):\n \"\"\" Return a list of Fortran f90 module names that\n given source file defines.\n \"\"\"\n if not f90_ext_match(source):\n return []\n modules = []\n f = open(source,'r')\n f_readlines = getattr(f,'xreadlines',f.readlines)\n for line in f_readlines():\n m = f90_module_name_match(line)\n if m:\n name = m.group('name')\n modules.append(name)\n # break # XXX can we assume that there is one module per file?\n f.close()\n return modules\n\ndef is_string(s):\n return isinstance(s, str)\n\ndef all_strings(lst):\n \"\"\" Return True if all items in lst are string objects. \"\"\"\n for item in lst:\n if not is_string(item):\n return False\n return True\n\ndef is_sequence(seq):\n if is_string(seq):\n return False\n try:\n len(seq)\n except:\n return False\n return True\n\ndef has_f_sources(sources):\n \"\"\" Return True if sources contains Fortran files \"\"\"\n for source in sources:\n if fortran_ext_match(source):\n return True\n return False\n\ndef has_cxx_sources(sources):\n \"\"\" Return True if sources contains C++ files \"\"\"\n for source in sources:\n if cxx_ext_match(source):\n return True\n return False\n\ndef filter_sources(sources):\n \"\"\" Return four lists of filenames containing\n C, C++, Fortran, and Fortran 90 module sources,\n respectively.\n \"\"\"\n c_sources = []\n cxx_sources = []\n f_sources = []\n fmodule_sources = []\n for source in sources:\n if fortran_ext_match(source):\n modules = _get_f90_modules(source)\n if modules:\n fmodule_sources.append(source)\n else:\n f_sources.append(source)\n elif cxx_ext_match(source):\n cxx_sources.append(source)\n else:\n c_sources.append(source)\n return c_sources, cxx_sources, f_sources, fmodule_sources\n\n\ndef _get_headers(directory_list):\n # get *.h files from list of directories\n headers = []\n for dir in directory_list:\n head = glob.glob(os.path.join(dir,\"*.h\")) #XXX: *.hpp files??\n headers.extend(head)\n return headers\n\ndef _get_directories(list_of_sources):\n # get unique directories from list of sources.\n direcs = []\n for file in list_of_sources:\n dir = os.path.split(file)\n if dir[0] != '' and not dir[0] in direcs:\n direcs.append(dir[0])\n return direcs\n\ndef get_dependencies(sources):\n #XXX scan sources for include statements\n return _get_headers(_get_directories(sources))\n\ndef is_local_src_dir(directory):\n \"\"\" Return true if directory is local directory.\n \"\"\"\n if not is_string(directory):\n return False\n abs_dir = os.path.abspath(directory)\n c = os.path.commonprefix([os.getcwd(),abs_dir])\n new_dir = abs_dir[len(c):].split(os.sep)\n if new_dir and not new_dir[0]:\n new_dir = new_dir[1:]\n if new_dir and new_dir[0]=='build':\n return False\n new_dir = os.sep.join(new_dir)\n return os.path.isdir(new_dir)\n\ndef _gsf_visit_func(filenames,dirname,names):\n if os.path.basename(dirname) in ['CVS','.svn','build']:\n names[:] = []\n return\n for name in names:\n if name[-1] in \"~#\":\n continue\n fullname = os.path.join(dirname,name)\n ext = os.path.splitext(fullname)[1]\n if ext and ext in ['.pyc','.o']:\n continue\n if os.path.isfile(fullname):\n filenames.append(fullname)\n\ndef get_ext_source_files(ext):\n # Get sources and any include files in the same directory.\n filenames = []\n sources = filter(is_string, ext.sources)\n filenames.extend(sources)\n filenames.extend(get_dependencies(sources))\n for d in ext.depends:\n if is_local_src_dir(d):\n os.path.walk(d,_gsf_visit_func,filenames)\n elif os.path.isfile(d):\n filenames.append(d)\n return filenames\n\ndef get_script_files(scripts):\n scripts = filter(is_string, scripts)\n return scripts\n\ndef get_lib_source_files(lib):\n filenames = []\n sources = lib[1].get('sources',[])\n sources = filter(is_string, sources)\n filenames.extend(sources)\n filenames.extend(get_dependencies(sources))\n depends = lib[1].get('depends',[])\n for d in depends:\n if is_local_src_dir(d):\n os.path.walk(d,_gsf_visit_func,filenames)\n elif os.path.isfile(d):\n filenames.append(d)\n return filenames\n\ndef get_data_files(data):\n if is_string(data):\n return [data]\n sources = data[1]\n filenames = []\n for s in sources:\n if callable(s):\n continue\n if is_local_src_dir(s):\n os.path.walk(s,_gsf_visit_func,filenames)\n elif is_string(s):\n if os.path.isfile(s):\n filenames.append(s)\n else:\n print 'Not existing data file:',s\n else:\n raise TypeError,repr(s)\n return filenames\n\ndef dot_join(*args):\n return '.'.join(filter(None,args))\n\ndef get_frame(level=0):\n try:\n return sys._getframe(level+1)\n except AttributeError:\n frame = sys.exc_info()[2].tb_frame\n for i in range(level+1):\n frame = frame.f_back\n return frame\n\n######################\n\nclass Configuration:\n\n _list_keys = ['packages','ext_modules','data_files','include_dirs',\n 'libraries','headers','scripts','py_modules']\n _dict_keys = ['package_dir']\n\n numpy_include_dirs = []\n\n def __init__(self,\n package_name=None,\n parent_name=None,\n top_path=None,\n package_path=None,\n **attrs):\n \"\"\" Construct configuration instance of a package.\n\n package_name -- name of the package\n Ex.: 'distutils'\n parent_name -- name of the parent package\n Ex.: 'numpy'\n top_path -- directory of the toplevel package\n Ex.: the directory where the numpy package source sits\n package_path -- directory of package. Will be computed by magic from the\n directory of the caller module if not specified\n Ex.: the directory where numpy.distutils is\n \"\"\"\n self.name = dot_join(parent_name, package_name)\n\n caller_frame = get_frame(1)\n caller_name = eval('__name__',caller_frame.f_globals,caller_frame.f_locals)\n\n self.local_path = get_path(caller_name, top_path)\n if top_path is None:\n top_path = self.local_path\n if package_path is None:\n package_path = self.local_path\n elif os.path.isdir(os.path.join(self.local_path,package_path)):\n package_path = os.path.join(self.local_path,package_path)\n if not os.path.isdir(package_path):\n raise ValueError(\"%r is not a directory\" % (package_path,))\n self.top_path = top_path\n self.package_path = package_path\n # this is the relative path in the installed package\n self.path_in_package = os.path.join(*self.name.split('.'))\n\n self.list_keys = copy.copy(self._list_keys)\n self.dict_keys = copy.copy(self._dict_keys)\n\n for n in self.list_keys:\n setattr(self,n,copy.copy(attrs.get(n,[])))\n\n for n in self.dict_keys:\n setattr(self,n,copy.copy(attrs.get(n,{})))\n\n known_keys = self.list_keys + self.dict_keys\n self.extra_keys = []\n for n in attrs.keys():\n if n in known_keys:\n continue\n a = attrs[n]\n setattr(self,n,a)\n if isinstance(a, list):\n self.list_keys.append(n)\n elif isinstance(a, dict):\n self.dict_keys.append(n)\n else:\n self.extra_keys.append(n)\n\n if os.path.exists(os.path.join(package_path,'__init__.py')):\n self.packages.append(self.name)\n self.package_dir[self.name] = package_path\n return\n\n def todict(self):\n \"\"\" Return configuration distionary suitable for passing\n to distutils.core.setup() function.\n \"\"\"\n d = {}\n for n in self.list_keys + self.dict_keys + self.extra_keys:\n a = getattr(self,n)\n if a:\n d[n] = a\n if self.name:\n d['name'] = self.name\n return d\n\n def __dict__(self):\n return self.todict()\n\n def get_distribution(self):\n import distutils.core\n dist = distutils.core._setup_distribution\n return dist\n\n def get_subpackage(self,subpackage_name,subpackage_path=None):\n \"\"\" Return subpackage configuration.\n \"\"\"\n if subpackage_name is None:\n assert subpackage_path is not None\n subpackage_name = os.path.basename(subpackage_path)\n l = subpackage_name.split('.')\n if subpackage_path is None:\n subpackage_path = os.path.join(*([self.local_path]+l))\n if '*' in subpackage_name:\n dirs = filter(os.path.isdir,glob.glob(subpackage_path))\n config_list = []\n for d in dirs:\n if not os.path.isfile(os.path.join(d,'__init__.py')):\n continue\n n = '.'.join(d.split(os.sep)[-len(l):])\n c = self.get_subpackage(n)\n if c:\n config_list.append(c)\n return config_list\n else:\n subpackage_path = os.path.join(*([subpackage_path]+l[:-1]))\n subpackage_path = self._fix_paths([subpackage_path])[0]\n\n setup_py = os.path.join(subpackage_path,'setup.py')\n if not os.path.isfile(setup_py):\n setup_py = os.path.join(subpackage_path,'setup_%s.py' % (subpackage_name))\n\n if not os.path.isfile(setup_py):\n print 'Assuming default configuration '\\\n '(%s/{setup_%s,setup}.py was not found)' \\\n % (os.path.dirname(setup_py),subpackage_name)\n config = Configuration(subpackage_name,self.name,\n self.top_path,subpackage_path)\n else:\n # In case setup_py imports local modules:\n sys.path.insert(0,os.path.dirname(setup_py))\n try:\n info = (open(setup_py),setup_py,('.py','U',1))\n setup_name = os.path.splitext(os.path.basename(setup_py))[0]\n n = dot_join(self.name,setup_name)\n setup_module = imp.load_module('_'.join(n.split('.')),*info)\n\n if not hasattr(setup_module,'configuration'):\n print 'Assuming default configuration '\\\n '(%s does not define configuration())' % (setup_module)\n config = Configuration(subpackage_name,self.name,\n self.top_path,subpackage_path)\n else:\n args = (self.name,)\n if setup_module.configuration.func_code.co_argcount>1:\n args = args + (self.top_path,)\n config = setup_module.configuration(*args)\n\n finally:\n del sys.path[0]\n\n return config\n\n def add_subpackage(self,subpackage_name,subpackage_path=None):\n \"\"\" Add subpackage to configuration.\n \"\"\"\n config = self.get_subpackage(subpackage_name,subpackage_path)\n if not isinstance(config, list):\n config_list = [config]\n else:\n config_list = config\n for config in config_list:\n if not config:\n print 'No configuration returned, assuming unavailable.'\n else:\n if isinstance(config,Configuration):\n print 'Appending %s configuration to %s' % (config.name,self.name)\n self.dict_append(**config.todict())\n else:\n print 'Appending %s configuration to %s' % (config.get('name'),self.name)\n self.dict_append(**config)\n\n dist = self.get_distribution()\n if dist is not None:\n print 'distutils distribution has been initialized, it may be too late to add a subpackage', subpackage_name\n return\n\n def add_data_dir(self,data_path):\n \"\"\" Recursively add files under data_path to data_files list.\n Argument can be either\n - 2-sequence (,)\n - path to data directory where python datadir suffix defaults\n to package dir.\n If path is not absolute then it's datadir suffix is\n package dir + subdirname of the path.\n \"\"\"\n if is_sequence(data_path):\n d, data_path = data_path\n else:\n d = None\n if not is_string(data_path):\n raise TypeError(\"not a string: %r\" % (data_path,))\n for path in self.paths(data_path):\n if not os.path.exists(path):\n print 'Not existing data path',path\n continue\n filenames = []\n os.path.walk(path, _gsf_visit_func,filenames)\n if not os.path.isabs(path):\n if d is None:\n d = self.path_in_package\n ds = os.path.join(d, data_path)\n self.add_data_files((ds,filenames))\n else:\n if d is None:\n self.add_data_files(*filenames)\n else:\n self.add_data_files((d,filenames))\n return\n\n def add_data_files(self,*files):\n \"\"\" Add data files to configuration data_files.\n Argument(s) can be either\n - 2-sequence (,)\n - paths to data files where python datadir prefix defaults\n to package dir.\n If path is not absolute then it's datadir prefix is\n package dir + dirname of the path.\n \"\"\"\n data_dict = {}\n new_files = []\n for p in files:\n if not is_sequence(p):\n d = self.path_in_package\n if is_string(p) and not os.path.isabs(p):\n d = appendpath(d,os.path.dirname(p))\n p = (d,p)\n new_files.append(p)\n files = []\n for prefix,filepattern in new_files:\n if is_string(filepattern):\n file_list = self.paths(filepattern)\n elif callable(filepattern):\n file_list = [filepattern]\n else:\n file_list = self.paths(*filepattern)\n\n nof_path_components = [len(f.split(os.sep))\n for f in file_list if is_string(f)]\n if nof_path_components:\n min_path_components = min(nof_path_components)-1\n else:\n min_path_components = 0\n\n for f in file_list:\n if is_string(f):\n extra_path_components = f.split(os.sep)[min_path_components:-1]\n p = os.path.join(*([prefix]+extra_path_components))\n else:\n p = prefix\n if not data_dict.has_key(p):\n data_dict[p] = [f]\n else:\n data_dict[p].append(f)\n\n dist = self.get_distribution()\n if dist is not None:\n dist.data_files.extend(data_dict.items())\n else:\n self.data_files.extend(data_dict.items())\n\n ### XXX Implement add_py_modules\n\n def add_include_dirs(self,*paths):\n \"\"\" Add paths to configuration include directories.\n \"\"\"\n include_dirs = self._fix_paths(paths)\n dist = self.get_distribution()\n if dist is not None:\n dist.include_dirs.extend(include_dirs)\n else:\n self.include_dirs.extend(include_dirs)\n return\n\n def add_headers(self,*files):\n \"\"\" Add installable headers to configuration.\n Argument(s) can be either\n - 2-sequence (,)\n - path(s) to header file(s) where python includedir suffix will default\n to package name.\n \"\"\"\n headers = []\n for path in files:\n if is_string(path):\n [headers.append((self.name,p)) for p in self.paths(path)]\n else:\n if not isinstance(path, (tuple, list)) or len(path) != 2:\n raise TypeError(repr(path))\n [headers.append((path[0],p)) for p in self.paths(path[1])]\n dist = self.get_distribution()\n if dist is not None:\n dist.headers.extend(headers)\n else:\n self.headers.extend(headers)\n return\n\n def _fix_paths(self,paths):\n new_paths = []\n for n in paths:\n if isinstance(n,str):\n if '*' in n or '?' in n:\n p = glob.glob(n)\n p2 = glob.glob(os.path.join(self.local_path,n))\n if p2:\n new_paths.extend(p2)\n elif p:\n new_paths.extend(p)\n else:\n new_paths.append(n)\n else:\n n2 = os.path.join(self.local_path,n)\n if os.path.exists(n2):\n new_paths.append(n2)\n else:\n new_paths.append(n)\n else:\n new_paths.append(n)\n return new_paths\n\n def paths(self,*paths):\n \"\"\" Apply glob to paths and prepend local_path if needed.\n \"\"\"\n return self._fix_paths(paths)\n\n def add_extension(self,name,sources,**kw):\n \"\"\" Add extension to configuration.\n\n Keywords:\n include_dirs, define_macros, undef_macros,\n library_dirs, libraries, runtime_library_dirs,\n extra_objects, extra_compile_args, extra_link_args,\n export_symbols, swig_opts, depends, language,\n f2py_options, module_dirs\n extra_info - dict or list of dict of keywords to be\n appended to keywords.\n \"\"\"\n ext_args = copy.copy(kw)\n ext_args['name'] = dot_join(self.name,name)\n ext_args['sources'] = sources\n\n if ext_args.has_key('extra_info'):\n extra_info = ext_args['extra_info']\n del ext_args['extra_info']\n if type(extra_info) is type({}):\n extra_info = [extra_info]\n for info in extra_info:\n assert type(info) is type({}),`info`\n dict_append(ext_args,**info)\n\n for k in ext_args.keys():\n v = ext_args[k]\n if k in ['sources','depends','include_dirs','library_dirs',\n 'module_dirs','extra_objects']:\n new_v = self._fix_paths(v)\n ext_args[k] = new_v\n\n # Resolve out-of-tree dependencies\n libraries = ext_args.get('libraries',[])\n libnames = []\n ext_args['libraries'] = []\n for libname in libraries:\n if '@' in libname:\n lname,lpath = libname.split('@',1)\n lpath = os.path.abspath(os.path.join(self.local_path,lpath))\n if os.path.isdir(lpath):\n c = self.get_subpackage(None,lpath)\n if isinstance(c,Configuration):\n c = c.todict()\n for l in [l[0] for l in c.get('libraries',[])]:\n llname = l.split('__OF__',1)[0]\n if llname == lname:\n c.pop('name',None)\n dict_append(ext_args,**c)\n break\n continue\n libnames.append(libname)\n\n ext_args['libraries'] = libnames + ext_args['libraries']\n\n from numpy.distutils.core import Extension\n ext = Extension(**ext_args)\n self.ext_modules.append(ext)\n\n dist = self.get_distribution()\n if dist is not None:\n print 'distutils distribution has been initialized, it may be too late to add an extension', name\n return ext\n\n def add_library(self,name,sources,**build_info):\n \"\"\" Add library to configuration.\n\n Valid keywords for build_info:\n depends\n macros\n include_dirs\n extra_compiler_args\n f2py_options\n \"\"\"\n build_info = copy.copy(build_info)\n name = name #+ '__OF__' + self.name\n build_info['sources'] = sources\n\n for k in build_info.keys():\n v = build_info[k]\n if k in ['sources','depends','include_dirs','library_dirs',\n 'module_dirs','extra_objects']:\n new_v = self._fix_paths(v)\n build_info[k] = new_v\n self.libraries.append((name,build_info))\n\n dist = self.get_distribution()\n if dist is not None:\n print 'distutils distribution has been initialized, it may be too late to add a library', name\n return\n\n def add_scripts(self,*files):\n \"\"\" Add scripts to configuration.\n \"\"\"\n scripts = self._fix_paths(files)\n dist = self.get_distribution()\n if dist is not None:\n dist.scripts.extend(scripts)\n else:\n self.scripts.extend(scripts)\n return\n\n def dict_append(self,**dict):\n for key in self.list_keys:\n a = getattr(self,key)\n a.extend(dict.get(key,[]))\n for key in self.dict_keys:\n a = getattr(self,key)\n a.update(dict.get(key,{}))\n known_keys = self.list_keys + self.dict_keys + self.extra_keys\n for key in dict.keys():\n if key not in known_keys and not hasattr(self,key):\n print 'Inheriting attribute %r from %r' \\\n % (key,dict.get('name','?'))\n setattr(self,key,dict[key])\n self.extra_keys.append(key)\n return\n\n def __str__(self):\n known_keys = self.list_keys + self.dict_keys + self.extra_keys\n s = '<'+5*'-' + '\\n'\n s += 'Configuration of '+self.name+':\\n'\n for k in known_keys:\n a = getattr(self,k,None)\n if a:\n s += '%s = %r\\n' % (k,a)\n s += 5*'-' + '>'\n return s\n\n def get_config_cmd(self):\n cmd = get_cmd('config')\n cmd.ensure_finalized()\n cmd.dump_source = 0\n cmd.noisy = 0\n old_path = os.environ.get('PATH')\n if old_path:\n path = os.pathsep.join(['.',old_path])\n os.environ['PATH'] = path\n return cmd\n\n def get_build_temp_dir(self):\n cmd = get_cmd('build')\n cmd.ensure_finalized()\n return cmd.build_temp\n\n def have_f77c(self):\n \"\"\" Check for availability of Fortran 77 compiler.\n Use it inside source generating function to ensure that\n setup distribution instance has been initialized.\n \"\"\"\n simple_fortran_subroutine = '''\n subroutine simple\n end\n '''\n config_cmd = self.get_config_cmd()\n flag = config_cmd.try_compile(simple_fortran_subroutine,lang='f77')\n return flag\n\n def have_f90c(self):\n \"\"\" Check for availability of Fortran 90 compiler.\n Use it inside source generating function to ensure that\n setup distribution instance has been initialized.\n \"\"\"\n simple_fortran_subroutine = '''\n subroutine simple\n end\n '''\n config_cmd = self.get_config_cmd()\n flag = config_cmd.try_compile(simple_fortran_subroutine,lang='f90')\n return flag\n\n def append_to(self, extlib):\n \"\"\" Append libraries, include_dirs to extension or library item.\n \"\"\"\n if is_sequence(extlib):\n lib_name, build_info = extlib\n dict_append(build_info,\n libraries=self.libraries,\n include_dirs=self.include_dirs)\n else:\n from numpy.distutils.core import Extension\n assert isinstance(extlib,Extension),`extlib`\n extlib.libraries.extend(self.libraries)\n extlib.include_dirs.extend(self.include_dirs)\n return\n\n def _get_svn_revision(self,path):\n \"\"\" Return path's SVN revision number.\n \"\"\"\n entries = os.path.join(path,'.svn','entries')\n revision = None\n if os.path.isfile(entries):\n f = open(entries)\n m = re.search(r'revision=\"(?P\\d+)\"',f.read())\n f.close()\n if m:\n revision = int(m.group('revision'))\n return revision\n\n def get_version(self):\n \"\"\" Try to get version string of a package.\n \"\"\"\n version = getattr(self,'version',None)\n if version is not None:\n return version\n\n # Get version from version file.\n files = ['__version__.py',\n self.name.split('.')[-1]+'_version.py',\n 'version.py',\n '__svn_version__.py']\n version_vars = ['version',\n '__version__',\n self.name.split('.')[-1]+'_version']\n for f in files:\n fn = os.path.join(self.local_path,f)\n if os.path.isfile(fn):\n info = (open(fn),fn,('.py','U',1))\n name = os.path.splitext(os.path.basename(fn))[0]\n n = dot_join(self.name,name)\n try:\n version_module = imp.load_module('_'.join(n.split('.')),*info)\n except ImportError,msg:\n print msg\n version_module = None\n if version_module is None:\n continue\n\n for a in version_vars:\n version = getattr(version_module,a,None)\n if version is not None:\n break\n if version is not None:\n break\n\n if version is not None:\n self.version = version\n return version\n\n # Get version as SVN revision number\n revision = self._get_svn_revision(self.local_path)\n if revision is not None:\n version = str(revision)\n self.version = version\n\n return version\n\n def make_svn_version_py(self):\n \"\"\" Generate package __svn_version__.py file from SVN revision number,\n it will be removed after python exits but will be available\n when sdist, etc commands are executed.\n\n If __svn_version__.py existed before, nothing is done.\n \"\"\"\n target = os.path.join(self.local_path,'__svn_version__.py')\n if os.path.isfile(target):\n return\n\n def generate_svn_version_py():\n if not os.path.isfile(target):\n revision = self._get_svn_revision(self.local_path)\n assert revision is not None,'hmm, why I am not inside SVN tree???'\n version = str(revision)\n print 'Creating %s (version=%r)' % (target,version)\n f = open(target,'w')\n f.write('version = %r\\n' % (version))\n f.close()\n\n import atexit\n def rm_file(f=target):\n try: os.remove(f); print 'removed',f\n except OSError: pass\n try: os.remove(f+'c'); print 'removed',f+'c'\n except OSError: pass\n atexit.register(rm_file)\n\n return target\n\n self.add_data_files(generate_svn_version_py())\n return\n\n def make_config_py(self,name='__config__'):\n \"\"\" Generate package __config__.py file containing system_info\n information used during building the package.\n \"\"\"\n self.py_modules.append((self.name,name,generate_config_py))\n return\n\n def get_info(self,*names):\n \"\"\" Get resources information.\n \"\"\"\n from system_info import get_info, dict_append\n info_dict = {}\n for a in names:\n dict_append(info_dict,**get_info(a))\n return info_dict\n\ndef get_cmd(cmdname,_cache={}):\n if not _cache.has_key(cmdname):\n import distutils.core\n dist = distutils.core._setup_distribution\n if dist is None:\n from distutils.errors import DistutilsInternalError\n raise DistutilsInternalError,\\\n 'setup distribution instance not initialized'\n cmd = dist.get_command_obj(cmdname)\n _cache[cmdname] = cmd\n return _cache[cmdname]\n\ndef get_numpy_include_dirs():\n # numpy_include_dirs are set by numpy/core/setup.py, otherwise []\n include_dirs = Configuration.numpy_include_dirs[:]\n if not include_dirs:\n import numpy\n if numpy.show_config is None:\n # running from numpy_core source directory\n include_dirs.append(os.path.join(os.path.dirname(numpy.__file__),\n 'core','include'))\n else:\n # using installed numpy core headers\n import numpy.core as core\n include_dirs.append(os.path.join(os.path.dirname(core.__file__),'include'))\n # else running numpy/core/setup.py\n return include_dirs\n\n#########################\n\ndef default_config_dict(name = None, parent_name = None, local_path=None):\n \"\"\" Return a configuration dictionary for usage in\n configuration() function defined in file setup_.py.\n \"\"\"\n import warnings\n warnings.warn('Use Configuration(%s,%s,top_path=%s) instead of '\\\n 'deprecated default_config_dict(%s,%s,%s)' \\\n % (`name`,`parent_name`,`local_path`,\n `name`,`parent_name`,`local_path`,\n ))\n c = Configuration(name, parent_name, local_path)\n return c.todict()\n\n\ndef dict_append(d,**kws):\n for k,v in kws.items():\n if d.has_key(k):\n d[k].extend(v)\n else:\n d[k] = v\n\ndef appendpath(prefix,path):\n if not ('/' == os.path.sep):\n prefix = prefix.replace('/',os.path.sep)\n path = path.replace('/',os.path.sep)\n drive = ''\n if os.path.isabs(path):\n drive = os.path.splitdrive(prefix)[0]\n absprefix = os.path.splitdrive(os.path.abspath(prefix))[1]\n pathdrive,path = os.path.splitdrive(path)\n d = os.path.commonprefix([absprefix,path])\n if os.path.join(absprefix[:len(d)],absprefix[len(d):])!=absprefix \\\n or os.path.join(path[:len(d)],path[len(d):])!=path:\n # Handle invalid paths\n d = os.path.dirname(d)\n subpath = path[len(d):]\n if os.path.isabs(subpath):\n subpath = subpath[1:]\n else:\n subpath = path\n return os.path.normpath(os.path.join(drive + prefix, subpath))\n\ndef generate_config_py(target):\n \"\"\" Generate config.py file containing system_info information\n used during building the package.\n\n Usage:\\\n config['py_modules'].append((packagename, '__config__',generate_config_py))\n \"\"\"\n from numpy.distutils.system_info import system_info\n from distutils.dir_util import mkpath\n mkpath(os.path.dirname(target))\n f = open(target,'w')\n f.write('# This file is generated by %s\\n' % (os.path.abspath(sys.argv[0])))\n f.write('# It contains system_info results at the time of building this package.\\n')\n f.write('__all__ = [\"get_info\",\"show\"]\\n\\n')\n for k,i in system_info.saved_results.items():\n f.write('%s=%r\\n' % (k,i))\n f.write('\\ndef get_info(name): g=globals(); return g.get(name,g.get(name+\"_info\",{}))\\n')\n f.write('''\ndef show():\n for name,info_dict in globals().items():\n if name[0]==\"_\" or type(info_dict) is not type({}): continue\n print name+\":\"\n if not info_dict:\n print \" NOT AVAILABLE\"\n for k,v in info_dict.items():\n v = str(v)\n if k==\\'sources\\' and len(v)>200: v = v[:60]+\\' ...\\\\n... \\'+v[-60:]\n print \\' %s = %s\\'%(k,v)\n print\n return\n ''')\n\n f.close()\n return target\n\ndef generate_svn_version_py(extension, build_dir):\n \"\"\" Generate __svn_version__.py file containing SVN\n revision number of a module.\n\n To use, add the following codelet to setup\n configuration(..) function\n\n ext = Extension(dot_join(config['name'],'__svn_version__'),\n sources=[generate_svn_version_py])\n ext.local_path = local_path\n config['ext_modules'].append(ext)\n\n \"\"\"\n from distutils import dep_util\n local_path = extension.local_path\n target = os.path.join(build_dir, '__svn_version__.py')\n entries = os.path.join(local_path,'.svn','entries')\n if os.path.isfile(entries):\n if not dep_util.newer(entries, target):\n return target\n elif os.path.isfile(target):\n return target\n\n revision = get_svn_revision(local_path)\n f = open(target,'w')\n f.write('revision=%s\\n' % (revision))\n f.close()\n return target\n", + "source_code_before": "import os\nimport re\nimport sys\nimport imp\nimport copy\nimport glob\n\n__all__ = ['Configuration', 'get_numpy_include_dirs', 'default_config_dict',\n 'dict_append', 'appendpath', 'generate_config_py',\n 'generate_svn_version_py', 'get_cmd', 'allpath',\n 'terminal_has_colors', 'red_text', 'green_text', 'yellow_text',\n 'blue_text', 'cyan_text', 'cyg2win32', 'all_strings',\n 'has_f_sources', 'has_cxx_sources', 'filter_sources',\n 'get_dependencies', 'is_local_src_dir', 'get_ext_source_files',\n 'get_script_files', 'get_lib_source_files', 'get_data_files',\n 'dot_join', 'get_frame']\n\ndef allpath(name):\n \"Convert a /-separated pathname to one using the OS's path separator.\"\n splitted = name.split('/')\n return os.path.join(*splitted)\n\ndef get_path(mod_name,parent_path=None):\n \"\"\" Return path of the module.\n\n Returned path is relative to parent_path when given,\n otherwise it is absolute path.\n \"\"\"\n if mod_name == '__main__':\n d = os.path.abspath('.')\n elif mod_name == '__builtin__':\n #builtin if/then added by Pearu for use in core.run_setup. \n d = os.path.dirname(os.path.abspath(sys.argv[0]))\n else:\n __import__(mod_name)\n mod = sys.modules[mod_name]\n file = mod.__file__\n d = os.path.dirname(os.path.abspath(file))\n if parent_path is not None:\n pd = os.path.abspath(parent_path)\n if pd==d[:len(pd)]:\n d = d[len(pd)+1:]\n return d or '.'\n\n# Hooks for colored terminal output.\n# See also http://www.livinglogic.de/Python/ansistyle\ndef terminal_has_colors():\n if sys.platform=='cygwin' and not os.environ.has_key('USE_COLOR'):\n # Avoid importing curses that causes illegal operation\n # with a message:\n # PYTHON2 caused an invalid page fault in\n # module CYGNURSES7.DLL as 015f:18bbfc28\n # Details: Python 2.3.3 [GCC 3.3.1 (cygming special)]\n # ssh to Win32 machine from debian\n # curses.version is 2.2\n # CYGWIN_98-4.10, release 1.5.7(0.109/3/2))\n return 0\n if hasattr(sys.stdout,'isatty') and sys.stdout.isatty(): \n try:\n import curses\n curses.setupterm()\n if (curses.tigetnum(\"colors\") >= 0\n and curses.tigetnum(\"pairs\") >= 0\n and ((curses.tigetstr(\"setf\") is not None \n and curses.tigetstr(\"setb\") is not None) \n or (curses.tigetstr(\"setaf\") is not None\n and curses.tigetstr(\"setab\") is not None)\n or curses.tigetstr(\"scp\") is not None)):\n return 1\n except Exception,msg:\n pass\n return 0\n\nif terminal_has_colors():\n def red_text(s): return '\\x1b[31m%s\\x1b[0m'%s\n def green_text(s): return '\\x1b[32m%s\\x1b[0m'%s\n def yellow_text(s): return '\\x1b[33m%s\\x1b[0m'%s\n def blue_text(s): return '\\x1b[34m%s\\x1b[0m'%s\n def cyan_text(s): return '\\x1b[35m%s\\x1b[0m'%s\nelse:\n def red_text(s): return s\n def green_text(s): return s\n def yellow_text(s): return s\n def cyan_text(s): return s\n def blue_text(s): return s\n\n#########################\n\ndef cyg2win32(path):\n if sys.platform=='cygwin' and path.startswith('/cygdrive'):\n path = path[10] + ':' + os.path.normcase(path[11:])\n return path\n\n#########################\n\n#XXX need support for .C that is also C++\ncxx_ext_match = re.compile(r'.*[.](cpp|cxx|cc)\\Z',re.I).match\nfortran_ext_match = re.compile(r'.*[.](f90|f95|f77|for|ftn|f)\\Z',re.I).match\nf90_ext_match = re.compile(r'.*[.](f90|f95)\\Z',re.I).match\nf90_module_name_match = re.compile(r'\\s*module\\s*(?P[\\w_]+)',re.I).match\ndef _get_f90_modules(source):\n \"\"\" Return a list of Fortran f90 module names that\n given source file defines.\n \"\"\"\n if not f90_ext_match(source):\n return []\n modules = []\n f = open(source,'r')\n f_readlines = getattr(f,'xreadlines',f.readlines)\n for line in f_readlines():\n m = f90_module_name_match(line)\n if m:\n name = m.group('name')\n modules.append(name)\n # break # XXX can we assume that there is one module per file?\n f.close()\n return modules\n\ndef is_string(s):\n return isinstance(s, str)\n\ndef all_strings(lst):\n \"\"\" Return True if all items in lst are string objects. \"\"\"\n for item in lst:\n if not is_string(item):\n return False\n return True\n\ndef is_sequence(seq):\n if is_string(seq):\n return False\n try:\n len(seq)\n except:\n return False\n return True\n\ndef has_f_sources(sources):\n \"\"\" Return True if sources contains Fortran files \"\"\"\n for source in sources:\n if fortran_ext_match(source):\n return True\n return False\n\ndef has_cxx_sources(sources):\n \"\"\" Return True if sources contains C++ files \"\"\"\n for source in sources:\n if cxx_ext_match(source):\n return True\n return False\n\ndef filter_sources(sources):\n \"\"\" Return four lists of filenames containing\n C, C++, Fortran, and Fortran 90 module sources,\n respectively.\n \"\"\"\n c_sources = []\n cxx_sources = []\n f_sources = []\n fmodule_sources = []\n for source in sources:\n if fortran_ext_match(source):\n modules = _get_f90_modules(source)\n if modules:\n fmodule_sources.append(source)\n else:\n f_sources.append(source)\n elif cxx_ext_match(source):\n cxx_sources.append(source)\n else:\n c_sources.append(source) \n return c_sources, cxx_sources, f_sources, fmodule_sources\n\n\ndef _get_headers(directory_list):\n # get *.h files from list of directories\n headers = []\n for dir in directory_list:\n head = glob.glob(os.path.join(dir,\"*.h\")) #XXX: *.hpp files??\n headers.extend(head)\n return headers\n\ndef _get_directories(list_of_sources):\n # get unique directories from list of sources.\n direcs = []\n for file in list_of_sources:\n dir = os.path.split(file)\n if dir[0] != '' and not dir[0] in direcs:\n direcs.append(dir[0])\n return direcs\n\ndef get_dependencies(sources):\n #XXX scan sources for include statements\n return _get_headers(_get_directories(sources))\n\ndef is_local_src_dir(directory):\n \"\"\" Return true if directory is local directory.\n \"\"\"\n if not is_string(directory):\n return False\n abs_dir = os.path.abspath(directory)\n c = os.path.commonprefix([os.getcwd(),abs_dir])\n new_dir = abs_dir[len(c):].split(os.sep)\n if new_dir and not new_dir[0]:\n new_dir = new_dir[1:]\n if new_dir and new_dir[0]=='build':\n return False\n new_dir = os.sep.join(new_dir)\n return os.path.isdir(new_dir)\n\ndef _gsf_visit_func(filenames,dirname,names):\n if os.path.basename(dirname) in ['CVS','.svn','build']:\n names[:] = []\n return\n for name in names:\n if name[-1] in \"~#\":\n continue\n fullname = os.path.join(dirname,name)\n ext = os.path.splitext(fullname)[1]\n if ext and ext in ['.pyc','.o']:\n continue\n if os.path.isfile(fullname):\n filenames.append(fullname)\n\ndef get_ext_source_files(ext):\n # Get sources and any include files in the same directory.\n filenames = []\n sources = filter(is_string, ext.sources)\n filenames.extend(sources)\n filenames.extend(get_dependencies(sources))\n for d in ext.depends:\n if is_local_src_dir(d):\n os.path.walk(d,_gsf_visit_func,filenames)\n elif os.path.isfile(d):\n filenames.append(d)\n return filenames\n\ndef get_script_files(scripts):\n scripts = filter(is_string, scripts)\n return scripts\n\ndef get_lib_source_files(lib):\n filenames = []\n sources = lib[1].get('sources',[])\n sources = filter(is_string, sources)\n filenames.extend(sources)\n filenames.extend(get_dependencies(sources))\n depends = lib[1].get('depends',[])\n for d in depends:\n if is_local_src_dir(d):\n os.path.walk(d,_gsf_visit_func,filenames)\n elif os.path.isfile(d):\n filenames.append(d)\n return filenames\n\ndef get_data_files(data):\n if is_string(data):\n return [data]\n sources = data[1]\n filenames = []\n for s in sources:\n if callable(s):\n continue\n if is_local_src_dir(s):\n os.path.walk(s,_gsf_visit_func,filenames)\n elif is_string(s):\n if os.path.isfile(s):\n filenames.append(s)\n else:\n print 'Not existing data file:',s\n else:\n raise TypeError,repr(s)\n return filenames\n\ndef dot_join(*args):\n return '.'.join(filter(None,args))\n\ndef get_frame(level=0):\n try:\n return sys._getframe(level+1)\n except AttributeError:\n frame = sys.exc_info()[2].tb_frame\n for i in range(level+1):\n frame = frame.f_back\n return frame\n\n######################\n\nclass Configuration:\n\n _list_keys = ['packages','ext_modules','data_files','include_dirs',\n 'libraries','headers','scripts','py_modules']\n _dict_keys = ['package_dir']\n\n numpy_include_dirs = []\n\n def __init__(self,\n package_name=None,\n parent_name=None,\n top_path=None,\n package_path=None,\n **attrs):\n \"\"\" Construct configuration instance of a package.\n\n package_name -- name of the package\n Ex.: 'distutils'\n parent_name -- name of the parent package\n Ex.: 'numpy'\n top_path -- directory of the toplevel package\n Ex.: the directory where the numpy package source sits\n package_path -- directory of package. Will be computed by magic from the\n directory of the caller module if not specified\n Ex.: the directory where numpy.distutils is\n \"\"\"\n self.name = dot_join(parent_name, package_name)\n\n caller_frame = get_frame(1)\n caller_name = eval('__name__',caller_frame.f_globals,caller_frame.f_locals)\n\n self.local_path = get_path(caller_name, top_path)\n if top_path is None:\n top_path = self.local_path\n if package_path is None:\n package_path = self.local_path\n elif os.path.isdir(os.path.join(self.local_path,package_path)):\n package_path = os.path.join(self.local_path,package_path)\n if not os.path.isdir(package_path):\n raise ValueError(\"%r is not a directory\" % (package_path,))\n self.top_path = top_path\n self.package_path = package_path\n\n self.list_keys = copy.copy(self._list_keys)\n self.dict_keys = copy.copy(self._dict_keys)\n\n for n in self.list_keys:\n setattr(self,n,copy.copy(attrs.get(n,[])))\n\n for n in self.dict_keys:\n setattr(self,n,copy.copy(attrs.get(n,{})))\n\n known_keys = self.list_keys + self.dict_keys\n self.extra_keys = []\n for n in attrs.keys():\n if n in known_keys:\n continue\n a = attrs[n]\n setattr(self,n,a)\n if isinstance(a, list):\n self.list_keys.append(n)\n elif isinstance(a, dict):\n self.dict_keys.append(n)\n else:\n self.extra_keys.append(n)\n\n if os.path.exists(os.path.join(package_path,'__init__.py')):\n self.packages.append(self.name)\n self.package_dir[self.name] = package_path\n return\n\n def todict(self):\n \"\"\" Return configuration distionary suitable for passing\n to distutils.core.setup() function.\n \"\"\"\n d = {}\n for n in self.list_keys + self.dict_keys + self.extra_keys:\n a = getattr(self,n)\n if a:\n d[n] = a\n if self.name:\n d['name'] = self.name\n return d\n\n def __dict__(self):\n return self.todict()\n\n def get_distribution(self):\n import distutils.core\n dist = distutils.core._setup_distribution\n return dist\n\n def get_subpackage(self,subpackage_name,subpackage_path=None):\n \"\"\" Return subpackage configuration.\n \"\"\"\n if subpackage_name is None:\n assert subpackage_path is not None\n subpackage_name = os.path.basename(subpackage_path)\n l = subpackage_name.split('.')\n if subpackage_path is None:\n subpackage_path = os.path.join(*([self.local_path]+l))\n if '*' in subpackage_name:\n dirs = filter(os.path.isdir,glob.glob(subpackage_path))\n config_list = []\n for d in dirs:\n if not os.path.isfile(os.path.join(d,'__init__.py')):\n continue\n n = '.'.join(d.split(os.sep)[-len(l):])\n c = self.get_subpackage(n)\n if c:\n config_list.append(c)\n return config_list\n else:\n subpackage_path = os.path.join(*([subpackage_path]+l[:-1]))\n subpackage_path = self._fix_paths([subpackage_path])[0]\n\n setup_py = os.path.join(subpackage_path,'setup.py')\n if not os.path.isfile(setup_py):\n setup_py = os.path.join(subpackage_path,'setup_%s.py' % (subpackage_name))\n\n if not os.path.isfile(setup_py):\n print 'Assuming default configuration '\\\n '(%s/{setup_%s,setup}.py was not found)' \\\n % (os.path.dirname(setup_py),subpackage_name)\n config = Configuration(subpackage_name,self.name,\n self.top_path,subpackage_path)\n else:\n # In case setup_py imports local modules:\n sys.path.insert(0,os.path.dirname(setup_py))\n try:\n info = (open(setup_py),setup_py,('.py','U',1))\n setup_name = os.path.splitext(os.path.basename(setup_py))[0]\n n = dot_join(self.name,setup_name)\n setup_module = imp.load_module('_'.join(n.split('.')),*info)\n\n if not hasattr(setup_module,'configuration'):\n print 'Assuming default configuration '\\\n '(%s does not define configuration())' % (setup_module)\n config = Configuration(subpackage_name,self.name,\n self.top_path,subpackage_path)\n else:\n args = (self.name,)\n if setup_module.configuration.func_code.co_argcount>1:\n args = args + (self.top_path,)\n config = setup_module.configuration(*args)\n\n finally:\n del sys.path[0]\n\n return config\n\n def add_subpackage(self,subpackage_name,subpackage_path=None):\n \"\"\" Add subpackage to configuration.\n \"\"\"\n config = self.get_subpackage(subpackage_name,subpackage_path)\n if not isinstance(config, list):\n config_list = [config]\n else:\n config_list = config\n for config in config_list:\n if not config:\n print 'No configuration returned, assuming unavailable.'\n else:\n if isinstance(config,Configuration):\n print 'Appending %s configuration to %s' % (config.name,self.name)\n self.dict_append(**config.todict())\n else:\n print 'Appending %s configuration to %s' % (config.get('name'),self.name)\n self.dict_append(**config)\n\n dist = self.get_distribution()\n if dist is not None:\n print 'distutils distribution has been initialized, it may be too late to add a subpackage', subpackage_name\n return\n\n def add_data_dir(self,data_path):\n \"\"\" Recursively add files under data_path to data_files list.\n Argument can be either\n - 2-sequence (,)\n - path to data directory where python datadir suffix defaults\n to package dir.\n If path is not absolute then it's datadir suffix is\n package dir + subdirname of the path.\n \"\"\"\n if is_sequence(data_path):\n d, data_path = data_path\n else:\n d = None\n if not is_string(data_path):\n raise TypeError(\"not a string: %r\" % (data_path,))\n for path in self.paths(data_path):\n if not os.path.exists(path):\n print 'Not existing data path',path\n continue\n filenames = []\n os.path.walk(path, _gsf_visit_func,filenames)\n if not os.path.isabs(path):\n if d is None:\n ds = os.path.join(*(self.name.split('.')+[data_path]))\n else:\n ds = os.path.join(d,data_path)\n self.add_data_files((ds,filenames))\n else:\n if d is None:\n self.add_data_files(*filenames)\n else:\n self.add_data_files((d,filenames))\n return\n\n def add_data_files(self,*files):\n \"\"\" Add data files to configuration data_files.\n Argument(s) can be either\n - 2-sequence (,)\n - paths to data files where python datadir prefix defaults\n to package dir.\n If path is not absolute then it's datadir prefix is\n package dir + dirname of the path.\n \"\"\"\n data_dict = {}\n new_files = []\n for p in files:\n if not is_sequence(p):\n d = os.path.join(*(self.name.split('.')))\n if is_string(p) and not os.path.isabs(p):\n d = appendpath(d,os.path.dirname(p))\n p = (d,p)\n new_files.append(p)\n files = []\n for prefix,filepattern in new_files:\n if is_string(filepattern):\n file_list = self.paths(filepattern)\n elif callable(filepattern):\n file_list = [filepattern]\n else:\n file_list = self.paths(*filepattern)\n\n nof_path_components = [len(f.split(os.sep))\n for f in file_list if is_string(f)]\n if nof_path_components:\n min_path_components = min(nof_path_components)-1\n else:\n min_path_components = 0\n\n for f in file_list:\n if is_string(f):\n extra_path_components = f.split(os.sep)[min_path_components:-1]\n p = os.path.join(*([prefix]+extra_path_components))\n else:\n p = prefix\n if not data_dict.has_key(p):\n data_dict[p] = [f]\n else:\n data_dict[p].append(f)\n\n dist = self.get_distribution()\n if dist is not None:\n dist.data_files.extend(data_dict.items())\n else:\n self.data_files.extend(data_dict.items())\n\n ### XXX Implement add_py_modules\n \n def add_include_dirs(self,*paths):\n \"\"\" Add paths to configuration include directories.\n \"\"\"\n include_dirs = self._fix_paths(paths)\n dist = self.get_distribution()\n if dist is not None:\n dist.include_dirs.extend(include_dirs)\n else:\n self.include_dirs.extend(include_dirs)\n return\n\n def add_headers(self,*files):\n \"\"\" Add installable headers to configuration.\n Argument(s) can be either\n - 2-sequence (,)\n - path(s) to header file(s) where python includedir suffix will default\n to package name.\n \"\"\"\n headers = []\n for path in files:\n if is_string(path):\n [headers.append((self.name,p)) for p in self.paths(path)]\n else:\n if not isinstance(path, (tuple, list)) or len(path) != 2:\n raise TypeError(repr(path))\n [headers.append((path[0],p)) for p in self.paths(path[1])]\n dist = self.get_distribution()\n if dist is not None:\n dist.headers.extend(headers)\n else:\n self.headers.extend(headers)\n return\n\n def _fix_paths(self,paths):\n new_paths = []\n for n in paths:\n if isinstance(n,str):\n if '*' in n or '?' in n:\n p = glob.glob(n)\n p2 = glob.glob(os.path.join(self.local_path,n))\n if p2:\n new_paths.extend(p2)\n elif p:\n new_paths.extend(p)\n else:\n new_paths.append(n)\n else:\n n2 = os.path.join(self.local_path,n)\n if os.path.exists(n2):\n new_paths.append(n2)\n else:\n new_paths.append(n)\n else:\n new_paths.append(n)\n return new_paths\n\n def paths(self,*paths):\n \"\"\" Apply glob to paths and prepend local_path if needed.\n \"\"\"\n return self._fix_paths(paths)\n\n def add_extension(self,name,sources,**kw):\n \"\"\" Add extension to configuration.\n\n Keywords:\n include_dirs, define_macros, undef_macros,\n library_dirs, libraries, runtime_library_dirs,\n extra_objects, extra_compile_args, extra_link_args,\n export_symbols, swig_opts, depends, language,\n f2py_options, module_dirs\n extra_info - dict or list of dict of keywords to be\n appended to keywords.\n \"\"\"\n ext_args = copy.copy(kw)\n ext_args['name'] = dot_join(self.name,name)\n ext_args['sources'] = sources\n\n if ext_args.has_key('extra_info'):\n extra_info = ext_args['extra_info']\n del ext_args['extra_info']\n if type(extra_info) is type({}):\n extra_info = [extra_info]\n for info in extra_info:\n assert type(info) is type({}),`info`\n dict_append(ext_args,**info)\n\n for k in ext_args.keys():\n v = ext_args[k]\n if k in ['sources','depends','include_dirs','library_dirs',\n 'module_dirs','extra_objects']:\n new_v = self._fix_paths(v)\n ext_args[k] = new_v\n\n # Resolve out-of-tree dependencies\n libraries = ext_args.get('libraries',[])\n libnames = []\n ext_args['libraries'] = []\n for libname in libraries:\n if '@' in libname:\n lname,lpath = libname.split('@',1)\n lpath = os.path.abspath(os.path.join(self.local_path,lpath))\n if os.path.isdir(lpath):\n c = self.get_subpackage(None,lpath)\n if isinstance(c,Configuration):\n c = c.todict()\n for l in [l[0] for l in c.get('libraries',[])]:\n llname = l.split('__OF__',1)[0]\n if llname == lname:\n c.pop('name',None)\n dict_append(ext_args,**c)\n break\n continue\n libnames.append(libname)\n\n ext_args['libraries'] = libnames + ext_args['libraries']\n\n from numpy.distutils.core import Extension\n ext = Extension(**ext_args)\n self.ext_modules.append(ext)\n\n dist = self.get_distribution()\n if dist is not None:\n print 'distutils distribution has been initialized, it may be too late to add an extension', name\n return ext\n\n def add_library(self,name,sources,**build_info):\n \"\"\" Add library to configuration.\n \n Valid keywords for build_info:\n depends\n macros\n include_dirs\n extra_compiler_args\n f2py_options\n \"\"\"\n build_info = copy.copy(build_info)\n name = name #+ '__OF__' + self.name\n build_info['sources'] = sources\n\n for k in build_info.keys():\n v = build_info[k]\n if k in ['sources','depends','include_dirs','library_dirs',\n 'module_dirs','extra_objects']:\n new_v = self._fix_paths(v)\n build_info[k] = new_v\n self.libraries.append((name,build_info))\n\n dist = self.get_distribution()\n if dist is not None:\n print 'distutils distribution has been initialized, it may be too late to add a library', name\n return\n\n def add_scripts(self,*files):\n \"\"\" Add scripts to configuration.\n \"\"\"\n scripts = self._fix_paths(files)\n dist = self.get_distribution()\n if dist is not None:\n dist.scripts.extend(scripts)\n else:\n self.scripts.extend(scripts)\n return\n\n def dict_append(self,**dict):\n for key in self.list_keys:\n a = getattr(self,key)\n a.extend(dict.get(key,[]))\n for key in self.dict_keys:\n a = getattr(self,key)\n a.update(dict.get(key,{}))\n known_keys = self.list_keys + self.dict_keys + self.extra_keys\n for key in dict.keys():\n if key not in known_keys and not hasattr(self,key):\n print 'Inheriting attribute %r from %r' \\\n % (key,dict.get('name','?'))\n setattr(self,key,dict[key])\n self.extra_keys.append(key)\n return\n\n def __str__(self):\n known_keys = self.list_keys + self.dict_keys + self.extra_keys\n s = '<'+5*'-' + '\\n'\n s += 'Configuration of '+self.name+':\\n'\n for k in known_keys:\n a = getattr(self,k,None)\n if a:\n s += '%s = %r\\n' % (k,a)\n s += 5*'-' + '>'\n return s\n\n def get_config_cmd(self):\n cmd = get_cmd('config')\n cmd.ensure_finalized()\n cmd.dump_source = 0\n cmd.noisy = 0\n old_path = os.environ.get('PATH')\n if old_path:\n path = os.pathsep.join(['.',old_path])\n os.environ['PATH'] = path\n return cmd\n\n def get_build_temp_dir(self):\n cmd = get_cmd('build')\n cmd.ensure_finalized()\n return cmd.build_temp\n\n def have_f77c(self):\n \"\"\" Check for availability of Fortran 77 compiler.\n Use it inside source generating function to ensure that\n setup distribution instance has been initialized.\n \"\"\"\n simple_fortran_subroutine = '''\n subroutine simple\n end\n '''\n config_cmd = self.get_config_cmd()\n flag = config_cmd.try_compile(simple_fortran_subroutine,lang='f77')\n return flag\n\n def have_f90c(self):\n \"\"\" Check for availability of Fortran 90 compiler.\n Use it inside source generating function to ensure that\n setup distribution instance has been initialized.\n \"\"\"\n simple_fortran_subroutine = '''\n subroutine simple\n end\n '''\n config_cmd = self.get_config_cmd()\n flag = config_cmd.try_compile(simple_fortran_subroutine,lang='f90')\n return flag\n\n def append_to(self, extlib):\n \"\"\" Append libraries, include_dirs to extension or library item.\n \"\"\"\n if is_sequence(extlib):\n lib_name, build_info = extlib\n dict_append(build_info,\n libraries=self.libraries,\n include_dirs=self.include_dirs)\n else:\n from numpy.distutils.core import Extension\n assert isinstance(extlib,Extension),`extlib`\n extlib.libraries.extend(self.libraries)\n extlib.include_dirs.extend(self.include_dirs)\n return\n\n def _get_svn_revision(self,path):\n \"\"\" Return path's SVN revision number.\n \"\"\"\n entries = os.path.join(path,'.svn','entries')\n revision = None\n if os.path.isfile(entries):\n f = open(entries)\n m = re.search(r'revision=\"(?P\\d+)\"',f.read())\n f.close()\n if m:\n revision = int(m.group('revision'))\n return revision\n\n def get_version(self):\n \"\"\" Try to get version string of a package.\n \"\"\"\n version = getattr(self,'version',None)\n if version is not None:\n return version\n\n # Get version from version file.\n files = ['__version__.py',\n self.name.split('.')[-1]+'_version.py',\n 'version.py',\n '__svn_version__.py']\n version_vars = ['version',\n '__version__',\n self.name.split('.')[-1]+'_version']\n for f in files:\n fn = os.path.join(self.local_path,f)\n if os.path.isfile(fn):\n info = (open(fn),fn,('.py','U',1))\n name = os.path.splitext(os.path.basename(fn))[0]\n n = dot_join(self.name,name)\n try:\n version_module = imp.load_module('_'.join(n.split('.')),*info)\n except ImportError,msg:\n print msg\n version_module = None\n if version_module is None:\n continue\n\n for a in version_vars:\n version = getattr(version_module,a,None)\n if version is not None:\n break\n if version is not None:\n break\n\n if version is not None:\n self.version = version\n return version\n\n # Get version as SVN revision number\n revision = self._get_svn_revision(self.local_path)\n if revision is not None:\n version = str(revision)\n self.version = version\n\n return version\n\n def make_svn_version_py(self):\n \"\"\" Generate package __svn_version__.py file from SVN revision number,\n it will be removed after python exits but will be available\n when sdist, etc commands are executed.\n\n If __svn_version__.py existed before, nothing is done.\n \"\"\"\n target = os.path.join(self.local_path,'__svn_version__.py')\n if os.path.isfile(target):\n return\n\n def generate_svn_version_py():\n if not os.path.isfile(target):\n revision = self._get_svn_revision(self.local_path)\n assert revision is not None,'hmm, why I am not inside SVN tree???'\n version = str(revision)\n print 'Creating %s (version=%r)' % (target,version)\n f = open(target,'w')\n f.write('version = %r\\n' % (version))\n f.close()\n \n import atexit\n def rm_file(f=target):\n try: os.remove(f); print 'removed',f\n except OSError: pass\n try: os.remove(f+'c'); print 'removed',f+'c'\n except OSError: pass\n atexit.register(rm_file)\n\n return target\n\n d = os.path.join(*(self.name.split('.')))\n self.add_data_files((d, generate_svn_version_py()))\n return\n\n def make_config_py(self,name='__config__'):\n \"\"\" Generate package __config__.py file containing system_info\n information used during building the package.\n \"\"\"\n self.py_modules.append((self.name,name,generate_config_py))\n return\n\n def get_info(self,*names):\n \"\"\" Get resources information.\n \"\"\"\n from system_info import get_info, dict_append\n info_dict = {}\n for a in names:\n dict_append(info_dict,**get_info(a))\n return info_dict\n\ndef get_cmd(cmdname,_cache={}):\n if not _cache.has_key(cmdname):\n import distutils.core\n dist = distutils.core._setup_distribution\n if dist is None:\n from distutils.errors import DistutilsInternalError\n raise DistutilsInternalError,\\\n 'setup distribution instance not initialized'\n cmd = dist.get_command_obj(cmdname)\n _cache[cmdname] = cmd\n return _cache[cmdname]\n\ndef get_numpy_include_dirs():\n # numpy_include_dirs are set by numpy/core/setup.py, otherwise []\n include_dirs = Configuration.numpy_include_dirs[:]\n if not include_dirs:\n import numpy\n if numpy.show_config is None:\n # running from numpy_core source directory\n include_dirs.append(os.path.join(os.path.dirname(numpy.__file__),\n 'core','include'))\n else:\n # using installed numpy core headers\n import numpy.core as core\n include_dirs.append(os.path.join(os.path.dirname(core.__file__),'include'))\n # else running numpy/core/setup.py\n return include_dirs\n\n#########################\n\ndef default_config_dict(name = None, parent_name = None, local_path=None):\n \"\"\" Return a configuration dictionary for usage in\n configuration() function defined in file setup_.py.\n \"\"\"\n import warnings\n warnings.warn('Use Configuration(%s,%s,top_path=%s) instead of '\\\n 'deprecated default_config_dict(%s,%s,%s)' \\\n % (`name`,`parent_name`,`local_path`,\n `name`,`parent_name`,`local_path`,\n ))\n c = Configuration(name, parent_name, local_path)\n return c.todict()\n\n\ndef dict_append(d,**kws):\n for k,v in kws.items():\n if d.has_key(k):\n d[k].extend(v)\n else:\n d[k] = v\n\ndef appendpath(prefix,path):\n if not ('/' == os.path.sep):\n prefix = prefix.replace('/',os.path.sep)\n path = path.replace('/',os.path.sep)\n drive = ''\n if os.path.isabs(path):\n drive = os.path.splitdrive(prefix)[0]\n absprefix = os.path.splitdrive(os.path.abspath(prefix))[1]\n pathdrive,path = os.path.splitdrive(path)\n d = os.path.commonprefix([absprefix,path])\n if os.path.join(absprefix[:len(d)],absprefix[len(d):])!=absprefix \\\n or os.path.join(path[:len(d)],path[len(d):])!=path:\n # Handle invalid paths\n d = os.path.dirname(d)\n subpath = path[len(d):]\n if os.path.isabs(subpath):\n subpath = subpath[1:]\n else:\n subpath = path\n return os.path.normpath(os.path.join(drive + prefix, subpath))\n\ndef generate_config_py(target):\n \"\"\" Generate config.py file containing system_info information\n used during building the package.\n\n Usage:\\\n config['py_modules'].append((packagename, '__config__',generate_config_py))\n \"\"\"\n from numpy.distutils.system_info import system_info\n from distutils.dir_util import mkpath\n mkpath(os.path.dirname(target))\n f = open(target,'w')\n f.write('# This file is generated by %s\\n' % (os.path.abspath(sys.argv[0])))\n f.write('# It contains system_info results at the time of building this package.\\n')\n f.write('__all__ = [\"get_info\",\"show\"]\\n\\n')\n for k,i in system_info.saved_results.items():\n f.write('%s=%r\\n' % (k,i))\n f.write('\\ndef get_info(name): g=globals(); return g.get(name,g.get(name+\"_info\",{}))\\n')\n f.write('''\ndef show():\n for name,info_dict in globals().items():\n if name[0]==\"_\" or type(info_dict) is not type({}): continue\n print name+\":\"\n if not info_dict:\n print \" NOT AVAILABLE\"\n for k,v in info_dict.items():\n v = str(v)\n if k==\\'sources\\' and len(v)>200: v = v[:60]+\\' ...\\\\n... \\'+v[-60:]\n print \\' %s = %s\\'%(k,v)\n print\n return\n ''')\n\n f.close()\n return target\n\ndef generate_svn_version_py(extension, build_dir):\n \"\"\" Generate __svn_version__.py file containing SVN\n revision number of a module.\n \n To use, add the following codelet to setup\n configuration(..) function\n\n ext = Extension(dot_join(config['name'],'__svn_version__'),\n sources=[generate_svn_version_py])\n ext.local_path = local_path\n config['ext_modules'].append(ext)\n\n \"\"\"\n from distutils import dep_util\n local_path = extension.local_path\n target = os.path.join(build_dir, '__svn_version__.py')\n entries = os.path.join(local_path,'.svn','entries')\n if os.path.isfile(entries):\n if not dep_util.newer(entries, target):\n return target\n elif os.path.isfile(target):\n return target\n\n revision = get_svn_revision(local_path)\n f = open(target,'w')\n f.write('revision=%s\\n' % (revision))\n f.close()\n return target\n", + "methods": [ + { + "name": "allpath", + "long_name": "allpath( name )", + "filename": "misc_util.py", + "nloc": 4, + "complexity": 1, + "token_count": 24, + "parameters": [ + "name" + ], + "start_line": 18, + "end_line": 21, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 4, + "top_nesting_level": 0 + }, + { + "name": "get_path", + "long_name": "get_path( mod_name , parent_path = None )", + "filename": "misc_util.py", + "nloc": 15, + "complexity": 6, + "token_count": 132, + "parameters": [ + "mod_name", + "parent_path" + ], + "start_line": 23, + "end_line": 43, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 21, + "top_nesting_level": 0 + }, + { + "name": "terminal_has_colors", + "long_name": "terminal_has_colors( )", + "filename": "misc_util.py", + "nloc": 18, + "complexity": 13, + "token_count": 137, + "parameters": [], + "start_line": 47, + "end_line": 72, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 26, + "top_nesting_level": 0 + }, + { + "name": "cyg2win32", + "long_name": "cyg2win32( path )", + "filename": "misc_util.py", + "nloc": 4, + "complexity": 3, + "token_count": 42, + "parameters": [ + "path" + ], + "start_line": 89, + "end_line": 92, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 4, + "top_nesting_level": 0 + }, + { + "name": "_get_f90_modules", + "long_name": "_get_f90_modules( source )", + "filename": "misc_util.py", + "nloc": 13, + "complexity": 4, + "token_count": 77, + "parameters": [ + "source" + ], + "start_line": 101, + "end_line": 117, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 17, + "top_nesting_level": 0 + }, + { + "name": "is_string", + "long_name": "is_string( s )", + "filename": "misc_util.py", + "nloc": 2, + "complexity": 1, + "token_count": 12, + "parameters": [ + "s" + ], + "start_line": 119, + "end_line": 120, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 2, + "top_nesting_level": 0 + }, + { + "name": "all_strings", + "long_name": "all_strings( lst )", + "filename": "misc_util.py", + "nloc": 5, + "complexity": 3, + "token_count": 22, + "parameters": [ + "lst" + ], + "start_line": 122, + "end_line": 127, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 6, + "top_nesting_level": 0 + }, + { + "name": "is_sequence", + "long_name": "is_sequence( seq )", + "filename": "misc_util.py", + "nloc": 8, + "complexity": 3, + "token_count": 25, + "parameters": [ + "seq" + ], + "start_line": 129, + "end_line": 136, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 8, + "top_nesting_level": 0 + }, + { + "name": "has_f_sources", + "long_name": "has_f_sources( sources )", + "filename": "misc_util.py", + "nloc": 5, + "complexity": 3, + "token_count": 21, + "parameters": [ + "sources" + ], + "start_line": 138, + "end_line": 143, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 6, + "top_nesting_level": 0 + }, + { + "name": "has_cxx_sources", + "long_name": "has_cxx_sources( sources )", + "filename": "misc_util.py", + "nloc": 5, + "complexity": 3, + "token_count": 21, + "parameters": [ + "sources" + ], + "start_line": 145, + "end_line": 150, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 6, + "top_nesting_level": 0 + }, + { + "name": "filter_sources", + "long_name": "filter_sources( sources )", + "filename": "misc_util.py", + "nloc": 17, + "complexity": 5, + "token_count": 84, + "parameters": [ + "sources" + ], + "start_line": 152, + "end_line": 172, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 21, + "top_nesting_level": 0 + }, + { + "name": "_get_headers", + "long_name": "_get_headers( directory_list )", + "filename": "misc_util.py", + "nloc": 6, + "complexity": 2, + "token_count": 39, + "parameters": [ + "directory_list" + ], + "start_line": 175, + "end_line": 181, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 7, + "top_nesting_level": 0 + }, + { + "name": "_get_directories", + "long_name": "_get_directories( list_of_sources )", + "filename": "misc_util.py", + "nloc": 7, + "complexity": 4, + "token_count": 51, + "parameters": [ + "list_of_sources" + ], + "start_line": 183, + "end_line": 190, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 8, + "top_nesting_level": 0 + }, + { + "name": "get_dependencies", + "long_name": "get_dependencies( sources )", + "filename": "misc_util.py", + "nloc": 2, + "complexity": 1, + "token_count": 13, + "parameters": [ + "sources" + ], + "start_line": 192, + "end_line": 194, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 3, + "top_nesting_level": 0 + }, + { + "name": "is_local_src_dir", + "long_name": "is_local_src_dir( directory )", + "filename": "misc_util.py", + "nloc": 12, + "complexity": 6, + "token_count": 107, + "parameters": [ + "directory" + ], + "start_line": 196, + "end_line": 209, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 14, + "top_nesting_level": 0 + }, + { + "name": "_gsf_visit_func", + "long_name": "_gsf_visit_func( filenames , dirname , names )", + "filename": "misc_util.py", + "nloc": 13, + "complexity": 7, + "token_count": 103, + "parameters": [ + "filenames", + "dirname", + "names" + ], + "start_line": 211, + "end_line": 223, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 13, + "top_nesting_level": 0 + }, + { + "name": "get_ext_source_files", + "long_name": "get_ext_source_files( ext )", + "filename": "misc_util.py", + "nloc": 11, + "complexity": 4, + "token_count": 77, + "parameters": [ + "ext" + ], + "start_line": 225, + "end_line": 236, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 12, + "top_nesting_level": 0 + }, + { + "name": "get_script_files", + "long_name": "get_script_files( scripts )", + "filename": "misc_util.py", + "nloc": 3, + "complexity": 1, + "token_count": 15, + "parameters": [ + "scripts" + ], + "start_line": 238, + "end_line": 240, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 3, + "top_nesting_level": 0 + }, + { + "name": "get_lib_source_files", + "long_name": "get_lib_source_files( lib )", + "filename": "misc_util.py", + "nloc": 13, + "complexity": 4, + "token_count": 101, + "parameters": [ + "lib" + ], + "start_line": 242, + "end_line": 254, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 13, + "top_nesting_level": 0 + }, + { + "name": "get_data_files", + "long_name": "get_data_files( data )", + "filename": "misc_util.py", + "nloc": 18, + "complexity": 7, + "token_count": 94, + "parameters": [ + "data" + ], + "start_line": 256, + "end_line": 273, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 18, + "top_nesting_level": 0 + }, + { + "name": "dot_join", + "long_name": "dot_join( * args )", + "filename": "misc_util.py", + "nloc": 2, + "complexity": 1, + "token_count": 18, + "parameters": [ + "args" + ], + "start_line": 275, + "end_line": 276, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 2, + "top_nesting_level": 0 + }, + { + "name": "get_frame", + "long_name": "get_frame( level = 0 )", + "filename": "misc_util.py", + "nloc": 8, + "complexity": 3, + "token_count": 50, + "parameters": [ + "level" + ], + "start_line": 278, + "end_line": 285, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 8, + "top_nesting_level": 0 + }, + { + "name": "__init__", + "long_name": "__init__( self , package_name = None , parent_name = None , top_path = None , package_path = None , ** attrs )", + "filename": "misc_util.py", + "nloc": 44, + "complexity": 12, + "token_count": 377, + "parameters": [ + "self", + "package_name", + "parent_name", + "top_path", + "package_path", + "attrs" + ], + "start_line": 297, + "end_line": 360, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 64, + "top_nesting_level": 1 + }, + { + "name": "todict", + "long_name": "todict( self )", + "filename": "misc_util.py", + "nloc": 9, + "complexity": 4, + "token_count": 57, + "parameters": [ + "self" + ], + "start_line": 362, + "end_line": 373, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 12, + "top_nesting_level": 1 + }, + { + "name": "__dict__", + "long_name": "__dict__( self )", + "filename": "misc_util.py", + "nloc": 2, + "complexity": 1, + "token_count": 11, + "parameters": [ + "self" + ], + "start_line": 375, + "end_line": 376, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 2, + "top_nesting_level": 1 + }, + { + "name": "get_distribution", + "long_name": "get_distribution( self )", + "filename": "misc_util.py", + "nloc": 4, + "complexity": 1, + "token_count": 18, + "parameters": [ + "self" + ], + "start_line": 378, + "end_line": 381, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 4, + "top_nesting_level": 1 + }, + { + "name": "get_subpackage", + "long_name": "get_subpackage( self , subpackage_name , subpackage_path = None )", + "filename": "misc_util.py", + "nloc": 50, + "complexity": 12, + "token_count": 453, + "parameters": [ + "self", + "subpackage_name", + "subpackage_path" + ], + "start_line": 383, + "end_line": 440, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 58, + "top_nesting_level": 1 + }, + { + "name": "add_subpackage", + "long_name": "add_subpackage( self , subpackage_name , subpackage_path = None )", + "filename": "misc_util.py", + "nloc": 20, + "complexity": 6, + "token_count": 127, + "parameters": [ + "self", + "subpackage_name", + "subpackage_path" + ], + "start_line": 442, + "end_line": 464, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 23, + "top_nesting_level": 1 + }, + { + "name": "add_data_dir", + "long_name": "add_data_dir( self , data_path )", + "filename": "misc_util.py", + "nloc": 24, + "complexity": 8, + "token_count": 153, + "parameters": [ + "self", + "data_path" + ], + "start_line": 466, + "end_line": 497, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 32, + "top_nesting_level": 1 + }, + { + "name": "add_data_files", + "long_name": "add_data_files( self , * files )", + "filename": "misc_util.py", + "nloc": 39, + "complexity": 15, + "token_count": 281, + "parameters": [ + "self", + "files" + ], + "start_line": 499, + "end_line": 548, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 50, + "top_nesting_level": 1 + }, + { + "name": "add_include_dirs", + "long_name": "add_include_dirs( self , * paths )", + "filename": "misc_util.py", + "nloc": 8, + "complexity": 2, + "token_count": 49, + "parameters": [ + "self", + "paths" + ], + "start_line": 552, + "end_line": 561, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 10, + "top_nesting_level": 1 + }, + { + "name": "add_headers", + "long_name": "add_headers( self , * files )", + "filename": "misc_util.py", + "nloc": 15, + "complexity": 8, + "token_count": 136, + "parameters": [ + "self", + "files" + ], + "start_line": 563, + "end_line": 583, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 21, + "top_nesting_level": 1 + }, + { + "name": "_fix_paths", + "long_name": "_fix_paths( self , paths )", + "filename": "misc_util.py", + "nloc": 22, + "complexity": 8, + "token_count": 136, + "parameters": [ + "self", + "paths" + ], + "start_line": 585, + "end_line": 606, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 22, + "top_nesting_level": 1 + }, + { + "name": "paths", + "long_name": "paths( self , * paths )", + "filename": "misc_util.py", + "nloc": 2, + "complexity": 1, + "token_count": 16, + "parameters": [ + "self", + "paths" + ], + "start_line": 608, + "end_line": 611, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 4, + "top_nesting_level": 1 + }, + { + "name": "add_extension", + "long_name": "add_extension( self , name , sources , ** kw )", + "filename": "misc_util.py", + "nloc": 45, + "complexity": 14, + "token_count": 365, + "parameters": [ + "self", + "name", + "sources", + "kw" + ], + "start_line": 613, + "end_line": 675, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 63, + "top_nesting_level": 1 + }, + { + "name": "add_library", + "long_name": "add_library( self , name , sources , ** build_info )", + "filename": "misc_util.py", + "nloc": 15, + "complexity": 4, + "token_count": 106, + "parameters": [ + "self", + "name", + "sources", + "build_info" + ], + "start_line": 677, + "end_line": 702, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 26, + "top_nesting_level": 1 + }, + { + "name": "add_scripts", + "long_name": "add_scripts( self , * files )", + "filename": "misc_util.py", + "nloc": 8, + "complexity": 2, + "token_count": 49, + "parameters": [ + "self", + "files" + ], + "start_line": 704, + "end_line": 713, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 10, + "top_nesting_level": 1 + }, + { + "name": "dict_append", + "long_name": "dict_append( self , ** dict )", + "filename": "misc_util.py", + "nloc": 15, + "complexity": 6, + "token_count": 138, + "parameters": [ + "self", + "dict" + ], + "start_line": 715, + "end_line": 729, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 15, + "top_nesting_level": 1 + }, + { + "name": "__str__", + "long_name": "__str__( self )", + "filename": "misc_util.py", + "nloc": 10, + "complexity": 3, + "token_count": 72, + "parameters": [ + "self" + ], + "start_line": 731, + "end_line": 740, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 10, + "top_nesting_level": 1 + }, + { + "name": "get_config_cmd", + "long_name": "get_config_cmd( self )", + "filename": "misc_util.py", + "nloc": 10, + "complexity": 2, + "token_count": 63, + "parameters": [ + "self" + ], + "start_line": 742, + "end_line": 751, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 10, + "top_nesting_level": 1 + }, + { + "name": "get_build_temp_dir", + "long_name": "get_build_temp_dir( self )", + "filename": "misc_util.py", + "nloc": 4, + "complexity": 1, + "token_count": 20, + "parameters": [ + "self" + ], + "start_line": 753, + "end_line": 756, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 4, + "top_nesting_level": 1 + }, + { + "name": "have_f77c", + "long_name": "have_f77c( self )", + "filename": "misc_util.py", + "nloc": 8, + "complexity": 1, + "token_count": 30, + "parameters": [ + "self" + ], + "start_line": 758, + "end_line": 769, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 12, + "top_nesting_level": 1 + }, + { + "name": "have_f90c", + "long_name": "have_f90c( self )", + "filename": "misc_util.py", + "nloc": 8, + "complexity": 1, + "token_count": 30, + "parameters": [ + "self" + ], + "start_line": 771, + "end_line": 782, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 12, + "top_nesting_level": 1 + }, + { + "name": "append_to", + "long_name": "append_to( self , extlib )", + "filename": "misc_util.py", + "nloc": 12, + "complexity": 2, + "token_count": 77, + "parameters": [ + "self", + "extlib" + ], + "start_line": 784, + "end_line": 797, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 14, + "top_nesting_level": 1 + }, + { + "name": "_get_svn_revision", + "long_name": "_get_svn_revision( self , path )", + "filename": "misc_util.py", + "nloc": 10, + "complexity": 3, + "token_count": 77, + "parameters": [ + "self", + "path" + ], + "start_line": 799, + "end_line": 810, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 12, + "top_nesting_level": 1 + }, + { + "name": "get_version", + "long_name": "get_version( self )", + "filename": "misc_util.py", + "nloc": 38, + "complexity": 11, + "token_count": 257, + "parameters": [ + "self" + ], + "start_line": 812, + "end_line": 858, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 47, + "top_nesting_level": 1 + }, + { + "name": "make_svn_version_py.make_svn_version_py.generate_svn_version_py.rm_file", + "long_name": "make_svn_version_py.make_svn_version_py.generate_svn_version_py.rm_file( f = target )", + "filename": "misc_util.py", + "nloc": 5, + "complexity": 3, + "token_count": 45, + "parameters": [ + "f" + ], + "start_line": 882, + "end_line": 886, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 5, + "top_nesting_level": 3 + }, + { + "name": "make_svn_version_py.generate_svn_version_py", + "long_name": "make_svn_version_py.generate_svn_version_py( )", + "filename": "misc_util.py", + "nloc": 13, + "complexity": 2, + "token_count": 81, + "parameters": [], + "start_line": 871, + "end_line": 889, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 19, + "top_nesting_level": 2 + }, + { + "name": "make_svn_version_py", + "long_name": "make_svn_version_py( self )", + "filename": "misc_util.py", + "nloc": 7, + "complexity": 2, + "token_count": 42, + "parameters": [ + "self" + ], + "start_line": 860, + "end_line": 892, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 33, + "top_nesting_level": 1 + }, + { + "name": "make_config_py", + "long_name": "make_config_py( self , name = '__config__' )", + "filename": "misc_util.py", + "nloc": 3, + "complexity": 1, + "token_count": 27, + "parameters": [ + "self", + "name" + ], + "start_line": 894, + "end_line": 899, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 6, + "top_nesting_level": 1 + }, + { + "name": "get_info", + "long_name": "get_info( self , * names )", + "filename": "misc_util.py", + "nloc": 6, + "complexity": 2, + "token_count": 36, + "parameters": [ + "self", + "names" + ], + "start_line": 901, + "end_line": 908, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 8, + "top_nesting_level": 1 + }, + { + "name": "get_cmd", + "long_name": "get_cmd( cmdname , _cache = { } )", + "filename": "misc_util.py", + "nloc": 11, + "complexity": 3, + "token_count": 65, + "parameters": [ + "cmdname", + "_cache" + ], + "start_line": 910, + "end_line": 920, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 11, + "top_nesting_level": 0 + }, + { + "name": "get_numpy_include_dirs", + "long_name": "get_numpy_include_dirs( )", + "filename": "misc_util.py", + "nloc": 11, + "complexity": 3, + "token_count": 85, + "parameters": [], + "start_line": 922, + "end_line": 936, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 15, + "top_nesting_level": 0 + }, + { + "name": "default_config_dict", + "long_name": "default_config_dict( name = None , parent_name = None , local_path = None )", + "filename": "misc_util.py", + "nloc": 9, + "complexity": 1, + "token_count": 70, + "parameters": [ + "name", + "parent_name", + "local_path" + ], + "start_line": 940, + "end_line": 951, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 12, + "top_nesting_level": 0 + }, + { + "name": "dict_append", + "long_name": "dict_append( d , ** kws )", + "filename": "misc_util.py", + "nloc": 6, + "complexity": 3, + "token_count": 44, + "parameters": [ + "d", + "kws" + ], + "start_line": 954, + "end_line": 959, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 6, + "top_nesting_level": 0 + }, + { + "name": "appendpath", + "long_name": "appendpath( prefix , path )", + "filename": "misc_util.py", + "nloc": 19, + "complexity": 6, + "token_count": 237, + "parameters": [ + "prefix", + "path" + ], + "start_line": 961, + "end_line": 980, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 20, + "top_nesting_level": 0 + }, + { + "name": "generate_config_py", + "long_name": "generate_config_py( target )", + "filename": "misc_util.py", + "nloc": 27, + "complexity": 2, + "token_count": 117, + "parameters": [ + "target" + ], + "start_line": 982, + "end_line": 1015, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 34, + "top_nesting_level": 0 + }, + { + "name": "generate_svn_version_py", + "long_name": "generate_svn_version_py( extension , build_dir )", + "filename": "misc_util.py", + "nloc": 15, + "complexity": 4, + "token_count": 109, + "parameters": [ + "extension", + "build_dir" + ], + "start_line": 1017, + "end_line": 1044, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 28, + "top_nesting_level": 0 + } + ], + "methods_before": [ + { + "name": "allpath", + "long_name": "allpath( name )", + "filename": "misc_util.py", + "nloc": 4, + "complexity": 1, + "token_count": 24, + "parameters": [ + "name" + ], + "start_line": 18, + "end_line": 21, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 4, + "top_nesting_level": 0 + }, + { + "name": "get_path", + "long_name": "get_path( mod_name , parent_path = None )", + "filename": "misc_util.py", + "nloc": 15, + "complexity": 6, + "token_count": 132, + "parameters": [ + "mod_name", + "parent_path" + ], + "start_line": 23, + "end_line": 43, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 21, + "top_nesting_level": 0 + }, + { + "name": "terminal_has_colors", + "long_name": "terminal_has_colors( )", + "filename": "misc_util.py", + "nloc": 18, + "complexity": 13, + "token_count": 137, + "parameters": [], + "start_line": 47, + "end_line": 72, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 26, + "top_nesting_level": 0 + }, + { + "name": "cyg2win32", + "long_name": "cyg2win32( path )", + "filename": "misc_util.py", + "nloc": 4, + "complexity": 3, + "token_count": 42, + "parameters": [ + "path" + ], + "start_line": 89, + "end_line": 92, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 4, + "top_nesting_level": 0 + }, + { + "name": "_get_f90_modules", + "long_name": "_get_f90_modules( source )", + "filename": "misc_util.py", + "nloc": 13, + "complexity": 4, + "token_count": 77, + "parameters": [ + "source" + ], + "start_line": 101, + "end_line": 117, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 17, + "top_nesting_level": 0 + }, + { + "name": "is_string", + "long_name": "is_string( s )", + "filename": "misc_util.py", + "nloc": 2, + "complexity": 1, + "token_count": 12, + "parameters": [ + "s" + ], + "start_line": 119, + "end_line": 120, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 2, + "top_nesting_level": 0 + }, + { + "name": "all_strings", + "long_name": "all_strings( lst )", + "filename": "misc_util.py", + "nloc": 5, + "complexity": 3, + "token_count": 22, + "parameters": [ + "lst" + ], + "start_line": 122, + "end_line": 127, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 6, + "top_nesting_level": 0 + }, + { + "name": "is_sequence", + "long_name": "is_sequence( seq )", + "filename": "misc_util.py", + "nloc": 8, + "complexity": 3, + "token_count": 25, + "parameters": [ + "seq" + ], + "start_line": 129, + "end_line": 136, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 8, + "top_nesting_level": 0 + }, + { + "name": "has_f_sources", + "long_name": "has_f_sources( sources )", + "filename": "misc_util.py", + "nloc": 5, + "complexity": 3, + "token_count": 21, + "parameters": [ + "sources" + ], + "start_line": 138, + "end_line": 143, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 6, + "top_nesting_level": 0 + }, + { + "name": "has_cxx_sources", + "long_name": "has_cxx_sources( sources )", + "filename": "misc_util.py", + "nloc": 5, + "complexity": 3, + "token_count": 21, + "parameters": [ + "sources" + ], + "start_line": 145, + "end_line": 150, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 6, + "top_nesting_level": 0 + }, + { + "name": "filter_sources", + "long_name": "filter_sources( sources )", + "filename": "misc_util.py", + "nloc": 17, + "complexity": 5, + "token_count": 84, + "parameters": [ + "sources" + ], + "start_line": 152, + "end_line": 172, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 21, + "top_nesting_level": 0 + }, + { + "name": "_get_headers", + "long_name": "_get_headers( directory_list )", + "filename": "misc_util.py", + "nloc": 6, + "complexity": 2, + "token_count": 39, + "parameters": [ + "directory_list" + ], + "start_line": 175, + "end_line": 181, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 7, + "top_nesting_level": 0 + }, + { + "name": "_get_directories", + "long_name": "_get_directories( list_of_sources )", + "filename": "misc_util.py", + "nloc": 7, + "complexity": 4, + "token_count": 51, + "parameters": [ + "list_of_sources" + ], + "start_line": 183, + "end_line": 190, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 8, + "top_nesting_level": 0 + }, + { + "name": "get_dependencies", + "long_name": "get_dependencies( sources )", + "filename": "misc_util.py", + "nloc": 2, + "complexity": 1, + "token_count": 13, + "parameters": [ + "sources" + ], + "start_line": 192, + "end_line": 194, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 3, + "top_nesting_level": 0 + }, + { + "name": "is_local_src_dir", + "long_name": "is_local_src_dir( directory )", + "filename": "misc_util.py", + "nloc": 12, + "complexity": 6, + "token_count": 107, + "parameters": [ + "directory" + ], + "start_line": 196, + "end_line": 209, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 14, + "top_nesting_level": 0 + }, + { + "name": "_gsf_visit_func", + "long_name": "_gsf_visit_func( filenames , dirname , names )", + "filename": "misc_util.py", + "nloc": 13, + "complexity": 7, + "token_count": 103, + "parameters": [ + "filenames", + "dirname", + "names" + ], + "start_line": 211, + "end_line": 223, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 13, + "top_nesting_level": 0 + }, + { + "name": "get_ext_source_files", + "long_name": "get_ext_source_files( ext )", + "filename": "misc_util.py", + "nloc": 11, + "complexity": 4, + "token_count": 77, + "parameters": [ + "ext" + ], + "start_line": 225, + "end_line": 236, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 12, + "top_nesting_level": 0 + }, + { + "name": "get_script_files", + "long_name": "get_script_files( scripts )", + "filename": "misc_util.py", + "nloc": 3, + "complexity": 1, + "token_count": 15, + "parameters": [ + "scripts" + ], + "start_line": 238, + "end_line": 240, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 3, + "top_nesting_level": 0 + }, + { + "name": "get_lib_source_files", + "long_name": "get_lib_source_files( lib )", + "filename": "misc_util.py", + "nloc": 13, + "complexity": 4, + "token_count": 101, + "parameters": [ + "lib" + ], + "start_line": 242, + "end_line": 254, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 13, + "top_nesting_level": 0 + }, + { + "name": "get_data_files", + "long_name": "get_data_files( data )", + "filename": "misc_util.py", + "nloc": 18, + "complexity": 7, + "token_count": 94, + "parameters": [ + "data" + ], + "start_line": 256, + "end_line": 273, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 18, + "top_nesting_level": 0 + }, + { + "name": "dot_join", + "long_name": "dot_join( * args )", + "filename": "misc_util.py", + "nloc": 2, + "complexity": 1, + "token_count": 18, + "parameters": [ + "args" + ], + "start_line": 275, + "end_line": 276, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 2, + "top_nesting_level": 0 + }, + { + "name": "get_frame", + "long_name": "get_frame( level = 0 )", + "filename": "misc_util.py", + "nloc": 8, + "complexity": 3, + "token_count": 50, + "parameters": [ + "level" + ], + "start_line": 278, + "end_line": 285, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 8, + "top_nesting_level": 0 + }, + { + "name": "__init__", + "long_name": "__init__( self , package_name = None , parent_name = None , top_path = None , package_path = None , ** attrs )", + "filename": "misc_util.py", + "nloc": 43, + "complexity": 12, + "token_count": 357, + "parameters": [ + "self", + "package_name", + "parent_name", + "top_path", + "package_path", + "attrs" + ], + "start_line": 297, + "end_line": 358, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 62, + "top_nesting_level": 1 + }, + { + "name": "todict", + "long_name": "todict( self )", + "filename": "misc_util.py", + "nloc": 9, + "complexity": 4, + "token_count": 57, + "parameters": [ + "self" + ], + "start_line": 360, + "end_line": 371, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 12, + "top_nesting_level": 1 + }, + { + "name": "__dict__", + "long_name": "__dict__( self )", + "filename": "misc_util.py", + "nloc": 2, + "complexity": 1, + "token_count": 11, + "parameters": [ + "self" + ], + "start_line": 373, + "end_line": 374, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 2, + "top_nesting_level": 1 + }, + { + "name": "get_distribution", + "long_name": "get_distribution( self )", + "filename": "misc_util.py", + "nloc": 4, + "complexity": 1, + "token_count": 18, + "parameters": [ + "self" + ], + "start_line": 376, + "end_line": 379, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 4, + "top_nesting_level": 1 + }, + { + "name": "get_subpackage", + "long_name": "get_subpackage( self , subpackage_name , subpackage_path = None )", + "filename": "misc_util.py", + "nloc": 50, + "complexity": 12, + "token_count": 453, + "parameters": [ + "self", + "subpackage_name", + "subpackage_path" + ], + "start_line": 381, + "end_line": 438, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 58, + "top_nesting_level": 1 + }, + { + "name": "add_subpackage", + "long_name": "add_subpackage( self , subpackage_name , subpackage_path = None )", + "filename": "misc_util.py", + "nloc": 20, + "complexity": 6, + "token_count": 127, + "parameters": [ + "self", + "subpackage_name", + "subpackage_path" + ], + "start_line": 440, + "end_line": 462, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 23, + "top_nesting_level": 1 + }, + { + "name": "add_data_dir", + "long_name": "add_data_dir( self , data_path )", + "filename": "misc_util.py", + "nloc": 25, + "complexity": 8, + "token_count": 174, + "parameters": [ + "self", + "data_path" + ], + "start_line": 464, + "end_line": 496, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 33, + "top_nesting_level": 1 + }, + { + "name": "add_data_files", + "long_name": "add_data_files( self , * files )", + "filename": "misc_util.py", + "nloc": 39, + "complexity": 15, + "token_count": 296, + "parameters": [ + "self", + "files" + ], + "start_line": 498, + "end_line": 547, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 50, + "top_nesting_level": 1 + }, + { + "name": "add_include_dirs", + "long_name": "add_include_dirs( self , * paths )", + "filename": "misc_util.py", + "nloc": 8, + "complexity": 2, + "token_count": 49, + "parameters": [ + "self", + "paths" + ], + "start_line": 551, + "end_line": 560, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 10, + "top_nesting_level": 1 + }, + { + "name": "add_headers", + "long_name": "add_headers( self , * files )", + "filename": "misc_util.py", + "nloc": 15, + "complexity": 8, + "token_count": 136, + "parameters": [ + "self", + "files" + ], + "start_line": 562, + "end_line": 582, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 21, + "top_nesting_level": 1 + }, + { + "name": "_fix_paths", + "long_name": "_fix_paths( self , paths )", + "filename": "misc_util.py", + "nloc": 22, + "complexity": 8, + "token_count": 136, + "parameters": [ + "self", + "paths" + ], + "start_line": 584, + "end_line": 605, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 22, + "top_nesting_level": 1 + }, + { + "name": "paths", + "long_name": "paths( self , * paths )", + "filename": "misc_util.py", + "nloc": 2, + "complexity": 1, + "token_count": 16, + "parameters": [ + "self", + "paths" + ], + "start_line": 607, + "end_line": 610, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 4, + "top_nesting_level": 1 + }, + { + "name": "add_extension", + "long_name": "add_extension( self , name , sources , ** kw )", + "filename": "misc_util.py", + "nloc": 45, + "complexity": 14, + "token_count": 365, + "parameters": [ + "self", + "name", + "sources", + "kw" + ], + "start_line": 612, + "end_line": 674, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 63, + "top_nesting_level": 1 + }, + { + "name": "add_library", + "long_name": "add_library( self , name , sources , ** build_info )", + "filename": "misc_util.py", + "nloc": 15, + "complexity": 4, + "token_count": 106, + "parameters": [ + "self", + "name", + "sources", + "build_info" + ], + "start_line": 676, + "end_line": 701, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 26, + "top_nesting_level": 1 + }, + { + "name": "add_scripts", + "long_name": "add_scripts( self , * files )", + "filename": "misc_util.py", + "nloc": 8, + "complexity": 2, + "token_count": 49, + "parameters": [ + "self", + "files" + ], + "start_line": 703, + "end_line": 712, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 10, + "top_nesting_level": 1 + }, + { + "name": "dict_append", + "long_name": "dict_append( self , ** dict )", + "filename": "misc_util.py", + "nloc": 15, + "complexity": 6, + "token_count": 138, + "parameters": [ + "self", + "dict" + ], + "start_line": 714, + "end_line": 728, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 15, + "top_nesting_level": 1 + }, + { + "name": "__str__", + "long_name": "__str__( self )", + "filename": "misc_util.py", + "nloc": 10, + "complexity": 3, + "token_count": 72, + "parameters": [ + "self" + ], + "start_line": 730, + "end_line": 739, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 10, + "top_nesting_level": 1 + }, + { + "name": "get_config_cmd", + "long_name": "get_config_cmd( self )", + "filename": "misc_util.py", + "nloc": 10, + "complexity": 2, + "token_count": 63, + "parameters": [ + "self" + ], + "start_line": 741, + "end_line": 750, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 10, + "top_nesting_level": 1 + }, + { + "name": "get_build_temp_dir", + "long_name": "get_build_temp_dir( self )", + "filename": "misc_util.py", + "nloc": 4, + "complexity": 1, + "token_count": 20, + "parameters": [ + "self" + ], + "start_line": 752, + "end_line": 755, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 4, + "top_nesting_level": 1 + }, + { + "name": "have_f77c", + "long_name": "have_f77c( self )", + "filename": "misc_util.py", + "nloc": 8, + "complexity": 1, + "token_count": 30, + "parameters": [ + "self" + ], + "start_line": 757, + "end_line": 768, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 12, + "top_nesting_level": 1 + }, + { + "name": "have_f90c", + "long_name": "have_f90c( self )", + "filename": "misc_util.py", + "nloc": 8, + "complexity": 1, + "token_count": 30, + "parameters": [ + "self" + ], + "start_line": 770, + "end_line": 781, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 12, + "top_nesting_level": 1 + }, + { + "name": "append_to", + "long_name": "append_to( self , extlib )", + "filename": "misc_util.py", + "nloc": 12, + "complexity": 2, + "token_count": 77, + "parameters": [ + "self", + "extlib" + ], + "start_line": 783, + "end_line": 796, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 14, + "top_nesting_level": 1 + }, + { + "name": "_get_svn_revision", + "long_name": "_get_svn_revision( self , path )", + "filename": "misc_util.py", + "nloc": 10, + "complexity": 3, + "token_count": 77, + "parameters": [ + "self", + "path" + ], + "start_line": 798, + "end_line": 809, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 12, + "top_nesting_level": 1 + }, + { + "name": "get_version", + "long_name": "get_version( self )", + "filename": "misc_util.py", + "nloc": 38, + "complexity": 11, + "token_count": 257, + "parameters": [ + "self" + ], + "start_line": 811, + "end_line": 857, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 47, + "top_nesting_level": 1 + }, + { + "name": "make_svn_version_py.make_svn_version_py.generate_svn_version_py.rm_file", + "long_name": "make_svn_version_py.make_svn_version_py.generate_svn_version_py.rm_file( f = target )", + "filename": "misc_util.py", + "nloc": 5, + "complexity": 3, + "token_count": 45, + "parameters": [ + "f" + ], + "start_line": 881, + "end_line": 885, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 5, + "top_nesting_level": 3 + }, + { + "name": "make_svn_version_py.generate_svn_version_py", + "long_name": "make_svn_version_py.generate_svn_version_py( )", + "filename": "misc_util.py", + "nloc": 13, + "complexity": 2, + "token_count": 81, + "parameters": [], + "start_line": 870, + "end_line": 888, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 19, + "top_nesting_level": 2 + }, + { + "name": "make_svn_version_py", + "long_name": "make_svn_version_py( self )", + "filename": "misc_util.py", + "nloc": 8, + "complexity": 2, + "token_count": 66, + "parameters": [ + "self" + ], + "start_line": 859, + "end_line": 892, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 34, + "top_nesting_level": 1 + }, + { + "name": "make_config_py", + "long_name": "make_config_py( self , name = '__config__' )", + "filename": "misc_util.py", + "nloc": 3, + "complexity": 1, + "token_count": 27, + "parameters": [ + "self", + "name" + ], + "start_line": 894, + "end_line": 899, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 6, + "top_nesting_level": 1 + }, + { + "name": "get_info", + "long_name": "get_info( self , * names )", + "filename": "misc_util.py", + "nloc": 6, + "complexity": 2, + "token_count": 36, + "parameters": [ + "self", + "names" + ], + "start_line": 901, + "end_line": 908, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 8, + "top_nesting_level": 1 + }, + { + "name": "get_cmd", + "long_name": "get_cmd( cmdname , _cache = { } )", + "filename": "misc_util.py", + "nloc": 11, + "complexity": 3, + "token_count": 65, + "parameters": [ + "cmdname", + "_cache" + ], + "start_line": 910, + "end_line": 920, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 11, + "top_nesting_level": 0 + }, + { + "name": "get_numpy_include_dirs", + "long_name": "get_numpy_include_dirs( )", + "filename": "misc_util.py", + "nloc": 11, + "complexity": 3, + "token_count": 85, + "parameters": [], + "start_line": 922, + "end_line": 936, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 15, + "top_nesting_level": 0 + }, + { + "name": "default_config_dict", + "long_name": "default_config_dict( name = None , parent_name = None , local_path = None )", + "filename": "misc_util.py", + "nloc": 9, + "complexity": 1, + "token_count": 70, + "parameters": [ + "name", + "parent_name", + "local_path" + ], + "start_line": 940, + "end_line": 951, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 12, + "top_nesting_level": 0 + }, + { + "name": "dict_append", + "long_name": "dict_append( d , ** kws )", + "filename": "misc_util.py", + "nloc": 6, + "complexity": 3, + "token_count": 44, + "parameters": [ + "d", + "kws" + ], + "start_line": 954, + "end_line": 959, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 6, + "top_nesting_level": 0 + }, + { + "name": "appendpath", + "long_name": "appendpath( prefix , path )", + "filename": "misc_util.py", + "nloc": 19, + "complexity": 6, + "token_count": 237, + "parameters": [ + "prefix", + "path" + ], + "start_line": 961, + "end_line": 980, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 20, + "top_nesting_level": 0 + }, + { + "name": "generate_config_py", + "long_name": "generate_config_py( target )", + "filename": "misc_util.py", + "nloc": 27, + "complexity": 2, + "token_count": 117, + "parameters": [ + "target" + ], + "start_line": 982, + "end_line": 1015, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 34, + "top_nesting_level": 0 + }, + { + "name": "generate_svn_version_py", + "long_name": "generate_svn_version_py( extension , build_dir )", + "filename": "misc_util.py", + "nloc": 15, + "complexity": 4, + "token_count": 109, + "parameters": [ + "extension", + "build_dir" + ], + "start_line": 1017, + "end_line": 1044, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 28, + "top_nesting_level": 0 + } + ], + "changed_methods": [ + { + "name": "generate_svn_version_py", + "long_name": "generate_svn_version_py( extension , build_dir )", + "filename": "misc_util.py", + "nloc": 15, + "complexity": 4, + "token_count": 109, + "parameters": [ + "extension", + "build_dir" + ], + "start_line": 1017, + "end_line": 1044, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 28, + "top_nesting_level": 0 + }, + { + "name": "add_data_dir", + "long_name": "add_data_dir( self , data_path )", + "filename": "misc_util.py", + "nloc": 24, + "complexity": 8, + "token_count": 153, + "parameters": [ + "self", + "data_path" + ], + "start_line": 466, + "end_line": 497, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 32, + "top_nesting_level": 1 + }, + { + "name": "get_path", + "long_name": "get_path( mod_name , parent_path = None )", + "filename": "misc_util.py", + "nloc": 15, + "complexity": 6, + "token_count": 132, + "parameters": [ + "mod_name", + "parent_path" + ], + "start_line": 23, + "end_line": 43, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 21, + "top_nesting_level": 0 + }, + { + "name": "add_data_files", + "long_name": "add_data_files( self , * files )", + "filename": "misc_util.py", + "nloc": 39, + "complexity": 15, + "token_count": 281, + "parameters": [ + "self", + "files" + ], + "start_line": 499, + "end_line": 548, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 50, + "top_nesting_level": 1 + }, + { + "name": "make_svn_version_py.generate_svn_version_py", + "long_name": "make_svn_version_py.generate_svn_version_py( )", + "filename": "misc_util.py", + "nloc": 13, + "complexity": 2, + "token_count": 81, + "parameters": [], + "start_line": 871, + "end_line": 889, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 19, + "top_nesting_level": 2 + }, + { + "name": "filter_sources", + "long_name": "filter_sources( sources )", + "filename": "misc_util.py", + "nloc": 17, + "complexity": 5, + "token_count": 84, + "parameters": [ + "sources" + ], + "start_line": 152, + "end_line": 172, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 21, + "top_nesting_level": 0 + }, + { + "name": "add_library", + "long_name": "add_library( self , name , sources , ** build_info )", + "filename": "misc_util.py", + "nloc": 15, + "complexity": 4, + "token_count": 106, + "parameters": [ + "self", + "name", + "sources", + "build_info" + ], + "start_line": 677, + "end_line": 702, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 26, + "top_nesting_level": 1 + }, + { + "name": "terminal_has_colors", + "long_name": "terminal_has_colors( )", + "filename": "misc_util.py", + "nloc": 18, + "complexity": 13, + "token_count": 137, + "parameters": [], + "start_line": 47, + "end_line": 72, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 26, + "top_nesting_level": 0 + }, + { + "name": "__init__", + "long_name": "__init__( self , package_name = None , parent_name = None , top_path = None , package_path = None , ** attrs )", + "filename": "misc_util.py", + "nloc": 44, + "complexity": 12, + "token_count": 377, + "parameters": [ + "self", + "package_name", + "parent_name", + "top_path", + "package_path", + "attrs" + ], + "start_line": 297, + "end_line": 360, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 64, + "top_nesting_level": 1 + }, + { + "name": "make_svn_version_py", + "long_name": "make_svn_version_py( self )", + "filename": "misc_util.py", + "nloc": 7, + "complexity": 2, + "token_count": 42, + "parameters": [ + "self" + ], + "start_line": 860, + "end_line": 892, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 33, + "top_nesting_level": 1 + } + ], + "nloc": 779, + "complexity": 245, + "token_count": 5634, + "diff_parsed": { + "added": [ + " #builtin if/then added by Pearu for use in core.run_setup.", + " if hasattr(sys.stdout,'isatty') and sys.stdout.isatty():", + " and ((curses.tigetstr(\"setf\") is not None", + " and curses.tigetstr(\"setb\") is not None)", + " c_sources.append(source)", + " # this is the relative path in the installed package", + " self.path_in_package = os.path.join(*self.name.split('.'))", + " d = self.path_in_package", + " ds = os.path.join(d, data_path)", + " d = self.path_in_package", + "", + "", + "", + " self.add_data_files(generate_svn_version_py())", + "" + ], + "deleted": [ + " #builtin if/then added by Pearu for use in core.run_setup.", + " if hasattr(sys.stdout,'isatty') and sys.stdout.isatty():", + " and ((curses.tigetstr(\"setf\") is not None", + " and curses.tigetstr(\"setb\") is not None)", + " c_sources.append(source)", + " ds = os.path.join(*(self.name.split('.')+[data_path]))", + " else:", + " ds = os.path.join(d,data_path)", + " d = os.path.join(*(self.name.split('.')))", + "", + "", + "", + " d = os.path.join(*(self.name.split('.')))", + " self.add_data_files((d, generate_svn_version_py()))", + "" + ] + } + } + ] + }, + { + "hash": "ba6c2ba95f4d0ab8a6c153a617aa5d1c789318a5", + "msg": "Fix bdist_rpm for path names containing spaces.", + "author": { + "name": "Pearu Peterson", + "email": "pearu.peterson@gmail.com" + }, + "committer": { + "name": "Pearu Peterson", + "email": "pearu.peterson@gmail.com" + }, + "author_date": "2006-01-28T09:25:27+00:00", + "author_timezone": 0, + "committer_date": "2006-01-28T09:25:27+00:00", + "committer_timezone": 0, + "branches": [ + "main" + ], + "in_main_branch": true, + "merge": false, + "parents": [ + "b8e4a5f019da3020939407e447b0631db5e17371" + ], + "project_name": "repo_copy", + "project_path": "/tmp/tmppy2o86q9/repo_copy", + "deletions": 0, + "insertions": 25, + "lines": 25, + "files": 1, + "dmm_unit_size": 0.0, + "dmm_unit_complexity": 1.0, + "dmm_unit_interfacing": 1.0, + "modified_files": [ + { + "old_path": "numpy/distutils/command/install.py", + "new_path": "numpy/distutils/command/install.py", + "filename": "install.py", + "extension": "py", + "change_type": "MODIFY", + "diff": "@@ -1,9 +1,34 @@\n \n+import os\n from distutils.command.install import *\n from distutils.command.install import install as old_install\n+from distutils.file_util import write_file\n \n class install(old_install):\n \n def finalize_options (self):\n old_install.finalize_options(self)\n self.install_lib = self.install_libbase\n+\n+ def run(self):\n+ r = old_install.run(self)\n+ if self.record:\n+ # bdist_rpm fails when INSTALLED_FILES contains\n+ # paths with spaces. Such paths must be enclosed\n+ # with double-quotes.\n+ f = open(self.record,'r')\n+ lines = []\n+ need_rewrite = False\n+ for l in f.readlines():\n+ l = l.rstrip()\n+ if ' ' in l:\n+ need_rewrite = True\n+ l = '\"%s\"' % (l)\n+ lines.append(l)\n+ f.close()\n+ if need_rewrite:\n+ self.execute(write_file,\n+ (self.record, lines),\n+ \"re-writing list of installed files to '%s'\" %\n+ self.record)\n+ return r\n", + "added_lines": 25, + "deleted_lines": 0, + "source_code": "\nimport os\nfrom distutils.command.install import *\nfrom distutils.command.install import install as old_install\nfrom distutils.file_util import write_file\n\nclass install(old_install):\n\n def finalize_options (self):\n old_install.finalize_options(self)\n self.install_lib = self.install_libbase\n\n def run(self):\n r = old_install.run(self)\n if self.record:\n # bdist_rpm fails when INSTALLED_FILES contains\n # paths with spaces. Such paths must be enclosed\n # with double-quotes.\n f = open(self.record,'r')\n lines = []\n need_rewrite = False\n for l in f.readlines():\n l = l.rstrip()\n if ' ' in l:\n need_rewrite = True\n l = '\"%s\"' % (l)\n lines.append(l)\n f.close()\n if need_rewrite:\n self.execute(write_file,\n (self.record, lines),\n \"re-writing list of installed files to '%s'\" %\n self.record)\n return r\n", + "source_code_before": "\nfrom distutils.command.install import *\nfrom distutils.command.install import install as old_install\n\nclass install(old_install):\n\n def finalize_options (self):\n old_install.finalize_options(self)\n self.install_lib = self.install_libbase\n", + "methods": [ + { + "name": "finalize_options", + "long_name": "finalize_options( self )", + "filename": "install.py", + "nloc": 3, + "complexity": 1, + "token_count": 18, + "parameters": [ + "self" + ], + "start_line": 9, + "end_line": 11, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 3, + "top_nesting_level": 1 + }, + { + "name": "run", + "long_name": "run( self )", + "filename": "install.py", + "nloc": 19, + "complexity": 5, + "token_count": 102, + "parameters": [ + "self" + ], + "start_line": 13, + "end_line": 34, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 22, + "top_nesting_level": 1 + } + ], + "methods_before": [ + { + "name": "finalize_options", + "long_name": "finalize_options( self )", + "filename": "install.py", + "nloc": 3, + "complexity": 1, + "token_count": 18, + "parameters": [ + "self" + ], + "start_line": 7, + "end_line": 9, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 3, + "top_nesting_level": 1 + } + ], + "changed_methods": [ + { + "name": "run", + "long_name": "run( self )", + "filename": "install.py", + "nloc": 19, + "complexity": 5, + "token_count": 102, + "parameters": [ + "self" + ], + "start_line": 13, + "end_line": 34, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 22, + "top_nesting_level": 1 + } + ], + "nloc": 27, + "complexity": 6, + "token_count": 154, + "diff_parsed": { + "added": [ + "import os", + "from distutils.file_util import write_file", + "", + " def run(self):", + " r = old_install.run(self)", + " if self.record:", + " # bdist_rpm fails when INSTALLED_FILES contains", + " # paths with spaces. Such paths must be enclosed", + " # with double-quotes.", + " f = open(self.record,'r')", + " lines = []", + " need_rewrite = False", + " for l in f.readlines():", + " l = l.rstrip()", + " if ' ' in l:", + " need_rewrite = True", + " l = '\"%s\"' % (l)", + " lines.append(l)", + " f.close()", + " if need_rewrite:", + " self.execute(write_file,", + " (self.record, lines),", + " \"re-writing list of installed files to '%s'\" %", + " self.record)", + " return r" + ], + "deleted": [] + } + } + ] + }, + { + "hash": "4c2ce0ae3095ce4f7420bfb88fafd51aca5a0a46", + "msg": "Introduced njoin and minrelpath to handle relative paths and containing slashes in an OS independent way. Fixed a __svn_version__ installation bug.", + "author": { + "name": "Pearu Peterson", + "email": "pearu.peterson@gmail.com" + }, + "committer": { + "name": "Pearu Peterson", + "email": "pearu.peterson@gmail.com" + }, + "author_date": "2006-01-28T09:52:05+00:00", + "author_timezone": 0, + "committer_date": "2006-01-28T09:52:05+00:00", + "committer_timezone": 0, + "branches": [ + "main" + ], + "in_main_branch": true, + "merge": false, + "parents": [ + "ba6c2ba95f4d0ab8a6c153a617aa5d1c789318a5" + ], + "project_name": "repo_copy", + "project_path": "/tmp/tmppy2o86q9/repo_copy", + "deletions": 26, + "insertions": 95, + "lines": 121, + "files": 2, + "dmm_unit_size": 0.36538461538461536, + "dmm_unit_complexity": 0.36538461538461536, + "dmm_unit_interfacing": 0.9615384615384616, + "modified_files": [ + { + "old_path": "numpy/distutils/misc_util.py", + "new_path": "numpy/distutils/misc_util.py", + "filename": "misc_util.py", + "extension": "py", + "change_type": "MODIFY", + "diff": "@@ -13,7 +13,7 @@\n 'has_f_sources', 'has_cxx_sources', 'filter_sources',\n 'get_dependencies', 'is_local_src_dir', 'get_ext_source_files',\n 'get_script_files', 'get_lib_source_files', 'get_data_files',\n- 'dot_join', 'get_frame']\n+ 'dot_join', 'get_frame', 'minrelpath','njoin']\n \n def allpath(name):\n \"Convert a /-separated pathname to one using the OS's path separator.\"\n@@ -42,6 +42,38 @@ def get_path(mod_name,parent_path=None):\n d = d[len(pd)+1:]\n return d or '.'\n \n+def njoin(*path):\n+ \"\"\" Join two or more pathname components +\n+ - convert a /-separated pathname to one using the OS's path separator.\n+ - resolve `..` from path.\n+ \"\"\"\n+ if isinstance(path,tuple):\n+ path = os.path.join(*path)\n+ if not isinstance(path,str): return path\n+ if not ('/' == os.path.sep):\n+ path = path.replace('/',os.path.sep)\n+ return minrelpath(path)\n+\n+def minrelpath(path):\n+ \"\"\" Resolve `..` from path.\n+ \"\"\"\n+ if not isinstance(path, str): return path\n+ if '..' not in path: return path\n+ l = path.split(os.sep)\n+ j = 1\n+ while l:\n+ try:\n+ i = l.index('..',j)\n+ except ValueError:\n+ break\n+ if l[i-1]=='..':\n+ j += 1\n+ else:\n+ del l[i],l[i-1]\n+ j = 1\n+ if not l: return ''\n+ return os.path.join(*l)\n+\n # Hooks for colored terminal output.\n # See also http://www.livinglogic.de/Python/ansistyle\n def terminal_has_colors():\n@@ -322,8 +354,8 @@ def __init__(self,\n top_path = self.local_path\n if package_path is None:\n package_path = self.local_path\n- elif os.path.isdir(os.path.join(self.local_path,package_path)):\n- package_path = os.path.join(self.local_path,package_path)\n+ elif os.path.isdir(njoin(self.local_path,package_path)):\n+ package_path = njoin(self.local_path,package_path)\n if not os.path.isdir(package_path):\n raise ValueError(\"%r is not a directory\" % (package_path,))\n self.top_path = top_path\n@@ -354,9 +386,10 @@ def __init__(self,\n else:\n self.extra_keys.append(n)\n \n- if os.path.exists(os.path.join(package_path,'__init__.py')):\n+ if os.path.exists(njoin(package_path,'__init__.py')):\n self.packages.append(self.name)\n self.package_dir[self.name] = package_path\n+\n return\n \n def todict(self):\n@@ -372,6 +405,12 @@ def todict(self):\n d['name'] = self.name\n return d\n \n+ def info(self, message):\n+ print message\n+\n+ def warn(self, message):\n+ print 'Warning:',message\n+\n def __dict__(self):\n return self.todict()\n \n@@ -388,12 +427,14 @@ def get_subpackage(self,subpackage_name,subpackage_path=None):\n subpackage_name = os.path.basename(subpackage_path)\n l = subpackage_name.split('.')\n if subpackage_path is None:\n- subpackage_path = os.path.join(*([self.local_path]+l))\n+ subpackage_path = njoin(*([self.local_path]+l))\n if '*' in subpackage_name:\n dirs = filter(os.path.isdir,glob.glob(subpackage_path))\n config_list = []\n for d in dirs:\n- if not os.path.isfile(os.path.join(d,'__init__.py')):\n+ if not os.path.isfile(njoin(d,'__init__.py')):\n+ continue\n+ if 'build' in d.split(os.sep):\n continue\n n = '.'.join(d.split(os.sep)[-len(l):])\n c = self.get_subpackage(n)\n@@ -401,12 +442,11 @@ def get_subpackage(self,subpackage_name,subpackage_path=None):\n config_list.append(c)\n return config_list\n else:\n- subpackage_path = os.path.join(*([subpackage_path]+l[:-1]))\n+ subpackage_path = njoin(*([subpackage_path]+l[:-1]))\n subpackage_path = self._fix_paths([subpackage_path])[0]\n-\n- setup_py = os.path.join(subpackage_path,'setup.py')\n+ setup_py = njoin(subpackage_path,'setup.py')\n if not os.path.isfile(setup_py):\n- setup_py = os.path.join(subpackage_path,'setup_%s.py' % (subpackage_name))\n+ setup_py = njoin(subpackage_path,'setup_%s.py' % (subpackage_name))\n \n if not os.path.isfile(setup_py):\n print 'Assuming default configuration '\\\n@@ -485,9 +525,12 @@ def add_data_dir(self,data_path):\n filenames = []\n os.path.walk(path, _gsf_visit_func,filenames)\n if not os.path.isabs(path):\n+ npath = data_path\n+ if '*' in npath:\n+ npath = os.path.join(*(path.split(os.sep)[-len(npath.split(os.sep)):]))\n if d is None:\n d = self.path_in_package\n- ds = os.path.join(d, data_path)\n+ ds = os.path.join(d, npath)\n self.add_data_files((ds,filenames))\n else:\n if d is None:\n@@ -505,6 +548,13 @@ def add_data_files(self,*files):\n If path is not absolute then it's datadir prefix is\n package dir + dirname of the path.\n \"\"\"\n+ new_files = []\n+ for p in files:\n+ if isinstance(p,str) and '*' in p:\n+ new_files.extend(self.paths(p))\n+ else:\n+ new_files.append(p)\n+ files = new_files\n data_dict = {}\n new_files = []\n for p in files:\n@@ -533,7 +583,7 @@ def add_data_files(self,*files):\n for f in file_list:\n if is_string(f):\n extra_path_components = f.split(os.sep)[min_path_components:-1]\n- p = os.path.join(*([prefix]+extra_path_components))\n+ p = njoin(*([prefix]+extra_path_components))\n else:\n p = prefix\n if not data_dict.has_key(p):\n@@ -583,27 +633,31 @@ def add_headers(self,*files):\n return\n \n def _fix_paths(self,paths):\n+ assert isinstance(paths,(list,tuple)),`type(paths)`\n new_paths = []\n for n in paths:\n if isinstance(n,str):\n if '*' in n or '?' in n:\n p = glob.glob(n)\n- p2 = glob.glob(os.path.join(self.local_path,n))\n+ p2 = glob.glob(njoin(self.local_path,n))\n if p2:\n new_paths.extend(p2)\n elif p:\n new_paths.extend(p)\n else:\n new_paths.append(n)\n+ self.warn('could not resolve pattern: %r' % (n))\n else:\n- n2 = os.path.join(self.local_path,n)\n+ n2 = njoin(self.local_path,n)\n if os.path.exists(n2):\n new_paths.append(n2)\n else:\n new_paths.append(n)\n+ if not os.path.exists(n):\n+ self.warn('not existing path: %r' % (n))\n else:\n new_paths.append(n)\n- return new_paths\n+ return map(minrelpath,new_paths)\n \n def paths(self,*paths):\n \"\"\" Apply glob to paths and prepend local_path if needed.\n@@ -649,7 +703,7 @@ def add_extension(self,name,sources,**kw):\n for libname in libraries:\n if '@' in libname:\n lname,lpath = libname.split('@',1)\n- lpath = os.path.abspath(os.path.join(self.local_path,lpath))\n+ lpath = os.path.abspath(njoin(self.local_path,lpath))\n if os.path.isdir(lpath):\n c = self.get_subpackage(None,lpath)\n if isinstance(c,Configuration):\n@@ -799,7 +853,7 @@ def append_to(self, extlib):\n def _get_svn_revision(self,path):\n \"\"\" Return path's SVN revision number.\n \"\"\"\n- entries = os.path.join(path,'.svn','entries')\n+ entries = njoin(path,'.svn','entries')\n revision = None\n if os.path.isfile(entries):\n f = open(entries)\n@@ -825,7 +879,7 @@ def get_version(self):\n '__version__',\n self.name.split('.')[-1]+'_version']\n for f in files:\n- fn = os.path.join(self.local_path,f)\n+ fn = njoin(self.local_path,f)\n if os.path.isfile(fn):\n info = (open(fn),fn,('.py','U',1))\n name = os.path.splitext(os.path.basename(fn))[0]\n@@ -864,7 +918,7 @@ def make_svn_version_py(self):\n \n If __svn_version__.py existed before, nothing is done.\n \"\"\"\n- target = os.path.join(self.local_path,'__svn_version__.py')\n+ target = njoin(self.local_path,'__svn_version__.py')\n if os.path.isfile(target):\n return\n \n@@ -888,7 +942,7 @@ def rm_file(f=target):\n \n return target\n \n- self.add_data_files(generate_svn_version_py())\n+ self.add_data_files((self.path_in_package, generate_svn_version_py()))\n return\n \n def make_config_py(self,name='__config__'):\n@@ -926,12 +980,12 @@ def get_numpy_include_dirs():\n import numpy\n if numpy.show_config is None:\n # running from numpy_core source directory\n- include_dirs.append(os.path.join(os.path.dirname(numpy.__file__),\n+ include_dirs.append(njoin(os.path.dirname(numpy.__file__),\n 'core','include'))\n else:\n # using installed numpy core headers\n import numpy.core as core\n- include_dirs.append(os.path.join(os.path.dirname(core.__file__),'include'))\n+ include_dirs.append(njoin(os.path.dirname(core.__file__),'include'))\n # else running numpy/core/setup.py\n return include_dirs\n \n@@ -977,7 +1031,11 @@ def appendpath(prefix,path):\n subpath = subpath[1:]\n else:\n subpath = path\n- return os.path.normpath(os.path.join(drive + prefix, subpath))\n+ return os.path.normpath(njoin(drive + prefix, subpath))\n+\n+\n+\n+\n \n def generate_config_py(target):\n \"\"\" Generate config.py file containing system_info information\n@@ -1029,8 +1087,8 @@ def generate_svn_version_py(extension, build_dir):\n \"\"\"\n from distutils import dep_util\n local_path = extension.local_path\n- target = os.path.join(build_dir, '__svn_version__.py')\n- entries = os.path.join(local_path,'.svn','entries')\n+ target = njoin(build_dir, '__svn_version__.py')\n+ entries = njoin(local_path,'.svn','entries')\n if os.path.isfile(entries):\n if not dep_util.newer(entries, target):\n return target\n", + "added_lines": 83, + "deleted_lines": 25, + "source_code": "import os\nimport re\nimport sys\nimport imp\nimport copy\nimport glob\n\n__all__ = ['Configuration', 'get_numpy_include_dirs', 'default_config_dict',\n 'dict_append', 'appendpath', 'generate_config_py',\n 'generate_svn_version_py', 'get_cmd', 'allpath',\n 'terminal_has_colors', 'red_text', 'green_text', 'yellow_text',\n 'blue_text', 'cyan_text', 'cyg2win32', 'all_strings',\n 'has_f_sources', 'has_cxx_sources', 'filter_sources',\n 'get_dependencies', 'is_local_src_dir', 'get_ext_source_files',\n 'get_script_files', 'get_lib_source_files', 'get_data_files',\n 'dot_join', 'get_frame', 'minrelpath','njoin']\n\ndef allpath(name):\n \"Convert a /-separated pathname to one using the OS's path separator.\"\n splitted = name.split('/')\n return os.path.join(*splitted)\n\ndef get_path(mod_name,parent_path=None):\n \"\"\" Return path of the module.\n\n Returned path is relative to parent_path when given,\n otherwise it is absolute path.\n \"\"\"\n if mod_name == '__main__':\n d = os.path.abspath('.')\n elif mod_name == '__builtin__':\n #builtin if/then added by Pearu for use in core.run_setup.\n d = os.path.dirname(os.path.abspath(sys.argv[0]))\n else:\n __import__(mod_name)\n mod = sys.modules[mod_name]\n file = mod.__file__\n d = os.path.dirname(os.path.abspath(file))\n if parent_path is not None:\n pd = os.path.abspath(parent_path)\n if pd==d[:len(pd)]:\n d = d[len(pd)+1:]\n return d or '.'\n\ndef njoin(*path):\n \"\"\" Join two or more pathname components +\n - convert a /-separated pathname to one using the OS's path separator.\n - resolve `..` from path.\n \"\"\"\n if isinstance(path,tuple):\n path = os.path.join(*path)\n if not isinstance(path,str): return path\n if not ('/' == os.path.sep):\n path = path.replace('/',os.path.sep)\n return minrelpath(path)\n\ndef minrelpath(path):\n \"\"\" Resolve `..` from path.\n \"\"\"\n if not isinstance(path, str): return path\n if '..' not in path: return path\n l = path.split(os.sep)\n j = 1\n while l:\n try:\n i = l.index('..',j)\n except ValueError:\n break\n if l[i-1]=='..':\n j += 1\n else:\n del l[i],l[i-1]\n j = 1\n if not l: return ''\n return os.path.join(*l)\n\n# Hooks for colored terminal output.\n# See also http://www.livinglogic.de/Python/ansistyle\ndef terminal_has_colors():\n if sys.platform=='cygwin' and not os.environ.has_key('USE_COLOR'):\n # Avoid importing curses that causes illegal operation\n # with a message:\n # PYTHON2 caused an invalid page fault in\n # module CYGNURSES7.DLL as 015f:18bbfc28\n # Details: Python 2.3.3 [GCC 3.3.1 (cygming special)]\n # ssh to Win32 machine from debian\n # curses.version is 2.2\n # CYGWIN_98-4.10, release 1.5.7(0.109/3/2))\n return 0\n if hasattr(sys.stdout,'isatty') and sys.stdout.isatty():\n try:\n import curses\n curses.setupterm()\n if (curses.tigetnum(\"colors\") >= 0\n and curses.tigetnum(\"pairs\") >= 0\n and ((curses.tigetstr(\"setf\") is not None\n and curses.tigetstr(\"setb\") is not None)\n or (curses.tigetstr(\"setaf\") is not None\n and curses.tigetstr(\"setab\") is not None)\n or curses.tigetstr(\"scp\") is not None)):\n return 1\n except Exception,msg:\n pass\n return 0\n\nif terminal_has_colors():\n def red_text(s): return '\\x1b[31m%s\\x1b[0m'%s\n def green_text(s): return '\\x1b[32m%s\\x1b[0m'%s\n def yellow_text(s): return '\\x1b[33m%s\\x1b[0m'%s\n def blue_text(s): return '\\x1b[34m%s\\x1b[0m'%s\n def cyan_text(s): return '\\x1b[35m%s\\x1b[0m'%s\nelse:\n def red_text(s): return s\n def green_text(s): return s\n def yellow_text(s): return s\n def cyan_text(s): return s\n def blue_text(s): return s\n\n#########################\n\ndef cyg2win32(path):\n if sys.platform=='cygwin' and path.startswith('/cygdrive'):\n path = path[10] + ':' + os.path.normcase(path[11:])\n return path\n\n#########################\n\n#XXX need support for .C that is also C++\ncxx_ext_match = re.compile(r'.*[.](cpp|cxx|cc)\\Z',re.I).match\nfortran_ext_match = re.compile(r'.*[.](f90|f95|f77|for|ftn|f)\\Z',re.I).match\nf90_ext_match = re.compile(r'.*[.](f90|f95)\\Z',re.I).match\nf90_module_name_match = re.compile(r'\\s*module\\s*(?P[\\w_]+)',re.I).match\ndef _get_f90_modules(source):\n \"\"\" Return a list of Fortran f90 module names that\n given source file defines.\n \"\"\"\n if not f90_ext_match(source):\n return []\n modules = []\n f = open(source,'r')\n f_readlines = getattr(f,'xreadlines',f.readlines)\n for line in f_readlines():\n m = f90_module_name_match(line)\n if m:\n name = m.group('name')\n modules.append(name)\n # break # XXX can we assume that there is one module per file?\n f.close()\n return modules\n\ndef is_string(s):\n return isinstance(s, str)\n\ndef all_strings(lst):\n \"\"\" Return True if all items in lst are string objects. \"\"\"\n for item in lst:\n if not is_string(item):\n return False\n return True\n\ndef is_sequence(seq):\n if is_string(seq):\n return False\n try:\n len(seq)\n except:\n return False\n return True\n\ndef has_f_sources(sources):\n \"\"\" Return True if sources contains Fortran files \"\"\"\n for source in sources:\n if fortran_ext_match(source):\n return True\n return False\n\ndef has_cxx_sources(sources):\n \"\"\" Return True if sources contains C++ files \"\"\"\n for source in sources:\n if cxx_ext_match(source):\n return True\n return False\n\ndef filter_sources(sources):\n \"\"\" Return four lists of filenames containing\n C, C++, Fortran, and Fortran 90 module sources,\n respectively.\n \"\"\"\n c_sources = []\n cxx_sources = []\n f_sources = []\n fmodule_sources = []\n for source in sources:\n if fortran_ext_match(source):\n modules = _get_f90_modules(source)\n if modules:\n fmodule_sources.append(source)\n else:\n f_sources.append(source)\n elif cxx_ext_match(source):\n cxx_sources.append(source)\n else:\n c_sources.append(source)\n return c_sources, cxx_sources, f_sources, fmodule_sources\n\n\ndef _get_headers(directory_list):\n # get *.h files from list of directories\n headers = []\n for dir in directory_list:\n head = glob.glob(os.path.join(dir,\"*.h\")) #XXX: *.hpp files??\n headers.extend(head)\n return headers\n\ndef _get_directories(list_of_sources):\n # get unique directories from list of sources.\n direcs = []\n for file in list_of_sources:\n dir = os.path.split(file)\n if dir[0] != '' and not dir[0] in direcs:\n direcs.append(dir[0])\n return direcs\n\ndef get_dependencies(sources):\n #XXX scan sources for include statements\n return _get_headers(_get_directories(sources))\n\ndef is_local_src_dir(directory):\n \"\"\" Return true if directory is local directory.\n \"\"\"\n if not is_string(directory):\n return False\n abs_dir = os.path.abspath(directory)\n c = os.path.commonprefix([os.getcwd(),abs_dir])\n new_dir = abs_dir[len(c):].split(os.sep)\n if new_dir and not new_dir[0]:\n new_dir = new_dir[1:]\n if new_dir and new_dir[0]=='build':\n return False\n new_dir = os.sep.join(new_dir)\n return os.path.isdir(new_dir)\n\ndef _gsf_visit_func(filenames,dirname,names):\n if os.path.basename(dirname) in ['CVS','.svn','build']:\n names[:] = []\n return\n for name in names:\n if name[-1] in \"~#\":\n continue\n fullname = os.path.join(dirname,name)\n ext = os.path.splitext(fullname)[1]\n if ext and ext in ['.pyc','.o']:\n continue\n if os.path.isfile(fullname):\n filenames.append(fullname)\n\ndef get_ext_source_files(ext):\n # Get sources and any include files in the same directory.\n filenames = []\n sources = filter(is_string, ext.sources)\n filenames.extend(sources)\n filenames.extend(get_dependencies(sources))\n for d in ext.depends:\n if is_local_src_dir(d):\n os.path.walk(d,_gsf_visit_func,filenames)\n elif os.path.isfile(d):\n filenames.append(d)\n return filenames\n\ndef get_script_files(scripts):\n scripts = filter(is_string, scripts)\n return scripts\n\ndef get_lib_source_files(lib):\n filenames = []\n sources = lib[1].get('sources',[])\n sources = filter(is_string, sources)\n filenames.extend(sources)\n filenames.extend(get_dependencies(sources))\n depends = lib[1].get('depends',[])\n for d in depends:\n if is_local_src_dir(d):\n os.path.walk(d,_gsf_visit_func,filenames)\n elif os.path.isfile(d):\n filenames.append(d)\n return filenames\n\ndef get_data_files(data):\n if is_string(data):\n return [data]\n sources = data[1]\n filenames = []\n for s in sources:\n if callable(s):\n continue\n if is_local_src_dir(s):\n os.path.walk(s,_gsf_visit_func,filenames)\n elif is_string(s):\n if os.path.isfile(s):\n filenames.append(s)\n else:\n print 'Not existing data file:',s\n else:\n raise TypeError,repr(s)\n return filenames\n\ndef dot_join(*args):\n return '.'.join(filter(None,args))\n\ndef get_frame(level=0):\n try:\n return sys._getframe(level+1)\n except AttributeError:\n frame = sys.exc_info()[2].tb_frame\n for i in range(level+1):\n frame = frame.f_back\n return frame\n\n######################\n\nclass Configuration:\n\n _list_keys = ['packages','ext_modules','data_files','include_dirs',\n 'libraries','headers','scripts','py_modules']\n _dict_keys = ['package_dir']\n\n numpy_include_dirs = []\n\n def __init__(self,\n package_name=None,\n parent_name=None,\n top_path=None,\n package_path=None,\n **attrs):\n \"\"\" Construct configuration instance of a package.\n\n package_name -- name of the package\n Ex.: 'distutils'\n parent_name -- name of the parent package\n Ex.: 'numpy'\n top_path -- directory of the toplevel package\n Ex.: the directory where the numpy package source sits\n package_path -- directory of package. Will be computed by magic from the\n directory of the caller module if not specified\n Ex.: the directory where numpy.distutils is\n \"\"\"\n self.name = dot_join(parent_name, package_name)\n\n caller_frame = get_frame(1)\n caller_name = eval('__name__',caller_frame.f_globals,caller_frame.f_locals)\n\n self.local_path = get_path(caller_name, top_path)\n if top_path is None:\n top_path = self.local_path\n if package_path is None:\n package_path = self.local_path\n elif os.path.isdir(njoin(self.local_path,package_path)):\n package_path = njoin(self.local_path,package_path)\n if not os.path.isdir(package_path):\n raise ValueError(\"%r is not a directory\" % (package_path,))\n self.top_path = top_path\n self.package_path = package_path\n # this is the relative path in the installed package\n self.path_in_package = os.path.join(*self.name.split('.'))\n\n self.list_keys = copy.copy(self._list_keys)\n self.dict_keys = copy.copy(self._dict_keys)\n\n for n in self.list_keys:\n setattr(self,n,copy.copy(attrs.get(n,[])))\n\n for n in self.dict_keys:\n setattr(self,n,copy.copy(attrs.get(n,{})))\n\n known_keys = self.list_keys + self.dict_keys\n self.extra_keys = []\n for n in attrs.keys():\n if n in known_keys:\n continue\n a = attrs[n]\n setattr(self,n,a)\n if isinstance(a, list):\n self.list_keys.append(n)\n elif isinstance(a, dict):\n self.dict_keys.append(n)\n else:\n self.extra_keys.append(n)\n\n if os.path.exists(njoin(package_path,'__init__.py')):\n self.packages.append(self.name)\n self.package_dir[self.name] = package_path\n\n return\n\n def todict(self):\n \"\"\" Return configuration distionary suitable for passing\n to distutils.core.setup() function.\n \"\"\"\n d = {}\n for n in self.list_keys + self.dict_keys + self.extra_keys:\n a = getattr(self,n)\n if a:\n d[n] = a\n if self.name:\n d['name'] = self.name\n return d\n\n def info(self, message):\n print message\n\n def warn(self, message):\n print 'Warning:',message\n\n def __dict__(self):\n return self.todict()\n\n def get_distribution(self):\n import distutils.core\n dist = distutils.core._setup_distribution\n return dist\n\n def get_subpackage(self,subpackage_name,subpackage_path=None):\n \"\"\" Return subpackage configuration.\n \"\"\"\n if subpackage_name is None:\n assert subpackage_path is not None\n subpackage_name = os.path.basename(subpackage_path)\n l = subpackage_name.split('.')\n if subpackage_path is None:\n subpackage_path = njoin(*([self.local_path]+l))\n if '*' in subpackage_name:\n dirs = filter(os.path.isdir,glob.glob(subpackage_path))\n config_list = []\n for d in dirs:\n if not os.path.isfile(njoin(d,'__init__.py')):\n continue\n if 'build' in d.split(os.sep):\n continue\n n = '.'.join(d.split(os.sep)[-len(l):])\n c = self.get_subpackage(n)\n if c:\n config_list.append(c)\n return config_list\n else:\n subpackage_path = njoin(*([subpackage_path]+l[:-1]))\n subpackage_path = self._fix_paths([subpackage_path])[0]\n setup_py = njoin(subpackage_path,'setup.py')\n if not os.path.isfile(setup_py):\n setup_py = njoin(subpackage_path,'setup_%s.py' % (subpackage_name))\n\n if not os.path.isfile(setup_py):\n print 'Assuming default configuration '\\\n '(%s/{setup_%s,setup}.py was not found)' \\\n % (os.path.dirname(setup_py),subpackage_name)\n config = Configuration(subpackage_name,self.name,\n self.top_path,subpackage_path)\n else:\n # In case setup_py imports local modules:\n sys.path.insert(0,os.path.dirname(setup_py))\n try:\n info = (open(setup_py),setup_py,('.py','U',1))\n setup_name = os.path.splitext(os.path.basename(setup_py))[0]\n n = dot_join(self.name,setup_name)\n setup_module = imp.load_module('_'.join(n.split('.')),*info)\n\n if not hasattr(setup_module,'configuration'):\n print 'Assuming default configuration '\\\n '(%s does not define configuration())' % (setup_module)\n config = Configuration(subpackage_name,self.name,\n self.top_path,subpackage_path)\n else:\n args = (self.name,)\n if setup_module.configuration.func_code.co_argcount>1:\n args = args + (self.top_path,)\n config = setup_module.configuration(*args)\n\n finally:\n del sys.path[0]\n\n return config\n\n def add_subpackage(self,subpackage_name,subpackage_path=None):\n \"\"\" Add subpackage to configuration.\n \"\"\"\n config = self.get_subpackage(subpackage_name,subpackage_path)\n if not isinstance(config, list):\n config_list = [config]\n else:\n config_list = config\n for config in config_list:\n if not config:\n print 'No configuration returned, assuming unavailable.'\n else:\n if isinstance(config,Configuration):\n print 'Appending %s configuration to %s' % (config.name,self.name)\n self.dict_append(**config.todict())\n else:\n print 'Appending %s configuration to %s' % (config.get('name'),self.name)\n self.dict_append(**config)\n\n dist = self.get_distribution()\n if dist is not None:\n print 'distutils distribution has been initialized, it may be too late to add a subpackage', subpackage_name\n return\n\n def add_data_dir(self,data_path):\n \"\"\" Recursively add files under data_path to data_files list.\n Argument can be either\n - 2-sequence (,)\n - path to data directory where python datadir suffix defaults\n to package dir.\n If path is not absolute then it's datadir suffix is\n package dir + subdirname of the path.\n \"\"\"\n if is_sequence(data_path):\n d, data_path = data_path\n else:\n d = None\n if not is_string(data_path):\n raise TypeError(\"not a string: %r\" % (data_path,))\n for path in self.paths(data_path):\n if not os.path.exists(path):\n print 'Not existing data path',path\n continue\n filenames = []\n os.path.walk(path, _gsf_visit_func,filenames)\n if not os.path.isabs(path):\n npath = data_path\n if '*' in npath:\n npath = os.path.join(*(path.split(os.sep)[-len(npath.split(os.sep)):]))\n if d is None:\n d = self.path_in_package\n ds = os.path.join(d, npath)\n self.add_data_files((ds,filenames))\n else:\n if d is None:\n self.add_data_files(*filenames)\n else:\n self.add_data_files((d,filenames))\n return\n\n def add_data_files(self,*files):\n \"\"\" Add data files to configuration data_files.\n Argument(s) can be either\n - 2-sequence (,)\n - paths to data files where python datadir prefix defaults\n to package dir.\n If path is not absolute then it's datadir prefix is\n package dir + dirname of the path.\n \"\"\"\n new_files = []\n for p in files:\n if isinstance(p,str) and '*' in p:\n new_files.extend(self.paths(p))\n else:\n new_files.append(p)\n files = new_files\n data_dict = {}\n new_files = []\n for p in files:\n if not is_sequence(p):\n d = self.path_in_package\n if is_string(p) and not os.path.isabs(p):\n d = appendpath(d,os.path.dirname(p))\n p = (d,p)\n new_files.append(p)\n files = []\n for prefix,filepattern in new_files:\n if is_string(filepattern):\n file_list = self.paths(filepattern)\n elif callable(filepattern):\n file_list = [filepattern]\n else:\n file_list = self.paths(*filepattern)\n\n nof_path_components = [len(f.split(os.sep))\n for f in file_list if is_string(f)]\n if nof_path_components:\n min_path_components = min(nof_path_components)-1\n else:\n min_path_components = 0\n\n for f in file_list:\n if is_string(f):\n extra_path_components = f.split(os.sep)[min_path_components:-1]\n p = njoin(*([prefix]+extra_path_components))\n else:\n p = prefix\n if not data_dict.has_key(p):\n data_dict[p] = [f]\n else:\n data_dict[p].append(f)\n\n dist = self.get_distribution()\n if dist is not None:\n dist.data_files.extend(data_dict.items())\n else:\n self.data_files.extend(data_dict.items())\n\n ### XXX Implement add_py_modules\n\n def add_include_dirs(self,*paths):\n \"\"\" Add paths to configuration include directories.\n \"\"\"\n include_dirs = self._fix_paths(paths)\n dist = self.get_distribution()\n if dist is not None:\n dist.include_dirs.extend(include_dirs)\n else:\n self.include_dirs.extend(include_dirs)\n return\n\n def add_headers(self,*files):\n \"\"\" Add installable headers to configuration.\n Argument(s) can be either\n - 2-sequence (,)\n - path(s) to header file(s) where python includedir suffix will default\n to package name.\n \"\"\"\n headers = []\n for path in files:\n if is_string(path):\n [headers.append((self.name,p)) for p in self.paths(path)]\n else:\n if not isinstance(path, (tuple, list)) or len(path) != 2:\n raise TypeError(repr(path))\n [headers.append((path[0],p)) for p in self.paths(path[1])]\n dist = self.get_distribution()\n if dist is not None:\n dist.headers.extend(headers)\n else:\n self.headers.extend(headers)\n return\n\n def _fix_paths(self,paths):\n assert isinstance(paths,(list,tuple)),`type(paths)`\n new_paths = []\n for n in paths:\n if isinstance(n,str):\n if '*' in n or '?' in n:\n p = glob.glob(n)\n p2 = glob.glob(njoin(self.local_path,n))\n if p2:\n new_paths.extend(p2)\n elif p:\n new_paths.extend(p)\n else:\n new_paths.append(n)\n self.warn('could not resolve pattern: %r' % (n))\n else:\n n2 = njoin(self.local_path,n)\n if os.path.exists(n2):\n new_paths.append(n2)\n else:\n new_paths.append(n)\n if not os.path.exists(n):\n self.warn('not existing path: %r' % (n))\n else:\n new_paths.append(n)\n return map(minrelpath,new_paths)\n\n def paths(self,*paths):\n \"\"\" Apply glob to paths and prepend local_path if needed.\n \"\"\"\n return self._fix_paths(paths)\n\n def add_extension(self,name,sources,**kw):\n \"\"\" Add extension to configuration.\n\n Keywords:\n include_dirs, define_macros, undef_macros,\n library_dirs, libraries, runtime_library_dirs,\n extra_objects, extra_compile_args, extra_link_args,\n export_symbols, swig_opts, depends, language,\n f2py_options, module_dirs\n extra_info - dict or list of dict of keywords to be\n appended to keywords.\n \"\"\"\n ext_args = copy.copy(kw)\n ext_args['name'] = dot_join(self.name,name)\n ext_args['sources'] = sources\n\n if ext_args.has_key('extra_info'):\n extra_info = ext_args['extra_info']\n del ext_args['extra_info']\n if type(extra_info) is type({}):\n extra_info = [extra_info]\n for info in extra_info:\n assert type(info) is type({}),`info`\n dict_append(ext_args,**info)\n\n for k in ext_args.keys():\n v = ext_args[k]\n if k in ['sources','depends','include_dirs','library_dirs',\n 'module_dirs','extra_objects']:\n new_v = self._fix_paths(v)\n ext_args[k] = new_v\n\n # Resolve out-of-tree dependencies\n libraries = ext_args.get('libraries',[])\n libnames = []\n ext_args['libraries'] = []\n for libname in libraries:\n if '@' in libname:\n lname,lpath = libname.split('@',1)\n lpath = os.path.abspath(njoin(self.local_path,lpath))\n if os.path.isdir(lpath):\n c = self.get_subpackage(None,lpath)\n if isinstance(c,Configuration):\n c = c.todict()\n for l in [l[0] for l in c.get('libraries',[])]:\n llname = l.split('__OF__',1)[0]\n if llname == lname:\n c.pop('name',None)\n dict_append(ext_args,**c)\n break\n continue\n libnames.append(libname)\n\n ext_args['libraries'] = libnames + ext_args['libraries']\n\n from numpy.distutils.core import Extension\n ext = Extension(**ext_args)\n self.ext_modules.append(ext)\n\n dist = self.get_distribution()\n if dist is not None:\n print 'distutils distribution has been initialized, it may be too late to add an extension', name\n return ext\n\n def add_library(self,name,sources,**build_info):\n \"\"\" Add library to configuration.\n\n Valid keywords for build_info:\n depends\n macros\n include_dirs\n extra_compiler_args\n f2py_options\n \"\"\"\n build_info = copy.copy(build_info)\n name = name #+ '__OF__' + self.name\n build_info['sources'] = sources\n\n for k in build_info.keys():\n v = build_info[k]\n if k in ['sources','depends','include_dirs','library_dirs',\n 'module_dirs','extra_objects']:\n new_v = self._fix_paths(v)\n build_info[k] = new_v\n self.libraries.append((name,build_info))\n\n dist = self.get_distribution()\n if dist is not None:\n print 'distutils distribution has been initialized, it may be too late to add a library', name\n return\n\n def add_scripts(self,*files):\n \"\"\" Add scripts to configuration.\n \"\"\"\n scripts = self._fix_paths(files)\n dist = self.get_distribution()\n if dist is not None:\n dist.scripts.extend(scripts)\n else:\n self.scripts.extend(scripts)\n return\n\n def dict_append(self,**dict):\n for key in self.list_keys:\n a = getattr(self,key)\n a.extend(dict.get(key,[]))\n for key in self.dict_keys:\n a = getattr(self,key)\n a.update(dict.get(key,{}))\n known_keys = self.list_keys + self.dict_keys + self.extra_keys\n for key in dict.keys():\n if key not in known_keys and not hasattr(self,key):\n print 'Inheriting attribute %r from %r' \\\n % (key,dict.get('name','?'))\n setattr(self,key,dict[key])\n self.extra_keys.append(key)\n return\n\n def __str__(self):\n known_keys = self.list_keys + self.dict_keys + self.extra_keys\n s = '<'+5*'-' + '\\n'\n s += 'Configuration of '+self.name+':\\n'\n for k in known_keys:\n a = getattr(self,k,None)\n if a:\n s += '%s = %r\\n' % (k,a)\n s += 5*'-' + '>'\n return s\n\n def get_config_cmd(self):\n cmd = get_cmd('config')\n cmd.ensure_finalized()\n cmd.dump_source = 0\n cmd.noisy = 0\n old_path = os.environ.get('PATH')\n if old_path:\n path = os.pathsep.join(['.',old_path])\n os.environ['PATH'] = path\n return cmd\n\n def get_build_temp_dir(self):\n cmd = get_cmd('build')\n cmd.ensure_finalized()\n return cmd.build_temp\n\n def have_f77c(self):\n \"\"\" Check for availability of Fortran 77 compiler.\n Use it inside source generating function to ensure that\n setup distribution instance has been initialized.\n \"\"\"\n simple_fortran_subroutine = '''\n subroutine simple\n end\n '''\n config_cmd = self.get_config_cmd()\n flag = config_cmd.try_compile(simple_fortran_subroutine,lang='f77')\n return flag\n\n def have_f90c(self):\n \"\"\" Check for availability of Fortran 90 compiler.\n Use it inside source generating function to ensure that\n setup distribution instance has been initialized.\n \"\"\"\n simple_fortran_subroutine = '''\n subroutine simple\n end\n '''\n config_cmd = self.get_config_cmd()\n flag = config_cmd.try_compile(simple_fortran_subroutine,lang='f90')\n return flag\n\n def append_to(self, extlib):\n \"\"\" Append libraries, include_dirs to extension or library item.\n \"\"\"\n if is_sequence(extlib):\n lib_name, build_info = extlib\n dict_append(build_info,\n libraries=self.libraries,\n include_dirs=self.include_dirs)\n else:\n from numpy.distutils.core import Extension\n assert isinstance(extlib,Extension),`extlib`\n extlib.libraries.extend(self.libraries)\n extlib.include_dirs.extend(self.include_dirs)\n return\n\n def _get_svn_revision(self,path):\n \"\"\" Return path's SVN revision number.\n \"\"\"\n entries = njoin(path,'.svn','entries')\n revision = None\n if os.path.isfile(entries):\n f = open(entries)\n m = re.search(r'revision=\"(?P\\d+)\"',f.read())\n f.close()\n if m:\n revision = int(m.group('revision'))\n return revision\n\n def get_version(self):\n \"\"\" Try to get version string of a package.\n \"\"\"\n version = getattr(self,'version',None)\n if version is not None:\n return version\n\n # Get version from version file.\n files = ['__version__.py',\n self.name.split('.')[-1]+'_version.py',\n 'version.py',\n '__svn_version__.py']\n version_vars = ['version',\n '__version__',\n self.name.split('.')[-1]+'_version']\n for f in files:\n fn = njoin(self.local_path,f)\n if os.path.isfile(fn):\n info = (open(fn),fn,('.py','U',1))\n name = os.path.splitext(os.path.basename(fn))[0]\n n = dot_join(self.name,name)\n try:\n version_module = imp.load_module('_'.join(n.split('.')),*info)\n except ImportError,msg:\n print msg\n version_module = None\n if version_module is None:\n continue\n\n for a in version_vars:\n version = getattr(version_module,a,None)\n if version is not None:\n break\n if version is not None:\n break\n\n if version is not None:\n self.version = version\n return version\n\n # Get version as SVN revision number\n revision = self._get_svn_revision(self.local_path)\n if revision is not None:\n version = str(revision)\n self.version = version\n\n return version\n\n def make_svn_version_py(self):\n \"\"\" Generate package __svn_version__.py file from SVN revision number,\n it will be removed after python exits but will be available\n when sdist, etc commands are executed.\n\n If __svn_version__.py existed before, nothing is done.\n \"\"\"\n target = njoin(self.local_path,'__svn_version__.py')\n if os.path.isfile(target):\n return\n\n def generate_svn_version_py():\n if not os.path.isfile(target):\n revision = self._get_svn_revision(self.local_path)\n assert revision is not None,'hmm, why I am not inside SVN tree???'\n version = str(revision)\n print 'Creating %s (version=%r)' % (target,version)\n f = open(target,'w')\n f.write('version = %r\\n' % (version))\n f.close()\n\n import atexit\n def rm_file(f=target):\n try: os.remove(f); print 'removed',f\n except OSError: pass\n try: os.remove(f+'c'); print 'removed',f+'c'\n except OSError: pass\n atexit.register(rm_file)\n\n return target\n\n self.add_data_files((self.path_in_package, generate_svn_version_py()))\n return\n\n def make_config_py(self,name='__config__'):\n \"\"\" Generate package __config__.py file containing system_info\n information used during building the package.\n \"\"\"\n self.py_modules.append((self.name,name,generate_config_py))\n return\n\n def get_info(self,*names):\n \"\"\" Get resources information.\n \"\"\"\n from system_info import get_info, dict_append\n info_dict = {}\n for a in names:\n dict_append(info_dict,**get_info(a))\n return info_dict\n\ndef get_cmd(cmdname,_cache={}):\n if not _cache.has_key(cmdname):\n import distutils.core\n dist = distutils.core._setup_distribution\n if dist is None:\n from distutils.errors import DistutilsInternalError\n raise DistutilsInternalError,\\\n 'setup distribution instance not initialized'\n cmd = dist.get_command_obj(cmdname)\n _cache[cmdname] = cmd\n return _cache[cmdname]\n\ndef get_numpy_include_dirs():\n # numpy_include_dirs are set by numpy/core/setup.py, otherwise []\n include_dirs = Configuration.numpy_include_dirs[:]\n if not include_dirs:\n import numpy\n if numpy.show_config is None:\n # running from numpy_core source directory\n include_dirs.append(njoin(os.path.dirname(numpy.__file__),\n 'core','include'))\n else:\n # using installed numpy core headers\n import numpy.core as core\n include_dirs.append(njoin(os.path.dirname(core.__file__),'include'))\n # else running numpy/core/setup.py\n return include_dirs\n\n#########################\n\ndef default_config_dict(name = None, parent_name = None, local_path=None):\n \"\"\" Return a configuration dictionary for usage in\n configuration() function defined in file setup_.py.\n \"\"\"\n import warnings\n warnings.warn('Use Configuration(%s,%s,top_path=%s) instead of '\\\n 'deprecated default_config_dict(%s,%s,%s)' \\\n % (`name`,`parent_name`,`local_path`,\n `name`,`parent_name`,`local_path`,\n ))\n c = Configuration(name, parent_name, local_path)\n return c.todict()\n\n\ndef dict_append(d,**kws):\n for k,v in kws.items():\n if d.has_key(k):\n d[k].extend(v)\n else:\n d[k] = v\n\ndef appendpath(prefix,path):\n if not ('/' == os.path.sep):\n prefix = prefix.replace('/',os.path.sep)\n path = path.replace('/',os.path.sep)\n drive = ''\n if os.path.isabs(path):\n drive = os.path.splitdrive(prefix)[0]\n absprefix = os.path.splitdrive(os.path.abspath(prefix))[1]\n pathdrive,path = os.path.splitdrive(path)\n d = os.path.commonprefix([absprefix,path])\n if os.path.join(absprefix[:len(d)],absprefix[len(d):])!=absprefix \\\n or os.path.join(path[:len(d)],path[len(d):])!=path:\n # Handle invalid paths\n d = os.path.dirname(d)\n subpath = path[len(d):]\n if os.path.isabs(subpath):\n subpath = subpath[1:]\n else:\n subpath = path\n return os.path.normpath(njoin(drive + prefix, subpath))\n\n\n\n\n\ndef generate_config_py(target):\n \"\"\" Generate config.py file containing system_info information\n used during building the package.\n\n Usage:\\\n config['py_modules'].append((packagename, '__config__',generate_config_py))\n \"\"\"\n from numpy.distutils.system_info import system_info\n from distutils.dir_util import mkpath\n mkpath(os.path.dirname(target))\n f = open(target,'w')\n f.write('# This file is generated by %s\\n' % (os.path.abspath(sys.argv[0])))\n f.write('# It contains system_info results at the time of building this package.\\n')\n f.write('__all__ = [\"get_info\",\"show\"]\\n\\n')\n for k,i in system_info.saved_results.items():\n f.write('%s=%r\\n' % (k,i))\n f.write('\\ndef get_info(name): g=globals(); return g.get(name,g.get(name+\"_info\",{}))\\n')\n f.write('''\ndef show():\n for name,info_dict in globals().items():\n if name[0]==\"_\" or type(info_dict) is not type({}): continue\n print name+\":\"\n if not info_dict:\n print \" NOT AVAILABLE\"\n for k,v in info_dict.items():\n v = str(v)\n if k==\\'sources\\' and len(v)>200: v = v[:60]+\\' ...\\\\n... \\'+v[-60:]\n print \\' %s = %s\\'%(k,v)\n print\n return\n ''')\n\n f.close()\n return target\n\ndef generate_svn_version_py(extension, build_dir):\n \"\"\" Generate __svn_version__.py file containing SVN\n revision number of a module.\n\n To use, add the following codelet to setup\n configuration(..) function\n\n ext = Extension(dot_join(config['name'],'__svn_version__'),\n sources=[generate_svn_version_py])\n ext.local_path = local_path\n config['ext_modules'].append(ext)\n\n \"\"\"\n from distutils import dep_util\n local_path = extension.local_path\n target = njoin(build_dir, '__svn_version__.py')\n entries = njoin(local_path,'.svn','entries')\n if os.path.isfile(entries):\n if not dep_util.newer(entries, target):\n return target\n elif os.path.isfile(target):\n return target\n\n revision = get_svn_revision(local_path)\n f = open(target,'w')\n f.write('revision=%s\\n' % (revision))\n f.close()\n return target\n", + "source_code_before": "import os\nimport re\nimport sys\nimport imp\nimport copy\nimport glob\n\n__all__ = ['Configuration', 'get_numpy_include_dirs', 'default_config_dict',\n 'dict_append', 'appendpath', 'generate_config_py',\n 'generate_svn_version_py', 'get_cmd', 'allpath',\n 'terminal_has_colors', 'red_text', 'green_text', 'yellow_text',\n 'blue_text', 'cyan_text', 'cyg2win32', 'all_strings',\n 'has_f_sources', 'has_cxx_sources', 'filter_sources',\n 'get_dependencies', 'is_local_src_dir', 'get_ext_source_files',\n 'get_script_files', 'get_lib_source_files', 'get_data_files',\n 'dot_join', 'get_frame']\n\ndef allpath(name):\n \"Convert a /-separated pathname to one using the OS's path separator.\"\n splitted = name.split('/')\n return os.path.join(*splitted)\n\ndef get_path(mod_name,parent_path=None):\n \"\"\" Return path of the module.\n\n Returned path is relative to parent_path when given,\n otherwise it is absolute path.\n \"\"\"\n if mod_name == '__main__':\n d = os.path.abspath('.')\n elif mod_name == '__builtin__':\n #builtin if/then added by Pearu for use in core.run_setup.\n d = os.path.dirname(os.path.abspath(sys.argv[0]))\n else:\n __import__(mod_name)\n mod = sys.modules[mod_name]\n file = mod.__file__\n d = os.path.dirname(os.path.abspath(file))\n if parent_path is not None:\n pd = os.path.abspath(parent_path)\n if pd==d[:len(pd)]:\n d = d[len(pd)+1:]\n return d or '.'\n\n# Hooks for colored terminal output.\n# See also http://www.livinglogic.de/Python/ansistyle\ndef terminal_has_colors():\n if sys.platform=='cygwin' and not os.environ.has_key('USE_COLOR'):\n # Avoid importing curses that causes illegal operation\n # with a message:\n # PYTHON2 caused an invalid page fault in\n # module CYGNURSES7.DLL as 015f:18bbfc28\n # Details: Python 2.3.3 [GCC 3.3.1 (cygming special)]\n # ssh to Win32 machine from debian\n # curses.version is 2.2\n # CYGWIN_98-4.10, release 1.5.7(0.109/3/2))\n return 0\n if hasattr(sys.stdout,'isatty') and sys.stdout.isatty():\n try:\n import curses\n curses.setupterm()\n if (curses.tigetnum(\"colors\") >= 0\n and curses.tigetnum(\"pairs\") >= 0\n and ((curses.tigetstr(\"setf\") is not None\n and curses.tigetstr(\"setb\") is not None)\n or (curses.tigetstr(\"setaf\") is not None\n and curses.tigetstr(\"setab\") is not None)\n or curses.tigetstr(\"scp\") is not None)):\n return 1\n except Exception,msg:\n pass\n return 0\n\nif terminal_has_colors():\n def red_text(s): return '\\x1b[31m%s\\x1b[0m'%s\n def green_text(s): return '\\x1b[32m%s\\x1b[0m'%s\n def yellow_text(s): return '\\x1b[33m%s\\x1b[0m'%s\n def blue_text(s): return '\\x1b[34m%s\\x1b[0m'%s\n def cyan_text(s): return '\\x1b[35m%s\\x1b[0m'%s\nelse:\n def red_text(s): return s\n def green_text(s): return s\n def yellow_text(s): return s\n def cyan_text(s): return s\n def blue_text(s): return s\n\n#########################\n\ndef cyg2win32(path):\n if sys.platform=='cygwin' and path.startswith('/cygdrive'):\n path = path[10] + ':' + os.path.normcase(path[11:])\n return path\n\n#########################\n\n#XXX need support for .C that is also C++\ncxx_ext_match = re.compile(r'.*[.](cpp|cxx|cc)\\Z',re.I).match\nfortran_ext_match = re.compile(r'.*[.](f90|f95|f77|for|ftn|f)\\Z',re.I).match\nf90_ext_match = re.compile(r'.*[.](f90|f95)\\Z',re.I).match\nf90_module_name_match = re.compile(r'\\s*module\\s*(?P[\\w_]+)',re.I).match\ndef _get_f90_modules(source):\n \"\"\" Return a list of Fortran f90 module names that\n given source file defines.\n \"\"\"\n if not f90_ext_match(source):\n return []\n modules = []\n f = open(source,'r')\n f_readlines = getattr(f,'xreadlines',f.readlines)\n for line in f_readlines():\n m = f90_module_name_match(line)\n if m:\n name = m.group('name')\n modules.append(name)\n # break # XXX can we assume that there is one module per file?\n f.close()\n return modules\n\ndef is_string(s):\n return isinstance(s, str)\n\ndef all_strings(lst):\n \"\"\" Return True if all items in lst are string objects. \"\"\"\n for item in lst:\n if not is_string(item):\n return False\n return True\n\ndef is_sequence(seq):\n if is_string(seq):\n return False\n try:\n len(seq)\n except:\n return False\n return True\n\ndef has_f_sources(sources):\n \"\"\" Return True if sources contains Fortran files \"\"\"\n for source in sources:\n if fortran_ext_match(source):\n return True\n return False\n\ndef has_cxx_sources(sources):\n \"\"\" Return True if sources contains C++ files \"\"\"\n for source in sources:\n if cxx_ext_match(source):\n return True\n return False\n\ndef filter_sources(sources):\n \"\"\" Return four lists of filenames containing\n C, C++, Fortran, and Fortran 90 module sources,\n respectively.\n \"\"\"\n c_sources = []\n cxx_sources = []\n f_sources = []\n fmodule_sources = []\n for source in sources:\n if fortran_ext_match(source):\n modules = _get_f90_modules(source)\n if modules:\n fmodule_sources.append(source)\n else:\n f_sources.append(source)\n elif cxx_ext_match(source):\n cxx_sources.append(source)\n else:\n c_sources.append(source)\n return c_sources, cxx_sources, f_sources, fmodule_sources\n\n\ndef _get_headers(directory_list):\n # get *.h files from list of directories\n headers = []\n for dir in directory_list:\n head = glob.glob(os.path.join(dir,\"*.h\")) #XXX: *.hpp files??\n headers.extend(head)\n return headers\n\ndef _get_directories(list_of_sources):\n # get unique directories from list of sources.\n direcs = []\n for file in list_of_sources:\n dir = os.path.split(file)\n if dir[0] != '' and not dir[0] in direcs:\n direcs.append(dir[0])\n return direcs\n\ndef get_dependencies(sources):\n #XXX scan sources for include statements\n return _get_headers(_get_directories(sources))\n\ndef is_local_src_dir(directory):\n \"\"\" Return true if directory is local directory.\n \"\"\"\n if not is_string(directory):\n return False\n abs_dir = os.path.abspath(directory)\n c = os.path.commonprefix([os.getcwd(),abs_dir])\n new_dir = abs_dir[len(c):].split(os.sep)\n if new_dir and not new_dir[0]:\n new_dir = new_dir[1:]\n if new_dir and new_dir[0]=='build':\n return False\n new_dir = os.sep.join(new_dir)\n return os.path.isdir(new_dir)\n\ndef _gsf_visit_func(filenames,dirname,names):\n if os.path.basename(dirname) in ['CVS','.svn','build']:\n names[:] = []\n return\n for name in names:\n if name[-1] in \"~#\":\n continue\n fullname = os.path.join(dirname,name)\n ext = os.path.splitext(fullname)[1]\n if ext and ext in ['.pyc','.o']:\n continue\n if os.path.isfile(fullname):\n filenames.append(fullname)\n\ndef get_ext_source_files(ext):\n # Get sources and any include files in the same directory.\n filenames = []\n sources = filter(is_string, ext.sources)\n filenames.extend(sources)\n filenames.extend(get_dependencies(sources))\n for d in ext.depends:\n if is_local_src_dir(d):\n os.path.walk(d,_gsf_visit_func,filenames)\n elif os.path.isfile(d):\n filenames.append(d)\n return filenames\n\ndef get_script_files(scripts):\n scripts = filter(is_string, scripts)\n return scripts\n\ndef get_lib_source_files(lib):\n filenames = []\n sources = lib[1].get('sources',[])\n sources = filter(is_string, sources)\n filenames.extend(sources)\n filenames.extend(get_dependencies(sources))\n depends = lib[1].get('depends',[])\n for d in depends:\n if is_local_src_dir(d):\n os.path.walk(d,_gsf_visit_func,filenames)\n elif os.path.isfile(d):\n filenames.append(d)\n return filenames\n\ndef get_data_files(data):\n if is_string(data):\n return [data]\n sources = data[1]\n filenames = []\n for s in sources:\n if callable(s):\n continue\n if is_local_src_dir(s):\n os.path.walk(s,_gsf_visit_func,filenames)\n elif is_string(s):\n if os.path.isfile(s):\n filenames.append(s)\n else:\n print 'Not existing data file:',s\n else:\n raise TypeError,repr(s)\n return filenames\n\ndef dot_join(*args):\n return '.'.join(filter(None,args))\n\ndef get_frame(level=0):\n try:\n return sys._getframe(level+1)\n except AttributeError:\n frame = sys.exc_info()[2].tb_frame\n for i in range(level+1):\n frame = frame.f_back\n return frame\n\n######################\n\nclass Configuration:\n\n _list_keys = ['packages','ext_modules','data_files','include_dirs',\n 'libraries','headers','scripts','py_modules']\n _dict_keys = ['package_dir']\n\n numpy_include_dirs = []\n\n def __init__(self,\n package_name=None,\n parent_name=None,\n top_path=None,\n package_path=None,\n **attrs):\n \"\"\" Construct configuration instance of a package.\n\n package_name -- name of the package\n Ex.: 'distutils'\n parent_name -- name of the parent package\n Ex.: 'numpy'\n top_path -- directory of the toplevel package\n Ex.: the directory where the numpy package source sits\n package_path -- directory of package. Will be computed by magic from the\n directory of the caller module if not specified\n Ex.: the directory where numpy.distutils is\n \"\"\"\n self.name = dot_join(parent_name, package_name)\n\n caller_frame = get_frame(1)\n caller_name = eval('__name__',caller_frame.f_globals,caller_frame.f_locals)\n\n self.local_path = get_path(caller_name, top_path)\n if top_path is None:\n top_path = self.local_path\n if package_path is None:\n package_path = self.local_path\n elif os.path.isdir(os.path.join(self.local_path,package_path)):\n package_path = os.path.join(self.local_path,package_path)\n if not os.path.isdir(package_path):\n raise ValueError(\"%r is not a directory\" % (package_path,))\n self.top_path = top_path\n self.package_path = package_path\n # this is the relative path in the installed package\n self.path_in_package = os.path.join(*self.name.split('.'))\n\n self.list_keys = copy.copy(self._list_keys)\n self.dict_keys = copy.copy(self._dict_keys)\n\n for n in self.list_keys:\n setattr(self,n,copy.copy(attrs.get(n,[])))\n\n for n in self.dict_keys:\n setattr(self,n,copy.copy(attrs.get(n,{})))\n\n known_keys = self.list_keys + self.dict_keys\n self.extra_keys = []\n for n in attrs.keys():\n if n in known_keys:\n continue\n a = attrs[n]\n setattr(self,n,a)\n if isinstance(a, list):\n self.list_keys.append(n)\n elif isinstance(a, dict):\n self.dict_keys.append(n)\n else:\n self.extra_keys.append(n)\n\n if os.path.exists(os.path.join(package_path,'__init__.py')):\n self.packages.append(self.name)\n self.package_dir[self.name] = package_path\n return\n\n def todict(self):\n \"\"\" Return configuration distionary suitable for passing\n to distutils.core.setup() function.\n \"\"\"\n d = {}\n for n in self.list_keys + self.dict_keys + self.extra_keys:\n a = getattr(self,n)\n if a:\n d[n] = a\n if self.name:\n d['name'] = self.name\n return d\n\n def __dict__(self):\n return self.todict()\n\n def get_distribution(self):\n import distutils.core\n dist = distutils.core._setup_distribution\n return dist\n\n def get_subpackage(self,subpackage_name,subpackage_path=None):\n \"\"\" Return subpackage configuration.\n \"\"\"\n if subpackage_name is None:\n assert subpackage_path is not None\n subpackage_name = os.path.basename(subpackage_path)\n l = subpackage_name.split('.')\n if subpackage_path is None:\n subpackage_path = os.path.join(*([self.local_path]+l))\n if '*' in subpackage_name:\n dirs = filter(os.path.isdir,glob.glob(subpackage_path))\n config_list = []\n for d in dirs:\n if not os.path.isfile(os.path.join(d,'__init__.py')):\n continue\n n = '.'.join(d.split(os.sep)[-len(l):])\n c = self.get_subpackage(n)\n if c:\n config_list.append(c)\n return config_list\n else:\n subpackage_path = os.path.join(*([subpackage_path]+l[:-1]))\n subpackage_path = self._fix_paths([subpackage_path])[0]\n\n setup_py = os.path.join(subpackage_path,'setup.py')\n if not os.path.isfile(setup_py):\n setup_py = os.path.join(subpackage_path,'setup_%s.py' % (subpackage_name))\n\n if not os.path.isfile(setup_py):\n print 'Assuming default configuration '\\\n '(%s/{setup_%s,setup}.py was not found)' \\\n % (os.path.dirname(setup_py),subpackage_name)\n config = Configuration(subpackage_name,self.name,\n self.top_path,subpackage_path)\n else:\n # In case setup_py imports local modules:\n sys.path.insert(0,os.path.dirname(setup_py))\n try:\n info = (open(setup_py),setup_py,('.py','U',1))\n setup_name = os.path.splitext(os.path.basename(setup_py))[0]\n n = dot_join(self.name,setup_name)\n setup_module = imp.load_module('_'.join(n.split('.')),*info)\n\n if not hasattr(setup_module,'configuration'):\n print 'Assuming default configuration '\\\n '(%s does not define configuration())' % (setup_module)\n config = Configuration(subpackage_name,self.name,\n self.top_path,subpackage_path)\n else:\n args = (self.name,)\n if setup_module.configuration.func_code.co_argcount>1:\n args = args + (self.top_path,)\n config = setup_module.configuration(*args)\n\n finally:\n del sys.path[0]\n\n return config\n\n def add_subpackage(self,subpackage_name,subpackage_path=None):\n \"\"\" Add subpackage to configuration.\n \"\"\"\n config = self.get_subpackage(subpackage_name,subpackage_path)\n if not isinstance(config, list):\n config_list = [config]\n else:\n config_list = config\n for config in config_list:\n if not config:\n print 'No configuration returned, assuming unavailable.'\n else:\n if isinstance(config,Configuration):\n print 'Appending %s configuration to %s' % (config.name,self.name)\n self.dict_append(**config.todict())\n else:\n print 'Appending %s configuration to %s' % (config.get('name'),self.name)\n self.dict_append(**config)\n\n dist = self.get_distribution()\n if dist is not None:\n print 'distutils distribution has been initialized, it may be too late to add a subpackage', subpackage_name\n return\n\n def add_data_dir(self,data_path):\n \"\"\" Recursively add files under data_path to data_files list.\n Argument can be either\n - 2-sequence (,)\n - path to data directory where python datadir suffix defaults\n to package dir.\n If path is not absolute then it's datadir suffix is\n package dir + subdirname of the path.\n \"\"\"\n if is_sequence(data_path):\n d, data_path = data_path\n else:\n d = None\n if not is_string(data_path):\n raise TypeError(\"not a string: %r\" % (data_path,))\n for path in self.paths(data_path):\n if not os.path.exists(path):\n print 'Not existing data path',path\n continue\n filenames = []\n os.path.walk(path, _gsf_visit_func,filenames)\n if not os.path.isabs(path):\n if d is None:\n d = self.path_in_package\n ds = os.path.join(d, data_path)\n self.add_data_files((ds,filenames))\n else:\n if d is None:\n self.add_data_files(*filenames)\n else:\n self.add_data_files((d,filenames))\n return\n\n def add_data_files(self,*files):\n \"\"\" Add data files to configuration data_files.\n Argument(s) can be either\n - 2-sequence (,)\n - paths to data files where python datadir prefix defaults\n to package dir.\n If path is not absolute then it's datadir prefix is\n package dir + dirname of the path.\n \"\"\"\n data_dict = {}\n new_files = []\n for p in files:\n if not is_sequence(p):\n d = self.path_in_package\n if is_string(p) and not os.path.isabs(p):\n d = appendpath(d,os.path.dirname(p))\n p = (d,p)\n new_files.append(p)\n files = []\n for prefix,filepattern in new_files:\n if is_string(filepattern):\n file_list = self.paths(filepattern)\n elif callable(filepattern):\n file_list = [filepattern]\n else:\n file_list = self.paths(*filepattern)\n\n nof_path_components = [len(f.split(os.sep))\n for f in file_list if is_string(f)]\n if nof_path_components:\n min_path_components = min(nof_path_components)-1\n else:\n min_path_components = 0\n\n for f in file_list:\n if is_string(f):\n extra_path_components = f.split(os.sep)[min_path_components:-1]\n p = os.path.join(*([prefix]+extra_path_components))\n else:\n p = prefix\n if not data_dict.has_key(p):\n data_dict[p] = [f]\n else:\n data_dict[p].append(f)\n\n dist = self.get_distribution()\n if dist is not None:\n dist.data_files.extend(data_dict.items())\n else:\n self.data_files.extend(data_dict.items())\n\n ### XXX Implement add_py_modules\n\n def add_include_dirs(self,*paths):\n \"\"\" Add paths to configuration include directories.\n \"\"\"\n include_dirs = self._fix_paths(paths)\n dist = self.get_distribution()\n if dist is not None:\n dist.include_dirs.extend(include_dirs)\n else:\n self.include_dirs.extend(include_dirs)\n return\n\n def add_headers(self,*files):\n \"\"\" Add installable headers to configuration.\n Argument(s) can be either\n - 2-sequence (,)\n - path(s) to header file(s) where python includedir suffix will default\n to package name.\n \"\"\"\n headers = []\n for path in files:\n if is_string(path):\n [headers.append((self.name,p)) for p in self.paths(path)]\n else:\n if not isinstance(path, (tuple, list)) or len(path) != 2:\n raise TypeError(repr(path))\n [headers.append((path[0],p)) for p in self.paths(path[1])]\n dist = self.get_distribution()\n if dist is not None:\n dist.headers.extend(headers)\n else:\n self.headers.extend(headers)\n return\n\n def _fix_paths(self,paths):\n new_paths = []\n for n in paths:\n if isinstance(n,str):\n if '*' in n or '?' in n:\n p = glob.glob(n)\n p2 = glob.glob(os.path.join(self.local_path,n))\n if p2:\n new_paths.extend(p2)\n elif p:\n new_paths.extend(p)\n else:\n new_paths.append(n)\n else:\n n2 = os.path.join(self.local_path,n)\n if os.path.exists(n2):\n new_paths.append(n2)\n else:\n new_paths.append(n)\n else:\n new_paths.append(n)\n return new_paths\n\n def paths(self,*paths):\n \"\"\" Apply glob to paths and prepend local_path if needed.\n \"\"\"\n return self._fix_paths(paths)\n\n def add_extension(self,name,sources,**kw):\n \"\"\" Add extension to configuration.\n\n Keywords:\n include_dirs, define_macros, undef_macros,\n library_dirs, libraries, runtime_library_dirs,\n extra_objects, extra_compile_args, extra_link_args,\n export_symbols, swig_opts, depends, language,\n f2py_options, module_dirs\n extra_info - dict or list of dict of keywords to be\n appended to keywords.\n \"\"\"\n ext_args = copy.copy(kw)\n ext_args['name'] = dot_join(self.name,name)\n ext_args['sources'] = sources\n\n if ext_args.has_key('extra_info'):\n extra_info = ext_args['extra_info']\n del ext_args['extra_info']\n if type(extra_info) is type({}):\n extra_info = [extra_info]\n for info in extra_info:\n assert type(info) is type({}),`info`\n dict_append(ext_args,**info)\n\n for k in ext_args.keys():\n v = ext_args[k]\n if k in ['sources','depends','include_dirs','library_dirs',\n 'module_dirs','extra_objects']:\n new_v = self._fix_paths(v)\n ext_args[k] = new_v\n\n # Resolve out-of-tree dependencies\n libraries = ext_args.get('libraries',[])\n libnames = []\n ext_args['libraries'] = []\n for libname in libraries:\n if '@' in libname:\n lname,lpath = libname.split('@',1)\n lpath = os.path.abspath(os.path.join(self.local_path,lpath))\n if os.path.isdir(lpath):\n c = self.get_subpackage(None,lpath)\n if isinstance(c,Configuration):\n c = c.todict()\n for l in [l[0] for l in c.get('libraries',[])]:\n llname = l.split('__OF__',1)[0]\n if llname == lname:\n c.pop('name',None)\n dict_append(ext_args,**c)\n break\n continue\n libnames.append(libname)\n\n ext_args['libraries'] = libnames + ext_args['libraries']\n\n from numpy.distutils.core import Extension\n ext = Extension(**ext_args)\n self.ext_modules.append(ext)\n\n dist = self.get_distribution()\n if dist is not None:\n print 'distutils distribution has been initialized, it may be too late to add an extension', name\n return ext\n\n def add_library(self,name,sources,**build_info):\n \"\"\" Add library to configuration.\n\n Valid keywords for build_info:\n depends\n macros\n include_dirs\n extra_compiler_args\n f2py_options\n \"\"\"\n build_info = copy.copy(build_info)\n name = name #+ '__OF__' + self.name\n build_info['sources'] = sources\n\n for k in build_info.keys():\n v = build_info[k]\n if k in ['sources','depends','include_dirs','library_dirs',\n 'module_dirs','extra_objects']:\n new_v = self._fix_paths(v)\n build_info[k] = new_v\n self.libraries.append((name,build_info))\n\n dist = self.get_distribution()\n if dist is not None:\n print 'distutils distribution has been initialized, it may be too late to add a library', name\n return\n\n def add_scripts(self,*files):\n \"\"\" Add scripts to configuration.\n \"\"\"\n scripts = self._fix_paths(files)\n dist = self.get_distribution()\n if dist is not None:\n dist.scripts.extend(scripts)\n else:\n self.scripts.extend(scripts)\n return\n\n def dict_append(self,**dict):\n for key in self.list_keys:\n a = getattr(self,key)\n a.extend(dict.get(key,[]))\n for key in self.dict_keys:\n a = getattr(self,key)\n a.update(dict.get(key,{}))\n known_keys = self.list_keys + self.dict_keys + self.extra_keys\n for key in dict.keys():\n if key not in known_keys and not hasattr(self,key):\n print 'Inheriting attribute %r from %r' \\\n % (key,dict.get('name','?'))\n setattr(self,key,dict[key])\n self.extra_keys.append(key)\n return\n\n def __str__(self):\n known_keys = self.list_keys + self.dict_keys + self.extra_keys\n s = '<'+5*'-' + '\\n'\n s += 'Configuration of '+self.name+':\\n'\n for k in known_keys:\n a = getattr(self,k,None)\n if a:\n s += '%s = %r\\n' % (k,a)\n s += 5*'-' + '>'\n return s\n\n def get_config_cmd(self):\n cmd = get_cmd('config')\n cmd.ensure_finalized()\n cmd.dump_source = 0\n cmd.noisy = 0\n old_path = os.environ.get('PATH')\n if old_path:\n path = os.pathsep.join(['.',old_path])\n os.environ['PATH'] = path\n return cmd\n\n def get_build_temp_dir(self):\n cmd = get_cmd('build')\n cmd.ensure_finalized()\n return cmd.build_temp\n\n def have_f77c(self):\n \"\"\" Check for availability of Fortran 77 compiler.\n Use it inside source generating function to ensure that\n setup distribution instance has been initialized.\n \"\"\"\n simple_fortran_subroutine = '''\n subroutine simple\n end\n '''\n config_cmd = self.get_config_cmd()\n flag = config_cmd.try_compile(simple_fortran_subroutine,lang='f77')\n return flag\n\n def have_f90c(self):\n \"\"\" Check for availability of Fortran 90 compiler.\n Use it inside source generating function to ensure that\n setup distribution instance has been initialized.\n \"\"\"\n simple_fortran_subroutine = '''\n subroutine simple\n end\n '''\n config_cmd = self.get_config_cmd()\n flag = config_cmd.try_compile(simple_fortran_subroutine,lang='f90')\n return flag\n\n def append_to(self, extlib):\n \"\"\" Append libraries, include_dirs to extension or library item.\n \"\"\"\n if is_sequence(extlib):\n lib_name, build_info = extlib\n dict_append(build_info,\n libraries=self.libraries,\n include_dirs=self.include_dirs)\n else:\n from numpy.distutils.core import Extension\n assert isinstance(extlib,Extension),`extlib`\n extlib.libraries.extend(self.libraries)\n extlib.include_dirs.extend(self.include_dirs)\n return\n\n def _get_svn_revision(self,path):\n \"\"\" Return path's SVN revision number.\n \"\"\"\n entries = os.path.join(path,'.svn','entries')\n revision = None\n if os.path.isfile(entries):\n f = open(entries)\n m = re.search(r'revision=\"(?P\\d+)\"',f.read())\n f.close()\n if m:\n revision = int(m.group('revision'))\n return revision\n\n def get_version(self):\n \"\"\" Try to get version string of a package.\n \"\"\"\n version = getattr(self,'version',None)\n if version is not None:\n return version\n\n # Get version from version file.\n files = ['__version__.py',\n self.name.split('.')[-1]+'_version.py',\n 'version.py',\n '__svn_version__.py']\n version_vars = ['version',\n '__version__',\n self.name.split('.')[-1]+'_version']\n for f in files:\n fn = os.path.join(self.local_path,f)\n if os.path.isfile(fn):\n info = (open(fn),fn,('.py','U',1))\n name = os.path.splitext(os.path.basename(fn))[0]\n n = dot_join(self.name,name)\n try:\n version_module = imp.load_module('_'.join(n.split('.')),*info)\n except ImportError,msg:\n print msg\n version_module = None\n if version_module is None:\n continue\n\n for a in version_vars:\n version = getattr(version_module,a,None)\n if version is not None:\n break\n if version is not None:\n break\n\n if version is not None:\n self.version = version\n return version\n\n # Get version as SVN revision number\n revision = self._get_svn_revision(self.local_path)\n if revision is not None:\n version = str(revision)\n self.version = version\n\n return version\n\n def make_svn_version_py(self):\n \"\"\" Generate package __svn_version__.py file from SVN revision number,\n it will be removed after python exits but will be available\n when sdist, etc commands are executed.\n\n If __svn_version__.py existed before, nothing is done.\n \"\"\"\n target = os.path.join(self.local_path,'__svn_version__.py')\n if os.path.isfile(target):\n return\n\n def generate_svn_version_py():\n if not os.path.isfile(target):\n revision = self._get_svn_revision(self.local_path)\n assert revision is not None,'hmm, why I am not inside SVN tree???'\n version = str(revision)\n print 'Creating %s (version=%r)' % (target,version)\n f = open(target,'w')\n f.write('version = %r\\n' % (version))\n f.close()\n\n import atexit\n def rm_file(f=target):\n try: os.remove(f); print 'removed',f\n except OSError: pass\n try: os.remove(f+'c'); print 'removed',f+'c'\n except OSError: pass\n atexit.register(rm_file)\n\n return target\n\n self.add_data_files(generate_svn_version_py())\n return\n\n def make_config_py(self,name='__config__'):\n \"\"\" Generate package __config__.py file containing system_info\n information used during building the package.\n \"\"\"\n self.py_modules.append((self.name,name,generate_config_py))\n return\n\n def get_info(self,*names):\n \"\"\" Get resources information.\n \"\"\"\n from system_info import get_info, dict_append\n info_dict = {}\n for a in names:\n dict_append(info_dict,**get_info(a))\n return info_dict\n\ndef get_cmd(cmdname,_cache={}):\n if not _cache.has_key(cmdname):\n import distutils.core\n dist = distutils.core._setup_distribution\n if dist is None:\n from distutils.errors import DistutilsInternalError\n raise DistutilsInternalError,\\\n 'setup distribution instance not initialized'\n cmd = dist.get_command_obj(cmdname)\n _cache[cmdname] = cmd\n return _cache[cmdname]\n\ndef get_numpy_include_dirs():\n # numpy_include_dirs are set by numpy/core/setup.py, otherwise []\n include_dirs = Configuration.numpy_include_dirs[:]\n if not include_dirs:\n import numpy\n if numpy.show_config is None:\n # running from numpy_core source directory\n include_dirs.append(os.path.join(os.path.dirname(numpy.__file__),\n 'core','include'))\n else:\n # using installed numpy core headers\n import numpy.core as core\n include_dirs.append(os.path.join(os.path.dirname(core.__file__),'include'))\n # else running numpy/core/setup.py\n return include_dirs\n\n#########################\n\ndef default_config_dict(name = None, parent_name = None, local_path=None):\n \"\"\" Return a configuration dictionary for usage in\n configuration() function defined in file setup_.py.\n \"\"\"\n import warnings\n warnings.warn('Use Configuration(%s,%s,top_path=%s) instead of '\\\n 'deprecated default_config_dict(%s,%s,%s)' \\\n % (`name`,`parent_name`,`local_path`,\n `name`,`parent_name`,`local_path`,\n ))\n c = Configuration(name, parent_name, local_path)\n return c.todict()\n\n\ndef dict_append(d,**kws):\n for k,v in kws.items():\n if d.has_key(k):\n d[k].extend(v)\n else:\n d[k] = v\n\ndef appendpath(prefix,path):\n if not ('/' == os.path.sep):\n prefix = prefix.replace('/',os.path.sep)\n path = path.replace('/',os.path.sep)\n drive = ''\n if os.path.isabs(path):\n drive = os.path.splitdrive(prefix)[0]\n absprefix = os.path.splitdrive(os.path.abspath(prefix))[1]\n pathdrive,path = os.path.splitdrive(path)\n d = os.path.commonprefix([absprefix,path])\n if os.path.join(absprefix[:len(d)],absprefix[len(d):])!=absprefix \\\n or os.path.join(path[:len(d)],path[len(d):])!=path:\n # Handle invalid paths\n d = os.path.dirname(d)\n subpath = path[len(d):]\n if os.path.isabs(subpath):\n subpath = subpath[1:]\n else:\n subpath = path\n return os.path.normpath(os.path.join(drive + prefix, subpath))\n\ndef generate_config_py(target):\n \"\"\" Generate config.py file containing system_info information\n used during building the package.\n\n Usage:\\\n config['py_modules'].append((packagename, '__config__',generate_config_py))\n \"\"\"\n from numpy.distutils.system_info import system_info\n from distutils.dir_util import mkpath\n mkpath(os.path.dirname(target))\n f = open(target,'w')\n f.write('# This file is generated by %s\\n' % (os.path.abspath(sys.argv[0])))\n f.write('# It contains system_info results at the time of building this package.\\n')\n f.write('__all__ = [\"get_info\",\"show\"]\\n\\n')\n for k,i in system_info.saved_results.items():\n f.write('%s=%r\\n' % (k,i))\n f.write('\\ndef get_info(name): g=globals(); return g.get(name,g.get(name+\"_info\",{}))\\n')\n f.write('''\ndef show():\n for name,info_dict in globals().items():\n if name[0]==\"_\" or type(info_dict) is not type({}): continue\n print name+\":\"\n if not info_dict:\n print \" NOT AVAILABLE\"\n for k,v in info_dict.items():\n v = str(v)\n if k==\\'sources\\' and len(v)>200: v = v[:60]+\\' ...\\\\n... \\'+v[-60:]\n print \\' %s = %s\\'%(k,v)\n print\n return\n ''')\n\n f.close()\n return target\n\ndef generate_svn_version_py(extension, build_dir):\n \"\"\" Generate __svn_version__.py file containing SVN\n revision number of a module.\n\n To use, add the following codelet to setup\n configuration(..) function\n\n ext = Extension(dot_join(config['name'],'__svn_version__'),\n sources=[generate_svn_version_py])\n ext.local_path = local_path\n config['ext_modules'].append(ext)\n\n \"\"\"\n from distutils import dep_util\n local_path = extension.local_path\n target = os.path.join(build_dir, '__svn_version__.py')\n entries = os.path.join(local_path,'.svn','entries')\n if os.path.isfile(entries):\n if not dep_util.newer(entries, target):\n return target\n elif os.path.isfile(target):\n return target\n\n revision = get_svn_revision(local_path)\n f = open(target,'w')\n f.write('revision=%s\\n' % (revision))\n f.close()\n return target\n", + "methods": [ + { + "name": "allpath", + "long_name": "allpath( name )", + "filename": "misc_util.py", + "nloc": 4, + "complexity": 1, + "token_count": 24, + "parameters": [ + "name" + ], + "start_line": 18, + "end_line": 21, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 4, + "top_nesting_level": 0 + }, + { + "name": "get_path", + "long_name": "get_path( mod_name , parent_path = None )", + "filename": "misc_util.py", + "nloc": 15, + "complexity": 6, + "token_count": 132, + "parameters": [ + "mod_name", + "parent_path" + ], + "start_line": 23, + "end_line": 43, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 21, + "top_nesting_level": 0 + }, + { + "name": "njoin", + "long_name": "njoin( * path )", + "filename": "misc_util.py", + "nloc": 7, + "complexity": 4, + "token_count": 68, + "parameters": [ + "path" + ], + "start_line": 45, + "end_line": 55, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 11, + "top_nesting_level": 0 + }, + { + "name": "minrelpath", + "long_name": "minrelpath( path )", + "filename": "misc_util.py", + "nloc": 17, + "complexity": 7, + "token_count": 103, + "parameters": [ + "path" + ], + "start_line": 57, + "end_line": 75, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 19, + "top_nesting_level": 0 + }, + { + "name": "terminal_has_colors", + "long_name": "terminal_has_colors( )", + "filename": "misc_util.py", + "nloc": 18, + "complexity": 13, + "token_count": 137, + "parameters": [], + "start_line": 79, + "end_line": 104, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 26, + "top_nesting_level": 0 + }, + { + "name": "cyg2win32", + "long_name": "cyg2win32( path )", + "filename": "misc_util.py", + "nloc": 4, + "complexity": 3, + "token_count": 42, + "parameters": [ + "path" + ], + "start_line": 121, + "end_line": 124, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 4, + "top_nesting_level": 0 + }, + { + "name": "_get_f90_modules", + "long_name": "_get_f90_modules( source )", + "filename": "misc_util.py", + "nloc": 13, + "complexity": 4, + "token_count": 77, + "parameters": [ + "source" + ], + "start_line": 133, + "end_line": 149, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 17, + "top_nesting_level": 0 + }, + { + "name": "is_string", + "long_name": "is_string( s )", + "filename": "misc_util.py", + "nloc": 2, + "complexity": 1, + "token_count": 12, + "parameters": [ + "s" + ], + "start_line": 151, + "end_line": 152, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 2, + "top_nesting_level": 0 + }, + { + "name": "all_strings", + "long_name": "all_strings( lst )", + "filename": "misc_util.py", + "nloc": 5, + "complexity": 3, + "token_count": 22, + "parameters": [ + "lst" + ], + "start_line": 154, + "end_line": 159, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 6, + "top_nesting_level": 0 + }, + { + "name": "is_sequence", + "long_name": "is_sequence( seq )", + "filename": "misc_util.py", + "nloc": 8, + "complexity": 3, + "token_count": 25, + "parameters": [ + "seq" + ], + "start_line": 161, + "end_line": 168, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 8, + "top_nesting_level": 0 + }, + { + "name": "has_f_sources", + "long_name": "has_f_sources( sources )", + "filename": "misc_util.py", + "nloc": 5, + "complexity": 3, + "token_count": 21, + "parameters": [ + "sources" + ], + "start_line": 170, + "end_line": 175, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 6, + "top_nesting_level": 0 + }, + { + "name": "has_cxx_sources", + "long_name": "has_cxx_sources( sources )", + "filename": "misc_util.py", + "nloc": 5, + "complexity": 3, + "token_count": 21, + "parameters": [ + "sources" + ], + "start_line": 177, + "end_line": 182, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 6, + "top_nesting_level": 0 + }, + { + "name": "filter_sources", + "long_name": "filter_sources( sources )", + "filename": "misc_util.py", + "nloc": 17, + "complexity": 5, + "token_count": 84, + "parameters": [ + "sources" + ], + "start_line": 184, + "end_line": 204, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 21, + "top_nesting_level": 0 + }, + { + "name": "_get_headers", + "long_name": "_get_headers( directory_list )", + "filename": "misc_util.py", + "nloc": 6, + "complexity": 2, + "token_count": 39, + "parameters": [ + "directory_list" + ], + "start_line": 207, + "end_line": 213, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 7, + "top_nesting_level": 0 + }, + { + "name": "_get_directories", + "long_name": "_get_directories( list_of_sources )", + "filename": "misc_util.py", + "nloc": 7, + "complexity": 4, + "token_count": 51, + "parameters": [ + "list_of_sources" + ], + "start_line": 215, + "end_line": 222, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 8, + "top_nesting_level": 0 + }, + { + "name": "get_dependencies", + "long_name": "get_dependencies( sources )", + "filename": "misc_util.py", + "nloc": 2, + "complexity": 1, + "token_count": 13, + "parameters": [ + "sources" + ], + "start_line": 224, + "end_line": 226, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 3, + "top_nesting_level": 0 + }, + { + "name": "is_local_src_dir", + "long_name": "is_local_src_dir( directory )", + "filename": "misc_util.py", + "nloc": 12, + "complexity": 6, + "token_count": 107, + "parameters": [ + "directory" + ], + "start_line": 228, + "end_line": 241, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 14, + "top_nesting_level": 0 + }, + { + "name": "_gsf_visit_func", + "long_name": "_gsf_visit_func( filenames , dirname , names )", + "filename": "misc_util.py", + "nloc": 13, + "complexity": 7, + "token_count": 103, + "parameters": [ + "filenames", + "dirname", + "names" + ], + "start_line": 243, + "end_line": 255, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 13, + "top_nesting_level": 0 + }, + { + "name": "get_ext_source_files", + "long_name": "get_ext_source_files( ext )", + "filename": "misc_util.py", + "nloc": 11, + "complexity": 4, + "token_count": 77, + "parameters": [ + "ext" + ], + "start_line": 257, + "end_line": 268, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 12, + "top_nesting_level": 0 + }, + { + "name": "get_script_files", + "long_name": "get_script_files( scripts )", + "filename": "misc_util.py", + "nloc": 3, + "complexity": 1, + "token_count": 15, + "parameters": [ + "scripts" + ], + "start_line": 270, + "end_line": 272, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 3, + "top_nesting_level": 0 + }, + { + "name": "get_lib_source_files", + "long_name": "get_lib_source_files( lib )", + "filename": "misc_util.py", + "nloc": 13, + "complexity": 4, + "token_count": 101, + "parameters": [ + "lib" + ], + "start_line": 274, + "end_line": 286, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 13, + "top_nesting_level": 0 + }, + { + "name": "get_data_files", + "long_name": "get_data_files( data )", + "filename": "misc_util.py", + "nloc": 18, + "complexity": 7, + "token_count": 94, + "parameters": [ + "data" + ], + "start_line": 288, + "end_line": 305, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 18, + "top_nesting_level": 0 + }, + { + "name": "dot_join", + "long_name": "dot_join( * args )", + "filename": "misc_util.py", + "nloc": 2, + "complexity": 1, + "token_count": 18, + "parameters": [ + "args" + ], + "start_line": 307, + "end_line": 308, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 2, + "top_nesting_level": 0 + }, + { + "name": "get_frame", + "long_name": "get_frame( level = 0 )", + "filename": "misc_util.py", + "nloc": 8, + "complexity": 3, + "token_count": 50, + "parameters": [ + "level" + ], + "start_line": 310, + "end_line": 317, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 8, + "top_nesting_level": 0 + }, + { + "name": "__init__", + "long_name": "__init__( self , package_name = None , parent_name = None , top_path = None , package_path = None , ** attrs )", + "filename": "misc_util.py", + "nloc": 44, + "complexity": 12, + "token_count": 365, + "parameters": [ + "self", + "package_name", + "parent_name", + "top_path", + "package_path", + "attrs" + ], + "start_line": 329, + "end_line": 393, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 65, + "top_nesting_level": 1 + }, + { + "name": "todict", + "long_name": "todict( self )", + "filename": "misc_util.py", + "nloc": 9, + "complexity": 4, + "token_count": 57, + "parameters": [ + "self" + ], + "start_line": 395, + "end_line": 406, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 12, + "top_nesting_level": 1 + }, + { + "name": "info", + "long_name": "info( self , message )", + "filename": "misc_util.py", + "nloc": 2, + "complexity": 1, + "token_count": 9, + "parameters": [ + "self", + "message" + ], + "start_line": 408, + "end_line": 409, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 2, + "top_nesting_level": 1 + }, + { + "name": "warn", + "long_name": "warn( self , message )", + "filename": "misc_util.py", + "nloc": 2, + "complexity": 1, + "token_count": 11, + "parameters": [ + "self", + "message" + ], + "start_line": 411, + "end_line": 412, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 2, + "top_nesting_level": 1 + }, + { + "name": "__dict__", + "long_name": "__dict__( self )", + "filename": "misc_util.py", + "nloc": 2, + "complexity": 1, + "token_count": 11, + "parameters": [ + "self" + ], + "start_line": 414, + "end_line": 415, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 2, + "top_nesting_level": 1 + }, + { + "name": "get_distribution", + "long_name": "get_distribution( self )", + "filename": "misc_util.py", + "nloc": 4, + "complexity": 1, + "token_count": 18, + "parameters": [ + "self" + ], + "start_line": 417, + "end_line": 420, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 4, + "top_nesting_level": 1 + }, + { + "name": "get_subpackage", + "long_name": "get_subpackage( self , subpackage_name , subpackage_path = None )", + "filename": "misc_util.py", + "nloc": 52, + "complexity": 13, + "token_count": 446, + "parameters": [ + "self", + "subpackage_name", + "subpackage_path" + ], + "start_line": 422, + "end_line": 480, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 59, + "top_nesting_level": 1 + }, + { + "name": "add_subpackage", + "long_name": "add_subpackage( self , subpackage_name , subpackage_path = None )", + "filename": "misc_util.py", + "nloc": 20, + "complexity": 6, + "token_count": 127, + "parameters": [ + "self", + "subpackage_name", + "subpackage_path" + ], + "start_line": 482, + "end_line": 504, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 23, + "top_nesting_level": 1 + }, + { + "name": "add_data_dir", + "long_name": "add_data_dir( self , data_path )", + "filename": "misc_util.py", + "nloc": 27, + "complexity": 9, + "token_count": 196, + "parameters": [ + "self", + "data_path" + ], + "start_line": 506, + "end_line": 540, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 35, + "top_nesting_level": 1 + }, + { + "name": "add_data_files", + "long_name": "add_data_files( self , * files )", + "filename": "misc_util.py", + "nloc": 46, + "complexity": 18, + "token_count": 320, + "parameters": [ + "self", + "files" + ], + "start_line": 542, + "end_line": 598, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 57, + "top_nesting_level": 1 + }, + { + "name": "add_include_dirs", + "long_name": "add_include_dirs( self , * paths )", + "filename": "misc_util.py", + "nloc": 8, + "complexity": 2, + "token_count": 49, + "parameters": [ + "self", + "paths" + ], + "start_line": 602, + "end_line": 611, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 10, + "top_nesting_level": 1 + }, + { + "name": "add_headers", + "long_name": "add_headers( self , * files )", + "filename": "misc_util.py", + "nloc": 15, + "complexity": 8, + "token_count": 136, + "parameters": [ + "self", + "files" + ], + "start_line": 613, + "end_line": 633, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 21, + "top_nesting_level": 1 + }, + { + "name": "_fix_paths", + "long_name": "_fix_paths( self , paths )", + "filename": "misc_util.py", + "nloc": 26, + "complexity": 9, + "token_count": 182, + "parameters": [ + "self", + "paths" + ], + "start_line": 635, + "end_line": 660, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 26, + "top_nesting_level": 1 + }, + { + "name": "paths", + "long_name": "paths( self , * paths )", + "filename": "misc_util.py", + "nloc": 2, + "complexity": 1, + "token_count": 16, + "parameters": [ + "self", + "paths" + ], + "start_line": 662, + "end_line": 665, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 4, + "top_nesting_level": 1 + }, + { + "name": "add_extension", + "long_name": "add_extension( self , name , sources , ** kw )", + "filename": "misc_util.py", + "nloc": 45, + "complexity": 14, + "token_count": 361, + "parameters": [ + "self", + "name", + "sources", + "kw" + ], + "start_line": 667, + "end_line": 729, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 63, + "top_nesting_level": 1 + }, + { + "name": "add_library", + "long_name": "add_library( self , name , sources , ** build_info )", + "filename": "misc_util.py", + "nloc": 15, + "complexity": 4, + "token_count": 106, + "parameters": [ + "self", + "name", + "sources", + "build_info" + ], + "start_line": 731, + "end_line": 756, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 26, + "top_nesting_level": 1 + }, + { + "name": "add_scripts", + "long_name": "add_scripts( self , * files )", + "filename": "misc_util.py", + "nloc": 8, + "complexity": 2, + "token_count": 49, + "parameters": [ + "self", + "files" + ], + "start_line": 758, + "end_line": 767, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 10, + "top_nesting_level": 1 + }, + { + "name": "dict_append", + "long_name": "dict_append( self , ** dict )", + "filename": "misc_util.py", + "nloc": 15, + "complexity": 6, + "token_count": 138, + "parameters": [ + "self", + "dict" + ], + "start_line": 769, + "end_line": 783, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 15, + "top_nesting_level": 1 + }, + { + "name": "__str__", + "long_name": "__str__( self )", + "filename": "misc_util.py", + "nloc": 10, + "complexity": 3, + "token_count": 72, + "parameters": [ + "self" + ], + "start_line": 785, + "end_line": 794, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 10, + "top_nesting_level": 1 + }, + { + "name": "get_config_cmd", + "long_name": "get_config_cmd( self )", + "filename": "misc_util.py", + "nloc": 10, + "complexity": 2, + "token_count": 63, + "parameters": [ + "self" + ], + "start_line": 796, + "end_line": 805, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 10, + "top_nesting_level": 1 + }, + { + "name": "get_build_temp_dir", + "long_name": "get_build_temp_dir( self )", + "filename": "misc_util.py", + "nloc": 4, + "complexity": 1, + "token_count": 20, + "parameters": [ + "self" + ], + "start_line": 807, + "end_line": 810, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 4, + "top_nesting_level": 1 + }, + { + "name": "have_f77c", + "long_name": "have_f77c( self )", + "filename": "misc_util.py", + "nloc": 8, + "complexity": 1, + "token_count": 30, + "parameters": [ + "self" + ], + "start_line": 812, + "end_line": 823, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 12, + "top_nesting_level": 1 + }, + { + "name": "have_f90c", + "long_name": "have_f90c( self )", + "filename": "misc_util.py", + "nloc": 8, + "complexity": 1, + "token_count": 30, + "parameters": [ + "self" + ], + "start_line": 825, + "end_line": 836, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 12, + "top_nesting_level": 1 + }, + { + "name": "append_to", + "long_name": "append_to( self , extlib )", + "filename": "misc_util.py", + "nloc": 12, + "complexity": 2, + "token_count": 77, + "parameters": [ + "self", + "extlib" + ], + "start_line": 838, + "end_line": 851, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 14, + "top_nesting_level": 1 + }, + { + "name": "_get_svn_revision", + "long_name": "_get_svn_revision( self , path )", + "filename": "misc_util.py", + "nloc": 10, + "complexity": 3, + "token_count": 73, + "parameters": [ + "self", + "path" + ], + "start_line": 853, + "end_line": 864, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 12, + "top_nesting_level": 1 + }, + { + "name": "get_version", + "long_name": "get_version( self )", + "filename": "misc_util.py", + "nloc": 38, + "complexity": 11, + "token_count": 253, + "parameters": [ + "self" + ], + "start_line": 866, + "end_line": 912, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 47, + "top_nesting_level": 1 + }, + { + "name": "make_svn_version_py.make_svn_version_py.generate_svn_version_py.rm_file", + "long_name": "make_svn_version_py.make_svn_version_py.generate_svn_version_py.rm_file( f = target )", + "filename": "misc_util.py", + "nloc": 5, + "complexity": 3, + "token_count": 45, + "parameters": [ + "f" + ], + "start_line": 936, + "end_line": 940, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 5, + "top_nesting_level": 3 + }, + { + "name": "make_svn_version_py.generate_svn_version_py", + "long_name": "make_svn_version_py.generate_svn_version_py( )", + "filename": "misc_util.py", + "nloc": 13, + "complexity": 2, + "token_count": 81, + "parameters": [], + "start_line": 925, + "end_line": 943, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 19, + "top_nesting_level": 2 + }, + { + "name": "make_svn_version_py", + "long_name": "make_svn_version_py( self )", + "filename": "misc_util.py", + "nloc": 7, + "complexity": 2, + "token_count": 44, + "parameters": [ + "self" + ], + "start_line": 914, + "end_line": 946, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 33, + "top_nesting_level": 1 + }, + { + "name": "make_config_py", + "long_name": "make_config_py( self , name = '__config__' )", + "filename": "misc_util.py", + "nloc": 3, + "complexity": 1, + "token_count": 27, + "parameters": [ + "self", + "name" + ], + "start_line": 948, + "end_line": 953, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 6, + "top_nesting_level": 1 + }, + { + "name": "get_info", + "long_name": "get_info( self , * names )", + "filename": "misc_util.py", + "nloc": 6, + "complexity": 2, + "token_count": 36, + "parameters": [ + "self", + "names" + ], + "start_line": 955, + "end_line": 962, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 8, + "top_nesting_level": 1 + }, + { + "name": "get_cmd", + "long_name": "get_cmd( cmdname , _cache = { } )", + "filename": "misc_util.py", + "nloc": 11, + "complexity": 3, + "token_count": 65, + "parameters": [ + "cmdname", + "_cache" + ], + "start_line": 964, + "end_line": 974, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 11, + "top_nesting_level": 0 + }, + { + "name": "get_numpy_include_dirs", + "long_name": "get_numpy_include_dirs( )", + "filename": "misc_util.py", + "nloc": 11, + "complexity": 3, + "token_count": 77, + "parameters": [], + "start_line": 976, + "end_line": 990, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 15, + "top_nesting_level": 0 + }, + { + "name": "default_config_dict", + "long_name": "default_config_dict( name = None , parent_name = None , local_path = None )", + "filename": "misc_util.py", + "nloc": 9, + "complexity": 1, + "token_count": 70, + "parameters": [ + "name", + "parent_name", + "local_path" + ], + "start_line": 994, + "end_line": 1005, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 12, + "top_nesting_level": 0 + }, + { + "name": "dict_append", + "long_name": "dict_append( d , ** kws )", + "filename": "misc_util.py", + "nloc": 6, + "complexity": 3, + "token_count": 44, + "parameters": [ + "d", + "kws" + ], + "start_line": 1008, + "end_line": 1013, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 6, + "top_nesting_level": 0 + }, + { + "name": "appendpath", + "long_name": "appendpath( prefix , path )", + "filename": "misc_util.py", + "nloc": 19, + "complexity": 6, + "token_count": 233, + "parameters": [ + "prefix", + "path" + ], + "start_line": 1015, + "end_line": 1034, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 20, + "top_nesting_level": 0 + }, + { + "name": "generate_config_py", + "long_name": "generate_config_py( target )", + "filename": "misc_util.py", + "nloc": 27, + "complexity": 2, + "token_count": 117, + "parameters": [ + "target" + ], + "start_line": 1040, + "end_line": 1073, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 34, + "top_nesting_level": 0 + }, + { + "name": "generate_svn_version_py", + "long_name": "generate_svn_version_py( extension , build_dir )", + "filename": "misc_util.py", + "nloc": 15, + "complexity": 4, + "token_count": 101, + "parameters": [ + "extension", + "build_dir" + ], + "start_line": 1075, + "end_line": 1102, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 28, + "top_nesting_level": 0 + } + ], + "methods_before": [ + { + "name": "allpath", + "long_name": "allpath( name )", + "filename": "misc_util.py", + "nloc": 4, + "complexity": 1, + "token_count": 24, + "parameters": [ + "name" + ], + "start_line": 18, + "end_line": 21, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 4, + "top_nesting_level": 0 + }, + { + "name": "get_path", + "long_name": "get_path( mod_name , parent_path = None )", + "filename": "misc_util.py", + "nloc": 15, + "complexity": 6, + "token_count": 132, + "parameters": [ + "mod_name", + "parent_path" + ], + "start_line": 23, + "end_line": 43, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 21, + "top_nesting_level": 0 + }, + { + "name": "terminal_has_colors", + "long_name": "terminal_has_colors( )", + "filename": "misc_util.py", + "nloc": 18, + "complexity": 13, + "token_count": 137, + "parameters": [], + "start_line": 47, + "end_line": 72, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 26, + "top_nesting_level": 0 + }, + { + "name": "cyg2win32", + "long_name": "cyg2win32( path )", + "filename": "misc_util.py", + "nloc": 4, + "complexity": 3, + "token_count": 42, + "parameters": [ + "path" + ], + "start_line": 89, + "end_line": 92, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 4, + "top_nesting_level": 0 + }, + { + "name": "_get_f90_modules", + "long_name": "_get_f90_modules( source )", + "filename": "misc_util.py", + "nloc": 13, + "complexity": 4, + "token_count": 77, + "parameters": [ + "source" + ], + "start_line": 101, + "end_line": 117, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 17, + "top_nesting_level": 0 + }, + { + "name": "is_string", + "long_name": "is_string( s )", + "filename": "misc_util.py", + "nloc": 2, + "complexity": 1, + "token_count": 12, + "parameters": [ + "s" + ], + "start_line": 119, + "end_line": 120, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 2, + "top_nesting_level": 0 + }, + { + "name": "all_strings", + "long_name": "all_strings( lst )", + "filename": "misc_util.py", + "nloc": 5, + "complexity": 3, + "token_count": 22, + "parameters": [ + "lst" + ], + "start_line": 122, + "end_line": 127, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 6, + "top_nesting_level": 0 + }, + { + "name": "is_sequence", + "long_name": "is_sequence( seq )", + "filename": "misc_util.py", + "nloc": 8, + "complexity": 3, + "token_count": 25, + "parameters": [ + "seq" + ], + "start_line": 129, + "end_line": 136, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 8, + "top_nesting_level": 0 + }, + { + "name": "has_f_sources", + "long_name": "has_f_sources( sources )", + "filename": "misc_util.py", + "nloc": 5, + "complexity": 3, + "token_count": 21, + "parameters": [ + "sources" + ], + "start_line": 138, + "end_line": 143, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 6, + "top_nesting_level": 0 + }, + { + "name": "has_cxx_sources", + "long_name": "has_cxx_sources( sources )", + "filename": "misc_util.py", + "nloc": 5, + "complexity": 3, + "token_count": 21, + "parameters": [ + "sources" + ], + "start_line": 145, + "end_line": 150, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 6, + "top_nesting_level": 0 + }, + { + "name": "filter_sources", + "long_name": "filter_sources( sources )", + "filename": "misc_util.py", + "nloc": 17, + "complexity": 5, + "token_count": 84, + "parameters": [ + "sources" + ], + "start_line": 152, + "end_line": 172, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 21, + "top_nesting_level": 0 + }, + { + "name": "_get_headers", + "long_name": "_get_headers( directory_list )", + "filename": "misc_util.py", + "nloc": 6, + "complexity": 2, + "token_count": 39, + "parameters": [ + "directory_list" + ], + "start_line": 175, + "end_line": 181, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 7, + "top_nesting_level": 0 + }, + { + "name": "_get_directories", + "long_name": "_get_directories( list_of_sources )", + "filename": "misc_util.py", + "nloc": 7, + "complexity": 4, + "token_count": 51, + "parameters": [ + "list_of_sources" + ], + "start_line": 183, + "end_line": 190, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 8, + "top_nesting_level": 0 + }, + { + "name": "get_dependencies", + "long_name": "get_dependencies( sources )", + "filename": "misc_util.py", + "nloc": 2, + "complexity": 1, + "token_count": 13, + "parameters": [ + "sources" + ], + "start_line": 192, + "end_line": 194, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 3, + "top_nesting_level": 0 + }, + { + "name": "is_local_src_dir", + "long_name": "is_local_src_dir( directory )", + "filename": "misc_util.py", + "nloc": 12, + "complexity": 6, + "token_count": 107, + "parameters": [ + "directory" + ], + "start_line": 196, + "end_line": 209, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 14, + "top_nesting_level": 0 + }, + { + "name": "_gsf_visit_func", + "long_name": "_gsf_visit_func( filenames , dirname , names )", + "filename": "misc_util.py", + "nloc": 13, + "complexity": 7, + "token_count": 103, + "parameters": [ + "filenames", + "dirname", + "names" + ], + "start_line": 211, + "end_line": 223, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 13, + "top_nesting_level": 0 + }, + { + "name": "get_ext_source_files", + "long_name": "get_ext_source_files( ext )", + "filename": "misc_util.py", + "nloc": 11, + "complexity": 4, + "token_count": 77, + "parameters": [ + "ext" + ], + "start_line": 225, + "end_line": 236, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 12, + "top_nesting_level": 0 + }, + { + "name": "get_script_files", + "long_name": "get_script_files( scripts )", + "filename": "misc_util.py", + "nloc": 3, + "complexity": 1, + "token_count": 15, + "parameters": [ + "scripts" + ], + "start_line": 238, + "end_line": 240, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 3, + "top_nesting_level": 0 + }, + { + "name": "get_lib_source_files", + "long_name": "get_lib_source_files( lib )", + "filename": "misc_util.py", + "nloc": 13, + "complexity": 4, + "token_count": 101, + "parameters": [ + "lib" + ], + "start_line": 242, + "end_line": 254, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 13, + "top_nesting_level": 0 + }, + { + "name": "get_data_files", + "long_name": "get_data_files( data )", + "filename": "misc_util.py", + "nloc": 18, + "complexity": 7, + "token_count": 94, + "parameters": [ + "data" + ], + "start_line": 256, + "end_line": 273, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 18, + "top_nesting_level": 0 + }, + { + "name": "dot_join", + "long_name": "dot_join( * args )", + "filename": "misc_util.py", + "nloc": 2, + "complexity": 1, + "token_count": 18, + "parameters": [ + "args" + ], + "start_line": 275, + "end_line": 276, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 2, + "top_nesting_level": 0 + }, + { + "name": "get_frame", + "long_name": "get_frame( level = 0 )", + "filename": "misc_util.py", + "nloc": 8, + "complexity": 3, + "token_count": 50, + "parameters": [ + "level" + ], + "start_line": 278, + "end_line": 285, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 8, + "top_nesting_level": 0 + }, + { + "name": "__init__", + "long_name": "__init__( self , package_name = None , parent_name = None , top_path = None , package_path = None , ** attrs )", + "filename": "misc_util.py", + "nloc": 44, + "complexity": 12, + "token_count": 377, + "parameters": [ + "self", + "package_name", + "parent_name", + "top_path", + "package_path", + "attrs" + ], + "start_line": 297, + "end_line": 360, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 64, + "top_nesting_level": 1 + }, + { + "name": "todict", + "long_name": "todict( self )", + "filename": "misc_util.py", + "nloc": 9, + "complexity": 4, + "token_count": 57, + "parameters": [ + "self" + ], + "start_line": 362, + "end_line": 373, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 12, + "top_nesting_level": 1 + }, + { + "name": "__dict__", + "long_name": "__dict__( self )", + "filename": "misc_util.py", + "nloc": 2, + "complexity": 1, + "token_count": 11, + "parameters": [ + "self" + ], + "start_line": 375, + "end_line": 376, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 2, + "top_nesting_level": 1 + }, + { + "name": "get_distribution", + "long_name": "get_distribution( self )", + "filename": "misc_util.py", + "nloc": 4, + "complexity": 1, + "token_count": 18, + "parameters": [ + "self" + ], + "start_line": 378, + "end_line": 381, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 4, + "top_nesting_level": 1 + }, + { + "name": "get_subpackage", + "long_name": "get_subpackage( self , subpackage_name , subpackage_path = None )", + "filename": "misc_util.py", + "nloc": 50, + "complexity": 12, + "token_count": 453, + "parameters": [ + "self", + "subpackage_name", + "subpackage_path" + ], + "start_line": 383, + "end_line": 440, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 58, + "top_nesting_level": 1 + }, + { + "name": "add_subpackage", + "long_name": "add_subpackage( self , subpackage_name , subpackage_path = None )", + "filename": "misc_util.py", + "nloc": 20, + "complexity": 6, + "token_count": 127, + "parameters": [ + "self", + "subpackage_name", + "subpackage_path" + ], + "start_line": 442, + "end_line": 464, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 23, + "top_nesting_level": 1 + }, + { + "name": "add_data_dir", + "long_name": "add_data_dir( self , data_path )", + "filename": "misc_util.py", + "nloc": 24, + "complexity": 8, + "token_count": 153, + "parameters": [ + "self", + "data_path" + ], + "start_line": 466, + "end_line": 497, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 32, + "top_nesting_level": 1 + }, + { + "name": "add_data_files", + "long_name": "add_data_files( self , * files )", + "filename": "misc_util.py", + "nloc": 39, + "complexity": 15, + "token_count": 281, + "parameters": [ + "self", + "files" + ], + "start_line": 499, + "end_line": 548, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 50, + "top_nesting_level": 1 + }, + { + "name": "add_include_dirs", + "long_name": "add_include_dirs( self , * paths )", + "filename": "misc_util.py", + "nloc": 8, + "complexity": 2, + "token_count": 49, + "parameters": [ + "self", + "paths" + ], + "start_line": 552, + "end_line": 561, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 10, + "top_nesting_level": 1 + }, + { + "name": "add_headers", + "long_name": "add_headers( self , * files )", + "filename": "misc_util.py", + "nloc": 15, + "complexity": 8, + "token_count": 136, + "parameters": [ + "self", + "files" + ], + "start_line": 563, + "end_line": 583, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 21, + "top_nesting_level": 1 + }, + { + "name": "_fix_paths", + "long_name": "_fix_paths( self , paths )", + "filename": "misc_util.py", + "nloc": 22, + "complexity": 8, + "token_count": 136, + "parameters": [ + "self", + "paths" + ], + "start_line": 585, + "end_line": 606, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 22, + "top_nesting_level": 1 + }, + { + "name": "paths", + "long_name": "paths( self , * paths )", + "filename": "misc_util.py", + "nloc": 2, + "complexity": 1, + "token_count": 16, + "parameters": [ + "self", + "paths" + ], + "start_line": 608, + "end_line": 611, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 4, + "top_nesting_level": 1 + }, + { + "name": "add_extension", + "long_name": "add_extension( self , name , sources , ** kw )", + "filename": "misc_util.py", + "nloc": 45, + "complexity": 14, + "token_count": 365, + "parameters": [ + "self", + "name", + "sources", + "kw" + ], + "start_line": 613, + "end_line": 675, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 63, + "top_nesting_level": 1 + }, + { + "name": "add_library", + "long_name": "add_library( self , name , sources , ** build_info )", + "filename": "misc_util.py", + "nloc": 15, + "complexity": 4, + "token_count": 106, + "parameters": [ + "self", + "name", + "sources", + "build_info" + ], + "start_line": 677, + "end_line": 702, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 26, + "top_nesting_level": 1 + }, + { + "name": "add_scripts", + "long_name": "add_scripts( self , * files )", + "filename": "misc_util.py", + "nloc": 8, + "complexity": 2, + "token_count": 49, + "parameters": [ + "self", + "files" + ], + "start_line": 704, + "end_line": 713, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 10, + "top_nesting_level": 1 + }, + { + "name": "dict_append", + "long_name": "dict_append( self , ** dict )", + "filename": "misc_util.py", + "nloc": 15, + "complexity": 6, + "token_count": 138, + "parameters": [ + "self", + "dict" + ], + "start_line": 715, + "end_line": 729, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 15, + "top_nesting_level": 1 + }, + { + "name": "__str__", + "long_name": "__str__( self )", + "filename": "misc_util.py", + "nloc": 10, + "complexity": 3, + "token_count": 72, + "parameters": [ + "self" + ], + "start_line": 731, + "end_line": 740, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 10, + "top_nesting_level": 1 + }, + { + "name": "get_config_cmd", + "long_name": "get_config_cmd( self )", + "filename": "misc_util.py", + "nloc": 10, + "complexity": 2, + "token_count": 63, + "parameters": [ + "self" + ], + "start_line": 742, + "end_line": 751, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 10, + "top_nesting_level": 1 + }, + { + "name": "get_build_temp_dir", + "long_name": "get_build_temp_dir( self )", + "filename": "misc_util.py", + "nloc": 4, + "complexity": 1, + "token_count": 20, + "parameters": [ + "self" + ], + "start_line": 753, + "end_line": 756, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 4, + "top_nesting_level": 1 + }, + { + "name": "have_f77c", + "long_name": "have_f77c( self )", + "filename": "misc_util.py", + "nloc": 8, + "complexity": 1, + "token_count": 30, + "parameters": [ + "self" + ], + "start_line": 758, + "end_line": 769, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 12, + "top_nesting_level": 1 + }, + { + "name": "have_f90c", + "long_name": "have_f90c( self )", + "filename": "misc_util.py", + "nloc": 8, + "complexity": 1, + "token_count": 30, + "parameters": [ + "self" + ], + "start_line": 771, + "end_line": 782, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 12, + "top_nesting_level": 1 + }, + { + "name": "append_to", + "long_name": "append_to( self , extlib )", + "filename": "misc_util.py", + "nloc": 12, + "complexity": 2, + "token_count": 77, + "parameters": [ + "self", + "extlib" + ], + "start_line": 784, + "end_line": 797, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 14, + "top_nesting_level": 1 + }, + { + "name": "_get_svn_revision", + "long_name": "_get_svn_revision( self , path )", + "filename": "misc_util.py", + "nloc": 10, + "complexity": 3, + "token_count": 77, + "parameters": [ + "self", + "path" + ], + "start_line": 799, + "end_line": 810, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 12, + "top_nesting_level": 1 + }, + { + "name": "get_version", + "long_name": "get_version( self )", + "filename": "misc_util.py", + "nloc": 38, + "complexity": 11, + "token_count": 257, + "parameters": [ + "self" + ], + "start_line": 812, + "end_line": 858, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 47, + "top_nesting_level": 1 + }, + { + "name": "make_svn_version_py.make_svn_version_py.generate_svn_version_py.rm_file", + "long_name": "make_svn_version_py.make_svn_version_py.generate_svn_version_py.rm_file( f = target )", + "filename": "misc_util.py", + "nloc": 5, + "complexity": 3, + "token_count": 45, + "parameters": [ + "f" + ], + "start_line": 882, + "end_line": 886, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 5, + "top_nesting_level": 3 + }, + { + "name": "make_svn_version_py.generate_svn_version_py", + "long_name": "make_svn_version_py.generate_svn_version_py( )", + "filename": "misc_util.py", + "nloc": 13, + "complexity": 2, + "token_count": 81, + "parameters": [], + "start_line": 871, + "end_line": 889, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 19, + "top_nesting_level": 2 + }, + { + "name": "make_svn_version_py", + "long_name": "make_svn_version_py( self )", + "filename": "misc_util.py", + "nloc": 7, + "complexity": 2, + "token_count": 42, + "parameters": [ + "self" + ], + "start_line": 860, + "end_line": 892, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 33, + "top_nesting_level": 1 + }, + { + "name": "make_config_py", + "long_name": "make_config_py( self , name = '__config__' )", + "filename": "misc_util.py", + "nloc": 3, + "complexity": 1, + "token_count": 27, + "parameters": [ + "self", + "name" + ], + "start_line": 894, + "end_line": 899, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 6, + "top_nesting_level": 1 + }, + { + "name": "get_info", + "long_name": "get_info( self , * names )", + "filename": "misc_util.py", + "nloc": 6, + "complexity": 2, + "token_count": 36, + "parameters": [ + "self", + "names" + ], + "start_line": 901, + "end_line": 908, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 8, + "top_nesting_level": 1 + }, + { + "name": "get_cmd", + "long_name": "get_cmd( cmdname , _cache = { } )", + "filename": "misc_util.py", + "nloc": 11, + "complexity": 3, + "token_count": 65, + "parameters": [ + "cmdname", + "_cache" + ], + "start_line": 910, + "end_line": 920, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 11, + "top_nesting_level": 0 + }, + { + "name": "get_numpy_include_dirs", + "long_name": "get_numpy_include_dirs( )", + "filename": "misc_util.py", + "nloc": 11, + "complexity": 3, + "token_count": 85, + "parameters": [], + "start_line": 922, + "end_line": 936, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 15, + "top_nesting_level": 0 + }, + { + "name": "default_config_dict", + "long_name": "default_config_dict( name = None , parent_name = None , local_path = None )", + "filename": "misc_util.py", + "nloc": 9, + "complexity": 1, + "token_count": 70, + "parameters": [ + "name", + "parent_name", + "local_path" + ], + "start_line": 940, + "end_line": 951, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 12, + "top_nesting_level": 0 + }, + { + "name": "dict_append", + "long_name": "dict_append( d , ** kws )", + "filename": "misc_util.py", + "nloc": 6, + "complexity": 3, + "token_count": 44, + "parameters": [ + "d", + "kws" + ], + "start_line": 954, + "end_line": 959, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 6, + "top_nesting_level": 0 + }, + { + "name": "appendpath", + "long_name": "appendpath( prefix , path )", + "filename": "misc_util.py", + "nloc": 19, + "complexity": 6, + "token_count": 237, + "parameters": [ + "prefix", + "path" + ], + "start_line": 961, + "end_line": 980, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 20, + "top_nesting_level": 0 + }, + { + "name": "generate_config_py", + "long_name": "generate_config_py( target )", + "filename": "misc_util.py", + "nloc": 27, + "complexity": 2, + "token_count": 117, + "parameters": [ + "target" + ], + "start_line": 982, + "end_line": 1015, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 34, + "top_nesting_level": 0 + }, + { + "name": "generate_svn_version_py", + "long_name": "generate_svn_version_py( extension , build_dir )", + "filename": "misc_util.py", + "nloc": 15, + "complexity": 4, + "token_count": 109, + "parameters": [ + "extension", + "build_dir" + ], + "start_line": 1017, + "end_line": 1044, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 28, + "top_nesting_level": 0 + } + ], + "changed_methods": [ + { + "name": "_fix_paths", + "long_name": "_fix_paths( self , paths )", + "filename": "misc_util.py", + "nloc": 26, + "complexity": 9, + "token_count": 182, + "parameters": [ + "self", + "paths" + ], + "start_line": 635, + "end_line": 660, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 26, + "top_nesting_level": 1 + }, + { + "name": "get_version", + "long_name": "get_version( self )", + "filename": "misc_util.py", + "nloc": 38, + "complexity": 11, + "token_count": 253, + "parameters": [ + "self" + ], + "start_line": 866, + "end_line": 912, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 47, + "top_nesting_level": 1 + }, + { + "name": "generate_svn_version_py", + "long_name": "generate_svn_version_py( extension , build_dir )", + "filename": "misc_util.py", + "nloc": 15, + "complexity": 4, + "token_count": 101, + "parameters": [ + "extension", + "build_dir" + ], + "start_line": 1075, + "end_line": 1102, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 28, + "top_nesting_level": 0 + }, + { + "name": "add_data_dir", + "long_name": "add_data_dir( self , data_path )", + "filename": "misc_util.py", + "nloc": 27, + "complexity": 9, + "token_count": 196, + "parameters": [ + "self", + "data_path" + ], + "start_line": 506, + "end_line": 540, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 35, + "top_nesting_level": 1 + }, + { + "name": "get_subpackage", + "long_name": "get_subpackage( self , subpackage_name , subpackage_path = None )", + "filename": "misc_util.py", + "nloc": 52, + "complexity": 13, + "token_count": 446, + "parameters": [ + "self", + "subpackage_name", + "subpackage_path" + ], + "start_line": 422, + "end_line": 480, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 59, + "top_nesting_level": 1 + }, + { + "name": "info", + "long_name": "info( self , message )", + "filename": "misc_util.py", + "nloc": 2, + "complexity": 1, + "token_count": 9, + "parameters": [ + "self", + "message" + ], + "start_line": 408, + "end_line": 409, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 2, + "top_nesting_level": 1 + }, + { + "name": "get_numpy_include_dirs", + "long_name": "get_numpy_include_dirs( )", + "filename": "misc_util.py", + "nloc": 11, + "complexity": 3, + "token_count": 77, + "parameters": [], + "start_line": 976, + "end_line": 990, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 15, + "top_nesting_level": 0 + }, + { + "name": "add_extension", + "long_name": "add_extension( self , name , sources , ** kw )", + "filename": "misc_util.py", + "nloc": 45, + "complexity": 14, + "token_count": 361, + "parameters": [ + "self", + "name", + "sources", + "kw" + ], + "start_line": 667, + "end_line": 729, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 63, + "top_nesting_level": 1 + }, + { + "name": "add_data_files", + "long_name": "add_data_files( self , * files )", + "filename": "misc_util.py", + "nloc": 46, + "complexity": 18, + "token_count": 320, + "parameters": [ + "self", + "files" + ], + "start_line": 542, + "end_line": 598, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 57, + "top_nesting_level": 1 + }, + { + "name": "njoin", + "long_name": "njoin( * path )", + "filename": "misc_util.py", + "nloc": 7, + "complexity": 4, + "token_count": 68, + "parameters": [ + "path" + ], + "start_line": 45, + "end_line": 55, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 11, + "top_nesting_level": 0 + }, + { + "name": "_get_svn_revision", + "long_name": "_get_svn_revision( self , path )", + "filename": "misc_util.py", + "nloc": 10, + "complexity": 3, + "token_count": 73, + "parameters": [ + "self", + "path" + ], + "start_line": 853, + "end_line": 864, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 12, + "top_nesting_level": 1 + }, + { + "name": "appendpath", + "long_name": "appendpath( prefix , path )", + "filename": "misc_util.py", + "nloc": 19, + "complexity": 6, + "token_count": 233, + "parameters": [ + "prefix", + "path" + ], + "start_line": 1015, + "end_line": 1034, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 20, + "top_nesting_level": 0 + }, + { + "name": "warn", + "long_name": "warn( self , message )", + "filename": "misc_util.py", + "nloc": 2, + "complexity": 1, + "token_count": 11, + "parameters": [ + "self", + "message" + ], + "start_line": 411, + "end_line": 412, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 2, + "top_nesting_level": 1 + }, + { + "name": "minrelpath", + "long_name": "minrelpath( path )", + "filename": "misc_util.py", + "nloc": 17, + "complexity": 7, + "token_count": 103, + "parameters": [ + "path" + ], + "start_line": 57, + "end_line": 75, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 19, + "top_nesting_level": 0 + }, + { + "name": "__init__", + "long_name": "__init__( self , package_name = None , parent_name = None , top_path = None , package_path = None , ** attrs )", + "filename": "misc_util.py", + "nloc": 44, + "complexity": 12, + "token_count": 365, + "parameters": [ + "self", + "package_name", + "parent_name", + "top_path", + "package_path", + "attrs" + ], + "start_line": 329, + "end_line": 393, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 65, + "top_nesting_level": 1 + }, + { + "name": "make_svn_version_py", + "long_name": "make_svn_version_py( self )", + "filename": "misc_util.py", + "nloc": 7, + "complexity": 2, + "token_count": 44, + "parameters": [ + "self" + ], + "start_line": 914, + "end_line": 946, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 33, + "top_nesting_level": 1 + } + ], + "nloc": 823, + "complexity": 264, + "token_count": 5912, + "diff_parsed": { + "added": [ + " 'dot_join', 'get_frame', 'minrelpath','njoin']", + "def njoin(*path):", + " \"\"\" Join two or more pathname components +", + " - convert a /-separated pathname to one using the OS's path separator.", + " - resolve `..` from path.", + " \"\"\"", + " if isinstance(path,tuple):", + " path = os.path.join(*path)", + " if not isinstance(path,str): return path", + " if not ('/' == os.path.sep):", + " path = path.replace('/',os.path.sep)", + " return minrelpath(path)", + "", + "def minrelpath(path):", + " \"\"\" Resolve `..` from path.", + " \"\"\"", + " if not isinstance(path, str): return path", + " if '..' not in path: return path", + " l = path.split(os.sep)", + " j = 1", + " while l:", + " try:", + " i = l.index('..',j)", + " except ValueError:", + " break", + " if l[i-1]=='..':", + " j += 1", + " else:", + " del l[i],l[i-1]", + " j = 1", + " if not l: return ''", + " return os.path.join(*l)", + "", + " elif os.path.isdir(njoin(self.local_path,package_path)):", + " package_path = njoin(self.local_path,package_path)", + " if os.path.exists(njoin(package_path,'__init__.py')):", + "", + " def info(self, message):", + " print message", + "", + " def warn(self, message):", + " print 'Warning:',message", + "", + " subpackage_path = njoin(*([self.local_path]+l))", + " if not os.path.isfile(njoin(d,'__init__.py')):", + " continue", + " if 'build' in d.split(os.sep):", + " subpackage_path = njoin(*([subpackage_path]+l[:-1]))", + " setup_py = njoin(subpackage_path,'setup.py')", + " setup_py = njoin(subpackage_path,'setup_%s.py' % (subpackage_name))", + " npath = data_path", + " if '*' in npath:", + " npath = os.path.join(*(path.split(os.sep)[-len(npath.split(os.sep)):]))", + " ds = os.path.join(d, npath)", + " new_files = []", + " for p in files:", + " if isinstance(p,str) and '*' in p:", + " new_files.extend(self.paths(p))", + " else:", + " new_files.append(p)", + " files = new_files", + " p = njoin(*([prefix]+extra_path_components))", + " assert isinstance(paths,(list,tuple)),`type(paths)`", + " p2 = glob.glob(njoin(self.local_path,n))", + " self.warn('could not resolve pattern: %r' % (n))", + " n2 = njoin(self.local_path,n)", + " if not os.path.exists(n):", + " self.warn('not existing path: %r' % (n))", + " return map(minrelpath,new_paths)", + " lpath = os.path.abspath(njoin(self.local_path,lpath))", + " entries = njoin(path,'.svn','entries')", + " fn = njoin(self.local_path,f)", + " target = njoin(self.local_path,'__svn_version__.py')", + " self.add_data_files((self.path_in_package, generate_svn_version_py()))", + " include_dirs.append(njoin(os.path.dirname(numpy.__file__),", + " include_dirs.append(njoin(os.path.dirname(core.__file__),'include'))", + " return os.path.normpath(njoin(drive + prefix, subpath))", + "", + "", + "", + "", + " target = njoin(build_dir, '__svn_version__.py')", + " entries = njoin(local_path,'.svn','entries')" + ], + "deleted": [ + " 'dot_join', 'get_frame']", + " elif os.path.isdir(os.path.join(self.local_path,package_path)):", + " package_path = os.path.join(self.local_path,package_path)", + " if os.path.exists(os.path.join(package_path,'__init__.py')):", + " subpackage_path = os.path.join(*([self.local_path]+l))", + " if not os.path.isfile(os.path.join(d,'__init__.py')):", + " subpackage_path = os.path.join(*([subpackage_path]+l[:-1]))", + "", + " setup_py = os.path.join(subpackage_path,'setup.py')", + " setup_py = os.path.join(subpackage_path,'setup_%s.py' % (subpackage_name))", + " ds = os.path.join(d, data_path)", + " p = os.path.join(*([prefix]+extra_path_components))", + " p2 = glob.glob(os.path.join(self.local_path,n))", + " n2 = os.path.join(self.local_path,n)", + " return new_paths", + " lpath = os.path.abspath(os.path.join(self.local_path,lpath))", + " entries = os.path.join(path,'.svn','entries')", + " fn = os.path.join(self.local_path,f)", + " target = os.path.join(self.local_path,'__svn_version__.py')", + " self.add_data_files(generate_svn_version_py())", + " include_dirs.append(os.path.join(os.path.dirname(numpy.__file__),", + " include_dirs.append(os.path.join(os.path.dirname(core.__file__),'include'))", + " return os.path.normpath(os.path.join(drive + prefix, subpath))", + " target = os.path.join(build_dir, '__svn_version__.py')", + " entries = os.path.join(local_path,'.svn','entries')" + ] + } + }, + { + "old_path": "numpy/distutils/tests/test_misc_util.py", + "new_path": "numpy/distutils/tests/test_misc_util.py", + "filename": "test_misc_util.py", + "extension": "py", + "change_type": "MODIFY", + "diff": "@@ -1,6 +1,6 @@\n import sys\n from numpy.testing import *\n-from numpy.distutils.misc_util import appendpath\n+from numpy.distutils.misc_util import appendpath, minrelpath\n from os.path import join, sep\n \n ajoin = lambda *paths: join(*((sep,)+paths))\n@@ -29,5 +29,16 @@ def check_3(self):\n assert_equal(appendpath('/prefix/sub/sub2','/prefix/sub/sup/name'),\n ajoin('prefix','sub','sub2','sup','name'))\n \n+class test_minrelpath(ScipyTestCase):\n+\n+ def check_1(self):\n+ assert_equal(minrelpath(join('aa/bb')),'aa/bb')\n+ assert_equal(minrelpath(join('..')),'..')\n+ assert_equal(minrelpath(join('aa/..')),'')\n+ assert_equal(minrelpath(join('aa/../bb')),'bb')\n+ assert_equal(minrelpath(join('aa/bb/..')),'aa')\n+ assert_equal(minrelpath(join('aa/bb/../..')),'')\n+ assert_equal(minrelpath(join('aa/bb/../cc/../dd')),'aa/dd')\n+\n if __name__ == \"__main__\":\n ScipyTest().run()\n", + "added_lines": 12, + "deleted_lines": 1, + "source_code": "import sys\nfrom numpy.testing import *\nfrom numpy.distutils.misc_util import appendpath, minrelpath\nfrom os.path import join, sep\n\najoin = lambda *paths: join(*((sep,)+paths))\n\nclass test_appendpath(ScipyTestCase):\n\n def check_1(self):\n assert_equal(appendpath('prefix','name'),join('prefix','name'))\n assert_equal(appendpath('/prefix','name'),ajoin('prefix','name'))\n assert_equal(appendpath('/prefix','/name'),ajoin('prefix','name'))\n assert_equal(appendpath('prefix','/name'),join('prefix','name'))\n\n def check_2(self):\n assert_equal(appendpath('prefix/sub','name'),\n join('prefix','sub','name'))\n assert_equal(appendpath('prefix/sub','sup/name'),\n join('prefix','sub','sup','name'))\n assert_equal(appendpath('/prefix/sub','/prefix/name'),\n ajoin('prefix','sub','name'))\n\n def check_3(self):\n assert_equal(appendpath('/prefix/sub','/prefix/sup/name'),\n ajoin('prefix','sub','sup','name'))\n assert_equal(appendpath('/prefix/sub/sub2','/prefix/sup/sup2/name'),\n ajoin('prefix','sub','sub2','sup','sup2','name'))\n assert_equal(appendpath('/prefix/sub/sub2','/prefix/sub/sup/name'),\n ajoin('prefix','sub','sub2','sup','name'))\n\nclass test_minrelpath(ScipyTestCase):\n\n def check_1(self):\n assert_equal(minrelpath(join('aa/bb')),'aa/bb')\n assert_equal(minrelpath(join('..')),'..')\n assert_equal(minrelpath(join('aa/..')),'')\n assert_equal(minrelpath(join('aa/../bb')),'bb')\n assert_equal(minrelpath(join('aa/bb/..')),'aa')\n assert_equal(minrelpath(join('aa/bb/../..')),'')\n assert_equal(minrelpath(join('aa/bb/../cc/../dd')),'aa/dd')\n\nif __name__ == \"__main__\":\n ScipyTest().run()\n", + "source_code_before": "import sys\nfrom numpy.testing import *\nfrom numpy.distutils.misc_util import appendpath\nfrom os.path import join, sep\n\najoin = lambda *paths: join(*((sep,)+paths))\n\nclass test_appendpath(ScipyTestCase):\n\n def check_1(self):\n assert_equal(appendpath('prefix','name'),join('prefix','name'))\n assert_equal(appendpath('/prefix','name'),ajoin('prefix','name'))\n assert_equal(appendpath('/prefix','/name'),ajoin('prefix','name'))\n assert_equal(appendpath('prefix','/name'),join('prefix','name'))\n\n def check_2(self):\n assert_equal(appendpath('prefix/sub','name'),\n join('prefix','sub','name'))\n assert_equal(appendpath('prefix/sub','sup/name'),\n join('prefix','sub','sup','name'))\n assert_equal(appendpath('/prefix/sub','/prefix/name'),\n ajoin('prefix','sub','name'))\n\n def check_3(self):\n assert_equal(appendpath('/prefix/sub','/prefix/sup/name'),\n ajoin('prefix','sub','sup','name'))\n assert_equal(appendpath('/prefix/sub/sub2','/prefix/sup/sup2/name'),\n ajoin('prefix','sub','sub2','sup','sup2','name'))\n assert_equal(appendpath('/prefix/sub/sub2','/prefix/sub/sup/name'),\n ajoin('prefix','sub','sub2','sup','name'))\n\nif __name__ == \"__main__\":\n ScipyTest().run()\n", + "methods": [ + { + "name": "check_1", + "long_name": "check_1( self )", + "filename": "test_misc_util.py", + "nloc": 5, + "complexity": 1, + "token_count": 69, + "parameters": [ + "self" + ], + "start_line": 10, + "end_line": 14, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 5, + "top_nesting_level": 1 + }, + { + "name": "check_2", + "long_name": "check_2( self )", + "filename": "test_misc_util.py", + "nloc": 7, + "complexity": 1, + "token_count": 61, + "parameters": [ + "self" + ], + "start_line": 16, + "end_line": 22, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 7, + "top_nesting_level": 1 + }, + { + "name": "check_3", + "long_name": "check_3( self )", + "filename": "test_misc_util.py", + "nloc": 7, + "complexity": 1, + "token_count": 71, + "parameters": [ + "self" + ], + "start_line": 24, + "end_line": 30, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 7, + "top_nesting_level": 1 + }, + { + "name": "check_1", + "long_name": "check_1( self )", + "filename": "test_misc_util.py", + "nloc": 8, + "complexity": 1, + "token_count": 89, + "parameters": [ + "self" + ], + "start_line": 34, + "end_line": 41, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 8, + "top_nesting_level": 1 + } + ], + "methods_before": [ + { + "name": "check_1", + "long_name": "check_1( self )", + "filename": "test_misc_util.py", + "nloc": 5, + "complexity": 1, + "token_count": 69, + "parameters": [ + "self" + ], + "start_line": 10, + "end_line": 14, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 5, + "top_nesting_level": 1 + }, + { + "name": "check_2", + "long_name": "check_2( self )", + "filename": "test_misc_util.py", + "nloc": 7, + "complexity": 1, + "token_count": 61, + "parameters": [ + "self" + ], + "start_line": 16, + "end_line": 22, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 7, + "top_nesting_level": 1 + }, + { + "name": "check_3", + "long_name": "check_3( self )", + "filename": "test_misc_util.py", + "nloc": 7, + "complexity": 1, + "token_count": 71, + "parameters": [ + "self" + ], + "start_line": 24, + "end_line": 30, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 7, + "top_nesting_level": 1 + } + ], + "changed_methods": [ + { + "name": "check_1", + "long_name": "check_1( self )", + "filename": "test_misc_util.py", + "nloc": 8, + "complexity": 1, + "token_count": 89, + "parameters": [ + "self" + ], + "start_line": 34, + "end_line": 41, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 8, + "top_nesting_level": 1 + } + ], + "nloc": 36, + "complexity": 4, + "token_count": 362, + "diff_parsed": { + "added": [ + "from numpy.distutils.misc_util import appendpath, minrelpath", + "class test_minrelpath(ScipyTestCase):", + "", + " def check_1(self):", + " assert_equal(minrelpath(join('aa/bb')),'aa/bb')", + " assert_equal(minrelpath(join('..')),'..')", + " assert_equal(minrelpath(join('aa/..')),'')", + " assert_equal(minrelpath(join('aa/../bb')),'bb')", + " assert_equal(minrelpath(join('aa/bb/..')),'aa')", + " assert_equal(minrelpath(join('aa/bb/../..')),'')", + " assert_equal(minrelpath(join('aa/bb/../cc/../dd')),'aa/dd')", + "" + ], + "deleted": [ + "from numpy.distutils.misc_util import appendpath" + ] + } + } + ] + }, + { + "hash": "e97d2da5c89a2dc2ee87bc67d54b7d6a946835a9", + "msg": "Fixed add_data_files for patterns. paths takes include_non_existing kw argument.", + "author": { + "name": "Pearu Peterson", + "email": "pearu.peterson@gmail.com" + }, + "committer": { + "name": "Pearu Peterson", + "email": "pearu.peterson@gmail.com" + }, + "author_date": "2006-01-28T11:33:35+00:00", + "author_timezone": 0, + "committer_date": "2006-01-28T11:33:35+00:00", + "committer_timezone": 0, + "branches": [ + "main" + ], + "in_main_branch": true, + "merge": false, + "parents": [ + "4c2ce0ae3095ce4f7420bfb88fafd51aca5a0a46" + ], + "project_name": "repo_copy", + "project_path": "/tmp/tmppy2o86q9/repo_copy", + "deletions": 15, + "insertions": 25, + "lines": 40, + "files": 1, + "dmm_unit_size": 0.2222222222222222, + "dmm_unit_complexity": 0.2222222222222222, + "dmm_unit_interfacing": 0.0, + "modified_files": [ + { + "old_path": "numpy/distutils/misc_util.py", + "new_path": "numpy/distutils/misc_util.py", + "filename": "misc_util.py", + "extension": "py", + "change_type": "MODIFY", + "diff": "@@ -548,26 +548,30 @@ def add_data_files(self,*files):\n If path is not absolute then it's datadir prefix is\n package dir + dirname of the path.\n \"\"\"\n- new_files = []\n- for p in files:\n- if isinstance(p,str) and '*' in p:\n- new_files.extend(self.paths(p))\n- else:\n- new_files.append(p)\n- files = new_files\n data_dict = {}\n new_files = []\n for p in files:\n if not is_sequence(p):\n d = self.path_in_package\n if is_string(p) and not os.path.isabs(p):\n- d = appendpath(d,os.path.dirname(p))\n- p = (d,p)\n+ pd = os.path.dirname(p)\n+ if '*' in pd:\n+ pn = os.path.basename(p)\n+ n = len(pd.split(os.sep))\n+ for d1 in filter(os.path.isdir,self.paths(pd)):\n+ p = os.path.join(d1,pn)\n+ d1 = os.sep.join(d1.split(os.sep)[-n:])\n+ new_files.append((appendpath(d,d1),p))\n+ continue\n+ d = appendpath(d,pd)\n+ p = (d,p) \n new_files.append(p)\n+ \n files = []\n for prefix,filepattern in new_files:\n+ assert '*' not in prefix,`prefix,filepattern`\n if is_string(filepattern):\n- file_list = self.paths(filepattern)\n+ file_list = self.paths(filepattern,include_non_existing=False)\n elif callable(filepattern):\n file_list = [filepattern]\n else:\n@@ -632,7 +636,7 @@ def add_headers(self,*files):\n self.headers.extend(headers)\n return\n \n- def _fix_paths(self,paths):\n+ def _fix_paths(self,paths,include_non_existing=True):\n assert isinstance(paths,(list,tuple)),`type(paths)`\n new_paths = []\n for n in paths:\n@@ -645,24 +649,30 @@ def _fix_paths(self,paths):\n elif p:\n new_paths.extend(p)\n else:\n- new_paths.append(n)\n+ if include_non_existing:\n+ new_paths.append(n)\n self.warn('could not resolve pattern: %r' % (n))\n else:\n n2 = njoin(self.local_path,n)\n if os.path.exists(n2):\n new_paths.append(n2)\n else:\n- new_paths.append(n)\n+ if os.path.exists(n):\n+ new_paths.append(n)\n+ elif include_non_existing:\n+ new_paths.append(n)\n if not os.path.exists(n):\n self.warn('not existing path: %r' % (n))\n else:\n new_paths.append(n)\n return map(minrelpath,new_paths)\n \n- def paths(self,*paths):\n+ def paths(self,*paths,**kws):\n \"\"\" Apply glob to paths and prepend local_path if needed.\n \"\"\"\n- return self._fix_paths(paths)\n+ include_non_existing = kws.get('include_non_existing',True)\n+ return self._fix_paths(paths,\n+ include_non_existing=include_non_existing)\n \n def add_extension(self,name,sources,**kw):\n \"\"\" Add extension to configuration.\n", + "added_lines": 25, + "deleted_lines": 15, + "source_code": "import os\nimport re\nimport sys\nimport imp\nimport copy\nimport glob\n\n__all__ = ['Configuration', 'get_numpy_include_dirs', 'default_config_dict',\n 'dict_append', 'appendpath', 'generate_config_py',\n 'generate_svn_version_py', 'get_cmd', 'allpath',\n 'terminal_has_colors', 'red_text', 'green_text', 'yellow_text',\n 'blue_text', 'cyan_text', 'cyg2win32', 'all_strings',\n 'has_f_sources', 'has_cxx_sources', 'filter_sources',\n 'get_dependencies', 'is_local_src_dir', 'get_ext_source_files',\n 'get_script_files', 'get_lib_source_files', 'get_data_files',\n 'dot_join', 'get_frame', 'minrelpath','njoin']\n\ndef allpath(name):\n \"Convert a /-separated pathname to one using the OS's path separator.\"\n splitted = name.split('/')\n return os.path.join(*splitted)\n\ndef get_path(mod_name,parent_path=None):\n \"\"\" Return path of the module.\n\n Returned path is relative to parent_path when given,\n otherwise it is absolute path.\n \"\"\"\n if mod_name == '__main__':\n d = os.path.abspath('.')\n elif mod_name == '__builtin__':\n #builtin if/then added by Pearu for use in core.run_setup.\n d = os.path.dirname(os.path.abspath(sys.argv[0]))\n else:\n __import__(mod_name)\n mod = sys.modules[mod_name]\n file = mod.__file__\n d = os.path.dirname(os.path.abspath(file))\n if parent_path is not None:\n pd = os.path.abspath(parent_path)\n if pd==d[:len(pd)]:\n d = d[len(pd)+1:]\n return d or '.'\n\ndef njoin(*path):\n \"\"\" Join two or more pathname components +\n - convert a /-separated pathname to one using the OS's path separator.\n - resolve `..` from path.\n \"\"\"\n if isinstance(path,tuple):\n path = os.path.join(*path)\n if not isinstance(path,str): return path\n if not ('/' == os.path.sep):\n path = path.replace('/',os.path.sep)\n return minrelpath(path)\n\ndef minrelpath(path):\n \"\"\" Resolve `..` from path.\n \"\"\"\n if not isinstance(path, str): return path\n if '..' not in path: return path\n l = path.split(os.sep)\n j = 1\n while l:\n try:\n i = l.index('..',j)\n except ValueError:\n break\n if l[i-1]=='..':\n j += 1\n else:\n del l[i],l[i-1]\n j = 1\n if not l: return ''\n return os.path.join(*l)\n\n# Hooks for colored terminal output.\n# See also http://www.livinglogic.de/Python/ansistyle\ndef terminal_has_colors():\n if sys.platform=='cygwin' and not os.environ.has_key('USE_COLOR'):\n # Avoid importing curses that causes illegal operation\n # with a message:\n # PYTHON2 caused an invalid page fault in\n # module CYGNURSES7.DLL as 015f:18bbfc28\n # Details: Python 2.3.3 [GCC 3.3.1 (cygming special)]\n # ssh to Win32 machine from debian\n # curses.version is 2.2\n # CYGWIN_98-4.10, release 1.5.7(0.109/3/2))\n return 0\n if hasattr(sys.stdout,'isatty') and sys.stdout.isatty():\n try:\n import curses\n curses.setupterm()\n if (curses.tigetnum(\"colors\") >= 0\n and curses.tigetnum(\"pairs\") >= 0\n and ((curses.tigetstr(\"setf\") is not None\n and curses.tigetstr(\"setb\") is not None)\n or (curses.tigetstr(\"setaf\") is not None\n and curses.tigetstr(\"setab\") is not None)\n or curses.tigetstr(\"scp\") is not None)):\n return 1\n except Exception,msg:\n pass\n return 0\n\nif terminal_has_colors():\n def red_text(s): return '\\x1b[31m%s\\x1b[0m'%s\n def green_text(s): return '\\x1b[32m%s\\x1b[0m'%s\n def yellow_text(s): return '\\x1b[33m%s\\x1b[0m'%s\n def blue_text(s): return '\\x1b[34m%s\\x1b[0m'%s\n def cyan_text(s): return '\\x1b[35m%s\\x1b[0m'%s\nelse:\n def red_text(s): return s\n def green_text(s): return s\n def yellow_text(s): return s\n def cyan_text(s): return s\n def blue_text(s): return s\n\n#########################\n\ndef cyg2win32(path):\n if sys.platform=='cygwin' and path.startswith('/cygdrive'):\n path = path[10] + ':' + os.path.normcase(path[11:])\n return path\n\n#########################\n\n#XXX need support for .C that is also C++\ncxx_ext_match = re.compile(r'.*[.](cpp|cxx|cc)\\Z',re.I).match\nfortran_ext_match = re.compile(r'.*[.](f90|f95|f77|for|ftn|f)\\Z',re.I).match\nf90_ext_match = re.compile(r'.*[.](f90|f95)\\Z',re.I).match\nf90_module_name_match = re.compile(r'\\s*module\\s*(?P[\\w_]+)',re.I).match\ndef _get_f90_modules(source):\n \"\"\" Return a list of Fortran f90 module names that\n given source file defines.\n \"\"\"\n if not f90_ext_match(source):\n return []\n modules = []\n f = open(source,'r')\n f_readlines = getattr(f,'xreadlines',f.readlines)\n for line in f_readlines():\n m = f90_module_name_match(line)\n if m:\n name = m.group('name')\n modules.append(name)\n # break # XXX can we assume that there is one module per file?\n f.close()\n return modules\n\ndef is_string(s):\n return isinstance(s, str)\n\ndef all_strings(lst):\n \"\"\" Return True if all items in lst are string objects. \"\"\"\n for item in lst:\n if not is_string(item):\n return False\n return True\n\ndef is_sequence(seq):\n if is_string(seq):\n return False\n try:\n len(seq)\n except:\n return False\n return True\n\ndef has_f_sources(sources):\n \"\"\" Return True if sources contains Fortran files \"\"\"\n for source in sources:\n if fortran_ext_match(source):\n return True\n return False\n\ndef has_cxx_sources(sources):\n \"\"\" Return True if sources contains C++ files \"\"\"\n for source in sources:\n if cxx_ext_match(source):\n return True\n return False\n\ndef filter_sources(sources):\n \"\"\" Return four lists of filenames containing\n C, C++, Fortran, and Fortran 90 module sources,\n respectively.\n \"\"\"\n c_sources = []\n cxx_sources = []\n f_sources = []\n fmodule_sources = []\n for source in sources:\n if fortran_ext_match(source):\n modules = _get_f90_modules(source)\n if modules:\n fmodule_sources.append(source)\n else:\n f_sources.append(source)\n elif cxx_ext_match(source):\n cxx_sources.append(source)\n else:\n c_sources.append(source)\n return c_sources, cxx_sources, f_sources, fmodule_sources\n\n\ndef _get_headers(directory_list):\n # get *.h files from list of directories\n headers = []\n for dir in directory_list:\n head = glob.glob(os.path.join(dir,\"*.h\")) #XXX: *.hpp files??\n headers.extend(head)\n return headers\n\ndef _get_directories(list_of_sources):\n # get unique directories from list of sources.\n direcs = []\n for file in list_of_sources:\n dir = os.path.split(file)\n if dir[0] != '' and not dir[0] in direcs:\n direcs.append(dir[0])\n return direcs\n\ndef get_dependencies(sources):\n #XXX scan sources for include statements\n return _get_headers(_get_directories(sources))\n\ndef is_local_src_dir(directory):\n \"\"\" Return true if directory is local directory.\n \"\"\"\n if not is_string(directory):\n return False\n abs_dir = os.path.abspath(directory)\n c = os.path.commonprefix([os.getcwd(),abs_dir])\n new_dir = abs_dir[len(c):].split(os.sep)\n if new_dir and not new_dir[0]:\n new_dir = new_dir[1:]\n if new_dir and new_dir[0]=='build':\n return False\n new_dir = os.sep.join(new_dir)\n return os.path.isdir(new_dir)\n\ndef _gsf_visit_func(filenames,dirname,names):\n if os.path.basename(dirname) in ['CVS','.svn','build']:\n names[:] = []\n return\n for name in names:\n if name[-1] in \"~#\":\n continue\n fullname = os.path.join(dirname,name)\n ext = os.path.splitext(fullname)[1]\n if ext and ext in ['.pyc','.o']:\n continue\n if os.path.isfile(fullname):\n filenames.append(fullname)\n\ndef get_ext_source_files(ext):\n # Get sources and any include files in the same directory.\n filenames = []\n sources = filter(is_string, ext.sources)\n filenames.extend(sources)\n filenames.extend(get_dependencies(sources))\n for d in ext.depends:\n if is_local_src_dir(d):\n os.path.walk(d,_gsf_visit_func,filenames)\n elif os.path.isfile(d):\n filenames.append(d)\n return filenames\n\ndef get_script_files(scripts):\n scripts = filter(is_string, scripts)\n return scripts\n\ndef get_lib_source_files(lib):\n filenames = []\n sources = lib[1].get('sources',[])\n sources = filter(is_string, sources)\n filenames.extend(sources)\n filenames.extend(get_dependencies(sources))\n depends = lib[1].get('depends',[])\n for d in depends:\n if is_local_src_dir(d):\n os.path.walk(d,_gsf_visit_func,filenames)\n elif os.path.isfile(d):\n filenames.append(d)\n return filenames\n\ndef get_data_files(data):\n if is_string(data):\n return [data]\n sources = data[1]\n filenames = []\n for s in sources:\n if callable(s):\n continue\n if is_local_src_dir(s):\n os.path.walk(s,_gsf_visit_func,filenames)\n elif is_string(s):\n if os.path.isfile(s):\n filenames.append(s)\n else:\n print 'Not existing data file:',s\n else:\n raise TypeError,repr(s)\n return filenames\n\ndef dot_join(*args):\n return '.'.join(filter(None,args))\n\ndef get_frame(level=0):\n try:\n return sys._getframe(level+1)\n except AttributeError:\n frame = sys.exc_info()[2].tb_frame\n for i in range(level+1):\n frame = frame.f_back\n return frame\n\n######################\n\nclass Configuration:\n\n _list_keys = ['packages','ext_modules','data_files','include_dirs',\n 'libraries','headers','scripts','py_modules']\n _dict_keys = ['package_dir']\n\n numpy_include_dirs = []\n\n def __init__(self,\n package_name=None,\n parent_name=None,\n top_path=None,\n package_path=None,\n **attrs):\n \"\"\" Construct configuration instance of a package.\n\n package_name -- name of the package\n Ex.: 'distutils'\n parent_name -- name of the parent package\n Ex.: 'numpy'\n top_path -- directory of the toplevel package\n Ex.: the directory where the numpy package source sits\n package_path -- directory of package. Will be computed by magic from the\n directory of the caller module if not specified\n Ex.: the directory where numpy.distutils is\n \"\"\"\n self.name = dot_join(parent_name, package_name)\n\n caller_frame = get_frame(1)\n caller_name = eval('__name__',caller_frame.f_globals,caller_frame.f_locals)\n\n self.local_path = get_path(caller_name, top_path)\n if top_path is None:\n top_path = self.local_path\n if package_path is None:\n package_path = self.local_path\n elif os.path.isdir(njoin(self.local_path,package_path)):\n package_path = njoin(self.local_path,package_path)\n if not os.path.isdir(package_path):\n raise ValueError(\"%r is not a directory\" % (package_path,))\n self.top_path = top_path\n self.package_path = package_path\n # this is the relative path in the installed package\n self.path_in_package = os.path.join(*self.name.split('.'))\n\n self.list_keys = copy.copy(self._list_keys)\n self.dict_keys = copy.copy(self._dict_keys)\n\n for n in self.list_keys:\n setattr(self,n,copy.copy(attrs.get(n,[])))\n\n for n in self.dict_keys:\n setattr(self,n,copy.copy(attrs.get(n,{})))\n\n known_keys = self.list_keys + self.dict_keys\n self.extra_keys = []\n for n in attrs.keys():\n if n in known_keys:\n continue\n a = attrs[n]\n setattr(self,n,a)\n if isinstance(a, list):\n self.list_keys.append(n)\n elif isinstance(a, dict):\n self.dict_keys.append(n)\n else:\n self.extra_keys.append(n)\n\n if os.path.exists(njoin(package_path,'__init__.py')):\n self.packages.append(self.name)\n self.package_dir[self.name] = package_path\n\n return\n\n def todict(self):\n \"\"\" Return configuration distionary suitable for passing\n to distutils.core.setup() function.\n \"\"\"\n d = {}\n for n in self.list_keys + self.dict_keys + self.extra_keys:\n a = getattr(self,n)\n if a:\n d[n] = a\n if self.name:\n d['name'] = self.name\n return d\n\n def info(self, message):\n print message\n\n def warn(self, message):\n print 'Warning:',message\n\n def __dict__(self):\n return self.todict()\n\n def get_distribution(self):\n import distutils.core\n dist = distutils.core._setup_distribution\n return dist\n\n def get_subpackage(self,subpackage_name,subpackage_path=None):\n \"\"\" Return subpackage configuration.\n \"\"\"\n if subpackage_name is None:\n assert subpackage_path is not None\n subpackage_name = os.path.basename(subpackage_path)\n l = subpackage_name.split('.')\n if subpackage_path is None:\n subpackage_path = njoin(*([self.local_path]+l))\n if '*' in subpackage_name:\n dirs = filter(os.path.isdir,glob.glob(subpackage_path))\n config_list = []\n for d in dirs:\n if not os.path.isfile(njoin(d,'__init__.py')):\n continue\n if 'build' in d.split(os.sep):\n continue\n n = '.'.join(d.split(os.sep)[-len(l):])\n c = self.get_subpackage(n)\n if c:\n config_list.append(c)\n return config_list\n else:\n subpackage_path = njoin(*([subpackage_path]+l[:-1]))\n subpackage_path = self._fix_paths([subpackage_path])[0]\n setup_py = njoin(subpackage_path,'setup.py')\n if not os.path.isfile(setup_py):\n setup_py = njoin(subpackage_path,'setup_%s.py' % (subpackage_name))\n\n if not os.path.isfile(setup_py):\n print 'Assuming default configuration '\\\n '(%s/{setup_%s,setup}.py was not found)' \\\n % (os.path.dirname(setup_py),subpackage_name)\n config = Configuration(subpackage_name,self.name,\n self.top_path,subpackage_path)\n else:\n # In case setup_py imports local modules:\n sys.path.insert(0,os.path.dirname(setup_py))\n try:\n info = (open(setup_py),setup_py,('.py','U',1))\n setup_name = os.path.splitext(os.path.basename(setup_py))[0]\n n = dot_join(self.name,setup_name)\n setup_module = imp.load_module('_'.join(n.split('.')),*info)\n\n if not hasattr(setup_module,'configuration'):\n print 'Assuming default configuration '\\\n '(%s does not define configuration())' % (setup_module)\n config = Configuration(subpackage_name,self.name,\n self.top_path,subpackage_path)\n else:\n args = (self.name,)\n if setup_module.configuration.func_code.co_argcount>1:\n args = args + (self.top_path,)\n config = setup_module.configuration(*args)\n\n finally:\n del sys.path[0]\n\n return config\n\n def add_subpackage(self,subpackage_name,subpackage_path=None):\n \"\"\" Add subpackage to configuration.\n \"\"\"\n config = self.get_subpackage(subpackage_name,subpackage_path)\n if not isinstance(config, list):\n config_list = [config]\n else:\n config_list = config\n for config in config_list:\n if not config:\n print 'No configuration returned, assuming unavailable.'\n else:\n if isinstance(config,Configuration):\n print 'Appending %s configuration to %s' % (config.name,self.name)\n self.dict_append(**config.todict())\n else:\n print 'Appending %s configuration to %s' % (config.get('name'),self.name)\n self.dict_append(**config)\n\n dist = self.get_distribution()\n if dist is not None:\n print 'distutils distribution has been initialized, it may be too late to add a subpackage', subpackage_name\n return\n\n def add_data_dir(self,data_path):\n \"\"\" Recursively add files under data_path to data_files list.\n Argument can be either\n - 2-sequence (,)\n - path to data directory where python datadir suffix defaults\n to package dir.\n If path is not absolute then it's datadir suffix is\n package dir + subdirname of the path.\n \"\"\"\n if is_sequence(data_path):\n d, data_path = data_path\n else:\n d = None\n if not is_string(data_path):\n raise TypeError(\"not a string: %r\" % (data_path,))\n for path in self.paths(data_path):\n if not os.path.exists(path):\n print 'Not existing data path',path\n continue\n filenames = []\n os.path.walk(path, _gsf_visit_func,filenames)\n if not os.path.isabs(path):\n npath = data_path\n if '*' in npath:\n npath = os.path.join(*(path.split(os.sep)[-len(npath.split(os.sep)):]))\n if d is None:\n d = self.path_in_package\n ds = os.path.join(d, npath)\n self.add_data_files((ds,filenames))\n else:\n if d is None:\n self.add_data_files(*filenames)\n else:\n self.add_data_files((d,filenames))\n return\n\n def add_data_files(self,*files):\n \"\"\" Add data files to configuration data_files.\n Argument(s) can be either\n - 2-sequence (,)\n - paths to data files where python datadir prefix defaults\n to package dir.\n If path is not absolute then it's datadir prefix is\n package dir + dirname of the path.\n \"\"\"\n data_dict = {}\n new_files = []\n for p in files:\n if not is_sequence(p):\n d = self.path_in_package\n if is_string(p) and not os.path.isabs(p):\n pd = os.path.dirname(p)\n if '*' in pd:\n pn = os.path.basename(p)\n n = len(pd.split(os.sep))\n for d1 in filter(os.path.isdir,self.paths(pd)):\n p = os.path.join(d1,pn)\n d1 = os.sep.join(d1.split(os.sep)[-n:])\n new_files.append((appendpath(d,d1),p))\n continue\n d = appendpath(d,pd)\n p = (d,p) \n new_files.append(p)\n \n files = []\n for prefix,filepattern in new_files:\n assert '*' not in prefix,`prefix,filepattern`\n if is_string(filepattern):\n file_list = self.paths(filepattern,include_non_existing=False)\n elif callable(filepattern):\n file_list = [filepattern]\n else:\n file_list = self.paths(*filepattern)\n\n nof_path_components = [len(f.split(os.sep))\n for f in file_list if is_string(f)]\n if nof_path_components:\n min_path_components = min(nof_path_components)-1\n else:\n min_path_components = 0\n\n for f in file_list:\n if is_string(f):\n extra_path_components = f.split(os.sep)[min_path_components:-1]\n p = njoin(*([prefix]+extra_path_components))\n else:\n p = prefix\n if not data_dict.has_key(p):\n data_dict[p] = [f]\n else:\n data_dict[p].append(f)\n\n dist = self.get_distribution()\n if dist is not None:\n dist.data_files.extend(data_dict.items())\n else:\n self.data_files.extend(data_dict.items())\n\n ### XXX Implement add_py_modules\n\n def add_include_dirs(self,*paths):\n \"\"\" Add paths to configuration include directories.\n \"\"\"\n include_dirs = self._fix_paths(paths)\n dist = self.get_distribution()\n if dist is not None:\n dist.include_dirs.extend(include_dirs)\n else:\n self.include_dirs.extend(include_dirs)\n return\n\n def add_headers(self,*files):\n \"\"\" Add installable headers to configuration.\n Argument(s) can be either\n - 2-sequence (,)\n - path(s) to header file(s) where python includedir suffix will default\n to package name.\n \"\"\"\n headers = []\n for path in files:\n if is_string(path):\n [headers.append((self.name,p)) for p in self.paths(path)]\n else:\n if not isinstance(path, (tuple, list)) or len(path) != 2:\n raise TypeError(repr(path))\n [headers.append((path[0],p)) for p in self.paths(path[1])]\n dist = self.get_distribution()\n if dist is not None:\n dist.headers.extend(headers)\n else:\n self.headers.extend(headers)\n return\n\n def _fix_paths(self,paths,include_non_existing=True):\n assert isinstance(paths,(list,tuple)),`type(paths)`\n new_paths = []\n for n in paths:\n if isinstance(n,str):\n if '*' in n or '?' in n:\n p = glob.glob(n)\n p2 = glob.glob(njoin(self.local_path,n))\n if p2:\n new_paths.extend(p2)\n elif p:\n new_paths.extend(p)\n else:\n if include_non_existing:\n new_paths.append(n)\n self.warn('could not resolve pattern: %r' % (n))\n else:\n n2 = njoin(self.local_path,n)\n if os.path.exists(n2):\n new_paths.append(n2)\n else:\n if os.path.exists(n):\n new_paths.append(n)\n elif include_non_existing:\n new_paths.append(n)\n if not os.path.exists(n):\n self.warn('not existing path: %r' % (n))\n else:\n new_paths.append(n)\n return map(minrelpath,new_paths)\n\n def paths(self,*paths,**kws):\n \"\"\" Apply glob to paths and prepend local_path if needed.\n \"\"\"\n include_non_existing = kws.get('include_non_existing',True)\n return self._fix_paths(paths,\n include_non_existing=include_non_existing)\n\n def add_extension(self,name,sources,**kw):\n \"\"\" Add extension to configuration.\n\n Keywords:\n include_dirs, define_macros, undef_macros,\n library_dirs, libraries, runtime_library_dirs,\n extra_objects, extra_compile_args, extra_link_args,\n export_symbols, swig_opts, depends, language,\n f2py_options, module_dirs\n extra_info - dict or list of dict of keywords to be\n appended to keywords.\n \"\"\"\n ext_args = copy.copy(kw)\n ext_args['name'] = dot_join(self.name,name)\n ext_args['sources'] = sources\n\n if ext_args.has_key('extra_info'):\n extra_info = ext_args['extra_info']\n del ext_args['extra_info']\n if type(extra_info) is type({}):\n extra_info = [extra_info]\n for info in extra_info:\n assert type(info) is type({}),`info`\n dict_append(ext_args,**info)\n\n for k in ext_args.keys():\n v = ext_args[k]\n if k in ['sources','depends','include_dirs','library_dirs',\n 'module_dirs','extra_objects']:\n new_v = self._fix_paths(v)\n ext_args[k] = new_v\n\n # Resolve out-of-tree dependencies\n libraries = ext_args.get('libraries',[])\n libnames = []\n ext_args['libraries'] = []\n for libname in libraries:\n if '@' in libname:\n lname,lpath = libname.split('@',1)\n lpath = os.path.abspath(njoin(self.local_path,lpath))\n if os.path.isdir(lpath):\n c = self.get_subpackage(None,lpath)\n if isinstance(c,Configuration):\n c = c.todict()\n for l in [l[0] for l in c.get('libraries',[])]:\n llname = l.split('__OF__',1)[0]\n if llname == lname:\n c.pop('name',None)\n dict_append(ext_args,**c)\n break\n continue\n libnames.append(libname)\n\n ext_args['libraries'] = libnames + ext_args['libraries']\n\n from numpy.distutils.core import Extension\n ext = Extension(**ext_args)\n self.ext_modules.append(ext)\n\n dist = self.get_distribution()\n if dist is not None:\n print 'distutils distribution has been initialized, it may be too late to add an extension', name\n return ext\n\n def add_library(self,name,sources,**build_info):\n \"\"\" Add library to configuration.\n\n Valid keywords for build_info:\n depends\n macros\n include_dirs\n extra_compiler_args\n f2py_options\n \"\"\"\n build_info = copy.copy(build_info)\n name = name #+ '__OF__' + self.name\n build_info['sources'] = sources\n\n for k in build_info.keys():\n v = build_info[k]\n if k in ['sources','depends','include_dirs','library_dirs',\n 'module_dirs','extra_objects']:\n new_v = self._fix_paths(v)\n build_info[k] = new_v\n self.libraries.append((name,build_info))\n\n dist = self.get_distribution()\n if dist is not None:\n print 'distutils distribution has been initialized, it may be too late to add a library', name\n return\n\n def add_scripts(self,*files):\n \"\"\" Add scripts to configuration.\n \"\"\"\n scripts = self._fix_paths(files)\n dist = self.get_distribution()\n if dist is not None:\n dist.scripts.extend(scripts)\n else:\n self.scripts.extend(scripts)\n return\n\n def dict_append(self,**dict):\n for key in self.list_keys:\n a = getattr(self,key)\n a.extend(dict.get(key,[]))\n for key in self.dict_keys:\n a = getattr(self,key)\n a.update(dict.get(key,{}))\n known_keys = self.list_keys + self.dict_keys + self.extra_keys\n for key in dict.keys():\n if key not in known_keys and not hasattr(self,key):\n print 'Inheriting attribute %r from %r' \\\n % (key,dict.get('name','?'))\n setattr(self,key,dict[key])\n self.extra_keys.append(key)\n return\n\n def __str__(self):\n known_keys = self.list_keys + self.dict_keys + self.extra_keys\n s = '<'+5*'-' + '\\n'\n s += 'Configuration of '+self.name+':\\n'\n for k in known_keys:\n a = getattr(self,k,None)\n if a:\n s += '%s = %r\\n' % (k,a)\n s += 5*'-' + '>'\n return s\n\n def get_config_cmd(self):\n cmd = get_cmd('config')\n cmd.ensure_finalized()\n cmd.dump_source = 0\n cmd.noisy = 0\n old_path = os.environ.get('PATH')\n if old_path:\n path = os.pathsep.join(['.',old_path])\n os.environ['PATH'] = path\n return cmd\n\n def get_build_temp_dir(self):\n cmd = get_cmd('build')\n cmd.ensure_finalized()\n return cmd.build_temp\n\n def have_f77c(self):\n \"\"\" Check for availability of Fortran 77 compiler.\n Use it inside source generating function to ensure that\n setup distribution instance has been initialized.\n \"\"\"\n simple_fortran_subroutine = '''\n subroutine simple\n end\n '''\n config_cmd = self.get_config_cmd()\n flag = config_cmd.try_compile(simple_fortran_subroutine,lang='f77')\n return flag\n\n def have_f90c(self):\n \"\"\" Check for availability of Fortran 90 compiler.\n Use it inside source generating function to ensure that\n setup distribution instance has been initialized.\n \"\"\"\n simple_fortran_subroutine = '''\n subroutine simple\n end\n '''\n config_cmd = self.get_config_cmd()\n flag = config_cmd.try_compile(simple_fortran_subroutine,lang='f90')\n return flag\n\n def append_to(self, extlib):\n \"\"\" Append libraries, include_dirs to extension or library item.\n \"\"\"\n if is_sequence(extlib):\n lib_name, build_info = extlib\n dict_append(build_info,\n libraries=self.libraries,\n include_dirs=self.include_dirs)\n else:\n from numpy.distutils.core import Extension\n assert isinstance(extlib,Extension),`extlib`\n extlib.libraries.extend(self.libraries)\n extlib.include_dirs.extend(self.include_dirs)\n return\n\n def _get_svn_revision(self,path):\n \"\"\" Return path's SVN revision number.\n \"\"\"\n entries = njoin(path,'.svn','entries')\n revision = None\n if os.path.isfile(entries):\n f = open(entries)\n m = re.search(r'revision=\"(?P\\d+)\"',f.read())\n f.close()\n if m:\n revision = int(m.group('revision'))\n return revision\n\n def get_version(self):\n \"\"\" Try to get version string of a package.\n \"\"\"\n version = getattr(self,'version',None)\n if version is not None:\n return version\n\n # Get version from version file.\n files = ['__version__.py',\n self.name.split('.')[-1]+'_version.py',\n 'version.py',\n '__svn_version__.py']\n version_vars = ['version',\n '__version__',\n self.name.split('.')[-1]+'_version']\n for f in files:\n fn = njoin(self.local_path,f)\n if os.path.isfile(fn):\n info = (open(fn),fn,('.py','U',1))\n name = os.path.splitext(os.path.basename(fn))[0]\n n = dot_join(self.name,name)\n try:\n version_module = imp.load_module('_'.join(n.split('.')),*info)\n except ImportError,msg:\n print msg\n version_module = None\n if version_module is None:\n continue\n\n for a in version_vars:\n version = getattr(version_module,a,None)\n if version is not None:\n break\n if version is not None:\n break\n\n if version is not None:\n self.version = version\n return version\n\n # Get version as SVN revision number\n revision = self._get_svn_revision(self.local_path)\n if revision is not None:\n version = str(revision)\n self.version = version\n\n return version\n\n def make_svn_version_py(self):\n \"\"\" Generate package __svn_version__.py file from SVN revision number,\n it will be removed after python exits but will be available\n when sdist, etc commands are executed.\n\n If __svn_version__.py existed before, nothing is done.\n \"\"\"\n target = njoin(self.local_path,'__svn_version__.py')\n if os.path.isfile(target):\n return\n\n def generate_svn_version_py():\n if not os.path.isfile(target):\n revision = self._get_svn_revision(self.local_path)\n assert revision is not None,'hmm, why I am not inside SVN tree???'\n version = str(revision)\n print 'Creating %s (version=%r)' % (target,version)\n f = open(target,'w')\n f.write('version = %r\\n' % (version))\n f.close()\n\n import atexit\n def rm_file(f=target):\n try: os.remove(f); print 'removed',f\n except OSError: pass\n try: os.remove(f+'c'); print 'removed',f+'c'\n except OSError: pass\n atexit.register(rm_file)\n\n return target\n\n self.add_data_files((self.path_in_package, generate_svn_version_py()))\n return\n\n def make_config_py(self,name='__config__'):\n \"\"\" Generate package __config__.py file containing system_info\n information used during building the package.\n \"\"\"\n self.py_modules.append((self.name,name,generate_config_py))\n return\n\n def get_info(self,*names):\n \"\"\" Get resources information.\n \"\"\"\n from system_info import get_info, dict_append\n info_dict = {}\n for a in names:\n dict_append(info_dict,**get_info(a))\n return info_dict\n\ndef get_cmd(cmdname,_cache={}):\n if not _cache.has_key(cmdname):\n import distutils.core\n dist = distutils.core._setup_distribution\n if dist is None:\n from distutils.errors import DistutilsInternalError\n raise DistutilsInternalError,\\\n 'setup distribution instance not initialized'\n cmd = dist.get_command_obj(cmdname)\n _cache[cmdname] = cmd\n return _cache[cmdname]\n\ndef get_numpy_include_dirs():\n # numpy_include_dirs are set by numpy/core/setup.py, otherwise []\n include_dirs = Configuration.numpy_include_dirs[:]\n if not include_dirs:\n import numpy\n if numpy.show_config is None:\n # running from numpy_core source directory\n include_dirs.append(njoin(os.path.dirname(numpy.__file__),\n 'core','include'))\n else:\n # using installed numpy core headers\n import numpy.core as core\n include_dirs.append(njoin(os.path.dirname(core.__file__),'include'))\n # else running numpy/core/setup.py\n return include_dirs\n\n#########################\n\ndef default_config_dict(name = None, parent_name = None, local_path=None):\n \"\"\" Return a configuration dictionary for usage in\n configuration() function defined in file setup_.py.\n \"\"\"\n import warnings\n warnings.warn('Use Configuration(%s,%s,top_path=%s) instead of '\\\n 'deprecated default_config_dict(%s,%s,%s)' \\\n % (`name`,`parent_name`,`local_path`,\n `name`,`parent_name`,`local_path`,\n ))\n c = Configuration(name, parent_name, local_path)\n return c.todict()\n\n\ndef dict_append(d,**kws):\n for k,v in kws.items():\n if d.has_key(k):\n d[k].extend(v)\n else:\n d[k] = v\n\ndef appendpath(prefix,path):\n if not ('/' == os.path.sep):\n prefix = prefix.replace('/',os.path.sep)\n path = path.replace('/',os.path.sep)\n drive = ''\n if os.path.isabs(path):\n drive = os.path.splitdrive(prefix)[0]\n absprefix = os.path.splitdrive(os.path.abspath(prefix))[1]\n pathdrive,path = os.path.splitdrive(path)\n d = os.path.commonprefix([absprefix,path])\n if os.path.join(absprefix[:len(d)],absprefix[len(d):])!=absprefix \\\n or os.path.join(path[:len(d)],path[len(d):])!=path:\n # Handle invalid paths\n d = os.path.dirname(d)\n subpath = path[len(d):]\n if os.path.isabs(subpath):\n subpath = subpath[1:]\n else:\n subpath = path\n return os.path.normpath(njoin(drive + prefix, subpath))\n\n\n\n\n\ndef generate_config_py(target):\n \"\"\" Generate config.py file containing system_info information\n used during building the package.\n\n Usage:\\\n config['py_modules'].append((packagename, '__config__',generate_config_py))\n \"\"\"\n from numpy.distutils.system_info import system_info\n from distutils.dir_util import mkpath\n mkpath(os.path.dirname(target))\n f = open(target,'w')\n f.write('# This file is generated by %s\\n' % (os.path.abspath(sys.argv[0])))\n f.write('# It contains system_info results at the time of building this package.\\n')\n f.write('__all__ = [\"get_info\",\"show\"]\\n\\n')\n for k,i in system_info.saved_results.items():\n f.write('%s=%r\\n' % (k,i))\n f.write('\\ndef get_info(name): g=globals(); return g.get(name,g.get(name+\"_info\",{}))\\n')\n f.write('''\ndef show():\n for name,info_dict in globals().items():\n if name[0]==\"_\" or type(info_dict) is not type({}): continue\n print name+\":\"\n if not info_dict:\n print \" NOT AVAILABLE\"\n for k,v in info_dict.items():\n v = str(v)\n if k==\\'sources\\' and len(v)>200: v = v[:60]+\\' ...\\\\n... \\'+v[-60:]\n print \\' %s = %s\\'%(k,v)\n print\n return\n ''')\n\n f.close()\n return target\n\ndef generate_svn_version_py(extension, build_dir):\n \"\"\" Generate __svn_version__.py file containing SVN\n revision number of a module.\n\n To use, add the following codelet to setup\n configuration(..) function\n\n ext = Extension(dot_join(config['name'],'__svn_version__'),\n sources=[generate_svn_version_py])\n ext.local_path = local_path\n config['ext_modules'].append(ext)\n\n \"\"\"\n from distutils import dep_util\n local_path = extension.local_path\n target = njoin(build_dir, '__svn_version__.py')\n entries = njoin(local_path,'.svn','entries')\n if os.path.isfile(entries):\n if not dep_util.newer(entries, target):\n return target\n elif os.path.isfile(target):\n return target\n\n revision = get_svn_revision(local_path)\n f = open(target,'w')\n f.write('revision=%s\\n' % (revision))\n f.close()\n return target\n", + "source_code_before": "import os\nimport re\nimport sys\nimport imp\nimport copy\nimport glob\n\n__all__ = ['Configuration', 'get_numpy_include_dirs', 'default_config_dict',\n 'dict_append', 'appendpath', 'generate_config_py',\n 'generate_svn_version_py', 'get_cmd', 'allpath',\n 'terminal_has_colors', 'red_text', 'green_text', 'yellow_text',\n 'blue_text', 'cyan_text', 'cyg2win32', 'all_strings',\n 'has_f_sources', 'has_cxx_sources', 'filter_sources',\n 'get_dependencies', 'is_local_src_dir', 'get_ext_source_files',\n 'get_script_files', 'get_lib_source_files', 'get_data_files',\n 'dot_join', 'get_frame', 'minrelpath','njoin']\n\ndef allpath(name):\n \"Convert a /-separated pathname to one using the OS's path separator.\"\n splitted = name.split('/')\n return os.path.join(*splitted)\n\ndef get_path(mod_name,parent_path=None):\n \"\"\" Return path of the module.\n\n Returned path is relative to parent_path when given,\n otherwise it is absolute path.\n \"\"\"\n if mod_name == '__main__':\n d = os.path.abspath('.')\n elif mod_name == '__builtin__':\n #builtin if/then added by Pearu for use in core.run_setup.\n d = os.path.dirname(os.path.abspath(sys.argv[0]))\n else:\n __import__(mod_name)\n mod = sys.modules[mod_name]\n file = mod.__file__\n d = os.path.dirname(os.path.abspath(file))\n if parent_path is not None:\n pd = os.path.abspath(parent_path)\n if pd==d[:len(pd)]:\n d = d[len(pd)+1:]\n return d or '.'\n\ndef njoin(*path):\n \"\"\" Join two or more pathname components +\n - convert a /-separated pathname to one using the OS's path separator.\n - resolve `..` from path.\n \"\"\"\n if isinstance(path,tuple):\n path = os.path.join(*path)\n if not isinstance(path,str): return path\n if not ('/' == os.path.sep):\n path = path.replace('/',os.path.sep)\n return minrelpath(path)\n\ndef minrelpath(path):\n \"\"\" Resolve `..` from path.\n \"\"\"\n if not isinstance(path, str): return path\n if '..' not in path: return path\n l = path.split(os.sep)\n j = 1\n while l:\n try:\n i = l.index('..',j)\n except ValueError:\n break\n if l[i-1]=='..':\n j += 1\n else:\n del l[i],l[i-1]\n j = 1\n if not l: return ''\n return os.path.join(*l)\n\n# Hooks for colored terminal output.\n# See also http://www.livinglogic.de/Python/ansistyle\ndef terminal_has_colors():\n if sys.platform=='cygwin' and not os.environ.has_key('USE_COLOR'):\n # Avoid importing curses that causes illegal operation\n # with a message:\n # PYTHON2 caused an invalid page fault in\n # module CYGNURSES7.DLL as 015f:18bbfc28\n # Details: Python 2.3.3 [GCC 3.3.1 (cygming special)]\n # ssh to Win32 machine from debian\n # curses.version is 2.2\n # CYGWIN_98-4.10, release 1.5.7(0.109/3/2))\n return 0\n if hasattr(sys.stdout,'isatty') and sys.stdout.isatty():\n try:\n import curses\n curses.setupterm()\n if (curses.tigetnum(\"colors\") >= 0\n and curses.tigetnum(\"pairs\") >= 0\n and ((curses.tigetstr(\"setf\") is not None\n and curses.tigetstr(\"setb\") is not None)\n or (curses.tigetstr(\"setaf\") is not None\n and curses.tigetstr(\"setab\") is not None)\n or curses.tigetstr(\"scp\") is not None)):\n return 1\n except Exception,msg:\n pass\n return 0\n\nif terminal_has_colors():\n def red_text(s): return '\\x1b[31m%s\\x1b[0m'%s\n def green_text(s): return '\\x1b[32m%s\\x1b[0m'%s\n def yellow_text(s): return '\\x1b[33m%s\\x1b[0m'%s\n def blue_text(s): return '\\x1b[34m%s\\x1b[0m'%s\n def cyan_text(s): return '\\x1b[35m%s\\x1b[0m'%s\nelse:\n def red_text(s): return s\n def green_text(s): return s\n def yellow_text(s): return s\n def cyan_text(s): return s\n def blue_text(s): return s\n\n#########################\n\ndef cyg2win32(path):\n if sys.platform=='cygwin' and path.startswith('/cygdrive'):\n path = path[10] + ':' + os.path.normcase(path[11:])\n return path\n\n#########################\n\n#XXX need support for .C that is also C++\ncxx_ext_match = re.compile(r'.*[.](cpp|cxx|cc)\\Z',re.I).match\nfortran_ext_match = re.compile(r'.*[.](f90|f95|f77|for|ftn|f)\\Z',re.I).match\nf90_ext_match = re.compile(r'.*[.](f90|f95)\\Z',re.I).match\nf90_module_name_match = re.compile(r'\\s*module\\s*(?P[\\w_]+)',re.I).match\ndef _get_f90_modules(source):\n \"\"\" Return a list of Fortran f90 module names that\n given source file defines.\n \"\"\"\n if not f90_ext_match(source):\n return []\n modules = []\n f = open(source,'r')\n f_readlines = getattr(f,'xreadlines',f.readlines)\n for line in f_readlines():\n m = f90_module_name_match(line)\n if m:\n name = m.group('name')\n modules.append(name)\n # break # XXX can we assume that there is one module per file?\n f.close()\n return modules\n\ndef is_string(s):\n return isinstance(s, str)\n\ndef all_strings(lst):\n \"\"\" Return True if all items in lst are string objects. \"\"\"\n for item in lst:\n if not is_string(item):\n return False\n return True\n\ndef is_sequence(seq):\n if is_string(seq):\n return False\n try:\n len(seq)\n except:\n return False\n return True\n\ndef has_f_sources(sources):\n \"\"\" Return True if sources contains Fortran files \"\"\"\n for source in sources:\n if fortran_ext_match(source):\n return True\n return False\n\ndef has_cxx_sources(sources):\n \"\"\" Return True if sources contains C++ files \"\"\"\n for source in sources:\n if cxx_ext_match(source):\n return True\n return False\n\ndef filter_sources(sources):\n \"\"\" Return four lists of filenames containing\n C, C++, Fortran, and Fortran 90 module sources,\n respectively.\n \"\"\"\n c_sources = []\n cxx_sources = []\n f_sources = []\n fmodule_sources = []\n for source in sources:\n if fortran_ext_match(source):\n modules = _get_f90_modules(source)\n if modules:\n fmodule_sources.append(source)\n else:\n f_sources.append(source)\n elif cxx_ext_match(source):\n cxx_sources.append(source)\n else:\n c_sources.append(source)\n return c_sources, cxx_sources, f_sources, fmodule_sources\n\n\ndef _get_headers(directory_list):\n # get *.h files from list of directories\n headers = []\n for dir in directory_list:\n head = glob.glob(os.path.join(dir,\"*.h\")) #XXX: *.hpp files??\n headers.extend(head)\n return headers\n\ndef _get_directories(list_of_sources):\n # get unique directories from list of sources.\n direcs = []\n for file in list_of_sources:\n dir = os.path.split(file)\n if dir[0] != '' and not dir[0] in direcs:\n direcs.append(dir[0])\n return direcs\n\ndef get_dependencies(sources):\n #XXX scan sources for include statements\n return _get_headers(_get_directories(sources))\n\ndef is_local_src_dir(directory):\n \"\"\" Return true if directory is local directory.\n \"\"\"\n if not is_string(directory):\n return False\n abs_dir = os.path.abspath(directory)\n c = os.path.commonprefix([os.getcwd(),abs_dir])\n new_dir = abs_dir[len(c):].split(os.sep)\n if new_dir and not new_dir[0]:\n new_dir = new_dir[1:]\n if new_dir and new_dir[0]=='build':\n return False\n new_dir = os.sep.join(new_dir)\n return os.path.isdir(new_dir)\n\ndef _gsf_visit_func(filenames,dirname,names):\n if os.path.basename(dirname) in ['CVS','.svn','build']:\n names[:] = []\n return\n for name in names:\n if name[-1] in \"~#\":\n continue\n fullname = os.path.join(dirname,name)\n ext = os.path.splitext(fullname)[1]\n if ext and ext in ['.pyc','.o']:\n continue\n if os.path.isfile(fullname):\n filenames.append(fullname)\n\ndef get_ext_source_files(ext):\n # Get sources and any include files in the same directory.\n filenames = []\n sources = filter(is_string, ext.sources)\n filenames.extend(sources)\n filenames.extend(get_dependencies(sources))\n for d in ext.depends:\n if is_local_src_dir(d):\n os.path.walk(d,_gsf_visit_func,filenames)\n elif os.path.isfile(d):\n filenames.append(d)\n return filenames\n\ndef get_script_files(scripts):\n scripts = filter(is_string, scripts)\n return scripts\n\ndef get_lib_source_files(lib):\n filenames = []\n sources = lib[1].get('sources',[])\n sources = filter(is_string, sources)\n filenames.extend(sources)\n filenames.extend(get_dependencies(sources))\n depends = lib[1].get('depends',[])\n for d in depends:\n if is_local_src_dir(d):\n os.path.walk(d,_gsf_visit_func,filenames)\n elif os.path.isfile(d):\n filenames.append(d)\n return filenames\n\ndef get_data_files(data):\n if is_string(data):\n return [data]\n sources = data[1]\n filenames = []\n for s in sources:\n if callable(s):\n continue\n if is_local_src_dir(s):\n os.path.walk(s,_gsf_visit_func,filenames)\n elif is_string(s):\n if os.path.isfile(s):\n filenames.append(s)\n else:\n print 'Not existing data file:',s\n else:\n raise TypeError,repr(s)\n return filenames\n\ndef dot_join(*args):\n return '.'.join(filter(None,args))\n\ndef get_frame(level=0):\n try:\n return sys._getframe(level+1)\n except AttributeError:\n frame = sys.exc_info()[2].tb_frame\n for i in range(level+1):\n frame = frame.f_back\n return frame\n\n######################\n\nclass Configuration:\n\n _list_keys = ['packages','ext_modules','data_files','include_dirs',\n 'libraries','headers','scripts','py_modules']\n _dict_keys = ['package_dir']\n\n numpy_include_dirs = []\n\n def __init__(self,\n package_name=None,\n parent_name=None,\n top_path=None,\n package_path=None,\n **attrs):\n \"\"\" Construct configuration instance of a package.\n\n package_name -- name of the package\n Ex.: 'distutils'\n parent_name -- name of the parent package\n Ex.: 'numpy'\n top_path -- directory of the toplevel package\n Ex.: the directory where the numpy package source sits\n package_path -- directory of package. Will be computed by magic from the\n directory of the caller module if not specified\n Ex.: the directory where numpy.distutils is\n \"\"\"\n self.name = dot_join(parent_name, package_name)\n\n caller_frame = get_frame(1)\n caller_name = eval('__name__',caller_frame.f_globals,caller_frame.f_locals)\n\n self.local_path = get_path(caller_name, top_path)\n if top_path is None:\n top_path = self.local_path\n if package_path is None:\n package_path = self.local_path\n elif os.path.isdir(njoin(self.local_path,package_path)):\n package_path = njoin(self.local_path,package_path)\n if not os.path.isdir(package_path):\n raise ValueError(\"%r is not a directory\" % (package_path,))\n self.top_path = top_path\n self.package_path = package_path\n # this is the relative path in the installed package\n self.path_in_package = os.path.join(*self.name.split('.'))\n\n self.list_keys = copy.copy(self._list_keys)\n self.dict_keys = copy.copy(self._dict_keys)\n\n for n in self.list_keys:\n setattr(self,n,copy.copy(attrs.get(n,[])))\n\n for n in self.dict_keys:\n setattr(self,n,copy.copy(attrs.get(n,{})))\n\n known_keys = self.list_keys + self.dict_keys\n self.extra_keys = []\n for n in attrs.keys():\n if n in known_keys:\n continue\n a = attrs[n]\n setattr(self,n,a)\n if isinstance(a, list):\n self.list_keys.append(n)\n elif isinstance(a, dict):\n self.dict_keys.append(n)\n else:\n self.extra_keys.append(n)\n\n if os.path.exists(njoin(package_path,'__init__.py')):\n self.packages.append(self.name)\n self.package_dir[self.name] = package_path\n\n return\n\n def todict(self):\n \"\"\" Return configuration distionary suitable for passing\n to distutils.core.setup() function.\n \"\"\"\n d = {}\n for n in self.list_keys + self.dict_keys + self.extra_keys:\n a = getattr(self,n)\n if a:\n d[n] = a\n if self.name:\n d['name'] = self.name\n return d\n\n def info(self, message):\n print message\n\n def warn(self, message):\n print 'Warning:',message\n\n def __dict__(self):\n return self.todict()\n\n def get_distribution(self):\n import distutils.core\n dist = distutils.core._setup_distribution\n return dist\n\n def get_subpackage(self,subpackage_name,subpackage_path=None):\n \"\"\" Return subpackage configuration.\n \"\"\"\n if subpackage_name is None:\n assert subpackage_path is not None\n subpackage_name = os.path.basename(subpackage_path)\n l = subpackage_name.split('.')\n if subpackage_path is None:\n subpackage_path = njoin(*([self.local_path]+l))\n if '*' in subpackage_name:\n dirs = filter(os.path.isdir,glob.glob(subpackage_path))\n config_list = []\n for d in dirs:\n if not os.path.isfile(njoin(d,'__init__.py')):\n continue\n if 'build' in d.split(os.sep):\n continue\n n = '.'.join(d.split(os.sep)[-len(l):])\n c = self.get_subpackage(n)\n if c:\n config_list.append(c)\n return config_list\n else:\n subpackage_path = njoin(*([subpackage_path]+l[:-1]))\n subpackage_path = self._fix_paths([subpackage_path])[0]\n setup_py = njoin(subpackage_path,'setup.py')\n if not os.path.isfile(setup_py):\n setup_py = njoin(subpackage_path,'setup_%s.py' % (subpackage_name))\n\n if not os.path.isfile(setup_py):\n print 'Assuming default configuration '\\\n '(%s/{setup_%s,setup}.py was not found)' \\\n % (os.path.dirname(setup_py),subpackage_name)\n config = Configuration(subpackage_name,self.name,\n self.top_path,subpackage_path)\n else:\n # In case setup_py imports local modules:\n sys.path.insert(0,os.path.dirname(setup_py))\n try:\n info = (open(setup_py),setup_py,('.py','U',1))\n setup_name = os.path.splitext(os.path.basename(setup_py))[0]\n n = dot_join(self.name,setup_name)\n setup_module = imp.load_module('_'.join(n.split('.')),*info)\n\n if not hasattr(setup_module,'configuration'):\n print 'Assuming default configuration '\\\n '(%s does not define configuration())' % (setup_module)\n config = Configuration(subpackage_name,self.name,\n self.top_path,subpackage_path)\n else:\n args = (self.name,)\n if setup_module.configuration.func_code.co_argcount>1:\n args = args + (self.top_path,)\n config = setup_module.configuration(*args)\n\n finally:\n del sys.path[0]\n\n return config\n\n def add_subpackage(self,subpackage_name,subpackage_path=None):\n \"\"\" Add subpackage to configuration.\n \"\"\"\n config = self.get_subpackage(subpackage_name,subpackage_path)\n if not isinstance(config, list):\n config_list = [config]\n else:\n config_list = config\n for config in config_list:\n if not config:\n print 'No configuration returned, assuming unavailable.'\n else:\n if isinstance(config,Configuration):\n print 'Appending %s configuration to %s' % (config.name,self.name)\n self.dict_append(**config.todict())\n else:\n print 'Appending %s configuration to %s' % (config.get('name'),self.name)\n self.dict_append(**config)\n\n dist = self.get_distribution()\n if dist is not None:\n print 'distutils distribution has been initialized, it may be too late to add a subpackage', subpackage_name\n return\n\n def add_data_dir(self,data_path):\n \"\"\" Recursively add files under data_path to data_files list.\n Argument can be either\n - 2-sequence (,)\n - path to data directory where python datadir suffix defaults\n to package dir.\n If path is not absolute then it's datadir suffix is\n package dir + subdirname of the path.\n \"\"\"\n if is_sequence(data_path):\n d, data_path = data_path\n else:\n d = None\n if not is_string(data_path):\n raise TypeError(\"not a string: %r\" % (data_path,))\n for path in self.paths(data_path):\n if not os.path.exists(path):\n print 'Not existing data path',path\n continue\n filenames = []\n os.path.walk(path, _gsf_visit_func,filenames)\n if not os.path.isabs(path):\n npath = data_path\n if '*' in npath:\n npath = os.path.join(*(path.split(os.sep)[-len(npath.split(os.sep)):]))\n if d is None:\n d = self.path_in_package\n ds = os.path.join(d, npath)\n self.add_data_files((ds,filenames))\n else:\n if d is None:\n self.add_data_files(*filenames)\n else:\n self.add_data_files((d,filenames))\n return\n\n def add_data_files(self,*files):\n \"\"\" Add data files to configuration data_files.\n Argument(s) can be either\n - 2-sequence (,)\n - paths to data files where python datadir prefix defaults\n to package dir.\n If path is not absolute then it's datadir prefix is\n package dir + dirname of the path.\n \"\"\"\n new_files = []\n for p in files:\n if isinstance(p,str) and '*' in p:\n new_files.extend(self.paths(p))\n else:\n new_files.append(p)\n files = new_files\n data_dict = {}\n new_files = []\n for p in files:\n if not is_sequence(p):\n d = self.path_in_package\n if is_string(p) and not os.path.isabs(p):\n d = appendpath(d,os.path.dirname(p))\n p = (d,p)\n new_files.append(p)\n files = []\n for prefix,filepattern in new_files:\n if is_string(filepattern):\n file_list = self.paths(filepattern)\n elif callable(filepattern):\n file_list = [filepattern]\n else:\n file_list = self.paths(*filepattern)\n\n nof_path_components = [len(f.split(os.sep))\n for f in file_list if is_string(f)]\n if nof_path_components:\n min_path_components = min(nof_path_components)-1\n else:\n min_path_components = 0\n\n for f in file_list:\n if is_string(f):\n extra_path_components = f.split(os.sep)[min_path_components:-1]\n p = njoin(*([prefix]+extra_path_components))\n else:\n p = prefix\n if not data_dict.has_key(p):\n data_dict[p] = [f]\n else:\n data_dict[p].append(f)\n\n dist = self.get_distribution()\n if dist is not None:\n dist.data_files.extend(data_dict.items())\n else:\n self.data_files.extend(data_dict.items())\n\n ### XXX Implement add_py_modules\n\n def add_include_dirs(self,*paths):\n \"\"\" Add paths to configuration include directories.\n \"\"\"\n include_dirs = self._fix_paths(paths)\n dist = self.get_distribution()\n if dist is not None:\n dist.include_dirs.extend(include_dirs)\n else:\n self.include_dirs.extend(include_dirs)\n return\n\n def add_headers(self,*files):\n \"\"\" Add installable headers to configuration.\n Argument(s) can be either\n - 2-sequence (,)\n - path(s) to header file(s) where python includedir suffix will default\n to package name.\n \"\"\"\n headers = []\n for path in files:\n if is_string(path):\n [headers.append((self.name,p)) for p in self.paths(path)]\n else:\n if not isinstance(path, (tuple, list)) or len(path) != 2:\n raise TypeError(repr(path))\n [headers.append((path[0],p)) for p in self.paths(path[1])]\n dist = self.get_distribution()\n if dist is not None:\n dist.headers.extend(headers)\n else:\n self.headers.extend(headers)\n return\n\n def _fix_paths(self,paths):\n assert isinstance(paths,(list,tuple)),`type(paths)`\n new_paths = []\n for n in paths:\n if isinstance(n,str):\n if '*' in n or '?' in n:\n p = glob.glob(n)\n p2 = glob.glob(njoin(self.local_path,n))\n if p2:\n new_paths.extend(p2)\n elif p:\n new_paths.extend(p)\n else:\n new_paths.append(n)\n self.warn('could not resolve pattern: %r' % (n))\n else:\n n2 = njoin(self.local_path,n)\n if os.path.exists(n2):\n new_paths.append(n2)\n else:\n new_paths.append(n)\n if not os.path.exists(n):\n self.warn('not existing path: %r' % (n))\n else:\n new_paths.append(n)\n return map(minrelpath,new_paths)\n\n def paths(self,*paths):\n \"\"\" Apply glob to paths and prepend local_path if needed.\n \"\"\"\n return self._fix_paths(paths)\n\n def add_extension(self,name,sources,**kw):\n \"\"\" Add extension to configuration.\n\n Keywords:\n include_dirs, define_macros, undef_macros,\n library_dirs, libraries, runtime_library_dirs,\n extra_objects, extra_compile_args, extra_link_args,\n export_symbols, swig_opts, depends, language,\n f2py_options, module_dirs\n extra_info - dict or list of dict of keywords to be\n appended to keywords.\n \"\"\"\n ext_args = copy.copy(kw)\n ext_args['name'] = dot_join(self.name,name)\n ext_args['sources'] = sources\n\n if ext_args.has_key('extra_info'):\n extra_info = ext_args['extra_info']\n del ext_args['extra_info']\n if type(extra_info) is type({}):\n extra_info = [extra_info]\n for info in extra_info:\n assert type(info) is type({}),`info`\n dict_append(ext_args,**info)\n\n for k in ext_args.keys():\n v = ext_args[k]\n if k in ['sources','depends','include_dirs','library_dirs',\n 'module_dirs','extra_objects']:\n new_v = self._fix_paths(v)\n ext_args[k] = new_v\n\n # Resolve out-of-tree dependencies\n libraries = ext_args.get('libraries',[])\n libnames = []\n ext_args['libraries'] = []\n for libname in libraries:\n if '@' in libname:\n lname,lpath = libname.split('@',1)\n lpath = os.path.abspath(njoin(self.local_path,lpath))\n if os.path.isdir(lpath):\n c = self.get_subpackage(None,lpath)\n if isinstance(c,Configuration):\n c = c.todict()\n for l in [l[0] for l in c.get('libraries',[])]:\n llname = l.split('__OF__',1)[0]\n if llname == lname:\n c.pop('name',None)\n dict_append(ext_args,**c)\n break\n continue\n libnames.append(libname)\n\n ext_args['libraries'] = libnames + ext_args['libraries']\n\n from numpy.distutils.core import Extension\n ext = Extension(**ext_args)\n self.ext_modules.append(ext)\n\n dist = self.get_distribution()\n if dist is not None:\n print 'distutils distribution has been initialized, it may be too late to add an extension', name\n return ext\n\n def add_library(self,name,sources,**build_info):\n \"\"\" Add library to configuration.\n\n Valid keywords for build_info:\n depends\n macros\n include_dirs\n extra_compiler_args\n f2py_options\n \"\"\"\n build_info = copy.copy(build_info)\n name = name #+ '__OF__' + self.name\n build_info['sources'] = sources\n\n for k in build_info.keys():\n v = build_info[k]\n if k in ['sources','depends','include_dirs','library_dirs',\n 'module_dirs','extra_objects']:\n new_v = self._fix_paths(v)\n build_info[k] = new_v\n self.libraries.append((name,build_info))\n\n dist = self.get_distribution()\n if dist is not None:\n print 'distutils distribution has been initialized, it may be too late to add a library', name\n return\n\n def add_scripts(self,*files):\n \"\"\" Add scripts to configuration.\n \"\"\"\n scripts = self._fix_paths(files)\n dist = self.get_distribution()\n if dist is not None:\n dist.scripts.extend(scripts)\n else:\n self.scripts.extend(scripts)\n return\n\n def dict_append(self,**dict):\n for key in self.list_keys:\n a = getattr(self,key)\n a.extend(dict.get(key,[]))\n for key in self.dict_keys:\n a = getattr(self,key)\n a.update(dict.get(key,{}))\n known_keys = self.list_keys + self.dict_keys + self.extra_keys\n for key in dict.keys():\n if key not in known_keys and not hasattr(self,key):\n print 'Inheriting attribute %r from %r' \\\n % (key,dict.get('name','?'))\n setattr(self,key,dict[key])\n self.extra_keys.append(key)\n return\n\n def __str__(self):\n known_keys = self.list_keys + self.dict_keys + self.extra_keys\n s = '<'+5*'-' + '\\n'\n s += 'Configuration of '+self.name+':\\n'\n for k in known_keys:\n a = getattr(self,k,None)\n if a:\n s += '%s = %r\\n' % (k,a)\n s += 5*'-' + '>'\n return s\n\n def get_config_cmd(self):\n cmd = get_cmd('config')\n cmd.ensure_finalized()\n cmd.dump_source = 0\n cmd.noisy = 0\n old_path = os.environ.get('PATH')\n if old_path:\n path = os.pathsep.join(['.',old_path])\n os.environ['PATH'] = path\n return cmd\n\n def get_build_temp_dir(self):\n cmd = get_cmd('build')\n cmd.ensure_finalized()\n return cmd.build_temp\n\n def have_f77c(self):\n \"\"\" Check for availability of Fortran 77 compiler.\n Use it inside source generating function to ensure that\n setup distribution instance has been initialized.\n \"\"\"\n simple_fortran_subroutine = '''\n subroutine simple\n end\n '''\n config_cmd = self.get_config_cmd()\n flag = config_cmd.try_compile(simple_fortran_subroutine,lang='f77')\n return flag\n\n def have_f90c(self):\n \"\"\" Check for availability of Fortran 90 compiler.\n Use it inside source generating function to ensure that\n setup distribution instance has been initialized.\n \"\"\"\n simple_fortran_subroutine = '''\n subroutine simple\n end\n '''\n config_cmd = self.get_config_cmd()\n flag = config_cmd.try_compile(simple_fortran_subroutine,lang='f90')\n return flag\n\n def append_to(self, extlib):\n \"\"\" Append libraries, include_dirs to extension or library item.\n \"\"\"\n if is_sequence(extlib):\n lib_name, build_info = extlib\n dict_append(build_info,\n libraries=self.libraries,\n include_dirs=self.include_dirs)\n else:\n from numpy.distutils.core import Extension\n assert isinstance(extlib,Extension),`extlib`\n extlib.libraries.extend(self.libraries)\n extlib.include_dirs.extend(self.include_dirs)\n return\n\n def _get_svn_revision(self,path):\n \"\"\" Return path's SVN revision number.\n \"\"\"\n entries = njoin(path,'.svn','entries')\n revision = None\n if os.path.isfile(entries):\n f = open(entries)\n m = re.search(r'revision=\"(?P\\d+)\"',f.read())\n f.close()\n if m:\n revision = int(m.group('revision'))\n return revision\n\n def get_version(self):\n \"\"\" Try to get version string of a package.\n \"\"\"\n version = getattr(self,'version',None)\n if version is not None:\n return version\n\n # Get version from version file.\n files = ['__version__.py',\n self.name.split('.')[-1]+'_version.py',\n 'version.py',\n '__svn_version__.py']\n version_vars = ['version',\n '__version__',\n self.name.split('.')[-1]+'_version']\n for f in files:\n fn = njoin(self.local_path,f)\n if os.path.isfile(fn):\n info = (open(fn),fn,('.py','U',1))\n name = os.path.splitext(os.path.basename(fn))[0]\n n = dot_join(self.name,name)\n try:\n version_module = imp.load_module('_'.join(n.split('.')),*info)\n except ImportError,msg:\n print msg\n version_module = None\n if version_module is None:\n continue\n\n for a in version_vars:\n version = getattr(version_module,a,None)\n if version is not None:\n break\n if version is not None:\n break\n\n if version is not None:\n self.version = version\n return version\n\n # Get version as SVN revision number\n revision = self._get_svn_revision(self.local_path)\n if revision is not None:\n version = str(revision)\n self.version = version\n\n return version\n\n def make_svn_version_py(self):\n \"\"\" Generate package __svn_version__.py file from SVN revision number,\n it will be removed after python exits but will be available\n when sdist, etc commands are executed.\n\n If __svn_version__.py existed before, nothing is done.\n \"\"\"\n target = njoin(self.local_path,'__svn_version__.py')\n if os.path.isfile(target):\n return\n\n def generate_svn_version_py():\n if not os.path.isfile(target):\n revision = self._get_svn_revision(self.local_path)\n assert revision is not None,'hmm, why I am not inside SVN tree???'\n version = str(revision)\n print 'Creating %s (version=%r)' % (target,version)\n f = open(target,'w')\n f.write('version = %r\\n' % (version))\n f.close()\n\n import atexit\n def rm_file(f=target):\n try: os.remove(f); print 'removed',f\n except OSError: pass\n try: os.remove(f+'c'); print 'removed',f+'c'\n except OSError: pass\n atexit.register(rm_file)\n\n return target\n\n self.add_data_files((self.path_in_package, generate_svn_version_py()))\n return\n\n def make_config_py(self,name='__config__'):\n \"\"\" Generate package __config__.py file containing system_info\n information used during building the package.\n \"\"\"\n self.py_modules.append((self.name,name,generate_config_py))\n return\n\n def get_info(self,*names):\n \"\"\" Get resources information.\n \"\"\"\n from system_info import get_info, dict_append\n info_dict = {}\n for a in names:\n dict_append(info_dict,**get_info(a))\n return info_dict\n\ndef get_cmd(cmdname,_cache={}):\n if not _cache.has_key(cmdname):\n import distutils.core\n dist = distutils.core._setup_distribution\n if dist is None:\n from distutils.errors import DistutilsInternalError\n raise DistutilsInternalError,\\\n 'setup distribution instance not initialized'\n cmd = dist.get_command_obj(cmdname)\n _cache[cmdname] = cmd\n return _cache[cmdname]\n\ndef get_numpy_include_dirs():\n # numpy_include_dirs are set by numpy/core/setup.py, otherwise []\n include_dirs = Configuration.numpy_include_dirs[:]\n if not include_dirs:\n import numpy\n if numpy.show_config is None:\n # running from numpy_core source directory\n include_dirs.append(njoin(os.path.dirname(numpy.__file__),\n 'core','include'))\n else:\n # using installed numpy core headers\n import numpy.core as core\n include_dirs.append(njoin(os.path.dirname(core.__file__),'include'))\n # else running numpy/core/setup.py\n return include_dirs\n\n#########################\n\ndef default_config_dict(name = None, parent_name = None, local_path=None):\n \"\"\" Return a configuration dictionary for usage in\n configuration() function defined in file setup_.py.\n \"\"\"\n import warnings\n warnings.warn('Use Configuration(%s,%s,top_path=%s) instead of '\\\n 'deprecated default_config_dict(%s,%s,%s)' \\\n % (`name`,`parent_name`,`local_path`,\n `name`,`parent_name`,`local_path`,\n ))\n c = Configuration(name, parent_name, local_path)\n return c.todict()\n\n\ndef dict_append(d,**kws):\n for k,v in kws.items():\n if d.has_key(k):\n d[k].extend(v)\n else:\n d[k] = v\n\ndef appendpath(prefix,path):\n if not ('/' == os.path.sep):\n prefix = prefix.replace('/',os.path.sep)\n path = path.replace('/',os.path.sep)\n drive = ''\n if os.path.isabs(path):\n drive = os.path.splitdrive(prefix)[0]\n absprefix = os.path.splitdrive(os.path.abspath(prefix))[1]\n pathdrive,path = os.path.splitdrive(path)\n d = os.path.commonprefix([absprefix,path])\n if os.path.join(absprefix[:len(d)],absprefix[len(d):])!=absprefix \\\n or os.path.join(path[:len(d)],path[len(d):])!=path:\n # Handle invalid paths\n d = os.path.dirname(d)\n subpath = path[len(d):]\n if os.path.isabs(subpath):\n subpath = subpath[1:]\n else:\n subpath = path\n return os.path.normpath(njoin(drive + prefix, subpath))\n\n\n\n\n\ndef generate_config_py(target):\n \"\"\" Generate config.py file containing system_info information\n used during building the package.\n\n Usage:\\\n config['py_modules'].append((packagename, '__config__',generate_config_py))\n \"\"\"\n from numpy.distutils.system_info import system_info\n from distutils.dir_util import mkpath\n mkpath(os.path.dirname(target))\n f = open(target,'w')\n f.write('# This file is generated by %s\\n' % (os.path.abspath(sys.argv[0])))\n f.write('# It contains system_info results at the time of building this package.\\n')\n f.write('__all__ = [\"get_info\",\"show\"]\\n\\n')\n for k,i in system_info.saved_results.items():\n f.write('%s=%r\\n' % (k,i))\n f.write('\\ndef get_info(name): g=globals(); return g.get(name,g.get(name+\"_info\",{}))\\n')\n f.write('''\ndef show():\n for name,info_dict in globals().items():\n if name[0]==\"_\" or type(info_dict) is not type({}): continue\n print name+\":\"\n if not info_dict:\n print \" NOT AVAILABLE\"\n for k,v in info_dict.items():\n v = str(v)\n if k==\\'sources\\' and len(v)>200: v = v[:60]+\\' ...\\\\n... \\'+v[-60:]\n print \\' %s = %s\\'%(k,v)\n print\n return\n ''')\n\n f.close()\n return target\n\ndef generate_svn_version_py(extension, build_dir):\n \"\"\" Generate __svn_version__.py file containing SVN\n revision number of a module.\n\n To use, add the following codelet to setup\n configuration(..) function\n\n ext = Extension(dot_join(config['name'],'__svn_version__'),\n sources=[generate_svn_version_py])\n ext.local_path = local_path\n config['ext_modules'].append(ext)\n\n \"\"\"\n from distutils import dep_util\n local_path = extension.local_path\n target = njoin(build_dir, '__svn_version__.py')\n entries = njoin(local_path,'.svn','entries')\n if os.path.isfile(entries):\n if not dep_util.newer(entries, target):\n return target\n elif os.path.isfile(target):\n return target\n\n revision = get_svn_revision(local_path)\n f = open(target,'w')\n f.write('revision=%s\\n' % (revision))\n f.close()\n return target\n", + "methods": [ + { + "name": "allpath", + "long_name": "allpath( name )", + "filename": "misc_util.py", + "nloc": 4, + "complexity": 1, + "token_count": 24, + "parameters": [ + "name" + ], + "start_line": 18, + "end_line": 21, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 4, + "top_nesting_level": 0 + }, + { + "name": "get_path", + "long_name": "get_path( mod_name , parent_path = None )", + "filename": "misc_util.py", + "nloc": 15, + "complexity": 6, + "token_count": 132, + "parameters": [ + "mod_name", + "parent_path" + ], + "start_line": 23, + "end_line": 43, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 21, + "top_nesting_level": 0 + }, + { + "name": "njoin", + "long_name": "njoin( * path )", + "filename": "misc_util.py", + "nloc": 7, + "complexity": 4, + "token_count": 68, + "parameters": [ + "path" + ], + "start_line": 45, + "end_line": 55, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 11, + "top_nesting_level": 0 + }, + { + "name": "minrelpath", + "long_name": "minrelpath( path )", + "filename": "misc_util.py", + "nloc": 17, + "complexity": 7, + "token_count": 103, + "parameters": [ + "path" + ], + "start_line": 57, + "end_line": 75, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 19, + "top_nesting_level": 0 + }, + { + "name": "terminal_has_colors", + "long_name": "terminal_has_colors( )", + "filename": "misc_util.py", + "nloc": 18, + "complexity": 13, + "token_count": 137, + "parameters": [], + "start_line": 79, + "end_line": 104, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 26, + "top_nesting_level": 0 + }, + { + "name": "cyg2win32", + "long_name": "cyg2win32( path )", + "filename": "misc_util.py", + "nloc": 4, + "complexity": 3, + "token_count": 42, + "parameters": [ + "path" + ], + "start_line": 121, + "end_line": 124, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 4, + "top_nesting_level": 0 + }, + { + "name": "_get_f90_modules", + "long_name": "_get_f90_modules( source )", + "filename": "misc_util.py", + "nloc": 13, + "complexity": 4, + "token_count": 77, + "parameters": [ + "source" + ], + "start_line": 133, + "end_line": 149, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 17, + "top_nesting_level": 0 + }, + { + "name": "is_string", + "long_name": "is_string( s )", + "filename": "misc_util.py", + "nloc": 2, + "complexity": 1, + "token_count": 12, + "parameters": [ + "s" + ], + "start_line": 151, + "end_line": 152, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 2, + "top_nesting_level": 0 + }, + { + "name": "all_strings", + "long_name": "all_strings( lst )", + "filename": "misc_util.py", + "nloc": 5, + "complexity": 3, + "token_count": 22, + "parameters": [ + "lst" + ], + "start_line": 154, + "end_line": 159, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 6, + "top_nesting_level": 0 + }, + { + "name": "is_sequence", + "long_name": "is_sequence( seq )", + "filename": "misc_util.py", + "nloc": 8, + "complexity": 3, + "token_count": 25, + "parameters": [ + "seq" + ], + "start_line": 161, + "end_line": 168, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 8, + "top_nesting_level": 0 + }, + { + "name": "has_f_sources", + "long_name": "has_f_sources( sources )", + "filename": "misc_util.py", + "nloc": 5, + "complexity": 3, + "token_count": 21, + "parameters": [ + "sources" + ], + "start_line": 170, + "end_line": 175, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 6, + "top_nesting_level": 0 + }, + { + "name": "has_cxx_sources", + "long_name": "has_cxx_sources( sources )", + "filename": "misc_util.py", + "nloc": 5, + "complexity": 3, + "token_count": 21, + "parameters": [ + "sources" + ], + "start_line": 177, + "end_line": 182, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 6, + "top_nesting_level": 0 + }, + { + "name": "filter_sources", + "long_name": "filter_sources( sources )", + "filename": "misc_util.py", + "nloc": 17, + "complexity": 5, + "token_count": 84, + "parameters": [ + "sources" + ], + "start_line": 184, + "end_line": 204, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 21, + "top_nesting_level": 0 + }, + { + "name": "_get_headers", + "long_name": "_get_headers( directory_list )", + "filename": "misc_util.py", + "nloc": 6, + "complexity": 2, + "token_count": 39, + "parameters": [ + "directory_list" + ], + "start_line": 207, + "end_line": 213, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 7, + "top_nesting_level": 0 + }, + { + "name": "_get_directories", + "long_name": "_get_directories( list_of_sources )", + "filename": "misc_util.py", + "nloc": 7, + "complexity": 4, + "token_count": 51, + "parameters": [ + "list_of_sources" + ], + "start_line": 215, + "end_line": 222, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 8, + "top_nesting_level": 0 + }, + { + "name": "get_dependencies", + "long_name": "get_dependencies( sources )", + "filename": "misc_util.py", + "nloc": 2, + "complexity": 1, + "token_count": 13, + "parameters": [ + "sources" + ], + "start_line": 224, + "end_line": 226, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 3, + "top_nesting_level": 0 + }, + { + "name": "is_local_src_dir", + "long_name": "is_local_src_dir( directory )", + "filename": "misc_util.py", + "nloc": 12, + "complexity": 6, + "token_count": 107, + "parameters": [ + "directory" + ], + "start_line": 228, + "end_line": 241, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 14, + "top_nesting_level": 0 + }, + { + "name": "_gsf_visit_func", + "long_name": "_gsf_visit_func( filenames , dirname , names )", + "filename": "misc_util.py", + "nloc": 13, + "complexity": 7, + "token_count": 103, + "parameters": [ + "filenames", + "dirname", + "names" + ], + "start_line": 243, + "end_line": 255, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 13, + "top_nesting_level": 0 + }, + { + "name": "get_ext_source_files", + "long_name": "get_ext_source_files( ext )", + "filename": "misc_util.py", + "nloc": 11, + "complexity": 4, + "token_count": 77, + "parameters": [ + "ext" + ], + "start_line": 257, + "end_line": 268, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 12, + "top_nesting_level": 0 + }, + { + "name": "get_script_files", + "long_name": "get_script_files( scripts )", + "filename": "misc_util.py", + "nloc": 3, + "complexity": 1, + "token_count": 15, + "parameters": [ + "scripts" + ], + "start_line": 270, + "end_line": 272, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 3, + "top_nesting_level": 0 + }, + { + "name": "get_lib_source_files", + "long_name": "get_lib_source_files( lib )", + "filename": "misc_util.py", + "nloc": 13, + "complexity": 4, + "token_count": 101, + "parameters": [ + "lib" + ], + "start_line": 274, + "end_line": 286, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 13, + "top_nesting_level": 0 + }, + { + "name": "get_data_files", + "long_name": "get_data_files( data )", + "filename": "misc_util.py", + "nloc": 18, + "complexity": 7, + "token_count": 94, + "parameters": [ + "data" + ], + "start_line": 288, + "end_line": 305, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 18, + "top_nesting_level": 0 + }, + { + "name": "dot_join", + "long_name": "dot_join( * args )", + "filename": "misc_util.py", + "nloc": 2, + "complexity": 1, + "token_count": 18, + "parameters": [ + "args" + ], + "start_line": 307, + "end_line": 308, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 2, + "top_nesting_level": 0 + }, + { + "name": "get_frame", + "long_name": "get_frame( level = 0 )", + "filename": "misc_util.py", + "nloc": 8, + "complexity": 3, + "token_count": 50, + "parameters": [ + "level" + ], + "start_line": 310, + "end_line": 317, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 8, + "top_nesting_level": 0 + }, + { + "name": "__init__", + "long_name": "__init__( self , package_name = None , parent_name = None , top_path = None , package_path = None , ** attrs )", + "filename": "misc_util.py", + "nloc": 44, + "complexity": 12, + "token_count": 365, + "parameters": [ + "self", + "package_name", + "parent_name", + "top_path", + "package_path", + "attrs" + ], + "start_line": 329, + "end_line": 393, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 65, + "top_nesting_level": 1 + }, + { + "name": "todict", + "long_name": "todict( self )", + "filename": "misc_util.py", + "nloc": 9, + "complexity": 4, + "token_count": 57, + "parameters": [ + "self" + ], + "start_line": 395, + "end_line": 406, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 12, + "top_nesting_level": 1 + }, + { + "name": "info", + "long_name": "info( self , message )", + "filename": "misc_util.py", + "nloc": 2, + "complexity": 1, + "token_count": 9, + "parameters": [ + "self", + "message" + ], + "start_line": 408, + "end_line": 409, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 2, + "top_nesting_level": 1 + }, + { + "name": "warn", + "long_name": "warn( self , message )", + "filename": "misc_util.py", + "nloc": 2, + "complexity": 1, + "token_count": 11, + "parameters": [ + "self", + "message" + ], + "start_line": 411, + "end_line": 412, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 2, + "top_nesting_level": 1 + }, + { + "name": "__dict__", + "long_name": "__dict__( self )", + "filename": "misc_util.py", + "nloc": 2, + "complexity": 1, + "token_count": 11, + "parameters": [ + "self" + ], + "start_line": 414, + "end_line": 415, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 2, + "top_nesting_level": 1 + }, + { + "name": "get_distribution", + "long_name": "get_distribution( self )", + "filename": "misc_util.py", + "nloc": 4, + "complexity": 1, + "token_count": 18, + "parameters": [ + "self" + ], + "start_line": 417, + "end_line": 420, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 4, + "top_nesting_level": 1 + }, + { + "name": "get_subpackage", + "long_name": "get_subpackage( self , subpackage_name , subpackage_path = None )", + "filename": "misc_util.py", + "nloc": 52, + "complexity": 13, + "token_count": 446, + "parameters": [ + "self", + "subpackage_name", + "subpackage_path" + ], + "start_line": 422, + "end_line": 480, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 59, + "top_nesting_level": 1 + }, + { + "name": "add_subpackage", + "long_name": "add_subpackage( self , subpackage_name , subpackage_path = None )", + "filename": "misc_util.py", + "nloc": 20, + "complexity": 6, + "token_count": 127, + "parameters": [ + "self", + "subpackage_name", + "subpackage_path" + ], + "start_line": 482, + "end_line": 504, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 23, + "top_nesting_level": 1 + }, + { + "name": "add_data_dir", + "long_name": "add_data_dir( self , data_path )", + "filename": "misc_util.py", + "nloc": 27, + "complexity": 9, + "token_count": 196, + "parameters": [ + "self", + "data_path" + ], + "start_line": 506, + "end_line": 540, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 35, + "top_nesting_level": 1 + }, + { + "name": "add_data_files", + "long_name": "add_data_files( self , * files )", + "filename": "misc_util.py", + "nloc": 49, + "complexity": 17, + "token_count": 392, + "parameters": [ + "self", + "files" + ], + "start_line": 542, + "end_line": 602, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 61, + "top_nesting_level": 1 + }, + { + "name": "add_include_dirs", + "long_name": "add_include_dirs( self , * paths )", + "filename": "misc_util.py", + "nloc": 8, + "complexity": 2, + "token_count": 49, + "parameters": [ + "self", + "paths" + ], + "start_line": 606, + "end_line": 615, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 10, + "top_nesting_level": 1 + }, + { + "name": "add_headers", + "long_name": "add_headers( self , * files )", + "filename": "misc_util.py", + "nloc": 15, + "complexity": 8, + "token_count": 136, + "parameters": [ + "self", + "files" + ], + "start_line": 617, + "end_line": 637, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 21, + "top_nesting_level": 1 + }, + { + "name": "_fix_paths", + "long_name": "_fix_paths( self , paths , include_non_existing = True )", + "filename": "misc_util.py", + "nloc": 30, + "complexity": 12, + "token_count": 208, + "parameters": [ + "self", + "paths", + "include_non_existing" + ], + "start_line": 639, + "end_line": 668, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 30, + "top_nesting_level": 1 + }, + { + "name": "paths", + "long_name": "paths( self , * paths , ** kws )", + "filename": "misc_util.py", + "nloc": 4, + "complexity": 1, + "token_count": 33, + "parameters": [ + "self", + "paths", + "kws" + ], + "start_line": 670, + "end_line": 675, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 6, + "top_nesting_level": 1 + }, + { + "name": "add_extension", + "long_name": "add_extension( self , name , sources , ** kw )", + "filename": "misc_util.py", + "nloc": 45, + "complexity": 14, + "token_count": 361, + "parameters": [ + "self", + "name", + "sources", + "kw" + ], + "start_line": 677, + "end_line": 739, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 63, + "top_nesting_level": 1 + }, + { + "name": "add_library", + "long_name": "add_library( self , name , sources , ** build_info )", + "filename": "misc_util.py", + "nloc": 15, + "complexity": 4, + "token_count": 106, + "parameters": [ + "self", + "name", + "sources", + "build_info" + ], + "start_line": 741, + "end_line": 766, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 26, + "top_nesting_level": 1 + }, + { + "name": "add_scripts", + "long_name": "add_scripts( self , * files )", + "filename": "misc_util.py", + "nloc": 8, + "complexity": 2, + "token_count": 49, + "parameters": [ + "self", + "files" + ], + "start_line": 768, + "end_line": 777, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 10, + "top_nesting_level": 1 + }, + { + "name": "dict_append", + "long_name": "dict_append( self , ** dict )", + "filename": "misc_util.py", + "nloc": 15, + "complexity": 6, + "token_count": 138, + "parameters": [ + "self", + "dict" + ], + "start_line": 779, + "end_line": 793, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 15, + "top_nesting_level": 1 + }, + { + "name": "__str__", + "long_name": "__str__( self )", + "filename": "misc_util.py", + "nloc": 10, + "complexity": 3, + "token_count": 72, + "parameters": [ + "self" + ], + "start_line": 795, + "end_line": 804, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 10, + "top_nesting_level": 1 + }, + { + "name": "get_config_cmd", + "long_name": "get_config_cmd( self )", + "filename": "misc_util.py", + "nloc": 10, + "complexity": 2, + "token_count": 63, + "parameters": [ + "self" + ], + "start_line": 806, + "end_line": 815, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 10, + "top_nesting_level": 1 + }, + { + "name": "get_build_temp_dir", + "long_name": "get_build_temp_dir( self )", + "filename": "misc_util.py", + "nloc": 4, + "complexity": 1, + "token_count": 20, + "parameters": [ + "self" + ], + "start_line": 817, + "end_line": 820, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 4, + "top_nesting_level": 1 + }, + { + "name": "have_f77c", + "long_name": "have_f77c( self )", + "filename": "misc_util.py", + "nloc": 8, + "complexity": 1, + "token_count": 30, + "parameters": [ + "self" + ], + "start_line": 822, + "end_line": 833, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 12, + "top_nesting_level": 1 + }, + { + "name": "have_f90c", + "long_name": "have_f90c( self )", + "filename": "misc_util.py", + "nloc": 8, + "complexity": 1, + "token_count": 30, + "parameters": [ + "self" + ], + "start_line": 835, + "end_line": 846, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 12, + "top_nesting_level": 1 + }, + { + "name": "append_to", + "long_name": "append_to( self , extlib )", + "filename": "misc_util.py", + "nloc": 12, + "complexity": 2, + "token_count": 77, + "parameters": [ + "self", + "extlib" + ], + "start_line": 848, + "end_line": 861, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 14, + "top_nesting_level": 1 + }, + { + "name": "_get_svn_revision", + "long_name": "_get_svn_revision( self , path )", + "filename": "misc_util.py", + "nloc": 10, + "complexity": 3, + "token_count": 73, + "parameters": [ + "self", + "path" + ], + "start_line": 863, + "end_line": 874, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 12, + "top_nesting_level": 1 + }, + { + "name": "get_version", + "long_name": "get_version( self )", + "filename": "misc_util.py", + "nloc": 38, + "complexity": 11, + "token_count": 253, + "parameters": [ + "self" + ], + "start_line": 876, + "end_line": 922, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 47, + "top_nesting_level": 1 + }, + { + "name": "make_svn_version_py.make_svn_version_py.generate_svn_version_py.rm_file", + "long_name": "make_svn_version_py.make_svn_version_py.generate_svn_version_py.rm_file( f = target )", + "filename": "misc_util.py", + "nloc": 5, + "complexity": 3, + "token_count": 45, + "parameters": [ + "f" + ], + "start_line": 946, + "end_line": 950, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 5, + "top_nesting_level": 3 + }, + { + "name": "make_svn_version_py.generate_svn_version_py", + "long_name": "make_svn_version_py.generate_svn_version_py( )", + "filename": "misc_util.py", + "nloc": 13, + "complexity": 2, + "token_count": 81, + "parameters": [], + "start_line": 935, + "end_line": 953, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 19, + "top_nesting_level": 2 + }, + { + "name": "make_svn_version_py", + "long_name": "make_svn_version_py( self )", + "filename": "misc_util.py", + "nloc": 7, + "complexity": 2, + "token_count": 44, + "parameters": [ + "self" + ], + "start_line": 924, + "end_line": 956, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 33, + "top_nesting_level": 1 + }, + { + "name": "make_config_py", + "long_name": "make_config_py( self , name = '__config__' )", + "filename": "misc_util.py", + "nloc": 3, + "complexity": 1, + "token_count": 27, + "parameters": [ + "self", + "name" + ], + "start_line": 958, + "end_line": 963, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 6, + "top_nesting_level": 1 + }, + { + "name": "get_info", + "long_name": "get_info( self , * names )", + "filename": "misc_util.py", + "nloc": 6, + "complexity": 2, + "token_count": 36, + "parameters": [ + "self", + "names" + ], + "start_line": 965, + "end_line": 972, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 8, + "top_nesting_level": 1 + }, + { + "name": "get_cmd", + "long_name": "get_cmd( cmdname , _cache = { } )", + "filename": "misc_util.py", + "nloc": 11, + "complexity": 3, + "token_count": 65, + "parameters": [ + "cmdname", + "_cache" + ], + "start_line": 974, + "end_line": 984, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 11, + "top_nesting_level": 0 + }, + { + "name": "get_numpy_include_dirs", + "long_name": "get_numpy_include_dirs( )", + "filename": "misc_util.py", + "nloc": 11, + "complexity": 3, + "token_count": 77, + "parameters": [], + "start_line": 986, + "end_line": 1000, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 15, + "top_nesting_level": 0 + }, + { + "name": "default_config_dict", + "long_name": "default_config_dict( name = None , parent_name = None , local_path = None )", + "filename": "misc_util.py", + "nloc": 9, + "complexity": 1, + "token_count": 70, + "parameters": [ + "name", + "parent_name", + "local_path" + ], + "start_line": 1004, + "end_line": 1015, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 12, + "top_nesting_level": 0 + }, + { + "name": "dict_append", + "long_name": "dict_append( d , ** kws )", + "filename": "misc_util.py", + "nloc": 6, + "complexity": 3, + "token_count": 44, + "parameters": [ + "d", + "kws" + ], + "start_line": 1018, + "end_line": 1023, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 6, + "top_nesting_level": 0 + }, + { + "name": "appendpath", + "long_name": "appendpath( prefix , path )", + "filename": "misc_util.py", + "nloc": 19, + "complexity": 6, + "token_count": 233, + "parameters": [ + "prefix", + "path" + ], + "start_line": 1025, + "end_line": 1044, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 20, + "top_nesting_level": 0 + }, + { + "name": "generate_config_py", + "long_name": "generate_config_py( target )", + "filename": "misc_util.py", + "nloc": 27, + "complexity": 2, + "token_count": 117, + "parameters": [ + "target" + ], + "start_line": 1050, + "end_line": 1083, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 34, + "top_nesting_level": 0 + }, + { + "name": "generate_svn_version_py", + "long_name": "generate_svn_version_py( extension , build_dir )", + "filename": "misc_util.py", + "nloc": 15, + "complexity": 4, + "token_count": 101, + "parameters": [ + "extension", + "build_dir" + ], + "start_line": 1085, + "end_line": 1112, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 28, + "top_nesting_level": 0 + } + ], + "methods_before": [ + { + "name": "allpath", + "long_name": "allpath( name )", + "filename": "misc_util.py", + "nloc": 4, + "complexity": 1, + "token_count": 24, + "parameters": [ + "name" + ], + "start_line": 18, + "end_line": 21, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 4, + "top_nesting_level": 0 + }, + { + "name": "get_path", + "long_name": "get_path( mod_name , parent_path = None )", + "filename": "misc_util.py", + "nloc": 15, + "complexity": 6, + "token_count": 132, + "parameters": [ + "mod_name", + "parent_path" + ], + "start_line": 23, + "end_line": 43, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 21, + "top_nesting_level": 0 + }, + { + "name": "njoin", + "long_name": "njoin( * path )", + "filename": "misc_util.py", + "nloc": 7, + "complexity": 4, + "token_count": 68, + "parameters": [ + "path" + ], + "start_line": 45, + "end_line": 55, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 11, + "top_nesting_level": 0 + }, + { + "name": "minrelpath", + "long_name": "minrelpath( path )", + "filename": "misc_util.py", + "nloc": 17, + "complexity": 7, + "token_count": 103, + "parameters": [ + "path" + ], + "start_line": 57, + "end_line": 75, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 19, + "top_nesting_level": 0 + }, + { + "name": "terminal_has_colors", + "long_name": "terminal_has_colors( )", + "filename": "misc_util.py", + "nloc": 18, + "complexity": 13, + "token_count": 137, + "parameters": [], + "start_line": 79, + "end_line": 104, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 26, + "top_nesting_level": 0 + }, + { + "name": "cyg2win32", + "long_name": "cyg2win32( path )", + "filename": "misc_util.py", + "nloc": 4, + "complexity": 3, + "token_count": 42, + "parameters": [ + "path" + ], + "start_line": 121, + "end_line": 124, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 4, + "top_nesting_level": 0 + }, + { + "name": "_get_f90_modules", + "long_name": "_get_f90_modules( source )", + "filename": "misc_util.py", + "nloc": 13, + "complexity": 4, + "token_count": 77, + "parameters": [ + "source" + ], + "start_line": 133, + "end_line": 149, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 17, + "top_nesting_level": 0 + }, + { + "name": "is_string", + "long_name": "is_string( s )", + "filename": "misc_util.py", + "nloc": 2, + "complexity": 1, + "token_count": 12, + "parameters": [ + "s" + ], + "start_line": 151, + "end_line": 152, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 2, + "top_nesting_level": 0 + }, + { + "name": "all_strings", + "long_name": "all_strings( lst )", + "filename": "misc_util.py", + "nloc": 5, + "complexity": 3, + "token_count": 22, + "parameters": [ + "lst" + ], + "start_line": 154, + "end_line": 159, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 6, + "top_nesting_level": 0 + }, + { + "name": "is_sequence", + "long_name": "is_sequence( seq )", + "filename": "misc_util.py", + "nloc": 8, + "complexity": 3, + "token_count": 25, + "parameters": [ + "seq" + ], + "start_line": 161, + "end_line": 168, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 8, + "top_nesting_level": 0 + }, + { + "name": "has_f_sources", + "long_name": "has_f_sources( sources )", + "filename": "misc_util.py", + "nloc": 5, + "complexity": 3, + "token_count": 21, + "parameters": [ + "sources" + ], + "start_line": 170, + "end_line": 175, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 6, + "top_nesting_level": 0 + }, + { + "name": "has_cxx_sources", + "long_name": "has_cxx_sources( sources )", + "filename": "misc_util.py", + "nloc": 5, + "complexity": 3, + "token_count": 21, + "parameters": [ + "sources" + ], + "start_line": 177, + "end_line": 182, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 6, + "top_nesting_level": 0 + }, + { + "name": "filter_sources", + "long_name": "filter_sources( sources )", + "filename": "misc_util.py", + "nloc": 17, + "complexity": 5, + "token_count": 84, + "parameters": [ + "sources" + ], + "start_line": 184, + "end_line": 204, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 21, + "top_nesting_level": 0 + }, + { + "name": "_get_headers", + "long_name": "_get_headers( directory_list )", + "filename": "misc_util.py", + "nloc": 6, + "complexity": 2, + "token_count": 39, + "parameters": [ + "directory_list" + ], + "start_line": 207, + "end_line": 213, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 7, + "top_nesting_level": 0 + }, + { + "name": "_get_directories", + "long_name": "_get_directories( list_of_sources )", + "filename": "misc_util.py", + "nloc": 7, + "complexity": 4, + "token_count": 51, + "parameters": [ + "list_of_sources" + ], + "start_line": 215, + "end_line": 222, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 8, + "top_nesting_level": 0 + }, + { + "name": "get_dependencies", + "long_name": "get_dependencies( sources )", + "filename": "misc_util.py", + "nloc": 2, + "complexity": 1, + "token_count": 13, + "parameters": [ + "sources" + ], + "start_line": 224, + "end_line": 226, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 3, + "top_nesting_level": 0 + }, + { + "name": "is_local_src_dir", + "long_name": "is_local_src_dir( directory )", + "filename": "misc_util.py", + "nloc": 12, + "complexity": 6, + "token_count": 107, + "parameters": [ + "directory" + ], + "start_line": 228, + "end_line": 241, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 14, + "top_nesting_level": 0 + }, + { + "name": "_gsf_visit_func", + "long_name": "_gsf_visit_func( filenames , dirname , names )", + "filename": "misc_util.py", + "nloc": 13, + "complexity": 7, + "token_count": 103, + "parameters": [ + "filenames", + "dirname", + "names" + ], + "start_line": 243, + "end_line": 255, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 13, + "top_nesting_level": 0 + }, + { + "name": "get_ext_source_files", + "long_name": "get_ext_source_files( ext )", + "filename": "misc_util.py", + "nloc": 11, + "complexity": 4, + "token_count": 77, + "parameters": [ + "ext" + ], + "start_line": 257, + "end_line": 268, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 12, + "top_nesting_level": 0 + }, + { + "name": "get_script_files", + "long_name": "get_script_files( scripts )", + "filename": "misc_util.py", + "nloc": 3, + "complexity": 1, + "token_count": 15, + "parameters": [ + "scripts" + ], + "start_line": 270, + "end_line": 272, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 3, + "top_nesting_level": 0 + }, + { + "name": "get_lib_source_files", + "long_name": "get_lib_source_files( lib )", + "filename": "misc_util.py", + "nloc": 13, + "complexity": 4, + "token_count": 101, + "parameters": [ + "lib" + ], + "start_line": 274, + "end_line": 286, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 13, + "top_nesting_level": 0 + }, + { + "name": "get_data_files", + "long_name": "get_data_files( data )", + "filename": "misc_util.py", + "nloc": 18, + "complexity": 7, + "token_count": 94, + "parameters": [ + "data" + ], + "start_line": 288, + "end_line": 305, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 18, + "top_nesting_level": 0 + }, + { + "name": "dot_join", + "long_name": "dot_join( * args )", + "filename": "misc_util.py", + "nloc": 2, + "complexity": 1, + "token_count": 18, + "parameters": [ + "args" + ], + "start_line": 307, + "end_line": 308, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 2, + "top_nesting_level": 0 + }, + { + "name": "get_frame", + "long_name": "get_frame( level = 0 )", + "filename": "misc_util.py", + "nloc": 8, + "complexity": 3, + "token_count": 50, + "parameters": [ + "level" + ], + "start_line": 310, + "end_line": 317, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 8, + "top_nesting_level": 0 + }, + { + "name": "__init__", + "long_name": "__init__( self , package_name = None , parent_name = None , top_path = None , package_path = None , ** attrs )", + "filename": "misc_util.py", + "nloc": 44, + "complexity": 12, + "token_count": 365, + "parameters": [ + "self", + "package_name", + "parent_name", + "top_path", + "package_path", + "attrs" + ], + "start_line": 329, + "end_line": 393, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 65, + "top_nesting_level": 1 + }, + { + "name": "todict", + "long_name": "todict( self )", + "filename": "misc_util.py", + "nloc": 9, + "complexity": 4, + "token_count": 57, + "parameters": [ + "self" + ], + "start_line": 395, + "end_line": 406, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 12, + "top_nesting_level": 1 + }, + { + "name": "info", + "long_name": "info( self , message )", + "filename": "misc_util.py", + "nloc": 2, + "complexity": 1, + "token_count": 9, + "parameters": [ + "self", + "message" + ], + "start_line": 408, + "end_line": 409, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 2, + "top_nesting_level": 1 + }, + { + "name": "warn", + "long_name": "warn( self , message )", + "filename": "misc_util.py", + "nloc": 2, + "complexity": 1, + "token_count": 11, + "parameters": [ + "self", + "message" + ], + "start_line": 411, + "end_line": 412, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 2, + "top_nesting_level": 1 + }, + { + "name": "__dict__", + "long_name": "__dict__( self )", + "filename": "misc_util.py", + "nloc": 2, + "complexity": 1, + "token_count": 11, + "parameters": [ + "self" + ], + "start_line": 414, + "end_line": 415, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 2, + "top_nesting_level": 1 + }, + { + "name": "get_distribution", + "long_name": "get_distribution( self )", + "filename": "misc_util.py", + "nloc": 4, + "complexity": 1, + "token_count": 18, + "parameters": [ + "self" + ], + "start_line": 417, + "end_line": 420, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 4, + "top_nesting_level": 1 + }, + { + "name": "get_subpackage", + "long_name": "get_subpackage( self , subpackage_name , subpackage_path = None )", + "filename": "misc_util.py", + "nloc": 52, + "complexity": 13, + "token_count": 446, + "parameters": [ + "self", + "subpackage_name", + "subpackage_path" + ], + "start_line": 422, + "end_line": 480, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 59, + "top_nesting_level": 1 + }, + { + "name": "add_subpackage", + "long_name": "add_subpackage( self , subpackage_name , subpackage_path = None )", + "filename": "misc_util.py", + "nloc": 20, + "complexity": 6, + "token_count": 127, + "parameters": [ + "self", + "subpackage_name", + "subpackage_path" + ], + "start_line": 482, + "end_line": 504, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 23, + "top_nesting_level": 1 + }, + { + "name": "add_data_dir", + "long_name": "add_data_dir( self , data_path )", + "filename": "misc_util.py", + "nloc": 27, + "complexity": 9, + "token_count": 196, + "parameters": [ + "self", + "data_path" + ], + "start_line": 506, + "end_line": 540, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 35, + "top_nesting_level": 1 + }, + { + "name": "add_data_files", + "long_name": "add_data_files( self , * files )", + "filename": "misc_util.py", + "nloc": 46, + "complexity": 18, + "token_count": 320, + "parameters": [ + "self", + "files" + ], + "start_line": 542, + "end_line": 598, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 57, + "top_nesting_level": 1 + }, + { + "name": "add_include_dirs", + "long_name": "add_include_dirs( self , * paths )", + "filename": "misc_util.py", + "nloc": 8, + "complexity": 2, + "token_count": 49, + "parameters": [ + "self", + "paths" + ], + "start_line": 602, + "end_line": 611, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 10, + "top_nesting_level": 1 + }, + { + "name": "add_headers", + "long_name": "add_headers( self , * files )", + "filename": "misc_util.py", + "nloc": 15, + "complexity": 8, + "token_count": 136, + "parameters": [ + "self", + "files" + ], + "start_line": 613, + "end_line": 633, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 21, + "top_nesting_level": 1 + }, + { + "name": "_fix_paths", + "long_name": "_fix_paths( self , paths )", + "filename": "misc_util.py", + "nloc": 26, + "complexity": 9, + "token_count": 182, + "parameters": [ + "self", + "paths" + ], + "start_line": 635, + "end_line": 660, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 26, + "top_nesting_level": 1 + }, + { + "name": "paths", + "long_name": "paths( self , * paths )", + "filename": "misc_util.py", + "nloc": 2, + "complexity": 1, + "token_count": 16, + "parameters": [ + "self", + "paths" + ], + "start_line": 662, + "end_line": 665, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 4, + "top_nesting_level": 1 + }, + { + "name": "add_extension", + "long_name": "add_extension( self , name , sources , ** kw )", + "filename": "misc_util.py", + "nloc": 45, + "complexity": 14, + "token_count": 361, + "parameters": [ + "self", + "name", + "sources", + "kw" + ], + "start_line": 667, + "end_line": 729, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 63, + "top_nesting_level": 1 + }, + { + "name": "add_library", + "long_name": "add_library( self , name , sources , ** build_info )", + "filename": "misc_util.py", + "nloc": 15, + "complexity": 4, + "token_count": 106, + "parameters": [ + "self", + "name", + "sources", + "build_info" + ], + "start_line": 731, + "end_line": 756, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 26, + "top_nesting_level": 1 + }, + { + "name": "add_scripts", + "long_name": "add_scripts( self , * files )", + "filename": "misc_util.py", + "nloc": 8, + "complexity": 2, + "token_count": 49, + "parameters": [ + "self", + "files" + ], + "start_line": 758, + "end_line": 767, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 10, + "top_nesting_level": 1 + }, + { + "name": "dict_append", + "long_name": "dict_append( self , ** dict )", + "filename": "misc_util.py", + "nloc": 15, + "complexity": 6, + "token_count": 138, + "parameters": [ + "self", + "dict" + ], + "start_line": 769, + "end_line": 783, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 15, + "top_nesting_level": 1 + }, + { + "name": "__str__", + "long_name": "__str__( self )", + "filename": "misc_util.py", + "nloc": 10, + "complexity": 3, + "token_count": 72, + "parameters": [ + "self" + ], + "start_line": 785, + "end_line": 794, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 10, + "top_nesting_level": 1 + }, + { + "name": "get_config_cmd", + "long_name": "get_config_cmd( self )", + "filename": "misc_util.py", + "nloc": 10, + "complexity": 2, + "token_count": 63, + "parameters": [ + "self" + ], + "start_line": 796, + "end_line": 805, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 10, + "top_nesting_level": 1 + }, + { + "name": "get_build_temp_dir", + "long_name": "get_build_temp_dir( self )", + "filename": "misc_util.py", + "nloc": 4, + "complexity": 1, + "token_count": 20, + "parameters": [ + "self" + ], + "start_line": 807, + "end_line": 810, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 4, + "top_nesting_level": 1 + }, + { + "name": "have_f77c", + "long_name": "have_f77c( self )", + "filename": "misc_util.py", + "nloc": 8, + "complexity": 1, + "token_count": 30, + "parameters": [ + "self" + ], + "start_line": 812, + "end_line": 823, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 12, + "top_nesting_level": 1 + }, + { + "name": "have_f90c", + "long_name": "have_f90c( self )", + "filename": "misc_util.py", + "nloc": 8, + "complexity": 1, + "token_count": 30, + "parameters": [ + "self" + ], + "start_line": 825, + "end_line": 836, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 12, + "top_nesting_level": 1 + }, + { + "name": "append_to", + "long_name": "append_to( self , extlib )", + "filename": "misc_util.py", + "nloc": 12, + "complexity": 2, + "token_count": 77, + "parameters": [ + "self", + "extlib" + ], + "start_line": 838, + "end_line": 851, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 14, + "top_nesting_level": 1 + }, + { + "name": "_get_svn_revision", + "long_name": "_get_svn_revision( self , path )", + "filename": "misc_util.py", + "nloc": 10, + "complexity": 3, + "token_count": 73, + "parameters": [ + "self", + "path" + ], + "start_line": 853, + "end_line": 864, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 12, + "top_nesting_level": 1 + }, + { + "name": "get_version", + "long_name": "get_version( self )", + "filename": "misc_util.py", + "nloc": 38, + "complexity": 11, + "token_count": 253, + "parameters": [ + "self" + ], + "start_line": 866, + "end_line": 912, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 47, + "top_nesting_level": 1 + }, + { + "name": "make_svn_version_py.make_svn_version_py.generate_svn_version_py.rm_file", + "long_name": "make_svn_version_py.make_svn_version_py.generate_svn_version_py.rm_file( f = target )", + "filename": "misc_util.py", + "nloc": 5, + "complexity": 3, + "token_count": 45, + "parameters": [ + "f" + ], + "start_line": 936, + "end_line": 940, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 5, + "top_nesting_level": 3 + }, + { + "name": "make_svn_version_py.generate_svn_version_py", + "long_name": "make_svn_version_py.generate_svn_version_py( )", + "filename": "misc_util.py", + "nloc": 13, + "complexity": 2, + "token_count": 81, + "parameters": [], + "start_line": 925, + "end_line": 943, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 19, + "top_nesting_level": 2 + }, + { + "name": "make_svn_version_py", + "long_name": "make_svn_version_py( self )", + "filename": "misc_util.py", + "nloc": 7, + "complexity": 2, + "token_count": 44, + "parameters": [ + "self" + ], + "start_line": 914, + "end_line": 946, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 33, + "top_nesting_level": 1 + }, + { + "name": "make_config_py", + "long_name": "make_config_py( self , name = '__config__' )", + "filename": "misc_util.py", + "nloc": 3, + "complexity": 1, + "token_count": 27, + "parameters": [ + "self", + "name" + ], + "start_line": 948, + "end_line": 953, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 6, + "top_nesting_level": 1 + }, + { + "name": "get_info", + "long_name": "get_info( self , * names )", + "filename": "misc_util.py", + "nloc": 6, + "complexity": 2, + "token_count": 36, + "parameters": [ + "self", + "names" + ], + "start_line": 955, + "end_line": 962, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 8, + "top_nesting_level": 1 + }, + { + "name": "get_cmd", + "long_name": "get_cmd( cmdname , _cache = { } )", + "filename": "misc_util.py", + "nloc": 11, + "complexity": 3, + "token_count": 65, + "parameters": [ + "cmdname", + "_cache" + ], + "start_line": 964, + "end_line": 974, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 11, + "top_nesting_level": 0 + }, + { + "name": "get_numpy_include_dirs", + "long_name": "get_numpy_include_dirs( )", + "filename": "misc_util.py", + "nloc": 11, + "complexity": 3, + "token_count": 77, + "parameters": [], + "start_line": 976, + "end_line": 990, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 15, + "top_nesting_level": 0 + }, + { + "name": "default_config_dict", + "long_name": "default_config_dict( name = None , parent_name = None , local_path = None )", + "filename": "misc_util.py", + "nloc": 9, + "complexity": 1, + "token_count": 70, + "parameters": [ + "name", + "parent_name", + "local_path" + ], + "start_line": 994, + "end_line": 1005, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 12, + "top_nesting_level": 0 + }, + { + "name": "dict_append", + "long_name": "dict_append( d , ** kws )", + "filename": "misc_util.py", + "nloc": 6, + "complexity": 3, + "token_count": 44, + "parameters": [ + "d", + "kws" + ], + "start_line": 1008, + "end_line": 1013, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 6, + "top_nesting_level": 0 + }, + { + "name": "appendpath", + "long_name": "appendpath( prefix , path )", + "filename": "misc_util.py", + "nloc": 19, + "complexity": 6, + "token_count": 233, + "parameters": [ + "prefix", + "path" + ], + "start_line": 1015, + "end_line": 1034, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 20, + "top_nesting_level": 0 + }, + { + "name": "generate_config_py", + "long_name": "generate_config_py( target )", + "filename": "misc_util.py", + "nloc": 27, + "complexity": 2, + "token_count": 117, + "parameters": [ + "target" + ], + "start_line": 1040, + "end_line": 1073, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 34, + "top_nesting_level": 0 + }, + { + "name": "generate_svn_version_py", + "long_name": "generate_svn_version_py( extension , build_dir )", + "filename": "misc_util.py", + "nloc": 15, + "complexity": 4, + "token_count": 101, + "parameters": [ + "extension", + "build_dir" + ], + "start_line": 1075, + "end_line": 1102, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 28, + "top_nesting_level": 0 + } + ], + "changed_methods": [ + { + "name": "_fix_paths", + "long_name": "_fix_paths( self , paths )", + "filename": "misc_util.py", + "nloc": 26, + "complexity": 9, + "token_count": 182, + "parameters": [ + "self", + "paths" + ], + "start_line": 635, + "end_line": 660, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 26, + "top_nesting_level": 1 + }, + { + "name": "paths", + "long_name": "paths( self , * paths , ** kws )", + "filename": "misc_util.py", + "nloc": 4, + "complexity": 1, + "token_count": 33, + "parameters": [ + "self", + "paths", + "kws" + ], + "start_line": 670, + "end_line": 675, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 6, + "top_nesting_level": 1 + }, + { + "name": "add_data_files", + "long_name": "add_data_files( self , * files )", + "filename": "misc_util.py", + "nloc": 49, + "complexity": 17, + "token_count": 392, + "parameters": [ + "self", + "files" + ], + "start_line": 542, + "end_line": 602, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 61, + "top_nesting_level": 1 + }, + { + "name": "paths", + "long_name": "paths( self , * paths )", + "filename": "misc_util.py", + "nloc": 2, + "complexity": 1, + "token_count": 16, + "parameters": [ + "self", + "paths" + ], + "start_line": 662, + "end_line": 665, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 4, + "top_nesting_level": 1 + }, + { + "name": "_fix_paths", + "long_name": "_fix_paths( self , paths , include_non_existing = True )", + "filename": "misc_util.py", + "nloc": 30, + "complexity": 12, + "token_count": 208, + "parameters": [ + "self", + "paths", + "include_non_existing" + ], + "start_line": 639, + "end_line": 668, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 30, + "top_nesting_level": 1 + } + ], + "nloc": 832, + "complexity": 266, + "token_count": 6027, + "diff_parsed": { + "added": [ + " pd = os.path.dirname(p)", + " if '*' in pd:", + " pn = os.path.basename(p)", + " n = len(pd.split(os.sep))", + " for d1 in filter(os.path.isdir,self.paths(pd)):", + " p = os.path.join(d1,pn)", + " d1 = os.sep.join(d1.split(os.sep)[-n:])", + " new_files.append((appendpath(d,d1),p))", + " continue", + " d = appendpath(d,pd)", + " p = (d,p)", + "", + " assert '*' not in prefix,`prefix,filepattern`", + " file_list = self.paths(filepattern,include_non_existing=False)", + " def _fix_paths(self,paths,include_non_existing=True):", + " if include_non_existing:", + " new_paths.append(n)", + " if os.path.exists(n):", + " new_paths.append(n)", + " elif include_non_existing:", + " new_paths.append(n)", + " def paths(self,*paths,**kws):", + " include_non_existing = kws.get('include_non_existing',True)", + " return self._fix_paths(paths,", + " include_non_existing=include_non_existing)" + ], + "deleted": [ + " new_files = []", + " for p in files:", + " if isinstance(p,str) and '*' in p:", + " new_files.extend(self.paths(p))", + " else:", + " new_files.append(p)", + " files = new_files", + " d = appendpath(d,os.path.dirname(p))", + " p = (d,p)", + " file_list = self.paths(filepattern)", + " def _fix_paths(self,paths):", + " new_paths.append(n)", + " new_paths.append(n)", + " def paths(self,*paths):", + " return self._fix_paths(paths)" + ] + } + } + ] + }, + { + "hash": "83d691d731082ec8d2367affb77b454c2a0b0855", + "msg": "Add test for column-vector bug in dotblas.", + "author": { + "name": "Travis Oliphant", + "email": "oliphant@enthought.com" + }, + "committer": { + "name": "Travis Oliphant", + "email": "oliphant@enthought.com" + }, + "author_date": "2006-01-29T02:58:55+00:00", + "author_timezone": 0, + "committer_date": "2006-01-29T02:58:55+00:00", + "committer_timezone": 0, + "branches": [ + "main" + ], + "in_main_branch": true, + "merge": false, + "parents": [ + "e97d2da5c89a2dc2ee87bc67d54b7d6a946835a9" + ], + "project_name": "repo_copy", + "project_path": "/tmp/tmppy2o86q9/repo_copy", + "deletions": 0, + "insertions": 9, + "lines": 9, + "files": 2, + "dmm_unit_size": 1.0, + "dmm_unit_complexity": 1.0, + "dmm_unit_interfacing": 1.0, + "modified_files": [ + { + "old_path": "numpy/core/tests/test_numeric.py", + "new_path": "numpy/core/tests/test_numeric.py", + "filename": "test_numeric.py", + "extension": "py", + "change_type": "MODIFY", + "diff": "@@ -64,6 +64,13 @@ def check_matscalar(self):\n \tb1 = matrix(ones((3,3),dtype=complex))\n \tassert_equal(b1*1.0, b1)\n \n+ def check_columnvect(self):\n+\tb1 = ones((3,1))\n+\tb2 = [5.3]\n+\tc1 = dot(b1,b2)\n+\tc2 = dot_(b1,b2)\n+\tassert_almost_equal(c1, c2, decimal=self.N)\n+\n \n class test_bool_scalar(ScipyTestCase):\n def test_logical(self):\n", + "added_lines": 7, + "deleted_lines": 0, + "source_code": "from numpy.core import *\nfrom numpy.random import rand\nfrom numpy.testing import *\nfrom numpy.core.multiarray import dot as dot_\n\nclass test_dot(ScipyTestCase):\n def setUp(self):\n self.A = rand(10,8)\n self.b1 = rand(8,1)\n self.b2 = rand(8)\n self.b3 = rand(1,8)\n self.b4 = rand(10)\n self.N = 14\n\n def check_matmat(self):\n A = self.A\n c1 = dot(A.transpose(), A)\n c2 = dot_(A.transpose(), A)\n assert_almost_equal(c1, c2, decimal=self.N)\n\n def check_matvec(self):\n A, b1 = self.A, self.b1\n c1 = dot(A, b1)\n c2 = dot_(A, b1)\n assert_almost_equal(c1, c2, decimal=self.N)\n\n def check_matvec2(self):\n A, b2 = self.A, self.b2 \n c1 = dot(A, b2)\n c2 = dot_(A, b2)\n assert_almost_equal(c1, c2, decimal=self.N)\n\n def check_vecmat(self):\n A, b4 = self.A, self.b4\n c1 = dot(b4, A)\n c2 = dot_(b4, A)\n assert_almost_equal(c1, c2, decimal=self.N)\n\n def check_vecmat2(self):\n b3, A = self.b3, self.A\n c1 = dot(b3, A.transpose())\n c2 = dot_(b3, A.transpose())\n assert_almost_equal(c1, c2, decimal=self.N)\n\n def check_vecmat3(self):\n A, b4 = self.A, self.b4\n c1 = dot(A.transpose(),b4)\n c2 = dot_(A.transpose(),b4)\n assert_almost_equal(c1, c2, decimal=self.N) \n\n def check_vecvecouter(self):\n b1, b3 = self.b1, self.b3\n c1 = dot(b1, b3)\n c2 = dot_(b1, b3)\n assert_almost_equal(c1, c2, decimal=self.N)\n\n def check_vecvecinner(self):\n b1, b3 = self.b1, self.b3\n c1 = dot(b3, b1)\n c2 = dot_(b3, b1)\n assert_almost_equal(c1, c2, decimal=self.N)\n\n def check_matscalar(self):\n\tb1 = matrix(ones((3,3),dtype=complex))\n\tassert_equal(b1*1.0, b1)\n\n def check_columnvect(self):\n\tb1 = ones((3,1))\n\tb2 = [5.3]\n\tc1 = dot(b1,b2)\n\tc2 = dot_(b1,b2)\n\tassert_almost_equal(c1, c2, decimal=self.N)\n\n\nclass test_bool_scalar(ScipyTestCase):\n def test_logical(self):\n f = False_\n t = True_\n s = \"xyz\"\n self.failUnless((t and s) is s)\n self.failUnless((f and s) is f)\n\n def test_bitwise_or(self):\n f = False_\n t = True_\n self.failUnless((t | t) is t)\n self.failUnless((f | t) is t)\n self.failUnless((t | f) is t)\n self.failUnless((f | f) is f)\n\n def test_bitwise_and(self): \n f = False_\n t = True_\n self.failUnless((t & t) is t)\n self.failUnless((f & t) is f)\n self.failUnless((t & f) is f)\n self.failUnless((f & f) is f)\n\n def test_bitwise_xor(self): \n f = False_\n t = True_\n self.failUnless((t ^ t) is f)\n self.failUnless((f ^ t) is t)\n self.failUnless((t ^ f) is t)\n self.failUnless((f ^ f) is f)\n \n \n \n", + "source_code_before": "from numpy.core import *\nfrom numpy.random import rand\nfrom numpy.testing import *\nfrom numpy.core.multiarray import dot as dot_\n\nclass test_dot(ScipyTestCase):\n def setUp(self):\n self.A = rand(10,8)\n self.b1 = rand(8,1)\n self.b2 = rand(8)\n self.b3 = rand(1,8)\n self.b4 = rand(10)\n self.N = 14\n\n def check_matmat(self):\n A = self.A\n c1 = dot(A.transpose(), A)\n c2 = dot_(A.transpose(), A)\n assert_almost_equal(c1, c2, decimal=self.N)\n\n def check_matvec(self):\n A, b1 = self.A, self.b1\n c1 = dot(A, b1)\n c2 = dot_(A, b1)\n assert_almost_equal(c1, c2, decimal=self.N)\n\n def check_matvec2(self):\n A, b2 = self.A, self.b2 \n c1 = dot(A, b2)\n c2 = dot_(A, b2)\n assert_almost_equal(c1, c2, decimal=self.N)\n\n def check_vecmat(self):\n A, b4 = self.A, self.b4\n c1 = dot(b4, A)\n c2 = dot_(b4, A)\n assert_almost_equal(c1, c2, decimal=self.N)\n\n def check_vecmat2(self):\n b3, A = self.b3, self.A\n c1 = dot(b3, A.transpose())\n c2 = dot_(b3, A.transpose())\n assert_almost_equal(c1, c2, decimal=self.N)\n\n def check_vecmat3(self):\n A, b4 = self.A, self.b4\n c1 = dot(A.transpose(),b4)\n c2 = dot_(A.transpose(),b4)\n assert_almost_equal(c1, c2, decimal=self.N) \n\n def check_vecvecouter(self):\n b1, b3 = self.b1, self.b3\n c1 = dot(b1, b3)\n c2 = dot_(b1, b3)\n assert_almost_equal(c1, c2, decimal=self.N)\n\n def check_vecvecinner(self):\n b1, b3 = self.b1, self.b3\n c1 = dot(b3, b1)\n c2 = dot_(b3, b1)\n assert_almost_equal(c1, c2, decimal=self.N)\n\n def check_matscalar(self):\n\tb1 = matrix(ones((3,3),dtype=complex))\n\tassert_equal(b1*1.0, b1)\n\n\nclass test_bool_scalar(ScipyTestCase):\n def test_logical(self):\n f = False_\n t = True_\n s = \"xyz\"\n self.failUnless((t and s) is s)\n self.failUnless((f and s) is f)\n\n def test_bitwise_or(self):\n f = False_\n t = True_\n self.failUnless((t | t) is t)\n self.failUnless((f | t) is t)\n self.failUnless((t | f) is t)\n self.failUnless((f | f) is f)\n\n def test_bitwise_and(self): \n f = False_\n t = True_\n self.failUnless((t & t) is t)\n self.failUnless((f & t) is f)\n self.failUnless((t & f) is f)\n self.failUnless((f & f) is f)\n\n def test_bitwise_xor(self): \n f = False_\n t = True_\n self.failUnless((t ^ t) is f)\n self.failUnless((f ^ t) is t)\n self.failUnless((t ^ f) is t)\n self.failUnless((f ^ f) is f)\n \n \n \n", + "methods": [ + { + "name": "setUp", + "long_name": "setUp( self )", + "filename": "test_numeric.py", + "nloc": 7, + "complexity": 1, + "token_count": 56, + "parameters": [ + "self" + ], + "start_line": 7, + "end_line": 13, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 7, + "top_nesting_level": 1 + }, + { + "name": "check_matmat", + "long_name": "check_matmat( self )", + "filename": "test_numeric.py", + "nloc": 5, + "complexity": 1, + "token_count": 46, + "parameters": [ + "self" + ], + "start_line": 15, + "end_line": 19, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 5, + "top_nesting_level": 1 + }, + { + "name": "check_matvec", + "long_name": "check_matvec( self )", + "filename": "test_numeric.py", + "nloc": 5, + "complexity": 1, + "token_count": 44, + "parameters": [ + "self" + ], + "start_line": 21, + "end_line": 25, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 5, + "top_nesting_level": 1 + }, + { + "name": "check_matvec2", + "long_name": "check_matvec2( self )", + "filename": "test_numeric.py", + "nloc": 5, + "complexity": 1, + "token_count": 44, + "parameters": [ + "self" + ], + "start_line": 27, + "end_line": 31, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 5, + "top_nesting_level": 1 + }, + { + "name": "check_vecmat", + "long_name": "check_vecmat( self )", + "filename": "test_numeric.py", + "nloc": 5, + "complexity": 1, + "token_count": 44, + "parameters": [ + "self" + ], + "start_line": 33, + "end_line": 37, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 5, + "top_nesting_level": 1 + }, + { + "name": "check_vecmat2", + "long_name": "check_vecmat2( self )", + "filename": "test_numeric.py", + "nloc": 5, + "complexity": 1, + "token_count": 52, + "parameters": [ + "self" + ], + "start_line": 39, + "end_line": 43, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 5, + "top_nesting_level": 1 + }, + { + "name": "check_vecmat3", + "long_name": "check_vecmat3( self )", + "filename": "test_numeric.py", + "nloc": 5, + "complexity": 1, + "token_count": 52, + "parameters": [ + "self" + ], + "start_line": 45, + "end_line": 49, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 5, + "top_nesting_level": 1 + }, + { + "name": "check_vecvecouter", + "long_name": "check_vecvecouter( self )", + "filename": "test_numeric.py", + "nloc": 5, + "complexity": 1, + "token_count": 44, + "parameters": [ + "self" + ], + "start_line": 51, + "end_line": 55, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 5, + "top_nesting_level": 1 + }, + { + "name": "check_vecvecinner", + "long_name": "check_vecvecinner( self )", + "filename": "test_numeric.py", + "nloc": 5, + "complexity": 1, + "token_count": 44, + "parameters": [ + "self" + ], + "start_line": 57, + "end_line": 61, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 5, + "top_nesting_level": 1 + }, + { + "name": "check_matscalar", + "long_name": "check_matscalar( self )", + "filename": "test_numeric.py", + "nloc": 3, + "complexity": 1, + "token_count": 32, + "parameters": [ + "self" + ], + "start_line": 63, + "end_line": 65, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 3, + "top_nesting_level": 1 + }, + { + "name": "check_columnvect", + "long_name": "check_columnvect( self )", + "filename": "test_numeric.py", + "nloc": 6, + "complexity": 1, + "token_count": 50, + "parameters": [ + "self" + ], + "start_line": 67, + "end_line": 72, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 6, + "top_nesting_level": 1 + }, + { + "name": "test_logical", + "long_name": "test_logical( self )", + "filename": "test_numeric.py", + "nloc": 6, + "complexity": 3, + "token_count": 38, + "parameters": [ + "self" + ], + "start_line": 76, + "end_line": 81, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 6, + "top_nesting_level": 1 + }, + { + "name": "test_bitwise_or", + "long_name": "test_bitwise_or( self )", + "filename": "test_numeric.py", + "nloc": 7, + "complexity": 1, + "token_count": 59, + "parameters": [ + "self" + ], + "start_line": 83, + "end_line": 89, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 7, + "top_nesting_level": 1 + }, + { + "name": "test_bitwise_and", + "long_name": "test_bitwise_and( self )", + "filename": "test_numeric.py", + "nloc": 7, + "complexity": 1, + "token_count": 59, + "parameters": [ + "self" + ], + "start_line": 91, + "end_line": 97, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 7, + "top_nesting_level": 1 + }, + { + "name": "test_bitwise_xor", + "long_name": "test_bitwise_xor( self )", + "filename": "test_numeric.py", + "nloc": 7, + "complexity": 1, + "token_count": 59, + "parameters": [ + "self" + ], + "start_line": 99, + "end_line": 105, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 7, + "top_nesting_level": 1 + } + ], + "methods_before": [ + { + "name": "setUp", + "long_name": "setUp( self )", + "filename": "test_numeric.py", + "nloc": 7, + "complexity": 1, + "token_count": 56, + "parameters": [ + "self" + ], + "start_line": 7, + "end_line": 13, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 7, + "top_nesting_level": 1 + }, + { + "name": "check_matmat", + "long_name": "check_matmat( self )", + "filename": "test_numeric.py", + "nloc": 5, + "complexity": 1, + "token_count": 46, + "parameters": [ + "self" + ], + "start_line": 15, + "end_line": 19, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 5, + "top_nesting_level": 1 + }, + { + "name": "check_matvec", + "long_name": "check_matvec( self )", + "filename": "test_numeric.py", + "nloc": 5, + "complexity": 1, + "token_count": 44, + "parameters": [ + "self" + ], + "start_line": 21, + "end_line": 25, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 5, + "top_nesting_level": 1 + }, + { + "name": "check_matvec2", + "long_name": "check_matvec2( self )", + "filename": "test_numeric.py", + "nloc": 5, + "complexity": 1, + "token_count": 44, + "parameters": [ + "self" + ], + "start_line": 27, + "end_line": 31, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 5, + "top_nesting_level": 1 + }, + { + "name": "check_vecmat", + "long_name": "check_vecmat( self )", + "filename": "test_numeric.py", + "nloc": 5, + "complexity": 1, + "token_count": 44, + "parameters": [ + "self" + ], + "start_line": 33, + "end_line": 37, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 5, + "top_nesting_level": 1 + }, + { + "name": "check_vecmat2", + "long_name": "check_vecmat2( self )", + "filename": "test_numeric.py", + "nloc": 5, + "complexity": 1, + "token_count": 52, + "parameters": [ + "self" + ], + "start_line": 39, + "end_line": 43, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 5, + "top_nesting_level": 1 + }, + { + "name": "check_vecmat3", + "long_name": "check_vecmat3( self )", + "filename": "test_numeric.py", + "nloc": 5, + "complexity": 1, + "token_count": 52, + "parameters": [ + "self" + ], + "start_line": 45, + "end_line": 49, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 5, + "top_nesting_level": 1 + }, + { + "name": "check_vecvecouter", + "long_name": "check_vecvecouter( self )", + "filename": "test_numeric.py", + "nloc": 5, + "complexity": 1, + "token_count": 44, + "parameters": [ + "self" + ], + "start_line": 51, + "end_line": 55, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 5, + "top_nesting_level": 1 + }, + { + "name": "check_vecvecinner", + "long_name": "check_vecvecinner( self )", + "filename": "test_numeric.py", + "nloc": 5, + "complexity": 1, + "token_count": 44, + "parameters": [ + "self" + ], + "start_line": 57, + "end_line": 61, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 5, + "top_nesting_level": 1 + }, + { + "name": "check_matscalar", + "long_name": "check_matscalar( self )", + "filename": "test_numeric.py", + "nloc": 3, + "complexity": 1, + "token_count": 32, + "parameters": [ + "self" + ], + "start_line": 63, + "end_line": 65, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 3, + "top_nesting_level": 1 + }, + { + "name": "test_logical", + "long_name": "test_logical( self )", + "filename": "test_numeric.py", + "nloc": 6, + "complexity": 3, + "token_count": 38, + "parameters": [ + "self" + ], + "start_line": 69, + "end_line": 74, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 6, + "top_nesting_level": 1 + }, + { + "name": "test_bitwise_or", + "long_name": "test_bitwise_or( self )", + "filename": "test_numeric.py", + "nloc": 7, + "complexity": 1, + "token_count": 59, + "parameters": [ + "self" + ], + "start_line": 76, + "end_line": 82, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 7, + "top_nesting_level": 1 + }, + { + "name": "test_bitwise_and", + "long_name": "test_bitwise_and( self )", + "filename": "test_numeric.py", + "nloc": 7, + "complexity": 1, + "token_count": 59, + "parameters": [ + "self" + ], + "start_line": 84, + "end_line": 90, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 7, + "top_nesting_level": 1 + }, + { + "name": "test_bitwise_xor", + "long_name": "test_bitwise_xor( self )", + "filename": "test_numeric.py", + "nloc": 7, + "complexity": 1, + "token_count": 59, + "parameters": [ + "self" + ], + "start_line": 92, + "end_line": 98, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 7, + "top_nesting_level": 1 + } + ], + "changed_methods": [ + { + "name": "check_columnvect", + "long_name": "check_columnvect( self )", + "filename": "test_numeric.py", + "nloc": 6, + "complexity": 1, + "token_count": 50, + "parameters": [ + "self" + ], + "start_line": 67, + "end_line": 72, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 6, + "top_nesting_level": 1 + } + ], + "nloc": 89, + "complexity": 17, + "token_count": 778, + "diff_parsed": { + "added": [ + " def check_columnvect(self):", + "\tb1 = ones((3,1))", + "\tb2 = [5.3]", + "\tc1 = dot(b1,b2)", + "\tc2 = dot_(b1,b2)", + "\tassert_almost_equal(c1, c2, decimal=self.N)", + "" + ], + "deleted": [] + } + }, + { + "old_path": "numpy/lib/function_base.py", + "new_path": "numpy/lib/function_base.py", + "filename": "function_base.py", + "extension": "py", + "change_type": "MODIFY", + "diff": "@@ -183,6 +183,8 @@ def piecewise(x, condlist, funclist, *args, **kw):\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", + "added_lines": 2, + "deleted_lines": 0, + "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 math\nimport numpy.core.numeric as _nx\nfrom numpy.core.numeric import ones, zeros, arange, concatenate, array, \\\n asarray, empty, empty_like\nfrom numpy.core.numeric import ScalarType, dot, where, newaxis, isscalar\nfrom numpy.core.umath import pi, multiply, add, arctan2, maximum, minimum, \\\n frompyfunc, isnan, absolute, cos, less_equal, sqrt, sin, mod, exp\nfrom numpy.core.oldnumeric import ravel, nonzero, choose, \\\n sometrue, alltrue, reshape, any, all, 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 n2 = len(funclist)\n if not isinstance(condlist, type([])):\n condlist = [condlist]\n n = len(condlist)\n if n == n2-1: # compute the \"otherwise\" condition.\n totlist = condlist[0]\n for k in range(1, n):\n totlist |= condlist\n condlist.append(~totlist)\n n += 1\n if (n != n2):\n raise ValueError, \"function list and condition list must be the same\"\n y = empty(x.shape, x.dtype)\n for k in range(n):\n item = funclist[k]\n if not callable(item):\n y[condlist[k]] = item\n else:\n y[condlist[k]] = item(x[condlist[k]], *args, **kw)\n return y\n\ndef select(condlist, choicelist, default=0):\n \"\"\" Return an array composed of different elements of choicelist\n depending on the list of conditions.\n\n condlist is a list of condition arrays containing ones or zeros\n\n choicelist is a list of choice arrays (of the \"same\" size as the\n arrays in condlist). The result array has the \"same\" size as the\n arrays in choicelist. If condlist is [c0, ..., cN-1] then choicelist\n must be of length N. The elements of the choicelist can then be\n represented as [v0, ..., vN-1]. The default choice if none of the\n conditions are met is given as the default argument. \n\n The conditions are tested in order and the first one statisfied is\n used to select the choice. In other words, the elements of the\n output array are found from the following tree (notice the order of\n the conditions matters):\n\n if c0: v0\n elif c1: v1\n elif c2: v2\n ...\n elif cN-1: vN-1\n else: default\n\n Note that one of the condition arrays must be large enough to handle\n the largest array in the choice list.\n \"\"\"\n n = len(condlist)\n n2 = len(choicelist)\n if n2 != n:\n raise ValueError, \"list of cases must be same length as list of conditions\"\n choicelist.insert(0, default)\n S = 0\n pfac = 1\n for k in range(1, n+1):\n S += k * pfac * asarray(condlist[k-1])\n if k < n:\n pfac *= (1-asarray(condlist[k-1]))\n # handle special case of a 1-element condition but\n # a multi-element choice\n if type(S) in ScalarType or max(asarray(S).shape)==1:\n pfac = asarray(1)\n for k in range(n2+1):\n pfac = pfac + asarray(choicelist[k])\n S = S*ones(asarray(pfac).shape)\n return choose(S, tuple(choicelist))\n\ndef _asarray1d(arr, copy=False):\n \"\"\"Ensure 1D array for one array.\n \"\"\"\n if copy:\n return asarray(arr).flatten()\n else:\n return asarray(arr).ravel()\n\ndef copy(a):\n \"\"\"Return an array copy of the given object.\n \"\"\"\n return array(a, copy=True)\n\n# Basic operations\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", + "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 math\nimport numpy.core.numeric as _nx\nfrom numpy.core.numeric import ones, zeros, arange, concatenate, array, \\\n asarray, empty, empty_like\nfrom numpy.core.numeric import ScalarType, dot, where, newaxis, isscalar\nfrom numpy.core.umath import pi, multiply, add, arctan2, maximum, minimum, \\\n frompyfunc, isnan, absolute, cos, less_equal, sqrt, sin, mod, exp\nfrom numpy.core.oldnumeric import ravel, nonzero, choose, \\\n sometrue, alltrue, reshape, any, all, 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\n The output is the same shape and type as x and is found by\n calling the functions on the appropriate portions of x.\n\n Note: This is similar to choose or select, except\n the the functions are only evaluated on elements of x\n that satisfy the corresponding condition.\n\n The result is\n |--\n | f1(x) for condition1\n y = --| f2(x) for condition2\n | ...\n | fn(x) for conditionn\n |--\n\n \"\"\"\n n2 = len(funclist)\n if not isinstance(condlist, type([])):\n condlist = [condlist]\n n = len(condlist)\n if n == n2-1: # compute the \"otherwise\" condition.\n totlist = condlist[0]\n for k in range(1, n):\n totlist |= condlist\n condlist.append(~totlist)\n n += 1\n if (n != n2):\n raise ValueError, \"function list and condition list must be the same\"\n y = empty(x.shape, x.dtype)\n for k in range(n):\n item = funclist[k]\n if not callable(item):\n y[condlist[k]] = item\n else:\n y[condlist[k]] = item(x[condlist[k]], *args, **kw)\n return y\n\ndef select(condlist, choicelist, default=0):\n \"\"\" Return an array composed of different elements of choicelist\n depending on the list of conditions.\n\n condlist is a list of condition arrays containing ones or zeros\n\n choicelist is a list of choice arrays (of the \"same\" size as the\n arrays in condlist). The result array has the \"same\" size as the\n arrays in choicelist. If condlist is [c0, ..., cN-1] then choicelist\n must be of length N. The elements of the choicelist can then be\n represented as [v0, ..., vN-1]. The default choice if none of the\n conditions are met is given as the default argument. \n\n The conditions are tested in order and the first one statisfied is\n used to select the choice. In other words, the elements of the\n output array are found from the following tree (notice the order of\n the conditions matters):\n\n if c0: v0\n elif c1: v1\n elif c2: v2\n ...\n elif cN-1: vN-1\n else: default\n\n Note that one of the condition arrays must be large enough to handle\n the largest array in the choice list.\n \"\"\"\n n = len(condlist)\n n2 = len(choicelist)\n if n2 != n:\n raise ValueError, \"list of cases must be same length as list of conditions\"\n choicelist.insert(0, default)\n S = 0\n pfac = 1\n for k in range(1, n+1):\n S += k * pfac * asarray(condlist[k-1])\n if k < n:\n pfac *= (1-asarray(condlist[k-1]))\n # handle special case of a 1-element condition but\n # a multi-element choice\n if type(S) in ScalarType or max(asarray(S).shape)==1:\n pfac = asarray(1)\n for k in range(n2+1):\n pfac = pfac + asarray(choicelist[k])\n S = S*ones(asarray(pfac).shape)\n return choose(S, tuple(choicelist))\n\ndef _asarray1d(arr, copy=False):\n \"\"\"Ensure 1D array for one array.\n \"\"\"\n if copy:\n return asarray(arr).flatten()\n else:\n return asarray(arr).ravel()\n\ndef copy(a):\n \"\"\"Return an array copy of the given object.\n \"\"\"\n return array(a, copy=True)\n\n# Basic operations\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": 32, + "end_line": 52, + "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": 54, + "end_line": 62, + "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": 64, + "end_line": 67, + "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": 69, + "end_line": 88, + "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": 90, + "end_line": 160, + "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": 162, + "end_line": 169, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 8, + "top_nesting_level": 0 + }, + { + "name": "piecewise", + "long_name": "piecewise( x , condlist , funclist , * args , ** kw )", + "filename": "function_base.py", + "nloc": 21, + "complexity": 7, + "token_count": 163, + "parameters": [ + "x", + "condlist", + "funclist", + "args", + "kw" + ], + "start_line": 171, + "end_line": 224, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 54, + "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 + } + ], + "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": 32, + "end_line": 52, + "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": 54, + "end_line": 62, + "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": 64, + "end_line": 67, + "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": 69, + "end_line": 88, + "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": 90, + "end_line": 160, + "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": 162, + "end_line": 169, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 8, + "top_nesting_level": 0 + }, + { + "name": "piecewise", + "long_name": "piecewise( x , condlist , funclist , * args , ** kw )", + "filename": "function_base.py", + "nloc": 21, + "complexity": 7, + "token_count": 163, + "parameters": [ + "x", + "condlist", + "funclist", + "args", + "kw" + ], + "start_line": 171, + "end_line": 222, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 52, + "top_nesting_level": 0 + }, + { + "name": "select", + "long_name": "select( condlist , choicelist , default = 0 )", + "filename": "function_base.py", + "nloc": 18, + "complexity": 7, + "token_count": 165, + "parameters": [ + "condlist", + "choicelist", + "default" + ], + "start_line": 224, + "end_line": 270, + "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": 272, + "end_line": 278, + "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": 280, + "end_line": 283, + "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": 287, + "end_line": 359, + "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": 362, + "end_line": 380, + "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": 382, + "end_line": 396, + "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": 398, + "end_line": 413, + "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": 415, + "end_line": 431, + "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": 433, + "end_line": 453, + "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": 455, + "end_line": 462, + "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": 464, + "end_line": 470, + "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": 472, + "end_line": 477, + "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": 479, + "end_line": 485, + "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": 487, + "end_line": 493, + "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": 495, + "end_line": 501, + "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": 503, + "end_line": 509, + "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": 511, + "end_line": 517, + "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": 519, + "end_line": 531, + "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": 564, + "end_line": 589, + "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": 591, + "end_line": 621, + "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": 623, + "end_line": 662, + "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": 664, + "end_line": 669, + "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": 671, + "end_line": 675, + "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": 677, + "end_line": 681, + "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": 683, + "end_line": 687, + "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": 689, + "end_line": 693, + "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": 756, + "end_line": 765, + "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": 767, + "end_line": 768, + "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": 770, + "end_line": 771, + "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": 773, + "end_line": 782, + "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": 786, + "end_line": 794, + "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": 796, + "end_line": 800, + "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": 802, + "end_line": 805, + "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": 807, + "end_line": 816, + "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": 818, + "end_line": 832, + "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": 835, + "end_line": 847, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 13, + "top_nesting_level": 0 + } + ], + "changed_methods": [ + { + "name": "piecewise", + "long_name": "piecewise( x , condlist , funclist , * args , ** kw )", + "filename": "function_base.py", + "nloc": 21, + "complexity": 7, + "token_count": 163, + "parameters": [ + "x", + "condlist", + "funclist", + "args", + "kw" + ], + "start_line": 171, + "end_line": 224, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 54, + "top_nesting_level": 0 + } + ], + "nloc": 561, + "complexity": 140, + "token_count": 4441, + "diff_parsed": { + "added": [ + " A constant may be used in funclist for a function that returns a", + " constant (e.g. val and lambda x: val are equivalent in a funclist)." + ], + "deleted": [] + } + } + ] + }, + { + "hash": "518655847eb27aadcccc4fb9fed27897fcc9828d", + "msg": "Fix column-vector x (1,) in dotblas.", + "author": { + "name": "Travis Oliphant", + "email": "oliphant@enthought.com" + }, + "committer": { + "name": "Travis Oliphant", + "email": "oliphant@enthought.com" + }, + "author_date": "2006-01-29T03:20:22+00:00", + "author_timezone": 0, + "committer_date": "2006-01-29T03:20:22+00:00", + "committer_timezone": 0, + "branches": [ + "main" + ], + "in_main_branch": true, + "merge": false, + "parents": [ + "83d691d731082ec8d2367affb77b454c2a0b0855" + ], + "project_name": "repo_copy", + "project_path": "/tmp/tmppy2o86q9/repo_copy", + "deletions": 7, + "insertions": 8, + "lines": 15, + "files": 1, + "dmm_unit_size": 0.0, + "dmm_unit_complexity": 0.0, + "dmm_unit_interfacing": 1.0, + "modified_files": [ + { + "old_path": "numpy/core/blasdot/_dotblas.c", + "new_path": "numpy/core/blasdot/_dotblas.c", + "filename": "_dotblas.c", + "extension": "c", + "change_type": "MODIFY", + "diff": "@@ -136,7 +136,7 @@ _select_matrix_shape(PyArrayObject *array)\n case 0:\n \treturn _scalar;\n case 1:\n-\tif (array->dimensions[0] > 0)\n+\tif (array->dimensions[0] > 1)\n \t return _column;\n \treturn _scalar;\n case 2:\n@@ -228,11 +228,12 @@ dotblas_matrixproduct(PyObject *dummy, PyObject *args)\n \t ap1shape = ap2shape;\n \t ap2shape = _scalar;\n \t}\n-\tfor (l = 1, j = 0; j < ap1->nd; j++) {\n+\tif (ap1shape == _column) nd = 1;\n+\telse nd = ap1->nd;\n+\tfor (l = 1, j = 0; j < nd; j++) {\n \t dimensions[j] = ap1->dimensions[j];\n \t l *= dimensions[j];\n \t}\n-\tnd = ap1->nd;\n }\n else { /* (ap1->nd <= 2 && ap2->nd <= 2) */\n \t/* Both ap1 and ap2 are vectors or matrices */\n@@ -287,7 +288,7 @@ dotblas_matrixproduct(PyObject *dummy, PyObject *args)\n \t\t*((double *)ret->data) = *((double *)ap2->data) * \\\n \t\t *((double *)ap1->data);\n \t }\n-\t else if (ap1->nd < 2) {\n+\t else if (ap1->nd < 2 || ap1shape == _column) {\n \t\tcblas_daxpy(l, *((double *)ap2->data), (double *)ap1->data,\n \t\t\t ap1->strides[0] / sizeof(double), \n \t\t\t (double *)ret->data, 1);\n@@ -321,7 +322,7 @@ dotblas_matrixproduct(PyObject *dummy, PyObject *args)\n \t\tres->real = ptr1->real * ptr2->real - ptr1->imag * ptr2->imag;\n \t\tres->imag = ptr1->real * ptr2->imag + ptr1->imag * ptr2->real;\n \t }\n-\t else if (ap1->nd < 2) {\n+\t else if (ap1->nd < 2 || ap1shape == _column) {\n \t\tcblas_zaxpy(l, (double *)ap2->data, (double *)ap1->data,\n \t\t\t ap1->strides[0] / sizeof(cdouble), \n \t\t\t (double *)ret->data, 1);\n@@ -351,7 +352,7 @@ dotblas_matrixproduct(PyObject *dummy, PyObject *args)\n \t\t*((float *)ret->data) = *((float *)ap2->data) * \\\n \t\t *((float *)ap1->data);\n \t }\n-\t else if (ap1->nd < 2) {\n+\t else if (ap1->nd < 2 || ap1shape == _column) {\n \t\tcblas_saxpy(l, *((float *)ap2->data), (float *)ap1->data,\n \t\t\t ap1->strides[0] / sizeof(float), \n \t\t\t (float *)ret->data, 1);\n@@ -385,7 +386,7 @@ dotblas_matrixproduct(PyObject *dummy, PyObject *args)\n \t\tres->real = ptr1->real * ptr2->real - ptr1->imag * ptr2->imag;\n \t\tres->imag = ptr1->real * ptr2->imag + ptr1->imag * ptr2->real;\n \t }\n-\t else if (ap1->nd < 2) {\n+\t else if (ap1->nd < 2 || ap1shape == _column) {\n \t\tcblas_caxpy(l, (float *)ap2->data, (float *)ap1->data,\n \t\t\t ap1->strides[0] / sizeof(cfloat), \n \t\t\t (float *)ret->data, 1);\n", + "added_lines": 8, + "deleted_lines": 7, + "source_code": "static char module_doc[] =\n\"This module provides a BLAS optimized\\nmatrix multiply, inner product and dot for numpy arrays\";\n\n#include \"Python.h\"\n#include \"numpy/arrayobject.h\"\n#ifndef CBLAS_HEADER\n#define CBLAS_HEADER \"cblas.h\"\n#endif\n#include CBLAS_HEADER\n\n#include \n\nstatic void \nFLOAT_dot(void *a, intp stridea, void *b, intp strideb, void *res, \n\t intp n, void *tmp)\n{\n register int na = stridea / sizeof(float);\n register int nb = strideb / sizeof(float);\n\n *((float *)res) = cblas_sdot((int)n, (float *)a, na, (float *)b, nb);\n}\n\nstatic void \nDOUBLE_dot(void *a, intp stridea, void *b, intp strideb, void *res, \n\t intp n, void *tmp)\n{\n register int na = stridea / sizeof(double);\n register int nb = strideb / sizeof(double);\n\n *((double *)res) = cblas_ddot((int)n, (double *)a, na, (double *)b, nb);\n}\n\nstatic void \nCFLOAT_dot(void *a, intp stridea, void *b, intp strideb, void *res, \n\t intp n, void *tmp)\n{\n \n register int na = stridea / sizeof(cfloat);\n register int nb = strideb / sizeof(cfloat);\n\n cblas_cdotu_sub((int)n, (float *)a, na, (float *)b, nb, (float *)res);\n}\n\nstatic void \nCDOUBLE_dot(void *a, intp stridea, void *b, intp strideb, void *res, \n\t intp n, void *tmp)\n{\n register int na = stridea / sizeof(cdouble);\n register int nb = strideb / sizeof(cdouble);\n\n cblas_zdotu_sub((int)n, (double *)a, na, (double *)b, nb, (double *)res);\n}\n\n\nstatic PyArray_DotFunc *oldFunctions[PyArray_NTYPES];\nstatic Bool altered=FALSE;\n\nstatic char doc_alterdot[] = \"alterdot() changes all dot functions to use blas.\";\n\nstatic PyObject *\ndotblas_alterdot(PyObject *dummy, PyObject *args) \n{\n PyArray_Descr *descr;\n \n if (!PyArg_ParseTuple(args, \"\")) return NULL;\n\n /* Replace the dot functions to the ones using blas */\n\n if (!altered) {\n\tdescr = PyArray_DescrFromType(PyArray_FLOAT);\n\toldFunctions[PyArray_FLOAT] = descr->f->dotfunc;\n\tdescr->f->dotfunc = (PyArray_DotFunc *)FLOAT_dot;\n\t\n\tdescr = PyArray_DescrFromType(PyArray_DOUBLE);\n\toldFunctions[PyArray_DOUBLE] = descr->f->dotfunc;\n\tdescr->f->dotfunc = (PyArray_DotFunc *)DOUBLE_dot;\n\t\n\tdescr = PyArray_DescrFromType(PyArray_CFLOAT);\n\toldFunctions[PyArray_CFLOAT] = descr->f->dotfunc;\n\tdescr->f->dotfunc = (PyArray_DotFunc *)CFLOAT_dot;\n\t\n\tdescr = PyArray_DescrFromType(PyArray_CDOUBLE);\n\toldFunctions[PyArray_CDOUBLE] = descr->f->dotfunc;\n\tdescr->f->dotfunc = (PyArray_DotFunc *)CDOUBLE_dot;\n\n\taltered = TRUE;\n }\n\n Py_INCREF(Py_None);\n return Py_None;\n}\n\nstatic char doc_restoredot[] = \"restoredot() restores dots to defaults.\";\n\nstatic PyObject *\ndotblas_restoredot(PyObject *dummy, PyObject *args) \n{\n PyArray_Descr *descr;\n\n if (!PyArg_ParseTuple(args, \"\")) return NULL;\n\n if (altered) {\n\tdescr = PyArray_DescrFromType(PyArray_FLOAT);\n\tdescr->f->dotfunc = oldFunctions[PyArray_FLOAT];\n\toldFunctions[PyArray_FLOAT] = NULL;\n\tPy_XDECREF(descr);\n\n\tdescr = PyArray_DescrFromType(PyArray_DOUBLE);\n\tdescr->f->dotfunc = oldFunctions[PyArray_DOUBLE];\n\toldFunctions[PyArray_DOUBLE] = NULL;\n\tPy_XDECREF(descr);\n\n\tdescr = PyArray_DescrFromType(PyArray_CFLOAT);\n\tdescr->f->dotfunc = oldFunctions[PyArray_CFLOAT];\n\toldFunctions[PyArray_CFLOAT] = NULL;\n\tPy_XDECREF(descr);\n\n\tdescr = PyArray_DescrFromType(PyArray_CDOUBLE);\n\tdescr->f->dotfunc = oldFunctions[PyArray_CDOUBLE];\n\toldFunctions[PyArray_CDOUBLE] = NULL;\n\tPy_XDECREF(descr);\n\t\n\taltered = FALSE;\n }\n\n Py_INCREF(Py_None);\n return Py_None;\n}\n\ntypedef enum {_scalar, _column, _row, _matrix} MatrixShape;\n\nstatic MatrixShape \n_select_matrix_shape(PyArrayObject *array)\n{\n switch (array->nd) {\n case 0:\n\treturn _scalar;\n case 1:\n\tif (array->dimensions[0] > 1)\n\t return _column;\n\treturn _scalar;\n case 2:\n\tif (array->dimensions[0] > 1) {\n\t if (array->dimensions[1] == 1)\n\t\treturn _column;\n\t else\n\t\treturn _matrix;\n\t}\n\tif (array->dimensions[1] == 1)\n\t return _scalar;\n\treturn _row;\n }\n return _matrix;\n}\n\n\nstatic char doc_matrixproduct[] = \"matrixproduct(a,b)\\nReturns the dot product of a and b for arrays of floating point types.\\nLike the generic numpy equivalent the product sum is over\\nthe last dimension of a and the second-to-last dimension of b.\\nNB: The first argument is not conjugated.\";\n\nstatic PyObject *\ndotblas_matrixproduct(PyObject *dummy, PyObject *args) \n{\n PyObject *op1, *op2;\n PyArrayObject *ap1, *ap2, *ret;\n int j, l, lda, ldb, ldc;\n int typenum, nd;\n intp dimensions[MAX_DIMS];\n static const float oneF[2] = {1.0, 0.0};\n static const float zeroF[2] = {0.0, 0.0};\n static const double oneD[2] = {1.0, 0.0};\n static const double zeroD[2] = {0.0, 0.0};\n double prior1, prior2;\n PyTypeObject *subtype;\n PyArray_Descr *dtype;\n MatrixShape ap1shape, ap2shape;\n \n if (!PyArg_ParseTuple(args, \"OO\", &op1, &op2)) return NULL;\n\t\n /* \n * \"Matrix product\" using the BLAS. \n * Only works for float double and complex types.\n */\n\n\n typenum = PyArray_ObjectType(op1, 0); \n typenum = PyArray_ObjectType(op2, typenum);\n \n /* This function doesn't handle other types */\n if ((typenum != PyArray_DOUBLE && typenum != PyArray_CDOUBLE &&\n\t typenum != PyArray_FLOAT && typenum != PyArray_CFLOAT)) {\n\treturn PyArray_Return((PyArrayObject *)PyArray_MatrixProduct(op1, op2));\n }\n \n ret = NULL;\n dtype = PyArray_DescrFromType(typenum);\n ap1 = (PyArrayObject *)PyArray_FromAny(op1, dtype, 0, 0, ALIGNED, NULL);\n if (ap1 == NULL) return NULL;\n ap2 = (PyArrayObject *)PyArray_FromAny(op2, dtype, 0, 0, ALIGNED, NULL);\n if (ap2 == NULL) goto fail;\n \n if ((ap1->nd > 2) || (ap2->nd > 2)) { \n\t/* This function doesn't handle dimensions greater than 2 -- other\n\t than to ensure the dot function is altered\n\t*/\n\tif (!altered) {\n\t /* need to alter dot product */\n\t PyObject *tmp1, *tmp2;\n\t tmp1 = PyTuple_New(0);\n\t tmp2 = dotblas_alterdot(NULL, tmp1);\n\t Py_DECREF(tmp1); \n\t Py_DECREF(tmp2);\n\t}\n\tret = (PyArrayObject *)PyArray_MatrixProduct((PyObject *)ap1, \n\t\t\t\t\t\t (PyObject *)ap2);\n\tPy_DECREF(ap1); \n\tPy_DECREF(ap2);\n\treturn PyArray_Return(ret);\n }\n \n ap1shape = _select_matrix_shape(ap1);\n ap2shape = _select_matrix_shape(ap2);\n \n if (ap1shape == _scalar || ap2shape == _scalar) {\n\t/* One of ap1 or ap2 is a scalar */\n\tif (ap1shape == _scalar) { \t\t/* Make ap2 the scalar */\n\t PyArrayObject *t = ap1;\n\t ap1 = ap2;\n\t ap2 = t;\n\t ap1shape = ap2shape;\n\t ap2shape = _scalar;\n\t}\n\tif (ap1shape == _column) nd = 1;\n\telse nd = ap1->nd;\n\tfor (l = 1, j = 0; j < nd; j++) {\n\t dimensions[j] = ap1->dimensions[j];\n\t l *= dimensions[j];\n\t}\n }\n else { /* (ap1->nd <= 2 && ap2->nd <= 2) */\n\t/* Both ap1 and ap2 are vectors or matrices */\n\tl = ap1->dimensions[ap1->nd-1];\n\t\n\tif (ap2->dimensions[0] != l) {\n\t PyErr_SetString(PyExc_ValueError, \"matrices are not aligned\");\n\t goto fail;\n\t}\n\tnd = ap1->nd+ap2->nd-2;\n\t\n\tif (nd == 1) \n\t dimensions[0] = (ap1->nd == 2) ? ap1->dimensions[0] : ap2->dimensions[1];\n\telse if (nd == 2) {\n\t dimensions[0] = ap1->dimensions[0];\n\t dimensions[1] = ap2->dimensions[1];\n\t}\n }\n \n /* Choose which subtype to return */\n if (ap1->ob_type != ap2->ob_type) {\n\tprior2 = PyArray_GetPriority((PyObject *)ap2, 0.0);\n\tprior1 = PyArray_GetPriority((PyObject *)ap1, 0.0);\n\tsubtype = (prior2 > prior1 ? ap2->ob_type : ap1->ob_type);\n }\n else {\n\tprior1 = prior2 = 0.0;\n\tsubtype = ap1->ob_type;\n }\n \n if (l==0) nd = 0;\n ret = (PyArrayObject *)PyArray_New(subtype, nd, dimensions,\n\t\t\t\t typenum, NULL, NULL, 0, 0,\n\t\t\t\t (PyObject *)\n\t\t\t\t (prior2 > prior1 ? ap2 : ap1));\n \n if (ret == NULL) goto fail;\n memset(ret->data, 0, PyArray_NBYTES(ret));\n if (l==0) {\n\t Py_DECREF(ap1);\n\t Py_DECREF(ap2);\n\t return PyArray_Return(ret);\n }\n \n if (ap2shape == _scalar) {\n\t/* Multiplication by a scalar -- Level 1 BLAS */\n\t/* if ap1shape is a matrix and we are not contiguous, then we can't\n\t just blast through the entire array using a single\n\t striding factor */\n\tif (typenum == PyArray_DOUBLE) {\n\t if (l == 1) {\n\t\t*((double *)ret->data) = *((double *)ap2->data) * \\\n\t\t *((double *)ap1->data);\n\t }\n\t else if (ap1->nd < 2 || ap1shape == _column) {\n\t\tcblas_daxpy(l, *((double *)ap2->data), (double *)ap1->data,\n\t\t\t ap1->strides[0] / sizeof(double), \n\t\t\t (double *)ret->data, 1);\n\t }\n\t else {\n\t\tint maxind, oind, i, a1s, rets;\n\t\tchar *ptr, *rptr;\n\t\tdouble val;\n\t\tmaxind = (ap1->dimensions[0] >= ap1->dimensions[1] ? 0 : 1);\n\t\toind = 1-maxind;\n\t\tptr = ap1->data;\n\t\trptr = ret->data;\n\t\tl = ap1->dimensions[maxind];\n\t\tval = *((double *)ap2->data);\n\t\ta1s = ap1->strides[maxind] / sizeof(double);\n\t\trets = ret->strides[maxind] / sizeof(double);\n\t\tfor (i=0; i < ap1->dimensions[oind]; i++) {\n\t\t cblas_daxpy(l, val, (double *)ptr, a1s, \n\t\t\t\t(double *)rptr, rets);\n\t\t ptr += ap1->strides[oind];\n\t\t rptr += ret->strides[oind];\n\t\t}\n\t }\n\t} \n\telse if (typenum == PyArray_CDOUBLE) {\n\t if (l == 1) {\n\t\tcdouble *ptr1, *ptr2, *res;\n\t\tptr1 = (cdouble *)ap2->data;\n\t\tptr2 = (cdouble *)ap1->data;\n\t\tres = (cdouble *)ret->data;\t\t\n\t\tres->real = ptr1->real * ptr2->real - ptr1->imag * ptr2->imag;\n\t\tres->imag = ptr1->real * ptr2->imag + ptr1->imag * ptr2->real;\n\t }\n\t else if (ap1->nd < 2 || ap1shape == _column) {\n\t\tcblas_zaxpy(l, (double *)ap2->data, (double *)ap1->data,\n\t\t\t ap1->strides[0] / sizeof(cdouble), \n\t\t\t (double *)ret->data, 1);\n\t }\n\t else {\n\t\tint maxind, oind, i, a1s, rets;\n\t\tchar *ptr, *rptr;\n\t\tdouble *pval;\n\t\tmaxind = (ap1->dimensions[0] >= ap1->dimensions[1] ? 0 : 1);\n\t\toind = 1-maxind;\n\t\tptr = ap1->data;\n\t\trptr = ret->data;\n\t\tl = ap1->dimensions[maxind];\n\t\tpval = (double *)ap2->data;\n\t\ta1s = ap1->strides[maxind] / sizeof(cdouble);\n\t\trets = ret->strides[maxind] / sizeof(cdouble);\n\t\tfor (i=0; i < ap1->dimensions[oind]; i++) {\n\t\t cblas_zaxpy(l, pval, (double *)ptr, a1s, \n\t\t\t\t(double *)rptr, rets);\n\t\t ptr += ap1->strides[oind];\n\t\t rptr += ret->strides[oind];\n\t\t}\n\t }\n\t}\n\telse if (typenum == PyArray_FLOAT) {\n\t if (l == 1) {\n\t\t*((float *)ret->data) = *((float *)ap2->data) * \\\n\t\t *((float *)ap1->data);\n\t }\n\t else if (ap1->nd < 2 || ap1shape == _column) {\n\t\tcblas_saxpy(l, *((float *)ap2->data), (float *)ap1->data,\n\t\t\t ap1->strides[0] / sizeof(float), \n\t\t\t (float *)ret->data, 1);\n\t }\n\t else {\n\t\tint maxind, oind, i, a1s, rets;\n\t\tchar *ptr, *rptr;\n\t\tfloat val;\n\t\tmaxind = (ap1->dimensions[0] >= ap1->dimensions[1] ? 0 : 1);\n\t\toind = 1-maxind;\n\t\tptr = ap1->data;\n\t\trptr = ret->data;\n\t\tl = ap1->dimensions[maxind];\n\t\tval = *((float *)ap2->data);\n\t\ta1s = ap1->strides[maxind] / sizeof(float);\n\t\trets = ret->strides[maxind] / sizeof(float);\n\t\tfor (i=0; i < ap1->dimensions[oind]; i++) {\n\t\t cblas_saxpy(l, val, (float *)ptr, a1s, \n\t\t\t\t(float *)rptr, rets);\n\t\t ptr += ap1->strides[oind];\n\t\t rptr += ret->strides[oind];\n\t\t}\n\t }\n\t}\n\telse if (typenum == PyArray_CFLOAT) {\n\t if (l == 1) {\n\t\tcfloat *ptr1, *ptr2, *res;\n\t\tptr1 = (cfloat *)ap2->data;\n\t\tptr2 = (cfloat *)ap1->data;\n\t\tres = (cfloat *)ret->data;\t\t\n\t\tres->real = ptr1->real * ptr2->real - ptr1->imag * ptr2->imag;\n\t\tres->imag = ptr1->real * ptr2->imag + ptr1->imag * ptr2->real;\n\t }\n\t else if (ap1->nd < 2 || ap1shape == _column) {\n\t\tcblas_caxpy(l, (float *)ap2->data, (float *)ap1->data,\n\t\t\t ap1->strides[0] / sizeof(cfloat), \n\t\t\t (float *)ret->data, 1);\n\t }\n\t else {\n\t\tint maxind, oind, i, a1s, rets;\n\t\tchar *ptr, *rptr;\n\t\tfloat *pval;\n\t\tmaxind = (ap1->dimensions[0] >= ap1->dimensions[1] ? 0 : 1);\n\t\toind = 1-maxind;\n\t\tptr = ap1->data;\n\t\trptr = ret->data;\n\t\tl = ap1->dimensions[maxind];\n\t\tpval = (float *)ap2->data;\n\t\ta1s = ap1->strides[maxind] / sizeof(cfloat);\n\t\trets = ret->strides[maxind] / sizeof(cfloat);\n\t\tfor (i=0; i < ap1->dimensions[oind]; i++) {\n\t\t cblas_caxpy(l, pval, (float *)ptr, a1s, \n\t\t\t\t(float *)rptr, rets);\n\t\t ptr += ap1->strides[oind];\n\t\t rptr += ret->strides[oind];\n\t\t}\n\t }\n\t}\n }\n else if ((ap2shape == _column) && (ap1shape != _matrix)) {\n\tint ap1s, ap2s;\n\tap2s = ap2->strides[0] / ap2->descr->elsize;\n\tif (ap1shape == _row) {\n\t ap1s = ap1->strides[1] / ap1->descr->elsize;\n\t}\n\telse {\n\t ap1s = ap1->strides[0] / ap1->descr->elsize;\n\t}\n\t \n\t/* Dot product between two vectors -- Level 1 BLAS */\n\tif (typenum == PyArray_DOUBLE) {\n\t double result = cblas_ddot(l, (double *)ap1->data, ap1s, \n\t\t\t\t (double *)ap2->data, ap2s);\n\t *((double *)ret->data) = result;\n\t}\n\telse if (typenum == PyArray_FLOAT) {\n\t float result = cblas_sdot(l, (float *)ap1->data, ap1s, \n\t\t\t\t (float *)ap2->data, ap2s);\n\t *((float *)ret->data) = result;\n\t}\n\telse if (typenum == PyArray_CDOUBLE) {\n\t cblas_zdotu_sub(l, (double *)ap1->data, ap1s, \n\t\t\t (double *)ap2->data, ap2s, (double *)ret->data);\n\t}\n\telse if (typenum == PyArray_CFLOAT) {\n\t cblas_cdotu_sub(l, (float *)ap1->data, ap1s, \n\t\t\t (float *)ap2->data, ap2s, (float *)ret->data);\n\t}\n }\n else if (ap1shape == _matrix && ap2shape != _matrix) {\n\t/* Matrix vector multiplication -- Level 2 BLAS */\n\t/* lda must be MAX(M,1) */\n\tenum CBLAS_ORDER Order;\n\tint ap2s;\n\n\tif (!PyArray_ISONESEGMENT(ap1)) {\n\t PyObject *new;\n\t new = PyArray_Copy(ap1);\n\t Py_DECREF(ap1);\n\t ap1 = (PyArrayObject *)new;\n\t if (new == NULL) goto fail;\n\t}\n\tif (PyArray_ISCONTIGUOUS(ap1)) {\n Order = CblasRowMajor;\n lda = (ap1->dimensions[1] > 1 ? ap1->dimensions[1] : 1);\n\t}\n\telse {\n\t Order = CblasColMajor;\n lda = (ap1->dimensions[0] > 1 ? ap1->dimensions[0] : 1);\n\t}\n\tap2s = ap2->strides[0] / ap2->descr->elsize;\n\tif (typenum == PyArray_DOUBLE) {\n\t cblas_dgemv(Order, CblasNoTrans, \n\t\t\tap1->dimensions[0], ap1->dimensions[1], \n\t\t\t1.0, (double *)ap1->data, lda, \n\t\t\t(double *)ap2->data, ap2s, 0.0, (double *)ret->data, 1);\n\t}\n\telse if (typenum == PyArray_FLOAT) {\n\t cblas_sgemv(Order, CblasNoTrans, \n\t\t\tap1->dimensions[0], ap1->dimensions[1], \n\t\t\t1.0, (float *)ap1->data, lda, \n\t\t\t(float *)ap2->data, ap2s, 0.0, (float *)ret->data, 1);\n\t}\n\telse if (typenum == PyArray_CDOUBLE) {\n\t cblas_zgemv(Order, \n\t\t\tCblasNoTrans, ap1->dimensions[0], ap1->dimensions[1], \n\t\t\toneD, (double *)ap1->data, lda, \n\t\t\t(double *)ap2->data, ap2s, zeroD, \n\t\t\t(double *)ret->data, 1);\n\t}\n\telse if (typenum == PyArray_CFLOAT) {\n\t cblas_cgemv(Order, \n\t\t\tCblasNoTrans, ap1->dimensions[0], ap1->dimensions[1], \n\t\t\toneF, (float *)ap1->data, lda, \n\t\t\t(float *)ap2->data, ap2s, zeroF, \n\t\t\t(float *)ret->data, 1);\n\t}\n }\n else if (ap1shape != _matrix && ap2shape == _matrix) {\n\t/* Vector matrix multiplication -- Level 2 BLAS */\n\tenum CBLAS_ORDER Order;\n\tint ap1s;\n\n\tif (!PyArray_ISONESEGMENT(ap2)) {\n\t PyObject *new;\n\t new = PyArray_Copy(ap2);\n\t Py_DECREF(ap2);\n\t ap2 = (PyArrayObject *)new;\n\t if (new == NULL) goto fail;\n\t}\n\tif (PyArray_ISCONTIGUOUS(ap2)) {\n\t Order = CblasRowMajor;\n lda = (ap2->dimensions[1] > 1 ? ap2->dimensions[1] : 1);\n\t}\n\telse {\n\t Order = CblasColMajor;\n lda = (ap2->dimensions[0] > 1 ? ap2->dimensions[0] : 1);\n\t}\n\tif (ap1shape == _row) {\n\t ap1s = ap1->strides[1] / ap1->descr->elsize;\n\t}\n\telse {\n\t ap1s = ap1->strides[0] / ap1->descr->elsize;\n\t}\n\tif (typenum == PyArray_DOUBLE) {\n\t cblas_dgemv(Order, \n\t\t\tCblasTrans, ap2->dimensions[0], ap2->dimensions[1], \n\t\t\t1.0, (double *)ap2->data, lda,\n\t\t\t(double *)ap1->data, ap1s, 0.0, (double *)ret->data, 1);\n\t}\n\telse if (typenum == PyArray_FLOAT) {\n\t cblas_sgemv(Order,\n\t\t\tCblasTrans, ap2->dimensions[0], ap2->dimensions[1], \n\t\t\t1.0, (float *)ap2->data, lda,\n\t\t\t(float *)ap1->data, ap1s, 0.0, (float *)ret->data, 1);\n\t}\n\telse if (typenum == PyArray_CDOUBLE) {\n\t cblas_zgemv(Order,\n\t\t\tCblasTrans, ap2->dimensions[0], ap2->dimensions[1], \n\t\t\toneD, (double *)ap2->data, lda,\n\t\t\t(double *)ap1->data, ap1s, zeroD, (double *)ret->data, 1);\n\t}\n\telse if (typenum == PyArray_CFLOAT) {\n\t cblas_cgemv(Order,\n\t\t\tCblasTrans, ap2->dimensions[0], ap2->dimensions[1], \n\t\t\toneF, (float *)ap2->data, lda,\n\t\t\t(float *)ap1->data, ap1s, zeroF, (float *)ret->data, 1);\n\t}\n }\n else { /* (ap1->nd == 2 && ap2->nd == 2) */\n\t/* Matrix matrix multiplication -- Level 3 BLAS */ \n\t/* L x M multiplied by M x N */\n\tenum CBLAS_ORDER Order;\n\tenum CBLAS_TRANSPOSE Trans1, Trans2;\n\tint M, N, L;\n\n\t/* Optimization possible: */\n\t/* We may be able to handle single-segment arrays here\n\t using appropriate values of Order, Trans1, and Trans2.\n\t*/\n\t\n \tif (!PyArray_ISCONTIGUOUS(ap2)) {\n\t PyObject *new;\n\t new = PyArray_Copy(ap2);\n\t Py_DECREF(ap2);\n\t ap2 = (PyArrayObject *)new;\n\t if (new == NULL) goto fail;\n\t}\n\tif (!PyArray_ISCONTIGUOUS(ap1)) {\n\t PyObject *new;\n\t new = PyArray_Copy(ap1);\n\t Py_DECREF(ap1);\n\t ap1 = (PyArrayObject *)new;\n\t if (new == NULL) goto fail;\n\t}\n\t\n\tOrder = CblasRowMajor;\n\tTrans1 = CblasNoTrans;\n\tTrans2 = CblasNoTrans;\n\tL = ap1->dimensions[0];\n\tN = ap2->dimensions[1];\n\tM = ap2->dimensions[0];\n\tlda = (ap1->dimensions[1] > 1 ? ap1->dimensions[1] : 1);\n\tldb = (ap2->dimensions[1] > 1 ? ap2->dimensions[1] : 1);\n\tldc = (ret->dimensions[1] > 1 ? ret->dimensions[1] : 1);\t \n\tif (typenum == PyArray_DOUBLE) {\n\t cblas_dgemm(Order, Trans1, Trans2, \n\t\t\tL, N, M,\n\t\t\t1.0, (double *)ap1->data, lda,\n\t\t\t(double *)ap2->data, ldb,\n\t\t\t0.0, (double *)ret->data, ldc);\n\t}\n\telse if (typenum == PyArray_FLOAT) {\n\t cblas_sgemm(Order, Trans1, Trans2,\n\t\t\tL, N, M, \n\t\t\t1.0, (float *)ap1->data, lda,\n\t\t\t(float *)ap2->data, ldb,\n\t\t\t0.0, (float *)ret->data, ldc);\n\t}\n\telse if (typenum == PyArray_CDOUBLE) {\n\t cblas_zgemm(Order, Trans1, Trans2,\n\t\t\tL, N, M, \n\t\t\toneD, (double *)ap1->data, lda,\n\t\t\t(double *)ap2->data, ldb,\n\t\t\tzeroD, (double *)ret->data, ldc);\n\t}\n\telse if (typenum == PyArray_CFLOAT) {\n\t cblas_cgemm(Order, Trans1, Trans2,\n\t\t\tL, N, M,\n\t\t\toneF, (float *)ap1->data, lda,\n\t\t\t(float *)ap2->data, ldb,\n\t\t\tzeroF, (float *)ret->data, ldc);\n\t}\n }\n\n Py_DECREF(ap1);\n Py_DECREF(ap2);\n return PyArray_Return(ret);\n\t\n fail:\n Py_XDECREF(ap1);\n Py_XDECREF(ap2);\n Py_XDECREF(ret);\n return NULL;\n}\n\n\nstatic char doc_innerproduct[] = \"innerproduct(a,b)\\nReturns the inner product of a and b for arrays of floating point types.\\nLike the generic Numeric equivalent the product sum is over\\nthe last dimension of a and b.\\nNB: The first argument is not conjugated.\";\n\nstatic PyObject *\ndotblas_innerproduct(PyObject *dummy, PyObject *args) \n{\n PyObject *op1, *op2;\n PyArrayObject *ap1, *ap2, *ret;\n int j, l, lda, ldb, ldc;\n int typenum, nd;\n intp dimensions[MAX_DIMS];\n static const float oneF[2] = {1.0, 0.0};\n static const float zeroF[2] = {0.0, 0.0};\n static const double oneD[2] = {1.0, 0.0};\n static const double zeroD[2] = {0.0, 0.0};\n PyTypeObject *subtype;\n double prior1, prior2;\n\n if (!PyArg_ParseTuple(args, \"OO\", &op1, &op2)) return NULL;\n\t\n /* \n * Inner product using the BLAS. The product sum is taken along the last\n * dimensions of the two arrays.\n * Only speeds things up for float double and complex types.\n */\n\n\n typenum = PyArray_ObjectType(op1, 0); \n typenum = PyArray_ObjectType(op2, typenum);\n\n /* This function doesn't handle other types */\n if ((typenum != PyArray_DOUBLE && typenum != PyArray_CDOUBLE &&\n\t typenum != PyArray_FLOAT && typenum != PyArray_CFLOAT)) {\n return PyArray_Return((PyArrayObject *)PyArray_InnerProduct(op1, op2));\n }\n\n ret = NULL;\n ap1 = (PyArrayObject *)PyArray_ContiguousFromObject(op1, typenum, 0, 0);\n if (ap1 == NULL) return NULL;\n ap2 = (PyArrayObject *)PyArray_ContiguousFromObject(op2, typenum, 0, 0);\n if (ap2 == NULL) goto fail;\n\n if ((ap1->nd > 2) || (ap2->nd > 2)) { \n\t/* This function doesn't handle dimensions greater than 2 -- other\n\t than to ensure the dot function is altered\n\t*/\n\tif (!altered) {\n\t /* need to alter dot product */\n\t PyObject *tmp1, *tmp2;\n\t tmp1 = PyTuple_New(0);\n\t tmp2 = dotblas_alterdot(NULL, tmp1);\n\t Py_DECREF(tmp1); \n\t Py_DECREF(tmp2);\n\t}\n\tret = (PyArrayObject *)PyArray_InnerProduct((PyObject *)ap1, \n\t\t\t\t\t\t (PyObject *)ap2);\n\tPy_DECREF(ap1); \n\tPy_DECREF(ap2);\n\treturn PyArray_Return(ret);\n }\n\n if (ap1->nd == 0 || ap2->nd == 0) {\n\t/* One of ap1 or ap2 is a scalar */\n\tif (ap1->nd == 0) {\t\t/* Make ap2 the scalar */\n\t PyArrayObject *t = ap1;\n\t ap1 = ap2;\n\t ap2 = t;\n\t}\n\tfor (l = 1, j = 0; j < ap1->nd; j++) {\n\t dimensions[j] = ap1->dimensions[j];\n\t l *= dimensions[j];\n\t}\n\tnd = ap1->nd;\n }\n else { /* (ap1->nd <= 2 && ap2->nd <= 2) */\n\t/* Both ap1 and ap2 are vectors or matrices */\n\tl = ap1->dimensions[ap1->nd-1];\n\t\n\tif (ap2->dimensions[ap2->nd-1] != l) {\n\t PyErr_SetString(PyExc_ValueError, \"matrices are not aligned\");\n\t goto fail;\n\t}\n\tnd = ap1->nd+ap2->nd-2;\n \n\tif (nd == 1) \n\t dimensions[0] = (ap1->nd == 2) ? ap1->dimensions[0] : ap2->dimensions[0];\n\telse if (nd == 2) {\n\t dimensions[0] = ap1->dimensions[0];\n\t dimensions[1] = ap2->dimensions[0];\n\t}\n }\n\n /* Choose which subtype to return */\n prior2 = PyArray_GetPriority((PyObject *)ap2, 0.0);\n prior1 = PyArray_GetPriority((PyObject *)ap1, 0.0);\n subtype = (prior2 > prior1 ? ap2->ob_type : ap1->ob_type);\n \n ret = (PyArrayObject *)PyArray_New(subtype, nd, dimensions, \n\t\t\t\t typenum, NULL, NULL, 0, 0, \n\t\t\t\t (PyObject *)\\\n\t\t\t\t (prior2 > prior1 ? ap2 : ap1));\n \n if (ret == NULL) goto fail;\n memset(ret->data, 0, PyArray_NBYTES(ret));\n\n if (ap2->nd == 0) {\n\t/* Multiplication by a scalar -- Level 1 BLAS */\n\tif (typenum == PyArray_DOUBLE) {\n\t cblas_daxpy(l, *((double *)ap2->data), (double *)ap1->data, 1,\n\t\t\t(double *)ret->data, 1);\n\t} \n\telse if (typenum == PyArray_CDOUBLE) {\n\t cblas_zaxpy(l, (double *)ap2->data, (double *)ap1->data, 1,\n\t\t\t(double *)ret->data, 1);\n\t}\n\telse if (typenum == PyArray_FLOAT) {\n\t cblas_saxpy(l, *((float *)ap2->data), (float *)ap1->data, 1,\n\t\t\t(float *)ret->data, 1);\n\t}\n\telse if (typenum == PyArray_CFLOAT) {\n\t cblas_caxpy(l, (float *)ap2->data, (float *)ap1->data, 1,\n\t\t\t(float *)ret->data, 1);\n\t}\n }\n else if (ap1->nd == 1 && ap2->nd == 1) {\n\t/* Dot product between two vectors -- Level 1 BLAS */\n\tif (typenum == PyArray_DOUBLE) {\n\t double result = cblas_ddot(l, (double *)ap1->data, 1, \n\t\t\t\t (double *)ap2->data, 1);\n\t *((double *)ret->data) = result;\n\t}\n\telse if (typenum == PyArray_CDOUBLE) {\n\t cblas_zdotu_sub(l, (double *)ap1->data, 1, \n\t\t\t (double *)ap2->data, 1, (double *)ret->data);\n\t}\n\telse if (typenum == PyArray_FLOAT) {\n\t float result = cblas_sdot(l, (float *)ap1->data, 1, \n\t\t\t\t (float *)ap2->data, 1);\n\t *((float *)ret->data) = result;\n\t}\n\telse if (typenum == PyArray_CFLOAT) {\n\t cblas_cdotu_sub(l, (float *)ap1->data, 1, \n\t\t\t (float *)ap2->data, 1, (float *)ret->data);\n\t}\n }\n else if (ap1->nd == 2 && ap2->nd == 1) {\n\t/* Matrix-vector multiplication -- Level 2 BLAS */\n\tlda = (ap1->dimensions[1] > 1 ? ap1->dimensions[1] : 1);\n\tif (typenum == PyArray_DOUBLE) {\n\t cblas_dgemv(CblasRowMajor, \n\t\t\tCblasNoTrans, ap1->dimensions[0], ap1->dimensions[1], \n\t\t\t1.0, (double *)ap1->data, lda,\n\t\t\t(double *)ap2->data, 1, 0.0, (double *)ret->data, 1);\n\t}\n\telse if (typenum == PyArray_CDOUBLE) {\n\t cblas_zgemv(CblasRowMajor, \n\t\t\tCblasNoTrans, ap1->dimensions[0], ap1->dimensions[1], \n\t\t\toneD, (double *)ap1->data, lda,\n\t\t\t(double *)ap2->data, 1, zeroD, (double *)ret->data, 1);\n\t}\n\telse if (typenum == PyArray_FLOAT) {\n\t cblas_sgemv(CblasRowMajor, \n\t\t\tCblasNoTrans, ap1->dimensions[0], ap1->dimensions[1], \n\t\t\t1.0, (float *)ap1->data, lda,\n\t\t\t(float *)ap2->data, 1, 0.0, (float *)ret->data, 1);\n\t}\n\telse if (typenum == PyArray_CFLOAT) {\n\t cblas_cgemv(CblasRowMajor, \n\t\t\tCblasNoTrans, ap1->dimensions[0], ap1->dimensions[1], \n\t\t\toneF, (float *)ap1->data, lda,\n\t\t\t(float *)ap2->data, 1, zeroF, (float *)ret->data, 1);\n\t}\n }\n else if (ap1->nd == 1 && ap2->nd == 2) {\n\t/* Vector matrix multiplication -- Level 2 BLAS */\n\tlda = (ap2->dimensions[1] > 1 ? ap2->dimensions[1] : 1);\n\tif (typenum == PyArray_DOUBLE) {\n\t cblas_dgemv(CblasRowMajor, \n\t\t\tCblasNoTrans, ap2->dimensions[0], ap2->dimensions[1], \n\t\t\t1.0, (double *)ap2->data, lda,\n\t\t\t(double *)ap1->data, 1, 0.0, (double *)ret->data, 1);\n\t}\n\telse if (typenum == PyArray_CDOUBLE) {\n\t cblas_zgemv(CblasRowMajor, \n\t\t\tCblasNoTrans, ap2->dimensions[0], ap2->dimensions[1], \n\t\t\toneD, (double *)ap2->data, lda,\n\t\t\t(double *)ap1->data, 1, zeroD, (double *)ret->data, 1);\n\t}\n\telse if (typenum == PyArray_FLOAT) {\n\t cblas_sgemv(CblasRowMajor, \n\t\t\tCblasNoTrans, ap2->dimensions[0], ap2->dimensions[1], \n\t\t\t1.0, (float *)ap2->data, lda,\n\t\t\t(float *)ap1->data, 1, 0.0, (float *)ret->data, 1);\n\t}\n\telse if (typenum == PyArray_CFLOAT) {\n\t cblas_cgemv(CblasRowMajor, \n\t\t\tCblasNoTrans, ap2->dimensions[0], ap2->dimensions[1], \n\t\t\toneF, (float *)ap2->data, lda,\n\t\t\t(float *)ap1->data, 1, zeroF, (float *)ret->data, 1);\n\t}\n }\n else { /* (ap1->nd == 2 && ap2->nd == 2) */ \n\t/* Matrix matrix multiplication -- Level 3 BLAS */ \n\tlda = (ap1->dimensions[1] > 1 ? ap1->dimensions[1] : 1);\n\tldb = (ap2->dimensions[1] > 1 ? ap2->dimensions[1] : 1);\n\tldc = (ret->dimensions[1] > 1 ? ret->dimensions[1] : 1);\n\tif (typenum == PyArray_DOUBLE) {\n\t cblas_dgemm(CblasRowMajor, CblasNoTrans, CblasTrans,\n\t\t\tap1->dimensions[0], ap2->dimensions[0], ap1->dimensions[1],\n\t\t\t1.0, (double *)ap1->data, lda,\n\t\t\t(double *)ap2->data, ldb,\n\t\t\t0.0, (double *)ret->data, ldc);\n\t}\n\telse if (typenum == PyArray_FLOAT) {\n\t cblas_sgemm(CblasRowMajor, CblasNoTrans, CblasTrans,\n\t\t\tap1->dimensions[0], ap2->dimensions[0], ap1->dimensions[1],\n\t\t\t1.0, (float *)ap1->data, lda,\n\t\t\t(float *)ap2->data, ldb,\n\t\t\t0.0, (float *)ret->data, ldc);\n\t}\n\telse if (typenum == PyArray_CDOUBLE) {\n\t cblas_zgemm(CblasRowMajor, CblasNoTrans, CblasTrans,\n\t\t\tap1->dimensions[0], ap2->dimensions[0], ap1->dimensions[1],\n\t\t\toneD, (double *)ap1->data, lda,\n\t\t\t(double *)ap2->data, ldb,\n\t\t\tzeroD, (double *)ret->data, ldc);\n\t}\n\telse if (typenum == PyArray_CFLOAT) {\n\t cblas_cgemm(CblasRowMajor, CblasNoTrans, CblasTrans,\n\t\t\tap1->dimensions[0], ap2->dimensions[0], ap1->dimensions[1],\n\t\t\toneF, (float *)ap1->data, lda,\n\t\t\t(float *)ap2->data, ldb,\n\t\t\tzeroF, (float *)ret->data, ldc);\n\t}\n }\n Py_DECREF(ap1);\n Py_DECREF(ap2);\n return PyArray_Return(ret);\n\t\n fail:\n Py_XDECREF(ap1);\n Py_XDECREF(ap2);\n Py_XDECREF(ret);\n return NULL;\n}\n\n\nstatic char doc_vdot[] = \"vdot(a,b)\\nReturns the dot product of a and b for scalars and vectors\\nof floating point and complex types. The first argument, a, is conjugated.\";\n\n\nstatic PyObject *dotblas_vdot(PyObject *dummy, PyObject *args) {\n PyObject *op1, *op2;\n PyArrayObject *ap1=NULL, *ap2=NULL, *ret=NULL;\n int l;\n int typenum;\n intp dimensions[MAX_DIMS];\n PyArray_Descr *type;\n\n if (!PyArg_ParseTuple(args, \"OO\", &op1, &op2)) return NULL;\n\t\n /* \n * Conjugating dot product using the BLAS for vectors.\n * Multiplies op1 and op2, each of which must be vector.\n */\n\n typenum = PyArray_ObjectType(op1, 0); \n typenum = PyArray_ObjectType(op2, typenum);\n \n type = PyArray_DescrFromType(typenum);\n \n ap1 = (PyArrayObject *)PyArray_FromAny(op1, type, 0, 0, 0, NULL);\n if (ap1==NULL) goto fail;\n op1 = PyArray_Flatten(ap1, 0);\n if (op1==NULL) goto fail;\n Py_DECREF(ap1);\n ap1 = (PyArrayObject *)op1;\n \n ap2 = (PyArrayObject *)PyArray_FromAny(op2, type, 0, 0, 0, NULL);\n if (ap2==NULL) goto fail;\n op2 = PyArray_Flatten(ap2, 0);\n if (op2 == NULL) goto fail;\n Py_DECREF(ap2);\n ap2 = (PyArrayObject *)op2;\n \n if (typenum != PyArray_FLOAT && typenum != PyArray_DOUBLE &&\n\ttypenum != PyArray_CFLOAT && typenum != PyArray_CDOUBLE) {\n\tif (!altered) {\n\t /* need to alter dot product */\n\t PyObject *tmp1, *tmp2;\n\t tmp1 = PyTuple_New(0);\n\t tmp2 = dotblas_alterdot(NULL, tmp1);\n\t Py_DECREF(tmp1); \n\t Py_DECREF(tmp2);\n\t}\n\tif (PyTypeNum_ISCOMPLEX(typenum)) {\n\t op1 = PyArray_Conjugate(ap1);\n\t if (op1==NULL) goto fail;\n\t Py_DECREF(ap1);\n\t ap1 = (PyArrayObject *)op1;\n\t}\t\n\tret = (PyArrayObject *)PyArray_InnerProduct((PyObject *)ap1, \n\t\t\t\t\t\t (PyObject *)ap2);\n\tPy_DECREF(ap1); \n\tPy_DECREF(ap2);\n\treturn PyArray_Return(ret);\n }\n\n if (ap2->dimensions[0] != ap1->dimensions[ap1->nd-1]) {\n\tPyErr_SetString(PyExc_ValueError, \"vectors have different lengths\");\n\tgoto fail;\n }\n l = ap1->dimensions[ap1->nd-1];\n \n ret = (PyArrayObject *)PyArray_SimpleNew(0, dimensions, typenum);\n if (ret == NULL) goto fail;\n\n\n /* Dot product between two vectors -- Level 1 BLAS */\n if (typenum == PyArray_DOUBLE) {\n\t*((double *)ret->data) = cblas_ddot(l, (double *)ap1->data, 1, \n\t\t\t\t\t (double *)ap2->data, 1);\n }\n else if (typenum == PyArray_FLOAT) {\n\t*((float *)ret->data) = cblas_sdot(l, (float *)ap1->data, 1, \n\t\t\t\t\t (float *)ap2->data, 1);\n }\n else if (typenum == PyArray_CDOUBLE) {\n\tcblas_zdotc_sub(l, (double *)ap1->data, 1, \n\t\t\t(double *)ap2->data, 1, (double *)ret->data);\n }\n else if (typenum == PyArray_CFLOAT) {\n\tcblas_cdotc_sub(l, (float *)ap1->data, 1, \n\t\t\t(float *)ap2->data, 1, (float *)ret->data);\n }\n\n Py_DECREF(ap1);\n Py_DECREF(ap2);\n return PyArray_Return(ret);\n\t\n fail:\n Py_XDECREF(ap1);\n Py_XDECREF(ap2);\n Py_XDECREF(ret);\n return NULL;\n}\n\nstatic struct PyMethodDef dotblas_module_methods[] = {\n {\"dot\", (PyCFunction)dotblas_matrixproduct, 1, doc_matrixproduct},\n {\"inner\", (PyCFunction)dotblas_innerproduct, 1, doc_innerproduct},\n {\"vdot\", (PyCFunction)dotblas_vdot, 1, doc_vdot},\n {\"alterdot\", (PyCFunction)dotblas_alterdot, 1, doc_alterdot},\n {\"restoredot\", (PyCFunction)dotblas_restoredot, 1, doc_restoredot},\n {NULL,\t\tNULL, 0}\t\t/* sentinel */\n};\n\n/* Initialization function for the module */\nDL_EXPORT(void) init_dotblas(void) {\n int i;\n PyObject *m, *d, *s;\n \n /* Create the module and add the functions */\n m = Py_InitModule3(\"_dotblas\", dotblas_module_methods, module_doc);\n\n /* Import the array object */\n import_array();\n\n /* Initialise the array of dot functions */\n for (i = 0; i < PyArray_NTYPES; i++)\n\toldFunctions[i] = NULL;\n\n /* alterdot at load */\n d = PyTuple_New(0);\n s = dotblas_alterdot(NULL, d);\n Py_DECREF(d);\n Py_DECREF(s);\n \n}\n", + "source_code_before": "static char module_doc[] =\n\"This module provides a BLAS optimized\\nmatrix multiply, inner product and dot for numpy arrays\";\n\n#include \"Python.h\"\n#include \"numpy/arrayobject.h\"\n#ifndef CBLAS_HEADER\n#define CBLAS_HEADER \"cblas.h\"\n#endif\n#include CBLAS_HEADER\n\n#include \n\nstatic void \nFLOAT_dot(void *a, intp stridea, void *b, intp strideb, void *res, \n\t intp n, void *tmp)\n{\n register int na = stridea / sizeof(float);\n register int nb = strideb / sizeof(float);\n\n *((float *)res) = cblas_sdot((int)n, (float *)a, na, (float *)b, nb);\n}\n\nstatic void \nDOUBLE_dot(void *a, intp stridea, void *b, intp strideb, void *res, \n\t intp n, void *tmp)\n{\n register int na = stridea / sizeof(double);\n register int nb = strideb / sizeof(double);\n\n *((double *)res) = cblas_ddot((int)n, (double *)a, na, (double *)b, nb);\n}\n\nstatic void \nCFLOAT_dot(void *a, intp stridea, void *b, intp strideb, void *res, \n\t intp n, void *tmp)\n{\n \n register int na = stridea / sizeof(cfloat);\n register int nb = strideb / sizeof(cfloat);\n\n cblas_cdotu_sub((int)n, (float *)a, na, (float *)b, nb, (float *)res);\n}\n\nstatic void \nCDOUBLE_dot(void *a, intp stridea, void *b, intp strideb, void *res, \n\t intp n, void *tmp)\n{\n register int na = stridea / sizeof(cdouble);\n register int nb = strideb / sizeof(cdouble);\n\n cblas_zdotu_sub((int)n, (double *)a, na, (double *)b, nb, (double *)res);\n}\n\n\nstatic PyArray_DotFunc *oldFunctions[PyArray_NTYPES];\nstatic Bool altered=FALSE;\n\nstatic char doc_alterdot[] = \"alterdot() changes all dot functions to use blas.\";\n\nstatic PyObject *\ndotblas_alterdot(PyObject *dummy, PyObject *args) \n{\n PyArray_Descr *descr;\n \n if (!PyArg_ParseTuple(args, \"\")) return NULL;\n\n /* Replace the dot functions to the ones using blas */\n\n if (!altered) {\n\tdescr = PyArray_DescrFromType(PyArray_FLOAT);\n\toldFunctions[PyArray_FLOAT] = descr->f->dotfunc;\n\tdescr->f->dotfunc = (PyArray_DotFunc *)FLOAT_dot;\n\t\n\tdescr = PyArray_DescrFromType(PyArray_DOUBLE);\n\toldFunctions[PyArray_DOUBLE] = descr->f->dotfunc;\n\tdescr->f->dotfunc = (PyArray_DotFunc *)DOUBLE_dot;\n\t\n\tdescr = PyArray_DescrFromType(PyArray_CFLOAT);\n\toldFunctions[PyArray_CFLOAT] = descr->f->dotfunc;\n\tdescr->f->dotfunc = (PyArray_DotFunc *)CFLOAT_dot;\n\t\n\tdescr = PyArray_DescrFromType(PyArray_CDOUBLE);\n\toldFunctions[PyArray_CDOUBLE] = descr->f->dotfunc;\n\tdescr->f->dotfunc = (PyArray_DotFunc *)CDOUBLE_dot;\n\n\taltered = TRUE;\n }\n\n Py_INCREF(Py_None);\n return Py_None;\n}\n\nstatic char doc_restoredot[] = \"restoredot() restores dots to defaults.\";\n\nstatic PyObject *\ndotblas_restoredot(PyObject *dummy, PyObject *args) \n{\n PyArray_Descr *descr;\n\n if (!PyArg_ParseTuple(args, \"\")) return NULL;\n\n if (altered) {\n\tdescr = PyArray_DescrFromType(PyArray_FLOAT);\n\tdescr->f->dotfunc = oldFunctions[PyArray_FLOAT];\n\toldFunctions[PyArray_FLOAT] = NULL;\n\tPy_XDECREF(descr);\n\n\tdescr = PyArray_DescrFromType(PyArray_DOUBLE);\n\tdescr->f->dotfunc = oldFunctions[PyArray_DOUBLE];\n\toldFunctions[PyArray_DOUBLE] = NULL;\n\tPy_XDECREF(descr);\n\n\tdescr = PyArray_DescrFromType(PyArray_CFLOAT);\n\tdescr->f->dotfunc = oldFunctions[PyArray_CFLOAT];\n\toldFunctions[PyArray_CFLOAT] = NULL;\n\tPy_XDECREF(descr);\n\n\tdescr = PyArray_DescrFromType(PyArray_CDOUBLE);\n\tdescr->f->dotfunc = oldFunctions[PyArray_CDOUBLE];\n\toldFunctions[PyArray_CDOUBLE] = NULL;\n\tPy_XDECREF(descr);\n\t\n\taltered = FALSE;\n }\n\n Py_INCREF(Py_None);\n return Py_None;\n}\n\ntypedef enum {_scalar, _column, _row, _matrix} MatrixShape;\n\nstatic MatrixShape \n_select_matrix_shape(PyArrayObject *array)\n{\n switch (array->nd) {\n case 0:\n\treturn _scalar;\n case 1:\n\tif (array->dimensions[0] > 0)\n\t return _column;\n\treturn _scalar;\n case 2:\n\tif (array->dimensions[0] > 1) {\n\t if (array->dimensions[1] == 1)\n\t\treturn _column;\n\t else\n\t\treturn _matrix;\n\t}\n\tif (array->dimensions[1] == 1)\n\t return _scalar;\n\treturn _row;\n }\n return _matrix;\n}\n\n\nstatic char doc_matrixproduct[] = \"matrixproduct(a,b)\\nReturns the dot product of a and b for arrays of floating point types.\\nLike the generic numpy equivalent the product sum is over\\nthe last dimension of a and the second-to-last dimension of b.\\nNB: The first argument is not conjugated.\";\n\nstatic PyObject *\ndotblas_matrixproduct(PyObject *dummy, PyObject *args) \n{\n PyObject *op1, *op2;\n PyArrayObject *ap1, *ap2, *ret;\n int j, l, lda, ldb, ldc;\n int typenum, nd;\n intp dimensions[MAX_DIMS];\n static const float oneF[2] = {1.0, 0.0};\n static const float zeroF[2] = {0.0, 0.0};\n static const double oneD[2] = {1.0, 0.0};\n static const double zeroD[2] = {0.0, 0.0};\n double prior1, prior2;\n PyTypeObject *subtype;\n PyArray_Descr *dtype;\n MatrixShape ap1shape, ap2shape;\n \n if (!PyArg_ParseTuple(args, \"OO\", &op1, &op2)) return NULL;\n\t\n /* \n * \"Matrix product\" using the BLAS. \n * Only works for float double and complex types.\n */\n\n\n typenum = PyArray_ObjectType(op1, 0); \n typenum = PyArray_ObjectType(op2, typenum);\n \n /* This function doesn't handle other types */\n if ((typenum != PyArray_DOUBLE && typenum != PyArray_CDOUBLE &&\n\t typenum != PyArray_FLOAT && typenum != PyArray_CFLOAT)) {\n\treturn PyArray_Return((PyArrayObject *)PyArray_MatrixProduct(op1, op2));\n }\n \n ret = NULL;\n dtype = PyArray_DescrFromType(typenum);\n ap1 = (PyArrayObject *)PyArray_FromAny(op1, dtype, 0, 0, ALIGNED, NULL);\n if (ap1 == NULL) return NULL;\n ap2 = (PyArrayObject *)PyArray_FromAny(op2, dtype, 0, 0, ALIGNED, NULL);\n if (ap2 == NULL) goto fail;\n \n if ((ap1->nd > 2) || (ap2->nd > 2)) { \n\t/* This function doesn't handle dimensions greater than 2 -- other\n\t than to ensure the dot function is altered\n\t*/\n\tif (!altered) {\n\t /* need to alter dot product */\n\t PyObject *tmp1, *tmp2;\n\t tmp1 = PyTuple_New(0);\n\t tmp2 = dotblas_alterdot(NULL, tmp1);\n\t Py_DECREF(tmp1); \n\t Py_DECREF(tmp2);\n\t}\n\tret = (PyArrayObject *)PyArray_MatrixProduct((PyObject *)ap1, \n\t\t\t\t\t\t (PyObject *)ap2);\n\tPy_DECREF(ap1); \n\tPy_DECREF(ap2);\n\treturn PyArray_Return(ret);\n }\n \n ap1shape = _select_matrix_shape(ap1);\n ap2shape = _select_matrix_shape(ap2);\n \n if (ap1shape == _scalar || ap2shape == _scalar) {\n\t/* One of ap1 or ap2 is a scalar */\n\tif (ap1shape == _scalar) { \t\t/* Make ap2 the scalar */\n\t PyArrayObject *t = ap1;\n\t ap1 = ap2;\n\t ap2 = t;\n\t ap1shape = ap2shape;\n\t ap2shape = _scalar;\n\t}\n\tfor (l = 1, j = 0; j < ap1->nd; j++) {\n\t dimensions[j] = ap1->dimensions[j];\n\t l *= dimensions[j];\n\t}\n\tnd = ap1->nd;\n }\n else { /* (ap1->nd <= 2 && ap2->nd <= 2) */\n\t/* Both ap1 and ap2 are vectors or matrices */\n\tl = ap1->dimensions[ap1->nd-1];\n\t\n\tif (ap2->dimensions[0] != l) {\n\t PyErr_SetString(PyExc_ValueError, \"matrices are not aligned\");\n\t goto fail;\n\t}\n\tnd = ap1->nd+ap2->nd-2;\n\t\n\tif (nd == 1) \n\t dimensions[0] = (ap1->nd == 2) ? ap1->dimensions[0] : ap2->dimensions[1];\n\telse if (nd == 2) {\n\t dimensions[0] = ap1->dimensions[0];\n\t dimensions[1] = ap2->dimensions[1];\n\t}\n }\n \n /* Choose which subtype to return */\n if (ap1->ob_type != ap2->ob_type) {\n\tprior2 = PyArray_GetPriority((PyObject *)ap2, 0.0);\n\tprior1 = PyArray_GetPriority((PyObject *)ap1, 0.0);\n\tsubtype = (prior2 > prior1 ? ap2->ob_type : ap1->ob_type);\n }\n else {\n\tprior1 = prior2 = 0.0;\n\tsubtype = ap1->ob_type;\n }\n \n if (l==0) nd = 0;\n ret = (PyArrayObject *)PyArray_New(subtype, nd, dimensions,\n\t\t\t\t typenum, NULL, NULL, 0, 0,\n\t\t\t\t (PyObject *)\n\t\t\t\t (prior2 > prior1 ? ap2 : ap1));\n \n if (ret == NULL) goto fail;\n memset(ret->data, 0, PyArray_NBYTES(ret));\n if (l==0) {\n\t Py_DECREF(ap1);\n\t Py_DECREF(ap2);\n\t return PyArray_Return(ret);\n }\n \n if (ap2shape == _scalar) {\n\t/* Multiplication by a scalar -- Level 1 BLAS */\n\t/* if ap1shape is a matrix and we are not contiguous, then we can't\n\t just blast through the entire array using a single\n\t striding factor */\n\tif (typenum == PyArray_DOUBLE) {\n\t if (l == 1) {\n\t\t*((double *)ret->data) = *((double *)ap2->data) * \\\n\t\t *((double *)ap1->data);\n\t }\n\t else if (ap1->nd < 2) {\n\t\tcblas_daxpy(l, *((double *)ap2->data), (double *)ap1->data,\n\t\t\t ap1->strides[0] / sizeof(double), \n\t\t\t (double *)ret->data, 1);\n\t }\n\t else {\n\t\tint maxind, oind, i, a1s, rets;\n\t\tchar *ptr, *rptr;\n\t\tdouble val;\n\t\tmaxind = (ap1->dimensions[0] >= ap1->dimensions[1] ? 0 : 1);\n\t\toind = 1-maxind;\n\t\tptr = ap1->data;\n\t\trptr = ret->data;\n\t\tl = ap1->dimensions[maxind];\n\t\tval = *((double *)ap2->data);\n\t\ta1s = ap1->strides[maxind] / sizeof(double);\n\t\trets = ret->strides[maxind] / sizeof(double);\n\t\tfor (i=0; i < ap1->dimensions[oind]; i++) {\n\t\t cblas_daxpy(l, val, (double *)ptr, a1s, \n\t\t\t\t(double *)rptr, rets);\n\t\t ptr += ap1->strides[oind];\n\t\t rptr += ret->strides[oind];\n\t\t}\n\t }\n\t} \n\telse if (typenum == PyArray_CDOUBLE) {\n\t if (l == 1) {\n\t\tcdouble *ptr1, *ptr2, *res;\n\t\tptr1 = (cdouble *)ap2->data;\n\t\tptr2 = (cdouble *)ap1->data;\n\t\tres = (cdouble *)ret->data;\t\t\n\t\tres->real = ptr1->real * ptr2->real - ptr1->imag * ptr2->imag;\n\t\tres->imag = ptr1->real * ptr2->imag + ptr1->imag * ptr2->real;\n\t }\n\t else if (ap1->nd < 2) {\n\t\tcblas_zaxpy(l, (double *)ap2->data, (double *)ap1->data,\n\t\t\t ap1->strides[0] / sizeof(cdouble), \n\t\t\t (double *)ret->data, 1);\n\t }\n\t else {\n\t\tint maxind, oind, i, a1s, rets;\n\t\tchar *ptr, *rptr;\n\t\tdouble *pval;\n\t\tmaxind = (ap1->dimensions[0] >= ap1->dimensions[1] ? 0 : 1);\n\t\toind = 1-maxind;\n\t\tptr = ap1->data;\n\t\trptr = ret->data;\n\t\tl = ap1->dimensions[maxind];\n\t\tpval = (double *)ap2->data;\n\t\ta1s = ap1->strides[maxind] / sizeof(cdouble);\n\t\trets = ret->strides[maxind] / sizeof(cdouble);\n\t\tfor (i=0; i < ap1->dimensions[oind]; i++) {\n\t\t cblas_zaxpy(l, pval, (double *)ptr, a1s, \n\t\t\t\t(double *)rptr, rets);\n\t\t ptr += ap1->strides[oind];\n\t\t rptr += ret->strides[oind];\n\t\t}\n\t }\n\t}\n\telse if (typenum == PyArray_FLOAT) {\n\t if (l == 1) {\n\t\t*((float *)ret->data) = *((float *)ap2->data) * \\\n\t\t *((float *)ap1->data);\n\t }\n\t else if (ap1->nd < 2) {\n\t\tcblas_saxpy(l, *((float *)ap2->data), (float *)ap1->data,\n\t\t\t ap1->strides[0] / sizeof(float), \n\t\t\t (float *)ret->data, 1);\n\t }\n\t else {\n\t\tint maxind, oind, i, a1s, rets;\n\t\tchar *ptr, *rptr;\n\t\tfloat val;\n\t\tmaxind = (ap1->dimensions[0] >= ap1->dimensions[1] ? 0 : 1);\n\t\toind = 1-maxind;\n\t\tptr = ap1->data;\n\t\trptr = ret->data;\n\t\tl = ap1->dimensions[maxind];\n\t\tval = *((float *)ap2->data);\n\t\ta1s = ap1->strides[maxind] / sizeof(float);\n\t\trets = ret->strides[maxind] / sizeof(float);\n\t\tfor (i=0; i < ap1->dimensions[oind]; i++) {\n\t\t cblas_saxpy(l, val, (float *)ptr, a1s, \n\t\t\t\t(float *)rptr, rets);\n\t\t ptr += ap1->strides[oind];\n\t\t rptr += ret->strides[oind];\n\t\t}\n\t }\n\t}\n\telse if (typenum == PyArray_CFLOAT) {\n\t if (l == 1) {\n\t\tcfloat *ptr1, *ptr2, *res;\n\t\tptr1 = (cfloat *)ap2->data;\n\t\tptr2 = (cfloat *)ap1->data;\n\t\tres = (cfloat *)ret->data;\t\t\n\t\tres->real = ptr1->real * ptr2->real - ptr1->imag * ptr2->imag;\n\t\tres->imag = ptr1->real * ptr2->imag + ptr1->imag * ptr2->real;\n\t }\n\t else if (ap1->nd < 2) {\n\t\tcblas_caxpy(l, (float *)ap2->data, (float *)ap1->data,\n\t\t\t ap1->strides[0] / sizeof(cfloat), \n\t\t\t (float *)ret->data, 1);\n\t }\n\t else {\n\t\tint maxind, oind, i, a1s, rets;\n\t\tchar *ptr, *rptr;\n\t\tfloat *pval;\n\t\tmaxind = (ap1->dimensions[0] >= ap1->dimensions[1] ? 0 : 1);\n\t\toind = 1-maxind;\n\t\tptr = ap1->data;\n\t\trptr = ret->data;\n\t\tl = ap1->dimensions[maxind];\n\t\tpval = (float *)ap2->data;\n\t\ta1s = ap1->strides[maxind] / sizeof(cfloat);\n\t\trets = ret->strides[maxind] / sizeof(cfloat);\n\t\tfor (i=0; i < ap1->dimensions[oind]; i++) {\n\t\t cblas_caxpy(l, pval, (float *)ptr, a1s, \n\t\t\t\t(float *)rptr, rets);\n\t\t ptr += ap1->strides[oind];\n\t\t rptr += ret->strides[oind];\n\t\t}\n\t }\n\t}\n }\n else if ((ap2shape == _column) && (ap1shape != _matrix)) {\n\tint ap1s, ap2s;\n\tap2s = ap2->strides[0] / ap2->descr->elsize;\n\tif (ap1shape == _row) {\n\t ap1s = ap1->strides[1] / ap1->descr->elsize;\n\t}\n\telse {\n\t ap1s = ap1->strides[0] / ap1->descr->elsize;\n\t}\n\t \n\t/* Dot product between two vectors -- Level 1 BLAS */\n\tif (typenum == PyArray_DOUBLE) {\n\t double result = cblas_ddot(l, (double *)ap1->data, ap1s, \n\t\t\t\t (double *)ap2->data, ap2s);\n\t *((double *)ret->data) = result;\n\t}\n\telse if (typenum == PyArray_FLOAT) {\n\t float result = cblas_sdot(l, (float *)ap1->data, ap1s, \n\t\t\t\t (float *)ap2->data, ap2s);\n\t *((float *)ret->data) = result;\n\t}\n\telse if (typenum == PyArray_CDOUBLE) {\n\t cblas_zdotu_sub(l, (double *)ap1->data, ap1s, \n\t\t\t (double *)ap2->data, ap2s, (double *)ret->data);\n\t}\n\telse if (typenum == PyArray_CFLOAT) {\n\t cblas_cdotu_sub(l, (float *)ap1->data, ap1s, \n\t\t\t (float *)ap2->data, ap2s, (float *)ret->data);\n\t}\n }\n else if (ap1shape == _matrix && ap2shape != _matrix) {\n\t/* Matrix vector multiplication -- Level 2 BLAS */\n\t/* lda must be MAX(M,1) */\n\tenum CBLAS_ORDER Order;\n\tint ap2s;\n\n\tif (!PyArray_ISONESEGMENT(ap1)) {\n\t PyObject *new;\n\t new = PyArray_Copy(ap1);\n\t Py_DECREF(ap1);\n\t ap1 = (PyArrayObject *)new;\n\t if (new == NULL) goto fail;\n\t}\n\tif (PyArray_ISCONTIGUOUS(ap1)) {\n Order = CblasRowMajor;\n lda = (ap1->dimensions[1] > 1 ? ap1->dimensions[1] : 1);\n\t}\n\telse {\n\t Order = CblasColMajor;\n lda = (ap1->dimensions[0] > 1 ? ap1->dimensions[0] : 1);\n\t}\n\tap2s = ap2->strides[0] / ap2->descr->elsize;\n\tif (typenum == PyArray_DOUBLE) {\n\t cblas_dgemv(Order, CblasNoTrans, \n\t\t\tap1->dimensions[0], ap1->dimensions[1], \n\t\t\t1.0, (double *)ap1->data, lda, \n\t\t\t(double *)ap2->data, ap2s, 0.0, (double *)ret->data, 1);\n\t}\n\telse if (typenum == PyArray_FLOAT) {\n\t cblas_sgemv(Order, CblasNoTrans, \n\t\t\tap1->dimensions[0], ap1->dimensions[1], \n\t\t\t1.0, (float *)ap1->data, lda, \n\t\t\t(float *)ap2->data, ap2s, 0.0, (float *)ret->data, 1);\n\t}\n\telse if (typenum == PyArray_CDOUBLE) {\n\t cblas_zgemv(Order, \n\t\t\tCblasNoTrans, ap1->dimensions[0], ap1->dimensions[1], \n\t\t\toneD, (double *)ap1->data, lda, \n\t\t\t(double *)ap2->data, ap2s, zeroD, \n\t\t\t(double *)ret->data, 1);\n\t}\n\telse if (typenum == PyArray_CFLOAT) {\n\t cblas_cgemv(Order, \n\t\t\tCblasNoTrans, ap1->dimensions[0], ap1->dimensions[1], \n\t\t\toneF, (float *)ap1->data, lda, \n\t\t\t(float *)ap2->data, ap2s, zeroF, \n\t\t\t(float *)ret->data, 1);\n\t}\n }\n else if (ap1shape != _matrix && ap2shape == _matrix) {\n\t/* Vector matrix multiplication -- Level 2 BLAS */\n\tenum CBLAS_ORDER Order;\n\tint ap1s;\n\n\tif (!PyArray_ISONESEGMENT(ap2)) {\n\t PyObject *new;\n\t new = PyArray_Copy(ap2);\n\t Py_DECREF(ap2);\n\t ap2 = (PyArrayObject *)new;\n\t if (new == NULL) goto fail;\n\t}\n\tif (PyArray_ISCONTIGUOUS(ap2)) {\n\t Order = CblasRowMajor;\n lda = (ap2->dimensions[1] > 1 ? ap2->dimensions[1] : 1);\n\t}\n\telse {\n\t Order = CblasColMajor;\n lda = (ap2->dimensions[0] > 1 ? ap2->dimensions[0] : 1);\n\t}\n\tif (ap1shape == _row) {\n\t ap1s = ap1->strides[1] / ap1->descr->elsize;\n\t}\n\telse {\n\t ap1s = ap1->strides[0] / ap1->descr->elsize;\n\t}\n\tif (typenum == PyArray_DOUBLE) {\n\t cblas_dgemv(Order, \n\t\t\tCblasTrans, ap2->dimensions[0], ap2->dimensions[1], \n\t\t\t1.0, (double *)ap2->data, lda,\n\t\t\t(double *)ap1->data, ap1s, 0.0, (double *)ret->data, 1);\n\t}\n\telse if (typenum == PyArray_FLOAT) {\n\t cblas_sgemv(Order,\n\t\t\tCblasTrans, ap2->dimensions[0], ap2->dimensions[1], \n\t\t\t1.0, (float *)ap2->data, lda,\n\t\t\t(float *)ap1->data, ap1s, 0.0, (float *)ret->data, 1);\n\t}\n\telse if (typenum == PyArray_CDOUBLE) {\n\t cblas_zgemv(Order,\n\t\t\tCblasTrans, ap2->dimensions[0], ap2->dimensions[1], \n\t\t\toneD, (double *)ap2->data, lda,\n\t\t\t(double *)ap1->data, ap1s, zeroD, (double *)ret->data, 1);\n\t}\n\telse if (typenum == PyArray_CFLOAT) {\n\t cblas_cgemv(Order,\n\t\t\tCblasTrans, ap2->dimensions[0], ap2->dimensions[1], \n\t\t\toneF, (float *)ap2->data, lda,\n\t\t\t(float *)ap1->data, ap1s, zeroF, (float *)ret->data, 1);\n\t}\n }\n else { /* (ap1->nd == 2 && ap2->nd == 2) */\n\t/* Matrix matrix multiplication -- Level 3 BLAS */ \n\t/* L x M multiplied by M x N */\n\tenum CBLAS_ORDER Order;\n\tenum CBLAS_TRANSPOSE Trans1, Trans2;\n\tint M, N, L;\n\n\t/* Optimization possible: */\n\t/* We may be able to handle single-segment arrays here\n\t using appropriate values of Order, Trans1, and Trans2.\n\t*/\n\t\n \tif (!PyArray_ISCONTIGUOUS(ap2)) {\n\t PyObject *new;\n\t new = PyArray_Copy(ap2);\n\t Py_DECREF(ap2);\n\t ap2 = (PyArrayObject *)new;\n\t if (new == NULL) goto fail;\n\t}\n\tif (!PyArray_ISCONTIGUOUS(ap1)) {\n\t PyObject *new;\n\t new = PyArray_Copy(ap1);\n\t Py_DECREF(ap1);\n\t ap1 = (PyArrayObject *)new;\n\t if (new == NULL) goto fail;\n\t}\n\t\n\tOrder = CblasRowMajor;\n\tTrans1 = CblasNoTrans;\n\tTrans2 = CblasNoTrans;\n\tL = ap1->dimensions[0];\n\tN = ap2->dimensions[1];\n\tM = ap2->dimensions[0];\n\tlda = (ap1->dimensions[1] > 1 ? ap1->dimensions[1] : 1);\n\tldb = (ap2->dimensions[1] > 1 ? ap2->dimensions[1] : 1);\n\tldc = (ret->dimensions[1] > 1 ? ret->dimensions[1] : 1);\t \n\tif (typenum == PyArray_DOUBLE) {\n\t cblas_dgemm(Order, Trans1, Trans2, \n\t\t\tL, N, M,\n\t\t\t1.0, (double *)ap1->data, lda,\n\t\t\t(double *)ap2->data, ldb,\n\t\t\t0.0, (double *)ret->data, ldc);\n\t}\n\telse if (typenum == PyArray_FLOAT) {\n\t cblas_sgemm(Order, Trans1, Trans2,\n\t\t\tL, N, M, \n\t\t\t1.0, (float *)ap1->data, lda,\n\t\t\t(float *)ap2->data, ldb,\n\t\t\t0.0, (float *)ret->data, ldc);\n\t}\n\telse if (typenum == PyArray_CDOUBLE) {\n\t cblas_zgemm(Order, Trans1, Trans2,\n\t\t\tL, N, M, \n\t\t\toneD, (double *)ap1->data, lda,\n\t\t\t(double *)ap2->data, ldb,\n\t\t\tzeroD, (double *)ret->data, ldc);\n\t}\n\telse if (typenum == PyArray_CFLOAT) {\n\t cblas_cgemm(Order, Trans1, Trans2,\n\t\t\tL, N, M,\n\t\t\toneF, (float *)ap1->data, lda,\n\t\t\t(float *)ap2->data, ldb,\n\t\t\tzeroF, (float *)ret->data, ldc);\n\t}\n }\n\n Py_DECREF(ap1);\n Py_DECREF(ap2);\n return PyArray_Return(ret);\n\t\n fail:\n Py_XDECREF(ap1);\n Py_XDECREF(ap2);\n Py_XDECREF(ret);\n return NULL;\n}\n\n\nstatic char doc_innerproduct[] = \"innerproduct(a,b)\\nReturns the inner product of a and b for arrays of floating point types.\\nLike the generic Numeric equivalent the product sum is over\\nthe last dimension of a and b.\\nNB: The first argument is not conjugated.\";\n\nstatic PyObject *\ndotblas_innerproduct(PyObject *dummy, PyObject *args) \n{\n PyObject *op1, *op2;\n PyArrayObject *ap1, *ap2, *ret;\n int j, l, lda, ldb, ldc;\n int typenum, nd;\n intp dimensions[MAX_DIMS];\n static const float oneF[2] = {1.0, 0.0};\n static const float zeroF[2] = {0.0, 0.0};\n static const double oneD[2] = {1.0, 0.0};\n static const double zeroD[2] = {0.0, 0.0};\n PyTypeObject *subtype;\n double prior1, prior2;\n\n if (!PyArg_ParseTuple(args, \"OO\", &op1, &op2)) return NULL;\n\t\n /* \n * Inner product using the BLAS. The product sum is taken along the last\n * dimensions of the two arrays.\n * Only speeds things up for float double and complex types.\n */\n\n\n typenum = PyArray_ObjectType(op1, 0); \n typenum = PyArray_ObjectType(op2, typenum);\n\n /* This function doesn't handle other types */\n if ((typenum != PyArray_DOUBLE && typenum != PyArray_CDOUBLE &&\n\t typenum != PyArray_FLOAT && typenum != PyArray_CFLOAT)) {\n return PyArray_Return((PyArrayObject *)PyArray_InnerProduct(op1, op2));\n }\n\n ret = NULL;\n ap1 = (PyArrayObject *)PyArray_ContiguousFromObject(op1, typenum, 0, 0);\n if (ap1 == NULL) return NULL;\n ap2 = (PyArrayObject *)PyArray_ContiguousFromObject(op2, typenum, 0, 0);\n if (ap2 == NULL) goto fail;\n\n if ((ap1->nd > 2) || (ap2->nd > 2)) { \n\t/* This function doesn't handle dimensions greater than 2 -- other\n\t than to ensure the dot function is altered\n\t*/\n\tif (!altered) {\n\t /* need to alter dot product */\n\t PyObject *tmp1, *tmp2;\n\t tmp1 = PyTuple_New(0);\n\t tmp2 = dotblas_alterdot(NULL, tmp1);\n\t Py_DECREF(tmp1); \n\t Py_DECREF(tmp2);\n\t}\n\tret = (PyArrayObject *)PyArray_InnerProduct((PyObject *)ap1, \n\t\t\t\t\t\t (PyObject *)ap2);\n\tPy_DECREF(ap1); \n\tPy_DECREF(ap2);\n\treturn PyArray_Return(ret);\n }\n\n if (ap1->nd == 0 || ap2->nd == 0) {\n\t/* One of ap1 or ap2 is a scalar */\n\tif (ap1->nd == 0) {\t\t/* Make ap2 the scalar */\n\t PyArrayObject *t = ap1;\n\t ap1 = ap2;\n\t ap2 = t;\n\t}\n\tfor (l = 1, j = 0; j < ap1->nd; j++) {\n\t dimensions[j] = ap1->dimensions[j];\n\t l *= dimensions[j];\n\t}\n\tnd = ap1->nd;\n }\n else { /* (ap1->nd <= 2 && ap2->nd <= 2) */\n\t/* Both ap1 and ap2 are vectors or matrices */\n\tl = ap1->dimensions[ap1->nd-1];\n\t\n\tif (ap2->dimensions[ap2->nd-1] != l) {\n\t PyErr_SetString(PyExc_ValueError, \"matrices are not aligned\");\n\t goto fail;\n\t}\n\tnd = ap1->nd+ap2->nd-2;\n \n\tif (nd == 1) \n\t dimensions[0] = (ap1->nd == 2) ? ap1->dimensions[0] : ap2->dimensions[0];\n\telse if (nd == 2) {\n\t dimensions[0] = ap1->dimensions[0];\n\t dimensions[1] = ap2->dimensions[0];\n\t}\n }\n\n /* Choose which subtype to return */\n prior2 = PyArray_GetPriority((PyObject *)ap2, 0.0);\n prior1 = PyArray_GetPriority((PyObject *)ap1, 0.0);\n subtype = (prior2 > prior1 ? ap2->ob_type : ap1->ob_type);\n \n ret = (PyArrayObject *)PyArray_New(subtype, nd, dimensions, \n\t\t\t\t typenum, NULL, NULL, 0, 0, \n\t\t\t\t (PyObject *)\\\n\t\t\t\t (prior2 > prior1 ? ap2 : ap1));\n \n if (ret == NULL) goto fail;\n memset(ret->data, 0, PyArray_NBYTES(ret));\n\n if (ap2->nd == 0) {\n\t/* Multiplication by a scalar -- Level 1 BLAS */\n\tif (typenum == PyArray_DOUBLE) {\n\t cblas_daxpy(l, *((double *)ap2->data), (double *)ap1->data, 1,\n\t\t\t(double *)ret->data, 1);\n\t} \n\telse if (typenum == PyArray_CDOUBLE) {\n\t cblas_zaxpy(l, (double *)ap2->data, (double *)ap1->data, 1,\n\t\t\t(double *)ret->data, 1);\n\t}\n\telse if (typenum == PyArray_FLOAT) {\n\t cblas_saxpy(l, *((float *)ap2->data), (float *)ap1->data, 1,\n\t\t\t(float *)ret->data, 1);\n\t}\n\telse if (typenum == PyArray_CFLOAT) {\n\t cblas_caxpy(l, (float *)ap2->data, (float *)ap1->data, 1,\n\t\t\t(float *)ret->data, 1);\n\t}\n }\n else if (ap1->nd == 1 && ap2->nd == 1) {\n\t/* Dot product between two vectors -- Level 1 BLAS */\n\tif (typenum == PyArray_DOUBLE) {\n\t double result = cblas_ddot(l, (double *)ap1->data, 1, \n\t\t\t\t (double *)ap2->data, 1);\n\t *((double *)ret->data) = result;\n\t}\n\telse if (typenum == PyArray_CDOUBLE) {\n\t cblas_zdotu_sub(l, (double *)ap1->data, 1, \n\t\t\t (double *)ap2->data, 1, (double *)ret->data);\n\t}\n\telse if (typenum == PyArray_FLOAT) {\n\t float result = cblas_sdot(l, (float *)ap1->data, 1, \n\t\t\t\t (float *)ap2->data, 1);\n\t *((float *)ret->data) = result;\n\t}\n\telse if (typenum == PyArray_CFLOAT) {\n\t cblas_cdotu_sub(l, (float *)ap1->data, 1, \n\t\t\t (float *)ap2->data, 1, (float *)ret->data);\n\t}\n }\n else if (ap1->nd == 2 && ap2->nd == 1) {\n\t/* Matrix-vector multiplication -- Level 2 BLAS */\n\tlda = (ap1->dimensions[1] > 1 ? ap1->dimensions[1] : 1);\n\tif (typenum == PyArray_DOUBLE) {\n\t cblas_dgemv(CblasRowMajor, \n\t\t\tCblasNoTrans, ap1->dimensions[0], ap1->dimensions[1], \n\t\t\t1.0, (double *)ap1->data, lda,\n\t\t\t(double *)ap2->data, 1, 0.0, (double *)ret->data, 1);\n\t}\n\telse if (typenum == PyArray_CDOUBLE) {\n\t cblas_zgemv(CblasRowMajor, \n\t\t\tCblasNoTrans, ap1->dimensions[0], ap1->dimensions[1], \n\t\t\toneD, (double *)ap1->data, lda,\n\t\t\t(double *)ap2->data, 1, zeroD, (double *)ret->data, 1);\n\t}\n\telse if (typenum == PyArray_FLOAT) {\n\t cblas_sgemv(CblasRowMajor, \n\t\t\tCblasNoTrans, ap1->dimensions[0], ap1->dimensions[1], \n\t\t\t1.0, (float *)ap1->data, lda,\n\t\t\t(float *)ap2->data, 1, 0.0, (float *)ret->data, 1);\n\t}\n\telse if (typenum == PyArray_CFLOAT) {\n\t cblas_cgemv(CblasRowMajor, \n\t\t\tCblasNoTrans, ap1->dimensions[0], ap1->dimensions[1], \n\t\t\toneF, (float *)ap1->data, lda,\n\t\t\t(float *)ap2->data, 1, zeroF, (float *)ret->data, 1);\n\t}\n }\n else if (ap1->nd == 1 && ap2->nd == 2) {\n\t/* Vector matrix multiplication -- Level 2 BLAS */\n\tlda = (ap2->dimensions[1] > 1 ? ap2->dimensions[1] : 1);\n\tif (typenum == PyArray_DOUBLE) {\n\t cblas_dgemv(CblasRowMajor, \n\t\t\tCblasNoTrans, ap2->dimensions[0], ap2->dimensions[1], \n\t\t\t1.0, (double *)ap2->data, lda,\n\t\t\t(double *)ap1->data, 1, 0.0, (double *)ret->data, 1);\n\t}\n\telse if (typenum == PyArray_CDOUBLE) {\n\t cblas_zgemv(CblasRowMajor, \n\t\t\tCblasNoTrans, ap2->dimensions[0], ap2->dimensions[1], \n\t\t\toneD, (double *)ap2->data, lda,\n\t\t\t(double *)ap1->data, 1, zeroD, (double *)ret->data, 1);\n\t}\n\telse if (typenum == PyArray_FLOAT) {\n\t cblas_sgemv(CblasRowMajor, \n\t\t\tCblasNoTrans, ap2->dimensions[0], ap2->dimensions[1], \n\t\t\t1.0, (float *)ap2->data, lda,\n\t\t\t(float *)ap1->data, 1, 0.0, (float *)ret->data, 1);\n\t}\n\telse if (typenum == PyArray_CFLOAT) {\n\t cblas_cgemv(CblasRowMajor, \n\t\t\tCblasNoTrans, ap2->dimensions[0], ap2->dimensions[1], \n\t\t\toneF, (float *)ap2->data, lda,\n\t\t\t(float *)ap1->data, 1, zeroF, (float *)ret->data, 1);\n\t}\n }\n else { /* (ap1->nd == 2 && ap2->nd == 2) */ \n\t/* Matrix matrix multiplication -- Level 3 BLAS */ \n\tlda = (ap1->dimensions[1] > 1 ? ap1->dimensions[1] : 1);\n\tldb = (ap2->dimensions[1] > 1 ? ap2->dimensions[1] : 1);\n\tldc = (ret->dimensions[1] > 1 ? ret->dimensions[1] : 1);\n\tif (typenum == PyArray_DOUBLE) {\n\t cblas_dgemm(CblasRowMajor, CblasNoTrans, CblasTrans,\n\t\t\tap1->dimensions[0], ap2->dimensions[0], ap1->dimensions[1],\n\t\t\t1.0, (double *)ap1->data, lda,\n\t\t\t(double *)ap2->data, ldb,\n\t\t\t0.0, (double *)ret->data, ldc);\n\t}\n\telse if (typenum == PyArray_FLOAT) {\n\t cblas_sgemm(CblasRowMajor, CblasNoTrans, CblasTrans,\n\t\t\tap1->dimensions[0], ap2->dimensions[0], ap1->dimensions[1],\n\t\t\t1.0, (float *)ap1->data, lda,\n\t\t\t(float *)ap2->data, ldb,\n\t\t\t0.0, (float *)ret->data, ldc);\n\t}\n\telse if (typenum == PyArray_CDOUBLE) {\n\t cblas_zgemm(CblasRowMajor, CblasNoTrans, CblasTrans,\n\t\t\tap1->dimensions[0], ap2->dimensions[0], ap1->dimensions[1],\n\t\t\toneD, (double *)ap1->data, lda,\n\t\t\t(double *)ap2->data, ldb,\n\t\t\tzeroD, (double *)ret->data, ldc);\n\t}\n\telse if (typenum == PyArray_CFLOAT) {\n\t cblas_cgemm(CblasRowMajor, CblasNoTrans, CblasTrans,\n\t\t\tap1->dimensions[0], ap2->dimensions[0], ap1->dimensions[1],\n\t\t\toneF, (float *)ap1->data, lda,\n\t\t\t(float *)ap2->data, ldb,\n\t\t\tzeroF, (float *)ret->data, ldc);\n\t}\n }\n Py_DECREF(ap1);\n Py_DECREF(ap2);\n return PyArray_Return(ret);\n\t\n fail:\n Py_XDECREF(ap1);\n Py_XDECREF(ap2);\n Py_XDECREF(ret);\n return NULL;\n}\n\n\nstatic char doc_vdot[] = \"vdot(a,b)\\nReturns the dot product of a and b for scalars and vectors\\nof floating point and complex types. The first argument, a, is conjugated.\";\n\n\nstatic PyObject *dotblas_vdot(PyObject *dummy, PyObject *args) {\n PyObject *op1, *op2;\n PyArrayObject *ap1=NULL, *ap2=NULL, *ret=NULL;\n int l;\n int typenum;\n intp dimensions[MAX_DIMS];\n PyArray_Descr *type;\n\n if (!PyArg_ParseTuple(args, \"OO\", &op1, &op2)) return NULL;\n\t\n /* \n * Conjugating dot product using the BLAS for vectors.\n * Multiplies op1 and op2, each of which must be vector.\n */\n\n typenum = PyArray_ObjectType(op1, 0); \n typenum = PyArray_ObjectType(op2, typenum);\n \n type = PyArray_DescrFromType(typenum);\n \n ap1 = (PyArrayObject *)PyArray_FromAny(op1, type, 0, 0, 0, NULL);\n if (ap1==NULL) goto fail;\n op1 = PyArray_Flatten(ap1, 0);\n if (op1==NULL) goto fail;\n Py_DECREF(ap1);\n ap1 = (PyArrayObject *)op1;\n \n ap2 = (PyArrayObject *)PyArray_FromAny(op2, type, 0, 0, 0, NULL);\n if (ap2==NULL) goto fail;\n op2 = PyArray_Flatten(ap2, 0);\n if (op2 == NULL) goto fail;\n Py_DECREF(ap2);\n ap2 = (PyArrayObject *)op2;\n \n if (typenum != PyArray_FLOAT && typenum != PyArray_DOUBLE &&\n\ttypenum != PyArray_CFLOAT && typenum != PyArray_CDOUBLE) {\n\tif (!altered) {\n\t /* need to alter dot product */\n\t PyObject *tmp1, *tmp2;\n\t tmp1 = PyTuple_New(0);\n\t tmp2 = dotblas_alterdot(NULL, tmp1);\n\t Py_DECREF(tmp1); \n\t Py_DECREF(tmp2);\n\t}\n\tif (PyTypeNum_ISCOMPLEX(typenum)) {\n\t op1 = PyArray_Conjugate(ap1);\n\t if (op1==NULL) goto fail;\n\t Py_DECREF(ap1);\n\t ap1 = (PyArrayObject *)op1;\n\t}\t\n\tret = (PyArrayObject *)PyArray_InnerProduct((PyObject *)ap1, \n\t\t\t\t\t\t (PyObject *)ap2);\n\tPy_DECREF(ap1); \n\tPy_DECREF(ap2);\n\treturn PyArray_Return(ret);\n }\n\n if (ap2->dimensions[0] != ap1->dimensions[ap1->nd-1]) {\n\tPyErr_SetString(PyExc_ValueError, \"vectors have different lengths\");\n\tgoto fail;\n }\n l = ap1->dimensions[ap1->nd-1];\n \n ret = (PyArrayObject *)PyArray_SimpleNew(0, dimensions, typenum);\n if (ret == NULL) goto fail;\n\n\n /* Dot product between two vectors -- Level 1 BLAS */\n if (typenum == PyArray_DOUBLE) {\n\t*((double *)ret->data) = cblas_ddot(l, (double *)ap1->data, 1, \n\t\t\t\t\t (double *)ap2->data, 1);\n }\n else if (typenum == PyArray_FLOAT) {\n\t*((float *)ret->data) = cblas_sdot(l, (float *)ap1->data, 1, \n\t\t\t\t\t (float *)ap2->data, 1);\n }\n else if (typenum == PyArray_CDOUBLE) {\n\tcblas_zdotc_sub(l, (double *)ap1->data, 1, \n\t\t\t(double *)ap2->data, 1, (double *)ret->data);\n }\n else if (typenum == PyArray_CFLOAT) {\n\tcblas_cdotc_sub(l, (float *)ap1->data, 1, \n\t\t\t(float *)ap2->data, 1, (float *)ret->data);\n }\n\n Py_DECREF(ap1);\n Py_DECREF(ap2);\n return PyArray_Return(ret);\n\t\n fail:\n Py_XDECREF(ap1);\n Py_XDECREF(ap2);\n Py_XDECREF(ret);\n return NULL;\n}\n\nstatic struct PyMethodDef dotblas_module_methods[] = {\n {\"dot\", (PyCFunction)dotblas_matrixproduct, 1, doc_matrixproduct},\n {\"inner\", (PyCFunction)dotblas_innerproduct, 1, doc_innerproduct},\n {\"vdot\", (PyCFunction)dotblas_vdot, 1, doc_vdot},\n {\"alterdot\", (PyCFunction)dotblas_alterdot, 1, doc_alterdot},\n {\"restoredot\", (PyCFunction)dotblas_restoredot, 1, doc_restoredot},\n {NULL,\t\tNULL, 0}\t\t/* sentinel */\n};\n\n/* Initialization function for the module */\nDL_EXPORT(void) init_dotblas(void) {\n int i;\n PyObject *m, *d, *s;\n \n /* Create the module and add the functions */\n m = Py_InitModule3(\"_dotblas\", dotblas_module_methods, module_doc);\n\n /* Import the array object */\n import_array();\n\n /* Initialise the array of dot functions */\n for (i = 0; i < PyArray_NTYPES; i++)\n\toldFunctions[i] = NULL;\n\n /* alterdot at load */\n d = PyTuple_New(0);\n s = dotblas_alterdot(NULL, d);\n Py_DECREF(d);\n Py_DECREF(s);\n \n}\n", + "methods": [ + { + "name": "FLOAT_dot", + "long_name": "FLOAT_dot( * a , intp stridea , * b , intp strideb , * res , intp n , * tmp)", + "filename": "_dotblas.c", + "nloc": 7, + "complexity": 1, + "token_count": 84, + "parameters": [ + "a", + "stridea", + "b", + "strideb", + "res", + "n", + "tmp" + ], + "start_line": 14, + "end_line": 21, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 8, + "top_nesting_level": 0 + }, + { + "name": "DOUBLE_dot", + "long_name": "DOUBLE_dot( * a , intp stridea , * b , intp strideb , * res , intp n , * tmp)", + "filename": "_dotblas.c", + "nloc": 7, + "complexity": 1, + "token_count": 84, + "parameters": [ + "a", + "stridea", + "b", + "strideb", + "res", + "n", + "tmp" + ], + "start_line": 24, + "end_line": 31, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 8, + "top_nesting_level": 0 + }, + { + "name": "CFLOAT_dot", + "long_name": "CFLOAT_dot( * a , intp stridea , * b , intp strideb , * res , intp n , * tmp)", + "filename": "_dotblas.c", + "nloc": 7, + "complexity": 1, + "token_count": 81, + "parameters": [ + "a", + "stridea", + "b", + "strideb", + "res", + "n", + "tmp" + ], + "start_line": 34, + "end_line": 42, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 9, + "top_nesting_level": 0 + }, + { + "name": "CDOUBLE_dot", + "long_name": "CDOUBLE_dot( * a , intp stridea , * b , intp strideb , * res , intp n , * tmp)", + "filename": "_dotblas.c", + "nloc": 7, + "complexity": 1, + "token_count": 81, + "parameters": [ + "a", + "stridea", + "b", + "strideb", + "res", + "n", + "tmp" + ], + "start_line": 45, + "end_line": 52, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 8, + "top_nesting_level": 0 + }, + { + "name": "dotblas_alterdot", + "long_name": "dotblas_alterdot( PyObject * dummy , PyObject * args)", + "filename": "_dotblas.c", + "nloc": 22, + "complexity": 3, + "token_count": 168, + "parameters": [ + "dummy", + "args" + ], + "start_line": 61, + "end_line": 91, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 31, + "top_nesting_level": 0 + }, + { + "name": "dotblas_restoredot", + "long_name": "dotblas_restoredot( PyObject * dummy , PyObject * args)", + "filename": "_dotblas.c", + "nloc": 26, + "complexity": 3, + "token_count": 167, + "parameters": [ + "dummy", + "args" + ], + "start_line": 96, + "end_line": 128, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 33, + "top_nesting_level": 0 + }, + { + "name": "_select_matrix_shape", + "long_name": "_select_matrix_shape( PyArrayObject * array)", + "filename": "_dotblas.c", + "nloc": 22, + "complexity": 8, + "token_count": 96, + "parameters": [ + "array" + ], + "start_line": 133, + "end_line": 154, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 22, + "top_nesting_level": 0 + }, + { + "name": "dotblas_matrixproduct", + "long_name": "dotblas_matrixproduct( PyObject * dummy , PyObject * args)", + "filename": "_dotblas.c", + "nloc": 412, + "complexity": 92, + "token_count": 3557, + "parameters": [ + "dummy", + "args" + ], + "start_line": 160, + "end_line": 620, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 461, + "top_nesting_level": 0 + }, + { + "name": "dotblas_innerproduct", + "long_name": "dotblas_innerproduct( PyObject * dummy , PyObject * args)", + "filename": "_dotblas.c", + "nloc": 208, + "complexity": 54, + "token_count": 2023, + "parameters": [ + "dummy", + "args" + ], + "start_line": 626, + "end_line": 866, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 241, + "top_nesting_level": 0 + }, + { + "name": "dotblas_vdot", + "long_name": "dotblas_vdot( PyObject * dummy , PyObject * args)", + "filename": "_dotblas.c", + "nloc": 76, + "complexity": 19, + "token_count": 630, + "parameters": [ + "dummy", + "args" + ], + "start_line": 872, + "end_line": 966, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 95, + "top_nesting_level": 0 + }, + { + "name": "init_dotblas", + "long_name": "init_dotblas()", + "filename": "_dotblas.c", + "nloc": 12, + "complexity": 2, + "token_count": 79, + "parameters": [], + "start_line": 978, + "end_line": 998, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 21, + "top_nesting_level": 0 + } + ], + "methods_before": [ + { + "name": "FLOAT_dot", + "long_name": "FLOAT_dot( * a , intp stridea , * b , intp strideb , * res , intp n , * tmp)", + "filename": "_dotblas.c", + "nloc": 7, + "complexity": 1, + "token_count": 84, + "parameters": [ + "a", + "stridea", + "b", + "strideb", + "res", + "n", + "tmp" + ], + "start_line": 14, + "end_line": 21, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 8, + "top_nesting_level": 0 + }, + { + "name": "DOUBLE_dot", + "long_name": "DOUBLE_dot( * a , intp stridea , * b , intp strideb , * res , intp n , * tmp)", + "filename": "_dotblas.c", + "nloc": 7, + "complexity": 1, + "token_count": 84, + "parameters": [ + "a", + "stridea", + "b", + "strideb", + "res", + "n", + "tmp" + ], + "start_line": 24, + "end_line": 31, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 8, + "top_nesting_level": 0 + }, + { + "name": "CFLOAT_dot", + "long_name": "CFLOAT_dot( * a , intp stridea , * b , intp strideb , * res , intp n , * tmp)", + "filename": "_dotblas.c", + "nloc": 7, + "complexity": 1, + "token_count": 81, + "parameters": [ + "a", + "stridea", + "b", + "strideb", + "res", + "n", + "tmp" + ], + "start_line": 34, + "end_line": 42, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 9, + "top_nesting_level": 0 + }, + { + "name": "CDOUBLE_dot", + "long_name": "CDOUBLE_dot( * a , intp stridea , * b , intp strideb , * res , intp n , * tmp)", + "filename": "_dotblas.c", + "nloc": 7, + "complexity": 1, + "token_count": 81, + "parameters": [ + "a", + "stridea", + "b", + "strideb", + "res", + "n", + "tmp" + ], + "start_line": 45, + "end_line": 52, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 8, + "top_nesting_level": 0 + }, + { + "name": "dotblas_alterdot", + "long_name": "dotblas_alterdot( PyObject * dummy , PyObject * args)", + "filename": "_dotblas.c", + "nloc": 22, + "complexity": 3, + "token_count": 168, + "parameters": [ + "dummy", + "args" + ], + "start_line": 61, + "end_line": 91, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 31, + "top_nesting_level": 0 + }, + { + "name": "dotblas_restoredot", + "long_name": "dotblas_restoredot( PyObject * dummy , PyObject * args)", + "filename": "_dotblas.c", + "nloc": 26, + "complexity": 3, + "token_count": 167, + "parameters": [ + "dummy", + "args" + ], + "start_line": 96, + "end_line": 128, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 33, + "top_nesting_level": 0 + }, + { + "name": "_select_matrix_shape", + "long_name": "_select_matrix_shape( PyArrayObject * array)", + "filename": "_dotblas.c", + "nloc": 22, + "complexity": 8, + "token_count": 96, + "parameters": [ + "array" + ], + "start_line": 133, + "end_line": 154, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 22, + "top_nesting_level": 0 + }, + { + "name": "dotblas_matrixproduct", + "long_name": "dotblas_matrixproduct( PyObject * dummy , PyObject * args)", + "filename": "_dotblas.c", + "nloc": 411, + "complexity": 87, + "token_count": 3532, + "parameters": [ + "dummy", + "args" + ], + "start_line": 160, + "end_line": 619, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 460, + "top_nesting_level": 0 + }, + { + "name": "dotblas_innerproduct", + "long_name": "dotblas_innerproduct( PyObject * dummy , PyObject * args)", + "filename": "_dotblas.c", + "nloc": 208, + "complexity": 54, + "token_count": 2023, + "parameters": [ + "dummy", + "args" + ], + "start_line": 625, + "end_line": 865, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 241, + "top_nesting_level": 0 + }, + { + "name": "dotblas_vdot", + "long_name": "dotblas_vdot( PyObject * dummy , PyObject * args)", + "filename": "_dotblas.c", + "nloc": 76, + "complexity": 19, + "token_count": 630, + "parameters": [ + "dummy", + "args" + ], + "start_line": 871, + "end_line": 965, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 95, + "top_nesting_level": 0 + }, + { + "name": "init_dotblas", + "long_name": "init_dotblas()", + "filename": "_dotblas.c", + "nloc": 12, + "complexity": 2, + "token_count": 79, + "parameters": [], + "start_line": 977, + "end_line": 997, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 21, + "top_nesting_level": 0 + } + ], + "changed_methods": [ + { + "name": "_select_matrix_shape", + "long_name": "_select_matrix_shape( PyArrayObject * array)", + "filename": "_dotblas.c", + "nloc": 22, + "complexity": 8, + "token_count": 96, + "parameters": [ + "array" + ], + "start_line": 133, + "end_line": 154, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 22, + "top_nesting_level": 0 + }, + { + "name": "dotblas_matrixproduct", + "long_name": "dotblas_matrixproduct( PyObject * dummy , PyObject * args)", + "filename": "_dotblas.c", + "nloc": 412, + "complexity": 92, + "token_count": 3557, + "parameters": [ + "dummy", + "args" + ], + "start_line": 160, + "end_line": 620, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 461, + "top_nesting_level": 0 + } + ], + "nloc": 837, + "complexity": 185, + "token_count": 7245, + "diff_parsed": { + "added": [ + "\tif (array->dimensions[0] > 1)", + "\tif (ap1shape == _column) nd = 1;", + "\telse nd = ap1->nd;", + "\tfor (l = 1, j = 0; j < nd; j++) {", + "\t else if (ap1->nd < 2 || ap1shape == _column) {", + "\t else if (ap1->nd < 2 || ap1shape == _column) {", + "\t else if (ap1->nd < 2 || ap1shape == _column) {", + "\t else if (ap1->nd < 2 || ap1shape == _column) {" + ], + "deleted": [ + "\tif (array->dimensions[0] > 0)", + "\tfor (l = 1, j = 0; j < ap1->nd; j++) {", + "\tnd = ap1->nd;", + "\t else if (ap1->nd < 2) {", + "\t else if (ap1->nd < 2) {", + "\t else if (ap1->nd < 2) {", + "\t else if (ap1->nd < 2) {" + ] + } + } + ] + }, + { + "hash": "bbca1e38ad33e95145c7e96229a3a5b6d012231f", + "msg": "Fix inconsistency with un-optimized dot function", + "author": { + "name": "Travis Oliphant", + "email": "oliphant@enthought.com" + }, + "committer": { + "name": "Travis Oliphant", + "email": "oliphant@enthought.com" + }, + "author_date": "2006-01-29T03:32:14+00:00", + "author_timezone": 0, + "committer_date": "2006-01-29T03:32:14+00:00", + "committer_timezone": 0, + "branches": [ + "main" + ], + "in_main_branch": true, + "merge": false, + "parents": [ + "518655847eb27aadcccc4fb9fed27897fcc9828d" + ], + "project_name": "repo_copy", + "project_path": "/tmp/tmppy2o86q9/repo_copy", + "deletions": 1, + "insertions": 4, + "lines": 5, + "files": 1, + "dmm_unit_size": null, + "dmm_unit_complexity": null, + "dmm_unit_interfacing": null, + "modified_files": [ + { + "old_path": "numpy/core/blasdot/_dotblas.c", + "new_path": "numpy/core/blasdot/_dotblas.c", + "filename": "_dotblas.c", + "extension": "c", + "change_type": "MODIFY", + "diff": "@@ -228,7 +228,10 @@ dotblas_matrixproduct(PyObject *dummy, PyObject *args)\n \t ap1shape = ap2shape;\n \t ap2shape = _scalar;\n \t}\n-\tif (ap1shape == _column) nd = 1;\n+\t/* Fix it so that dot(shape=(N,1), shape=(1,))\n+\t returns an (N,) array (but uses the fast scalar code)\n+\t*/\n+\tif (ap1shape == _column && ap2->nd == 1) nd = 1;\n \telse nd = ap1->nd;\n \tfor (l = 1, j = 0; j < nd; j++) {\n \t dimensions[j] = ap1->dimensions[j];\n", + "added_lines": 4, + "deleted_lines": 1, + "source_code": "static char module_doc[] =\n\"This module provides a BLAS optimized\\nmatrix multiply, inner product and dot for numpy arrays\";\n\n#include \"Python.h\"\n#include \"numpy/arrayobject.h\"\n#ifndef CBLAS_HEADER\n#define CBLAS_HEADER \"cblas.h\"\n#endif\n#include CBLAS_HEADER\n\n#include \n\nstatic void \nFLOAT_dot(void *a, intp stridea, void *b, intp strideb, void *res, \n\t intp n, void *tmp)\n{\n register int na = stridea / sizeof(float);\n register int nb = strideb / sizeof(float);\n\n *((float *)res) = cblas_sdot((int)n, (float *)a, na, (float *)b, nb);\n}\n\nstatic void \nDOUBLE_dot(void *a, intp stridea, void *b, intp strideb, void *res, \n\t intp n, void *tmp)\n{\n register int na = stridea / sizeof(double);\n register int nb = strideb / sizeof(double);\n\n *((double *)res) = cblas_ddot((int)n, (double *)a, na, (double *)b, nb);\n}\n\nstatic void \nCFLOAT_dot(void *a, intp stridea, void *b, intp strideb, void *res, \n\t intp n, void *tmp)\n{\n \n register int na = stridea / sizeof(cfloat);\n register int nb = strideb / sizeof(cfloat);\n\n cblas_cdotu_sub((int)n, (float *)a, na, (float *)b, nb, (float *)res);\n}\n\nstatic void \nCDOUBLE_dot(void *a, intp stridea, void *b, intp strideb, void *res, \n\t intp n, void *tmp)\n{\n register int na = stridea / sizeof(cdouble);\n register int nb = strideb / sizeof(cdouble);\n\n cblas_zdotu_sub((int)n, (double *)a, na, (double *)b, nb, (double *)res);\n}\n\n\nstatic PyArray_DotFunc *oldFunctions[PyArray_NTYPES];\nstatic Bool altered=FALSE;\n\nstatic char doc_alterdot[] = \"alterdot() changes all dot functions to use blas.\";\n\nstatic PyObject *\ndotblas_alterdot(PyObject *dummy, PyObject *args) \n{\n PyArray_Descr *descr;\n \n if (!PyArg_ParseTuple(args, \"\")) return NULL;\n\n /* Replace the dot functions to the ones using blas */\n\n if (!altered) {\n\tdescr = PyArray_DescrFromType(PyArray_FLOAT);\n\toldFunctions[PyArray_FLOAT] = descr->f->dotfunc;\n\tdescr->f->dotfunc = (PyArray_DotFunc *)FLOAT_dot;\n\t\n\tdescr = PyArray_DescrFromType(PyArray_DOUBLE);\n\toldFunctions[PyArray_DOUBLE] = descr->f->dotfunc;\n\tdescr->f->dotfunc = (PyArray_DotFunc *)DOUBLE_dot;\n\t\n\tdescr = PyArray_DescrFromType(PyArray_CFLOAT);\n\toldFunctions[PyArray_CFLOAT] = descr->f->dotfunc;\n\tdescr->f->dotfunc = (PyArray_DotFunc *)CFLOAT_dot;\n\t\n\tdescr = PyArray_DescrFromType(PyArray_CDOUBLE);\n\toldFunctions[PyArray_CDOUBLE] = descr->f->dotfunc;\n\tdescr->f->dotfunc = (PyArray_DotFunc *)CDOUBLE_dot;\n\n\taltered = TRUE;\n }\n\n Py_INCREF(Py_None);\n return Py_None;\n}\n\nstatic char doc_restoredot[] = \"restoredot() restores dots to defaults.\";\n\nstatic PyObject *\ndotblas_restoredot(PyObject *dummy, PyObject *args) \n{\n PyArray_Descr *descr;\n\n if (!PyArg_ParseTuple(args, \"\")) return NULL;\n\n if (altered) {\n\tdescr = PyArray_DescrFromType(PyArray_FLOAT);\n\tdescr->f->dotfunc = oldFunctions[PyArray_FLOAT];\n\toldFunctions[PyArray_FLOAT] = NULL;\n\tPy_XDECREF(descr);\n\n\tdescr = PyArray_DescrFromType(PyArray_DOUBLE);\n\tdescr->f->dotfunc = oldFunctions[PyArray_DOUBLE];\n\toldFunctions[PyArray_DOUBLE] = NULL;\n\tPy_XDECREF(descr);\n\n\tdescr = PyArray_DescrFromType(PyArray_CFLOAT);\n\tdescr->f->dotfunc = oldFunctions[PyArray_CFLOAT];\n\toldFunctions[PyArray_CFLOAT] = NULL;\n\tPy_XDECREF(descr);\n\n\tdescr = PyArray_DescrFromType(PyArray_CDOUBLE);\n\tdescr->f->dotfunc = oldFunctions[PyArray_CDOUBLE];\n\toldFunctions[PyArray_CDOUBLE] = NULL;\n\tPy_XDECREF(descr);\n\t\n\taltered = FALSE;\n }\n\n Py_INCREF(Py_None);\n return Py_None;\n}\n\ntypedef enum {_scalar, _column, _row, _matrix} MatrixShape;\n\nstatic MatrixShape \n_select_matrix_shape(PyArrayObject *array)\n{\n switch (array->nd) {\n case 0:\n\treturn _scalar;\n case 1:\n\tif (array->dimensions[0] > 1)\n\t return _column;\n\treturn _scalar;\n case 2:\n\tif (array->dimensions[0] > 1) {\n\t if (array->dimensions[1] == 1)\n\t\treturn _column;\n\t else\n\t\treturn _matrix;\n\t}\n\tif (array->dimensions[1] == 1)\n\t return _scalar;\n\treturn _row;\n }\n return _matrix;\n}\n\n\nstatic char doc_matrixproduct[] = \"matrixproduct(a,b)\\nReturns the dot product of a and b for arrays of floating point types.\\nLike the generic numpy equivalent the product sum is over\\nthe last dimension of a and the second-to-last dimension of b.\\nNB: The first argument is not conjugated.\";\n\nstatic PyObject *\ndotblas_matrixproduct(PyObject *dummy, PyObject *args) \n{\n PyObject *op1, *op2;\n PyArrayObject *ap1, *ap2, *ret;\n int j, l, lda, ldb, ldc;\n int typenum, nd;\n intp dimensions[MAX_DIMS];\n static const float oneF[2] = {1.0, 0.0};\n static const float zeroF[2] = {0.0, 0.0};\n static const double oneD[2] = {1.0, 0.0};\n static const double zeroD[2] = {0.0, 0.0};\n double prior1, prior2;\n PyTypeObject *subtype;\n PyArray_Descr *dtype;\n MatrixShape ap1shape, ap2shape;\n \n if (!PyArg_ParseTuple(args, \"OO\", &op1, &op2)) return NULL;\n\t\n /* \n * \"Matrix product\" using the BLAS. \n * Only works for float double and complex types.\n */\n\n\n typenum = PyArray_ObjectType(op1, 0); \n typenum = PyArray_ObjectType(op2, typenum);\n \n /* This function doesn't handle other types */\n if ((typenum != PyArray_DOUBLE && typenum != PyArray_CDOUBLE &&\n\t typenum != PyArray_FLOAT && typenum != PyArray_CFLOAT)) {\n\treturn PyArray_Return((PyArrayObject *)PyArray_MatrixProduct(op1, op2));\n }\n \n ret = NULL;\n dtype = PyArray_DescrFromType(typenum);\n ap1 = (PyArrayObject *)PyArray_FromAny(op1, dtype, 0, 0, ALIGNED, NULL);\n if (ap1 == NULL) return NULL;\n ap2 = (PyArrayObject *)PyArray_FromAny(op2, dtype, 0, 0, ALIGNED, NULL);\n if (ap2 == NULL) goto fail;\n \n if ((ap1->nd > 2) || (ap2->nd > 2)) { \n\t/* This function doesn't handle dimensions greater than 2 -- other\n\t than to ensure the dot function is altered\n\t*/\n\tif (!altered) {\n\t /* need to alter dot product */\n\t PyObject *tmp1, *tmp2;\n\t tmp1 = PyTuple_New(0);\n\t tmp2 = dotblas_alterdot(NULL, tmp1);\n\t Py_DECREF(tmp1); \n\t Py_DECREF(tmp2);\n\t}\n\tret = (PyArrayObject *)PyArray_MatrixProduct((PyObject *)ap1, \n\t\t\t\t\t\t (PyObject *)ap2);\n\tPy_DECREF(ap1); \n\tPy_DECREF(ap2);\n\treturn PyArray_Return(ret);\n }\n \n ap1shape = _select_matrix_shape(ap1);\n ap2shape = _select_matrix_shape(ap2);\n \n if (ap1shape == _scalar || ap2shape == _scalar) {\n\t/* One of ap1 or ap2 is a scalar */\n\tif (ap1shape == _scalar) { \t\t/* Make ap2 the scalar */\n\t PyArrayObject *t = ap1;\n\t ap1 = ap2;\n\t ap2 = t;\n\t ap1shape = ap2shape;\n\t ap2shape = _scalar;\n\t}\n\t/* Fix it so that dot(shape=(N,1), shape=(1,))\n\t returns an (N,) array (but uses the fast scalar code)\n\t*/\n\tif (ap1shape == _column && ap2->nd == 1) nd = 1;\n\telse nd = ap1->nd;\n\tfor (l = 1, j = 0; j < nd; j++) {\n\t dimensions[j] = ap1->dimensions[j];\n\t l *= dimensions[j];\n\t}\n }\n else { /* (ap1->nd <= 2 && ap2->nd <= 2) */\n\t/* Both ap1 and ap2 are vectors or matrices */\n\tl = ap1->dimensions[ap1->nd-1];\n\t\n\tif (ap2->dimensions[0] != l) {\n\t PyErr_SetString(PyExc_ValueError, \"matrices are not aligned\");\n\t goto fail;\n\t}\n\tnd = ap1->nd+ap2->nd-2;\n\t\n\tif (nd == 1) \n\t dimensions[0] = (ap1->nd == 2) ? ap1->dimensions[0] : ap2->dimensions[1];\n\telse if (nd == 2) {\n\t dimensions[0] = ap1->dimensions[0];\n\t dimensions[1] = ap2->dimensions[1];\n\t}\n }\n \n /* Choose which subtype to return */\n if (ap1->ob_type != ap2->ob_type) {\n\tprior2 = PyArray_GetPriority((PyObject *)ap2, 0.0);\n\tprior1 = PyArray_GetPriority((PyObject *)ap1, 0.0);\n\tsubtype = (prior2 > prior1 ? ap2->ob_type : ap1->ob_type);\n }\n else {\n\tprior1 = prior2 = 0.0;\n\tsubtype = ap1->ob_type;\n }\n \n if (l==0) nd = 0;\n ret = (PyArrayObject *)PyArray_New(subtype, nd, dimensions,\n\t\t\t\t typenum, NULL, NULL, 0, 0,\n\t\t\t\t (PyObject *)\n\t\t\t\t (prior2 > prior1 ? ap2 : ap1));\n \n if (ret == NULL) goto fail;\n memset(ret->data, 0, PyArray_NBYTES(ret));\n if (l==0) {\n\t Py_DECREF(ap1);\n\t Py_DECREF(ap2);\n\t return PyArray_Return(ret);\n }\n \n if (ap2shape == _scalar) {\n\t/* Multiplication by a scalar -- Level 1 BLAS */\n\t/* if ap1shape is a matrix and we are not contiguous, then we can't\n\t just blast through the entire array using a single\n\t striding factor */\n\tif (typenum == PyArray_DOUBLE) {\n\t if (l == 1) {\n\t\t*((double *)ret->data) = *((double *)ap2->data) * \\\n\t\t *((double *)ap1->data);\n\t }\n\t else if (ap1->nd < 2 || ap1shape == _column) {\n\t\tcblas_daxpy(l, *((double *)ap2->data), (double *)ap1->data,\n\t\t\t ap1->strides[0] / sizeof(double), \n\t\t\t (double *)ret->data, 1);\n\t }\n\t else {\n\t\tint maxind, oind, i, a1s, rets;\n\t\tchar *ptr, *rptr;\n\t\tdouble val;\n\t\tmaxind = (ap1->dimensions[0] >= ap1->dimensions[1] ? 0 : 1);\n\t\toind = 1-maxind;\n\t\tptr = ap1->data;\n\t\trptr = ret->data;\n\t\tl = ap1->dimensions[maxind];\n\t\tval = *((double *)ap2->data);\n\t\ta1s = ap1->strides[maxind] / sizeof(double);\n\t\trets = ret->strides[maxind] / sizeof(double);\n\t\tfor (i=0; i < ap1->dimensions[oind]; i++) {\n\t\t cblas_daxpy(l, val, (double *)ptr, a1s, \n\t\t\t\t(double *)rptr, rets);\n\t\t ptr += ap1->strides[oind];\n\t\t rptr += ret->strides[oind];\n\t\t}\n\t }\n\t} \n\telse if (typenum == PyArray_CDOUBLE) {\n\t if (l == 1) {\n\t\tcdouble *ptr1, *ptr2, *res;\n\t\tptr1 = (cdouble *)ap2->data;\n\t\tptr2 = (cdouble *)ap1->data;\n\t\tres = (cdouble *)ret->data;\t\t\n\t\tres->real = ptr1->real * ptr2->real - ptr1->imag * ptr2->imag;\n\t\tres->imag = ptr1->real * ptr2->imag + ptr1->imag * ptr2->real;\n\t }\n\t else if (ap1->nd < 2 || ap1shape == _column) {\n\t\tcblas_zaxpy(l, (double *)ap2->data, (double *)ap1->data,\n\t\t\t ap1->strides[0] / sizeof(cdouble), \n\t\t\t (double *)ret->data, 1);\n\t }\n\t else {\n\t\tint maxind, oind, i, a1s, rets;\n\t\tchar *ptr, *rptr;\n\t\tdouble *pval;\n\t\tmaxind = (ap1->dimensions[0] >= ap1->dimensions[1] ? 0 : 1);\n\t\toind = 1-maxind;\n\t\tptr = ap1->data;\n\t\trptr = ret->data;\n\t\tl = ap1->dimensions[maxind];\n\t\tpval = (double *)ap2->data;\n\t\ta1s = ap1->strides[maxind] / sizeof(cdouble);\n\t\trets = ret->strides[maxind] / sizeof(cdouble);\n\t\tfor (i=0; i < ap1->dimensions[oind]; i++) {\n\t\t cblas_zaxpy(l, pval, (double *)ptr, a1s, \n\t\t\t\t(double *)rptr, rets);\n\t\t ptr += ap1->strides[oind];\n\t\t rptr += ret->strides[oind];\n\t\t}\n\t }\n\t}\n\telse if (typenum == PyArray_FLOAT) {\n\t if (l == 1) {\n\t\t*((float *)ret->data) = *((float *)ap2->data) * \\\n\t\t *((float *)ap1->data);\n\t }\n\t else if (ap1->nd < 2 || ap1shape == _column) {\n\t\tcblas_saxpy(l, *((float *)ap2->data), (float *)ap1->data,\n\t\t\t ap1->strides[0] / sizeof(float), \n\t\t\t (float *)ret->data, 1);\n\t }\n\t else {\n\t\tint maxind, oind, i, a1s, rets;\n\t\tchar *ptr, *rptr;\n\t\tfloat val;\n\t\tmaxind = (ap1->dimensions[0] >= ap1->dimensions[1] ? 0 : 1);\n\t\toind = 1-maxind;\n\t\tptr = ap1->data;\n\t\trptr = ret->data;\n\t\tl = ap1->dimensions[maxind];\n\t\tval = *((float *)ap2->data);\n\t\ta1s = ap1->strides[maxind] / sizeof(float);\n\t\trets = ret->strides[maxind] / sizeof(float);\n\t\tfor (i=0; i < ap1->dimensions[oind]; i++) {\n\t\t cblas_saxpy(l, val, (float *)ptr, a1s, \n\t\t\t\t(float *)rptr, rets);\n\t\t ptr += ap1->strides[oind];\n\t\t rptr += ret->strides[oind];\n\t\t}\n\t }\n\t}\n\telse if (typenum == PyArray_CFLOAT) {\n\t if (l == 1) {\n\t\tcfloat *ptr1, *ptr2, *res;\n\t\tptr1 = (cfloat *)ap2->data;\n\t\tptr2 = (cfloat *)ap1->data;\n\t\tres = (cfloat *)ret->data;\t\t\n\t\tres->real = ptr1->real * ptr2->real - ptr1->imag * ptr2->imag;\n\t\tres->imag = ptr1->real * ptr2->imag + ptr1->imag * ptr2->real;\n\t }\n\t else if (ap1->nd < 2 || ap1shape == _column) {\n\t\tcblas_caxpy(l, (float *)ap2->data, (float *)ap1->data,\n\t\t\t ap1->strides[0] / sizeof(cfloat), \n\t\t\t (float *)ret->data, 1);\n\t }\n\t else {\n\t\tint maxind, oind, i, a1s, rets;\n\t\tchar *ptr, *rptr;\n\t\tfloat *pval;\n\t\tmaxind = (ap1->dimensions[0] >= ap1->dimensions[1] ? 0 : 1);\n\t\toind = 1-maxind;\n\t\tptr = ap1->data;\n\t\trptr = ret->data;\n\t\tl = ap1->dimensions[maxind];\n\t\tpval = (float *)ap2->data;\n\t\ta1s = ap1->strides[maxind] / sizeof(cfloat);\n\t\trets = ret->strides[maxind] / sizeof(cfloat);\n\t\tfor (i=0; i < ap1->dimensions[oind]; i++) {\n\t\t cblas_caxpy(l, pval, (float *)ptr, a1s, \n\t\t\t\t(float *)rptr, rets);\n\t\t ptr += ap1->strides[oind];\n\t\t rptr += ret->strides[oind];\n\t\t}\n\t }\n\t}\n }\n else if ((ap2shape == _column) && (ap1shape != _matrix)) {\n\tint ap1s, ap2s;\n\tap2s = ap2->strides[0] / ap2->descr->elsize;\n\tif (ap1shape == _row) {\n\t ap1s = ap1->strides[1] / ap1->descr->elsize;\n\t}\n\telse {\n\t ap1s = ap1->strides[0] / ap1->descr->elsize;\n\t}\n\t \n\t/* Dot product between two vectors -- Level 1 BLAS */\n\tif (typenum == PyArray_DOUBLE) {\n\t double result = cblas_ddot(l, (double *)ap1->data, ap1s, \n\t\t\t\t (double *)ap2->data, ap2s);\n\t *((double *)ret->data) = result;\n\t}\n\telse if (typenum == PyArray_FLOAT) {\n\t float result = cblas_sdot(l, (float *)ap1->data, ap1s, \n\t\t\t\t (float *)ap2->data, ap2s);\n\t *((float *)ret->data) = result;\n\t}\n\telse if (typenum == PyArray_CDOUBLE) {\n\t cblas_zdotu_sub(l, (double *)ap1->data, ap1s, \n\t\t\t (double *)ap2->data, ap2s, (double *)ret->data);\n\t}\n\telse if (typenum == PyArray_CFLOAT) {\n\t cblas_cdotu_sub(l, (float *)ap1->data, ap1s, \n\t\t\t (float *)ap2->data, ap2s, (float *)ret->data);\n\t}\n }\n else if (ap1shape == _matrix && ap2shape != _matrix) {\n\t/* Matrix vector multiplication -- Level 2 BLAS */\n\t/* lda must be MAX(M,1) */\n\tenum CBLAS_ORDER Order;\n\tint ap2s;\n\n\tif (!PyArray_ISONESEGMENT(ap1)) {\n\t PyObject *new;\n\t new = PyArray_Copy(ap1);\n\t Py_DECREF(ap1);\n\t ap1 = (PyArrayObject *)new;\n\t if (new == NULL) goto fail;\n\t}\n\tif (PyArray_ISCONTIGUOUS(ap1)) {\n Order = CblasRowMajor;\n lda = (ap1->dimensions[1] > 1 ? ap1->dimensions[1] : 1);\n\t}\n\telse {\n\t Order = CblasColMajor;\n lda = (ap1->dimensions[0] > 1 ? ap1->dimensions[0] : 1);\n\t}\n\tap2s = ap2->strides[0] / ap2->descr->elsize;\n\tif (typenum == PyArray_DOUBLE) {\n\t cblas_dgemv(Order, CblasNoTrans, \n\t\t\tap1->dimensions[0], ap1->dimensions[1], \n\t\t\t1.0, (double *)ap1->data, lda, \n\t\t\t(double *)ap2->data, ap2s, 0.0, (double *)ret->data, 1);\n\t}\n\telse if (typenum == PyArray_FLOAT) {\n\t cblas_sgemv(Order, CblasNoTrans, \n\t\t\tap1->dimensions[0], ap1->dimensions[1], \n\t\t\t1.0, (float *)ap1->data, lda, \n\t\t\t(float *)ap2->data, ap2s, 0.0, (float *)ret->data, 1);\n\t}\n\telse if (typenum == PyArray_CDOUBLE) {\n\t cblas_zgemv(Order, \n\t\t\tCblasNoTrans, ap1->dimensions[0], ap1->dimensions[1], \n\t\t\toneD, (double *)ap1->data, lda, \n\t\t\t(double *)ap2->data, ap2s, zeroD, \n\t\t\t(double *)ret->data, 1);\n\t}\n\telse if (typenum == PyArray_CFLOAT) {\n\t cblas_cgemv(Order, \n\t\t\tCblasNoTrans, ap1->dimensions[0], ap1->dimensions[1], \n\t\t\toneF, (float *)ap1->data, lda, \n\t\t\t(float *)ap2->data, ap2s, zeroF, \n\t\t\t(float *)ret->data, 1);\n\t}\n }\n else if (ap1shape != _matrix && ap2shape == _matrix) {\n\t/* Vector matrix multiplication -- Level 2 BLAS */\n\tenum CBLAS_ORDER Order;\n\tint ap1s;\n\n\tif (!PyArray_ISONESEGMENT(ap2)) {\n\t PyObject *new;\n\t new = PyArray_Copy(ap2);\n\t Py_DECREF(ap2);\n\t ap2 = (PyArrayObject *)new;\n\t if (new == NULL) goto fail;\n\t}\n\tif (PyArray_ISCONTIGUOUS(ap2)) {\n\t Order = CblasRowMajor;\n lda = (ap2->dimensions[1] > 1 ? ap2->dimensions[1] : 1);\n\t}\n\telse {\n\t Order = CblasColMajor;\n lda = (ap2->dimensions[0] > 1 ? ap2->dimensions[0] : 1);\n\t}\n\tif (ap1shape == _row) {\n\t ap1s = ap1->strides[1] / ap1->descr->elsize;\n\t}\n\telse {\n\t ap1s = ap1->strides[0] / ap1->descr->elsize;\n\t}\n\tif (typenum == PyArray_DOUBLE) {\n\t cblas_dgemv(Order, \n\t\t\tCblasTrans, ap2->dimensions[0], ap2->dimensions[1], \n\t\t\t1.0, (double *)ap2->data, lda,\n\t\t\t(double *)ap1->data, ap1s, 0.0, (double *)ret->data, 1);\n\t}\n\telse if (typenum == PyArray_FLOAT) {\n\t cblas_sgemv(Order,\n\t\t\tCblasTrans, ap2->dimensions[0], ap2->dimensions[1], \n\t\t\t1.0, (float *)ap2->data, lda,\n\t\t\t(float *)ap1->data, ap1s, 0.0, (float *)ret->data, 1);\n\t}\n\telse if (typenum == PyArray_CDOUBLE) {\n\t cblas_zgemv(Order,\n\t\t\tCblasTrans, ap2->dimensions[0], ap2->dimensions[1], \n\t\t\toneD, (double *)ap2->data, lda,\n\t\t\t(double *)ap1->data, ap1s, zeroD, (double *)ret->data, 1);\n\t}\n\telse if (typenum == PyArray_CFLOAT) {\n\t cblas_cgemv(Order,\n\t\t\tCblasTrans, ap2->dimensions[0], ap2->dimensions[1], \n\t\t\toneF, (float *)ap2->data, lda,\n\t\t\t(float *)ap1->data, ap1s, zeroF, (float *)ret->data, 1);\n\t}\n }\n else { /* (ap1->nd == 2 && ap2->nd == 2) */\n\t/* Matrix matrix multiplication -- Level 3 BLAS */ \n\t/* L x M multiplied by M x N */\n\tenum CBLAS_ORDER Order;\n\tenum CBLAS_TRANSPOSE Trans1, Trans2;\n\tint M, N, L;\n\n\t/* Optimization possible: */\n\t/* We may be able to handle single-segment arrays here\n\t using appropriate values of Order, Trans1, and Trans2.\n\t*/\n\t\n \tif (!PyArray_ISCONTIGUOUS(ap2)) {\n\t PyObject *new;\n\t new = PyArray_Copy(ap2);\n\t Py_DECREF(ap2);\n\t ap2 = (PyArrayObject *)new;\n\t if (new == NULL) goto fail;\n\t}\n\tif (!PyArray_ISCONTIGUOUS(ap1)) {\n\t PyObject *new;\n\t new = PyArray_Copy(ap1);\n\t Py_DECREF(ap1);\n\t ap1 = (PyArrayObject *)new;\n\t if (new == NULL) goto fail;\n\t}\n\t\n\tOrder = CblasRowMajor;\n\tTrans1 = CblasNoTrans;\n\tTrans2 = CblasNoTrans;\n\tL = ap1->dimensions[0];\n\tN = ap2->dimensions[1];\n\tM = ap2->dimensions[0];\n\tlda = (ap1->dimensions[1] > 1 ? ap1->dimensions[1] : 1);\n\tldb = (ap2->dimensions[1] > 1 ? ap2->dimensions[1] : 1);\n\tldc = (ret->dimensions[1] > 1 ? ret->dimensions[1] : 1);\t \n\tif (typenum == PyArray_DOUBLE) {\n\t cblas_dgemm(Order, Trans1, Trans2, \n\t\t\tL, N, M,\n\t\t\t1.0, (double *)ap1->data, lda,\n\t\t\t(double *)ap2->data, ldb,\n\t\t\t0.0, (double *)ret->data, ldc);\n\t}\n\telse if (typenum == PyArray_FLOAT) {\n\t cblas_sgemm(Order, Trans1, Trans2,\n\t\t\tL, N, M, \n\t\t\t1.0, (float *)ap1->data, lda,\n\t\t\t(float *)ap2->data, ldb,\n\t\t\t0.0, (float *)ret->data, ldc);\n\t}\n\telse if (typenum == PyArray_CDOUBLE) {\n\t cblas_zgemm(Order, Trans1, Trans2,\n\t\t\tL, N, M, \n\t\t\toneD, (double *)ap1->data, lda,\n\t\t\t(double *)ap2->data, ldb,\n\t\t\tzeroD, (double *)ret->data, ldc);\n\t}\n\telse if (typenum == PyArray_CFLOAT) {\n\t cblas_cgemm(Order, Trans1, Trans2,\n\t\t\tL, N, M,\n\t\t\toneF, (float *)ap1->data, lda,\n\t\t\t(float *)ap2->data, ldb,\n\t\t\tzeroF, (float *)ret->data, ldc);\n\t}\n }\n\n Py_DECREF(ap1);\n Py_DECREF(ap2);\n return PyArray_Return(ret);\n\t\n fail:\n Py_XDECREF(ap1);\n Py_XDECREF(ap2);\n Py_XDECREF(ret);\n return NULL;\n}\n\n\nstatic char doc_innerproduct[] = \"innerproduct(a,b)\\nReturns the inner product of a and b for arrays of floating point types.\\nLike the generic Numeric equivalent the product sum is over\\nthe last dimension of a and b.\\nNB: The first argument is not conjugated.\";\n\nstatic PyObject *\ndotblas_innerproduct(PyObject *dummy, PyObject *args) \n{\n PyObject *op1, *op2;\n PyArrayObject *ap1, *ap2, *ret;\n int j, l, lda, ldb, ldc;\n int typenum, nd;\n intp dimensions[MAX_DIMS];\n static const float oneF[2] = {1.0, 0.0};\n static const float zeroF[2] = {0.0, 0.0};\n static const double oneD[2] = {1.0, 0.0};\n static const double zeroD[2] = {0.0, 0.0};\n PyTypeObject *subtype;\n double prior1, prior2;\n\n if (!PyArg_ParseTuple(args, \"OO\", &op1, &op2)) return NULL;\n\t\n /* \n * Inner product using the BLAS. The product sum is taken along the last\n * dimensions of the two arrays.\n * Only speeds things up for float double and complex types.\n */\n\n\n typenum = PyArray_ObjectType(op1, 0); \n typenum = PyArray_ObjectType(op2, typenum);\n\n /* This function doesn't handle other types */\n if ((typenum != PyArray_DOUBLE && typenum != PyArray_CDOUBLE &&\n\t typenum != PyArray_FLOAT && typenum != PyArray_CFLOAT)) {\n return PyArray_Return((PyArrayObject *)PyArray_InnerProduct(op1, op2));\n }\n\n ret = NULL;\n ap1 = (PyArrayObject *)PyArray_ContiguousFromObject(op1, typenum, 0, 0);\n if (ap1 == NULL) return NULL;\n ap2 = (PyArrayObject *)PyArray_ContiguousFromObject(op2, typenum, 0, 0);\n if (ap2 == NULL) goto fail;\n\n if ((ap1->nd > 2) || (ap2->nd > 2)) { \n\t/* This function doesn't handle dimensions greater than 2 -- other\n\t than to ensure the dot function is altered\n\t*/\n\tif (!altered) {\n\t /* need to alter dot product */\n\t PyObject *tmp1, *tmp2;\n\t tmp1 = PyTuple_New(0);\n\t tmp2 = dotblas_alterdot(NULL, tmp1);\n\t Py_DECREF(tmp1); \n\t Py_DECREF(tmp2);\n\t}\n\tret = (PyArrayObject *)PyArray_InnerProduct((PyObject *)ap1, \n\t\t\t\t\t\t (PyObject *)ap2);\n\tPy_DECREF(ap1); \n\tPy_DECREF(ap2);\n\treturn PyArray_Return(ret);\n }\n\n if (ap1->nd == 0 || ap2->nd == 0) {\n\t/* One of ap1 or ap2 is a scalar */\n\tif (ap1->nd == 0) {\t\t/* Make ap2 the scalar */\n\t PyArrayObject *t = ap1;\n\t ap1 = ap2;\n\t ap2 = t;\n\t}\n\tfor (l = 1, j = 0; j < ap1->nd; j++) {\n\t dimensions[j] = ap1->dimensions[j];\n\t l *= dimensions[j];\n\t}\n\tnd = ap1->nd;\n }\n else { /* (ap1->nd <= 2 && ap2->nd <= 2) */\n\t/* Both ap1 and ap2 are vectors or matrices */\n\tl = ap1->dimensions[ap1->nd-1];\n\t\n\tif (ap2->dimensions[ap2->nd-1] != l) {\n\t PyErr_SetString(PyExc_ValueError, \"matrices are not aligned\");\n\t goto fail;\n\t}\n\tnd = ap1->nd+ap2->nd-2;\n \n\tif (nd == 1) \n\t dimensions[0] = (ap1->nd == 2) ? ap1->dimensions[0] : ap2->dimensions[0];\n\telse if (nd == 2) {\n\t dimensions[0] = ap1->dimensions[0];\n\t dimensions[1] = ap2->dimensions[0];\n\t}\n }\n\n /* Choose which subtype to return */\n prior2 = PyArray_GetPriority((PyObject *)ap2, 0.0);\n prior1 = PyArray_GetPriority((PyObject *)ap1, 0.0);\n subtype = (prior2 > prior1 ? ap2->ob_type : ap1->ob_type);\n \n ret = (PyArrayObject *)PyArray_New(subtype, nd, dimensions, \n\t\t\t\t typenum, NULL, NULL, 0, 0, \n\t\t\t\t (PyObject *)\\\n\t\t\t\t (prior2 > prior1 ? ap2 : ap1));\n \n if (ret == NULL) goto fail;\n memset(ret->data, 0, PyArray_NBYTES(ret));\n\n if (ap2->nd == 0) {\n\t/* Multiplication by a scalar -- Level 1 BLAS */\n\tif (typenum == PyArray_DOUBLE) {\n\t cblas_daxpy(l, *((double *)ap2->data), (double *)ap1->data, 1,\n\t\t\t(double *)ret->data, 1);\n\t} \n\telse if (typenum == PyArray_CDOUBLE) {\n\t cblas_zaxpy(l, (double *)ap2->data, (double *)ap1->data, 1,\n\t\t\t(double *)ret->data, 1);\n\t}\n\telse if (typenum == PyArray_FLOAT) {\n\t cblas_saxpy(l, *((float *)ap2->data), (float *)ap1->data, 1,\n\t\t\t(float *)ret->data, 1);\n\t}\n\telse if (typenum == PyArray_CFLOAT) {\n\t cblas_caxpy(l, (float *)ap2->data, (float *)ap1->data, 1,\n\t\t\t(float *)ret->data, 1);\n\t}\n }\n else if (ap1->nd == 1 && ap2->nd == 1) {\n\t/* Dot product between two vectors -- Level 1 BLAS */\n\tif (typenum == PyArray_DOUBLE) {\n\t double result = cblas_ddot(l, (double *)ap1->data, 1, \n\t\t\t\t (double *)ap2->data, 1);\n\t *((double *)ret->data) = result;\n\t}\n\telse if (typenum == PyArray_CDOUBLE) {\n\t cblas_zdotu_sub(l, (double *)ap1->data, 1, \n\t\t\t (double *)ap2->data, 1, (double *)ret->data);\n\t}\n\telse if (typenum == PyArray_FLOAT) {\n\t float result = cblas_sdot(l, (float *)ap1->data, 1, \n\t\t\t\t (float *)ap2->data, 1);\n\t *((float *)ret->data) = result;\n\t}\n\telse if (typenum == PyArray_CFLOAT) {\n\t cblas_cdotu_sub(l, (float *)ap1->data, 1, \n\t\t\t (float *)ap2->data, 1, (float *)ret->data);\n\t}\n }\n else if (ap1->nd == 2 && ap2->nd == 1) {\n\t/* Matrix-vector multiplication -- Level 2 BLAS */\n\tlda = (ap1->dimensions[1] > 1 ? ap1->dimensions[1] : 1);\n\tif (typenum == PyArray_DOUBLE) {\n\t cblas_dgemv(CblasRowMajor, \n\t\t\tCblasNoTrans, ap1->dimensions[0], ap1->dimensions[1], \n\t\t\t1.0, (double *)ap1->data, lda,\n\t\t\t(double *)ap2->data, 1, 0.0, (double *)ret->data, 1);\n\t}\n\telse if (typenum == PyArray_CDOUBLE) {\n\t cblas_zgemv(CblasRowMajor, \n\t\t\tCblasNoTrans, ap1->dimensions[0], ap1->dimensions[1], \n\t\t\toneD, (double *)ap1->data, lda,\n\t\t\t(double *)ap2->data, 1, zeroD, (double *)ret->data, 1);\n\t}\n\telse if (typenum == PyArray_FLOAT) {\n\t cblas_sgemv(CblasRowMajor, \n\t\t\tCblasNoTrans, ap1->dimensions[0], ap1->dimensions[1], \n\t\t\t1.0, (float *)ap1->data, lda,\n\t\t\t(float *)ap2->data, 1, 0.0, (float *)ret->data, 1);\n\t}\n\telse if (typenum == PyArray_CFLOAT) {\n\t cblas_cgemv(CblasRowMajor, \n\t\t\tCblasNoTrans, ap1->dimensions[0], ap1->dimensions[1], \n\t\t\toneF, (float *)ap1->data, lda,\n\t\t\t(float *)ap2->data, 1, zeroF, (float *)ret->data, 1);\n\t}\n }\n else if (ap1->nd == 1 && ap2->nd == 2) {\n\t/* Vector matrix multiplication -- Level 2 BLAS */\n\tlda = (ap2->dimensions[1] > 1 ? ap2->dimensions[1] : 1);\n\tif (typenum == PyArray_DOUBLE) {\n\t cblas_dgemv(CblasRowMajor, \n\t\t\tCblasNoTrans, ap2->dimensions[0], ap2->dimensions[1], \n\t\t\t1.0, (double *)ap2->data, lda,\n\t\t\t(double *)ap1->data, 1, 0.0, (double *)ret->data, 1);\n\t}\n\telse if (typenum == PyArray_CDOUBLE) {\n\t cblas_zgemv(CblasRowMajor, \n\t\t\tCblasNoTrans, ap2->dimensions[0], ap2->dimensions[1], \n\t\t\toneD, (double *)ap2->data, lda,\n\t\t\t(double *)ap1->data, 1, zeroD, (double *)ret->data, 1);\n\t}\n\telse if (typenum == PyArray_FLOAT) {\n\t cblas_sgemv(CblasRowMajor, \n\t\t\tCblasNoTrans, ap2->dimensions[0], ap2->dimensions[1], \n\t\t\t1.0, (float *)ap2->data, lda,\n\t\t\t(float *)ap1->data, 1, 0.0, (float *)ret->data, 1);\n\t}\n\telse if (typenum == PyArray_CFLOAT) {\n\t cblas_cgemv(CblasRowMajor, \n\t\t\tCblasNoTrans, ap2->dimensions[0], ap2->dimensions[1], \n\t\t\toneF, (float *)ap2->data, lda,\n\t\t\t(float *)ap1->data, 1, zeroF, (float *)ret->data, 1);\n\t}\n }\n else { /* (ap1->nd == 2 && ap2->nd == 2) */ \n\t/* Matrix matrix multiplication -- Level 3 BLAS */ \n\tlda = (ap1->dimensions[1] > 1 ? ap1->dimensions[1] : 1);\n\tldb = (ap2->dimensions[1] > 1 ? ap2->dimensions[1] : 1);\n\tldc = (ret->dimensions[1] > 1 ? ret->dimensions[1] : 1);\n\tif (typenum == PyArray_DOUBLE) {\n\t cblas_dgemm(CblasRowMajor, CblasNoTrans, CblasTrans,\n\t\t\tap1->dimensions[0], ap2->dimensions[0], ap1->dimensions[1],\n\t\t\t1.0, (double *)ap1->data, lda,\n\t\t\t(double *)ap2->data, ldb,\n\t\t\t0.0, (double *)ret->data, ldc);\n\t}\n\telse if (typenum == PyArray_FLOAT) {\n\t cblas_sgemm(CblasRowMajor, CblasNoTrans, CblasTrans,\n\t\t\tap1->dimensions[0], ap2->dimensions[0], ap1->dimensions[1],\n\t\t\t1.0, (float *)ap1->data, lda,\n\t\t\t(float *)ap2->data, ldb,\n\t\t\t0.0, (float *)ret->data, ldc);\n\t}\n\telse if (typenum == PyArray_CDOUBLE) {\n\t cblas_zgemm(CblasRowMajor, CblasNoTrans, CblasTrans,\n\t\t\tap1->dimensions[0], ap2->dimensions[0], ap1->dimensions[1],\n\t\t\toneD, (double *)ap1->data, lda,\n\t\t\t(double *)ap2->data, ldb,\n\t\t\tzeroD, (double *)ret->data, ldc);\n\t}\n\telse if (typenum == PyArray_CFLOAT) {\n\t cblas_cgemm(CblasRowMajor, CblasNoTrans, CblasTrans,\n\t\t\tap1->dimensions[0], ap2->dimensions[0], ap1->dimensions[1],\n\t\t\toneF, (float *)ap1->data, lda,\n\t\t\t(float *)ap2->data, ldb,\n\t\t\tzeroF, (float *)ret->data, ldc);\n\t}\n }\n Py_DECREF(ap1);\n Py_DECREF(ap2);\n return PyArray_Return(ret);\n\t\n fail:\n Py_XDECREF(ap1);\n Py_XDECREF(ap2);\n Py_XDECREF(ret);\n return NULL;\n}\n\n\nstatic char doc_vdot[] = \"vdot(a,b)\\nReturns the dot product of a and b for scalars and vectors\\nof floating point and complex types. The first argument, a, is conjugated.\";\n\n\nstatic PyObject *dotblas_vdot(PyObject *dummy, PyObject *args) {\n PyObject *op1, *op2;\n PyArrayObject *ap1=NULL, *ap2=NULL, *ret=NULL;\n int l;\n int typenum;\n intp dimensions[MAX_DIMS];\n PyArray_Descr *type;\n\n if (!PyArg_ParseTuple(args, \"OO\", &op1, &op2)) return NULL;\n\t\n /* \n * Conjugating dot product using the BLAS for vectors.\n * Multiplies op1 and op2, each of which must be vector.\n */\n\n typenum = PyArray_ObjectType(op1, 0); \n typenum = PyArray_ObjectType(op2, typenum);\n \n type = PyArray_DescrFromType(typenum);\n \n ap1 = (PyArrayObject *)PyArray_FromAny(op1, type, 0, 0, 0, NULL);\n if (ap1==NULL) goto fail;\n op1 = PyArray_Flatten(ap1, 0);\n if (op1==NULL) goto fail;\n Py_DECREF(ap1);\n ap1 = (PyArrayObject *)op1;\n \n ap2 = (PyArrayObject *)PyArray_FromAny(op2, type, 0, 0, 0, NULL);\n if (ap2==NULL) goto fail;\n op2 = PyArray_Flatten(ap2, 0);\n if (op2 == NULL) goto fail;\n Py_DECREF(ap2);\n ap2 = (PyArrayObject *)op2;\n \n if (typenum != PyArray_FLOAT && typenum != PyArray_DOUBLE &&\n\ttypenum != PyArray_CFLOAT && typenum != PyArray_CDOUBLE) {\n\tif (!altered) {\n\t /* need to alter dot product */\n\t PyObject *tmp1, *tmp2;\n\t tmp1 = PyTuple_New(0);\n\t tmp2 = dotblas_alterdot(NULL, tmp1);\n\t Py_DECREF(tmp1); \n\t Py_DECREF(tmp2);\n\t}\n\tif (PyTypeNum_ISCOMPLEX(typenum)) {\n\t op1 = PyArray_Conjugate(ap1);\n\t if (op1==NULL) goto fail;\n\t Py_DECREF(ap1);\n\t ap1 = (PyArrayObject *)op1;\n\t}\t\n\tret = (PyArrayObject *)PyArray_InnerProduct((PyObject *)ap1, \n\t\t\t\t\t\t (PyObject *)ap2);\n\tPy_DECREF(ap1); \n\tPy_DECREF(ap2);\n\treturn PyArray_Return(ret);\n }\n\n if (ap2->dimensions[0] != ap1->dimensions[ap1->nd-1]) {\n\tPyErr_SetString(PyExc_ValueError, \"vectors have different lengths\");\n\tgoto fail;\n }\n l = ap1->dimensions[ap1->nd-1];\n \n ret = (PyArrayObject *)PyArray_SimpleNew(0, dimensions, typenum);\n if (ret == NULL) goto fail;\n\n\n /* Dot product between two vectors -- Level 1 BLAS */\n if (typenum == PyArray_DOUBLE) {\n\t*((double *)ret->data) = cblas_ddot(l, (double *)ap1->data, 1, \n\t\t\t\t\t (double *)ap2->data, 1);\n }\n else if (typenum == PyArray_FLOAT) {\n\t*((float *)ret->data) = cblas_sdot(l, (float *)ap1->data, 1, \n\t\t\t\t\t (float *)ap2->data, 1);\n }\n else if (typenum == PyArray_CDOUBLE) {\n\tcblas_zdotc_sub(l, (double *)ap1->data, 1, \n\t\t\t(double *)ap2->data, 1, (double *)ret->data);\n }\n else if (typenum == PyArray_CFLOAT) {\n\tcblas_cdotc_sub(l, (float *)ap1->data, 1, \n\t\t\t(float *)ap2->data, 1, (float *)ret->data);\n }\n\n Py_DECREF(ap1);\n Py_DECREF(ap2);\n return PyArray_Return(ret);\n\t\n fail:\n Py_XDECREF(ap1);\n Py_XDECREF(ap2);\n Py_XDECREF(ret);\n return NULL;\n}\n\nstatic struct PyMethodDef dotblas_module_methods[] = {\n {\"dot\", (PyCFunction)dotblas_matrixproduct, 1, doc_matrixproduct},\n {\"inner\", (PyCFunction)dotblas_innerproduct, 1, doc_innerproduct},\n {\"vdot\", (PyCFunction)dotblas_vdot, 1, doc_vdot},\n {\"alterdot\", (PyCFunction)dotblas_alterdot, 1, doc_alterdot},\n {\"restoredot\", (PyCFunction)dotblas_restoredot, 1, doc_restoredot},\n {NULL,\t\tNULL, 0}\t\t/* sentinel */\n};\n\n/* Initialization function for the module */\nDL_EXPORT(void) init_dotblas(void) {\n int i;\n PyObject *m, *d, *s;\n \n /* Create the module and add the functions */\n m = Py_InitModule3(\"_dotblas\", dotblas_module_methods, module_doc);\n\n /* Import the array object */\n import_array();\n\n /* Initialise the array of dot functions */\n for (i = 0; i < PyArray_NTYPES; i++)\n\toldFunctions[i] = NULL;\n\n /* alterdot at load */\n d = PyTuple_New(0);\n s = dotblas_alterdot(NULL, d);\n Py_DECREF(d);\n Py_DECREF(s);\n \n}\n", + "source_code_before": "static char module_doc[] =\n\"This module provides a BLAS optimized\\nmatrix multiply, inner product and dot for numpy arrays\";\n\n#include \"Python.h\"\n#include \"numpy/arrayobject.h\"\n#ifndef CBLAS_HEADER\n#define CBLAS_HEADER \"cblas.h\"\n#endif\n#include CBLAS_HEADER\n\n#include \n\nstatic void \nFLOAT_dot(void *a, intp stridea, void *b, intp strideb, void *res, \n\t intp n, void *tmp)\n{\n register int na = stridea / sizeof(float);\n register int nb = strideb / sizeof(float);\n\n *((float *)res) = cblas_sdot((int)n, (float *)a, na, (float *)b, nb);\n}\n\nstatic void \nDOUBLE_dot(void *a, intp stridea, void *b, intp strideb, void *res, \n\t intp n, void *tmp)\n{\n register int na = stridea / sizeof(double);\n register int nb = strideb / sizeof(double);\n\n *((double *)res) = cblas_ddot((int)n, (double *)a, na, (double *)b, nb);\n}\n\nstatic void \nCFLOAT_dot(void *a, intp stridea, void *b, intp strideb, void *res, \n\t intp n, void *tmp)\n{\n \n register int na = stridea / sizeof(cfloat);\n register int nb = strideb / sizeof(cfloat);\n\n cblas_cdotu_sub((int)n, (float *)a, na, (float *)b, nb, (float *)res);\n}\n\nstatic void \nCDOUBLE_dot(void *a, intp stridea, void *b, intp strideb, void *res, \n\t intp n, void *tmp)\n{\n register int na = stridea / sizeof(cdouble);\n register int nb = strideb / sizeof(cdouble);\n\n cblas_zdotu_sub((int)n, (double *)a, na, (double *)b, nb, (double *)res);\n}\n\n\nstatic PyArray_DotFunc *oldFunctions[PyArray_NTYPES];\nstatic Bool altered=FALSE;\n\nstatic char doc_alterdot[] = \"alterdot() changes all dot functions to use blas.\";\n\nstatic PyObject *\ndotblas_alterdot(PyObject *dummy, PyObject *args) \n{\n PyArray_Descr *descr;\n \n if (!PyArg_ParseTuple(args, \"\")) return NULL;\n\n /* Replace the dot functions to the ones using blas */\n\n if (!altered) {\n\tdescr = PyArray_DescrFromType(PyArray_FLOAT);\n\toldFunctions[PyArray_FLOAT] = descr->f->dotfunc;\n\tdescr->f->dotfunc = (PyArray_DotFunc *)FLOAT_dot;\n\t\n\tdescr = PyArray_DescrFromType(PyArray_DOUBLE);\n\toldFunctions[PyArray_DOUBLE] = descr->f->dotfunc;\n\tdescr->f->dotfunc = (PyArray_DotFunc *)DOUBLE_dot;\n\t\n\tdescr = PyArray_DescrFromType(PyArray_CFLOAT);\n\toldFunctions[PyArray_CFLOAT] = descr->f->dotfunc;\n\tdescr->f->dotfunc = (PyArray_DotFunc *)CFLOAT_dot;\n\t\n\tdescr = PyArray_DescrFromType(PyArray_CDOUBLE);\n\toldFunctions[PyArray_CDOUBLE] = descr->f->dotfunc;\n\tdescr->f->dotfunc = (PyArray_DotFunc *)CDOUBLE_dot;\n\n\taltered = TRUE;\n }\n\n Py_INCREF(Py_None);\n return Py_None;\n}\n\nstatic char doc_restoredot[] = \"restoredot() restores dots to defaults.\";\n\nstatic PyObject *\ndotblas_restoredot(PyObject *dummy, PyObject *args) \n{\n PyArray_Descr *descr;\n\n if (!PyArg_ParseTuple(args, \"\")) return NULL;\n\n if (altered) {\n\tdescr = PyArray_DescrFromType(PyArray_FLOAT);\n\tdescr->f->dotfunc = oldFunctions[PyArray_FLOAT];\n\toldFunctions[PyArray_FLOAT] = NULL;\n\tPy_XDECREF(descr);\n\n\tdescr = PyArray_DescrFromType(PyArray_DOUBLE);\n\tdescr->f->dotfunc = oldFunctions[PyArray_DOUBLE];\n\toldFunctions[PyArray_DOUBLE] = NULL;\n\tPy_XDECREF(descr);\n\n\tdescr = PyArray_DescrFromType(PyArray_CFLOAT);\n\tdescr->f->dotfunc = oldFunctions[PyArray_CFLOAT];\n\toldFunctions[PyArray_CFLOAT] = NULL;\n\tPy_XDECREF(descr);\n\n\tdescr = PyArray_DescrFromType(PyArray_CDOUBLE);\n\tdescr->f->dotfunc = oldFunctions[PyArray_CDOUBLE];\n\toldFunctions[PyArray_CDOUBLE] = NULL;\n\tPy_XDECREF(descr);\n\t\n\taltered = FALSE;\n }\n\n Py_INCREF(Py_None);\n return Py_None;\n}\n\ntypedef enum {_scalar, _column, _row, _matrix} MatrixShape;\n\nstatic MatrixShape \n_select_matrix_shape(PyArrayObject *array)\n{\n switch (array->nd) {\n case 0:\n\treturn _scalar;\n case 1:\n\tif (array->dimensions[0] > 1)\n\t return _column;\n\treturn _scalar;\n case 2:\n\tif (array->dimensions[0] > 1) {\n\t if (array->dimensions[1] == 1)\n\t\treturn _column;\n\t else\n\t\treturn _matrix;\n\t}\n\tif (array->dimensions[1] == 1)\n\t return _scalar;\n\treturn _row;\n }\n return _matrix;\n}\n\n\nstatic char doc_matrixproduct[] = \"matrixproduct(a,b)\\nReturns the dot product of a and b for arrays of floating point types.\\nLike the generic numpy equivalent the product sum is over\\nthe last dimension of a and the second-to-last dimension of b.\\nNB: The first argument is not conjugated.\";\n\nstatic PyObject *\ndotblas_matrixproduct(PyObject *dummy, PyObject *args) \n{\n PyObject *op1, *op2;\n PyArrayObject *ap1, *ap2, *ret;\n int j, l, lda, ldb, ldc;\n int typenum, nd;\n intp dimensions[MAX_DIMS];\n static const float oneF[2] = {1.0, 0.0};\n static const float zeroF[2] = {0.0, 0.0};\n static const double oneD[2] = {1.0, 0.0};\n static const double zeroD[2] = {0.0, 0.0};\n double prior1, prior2;\n PyTypeObject *subtype;\n PyArray_Descr *dtype;\n MatrixShape ap1shape, ap2shape;\n \n if (!PyArg_ParseTuple(args, \"OO\", &op1, &op2)) return NULL;\n\t\n /* \n * \"Matrix product\" using the BLAS. \n * Only works for float double and complex types.\n */\n\n\n typenum = PyArray_ObjectType(op1, 0); \n typenum = PyArray_ObjectType(op2, typenum);\n \n /* This function doesn't handle other types */\n if ((typenum != PyArray_DOUBLE && typenum != PyArray_CDOUBLE &&\n\t typenum != PyArray_FLOAT && typenum != PyArray_CFLOAT)) {\n\treturn PyArray_Return((PyArrayObject *)PyArray_MatrixProduct(op1, op2));\n }\n \n ret = NULL;\n dtype = PyArray_DescrFromType(typenum);\n ap1 = (PyArrayObject *)PyArray_FromAny(op1, dtype, 0, 0, ALIGNED, NULL);\n if (ap1 == NULL) return NULL;\n ap2 = (PyArrayObject *)PyArray_FromAny(op2, dtype, 0, 0, ALIGNED, NULL);\n if (ap2 == NULL) goto fail;\n \n if ((ap1->nd > 2) || (ap2->nd > 2)) { \n\t/* This function doesn't handle dimensions greater than 2 -- other\n\t than to ensure the dot function is altered\n\t*/\n\tif (!altered) {\n\t /* need to alter dot product */\n\t PyObject *tmp1, *tmp2;\n\t tmp1 = PyTuple_New(0);\n\t tmp2 = dotblas_alterdot(NULL, tmp1);\n\t Py_DECREF(tmp1); \n\t Py_DECREF(tmp2);\n\t}\n\tret = (PyArrayObject *)PyArray_MatrixProduct((PyObject *)ap1, \n\t\t\t\t\t\t (PyObject *)ap2);\n\tPy_DECREF(ap1); \n\tPy_DECREF(ap2);\n\treturn PyArray_Return(ret);\n }\n \n ap1shape = _select_matrix_shape(ap1);\n ap2shape = _select_matrix_shape(ap2);\n \n if (ap1shape == _scalar || ap2shape == _scalar) {\n\t/* One of ap1 or ap2 is a scalar */\n\tif (ap1shape == _scalar) { \t\t/* Make ap2 the scalar */\n\t PyArrayObject *t = ap1;\n\t ap1 = ap2;\n\t ap2 = t;\n\t ap1shape = ap2shape;\n\t ap2shape = _scalar;\n\t}\n\tif (ap1shape == _column) nd = 1;\n\telse nd = ap1->nd;\n\tfor (l = 1, j = 0; j < nd; j++) {\n\t dimensions[j] = ap1->dimensions[j];\n\t l *= dimensions[j];\n\t}\n }\n else { /* (ap1->nd <= 2 && ap2->nd <= 2) */\n\t/* Both ap1 and ap2 are vectors or matrices */\n\tl = ap1->dimensions[ap1->nd-1];\n\t\n\tif (ap2->dimensions[0] != l) {\n\t PyErr_SetString(PyExc_ValueError, \"matrices are not aligned\");\n\t goto fail;\n\t}\n\tnd = ap1->nd+ap2->nd-2;\n\t\n\tif (nd == 1) \n\t dimensions[0] = (ap1->nd == 2) ? ap1->dimensions[0] : ap2->dimensions[1];\n\telse if (nd == 2) {\n\t dimensions[0] = ap1->dimensions[0];\n\t dimensions[1] = ap2->dimensions[1];\n\t}\n }\n \n /* Choose which subtype to return */\n if (ap1->ob_type != ap2->ob_type) {\n\tprior2 = PyArray_GetPriority((PyObject *)ap2, 0.0);\n\tprior1 = PyArray_GetPriority((PyObject *)ap1, 0.0);\n\tsubtype = (prior2 > prior1 ? ap2->ob_type : ap1->ob_type);\n }\n else {\n\tprior1 = prior2 = 0.0;\n\tsubtype = ap1->ob_type;\n }\n \n if (l==0) nd = 0;\n ret = (PyArrayObject *)PyArray_New(subtype, nd, dimensions,\n\t\t\t\t typenum, NULL, NULL, 0, 0,\n\t\t\t\t (PyObject *)\n\t\t\t\t (prior2 > prior1 ? ap2 : ap1));\n \n if (ret == NULL) goto fail;\n memset(ret->data, 0, PyArray_NBYTES(ret));\n if (l==0) {\n\t Py_DECREF(ap1);\n\t Py_DECREF(ap2);\n\t return PyArray_Return(ret);\n }\n \n if (ap2shape == _scalar) {\n\t/* Multiplication by a scalar -- Level 1 BLAS */\n\t/* if ap1shape is a matrix and we are not contiguous, then we can't\n\t just blast through the entire array using a single\n\t striding factor */\n\tif (typenum == PyArray_DOUBLE) {\n\t if (l == 1) {\n\t\t*((double *)ret->data) = *((double *)ap2->data) * \\\n\t\t *((double *)ap1->data);\n\t }\n\t else if (ap1->nd < 2 || ap1shape == _column) {\n\t\tcblas_daxpy(l, *((double *)ap2->data), (double *)ap1->data,\n\t\t\t ap1->strides[0] / sizeof(double), \n\t\t\t (double *)ret->data, 1);\n\t }\n\t else {\n\t\tint maxind, oind, i, a1s, rets;\n\t\tchar *ptr, *rptr;\n\t\tdouble val;\n\t\tmaxind = (ap1->dimensions[0] >= ap1->dimensions[1] ? 0 : 1);\n\t\toind = 1-maxind;\n\t\tptr = ap1->data;\n\t\trptr = ret->data;\n\t\tl = ap1->dimensions[maxind];\n\t\tval = *((double *)ap2->data);\n\t\ta1s = ap1->strides[maxind] / sizeof(double);\n\t\trets = ret->strides[maxind] / sizeof(double);\n\t\tfor (i=0; i < ap1->dimensions[oind]; i++) {\n\t\t cblas_daxpy(l, val, (double *)ptr, a1s, \n\t\t\t\t(double *)rptr, rets);\n\t\t ptr += ap1->strides[oind];\n\t\t rptr += ret->strides[oind];\n\t\t}\n\t }\n\t} \n\telse if (typenum == PyArray_CDOUBLE) {\n\t if (l == 1) {\n\t\tcdouble *ptr1, *ptr2, *res;\n\t\tptr1 = (cdouble *)ap2->data;\n\t\tptr2 = (cdouble *)ap1->data;\n\t\tres = (cdouble *)ret->data;\t\t\n\t\tres->real = ptr1->real * ptr2->real - ptr1->imag * ptr2->imag;\n\t\tres->imag = ptr1->real * ptr2->imag + ptr1->imag * ptr2->real;\n\t }\n\t else if (ap1->nd < 2 || ap1shape == _column) {\n\t\tcblas_zaxpy(l, (double *)ap2->data, (double *)ap1->data,\n\t\t\t ap1->strides[0] / sizeof(cdouble), \n\t\t\t (double *)ret->data, 1);\n\t }\n\t else {\n\t\tint maxind, oind, i, a1s, rets;\n\t\tchar *ptr, *rptr;\n\t\tdouble *pval;\n\t\tmaxind = (ap1->dimensions[0] >= ap1->dimensions[1] ? 0 : 1);\n\t\toind = 1-maxind;\n\t\tptr = ap1->data;\n\t\trptr = ret->data;\n\t\tl = ap1->dimensions[maxind];\n\t\tpval = (double *)ap2->data;\n\t\ta1s = ap1->strides[maxind] / sizeof(cdouble);\n\t\trets = ret->strides[maxind] / sizeof(cdouble);\n\t\tfor (i=0; i < ap1->dimensions[oind]; i++) {\n\t\t cblas_zaxpy(l, pval, (double *)ptr, a1s, \n\t\t\t\t(double *)rptr, rets);\n\t\t ptr += ap1->strides[oind];\n\t\t rptr += ret->strides[oind];\n\t\t}\n\t }\n\t}\n\telse if (typenum == PyArray_FLOAT) {\n\t if (l == 1) {\n\t\t*((float *)ret->data) = *((float *)ap2->data) * \\\n\t\t *((float *)ap1->data);\n\t }\n\t else if (ap1->nd < 2 || ap1shape == _column) {\n\t\tcblas_saxpy(l, *((float *)ap2->data), (float *)ap1->data,\n\t\t\t ap1->strides[0] / sizeof(float), \n\t\t\t (float *)ret->data, 1);\n\t }\n\t else {\n\t\tint maxind, oind, i, a1s, rets;\n\t\tchar *ptr, *rptr;\n\t\tfloat val;\n\t\tmaxind = (ap1->dimensions[0] >= ap1->dimensions[1] ? 0 : 1);\n\t\toind = 1-maxind;\n\t\tptr = ap1->data;\n\t\trptr = ret->data;\n\t\tl = ap1->dimensions[maxind];\n\t\tval = *((float *)ap2->data);\n\t\ta1s = ap1->strides[maxind] / sizeof(float);\n\t\trets = ret->strides[maxind] / sizeof(float);\n\t\tfor (i=0; i < ap1->dimensions[oind]; i++) {\n\t\t cblas_saxpy(l, val, (float *)ptr, a1s, \n\t\t\t\t(float *)rptr, rets);\n\t\t ptr += ap1->strides[oind];\n\t\t rptr += ret->strides[oind];\n\t\t}\n\t }\n\t}\n\telse if (typenum == PyArray_CFLOAT) {\n\t if (l == 1) {\n\t\tcfloat *ptr1, *ptr2, *res;\n\t\tptr1 = (cfloat *)ap2->data;\n\t\tptr2 = (cfloat *)ap1->data;\n\t\tres = (cfloat *)ret->data;\t\t\n\t\tres->real = ptr1->real * ptr2->real - ptr1->imag * ptr2->imag;\n\t\tres->imag = ptr1->real * ptr2->imag + ptr1->imag * ptr2->real;\n\t }\n\t else if (ap1->nd < 2 || ap1shape == _column) {\n\t\tcblas_caxpy(l, (float *)ap2->data, (float *)ap1->data,\n\t\t\t ap1->strides[0] / sizeof(cfloat), \n\t\t\t (float *)ret->data, 1);\n\t }\n\t else {\n\t\tint maxind, oind, i, a1s, rets;\n\t\tchar *ptr, *rptr;\n\t\tfloat *pval;\n\t\tmaxind = (ap1->dimensions[0] >= ap1->dimensions[1] ? 0 : 1);\n\t\toind = 1-maxind;\n\t\tptr = ap1->data;\n\t\trptr = ret->data;\n\t\tl = ap1->dimensions[maxind];\n\t\tpval = (float *)ap2->data;\n\t\ta1s = ap1->strides[maxind] / sizeof(cfloat);\n\t\trets = ret->strides[maxind] / sizeof(cfloat);\n\t\tfor (i=0; i < ap1->dimensions[oind]; i++) {\n\t\t cblas_caxpy(l, pval, (float *)ptr, a1s, \n\t\t\t\t(float *)rptr, rets);\n\t\t ptr += ap1->strides[oind];\n\t\t rptr += ret->strides[oind];\n\t\t}\n\t }\n\t}\n }\n else if ((ap2shape == _column) && (ap1shape != _matrix)) {\n\tint ap1s, ap2s;\n\tap2s = ap2->strides[0] / ap2->descr->elsize;\n\tif (ap1shape == _row) {\n\t ap1s = ap1->strides[1] / ap1->descr->elsize;\n\t}\n\telse {\n\t ap1s = ap1->strides[0] / ap1->descr->elsize;\n\t}\n\t \n\t/* Dot product between two vectors -- Level 1 BLAS */\n\tif (typenum == PyArray_DOUBLE) {\n\t double result = cblas_ddot(l, (double *)ap1->data, ap1s, \n\t\t\t\t (double *)ap2->data, ap2s);\n\t *((double *)ret->data) = result;\n\t}\n\telse if (typenum == PyArray_FLOAT) {\n\t float result = cblas_sdot(l, (float *)ap1->data, ap1s, \n\t\t\t\t (float *)ap2->data, ap2s);\n\t *((float *)ret->data) = result;\n\t}\n\telse if (typenum == PyArray_CDOUBLE) {\n\t cblas_zdotu_sub(l, (double *)ap1->data, ap1s, \n\t\t\t (double *)ap2->data, ap2s, (double *)ret->data);\n\t}\n\telse if (typenum == PyArray_CFLOAT) {\n\t cblas_cdotu_sub(l, (float *)ap1->data, ap1s, \n\t\t\t (float *)ap2->data, ap2s, (float *)ret->data);\n\t}\n }\n else if (ap1shape == _matrix && ap2shape != _matrix) {\n\t/* Matrix vector multiplication -- Level 2 BLAS */\n\t/* lda must be MAX(M,1) */\n\tenum CBLAS_ORDER Order;\n\tint ap2s;\n\n\tif (!PyArray_ISONESEGMENT(ap1)) {\n\t PyObject *new;\n\t new = PyArray_Copy(ap1);\n\t Py_DECREF(ap1);\n\t ap1 = (PyArrayObject *)new;\n\t if (new == NULL) goto fail;\n\t}\n\tif (PyArray_ISCONTIGUOUS(ap1)) {\n Order = CblasRowMajor;\n lda = (ap1->dimensions[1] > 1 ? ap1->dimensions[1] : 1);\n\t}\n\telse {\n\t Order = CblasColMajor;\n lda = (ap1->dimensions[0] > 1 ? ap1->dimensions[0] : 1);\n\t}\n\tap2s = ap2->strides[0] / ap2->descr->elsize;\n\tif (typenum == PyArray_DOUBLE) {\n\t cblas_dgemv(Order, CblasNoTrans, \n\t\t\tap1->dimensions[0], ap1->dimensions[1], \n\t\t\t1.0, (double *)ap1->data, lda, \n\t\t\t(double *)ap2->data, ap2s, 0.0, (double *)ret->data, 1);\n\t}\n\telse if (typenum == PyArray_FLOAT) {\n\t cblas_sgemv(Order, CblasNoTrans, \n\t\t\tap1->dimensions[0], ap1->dimensions[1], \n\t\t\t1.0, (float *)ap1->data, lda, \n\t\t\t(float *)ap2->data, ap2s, 0.0, (float *)ret->data, 1);\n\t}\n\telse if (typenum == PyArray_CDOUBLE) {\n\t cblas_zgemv(Order, \n\t\t\tCblasNoTrans, ap1->dimensions[0], ap1->dimensions[1], \n\t\t\toneD, (double *)ap1->data, lda, \n\t\t\t(double *)ap2->data, ap2s, zeroD, \n\t\t\t(double *)ret->data, 1);\n\t}\n\telse if (typenum == PyArray_CFLOAT) {\n\t cblas_cgemv(Order, \n\t\t\tCblasNoTrans, ap1->dimensions[0], ap1->dimensions[1], \n\t\t\toneF, (float *)ap1->data, lda, \n\t\t\t(float *)ap2->data, ap2s, zeroF, \n\t\t\t(float *)ret->data, 1);\n\t}\n }\n else if (ap1shape != _matrix && ap2shape == _matrix) {\n\t/* Vector matrix multiplication -- Level 2 BLAS */\n\tenum CBLAS_ORDER Order;\n\tint ap1s;\n\n\tif (!PyArray_ISONESEGMENT(ap2)) {\n\t PyObject *new;\n\t new = PyArray_Copy(ap2);\n\t Py_DECREF(ap2);\n\t ap2 = (PyArrayObject *)new;\n\t if (new == NULL) goto fail;\n\t}\n\tif (PyArray_ISCONTIGUOUS(ap2)) {\n\t Order = CblasRowMajor;\n lda = (ap2->dimensions[1] > 1 ? ap2->dimensions[1] : 1);\n\t}\n\telse {\n\t Order = CblasColMajor;\n lda = (ap2->dimensions[0] > 1 ? ap2->dimensions[0] : 1);\n\t}\n\tif (ap1shape == _row) {\n\t ap1s = ap1->strides[1] / ap1->descr->elsize;\n\t}\n\telse {\n\t ap1s = ap1->strides[0] / ap1->descr->elsize;\n\t}\n\tif (typenum == PyArray_DOUBLE) {\n\t cblas_dgemv(Order, \n\t\t\tCblasTrans, ap2->dimensions[0], ap2->dimensions[1], \n\t\t\t1.0, (double *)ap2->data, lda,\n\t\t\t(double *)ap1->data, ap1s, 0.0, (double *)ret->data, 1);\n\t}\n\telse if (typenum == PyArray_FLOAT) {\n\t cblas_sgemv(Order,\n\t\t\tCblasTrans, ap2->dimensions[0], ap2->dimensions[1], \n\t\t\t1.0, (float *)ap2->data, lda,\n\t\t\t(float *)ap1->data, ap1s, 0.0, (float *)ret->data, 1);\n\t}\n\telse if (typenum == PyArray_CDOUBLE) {\n\t cblas_zgemv(Order,\n\t\t\tCblasTrans, ap2->dimensions[0], ap2->dimensions[1], \n\t\t\toneD, (double *)ap2->data, lda,\n\t\t\t(double *)ap1->data, ap1s, zeroD, (double *)ret->data, 1);\n\t}\n\telse if (typenum == PyArray_CFLOAT) {\n\t cblas_cgemv(Order,\n\t\t\tCblasTrans, ap2->dimensions[0], ap2->dimensions[1], \n\t\t\toneF, (float *)ap2->data, lda,\n\t\t\t(float *)ap1->data, ap1s, zeroF, (float *)ret->data, 1);\n\t}\n }\n else { /* (ap1->nd == 2 && ap2->nd == 2) */\n\t/* Matrix matrix multiplication -- Level 3 BLAS */ \n\t/* L x M multiplied by M x N */\n\tenum CBLAS_ORDER Order;\n\tenum CBLAS_TRANSPOSE Trans1, Trans2;\n\tint M, N, L;\n\n\t/* Optimization possible: */\n\t/* We may be able to handle single-segment arrays here\n\t using appropriate values of Order, Trans1, and Trans2.\n\t*/\n\t\n \tif (!PyArray_ISCONTIGUOUS(ap2)) {\n\t PyObject *new;\n\t new = PyArray_Copy(ap2);\n\t Py_DECREF(ap2);\n\t ap2 = (PyArrayObject *)new;\n\t if (new == NULL) goto fail;\n\t}\n\tif (!PyArray_ISCONTIGUOUS(ap1)) {\n\t PyObject *new;\n\t new = PyArray_Copy(ap1);\n\t Py_DECREF(ap1);\n\t ap1 = (PyArrayObject *)new;\n\t if (new == NULL) goto fail;\n\t}\n\t\n\tOrder = CblasRowMajor;\n\tTrans1 = CblasNoTrans;\n\tTrans2 = CblasNoTrans;\n\tL = ap1->dimensions[0];\n\tN = ap2->dimensions[1];\n\tM = ap2->dimensions[0];\n\tlda = (ap1->dimensions[1] > 1 ? ap1->dimensions[1] : 1);\n\tldb = (ap2->dimensions[1] > 1 ? ap2->dimensions[1] : 1);\n\tldc = (ret->dimensions[1] > 1 ? ret->dimensions[1] : 1);\t \n\tif (typenum == PyArray_DOUBLE) {\n\t cblas_dgemm(Order, Trans1, Trans2, \n\t\t\tL, N, M,\n\t\t\t1.0, (double *)ap1->data, lda,\n\t\t\t(double *)ap2->data, ldb,\n\t\t\t0.0, (double *)ret->data, ldc);\n\t}\n\telse if (typenum == PyArray_FLOAT) {\n\t cblas_sgemm(Order, Trans1, Trans2,\n\t\t\tL, N, M, \n\t\t\t1.0, (float *)ap1->data, lda,\n\t\t\t(float *)ap2->data, ldb,\n\t\t\t0.0, (float *)ret->data, ldc);\n\t}\n\telse if (typenum == PyArray_CDOUBLE) {\n\t cblas_zgemm(Order, Trans1, Trans2,\n\t\t\tL, N, M, \n\t\t\toneD, (double *)ap1->data, lda,\n\t\t\t(double *)ap2->data, ldb,\n\t\t\tzeroD, (double *)ret->data, ldc);\n\t}\n\telse if (typenum == PyArray_CFLOAT) {\n\t cblas_cgemm(Order, Trans1, Trans2,\n\t\t\tL, N, M,\n\t\t\toneF, (float *)ap1->data, lda,\n\t\t\t(float *)ap2->data, ldb,\n\t\t\tzeroF, (float *)ret->data, ldc);\n\t}\n }\n\n Py_DECREF(ap1);\n Py_DECREF(ap2);\n return PyArray_Return(ret);\n\t\n fail:\n Py_XDECREF(ap1);\n Py_XDECREF(ap2);\n Py_XDECREF(ret);\n return NULL;\n}\n\n\nstatic char doc_innerproduct[] = \"innerproduct(a,b)\\nReturns the inner product of a and b for arrays of floating point types.\\nLike the generic Numeric equivalent the product sum is over\\nthe last dimension of a and b.\\nNB: The first argument is not conjugated.\";\n\nstatic PyObject *\ndotblas_innerproduct(PyObject *dummy, PyObject *args) \n{\n PyObject *op1, *op2;\n PyArrayObject *ap1, *ap2, *ret;\n int j, l, lda, ldb, ldc;\n int typenum, nd;\n intp dimensions[MAX_DIMS];\n static const float oneF[2] = {1.0, 0.0};\n static const float zeroF[2] = {0.0, 0.0};\n static const double oneD[2] = {1.0, 0.0};\n static const double zeroD[2] = {0.0, 0.0};\n PyTypeObject *subtype;\n double prior1, prior2;\n\n if (!PyArg_ParseTuple(args, \"OO\", &op1, &op2)) return NULL;\n\t\n /* \n * Inner product using the BLAS. The product sum is taken along the last\n * dimensions of the two arrays.\n * Only speeds things up for float double and complex types.\n */\n\n\n typenum = PyArray_ObjectType(op1, 0); \n typenum = PyArray_ObjectType(op2, typenum);\n\n /* This function doesn't handle other types */\n if ((typenum != PyArray_DOUBLE && typenum != PyArray_CDOUBLE &&\n\t typenum != PyArray_FLOAT && typenum != PyArray_CFLOAT)) {\n return PyArray_Return((PyArrayObject *)PyArray_InnerProduct(op1, op2));\n }\n\n ret = NULL;\n ap1 = (PyArrayObject *)PyArray_ContiguousFromObject(op1, typenum, 0, 0);\n if (ap1 == NULL) return NULL;\n ap2 = (PyArrayObject *)PyArray_ContiguousFromObject(op2, typenum, 0, 0);\n if (ap2 == NULL) goto fail;\n\n if ((ap1->nd > 2) || (ap2->nd > 2)) { \n\t/* This function doesn't handle dimensions greater than 2 -- other\n\t than to ensure the dot function is altered\n\t*/\n\tif (!altered) {\n\t /* need to alter dot product */\n\t PyObject *tmp1, *tmp2;\n\t tmp1 = PyTuple_New(0);\n\t tmp2 = dotblas_alterdot(NULL, tmp1);\n\t Py_DECREF(tmp1); \n\t Py_DECREF(tmp2);\n\t}\n\tret = (PyArrayObject *)PyArray_InnerProduct((PyObject *)ap1, \n\t\t\t\t\t\t (PyObject *)ap2);\n\tPy_DECREF(ap1); \n\tPy_DECREF(ap2);\n\treturn PyArray_Return(ret);\n }\n\n if (ap1->nd == 0 || ap2->nd == 0) {\n\t/* One of ap1 or ap2 is a scalar */\n\tif (ap1->nd == 0) {\t\t/* Make ap2 the scalar */\n\t PyArrayObject *t = ap1;\n\t ap1 = ap2;\n\t ap2 = t;\n\t}\n\tfor (l = 1, j = 0; j < ap1->nd; j++) {\n\t dimensions[j] = ap1->dimensions[j];\n\t l *= dimensions[j];\n\t}\n\tnd = ap1->nd;\n }\n else { /* (ap1->nd <= 2 && ap2->nd <= 2) */\n\t/* Both ap1 and ap2 are vectors or matrices */\n\tl = ap1->dimensions[ap1->nd-1];\n\t\n\tif (ap2->dimensions[ap2->nd-1] != l) {\n\t PyErr_SetString(PyExc_ValueError, \"matrices are not aligned\");\n\t goto fail;\n\t}\n\tnd = ap1->nd+ap2->nd-2;\n \n\tif (nd == 1) \n\t dimensions[0] = (ap1->nd == 2) ? ap1->dimensions[0] : ap2->dimensions[0];\n\telse if (nd == 2) {\n\t dimensions[0] = ap1->dimensions[0];\n\t dimensions[1] = ap2->dimensions[0];\n\t}\n }\n\n /* Choose which subtype to return */\n prior2 = PyArray_GetPriority((PyObject *)ap2, 0.0);\n prior1 = PyArray_GetPriority((PyObject *)ap1, 0.0);\n subtype = (prior2 > prior1 ? ap2->ob_type : ap1->ob_type);\n \n ret = (PyArrayObject *)PyArray_New(subtype, nd, dimensions, \n\t\t\t\t typenum, NULL, NULL, 0, 0, \n\t\t\t\t (PyObject *)\\\n\t\t\t\t (prior2 > prior1 ? ap2 : ap1));\n \n if (ret == NULL) goto fail;\n memset(ret->data, 0, PyArray_NBYTES(ret));\n\n if (ap2->nd == 0) {\n\t/* Multiplication by a scalar -- Level 1 BLAS */\n\tif (typenum == PyArray_DOUBLE) {\n\t cblas_daxpy(l, *((double *)ap2->data), (double *)ap1->data, 1,\n\t\t\t(double *)ret->data, 1);\n\t} \n\telse if (typenum == PyArray_CDOUBLE) {\n\t cblas_zaxpy(l, (double *)ap2->data, (double *)ap1->data, 1,\n\t\t\t(double *)ret->data, 1);\n\t}\n\telse if (typenum == PyArray_FLOAT) {\n\t cblas_saxpy(l, *((float *)ap2->data), (float *)ap1->data, 1,\n\t\t\t(float *)ret->data, 1);\n\t}\n\telse if (typenum == PyArray_CFLOAT) {\n\t cblas_caxpy(l, (float *)ap2->data, (float *)ap1->data, 1,\n\t\t\t(float *)ret->data, 1);\n\t}\n }\n else if (ap1->nd == 1 && ap2->nd == 1) {\n\t/* Dot product between two vectors -- Level 1 BLAS */\n\tif (typenum == PyArray_DOUBLE) {\n\t double result = cblas_ddot(l, (double *)ap1->data, 1, \n\t\t\t\t (double *)ap2->data, 1);\n\t *((double *)ret->data) = result;\n\t}\n\telse if (typenum == PyArray_CDOUBLE) {\n\t cblas_zdotu_sub(l, (double *)ap1->data, 1, \n\t\t\t (double *)ap2->data, 1, (double *)ret->data);\n\t}\n\telse if (typenum == PyArray_FLOAT) {\n\t float result = cblas_sdot(l, (float *)ap1->data, 1, \n\t\t\t\t (float *)ap2->data, 1);\n\t *((float *)ret->data) = result;\n\t}\n\telse if (typenum == PyArray_CFLOAT) {\n\t cblas_cdotu_sub(l, (float *)ap1->data, 1, \n\t\t\t (float *)ap2->data, 1, (float *)ret->data);\n\t}\n }\n else if (ap1->nd == 2 && ap2->nd == 1) {\n\t/* Matrix-vector multiplication -- Level 2 BLAS */\n\tlda = (ap1->dimensions[1] > 1 ? ap1->dimensions[1] : 1);\n\tif (typenum == PyArray_DOUBLE) {\n\t cblas_dgemv(CblasRowMajor, \n\t\t\tCblasNoTrans, ap1->dimensions[0], ap1->dimensions[1], \n\t\t\t1.0, (double *)ap1->data, lda,\n\t\t\t(double *)ap2->data, 1, 0.0, (double *)ret->data, 1);\n\t}\n\telse if (typenum == PyArray_CDOUBLE) {\n\t cblas_zgemv(CblasRowMajor, \n\t\t\tCblasNoTrans, ap1->dimensions[0], ap1->dimensions[1], \n\t\t\toneD, (double *)ap1->data, lda,\n\t\t\t(double *)ap2->data, 1, zeroD, (double *)ret->data, 1);\n\t}\n\telse if (typenum == PyArray_FLOAT) {\n\t cblas_sgemv(CblasRowMajor, \n\t\t\tCblasNoTrans, ap1->dimensions[0], ap1->dimensions[1], \n\t\t\t1.0, (float *)ap1->data, lda,\n\t\t\t(float *)ap2->data, 1, 0.0, (float *)ret->data, 1);\n\t}\n\telse if (typenum == PyArray_CFLOAT) {\n\t cblas_cgemv(CblasRowMajor, \n\t\t\tCblasNoTrans, ap1->dimensions[0], ap1->dimensions[1], \n\t\t\toneF, (float *)ap1->data, lda,\n\t\t\t(float *)ap2->data, 1, zeroF, (float *)ret->data, 1);\n\t}\n }\n else if (ap1->nd == 1 && ap2->nd == 2) {\n\t/* Vector matrix multiplication -- Level 2 BLAS */\n\tlda = (ap2->dimensions[1] > 1 ? ap2->dimensions[1] : 1);\n\tif (typenum == PyArray_DOUBLE) {\n\t cblas_dgemv(CblasRowMajor, \n\t\t\tCblasNoTrans, ap2->dimensions[0], ap2->dimensions[1], \n\t\t\t1.0, (double *)ap2->data, lda,\n\t\t\t(double *)ap1->data, 1, 0.0, (double *)ret->data, 1);\n\t}\n\telse if (typenum == PyArray_CDOUBLE) {\n\t cblas_zgemv(CblasRowMajor, \n\t\t\tCblasNoTrans, ap2->dimensions[0], ap2->dimensions[1], \n\t\t\toneD, (double *)ap2->data, lda,\n\t\t\t(double *)ap1->data, 1, zeroD, (double *)ret->data, 1);\n\t}\n\telse if (typenum == PyArray_FLOAT) {\n\t cblas_sgemv(CblasRowMajor, \n\t\t\tCblasNoTrans, ap2->dimensions[0], ap2->dimensions[1], \n\t\t\t1.0, (float *)ap2->data, lda,\n\t\t\t(float *)ap1->data, 1, 0.0, (float *)ret->data, 1);\n\t}\n\telse if (typenum == PyArray_CFLOAT) {\n\t cblas_cgemv(CblasRowMajor, \n\t\t\tCblasNoTrans, ap2->dimensions[0], ap2->dimensions[1], \n\t\t\toneF, (float *)ap2->data, lda,\n\t\t\t(float *)ap1->data, 1, zeroF, (float *)ret->data, 1);\n\t}\n }\n else { /* (ap1->nd == 2 && ap2->nd == 2) */ \n\t/* Matrix matrix multiplication -- Level 3 BLAS */ \n\tlda = (ap1->dimensions[1] > 1 ? ap1->dimensions[1] : 1);\n\tldb = (ap2->dimensions[1] > 1 ? ap2->dimensions[1] : 1);\n\tldc = (ret->dimensions[1] > 1 ? ret->dimensions[1] : 1);\n\tif (typenum == PyArray_DOUBLE) {\n\t cblas_dgemm(CblasRowMajor, CblasNoTrans, CblasTrans,\n\t\t\tap1->dimensions[0], ap2->dimensions[0], ap1->dimensions[1],\n\t\t\t1.0, (double *)ap1->data, lda,\n\t\t\t(double *)ap2->data, ldb,\n\t\t\t0.0, (double *)ret->data, ldc);\n\t}\n\telse if (typenum == PyArray_FLOAT) {\n\t cblas_sgemm(CblasRowMajor, CblasNoTrans, CblasTrans,\n\t\t\tap1->dimensions[0], ap2->dimensions[0], ap1->dimensions[1],\n\t\t\t1.0, (float *)ap1->data, lda,\n\t\t\t(float *)ap2->data, ldb,\n\t\t\t0.0, (float *)ret->data, ldc);\n\t}\n\telse if (typenum == PyArray_CDOUBLE) {\n\t cblas_zgemm(CblasRowMajor, CblasNoTrans, CblasTrans,\n\t\t\tap1->dimensions[0], ap2->dimensions[0], ap1->dimensions[1],\n\t\t\toneD, (double *)ap1->data, lda,\n\t\t\t(double *)ap2->data, ldb,\n\t\t\tzeroD, (double *)ret->data, ldc);\n\t}\n\telse if (typenum == PyArray_CFLOAT) {\n\t cblas_cgemm(CblasRowMajor, CblasNoTrans, CblasTrans,\n\t\t\tap1->dimensions[0], ap2->dimensions[0], ap1->dimensions[1],\n\t\t\toneF, (float *)ap1->data, lda,\n\t\t\t(float *)ap2->data, ldb,\n\t\t\tzeroF, (float *)ret->data, ldc);\n\t}\n }\n Py_DECREF(ap1);\n Py_DECREF(ap2);\n return PyArray_Return(ret);\n\t\n fail:\n Py_XDECREF(ap1);\n Py_XDECREF(ap2);\n Py_XDECREF(ret);\n return NULL;\n}\n\n\nstatic char doc_vdot[] = \"vdot(a,b)\\nReturns the dot product of a and b for scalars and vectors\\nof floating point and complex types. The first argument, a, is conjugated.\";\n\n\nstatic PyObject *dotblas_vdot(PyObject *dummy, PyObject *args) {\n PyObject *op1, *op2;\n PyArrayObject *ap1=NULL, *ap2=NULL, *ret=NULL;\n int l;\n int typenum;\n intp dimensions[MAX_DIMS];\n PyArray_Descr *type;\n\n if (!PyArg_ParseTuple(args, \"OO\", &op1, &op2)) return NULL;\n\t\n /* \n * Conjugating dot product using the BLAS for vectors.\n * Multiplies op1 and op2, each of which must be vector.\n */\n\n typenum = PyArray_ObjectType(op1, 0); \n typenum = PyArray_ObjectType(op2, typenum);\n \n type = PyArray_DescrFromType(typenum);\n \n ap1 = (PyArrayObject *)PyArray_FromAny(op1, type, 0, 0, 0, NULL);\n if (ap1==NULL) goto fail;\n op1 = PyArray_Flatten(ap1, 0);\n if (op1==NULL) goto fail;\n Py_DECREF(ap1);\n ap1 = (PyArrayObject *)op1;\n \n ap2 = (PyArrayObject *)PyArray_FromAny(op2, type, 0, 0, 0, NULL);\n if (ap2==NULL) goto fail;\n op2 = PyArray_Flatten(ap2, 0);\n if (op2 == NULL) goto fail;\n Py_DECREF(ap2);\n ap2 = (PyArrayObject *)op2;\n \n if (typenum != PyArray_FLOAT && typenum != PyArray_DOUBLE &&\n\ttypenum != PyArray_CFLOAT && typenum != PyArray_CDOUBLE) {\n\tif (!altered) {\n\t /* need to alter dot product */\n\t PyObject *tmp1, *tmp2;\n\t tmp1 = PyTuple_New(0);\n\t tmp2 = dotblas_alterdot(NULL, tmp1);\n\t Py_DECREF(tmp1); \n\t Py_DECREF(tmp2);\n\t}\n\tif (PyTypeNum_ISCOMPLEX(typenum)) {\n\t op1 = PyArray_Conjugate(ap1);\n\t if (op1==NULL) goto fail;\n\t Py_DECREF(ap1);\n\t ap1 = (PyArrayObject *)op1;\n\t}\t\n\tret = (PyArrayObject *)PyArray_InnerProduct((PyObject *)ap1, \n\t\t\t\t\t\t (PyObject *)ap2);\n\tPy_DECREF(ap1); \n\tPy_DECREF(ap2);\n\treturn PyArray_Return(ret);\n }\n\n if (ap2->dimensions[0] != ap1->dimensions[ap1->nd-1]) {\n\tPyErr_SetString(PyExc_ValueError, \"vectors have different lengths\");\n\tgoto fail;\n }\n l = ap1->dimensions[ap1->nd-1];\n \n ret = (PyArrayObject *)PyArray_SimpleNew(0, dimensions, typenum);\n if (ret == NULL) goto fail;\n\n\n /* Dot product between two vectors -- Level 1 BLAS */\n if (typenum == PyArray_DOUBLE) {\n\t*((double *)ret->data) = cblas_ddot(l, (double *)ap1->data, 1, \n\t\t\t\t\t (double *)ap2->data, 1);\n }\n else if (typenum == PyArray_FLOAT) {\n\t*((float *)ret->data) = cblas_sdot(l, (float *)ap1->data, 1, \n\t\t\t\t\t (float *)ap2->data, 1);\n }\n else if (typenum == PyArray_CDOUBLE) {\n\tcblas_zdotc_sub(l, (double *)ap1->data, 1, \n\t\t\t(double *)ap2->data, 1, (double *)ret->data);\n }\n else if (typenum == PyArray_CFLOAT) {\n\tcblas_cdotc_sub(l, (float *)ap1->data, 1, \n\t\t\t(float *)ap2->data, 1, (float *)ret->data);\n }\n\n Py_DECREF(ap1);\n Py_DECREF(ap2);\n return PyArray_Return(ret);\n\t\n fail:\n Py_XDECREF(ap1);\n Py_XDECREF(ap2);\n Py_XDECREF(ret);\n return NULL;\n}\n\nstatic struct PyMethodDef dotblas_module_methods[] = {\n {\"dot\", (PyCFunction)dotblas_matrixproduct, 1, doc_matrixproduct},\n {\"inner\", (PyCFunction)dotblas_innerproduct, 1, doc_innerproduct},\n {\"vdot\", (PyCFunction)dotblas_vdot, 1, doc_vdot},\n {\"alterdot\", (PyCFunction)dotblas_alterdot, 1, doc_alterdot},\n {\"restoredot\", (PyCFunction)dotblas_restoredot, 1, doc_restoredot},\n {NULL,\t\tNULL, 0}\t\t/* sentinel */\n};\n\n/* Initialization function for the module */\nDL_EXPORT(void) init_dotblas(void) {\n int i;\n PyObject *m, *d, *s;\n \n /* Create the module and add the functions */\n m = Py_InitModule3(\"_dotblas\", dotblas_module_methods, module_doc);\n\n /* Import the array object */\n import_array();\n\n /* Initialise the array of dot functions */\n for (i = 0; i < PyArray_NTYPES; i++)\n\toldFunctions[i] = NULL;\n\n /* alterdot at load */\n d = PyTuple_New(0);\n s = dotblas_alterdot(NULL, d);\n Py_DECREF(d);\n Py_DECREF(s);\n \n}\n", + "methods": [ + { + "name": "FLOAT_dot", + "long_name": "FLOAT_dot( * a , intp stridea , * b , intp strideb , * res , intp n , * tmp)", + "filename": "_dotblas.c", + "nloc": 7, + "complexity": 1, + "token_count": 84, + "parameters": [ + "a", + "stridea", + "b", + "strideb", + "res", + "n", + "tmp" + ], + "start_line": 14, + "end_line": 21, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 8, + "top_nesting_level": 0 + }, + { + "name": "DOUBLE_dot", + "long_name": "DOUBLE_dot( * a , intp stridea , * b , intp strideb , * res , intp n , * tmp)", + "filename": "_dotblas.c", + "nloc": 7, + "complexity": 1, + "token_count": 84, + "parameters": [ + "a", + "stridea", + "b", + "strideb", + "res", + "n", + "tmp" + ], + "start_line": 24, + "end_line": 31, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 8, + "top_nesting_level": 0 + }, + { + "name": "CFLOAT_dot", + "long_name": "CFLOAT_dot( * a , intp stridea , * b , intp strideb , * res , intp n , * tmp)", + "filename": "_dotblas.c", + "nloc": 7, + "complexity": 1, + "token_count": 81, + "parameters": [ + "a", + "stridea", + "b", + "strideb", + "res", + "n", + "tmp" + ], + "start_line": 34, + "end_line": 42, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 9, + "top_nesting_level": 0 + }, + { + "name": "CDOUBLE_dot", + "long_name": "CDOUBLE_dot( * a , intp stridea , * b , intp strideb , * res , intp n , * tmp)", + "filename": "_dotblas.c", + "nloc": 7, + "complexity": 1, + "token_count": 81, + "parameters": [ + "a", + "stridea", + "b", + "strideb", + "res", + "n", + "tmp" + ], + "start_line": 45, + "end_line": 52, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 8, + "top_nesting_level": 0 + }, + { + "name": "dotblas_alterdot", + "long_name": "dotblas_alterdot( PyObject * dummy , PyObject * args)", + "filename": "_dotblas.c", + "nloc": 22, + "complexity": 3, + "token_count": 168, + "parameters": [ + "dummy", + "args" + ], + "start_line": 61, + "end_line": 91, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 31, + "top_nesting_level": 0 + }, + { + "name": "dotblas_restoredot", + "long_name": "dotblas_restoredot( PyObject * dummy , PyObject * args)", + "filename": "_dotblas.c", + "nloc": 26, + "complexity": 3, + "token_count": 167, + "parameters": [ + "dummy", + "args" + ], + "start_line": 96, + "end_line": 128, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 33, + "top_nesting_level": 0 + }, + { + "name": "_select_matrix_shape", + "long_name": "_select_matrix_shape( PyArrayObject * array)", + "filename": "_dotblas.c", + "nloc": 22, + "complexity": 8, + "token_count": 96, + "parameters": [ + "array" + ], + "start_line": 133, + "end_line": 154, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 22, + "top_nesting_level": 0 + }, + { + "name": "dotblas_matrixproduct", + "long_name": "dotblas_matrixproduct( PyObject * dummy , PyObject * args)", + "filename": "_dotblas.c", + "nloc": 412, + "complexity": 93, + "token_count": 3563, + "parameters": [ + "dummy", + "args" + ], + "start_line": 160, + "end_line": 623, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 464, + "top_nesting_level": 0 + }, + { + "name": "dotblas_innerproduct", + "long_name": "dotblas_innerproduct( PyObject * dummy , PyObject * args)", + "filename": "_dotblas.c", + "nloc": 208, + "complexity": 54, + "token_count": 2023, + "parameters": [ + "dummy", + "args" + ], + "start_line": 629, + "end_line": 869, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 241, + "top_nesting_level": 0 + }, + { + "name": "dotblas_vdot", + "long_name": "dotblas_vdot( PyObject * dummy , PyObject * args)", + "filename": "_dotblas.c", + "nloc": 76, + "complexity": 19, + "token_count": 630, + "parameters": [ + "dummy", + "args" + ], + "start_line": 875, + "end_line": 969, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 95, + "top_nesting_level": 0 + }, + { + "name": "init_dotblas", + "long_name": "init_dotblas()", + "filename": "_dotblas.c", + "nloc": 12, + "complexity": 2, + "token_count": 79, + "parameters": [], + "start_line": 981, + "end_line": 1001, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 21, + "top_nesting_level": 0 + } + ], + "methods_before": [ + { + "name": "FLOAT_dot", + "long_name": "FLOAT_dot( * a , intp stridea , * b , intp strideb , * res , intp n , * tmp)", + "filename": "_dotblas.c", + "nloc": 7, + "complexity": 1, + "token_count": 84, + "parameters": [ + "a", + "stridea", + "b", + "strideb", + "res", + "n", + "tmp" + ], + "start_line": 14, + "end_line": 21, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 8, + "top_nesting_level": 0 + }, + { + "name": "DOUBLE_dot", + "long_name": "DOUBLE_dot( * a , intp stridea , * b , intp strideb , * res , intp n , * tmp)", + "filename": "_dotblas.c", + "nloc": 7, + "complexity": 1, + "token_count": 84, + "parameters": [ + "a", + "stridea", + "b", + "strideb", + "res", + "n", + "tmp" + ], + "start_line": 24, + "end_line": 31, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 8, + "top_nesting_level": 0 + }, + { + "name": "CFLOAT_dot", + "long_name": "CFLOAT_dot( * a , intp stridea , * b , intp strideb , * res , intp n , * tmp)", + "filename": "_dotblas.c", + "nloc": 7, + "complexity": 1, + "token_count": 81, + "parameters": [ + "a", + "stridea", + "b", + "strideb", + "res", + "n", + "tmp" + ], + "start_line": 34, + "end_line": 42, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 9, + "top_nesting_level": 0 + }, + { + "name": "CDOUBLE_dot", + "long_name": "CDOUBLE_dot( * a , intp stridea , * b , intp strideb , * res , intp n , * tmp)", + "filename": "_dotblas.c", + "nloc": 7, + "complexity": 1, + "token_count": 81, + "parameters": [ + "a", + "stridea", + "b", + "strideb", + "res", + "n", + "tmp" + ], + "start_line": 45, + "end_line": 52, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 8, + "top_nesting_level": 0 + }, + { + "name": "dotblas_alterdot", + "long_name": "dotblas_alterdot( PyObject * dummy , PyObject * args)", + "filename": "_dotblas.c", + "nloc": 22, + "complexity": 3, + "token_count": 168, + "parameters": [ + "dummy", + "args" + ], + "start_line": 61, + "end_line": 91, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 31, + "top_nesting_level": 0 + }, + { + "name": "dotblas_restoredot", + "long_name": "dotblas_restoredot( PyObject * dummy , PyObject * args)", + "filename": "_dotblas.c", + "nloc": 26, + "complexity": 3, + "token_count": 167, + "parameters": [ + "dummy", + "args" + ], + "start_line": 96, + "end_line": 128, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 33, + "top_nesting_level": 0 + }, + { + "name": "_select_matrix_shape", + "long_name": "_select_matrix_shape( PyArrayObject * array)", + "filename": "_dotblas.c", + "nloc": 22, + "complexity": 8, + "token_count": 96, + "parameters": [ + "array" + ], + "start_line": 133, + "end_line": 154, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 22, + "top_nesting_level": 0 + }, + { + "name": "dotblas_matrixproduct", + "long_name": "dotblas_matrixproduct( PyObject * dummy , PyObject * args)", + "filename": "_dotblas.c", + "nloc": 412, + "complexity": 92, + "token_count": 3557, + "parameters": [ + "dummy", + "args" + ], + "start_line": 160, + "end_line": 620, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 461, + "top_nesting_level": 0 + }, + { + "name": "dotblas_innerproduct", + "long_name": "dotblas_innerproduct( PyObject * dummy , PyObject * args)", + "filename": "_dotblas.c", + "nloc": 208, + "complexity": 54, + "token_count": 2023, + "parameters": [ + "dummy", + "args" + ], + "start_line": 626, + "end_line": 866, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 241, + "top_nesting_level": 0 + }, + { + "name": "dotblas_vdot", + "long_name": "dotblas_vdot( PyObject * dummy , PyObject * args)", + "filename": "_dotblas.c", + "nloc": 76, + "complexity": 19, + "token_count": 630, + "parameters": [ + "dummy", + "args" + ], + "start_line": 872, + "end_line": 966, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 95, + "top_nesting_level": 0 + }, + { + "name": "init_dotblas", + "long_name": "init_dotblas()", + "filename": "_dotblas.c", + "nloc": 12, + "complexity": 2, + "token_count": 79, + "parameters": [], + "start_line": 978, + "end_line": 998, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 21, + "top_nesting_level": 0 + } + ], + "changed_methods": [ + { + "name": "dotblas_matrixproduct", + "long_name": "dotblas_matrixproduct( PyObject * dummy , PyObject * args)", + "filename": "_dotblas.c", + "nloc": 412, + "complexity": 93, + "token_count": 3563, + "parameters": [ + "dummy", + "args" + ], + "start_line": 160, + "end_line": 623, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 464, + "top_nesting_level": 0 + } + ], + "nloc": 837, + "complexity": 186, + "token_count": 7251, + "diff_parsed": { + "added": [ + "\t/* Fix it so that dot(shape=(N,1), shape=(1,))", + "\t returns an (N,) array (but uses the fast scalar code)", + "\t*/", + "\tif (ap1shape == _column && ap2->nd == 1) nd = 1;" + ], + "deleted": [ + "\tif (ap1shape == _column) nd = 1;" + ] + } + } + ] + }, + { + "hash": "c0d68f47a04c22d1e9de64b8d09d43fb1b72fc63", + "msg": "Fix the dot(shape=(1,), shape=(1,N)) case too", + "author": { + "name": "Travis Oliphant", + "email": "oliphant@enthought.com" + }, + "committer": { + "name": "Travis Oliphant", + "email": "oliphant@enthought.com" + }, + "author_date": "2006-01-29T03:50:48+00:00", + "author_timezone": 0, + "committer_date": "2006-01-29T03:50:48+00:00", + "committer_timezone": 0, + "branches": [ + "main" + ], + "in_main_branch": true, + "merge": false, + "parents": [ + "bbca1e38ad33e95145c7e96229a3a5b6d012231f" + ], + "project_name": "repo_copy", + "project_path": "/tmp/tmppy2o86q9/repo_copy", + "deletions": 18, + "insertions": 39, + "lines": 57, + "files": 2, + "dmm_unit_size": 0.3333333333333333, + "dmm_unit_complexity": 0.3333333333333333, + "dmm_unit_interfacing": 1.0, + "modified_files": [ + { + "old_path": "numpy/core/blasdot/_dotblas.c", + "new_path": "numpy/core/blasdot/_dotblas.c", + "filename": "_dotblas.c", + "extension": "c", + "change_type": "MODIFY", + "diff": "@@ -163,6 +163,7 @@ dotblas_matrixproduct(PyObject *dummy, PyObject *args)\n PyArrayObject *ap1, *ap2, *ret;\n int j, l, lda, ldb, ldc;\n int typenum, nd;\n+ intp ap1stride;\n intp dimensions[MAX_DIMS];\n static const float oneF[2] = {1.0, 0.0};\n static const float zeroF[2] = {0.0, 0.0};\n@@ -229,13 +230,29 @@ dotblas_matrixproduct(PyObject *dummy, PyObject *args)\n \t ap2shape = _scalar;\n \t}\n \t/* Fix it so that dot(shape=(N,1), shape=(1,))\n-\t returns an (N,) array (but uses the fast scalar code)\n+\t and dot(shape=(1,), shape=(1,N)) both return\n+\t an (N,) array (but use the fast scalar code)\n \t*/\n-\tif (ap1shape == _column && ap2->nd == 1) nd = 1;\n-\telse nd = ap1->nd;\n-\tfor (l = 1, j = 0; j < nd; j++) {\n-\t dimensions[j] = ap1->dimensions[j];\n-\t l *= dimensions[j];\n+\tif ((ap1shape == _column || ap1shape == _row) && \\\n+\t (ap2->nd == 1)) {\n+\t nd = 1;\n+\t if (ap1shape == _column) {\n+\t\tdimensions[0] = ap1->dimensions[0];\n+\t\tap1stride = ap1->strides[0] / sizeof(double);\n+\t }\n+\t else {\n+\t\tdimensions[0] = ap1->dimensions[1];\n+\t\tap1stride = ap1->strides[1] / sizeof(double);\n+\t }\n+\t l = dimensions[0];\n+\t}\n+\telse {\n+\t ap1stride = ap1->strides[0] / sizeof(double);\n+\t nd = ap1->nd;\n+\t for (l = 1, j = 0; j < nd; j++) {\n+\t\tdimensions[j] = ap1->dimensions[j];\n+\t\tl *= dimensions[j];\n+\t }\n \t}\n }\n else { /* (ap1->nd <= 2 && ap2->nd <= 2) */\n@@ -291,10 +308,9 @@ dotblas_matrixproduct(PyObject *dummy, PyObject *args)\n \t\t*((double *)ret->data) = *((double *)ap2->data) * \\\n \t\t *((double *)ap1->data);\n \t }\n-\t else if (ap1->nd < 2 || ap1shape == _column) {\n+\t else if (ap1shape != _matrix) {\n \t\tcblas_daxpy(l, *((double *)ap2->data), (double *)ap1->data,\n-\t\t\t ap1->strides[0] / sizeof(double), \n-\t\t\t (double *)ret->data, 1);\n+\t\t\t ap1stride, (double *)ret->data, 1);\n \t }\n \t else {\n \t\tint maxind, oind, i, a1s, rets;\n@@ -325,10 +341,9 @@ dotblas_matrixproduct(PyObject *dummy, PyObject *args)\n \t\tres->real = ptr1->real * ptr2->real - ptr1->imag * ptr2->imag;\n \t\tres->imag = ptr1->real * ptr2->imag + ptr1->imag * ptr2->real;\n \t }\n-\t else if (ap1->nd < 2 || ap1shape == _column) {\n+\t else if (ap1shape != _matrix) {\n \t\tcblas_zaxpy(l, (double *)ap2->data, (double *)ap1->data,\n-\t\t\t ap1->strides[0] / sizeof(cdouble), \n-\t\t\t (double *)ret->data, 1);\n+\t\t\t ap1stride, (double *)ret->data, 1);\n \t }\n \t else {\n \t\tint maxind, oind, i, a1s, rets;\n@@ -355,10 +370,9 @@ dotblas_matrixproduct(PyObject *dummy, PyObject *args)\n \t\t*((float *)ret->data) = *((float *)ap2->data) * \\\n \t\t *((float *)ap1->data);\n \t }\n-\t else if (ap1->nd < 2 || ap1shape == _column) {\n+\t else if (ap1shape != _matrix) {\n \t\tcblas_saxpy(l, *((float *)ap2->data), (float *)ap1->data,\n-\t\t\t ap1->strides[0] / sizeof(float), \n-\t\t\t (float *)ret->data, 1);\n+\t\t\t ap1stride, (float *)ret->data, 1);\n \t }\n \t else {\n \t\tint maxind, oind, i, a1s, rets;\n@@ -389,10 +403,9 @@ dotblas_matrixproduct(PyObject *dummy, PyObject *args)\n \t\tres->real = ptr1->real * ptr2->real - ptr1->imag * ptr2->imag;\n \t\tres->imag = ptr1->real * ptr2->imag + ptr1->imag * ptr2->real;\n \t }\n-\t else if (ap1->nd < 2 || ap1shape == _column) {\n+\t else if (ap1shape != _matrix) {\n \t\tcblas_caxpy(l, (float *)ap2->data, (float *)ap1->data,\n-\t\t\t ap1->strides[0] / sizeof(cfloat), \n-\t\t\t (float *)ret->data, 1);\n+\t\t\t ap1stride, (float *)ret->data, 1);\n \t }\n \t else {\n \t\tint maxind, oind, i, a1s, rets;\n", + "added_lines": 31, + "deleted_lines": 18, + "source_code": "static char module_doc[] =\n\"This module provides a BLAS optimized\\nmatrix multiply, inner product and dot for numpy arrays\";\n\n#include \"Python.h\"\n#include \"numpy/arrayobject.h\"\n#ifndef CBLAS_HEADER\n#define CBLAS_HEADER \"cblas.h\"\n#endif\n#include CBLAS_HEADER\n\n#include \n\nstatic void \nFLOAT_dot(void *a, intp stridea, void *b, intp strideb, void *res, \n\t intp n, void *tmp)\n{\n register int na = stridea / sizeof(float);\n register int nb = strideb / sizeof(float);\n\n *((float *)res) = cblas_sdot((int)n, (float *)a, na, (float *)b, nb);\n}\n\nstatic void \nDOUBLE_dot(void *a, intp stridea, void *b, intp strideb, void *res, \n\t intp n, void *tmp)\n{\n register int na = stridea / sizeof(double);\n register int nb = strideb / sizeof(double);\n\n *((double *)res) = cblas_ddot((int)n, (double *)a, na, (double *)b, nb);\n}\n\nstatic void \nCFLOAT_dot(void *a, intp stridea, void *b, intp strideb, void *res, \n\t intp n, void *tmp)\n{\n \n register int na = stridea / sizeof(cfloat);\n register int nb = strideb / sizeof(cfloat);\n\n cblas_cdotu_sub((int)n, (float *)a, na, (float *)b, nb, (float *)res);\n}\n\nstatic void \nCDOUBLE_dot(void *a, intp stridea, void *b, intp strideb, void *res, \n\t intp n, void *tmp)\n{\n register int na = stridea / sizeof(cdouble);\n register int nb = strideb / sizeof(cdouble);\n\n cblas_zdotu_sub((int)n, (double *)a, na, (double *)b, nb, (double *)res);\n}\n\n\nstatic PyArray_DotFunc *oldFunctions[PyArray_NTYPES];\nstatic Bool altered=FALSE;\n\nstatic char doc_alterdot[] = \"alterdot() changes all dot functions to use blas.\";\n\nstatic PyObject *\ndotblas_alterdot(PyObject *dummy, PyObject *args) \n{\n PyArray_Descr *descr;\n \n if (!PyArg_ParseTuple(args, \"\")) return NULL;\n\n /* Replace the dot functions to the ones using blas */\n\n if (!altered) {\n\tdescr = PyArray_DescrFromType(PyArray_FLOAT);\n\toldFunctions[PyArray_FLOAT] = descr->f->dotfunc;\n\tdescr->f->dotfunc = (PyArray_DotFunc *)FLOAT_dot;\n\t\n\tdescr = PyArray_DescrFromType(PyArray_DOUBLE);\n\toldFunctions[PyArray_DOUBLE] = descr->f->dotfunc;\n\tdescr->f->dotfunc = (PyArray_DotFunc *)DOUBLE_dot;\n\t\n\tdescr = PyArray_DescrFromType(PyArray_CFLOAT);\n\toldFunctions[PyArray_CFLOAT] = descr->f->dotfunc;\n\tdescr->f->dotfunc = (PyArray_DotFunc *)CFLOAT_dot;\n\t\n\tdescr = PyArray_DescrFromType(PyArray_CDOUBLE);\n\toldFunctions[PyArray_CDOUBLE] = descr->f->dotfunc;\n\tdescr->f->dotfunc = (PyArray_DotFunc *)CDOUBLE_dot;\n\n\taltered = TRUE;\n }\n\n Py_INCREF(Py_None);\n return Py_None;\n}\n\nstatic char doc_restoredot[] = \"restoredot() restores dots to defaults.\";\n\nstatic PyObject *\ndotblas_restoredot(PyObject *dummy, PyObject *args) \n{\n PyArray_Descr *descr;\n\n if (!PyArg_ParseTuple(args, \"\")) return NULL;\n\n if (altered) {\n\tdescr = PyArray_DescrFromType(PyArray_FLOAT);\n\tdescr->f->dotfunc = oldFunctions[PyArray_FLOAT];\n\toldFunctions[PyArray_FLOAT] = NULL;\n\tPy_XDECREF(descr);\n\n\tdescr = PyArray_DescrFromType(PyArray_DOUBLE);\n\tdescr->f->dotfunc = oldFunctions[PyArray_DOUBLE];\n\toldFunctions[PyArray_DOUBLE] = NULL;\n\tPy_XDECREF(descr);\n\n\tdescr = PyArray_DescrFromType(PyArray_CFLOAT);\n\tdescr->f->dotfunc = oldFunctions[PyArray_CFLOAT];\n\toldFunctions[PyArray_CFLOAT] = NULL;\n\tPy_XDECREF(descr);\n\n\tdescr = PyArray_DescrFromType(PyArray_CDOUBLE);\n\tdescr->f->dotfunc = oldFunctions[PyArray_CDOUBLE];\n\toldFunctions[PyArray_CDOUBLE] = NULL;\n\tPy_XDECREF(descr);\n\t\n\taltered = FALSE;\n }\n\n Py_INCREF(Py_None);\n return Py_None;\n}\n\ntypedef enum {_scalar, _column, _row, _matrix} MatrixShape;\n\nstatic MatrixShape \n_select_matrix_shape(PyArrayObject *array)\n{\n switch (array->nd) {\n case 0:\n\treturn _scalar;\n case 1:\n\tif (array->dimensions[0] > 1)\n\t return _column;\n\treturn _scalar;\n case 2:\n\tif (array->dimensions[0] > 1) {\n\t if (array->dimensions[1] == 1)\n\t\treturn _column;\n\t else\n\t\treturn _matrix;\n\t}\n\tif (array->dimensions[1] == 1)\n\t return _scalar;\n\treturn _row;\n }\n return _matrix;\n}\n\n\nstatic char doc_matrixproduct[] = \"matrixproduct(a,b)\\nReturns the dot product of a and b for arrays of floating point types.\\nLike the generic numpy equivalent the product sum is over\\nthe last dimension of a and the second-to-last dimension of b.\\nNB: The first argument is not conjugated.\";\n\nstatic PyObject *\ndotblas_matrixproduct(PyObject *dummy, PyObject *args) \n{\n PyObject *op1, *op2;\n PyArrayObject *ap1, *ap2, *ret;\n int j, l, lda, ldb, ldc;\n int typenum, nd;\n intp ap1stride;\n intp dimensions[MAX_DIMS];\n static const float oneF[2] = {1.0, 0.0};\n static const float zeroF[2] = {0.0, 0.0};\n static const double oneD[2] = {1.0, 0.0};\n static const double zeroD[2] = {0.0, 0.0};\n double prior1, prior2;\n PyTypeObject *subtype;\n PyArray_Descr *dtype;\n MatrixShape ap1shape, ap2shape;\n \n if (!PyArg_ParseTuple(args, \"OO\", &op1, &op2)) return NULL;\n\t\n /* \n * \"Matrix product\" using the BLAS. \n * Only works for float double and complex types.\n */\n\n\n typenum = PyArray_ObjectType(op1, 0); \n typenum = PyArray_ObjectType(op2, typenum);\n \n /* This function doesn't handle other types */\n if ((typenum != PyArray_DOUBLE && typenum != PyArray_CDOUBLE &&\n\t typenum != PyArray_FLOAT && typenum != PyArray_CFLOAT)) {\n\treturn PyArray_Return((PyArrayObject *)PyArray_MatrixProduct(op1, op2));\n }\n \n ret = NULL;\n dtype = PyArray_DescrFromType(typenum);\n ap1 = (PyArrayObject *)PyArray_FromAny(op1, dtype, 0, 0, ALIGNED, NULL);\n if (ap1 == NULL) return NULL;\n ap2 = (PyArrayObject *)PyArray_FromAny(op2, dtype, 0, 0, ALIGNED, NULL);\n if (ap2 == NULL) goto fail;\n \n if ((ap1->nd > 2) || (ap2->nd > 2)) { \n\t/* This function doesn't handle dimensions greater than 2 -- other\n\t than to ensure the dot function is altered\n\t*/\n\tif (!altered) {\n\t /* need to alter dot product */\n\t PyObject *tmp1, *tmp2;\n\t tmp1 = PyTuple_New(0);\n\t tmp2 = dotblas_alterdot(NULL, tmp1);\n\t Py_DECREF(tmp1); \n\t Py_DECREF(tmp2);\n\t}\n\tret = (PyArrayObject *)PyArray_MatrixProduct((PyObject *)ap1, \n\t\t\t\t\t\t (PyObject *)ap2);\n\tPy_DECREF(ap1); \n\tPy_DECREF(ap2);\n\treturn PyArray_Return(ret);\n }\n \n ap1shape = _select_matrix_shape(ap1);\n ap2shape = _select_matrix_shape(ap2);\n \n if (ap1shape == _scalar || ap2shape == _scalar) {\n\t/* One of ap1 or ap2 is a scalar */\n\tif (ap1shape == _scalar) { \t\t/* Make ap2 the scalar */\n\t PyArrayObject *t = ap1;\n\t ap1 = ap2;\n\t ap2 = t;\n\t ap1shape = ap2shape;\n\t ap2shape = _scalar;\n\t}\n\t/* Fix it so that dot(shape=(N,1), shape=(1,))\n\t and dot(shape=(1,), shape=(1,N)) both return\n\t an (N,) array (but use the fast scalar code)\n\t*/\n\tif ((ap1shape == _column || ap1shape == _row) && \\\n\t (ap2->nd == 1)) {\n\t nd = 1;\n\t if (ap1shape == _column) {\n\t\tdimensions[0] = ap1->dimensions[0];\n\t\tap1stride = ap1->strides[0] / sizeof(double);\n\t }\n\t else {\n\t\tdimensions[0] = ap1->dimensions[1];\n\t\tap1stride = ap1->strides[1] / sizeof(double);\n\t }\n\t l = dimensions[0];\n\t}\n\telse {\n\t ap1stride = ap1->strides[0] / sizeof(double);\n\t nd = ap1->nd;\n\t for (l = 1, j = 0; j < nd; j++) {\n\t\tdimensions[j] = ap1->dimensions[j];\n\t\tl *= dimensions[j];\n\t }\n\t}\n }\n else { /* (ap1->nd <= 2 && ap2->nd <= 2) */\n\t/* Both ap1 and ap2 are vectors or matrices */\n\tl = ap1->dimensions[ap1->nd-1];\n\t\n\tif (ap2->dimensions[0] != l) {\n\t PyErr_SetString(PyExc_ValueError, \"matrices are not aligned\");\n\t goto fail;\n\t}\n\tnd = ap1->nd+ap2->nd-2;\n\t\n\tif (nd == 1) \n\t dimensions[0] = (ap1->nd == 2) ? ap1->dimensions[0] : ap2->dimensions[1];\n\telse if (nd == 2) {\n\t dimensions[0] = ap1->dimensions[0];\n\t dimensions[1] = ap2->dimensions[1];\n\t}\n }\n \n /* Choose which subtype to return */\n if (ap1->ob_type != ap2->ob_type) {\n\tprior2 = PyArray_GetPriority((PyObject *)ap2, 0.0);\n\tprior1 = PyArray_GetPriority((PyObject *)ap1, 0.0);\n\tsubtype = (prior2 > prior1 ? ap2->ob_type : ap1->ob_type);\n }\n else {\n\tprior1 = prior2 = 0.0;\n\tsubtype = ap1->ob_type;\n }\n \n if (l==0) nd = 0;\n ret = (PyArrayObject *)PyArray_New(subtype, nd, dimensions,\n\t\t\t\t typenum, NULL, NULL, 0, 0,\n\t\t\t\t (PyObject *)\n\t\t\t\t (prior2 > prior1 ? ap2 : ap1));\n \n if (ret == NULL) goto fail;\n memset(ret->data, 0, PyArray_NBYTES(ret));\n if (l==0) {\n\t Py_DECREF(ap1);\n\t Py_DECREF(ap2);\n\t return PyArray_Return(ret);\n }\n \n if (ap2shape == _scalar) {\n\t/* Multiplication by a scalar -- Level 1 BLAS */\n\t/* if ap1shape is a matrix and we are not contiguous, then we can't\n\t just blast through the entire array using a single\n\t striding factor */\n\tif (typenum == PyArray_DOUBLE) {\n\t if (l == 1) {\n\t\t*((double *)ret->data) = *((double *)ap2->data) * \\\n\t\t *((double *)ap1->data);\n\t }\n\t else if (ap1shape != _matrix) {\n\t\tcblas_daxpy(l, *((double *)ap2->data), (double *)ap1->data,\n\t\t\t ap1stride, (double *)ret->data, 1);\n\t }\n\t else {\n\t\tint maxind, oind, i, a1s, rets;\n\t\tchar *ptr, *rptr;\n\t\tdouble val;\n\t\tmaxind = (ap1->dimensions[0] >= ap1->dimensions[1] ? 0 : 1);\n\t\toind = 1-maxind;\n\t\tptr = ap1->data;\n\t\trptr = ret->data;\n\t\tl = ap1->dimensions[maxind];\n\t\tval = *((double *)ap2->data);\n\t\ta1s = ap1->strides[maxind] / sizeof(double);\n\t\trets = ret->strides[maxind] / sizeof(double);\n\t\tfor (i=0; i < ap1->dimensions[oind]; i++) {\n\t\t cblas_daxpy(l, val, (double *)ptr, a1s, \n\t\t\t\t(double *)rptr, rets);\n\t\t ptr += ap1->strides[oind];\n\t\t rptr += ret->strides[oind];\n\t\t}\n\t }\n\t} \n\telse if (typenum == PyArray_CDOUBLE) {\n\t if (l == 1) {\n\t\tcdouble *ptr1, *ptr2, *res;\n\t\tptr1 = (cdouble *)ap2->data;\n\t\tptr2 = (cdouble *)ap1->data;\n\t\tres = (cdouble *)ret->data;\t\t\n\t\tres->real = ptr1->real * ptr2->real - ptr1->imag * ptr2->imag;\n\t\tres->imag = ptr1->real * ptr2->imag + ptr1->imag * ptr2->real;\n\t }\n\t else if (ap1shape != _matrix) {\n\t\tcblas_zaxpy(l, (double *)ap2->data, (double *)ap1->data,\n\t\t\t ap1stride, (double *)ret->data, 1);\n\t }\n\t else {\n\t\tint maxind, oind, i, a1s, rets;\n\t\tchar *ptr, *rptr;\n\t\tdouble *pval;\n\t\tmaxind = (ap1->dimensions[0] >= ap1->dimensions[1] ? 0 : 1);\n\t\toind = 1-maxind;\n\t\tptr = ap1->data;\n\t\trptr = ret->data;\n\t\tl = ap1->dimensions[maxind];\n\t\tpval = (double *)ap2->data;\n\t\ta1s = ap1->strides[maxind] / sizeof(cdouble);\n\t\trets = ret->strides[maxind] / sizeof(cdouble);\n\t\tfor (i=0; i < ap1->dimensions[oind]; i++) {\n\t\t cblas_zaxpy(l, pval, (double *)ptr, a1s, \n\t\t\t\t(double *)rptr, rets);\n\t\t ptr += ap1->strides[oind];\n\t\t rptr += ret->strides[oind];\n\t\t}\n\t }\n\t}\n\telse if (typenum == PyArray_FLOAT) {\n\t if (l == 1) {\n\t\t*((float *)ret->data) = *((float *)ap2->data) * \\\n\t\t *((float *)ap1->data);\n\t }\n\t else if (ap1shape != _matrix) {\n\t\tcblas_saxpy(l, *((float *)ap2->data), (float *)ap1->data,\n\t\t\t ap1stride, (float *)ret->data, 1);\n\t }\n\t else {\n\t\tint maxind, oind, i, a1s, rets;\n\t\tchar *ptr, *rptr;\n\t\tfloat val;\n\t\tmaxind = (ap1->dimensions[0] >= ap1->dimensions[1] ? 0 : 1);\n\t\toind = 1-maxind;\n\t\tptr = ap1->data;\n\t\trptr = ret->data;\n\t\tl = ap1->dimensions[maxind];\n\t\tval = *((float *)ap2->data);\n\t\ta1s = ap1->strides[maxind] / sizeof(float);\n\t\trets = ret->strides[maxind] / sizeof(float);\n\t\tfor (i=0; i < ap1->dimensions[oind]; i++) {\n\t\t cblas_saxpy(l, val, (float *)ptr, a1s, \n\t\t\t\t(float *)rptr, rets);\n\t\t ptr += ap1->strides[oind];\n\t\t rptr += ret->strides[oind];\n\t\t}\n\t }\n\t}\n\telse if (typenum == PyArray_CFLOAT) {\n\t if (l == 1) {\n\t\tcfloat *ptr1, *ptr2, *res;\n\t\tptr1 = (cfloat *)ap2->data;\n\t\tptr2 = (cfloat *)ap1->data;\n\t\tres = (cfloat *)ret->data;\t\t\n\t\tres->real = ptr1->real * ptr2->real - ptr1->imag * ptr2->imag;\n\t\tres->imag = ptr1->real * ptr2->imag + ptr1->imag * ptr2->real;\n\t }\n\t else if (ap1shape != _matrix) {\n\t\tcblas_caxpy(l, (float *)ap2->data, (float *)ap1->data,\n\t\t\t ap1stride, (float *)ret->data, 1);\n\t }\n\t else {\n\t\tint maxind, oind, i, a1s, rets;\n\t\tchar *ptr, *rptr;\n\t\tfloat *pval;\n\t\tmaxind = (ap1->dimensions[0] >= ap1->dimensions[1] ? 0 : 1);\n\t\toind = 1-maxind;\n\t\tptr = ap1->data;\n\t\trptr = ret->data;\n\t\tl = ap1->dimensions[maxind];\n\t\tpval = (float *)ap2->data;\n\t\ta1s = ap1->strides[maxind] / sizeof(cfloat);\n\t\trets = ret->strides[maxind] / sizeof(cfloat);\n\t\tfor (i=0; i < ap1->dimensions[oind]; i++) {\n\t\t cblas_caxpy(l, pval, (float *)ptr, a1s, \n\t\t\t\t(float *)rptr, rets);\n\t\t ptr += ap1->strides[oind];\n\t\t rptr += ret->strides[oind];\n\t\t}\n\t }\n\t}\n }\n else if ((ap2shape == _column) && (ap1shape != _matrix)) {\n\tint ap1s, ap2s;\n\tap2s = ap2->strides[0] / ap2->descr->elsize;\n\tif (ap1shape == _row) {\n\t ap1s = ap1->strides[1] / ap1->descr->elsize;\n\t}\n\telse {\n\t ap1s = ap1->strides[0] / ap1->descr->elsize;\n\t}\n\t \n\t/* Dot product between two vectors -- Level 1 BLAS */\n\tif (typenum == PyArray_DOUBLE) {\n\t double result = cblas_ddot(l, (double *)ap1->data, ap1s, \n\t\t\t\t (double *)ap2->data, ap2s);\n\t *((double *)ret->data) = result;\n\t}\n\telse if (typenum == PyArray_FLOAT) {\n\t float result = cblas_sdot(l, (float *)ap1->data, ap1s, \n\t\t\t\t (float *)ap2->data, ap2s);\n\t *((float *)ret->data) = result;\n\t}\n\telse if (typenum == PyArray_CDOUBLE) {\n\t cblas_zdotu_sub(l, (double *)ap1->data, ap1s, \n\t\t\t (double *)ap2->data, ap2s, (double *)ret->data);\n\t}\n\telse if (typenum == PyArray_CFLOAT) {\n\t cblas_cdotu_sub(l, (float *)ap1->data, ap1s, \n\t\t\t (float *)ap2->data, ap2s, (float *)ret->data);\n\t}\n }\n else if (ap1shape == _matrix && ap2shape != _matrix) {\n\t/* Matrix vector multiplication -- Level 2 BLAS */\n\t/* lda must be MAX(M,1) */\n\tenum CBLAS_ORDER Order;\n\tint ap2s;\n\n\tif (!PyArray_ISONESEGMENT(ap1)) {\n\t PyObject *new;\n\t new = PyArray_Copy(ap1);\n\t Py_DECREF(ap1);\n\t ap1 = (PyArrayObject *)new;\n\t if (new == NULL) goto fail;\n\t}\n\tif (PyArray_ISCONTIGUOUS(ap1)) {\n Order = CblasRowMajor;\n lda = (ap1->dimensions[1] > 1 ? ap1->dimensions[1] : 1);\n\t}\n\telse {\n\t Order = CblasColMajor;\n lda = (ap1->dimensions[0] > 1 ? ap1->dimensions[0] : 1);\n\t}\n\tap2s = ap2->strides[0] / ap2->descr->elsize;\n\tif (typenum == PyArray_DOUBLE) {\n\t cblas_dgemv(Order, CblasNoTrans, \n\t\t\tap1->dimensions[0], ap1->dimensions[1], \n\t\t\t1.0, (double *)ap1->data, lda, \n\t\t\t(double *)ap2->data, ap2s, 0.0, (double *)ret->data, 1);\n\t}\n\telse if (typenum == PyArray_FLOAT) {\n\t cblas_sgemv(Order, CblasNoTrans, \n\t\t\tap1->dimensions[0], ap1->dimensions[1], \n\t\t\t1.0, (float *)ap1->data, lda, \n\t\t\t(float *)ap2->data, ap2s, 0.0, (float *)ret->data, 1);\n\t}\n\telse if (typenum == PyArray_CDOUBLE) {\n\t cblas_zgemv(Order, \n\t\t\tCblasNoTrans, ap1->dimensions[0], ap1->dimensions[1], \n\t\t\toneD, (double *)ap1->data, lda, \n\t\t\t(double *)ap2->data, ap2s, zeroD, \n\t\t\t(double *)ret->data, 1);\n\t}\n\telse if (typenum == PyArray_CFLOAT) {\n\t cblas_cgemv(Order, \n\t\t\tCblasNoTrans, ap1->dimensions[0], ap1->dimensions[1], \n\t\t\toneF, (float *)ap1->data, lda, \n\t\t\t(float *)ap2->data, ap2s, zeroF, \n\t\t\t(float *)ret->data, 1);\n\t}\n }\n else if (ap1shape != _matrix && ap2shape == _matrix) {\n\t/* Vector matrix multiplication -- Level 2 BLAS */\n\tenum CBLAS_ORDER Order;\n\tint ap1s;\n\n\tif (!PyArray_ISONESEGMENT(ap2)) {\n\t PyObject *new;\n\t new = PyArray_Copy(ap2);\n\t Py_DECREF(ap2);\n\t ap2 = (PyArrayObject *)new;\n\t if (new == NULL) goto fail;\n\t}\n\tif (PyArray_ISCONTIGUOUS(ap2)) {\n\t Order = CblasRowMajor;\n lda = (ap2->dimensions[1] > 1 ? ap2->dimensions[1] : 1);\n\t}\n\telse {\n\t Order = CblasColMajor;\n lda = (ap2->dimensions[0] > 1 ? ap2->dimensions[0] : 1);\n\t}\n\tif (ap1shape == _row) {\n\t ap1s = ap1->strides[1] / ap1->descr->elsize;\n\t}\n\telse {\n\t ap1s = ap1->strides[0] / ap1->descr->elsize;\n\t}\n\tif (typenum == PyArray_DOUBLE) {\n\t cblas_dgemv(Order, \n\t\t\tCblasTrans, ap2->dimensions[0], ap2->dimensions[1], \n\t\t\t1.0, (double *)ap2->data, lda,\n\t\t\t(double *)ap1->data, ap1s, 0.0, (double *)ret->data, 1);\n\t}\n\telse if (typenum == PyArray_FLOAT) {\n\t cblas_sgemv(Order,\n\t\t\tCblasTrans, ap2->dimensions[0], ap2->dimensions[1], \n\t\t\t1.0, (float *)ap2->data, lda,\n\t\t\t(float *)ap1->data, ap1s, 0.0, (float *)ret->data, 1);\n\t}\n\telse if (typenum == PyArray_CDOUBLE) {\n\t cblas_zgemv(Order,\n\t\t\tCblasTrans, ap2->dimensions[0], ap2->dimensions[1], \n\t\t\toneD, (double *)ap2->data, lda,\n\t\t\t(double *)ap1->data, ap1s, zeroD, (double *)ret->data, 1);\n\t}\n\telse if (typenum == PyArray_CFLOAT) {\n\t cblas_cgemv(Order,\n\t\t\tCblasTrans, ap2->dimensions[0], ap2->dimensions[1], \n\t\t\toneF, (float *)ap2->data, lda,\n\t\t\t(float *)ap1->data, ap1s, zeroF, (float *)ret->data, 1);\n\t}\n }\n else { /* (ap1->nd == 2 && ap2->nd == 2) */\n\t/* Matrix matrix multiplication -- Level 3 BLAS */ \n\t/* L x M multiplied by M x N */\n\tenum CBLAS_ORDER Order;\n\tenum CBLAS_TRANSPOSE Trans1, Trans2;\n\tint M, N, L;\n\n\t/* Optimization possible: */\n\t/* We may be able to handle single-segment arrays here\n\t using appropriate values of Order, Trans1, and Trans2.\n\t*/\n\t\n \tif (!PyArray_ISCONTIGUOUS(ap2)) {\n\t PyObject *new;\n\t new = PyArray_Copy(ap2);\n\t Py_DECREF(ap2);\n\t ap2 = (PyArrayObject *)new;\n\t if (new == NULL) goto fail;\n\t}\n\tif (!PyArray_ISCONTIGUOUS(ap1)) {\n\t PyObject *new;\n\t new = PyArray_Copy(ap1);\n\t Py_DECREF(ap1);\n\t ap1 = (PyArrayObject *)new;\n\t if (new == NULL) goto fail;\n\t}\n\t\n\tOrder = CblasRowMajor;\n\tTrans1 = CblasNoTrans;\n\tTrans2 = CblasNoTrans;\n\tL = ap1->dimensions[0];\n\tN = ap2->dimensions[1];\n\tM = ap2->dimensions[0];\n\tlda = (ap1->dimensions[1] > 1 ? ap1->dimensions[1] : 1);\n\tldb = (ap2->dimensions[1] > 1 ? ap2->dimensions[1] : 1);\n\tldc = (ret->dimensions[1] > 1 ? ret->dimensions[1] : 1);\t \n\tif (typenum == PyArray_DOUBLE) {\n\t cblas_dgemm(Order, Trans1, Trans2, \n\t\t\tL, N, M,\n\t\t\t1.0, (double *)ap1->data, lda,\n\t\t\t(double *)ap2->data, ldb,\n\t\t\t0.0, (double *)ret->data, ldc);\n\t}\n\telse if (typenum == PyArray_FLOAT) {\n\t cblas_sgemm(Order, Trans1, Trans2,\n\t\t\tL, N, M, \n\t\t\t1.0, (float *)ap1->data, lda,\n\t\t\t(float *)ap2->data, ldb,\n\t\t\t0.0, (float *)ret->data, ldc);\n\t}\n\telse if (typenum == PyArray_CDOUBLE) {\n\t cblas_zgemm(Order, Trans1, Trans2,\n\t\t\tL, N, M, \n\t\t\toneD, (double *)ap1->data, lda,\n\t\t\t(double *)ap2->data, ldb,\n\t\t\tzeroD, (double *)ret->data, ldc);\n\t}\n\telse if (typenum == PyArray_CFLOAT) {\n\t cblas_cgemm(Order, Trans1, Trans2,\n\t\t\tL, N, M,\n\t\t\toneF, (float *)ap1->data, lda,\n\t\t\t(float *)ap2->data, ldb,\n\t\t\tzeroF, (float *)ret->data, ldc);\n\t}\n }\n\n Py_DECREF(ap1);\n Py_DECREF(ap2);\n return PyArray_Return(ret);\n\t\n fail:\n Py_XDECREF(ap1);\n Py_XDECREF(ap2);\n Py_XDECREF(ret);\n return NULL;\n}\n\n\nstatic char doc_innerproduct[] = \"innerproduct(a,b)\\nReturns the inner product of a and b for arrays of floating point types.\\nLike the generic Numeric equivalent the product sum is over\\nthe last dimension of a and b.\\nNB: The first argument is not conjugated.\";\n\nstatic PyObject *\ndotblas_innerproduct(PyObject *dummy, PyObject *args) \n{\n PyObject *op1, *op2;\n PyArrayObject *ap1, *ap2, *ret;\n int j, l, lda, ldb, ldc;\n int typenum, nd;\n intp dimensions[MAX_DIMS];\n static const float oneF[2] = {1.0, 0.0};\n static const float zeroF[2] = {0.0, 0.0};\n static const double oneD[2] = {1.0, 0.0};\n static const double zeroD[2] = {0.0, 0.0};\n PyTypeObject *subtype;\n double prior1, prior2;\n\n if (!PyArg_ParseTuple(args, \"OO\", &op1, &op2)) return NULL;\n\t\n /* \n * Inner product using the BLAS. The product sum is taken along the last\n * dimensions of the two arrays.\n * Only speeds things up for float double and complex types.\n */\n\n\n typenum = PyArray_ObjectType(op1, 0); \n typenum = PyArray_ObjectType(op2, typenum);\n\n /* This function doesn't handle other types */\n if ((typenum != PyArray_DOUBLE && typenum != PyArray_CDOUBLE &&\n\t typenum != PyArray_FLOAT && typenum != PyArray_CFLOAT)) {\n return PyArray_Return((PyArrayObject *)PyArray_InnerProduct(op1, op2));\n }\n\n ret = NULL;\n ap1 = (PyArrayObject *)PyArray_ContiguousFromObject(op1, typenum, 0, 0);\n if (ap1 == NULL) return NULL;\n ap2 = (PyArrayObject *)PyArray_ContiguousFromObject(op2, typenum, 0, 0);\n if (ap2 == NULL) goto fail;\n\n if ((ap1->nd > 2) || (ap2->nd > 2)) { \n\t/* This function doesn't handle dimensions greater than 2 -- other\n\t than to ensure the dot function is altered\n\t*/\n\tif (!altered) {\n\t /* need to alter dot product */\n\t PyObject *tmp1, *tmp2;\n\t tmp1 = PyTuple_New(0);\n\t tmp2 = dotblas_alterdot(NULL, tmp1);\n\t Py_DECREF(tmp1); \n\t Py_DECREF(tmp2);\n\t}\n\tret = (PyArrayObject *)PyArray_InnerProduct((PyObject *)ap1, \n\t\t\t\t\t\t (PyObject *)ap2);\n\tPy_DECREF(ap1); \n\tPy_DECREF(ap2);\n\treturn PyArray_Return(ret);\n }\n\n if (ap1->nd == 0 || ap2->nd == 0) {\n\t/* One of ap1 or ap2 is a scalar */\n\tif (ap1->nd == 0) {\t\t/* Make ap2 the scalar */\n\t PyArrayObject *t = ap1;\n\t ap1 = ap2;\n\t ap2 = t;\n\t}\n\tfor (l = 1, j = 0; j < ap1->nd; j++) {\n\t dimensions[j] = ap1->dimensions[j];\n\t l *= dimensions[j];\n\t}\n\tnd = ap1->nd;\n }\n else { /* (ap1->nd <= 2 && ap2->nd <= 2) */\n\t/* Both ap1 and ap2 are vectors or matrices */\n\tl = ap1->dimensions[ap1->nd-1];\n\t\n\tif (ap2->dimensions[ap2->nd-1] != l) {\n\t PyErr_SetString(PyExc_ValueError, \"matrices are not aligned\");\n\t goto fail;\n\t}\n\tnd = ap1->nd+ap2->nd-2;\n \n\tif (nd == 1) \n\t dimensions[0] = (ap1->nd == 2) ? ap1->dimensions[0] : ap2->dimensions[0];\n\telse if (nd == 2) {\n\t dimensions[0] = ap1->dimensions[0];\n\t dimensions[1] = ap2->dimensions[0];\n\t}\n }\n\n /* Choose which subtype to return */\n prior2 = PyArray_GetPriority((PyObject *)ap2, 0.0);\n prior1 = PyArray_GetPriority((PyObject *)ap1, 0.0);\n subtype = (prior2 > prior1 ? ap2->ob_type : ap1->ob_type);\n \n ret = (PyArrayObject *)PyArray_New(subtype, nd, dimensions, \n\t\t\t\t typenum, NULL, NULL, 0, 0, \n\t\t\t\t (PyObject *)\\\n\t\t\t\t (prior2 > prior1 ? ap2 : ap1));\n \n if (ret == NULL) goto fail;\n memset(ret->data, 0, PyArray_NBYTES(ret));\n\n if (ap2->nd == 0) {\n\t/* Multiplication by a scalar -- Level 1 BLAS */\n\tif (typenum == PyArray_DOUBLE) {\n\t cblas_daxpy(l, *((double *)ap2->data), (double *)ap1->data, 1,\n\t\t\t(double *)ret->data, 1);\n\t} \n\telse if (typenum == PyArray_CDOUBLE) {\n\t cblas_zaxpy(l, (double *)ap2->data, (double *)ap1->data, 1,\n\t\t\t(double *)ret->data, 1);\n\t}\n\telse if (typenum == PyArray_FLOAT) {\n\t cblas_saxpy(l, *((float *)ap2->data), (float *)ap1->data, 1,\n\t\t\t(float *)ret->data, 1);\n\t}\n\telse if (typenum == PyArray_CFLOAT) {\n\t cblas_caxpy(l, (float *)ap2->data, (float *)ap1->data, 1,\n\t\t\t(float *)ret->data, 1);\n\t}\n }\n else if (ap1->nd == 1 && ap2->nd == 1) {\n\t/* Dot product between two vectors -- Level 1 BLAS */\n\tif (typenum == PyArray_DOUBLE) {\n\t double result = cblas_ddot(l, (double *)ap1->data, 1, \n\t\t\t\t (double *)ap2->data, 1);\n\t *((double *)ret->data) = result;\n\t}\n\telse if (typenum == PyArray_CDOUBLE) {\n\t cblas_zdotu_sub(l, (double *)ap1->data, 1, \n\t\t\t (double *)ap2->data, 1, (double *)ret->data);\n\t}\n\telse if (typenum == PyArray_FLOAT) {\n\t float result = cblas_sdot(l, (float *)ap1->data, 1, \n\t\t\t\t (float *)ap2->data, 1);\n\t *((float *)ret->data) = result;\n\t}\n\telse if (typenum == PyArray_CFLOAT) {\n\t cblas_cdotu_sub(l, (float *)ap1->data, 1, \n\t\t\t (float *)ap2->data, 1, (float *)ret->data);\n\t}\n }\n else if (ap1->nd == 2 && ap2->nd == 1) {\n\t/* Matrix-vector multiplication -- Level 2 BLAS */\n\tlda = (ap1->dimensions[1] > 1 ? ap1->dimensions[1] : 1);\n\tif (typenum == PyArray_DOUBLE) {\n\t cblas_dgemv(CblasRowMajor, \n\t\t\tCblasNoTrans, ap1->dimensions[0], ap1->dimensions[1], \n\t\t\t1.0, (double *)ap1->data, lda,\n\t\t\t(double *)ap2->data, 1, 0.0, (double *)ret->data, 1);\n\t}\n\telse if (typenum == PyArray_CDOUBLE) {\n\t cblas_zgemv(CblasRowMajor, \n\t\t\tCblasNoTrans, ap1->dimensions[0], ap1->dimensions[1], \n\t\t\toneD, (double *)ap1->data, lda,\n\t\t\t(double *)ap2->data, 1, zeroD, (double *)ret->data, 1);\n\t}\n\telse if (typenum == PyArray_FLOAT) {\n\t cblas_sgemv(CblasRowMajor, \n\t\t\tCblasNoTrans, ap1->dimensions[0], ap1->dimensions[1], \n\t\t\t1.0, (float *)ap1->data, lda,\n\t\t\t(float *)ap2->data, 1, 0.0, (float *)ret->data, 1);\n\t}\n\telse if (typenum == PyArray_CFLOAT) {\n\t cblas_cgemv(CblasRowMajor, \n\t\t\tCblasNoTrans, ap1->dimensions[0], ap1->dimensions[1], \n\t\t\toneF, (float *)ap1->data, lda,\n\t\t\t(float *)ap2->data, 1, zeroF, (float *)ret->data, 1);\n\t}\n }\n else if (ap1->nd == 1 && ap2->nd == 2) {\n\t/* Vector matrix multiplication -- Level 2 BLAS */\n\tlda = (ap2->dimensions[1] > 1 ? ap2->dimensions[1] : 1);\n\tif (typenum == PyArray_DOUBLE) {\n\t cblas_dgemv(CblasRowMajor, \n\t\t\tCblasNoTrans, ap2->dimensions[0], ap2->dimensions[1], \n\t\t\t1.0, (double *)ap2->data, lda,\n\t\t\t(double *)ap1->data, 1, 0.0, (double *)ret->data, 1);\n\t}\n\telse if (typenum == PyArray_CDOUBLE) {\n\t cblas_zgemv(CblasRowMajor, \n\t\t\tCblasNoTrans, ap2->dimensions[0], ap2->dimensions[1], \n\t\t\toneD, (double *)ap2->data, lda,\n\t\t\t(double *)ap1->data, 1, zeroD, (double *)ret->data, 1);\n\t}\n\telse if (typenum == PyArray_FLOAT) {\n\t cblas_sgemv(CblasRowMajor, \n\t\t\tCblasNoTrans, ap2->dimensions[0], ap2->dimensions[1], \n\t\t\t1.0, (float *)ap2->data, lda,\n\t\t\t(float *)ap1->data, 1, 0.0, (float *)ret->data, 1);\n\t}\n\telse if (typenum == PyArray_CFLOAT) {\n\t cblas_cgemv(CblasRowMajor, \n\t\t\tCblasNoTrans, ap2->dimensions[0], ap2->dimensions[1], \n\t\t\toneF, (float *)ap2->data, lda,\n\t\t\t(float *)ap1->data, 1, zeroF, (float *)ret->data, 1);\n\t}\n }\n else { /* (ap1->nd == 2 && ap2->nd == 2) */ \n\t/* Matrix matrix multiplication -- Level 3 BLAS */ \n\tlda = (ap1->dimensions[1] > 1 ? ap1->dimensions[1] : 1);\n\tldb = (ap2->dimensions[1] > 1 ? ap2->dimensions[1] : 1);\n\tldc = (ret->dimensions[1] > 1 ? ret->dimensions[1] : 1);\n\tif (typenum == PyArray_DOUBLE) {\n\t cblas_dgemm(CblasRowMajor, CblasNoTrans, CblasTrans,\n\t\t\tap1->dimensions[0], ap2->dimensions[0], ap1->dimensions[1],\n\t\t\t1.0, (double *)ap1->data, lda,\n\t\t\t(double *)ap2->data, ldb,\n\t\t\t0.0, (double *)ret->data, ldc);\n\t}\n\telse if (typenum == PyArray_FLOAT) {\n\t cblas_sgemm(CblasRowMajor, CblasNoTrans, CblasTrans,\n\t\t\tap1->dimensions[0], ap2->dimensions[0], ap1->dimensions[1],\n\t\t\t1.0, (float *)ap1->data, lda,\n\t\t\t(float *)ap2->data, ldb,\n\t\t\t0.0, (float *)ret->data, ldc);\n\t}\n\telse if (typenum == PyArray_CDOUBLE) {\n\t cblas_zgemm(CblasRowMajor, CblasNoTrans, CblasTrans,\n\t\t\tap1->dimensions[0], ap2->dimensions[0], ap1->dimensions[1],\n\t\t\toneD, (double *)ap1->data, lda,\n\t\t\t(double *)ap2->data, ldb,\n\t\t\tzeroD, (double *)ret->data, ldc);\n\t}\n\telse if (typenum == PyArray_CFLOAT) {\n\t cblas_cgemm(CblasRowMajor, CblasNoTrans, CblasTrans,\n\t\t\tap1->dimensions[0], ap2->dimensions[0], ap1->dimensions[1],\n\t\t\toneF, (float *)ap1->data, lda,\n\t\t\t(float *)ap2->data, ldb,\n\t\t\tzeroF, (float *)ret->data, ldc);\n\t}\n }\n Py_DECREF(ap1);\n Py_DECREF(ap2);\n return PyArray_Return(ret);\n\t\n fail:\n Py_XDECREF(ap1);\n Py_XDECREF(ap2);\n Py_XDECREF(ret);\n return NULL;\n}\n\n\nstatic char doc_vdot[] = \"vdot(a,b)\\nReturns the dot product of a and b for scalars and vectors\\nof floating point and complex types. The first argument, a, is conjugated.\";\n\n\nstatic PyObject *dotblas_vdot(PyObject *dummy, PyObject *args) {\n PyObject *op1, *op2;\n PyArrayObject *ap1=NULL, *ap2=NULL, *ret=NULL;\n int l;\n int typenum;\n intp dimensions[MAX_DIMS];\n PyArray_Descr *type;\n\n if (!PyArg_ParseTuple(args, \"OO\", &op1, &op2)) return NULL;\n\t\n /* \n * Conjugating dot product using the BLAS for vectors.\n * Multiplies op1 and op2, each of which must be vector.\n */\n\n typenum = PyArray_ObjectType(op1, 0); \n typenum = PyArray_ObjectType(op2, typenum);\n \n type = PyArray_DescrFromType(typenum);\n \n ap1 = (PyArrayObject *)PyArray_FromAny(op1, type, 0, 0, 0, NULL);\n if (ap1==NULL) goto fail;\n op1 = PyArray_Flatten(ap1, 0);\n if (op1==NULL) goto fail;\n Py_DECREF(ap1);\n ap1 = (PyArrayObject *)op1;\n \n ap2 = (PyArrayObject *)PyArray_FromAny(op2, type, 0, 0, 0, NULL);\n if (ap2==NULL) goto fail;\n op2 = PyArray_Flatten(ap2, 0);\n if (op2 == NULL) goto fail;\n Py_DECREF(ap2);\n ap2 = (PyArrayObject *)op2;\n \n if (typenum != PyArray_FLOAT && typenum != PyArray_DOUBLE &&\n\ttypenum != PyArray_CFLOAT && typenum != PyArray_CDOUBLE) {\n\tif (!altered) {\n\t /* need to alter dot product */\n\t PyObject *tmp1, *tmp2;\n\t tmp1 = PyTuple_New(0);\n\t tmp2 = dotblas_alterdot(NULL, tmp1);\n\t Py_DECREF(tmp1); \n\t Py_DECREF(tmp2);\n\t}\n\tif (PyTypeNum_ISCOMPLEX(typenum)) {\n\t op1 = PyArray_Conjugate(ap1);\n\t if (op1==NULL) goto fail;\n\t Py_DECREF(ap1);\n\t ap1 = (PyArrayObject *)op1;\n\t}\t\n\tret = (PyArrayObject *)PyArray_InnerProduct((PyObject *)ap1, \n\t\t\t\t\t\t (PyObject *)ap2);\n\tPy_DECREF(ap1); \n\tPy_DECREF(ap2);\n\treturn PyArray_Return(ret);\n }\n\n if (ap2->dimensions[0] != ap1->dimensions[ap1->nd-1]) {\n\tPyErr_SetString(PyExc_ValueError, \"vectors have different lengths\");\n\tgoto fail;\n }\n l = ap1->dimensions[ap1->nd-1];\n \n ret = (PyArrayObject *)PyArray_SimpleNew(0, dimensions, typenum);\n if (ret == NULL) goto fail;\n\n\n /* Dot product between two vectors -- Level 1 BLAS */\n if (typenum == PyArray_DOUBLE) {\n\t*((double *)ret->data) = cblas_ddot(l, (double *)ap1->data, 1, \n\t\t\t\t\t (double *)ap2->data, 1);\n }\n else if (typenum == PyArray_FLOAT) {\n\t*((float *)ret->data) = cblas_sdot(l, (float *)ap1->data, 1, \n\t\t\t\t\t (float *)ap2->data, 1);\n }\n else if (typenum == PyArray_CDOUBLE) {\n\tcblas_zdotc_sub(l, (double *)ap1->data, 1, \n\t\t\t(double *)ap2->data, 1, (double *)ret->data);\n }\n else if (typenum == PyArray_CFLOAT) {\n\tcblas_cdotc_sub(l, (float *)ap1->data, 1, \n\t\t\t(float *)ap2->data, 1, (float *)ret->data);\n }\n\n Py_DECREF(ap1);\n Py_DECREF(ap2);\n return PyArray_Return(ret);\n\t\n fail:\n Py_XDECREF(ap1);\n Py_XDECREF(ap2);\n Py_XDECREF(ret);\n return NULL;\n}\n\nstatic struct PyMethodDef dotblas_module_methods[] = {\n {\"dot\", (PyCFunction)dotblas_matrixproduct, 1, doc_matrixproduct},\n {\"inner\", (PyCFunction)dotblas_innerproduct, 1, doc_innerproduct},\n {\"vdot\", (PyCFunction)dotblas_vdot, 1, doc_vdot},\n {\"alterdot\", (PyCFunction)dotblas_alterdot, 1, doc_alterdot},\n {\"restoredot\", (PyCFunction)dotblas_restoredot, 1, doc_restoredot},\n {NULL,\t\tNULL, 0}\t\t/* sentinel */\n};\n\n/* Initialization function for the module */\nDL_EXPORT(void) init_dotblas(void) {\n int i;\n PyObject *m, *d, *s;\n \n /* Create the module and add the functions */\n m = Py_InitModule3(\"_dotblas\", dotblas_module_methods, module_doc);\n\n /* Import the array object */\n import_array();\n\n /* Initialise the array of dot functions */\n for (i = 0; i < PyArray_NTYPES; i++)\n\toldFunctions[i] = NULL;\n\n /* alterdot at load */\n d = PyTuple_New(0);\n s = dotblas_alterdot(NULL, d);\n Py_DECREF(d);\n Py_DECREF(s);\n \n}\n", + "source_code_before": "static char module_doc[] =\n\"This module provides a BLAS optimized\\nmatrix multiply, inner product and dot for numpy arrays\";\n\n#include \"Python.h\"\n#include \"numpy/arrayobject.h\"\n#ifndef CBLAS_HEADER\n#define CBLAS_HEADER \"cblas.h\"\n#endif\n#include CBLAS_HEADER\n\n#include \n\nstatic void \nFLOAT_dot(void *a, intp stridea, void *b, intp strideb, void *res, \n\t intp n, void *tmp)\n{\n register int na = stridea / sizeof(float);\n register int nb = strideb / sizeof(float);\n\n *((float *)res) = cblas_sdot((int)n, (float *)a, na, (float *)b, nb);\n}\n\nstatic void \nDOUBLE_dot(void *a, intp stridea, void *b, intp strideb, void *res, \n\t intp n, void *tmp)\n{\n register int na = stridea / sizeof(double);\n register int nb = strideb / sizeof(double);\n\n *((double *)res) = cblas_ddot((int)n, (double *)a, na, (double *)b, nb);\n}\n\nstatic void \nCFLOAT_dot(void *a, intp stridea, void *b, intp strideb, void *res, \n\t intp n, void *tmp)\n{\n \n register int na = stridea / sizeof(cfloat);\n register int nb = strideb / sizeof(cfloat);\n\n cblas_cdotu_sub((int)n, (float *)a, na, (float *)b, nb, (float *)res);\n}\n\nstatic void \nCDOUBLE_dot(void *a, intp stridea, void *b, intp strideb, void *res, \n\t intp n, void *tmp)\n{\n register int na = stridea / sizeof(cdouble);\n register int nb = strideb / sizeof(cdouble);\n\n cblas_zdotu_sub((int)n, (double *)a, na, (double *)b, nb, (double *)res);\n}\n\n\nstatic PyArray_DotFunc *oldFunctions[PyArray_NTYPES];\nstatic Bool altered=FALSE;\n\nstatic char doc_alterdot[] = \"alterdot() changes all dot functions to use blas.\";\n\nstatic PyObject *\ndotblas_alterdot(PyObject *dummy, PyObject *args) \n{\n PyArray_Descr *descr;\n \n if (!PyArg_ParseTuple(args, \"\")) return NULL;\n\n /* Replace the dot functions to the ones using blas */\n\n if (!altered) {\n\tdescr = PyArray_DescrFromType(PyArray_FLOAT);\n\toldFunctions[PyArray_FLOAT] = descr->f->dotfunc;\n\tdescr->f->dotfunc = (PyArray_DotFunc *)FLOAT_dot;\n\t\n\tdescr = PyArray_DescrFromType(PyArray_DOUBLE);\n\toldFunctions[PyArray_DOUBLE] = descr->f->dotfunc;\n\tdescr->f->dotfunc = (PyArray_DotFunc *)DOUBLE_dot;\n\t\n\tdescr = PyArray_DescrFromType(PyArray_CFLOAT);\n\toldFunctions[PyArray_CFLOAT] = descr->f->dotfunc;\n\tdescr->f->dotfunc = (PyArray_DotFunc *)CFLOAT_dot;\n\t\n\tdescr = PyArray_DescrFromType(PyArray_CDOUBLE);\n\toldFunctions[PyArray_CDOUBLE] = descr->f->dotfunc;\n\tdescr->f->dotfunc = (PyArray_DotFunc *)CDOUBLE_dot;\n\n\taltered = TRUE;\n }\n\n Py_INCREF(Py_None);\n return Py_None;\n}\n\nstatic char doc_restoredot[] = \"restoredot() restores dots to defaults.\";\n\nstatic PyObject *\ndotblas_restoredot(PyObject *dummy, PyObject *args) \n{\n PyArray_Descr *descr;\n\n if (!PyArg_ParseTuple(args, \"\")) return NULL;\n\n if (altered) {\n\tdescr = PyArray_DescrFromType(PyArray_FLOAT);\n\tdescr->f->dotfunc = oldFunctions[PyArray_FLOAT];\n\toldFunctions[PyArray_FLOAT] = NULL;\n\tPy_XDECREF(descr);\n\n\tdescr = PyArray_DescrFromType(PyArray_DOUBLE);\n\tdescr->f->dotfunc = oldFunctions[PyArray_DOUBLE];\n\toldFunctions[PyArray_DOUBLE] = NULL;\n\tPy_XDECREF(descr);\n\n\tdescr = PyArray_DescrFromType(PyArray_CFLOAT);\n\tdescr->f->dotfunc = oldFunctions[PyArray_CFLOAT];\n\toldFunctions[PyArray_CFLOAT] = NULL;\n\tPy_XDECREF(descr);\n\n\tdescr = PyArray_DescrFromType(PyArray_CDOUBLE);\n\tdescr->f->dotfunc = oldFunctions[PyArray_CDOUBLE];\n\toldFunctions[PyArray_CDOUBLE] = NULL;\n\tPy_XDECREF(descr);\n\t\n\taltered = FALSE;\n }\n\n Py_INCREF(Py_None);\n return Py_None;\n}\n\ntypedef enum {_scalar, _column, _row, _matrix} MatrixShape;\n\nstatic MatrixShape \n_select_matrix_shape(PyArrayObject *array)\n{\n switch (array->nd) {\n case 0:\n\treturn _scalar;\n case 1:\n\tif (array->dimensions[0] > 1)\n\t return _column;\n\treturn _scalar;\n case 2:\n\tif (array->dimensions[0] > 1) {\n\t if (array->dimensions[1] == 1)\n\t\treturn _column;\n\t else\n\t\treturn _matrix;\n\t}\n\tif (array->dimensions[1] == 1)\n\t return _scalar;\n\treturn _row;\n }\n return _matrix;\n}\n\n\nstatic char doc_matrixproduct[] = \"matrixproduct(a,b)\\nReturns the dot product of a and b for arrays of floating point types.\\nLike the generic numpy equivalent the product sum is over\\nthe last dimension of a and the second-to-last dimension of b.\\nNB: The first argument is not conjugated.\";\n\nstatic PyObject *\ndotblas_matrixproduct(PyObject *dummy, PyObject *args) \n{\n PyObject *op1, *op2;\n PyArrayObject *ap1, *ap2, *ret;\n int j, l, lda, ldb, ldc;\n int typenum, nd;\n intp dimensions[MAX_DIMS];\n static const float oneF[2] = {1.0, 0.0};\n static const float zeroF[2] = {0.0, 0.0};\n static const double oneD[2] = {1.0, 0.0};\n static const double zeroD[2] = {0.0, 0.0};\n double prior1, prior2;\n PyTypeObject *subtype;\n PyArray_Descr *dtype;\n MatrixShape ap1shape, ap2shape;\n \n if (!PyArg_ParseTuple(args, \"OO\", &op1, &op2)) return NULL;\n\t\n /* \n * \"Matrix product\" using the BLAS. \n * Only works for float double and complex types.\n */\n\n\n typenum = PyArray_ObjectType(op1, 0); \n typenum = PyArray_ObjectType(op2, typenum);\n \n /* This function doesn't handle other types */\n if ((typenum != PyArray_DOUBLE && typenum != PyArray_CDOUBLE &&\n\t typenum != PyArray_FLOAT && typenum != PyArray_CFLOAT)) {\n\treturn PyArray_Return((PyArrayObject *)PyArray_MatrixProduct(op1, op2));\n }\n \n ret = NULL;\n dtype = PyArray_DescrFromType(typenum);\n ap1 = (PyArrayObject *)PyArray_FromAny(op1, dtype, 0, 0, ALIGNED, NULL);\n if (ap1 == NULL) return NULL;\n ap2 = (PyArrayObject *)PyArray_FromAny(op2, dtype, 0, 0, ALIGNED, NULL);\n if (ap2 == NULL) goto fail;\n \n if ((ap1->nd > 2) || (ap2->nd > 2)) { \n\t/* This function doesn't handle dimensions greater than 2 -- other\n\t than to ensure the dot function is altered\n\t*/\n\tif (!altered) {\n\t /* need to alter dot product */\n\t PyObject *tmp1, *tmp2;\n\t tmp1 = PyTuple_New(0);\n\t tmp2 = dotblas_alterdot(NULL, tmp1);\n\t Py_DECREF(tmp1); \n\t Py_DECREF(tmp2);\n\t}\n\tret = (PyArrayObject *)PyArray_MatrixProduct((PyObject *)ap1, \n\t\t\t\t\t\t (PyObject *)ap2);\n\tPy_DECREF(ap1); \n\tPy_DECREF(ap2);\n\treturn PyArray_Return(ret);\n }\n \n ap1shape = _select_matrix_shape(ap1);\n ap2shape = _select_matrix_shape(ap2);\n \n if (ap1shape == _scalar || ap2shape == _scalar) {\n\t/* One of ap1 or ap2 is a scalar */\n\tif (ap1shape == _scalar) { \t\t/* Make ap2 the scalar */\n\t PyArrayObject *t = ap1;\n\t ap1 = ap2;\n\t ap2 = t;\n\t ap1shape = ap2shape;\n\t ap2shape = _scalar;\n\t}\n\t/* Fix it so that dot(shape=(N,1), shape=(1,))\n\t returns an (N,) array (but uses the fast scalar code)\n\t*/\n\tif (ap1shape == _column && ap2->nd == 1) nd = 1;\n\telse nd = ap1->nd;\n\tfor (l = 1, j = 0; j < nd; j++) {\n\t dimensions[j] = ap1->dimensions[j];\n\t l *= dimensions[j];\n\t}\n }\n else { /* (ap1->nd <= 2 && ap2->nd <= 2) */\n\t/* Both ap1 and ap2 are vectors or matrices */\n\tl = ap1->dimensions[ap1->nd-1];\n\t\n\tif (ap2->dimensions[0] != l) {\n\t PyErr_SetString(PyExc_ValueError, \"matrices are not aligned\");\n\t goto fail;\n\t}\n\tnd = ap1->nd+ap2->nd-2;\n\t\n\tif (nd == 1) \n\t dimensions[0] = (ap1->nd == 2) ? ap1->dimensions[0] : ap2->dimensions[1];\n\telse if (nd == 2) {\n\t dimensions[0] = ap1->dimensions[0];\n\t dimensions[1] = ap2->dimensions[1];\n\t}\n }\n \n /* Choose which subtype to return */\n if (ap1->ob_type != ap2->ob_type) {\n\tprior2 = PyArray_GetPriority((PyObject *)ap2, 0.0);\n\tprior1 = PyArray_GetPriority((PyObject *)ap1, 0.0);\n\tsubtype = (prior2 > prior1 ? ap2->ob_type : ap1->ob_type);\n }\n else {\n\tprior1 = prior2 = 0.0;\n\tsubtype = ap1->ob_type;\n }\n \n if (l==0) nd = 0;\n ret = (PyArrayObject *)PyArray_New(subtype, nd, dimensions,\n\t\t\t\t typenum, NULL, NULL, 0, 0,\n\t\t\t\t (PyObject *)\n\t\t\t\t (prior2 > prior1 ? ap2 : ap1));\n \n if (ret == NULL) goto fail;\n memset(ret->data, 0, PyArray_NBYTES(ret));\n if (l==0) {\n\t Py_DECREF(ap1);\n\t Py_DECREF(ap2);\n\t return PyArray_Return(ret);\n }\n \n if (ap2shape == _scalar) {\n\t/* Multiplication by a scalar -- Level 1 BLAS */\n\t/* if ap1shape is a matrix and we are not contiguous, then we can't\n\t just blast through the entire array using a single\n\t striding factor */\n\tif (typenum == PyArray_DOUBLE) {\n\t if (l == 1) {\n\t\t*((double *)ret->data) = *((double *)ap2->data) * \\\n\t\t *((double *)ap1->data);\n\t }\n\t else if (ap1->nd < 2 || ap1shape == _column) {\n\t\tcblas_daxpy(l, *((double *)ap2->data), (double *)ap1->data,\n\t\t\t ap1->strides[0] / sizeof(double), \n\t\t\t (double *)ret->data, 1);\n\t }\n\t else {\n\t\tint maxind, oind, i, a1s, rets;\n\t\tchar *ptr, *rptr;\n\t\tdouble val;\n\t\tmaxind = (ap1->dimensions[0] >= ap1->dimensions[1] ? 0 : 1);\n\t\toind = 1-maxind;\n\t\tptr = ap1->data;\n\t\trptr = ret->data;\n\t\tl = ap1->dimensions[maxind];\n\t\tval = *((double *)ap2->data);\n\t\ta1s = ap1->strides[maxind] / sizeof(double);\n\t\trets = ret->strides[maxind] / sizeof(double);\n\t\tfor (i=0; i < ap1->dimensions[oind]; i++) {\n\t\t cblas_daxpy(l, val, (double *)ptr, a1s, \n\t\t\t\t(double *)rptr, rets);\n\t\t ptr += ap1->strides[oind];\n\t\t rptr += ret->strides[oind];\n\t\t}\n\t }\n\t} \n\telse if (typenum == PyArray_CDOUBLE) {\n\t if (l == 1) {\n\t\tcdouble *ptr1, *ptr2, *res;\n\t\tptr1 = (cdouble *)ap2->data;\n\t\tptr2 = (cdouble *)ap1->data;\n\t\tres = (cdouble *)ret->data;\t\t\n\t\tres->real = ptr1->real * ptr2->real - ptr1->imag * ptr2->imag;\n\t\tres->imag = ptr1->real * ptr2->imag + ptr1->imag * ptr2->real;\n\t }\n\t else if (ap1->nd < 2 || ap1shape == _column) {\n\t\tcblas_zaxpy(l, (double *)ap2->data, (double *)ap1->data,\n\t\t\t ap1->strides[0] / sizeof(cdouble), \n\t\t\t (double *)ret->data, 1);\n\t }\n\t else {\n\t\tint maxind, oind, i, a1s, rets;\n\t\tchar *ptr, *rptr;\n\t\tdouble *pval;\n\t\tmaxind = (ap1->dimensions[0] >= ap1->dimensions[1] ? 0 : 1);\n\t\toind = 1-maxind;\n\t\tptr = ap1->data;\n\t\trptr = ret->data;\n\t\tl = ap1->dimensions[maxind];\n\t\tpval = (double *)ap2->data;\n\t\ta1s = ap1->strides[maxind] / sizeof(cdouble);\n\t\trets = ret->strides[maxind] / sizeof(cdouble);\n\t\tfor (i=0; i < ap1->dimensions[oind]; i++) {\n\t\t cblas_zaxpy(l, pval, (double *)ptr, a1s, \n\t\t\t\t(double *)rptr, rets);\n\t\t ptr += ap1->strides[oind];\n\t\t rptr += ret->strides[oind];\n\t\t}\n\t }\n\t}\n\telse if (typenum == PyArray_FLOAT) {\n\t if (l == 1) {\n\t\t*((float *)ret->data) = *((float *)ap2->data) * \\\n\t\t *((float *)ap1->data);\n\t }\n\t else if (ap1->nd < 2 || ap1shape == _column) {\n\t\tcblas_saxpy(l, *((float *)ap2->data), (float *)ap1->data,\n\t\t\t ap1->strides[0] / sizeof(float), \n\t\t\t (float *)ret->data, 1);\n\t }\n\t else {\n\t\tint maxind, oind, i, a1s, rets;\n\t\tchar *ptr, *rptr;\n\t\tfloat val;\n\t\tmaxind = (ap1->dimensions[0] >= ap1->dimensions[1] ? 0 : 1);\n\t\toind = 1-maxind;\n\t\tptr = ap1->data;\n\t\trptr = ret->data;\n\t\tl = ap1->dimensions[maxind];\n\t\tval = *((float *)ap2->data);\n\t\ta1s = ap1->strides[maxind] / sizeof(float);\n\t\trets = ret->strides[maxind] / sizeof(float);\n\t\tfor (i=0; i < ap1->dimensions[oind]; i++) {\n\t\t cblas_saxpy(l, val, (float *)ptr, a1s, \n\t\t\t\t(float *)rptr, rets);\n\t\t ptr += ap1->strides[oind];\n\t\t rptr += ret->strides[oind];\n\t\t}\n\t }\n\t}\n\telse if (typenum == PyArray_CFLOAT) {\n\t if (l == 1) {\n\t\tcfloat *ptr1, *ptr2, *res;\n\t\tptr1 = (cfloat *)ap2->data;\n\t\tptr2 = (cfloat *)ap1->data;\n\t\tres = (cfloat *)ret->data;\t\t\n\t\tres->real = ptr1->real * ptr2->real - ptr1->imag * ptr2->imag;\n\t\tres->imag = ptr1->real * ptr2->imag + ptr1->imag * ptr2->real;\n\t }\n\t else if (ap1->nd < 2 || ap1shape == _column) {\n\t\tcblas_caxpy(l, (float *)ap2->data, (float *)ap1->data,\n\t\t\t ap1->strides[0] / sizeof(cfloat), \n\t\t\t (float *)ret->data, 1);\n\t }\n\t else {\n\t\tint maxind, oind, i, a1s, rets;\n\t\tchar *ptr, *rptr;\n\t\tfloat *pval;\n\t\tmaxind = (ap1->dimensions[0] >= ap1->dimensions[1] ? 0 : 1);\n\t\toind = 1-maxind;\n\t\tptr = ap1->data;\n\t\trptr = ret->data;\n\t\tl = ap1->dimensions[maxind];\n\t\tpval = (float *)ap2->data;\n\t\ta1s = ap1->strides[maxind] / sizeof(cfloat);\n\t\trets = ret->strides[maxind] / sizeof(cfloat);\n\t\tfor (i=0; i < ap1->dimensions[oind]; i++) {\n\t\t cblas_caxpy(l, pval, (float *)ptr, a1s, \n\t\t\t\t(float *)rptr, rets);\n\t\t ptr += ap1->strides[oind];\n\t\t rptr += ret->strides[oind];\n\t\t}\n\t }\n\t}\n }\n else if ((ap2shape == _column) && (ap1shape != _matrix)) {\n\tint ap1s, ap2s;\n\tap2s = ap2->strides[0] / ap2->descr->elsize;\n\tif (ap1shape == _row) {\n\t ap1s = ap1->strides[1] / ap1->descr->elsize;\n\t}\n\telse {\n\t ap1s = ap1->strides[0] / ap1->descr->elsize;\n\t}\n\t \n\t/* Dot product between two vectors -- Level 1 BLAS */\n\tif (typenum == PyArray_DOUBLE) {\n\t double result = cblas_ddot(l, (double *)ap1->data, ap1s, \n\t\t\t\t (double *)ap2->data, ap2s);\n\t *((double *)ret->data) = result;\n\t}\n\telse if (typenum == PyArray_FLOAT) {\n\t float result = cblas_sdot(l, (float *)ap1->data, ap1s, \n\t\t\t\t (float *)ap2->data, ap2s);\n\t *((float *)ret->data) = result;\n\t}\n\telse if (typenum == PyArray_CDOUBLE) {\n\t cblas_zdotu_sub(l, (double *)ap1->data, ap1s, \n\t\t\t (double *)ap2->data, ap2s, (double *)ret->data);\n\t}\n\telse if (typenum == PyArray_CFLOAT) {\n\t cblas_cdotu_sub(l, (float *)ap1->data, ap1s, \n\t\t\t (float *)ap2->data, ap2s, (float *)ret->data);\n\t}\n }\n else if (ap1shape == _matrix && ap2shape != _matrix) {\n\t/* Matrix vector multiplication -- Level 2 BLAS */\n\t/* lda must be MAX(M,1) */\n\tenum CBLAS_ORDER Order;\n\tint ap2s;\n\n\tif (!PyArray_ISONESEGMENT(ap1)) {\n\t PyObject *new;\n\t new = PyArray_Copy(ap1);\n\t Py_DECREF(ap1);\n\t ap1 = (PyArrayObject *)new;\n\t if (new == NULL) goto fail;\n\t}\n\tif (PyArray_ISCONTIGUOUS(ap1)) {\n Order = CblasRowMajor;\n lda = (ap1->dimensions[1] > 1 ? ap1->dimensions[1] : 1);\n\t}\n\telse {\n\t Order = CblasColMajor;\n lda = (ap1->dimensions[0] > 1 ? ap1->dimensions[0] : 1);\n\t}\n\tap2s = ap2->strides[0] / ap2->descr->elsize;\n\tif (typenum == PyArray_DOUBLE) {\n\t cblas_dgemv(Order, CblasNoTrans, \n\t\t\tap1->dimensions[0], ap1->dimensions[1], \n\t\t\t1.0, (double *)ap1->data, lda, \n\t\t\t(double *)ap2->data, ap2s, 0.0, (double *)ret->data, 1);\n\t}\n\telse if (typenum == PyArray_FLOAT) {\n\t cblas_sgemv(Order, CblasNoTrans, \n\t\t\tap1->dimensions[0], ap1->dimensions[1], \n\t\t\t1.0, (float *)ap1->data, lda, \n\t\t\t(float *)ap2->data, ap2s, 0.0, (float *)ret->data, 1);\n\t}\n\telse if (typenum == PyArray_CDOUBLE) {\n\t cblas_zgemv(Order, \n\t\t\tCblasNoTrans, ap1->dimensions[0], ap1->dimensions[1], \n\t\t\toneD, (double *)ap1->data, lda, \n\t\t\t(double *)ap2->data, ap2s, zeroD, \n\t\t\t(double *)ret->data, 1);\n\t}\n\telse if (typenum == PyArray_CFLOAT) {\n\t cblas_cgemv(Order, \n\t\t\tCblasNoTrans, ap1->dimensions[0], ap1->dimensions[1], \n\t\t\toneF, (float *)ap1->data, lda, \n\t\t\t(float *)ap2->data, ap2s, zeroF, \n\t\t\t(float *)ret->data, 1);\n\t}\n }\n else if (ap1shape != _matrix && ap2shape == _matrix) {\n\t/* Vector matrix multiplication -- Level 2 BLAS */\n\tenum CBLAS_ORDER Order;\n\tint ap1s;\n\n\tif (!PyArray_ISONESEGMENT(ap2)) {\n\t PyObject *new;\n\t new = PyArray_Copy(ap2);\n\t Py_DECREF(ap2);\n\t ap2 = (PyArrayObject *)new;\n\t if (new == NULL) goto fail;\n\t}\n\tif (PyArray_ISCONTIGUOUS(ap2)) {\n\t Order = CblasRowMajor;\n lda = (ap2->dimensions[1] > 1 ? ap2->dimensions[1] : 1);\n\t}\n\telse {\n\t Order = CblasColMajor;\n lda = (ap2->dimensions[0] > 1 ? ap2->dimensions[0] : 1);\n\t}\n\tif (ap1shape == _row) {\n\t ap1s = ap1->strides[1] / ap1->descr->elsize;\n\t}\n\telse {\n\t ap1s = ap1->strides[0] / ap1->descr->elsize;\n\t}\n\tif (typenum == PyArray_DOUBLE) {\n\t cblas_dgemv(Order, \n\t\t\tCblasTrans, ap2->dimensions[0], ap2->dimensions[1], \n\t\t\t1.0, (double *)ap2->data, lda,\n\t\t\t(double *)ap1->data, ap1s, 0.0, (double *)ret->data, 1);\n\t}\n\telse if (typenum == PyArray_FLOAT) {\n\t cblas_sgemv(Order,\n\t\t\tCblasTrans, ap2->dimensions[0], ap2->dimensions[1], \n\t\t\t1.0, (float *)ap2->data, lda,\n\t\t\t(float *)ap1->data, ap1s, 0.0, (float *)ret->data, 1);\n\t}\n\telse if (typenum == PyArray_CDOUBLE) {\n\t cblas_zgemv(Order,\n\t\t\tCblasTrans, ap2->dimensions[0], ap2->dimensions[1], \n\t\t\toneD, (double *)ap2->data, lda,\n\t\t\t(double *)ap1->data, ap1s, zeroD, (double *)ret->data, 1);\n\t}\n\telse if (typenum == PyArray_CFLOAT) {\n\t cblas_cgemv(Order,\n\t\t\tCblasTrans, ap2->dimensions[0], ap2->dimensions[1], \n\t\t\toneF, (float *)ap2->data, lda,\n\t\t\t(float *)ap1->data, ap1s, zeroF, (float *)ret->data, 1);\n\t}\n }\n else { /* (ap1->nd == 2 && ap2->nd == 2) */\n\t/* Matrix matrix multiplication -- Level 3 BLAS */ \n\t/* L x M multiplied by M x N */\n\tenum CBLAS_ORDER Order;\n\tenum CBLAS_TRANSPOSE Trans1, Trans2;\n\tint M, N, L;\n\n\t/* Optimization possible: */\n\t/* We may be able to handle single-segment arrays here\n\t using appropriate values of Order, Trans1, and Trans2.\n\t*/\n\t\n \tif (!PyArray_ISCONTIGUOUS(ap2)) {\n\t PyObject *new;\n\t new = PyArray_Copy(ap2);\n\t Py_DECREF(ap2);\n\t ap2 = (PyArrayObject *)new;\n\t if (new == NULL) goto fail;\n\t}\n\tif (!PyArray_ISCONTIGUOUS(ap1)) {\n\t PyObject *new;\n\t new = PyArray_Copy(ap1);\n\t Py_DECREF(ap1);\n\t ap1 = (PyArrayObject *)new;\n\t if (new == NULL) goto fail;\n\t}\n\t\n\tOrder = CblasRowMajor;\n\tTrans1 = CblasNoTrans;\n\tTrans2 = CblasNoTrans;\n\tL = ap1->dimensions[0];\n\tN = ap2->dimensions[1];\n\tM = ap2->dimensions[0];\n\tlda = (ap1->dimensions[1] > 1 ? ap1->dimensions[1] : 1);\n\tldb = (ap2->dimensions[1] > 1 ? ap2->dimensions[1] : 1);\n\tldc = (ret->dimensions[1] > 1 ? ret->dimensions[1] : 1);\t \n\tif (typenum == PyArray_DOUBLE) {\n\t cblas_dgemm(Order, Trans1, Trans2, \n\t\t\tL, N, M,\n\t\t\t1.0, (double *)ap1->data, lda,\n\t\t\t(double *)ap2->data, ldb,\n\t\t\t0.0, (double *)ret->data, ldc);\n\t}\n\telse if (typenum == PyArray_FLOAT) {\n\t cblas_sgemm(Order, Trans1, Trans2,\n\t\t\tL, N, M, \n\t\t\t1.0, (float *)ap1->data, lda,\n\t\t\t(float *)ap2->data, ldb,\n\t\t\t0.0, (float *)ret->data, ldc);\n\t}\n\telse if (typenum == PyArray_CDOUBLE) {\n\t cblas_zgemm(Order, Trans1, Trans2,\n\t\t\tL, N, M, \n\t\t\toneD, (double *)ap1->data, lda,\n\t\t\t(double *)ap2->data, ldb,\n\t\t\tzeroD, (double *)ret->data, ldc);\n\t}\n\telse if (typenum == PyArray_CFLOAT) {\n\t cblas_cgemm(Order, Trans1, Trans2,\n\t\t\tL, N, M,\n\t\t\toneF, (float *)ap1->data, lda,\n\t\t\t(float *)ap2->data, ldb,\n\t\t\tzeroF, (float *)ret->data, ldc);\n\t}\n }\n\n Py_DECREF(ap1);\n Py_DECREF(ap2);\n return PyArray_Return(ret);\n\t\n fail:\n Py_XDECREF(ap1);\n Py_XDECREF(ap2);\n Py_XDECREF(ret);\n return NULL;\n}\n\n\nstatic char doc_innerproduct[] = \"innerproduct(a,b)\\nReturns the inner product of a and b for arrays of floating point types.\\nLike the generic Numeric equivalent the product sum is over\\nthe last dimension of a and b.\\nNB: The first argument is not conjugated.\";\n\nstatic PyObject *\ndotblas_innerproduct(PyObject *dummy, PyObject *args) \n{\n PyObject *op1, *op2;\n PyArrayObject *ap1, *ap2, *ret;\n int j, l, lda, ldb, ldc;\n int typenum, nd;\n intp dimensions[MAX_DIMS];\n static const float oneF[2] = {1.0, 0.0};\n static const float zeroF[2] = {0.0, 0.0};\n static const double oneD[2] = {1.0, 0.0};\n static const double zeroD[2] = {0.0, 0.0};\n PyTypeObject *subtype;\n double prior1, prior2;\n\n if (!PyArg_ParseTuple(args, \"OO\", &op1, &op2)) return NULL;\n\t\n /* \n * Inner product using the BLAS. The product sum is taken along the last\n * dimensions of the two arrays.\n * Only speeds things up for float double and complex types.\n */\n\n\n typenum = PyArray_ObjectType(op1, 0); \n typenum = PyArray_ObjectType(op2, typenum);\n\n /* This function doesn't handle other types */\n if ((typenum != PyArray_DOUBLE && typenum != PyArray_CDOUBLE &&\n\t typenum != PyArray_FLOAT && typenum != PyArray_CFLOAT)) {\n return PyArray_Return((PyArrayObject *)PyArray_InnerProduct(op1, op2));\n }\n\n ret = NULL;\n ap1 = (PyArrayObject *)PyArray_ContiguousFromObject(op1, typenum, 0, 0);\n if (ap1 == NULL) return NULL;\n ap2 = (PyArrayObject *)PyArray_ContiguousFromObject(op2, typenum, 0, 0);\n if (ap2 == NULL) goto fail;\n\n if ((ap1->nd > 2) || (ap2->nd > 2)) { \n\t/* This function doesn't handle dimensions greater than 2 -- other\n\t than to ensure the dot function is altered\n\t*/\n\tif (!altered) {\n\t /* need to alter dot product */\n\t PyObject *tmp1, *tmp2;\n\t tmp1 = PyTuple_New(0);\n\t tmp2 = dotblas_alterdot(NULL, tmp1);\n\t Py_DECREF(tmp1); \n\t Py_DECREF(tmp2);\n\t}\n\tret = (PyArrayObject *)PyArray_InnerProduct((PyObject *)ap1, \n\t\t\t\t\t\t (PyObject *)ap2);\n\tPy_DECREF(ap1); \n\tPy_DECREF(ap2);\n\treturn PyArray_Return(ret);\n }\n\n if (ap1->nd == 0 || ap2->nd == 0) {\n\t/* One of ap1 or ap2 is a scalar */\n\tif (ap1->nd == 0) {\t\t/* Make ap2 the scalar */\n\t PyArrayObject *t = ap1;\n\t ap1 = ap2;\n\t ap2 = t;\n\t}\n\tfor (l = 1, j = 0; j < ap1->nd; j++) {\n\t dimensions[j] = ap1->dimensions[j];\n\t l *= dimensions[j];\n\t}\n\tnd = ap1->nd;\n }\n else { /* (ap1->nd <= 2 && ap2->nd <= 2) */\n\t/* Both ap1 and ap2 are vectors or matrices */\n\tl = ap1->dimensions[ap1->nd-1];\n\t\n\tif (ap2->dimensions[ap2->nd-1] != l) {\n\t PyErr_SetString(PyExc_ValueError, \"matrices are not aligned\");\n\t goto fail;\n\t}\n\tnd = ap1->nd+ap2->nd-2;\n \n\tif (nd == 1) \n\t dimensions[0] = (ap1->nd == 2) ? ap1->dimensions[0] : ap2->dimensions[0];\n\telse if (nd == 2) {\n\t dimensions[0] = ap1->dimensions[0];\n\t dimensions[1] = ap2->dimensions[0];\n\t}\n }\n\n /* Choose which subtype to return */\n prior2 = PyArray_GetPriority((PyObject *)ap2, 0.0);\n prior1 = PyArray_GetPriority((PyObject *)ap1, 0.0);\n subtype = (prior2 > prior1 ? ap2->ob_type : ap1->ob_type);\n \n ret = (PyArrayObject *)PyArray_New(subtype, nd, dimensions, \n\t\t\t\t typenum, NULL, NULL, 0, 0, \n\t\t\t\t (PyObject *)\\\n\t\t\t\t (prior2 > prior1 ? ap2 : ap1));\n \n if (ret == NULL) goto fail;\n memset(ret->data, 0, PyArray_NBYTES(ret));\n\n if (ap2->nd == 0) {\n\t/* Multiplication by a scalar -- Level 1 BLAS */\n\tif (typenum == PyArray_DOUBLE) {\n\t cblas_daxpy(l, *((double *)ap2->data), (double *)ap1->data, 1,\n\t\t\t(double *)ret->data, 1);\n\t} \n\telse if (typenum == PyArray_CDOUBLE) {\n\t cblas_zaxpy(l, (double *)ap2->data, (double *)ap1->data, 1,\n\t\t\t(double *)ret->data, 1);\n\t}\n\telse if (typenum == PyArray_FLOAT) {\n\t cblas_saxpy(l, *((float *)ap2->data), (float *)ap1->data, 1,\n\t\t\t(float *)ret->data, 1);\n\t}\n\telse if (typenum == PyArray_CFLOAT) {\n\t cblas_caxpy(l, (float *)ap2->data, (float *)ap1->data, 1,\n\t\t\t(float *)ret->data, 1);\n\t}\n }\n else if (ap1->nd == 1 && ap2->nd == 1) {\n\t/* Dot product between two vectors -- Level 1 BLAS */\n\tif (typenum == PyArray_DOUBLE) {\n\t double result = cblas_ddot(l, (double *)ap1->data, 1, \n\t\t\t\t (double *)ap2->data, 1);\n\t *((double *)ret->data) = result;\n\t}\n\telse if (typenum == PyArray_CDOUBLE) {\n\t cblas_zdotu_sub(l, (double *)ap1->data, 1, \n\t\t\t (double *)ap2->data, 1, (double *)ret->data);\n\t}\n\telse if (typenum == PyArray_FLOAT) {\n\t float result = cblas_sdot(l, (float *)ap1->data, 1, \n\t\t\t\t (float *)ap2->data, 1);\n\t *((float *)ret->data) = result;\n\t}\n\telse if (typenum == PyArray_CFLOAT) {\n\t cblas_cdotu_sub(l, (float *)ap1->data, 1, \n\t\t\t (float *)ap2->data, 1, (float *)ret->data);\n\t}\n }\n else if (ap1->nd == 2 && ap2->nd == 1) {\n\t/* Matrix-vector multiplication -- Level 2 BLAS */\n\tlda = (ap1->dimensions[1] > 1 ? ap1->dimensions[1] : 1);\n\tif (typenum == PyArray_DOUBLE) {\n\t cblas_dgemv(CblasRowMajor, \n\t\t\tCblasNoTrans, ap1->dimensions[0], ap1->dimensions[1], \n\t\t\t1.0, (double *)ap1->data, lda,\n\t\t\t(double *)ap2->data, 1, 0.0, (double *)ret->data, 1);\n\t}\n\telse if (typenum == PyArray_CDOUBLE) {\n\t cblas_zgemv(CblasRowMajor, \n\t\t\tCblasNoTrans, ap1->dimensions[0], ap1->dimensions[1], \n\t\t\toneD, (double *)ap1->data, lda,\n\t\t\t(double *)ap2->data, 1, zeroD, (double *)ret->data, 1);\n\t}\n\telse if (typenum == PyArray_FLOAT) {\n\t cblas_sgemv(CblasRowMajor, \n\t\t\tCblasNoTrans, ap1->dimensions[0], ap1->dimensions[1], \n\t\t\t1.0, (float *)ap1->data, lda,\n\t\t\t(float *)ap2->data, 1, 0.0, (float *)ret->data, 1);\n\t}\n\telse if (typenum == PyArray_CFLOAT) {\n\t cblas_cgemv(CblasRowMajor, \n\t\t\tCblasNoTrans, ap1->dimensions[0], ap1->dimensions[1], \n\t\t\toneF, (float *)ap1->data, lda,\n\t\t\t(float *)ap2->data, 1, zeroF, (float *)ret->data, 1);\n\t}\n }\n else if (ap1->nd == 1 && ap2->nd == 2) {\n\t/* Vector matrix multiplication -- Level 2 BLAS */\n\tlda = (ap2->dimensions[1] > 1 ? ap2->dimensions[1] : 1);\n\tif (typenum == PyArray_DOUBLE) {\n\t cblas_dgemv(CblasRowMajor, \n\t\t\tCblasNoTrans, ap2->dimensions[0], ap2->dimensions[1], \n\t\t\t1.0, (double *)ap2->data, lda,\n\t\t\t(double *)ap1->data, 1, 0.0, (double *)ret->data, 1);\n\t}\n\telse if (typenum == PyArray_CDOUBLE) {\n\t cblas_zgemv(CblasRowMajor, \n\t\t\tCblasNoTrans, ap2->dimensions[0], ap2->dimensions[1], \n\t\t\toneD, (double *)ap2->data, lda,\n\t\t\t(double *)ap1->data, 1, zeroD, (double *)ret->data, 1);\n\t}\n\telse if (typenum == PyArray_FLOAT) {\n\t cblas_sgemv(CblasRowMajor, \n\t\t\tCblasNoTrans, ap2->dimensions[0], ap2->dimensions[1], \n\t\t\t1.0, (float *)ap2->data, lda,\n\t\t\t(float *)ap1->data, 1, 0.0, (float *)ret->data, 1);\n\t}\n\telse if (typenum == PyArray_CFLOAT) {\n\t cblas_cgemv(CblasRowMajor, \n\t\t\tCblasNoTrans, ap2->dimensions[0], ap2->dimensions[1], \n\t\t\toneF, (float *)ap2->data, lda,\n\t\t\t(float *)ap1->data, 1, zeroF, (float *)ret->data, 1);\n\t}\n }\n else { /* (ap1->nd == 2 && ap2->nd == 2) */ \n\t/* Matrix matrix multiplication -- Level 3 BLAS */ \n\tlda = (ap1->dimensions[1] > 1 ? ap1->dimensions[1] : 1);\n\tldb = (ap2->dimensions[1] > 1 ? ap2->dimensions[1] : 1);\n\tldc = (ret->dimensions[1] > 1 ? ret->dimensions[1] : 1);\n\tif (typenum == PyArray_DOUBLE) {\n\t cblas_dgemm(CblasRowMajor, CblasNoTrans, CblasTrans,\n\t\t\tap1->dimensions[0], ap2->dimensions[0], ap1->dimensions[1],\n\t\t\t1.0, (double *)ap1->data, lda,\n\t\t\t(double *)ap2->data, ldb,\n\t\t\t0.0, (double *)ret->data, ldc);\n\t}\n\telse if (typenum == PyArray_FLOAT) {\n\t cblas_sgemm(CblasRowMajor, CblasNoTrans, CblasTrans,\n\t\t\tap1->dimensions[0], ap2->dimensions[0], ap1->dimensions[1],\n\t\t\t1.0, (float *)ap1->data, lda,\n\t\t\t(float *)ap2->data, ldb,\n\t\t\t0.0, (float *)ret->data, ldc);\n\t}\n\telse if (typenum == PyArray_CDOUBLE) {\n\t cblas_zgemm(CblasRowMajor, CblasNoTrans, CblasTrans,\n\t\t\tap1->dimensions[0], ap2->dimensions[0], ap1->dimensions[1],\n\t\t\toneD, (double *)ap1->data, lda,\n\t\t\t(double *)ap2->data, ldb,\n\t\t\tzeroD, (double *)ret->data, ldc);\n\t}\n\telse if (typenum == PyArray_CFLOAT) {\n\t cblas_cgemm(CblasRowMajor, CblasNoTrans, CblasTrans,\n\t\t\tap1->dimensions[0], ap2->dimensions[0], ap1->dimensions[1],\n\t\t\toneF, (float *)ap1->data, lda,\n\t\t\t(float *)ap2->data, ldb,\n\t\t\tzeroF, (float *)ret->data, ldc);\n\t}\n }\n Py_DECREF(ap1);\n Py_DECREF(ap2);\n return PyArray_Return(ret);\n\t\n fail:\n Py_XDECREF(ap1);\n Py_XDECREF(ap2);\n Py_XDECREF(ret);\n return NULL;\n}\n\n\nstatic char doc_vdot[] = \"vdot(a,b)\\nReturns the dot product of a and b for scalars and vectors\\nof floating point and complex types. The first argument, a, is conjugated.\";\n\n\nstatic PyObject *dotblas_vdot(PyObject *dummy, PyObject *args) {\n PyObject *op1, *op2;\n PyArrayObject *ap1=NULL, *ap2=NULL, *ret=NULL;\n int l;\n int typenum;\n intp dimensions[MAX_DIMS];\n PyArray_Descr *type;\n\n if (!PyArg_ParseTuple(args, \"OO\", &op1, &op2)) return NULL;\n\t\n /* \n * Conjugating dot product using the BLAS for vectors.\n * Multiplies op1 and op2, each of which must be vector.\n */\n\n typenum = PyArray_ObjectType(op1, 0); \n typenum = PyArray_ObjectType(op2, typenum);\n \n type = PyArray_DescrFromType(typenum);\n \n ap1 = (PyArrayObject *)PyArray_FromAny(op1, type, 0, 0, 0, NULL);\n if (ap1==NULL) goto fail;\n op1 = PyArray_Flatten(ap1, 0);\n if (op1==NULL) goto fail;\n Py_DECREF(ap1);\n ap1 = (PyArrayObject *)op1;\n \n ap2 = (PyArrayObject *)PyArray_FromAny(op2, type, 0, 0, 0, NULL);\n if (ap2==NULL) goto fail;\n op2 = PyArray_Flatten(ap2, 0);\n if (op2 == NULL) goto fail;\n Py_DECREF(ap2);\n ap2 = (PyArrayObject *)op2;\n \n if (typenum != PyArray_FLOAT && typenum != PyArray_DOUBLE &&\n\ttypenum != PyArray_CFLOAT && typenum != PyArray_CDOUBLE) {\n\tif (!altered) {\n\t /* need to alter dot product */\n\t PyObject *tmp1, *tmp2;\n\t tmp1 = PyTuple_New(0);\n\t tmp2 = dotblas_alterdot(NULL, tmp1);\n\t Py_DECREF(tmp1); \n\t Py_DECREF(tmp2);\n\t}\n\tif (PyTypeNum_ISCOMPLEX(typenum)) {\n\t op1 = PyArray_Conjugate(ap1);\n\t if (op1==NULL) goto fail;\n\t Py_DECREF(ap1);\n\t ap1 = (PyArrayObject *)op1;\n\t}\t\n\tret = (PyArrayObject *)PyArray_InnerProduct((PyObject *)ap1, \n\t\t\t\t\t\t (PyObject *)ap2);\n\tPy_DECREF(ap1); \n\tPy_DECREF(ap2);\n\treturn PyArray_Return(ret);\n }\n\n if (ap2->dimensions[0] != ap1->dimensions[ap1->nd-1]) {\n\tPyErr_SetString(PyExc_ValueError, \"vectors have different lengths\");\n\tgoto fail;\n }\n l = ap1->dimensions[ap1->nd-1];\n \n ret = (PyArrayObject *)PyArray_SimpleNew(0, dimensions, typenum);\n if (ret == NULL) goto fail;\n\n\n /* Dot product between two vectors -- Level 1 BLAS */\n if (typenum == PyArray_DOUBLE) {\n\t*((double *)ret->data) = cblas_ddot(l, (double *)ap1->data, 1, \n\t\t\t\t\t (double *)ap2->data, 1);\n }\n else if (typenum == PyArray_FLOAT) {\n\t*((float *)ret->data) = cblas_sdot(l, (float *)ap1->data, 1, \n\t\t\t\t\t (float *)ap2->data, 1);\n }\n else if (typenum == PyArray_CDOUBLE) {\n\tcblas_zdotc_sub(l, (double *)ap1->data, 1, \n\t\t\t(double *)ap2->data, 1, (double *)ret->data);\n }\n else if (typenum == PyArray_CFLOAT) {\n\tcblas_cdotc_sub(l, (float *)ap1->data, 1, \n\t\t\t(float *)ap2->data, 1, (float *)ret->data);\n }\n\n Py_DECREF(ap1);\n Py_DECREF(ap2);\n return PyArray_Return(ret);\n\t\n fail:\n Py_XDECREF(ap1);\n Py_XDECREF(ap2);\n Py_XDECREF(ret);\n return NULL;\n}\n\nstatic struct PyMethodDef dotblas_module_methods[] = {\n {\"dot\", (PyCFunction)dotblas_matrixproduct, 1, doc_matrixproduct},\n {\"inner\", (PyCFunction)dotblas_innerproduct, 1, doc_innerproduct},\n {\"vdot\", (PyCFunction)dotblas_vdot, 1, doc_vdot},\n {\"alterdot\", (PyCFunction)dotblas_alterdot, 1, doc_alterdot},\n {\"restoredot\", (PyCFunction)dotblas_restoredot, 1, doc_restoredot},\n {NULL,\t\tNULL, 0}\t\t/* sentinel */\n};\n\n/* Initialization function for the module */\nDL_EXPORT(void) init_dotblas(void) {\n int i;\n PyObject *m, *d, *s;\n \n /* Create the module and add the functions */\n m = Py_InitModule3(\"_dotblas\", dotblas_module_methods, module_doc);\n\n /* Import the array object */\n import_array();\n\n /* Initialise the array of dot functions */\n for (i = 0; i < PyArray_NTYPES; i++)\n\toldFunctions[i] = NULL;\n\n /* alterdot at load */\n d = PyTuple_New(0);\n s = dotblas_alterdot(NULL, d);\n Py_DECREF(d);\n Py_DECREF(s);\n \n}\n", + "methods": [ + { + "name": "FLOAT_dot", + "long_name": "FLOAT_dot( * a , intp stridea , * b , intp strideb , * res , intp n , * tmp)", + "filename": "_dotblas.c", + "nloc": 7, + "complexity": 1, + "token_count": 84, + "parameters": [ + "a", + "stridea", + "b", + "strideb", + "res", + "n", + "tmp" + ], + "start_line": 14, + "end_line": 21, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 8, + "top_nesting_level": 0 + }, + { + "name": "DOUBLE_dot", + "long_name": "DOUBLE_dot( * a , intp stridea , * b , intp strideb , * res , intp n , * tmp)", + "filename": "_dotblas.c", + "nloc": 7, + "complexity": 1, + "token_count": 84, + "parameters": [ + "a", + "stridea", + "b", + "strideb", + "res", + "n", + "tmp" + ], + "start_line": 24, + "end_line": 31, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 8, + "top_nesting_level": 0 + }, + { + "name": "CFLOAT_dot", + "long_name": "CFLOAT_dot( * a , intp stridea , * b , intp strideb , * res , intp n , * tmp)", + "filename": "_dotblas.c", + "nloc": 7, + "complexity": 1, + "token_count": 81, + "parameters": [ + "a", + "stridea", + "b", + "strideb", + "res", + "n", + "tmp" + ], + "start_line": 34, + "end_line": 42, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 9, + "top_nesting_level": 0 + }, + { + "name": "CDOUBLE_dot", + "long_name": "CDOUBLE_dot( * a , intp stridea , * b , intp strideb , * res , intp n , * tmp)", + "filename": "_dotblas.c", + "nloc": 7, + "complexity": 1, + "token_count": 81, + "parameters": [ + "a", + "stridea", + "b", + "strideb", + "res", + "n", + "tmp" + ], + "start_line": 45, + "end_line": 52, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 8, + "top_nesting_level": 0 + }, + { + "name": "dotblas_alterdot", + "long_name": "dotblas_alterdot( PyObject * dummy , PyObject * args)", + "filename": "_dotblas.c", + "nloc": 22, + "complexity": 3, + "token_count": 168, + "parameters": [ + "dummy", + "args" + ], + "start_line": 61, + "end_line": 91, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 31, + "top_nesting_level": 0 + }, + { + "name": "dotblas_restoredot", + "long_name": "dotblas_restoredot( PyObject * dummy , PyObject * args)", + "filename": "_dotblas.c", + "nloc": 26, + "complexity": 3, + "token_count": 167, + "parameters": [ + "dummy", + "args" + ], + "start_line": 96, + "end_line": 128, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 33, + "top_nesting_level": 0 + }, + { + "name": "_select_matrix_shape", + "long_name": "_select_matrix_shape( PyArrayObject * array)", + "filename": "_dotblas.c", + "nloc": 22, + "complexity": 8, + "token_count": 96, + "parameters": [ + "array" + ], + "start_line": 133, + "end_line": 154, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 22, + "top_nesting_level": 0 + }, + { + "name": "dotblas_matrixproduct", + "long_name": "dotblas_matrixproduct( PyObject * dummy , PyObject * args)", + "filename": "_dotblas.c", + "nloc": 424, + "complexity": 91, + "token_count": 3599, + "parameters": [ + "dummy", + "args" + ], + "start_line": 160, + "end_line": 636, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 477, + "top_nesting_level": 0 + }, + { + "name": "dotblas_innerproduct", + "long_name": "dotblas_innerproduct( PyObject * dummy , PyObject * args)", + "filename": "_dotblas.c", + "nloc": 208, + "complexity": 54, + "token_count": 2023, + "parameters": [ + "dummy", + "args" + ], + "start_line": 642, + "end_line": 882, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 241, + "top_nesting_level": 0 + }, + { + "name": "dotblas_vdot", + "long_name": "dotblas_vdot( PyObject * dummy , PyObject * args)", + "filename": "_dotblas.c", + "nloc": 76, + "complexity": 19, + "token_count": 630, + "parameters": [ + "dummy", + "args" + ], + "start_line": 888, + "end_line": 982, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 95, + "top_nesting_level": 0 + }, + { + "name": "init_dotblas", + "long_name": "init_dotblas()", + "filename": "_dotblas.c", + "nloc": 12, + "complexity": 2, + "token_count": 79, + "parameters": [], + "start_line": 994, + "end_line": 1014, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 21, + "top_nesting_level": 0 + } + ], + "methods_before": [ + { + "name": "FLOAT_dot", + "long_name": "FLOAT_dot( * a , intp stridea , * b , intp strideb , * res , intp n , * tmp)", + "filename": "_dotblas.c", + "nloc": 7, + "complexity": 1, + "token_count": 84, + "parameters": [ + "a", + "stridea", + "b", + "strideb", + "res", + "n", + "tmp" + ], + "start_line": 14, + "end_line": 21, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 8, + "top_nesting_level": 0 + }, + { + "name": "DOUBLE_dot", + "long_name": "DOUBLE_dot( * a , intp stridea , * b , intp strideb , * res , intp n , * tmp)", + "filename": "_dotblas.c", + "nloc": 7, + "complexity": 1, + "token_count": 84, + "parameters": [ + "a", + "stridea", + "b", + "strideb", + "res", + "n", + "tmp" + ], + "start_line": 24, + "end_line": 31, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 8, + "top_nesting_level": 0 + }, + { + "name": "CFLOAT_dot", + "long_name": "CFLOAT_dot( * a , intp stridea , * b , intp strideb , * res , intp n , * tmp)", + "filename": "_dotblas.c", + "nloc": 7, + "complexity": 1, + "token_count": 81, + "parameters": [ + "a", + "stridea", + "b", + "strideb", + "res", + "n", + "tmp" + ], + "start_line": 34, + "end_line": 42, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 9, + "top_nesting_level": 0 + }, + { + "name": "CDOUBLE_dot", + "long_name": "CDOUBLE_dot( * a , intp stridea , * b , intp strideb , * res , intp n , * tmp)", + "filename": "_dotblas.c", + "nloc": 7, + "complexity": 1, + "token_count": 81, + "parameters": [ + "a", + "stridea", + "b", + "strideb", + "res", + "n", + "tmp" + ], + "start_line": 45, + "end_line": 52, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 8, + "top_nesting_level": 0 + }, + { + "name": "dotblas_alterdot", + "long_name": "dotblas_alterdot( PyObject * dummy , PyObject * args)", + "filename": "_dotblas.c", + "nloc": 22, + "complexity": 3, + "token_count": 168, + "parameters": [ + "dummy", + "args" + ], + "start_line": 61, + "end_line": 91, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 31, + "top_nesting_level": 0 + }, + { + "name": "dotblas_restoredot", + "long_name": "dotblas_restoredot( PyObject * dummy , PyObject * args)", + "filename": "_dotblas.c", + "nloc": 26, + "complexity": 3, + "token_count": 167, + "parameters": [ + "dummy", + "args" + ], + "start_line": 96, + "end_line": 128, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 33, + "top_nesting_level": 0 + }, + { + "name": "_select_matrix_shape", + "long_name": "_select_matrix_shape( PyArrayObject * array)", + "filename": "_dotblas.c", + "nloc": 22, + "complexity": 8, + "token_count": 96, + "parameters": [ + "array" + ], + "start_line": 133, + "end_line": 154, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 22, + "top_nesting_level": 0 + }, + { + "name": "dotblas_matrixproduct", + "long_name": "dotblas_matrixproduct( PyObject * dummy , PyObject * args)", + "filename": "_dotblas.c", + "nloc": 412, + "complexity": 93, + "token_count": 3563, + "parameters": [ + "dummy", + "args" + ], + "start_line": 160, + "end_line": 623, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 464, + "top_nesting_level": 0 + }, + { + "name": "dotblas_innerproduct", + "long_name": "dotblas_innerproduct( PyObject * dummy , PyObject * args)", + "filename": "_dotblas.c", + "nloc": 208, + "complexity": 54, + "token_count": 2023, + "parameters": [ + "dummy", + "args" + ], + "start_line": 629, + "end_line": 869, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 241, + "top_nesting_level": 0 + }, + { + "name": "dotblas_vdot", + "long_name": "dotblas_vdot( PyObject * dummy , PyObject * args)", + "filename": "_dotblas.c", + "nloc": 76, + "complexity": 19, + "token_count": 630, + "parameters": [ + "dummy", + "args" + ], + "start_line": 875, + "end_line": 969, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 95, + "top_nesting_level": 0 + }, + { + "name": "init_dotblas", + "long_name": "init_dotblas()", + "filename": "_dotblas.c", + "nloc": 12, + "complexity": 2, + "token_count": 79, + "parameters": [], + "start_line": 981, + "end_line": 1001, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 21, + "top_nesting_level": 0 + } + ], + "changed_methods": [ + { + "name": "dotblas_matrixproduct", + "long_name": "dotblas_matrixproduct( PyObject * dummy , PyObject * args)", + "filename": "_dotblas.c", + "nloc": 424, + "complexity": 91, + "token_count": 3599, + "parameters": [ + "dummy", + "args" + ], + "start_line": 160, + "end_line": 636, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 477, + "top_nesting_level": 0 + } + ], + "nloc": 849, + "complexity": 184, + "token_count": 7287, + "diff_parsed": { + "added": [ + " intp ap1stride;", + "\t and dot(shape=(1,), shape=(1,N)) both return", + "\t an (N,) array (but use the fast scalar code)", + "\tif ((ap1shape == _column || ap1shape == _row) && \\", + "\t (ap2->nd == 1)) {", + "\t nd = 1;", + "\t if (ap1shape == _column) {", + "\t\tdimensions[0] = ap1->dimensions[0];", + "\t\tap1stride = ap1->strides[0] / sizeof(double);", + "\t }", + "\t else {", + "\t\tdimensions[0] = ap1->dimensions[1];", + "\t\tap1stride = ap1->strides[1] / sizeof(double);", + "\t }", + "\t l = dimensions[0];", + "\t}", + "\telse {", + "\t ap1stride = ap1->strides[0] / sizeof(double);", + "\t nd = ap1->nd;", + "\t for (l = 1, j = 0; j < nd; j++) {", + "\t\tdimensions[j] = ap1->dimensions[j];", + "\t\tl *= dimensions[j];", + "\t }", + "\t else if (ap1shape != _matrix) {", + "\t\t\t ap1stride, (double *)ret->data, 1);", + "\t else if (ap1shape != _matrix) {", + "\t\t\t ap1stride, (double *)ret->data, 1);", + "\t else if (ap1shape != _matrix) {", + "\t\t\t ap1stride, (float *)ret->data, 1);", + "\t else if (ap1shape != _matrix) {", + "\t\t\t ap1stride, (float *)ret->data, 1);" + ], + "deleted": [ + "\t returns an (N,) array (but uses the fast scalar code)", + "\tif (ap1shape == _column && ap2->nd == 1) nd = 1;", + "\telse nd = ap1->nd;", + "\tfor (l = 1, j = 0; j < nd; j++) {", + "\t dimensions[j] = ap1->dimensions[j];", + "\t l *= dimensions[j];", + "\t else if (ap1->nd < 2 || ap1shape == _column) {", + "\t\t\t ap1->strides[0] / sizeof(double),", + "\t\t\t (double *)ret->data, 1);", + "\t else if (ap1->nd < 2 || ap1shape == _column) {", + "\t\t\t ap1->strides[0] / sizeof(cdouble),", + "\t\t\t (double *)ret->data, 1);", + "\t else if (ap1->nd < 2 || ap1shape == _column) {", + "\t\t\t ap1->strides[0] / sizeof(float),", + "\t\t\t (float *)ret->data, 1);", + "\t else if (ap1->nd < 2 || ap1shape == _column) {", + "\t\t\t ap1->strides[0] / sizeof(cfloat),", + "\t\t\t (float *)ret->data, 1);" + ] + } + }, + { + "old_path": "numpy/core/tests/test_numeric.py", + "new_path": "numpy/core/tests/test_numeric.py", + "filename": "test_numeric.py", + "extension": "py", + "change_type": "MODIFY", + "diff": "@@ -71,6 +71,14 @@ def check_columnvect(self):\n \tc2 = dot_(b1,b2)\n \tassert_almost_equal(c1, c2, decimal=self.N)\n \n+ def check_columnvect(self):\n+\tb1 = ones((3,1)).transpose()\n+\tb2 = [6.2]\n+\tc1 = dot(b2,b1)\n+\tc2 = dot_(b2,b1)\n+\tassert_almost_equal(c1, c2, decimal=self.N)\n+\n+\n \n class test_bool_scalar(ScipyTestCase):\n def test_logical(self):\n", + "added_lines": 8, + "deleted_lines": 0, + "source_code": "from numpy.core import *\nfrom numpy.random import rand\nfrom numpy.testing import *\nfrom numpy.core.multiarray import dot as dot_\n\nclass test_dot(ScipyTestCase):\n def setUp(self):\n self.A = rand(10,8)\n self.b1 = rand(8,1)\n self.b2 = rand(8)\n self.b3 = rand(1,8)\n self.b4 = rand(10)\n self.N = 14\n\n def check_matmat(self):\n A = self.A\n c1 = dot(A.transpose(), A)\n c2 = dot_(A.transpose(), A)\n assert_almost_equal(c1, c2, decimal=self.N)\n\n def check_matvec(self):\n A, b1 = self.A, self.b1\n c1 = dot(A, b1)\n c2 = dot_(A, b1)\n assert_almost_equal(c1, c2, decimal=self.N)\n\n def check_matvec2(self):\n A, b2 = self.A, self.b2 \n c1 = dot(A, b2)\n c2 = dot_(A, b2)\n assert_almost_equal(c1, c2, decimal=self.N)\n\n def check_vecmat(self):\n A, b4 = self.A, self.b4\n c1 = dot(b4, A)\n c2 = dot_(b4, A)\n assert_almost_equal(c1, c2, decimal=self.N)\n\n def check_vecmat2(self):\n b3, A = self.b3, self.A\n c1 = dot(b3, A.transpose())\n c2 = dot_(b3, A.transpose())\n assert_almost_equal(c1, c2, decimal=self.N)\n\n def check_vecmat3(self):\n A, b4 = self.A, self.b4\n c1 = dot(A.transpose(),b4)\n c2 = dot_(A.transpose(),b4)\n assert_almost_equal(c1, c2, decimal=self.N) \n\n def check_vecvecouter(self):\n b1, b3 = self.b1, self.b3\n c1 = dot(b1, b3)\n c2 = dot_(b1, b3)\n assert_almost_equal(c1, c2, decimal=self.N)\n\n def check_vecvecinner(self):\n b1, b3 = self.b1, self.b3\n c1 = dot(b3, b1)\n c2 = dot_(b3, b1)\n assert_almost_equal(c1, c2, decimal=self.N)\n\n def check_matscalar(self):\n\tb1 = matrix(ones((3,3),dtype=complex))\n\tassert_equal(b1*1.0, b1)\n\n def check_columnvect(self):\n\tb1 = ones((3,1))\n\tb2 = [5.3]\n\tc1 = dot(b1,b2)\n\tc2 = dot_(b1,b2)\n\tassert_almost_equal(c1, c2, decimal=self.N)\n\n def check_columnvect(self):\n\tb1 = ones((3,1)).transpose()\n\tb2 = [6.2]\n\tc1 = dot(b2,b1)\n\tc2 = dot_(b2,b1)\n\tassert_almost_equal(c1, c2, decimal=self.N)\n\n\n\nclass test_bool_scalar(ScipyTestCase):\n def test_logical(self):\n f = False_\n t = True_\n s = \"xyz\"\n self.failUnless((t and s) is s)\n self.failUnless((f and s) is f)\n\n def test_bitwise_or(self):\n f = False_\n t = True_\n self.failUnless((t | t) is t)\n self.failUnless((f | t) is t)\n self.failUnless((t | f) is t)\n self.failUnless((f | f) is f)\n\n def test_bitwise_and(self): \n f = False_\n t = True_\n self.failUnless((t & t) is t)\n self.failUnless((f & t) is f)\n self.failUnless((t & f) is f)\n self.failUnless((f & f) is f)\n\n def test_bitwise_xor(self): \n f = False_\n t = True_\n self.failUnless((t ^ t) is f)\n self.failUnless((f ^ t) is t)\n self.failUnless((t ^ f) is t)\n self.failUnless((f ^ f) is f)\n \n \n \n", + "source_code_before": "from numpy.core import *\nfrom numpy.random import rand\nfrom numpy.testing import *\nfrom numpy.core.multiarray import dot as dot_\n\nclass test_dot(ScipyTestCase):\n def setUp(self):\n self.A = rand(10,8)\n self.b1 = rand(8,1)\n self.b2 = rand(8)\n self.b3 = rand(1,8)\n self.b4 = rand(10)\n self.N = 14\n\n def check_matmat(self):\n A = self.A\n c1 = dot(A.transpose(), A)\n c2 = dot_(A.transpose(), A)\n assert_almost_equal(c1, c2, decimal=self.N)\n\n def check_matvec(self):\n A, b1 = self.A, self.b1\n c1 = dot(A, b1)\n c2 = dot_(A, b1)\n assert_almost_equal(c1, c2, decimal=self.N)\n\n def check_matvec2(self):\n A, b2 = self.A, self.b2 \n c1 = dot(A, b2)\n c2 = dot_(A, b2)\n assert_almost_equal(c1, c2, decimal=self.N)\n\n def check_vecmat(self):\n A, b4 = self.A, self.b4\n c1 = dot(b4, A)\n c2 = dot_(b4, A)\n assert_almost_equal(c1, c2, decimal=self.N)\n\n def check_vecmat2(self):\n b3, A = self.b3, self.A\n c1 = dot(b3, A.transpose())\n c2 = dot_(b3, A.transpose())\n assert_almost_equal(c1, c2, decimal=self.N)\n\n def check_vecmat3(self):\n A, b4 = self.A, self.b4\n c1 = dot(A.transpose(),b4)\n c2 = dot_(A.transpose(),b4)\n assert_almost_equal(c1, c2, decimal=self.N) \n\n def check_vecvecouter(self):\n b1, b3 = self.b1, self.b3\n c1 = dot(b1, b3)\n c2 = dot_(b1, b3)\n assert_almost_equal(c1, c2, decimal=self.N)\n\n def check_vecvecinner(self):\n b1, b3 = self.b1, self.b3\n c1 = dot(b3, b1)\n c2 = dot_(b3, b1)\n assert_almost_equal(c1, c2, decimal=self.N)\n\n def check_matscalar(self):\n\tb1 = matrix(ones((3,3),dtype=complex))\n\tassert_equal(b1*1.0, b1)\n\n def check_columnvect(self):\n\tb1 = ones((3,1))\n\tb2 = [5.3]\n\tc1 = dot(b1,b2)\n\tc2 = dot_(b1,b2)\n\tassert_almost_equal(c1, c2, decimal=self.N)\n\n\nclass test_bool_scalar(ScipyTestCase):\n def test_logical(self):\n f = False_\n t = True_\n s = \"xyz\"\n self.failUnless((t and s) is s)\n self.failUnless((f and s) is f)\n\n def test_bitwise_or(self):\n f = False_\n t = True_\n self.failUnless((t | t) is t)\n self.failUnless((f | t) is t)\n self.failUnless((t | f) is t)\n self.failUnless((f | f) is f)\n\n def test_bitwise_and(self): \n f = False_\n t = True_\n self.failUnless((t & t) is t)\n self.failUnless((f & t) is f)\n self.failUnless((t & f) is f)\n self.failUnless((f & f) is f)\n\n def test_bitwise_xor(self): \n f = False_\n t = True_\n self.failUnless((t ^ t) is f)\n self.failUnless((f ^ t) is t)\n self.failUnless((t ^ f) is t)\n self.failUnless((f ^ f) is f)\n \n \n \n", + "methods": [ + { + "name": "setUp", + "long_name": "setUp( self )", + "filename": "test_numeric.py", + "nloc": 7, + "complexity": 1, + "token_count": 56, + "parameters": [ + "self" + ], + "start_line": 7, + "end_line": 13, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 7, + "top_nesting_level": 1 + }, + { + "name": "check_matmat", + "long_name": "check_matmat( self )", + "filename": "test_numeric.py", + "nloc": 5, + "complexity": 1, + "token_count": 46, + "parameters": [ + "self" + ], + "start_line": 15, + "end_line": 19, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 5, + "top_nesting_level": 1 + }, + { + "name": "check_matvec", + "long_name": "check_matvec( self )", + "filename": "test_numeric.py", + "nloc": 5, + "complexity": 1, + "token_count": 44, + "parameters": [ + "self" + ], + "start_line": 21, + "end_line": 25, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 5, + "top_nesting_level": 1 + }, + { + "name": "check_matvec2", + "long_name": "check_matvec2( self )", + "filename": "test_numeric.py", + "nloc": 5, + "complexity": 1, + "token_count": 44, + "parameters": [ + "self" + ], + "start_line": 27, + "end_line": 31, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 5, + "top_nesting_level": 1 + }, + { + "name": "check_vecmat", + "long_name": "check_vecmat( self )", + "filename": "test_numeric.py", + "nloc": 5, + "complexity": 1, + "token_count": 44, + "parameters": [ + "self" + ], + "start_line": 33, + "end_line": 37, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 5, + "top_nesting_level": 1 + }, + { + "name": "check_vecmat2", + "long_name": "check_vecmat2( self )", + "filename": "test_numeric.py", + "nloc": 5, + "complexity": 1, + "token_count": 52, + "parameters": [ + "self" + ], + "start_line": 39, + "end_line": 43, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 5, + "top_nesting_level": 1 + }, + { + "name": "check_vecmat3", + "long_name": "check_vecmat3( self )", + "filename": "test_numeric.py", + "nloc": 5, + "complexity": 1, + "token_count": 52, + "parameters": [ + "self" + ], + "start_line": 45, + "end_line": 49, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 5, + "top_nesting_level": 1 + }, + { + "name": "check_vecvecouter", + "long_name": "check_vecvecouter( self )", + "filename": "test_numeric.py", + "nloc": 5, + "complexity": 1, + "token_count": 44, + "parameters": [ + "self" + ], + "start_line": 51, + "end_line": 55, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 5, + "top_nesting_level": 1 + }, + { + "name": "check_vecvecinner", + "long_name": "check_vecvecinner( self )", + "filename": "test_numeric.py", + "nloc": 5, + "complexity": 1, + "token_count": 44, + "parameters": [ + "self" + ], + "start_line": 57, + "end_line": 61, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 5, + "top_nesting_level": 1 + }, + { + "name": "check_matscalar", + "long_name": "check_matscalar( self )", + "filename": "test_numeric.py", + "nloc": 3, + "complexity": 1, + "token_count": 32, + "parameters": [ + "self" + ], + "start_line": 63, + "end_line": 65, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 3, + "top_nesting_level": 1 + }, + { + "name": "check_columnvect", + "long_name": "check_columnvect( self )", + "filename": "test_numeric.py", + "nloc": 6, + "complexity": 1, + "token_count": 50, + "parameters": [ + "self" + ], + "start_line": 67, + "end_line": 72, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 6, + "top_nesting_level": 1 + }, + { + "name": "check_columnvect", + "long_name": "check_columnvect( self )", + "filename": "test_numeric.py", + "nloc": 6, + "complexity": 1, + "token_count": 54, + "parameters": [ + "self" + ], + "start_line": 74, + "end_line": 79, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 6, + "top_nesting_level": 1 + }, + { + "name": "test_logical", + "long_name": "test_logical( self )", + "filename": "test_numeric.py", + "nloc": 6, + "complexity": 3, + "token_count": 38, + "parameters": [ + "self" + ], + "start_line": 84, + "end_line": 89, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 6, + "top_nesting_level": 1 + }, + { + "name": "test_bitwise_or", + "long_name": "test_bitwise_or( self )", + "filename": "test_numeric.py", + "nloc": 7, + "complexity": 1, + "token_count": 59, + "parameters": [ + "self" + ], + "start_line": 91, + "end_line": 97, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 7, + "top_nesting_level": 1 + }, + { + "name": "test_bitwise_and", + "long_name": "test_bitwise_and( self )", + "filename": "test_numeric.py", + "nloc": 7, + "complexity": 1, + "token_count": 59, + "parameters": [ + "self" + ], + "start_line": 99, + "end_line": 105, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 7, + "top_nesting_level": 1 + }, + { + "name": "test_bitwise_xor", + "long_name": "test_bitwise_xor( self )", + "filename": "test_numeric.py", + "nloc": 7, + "complexity": 1, + "token_count": 59, + "parameters": [ + "self" + ], + "start_line": 107, + "end_line": 113, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 7, + "top_nesting_level": 1 + } + ], + "methods_before": [ + { + "name": "setUp", + "long_name": "setUp( self )", + "filename": "test_numeric.py", + "nloc": 7, + "complexity": 1, + "token_count": 56, + "parameters": [ + "self" + ], + "start_line": 7, + "end_line": 13, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 7, + "top_nesting_level": 1 + }, + { + "name": "check_matmat", + "long_name": "check_matmat( self )", + "filename": "test_numeric.py", + "nloc": 5, + "complexity": 1, + "token_count": 46, + "parameters": [ + "self" + ], + "start_line": 15, + "end_line": 19, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 5, + "top_nesting_level": 1 + }, + { + "name": "check_matvec", + "long_name": "check_matvec( self )", + "filename": "test_numeric.py", + "nloc": 5, + "complexity": 1, + "token_count": 44, + "parameters": [ + "self" + ], + "start_line": 21, + "end_line": 25, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 5, + "top_nesting_level": 1 + }, + { + "name": "check_matvec2", + "long_name": "check_matvec2( self )", + "filename": "test_numeric.py", + "nloc": 5, + "complexity": 1, + "token_count": 44, + "parameters": [ + "self" + ], + "start_line": 27, + "end_line": 31, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 5, + "top_nesting_level": 1 + }, + { + "name": "check_vecmat", + "long_name": "check_vecmat( self )", + "filename": "test_numeric.py", + "nloc": 5, + "complexity": 1, + "token_count": 44, + "parameters": [ + "self" + ], + "start_line": 33, + "end_line": 37, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 5, + "top_nesting_level": 1 + }, + { + "name": "check_vecmat2", + "long_name": "check_vecmat2( self )", + "filename": "test_numeric.py", + "nloc": 5, + "complexity": 1, + "token_count": 52, + "parameters": [ + "self" + ], + "start_line": 39, + "end_line": 43, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 5, + "top_nesting_level": 1 + }, + { + "name": "check_vecmat3", + "long_name": "check_vecmat3( self )", + "filename": "test_numeric.py", + "nloc": 5, + "complexity": 1, + "token_count": 52, + "parameters": [ + "self" + ], + "start_line": 45, + "end_line": 49, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 5, + "top_nesting_level": 1 + }, + { + "name": "check_vecvecouter", + "long_name": "check_vecvecouter( self )", + "filename": "test_numeric.py", + "nloc": 5, + "complexity": 1, + "token_count": 44, + "parameters": [ + "self" + ], + "start_line": 51, + "end_line": 55, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 5, + "top_nesting_level": 1 + }, + { + "name": "check_vecvecinner", + "long_name": "check_vecvecinner( self )", + "filename": "test_numeric.py", + "nloc": 5, + "complexity": 1, + "token_count": 44, + "parameters": [ + "self" + ], + "start_line": 57, + "end_line": 61, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 5, + "top_nesting_level": 1 + }, + { + "name": "check_matscalar", + "long_name": "check_matscalar( self )", + "filename": "test_numeric.py", + "nloc": 3, + "complexity": 1, + "token_count": 32, + "parameters": [ + "self" + ], + "start_line": 63, + "end_line": 65, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 3, + "top_nesting_level": 1 + }, + { + "name": "check_columnvect", + "long_name": "check_columnvect( self )", + "filename": "test_numeric.py", + "nloc": 6, + "complexity": 1, + "token_count": 50, + "parameters": [ + "self" + ], + "start_line": 67, + "end_line": 72, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 6, + "top_nesting_level": 1 + }, + { + "name": "test_logical", + "long_name": "test_logical( self )", + "filename": "test_numeric.py", + "nloc": 6, + "complexity": 3, + "token_count": 38, + "parameters": [ + "self" + ], + "start_line": 76, + "end_line": 81, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 6, + "top_nesting_level": 1 + }, + { + "name": "test_bitwise_or", + "long_name": "test_bitwise_or( self )", + "filename": "test_numeric.py", + "nloc": 7, + "complexity": 1, + "token_count": 59, + "parameters": [ + "self" + ], + "start_line": 83, + "end_line": 89, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 7, + "top_nesting_level": 1 + }, + { + "name": "test_bitwise_and", + "long_name": "test_bitwise_and( self )", + "filename": "test_numeric.py", + "nloc": 7, + "complexity": 1, + "token_count": 59, + "parameters": [ + "self" + ], + "start_line": 91, + "end_line": 97, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 7, + "top_nesting_level": 1 + }, + { + "name": "test_bitwise_xor", + "long_name": "test_bitwise_xor( self )", + "filename": "test_numeric.py", + "nloc": 7, + "complexity": 1, + "token_count": 59, + "parameters": [ + "self" + ], + "start_line": 99, + "end_line": 105, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 7, + "top_nesting_level": 1 + } + ], + "changed_methods": [ + { + "name": "check_columnvect", + "long_name": "check_columnvect( self )", + "filename": "test_numeric.py", + "nloc": 6, + "complexity": 1, + "token_count": 54, + "parameters": [ + "self" + ], + "start_line": 74, + "end_line": 79, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 6, + "top_nesting_level": 1 + } + ], + "nloc": 95, + "complexity": 18, + "token_count": 833, + "diff_parsed": { + "added": [ + " def check_columnvect(self):", + "\tb1 = ones((3,1)).transpose()", + "\tb2 = [6.2]", + "\tc1 = dot(b2,b1)", + "\tc2 = dot_(b2,b1)", + "\tassert_almost_equal(c1, c2, decimal=self.N)", + "", + "" + ], + "deleted": [] + } + } + ] + }, + { + "hash": "2438f98798fa6cf0443433d879365cd2121b6b5e", + "msg": "Convert to arrays in piecewise. Improve error-handling of object-array conversions.", + "author": { + "name": "Travis Oliphant", + "email": "oliphant@enthought.com" + }, + "committer": { + "name": "Travis Oliphant", + "email": "oliphant@enthought.com" + }, + "author_date": "2006-01-29T08:40:39+00:00", + "author_timezone": 0, + "committer_date": "2006-01-29T08:40:39+00:00", + "committer_timezone": 0, + "branches": [ + "main" + ], + "in_main_branch": true, + "merge": false, + "parents": [ + "c0d68f47a04c22d1e9de64b8d09d43fb1b72fc63" + ], + "project_name": "repo_copy", + "project_path": "/tmp/tmppy2o86q9/repo_copy", + "deletions": 27, + "insertions": 22, + "lines": 49, + "files": 2, + "dmm_unit_size": 0.0, + "dmm_unit_complexity": 0.0, + "dmm_unit_interfacing": 0.0, + "modified_files": [ + { + "old_path": "numpy/core/src/arraytypes.inc.src", + "new_path": "numpy/core/src/arraytypes.inc.src", + "filename": "arraytypes.inc.src", + "extension": "src", + "change_type": "MODIFY", + "diff": "@@ -1,34 +1,28 @@\n /* -*- c -*- */\n \n-static ulong\n-MyPyLong_AsUnsignedLong(PyObject *vv)\n+/**begin repeat\n+#name=UnsignedLong,UnsignedLongLong,LongLong#\n+#type=ulong,ulonglong,longlong#\n+ */\n+static @type@\n+MyPyLong_As@name@(PyObject *vv)\n {\n-\tif ((vv != NULL) && PyInt_Check(vv)) {\n-\t\tlong val = PyInt_AsLong(vv);\n-\t\tif (val < 0) {\n-\t\t\tPyErr_SetString(PyExc_OverflowError,\n-\t\t\t\"can't convert negative value to unsigned long\");\n-\t\t\treturn (ulong) -1;\n-\t\t}\n-\t\treturn val;\n-\t}\n-\treturn PyLong_AsUnsignedLong(vv);\t\n-}\n+\t@type@ ret;\n \n-static ulonglong\n-MyPyLong_AsUnsignedLongLong(PyObject *vv)\n-{\n-\tif ((vv != NULL) && PyInt_Check(vv)) {\n-\t\tlonglong val = PyInt_AsLong(vv);\n-\t\tif (val < 0) {\n-\t\t\tPyErr_SetString(PyExc_OverflowError,\n-\t\t\t\"can't convert negative value to unsigned long\");\n-\t\t\treturn (ulonglong) -1;\n-\t\t}\n-\t\treturn val;\n+\tif (!PyLong_Check(vv)) {\n+\t\tPyObject *mylong;\n+\t\tmylong = PyNumber_Long(vv);\n+\t\tif (mylong == NULL) return (@type@) -1;\n+\t\tvv = mylong;\n \t}\n-\treturn PyLong_AsUnsignedLongLong(vv);\t\n+\telse Py_INCREF(vv);\n+\n+\tret = PyLong_As@name@(vv);\n+\tPy_DECREF(vv);\n+\treturn ret;\n }\n+/**end repeat**/\n+\n \n static double \n _getNAN(void) {\n@@ -67,7 +61,7 @@ MyPyFloat_AsDouble(PyObject *obj)\n \n #TYP=BOOL,BYTE,UBYTE,SHORT,USHORT,INT,LONG,UINT,ULONG,LONGLONG,ULONGLONG,FLOAT,DOUBLE#\n #func1=PyBool_FromLong, PyInt_FromLong*6, PyLong_FromUnsignedLong*2, PyLong_FromLongLong, PyLong_FromUnsignedLongLong, PyFloat_FromDouble*2#\n-#func2=PyObject_IsTrue, PyInt_AsLong*6, MyPyLong_AsUnsignedLong*2, PyLong_AsLongLong, MyPyLong_AsUnsignedLongLong, MyPyFloat_AsDouble*2#\n+#func2=PyObject_IsTrue, PyInt_AsLong*6, MyPyLong_AsUnsignedLong*2, MyPyLong_AsLongLong, MyPyLong_AsUnsignedLongLong, MyPyFloat_AsDouble*2#\n #typ=Bool, byte, ubyte, short, ushort, int, long, uint, ulong, longlong, ulonglong, float, double#\n #typ1=long*7, ulong*2, longlong, ulonglong, float, double#\n #kind=Bool, Byte, UByte, Short, UShort, Int, Long, UInt, ULong, LongLong, ULongLong, Float, Double#\n", + "added_lines": 20, + "deleted_lines": 26, + "source_code": "/* -*- c -*- */\n\n/**begin repeat\n#name=UnsignedLong,UnsignedLongLong,LongLong#\n#type=ulong,ulonglong,longlong#\n */\nstatic @type@\nMyPyLong_As@name@(PyObject *vv)\n{\n\t@type@ ret;\n\n\tif (!PyLong_Check(vv)) {\n\t\tPyObject *mylong;\n\t\tmylong = PyNumber_Long(vv);\n\t\tif (mylong == NULL) return (@type@) -1;\n\t\tvv = mylong;\n\t}\n\telse Py_INCREF(vv);\n\n\tret = PyLong_As@name@(vv);\n\tPy_DECREF(vv);\n\treturn ret;\n}\n/**end repeat**/\n\n\nstatic double \n_getNAN(void) {\n#ifdef NAN\n return NAN;\n#else\n static double nan=0;\n \n if (nan == 0) {\n\t\tdouble mul = 1e100;\n\t\tdouble tmp = 0.0;\n\t\tdouble pinf=0;\n pinf = mul;\n for (;;) {\n pinf *= mul;\n if (pinf == tmp) break;\n tmp = pinf;\n }\n nan = pinf / pinf;\n }\n return nan;\n#endif\n}\n\nstatic double\nMyPyFloat_AsDouble(PyObject *obj)\n{\n if (obj == Py_None) return _getNAN();\n return PyFloat_AsDouble(obj); \n}\n\n\n/****************** getitem and setitem **********************/\n\n/**begin repeat\n\n#TYP=BOOL,BYTE,UBYTE,SHORT,USHORT,INT,LONG,UINT,ULONG,LONGLONG,ULONGLONG,FLOAT,DOUBLE#\n#func1=PyBool_FromLong, PyInt_FromLong*6, PyLong_FromUnsignedLong*2, PyLong_FromLongLong, PyLong_FromUnsignedLongLong, PyFloat_FromDouble*2#\n#func2=PyObject_IsTrue, PyInt_AsLong*6, MyPyLong_AsUnsignedLong*2, MyPyLong_AsLongLong, MyPyLong_AsUnsignedLongLong, MyPyFloat_AsDouble*2#\n#typ=Bool, byte, ubyte, short, ushort, int, long, uint, ulong, longlong, ulonglong, float, double#\n#typ1=long*7, ulong*2, longlong, ulonglong, float, double#\n#kind=Bool, Byte, UByte, Short, UShort, Int, Long, UInt, ULong, LongLong, ULongLong, Float, Double#\n*/\n\nstatic PyObject * \n@TYP@_getitem(char *ip, PyArrayObject *ap) {\n @typ@ t1;\n\n\tif ((ap==NULL) || PyArray_ISBEHAVED_RO(ap)) {\n t1 = *((@typ@ *)ip);\n return @func1@((@typ1@)t1);\n\t}\n\telse {\n ap->descr->f->copyswap(&t1, ip, !PyArray_ISNOTSWAPPED(ap),\n\t\t\t\t ap->descr->elsize);\n return @func1@((@typ1@)t1);\n\t}\n}\n\nstatic int \n@TYP@_setitem(PyObject *op, char *ov, PyArrayObject *ap) {\n @typ@ temp; /* ensures alignment */\n\n if (PyArray_IsScalar(op, @kind@)) {\n temp = ((Py@kind@ScalarObject *)op)->obval;\n }\n else {\n temp = (@typ@)@func2@(op);\n }\n if (PyErr_Occurred()) return -1;\n if (ap == NULL || PyArray_ISBEHAVED(ap)) \n *((@typ@ *)ov)=temp;\n else {\n ap->descr->f->copyswap(ov, &temp, !PyArray_ISNOTSWAPPED(ap), \n\t\t\t\t ap->descr->elsize);\n }\n \n return 0;\n}\n\n/**end repeat**/\n\n\n/**begin repeat \n\n#TYP=CFLOAT,CDOUBLE#\n#typ=float, double#\n*/\n\nstatic PyObject * \n@TYP@_getitem(char *ip, PyArrayObject *ap) {\n @typ@ t1, t2;\n\n if ((ap==NULL) || PyArray_ISBEHAVED_RO(ap)) { \n return PyComplex_FromDoubles((double)((@typ@ *)ip)[0], \n (double)((@typ@ *)ip)[1]);\n }\n else {\n\t\tint size = sizeof(@typ@);\n\t\tBool swap = !PyArray_ISNOTSWAPPED(ap);\n copy_and_swap(&t1, ip, size, 1, 0, swap);\n copy_and_swap(&t2, ip+size, size, 1, 0, swap);\n return PyComplex_FromDoubles((double)t1, (double)t2);\n }\n}\n/**end repeat**/\n\n/**begin repeat \n\n#TYP=CFLOAT, CDOUBLE, CLONGDOUBLE#\n#typ=float, double, longdouble#\n#kind=CFloat, CDouble, CLongDouble#\n*/\nstatic int \n@TYP@_setitem(PyObject *op, char *ov, PyArrayObject *ap) \n{\n Py_complex oop;\n PyObject *op2;\n c@typ@ temp;\n\tint rsize;\n \n if (!(PyArray_IsScalar(op, @kind@))) {\n if (PyArray_Check(op) && (PyArray_NDIM(op)==0)) {\n op2 = ((PyArrayObject *)op)->descr->f->getitem \\\n (((PyArrayObject *)op)->data, \n (PyArrayObject *)op);\n\t\t}\n\t\telse { \n op2 = op; Py_INCREF(op);\n }\n if (op2 == Py_None) {\n oop.real = oop.imag = _getNAN();\n }\n else {\n oop = PyComplex_AsCComplex (op2);\n }\n Py_DECREF(op2);\n if (PyErr_Occurred()) return -1;\n temp.real = (@typ@) oop.real;\n temp.imag = (@typ@) oop.imag; \n }\n\telse {\n temp = ((Py@kind@ScalarObject *)op)->obval;\n }\n\t\n memcpy(ov, &temp, ap->descr->elsize);\n if (!PyArray_ISNOTSWAPPED(ap))\n byte_swap_vector(ov, 2, sizeof(@typ@));\n\t\n\trsize = sizeof(@typ@);\n\tcopy_and_swap(ov, &temp, rsize, 2, rsize, !PyArray_ISNOTSWAPPED(ap));\n return 0;\n}\n/**end repeat**/\n\nstatic PyObject * \nLONGDOUBLE_getitem(char *ip, PyArrayObject *ap) \n{\n return PyArray_Scalar(ip, ap->descr, NULL);\n}\n\nstatic int \nLONGDOUBLE_setitem(PyObject *op, char *ov, PyArrayObject *ap) {\n longdouble temp; /* ensures alignment */\n\n if (PyArray_IsScalar(op, LongDouble)) {\n temp = ((PyLongDoubleScalarObject *)op)->obval;\n }\n else {\n if (op == Py_None) temp = (longdouble)_getNAN();\n else temp = (longdouble)PyFloat_AsDouble(op);\n }\n if (PyErr_Occurred()) return -1;\n if (ap == NULL || PyArray_ISBEHAVED(ap)) \n *((longdouble *)ov)=temp;\n else {\n copy_and_swap(ov, &temp, ap->descr->elsize, 1, 0,\n !PyArray_ISNOTSWAPPED(ap));\n }\n \n return 0;\n}\n\nstatic PyObject * \nCLONGDOUBLE_getitem(char *ip, PyArrayObject *ap) \n{\n return PyArray_Scalar(ip, ap->descr, NULL);\n}\n\n\n/* UNICODE */\nstatic PyObject * \nUNICODE_getitem(char *ip, PyArrayObject *ap) \n{\n\tPyObject *obj;\n\tsize_t size = sizeof(Py_UNICODE);\n\tint mysize;\n\tPy_UNICODE *dptr;\n\n\tmysize = ap->descr->elsize / size;\n\tdptr = (Py_UNICODE *)ip + mysize-1;\n\twhile(mysize > 0 && *dptr-- == 0) mysize--;\n\tobj = PyUnicode_FromUnicode((const Py_UNICODE *)ip, mysize);\n\tif (!PyArray_ISNOTSWAPPED(ap) && (obj != NULL)) {\n\t\tbyte_swap_vector(PyUnicode_AS_UNICODE(obj),\n\t\t\t\t mysize, size);\n\t}\n\treturn obj;\n}\n\nstatic int \nUNICODE_setitem(PyObject *op, char *ov, PyArrayObject *ap) \n{\n PyObject *temp;\n\tPy_UNICODE *ptr;\n\tint datalen;\n\tsize_t size = sizeof(Py_UNICODE);\n\n\tif ((temp=PyObject_Unicode(op)) == NULL) return -1;\n\n\tptr = PyUnicode_AS_UNICODE(temp);\n\tif ((ptr == NULL) || (PyErr_Occurred())) {\n\t\tPy_DECREF(temp);\n\t\treturn -1;\n\t}\n\tdatalen = PyUnicode_GET_DATA_SIZE(op);\n\n\tmemcpy(ov, ptr, MIN(ap->descr->elsize, datalen));\n\t/* Fill in the rest of the space with 0 */\n\tif (ap->descr->elsize > datalen) {\n\t\tmemset(ov + datalen, 0, (ap->descr->elsize - datalen));\n\t}\n\n\tif (!PyArray_ISNOTSWAPPED(ap)) \n\t\tbyte_swap_vector(ov, ap->descr->elsize / size, size);\n\t\n\tPy_DECREF(temp);\n\treturn 0;\n}\n\n/* STRING -- can handle both NULL-terminated and not NULL-terminated cases */\nstatic PyObject * \nSTRING_getitem(char *ip, PyArrayObject *ap) \n{\n\tif (ip[ap->descr->elsize-1])\n\t\treturn PyString_FromStringAndSize(ip,ap->descr->elsize);\n\telse\n\t\treturn PyString_FromString(ip);\n}\n\nstatic int \nSTRING_setitem(PyObject *op, char *ov, PyArrayObject *ap) \n{\n\tchar *ptr;\n\tint len;\n\tPyObject *temp=PyObject_Str(op);\n\t\n\tif (temp == NULL) return -1;\n\t\n\tif (PyString_AsStringAndSize(temp, &ptr, &len) == -1) {\n\t\tPy_DECREF(temp);\n\t\treturn -1;\n\t}\n\tmemcpy(ov, ptr, MIN(ap->descr->elsize,len));\n\tif (ap->descr->elsize > len) {\n\t\tmemset(ov + len, 0, (ap->descr->elsize - len));\n\t}\n\tPy_DECREF(temp);\n\treturn 0;\n}\n\n/* OBJECT */\n\nstatic PyObject * \nOBJECT_getitem(char *ip, PyArrayObject *ap) \n{\n\tPy_INCREF(*(PyObject **)ip);\n\treturn *(PyObject **)ip;\n}\n\nstatic int \nOBJECT_setitem(PyObject *op, char *ov, PyArrayObject *ap) \n{\n\tPy_XDECREF(*(PyObject **)ov);\n\tPy_INCREF(op);\n\t*(PyObject **)ov = op;\n\treturn PyErr_Occurred() ? -1:0;\n}\n\n/* VOID */\n\nstatic PyObject *\nVOID_getitem(char *ip, PyArrayObject *ap)\n{\n PyObject *u=NULL;\n\tPyArray_Descr* descr;\n int itemsize;\n\n\tdescr = ap->descr;\n\tif (descr->fields && descr->fields != Py_None) {\n\t\tPyObject *key;\n\t\tPyObject *names;\n\t\tint i, n;\n\t\tPyObject *ret;\n\t\tPyObject *tup, *title;\n\t\tPyArray_Descr *new;\n\t\tint offset;\n\t\tint savedflags;\n\n\t\t/* get the names from the fields dictionary*/\n\t\tkey = PyInt_FromLong(-1);\n\t\tnames = PyDict_GetItem(descr->fields, key);\n\t\tPy_DECREF(key);\n\t\tif (!names) goto finish;\n\t\tn = PyList_GET_SIZE(names);\n\t\tret = PyTuple_New(n);\n\t\tsavedflags = ap->flags;\n\t\tfor (i=0; ifields, key);\n\t\t\tif (!PyArg_ParseTuple(tup, \"Oi|O\", &new, &offset, \n\t\t\t\t\t &title)) {\n\t\t\t\tPy_DECREF(ret); \n\t\t\t\tap->descr = descr;\n\t\t\t\treturn NULL;\n\t\t\t}\n\t\t\tap->descr = new;\n\t\t\t/* update alignment based on offset */\n\t\t\tif ((new->alignment > 1) &&\t\t\t\\\n\t\t\t ((((intp)(ip+offset)) % new->alignment) != 0))\n\t\t\t\tap->flags &= ~ALIGNED;\n\t\t\telse\n\t\t\t\tap->flags |= ALIGNED;\n\n\t\t\tPyTuple_SET_ITEM(ret, i,\t\t\t\\\n\t\t\t\t\t new->f->getitem(ip+offset, ap));\n\t\t\tap->flags = savedflags;\n\t\t}\n\t\tap->descr = descr;\n\t\treturn ret;\n\t}\n\n\tif (descr->subarray) {\n\t\t/* return an array of the basic type */\n\t\tPyArray_Dims shape={NULL,-1};\n\t\tPyObject *ret;\n\t\tif (!(PyArray_IntpConverter(descr->subarray->shape, \n\t\t\t\t\t &shape))) {\n\t\t\tPyDimMem_FREE(shape.ptr);\n\t\t\tPyErr_SetString(PyExc_ValueError, \n\t\t\t\t\t\"invalid shape in fixed-type tuple.\");\n\t\t\treturn NULL;\n\t\t}\n Py_INCREF(descr->subarray->base);\n\t\tret = PyArray_NewFromDescr(&PyArray_Type,\n\t\t\t\t\t descr->subarray->base,\n\t\t\t\t\t shape.len, shape.ptr,\n\t\t\t\t\t NULL, ip, ap->flags, NULL);\n\t\tPyDimMem_FREE(shape.ptr);\n\t\tif (!ret) return NULL;\n\t\tPyArray_BASE(ret) = (PyObject *)ap;\n\t\tPy_INCREF(ap);\n\t\tPyArray_UpdateFlags((PyArrayObject *)ret, UPDATE_ALL_FLAGS);\n\t\treturn ret;\n\t}\n\n finish:\n\titemsize=ap->descr->elsize;\n\tif (PyArray_ISWRITEABLE(ap))\n\t\tu = PyBuffer_FromReadWriteMemory(ip, itemsize);\n\telse\n\t\tu = PyBuffer_FromMemory(ip, itemsize);\n\tif (u==NULL) goto fail;\n\n\t/* default is to return buffer object pointing to current item */\n\t/* a view of it */\n\treturn u; \n\t\n fail:\n return NULL;\n}\n\n\n\nstatic int PyArray_CopyObject(PyArrayObject *, PyObject *);\n\nstatic int\nVOID_setitem(PyObject *op, char *ip, PyArrayObject *ap)\n{\n\tPyArray_Descr* descr;\n int itemsize=ap->descr->elsize;\n\tint res;\n\n\tdescr = ap->descr;\n\tif (descr->fields && (descr->fields != Py_None) && \\\n\t PyTuple_Check(op)) {\n\t\tPyObject *key;\n\t\tPyObject *names;\n\t\tint i, n;\n\t\tPyObject *tup, *title;\n\t\tPyArray_Descr *new;\n\t\tint offset;\n\t\tint savedflags;\n\t\tres = -1;\n\t\t/* get the names from the fields dictionary*/\n\t\tkey = PyInt_FromLong(-1);\n\t\tnames = PyDict_GetItem(descr->fields, key);\n\t\tPy_DECREF(key);\n\t\tif (!names) goto finish;\n\t\tn = PyList_GET_SIZE(names);\n\t\tif (PyTuple_GET_SIZE(op) != n) {\n\t\t\tPyErr_SetString(PyExc_ValueError, \n\t\t\t\t\t\"size of tuple must match\"\\\n\t\t\t\t\t\"number of fields.\");\n\t\t\treturn -1;\n\t\t}\n\t\tsavedflags = ap->flags;\n\t\tfor (i=0; ifields, key);\n\t\t\tif (!PyArg_ParseTuple(tup, \"Oi|O\", &new, &offset, \n\t\t\t\t\t &title)) {\n\t\t\t\tap->descr = descr;\n\t\t\t\treturn -1;\n\t\t\t}\n\t\t\tap->descr = new;\n\t\t\t/* remember to update alignment flags */\n\t\t\tif ((new->alignment > 1) &&\t\t\t\\\n\t\t\t ((((intp)(ip+offset)) % new->alignment) != 0))\n\t\t\t\tap->flags &= ~ALIGNED;\n\t\t\telse\n\t\t\t\tap->flags |= ALIGNED;\n\n\t\t\tres = new->f->setitem(PyTuple_GET_ITEM(op, i),\n\t\t\t\t\t ip+offset, ap);\n\t\t\tap->flags = savedflags;\n\t\t\tif (res < 0) break;\n\t\t}\n\t\tap->descr = descr;\n\t\treturn res;\n\t}\n\n\tif (descr->subarray) {\n\t\t/* copy into an array of the same basic type */\n\t\tPyArray_Dims shape={NULL,-1};\n\t\tPyObject *ret;\n\t\tif (!(PyArray_IntpConverter(descr->subarray->shape, \n\t\t\t\t\t &shape))) {\n\t\t\tPyDimMem_FREE(shape.ptr);\n\t\t\tPyErr_SetString(PyExc_ValueError, \n\t\t\t\t\t\"invalid shape in fixed-type tuple.\");\n\t\t\treturn -1;\n\t\t}\n\t\tret = PyArray_NewFromDescr(&PyArray_Type,\n\t\t\t\t\t descr->subarray->base,\n\t\t\t\t\t shape.len, shape.ptr,\n\t\t\t\t\t NULL, ip, ap->flags, NULL);\n\t\tPyDimMem_FREE(shape.ptr);\n\t\tif (!ret) return -1;\n\t\tPyArray_BASE(ret) = (PyObject *)ap;\n\t\tPy_INCREF(ap);\n\t\tPyArray_UpdateFlags((PyArrayObject *)ret, UPDATE_ALL_FLAGS);\n\t\tres = PyArray_CopyObject((PyArrayObject *)ret, op);\n\t\tPy_DECREF(ret);\n\t\treturn res;\n\t}\n\n finish:\n\t/* Default is to use buffer interface to set item */\n\t{\n\t\tconst void *buffer;\n\t\tint buflen;\n\t\tres = PyObject_AsReadBuffer(op, &buffer, &buflen);\n\t\tif (res == -1) goto fail;\n\t\tmemcpy(ip, buffer, MIN(buflen, itemsize));\n }\n\treturn 0;\n\n fail:\n return -1; \n}\n\n\n/****************** XXX_to_YYY *******************************/ \n\n/* Assumes contiguous, and aligned, from and to */\n\n\n/**begin repeat\n#to=(BYTE,UBYTE,SHORT,USHORT,INT,UINT,LONG,ULONG,LONGLONG,ULONGLONG,FLOAT,DOUBLE,LONGDOUBLE)*16#\n#from=BYTE*13,UBYTE*13,SHORT*13,USHORT*13,INT*13,UINT*13,LONG*13,ULONG*13,LONGLONG*13,ULONGLONG*13,FLOAT*13,DOUBLE*13,LONGDOUBLE*13,CFLOAT*13,CDOUBLE*13,CLONGDOUBLE*13#\n#totyp=(byte, ubyte, short, ushort, int, uint, long, ulong, longlong, ulonglong, float, double, longdouble)*16#\n#fromtyp=byte*13, ubyte*13, short*13, ushort*13, int*13, uint*13, long*13, ulong*13, longlong*13, ulonglong*13, float*13, double*13, longdouble*13, float*13, double*13, longdouble*13#\n#incr= ip++*169,ip+=2*39#\n*/\nstatic void \n@from@_to_@to@(@fromtyp@ *ip, @totyp@ *op, intp n, PyArrayObject *aip, \n\t PyArrayObject *aop) {\n\tregister intp i; \n\tfor(i=0;idescr->elsize*3, 1#\n*/\nstatic void \n@from@_to_OBJECT(@fromtyp@ *ip, PyObject **op, intp n, PyArrayObject *aip,\n\t\t PyArrayObject *aop)\n{\n\tregister intp i; \n\tint skip=@skip@;\n\tfor(i=0;idescr->elsize*3#\n*/\nstatic void \nOBJECT_to_@to@(PyObject **ip, @totyp@ *op, intp n, PyArrayObject *aip,\n\t\t PyArrayObject *aop)\n{\n\tregister intp i; \n\tint skip=@skip@;\n\tfor(i=0;idescr->elsize*3)*3#\n#convert=1*17,0*3,1*17,0*3,0*20#\n#convstr=(Int*9,Long*2,Float*3,Complex*3,Tuple*3)*3#\n*/\nstatic void\n@from@_to_@to@(@fromtyp@ *ip, @totyp@ *op, intp n, PyArrayObject *aip, \n\t PyArrayObject *aop)\n{\n\tregister intp i;\n\tPyObject *temp=NULL;\n\tint skip=aip->descr->elsize;\n\tint oskip=@oskip@;\n\tfor(i=0; idescr->elsize;\n\tfor(i=0; i= 0x02040000) || defined(PyOS_ascii_strtod)\nstatic int\n@fname@_fromstr(char *str, @type@ *ip, char **endptr, void *ignore)\n{\n\tdouble result;\n\n\tresult = PyOS_ascii_strtod(str, endptr);\n\t*ip = (@type@) result;\n\treturn 0;\n}\n#else\n#define @fname@_fromstr NULL\n#endif\n/**end repeat**/\n\n\n\n/**begin repeat\n#fname=BOOL,CFLOAT,CDOUBLE,CLONGDOUBLE,OBJECT,STRING,UNICODE,VOID#\n*/\n#define @fname@_fromstr NULL\n/**end repeat**/\n\n\n/****************** copyswapn *************************************/\n\n/**begin repeat\n\n#fname=SHORT,USHORT,INT,UINT,LONG,ULONG,LONGLONG,ULONGLONG,FLOAT,DOUBLE,LONGDOUBLE#\n#fsize=SHORT,SHORT,INT,INT,LONG,LONG,LONGLONG,LONGLONG,FLOAT,DOUBLE,LONGDOUBLE#\n#type=short,ushort,int,uint,long,ulong,longlong,ulonglong,float,double,longdouble#\n*/\nstatic void\n@fname@_copyswapn (void *dst, void *src, intp n, int swap, int itemsize)\n{\n\tif (src != NULL) /* copy first if needed */\n\t\tmemcpy(dst, src, n*sizeof(@type@));\n\n\tif (swap) {\n\t\tregister char *a, *b, c;\n\t\tfor (a = (char *)dst; n>0; n--) {\n#if SIZEOF_@fsize@ == 2\n\t\t\tb = a + 1;\n\t\t\tc = *a; *a++ = *b; *b = c;\n\t\t\ta += 1;\n#elif SIZEOF_@fsize@ == 4\n\t\t\tb = a + 3;\n c = *a; *a++ = *b; *b-- = c;\n c = *a; *a++ = *b; *b = c;\n\t\t\ta += 2;\n#elif SIZEOF_@fsize@ == 8\n b = a + 7;\n c = *a; *a++ = *b; *b-- = c;\n c = *a; *a++ = *b; *b-- = c;\n c = *a; *a++ = *b; *b-- = c;\n c = *a; *a++ = *b; *b = c;\n\t\t\ta += 4;\n#elif SIZEOF_@fsize@ == 10\n b = a + 9;\n c = *a; *a++ = *b; *b-- = c;\n c = *a; *a++ = *b; *b-- = c;\n c = *a; *a++ = *b; *b-- = c;\n c = *a; *a++ = *b; *b-- = c;\n c = *a; *a++ = *b; *b = c;\n\t\t\ta += 5;\n#elif SIZEOF_@fsize@ == 12\n b = a + 11;\n c = *a; *a++ = *b; *b-- = c;\n c = *a; *a++ = *b; *b-- = c;\n c = *a; *a++ = *b; *b-- = c;\n c = *a; *a++ = *b; *b-- = c;\n c = *a; *a++ = *b; *b-- = c;\n c = *a; *a++ = *b; *b = c;\n\t\t\ta += 6;\n#elif SIZEOF_@fsize@ == 16\n b = a + 15;\n c = *a; *a++ = *b; *b-- = c;\n c = *a; *a++ = *b; *b-- = c;\n c = *a; *a++ = *b; *b-- = c;\n c = *a; *a++ = *b; *b-- = c;\n c = *a; *a++ = *b; *b-- = c;\n c = *a; *a++ = *b; *b-- = c;\n c = *a; *a++ = *b; *b-- = c;\n c = *a; *a++ = *b; *b = c;\n\t\t\ta += 8;\n#else\n\t\t\tregister int i, nn;\n b = a + (SIZEOF_@fsize@-1);\n\t\t\tnn = SIZEOF_@fsize@ / 2;\n for (i=0; i0; nn--) {\n#if SIZEOF_@fsize@ == 4\n\t\t\tb = a + 3;\n c = *a; *a++ = *b; *b-- = c;\n c = *a; *a++ = *b; *b = c;\n\t\t\ta += 2;\n#elif SIZEOF_@fsize@ == 8\n b = a + 7;\n c = *a; *a++ = *b; *b-- = c;\n c = *a; *a++ = *b; *b-- = c;\n c = *a; *a++ = *b; *b-- = c;\n c = *a; *a++ = *b; *b = c;\n\t\t\ta += 4;\n#elif SIZEOF_@fsize@ == 10\n b = a + 9;\n c = *a; *a++ = *b; *b-- = c;\n c = *a; *a++ = *b; *b-- = c;\n c = *a; *a++ = *b; *b-- = c;\n c = *a; *a++ = *b; *b-- = c;\n c = *a; *a++ = *b; *b = c;\n\t\t\ta += 5;\n#elif SIZEOF_@fsize@ == 12\n b = a + 11;\n c = *a; *a++ = *b; *b-- = c;\n c = *a; *a++ = *b; *b-- = c;\n c = *a; *a++ = *b; *b-- = c;\n c = *a; *a++ = *b; *b-- = c;\n c = *a; *a++ = *b; *b-- = c;\n c = *a; *a++ = *b; *b = c;\n\t\t\ta += 6;\n#elif SIZEOF_@fsize@ == 16\n b = a + 15;\n c = *a; *a++ = *b; *b-- = c;\n c = *a; *a++ = *b; *b-- = c;\n c = *a; *a++ = *b; *b-- = c;\n c = *a; *a++ = *b; *b-- = c;\n c = *a; *a++ = *b; *b-- = c;\n c = *a; *a++ = *b; *b-- = c;\n c = *a; *a++ = *b; *b-- = c;\n c = *a; *a++ = *b; *b = c;\n\t\t\ta += 8;\n#else\n\t\t\tregister int i, kn;\n\n b = a + (SIZEOF_@fsize@-1);\n\t\t\tkn = SIZEOF_@fsize@ / 2;\n for (i=0; i0; n--) {\n\t\t\tb = a + (size-1);\n for (j=0; jreal != 0) || (ip->imag != 0));\n\telse {\n\t\t/* don't worry about swap, since we are just testing\n\t\t whether or not equal to 0 */\n\t\tmemcpy(&t1, ip, sizeof(@type@));\n\t\treturn (Bool) ((t1.real != 0) || (t1.imag != 0));\n\t}\n}\n/**end repeat**/\n\n\n\n#define WHITESPACE \" \\t\\n\\r\\v\\f\"\n#define WHITELEN 6\n\nstatic Bool\nPy_STRING_ISSPACE(char ch) \n{\n\tchar white[] = WHITESPACE;\n\tint j;\n\tBool space=FALSE;\n\tfor (j=0; jdescr->elsize;\n\tint i;\n\tBool nonz = FALSE;\n\n\tfor (i=0; idescr->elsize >> 1;\n\tint i;\n\tBool nonz = FALSE;\n\t\n\tfor (i=0; idescr->elsize;\n\tBool nonz = FALSE;\n\t\n\tfor (i=0; idescr->elsize);\n}\n\n/* taken from Python */\nstatic int \nUNICODE_compare(register Py_UNICODE *ip1, register Py_UNICODE *ip2, \n\t\tPyArrayObject *ap)\n{\n register int itemsize=ap->descr->elsize;\n\tregister Py_UNICODE c1, c2;\n\n\tif (itemsize < 0) return 0;\n\t\n\twhile(itemsize-- > 0) {\n\t\tc1 = *ip1++;\n\t\tc2 = *ip2++;\n\t\t\n\t\tif (c1 != c2) \n\t\t\treturn (c1 < c2) ? -1 : 1;\n\t}\n\treturn 0;\n}\n\n/* possibly redefine compare in terms of fields and subarrays if any */\n\n/* as it is, it compares raw-bytes as it they were strings */\n#define VOID_compare STRING_compare\n\n/****************** argfunc **********************************/\n\n/**begin repeat\n\n#fname= BOOL,BYTE, UBYTE, SHORT, USHORT, INT, UINT, LONG, ULONG, LONGLONG, ULONGLONG, FLOAT, DOUBLE, LONGDOUBLE, CFLOAT, CDOUBLE, CLONGDOUBLE#\n#type= Bool, byte, ubyte, short, ushort, int, uint, long, ulong, longlong, ulonglong, float, double, longdouble, float, double, longdouble#\n#incr= ip++*14, ip+=2*3#\n*/\n\nstatic int\n@fname@_argmax(@type@ *ip, intp n, intp *max_ind, PyArrayObject *aip)\n{\n\tregister intp i;\n\t@type@ mp=*ip;\n\t*max_ind=0;\n\tfor (i=1; i mp) {\n\t\t\tmp = *ip;\n\t\t\t*max_ind = i;\n\t\t}\n\t}\n\treturn 0;\n}\n\n/**end repeat**/\n\nstatic int \nOBJECT_argmax(PyObject **ip, intp n, intp *max_ind, PyArrayObject *aip) \n{\n\tregister intp i; \n\tPyObject *mp=ip[0]; *max_ind=0;\n\tfor(i=1; i 0) { \n\t\t\tmp = *ip; \n\t\t\t*max_ind=i;\n\t\t} \n\t} \n\treturn 0;\n}\n\n/**begin repeat\n\n#fname= STRING, UNICODE#\n#type= char, Py_UNICODE#\n\n*/\nstatic int \n@fname@_argmax(@type@ *ip, intp n, intp *max_ind, PyArrayObject *aip) \n{\n\tregister intp i; \n\tint elsize = aip->descr->elsize;\n\t@type@ *mp = (@type@ *)_pya_malloc(elsize);\n\t\n\tif (mp==NULL) return 0;\n\tmemcpy(mp, ip, elsize);\n\t*max_ind = 0;\n\tfor(i=1; i 0) { \n\t\t\tmemcpy(mp, ip, elsize);\n\t\t\t*max_ind=i;\n\t\t} \n\t} \n\t_pya_free(mp);\n\treturn 0;\n}\n\n/**end repeat**/\n\n#define VOID_argmax NULL\n\nstatic void\nBOOL_dot(char *ip1, intp is1, char *ip2, intp is2, char *op, intp n, \n void *ignore)\n{\n\tregister Bool tmp=FALSE;\n\tregister intp i;\n\tfor(i=0;ireal;\n\tstart.imag = buffer->imag;\n\tdelta.real = buffer[1].real;\n\tdelta.imag = buffer[1].imag;\n\tdelta.real -= start.real;\n\tdelta.imag -= start.imag;\n\tstart.real += (delta.real + delta.real);\n\tstart.imag += (delta.imag + delta.imag);\n\tbuffer += 2;\n\tfor (i=2; ireal = start.real;\n\t\tbuffer->imag = start.imag; \n\t\tstart.real += delta.real;\n\t\tstart.imag += delta.imag;\n\t}\n}\n/**end repeat**/\n\n\n#define _ALIGN(type) offsetof(struct {char c; type v;},v)\n\n/**begin repeat\n\n#from= VOID, STRING, UNICODE#\n#align= char, char, Py_UNICODE#\n#NAME= Void, String, Unicode#\n#endian= |, |, =#\n*/\n\nstatic PyArray_ArrFuncs _Py@NAME@_ArrFuncs = {\n\t{\n\t\t(PyArray_VectorUnaryFunc*)@from@_to_BOOL, \n\t\t(PyArray_VectorUnaryFunc*)@from@_to_BYTE, \n\t\t(PyArray_VectorUnaryFunc*)@from@_to_UBYTE, \n\t\t(PyArray_VectorUnaryFunc*)@from@_to_SHORT, \n\t\t(PyArray_VectorUnaryFunc*)@from@_to_USHORT, \n\t\t(PyArray_VectorUnaryFunc*)@from@_to_INT, \n\t\t(PyArray_VectorUnaryFunc*)@from@_to_UINT, \n\t\t(PyArray_VectorUnaryFunc*)@from@_to_LONG,\n\t\t(PyArray_VectorUnaryFunc*)@from@_to_ULONG, \n\t\t(PyArray_VectorUnaryFunc*)@from@_to_LONGLONG, \n\t\t(PyArray_VectorUnaryFunc*)@from@_to_ULONGLONG, \n\t\t(PyArray_VectorUnaryFunc*)@from@_to_FLOAT, \n\t\t(PyArray_VectorUnaryFunc*)@from@_to_DOUBLE, \n\t\t(PyArray_VectorUnaryFunc*)@from@_to_LONGDOUBLE, \n\t\t(PyArray_VectorUnaryFunc*)@from@_to_CFLOAT, \n\t\t(PyArray_VectorUnaryFunc*)@from@_to_CDOUBLE, \n\t\t(PyArray_VectorUnaryFunc*)@from@_to_CLONGDOUBLE, \n\t\t(PyArray_VectorUnaryFunc*)@from@_to_OBJECT, \n\t\t(PyArray_VectorUnaryFunc*)@from@_to_STRING, \n\t\t(PyArray_VectorUnaryFunc*)@from@_to_UNICODE, \n\t\t(PyArray_VectorUnaryFunc*)@from@_to_VOID\n\t},\n\t(PyArray_GetItemFunc*)@from@_getitem, \n\t(PyArray_SetItemFunc*)@from@_setitem,\n\t(PyArray_CopySwapNFunc*)@from@_copyswapn,\n\t(PyArray_CopySwapFunc*)@from@_copyswap,\n\t(PyArray_CompareFunc*)@from@_compare, \n\t(PyArray_ArgFunc*)@from@_argmax,\n\t(PyArray_DotFunc*)NULL, \n\t(PyArray_ScanFunc*)@from@_scan,\n\t(PyArray_FromStrFunc*)@from@_fromstr,\n\t(PyArray_NonzeroFunc*)@from@_nonzero,\n\t(PyArray_FillFunc*)NULL,\n\t{\n\t\tNULL, NULL, NULL, NULL\n\t},\n\t{\n\t\tNULL, NULL, NULL, NULL\n\t}\n};\n\nstatic PyArray_Descr @from@_Descr = { \n\tPyObject_HEAD_INIT(&PyArrayDescr_Type)\n\t&Py@NAME@ArrType_Type,\n\tPyArray_@from@LTR,\n\tPyArray_@from@LTR,\n\t'@endian@', 0,\n\tPyArray_@from@, 0,\n\t_ALIGN(@align@),\n\tNULL,\n\tNULL,\n\t&_Py@NAME@_ArrFuncs,\n};\n\n/**end repeat**/\n\n\n/**begin repeat\n\n#from= BOOL,BYTE,UBYTE,SHORT,USHORT,INT,UINT,LONG,ULONG,LONGLONG,ULONGLONG,FLOAT,DOUBLE,LONGDOUBLE,CFLOAT,CDOUBLE,CLONGDOUBLE,OBJECT#\n#num= 1*14,2*3,1#\n#fromtyp= Bool, byte, ubyte, short, ushort, int, uint, long, ulong, longlong, ulonglong, float, double, longdouble, float, double, longdouble, PyObject *#\n#NAME= Bool, Byte, UByte, Short, UShort, Int, UInt, Long, ULong, LongLong, ULongLong, Float, Double, LongDouble, CFloat, CDouble, CLongDouble, Object#\n#kind= GENBOOL, SIGNED, UNSIGNED, SIGNED, UNSIGNED, SIGNED, UNSIGNED, SIGNED, UNSIGNED, SIGNED, UNSIGNED, FLOATING, FLOATING, FLOATING, COMPLEX, COMPLEX, COMPLEX, OBJECT#\n#endian= |*3, =*14, |#\n#isobject= 0*17,1#\n*/\n\nstatic PyArray_ArrFuncs _Py@NAME@_ArrFuncs = {\n\t{\n\t\t(PyArray_VectorUnaryFunc*)@from@_to_BOOL, \n\t\t(PyArray_VectorUnaryFunc*)@from@_to_BYTE,\n\t\t(PyArray_VectorUnaryFunc*)@from@_to_UBYTE, \n\t\t(PyArray_VectorUnaryFunc*)@from@_to_SHORT, \n\t\t(PyArray_VectorUnaryFunc*)@from@_to_USHORT, \n\t\t(PyArray_VectorUnaryFunc*)@from@_to_INT, \n\t\t(PyArray_VectorUnaryFunc*)@from@_to_UINT, \n\t\t(PyArray_VectorUnaryFunc*)@from@_to_LONG,\n\t\t(PyArray_VectorUnaryFunc*)@from@_to_ULONG, \n\t\t(PyArray_VectorUnaryFunc*)@from@_to_LONGLONG, \n\t\t(PyArray_VectorUnaryFunc*)@from@_to_ULONGLONG, \n\t\t(PyArray_VectorUnaryFunc*)@from@_to_FLOAT, \n\t\t(PyArray_VectorUnaryFunc*)@from@_to_DOUBLE, \n\t\t(PyArray_VectorUnaryFunc*)@from@_to_LONGDOUBLE, \n\t\t(PyArray_VectorUnaryFunc*)@from@_to_CFLOAT, \n\t\t(PyArray_VectorUnaryFunc*)@from@_to_CDOUBLE, \n\t\t(PyArray_VectorUnaryFunc*)@from@_to_CLONGDOUBLE, \n\t\t(PyArray_VectorUnaryFunc*)@from@_to_OBJECT, \n\t\t(PyArray_VectorUnaryFunc*)@from@_to_STRING, \n\t\t(PyArray_VectorUnaryFunc*)@from@_to_UNICODE, \n\t\t(PyArray_VectorUnaryFunc*)@from@_to_VOID\n\t},\n\t(PyArray_GetItemFunc*)@from@_getitem, \n\t(PyArray_SetItemFunc*)@from@_setitem,\n\t(PyArray_CopySwapNFunc*)@from@_copyswapn,\n\t(PyArray_CopySwapFunc*)@from@_copyswap,\n\t(PyArray_CompareFunc*)@from@_compare, \n\t(PyArray_ArgFunc*)@from@_argmax,\n\t(PyArray_DotFunc*)@from@_dot, \n\t(PyArray_ScanFunc*)@from@_scan,\n\t(PyArray_FromStrFunc*)@from@_fromstr,\n\t(PyArray_NonzeroFunc*)@from@_nonzero,\n\t(PyArray_FillFunc*)@from@_fill,\n\t{\n\t\tNULL, NULL, NULL, NULL\n\t},\n\t{\n\t\tNULL, NULL, NULL, NULL\n\t}\n};\n\nstatic PyArray_Descr @from@_Descr = { \n\tPyObject_HEAD_INIT(&PyArrayDescr_Type)\n\t&Py@NAME@ArrType_Type,\n\tPyArray_@kind@LTR,\n\tPyArray_@from@LTR,\n\t'@endian@', @isobject@,\n\tPyArray_@from@, \n\t@num@*sizeof(@fromtyp@), \n\t_ALIGN(@fromtyp@),\n\tNULL,\n\tNULL,\n\t&_Py@NAME@_ArrFuncs,\n};\n\n/**end repeat**/\n\n#define _MAX_LETTER 128\nstatic char _letter_to_num[_MAX_LETTER];\n\nstatic PyArray_Descr *_builtin_descrs[] = {\n\t&BOOL_Descr,\n\t&BYTE_Descr,\n\t&UBYTE_Descr,\n\t&SHORT_Descr, \n\t&USHORT_Descr, \n\t&INT_Descr, \n\t&UINT_Descr, \n\t&LONG_Descr, \n\t&ULONG_Descr,\n\t&LONGLONG_Descr,\n\t&ULONGLONG_Descr,\n\t&FLOAT_Descr, \n\t&DOUBLE_Descr,\n\t&LONGDOUBLE_Descr,\n\t&CFLOAT_Descr, \n\t&CDOUBLE_Descr, \n\t&CLONGDOUBLE_Descr,\n\t&OBJECT_Descr, \n\t&STRING_Descr, \n\t&UNICODE_Descr,\n\t&VOID_Descr,\n};\n\n/*OBJECT_API\n Get the PyArray_Descr structure for a type.\n*/\nstatic PyArray_Descr *\nPyArray_DescrFromType(int type)\n{\n\tPyArray_Descr *ret=NULL;\n\n\tif (type < PyArray_NTYPES) {\n\t\tret = _builtin_descrs[type];\n\t}\n\telse if (type == PyArray_NOTYPE) {\n\t\t/* This needs to not raise an error so\n\t\t that PyArray_DescrFromType(PyArray_NOTYPE)\n\t\t works for backwards-compatible C-API \n\t\t*/\t\t\n\t\treturn NULL;\n\t}\n\telse if PyTypeNum_ISUSERDEF(type) {\n\t\tret = userdescrs[type-PyArray_USERDEF];\n\t} \n\telse {\n\t\tint num=PyArray_NTYPES;\n\t\tif (type < _MAX_LETTER) \n\t\t\tnum = (int) _letter_to_num[type];\n\t\tif (num >= PyArray_NTYPES)\n\t\t\tret = NULL;\n\t\telse\n\t\t\tret = _builtin_descrs[num];\n\t}\n\tif (ret==NULL) {\n\t\tPyErr_SetString(PyExc_ValueError, \n\t\t\t\t\"Invalid data-type for array\"); \n\t}\n\telse Py_INCREF(ret);\n\treturn ret;\n}\n\n\nstatic int\nset_typeinfo(PyObject *dict)\n{\n\tPyObject *infodict, *s;\n\tint i;\n\n\tfor (i=0; i<_MAX_LETTER; i++) {\n\t\t_letter_to_num[i] = PyArray_NTYPES;\n\t}\n\n/**begin repeat\n#name=BOOL,BYTE,UBYTE,SHORT,USHORT,INT,UINT,INTP,UINTP,LONG,ULONG,LONGLONG,ULONGLONG,FLOAT,DOUBLE,LONGDOUBLE,CFLOAT,CDOUBLE,CLONGDOUBLE,OBJECT,STRING,UNICODE,VOID#\n*/\n\t_letter_to_num[PyArray_@name@LTR] = PyArray_@name@;\n/**end repeat**/\n\t_letter_to_num[PyArray_STRINGLTR2] = PyArray_STRING;\n\n\n/**begin repeat\n#name=BOOL,BYTE,UBYTE,SHORT,USHORT,INT,UINT,LONG,ULONG,LONGLONG,ULONGLONG,FLOAT,DOUBLE,LONGDOUBLE,CFLOAT,CDOUBLE,CLONGDOUBLE,OBJECT,STRING,UNICODE,VOID#\n*/\n\t@name@_Descr.fields = Py_None;\n/**end repeat**/\n\n\n\n\t/* Set a dictionary with type information */\n\tinfodict = PyDict_New();\n\tif (infodict == NULL) return -1;\n\n#define BITSOF_INTP CHAR_BIT*SIZEOF_PY_INTPTR_T\n#define BITSOF_BYTE CHAR_BIT\n\n/**begin repeat \n\n#name=BOOL,BYTE,UBYTE,SHORT,USHORT,INT,UINT,INTP,UINTP,LONG,ULONG,LONGLONG,ULONGLONG#\n#uname=BOOL,BYTE*2,SHORT*2,INT*2,INTP*2,LONG*2,LONGLONG*2#\n#Name=Bool,Byte,UByte,Short,UShort,Int,UInt,Intp,UIntp,Long,ULong,LongLong,ULongLong#\n#type=Bool,byte,ubyte,short,ushort,int,uint,intp,uintp,long,ulong,longlong,ulonglong#\n#max=1,MAX_BYTE,MAX_UBYTE,MAX_SHORT,MAX_USHORT,MAX_INT,PyLong_FromUnsignedLong(MAX_UINT),PyLong_FromLongLong((longlong) MAX_INTP),PyLong_FromUnsignedLongLong((ulonglong) MAX_UINTP),MAX_LONG,PyLong_FromUnsignedLong((unsigned long) MAX_ULONG),PyLong_FromLongLong((longlong) MAX_LONGLONG), PyLong_FromUnsignedLongLong((ulonglong) MAX_ULONGLONG)#\n#min=0,MIN_BYTE,0,MIN_SHORT,0,MIN_INT,0,PyLong_FromLongLong((longlong) MIN_INTP),0,MIN_LONG,0,PyLong_FromLongLong((longlong) MIN_LONGLONG),0#\n#cx=i*6,N,N,N,l,N,N,N#\n#cn=i*7,N,i,l,i,N,i#\n*/\n \tPyDict_SetItemString(infodict, \"@name@\", \n\t\t\t s=Py_BuildValue(\"ciii@cx@@cn@O\", \n\t\t\t\t\t PyArray_@name@LTR, \n\t\t\t\t\t PyArray_@name@,\n\t\t\t\t\t BITSOF_@uname@,\n\t\t\t\t\t _ALIGN(@type@),\n\t\t\t\t\t @max@, @min@,\n\t\t\t\t (PyObject *)&Py@Name@ArrType_Type));\n\tPy_DECREF(s); \n/**end repeat**/\n\n#define BITSOF_CFLOAT 2*BITSOF_FLOAT\n#define BITSOF_CDOUBLE 2*BITSOF_DOUBLE\n#define BITSOF_CLONGDOUBLE 2*BITSOF_LONGDOUBLE\n\n/**begin repeat\n\n#type=float,double,longdouble,cfloat,cdouble,clongdouble#\n#name=FLOAT, DOUBLE, LONGDOUBLE, CFLOAT, CDOUBLE, CLONGDOUBLE#\n#Name=Float,Double,LongDouble,CFloat,CDouble,CLongDouble#\n*/\n \tPyDict_SetItemString(infodict, \"@name@\", \n\t\t\t s=Py_BuildValue(\"ciiiO\", PyArray_@name@LTR, \n\t\t\t\t\t PyArray_@name@, BITSOF_@name@,\n\t\t\t\t\t _ALIGN(@type@),\n (PyObject *)\\\n &Py@Name@ArrType_Type));\n\tPy_DECREF(s);\n/**end repeat**/\n\t\n\tPyDict_SetItemString(infodict, \"OBJECT\", \n\t\t\t s=Py_BuildValue(\"ciiiO\", PyArray_OBJECTLTR, \n\t\t\t\t\t PyArray_OBJECT, \n\t\t\t\t\t sizeof(PyObject *)*CHAR_BIT,\n\t\t\t\t\t _ALIGN(PyObject *),\n (PyObject *)\\\n &PyObjectArrType_Type));\n\tPy_DECREF(s);\n\tPyDict_SetItemString(infodict, \"STRING\", \n\t\t\t s=Py_BuildValue(\"ciiiO\", PyArray_STRINGLTR, \n\t\t\t\t\t PyArray_STRING, 0,\n\t\t\t\t\t _ALIGN(char),\n (PyObject *)\\\n &PyStringArrType_Type));\n\tPy_DECREF(s);\n\tPyDict_SetItemString(infodict, \"UNICODE\", \n\t\t\t s=Py_BuildValue(\"ciiiO\", PyArray_UNICODELTR, \n\t\t\t\t\t PyArray_UNICODE, 0,\n\t\t\t\t\t _ALIGN(Py_UNICODE),\n (PyObject *)\\\n &PyUnicodeArrType_Type));\t\n\tPy_DECREF(s);\n\tPyDict_SetItemString(infodict, \"VOID\", \n\t\t\t s=Py_BuildValue(\"ciiiO\", PyArray_VOIDLTR, \n\t\t\t\t\t PyArray_VOID, 0,\n\t\t\t\t\t _ALIGN(char),\n (PyObject *)\\\n &PyVoidArrType_Type));\t\n\tPy_DECREF(s);\n\n#define SETTYPE(name) \\\n Py_INCREF(&Py##name##ArrType_Type); \\\n PyDict_SetItemString(infodict, #name, \\\n (PyObject *)&Py##name##ArrType_Type);\n\n SETTYPE(Generic)\n SETTYPE(Number)\n SETTYPE(Integer)\n\tSETTYPE(Inexact)\n SETTYPE(SignedInteger)\n SETTYPE(UnsignedInteger)\n SETTYPE(Floating)\n SETTYPE(ComplexFloating)\n SETTYPE(Flexible)\n SETTYPE(Character)\n\n#undef SETTYPE \t\n\n\tPyDict_SetItemString(dict, \"typeinfo\", infodict);\n\tPy_DECREF(infodict);\n\treturn 0;\n}\n\n#undef _MAX_LETTER\n\n", + "source_code_before": "/* -*- c -*- */\n\nstatic ulong\nMyPyLong_AsUnsignedLong(PyObject *vv)\n{\n\tif ((vv != NULL) && PyInt_Check(vv)) {\n\t\tlong val = PyInt_AsLong(vv);\n\t\tif (val < 0) {\n\t\t\tPyErr_SetString(PyExc_OverflowError,\n\t\t\t\"can't convert negative value to unsigned long\");\n\t\t\treturn (ulong) -1;\n\t\t}\n\t\treturn val;\n\t}\n\treturn PyLong_AsUnsignedLong(vv);\t\n}\n\nstatic ulonglong\nMyPyLong_AsUnsignedLongLong(PyObject *vv)\n{\n\tif ((vv != NULL) && PyInt_Check(vv)) {\n\t\tlonglong val = PyInt_AsLong(vv);\n\t\tif (val < 0) {\n\t\t\tPyErr_SetString(PyExc_OverflowError,\n\t\t\t\"can't convert negative value to unsigned long\");\n\t\t\treturn (ulonglong) -1;\n\t\t}\n\t\treturn val;\n\t}\n\treturn PyLong_AsUnsignedLongLong(vv);\t\n}\n\nstatic double \n_getNAN(void) {\n#ifdef NAN\n return NAN;\n#else\n static double nan=0;\n \n if (nan == 0) {\n\t\tdouble mul = 1e100;\n\t\tdouble tmp = 0.0;\n\t\tdouble pinf=0;\n pinf = mul;\n for (;;) {\n pinf *= mul;\n if (pinf == tmp) break;\n tmp = pinf;\n }\n nan = pinf / pinf;\n }\n return nan;\n#endif\n}\n\nstatic double\nMyPyFloat_AsDouble(PyObject *obj)\n{\n if (obj == Py_None) return _getNAN();\n return PyFloat_AsDouble(obj); \n}\n\n\n/****************** getitem and setitem **********************/\n\n/**begin repeat\n\n#TYP=BOOL,BYTE,UBYTE,SHORT,USHORT,INT,LONG,UINT,ULONG,LONGLONG,ULONGLONG,FLOAT,DOUBLE#\n#func1=PyBool_FromLong, PyInt_FromLong*6, PyLong_FromUnsignedLong*2, PyLong_FromLongLong, PyLong_FromUnsignedLongLong, PyFloat_FromDouble*2#\n#func2=PyObject_IsTrue, PyInt_AsLong*6, MyPyLong_AsUnsignedLong*2, PyLong_AsLongLong, MyPyLong_AsUnsignedLongLong, MyPyFloat_AsDouble*2#\n#typ=Bool, byte, ubyte, short, ushort, int, long, uint, ulong, longlong, ulonglong, float, double#\n#typ1=long*7, ulong*2, longlong, ulonglong, float, double#\n#kind=Bool, Byte, UByte, Short, UShort, Int, Long, UInt, ULong, LongLong, ULongLong, Float, Double#\n*/\n\nstatic PyObject * \n@TYP@_getitem(char *ip, PyArrayObject *ap) {\n @typ@ t1;\n\n\tif ((ap==NULL) || PyArray_ISBEHAVED_RO(ap)) {\n t1 = *((@typ@ *)ip);\n return @func1@((@typ1@)t1);\n\t}\n\telse {\n ap->descr->f->copyswap(&t1, ip, !PyArray_ISNOTSWAPPED(ap),\n\t\t\t\t ap->descr->elsize);\n return @func1@((@typ1@)t1);\n\t}\n}\n\nstatic int \n@TYP@_setitem(PyObject *op, char *ov, PyArrayObject *ap) {\n @typ@ temp; /* ensures alignment */\n\n if (PyArray_IsScalar(op, @kind@)) {\n temp = ((Py@kind@ScalarObject *)op)->obval;\n }\n else {\n temp = (@typ@)@func2@(op);\n }\n if (PyErr_Occurred()) return -1;\n if (ap == NULL || PyArray_ISBEHAVED(ap)) \n *((@typ@ *)ov)=temp;\n else {\n ap->descr->f->copyswap(ov, &temp, !PyArray_ISNOTSWAPPED(ap), \n\t\t\t\t ap->descr->elsize);\n }\n \n return 0;\n}\n\n/**end repeat**/\n\n\n/**begin repeat \n\n#TYP=CFLOAT,CDOUBLE#\n#typ=float, double#\n*/\n\nstatic PyObject * \n@TYP@_getitem(char *ip, PyArrayObject *ap) {\n @typ@ t1, t2;\n\n if ((ap==NULL) || PyArray_ISBEHAVED_RO(ap)) { \n return PyComplex_FromDoubles((double)((@typ@ *)ip)[0], \n (double)((@typ@ *)ip)[1]);\n }\n else {\n\t\tint size = sizeof(@typ@);\n\t\tBool swap = !PyArray_ISNOTSWAPPED(ap);\n copy_and_swap(&t1, ip, size, 1, 0, swap);\n copy_and_swap(&t2, ip+size, size, 1, 0, swap);\n return PyComplex_FromDoubles((double)t1, (double)t2);\n }\n}\n/**end repeat**/\n\n/**begin repeat \n\n#TYP=CFLOAT, CDOUBLE, CLONGDOUBLE#\n#typ=float, double, longdouble#\n#kind=CFloat, CDouble, CLongDouble#\n*/\nstatic int \n@TYP@_setitem(PyObject *op, char *ov, PyArrayObject *ap) \n{\n Py_complex oop;\n PyObject *op2;\n c@typ@ temp;\n\tint rsize;\n \n if (!(PyArray_IsScalar(op, @kind@))) {\n if (PyArray_Check(op) && (PyArray_NDIM(op)==0)) {\n op2 = ((PyArrayObject *)op)->descr->f->getitem \\\n (((PyArrayObject *)op)->data, \n (PyArrayObject *)op);\n\t\t}\n\t\telse { \n op2 = op; Py_INCREF(op);\n }\n if (op2 == Py_None) {\n oop.real = oop.imag = _getNAN();\n }\n else {\n oop = PyComplex_AsCComplex (op2);\n }\n Py_DECREF(op2);\n if (PyErr_Occurred()) return -1;\n temp.real = (@typ@) oop.real;\n temp.imag = (@typ@) oop.imag; \n }\n\telse {\n temp = ((Py@kind@ScalarObject *)op)->obval;\n }\n\t\n memcpy(ov, &temp, ap->descr->elsize);\n if (!PyArray_ISNOTSWAPPED(ap))\n byte_swap_vector(ov, 2, sizeof(@typ@));\n\t\n\trsize = sizeof(@typ@);\n\tcopy_and_swap(ov, &temp, rsize, 2, rsize, !PyArray_ISNOTSWAPPED(ap));\n return 0;\n}\n/**end repeat**/\n\nstatic PyObject * \nLONGDOUBLE_getitem(char *ip, PyArrayObject *ap) \n{\n return PyArray_Scalar(ip, ap->descr, NULL);\n}\n\nstatic int \nLONGDOUBLE_setitem(PyObject *op, char *ov, PyArrayObject *ap) {\n longdouble temp; /* ensures alignment */\n\n if (PyArray_IsScalar(op, LongDouble)) {\n temp = ((PyLongDoubleScalarObject *)op)->obval;\n }\n else {\n if (op == Py_None) temp = (longdouble)_getNAN();\n else temp = (longdouble)PyFloat_AsDouble(op);\n }\n if (PyErr_Occurred()) return -1;\n if (ap == NULL || PyArray_ISBEHAVED(ap)) \n *((longdouble *)ov)=temp;\n else {\n copy_and_swap(ov, &temp, ap->descr->elsize, 1, 0,\n !PyArray_ISNOTSWAPPED(ap));\n }\n \n return 0;\n}\n\nstatic PyObject * \nCLONGDOUBLE_getitem(char *ip, PyArrayObject *ap) \n{\n return PyArray_Scalar(ip, ap->descr, NULL);\n}\n\n\n/* UNICODE */\nstatic PyObject * \nUNICODE_getitem(char *ip, PyArrayObject *ap) \n{\n\tPyObject *obj;\n\tsize_t size = sizeof(Py_UNICODE);\n\tint mysize;\n\tPy_UNICODE *dptr;\n\n\tmysize = ap->descr->elsize / size;\n\tdptr = (Py_UNICODE *)ip + mysize-1;\n\twhile(mysize > 0 && *dptr-- == 0) mysize--;\n\tobj = PyUnicode_FromUnicode((const Py_UNICODE *)ip, mysize);\n\tif (!PyArray_ISNOTSWAPPED(ap) && (obj != NULL)) {\n\t\tbyte_swap_vector(PyUnicode_AS_UNICODE(obj),\n\t\t\t\t mysize, size);\n\t}\n\treturn obj;\n}\n\nstatic int \nUNICODE_setitem(PyObject *op, char *ov, PyArrayObject *ap) \n{\n PyObject *temp;\n\tPy_UNICODE *ptr;\n\tint datalen;\n\tsize_t size = sizeof(Py_UNICODE);\n\n\tif ((temp=PyObject_Unicode(op)) == NULL) return -1;\n\n\tptr = PyUnicode_AS_UNICODE(temp);\n\tif ((ptr == NULL) || (PyErr_Occurred())) {\n\t\tPy_DECREF(temp);\n\t\treturn -1;\n\t}\n\tdatalen = PyUnicode_GET_DATA_SIZE(op);\n\n\tmemcpy(ov, ptr, MIN(ap->descr->elsize, datalen));\n\t/* Fill in the rest of the space with 0 */\n\tif (ap->descr->elsize > datalen) {\n\t\tmemset(ov + datalen, 0, (ap->descr->elsize - datalen));\n\t}\n\n\tif (!PyArray_ISNOTSWAPPED(ap)) \n\t\tbyte_swap_vector(ov, ap->descr->elsize / size, size);\n\t\n\tPy_DECREF(temp);\n\treturn 0;\n}\n\n/* STRING -- can handle both NULL-terminated and not NULL-terminated cases */\nstatic PyObject * \nSTRING_getitem(char *ip, PyArrayObject *ap) \n{\n\tif (ip[ap->descr->elsize-1])\n\t\treturn PyString_FromStringAndSize(ip,ap->descr->elsize);\n\telse\n\t\treturn PyString_FromString(ip);\n}\n\nstatic int \nSTRING_setitem(PyObject *op, char *ov, PyArrayObject *ap) \n{\n\tchar *ptr;\n\tint len;\n\tPyObject *temp=PyObject_Str(op);\n\t\n\tif (temp == NULL) return -1;\n\t\n\tif (PyString_AsStringAndSize(temp, &ptr, &len) == -1) {\n\t\tPy_DECREF(temp);\n\t\treturn -1;\n\t}\n\tmemcpy(ov, ptr, MIN(ap->descr->elsize,len));\n\tif (ap->descr->elsize > len) {\n\t\tmemset(ov + len, 0, (ap->descr->elsize - len));\n\t}\n\tPy_DECREF(temp);\n\treturn 0;\n}\n\n/* OBJECT */\n\nstatic PyObject * \nOBJECT_getitem(char *ip, PyArrayObject *ap) \n{\n\tPy_INCREF(*(PyObject **)ip);\n\treturn *(PyObject **)ip;\n}\n\nstatic int \nOBJECT_setitem(PyObject *op, char *ov, PyArrayObject *ap) \n{\n\tPy_XDECREF(*(PyObject **)ov);\n\tPy_INCREF(op);\n\t*(PyObject **)ov = op;\n\treturn PyErr_Occurred() ? -1:0;\n}\n\n/* VOID */\n\nstatic PyObject *\nVOID_getitem(char *ip, PyArrayObject *ap)\n{\n PyObject *u=NULL;\n\tPyArray_Descr* descr;\n int itemsize;\n\n\tdescr = ap->descr;\n\tif (descr->fields && descr->fields != Py_None) {\n\t\tPyObject *key;\n\t\tPyObject *names;\n\t\tint i, n;\n\t\tPyObject *ret;\n\t\tPyObject *tup, *title;\n\t\tPyArray_Descr *new;\n\t\tint offset;\n\t\tint savedflags;\n\n\t\t/* get the names from the fields dictionary*/\n\t\tkey = PyInt_FromLong(-1);\n\t\tnames = PyDict_GetItem(descr->fields, key);\n\t\tPy_DECREF(key);\n\t\tif (!names) goto finish;\n\t\tn = PyList_GET_SIZE(names);\n\t\tret = PyTuple_New(n);\n\t\tsavedflags = ap->flags;\n\t\tfor (i=0; ifields, key);\n\t\t\tif (!PyArg_ParseTuple(tup, \"Oi|O\", &new, &offset, \n\t\t\t\t\t &title)) {\n\t\t\t\tPy_DECREF(ret); \n\t\t\t\tap->descr = descr;\n\t\t\t\treturn NULL;\n\t\t\t}\n\t\t\tap->descr = new;\n\t\t\t/* update alignment based on offset */\n\t\t\tif ((new->alignment > 1) &&\t\t\t\\\n\t\t\t ((((intp)(ip+offset)) % new->alignment) != 0))\n\t\t\t\tap->flags &= ~ALIGNED;\n\t\t\telse\n\t\t\t\tap->flags |= ALIGNED;\n\n\t\t\tPyTuple_SET_ITEM(ret, i,\t\t\t\\\n\t\t\t\t\t new->f->getitem(ip+offset, ap));\n\t\t\tap->flags = savedflags;\n\t\t}\n\t\tap->descr = descr;\n\t\treturn ret;\n\t}\n\n\tif (descr->subarray) {\n\t\t/* return an array of the basic type */\n\t\tPyArray_Dims shape={NULL,-1};\n\t\tPyObject *ret;\n\t\tif (!(PyArray_IntpConverter(descr->subarray->shape, \n\t\t\t\t\t &shape))) {\n\t\t\tPyDimMem_FREE(shape.ptr);\n\t\t\tPyErr_SetString(PyExc_ValueError, \n\t\t\t\t\t\"invalid shape in fixed-type tuple.\");\n\t\t\treturn NULL;\n\t\t}\n Py_INCREF(descr->subarray->base);\n\t\tret = PyArray_NewFromDescr(&PyArray_Type,\n\t\t\t\t\t descr->subarray->base,\n\t\t\t\t\t shape.len, shape.ptr,\n\t\t\t\t\t NULL, ip, ap->flags, NULL);\n\t\tPyDimMem_FREE(shape.ptr);\n\t\tif (!ret) return NULL;\n\t\tPyArray_BASE(ret) = (PyObject *)ap;\n\t\tPy_INCREF(ap);\n\t\tPyArray_UpdateFlags((PyArrayObject *)ret, UPDATE_ALL_FLAGS);\n\t\treturn ret;\n\t}\n\n finish:\n\titemsize=ap->descr->elsize;\n\tif (PyArray_ISWRITEABLE(ap))\n\t\tu = PyBuffer_FromReadWriteMemory(ip, itemsize);\n\telse\n\t\tu = PyBuffer_FromMemory(ip, itemsize);\n\tif (u==NULL) goto fail;\n\n\t/* default is to return buffer object pointing to current item */\n\t/* a view of it */\n\treturn u; \n\t\n fail:\n return NULL;\n}\n\n\n\nstatic int PyArray_CopyObject(PyArrayObject *, PyObject *);\n\nstatic int\nVOID_setitem(PyObject *op, char *ip, PyArrayObject *ap)\n{\n\tPyArray_Descr* descr;\n int itemsize=ap->descr->elsize;\n\tint res;\n\n\tdescr = ap->descr;\n\tif (descr->fields && (descr->fields != Py_None) && \\\n\t PyTuple_Check(op)) {\n\t\tPyObject *key;\n\t\tPyObject *names;\n\t\tint i, n;\n\t\tPyObject *tup, *title;\n\t\tPyArray_Descr *new;\n\t\tint offset;\n\t\tint savedflags;\n\t\tres = -1;\n\t\t/* get the names from the fields dictionary*/\n\t\tkey = PyInt_FromLong(-1);\n\t\tnames = PyDict_GetItem(descr->fields, key);\n\t\tPy_DECREF(key);\n\t\tif (!names) goto finish;\n\t\tn = PyList_GET_SIZE(names);\n\t\tif (PyTuple_GET_SIZE(op) != n) {\n\t\t\tPyErr_SetString(PyExc_ValueError, \n\t\t\t\t\t\"size of tuple must match\"\\\n\t\t\t\t\t\"number of fields.\");\n\t\t\treturn -1;\n\t\t}\n\t\tsavedflags = ap->flags;\n\t\tfor (i=0; ifields, key);\n\t\t\tif (!PyArg_ParseTuple(tup, \"Oi|O\", &new, &offset, \n\t\t\t\t\t &title)) {\n\t\t\t\tap->descr = descr;\n\t\t\t\treturn -1;\n\t\t\t}\n\t\t\tap->descr = new;\n\t\t\t/* remember to update alignment flags */\n\t\t\tif ((new->alignment > 1) &&\t\t\t\\\n\t\t\t ((((intp)(ip+offset)) % new->alignment) != 0))\n\t\t\t\tap->flags &= ~ALIGNED;\n\t\t\telse\n\t\t\t\tap->flags |= ALIGNED;\n\n\t\t\tres = new->f->setitem(PyTuple_GET_ITEM(op, i),\n\t\t\t\t\t ip+offset, ap);\n\t\t\tap->flags = savedflags;\n\t\t\tif (res < 0) break;\n\t\t}\n\t\tap->descr = descr;\n\t\treturn res;\n\t}\n\n\tif (descr->subarray) {\n\t\t/* copy into an array of the same basic type */\n\t\tPyArray_Dims shape={NULL,-1};\n\t\tPyObject *ret;\n\t\tif (!(PyArray_IntpConverter(descr->subarray->shape, \n\t\t\t\t\t &shape))) {\n\t\t\tPyDimMem_FREE(shape.ptr);\n\t\t\tPyErr_SetString(PyExc_ValueError, \n\t\t\t\t\t\"invalid shape in fixed-type tuple.\");\n\t\t\treturn -1;\n\t\t}\n\t\tret = PyArray_NewFromDescr(&PyArray_Type,\n\t\t\t\t\t descr->subarray->base,\n\t\t\t\t\t shape.len, shape.ptr,\n\t\t\t\t\t NULL, ip, ap->flags, NULL);\n\t\tPyDimMem_FREE(shape.ptr);\n\t\tif (!ret) return -1;\n\t\tPyArray_BASE(ret) = (PyObject *)ap;\n\t\tPy_INCREF(ap);\n\t\tPyArray_UpdateFlags((PyArrayObject *)ret, UPDATE_ALL_FLAGS);\n\t\tres = PyArray_CopyObject((PyArrayObject *)ret, op);\n\t\tPy_DECREF(ret);\n\t\treturn res;\n\t}\n\n finish:\n\t/* Default is to use buffer interface to set item */\n\t{\n\t\tconst void *buffer;\n\t\tint buflen;\n\t\tres = PyObject_AsReadBuffer(op, &buffer, &buflen);\n\t\tif (res == -1) goto fail;\n\t\tmemcpy(ip, buffer, MIN(buflen, itemsize));\n }\n\treturn 0;\n\n fail:\n return -1; \n}\n\n\n/****************** XXX_to_YYY *******************************/ \n\n/* Assumes contiguous, and aligned, from and to */\n\n\n/**begin repeat\n#to=(BYTE,UBYTE,SHORT,USHORT,INT,UINT,LONG,ULONG,LONGLONG,ULONGLONG,FLOAT,DOUBLE,LONGDOUBLE)*16#\n#from=BYTE*13,UBYTE*13,SHORT*13,USHORT*13,INT*13,UINT*13,LONG*13,ULONG*13,LONGLONG*13,ULONGLONG*13,FLOAT*13,DOUBLE*13,LONGDOUBLE*13,CFLOAT*13,CDOUBLE*13,CLONGDOUBLE*13#\n#totyp=(byte, ubyte, short, ushort, int, uint, long, ulong, longlong, ulonglong, float, double, longdouble)*16#\n#fromtyp=byte*13, ubyte*13, short*13, ushort*13, int*13, uint*13, long*13, ulong*13, longlong*13, ulonglong*13, float*13, double*13, longdouble*13, float*13, double*13, longdouble*13#\n#incr= ip++*169,ip+=2*39#\n*/\nstatic void \n@from@_to_@to@(@fromtyp@ *ip, @totyp@ *op, intp n, PyArrayObject *aip, \n\t PyArrayObject *aop) {\n\tregister intp i; \n\tfor(i=0;idescr->elsize*3, 1#\n*/\nstatic void \n@from@_to_OBJECT(@fromtyp@ *ip, PyObject **op, intp n, PyArrayObject *aip,\n\t\t PyArrayObject *aop)\n{\n\tregister intp i; \n\tint skip=@skip@;\n\tfor(i=0;idescr->elsize*3#\n*/\nstatic void \nOBJECT_to_@to@(PyObject **ip, @totyp@ *op, intp n, PyArrayObject *aip,\n\t\t PyArrayObject *aop)\n{\n\tregister intp i; \n\tint skip=@skip@;\n\tfor(i=0;idescr->elsize*3)*3#\n#convert=1*17,0*3,1*17,0*3,0*20#\n#convstr=(Int*9,Long*2,Float*3,Complex*3,Tuple*3)*3#\n*/\nstatic void\n@from@_to_@to@(@fromtyp@ *ip, @totyp@ *op, intp n, PyArrayObject *aip, \n\t PyArrayObject *aop)\n{\n\tregister intp i;\n\tPyObject *temp=NULL;\n\tint skip=aip->descr->elsize;\n\tint oskip=@oskip@;\n\tfor(i=0; idescr->elsize;\n\tfor(i=0; i= 0x02040000) || defined(PyOS_ascii_strtod)\nstatic int\n@fname@_fromstr(char *str, @type@ *ip, char **endptr, void *ignore)\n{\n\tdouble result;\n\n\tresult = PyOS_ascii_strtod(str, endptr);\n\t*ip = (@type@) result;\n\treturn 0;\n}\n#else\n#define @fname@_fromstr NULL\n#endif\n/**end repeat**/\n\n\n\n/**begin repeat\n#fname=BOOL,CFLOAT,CDOUBLE,CLONGDOUBLE,OBJECT,STRING,UNICODE,VOID#\n*/\n#define @fname@_fromstr NULL\n/**end repeat**/\n\n\n/****************** copyswapn *************************************/\n\n/**begin repeat\n\n#fname=SHORT,USHORT,INT,UINT,LONG,ULONG,LONGLONG,ULONGLONG,FLOAT,DOUBLE,LONGDOUBLE#\n#fsize=SHORT,SHORT,INT,INT,LONG,LONG,LONGLONG,LONGLONG,FLOAT,DOUBLE,LONGDOUBLE#\n#type=short,ushort,int,uint,long,ulong,longlong,ulonglong,float,double,longdouble#\n*/\nstatic void\n@fname@_copyswapn (void *dst, void *src, intp n, int swap, int itemsize)\n{\n\tif (src != NULL) /* copy first if needed */\n\t\tmemcpy(dst, src, n*sizeof(@type@));\n\n\tif (swap) {\n\t\tregister char *a, *b, c;\n\t\tfor (a = (char *)dst; n>0; n--) {\n#if SIZEOF_@fsize@ == 2\n\t\t\tb = a + 1;\n\t\t\tc = *a; *a++ = *b; *b = c;\n\t\t\ta += 1;\n#elif SIZEOF_@fsize@ == 4\n\t\t\tb = a + 3;\n c = *a; *a++ = *b; *b-- = c;\n c = *a; *a++ = *b; *b = c;\n\t\t\ta += 2;\n#elif SIZEOF_@fsize@ == 8\n b = a + 7;\n c = *a; *a++ = *b; *b-- = c;\n c = *a; *a++ = *b; *b-- = c;\n c = *a; *a++ = *b; *b-- = c;\n c = *a; *a++ = *b; *b = c;\n\t\t\ta += 4;\n#elif SIZEOF_@fsize@ == 10\n b = a + 9;\n c = *a; *a++ = *b; *b-- = c;\n c = *a; *a++ = *b; *b-- = c;\n c = *a; *a++ = *b; *b-- = c;\n c = *a; *a++ = *b; *b-- = c;\n c = *a; *a++ = *b; *b = c;\n\t\t\ta += 5;\n#elif SIZEOF_@fsize@ == 12\n b = a + 11;\n c = *a; *a++ = *b; *b-- = c;\n c = *a; *a++ = *b; *b-- = c;\n c = *a; *a++ = *b; *b-- = c;\n c = *a; *a++ = *b; *b-- = c;\n c = *a; *a++ = *b; *b-- = c;\n c = *a; *a++ = *b; *b = c;\n\t\t\ta += 6;\n#elif SIZEOF_@fsize@ == 16\n b = a + 15;\n c = *a; *a++ = *b; *b-- = c;\n c = *a; *a++ = *b; *b-- = c;\n c = *a; *a++ = *b; *b-- = c;\n c = *a; *a++ = *b; *b-- = c;\n c = *a; *a++ = *b; *b-- = c;\n c = *a; *a++ = *b; *b-- = c;\n c = *a; *a++ = *b; *b-- = c;\n c = *a; *a++ = *b; *b = c;\n\t\t\ta += 8;\n#else\n\t\t\tregister int i, nn;\n b = a + (SIZEOF_@fsize@-1);\n\t\t\tnn = SIZEOF_@fsize@ / 2;\n for (i=0; i0; nn--) {\n#if SIZEOF_@fsize@ == 4\n\t\t\tb = a + 3;\n c = *a; *a++ = *b; *b-- = c;\n c = *a; *a++ = *b; *b = c;\n\t\t\ta += 2;\n#elif SIZEOF_@fsize@ == 8\n b = a + 7;\n c = *a; *a++ = *b; *b-- = c;\n c = *a; *a++ = *b; *b-- = c;\n c = *a; *a++ = *b; *b-- = c;\n c = *a; *a++ = *b; *b = c;\n\t\t\ta += 4;\n#elif SIZEOF_@fsize@ == 10\n b = a + 9;\n c = *a; *a++ = *b; *b-- = c;\n c = *a; *a++ = *b; *b-- = c;\n c = *a; *a++ = *b; *b-- = c;\n c = *a; *a++ = *b; *b-- = c;\n c = *a; *a++ = *b; *b = c;\n\t\t\ta += 5;\n#elif SIZEOF_@fsize@ == 12\n b = a + 11;\n c = *a; *a++ = *b; *b-- = c;\n c = *a; *a++ = *b; *b-- = c;\n c = *a; *a++ = *b; *b-- = c;\n c = *a; *a++ = *b; *b-- = c;\n c = *a; *a++ = *b; *b-- = c;\n c = *a; *a++ = *b; *b = c;\n\t\t\ta += 6;\n#elif SIZEOF_@fsize@ == 16\n b = a + 15;\n c = *a; *a++ = *b; *b-- = c;\n c = *a; *a++ = *b; *b-- = c;\n c = *a; *a++ = *b; *b-- = c;\n c = *a; *a++ = *b; *b-- = c;\n c = *a; *a++ = *b; *b-- = c;\n c = *a; *a++ = *b; *b-- = c;\n c = *a; *a++ = *b; *b-- = c;\n c = *a; *a++ = *b; *b = c;\n\t\t\ta += 8;\n#else\n\t\t\tregister int i, kn;\n\n b = a + (SIZEOF_@fsize@-1);\n\t\t\tkn = SIZEOF_@fsize@ / 2;\n for (i=0; i0; n--) {\n\t\t\tb = a + (size-1);\n for (j=0; jreal != 0) || (ip->imag != 0));\n\telse {\n\t\t/* don't worry about swap, since we are just testing\n\t\t whether or not equal to 0 */\n\t\tmemcpy(&t1, ip, sizeof(@type@));\n\t\treturn (Bool) ((t1.real != 0) || (t1.imag != 0));\n\t}\n}\n/**end repeat**/\n\n\n\n#define WHITESPACE \" \\t\\n\\r\\v\\f\"\n#define WHITELEN 6\n\nstatic Bool\nPy_STRING_ISSPACE(char ch) \n{\n\tchar white[] = WHITESPACE;\n\tint j;\n\tBool space=FALSE;\n\tfor (j=0; jdescr->elsize;\n\tint i;\n\tBool nonz = FALSE;\n\n\tfor (i=0; idescr->elsize >> 1;\n\tint i;\n\tBool nonz = FALSE;\n\t\n\tfor (i=0; idescr->elsize;\n\tBool nonz = FALSE;\n\t\n\tfor (i=0; idescr->elsize);\n}\n\n/* taken from Python */\nstatic int \nUNICODE_compare(register Py_UNICODE *ip1, register Py_UNICODE *ip2, \n\t\tPyArrayObject *ap)\n{\n register int itemsize=ap->descr->elsize;\n\tregister Py_UNICODE c1, c2;\n\n\tif (itemsize < 0) return 0;\n\t\n\twhile(itemsize-- > 0) {\n\t\tc1 = *ip1++;\n\t\tc2 = *ip2++;\n\t\t\n\t\tif (c1 != c2) \n\t\t\treturn (c1 < c2) ? -1 : 1;\n\t}\n\treturn 0;\n}\n\n/* possibly redefine compare in terms of fields and subarrays if any */\n\n/* as it is, it compares raw-bytes as it they were strings */\n#define VOID_compare STRING_compare\n\n/****************** argfunc **********************************/\n\n/**begin repeat\n\n#fname= BOOL,BYTE, UBYTE, SHORT, USHORT, INT, UINT, LONG, ULONG, LONGLONG, ULONGLONG, FLOAT, DOUBLE, LONGDOUBLE, CFLOAT, CDOUBLE, CLONGDOUBLE#\n#type= Bool, byte, ubyte, short, ushort, int, uint, long, ulong, longlong, ulonglong, float, double, longdouble, float, double, longdouble#\n#incr= ip++*14, ip+=2*3#\n*/\n\nstatic int\n@fname@_argmax(@type@ *ip, intp n, intp *max_ind, PyArrayObject *aip)\n{\n\tregister intp i;\n\t@type@ mp=*ip;\n\t*max_ind=0;\n\tfor (i=1; i mp) {\n\t\t\tmp = *ip;\n\t\t\t*max_ind = i;\n\t\t}\n\t}\n\treturn 0;\n}\n\n/**end repeat**/\n\nstatic int \nOBJECT_argmax(PyObject **ip, intp n, intp *max_ind, PyArrayObject *aip) \n{\n\tregister intp i; \n\tPyObject *mp=ip[0]; *max_ind=0;\n\tfor(i=1; i 0) { \n\t\t\tmp = *ip; \n\t\t\t*max_ind=i;\n\t\t} \n\t} \n\treturn 0;\n}\n\n/**begin repeat\n\n#fname= STRING, UNICODE#\n#type= char, Py_UNICODE#\n\n*/\nstatic int \n@fname@_argmax(@type@ *ip, intp n, intp *max_ind, PyArrayObject *aip) \n{\n\tregister intp i; \n\tint elsize = aip->descr->elsize;\n\t@type@ *mp = (@type@ *)_pya_malloc(elsize);\n\t\n\tif (mp==NULL) return 0;\n\tmemcpy(mp, ip, elsize);\n\t*max_ind = 0;\n\tfor(i=1; i 0) { \n\t\t\tmemcpy(mp, ip, elsize);\n\t\t\t*max_ind=i;\n\t\t} \n\t} \n\t_pya_free(mp);\n\treturn 0;\n}\n\n/**end repeat**/\n\n#define VOID_argmax NULL\n\nstatic void\nBOOL_dot(char *ip1, intp is1, char *ip2, intp is2, char *op, intp n, \n void *ignore)\n{\n\tregister Bool tmp=FALSE;\n\tregister intp i;\n\tfor(i=0;ireal;\n\tstart.imag = buffer->imag;\n\tdelta.real = buffer[1].real;\n\tdelta.imag = buffer[1].imag;\n\tdelta.real -= start.real;\n\tdelta.imag -= start.imag;\n\tstart.real += (delta.real + delta.real);\n\tstart.imag += (delta.imag + delta.imag);\n\tbuffer += 2;\n\tfor (i=2; ireal = start.real;\n\t\tbuffer->imag = start.imag; \n\t\tstart.real += delta.real;\n\t\tstart.imag += delta.imag;\n\t}\n}\n/**end repeat**/\n\n\n#define _ALIGN(type) offsetof(struct {char c; type v;},v)\n\n/**begin repeat\n\n#from= VOID, STRING, UNICODE#\n#align= char, char, Py_UNICODE#\n#NAME= Void, String, Unicode#\n#endian= |, |, =#\n*/\n\nstatic PyArray_ArrFuncs _Py@NAME@_ArrFuncs = {\n\t{\n\t\t(PyArray_VectorUnaryFunc*)@from@_to_BOOL, \n\t\t(PyArray_VectorUnaryFunc*)@from@_to_BYTE, \n\t\t(PyArray_VectorUnaryFunc*)@from@_to_UBYTE, \n\t\t(PyArray_VectorUnaryFunc*)@from@_to_SHORT, \n\t\t(PyArray_VectorUnaryFunc*)@from@_to_USHORT, \n\t\t(PyArray_VectorUnaryFunc*)@from@_to_INT, \n\t\t(PyArray_VectorUnaryFunc*)@from@_to_UINT, \n\t\t(PyArray_VectorUnaryFunc*)@from@_to_LONG,\n\t\t(PyArray_VectorUnaryFunc*)@from@_to_ULONG, \n\t\t(PyArray_VectorUnaryFunc*)@from@_to_LONGLONG, \n\t\t(PyArray_VectorUnaryFunc*)@from@_to_ULONGLONG, \n\t\t(PyArray_VectorUnaryFunc*)@from@_to_FLOAT, \n\t\t(PyArray_VectorUnaryFunc*)@from@_to_DOUBLE, \n\t\t(PyArray_VectorUnaryFunc*)@from@_to_LONGDOUBLE, \n\t\t(PyArray_VectorUnaryFunc*)@from@_to_CFLOAT, \n\t\t(PyArray_VectorUnaryFunc*)@from@_to_CDOUBLE, \n\t\t(PyArray_VectorUnaryFunc*)@from@_to_CLONGDOUBLE, \n\t\t(PyArray_VectorUnaryFunc*)@from@_to_OBJECT, \n\t\t(PyArray_VectorUnaryFunc*)@from@_to_STRING, \n\t\t(PyArray_VectorUnaryFunc*)@from@_to_UNICODE, \n\t\t(PyArray_VectorUnaryFunc*)@from@_to_VOID\n\t},\n\t(PyArray_GetItemFunc*)@from@_getitem, \n\t(PyArray_SetItemFunc*)@from@_setitem,\n\t(PyArray_CopySwapNFunc*)@from@_copyswapn,\n\t(PyArray_CopySwapFunc*)@from@_copyswap,\n\t(PyArray_CompareFunc*)@from@_compare, \n\t(PyArray_ArgFunc*)@from@_argmax,\n\t(PyArray_DotFunc*)NULL, \n\t(PyArray_ScanFunc*)@from@_scan,\n\t(PyArray_FromStrFunc*)@from@_fromstr,\n\t(PyArray_NonzeroFunc*)@from@_nonzero,\n\t(PyArray_FillFunc*)NULL,\n\t{\n\t\tNULL, NULL, NULL, NULL\n\t},\n\t{\n\t\tNULL, NULL, NULL, NULL\n\t}\n};\n\nstatic PyArray_Descr @from@_Descr = { \n\tPyObject_HEAD_INIT(&PyArrayDescr_Type)\n\t&Py@NAME@ArrType_Type,\n\tPyArray_@from@LTR,\n\tPyArray_@from@LTR,\n\t'@endian@', 0,\n\tPyArray_@from@, 0,\n\t_ALIGN(@align@),\n\tNULL,\n\tNULL,\n\t&_Py@NAME@_ArrFuncs,\n};\n\n/**end repeat**/\n\n\n/**begin repeat\n\n#from= BOOL,BYTE,UBYTE,SHORT,USHORT,INT,UINT,LONG,ULONG,LONGLONG,ULONGLONG,FLOAT,DOUBLE,LONGDOUBLE,CFLOAT,CDOUBLE,CLONGDOUBLE,OBJECT#\n#num= 1*14,2*3,1#\n#fromtyp= Bool, byte, ubyte, short, ushort, int, uint, long, ulong, longlong, ulonglong, float, double, longdouble, float, double, longdouble, PyObject *#\n#NAME= Bool, Byte, UByte, Short, UShort, Int, UInt, Long, ULong, LongLong, ULongLong, Float, Double, LongDouble, CFloat, CDouble, CLongDouble, Object#\n#kind= GENBOOL, SIGNED, UNSIGNED, SIGNED, UNSIGNED, SIGNED, UNSIGNED, SIGNED, UNSIGNED, SIGNED, UNSIGNED, FLOATING, FLOATING, FLOATING, COMPLEX, COMPLEX, COMPLEX, OBJECT#\n#endian= |*3, =*14, |#\n#isobject= 0*17,1#\n*/\n\nstatic PyArray_ArrFuncs _Py@NAME@_ArrFuncs = {\n\t{\n\t\t(PyArray_VectorUnaryFunc*)@from@_to_BOOL, \n\t\t(PyArray_VectorUnaryFunc*)@from@_to_BYTE,\n\t\t(PyArray_VectorUnaryFunc*)@from@_to_UBYTE, \n\t\t(PyArray_VectorUnaryFunc*)@from@_to_SHORT, \n\t\t(PyArray_VectorUnaryFunc*)@from@_to_USHORT, \n\t\t(PyArray_VectorUnaryFunc*)@from@_to_INT, \n\t\t(PyArray_VectorUnaryFunc*)@from@_to_UINT, \n\t\t(PyArray_VectorUnaryFunc*)@from@_to_LONG,\n\t\t(PyArray_VectorUnaryFunc*)@from@_to_ULONG, \n\t\t(PyArray_VectorUnaryFunc*)@from@_to_LONGLONG, \n\t\t(PyArray_VectorUnaryFunc*)@from@_to_ULONGLONG, \n\t\t(PyArray_VectorUnaryFunc*)@from@_to_FLOAT, \n\t\t(PyArray_VectorUnaryFunc*)@from@_to_DOUBLE, \n\t\t(PyArray_VectorUnaryFunc*)@from@_to_LONGDOUBLE, \n\t\t(PyArray_VectorUnaryFunc*)@from@_to_CFLOAT, \n\t\t(PyArray_VectorUnaryFunc*)@from@_to_CDOUBLE, \n\t\t(PyArray_VectorUnaryFunc*)@from@_to_CLONGDOUBLE, \n\t\t(PyArray_VectorUnaryFunc*)@from@_to_OBJECT, \n\t\t(PyArray_VectorUnaryFunc*)@from@_to_STRING, \n\t\t(PyArray_VectorUnaryFunc*)@from@_to_UNICODE, \n\t\t(PyArray_VectorUnaryFunc*)@from@_to_VOID\n\t},\n\t(PyArray_GetItemFunc*)@from@_getitem, \n\t(PyArray_SetItemFunc*)@from@_setitem,\n\t(PyArray_CopySwapNFunc*)@from@_copyswapn,\n\t(PyArray_CopySwapFunc*)@from@_copyswap,\n\t(PyArray_CompareFunc*)@from@_compare, \n\t(PyArray_ArgFunc*)@from@_argmax,\n\t(PyArray_DotFunc*)@from@_dot, \n\t(PyArray_ScanFunc*)@from@_scan,\n\t(PyArray_FromStrFunc*)@from@_fromstr,\n\t(PyArray_NonzeroFunc*)@from@_nonzero,\n\t(PyArray_FillFunc*)@from@_fill,\n\t{\n\t\tNULL, NULL, NULL, NULL\n\t},\n\t{\n\t\tNULL, NULL, NULL, NULL\n\t}\n};\n\nstatic PyArray_Descr @from@_Descr = { \n\tPyObject_HEAD_INIT(&PyArrayDescr_Type)\n\t&Py@NAME@ArrType_Type,\n\tPyArray_@kind@LTR,\n\tPyArray_@from@LTR,\n\t'@endian@', @isobject@,\n\tPyArray_@from@, \n\t@num@*sizeof(@fromtyp@), \n\t_ALIGN(@fromtyp@),\n\tNULL,\n\tNULL,\n\t&_Py@NAME@_ArrFuncs,\n};\n\n/**end repeat**/\n\n#define _MAX_LETTER 128\nstatic char _letter_to_num[_MAX_LETTER];\n\nstatic PyArray_Descr *_builtin_descrs[] = {\n\t&BOOL_Descr,\n\t&BYTE_Descr,\n\t&UBYTE_Descr,\n\t&SHORT_Descr, \n\t&USHORT_Descr, \n\t&INT_Descr, \n\t&UINT_Descr, \n\t&LONG_Descr, \n\t&ULONG_Descr,\n\t&LONGLONG_Descr,\n\t&ULONGLONG_Descr,\n\t&FLOAT_Descr, \n\t&DOUBLE_Descr,\n\t&LONGDOUBLE_Descr,\n\t&CFLOAT_Descr, \n\t&CDOUBLE_Descr, \n\t&CLONGDOUBLE_Descr,\n\t&OBJECT_Descr, \n\t&STRING_Descr, \n\t&UNICODE_Descr,\n\t&VOID_Descr,\n};\n\n/*OBJECT_API\n Get the PyArray_Descr structure for a type.\n*/\nstatic PyArray_Descr *\nPyArray_DescrFromType(int type)\n{\n\tPyArray_Descr *ret=NULL;\n\n\tif (type < PyArray_NTYPES) {\n\t\tret = _builtin_descrs[type];\n\t}\n\telse if (type == PyArray_NOTYPE) {\n\t\t/* This needs to not raise an error so\n\t\t that PyArray_DescrFromType(PyArray_NOTYPE)\n\t\t works for backwards-compatible C-API \n\t\t*/\t\t\n\t\treturn NULL;\n\t}\n\telse if PyTypeNum_ISUSERDEF(type) {\n\t\tret = userdescrs[type-PyArray_USERDEF];\n\t} \n\telse {\n\t\tint num=PyArray_NTYPES;\n\t\tif (type < _MAX_LETTER) \n\t\t\tnum = (int) _letter_to_num[type];\n\t\tif (num >= PyArray_NTYPES)\n\t\t\tret = NULL;\n\t\telse\n\t\t\tret = _builtin_descrs[num];\n\t}\n\tif (ret==NULL) {\n\t\tPyErr_SetString(PyExc_ValueError, \n\t\t\t\t\"Invalid data-type for array\"); \n\t}\n\telse Py_INCREF(ret);\n\treturn ret;\n}\n\n\nstatic int\nset_typeinfo(PyObject *dict)\n{\n\tPyObject *infodict, *s;\n\tint i;\n\n\tfor (i=0; i<_MAX_LETTER; i++) {\n\t\t_letter_to_num[i] = PyArray_NTYPES;\n\t}\n\n/**begin repeat\n#name=BOOL,BYTE,UBYTE,SHORT,USHORT,INT,UINT,INTP,UINTP,LONG,ULONG,LONGLONG,ULONGLONG,FLOAT,DOUBLE,LONGDOUBLE,CFLOAT,CDOUBLE,CLONGDOUBLE,OBJECT,STRING,UNICODE,VOID#\n*/\n\t_letter_to_num[PyArray_@name@LTR] = PyArray_@name@;\n/**end repeat**/\n\t_letter_to_num[PyArray_STRINGLTR2] = PyArray_STRING;\n\n\n/**begin repeat\n#name=BOOL,BYTE,UBYTE,SHORT,USHORT,INT,UINT,LONG,ULONG,LONGLONG,ULONGLONG,FLOAT,DOUBLE,LONGDOUBLE,CFLOAT,CDOUBLE,CLONGDOUBLE,OBJECT,STRING,UNICODE,VOID#\n*/\n\t@name@_Descr.fields = Py_None;\n/**end repeat**/\n\n\n\n\t/* Set a dictionary with type information */\n\tinfodict = PyDict_New();\n\tif (infodict == NULL) return -1;\n\n#define BITSOF_INTP CHAR_BIT*SIZEOF_PY_INTPTR_T\n#define BITSOF_BYTE CHAR_BIT\n\n/**begin repeat \n\n#name=BOOL,BYTE,UBYTE,SHORT,USHORT,INT,UINT,INTP,UINTP,LONG,ULONG,LONGLONG,ULONGLONG#\n#uname=BOOL,BYTE*2,SHORT*2,INT*2,INTP*2,LONG*2,LONGLONG*2#\n#Name=Bool,Byte,UByte,Short,UShort,Int,UInt,Intp,UIntp,Long,ULong,LongLong,ULongLong#\n#type=Bool,byte,ubyte,short,ushort,int,uint,intp,uintp,long,ulong,longlong,ulonglong#\n#max=1,MAX_BYTE,MAX_UBYTE,MAX_SHORT,MAX_USHORT,MAX_INT,PyLong_FromUnsignedLong(MAX_UINT),PyLong_FromLongLong((longlong) MAX_INTP),PyLong_FromUnsignedLongLong((ulonglong) MAX_UINTP),MAX_LONG,PyLong_FromUnsignedLong((unsigned long) MAX_ULONG),PyLong_FromLongLong((longlong) MAX_LONGLONG), PyLong_FromUnsignedLongLong((ulonglong) MAX_ULONGLONG)#\n#min=0,MIN_BYTE,0,MIN_SHORT,0,MIN_INT,0,PyLong_FromLongLong((longlong) MIN_INTP),0,MIN_LONG,0,PyLong_FromLongLong((longlong) MIN_LONGLONG),0#\n#cx=i*6,N,N,N,l,N,N,N#\n#cn=i*7,N,i,l,i,N,i#\n*/\n \tPyDict_SetItemString(infodict, \"@name@\", \n\t\t\t s=Py_BuildValue(\"ciii@cx@@cn@O\", \n\t\t\t\t\t PyArray_@name@LTR, \n\t\t\t\t\t PyArray_@name@,\n\t\t\t\t\t BITSOF_@uname@,\n\t\t\t\t\t _ALIGN(@type@),\n\t\t\t\t\t @max@, @min@,\n\t\t\t\t (PyObject *)&Py@Name@ArrType_Type));\n\tPy_DECREF(s); \n/**end repeat**/\n\n#define BITSOF_CFLOAT 2*BITSOF_FLOAT\n#define BITSOF_CDOUBLE 2*BITSOF_DOUBLE\n#define BITSOF_CLONGDOUBLE 2*BITSOF_LONGDOUBLE\n\n/**begin repeat\n\n#type=float,double,longdouble,cfloat,cdouble,clongdouble#\n#name=FLOAT, DOUBLE, LONGDOUBLE, CFLOAT, CDOUBLE, CLONGDOUBLE#\n#Name=Float,Double,LongDouble,CFloat,CDouble,CLongDouble#\n*/\n \tPyDict_SetItemString(infodict, \"@name@\", \n\t\t\t s=Py_BuildValue(\"ciiiO\", PyArray_@name@LTR, \n\t\t\t\t\t PyArray_@name@, BITSOF_@name@,\n\t\t\t\t\t _ALIGN(@type@),\n (PyObject *)\\\n &Py@Name@ArrType_Type));\n\tPy_DECREF(s);\n/**end repeat**/\n\t\n\tPyDict_SetItemString(infodict, \"OBJECT\", \n\t\t\t s=Py_BuildValue(\"ciiiO\", PyArray_OBJECTLTR, \n\t\t\t\t\t PyArray_OBJECT, \n\t\t\t\t\t sizeof(PyObject *)*CHAR_BIT,\n\t\t\t\t\t _ALIGN(PyObject *),\n (PyObject *)\\\n &PyObjectArrType_Type));\n\tPy_DECREF(s);\n\tPyDict_SetItemString(infodict, \"STRING\", \n\t\t\t s=Py_BuildValue(\"ciiiO\", PyArray_STRINGLTR, \n\t\t\t\t\t PyArray_STRING, 0,\n\t\t\t\t\t _ALIGN(char),\n (PyObject *)\\\n &PyStringArrType_Type));\n\tPy_DECREF(s);\n\tPyDict_SetItemString(infodict, \"UNICODE\", \n\t\t\t s=Py_BuildValue(\"ciiiO\", PyArray_UNICODELTR, \n\t\t\t\t\t PyArray_UNICODE, 0,\n\t\t\t\t\t _ALIGN(Py_UNICODE),\n (PyObject *)\\\n &PyUnicodeArrType_Type));\t\n\tPy_DECREF(s);\n\tPyDict_SetItemString(infodict, \"VOID\", \n\t\t\t s=Py_BuildValue(\"ciiiO\", PyArray_VOIDLTR, \n\t\t\t\t\t PyArray_VOID, 0,\n\t\t\t\t\t _ALIGN(char),\n (PyObject *)\\\n &PyVoidArrType_Type));\t\n\tPy_DECREF(s);\n\n#define SETTYPE(name) \\\n Py_INCREF(&Py##name##ArrType_Type); \\\n PyDict_SetItemString(infodict, #name, \\\n (PyObject *)&Py##name##ArrType_Type);\n\n SETTYPE(Generic)\n SETTYPE(Number)\n SETTYPE(Integer)\n\tSETTYPE(Inexact)\n SETTYPE(SignedInteger)\n SETTYPE(UnsignedInteger)\n SETTYPE(Floating)\n SETTYPE(ComplexFloating)\n SETTYPE(Flexible)\n SETTYPE(Character)\n\n#undef SETTYPE \t\n\n\tPyDict_SetItemString(dict, \"typeinfo\", infodict);\n\tPy_DECREF(infodict);\n\treturn 0;\n}\n\n#undef _MAX_LETTER\n\n", + "methods": [], + "methods_before": [], + "changed_methods": [], + "nloc": null, + "complexity": null, + "token_count": null, + "diff_parsed": { + "added": [ + "/**begin repeat", + "#name=UnsignedLong,UnsignedLongLong,LongLong#", + "#type=ulong,ulonglong,longlong#", + " */", + "static @type@", + "MyPyLong_As@name@(PyObject *vv)", + "\t@type@ ret;", + "\tif (!PyLong_Check(vv)) {", + "\t\tPyObject *mylong;", + "\t\tmylong = PyNumber_Long(vv);", + "\t\tif (mylong == NULL) return (@type@) -1;", + "\t\tvv = mylong;", + "\telse Py_INCREF(vv);", + "", + "\tret = PyLong_As@name@(vv);", + "\tPy_DECREF(vv);", + "\treturn ret;", + "/**end repeat**/", + "", + "#func2=PyObject_IsTrue, PyInt_AsLong*6, MyPyLong_AsUnsignedLong*2, MyPyLong_AsLongLong, MyPyLong_AsUnsignedLongLong, MyPyFloat_AsDouble*2#" + ], + "deleted": [ + "static ulong", + "MyPyLong_AsUnsignedLong(PyObject *vv)", + "\tif ((vv != NULL) && PyInt_Check(vv)) {", + "\t\tlong val = PyInt_AsLong(vv);", + "\t\tif (val < 0) {", + "\t\t\tPyErr_SetString(PyExc_OverflowError,", + "\t\t\t\"can't convert negative value to unsigned long\");", + "\t\t\treturn (ulong) -1;", + "\t\t}", + "\t\treturn val;", + "\t}", + "\treturn PyLong_AsUnsignedLong(vv);", + "}", + "static ulonglong", + "MyPyLong_AsUnsignedLongLong(PyObject *vv)", + "{", + "\tif ((vv != NULL) && PyInt_Check(vv)) {", + "\t\tlonglong val = PyInt_AsLong(vv);", + "\t\tif (val < 0) {", + "\t\t\tPyErr_SetString(PyExc_OverflowError,", + "\t\t\t\"can't convert negative value to unsigned long\");", + "\t\t\treturn (ulonglong) -1;", + "\t\t}", + "\t\treturn val;", + "\treturn PyLong_AsUnsignedLongLong(vv);", + "#func2=PyObject_IsTrue, PyInt_AsLong*6, MyPyLong_AsUnsignedLong*2, PyLong_AsLongLong, MyPyLong_AsUnsignedLongLong, MyPyFloat_AsDouble*2#" + ] + } + }, + { + "old_path": "numpy/lib/function_base.py", + "new_path": "numpy/lib/function_base.py", + "filename": "function_base.py", + "extension": "py", + "change_type": "MODIFY", + "diff": "@@ -14,7 +14,7 @@\n import math\n import numpy.core.numeric as _nx\n from numpy.core.numeric import ones, zeros, arange, concatenate, array, \\\n- asarray, empty, empty_like\n+ asarray, empty, empty_like, asanyarray\n from numpy.core.numeric import ScalarType, dot, where, newaxis, isscalar\n from numpy.core.umath import pi, multiply, add, arctan2, maximum, minimum, \\\n frompyfunc, isnan, absolute, cos, less_equal, sqrt, sin, mod, exp\n@@ -202,6 +202,7 @@ def piecewise(x, condlist, funclist, *args, **kw):\n |--\n \n \"\"\"\n+ x = asanyarray(x)\n n2 = len(funclist)\n if not isinstance(condlist, type([])):\n condlist = [condlist]\n", + "added_lines": 2, + "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 math\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, isscalar\nfrom numpy.core.umath import pi, multiply, add, arctan2, maximum, minimum, \\\n frompyfunc, isnan, absolute, cos, less_equal, sqrt, sin, mod, exp\nfrom numpy.core.oldnumeric import ravel, nonzero, choose, \\\n sometrue, alltrue, reshape, any, all, 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\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", + "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 math\nimport numpy.core.numeric as _nx\nfrom numpy.core.numeric import ones, zeros, arange, concatenate, array, \\\n asarray, empty, empty_like\nfrom numpy.core.numeric import ScalarType, dot, where, newaxis, isscalar\nfrom numpy.core.umath import pi, multiply, add, arctan2, maximum, minimum, \\\n frompyfunc, isnan, absolute, cos, less_equal, sqrt, sin, mod, exp\nfrom numpy.core.oldnumeric import ravel, nonzero, choose, \\\n sometrue, alltrue, reshape, any, all, 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 n2 = len(funclist)\n if not isinstance(condlist, type([])):\n condlist = [condlist]\n n = len(condlist)\n if n == n2-1: # compute the \"otherwise\" condition.\n totlist = condlist[0]\n for k in range(1, n):\n totlist |= condlist\n condlist.append(~totlist)\n n += 1\n if (n != n2):\n raise ValueError, \"function list and condition list must be the same\"\n y = empty(x.shape, x.dtype)\n for k in range(n):\n item = funclist[k]\n if not callable(item):\n y[condlist[k]] = item\n else:\n y[condlist[k]] = item(x[condlist[k]], *args, **kw)\n return y\n\ndef select(condlist, choicelist, default=0):\n \"\"\" Return an array composed of different elements of choicelist\n depending on the list of conditions.\n\n condlist is a list of condition arrays containing ones or zeros\n\n choicelist is a list of choice arrays (of the \"same\" size as the\n arrays in condlist). The result array has the \"same\" size as the\n arrays in choicelist. If condlist is [c0, ..., cN-1] then choicelist\n must be of length N. The elements of the choicelist can then be\n represented as [v0, ..., vN-1]. The default choice if none of the\n conditions are met is given as the default argument. \n\n The conditions are tested in order and the first one statisfied is\n used to select the choice. In other words, the elements of the\n output array are found from the following tree (notice the order of\n the conditions matters):\n\n if c0: v0\n elif c1: v1\n elif c2: v2\n ...\n elif cN-1: vN-1\n else: default\n\n Note that one of the condition arrays must be large enough to handle\n the largest array in the choice list.\n \"\"\"\n n = len(condlist)\n n2 = len(choicelist)\n if n2 != n:\n raise ValueError, \"list of cases must be same length as list of conditions\"\n choicelist.insert(0, default)\n S = 0\n pfac = 1\n for k in range(1, n+1):\n S += k * pfac * asarray(condlist[k-1])\n if k < n:\n pfac *= (1-asarray(condlist[k-1]))\n # handle special case of a 1-element condition but\n # a multi-element choice\n if type(S) in ScalarType or max(asarray(S).shape)==1:\n pfac = asarray(1)\n for k in range(n2+1):\n pfac = pfac + asarray(choicelist[k])\n S = S*ones(asarray(pfac).shape)\n return choose(S, tuple(choicelist))\n\ndef _asarray1d(arr, copy=False):\n \"\"\"Ensure 1D array for one array.\n \"\"\"\n if copy:\n return asarray(arr).flatten()\n else:\n return asarray(arr).ravel()\n\ndef copy(a):\n \"\"\"Return an array copy of the given object.\n \"\"\"\n return array(a, copy=True)\n\n# Basic operations\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": 32, + "end_line": 52, + "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": 54, + "end_line": 62, + "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": 64, + "end_line": 67, + "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": 69, + "end_line": 88, + "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": 90, + "end_line": 160, + "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": 162, + "end_line": 169, + "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": 169, + "parameters": [ + "x", + "condlist", + "funclist", + "args", + "kw" + ], + "start_line": 171, + "end_line": 225, + "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": 227, + "end_line": 273, + "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": 275, + "end_line": 281, + "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": 283, + "end_line": 286, + "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": 290, + "end_line": 362, + "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": 365, + "end_line": 383, + "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": 385, + "end_line": 399, + "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": 401, + "end_line": 416, + "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": 418, + "end_line": 434, + "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": 436, + "end_line": 456, + "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": 458, + "end_line": 465, + "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": 467, + "end_line": 473, + "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": 475, + "end_line": 480, + "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": 482, + "end_line": 488, + "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": 490, + "end_line": 496, + "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": 498, + "end_line": 504, + "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": 506, + "end_line": 512, + "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": 514, + "end_line": 520, + "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": 522, + "end_line": 534, + "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": 567, + "end_line": 592, + "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": 594, + "end_line": 624, + "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": 626, + "end_line": 665, + "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": 667, + "end_line": 672, + "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": 674, + "end_line": 678, + "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": 680, + "end_line": 684, + "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": 686, + "end_line": 690, + "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": 692, + "end_line": 696, + "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": 759, + "end_line": 768, + "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": 770, + "end_line": 771, + "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": 773, + "end_line": 774, + "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": 776, + "end_line": 785, + "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": 789, + "end_line": 797, + "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": 799, + "end_line": 803, + "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": 805, + "end_line": 808, + "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": 810, + "end_line": 819, + "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": 821, + "end_line": 835, + "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": 838, + "end_line": 850, + "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": 32, + "end_line": 52, + "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": 54, + "end_line": 62, + "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": 64, + "end_line": 67, + "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": 69, + "end_line": 88, + "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": 90, + "end_line": 160, + "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": 162, + "end_line": 169, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 8, + "top_nesting_level": 0 + }, + { + "name": "piecewise", + "long_name": "piecewise( x , condlist , funclist , * args , ** kw )", + "filename": "function_base.py", + "nloc": 21, + "complexity": 7, + "token_count": 163, + "parameters": [ + "x", + "condlist", + "funclist", + "args", + "kw" + ], + "start_line": 171, + "end_line": 224, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 54, + "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": "piecewise", + "long_name": "piecewise( x , condlist , funclist , * args , ** kw )", + "filename": "function_base.py", + "nloc": 22, + "complexity": 7, + "token_count": 169, + "parameters": [ + "x", + "condlist", + "funclist", + "args", + "kw" + ], + "start_line": 171, + "end_line": 225, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 55, + "top_nesting_level": 0 + } + ], + "nloc": 562, + "complexity": 140, + "token_count": 4449, + "diff_parsed": { + "added": [ + " asarray, empty, empty_like, asanyarray", + " x = asanyarray(x)" + ], + "deleted": [ + " asarray, empty, empty_like" + ] + } + } + ] + }, + { + "hash": "0245ddea0b3a7ccf8dfc1a8366cbacb2232cefb8", + "msg": "Fixed so that long integers convert to int64 arrays if possible.", + "author": { + "name": "Travis Oliphant", + "email": "oliphant@enthought.com" + }, + "committer": { + "name": "Travis Oliphant", + "email": "oliphant@enthought.com" + }, + "author_date": "2006-01-29T10:38:34+00:00", + "author_timezone": 0, + "committer_date": "2006-01-29T10:38:34+00:00", + "committer_timezone": 0, + "branches": [ + "main" + ], + "in_main_branch": true, + "merge": false, + "parents": [ + "2438f98798fa6cf0443433d879365cd2121b6b5e" + ], + "project_name": "repo_copy", + "project_path": "/tmp/tmppy2o86q9/repo_copy", + "deletions": 0, + "insertions": 9, + "lines": 9, + "files": 1, + "dmm_unit_size": 0.0, + "dmm_unit_complexity": 0.0, + "dmm_unit_interfacing": 0.0, + "modified_files": [ + { + "old_path": "numpy/core/src/arrayobject.c", + "new_path": "numpy/core/src/arrayobject.c", + "filename": "arrayobject.c", + "extension": "c", + "change_type": "MODIFY", + "diff": "@@ -5189,6 +5189,15 @@ _array_find_type(PyObject *op, PyArray_Descr *minitype, int max)\n else if (PyInt_Check(op)) {\n \t\tchktype = PyArray_DescrFromType(PyArray_LONG);\n \t\tgoto finish;\n+\t} else if (PyLong_Check(op)) {\n+\t\t/* if integer can fit into a longlong then return that\n+\t\t*/\n+\t\tif ((PyLong_AsLongLong(op) == -1) && PyErr_Occurred()) {\n+\t\t\tPyErr_Clear();\n+\t\t\tgoto deflt;\n+\t\t}\n+\t\tchktype = PyArray_DescrFromType(PyArray_LONGLONG);\n+\t\tgoto finish;\n } else if (PyFloat_Check(op)) {\n \t\tchktype = PyArray_DescrFromType(PyArray_DOUBLE);\n \t\tgoto finish;\n", + "added_lines": 9, + "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 if (PyBigArray_CheckExact(obj)) \n return PyArray_BIG_PRIORITY;\n\n ret = PyObject_GetAttrString(obj, \"__array_priority__\");\n if (ret != NULL) priority = PyFloat_AsDouble(ret);\n if (PyErr_Occurred()) {\n PyErr_Clear(); \n priority = default_;\n }\n Py_XDECREF(ret);\n return priority; \n}\n\n/* Backward compatibility only */\n/* In both Zero and One\n\n ***You must free the memory once you are done with it\n using PyDataMem_FREE(ptr) or you create a memory leak***\n\n If arr is an Object array you are getting a \n BORROWED reference to Zero or One.\n Do not DECREF.\n Please INCREF if you will be hanging on to it.\n\n The memory for the ptr still must be freed in any case;\n*/\n\n\n/*OBJECT_API\n Get pointer to zero of correct type for array.\n*/\nstatic char *\nPyArray_Zero(PyArrayObject *arr)\n{\n char *zeroval;\n int ret, storeflags;\n PyObject *obj;\n\n zeroval = PyDataMem_NEW(arr->descr->elsize);\n if (zeroval == NULL) {\n PyErr_SetNone(PyExc_MemoryError);\n return NULL;\n }\n\n\tobj=PyInt_FromLong((long) 0);\n if (PyArray_ISOBJECT(arr)) {\n memcpy(zeroval, &obj, sizeof(PyObject *));\n Py_DECREF(obj);\n return zeroval;\n }\n\tstoreflags = arr->flags;\n\tarr->flags |= BEHAVED_FLAGS;\n ret = arr->descr->f->setitem(obj, zeroval, arr);\n\tarr->flags = storeflags;\n\tPy_DECREF(obj);\n\tif (ret < 0) {\n\t\tPyDataMem_FREE(zeroval);\n\t\treturn NULL;\n\t}\n return zeroval;\n}\n\n/*OBJECT_API\n Get pointer to one of correct type for array\n*/\nstatic char *\nPyArray_One(PyArrayObject *arr)\n{\n char *oneval;\n int ret, storeflags;\n PyObject *obj;\n\n oneval = PyDataMem_NEW(arr->descr->elsize);\n if (oneval == NULL) {\n PyErr_SetNone(PyExc_MemoryError);\n return NULL;\n }\n\n obj = PyInt_FromLong((long) 1);\n if (PyArray_ISOBJECT(arr)) {\n memcpy(oneval, &obj, sizeof(PyObject *));\n Py_DECREF(obj);\n return oneval;\n } \n\n\tstoreflags = arr->flags;\n\tarr->flags |= BEHAVED_FLAGS;\n ret = arr->descr->f->setitem(obj, oneval, arr);\n\tarr->flags = storeflags;\n Py_DECREF(obj);\n if (ret < 0) {\n PyDataMem_FREE(oneval);\n return NULL;\n }\n return oneval;\n}\n\n/* End deprecated */\n\n\nstatic int \ndo_sliced_copy(char *dest, intp *dest_strides, intp *dest_dimensions,\n\t int dest_nd, char *src, intp *src_strides, \n\t intp *src_dimensions, int src_nd, int elsize, \n\t int copies) {\n intp i, j;\n\t\n if (src_nd == 0 && dest_nd == 0) {\n for(j=0; j src_nd) {\n for(i=0; i<*dest_dimensions; i++, dest += *dest_strides) {\n if (do_sliced_copy(dest, dest_strides+1, \n dest_dimensions+1, dest_nd-1,\n src, src_strides, \n src_dimensions, src_nd, \n elsize, copies) == -1) \n return -1;\n }\n return 0;\n }\n\t\n if (dest_nd == 1) {\n if (*dest_dimensions != *src_dimensions) {\n PyErr_SetString(PyExc_ValueError, \n \"matrices are not aligned for copy\");\n return -1;\n }\n for(i=0; i<*dest_dimensions; i++, src += *src_strides) {\n for(j=0; j 0) {\n if (((*dest_strides)[*dest_nd-1] == *elsize) && \n ((*src_strides)[*src_nd-1] == *elsize)) {\n if ((*dest_dimensions)[*dest_nd-1] != \n (*src_dimensions)[*src_nd-1]) {\n\t\t\t\tPyErr_SetString(PyExc_ValueError, \n\t\t\t\t\t\t\"matrices are not aligned\");\n return -1;\n }\n *elsize *= (*dest_dimensions)[*dest_nd-1];\n *dest_nd-=1; *src_nd-=1;\n } else {\n break;\n }\n }\n if (*src_nd == 0) {\n while (*dest_nd > 0) {\n if (((*dest_strides)[*dest_nd-1] == *elsize)) {\n *copies *= (*dest_dimensions)[*dest_nd-1];\n *dest_nd-=1;\n } else {\n break;\n }\n }\n }\n return 0;\n}\n\nstatic char *\ncontiguous_data(PyArrayObject *src) \n{\n intp dest_strides[MAX_DIMS], *dest_strides_ptr;\n intp *dest_dimensions=src->dimensions;\n int dest_nd=src->nd;\n intp *src_strides = src->strides;\n intp *src_dimensions=src->dimensions;\n int src_nd=src->nd;\n int elsize=src->descr->elsize;\n int copies=1;\n int ret, i;\n intp stride=elsize;\n char *new_data;\n\t\n for(i=dest_nd-1; i>=0; i--) {\n dest_strides[i] = stride;\n stride *= dest_dimensions[i];\n }\n\t\n dest_strides_ptr = dest_strides;\n\t\n if (optimize_slices(&dest_strides_ptr, &dest_dimensions, &dest_nd,\n &src_strides, &src_dimensions, &src_nd,\n &elsize, &copies) == -1) \n return NULL;\n\t\n new_data = (char *)_pya_malloc(stride);\n\t\n ret = do_sliced_copy(new_data, dest_strides_ptr, dest_dimensions, \n dest_nd, src->data, src_strides, \n src_dimensions, src_nd, elsize, copies);\n\t\n if (ret != -1) { return new_data; }\n else { _pya_free(new_data); return NULL; }\n}\n\n/* end Helper functions */\n\n\nstatic PyObject *PyArray_New(PyTypeObject *, int nd, intp *, \n int, intp *, void *, int, int, PyObject *);\n\n/* C-API functions */\n\n/* Used for arrays of python objects to increment the reference count of */\n/* every python object in the array. */\n/*OBJECT_API\n For object arrays, increment all internal references.\n*/\nstatic int \nPyArray_INCREF(PyArrayObject *mp) \n{\n\tintp i, n;\n\n PyObject **data, **data2;\n\t\n if (mp->descr->type_num != PyArray_OBJECT) return 0;\n\t\n if (PyArray_ISONESEGMENT(mp)) {\n data = (PyObject **)mp->data;\n } else {\n if ((data = (PyObject **)contiguous_data(mp)) == NULL) \n return -1;\n }\n\t\n n = PyArray_SIZE(mp);\n data2 = data;\n for(i=0; idescr->type_num != PyArray_OBJECT) return 0;\n\t\n if (PyArray_ISONESEGMENT(mp)) {\n data = (PyObject **)mp->data;\n } else {\n if ((data = (PyObject **)contiguous_data(mp)) == NULL) \n return -1;\n }\n\t\n n = PyArray_SIZE(mp);\n data2 = data; \n for(i=0; i 0; n--, a += 1) {\n b = a + 1;\n c = *a; *a++ = *b; *b = c;\n }\n break;\n case 4:\n for (a = (char*)p ; n > 0; n--, a += 2) {\n b = a + 3;\n c = *a; *a++ = *b; *b-- = c;\n c = *a; *a++ = *b; *b = c;\n }\n break;\n case 8:\n for (a = (char*)p ; n > 0; n--, a += 4) {\n b = a + 7;\n c = *a; *a++ = *b; *b-- = c;\n c = *a; *a++ = *b; *b-- = c;\n c = *a; *a++ = *b; *b-- = c;\n c = *a; *a++ = *b; *b = c;\n }\n break;\n default:\n m = size / 2;\n for (a = (char *)p ; n > 0; n--, a += m) {\n b = a + (size-1);\n for (j=0; j 1, then dst must be contiguous */\nstatic void\ncopy_and_swap(void *dst, void *src, int itemsize, intp numitems,\n intp srcstrides, int swap) \n{\n int i;\n char *s1 = (char *)src;\n char *d1 = (char *)dst;\n \n\n if ((numitems == 1) || (itemsize == srcstrides)) \n memcpy(d1, s1, itemsize*numitems);\n else { \n for (i = 0; i < numitems; i++) {\n memcpy(d1, s1, itemsize);\n d1 += itemsize;\n s1 += srcstrides;\n } \n }\n\n if (swap)\n byte_swap_vector(d1, numitems, itemsize);\n}\n\nstatic PyArray_Descr **userdescrs=NULL;\n#define error_converting(x) (((x) == -1) && PyErr_Occurred())\n\n/* Computer-generated arraytype and scalartype code */\n#include \"scalartypes.inc\"\n#include \"arraytypes.inc\"\n\n\n/* Helper functions */\n\n/*OBJECT_API*/\nstatic intp\nPyArray_PyIntAsIntp(PyObject *o)\n{\n\tlonglong long_value = -1;\n\tPyObject *obj;\n\tstatic char *msg = \"an integer is required\";\n\tPyObject *arr;\n\tPyArray_Descr *descr;\n\tintp ret;\n\n\tif (!o) {\n\t\tPyErr_SetString(PyExc_TypeError, msg);\n\t\treturn -1;\n\t}\n\n\tif (PyInt_Check(o)) {\n\t\tlong_value = (longlong) PyInt_AS_LONG(o);\n\t\tgoto finish;\n\t} else if (PyLong_Check(o)) {\n\t\tlong_value = (longlong) PyLong_AsLongLong(o);\n\t\tgoto finish;\n\t}\n\n#if SIZEOF_INTP == SIZEOF_LONG \n\tdescr = &LONG_Descr;\n#elif SIZEOF_INTP == SIZEOF_INT\n\tdescr = &INT_Descr;\n#else\n\tdescr = &LONGLONG_DESCR;\n#endif\n\tarr = NULL;\n\n\tif (PyArray_Check(o)) {\n\t\tif (PyArray_SIZE(o)!=1 || !PyArray_ISINTEGER(o)) {\n\t\t\tPyErr_SetString(PyExc_TypeError, msg);\n\t\t\treturn -1;\n\t\t}\n\t\tPy_INCREF(descr);\n\t\tarr = PyArray_CastToType((PyArrayObject *)o, descr, 0);\n\t}\n\telse if (PyArray_IsScalar(o, Integer)) {\n\t\tPy_INCREF(descr);\n\t\tarr = PyArray_FromScalar(o, descr);\n\t}\n\tif (arr != NULL) {\n\t\tret = *((intp *)PyArray_DATA(arr));\n\t\tPy_DECREF(arr);\n\t\treturn ret;\n\t}\t\t\n\tif (o->ob_type->tp_as_number != NULL &&\t\t\t\\\n\t o->ob_type->tp_as_number->nb_long != NULL) {\n\t\tobj = o->ob_type->tp_as_number->nb_long(o);\n\t\tif (obj != NULL) {\n\t\t\tlong_value = (longlong) PyLong_AsLongLong(obj);\n\t\t\tPy_DECREF(obj);\n\t\t}\n\t}\n\telse if (o->ob_type->tp_as_number != NULL &&\t\t\\\n\t\t o->ob_type->tp_as_number->nb_int != NULL) {\n\t\tobj = o->ob_type->tp_as_number->nb_int(o);\n\t\tif (obj != NULL) {\n\t\t\tlong_value = (longlong) PyLong_AsLongLong(obj);\n\t\t\tPy_DECREF(obj);\n\t\t}\n\t}\n\telse {\n\t\tPyErr_SetString(PyExc_NotImplementedError,\"\");\n\t}\n\t\n finish:\n\tif error_converting(long_value) {\n\t\tPyErr_SetString(PyExc_TypeError, msg);\n\t\treturn -1;\n\t}\n\t\n#if (SIZEOF_LONGLONG > SIZEOF_INTP)\n\tif ((long_value < MIN_INTP) || (long_value > MAX_INTP)) {\n\t\tPyErr_SetString(PyExc_ValueError,\n\t\t\t\t\"integer won't fit into a C intp\");\n\t\treturn -1;\n\t}\n#endif\n\treturn (intp) long_value;\n}\n\n\nstatic PyObject *array_int(PyArrayObject *v);\n\n/*OBJECT_API*/\nstatic int\nPyArray_PyIntAsInt(PyObject *o)\n{\n\tlong long_value = -1;\n\tPyObject *obj;\n\tstatic char *msg = \"an integer is required\";\n\tPyObject *arr;\n\tPyArray_Descr *descr;\n\tint ret;\n\n\t\n\tif (!o) {\n\t\tPyErr_SetString(PyExc_TypeError, msg);\n\t\treturn -1;\n\t}\n\n\tif (PyInt_Check(o)) {\n\t\tlong_value = (long) PyInt_AS_LONG(o);\n\t\tgoto finish;\n\t} else if (PyLong_Check(o)) {\n\t\tlong_value = (long) PyLong_AsLong(o);\n\t\tgoto finish;\n\t}\n\n\tdescr = &INT_Descr;\n\tarr=NULL;\n\tif (PyArray_Check(o)) {\n\t\tif (PyArray_SIZE(o)!=1 || !PyArray_ISINTEGER(o)) {\n\t\t\tPyErr_SetString(PyExc_TypeError, msg);\n\t\t\treturn -1;\n\t\t}\n\t\tPy_INCREF(descr);\n\t\tarr = PyArray_CastToType((PyArrayObject *)o, descr, 0);\n\t}\n\tif (PyArray_IsScalar(o, Integer)) {\n\t\tPy_INCREF(descr);\n\t\tarr = PyArray_FromScalar(o, descr);\n\t}\n\tif (arr != NULL) {\n\t\tret = *((int *)PyArray_DATA(arr));\n\t\tPy_DECREF(arr);\n\t\treturn ret;\n\t}\t\t\n\tif (o->ob_type->tp_as_number != NULL &&\t\t\\\n\t o->ob_type->tp_as_number->nb_int != NULL) {\n\t\tobj = o->ob_type->tp_as_number->nb_int(o);\n\t\tif (obj == NULL) return -1;\n\t\tlong_value = (long) PyLong_AsLong(obj);\n\t\tPy_DECREF(obj);\n\t}\n\telse if (o->ob_type->tp_as_number != NULL &&\t\t\t\\\n\t\t o->ob_type->tp_as_number->nb_long != NULL) {\n\t\tobj = o->ob_type->tp_as_number->nb_long(o);\n\t\tif (obj == NULL) return -1;\n\t\tlong_value = (long) PyLong_AsLong(obj);\n\t\tPy_DECREF(obj);\n\t}\t\t\n\telse {\n\t\tPyErr_SetString(PyExc_NotImplementedError,\"\");\n\t}\n\n finish:\n\tif error_converting(long_value) {\n\t\tPyErr_SetString(PyExc_TypeError, msg);\n\t\treturn -1;\n\t}\n\t\n#if (SIZEOF_LONG > SIZEOF_INT)\n\tif ((long_value < INT_MIN) || (long_value > INT_MAX)) {\n\t\tPyErr_SetString(PyExc_ValueError,\n\t\t\t\t\"integer won't fit into a C int\");\n\t\treturn -1;\n\t}\n#endif\n\treturn (int) long_value;\n}\n\nstatic char *\nindex2ptr(PyArrayObject *mp, intp i) \n{\n\tif(mp->nd == 0) {\n\t\tPyErr_SetString(PyExc_IndexError, \n\t\t\t\t\"0-d arrays can't be indexed\");\n\t\treturn NULL;\n\t}\n\tif (i==0 && mp->dimensions[0] > 0)\n\t\treturn mp->data;\n\t\n if (mp->nd>0 && i>0 && i < mp->dimensions[0]) {\n return mp->data+i*mp->strides[0];\n }\n PyErr_SetString(PyExc_IndexError,\"index out of bounds\");\n return NULL;\n}\n\n/*OBJECT_API\n Compute the size of an array (in number of items)\n*/\nstatic intp \nPyArray_Size(PyObject *op) \n{\n if (PyArray_Check(op)) {\n return PyArray_SIZE((PyArrayObject *)op);\n } \n\telse {\n return 0;\n }\n}\n\n/* If destination is not the right type, then src \n will be cast to destination. \n*/\n\n/* Does a flat iterator-based copy. \n\n The arrays are assumed to have the same number of elements\n They can be different sizes and have different types however. \n*/\n\n/*OBJECT_API\n Copy an Array into another array.\n*/\nstatic int\nPyArray_CopyInto(PyArrayObject *dest, PyArrayObject *src)\n{\n intp dsize, ssize, sbytes, ncopies;\n\tint elsize, index;\n PyArrayIterObject *dit=NULL;\n PyArrayIterObject *sit=NULL;\n\tchar *dptr;\n\tint swap;\n PyArray_CopySwapFunc *copyswap;\n PyArray_CopySwapNFunc *copyswapn;\n \n if (!PyArray_ISWRITEABLE(dest)) {\n PyErr_SetString(PyExc_RuntimeError, \n \"cannot write to array\");\n return -1;\n }\n\n if (!PyArray_EquivArrTypes(dest, src)) {\n return PyArray_CastTo(dest, src);\n }\n\n dsize = PyArray_SIZE(dest);\n ssize = PyArray_SIZE(src);\n\tif (ssize == 0) return 0;\n if (dsize % ssize != 0) {\n PyErr_SetString(PyExc_ValueError, \n \"number of elements in destination must be \"\\\n \"integer multiple of number of \"\\\n \"elements in source\");\n return -1;\n }\n ncopies = (dsize / ssize);\n\n\tswap = PyArray_ISNOTSWAPPED(dest) != PyArray_ISNOTSWAPPED(src);\n\tcopyswap = dest->descr->f->copyswap;\n\tcopyswapn = dest->descr->f->copyswapn;\n\n elsize = dest->descr->elsize;\n\n if ((PyArray_ISCONTIGUOUS(dest) && PyArray_ISCONTIGUOUS(src))\t\\\n\t || (PyArray_ISFORTRAN(dest) && PyArray_ISFORTRAN(src))) {\n \n PyArray_XDECREF(dest);\n dptr = dest->data;\n sbytes = ssize * src->descr->elsize;\n while(ncopies--) {\n memmove(dptr, src->data, sbytes);\n dptr += sbytes;\n }\n\t\tif (swap)\n\t\t\tcopyswapn(dest->data, NULL, dsize, 1, elsize);\n PyArray_INCREF(dest);\n return 0;\n }\n\n dit = (PyArrayIterObject *)PyArray_IterNew((PyObject *)dest);\n sit = (PyArrayIterObject *)PyArray_IterNew((PyObject *)src);\n\n if ((dit == NULL) || (sit == NULL)) {\n Py_XDECREF(dit);\n Py_XDECREF(sit);\n return -1;\n }\n\n PyArray_XDECREF(dest);\n while(ncopies--) {\n index = ssize;\n while(index--) {\n memmove(dit->dataptr, sit->dataptr, elsize);\n\t\t\tif (swap)\n\t\t\t\tcopyswap(dit->dataptr, NULL, 1, elsize);\n PyArray_ITER_NEXT(dit);\n PyArray_ITER_NEXT(sit);\n }\n PyArray_ITER_RESET(sit);\n } \n PyArray_INCREF(dest);\n Py_DECREF(dit);\n Py_DECREF(sit);\n\treturn 0;\n}\n\n\nstatic int \nPyArray_CopyObject(PyArrayObject *dest, PyObject *src_object) \n{\n PyArrayObject *src;\n int ret;\n\n\tPy_INCREF(dest->descr);\n src = (PyArrayObject *)PyArray_FromAny(src_object,\n dest->descr, 0,\n dest->nd, FORTRAN_IF(dest), NULL);\n if (src == NULL) return -1;\n\n ret = PyArray_CopyInto(dest, src);\n Py_DECREF(src);\n return ret;\n}\n\n\n/* These are also old calls (should use PyArray_New) */\n\n/* They all zero-out the memory as previously done */\n\n/* steals reference to descr -- and enforces native byteorder on it.*/\n/*OBJECT_API\n Like FromDimsAndData but uses the Descr structure instead of typecode\n as input.\n*/\nstatic PyObject *\nPyArray_FromDimsAndDataAndDescr(int nd, int *d, \n PyArray_Descr *descr,\n char *data)\n{\n\tPyObject *ret;\n#if SIZEOF_INTP != SIZEOF_INT\n\tint i;\n\tintp newd[MAX_DIMS];\n#endif\n\n\tif (!PyArray_ISNBO(descr->byteorder))\n\t\tdescr->byteorder = '=';\n\t\n#if SIZEOF_INTP != SIZEOF_INT\n\tfor (i=0; itype_num != PyArray_OBJECT)) {\n\t\tmemset(PyArray_DATA(ret), 0, PyArray_NBYTES(ret));\n\t}\n\treturn ret;\n}\n\n/* end old calls */\n\n\n/*OBJECT_API\n Copy an array.\n*/\nstatic PyObject *\nPyArray_NewCopy(PyArrayObject *m1, int fortran)\n{\n\tPyArrayObject *ret;\n\tif (fortran < 0) fortran = PyArray_ISFORTRAN(m1);\n\t\n\tPy_INCREF(m1->descr);\n\tret = (PyArrayObject *)PyArray_NewFromDescr(m1->ob_type, \n\t\t\t\t\t\t m1->descr,\n\t\t\t\t\t\t m1->nd, \n\t\t\t\t\t\t m1->dimensions,\n\t\t\t\t\t\t NULL, NULL, \n\t\t\t\t\t\t fortran, \n\t\t\t\t\t\t (PyObject *)m1);\n\tif (ret == NULL) return NULL;\n if (PyArray_CopyInto(ret, m1) == -1) {\n Py_DECREF(ret);\n return NULL;\n }\n\t\n return (PyObject *)ret;\t\n}\n\nstatic PyObject *array_big_item(PyArrayObject *, intp);\n\n/* Does nothing with descr (cannot be NULL) */\n/*OBJECT_API\n Get scalar-equivalent to a region of memory described by a descriptor.\n*/\nstatic PyObject *\nPyArray_Scalar(void *data, PyArray_Descr *descr, PyObject *base)\n{\n\tPyTypeObject *type;\n\tPyObject *obj;\n void *destptr;\n PyArray_CopySwapFunc *copyswap;\n\tint type_num;\n\tint itemsize;\n\tint swap;\n\n\ttype_num = descr->type_num;\n\tif (type_num == PyArray_BOOL)\n\t\tPyArrayScalar_RETURN_BOOL_FROM_LONG(*(Bool*)data);\n\telse if (type_num == PyArray_OBJECT) {\n\t\tPy_INCREF(*((PyObject **)data));\n\t\treturn *((PyObject **)data);\n\t}\n\titemsize = descr->elsize;\n type = descr->typeobj;\n copyswap = descr->f->copyswap;\n\tswap = !PyArray_ISNBO(descr->byteorder);\n\tif (type->tp_itemsize != 0) /* String type */\n\t\tobj = type->tp_alloc(type, itemsize);\n\telse\n\t\tobj = type->tp_alloc(type, 0);\n\tif (obj == NULL) return NULL;\n\tif PyTypeNum_ISEXTENDED(type_num) { \n\t\tif (type_num == PyArray_STRING) {\n\t\t\tdestptr = PyString_AS_STRING(obj);\n\t\t\t((PyStringObject *)obj)->ob_shash = -1;\n\t\t\t((PyStringObject *)obj)->ob_sstate =\t\\\n\t\t\t\tSSTATE_NOT_INTERNED; \n\t\t}\n\t\telse if (type_num == PyArray_UNICODE) {\n\t\t\tPyUnicodeObject *uni = (PyUnicodeObject*)obj;\n\t\t\tint length = itemsize / sizeof(Py_UNICODE);\n\t\t\t/* Need an extra slot and need to use \n\t\t\t Python memory manager */\n\t\t\tuni->str = NULL;\n\t\t\tdestptr = PyMem_NEW(Py_UNICODE, length+1);\n\t\t\tif (destptr == NULL) {\n Py_DECREF(obj);\n\t\t\t\treturn PyErr_NoMemory();\n\t\t\t}\n\t\t\tuni->str = (Py_UNICODE *)destptr;\n\t\t\tuni->str[0] = 0;\n\t\t\tuni->str[length] = 0;\n\t\t\tuni->length = length;\n\t\t\tuni->hash = -1;\n\t\t\tuni->defenc = NULL;\n\t\t}\n\t\telse { \n\t\t\tPyVoidScalarObject *vobj = (PyVoidScalarObject *)obj;\n\t\t\tvobj->base = NULL;\n\t\t\tvobj->descr = descr;\n\t\t\tPy_INCREF(descr);\n\t\t\tvobj->obval = NULL;\n\t\t\tvobj->ob_size = itemsize;\n\t\t\tvobj->flags = BEHAVED_FLAGS | OWNDATA;\n\t\t\tswap = 0;\n\t\t\tif (descr->fields) {\n\t\t\t\tif (base) {\n\t\t\t\t\tPy_INCREF(base);\n\t\t\t\t\tvobj->base = base;\n\t\t\t\t\tvobj->flags = PyArray_FLAGS(base);\n\t\t\t\t\tvobj->flags &= ~OWNDATA;\n\t\t\t\t\tvobj->obval = data;\n\t\t\t\t\treturn obj;\n\t\t\t\t}\n\t\t\t}\n\t\t\tdestptr = PyDataMem_NEW(itemsize);\n\t\t\tif (destptr == NULL) {\n Py_DECREF(obj);\n\t\t\t\treturn PyErr_NoMemory();\n\t\t\t}\n\t\t\tvobj->obval = destptr;\n\t\t}\n\t}\n\telse {\n\t\tdestptr = _SOFFSET_(obj, type_num);\n\t}\n\t/* copyswap for OBJECT increments the reference count */\n copyswap(destptr, data, swap, itemsize);\n\treturn obj;\n}\n\n/* returns an Array-Scalar Object of the type of arr\n from the given pointer to memory -- main Scalar creation function\n default new method calls this. \n*/\n\n/* Ideally, here the descriptor would contain all the information needed.\n So, that we simply need the data and the descriptor, and perhaps\n a flag \n*/\n\n/*OBJECT_API\n Get scalar-equivalent to 0-d array\n*/\nstatic PyObject *\nPyArray_ToScalar(void *data, PyArrayObject *arr)\n{\n\treturn PyArray_Scalar(data, arr->descr, (PyObject *)arr);\n}\n\n\n/* Return Python scalar if 0-d array object is encountered */\n\n/*OBJECT_API\n Return either an array or the appropriate Python object if the array\n is 0d and matches a Python type.\n*/\nstatic PyObject *\nPyArray_Return(PyArrayObject *mp) \n{\n \n\n\tif (mp == NULL) return NULL;\n\n if (PyErr_Occurred()) {\n Py_XDECREF(mp);\n return NULL;\n }\n\n\tif (!PyArray_Check(mp)) return (PyObject *)mp;\n\t\n\tif (mp->nd == 0) {\n\t\tPyObject *ret;\n\t\tret = PyArray_ToScalar(mp->data, mp);\n\t\tPy_DECREF(mp);\n\t\treturn ret;\n\t}\n\telse {\n\t\treturn (PyObject *)mp;\n\t}\n}\n\n/*\n returns typenum to associate with this type >=PyArray_USERDEF.\n Also creates a copy of the VOID_DESCR table inserting it's typeobject in\n and it's typenum in the appropriate place.\n \n needs the userdecrs table and PyArray_NUMUSER variables\n defined in arratypes.inc\n*/\n/*OBJECT_API\n Register Data type\n*/\nstatic int \nPyArray_RegisterDataType(PyTypeObject *type)\n{\n\tPyArray_Descr *descr;\n\tPyObject *obj;\n\tint typenum;\n\tint i;\n\t\n\tif ((type == &PyVoidArrType_Type) ||\t\t\t\\\n\t !PyType_IsSubtype(type, &PyVoidArrType_Type)) {\n\t\tPyErr_SetString(PyExc_ValueError, \n\t\t\t\t\"can only register void subtypes\");\n\t\treturn -1;\n\t}\n\t/* See if this type is already registered */\n\tfor (i=0; itypeobj == type)\n\t\t\treturn descr->type_num;\n\t}\n\tdescr = PyArray_DescrNewFromType(PyArray_VOID);\n\ttypenum = PyArray_USERDEF + PyArray_NUMUSERTYPES;\n\tdescr->type_num = typenum;\n descr->typeobj = type;\n\tobj = PyObject_GetAttrString((PyObject *)type,\"itemsize\");\n\tif (obj) {\n\t\ti = PyInt_AsLong(obj);\n\t\tif ((i < 0) && (PyErr_Occurred())) PyErr_Clear();\n\t\telse descr->elsize = i;\n\t\tPy_DECREF(obj);\n\t}\n\tPy_INCREF(type);\n\tuserdescrs = realloc(userdescrs, \n\t\t\t (PyArray_NUMUSERTYPES+1)*sizeof(void *));\n if (userdescrs == NULL) {\n PyErr_SetString(PyExc_MemoryError, \"RegisterDataType\");\n\t\tPy_DECREF(descr);\n return -1;\n }\n\tuserdescrs[PyArray_NUMUSERTYPES++] = descr;\n\treturn typenum;\n}\n\n\n/* \n copyies over from the old descr table for anything\n NULL or zero in what is given. \n DECREF's the Descr already there.\n places a pointer to the new one into the slot.\n*/\n\n/* steals a reference to descr */\n/*OBJECT_API\n Insert Descr Table\n*/\nstatic int\nPyArray_RegisterDescrForType(int typenum, PyArray_Descr *descr)\n{\n\tPyArray_Descr *old;\n\n\tif (!PyTypeNum_ISUSERDEF(typenum)) {\n\t\tPyErr_SetString(PyExc_TypeError, \n\t\t\t\t\"data type not registered\");\n\t\tPy_DECREF(descr);\n\t\treturn -1;\n\t}\n\told = userdescrs[typenum-PyArray_USERDEF];\n\tdescr->typeobj = old->typeobj;\n\tdescr->type_num = typenum;\n\n\tif (descr->f == NULL) descr->f = old->f;\n\tif (descr->fields == NULL) {\n\t\tdescr->fields = old->fields;\n\t\tPy_XINCREF(descr->fields);\n\t}\n\tif (descr->subarray == NULL && old->subarray) {\n\t\tdescr->subarray = _pya_malloc(sizeof(PyArray_ArrayDescr));\n\t\tmemcpy(descr->subarray, old->subarray, \n\t\t sizeof(PyArray_ArrayDescr));\n\t\tPy_INCREF(descr->subarray->shape);\n\t\tPy_INCREF(descr->subarray->base);\n\t}\n Py_XINCREF(descr->typeobj);\n\n#define _ZERO_CHECK(member) \\\n\tif (descr->member == 0) descr->member = old->member\n\n\t_ZERO_CHECK(kind);\n\t_ZERO_CHECK(type);\n _ZERO_CHECK(byteorder);\n\t_ZERO_CHECK(elsize);\n\t_ZERO_CHECK(alignment);\n#undef _ZERO_CHECK\n\n\tPy_DECREF(old);\n\tuserdescrs[typenum-PyArray_USERDEF] = descr;\n\treturn 0;\n}\n\n\n/*OBJECT_API\n To File\n*/\nstatic int\nPyArray_ToFile(PyArrayObject *self, FILE *fp, char *sep, char *format) \n{\n intp size;\n intp n, n2;\n int n3, n4;\n PyArrayIterObject *it;\n PyObject *obj, *strobj, *tupobj;\n\n\tn3 = (sep ? strlen((const char *)sep) : 0);\n\tif (n3 == 0) { /* binary data */\n if (PyArray_ISOBJECT(self)) {\n PyErr_SetString(PyExc_ValueError, \"cannot write \"\\\n\t\t\t\t\t\"object arrays to a file in \"\t\\\n\t\t\t\t\t\"binary mode\");\n return -1;\n }\n\n if (PyArray_ISCONTIGUOUS(self)) {\n size = PyArray_SIZE(self);\n if ((n=fwrite((const void *)self->data, \n (size_t) self->descr->elsize,\n (size_t) size, fp)) < size) {\n PyErr_Format(PyExc_ValueError, \n \"%ld requested and %ld written\",\n (long) size, (long) n);\n return -1;\n }\n }\n else {\n it=(PyArrayIterObject *) \\\n PyArray_IterNew((PyObject *)self);\n while(it->index < it->size) {\n if (fwrite((const void *)it->dataptr, \n (size_t) self->descr->elsize,\n 1, fp) < 1) {\n PyErr_Format(PyExc_IOError, \n \"problem writing element\"\\\n \" %d to file\", \n\t\t\t\t\t\t (int)it->index);\n Py_DECREF(it);\n return -1;\n }\n PyArray_ITER_NEXT(it);\n }\n Py_DECREF(it);\n } \n }\n else { /* text data */\n it=(PyArrayIterObject *) \\\n PyArray_IterNew((PyObject *)self);\n\t\tn4 = (format ? strlen((const char *)format) : 0);\n while(it->index < it->size) {\n obj = self->descr->f->getitem(it->dataptr, self);\n if (obj == NULL) {Py_DECREF(it); return -1;}\n\t\t\tif (n4 == 0) { /* standard writing */\n\t\t\t\tstrobj = PyObject_Str(obj);\n\t\t\t\tPy_DECREF(obj);\n\t\t\t\tif (strobj == NULL) {Py_DECREF(it); return -1;}\n\t\t\t}\n\t\t\telse { /* use format string */\n\t\t\t\ttupobj = PyTuple_New(1);\n\t\t\t\tif (tupobj == NULL) {Py_DECREF(it); return -1;}\n\t\t\t\tPyTuple_SET_ITEM(tupobj,0,obj);\n\t\t\t\tobj = PyString_FromString((const char *)format);\n\t\t\t\tif (obj == NULL) {Py_DECREF(tupobj); \n\t\t\t\t\tPy_DECREF(it); return -1;}\n\t\t\t\tstrobj = PyString_Format(obj, tupobj);\n\t\t\t\tPy_DECREF(obj);\n\t\t\t\tPy_DECREF(tupobj);\n\t\t\t\tif (strobj == NULL) {Py_DECREF(it); return -1;}\n\t\t\t}\n if ((n=fwrite(PyString_AS_STRING(strobj), \n 1, n2=PyString_GET_SIZE(strobj),\n fp)) < n2) {\n PyErr_Format(PyExc_IOError,\n \"problem writing element %d\"\\\n \" to file\", \n\t\t\t\t\t (int) it->index);\n Py_DECREF(strobj);\n Py_DECREF(it);\n return -1;\n }\n /* write separator for all but last one */\n if (it->index != it->size-1) \n fwrite(sep, 1, n3, fp);\n Py_DECREF(strobj);\n PyArray_ITER_NEXT(it);\n }\n Py_DECREF(it);\n }\n return 0;\n}\n\n/*OBJECT_API\n To List\n*/\nstatic PyObject *\nPyArray_ToList(PyArrayObject *self) \n{\n PyObject *lp;\n PyArrayObject *v;\n intp sz, i;\n\t\n if (!PyArray_Check(self)) return (PyObject *)self;\n\n if (self->nd == 0) \n\t\treturn self->descr->f->getitem(self->data,self);\n\t\n sz = self->dimensions[0];\n lp = PyList_New(sz);\n\t\n for (i=0; ind >= self->nd) {\n\t\t\tPyErr_SetString(PyExc_RuntimeError,\n\t\t\t\t\t\"array_item not returning smaller-\" \\\n\t\t\t\t\t\"dimensional array\");\n Py_DECREF(v);\n\t\t\tPy_DECREF(lp);\n\t\t\treturn NULL;\n\t\t}\n PyList_SetItem(lp, i, PyArray_ToList(v));\n\t\tPy_DECREF(v);\n }\n\t\n return lp;\n}\n\nstatic PyObject *\nPyArray_ToString(PyArrayObject *self)\n{\n intp numbytes;\n intp index;\n char *dptr;\n int elsize;\n PyObject *ret;\n PyArrayIterObject *it;\n \n\t/* if (PyArray_TYPE(self) == PyArray_OBJECT) {\n\t\t PyErr_SetString(PyExc_ValueError, \"a string for the data\" \\\n\t\t \"in an object array is not appropriate\");\n\t\t return NULL;\n\t\t }\n\t*/\n\n numbytes = PyArray_NBYTES(self);\n if (PyArray_ISONESEGMENT(self)) {\n ret = PyString_FromStringAndSize(self->data, (int) numbytes);\n }\n else {\n it = (PyArrayIterObject *)PyArray_IterNew((PyObject *)self);\n if (it==NULL) return NULL;\n ret = PyString_FromStringAndSize(NULL, (int) numbytes);\n if (ret == NULL) {Py_DECREF(it); return NULL;}\n dptr = PyString_AS_STRING(ret);\n index = it->size;\n elsize = self->descr->elsize;\n while(index--) {\n memcpy(dptr, it->dataptr, elsize);\n dptr += elsize;\n PyArray_ITER_NEXT(it);\n }\n Py_DECREF(it);\n }\n\treturn ret;\n}\n\n\n/*********************** end C-API functions **********************/\n\n\n/* array object functions */\n\nstatic void \narray_dealloc(PyArrayObject *self) {\n\n if (self->weakreflist != NULL)\n PyObject_ClearWeakRefs((PyObject *)self);\n\n if(self->base) {\n\t\t/* UPDATEIFCOPY means that base points to an \n\t\t array that should be updated with the contents\n\t\t of this array upon destruction.\n self->base->flags must have been WRITEABLE \n (checked previously) and it was locked here\n thus, unlock it.\n\t\t*/\n\t\tif (self->flags & UPDATEIFCOPY) {\n ((PyArrayObject *)self->base)->flags |= WRITEABLE;\n\t\t\tPy_INCREF(self); /* hold on to self in next call */\n PyArray_CopyInto((PyArrayObject *)self->base, self);\n\t\t\t/* Don't need to DECREF -- because we are deleting\n\t\t\t self already... */\n\t\t}\n\t\t/* In any case base is pointing to something that we need\n\t\t to DECREF -- either a view or a buffer object */\n Py_DECREF(self->base);\n }\n \n if ((self->flags & OWN_DATA) && self->data) {\n\t\t/* Free internal references if an Object array */\n\t\tif (PyArray_ISOBJECT(self))\n\t\t\tPyArray_XDECREF(self);\n PyDataMem_FREE(self->data);\n }\n\t\n\tPyDimMem_FREE(self->dimensions);\n\n\tPy_DECREF(self->descr);\n\t\n self->ob_type->tp_free((PyObject *)self);\n}\n\n/*************************************************************************\n **************** Implement Mapping Protocol ***************************\n *************************************************************************/\n\nstatic int \narray_length(PyArrayObject *self) \n{\n if (self->nd != 0) {\n return self->dimensions[0];\n } else {\n\t\tPyErr_SetString(PyExc_TypeError, \"len() of unsized object\");\n\t\treturn -1;\n }\n}\n\nstatic PyObject *\narray_big_item(PyArrayObject *self, intp i) \n{\n\tchar *item;\n\tPyArrayObject *r;\n\t\t\n\tif(self->nd == 0) {\n\t\tPyErr_SetString(PyExc_IndexError, \n\t\t\t\t\"0-d arrays can't be indexed\");\n\t\treturn NULL;\n\t}\n if ((item = index2ptr(self, i)) == NULL) return NULL;\n\t\n\tPy_INCREF(self->descr);\n\tr = (PyArrayObject *)PyArray_NewFromDescr(self->ob_type, \n\t\t\t\t\t\t self->descr,\n\t\t\t\t\t\t self->nd-1, \n\t\t\t\t\t\t self->dimensions+1, \n\t\t\t\t\t\t self->strides+1, item, \n\t\t\t\t\t\t self->flags,\n\t\t\t\t\t\t (PyObject *)self);\n\tif (r == NULL) return NULL;\n\tPy_INCREF(self);\n\tr->base = (PyObject *)self;\n PyArray_UpdateFlags(r, CONTIGUOUS | FORTRAN);\n\treturn (PyObject *)r;\n}\n\nstatic PyObject *\narray_item_nice(PyArrayObject *self, int i) \n{\n\treturn PyArray_Return((PyArrayObject *)array_big_item(self, (intp) i));\n}\n\n\nstatic int \narray_ass_big_item(PyArrayObject *self, intp i, PyObject *v) \n{\n PyArrayObject *tmp;\n char *item;\n int ret;\n\n if (v == NULL) {\n PyErr_SetString(PyExc_ValueError, \n \"can't delete array elements\");\n return -1;\n }\n\tif (!PyArray_ISWRITEABLE(self)) {\n\t\tPyErr_SetString(PyExc_RuntimeError,\n\t\t\t\t\"array is not writeable\");\n\t\treturn -1;\n\t}\n if (self->nd == 0) {\n PyErr_SetString(PyExc_IndexError, \n \"0-d arrays can't be indexed.\");\n return -1;\n }\n\n if (i < 0) i = i+self->dimensions[0];\n\n if (self->nd > 1) {\n if((tmp = (PyArrayObject *)array_big_item(self, i)) == NULL)\n return -1;\n ret = PyArray_CopyObject(tmp, v);\n Py_DECREF(tmp);\n return ret; \n }\n\t\n if ((item = index2ptr(self, i)) == NULL) return -1;\n if (self->descr->f->setitem(v, item, self) == -1) return -1;\n return 0;\n}\n\n#if SIZEOF_INT == SIZEOF_INTP\n#define array_ass_item array_ass_big_item\n#else\nstatic int\narray_ass_item(PyArrayObject *self, int i, PyObject *v)\n{\n\treturn array_ass_big_item(self, (intp) i, v);\n}\n#endif\n\n\n/* -------------------------------------------------------------- */\nstatic int\nslice_coerce_index(PyObject *o, intp *v)\n{\n\t*v = PyArray_PyIntAsIntp(o);\n\tif (error_converting(*v)) {\n\t\tPyErr_Clear();\n\t\treturn 0;\n\t}\n\treturn 1;\n}\n\n\n/* This is basically PySlice_GetIndicesEx, but with our coercion\n * of indices to integers (plus, that function is new in Python 2.3) */\nstatic int\nslice_GetIndices(PySliceObject *r, intp length,\n intp *start, intp *stop, intp *step,\n intp *slicelength)\n{\n\tintp defstart, defstop;\n\t\n\tif (r->step == Py_None) {\n\t\t*step = 1;\n\t} else {\n\t\tif (!slice_coerce_index(r->step, step)) return -1;\n\t\tif (*step == 0) {\n\t\t\tPyErr_SetString(PyExc_ValueError, \n\t\t\t\t\t\"slice step cannot be zero\");\n\t\t\treturn -1;\n\t\t}\n\t}\n\t\n\tdefstart = *step < 0 ? length - 1 : 0;\n\tdefstop = *step < 0 ? -1 : length;\n\t\n\tif (r->start == Py_None) {\n\t\t*start = *step < 0 ? length-1 : 0;\n\t} else {\n\t\tif (!slice_coerce_index(r->start, start)) return -1;\n\t\tif (*start < 0) *start += length;\n\t\tif (*start < 0) *start = (*step < 0) ? -1 : 0;\n\t\tif (*start >= length) {\n\t\t\t*start = (*step < 0) ? length - 1 : length;\n\t\t}\n\t}\n\t\n\tif (r->stop == Py_None) {\n\t\t*stop = defstop;\n\t} else {\n\t\tif (!slice_coerce_index(r->stop, stop)) return -1;\n\t\tif (*stop < 0) *stop += length;\n if (*stop < 0) *stop = -1;\n if (*stop > length) *stop = length;\n\t}\n\t\n\tif ((*step < 0 && *stop >= *start) || \\\n\t (*step > 0 && *start >= *stop)) {\n\t\t*slicelength = 0;\n\t} else if (*step < 0) {\n\t\t*slicelength = (*stop - *start + 1) / (*step) + 1;\n\t} else {\n\t\t*slicelength = (*stop - *start - 1) / (*step) + 1;\n\t}\n\t\n\treturn 0;\n}\n\n#define PseudoIndex -1\n#define RubberIndex -2\n#define SingleIndex -3\n\nstatic intp\nparse_subindex(PyObject *op, intp *step_size, intp *n_steps, intp max)\n{\n\tintp index;\n\t\n\tif (op == Py_None) {\n\t\t*n_steps = PseudoIndex;\n\t\tindex = 0;\n\t} else if (op == Py_Ellipsis) {\n\t\t*n_steps = RubberIndex;\n\t\tindex = 0;\n\t} else if (PySlice_Check(op)) {\n\t\tintp stop;\n\t\tif (slice_GetIndices((PySliceObject *)op, max,\n\t\t\t\t &index, &stop, step_size, n_steps) < 0) {\n\t\t\tif (!PyErr_Occurred()) {\n\t\t\t\tPyErr_SetString(PyExc_IndexError, \n\t\t\t\t\t\t\"invalid slice\");\n\t\t\t}\n\t\t\tgoto fail;\n\t\t}\n\t\tif (*n_steps <= 0) {\n\t\t\t*n_steps = 0;\n\t\t\t*step_size = 1;\n\t\t\tindex = 0;\n\t\t}\n\t} else {\n\t\tindex = PyArray_PyIntAsIntp(op);\n\t\tif (error_converting(index)) {\n\t\t\tPyErr_SetString(PyExc_IndexError,\n\t\t\t\t\t\"each subindex must be either a \"\\\n\t\t\t\t\t\"slice, an integer, Ellipsis, or \"\\\n\t\t\t\t\t\"newaxis\");\n\t\t\tgoto fail;\n\t\t}\n\t\t*n_steps = SingleIndex;\n\t\t*step_size = 0;\n\t\tif (index < 0) index += max;\n\t\tif (index >= max || index < 0) {\n\t\t\tPyErr_SetString(PyExc_IndexError, \"invalid index\");\n\t\t\tgoto fail;\n\t\t}\n\t}\n\treturn index;\n fail:\n\treturn -1;\n}\n\n\nstatic int \nparse_index(PyArrayObject *self, PyObject *op, \n intp *dimensions, intp *strides, intp *offset_ptr)\n{\n int i, j, n;\n int nd_old, nd_new, n_add, n_pseudo;\n\tintp n_steps, start, offset, step_size;\n PyObject *op1=NULL;\n int is_slice;\n\n\n if (PySlice_Check(op) || op == Py_Ellipsis || op == Py_None) {\n n = 1;\n op1 = op;\n Py_INCREF(op);\t\n /* this relies on the fact that n==1 for loop below */\n is_slice = 1;\n }\n else {\n if (!PySequence_Check(op)) {\n PyErr_SetString(PyExc_IndexError, \n \"index must be either an int \"\\\n \"or a sequence\");\n return -1;\n }\n n = PySequence_Length(op);\n is_slice = 0;\n }\n\t\n nd_old = nd_new = 0;\n\t\n offset = 0;\n for(i=0; ind ? \\\n self->dimensions[nd_old] : 0);\n Py_DECREF(op1);\n if (start == -1) break;\n\t\t\n if (n_steps == PseudoIndex) {\n dimensions[nd_new] = 1; strides[nd_new] = 0; nd_new++;\n } else {\n if (n_steps == RubberIndex) {\n for(j=i+1, n_pseudo=0; jnd-(n-i-n_pseudo-1+nd_old);\n if (n_add < 0) {\n PyErr_SetString(PyExc_IndexError, \n \"too many indices\");\n return -1;\n }\n for(j=0; jdimensions[nd_old];\n strides[nd_new] = \\\n self->strides[nd_old];\n nd_new++; nd_old++;\n }\n } else {\n if (nd_old >= self->nd) {\n PyErr_SetString(PyExc_IndexError, \n \"too many indices\");\n return -1;\n }\n offset += self->strides[nd_old]*start;\n nd_old++;\n if (n_steps != SingleIndex) {\n dimensions[nd_new] = n_steps;\n strides[nd_new] = step_size * \\\n self->strides[nd_old-1];\n nd_new++;\n }\n }\n }\n }\n if (i < n) return -1;\n n_add = self->nd-nd_old;\n for(j=0; jdimensions[nd_old];\n strides[nd_new] = self->strides[nd_old];\n nd_new++; nd_old++;\n }\t \n *offset_ptr = offset;\n return nd_new;\n}\n\nstatic void\n_swap_axes(PyArrayMapIterObject *mit, PyArrayObject **ret)\n{\n\tPyObject *new;\n\tint n1, n2, n3, val;\n\tint i;\n\tPyArray_Dims permute;\n\tintp d[MAX_DIMS];\n\n\tpermute.ptr = d;\n\tpermute.len = mit->nd;\n\n\t/* tuple for transpose is \n\t (n1,..,n1+n2-1,0,..,n1-1,n1+n2,...,n3-1)\n\t n1 is the number of dimensions of \n\t the broadcasted index array \n\t n2 is the number of dimensions skipped at the\n\t start\n\t n3 is the number of dimensions of the \n\t result \n\t*/\n\tn1 = mit->iters[0]->nd_m1 + 1;\n\tn2 = mit->iteraxes[0];\n\tn3 = mit->nd;\n\tval = n1;\n\ti = 0;\n\twhile(val < n1+n2) \n\t\tpermute.ptr[i++] = val++;\n\tval = 0;\n\twhile(val < n1)\n\t\tpermute.ptr[i++] = val++;\n\tval = n1+n2;\n\twhile(val < n3)\n\t\tpermute.ptr[i++] = val++;\n\n\tnew = PyArray_Transpose(*ret, &permute);\n\tPy_DECREF(*ret);\n\t*ret = (PyArrayObject *)new;\n}\n\n/* Prototypes for Mapping calls --- not part of the C-API\n because only useful as part of a getitem call. \n*/\n\nstatic void PyArray_MapIterReset(PyArrayMapIterObject *);\nstatic void PyArray_MapIterNext(PyArrayMapIterObject *);\nstatic void PyArray_MapIterBind(PyArrayMapIterObject *, PyArrayObject *);\nstatic PyObject* PyArray_MapIterNew(PyObject *, int, int);\n\nstatic PyObject *\nPyArray_GetMap(PyArrayMapIterObject *mit)\n{\n\n\tPyArrayObject *ret, *temp;\n\tPyArrayIterObject *it;\n\tint index;\n\tint swap;\n PyArray_CopySwapFunc *copyswap;\n\n\t/* Unbound map iterator --- Bind should have been called */\n\tif (mit->ait == NULL) return NULL;\n\n\t/* This relies on the map iterator object telling us the shape\n\t of the new array in nd and dimensions.\n\t*/\n\ttemp = mit->ait->ao;\n\tPy_INCREF(temp->descr);\n\tret = (PyArrayObject *)\\\n\t\tPyArray_NewFromDescr(temp->ob_type, \n\t\t\t\t temp->descr,\n\t\t\t\t mit->nd, mit->dimensions, \n\t\t\t\t NULL, NULL, \n\t\t\t\t PyArray_ISFORTRAN(temp),\n\t\t\t\t (PyObject *)temp);\n\tif (ret == NULL) return NULL;\n\n\t/* Now just iterate through the new array filling it in\n\t with the next object from the original array as\n\t defined by the mapping iterator */\n\n\tif ((it = (PyArrayIterObject *)PyArray_IterNew((PyObject *)ret)) \n\t == NULL) {\n\t\tPy_DECREF(ret);\n\t\treturn NULL;\n\t}\n\tindex = it->size;\n\tswap = (PyArray_ISNOTSWAPPED(temp) != PyArray_ISNOTSWAPPED(ret));\n copyswap = ret->descr->f->copyswap;\n\tPyArray_MapIterReset(mit);\n\twhile (index--) {\n copyswap(it->dataptr, mit->dataptr, swap, ret->descr->elsize);\n\t\tPyArray_MapIterNext(mit);\n\t\tPyArray_ITER_NEXT(it);\n\t}\n\tPy_DECREF(it);\n\t\n\t/* check for consecutive axes */\n\tif ((mit->subspace != NULL) && (mit->consec)) {\n\t\tif (mit->iteraxes[0] > 0) { /* then we need to swap */\n\t\t\t_swap_axes(mit, &ret);\n\t\t}\n\t}\n\treturn (PyObject *)ret;\n}\n\nstatic int\nPyArray_SetMap(PyArrayMapIterObject *mit, PyObject *op)\n{\n\tPyObject *arr=NULL;\n\tPyArrayIterObject *it;\n\tint index;\n\tint swap;\n PyArray_CopySwapFunc *copyswap;\n\tPyArray_Descr *descr;\n\n\t/* Unbound Map Iterator */\n\tif (mit->ait == NULL) return -1;\n\n\tdescr = mit->ait->ao->descr;\n\tPy_INCREF(descr);\n\tarr = PyArray_FromAny(op, descr, 0, 0, FORCECAST, NULL);\n\tif (arr == NULL) return -1;\n\n\tif ((mit->subspace != NULL) && (mit->consec)) {\n\t\tif (mit->iteraxes[0] > 0) { /* then we need to swap */\n\t\t\t_swap_axes(mit, (PyArrayObject **)&arr);\n\t\t}\n\t}\n\t\n\tif ((it = (PyArrayIterObject *)PyArray_IterNew(arr))==NULL) {\n\t\tPy_DECREF(arr);\n\t\treturn -1;\n\t}\n\n\tindex = mit->size;\n\tswap = (PyArray_ISNOTSWAPPED(mit->ait->ao) != \\\n\t\t(PyArray_ISNOTSWAPPED(arr)));\n\n copyswap = PyArray_DESCR(arr)->f->copyswap;\n\tPyArray_MapIterReset(mit);\n /* Need to decref OBJECT arrays */\n if (PyTypeNum_ISOBJECT(descr->type_num)) {\n while (index--) {\n Py_XDECREF(*((PyObject **)mit->dataptr));\n Py_INCREF(*((PyObject **)it->dataptr));\n memmove(mit->dataptr, it->dataptr, sizeof(PyObject *));\n PyArray_MapIterNext(mit);\n PyArray_ITER_NEXT(it);\n if (it->index == it->size)\n PyArray_ITER_RESET(it);\n }\n\t\tPy_DECREF(arr);\n\t\tPy_DECREF(it);\n return 0;\n }\n\twhile(index--) {\n\t\tmemmove(mit->dataptr, it->dataptr, PyArray_ITEMSIZE(arr));\n copyswap(mit->dataptr, NULL, swap, PyArray_ITEMSIZE(arr));\n\t\tPyArray_MapIterNext(mit);\n\t\tPyArray_ITER_NEXT(it);\n\t\tif (it->index == it->size)\n\t\t\tPyArray_ITER_RESET(it);\n\t}\t\t\n\tPy_DECREF(arr);\n\tPy_DECREF(it);\n\treturn 0;\n}\n\nint\ncount_new_axes_0d(PyObject *tuple)\n{\n\tint i, argument_count;\n\tint ellipsis_count = 0;\n\tint newaxis_count = 0;\n\t\n\targument_count = PyTuple_GET_SIZE(tuple);\n\n\tfor (i = 0; i < argument_count; ++i) {\n\t\tPyObject *arg = PyTuple_GET_ITEM(tuple, i);\n\t\tif (arg == Py_Ellipsis && !ellipsis_count) ellipsis_count++;\n\t\telse if (arg == Py_None) newaxis_count++;\n\t\telse break;\n\t}\n\tif (i < argument_count) {\n\t\tPyErr_SetString(PyExc_IndexError,\n\t\t\t\t\"0-d arrays can only use a single ()\"\n\t\t\t\t\" or a list of newaxes (and a single ...)\"\n\t\t\t\t\" as an index\");\n\t\treturn -1;\n\t}\n\tif (newaxis_count > MAX_DIMS) {\n\t\tPyErr_SetString(PyExc_IndexError,\n\t\t\t\t\"too many dimensions\");\n\t\treturn -1;\n\t}\n\treturn newaxis_count;\n}\n\nstatic PyObject *\nadd_new_axes_0d(PyArrayObject *arr, int newaxis_count)\n{\n\tPyArrayObject *other;\n\tintp dimensions[MAX_DIMS]; \n\tint i;\n\tfor (i = 0; i < newaxis_count; ++i) {\n\t\tdimensions[i] = 1;\n\t}\n\tPy_INCREF(arr->descr);\n\tif ((other = (PyArrayObject *)\n\t PyArray_NewFromDescr(arr->ob_type, arr->descr,\n\t\t\t\t newaxis_count, dimensions,\n\t\t\t\t NULL, arr->data,\n\t\t\t\t arr->flags,\n\t\t\t\t (PyObject *)arr)) == NULL) \n\t\treturn NULL;\n\tother->base = (PyObject *)arr;\n\tPy_INCREF(arr);\n\treturn (PyObject *)other;\n}\n\n\n/* This checks the args for any fancy indexing objects */\n\n#define SOBJ_NOTFANCY 0 \n#define SOBJ_ISFANCY 1\n#define SOBJ_BADARRAY 2\n#define SOBJ_TOOMANY 3\n#define SOBJ_LISTTUP 4\n\nstatic int\nfancy_indexing_check(PyObject *args)\n{\n\tint i, n;\n\tPyObject *obj;\n\tint retval = SOBJ_NOTFANCY;\n\n\tif (PyTuple_Check(args)) {\n\t\tn = PyTuple_GET_SIZE(args);\n\t\tif (n >= MAX_DIMS) return SOBJ_TOOMANY;\n\t\tfor (i=0; i=MAX_DIMS) return SOBJ_ISFANCY;\n\t\tfor (i=0; i SOBJ_ISFANCY) return retval;\n\t\t}\n\t}\n\n\treturn retval;\n}\n\n/* Called when treating array object like a mapping -- called first from \n Python when using a[object] unless object is a standard slice object\n (not an extended one). \n\n*/\n\n/* There are two situations: \n\n 1 - the subscript is a standard view and a reference to the \n array can be returned\n\n 2 - the subscript uses Boolean masks or integer indexing and\n therefore a new array is created and returned. \n\n*/\n\n/* Always returns arrays */\n\nstatic PyObject *iter_subscript(PyArrayIterObject *, PyObject *); \n\n\nstatic PyObject *\narray_subscript(PyArrayObject *self, PyObject *op) \n{\n intp dimensions[MAX_DIMS], strides[MAX_DIMS];\n\tintp offset;\n int nd, oned, fancy;\n\tintp i;\n PyArrayObject *other;\n\tPyArrayMapIterObject *mit;\n\n\tif (PyString_Check(op) || PyUnicode_Check(op)) {\n\t\tif (self->descr->fields) {\n\t\t\tPyObject *obj;\n\t\t\tobj = PyDict_GetItem(self->descr->fields, op);\n\t\t\tif (obj != NULL) {\n\t\t\t\tPyArray_Descr *descr;\n\t\t\t\tint offset;\n\t\t\t\tPyObject *title;\n\t\t\t\t\n\t\t\t\tif (PyArg_ParseTuple(obj, \"Oi|O\",\n\t\t\t\t\t\t &descr, &offset, &title)) {\n\t\t\t\t\tPy_INCREF(descr);\n\t\t\t\t\treturn PyArray_GetField(self, descr, \n\t\t\t\t\t\t\t\toffset);\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t\t\n\t\tPyErr_Format(PyExc_ValueError, \n\t\t\t \"field named %s not found.\",\n\t\t\t PyString_AsString(op));\n\t\treturn NULL;\n\t}\n if (self->nd == 0) {\n\t\tif (op == Py_Ellipsis)\n\t\t\treturn PyArray_ToScalar(self->data, self);\n\t\tif (op == Py_None)\n\t\t\treturn add_new_axes_0d(self, 1);\n\t\tif (PyTuple_Check(op)) {\n\t\t\tif (0 == PyTuple_GET_SIZE(op))\n\t\t\t\treturn PyArray_ToScalar(self->data, self);\n\t\t\tif ((nd = count_new_axes_0d(op)) == -1)\n\t\t\t\treturn NULL;\n\t\t\treturn add_new_axes_0d(self, nd);\n\t\t}\n PyErr_SetString(PyExc_IndexError, \n \"0-d arrays can't be indexed.\");\n return NULL;\n }\n if (PyArray_IsScalar(op, Integer) || PyInt_Check(op) || \\\n PyLong_Check(op)) {\n intp value;\n value = PyArray_PyIntAsIntp(op);\n\t\tif (PyErr_Occurred())\n\t\t\tPyErr_Clear();\n else if (value >= 0) {\n\t\t\treturn array_big_item(self, value);\n }\n else /* (value < 0) */ {\n\t\t\tvalue += self->dimensions[0];\n\t\t\treturn array_big_item(self, value);\n\t\t}\n }\n\n\tfancy = fancy_indexing_check(op);\n\n\tif (fancy != SOBJ_NOTFANCY) { \n\t\toned = ((self->nd == 1) && !(PyTuple_Check(op) &&\t\\\n\t\t\t\t\t PyTuple_GET_SIZE(op) > 1));\n\n\t\t/* wrap arguments into a mapiter object */\n\t\tmit = (PyArrayMapIterObject *)\\\n\t\t\tPyArray_MapIterNew(op, oned, fancy);\n\t\tif (mit == NULL) return NULL;\n\t\tif (oned) {\n\t\t\tPyArrayIterObject *it;\n\t\t\tPyObject *rval;\n\t\t\tit = (PyArrayIterObject *)PyArray_IterNew((PyObject *)self);\n\t\t\tif (it == NULL) {Py_DECREF(mit); return NULL;}\n\t\t\trval = iter_subscript(it, mit->indexobj);\n\t\t\tPy_DECREF(it);\n\t\t\tPy_DECREF(mit);\n\t\t\treturn rval;\n\t\t}\n PyArray_MapIterBind(mit, self);\n other = (PyArrayObject *)PyArray_GetMap(mit);\n Py_DECREF(mit);\n return (PyObject *)other;\n }\n\n\ti = PyArray_PyIntAsIntp(op);\n\tif (!error_converting(i)) {\n\t\tif (i < 0 && self->nd > 0) i = i+self->dimensions[0];\n\t\treturn array_big_item(self, i);\n\t}\n\tPyErr_Clear();\n\n\t/* Standard (view-based) Indexing */\n if ((nd = parse_index(self, op, dimensions, strides, &offset)) \n == -1) \n return NULL;\n\n\t/* This will only work if new array will be a view */\n\tPy_INCREF(self->descr);\n\tif ((other = (PyArrayObject *)\t\t\t\t\t\\\n\t PyArray_NewFromDescr(self->ob_type, self->descr,\n\t\t\t\t nd, dimensions,\n\t\t\t\t strides, self->data+offset, \n\t\t\t\t self->flags,\n\t\t\t\t (PyObject *)self)) == NULL) \n\t\treturn NULL;\n\n\n\tother->base = (PyObject *)self;\n\tPy_INCREF(self);\n\t\n\tPyArray_UpdateFlags(other, UPDATE_ALL_FLAGS);\n\t\n\treturn (PyObject *)other;\n}\n\n\n/* Another assignment hacked by using CopyObject. */\n\n/* This only works if subscript returns a standard view. */\n\n/* Again there are two cases. In the first case, PyArray_CopyObject\n can be used. In the second case, a new indexing function has to be \n used.\n*/\n\nstatic int iter_ass_subscript(PyArrayIterObject *, PyObject *, PyObject *); \n\nstatic int \narray_ass_sub(PyArrayObject *self, PyObject *index, PyObject *op) \n{\n int ret, oned, fancy;\n\tintp i;\n PyArrayObject *tmp;\n\tPyArrayMapIterObject *mit;\n\t\n if (op == NULL) {\n PyErr_SetString(PyExc_ValueError, \n \"cannot delete array elements\");\n return -1;\n }\n\tif (!PyArray_ISWRITEABLE(self)) {\n\t\tPyErr_SetString(PyExc_RuntimeError,\n\t\t\t\t\"array is not writeable\");\n\t\treturn -1;\n\t}\n\t\n if (PyArray_IsScalar(index, Integer) || PyInt_Check(index) ||\t\\\n PyLong_Check(index)) {\n intp value;\n value = PyArray_PyIntAsIntp(index);\n if (PyErr_Occurred())\n PyErr_Clear();\n\t\telse\n\t\t\treturn array_ass_big_item(self, value, op);\n }\n\n\tif (PyString_Check(index) || PyUnicode_Check(index)) {\n\t\tif (self->descr->fields) {\n\t\t\tPyObject *obj;\n\t\t\tobj = PyDict_GetItem(self->descr->fields, index);\n\t\t\tif (obj != NULL) {\n\t\t\t\tPyArray_Descr *descr;\n\t\t\t\tint offset;\n\t\t\t\tPyObject *title;\n\t\t\t\t\n\t\t\t\tif (PyArg_ParseTuple(obj, \"Oi|O\",\n\t\t\t\t\t\t &descr, &offset, &title)) {\n\t\t\t\t\tPy_INCREF(descr);\n\t\t\t\t\treturn PyArray_SetField(self, descr, \n\t\t\t\t\t\t\t\toffset, op);\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t\t\n\t\tPyErr_Format(PyExc_ValueError, \n\t\t\t \"field named %s not found.\",\n\t\t\t PyString_AsString(index));\n\t\treturn -1;\n\t}\n\n if (self->nd == 0) {\n\t\tif (index == Py_Ellipsis || index == Py_None ||\t\t\\\n\t\t (PyTuple_Check(index) && (0 == PyTuple_GET_SIZE(index) || \\\n\t\t\t\t\t count_new_axes_0d(index) > 0)))\n\t\t\treturn self->descr->f->setitem(op, self->data, self);\n PyErr_SetString(PyExc_IndexError, \n \"0-d arrays can't be indexed.\");\n return -1;\n }\n\n\tfancy = fancy_indexing_check(index);\n\n\tif (fancy != SOBJ_NOTFANCY) { \n\t\toned = ((self->nd == 1) && !(PyTuple_Check(index) && \\\n\t\t\t\t\t PyTuple_GET_SIZE(index) > 1));\n\n\t\tmit = (PyArrayMapIterObject *)\t\t\t\\\n\t\t\tPyArray_MapIterNew(index, oned, fancy);\n\t\tif (mit == NULL) return -1;\n\t\tif (oned) {\n\t\t\tPyArrayIterObject *it;\n\t\t\tint rval;\n\t\t\tit = (PyArrayIterObject *)PyArray_IterNew((PyObject *)self);\n\t\t\tif (it == NULL) {Py_DECREF(mit); return -1;}\n\t\t\trval = iter_ass_subscript(it, mit->indexobj, op);\n\t\t\tPy_DECREF(it);\n\t\t\tPy_DECREF(mit);\n\t\t\treturn rval;\n\t\t}\n PyArray_MapIterBind(mit, self);\n ret = PyArray_SetMap(mit, op);\n Py_DECREF(mit);\n return ret;\n }\n\t\n\ti = PyArray_PyIntAsIntp(index);\n\tif (!error_converting(i)) {\n\t\treturn array_ass_big_item(self, i, op);\n\t}\n\tPyErr_Clear();\n\t\n\t/* Rest of standard (view-based) indexing */\n\n if ((tmp = (PyArrayObject *)array_subscript(self, index)) == NULL)\n return -1; \n\tif (PyArray_ISOBJECT(self) && (tmp->nd == 0)) {\n\t\tret = tmp->descr->f->setitem(op, tmp->data, tmp);\n\t}\n\telse {\n\t\tret = PyArray_CopyObject(tmp, op);\n\t}\n\tPy_DECREF(tmp);\n return ret;\n}\n\n\n/* There are places that require that array_subscript return a PyArrayObject\n and not possibly a scalar. Thus, this is the function exposed to \n Python so that 0-dim arrays are passed as scalars\n*/\n\nstatic PyObject *\narray_subscript_nice(PyArrayObject *self, PyObject *op) \n{\n\treturn PyArray_Return((PyArrayObject *)array_subscript(self, op));\n}\n\n\nstatic PyMappingMethods array_as_mapping = {\n (inquiry)array_length,\t\t /*mp_length*/\n (binaryfunc)array_subscript_nice,\t/*mp_subscript*/\n (objobjargproc)array_ass_sub,\t /*mp_ass_subscript*/\n};\n\n/****************** End of Mapping Protocol ******************************/\n\n\n/*************************************************************************\n **************** Implement Buffer Protocol ****************************\n *************************************************************************/\n\n/* removed multiple segment interface */\n\nstatic int \narray_getsegcount(PyArrayObject *self, int *lenp) \n{\n if (lenp)\n *lenp = PyArray_NBYTES(self);\n\n if (PyArray_ISONESEGMENT(self)) {\n return 1;\n }\n\n if (lenp)\n *lenp = 0;\n return 0;\n}\n\nstatic int \narray_getreadbuf(PyArrayObject *self, int segment, void **ptrptr) \n{\n if (segment != 0) {\n PyErr_SetString(PyExc_ValueError, \n \"accessing non-existing array segment\");\n return -1;\n }\n \n if (PyArray_ISONESEGMENT(self)) {\n *ptrptr = self->data;\n return PyArray_NBYTES(self);\n }\n PyErr_SetString(PyExc_ValueError, \"array is not a single segment\");\n *ptrptr = NULL;\n return -1;\n}\n\n\nstatic int \narray_getwritebuf(PyArrayObject *self, int segment, void **ptrptr) \n{\n if (PyArray_CHKFLAGS(self, WRITEABLE)) \n return array_getreadbuf(self, segment, (void **) ptrptr);\n else {\n PyErr_SetString(PyExc_ValueError, \"array cannot be \"\\\n \"accessed as a writeable buffer\");\n return -1;\n }\n}\n\nstatic int \narray_getcharbuf(PyArrayObject *self, int segment, const char **ptrptr) \n{\n if (self->descr->type_num == PyArray_STRING || \\\n\t self->descr->type_num == PyArray_UNICODE)\n return array_getreadbuf(self, segment, (void **) ptrptr);\n else {\n PyErr_SetString(PyExc_TypeError, \n \"non-character array cannot be interpreted \"\\\n \"as character buffer\");\n return -1;\n }\n}\n\nstatic PyBufferProcs array_as_buffer = {\n (getreadbufferproc)array_getreadbuf, /*bf_getreadbuffer*/\n (getwritebufferproc)array_getwritebuf, /*bf_getwritebuffer*/\n (getsegcountproc)array_getsegcount,\t /*bf_getsegcount*/\n (getcharbufferproc)array_getcharbuf, /*bf_getcharbuffer*/\n};\n\n/****************** End of Buffer Protocol *******************************/\n\n\n/*************************************************************************\n **************** Implement Number Protocol ****************************\n *************************************************************************/\n\n\ntypedef struct {\n PyObject *add,\n *subtract,\n *multiply,\n *divide,\n *remainder,\n *power,\n\t\t*sqrt,\n *negative,\n *absolute,\n *invert,\n *left_shift,\n *right_shift,\n *bitwise_and,\n *bitwise_xor,\n *bitwise_or,\n *less,\n *less_equal,\n *equal,\n *not_equal,\n *greater,\n *greater_equal,\n *floor_divide,\n *true_divide,\n\t\t*logical_or,\n\t\t*logical_and,\n\t\t*floor,\n\t\t*ceil,\n\t\t*maximum,\n\t\t*minimum;\t\n\t\n} NumericOps;\n\nstatic NumericOps n_ops = {NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, \n NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL,\n NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL,\n NULL, NULL, NULL, NULL, NULL};\n\n/* Dictionary can contain any of the numeric operations, by name. \n Those not present will not be changed\n */\n\n#define SET(op) temp=PyDict_GetItemString(dict, #op);\t\\\n\tif (temp != NULL) {\t\t\t\t\\\n\t\tif (!(PyCallable_Check(temp))) return -1; \\\n Py_XDECREF(n_ops.op); \\\n\t\tn_ops.op = temp; \\\n\t}\n\n \n/*OBJECT_API\n Set internal structure with number functions that all arrays will use\n*/\nint \nPyArray_SetNumericOps(PyObject *dict) \n{\n PyObject *temp = NULL;\n SET(add);\n SET(subtract);\n SET(multiply);\n SET(divide);\n SET(remainder);\n SET(power);\n\tSET(sqrt);\n SET(negative);\n SET(absolute);\n SET(invert);\n SET(left_shift);\n SET(right_shift);\n SET(bitwise_and);\n SET(bitwise_or);\n SET(bitwise_xor);\n SET(less);\t \n SET(less_equal);\n SET(equal);\n SET(not_equal);\n SET(greater);\n SET(greater_equal);\n SET(floor_divide);\t\n SET(true_divide);\t\n\tSET(logical_or);\n\tSET(logical_and);\n\tSET(floor);\n\tSET(ceil);\n\tSET(maximum);\n\tSET(minimum);\n return 0;\n}\n\n#define GET(op) if (n_ops.op &&\t\t\t\t\t\t\\\n\t\t (PyDict_SetItemString(dict, #op, n_ops.op)==-1))\t\\\n\t\tgoto fail;\n\n/*OBJECT_API\n Get dictionary showing number functions that all arrays will use\n*/\nstatic PyObject *\nPyArray_GetNumericOps(void) \n{\n\tPyObject *dict;\n\tif ((dict = PyDict_New())==NULL) \n\t\treturn NULL;\t\n\tGET(add);\n GET(subtract);\n GET(multiply);\n GET(divide);\n GET(remainder);\n GET(power);\n\tGET(sqrt);\n GET(negative);\n GET(absolute);\n GET(invert);\n GET(left_shift);\n GET(right_shift);\n GET(bitwise_and);\n GET(bitwise_or);\n GET(bitwise_xor);\n GET(less);\t \n GET(less_equal);\n GET(equal);\n GET(not_equal);\n GET(greater);\n GET(greater_equal);\n GET(floor_divide); \n GET(true_divide); \n\tGET(logical_or);\n\tGET(logical_and);\n\tGET(floor);\n\tGET(ceil);\n\tGET(maximum);\n\tGET(minimum);\n\treturn dict;\t\n\n fail:\n\tPy_DECREF(dict);\n\treturn NULL;\t\t\n}\n\nstatic PyObject *\nPyArray_GenericReduceFunction(PyArrayObject *m1, PyObject *op, int axis,\n\t\t\t int rtype)\n{\n\tPyObject *args, *ret=NULL, *meth;\n\tif (op == NULL) {\n\t\tPy_INCREF(Py_NotImplemented);\n\t\treturn Py_NotImplemented;\n\t}\n\tif (rtype == PyArray_NOTYPE) \n\t\targs = Py_BuildValue(\"(Oi)\", m1, axis);\n\telse {\n\t\tPyArray_Descr *descr;\n\t\tdescr = PyArray_DescrFromType(rtype);\n\t\targs = Py_BuildValue(\"(Oic)\", m1, axis, descr->type);\n\t\tPy_DECREF(descr);\n\t}\n\tmeth = PyObject_GetAttrString(op, \"reduce\");\n\tif (meth && PyCallable_Check(meth)) {\n\t\tret = PyObject_Call(meth, args, NULL);\n\t}\n\tPy_DECREF(args);\n\tPy_DECREF(meth);\n\treturn ret;\n}\t\n\n\nstatic PyObject *\nPyArray_GenericAccumulateFunction(PyArrayObject *m1, PyObject *op, int axis,\n\t\t\t\t int rtype)\n{\n\tPyObject *args, *ret=NULL, *meth;\n\tif (op == NULL) {\n\t\tPy_INCREF(Py_NotImplemented);\n\t\treturn Py_NotImplemented;\n\t}\n\tif (rtype == PyArray_NOTYPE) \n\t\targs = Py_BuildValue(\"(Oi)\", m1, axis);\n\telse {\n\t\tPyArray_Descr *descr;\n\t\tdescr = PyArray_DescrFromType(rtype);\n\t\targs = Py_BuildValue(\"(Oic)\", m1, axis, descr->type);\n\t\tPy_DECREF(descr);\n\t}\n\tmeth = PyObject_GetAttrString(op, \"accumulate\");\n\tif (meth && PyCallable_Check(meth)) {\n\t\tret = PyObject_Call(meth, args, NULL);\n\t}\n\tPy_DECREF(args);\n\tPy_DECREF(meth);\n\treturn ret;\n}\t\n\n\nstatic PyObject *\nPyArray_GenericBinaryFunction(PyArrayObject *m1, PyObject *m2, PyObject *op) \n{\n if (op == NULL) {\n Py_INCREF(Py_NotImplemented);\n return Py_NotImplemented; \n }\n return PyObject_CallFunction(op, \"OO\", m1, m2);\n}\n\nstatic PyObject *\nPyArray_GenericUnaryFunction(PyArrayObject *m1, PyObject *op) \n{\n if (op == NULL) {\n Py_INCREF(Py_NotImplemented);\n return Py_NotImplemented; \n }\n return PyObject_CallFunction(op, \"(O)\", m1);\n}\n\nstatic PyObject *\nPyArray_GenericInplaceBinaryFunction(PyArrayObject *m1, \n\t\t\t\t PyObject *m2, PyObject *op) \n{\n if (op == NULL) {\n Py_INCREF(Py_NotImplemented);\n return Py_NotImplemented; \n }\n return PyObject_CallFunction(op, \"OOO\", m1, m2, m1);\n}\n\nstatic PyObject *\narray_add(PyArrayObject *m1, PyObject *m2) \n{ \n return PyArray_GenericBinaryFunction(m1, m2, n_ops.add); \n}\n\nstatic PyObject *\narray_subtract(PyArrayObject *m1, PyObject *m2) \n{\n\treturn PyArray_GenericBinaryFunction(m1, m2, n_ops.subtract);\n}\n\nstatic PyObject *\narray_multiply(PyArrayObject *m1, PyObject *m2) \n{\n return PyArray_GenericBinaryFunction(m1, m2, n_ops.multiply);\n}\n\nstatic PyObject *\narray_divide(PyArrayObject *m1, PyObject *m2) \n{\n return PyArray_GenericBinaryFunction(m1, m2, n_ops.divide);\n}\n\nstatic PyObject *\narray_remainder(PyArrayObject *m1, PyObject *m2) \n{\n return PyArray_GenericBinaryFunction(m1, m2, n_ops.remainder);\n}\n\nstatic PyObject *\narray_power(PyArrayObject *m1, PyObject *m2) \n{\n return PyArray_GenericBinaryFunction(m1, m2, n_ops.power);\n}\n\nstatic PyObject *\narray_negative(PyArrayObject *m1) \n{ \n return PyArray_GenericUnaryFunction(m1, n_ops.negative);\n}\n\nstatic PyObject *\narray_absolute(PyArrayObject *m1) \n{ \n return PyArray_GenericUnaryFunction(m1, n_ops.absolute);\n}\n\nstatic PyObject *\narray_invert(PyArrayObject *m1) \n{ \n return PyArray_GenericUnaryFunction(m1, n_ops.invert);\n}\n\nstatic PyObject *\narray_left_shift(PyArrayObject *m1, PyObject *m2) \n{\n return PyArray_GenericBinaryFunction(m1, m2, n_ops.left_shift);\n}\n\nstatic PyObject *\narray_right_shift(PyArrayObject *m1, PyObject *m2) \n{\n return PyArray_GenericBinaryFunction(m1, m2, n_ops.right_shift);\n}\n\nstatic PyObject *\narray_bitwise_and(PyArrayObject *m1, PyObject *m2) \n{\n return PyArray_GenericBinaryFunction(m1, m2, n_ops.bitwise_and);\n}\n\nstatic PyObject *\narray_bitwise_or(PyArrayObject *m1, PyObject *m2) \n{\n return PyArray_GenericBinaryFunction(m1, m2, n_ops.bitwise_or);\n}\n\nstatic PyObject *\narray_bitwise_xor(PyArrayObject *m1, PyObject *m2) \n{\n return PyArray_GenericBinaryFunction(m1, m2, n_ops.bitwise_xor);\n}\n\nstatic PyObject *\narray_inplace_add(PyArrayObject *m1, PyObject *m2) \n{\n return PyArray_GenericInplaceBinaryFunction(m1, m2, n_ops.add);\n}\n\nstatic PyObject *\narray_inplace_subtract(PyArrayObject *m1, PyObject *m2) \n{\n return PyArray_GenericInplaceBinaryFunction(m1, m2, n_ops.subtract);\n}\n\nstatic PyObject *\narray_inplace_multiply(PyArrayObject *m1, PyObject *m2) \n{\n return PyArray_GenericInplaceBinaryFunction(m1, m2, n_ops.multiply);\n}\n\nstatic PyObject *\narray_inplace_divide(PyArrayObject *m1, PyObject *m2) \n{\n return PyArray_GenericInplaceBinaryFunction(m1, m2, n_ops.divide);\n}\n\nstatic PyObject *\narray_inplace_remainder(PyArrayObject *m1, PyObject *m2) \n{\n return PyArray_GenericInplaceBinaryFunction(m1, m2, n_ops.remainder);\n}\n\nstatic PyObject *\narray_inplace_power(PyArrayObject *m1, PyObject *m2) \n{\n return PyArray_GenericInplaceBinaryFunction(m1, m2, n_ops.power);\n}\n\nstatic PyObject *\narray_inplace_left_shift(PyArrayObject *m1, PyObject *m2) \n{\n return PyArray_GenericInplaceBinaryFunction(m1, m2, n_ops.left_shift);\n}\n\nstatic PyObject *\narray_inplace_right_shift(PyArrayObject *m1, PyObject *m2) \n{\n return PyArray_GenericInplaceBinaryFunction(m1, m2, n_ops.right_shift);\n}\n\nstatic PyObject *\narray_inplace_bitwise_and(PyArrayObject *m1, PyObject *m2) \n{\n return PyArray_GenericInplaceBinaryFunction(m1, m2, n_ops.bitwise_and);\n}\n\nstatic PyObject *\narray_inplace_bitwise_or(PyArrayObject *m1, PyObject *m2) \n{\n return PyArray_GenericInplaceBinaryFunction(m1, m2, n_ops.bitwise_or);\n}\n\nstatic PyObject *\narray_inplace_bitwise_xor(PyArrayObject *m1, PyObject *m2) \n{\n return PyArray_GenericInplaceBinaryFunction(m1, m2, n_ops.bitwise_xor);\n}\n\nstatic PyObject *\narray_floor_divide(PyArrayObject *m1, PyObject *m2) \n{\n return PyArray_GenericBinaryFunction(m1, m2, n_ops.floor_divide);\n}\n\nstatic PyObject *\narray_true_divide(PyArrayObject *m1, PyObject *m2) \n{\n return PyArray_GenericBinaryFunction(m1, m2, n_ops.true_divide);\n}\n\nstatic PyObject *\narray_inplace_floor_divide(PyArrayObject *m1, PyObject *m2) \n{\n return PyArray_GenericInplaceBinaryFunction(m1, m2, \n\t\t\t\t\t\t n_ops.floor_divide);\n}\n\nstatic PyObject *\narray_inplace_true_divide(PyArrayObject *m1, PyObject *m2) \n{\n return PyArray_GenericInplaceBinaryFunction(m1, m2, \n\t\t\t\t\t\t n_ops.true_divide);\n}\n\n/* Array evaluates as \"TRUE\" if any of the elements are non-zero*/\nstatic int \narray_any_nonzero(PyArrayObject *mp) \n{\n\tintp index;\n\tPyArrayIterObject *it;\n\tBool anyTRUE = FALSE;\n\t\n\tit = (PyArrayIterObject *)PyArray_IterNew((PyObject *)mp);\n\tif (it==NULL) return anyTRUE;\n\tindex = it->size;\n\twhile(index--) {\n\t\tif (mp->descr->f->nonzero(it->dataptr, mp)) {\n\t\t\tanyTRUE = TRUE;\n\t\t\tbreak;\n\t\t}\n\t\tPyArray_ITER_NEXT(it);\n\t}\n\tPy_DECREF(it);\n\treturn anyTRUE;\n}\n\nstatic int\n_array_nonzero(PyArrayObject *mp)\n{\n\tintp n;\n\tn = PyArray_SIZE(mp);\n\tif (n == 1) {\n\t\treturn mp->descr->f->nonzero(mp->data, mp);\n\t}\n\telse if (n == 0) {\n\t\treturn 0;\n\t}\n\telse {\n\t\tPyErr_SetString(PyExc_ValueError, \n\t\t\t\t\"The truth value of an array \" \\\n\t\t\t\t\"with more than one element is ambiguous. \" \\\n\t\t\t\t\"Use a.any() or a.all()\");\n\t\treturn -1;\n\t}\n}\n\n\n\nstatic PyObject *\narray_divmod(PyArrayObject *op1, PyObject *op2) \n{\n PyObject *divp, *modp, *result;\n\n divp = array_floor_divide(op1, op2);\n if (divp == NULL) return NULL;\n modp = array_remainder(op1, op2);\n if (modp == NULL) {\n Py_DECREF(divp);\n return NULL;\n }\n result = Py_BuildValue(\"OO\", divp, modp);\n Py_DECREF(divp);\n Py_DECREF(modp);\n return result;\n}\n\n\nstatic PyObject *\narray_int(PyArrayObject *v) \n{ \n PyObject *pv, *pv2;\n if (PyArray_SIZE(v) != 1) {\n PyErr_SetString(PyExc_TypeError, \"only length-1 arrays can be\"\\\n\t\t\t\t\" converted to Python scalars\");\n return NULL;\n }\n pv = v->descr->f->getitem(v->data, v);\n if (pv == NULL) return NULL;\n if (pv->ob_type->tp_as_number == 0) {\n PyErr_SetString(PyExc_TypeError, \"cannot convert to an int; \"\\\n\t\t\t\t\"scalar object is not a number\");\n Py_DECREF(pv);\n return NULL;\n }\n if (pv->ob_type->tp_as_number->nb_int == 0) {\n PyErr_SetString(PyExc_TypeError, \"don't know how to convert \"\\\n\t\t\t\t\"scalar number to int\");\n Py_DECREF(pv);\n return NULL;\n }\n\n pv2 = pv->ob_type->tp_as_number->nb_int(pv);\n Py_DECREF(pv);\n return pv2;\t \n}\n\nstatic PyObject *\narray_float(PyArrayObject *v) \n{\n PyObject *pv, *pv2;\n if (PyArray_SIZE(v) != 1) {\n PyErr_SetString(PyExc_TypeError, \"only length-1 arrays can \"\\\n\t\t\t\t\"be converted to Python scalars\");\n return NULL;\n }\n pv = v->descr->f->getitem(v->data, v);\n if (pv == NULL) return NULL;\n if (pv->ob_type->tp_as_number == 0) {\n PyErr_SetString(PyExc_TypeError, \"cannot convert to an \"\\\n\t\t\t\t\"int; scalar object is not a number\");\n Py_DECREF(pv);\n return NULL;\n }\n if (pv->ob_type->tp_as_number->nb_float == 0) {\n PyErr_SetString(PyExc_TypeError, \"don't know how to convert \"\\\n\t\t\t\t\"scalar number to float\");\n Py_DECREF(pv);\n return NULL;\n }\n pv2 = pv->ob_type->tp_as_number->nb_float(pv);\n Py_DECREF(pv);\n return pv2;\t \n}\n\nstatic PyObject *\narray_long(PyArrayObject *v) \n{ \n PyObject *pv, *pv2;\n if (PyArray_SIZE(v) != 1) {\n PyErr_SetString(PyExc_TypeError, \"only length-1 arrays can \"\\\n\t\t\t\t\"be converted to Python scalars\");\n return NULL;\n }\n pv = v->descr->f->getitem(v->data, v);\n if (pv->ob_type->tp_as_number == 0) {\n PyErr_SetString(PyExc_TypeError, \"cannot convert to an int; \"\\\n\t\t\t\t\"scalar object is not a number\");\n return NULL;\n }\n if (pv->ob_type->tp_as_number->nb_long == 0) {\n PyErr_SetString(PyExc_TypeError, \"don't know how to convert \"\\\n\t\t\t\t\"scalar number to long\");\n return NULL;\n }\n pv2 = pv->ob_type->tp_as_number->nb_long(pv);\n Py_DECREF(pv);\n return pv2;\t \n}\n\nstatic PyObject *\narray_oct(PyArrayObject *v) \n{\t \n PyObject *pv, *pv2;\n if (PyArray_SIZE(v) != 1) {\n PyErr_SetString(PyExc_TypeError, \"only length-1 arrays can \"\\\n\t\t\t\t\"be converted to Python scalars\");\n return NULL;\n }\n pv = v->descr->f->getitem(v->data, v);\n if (pv->ob_type->tp_as_number == 0) {\n PyErr_SetString(PyExc_TypeError, \"cannot convert to an int; \"\\\n\t\t\t\t\"scalar object is not a number\");\n return NULL;\n }\n if (pv->ob_type->tp_as_number->nb_oct == 0) {\n PyErr_SetString(PyExc_TypeError, \"don't know how to convert \"\\\n\t\t\t\t\"scalar number to oct\");\n return NULL;\n }\n pv2 = pv->ob_type->tp_as_number->nb_oct(pv);\n Py_DECREF(pv);\n return pv2;\t \n}\n\nstatic PyObject *\narray_hex(PyArrayObject *v) \n{ \n PyObject *pv, *pv2;\n if (PyArray_SIZE(v) != 1) {\n PyErr_SetString(PyExc_TypeError, \"only length-1 arrays can \"\\\n\t\t\t\t\"be converted to Python scalars\");\n return NULL;\n }\n pv = v->descr->f->getitem(v->data, v);\n if (pv->ob_type->tp_as_number == 0) {\n PyErr_SetString(PyExc_TypeError, \"cannot convert to an int; \"\\\n\t\t\t\t\"scalar object is not a number\");\n return NULL;\n }\n if (pv->ob_type->tp_as_number->nb_hex == 0) {\n PyErr_SetString(PyExc_TypeError, \"don't know how to convert \"\\\n\t\t\t\t\"scalar number to hex\");\n return NULL;\n }\n pv2 = pv->ob_type->tp_as_number->nb_hex(pv);\n Py_DECREF(pv);\n return pv2;\t \n}\n\nstatic PyObject *\n_array_copy_nice(PyArrayObject *self)\n{\n\treturn PyArray_Return((PyArrayObject *)\t\t\\\n\t\t\t PyArray_Copy(self));\n}\n\nstatic PyNumberMethods array_as_number = {\n (binaryfunc)array_add,\t\t /*nb_add*/\n (binaryfunc)array_subtract,\t\t /*nb_subtract*/\n (binaryfunc)array_multiply,\t\t /*nb_multiply*/\n (binaryfunc)array_divide,\t\t /*nb_divide*/\n (binaryfunc)array_remainder,\t /*nb_remainder*/\n (binaryfunc)array_divmod,\t\t /*nb_divmod*/\n (ternaryfunc)array_power,\t\t /*nb_power*/\n (unaryfunc)array_negative, /*nb_neg*/\t\n (unaryfunc)_array_copy_nice,\t\t /*nb_pos*/ \n (unaryfunc)array_absolute,\t\t /*(unaryfunc)array_abs,*/\n (inquiry)_array_nonzero,\t\t /*nb_nonzero*/\n (unaryfunc)array_invert,\t\t /*nb_invert*/\n (binaryfunc)array_left_shift,\t /*nb_lshift*/\n (binaryfunc)array_right_shift,\t /*nb_rshift*/\n (binaryfunc)array_bitwise_and,\t /*nb_and*/\n (binaryfunc)array_bitwise_xor,\t /*nb_xor*/\n (binaryfunc)array_bitwise_or,\t /*nb_or*/\n 0,\t\t /*nb_coerce*/\n (unaryfunc)array_int,\t\t /*nb_int*/\n (unaryfunc)array_long,\t\t /*nb_long*/\n (unaryfunc)array_float,\t\t /*nb_float*/\n (unaryfunc)array_oct,\t\t /*nb_oct*/\n (unaryfunc)array_hex,\t\t /*nb_hex*/\n\n /*This code adds augmented assignment functionality*/\n /*that was made available in Python 2.0*/\n (binaryfunc)array_inplace_add,\t /*inplace_add*/\n (binaryfunc)array_inplace_subtract,\t /*inplace_subtract*/\n (binaryfunc)array_inplace_multiply,\t /*inplace_multiply*/\n (binaryfunc)array_inplace_divide,\t /*inplace_divide*/\n (binaryfunc)array_inplace_remainder, /*inplace_remainder*/\n (ternaryfunc)array_inplace_power,\t /*inplace_power*/\n (binaryfunc)array_inplace_left_shift, /*inplace_lshift*/\n (binaryfunc)array_inplace_right_shift, /*inplace_rshift*/\n (binaryfunc)array_inplace_bitwise_and, /*inplace_and*/\n (binaryfunc)array_inplace_bitwise_xor, /*inplace_xor*/\n (binaryfunc)array_inplace_bitwise_or, /*inplace_or*/\n\n (binaryfunc)array_floor_divide,\t /*nb_floor_divide*/\n (binaryfunc)array_true_divide,\t /*nb_true_divide*/\n (binaryfunc)array_inplace_floor_divide, /*nb_inplace_floor_divide*/\n (binaryfunc)array_inplace_true_divide, /*nb_inplace_true_divide*/\n\n};\n\n/****************** End of Buffer Protocol *******************************/\n\n\n/*************************************************************************\n **************** Implement Sequence Protocol **************************\n *************************************************************************/\n\n/* Some of this is repeated in the array_as_mapping protocol. But\n we fill it in here so that PySequence_XXXX calls work as expected \n*/\n\n\nstatic PyObject * \narray_slice(PyArrayObject *self, int ilow, int ihigh) \n{\n PyArrayObject *r;\n int l;\n char *data;\n\n if (self->nd == 0) {\n PyErr_SetString(PyExc_ValueError, \"cannot slice a scalar\");\n return NULL;\n }\n \t\n l=self->dimensions[0];\n if (ihigh < 0) ihigh += l;\n if (ilow < 0) ilow += l;\n if (ilow < 0) ilow = 0;\n else if (ilow > l) ilow = l;\n if (ihigh < 0) ihigh = 0;\n else if (ihigh > l) ihigh = l;\n if (ihigh < ilow) ihigh = ilow;\n\n if (ihigh != ilow) {\n data = index2ptr(self, ilow);\n if (data == NULL) return NULL;\n } else {\n data = self->data;\n }\n\n self->dimensions[0] = ihigh-ilow;\n\tPy_INCREF(self->descr);\n r = (PyArrayObject *)\t\t\t\t\t\t\\\n\t\tPyArray_NewFromDescr(self->ob_type, self->descr,\n\t\t\t\t self->nd, self->dimensions, \n\t\t\t\t self->strides, data,\n\t\t\t\t self->flags, (PyObject *)self);\n\n self->dimensions[0] = l;\n r->base = (PyObject *)self;\n Py_INCREF(self);\n\tPyArray_UpdateFlags(r, UPDATE_ALL_FLAGS); \n return (PyObject *)r;\n}\n\n\nstatic int \narray_ass_slice(PyArrayObject *self, int ilow, int ihigh, PyObject *v) {\n int ret;\n PyArrayObject *tmp;\n\t\n if (v == NULL) {\n PyErr_SetString(PyExc_ValueError, \n \"cannot delete array elements\");\n return -1;\n }\n\tif (!PyArray_ISWRITEABLE(self)) {\n\t\tPyErr_SetString(PyExc_RuntimeError,\n\t\t\t\t\"array is not writeable\");\n\t\treturn -1;\n\t}\n if ((tmp = (PyArrayObject *)array_slice(self, ilow, ihigh)) \\\n == NULL) \n return -1; \n ret = PyArray_CopyObject(tmp, v);\n Py_DECREF(tmp);\n\t\n return ret;\n}\n\nstatic int\narray_contains(PyArrayObject *self, PyObject *el)\n{\n /* equivalent to (self == el).any() */\n\n PyObject *res; \n int ret;\n\n res = PyArray_EnsureArray(PyObject_RichCompare((PyObject *)self, el, Py_EQ));\n if (res == NULL) return -1;\n ret = array_any_nonzero((PyArrayObject *)res);\n Py_DECREF(res);\n return ret;\n}\n\n\nstatic PySequenceMethods array_as_sequence = {\n (inquiry)array_length,\t\t/*sq_length*/\n (binaryfunc)NULL, /* sq_concat is handled by nb_add*/\n (intargfunc)NULL, /* sq_repeat is handled nb_multiply*/\n (intargfunc)array_item_nice,\t\t/*sq_item*/\n (intintargfunc)array_slice,\t\t/*sq_slice*/\n (intobjargproc)array_ass_item,\t/*sq_ass_item*/\n (intintobjargproc)array_ass_slice,\t/*sq_ass_slice*/\n\t(objobjproc) array_contains, /* sq_contains */\n\t(binaryfunc) NULL, /* sg_inplace_concat */\n\t(intargfunc) NULL /* sg_inplace_repeat */\n};\n\n\n/****************** End of Sequence Protocol ****************************/\n\n\nstatic int \ndump_data(char **string, int *n, int *max_n, char *data, int nd, \n intp *dimensions, intp *strides, PyArrayObject* self) \n{\n PyArray_Descr *descr=self->descr;\n PyObject *op, *sp;\n char *ostring;\n int i, N;\n\t\n#define CHECK_MEMORY if (*n >= *max_n-16) { *max_n *= 2; \\\n\t\t*string = (char *)_pya_realloc(*string, *max_n); }\n\t\n if (nd == 0) {\n\t\t\n if ((op = descr->f->getitem(data, self)) == NULL) return -1;\n sp = PyObject_Repr(op);\n if (sp == NULL) {Py_DECREF(op); return -1;}\n ostring = PyString_AsString(sp);\n N = PyString_Size(sp)*sizeof(char);\n *n += N;\n CHECK_MEMORY\n memmove(*string+(*n-N), ostring, N);\n Py_DECREF(sp);\n Py_DECREF(op);\n return 0;\n } else {\n CHECK_MEMORY\n (*string)[*n] = '[';\n *n += 1;\n for(i=0; idata, \n\t\t self->nd, self->dimensions, \n self->strides, self) < 0) { \n\t\t_pya_free(string); return NULL; \n\t}\n\t\n\tif (PyArray_ISEXTENDED(self)) {\n\t\tchar buf[100];\n\t\tsnprintf(buf, sizeof(buf), \"%d\", self->descr->elsize);\n\t\tsprintf(string+n, \", '%c%s')\", self->descr->type, buf);\n\t\tret = PyString_FromStringAndSize(string, n+6+strlen(buf));\n\t}\n\telse {\n\t\tsprintf(string+n, \", '%c')\", self->descr->type);\n\t\tret = PyString_FromStringAndSize(string, n+6);\n\t}\n\t\n\n _pya_free(string);\n return ret;\n}\n\nstatic PyObject *PyArray_StrFunction=NULL;\nstatic PyObject *PyArray_ReprFunction=NULL;\n\n/*OBJECT_API\n Set the array print function to be a Python function.\n*/\nstatic void \nPyArray_SetStringFunction(PyObject *op, int repr) \n{\n if (repr) {\n\t\t/* Dispose of previous callback */\n Py_XDECREF(PyArray_ReprFunction); \n\t\t/* Add a reference to new callback */\n Py_XINCREF(op); \n\t\t/* Remember new callback */\n PyArray_ReprFunction = op; \n } else {\n\t\t/* Dispose of previous callback */\n Py_XDECREF(PyArray_StrFunction); \n\t\t/* Add a reference to new callback */\n Py_XINCREF(op); \n\t\t/* Remember new callback */\n PyArray_StrFunction = op; \n }\n}\n\nstatic PyObject *\narray_repr(PyArrayObject *self) \n{\n PyObject *s, *arglist;\n\t\n if (PyArray_ReprFunction == NULL) {\n s = array_repr_builtin(self);\n } else {\n arglist = Py_BuildValue(\"(O)\", self);\n s = PyEval_CallObject(PyArray_ReprFunction, arglist);\n Py_DECREF(arglist); \n }\n return s;\n}\n\nstatic PyObject *\narray_str(PyArrayObject *self) \n{\n PyObject *s, *arglist;\n\t\n if (PyArray_StrFunction == NULL) {\n s = array_repr(self);\n } else {\n arglist = Py_BuildValue(\"(O)\", self);\n s = PyEval_CallObject(PyArray_StrFunction, arglist);\n Py_DECREF(arglist); \n }\n return s;\n}\n\nstatic PyObject *\narray_richcompare(PyArrayObject *self, PyObject *other, int cmp_op) \n{\n PyObject *array_other, *result;\n\n switch (cmp_op) \n {\n case Py_LT:\n return PyArray_GenericBinaryFunction(self, other, \n\t\t\t\t\t\t\t n_ops.less);\n case Py_LE:\n return PyArray_GenericBinaryFunction(self, other, \n\t\t\t\t\t\t\t n_ops.less_equal);\n case Py_EQ:\n /* Try to convert other to an array */\n\t\t\tif (!PyArray_Check(other)) {\n\t\t\t\tarray_other = PyArray_FromObject(other, \n\t\t\t\t\t\t\t\t self->descr->type_num, 0, 0);\n\t\t\t\t/* If not successful, then return the integer\n\t\t\t\t object 0. This fixes code that used to\n\t\t\t\t allow equality comparisons between arrays\n\t\t\t\t and other objects which would give a result\n\t\t\t\t of 0\n\t\t\t\t*/\n\t\t\t\tif ((array_other == NULL) ||\t\\\n\t\t\t\t (array_other == Py_None)) {\n\t\t\t\t\tPy_XDECREF(array_other);\n\t\t\t\t\tPyErr_Clear();\n\t\t\t\t\tPy_INCREF(Py_False);\n\t\t\t\t\treturn Py_False;\n\t\t\t\t}\n\t\t\t}\n\t\t\telse {\n\t\t\t\tPy_INCREF(other);\n\t\t\t\tarray_other = other;\n\t\t\t}\n result = PyArray_GenericBinaryFunction(self, \n\t\t\t\t\t\t\t array_other, \n\t\t\t\t\t\t\t n_ops.equal);\n /* If the comparison results in NULL, then the \n\t\t\t two array objects can not be compared together so \n\t\t\t return zero \n */\n Py_DECREF(array_other);\n if (result == NULL) {\n PyErr_Clear();\n Py_INCREF(Py_False);\n return Py_False;\n }\n return result;\n case Py_NE:\n /* Try to convert other to an array */\n\t\t\tif (!PyArray_Check(other)) {\n\t\t\t\tarray_other = PyArray_FromObject(other, \n\t\t\t\t\t\t\t\t self->descr->type_num, 0, 0);\n\t\t\t\t/* If not successful, then objects cannot be \n\t\t\t\t compared and cannot be equal, therefore, \n\t\t\t\t return True;\n\t\t\t\t*/\n\t\t\t\tif ((array_other == NULL) ||\t\\\n\t\t\t\t (array_other == Py_None)) {\n\t\t\t\t\tPy_XDECREF(array_other);\n\t\t\t\t\tPyErr_Clear();\n\t\t\t\t\tPy_INCREF(Py_True);\n\t\t\t\t\treturn Py_True;\n\t\t\t\t}\n\t\t\t}\n\t\t\telse {\n\t\t\t\tPy_INCREF(other);\n\t\t\t\tarray_other = other;\n\t\t\t}\n\t\t\tresult = PyArray_GenericBinaryFunction(self, \n\t\t\t\t\t\t\t array_other, \n\t\t\t\t\t\t\t n_ops.not_equal);\n\t\t\tPy_DECREF(array_other);\n if (result == NULL) {\n PyErr_Clear();\n Py_INCREF(Py_True);\n return Py_True;\n }\n return result;\n case Py_GT:\n return PyArray_GenericBinaryFunction(self, other, \n\t\t\t\t\t\t\t n_ops.greater);\n case Py_GE:\n return PyArray_GenericBinaryFunction(self, \n\t\t\t\t\t\t\t other, \n\t\t\t\t\t \t n_ops.greater_equal);\n }\n return NULL;\n}\n\nstatic PyObject *\n_check_axis(PyArrayObject *arr, int *axis, int flags)\n{\n\tPyObject *temp;\n\tint n = arr->nd;\n\n\tif ((*axis >= MAX_DIMS) || (n==0)) {\n\t\ttemp = PyArray_Ravel(arr,0);\n\t\t*axis = PyArray_NDIM(temp)-1;\n\t\treturn temp;\n\t}\n\telse {\n\t\tif (flags) {\n\t\t\ttemp = PyArray_CheckFromAny((PyObject *)arr, NULL, \n 0, 0, flags, NULL);\n\t\t\tif (temp == NULL) return NULL;\n\t\t}\n\t\telse {\n\t\t\tPy_INCREF(arr);\n\t\t\ttemp = (PyObject *)arr;\n\t\t}\n\t}\n\tif (*axis < 0) *axis += n;\n\tif ((*axis < 0) || (*axis >= n)) {\n\t\tPyErr_Format(PyExc_ValueError, \n\t\t\t \"axis(=%d) out of bounds\", *axis);\n\t\tPy_DECREF(temp);\n\t\treturn NULL;\n\t}\n\treturn temp;\n}\n\n#include \"arraymethods.c\"\n\n/* Lifted from numarray */\nstatic PyObject *\nPyArray_IntTupleFromIntp(int len, intp *vals)\n{\n\tint i;\n PyObject *intTuple = PyTuple_New(len);\n if (!intTuple) goto fail;\n for(i=0; i= SIZEOF_INTP\n\t\tif (!(op = PyNumber_Int(seq))) return -1;\n#else\n\t\tif (!(op = PyNumber_Long(seq))) return -1;\n#endif\n\t\tnd = 1;\n#if SIZEOF_LONG >= SIZEOF_INTP\n\t\tvals[0] = (intp ) PyInt_AsLong(op);\n#else\n\t\tvals[0] = (intp ) PyLong_AsLongLong(op);\n#endif\n\t\tPy_DECREF(op);\n\t} else {\n\t\tfor(i=0; i < MIN(nd,maxvals); i++) {\n\t\t\top = PySequence_GetItem(seq, i);\n\t\t\tif (op == NULL) return -1;\n#if SIZEOF_LONG >= SIZEOF_INTP\n\t\t\tvals[i]=(intp )PyInt_AsLong(op);\n#else\n\t\t\tvals[i]=(intp )PyLong_AsLongLong(op);\n#endif\n\t\t\tPy_DECREF(op);\n\t\t\tif(PyErr_Occurred()) return -1;\n\t\t}\n\t}\n\treturn nd;\n}\n\n\n/* Check whether the given array is stored contiguously (row-wise) in\n memory. */\nstatic int\n_IsContiguous(PyArrayObject *ap) \n{\n\tregister intp sd;\n\tregister intp dim;\n\tregister int i;\n \n\n\tif (ap->nd == 0) return 1;\n\tsd = ap->descr->elsize;\n\tif (ap->nd == 1) return (ap->dimensions[0] == 1 || \\\n\t\t\t\t sd == ap->strides[0]);\n\tfor (i = ap->nd-1; i >= 0; --i) {\n\t\tdim = ap->dimensions[i];\n\t\t/* contiguous by definition */\n\t\tif (dim == 0) return 1;\n\t\tif (ap->strides[i] != sd) return 0;\n\t\tsd *= dim;\n\t}\n\treturn 1;\n}\n\n\nstatic int \n_IsFortranContiguous(PyArrayObject *ap) \n{\n\tregister intp sd;\n\tregister intp dim;\n\tregister int i;\n\t\n\tif (ap->nd == 0) return 1;\n\tsd = ap->descr->elsize;\n\tif (ap->nd == 1) return (ap->dimensions[0] == 1 || \\\n\t\t\t\t sd == ap->strides[0]);\n\tfor (i=0; i< ap->nd; ++i) {\n\t\tdim = ap->dimensions[i];\n\t\t/* contiguous by definition */\n\t\tif (dim == 0) return 1; \n\t\tif (ap->strides[i] != sd) return 0;\n\t\tsd *= dim;\n\t}\n\treturn 1;\n}\n\nstatic int\n_IsAligned(PyArrayObject *ap) \n{\n\tint i, alignment, aligned=1;\n\tintp ptr;\n\tint type = ap->descr->type_num;\n\n\tif ((type == PyArray_STRING) || (type == PyArray_VOID))\n\t\treturn 1;\n\n\talignment = ap->descr->alignment;\n\tif (alignment == 1) return 1;\n\n\tptr = (intp) ap->data;\n aligned = (ptr % alignment) == 0;\n for (i=0; i nd; i++)\n aligned &= ((ap->strides[i] % alignment) == 0);\n return aligned != 0;\n}\n\nstatic Bool\n_IsWriteable(PyArrayObject *ap)\n{\n\tPyObject *base=ap->base;\n\tvoid *dummy;\n\tint n;\n\n\t/* If we own our own data, then no-problem */\n\tif ((base == NULL) || (ap->flags & OWN_DATA)) return TRUE;\n\n\t/* Get to the final base object \n\t If it is a writeable array, then return TRUE\n\t If we can find an array object \n\t or a writeable buffer object as the final base object\n\t or a string object (for pickling support memory savings).\n\t - this last could be removed if a proper pickleable \n\t buffer was added to Python.\n\t*/\n\n\twhile(PyArray_Check(base)) {\n\t\tif (PyArray_CHKFLAGS(base, OWN_DATA)) \n\t\t\treturn (Bool) (PyArray_ISWRITEABLE(base));\n\t\tbase = PyArray_BASE(base);\n\t}\n\n\t/* here so pickle support works seamlessly \n\t and unpickled array can be set and reset writeable \n\t -- could be abused -- */\n\tif PyString_Check(base) return TRUE;\n\n\tif (PyObject_AsWriteBuffer(base, &dummy, &n) < 0)\n\t\treturn FALSE;\n\t\n\treturn TRUE;\n}\n\n\n/*OBJECT_API\n Update Several Flags at once.\n*/\nstatic void\nPyArray_UpdateFlags(PyArrayObject *ret, int flagmask)\n{\n\n\tif (flagmask & FORTRAN) {\n\t\tif (_IsFortranContiguous(ret)) {\n\t\t\tret->flags |= FORTRAN;\n\t\t\tif (ret->nd > 1) ret->flags &= ~CONTIGUOUS;\n\t\t}\n\t\telse ret->flags &= ~FORTRAN;\n\t}\n\tif (flagmask & CONTIGUOUS) {\n\t\tif (_IsContiguous(ret)) {\n\t\t\tret->flags |= CONTIGUOUS;\n\t\t\tif (ret->nd > 1) ret->flags &= ~FORTRAN;\n\t\t}\n\t\telse ret->flags &= ~CONTIGUOUS;\n\t}\n\tif (flagmask & ALIGNED) {\n\t\tif (_IsAligned(ret)) ret->flags |= ALIGNED;\n\t\telse ret->flags &= ~ALIGNED;\n\t}\n\t/* This is not checked by default WRITEABLE is not part of UPDATE_ALL_FLAGS */\n\tif (flagmask & WRITEABLE) {\n\t if (_IsWriteable(ret)) ret->flags |= WRITEABLE;\n\t \telse ret->flags &= ~WRITEABLE;\t\n }\n\treturn;\n}\n\n/* This routine checks to see if newstrides (of length nd) will not \n walk outside of the memory implied by a single segment array of the provided \n dimensions and element size. If numbytes is 0 it will be calculated from \n the provided shape and element size.\n*/\n/*OBJECT_API*/\nstatic Bool\nPyArray_CheckStrides(int elsize, int nd, intp numbytes, \n\t\t intp *dims, intp *newstrides)\n{\n\tint i;\n\t\n\tif (numbytes == 0) \n\t\tnumbytes = PyArray_MultiplyList(dims, nd) * elsize;\n\t\n\tfor (i=0; i numbytes) {\n\t\t\treturn FALSE;\n\t\t}\n\t}\n\treturn TRUE;\n\t\n}\n\n\n/* This is the main array creation routine. */\n\n/* Flags argument has multiple related meanings \n depending on data and strides: \n\n If data is given, then flags is flags associated with data. \n If strides is not given, then a contiguous strides array will be created\n and the CONTIGUOUS bit will be set. If the flags argument \n has the FORTRAN bit set, then a FORTRAN-style strides array will be\n created (and of course the FORTRAN flag bit will be set). \n\n If data is not given but created here, then flags will be DEFAULT_FLAGS\n and a non-zero flags argument can be used to indicate a FORTRAN style\n array is desired. \n*/\n\nstatic intp\n_array_fill_strides(intp *strides, intp *dims, int nd, intp itemsize, \n\t\t int inflag, int *objflags) \n{\n\tint i;\n\t/* Only make Fortran strides if not contiguous as well */\n\tif ((inflag & FORTRAN) && !(inflag & CONTIGUOUS)) {\n\t\tfor (i=0; i 1) *objflags &= ~CONTIGUOUS;\n\t\telse *objflags |= CONTIGUOUS;\n\t}\n\telse {\n\t\tfor (i=nd-1;i>=0;i--) {\n\t\t\tstrides[i] = itemsize;\n\t\t\titemsize *= dims[i] ? dims[i] : 1;\n\t\t}\n\t\t*objflags |= CONTIGUOUS;\n\t\tif (nd > 1) *objflags &= ~FORTRAN;\n\t\telse *objflags |= FORTRAN;\n\t}\n\treturn itemsize;\n}\n\n/*OBJECT_API\n Generic new array creation routine.\n*/\nstatic PyObject *\nPyArray_New(PyTypeObject *subtype, int nd, intp *dims, int type_num,\n intp *strides, void *data, int itemsize, int flags,\n\t PyObject *obj)\n{\n\tPyArray_Descr *descr;\n\tPyObject *new;\n\n\tdescr = PyArray_DescrFromType(type_num);\n\tif (descr == NULL) return NULL;\t\n\tif (descr->elsize == 0) {\n\t\tif (itemsize < 1) {\n\t\t\tPyErr_SetString(PyExc_ValueError,\n\t\t\t\t\t\"data type must provide an itemsize\");\n\t\t\tPy_DECREF(descr);\n\t\t\treturn NULL;\n\t\t}\n\t\tPyArray_DESCR_REPLACE(descr);\n\t\tdescr->elsize = itemsize;\n\t}\n\tnew = PyArray_NewFromDescr(subtype, descr, nd, dims, strides,\n\t\t\t\t data, flags, obj);\n\treturn new;\n}\n\n/* Change a sub-array field to the base descriptor */\nstatic int\n_update_descr_and_dimensions(PyArray_Descr **des, intp *newdims, \n\t\t\t intp *newstrides, int oldnd)\n{\n\tPyArray_Descr *old;\n\tint newnd;\n\tint numnew;\n\tintp *mydim;\n\tint i;\n\t\n\told = *des;\n\t*des = old->subarray->base;\n\n\tmydim = newdims + oldnd;\n\tif (PyTuple_Check(old->subarray->shape)) {\n\t\tnumnew = PyTuple_GET_SIZE(old->subarray->shape);\n\t\t\n\t\tfor (i=0; isubarray->shape, i));\n\t\t}\n\t}\n\telse {\n\t\tnumnew = 1;\n\t\tmydim[0] = (intp) PyInt_AsLong(old->subarray->shape);\n\t}\n\t\n\tnewnd = oldnd + numnew;\n\n\tif (newstrides) {\n\t\tintp tempsize;\n\t\tintp *mystrides;\n\t\tmystrides = newstrides + oldnd;\n\t\t/* Make new strides */\n\t\ttempsize = (*des)->elsize;\n\t\tfor (i=numnew-1; i>=0; i--) {\n\t\t\tmystrides[i] = tempsize;\n\t\t\ttempsize *= mydim[i] ? mydim[i] : 1;\n\t\t}\n\t}\n\tPy_INCREF(*des); \n\tPy_DECREF(old); \n\treturn newnd;\n}\n\n\n/* steals a reference to descr (even on failure) */\n/*OBJECT_API\n Generic new array creation routine.\n*/\nstatic PyObject *\nPyArray_NewFromDescr(PyTypeObject *subtype, PyArray_Descr *descr, int nd, \n\t\t intp *dims, intp *strides, void *data, \n\t\t int flags, PyObject *obj)\n{\t\n\tPyArrayObject *self;\n\tregister int i;\n\tintp sd;\n\n\tif (descr->subarray) {\n\t\tPyObject *ret;\n\t\tintp newdims[2*MAX_DIMS];\n\t\tintp *newstrides=NULL;\n\t\tmemcpy(newdims, dims, nd*sizeof(intp));\n\t\tif (strides) {\n\t\t\tnewstrides = newdims + MAX_DIMS;\n\t\t\tmemcpy(newstrides, strides, nd*sizeof(intp));\n\t\t}\n\t\tnd =_update_descr_and_dimensions(&descr, newdims, \n\t\t\t\t\t\t newstrides, nd);\n\t\tret = PyArray_NewFromDescr(subtype, descr, nd, newdims, \n\t\t\t\t\t newstrides,\n\t\t\t\t\t data, flags, obj);\n\t\treturn ret;\n\t}\n\n\tif (nd < 0) {\n\t\tPyErr_SetString(PyExc_ValueError,\n\t\t\t\t\"number of dimensions must be >=0\");\n\t\tPy_DECREF(descr);\n\t\treturn NULL;\n\t}\n if (nd > MAX_DIMS) {\n PyErr_Format(PyExc_ValueError,\n \"maximum number of dimensions is %d\", MAX_DIMS);\n\t\tPy_DECREF(descr);\n return NULL;\n\t}\n\n\t/* Check dimensions */\n\tfor (i=nd-1;i>=0;i--) {\n\t\tif (dims[i] < 0) {\n\t\t\tPyErr_SetString(PyExc_ValueError,\n\t\t\t\t\t\"negative dimensions \"\t\\\n\t\t\t\t\t\"are not allowed\");\n\t\t\tPy_DECREF(descr);\n\t\t\treturn NULL;\n\t\t}\n\t}\n\t\n\tself = (PyArrayObject *) subtype->tp_alloc(subtype, 0);\n\tif (self == NULL) {\n\t\tPy_DECREF(descr);\n\t\treturn NULL;\t\n\t}\n\tself->nd = nd;\n\tself->dimensions = NULL;\n\tself->data = NULL;\n\tif (data == NULL) { /* strides is NULL too */\n\t\tself->flags = DEFAULT_FLAGS;\n\t\tif (flags) {\n\t\t\tself->flags |= FORTRAN; \n\t\t\tif (nd > 1) self->flags &= ~CONTIGUOUS;\n\t\t\tflags = FORTRAN;\n\t\t}\n\t}\n\telse self->flags = (flags & ~UPDATEIFCOPY);\n\t\t\n\tsd = descr->elsize;\n\tself->descr = descr;\n\tself->base = (PyObject *)NULL;\n self->weakreflist = (PyObject *)NULL;\n\t\n\tif (nd > 0) {\n\t\tself->dimensions = PyDimMem_NEW(2*nd);\n\t\tif (self->dimensions == NULL) {\n\t\t\tPyErr_NoMemory();\n\t\t\tgoto fail;\n\t\t}\n\t\tself->strides = self->dimensions + nd;\n\t\tmemcpy(self->dimensions, dims, sizeof(intp)*nd);\n\t\tif (strides == NULL) { /* fill it in */\n\t\t\tsd = _array_fill_strides(self->strides, dims, nd, sd,\n\t\t\t\t\t\t flags, &(self->flags));\n\t\t}\n\t\telse {\n\t\t\tif (data == NULL) {\n\t\t\t\tPyErr_SetString(PyExc_ValueError, \n\t\t\t\t\t\t\"if 'strides' is given in \" \\\n\t\t\t\t\t\t\"array creation, data must \" \\\n\t\t\t\t\t\t\"be given too\");\n\t\t\t\tgoto fail;\n\t\t\t} \n\t\t\tmemcpy(self->strides, strides, sizeof(intp)*nd);\n\t\t}\n\t} \t\n\t\t\n\tif (data == NULL) {\n\n\t\t/* Allocate something even for zero-space arrays \n\t\t e.g. shape=(0,) -- otherwise buffer exposure \n\t\t (a.data) doesn't work as it should. */\n\n\t\tif (sd==0) sd = descr->elsize;\n\n\t\tif ((data = PyDataMem_NEW(sd))==NULL) {\n\t\t\tPyErr_NoMemory();\n\t\t\tgoto fail;\n\t\t}\n\t\tself->flags |= OWN_DATA;\n\n\t\t/* It is bad to have unitialized OBJECT pointers */\n /* which could also be sub-fields of a VOID array */\n\t\tif (descr->hasobject) {\n if (descr != &OBJECT_Descr) {\n PyErr_SetString(PyExc_TypeError,\n \"fields with object members \" \\\n \"not yet supported.\");\n goto fail;\n }\n\t\t\tmemset(data, 0, sd);\n\t\t}\n\t}\n\telse {\n self->flags &= ~OWN_DATA; /* If data is passed in, \n\t\t\t\t\t this object won't own it \n\t\t\t\t\t by default.\n\t\t\t\t\t Caller must arrange for \n\t\t\t\t\t this to be reset if truly\n\t\t\t\t\t desired */\n }\n self->data = data;\n\n /* call the __array_finalize__\n\t method if a subtype and some object passed in */\n\tif ((obj != NULL) && (subtype != &PyArray_Type) && \n\t (subtype != &PyBigArray_Type)) {\n\t\tPyObject *res, *func, *args;\n\t\tstatic PyObject *str=NULL;\n\n\t\tif (str == NULL) {\n\t\t\tstr = PyString_InternFromString(\"__array_finalize__\");\n\t\t}\n\t\tif (!(self->flags & OWNDATA)) { /* did not allocate own data */\n\t\t\t /* update flags before calling back into\n\t\t\t Python */\n\t\t\tPyArray_UpdateFlags(self, UPDATE_ALL_FLAGS);\n\t\t}\n\t\tfunc = PyObject_GetAttr((PyObject *)self, str);\n\t\tif (func) {\n\t\t\targs = PyTuple_New(1);\n\t\t\tPy_INCREF(obj);\n\t\t\tPyTuple_SET_ITEM(args, 0, obj);\n\t\t\tres = PyObject_Call(func, args, NULL);\n\t\t\tPy_DECREF(args);\n\t\t\tPy_DECREF(func);\n\t\t\tif (res == NULL) goto fail;\n\t\t\telse Py_DECREF(res);\n\t\t}\n\t}\n\t\n\treturn (PyObject *)self;\n\n fail:\n\tPy_DECREF(self);\n\treturn NULL;\n}\n\n\n\n/*OBJECT_API\n Resize (reallocate data). Only works if nothing else is referencing\n this array and it is contiguous.\n*/\nstatic PyObject * \nPyArray_Resize(PyArrayObject *self, PyArray_Dims *newshape)\n{\n intp oldsize, newsize;\n int new_nd=newshape->len, k, n, elsize;\n int refcnt;\n intp* new_dimensions=newshape->ptr;\n intp new_strides[MAX_DIMS];\n intp sd;\n intp *dimptr;\n char *new_data;\n\t\n if (!PyArray_ISCONTIGUOUS(self)) {\n PyErr_SetString(PyExc_ValueError, \n \"resize only works on contiguous arrays\");\n return NULL;\n }\n\n newsize = PyArray_MultiplyList(new_dimensions, new_nd);\n oldsize = PyArray_SIZE(self);\n \n\tif (oldsize != newsize) {\n\t\tif (!(self->flags & OWN_DATA)) {\n\t\t\tPyErr_SetString(PyExc_ValueError, \n\t\t\t\t\t\"cannot resize this array: \"\t\\\n\t\t\t\t\t\"it does not own its data\");\n\t\t\treturn NULL;\n\t\t}\n\t\t\n\t\trefcnt = REFCOUNT(self);\n\t\tif ((refcnt > 2) || (self->base != NULL) || \\\n\t\t (self->weakreflist != NULL)) {\n\t\t\tPyErr_SetString(PyExc_ValueError, \n\t\t\t\t\t\"cannot resize an array that has \"\\\n\t\t\t\t\t\"been referenced or is referencing\\n\"\\\n\t\t\t\t\t\"another array in this way. Use the \"\\\n\t\t\t\t\t\"resize function\");\n\t\t\treturn NULL;\n\t\t} \n\t\t\t\t\n\t\tif (newsize == 0) sd = self->descr->elsize;\t\n\t\telse sd = newsize * self->descr->elsize;\n\t\t/* Reallocate space if needed */\n\t\tnew_data = PyDataMem_RENEW(self->data, sd);\n\t\tif (new_data == NULL) {\n\t\t\tPyErr_SetString(PyExc_MemoryError, \n\t\t\t\t\t\"cannot allocate memory for array\");\n\t\t\treturn NULL;\n\t\t}\n\t\tself->data = new_data;\n\t}\n \n if ((newsize > oldsize) && PyArray_ISWRITEABLE(self)) { \n\t\t/* Fill new memory with zeros */\n elsize = self->descr->elsize;\n\t\tif ((PyArray_TYPE(self) == PyArray_OBJECT)) {\n\t\t\tPyObject *zero = PyInt_FromLong(0);\n PyObject **optr;\n\t\t\toptr = ((PyObject **)self->data) + oldsize;\n\t\t\tn = newsize - oldsize;\n\t\t\tfor (k=0; kdata+oldsize*elsize, 0, \n\t\t\t (newsize-oldsize)*elsize);\n\t\t}\n\t}\n \n if (self->nd != new_nd) { /* Different number of dimensions. */\n self->nd = new_nd;\n \n /* Need new dimensions and strides arrays */\n dimptr = PyDimMem_RENEW(self->dimensions, 2*new_nd);\n if (dimptr == NULL) {\n\t\t\tPyErr_SetString(PyExc_MemoryError, \n \"cannot allocate memory for array \" \\\n \"(array may be corrupted)\");\n return NULL;\n }\n self->dimensions = dimptr;\n\t\tself->strides = dimptr + new_nd;\n }\n\n /* make new_strides variable */\n sd = (intp) self->descr->elsize;\n sd = _array_fill_strides(new_strides, new_dimensions, new_nd, sd,\n 0, &(self->flags));\n\n \n memmove(self->dimensions, new_dimensions, new_nd*sizeof(intp));\n memmove(self->strides, new_strides, new_nd*sizeof(intp));\n\n Py_INCREF(Py_None);\t\n return Py_None;\n \n}\n\n\n/* Assumes contiguous */\n/*OBJECT_API*/\nstatic void\nPyArray_FillObjectArray(PyArrayObject *arr, PyObject *obj)\n{\n PyObject **optr;\n intp i,n;\n optr = (PyObject **)(arr->data);\n n = PyArray_SIZE(arr);\n if (obj == NULL) {\n for (i=0; ielsize;\n\tPy_INCREF(descr);\n\tnewarr = PyArray_FromAny(obj, descr, 0,0, ALIGNED, NULL);\n\tif (newarr == NULL) return -1;\n\tfromptr = PyArray_DATA(newarr);\n\tsize=PyArray_SIZE(arr);\n\tswap=!PyArray_ISNOTSWAPPED(arr);\n\tcopyswap = arr->descr->f->copyswap;\n\tif (PyArray_ISONESEGMENT(arr)) {\n\t\tchar *toptr=PyArray_DATA(arr);\n\t\twhile (size--) {\n\t\t\tcopyswap(toptr, fromptr, swap, itemsize);\n\t\t\ttoptr += itemsize;\n\t\t}\n\t}\n\telse {\n\t\tPyArrayIterObject *iter;\n\t\t\n\t\titer = (PyArrayIterObject *)\\\n\t\t\tPyArray_IterNew((PyObject *)arr);\n\t\tif (iter == NULL) {\n\t\t\tPy_DECREF(newarr);\n\t\t\treturn -1;\n\t\t}\n\t\twhile(size--) {\n\t\t\tcopyswap(iter->dataptr, fromptr, swap, itemsize);\n\t\t\tPyArray_ITER_NEXT(iter);\n\t\t}\n\t\tPy_DECREF(iter);\n\t}\n\tPy_DECREF(newarr);\n\treturn 0;\n}\n\nstatic PyObject *\narray_new(PyTypeObject *subtype, PyObject *args, PyObject *kwds) \n{\n\tstatic char *kwlist[] = {\"shape\", \"dtype\", \"buffer\", /* XXX ? */\n\t\t\t\t \"offset\", \"strides\",\n\t\t\t\t \"fortran\", NULL};\n\tPyArray_Descr *descr=NULL;\n\tint type_num;\n\tint itemsize;\n PyArray_Dims dims = {NULL, 0};\n PyArray_Dims strides = {NULL, 0};\n PyArray_Chunk buffer;\n\tlonglong offset=0;\n\tint fortran = 0;\n\tPyArrayObject *ret;\n\n\tbuffer.ptr = NULL; \n /* Usually called with shape and type\n but can also be called with buffer, strides, and swapped info\n */\n\n\t/* For now, let's just use this to create an empty, contiguous \n\t array of a specific type and shape. \n\t*/\t\n\n\tif (!PyArg_ParseTupleAndKeywords(args, kwds, \"O&|O&O&LO&i\",\n\t\t\t\t\t kwlist, PyArray_IntpConverter,\n &dims, \n PyArray_DescrConverter,\n\t\t\t\t\t &descr,\n PyArray_BufferConverter,\n &buffer,\n\t\t\t\t\t &offset,\n &PyArray_IntpConverter, \n &strides,\n &fortran)) \n\t\tgoto fail;\n\n\n\tif (descr == NULL)\n\t\tdescr = PyArray_DescrFromType(PyArray_LONG);\n\n\ttype_num = descr->type_num;\n\titemsize = descr->elsize;\n\n if (dims.ptr == NULL) {\n PyErr_SetString(PyExc_ValueError, \"need to give a \"\\\n \"valid shape as the first argument\");\n goto fail;\n }\n\n if (buffer.ptr == NULL) {\n ret = (PyArrayObject *)\\\n\t\t\tPyArray_NewFromDescr(subtype, descr,\n\t\t\t\t\t (int)dims.len, \n\t\t\t\t\t dims.ptr, \n\t\t\t\t\t NULL, NULL, fortran, NULL);\n if (ret == NULL) {descr=NULL;goto fail;}\n if (type_num == PyArray_OBJECT) { /* place Py_None */\n PyArray_FillObjectArray(ret, Py_None);\n }\n }\n else { /* buffer given -- use it */\n\t\tbuffer.len -= offset;\n\t\tbuffer.ptr += offset;\n if (dims.len == 1 && dims.ptr[0] == -1) {\n dims.ptr[0] = buffer.len / itemsize;\n }\n else if (buffer.len < itemsize* \\\n PyArray_MultiplyList(dims.ptr, dims.len)) {\n PyErr_SetString(PyExc_TypeError, \n \"buffer is too small for \" \\\n \"requested array\");\n goto fail;\n }\n if (strides.ptr != NULL) {\n\t\t\tif (strides.len != dims.len) {\n\t\t\t\tPyErr_SetString(PyExc_ValueError, \n\t\t\t\t\t\t\"strides, if given, must be \"\\\n\t\t\t\t\t\t\"the same length as shape\");\n\t\t\t\tgoto fail;\n\t\t\t}\n\t\t\tif (!PyArray_CheckStrides(itemsize, strides.len, \n\t\t\t\t\t\t buffer.len,\n\t\t\t\t\t\t dims.ptr, strides.ptr)) {\n\t\t\t\tPyErr_SetString(PyExc_ValueError, \n\t\t\t\t\t\t\"strides is incompatible \"\\\n\t\t\t\t\t\t\"with shape of requested\"\\\n\t\t\t\t\t\t\"array and size of buffer\");\n\t\t\t\tgoto fail;\n\t\t\t}\n }\n if (type_num == PyArray_OBJECT) {\n PyErr_SetString(PyExc_TypeError, \"cannot construct \"\\\n \"an object array from buffer data\");\n goto fail;\n }\n /* get writeable and aligned */\n if (fortran) buffer.flags |= FORTRAN;\n ret = (PyArrayObject *)\\\n\t\t\tPyArray_NewFromDescr(subtype, descr,\n\t\t\t\t\t dims.len, dims.ptr,\n\t\t\t\t\t strides.ptr,\n\t\t\t\t\t (char *)buffer.ptr, \n\t\t\t\t\t buffer.flags, NULL); \n if (ret == NULL) {descr=NULL; goto fail;}\n PyArray_UpdateFlags(ret, UPDATE_ALL_FLAGS);\n ret->base = buffer.base;\n Py_INCREF(buffer.base); \n }\n\n PyDimMem_FREE(dims.ptr);\n if (strides.ptr) PyDimMem_FREE(strides.ptr);\n return (PyObject *)ret;\n \n fail:\n\tPy_XDECREF(descr);\n if (dims.ptr) PyDimMem_FREE(dims.ptr);\n if (strides.ptr) PyDimMem_FREE(strides.ptr);\n return NULL;\n}\n\n\nstatic PyObject *\narray_iter(PyArrayObject *arr)\n{\n\tif (arr->nd == 0) {\n\t\tPyErr_SetString(PyExc_TypeError,\n\t\t\t\t\"iteration over a scalar (0-dim array)\");\n\t\treturn NULL;\n\t}\n\treturn PySeqIter_New((PyObject *)arr);\n}\n\n\n/******************* array attribute get and set routines ******************/\n\nstatic PyObject *\narray_ndim_get(PyArrayObject *self)\n{\n\treturn PyInt_FromLong(self->nd);\n}\n\nstatic PyObject *\narray_flags_get(PyArrayObject *self)\n{\n return PyObject_CallMethod(_numpy_internal, \"flagsobj\", \"Oii\", \n self, self->flags, 0);\n}\n\nstatic PyObject *\narray_shape_get(PyArrayObject *self)\n{\n\treturn PyArray_IntTupleFromIntp(self->nd, self->dimensions);\n}\n\n\nstatic int\narray_shape_set(PyArrayObject *self, PyObject *val)\n{\n \tint nd;\n\tPyObject *ret;\n\n\tret = PyArray_Reshape(self, val);\n\tif (ret == NULL) return -1;\n\n\t/* Free old dimensions and strides */\n\tPyDimMem_FREE(self->dimensions);\n\tnd = PyArray_NDIM(ret);\n\tself->nd = nd;\n\tif (nd > 0) { /* create new dimensions and strides */\n\t\tself->dimensions = PyDimMem_NEW(2*nd);\n\t\tif (self->dimensions == NULL) {\n\t\t\tPy_DECREF(ret);\n\t\t\tPyErr_SetString(PyExc_MemoryError,\"\");\n\t\t\treturn -1;\n\t\t}\n\t\tself->strides = self->dimensions + nd;\n\t\tmemcpy(self->dimensions, PyArray_DIMS(ret), \n\t\t nd*sizeof(intp));\n\t\tmemcpy(self->strides, PyArray_STRIDES(ret), \n\t\t nd*sizeof(intp));\n\t}\n\telse {self->dimensions=NULL; self->strides=NULL;}\n\tPy_DECREF(ret);\n\tPyArray_UpdateFlags(self, CONTIGUOUS | FORTRAN);\n\treturn 0;\n}\n\n\nstatic PyObject *\narray_strides_get(PyArrayObject *self)\n{\n\treturn PyArray_IntTupleFromIntp(self->nd, self->strides);\n}\n\nstatic int\narray_strides_set(PyArrayObject *self, PyObject *obj)\n{\n\tPyArray_Dims newstrides = {NULL, 0};\n\tPyArrayObject *new;\n\tintp numbytes;\n\n\tif (!PyArray_IntpConverter(obj, &newstrides) || \\\n\t newstrides.ptr == NULL) {\n\t\tPyErr_SetString(PyExc_TypeError, \"invalid strides\");\n\t\treturn -1;\n\t}\n\tif (newstrides.len != self->nd) {\n\t\tPyErr_Format(PyExc_ValueError, \"strides must be \"\t\\\n\t\t\t \" same length as shape (%d)\", self->nd);\n\t\tgoto fail;\n\t}\n\tnew = self;\n\twhile(new->base != NULL) {\n\t\tif (PyArray_Check(new->base)) \n\t\t\tnew = (PyArrayObject *)new->base;\n\t}\n\tnumbytes = PyArray_MultiplyList(new->dimensions, \n\t\t\t\t\tnew->nd)*new->descr->elsize;\n\t\n\tif (!PyArray_CheckStrides(self->descr->elsize, self->nd, numbytes, \n\t\t\t\t self->dimensions, newstrides.ptr)) {\n\t\tPyErr_SetString(PyExc_ValueError, \"strides is not \"\\\n\t\t\t\t\"compatible with available memory\");\n\t\tgoto fail;\n\t}\n\tmemcpy(self->strides, newstrides.ptr, sizeof(intp)*newstrides.len);\n\tPyArray_UpdateFlags(self, CONTIGUOUS | FORTRAN);\n\tPyDimMem_FREE(newstrides.ptr);\n\treturn 0;\n\n fail:\n\tPyDimMem_FREE(newstrides.ptr);\n\treturn -1;\n}\n\n\nstatic PyObject *\narray_protocol_strides_get(PyArrayObject *self)\n{\n\tif PyArray_ISCONTIGUOUS(self) {\n\t\tPy_INCREF(Py_None);\n\t\treturn Py_None;\n\t}\n\treturn PyArray_IntTupleFromIntp(self->nd, self->strides);\n}\n\nstatic PyObject *\narray_priority_get(PyArrayObject *self)\n{\n\tif (PyArray_CheckExact(self)) \n\t\treturn PyFloat_FromDouble(PyArray_PRIORITY);\n\telse if (PyBigArray_CheckExact(self)) \n\t\treturn PyFloat_FromDouble(PyArray_BIG_PRIORITY);\n\telse\n\t\treturn PyFloat_FromDouble(PyArray_SUBTYPE_PRIORITY);\n}\n\n\nstatic PyObject *\narray_dataptr_get(PyArrayObject *self)\n{\n\treturn Py_BuildValue(\"NO\",\n\t\t\t PyString_FromFormat(\"%p\", self->data),\n\t\t\t (self->flags & WRITEABLE ? Py_False :\n\t\t\t Py_True));\n}\n\nstatic PyObject *\narray_data_get(PyArrayObject *self)\n{\n\tintp nbytes;\n\tif (!(PyArray_ISONESEGMENT(self))) {\n\t\tPyErr_SetString(PyExc_AttributeError, \"cannot get single-\"\\\n\t\t\t\t\"segment buffer for discontiguous array\");\n\t\treturn NULL;\n\t}\t\t\n\tnbytes = PyArray_NBYTES(self);\n\tif PyArray_ISWRITEABLE(self) \n\t\treturn PyBuffer_FromReadWriteObject((PyObject *)self, 0, \n\t\t\t\t\t\t (int) nbytes);\n\telse\n\t\treturn PyBuffer_FromObject((PyObject *)self, 0, (int) nbytes);\n}\n\nstatic int\narray_data_set(PyArrayObject *self, PyObject *op)\n{\n\tvoid *buf;\n\tint buf_len;\n\tint writeable=1;\n\n\tif (PyObject_AsWriteBuffer(op, &buf, &buf_len) < 0) {\n\t\twriteable = 0;\n\t\tif (PyObject_AsReadBuffer(op, (const void **)&buf, \n\t\t\t\t\t &buf_len) < 0) {\n\t\t\tPyErr_SetString(PyExc_AttributeError, \n\t\t\t\t\t\"object does not have single-segment \" \\\n\t\t\t\t\t\"buffer interface\");\n\t\t\treturn -1;\n\t\t}\n\t}\n\tif (!PyArray_ISONESEGMENT(self)) {\n\t\tPyErr_SetString(PyExc_AttributeError, \"cannot set single-\" \\\n\t\t\t\t\"segment buffer for discontiguous array\");\n\t\treturn -1;\n\t}\n\tif (PyArray_NBYTES(self) > buf_len) {\n\t\tPyErr_SetString(PyExc_AttributeError, \n\t\t\t\t\"not enough data for array\");\n\t\treturn -1;\n\t}\n\tif (self->flags & OWN_DATA) {\n\t\tPyArray_XDECREF(self);\n\t\tPyDataMem_FREE(self->data);\n\t}\n\tif (self->base) {\n\t\tif (self->flags & UPDATEIFCOPY) {\n\t\t\t((PyArrayObject *)self->base)->flags |= WRITEABLE;\n\t\t\tself->flags &= ~UPDATEIFCOPY;\n\t\t}\n\t\tPy_DECREF(self->base);\n\t}\n\tPy_INCREF(op);\n\tself->base = op;\n\tself->data = buf;\n\tself->flags = CARRAY_FLAGS;\n\tif (!writeable)\n\t\tself->flags &= ~WRITEABLE;\n\treturn 0;\n}\n\n\nstatic PyObject *\narray_itemsize_get(PyArrayObject *self)\n{\n\treturn PyInt_FromLong((long) self->descr->elsize);\n}\n\nstatic PyObject *\narray_size_get(PyArrayObject *self)\n{\n\tintp size=PyArray_SIZE(self);\n#if SIZEOF_INTP <= SIZEOF_LONG\n return PyInt_FromLong((long) size);\n#else\n\tif (size > MAX_LONG || size < MIN_LONG)\n\t\treturn PyLong_FromLongLong(size);\n\telse \n\t\treturn PyInt_FromLong((long) size);\n#endif\n}\n\nstatic PyObject *\narray_nbytes_get(PyArrayObject *self)\n{\n intp nbytes = PyArray_NBYTES(self);\n#if SIZEOF_INTP <= SIZEOF_LONG\n return PyInt_FromLong((long) nbytes);\n#else\n\tif (nbytes > MAX_LONG || nbytes < MIN_LONG)\n\t\treturn PyLong_FromLongLong(nbytes);\n\telse \n\t\treturn PyInt_FromLong((long) nbytes);\n#endif\n}\n\n\nstatic PyObject *arraydescr_protocol_typestr_get(PyArray_Descr *);\n\nstatic PyObject *\narray_typestr_get(PyArrayObject *self)\n{\n\treturn arraydescr_protocol_typestr_get(self->descr);\n}\n\nstatic PyObject *\narray_descr_get(PyArrayObject *self) \n{\n\tPy_INCREF(self->descr);\n\treturn (PyObject *)self->descr;\n}\n\n\n/* If the type is changed. \n Also needing change: strides, itemsize\n\n Either itemsize is exactly the same\n or the array is single-segment (contiguous or fortran) with\n compatibile dimensions\n\n The shape and strides will be adjusted in that case as well.\n*/\n\nstatic int\narray_descr_set(PyArrayObject *self, PyObject *arg)\n{\n PyArray_Descr *newtype=NULL;\n intp newdim;\n int index;\n char *msg = \"new type not compatible with array.\";\n\n if (!(PyArray_DescrConverter(arg, &newtype)) ||\n newtype == NULL) {\n PyErr_SetString(PyExc_TypeError, \"invalid data-type for array\");\n\t\treturn -1;\n }\n\tif (newtype->type_num == PyArray_OBJECT || \\\n\t self->descr->type_num == PyArray_OBJECT) {\n\t\tPyErr_SetString(PyExc_TypeError, \\\n\t\t\t\t\"Cannot change descriptor for object\"\\\n\t\t\t\t\"array.\");\n\t\tPy_DECREF(newtype);\n\t\treturn -1;\n\t}\n\n\tif ((newtype->elsize != self->descr->elsize) &&\t\t\\\n\t (self->nd == 0 || !PyArray_ISONESEGMENT(self) || \\\n\t newtype->subarray)) goto fail;\n\t\n\tif (PyArray_ISCONTIGUOUS(self)) index = self->nd - 1;\n\telse index = 0;\n\t\n\tif (newtype->elsize < self->descr->elsize) {\n\t\t/* if it is compatible increase the size of the \n\t\t dimension at end (or at the front for FORTRAN)\n\t\t*/\n\t\tif (self->descr->elsize % newtype->elsize != 0) \n\t\t\tgoto fail;\n\t\tnewdim = self->descr->elsize / newtype->elsize;\n\t\tself->dimensions[index] *= newdim;\n\t\tself->strides[index] = newtype->elsize;\n\t}\n\t\n\telse if (newtype->elsize > self->descr->elsize) {\n\t\t\n\t\t/* Determine if last (or first if FORTRAN) dimension\n\t\t is compatible */\n\t\t\n\t\tnewdim = self->dimensions[index] * self->descr->elsize;\n\t\tif ((newdim % newtype->elsize) != 0) goto fail;\n\t\t\n\t\tself->dimensions[index] = newdim / newtype->elsize;\n\t\tself->strides[index] = newtype->elsize;\n\t}\n\n /* fall through -- adjust type*/\n\n\tPy_DECREF(self->descr);\n\tif (newtype->subarray) {\n\t\t/* create new array object from data and update \n\t\t dimensions, strides and descr from it */\n\t\tPyArrayObject *temp;\n\n\t\ttemp = (PyArrayObject *)\\\n\t\t\tPyArray_NewFromDescr(&PyArray_Type, newtype, self->nd,\n\t\t\t\t\t self->dimensions, self->strides,\n\t\t\t\t\t self->data, self->flags, NULL);\n\t\tPyDimMem_FREE(self->dimensions);\n\t\tself->dimensions = temp->dimensions;\n\t\tself->nd = temp->nd;\n\t\tself->strides = temp->strides;\n\t\tPy_DECREF(newtype);\n\t\tnewtype = temp->descr;\n\t\t/* Fool deallocator */\n\t\ttemp->nd = 0;\n\t\ttemp->dimensions = NULL;\n\t\ttemp->descr = NULL;\n\t\tPy_DECREF(temp);\n\t}\n\n\tself->descr = newtype; \n\tPyArray_UpdateFlags(self, UPDATE_ALL_FLAGS);\n\t\n return 0;\n\n fail:\n\tPyErr_SetString(PyExc_ValueError, msg);\n\tPy_DECREF(newtype);\n\treturn -1;\n}\n\nstatic PyObject *\narray_protocol_descr_get(PyArrayObject *self)\n{\n\tPyObject *res;\n\tPyObject *dobj;\n\t\n\tres = PyObject_GetAttrString((PyObject *)self->descr, \"descr\");\n\tif (res) return res;\n\tPyErr_Clear();\n\n\t/* get default */\n\tdobj = PyTuple_New(2);\n\tif (dobj == NULL) return NULL;\n\tPyTuple_SET_ITEM(dobj, 0, PyString_FromString(\"\"));\n\tPyTuple_SET_ITEM(dobj, 1, array_typestr_get(self));\n\tres = PyList_New(1);\n\tif (res == NULL) {Py_DECREF(dobj); return NULL;}\n\tPyList_SET_ITEM(res, 0, dobj);\n\treturn res;\n}\n\nstatic PyObject *\narray_struct_get(PyArrayObject *self)\n{\n PyArrayInterface *inter;\n \n inter = (PyArrayInterface *)_pya_malloc(sizeof(PyArrayInterface));\n inter->version = 2;\n inter->nd = self->nd;\n inter->typekind = self->descr->kind;\n inter->itemsize = self->descr->elsize;\n inter->flags = self->flags;\n /* reset unused flags */\n\tinter->flags &= ~(UPDATEIFCOPY | OWNDATA); \n\tif (PyArray_ISNOTSWAPPED(self)) inter->flags |= NOTSWAPPED;\n inter->strides = self->strides;\n inter->shape = self->dimensions;\n inter->data = self->data;\n\tPy_INCREF(self);\n return PyCObject_FromVoidPtrAndDesc(inter, self, gentype_struct_free);\n}\n\nstatic PyObject *\narray_base_get(PyArrayObject *self)\n{\n\tif (self->base == NULL) {\n\t\tPy_INCREF(Py_None);\n\t\treturn Py_None;\n\t}\n\telse {\n\t\tPy_INCREF(self->base);\n\t\treturn self->base;\n\t}\n}\n\n\nstatic PyObject *\narray_real_get(PyArrayObject *self)\n{\n\tPyArrayObject *ret;\n\n\tif (PyArray_ISCOMPLEX(self)) {\n\t\tret = (PyArrayObject *)PyArray_New(self->ob_type,\n\t\t\t\t\t\t self->nd,\n\t\t\t\t\t\t self->dimensions,\n\t\t\t\t\t\t self->descr->type_num - \\\n\t\t\t\t\t\t PyArray_NUM_FLOATTYPE,\n\t\t\t\t\t\t self->strides,\n\t\t\t\t\t\t self->data,\n\t\t\t\t\t\t 0,\n\t\t\t\t\t\t self->flags, (PyObject *)self);\n\t\tif (ret == NULL) return NULL;\n\t\tret->flags &= ~CONTIGUOUS;\n\t\tret->flags &= ~FORTRAN;\n\t\tPy_INCREF(self);\n\t\tret->base = (PyObject *)self;\n\t\treturn (PyObject *)ret;\n\t}\n\telse {\n\t\tPy_INCREF(self);\n\t\treturn (PyObject *)self;\n\t}\n}\n\n\nstatic int\narray_real_set(PyArrayObject *self, PyObject *val)\n{\n\tPyArrayObject *ret;\n\tPyArrayObject *new;\n\tint rint;\n\n\tnew = (PyArrayObject *)PyArray_FromAny(val, NULL, 0, 0, 0, NULL);\n\tif (new == NULL) return -1;\n\t\n\tif (PyArray_ISCOMPLEX(self)) {\n\t\tret = (PyArrayObject *)PyArray_New(self->ob_type,\n\t\t\t\t\t\t self->nd,\n\t\t\t\t\t\t self->dimensions,\n\t\t\t\t\t\t self->descr->type_num - \\\n\t\t\t\t\t\t PyArray_NUM_FLOATTYPE,\n\t\t\t\t\t\t self->strides,\n\t\t\t\t\t\t self->data,\n\t\t\t\t\t\t 0,\n\t\t\t\t\t\t self->flags, (PyObject *)self);\n\t\tif (ret == NULL) {Py_DECREF(new); return -1;}\n\t\tret->flags &= ~CONTIGUOUS;\n\t\tret->flags &= ~FORTRAN;\n\t\tPy_INCREF(self);\n\t\tret->base = (PyObject *)self;\n\t}\n\telse {\n\t\tPy_INCREF(self);\n\t\tret = self;\n\t}\t\n\trint = PyArray_CopyInto(ret, new);\n\tPy_DECREF(ret);\n\tPy_DECREF(new);\n\treturn rint;\n}\n\nstatic PyObject *\narray_imag_get(PyArrayObject *self)\n{\t\n\tPyArrayObject *ret;\n PyArray_Descr *type;\n\n\tif (PyArray_ISCOMPLEX(self)) {\n\t\ttype = PyArray_DescrFromType(self->descr->type_num - \n\t\t\t\t\t PyArray_NUM_FLOATTYPE);\n\t\tret = (PyArrayObject *)\t\t\t\t\\\n\t\t\tPyArray_NewFromDescr(self->ob_type,\n\t\t\t\t\t type,\n\t\t\t\t\t self->nd,\n\t\t\t\t\t self->dimensions,\n\t\t\t\t\t self->strides,\n\t\t\t\t\t self->data + type->elsize,\n\t\t\t\t\t self->flags, (PyObject *)self);\n\t\tif (ret == NULL) return NULL;\n\t\tret->flags &= ~CONTIGUOUS;\n\t\tret->flags &= ~FORTRAN;\n\t\tPy_INCREF(self);\n\t\tret->base = (PyObject *)self;\n\t\treturn (PyObject *) ret;\n\t}\n\telse {\n\t\ttype = self->descr;\n\t\tPy_INCREF(type);\n\t\tret = (PyArrayObject *)PyArray_Zeros(self->nd, \n\t\t\t\t\t\t self->dimensions,\n\t\t\t\t\t\t type, \n\t\t\t\t\t\t PyArray_ISFORTRAN(self));\n\t\tret->flags &= ~WRITEABLE;\n\t\treturn (PyObject *)ret;\n\t}\n}\n\nstatic int\narray_imag_set(PyArrayObject *self, PyObject *val)\n{\t\n\tif (PyArray_ISCOMPLEX(self)) {\n\t\tPyArrayObject *ret;\n\t\tPyArrayObject *new;\n\t\tint rint;\n\n\t\tnew = (PyArrayObject *)PyArray_FromAny(val, NULL, 0, 0, 0, NULL); \n\t\tif (new == NULL) return -1;\n\t\tret = (PyArrayObject *)PyArray_New(self->ob_type,\n\t\t\t\t\t\t self->nd,\n\t\t\t\t\t\t self->dimensions,\n\t\t\t\t\t\t self->descr->type_num - \\\n\t\t\t\t\t\t PyArray_NUM_FLOATTYPE,\n\t\t\t\t\t\t self->strides,\n \t\t\t\t\t\t self->data +\t\t\\\n\t\t\t\t\t\t (self->descr->elsize >> 1),\n\t\t\t\t\t\t 0,\n\t\t\t\t\t\t self->flags, (PyObject *)self);\n\t\tif (ret == NULL) {\n\t\t\tPy_DECREF(new); \n\t\t\treturn -1;\n\t\t}\n\t\tret->flags &= ~CONTIGUOUS;\n\t\tret->flags &= ~FORTRAN;\n\t\tPy_INCREF(self);\n\t\tret->base = (PyObject *)self;\n\t\trint = PyArray_CopyInto(ret, new);\n\t\tPy_DECREF(ret);\t\t\n\t\tPy_DECREF(new);\n\t\treturn rint;\n\t}\n\telse {\n\t\tPyErr_SetString(PyExc_TypeError, \"does not have imaginary \" \\\n\t\t\t\t\"part to set\");\n\t\treturn -1;\n\t}\n}\n\nstatic PyObject *\narray_flat_get(PyArrayObject *self)\n{\n return PyArray_IterNew((PyObject *)self);\n}\n\nstatic int \narray_flat_set(PyArrayObject *self, PyObject *val)\n{\n\tPyObject *arr=NULL;\n\tint retval = -1;\n\tPyArrayIterObject *selfit=NULL, *arrit=NULL;\n\tPyArray_Descr *typecode;\n int swap;\n PyArray_CopySwapFunc *copyswap;\n\n\ttypecode = self->descr;\n\tPy_INCREF(typecode);\n\tarr = PyArray_FromAny(val, typecode, \n\t\t\t 0, 0, FORCECAST | FORTRAN_IF(self), NULL);\n\tif (arr == NULL) return -1;\n\tarrit = (PyArrayIterObject *)PyArray_IterNew(arr);\n\tif (arrit == NULL) goto exit;\n\tselfit = (PyArrayIterObject *)PyArray_IterNew((PyObject *)self);\n\tif (selfit == NULL) goto exit;\n\n swap = PyArray_ISNOTSWAPPED(self) != PyArray_ISNOTSWAPPED(arr);\n copyswap = self->descr->f->copyswap;\n if (PyArray_ISOBJECT(self)) {\n while(selfit->index < selfit->size) {\n Py_XDECREF(*((PyObject **)selfit->dataptr));\n Py_INCREF(*((PyObject **)arrit->dataptr)); \n memmove(selfit->dataptr, arrit->dataptr, \n sizeof(PyObject *));\n PyArray_ITER_NEXT(selfit);\n PyArray_ITER_NEXT(arrit);\n if (arrit->index == arrit->size) \n PyArray_ITER_RESET(arrit);\n }\n retval = 0; \n goto exit;\n }\n\n\twhile(selfit->index < selfit->size) {\n\t\tmemmove(selfit->dataptr, arrit->dataptr, self->descr->elsize);\n copyswap(selfit->dataptr, NULL, swap, self->descr->elsize);\n\t\tPyArray_ITER_NEXT(selfit);\n\t\tPyArray_ITER_NEXT(arrit);\n\t\tif (arrit->index == arrit->size) \n\t\t\tPyArray_ITER_RESET(arrit);\n\t}\n\tretval = 0;\n exit:\n\tPy_XDECREF(selfit);\n\tPy_XDECREF(arrit);\n\tPy_XDECREF(arr);\n\treturn retval;\n}\n\nstatic PyGetSetDef array_getsetlist[] = {\n {\"ndim\", \n\t (getter)array_ndim_get, \n\t NULL, \n\t \"number of array dimensions\"},\n {\"flags\", \n\t (getter)array_flags_get, \n NULL,\n\t \"special dictionary of flags\"},\n {\"shape\", \n\t (getter)array_shape_get, \n\t (setter)array_shape_set, \n\t \"tuple of array dimensions\"},\n {\"strides\", \n\t (getter)array_strides_get, \n\t (setter)array_strides_set,\n\t \"tuple of bytes steps in each dimension\"},\n {\"data\", \n\t (getter)array_data_get, \n\t (setter)array_data_set, \n\t \"pointer to start of data\"},\n {\"itemsize\", \n\t (getter)array_itemsize_get, \n\t NULL,\n\t \"length of one element in bytes\"},\n {\"size\",\n (getter)array_size_get,\n\t NULL,\n \"number of elements in the array\"},\n {\"nbytes\",\n (getter)array_nbytes_get,\n NULL,\n \"number of bytes in the array\"},\n\t{\"base\",\n\t (getter)array_base_get,\n\t NULL,\n\t \"base object\"},\n\t{\"dtype\",\n\t (getter)array_descr_get,\n\t (setter)array_descr_set,\n\t \"get(set) data-type-descriptor for array\"},\n {\"real\", \n\t (getter)array_real_get, \n\t (setter)array_real_set, \n\t \"real part of array\"},\n {\"imag\", \n\t (getter)array_imag_get, \n\t (setter)array_imag_set, \n\t \"imaginary part of array\"},\n\t{\"flat\", \n\t (getter)array_flat_get, \n\t (setter)array_flat_set, \n\t \"a 1-d view of a contiguous array\"}, \n\t{\"__array_data__\", \n\t (getter)array_dataptr_get,\n\t NULL,\n\t \"Array protocol: data\"},\n\t{\"__array_typestr__\",\n\t (getter)array_typestr_get,\n\t NULL,\n\t \"Array protocol: typestr\"},\n\t{\"__array_descr__\",\n\t (getter)array_protocol_descr_get,\n\t NULL,\n\t \"Array protocol: descr\"},\n\t{\"__array_shape__\", \n\t (getter)array_shape_get,\n\t NULL,\n\t \"Array protocol: shape\"},\n\t{\"__array_strides__\",\n\t (getter)array_protocol_strides_get,\n\t NULL,\n\t \"Array protocol: strides\"},\n {\"__array_struct__\",\n (getter)array_struct_get,\n NULL,\n \"Array protocol: struct\"},\n\t{\"__array_priority__\",\n\t (getter)array_priority_get,\n\t NULL,\n\t \"Array priority\"},\n \t{NULL, NULL, NULL, NULL}, /* Sentinel */\n};\n\n/****************** end of attribute get and set routines *******************/\n\n\nstatic PyObject *\narray_alloc(PyTypeObject *type, int nitems)\n{\n PyObject *obj;\n /* nitems will always be 0 */ \n obj = (PyObject *)_pya_malloc(sizeof(PyArrayObject));\n PyObject_Init(obj, type);\n return obj;\n}\n\n\nstatic char Arraytype__doc__[] = \n \"A array object represents a multidimensional, homogeneous array\\n\"\n\t\" of fixed-size items. An associated data-type-descriptor object\\n\"\n\t\" details the data-type in an array (including byteorder and any\\n\"\n\t\" fields). An array can be constructed using the numpy.array\\n\"\n\t\" command. Arrays are sequence, mapping and numeric objects.\\n\"\n\t\" More information is available in the numpy module and by looking\\n\"\n\t\" at the methods and attributes of an array.\\n\\n\"\n\t\" ndarray.__new__(subtype, shape=, dtype=int_, buffer=None, \\n\"\n\t\" offset=0, strides=None, fortran=False)\\n\\n\"\n\t\" There are two modes of creating an array using __new__:\\n\"\n\t\" 1) If buffer is None, then only shape, dtype, and fortran \\n\"\n\t\" are used\\n\"\n\t\" 2) If buffer is an object exporting the buffer interface, then\\n\"\n\t\" all keywords are interpreted.\\n\"\n\t\" The dtype parameter can be any object that can be interpreted \\n\"\n\t\" as a numpy.dtype object.\\n\\n\"\n\t\" No __init__ method is needed because the array is fully \\n\"\n\t\" initialized after the __new__ method.\";\n\t\nstatic PyTypeObject PyBigArray_Type = { \n PyObject_HEAD_INIT(NULL)\n 0,\t\t\t\t\t /*ob_size*/\n \"numpy.bigndarray\",\t\t /*tp_name*/\n sizeof(PyArrayObject),\t\t /*tp_basicsize*/\n 0,\t\t\t\t\t /*tp_itemsize*/\n /* methods */\n (destructor)array_dealloc,\t\t /*tp_dealloc */\n (printfunc)NULL,\t\t\t /*tp_print*/\n 0,\t\t\t\t\t /*tp_getattr*/\n 0,\t\t\t\t\t /*tp_setattr*/\n (cmpfunc)0, \t\t /*tp_compare*/\n (reprfunc)array_repr,\t\t /*tp_repr*/\n &array_as_number,\t\t\t /*tp_as_number*/\n NULL, \t\t\t /*tp_as_sequence*/\n &array_as_mapping,\t\t\t /*tp_as_mapping*/\n (hashfunc)0,\t\t\t /*tp_hash*/\n (ternaryfunc)0,\t\t\t /*tp_call*/\n (reprfunc)array_str, \t /*tp_str*/\n\t\t\n (getattrofunc)0,\t\t\t /*tp_getattro*/\n (setattrofunc)0,\t\t\t /*tp_setattro*/\n NULL, \t /*tp_as_buffer*/\n (Py_TPFLAGS_DEFAULT \n | Py_TPFLAGS_BASETYPE\n | Py_TPFLAGS_CHECKTYPES), /*tp_flags*/\n /*Documentation string */\n Arraytype__doc__,\t\t\t /*tp_doc*/\n\n (traverseproc)0,\t\t\t /*tp_traverse */\n (inquiry)0,\t\t\t /*tp_clear */\n (richcmpfunc)array_richcompare,\t /*tp_richcompare */\n offsetof(PyArrayObject, weakreflist), /*tp_weaklistoffset */\n\n /* Iterator support (use standard) */\n\n (getiterfunc)array_iter, \t /* tp_iter */\n (iternextfunc)0,\t\t\t /* tp_iternext */\n\n /* Sub-classing (new-style object) support */\n\n array_methods,\t\t\t /* tp_methods */\n 0,\t\t\t\t\t /* tp_members */\n array_getsetlist,\t\t /* tp_getset */\n 0,\t\t\t\t\t /* tp_base */\n 0,\t\t\t\t\t /* tp_dict */\n 0,\t\t\t\t\t /* tp_descr_get */\n 0,\t\t\t\t\t /* tp_descr_set */\n 0,\t\t\t\t\t /* tp_dictoffset */\n (initproc)0,\t \t /* tp_init */\n array_alloc,\t /* tp_alloc */ \n (newfunc)array_new,\t\t /* tp_new */\n _pya_free, \t /* tp_free */\n 0,\t\t\t\t\t /* tp_is_gc */\n 0,\t\t\t\t\t /* tp_bases */\n 0,\t\t\t\t\t /* tp_mro */\n 0,\t\t\t\t\t /* tp_cache */\n 0,\t\t\t\t\t /* tp_subclasses */\n 0\t\t\t\t\t /* tp_weaklist */\n};\n\n/* A standard array will subclass from the Big Array and \n add the array_as_sequence table\n and the array_as_buffer table\n */\n\nstatic PyTypeObject PyArray_Type = { \n PyObject_HEAD_INIT(NULL)\n 0,\t\t\t\t\t /*ob_size*/\n \"numpy.ndarray\",\t\t\t /*tp_name*/\n sizeof(PyArrayObject),\t\t /*tp_basicsize*/\n 0,\t\t\t\t\t /*tp_itemsize*/\n};\n\n\n/* The rest of this code is to build the right kind of array from a python */\n/* object. */\n\nstatic int \ndiscover_depth(PyObject *s, int max, int stop_at_string, int stop_at_tuple) \n{\n int d=0;\n PyObject *e;\n\t\n if(max < 1) return -1;\n\n if(! PySequence_Check(s) || PyInstance_Check(s) || \\\n\t PySequence_Length(s) < 0) {\n PyErr_Clear(); return 0;\n }\n if (PyArray_Check(s))\n\t\treturn PyArray_NDIM(s);\n if(PyString_Check(s) || PyBuffer_Check(s) || PyUnicode_Check(s))\n\t\treturn stop_at_string ? 0:1;\n\tif (stop_at_tuple && PyTuple_Check(s)) return 0;\n\tif ((e=PyObject_GetAttrString(s, \"__array_shape__\")) != NULL) {\n\t\tif (PyTuple_Check(e)) d=PyTuple_GET_SIZE(e);\n\t\telse d=-1;\n\t\tPy_DECREF(e);\n\t\tif (d>-1) return d;\n\t}\n\telse PyErr_Clear();\n\n if (PySequence_Length(s) == 0) \n\t\treturn 1;\t\n if ((e=PySequence_GetItem(s,0)) == NULL) return -1;\n if(e!=s) {\n\t\td=discover_depth(e, max-1, stop_at_string, stop_at_tuple);\n\t\tif(d >= 0) d++;\n\t}\n Py_DECREF(e);\n return d;\n}\n\nstatic int\ndiscover_itemsize(PyObject *s, int nd, int *itemsize) \n{\n\tint n, r, i;\n\tPyObject *e;\n\t\n\tn = PyObject_Length(s);\n\n\tif ((nd == 0) || PyString_Check(s) ||\t\t\\\n\t PyUnicode_Check(s) || PyBuffer_Check(s)) {\n\t\tif PyUnicode_Check(s) \n\t\t\t*itemsize = MAX(*itemsize, sizeof(Py_UNICODE)*n);\n\t\telse\n\t\t\t*itemsize = MAX(*itemsize, n);\n\t\treturn 0;\n\t}\n\tfor (i=0; i n_lower) n_lower = d[1];\n }\n d[1] = n_lower;\n\t\n return 0;\n}\n\n/* new reference */\n/* doesn't alter refcount of chktype or mintype --- \n unless one of them is returned */\nstatic PyArray_Descr *\n_array_small_type(PyArray_Descr *chktype, PyArray_Descr* mintype)\n{\n\tPyArray_Descr *outtype;\n\n\tif (chktype->type_num > mintype->type_num) outtype = chktype;\n\telse outtype = mintype;\n\n\tPy_INCREF(outtype);\n\tif (PyTypeNum_ISEXTENDED(outtype->type_num) &&\t\t\\\n\t (PyTypeNum_ISEXTENDED(mintype->type_num) ||\t\t\\\n\t mintype->type_num==0)) {\n\t\tint testsize = outtype->elsize;\n\t\tregister int chksize, minsize;\n\t\tchksize = chktype->elsize;\n\t\tminsize = mintype->elsize;\n\t\t/* Handle string->unicode case separately \n\t\t because string itemsize is twice as large */\n\t\tif (outtype->type_num == PyArray_UNICODE && \n\t\t mintype->type_num == PyArray_STRING) {\n\t\t\ttestsize = MAX(chksize, 2*minsize);\n\t\t}\n\t\telse {\n\t\t\ttestsize = MAX(chksize, minsize);\n\t\t}\n\t\tif (testsize != outtype->elsize) {\n\t\t\tPyArray_DESCR_REPLACE(outtype);\n\t\t\touttype->elsize = testsize;\n\t\t\tPy_XDECREF(outtype->fields);\n\t\t\touttype->fields = NULL;\n\t\t}\n\t}\n\treturn outtype;\n}\n\n/* op is an object to be converted to an ndarray. \n\n minitype is the minimum type-descriptor needed. \n \n max is the maximum number of dimensions -- used for recursive call\n to avoid infinite recursion...\n \n*/\n\nstatic PyArray_Descr *\n_array_find_type(PyObject *op, PyArray_Descr *minitype, int max)\n{\n int l;\n PyObject *ip;\n\tPyArray_Descr *chktype=NULL;\n\tPyArray_Descr *outtype;\n\t\n\tif (minitype == NULL) \n\t\tminitype = PyArray_DescrFromType(PyArray_BOOL);\n\telse Py_INCREF(minitype);\n\t\n if (max < 0) goto deflt;\n\t\n if (PyArray_Check(op)) {\n\t\tchktype = PyArray_DESCR(op);\n\t\tPy_INCREF(chktype);\n\t\tgoto finish;\n\t}\n\t\n\tif (PyArray_IsScalar(op, Generic)) {\n\t\tchktype = PyArray_DescrFromScalar(op);\n\t\tgoto finish;\n\t}\n\n\tif ((ip=PyObject_GetAttrString(op, \"__array_typestr__\"))!=NULL) {\n\t\tif (PyString_Check(ip)) {\n\t\t\tchktype =_array_typedescr_fromstr(PyString_AS_STRING(ip));\n\t\t}\n\t\tPy_DECREF(ip);\n if (chktype) goto finish;\n\t}\n\telse PyErr_Clear();\n \n if ((ip=PyObject_GetAttrString(op, \"__array_struct__\")) != NULL) {\n PyArrayInterface *inter;\n char buf[40];\n if (PyCObject_Check(ip)) {\n inter=(PyArrayInterface *)PyCObject_AsVoidPtr(ip);\n if (inter->version == 2) {\n snprintf(buf, 40, \"|%c%d\", inter->typekind, \n\t\t\t\t\t inter->itemsize);\n\t\t\t\tchktype = _array_typedescr_fromstr(buf);\n }\n }\n Py_DECREF(ip);\n if (chktype) goto finish;\n }\n\telse PyErr_Clear();\n \t\n if (PyString_Check(op)) {\n\t\tchktype = PyArray_DescrNewFromType(PyArray_STRING);\n\t\tchktype->elsize = PyString_GET_SIZE(op);\n\t\tgoto finish;\n }\n\n\tif (PyUnicode_Check(op)) {\n\t\tchktype = PyArray_DescrNewFromType(PyArray_UNICODE);\n\t\tchktype->elsize = PyUnicode_GET_DATA_SIZE(op);\n\t\tgoto finish;\n\t}\n\n\tif (PyBuffer_Check(op)) {\n\t\tchktype = PyArray_DescrNewFromType(PyArray_VOID);\n\t\tchktype->elsize = op->ob_type->tp_as_sequence->sq_length(op);\n PyErr_Clear();\n\t\tgoto finish;\n\t}\n\n if (PyObject_HasAttrString(op, \"__array__\")) {\n ip = PyObject_CallMethod(op, \"__array__\", NULL);\n if(ip && PyArray_Check(ip)) {\n\t\t\tchktype = PyArray_DESCR(ip);\n\t\t\tPy_INCREF(chktype);\n Py_DECREF(ip);\n\t\t\tgoto finish;\n\t\t}\n Py_XDECREF(ip);\n\t\tif (PyErr_Occurred()) PyErr_Clear();\n } \n\n\tif (PyInstance_Check(op)) goto deflt;\n\t\n if (PySequence_Check(op)) {\n\n l = PyObject_Length(op);\n if (l < 0 && PyErr_Occurred()) { \n\t\t\tPyErr_Clear(); \n\t\t\tgoto deflt;\n\t\t}\n if (l == 0 && minitype->type_num == PyArray_BOOL) {\n\t\t\tPy_DECREF(minitype);\n\t\t\tminitype = PyArray_DescrFromType(PyArray_INTP);\n\t\t}\n while (--l >= 0) {\n\t\t\tPyArray_Descr *newtype;\n ip = PySequence_GetItem(op, l);\n if (ip==NULL) {\n\t\t\t\tPyErr_Clear(); \n\t\t\t\tgoto deflt;\n\t\t\t}\n\t\t\tchktype = _array_find_type(ip, minitype, max-1);\n\t\t\tnewtype = _array_small_type(chktype, minitype);\n\t\t\tPy_DECREF(minitype);\n\t\t\tminitype = newtype;\n\t\t\tPy_DECREF(chktype);\n Py_DECREF(ip);\n }\n\t\tchktype = minitype;\n\t\tPy_INCREF(minitype);\n\t\tgoto finish;\n }\n\t\n\tif (PyBool_Check(op)) {\n\t\tchktype = PyArray_DescrFromType(PyArray_BOOL);\n\t\tgoto finish;\t\t\n\t}\n else if (PyInt_Check(op)) {\n\t\tchktype = PyArray_DescrFromType(PyArray_LONG);\n\t\tgoto finish;\n\t} else if (PyLong_Check(op)) {\n\t\t/* if integer can fit into a longlong then return that\n\t\t*/\n\t\tif ((PyLong_AsLongLong(op) == -1) && PyErr_Occurred()) {\n\t\t\tPyErr_Clear();\n\t\t\tgoto deflt;\n\t\t}\n\t\tchktype = PyArray_DescrFromType(PyArray_LONGLONG);\n\t\tgoto finish;\n } else if (PyFloat_Check(op)) {\n\t\tchktype = PyArray_DescrFromType(PyArray_DOUBLE);\n\t\tgoto finish;\n\t} else if (PyComplex_Check(op)) {\n\t\tchktype = PyArray_DescrFromType(PyArray_CDOUBLE);\n\t\tgoto finish;\n\t}\n\n deflt:\n\tchktype = PyArray_DescrFromType(PyArray_OBJECT);\n\t\n finish:\n\t\n\touttype = _array_small_type(chktype, minitype);\n\tPy_DECREF(chktype);\n\tPy_DECREF(minitype);\n\treturn outtype; \n}\n\nstatic int \nAssign_Array(PyArrayObject *self, PyObject *v) \n{\n PyObject *e;\n int l, r;\n\t\n if (!PySequence_Check(v)) {\n PyErr_SetString(PyExc_ValueError,\n\t\t\t\t\"assignment from non-sequence\");\n return -1;\n }\n\t\n l=PyObject_Length(v);\n if(l < 0) return -1; \n\t\n while(--l >= 0)\n {\n e=PySequence_GetItem(v,l);\n if (e == NULL) return -1; \n\t\t\tr = PySequence_SetItem((PyObject*)self,l,e);\n Py_DECREF(e);\n if(r == -1) return -1;\n }\n return 0;\n}\n\n/* \"Array Scalars don't call this code\" */ \n/* steals reference to typecode -- no NULL*/\nstatic PyObject *\nArray_FromScalar(PyObject *op, PyArray_Descr *typecode) \n{\n PyArrayObject *ret;\n\tint itemsize; \n\tint type;\n\t\n\titemsize = typecode->elsize;\n\ttype = typecode->type_num;\n\n\tif (itemsize == 0 && PyTypeNum_ISEXTENDED(type)) {\n\t\titemsize = PyObject_Length(op);\n\t\tif (type == PyArray_UNICODE) itemsize *= sizeof(Py_UNICODE);\n\t}\n\n\tret = (PyArrayObject *)PyArray_NewFromDescr(&PyArray_Type, typecode,\n\t\t\t\t\t\t 0, NULL, \n\t\t\t\t\t\t NULL, NULL, 0, NULL);\n\n\tif (ret == NULL) return NULL;\n\n ret->descr->f->setitem(op, ret->data, ret);\n\t\n if (PyErr_Occurred()) {\n Py_DECREF(ret);\n return NULL;\n } else {\n return (PyObject *)ret;\n }\n}\n\n\n/* steals reference to typecode unless return value is NULL*/\nstatic PyObject *\nArray_FromSequence(PyObject *s, PyArray_Descr *typecode, int fortran, \n\t\t int min_depth, int max_depth)\n{\n PyArrayObject *r;\n int nd;\n\tintp d[MAX_DIMS];\n\tint stop_at_string;\n\tint stop_at_tuple;\n\tint type = typecode->type_num;\n\tint itemsize = typecode->elsize;\n\tPyArray_Descr *savetype=typecode;\n\t\n\tstop_at_string = ((type == PyArray_OBJECT) ||\t\\\n\t\t\t (type == PyArray_STRING) ||\t\\\n\t\t\t (type == PyArray_UNICODE) || \\\n\t\t\t (type == PyArray_VOID));\n\n\tstop_at_tuple = (type == PyArray_VOID && ((typecode->fields &&\t\\\n\t\t\t\t\t\t typecode->fields!=Py_None) \\\n\t\t\t\t\t\t || (typecode->subarray)));\n\t\n if (!((nd=discover_depth(s, MAX_DIMS+1, stop_at_string, \n\t\t\t\t stop_at_tuple)) > 0)) {\n\t\tif (nd==0)\n\t\t\treturn Array_FromScalar(s, typecode);\n PyErr_SetString(PyExc_ValueError, \n\t\t\t\t\"invalid input sequence\");\n return NULL;\n }\n\t\n if ((max_depth && nd > max_depth) ||\t\\\n\t (min_depth && nd < min_depth)) {\n PyErr_SetString(PyExc_ValueError, \n\t\t\t\t\"invalid number of dimensions\");\n return NULL;\n }\n\t\n\tif(discover_dimensions(s,nd,d, !stop_at_string) == -1) {\n\t\treturn NULL;\n\t}\n\tif (itemsize == 0 && PyTypeNum_ISEXTENDED(type)) {\n\t\tif (discover_itemsize(s, nd, &itemsize) == -1) {\n\t\t\treturn NULL;\n\t\t}\n\t\tif (type == PyArray_UNICODE) itemsize*=sizeof(Py_UNICODE);\n\t}\n\n\tif (itemsize != typecode->elsize) {\n\t\tPyArray_DESCR_REPLACE(typecode);\n\t\ttypecode->elsize = itemsize;\n\t}\n\t\n r=(PyArrayObject*)PyArray_NewFromDescr(&PyArray_Type, typecode,\n\t\t\t\t\t nd, d, \n\t\t\t\t\t NULL, NULL,\n\t\t\t\t\t fortran, NULL);\n\t\n if(!r) {Py_XINCREF(savetype); return NULL;}\n if(Assign_Array(r,s) == -1) {\n\t\tPy_XINCREF(savetype);\n\t\tPy_DECREF(r);\n\t\treturn NULL;\n\t}\n return (PyObject*)r;\n}\n\n\n/*OBJECT_API\n Is the typenum valid?\n*/\nstatic int \nPyArray_ValidType(int type) \n{\n\tPyArray_Descr *descr;\n\tint res=TRUE;\n\t\n\tdescr = PyArray_DescrFromType(type);\n\tif (descr==NULL) res = FALSE;\n\tPy_DECREF(descr);\n\treturn res;\n}\n\n\n/* If the output is not a CARRAY, then it is buffered also */\n\nstatic int\n_bufferedcast(PyArrayObject *out, PyArrayObject *in)\n{\n\tchar *inbuffer, *bptr, *optr;\n\tchar *outbuffer=NULL;\n\tPyArrayIterObject *it_in=NULL, *it_out=NULL;\n\tregister intp i, index;\n\tintp ncopies = PyArray_SIZE(out) / PyArray_SIZE(in);\n\tint elsize=in->descr->elsize;\n\tint nels = PyArray_BUFSIZE;\n\tint el;\n\tint inswap, outswap=0;\n\tint obuf=!PyArray_ISCARRAY(out);\n\tint oelsize = out->descr->elsize;\n\tPyArray_VectorUnaryFunc *castfunc;\n PyArray_CopySwapFunc *in_csn;\n PyArray_CopySwapFunc *out_csn;\n\tint retval = -1;\n\n\tcastfunc = in->descr->f->cast[out->descr->type_num];\n in_csn = in->descr->f->copyswap;\n out_csn = out->descr->f->copyswap;\n\n\t/* If the input or output is STRING, UNICODE, or VOID */\n\t/* then getitem and setitem are used for the cast */\n\t/* and byteswapping is handled by those methods */\n\n\tinswap = !(PyArray_ISFLEXIBLE(in) || PyArray_ISNOTSWAPPED(in));\n\t\n\tinbuffer = PyDataMem_NEW(PyArray_BUFSIZE*elsize);\n\tif (inbuffer == NULL) return -1;\n\tif (PyArray_ISOBJECT(in)) \n\t\tmemset(inbuffer, 0, PyArray_BUFSIZE*elsize);\n\tit_in = (PyArrayIterObject *)PyArray_IterNew((PyObject *)in);\n\tif (it_in == NULL) goto exit;\n\n\tif (obuf) {\n\t\toutswap = !(PyArray_ISFLEXIBLE(out) || \\\n\t\t\t PyArray_ISNOTSWAPPED(out));\n\t\toutbuffer = PyDataMem_NEW(PyArray_BUFSIZE*oelsize);\n\t\tif (outbuffer == NULL) goto exit;\n\t\tif (PyArray_ISOBJECT(out))\n\t\t\tmemset(outbuffer, 0, PyArray_BUFSIZE*oelsize);\n\t\t\n\t\tit_out = (PyArrayIterObject *)PyArray_IterNew((PyObject *)out);\n\t\tif (it_out == NULL) goto exit;\n\n\t\tnels = MIN(nels, PyArray_BUFSIZE);\n\t}\n\t\n\toptr = (obuf) ? outbuffer: out->data;\n\tbptr = inbuffer;\n\tel = 0;\t\n\twhile(ncopies--) {\n\t\tindex = it_in->size;\n\t\tPyArray_ITER_RESET(it_in);\n\t\twhile(index--) {\n in_csn(bptr, it_in->dataptr, inswap, elsize);\n\t\t\tbptr += elsize;\n\t\t\tPyArray_ITER_NEXT(it_in);\n\t\t\tel += 1;\n\t\t\tif ((el == nels) || (index == 0)) {\n\t\t\t\t/* buffer filled, do cast */\n\t\t\t\t\n\t\t\t\tcastfunc(inbuffer, optr, el, in, out);\n\t\t\t\t\n\t\t\t\tif (obuf) {\n\t\t\t\t\t/* Copy from outbuffer to array */\n\t\t\t\t\tfor(i=0; idataptr,\n optr, outswap,\n oelsize);\n\t\t\t\t\t\toptr += oelsize;\n\t\t\t\t\t\tPyArray_ITER_NEXT(it_out);\n\t\t\t\t\t}\n\t\t\t\t\toptr = outbuffer;\n\t\t\t\t}\n\t\t\t\telse {\n\t\t\t\t\toptr += out->descr->elsize * nels;\n\t\t\t\t}\n\t\t\t\tel = 0;\n\t\t\t\tbptr = inbuffer;\n\t\t\t}\n\t\t}\n\t}\n\tretval = 0;\n exit:\n\tPy_XDECREF(it_in);\n\tPyDataMem_FREE(inbuffer);\n\tPyDataMem_FREE(outbuffer);\t\n\tif (obuf) {\n\t\tPy_XDECREF(it_out);\n\t}\n\treturn retval;\n}\n\n\n/* For backward compatibility */\n\n/* steals reference to at --- cannot be NULL*/\n/*OBJECT_API\n Cast an array using typecode structure.\n*/\nstatic PyObject * \nPyArray_CastToType(PyArrayObject *mp, PyArray_Descr *at, int fortran)\n{\n\tPyObject *out;\n\tint ret;\n\tPyArray_Descr *mpd;\n\n\tmpd = mp->descr;\n\n\tif (((mpd == at) || ((mpd->type_num == at->type_num) &&\t\t\\\n\t\t\t PyArray_EquivByteorders(mpd->byteorder,\\\n\t\t\t\t\t\t at->byteorder) &&\t\\\n\t\t\t ((mpd->elsize == at->elsize) ||\t\t\\\n\t\t\t (at->elsize==0)))) &&\t\t\t\\\n\t PyArray_ISBEHAVED_RO(mp)) {\n\t\tPy_DECREF(at);\n\t\tPy_INCREF(mp);\n\t\treturn (PyObject *)mp;\n\t}\n\t\t\n\tif (at->elsize == 0) {\n\t\tPyArray_DESCR_REPLACE(at);\n\t\tif (at == NULL) return NULL;\n\t\tif (mpd->type_num == PyArray_STRING &&\t\\\n\t\t at->type_num == PyArray_UNICODE)\n\t\t\tat->elsize = mpd->elsize*sizeof(Py_UNICODE);\n\t\tif (mpd->type_num == PyArray_UNICODE &&\n\t\t at->type_num == PyArray_STRING) \n\t\t\tat->elsize = mpd->elsize/sizeof(Py_UNICODE);\n\t\tif (at->type_num == PyArray_VOID)\n\t\t\tat->elsize = mpd->elsize;\n\t}\n\n\tout = PyArray_NewFromDescr(mp->ob_type, at,\n\t\t\t\t mp->nd, \n\t\t\t\t mp->dimensions, \n\t\t\t\t NULL, NULL, \n\t\t\t\t fortran,\n\t\t\t\t (PyObject *)mp);\n\n\tif (out == NULL) return NULL;\n\tret = PyArray_CastTo((PyArrayObject *)out, mp);\n\tif (ret != -1) return out;\n\t\n\tPy_DECREF(out);\n\treturn NULL;\n\t\n}\n\t \n/* The number of elements in out must be an integer multiple\n of the number of elements in mp. \n*/\n\n/*OBJECT_API\n Cast to an already created array.\n*/\nstatic int\nPyArray_CastTo(PyArrayObject *out, PyArrayObject *mp)\n{\n\n\tint simple;\n\tintp mpsize = PyArray_SIZE(mp);\n\tintp outsize = PyArray_SIZE(out);\n\n\tif (mpsize == 0) return 0;\n\tif (!PyArray_ISWRITEABLE(out)) {\n\t\tPyErr_SetString(PyExc_ValueError, \n\t\t\t\t\"output array is not writeable\");\n\t\treturn -1;\n\t}\n\tif (outsize % mpsize != 0) {\n\t\tPyErr_SetString(PyExc_ValueError, \n\t\t\t\t\"output array must have an integer-multiple\"\\\n\t\t\t\t\" of the number of elements in the input \"\\\n\t\t\t\t\"array\");\n\t\treturn -1; \n\t}\n\n\tif (out->descr->type_num >= PyArray_NTYPES) {\n\t\tPyErr_SetString(PyExc_ValueError, \n\t\t\t\t\"Can only cast to builtin types.\");\n\t\treturn -1;\n\t\t\t\t\n\t}\n\n\tsimple = ((PyArray_ISCARRAY_RO(mp) && PyArray_ISCARRAY(out)) || \\\n (PyArray_ISFARRAY_RO(mp) && PyArray_ISFARRAY(out)));\n\t\n\tif (simple) {\n\t\tchar *inptr;\n\t\tchar *optr = out->data;\n\t\tintp obytes = out->descr->elsize * outsize;\n\t\tintp ncopies = outsize / mpsize;\n\n\t\twhile(ncopies--) {\n\t\t\tinptr = mp->data;\n\t\t\tmp->descr->f->cast[out->descr->type_num](inptr, \n\t\t\t\t\t\t\t optr,\n\t\t\t\t\t\t\t mpsize,\n\t\t\t\t\t\t\t mp, out);\n\t\t\toptr += obytes;\n\t\t}\n\t\treturn 0;\n\t}\n\t\n\t/* If not a well-behaved cast, then use buffers */\n\tif (_bufferedcast(out, mp) == -1) {\n\t\treturn -1;\n\t}\n\treturn 0;\n}\n\n/* steals reference to newtype --- acc. NULL */\n/*OBJECT_API*/\nstatic PyObject *\nPyArray_FromArray(PyArrayObject *arr, PyArray_Descr *newtype, int flags) \n{\n\t\n\tPyArrayObject *ret=NULL;\n\tint type, itemsize;\n\tint copy = 0;\n\tint arrflags;\n\tPyArray_Descr *oldtype;\n\tchar *msg = \"cannot copy back to a read-only array\";\n PyTypeObject *subtype;\n\n\toldtype = PyArray_DESCR(arr);\n\n subtype = arr->ob_type;\n\t\n\tif (newtype == NULL) {newtype = oldtype; Py_INCREF(oldtype);}\n\ttype = newtype->type_num;\n\titemsize = newtype->elsize;\n\n\t/* Don't copy if sizes are compatible */\n\tif (PyArray_EquivTypes(oldtype, newtype)) {\n\t\tarrflags = arr->flags;\n\n\t\tcopy = (flags & ENSURECOPY) || \\\n\t\t\t((flags & CONTIGUOUS) && (!(arrflags & CONTIGUOUS))) \\\n\t\t\t|| ((flags & ALIGNED) && (!(arrflags & ALIGNED))) \\\n\t\t\t|| (arr->nd > 1 &&\t\t\t\t\\\n\t\t\t ((flags & FORTRAN) && (!(arrflags & FORTRAN)))) \\\n\t\t\t|| ((flags & WRITEABLE) && (!(arrflags & WRITEABLE)));\n\t\t\n\t\tif (copy) {\n if ((flags & UPDATEIFCOPY) && \\\n (!PyArray_ISWRITEABLE(arr))) {\n\t\t\t\tPy_DECREF(newtype);\n PyErr_SetString(PyExc_ValueError, msg);\n return NULL;\n }\n if ((flags & ENSUREARRAY) && \\\n (subtype != &PyBigArray_Type)) {\n subtype = &PyArray_Type;\n }\n\t\t\tret = (PyArrayObject *) \\\n\t\t\t\tPyArray_NewFromDescr(subtype, newtype,\n\t\t\t\t\t\t arr->nd, \n\t\t\t\t\t\t arr->dimensions,\n\t\t\t\t\t\t NULL, NULL, \n\t\t\t\t\t\t flags & FORTRAN,\n\t\t\t\t\t\t (PyObject *)arr);\n if (ret == NULL) return NULL;\n\t\t\tif (PyArray_CopyInto(ret, arr) == -1) \n\t\t\t\t{Py_DECREF(ret); return NULL;}\n\t\t\tif (flags & UPDATEIFCOPY) {\n\t\t\t\tret->flags |= UPDATEIFCOPY;\n\t\t\t\tret->base = (PyObject *)arr;\n PyArray_FLAGS(ret->base) &= ~WRITEABLE;\n\t\t\t\tPy_INCREF(arr);\n\t\t\t}\n\t\t} \n\t\t/* If no copy then just increase the reference\n\t\t count and return the input */\n\t\telse { \n if ((flags & ENSUREARRAY) && \\\n (subtype != &PyBigArray_Type)) {\n\t\t\t\tPy_DECREF(newtype);\n\t\t\t\tPy_INCREF(arr->descr);\n\t\t\t\tret = (PyArrayObject *)\t\t\t\\\n PyArray_NewFromDescr(&PyArray_Type,\n\t\t\t\t\t\t\t arr->descr,\n\t\t\t\t\t\t\t arr->nd,\n\t\t\t\t\t\t\t arr->dimensions,\n\t\t\t\t\t\t\t arr->strides,\n\t\t\t\t\t\t\t arr->data,\n\t\t\t\t\t\t\t arr->flags,NULL);\n if (ret == NULL) return NULL;\n ret->base = (PyObject *)arr;\n }\n else {\n ret = arr;\n }\n\t\t\tPy_INCREF(arr);\n\t\t}\n\t}\n\t\n\t/* The desired output type is different than the input\n\t array type */\n\telse {\n\t\t/* Cast to the desired type if we can do it safely\n\t\t Also cast if source is a ndim-0 array to mimic\n\t\t behavior with Python scalars */\n\t\tif (flags & FORCECAST || PyArray_NDIM(arr)==0 ||\n\t\t PyArray_CanCastTo(oldtype, newtype)) {\n if ((flags & UPDATEIFCOPY) &&\t\t\\\n (!PyArray_ISWRITEABLE(arr))) {\n\t\t\t\tPy_DECREF(newtype);\n PyErr_SetString(PyExc_ValueError, msg);\n return NULL;\n }\n if ((flags & ENSUREARRAY) && \\\n (subtype != &PyBigArray_Type)) {\n subtype = &PyArray_Type;\n }\n ret = (PyArrayObject *)\\\n PyArray_NewFromDescr(subtype, \n\t\t\t\t\t\t newtype, \n\t\t\t\t\t\t arr->nd,\n\t\t\t\t\t\t arr->dimensions, \n\t\t\t\t\t\t NULL, NULL, \n\t\t\t\t\t\t flags & FORTRAN,\n\t\t\t\t\t\t (PyObject *)arr);\n if (ret == NULL) return NULL;\n if (PyArray_CastTo(ret, arr) < 0) {\n Py_DECREF(ret);\n return NULL;\n }\n\t\t\tif (flags & UPDATEIFCOPY) {\n\t\t\t\tret->flags |= UPDATEIFCOPY;\n\t\t\t\tret->base = (PyObject *)arr;\n PyArray_FLAGS(ret->base) &= ~WRITEABLE;\n\t\t\t\tPy_INCREF(arr);\n\t\t\t}\n\t\t}\n\t\telse {\n\t\t\tPyErr_SetString(PyExc_TypeError, \n\t\t\t\t\t\"array cannot be safely cast \" \\\n\t\t\t\t\t\"to required type\");\n\t\t\tret = NULL;\n\t\t}\n\t}\n\treturn (PyObject *)ret;\n}\n\n/* new reference */\nstatic PyArray_Descr *\n_array_typedescr_fromstr(char *str)\n{\n\tPyArray_Descr *descr; \n\tint type_num;\n\tchar typechar;\n\tint size;\n\tchar msg[] = \"unsupported typestring\";\n\tint swap;\n\tchar swapchar;\n\n\tswapchar = str[0];\n\tstr += 1;\n\t\n#define _MY_FAIL {\t\t\t\t \\\n\t\tPyErr_SetString(PyExc_ValueError, msg); \\\n\t\treturn NULL;\t\t\t\t\\\n\t}\t\t\n\t\n\ttypechar = str[0];\n\tsize = atoi(str + 1);\n\tswitch (typechar) {\n\tcase 'b':\n\t\tif (size == sizeof(Bool))\n\t\t\ttype_num = PyArray_BOOL;\t \n\t\telse _MY_FAIL \n\t\t\tbreak;\t\t \n\tcase 'u':\n\t\tif (size == sizeof(uintp))\n\t\t\ttype_num = PyArray_UINTP;\n\t\telse if (size == sizeof(char))\n\t\t\ttype_num = PyArray_UBYTE;\n\t\telse if (size == sizeof(short)) \n\t\t\ttype_num = PyArray_USHORT;\n\t\telse if (size == sizeof(ulong)) \n\t\t\ttype_num = PyArray_ULONG;\n\t\telse if (size == sizeof(int)) \n\t\t\ttype_num = PyArray_UINT;\n\t\telse if (size == sizeof(ulonglong))\n\t\t\ttype_num = PyArray_ULONGLONG;\n\t\telse _MY_FAIL\n\t\t\tbreak;\t\t \n\tcase 'i':\n\t\tif (size == sizeof(intp))\n\t\t\ttype_num = PyArray_INTP;\n\t\telse if (size == sizeof(char)) \n\t\t type_num = PyArray_BYTE;\n\t\telse if (size == sizeof(short)) \n\t\t\ttype_num = PyArray_SHORT;\n\t\telse if (size == sizeof(long)) \n\t\t\ttype_num = PyArray_LONG;\n\t\telse if (size == sizeof(int))\n\t\t\ttype_num = PyArray_INT;\n\t\telse if (size == sizeof(longlong))\n\t\t\ttype_num = PyArray_LONGLONG;\n\t\telse _MY_FAIL\n\t\t\tbreak;\t\t \n\tcase 'f':\n\t\tif (size == sizeof(float))\n\t\t\ttype_num = PyArray_FLOAT;\n\t\telse if (size == sizeof(double))\n\t\t\ttype_num = PyArray_DOUBLE;\n\t\telse if (size == sizeof(longdouble))\n\t\t\ttype_num = PyArray_LONGDOUBLE;\n\t\telse _MY_FAIL\n\t\t\tbreak;\n\tcase 'c':\n\t\tif (size == sizeof(float)*2)\n\t\t\ttype_num = PyArray_CFLOAT;\n\t\telse if (size == sizeof(double)*2)\n\t\t\ttype_num = PyArray_CDOUBLE;\n\t\telse if (size == sizeof(longdouble)*2)\n\t\t\ttype_num = PyArray_CLONGDOUBLE;\n\t\telse _MY_FAIL\n\t\t\tbreak;\n\tcase 'O':\n\t\tif (size == sizeof(PyObject *))\n\t\t\ttype_num = PyArray_OBJECT;\n\t\telse _MY_FAIL\n\t\t\tbreak;\n\tcase 'S':\n\t\ttype_num = PyArray_STRING;\n\t\tbreak;\n\tcase 'U':\n\t\ttype_num = PyArray_UNICODE;\n\t\tsize *= sizeof(Py_UNICODE);\n\t\tbreak;\t \n\tcase 'V':\n\t\ttype_num = PyArray_VOID;\n\t\tbreak;\n\tdefault:\n\t\t_MY_FAIL\n\t}\n\t\n#undef _MY_FAIL\n\n descr = PyArray_DescrFromType(type_num);\n if (descr == NULL) return NULL;\n swap = !PyArray_ISNBO(swapchar);\n if (descr->elsize == 0 || swap) {\n\t /* Need to make a new PyArray_Descr */\n\t PyArray_DESCR_REPLACE(descr);\n\t if (descr==NULL) return NULL;\n\t if (descr->elsize == 0)\n\t\t descr->elsize = size;\n\t if (swap) \n\t\t descr->byteorder = swapchar;\n }\n return descr;\n}\n\n/* OBJECT_API */\nstatic PyObject *\nPyArray_FromStructInterface(PyObject *input)\n{\n\tPyArray_Descr *thetype;\n\tchar buf[40];\n\tPyArrayInterface *inter;\n\tPyObject *attr, *r;\n\tchar endian = PyArray_NATBYTE;\n \n attr = PyObject_GetAttrString(input, \"__array_struct__\");\n if (attr == NULL) {\n\t\tPyErr_Clear();\n\t\treturn Py_NotImplemented;\n\t}\n if (!PyCObject_Check(attr) || \\\n ((inter=((PyArrayInterface *)\\\n\t\t PyCObject_AsVoidPtr(attr)))->version != 2)) {\n PyErr_SetString(PyExc_ValueError, \"invalid __array_struct__\");\n\t\tPy_DECREF(attr);\n return NULL;\n }\n\tif ((inter->flags & NOTSWAPPED) != NOTSWAPPED) {\n\t\tendian = PyArray_OPPBYTE;\n\t\tinter->flags &= ~NOTSWAPPED;\n\t}\n\n snprintf(buf, 40, \"%c%c%d\", endian, inter->typekind, inter->itemsize);\n if (!(thetype=_array_typedescr_fromstr(buf))) {\n\t\tPy_DECREF(attr);\n return NULL;\n }\n\n r = PyArray_NewFromDescr(&PyArray_Type, thetype,\n\t\t\t\t inter->nd, inter->shape,\n\t\t\t\t inter->strides, inter->data,\n\t\t\t\t inter->flags, NULL);\n\tPy_INCREF(input);\n\tPyArray_BASE(r) = input;\n Py_DECREF(attr);\n PyArray_UpdateFlags((PyArrayObject *)r, UPDATE_ALL_FLAGS);\n return r;\n}\n\n/*OBJECT_API*/\nstatic PyObject *\nPyArray_FromInterface(PyObject *input)\n{\n\tPyObject *attr=NULL, *item=NULL;\n PyObject *tstr=NULL, *shape=NULL; \n PyArrayObject *ret;\n\tPyArray_Descr *type=NULL;\n\tchar *data;\n\tint buffer_len;\n\tint res, i, n;\n\tintp dims[MAX_DIMS], strides[MAX_DIMS];\n\tint dataflags = BEHAVED_FLAGS;\n\n\t/* Get the memory from __array_data__ and __array_offset__ */\n\t/* Get the shape */\n\t/* Get the typestring -- ignore array_descr */\n\t/* Get the strides */\n\t\n shape = PyObject_GetAttrString(input, \"__array_shape__\");\n if (shape == NULL) {PyErr_Clear(); return Py_NotImplemented;}\n tstr = PyObject_GetAttrString(input, \"__array_typestr__\");\n if (tstr == NULL) {Py_DECREF(shape); PyErr_Clear(); return Py_NotImplemented;}\n \n\tattr = PyObject_GetAttrString(input, \"__array_data__\");\n\tif ((attr == NULL) || (attr==Py_None) || (!PyTuple_Check(attr))) {\n\t\tif (attr && (attr != Py_None)) item=attr;\n\t\telse item=input;\n\t\tres = PyObject_AsWriteBuffer(item, (void **)&data, \n\t\t\t\t\t &buffer_len);\n\t\tif (res < 0) {\n\t\t\tPyErr_Clear();\n\t\t\tres = PyObject_AsReadBuffer(item, (const void **)&data,\n\t\t\t\t\t\t &buffer_len);\n\t\t\tif (res < 0) goto fail;\n\t\t\tdataflags &= ~WRITEABLE;\n\t\t}\n\t\tPy_XDECREF(attr);\n\t\tattr = PyObject_GetAttrString(input, \"__array_offset__\");\n\t\tif (attr) {\n\t\t\tlong num = PyInt_AsLong(attr);\n\t\t\tif (error_converting(num)) {\n\t\t\t\tPyErr_SetString(PyExc_TypeError, \n\t\t\t\t\t\t\"__array_offset__ \"\\\n\t\t\t\t\t\t\"must be an integer\");\n\t\t\t\tgoto fail;\n\t\t\t}\n\t\t\tdata += num;\n\t\t}\n\t\telse PyErr_Clear();\n\t}\n\telse {\n\t\tif (PyTuple_GET_SIZE(attr) != 2) {\n\t\t\tPyErr_SetString(PyExc_TypeError, \n\t\t\t\t\t\"__array_data__ must return \"\t\\\n\t\t\t\t\t\"a 2-tuple with ('data pointer \"\\\n\t\t\t\t\t\"string', read-only flag)\");\n\t\t\tgoto fail;\n\t\t}\n\t\tres = sscanf(PyString_AsString(PyTuple_GET_ITEM(attr,0)),\n\t\t\t \"%p\", (void **)&data);\n\t\tif (res < 1) {\n\t\t\tPyErr_SetString(PyExc_TypeError, \n\t\t\t\t\t\"__array_data__ string cannot be \" \\\n\t\t\t\t\t\"converted\");\n\t\t\tgoto fail;\n\t\t}\n\t\tif (PyObject_IsTrue(PyTuple_GET_ITEM(attr,1))) {\n\t\t\tdataflags &= ~WRITEABLE;\n\t\t}\n\t}\n\tPy_XDECREF(attr);\n\tattr = tstr;\n\tif (!PyString_Check(attr)) {\n\t\tPyErr_SetString(PyExc_TypeError, \"__array_typestr__ must be a string\");\n\t\tPy_INCREF(attr); /* decref'd twice below */\n\t\tgoto fail;\n\t}\n\ttype = _array_typedescr_fromstr(PyString_AS_STRING(attr)); \n\tPy_DECREF(attr); attr=NULL; tstr=NULL;\n\tif (type==NULL) goto fail;\n\tattr = shape;\n\tif (!PyTuple_Check(attr)) {\n\t\tPyErr_SetString(PyExc_TypeError, \"__array_shape__ must be a tuple\");\n\t\tPy_INCREF(attr); /* decref'd twice below */\n\t\tPy_DECREF(type);\n\t\tgoto fail;\n\t}\n\tn = PyTuple_GET_SIZE(attr);\n\tfor (i=0; ibase = input;\n \n\tattr = PyObject_GetAttrString(input, \"__array_strides__\");\n\tif (attr != NULL && attr != Py_None) {\n\t\tif (!PyTuple_Check(attr)) {\n\t\t\tPyErr_SetString(PyExc_TypeError, \n\t\t\t\t\t\"__array_strides__ must be a tuple\");\n\t\t\tPy_DECREF(attr);\n\t\t\tPy_DECREF(ret);\n\t\t\treturn NULL;\n\t\t}\n\t\tif (n != PyTuple_GET_SIZE(attr)) {\n\t\t\tPyErr_SetString(PyExc_ValueError, \n\t\t\t\t\t\"mismatch in length of \"\\\n\t\t\t\t\t\"__array_strides__ and \"\\\n\t\t\t\t\t\"__array_shape__\");\n\t\t\tPy_DECREF(attr);\n\t\t\tPy_DECREF(ret);\n\t\t\treturn NULL;\n\t\t}\n\t\tfor (i=0; istrides, strides, n*sizeof(intp));\n\t}\n\telse PyErr_Clear();\n\tPyArray_UpdateFlags(ret, UPDATE_ALL_FLAGS);\n\treturn (PyObject *)ret;\n\n fail:\n\tPy_XDECREF(attr);\n\tPy_XDECREF(shape);\n\tPy_XDECREF(tstr);\n\treturn NULL;\n}\n\n/* OBJECT_API*/\nstatic PyObject *\nPyArray_FromArrayAttr(PyObject *op, PyArray_Descr *typecode, PyObject *context) \n{\n PyObject *new;\n PyObject *array_meth;\n\n array_meth = PyObject_GetAttrString(op, \"__array__\");\n if (array_meth == NULL) {PyErr_Clear(); return Py_NotImplemented;}\n if (context == NULL) {\n if (typecode == NULL) new = PyObject_CallFunction(array_meth, NULL);\n else new = PyObject_CallFunction(array_meth, \"O\", typecode);\n }\n else {\n if (typecode == NULL) {\n new = PyObject_CallFunction(array_meth, \"OO\", Py_None, context);\n if (new == NULL && PyErr_ExceptionMatches(PyExc_TypeError)) {\n PyErr_Clear();\n new = PyObject_CallFunction(array_meth, \"\");\n }\n }\n else {\n new = PyObject_CallFunction(array_meth, \"OO\", typecode, context);\n if (new == NULL && PyErr_ExceptionMatches(PyExc_TypeError)) {\n PyErr_Clear();\n new = PyObject_CallFunction(array_meth, \"O\", typecode);\n }\n }\n }\n Py_DECREF(array_meth);\n if (new == NULL) return NULL;\n if (!PyArray_Check(new)) {\n PyErr_SetString(PyExc_ValueError, \n \"object __array__ method not \" \\\n \"producing an array\");\n Py_DECREF(new);\n return NULL;\n }\n return new;\n} \n\n/* Does not check for ENSURECOPY and NOTSWAPPED in flags */\n/* Steals a reference to newtype --- which can be NULL */\n/*OBJECT_API*/\nstatic PyObject *\nPyArray_FromAny(PyObject *op, PyArray_Descr *newtype, int min_depth, \n int max_depth, int flags, PyObject *context) \n{\n /* This is the main code to make a NumPy array from a Python\n Object. It is called from lot's of different places which\n is why there are so many checks. The comments try to\n explain some of the checks. */\n\n PyObject *r=NULL;\n int seq = FALSE;\n \n\t/* Is input object already an array? */\n\t/* This is where the flags are used */\n if (PyArray_Check(op)) \n\t\tr = PyArray_FromArray((PyArrayObject *)op, newtype, flags);\n\telse if (PyArray_IsScalar(op, Generic)) {\n\t\tr = PyArray_FromScalar(op, newtype);\n\t}\n else if (((r = PyArray_FromStructInterface(op))!=Py_NotImplemented)|| \\\n ((r = PyArray_FromInterface(op)) != Py_NotImplemented) || \\\n ((r = PyArray_FromArrayAttr(op, newtype, context)) \\\n != Py_NotImplemented)) {\n PyObject *new;\n if (r == NULL) return NULL;\n if (newtype != NULL || flags != 0) {\n new = PyArray_FromArray((PyArrayObject *)r, newtype, flags);\n Py_DECREF(r);\n r = new;\n }\n }\n\telse {\n\t\tif (newtype == NULL) {\n\t\t\tnewtype = _array_find_type(op, NULL, MAX_DIMS);\n\t\t}\n\t\tif (PySequence_Check(op)) {\n\t\t\t/* necessary but not sufficient */\n\t\t\t\n\t\t\tr = Array_FromSequence(op, newtype, flags & FORTRAN,\n\t\t\t\t\t min_depth, max_depth);\n\t\t\tif (PyErr_Occurred() && r == NULL)\n /* It wasn't really a sequence after all.\n * Try interpreting it as a scalar */\n PyErr_Clear();\n else\n seq = TRUE;\n }\n if (!seq)\n\t\t\tr = Array_FromScalar(op, newtype);\n\t}\n\n /* If we didn't succeed return NULL */\n if (r == NULL) return NULL;\n\t\n\t/* Be sure we succeed here */\n\t\n if(!PyArray_Check(r)) {\n PyErr_SetString(PyExc_RuntimeError, \n\t\t\t\t\"internal error: PyArray_FromAny \"\\\n\t\t\t\t\"not producing an array\");\n\t\tPy_DECREF(r);\n return NULL;\n }\n\n if (min_depth != 0 && ((PyArrayObject *)r)->nd < min_depth) {\n PyErr_SetString(PyExc_ValueError, \n \"object of too small depth for desired array\");\n Py_DECREF(r);\n return NULL;\n }\n if (max_depth != 0 && ((PyArrayObject *)r)->nd > max_depth) {\n PyErr_SetString(PyExc_ValueError, \n \"object too deep for desired array\");\n Py_DECREF(r);\n return NULL;\n }\n return r;\n}\n\n/* new reference -- accepts NULL for mintype*/\n/*OBJECT_API*/\nstatic PyArray_Descr *\nPyArray_DescrFromObject(PyObject *op, PyArray_Descr *mintype)\n{\n\treturn _array_find_type(op, mintype, MAX_DIMS);\n}\n\n/*OBJECT_API\n Return the typecode of the array a Python object would be converted\n to\n*/\nstatic int \nPyArray_ObjectType(PyObject *op, int minimum_type) \n{\n\tPyArray_Descr *intype;\n\tPyArray_Descr *outtype;\n\tint ret;\n\n\tintype = PyArray_DescrFromType(minimum_type);\n\tif (intype == NULL) PyErr_Clear();\n\touttype = _array_find_type(op, intype, MAX_DIMS);\n\tret = outtype->type_num;\n\tPy_DECREF(outtype);\n\tPy_DECREF(intype);\n\treturn ret;\n}\n\n\n/* flags is any of \n CONTIGUOUS, \n FORTRAN,\n ALIGNED, \n WRITEABLE, \n NOTSWAPPED,\n ENSURECOPY, \n UPDATEIFCOPY,\n FORCECAST,\n ENSUREARRAY\n\n or'd (|) together\n\n Any of these flags present means that the returned array should \n guarantee that aspect of the array. Otherwise the returned array\n won't guarantee it -- it will depend on the object as to whether or \n not it has such features. \n\n Note that ENSURECOPY is enough\n to guarantee CONTIGUOUS, ALIGNED and WRITEABLE\n and therefore it is redundant to include those as well. \n\n BEHAVED_FLAGS == ALIGNED | WRITEABLE\n CARRAY_FLAGS = CONTIGUOUS | BEHAVED_FLAGS\n FARRAY_FLAGS = FORTRAN | BEHAVED_FLAGS\n \n FORTRAN can be set in the FLAGS to request a FORTRAN array. \n Fortran arrays are always behaved (aligned, \n notswapped, and writeable) and not (C) CONTIGUOUS (if > 1d). \n\n UPDATEIFCOPY flag sets this flag in the returned array if a copy is\n made and the base argument points to the (possibly) misbehaved array.\n When the new array is deallocated, the original array held in base\n is updated with the contents of the new array. \n\n FORCECAST will cause a cast to occur regardless of whether or not\n it is safe. \n*/\n\n\n/* steals a reference to descr -- accepts NULL */\n/*OBJECT_API*/\nstatic PyObject *\nPyArray_CheckFromAny(PyObject *op, PyArray_Descr *descr, int min_depth, \n int max_depth, int requires, PyObject *context) \n{\n\tif (requires & NOTSWAPPED) {\n\t\tif (!descr && PyArray_Check(op) && \\\n\t\t !PyArray_ISNBO(PyArray_DESCR(op)->byteorder)) {\n\t\t\tdescr = PyArray_DescrNew(PyArray_DESCR(op));\n\t\t}\n\t\telse if ((descr && !PyArray_ISNBO(descr->byteorder))) {\n\t\t\tPyArray_DESCR_REPLACE(descr);\n\t\t}\n\t\tdescr->byteorder = PyArray_NATIVE;\n\t}\n\n\treturn PyArray_FromAny(op, descr, min_depth, max_depth,\n requires, context);\n}\n\n/* This is a quick wrapper around PyArray_FromAny(op, NULL, 0, 0, \n ENSUREARRAY) */\n/* that special cases Arrays and PyArray_Scalars up front */\n/* It *steals a reference* to the object */\n/* It also guarantees that the result is PyArray_Type or PyBigArray_Type */\n\n/* Because it decrefs op if any conversion needs to take place \n so it can be used like PyArray_EnsureArray(some_function(...)) */\n\n/*OBJECT_API*/\nstatic PyObject *\nPyArray_EnsureArray(PyObject *op)\n{\n PyObject *new;\n\n if (op == NULL) return NULL;\n\n if (PyArray_CheckExact(op) || PyBigArray_CheckExact(op)) return op;\n \n if (PyArray_IsScalar(op, Generic)) {\n new = PyArray_FromScalar(op, NULL);\n Py_DECREF(op);\n return new;\n }\n new = PyArray_FromAny(op, NULL, 0, 0, ENSUREARRAY, NULL);\n Py_DECREF(op);\n return new;\n}\n\n/*OBJECT_API\n Check the type coercion rules.\n*/\nstatic int \nPyArray_CanCastSafely(int fromtype, int totype) \n{\n\tPyArray_Descr *from, *to;\n\tregister int felsize, telsize;\n\n if (fromtype == totype) return 1;\n if (fromtype == PyArray_BOOL) return 1;\n\tif (totype == PyArray_BOOL) return 0;\n if (totype == PyArray_OBJECT || totype == PyArray_VOID) return 1;\n\tif (fromtype == PyArray_OBJECT || fromtype == PyArray_VOID) return 0;\n\n\tfrom = PyArray_DescrFromType(fromtype);\n\tto = PyArray_DescrFromType(totype);\n\ttelsize = to->elsize;\n\tfelsize = from->elsize;\n\tPy_DECREF(from);\n\tPy_DECREF(to);\n\n switch(fromtype) {\n case PyArray_BYTE:\n\tcase PyArray_SHORT:\n case PyArray_INT:\n case PyArray_LONG:\n\tcase PyArray_LONGLONG:\n\t\tif (PyTypeNum_ISINTEGER(totype)) {\n\t\t\tif (PyTypeNum_ISUNSIGNED(totype)) {\n\t\t\t\treturn (telsize > felsize);\n\t\t\t}\n\t\t\telse {\n\t\t\t\treturn (telsize >= felsize);\n\t\t\t}\n\t\t}\n\t\telse if (PyTypeNum_ISFLOAT(totype)) {\n if (felsize < 8)\n return (telsize > felsize);\n else\n return (telsize >= felsize);\n\t\t}\n\t\telse if (PyTypeNum_ISCOMPLEX(totype)) {\n if (felsize < 8)\n return ((telsize >> 1) > felsize);\n else\n return ((telsize >> 1) >= felsize);\n\t\t}\n\t\telse return totype > fromtype;\n case PyArray_UBYTE:\n case PyArray_USHORT:\n case PyArray_UINT:\n\tcase PyArray_ULONG:\n\tcase PyArray_ULONGLONG:\n\t\tif (PyTypeNum_ISINTEGER(totype)) {\n\t\t\tif (PyTypeNum_ISSIGNED(totype)) {\n\t\t\t\treturn (telsize > felsize);\n\t\t\t}\n\t\t\telse {\n\t\t\t\treturn (telsize >= felsize);\n\t\t\t}\n\t\t}\n\t\telse if (PyTypeNum_ISFLOAT(totype)) {\n if (felsize < 8)\n return (telsize > felsize);\n else\n return (telsize >= felsize);\n\t\t}\n\t\telse if (PyTypeNum_ISCOMPLEX(totype)) {\n if (felsize < 8)\n return ((telsize >> 1) > felsize);\n else\n return ((telsize >> 1) >= felsize);\n\t\t}\n\t\telse return totype > fromtype;\n case PyArray_FLOAT:\n case PyArray_DOUBLE:\n\tcase PyArray_LONGDOUBLE:\n\t\tif (PyTypeNum_ISCOMPLEX(totype)) \n\t\t\treturn ((telsize >> 1) >= felsize);\n\t\telse\n\t\t\treturn (totype > fromtype);\n case PyArray_CFLOAT:\n case PyArray_CDOUBLE:\n\tcase PyArray_CLONGDOUBLE:\n\t\treturn (totype > fromtype);\n\tcase PyArray_STRING:\n\tcase PyArray_UNICODE:\n\t\treturn (totype > fromtype);\n default:\n return 0;\n }\n}\n\n/* leaves reference count alone --- cannot be NULL*/\n/*OBJECT_API*/\nstatic Bool\nPyArray_CanCastTo(PyArray_Descr *from, PyArray_Descr *to)\n{\n\tint fromtype=from->type_num;\n\tint totype=to->type_num;\n\tBool ret;\n\n\tret = (Bool) PyArray_CanCastSafely(fromtype, totype);\n\tif (ret) { /* Check String and Unicode more closely */\n\t\tif (fromtype == PyArray_STRING) {\n\t\t\tif (totype == PyArray_STRING) {\n\t\t\t\tret = (from->elsize <= to->elsize);\n\t\t\t}\n\t\t\telse if (totype == PyArray_UNICODE) {\n\t\t\t\tret = (from->elsize * sizeof(Py_UNICODE)\\\n\t\t\t\t <= to->elsize);\n\t\t\t}\n\t\t}\n\t\telse if (fromtype == PyArray_UNICODE) {\n\t\t\tif (totype == PyArray_UNICODE) {\n\t\t\t\tret = (from->elsize <= to->elsize);\n\t\t\t}\n\t\t}\n\t\t/* TODO: If totype is STRING or unicode \n\t\t see if the length is long enough to hold the\n\t\t stringified value of the object.\t\t \n\t\t*/\n\t}\n\treturn ret;\n}\n\n\n\n/*********************** Element-wise Array Iterator ***********************/\n/* Aided by Peter J. Verveer's nd_image package and numpy's arraymap ****/\n/* and Python's array iterator ***/\n \n\n/*OBJECT_API\n Get Iterator.\n*/\nstatic PyObject *\nPyArray_IterNew(PyObject *obj)\n{\n PyArrayIterObject *it;\n\tint i, nd; \n\tPyArrayObject *ao = (PyArrayObject *)obj;\n\n if (!PyArray_Check(ao)) {\n PyErr_BadInternalCall();\n return NULL;\n }\n\n it = (PyArrayIterObject *)_pya_malloc(sizeof(PyArrayIterObject));\n PyObject_Init((PyObject *)it, &PyArrayIter_Type);\n /* it = PyObject_New(PyArrayIterObject, &PyArrayIter_Type);*/\n if (it == NULL)\n return NULL;\n\n\tnd = ao->nd;\n\tPyArray_UpdateFlags(ao, CONTIGUOUS);\n\tit->contiguous = 0;\n\tif PyArray_ISCONTIGUOUS(ao) it->contiguous = 1;\n Py_INCREF(ao);\n it->ao = ao;\n\tit->size = PyArray_SIZE(ao);\n\tit->nd_m1 = nd - 1;\n\tit->factors[nd-1] = 1;\n\tfor (i=0; i < nd; i++) {\n\t\tit->dims_m1[i] = it->ao->dimensions[i] - 1;\n\t\tit->strides[i] = it->ao->strides[i];\n\t\tit->backstrides[i] = it->strides[i] *\t\\\n\t\t\tit->dims_m1[i];\n\t\tif (i > 0)\n\t\t\tit->factors[nd-i-1] = it->factors[nd-i] *\t\\\n\t\t\t\tit->ao->dimensions[nd-i];\n\t}\n\tPyArray_ITER_RESET(it);\n\t\n return (PyObject *)it;\n}\n\n\n/*OBJECT_API\n Get Iterator that iterates over all but one axis (don't use this with\n PyArray_ITER_GOTO1D) \n*/\nstatic PyObject *\nPyArray_IterAllButAxis(PyObject *obj, int axis)\n{\n\tPyArrayIterObject *it;\n\tit = (PyArrayIterObject *)PyArray_IterNew(obj);\n\tif (it == NULL) return NULL;\n\t\n\t/* adjust so that will not iterate over axis */\n\tit->contiguous = 0;\n\tif (it->size != 0) {\n\t\tit->size /= PyArray_DIM(obj,axis);\n\t}\n\tit->dims_m1[axis] = 0;\n\tit->backstrides[axis] = 0;\n\t\n\t/* (won't fix factors so don't use\n\t PyArray_ITER_GOTO1D with this iterator) */\n\treturn (PyObject *)it;\n}\n\n/* Returns an array scalar holding the element desired */\n\nstatic PyObject *\narrayiter_next(PyArrayIterObject *it)\n{\n\tPyObject *ret;\n\n\tif (it->index < it->size) {\n\t\tret = PyArray_ToScalar(it->dataptr, it->ao);\n\t\tPyArray_ITER_NEXT(it);\n\t\treturn ret;\n\t}\n return NULL;\n}\n\nstatic void\narrayiter_dealloc(PyArrayIterObject *it)\n{\n Py_XDECREF(it->ao);\n _pya_free(it);\n}\n\nstatic int\niter_length(PyArrayIterObject *self) \n{\n return (int) self->size;\n}\n\n\nstatic PyObject *\niter_subscript_Bool(PyArrayIterObject *self, PyArrayObject *ind)\n{\n\tint index, strides, itemsize;\n\tintp count=0;\n\tchar *dptr, *optr;\n\tPyObject *r;\n\tint swap;\n PyArray_CopySwapFunc *copyswap;\n\n\n\tif (ind->nd != 1) {\n\t\tPyErr_SetString(PyExc_ValueError, \n\t\t\t\t\"boolean index array should have 1 dimension\");\n\t\treturn NULL;\n\t}\n\tindex = (ind->dimensions[0]);\n\tstrides = ind->strides[0];\n\tdptr = ind->data;\n\t/* Get size of return array */\n\twhile(index--) {\n\t\tif (*((Bool *)dptr) != 0)\n\t\t\tcount++;\n\t\tdptr += strides;\n\t}\n\titemsize = self->ao->descr->elsize;\n\tPy_INCREF(self->ao->descr);\n\tr = PyArray_NewFromDescr(self->ao->ob_type,\n\t\t\t\t self->ao->descr, 1, &count, \n\t\t\t\t NULL, NULL,\n\t\t\t\t 0, (PyObject *)self->ao);\n\tif (r==NULL) return NULL;\n\n\t/* Set up loop */\n\toptr = PyArray_DATA(r);\n\tindex = ind->dimensions[0];\n\tdptr = ind->data;\n\n copyswap = self->ao->descr->f->copyswap;\n\t/* Loop over Boolean array */\n\tswap = !(PyArray_ISNOTSWAPPED(self->ao));\n\twhile(index--) {\n\t\tif (*((Bool *)dptr) != 0) {\n copyswap(optr, self->dataptr, swap, itemsize);\n\t\t\toptr += itemsize;\n\t\t}\n\t\tdptr += strides;\n\t\tPyArray_ITER_NEXT(self);\n\t}\n\tPyArray_ITER_RESET(self);\n\treturn r;\n}\n\nstatic PyObject *\niter_subscript_int(PyArrayIterObject *self, PyArrayObject *ind)\n{\n\tintp num;\n\tPyObject *r;\n\tPyArrayIterObject *ind_it;\n\tint itemsize;\n\tint swap;\n\tchar *optr;\n\tint index;\n PyArray_CopySwapFunc *copyswap;\n\n\titemsize = self->ao->descr->elsize;\n\tif (ind->nd == 0) {\n\t\tnum = *((intp *)ind->data);\n\t\tPyArray_ITER_GOTO1D(self, num);\n\t\tr = PyArray_ToScalar(self->dataptr, self->ao);\n\t\tPyArray_ITER_RESET(self);\n\t\treturn r;\n\t}\n\t\n\tPy_INCREF(self->ao->descr);\n\tr = PyArray_NewFromDescr(self->ao->ob_type, self->ao->descr, \n\t\t\t\t ind->nd, ind->dimensions,\n\t\t\t\t NULL, NULL, \n\t\t\t\t 0, (PyObject *)self->ao);\n\tif (r==NULL) return NULL;\n\n\toptr = PyArray_DATA(r);\n\tind_it = (PyArrayIterObject *)PyArray_IterNew((PyObject *)ind);\n\tif (ind_it == NULL) {Py_DECREF(r); return NULL;}\n\tindex = ind_it->size;\n copyswap = PyArray_DESCR(r)->f->copyswap;\n swap = !PyArray_ISNOTSWAPPED(self->ao);\n\twhile(index--) {\n\t\tnum = *((intp *)(ind_it->dataptr));\n\t\tif (num < 0) num += self->size;\n\t\tif (num < 0 || num >= self->size) {\n\t\t\tPyErr_Format(PyExc_IndexError,\n\t\t\t\t \"index %d out of bounds\"\t\t\\\n\t\t\t\t \" 0<=index<%d\", (int) num, \n\t\t\t\t (int) self->size);\n\t\t\tPy_DECREF(ind_it);\n\t\t\tPy_DECREF(r);\n\t\t\tPyArray_ITER_RESET(self);\n\t\t\treturn NULL;\n\t\t}\n\t\tPyArray_ITER_GOTO1D(self, num);\n copyswap(optr, self->dataptr, swap, itemsize);\n\t\toptr += itemsize;\n\t\tPyArray_ITER_NEXT(ind_it);\n\t}\n\tPy_DECREF(ind_it);\n\tPyArray_ITER_RESET(self);\n\treturn r;\n}\n\n\nstatic PyObject *\niter_subscript(PyArrayIterObject *self, PyObject *ind)\n{\n\tPyArray_Descr *indtype=NULL;\n\tintp start, step_size;\n\tintp n_steps;\n\tPyObject *r;\n\tchar *dptr;\n\tint size;\n\tPyObject *obj = NULL;\n\tint swap;\n PyArray_CopySwapFunc *copyswap;\n\n\tif (ind == Py_Ellipsis) {\n\t\tind = PySlice_New(NULL, NULL, NULL);\n\t\tobj = iter_subscript(self, ind);\n\t\tPy_DECREF(ind);\n\t\treturn obj;\n\t}\n\tif (PyTuple_Check(ind)) {\n\t\tint len;\n\t\tlen = PyTuple_GET_SIZE(ind);\n\t\tif (len > 1) goto fail;\n\t\tind = PyTuple_GET_ITEM(ind, 0);\n\t}\n\n\t/* Tuples >1d not accepted --- i.e. no newaxis */\n\t/* Could implement this with adjusted strides\n\t and dimensions in iterator */\n\n\t/* Check for Boolean -- this is first becasue\n\t Bool is a subclass of Int */\n\tPyArray_ITER_RESET(self);\n\n\tif (PyBool_Check(ind)) {\n\t\tif (PyObject_IsTrue(ind)) {\n\t\t\treturn PyArray_ToScalar(self->dataptr, self->ao);\n\t\t}\n\t\telse { /* empty array */\n\t\t\tintp ii = 0;\n\t\t\tPy_INCREF(self->ao->descr);\n\t\t\tr = PyArray_NewFromDescr(self->ao->ob_type, \n\t\t\t\t\t\t self->ao->descr,\n\t\t\t\t\t\t 1, &ii, \n\t\t\t\t\t\t NULL, NULL, 0,\n\t\t\t\t\t\t (PyObject *)self->ao);\n\t\t\treturn r;\t\t\t\n\t\t}\n\t}\n\n\t/* Check for Integer or Slice */ \t\n\t\n\tif (PyLong_Check(ind) || PyInt_Check(ind) || PySlice_Check(ind)) {\n\t\tstart = parse_subindex(ind, &step_size, &n_steps, \n\t\t\t\t self->size);\n\t\tif (start == -1) \n\t\t\tgoto fail;\n\t\tif (n_steps == RubberIndex || n_steps == PseudoIndex) {\n\t\t\tPyErr_SetString(PyExc_IndexError, \n\t\t\t\t\t\"cannot use Ellipsis or newaxes here\");\n\t\t\tgoto fail;\n\t\t}\n\t\tPyArray_ITER_GOTO1D(self, start)\n\t\tif (n_steps == SingleIndex) { /* Integer */\n\t\t\tr = PyArray_ToScalar(self->dataptr, self->ao);\n\t\t\tPyArray_ITER_RESET(self);\n\t\t\treturn r;\n\t\t}\n\t\tsize = self->ao->descr->elsize;\n\t\tPy_INCREF(self->ao->descr);\n\t\tr = PyArray_NewFromDescr(self->ao->ob_type, \n\t\t\t\t\t self->ao->descr, \n\t\t\t\t\t 1, &n_steps, \n\t\t\t\t\t NULL, NULL,\n\t\t\t\t\t 0, (PyObject *)self->ao);\n\t\tif (r==NULL) goto fail; \n\t\tdptr = PyArray_DATA(r);\n swap = !PyArray_ISNOTSWAPPED(self->ao);\n copyswap = PyArray_DESCR(r)->f->copyswap;\n\t\twhile(n_steps--) {\n copyswap(dptr, self->dataptr, swap, size);\n\t\t\tstart += step_size;\n\t\t\tPyArray_ITER_GOTO1D(self, start)\n\t\t\tdptr += size;\n\t\t}\n\t\tPyArray_ITER_RESET(self);\n\t\treturn r;\n\t} \n\n\t/* convert to INTP array if Integer array scalar or List */\n\n\tindtype = PyArray_DescrFromType(PyArray_INTP);\n\tif (PyArray_IsScalar(ind, Integer) || PyList_Check(ind)) {\n\t\tPy_INCREF(indtype);\n\t\tobj = PyArray_FromAny(ind, indtype, 0, 0, FORCECAST, NULL);\n\t\tif (obj == NULL) goto fail;\n\t}\n\telse {\n\t\tPy_INCREF(ind);\n\t\tobj = ind;\n\t}\n\t\n\tif (PyArray_Check(obj)) {\n\t\t/* Check for Boolean object */\n\t\tif (PyArray_TYPE(obj)==PyArray_BOOL) {\n\t\t\tr = iter_subscript_Bool(self, (PyArrayObject *)obj);\n\t\t\tPy_DECREF(indtype);\n\t\t} \n\t\t/* Check for integer array */\n\t\telse if (PyArray_ISINTEGER(obj)) {\n\t\t\tPyObject *new;\n\t\t\tnew = PyArray_FromAny(obj, indtype, 0, 0, \n FORCECAST | ALIGNED, NULL);\n\t\t\tif (new==NULL) goto fail;\n Py_DECREF(obj);\n\t\t\tobj = new;\n\t\t\tr = iter_subscript_int(self, (PyArrayObject *)obj);\n\t\t}\n\t\telse {\n\t\t\tgoto fail;\n\t\t}\n\t\tPy_DECREF(obj);\n\t\treturn r;\n\t}\n\telse Py_DECREF(indtype);\n\n\n fail:\n\tif (!PyErr_Occurred())\n\t\tPyErr_SetString(PyExc_IndexError, \"unsupported iterator index\");\n\tPy_XDECREF(indtype);\n\tPy_XDECREF(obj);\n\treturn NULL;\n\n}\n\n\nstatic int\niter_ass_sub_Bool(PyArrayIterObject *self, PyArrayObject *ind,\n\t\t PyArrayIterObject *val, int swap)\n{\n\tint index, strides, itemsize;\n\tchar *dptr;\n PyArray_CopySwapFunc *copyswap;\n\n\tif (ind->nd != 1) {\n\t\tPyErr_SetString(PyExc_ValueError, \n\t\t\t\t\"boolean index array should have 1 dimension\");\n\t\treturn -1;\n\t}\n\titemsize = self->ao->descr->elsize;\n\tindex = ind->dimensions[0];\n\tstrides = ind->strides[0];\n\tdptr = ind->data;\n\tPyArray_ITER_RESET(self);\n\t/* Loop over Boolean array */\n copyswap = self->ao->descr->f->copyswap;\n\twhile(index--) {\n\t\tif (*((Bool *)dptr) != 0) {\n copyswap(self->dataptr, val->dataptr, swap,\n\t\t\t\t itemsize);\n\t\t\tPyArray_ITER_NEXT(val);\n\t\t\tif (val->index==val->size) \n\t\t\t\tPyArray_ITER_RESET(val);\n\t\t}\n\t\tdptr += strides;\n\t\tPyArray_ITER_NEXT(self);\n\t}\n\tPyArray_ITER_RESET(self);\n\treturn 0;\n}\n\nstatic int\niter_ass_sub_int(PyArrayIterObject *self, PyArrayObject *ind,\n\t\t PyArrayIterObject *val, int swap)\n{\n\tPyArray_Descr *typecode;\n\tintp num;\n\tPyArrayIterObject *ind_it;\n\tint itemsize;\n\tint index;\n PyArray_CopySwapFunc *copyswap;\n\n\ttypecode = self->ao->descr;\n\titemsize = typecode->elsize;\n copyswap = self->ao->descr->f->copyswap;\n\tif (ind->nd == 0) {\n\t\tnum = *((intp *)ind->data);\n\t\tPyArray_ITER_GOTO1D(self, num);\n copyswap(self->dataptr, val->dataptr, swap, itemsize);\n\t\treturn 0;\n\t}\n\tind_it = (PyArrayIterObject *)PyArray_IterNew((PyObject *)ind);\n\tif (ind_it == NULL) return -1;\n\tindex = ind_it->size;\n\twhile(index--) {\n\t\tnum = *((intp *)(ind_it->dataptr));\n\t\tif (num < 0) num += self->size;\n\t\tif ((num < 0) || (num >= self->size)) {\n\t\t\tPyErr_Format(PyExc_IndexError,\n\t\t\t\t \"index %d out of bounds\"\t\t\\\n\t\t\t\t \" 0<=index<%d\", (int) num, \n\t\t\t\t (int) self->size);\n\t\t\tPy_DECREF(ind_it);\n\t\t\treturn -1;\n\t\t}\n\t\tPyArray_ITER_GOTO1D(self, num);\n copyswap(self->dataptr, val->dataptr, swap, itemsize);\n\t\tPyArray_ITER_NEXT(ind_it);\n\t\tPyArray_ITER_NEXT(val);\n\t\tif (val->index == val->size) \n\t\t\tPyArray_ITER_RESET(val);\n\t}\n\tPy_DECREF(ind_it);\n\treturn 0;\n}\n\nstatic int\niter_ass_subscript(PyArrayIterObject *self, PyObject *ind, PyObject *val) \n{\n\tPyObject *arrval=NULL;\n\tPyArrayIterObject *val_it=NULL;\n\tPyArray_Descr *type;\n\tPyArray_Descr *indtype=NULL;\n\tint swap, retval=-1;\n\tint itemsize;\n\tintp start, step_size;\n\tintp n_steps;\n\tPyObject *obj=NULL;\n PyArray_CopySwapFunc *copyswap;\n\n\t\n\tif (ind == Py_Ellipsis) {\n\t\tind = PySlice_New(NULL, NULL, NULL);\n\t\tretval = iter_ass_subscript(self, ind, val);\n\t\tPy_DECREF(ind);\n\t\treturn retval;\n\t}\n\n\tif (PyTuple_Check(ind)) {\n\t\tint len;\n\t\tlen = PyTuple_GET_SIZE(ind);\n\t\tif (len > 1) goto finish;\n\t\tind = PyTuple_GET_ITEM(ind, 0);\n\t}\n\n\ttype = self->ao->descr;\n\titemsize = type->elsize;\n\t\n\tPy_INCREF(type);\n\tarrval = PyArray_FromAny(val, type, 0, 0, 0, NULL);\n\tif (arrval==NULL) return -1;\n\tval_it = (PyArrayIterObject *)PyArray_IterNew(arrval);\n\tif (val_it==NULL) goto finish;\n\n\t/* Check for Boolean -- this is first becasue\n\t Bool is a subclass of Int */\n\n copyswap = PyArray_DESCR(arrval)->f->copyswap;\n\tswap = (PyArray_ISNOTSWAPPED(self->ao)!=PyArray_ISNOTSWAPPED(arrval));\n\tif (PyBool_Check(ind)) {\n\t\tif (PyObject_IsTrue(ind)) {\n copyswap(self->dataptr, PyArray_DATA(arrval), \n swap, itemsize);\n\t\t}\n\t\tretval=0;\n\t\tgoto finish;\n\t}\n\n\t/* Check for Integer or Slice */\n\t\n\tif (PyLong_Check(ind) || PyInt_Check(ind) || PySlice_Check(ind)) {\n\t\tstart = parse_subindex(ind, &step_size, &n_steps, \n\t\t\t\t self->size);\n\t\tif (start == -1) goto finish;\n\t\tif (n_steps == RubberIndex || n_steps == PseudoIndex) {\n\t\t\tPyErr_SetString(PyExc_IndexError, \n\t\t\t\t\t\"cannot use Ellipsis or newaxes here\");\n\t\t\tgoto finish;\n\t\t}\n\t\tPyArray_ITER_GOTO1D(self, start);\n\t\tif (n_steps == SingleIndex) { /* Integer */\n copyswap(self->dataptr, PyArray_DATA(arrval),\n swap, itemsize);\n\t\t\tPyArray_ITER_RESET(self);\n\t\t\tretval=0;\n\t\t\tgoto finish;\n\t\t}\n\t\twhile(n_steps--) {\n copyswap(self->dataptr, val_it->dataptr,\n swap, itemsize);\n\t\t\tstart += step_size;\n\t\t\tPyArray_ITER_GOTO1D(self, start)\n\t\t\tPyArray_ITER_NEXT(val_it);\n\t\t\tif (val_it->index == val_it->size) \n\t\t\t\tPyArray_ITER_RESET(val_it);\n\t\t}\n\t\tPyArray_ITER_RESET(self);\n\t\tretval = 0;\n\t\tgoto finish;\n\t} \n\n\t/* convert to INTP array if Integer array scalar or List */\n\n\tindtype = PyArray_DescrFromType(PyArray_INTP);\n\tif (PyArray_IsScalar(ind, Integer)) {\n\t\tPy_INCREF(indtype);\n\t\tobj = PyArray_FromScalar(ind, indtype);\n\t}\n\telse if (PyList_Check(ind)) {\n\t\tPy_INCREF(indtype);\n\t\tobj = PyArray_FromAny(ind, indtype, 0, 0, FORCECAST, NULL);\n\t}\n\telse {\n\t\tPy_INCREF(ind);\n\t\tobj = ind;\n\t}\n\t\n\tif (PyArray_Check(obj)) {\n\t\t/* Check for Boolean object */\n\t\tif (PyArray_TYPE(obj)==PyArray_BOOL) {\n\t\t\tif (iter_ass_sub_Bool(self, (PyArrayObject *)obj,\n\t\t\t\t\t val_it, swap) < 0)\n\t\t\t\tgoto finish;\n\t\t\tretval=0;\n\t\t} \n\t\t/* Check for integer array */\n\t\telse if (PyArray_ISINTEGER(obj)) {\n\t\t\tPyObject *new;\n\t\t\tPy_INCREF(indtype);\n\t\t\tnew = PyArray_CheckFromAny(obj, indtype, 0, 0, \n FORCECAST | BEHAVED_NS_FLAGS, NULL);\n\t\t\tPy_DECREF(obj);\n\t\t\tobj = new;\n\t\t\tif (new==NULL) goto finish;\n\t\t\tif (iter_ass_sub_int(self, (PyArrayObject *)obj,\n\t\t\t\t\t val_it, swap) < 0)\n\t\t\t\tgoto finish;\n\t\t\tretval=0;\n\t\t}\n\t}\n\n finish:\n\tif (!PyErr_Occurred() && retval < 0)\n\t\tPyErr_SetString(PyExc_IndexError, \n\t\t\t\t\"unsupported iterator index\");\n\tPy_XDECREF(indtype);\n\tPy_XDECREF(obj);\n\tPy_XDECREF(val_it);\n\tPy_XDECREF(arrval);\n\treturn retval;\n\t\n}\n\n\nstatic PyMappingMethods iter_as_mapping = {\n (inquiry)iter_length,\t\t /*mp_length*/\n (binaryfunc)iter_subscript,\t /*mp_subscript*/\n (objobjargproc)iter_ass_subscript,\t/*mp_ass_subscript*/\n};\n\nstatic char doc_iter_array[] = \"__array__(type=None)\\n Get array \"\\\n \"from iterator\";\n\nstatic PyObject *\niter_array(PyArrayIterObject *it, PyObject *op) \n{\n \n PyObject *r;\n intp size;\n\n /* Any argument ignored */\n\n /* Two options: \n 1) underlying array is contiguous\n -- return 1-d wrapper around it \n 2) underlying array is not contiguous\n -- make new 1-d contiguous array with updateifcopy flag set\n to copy back to the old array\n */\n\n size = PyArray_SIZE(it->ao);\n\tPy_INCREF(it->ao->descr);\n if (PyArray_ISCONTIGUOUS(it->ao)) {\n r = PyArray_NewFromDescr(it->ao->ob_type, \n\t\t\t\t\t it->ao->descr,\n\t\t\t\t\t 1, &size, \n\t\t\t\t\t NULL, it->ao->data, \n\t\t\t\t\t it->ao->flags,\n\t\t\t\t\t (PyObject *)it->ao); \n\t\tif (r==NULL) return NULL;\n }\n else {\n r = PyArray_NewFromDescr(it->ao->ob_type, \n\t\t\t\t\t it->ao->descr,\n\t\t\t\t\t 1, &size, \n\t\t\t\t\t NULL, NULL, \n\t\t\t\t\t 0, (PyObject *)it->ao);\n\t\tif (r==NULL) return NULL;\n\t\tif (PyArray_CopyInto((PyArrayObject *)r, it->ao) < 0) {\n\t\t\tPy_DECREF(r); \n\t\t\treturn NULL;\n\t\t}\n PyArray_FLAGS(r) |= UPDATEIFCOPY;\n it->ao->flags &= ~WRITEABLE;\n }\n Py_INCREF(it->ao);\n PyArray_BASE(r) = (PyObject *)it->ao;\n return r;\n \n}\n\nstatic char doc_iter_copy[] = \"copy()\\n Get a copy of 1-d array\";\n\nstatic PyObject *\niter_copy(PyArrayIterObject *it, PyObject *args)\n{\n if (!PyArg_ParseTuple(args, \"\")) return NULL;\t\n\treturn PyArray_Flatten(it->ao, 0);\n}\n\nstatic PyMethodDef iter_methods[] = {\n /* to get array */\n {\"__array__\", (PyCFunction)iter_array, 1, doc_iter_array},\n\t{\"copy\", (PyCFunction)iter_copy, 1, doc_iter_copy},\n {NULL,\t\tNULL}\t\t/* sentinel */\n};\n\nstatic PyMemberDef iter_members[] = {\n\t{\"base\", T_OBJECT, offsetof(PyArrayIterObject, ao), RO, NULL},\n {\"index\", T_INT, offsetof(PyArrayIterObject, index), RO, NULL},\n\t{NULL},\n};\n\nstatic PyObject *\niter_coords_get(PyArrayIterObject *self)\n{\n int nd;\n nd = self->ao->nd;\n if (self->contiguous) { /* coordinates not kept track of --- need to generate\n from index */\n intp val;\n int i;\n val = self->index;\n for (i=0;icoordinates[i] = val / self->factors[i];\n val = val % self->factors[i];\n }\n }\n return PyArray_IntTupleFromIntp(nd, self->coordinates);\n}\n\nstatic PyGetSetDef iter_getsets[] = {\n\t{\"coords\", \n\t (getter)iter_coords_get,\n\t NULL,\n\t \"An N-d tuple of current coordinates.\"},\n\t{NULL, NULL, NULL, NULL},\n};\n\nstatic PyTypeObject PyArrayIter_Type = {\n PyObject_HEAD_INIT(NULL)\n 0,\t\t\t\t\t /* ob_size */\n \"numpy.flatiter\",\t\t /* tp_name */\n sizeof(PyArrayIterObject), /* tp_basicsize */\n 0,\t\t\t\t\t /* tp_itemsize */\n /* methods */\n (destructor)arrayiter_dealloc,\t\t/* tp_dealloc */\n 0,\t\t\t\t\t/* tp_print */\n 0,\t\t\t\t\t/* tp_getattr */\n 0,\t\t\t\t\t/* tp_setattr */\n 0,\t\t\t\t\t/* tp_compare */\n 0,\t\t\t\t\t/* tp_repr */\n 0,\t\t\t\t\t/* tp_as_number */\n 0, \t\t\t /* tp_as_sequence */\n &iter_as_mapping, \t /* tp_as_mapping */\n 0,\t\t\t\t\t/* tp_hash */\n 0,\t\t\t\t\t/* tp_call */\n 0,\t\t\t\t\t/* tp_str */\n 0,\t \t/* tp_getattro */\n 0,\t\t\t\t\t/* tp_setattro */\n 0,\t\t\t\t\t/* tp_as_buffer */\n Py_TPFLAGS_DEFAULT, /* tp_flags */\n 0,\t\t\t\t\t/* tp_doc */\n 0, \t /* tp_traverse */\n 0,\t\t\t\t\t/* tp_clear */\n 0,\t\t\t\t\t/* tp_richcompare */\n 0,\t\t\t\t\t/* tp_weaklistoffset */\n 0, \t /* tp_iter */\n (iternextfunc)arrayiter_next,\t\t/* tp_iternext */\n iter_methods,\t\t\t\t/* tp_methods */\n iter_members,\t \t /* tp_members */\n iter_getsets, /* tp_getset */\n\n};\n\n/** END of Array Iterator **/\n\n\n\n/*********************** Subscript Array Iterator *************************\n * *\n * This object handles subscript behavior for array objects. *\n * It is an iterator object with a next method *\n * It abstracts the n-dimensional mapping behavior to make the looping *\n * code more understandable (maybe) *\n * and so that indexing can be set up ahead of time *\n */ \n\n/* convert an indexing object to an INTP indexing array iterator\n if possible -- otherwise, it is a Slice or Ellipsis object\n and has to be interpreted on bind to a particular \n array so leave it NULL for now.\n */\nstatic int\n_convert_obj(PyObject *obj, PyArrayIterObject **iter)\n{\n\tPyArray_Descr *indtype;\n\tPyObject *arr;\n\n\tif (PySlice_Check(obj) || (obj == Py_Ellipsis))\n\t\t*iter = NULL;\n\telse {\n\t\tindtype = PyArray_DescrFromType(PyArray_INTP);\n\t\tarr = PyArray_FromAny(obj, indtype, 0, 0, FORCECAST, NULL);\n\t\tif (arr == NULL) return -1;\n\t\t*iter = (PyArrayIterObject *)PyArray_IterNew(arr);\n\t\tPy_DECREF(arr);\n\t\tif (*iter == NULL) return -1;\n\t}\n\treturn 0;\n}\n\n/* Adjust dimensionality and strides for index object iterators \n --- i.e. broadcast\n */\n/*OBJECT_API*/\nstatic int\nPyArray_Broadcast(PyArrayMultiIterObject *mit)\n{\n\tint i, nd, k, j;\n\tintp tmp;\n\tPyArrayIterObject *it;\n\t\n\t/* Discover the broadcast number of dimensions */\n\tfor (i=0, nd=0; inumiter; i++) \n\t\tnd = MAX(nd, mit->iters[i]->ao->nd);\n\tmit->nd = nd;\n\n\t/* Discover the broadcast shape in each dimension */\n\tfor (i=0; idimensions[i] = 1;\n\t\tfor (j=0; jnumiter; j++) {\n\t\t\tit = mit->iters[j];\n\t\t\t/* This prepends 1 to shapes not already \n\t\t\t equal to nd */\n\t\t\tk = i + it->ao->nd - nd;\n\t\t\tif (k>=0) {\n\t\t\t\ttmp = it->ao->dimensions[k];\n\t\t\t\tif (tmp == 1) continue;\n\t\t\t\tif (mit->dimensions[i] == 1) \n\t\t\t\t\tmit->dimensions[i] = tmp;\n\t\t\t\telse if (mit->dimensions[i] != tmp) {\n\t\t\t\t\tPyErr_SetString(PyExc_ValueError, \n\t\t\t\t\t\t\t\"index objects are \" \\\n\t\t\t\t\t\t\t\"not broadcastable \" \\\n\t\t\t\t\t\t\t\"to a single shape\");\n\t\t\t\t\treturn -1;\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t}\n\n\t/* Reset the iterator dimensions and strides of each iterator\n\t object -- using 0 valued strides for broadcasting */\n\n\ttmp = PyArray_MultiplyList(mit->dimensions, mit->nd);\n\tmit->size = tmp;\n\tfor (i=0; inumiter; i++) {\n\t\tit = mit->iters[i];\n\t\tit->nd_m1 = mit->nd - 1;\n\t\tit->size = tmp;\n\t\tnd = it->ao->nd;\n\t\tit->factors[mit->nd-1] = 1;\n\t\tfor (j=0; j < mit->nd; j++) {\n\t\t\tit->dims_m1[j] = mit->dimensions[j] - 1;\n\t\t\tk = j + nd - mit->nd;\n\t\t\t/* If this dimension was added or shape\n\t\t\t of underlying array was 1 */\n\t\t\tif ((k < 0) || \\\n\t\t\t it->ao->dimensions[k] != mit->dimensions[j]) {\n\t\t\t\tit->contiguous = 0;\n\t\t\t\tit->strides[j] = 0;\n\t\t\t}\n\t\t\telse {\n\t\t\t\tit->strides[j] = it->ao->strides[k];\n\t\t\t}\n\t\t\tit->backstrides[j] = it->strides[j] *\t\\\n\t\t\t\tit->dims_m1[j];\n\t\t\tif (j > 0)\n\t\t\t\tit->factors[mit->nd-j-1] =\t\t\\\n\t\t\t\t\tit->factors[mit->nd-j] *\t\\\n\t\t\t\t\tmit->dimensions[mit->nd-j];\n\t\t}\n\t\tPyArray_ITER_RESET(it);\n\t}\n\treturn 0;\n}\n\n/* Reset the map iterator to the beginning */\nstatic void\nPyArray_MapIterReset(PyArrayMapIterObject *mit)\n{\n\tint i,j; intp coord[MAX_DIMS];\n\tPyArrayIterObject *it;\n\tPyArray_CopySwapFunc *copyswap;\n\n\tmit->index = 0;\n\n\tcopyswap = mit->iters[0]->ao->descr->f->copyswap;\n\n\tif (mit->subspace != NULL) {\n\t\tmemcpy(coord, mit->bscoord, sizeof(intp)*mit->ait->ao->nd);\n\t\tPyArray_ITER_RESET(mit->subspace);\n\t\tfor (i=0; inumiter; i++) {\n\t\t\tit = mit->iters[i];\n\t\t\tPyArray_ITER_RESET(it);\n\t\t\tj = mit->iteraxes[i];\n\t\t\tcopyswap(coord+j,it->dataptr,\n\t\t\t\t !PyArray_ISNOTSWAPPED(it->ao),\n\t\t\t\t sizeof(intp));\n\t\t}\n\t\tPyArray_ITER_GOTO(mit->ait, coord);\n\t\tmit->subspace->dataptr = mit->ait->dataptr;\n\t\tmit->dataptr = mit->subspace->dataptr;\n\t}\n\telse {\n\t\tfor (i=0; inumiter; i++) {\n\t\t\tit = mit->iters[i];\n\t\t\tPyArray_ITER_RESET(it);\n\t\t\tcopyswap(coord+i,it->dataptr, \n\t\t\t\t !PyArray_ISNOTSWAPPED(it->ao),\n\t\t\t\t sizeof(intp));\n\t\t}\n\t\tPyArray_ITER_GOTO(mit->ait, coord);\n\t\tmit->dataptr = mit->ait->dataptr;\n\t}\n\treturn;\n}\n\n/* This function needs to update the state of the map iterator\n and point mit->dataptr to the memory-location of the next object\n*/\nstatic void\nPyArray_MapIterNext(PyArrayMapIterObject *mit)\n{\n\tint i, j;\n\tintp coord[MAX_DIMS];\n\tPyArrayIterObject *it;\n\tPyArray_CopySwapFunc *copyswap;\n\n\tmit->index += 1;\n\tif (mit->index >= mit->size) return;\n\tcopyswap = mit->iters[0]->ao->descr->f->copyswap;\n\t/* Sub-space iteration */\n\tif (mit->subspace != NULL) {\n\t\tPyArray_ITER_NEXT(mit->subspace);\n\t\tif (mit->subspace->index == mit->subspace->size) {\n\t\t\t/* reset coord to coordinates of \n\t\t\t beginning of the subspace */\n\t\t\tmemcpy(coord, mit->bscoord, \n\t\t\t sizeof(intp)*mit->ait->ao->nd);\n\t\t\tPyArray_ITER_RESET(mit->subspace);\n\t\t\tfor (i=0; inumiter; i++) {\n\t\t\t\tit = mit->iters[i];\n\t\t\t\tPyArray_ITER_NEXT(it);\n\t\t\t\tj = mit->iteraxes[i];\n\t\t\t\tcopyswap(coord+j,it->dataptr,\n\t\t\t\t\t !PyArray_ISNOTSWAPPED(it->ao),\n\t\t\t\t\t sizeof(intp));\n\t\t\t}\n\t\t\tPyArray_ITER_GOTO(mit->ait, coord);\n\t\t\tmit->subspace->dataptr = mit->ait->dataptr;\n\t\t}\n\t\tmit->dataptr = mit->subspace->dataptr;\n\t}\n\telse {\n\t\tfor (i=0; inumiter; i++) {\n\t\t\tit = mit->iters[i];\n\t\t\tPyArray_ITER_NEXT(it);\n\t\t\tcopyswap(coord+i,it->dataptr, \n\t\t\t\t !PyArray_ISNOTSWAPPED(it->ao),\n\t\t\t\t sizeof(intp));\n\t\t}\n\t\tPyArray_ITER_GOTO(mit->ait, coord);\n\t\tmit->dataptr = mit->ait->dataptr;\n\t}\n\treturn;\n}\n\n/* Bind a mapiteration to a particular array */\n\n/* Determine if subspace iteration is necessary. If so, \n 1) Fill in mit->iteraxes\n\t 2) Create subspace iterator\n\t 3) Update nd, dimensions, and size. \n\n Subspace iteration is necessary if: arr->nd > mit->numiter\n*/\n\n/* Need to check for index-errors somewhere. \n\n Let's do it at bind time and also convert all <0 values to >0 here\n as well. \n*/\nstatic void\nPyArray_MapIterBind(PyArrayMapIterObject *mit, PyArrayObject *arr)\n{\n\tint subnd;\n\tPyObject *sub, *obj=NULL;\n\tint i, j, n, curraxis, ellipexp, noellip;\n\tPyArrayIterObject *it;\n\tintp dimsize;\n\tintp *indptr;\n\t\n\tsubnd = arr->nd - mit->numiter;\n\tif (subnd < 0) {\n\t\tPyErr_SetString(PyExc_ValueError, \n\t\t\t\t\"too many indices for array\");\n\t\treturn;\n\t}\n\n\tmit->ait = (PyArrayIterObject *)PyArray_IterNew((PyObject *)arr);\n\tif (mit->ait == NULL) return;\n\n\t/* If this is just a view, then do nothing more */\n\t/* views are handled by just adjusting the strides\n\t and dimensions of the object.\n\t*/\n\t \n\t/* no subspace iteration needed. Finish up and Return */\n\tif (subnd == 0) {\n\t\tn = arr->nd;\n\t\tfor (i=0; iiteraxes[i] = i;\n\t\t}\n\t\tgoto finish;\n\t}\n\n\t/* all indexing arrays have been converted to 0 \n\t therefore we can extract the subspace with a simple\n\t getitem call which will use view semantics\n\t*/\n\t\n\tsub = PyObject_GetItem((PyObject *)arr, mit->indexobj);\n\tif (sub == NULL) goto fail;\n\tmit->subspace = (PyArrayIterObject *)PyArray_IterNew(sub);\n\tPy_DECREF(sub);\n\tif (mit->subspace == NULL) goto fail;\n\t\n\t/* Expand dimensions of result */\n\tn = mit->subspace->ao->nd;\n\tfor (i=0; idimensions[mit->nd+i] = mit->subspace->ao->dimensions[i];\n\tmit->nd += n;\n\n\t/* Now, we still need to interpret the ellipsis and slice objects \n\t to determine which axes the indexing arrays are referring to\n\t*/\n\tn = PyTuple_GET_SIZE(mit->indexobj);\n\n\t/* The number of dimensions an ellipsis takes up */\n\tellipexp = arr->nd - n + 1;\n\t/* Now fill in iteraxes -- remember indexing arrays have been \n converted to 0's in mit->indexobj */\n\tcurraxis = 0;\n\tj = 0;\n\tnoellip = 1; /* Only expand the first ellipsis */\n\tmemset(mit->bscoord, 0, sizeof(intp)*arr->nd);\n\tfor (i=0; iindexobj, i);\n\t\tif (PyInt_Check(obj) || PyLong_Check(obj)) \n\t\t\tmit->iteraxes[j++] = curraxis++;\n\t\telse if (noellip && obj == Py_Ellipsis) {\n\t\t\tcurraxis += ellipexp;\n\t\t\tnoellip = 0;\n\t\t}\n\t\telse {\n\t\t\tintp start=0;\n\t\t\tintp stop, step;\n\t\t\t/* Should be slice object or\n\t\t\t another Ellipsis */\n\t\t\tif (obj == Py_Ellipsis) {\n\t\t\t\tmit->bscoord[curraxis] = 0;\n\t\t\t}\n\t\t\telse if (!PySlice_Check(obj) || \\\n\t\t\t\t (slice_GetIndices((PySliceObject *)obj, \n\t\t\t\t\t\t arr->dimensions[curraxis],\n\t\t\t\t\t\t &start, &stop, &step,\n\t\t\t\t\t\t &dimsize) < 0)) {\n\t\t\t\tPyErr_Format(PyExc_ValueError, \n\t\t\t\t\t \"unexpected object \"\t\\\n\t\t\t\t\t \"(%s) in selection position %d\",\n\t\t\t\t\t obj->ob_type->tp_name, i);\n\t\t\t goto fail;\n\t\t\t}\n\t\t\telse {\n\t\t\t\tmit->bscoord[curraxis] = start;\n\t\t\t}\n\t\t\tcurraxis += 1; \n\t\t}\n\t}\n finish:\n\t/* Here check the indexes (now that we have iteraxes) */\n\tmit->size = PyArray_MultiplyList(mit->dimensions, mit->nd);\n\tfor (i=0; inumiter; i++) {\n\t\tit = mit->iters[i];\n\t\tPyArray_ITER_RESET(it);\n\t\tdimsize = arr->dimensions[mit->iteraxes[i]];\n\t\twhile(it->index < it->size) {\n\t\t\tindptr = ((intp *)it->dataptr);\n\t\t\tif (*indptr < 0) *indptr += dimsize;\n\t\t\tif (*indptr < 0 || *indptr >= dimsize) {\n\t\t\t\tPyErr_Format(PyExc_IndexError,\n\t\t\t\t\t \"index (%d) out of range \"\\\n\t\t\t\t\t \"(0<=index<=%d) in dimension %d\",\n\t\t\t\t\t (int) *indptr, (int) (dimsize-1), \n\t\t\t\t\t mit->iteraxes[i]);\n\t\t\t\tgoto fail;\n\t\t\t}\n\t\t\tPyArray_ITER_NEXT(it);\n\t\t} \n\t\tPyArray_ITER_RESET(it);\n\t}\n\treturn;\n\n fail:\n\tPy_XDECREF(mit->subspace);\n\tPy_XDECREF(mit->ait);\n\tmit->subspace = NULL;\n\tmit->ait = NULL;\n\treturn;\n}\n\n/* This function takes a Boolean array and constructs index objects and\n iterators as if nonzero(Bool) had been called\n*/\nstatic int\n_nonzero_indices(PyObject *myBool, PyArrayIterObject **iters)\n{\n\tPyArray_Descr *typecode;\n\tPyArrayObject *ba =NULL, *new=NULL;\n\tint nd, j;\n\tintp size, i, count;\n\tBool *ptr;\n\tintp coords[MAX_DIMS], dims_m1[MAX_DIMS];\n\tintp *dptr[MAX_DIMS];\n\n\ttypecode=PyArray_DescrFromType(PyArray_BOOL);\n\tba = (PyArrayObject *)PyArray_FromAny(myBool, typecode, 0, 0, \n\t\t\t\t\t CARRAY_FLAGS, NULL);\n\tif (ba == NULL) return -1;\n\tnd = ba->nd;\n\tfor (j=0; jdata;\n\tcount = 0;\n\n\t/* pre-determine how many nonzero entries there are */\n\tfor (i=0; iao->data;\n\t\tcoords[j] = 0;\n\t\tdims_m1[j] = ba->dimensions[j]-1;\n\t}\n\n\tptr = (Bool *)ba->data;\n\n\tif (count == 0) goto finish;\n\t\n\t/* Loop through the Boolean array and copy coordinates\n\t for non-zero entries */\n\tfor (i=0; i=0; j--) {\n\t\t\tif (coords[j] < dims_m1[j]) {\n\t\t\t\tcoords[j]++;\n\t\t\t\tbreak;\n\t\t\t}\n\t\t\telse {\n\t\t\t\tcoords[j] = 0;\n\t\t\t}\n\t\t}\n\t}\n\n finish:\n\tPy_DECREF(ba);\n\treturn nd;\n\n fail:\n\tfor (j=0; jiters[i] = NULL;\n \tmit->index = 0;\n \tmit->ait = NULL;\n \tmit->subspace = NULL;\n\tmit->numiter = 0;\n\tmit->consec = 1;\n\tPy_INCREF(indexobj);\n\tmit->indexobj = indexobj;\n\n\tif (fancy == SOBJ_LISTTUP) {\n\t\tPyObject *newobj;\n\t\tnewobj = PySequence_Tuple(indexobj);\n\t\tif (newobj == NULL) goto fail;\n\t\tPy_DECREF(indexobj);\n\t\tindexobj = newobj;\n\t\tmit->indexobj = indexobj;\n\t}\n\n#undef SOBJ_NOTFANCY \n#undef SOBJ_ISFANCY \n#undef SOBJ_BADARRAY \n#undef SOBJ_TOOMANY \n#undef SOBJ_LISTTUP \n \n\tif (oned) return (PyObject *)mit;\n\n\t/* Must have some kind of fancy indexing if we are here */\n\t/* indexobj is either a list, an arrayobject, or a tuple \n\t (with at least 1 list or arrayobject or Bool object), */\n\t\n\t/* convert all inputs to iterators */\n\tif (PyArray_Check(indexobj) &&\t\t\t\\\n\t (PyArray_TYPE(indexobj) == PyArray_BOOL)) {\n\t\tmit->numiter = _nonzero_indices(indexobj, mit->iters);\n\t\tif (mit->numiter < 0) goto fail;\n\t\tmit->nd = 1;\n\t\tmit->dimensions[0] = mit->iters[0]->dims_m1[0]+1;\n\t\tPy_DECREF(mit->indexobj);\n\t\tmit->indexobj = PyTuple_New(mit->numiter);\n\t\tif (mit->indexobj == NULL) goto fail;\n\t\tfor (i=0; inumiter; i++) {\n\t\t\tPyTuple_SET_ITEM(mit->indexobj, i, \n\t\t\t\t\t PyInt_FromLong(0));\n\t\t}\n\t}\n\n\telse if (PyArray_Check(indexobj) || !PyTuple_Check(indexobj)) {\n\t\tmit->numiter = 1;\n\t\tindtype = PyArray_DescrFromType(PyArray_INTP);\n\t\tarr = PyArray_FromAny(indexobj, indtype, 0, 0, FORCECAST, NULL);\n\t\tif (arr == NULL) goto fail;\n\t\tmit->iters[0] = (PyArrayIterObject *)PyArray_IterNew(arr);\n\t\tif (mit->iters[0] == NULL) {Py_DECREF(arr); goto fail;}\n\t\tmit->nd = PyArray_NDIM(arr);\n\t\tmemcpy(mit->dimensions,PyArray_DIMS(arr),mit->nd*sizeof(intp));\n\t\tmit->size = PyArray_SIZE(arr);\n\t\tPy_DECREF(arr);\n\t\tPy_DECREF(mit->indexobj);\n\t\tmit->indexobj = Py_BuildValue(\"(N)\", PyInt_FromLong(0));\n\t}\n\telse { /* must be a tuple */\n\t\tPyObject *obj;\n\t\tPyArrayIterObject *iter;\n\t\tPyObject *new;\n\t\t/* Make a copy of the tuple -- we will be replacing \n\t\t index objects with 0's */\n\t\tn = PyTuple_GET_SIZE(indexobj);\n\t\tnew = PyTuple_New(n);\n\t\tif (new == NULL) goto fail;\n\t\tstarted = 0;\n\t\tnonindex = 0;\n\t\tfor (i=0; iconsec = 0;\n\t\t\t\tmit->iters[(mit->numiter)++] = iter;\n\t\t\t\tPyTuple_SET_ITEM(new,i,\n\t\t\t\t\t\t PyInt_FromLong(0));\n\t\t\t}\n\t\t\telse {\n\t\t\t\tif (started) nonindex = 1;\n\t\t\t\tPy_INCREF(obj);\n\t\t\t\tPyTuple_SET_ITEM(new,i,obj);\n\t\t\t}\n\t\t}\n\t\tPy_DECREF(mit->indexobj);\n\t\tmit->indexobj = new;\n\t\t/* Store the number of iterators actually converted */\n\t\t/* These will be mapped to actual axes at bind time */\n\t\tif (PyArray_Broadcast((PyArrayMultiIterObject *)mit) < 0)\n\t\t\tgoto fail;\n\t}\n\n return (PyObject *)mit;\n \n fail:\n Py_DECREF(mit);\n\treturn NULL;\n}\n\n\nstatic void\narraymapiter_dealloc(PyArrayMapIterObject *mit)\n{\n\tint i;\n\tPy_XDECREF(mit->indexobj);\n Py_XDECREF(mit->ait);\n\tPy_XDECREF(mit->subspace);\n\tfor (i=0; inumiter; i++)\n\t\tPy_XDECREF(mit->iters[i]);\n _pya_free(mit);\n}\n\n/* The mapiter object must be created new each time. It does not work\n to bind to a new array, and continue.\n\n This was the orginal intention, but currently that does not work. \n Do not expose the MapIter_Type to Python.\n\n It's not very useful anyway, since mapiter(indexobj); mapiter.bind(a); \n mapiter is equivalent to a[indexobj].flat but the latter gets to use \n slice syntax.\n*/\n\nstatic PyTypeObject PyArrayMapIter_Type = {\n PyObject_HEAD_INIT(NULL)\n 0,\t\t\t\t\t /* ob_size */\n \"numpy.mapiter\",\t\t \t/* tp_name */\n sizeof(PyArrayIterObject), /* tp_basicsize */\n 0,\t\t\t\t\t /* tp_itemsize */\n /* methods */\n (destructor)arraymapiter_dealloc,\t/* tp_dealloc */\n 0,\t\t\t\t\t/* tp_print */\n 0,\t\t\t\t\t/* tp_getattr */\n 0,\t\t\t\t\t/* tp_setattr */\n 0,\t\t\t\t\t/* tp_compare */\n 0,\t\t\t\t\t/* tp_repr */\n 0,\t\t\t\t\t/* tp_as_number */\n 0,\t\t\t\t\t/* tp_as_sequence */\n 0,\t\t\t\t\t/* tp_as_mapping */\n 0,\t\t\t\t\t/* tp_hash */\n 0,\t\t\t\t\t/* tp_call */\n 0,\t\t\t\t\t/* tp_str */\n 0, \t\t/* tp_getattro */\n 0,\t\t\t\t\t/* tp_setattro */\n 0,\t\t\t\t\t/* tp_as_buffer */\n Py_TPFLAGS_DEFAULT, /* tp_flags */\n 0,\t\t\t\t\t/* tp_doc */\n (traverseproc)0, \t /* tp_traverse */\n 0,\t\t\t\t\t/* tp_clear */\n 0,\t\t\t\t\t/* tp_richcompare */\n 0,\t\t\t\t\t/* tp_weaklistoffset */\n 0,\t\t \t /* tp_iter */\n (iternextfunc)0, \t /* tp_iternext */\n 0, \t /* tp_methods */\n 0,\t\t\t\t\t /* tp_members */\n 0,\t\t\t /* tp_getset */\n 0,\t\t\t\t\t /* tp_base */\n 0,\t\t\t\t\t /* tp_dict */\n 0,\t\t\t\t\t /* tp_descr_get */\n 0,\t\t\t\t\t /* tp_descr_set */\n 0,\t\t\t\t\t /* tp_dictoffset */\n (initproc)0,\t \t /* tp_init */\n 0, \t /* tp_alloc */\n 0,\t /* tp_new */\n 0,\t /* tp_free */\n 0,\t\t\t\t\t /* tp_is_gc */\n 0,\t\t\t\t\t /* tp_bases */\n 0,\t\t\t\t\t /* tp_mro */\n 0,\t\t\t\t\t /* tp_cache */\n 0,\t\t\t\t\t /* tp_subclasses */\n 0\t\t\t\t\t /* tp_weaklist */\n\n};\n\n/** END of Subscript Iterator **/\n\n\n/*OBJECT_API\n Get MultiIterator,\n*/\nstatic PyObject *\nPyArray_MultiIterNew(int n, ...)\n{\n va_list va;\n\tPyArrayMultiIterObject *multi;\n\tPyObject *current;\n\tPyObject *arr;\n\t\n\tint i, err=0;\n\t\n\tif (n < 2 || n > MAX_DIMS) {\n\t\tPyErr_Format(PyExc_ValueError, \n\t\t\t \"Need between 2 and (%d) \"\t\t\t\\\n\t\t\t \"array objects (inclusive).\", MAX_DIMS);\n\t}\n\t\n /* fprintf(stderr, \"multi new...\");*/\n multi = PyObject_New(PyArrayMultiIterObject, &PyArrayMultiIter_Type);\n if (multi == NULL)\n return NULL;\n\t\n\tfor (i=0; iiters[i] = NULL;\n\tmulti->numiter = n;\n\tmulti->index = 0;\n\n va_start(va, n);\n\tfor (i=0; iiters[i] = (PyArrayIterObject *)PyArray_IterNew(arr);\n\t\t\tPy_DECREF(arr);\n\t\t}\n\t}\n\n\tva_end(va);\t\n\t\n\tif (!err && PyArray_Broadcast(multi) < 0) err=1;\n\n\tif (err) {\n Py_DECREF(multi);\n\t\treturn NULL;\n\t}\n\t\n\tPyArray_MultiIter_RESET(multi);\n\t\n return (PyObject *)multi;\n}\n\nstatic PyObject *\narraymultiter_new(PyTypeObject *subtype, PyObject *args, PyObject *kwds)\n{\n\t\n\tint n, i;\n\tPyArrayMultiIterObject *multi;\n\tPyObject *arr;\n\t\n\tif (kwds != NULL) {\n\t\tPyErr_SetString(PyExc_ValueError, \n\t\t\t\t\"keyword arguments not accepted.\");\n\t\treturn NULL;\n\t}\n\n\tn = PyTuple_Size(args);\n\tif (n < 2 || n > MAX_DIMS) {\n\t\tif (PyErr_Occurred()) return NULL;\n\t\tPyErr_Format(PyExc_ValueError, \n\t\t\t \"Need at least two and fewer than (%d) \"\t\\\n\t\t\t \"array objects.\", MAX_DIMS);\n\t\treturn NULL;\n\t}\n\t\n\tmulti = _pya_malloc(sizeof(PyArrayMultiIterObject));\n if (multi == NULL) return PyErr_NoMemory();\n\tPyObject_Init((PyObject *)multi, &PyArrayMultiIter_Type);\n\n\tmulti->numiter = n;\n\tmulti->index = 0;\n\tfor (i=0; iiters[i] = NULL;\n\tfor (i=0; iiters[i] =\t\t\t\t\t\\\n\t\t (PyArrayIterObject *)PyArray_IterNew(arr))==NULL) \n\t\t\tgoto fail;\n\t\tPy_DECREF(arr);\n\t}\n\tif (PyArray_Broadcast(multi) < 0) goto fail;\n\tPyArray_MultiIter_RESET(multi);\n\t\n return (PyObject *)multi;\n\t\n fail:\n Py_DECREF(multi);\n\treturn NULL;\n}\n\nstatic PyObject *\narraymultiter_next(PyArrayMultiIterObject *multi)\n{\n\tPyObject *ret;\n\tint i, n;\n\n\tn = multi->numiter;\n\tret = PyTuple_New(n);\n\tif (ret == NULL) return NULL;\n\tif (multi->index < multi->size) {\n\t\tfor (i=0; i < n; i++) {\n\t\t\tPyArrayIterObject *it=multi->iters[i];\n\t\t\tPyTuple_SET_ITEM(ret, i, \n\t\t\t\t\t PyArray_ToScalar(it->dataptr, it->ao));\n\t\t\tPyArray_ITER_NEXT(it);\n\t\t}\n\t\tmulti->index++;\n\t\treturn ret;\n\t}\n return NULL;\n}\n\nstatic void\narraymultiter_dealloc(PyArrayMultiIterObject *multi)\n{\n\tint i;\n\n\tfor (i=0; inumiter; i++) \n\t\tPy_XDECREF(multi->iters[i]);\n\t_pya_free(multi);\n}\n\nstatic PyObject *\narraymultiter_size_get(PyArrayMultiIterObject *self)\n{\n#if SIZEOF_INTP <= SIZEOF_LONG\n\treturn PyInt_FromLong((long) self->size);\n#else\n\tif (self->size < MAX_LONG)\n\t\treturn PyInt_FromLong((long) self->size);\n\telse\n\t\treturn PyLong_FromLongLong((longlong) self->size);\n#endif\n}\n\nstatic PyObject *\narraymultiter_index_get(PyArrayMultiIterObject *self)\n{\n#if SIZEOF_INTP <= SIZEOF_LONG\n\treturn PyInt_FromLong((long) self->index);\n#else\n\tif (self->size < MAX_LONG)\n\t\treturn PyInt_FromLong((long) self->index);\n\telse\n\t\treturn PyLong_FromLongLong((longlong) self->index);\n#endif\n}\n\nstatic PyObject *\narraymultiter_shape_get(PyArrayMultiIterObject *self)\n{\n\treturn PyArray_IntTupleFromIntp(self->nd, self->dimensions);\t\n}\n\nstatic PyObject *\narraymultiter_iters_get(PyArrayMultiIterObject *self)\n{\n\tPyObject *res;\n\tint i, n;\n\tn = self->numiter;\n\tres = PyTuple_New(n);\n\tif (res == NULL) return res;\n\tfor (i=0; iiters[i]);\n\t\tPyTuple_SET_ITEM(res, i, (PyObject *)self->iters[i]);\n\t}\n\treturn res;\n}\n\nstatic PyGetSetDef arraymultiter_getsetlist[] = {\n {\"size\", \n\t (getter)arraymultiter_size_get,\n\t NULL, \n\t \"total size of broadcasted result\"},\n {\"index\", \n\t (getter)arraymultiter_index_get, \n NULL,\n\t \"current index in broadcasted result\"},\n\t{\"shape\",\n\t (getter)arraymultiter_shape_get,\n\t NULL,\n\t \"shape of broadcasted result\"},\n\t{\"iters\",\n\t (getter)arraymultiter_iters_get,\n\t NULL,\n\t \"tuple of individual iterators\"},\n\t{NULL, NULL, NULL, NULL},\n};\n\nstatic PyMemberDef arraymultiter_members[] = {\n\t{\"numiter\", T_INT, offsetof(PyArrayMultiIterObject, numiter), \n\t RO, NULL},\n\t{\"nd\", T_INT, offsetof(PyArrayMultiIterObject, nd), RO, NULL},\n\t{NULL},\n};\n\nstatic PyObject *\narraymultiter_reset(PyArrayMultiIterObject *self, PyObject *args)\n{\n\tif (!PyArg_ParseTuple(args, \"\")) return NULL;\n\n\tPyArray_MultiIter_RESET(self);\n\tPy_INCREF(Py_None);\n\treturn Py_None;\n}\n\nstatic PyMethodDef arraymultiter_methods[] = {\n\t{\"reset\", (PyCFunction) arraymultiter_reset, METH_VARARGS, NULL},\n\t{NULL, NULL},\n};\n\nstatic PyTypeObject PyArrayMultiIter_Type = {\n PyObject_HEAD_INIT(NULL)\n 0,\t\t\t\t\t /* ob_size */\n \"numpy.broadcast\",\t\t \t /* tp_name */\n sizeof(PyArrayMultiIterObject), /* tp_basicsize */\n 0,\t\t\t\t\t /* tp_itemsize */\n /* methods */\n (destructor)arraymultiter_dealloc,\t/* tp_dealloc */\n 0,\t\t\t\t\t/* tp_print */\n 0,\t\t\t\t\t/* tp_getattr */\n 0,\t\t\t\t\t/* tp_setattr */\n 0,\t\t\t\t\t/* tp_compare */\n 0,\t\t\t\t\t/* tp_repr */\n 0,\t\t\t\t\t/* tp_as_number */\n 0, /* tp_as_sequence */\n 0, \t /* tp_as_mapping */\n 0,\t\t\t\t\t/* tp_hash */\n 0,\t\t\t\t\t/* tp_call */\n 0,\t\t\t\t\t/* tp_str */\n 0,\t \t/* tp_getattro */\n 0,\t\t\t\t\t/* tp_setattro */\n 0,\t\t\t\t\t/* tp_as_buffer */\n Py_TPFLAGS_DEFAULT, /* tp_flags */\n 0,\t\t\t\t\t/* tp_doc */\n 0, \t /* tp_traverse */\n 0,\t\t\t\t\t/* tp_clear */\n 0,\t\t\t\t\t/* tp_richcompare */\n 0,\t\t\t\t\t/* tp_weaklistoffset */\n 0, \t /* tp_iter */\n (iternextfunc)arraymultiter_next,\t/* tp_iternext */\n arraymultiter_methods, \t /* tp_methods */\n arraymultiter_members,\t \t /* tp_members */\n arraymultiter_getsetlist, /* tp_getset */\n 0,\t\t\t\t\t /* tp_base */\n 0,\t\t\t\t\t /* tp_dict */\n 0,\t\t\t\t\t /* tp_descr_get */\n 0,\t\t\t\t\t /* tp_descr_set */\n 0,\t\t\t\t\t /* tp_dictoffset */\n (initproc)0,\t \t /* tp_init */\n 0, \t /* tp_alloc */\n arraymultiter_new,\t /* tp_new */\n 0,\t /* tp_free */\n 0,\t\t\t\t\t /* tp_is_gc */\n 0,\t\t\t\t\t /* tp_bases */\n 0,\t\t\t\t\t /* tp_mro */\n 0,\t\t\t\t\t /* tp_cache */\n 0,\t\t\t\t\t /* tp_subclasses */\n 0\t\t\t\t\t /* tp_weaklist */\n};\n\n/*OBJECT_API*/\nstatic PyArray_Descr *\nPyArray_DescrNewFromType(int type_num)\n{\n\tPyArray_Descr *old;\n\tPyArray_Descr *new;\n\n\told = PyArray_DescrFromType(type_num);\n\tnew = PyArray_DescrNew(old);\n\tPy_DECREF(old);\n\treturn new;\t\n}\n\n/*** Array Descr Objects for dynamic types **/\n\n/** There are some statically-defined PyArray_Descr objects corresponding\n to the basic built-in types. \n These can and should be DECREF'd and INCREF'd as appropriate, anyway.\n If a mistake is made in reference counting, deallocation on these \n builtins will be attempted leading to problems. \n\n This let's us deal with all PyArray_Descr objects using reference\n counting (regardless of whether they are statically or dynamically \n allocated). \n**/\n\n/* base cannot be NULL */\n/*OBJECT_API*/\nstatic PyArray_Descr *\nPyArray_DescrNew(PyArray_Descr *base)\n{\n\tPyArray_Descr *new;\n\n\tnew = PyObject_New(PyArray_Descr, &PyArrayDescr_Type);\n\tif (new == NULL) return NULL;\n\t/* Don't copy PyObject_HEAD part */\n\tmemcpy((char *)new+sizeof(PyObject),\n\t (char *)base+sizeof(PyObject),\n\t sizeof(PyArray_Descr)-sizeof(PyObject));\n\n\tif (new->fields == Py_None) new->fields = NULL;\n\tPy_XINCREF(new->fields);\n\tif (new->subarray) {\n\t\tnew->subarray = _pya_malloc(sizeof(PyArray_ArrayDescr));\n\t\tmemcpy(new->subarray, base->subarray, \n\t\t sizeof(PyArray_ArrayDescr));\n\t\tPy_INCREF(new->subarray->shape);\n\t\tPy_INCREF(new->subarray->base);\n\t}\n\tPy_INCREF(new->typeobj);\n\treturn new;\n}\n\n/* should never be called for builtin-types unless \n there is a reference-count problem \n*/\nstatic void\narraydescr_dealloc(PyArray_Descr *self)\n{\n\tPy_XDECREF(self->typeobj);\n\tPy_XDECREF(self->fields);\n\tif (self->subarray) {\n\t\tPy_DECREF(self->subarray->shape);\n\t\tPy_DECREF(self->subarray->base);\n\t\t_pya_free(self->subarray);\n\t}\n\tself->ob_type->tp_free(self);\n}\n\n/* we need to be careful about setting attributes because these\n objects are pointed to by arrays that depend on them for interpreting\n data. Currently no attributes of dtype objects can be set. \n*/\nstatic PyMemberDef arraydescr_members[] = {\n\t{\"type\", T_OBJECT, offsetof(PyArray_Descr, typeobj), RO, NULL},\n\t{\"kind\", T_CHAR, offsetof(PyArray_Descr, kind), RO, NULL},\n\t{\"char\", T_CHAR, offsetof(PyArray_Descr, type), RO, NULL},\n\t{\"num\", T_INT, offsetof(PyArray_Descr, type_num), RO, NULL},\n\t{\"byteorder\", T_CHAR, offsetof(PyArray_Descr, byteorder), RO, NULL},\n\t{\"itemsize\", T_INT, offsetof(PyArray_Descr, elsize), RO, NULL},\n\t{\"alignment\", T_INT, offsetof(PyArray_Descr, alignment), RO, NULL},\n {\"hasobject\", T_UBYTE, offsetof(PyArray_Descr, hasobject), RO, NULL},\n\t{NULL}, \n};\n\nstatic PyObject *\narraydescr_subdescr_get(PyArray_Descr *self)\n{\n\tif (self->subarray == NULL) {\n\t\tPy_INCREF(Py_None);\n\t\treturn Py_None;\n\t}\n\treturn Py_BuildValue(\"OO\", (PyObject *)self->subarray->base, \n\t\t\t self->subarray->shape);\n}\n\nstatic PyObject *\narraydescr_protocol_typestr_get(PyArray_Descr *self)\n{\n char basic_=self->kind;\n char endian = self->byteorder;\n\n if (endian == '=') {\n endian = '<';\n if (!PyArray_IsNativeByteOrder(endian)) endian = '>';\n }\n\n return PyString_FromFormat(\"%c%c%d\", endian, basic_,\n self->elsize);\n}\n\nstatic PyObject *\narraydescr_typename_get(PyArray_Descr *self)\n{\n int len;\n PyTypeObject *typeobj = self->typeobj;\n\tPyObject *res;\n\n\t/* Both are equivalents, but second is more resistent to changes */\n/* \tlen = strlen(typeobj->tp_name) - 8; */\n\n\tif (PyTypeNum_ISUSERDEF(self->type_num)) {\n\t\tres = PyString_FromString(typeobj->tp_name);\n\t}\n\telse {\n\t\tlen = strchr(typeobj->tp_name, (int)'_')-(typeobj->tp_name);\n\t\tres = PyString_FromStringAndSize(typeobj->tp_name, len);\n\t}\n\tif (PyTypeNum_ISEXTENDED(self->type_num) && self->elsize != 0) {\n\t\tPyObject *p;\n\t\tp = PyString_FromFormat(\"%d\", self->elsize * 8);\n\t\tPyString_ConcatAndDel(&res, p);\n\t}\n\treturn res;\t\t\t\t\t\t \n}\n\nstatic PyObject *\narraydescr_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\t{\"name\",\n\t (getter)arraydescr_typename_get,\n\t NULL,\n\t \"The array_protocol typename.\"},\n\t{\"isbuiltin\",\n\t (getter)arraydescr_isbuiltin_get,\n\t NULL,\n\t \"Is this a buillt-in data-type descriptor?\"},\n\t{\"isnative\",\n\t (getter)arraydescr_isnative_get,\n\t NULL,\n\t \"Is the byte-order of this descriptor native?\"},\n\t{\"fields\",\n\t (getter)arraydescr_fields_get,\n\t NULL,\n\t NULL},\n\t{NULL, NULL, NULL, NULL},\n};\n\nstatic PyArray_Descr *_convert_from_list(PyObject *obj, int align, int try_descr);\nstatic PyArray_Descr *_convert_from_dict(PyObject *obj, int align);\nstatic PyArray_Descr *_convert_from_commastring(PyObject *obj, int align);\nstatic PyArray_Descr *_convert_from_array_descr(PyObject *obj);\n\nstatic PyObject *\narraydescr_new(PyTypeObject *subtype, PyObject *args, PyObject *kwds)\n{\n\tPyObject *odescr;\n\tPyArray_Descr *descr, *conv;\n\tint align=0;\n\tBool copy=FALSE;\n\tstatic char *kwlist[] = {\"dtype\", \"align\", \"copy\", NULL};\n\t\n\tif (!PyArg_ParseTupleAndKeywords(args, kwds, \"O|iO&\",\n\t\t\t\t\t kwlist, &odescr, &align,\n\t\t\t\t\t PyArray_BoolConverter, ©))\n\t\treturn NULL;\n\t\n\tif (align) {\n\t\tconv = NULL;\n\t\tif PyDict_Check(odescr) \n\t\t\tconv = _convert_from_dict(odescr, 1);\n\t\telse if PyList_Check(odescr) \n\t\t\tconv = _convert_from_list(odescr, 1, 0);\n\t\telse if PyString_Check(odescr)\n\t\t\tconv = _convert_from_commastring(odescr, 1);\n\t\telse {\n\t\t\tPyErr_SetString(PyExc_ValueError, \n\t\t\t\t\t\"align can only be non-zero for\" \\\n\t\t\t\t\t\"dictionary, list, and string objects.\");\n\t\t}\n\t\tif (conv) return (PyObject *)conv;\n\t\tif (!PyErr_Occurred()) {\n\t\t\tPyErr_SetString(PyExc_ValueError,\n\t\t\t\t\t\"data-type-descriptor not understood\");\n\t\t}\n\t\treturn NULL;\n\t}\n\n\tif PyList_Check(odescr) {\n\t\tconv = _convert_from_array_descr(odescr);\n\t\tif (!conv) {\n\t\t\tPyErr_Clear();\n\t\t\tconv = _convert_from_list(odescr, 0, 0);\n\t\t}\n\t\treturn (PyObject *)conv;\n\t}\n\n\tif (!PyArray_DescrConverter(odescr, &conv)) \n\t\treturn NULL;\n\t/* Get a new copy of it unless it's already a copy */\n\tif (copy && conv->fields == Py_None) {\n\t\tdescr = PyArray_DescrNew(conv);\n\t\tPy_DECREF(conv);\n\t\tconv = descr;\n\t}\n\treturn (PyObject *)conv;\n}\n\nstatic char doc_arraydescr_reduce[] = \"self.__reduce__() for pickling.\";\n\n/* return a tuple of (callable object, args, state) */\nstatic PyObject *\narraydescr_reduce(PyArray_Descr *self, PyObject *args)\n{\n\tPyObject *ret, *mod, *obj;\n\tPyObject *state;\n\tchar endian;\n\tint elsize, alignment;\n\n\tret = PyTuple_New(3);\n\tif (ret == NULL) return NULL;\n\tmod = PyImport_ImportModule(\"numpy.core.multiarray\");\n\tif (mod == NULL) {Py_DECREF(ret); return NULL;}\n\tobj = PyObject_GetAttrString(mod, \"dtype\");\n\tPy_DECREF(mod);\n\tif (obj == NULL) {Py_DECREF(ret); return NULL;}\n\tPyTuple_SET_ITEM(ret, 0, obj);\n\tif (PyTypeNum_ISUSERDEF(self->type_num) ||\t\t\\\n\t ((self->type_num == PyArray_VOID &&\t\t\t\\\n\t self->typeobj != &PyVoidArrType_Type))) {\n\t\tobj = (PyObject *)self->typeobj;\n\t\tPy_INCREF(obj);\n\t}\n\telse {\n\t\tobj = PyString_FromFormat(\"%c%d\",self->kind, self->elsize);\n\t}\n\tPyTuple_SET_ITEM(ret, 1, Py_BuildValue(\"(Nii)\", obj, 0, 1));\n\t\n\t/* Now return the state which is at least \n\t byteorder, subarray, and fields */\n\tendian = self->byteorder;\n\tif (endian == '=') {\n\t\tendian = '<';\n\t\tif (!PyArray_IsNativeByteOrder(endian)) endian = '>';\n\t}\n\tstate = PyTuple_New(5);\n\tPyTuple_SET_ITEM(state, 0, PyString_FromFormat(\"%c\", endian));\n\tPyTuple_SET_ITEM(state, 1, arraydescr_subdescr_get(self));\n\tif (self->fields && self->fields != Py_None) {\n\t\tPy_INCREF(self->fields);\n\t\tPyTuple_SET_ITEM(state, 2, self->fields);\n\t}\n\telse {\n\t\tPyTuple_SET_ITEM(state, 2, Py_None);\n\t\tPy_INCREF(Py_None);\n\t}\n\n\t/* for extended types it also includes elsize and alignment */\n\tif (PyTypeNum_ISEXTENDED(self->type_num)) {\n\t\telsize = self->elsize;\n\t\talignment = self->alignment;\n\t}\n\telse {elsize = -1; alignment = -1;}\n\n\tPyTuple_SET_ITEM(state, 3, PyInt_FromLong(elsize));\n\tPyTuple_SET_ITEM(state, 4, PyInt_FromLong(alignment));\n\n\tPyTuple_SET_ITEM(ret, 2, state);\n\treturn ret;\n}\n\n/* state is at least byteorder, subarray, and fields but could include elsize \n and alignment for EXTENDED arrays \n*/\nstatic char doc_arraydescr_setstate[] = \"self.__setstate__() for pickling.\";\n\nstatic PyObject *\narraydescr_setstate(PyArray_Descr *self, PyObject *args)\n{\n\tint elsize = -1, alignment = -1;\n\tchar endian;\n\tPyObject *subarray, *fields;\n\n\tif (self->fields == Py_None) {Py_INCREF(Py_None); return Py_None;}\n\n\tif (!PyArg_ParseTuple(args, \"(cOOii)\", &endian, &subarray, &fields,\n\t\t\t &elsize, &alignment)) return NULL;\n\t\n\tif (PyArray_IsNativeByteOrder(endian)) endian = '=';\n\n\tself->byteorder = endian;\n\tif (self->subarray) {\n\t\tPy_XDECREF(self->subarray->base);\n\t\tPy_XDECREF(self->subarray->shape);\n\t\t_pya_free(self->subarray);\n\t}\n\tself->subarray = NULL;\n\n\tif (subarray != Py_None) {\n\t\tself->subarray = _pya_malloc(sizeof(PyArray_ArrayDescr));\n\t\tself->subarray->base = (PyArray_Descr *)PyTuple_GET_ITEM(subarray, 0);\n\t\tPy_INCREF(self->subarray->base);\n\t\tself->subarray->shape = PyTuple_GET_ITEM(subarray, 1);\n\t\tPy_INCREF(self->subarray->shape);\n\t}\n\t\n\tif (fields != Py_None) {\n\t\tPy_XDECREF(self->fields);\n\t\tself->fields = fields;\n\t\tPy_INCREF(fields);\n\t}\n\t\n\tif (PyTypeNum_ISEXTENDED(self->type_num)) {\n\t\tself->elsize = elsize;\n\t\tself->alignment = alignment;\n\t}\n\t\n\tPy_INCREF(Py_None);\n\treturn Py_None;\n}\n\n\n/* returns a copy of the PyArray_Descr structure with the byteorder\n altered:\n no arguments: The byteorder is swapped (in all subfields as well)\n single argument: The byteorder is forced to the given state\n (in all subfields as well)\n\n Valid states: ('big', '>') or ('little' or '<')\n\t\t ('native', or '=')\n\n\t\t If a descr structure with | is encountered it's own\n\t\t byte-order is not changed but any fields are: \n*/\n\n/*OBJECT_API\n Deep bytorder change of a data-type descriptor\n*/\nstatic PyArray_Descr *\nPyArray_DescrNewByteorder(PyArray_Descr *self, char newendian)\n{\n\tPyArray_Descr *new;\n\tchar endian;\n\n\tnew = PyArray_DescrNew(self);\n\tendian = new->byteorder;\n\tif (endian != PyArray_IGNORE) {\n\t\tif (newendian == PyArray_SWAP) { /* swap byteorder */\n\t\t\tif PyArray_ISNBO(endian) endian = PyArray_OPPBYTE;\n\t\t\telse endian = PyArray_NATBYTE;\n\t\t\tnew->byteorder = endian;\n\t\t}\n\t\telse if (newendian != PyArray_IGNORE) {\n\t\t\tnew->byteorder = newendian;\n\t\t}\n\t}\n\tif (new->fields) {\n\t\tPyObject *newfields;\n\t\tPyObject *key, *value;\n\t\tPyObject *newvalue;\n\t\tPyObject *old;\n\t\tPyArray_Descr *newdescr;\n\t\tint pos = 0, len, i;\n\t\tnewfields = PyDict_New();\n\t\t/* make new dictionary with replaced */\n\t\t/* PyArray_Descr Objects */\n\t\twhile(PyDict_Next(self->fields, &pos, &key, &value)) {\n\t\t\tif (PyInt_Check(key) &&\t\t\t\\\n\t\t\t PyInt_AsLong(key) == -1) {\n\t\t\t\tPyDict_SetItem(newfields, key, value);\n\t\t\t\tcontinue;\n\t\t\t}\n\t\t\tif (!PyString_Check(key) ||\t \\\n\t\t\t !PyTuple_Check(value) ||\t\t\t\\\n\t\t\t ((len=PyTuple_GET_SIZE(value)) < 2))\n\t\t\t\tcontinue;\n\t\t\t\n\t\t\told = PyTuple_GET_ITEM(value, 0);\n\t\t\tif (!PyArray_DescrCheck(old)) continue;\n\t\t\tnewdescr = PyArray_DescrNewByteorder\t\t\\\n\t\t\t\t((PyArray_Descr *)old, newendian);\n\t\t\tif (newdescr == NULL) {\n\t\t\t\tPy_DECREF(newfields); Py_DECREF(new);\n\t\t\t\treturn NULL;\n\t\t\t}\n\t\t\tnewvalue = PyTuple_New(len);\n\t\t\tPyTuple_SET_ITEM(newvalue, 0,\t\t\\\n\t\t\t\t\t (PyObject *)newdescr);\n\t\t\tfor(i=1; ifields);\n\t\tnew->fields = newfields;\n\t}\n\tif (new->subarray) {\n\t\tPy_DECREF(new->subarray->base);\n\t\tnew->subarray->base = PyArray_DescrNewByteorder \\\n\t\t\t(self->subarray->base, newendian);\n\t}\n\treturn new;\n}\n\n\nstatic char doc_arraydescr_newbyteorder[] = \"self.newbyteorder()\"\n\t\" returns a copy of the dtype object\\n\"\n\t\" with altered byteorders. If is not given all byteorders\\n\"\n\t\" are swapped. Otherwise endian can be '>', '<', or '=' to force\\n\"\n\t\" a byteorder. Descriptors in all fields are also updated in the\\n\"\n\t\" new dtype object.\";\n\nstatic PyObject *\narraydescr_newbyteorder(PyArray_Descr *self, PyObject *args) \n{\n\tchar endian=PyArray_SWAP;\n\t\n\tif (!PyArg_ParseTuple(args, \"|O&\", PyArray_ByteorderConverter,\n\t\t\t &endian)) return NULL;\n\t\t\t\n\treturn (PyObject *)PyArray_DescrNewByteorder(self, endian);\n}\n\nstatic PyMethodDef arraydescr_methods[] = {\n /* for pickling */\n {\"__reduce__\", (PyCFunction)arraydescr_reduce, METH_VARARGS, \n\t doc_arraydescr_reduce},\n\t{\"__setstate__\", (PyCFunction)arraydescr_setstate, METH_VARARGS,\n\t doc_arraydescr_setstate},\n\n\t{\"newbyteorder\", (PyCFunction)arraydescr_newbyteorder, METH_VARARGS,\n\t doc_arraydescr_newbyteorder},\n {NULL,\t\tNULL}\t\t/* sentinel */\n};\n\nstatic PyObject *\narraydescr_str(PyArray_Descr *self)\n{\n\tPyObject *sub;\n\n\tif (self->fields && self->fields != Py_None) {\n\t\tPyObject *lst;\n\t\tlst = arraydescr_protocol_descr_get(self);\n\t\tif (!lst) {\n\t\t\tsub = PyString_FromString(\"\");\n\t\t\tPyErr_Clear();\n\t\t}\n\t\telse sub = PyObject_Str(lst);\n\t\tPy_XDECREF(lst);\n\t\tif (self->type_num != PyArray_VOID) {\n\t\t\tPyObject *p;\n\t\t\tPyObject *t=PyString_FromString(\"'\");\n\t\t\tp = arraydescr_protocol_typestr_get(self);\n\t\t\tPyString_Concat(&p, t);\n\t\t\tPyString_ConcatAndDel(&t, p);\n\t\t\tp = PyString_FromString(\"(\");\n\t\t\tPyString_ConcatAndDel(&p, t);\n\t\t\tPyString_ConcatAndDel(&p, PyString_FromString(\", \"));\n\t\t\tPyString_ConcatAndDel(&p, sub);\n\t\t\tPyString_ConcatAndDel(&p, PyString_FromString(\")\"));\n\t\t\tsub = p;\n\t\t}\n\t}\n\telse if (self->subarray) {\n\t\tPyObject *p;\n\t\tPyObject *t = PyString_FromString(\"(\");\n\t\tp = arraydescr_str(self->subarray->base);\n\t\tPyString_ConcatAndDel(&t, p);\n\t\tPyString_ConcatAndDel(&t, PyString_FromString(\",\"));\n\t\tPyString_ConcatAndDel(&t, PyObject_Str(self->subarray->shape));\n\t\tPyString_ConcatAndDel(&t, PyString_FromString(\")\"));\n\t\tsub = t;\n\t}\n\telse {\n\t\tPyObject *t=PyString_FromString(\"'\");\n\t\tsub = arraydescr_protocol_typestr_get(self);\n\t\tPyString_Concat(&sub, t);\n\t\tPyString_ConcatAndDel(&t, sub);\n\t\tsub = t;\n\t}\n\treturn sub;\n}\n\nstatic PyObject *\narraydescr_repr(PyArray_Descr *self)\n{\n\tPyObject *sub, *s;\n\ts = PyString_FromString(\"dtype(\");\n sub = arraydescr_str(self);\n\tPyString_ConcatAndDel(&s, sub);\n\tsub = PyString_FromString(\")\");\n\tPyString_ConcatAndDel(&s, sub);\n\treturn s;\n}\n\nstatic int\narraydescr_compare(PyArray_Descr *self, PyObject *other)\n{\n \tif (!PyArray_DescrCheck(other)) {\n\t\tPyErr_SetString(PyExc_TypeError,\n\t\t\t\t\"not a dtype object.\");\n\t\treturn -1;\n\t}\n\tif (PyArray_EquivTypes(self, (PyArray_Descr *)other)) return 0;\n\tif (PyArray_CanCastTo(self, (PyArray_Descr *)other)) return -1;\n\treturn 1;\n}\n\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 0, \t /* tp_as_mapping */\n 0,\t\t\t\t\t/* tp_hash */\n 0,\t\t\t\t\t/* tp_call */\n (reprfunc)arraydescr_str, /* tp_str */\n 0,\t \t/* tp_getattro */\n 0,\t\t\t\t\t/* tp_setattro */\n 0,\t\t\t\t\t/* tp_as_buffer */\n Py_TPFLAGS_DEFAULT, /* tp_flags */\n 0,\t\t\t\t\t/* tp_doc */\n 0, \t /* tp_traverse */\n 0,\t\t\t\t\t/* tp_clear */\n 0,\t\t\t\t\t/* tp_richcompare */\n 0,\t\t\t\t\t/* tp_weaklistoffset */\n 0, \t /* tp_iter */\n 0,\t \t/* tp_iternext */\n arraydescr_methods,\t \t /* tp_methods */\n arraydescr_members,\t /* tp_members */\n arraydescr_getsets, /* tp_getset */\n 0,\t\t\t\t\t /* tp_base */\n 0,\t\t\t\t\t /* tp_dict */\n 0,\t\t\t\t\t /* tp_descr_get */\n 0,\t\t\t\t\t /* tp_descr_set */\n 0,\t\t\t\t\t /* tp_dictoffset */\n 0, \t \t /* tp_init */\n 0, \t /* tp_alloc */\n arraydescr_new,\t /* tp_new */\n 0,\t /* tp_free */\n 0,\t\t\t\t\t /* tp_is_gc */\n 0,\t\t\t\t\t /* tp_bases */\n 0,\t\t\t\t\t /* tp_mro */\n 0,\t\t\t\t\t /* tp_cache */\n 0,\t\t\t\t\t /* tp_subclasses */\n 0\t\t\t\t\t /* tp_weaklist */\n};\n", + "source_code_before": "/*\n Provide multidimensional arrays as a basic object type in python. \n\nBased on Original Numeric implementation\nCopyright (c) 1995, 1996, 1997 Jim Hugunin, hugunin@mit.edu\n\nwith contributions from many Numeric Python developers 1995-2004 \n\nHeavily modified in 2005 with inspiration from Numarray \n\nby\n\nTravis Oliphant\nAssistant Professor at\nBrigham Young University \n\nmaintainer email: oliphant.travis@ieee.org\n\nNumarray design (which provided guidance) by \nSpace Science Telescope Institute \n (J. Todd Miller, Perry Greenfield, Rick White)\n*/\n\n/*OBJECT_API\n Get Priority from object\n*/\nstatic double\nPyArray_GetPriority(PyObject *obj, double default_) \n{\n PyObject *ret;\n double priority=PyArray_PRIORITY;\n\n\tif (PyArray_CheckExact(obj))\n\t\treturn priority;\n if (PyBigArray_CheckExact(obj)) \n return PyArray_BIG_PRIORITY;\n\n ret = PyObject_GetAttrString(obj, \"__array_priority__\");\n if (ret != NULL) priority = PyFloat_AsDouble(ret);\n if (PyErr_Occurred()) {\n PyErr_Clear(); \n priority = default_;\n }\n Py_XDECREF(ret);\n return priority; \n}\n\n/* Backward compatibility only */\n/* In both Zero and One\n\n ***You must free the memory once you are done with it\n using PyDataMem_FREE(ptr) or you create a memory leak***\n\n If arr is an Object array you are getting a \n BORROWED reference to Zero or One.\n Do not DECREF.\n Please INCREF if you will be hanging on to it.\n\n The memory for the ptr still must be freed in any case;\n*/\n\n\n/*OBJECT_API\n Get pointer to zero of correct type for array.\n*/\nstatic char *\nPyArray_Zero(PyArrayObject *arr)\n{\n char *zeroval;\n int ret, storeflags;\n PyObject *obj;\n\n zeroval = PyDataMem_NEW(arr->descr->elsize);\n if (zeroval == NULL) {\n PyErr_SetNone(PyExc_MemoryError);\n return NULL;\n }\n\n\tobj=PyInt_FromLong((long) 0);\n if (PyArray_ISOBJECT(arr)) {\n memcpy(zeroval, &obj, sizeof(PyObject *));\n Py_DECREF(obj);\n return zeroval;\n }\n\tstoreflags = arr->flags;\n\tarr->flags |= BEHAVED_FLAGS;\n ret = arr->descr->f->setitem(obj, zeroval, arr);\n\tarr->flags = storeflags;\n\tPy_DECREF(obj);\n\tif (ret < 0) {\n\t\tPyDataMem_FREE(zeroval);\n\t\treturn NULL;\n\t}\n return zeroval;\n}\n\n/*OBJECT_API\n Get pointer to one of correct type for array\n*/\nstatic char *\nPyArray_One(PyArrayObject *arr)\n{\n char *oneval;\n int ret, storeflags;\n PyObject *obj;\n\n oneval = PyDataMem_NEW(arr->descr->elsize);\n if (oneval == NULL) {\n PyErr_SetNone(PyExc_MemoryError);\n return NULL;\n }\n\n obj = PyInt_FromLong((long) 1);\n if (PyArray_ISOBJECT(arr)) {\n memcpy(oneval, &obj, sizeof(PyObject *));\n Py_DECREF(obj);\n return oneval;\n } \n\n\tstoreflags = arr->flags;\n\tarr->flags |= BEHAVED_FLAGS;\n ret = arr->descr->f->setitem(obj, oneval, arr);\n\tarr->flags = storeflags;\n Py_DECREF(obj);\n if (ret < 0) {\n PyDataMem_FREE(oneval);\n return NULL;\n }\n return oneval;\n}\n\n/* End deprecated */\n\n\nstatic int \ndo_sliced_copy(char *dest, intp *dest_strides, intp *dest_dimensions,\n\t int dest_nd, char *src, intp *src_strides, \n\t intp *src_dimensions, int src_nd, int elsize, \n\t int copies) {\n intp i, j;\n\t\n if (src_nd == 0 && dest_nd == 0) {\n for(j=0; j src_nd) {\n for(i=0; i<*dest_dimensions; i++, dest += *dest_strides) {\n if (do_sliced_copy(dest, dest_strides+1, \n dest_dimensions+1, dest_nd-1,\n src, src_strides, \n src_dimensions, src_nd, \n elsize, copies) == -1) \n return -1;\n }\n return 0;\n }\n\t\n if (dest_nd == 1) {\n if (*dest_dimensions != *src_dimensions) {\n PyErr_SetString(PyExc_ValueError, \n \"matrices are not aligned for copy\");\n return -1;\n }\n for(i=0; i<*dest_dimensions; i++, src += *src_strides) {\n for(j=0; j 0) {\n if (((*dest_strides)[*dest_nd-1] == *elsize) && \n ((*src_strides)[*src_nd-1] == *elsize)) {\n if ((*dest_dimensions)[*dest_nd-1] != \n (*src_dimensions)[*src_nd-1]) {\n\t\t\t\tPyErr_SetString(PyExc_ValueError, \n\t\t\t\t\t\t\"matrices are not aligned\");\n return -1;\n }\n *elsize *= (*dest_dimensions)[*dest_nd-1];\n *dest_nd-=1; *src_nd-=1;\n } else {\n break;\n }\n }\n if (*src_nd == 0) {\n while (*dest_nd > 0) {\n if (((*dest_strides)[*dest_nd-1] == *elsize)) {\n *copies *= (*dest_dimensions)[*dest_nd-1];\n *dest_nd-=1;\n } else {\n break;\n }\n }\n }\n return 0;\n}\n\nstatic char *\ncontiguous_data(PyArrayObject *src) \n{\n intp dest_strides[MAX_DIMS], *dest_strides_ptr;\n intp *dest_dimensions=src->dimensions;\n int dest_nd=src->nd;\n intp *src_strides = src->strides;\n intp *src_dimensions=src->dimensions;\n int src_nd=src->nd;\n int elsize=src->descr->elsize;\n int copies=1;\n int ret, i;\n intp stride=elsize;\n char *new_data;\n\t\n for(i=dest_nd-1; i>=0; i--) {\n dest_strides[i] = stride;\n stride *= dest_dimensions[i];\n }\n\t\n dest_strides_ptr = dest_strides;\n\t\n if (optimize_slices(&dest_strides_ptr, &dest_dimensions, &dest_nd,\n &src_strides, &src_dimensions, &src_nd,\n &elsize, &copies) == -1) \n return NULL;\n\t\n new_data = (char *)_pya_malloc(stride);\n\t\n ret = do_sliced_copy(new_data, dest_strides_ptr, dest_dimensions, \n dest_nd, src->data, src_strides, \n src_dimensions, src_nd, elsize, copies);\n\t\n if (ret != -1) { return new_data; }\n else { _pya_free(new_data); return NULL; }\n}\n\n/* end Helper functions */\n\n\nstatic PyObject *PyArray_New(PyTypeObject *, int nd, intp *, \n int, intp *, void *, int, int, PyObject *);\n\n/* C-API functions */\n\n/* Used for arrays of python objects to increment the reference count of */\n/* every python object in the array. */\n/*OBJECT_API\n For object arrays, increment all internal references.\n*/\nstatic int \nPyArray_INCREF(PyArrayObject *mp) \n{\n\tintp i, n;\n\n PyObject **data, **data2;\n\t\n if (mp->descr->type_num != PyArray_OBJECT) return 0;\n\t\n if (PyArray_ISONESEGMENT(mp)) {\n data = (PyObject **)mp->data;\n } else {\n if ((data = (PyObject **)contiguous_data(mp)) == NULL) \n return -1;\n }\n\t\n n = PyArray_SIZE(mp);\n data2 = data;\n for(i=0; idescr->type_num != PyArray_OBJECT) return 0;\n\t\n if (PyArray_ISONESEGMENT(mp)) {\n data = (PyObject **)mp->data;\n } else {\n if ((data = (PyObject **)contiguous_data(mp)) == NULL) \n return -1;\n }\n\t\n n = PyArray_SIZE(mp);\n data2 = data; \n for(i=0; i 0; n--, a += 1) {\n b = a + 1;\n c = *a; *a++ = *b; *b = c;\n }\n break;\n case 4:\n for (a = (char*)p ; n > 0; n--, a += 2) {\n b = a + 3;\n c = *a; *a++ = *b; *b-- = c;\n c = *a; *a++ = *b; *b = c;\n }\n break;\n case 8:\n for (a = (char*)p ; n > 0; n--, a += 4) {\n b = a + 7;\n c = *a; *a++ = *b; *b-- = c;\n c = *a; *a++ = *b; *b-- = c;\n c = *a; *a++ = *b; *b-- = c;\n c = *a; *a++ = *b; *b = c;\n }\n break;\n default:\n m = size / 2;\n for (a = (char *)p ; n > 0; n--, a += m) {\n b = a + (size-1);\n for (j=0; j 1, then dst must be contiguous */\nstatic void\ncopy_and_swap(void *dst, void *src, int itemsize, intp numitems,\n intp srcstrides, int swap) \n{\n int i;\n char *s1 = (char *)src;\n char *d1 = (char *)dst;\n \n\n if ((numitems == 1) || (itemsize == srcstrides)) \n memcpy(d1, s1, itemsize*numitems);\n else { \n for (i = 0; i < numitems; i++) {\n memcpy(d1, s1, itemsize);\n d1 += itemsize;\n s1 += srcstrides;\n } \n }\n\n if (swap)\n byte_swap_vector(d1, numitems, itemsize);\n}\n\nstatic PyArray_Descr **userdescrs=NULL;\n#define error_converting(x) (((x) == -1) && PyErr_Occurred())\n\n/* Computer-generated arraytype and scalartype code */\n#include \"scalartypes.inc\"\n#include \"arraytypes.inc\"\n\n\n/* Helper functions */\n\n/*OBJECT_API*/\nstatic intp\nPyArray_PyIntAsIntp(PyObject *o)\n{\n\tlonglong long_value = -1;\n\tPyObject *obj;\n\tstatic char *msg = \"an integer is required\";\n\tPyObject *arr;\n\tPyArray_Descr *descr;\n\tintp ret;\n\n\tif (!o) {\n\t\tPyErr_SetString(PyExc_TypeError, msg);\n\t\treturn -1;\n\t}\n\n\tif (PyInt_Check(o)) {\n\t\tlong_value = (longlong) PyInt_AS_LONG(o);\n\t\tgoto finish;\n\t} else if (PyLong_Check(o)) {\n\t\tlong_value = (longlong) PyLong_AsLongLong(o);\n\t\tgoto finish;\n\t}\n\n#if SIZEOF_INTP == SIZEOF_LONG \n\tdescr = &LONG_Descr;\n#elif SIZEOF_INTP == SIZEOF_INT\n\tdescr = &INT_Descr;\n#else\n\tdescr = &LONGLONG_DESCR;\n#endif\n\tarr = NULL;\n\n\tif (PyArray_Check(o)) {\n\t\tif (PyArray_SIZE(o)!=1 || !PyArray_ISINTEGER(o)) {\n\t\t\tPyErr_SetString(PyExc_TypeError, msg);\n\t\t\treturn -1;\n\t\t}\n\t\tPy_INCREF(descr);\n\t\tarr = PyArray_CastToType((PyArrayObject *)o, descr, 0);\n\t}\n\telse if (PyArray_IsScalar(o, Integer)) {\n\t\tPy_INCREF(descr);\n\t\tarr = PyArray_FromScalar(o, descr);\n\t}\n\tif (arr != NULL) {\n\t\tret = *((intp *)PyArray_DATA(arr));\n\t\tPy_DECREF(arr);\n\t\treturn ret;\n\t}\t\t\n\tif (o->ob_type->tp_as_number != NULL &&\t\t\t\\\n\t o->ob_type->tp_as_number->nb_long != NULL) {\n\t\tobj = o->ob_type->tp_as_number->nb_long(o);\n\t\tif (obj != NULL) {\n\t\t\tlong_value = (longlong) PyLong_AsLongLong(obj);\n\t\t\tPy_DECREF(obj);\n\t\t}\n\t}\n\telse if (o->ob_type->tp_as_number != NULL &&\t\t\\\n\t\t o->ob_type->tp_as_number->nb_int != NULL) {\n\t\tobj = o->ob_type->tp_as_number->nb_int(o);\n\t\tif (obj != NULL) {\n\t\t\tlong_value = (longlong) PyLong_AsLongLong(obj);\n\t\t\tPy_DECREF(obj);\n\t\t}\n\t}\n\telse {\n\t\tPyErr_SetString(PyExc_NotImplementedError,\"\");\n\t}\n\t\n finish:\n\tif error_converting(long_value) {\n\t\tPyErr_SetString(PyExc_TypeError, msg);\n\t\treturn -1;\n\t}\n\t\n#if (SIZEOF_LONGLONG > SIZEOF_INTP)\n\tif ((long_value < MIN_INTP) || (long_value > MAX_INTP)) {\n\t\tPyErr_SetString(PyExc_ValueError,\n\t\t\t\t\"integer won't fit into a C intp\");\n\t\treturn -1;\n\t}\n#endif\n\treturn (intp) long_value;\n}\n\n\nstatic PyObject *array_int(PyArrayObject *v);\n\n/*OBJECT_API*/\nstatic int\nPyArray_PyIntAsInt(PyObject *o)\n{\n\tlong long_value = -1;\n\tPyObject *obj;\n\tstatic char *msg = \"an integer is required\";\n\tPyObject *arr;\n\tPyArray_Descr *descr;\n\tint ret;\n\n\t\n\tif (!o) {\n\t\tPyErr_SetString(PyExc_TypeError, msg);\n\t\treturn -1;\n\t}\n\n\tif (PyInt_Check(o)) {\n\t\tlong_value = (long) PyInt_AS_LONG(o);\n\t\tgoto finish;\n\t} else if (PyLong_Check(o)) {\n\t\tlong_value = (long) PyLong_AsLong(o);\n\t\tgoto finish;\n\t}\n\n\tdescr = &INT_Descr;\n\tarr=NULL;\n\tif (PyArray_Check(o)) {\n\t\tif (PyArray_SIZE(o)!=1 || !PyArray_ISINTEGER(o)) {\n\t\t\tPyErr_SetString(PyExc_TypeError, msg);\n\t\t\treturn -1;\n\t\t}\n\t\tPy_INCREF(descr);\n\t\tarr = PyArray_CastToType((PyArrayObject *)o, descr, 0);\n\t}\n\tif (PyArray_IsScalar(o, Integer)) {\n\t\tPy_INCREF(descr);\n\t\tarr = PyArray_FromScalar(o, descr);\n\t}\n\tif (arr != NULL) {\n\t\tret = *((int *)PyArray_DATA(arr));\n\t\tPy_DECREF(arr);\n\t\treturn ret;\n\t}\t\t\n\tif (o->ob_type->tp_as_number != NULL &&\t\t\\\n\t o->ob_type->tp_as_number->nb_int != NULL) {\n\t\tobj = o->ob_type->tp_as_number->nb_int(o);\n\t\tif (obj == NULL) return -1;\n\t\tlong_value = (long) PyLong_AsLong(obj);\n\t\tPy_DECREF(obj);\n\t}\n\telse if (o->ob_type->tp_as_number != NULL &&\t\t\t\\\n\t\t o->ob_type->tp_as_number->nb_long != NULL) {\n\t\tobj = o->ob_type->tp_as_number->nb_long(o);\n\t\tif (obj == NULL) return -1;\n\t\tlong_value = (long) PyLong_AsLong(obj);\n\t\tPy_DECREF(obj);\n\t}\t\t\n\telse {\n\t\tPyErr_SetString(PyExc_NotImplementedError,\"\");\n\t}\n\n finish:\n\tif error_converting(long_value) {\n\t\tPyErr_SetString(PyExc_TypeError, msg);\n\t\treturn -1;\n\t}\n\t\n#if (SIZEOF_LONG > SIZEOF_INT)\n\tif ((long_value < INT_MIN) || (long_value > INT_MAX)) {\n\t\tPyErr_SetString(PyExc_ValueError,\n\t\t\t\t\"integer won't fit into a C int\");\n\t\treturn -1;\n\t}\n#endif\n\treturn (int) long_value;\n}\n\nstatic char *\nindex2ptr(PyArrayObject *mp, intp i) \n{\n\tif(mp->nd == 0) {\n\t\tPyErr_SetString(PyExc_IndexError, \n\t\t\t\t\"0-d arrays can't be indexed\");\n\t\treturn NULL;\n\t}\n\tif (i==0 && mp->dimensions[0] > 0)\n\t\treturn mp->data;\n\t\n if (mp->nd>0 && i>0 && i < mp->dimensions[0]) {\n return mp->data+i*mp->strides[0];\n }\n PyErr_SetString(PyExc_IndexError,\"index out of bounds\");\n return NULL;\n}\n\n/*OBJECT_API\n Compute the size of an array (in number of items)\n*/\nstatic intp \nPyArray_Size(PyObject *op) \n{\n if (PyArray_Check(op)) {\n return PyArray_SIZE((PyArrayObject *)op);\n } \n\telse {\n return 0;\n }\n}\n\n/* If destination is not the right type, then src \n will be cast to destination. \n*/\n\n/* Does a flat iterator-based copy. \n\n The arrays are assumed to have the same number of elements\n They can be different sizes and have different types however. \n*/\n\n/*OBJECT_API\n Copy an Array into another array.\n*/\nstatic int\nPyArray_CopyInto(PyArrayObject *dest, PyArrayObject *src)\n{\n intp dsize, ssize, sbytes, ncopies;\n\tint elsize, index;\n PyArrayIterObject *dit=NULL;\n PyArrayIterObject *sit=NULL;\n\tchar *dptr;\n\tint swap;\n PyArray_CopySwapFunc *copyswap;\n PyArray_CopySwapNFunc *copyswapn;\n \n if (!PyArray_ISWRITEABLE(dest)) {\n PyErr_SetString(PyExc_RuntimeError, \n \"cannot write to array\");\n return -1;\n }\n\n if (!PyArray_EquivArrTypes(dest, src)) {\n return PyArray_CastTo(dest, src);\n }\n\n dsize = PyArray_SIZE(dest);\n ssize = PyArray_SIZE(src);\n\tif (ssize == 0) return 0;\n if (dsize % ssize != 0) {\n PyErr_SetString(PyExc_ValueError, \n \"number of elements in destination must be \"\\\n \"integer multiple of number of \"\\\n \"elements in source\");\n return -1;\n }\n ncopies = (dsize / ssize);\n\n\tswap = PyArray_ISNOTSWAPPED(dest) != PyArray_ISNOTSWAPPED(src);\n\tcopyswap = dest->descr->f->copyswap;\n\tcopyswapn = dest->descr->f->copyswapn;\n\n elsize = dest->descr->elsize;\n\n if ((PyArray_ISCONTIGUOUS(dest) && PyArray_ISCONTIGUOUS(src))\t\\\n\t || (PyArray_ISFORTRAN(dest) && PyArray_ISFORTRAN(src))) {\n \n PyArray_XDECREF(dest);\n dptr = dest->data;\n sbytes = ssize * src->descr->elsize;\n while(ncopies--) {\n memmove(dptr, src->data, sbytes);\n dptr += sbytes;\n }\n\t\tif (swap)\n\t\t\tcopyswapn(dest->data, NULL, dsize, 1, elsize);\n PyArray_INCREF(dest);\n return 0;\n }\n\n dit = (PyArrayIterObject *)PyArray_IterNew((PyObject *)dest);\n sit = (PyArrayIterObject *)PyArray_IterNew((PyObject *)src);\n\n if ((dit == NULL) || (sit == NULL)) {\n Py_XDECREF(dit);\n Py_XDECREF(sit);\n return -1;\n }\n\n PyArray_XDECREF(dest);\n while(ncopies--) {\n index = ssize;\n while(index--) {\n memmove(dit->dataptr, sit->dataptr, elsize);\n\t\t\tif (swap)\n\t\t\t\tcopyswap(dit->dataptr, NULL, 1, elsize);\n PyArray_ITER_NEXT(dit);\n PyArray_ITER_NEXT(sit);\n }\n PyArray_ITER_RESET(sit);\n } \n PyArray_INCREF(dest);\n Py_DECREF(dit);\n Py_DECREF(sit);\n\treturn 0;\n}\n\n\nstatic int \nPyArray_CopyObject(PyArrayObject *dest, PyObject *src_object) \n{\n PyArrayObject *src;\n int ret;\n\n\tPy_INCREF(dest->descr);\n src = (PyArrayObject *)PyArray_FromAny(src_object,\n dest->descr, 0,\n dest->nd, FORTRAN_IF(dest), NULL);\n if (src == NULL) return -1;\n\n ret = PyArray_CopyInto(dest, src);\n Py_DECREF(src);\n return ret;\n}\n\n\n/* These are also old calls (should use PyArray_New) */\n\n/* They all zero-out the memory as previously done */\n\n/* steals reference to descr -- and enforces native byteorder on it.*/\n/*OBJECT_API\n Like FromDimsAndData but uses the Descr structure instead of typecode\n as input.\n*/\nstatic PyObject *\nPyArray_FromDimsAndDataAndDescr(int nd, int *d, \n PyArray_Descr *descr,\n char *data)\n{\n\tPyObject *ret;\n#if SIZEOF_INTP != SIZEOF_INT\n\tint i;\n\tintp newd[MAX_DIMS];\n#endif\n\n\tif (!PyArray_ISNBO(descr->byteorder))\n\t\tdescr->byteorder = '=';\n\t\n#if SIZEOF_INTP != SIZEOF_INT\n\tfor (i=0; itype_num != PyArray_OBJECT)) {\n\t\tmemset(PyArray_DATA(ret), 0, PyArray_NBYTES(ret));\n\t}\n\treturn ret;\n}\n\n/* end old calls */\n\n\n/*OBJECT_API\n Copy an array.\n*/\nstatic PyObject *\nPyArray_NewCopy(PyArrayObject *m1, int fortran)\n{\n\tPyArrayObject *ret;\n\tif (fortran < 0) fortran = PyArray_ISFORTRAN(m1);\n\t\n\tPy_INCREF(m1->descr);\n\tret = (PyArrayObject *)PyArray_NewFromDescr(m1->ob_type, \n\t\t\t\t\t\t m1->descr,\n\t\t\t\t\t\t m1->nd, \n\t\t\t\t\t\t m1->dimensions,\n\t\t\t\t\t\t NULL, NULL, \n\t\t\t\t\t\t fortran, \n\t\t\t\t\t\t (PyObject *)m1);\n\tif (ret == NULL) return NULL;\n if (PyArray_CopyInto(ret, m1) == -1) {\n Py_DECREF(ret);\n return NULL;\n }\n\t\n return (PyObject *)ret;\t\n}\n\nstatic PyObject *array_big_item(PyArrayObject *, intp);\n\n/* Does nothing with descr (cannot be NULL) */\n/*OBJECT_API\n Get scalar-equivalent to a region of memory described by a descriptor.\n*/\nstatic PyObject *\nPyArray_Scalar(void *data, PyArray_Descr *descr, PyObject *base)\n{\n\tPyTypeObject *type;\n\tPyObject *obj;\n void *destptr;\n PyArray_CopySwapFunc *copyswap;\n\tint type_num;\n\tint itemsize;\n\tint swap;\n\n\ttype_num = descr->type_num;\n\tif (type_num == PyArray_BOOL)\n\t\tPyArrayScalar_RETURN_BOOL_FROM_LONG(*(Bool*)data);\n\telse if (type_num == PyArray_OBJECT) {\n\t\tPy_INCREF(*((PyObject **)data));\n\t\treturn *((PyObject **)data);\n\t}\n\titemsize = descr->elsize;\n type = descr->typeobj;\n copyswap = descr->f->copyswap;\n\tswap = !PyArray_ISNBO(descr->byteorder);\n\tif (type->tp_itemsize != 0) /* String type */\n\t\tobj = type->tp_alloc(type, itemsize);\n\telse\n\t\tobj = type->tp_alloc(type, 0);\n\tif (obj == NULL) return NULL;\n\tif PyTypeNum_ISEXTENDED(type_num) { \n\t\tif (type_num == PyArray_STRING) {\n\t\t\tdestptr = PyString_AS_STRING(obj);\n\t\t\t((PyStringObject *)obj)->ob_shash = -1;\n\t\t\t((PyStringObject *)obj)->ob_sstate =\t\\\n\t\t\t\tSSTATE_NOT_INTERNED; \n\t\t}\n\t\telse if (type_num == PyArray_UNICODE) {\n\t\t\tPyUnicodeObject *uni = (PyUnicodeObject*)obj;\n\t\t\tint length = itemsize / sizeof(Py_UNICODE);\n\t\t\t/* Need an extra slot and need to use \n\t\t\t Python memory manager */\n\t\t\tuni->str = NULL;\n\t\t\tdestptr = PyMem_NEW(Py_UNICODE, length+1);\n\t\t\tif (destptr == NULL) {\n Py_DECREF(obj);\n\t\t\t\treturn PyErr_NoMemory();\n\t\t\t}\n\t\t\tuni->str = (Py_UNICODE *)destptr;\n\t\t\tuni->str[0] = 0;\n\t\t\tuni->str[length] = 0;\n\t\t\tuni->length = length;\n\t\t\tuni->hash = -1;\n\t\t\tuni->defenc = NULL;\n\t\t}\n\t\telse { \n\t\t\tPyVoidScalarObject *vobj = (PyVoidScalarObject *)obj;\n\t\t\tvobj->base = NULL;\n\t\t\tvobj->descr = descr;\n\t\t\tPy_INCREF(descr);\n\t\t\tvobj->obval = NULL;\n\t\t\tvobj->ob_size = itemsize;\n\t\t\tvobj->flags = BEHAVED_FLAGS | OWNDATA;\n\t\t\tswap = 0;\n\t\t\tif (descr->fields) {\n\t\t\t\tif (base) {\n\t\t\t\t\tPy_INCREF(base);\n\t\t\t\t\tvobj->base = base;\n\t\t\t\t\tvobj->flags = PyArray_FLAGS(base);\n\t\t\t\t\tvobj->flags &= ~OWNDATA;\n\t\t\t\t\tvobj->obval = data;\n\t\t\t\t\treturn obj;\n\t\t\t\t}\n\t\t\t}\n\t\t\tdestptr = PyDataMem_NEW(itemsize);\n\t\t\tif (destptr == NULL) {\n Py_DECREF(obj);\n\t\t\t\treturn PyErr_NoMemory();\n\t\t\t}\n\t\t\tvobj->obval = destptr;\n\t\t}\n\t}\n\telse {\n\t\tdestptr = _SOFFSET_(obj, type_num);\n\t}\n\t/* copyswap for OBJECT increments the reference count */\n copyswap(destptr, data, swap, itemsize);\n\treturn obj;\n}\n\n/* returns an Array-Scalar Object of the type of arr\n from the given pointer to memory -- main Scalar creation function\n default new method calls this. \n*/\n\n/* Ideally, here the descriptor would contain all the information needed.\n So, that we simply need the data and the descriptor, and perhaps\n a flag \n*/\n\n/*OBJECT_API\n Get scalar-equivalent to 0-d array\n*/\nstatic PyObject *\nPyArray_ToScalar(void *data, PyArrayObject *arr)\n{\n\treturn PyArray_Scalar(data, arr->descr, (PyObject *)arr);\n}\n\n\n/* Return Python scalar if 0-d array object is encountered */\n\n/*OBJECT_API\n Return either an array or the appropriate Python object if the array\n is 0d and matches a Python type.\n*/\nstatic PyObject *\nPyArray_Return(PyArrayObject *mp) \n{\n \n\n\tif (mp == NULL) return NULL;\n\n if (PyErr_Occurred()) {\n Py_XDECREF(mp);\n return NULL;\n }\n\n\tif (!PyArray_Check(mp)) return (PyObject *)mp;\n\t\n\tif (mp->nd == 0) {\n\t\tPyObject *ret;\n\t\tret = PyArray_ToScalar(mp->data, mp);\n\t\tPy_DECREF(mp);\n\t\treturn ret;\n\t}\n\telse {\n\t\treturn (PyObject *)mp;\n\t}\n}\n\n/*\n returns typenum to associate with this type >=PyArray_USERDEF.\n Also creates a copy of the VOID_DESCR table inserting it's typeobject in\n and it's typenum in the appropriate place.\n \n needs the userdecrs table and PyArray_NUMUSER variables\n defined in arratypes.inc\n*/\n/*OBJECT_API\n Register Data type\n*/\nstatic int \nPyArray_RegisterDataType(PyTypeObject *type)\n{\n\tPyArray_Descr *descr;\n\tPyObject *obj;\n\tint typenum;\n\tint i;\n\t\n\tif ((type == &PyVoidArrType_Type) ||\t\t\t\\\n\t !PyType_IsSubtype(type, &PyVoidArrType_Type)) {\n\t\tPyErr_SetString(PyExc_ValueError, \n\t\t\t\t\"can only register void subtypes\");\n\t\treturn -1;\n\t}\n\t/* See if this type is already registered */\n\tfor (i=0; itypeobj == type)\n\t\t\treturn descr->type_num;\n\t}\n\tdescr = PyArray_DescrNewFromType(PyArray_VOID);\n\ttypenum = PyArray_USERDEF + PyArray_NUMUSERTYPES;\n\tdescr->type_num = typenum;\n descr->typeobj = type;\n\tobj = PyObject_GetAttrString((PyObject *)type,\"itemsize\");\n\tif (obj) {\n\t\ti = PyInt_AsLong(obj);\n\t\tif ((i < 0) && (PyErr_Occurred())) PyErr_Clear();\n\t\telse descr->elsize = i;\n\t\tPy_DECREF(obj);\n\t}\n\tPy_INCREF(type);\n\tuserdescrs = realloc(userdescrs, \n\t\t\t (PyArray_NUMUSERTYPES+1)*sizeof(void *));\n if (userdescrs == NULL) {\n PyErr_SetString(PyExc_MemoryError, \"RegisterDataType\");\n\t\tPy_DECREF(descr);\n return -1;\n }\n\tuserdescrs[PyArray_NUMUSERTYPES++] = descr;\n\treturn typenum;\n}\n\n\n/* \n copyies over from the old descr table for anything\n NULL or zero in what is given. \n DECREF's the Descr already there.\n places a pointer to the new one into the slot.\n*/\n\n/* steals a reference to descr */\n/*OBJECT_API\n Insert Descr Table\n*/\nstatic int\nPyArray_RegisterDescrForType(int typenum, PyArray_Descr *descr)\n{\n\tPyArray_Descr *old;\n\n\tif (!PyTypeNum_ISUSERDEF(typenum)) {\n\t\tPyErr_SetString(PyExc_TypeError, \n\t\t\t\t\"data type not registered\");\n\t\tPy_DECREF(descr);\n\t\treturn -1;\n\t}\n\told = userdescrs[typenum-PyArray_USERDEF];\n\tdescr->typeobj = old->typeobj;\n\tdescr->type_num = typenum;\n\n\tif (descr->f == NULL) descr->f = old->f;\n\tif (descr->fields == NULL) {\n\t\tdescr->fields = old->fields;\n\t\tPy_XINCREF(descr->fields);\n\t}\n\tif (descr->subarray == NULL && old->subarray) {\n\t\tdescr->subarray = _pya_malloc(sizeof(PyArray_ArrayDescr));\n\t\tmemcpy(descr->subarray, old->subarray, \n\t\t sizeof(PyArray_ArrayDescr));\n\t\tPy_INCREF(descr->subarray->shape);\n\t\tPy_INCREF(descr->subarray->base);\n\t}\n Py_XINCREF(descr->typeobj);\n\n#define _ZERO_CHECK(member) \\\n\tif (descr->member == 0) descr->member = old->member\n\n\t_ZERO_CHECK(kind);\n\t_ZERO_CHECK(type);\n _ZERO_CHECK(byteorder);\n\t_ZERO_CHECK(elsize);\n\t_ZERO_CHECK(alignment);\n#undef _ZERO_CHECK\n\n\tPy_DECREF(old);\n\tuserdescrs[typenum-PyArray_USERDEF] = descr;\n\treturn 0;\n}\n\n\n/*OBJECT_API\n To File\n*/\nstatic int\nPyArray_ToFile(PyArrayObject *self, FILE *fp, char *sep, char *format) \n{\n intp size;\n intp n, n2;\n int n3, n4;\n PyArrayIterObject *it;\n PyObject *obj, *strobj, *tupobj;\n\n\tn3 = (sep ? strlen((const char *)sep) : 0);\n\tif (n3 == 0) { /* binary data */\n if (PyArray_ISOBJECT(self)) {\n PyErr_SetString(PyExc_ValueError, \"cannot write \"\\\n\t\t\t\t\t\"object arrays to a file in \"\t\\\n\t\t\t\t\t\"binary mode\");\n return -1;\n }\n\n if (PyArray_ISCONTIGUOUS(self)) {\n size = PyArray_SIZE(self);\n if ((n=fwrite((const void *)self->data, \n (size_t) self->descr->elsize,\n (size_t) size, fp)) < size) {\n PyErr_Format(PyExc_ValueError, \n \"%ld requested and %ld written\",\n (long) size, (long) n);\n return -1;\n }\n }\n else {\n it=(PyArrayIterObject *) \\\n PyArray_IterNew((PyObject *)self);\n while(it->index < it->size) {\n if (fwrite((const void *)it->dataptr, \n (size_t) self->descr->elsize,\n 1, fp) < 1) {\n PyErr_Format(PyExc_IOError, \n \"problem writing element\"\\\n \" %d to file\", \n\t\t\t\t\t\t (int)it->index);\n Py_DECREF(it);\n return -1;\n }\n PyArray_ITER_NEXT(it);\n }\n Py_DECREF(it);\n } \n }\n else { /* text data */\n it=(PyArrayIterObject *) \\\n PyArray_IterNew((PyObject *)self);\n\t\tn4 = (format ? strlen((const char *)format) : 0);\n while(it->index < it->size) {\n obj = self->descr->f->getitem(it->dataptr, self);\n if (obj == NULL) {Py_DECREF(it); return -1;}\n\t\t\tif (n4 == 0) { /* standard writing */\n\t\t\t\tstrobj = PyObject_Str(obj);\n\t\t\t\tPy_DECREF(obj);\n\t\t\t\tif (strobj == NULL) {Py_DECREF(it); return -1;}\n\t\t\t}\n\t\t\telse { /* use format string */\n\t\t\t\ttupobj = PyTuple_New(1);\n\t\t\t\tif (tupobj == NULL) {Py_DECREF(it); return -1;}\n\t\t\t\tPyTuple_SET_ITEM(tupobj,0,obj);\n\t\t\t\tobj = PyString_FromString((const char *)format);\n\t\t\t\tif (obj == NULL) {Py_DECREF(tupobj); \n\t\t\t\t\tPy_DECREF(it); return -1;}\n\t\t\t\tstrobj = PyString_Format(obj, tupobj);\n\t\t\t\tPy_DECREF(obj);\n\t\t\t\tPy_DECREF(tupobj);\n\t\t\t\tif (strobj == NULL) {Py_DECREF(it); return -1;}\n\t\t\t}\n if ((n=fwrite(PyString_AS_STRING(strobj), \n 1, n2=PyString_GET_SIZE(strobj),\n fp)) < n2) {\n PyErr_Format(PyExc_IOError,\n \"problem writing element %d\"\\\n \" to file\", \n\t\t\t\t\t (int) it->index);\n Py_DECREF(strobj);\n Py_DECREF(it);\n return -1;\n }\n /* write separator for all but last one */\n if (it->index != it->size-1) \n fwrite(sep, 1, n3, fp);\n Py_DECREF(strobj);\n PyArray_ITER_NEXT(it);\n }\n Py_DECREF(it);\n }\n return 0;\n}\n\n/*OBJECT_API\n To List\n*/\nstatic PyObject *\nPyArray_ToList(PyArrayObject *self) \n{\n PyObject *lp;\n PyArrayObject *v;\n intp sz, i;\n\t\n if (!PyArray_Check(self)) return (PyObject *)self;\n\n if (self->nd == 0) \n\t\treturn self->descr->f->getitem(self->data,self);\n\t\n sz = self->dimensions[0];\n lp = PyList_New(sz);\n\t\n for (i=0; ind >= self->nd) {\n\t\t\tPyErr_SetString(PyExc_RuntimeError,\n\t\t\t\t\t\"array_item not returning smaller-\" \\\n\t\t\t\t\t\"dimensional array\");\n Py_DECREF(v);\n\t\t\tPy_DECREF(lp);\n\t\t\treturn NULL;\n\t\t}\n PyList_SetItem(lp, i, PyArray_ToList(v));\n\t\tPy_DECREF(v);\n }\n\t\n return lp;\n}\n\nstatic PyObject *\nPyArray_ToString(PyArrayObject *self)\n{\n intp numbytes;\n intp index;\n char *dptr;\n int elsize;\n PyObject *ret;\n PyArrayIterObject *it;\n \n\t/* if (PyArray_TYPE(self) == PyArray_OBJECT) {\n\t\t PyErr_SetString(PyExc_ValueError, \"a string for the data\" \\\n\t\t \"in an object array is not appropriate\");\n\t\t return NULL;\n\t\t }\n\t*/\n\n numbytes = PyArray_NBYTES(self);\n if (PyArray_ISONESEGMENT(self)) {\n ret = PyString_FromStringAndSize(self->data, (int) numbytes);\n }\n else {\n it = (PyArrayIterObject *)PyArray_IterNew((PyObject *)self);\n if (it==NULL) return NULL;\n ret = PyString_FromStringAndSize(NULL, (int) numbytes);\n if (ret == NULL) {Py_DECREF(it); return NULL;}\n dptr = PyString_AS_STRING(ret);\n index = it->size;\n elsize = self->descr->elsize;\n while(index--) {\n memcpy(dptr, it->dataptr, elsize);\n dptr += elsize;\n PyArray_ITER_NEXT(it);\n }\n Py_DECREF(it);\n }\n\treturn ret;\n}\n\n\n/*********************** end C-API functions **********************/\n\n\n/* array object functions */\n\nstatic void \narray_dealloc(PyArrayObject *self) {\n\n if (self->weakreflist != NULL)\n PyObject_ClearWeakRefs((PyObject *)self);\n\n if(self->base) {\n\t\t/* UPDATEIFCOPY means that base points to an \n\t\t array that should be updated with the contents\n\t\t of this array upon destruction.\n self->base->flags must have been WRITEABLE \n (checked previously) and it was locked here\n thus, unlock it.\n\t\t*/\n\t\tif (self->flags & UPDATEIFCOPY) {\n ((PyArrayObject *)self->base)->flags |= WRITEABLE;\n\t\t\tPy_INCREF(self); /* hold on to self in next call */\n PyArray_CopyInto((PyArrayObject *)self->base, self);\n\t\t\t/* Don't need to DECREF -- because we are deleting\n\t\t\t self already... */\n\t\t}\n\t\t/* In any case base is pointing to something that we need\n\t\t to DECREF -- either a view or a buffer object */\n Py_DECREF(self->base);\n }\n \n if ((self->flags & OWN_DATA) && self->data) {\n\t\t/* Free internal references if an Object array */\n\t\tif (PyArray_ISOBJECT(self))\n\t\t\tPyArray_XDECREF(self);\n PyDataMem_FREE(self->data);\n }\n\t\n\tPyDimMem_FREE(self->dimensions);\n\n\tPy_DECREF(self->descr);\n\t\n self->ob_type->tp_free((PyObject *)self);\n}\n\n/*************************************************************************\n **************** Implement Mapping Protocol ***************************\n *************************************************************************/\n\nstatic int \narray_length(PyArrayObject *self) \n{\n if (self->nd != 0) {\n return self->dimensions[0];\n } else {\n\t\tPyErr_SetString(PyExc_TypeError, \"len() of unsized object\");\n\t\treturn -1;\n }\n}\n\nstatic PyObject *\narray_big_item(PyArrayObject *self, intp i) \n{\n\tchar *item;\n\tPyArrayObject *r;\n\t\t\n\tif(self->nd == 0) {\n\t\tPyErr_SetString(PyExc_IndexError, \n\t\t\t\t\"0-d arrays can't be indexed\");\n\t\treturn NULL;\n\t}\n if ((item = index2ptr(self, i)) == NULL) return NULL;\n\t\n\tPy_INCREF(self->descr);\n\tr = (PyArrayObject *)PyArray_NewFromDescr(self->ob_type, \n\t\t\t\t\t\t self->descr,\n\t\t\t\t\t\t self->nd-1, \n\t\t\t\t\t\t self->dimensions+1, \n\t\t\t\t\t\t self->strides+1, item, \n\t\t\t\t\t\t self->flags,\n\t\t\t\t\t\t (PyObject *)self);\n\tif (r == NULL) return NULL;\n\tPy_INCREF(self);\n\tr->base = (PyObject *)self;\n PyArray_UpdateFlags(r, CONTIGUOUS | FORTRAN);\n\treturn (PyObject *)r;\n}\n\nstatic PyObject *\narray_item_nice(PyArrayObject *self, int i) \n{\n\treturn PyArray_Return((PyArrayObject *)array_big_item(self, (intp) i));\n}\n\n\nstatic int \narray_ass_big_item(PyArrayObject *self, intp i, PyObject *v) \n{\n PyArrayObject *tmp;\n char *item;\n int ret;\n\n if (v == NULL) {\n PyErr_SetString(PyExc_ValueError, \n \"can't delete array elements\");\n return -1;\n }\n\tif (!PyArray_ISWRITEABLE(self)) {\n\t\tPyErr_SetString(PyExc_RuntimeError,\n\t\t\t\t\"array is not writeable\");\n\t\treturn -1;\n\t}\n if (self->nd == 0) {\n PyErr_SetString(PyExc_IndexError, \n \"0-d arrays can't be indexed.\");\n return -1;\n }\n\n if (i < 0) i = i+self->dimensions[0];\n\n if (self->nd > 1) {\n if((tmp = (PyArrayObject *)array_big_item(self, i)) == NULL)\n return -1;\n ret = PyArray_CopyObject(tmp, v);\n Py_DECREF(tmp);\n return ret; \n }\n\t\n if ((item = index2ptr(self, i)) == NULL) return -1;\n if (self->descr->f->setitem(v, item, self) == -1) return -1;\n return 0;\n}\n\n#if SIZEOF_INT == SIZEOF_INTP\n#define array_ass_item array_ass_big_item\n#else\nstatic int\narray_ass_item(PyArrayObject *self, int i, PyObject *v)\n{\n\treturn array_ass_big_item(self, (intp) i, v);\n}\n#endif\n\n\n/* -------------------------------------------------------------- */\nstatic int\nslice_coerce_index(PyObject *o, intp *v)\n{\n\t*v = PyArray_PyIntAsIntp(o);\n\tif (error_converting(*v)) {\n\t\tPyErr_Clear();\n\t\treturn 0;\n\t}\n\treturn 1;\n}\n\n\n/* This is basically PySlice_GetIndicesEx, but with our coercion\n * of indices to integers (plus, that function is new in Python 2.3) */\nstatic int\nslice_GetIndices(PySliceObject *r, intp length,\n intp *start, intp *stop, intp *step,\n intp *slicelength)\n{\n\tintp defstart, defstop;\n\t\n\tif (r->step == Py_None) {\n\t\t*step = 1;\n\t} else {\n\t\tif (!slice_coerce_index(r->step, step)) return -1;\n\t\tif (*step == 0) {\n\t\t\tPyErr_SetString(PyExc_ValueError, \n\t\t\t\t\t\"slice step cannot be zero\");\n\t\t\treturn -1;\n\t\t}\n\t}\n\t\n\tdefstart = *step < 0 ? length - 1 : 0;\n\tdefstop = *step < 0 ? -1 : length;\n\t\n\tif (r->start == Py_None) {\n\t\t*start = *step < 0 ? length-1 : 0;\n\t} else {\n\t\tif (!slice_coerce_index(r->start, start)) return -1;\n\t\tif (*start < 0) *start += length;\n\t\tif (*start < 0) *start = (*step < 0) ? -1 : 0;\n\t\tif (*start >= length) {\n\t\t\t*start = (*step < 0) ? length - 1 : length;\n\t\t}\n\t}\n\t\n\tif (r->stop == Py_None) {\n\t\t*stop = defstop;\n\t} else {\n\t\tif (!slice_coerce_index(r->stop, stop)) return -1;\n\t\tif (*stop < 0) *stop += length;\n if (*stop < 0) *stop = -1;\n if (*stop > length) *stop = length;\n\t}\n\t\n\tif ((*step < 0 && *stop >= *start) || \\\n\t (*step > 0 && *start >= *stop)) {\n\t\t*slicelength = 0;\n\t} else if (*step < 0) {\n\t\t*slicelength = (*stop - *start + 1) / (*step) + 1;\n\t} else {\n\t\t*slicelength = (*stop - *start - 1) / (*step) + 1;\n\t}\n\t\n\treturn 0;\n}\n\n#define PseudoIndex -1\n#define RubberIndex -2\n#define SingleIndex -3\n\nstatic intp\nparse_subindex(PyObject *op, intp *step_size, intp *n_steps, intp max)\n{\n\tintp index;\n\t\n\tif (op == Py_None) {\n\t\t*n_steps = PseudoIndex;\n\t\tindex = 0;\n\t} else if (op == Py_Ellipsis) {\n\t\t*n_steps = RubberIndex;\n\t\tindex = 0;\n\t} else if (PySlice_Check(op)) {\n\t\tintp stop;\n\t\tif (slice_GetIndices((PySliceObject *)op, max,\n\t\t\t\t &index, &stop, step_size, n_steps) < 0) {\n\t\t\tif (!PyErr_Occurred()) {\n\t\t\t\tPyErr_SetString(PyExc_IndexError, \n\t\t\t\t\t\t\"invalid slice\");\n\t\t\t}\n\t\t\tgoto fail;\n\t\t}\n\t\tif (*n_steps <= 0) {\n\t\t\t*n_steps = 0;\n\t\t\t*step_size = 1;\n\t\t\tindex = 0;\n\t\t}\n\t} else {\n\t\tindex = PyArray_PyIntAsIntp(op);\n\t\tif (error_converting(index)) {\n\t\t\tPyErr_SetString(PyExc_IndexError,\n\t\t\t\t\t\"each subindex must be either a \"\\\n\t\t\t\t\t\"slice, an integer, Ellipsis, or \"\\\n\t\t\t\t\t\"newaxis\");\n\t\t\tgoto fail;\n\t\t}\n\t\t*n_steps = SingleIndex;\n\t\t*step_size = 0;\n\t\tif (index < 0) index += max;\n\t\tif (index >= max || index < 0) {\n\t\t\tPyErr_SetString(PyExc_IndexError, \"invalid index\");\n\t\t\tgoto fail;\n\t\t}\n\t}\n\treturn index;\n fail:\n\treturn -1;\n}\n\n\nstatic int \nparse_index(PyArrayObject *self, PyObject *op, \n intp *dimensions, intp *strides, intp *offset_ptr)\n{\n int i, j, n;\n int nd_old, nd_new, n_add, n_pseudo;\n\tintp n_steps, start, offset, step_size;\n PyObject *op1=NULL;\n int is_slice;\n\n\n if (PySlice_Check(op) || op == Py_Ellipsis || op == Py_None) {\n n = 1;\n op1 = op;\n Py_INCREF(op);\t\n /* this relies on the fact that n==1 for loop below */\n is_slice = 1;\n }\n else {\n if (!PySequence_Check(op)) {\n PyErr_SetString(PyExc_IndexError, \n \"index must be either an int \"\\\n \"or a sequence\");\n return -1;\n }\n n = PySequence_Length(op);\n is_slice = 0;\n }\n\t\n nd_old = nd_new = 0;\n\t\n offset = 0;\n for(i=0; ind ? \\\n self->dimensions[nd_old] : 0);\n Py_DECREF(op1);\n if (start == -1) break;\n\t\t\n if (n_steps == PseudoIndex) {\n dimensions[nd_new] = 1; strides[nd_new] = 0; nd_new++;\n } else {\n if (n_steps == RubberIndex) {\n for(j=i+1, n_pseudo=0; jnd-(n-i-n_pseudo-1+nd_old);\n if (n_add < 0) {\n PyErr_SetString(PyExc_IndexError, \n \"too many indices\");\n return -1;\n }\n for(j=0; jdimensions[nd_old];\n strides[nd_new] = \\\n self->strides[nd_old];\n nd_new++; nd_old++;\n }\n } else {\n if (nd_old >= self->nd) {\n PyErr_SetString(PyExc_IndexError, \n \"too many indices\");\n return -1;\n }\n offset += self->strides[nd_old]*start;\n nd_old++;\n if (n_steps != SingleIndex) {\n dimensions[nd_new] = n_steps;\n strides[nd_new] = step_size * \\\n self->strides[nd_old-1];\n nd_new++;\n }\n }\n }\n }\n if (i < n) return -1;\n n_add = self->nd-nd_old;\n for(j=0; jdimensions[nd_old];\n strides[nd_new] = self->strides[nd_old];\n nd_new++; nd_old++;\n }\t \n *offset_ptr = offset;\n return nd_new;\n}\n\nstatic void\n_swap_axes(PyArrayMapIterObject *mit, PyArrayObject **ret)\n{\n\tPyObject *new;\n\tint n1, n2, n3, val;\n\tint i;\n\tPyArray_Dims permute;\n\tintp d[MAX_DIMS];\n\n\tpermute.ptr = d;\n\tpermute.len = mit->nd;\n\n\t/* tuple for transpose is \n\t (n1,..,n1+n2-1,0,..,n1-1,n1+n2,...,n3-1)\n\t n1 is the number of dimensions of \n\t the broadcasted index array \n\t n2 is the number of dimensions skipped at the\n\t start\n\t n3 is the number of dimensions of the \n\t result \n\t*/\n\tn1 = mit->iters[0]->nd_m1 + 1;\n\tn2 = mit->iteraxes[0];\n\tn3 = mit->nd;\n\tval = n1;\n\ti = 0;\n\twhile(val < n1+n2) \n\t\tpermute.ptr[i++] = val++;\n\tval = 0;\n\twhile(val < n1)\n\t\tpermute.ptr[i++] = val++;\n\tval = n1+n2;\n\twhile(val < n3)\n\t\tpermute.ptr[i++] = val++;\n\n\tnew = PyArray_Transpose(*ret, &permute);\n\tPy_DECREF(*ret);\n\t*ret = (PyArrayObject *)new;\n}\n\n/* Prototypes for Mapping calls --- not part of the C-API\n because only useful as part of a getitem call. \n*/\n\nstatic void PyArray_MapIterReset(PyArrayMapIterObject *);\nstatic void PyArray_MapIterNext(PyArrayMapIterObject *);\nstatic void PyArray_MapIterBind(PyArrayMapIterObject *, PyArrayObject *);\nstatic PyObject* PyArray_MapIterNew(PyObject *, int, int);\n\nstatic PyObject *\nPyArray_GetMap(PyArrayMapIterObject *mit)\n{\n\n\tPyArrayObject *ret, *temp;\n\tPyArrayIterObject *it;\n\tint index;\n\tint swap;\n PyArray_CopySwapFunc *copyswap;\n\n\t/* Unbound map iterator --- Bind should have been called */\n\tif (mit->ait == NULL) return NULL;\n\n\t/* This relies on the map iterator object telling us the shape\n\t of the new array in nd and dimensions.\n\t*/\n\ttemp = mit->ait->ao;\n\tPy_INCREF(temp->descr);\n\tret = (PyArrayObject *)\\\n\t\tPyArray_NewFromDescr(temp->ob_type, \n\t\t\t\t temp->descr,\n\t\t\t\t mit->nd, mit->dimensions, \n\t\t\t\t NULL, NULL, \n\t\t\t\t PyArray_ISFORTRAN(temp),\n\t\t\t\t (PyObject *)temp);\n\tif (ret == NULL) return NULL;\n\n\t/* Now just iterate through the new array filling it in\n\t with the next object from the original array as\n\t defined by the mapping iterator */\n\n\tif ((it = (PyArrayIterObject *)PyArray_IterNew((PyObject *)ret)) \n\t == NULL) {\n\t\tPy_DECREF(ret);\n\t\treturn NULL;\n\t}\n\tindex = it->size;\n\tswap = (PyArray_ISNOTSWAPPED(temp) != PyArray_ISNOTSWAPPED(ret));\n copyswap = ret->descr->f->copyswap;\n\tPyArray_MapIterReset(mit);\n\twhile (index--) {\n copyswap(it->dataptr, mit->dataptr, swap, ret->descr->elsize);\n\t\tPyArray_MapIterNext(mit);\n\t\tPyArray_ITER_NEXT(it);\n\t}\n\tPy_DECREF(it);\n\t\n\t/* check for consecutive axes */\n\tif ((mit->subspace != NULL) && (mit->consec)) {\n\t\tif (mit->iteraxes[0] > 0) { /* then we need to swap */\n\t\t\t_swap_axes(mit, &ret);\n\t\t}\n\t}\n\treturn (PyObject *)ret;\n}\n\nstatic int\nPyArray_SetMap(PyArrayMapIterObject *mit, PyObject *op)\n{\n\tPyObject *arr=NULL;\n\tPyArrayIterObject *it;\n\tint index;\n\tint swap;\n PyArray_CopySwapFunc *copyswap;\n\tPyArray_Descr *descr;\n\n\t/* Unbound Map Iterator */\n\tif (mit->ait == NULL) return -1;\n\n\tdescr = mit->ait->ao->descr;\n\tPy_INCREF(descr);\n\tarr = PyArray_FromAny(op, descr, 0, 0, FORCECAST, NULL);\n\tif (arr == NULL) return -1;\n\n\tif ((mit->subspace != NULL) && (mit->consec)) {\n\t\tif (mit->iteraxes[0] > 0) { /* then we need to swap */\n\t\t\t_swap_axes(mit, (PyArrayObject **)&arr);\n\t\t}\n\t}\n\t\n\tif ((it = (PyArrayIterObject *)PyArray_IterNew(arr))==NULL) {\n\t\tPy_DECREF(arr);\n\t\treturn -1;\n\t}\n\n\tindex = mit->size;\n\tswap = (PyArray_ISNOTSWAPPED(mit->ait->ao) != \\\n\t\t(PyArray_ISNOTSWAPPED(arr)));\n\n copyswap = PyArray_DESCR(arr)->f->copyswap;\n\tPyArray_MapIterReset(mit);\n /* Need to decref OBJECT arrays */\n if (PyTypeNum_ISOBJECT(descr->type_num)) {\n while (index--) {\n Py_XDECREF(*((PyObject **)mit->dataptr));\n Py_INCREF(*((PyObject **)it->dataptr));\n memmove(mit->dataptr, it->dataptr, sizeof(PyObject *));\n PyArray_MapIterNext(mit);\n PyArray_ITER_NEXT(it);\n if (it->index == it->size)\n PyArray_ITER_RESET(it);\n }\n\t\tPy_DECREF(arr);\n\t\tPy_DECREF(it);\n return 0;\n }\n\twhile(index--) {\n\t\tmemmove(mit->dataptr, it->dataptr, PyArray_ITEMSIZE(arr));\n copyswap(mit->dataptr, NULL, swap, PyArray_ITEMSIZE(arr));\n\t\tPyArray_MapIterNext(mit);\n\t\tPyArray_ITER_NEXT(it);\n\t\tif (it->index == it->size)\n\t\t\tPyArray_ITER_RESET(it);\n\t}\t\t\n\tPy_DECREF(arr);\n\tPy_DECREF(it);\n\treturn 0;\n}\n\nint\ncount_new_axes_0d(PyObject *tuple)\n{\n\tint i, argument_count;\n\tint ellipsis_count = 0;\n\tint newaxis_count = 0;\n\t\n\targument_count = PyTuple_GET_SIZE(tuple);\n\n\tfor (i = 0; i < argument_count; ++i) {\n\t\tPyObject *arg = PyTuple_GET_ITEM(tuple, i);\n\t\tif (arg == Py_Ellipsis && !ellipsis_count) ellipsis_count++;\n\t\telse if (arg == Py_None) newaxis_count++;\n\t\telse break;\n\t}\n\tif (i < argument_count) {\n\t\tPyErr_SetString(PyExc_IndexError,\n\t\t\t\t\"0-d arrays can only use a single ()\"\n\t\t\t\t\" or a list of newaxes (and a single ...)\"\n\t\t\t\t\" as an index\");\n\t\treturn -1;\n\t}\n\tif (newaxis_count > MAX_DIMS) {\n\t\tPyErr_SetString(PyExc_IndexError,\n\t\t\t\t\"too many dimensions\");\n\t\treturn -1;\n\t}\n\treturn newaxis_count;\n}\n\nstatic PyObject *\nadd_new_axes_0d(PyArrayObject *arr, int newaxis_count)\n{\n\tPyArrayObject *other;\n\tintp dimensions[MAX_DIMS]; \n\tint i;\n\tfor (i = 0; i < newaxis_count; ++i) {\n\t\tdimensions[i] = 1;\n\t}\n\tPy_INCREF(arr->descr);\n\tif ((other = (PyArrayObject *)\n\t PyArray_NewFromDescr(arr->ob_type, arr->descr,\n\t\t\t\t newaxis_count, dimensions,\n\t\t\t\t NULL, arr->data,\n\t\t\t\t arr->flags,\n\t\t\t\t (PyObject *)arr)) == NULL) \n\t\treturn NULL;\n\tother->base = (PyObject *)arr;\n\tPy_INCREF(arr);\n\treturn (PyObject *)other;\n}\n\n\n/* This checks the args for any fancy indexing objects */\n\n#define SOBJ_NOTFANCY 0 \n#define SOBJ_ISFANCY 1\n#define SOBJ_BADARRAY 2\n#define SOBJ_TOOMANY 3\n#define SOBJ_LISTTUP 4\n\nstatic int\nfancy_indexing_check(PyObject *args)\n{\n\tint i, n;\n\tPyObject *obj;\n\tint retval = SOBJ_NOTFANCY;\n\n\tif (PyTuple_Check(args)) {\n\t\tn = PyTuple_GET_SIZE(args);\n\t\tif (n >= MAX_DIMS) return SOBJ_TOOMANY;\n\t\tfor (i=0; i=MAX_DIMS) return SOBJ_ISFANCY;\n\t\tfor (i=0; i SOBJ_ISFANCY) return retval;\n\t\t}\n\t}\n\n\treturn retval;\n}\n\n/* Called when treating array object like a mapping -- called first from \n Python when using a[object] unless object is a standard slice object\n (not an extended one). \n\n*/\n\n/* There are two situations: \n\n 1 - the subscript is a standard view and a reference to the \n array can be returned\n\n 2 - the subscript uses Boolean masks or integer indexing and\n therefore a new array is created and returned. \n\n*/\n\n/* Always returns arrays */\n\nstatic PyObject *iter_subscript(PyArrayIterObject *, PyObject *); \n\n\nstatic PyObject *\narray_subscript(PyArrayObject *self, PyObject *op) \n{\n intp dimensions[MAX_DIMS], strides[MAX_DIMS];\n\tintp offset;\n int nd, oned, fancy;\n\tintp i;\n PyArrayObject *other;\n\tPyArrayMapIterObject *mit;\n\n\tif (PyString_Check(op) || PyUnicode_Check(op)) {\n\t\tif (self->descr->fields) {\n\t\t\tPyObject *obj;\n\t\t\tobj = PyDict_GetItem(self->descr->fields, op);\n\t\t\tif (obj != NULL) {\n\t\t\t\tPyArray_Descr *descr;\n\t\t\t\tint offset;\n\t\t\t\tPyObject *title;\n\t\t\t\t\n\t\t\t\tif (PyArg_ParseTuple(obj, \"Oi|O\",\n\t\t\t\t\t\t &descr, &offset, &title)) {\n\t\t\t\t\tPy_INCREF(descr);\n\t\t\t\t\treturn PyArray_GetField(self, descr, \n\t\t\t\t\t\t\t\toffset);\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t\t\n\t\tPyErr_Format(PyExc_ValueError, \n\t\t\t \"field named %s not found.\",\n\t\t\t PyString_AsString(op));\n\t\treturn NULL;\n\t}\n if (self->nd == 0) {\n\t\tif (op == Py_Ellipsis)\n\t\t\treturn PyArray_ToScalar(self->data, self);\n\t\tif (op == Py_None)\n\t\t\treturn add_new_axes_0d(self, 1);\n\t\tif (PyTuple_Check(op)) {\n\t\t\tif (0 == PyTuple_GET_SIZE(op))\n\t\t\t\treturn PyArray_ToScalar(self->data, self);\n\t\t\tif ((nd = count_new_axes_0d(op)) == -1)\n\t\t\t\treturn NULL;\n\t\t\treturn add_new_axes_0d(self, nd);\n\t\t}\n PyErr_SetString(PyExc_IndexError, \n \"0-d arrays can't be indexed.\");\n return NULL;\n }\n if (PyArray_IsScalar(op, Integer) || PyInt_Check(op) || \\\n PyLong_Check(op)) {\n intp value;\n value = PyArray_PyIntAsIntp(op);\n\t\tif (PyErr_Occurred())\n\t\t\tPyErr_Clear();\n else if (value >= 0) {\n\t\t\treturn array_big_item(self, value);\n }\n else /* (value < 0) */ {\n\t\t\tvalue += self->dimensions[0];\n\t\t\treturn array_big_item(self, value);\n\t\t}\n }\n\n\tfancy = fancy_indexing_check(op);\n\n\tif (fancy != SOBJ_NOTFANCY) { \n\t\toned = ((self->nd == 1) && !(PyTuple_Check(op) &&\t\\\n\t\t\t\t\t PyTuple_GET_SIZE(op) > 1));\n\n\t\t/* wrap arguments into a mapiter object */\n\t\tmit = (PyArrayMapIterObject *)\\\n\t\t\tPyArray_MapIterNew(op, oned, fancy);\n\t\tif (mit == NULL) return NULL;\n\t\tif (oned) {\n\t\t\tPyArrayIterObject *it;\n\t\t\tPyObject *rval;\n\t\t\tit = (PyArrayIterObject *)PyArray_IterNew((PyObject *)self);\n\t\t\tif (it == NULL) {Py_DECREF(mit); return NULL;}\n\t\t\trval = iter_subscript(it, mit->indexobj);\n\t\t\tPy_DECREF(it);\n\t\t\tPy_DECREF(mit);\n\t\t\treturn rval;\n\t\t}\n PyArray_MapIterBind(mit, self);\n other = (PyArrayObject *)PyArray_GetMap(mit);\n Py_DECREF(mit);\n return (PyObject *)other;\n }\n\n\ti = PyArray_PyIntAsIntp(op);\n\tif (!error_converting(i)) {\n\t\tif (i < 0 && self->nd > 0) i = i+self->dimensions[0];\n\t\treturn array_big_item(self, i);\n\t}\n\tPyErr_Clear();\n\n\t/* Standard (view-based) Indexing */\n if ((nd = parse_index(self, op, dimensions, strides, &offset)) \n == -1) \n return NULL;\n\n\t/* This will only work if new array will be a view */\n\tPy_INCREF(self->descr);\n\tif ((other = (PyArrayObject *)\t\t\t\t\t\\\n\t PyArray_NewFromDescr(self->ob_type, self->descr,\n\t\t\t\t nd, dimensions,\n\t\t\t\t strides, self->data+offset, \n\t\t\t\t self->flags,\n\t\t\t\t (PyObject *)self)) == NULL) \n\t\treturn NULL;\n\n\n\tother->base = (PyObject *)self;\n\tPy_INCREF(self);\n\t\n\tPyArray_UpdateFlags(other, UPDATE_ALL_FLAGS);\n\t\n\treturn (PyObject *)other;\n}\n\n\n/* Another assignment hacked by using CopyObject. */\n\n/* This only works if subscript returns a standard view. */\n\n/* Again there are two cases. In the first case, PyArray_CopyObject\n can be used. In the second case, a new indexing function has to be \n used.\n*/\n\nstatic int iter_ass_subscript(PyArrayIterObject *, PyObject *, PyObject *); \n\nstatic int \narray_ass_sub(PyArrayObject *self, PyObject *index, PyObject *op) \n{\n int ret, oned, fancy;\n\tintp i;\n PyArrayObject *tmp;\n\tPyArrayMapIterObject *mit;\n\t\n if (op == NULL) {\n PyErr_SetString(PyExc_ValueError, \n \"cannot delete array elements\");\n return -1;\n }\n\tif (!PyArray_ISWRITEABLE(self)) {\n\t\tPyErr_SetString(PyExc_RuntimeError,\n\t\t\t\t\"array is not writeable\");\n\t\treturn -1;\n\t}\n\t\n if (PyArray_IsScalar(index, Integer) || PyInt_Check(index) ||\t\\\n PyLong_Check(index)) {\n intp value;\n value = PyArray_PyIntAsIntp(index);\n if (PyErr_Occurred())\n PyErr_Clear();\n\t\telse\n\t\t\treturn array_ass_big_item(self, value, op);\n }\n\n\tif (PyString_Check(index) || PyUnicode_Check(index)) {\n\t\tif (self->descr->fields) {\n\t\t\tPyObject *obj;\n\t\t\tobj = PyDict_GetItem(self->descr->fields, index);\n\t\t\tif (obj != NULL) {\n\t\t\t\tPyArray_Descr *descr;\n\t\t\t\tint offset;\n\t\t\t\tPyObject *title;\n\t\t\t\t\n\t\t\t\tif (PyArg_ParseTuple(obj, \"Oi|O\",\n\t\t\t\t\t\t &descr, &offset, &title)) {\n\t\t\t\t\tPy_INCREF(descr);\n\t\t\t\t\treturn PyArray_SetField(self, descr, \n\t\t\t\t\t\t\t\toffset, op);\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t\t\n\t\tPyErr_Format(PyExc_ValueError, \n\t\t\t \"field named %s not found.\",\n\t\t\t PyString_AsString(index));\n\t\treturn -1;\n\t}\n\n if (self->nd == 0) {\n\t\tif (index == Py_Ellipsis || index == Py_None ||\t\t\\\n\t\t (PyTuple_Check(index) && (0 == PyTuple_GET_SIZE(index) || \\\n\t\t\t\t\t count_new_axes_0d(index) > 0)))\n\t\t\treturn self->descr->f->setitem(op, self->data, self);\n PyErr_SetString(PyExc_IndexError, \n \"0-d arrays can't be indexed.\");\n return -1;\n }\n\n\tfancy = fancy_indexing_check(index);\n\n\tif (fancy != SOBJ_NOTFANCY) { \n\t\toned = ((self->nd == 1) && !(PyTuple_Check(index) && \\\n\t\t\t\t\t PyTuple_GET_SIZE(index) > 1));\n\n\t\tmit = (PyArrayMapIterObject *)\t\t\t\\\n\t\t\tPyArray_MapIterNew(index, oned, fancy);\n\t\tif (mit == NULL) return -1;\n\t\tif (oned) {\n\t\t\tPyArrayIterObject *it;\n\t\t\tint rval;\n\t\t\tit = (PyArrayIterObject *)PyArray_IterNew((PyObject *)self);\n\t\t\tif (it == NULL) {Py_DECREF(mit); return -1;}\n\t\t\trval = iter_ass_subscript(it, mit->indexobj, op);\n\t\t\tPy_DECREF(it);\n\t\t\tPy_DECREF(mit);\n\t\t\treturn rval;\n\t\t}\n PyArray_MapIterBind(mit, self);\n ret = PyArray_SetMap(mit, op);\n Py_DECREF(mit);\n return ret;\n }\n\t\n\ti = PyArray_PyIntAsIntp(index);\n\tif (!error_converting(i)) {\n\t\treturn array_ass_big_item(self, i, op);\n\t}\n\tPyErr_Clear();\n\t\n\t/* Rest of standard (view-based) indexing */\n\n if ((tmp = (PyArrayObject *)array_subscript(self, index)) == NULL)\n return -1; \n\tif (PyArray_ISOBJECT(self) && (tmp->nd == 0)) {\n\t\tret = tmp->descr->f->setitem(op, tmp->data, tmp);\n\t}\n\telse {\n\t\tret = PyArray_CopyObject(tmp, op);\n\t}\n\tPy_DECREF(tmp);\n return ret;\n}\n\n\n/* There are places that require that array_subscript return a PyArrayObject\n and not possibly a scalar. Thus, this is the function exposed to \n Python so that 0-dim arrays are passed as scalars\n*/\n\nstatic PyObject *\narray_subscript_nice(PyArrayObject *self, PyObject *op) \n{\n\treturn PyArray_Return((PyArrayObject *)array_subscript(self, op));\n}\n\n\nstatic PyMappingMethods array_as_mapping = {\n (inquiry)array_length,\t\t /*mp_length*/\n (binaryfunc)array_subscript_nice,\t/*mp_subscript*/\n (objobjargproc)array_ass_sub,\t /*mp_ass_subscript*/\n};\n\n/****************** End of Mapping Protocol ******************************/\n\n\n/*************************************************************************\n **************** Implement Buffer Protocol ****************************\n *************************************************************************/\n\n/* removed multiple segment interface */\n\nstatic int \narray_getsegcount(PyArrayObject *self, int *lenp) \n{\n if (lenp)\n *lenp = PyArray_NBYTES(self);\n\n if (PyArray_ISONESEGMENT(self)) {\n return 1;\n }\n\n if (lenp)\n *lenp = 0;\n return 0;\n}\n\nstatic int \narray_getreadbuf(PyArrayObject *self, int segment, void **ptrptr) \n{\n if (segment != 0) {\n PyErr_SetString(PyExc_ValueError, \n \"accessing non-existing array segment\");\n return -1;\n }\n \n if (PyArray_ISONESEGMENT(self)) {\n *ptrptr = self->data;\n return PyArray_NBYTES(self);\n }\n PyErr_SetString(PyExc_ValueError, \"array is not a single segment\");\n *ptrptr = NULL;\n return -1;\n}\n\n\nstatic int \narray_getwritebuf(PyArrayObject *self, int segment, void **ptrptr) \n{\n if (PyArray_CHKFLAGS(self, WRITEABLE)) \n return array_getreadbuf(self, segment, (void **) ptrptr);\n else {\n PyErr_SetString(PyExc_ValueError, \"array cannot be \"\\\n \"accessed as a writeable buffer\");\n return -1;\n }\n}\n\nstatic int \narray_getcharbuf(PyArrayObject *self, int segment, const char **ptrptr) \n{\n if (self->descr->type_num == PyArray_STRING || \\\n\t self->descr->type_num == PyArray_UNICODE)\n return array_getreadbuf(self, segment, (void **) ptrptr);\n else {\n PyErr_SetString(PyExc_TypeError, \n \"non-character array cannot be interpreted \"\\\n \"as character buffer\");\n return -1;\n }\n}\n\nstatic PyBufferProcs array_as_buffer = {\n (getreadbufferproc)array_getreadbuf, /*bf_getreadbuffer*/\n (getwritebufferproc)array_getwritebuf, /*bf_getwritebuffer*/\n (getsegcountproc)array_getsegcount,\t /*bf_getsegcount*/\n (getcharbufferproc)array_getcharbuf, /*bf_getcharbuffer*/\n};\n\n/****************** End of Buffer Protocol *******************************/\n\n\n/*************************************************************************\n **************** Implement Number Protocol ****************************\n *************************************************************************/\n\n\ntypedef struct {\n PyObject *add,\n *subtract,\n *multiply,\n *divide,\n *remainder,\n *power,\n\t\t*sqrt,\n *negative,\n *absolute,\n *invert,\n *left_shift,\n *right_shift,\n *bitwise_and,\n *bitwise_xor,\n *bitwise_or,\n *less,\n *less_equal,\n *equal,\n *not_equal,\n *greater,\n *greater_equal,\n *floor_divide,\n *true_divide,\n\t\t*logical_or,\n\t\t*logical_and,\n\t\t*floor,\n\t\t*ceil,\n\t\t*maximum,\n\t\t*minimum;\t\n\t\n} NumericOps;\n\nstatic NumericOps n_ops = {NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, \n NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL,\n NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL,\n NULL, NULL, NULL, NULL, NULL};\n\n/* Dictionary can contain any of the numeric operations, by name. \n Those not present will not be changed\n */\n\n#define SET(op) temp=PyDict_GetItemString(dict, #op);\t\\\n\tif (temp != NULL) {\t\t\t\t\\\n\t\tif (!(PyCallable_Check(temp))) return -1; \\\n Py_XDECREF(n_ops.op); \\\n\t\tn_ops.op = temp; \\\n\t}\n\n \n/*OBJECT_API\n Set internal structure with number functions that all arrays will use\n*/\nint \nPyArray_SetNumericOps(PyObject *dict) \n{\n PyObject *temp = NULL;\n SET(add);\n SET(subtract);\n SET(multiply);\n SET(divide);\n SET(remainder);\n SET(power);\n\tSET(sqrt);\n SET(negative);\n SET(absolute);\n SET(invert);\n SET(left_shift);\n SET(right_shift);\n SET(bitwise_and);\n SET(bitwise_or);\n SET(bitwise_xor);\n SET(less);\t \n SET(less_equal);\n SET(equal);\n SET(not_equal);\n SET(greater);\n SET(greater_equal);\n SET(floor_divide);\t\n SET(true_divide);\t\n\tSET(logical_or);\n\tSET(logical_and);\n\tSET(floor);\n\tSET(ceil);\n\tSET(maximum);\n\tSET(minimum);\n return 0;\n}\n\n#define GET(op) if (n_ops.op &&\t\t\t\t\t\t\\\n\t\t (PyDict_SetItemString(dict, #op, n_ops.op)==-1))\t\\\n\t\tgoto fail;\n\n/*OBJECT_API\n Get dictionary showing number functions that all arrays will use\n*/\nstatic PyObject *\nPyArray_GetNumericOps(void) \n{\n\tPyObject *dict;\n\tif ((dict = PyDict_New())==NULL) \n\t\treturn NULL;\t\n\tGET(add);\n GET(subtract);\n GET(multiply);\n GET(divide);\n GET(remainder);\n GET(power);\n\tGET(sqrt);\n GET(negative);\n GET(absolute);\n GET(invert);\n GET(left_shift);\n GET(right_shift);\n GET(bitwise_and);\n GET(bitwise_or);\n GET(bitwise_xor);\n GET(less);\t \n GET(less_equal);\n GET(equal);\n GET(not_equal);\n GET(greater);\n GET(greater_equal);\n GET(floor_divide); \n GET(true_divide); \n\tGET(logical_or);\n\tGET(logical_and);\n\tGET(floor);\n\tGET(ceil);\n\tGET(maximum);\n\tGET(minimum);\n\treturn dict;\t\n\n fail:\n\tPy_DECREF(dict);\n\treturn NULL;\t\t\n}\n\nstatic PyObject *\nPyArray_GenericReduceFunction(PyArrayObject *m1, PyObject *op, int axis,\n\t\t\t int rtype)\n{\n\tPyObject *args, *ret=NULL, *meth;\n\tif (op == NULL) {\n\t\tPy_INCREF(Py_NotImplemented);\n\t\treturn Py_NotImplemented;\n\t}\n\tif (rtype == PyArray_NOTYPE) \n\t\targs = Py_BuildValue(\"(Oi)\", m1, axis);\n\telse {\n\t\tPyArray_Descr *descr;\n\t\tdescr = PyArray_DescrFromType(rtype);\n\t\targs = Py_BuildValue(\"(Oic)\", m1, axis, descr->type);\n\t\tPy_DECREF(descr);\n\t}\n\tmeth = PyObject_GetAttrString(op, \"reduce\");\n\tif (meth && PyCallable_Check(meth)) {\n\t\tret = PyObject_Call(meth, args, NULL);\n\t}\n\tPy_DECREF(args);\n\tPy_DECREF(meth);\n\treturn ret;\n}\t\n\n\nstatic PyObject *\nPyArray_GenericAccumulateFunction(PyArrayObject *m1, PyObject *op, int axis,\n\t\t\t\t int rtype)\n{\n\tPyObject *args, *ret=NULL, *meth;\n\tif (op == NULL) {\n\t\tPy_INCREF(Py_NotImplemented);\n\t\treturn Py_NotImplemented;\n\t}\n\tif (rtype == PyArray_NOTYPE) \n\t\targs = Py_BuildValue(\"(Oi)\", m1, axis);\n\telse {\n\t\tPyArray_Descr *descr;\n\t\tdescr = PyArray_DescrFromType(rtype);\n\t\targs = Py_BuildValue(\"(Oic)\", m1, axis, descr->type);\n\t\tPy_DECREF(descr);\n\t}\n\tmeth = PyObject_GetAttrString(op, \"accumulate\");\n\tif (meth && PyCallable_Check(meth)) {\n\t\tret = PyObject_Call(meth, args, NULL);\n\t}\n\tPy_DECREF(args);\n\tPy_DECREF(meth);\n\treturn ret;\n}\t\n\n\nstatic PyObject *\nPyArray_GenericBinaryFunction(PyArrayObject *m1, PyObject *m2, PyObject *op) \n{\n if (op == NULL) {\n Py_INCREF(Py_NotImplemented);\n return Py_NotImplemented; \n }\n return PyObject_CallFunction(op, \"OO\", m1, m2);\n}\n\nstatic PyObject *\nPyArray_GenericUnaryFunction(PyArrayObject *m1, PyObject *op) \n{\n if (op == NULL) {\n Py_INCREF(Py_NotImplemented);\n return Py_NotImplemented; \n }\n return PyObject_CallFunction(op, \"(O)\", m1);\n}\n\nstatic PyObject *\nPyArray_GenericInplaceBinaryFunction(PyArrayObject *m1, \n\t\t\t\t PyObject *m2, PyObject *op) \n{\n if (op == NULL) {\n Py_INCREF(Py_NotImplemented);\n return Py_NotImplemented; \n }\n return PyObject_CallFunction(op, \"OOO\", m1, m2, m1);\n}\n\nstatic PyObject *\narray_add(PyArrayObject *m1, PyObject *m2) \n{ \n return PyArray_GenericBinaryFunction(m1, m2, n_ops.add); \n}\n\nstatic PyObject *\narray_subtract(PyArrayObject *m1, PyObject *m2) \n{\n\treturn PyArray_GenericBinaryFunction(m1, m2, n_ops.subtract);\n}\n\nstatic PyObject *\narray_multiply(PyArrayObject *m1, PyObject *m2) \n{\n return PyArray_GenericBinaryFunction(m1, m2, n_ops.multiply);\n}\n\nstatic PyObject *\narray_divide(PyArrayObject *m1, PyObject *m2) \n{\n return PyArray_GenericBinaryFunction(m1, m2, n_ops.divide);\n}\n\nstatic PyObject *\narray_remainder(PyArrayObject *m1, PyObject *m2) \n{\n return PyArray_GenericBinaryFunction(m1, m2, n_ops.remainder);\n}\n\nstatic PyObject *\narray_power(PyArrayObject *m1, PyObject *m2) \n{\n return PyArray_GenericBinaryFunction(m1, m2, n_ops.power);\n}\n\nstatic PyObject *\narray_negative(PyArrayObject *m1) \n{ \n return PyArray_GenericUnaryFunction(m1, n_ops.negative);\n}\n\nstatic PyObject *\narray_absolute(PyArrayObject *m1) \n{ \n return PyArray_GenericUnaryFunction(m1, n_ops.absolute);\n}\n\nstatic PyObject *\narray_invert(PyArrayObject *m1) \n{ \n return PyArray_GenericUnaryFunction(m1, n_ops.invert);\n}\n\nstatic PyObject *\narray_left_shift(PyArrayObject *m1, PyObject *m2) \n{\n return PyArray_GenericBinaryFunction(m1, m2, n_ops.left_shift);\n}\n\nstatic PyObject *\narray_right_shift(PyArrayObject *m1, PyObject *m2) \n{\n return PyArray_GenericBinaryFunction(m1, m2, n_ops.right_shift);\n}\n\nstatic PyObject *\narray_bitwise_and(PyArrayObject *m1, PyObject *m2) \n{\n return PyArray_GenericBinaryFunction(m1, m2, n_ops.bitwise_and);\n}\n\nstatic PyObject *\narray_bitwise_or(PyArrayObject *m1, PyObject *m2) \n{\n return PyArray_GenericBinaryFunction(m1, m2, n_ops.bitwise_or);\n}\n\nstatic PyObject *\narray_bitwise_xor(PyArrayObject *m1, PyObject *m2) \n{\n return PyArray_GenericBinaryFunction(m1, m2, n_ops.bitwise_xor);\n}\n\nstatic PyObject *\narray_inplace_add(PyArrayObject *m1, PyObject *m2) \n{\n return PyArray_GenericInplaceBinaryFunction(m1, m2, n_ops.add);\n}\n\nstatic PyObject *\narray_inplace_subtract(PyArrayObject *m1, PyObject *m2) \n{\n return PyArray_GenericInplaceBinaryFunction(m1, m2, n_ops.subtract);\n}\n\nstatic PyObject *\narray_inplace_multiply(PyArrayObject *m1, PyObject *m2) \n{\n return PyArray_GenericInplaceBinaryFunction(m1, m2, n_ops.multiply);\n}\n\nstatic PyObject *\narray_inplace_divide(PyArrayObject *m1, PyObject *m2) \n{\n return PyArray_GenericInplaceBinaryFunction(m1, m2, n_ops.divide);\n}\n\nstatic PyObject *\narray_inplace_remainder(PyArrayObject *m1, PyObject *m2) \n{\n return PyArray_GenericInplaceBinaryFunction(m1, m2, n_ops.remainder);\n}\n\nstatic PyObject *\narray_inplace_power(PyArrayObject *m1, PyObject *m2) \n{\n return PyArray_GenericInplaceBinaryFunction(m1, m2, n_ops.power);\n}\n\nstatic PyObject *\narray_inplace_left_shift(PyArrayObject *m1, PyObject *m2) \n{\n return PyArray_GenericInplaceBinaryFunction(m1, m2, n_ops.left_shift);\n}\n\nstatic PyObject *\narray_inplace_right_shift(PyArrayObject *m1, PyObject *m2) \n{\n return PyArray_GenericInplaceBinaryFunction(m1, m2, n_ops.right_shift);\n}\n\nstatic PyObject *\narray_inplace_bitwise_and(PyArrayObject *m1, PyObject *m2) \n{\n return PyArray_GenericInplaceBinaryFunction(m1, m2, n_ops.bitwise_and);\n}\n\nstatic PyObject *\narray_inplace_bitwise_or(PyArrayObject *m1, PyObject *m2) \n{\n return PyArray_GenericInplaceBinaryFunction(m1, m2, n_ops.bitwise_or);\n}\n\nstatic PyObject *\narray_inplace_bitwise_xor(PyArrayObject *m1, PyObject *m2) \n{\n return PyArray_GenericInplaceBinaryFunction(m1, m2, n_ops.bitwise_xor);\n}\n\nstatic PyObject *\narray_floor_divide(PyArrayObject *m1, PyObject *m2) \n{\n return PyArray_GenericBinaryFunction(m1, m2, n_ops.floor_divide);\n}\n\nstatic PyObject *\narray_true_divide(PyArrayObject *m1, PyObject *m2) \n{\n return PyArray_GenericBinaryFunction(m1, m2, n_ops.true_divide);\n}\n\nstatic PyObject *\narray_inplace_floor_divide(PyArrayObject *m1, PyObject *m2) \n{\n return PyArray_GenericInplaceBinaryFunction(m1, m2, \n\t\t\t\t\t\t n_ops.floor_divide);\n}\n\nstatic PyObject *\narray_inplace_true_divide(PyArrayObject *m1, PyObject *m2) \n{\n return PyArray_GenericInplaceBinaryFunction(m1, m2, \n\t\t\t\t\t\t n_ops.true_divide);\n}\n\n/* Array evaluates as \"TRUE\" if any of the elements are non-zero*/\nstatic int \narray_any_nonzero(PyArrayObject *mp) \n{\n\tintp index;\n\tPyArrayIterObject *it;\n\tBool anyTRUE = FALSE;\n\t\n\tit = (PyArrayIterObject *)PyArray_IterNew((PyObject *)mp);\n\tif (it==NULL) return anyTRUE;\n\tindex = it->size;\n\twhile(index--) {\n\t\tif (mp->descr->f->nonzero(it->dataptr, mp)) {\n\t\t\tanyTRUE = TRUE;\n\t\t\tbreak;\n\t\t}\n\t\tPyArray_ITER_NEXT(it);\n\t}\n\tPy_DECREF(it);\n\treturn anyTRUE;\n}\n\nstatic int\n_array_nonzero(PyArrayObject *mp)\n{\n\tintp n;\n\tn = PyArray_SIZE(mp);\n\tif (n == 1) {\n\t\treturn mp->descr->f->nonzero(mp->data, mp);\n\t}\n\telse if (n == 0) {\n\t\treturn 0;\n\t}\n\telse {\n\t\tPyErr_SetString(PyExc_ValueError, \n\t\t\t\t\"The truth value of an array \" \\\n\t\t\t\t\"with more than one element is ambiguous. \" \\\n\t\t\t\t\"Use a.any() or a.all()\");\n\t\treturn -1;\n\t}\n}\n\n\n\nstatic PyObject *\narray_divmod(PyArrayObject *op1, PyObject *op2) \n{\n PyObject *divp, *modp, *result;\n\n divp = array_floor_divide(op1, op2);\n if (divp == NULL) return NULL;\n modp = array_remainder(op1, op2);\n if (modp == NULL) {\n Py_DECREF(divp);\n return NULL;\n }\n result = Py_BuildValue(\"OO\", divp, modp);\n Py_DECREF(divp);\n Py_DECREF(modp);\n return result;\n}\n\n\nstatic PyObject *\narray_int(PyArrayObject *v) \n{ \n PyObject *pv, *pv2;\n if (PyArray_SIZE(v) != 1) {\n PyErr_SetString(PyExc_TypeError, \"only length-1 arrays can be\"\\\n\t\t\t\t\" converted to Python scalars\");\n return NULL;\n }\n pv = v->descr->f->getitem(v->data, v);\n if (pv == NULL) return NULL;\n if (pv->ob_type->tp_as_number == 0) {\n PyErr_SetString(PyExc_TypeError, \"cannot convert to an int; \"\\\n\t\t\t\t\"scalar object is not a number\");\n Py_DECREF(pv);\n return NULL;\n }\n if (pv->ob_type->tp_as_number->nb_int == 0) {\n PyErr_SetString(PyExc_TypeError, \"don't know how to convert \"\\\n\t\t\t\t\"scalar number to int\");\n Py_DECREF(pv);\n return NULL;\n }\n\n pv2 = pv->ob_type->tp_as_number->nb_int(pv);\n Py_DECREF(pv);\n return pv2;\t \n}\n\nstatic PyObject *\narray_float(PyArrayObject *v) \n{\n PyObject *pv, *pv2;\n if (PyArray_SIZE(v) != 1) {\n PyErr_SetString(PyExc_TypeError, \"only length-1 arrays can \"\\\n\t\t\t\t\"be converted to Python scalars\");\n return NULL;\n }\n pv = v->descr->f->getitem(v->data, v);\n if (pv == NULL) return NULL;\n if (pv->ob_type->tp_as_number == 0) {\n PyErr_SetString(PyExc_TypeError, \"cannot convert to an \"\\\n\t\t\t\t\"int; scalar object is not a number\");\n Py_DECREF(pv);\n return NULL;\n }\n if (pv->ob_type->tp_as_number->nb_float == 0) {\n PyErr_SetString(PyExc_TypeError, \"don't know how to convert \"\\\n\t\t\t\t\"scalar number to float\");\n Py_DECREF(pv);\n return NULL;\n }\n pv2 = pv->ob_type->tp_as_number->nb_float(pv);\n Py_DECREF(pv);\n return pv2;\t \n}\n\nstatic PyObject *\narray_long(PyArrayObject *v) \n{ \n PyObject *pv, *pv2;\n if (PyArray_SIZE(v) != 1) {\n PyErr_SetString(PyExc_TypeError, \"only length-1 arrays can \"\\\n\t\t\t\t\"be converted to Python scalars\");\n return NULL;\n }\n pv = v->descr->f->getitem(v->data, v);\n if (pv->ob_type->tp_as_number == 0) {\n PyErr_SetString(PyExc_TypeError, \"cannot convert to an int; \"\\\n\t\t\t\t\"scalar object is not a number\");\n return NULL;\n }\n if (pv->ob_type->tp_as_number->nb_long == 0) {\n PyErr_SetString(PyExc_TypeError, \"don't know how to convert \"\\\n\t\t\t\t\"scalar number to long\");\n return NULL;\n }\n pv2 = pv->ob_type->tp_as_number->nb_long(pv);\n Py_DECREF(pv);\n return pv2;\t \n}\n\nstatic PyObject *\narray_oct(PyArrayObject *v) \n{\t \n PyObject *pv, *pv2;\n if (PyArray_SIZE(v) != 1) {\n PyErr_SetString(PyExc_TypeError, \"only length-1 arrays can \"\\\n\t\t\t\t\"be converted to Python scalars\");\n return NULL;\n }\n pv = v->descr->f->getitem(v->data, v);\n if (pv->ob_type->tp_as_number == 0) {\n PyErr_SetString(PyExc_TypeError, \"cannot convert to an int; \"\\\n\t\t\t\t\"scalar object is not a number\");\n return NULL;\n }\n if (pv->ob_type->tp_as_number->nb_oct == 0) {\n PyErr_SetString(PyExc_TypeError, \"don't know how to convert \"\\\n\t\t\t\t\"scalar number to oct\");\n return NULL;\n }\n pv2 = pv->ob_type->tp_as_number->nb_oct(pv);\n Py_DECREF(pv);\n return pv2;\t \n}\n\nstatic PyObject *\narray_hex(PyArrayObject *v) \n{ \n PyObject *pv, *pv2;\n if (PyArray_SIZE(v) != 1) {\n PyErr_SetString(PyExc_TypeError, \"only length-1 arrays can \"\\\n\t\t\t\t\"be converted to Python scalars\");\n return NULL;\n }\n pv = v->descr->f->getitem(v->data, v);\n if (pv->ob_type->tp_as_number == 0) {\n PyErr_SetString(PyExc_TypeError, \"cannot convert to an int; \"\\\n\t\t\t\t\"scalar object is not a number\");\n return NULL;\n }\n if (pv->ob_type->tp_as_number->nb_hex == 0) {\n PyErr_SetString(PyExc_TypeError, \"don't know how to convert \"\\\n\t\t\t\t\"scalar number to hex\");\n return NULL;\n }\n pv2 = pv->ob_type->tp_as_number->nb_hex(pv);\n Py_DECREF(pv);\n return pv2;\t \n}\n\nstatic PyObject *\n_array_copy_nice(PyArrayObject *self)\n{\n\treturn PyArray_Return((PyArrayObject *)\t\t\\\n\t\t\t PyArray_Copy(self));\n}\n\nstatic PyNumberMethods array_as_number = {\n (binaryfunc)array_add,\t\t /*nb_add*/\n (binaryfunc)array_subtract,\t\t /*nb_subtract*/\n (binaryfunc)array_multiply,\t\t /*nb_multiply*/\n (binaryfunc)array_divide,\t\t /*nb_divide*/\n (binaryfunc)array_remainder,\t /*nb_remainder*/\n (binaryfunc)array_divmod,\t\t /*nb_divmod*/\n (ternaryfunc)array_power,\t\t /*nb_power*/\n (unaryfunc)array_negative, /*nb_neg*/\t\n (unaryfunc)_array_copy_nice,\t\t /*nb_pos*/ \n (unaryfunc)array_absolute,\t\t /*(unaryfunc)array_abs,*/\n (inquiry)_array_nonzero,\t\t /*nb_nonzero*/\n (unaryfunc)array_invert,\t\t /*nb_invert*/\n (binaryfunc)array_left_shift,\t /*nb_lshift*/\n (binaryfunc)array_right_shift,\t /*nb_rshift*/\n (binaryfunc)array_bitwise_and,\t /*nb_and*/\n (binaryfunc)array_bitwise_xor,\t /*nb_xor*/\n (binaryfunc)array_bitwise_or,\t /*nb_or*/\n 0,\t\t /*nb_coerce*/\n (unaryfunc)array_int,\t\t /*nb_int*/\n (unaryfunc)array_long,\t\t /*nb_long*/\n (unaryfunc)array_float,\t\t /*nb_float*/\n (unaryfunc)array_oct,\t\t /*nb_oct*/\n (unaryfunc)array_hex,\t\t /*nb_hex*/\n\n /*This code adds augmented assignment functionality*/\n /*that was made available in Python 2.0*/\n (binaryfunc)array_inplace_add,\t /*inplace_add*/\n (binaryfunc)array_inplace_subtract,\t /*inplace_subtract*/\n (binaryfunc)array_inplace_multiply,\t /*inplace_multiply*/\n (binaryfunc)array_inplace_divide,\t /*inplace_divide*/\n (binaryfunc)array_inplace_remainder, /*inplace_remainder*/\n (ternaryfunc)array_inplace_power,\t /*inplace_power*/\n (binaryfunc)array_inplace_left_shift, /*inplace_lshift*/\n (binaryfunc)array_inplace_right_shift, /*inplace_rshift*/\n (binaryfunc)array_inplace_bitwise_and, /*inplace_and*/\n (binaryfunc)array_inplace_bitwise_xor, /*inplace_xor*/\n (binaryfunc)array_inplace_bitwise_or, /*inplace_or*/\n\n (binaryfunc)array_floor_divide,\t /*nb_floor_divide*/\n (binaryfunc)array_true_divide,\t /*nb_true_divide*/\n (binaryfunc)array_inplace_floor_divide, /*nb_inplace_floor_divide*/\n (binaryfunc)array_inplace_true_divide, /*nb_inplace_true_divide*/\n\n};\n\n/****************** End of Buffer Protocol *******************************/\n\n\n/*************************************************************************\n **************** Implement Sequence Protocol **************************\n *************************************************************************/\n\n/* Some of this is repeated in the array_as_mapping protocol. But\n we fill it in here so that PySequence_XXXX calls work as expected \n*/\n\n\nstatic PyObject * \narray_slice(PyArrayObject *self, int ilow, int ihigh) \n{\n PyArrayObject *r;\n int l;\n char *data;\n\n if (self->nd == 0) {\n PyErr_SetString(PyExc_ValueError, \"cannot slice a scalar\");\n return NULL;\n }\n \t\n l=self->dimensions[0];\n if (ihigh < 0) ihigh += l;\n if (ilow < 0) ilow += l;\n if (ilow < 0) ilow = 0;\n else if (ilow > l) ilow = l;\n if (ihigh < 0) ihigh = 0;\n else if (ihigh > l) ihigh = l;\n if (ihigh < ilow) ihigh = ilow;\n\n if (ihigh != ilow) {\n data = index2ptr(self, ilow);\n if (data == NULL) return NULL;\n } else {\n data = self->data;\n }\n\n self->dimensions[0] = ihigh-ilow;\n\tPy_INCREF(self->descr);\n r = (PyArrayObject *)\t\t\t\t\t\t\\\n\t\tPyArray_NewFromDescr(self->ob_type, self->descr,\n\t\t\t\t self->nd, self->dimensions, \n\t\t\t\t self->strides, data,\n\t\t\t\t self->flags, (PyObject *)self);\n\n self->dimensions[0] = l;\n r->base = (PyObject *)self;\n Py_INCREF(self);\n\tPyArray_UpdateFlags(r, UPDATE_ALL_FLAGS); \n return (PyObject *)r;\n}\n\n\nstatic int \narray_ass_slice(PyArrayObject *self, int ilow, int ihigh, PyObject *v) {\n int ret;\n PyArrayObject *tmp;\n\t\n if (v == NULL) {\n PyErr_SetString(PyExc_ValueError, \n \"cannot delete array elements\");\n return -1;\n }\n\tif (!PyArray_ISWRITEABLE(self)) {\n\t\tPyErr_SetString(PyExc_RuntimeError,\n\t\t\t\t\"array is not writeable\");\n\t\treturn -1;\n\t}\n if ((tmp = (PyArrayObject *)array_slice(self, ilow, ihigh)) \\\n == NULL) \n return -1; \n ret = PyArray_CopyObject(tmp, v);\n Py_DECREF(tmp);\n\t\n return ret;\n}\n\nstatic int\narray_contains(PyArrayObject *self, PyObject *el)\n{\n /* equivalent to (self == el).any() */\n\n PyObject *res; \n int ret;\n\n res = PyArray_EnsureArray(PyObject_RichCompare((PyObject *)self, el, Py_EQ));\n if (res == NULL) return -1;\n ret = array_any_nonzero((PyArrayObject *)res);\n Py_DECREF(res);\n return ret;\n}\n\n\nstatic PySequenceMethods array_as_sequence = {\n (inquiry)array_length,\t\t/*sq_length*/\n (binaryfunc)NULL, /* sq_concat is handled by nb_add*/\n (intargfunc)NULL, /* sq_repeat is handled nb_multiply*/\n (intargfunc)array_item_nice,\t\t/*sq_item*/\n (intintargfunc)array_slice,\t\t/*sq_slice*/\n (intobjargproc)array_ass_item,\t/*sq_ass_item*/\n (intintobjargproc)array_ass_slice,\t/*sq_ass_slice*/\n\t(objobjproc) array_contains, /* sq_contains */\n\t(binaryfunc) NULL, /* sg_inplace_concat */\n\t(intargfunc) NULL /* sg_inplace_repeat */\n};\n\n\n/****************** End of Sequence Protocol ****************************/\n\n\nstatic int \ndump_data(char **string, int *n, int *max_n, char *data, int nd, \n intp *dimensions, intp *strides, PyArrayObject* self) \n{\n PyArray_Descr *descr=self->descr;\n PyObject *op, *sp;\n char *ostring;\n int i, N;\n\t\n#define CHECK_MEMORY if (*n >= *max_n-16) { *max_n *= 2; \\\n\t\t*string = (char *)_pya_realloc(*string, *max_n); }\n\t\n if (nd == 0) {\n\t\t\n if ((op = descr->f->getitem(data, self)) == NULL) return -1;\n sp = PyObject_Repr(op);\n if (sp == NULL) {Py_DECREF(op); return -1;}\n ostring = PyString_AsString(sp);\n N = PyString_Size(sp)*sizeof(char);\n *n += N;\n CHECK_MEMORY\n memmove(*string+(*n-N), ostring, N);\n Py_DECREF(sp);\n Py_DECREF(op);\n return 0;\n } else {\n CHECK_MEMORY\n (*string)[*n] = '[';\n *n += 1;\n for(i=0; idata, \n\t\t self->nd, self->dimensions, \n self->strides, self) < 0) { \n\t\t_pya_free(string); return NULL; \n\t}\n\t\n\tif (PyArray_ISEXTENDED(self)) {\n\t\tchar buf[100];\n\t\tsnprintf(buf, sizeof(buf), \"%d\", self->descr->elsize);\n\t\tsprintf(string+n, \", '%c%s')\", self->descr->type, buf);\n\t\tret = PyString_FromStringAndSize(string, n+6+strlen(buf));\n\t}\n\telse {\n\t\tsprintf(string+n, \", '%c')\", self->descr->type);\n\t\tret = PyString_FromStringAndSize(string, n+6);\n\t}\n\t\n\n _pya_free(string);\n return ret;\n}\n\nstatic PyObject *PyArray_StrFunction=NULL;\nstatic PyObject *PyArray_ReprFunction=NULL;\n\n/*OBJECT_API\n Set the array print function to be a Python function.\n*/\nstatic void \nPyArray_SetStringFunction(PyObject *op, int repr) \n{\n if (repr) {\n\t\t/* Dispose of previous callback */\n Py_XDECREF(PyArray_ReprFunction); \n\t\t/* Add a reference to new callback */\n Py_XINCREF(op); \n\t\t/* Remember new callback */\n PyArray_ReprFunction = op; \n } else {\n\t\t/* Dispose of previous callback */\n Py_XDECREF(PyArray_StrFunction); \n\t\t/* Add a reference to new callback */\n Py_XINCREF(op); \n\t\t/* Remember new callback */\n PyArray_StrFunction = op; \n }\n}\n\nstatic PyObject *\narray_repr(PyArrayObject *self) \n{\n PyObject *s, *arglist;\n\t\n if (PyArray_ReprFunction == NULL) {\n s = array_repr_builtin(self);\n } else {\n arglist = Py_BuildValue(\"(O)\", self);\n s = PyEval_CallObject(PyArray_ReprFunction, arglist);\n Py_DECREF(arglist); \n }\n return s;\n}\n\nstatic PyObject *\narray_str(PyArrayObject *self) \n{\n PyObject *s, *arglist;\n\t\n if (PyArray_StrFunction == NULL) {\n s = array_repr(self);\n } else {\n arglist = Py_BuildValue(\"(O)\", self);\n s = PyEval_CallObject(PyArray_StrFunction, arglist);\n Py_DECREF(arglist); \n }\n return s;\n}\n\nstatic PyObject *\narray_richcompare(PyArrayObject *self, PyObject *other, int cmp_op) \n{\n PyObject *array_other, *result;\n\n switch (cmp_op) \n {\n case Py_LT:\n return PyArray_GenericBinaryFunction(self, other, \n\t\t\t\t\t\t\t n_ops.less);\n case Py_LE:\n return PyArray_GenericBinaryFunction(self, other, \n\t\t\t\t\t\t\t n_ops.less_equal);\n case Py_EQ:\n /* Try to convert other to an array */\n\t\t\tif (!PyArray_Check(other)) {\n\t\t\t\tarray_other = PyArray_FromObject(other, \n\t\t\t\t\t\t\t\t self->descr->type_num, 0, 0);\n\t\t\t\t/* If not successful, then return the integer\n\t\t\t\t object 0. This fixes code that used to\n\t\t\t\t allow equality comparisons between arrays\n\t\t\t\t and other objects which would give a result\n\t\t\t\t of 0\n\t\t\t\t*/\n\t\t\t\tif ((array_other == NULL) ||\t\\\n\t\t\t\t (array_other == Py_None)) {\n\t\t\t\t\tPy_XDECREF(array_other);\n\t\t\t\t\tPyErr_Clear();\n\t\t\t\t\tPy_INCREF(Py_False);\n\t\t\t\t\treturn Py_False;\n\t\t\t\t}\n\t\t\t}\n\t\t\telse {\n\t\t\t\tPy_INCREF(other);\n\t\t\t\tarray_other = other;\n\t\t\t}\n result = PyArray_GenericBinaryFunction(self, \n\t\t\t\t\t\t\t array_other, \n\t\t\t\t\t\t\t n_ops.equal);\n /* If the comparison results in NULL, then the \n\t\t\t two array objects can not be compared together so \n\t\t\t return zero \n */\n Py_DECREF(array_other);\n if (result == NULL) {\n PyErr_Clear();\n Py_INCREF(Py_False);\n return Py_False;\n }\n return result;\n case Py_NE:\n /* Try to convert other to an array */\n\t\t\tif (!PyArray_Check(other)) {\n\t\t\t\tarray_other = PyArray_FromObject(other, \n\t\t\t\t\t\t\t\t self->descr->type_num, 0, 0);\n\t\t\t\t/* If not successful, then objects cannot be \n\t\t\t\t compared and cannot be equal, therefore, \n\t\t\t\t return True;\n\t\t\t\t*/\n\t\t\t\tif ((array_other == NULL) ||\t\\\n\t\t\t\t (array_other == Py_None)) {\n\t\t\t\t\tPy_XDECREF(array_other);\n\t\t\t\t\tPyErr_Clear();\n\t\t\t\t\tPy_INCREF(Py_True);\n\t\t\t\t\treturn Py_True;\n\t\t\t\t}\n\t\t\t}\n\t\t\telse {\n\t\t\t\tPy_INCREF(other);\n\t\t\t\tarray_other = other;\n\t\t\t}\n\t\t\tresult = PyArray_GenericBinaryFunction(self, \n\t\t\t\t\t\t\t array_other, \n\t\t\t\t\t\t\t n_ops.not_equal);\n\t\t\tPy_DECREF(array_other);\n if (result == NULL) {\n PyErr_Clear();\n Py_INCREF(Py_True);\n return Py_True;\n }\n return result;\n case Py_GT:\n return PyArray_GenericBinaryFunction(self, other, \n\t\t\t\t\t\t\t n_ops.greater);\n case Py_GE:\n return PyArray_GenericBinaryFunction(self, \n\t\t\t\t\t\t\t other, \n\t\t\t\t\t \t n_ops.greater_equal);\n }\n return NULL;\n}\n\nstatic PyObject *\n_check_axis(PyArrayObject *arr, int *axis, int flags)\n{\n\tPyObject *temp;\n\tint n = arr->nd;\n\n\tif ((*axis >= MAX_DIMS) || (n==0)) {\n\t\ttemp = PyArray_Ravel(arr,0);\n\t\t*axis = PyArray_NDIM(temp)-1;\n\t\treturn temp;\n\t}\n\telse {\n\t\tif (flags) {\n\t\t\ttemp = PyArray_CheckFromAny((PyObject *)arr, NULL, \n 0, 0, flags, NULL);\n\t\t\tif (temp == NULL) return NULL;\n\t\t}\n\t\telse {\n\t\t\tPy_INCREF(arr);\n\t\t\ttemp = (PyObject *)arr;\n\t\t}\n\t}\n\tif (*axis < 0) *axis += n;\n\tif ((*axis < 0) || (*axis >= n)) {\n\t\tPyErr_Format(PyExc_ValueError, \n\t\t\t \"axis(=%d) out of bounds\", *axis);\n\t\tPy_DECREF(temp);\n\t\treturn NULL;\n\t}\n\treturn temp;\n}\n\n#include \"arraymethods.c\"\n\n/* Lifted from numarray */\nstatic PyObject *\nPyArray_IntTupleFromIntp(int len, intp *vals)\n{\n\tint i;\n PyObject *intTuple = PyTuple_New(len);\n if (!intTuple) goto fail;\n for(i=0; i= SIZEOF_INTP\n\t\tif (!(op = PyNumber_Int(seq))) return -1;\n#else\n\t\tif (!(op = PyNumber_Long(seq))) return -1;\n#endif\n\t\tnd = 1;\n#if SIZEOF_LONG >= SIZEOF_INTP\n\t\tvals[0] = (intp ) PyInt_AsLong(op);\n#else\n\t\tvals[0] = (intp ) PyLong_AsLongLong(op);\n#endif\n\t\tPy_DECREF(op);\n\t} else {\n\t\tfor(i=0; i < MIN(nd,maxvals); i++) {\n\t\t\top = PySequence_GetItem(seq, i);\n\t\t\tif (op == NULL) return -1;\n#if SIZEOF_LONG >= SIZEOF_INTP\n\t\t\tvals[i]=(intp )PyInt_AsLong(op);\n#else\n\t\t\tvals[i]=(intp )PyLong_AsLongLong(op);\n#endif\n\t\t\tPy_DECREF(op);\n\t\t\tif(PyErr_Occurred()) return -1;\n\t\t}\n\t}\n\treturn nd;\n}\n\n\n/* Check whether the given array is stored contiguously (row-wise) in\n memory. */\nstatic int\n_IsContiguous(PyArrayObject *ap) \n{\n\tregister intp sd;\n\tregister intp dim;\n\tregister int i;\n \n\n\tif (ap->nd == 0) return 1;\n\tsd = ap->descr->elsize;\n\tif (ap->nd == 1) return (ap->dimensions[0] == 1 || \\\n\t\t\t\t sd == ap->strides[0]);\n\tfor (i = ap->nd-1; i >= 0; --i) {\n\t\tdim = ap->dimensions[i];\n\t\t/* contiguous by definition */\n\t\tif (dim == 0) return 1;\n\t\tif (ap->strides[i] != sd) return 0;\n\t\tsd *= dim;\n\t}\n\treturn 1;\n}\n\n\nstatic int \n_IsFortranContiguous(PyArrayObject *ap) \n{\n\tregister intp sd;\n\tregister intp dim;\n\tregister int i;\n\t\n\tif (ap->nd == 0) return 1;\n\tsd = ap->descr->elsize;\n\tif (ap->nd == 1) return (ap->dimensions[0] == 1 || \\\n\t\t\t\t sd == ap->strides[0]);\n\tfor (i=0; i< ap->nd; ++i) {\n\t\tdim = ap->dimensions[i];\n\t\t/* contiguous by definition */\n\t\tif (dim == 0) return 1; \n\t\tif (ap->strides[i] != sd) return 0;\n\t\tsd *= dim;\n\t}\n\treturn 1;\n}\n\nstatic int\n_IsAligned(PyArrayObject *ap) \n{\n\tint i, alignment, aligned=1;\n\tintp ptr;\n\tint type = ap->descr->type_num;\n\n\tif ((type == PyArray_STRING) || (type == PyArray_VOID))\n\t\treturn 1;\n\n\talignment = ap->descr->alignment;\n\tif (alignment == 1) return 1;\n\n\tptr = (intp) ap->data;\n aligned = (ptr % alignment) == 0;\n for (i=0; i nd; i++)\n aligned &= ((ap->strides[i] % alignment) == 0);\n return aligned != 0;\n}\n\nstatic Bool\n_IsWriteable(PyArrayObject *ap)\n{\n\tPyObject *base=ap->base;\n\tvoid *dummy;\n\tint n;\n\n\t/* If we own our own data, then no-problem */\n\tif ((base == NULL) || (ap->flags & OWN_DATA)) return TRUE;\n\n\t/* Get to the final base object \n\t If it is a writeable array, then return TRUE\n\t If we can find an array object \n\t or a writeable buffer object as the final base object\n\t or a string object (for pickling support memory savings).\n\t - this last could be removed if a proper pickleable \n\t buffer was added to Python.\n\t*/\n\n\twhile(PyArray_Check(base)) {\n\t\tif (PyArray_CHKFLAGS(base, OWN_DATA)) \n\t\t\treturn (Bool) (PyArray_ISWRITEABLE(base));\n\t\tbase = PyArray_BASE(base);\n\t}\n\n\t/* here so pickle support works seamlessly \n\t and unpickled array can be set and reset writeable \n\t -- could be abused -- */\n\tif PyString_Check(base) return TRUE;\n\n\tif (PyObject_AsWriteBuffer(base, &dummy, &n) < 0)\n\t\treturn FALSE;\n\t\n\treturn TRUE;\n}\n\n\n/*OBJECT_API\n Update Several Flags at once.\n*/\nstatic void\nPyArray_UpdateFlags(PyArrayObject *ret, int flagmask)\n{\n\n\tif (flagmask & FORTRAN) {\n\t\tif (_IsFortranContiguous(ret)) {\n\t\t\tret->flags |= FORTRAN;\n\t\t\tif (ret->nd > 1) ret->flags &= ~CONTIGUOUS;\n\t\t}\n\t\telse ret->flags &= ~FORTRAN;\n\t}\n\tif (flagmask & CONTIGUOUS) {\n\t\tif (_IsContiguous(ret)) {\n\t\t\tret->flags |= CONTIGUOUS;\n\t\t\tif (ret->nd > 1) ret->flags &= ~FORTRAN;\n\t\t}\n\t\telse ret->flags &= ~CONTIGUOUS;\n\t}\n\tif (flagmask & ALIGNED) {\n\t\tif (_IsAligned(ret)) ret->flags |= ALIGNED;\n\t\telse ret->flags &= ~ALIGNED;\n\t}\n\t/* This is not checked by default WRITEABLE is not part of UPDATE_ALL_FLAGS */\n\tif (flagmask & WRITEABLE) {\n\t if (_IsWriteable(ret)) ret->flags |= WRITEABLE;\n\t \telse ret->flags &= ~WRITEABLE;\t\n }\n\treturn;\n}\n\n/* This routine checks to see if newstrides (of length nd) will not \n walk outside of the memory implied by a single segment array of the provided \n dimensions and element size. If numbytes is 0 it will be calculated from \n the provided shape and element size.\n*/\n/*OBJECT_API*/\nstatic Bool\nPyArray_CheckStrides(int elsize, int nd, intp numbytes, \n\t\t intp *dims, intp *newstrides)\n{\n\tint i;\n\t\n\tif (numbytes == 0) \n\t\tnumbytes = PyArray_MultiplyList(dims, nd) * elsize;\n\t\n\tfor (i=0; i numbytes) {\n\t\t\treturn FALSE;\n\t\t}\n\t}\n\treturn TRUE;\n\t\n}\n\n\n/* This is the main array creation routine. */\n\n/* Flags argument has multiple related meanings \n depending on data and strides: \n\n If data is given, then flags is flags associated with data. \n If strides is not given, then a contiguous strides array will be created\n and the CONTIGUOUS bit will be set. If the flags argument \n has the FORTRAN bit set, then a FORTRAN-style strides array will be\n created (and of course the FORTRAN flag bit will be set). \n\n If data is not given but created here, then flags will be DEFAULT_FLAGS\n and a non-zero flags argument can be used to indicate a FORTRAN style\n array is desired. \n*/\n\nstatic intp\n_array_fill_strides(intp *strides, intp *dims, int nd, intp itemsize, \n\t\t int inflag, int *objflags) \n{\n\tint i;\n\t/* Only make Fortran strides if not contiguous as well */\n\tif ((inflag & FORTRAN) && !(inflag & CONTIGUOUS)) {\n\t\tfor (i=0; i 1) *objflags &= ~CONTIGUOUS;\n\t\telse *objflags |= CONTIGUOUS;\n\t}\n\telse {\n\t\tfor (i=nd-1;i>=0;i--) {\n\t\t\tstrides[i] = itemsize;\n\t\t\titemsize *= dims[i] ? dims[i] : 1;\n\t\t}\n\t\t*objflags |= CONTIGUOUS;\n\t\tif (nd > 1) *objflags &= ~FORTRAN;\n\t\telse *objflags |= FORTRAN;\n\t}\n\treturn itemsize;\n}\n\n/*OBJECT_API\n Generic new array creation routine.\n*/\nstatic PyObject *\nPyArray_New(PyTypeObject *subtype, int nd, intp *dims, int type_num,\n intp *strides, void *data, int itemsize, int flags,\n\t PyObject *obj)\n{\n\tPyArray_Descr *descr;\n\tPyObject *new;\n\n\tdescr = PyArray_DescrFromType(type_num);\n\tif (descr == NULL) return NULL;\t\n\tif (descr->elsize == 0) {\n\t\tif (itemsize < 1) {\n\t\t\tPyErr_SetString(PyExc_ValueError,\n\t\t\t\t\t\"data type must provide an itemsize\");\n\t\t\tPy_DECREF(descr);\n\t\t\treturn NULL;\n\t\t}\n\t\tPyArray_DESCR_REPLACE(descr);\n\t\tdescr->elsize = itemsize;\n\t}\n\tnew = PyArray_NewFromDescr(subtype, descr, nd, dims, strides,\n\t\t\t\t data, flags, obj);\n\treturn new;\n}\n\n/* Change a sub-array field to the base descriptor */\nstatic int\n_update_descr_and_dimensions(PyArray_Descr **des, intp *newdims, \n\t\t\t intp *newstrides, int oldnd)\n{\n\tPyArray_Descr *old;\n\tint newnd;\n\tint numnew;\n\tintp *mydim;\n\tint i;\n\t\n\told = *des;\n\t*des = old->subarray->base;\n\n\tmydim = newdims + oldnd;\n\tif (PyTuple_Check(old->subarray->shape)) {\n\t\tnumnew = PyTuple_GET_SIZE(old->subarray->shape);\n\t\t\n\t\tfor (i=0; isubarray->shape, i));\n\t\t}\n\t}\n\telse {\n\t\tnumnew = 1;\n\t\tmydim[0] = (intp) PyInt_AsLong(old->subarray->shape);\n\t}\n\t\n\tnewnd = oldnd + numnew;\n\n\tif (newstrides) {\n\t\tintp tempsize;\n\t\tintp *mystrides;\n\t\tmystrides = newstrides + oldnd;\n\t\t/* Make new strides */\n\t\ttempsize = (*des)->elsize;\n\t\tfor (i=numnew-1; i>=0; i--) {\n\t\t\tmystrides[i] = tempsize;\n\t\t\ttempsize *= mydim[i] ? mydim[i] : 1;\n\t\t}\n\t}\n\tPy_INCREF(*des); \n\tPy_DECREF(old); \n\treturn newnd;\n}\n\n\n/* steals a reference to descr (even on failure) */\n/*OBJECT_API\n Generic new array creation routine.\n*/\nstatic PyObject *\nPyArray_NewFromDescr(PyTypeObject *subtype, PyArray_Descr *descr, int nd, \n\t\t intp *dims, intp *strides, void *data, \n\t\t int flags, PyObject *obj)\n{\t\n\tPyArrayObject *self;\n\tregister int i;\n\tintp sd;\n\n\tif (descr->subarray) {\n\t\tPyObject *ret;\n\t\tintp newdims[2*MAX_DIMS];\n\t\tintp *newstrides=NULL;\n\t\tmemcpy(newdims, dims, nd*sizeof(intp));\n\t\tif (strides) {\n\t\t\tnewstrides = newdims + MAX_DIMS;\n\t\t\tmemcpy(newstrides, strides, nd*sizeof(intp));\n\t\t}\n\t\tnd =_update_descr_and_dimensions(&descr, newdims, \n\t\t\t\t\t\t newstrides, nd);\n\t\tret = PyArray_NewFromDescr(subtype, descr, nd, newdims, \n\t\t\t\t\t newstrides,\n\t\t\t\t\t data, flags, obj);\n\t\treturn ret;\n\t}\n\n\tif (nd < 0) {\n\t\tPyErr_SetString(PyExc_ValueError,\n\t\t\t\t\"number of dimensions must be >=0\");\n\t\tPy_DECREF(descr);\n\t\treturn NULL;\n\t}\n if (nd > MAX_DIMS) {\n PyErr_Format(PyExc_ValueError,\n \"maximum number of dimensions is %d\", MAX_DIMS);\n\t\tPy_DECREF(descr);\n return NULL;\n\t}\n\n\t/* Check dimensions */\n\tfor (i=nd-1;i>=0;i--) {\n\t\tif (dims[i] < 0) {\n\t\t\tPyErr_SetString(PyExc_ValueError,\n\t\t\t\t\t\"negative dimensions \"\t\\\n\t\t\t\t\t\"are not allowed\");\n\t\t\tPy_DECREF(descr);\n\t\t\treturn NULL;\n\t\t}\n\t}\n\t\n\tself = (PyArrayObject *) subtype->tp_alloc(subtype, 0);\n\tif (self == NULL) {\n\t\tPy_DECREF(descr);\n\t\treturn NULL;\t\n\t}\n\tself->nd = nd;\n\tself->dimensions = NULL;\n\tself->data = NULL;\n\tif (data == NULL) { /* strides is NULL too */\n\t\tself->flags = DEFAULT_FLAGS;\n\t\tif (flags) {\n\t\t\tself->flags |= FORTRAN; \n\t\t\tif (nd > 1) self->flags &= ~CONTIGUOUS;\n\t\t\tflags = FORTRAN;\n\t\t}\n\t}\n\telse self->flags = (flags & ~UPDATEIFCOPY);\n\t\t\n\tsd = descr->elsize;\n\tself->descr = descr;\n\tself->base = (PyObject *)NULL;\n self->weakreflist = (PyObject *)NULL;\n\t\n\tif (nd > 0) {\n\t\tself->dimensions = PyDimMem_NEW(2*nd);\n\t\tif (self->dimensions == NULL) {\n\t\t\tPyErr_NoMemory();\n\t\t\tgoto fail;\n\t\t}\n\t\tself->strides = self->dimensions + nd;\n\t\tmemcpy(self->dimensions, dims, sizeof(intp)*nd);\n\t\tif (strides == NULL) { /* fill it in */\n\t\t\tsd = _array_fill_strides(self->strides, dims, nd, sd,\n\t\t\t\t\t\t flags, &(self->flags));\n\t\t}\n\t\telse {\n\t\t\tif (data == NULL) {\n\t\t\t\tPyErr_SetString(PyExc_ValueError, \n\t\t\t\t\t\t\"if 'strides' is given in \" \\\n\t\t\t\t\t\t\"array creation, data must \" \\\n\t\t\t\t\t\t\"be given too\");\n\t\t\t\tgoto fail;\n\t\t\t} \n\t\t\tmemcpy(self->strides, strides, sizeof(intp)*nd);\n\t\t}\n\t} \t\n\t\t\n\tif (data == NULL) {\n\n\t\t/* Allocate something even for zero-space arrays \n\t\t e.g. shape=(0,) -- otherwise buffer exposure \n\t\t (a.data) doesn't work as it should. */\n\n\t\tif (sd==0) sd = descr->elsize;\n\n\t\tif ((data = PyDataMem_NEW(sd))==NULL) {\n\t\t\tPyErr_NoMemory();\n\t\t\tgoto fail;\n\t\t}\n\t\tself->flags |= OWN_DATA;\n\n\t\t/* It is bad to have unitialized OBJECT pointers */\n /* which could also be sub-fields of a VOID array */\n\t\tif (descr->hasobject) {\n if (descr != &OBJECT_Descr) {\n PyErr_SetString(PyExc_TypeError,\n \"fields with object members \" \\\n \"not yet supported.\");\n goto fail;\n }\n\t\t\tmemset(data, 0, sd);\n\t\t}\n\t}\n\telse {\n self->flags &= ~OWN_DATA; /* If data is passed in, \n\t\t\t\t\t this object won't own it \n\t\t\t\t\t by default.\n\t\t\t\t\t Caller must arrange for \n\t\t\t\t\t this to be reset if truly\n\t\t\t\t\t desired */\n }\n self->data = data;\n\n /* call the __array_finalize__\n\t method if a subtype and some object passed in */\n\tif ((obj != NULL) && (subtype != &PyArray_Type) && \n\t (subtype != &PyBigArray_Type)) {\n\t\tPyObject *res, *func, *args;\n\t\tstatic PyObject *str=NULL;\n\n\t\tif (str == NULL) {\n\t\t\tstr = PyString_InternFromString(\"__array_finalize__\");\n\t\t}\n\t\tif (!(self->flags & OWNDATA)) { /* did not allocate own data */\n\t\t\t /* update flags before calling back into\n\t\t\t Python */\n\t\t\tPyArray_UpdateFlags(self, UPDATE_ALL_FLAGS);\n\t\t}\n\t\tfunc = PyObject_GetAttr((PyObject *)self, str);\n\t\tif (func) {\n\t\t\targs = PyTuple_New(1);\n\t\t\tPy_INCREF(obj);\n\t\t\tPyTuple_SET_ITEM(args, 0, obj);\n\t\t\tres = PyObject_Call(func, args, NULL);\n\t\t\tPy_DECREF(args);\n\t\t\tPy_DECREF(func);\n\t\t\tif (res == NULL) goto fail;\n\t\t\telse Py_DECREF(res);\n\t\t}\n\t}\n\t\n\treturn (PyObject *)self;\n\n fail:\n\tPy_DECREF(self);\n\treturn NULL;\n}\n\n\n\n/*OBJECT_API\n Resize (reallocate data). Only works if nothing else is referencing\n this array and it is contiguous.\n*/\nstatic PyObject * \nPyArray_Resize(PyArrayObject *self, PyArray_Dims *newshape)\n{\n intp oldsize, newsize;\n int new_nd=newshape->len, k, n, elsize;\n int refcnt;\n intp* new_dimensions=newshape->ptr;\n intp new_strides[MAX_DIMS];\n intp sd;\n intp *dimptr;\n char *new_data;\n\t\n if (!PyArray_ISCONTIGUOUS(self)) {\n PyErr_SetString(PyExc_ValueError, \n \"resize only works on contiguous arrays\");\n return NULL;\n }\n\n newsize = PyArray_MultiplyList(new_dimensions, new_nd);\n oldsize = PyArray_SIZE(self);\n \n\tif (oldsize != newsize) {\n\t\tif (!(self->flags & OWN_DATA)) {\n\t\t\tPyErr_SetString(PyExc_ValueError, \n\t\t\t\t\t\"cannot resize this array: \"\t\\\n\t\t\t\t\t\"it does not own its data\");\n\t\t\treturn NULL;\n\t\t}\n\t\t\n\t\trefcnt = REFCOUNT(self);\n\t\tif ((refcnt > 2) || (self->base != NULL) || \\\n\t\t (self->weakreflist != NULL)) {\n\t\t\tPyErr_SetString(PyExc_ValueError, \n\t\t\t\t\t\"cannot resize an array that has \"\\\n\t\t\t\t\t\"been referenced or is referencing\\n\"\\\n\t\t\t\t\t\"another array in this way. Use the \"\\\n\t\t\t\t\t\"resize function\");\n\t\t\treturn NULL;\n\t\t} \n\t\t\t\t\n\t\tif (newsize == 0) sd = self->descr->elsize;\t\n\t\telse sd = newsize * self->descr->elsize;\n\t\t/* Reallocate space if needed */\n\t\tnew_data = PyDataMem_RENEW(self->data, sd);\n\t\tif (new_data == NULL) {\n\t\t\tPyErr_SetString(PyExc_MemoryError, \n\t\t\t\t\t\"cannot allocate memory for array\");\n\t\t\treturn NULL;\n\t\t}\n\t\tself->data = new_data;\n\t}\n \n if ((newsize > oldsize) && PyArray_ISWRITEABLE(self)) { \n\t\t/* Fill new memory with zeros */\n elsize = self->descr->elsize;\n\t\tif ((PyArray_TYPE(self) == PyArray_OBJECT)) {\n\t\t\tPyObject *zero = PyInt_FromLong(0);\n PyObject **optr;\n\t\t\toptr = ((PyObject **)self->data) + oldsize;\n\t\t\tn = newsize - oldsize;\n\t\t\tfor (k=0; kdata+oldsize*elsize, 0, \n\t\t\t (newsize-oldsize)*elsize);\n\t\t}\n\t}\n \n if (self->nd != new_nd) { /* Different number of dimensions. */\n self->nd = new_nd;\n \n /* Need new dimensions and strides arrays */\n dimptr = PyDimMem_RENEW(self->dimensions, 2*new_nd);\n if (dimptr == NULL) {\n\t\t\tPyErr_SetString(PyExc_MemoryError, \n \"cannot allocate memory for array \" \\\n \"(array may be corrupted)\");\n return NULL;\n }\n self->dimensions = dimptr;\n\t\tself->strides = dimptr + new_nd;\n }\n\n /* make new_strides variable */\n sd = (intp) self->descr->elsize;\n sd = _array_fill_strides(new_strides, new_dimensions, new_nd, sd,\n 0, &(self->flags));\n\n \n memmove(self->dimensions, new_dimensions, new_nd*sizeof(intp));\n memmove(self->strides, new_strides, new_nd*sizeof(intp));\n\n Py_INCREF(Py_None);\t\n return Py_None;\n \n}\n\n\n/* Assumes contiguous */\n/*OBJECT_API*/\nstatic void\nPyArray_FillObjectArray(PyArrayObject *arr, PyObject *obj)\n{\n PyObject **optr;\n intp i,n;\n optr = (PyObject **)(arr->data);\n n = PyArray_SIZE(arr);\n if (obj == NULL) {\n for (i=0; ielsize;\n\tPy_INCREF(descr);\n\tnewarr = PyArray_FromAny(obj, descr, 0,0, ALIGNED, NULL);\n\tif (newarr == NULL) return -1;\n\tfromptr = PyArray_DATA(newarr);\n\tsize=PyArray_SIZE(arr);\n\tswap=!PyArray_ISNOTSWAPPED(arr);\n\tcopyswap = arr->descr->f->copyswap;\n\tif (PyArray_ISONESEGMENT(arr)) {\n\t\tchar *toptr=PyArray_DATA(arr);\n\t\twhile (size--) {\n\t\t\tcopyswap(toptr, fromptr, swap, itemsize);\n\t\t\ttoptr += itemsize;\n\t\t}\n\t}\n\telse {\n\t\tPyArrayIterObject *iter;\n\t\t\n\t\titer = (PyArrayIterObject *)\\\n\t\t\tPyArray_IterNew((PyObject *)arr);\n\t\tif (iter == NULL) {\n\t\t\tPy_DECREF(newarr);\n\t\t\treturn -1;\n\t\t}\n\t\twhile(size--) {\n\t\t\tcopyswap(iter->dataptr, fromptr, swap, itemsize);\n\t\t\tPyArray_ITER_NEXT(iter);\n\t\t}\n\t\tPy_DECREF(iter);\n\t}\n\tPy_DECREF(newarr);\n\treturn 0;\n}\n\nstatic PyObject *\narray_new(PyTypeObject *subtype, PyObject *args, PyObject *kwds) \n{\n\tstatic char *kwlist[] = {\"shape\", \"dtype\", \"buffer\", /* XXX ? */\n\t\t\t\t \"offset\", \"strides\",\n\t\t\t\t \"fortran\", NULL};\n\tPyArray_Descr *descr=NULL;\n\tint type_num;\n\tint itemsize;\n PyArray_Dims dims = {NULL, 0};\n PyArray_Dims strides = {NULL, 0};\n PyArray_Chunk buffer;\n\tlonglong offset=0;\n\tint fortran = 0;\n\tPyArrayObject *ret;\n\n\tbuffer.ptr = NULL; \n /* Usually called with shape and type\n but can also be called with buffer, strides, and swapped info\n */\n\n\t/* For now, let's just use this to create an empty, contiguous \n\t array of a specific type and shape. \n\t*/\t\n\n\tif (!PyArg_ParseTupleAndKeywords(args, kwds, \"O&|O&O&LO&i\",\n\t\t\t\t\t kwlist, PyArray_IntpConverter,\n &dims, \n PyArray_DescrConverter,\n\t\t\t\t\t &descr,\n PyArray_BufferConverter,\n &buffer,\n\t\t\t\t\t &offset,\n &PyArray_IntpConverter, \n &strides,\n &fortran)) \n\t\tgoto fail;\n\n\n\tif (descr == NULL)\n\t\tdescr = PyArray_DescrFromType(PyArray_LONG);\n\n\ttype_num = descr->type_num;\n\titemsize = descr->elsize;\n\n if (dims.ptr == NULL) {\n PyErr_SetString(PyExc_ValueError, \"need to give a \"\\\n \"valid shape as the first argument\");\n goto fail;\n }\n\n if (buffer.ptr == NULL) {\n ret = (PyArrayObject *)\\\n\t\t\tPyArray_NewFromDescr(subtype, descr,\n\t\t\t\t\t (int)dims.len, \n\t\t\t\t\t dims.ptr, \n\t\t\t\t\t NULL, NULL, fortran, NULL);\n if (ret == NULL) {descr=NULL;goto fail;}\n if (type_num == PyArray_OBJECT) { /* place Py_None */\n PyArray_FillObjectArray(ret, Py_None);\n }\n }\n else { /* buffer given -- use it */\n\t\tbuffer.len -= offset;\n\t\tbuffer.ptr += offset;\n if (dims.len == 1 && dims.ptr[0] == -1) {\n dims.ptr[0] = buffer.len / itemsize;\n }\n else if (buffer.len < itemsize* \\\n PyArray_MultiplyList(dims.ptr, dims.len)) {\n PyErr_SetString(PyExc_TypeError, \n \"buffer is too small for \" \\\n \"requested array\");\n goto fail;\n }\n if (strides.ptr != NULL) {\n\t\t\tif (strides.len != dims.len) {\n\t\t\t\tPyErr_SetString(PyExc_ValueError, \n\t\t\t\t\t\t\"strides, if given, must be \"\\\n\t\t\t\t\t\t\"the same length as shape\");\n\t\t\t\tgoto fail;\n\t\t\t}\n\t\t\tif (!PyArray_CheckStrides(itemsize, strides.len, \n\t\t\t\t\t\t buffer.len,\n\t\t\t\t\t\t dims.ptr, strides.ptr)) {\n\t\t\t\tPyErr_SetString(PyExc_ValueError, \n\t\t\t\t\t\t\"strides is incompatible \"\\\n\t\t\t\t\t\t\"with shape of requested\"\\\n\t\t\t\t\t\t\"array and size of buffer\");\n\t\t\t\tgoto fail;\n\t\t\t}\n }\n if (type_num == PyArray_OBJECT) {\n PyErr_SetString(PyExc_TypeError, \"cannot construct \"\\\n \"an object array from buffer data\");\n goto fail;\n }\n /* get writeable and aligned */\n if (fortran) buffer.flags |= FORTRAN;\n ret = (PyArrayObject *)\\\n\t\t\tPyArray_NewFromDescr(subtype, descr,\n\t\t\t\t\t dims.len, dims.ptr,\n\t\t\t\t\t strides.ptr,\n\t\t\t\t\t (char *)buffer.ptr, \n\t\t\t\t\t buffer.flags, NULL); \n if (ret == NULL) {descr=NULL; goto fail;}\n PyArray_UpdateFlags(ret, UPDATE_ALL_FLAGS);\n ret->base = buffer.base;\n Py_INCREF(buffer.base); \n }\n\n PyDimMem_FREE(dims.ptr);\n if (strides.ptr) PyDimMem_FREE(strides.ptr);\n return (PyObject *)ret;\n \n fail:\n\tPy_XDECREF(descr);\n if (dims.ptr) PyDimMem_FREE(dims.ptr);\n if (strides.ptr) PyDimMem_FREE(strides.ptr);\n return NULL;\n}\n\n\nstatic PyObject *\narray_iter(PyArrayObject *arr)\n{\n\tif (arr->nd == 0) {\n\t\tPyErr_SetString(PyExc_TypeError,\n\t\t\t\t\"iteration over a scalar (0-dim array)\");\n\t\treturn NULL;\n\t}\n\treturn PySeqIter_New((PyObject *)arr);\n}\n\n\n/******************* array attribute get and set routines ******************/\n\nstatic PyObject *\narray_ndim_get(PyArrayObject *self)\n{\n\treturn PyInt_FromLong(self->nd);\n}\n\nstatic PyObject *\narray_flags_get(PyArrayObject *self)\n{\n return PyObject_CallMethod(_numpy_internal, \"flagsobj\", \"Oii\", \n self, self->flags, 0);\n}\n\nstatic PyObject *\narray_shape_get(PyArrayObject *self)\n{\n\treturn PyArray_IntTupleFromIntp(self->nd, self->dimensions);\n}\n\n\nstatic int\narray_shape_set(PyArrayObject *self, PyObject *val)\n{\n \tint nd;\n\tPyObject *ret;\n\n\tret = PyArray_Reshape(self, val);\n\tif (ret == NULL) return -1;\n\n\t/* Free old dimensions and strides */\n\tPyDimMem_FREE(self->dimensions);\n\tnd = PyArray_NDIM(ret);\n\tself->nd = nd;\n\tif (nd > 0) { /* create new dimensions and strides */\n\t\tself->dimensions = PyDimMem_NEW(2*nd);\n\t\tif (self->dimensions == NULL) {\n\t\t\tPy_DECREF(ret);\n\t\t\tPyErr_SetString(PyExc_MemoryError,\"\");\n\t\t\treturn -1;\n\t\t}\n\t\tself->strides = self->dimensions + nd;\n\t\tmemcpy(self->dimensions, PyArray_DIMS(ret), \n\t\t nd*sizeof(intp));\n\t\tmemcpy(self->strides, PyArray_STRIDES(ret), \n\t\t nd*sizeof(intp));\n\t}\n\telse {self->dimensions=NULL; self->strides=NULL;}\n\tPy_DECREF(ret);\n\tPyArray_UpdateFlags(self, CONTIGUOUS | FORTRAN);\n\treturn 0;\n}\n\n\nstatic PyObject *\narray_strides_get(PyArrayObject *self)\n{\n\treturn PyArray_IntTupleFromIntp(self->nd, self->strides);\n}\n\nstatic int\narray_strides_set(PyArrayObject *self, PyObject *obj)\n{\n\tPyArray_Dims newstrides = {NULL, 0};\n\tPyArrayObject *new;\n\tintp numbytes;\n\n\tif (!PyArray_IntpConverter(obj, &newstrides) || \\\n\t newstrides.ptr == NULL) {\n\t\tPyErr_SetString(PyExc_TypeError, \"invalid strides\");\n\t\treturn -1;\n\t}\n\tif (newstrides.len != self->nd) {\n\t\tPyErr_Format(PyExc_ValueError, \"strides must be \"\t\\\n\t\t\t \" same length as shape (%d)\", self->nd);\n\t\tgoto fail;\n\t}\n\tnew = self;\n\twhile(new->base != NULL) {\n\t\tif (PyArray_Check(new->base)) \n\t\t\tnew = (PyArrayObject *)new->base;\n\t}\n\tnumbytes = PyArray_MultiplyList(new->dimensions, \n\t\t\t\t\tnew->nd)*new->descr->elsize;\n\t\n\tif (!PyArray_CheckStrides(self->descr->elsize, self->nd, numbytes, \n\t\t\t\t self->dimensions, newstrides.ptr)) {\n\t\tPyErr_SetString(PyExc_ValueError, \"strides is not \"\\\n\t\t\t\t\"compatible with available memory\");\n\t\tgoto fail;\n\t}\n\tmemcpy(self->strides, newstrides.ptr, sizeof(intp)*newstrides.len);\n\tPyArray_UpdateFlags(self, CONTIGUOUS | FORTRAN);\n\tPyDimMem_FREE(newstrides.ptr);\n\treturn 0;\n\n fail:\n\tPyDimMem_FREE(newstrides.ptr);\n\treturn -1;\n}\n\n\nstatic PyObject *\narray_protocol_strides_get(PyArrayObject *self)\n{\n\tif PyArray_ISCONTIGUOUS(self) {\n\t\tPy_INCREF(Py_None);\n\t\treturn Py_None;\n\t}\n\treturn PyArray_IntTupleFromIntp(self->nd, self->strides);\n}\n\nstatic PyObject *\narray_priority_get(PyArrayObject *self)\n{\n\tif (PyArray_CheckExact(self)) \n\t\treturn PyFloat_FromDouble(PyArray_PRIORITY);\n\telse if (PyBigArray_CheckExact(self)) \n\t\treturn PyFloat_FromDouble(PyArray_BIG_PRIORITY);\n\telse\n\t\treturn PyFloat_FromDouble(PyArray_SUBTYPE_PRIORITY);\n}\n\n\nstatic PyObject *\narray_dataptr_get(PyArrayObject *self)\n{\n\treturn Py_BuildValue(\"NO\",\n\t\t\t PyString_FromFormat(\"%p\", self->data),\n\t\t\t (self->flags & WRITEABLE ? Py_False :\n\t\t\t Py_True));\n}\n\nstatic PyObject *\narray_data_get(PyArrayObject *self)\n{\n\tintp nbytes;\n\tif (!(PyArray_ISONESEGMENT(self))) {\n\t\tPyErr_SetString(PyExc_AttributeError, \"cannot get single-\"\\\n\t\t\t\t\"segment buffer for discontiguous array\");\n\t\treturn NULL;\n\t}\t\t\n\tnbytes = PyArray_NBYTES(self);\n\tif PyArray_ISWRITEABLE(self) \n\t\treturn PyBuffer_FromReadWriteObject((PyObject *)self, 0, \n\t\t\t\t\t\t (int) nbytes);\n\telse\n\t\treturn PyBuffer_FromObject((PyObject *)self, 0, (int) nbytes);\n}\n\nstatic int\narray_data_set(PyArrayObject *self, PyObject *op)\n{\n\tvoid *buf;\n\tint buf_len;\n\tint writeable=1;\n\n\tif (PyObject_AsWriteBuffer(op, &buf, &buf_len) < 0) {\n\t\twriteable = 0;\n\t\tif (PyObject_AsReadBuffer(op, (const void **)&buf, \n\t\t\t\t\t &buf_len) < 0) {\n\t\t\tPyErr_SetString(PyExc_AttributeError, \n\t\t\t\t\t\"object does not have single-segment \" \\\n\t\t\t\t\t\"buffer interface\");\n\t\t\treturn -1;\n\t\t}\n\t}\n\tif (!PyArray_ISONESEGMENT(self)) {\n\t\tPyErr_SetString(PyExc_AttributeError, \"cannot set single-\" \\\n\t\t\t\t\"segment buffer for discontiguous array\");\n\t\treturn -1;\n\t}\n\tif (PyArray_NBYTES(self) > buf_len) {\n\t\tPyErr_SetString(PyExc_AttributeError, \n\t\t\t\t\"not enough data for array\");\n\t\treturn -1;\n\t}\n\tif (self->flags & OWN_DATA) {\n\t\tPyArray_XDECREF(self);\n\t\tPyDataMem_FREE(self->data);\n\t}\n\tif (self->base) {\n\t\tif (self->flags & UPDATEIFCOPY) {\n\t\t\t((PyArrayObject *)self->base)->flags |= WRITEABLE;\n\t\t\tself->flags &= ~UPDATEIFCOPY;\n\t\t}\n\t\tPy_DECREF(self->base);\n\t}\n\tPy_INCREF(op);\n\tself->base = op;\n\tself->data = buf;\n\tself->flags = CARRAY_FLAGS;\n\tif (!writeable)\n\t\tself->flags &= ~WRITEABLE;\n\treturn 0;\n}\n\n\nstatic PyObject *\narray_itemsize_get(PyArrayObject *self)\n{\n\treturn PyInt_FromLong((long) self->descr->elsize);\n}\n\nstatic PyObject *\narray_size_get(PyArrayObject *self)\n{\n\tintp size=PyArray_SIZE(self);\n#if SIZEOF_INTP <= SIZEOF_LONG\n return PyInt_FromLong((long) size);\n#else\n\tif (size > MAX_LONG || size < MIN_LONG)\n\t\treturn PyLong_FromLongLong(size);\n\telse \n\t\treturn PyInt_FromLong((long) size);\n#endif\n}\n\nstatic PyObject *\narray_nbytes_get(PyArrayObject *self)\n{\n intp nbytes = PyArray_NBYTES(self);\n#if SIZEOF_INTP <= SIZEOF_LONG\n return PyInt_FromLong((long) nbytes);\n#else\n\tif (nbytes > MAX_LONG || nbytes < MIN_LONG)\n\t\treturn PyLong_FromLongLong(nbytes);\n\telse \n\t\treturn PyInt_FromLong((long) nbytes);\n#endif\n}\n\n\nstatic PyObject *arraydescr_protocol_typestr_get(PyArray_Descr *);\n\nstatic PyObject *\narray_typestr_get(PyArrayObject *self)\n{\n\treturn arraydescr_protocol_typestr_get(self->descr);\n}\n\nstatic PyObject *\narray_descr_get(PyArrayObject *self) \n{\n\tPy_INCREF(self->descr);\n\treturn (PyObject *)self->descr;\n}\n\n\n/* If the type is changed. \n Also needing change: strides, itemsize\n\n Either itemsize is exactly the same\n or the array is single-segment (contiguous or fortran) with\n compatibile dimensions\n\n The shape and strides will be adjusted in that case as well.\n*/\n\nstatic int\narray_descr_set(PyArrayObject *self, PyObject *arg)\n{\n PyArray_Descr *newtype=NULL;\n intp newdim;\n int index;\n char *msg = \"new type not compatible with array.\";\n\n if (!(PyArray_DescrConverter(arg, &newtype)) ||\n newtype == NULL) {\n PyErr_SetString(PyExc_TypeError, \"invalid data-type for array\");\n\t\treturn -1;\n }\n\tif (newtype->type_num == PyArray_OBJECT || \\\n\t self->descr->type_num == PyArray_OBJECT) {\n\t\tPyErr_SetString(PyExc_TypeError, \\\n\t\t\t\t\"Cannot change descriptor for object\"\\\n\t\t\t\t\"array.\");\n\t\tPy_DECREF(newtype);\n\t\treturn -1;\n\t}\n\n\tif ((newtype->elsize != self->descr->elsize) &&\t\t\\\n\t (self->nd == 0 || !PyArray_ISONESEGMENT(self) || \\\n\t newtype->subarray)) goto fail;\n\t\n\tif (PyArray_ISCONTIGUOUS(self)) index = self->nd - 1;\n\telse index = 0;\n\t\n\tif (newtype->elsize < self->descr->elsize) {\n\t\t/* if it is compatible increase the size of the \n\t\t dimension at end (or at the front for FORTRAN)\n\t\t*/\n\t\tif (self->descr->elsize % newtype->elsize != 0) \n\t\t\tgoto fail;\n\t\tnewdim = self->descr->elsize / newtype->elsize;\n\t\tself->dimensions[index] *= newdim;\n\t\tself->strides[index] = newtype->elsize;\n\t}\n\t\n\telse if (newtype->elsize > self->descr->elsize) {\n\t\t\n\t\t/* Determine if last (or first if FORTRAN) dimension\n\t\t is compatible */\n\t\t\n\t\tnewdim = self->dimensions[index] * self->descr->elsize;\n\t\tif ((newdim % newtype->elsize) != 0) goto fail;\n\t\t\n\t\tself->dimensions[index] = newdim / newtype->elsize;\n\t\tself->strides[index] = newtype->elsize;\n\t}\n\n /* fall through -- adjust type*/\n\n\tPy_DECREF(self->descr);\n\tif (newtype->subarray) {\n\t\t/* create new array object from data and update \n\t\t dimensions, strides and descr from it */\n\t\tPyArrayObject *temp;\n\n\t\ttemp = (PyArrayObject *)\\\n\t\t\tPyArray_NewFromDescr(&PyArray_Type, newtype, self->nd,\n\t\t\t\t\t self->dimensions, self->strides,\n\t\t\t\t\t self->data, self->flags, NULL);\n\t\tPyDimMem_FREE(self->dimensions);\n\t\tself->dimensions = temp->dimensions;\n\t\tself->nd = temp->nd;\n\t\tself->strides = temp->strides;\n\t\tPy_DECREF(newtype);\n\t\tnewtype = temp->descr;\n\t\t/* Fool deallocator */\n\t\ttemp->nd = 0;\n\t\ttemp->dimensions = NULL;\n\t\ttemp->descr = NULL;\n\t\tPy_DECREF(temp);\n\t}\n\n\tself->descr = newtype; \n\tPyArray_UpdateFlags(self, UPDATE_ALL_FLAGS);\n\t\n return 0;\n\n fail:\n\tPyErr_SetString(PyExc_ValueError, msg);\n\tPy_DECREF(newtype);\n\treturn -1;\n}\n\nstatic PyObject *\narray_protocol_descr_get(PyArrayObject *self)\n{\n\tPyObject *res;\n\tPyObject *dobj;\n\t\n\tres = PyObject_GetAttrString((PyObject *)self->descr, \"descr\");\n\tif (res) return res;\n\tPyErr_Clear();\n\n\t/* get default */\n\tdobj = PyTuple_New(2);\n\tif (dobj == NULL) return NULL;\n\tPyTuple_SET_ITEM(dobj, 0, PyString_FromString(\"\"));\n\tPyTuple_SET_ITEM(dobj, 1, array_typestr_get(self));\n\tres = PyList_New(1);\n\tif (res == NULL) {Py_DECREF(dobj); return NULL;}\n\tPyList_SET_ITEM(res, 0, dobj);\n\treturn res;\n}\n\nstatic PyObject *\narray_struct_get(PyArrayObject *self)\n{\n PyArrayInterface *inter;\n \n inter = (PyArrayInterface *)_pya_malloc(sizeof(PyArrayInterface));\n inter->version = 2;\n inter->nd = self->nd;\n inter->typekind = self->descr->kind;\n inter->itemsize = self->descr->elsize;\n inter->flags = self->flags;\n /* reset unused flags */\n\tinter->flags &= ~(UPDATEIFCOPY | OWNDATA); \n\tif (PyArray_ISNOTSWAPPED(self)) inter->flags |= NOTSWAPPED;\n inter->strides = self->strides;\n inter->shape = self->dimensions;\n inter->data = self->data;\n\tPy_INCREF(self);\n return PyCObject_FromVoidPtrAndDesc(inter, self, gentype_struct_free);\n}\n\nstatic PyObject *\narray_base_get(PyArrayObject *self)\n{\n\tif (self->base == NULL) {\n\t\tPy_INCREF(Py_None);\n\t\treturn Py_None;\n\t}\n\telse {\n\t\tPy_INCREF(self->base);\n\t\treturn self->base;\n\t}\n}\n\n\nstatic PyObject *\narray_real_get(PyArrayObject *self)\n{\n\tPyArrayObject *ret;\n\n\tif (PyArray_ISCOMPLEX(self)) {\n\t\tret = (PyArrayObject *)PyArray_New(self->ob_type,\n\t\t\t\t\t\t self->nd,\n\t\t\t\t\t\t self->dimensions,\n\t\t\t\t\t\t self->descr->type_num - \\\n\t\t\t\t\t\t PyArray_NUM_FLOATTYPE,\n\t\t\t\t\t\t self->strides,\n\t\t\t\t\t\t self->data,\n\t\t\t\t\t\t 0,\n\t\t\t\t\t\t self->flags, (PyObject *)self);\n\t\tif (ret == NULL) return NULL;\n\t\tret->flags &= ~CONTIGUOUS;\n\t\tret->flags &= ~FORTRAN;\n\t\tPy_INCREF(self);\n\t\tret->base = (PyObject *)self;\n\t\treturn (PyObject *)ret;\n\t}\n\telse {\n\t\tPy_INCREF(self);\n\t\treturn (PyObject *)self;\n\t}\n}\n\n\nstatic int\narray_real_set(PyArrayObject *self, PyObject *val)\n{\n\tPyArrayObject *ret;\n\tPyArrayObject *new;\n\tint rint;\n\n\tnew = (PyArrayObject *)PyArray_FromAny(val, NULL, 0, 0, 0, NULL);\n\tif (new == NULL) return -1;\n\t\n\tif (PyArray_ISCOMPLEX(self)) {\n\t\tret = (PyArrayObject *)PyArray_New(self->ob_type,\n\t\t\t\t\t\t self->nd,\n\t\t\t\t\t\t self->dimensions,\n\t\t\t\t\t\t self->descr->type_num - \\\n\t\t\t\t\t\t PyArray_NUM_FLOATTYPE,\n\t\t\t\t\t\t self->strides,\n\t\t\t\t\t\t self->data,\n\t\t\t\t\t\t 0,\n\t\t\t\t\t\t self->flags, (PyObject *)self);\n\t\tif (ret == NULL) {Py_DECREF(new); return -1;}\n\t\tret->flags &= ~CONTIGUOUS;\n\t\tret->flags &= ~FORTRAN;\n\t\tPy_INCREF(self);\n\t\tret->base = (PyObject *)self;\n\t}\n\telse {\n\t\tPy_INCREF(self);\n\t\tret = self;\n\t}\t\n\trint = PyArray_CopyInto(ret, new);\n\tPy_DECREF(ret);\n\tPy_DECREF(new);\n\treturn rint;\n}\n\nstatic PyObject *\narray_imag_get(PyArrayObject *self)\n{\t\n\tPyArrayObject *ret;\n PyArray_Descr *type;\n\n\tif (PyArray_ISCOMPLEX(self)) {\n\t\ttype = PyArray_DescrFromType(self->descr->type_num - \n\t\t\t\t\t PyArray_NUM_FLOATTYPE);\n\t\tret = (PyArrayObject *)\t\t\t\t\\\n\t\t\tPyArray_NewFromDescr(self->ob_type,\n\t\t\t\t\t type,\n\t\t\t\t\t self->nd,\n\t\t\t\t\t self->dimensions,\n\t\t\t\t\t self->strides,\n\t\t\t\t\t self->data + type->elsize,\n\t\t\t\t\t self->flags, (PyObject *)self);\n\t\tif (ret == NULL) return NULL;\n\t\tret->flags &= ~CONTIGUOUS;\n\t\tret->flags &= ~FORTRAN;\n\t\tPy_INCREF(self);\n\t\tret->base = (PyObject *)self;\n\t\treturn (PyObject *) ret;\n\t}\n\telse {\n\t\ttype = self->descr;\n\t\tPy_INCREF(type);\n\t\tret = (PyArrayObject *)PyArray_Zeros(self->nd, \n\t\t\t\t\t\t self->dimensions,\n\t\t\t\t\t\t type, \n\t\t\t\t\t\t PyArray_ISFORTRAN(self));\n\t\tret->flags &= ~WRITEABLE;\n\t\treturn (PyObject *)ret;\n\t}\n}\n\nstatic int\narray_imag_set(PyArrayObject *self, PyObject *val)\n{\t\n\tif (PyArray_ISCOMPLEX(self)) {\n\t\tPyArrayObject *ret;\n\t\tPyArrayObject *new;\n\t\tint rint;\n\n\t\tnew = (PyArrayObject *)PyArray_FromAny(val, NULL, 0, 0, 0, NULL); \n\t\tif (new == NULL) return -1;\n\t\tret = (PyArrayObject *)PyArray_New(self->ob_type,\n\t\t\t\t\t\t self->nd,\n\t\t\t\t\t\t self->dimensions,\n\t\t\t\t\t\t self->descr->type_num - \\\n\t\t\t\t\t\t PyArray_NUM_FLOATTYPE,\n\t\t\t\t\t\t self->strides,\n \t\t\t\t\t\t self->data +\t\t\\\n\t\t\t\t\t\t (self->descr->elsize >> 1),\n\t\t\t\t\t\t 0,\n\t\t\t\t\t\t self->flags, (PyObject *)self);\n\t\tif (ret == NULL) {\n\t\t\tPy_DECREF(new); \n\t\t\treturn -1;\n\t\t}\n\t\tret->flags &= ~CONTIGUOUS;\n\t\tret->flags &= ~FORTRAN;\n\t\tPy_INCREF(self);\n\t\tret->base = (PyObject *)self;\n\t\trint = PyArray_CopyInto(ret, new);\n\t\tPy_DECREF(ret);\t\t\n\t\tPy_DECREF(new);\n\t\treturn rint;\n\t}\n\telse {\n\t\tPyErr_SetString(PyExc_TypeError, \"does not have imaginary \" \\\n\t\t\t\t\"part to set\");\n\t\treturn -1;\n\t}\n}\n\nstatic PyObject *\narray_flat_get(PyArrayObject *self)\n{\n return PyArray_IterNew((PyObject *)self);\n}\n\nstatic int \narray_flat_set(PyArrayObject *self, PyObject *val)\n{\n\tPyObject *arr=NULL;\n\tint retval = -1;\n\tPyArrayIterObject *selfit=NULL, *arrit=NULL;\n\tPyArray_Descr *typecode;\n int swap;\n PyArray_CopySwapFunc *copyswap;\n\n\ttypecode = self->descr;\n\tPy_INCREF(typecode);\n\tarr = PyArray_FromAny(val, typecode, \n\t\t\t 0, 0, FORCECAST | FORTRAN_IF(self), NULL);\n\tif (arr == NULL) return -1;\n\tarrit = (PyArrayIterObject *)PyArray_IterNew(arr);\n\tif (arrit == NULL) goto exit;\n\tselfit = (PyArrayIterObject *)PyArray_IterNew((PyObject *)self);\n\tif (selfit == NULL) goto exit;\n\n swap = PyArray_ISNOTSWAPPED(self) != PyArray_ISNOTSWAPPED(arr);\n copyswap = self->descr->f->copyswap;\n if (PyArray_ISOBJECT(self)) {\n while(selfit->index < selfit->size) {\n Py_XDECREF(*((PyObject **)selfit->dataptr));\n Py_INCREF(*((PyObject **)arrit->dataptr)); \n memmove(selfit->dataptr, arrit->dataptr, \n sizeof(PyObject *));\n PyArray_ITER_NEXT(selfit);\n PyArray_ITER_NEXT(arrit);\n if (arrit->index == arrit->size) \n PyArray_ITER_RESET(arrit);\n }\n retval = 0; \n goto exit;\n }\n\n\twhile(selfit->index < selfit->size) {\n\t\tmemmove(selfit->dataptr, arrit->dataptr, self->descr->elsize);\n copyswap(selfit->dataptr, NULL, swap, self->descr->elsize);\n\t\tPyArray_ITER_NEXT(selfit);\n\t\tPyArray_ITER_NEXT(arrit);\n\t\tif (arrit->index == arrit->size) \n\t\t\tPyArray_ITER_RESET(arrit);\n\t}\n\tretval = 0;\n exit:\n\tPy_XDECREF(selfit);\n\tPy_XDECREF(arrit);\n\tPy_XDECREF(arr);\n\treturn retval;\n}\n\nstatic PyGetSetDef array_getsetlist[] = {\n {\"ndim\", \n\t (getter)array_ndim_get, \n\t NULL, \n\t \"number of array dimensions\"},\n {\"flags\", \n\t (getter)array_flags_get, \n NULL,\n\t \"special dictionary of flags\"},\n {\"shape\", \n\t (getter)array_shape_get, \n\t (setter)array_shape_set, \n\t \"tuple of array dimensions\"},\n {\"strides\", \n\t (getter)array_strides_get, \n\t (setter)array_strides_set,\n\t \"tuple of bytes steps in each dimension\"},\n {\"data\", \n\t (getter)array_data_get, \n\t (setter)array_data_set, \n\t \"pointer to start of data\"},\n {\"itemsize\", \n\t (getter)array_itemsize_get, \n\t NULL,\n\t \"length of one element in bytes\"},\n {\"size\",\n (getter)array_size_get,\n\t NULL,\n \"number of elements in the array\"},\n {\"nbytes\",\n (getter)array_nbytes_get,\n NULL,\n \"number of bytes in the array\"},\n\t{\"base\",\n\t (getter)array_base_get,\n\t NULL,\n\t \"base object\"},\n\t{\"dtype\",\n\t (getter)array_descr_get,\n\t (setter)array_descr_set,\n\t \"get(set) data-type-descriptor for array\"},\n {\"real\", \n\t (getter)array_real_get, \n\t (setter)array_real_set, \n\t \"real part of array\"},\n {\"imag\", \n\t (getter)array_imag_get, \n\t (setter)array_imag_set, \n\t \"imaginary part of array\"},\n\t{\"flat\", \n\t (getter)array_flat_get, \n\t (setter)array_flat_set, \n\t \"a 1-d view of a contiguous array\"}, \n\t{\"__array_data__\", \n\t (getter)array_dataptr_get,\n\t NULL,\n\t \"Array protocol: data\"},\n\t{\"__array_typestr__\",\n\t (getter)array_typestr_get,\n\t NULL,\n\t \"Array protocol: typestr\"},\n\t{\"__array_descr__\",\n\t (getter)array_protocol_descr_get,\n\t NULL,\n\t \"Array protocol: descr\"},\n\t{\"__array_shape__\", \n\t (getter)array_shape_get,\n\t NULL,\n\t \"Array protocol: shape\"},\n\t{\"__array_strides__\",\n\t (getter)array_protocol_strides_get,\n\t NULL,\n\t \"Array protocol: strides\"},\n {\"__array_struct__\",\n (getter)array_struct_get,\n NULL,\n \"Array protocol: struct\"},\n\t{\"__array_priority__\",\n\t (getter)array_priority_get,\n\t NULL,\n\t \"Array priority\"},\n \t{NULL, NULL, NULL, NULL}, /* Sentinel */\n};\n\n/****************** end of attribute get and set routines *******************/\n\n\nstatic PyObject *\narray_alloc(PyTypeObject *type, int nitems)\n{\n PyObject *obj;\n /* nitems will always be 0 */ \n obj = (PyObject *)_pya_malloc(sizeof(PyArrayObject));\n PyObject_Init(obj, type);\n return obj;\n}\n\n\nstatic char Arraytype__doc__[] = \n \"A array object represents a multidimensional, homogeneous array\\n\"\n\t\" of fixed-size items. An associated data-type-descriptor object\\n\"\n\t\" details the data-type in an array (including byteorder and any\\n\"\n\t\" fields). An array can be constructed using the numpy.array\\n\"\n\t\" command. Arrays are sequence, mapping and numeric objects.\\n\"\n\t\" More information is available in the numpy module and by looking\\n\"\n\t\" at the methods and attributes of an array.\\n\\n\"\n\t\" ndarray.__new__(subtype, shape=, dtype=int_, buffer=None, \\n\"\n\t\" offset=0, strides=None, fortran=False)\\n\\n\"\n\t\" There are two modes of creating an array using __new__:\\n\"\n\t\" 1) If buffer is None, then only shape, dtype, and fortran \\n\"\n\t\" are used\\n\"\n\t\" 2) If buffer is an object exporting the buffer interface, then\\n\"\n\t\" all keywords are interpreted.\\n\"\n\t\" The dtype parameter can be any object that can be interpreted \\n\"\n\t\" as a numpy.dtype object.\\n\\n\"\n\t\" No __init__ method is needed because the array is fully \\n\"\n\t\" initialized after the __new__ method.\";\n\t\nstatic PyTypeObject PyBigArray_Type = { \n PyObject_HEAD_INIT(NULL)\n 0,\t\t\t\t\t /*ob_size*/\n \"numpy.bigndarray\",\t\t /*tp_name*/\n sizeof(PyArrayObject),\t\t /*tp_basicsize*/\n 0,\t\t\t\t\t /*tp_itemsize*/\n /* methods */\n (destructor)array_dealloc,\t\t /*tp_dealloc */\n (printfunc)NULL,\t\t\t /*tp_print*/\n 0,\t\t\t\t\t /*tp_getattr*/\n 0,\t\t\t\t\t /*tp_setattr*/\n (cmpfunc)0, \t\t /*tp_compare*/\n (reprfunc)array_repr,\t\t /*tp_repr*/\n &array_as_number,\t\t\t /*tp_as_number*/\n NULL, \t\t\t /*tp_as_sequence*/\n &array_as_mapping,\t\t\t /*tp_as_mapping*/\n (hashfunc)0,\t\t\t /*tp_hash*/\n (ternaryfunc)0,\t\t\t /*tp_call*/\n (reprfunc)array_str, \t /*tp_str*/\n\t\t\n (getattrofunc)0,\t\t\t /*tp_getattro*/\n (setattrofunc)0,\t\t\t /*tp_setattro*/\n NULL, \t /*tp_as_buffer*/\n (Py_TPFLAGS_DEFAULT \n | Py_TPFLAGS_BASETYPE\n | Py_TPFLAGS_CHECKTYPES), /*tp_flags*/\n /*Documentation string */\n Arraytype__doc__,\t\t\t /*tp_doc*/\n\n (traverseproc)0,\t\t\t /*tp_traverse */\n (inquiry)0,\t\t\t /*tp_clear */\n (richcmpfunc)array_richcompare,\t /*tp_richcompare */\n offsetof(PyArrayObject, weakreflist), /*tp_weaklistoffset */\n\n /* Iterator support (use standard) */\n\n (getiterfunc)array_iter, \t /* tp_iter */\n (iternextfunc)0,\t\t\t /* tp_iternext */\n\n /* Sub-classing (new-style object) support */\n\n array_methods,\t\t\t /* tp_methods */\n 0,\t\t\t\t\t /* tp_members */\n array_getsetlist,\t\t /* tp_getset */\n 0,\t\t\t\t\t /* tp_base */\n 0,\t\t\t\t\t /* tp_dict */\n 0,\t\t\t\t\t /* tp_descr_get */\n 0,\t\t\t\t\t /* tp_descr_set */\n 0,\t\t\t\t\t /* tp_dictoffset */\n (initproc)0,\t \t /* tp_init */\n array_alloc,\t /* tp_alloc */ \n (newfunc)array_new,\t\t /* tp_new */\n _pya_free, \t /* tp_free */\n 0,\t\t\t\t\t /* tp_is_gc */\n 0,\t\t\t\t\t /* tp_bases */\n 0,\t\t\t\t\t /* tp_mro */\n 0,\t\t\t\t\t /* tp_cache */\n 0,\t\t\t\t\t /* tp_subclasses */\n 0\t\t\t\t\t /* tp_weaklist */\n};\n\n/* A standard array will subclass from the Big Array and \n add the array_as_sequence table\n and the array_as_buffer table\n */\n\nstatic PyTypeObject PyArray_Type = { \n PyObject_HEAD_INIT(NULL)\n 0,\t\t\t\t\t /*ob_size*/\n \"numpy.ndarray\",\t\t\t /*tp_name*/\n sizeof(PyArrayObject),\t\t /*tp_basicsize*/\n 0,\t\t\t\t\t /*tp_itemsize*/\n};\n\n\n/* The rest of this code is to build the right kind of array from a python */\n/* object. */\n\nstatic int \ndiscover_depth(PyObject *s, int max, int stop_at_string, int stop_at_tuple) \n{\n int d=0;\n PyObject *e;\n\t\n if(max < 1) return -1;\n\n if(! PySequence_Check(s) || PyInstance_Check(s) || \\\n\t PySequence_Length(s) < 0) {\n PyErr_Clear(); return 0;\n }\n if (PyArray_Check(s))\n\t\treturn PyArray_NDIM(s);\n if(PyString_Check(s) || PyBuffer_Check(s) || PyUnicode_Check(s))\n\t\treturn stop_at_string ? 0:1;\n\tif (stop_at_tuple && PyTuple_Check(s)) return 0;\n\tif ((e=PyObject_GetAttrString(s, \"__array_shape__\")) != NULL) {\n\t\tif (PyTuple_Check(e)) d=PyTuple_GET_SIZE(e);\n\t\telse d=-1;\n\t\tPy_DECREF(e);\n\t\tif (d>-1) return d;\n\t}\n\telse PyErr_Clear();\n\n if (PySequence_Length(s) == 0) \n\t\treturn 1;\t\n if ((e=PySequence_GetItem(s,0)) == NULL) return -1;\n if(e!=s) {\n\t\td=discover_depth(e, max-1, stop_at_string, stop_at_tuple);\n\t\tif(d >= 0) d++;\n\t}\n Py_DECREF(e);\n return d;\n}\n\nstatic int\ndiscover_itemsize(PyObject *s, int nd, int *itemsize) \n{\n\tint n, r, i;\n\tPyObject *e;\n\t\n\tn = PyObject_Length(s);\n\n\tif ((nd == 0) || PyString_Check(s) ||\t\t\\\n\t PyUnicode_Check(s) || PyBuffer_Check(s)) {\n\t\tif PyUnicode_Check(s) \n\t\t\t*itemsize = MAX(*itemsize, sizeof(Py_UNICODE)*n);\n\t\telse\n\t\t\t*itemsize = MAX(*itemsize, n);\n\t\treturn 0;\n\t}\n\tfor (i=0; i n_lower) n_lower = d[1];\n }\n d[1] = n_lower;\n\t\n return 0;\n}\n\n/* new reference */\n/* doesn't alter refcount of chktype or mintype --- \n unless one of them is returned */\nstatic PyArray_Descr *\n_array_small_type(PyArray_Descr *chktype, PyArray_Descr* mintype)\n{\n\tPyArray_Descr *outtype;\n\n\tif (chktype->type_num > mintype->type_num) outtype = chktype;\n\telse outtype = mintype;\n\n\tPy_INCREF(outtype);\n\tif (PyTypeNum_ISEXTENDED(outtype->type_num) &&\t\t\\\n\t (PyTypeNum_ISEXTENDED(mintype->type_num) ||\t\t\\\n\t mintype->type_num==0)) {\n\t\tint testsize = outtype->elsize;\n\t\tregister int chksize, minsize;\n\t\tchksize = chktype->elsize;\n\t\tminsize = mintype->elsize;\n\t\t/* Handle string->unicode case separately \n\t\t because string itemsize is twice as large */\n\t\tif (outtype->type_num == PyArray_UNICODE && \n\t\t mintype->type_num == PyArray_STRING) {\n\t\t\ttestsize = MAX(chksize, 2*minsize);\n\t\t}\n\t\telse {\n\t\t\ttestsize = MAX(chksize, minsize);\n\t\t}\n\t\tif (testsize != outtype->elsize) {\n\t\t\tPyArray_DESCR_REPLACE(outtype);\n\t\t\touttype->elsize = testsize;\n\t\t\tPy_XDECREF(outtype->fields);\n\t\t\touttype->fields = NULL;\n\t\t}\n\t}\n\treturn outtype;\n}\n\n/* op is an object to be converted to an ndarray. \n\n minitype is the minimum type-descriptor needed. \n \n max is the maximum number of dimensions -- used for recursive call\n to avoid infinite recursion...\n \n*/\n\nstatic PyArray_Descr *\n_array_find_type(PyObject *op, PyArray_Descr *minitype, int max)\n{\n int l;\n PyObject *ip;\n\tPyArray_Descr *chktype=NULL;\n\tPyArray_Descr *outtype;\n\t\n\tif (minitype == NULL) \n\t\tminitype = PyArray_DescrFromType(PyArray_BOOL);\n\telse Py_INCREF(minitype);\n\t\n if (max < 0) goto deflt;\n\t\n if (PyArray_Check(op)) {\n\t\tchktype = PyArray_DESCR(op);\n\t\tPy_INCREF(chktype);\n\t\tgoto finish;\n\t}\n\t\n\tif (PyArray_IsScalar(op, Generic)) {\n\t\tchktype = PyArray_DescrFromScalar(op);\n\t\tgoto finish;\n\t}\n\n\tif ((ip=PyObject_GetAttrString(op, \"__array_typestr__\"))!=NULL) {\n\t\tif (PyString_Check(ip)) {\n\t\t\tchktype =_array_typedescr_fromstr(PyString_AS_STRING(ip));\n\t\t}\n\t\tPy_DECREF(ip);\n if (chktype) goto finish;\n\t}\n\telse PyErr_Clear();\n \n if ((ip=PyObject_GetAttrString(op, \"__array_struct__\")) != NULL) {\n PyArrayInterface *inter;\n char buf[40];\n if (PyCObject_Check(ip)) {\n inter=(PyArrayInterface *)PyCObject_AsVoidPtr(ip);\n if (inter->version == 2) {\n snprintf(buf, 40, \"|%c%d\", inter->typekind, \n\t\t\t\t\t inter->itemsize);\n\t\t\t\tchktype = _array_typedescr_fromstr(buf);\n }\n }\n Py_DECREF(ip);\n if (chktype) goto finish;\n }\n\telse PyErr_Clear();\n \t\n if (PyString_Check(op)) {\n\t\tchktype = PyArray_DescrNewFromType(PyArray_STRING);\n\t\tchktype->elsize = PyString_GET_SIZE(op);\n\t\tgoto finish;\n }\n\n\tif (PyUnicode_Check(op)) {\n\t\tchktype = PyArray_DescrNewFromType(PyArray_UNICODE);\n\t\tchktype->elsize = PyUnicode_GET_DATA_SIZE(op);\n\t\tgoto finish;\n\t}\n\n\tif (PyBuffer_Check(op)) {\n\t\tchktype = PyArray_DescrNewFromType(PyArray_VOID);\n\t\tchktype->elsize = op->ob_type->tp_as_sequence->sq_length(op);\n PyErr_Clear();\n\t\tgoto finish;\n\t}\n\n if (PyObject_HasAttrString(op, \"__array__\")) {\n ip = PyObject_CallMethod(op, \"__array__\", NULL);\n if(ip && PyArray_Check(ip)) {\n\t\t\tchktype = PyArray_DESCR(ip);\n\t\t\tPy_INCREF(chktype);\n Py_DECREF(ip);\n\t\t\tgoto finish;\n\t\t}\n Py_XDECREF(ip);\n\t\tif (PyErr_Occurred()) PyErr_Clear();\n } \n\n\tif (PyInstance_Check(op)) goto deflt;\n\t\n if (PySequence_Check(op)) {\n\n l = PyObject_Length(op);\n if (l < 0 && PyErr_Occurred()) { \n\t\t\tPyErr_Clear(); \n\t\t\tgoto deflt;\n\t\t}\n if (l == 0 && minitype->type_num == PyArray_BOOL) {\n\t\t\tPy_DECREF(minitype);\n\t\t\tminitype = PyArray_DescrFromType(PyArray_INTP);\n\t\t}\n while (--l >= 0) {\n\t\t\tPyArray_Descr *newtype;\n ip = PySequence_GetItem(op, l);\n if (ip==NULL) {\n\t\t\t\tPyErr_Clear(); \n\t\t\t\tgoto deflt;\n\t\t\t}\n\t\t\tchktype = _array_find_type(ip, minitype, max-1);\n\t\t\tnewtype = _array_small_type(chktype, minitype);\n\t\t\tPy_DECREF(minitype);\n\t\t\tminitype = newtype;\n\t\t\tPy_DECREF(chktype);\n Py_DECREF(ip);\n }\n\t\tchktype = minitype;\n\t\tPy_INCREF(minitype);\n\t\tgoto finish;\n }\n\t\n\tif (PyBool_Check(op)) {\n\t\tchktype = PyArray_DescrFromType(PyArray_BOOL);\n\t\tgoto finish;\t\t\n\t}\n else if (PyInt_Check(op)) {\n\t\tchktype = PyArray_DescrFromType(PyArray_LONG);\n\t\tgoto finish;\n } else if (PyFloat_Check(op)) {\n\t\tchktype = PyArray_DescrFromType(PyArray_DOUBLE);\n\t\tgoto finish;\n\t} else if (PyComplex_Check(op)) {\n\t\tchktype = PyArray_DescrFromType(PyArray_CDOUBLE);\n\t\tgoto finish;\n\t}\n\n deflt:\n\tchktype = PyArray_DescrFromType(PyArray_OBJECT);\n\t\n finish:\n\t\n\touttype = _array_small_type(chktype, minitype);\n\tPy_DECREF(chktype);\n\tPy_DECREF(minitype);\n\treturn outtype; \n}\n\nstatic int \nAssign_Array(PyArrayObject *self, PyObject *v) \n{\n PyObject *e;\n int l, r;\n\t\n if (!PySequence_Check(v)) {\n PyErr_SetString(PyExc_ValueError,\n\t\t\t\t\"assignment from non-sequence\");\n return -1;\n }\n\t\n l=PyObject_Length(v);\n if(l < 0) return -1; \n\t\n while(--l >= 0)\n {\n e=PySequence_GetItem(v,l);\n if (e == NULL) return -1; \n\t\t\tr = PySequence_SetItem((PyObject*)self,l,e);\n Py_DECREF(e);\n if(r == -1) return -1;\n }\n return 0;\n}\n\n/* \"Array Scalars don't call this code\" */ \n/* steals reference to typecode -- no NULL*/\nstatic PyObject *\nArray_FromScalar(PyObject *op, PyArray_Descr *typecode) \n{\n PyArrayObject *ret;\n\tint itemsize; \n\tint type;\n\t\n\titemsize = typecode->elsize;\n\ttype = typecode->type_num;\n\n\tif (itemsize == 0 && PyTypeNum_ISEXTENDED(type)) {\n\t\titemsize = PyObject_Length(op);\n\t\tif (type == PyArray_UNICODE) itemsize *= sizeof(Py_UNICODE);\n\t}\n\n\tret = (PyArrayObject *)PyArray_NewFromDescr(&PyArray_Type, typecode,\n\t\t\t\t\t\t 0, NULL, \n\t\t\t\t\t\t NULL, NULL, 0, NULL);\n\n\tif (ret == NULL) return NULL;\n\n ret->descr->f->setitem(op, ret->data, ret);\n\t\n if (PyErr_Occurred()) {\n Py_DECREF(ret);\n return NULL;\n } else {\n return (PyObject *)ret;\n }\n}\n\n\n/* steals reference to typecode unless return value is NULL*/\nstatic PyObject *\nArray_FromSequence(PyObject *s, PyArray_Descr *typecode, int fortran, \n\t\t int min_depth, int max_depth)\n{\n PyArrayObject *r;\n int nd;\n\tintp d[MAX_DIMS];\n\tint stop_at_string;\n\tint stop_at_tuple;\n\tint type = typecode->type_num;\n\tint itemsize = typecode->elsize;\n\tPyArray_Descr *savetype=typecode;\n\t\n\tstop_at_string = ((type == PyArray_OBJECT) ||\t\\\n\t\t\t (type == PyArray_STRING) ||\t\\\n\t\t\t (type == PyArray_UNICODE) || \\\n\t\t\t (type == PyArray_VOID));\n\n\tstop_at_tuple = (type == PyArray_VOID && ((typecode->fields &&\t\\\n\t\t\t\t\t\t typecode->fields!=Py_None) \\\n\t\t\t\t\t\t || (typecode->subarray)));\n\t\n if (!((nd=discover_depth(s, MAX_DIMS+1, stop_at_string, \n\t\t\t\t stop_at_tuple)) > 0)) {\n\t\tif (nd==0)\n\t\t\treturn Array_FromScalar(s, typecode);\n PyErr_SetString(PyExc_ValueError, \n\t\t\t\t\"invalid input sequence\");\n return NULL;\n }\n\t\n if ((max_depth && nd > max_depth) ||\t\\\n\t (min_depth && nd < min_depth)) {\n PyErr_SetString(PyExc_ValueError, \n\t\t\t\t\"invalid number of dimensions\");\n return NULL;\n }\n\t\n\tif(discover_dimensions(s,nd,d, !stop_at_string) == -1) {\n\t\treturn NULL;\n\t}\n\tif (itemsize == 0 && PyTypeNum_ISEXTENDED(type)) {\n\t\tif (discover_itemsize(s, nd, &itemsize) == -1) {\n\t\t\treturn NULL;\n\t\t}\n\t\tif (type == PyArray_UNICODE) itemsize*=sizeof(Py_UNICODE);\n\t}\n\n\tif (itemsize != typecode->elsize) {\n\t\tPyArray_DESCR_REPLACE(typecode);\n\t\ttypecode->elsize = itemsize;\n\t}\n\t\n r=(PyArrayObject*)PyArray_NewFromDescr(&PyArray_Type, typecode,\n\t\t\t\t\t nd, d, \n\t\t\t\t\t NULL, NULL,\n\t\t\t\t\t fortran, NULL);\n\t\n if(!r) {Py_XINCREF(savetype); return NULL;}\n if(Assign_Array(r,s) == -1) {\n\t\tPy_XINCREF(savetype);\n\t\tPy_DECREF(r);\n\t\treturn NULL;\n\t}\n return (PyObject*)r;\n}\n\n\n/*OBJECT_API\n Is the typenum valid?\n*/\nstatic int \nPyArray_ValidType(int type) \n{\n\tPyArray_Descr *descr;\n\tint res=TRUE;\n\t\n\tdescr = PyArray_DescrFromType(type);\n\tif (descr==NULL) res = FALSE;\n\tPy_DECREF(descr);\n\treturn res;\n}\n\n\n/* If the output is not a CARRAY, then it is buffered also */\n\nstatic int\n_bufferedcast(PyArrayObject *out, PyArrayObject *in)\n{\n\tchar *inbuffer, *bptr, *optr;\n\tchar *outbuffer=NULL;\n\tPyArrayIterObject *it_in=NULL, *it_out=NULL;\n\tregister intp i, index;\n\tintp ncopies = PyArray_SIZE(out) / PyArray_SIZE(in);\n\tint elsize=in->descr->elsize;\n\tint nels = PyArray_BUFSIZE;\n\tint el;\n\tint inswap, outswap=0;\n\tint obuf=!PyArray_ISCARRAY(out);\n\tint oelsize = out->descr->elsize;\n\tPyArray_VectorUnaryFunc *castfunc;\n PyArray_CopySwapFunc *in_csn;\n PyArray_CopySwapFunc *out_csn;\n\tint retval = -1;\n\n\tcastfunc = in->descr->f->cast[out->descr->type_num];\n in_csn = in->descr->f->copyswap;\n out_csn = out->descr->f->copyswap;\n\n\t/* If the input or output is STRING, UNICODE, or VOID */\n\t/* then getitem and setitem are used for the cast */\n\t/* and byteswapping is handled by those methods */\n\n\tinswap = !(PyArray_ISFLEXIBLE(in) || PyArray_ISNOTSWAPPED(in));\n\t\n\tinbuffer = PyDataMem_NEW(PyArray_BUFSIZE*elsize);\n\tif (inbuffer == NULL) return -1;\n\tif (PyArray_ISOBJECT(in)) \n\t\tmemset(inbuffer, 0, PyArray_BUFSIZE*elsize);\n\tit_in = (PyArrayIterObject *)PyArray_IterNew((PyObject *)in);\n\tif (it_in == NULL) goto exit;\n\n\tif (obuf) {\n\t\toutswap = !(PyArray_ISFLEXIBLE(out) || \\\n\t\t\t PyArray_ISNOTSWAPPED(out));\n\t\toutbuffer = PyDataMem_NEW(PyArray_BUFSIZE*oelsize);\n\t\tif (outbuffer == NULL) goto exit;\n\t\tif (PyArray_ISOBJECT(out))\n\t\t\tmemset(outbuffer, 0, PyArray_BUFSIZE*oelsize);\n\t\t\n\t\tit_out = (PyArrayIterObject *)PyArray_IterNew((PyObject *)out);\n\t\tif (it_out == NULL) goto exit;\n\n\t\tnels = MIN(nels, PyArray_BUFSIZE);\n\t}\n\t\n\toptr = (obuf) ? outbuffer: out->data;\n\tbptr = inbuffer;\n\tel = 0;\t\n\twhile(ncopies--) {\n\t\tindex = it_in->size;\n\t\tPyArray_ITER_RESET(it_in);\n\t\twhile(index--) {\n in_csn(bptr, it_in->dataptr, inswap, elsize);\n\t\t\tbptr += elsize;\n\t\t\tPyArray_ITER_NEXT(it_in);\n\t\t\tel += 1;\n\t\t\tif ((el == nels) || (index == 0)) {\n\t\t\t\t/* buffer filled, do cast */\n\t\t\t\t\n\t\t\t\tcastfunc(inbuffer, optr, el, in, out);\n\t\t\t\t\n\t\t\t\tif (obuf) {\n\t\t\t\t\t/* Copy from outbuffer to array */\n\t\t\t\t\tfor(i=0; idataptr,\n optr, outswap,\n oelsize);\n\t\t\t\t\t\toptr += oelsize;\n\t\t\t\t\t\tPyArray_ITER_NEXT(it_out);\n\t\t\t\t\t}\n\t\t\t\t\toptr = outbuffer;\n\t\t\t\t}\n\t\t\t\telse {\n\t\t\t\t\toptr += out->descr->elsize * nels;\n\t\t\t\t}\n\t\t\t\tel = 0;\n\t\t\t\tbptr = inbuffer;\n\t\t\t}\n\t\t}\n\t}\n\tretval = 0;\n exit:\n\tPy_XDECREF(it_in);\n\tPyDataMem_FREE(inbuffer);\n\tPyDataMem_FREE(outbuffer);\t\n\tif (obuf) {\n\t\tPy_XDECREF(it_out);\n\t}\n\treturn retval;\n}\n\n\n/* For backward compatibility */\n\n/* steals reference to at --- cannot be NULL*/\n/*OBJECT_API\n Cast an array using typecode structure.\n*/\nstatic PyObject * \nPyArray_CastToType(PyArrayObject *mp, PyArray_Descr *at, int fortran)\n{\n\tPyObject *out;\n\tint ret;\n\tPyArray_Descr *mpd;\n\n\tmpd = mp->descr;\n\n\tif (((mpd == at) || ((mpd->type_num == at->type_num) &&\t\t\\\n\t\t\t PyArray_EquivByteorders(mpd->byteorder,\\\n\t\t\t\t\t\t at->byteorder) &&\t\\\n\t\t\t ((mpd->elsize == at->elsize) ||\t\t\\\n\t\t\t (at->elsize==0)))) &&\t\t\t\\\n\t PyArray_ISBEHAVED_RO(mp)) {\n\t\tPy_DECREF(at);\n\t\tPy_INCREF(mp);\n\t\treturn (PyObject *)mp;\n\t}\n\t\t\n\tif (at->elsize == 0) {\n\t\tPyArray_DESCR_REPLACE(at);\n\t\tif (at == NULL) return NULL;\n\t\tif (mpd->type_num == PyArray_STRING &&\t\\\n\t\t at->type_num == PyArray_UNICODE)\n\t\t\tat->elsize = mpd->elsize*sizeof(Py_UNICODE);\n\t\tif (mpd->type_num == PyArray_UNICODE &&\n\t\t at->type_num == PyArray_STRING) \n\t\t\tat->elsize = mpd->elsize/sizeof(Py_UNICODE);\n\t\tif (at->type_num == PyArray_VOID)\n\t\t\tat->elsize = mpd->elsize;\n\t}\n\n\tout = PyArray_NewFromDescr(mp->ob_type, at,\n\t\t\t\t mp->nd, \n\t\t\t\t mp->dimensions, \n\t\t\t\t NULL, NULL, \n\t\t\t\t fortran,\n\t\t\t\t (PyObject *)mp);\n\n\tif (out == NULL) return NULL;\n\tret = PyArray_CastTo((PyArrayObject *)out, mp);\n\tif (ret != -1) return out;\n\t\n\tPy_DECREF(out);\n\treturn NULL;\n\t\n}\n\t \n/* The number of elements in out must be an integer multiple\n of the number of elements in mp. \n*/\n\n/*OBJECT_API\n Cast to an already created array.\n*/\nstatic int\nPyArray_CastTo(PyArrayObject *out, PyArrayObject *mp)\n{\n\n\tint simple;\n\tintp mpsize = PyArray_SIZE(mp);\n\tintp outsize = PyArray_SIZE(out);\n\n\tif (mpsize == 0) return 0;\n\tif (!PyArray_ISWRITEABLE(out)) {\n\t\tPyErr_SetString(PyExc_ValueError, \n\t\t\t\t\"output array is not writeable\");\n\t\treturn -1;\n\t}\n\tif (outsize % mpsize != 0) {\n\t\tPyErr_SetString(PyExc_ValueError, \n\t\t\t\t\"output array must have an integer-multiple\"\\\n\t\t\t\t\" of the number of elements in the input \"\\\n\t\t\t\t\"array\");\n\t\treturn -1; \n\t}\n\n\tif (out->descr->type_num >= PyArray_NTYPES) {\n\t\tPyErr_SetString(PyExc_ValueError, \n\t\t\t\t\"Can only cast to builtin types.\");\n\t\treturn -1;\n\t\t\t\t\n\t}\n\n\tsimple = ((PyArray_ISCARRAY_RO(mp) && PyArray_ISCARRAY(out)) || \\\n (PyArray_ISFARRAY_RO(mp) && PyArray_ISFARRAY(out)));\n\t\n\tif (simple) {\n\t\tchar *inptr;\n\t\tchar *optr = out->data;\n\t\tintp obytes = out->descr->elsize * outsize;\n\t\tintp ncopies = outsize / mpsize;\n\n\t\twhile(ncopies--) {\n\t\t\tinptr = mp->data;\n\t\t\tmp->descr->f->cast[out->descr->type_num](inptr, \n\t\t\t\t\t\t\t optr,\n\t\t\t\t\t\t\t mpsize,\n\t\t\t\t\t\t\t mp, out);\n\t\t\toptr += obytes;\n\t\t}\n\t\treturn 0;\n\t}\n\t\n\t/* If not a well-behaved cast, then use buffers */\n\tif (_bufferedcast(out, mp) == -1) {\n\t\treturn -1;\n\t}\n\treturn 0;\n}\n\n/* steals reference to newtype --- acc. NULL */\n/*OBJECT_API*/\nstatic PyObject *\nPyArray_FromArray(PyArrayObject *arr, PyArray_Descr *newtype, int flags) \n{\n\t\n\tPyArrayObject *ret=NULL;\n\tint type, itemsize;\n\tint copy = 0;\n\tint arrflags;\n\tPyArray_Descr *oldtype;\n\tchar *msg = \"cannot copy back to a read-only array\";\n PyTypeObject *subtype;\n\n\toldtype = PyArray_DESCR(arr);\n\n subtype = arr->ob_type;\n\t\n\tif (newtype == NULL) {newtype = oldtype; Py_INCREF(oldtype);}\n\ttype = newtype->type_num;\n\titemsize = newtype->elsize;\n\n\t/* Don't copy if sizes are compatible */\n\tif (PyArray_EquivTypes(oldtype, newtype)) {\n\t\tarrflags = arr->flags;\n\n\t\tcopy = (flags & ENSURECOPY) || \\\n\t\t\t((flags & CONTIGUOUS) && (!(arrflags & CONTIGUOUS))) \\\n\t\t\t|| ((flags & ALIGNED) && (!(arrflags & ALIGNED))) \\\n\t\t\t|| (arr->nd > 1 &&\t\t\t\t\\\n\t\t\t ((flags & FORTRAN) && (!(arrflags & FORTRAN)))) \\\n\t\t\t|| ((flags & WRITEABLE) && (!(arrflags & WRITEABLE)));\n\t\t\n\t\tif (copy) {\n if ((flags & UPDATEIFCOPY) && \\\n (!PyArray_ISWRITEABLE(arr))) {\n\t\t\t\tPy_DECREF(newtype);\n PyErr_SetString(PyExc_ValueError, msg);\n return NULL;\n }\n if ((flags & ENSUREARRAY) && \\\n (subtype != &PyBigArray_Type)) {\n subtype = &PyArray_Type;\n }\n\t\t\tret = (PyArrayObject *) \\\n\t\t\t\tPyArray_NewFromDescr(subtype, newtype,\n\t\t\t\t\t\t arr->nd, \n\t\t\t\t\t\t arr->dimensions,\n\t\t\t\t\t\t NULL, NULL, \n\t\t\t\t\t\t flags & FORTRAN,\n\t\t\t\t\t\t (PyObject *)arr);\n if (ret == NULL) return NULL;\n\t\t\tif (PyArray_CopyInto(ret, arr) == -1) \n\t\t\t\t{Py_DECREF(ret); return NULL;}\n\t\t\tif (flags & UPDATEIFCOPY) {\n\t\t\t\tret->flags |= UPDATEIFCOPY;\n\t\t\t\tret->base = (PyObject *)arr;\n PyArray_FLAGS(ret->base) &= ~WRITEABLE;\n\t\t\t\tPy_INCREF(arr);\n\t\t\t}\n\t\t} \n\t\t/* If no copy then just increase the reference\n\t\t count and return the input */\n\t\telse { \n if ((flags & ENSUREARRAY) && \\\n (subtype != &PyBigArray_Type)) {\n\t\t\t\tPy_DECREF(newtype);\n\t\t\t\tPy_INCREF(arr->descr);\n\t\t\t\tret = (PyArrayObject *)\t\t\t\\\n PyArray_NewFromDescr(&PyArray_Type,\n\t\t\t\t\t\t\t arr->descr,\n\t\t\t\t\t\t\t arr->nd,\n\t\t\t\t\t\t\t arr->dimensions,\n\t\t\t\t\t\t\t arr->strides,\n\t\t\t\t\t\t\t arr->data,\n\t\t\t\t\t\t\t arr->flags,NULL);\n if (ret == NULL) return NULL;\n ret->base = (PyObject *)arr;\n }\n else {\n ret = arr;\n }\n\t\t\tPy_INCREF(arr);\n\t\t}\n\t}\n\t\n\t/* The desired output type is different than the input\n\t array type */\n\telse {\n\t\t/* Cast to the desired type if we can do it safely\n\t\t Also cast if source is a ndim-0 array to mimic\n\t\t behavior with Python scalars */\n\t\tif (flags & FORCECAST || PyArray_NDIM(arr)==0 ||\n\t\t PyArray_CanCastTo(oldtype, newtype)) {\n if ((flags & UPDATEIFCOPY) &&\t\t\\\n (!PyArray_ISWRITEABLE(arr))) {\n\t\t\t\tPy_DECREF(newtype);\n PyErr_SetString(PyExc_ValueError, msg);\n return NULL;\n }\n if ((flags & ENSUREARRAY) && \\\n (subtype != &PyBigArray_Type)) {\n subtype = &PyArray_Type;\n }\n ret = (PyArrayObject *)\\\n PyArray_NewFromDescr(subtype, \n\t\t\t\t\t\t newtype, \n\t\t\t\t\t\t arr->nd,\n\t\t\t\t\t\t arr->dimensions, \n\t\t\t\t\t\t NULL, NULL, \n\t\t\t\t\t\t flags & FORTRAN,\n\t\t\t\t\t\t (PyObject *)arr);\n if (ret == NULL) return NULL;\n if (PyArray_CastTo(ret, arr) < 0) {\n Py_DECREF(ret);\n return NULL;\n }\n\t\t\tif (flags & UPDATEIFCOPY) {\n\t\t\t\tret->flags |= UPDATEIFCOPY;\n\t\t\t\tret->base = (PyObject *)arr;\n PyArray_FLAGS(ret->base) &= ~WRITEABLE;\n\t\t\t\tPy_INCREF(arr);\n\t\t\t}\n\t\t}\n\t\telse {\n\t\t\tPyErr_SetString(PyExc_TypeError, \n\t\t\t\t\t\"array cannot be safely cast \" \\\n\t\t\t\t\t\"to required type\");\n\t\t\tret = NULL;\n\t\t}\n\t}\n\treturn (PyObject *)ret;\n}\n\n/* new reference */\nstatic PyArray_Descr *\n_array_typedescr_fromstr(char *str)\n{\n\tPyArray_Descr *descr; \n\tint type_num;\n\tchar typechar;\n\tint size;\n\tchar msg[] = \"unsupported typestring\";\n\tint swap;\n\tchar swapchar;\n\n\tswapchar = str[0];\n\tstr += 1;\n\t\n#define _MY_FAIL {\t\t\t\t \\\n\t\tPyErr_SetString(PyExc_ValueError, msg); \\\n\t\treturn NULL;\t\t\t\t\\\n\t}\t\t\n\t\n\ttypechar = str[0];\n\tsize = atoi(str + 1);\n\tswitch (typechar) {\n\tcase 'b':\n\t\tif (size == sizeof(Bool))\n\t\t\ttype_num = PyArray_BOOL;\t \n\t\telse _MY_FAIL \n\t\t\tbreak;\t\t \n\tcase 'u':\n\t\tif (size == sizeof(uintp))\n\t\t\ttype_num = PyArray_UINTP;\n\t\telse if (size == sizeof(char))\n\t\t\ttype_num = PyArray_UBYTE;\n\t\telse if (size == sizeof(short)) \n\t\t\ttype_num = PyArray_USHORT;\n\t\telse if (size == sizeof(ulong)) \n\t\t\ttype_num = PyArray_ULONG;\n\t\telse if (size == sizeof(int)) \n\t\t\ttype_num = PyArray_UINT;\n\t\telse if (size == sizeof(ulonglong))\n\t\t\ttype_num = PyArray_ULONGLONG;\n\t\telse _MY_FAIL\n\t\t\tbreak;\t\t \n\tcase 'i':\n\t\tif (size == sizeof(intp))\n\t\t\ttype_num = PyArray_INTP;\n\t\telse if (size == sizeof(char)) \n\t\t type_num = PyArray_BYTE;\n\t\telse if (size == sizeof(short)) \n\t\t\ttype_num = PyArray_SHORT;\n\t\telse if (size == sizeof(long)) \n\t\t\ttype_num = PyArray_LONG;\n\t\telse if (size == sizeof(int))\n\t\t\ttype_num = PyArray_INT;\n\t\telse if (size == sizeof(longlong))\n\t\t\ttype_num = PyArray_LONGLONG;\n\t\telse _MY_FAIL\n\t\t\tbreak;\t\t \n\tcase 'f':\n\t\tif (size == sizeof(float))\n\t\t\ttype_num = PyArray_FLOAT;\n\t\telse if (size == sizeof(double))\n\t\t\ttype_num = PyArray_DOUBLE;\n\t\telse if (size == sizeof(longdouble))\n\t\t\ttype_num = PyArray_LONGDOUBLE;\n\t\telse _MY_FAIL\n\t\t\tbreak;\n\tcase 'c':\n\t\tif (size == sizeof(float)*2)\n\t\t\ttype_num = PyArray_CFLOAT;\n\t\telse if (size == sizeof(double)*2)\n\t\t\ttype_num = PyArray_CDOUBLE;\n\t\telse if (size == sizeof(longdouble)*2)\n\t\t\ttype_num = PyArray_CLONGDOUBLE;\n\t\telse _MY_FAIL\n\t\t\tbreak;\n\tcase 'O':\n\t\tif (size == sizeof(PyObject *))\n\t\t\ttype_num = PyArray_OBJECT;\n\t\telse _MY_FAIL\n\t\t\tbreak;\n\tcase 'S':\n\t\ttype_num = PyArray_STRING;\n\t\tbreak;\n\tcase 'U':\n\t\ttype_num = PyArray_UNICODE;\n\t\tsize *= sizeof(Py_UNICODE);\n\t\tbreak;\t \n\tcase 'V':\n\t\ttype_num = PyArray_VOID;\n\t\tbreak;\n\tdefault:\n\t\t_MY_FAIL\n\t}\n\t\n#undef _MY_FAIL\n\n descr = PyArray_DescrFromType(type_num);\n if (descr == NULL) return NULL;\n swap = !PyArray_ISNBO(swapchar);\n if (descr->elsize == 0 || swap) {\n\t /* Need to make a new PyArray_Descr */\n\t PyArray_DESCR_REPLACE(descr);\n\t if (descr==NULL) return NULL;\n\t if (descr->elsize == 0)\n\t\t descr->elsize = size;\n\t if (swap) \n\t\t descr->byteorder = swapchar;\n }\n return descr;\n}\n\n/* OBJECT_API */\nstatic PyObject *\nPyArray_FromStructInterface(PyObject *input)\n{\n\tPyArray_Descr *thetype;\n\tchar buf[40];\n\tPyArrayInterface *inter;\n\tPyObject *attr, *r;\n\tchar endian = PyArray_NATBYTE;\n \n attr = PyObject_GetAttrString(input, \"__array_struct__\");\n if (attr == NULL) {\n\t\tPyErr_Clear();\n\t\treturn Py_NotImplemented;\n\t}\n if (!PyCObject_Check(attr) || \\\n ((inter=((PyArrayInterface *)\\\n\t\t PyCObject_AsVoidPtr(attr)))->version != 2)) {\n PyErr_SetString(PyExc_ValueError, \"invalid __array_struct__\");\n\t\tPy_DECREF(attr);\n return NULL;\n }\n\tif ((inter->flags & NOTSWAPPED) != NOTSWAPPED) {\n\t\tendian = PyArray_OPPBYTE;\n\t\tinter->flags &= ~NOTSWAPPED;\n\t}\n\n snprintf(buf, 40, \"%c%c%d\", endian, inter->typekind, inter->itemsize);\n if (!(thetype=_array_typedescr_fromstr(buf))) {\n\t\tPy_DECREF(attr);\n return NULL;\n }\n\n r = PyArray_NewFromDescr(&PyArray_Type, thetype,\n\t\t\t\t inter->nd, inter->shape,\n\t\t\t\t inter->strides, inter->data,\n\t\t\t\t inter->flags, NULL);\n\tPy_INCREF(input);\n\tPyArray_BASE(r) = input;\n Py_DECREF(attr);\n PyArray_UpdateFlags((PyArrayObject *)r, UPDATE_ALL_FLAGS);\n return r;\n}\n\n/*OBJECT_API*/\nstatic PyObject *\nPyArray_FromInterface(PyObject *input)\n{\n\tPyObject *attr=NULL, *item=NULL;\n PyObject *tstr=NULL, *shape=NULL; \n PyArrayObject *ret;\n\tPyArray_Descr *type=NULL;\n\tchar *data;\n\tint buffer_len;\n\tint res, i, n;\n\tintp dims[MAX_DIMS], strides[MAX_DIMS];\n\tint dataflags = BEHAVED_FLAGS;\n\n\t/* Get the memory from __array_data__ and __array_offset__ */\n\t/* Get the shape */\n\t/* Get the typestring -- ignore array_descr */\n\t/* Get the strides */\n\t\n shape = PyObject_GetAttrString(input, \"__array_shape__\");\n if (shape == NULL) {PyErr_Clear(); return Py_NotImplemented;}\n tstr = PyObject_GetAttrString(input, \"__array_typestr__\");\n if (tstr == NULL) {Py_DECREF(shape); PyErr_Clear(); return Py_NotImplemented;}\n \n\tattr = PyObject_GetAttrString(input, \"__array_data__\");\n\tif ((attr == NULL) || (attr==Py_None) || (!PyTuple_Check(attr))) {\n\t\tif (attr && (attr != Py_None)) item=attr;\n\t\telse item=input;\n\t\tres = PyObject_AsWriteBuffer(item, (void **)&data, \n\t\t\t\t\t &buffer_len);\n\t\tif (res < 0) {\n\t\t\tPyErr_Clear();\n\t\t\tres = PyObject_AsReadBuffer(item, (const void **)&data,\n\t\t\t\t\t\t &buffer_len);\n\t\t\tif (res < 0) goto fail;\n\t\t\tdataflags &= ~WRITEABLE;\n\t\t}\n\t\tPy_XDECREF(attr);\n\t\tattr = PyObject_GetAttrString(input, \"__array_offset__\");\n\t\tif (attr) {\n\t\t\tlong num = PyInt_AsLong(attr);\n\t\t\tif (error_converting(num)) {\n\t\t\t\tPyErr_SetString(PyExc_TypeError, \n\t\t\t\t\t\t\"__array_offset__ \"\\\n\t\t\t\t\t\t\"must be an integer\");\n\t\t\t\tgoto fail;\n\t\t\t}\n\t\t\tdata += num;\n\t\t}\n\t\telse PyErr_Clear();\n\t}\n\telse {\n\t\tif (PyTuple_GET_SIZE(attr) != 2) {\n\t\t\tPyErr_SetString(PyExc_TypeError, \n\t\t\t\t\t\"__array_data__ must return \"\t\\\n\t\t\t\t\t\"a 2-tuple with ('data pointer \"\\\n\t\t\t\t\t\"string', read-only flag)\");\n\t\t\tgoto fail;\n\t\t}\n\t\tres = sscanf(PyString_AsString(PyTuple_GET_ITEM(attr,0)),\n\t\t\t \"%p\", (void **)&data);\n\t\tif (res < 1) {\n\t\t\tPyErr_SetString(PyExc_TypeError, \n\t\t\t\t\t\"__array_data__ string cannot be \" \\\n\t\t\t\t\t\"converted\");\n\t\t\tgoto fail;\n\t\t}\n\t\tif (PyObject_IsTrue(PyTuple_GET_ITEM(attr,1))) {\n\t\t\tdataflags &= ~WRITEABLE;\n\t\t}\n\t}\n\tPy_XDECREF(attr);\n\tattr = tstr;\n\tif (!PyString_Check(attr)) {\n\t\tPyErr_SetString(PyExc_TypeError, \"__array_typestr__ must be a string\");\n\t\tPy_INCREF(attr); /* decref'd twice below */\n\t\tgoto fail;\n\t}\n\ttype = _array_typedescr_fromstr(PyString_AS_STRING(attr)); \n\tPy_DECREF(attr); attr=NULL; tstr=NULL;\n\tif (type==NULL) goto fail;\n\tattr = shape;\n\tif (!PyTuple_Check(attr)) {\n\t\tPyErr_SetString(PyExc_TypeError, \"__array_shape__ must be a tuple\");\n\t\tPy_INCREF(attr); /* decref'd twice below */\n\t\tPy_DECREF(type);\n\t\tgoto fail;\n\t}\n\tn = PyTuple_GET_SIZE(attr);\n\tfor (i=0; ibase = input;\n \n\tattr = PyObject_GetAttrString(input, \"__array_strides__\");\n\tif (attr != NULL && attr != Py_None) {\n\t\tif (!PyTuple_Check(attr)) {\n\t\t\tPyErr_SetString(PyExc_TypeError, \n\t\t\t\t\t\"__array_strides__ must be a tuple\");\n\t\t\tPy_DECREF(attr);\n\t\t\tPy_DECREF(ret);\n\t\t\treturn NULL;\n\t\t}\n\t\tif (n != PyTuple_GET_SIZE(attr)) {\n\t\t\tPyErr_SetString(PyExc_ValueError, \n\t\t\t\t\t\"mismatch in length of \"\\\n\t\t\t\t\t\"__array_strides__ and \"\\\n\t\t\t\t\t\"__array_shape__\");\n\t\t\tPy_DECREF(attr);\n\t\t\tPy_DECREF(ret);\n\t\t\treturn NULL;\n\t\t}\n\t\tfor (i=0; istrides, strides, n*sizeof(intp));\n\t}\n\telse PyErr_Clear();\n\tPyArray_UpdateFlags(ret, UPDATE_ALL_FLAGS);\n\treturn (PyObject *)ret;\n\n fail:\n\tPy_XDECREF(attr);\n\tPy_XDECREF(shape);\n\tPy_XDECREF(tstr);\n\treturn NULL;\n}\n\n/* OBJECT_API*/\nstatic PyObject *\nPyArray_FromArrayAttr(PyObject *op, PyArray_Descr *typecode, PyObject *context) \n{\n PyObject *new;\n PyObject *array_meth;\n\n array_meth = PyObject_GetAttrString(op, \"__array__\");\n if (array_meth == NULL) {PyErr_Clear(); return Py_NotImplemented;}\n if (context == NULL) {\n if (typecode == NULL) new = PyObject_CallFunction(array_meth, NULL);\n else new = PyObject_CallFunction(array_meth, \"O\", typecode);\n }\n else {\n if (typecode == NULL) {\n new = PyObject_CallFunction(array_meth, \"OO\", Py_None, context);\n if (new == NULL && PyErr_ExceptionMatches(PyExc_TypeError)) {\n PyErr_Clear();\n new = PyObject_CallFunction(array_meth, \"\");\n }\n }\n else {\n new = PyObject_CallFunction(array_meth, \"OO\", typecode, context);\n if (new == NULL && PyErr_ExceptionMatches(PyExc_TypeError)) {\n PyErr_Clear();\n new = PyObject_CallFunction(array_meth, \"O\", typecode);\n }\n }\n }\n Py_DECREF(array_meth);\n if (new == NULL) return NULL;\n if (!PyArray_Check(new)) {\n PyErr_SetString(PyExc_ValueError, \n \"object __array__ method not \" \\\n \"producing an array\");\n Py_DECREF(new);\n return NULL;\n }\n return new;\n} \n\n/* Does not check for ENSURECOPY and NOTSWAPPED in flags */\n/* Steals a reference to newtype --- which can be NULL */\n/*OBJECT_API*/\nstatic PyObject *\nPyArray_FromAny(PyObject *op, PyArray_Descr *newtype, int min_depth, \n int max_depth, int flags, PyObject *context) \n{\n /* This is the main code to make a NumPy array from a Python\n Object. It is called from lot's of different places which\n is why there are so many checks. The comments try to\n explain some of the checks. */\n\n PyObject *r=NULL;\n int seq = FALSE;\n \n\t/* Is input object already an array? */\n\t/* This is where the flags are used */\n if (PyArray_Check(op)) \n\t\tr = PyArray_FromArray((PyArrayObject *)op, newtype, flags);\n\telse if (PyArray_IsScalar(op, Generic)) {\n\t\tr = PyArray_FromScalar(op, newtype);\n\t}\n else if (((r = PyArray_FromStructInterface(op))!=Py_NotImplemented)|| \\\n ((r = PyArray_FromInterface(op)) != Py_NotImplemented) || \\\n ((r = PyArray_FromArrayAttr(op, newtype, context)) \\\n != Py_NotImplemented)) {\n PyObject *new;\n if (r == NULL) return NULL;\n if (newtype != NULL || flags != 0) {\n new = PyArray_FromArray((PyArrayObject *)r, newtype, flags);\n Py_DECREF(r);\n r = new;\n }\n }\n\telse {\n\t\tif (newtype == NULL) {\n\t\t\tnewtype = _array_find_type(op, NULL, MAX_DIMS);\n\t\t}\n\t\tif (PySequence_Check(op)) {\n\t\t\t/* necessary but not sufficient */\n\t\t\t\n\t\t\tr = Array_FromSequence(op, newtype, flags & FORTRAN,\n\t\t\t\t\t min_depth, max_depth);\n\t\t\tif (PyErr_Occurred() && r == NULL)\n /* It wasn't really a sequence after all.\n * Try interpreting it as a scalar */\n PyErr_Clear();\n else\n seq = TRUE;\n }\n if (!seq)\n\t\t\tr = Array_FromScalar(op, newtype);\n\t}\n\n /* If we didn't succeed return NULL */\n if (r == NULL) return NULL;\n\t\n\t/* Be sure we succeed here */\n\t\n if(!PyArray_Check(r)) {\n PyErr_SetString(PyExc_RuntimeError, \n\t\t\t\t\"internal error: PyArray_FromAny \"\\\n\t\t\t\t\"not producing an array\");\n\t\tPy_DECREF(r);\n return NULL;\n }\n\n if (min_depth != 0 && ((PyArrayObject *)r)->nd < min_depth) {\n PyErr_SetString(PyExc_ValueError, \n \"object of too small depth for desired array\");\n Py_DECREF(r);\n return NULL;\n }\n if (max_depth != 0 && ((PyArrayObject *)r)->nd > max_depth) {\n PyErr_SetString(PyExc_ValueError, \n \"object too deep for desired array\");\n Py_DECREF(r);\n return NULL;\n }\n return r;\n}\n\n/* new reference -- accepts NULL for mintype*/\n/*OBJECT_API*/\nstatic PyArray_Descr *\nPyArray_DescrFromObject(PyObject *op, PyArray_Descr *mintype)\n{\n\treturn _array_find_type(op, mintype, MAX_DIMS);\n}\n\n/*OBJECT_API\n Return the typecode of the array a Python object would be converted\n to\n*/\nstatic int \nPyArray_ObjectType(PyObject *op, int minimum_type) \n{\n\tPyArray_Descr *intype;\n\tPyArray_Descr *outtype;\n\tint ret;\n\n\tintype = PyArray_DescrFromType(minimum_type);\n\tif (intype == NULL) PyErr_Clear();\n\touttype = _array_find_type(op, intype, MAX_DIMS);\n\tret = outtype->type_num;\n\tPy_DECREF(outtype);\n\tPy_DECREF(intype);\n\treturn ret;\n}\n\n\n/* flags is any of \n CONTIGUOUS, \n FORTRAN,\n ALIGNED, \n WRITEABLE, \n NOTSWAPPED,\n ENSURECOPY, \n UPDATEIFCOPY,\n FORCECAST,\n ENSUREARRAY\n\n or'd (|) together\n\n Any of these flags present means that the returned array should \n guarantee that aspect of the array. Otherwise the returned array\n won't guarantee it -- it will depend on the object as to whether or \n not it has such features. \n\n Note that ENSURECOPY is enough\n to guarantee CONTIGUOUS, ALIGNED and WRITEABLE\n and therefore it is redundant to include those as well. \n\n BEHAVED_FLAGS == ALIGNED | WRITEABLE\n CARRAY_FLAGS = CONTIGUOUS | BEHAVED_FLAGS\n FARRAY_FLAGS = FORTRAN | BEHAVED_FLAGS\n \n FORTRAN can be set in the FLAGS to request a FORTRAN array. \n Fortran arrays are always behaved (aligned, \n notswapped, and writeable) and not (C) CONTIGUOUS (if > 1d). \n\n UPDATEIFCOPY flag sets this flag in the returned array if a copy is\n made and the base argument points to the (possibly) misbehaved array.\n When the new array is deallocated, the original array held in base\n is updated with the contents of the new array. \n\n FORCECAST will cause a cast to occur regardless of whether or not\n it is safe. \n*/\n\n\n/* steals a reference to descr -- accepts NULL */\n/*OBJECT_API*/\nstatic PyObject *\nPyArray_CheckFromAny(PyObject *op, PyArray_Descr *descr, int min_depth, \n int max_depth, int requires, PyObject *context) \n{\n\tif (requires & NOTSWAPPED) {\n\t\tif (!descr && PyArray_Check(op) && \\\n\t\t !PyArray_ISNBO(PyArray_DESCR(op)->byteorder)) {\n\t\t\tdescr = PyArray_DescrNew(PyArray_DESCR(op));\n\t\t}\n\t\telse if ((descr && !PyArray_ISNBO(descr->byteorder))) {\n\t\t\tPyArray_DESCR_REPLACE(descr);\n\t\t}\n\t\tdescr->byteorder = PyArray_NATIVE;\n\t}\n\n\treturn PyArray_FromAny(op, descr, min_depth, max_depth,\n requires, context);\n}\n\n/* This is a quick wrapper around PyArray_FromAny(op, NULL, 0, 0, \n ENSUREARRAY) */\n/* that special cases Arrays and PyArray_Scalars up front */\n/* It *steals a reference* to the object */\n/* It also guarantees that the result is PyArray_Type or PyBigArray_Type */\n\n/* Because it decrefs op if any conversion needs to take place \n so it can be used like PyArray_EnsureArray(some_function(...)) */\n\n/*OBJECT_API*/\nstatic PyObject *\nPyArray_EnsureArray(PyObject *op)\n{\n PyObject *new;\n\n if (op == NULL) return NULL;\n\n if (PyArray_CheckExact(op) || PyBigArray_CheckExact(op)) return op;\n \n if (PyArray_IsScalar(op, Generic)) {\n new = PyArray_FromScalar(op, NULL);\n Py_DECREF(op);\n return new;\n }\n new = PyArray_FromAny(op, NULL, 0, 0, ENSUREARRAY, NULL);\n Py_DECREF(op);\n return new;\n}\n\n/*OBJECT_API\n Check the type coercion rules.\n*/\nstatic int \nPyArray_CanCastSafely(int fromtype, int totype) \n{\n\tPyArray_Descr *from, *to;\n\tregister int felsize, telsize;\n\n if (fromtype == totype) return 1;\n if (fromtype == PyArray_BOOL) return 1;\n\tif (totype == PyArray_BOOL) return 0;\n if (totype == PyArray_OBJECT || totype == PyArray_VOID) return 1;\n\tif (fromtype == PyArray_OBJECT || fromtype == PyArray_VOID) return 0;\n\n\tfrom = PyArray_DescrFromType(fromtype);\n\tto = PyArray_DescrFromType(totype);\n\ttelsize = to->elsize;\n\tfelsize = from->elsize;\n\tPy_DECREF(from);\n\tPy_DECREF(to);\n\n switch(fromtype) {\n case PyArray_BYTE:\n\tcase PyArray_SHORT:\n case PyArray_INT:\n case PyArray_LONG:\n\tcase PyArray_LONGLONG:\n\t\tif (PyTypeNum_ISINTEGER(totype)) {\n\t\t\tif (PyTypeNum_ISUNSIGNED(totype)) {\n\t\t\t\treturn (telsize > felsize);\n\t\t\t}\n\t\t\telse {\n\t\t\t\treturn (telsize >= felsize);\n\t\t\t}\n\t\t}\n\t\telse if (PyTypeNum_ISFLOAT(totype)) {\n if (felsize < 8)\n return (telsize > felsize);\n else\n return (telsize >= felsize);\n\t\t}\n\t\telse if (PyTypeNum_ISCOMPLEX(totype)) {\n if (felsize < 8)\n return ((telsize >> 1) > felsize);\n else\n return ((telsize >> 1) >= felsize);\n\t\t}\n\t\telse return totype > fromtype;\n case PyArray_UBYTE:\n case PyArray_USHORT:\n case PyArray_UINT:\n\tcase PyArray_ULONG:\n\tcase PyArray_ULONGLONG:\n\t\tif (PyTypeNum_ISINTEGER(totype)) {\n\t\t\tif (PyTypeNum_ISSIGNED(totype)) {\n\t\t\t\treturn (telsize > felsize);\n\t\t\t}\n\t\t\telse {\n\t\t\t\treturn (telsize >= felsize);\n\t\t\t}\n\t\t}\n\t\telse if (PyTypeNum_ISFLOAT(totype)) {\n if (felsize < 8)\n return (telsize > felsize);\n else\n return (telsize >= felsize);\n\t\t}\n\t\telse if (PyTypeNum_ISCOMPLEX(totype)) {\n if (felsize < 8)\n return ((telsize >> 1) > felsize);\n else\n return ((telsize >> 1) >= felsize);\n\t\t}\n\t\telse return totype > fromtype;\n case PyArray_FLOAT:\n case PyArray_DOUBLE:\n\tcase PyArray_LONGDOUBLE:\n\t\tif (PyTypeNum_ISCOMPLEX(totype)) \n\t\t\treturn ((telsize >> 1) >= felsize);\n\t\telse\n\t\t\treturn (totype > fromtype);\n case PyArray_CFLOAT:\n case PyArray_CDOUBLE:\n\tcase PyArray_CLONGDOUBLE:\n\t\treturn (totype > fromtype);\n\tcase PyArray_STRING:\n\tcase PyArray_UNICODE:\n\t\treturn (totype > fromtype);\n default:\n return 0;\n }\n}\n\n/* leaves reference count alone --- cannot be NULL*/\n/*OBJECT_API*/\nstatic Bool\nPyArray_CanCastTo(PyArray_Descr *from, PyArray_Descr *to)\n{\n\tint fromtype=from->type_num;\n\tint totype=to->type_num;\n\tBool ret;\n\n\tret = (Bool) PyArray_CanCastSafely(fromtype, totype);\n\tif (ret) { /* Check String and Unicode more closely */\n\t\tif (fromtype == PyArray_STRING) {\n\t\t\tif (totype == PyArray_STRING) {\n\t\t\t\tret = (from->elsize <= to->elsize);\n\t\t\t}\n\t\t\telse if (totype == PyArray_UNICODE) {\n\t\t\t\tret = (from->elsize * sizeof(Py_UNICODE)\\\n\t\t\t\t <= to->elsize);\n\t\t\t}\n\t\t}\n\t\telse if (fromtype == PyArray_UNICODE) {\n\t\t\tif (totype == PyArray_UNICODE) {\n\t\t\t\tret = (from->elsize <= to->elsize);\n\t\t\t}\n\t\t}\n\t\t/* TODO: If totype is STRING or unicode \n\t\t see if the length is long enough to hold the\n\t\t stringified value of the object.\t\t \n\t\t*/\n\t}\n\treturn ret;\n}\n\n\n\n/*********************** Element-wise Array Iterator ***********************/\n/* Aided by Peter J. Verveer's nd_image package and numpy's arraymap ****/\n/* and Python's array iterator ***/\n \n\n/*OBJECT_API\n Get Iterator.\n*/\nstatic PyObject *\nPyArray_IterNew(PyObject *obj)\n{\n PyArrayIterObject *it;\n\tint i, nd; \n\tPyArrayObject *ao = (PyArrayObject *)obj;\n\n if (!PyArray_Check(ao)) {\n PyErr_BadInternalCall();\n return NULL;\n }\n\n it = (PyArrayIterObject *)_pya_malloc(sizeof(PyArrayIterObject));\n PyObject_Init((PyObject *)it, &PyArrayIter_Type);\n /* it = PyObject_New(PyArrayIterObject, &PyArrayIter_Type);*/\n if (it == NULL)\n return NULL;\n\n\tnd = ao->nd;\n\tPyArray_UpdateFlags(ao, CONTIGUOUS);\n\tit->contiguous = 0;\n\tif PyArray_ISCONTIGUOUS(ao) it->contiguous = 1;\n Py_INCREF(ao);\n it->ao = ao;\n\tit->size = PyArray_SIZE(ao);\n\tit->nd_m1 = nd - 1;\n\tit->factors[nd-1] = 1;\n\tfor (i=0; i < nd; i++) {\n\t\tit->dims_m1[i] = it->ao->dimensions[i] - 1;\n\t\tit->strides[i] = it->ao->strides[i];\n\t\tit->backstrides[i] = it->strides[i] *\t\\\n\t\t\tit->dims_m1[i];\n\t\tif (i > 0)\n\t\t\tit->factors[nd-i-1] = it->factors[nd-i] *\t\\\n\t\t\t\tit->ao->dimensions[nd-i];\n\t}\n\tPyArray_ITER_RESET(it);\n\t\n return (PyObject *)it;\n}\n\n\n/*OBJECT_API\n Get Iterator that iterates over all but one axis (don't use this with\n PyArray_ITER_GOTO1D) \n*/\nstatic PyObject *\nPyArray_IterAllButAxis(PyObject *obj, int axis)\n{\n\tPyArrayIterObject *it;\n\tit = (PyArrayIterObject *)PyArray_IterNew(obj);\n\tif (it == NULL) return NULL;\n\t\n\t/* adjust so that will not iterate over axis */\n\tit->contiguous = 0;\n\tif (it->size != 0) {\n\t\tit->size /= PyArray_DIM(obj,axis);\n\t}\n\tit->dims_m1[axis] = 0;\n\tit->backstrides[axis] = 0;\n\t\n\t/* (won't fix factors so don't use\n\t PyArray_ITER_GOTO1D with this iterator) */\n\treturn (PyObject *)it;\n}\n\n/* Returns an array scalar holding the element desired */\n\nstatic PyObject *\narrayiter_next(PyArrayIterObject *it)\n{\n\tPyObject *ret;\n\n\tif (it->index < it->size) {\n\t\tret = PyArray_ToScalar(it->dataptr, it->ao);\n\t\tPyArray_ITER_NEXT(it);\n\t\treturn ret;\n\t}\n return NULL;\n}\n\nstatic void\narrayiter_dealloc(PyArrayIterObject *it)\n{\n Py_XDECREF(it->ao);\n _pya_free(it);\n}\n\nstatic int\niter_length(PyArrayIterObject *self) \n{\n return (int) self->size;\n}\n\n\nstatic PyObject *\niter_subscript_Bool(PyArrayIterObject *self, PyArrayObject *ind)\n{\n\tint index, strides, itemsize;\n\tintp count=0;\n\tchar *dptr, *optr;\n\tPyObject *r;\n\tint swap;\n PyArray_CopySwapFunc *copyswap;\n\n\n\tif (ind->nd != 1) {\n\t\tPyErr_SetString(PyExc_ValueError, \n\t\t\t\t\"boolean index array should have 1 dimension\");\n\t\treturn NULL;\n\t}\n\tindex = (ind->dimensions[0]);\n\tstrides = ind->strides[0];\n\tdptr = ind->data;\n\t/* Get size of return array */\n\twhile(index--) {\n\t\tif (*((Bool *)dptr) != 0)\n\t\t\tcount++;\n\t\tdptr += strides;\n\t}\n\titemsize = self->ao->descr->elsize;\n\tPy_INCREF(self->ao->descr);\n\tr = PyArray_NewFromDescr(self->ao->ob_type,\n\t\t\t\t self->ao->descr, 1, &count, \n\t\t\t\t NULL, NULL,\n\t\t\t\t 0, (PyObject *)self->ao);\n\tif (r==NULL) return NULL;\n\n\t/* Set up loop */\n\toptr = PyArray_DATA(r);\n\tindex = ind->dimensions[0];\n\tdptr = ind->data;\n\n copyswap = self->ao->descr->f->copyswap;\n\t/* Loop over Boolean array */\n\tswap = !(PyArray_ISNOTSWAPPED(self->ao));\n\twhile(index--) {\n\t\tif (*((Bool *)dptr) != 0) {\n copyswap(optr, self->dataptr, swap, itemsize);\n\t\t\toptr += itemsize;\n\t\t}\n\t\tdptr += strides;\n\t\tPyArray_ITER_NEXT(self);\n\t}\n\tPyArray_ITER_RESET(self);\n\treturn r;\n}\n\nstatic PyObject *\niter_subscript_int(PyArrayIterObject *self, PyArrayObject *ind)\n{\n\tintp num;\n\tPyObject *r;\n\tPyArrayIterObject *ind_it;\n\tint itemsize;\n\tint swap;\n\tchar *optr;\n\tint index;\n PyArray_CopySwapFunc *copyswap;\n\n\titemsize = self->ao->descr->elsize;\n\tif (ind->nd == 0) {\n\t\tnum = *((intp *)ind->data);\n\t\tPyArray_ITER_GOTO1D(self, num);\n\t\tr = PyArray_ToScalar(self->dataptr, self->ao);\n\t\tPyArray_ITER_RESET(self);\n\t\treturn r;\n\t}\n\t\n\tPy_INCREF(self->ao->descr);\n\tr = PyArray_NewFromDescr(self->ao->ob_type, self->ao->descr, \n\t\t\t\t ind->nd, ind->dimensions,\n\t\t\t\t NULL, NULL, \n\t\t\t\t 0, (PyObject *)self->ao);\n\tif (r==NULL) return NULL;\n\n\toptr = PyArray_DATA(r);\n\tind_it = (PyArrayIterObject *)PyArray_IterNew((PyObject *)ind);\n\tif (ind_it == NULL) {Py_DECREF(r); return NULL;}\n\tindex = ind_it->size;\n copyswap = PyArray_DESCR(r)->f->copyswap;\n swap = !PyArray_ISNOTSWAPPED(self->ao);\n\twhile(index--) {\n\t\tnum = *((intp *)(ind_it->dataptr));\n\t\tif (num < 0) num += self->size;\n\t\tif (num < 0 || num >= self->size) {\n\t\t\tPyErr_Format(PyExc_IndexError,\n\t\t\t\t \"index %d out of bounds\"\t\t\\\n\t\t\t\t \" 0<=index<%d\", (int) num, \n\t\t\t\t (int) self->size);\n\t\t\tPy_DECREF(ind_it);\n\t\t\tPy_DECREF(r);\n\t\t\tPyArray_ITER_RESET(self);\n\t\t\treturn NULL;\n\t\t}\n\t\tPyArray_ITER_GOTO1D(self, num);\n copyswap(optr, self->dataptr, swap, itemsize);\n\t\toptr += itemsize;\n\t\tPyArray_ITER_NEXT(ind_it);\n\t}\n\tPy_DECREF(ind_it);\n\tPyArray_ITER_RESET(self);\n\treturn r;\n}\n\n\nstatic PyObject *\niter_subscript(PyArrayIterObject *self, PyObject *ind)\n{\n\tPyArray_Descr *indtype=NULL;\n\tintp start, step_size;\n\tintp n_steps;\n\tPyObject *r;\n\tchar *dptr;\n\tint size;\n\tPyObject *obj = NULL;\n\tint swap;\n PyArray_CopySwapFunc *copyswap;\n\n\tif (ind == Py_Ellipsis) {\n\t\tind = PySlice_New(NULL, NULL, NULL);\n\t\tobj = iter_subscript(self, ind);\n\t\tPy_DECREF(ind);\n\t\treturn obj;\n\t}\n\tif (PyTuple_Check(ind)) {\n\t\tint len;\n\t\tlen = PyTuple_GET_SIZE(ind);\n\t\tif (len > 1) goto fail;\n\t\tind = PyTuple_GET_ITEM(ind, 0);\n\t}\n\n\t/* Tuples >1d not accepted --- i.e. no newaxis */\n\t/* Could implement this with adjusted strides\n\t and dimensions in iterator */\n\n\t/* Check for Boolean -- this is first becasue\n\t Bool is a subclass of Int */\n\tPyArray_ITER_RESET(self);\n\n\tif (PyBool_Check(ind)) {\n\t\tif (PyObject_IsTrue(ind)) {\n\t\t\treturn PyArray_ToScalar(self->dataptr, self->ao);\n\t\t}\n\t\telse { /* empty array */\n\t\t\tintp ii = 0;\n\t\t\tPy_INCREF(self->ao->descr);\n\t\t\tr = PyArray_NewFromDescr(self->ao->ob_type, \n\t\t\t\t\t\t self->ao->descr,\n\t\t\t\t\t\t 1, &ii, \n\t\t\t\t\t\t NULL, NULL, 0,\n\t\t\t\t\t\t (PyObject *)self->ao);\n\t\t\treturn r;\t\t\t\n\t\t}\n\t}\n\n\t/* Check for Integer or Slice */ \t\n\t\n\tif (PyLong_Check(ind) || PyInt_Check(ind) || PySlice_Check(ind)) {\n\t\tstart = parse_subindex(ind, &step_size, &n_steps, \n\t\t\t\t self->size);\n\t\tif (start == -1) \n\t\t\tgoto fail;\n\t\tif (n_steps == RubberIndex || n_steps == PseudoIndex) {\n\t\t\tPyErr_SetString(PyExc_IndexError, \n\t\t\t\t\t\"cannot use Ellipsis or newaxes here\");\n\t\t\tgoto fail;\n\t\t}\n\t\tPyArray_ITER_GOTO1D(self, start)\n\t\tif (n_steps == SingleIndex) { /* Integer */\n\t\t\tr = PyArray_ToScalar(self->dataptr, self->ao);\n\t\t\tPyArray_ITER_RESET(self);\n\t\t\treturn r;\n\t\t}\n\t\tsize = self->ao->descr->elsize;\n\t\tPy_INCREF(self->ao->descr);\n\t\tr = PyArray_NewFromDescr(self->ao->ob_type, \n\t\t\t\t\t self->ao->descr, \n\t\t\t\t\t 1, &n_steps, \n\t\t\t\t\t NULL, NULL,\n\t\t\t\t\t 0, (PyObject *)self->ao);\n\t\tif (r==NULL) goto fail; \n\t\tdptr = PyArray_DATA(r);\n swap = !PyArray_ISNOTSWAPPED(self->ao);\n copyswap = PyArray_DESCR(r)->f->copyswap;\n\t\twhile(n_steps--) {\n copyswap(dptr, self->dataptr, swap, size);\n\t\t\tstart += step_size;\n\t\t\tPyArray_ITER_GOTO1D(self, start)\n\t\t\tdptr += size;\n\t\t}\n\t\tPyArray_ITER_RESET(self);\n\t\treturn r;\n\t} \n\n\t/* convert to INTP array if Integer array scalar or List */\n\n\tindtype = PyArray_DescrFromType(PyArray_INTP);\n\tif (PyArray_IsScalar(ind, Integer) || PyList_Check(ind)) {\n\t\tPy_INCREF(indtype);\n\t\tobj = PyArray_FromAny(ind, indtype, 0, 0, FORCECAST, NULL);\n\t\tif (obj == NULL) goto fail;\n\t}\n\telse {\n\t\tPy_INCREF(ind);\n\t\tobj = ind;\n\t}\n\t\n\tif (PyArray_Check(obj)) {\n\t\t/* Check for Boolean object */\n\t\tif (PyArray_TYPE(obj)==PyArray_BOOL) {\n\t\t\tr = iter_subscript_Bool(self, (PyArrayObject *)obj);\n\t\t\tPy_DECREF(indtype);\n\t\t} \n\t\t/* Check for integer array */\n\t\telse if (PyArray_ISINTEGER(obj)) {\n\t\t\tPyObject *new;\n\t\t\tnew = PyArray_FromAny(obj, indtype, 0, 0, \n FORCECAST | ALIGNED, NULL);\n\t\t\tif (new==NULL) goto fail;\n Py_DECREF(obj);\n\t\t\tobj = new;\n\t\t\tr = iter_subscript_int(self, (PyArrayObject *)obj);\n\t\t}\n\t\telse {\n\t\t\tgoto fail;\n\t\t}\n\t\tPy_DECREF(obj);\n\t\treturn r;\n\t}\n\telse Py_DECREF(indtype);\n\n\n fail:\n\tif (!PyErr_Occurred())\n\t\tPyErr_SetString(PyExc_IndexError, \"unsupported iterator index\");\n\tPy_XDECREF(indtype);\n\tPy_XDECREF(obj);\n\treturn NULL;\n\n}\n\n\nstatic int\niter_ass_sub_Bool(PyArrayIterObject *self, PyArrayObject *ind,\n\t\t PyArrayIterObject *val, int swap)\n{\n\tint index, strides, itemsize;\n\tchar *dptr;\n PyArray_CopySwapFunc *copyswap;\n\n\tif (ind->nd != 1) {\n\t\tPyErr_SetString(PyExc_ValueError, \n\t\t\t\t\"boolean index array should have 1 dimension\");\n\t\treturn -1;\n\t}\n\titemsize = self->ao->descr->elsize;\n\tindex = ind->dimensions[0];\n\tstrides = ind->strides[0];\n\tdptr = ind->data;\n\tPyArray_ITER_RESET(self);\n\t/* Loop over Boolean array */\n copyswap = self->ao->descr->f->copyswap;\n\twhile(index--) {\n\t\tif (*((Bool *)dptr) != 0) {\n copyswap(self->dataptr, val->dataptr, swap,\n\t\t\t\t itemsize);\n\t\t\tPyArray_ITER_NEXT(val);\n\t\t\tif (val->index==val->size) \n\t\t\t\tPyArray_ITER_RESET(val);\n\t\t}\n\t\tdptr += strides;\n\t\tPyArray_ITER_NEXT(self);\n\t}\n\tPyArray_ITER_RESET(self);\n\treturn 0;\n}\n\nstatic int\niter_ass_sub_int(PyArrayIterObject *self, PyArrayObject *ind,\n\t\t PyArrayIterObject *val, int swap)\n{\n\tPyArray_Descr *typecode;\n\tintp num;\n\tPyArrayIterObject *ind_it;\n\tint itemsize;\n\tint index;\n PyArray_CopySwapFunc *copyswap;\n\n\ttypecode = self->ao->descr;\n\titemsize = typecode->elsize;\n copyswap = self->ao->descr->f->copyswap;\n\tif (ind->nd == 0) {\n\t\tnum = *((intp *)ind->data);\n\t\tPyArray_ITER_GOTO1D(self, num);\n copyswap(self->dataptr, val->dataptr, swap, itemsize);\n\t\treturn 0;\n\t}\n\tind_it = (PyArrayIterObject *)PyArray_IterNew((PyObject *)ind);\n\tif (ind_it == NULL) return -1;\n\tindex = ind_it->size;\n\twhile(index--) {\n\t\tnum = *((intp *)(ind_it->dataptr));\n\t\tif (num < 0) num += self->size;\n\t\tif ((num < 0) || (num >= self->size)) {\n\t\t\tPyErr_Format(PyExc_IndexError,\n\t\t\t\t \"index %d out of bounds\"\t\t\\\n\t\t\t\t \" 0<=index<%d\", (int) num, \n\t\t\t\t (int) self->size);\n\t\t\tPy_DECREF(ind_it);\n\t\t\treturn -1;\n\t\t}\n\t\tPyArray_ITER_GOTO1D(self, num);\n copyswap(self->dataptr, val->dataptr, swap, itemsize);\n\t\tPyArray_ITER_NEXT(ind_it);\n\t\tPyArray_ITER_NEXT(val);\n\t\tif (val->index == val->size) \n\t\t\tPyArray_ITER_RESET(val);\n\t}\n\tPy_DECREF(ind_it);\n\treturn 0;\n}\n\nstatic int\niter_ass_subscript(PyArrayIterObject *self, PyObject *ind, PyObject *val) \n{\n\tPyObject *arrval=NULL;\n\tPyArrayIterObject *val_it=NULL;\n\tPyArray_Descr *type;\n\tPyArray_Descr *indtype=NULL;\n\tint swap, retval=-1;\n\tint itemsize;\n\tintp start, step_size;\n\tintp n_steps;\n\tPyObject *obj=NULL;\n PyArray_CopySwapFunc *copyswap;\n\n\t\n\tif (ind == Py_Ellipsis) {\n\t\tind = PySlice_New(NULL, NULL, NULL);\n\t\tretval = iter_ass_subscript(self, ind, val);\n\t\tPy_DECREF(ind);\n\t\treturn retval;\n\t}\n\n\tif (PyTuple_Check(ind)) {\n\t\tint len;\n\t\tlen = PyTuple_GET_SIZE(ind);\n\t\tif (len > 1) goto finish;\n\t\tind = PyTuple_GET_ITEM(ind, 0);\n\t}\n\n\ttype = self->ao->descr;\n\titemsize = type->elsize;\n\t\n\tPy_INCREF(type);\n\tarrval = PyArray_FromAny(val, type, 0, 0, 0, NULL);\n\tif (arrval==NULL) return -1;\n\tval_it = (PyArrayIterObject *)PyArray_IterNew(arrval);\n\tif (val_it==NULL) goto finish;\n\n\t/* Check for Boolean -- this is first becasue\n\t Bool is a subclass of Int */\n\n copyswap = PyArray_DESCR(arrval)->f->copyswap;\n\tswap = (PyArray_ISNOTSWAPPED(self->ao)!=PyArray_ISNOTSWAPPED(arrval));\n\tif (PyBool_Check(ind)) {\n\t\tif (PyObject_IsTrue(ind)) {\n copyswap(self->dataptr, PyArray_DATA(arrval), \n swap, itemsize);\n\t\t}\n\t\tretval=0;\n\t\tgoto finish;\n\t}\n\n\t/* Check for Integer or Slice */\n\t\n\tif (PyLong_Check(ind) || PyInt_Check(ind) || PySlice_Check(ind)) {\n\t\tstart = parse_subindex(ind, &step_size, &n_steps, \n\t\t\t\t self->size);\n\t\tif (start == -1) goto finish;\n\t\tif (n_steps == RubberIndex || n_steps == PseudoIndex) {\n\t\t\tPyErr_SetString(PyExc_IndexError, \n\t\t\t\t\t\"cannot use Ellipsis or newaxes here\");\n\t\t\tgoto finish;\n\t\t}\n\t\tPyArray_ITER_GOTO1D(self, start);\n\t\tif (n_steps == SingleIndex) { /* Integer */\n copyswap(self->dataptr, PyArray_DATA(arrval),\n swap, itemsize);\n\t\t\tPyArray_ITER_RESET(self);\n\t\t\tretval=0;\n\t\t\tgoto finish;\n\t\t}\n\t\twhile(n_steps--) {\n copyswap(self->dataptr, val_it->dataptr,\n swap, itemsize);\n\t\t\tstart += step_size;\n\t\t\tPyArray_ITER_GOTO1D(self, start)\n\t\t\tPyArray_ITER_NEXT(val_it);\n\t\t\tif (val_it->index == val_it->size) \n\t\t\t\tPyArray_ITER_RESET(val_it);\n\t\t}\n\t\tPyArray_ITER_RESET(self);\n\t\tretval = 0;\n\t\tgoto finish;\n\t} \n\n\t/* convert to INTP array if Integer array scalar or List */\n\n\tindtype = PyArray_DescrFromType(PyArray_INTP);\n\tif (PyArray_IsScalar(ind, Integer)) {\n\t\tPy_INCREF(indtype);\n\t\tobj = PyArray_FromScalar(ind, indtype);\n\t}\n\telse if (PyList_Check(ind)) {\n\t\tPy_INCREF(indtype);\n\t\tobj = PyArray_FromAny(ind, indtype, 0, 0, FORCECAST, NULL);\n\t}\n\telse {\n\t\tPy_INCREF(ind);\n\t\tobj = ind;\n\t}\n\t\n\tif (PyArray_Check(obj)) {\n\t\t/* Check for Boolean object */\n\t\tif (PyArray_TYPE(obj)==PyArray_BOOL) {\n\t\t\tif (iter_ass_sub_Bool(self, (PyArrayObject *)obj,\n\t\t\t\t\t val_it, swap) < 0)\n\t\t\t\tgoto finish;\n\t\t\tretval=0;\n\t\t} \n\t\t/* Check for integer array */\n\t\telse if (PyArray_ISINTEGER(obj)) {\n\t\t\tPyObject *new;\n\t\t\tPy_INCREF(indtype);\n\t\t\tnew = PyArray_CheckFromAny(obj, indtype, 0, 0, \n FORCECAST | BEHAVED_NS_FLAGS, NULL);\n\t\t\tPy_DECREF(obj);\n\t\t\tobj = new;\n\t\t\tif (new==NULL) goto finish;\n\t\t\tif (iter_ass_sub_int(self, (PyArrayObject *)obj,\n\t\t\t\t\t val_it, swap) < 0)\n\t\t\t\tgoto finish;\n\t\t\tretval=0;\n\t\t}\n\t}\n\n finish:\n\tif (!PyErr_Occurred() && retval < 0)\n\t\tPyErr_SetString(PyExc_IndexError, \n\t\t\t\t\"unsupported iterator index\");\n\tPy_XDECREF(indtype);\n\tPy_XDECREF(obj);\n\tPy_XDECREF(val_it);\n\tPy_XDECREF(arrval);\n\treturn retval;\n\t\n}\n\n\nstatic PyMappingMethods iter_as_mapping = {\n (inquiry)iter_length,\t\t /*mp_length*/\n (binaryfunc)iter_subscript,\t /*mp_subscript*/\n (objobjargproc)iter_ass_subscript,\t/*mp_ass_subscript*/\n};\n\nstatic char doc_iter_array[] = \"__array__(type=None)\\n Get array \"\\\n \"from iterator\";\n\nstatic PyObject *\niter_array(PyArrayIterObject *it, PyObject *op) \n{\n \n PyObject *r;\n intp size;\n\n /* Any argument ignored */\n\n /* Two options: \n 1) underlying array is contiguous\n -- return 1-d wrapper around it \n 2) underlying array is not contiguous\n -- make new 1-d contiguous array with updateifcopy flag set\n to copy back to the old array\n */\n\n size = PyArray_SIZE(it->ao);\n\tPy_INCREF(it->ao->descr);\n if (PyArray_ISCONTIGUOUS(it->ao)) {\n r = PyArray_NewFromDescr(it->ao->ob_type, \n\t\t\t\t\t it->ao->descr,\n\t\t\t\t\t 1, &size, \n\t\t\t\t\t NULL, it->ao->data, \n\t\t\t\t\t it->ao->flags,\n\t\t\t\t\t (PyObject *)it->ao); \n\t\tif (r==NULL) return NULL;\n }\n else {\n r = PyArray_NewFromDescr(it->ao->ob_type, \n\t\t\t\t\t it->ao->descr,\n\t\t\t\t\t 1, &size, \n\t\t\t\t\t NULL, NULL, \n\t\t\t\t\t 0, (PyObject *)it->ao);\n\t\tif (r==NULL) return NULL;\n\t\tif (PyArray_CopyInto((PyArrayObject *)r, it->ao) < 0) {\n\t\t\tPy_DECREF(r); \n\t\t\treturn NULL;\n\t\t}\n PyArray_FLAGS(r) |= UPDATEIFCOPY;\n it->ao->flags &= ~WRITEABLE;\n }\n Py_INCREF(it->ao);\n PyArray_BASE(r) = (PyObject *)it->ao;\n return r;\n \n}\n\nstatic char doc_iter_copy[] = \"copy()\\n Get a copy of 1-d array\";\n\nstatic PyObject *\niter_copy(PyArrayIterObject *it, PyObject *args)\n{\n if (!PyArg_ParseTuple(args, \"\")) return NULL;\t\n\treturn PyArray_Flatten(it->ao, 0);\n}\n\nstatic PyMethodDef iter_methods[] = {\n /* to get array */\n {\"__array__\", (PyCFunction)iter_array, 1, doc_iter_array},\n\t{\"copy\", (PyCFunction)iter_copy, 1, doc_iter_copy},\n {NULL,\t\tNULL}\t\t/* sentinel */\n};\n\nstatic PyMemberDef iter_members[] = {\n\t{\"base\", T_OBJECT, offsetof(PyArrayIterObject, ao), RO, NULL},\n {\"index\", T_INT, offsetof(PyArrayIterObject, index), RO, NULL},\n\t{NULL},\n};\n\nstatic PyObject *\niter_coords_get(PyArrayIterObject *self)\n{\n int nd;\n nd = self->ao->nd;\n if (self->contiguous) { /* coordinates not kept track of --- need to generate\n from index */\n intp val;\n int i;\n val = self->index;\n for (i=0;icoordinates[i] = val / self->factors[i];\n val = val % self->factors[i];\n }\n }\n return PyArray_IntTupleFromIntp(nd, self->coordinates);\n}\n\nstatic PyGetSetDef iter_getsets[] = {\n\t{\"coords\", \n\t (getter)iter_coords_get,\n\t NULL,\n\t \"An N-d tuple of current coordinates.\"},\n\t{NULL, NULL, NULL, NULL},\n};\n\nstatic PyTypeObject PyArrayIter_Type = {\n PyObject_HEAD_INIT(NULL)\n 0,\t\t\t\t\t /* ob_size */\n \"numpy.flatiter\",\t\t /* tp_name */\n sizeof(PyArrayIterObject), /* tp_basicsize */\n 0,\t\t\t\t\t /* tp_itemsize */\n /* methods */\n (destructor)arrayiter_dealloc,\t\t/* tp_dealloc */\n 0,\t\t\t\t\t/* tp_print */\n 0,\t\t\t\t\t/* tp_getattr */\n 0,\t\t\t\t\t/* tp_setattr */\n 0,\t\t\t\t\t/* tp_compare */\n 0,\t\t\t\t\t/* tp_repr */\n 0,\t\t\t\t\t/* tp_as_number */\n 0, \t\t\t /* tp_as_sequence */\n &iter_as_mapping, \t /* tp_as_mapping */\n 0,\t\t\t\t\t/* tp_hash */\n 0,\t\t\t\t\t/* tp_call */\n 0,\t\t\t\t\t/* tp_str */\n 0,\t \t/* tp_getattro */\n 0,\t\t\t\t\t/* tp_setattro */\n 0,\t\t\t\t\t/* tp_as_buffer */\n Py_TPFLAGS_DEFAULT, /* tp_flags */\n 0,\t\t\t\t\t/* tp_doc */\n 0, \t /* tp_traverse */\n 0,\t\t\t\t\t/* tp_clear */\n 0,\t\t\t\t\t/* tp_richcompare */\n 0,\t\t\t\t\t/* tp_weaklistoffset */\n 0, \t /* tp_iter */\n (iternextfunc)arrayiter_next,\t\t/* tp_iternext */\n iter_methods,\t\t\t\t/* tp_methods */\n iter_members,\t \t /* tp_members */\n iter_getsets, /* tp_getset */\n\n};\n\n/** END of Array Iterator **/\n\n\n\n/*********************** Subscript Array Iterator *************************\n * *\n * This object handles subscript behavior for array objects. *\n * It is an iterator object with a next method *\n * It abstracts the n-dimensional mapping behavior to make the looping *\n * code more understandable (maybe) *\n * and so that indexing can be set up ahead of time *\n */ \n\n/* convert an indexing object to an INTP indexing array iterator\n if possible -- otherwise, it is a Slice or Ellipsis object\n and has to be interpreted on bind to a particular \n array so leave it NULL for now.\n */\nstatic int\n_convert_obj(PyObject *obj, PyArrayIterObject **iter)\n{\n\tPyArray_Descr *indtype;\n\tPyObject *arr;\n\n\tif (PySlice_Check(obj) || (obj == Py_Ellipsis))\n\t\t*iter = NULL;\n\telse {\n\t\tindtype = PyArray_DescrFromType(PyArray_INTP);\n\t\tarr = PyArray_FromAny(obj, indtype, 0, 0, FORCECAST, NULL);\n\t\tif (arr == NULL) return -1;\n\t\t*iter = (PyArrayIterObject *)PyArray_IterNew(arr);\n\t\tPy_DECREF(arr);\n\t\tif (*iter == NULL) return -1;\n\t}\n\treturn 0;\n}\n\n/* Adjust dimensionality and strides for index object iterators \n --- i.e. broadcast\n */\n/*OBJECT_API*/\nstatic int\nPyArray_Broadcast(PyArrayMultiIterObject *mit)\n{\n\tint i, nd, k, j;\n\tintp tmp;\n\tPyArrayIterObject *it;\n\t\n\t/* Discover the broadcast number of dimensions */\n\tfor (i=0, nd=0; inumiter; i++) \n\t\tnd = MAX(nd, mit->iters[i]->ao->nd);\n\tmit->nd = nd;\n\n\t/* Discover the broadcast shape in each dimension */\n\tfor (i=0; idimensions[i] = 1;\n\t\tfor (j=0; jnumiter; j++) {\n\t\t\tit = mit->iters[j];\n\t\t\t/* This prepends 1 to shapes not already \n\t\t\t equal to nd */\n\t\t\tk = i + it->ao->nd - nd;\n\t\t\tif (k>=0) {\n\t\t\t\ttmp = it->ao->dimensions[k];\n\t\t\t\tif (tmp == 1) continue;\n\t\t\t\tif (mit->dimensions[i] == 1) \n\t\t\t\t\tmit->dimensions[i] = tmp;\n\t\t\t\telse if (mit->dimensions[i] != tmp) {\n\t\t\t\t\tPyErr_SetString(PyExc_ValueError, \n\t\t\t\t\t\t\t\"index objects are \" \\\n\t\t\t\t\t\t\t\"not broadcastable \" \\\n\t\t\t\t\t\t\t\"to a single shape\");\n\t\t\t\t\treturn -1;\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t}\n\n\t/* Reset the iterator dimensions and strides of each iterator\n\t object -- using 0 valued strides for broadcasting */\n\n\ttmp = PyArray_MultiplyList(mit->dimensions, mit->nd);\n\tmit->size = tmp;\n\tfor (i=0; inumiter; i++) {\n\t\tit = mit->iters[i];\n\t\tit->nd_m1 = mit->nd - 1;\n\t\tit->size = tmp;\n\t\tnd = it->ao->nd;\n\t\tit->factors[mit->nd-1] = 1;\n\t\tfor (j=0; j < mit->nd; j++) {\n\t\t\tit->dims_m1[j] = mit->dimensions[j] - 1;\n\t\t\tk = j + nd - mit->nd;\n\t\t\t/* If this dimension was added or shape\n\t\t\t of underlying array was 1 */\n\t\t\tif ((k < 0) || \\\n\t\t\t it->ao->dimensions[k] != mit->dimensions[j]) {\n\t\t\t\tit->contiguous = 0;\n\t\t\t\tit->strides[j] = 0;\n\t\t\t}\n\t\t\telse {\n\t\t\t\tit->strides[j] = it->ao->strides[k];\n\t\t\t}\n\t\t\tit->backstrides[j] = it->strides[j] *\t\\\n\t\t\t\tit->dims_m1[j];\n\t\t\tif (j > 0)\n\t\t\t\tit->factors[mit->nd-j-1] =\t\t\\\n\t\t\t\t\tit->factors[mit->nd-j] *\t\\\n\t\t\t\t\tmit->dimensions[mit->nd-j];\n\t\t}\n\t\tPyArray_ITER_RESET(it);\n\t}\n\treturn 0;\n}\n\n/* Reset the map iterator to the beginning */\nstatic void\nPyArray_MapIterReset(PyArrayMapIterObject *mit)\n{\n\tint i,j; intp coord[MAX_DIMS];\n\tPyArrayIterObject *it;\n\tPyArray_CopySwapFunc *copyswap;\n\n\tmit->index = 0;\n\n\tcopyswap = mit->iters[0]->ao->descr->f->copyswap;\n\n\tif (mit->subspace != NULL) {\n\t\tmemcpy(coord, mit->bscoord, sizeof(intp)*mit->ait->ao->nd);\n\t\tPyArray_ITER_RESET(mit->subspace);\n\t\tfor (i=0; inumiter; i++) {\n\t\t\tit = mit->iters[i];\n\t\t\tPyArray_ITER_RESET(it);\n\t\t\tj = mit->iteraxes[i];\n\t\t\tcopyswap(coord+j,it->dataptr,\n\t\t\t\t !PyArray_ISNOTSWAPPED(it->ao),\n\t\t\t\t sizeof(intp));\n\t\t}\n\t\tPyArray_ITER_GOTO(mit->ait, coord);\n\t\tmit->subspace->dataptr = mit->ait->dataptr;\n\t\tmit->dataptr = mit->subspace->dataptr;\n\t}\n\telse {\n\t\tfor (i=0; inumiter; i++) {\n\t\t\tit = mit->iters[i];\n\t\t\tPyArray_ITER_RESET(it);\n\t\t\tcopyswap(coord+i,it->dataptr, \n\t\t\t\t !PyArray_ISNOTSWAPPED(it->ao),\n\t\t\t\t sizeof(intp));\n\t\t}\n\t\tPyArray_ITER_GOTO(mit->ait, coord);\n\t\tmit->dataptr = mit->ait->dataptr;\n\t}\n\treturn;\n}\n\n/* This function needs to update the state of the map iterator\n and point mit->dataptr to the memory-location of the next object\n*/\nstatic void\nPyArray_MapIterNext(PyArrayMapIterObject *mit)\n{\n\tint i, j;\n\tintp coord[MAX_DIMS];\n\tPyArrayIterObject *it;\n\tPyArray_CopySwapFunc *copyswap;\n\n\tmit->index += 1;\n\tif (mit->index >= mit->size) return;\n\tcopyswap = mit->iters[0]->ao->descr->f->copyswap;\n\t/* Sub-space iteration */\n\tif (mit->subspace != NULL) {\n\t\tPyArray_ITER_NEXT(mit->subspace);\n\t\tif (mit->subspace->index == mit->subspace->size) {\n\t\t\t/* reset coord to coordinates of \n\t\t\t beginning of the subspace */\n\t\t\tmemcpy(coord, mit->bscoord, \n\t\t\t sizeof(intp)*mit->ait->ao->nd);\n\t\t\tPyArray_ITER_RESET(mit->subspace);\n\t\t\tfor (i=0; inumiter; i++) {\n\t\t\t\tit = mit->iters[i];\n\t\t\t\tPyArray_ITER_NEXT(it);\n\t\t\t\tj = mit->iteraxes[i];\n\t\t\t\tcopyswap(coord+j,it->dataptr,\n\t\t\t\t\t !PyArray_ISNOTSWAPPED(it->ao),\n\t\t\t\t\t sizeof(intp));\n\t\t\t}\n\t\t\tPyArray_ITER_GOTO(mit->ait, coord);\n\t\t\tmit->subspace->dataptr = mit->ait->dataptr;\n\t\t}\n\t\tmit->dataptr = mit->subspace->dataptr;\n\t}\n\telse {\n\t\tfor (i=0; inumiter; i++) {\n\t\t\tit = mit->iters[i];\n\t\t\tPyArray_ITER_NEXT(it);\n\t\t\tcopyswap(coord+i,it->dataptr, \n\t\t\t\t !PyArray_ISNOTSWAPPED(it->ao),\n\t\t\t\t sizeof(intp));\n\t\t}\n\t\tPyArray_ITER_GOTO(mit->ait, coord);\n\t\tmit->dataptr = mit->ait->dataptr;\n\t}\n\treturn;\n}\n\n/* Bind a mapiteration to a particular array */\n\n/* Determine if subspace iteration is necessary. If so, \n 1) Fill in mit->iteraxes\n\t 2) Create subspace iterator\n\t 3) Update nd, dimensions, and size. \n\n Subspace iteration is necessary if: arr->nd > mit->numiter\n*/\n\n/* Need to check for index-errors somewhere. \n\n Let's do it at bind time and also convert all <0 values to >0 here\n as well. \n*/\nstatic void\nPyArray_MapIterBind(PyArrayMapIterObject *mit, PyArrayObject *arr)\n{\n\tint subnd;\n\tPyObject *sub, *obj=NULL;\n\tint i, j, n, curraxis, ellipexp, noellip;\n\tPyArrayIterObject *it;\n\tintp dimsize;\n\tintp *indptr;\n\t\n\tsubnd = arr->nd - mit->numiter;\n\tif (subnd < 0) {\n\t\tPyErr_SetString(PyExc_ValueError, \n\t\t\t\t\"too many indices for array\");\n\t\treturn;\n\t}\n\n\tmit->ait = (PyArrayIterObject *)PyArray_IterNew((PyObject *)arr);\n\tif (mit->ait == NULL) return;\n\n\t/* If this is just a view, then do nothing more */\n\t/* views are handled by just adjusting the strides\n\t and dimensions of the object.\n\t*/\n\t \n\t/* no subspace iteration needed. Finish up and Return */\n\tif (subnd == 0) {\n\t\tn = arr->nd;\n\t\tfor (i=0; iiteraxes[i] = i;\n\t\t}\n\t\tgoto finish;\n\t}\n\n\t/* all indexing arrays have been converted to 0 \n\t therefore we can extract the subspace with a simple\n\t getitem call which will use view semantics\n\t*/\n\t\n\tsub = PyObject_GetItem((PyObject *)arr, mit->indexobj);\n\tif (sub == NULL) goto fail;\n\tmit->subspace = (PyArrayIterObject *)PyArray_IterNew(sub);\n\tPy_DECREF(sub);\n\tif (mit->subspace == NULL) goto fail;\n\t\n\t/* Expand dimensions of result */\n\tn = mit->subspace->ao->nd;\n\tfor (i=0; idimensions[mit->nd+i] = mit->subspace->ao->dimensions[i];\n\tmit->nd += n;\n\n\t/* Now, we still need to interpret the ellipsis and slice objects \n\t to determine which axes the indexing arrays are referring to\n\t*/\n\tn = PyTuple_GET_SIZE(mit->indexobj);\n\n\t/* The number of dimensions an ellipsis takes up */\n\tellipexp = arr->nd - n + 1;\n\t/* Now fill in iteraxes -- remember indexing arrays have been \n converted to 0's in mit->indexobj */\n\tcurraxis = 0;\n\tj = 0;\n\tnoellip = 1; /* Only expand the first ellipsis */\n\tmemset(mit->bscoord, 0, sizeof(intp)*arr->nd);\n\tfor (i=0; iindexobj, i);\n\t\tif (PyInt_Check(obj) || PyLong_Check(obj)) \n\t\t\tmit->iteraxes[j++] = curraxis++;\n\t\telse if (noellip && obj == Py_Ellipsis) {\n\t\t\tcurraxis += ellipexp;\n\t\t\tnoellip = 0;\n\t\t}\n\t\telse {\n\t\t\tintp start=0;\n\t\t\tintp stop, step;\n\t\t\t/* Should be slice object or\n\t\t\t another Ellipsis */\n\t\t\tif (obj == Py_Ellipsis) {\n\t\t\t\tmit->bscoord[curraxis] = 0;\n\t\t\t}\n\t\t\telse if (!PySlice_Check(obj) || \\\n\t\t\t\t (slice_GetIndices((PySliceObject *)obj, \n\t\t\t\t\t\t arr->dimensions[curraxis],\n\t\t\t\t\t\t &start, &stop, &step,\n\t\t\t\t\t\t &dimsize) < 0)) {\n\t\t\t\tPyErr_Format(PyExc_ValueError, \n\t\t\t\t\t \"unexpected object \"\t\\\n\t\t\t\t\t \"(%s) in selection position %d\",\n\t\t\t\t\t obj->ob_type->tp_name, i);\n\t\t\t goto fail;\n\t\t\t}\n\t\t\telse {\n\t\t\t\tmit->bscoord[curraxis] = start;\n\t\t\t}\n\t\t\tcurraxis += 1; \n\t\t}\n\t}\n finish:\n\t/* Here check the indexes (now that we have iteraxes) */\n\tmit->size = PyArray_MultiplyList(mit->dimensions, mit->nd);\n\tfor (i=0; inumiter; i++) {\n\t\tit = mit->iters[i];\n\t\tPyArray_ITER_RESET(it);\n\t\tdimsize = arr->dimensions[mit->iteraxes[i]];\n\t\twhile(it->index < it->size) {\n\t\t\tindptr = ((intp *)it->dataptr);\n\t\t\tif (*indptr < 0) *indptr += dimsize;\n\t\t\tif (*indptr < 0 || *indptr >= dimsize) {\n\t\t\t\tPyErr_Format(PyExc_IndexError,\n\t\t\t\t\t \"index (%d) out of range \"\\\n\t\t\t\t\t \"(0<=index<=%d) in dimension %d\",\n\t\t\t\t\t (int) *indptr, (int) (dimsize-1), \n\t\t\t\t\t mit->iteraxes[i]);\n\t\t\t\tgoto fail;\n\t\t\t}\n\t\t\tPyArray_ITER_NEXT(it);\n\t\t} \n\t\tPyArray_ITER_RESET(it);\n\t}\n\treturn;\n\n fail:\n\tPy_XDECREF(mit->subspace);\n\tPy_XDECREF(mit->ait);\n\tmit->subspace = NULL;\n\tmit->ait = NULL;\n\treturn;\n}\n\n/* This function takes a Boolean array and constructs index objects and\n iterators as if nonzero(Bool) had been called\n*/\nstatic int\n_nonzero_indices(PyObject *myBool, PyArrayIterObject **iters)\n{\n\tPyArray_Descr *typecode;\n\tPyArrayObject *ba =NULL, *new=NULL;\n\tint nd, j;\n\tintp size, i, count;\n\tBool *ptr;\n\tintp coords[MAX_DIMS], dims_m1[MAX_DIMS];\n\tintp *dptr[MAX_DIMS];\n\n\ttypecode=PyArray_DescrFromType(PyArray_BOOL);\n\tba = (PyArrayObject *)PyArray_FromAny(myBool, typecode, 0, 0, \n\t\t\t\t\t CARRAY_FLAGS, NULL);\n\tif (ba == NULL) return -1;\n\tnd = ba->nd;\n\tfor (j=0; jdata;\n\tcount = 0;\n\n\t/* pre-determine how many nonzero entries there are */\n\tfor (i=0; iao->data;\n\t\tcoords[j] = 0;\n\t\tdims_m1[j] = ba->dimensions[j]-1;\n\t}\n\n\tptr = (Bool *)ba->data;\n\n\tif (count == 0) goto finish;\n\t\n\t/* Loop through the Boolean array and copy coordinates\n\t for non-zero entries */\n\tfor (i=0; i=0; j--) {\n\t\t\tif (coords[j] < dims_m1[j]) {\n\t\t\t\tcoords[j]++;\n\t\t\t\tbreak;\n\t\t\t}\n\t\t\telse {\n\t\t\t\tcoords[j] = 0;\n\t\t\t}\n\t\t}\n\t}\n\n finish:\n\tPy_DECREF(ba);\n\treturn nd;\n\n fail:\n\tfor (j=0; jiters[i] = NULL;\n \tmit->index = 0;\n \tmit->ait = NULL;\n \tmit->subspace = NULL;\n\tmit->numiter = 0;\n\tmit->consec = 1;\n\tPy_INCREF(indexobj);\n\tmit->indexobj = indexobj;\n\n\tif (fancy == SOBJ_LISTTUP) {\n\t\tPyObject *newobj;\n\t\tnewobj = PySequence_Tuple(indexobj);\n\t\tif (newobj == NULL) goto fail;\n\t\tPy_DECREF(indexobj);\n\t\tindexobj = newobj;\n\t\tmit->indexobj = indexobj;\n\t}\n\n#undef SOBJ_NOTFANCY \n#undef SOBJ_ISFANCY \n#undef SOBJ_BADARRAY \n#undef SOBJ_TOOMANY \n#undef SOBJ_LISTTUP \n \n\tif (oned) return (PyObject *)mit;\n\n\t/* Must have some kind of fancy indexing if we are here */\n\t/* indexobj is either a list, an arrayobject, or a tuple \n\t (with at least 1 list or arrayobject or Bool object), */\n\t\n\t/* convert all inputs to iterators */\n\tif (PyArray_Check(indexobj) &&\t\t\t\\\n\t (PyArray_TYPE(indexobj) == PyArray_BOOL)) {\n\t\tmit->numiter = _nonzero_indices(indexobj, mit->iters);\n\t\tif (mit->numiter < 0) goto fail;\n\t\tmit->nd = 1;\n\t\tmit->dimensions[0] = mit->iters[0]->dims_m1[0]+1;\n\t\tPy_DECREF(mit->indexobj);\n\t\tmit->indexobj = PyTuple_New(mit->numiter);\n\t\tif (mit->indexobj == NULL) goto fail;\n\t\tfor (i=0; inumiter; i++) {\n\t\t\tPyTuple_SET_ITEM(mit->indexobj, i, \n\t\t\t\t\t PyInt_FromLong(0));\n\t\t}\n\t}\n\n\telse if (PyArray_Check(indexobj) || !PyTuple_Check(indexobj)) {\n\t\tmit->numiter = 1;\n\t\tindtype = PyArray_DescrFromType(PyArray_INTP);\n\t\tarr = PyArray_FromAny(indexobj, indtype, 0, 0, FORCECAST, NULL);\n\t\tif (arr == NULL) goto fail;\n\t\tmit->iters[0] = (PyArrayIterObject *)PyArray_IterNew(arr);\n\t\tif (mit->iters[0] == NULL) {Py_DECREF(arr); goto fail;}\n\t\tmit->nd = PyArray_NDIM(arr);\n\t\tmemcpy(mit->dimensions,PyArray_DIMS(arr),mit->nd*sizeof(intp));\n\t\tmit->size = PyArray_SIZE(arr);\n\t\tPy_DECREF(arr);\n\t\tPy_DECREF(mit->indexobj);\n\t\tmit->indexobj = Py_BuildValue(\"(N)\", PyInt_FromLong(0));\n\t}\n\telse { /* must be a tuple */\n\t\tPyObject *obj;\n\t\tPyArrayIterObject *iter;\n\t\tPyObject *new;\n\t\t/* Make a copy of the tuple -- we will be replacing \n\t\t index objects with 0's */\n\t\tn = PyTuple_GET_SIZE(indexobj);\n\t\tnew = PyTuple_New(n);\n\t\tif (new == NULL) goto fail;\n\t\tstarted = 0;\n\t\tnonindex = 0;\n\t\tfor (i=0; iconsec = 0;\n\t\t\t\tmit->iters[(mit->numiter)++] = iter;\n\t\t\t\tPyTuple_SET_ITEM(new,i,\n\t\t\t\t\t\t PyInt_FromLong(0));\n\t\t\t}\n\t\t\telse {\n\t\t\t\tif (started) nonindex = 1;\n\t\t\t\tPy_INCREF(obj);\n\t\t\t\tPyTuple_SET_ITEM(new,i,obj);\n\t\t\t}\n\t\t}\n\t\tPy_DECREF(mit->indexobj);\n\t\tmit->indexobj = new;\n\t\t/* Store the number of iterators actually converted */\n\t\t/* These will be mapped to actual axes at bind time */\n\t\tif (PyArray_Broadcast((PyArrayMultiIterObject *)mit) < 0)\n\t\t\tgoto fail;\n\t}\n\n return (PyObject *)mit;\n \n fail:\n Py_DECREF(mit);\n\treturn NULL;\n}\n\n\nstatic void\narraymapiter_dealloc(PyArrayMapIterObject *mit)\n{\n\tint i;\n\tPy_XDECREF(mit->indexobj);\n Py_XDECREF(mit->ait);\n\tPy_XDECREF(mit->subspace);\n\tfor (i=0; inumiter; i++)\n\t\tPy_XDECREF(mit->iters[i]);\n _pya_free(mit);\n}\n\n/* The mapiter object must be created new each time. It does not work\n to bind to a new array, and continue.\n\n This was the orginal intention, but currently that does not work. \n Do not expose the MapIter_Type to Python.\n\n It's not very useful anyway, since mapiter(indexobj); mapiter.bind(a); \n mapiter is equivalent to a[indexobj].flat but the latter gets to use \n slice syntax.\n*/\n\nstatic PyTypeObject PyArrayMapIter_Type = {\n PyObject_HEAD_INIT(NULL)\n 0,\t\t\t\t\t /* ob_size */\n \"numpy.mapiter\",\t\t \t/* tp_name */\n sizeof(PyArrayIterObject), /* tp_basicsize */\n 0,\t\t\t\t\t /* tp_itemsize */\n /* methods */\n (destructor)arraymapiter_dealloc,\t/* tp_dealloc */\n 0,\t\t\t\t\t/* tp_print */\n 0,\t\t\t\t\t/* tp_getattr */\n 0,\t\t\t\t\t/* tp_setattr */\n 0,\t\t\t\t\t/* tp_compare */\n 0,\t\t\t\t\t/* tp_repr */\n 0,\t\t\t\t\t/* tp_as_number */\n 0,\t\t\t\t\t/* tp_as_sequence */\n 0,\t\t\t\t\t/* tp_as_mapping */\n 0,\t\t\t\t\t/* tp_hash */\n 0,\t\t\t\t\t/* tp_call */\n 0,\t\t\t\t\t/* tp_str */\n 0, \t\t/* tp_getattro */\n 0,\t\t\t\t\t/* tp_setattro */\n 0,\t\t\t\t\t/* tp_as_buffer */\n Py_TPFLAGS_DEFAULT, /* tp_flags */\n 0,\t\t\t\t\t/* tp_doc */\n (traverseproc)0, \t /* tp_traverse */\n 0,\t\t\t\t\t/* tp_clear */\n 0,\t\t\t\t\t/* tp_richcompare */\n 0,\t\t\t\t\t/* tp_weaklistoffset */\n 0,\t\t \t /* tp_iter */\n (iternextfunc)0, \t /* tp_iternext */\n 0, \t /* tp_methods */\n 0,\t\t\t\t\t /* tp_members */\n 0,\t\t\t /* tp_getset */\n 0,\t\t\t\t\t /* tp_base */\n 0,\t\t\t\t\t /* tp_dict */\n 0,\t\t\t\t\t /* tp_descr_get */\n 0,\t\t\t\t\t /* tp_descr_set */\n 0,\t\t\t\t\t /* tp_dictoffset */\n (initproc)0,\t \t /* tp_init */\n 0, \t /* tp_alloc */\n 0,\t /* tp_new */\n 0,\t /* tp_free */\n 0,\t\t\t\t\t /* tp_is_gc */\n 0,\t\t\t\t\t /* tp_bases */\n 0,\t\t\t\t\t /* tp_mro */\n 0,\t\t\t\t\t /* tp_cache */\n 0,\t\t\t\t\t /* tp_subclasses */\n 0\t\t\t\t\t /* tp_weaklist */\n\n};\n\n/** END of Subscript Iterator **/\n\n\n/*OBJECT_API\n Get MultiIterator,\n*/\nstatic PyObject *\nPyArray_MultiIterNew(int n, ...)\n{\n va_list va;\n\tPyArrayMultiIterObject *multi;\n\tPyObject *current;\n\tPyObject *arr;\n\t\n\tint i, err=0;\n\t\n\tif (n < 2 || n > MAX_DIMS) {\n\t\tPyErr_Format(PyExc_ValueError, \n\t\t\t \"Need between 2 and (%d) \"\t\t\t\\\n\t\t\t \"array objects (inclusive).\", MAX_DIMS);\n\t}\n\t\n /* fprintf(stderr, \"multi new...\");*/\n multi = PyObject_New(PyArrayMultiIterObject, &PyArrayMultiIter_Type);\n if (multi == NULL)\n return NULL;\n\t\n\tfor (i=0; iiters[i] = NULL;\n\tmulti->numiter = n;\n\tmulti->index = 0;\n\n va_start(va, n);\n\tfor (i=0; iiters[i] = (PyArrayIterObject *)PyArray_IterNew(arr);\n\t\t\tPy_DECREF(arr);\n\t\t}\n\t}\n\n\tva_end(va);\t\n\t\n\tif (!err && PyArray_Broadcast(multi) < 0) err=1;\n\n\tif (err) {\n Py_DECREF(multi);\n\t\treturn NULL;\n\t}\n\t\n\tPyArray_MultiIter_RESET(multi);\n\t\n return (PyObject *)multi;\n}\n\nstatic PyObject *\narraymultiter_new(PyTypeObject *subtype, PyObject *args, PyObject *kwds)\n{\n\t\n\tint n, i;\n\tPyArrayMultiIterObject *multi;\n\tPyObject *arr;\n\t\n\tif (kwds != NULL) {\n\t\tPyErr_SetString(PyExc_ValueError, \n\t\t\t\t\"keyword arguments not accepted.\");\n\t\treturn NULL;\n\t}\n\n\tn = PyTuple_Size(args);\n\tif (n < 2 || n > MAX_DIMS) {\n\t\tif (PyErr_Occurred()) return NULL;\n\t\tPyErr_Format(PyExc_ValueError, \n\t\t\t \"Need at least two and fewer than (%d) \"\t\\\n\t\t\t \"array objects.\", MAX_DIMS);\n\t\treturn NULL;\n\t}\n\t\n\tmulti = _pya_malloc(sizeof(PyArrayMultiIterObject));\n if (multi == NULL) return PyErr_NoMemory();\n\tPyObject_Init((PyObject *)multi, &PyArrayMultiIter_Type);\n\n\tmulti->numiter = n;\n\tmulti->index = 0;\n\tfor (i=0; iiters[i] = NULL;\n\tfor (i=0; iiters[i] =\t\t\t\t\t\\\n\t\t (PyArrayIterObject *)PyArray_IterNew(arr))==NULL) \n\t\t\tgoto fail;\n\t\tPy_DECREF(arr);\n\t}\n\tif (PyArray_Broadcast(multi) < 0) goto fail;\n\tPyArray_MultiIter_RESET(multi);\n\t\n return (PyObject *)multi;\n\t\n fail:\n Py_DECREF(multi);\n\treturn NULL;\n}\n\nstatic PyObject *\narraymultiter_next(PyArrayMultiIterObject *multi)\n{\n\tPyObject *ret;\n\tint i, n;\n\n\tn = multi->numiter;\n\tret = PyTuple_New(n);\n\tif (ret == NULL) return NULL;\n\tif (multi->index < multi->size) {\n\t\tfor (i=0; i < n; i++) {\n\t\t\tPyArrayIterObject *it=multi->iters[i];\n\t\t\tPyTuple_SET_ITEM(ret, i, \n\t\t\t\t\t PyArray_ToScalar(it->dataptr, it->ao));\n\t\t\tPyArray_ITER_NEXT(it);\n\t\t}\n\t\tmulti->index++;\n\t\treturn ret;\n\t}\n return NULL;\n}\n\nstatic void\narraymultiter_dealloc(PyArrayMultiIterObject *multi)\n{\n\tint i;\n\n\tfor (i=0; inumiter; i++) \n\t\tPy_XDECREF(multi->iters[i]);\n\t_pya_free(multi);\n}\n\nstatic PyObject *\narraymultiter_size_get(PyArrayMultiIterObject *self)\n{\n#if SIZEOF_INTP <= SIZEOF_LONG\n\treturn PyInt_FromLong((long) self->size);\n#else\n\tif (self->size < MAX_LONG)\n\t\treturn PyInt_FromLong((long) self->size);\n\telse\n\t\treturn PyLong_FromLongLong((longlong) self->size);\n#endif\n}\n\nstatic PyObject *\narraymultiter_index_get(PyArrayMultiIterObject *self)\n{\n#if SIZEOF_INTP <= SIZEOF_LONG\n\treturn PyInt_FromLong((long) self->index);\n#else\n\tif (self->size < MAX_LONG)\n\t\treturn PyInt_FromLong((long) self->index);\n\telse\n\t\treturn PyLong_FromLongLong((longlong) self->index);\n#endif\n}\n\nstatic PyObject *\narraymultiter_shape_get(PyArrayMultiIterObject *self)\n{\n\treturn PyArray_IntTupleFromIntp(self->nd, self->dimensions);\t\n}\n\nstatic PyObject *\narraymultiter_iters_get(PyArrayMultiIterObject *self)\n{\n\tPyObject *res;\n\tint i, n;\n\tn = self->numiter;\n\tres = PyTuple_New(n);\n\tif (res == NULL) return res;\n\tfor (i=0; iiters[i]);\n\t\tPyTuple_SET_ITEM(res, i, (PyObject *)self->iters[i]);\n\t}\n\treturn res;\n}\n\nstatic PyGetSetDef arraymultiter_getsetlist[] = {\n {\"size\", \n\t (getter)arraymultiter_size_get,\n\t NULL, \n\t \"total size of broadcasted result\"},\n {\"index\", \n\t (getter)arraymultiter_index_get, \n NULL,\n\t \"current index in broadcasted result\"},\n\t{\"shape\",\n\t (getter)arraymultiter_shape_get,\n\t NULL,\n\t \"shape of broadcasted result\"},\n\t{\"iters\",\n\t (getter)arraymultiter_iters_get,\n\t NULL,\n\t \"tuple of individual iterators\"},\n\t{NULL, NULL, NULL, NULL},\n};\n\nstatic PyMemberDef arraymultiter_members[] = {\n\t{\"numiter\", T_INT, offsetof(PyArrayMultiIterObject, numiter), \n\t RO, NULL},\n\t{\"nd\", T_INT, offsetof(PyArrayMultiIterObject, nd), RO, NULL},\n\t{NULL},\n};\n\nstatic PyObject *\narraymultiter_reset(PyArrayMultiIterObject *self, PyObject *args)\n{\n\tif (!PyArg_ParseTuple(args, \"\")) return NULL;\n\n\tPyArray_MultiIter_RESET(self);\n\tPy_INCREF(Py_None);\n\treturn Py_None;\n}\n\nstatic PyMethodDef arraymultiter_methods[] = {\n\t{\"reset\", (PyCFunction) arraymultiter_reset, METH_VARARGS, NULL},\n\t{NULL, NULL},\n};\n\nstatic PyTypeObject PyArrayMultiIter_Type = {\n PyObject_HEAD_INIT(NULL)\n 0,\t\t\t\t\t /* ob_size */\n \"numpy.broadcast\",\t\t \t /* tp_name */\n sizeof(PyArrayMultiIterObject), /* tp_basicsize */\n 0,\t\t\t\t\t /* tp_itemsize */\n /* methods */\n (destructor)arraymultiter_dealloc,\t/* tp_dealloc */\n 0,\t\t\t\t\t/* tp_print */\n 0,\t\t\t\t\t/* tp_getattr */\n 0,\t\t\t\t\t/* tp_setattr */\n 0,\t\t\t\t\t/* tp_compare */\n 0,\t\t\t\t\t/* tp_repr */\n 0,\t\t\t\t\t/* tp_as_number */\n 0, /* tp_as_sequence */\n 0, \t /* tp_as_mapping */\n 0,\t\t\t\t\t/* tp_hash */\n 0,\t\t\t\t\t/* tp_call */\n 0,\t\t\t\t\t/* tp_str */\n 0,\t \t/* tp_getattro */\n 0,\t\t\t\t\t/* tp_setattro */\n 0,\t\t\t\t\t/* tp_as_buffer */\n Py_TPFLAGS_DEFAULT, /* tp_flags */\n 0,\t\t\t\t\t/* tp_doc */\n 0, \t /* tp_traverse */\n 0,\t\t\t\t\t/* tp_clear */\n 0,\t\t\t\t\t/* tp_richcompare */\n 0,\t\t\t\t\t/* tp_weaklistoffset */\n 0, \t /* tp_iter */\n (iternextfunc)arraymultiter_next,\t/* tp_iternext */\n arraymultiter_methods, \t /* tp_methods */\n arraymultiter_members,\t \t /* tp_members */\n arraymultiter_getsetlist, /* tp_getset */\n 0,\t\t\t\t\t /* tp_base */\n 0,\t\t\t\t\t /* tp_dict */\n 0,\t\t\t\t\t /* tp_descr_get */\n 0,\t\t\t\t\t /* tp_descr_set */\n 0,\t\t\t\t\t /* tp_dictoffset */\n (initproc)0,\t \t /* tp_init */\n 0, \t /* tp_alloc */\n arraymultiter_new,\t /* tp_new */\n 0,\t /* tp_free */\n 0,\t\t\t\t\t /* tp_is_gc */\n 0,\t\t\t\t\t /* tp_bases */\n 0,\t\t\t\t\t /* tp_mro */\n 0,\t\t\t\t\t /* tp_cache */\n 0,\t\t\t\t\t /* tp_subclasses */\n 0\t\t\t\t\t /* tp_weaklist */\n};\n\n/*OBJECT_API*/\nstatic PyArray_Descr *\nPyArray_DescrNewFromType(int type_num)\n{\n\tPyArray_Descr *old;\n\tPyArray_Descr *new;\n\n\told = PyArray_DescrFromType(type_num);\n\tnew = PyArray_DescrNew(old);\n\tPy_DECREF(old);\n\treturn new;\t\n}\n\n/*** Array Descr Objects for dynamic types **/\n\n/** There are some statically-defined PyArray_Descr objects corresponding\n to the basic built-in types. \n These can and should be DECREF'd and INCREF'd as appropriate, anyway.\n If a mistake is made in reference counting, deallocation on these \n builtins will be attempted leading to problems. \n\n This let's us deal with all PyArray_Descr objects using reference\n counting (regardless of whether they are statically or dynamically \n allocated). \n**/\n\n/* base cannot be NULL */\n/*OBJECT_API*/\nstatic PyArray_Descr *\nPyArray_DescrNew(PyArray_Descr *base)\n{\n\tPyArray_Descr *new;\n\n\tnew = PyObject_New(PyArray_Descr, &PyArrayDescr_Type);\n\tif (new == NULL) return NULL;\n\t/* Don't copy PyObject_HEAD part */\n\tmemcpy((char *)new+sizeof(PyObject),\n\t (char *)base+sizeof(PyObject),\n\t sizeof(PyArray_Descr)-sizeof(PyObject));\n\n\tif (new->fields == Py_None) new->fields = NULL;\n\tPy_XINCREF(new->fields);\n\tif (new->subarray) {\n\t\tnew->subarray = _pya_malloc(sizeof(PyArray_ArrayDescr));\n\t\tmemcpy(new->subarray, base->subarray, \n\t\t sizeof(PyArray_ArrayDescr));\n\t\tPy_INCREF(new->subarray->shape);\n\t\tPy_INCREF(new->subarray->base);\n\t}\n\tPy_INCREF(new->typeobj);\n\treturn new;\n}\n\n/* should never be called for builtin-types unless \n there is a reference-count problem \n*/\nstatic void\narraydescr_dealloc(PyArray_Descr *self)\n{\n\tPy_XDECREF(self->typeobj);\n\tPy_XDECREF(self->fields);\n\tif (self->subarray) {\n\t\tPy_DECREF(self->subarray->shape);\n\t\tPy_DECREF(self->subarray->base);\n\t\t_pya_free(self->subarray);\n\t}\n\tself->ob_type->tp_free(self);\n}\n\n/* we need to be careful about setting attributes because these\n objects are pointed to by arrays that depend on them for interpreting\n data. Currently no attributes of dtype objects can be set. \n*/\nstatic PyMemberDef arraydescr_members[] = {\n\t{\"type\", T_OBJECT, offsetof(PyArray_Descr, typeobj), RO, NULL},\n\t{\"kind\", T_CHAR, offsetof(PyArray_Descr, kind), RO, NULL},\n\t{\"char\", T_CHAR, offsetof(PyArray_Descr, type), RO, NULL},\n\t{\"num\", T_INT, offsetof(PyArray_Descr, type_num), RO, NULL},\n\t{\"byteorder\", T_CHAR, offsetof(PyArray_Descr, byteorder), RO, NULL},\n\t{\"itemsize\", T_INT, offsetof(PyArray_Descr, elsize), RO, NULL},\n\t{\"alignment\", T_INT, offsetof(PyArray_Descr, alignment), RO, NULL},\n {\"hasobject\", T_UBYTE, offsetof(PyArray_Descr, hasobject), RO, NULL},\n\t{NULL}, \n};\n\nstatic PyObject *\narraydescr_subdescr_get(PyArray_Descr *self)\n{\n\tif (self->subarray == NULL) {\n\t\tPy_INCREF(Py_None);\n\t\treturn Py_None;\n\t}\n\treturn Py_BuildValue(\"OO\", (PyObject *)self->subarray->base, \n\t\t\t self->subarray->shape);\n}\n\nstatic PyObject *\narraydescr_protocol_typestr_get(PyArray_Descr *self)\n{\n char basic_=self->kind;\n char endian = self->byteorder;\n\n if (endian == '=') {\n endian = '<';\n if (!PyArray_IsNativeByteOrder(endian)) endian = '>';\n }\n\n return PyString_FromFormat(\"%c%c%d\", endian, basic_,\n self->elsize);\n}\n\nstatic PyObject *\narraydescr_typename_get(PyArray_Descr *self)\n{\n int len;\n PyTypeObject *typeobj = self->typeobj;\n\tPyObject *res;\n\n\t/* Both are equivalents, but second is more resistent to changes */\n/* \tlen = strlen(typeobj->tp_name) - 8; */\n\n\tif (PyTypeNum_ISUSERDEF(self->type_num)) {\n\t\tres = PyString_FromString(typeobj->tp_name);\n\t}\n\telse {\n\t\tlen = strchr(typeobj->tp_name, (int)'_')-(typeobj->tp_name);\n\t\tres = PyString_FromStringAndSize(typeobj->tp_name, len);\n\t}\n\tif (PyTypeNum_ISEXTENDED(self->type_num) && self->elsize != 0) {\n\t\tPyObject *p;\n\t\tp = PyString_FromFormat(\"%d\", self->elsize * 8);\n\t\tPyString_ConcatAndDel(&res, p);\n\t}\n\treturn res;\t\t\t\t\t\t \n}\n\nstatic PyObject *\narraydescr_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\t{\"name\",\n\t (getter)arraydescr_typename_get,\n\t NULL,\n\t \"The array_protocol typename.\"},\n\t{\"isbuiltin\",\n\t (getter)arraydescr_isbuiltin_get,\n\t NULL,\n\t \"Is this a buillt-in data-type descriptor?\"},\n\t{\"isnative\",\n\t (getter)arraydescr_isnative_get,\n\t NULL,\n\t \"Is the byte-order of this descriptor native?\"},\n\t{\"fields\",\n\t (getter)arraydescr_fields_get,\n\t NULL,\n\t NULL},\n\t{NULL, NULL, NULL, NULL},\n};\n\nstatic PyArray_Descr *_convert_from_list(PyObject *obj, int align, int try_descr);\nstatic PyArray_Descr *_convert_from_dict(PyObject *obj, int align);\nstatic PyArray_Descr *_convert_from_commastring(PyObject *obj, int align);\nstatic PyArray_Descr *_convert_from_array_descr(PyObject *obj);\n\nstatic PyObject *\narraydescr_new(PyTypeObject *subtype, PyObject *args, PyObject *kwds)\n{\n\tPyObject *odescr;\n\tPyArray_Descr *descr, *conv;\n\tint align=0;\n\tBool copy=FALSE;\n\tstatic char *kwlist[] = {\"dtype\", \"align\", \"copy\", NULL};\n\t\n\tif (!PyArg_ParseTupleAndKeywords(args, kwds, \"O|iO&\",\n\t\t\t\t\t kwlist, &odescr, &align,\n\t\t\t\t\t PyArray_BoolConverter, ©))\n\t\treturn NULL;\n\t\n\tif (align) {\n\t\tconv = NULL;\n\t\tif PyDict_Check(odescr) \n\t\t\tconv = _convert_from_dict(odescr, 1);\n\t\telse if PyList_Check(odescr) \n\t\t\tconv = _convert_from_list(odescr, 1, 0);\n\t\telse if PyString_Check(odescr)\n\t\t\tconv = _convert_from_commastring(odescr, 1);\n\t\telse {\n\t\t\tPyErr_SetString(PyExc_ValueError, \n\t\t\t\t\t\"align can only be non-zero for\" \\\n\t\t\t\t\t\"dictionary, list, and string objects.\");\n\t\t}\n\t\tif (conv) return (PyObject *)conv;\n\t\tif (!PyErr_Occurred()) {\n\t\t\tPyErr_SetString(PyExc_ValueError,\n\t\t\t\t\t\"data-type-descriptor not understood\");\n\t\t}\n\t\treturn NULL;\n\t}\n\n\tif PyList_Check(odescr) {\n\t\tconv = _convert_from_array_descr(odescr);\n\t\tif (!conv) {\n\t\t\tPyErr_Clear();\n\t\t\tconv = _convert_from_list(odescr, 0, 0);\n\t\t}\n\t\treturn (PyObject *)conv;\n\t}\n\n\tif (!PyArray_DescrConverter(odescr, &conv)) \n\t\treturn NULL;\n\t/* Get a new copy of it unless it's already a copy */\n\tif (copy && conv->fields == Py_None) {\n\t\tdescr = PyArray_DescrNew(conv);\n\t\tPy_DECREF(conv);\n\t\tconv = descr;\n\t}\n\treturn (PyObject *)conv;\n}\n\nstatic char doc_arraydescr_reduce[] = \"self.__reduce__() for pickling.\";\n\n/* return a tuple of (callable object, args, state) */\nstatic PyObject *\narraydescr_reduce(PyArray_Descr *self, PyObject *args)\n{\n\tPyObject *ret, *mod, *obj;\n\tPyObject *state;\n\tchar endian;\n\tint elsize, alignment;\n\n\tret = PyTuple_New(3);\n\tif (ret == NULL) return NULL;\n\tmod = PyImport_ImportModule(\"numpy.core.multiarray\");\n\tif (mod == NULL) {Py_DECREF(ret); return NULL;}\n\tobj = PyObject_GetAttrString(mod, \"dtype\");\n\tPy_DECREF(mod);\n\tif (obj == NULL) {Py_DECREF(ret); return NULL;}\n\tPyTuple_SET_ITEM(ret, 0, obj);\n\tif (PyTypeNum_ISUSERDEF(self->type_num) ||\t\t\\\n\t ((self->type_num == PyArray_VOID &&\t\t\t\\\n\t self->typeobj != &PyVoidArrType_Type))) {\n\t\tobj = (PyObject *)self->typeobj;\n\t\tPy_INCREF(obj);\n\t}\n\telse {\n\t\tobj = PyString_FromFormat(\"%c%d\",self->kind, self->elsize);\n\t}\n\tPyTuple_SET_ITEM(ret, 1, Py_BuildValue(\"(Nii)\", obj, 0, 1));\n\t\n\t/* Now return the state which is at least \n\t byteorder, subarray, and fields */\n\tendian = self->byteorder;\n\tif (endian == '=') {\n\t\tendian = '<';\n\t\tif (!PyArray_IsNativeByteOrder(endian)) endian = '>';\n\t}\n\tstate = PyTuple_New(5);\n\tPyTuple_SET_ITEM(state, 0, PyString_FromFormat(\"%c\", endian));\n\tPyTuple_SET_ITEM(state, 1, arraydescr_subdescr_get(self));\n\tif (self->fields && self->fields != Py_None) {\n\t\tPy_INCREF(self->fields);\n\t\tPyTuple_SET_ITEM(state, 2, self->fields);\n\t}\n\telse {\n\t\tPyTuple_SET_ITEM(state, 2, Py_None);\n\t\tPy_INCREF(Py_None);\n\t}\n\n\t/* for extended types it also includes elsize and alignment */\n\tif (PyTypeNum_ISEXTENDED(self->type_num)) {\n\t\telsize = self->elsize;\n\t\talignment = self->alignment;\n\t}\n\telse {elsize = -1; alignment = -1;}\n\n\tPyTuple_SET_ITEM(state, 3, PyInt_FromLong(elsize));\n\tPyTuple_SET_ITEM(state, 4, PyInt_FromLong(alignment));\n\n\tPyTuple_SET_ITEM(ret, 2, state);\n\treturn ret;\n}\n\n/* state is at least byteorder, subarray, and fields but could include elsize \n and alignment for EXTENDED arrays \n*/\nstatic char doc_arraydescr_setstate[] = \"self.__setstate__() for pickling.\";\n\nstatic PyObject *\narraydescr_setstate(PyArray_Descr *self, PyObject *args)\n{\n\tint elsize = -1, alignment = -1;\n\tchar endian;\n\tPyObject *subarray, *fields;\n\n\tif (self->fields == Py_None) {Py_INCREF(Py_None); return Py_None;}\n\n\tif (!PyArg_ParseTuple(args, \"(cOOii)\", &endian, &subarray, &fields,\n\t\t\t &elsize, &alignment)) return NULL;\n\t\n\tif (PyArray_IsNativeByteOrder(endian)) endian = '=';\n\n\tself->byteorder = endian;\n\tif (self->subarray) {\n\t\tPy_XDECREF(self->subarray->base);\n\t\tPy_XDECREF(self->subarray->shape);\n\t\t_pya_free(self->subarray);\n\t}\n\tself->subarray = NULL;\n\n\tif (subarray != Py_None) {\n\t\tself->subarray = _pya_malloc(sizeof(PyArray_ArrayDescr));\n\t\tself->subarray->base = (PyArray_Descr *)PyTuple_GET_ITEM(subarray, 0);\n\t\tPy_INCREF(self->subarray->base);\n\t\tself->subarray->shape = PyTuple_GET_ITEM(subarray, 1);\n\t\tPy_INCREF(self->subarray->shape);\n\t}\n\t\n\tif (fields != Py_None) {\n\t\tPy_XDECREF(self->fields);\n\t\tself->fields = fields;\n\t\tPy_INCREF(fields);\n\t}\n\t\n\tif (PyTypeNum_ISEXTENDED(self->type_num)) {\n\t\tself->elsize = elsize;\n\t\tself->alignment = alignment;\n\t}\n\t\n\tPy_INCREF(Py_None);\n\treturn Py_None;\n}\n\n\n/* returns a copy of the PyArray_Descr structure with the byteorder\n altered:\n no arguments: The byteorder is swapped (in all subfields as well)\n single argument: The byteorder is forced to the given state\n (in all subfields as well)\n\n Valid states: ('big', '>') or ('little' or '<')\n\t\t ('native', or '=')\n\n\t\t If a descr structure with | is encountered it's own\n\t\t byte-order is not changed but any fields are: \n*/\n\n/*OBJECT_API\n Deep bytorder change of a data-type descriptor\n*/\nstatic PyArray_Descr *\nPyArray_DescrNewByteorder(PyArray_Descr *self, char newendian)\n{\n\tPyArray_Descr *new;\n\tchar endian;\n\n\tnew = PyArray_DescrNew(self);\n\tendian = new->byteorder;\n\tif (endian != PyArray_IGNORE) {\n\t\tif (newendian == PyArray_SWAP) { /* swap byteorder */\n\t\t\tif PyArray_ISNBO(endian) endian = PyArray_OPPBYTE;\n\t\t\telse endian = PyArray_NATBYTE;\n\t\t\tnew->byteorder = endian;\n\t\t}\n\t\telse if (newendian != PyArray_IGNORE) {\n\t\t\tnew->byteorder = newendian;\n\t\t}\n\t}\n\tif (new->fields) {\n\t\tPyObject *newfields;\n\t\tPyObject *key, *value;\n\t\tPyObject *newvalue;\n\t\tPyObject *old;\n\t\tPyArray_Descr *newdescr;\n\t\tint pos = 0, len, i;\n\t\tnewfields = PyDict_New();\n\t\t/* make new dictionary with replaced */\n\t\t/* PyArray_Descr Objects */\n\t\twhile(PyDict_Next(self->fields, &pos, &key, &value)) {\n\t\t\tif (PyInt_Check(key) &&\t\t\t\\\n\t\t\t PyInt_AsLong(key) == -1) {\n\t\t\t\tPyDict_SetItem(newfields, key, value);\n\t\t\t\tcontinue;\n\t\t\t}\n\t\t\tif (!PyString_Check(key) ||\t \\\n\t\t\t !PyTuple_Check(value) ||\t\t\t\\\n\t\t\t ((len=PyTuple_GET_SIZE(value)) < 2))\n\t\t\t\tcontinue;\n\t\t\t\n\t\t\told = PyTuple_GET_ITEM(value, 0);\n\t\t\tif (!PyArray_DescrCheck(old)) continue;\n\t\t\tnewdescr = PyArray_DescrNewByteorder\t\t\\\n\t\t\t\t((PyArray_Descr *)old, newendian);\n\t\t\tif (newdescr == NULL) {\n\t\t\t\tPy_DECREF(newfields); Py_DECREF(new);\n\t\t\t\treturn NULL;\n\t\t\t}\n\t\t\tnewvalue = PyTuple_New(len);\n\t\t\tPyTuple_SET_ITEM(newvalue, 0,\t\t\\\n\t\t\t\t\t (PyObject *)newdescr);\n\t\t\tfor(i=1; ifields);\n\t\tnew->fields = newfields;\n\t}\n\tif (new->subarray) {\n\t\tPy_DECREF(new->subarray->base);\n\t\tnew->subarray->base = PyArray_DescrNewByteorder \\\n\t\t\t(self->subarray->base, newendian);\n\t}\n\treturn new;\n}\n\n\nstatic char doc_arraydescr_newbyteorder[] = \"self.newbyteorder()\"\n\t\" returns a copy of the dtype object\\n\"\n\t\" with altered byteorders. If is not given all byteorders\\n\"\n\t\" are swapped. Otherwise endian can be '>', '<', or '=' to force\\n\"\n\t\" a byteorder. Descriptors in all fields are also updated in the\\n\"\n\t\" new dtype object.\";\n\nstatic PyObject *\narraydescr_newbyteorder(PyArray_Descr *self, PyObject *args) \n{\n\tchar endian=PyArray_SWAP;\n\t\n\tif (!PyArg_ParseTuple(args, \"|O&\", PyArray_ByteorderConverter,\n\t\t\t &endian)) return NULL;\n\t\t\t\n\treturn (PyObject *)PyArray_DescrNewByteorder(self, endian);\n}\n\nstatic PyMethodDef arraydescr_methods[] = {\n /* for pickling */\n {\"__reduce__\", (PyCFunction)arraydescr_reduce, METH_VARARGS, \n\t doc_arraydescr_reduce},\n\t{\"__setstate__\", (PyCFunction)arraydescr_setstate, METH_VARARGS,\n\t doc_arraydescr_setstate},\n\n\t{\"newbyteorder\", (PyCFunction)arraydescr_newbyteorder, METH_VARARGS,\n\t doc_arraydescr_newbyteorder},\n {NULL,\t\tNULL}\t\t/* sentinel */\n};\n\nstatic PyObject *\narraydescr_str(PyArray_Descr *self)\n{\n\tPyObject *sub;\n\n\tif (self->fields && self->fields != Py_None) {\n\t\tPyObject *lst;\n\t\tlst = arraydescr_protocol_descr_get(self);\n\t\tif (!lst) {\n\t\t\tsub = PyString_FromString(\"\");\n\t\t\tPyErr_Clear();\n\t\t}\n\t\telse sub = PyObject_Str(lst);\n\t\tPy_XDECREF(lst);\n\t\tif (self->type_num != PyArray_VOID) {\n\t\t\tPyObject *p;\n\t\t\tPyObject *t=PyString_FromString(\"'\");\n\t\t\tp = arraydescr_protocol_typestr_get(self);\n\t\t\tPyString_Concat(&p, t);\n\t\t\tPyString_ConcatAndDel(&t, p);\n\t\t\tp = PyString_FromString(\"(\");\n\t\t\tPyString_ConcatAndDel(&p, t);\n\t\t\tPyString_ConcatAndDel(&p, PyString_FromString(\", \"));\n\t\t\tPyString_ConcatAndDel(&p, sub);\n\t\t\tPyString_ConcatAndDel(&p, PyString_FromString(\")\"));\n\t\t\tsub = p;\n\t\t}\n\t}\n\telse if (self->subarray) {\n\t\tPyObject *p;\n\t\tPyObject *t = PyString_FromString(\"(\");\n\t\tp = arraydescr_str(self->subarray->base);\n\t\tPyString_ConcatAndDel(&t, p);\n\t\tPyString_ConcatAndDel(&t, PyString_FromString(\",\"));\n\t\tPyString_ConcatAndDel(&t, PyObject_Str(self->subarray->shape));\n\t\tPyString_ConcatAndDel(&t, PyString_FromString(\")\"));\n\t\tsub = t;\n\t}\n\telse {\n\t\tPyObject *t=PyString_FromString(\"'\");\n\t\tsub = arraydescr_protocol_typestr_get(self);\n\t\tPyString_Concat(&sub, t);\n\t\tPyString_ConcatAndDel(&t, sub);\n\t\tsub = t;\n\t}\n\treturn sub;\n}\n\nstatic PyObject *\narraydescr_repr(PyArray_Descr *self)\n{\n\tPyObject *sub, *s;\n\ts = PyString_FromString(\"dtype(\");\n sub = arraydescr_str(self);\n\tPyString_ConcatAndDel(&s, sub);\n\tsub = PyString_FromString(\")\");\n\tPyString_ConcatAndDel(&s, sub);\n\treturn s;\n}\n\nstatic int\narraydescr_compare(PyArray_Descr *self, PyObject *other)\n{\n \tif (!PyArray_DescrCheck(other)) {\n\t\tPyErr_SetString(PyExc_TypeError,\n\t\t\t\t\"not a dtype object.\");\n\t\treturn -1;\n\t}\n\tif (PyArray_EquivTypes(self, (PyArray_Descr *)other)) return 0;\n\tif (PyArray_CanCastTo(self, (PyArray_Descr *)other)) return -1;\n\treturn 1;\n}\n\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 0, \t /* tp_as_mapping */\n 0,\t\t\t\t\t/* tp_hash */\n 0,\t\t\t\t\t/* tp_call */\n (reprfunc)arraydescr_str, /* tp_str */\n 0,\t \t/* tp_getattro */\n 0,\t\t\t\t\t/* tp_setattro */\n 0,\t\t\t\t\t/* tp_as_buffer */\n Py_TPFLAGS_DEFAULT, /* tp_flags */\n 0,\t\t\t\t\t/* tp_doc */\n 0, \t /* tp_traverse */\n 0,\t\t\t\t\t/* tp_clear */\n 0,\t\t\t\t\t/* tp_richcompare */\n 0,\t\t\t\t\t/* tp_weaklistoffset */\n 0, \t /* tp_iter */\n 0,\t \t/* tp_iternext */\n arraydescr_methods,\t \t /* tp_methods */\n arraydescr_members,\t /* tp_members */\n arraydescr_getsets, /* tp_getset */\n 0,\t\t\t\t\t /* tp_base */\n 0,\t\t\t\t\t /* tp_dict */\n 0,\t\t\t\t\t /* tp_descr_get */\n 0,\t\t\t\t\t /* tp_descr_set */\n 0,\t\t\t\t\t /* tp_dictoffset */\n 0, \t \t /* tp_init */\n 0, \t /* tp_alloc */\n arraydescr_new,\t /* tp_new */\n 0,\t /* tp_free */\n 0,\t\t\t\t\t /* tp_is_gc */\n 0,\t\t\t\t\t /* tp_bases */\n 0,\t\t\t\t\t /* tp_mro */\n 0,\t\t\t\t\t /* tp_cache */\n 0,\t\t\t\t\t /* tp_subclasses */\n 0\t\t\t\t\t /* tp_weaklist */\n};\n", + "methods": [ + { + "name": "PyArray_GetPriority", + "long_name": "PyArray_GetPriority( PyObject * obj , double default_)", + "filename": "arrayobject.c", + "nloc": 17, + "complexity": 5, + "token_count": 86, + "parameters": [ + "obj", + "default_" + ], + "start_line": 28, + "end_line": 46, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 19, + "top_nesting_level": 0 + }, + { + "name": "PyArray_Zero", + "long_name": "PyArray_Zero( PyArrayObject * arr)", + "filename": "arrayobject.c", + "nloc": 27, + "complexity": 4, + "token_count": 148, + "parameters": [ + "arr" + ], + "start_line": 67, + "end_line": 95, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 29, + "top_nesting_level": 0 + }, + { + "name": "PyArray_One", + "long_name": "PyArray_One( PyArrayObject * arr)", + "filename": "arrayobject.c", + "nloc": 27, + "complexity": 4, + "token_count": 148, + "parameters": [ + "arr" + ], + "start_line": 101, + "end_line": 130, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 30, + "top_nesting_level": 0 + }, + { + "name": "do_sliced_copy", + "long_name": "do_sliced_copy( char * dest , intp * dest_strides , intp * dest_dimensions , int dest_nd , char * src , intp * src_strides , intp * src_dimensions , int src_nd , int elsize , int copies)", + "filename": "arrayobject.c", + "nloc": 48, + "complexity": 13, + "token_count": 313, + "parameters": [ + "dest", + "dest_strides", + "dest_dimensions", + "dest_nd", + "src", + "src_strides", + "src_dimensions", + "src_nd", + "elsize", + "copies" + ], + "start_line": 136, + "end_line": 186, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 51, + "top_nesting_level": 0 + }, + { + "name": "optimize_slices", + "long_name": "optimize_slices( intp ** dest_strides , intp ** dest_dimensions , int * dest_nd , intp ** src_strides , intp ** src_dimensions , int * src_nd , int * elsize , int * copies)", + "filename": "arrayobject.c", + "nloc": 32, + "complexity": 8, + "token_count": 214, + "parameters": [ + "dest_strides", + "dest_dimensions", + "dest_nd", + "src_strides", + "src_dimensions", + "src_nd", + "elsize", + "copies" + ], + "start_line": 209, + "end_line": 240, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 32, + "top_nesting_level": 0 + }, + { + "name": "contiguous_data", + "long_name": "contiguous_data( PyArrayObject * src)", + "filename": "arrayobject.c", + "nloc": 29, + "complexity": 4, + "token_count": 215, + "parameters": [ + "src" + ], + "start_line": 243, + "end_line": 277, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 35, + "top_nesting_level": 0 + }, + { + "name": "PyArray_INCREF", + "long_name": "PyArray_INCREF( PyArrayObject * mp)", + "filename": "arrayobject.c", + "nloc": 17, + "complexity": 6, + "token_count": 125, + "parameters": [ + "mp" + ], + "start_line": 293, + "end_line": 315, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 23, + "top_nesting_level": 0 + }, + { + "name": "PyArray_XDECREF", + "long_name": "PyArray_XDECREF( PyArrayObject * mp)", + "filename": "arrayobject.c", + "nloc": 17, + "complexity": 6, + "token_count": 125, + "parameters": [ + "mp" + ], + "start_line": 321, + "end_line": 342, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 22, + "top_nesting_level": 0 + }, + { + "name": "byte_swap_vector", + "long_name": "byte_swap_vector( * p , int n , int size)", + "filename": "arrayobject.c", + "nloc": 38, + "complexity": 10, + "token_count": 340, + "parameters": [ + "p", + "n", + "size" + ], + "start_line": 346, + "end_line": 384, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 39, + "top_nesting_level": 0 + }, + { + "name": "copy_and_swap", + "long_name": "copy_and_swap( * dst , * src , int itemsize , intp numitems , intp srcstrides , int swap)", + "filename": "arrayobject.c", + "nloc": 18, + "complexity": 5, + "token_count": 120, + "parameters": [ + "dst", + "src", + "itemsize", + "numitems", + "srcstrides", + "swap" + ], + "start_line": 389, + "end_line": 409, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 21, + "top_nesting_level": 0 + }, + { + "name": "PyArray_PyIntAsIntp", + "long_name": "PyArray_PyIntAsIntp( PyObject * o)", + "filename": "arrayobject.c", + "nloc": 71, + "complexity": 21, + "token_count": 413, + "parameters": [ + "o" + ], + "start_line": 423, + "end_line": 505, + "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": 512, + "end_line": 586, + "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": 589, + "end_line": 604, + "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": 610, + "end_line": 618, + "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": 634, + "end_line": 714, + "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": 718, + "end_line": 732, + "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": 745, + "end_line": 771, + "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": 777, + "end_line": 791, + "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": 800, + "end_line": 820, + "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": 81, + "complexity": 12, + "token_count": 483, + "parameters": [ + "data", + "descr", + "base" + ], + "start_line": 829, + "end_line": 913, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 85, + "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": 929, + "end_line": 932, + "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": 942, + "end_line": 964, + "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": 978, + "end_line": 1018, + "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": 1033, + "end_line": 1074, + "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": 1081, + "end_line": 1172, + "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": 1178, + "end_line": 1207, + "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": 1210, + "end_line": 1246, + "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": 1255, + "end_line": 1292, + "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": 1299, + "end_line": 1307, + "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": 1310, + "end_line": 1335, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 26, + "top_nesting_level": 0 + }, + { + "name": "array_item_nice", + "long_name": "array_item_nice( PyArrayObject * self , int i)", + "filename": "arrayobject.c", + "nloc": 4, + "complexity": 1, + "token_count": 29, + "parameters": [ + "self", + "i" + ], + "start_line": 1338, + "end_line": 1341, + "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": 1345, + "end_line": 1380, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 36, + "top_nesting_level": 0 + }, + { + "name": "array_ass_item", + "long_name": "array_ass_item( PyArrayObject * self , int i , PyObject * v)", + "filename": "arrayobject.c", + "nloc": 4, + "complexity": 1, + "token_count": 28, + "parameters": [ + "self", + "i", + "v" + ], + "start_line": 1386, + "end_line": 1389, + "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": 1395, + "end_line": 1403, + "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": 1409, + "end_line": 1459, + "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": 1466, + "end_line": 1511, + "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": 1515, + "end_line": 1609, + "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": 1612, + "end_line": 1649, + "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": 1661, + "end_line": 1714, + "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": 1717, + "end_line": 1777, + "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": 1780, + "end_line": 1807, + "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": 1810, + "end_line": 1829, + "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": 1841, + "end_line": 1903, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 63, + "top_nesting_level": 0 + }, + { + "name": "array_subscript", + "long_name": "array_subscript( PyArrayObject * self , PyObject * op)", + "filename": "arrayobject.c", + "nloc": 103, + "complexity": 28, + "token_count": 666, + "parameters": [ + "self", + "op" + ], + "start_line": 1927, + "end_line": 2045, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 119, + "top_nesting_level": 0 + }, + { + "name": "array_ass_sub", + "long_name": "array_ass_sub( PyArrayObject * self , PyObject * index , PyObject * op)", + "filename": "arrayobject.c", + "nloc": 93, + "complexity": 28, + "token_count": 588, + "parameters": [ + "self", + "index", + "op" + ], + "start_line": 2060, + "end_line": 2165, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 106, + "top_nesting_level": 0 + }, + { + "name": "array_subscript_nice", + "long_name": "array_subscript_nice( PyArrayObject * self , PyObject * op)", + "filename": "arrayobject.c", + "nloc": 4, + "complexity": 1, + "token_count": 27, + "parameters": [ + "self", + "op" + ], + "start_line": 2174, + "end_line": 2177, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 4, + "top_nesting_level": 0 + }, + { + "name": "array_getsegcount", + "long_name": "array_getsegcount( PyArrayObject * self , int * lenp)", + "filename": "arrayobject.c", + "nloc": 11, + "complexity": 4, + "token_count": 48, + "parameters": [ + "self", + "lenp" + ], + "start_line": 2196, + "end_line": 2208, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 13, + "top_nesting_level": 0 + }, + { + "name": "array_getreadbuf", + "long_name": "array_getreadbuf( PyArrayObject * self , int segment , ** ptrptr)", + "filename": "arrayobject.c", + "nloc": 15, + "complexity": 3, + "token_count": 72, + "parameters": [ + "self", + "segment", + "ptrptr" + ], + "start_line": 2211, + "end_line": 2226, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 16, + "top_nesting_level": 0 + }, + { + "name": "array_getwritebuf", + "long_name": "array_getwritebuf( PyArrayObject * self , int segment , ** ptrptr)", + "filename": "arrayobject.c", + "nloc": 10, + "complexity": 2, + "token_count": 54, + "parameters": [ + "self", + "segment", + "ptrptr" + ], + "start_line": 2230, + "end_line": 2239, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 10, + "top_nesting_level": 0 + }, + { + "name": "array_getcharbuf", + "long_name": "array_getcharbuf( PyArrayObject * self , int segment , const char ** ptrptr)", + "filename": "arrayobject.c", + "nloc": 12, + "complexity": 3, + "token_count": 65, + "parameters": [ + "self", + "segment", + "ptrptr" + ], + "start_line": 2242, + "end_line": 2253, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 12, + "top_nesting_level": 0 + }, + { + "name": "PyArray_SetNumericOps", + "long_name": "PyArray_SetNumericOps( PyObject * dict)", + "filename": "arrayobject.c", + "nloc": 34, + "complexity": 1, + "token_count": 162, + "parameters": [ + "dict" + ], + "start_line": 2324, + "end_line": 2357, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 34, + "top_nesting_level": 0 + }, + { + "name": "PyArray_GetNumericOps", + "long_name": "PyArray_GetNumericOps()", + "filename": "arrayobject.c", + "nloc": 39, + "complexity": 2, + "token_count": 183, + "parameters": [], + "start_line": 2367, + "end_line": 2406, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 40, + "top_nesting_level": 0 + }, + { + "name": "PyArray_GenericReduceFunction", + "long_name": "PyArray_GenericReduceFunction( PyArrayObject * m1 , PyObject * op , int axis , int rtype)", + "filename": "arrayobject.c", + "nloc": 24, + "complexity": 5, + "token_count": 141, + "parameters": [ + "m1", + "op", + "axis", + "rtype" + ], + "start_line": 2409, + "end_line": 2432, + "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": 2436, + "end_line": 2459, + "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": 2463, + "end_line": 2470, + "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": 2473, + "end_line": 2480, + "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": 2483, + "end_line": 2491, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 9, + "top_nesting_level": 0 + }, + { + "name": "array_add", + "long_name": "array_add( PyArrayObject * m1 , PyObject * m2)", + "filename": "arrayobject.c", + "nloc": 4, + "complexity": 1, + "token_count": 24, + "parameters": [ + "m1", + "m2" + ], + "start_line": 2494, + "end_line": 2497, + "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": 2500, + "end_line": 2503, + "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": 2506, + "end_line": 2509, + "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": 2512, + "end_line": 2515, + "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": 2518, + "end_line": 2521, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 4, + "top_nesting_level": 0 + }, + { + "name": "array_power", + "long_name": "array_power( PyArrayObject * m1 , PyObject * m2)", + "filename": "arrayobject.c", + "nloc": 4, + "complexity": 1, + "token_count": 24, + "parameters": [ + "m1", + "m2" + ], + "start_line": 2524, + "end_line": 2527, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 4, + "top_nesting_level": 0 + }, + { + "name": "array_negative", + "long_name": "array_negative( PyArrayObject * m1)", + "filename": "arrayobject.c", + "nloc": 4, + "complexity": 1, + "token_count": 18, + "parameters": [ + "m1" + ], + "start_line": 2530, + "end_line": 2533, + "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": 2536, + "end_line": 2539, + "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": 2542, + "end_line": 2545, + "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": 2548, + "end_line": 2551, + "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": 2554, + "end_line": 2557, + "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": 2560, + "end_line": 2563, + "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": 2566, + "end_line": 2569, + "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": 2572, + "end_line": 2575, + "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": 2578, + "end_line": 2581, + "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": 2584, + "end_line": 2587, + "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": 2590, + "end_line": 2593, + "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": 2596, + "end_line": 2599, + "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": 2602, + "end_line": 2605, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 4, + "top_nesting_level": 0 + }, + { + "name": "array_inplace_power", + "long_name": "array_inplace_power( PyArrayObject * m1 , PyObject * m2)", + "filename": "arrayobject.c", + "nloc": 4, + "complexity": 1, + "token_count": 24, + "parameters": [ + "m1", + "m2" + ], + "start_line": 2608, + "end_line": 2611, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 4, + "top_nesting_level": 0 + }, + { + "name": "array_inplace_left_shift", + "long_name": "array_inplace_left_shift( PyArrayObject * m1 , PyObject * m2)", + "filename": "arrayobject.c", + "nloc": 4, + "complexity": 1, + "token_count": 24, + "parameters": [ + "m1", + "m2" + ], + "start_line": 2614, + "end_line": 2617, + "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": 2620, + "end_line": 2623, + "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": 2626, + "end_line": 2629, + "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": 2632, + "end_line": 2635, + "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": 2638, + "end_line": 2641, + "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": 2644, + "end_line": 2647, + "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": 2650, + "end_line": 2653, + "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": 2656, + "end_line": 2660, + "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": 2663, + "end_line": 2667, + "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": 2671, + "end_line": 2689, + "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": 2692, + "end_line": 2709, + "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": 2714, + "end_line": 2729, + "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": 2733, + "end_line": 2759, + "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": 2762, + "end_line": 2787, + "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": 2790, + "end_line": 2812, + "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": 2815, + "end_line": 2837, + "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": 2840, + "end_line": 2862, + "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": 2865, + "end_line": 2869, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 5, + "top_nesting_level": 0 + }, + { + "name": "array_slice", + "long_name": "array_slice( PyArrayObject * self , int ilow , int ihigh)", + "filename": "arrayobject.c", + "nloc": 36, + "complexity": 11, + "token_count": 259, + "parameters": [ + "self", + "ilow", + "ihigh" + ], + "start_line": 2930, + "end_line": 2970, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 41, + "top_nesting_level": 0 + }, + { + "name": "array_ass_slice", + "long_name": "array_ass_slice( PyArrayObject * self , int ilow , int ihigh , PyObject * v)", + "filename": "arrayobject.c", + "nloc": 20, + "complexity": 4, + "token_count": 108, + "parameters": [ + "self", + "ilow", + "ihigh", + "v" + ], + "start_line": 2974, + "end_line": 2995, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 22, + "top_nesting_level": 0 + }, + { + "name": "array_contains", + "long_name": "array_contains( PyArrayObject * self , PyObject * el)", + "filename": "arrayobject.c", + "nloc": 10, + "complexity": 2, + "token_count": 66, + "parameters": [ + "self", + "el" + ], + "start_line": 2998, + "end_line": 3010, + "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": 3031, + "end_line": 3078, + "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": 3081, + "end_line": 3117, + "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": 3126, + "end_line": 3143, + "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": 3146, + "end_line": 3158, + "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": 3161, + "end_line": 3173, + "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": 73, + "complexity": 15, + "token_count": 325, + "parameters": [ + "self", + "other", + "cmp_op" + ], + "start_line": 3176, + "end_line": 3265, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 90, + "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": 3268, + "end_line": 3297, + "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": 3303, + "end_line": 3323, + "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": 3331, + "end_line": 3366, + "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": 3372, + "end_line": 3391, + "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": 3395, + "end_line": 3413, + "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": 3416, + "end_line": 3433, + "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": 3436, + "end_line": 3469, + "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": 3476, + "end_line": 3503, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 28, + "top_nesting_level": 0 + }, + { + "name": "PyArray_CheckStrides", + "long_name": "PyArray_CheckStrides( int elsize , int nd , intp numbytes , intp * dims , intp * newstrides)", + "filename": "arrayobject.c", + "nloc": 13, + "complexity": 4, + "token_count": 84, + "parameters": [ + "elsize", + "nd", + "numbytes", + "dims", + "newstrides" + ], + "start_line": 3512, + "end_line": 3527, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 16, + "top_nesting_level": 0 + }, + { + "name": "_array_fill_strides", + "long_name": "_array_fill_strides( intp * strides , intp * dims , int nd , intp itemsize , int inflag , int * objflags)", + "filename": "arrayobject.c", + "nloc": 24, + "complexity": 9, + "token_count": 171, + "parameters": [ + "strides", + "dims", + "nd", + "itemsize", + "inflag", + "objflags" + ], + "start_line": 3547, + "end_line": 3571, + "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": 3577, + "end_line": 3599, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 23, + "top_nesting_level": 0 + }, + { + "name": "_update_descr_and_dimensions", + "long_name": "_update_descr_and_dimensions( PyArray_Descr ** des , intp * newdims , intp * newstrides , int oldnd)", + "filename": "arrayobject.c", + "nloc": 37, + "complexity": 6, + "token_count": 229, + "parameters": [ + "des", + "newdims", + "newstrides", + "oldnd" + ], + "start_line": 3603, + "end_line": 3645, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 43, + "top_nesting_level": 0 + }, + { + "name": "PyArray_NewFromDescr", + "long_name": "PyArray_NewFromDescr( PyTypeObject * subtype , PyArray_Descr * descr , int nd , intp * dims , intp * strides , * data , int flags , PyObject * obj)", + "filename": "arrayobject.c", + "nloc": 136, + "complexity": 27, + "token_count": 781, + "parameters": [ + "subtype", + "descr", + "nd", + "dims", + "strides", + "data", + "flags", + "obj" + ], + "start_line": 3653, + "end_line": 3818, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 166, + "top_nesting_level": 0 + }, + { + "name": "PyArray_Resize", + "long_name": "PyArray_Resize( PyArrayObject * self , PyArray_Dims * newshape)", + "filename": "arrayobject.c", + "nloc": 82, + "complexity": 15, + "token_count": 497, + "parameters": [ + "self", + "newshape" + ], + "start_line": 3827, + "end_line": 3925, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 99, + "top_nesting_level": 0 + }, + { + "name": "PyArray_FillObjectArray", + "long_name": "PyArray_FillObjectArray( PyArrayObject * arr , PyObject * obj)", + "filename": "arrayobject.c", + "nloc": 18, + "complexity": 4, + "token_count": 98, + "parameters": [ + "arr", + "obj" + ], + "start_line": 3931, + "end_line": 3948, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 18, + "top_nesting_level": 0 + }, + { + "name": "PyArray_FillWithScalar", + "long_name": "PyArray_FillWithScalar( PyArrayObject * arr , PyObject * obj)", + "filename": "arrayobject.c", + "nloc": 41, + "complexity": 6, + "token_count": 231, + "parameters": [ + "arr", + "obj" + ], + "start_line": 3952, + "end_line": 3994, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 43, + "top_nesting_level": 0 + }, + { + "name": "array_new", + "long_name": "array_new( PyTypeObject * subtype , PyObject * args , PyObject * kwds)", + "filename": "arrayobject.c", + "nloc": 103, + "complexity": 19, + "token_count": 583, + "parameters": [ + "subtype", + "args", + "kwds" + ], + "start_line": 3997, + "end_line": 4116, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 120, + "top_nesting_level": 0 + }, + { + "name": "array_iter", + "long_name": "array_iter( PyArrayObject * arr)", + "filename": "arrayobject.c", + "nloc": 9, + "complexity": 2, + "token_count": 38, + "parameters": [ + "arr" + ], + "start_line": 4120, + "end_line": 4128, + "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": 4134, + "end_line": 4137, + "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": 4140, + "end_line": 4144, + "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": 4147, + "end_line": 4150, + "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": 4154, + "end_line": 4183, + "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": 4187, + "end_line": 4190, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 4, + "top_nesting_level": 0 + }, + { + "name": "array_strides_set", + "long_name": "array_strides_set( PyArrayObject * self , PyObject * obj)", + "filename": "arrayobject.c", + "nloc": 36, + "complexity": 7, + "token_count": 231, + "parameters": [ + "self", + "obj" + ], + "start_line": 4193, + "end_line": 4231, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 39, + "top_nesting_level": 0 + }, + { + "name": "array_protocol_strides_get", + "long_name": "array_protocol_strides_get( PyArrayObject * self)", + "filename": "arrayobject.c", + "nloc": 8, + "complexity": 2, + "token_count": 35, + "parameters": [ + "self" + ], + "start_line": 4235, + "end_line": 4242, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 8, + "top_nesting_level": 0 + }, + { + "name": "array_priority_get", + "long_name": "array_priority_get( PyArrayObject * self)", + "filename": "arrayobject.c", + "nloc": 9, + "complexity": 3, + "token_count": 42, + "parameters": [ + "self" + ], + "start_line": 4245, + "end_line": 4253, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 9, + "top_nesting_level": 0 + }, + { + "name": "array_dataptr_get", + "long_name": "array_dataptr_get( PyArrayObject * self)", + "filename": "arrayobject.c", + "nloc": 7, + "complexity": 2, + "token_count": 35, + "parameters": [ + "self" + ], + "start_line": 4257, + "end_line": 4263, + "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": 4266, + "end_line": 4280, + "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": 4283, + "end_line": 4327, + "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": 4331, + "end_line": 4334, + "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": 4337, + "end_line": 4348, + "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": 4351, + "end_line": 4362, + "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": 4368, + "end_line": 4371, + "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": 4374, + "end_line": 4378, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 5, + "top_nesting_level": 0 + }, + { + "name": "array_descr_set", + "long_name": "array_descr_set( PyArrayObject * self , PyObject * arg)", + "filename": "arrayobject.c", + "nloc": 63, + "complexity": 15, + "token_count": 443, + "parameters": [ + "self", + "arg" + ], + "start_line": 4392, + "end_line": 4477, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 86, + "top_nesting_level": 0 + }, + { + "name": "array_protocol_descr_get", + "long_name": "array_protocol_descr_get( PyArrayObject * self)", + "filename": "arrayobject.c", + "nloc": 16, + "complexity": 4, + "token_count": 117, + "parameters": [ + "self" + ], + "start_line": 4480, + "end_line": 4498, + "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": 4501, + "end_line": 4519, + "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": 4522, + "end_line": 4532, + "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": 4536, + "end_line": 4561, + "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": 4565, + "end_line": 4598, + "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": 4601, + "end_line": 4634, + "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": 4637, + "end_line": 4674, + "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": 4677, + "end_line": 4680, + "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": 4683, + "end_line": 4733, + "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": 4823, + "end_line": 4830, + "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": 4932, + "end_line": 4965, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 34, + "top_nesting_level": 0 + }, + { + "name": "discover_itemsize", + "long_name": "discover_itemsize( PyObject * s , int nd , int * itemsize)", + "filename": "arrayobject.c", + "nloc": 21, + "complexity": 9, + "token_count": 161, + "parameters": [ + "s", + "nd", + "itemsize" + ], + "start_line": 4968, + "end_line": 4990, + "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": 4997, + "end_line": 5023, + "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": 5029, + "end_line": 5061, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 33, + "top_nesting_level": 0 + }, + { + "name": "_array_find_type", + "long_name": "_array_find_type( PyObject * op , PyArray_Descr * minitype , int max)", + "filename": "arrayobject.c", + "nloc": 127, + "complexity": 34, + "token_count": 736, + "parameters": [ + "op", + "minitype", + "max" + ], + "start_line": 5073, + "end_line": 5218, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 146, + "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": 5221, + "end_line": 5244, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 24, + "top_nesting_level": 0 + }, + { + "name": "Array_FromScalar", + "long_name": "Array_FromScalar( PyObject * op , PyArray_Descr * typecode)", + "filename": "arrayobject.c", + "nloc": 23, + "complexity": 6, + "token_count": 146, + "parameters": [ + "op", + "typecode" + ], + "start_line": 5249, + "end_line": 5277, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 29, + "top_nesting_level": 0 + }, + { + "name": "Array_FromSequence", + "long_name": "Array_FromSequence( PyObject * s , PyArray_Descr * typecode , int fortran , int min_depth , int max_depth)", + "filename": "arrayobject.c", + "nloc": 57, + "complexity": 21, + "token_count": 367, + "parameters": [ + "s", + "typecode", + "fortran", + "min_depth", + "max_depth" + ], + "start_line": 5282, + "end_line": 5346, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 65, + "top_nesting_level": 0 + }, + { + "name": "PyArray_ValidType", + "long_name": "PyArray_ValidType( int type)", + "filename": "arrayobject.c", + "nloc": 9, + "complexity": 2, + "token_count": 41, + "parameters": [ + "type" + ], + "start_line": 5353, + "end_line": 5362, + "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": 5368, + "end_line": 5461, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 94, + "top_nesting_level": 0 + }, + { + "name": "PyArray_CastToType", + "long_name": "PyArray_CastToType( PyArrayObject * mp , PyArray_Descr * at , int fortran)", + "filename": "arrayobject.c", + "nloc": 40, + "complexity": 16, + "token_count": 280, + "parameters": [ + "mp", + "at", + "fortran" + ], + "start_line": 5471, + "end_line": 5517, + "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": 5527, + "end_line": 5580, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 54, + "top_nesting_level": 0 + }, + { + "name": "PyArray_FromArray", + "long_name": "PyArray_FromArray( PyArrayObject * arr , PyArray_Descr * newtype , int flags)", + "filename": "arrayobject.c", + "nloc": 114, + "complexity": 33, + "token_count": 676, + "parameters": [ + "arr", + "newtype", + "flags" + ], + "start_line": 5585, + "end_line": 5714, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 130, + "top_nesting_level": 0 + }, + { + "name": "_array_typedescr_fromstr", + "long_name": "_array_typedescr_fromstr( char * str)", + "filename": "arrayobject.c", + "nloc": 98, + "complexity": 36, + "token_count": 505, + "parameters": [ + "str" + ], + "start_line": 5718, + "end_line": 5826, + "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": 5830, + "end_line": 5870, + "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": 5874, + "end_line": 6012, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 139, + "top_nesting_level": 0 + }, + { + "name": "PyArray_FromArrayAttr", + "long_name": "PyArray_FromArrayAttr( PyObject * op , PyArray_Descr * typecode , PyObject * context)", + "filename": "arrayobject.c", + "nloc": 37, + "complexity": 11, + "token_count": 221, + "parameters": [ + "op", + "typecode", + "context" + ], + "start_line": 6016, + "end_line": 6053, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 38, + "top_nesting_level": 0 + }, + { + "name": "PyArray_FromAny", + "long_name": "PyArray_FromAny( PyObject * op , PyArray_Descr * newtype , int min_depth , int max_depth , int flags , PyObject * context)", + "filename": "arrayobject.c", + "nloc": 59, + "complexity": 20, + "token_count": 369, + "parameters": [ + "op", + "newtype", + "min_depth", + "max_depth", + "flags", + "context" + ], + "start_line": 6059, + "end_line": 6135, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 77, + "top_nesting_level": 0 + }, + { + "name": "PyArray_DescrFromObject", + "long_name": "PyArray_DescrFromObject( PyObject * op , PyArray_Descr * mintype)", + "filename": "arrayobject.c", + "nloc": 4, + "complexity": 1, + "token_count": 22, + "parameters": [ + "op", + "mintype" + ], + "start_line": 6140, + "end_line": 6143, + "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": 6150, + "end_line": 6163, + "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": 6209, + "end_line": 6225, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 17, + "top_nesting_level": 0 + }, + { + "name": "PyArray_EnsureArray", + "long_name": "PyArray_EnsureArray( PyObject * op)", + "filename": "arrayobject.c", + "nloc": 14, + "complexity": 5, + "token_count": 89, + "parameters": [ + "op" + ], + "start_line": 6238, + "end_line": 6254, + "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": 6260, + "end_line": 6348, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 89, + "top_nesting_level": 0 + }, + { + "name": "PyArray_CanCastTo", + "long_name": "PyArray_CanCastTo( PyArray_Descr * from , PyArray_Descr * to)", + "filename": "arrayobject.c", + "nloc": 24, + "complexity": 7, + "token_count": 134, + "parameters": [ + "from", + "to" + ], + "start_line": 6353, + "end_line": 6381, + "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": 6394, + "end_line": 6432, + "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": 6440, + "end_line": 6457, + "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": 6462, + "end_line": 6472, + "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": 6475, + "end_line": 6479, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 5, + "top_nesting_level": 0 + }, + { + "name": "iter_length", + "long_name": "iter_length( PyArrayIterObject * self)", + "filename": "arrayobject.c", + "nloc": 4, + "complexity": 1, + "token_count": 16, + "parameters": [ + "self" + ], + "start_line": 6482, + "end_line": 6485, + "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": 6489, + "end_line": 6539, + "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": 6542, + "end_line": 6596, + "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": 6600, + "end_line": 6733, + "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": 6737, + "end_line": 6769, + "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": 6772, + "end_line": 6814, + "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": 6817, + "end_line": 6951, + "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": 6964, + "end_line": 7009, + "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": 7014, + "end_line": 7018, + "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": 7034, + "end_line": 7049, + "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": 7114, + "end_line": 7130, + "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": 7137, + "end_line": 7206, + "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": 7210, + "end_line": 7247, + "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": 7253, + "end_line": 7297, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 45, + "top_nesting_level": 0 + }, + { + "name": "PyArray_MapIterBind", + "long_name": "PyArray_MapIterBind( PyArrayMapIterObject * mit , PyArrayObject * arr)", + "filename": "arrayobject.c", + "nloc": 98, + "complexity": 21, + "token_count": 662, + "parameters": [ + "mit", + "arr" + ], + "start_line": 7315, + "end_line": 7443, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 129, + "top_nesting_level": 0 + }, + { + "name": "_nonzero_indices", + "long_name": "_nonzero_indices( PyObject * myBool , PyArrayIterObject ** iters)", + "filename": "arrayobject.c", + "nloc": 60, + "complexity": 15, + "token_count": 462, + "parameters": [ + "myBool", + "iters" + ], + "start_line": 7449, + "end_line": 7521, + "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": 7524, + "end_line": 7650, + "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": 7654, + "end_line": 7663, + "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": 7734, + "end_line": 7783, + "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": 7786, + "end_line": 7831, + "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": 7834, + "end_line": 7853, + "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": 7856, + "end_line": 7863, + "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": 7866, + "end_line": 7876, + "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": 7879, + "end_line": 7889, + "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": 7892, + "end_line": 7895, + "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": 7898, + "end_line": 7910, + "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": 7940, + "end_line": 7947, + "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": 8006, + "end_line": 8015, + "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": 8033, + "end_line": 8055, + "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": 8061, + "end_line": 8071, + "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": 8090, + "end_line": 8098, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 9, + "top_nesting_level": 0 + }, + { + "name": "arraydescr_protocol_typestr_get", + "long_name": "arraydescr_protocol_typestr_get( PyArray_Descr * self)", + "filename": "arrayobject.c", + "nloc": 11, + "complexity": 3, + "token_count": 60, + "parameters": [ + "self" + ], + "start_line": 8101, + "end_line": 8113, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 13, + "top_nesting_level": 0 + }, + { + "name": "arraydescr_typename_get", + "long_name": "arraydescr_typename_get( PyArray_Descr * self)", + "filename": "arrayobject.c", + "nloc": 19, + "complexity": 4, + "token_count": 122, + "parameters": [ + "self" + ], + "start_line": 8116, + "end_line": 8138, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 23, + "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": 8141, + "end_line": 8160, + "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": 8167, + "end_line": 8174, + "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": 8177, + "end_line": 8184, + "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": 8187, + "end_line": 8194, + "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": 8234, + "end_line": 8286, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 53, + "top_nesting_level": 0 + }, + { + "name": "arraydescr_reduce", + "long_name": "arraydescr_reduce( PyArray_Descr * self , PyObject * args)", + "filename": "arrayobject.c", + "nloc": 50, + "complexity": 12, + "token_count": 377, + "parameters": [ + "self", + "args" + ], + "start_line": 8292, + "end_line": 8349, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 58, + "top_nesting_level": 0 + }, + { + "name": "arraydescr_setstate", + "long_name": "arraydescr_setstate( PyArray_Descr * self , PyObject * args)", + "filename": "arrayobject.c", + "nloc": 35, + "complexity": 8, + "token_count": 260, + "parameters": [ + "self", + "args" + ], + "start_line": 8357, + "end_line": 8399, + "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": 8419, + "end_line": 8485, + "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": 8496, + "end_line": 8504, + "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": 8519, + "end_line": 8564, + "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": 8567, + "end_line": 8576, + "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": 8579, + "end_line": 8589, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 11, + "top_nesting_level": 0 + } + ], + "methods_before": [ + { + "name": "PyArray_GetPriority", + "long_name": "PyArray_GetPriority( PyObject * obj , double default_)", + "filename": "arrayobject.c", + "nloc": 17, + "complexity": 5, + "token_count": 86, + "parameters": [ + "obj", + "default_" + ], + "start_line": 28, + "end_line": 46, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 19, + "top_nesting_level": 0 + }, + { + "name": "PyArray_Zero", + "long_name": "PyArray_Zero( PyArrayObject * arr)", + "filename": "arrayobject.c", + "nloc": 27, + "complexity": 4, + "token_count": 148, + "parameters": [ + "arr" + ], + "start_line": 67, + "end_line": 95, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 29, + "top_nesting_level": 0 + }, + { + "name": "PyArray_One", + "long_name": "PyArray_One( PyArrayObject * arr)", + "filename": "arrayobject.c", + "nloc": 27, + "complexity": 4, + "token_count": 148, + "parameters": [ + "arr" + ], + "start_line": 101, + "end_line": 130, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 30, + "top_nesting_level": 0 + }, + { + "name": "do_sliced_copy", + "long_name": "do_sliced_copy( char * dest , intp * dest_strides , intp * dest_dimensions , int dest_nd , char * src , intp * src_strides , intp * src_dimensions , int src_nd , int elsize , int copies)", + "filename": "arrayobject.c", + "nloc": 48, + "complexity": 13, + "token_count": 313, + "parameters": [ + "dest", + "dest_strides", + "dest_dimensions", + "dest_nd", + "src", + "src_strides", + "src_dimensions", + "src_nd", + "elsize", + "copies" + ], + "start_line": 136, + "end_line": 186, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 51, + "top_nesting_level": 0 + }, + { + "name": "optimize_slices", + "long_name": "optimize_slices( intp ** dest_strides , intp ** dest_dimensions , int * dest_nd , intp ** src_strides , intp ** src_dimensions , int * src_nd , int * elsize , int * copies)", + "filename": "arrayobject.c", + "nloc": 32, + "complexity": 8, + "token_count": 214, + "parameters": [ + "dest_strides", + "dest_dimensions", + "dest_nd", + "src_strides", + "src_dimensions", + "src_nd", + "elsize", + "copies" + ], + "start_line": 209, + "end_line": 240, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 32, + "top_nesting_level": 0 + }, + { + "name": "contiguous_data", + "long_name": "contiguous_data( PyArrayObject * src)", + "filename": "arrayobject.c", + "nloc": 29, + "complexity": 4, + "token_count": 215, + "parameters": [ + "src" + ], + "start_line": 243, + "end_line": 277, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 35, + "top_nesting_level": 0 + }, + { + "name": "PyArray_INCREF", + "long_name": "PyArray_INCREF( PyArrayObject * mp)", + "filename": "arrayobject.c", + "nloc": 17, + "complexity": 6, + "token_count": 125, + "parameters": [ + "mp" + ], + "start_line": 293, + "end_line": 315, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 23, + "top_nesting_level": 0 + }, + { + "name": "PyArray_XDECREF", + "long_name": "PyArray_XDECREF( PyArrayObject * mp)", + "filename": "arrayobject.c", + "nloc": 17, + "complexity": 6, + "token_count": 125, + "parameters": [ + "mp" + ], + "start_line": 321, + "end_line": 342, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 22, + "top_nesting_level": 0 + }, + { + "name": "byte_swap_vector", + "long_name": "byte_swap_vector( * p , int n , int size)", + "filename": "arrayobject.c", + "nloc": 38, + "complexity": 10, + "token_count": 340, + "parameters": [ + "p", + "n", + "size" + ], + "start_line": 346, + "end_line": 384, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 39, + "top_nesting_level": 0 + }, + { + "name": "copy_and_swap", + "long_name": "copy_and_swap( * dst , * src , int itemsize , intp numitems , intp srcstrides , int swap)", + "filename": "arrayobject.c", + "nloc": 18, + "complexity": 5, + "token_count": 120, + "parameters": [ + "dst", + "src", + "itemsize", + "numitems", + "srcstrides", + "swap" + ], + "start_line": 389, + "end_line": 409, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 21, + "top_nesting_level": 0 + }, + { + "name": "PyArray_PyIntAsIntp", + "long_name": "PyArray_PyIntAsIntp( PyObject * o)", + "filename": "arrayobject.c", + "nloc": 71, + "complexity": 21, + "token_count": 413, + "parameters": [ + "o" + ], + "start_line": 423, + "end_line": 505, + "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": 512, + "end_line": 586, + "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": 589, + "end_line": 604, + "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": 610, + "end_line": 618, + "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": 634, + "end_line": 714, + "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": 718, + "end_line": 732, + "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": 745, + "end_line": 771, + "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": 777, + "end_line": 791, + "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": 800, + "end_line": 820, + "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": 81, + "complexity": 12, + "token_count": 483, + "parameters": [ + "data", + "descr", + "base" + ], + "start_line": 829, + "end_line": 913, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 85, + "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": 929, + "end_line": 932, + "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": 942, + "end_line": 964, + "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": 978, + "end_line": 1018, + "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": 1033, + "end_line": 1074, + "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": 1081, + "end_line": 1172, + "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": 1178, + "end_line": 1207, + "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": 1210, + "end_line": 1246, + "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": 1255, + "end_line": 1292, + "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": 1299, + "end_line": 1307, + "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": 1310, + "end_line": 1335, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 26, + "top_nesting_level": 0 + }, + { + "name": "array_item_nice", + "long_name": "array_item_nice( PyArrayObject * self , int i)", + "filename": "arrayobject.c", + "nloc": 4, + "complexity": 1, + "token_count": 29, + "parameters": [ + "self", + "i" + ], + "start_line": 1338, + "end_line": 1341, + "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": 1345, + "end_line": 1380, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 36, + "top_nesting_level": 0 + }, + { + "name": "array_ass_item", + "long_name": "array_ass_item( PyArrayObject * self , int i , PyObject * v)", + "filename": "arrayobject.c", + "nloc": 4, + "complexity": 1, + "token_count": 28, + "parameters": [ + "self", + "i", + "v" + ], + "start_line": 1386, + "end_line": 1389, + "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": 1395, + "end_line": 1403, + "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": 1409, + "end_line": 1459, + "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": 1466, + "end_line": 1511, + "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": 1515, + "end_line": 1609, + "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": 1612, + "end_line": 1649, + "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": 1661, + "end_line": 1714, + "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": 1717, + "end_line": 1777, + "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": 1780, + "end_line": 1807, + "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": 1810, + "end_line": 1829, + "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": 1841, + "end_line": 1903, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 63, + "top_nesting_level": 0 + }, + { + "name": "array_subscript", + "long_name": "array_subscript( PyArrayObject * self , PyObject * op)", + "filename": "arrayobject.c", + "nloc": 103, + "complexity": 28, + "token_count": 666, + "parameters": [ + "self", + "op" + ], + "start_line": 1927, + "end_line": 2045, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 119, + "top_nesting_level": 0 + }, + { + "name": "array_ass_sub", + "long_name": "array_ass_sub( PyArrayObject * self , PyObject * index , PyObject * op)", + "filename": "arrayobject.c", + "nloc": 93, + "complexity": 28, + "token_count": 588, + "parameters": [ + "self", + "index", + "op" + ], + "start_line": 2060, + "end_line": 2165, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 106, + "top_nesting_level": 0 + }, + { + "name": "array_subscript_nice", + "long_name": "array_subscript_nice( PyArrayObject * self , PyObject * op)", + "filename": "arrayobject.c", + "nloc": 4, + "complexity": 1, + "token_count": 27, + "parameters": [ + "self", + "op" + ], + "start_line": 2174, + "end_line": 2177, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 4, + "top_nesting_level": 0 + }, + { + "name": "array_getsegcount", + "long_name": "array_getsegcount( PyArrayObject * self , int * lenp)", + "filename": "arrayobject.c", + "nloc": 11, + "complexity": 4, + "token_count": 48, + "parameters": [ + "self", + "lenp" + ], + "start_line": 2196, + "end_line": 2208, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 13, + "top_nesting_level": 0 + }, + { + "name": "array_getreadbuf", + "long_name": "array_getreadbuf( PyArrayObject * self , int segment , ** ptrptr)", + "filename": "arrayobject.c", + "nloc": 15, + "complexity": 3, + "token_count": 72, + "parameters": [ + "self", + "segment", + "ptrptr" + ], + "start_line": 2211, + "end_line": 2226, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 16, + "top_nesting_level": 0 + }, + { + "name": "array_getwritebuf", + "long_name": "array_getwritebuf( PyArrayObject * self , int segment , ** ptrptr)", + "filename": "arrayobject.c", + "nloc": 10, + "complexity": 2, + "token_count": 54, + "parameters": [ + "self", + "segment", + "ptrptr" + ], + "start_line": 2230, + "end_line": 2239, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 10, + "top_nesting_level": 0 + }, + { + "name": "array_getcharbuf", + "long_name": "array_getcharbuf( PyArrayObject * self , int segment , const char ** ptrptr)", + "filename": "arrayobject.c", + "nloc": 12, + "complexity": 3, + "token_count": 65, + "parameters": [ + "self", + "segment", + "ptrptr" + ], + "start_line": 2242, + "end_line": 2253, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 12, + "top_nesting_level": 0 + }, + { + "name": "PyArray_SetNumericOps", + "long_name": "PyArray_SetNumericOps( PyObject * dict)", + "filename": "arrayobject.c", + "nloc": 34, + "complexity": 1, + "token_count": 162, + "parameters": [ + "dict" + ], + "start_line": 2324, + "end_line": 2357, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 34, + "top_nesting_level": 0 + }, + { + "name": "PyArray_GetNumericOps", + "long_name": "PyArray_GetNumericOps()", + "filename": "arrayobject.c", + "nloc": 39, + "complexity": 2, + "token_count": 183, + "parameters": [], + "start_line": 2367, + "end_line": 2406, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 40, + "top_nesting_level": 0 + }, + { + "name": "PyArray_GenericReduceFunction", + "long_name": "PyArray_GenericReduceFunction( PyArrayObject * m1 , PyObject * op , int axis , int rtype)", + "filename": "arrayobject.c", + "nloc": 24, + "complexity": 5, + "token_count": 141, + "parameters": [ + "m1", + "op", + "axis", + "rtype" + ], + "start_line": 2409, + "end_line": 2432, + "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": 2436, + "end_line": 2459, + "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": 2463, + "end_line": 2470, + "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": 2473, + "end_line": 2480, + "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": 2483, + "end_line": 2491, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 9, + "top_nesting_level": 0 + }, + { + "name": "array_add", + "long_name": "array_add( PyArrayObject * m1 , PyObject * m2)", + "filename": "arrayobject.c", + "nloc": 4, + "complexity": 1, + "token_count": 24, + "parameters": [ + "m1", + "m2" + ], + "start_line": 2494, + "end_line": 2497, + "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": 2500, + "end_line": 2503, + "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": 2506, + "end_line": 2509, + "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": 2512, + "end_line": 2515, + "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": 2518, + "end_line": 2521, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 4, + "top_nesting_level": 0 + }, + { + "name": "array_power", + "long_name": "array_power( PyArrayObject * m1 , PyObject * m2)", + "filename": "arrayobject.c", + "nloc": 4, + "complexity": 1, + "token_count": 24, + "parameters": [ + "m1", + "m2" + ], + "start_line": 2524, + "end_line": 2527, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 4, + "top_nesting_level": 0 + }, + { + "name": "array_negative", + "long_name": "array_negative( PyArrayObject * m1)", + "filename": "arrayobject.c", + "nloc": 4, + "complexity": 1, + "token_count": 18, + "parameters": [ + "m1" + ], + "start_line": 2530, + "end_line": 2533, + "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": 2536, + "end_line": 2539, + "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": 2542, + "end_line": 2545, + "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": 2548, + "end_line": 2551, + "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": 2554, + "end_line": 2557, + "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": 2560, + "end_line": 2563, + "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": 2566, + "end_line": 2569, + "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": 2572, + "end_line": 2575, + "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": 2578, + "end_line": 2581, + "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": 2584, + "end_line": 2587, + "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": 2590, + "end_line": 2593, + "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": 2596, + "end_line": 2599, + "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": 2602, + "end_line": 2605, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 4, + "top_nesting_level": 0 + }, + { + "name": "array_inplace_power", + "long_name": "array_inplace_power( PyArrayObject * m1 , PyObject * m2)", + "filename": "arrayobject.c", + "nloc": 4, + "complexity": 1, + "token_count": 24, + "parameters": [ + "m1", + "m2" + ], + "start_line": 2608, + "end_line": 2611, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 4, + "top_nesting_level": 0 + }, + { + "name": "array_inplace_left_shift", + "long_name": "array_inplace_left_shift( PyArrayObject * m1 , PyObject * m2)", + "filename": "arrayobject.c", + "nloc": 4, + "complexity": 1, + "token_count": 24, + "parameters": [ + "m1", + "m2" + ], + "start_line": 2614, + "end_line": 2617, + "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": 2620, + "end_line": 2623, + "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": 2626, + "end_line": 2629, + "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": 2632, + "end_line": 2635, + "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": 2638, + "end_line": 2641, + "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": 2644, + "end_line": 2647, + "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": 2650, + "end_line": 2653, + "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": 2656, + "end_line": 2660, + "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": 2663, + "end_line": 2667, + "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": 2671, + "end_line": 2689, + "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": 2692, + "end_line": 2709, + "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": 2714, + "end_line": 2729, + "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": 2733, + "end_line": 2759, + "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": 2762, + "end_line": 2787, + "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": 2790, + "end_line": 2812, + "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": 2815, + "end_line": 2837, + "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": 2840, + "end_line": 2862, + "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": 2865, + "end_line": 2869, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 5, + "top_nesting_level": 0 + }, + { + "name": "array_slice", + "long_name": "array_slice( PyArrayObject * self , int ilow , int ihigh)", + "filename": "arrayobject.c", + "nloc": 36, + "complexity": 11, + "token_count": 259, + "parameters": [ + "self", + "ilow", + "ihigh" + ], + "start_line": 2930, + "end_line": 2970, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 41, + "top_nesting_level": 0 + }, + { + "name": "array_ass_slice", + "long_name": "array_ass_slice( PyArrayObject * self , int ilow , int ihigh , PyObject * v)", + "filename": "arrayobject.c", + "nloc": 20, + "complexity": 4, + "token_count": 108, + "parameters": [ + "self", + "ilow", + "ihigh", + "v" + ], + "start_line": 2974, + "end_line": 2995, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 22, + "top_nesting_level": 0 + }, + { + "name": "array_contains", + "long_name": "array_contains( PyArrayObject * self , PyObject * el)", + "filename": "arrayobject.c", + "nloc": 10, + "complexity": 2, + "token_count": 66, + "parameters": [ + "self", + "el" + ], + "start_line": 2998, + "end_line": 3010, + "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": 3031, + "end_line": 3078, + "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": 3081, + "end_line": 3117, + "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": 3126, + "end_line": 3143, + "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": 3146, + "end_line": 3158, + "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": 3161, + "end_line": 3173, + "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": 73, + "complexity": 15, + "token_count": 325, + "parameters": [ + "self", + "other", + "cmp_op" + ], + "start_line": 3176, + "end_line": 3265, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 90, + "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": 3268, + "end_line": 3297, + "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": 3303, + "end_line": 3323, + "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": 3331, + "end_line": 3366, + "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": 3372, + "end_line": 3391, + "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": 3395, + "end_line": 3413, + "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": 3416, + "end_line": 3433, + "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": 3436, + "end_line": 3469, + "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": 3476, + "end_line": 3503, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 28, + "top_nesting_level": 0 + }, + { + "name": "PyArray_CheckStrides", + "long_name": "PyArray_CheckStrides( int elsize , int nd , intp numbytes , intp * dims , intp * newstrides)", + "filename": "arrayobject.c", + "nloc": 13, + "complexity": 4, + "token_count": 84, + "parameters": [ + "elsize", + "nd", + "numbytes", + "dims", + "newstrides" + ], + "start_line": 3512, + "end_line": 3527, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 16, + "top_nesting_level": 0 + }, + { + "name": "_array_fill_strides", + "long_name": "_array_fill_strides( intp * strides , intp * dims , int nd , intp itemsize , int inflag , int * objflags)", + "filename": "arrayobject.c", + "nloc": 24, + "complexity": 9, + "token_count": 171, + "parameters": [ + "strides", + "dims", + "nd", + "itemsize", + "inflag", + "objflags" + ], + "start_line": 3547, + "end_line": 3571, + "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": 3577, + "end_line": 3599, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 23, + "top_nesting_level": 0 + }, + { + "name": "_update_descr_and_dimensions", + "long_name": "_update_descr_and_dimensions( PyArray_Descr ** des , intp * newdims , intp * newstrides , int oldnd)", + "filename": "arrayobject.c", + "nloc": 37, + "complexity": 6, + "token_count": 229, + "parameters": [ + "des", + "newdims", + "newstrides", + "oldnd" + ], + "start_line": 3603, + "end_line": 3645, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 43, + "top_nesting_level": 0 + }, + { + "name": "PyArray_NewFromDescr", + "long_name": "PyArray_NewFromDescr( PyTypeObject * subtype , PyArray_Descr * descr , int nd , intp * dims , intp * strides , * data , int flags , PyObject * obj)", + "filename": "arrayobject.c", + "nloc": 136, + "complexity": 27, + "token_count": 781, + "parameters": [ + "subtype", + "descr", + "nd", + "dims", + "strides", + "data", + "flags", + "obj" + ], + "start_line": 3653, + "end_line": 3818, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 166, + "top_nesting_level": 0 + }, + { + "name": "PyArray_Resize", + "long_name": "PyArray_Resize( PyArrayObject * self , PyArray_Dims * newshape)", + "filename": "arrayobject.c", + "nloc": 82, + "complexity": 15, + "token_count": 497, + "parameters": [ + "self", + "newshape" + ], + "start_line": 3827, + "end_line": 3925, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 99, + "top_nesting_level": 0 + }, + { + "name": "PyArray_FillObjectArray", + "long_name": "PyArray_FillObjectArray( PyArrayObject * arr , PyObject * obj)", + "filename": "arrayobject.c", + "nloc": 18, + "complexity": 4, + "token_count": 98, + "parameters": [ + "arr", + "obj" + ], + "start_line": 3931, + "end_line": 3948, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 18, + "top_nesting_level": 0 + }, + { + "name": "PyArray_FillWithScalar", + "long_name": "PyArray_FillWithScalar( PyArrayObject * arr , PyObject * obj)", + "filename": "arrayobject.c", + "nloc": 41, + "complexity": 6, + "token_count": 231, + "parameters": [ + "arr", + "obj" + ], + "start_line": 3952, + "end_line": 3994, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 43, + "top_nesting_level": 0 + }, + { + "name": "array_new", + "long_name": "array_new( PyTypeObject * subtype , PyObject * args , PyObject * kwds)", + "filename": "arrayobject.c", + "nloc": 103, + "complexity": 19, + "token_count": 583, + "parameters": [ + "subtype", + "args", + "kwds" + ], + "start_line": 3997, + "end_line": 4116, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 120, + "top_nesting_level": 0 + }, + { + "name": "array_iter", + "long_name": "array_iter( PyArrayObject * arr)", + "filename": "arrayobject.c", + "nloc": 9, + "complexity": 2, + "token_count": 38, + "parameters": [ + "arr" + ], + "start_line": 4120, + "end_line": 4128, + "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": 4134, + "end_line": 4137, + "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": 4140, + "end_line": 4144, + "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": 4147, + "end_line": 4150, + "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": 4154, + "end_line": 4183, + "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": 4187, + "end_line": 4190, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 4, + "top_nesting_level": 0 + }, + { + "name": "array_strides_set", + "long_name": "array_strides_set( PyArrayObject * self , PyObject * obj)", + "filename": "arrayobject.c", + "nloc": 36, + "complexity": 7, + "token_count": 231, + "parameters": [ + "self", + "obj" + ], + "start_line": 4193, + "end_line": 4231, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 39, + "top_nesting_level": 0 + }, + { + "name": "array_protocol_strides_get", + "long_name": "array_protocol_strides_get( PyArrayObject * self)", + "filename": "arrayobject.c", + "nloc": 8, + "complexity": 2, + "token_count": 35, + "parameters": [ + "self" + ], + "start_line": 4235, + "end_line": 4242, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 8, + "top_nesting_level": 0 + }, + { + "name": "array_priority_get", + "long_name": "array_priority_get( PyArrayObject * self)", + "filename": "arrayobject.c", + "nloc": 9, + "complexity": 3, + "token_count": 42, + "parameters": [ + "self" + ], + "start_line": 4245, + "end_line": 4253, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 9, + "top_nesting_level": 0 + }, + { + "name": "array_dataptr_get", + "long_name": "array_dataptr_get( PyArrayObject * self)", + "filename": "arrayobject.c", + "nloc": 7, + "complexity": 2, + "token_count": 35, + "parameters": [ + "self" + ], + "start_line": 4257, + "end_line": 4263, + "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": 4266, + "end_line": 4280, + "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": 4283, + "end_line": 4327, + "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": 4331, + "end_line": 4334, + "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": 4337, + "end_line": 4348, + "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": 4351, + "end_line": 4362, + "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": 4368, + "end_line": 4371, + "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": 4374, + "end_line": 4378, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 5, + "top_nesting_level": 0 + }, + { + "name": "array_descr_set", + "long_name": "array_descr_set( PyArrayObject * self , PyObject * arg)", + "filename": "arrayobject.c", + "nloc": 63, + "complexity": 15, + "token_count": 443, + "parameters": [ + "self", + "arg" + ], + "start_line": 4392, + "end_line": 4477, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 86, + "top_nesting_level": 0 + }, + { + "name": "array_protocol_descr_get", + "long_name": "array_protocol_descr_get( PyArrayObject * self)", + "filename": "arrayobject.c", + "nloc": 16, + "complexity": 4, + "token_count": 117, + "parameters": [ + "self" + ], + "start_line": 4480, + "end_line": 4498, + "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": 4501, + "end_line": 4519, + "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": 4522, + "end_line": 4532, + "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": 4536, + "end_line": 4561, + "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": 4565, + "end_line": 4598, + "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": 4601, + "end_line": 4634, + "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": 4637, + "end_line": 4674, + "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": 4677, + "end_line": 4680, + "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": 4683, + "end_line": 4733, + "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": 4823, + "end_line": 4830, + "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": 4932, + "end_line": 4965, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 34, + "top_nesting_level": 0 + }, + { + "name": "discover_itemsize", + "long_name": "discover_itemsize( PyObject * s , int nd , int * itemsize)", + "filename": "arrayobject.c", + "nloc": 21, + "complexity": 9, + "token_count": 161, + "parameters": [ + "s", + "nd", + "itemsize" + ], + "start_line": 4968, + "end_line": 4990, + "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": 4997, + "end_line": 5023, + "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": 5029, + "end_line": 5061, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 33, + "top_nesting_level": 0 + }, + { + "name": "_array_find_type", + "long_name": "_array_find_type( PyObject * op , PyArray_Descr * minitype , int max)", + "filename": "arrayobject.c", + "nloc": 120, + "complexity": 31, + "token_count": 691, + "parameters": [ + "op", + "minitype", + "max" + ], + "start_line": 5073, + "end_line": 5209, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 137, + "top_nesting_level": 0 + }, + { + "name": "Assign_Array", + "long_name": "Assign_Array( PyArrayObject * self , PyObject * v)", + "filename": "arrayobject.c", + "nloc": 21, + "complexity": 6, + "token_count": 121, + "parameters": [ + "self", + "v" + ], + "start_line": 5212, + "end_line": 5235, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 24, + "top_nesting_level": 0 + }, + { + "name": "Array_FromScalar", + "long_name": "Array_FromScalar( PyObject * op , PyArray_Descr * typecode)", + "filename": "arrayobject.c", + "nloc": 23, + "complexity": 6, + "token_count": 146, + "parameters": [ + "op", + "typecode" + ], + "start_line": 5240, + "end_line": 5268, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 29, + "top_nesting_level": 0 + }, + { + "name": "Array_FromSequence", + "long_name": "Array_FromSequence( PyObject * s , PyArray_Descr * typecode , int fortran , int min_depth , int max_depth)", + "filename": "arrayobject.c", + "nloc": 57, + "complexity": 21, + "token_count": 367, + "parameters": [ + "s", + "typecode", + "fortran", + "min_depth", + "max_depth" + ], + "start_line": 5273, + "end_line": 5337, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 65, + "top_nesting_level": 0 + }, + { + "name": "PyArray_ValidType", + "long_name": "PyArray_ValidType( int type)", + "filename": "arrayobject.c", + "nloc": 9, + "complexity": 2, + "token_count": 41, + "parameters": [ + "type" + ], + "start_line": 5344, + "end_line": 5353, + "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": 5359, + "end_line": 5452, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 94, + "top_nesting_level": 0 + }, + { + "name": "PyArray_CastToType", + "long_name": "PyArray_CastToType( PyArrayObject * mp , PyArray_Descr * at , int fortran)", + "filename": "arrayobject.c", + "nloc": 40, + "complexity": 16, + "token_count": 280, + "parameters": [ + "mp", + "at", + "fortran" + ], + "start_line": 5462, + "end_line": 5508, + "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": 5518, + "end_line": 5571, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 54, + "top_nesting_level": 0 + }, + { + "name": "PyArray_FromArray", + "long_name": "PyArray_FromArray( PyArrayObject * arr , PyArray_Descr * newtype , int flags)", + "filename": "arrayobject.c", + "nloc": 114, + "complexity": 33, + "token_count": 676, + "parameters": [ + "arr", + "newtype", + "flags" + ], + "start_line": 5576, + "end_line": 5705, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 130, + "top_nesting_level": 0 + }, + { + "name": "_array_typedescr_fromstr", + "long_name": "_array_typedescr_fromstr( char * str)", + "filename": "arrayobject.c", + "nloc": 98, + "complexity": 36, + "token_count": 505, + "parameters": [ + "str" + ], + "start_line": 5709, + "end_line": 5817, + "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": 5821, + "end_line": 5861, + "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": 5865, + "end_line": 6003, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 139, + "top_nesting_level": 0 + }, + { + "name": "PyArray_FromArrayAttr", + "long_name": "PyArray_FromArrayAttr( PyObject * op , PyArray_Descr * typecode , PyObject * context)", + "filename": "arrayobject.c", + "nloc": 37, + "complexity": 11, + "token_count": 221, + "parameters": [ + "op", + "typecode", + "context" + ], + "start_line": 6007, + "end_line": 6044, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 38, + "top_nesting_level": 0 + }, + { + "name": "PyArray_FromAny", + "long_name": "PyArray_FromAny( PyObject * op , PyArray_Descr * newtype , int min_depth , int max_depth , int flags , PyObject * context)", + "filename": "arrayobject.c", + "nloc": 59, + "complexity": 20, + "token_count": 369, + "parameters": [ + "op", + "newtype", + "min_depth", + "max_depth", + "flags", + "context" + ], + "start_line": 6050, + "end_line": 6126, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 77, + "top_nesting_level": 0 + }, + { + "name": "PyArray_DescrFromObject", + "long_name": "PyArray_DescrFromObject( PyObject * op , PyArray_Descr * mintype)", + "filename": "arrayobject.c", + "nloc": 4, + "complexity": 1, + "token_count": 22, + "parameters": [ + "op", + "mintype" + ], + "start_line": 6131, + "end_line": 6134, + "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": 6141, + "end_line": 6154, + "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": 6200, + "end_line": 6216, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 17, + "top_nesting_level": 0 + }, + { + "name": "PyArray_EnsureArray", + "long_name": "PyArray_EnsureArray( PyObject * op)", + "filename": "arrayobject.c", + "nloc": 14, + "complexity": 5, + "token_count": 89, + "parameters": [ + "op" + ], + "start_line": 6229, + "end_line": 6245, + "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": 6251, + "end_line": 6339, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 89, + "top_nesting_level": 0 + }, + { + "name": "PyArray_CanCastTo", + "long_name": "PyArray_CanCastTo( PyArray_Descr * from , PyArray_Descr * to)", + "filename": "arrayobject.c", + "nloc": 24, + "complexity": 7, + "token_count": 134, + "parameters": [ + "from", + "to" + ], + "start_line": 6344, + "end_line": 6372, + "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": 6385, + "end_line": 6423, + "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": 6431, + "end_line": 6448, + "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": 6453, + "end_line": 6463, + "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": 6466, + "end_line": 6470, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 5, + "top_nesting_level": 0 + }, + { + "name": "iter_length", + "long_name": "iter_length( PyArrayIterObject * self)", + "filename": "arrayobject.c", + "nloc": 4, + "complexity": 1, + "token_count": 16, + "parameters": [ + "self" + ], + "start_line": 6473, + "end_line": 6476, + "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": 6480, + "end_line": 6530, + "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": 6533, + "end_line": 6587, + "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": 6591, + "end_line": 6724, + "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": 6728, + "end_line": 6760, + "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": 6763, + "end_line": 6805, + "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": 6808, + "end_line": 6942, + "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": 6955, + "end_line": 7000, + "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": 7005, + "end_line": 7009, + "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": 7025, + "end_line": 7040, + "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": 7105, + "end_line": 7121, + "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": 7128, + "end_line": 7197, + "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": 7201, + "end_line": 7238, + "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": 7244, + "end_line": 7288, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 45, + "top_nesting_level": 0 + }, + { + "name": "PyArray_MapIterBind", + "long_name": "PyArray_MapIterBind( PyArrayMapIterObject * mit , PyArrayObject * arr)", + "filename": "arrayobject.c", + "nloc": 98, + "complexity": 21, + "token_count": 662, + "parameters": [ + "mit", + "arr" + ], + "start_line": 7306, + "end_line": 7434, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 129, + "top_nesting_level": 0 + }, + { + "name": "_nonzero_indices", + "long_name": "_nonzero_indices( PyObject * myBool , PyArrayIterObject ** iters)", + "filename": "arrayobject.c", + "nloc": 60, + "complexity": 15, + "token_count": 462, + "parameters": [ + "myBool", + "iters" + ], + "start_line": 7440, + "end_line": 7512, + "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": 7515, + "end_line": 7641, + "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": 7645, + "end_line": 7654, + "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": 7725, + "end_line": 7774, + "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": 7777, + "end_line": 7822, + "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": 7825, + "end_line": 7844, + "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": 7847, + "end_line": 7854, + "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": 7857, + "end_line": 7867, + "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": 7870, + "end_line": 7880, + "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": 7883, + "end_line": 7886, + "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": 7889, + "end_line": 7901, + "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": 7931, + "end_line": 7938, + "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": 7997, + "end_line": 8006, + "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": 8024, + "end_line": 8046, + "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": 8052, + "end_line": 8062, + "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": 8081, + "end_line": 8089, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 9, + "top_nesting_level": 0 + }, + { + "name": "arraydescr_protocol_typestr_get", + "long_name": "arraydescr_protocol_typestr_get( PyArray_Descr * self)", + "filename": "arrayobject.c", + "nloc": 11, + "complexity": 3, + "token_count": 60, + "parameters": [ + "self" + ], + "start_line": 8092, + "end_line": 8104, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 13, + "top_nesting_level": 0 + }, + { + "name": "arraydescr_typename_get", + "long_name": "arraydescr_typename_get( PyArray_Descr * self)", + "filename": "arrayobject.c", + "nloc": 19, + "complexity": 4, + "token_count": 122, + "parameters": [ + "self" + ], + "start_line": 8107, + "end_line": 8129, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 23, + "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": 8132, + "end_line": 8151, + "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": 8158, + "end_line": 8165, + "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": 8168, + "end_line": 8175, + "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": 8178, + "end_line": 8185, + "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": 8225, + "end_line": 8277, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 53, + "top_nesting_level": 0 + }, + { + "name": "arraydescr_reduce", + "long_name": "arraydescr_reduce( PyArray_Descr * self , PyObject * args)", + "filename": "arrayobject.c", + "nloc": 50, + "complexity": 12, + "token_count": 377, + "parameters": [ + "self", + "args" + ], + "start_line": 8283, + "end_line": 8340, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 58, + "top_nesting_level": 0 + }, + { + "name": "arraydescr_setstate", + "long_name": "arraydescr_setstate( PyArray_Descr * self , PyObject * args)", + "filename": "arrayobject.c", + "nloc": 35, + "complexity": 8, + "token_count": 260, + "parameters": [ + "self", + "args" + ], + "start_line": 8348, + "end_line": 8390, + "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": 8410, + "end_line": 8476, + "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": 8487, + "end_line": 8495, + "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": 8510, + "end_line": 8555, + "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": 8558, + "end_line": 8567, + "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": 8570, + "end_line": 8580, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 11, + "top_nesting_level": 0 + } + ], + "changed_methods": [ + { + "name": "_array_find_type", + "long_name": "_array_find_type( PyObject * op , PyArray_Descr * minitype , int max)", + "filename": "arrayobject.c", + "nloc": 127, + "complexity": 34, + "token_count": 736, + "parameters": [ + "op", + "minitype", + "max" + ], + "start_line": 5073, + "end_line": 5218, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 146, + "top_nesting_level": 0 + } + ], + "nloc": 6853, + "complexity": 1469, + "token_count": 40312, + "diff_parsed": { + "added": [ + "\t} else if (PyLong_Check(op)) {", + "\t\t/* if integer can fit into a longlong then return that", + "\t\t*/", + "\t\tif ((PyLong_AsLongLong(op) == -1) && PyErr_Occurred()) {", + "\t\t\tPyErr_Clear();", + "\t\t\tgoto deflt;", + "\t\t}", + "\t\tchktype = PyArray_DescrFromType(PyArray_LONGLONG);", + "\t\tgoto finish;" + ], + "deleted": [] + } + } + ] + }, + { + "hash": "f097ed4fa79aca45adf867a3f01bf677679559d7", + "msg": "Fix bugs relating to adding hasobject. Add scalar-loops for some operations to see if they are faster on some platforms.", + "author": { + "name": "Travis Oliphant", + "email": "oliphant@enthought.com" + }, + "committer": { + "name": "Travis Oliphant", + "email": "oliphant@enthought.com" + }, + "author_date": "2006-01-30T07:49:07+00:00", + "author_timezone": 0, + "committer_date": "2006-01-30T07:49:07+00:00", + "committer_timezone": 0, + "branches": [ + "main" + ], + "in_main_branch": true, + "merge": false, + "parents": [ + "0245ddea0b3a7ccf8dfc1a8366cbacb2232cefb8" + ], + "project_name": "repo_copy", + "project_path": "/tmp/tmppy2o86q9/repo_copy", + "deletions": 25, + "insertions": 53, + "lines": 78, + "files": 3, + "dmm_unit_size": 0.0, + "dmm_unit_complexity": 0.0, + "dmm_unit_interfacing": 0.5833333333333334, + "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": "@@ -5265,6 +5265,12 @@ Array_FromScalar(PyObject *op, PyArray_Descr *typecode)\n \t\t\t\t\t\t NULL, NULL, 0, NULL);\n \n \tif (ret == NULL) return NULL;\n+\tif (ret->nd > 0) {\n+\t\tPyErr_SetString(PyExc_ValueError,\n+\t\t\t\t\"shape-mismatch on array construction\");\n+\t\tPy_DECREF(ret);\n+\t\treturn NULL;\n+\t}\n \n ret->descr->f->setitem(op, ret->data, ret);\n \t\n@@ -5277,7 +5283,7 @@ Array_FromScalar(PyObject *op, PyArray_Descr *typecode)\n }\n \n \n-/* steals reference to typecode unless return value is NULL*/\n+/* steals reference to typecode */\n static PyObject *\n Array_FromSequence(PyObject *s, PyArray_Descr *typecode, int fortran, \n \t\t int min_depth, int max_depth)\n@@ -5289,7 +5295,6 @@ Array_FromSequence(PyObject *s, PyArray_Descr *typecode, int fortran,\n \tint stop_at_tuple;\n \tint type = typecode->type_num;\n \tint itemsize = typecode->elsize;\n-\tPyArray_Descr *savetype=typecode;\n \t\n \tstop_at_string = ((type == PyArray_OBJECT) ||\t\\\n \t\t\t (type == PyArray_STRING) ||\t\\\n@@ -5306,23 +5311,20 @@ Array_FromSequence(PyObject *s, PyArray_Descr *typecode, int fortran,\n \t\t\treturn Array_FromScalar(s, typecode);\n PyErr_SetString(PyExc_ValueError, \n \t\t\t\t\"invalid input sequence\");\n- return NULL;\n+\t\tgoto fail;\n }\n \t\n if ((max_depth && nd > max_depth) ||\t\\\n \t (min_depth && nd < min_depth)) {\n PyErr_SetString(PyExc_ValueError, \n \t\t\t\t\"invalid number of dimensions\");\n- return NULL;\n+\t\tgoto fail;\n }\n \t\n-\tif(discover_dimensions(s,nd,d, !stop_at_string) == -1) {\n-\t\treturn NULL;\n-\t}\n+\tif(discover_dimensions(s,nd,d, !stop_at_string) == -1) goto fail;\n+\n \tif (itemsize == 0 && PyTypeNum_ISEXTENDED(type)) {\n-\t\tif (discover_itemsize(s, nd, &itemsize) == -1) {\n-\t\t\treturn NULL;\n-\t\t}\n+\t\tif (discover_itemsize(s, nd, &itemsize) == -1) goto fail;\n \t\tif (type == PyArray_UNICODE) itemsize*=sizeof(Py_UNICODE);\n \t}\n \n@@ -5336,13 +5338,16 @@ Array_FromSequence(PyObject *s, PyArray_Descr *typecode, int fortran,\n \t\t\t\t\t NULL, NULL,\n \t\t\t\t\t fortran, NULL);\n \t\n- if(!r) {Py_XINCREF(savetype); return NULL;}\n+ if(!r) return NULL;\n if(Assign_Array(r,s) == -1) {\n-\t\tPy_XINCREF(savetype);\n \t\tPy_DECREF(r);\n \t\treturn NULL;\n \t}\n return (PyObject*)r;\n+\n+ fail:\n+\tPy_DECREF(typecode);\n+\treturn NULL;\n }\n \n \n@@ -6092,15 +6097,19 @@ PyArray_FromAny(PyObject *op, PyArray_Descr *newtype, int min_depth,\n \t\t}\n \t\tif (PySequence_Check(op)) {\n \t\t\t/* necessary but not sufficient */\n-\t\t\t\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+\t\t\tif (PyErr_Occurred() && r == NULL) {\n /* It wasn't really a sequence after all.\n * Try interpreting it as a scalar */\n- PyErr_Clear();\n- else\n- seq = TRUE;\n+\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", + "added_lines": 26, + "deleted_lines": 17, + "source_code": "/*\n Provide multidimensional arrays as a basic object type in python. \n\nBased on Original Numeric implementation\nCopyright (c) 1995, 1996, 1997 Jim Hugunin, hugunin@mit.edu\n\nwith contributions from many Numeric Python developers 1995-2004 \n\nHeavily modified in 2005 with inspiration from Numarray \n\nby\n\nTravis Oliphant\nAssistant Professor at\nBrigham Young University \n\nmaintainer email: oliphant.travis@ieee.org\n\nNumarray design (which provided guidance) by \nSpace Science Telescope Institute \n (J. Todd Miller, Perry Greenfield, Rick White)\n*/\n\n/*OBJECT_API\n Get Priority from object\n*/\nstatic double\nPyArray_GetPriority(PyObject *obj, double default_) \n{\n PyObject *ret;\n double priority=PyArray_PRIORITY;\n\n\tif (PyArray_CheckExact(obj))\n\t\treturn priority;\n if (PyBigArray_CheckExact(obj)) \n return PyArray_BIG_PRIORITY;\n\n ret = PyObject_GetAttrString(obj, \"__array_priority__\");\n if (ret != NULL) priority = PyFloat_AsDouble(ret);\n if (PyErr_Occurred()) {\n PyErr_Clear(); \n priority = default_;\n }\n Py_XDECREF(ret);\n return priority; \n}\n\n/* Backward compatibility only */\n/* In both Zero and One\n\n ***You must free the memory once you are done with it\n using PyDataMem_FREE(ptr) or you create a memory leak***\n\n If arr is an Object array you are getting a \n BORROWED reference to Zero or One.\n Do not DECREF.\n Please INCREF if you will be hanging on to it.\n\n The memory for the ptr still must be freed in any case;\n*/\n\n\n/*OBJECT_API\n Get pointer to zero of correct type for array.\n*/\nstatic char *\nPyArray_Zero(PyArrayObject *arr)\n{\n char *zeroval;\n int ret, storeflags;\n PyObject *obj;\n\n zeroval = PyDataMem_NEW(arr->descr->elsize);\n if (zeroval == NULL) {\n PyErr_SetNone(PyExc_MemoryError);\n return NULL;\n }\n\n\tobj=PyInt_FromLong((long) 0);\n if (PyArray_ISOBJECT(arr)) {\n memcpy(zeroval, &obj, sizeof(PyObject *));\n Py_DECREF(obj);\n return zeroval;\n }\n\tstoreflags = arr->flags;\n\tarr->flags |= BEHAVED_FLAGS;\n ret = arr->descr->f->setitem(obj, zeroval, arr);\n\tarr->flags = storeflags;\n\tPy_DECREF(obj);\n\tif (ret < 0) {\n\t\tPyDataMem_FREE(zeroval);\n\t\treturn NULL;\n\t}\n return zeroval;\n}\n\n/*OBJECT_API\n Get pointer to one of correct type for array\n*/\nstatic char *\nPyArray_One(PyArrayObject *arr)\n{\n char *oneval;\n int ret, storeflags;\n PyObject *obj;\n\n oneval = PyDataMem_NEW(arr->descr->elsize);\n if (oneval == NULL) {\n PyErr_SetNone(PyExc_MemoryError);\n return NULL;\n }\n\n obj = PyInt_FromLong((long) 1);\n if (PyArray_ISOBJECT(arr)) {\n memcpy(oneval, &obj, sizeof(PyObject *));\n Py_DECREF(obj);\n return oneval;\n } \n\n\tstoreflags = arr->flags;\n\tarr->flags |= BEHAVED_FLAGS;\n ret = arr->descr->f->setitem(obj, oneval, arr);\n\tarr->flags = storeflags;\n Py_DECREF(obj);\n if (ret < 0) {\n PyDataMem_FREE(oneval);\n return NULL;\n }\n return oneval;\n}\n\n/* End deprecated */\n\n\nstatic int \ndo_sliced_copy(char *dest, intp *dest_strides, intp *dest_dimensions,\n\t int dest_nd, char *src, intp *src_strides, \n\t intp *src_dimensions, int src_nd, int elsize, \n\t int copies) {\n intp i, j;\n\t\n if (src_nd == 0 && dest_nd == 0) {\n for(j=0; j src_nd) {\n for(i=0; i<*dest_dimensions; i++, dest += *dest_strides) {\n if (do_sliced_copy(dest, dest_strides+1, \n dest_dimensions+1, dest_nd-1,\n src, src_strides, \n src_dimensions, src_nd, \n elsize, copies) == -1) \n return -1;\n }\n return 0;\n }\n\t\n if (dest_nd == 1) {\n if (*dest_dimensions != *src_dimensions) {\n PyErr_SetString(PyExc_ValueError, \n \"matrices are not aligned for copy\");\n return -1;\n }\n for(i=0; i<*dest_dimensions; i++, src += *src_strides) {\n for(j=0; j 0) {\n if (((*dest_strides)[*dest_nd-1] == *elsize) && \n ((*src_strides)[*src_nd-1] == *elsize)) {\n if ((*dest_dimensions)[*dest_nd-1] != \n (*src_dimensions)[*src_nd-1]) {\n\t\t\t\tPyErr_SetString(PyExc_ValueError, \n\t\t\t\t\t\t\"matrices are not aligned\");\n return -1;\n }\n *elsize *= (*dest_dimensions)[*dest_nd-1];\n *dest_nd-=1; *src_nd-=1;\n } else {\n break;\n }\n }\n if (*src_nd == 0) {\n while (*dest_nd > 0) {\n if (((*dest_strides)[*dest_nd-1] == *elsize)) {\n *copies *= (*dest_dimensions)[*dest_nd-1];\n *dest_nd-=1;\n } else {\n break;\n }\n }\n }\n return 0;\n}\n\nstatic char *\ncontiguous_data(PyArrayObject *src) \n{\n intp dest_strides[MAX_DIMS], *dest_strides_ptr;\n intp *dest_dimensions=src->dimensions;\n int dest_nd=src->nd;\n intp *src_strides = src->strides;\n intp *src_dimensions=src->dimensions;\n int src_nd=src->nd;\n int elsize=src->descr->elsize;\n int copies=1;\n int ret, i;\n intp stride=elsize;\n char *new_data;\n\t\n for(i=dest_nd-1; i>=0; i--) {\n dest_strides[i] = stride;\n stride *= dest_dimensions[i];\n }\n\t\n dest_strides_ptr = dest_strides;\n\t\n if (optimize_slices(&dest_strides_ptr, &dest_dimensions, &dest_nd,\n &src_strides, &src_dimensions, &src_nd,\n &elsize, &copies) == -1) \n return NULL;\n\t\n new_data = (char *)_pya_malloc(stride);\n\t\n ret = do_sliced_copy(new_data, dest_strides_ptr, dest_dimensions, \n dest_nd, src->data, src_strides, \n src_dimensions, src_nd, elsize, copies);\n\t\n if (ret != -1) { return new_data; }\n else { _pya_free(new_data); return NULL; }\n}\n\n/* end Helper functions */\n\n\nstatic PyObject *PyArray_New(PyTypeObject *, int nd, intp *, \n int, intp *, void *, int, int, PyObject *);\n\n/* C-API functions */\n\n/* Used for arrays of python objects to increment the reference count of */\n/* every python object in the array. */\n/*OBJECT_API\n For object arrays, increment all internal references.\n*/\nstatic int \nPyArray_INCREF(PyArrayObject *mp) \n{\n\tintp i, n;\n\n PyObject **data, **data2;\n\t\n if (mp->descr->type_num != PyArray_OBJECT) return 0;\n\t\n if (PyArray_ISONESEGMENT(mp)) {\n data = (PyObject **)mp->data;\n } else {\n if ((data = (PyObject **)contiguous_data(mp)) == NULL) \n return -1;\n }\n\t\n n = PyArray_SIZE(mp);\n data2 = data;\n for(i=0; idescr->type_num != PyArray_OBJECT) return 0;\n\t\n if (PyArray_ISONESEGMENT(mp)) {\n data = (PyObject **)mp->data;\n } else {\n if ((data = (PyObject **)contiguous_data(mp)) == NULL) \n return -1;\n }\n\t\n n = PyArray_SIZE(mp);\n data2 = data; \n for(i=0; i 0; n--, a += 1) {\n b = a + 1;\n c = *a; *a++ = *b; *b = c;\n }\n break;\n case 4:\n for (a = (char*)p ; n > 0; n--, a += 2) {\n b = a + 3;\n c = *a; *a++ = *b; *b-- = c;\n c = *a; *a++ = *b; *b = c;\n }\n break;\n case 8:\n for (a = (char*)p ; n > 0; n--, a += 4) {\n b = a + 7;\n c = *a; *a++ = *b; *b-- = c;\n c = *a; *a++ = *b; *b-- = c;\n c = *a; *a++ = *b; *b-- = c;\n c = *a; *a++ = *b; *b = c;\n }\n break;\n default:\n m = size / 2;\n for (a = (char *)p ; n > 0; n--, a += m) {\n b = a + (size-1);\n for (j=0; j 1, then dst must be contiguous */\nstatic void\ncopy_and_swap(void *dst, void *src, int itemsize, intp numitems,\n intp srcstrides, int swap) \n{\n int i;\n char *s1 = (char *)src;\n char *d1 = (char *)dst;\n \n\n if ((numitems == 1) || (itemsize == srcstrides)) \n memcpy(d1, s1, itemsize*numitems);\n else { \n for (i = 0; i < numitems; i++) {\n memcpy(d1, s1, itemsize);\n d1 += itemsize;\n s1 += srcstrides;\n } \n }\n\n if (swap)\n byte_swap_vector(d1, numitems, itemsize);\n}\n\nstatic PyArray_Descr **userdescrs=NULL;\n#define error_converting(x) (((x) == -1) && PyErr_Occurred())\n\n/* Computer-generated arraytype and scalartype code */\n#include \"scalartypes.inc\"\n#include \"arraytypes.inc\"\n\n\n/* Helper functions */\n\n/*OBJECT_API*/\nstatic intp\nPyArray_PyIntAsIntp(PyObject *o)\n{\n\tlonglong long_value = -1;\n\tPyObject *obj;\n\tstatic char *msg = \"an integer is required\";\n\tPyObject *arr;\n\tPyArray_Descr *descr;\n\tintp ret;\n\n\tif (!o) {\n\t\tPyErr_SetString(PyExc_TypeError, msg);\n\t\treturn -1;\n\t}\n\n\tif (PyInt_Check(o)) {\n\t\tlong_value = (longlong) PyInt_AS_LONG(o);\n\t\tgoto finish;\n\t} else if (PyLong_Check(o)) {\n\t\tlong_value = (longlong) PyLong_AsLongLong(o);\n\t\tgoto finish;\n\t}\n\n#if SIZEOF_INTP == SIZEOF_LONG \n\tdescr = &LONG_Descr;\n#elif SIZEOF_INTP == SIZEOF_INT\n\tdescr = &INT_Descr;\n#else\n\tdescr = &LONGLONG_DESCR;\n#endif\n\tarr = NULL;\n\n\tif (PyArray_Check(o)) {\n\t\tif (PyArray_SIZE(o)!=1 || !PyArray_ISINTEGER(o)) {\n\t\t\tPyErr_SetString(PyExc_TypeError, msg);\n\t\t\treturn -1;\n\t\t}\n\t\tPy_INCREF(descr);\n\t\tarr = PyArray_CastToType((PyArrayObject *)o, descr, 0);\n\t}\n\telse if (PyArray_IsScalar(o, Integer)) {\n\t\tPy_INCREF(descr);\n\t\tarr = PyArray_FromScalar(o, descr);\n\t}\n\tif (arr != NULL) {\n\t\tret = *((intp *)PyArray_DATA(arr));\n\t\tPy_DECREF(arr);\n\t\treturn ret;\n\t}\t\t\n\tif (o->ob_type->tp_as_number != NULL &&\t\t\t\\\n\t o->ob_type->tp_as_number->nb_long != NULL) {\n\t\tobj = o->ob_type->tp_as_number->nb_long(o);\n\t\tif (obj != NULL) {\n\t\t\tlong_value = (longlong) PyLong_AsLongLong(obj);\n\t\t\tPy_DECREF(obj);\n\t\t}\n\t}\n\telse if (o->ob_type->tp_as_number != NULL &&\t\t\\\n\t\t o->ob_type->tp_as_number->nb_int != NULL) {\n\t\tobj = o->ob_type->tp_as_number->nb_int(o);\n\t\tif (obj != NULL) {\n\t\t\tlong_value = (longlong) PyLong_AsLongLong(obj);\n\t\t\tPy_DECREF(obj);\n\t\t}\n\t}\n\telse {\n\t\tPyErr_SetString(PyExc_NotImplementedError,\"\");\n\t}\n\t\n finish:\n\tif error_converting(long_value) {\n\t\tPyErr_SetString(PyExc_TypeError, msg);\n\t\treturn -1;\n\t}\n\t\n#if (SIZEOF_LONGLONG > SIZEOF_INTP)\n\tif ((long_value < MIN_INTP) || (long_value > MAX_INTP)) {\n\t\tPyErr_SetString(PyExc_ValueError,\n\t\t\t\t\"integer won't fit into a C intp\");\n\t\treturn -1;\n\t}\n#endif\n\treturn (intp) long_value;\n}\n\n\nstatic PyObject *array_int(PyArrayObject *v);\n\n/*OBJECT_API*/\nstatic int\nPyArray_PyIntAsInt(PyObject *o)\n{\n\tlong long_value = -1;\n\tPyObject *obj;\n\tstatic char *msg = \"an integer is required\";\n\tPyObject *arr;\n\tPyArray_Descr *descr;\n\tint ret;\n\n\t\n\tif (!o) {\n\t\tPyErr_SetString(PyExc_TypeError, msg);\n\t\treturn -1;\n\t}\n\n\tif (PyInt_Check(o)) {\n\t\tlong_value = (long) PyInt_AS_LONG(o);\n\t\tgoto finish;\n\t} else if (PyLong_Check(o)) {\n\t\tlong_value = (long) PyLong_AsLong(o);\n\t\tgoto finish;\n\t}\n\n\tdescr = &INT_Descr;\n\tarr=NULL;\n\tif (PyArray_Check(o)) {\n\t\tif (PyArray_SIZE(o)!=1 || !PyArray_ISINTEGER(o)) {\n\t\t\tPyErr_SetString(PyExc_TypeError, msg);\n\t\t\treturn -1;\n\t\t}\n\t\tPy_INCREF(descr);\n\t\tarr = PyArray_CastToType((PyArrayObject *)o, descr, 0);\n\t}\n\tif (PyArray_IsScalar(o, Integer)) {\n\t\tPy_INCREF(descr);\n\t\tarr = PyArray_FromScalar(o, descr);\n\t}\n\tif (arr != NULL) {\n\t\tret = *((int *)PyArray_DATA(arr));\n\t\tPy_DECREF(arr);\n\t\treturn ret;\n\t}\t\t\n\tif (o->ob_type->tp_as_number != NULL &&\t\t\\\n\t o->ob_type->tp_as_number->nb_int != NULL) {\n\t\tobj = o->ob_type->tp_as_number->nb_int(o);\n\t\tif (obj == NULL) return -1;\n\t\tlong_value = (long) PyLong_AsLong(obj);\n\t\tPy_DECREF(obj);\n\t}\n\telse if (o->ob_type->tp_as_number != NULL &&\t\t\t\\\n\t\t o->ob_type->tp_as_number->nb_long != NULL) {\n\t\tobj = o->ob_type->tp_as_number->nb_long(o);\n\t\tif (obj == NULL) return -1;\n\t\tlong_value = (long) PyLong_AsLong(obj);\n\t\tPy_DECREF(obj);\n\t}\t\t\n\telse {\n\t\tPyErr_SetString(PyExc_NotImplementedError,\"\");\n\t}\n\n finish:\n\tif error_converting(long_value) {\n\t\tPyErr_SetString(PyExc_TypeError, msg);\n\t\treturn -1;\n\t}\n\t\n#if (SIZEOF_LONG > SIZEOF_INT)\n\tif ((long_value < INT_MIN) || (long_value > INT_MAX)) {\n\t\tPyErr_SetString(PyExc_ValueError,\n\t\t\t\t\"integer won't fit into a C int\");\n\t\treturn -1;\n\t}\n#endif\n\treturn (int) long_value;\n}\n\nstatic char *\nindex2ptr(PyArrayObject *mp, intp i) \n{\n\tif(mp->nd == 0) {\n\t\tPyErr_SetString(PyExc_IndexError, \n\t\t\t\t\"0-d arrays can't be indexed\");\n\t\treturn NULL;\n\t}\n\tif (i==0 && mp->dimensions[0] > 0)\n\t\treturn mp->data;\n\t\n if (mp->nd>0 && i>0 && i < mp->dimensions[0]) {\n return mp->data+i*mp->strides[0];\n }\n PyErr_SetString(PyExc_IndexError,\"index out of bounds\");\n return NULL;\n}\n\n/*OBJECT_API\n Compute the size of an array (in number of items)\n*/\nstatic intp \nPyArray_Size(PyObject *op) \n{\n if (PyArray_Check(op)) {\n return PyArray_SIZE((PyArrayObject *)op);\n } \n\telse {\n return 0;\n }\n}\n\n/* If destination is not the right type, then src \n will be cast to destination. \n*/\n\n/* Does a flat iterator-based copy. \n\n The arrays are assumed to have the same number of elements\n They can be different sizes and have different types however. \n*/\n\n/*OBJECT_API\n Copy an Array into another array.\n*/\nstatic int\nPyArray_CopyInto(PyArrayObject *dest, PyArrayObject *src)\n{\n intp dsize, ssize, sbytes, ncopies;\n\tint elsize, index;\n PyArrayIterObject *dit=NULL;\n PyArrayIterObject *sit=NULL;\n\tchar *dptr;\n\tint swap;\n PyArray_CopySwapFunc *copyswap;\n PyArray_CopySwapNFunc *copyswapn;\n \n if (!PyArray_ISWRITEABLE(dest)) {\n PyErr_SetString(PyExc_RuntimeError, \n \"cannot write to array\");\n return -1;\n }\n\n if (!PyArray_EquivArrTypes(dest, src)) {\n return PyArray_CastTo(dest, src);\n }\n\n dsize = PyArray_SIZE(dest);\n ssize = PyArray_SIZE(src);\n\tif (ssize == 0) return 0;\n if (dsize % ssize != 0) {\n PyErr_SetString(PyExc_ValueError, \n \"number of elements in destination must be \"\\\n \"integer multiple of number of \"\\\n \"elements in source\");\n return -1;\n }\n ncopies = (dsize / ssize);\n\n\tswap = PyArray_ISNOTSWAPPED(dest) != PyArray_ISNOTSWAPPED(src);\n\tcopyswap = dest->descr->f->copyswap;\n\tcopyswapn = dest->descr->f->copyswapn;\n\n elsize = dest->descr->elsize;\n\n if ((PyArray_ISCONTIGUOUS(dest) && PyArray_ISCONTIGUOUS(src))\t\\\n\t || (PyArray_ISFORTRAN(dest) && PyArray_ISFORTRAN(src))) {\n \n PyArray_XDECREF(dest);\n dptr = dest->data;\n sbytes = ssize * src->descr->elsize;\n while(ncopies--) {\n memmove(dptr, src->data, sbytes);\n dptr += sbytes;\n }\n\t\tif (swap)\n\t\t\tcopyswapn(dest->data, NULL, dsize, 1, elsize);\n PyArray_INCREF(dest);\n return 0;\n }\n\n dit = (PyArrayIterObject *)PyArray_IterNew((PyObject *)dest);\n sit = (PyArrayIterObject *)PyArray_IterNew((PyObject *)src);\n\n if ((dit == NULL) || (sit == NULL)) {\n Py_XDECREF(dit);\n Py_XDECREF(sit);\n return -1;\n }\n\n PyArray_XDECREF(dest);\n while(ncopies--) {\n index = ssize;\n while(index--) {\n memmove(dit->dataptr, sit->dataptr, elsize);\n\t\t\tif (swap)\n\t\t\t\tcopyswap(dit->dataptr, NULL, 1, elsize);\n PyArray_ITER_NEXT(dit);\n PyArray_ITER_NEXT(sit);\n }\n PyArray_ITER_RESET(sit);\n } \n PyArray_INCREF(dest);\n Py_DECREF(dit);\n Py_DECREF(sit);\n\treturn 0;\n}\n\n\nstatic int \nPyArray_CopyObject(PyArrayObject *dest, PyObject *src_object) \n{\n PyArrayObject *src;\n int ret;\n\n\tPy_INCREF(dest->descr);\n src = (PyArrayObject *)PyArray_FromAny(src_object,\n dest->descr, 0,\n dest->nd, FORTRAN_IF(dest), NULL);\n if (src == NULL) return -1;\n\n ret = PyArray_CopyInto(dest, src);\n Py_DECREF(src);\n return ret;\n}\n\n\n/* These are also old calls (should use PyArray_New) */\n\n/* They all zero-out the memory as previously done */\n\n/* steals reference to descr -- and enforces native byteorder on it.*/\n/*OBJECT_API\n Like FromDimsAndData but uses the Descr structure instead of typecode\n as input.\n*/\nstatic PyObject *\nPyArray_FromDimsAndDataAndDescr(int nd, int *d, \n PyArray_Descr *descr,\n char *data)\n{\n\tPyObject *ret;\n#if SIZEOF_INTP != SIZEOF_INT\n\tint i;\n\tintp newd[MAX_DIMS];\n#endif\n\n\tif (!PyArray_ISNBO(descr->byteorder))\n\t\tdescr->byteorder = '=';\n\t\n#if SIZEOF_INTP != SIZEOF_INT\n\tfor (i=0; itype_num != PyArray_OBJECT)) {\n\t\tmemset(PyArray_DATA(ret), 0, PyArray_NBYTES(ret));\n\t}\n\treturn ret;\n}\n\n/* end old calls */\n\n\n/*OBJECT_API\n Copy an array.\n*/\nstatic PyObject *\nPyArray_NewCopy(PyArrayObject *m1, int fortran)\n{\n\tPyArrayObject *ret;\n\tif (fortran < 0) fortran = PyArray_ISFORTRAN(m1);\n\t\n\tPy_INCREF(m1->descr);\n\tret = (PyArrayObject *)PyArray_NewFromDescr(m1->ob_type, \n\t\t\t\t\t\t m1->descr,\n\t\t\t\t\t\t m1->nd, \n\t\t\t\t\t\t m1->dimensions,\n\t\t\t\t\t\t NULL, NULL, \n\t\t\t\t\t\t fortran, \n\t\t\t\t\t\t (PyObject *)m1);\n\tif (ret == NULL) return NULL;\n if (PyArray_CopyInto(ret, m1) == -1) {\n Py_DECREF(ret);\n return NULL;\n }\n\t\n return (PyObject *)ret;\t\n}\n\nstatic PyObject *array_big_item(PyArrayObject *, intp);\n\n/* Does nothing with descr (cannot be NULL) */\n/*OBJECT_API\n Get scalar-equivalent to a region of memory described by a descriptor.\n*/\nstatic PyObject *\nPyArray_Scalar(void *data, PyArray_Descr *descr, PyObject *base)\n{\n\tPyTypeObject *type;\n\tPyObject *obj;\n void *destptr;\n PyArray_CopySwapFunc *copyswap;\n\tint type_num;\n\tint itemsize;\n\tint swap;\n\n\ttype_num = descr->type_num;\n\tif (type_num == PyArray_BOOL)\n\t\tPyArrayScalar_RETURN_BOOL_FROM_LONG(*(Bool*)data);\n\telse if (type_num == PyArray_OBJECT) {\n\t\tPy_INCREF(*((PyObject **)data));\n\t\treturn *((PyObject **)data);\n\t}\n\titemsize = descr->elsize;\n type = descr->typeobj;\n copyswap = descr->f->copyswap;\n\tswap = !PyArray_ISNBO(descr->byteorder);\n\tif (type->tp_itemsize != 0) /* String type */\n\t\tobj = type->tp_alloc(type, itemsize);\n\telse\n\t\tobj = type->tp_alloc(type, 0);\n\tif (obj == NULL) return NULL;\n\tif PyTypeNum_ISEXTENDED(type_num) { \n\t\tif (type_num == PyArray_STRING) {\n\t\t\tdestptr = PyString_AS_STRING(obj);\n\t\t\t((PyStringObject *)obj)->ob_shash = -1;\n\t\t\t((PyStringObject *)obj)->ob_sstate =\t\\\n\t\t\t\tSSTATE_NOT_INTERNED; \n\t\t}\n\t\telse if (type_num == PyArray_UNICODE) {\n\t\t\tPyUnicodeObject *uni = (PyUnicodeObject*)obj;\n\t\t\tint length = itemsize / sizeof(Py_UNICODE);\n\t\t\t/* Need an extra slot and need to use \n\t\t\t Python memory manager */\n\t\t\tuni->str = NULL;\n\t\t\tdestptr = PyMem_NEW(Py_UNICODE, length+1);\n\t\t\tif (destptr == NULL) {\n Py_DECREF(obj);\n\t\t\t\treturn PyErr_NoMemory();\n\t\t\t}\n\t\t\tuni->str = (Py_UNICODE *)destptr;\n\t\t\tuni->str[0] = 0;\n\t\t\tuni->str[length] = 0;\n\t\t\tuni->length = length;\n\t\t\tuni->hash = -1;\n\t\t\tuni->defenc = NULL;\n\t\t}\n\t\telse { \n\t\t\tPyVoidScalarObject *vobj = (PyVoidScalarObject *)obj;\n\t\t\tvobj->base = NULL;\n\t\t\tvobj->descr = descr;\n\t\t\tPy_INCREF(descr);\n\t\t\tvobj->obval = NULL;\n\t\t\tvobj->ob_size = itemsize;\n\t\t\tvobj->flags = BEHAVED_FLAGS | OWNDATA;\n\t\t\tswap = 0;\n\t\t\tif (descr->fields) {\n\t\t\t\tif (base) {\n\t\t\t\t\tPy_INCREF(base);\n\t\t\t\t\tvobj->base = base;\n\t\t\t\t\tvobj->flags = PyArray_FLAGS(base);\n\t\t\t\t\tvobj->flags &= ~OWNDATA;\n\t\t\t\t\tvobj->obval = data;\n\t\t\t\t\treturn obj;\n\t\t\t\t}\n\t\t\t}\n\t\t\tdestptr = PyDataMem_NEW(itemsize);\n\t\t\tif (destptr == NULL) {\n Py_DECREF(obj);\n\t\t\t\treturn PyErr_NoMemory();\n\t\t\t}\n\t\t\tvobj->obval = destptr;\n\t\t}\n\t}\n\telse {\n\t\tdestptr = _SOFFSET_(obj, type_num);\n\t}\n\t/* copyswap for OBJECT increments the reference count */\n copyswap(destptr, data, swap, itemsize);\n\treturn obj;\n}\n\n/* returns an Array-Scalar Object of the type of arr\n from the given pointer to memory -- main Scalar creation function\n default new method calls this. \n*/\n\n/* Ideally, here the descriptor would contain all the information needed.\n So, that we simply need the data and the descriptor, and perhaps\n a flag \n*/\n\n/*OBJECT_API\n Get scalar-equivalent to 0-d array\n*/\nstatic PyObject *\nPyArray_ToScalar(void *data, PyArrayObject *arr)\n{\n\treturn PyArray_Scalar(data, arr->descr, (PyObject *)arr);\n}\n\n\n/* Return Python scalar if 0-d array object is encountered */\n\n/*OBJECT_API\n Return either an array or the appropriate Python object if the array\n is 0d and matches a Python type.\n*/\nstatic PyObject *\nPyArray_Return(PyArrayObject *mp) \n{\n \n\n\tif (mp == NULL) return NULL;\n\n if (PyErr_Occurred()) {\n Py_XDECREF(mp);\n return NULL;\n }\n\n\tif (!PyArray_Check(mp)) return (PyObject *)mp;\n\t\n\tif (mp->nd == 0) {\n\t\tPyObject *ret;\n\t\tret = PyArray_ToScalar(mp->data, mp);\n\t\tPy_DECREF(mp);\n\t\treturn ret;\n\t}\n\telse {\n\t\treturn (PyObject *)mp;\n\t}\n}\n\n/*\n returns typenum to associate with this type >=PyArray_USERDEF.\n Also creates a copy of the VOID_DESCR table inserting it's typeobject in\n and it's typenum in the appropriate place.\n \n needs the userdecrs table and PyArray_NUMUSER variables\n defined in arratypes.inc\n*/\n/*OBJECT_API\n Register Data type\n*/\nstatic int \nPyArray_RegisterDataType(PyTypeObject *type)\n{\n\tPyArray_Descr *descr;\n\tPyObject *obj;\n\tint typenum;\n\tint i;\n\t\n\tif ((type == &PyVoidArrType_Type) ||\t\t\t\\\n\t !PyType_IsSubtype(type, &PyVoidArrType_Type)) {\n\t\tPyErr_SetString(PyExc_ValueError, \n\t\t\t\t\"can only register void subtypes\");\n\t\treturn -1;\n\t}\n\t/* See if this type is already registered */\n\tfor (i=0; itypeobj == type)\n\t\t\treturn descr->type_num;\n\t}\n\tdescr = PyArray_DescrNewFromType(PyArray_VOID);\n\ttypenum = PyArray_USERDEF + PyArray_NUMUSERTYPES;\n\tdescr->type_num = typenum;\n descr->typeobj = type;\n\tobj = PyObject_GetAttrString((PyObject *)type,\"itemsize\");\n\tif (obj) {\n\t\ti = PyInt_AsLong(obj);\n\t\tif ((i < 0) && (PyErr_Occurred())) PyErr_Clear();\n\t\telse descr->elsize = i;\n\t\tPy_DECREF(obj);\n\t}\n\tPy_INCREF(type);\n\tuserdescrs = realloc(userdescrs, \n\t\t\t (PyArray_NUMUSERTYPES+1)*sizeof(void *));\n if (userdescrs == NULL) {\n PyErr_SetString(PyExc_MemoryError, \"RegisterDataType\");\n\t\tPy_DECREF(descr);\n return -1;\n }\n\tuserdescrs[PyArray_NUMUSERTYPES++] = descr;\n\treturn typenum;\n}\n\n\n/* \n copyies over from the old descr table for anything\n NULL or zero in what is given. \n DECREF's the Descr already there.\n places a pointer to the new one into the slot.\n*/\n\n/* steals a reference to descr */\n/*OBJECT_API\n Insert Descr Table\n*/\nstatic int\nPyArray_RegisterDescrForType(int typenum, PyArray_Descr *descr)\n{\n\tPyArray_Descr *old;\n\n\tif (!PyTypeNum_ISUSERDEF(typenum)) {\n\t\tPyErr_SetString(PyExc_TypeError, \n\t\t\t\t\"data type not registered\");\n\t\tPy_DECREF(descr);\n\t\treturn -1;\n\t}\n\told = userdescrs[typenum-PyArray_USERDEF];\n\tdescr->typeobj = old->typeobj;\n\tdescr->type_num = typenum;\n\n\tif (descr->f == NULL) descr->f = old->f;\n\tif (descr->fields == NULL) {\n\t\tdescr->fields = old->fields;\n\t\tPy_XINCREF(descr->fields);\n\t}\n\tif (descr->subarray == NULL && old->subarray) {\n\t\tdescr->subarray = _pya_malloc(sizeof(PyArray_ArrayDescr));\n\t\tmemcpy(descr->subarray, old->subarray, \n\t\t sizeof(PyArray_ArrayDescr));\n\t\tPy_INCREF(descr->subarray->shape);\n\t\tPy_INCREF(descr->subarray->base);\n\t}\n Py_XINCREF(descr->typeobj);\n\n#define _ZERO_CHECK(member) \\\n\tif (descr->member == 0) descr->member = old->member\n\n\t_ZERO_CHECK(kind);\n\t_ZERO_CHECK(type);\n _ZERO_CHECK(byteorder);\n\t_ZERO_CHECK(elsize);\n\t_ZERO_CHECK(alignment);\n#undef _ZERO_CHECK\n\n\tPy_DECREF(old);\n\tuserdescrs[typenum-PyArray_USERDEF] = descr;\n\treturn 0;\n}\n\n\n/*OBJECT_API\n To File\n*/\nstatic int\nPyArray_ToFile(PyArrayObject *self, FILE *fp, char *sep, char *format) \n{\n intp size;\n intp n, n2;\n int n3, n4;\n PyArrayIterObject *it;\n PyObject *obj, *strobj, *tupobj;\n\n\tn3 = (sep ? strlen((const char *)sep) : 0);\n\tif (n3 == 0) { /* binary data */\n if (PyArray_ISOBJECT(self)) {\n PyErr_SetString(PyExc_ValueError, \"cannot write \"\\\n\t\t\t\t\t\"object arrays to a file in \"\t\\\n\t\t\t\t\t\"binary mode\");\n return -1;\n }\n\n if (PyArray_ISCONTIGUOUS(self)) {\n size = PyArray_SIZE(self);\n if ((n=fwrite((const void *)self->data, \n (size_t) self->descr->elsize,\n (size_t) size, fp)) < size) {\n PyErr_Format(PyExc_ValueError, \n \"%ld requested and %ld written\",\n (long) size, (long) n);\n return -1;\n }\n }\n else {\n it=(PyArrayIterObject *) \\\n PyArray_IterNew((PyObject *)self);\n while(it->index < it->size) {\n if (fwrite((const void *)it->dataptr, \n (size_t) self->descr->elsize,\n 1, fp) < 1) {\n PyErr_Format(PyExc_IOError, \n \"problem writing element\"\\\n \" %d to file\", \n\t\t\t\t\t\t (int)it->index);\n Py_DECREF(it);\n return -1;\n }\n PyArray_ITER_NEXT(it);\n }\n Py_DECREF(it);\n } \n }\n else { /* text data */\n it=(PyArrayIterObject *) \\\n PyArray_IterNew((PyObject *)self);\n\t\tn4 = (format ? strlen((const char *)format) : 0);\n while(it->index < it->size) {\n obj = self->descr->f->getitem(it->dataptr, self);\n if (obj == NULL) {Py_DECREF(it); return -1;}\n\t\t\tif (n4 == 0) { /* standard writing */\n\t\t\t\tstrobj = PyObject_Str(obj);\n\t\t\t\tPy_DECREF(obj);\n\t\t\t\tif (strobj == NULL) {Py_DECREF(it); return -1;}\n\t\t\t}\n\t\t\telse { /* use format string */\n\t\t\t\ttupobj = PyTuple_New(1);\n\t\t\t\tif (tupobj == NULL) {Py_DECREF(it); return -1;}\n\t\t\t\tPyTuple_SET_ITEM(tupobj,0,obj);\n\t\t\t\tobj = PyString_FromString((const char *)format);\n\t\t\t\tif (obj == NULL) {Py_DECREF(tupobj); \n\t\t\t\t\tPy_DECREF(it); return -1;}\n\t\t\t\tstrobj = PyString_Format(obj, tupobj);\n\t\t\t\tPy_DECREF(obj);\n\t\t\t\tPy_DECREF(tupobj);\n\t\t\t\tif (strobj == NULL) {Py_DECREF(it); return -1;}\n\t\t\t}\n if ((n=fwrite(PyString_AS_STRING(strobj), \n 1, n2=PyString_GET_SIZE(strobj),\n fp)) < n2) {\n PyErr_Format(PyExc_IOError,\n \"problem writing element %d\"\\\n \" to file\", \n\t\t\t\t\t (int) it->index);\n Py_DECREF(strobj);\n Py_DECREF(it);\n return -1;\n }\n /* write separator for all but last one */\n if (it->index != it->size-1) \n fwrite(sep, 1, n3, fp);\n Py_DECREF(strobj);\n PyArray_ITER_NEXT(it);\n }\n Py_DECREF(it);\n }\n return 0;\n}\n\n/*OBJECT_API\n To List\n*/\nstatic PyObject *\nPyArray_ToList(PyArrayObject *self) \n{\n PyObject *lp;\n PyArrayObject *v;\n intp sz, i;\n\t\n if (!PyArray_Check(self)) return (PyObject *)self;\n\n if (self->nd == 0) \n\t\treturn self->descr->f->getitem(self->data,self);\n\t\n sz = self->dimensions[0];\n lp = PyList_New(sz);\n\t\n for (i=0; ind >= self->nd) {\n\t\t\tPyErr_SetString(PyExc_RuntimeError,\n\t\t\t\t\t\"array_item not returning smaller-\" \\\n\t\t\t\t\t\"dimensional array\");\n Py_DECREF(v);\n\t\t\tPy_DECREF(lp);\n\t\t\treturn NULL;\n\t\t}\n PyList_SetItem(lp, i, PyArray_ToList(v));\n\t\tPy_DECREF(v);\n }\n\t\n return lp;\n}\n\nstatic PyObject *\nPyArray_ToString(PyArrayObject *self)\n{\n intp numbytes;\n intp index;\n char *dptr;\n int elsize;\n PyObject *ret;\n PyArrayIterObject *it;\n \n\t/* if (PyArray_TYPE(self) == PyArray_OBJECT) {\n\t\t PyErr_SetString(PyExc_ValueError, \"a string for the data\" \\\n\t\t \"in an object array is not appropriate\");\n\t\t return NULL;\n\t\t }\n\t*/\n\n numbytes = PyArray_NBYTES(self);\n if (PyArray_ISONESEGMENT(self)) {\n ret = PyString_FromStringAndSize(self->data, (int) numbytes);\n }\n else {\n it = (PyArrayIterObject *)PyArray_IterNew((PyObject *)self);\n if (it==NULL) return NULL;\n ret = PyString_FromStringAndSize(NULL, (int) numbytes);\n if (ret == NULL) {Py_DECREF(it); return NULL;}\n dptr = PyString_AS_STRING(ret);\n index = it->size;\n elsize = self->descr->elsize;\n while(index--) {\n memcpy(dptr, it->dataptr, elsize);\n dptr += elsize;\n PyArray_ITER_NEXT(it);\n }\n Py_DECREF(it);\n }\n\treturn ret;\n}\n\n\n/*********************** end C-API functions **********************/\n\n\n/* array object functions */\n\nstatic void \narray_dealloc(PyArrayObject *self) {\n\n if (self->weakreflist != NULL)\n PyObject_ClearWeakRefs((PyObject *)self);\n\n if(self->base) {\n\t\t/* UPDATEIFCOPY means that base points to an \n\t\t array that should be updated with the contents\n\t\t of this array upon destruction.\n self->base->flags must have been WRITEABLE \n (checked previously) and it was locked here\n thus, unlock it.\n\t\t*/\n\t\tif (self->flags & UPDATEIFCOPY) {\n ((PyArrayObject *)self->base)->flags |= WRITEABLE;\n\t\t\tPy_INCREF(self); /* hold on to self in next call */\n PyArray_CopyInto((PyArrayObject *)self->base, self);\n\t\t\t/* Don't need to DECREF -- because we are deleting\n\t\t\t self already... */\n\t\t}\n\t\t/* In any case base is pointing to something that we need\n\t\t to DECREF -- either a view or a buffer object */\n Py_DECREF(self->base);\n }\n \n if ((self->flags & OWN_DATA) && self->data) {\n\t\t/* Free internal references if an Object array */\n\t\tif (PyArray_ISOBJECT(self))\n\t\t\tPyArray_XDECREF(self);\n PyDataMem_FREE(self->data);\n }\n\t\n\tPyDimMem_FREE(self->dimensions);\n\n\tPy_DECREF(self->descr);\n\t\n self->ob_type->tp_free((PyObject *)self);\n}\n\n/*************************************************************************\n **************** Implement Mapping Protocol ***************************\n *************************************************************************/\n\nstatic int \narray_length(PyArrayObject *self) \n{\n if (self->nd != 0) {\n return self->dimensions[0];\n } else {\n\t\tPyErr_SetString(PyExc_TypeError, \"len() of unsized object\");\n\t\treturn -1;\n }\n}\n\nstatic PyObject *\narray_big_item(PyArrayObject *self, intp i) \n{\n\tchar *item;\n\tPyArrayObject *r;\n\t\t\n\tif(self->nd == 0) {\n\t\tPyErr_SetString(PyExc_IndexError, \n\t\t\t\t\"0-d arrays can't be indexed\");\n\t\treturn NULL;\n\t}\n if ((item = index2ptr(self, i)) == NULL) return NULL;\n\t\n\tPy_INCREF(self->descr);\n\tr = (PyArrayObject *)PyArray_NewFromDescr(self->ob_type, \n\t\t\t\t\t\t self->descr,\n\t\t\t\t\t\t self->nd-1, \n\t\t\t\t\t\t self->dimensions+1, \n\t\t\t\t\t\t self->strides+1, item, \n\t\t\t\t\t\t self->flags,\n\t\t\t\t\t\t (PyObject *)self);\n\tif (r == NULL) return NULL;\n\tPy_INCREF(self);\n\tr->base = (PyObject *)self;\n PyArray_UpdateFlags(r, CONTIGUOUS | FORTRAN);\n\treturn (PyObject *)r;\n}\n\nstatic PyObject *\narray_item_nice(PyArrayObject *self, int i) \n{\n\treturn PyArray_Return((PyArrayObject *)array_big_item(self, (intp) i));\n}\n\n\nstatic int \narray_ass_big_item(PyArrayObject *self, intp i, PyObject *v) \n{\n PyArrayObject *tmp;\n char *item;\n int ret;\n\n if (v == NULL) {\n PyErr_SetString(PyExc_ValueError, \n \"can't delete array elements\");\n return -1;\n }\n\tif (!PyArray_ISWRITEABLE(self)) {\n\t\tPyErr_SetString(PyExc_RuntimeError,\n\t\t\t\t\"array is not writeable\");\n\t\treturn -1;\n\t}\n if (self->nd == 0) {\n PyErr_SetString(PyExc_IndexError, \n \"0-d arrays can't be indexed.\");\n return -1;\n }\n\n if (i < 0) i = i+self->dimensions[0];\n\n if (self->nd > 1) {\n if((tmp = (PyArrayObject *)array_big_item(self, i)) == NULL)\n return -1;\n ret = PyArray_CopyObject(tmp, v);\n Py_DECREF(tmp);\n return ret; \n }\n\t\n if ((item = index2ptr(self, i)) == NULL) return -1;\n if (self->descr->f->setitem(v, item, self) == -1) return -1;\n return 0;\n}\n\n#if SIZEOF_INT == SIZEOF_INTP\n#define array_ass_item array_ass_big_item\n#else\nstatic int\narray_ass_item(PyArrayObject *self, int i, PyObject *v)\n{\n\treturn array_ass_big_item(self, (intp) i, v);\n}\n#endif\n\n\n/* -------------------------------------------------------------- */\nstatic int\nslice_coerce_index(PyObject *o, intp *v)\n{\n\t*v = PyArray_PyIntAsIntp(o);\n\tif (error_converting(*v)) {\n\t\tPyErr_Clear();\n\t\treturn 0;\n\t}\n\treturn 1;\n}\n\n\n/* This is basically PySlice_GetIndicesEx, but with our coercion\n * of indices to integers (plus, that function is new in Python 2.3) */\nstatic int\nslice_GetIndices(PySliceObject *r, intp length,\n intp *start, intp *stop, intp *step,\n intp *slicelength)\n{\n\tintp defstart, defstop;\n\t\n\tif (r->step == Py_None) {\n\t\t*step = 1;\n\t} else {\n\t\tif (!slice_coerce_index(r->step, step)) return -1;\n\t\tif (*step == 0) {\n\t\t\tPyErr_SetString(PyExc_ValueError, \n\t\t\t\t\t\"slice step cannot be zero\");\n\t\t\treturn -1;\n\t\t}\n\t}\n\t\n\tdefstart = *step < 0 ? length - 1 : 0;\n\tdefstop = *step < 0 ? -1 : length;\n\t\n\tif (r->start == Py_None) {\n\t\t*start = *step < 0 ? length-1 : 0;\n\t} else {\n\t\tif (!slice_coerce_index(r->start, start)) return -1;\n\t\tif (*start < 0) *start += length;\n\t\tif (*start < 0) *start = (*step < 0) ? -1 : 0;\n\t\tif (*start >= length) {\n\t\t\t*start = (*step < 0) ? length - 1 : length;\n\t\t}\n\t}\n\t\n\tif (r->stop == Py_None) {\n\t\t*stop = defstop;\n\t} else {\n\t\tif (!slice_coerce_index(r->stop, stop)) return -1;\n\t\tif (*stop < 0) *stop += length;\n if (*stop < 0) *stop = -1;\n if (*stop > length) *stop = length;\n\t}\n\t\n\tif ((*step < 0 && *stop >= *start) || \\\n\t (*step > 0 && *start >= *stop)) {\n\t\t*slicelength = 0;\n\t} else if (*step < 0) {\n\t\t*slicelength = (*stop - *start + 1) / (*step) + 1;\n\t} else {\n\t\t*slicelength = (*stop - *start - 1) / (*step) + 1;\n\t}\n\t\n\treturn 0;\n}\n\n#define PseudoIndex -1\n#define RubberIndex -2\n#define SingleIndex -3\n\nstatic intp\nparse_subindex(PyObject *op, intp *step_size, intp *n_steps, intp max)\n{\n\tintp index;\n\t\n\tif (op == Py_None) {\n\t\t*n_steps = PseudoIndex;\n\t\tindex = 0;\n\t} else if (op == Py_Ellipsis) {\n\t\t*n_steps = RubberIndex;\n\t\tindex = 0;\n\t} else if (PySlice_Check(op)) {\n\t\tintp stop;\n\t\tif (slice_GetIndices((PySliceObject *)op, max,\n\t\t\t\t &index, &stop, step_size, n_steps) < 0) {\n\t\t\tif (!PyErr_Occurred()) {\n\t\t\t\tPyErr_SetString(PyExc_IndexError, \n\t\t\t\t\t\t\"invalid slice\");\n\t\t\t}\n\t\t\tgoto fail;\n\t\t}\n\t\tif (*n_steps <= 0) {\n\t\t\t*n_steps = 0;\n\t\t\t*step_size = 1;\n\t\t\tindex = 0;\n\t\t}\n\t} else {\n\t\tindex = PyArray_PyIntAsIntp(op);\n\t\tif (error_converting(index)) {\n\t\t\tPyErr_SetString(PyExc_IndexError,\n\t\t\t\t\t\"each subindex must be either a \"\\\n\t\t\t\t\t\"slice, an integer, Ellipsis, or \"\\\n\t\t\t\t\t\"newaxis\");\n\t\t\tgoto fail;\n\t\t}\n\t\t*n_steps = SingleIndex;\n\t\t*step_size = 0;\n\t\tif (index < 0) index += max;\n\t\tif (index >= max || index < 0) {\n\t\t\tPyErr_SetString(PyExc_IndexError, \"invalid index\");\n\t\t\tgoto fail;\n\t\t}\n\t}\n\treturn index;\n fail:\n\treturn -1;\n}\n\n\nstatic int \nparse_index(PyArrayObject *self, PyObject *op, \n intp *dimensions, intp *strides, intp *offset_ptr)\n{\n int i, j, n;\n int nd_old, nd_new, n_add, n_pseudo;\n\tintp n_steps, start, offset, step_size;\n PyObject *op1=NULL;\n int is_slice;\n\n\n if (PySlice_Check(op) || op == Py_Ellipsis || op == Py_None) {\n n = 1;\n op1 = op;\n Py_INCREF(op);\t\n /* this relies on the fact that n==1 for loop below */\n is_slice = 1;\n }\n else {\n if (!PySequence_Check(op)) {\n PyErr_SetString(PyExc_IndexError, \n \"index must be either an int \"\\\n \"or a sequence\");\n return -1;\n }\n n = PySequence_Length(op);\n is_slice = 0;\n }\n\t\n nd_old = nd_new = 0;\n\t\n offset = 0;\n for(i=0; ind ? \\\n self->dimensions[nd_old] : 0);\n Py_DECREF(op1);\n if (start == -1) break;\n\t\t\n if (n_steps == PseudoIndex) {\n dimensions[nd_new] = 1; strides[nd_new] = 0; nd_new++;\n } else {\n if (n_steps == RubberIndex) {\n for(j=i+1, n_pseudo=0; jnd-(n-i-n_pseudo-1+nd_old);\n if (n_add < 0) {\n PyErr_SetString(PyExc_IndexError, \n \"too many indices\");\n return -1;\n }\n for(j=0; jdimensions[nd_old];\n strides[nd_new] = \\\n self->strides[nd_old];\n nd_new++; nd_old++;\n }\n } else {\n if (nd_old >= self->nd) {\n PyErr_SetString(PyExc_IndexError, \n \"too many indices\");\n return -1;\n }\n offset += self->strides[nd_old]*start;\n nd_old++;\n if (n_steps != SingleIndex) {\n dimensions[nd_new] = n_steps;\n strides[nd_new] = step_size * \\\n self->strides[nd_old-1];\n nd_new++;\n }\n }\n }\n }\n if (i < n) return -1;\n n_add = self->nd-nd_old;\n for(j=0; jdimensions[nd_old];\n strides[nd_new] = self->strides[nd_old];\n nd_new++; nd_old++;\n }\t \n *offset_ptr = offset;\n return nd_new;\n}\n\nstatic void\n_swap_axes(PyArrayMapIterObject *mit, PyArrayObject **ret)\n{\n\tPyObject *new;\n\tint n1, n2, n3, val;\n\tint i;\n\tPyArray_Dims permute;\n\tintp d[MAX_DIMS];\n\n\tpermute.ptr = d;\n\tpermute.len = mit->nd;\n\n\t/* tuple for transpose is \n\t (n1,..,n1+n2-1,0,..,n1-1,n1+n2,...,n3-1)\n\t n1 is the number of dimensions of \n\t the broadcasted index array \n\t n2 is the number of dimensions skipped at the\n\t start\n\t n3 is the number of dimensions of the \n\t result \n\t*/\n\tn1 = mit->iters[0]->nd_m1 + 1;\n\tn2 = mit->iteraxes[0];\n\tn3 = mit->nd;\n\tval = n1;\n\ti = 0;\n\twhile(val < n1+n2) \n\t\tpermute.ptr[i++] = val++;\n\tval = 0;\n\twhile(val < n1)\n\t\tpermute.ptr[i++] = val++;\n\tval = n1+n2;\n\twhile(val < n3)\n\t\tpermute.ptr[i++] = val++;\n\n\tnew = PyArray_Transpose(*ret, &permute);\n\tPy_DECREF(*ret);\n\t*ret = (PyArrayObject *)new;\n}\n\n/* Prototypes for Mapping calls --- not part of the C-API\n because only useful as part of a getitem call. \n*/\n\nstatic void PyArray_MapIterReset(PyArrayMapIterObject *);\nstatic void PyArray_MapIterNext(PyArrayMapIterObject *);\nstatic void PyArray_MapIterBind(PyArrayMapIterObject *, PyArrayObject *);\nstatic PyObject* PyArray_MapIterNew(PyObject *, int, int);\n\nstatic PyObject *\nPyArray_GetMap(PyArrayMapIterObject *mit)\n{\n\n\tPyArrayObject *ret, *temp;\n\tPyArrayIterObject *it;\n\tint index;\n\tint swap;\n PyArray_CopySwapFunc *copyswap;\n\n\t/* Unbound map iterator --- Bind should have been called */\n\tif (mit->ait == NULL) return NULL;\n\n\t/* This relies on the map iterator object telling us the shape\n\t of the new array in nd and dimensions.\n\t*/\n\ttemp = mit->ait->ao;\n\tPy_INCREF(temp->descr);\n\tret = (PyArrayObject *)\\\n\t\tPyArray_NewFromDescr(temp->ob_type, \n\t\t\t\t temp->descr,\n\t\t\t\t mit->nd, mit->dimensions, \n\t\t\t\t NULL, NULL, \n\t\t\t\t PyArray_ISFORTRAN(temp),\n\t\t\t\t (PyObject *)temp);\n\tif (ret == NULL) return NULL;\n\n\t/* Now just iterate through the new array filling it in\n\t with the next object from the original array as\n\t defined by the mapping iterator */\n\n\tif ((it = (PyArrayIterObject *)PyArray_IterNew((PyObject *)ret)) \n\t == NULL) {\n\t\tPy_DECREF(ret);\n\t\treturn NULL;\n\t}\n\tindex = it->size;\n\tswap = (PyArray_ISNOTSWAPPED(temp) != PyArray_ISNOTSWAPPED(ret));\n copyswap = ret->descr->f->copyswap;\n\tPyArray_MapIterReset(mit);\n\twhile (index--) {\n copyswap(it->dataptr, mit->dataptr, swap, ret->descr->elsize);\n\t\tPyArray_MapIterNext(mit);\n\t\tPyArray_ITER_NEXT(it);\n\t}\n\tPy_DECREF(it);\n\t\n\t/* check for consecutive axes */\n\tif ((mit->subspace != NULL) && (mit->consec)) {\n\t\tif (mit->iteraxes[0] > 0) { /* then we need to swap */\n\t\t\t_swap_axes(mit, &ret);\n\t\t}\n\t}\n\treturn (PyObject *)ret;\n}\n\nstatic int\nPyArray_SetMap(PyArrayMapIterObject *mit, PyObject *op)\n{\n\tPyObject *arr=NULL;\n\tPyArrayIterObject *it;\n\tint index;\n\tint swap;\n PyArray_CopySwapFunc *copyswap;\n\tPyArray_Descr *descr;\n\n\t/* Unbound Map Iterator */\n\tif (mit->ait == NULL) return -1;\n\n\tdescr = mit->ait->ao->descr;\n\tPy_INCREF(descr);\n\tarr = PyArray_FromAny(op, descr, 0, 0, FORCECAST, NULL);\n\tif (arr == NULL) return -1;\n\n\tif ((mit->subspace != NULL) && (mit->consec)) {\n\t\tif (mit->iteraxes[0] > 0) { /* then we need to swap */\n\t\t\t_swap_axes(mit, (PyArrayObject **)&arr);\n\t\t}\n\t}\n\t\n\tif ((it = (PyArrayIterObject *)PyArray_IterNew(arr))==NULL) {\n\t\tPy_DECREF(arr);\n\t\treturn -1;\n\t}\n\n\tindex = mit->size;\n\tswap = (PyArray_ISNOTSWAPPED(mit->ait->ao) != \\\n\t\t(PyArray_ISNOTSWAPPED(arr)));\n\n copyswap = PyArray_DESCR(arr)->f->copyswap;\n\tPyArray_MapIterReset(mit);\n /* Need to decref OBJECT arrays */\n if (PyTypeNum_ISOBJECT(descr->type_num)) {\n while (index--) {\n Py_XDECREF(*((PyObject **)mit->dataptr));\n Py_INCREF(*((PyObject **)it->dataptr));\n memmove(mit->dataptr, it->dataptr, sizeof(PyObject *));\n PyArray_MapIterNext(mit);\n PyArray_ITER_NEXT(it);\n if (it->index == it->size)\n PyArray_ITER_RESET(it);\n }\n\t\tPy_DECREF(arr);\n\t\tPy_DECREF(it);\n return 0;\n }\n\twhile(index--) {\n\t\tmemmove(mit->dataptr, it->dataptr, PyArray_ITEMSIZE(arr));\n copyswap(mit->dataptr, NULL, swap, PyArray_ITEMSIZE(arr));\n\t\tPyArray_MapIterNext(mit);\n\t\tPyArray_ITER_NEXT(it);\n\t\tif (it->index == it->size)\n\t\t\tPyArray_ITER_RESET(it);\n\t}\t\t\n\tPy_DECREF(arr);\n\tPy_DECREF(it);\n\treturn 0;\n}\n\nint\ncount_new_axes_0d(PyObject *tuple)\n{\n\tint i, argument_count;\n\tint ellipsis_count = 0;\n\tint newaxis_count = 0;\n\t\n\targument_count = PyTuple_GET_SIZE(tuple);\n\n\tfor (i = 0; i < argument_count; ++i) {\n\t\tPyObject *arg = PyTuple_GET_ITEM(tuple, i);\n\t\tif (arg == Py_Ellipsis && !ellipsis_count) ellipsis_count++;\n\t\telse if (arg == Py_None) newaxis_count++;\n\t\telse break;\n\t}\n\tif (i < argument_count) {\n\t\tPyErr_SetString(PyExc_IndexError,\n\t\t\t\t\"0-d arrays can only use a single ()\"\n\t\t\t\t\" or a list of newaxes (and a single ...)\"\n\t\t\t\t\" as an index\");\n\t\treturn -1;\n\t}\n\tif (newaxis_count > MAX_DIMS) {\n\t\tPyErr_SetString(PyExc_IndexError,\n\t\t\t\t\"too many dimensions\");\n\t\treturn -1;\n\t}\n\treturn newaxis_count;\n}\n\nstatic PyObject *\nadd_new_axes_0d(PyArrayObject *arr, int newaxis_count)\n{\n\tPyArrayObject *other;\n\tintp dimensions[MAX_DIMS]; \n\tint i;\n\tfor (i = 0; i < newaxis_count; ++i) {\n\t\tdimensions[i] = 1;\n\t}\n\tPy_INCREF(arr->descr);\n\tif ((other = (PyArrayObject *)\n\t PyArray_NewFromDescr(arr->ob_type, arr->descr,\n\t\t\t\t newaxis_count, dimensions,\n\t\t\t\t NULL, arr->data,\n\t\t\t\t arr->flags,\n\t\t\t\t (PyObject *)arr)) == NULL) \n\t\treturn NULL;\n\tother->base = (PyObject *)arr;\n\tPy_INCREF(arr);\n\treturn (PyObject *)other;\n}\n\n\n/* This checks the args for any fancy indexing objects */\n\n#define SOBJ_NOTFANCY 0 \n#define SOBJ_ISFANCY 1\n#define SOBJ_BADARRAY 2\n#define SOBJ_TOOMANY 3\n#define SOBJ_LISTTUP 4\n\nstatic int\nfancy_indexing_check(PyObject *args)\n{\n\tint i, n;\n\tPyObject *obj;\n\tint retval = SOBJ_NOTFANCY;\n\n\tif (PyTuple_Check(args)) {\n\t\tn = PyTuple_GET_SIZE(args);\n\t\tif (n >= MAX_DIMS) return SOBJ_TOOMANY;\n\t\tfor (i=0; i=MAX_DIMS) return SOBJ_ISFANCY;\n\t\tfor (i=0; i SOBJ_ISFANCY) return retval;\n\t\t}\n\t}\n\n\treturn retval;\n}\n\n/* Called when treating array object like a mapping -- called first from \n Python when using a[object] unless object is a standard slice object\n (not an extended one). \n\n*/\n\n/* There are two situations: \n\n 1 - the subscript is a standard view and a reference to the \n array can be returned\n\n 2 - the subscript uses Boolean masks or integer indexing and\n therefore a new array is created and returned. \n\n*/\n\n/* Always returns arrays */\n\nstatic PyObject *iter_subscript(PyArrayIterObject *, PyObject *); \n\n\nstatic PyObject *\narray_subscript(PyArrayObject *self, PyObject *op) \n{\n intp dimensions[MAX_DIMS], strides[MAX_DIMS];\n\tintp offset;\n int nd, oned, fancy;\n\tintp i;\n PyArrayObject *other;\n\tPyArrayMapIterObject *mit;\n\n\tif (PyString_Check(op) || PyUnicode_Check(op)) {\n\t\tif (self->descr->fields) {\n\t\t\tPyObject *obj;\n\t\t\tobj = PyDict_GetItem(self->descr->fields, op);\n\t\t\tif (obj != NULL) {\n\t\t\t\tPyArray_Descr *descr;\n\t\t\t\tint offset;\n\t\t\t\tPyObject *title;\n\t\t\t\t\n\t\t\t\tif (PyArg_ParseTuple(obj, \"Oi|O\",\n\t\t\t\t\t\t &descr, &offset, &title)) {\n\t\t\t\t\tPy_INCREF(descr);\n\t\t\t\t\treturn PyArray_GetField(self, descr, \n\t\t\t\t\t\t\t\toffset);\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t\t\n\t\tPyErr_Format(PyExc_ValueError, \n\t\t\t \"field named %s not found.\",\n\t\t\t PyString_AsString(op));\n\t\treturn NULL;\n\t}\n if (self->nd == 0) {\n\t\tif (op == Py_Ellipsis)\n\t\t\treturn PyArray_ToScalar(self->data, self);\n\t\tif (op == Py_None)\n\t\t\treturn add_new_axes_0d(self, 1);\n\t\tif (PyTuple_Check(op)) {\n\t\t\tif (0 == PyTuple_GET_SIZE(op))\n\t\t\t\treturn PyArray_ToScalar(self->data, self);\n\t\t\tif ((nd = count_new_axes_0d(op)) == -1)\n\t\t\t\treturn NULL;\n\t\t\treturn add_new_axes_0d(self, nd);\n\t\t}\n PyErr_SetString(PyExc_IndexError, \n \"0-d arrays can't be indexed.\");\n return NULL;\n }\n if (PyArray_IsScalar(op, Integer) || PyInt_Check(op) || \\\n PyLong_Check(op)) {\n intp value;\n value = PyArray_PyIntAsIntp(op);\n\t\tif (PyErr_Occurred())\n\t\t\tPyErr_Clear();\n else if (value >= 0) {\n\t\t\treturn array_big_item(self, value);\n }\n else /* (value < 0) */ {\n\t\t\tvalue += self->dimensions[0];\n\t\t\treturn array_big_item(self, value);\n\t\t}\n }\n\n\tfancy = fancy_indexing_check(op);\n\n\tif (fancy != SOBJ_NOTFANCY) { \n\t\toned = ((self->nd == 1) && !(PyTuple_Check(op) &&\t\\\n\t\t\t\t\t PyTuple_GET_SIZE(op) > 1));\n\n\t\t/* wrap arguments into a mapiter object */\n\t\tmit = (PyArrayMapIterObject *)\\\n\t\t\tPyArray_MapIterNew(op, oned, fancy);\n\t\tif (mit == NULL) return NULL;\n\t\tif (oned) {\n\t\t\tPyArrayIterObject *it;\n\t\t\tPyObject *rval;\n\t\t\tit = (PyArrayIterObject *)PyArray_IterNew((PyObject *)self);\n\t\t\tif (it == NULL) {Py_DECREF(mit); return NULL;}\n\t\t\trval = iter_subscript(it, mit->indexobj);\n\t\t\tPy_DECREF(it);\n\t\t\tPy_DECREF(mit);\n\t\t\treturn rval;\n\t\t}\n PyArray_MapIterBind(mit, self);\n other = (PyArrayObject *)PyArray_GetMap(mit);\n Py_DECREF(mit);\n return (PyObject *)other;\n }\n\n\ti = PyArray_PyIntAsIntp(op);\n\tif (!error_converting(i)) {\n\t\tif (i < 0 && self->nd > 0) i = i+self->dimensions[0];\n\t\treturn array_big_item(self, i);\n\t}\n\tPyErr_Clear();\n\n\t/* Standard (view-based) Indexing */\n if ((nd = parse_index(self, op, dimensions, strides, &offset)) \n == -1) \n return NULL;\n\n\t/* This will only work if new array will be a view */\n\tPy_INCREF(self->descr);\n\tif ((other = (PyArrayObject *)\t\t\t\t\t\\\n\t PyArray_NewFromDescr(self->ob_type, self->descr,\n\t\t\t\t nd, dimensions,\n\t\t\t\t strides, self->data+offset, \n\t\t\t\t self->flags,\n\t\t\t\t (PyObject *)self)) == NULL) \n\t\treturn NULL;\n\n\n\tother->base = (PyObject *)self;\n\tPy_INCREF(self);\n\t\n\tPyArray_UpdateFlags(other, UPDATE_ALL_FLAGS);\n\t\n\treturn (PyObject *)other;\n}\n\n\n/* Another assignment hacked by using CopyObject. */\n\n/* This only works if subscript returns a standard view. */\n\n/* Again there are two cases. In the first case, PyArray_CopyObject\n can be used. In the second case, a new indexing function has to be \n used.\n*/\n\nstatic int iter_ass_subscript(PyArrayIterObject *, PyObject *, PyObject *); \n\nstatic int \narray_ass_sub(PyArrayObject *self, PyObject *index, PyObject *op) \n{\n int ret, oned, fancy;\n\tintp i;\n PyArrayObject *tmp;\n\tPyArrayMapIterObject *mit;\n\t\n if (op == NULL) {\n PyErr_SetString(PyExc_ValueError, \n \"cannot delete array elements\");\n return -1;\n }\n\tif (!PyArray_ISWRITEABLE(self)) {\n\t\tPyErr_SetString(PyExc_RuntimeError,\n\t\t\t\t\"array is not writeable\");\n\t\treturn -1;\n\t}\n\t\n if (PyArray_IsScalar(index, Integer) || PyInt_Check(index) ||\t\\\n PyLong_Check(index)) {\n intp value;\n value = PyArray_PyIntAsIntp(index);\n if (PyErr_Occurred())\n PyErr_Clear();\n\t\telse\n\t\t\treturn array_ass_big_item(self, value, op);\n }\n\n\tif (PyString_Check(index) || PyUnicode_Check(index)) {\n\t\tif (self->descr->fields) {\n\t\t\tPyObject *obj;\n\t\t\tobj = PyDict_GetItem(self->descr->fields, index);\n\t\t\tif (obj != NULL) {\n\t\t\t\tPyArray_Descr *descr;\n\t\t\t\tint offset;\n\t\t\t\tPyObject *title;\n\t\t\t\t\n\t\t\t\tif (PyArg_ParseTuple(obj, \"Oi|O\",\n\t\t\t\t\t\t &descr, &offset, &title)) {\n\t\t\t\t\tPy_INCREF(descr);\n\t\t\t\t\treturn PyArray_SetField(self, descr, \n\t\t\t\t\t\t\t\toffset, op);\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t\t\n\t\tPyErr_Format(PyExc_ValueError, \n\t\t\t \"field named %s not found.\",\n\t\t\t PyString_AsString(index));\n\t\treturn -1;\n\t}\n\n if (self->nd == 0) {\n\t\tif (index == Py_Ellipsis || index == Py_None ||\t\t\\\n\t\t (PyTuple_Check(index) && (0 == PyTuple_GET_SIZE(index) || \\\n\t\t\t\t\t count_new_axes_0d(index) > 0)))\n\t\t\treturn self->descr->f->setitem(op, self->data, self);\n PyErr_SetString(PyExc_IndexError, \n \"0-d arrays can't be indexed.\");\n return -1;\n }\n\n\tfancy = fancy_indexing_check(index);\n\n\tif (fancy != SOBJ_NOTFANCY) { \n\t\toned = ((self->nd == 1) && !(PyTuple_Check(index) && \\\n\t\t\t\t\t PyTuple_GET_SIZE(index) > 1));\n\n\t\tmit = (PyArrayMapIterObject *)\t\t\t\\\n\t\t\tPyArray_MapIterNew(index, oned, fancy);\n\t\tif (mit == NULL) return -1;\n\t\tif (oned) {\n\t\t\tPyArrayIterObject *it;\n\t\t\tint rval;\n\t\t\tit = (PyArrayIterObject *)PyArray_IterNew((PyObject *)self);\n\t\t\tif (it == NULL) {Py_DECREF(mit); return -1;}\n\t\t\trval = iter_ass_subscript(it, mit->indexobj, op);\n\t\t\tPy_DECREF(it);\n\t\t\tPy_DECREF(mit);\n\t\t\treturn rval;\n\t\t}\n PyArray_MapIterBind(mit, self);\n ret = PyArray_SetMap(mit, op);\n Py_DECREF(mit);\n return ret;\n }\n\t\n\ti = PyArray_PyIntAsIntp(index);\n\tif (!error_converting(i)) {\n\t\treturn array_ass_big_item(self, i, op);\n\t}\n\tPyErr_Clear();\n\t\n\t/* Rest of standard (view-based) indexing */\n\n if ((tmp = (PyArrayObject *)array_subscript(self, index)) == NULL)\n return -1; \n\tif (PyArray_ISOBJECT(self) && (tmp->nd == 0)) {\n\t\tret = tmp->descr->f->setitem(op, tmp->data, tmp);\n\t}\n\telse {\n\t\tret = PyArray_CopyObject(tmp, op);\n\t}\n\tPy_DECREF(tmp);\n return ret;\n}\n\n\n/* There are places that require that array_subscript return a PyArrayObject\n and not possibly a scalar. Thus, this is the function exposed to \n Python so that 0-dim arrays are passed as scalars\n*/\n\nstatic PyObject *\narray_subscript_nice(PyArrayObject *self, PyObject *op) \n{\n\treturn PyArray_Return((PyArrayObject *)array_subscript(self, op));\n}\n\n\nstatic PyMappingMethods array_as_mapping = {\n (inquiry)array_length,\t\t /*mp_length*/\n (binaryfunc)array_subscript_nice,\t/*mp_subscript*/\n (objobjargproc)array_ass_sub,\t /*mp_ass_subscript*/\n};\n\n/****************** End of Mapping Protocol ******************************/\n\n\n/*************************************************************************\n **************** Implement Buffer Protocol ****************************\n *************************************************************************/\n\n/* removed multiple segment interface */\n\nstatic int \narray_getsegcount(PyArrayObject *self, int *lenp) \n{\n if (lenp)\n *lenp = PyArray_NBYTES(self);\n\n if (PyArray_ISONESEGMENT(self)) {\n return 1;\n }\n\n if (lenp)\n *lenp = 0;\n return 0;\n}\n\nstatic int \narray_getreadbuf(PyArrayObject *self, int segment, void **ptrptr) \n{\n if (segment != 0) {\n PyErr_SetString(PyExc_ValueError, \n \"accessing non-existing array segment\");\n return -1;\n }\n \n if (PyArray_ISONESEGMENT(self)) {\n *ptrptr = self->data;\n return PyArray_NBYTES(self);\n }\n PyErr_SetString(PyExc_ValueError, \"array is not a single segment\");\n *ptrptr = NULL;\n return -1;\n}\n\n\nstatic int \narray_getwritebuf(PyArrayObject *self, int segment, void **ptrptr) \n{\n if (PyArray_CHKFLAGS(self, WRITEABLE)) \n return array_getreadbuf(self, segment, (void **) ptrptr);\n else {\n PyErr_SetString(PyExc_ValueError, \"array cannot be \"\\\n \"accessed as a writeable buffer\");\n return -1;\n }\n}\n\nstatic int \narray_getcharbuf(PyArrayObject *self, int segment, const char **ptrptr) \n{\n if (self->descr->type_num == PyArray_STRING || \\\n\t self->descr->type_num == PyArray_UNICODE)\n return array_getreadbuf(self, segment, (void **) ptrptr);\n else {\n PyErr_SetString(PyExc_TypeError, \n \"non-character array cannot be interpreted \"\\\n \"as character buffer\");\n return -1;\n }\n}\n\nstatic PyBufferProcs array_as_buffer = {\n (getreadbufferproc)array_getreadbuf, /*bf_getreadbuffer*/\n (getwritebufferproc)array_getwritebuf, /*bf_getwritebuffer*/\n (getsegcountproc)array_getsegcount,\t /*bf_getsegcount*/\n (getcharbufferproc)array_getcharbuf, /*bf_getcharbuffer*/\n};\n\n/****************** End of Buffer Protocol *******************************/\n\n\n/*************************************************************************\n **************** Implement Number Protocol ****************************\n *************************************************************************/\n\n\ntypedef struct {\n PyObject *add,\n *subtract,\n *multiply,\n *divide,\n *remainder,\n *power,\n\t\t*sqrt,\n *negative,\n *absolute,\n *invert,\n *left_shift,\n *right_shift,\n *bitwise_and,\n *bitwise_xor,\n *bitwise_or,\n *less,\n *less_equal,\n *equal,\n *not_equal,\n *greater,\n *greater_equal,\n *floor_divide,\n *true_divide,\n\t\t*logical_or,\n\t\t*logical_and,\n\t\t*floor,\n\t\t*ceil,\n\t\t*maximum,\n\t\t*minimum;\t\n\t\n} NumericOps;\n\nstatic NumericOps n_ops = {NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, \n NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL,\n NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL,\n NULL, NULL, NULL, NULL, NULL};\n\n/* Dictionary can contain any of the numeric operations, by name. \n Those not present will not be changed\n */\n\n#define SET(op) temp=PyDict_GetItemString(dict, #op);\t\\\n\tif (temp != NULL) {\t\t\t\t\\\n\t\tif (!(PyCallable_Check(temp))) return -1; \\\n Py_XDECREF(n_ops.op); \\\n\t\tn_ops.op = temp; \\\n\t}\n\n \n/*OBJECT_API\n Set internal structure with number functions that all arrays will use\n*/\nint \nPyArray_SetNumericOps(PyObject *dict) \n{\n PyObject *temp = NULL;\n SET(add);\n SET(subtract);\n SET(multiply);\n SET(divide);\n SET(remainder);\n SET(power);\n\tSET(sqrt);\n SET(negative);\n SET(absolute);\n SET(invert);\n SET(left_shift);\n SET(right_shift);\n SET(bitwise_and);\n SET(bitwise_or);\n SET(bitwise_xor);\n SET(less);\t \n SET(less_equal);\n SET(equal);\n SET(not_equal);\n SET(greater);\n SET(greater_equal);\n SET(floor_divide);\t\n SET(true_divide);\t\n\tSET(logical_or);\n\tSET(logical_and);\n\tSET(floor);\n\tSET(ceil);\n\tSET(maximum);\n\tSET(minimum);\n return 0;\n}\n\n#define GET(op) if (n_ops.op &&\t\t\t\t\t\t\\\n\t\t (PyDict_SetItemString(dict, #op, n_ops.op)==-1))\t\\\n\t\tgoto fail;\n\n/*OBJECT_API\n Get dictionary showing number functions that all arrays will use\n*/\nstatic PyObject *\nPyArray_GetNumericOps(void) \n{\n\tPyObject *dict;\n\tif ((dict = PyDict_New())==NULL) \n\t\treturn NULL;\t\n\tGET(add);\n GET(subtract);\n GET(multiply);\n GET(divide);\n GET(remainder);\n GET(power);\n\tGET(sqrt);\n GET(negative);\n GET(absolute);\n GET(invert);\n GET(left_shift);\n GET(right_shift);\n GET(bitwise_and);\n GET(bitwise_or);\n GET(bitwise_xor);\n GET(less);\t \n GET(less_equal);\n GET(equal);\n GET(not_equal);\n GET(greater);\n GET(greater_equal);\n GET(floor_divide); \n GET(true_divide); \n\tGET(logical_or);\n\tGET(logical_and);\n\tGET(floor);\n\tGET(ceil);\n\tGET(maximum);\n\tGET(minimum);\n\treturn dict;\t\n\n fail:\n\tPy_DECREF(dict);\n\treturn NULL;\t\t\n}\n\nstatic PyObject *\nPyArray_GenericReduceFunction(PyArrayObject *m1, PyObject *op, int axis,\n\t\t\t int rtype)\n{\n\tPyObject *args, *ret=NULL, *meth;\n\tif (op == NULL) {\n\t\tPy_INCREF(Py_NotImplemented);\n\t\treturn Py_NotImplemented;\n\t}\n\tif (rtype == PyArray_NOTYPE) \n\t\targs = Py_BuildValue(\"(Oi)\", m1, axis);\n\telse {\n\t\tPyArray_Descr *descr;\n\t\tdescr = PyArray_DescrFromType(rtype);\n\t\targs = Py_BuildValue(\"(Oic)\", m1, axis, descr->type);\n\t\tPy_DECREF(descr);\n\t}\n\tmeth = PyObject_GetAttrString(op, \"reduce\");\n\tif (meth && PyCallable_Check(meth)) {\n\t\tret = PyObject_Call(meth, args, NULL);\n\t}\n\tPy_DECREF(args);\n\tPy_DECREF(meth);\n\treturn ret;\n}\t\n\n\nstatic PyObject *\nPyArray_GenericAccumulateFunction(PyArrayObject *m1, PyObject *op, int axis,\n\t\t\t\t int rtype)\n{\n\tPyObject *args, *ret=NULL, *meth;\n\tif (op == NULL) {\n\t\tPy_INCREF(Py_NotImplemented);\n\t\treturn Py_NotImplemented;\n\t}\n\tif (rtype == PyArray_NOTYPE) \n\t\targs = Py_BuildValue(\"(Oi)\", m1, axis);\n\telse {\n\t\tPyArray_Descr *descr;\n\t\tdescr = PyArray_DescrFromType(rtype);\n\t\targs = Py_BuildValue(\"(Oic)\", m1, axis, descr->type);\n\t\tPy_DECREF(descr);\n\t}\n\tmeth = PyObject_GetAttrString(op, \"accumulate\");\n\tif (meth && PyCallable_Check(meth)) {\n\t\tret = PyObject_Call(meth, args, NULL);\n\t}\n\tPy_DECREF(args);\n\tPy_DECREF(meth);\n\treturn ret;\n}\t\n\n\nstatic PyObject *\nPyArray_GenericBinaryFunction(PyArrayObject *m1, PyObject *m2, PyObject *op) \n{\n if (op == NULL) {\n Py_INCREF(Py_NotImplemented);\n return Py_NotImplemented; \n }\n return PyObject_CallFunction(op, \"OO\", m1, m2);\n}\n\nstatic PyObject *\nPyArray_GenericUnaryFunction(PyArrayObject *m1, PyObject *op) \n{\n if (op == NULL) {\n Py_INCREF(Py_NotImplemented);\n return Py_NotImplemented; \n }\n return PyObject_CallFunction(op, \"(O)\", m1);\n}\n\nstatic PyObject *\nPyArray_GenericInplaceBinaryFunction(PyArrayObject *m1, \n\t\t\t\t PyObject *m2, PyObject *op) \n{\n if (op == NULL) {\n Py_INCREF(Py_NotImplemented);\n return Py_NotImplemented; \n }\n return PyObject_CallFunction(op, \"OOO\", m1, m2, m1);\n}\n\nstatic PyObject *\narray_add(PyArrayObject *m1, PyObject *m2) \n{ \n return PyArray_GenericBinaryFunction(m1, m2, n_ops.add); \n}\n\nstatic PyObject *\narray_subtract(PyArrayObject *m1, PyObject *m2) \n{\n\treturn PyArray_GenericBinaryFunction(m1, m2, n_ops.subtract);\n}\n\nstatic PyObject *\narray_multiply(PyArrayObject *m1, PyObject *m2) \n{\n return PyArray_GenericBinaryFunction(m1, m2, n_ops.multiply);\n}\n\nstatic PyObject *\narray_divide(PyArrayObject *m1, PyObject *m2) \n{\n return PyArray_GenericBinaryFunction(m1, m2, n_ops.divide);\n}\n\nstatic PyObject *\narray_remainder(PyArrayObject *m1, PyObject *m2) \n{\n return PyArray_GenericBinaryFunction(m1, m2, n_ops.remainder);\n}\n\nstatic PyObject *\narray_power(PyArrayObject *m1, PyObject *m2) \n{\n return PyArray_GenericBinaryFunction(m1, m2, n_ops.power);\n}\n\nstatic PyObject *\narray_negative(PyArrayObject *m1) \n{ \n return PyArray_GenericUnaryFunction(m1, n_ops.negative);\n}\n\nstatic PyObject *\narray_absolute(PyArrayObject *m1) \n{ \n return PyArray_GenericUnaryFunction(m1, n_ops.absolute);\n}\n\nstatic PyObject *\narray_invert(PyArrayObject *m1) \n{ \n return PyArray_GenericUnaryFunction(m1, n_ops.invert);\n}\n\nstatic PyObject *\narray_left_shift(PyArrayObject *m1, PyObject *m2) \n{\n return PyArray_GenericBinaryFunction(m1, m2, n_ops.left_shift);\n}\n\nstatic PyObject *\narray_right_shift(PyArrayObject *m1, PyObject *m2) \n{\n return PyArray_GenericBinaryFunction(m1, m2, n_ops.right_shift);\n}\n\nstatic PyObject *\narray_bitwise_and(PyArrayObject *m1, PyObject *m2) \n{\n return PyArray_GenericBinaryFunction(m1, m2, n_ops.bitwise_and);\n}\n\nstatic PyObject *\narray_bitwise_or(PyArrayObject *m1, PyObject *m2) \n{\n return PyArray_GenericBinaryFunction(m1, m2, n_ops.bitwise_or);\n}\n\nstatic PyObject *\narray_bitwise_xor(PyArrayObject *m1, PyObject *m2) \n{\n return PyArray_GenericBinaryFunction(m1, m2, n_ops.bitwise_xor);\n}\n\nstatic PyObject *\narray_inplace_add(PyArrayObject *m1, PyObject *m2) \n{\n return PyArray_GenericInplaceBinaryFunction(m1, m2, n_ops.add);\n}\n\nstatic PyObject *\narray_inplace_subtract(PyArrayObject *m1, PyObject *m2) \n{\n return PyArray_GenericInplaceBinaryFunction(m1, m2, n_ops.subtract);\n}\n\nstatic PyObject *\narray_inplace_multiply(PyArrayObject *m1, PyObject *m2) \n{\n return PyArray_GenericInplaceBinaryFunction(m1, m2, n_ops.multiply);\n}\n\nstatic PyObject *\narray_inplace_divide(PyArrayObject *m1, PyObject *m2) \n{\n return PyArray_GenericInplaceBinaryFunction(m1, m2, n_ops.divide);\n}\n\nstatic PyObject *\narray_inplace_remainder(PyArrayObject *m1, PyObject *m2) \n{\n return PyArray_GenericInplaceBinaryFunction(m1, m2, n_ops.remainder);\n}\n\nstatic PyObject *\narray_inplace_power(PyArrayObject *m1, PyObject *m2) \n{\n return PyArray_GenericInplaceBinaryFunction(m1, m2, n_ops.power);\n}\n\nstatic PyObject *\narray_inplace_left_shift(PyArrayObject *m1, PyObject *m2) \n{\n return PyArray_GenericInplaceBinaryFunction(m1, m2, n_ops.left_shift);\n}\n\nstatic PyObject *\narray_inplace_right_shift(PyArrayObject *m1, PyObject *m2) \n{\n return PyArray_GenericInplaceBinaryFunction(m1, m2, n_ops.right_shift);\n}\n\nstatic PyObject *\narray_inplace_bitwise_and(PyArrayObject *m1, PyObject *m2) \n{\n return PyArray_GenericInplaceBinaryFunction(m1, m2, n_ops.bitwise_and);\n}\n\nstatic PyObject *\narray_inplace_bitwise_or(PyArrayObject *m1, PyObject *m2) \n{\n return PyArray_GenericInplaceBinaryFunction(m1, m2, n_ops.bitwise_or);\n}\n\nstatic PyObject *\narray_inplace_bitwise_xor(PyArrayObject *m1, PyObject *m2) \n{\n return PyArray_GenericInplaceBinaryFunction(m1, m2, n_ops.bitwise_xor);\n}\n\nstatic PyObject *\narray_floor_divide(PyArrayObject *m1, PyObject *m2) \n{\n return PyArray_GenericBinaryFunction(m1, m2, n_ops.floor_divide);\n}\n\nstatic PyObject *\narray_true_divide(PyArrayObject *m1, PyObject *m2) \n{\n return PyArray_GenericBinaryFunction(m1, m2, n_ops.true_divide);\n}\n\nstatic PyObject *\narray_inplace_floor_divide(PyArrayObject *m1, PyObject *m2) \n{\n return PyArray_GenericInplaceBinaryFunction(m1, m2, \n\t\t\t\t\t\t n_ops.floor_divide);\n}\n\nstatic PyObject *\narray_inplace_true_divide(PyArrayObject *m1, PyObject *m2) \n{\n return PyArray_GenericInplaceBinaryFunction(m1, m2, \n\t\t\t\t\t\t n_ops.true_divide);\n}\n\n/* Array evaluates as \"TRUE\" if any of the elements are non-zero*/\nstatic int \narray_any_nonzero(PyArrayObject *mp) \n{\n\tintp index;\n\tPyArrayIterObject *it;\n\tBool anyTRUE = FALSE;\n\t\n\tit = (PyArrayIterObject *)PyArray_IterNew((PyObject *)mp);\n\tif (it==NULL) return anyTRUE;\n\tindex = it->size;\n\twhile(index--) {\n\t\tif (mp->descr->f->nonzero(it->dataptr, mp)) {\n\t\t\tanyTRUE = TRUE;\n\t\t\tbreak;\n\t\t}\n\t\tPyArray_ITER_NEXT(it);\n\t}\n\tPy_DECREF(it);\n\treturn anyTRUE;\n}\n\nstatic int\n_array_nonzero(PyArrayObject *mp)\n{\n\tintp n;\n\tn = PyArray_SIZE(mp);\n\tif (n == 1) {\n\t\treturn mp->descr->f->nonzero(mp->data, mp);\n\t}\n\telse if (n == 0) {\n\t\treturn 0;\n\t}\n\telse {\n\t\tPyErr_SetString(PyExc_ValueError, \n\t\t\t\t\"The truth value of an array \" \\\n\t\t\t\t\"with more than one element is ambiguous. \" \\\n\t\t\t\t\"Use a.any() or a.all()\");\n\t\treturn -1;\n\t}\n}\n\n\n\nstatic PyObject *\narray_divmod(PyArrayObject *op1, PyObject *op2) \n{\n PyObject *divp, *modp, *result;\n\n divp = array_floor_divide(op1, op2);\n if (divp == NULL) return NULL;\n modp = array_remainder(op1, op2);\n if (modp == NULL) {\n Py_DECREF(divp);\n return NULL;\n }\n result = Py_BuildValue(\"OO\", divp, modp);\n Py_DECREF(divp);\n Py_DECREF(modp);\n return result;\n}\n\n\nstatic PyObject *\narray_int(PyArrayObject *v) \n{ \n PyObject *pv, *pv2;\n if (PyArray_SIZE(v) != 1) {\n PyErr_SetString(PyExc_TypeError, \"only length-1 arrays can be\"\\\n\t\t\t\t\" converted to Python scalars\");\n return NULL;\n }\n pv = v->descr->f->getitem(v->data, v);\n if (pv == NULL) return NULL;\n if (pv->ob_type->tp_as_number == 0) {\n PyErr_SetString(PyExc_TypeError, \"cannot convert to an int; \"\\\n\t\t\t\t\"scalar object is not a number\");\n Py_DECREF(pv);\n return NULL;\n }\n if (pv->ob_type->tp_as_number->nb_int == 0) {\n PyErr_SetString(PyExc_TypeError, \"don't know how to convert \"\\\n\t\t\t\t\"scalar number to int\");\n Py_DECREF(pv);\n return NULL;\n }\n\n pv2 = pv->ob_type->tp_as_number->nb_int(pv);\n Py_DECREF(pv);\n return pv2;\t \n}\n\nstatic PyObject *\narray_float(PyArrayObject *v) \n{\n PyObject *pv, *pv2;\n if (PyArray_SIZE(v) != 1) {\n PyErr_SetString(PyExc_TypeError, \"only length-1 arrays can \"\\\n\t\t\t\t\"be converted to Python scalars\");\n return NULL;\n }\n pv = v->descr->f->getitem(v->data, v);\n if (pv == NULL) return NULL;\n if (pv->ob_type->tp_as_number == 0) {\n PyErr_SetString(PyExc_TypeError, \"cannot convert to an \"\\\n\t\t\t\t\"int; scalar object is not a number\");\n Py_DECREF(pv);\n return NULL;\n }\n if (pv->ob_type->tp_as_number->nb_float == 0) {\n PyErr_SetString(PyExc_TypeError, \"don't know how to convert \"\\\n\t\t\t\t\"scalar number to float\");\n Py_DECREF(pv);\n return NULL;\n }\n pv2 = pv->ob_type->tp_as_number->nb_float(pv);\n Py_DECREF(pv);\n return pv2;\t \n}\n\nstatic PyObject *\narray_long(PyArrayObject *v) \n{ \n PyObject *pv, *pv2;\n if (PyArray_SIZE(v) != 1) {\n PyErr_SetString(PyExc_TypeError, \"only length-1 arrays can \"\\\n\t\t\t\t\"be converted to Python scalars\");\n return NULL;\n }\n pv = v->descr->f->getitem(v->data, v);\n if (pv->ob_type->tp_as_number == 0) {\n PyErr_SetString(PyExc_TypeError, \"cannot convert to an int; \"\\\n\t\t\t\t\"scalar object is not a number\");\n return NULL;\n }\n if (pv->ob_type->tp_as_number->nb_long == 0) {\n PyErr_SetString(PyExc_TypeError, \"don't know how to convert \"\\\n\t\t\t\t\"scalar number to long\");\n return NULL;\n }\n pv2 = pv->ob_type->tp_as_number->nb_long(pv);\n Py_DECREF(pv);\n return pv2;\t \n}\n\nstatic PyObject *\narray_oct(PyArrayObject *v) \n{\t \n PyObject *pv, *pv2;\n if (PyArray_SIZE(v) != 1) {\n PyErr_SetString(PyExc_TypeError, \"only length-1 arrays can \"\\\n\t\t\t\t\"be converted to Python scalars\");\n return NULL;\n }\n pv = v->descr->f->getitem(v->data, v);\n if (pv->ob_type->tp_as_number == 0) {\n PyErr_SetString(PyExc_TypeError, \"cannot convert to an int; \"\\\n\t\t\t\t\"scalar object is not a number\");\n return NULL;\n }\n if (pv->ob_type->tp_as_number->nb_oct == 0) {\n PyErr_SetString(PyExc_TypeError, \"don't know how to convert \"\\\n\t\t\t\t\"scalar number to oct\");\n return NULL;\n }\n pv2 = pv->ob_type->tp_as_number->nb_oct(pv);\n Py_DECREF(pv);\n return pv2;\t \n}\n\nstatic PyObject *\narray_hex(PyArrayObject *v) \n{ \n PyObject *pv, *pv2;\n if (PyArray_SIZE(v) != 1) {\n PyErr_SetString(PyExc_TypeError, \"only length-1 arrays can \"\\\n\t\t\t\t\"be converted to Python scalars\");\n return NULL;\n }\n pv = v->descr->f->getitem(v->data, v);\n if (pv->ob_type->tp_as_number == 0) {\n PyErr_SetString(PyExc_TypeError, \"cannot convert to an int; \"\\\n\t\t\t\t\"scalar object is not a number\");\n return NULL;\n }\n if (pv->ob_type->tp_as_number->nb_hex == 0) {\n PyErr_SetString(PyExc_TypeError, \"don't know how to convert \"\\\n\t\t\t\t\"scalar number to hex\");\n return NULL;\n }\n pv2 = pv->ob_type->tp_as_number->nb_hex(pv);\n Py_DECREF(pv);\n return pv2;\t \n}\n\nstatic PyObject *\n_array_copy_nice(PyArrayObject *self)\n{\n\treturn PyArray_Return((PyArrayObject *)\t\t\\\n\t\t\t PyArray_Copy(self));\n}\n\nstatic PyNumberMethods array_as_number = {\n (binaryfunc)array_add,\t\t /*nb_add*/\n (binaryfunc)array_subtract,\t\t /*nb_subtract*/\n (binaryfunc)array_multiply,\t\t /*nb_multiply*/\n (binaryfunc)array_divide,\t\t /*nb_divide*/\n (binaryfunc)array_remainder,\t /*nb_remainder*/\n (binaryfunc)array_divmod,\t\t /*nb_divmod*/\n (ternaryfunc)array_power,\t\t /*nb_power*/\n (unaryfunc)array_negative, /*nb_neg*/\t\n (unaryfunc)_array_copy_nice,\t\t /*nb_pos*/ \n (unaryfunc)array_absolute,\t\t /*(unaryfunc)array_abs,*/\n (inquiry)_array_nonzero,\t\t /*nb_nonzero*/\n (unaryfunc)array_invert,\t\t /*nb_invert*/\n (binaryfunc)array_left_shift,\t /*nb_lshift*/\n (binaryfunc)array_right_shift,\t /*nb_rshift*/\n (binaryfunc)array_bitwise_and,\t /*nb_and*/\n (binaryfunc)array_bitwise_xor,\t /*nb_xor*/\n (binaryfunc)array_bitwise_or,\t /*nb_or*/\n 0,\t\t /*nb_coerce*/\n (unaryfunc)array_int,\t\t /*nb_int*/\n (unaryfunc)array_long,\t\t /*nb_long*/\n (unaryfunc)array_float,\t\t /*nb_float*/\n (unaryfunc)array_oct,\t\t /*nb_oct*/\n (unaryfunc)array_hex,\t\t /*nb_hex*/\n\n /*This code adds augmented assignment functionality*/\n /*that was made available in Python 2.0*/\n (binaryfunc)array_inplace_add,\t /*inplace_add*/\n (binaryfunc)array_inplace_subtract,\t /*inplace_subtract*/\n (binaryfunc)array_inplace_multiply,\t /*inplace_multiply*/\n (binaryfunc)array_inplace_divide,\t /*inplace_divide*/\n (binaryfunc)array_inplace_remainder, /*inplace_remainder*/\n (ternaryfunc)array_inplace_power,\t /*inplace_power*/\n (binaryfunc)array_inplace_left_shift, /*inplace_lshift*/\n (binaryfunc)array_inplace_right_shift, /*inplace_rshift*/\n (binaryfunc)array_inplace_bitwise_and, /*inplace_and*/\n (binaryfunc)array_inplace_bitwise_xor, /*inplace_xor*/\n (binaryfunc)array_inplace_bitwise_or, /*inplace_or*/\n\n (binaryfunc)array_floor_divide,\t /*nb_floor_divide*/\n (binaryfunc)array_true_divide,\t /*nb_true_divide*/\n (binaryfunc)array_inplace_floor_divide, /*nb_inplace_floor_divide*/\n (binaryfunc)array_inplace_true_divide, /*nb_inplace_true_divide*/\n\n};\n\n/****************** End of Buffer Protocol *******************************/\n\n\n/*************************************************************************\n **************** Implement Sequence Protocol **************************\n *************************************************************************/\n\n/* Some of this is repeated in the array_as_mapping protocol. But\n we fill it in here so that PySequence_XXXX calls work as expected \n*/\n\n\nstatic PyObject * \narray_slice(PyArrayObject *self, int ilow, int ihigh) \n{\n PyArrayObject *r;\n int l;\n char *data;\n\n if (self->nd == 0) {\n PyErr_SetString(PyExc_ValueError, \"cannot slice a scalar\");\n return NULL;\n }\n \t\n l=self->dimensions[0];\n if (ihigh < 0) ihigh += l;\n if (ilow < 0) ilow += l;\n if (ilow < 0) ilow = 0;\n else if (ilow > l) ilow = l;\n if (ihigh < 0) ihigh = 0;\n else if (ihigh > l) ihigh = l;\n if (ihigh < ilow) ihigh = ilow;\n\n if (ihigh != ilow) {\n data = index2ptr(self, ilow);\n if (data == NULL) return NULL;\n } else {\n data = self->data;\n }\n\n self->dimensions[0] = ihigh-ilow;\n\tPy_INCREF(self->descr);\n r = (PyArrayObject *)\t\t\t\t\t\t\\\n\t\tPyArray_NewFromDescr(self->ob_type, self->descr,\n\t\t\t\t self->nd, self->dimensions, \n\t\t\t\t self->strides, data,\n\t\t\t\t self->flags, (PyObject *)self);\n\n self->dimensions[0] = l;\n r->base = (PyObject *)self;\n Py_INCREF(self);\n\tPyArray_UpdateFlags(r, UPDATE_ALL_FLAGS); \n return (PyObject *)r;\n}\n\n\nstatic int \narray_ass_slice(PyArrayObject *self, int ilow, int ihigh, PyObject *v) {\n int ret;\n PyArrayObject *tmp;\n\t\n if (v == NULL) {\n PyErr_SetString(PyExc_ValueError, \n \"cannot delete array elements\");\n return -1;\n }\n\tif (!PyArray_ISWRITEABLE(self)) {\n\t\tPyErr_SetString(PyExc_RuntimeError,\n\t\t\t\t\"array is not writeable\");\n\t\treturn -1;\n\t}\n if ((tmp = (PyArrayObject *)array_slice(self, ilow, ihigh)) \\\n == NULL) \n return -1; \n ret = PyArray_CopyObject(tmp, v);\n Py_DECREF(tmp);\n\t\n return ret;\n}\n\nstatic int\narray_contains(PyArrayObject *self, PyObject *el)\n{\n /* equivalent to (self == el).any() */\n\n PyObject *res; \n int ret;\n\n res = PyArray_EnsureArray(PyObject_RichCompare((PyObject *)self, el, Py_EQ));\n if (res == NULL) return -1;\n ret = array_any_nonzero((PyArrayObject *)res);\n Py_DECREF(res);\n return ret;\n}\n\n\nstatic PySequenceMethods array_as_sequence = {\n (inquiry)array_length,\t\t/*sq_length*/\n (binaryfunc)NULL, /* sq_concat is handled by nb_add*/\n (intargfunc)NULL, /* sq_repeat is handled nb_multiply*/\n (intargfunc)array_item_nice,\t\t/*sq_item*/\n (intintargfunc)array_slice,\t\t/*sq_slice*/\n (intobjargproc)array_ass_item,\t/*sq_ass_item*/\n (intintobjargproc)array_ass_slice,\t/*sq_ass_slice*/\n\t(objobjproc) array_contains, /* sq_contains */\n\t(binaryfunc) NULL, /* sg_inplace_concat */\n\t(intargfunc) NULL /* sg_inplace_repeat */\n};\n\n\n/****************** End of Sequence Protocol ****************************/\n\n\nstatic int \ndump_data(char **string, int *n, int *max_n, char *data, int nd, \n intp *dimensions, intp *strides, PyArrayObject* self) \n{\n PyArray_Descr *descr=self->descr;\n PyObject *op, *sp;\n char *ostring;\n int i, N;\n\t\n#define CHECK_MEMORY if (*n >= *max_n-16) { *max_n *= 2; \\\n\t\t*string = (char *)_pya_realloc(*string, *max_n); }\n\t\n if (nd == 0) {\n\t\t\n if ((op = descr->f->getitem(data, self)) == NULL) return -1;\n sp = PyObject_Repr(op);\n if (sp == NULL) {Py_DECREF(op); return -1;}\n ostring = PyString_AsString(sp);\n N = PyString_Size(sp)*sizeof(char);\n *n += N;\n CHECK_MEMORY\n memmove(*string+(*n-N), ostring, N);\n Py_DECREF(sp);\n Py_DECREF(op);\n return 0;\n } else {\n CHECK_MEMORY\n (*string)[*n] = '[';\n *n += 1;\n for(i=0; idata, \n\t\t self->nd, self->dimensions, \n self->strides, self) < 0) { \n\t\t_pya_free(string); return NULL; \n\t}\n\t\n\tif (PyArray_ISEXTENDED(self)) {\n\t\tchar buf[100];\n\t\tsnprintf(buf, sizeof(buf), \"%d\", self->descr->elsize);\n\t\tsprintf(string+n, \", '%c%s')\", self->descr->type, buf);\n\t\tret = PyString_FromStringAndSize(string, n+6+strlen(buf));\n\t}\n\telse {\n\t\tsprintf(string+n, \", '%c')\", self->descr->type);\n\t\tret = PyString_FromStringAndSize(string, n+6);\n\t}\n\t\n\n _pya_free(string);\n return ret;\n}\n\nstatic PyObject *PyArray_StrFunction=NULL;\nstatic PyObject *PyArray_ReprFunction=NULL;\n\n/*OBJECT_API\n Set the array print function to be a Python function.\n*/\nstatic void \nPyArray_SetStringFunction(PyObject *op, int repr) \n{\n if (repr) {\n\t\t/* Dispose of previous callback */\n Py_XDECREF(PyArray_ReprFunction); \n\t\t/* Add a reference to new callback */\n Py_XINCREF(op); \n\t\t/* Remember new callback */\n PyArray_ReprFunction = op; \n } else {\n\t\t/* Dispose of previous callback */\n Py_XDECREF(PyArray_StrFunction); \n\t\t/* Add a reference to new callback */\n Py_XINCREF(op); \n\t\t/* Remember new callback */\n PyArray_StrFunction = op; \n }\n}\n\nstatic PyObject *\narray_repr(PyArrayObject *self) \n{\n PyObject *s, *arglist;\n\t\n if (PyArray_ReprFunction == NULL) {\n s = array_repr_builtin(self);\n } else {\n arglist = Py_BuildValue(\"(O)\", self);\n s = PyEval_CallObject(PyArray_ReprFunction, arglist);\n Py_DECREF(arglist); \n }\n return s;\n}\n\nstatic PyObject *\narray_str(PyArrayObject *self) \n{\n PyObject *s, *arglist;\n\t\n if (PyArray_StrFunction == NULL) {\n s = array_repr(self);\n } else {\n arglist = Py_BuildValue(\"(O)\", self);\n s = PyEval_CallObject(PyArray_StrFunction, arglist);\n Py_DECREF(arglist); \n }\n return s;\n}\n\nstatic PyObject *\narray_richcompare(PyArrayObject *self, PyObject *other, int cmp_op) \n{\n PyObject *array_other, *result;\n\n switch (cmp_op) \n {\n case Py_LT:\n return PyArray_GenericBinaryFunction(self, other, \n\t\t\t\t\t\t\t n_ops.less);\n case Py_LE:\n return PyArray_GenericBinaryFunction(self, other, \n\t\t\t\t\t\t\t n_ops.less_equal);\n case Py_EQ:\n /* Try to convert other to an array */\n\t\t\tif (!PyArray_Check(other)) {\n\t\t\t\tarray_other = PyArray_FromObject(other, \n\t\t\t\t\t\t\t\t self->descr->type_num, 0, 0);\n\t\t\t\t/* If not successful, then return the integer\n\t\t\t\t object 0. This fixes code that used to\n\t\t\t\t allow equality comparisons between arrays\n\t\t\t\t and other objects which would give a result\n\t\t\t\t of 0\n\t\t\t\t*/\n\t\t\t\tif ((array_other == NULL) ||\t\\\n\t\t\t\t (array_other == Py_None)) {\n\t\t\t\t\tPy_XDECREF(array_other);\n\t\t\t\t\tPyErr_Clear();\n\t\t\t\t\tPy_INCREF(Py_False);\n\t\t\t\t\treturn Py_False;\n\t\t\t\t}\n\t\t\t}\n\t\t\telse {\n\t\t\t\tPy_INCREF(other);\n\t\t\t\tarray_other = other;\n\t\t\t}\n result = PyArray_GenericBinaryFunction(self, \n\t\t\t\t\t\t\t array_other, \n\t\t\t\t\t\t\t n_ops.equal);\n /* If the comparison results in NULL, then the \n\t\t\t two array objects can not be compared together so \n\t\t\t return zero \n */\n Py_DECREF(array_other);\n if (result == NULL) {\n PyErr_Clear();\n Py_INCREF(Py_False);\n return Py_False;\n }\n return result;\n case Py_NE:\n /* Try to convert other to an array */\n\t\t\tif (!PyArray_Check(other)) {\n\t\t\t\tarray_other = PyArray_FromObject(other, \n\t\t\t\t\t\t\t\t self->descr->type_num, 0, 0);\n\t\t\t\t/* If not successful, then objects cannot be \n\t\t\t\t compared and cannot be equal, therefore, \n\t\t\t\t return True;\n\t\t\t\t*/\n\t\t\t\tif ((array_other == NULL) ||\t\\\n\t\t\t\t (array_other == Py_None)) {\n\t\t\t\t\tPy_XDECREF(array_other);\n\t\t\t\t\tPyErr_Clear();\n\t\t\t\t\tPy_INCREF(Py_True);\n\t\t\t\t\treturn Py_True;\n\t\t\t\t}\n\t\t\t}\n\t\t\telse {\n\t\t\t\tPy_INCREF(other);\n\t\t\t\tarray_other = other;\n\t\t\t}\n\t\t\tresult = PyArray_GenericBinaryFunction(self, \n\t\t\t\t\t\t\t array_other, \n\t\t\t\t\t\t\t n_ops.not_equal);\n\t\t\tPy_DECREF(array_other);\n if (result == NULL) {\n PyErr_Clear();\n Py_INCREF(Py_True);\n return Py_True;\n }\n return result;\n case Py_GT:\n return PyArray_GenericBinaryFunction(self, other, \n\t\t\t\t\t\t\t n_ops.greater);\n case Py_GE:\n return PyArray_GenericBinaryFunction(self, \n\t\t\t\t\t\t\t other, \n\t\t\t\t\t \t n_ops.greater_equal);\n }\n return NULL;\n}\n\nstatic PyObject *\n_check_axis(PyArrayObject *arr, int *axis, int flags)\n{\n\tPyObject *temp;\n\tint n = arr->nd;\n\n\tif ((*axis >= MAX_DIMS) || (n==0)) {\n\t\ttemp = PyArray_Ravel(arr,0);\n\t\t*axis = PyArray_NDIM(temp)-1;\n\t\treturn temp;\n\t}\n\telse {\n\t\tif (flags) {\n\t\t\ttemp = PyArray_CheckFromAny((PyObject *)arr, NULL, \n 0, 0, flags, NULL);\n\t\t\tif (temp == NULL) return NULL;\n\t\t}\n\t\telse {\n\t\t\tPy_INCREF(arr);\n\t\t\ttemp = (PyObject *)arr;\n\t\t}\n\t}\n\tif (*axis < 0) *axis += n;\n\tif ((*axis < 0) || (*axis >= n)) {\n\t\tPyErr_Format(PyExc_ValueError, \n\t\t\t \"axis(=%d) out of bounds\", *axis);\n\t\tPy_DECREF(temp);\n\t\treturn NULL;\n\t}\n\treturn temp;\n}\n\n#include \"arraymethods.c\"\n\n/* Lifted from numarray */\nstatic PyObject *\nPyArray_IntTupleFromIntp(int len, intp *vals)\n{\n\tint i;\n PyObject *intTuple = PyTuple_New(len);\n if (!intTuple) goto fail;\n for(i=0; i= SIZEOF_INTP\n\t\tif (!(op = PyNumber_Int(seq))) return -1;\n#else\n\t\tif (!(op = PyNumber_Long(seq))) return -1;\n#endif\n\t\tnd = 1;\n#if SIZEOF_LONG >= SIZEOF_INTP\n\t\tvals[0] = (intp ) PyInt_AsLong(op);\n#else\n\t\tvals[0] = (intp ) PyLong_AsLongLong(op);\n#endif\n\t\tPy_DECREF(op);\n\t} else {\n\t\tfor(i=0; i < MIN(nd,maxvals); i++) {\n\t\t\top = PySequence_GetItem(seq, i);\n\t\t\tif (op == NULL) return -1;\n#if SIZEOF_LONG >= SIZEOF_INTP\n\t\t\tvals[i]=(intp )PyInt_AsLong(op);\n#else\n\t\t\tvals[i]=(intp )PyLong_AsLongLong(op);\n#endif\n\t\t\tPy_DECREF(op);\n\t\t\tif(PyErr_Occurred()) return -1;\n\t\t}\n\t}\n\treturn nd;\n}\n\n\n/* Check whether the given array is stored contiguously (row-wise) in\n memory. */\nstatic int\n_IsContiguous(PyArrayObject *ap) \n{\n\tregister intp sd;\n\tregister intp dim;\n\tregister int i;\n \n\n\tif (ap->nd == 0) return 1;\n\tsd = ap->descr->elsize;\n\tif (ap->nd == 1) return (ap->dimensions[0] == 1 || \\\n\t\t\t\t sd == ap->strides[0]);\n\tfor (i = ap->nd-1; i >= 0; --i) {\n\t\tdim = ap->dimensions[i];\n\t\t/* contiguous by definition */\n\t\tif (dim == 0) return 1;\n\t\tif (ap->strides[i] != sd) return 0;\n\t\tsd *= dim;\n\t}\n\treturn 1;\n}\n\n\nstatic int \n_IsFortranContiguous(PyArrayObject *ap) \n{\n\tregister intp sd;\n\tregister intp dim;\n\tregister int i;\n\t\n\tif (ap->nd == 0) return 1;\n\tsd = ap->descr->elsize;\n\tif (ap->nd == 1) return (ap->dimensions[0] == 1 || \\\n\t\t\t\t sd == ap->strides[0]);\n\tfor (i=0; i< ap->nd; ++i) {\n\t\tdim = ap->dimensions[i];\n\t\t/* contiguous by definition */\n\t\tif (dim == 0) return 1; \n\t\tif (ap->strides[i] != sd) return 0;\n\t\tsd *= dim;\n\t}\n\treturn 1;\n}\n\nstatic int\n_IsAligned(PyArrayObject *ap) \n{\n\tint i, alignment, aligned=1;\n\tintp ptr;\n\tint type = ap->descr->type_num;\n\n\tif ((type == PyArray_STRING) || (type == PyArray_VOID))\n\t\treturn 1;\n\n\talignment = ap->descr->alignment;\n\tif (alignment == 1) return 1;\n\n\tptr = (intp) ap->data;\n aligned = (ptr % alignment) == 0;\n for (i=0; i nd; i++)\n aligned &= ((ap->strides[i] % alignment) == 0);\n return aligned != 0;\n}\n\nstatic Bool\n_IsWriteable(PyArrayObject *ap)\n{\n\tPyObject *base=ap->base;\n\tvoid *dummy;\n\tint n;\n\n\t/* If we own our own data, then no-problem */\n\tif ((base == NULL) || (ap->flags & OWN_DATA)) return TRUE;\n\n\t/* Get to the final base object \n\t If it is a writeable array, then return TRUE\n\t If we can find an array object \n\t or a writeable buffer object as the final base object\n\t or a string object (for pickling support memory savings).\n\t - this last could be removed if a proper pickleable \n\t buffer was added to Python.\n\t*/\n\n\twhile(PyArray_Check(base)) {\n\t\tif (PyArray_CHKFLAGS(base, OWN_DATA)) \n\t\t\treturn (Bool) (PyArray_ISWRITEABLE(base));\n\t\tbase = PyArray_BASE(base);\n\t}\n\n\t/* here so pickle support works seamlessly \n\t and unpickled array can be set and reset writeable \n\t -- could be abused -- */\n\tif PyString_Check(base) return TRUE;\n\n\tif (PyObject_AsWriteBuffer(base, &dummy, &n) < 0)\n\t\treturn FALSE;\n\t\n\treturn TRUE;\n}\n\n\n/*OBJECT_API\n Update Several Flags at once.\n*/\nstatic void\nPyArray_UpdateFlags(PyArrayObject *ret, int flagmask)\n{\n\n\tif (flagmask & FORTRAN) {\n\t\tif (_IsFortranContiguous(ret)) {\n\t\t\tret->flags |= FORTRAN;\n\t\t\tif (ret->nd > 1) ret->flags &= ~CONTIGUOUS;\n\t\t}\n\t\telse ret->flags &= ~FORTRAN;\n\t}\n\tif (flagmask & CONTIGUOUS) {\n\t\tif (_IsContiguous(ret)) {\n\t\t\tret->flags |= CONTIGUOUS;\n\t\t\tif (ret->nd > 1) ret->flags &= ~FORTRAN;\n\t\t}\n\t\telse ret->flags &= ~CONTIGUOUS;\n\t}\n\tif (flagmask & ALIGNED) {\n\t\tif (_IsAligned(ret)) ret->flags |= ALIGNED;\n\t\telse ret->flags &= ~ALIGNED;\n\t}\n\t/* This is not checked by default WRITEABLE is not part of UPDATE_ALL_FLAGS */\n\tif (flagmask & WRITEABLE) {\n\t if (_IsWriteable(ret)) ret->flags |= WRITEABLE;\n\t \telse ret->flags &= ~WRITEABLE;\t\n }\n\treturn;\n}\n\n/* This routine checks to see if newstrides (of length nd) will not \n walk outside of the memory implied by a single segment array of the provided \n dimensions and element size. If numbytes is 0 it will be calculated from \n the provided shape and element size.\n*/\n/*OBJECT_API*/\nstatic Bool\nPyArray_CheckStrides(int elsize, int nd, intp numbytes, \n\t\t intp *dims, intp *newstrides)\n{\n\tint i;\n\t\n\tif (numbytes == 0) \n\t\tnumbytes = PyArray_MultiplyList(dims, nd) * elsize;\n\t\n\tfor (i=0; i numbytes) {\n\t\t\treturn FALSE;\n\t\t}\n\t}\n\treturn TRUE;\n\t\n}\n\n\n/* This is the main array creation routine. */\n\n/* Flags argument has multiple related meanings \n depending on data and strides: \n\n If data is given, then flags is flags associated with data. \n If strides is not given, then a contiguous strides array will be created\n and the CONTIGUOUS bit will be set. If the flags argument \n has the FORTRAN bit set, then a FORTRAN-style strides array will be\n created (and of course the FORTRAN flag bit will be set). \n\n If data is not given but created here, then flags will be DEFAULT_FLAGS\n and a non-zero flags argument can be used to indicate a FORTRAN style\n array is desired. \n*/\n\nstatic intp\n_array_fill_strides(intp *strides, intp *dims, int nd, intp itemsize, \n\t\t int inflag, int *objflags) \n{\n\tint i;\n\t/* Only make Fortran strides if not contiguous as well */\n\tif ((inflag & FORTRAN) && !(inflag & CONTIGUOUS)) {\n\t\tfor (i=0; i 1) *objflags &= ~CONTIGUOUS;\n\t\telse *objflags |= CONTIGUOUS;\n\t}\n\telse {\n\t\tfor (i=nd-1;i>=0;i--) {\n\t\t\tstrides[i] = itemsize;\n\t\t\titemsize *= dims[i] ? dims[i] : 1;\n\t\t}\n\t\t*objflags |= CONTIGUOUS;\n\t\tif (nd > 1) *objflags &= ~FORTRAN;\n\t\telse *objflags |= FORTRAN;\n\t}\n\treturn itemsize;\n}\n\n/*OBJECT_API\n Generic new array creation routine.\n*/\nstatic PyObject *\nPyArray_New(PyTypeObject *subtype, int nd, intp *dims, int type_num,\n intp *strides, void *data, int itemsize, int flags,\n\t PyObject *obj)\n{\n\tPyArray_Descr *descr;\n\tPyObject *new;\n\n\tdescr = PyArray_DescrFromType(type_num);\n\tif (descr == NULL) return NULL;\t\n\tif (descr->elsize == 0) {\n\t\tif (itemsize < 1) {\n\t\t\tPyErr_SetString(PyExc_ValueError,\n\t\t\t\t\t\"data type must provide an itemsize\");\n\t\t\tPy_DECREF(descr);\n\t\t\treturn NULL;\n\t\t}\n\t\tPyArray_DESCR_REPLACE(descr);\n\t\tdescr->elsize = itemsize;\n\t}\n\tnew = PyArray_NewFromDescr(subtype, descr, nd, dims, strides,\n\t\t\t\t data, flags, obj);\n\treturn new;\n}\n\n/* Change a sub-array field to the base descriptor */\nstatic int\n_update_descr_and_dimensions(PyArray_Descr **des, intp *newdims, \n\t\t\t intp *newstrides, int oldnd)\n{\n\tPyArray_Descr *old;\n\tint newnd;\n\tint numnew;\n\tintp *mydim;\n\tint i;\n\t\n\told = *des;\n\t*des = old->subarray->base;\n\n\tmydim = newdims + oldnd;\n\tif (PyTuple_Check(old->subarray->shape)) {\n\t\tnumnew = PyTuple_GET_SIZE(old->subarray->shape);\n\t\t\n\t\tfor (i=0; isubarray->shape, i));\n\t\t}\n\t}\n\telse {\n\t\tnumnew = 1;\n\t\tmydim[0] = (intp) PyInt_AsLong(old->subarray->shape);\n\t}\n\t\n\tnewnd = oldnd + numnew;\n\n\tif (newstrides) {\n\t\tintp tempsize;\n\t\tintp *mystrides;\n\t\tmystrides = newstrides + oldnd;\n\t\t/* Make new strides */\n\t\ttempsize = (*des)->elsize;\n\t\tfor (i=numnew-1; i>=0; i--) {\n\t\t\tmystrides[i] = tempsize;\n\t\t\ttempsize *= mydim[i] ? mydim[i] : 1;\n\t\t}\n\t}\n\tPy_INCREF(*des); \n\tPy_DECREF(old); \n\treturn newnd;\n}\n\n\n/* steals a reference to descr (even on failure) */\n/*OBJECT_API\n Generic new array creation routine.\n*/\nstatic PyObject *\nPyArray_NewFromDescr(PyTypeObject *subtype, PyArray_Descr *descr, int nd, \n\t\t intp *dims, intp *strides, void *data, \n\t\t int flags, PyObject *obj)\n{\t\n\tPyArrayObject *self;\n\tregister int i;\n\tintp sd;\n\n\tif (descr->subarray) {\n\t\tPyObject *ret;\n\t\tintp newdims[2*MAX_DIMS];\n\t\tintp *newstrides=NULL;\n\t\tmemcpy(newdims, dims, nd*sizeof(intp));\n\t\tif (strides) {\n\t\t\tnewstrides = newdims + MAX_DIMS;\n\t\t\tmemcpy(newstrides, strides, nd*sizeof(intp));\n\t\t}\n\t\tnd =_update_descr_and_dimensions(&descr, newdims, \n\t\t\t\t\t\t newstrides, nd);\n\t\tret = PyArray_NewFromDescr(subtype, descr, nd, newdims, \n\t\t\t\t\t newstrides,\n\t\t\t\t\t data, flags, obj);\n\t\treturn ret;\n\t}\n\n\tif (nd < 0) {\n\t\tPyErr_SetString(PyExc_ValueError,\n\t\t\t\t\"number of dimensions must be >=0\");\n\t\tPy_DECREF(descr);\n\t\treturn NULL;\n\t}\n if (nd > MAX_DIMS) {\n PyErr_Format(PyExc_ValueError,\n \"maximum number of dimensions is %d\", MAX_DIMS);\n\t\tPy_DECREF(descr);\n return NULL;\n\t}\n\n\t/* Check dimensions */\n\tfor (i=nd-1;i>=0;i--) {\n\t\tif (dims[i] < 0) {\n\t\t\tPyErr_SetString(PyExc_ValueError,\n\t\t\t\t\t\"negative dimensions \"\t\\\n\t\t\t\t\t\"are not allowed\");\n\t\t\tPy_DECREF(descr);\n\t\t\treturn NULL;\n\t\t}\n\t}\n\t\n\tself = (PyArrayObject *) subtype->tp_alloc(subtype, 0);\n\tif (self == NULL) {\n\t\tPy_DECREF(descr);\n\t\treturn NULL;\t\n\t}\n\tself->nd = nd;\n\tself->dimensions = NULL;\n\tself->data = NULL;\n\tif (data == NULL) { /* strides is NULL too */\n\t\tself->flags = DEFAULT_FLAGS;\n\t\tif (flags) {\n\t\t\tself->flags |= FORTRAN; \n\t\t\tif (nd > 1) self->flags &= ~CONTIGUOUS;\n\t\t\tflags = FORTRAN;\n\t\t}\n\t}\n\telse self->flags = (flags & ~UPDATEIFCOPY);\n\t\t\n\tsd = descr->elsize;\n\tself->descr = descr;\n\tself->base = (PyObject *)NULL;\n self->weakreflist = (PyObject *)NULL;\n\t\n\tif (nd > 0) {\n\t\tself->dimensions = PyDimMem_NEW(2*nd);\n\t\tif (self->dimensions == NULL) {\n\t\t\tPyErr_NoMemory();\n\t\t\tgoto fail;\n\t\t}\n\t\tself->strides = self->dimensions + nd;\n\t\tmemcpy(self->dimensions, dims, sizeof(intp)*nd);\n\t\tif (strides == NULL) { /* fill it in */\n\t\t\tsd = _array_fill_strides(self->strides, dims, nd, sd,\n\t\t\t\t\t\t flags, &(self->flags));\n\t\t}\n\t\telse {\n\t\t\tif (data == NULL) {\n\t\t\t\tPyErr_SetString(PyExc_ValueError, \n\t\t\t\t\t\t\"if 'strides' is given in \" \\\n\t\t\t\t\t\t\"array creation, data must \" \\\n\t\t\t\t\t\t\"be given too\");\n\t\t\t\tgoto fail;\n\t\t\t} \n\t\t\tmemcpy(self->strides, strides, sizeof(intp)*nd);\n\t\t}\n\t} \t\n\t\t\n\tif (data == NULL) {\n\n\t\t/* Allocate something even for zero-space arrays \n\t\t e.g. shape=(0,) -- otherwise buffer exposure \n\t\t (a.data) doesn't work as it should. */\n\n\t\tif (sd==0) sd = descr->elsize;\n\n\t\tif ((data = PyDataMem_NEW(sd))==NULL) {\n\t\t\tPyErr_NoMemory();\n\t\t\tgoto fail;\n\t\t}\n\t\tself->flags |= OWN_DATA;\n\n\t\t/* It is bad to have unitialized OBJECT pointers */\n /* which could also be sub-fields of a VOID array */\n\t\tif (descr->hasobject) {\n if (descr != &OBJECT_Descr) {\n PyErr_SetString(PyExc_TypeError,\n \"fields with object members \" \\\n \"not yet supported.\");\n goto fail;\n }\n\t\t\tmemset(data, 0, sd);\n\t\t}\n\t}\n\telse {\n self->flags &= ~OWN_DATA; /* If data is passed in, \n\t\t\t\t\t this object won't own it \n\t\t\t\t\t by default.\n\t\t\t\t\t Caller must arrange for \n\t\t\t\t\t this to be reset if truly\n\t\t\t\t\t desired */\n }\n self->data = data;\n\n /* call the __array_finalize__\n\t method if a subtype and some object passed in */\n\tif ((obj != NULL) && (subtype != &PyArray_Type) && \n\t (subtype != &PyBigArray_Type)) {\n\t\tPyObject *res, *func, *args;\n\t\tstatic PyObject *str=NULL;\n\n\t\tif (str == NULL) {\n\t\t\tstr = PyString_InternFromString(\"__array_finalize__\");\n\t\t}\n\t\tif (!(self->flags & OWNDATA)) { /* did not allocate own data */\n\t\t\t /* update flags before calling back into\n\t\t\t Python */\n\t\t\tPyArray_UpdateFlags(self, UPDATE_ALL_FLAGS);\n\t\t}\n\t\tfunc = PyObject_GetAttr((PyObject *)self, str);\n\t\tif (func) {\n\t\t\targs = PyTuple_New(1);\n\t\t\tPy_INCREF(obj);\n\t\t\tPyTuple_SET_ITEM(args, 0, obj);\n\t\t\tres = PyObject_Call(func, args, NULL);\n\t\t\tPy_DECREF(args);\n\t\t\tPy_DECREF(func);\n\t\t\tif (res == NULL) goto fail;\n\t\t\telse Py_DECREF(res);\n\t\t}\n\t}\n\t\n\treturn (PyObject *)self;\n\n fail:\n\tPy_DECREF(self);\n\treturn NULL;\n}\n\n\n\n/*OBJECT_API\n Resize (reallocate data). Only works if nothing else is referencing\n this array and it is contiguous.\n*/\nstatic PyObject * \nPyArray_Resize(PyArrayObject *self, PyArray_Dims *newshape)\n{\n intp oldsize, newsize;\n int new_nd=newshape->len, k, n, elsize;\n int refcnt;\n intp* new_dimensions=newshape->ptr;\n intp new_strides[MAX_DIMS];\n intp sd;\n intp *dimptr;\n char *new_data;\n\t\n if (!PyArray_ISCONTIGUOUS(self)) {\n PyErr_SetString(PyExc_ValueError, \n \"resize only works on contiguous arrays\");\n return NULL;\n }\n\n newsize = PyArray_MultiplyList(new_dimensions, new_nd);\n oldsize = PyArray_SIZE(self);\n \n\tif (oldsize != newsize) {\n\t\tif (!(self->flags & OWN_DATA)) {\n\t\t\tPyErr_SetString(PyExc_ValueError, \n\t\t\t\t\t\"cannot resize this array: \"\t\\\n\t\t\t\t\t\"it does not own its data\");\n\t\t\treturn NULL;\n\t\t}\n\t\t\n\t\trefcnt = REFCOUNT(self);\n\t\tif ((refcnt > 2) || (self->base != NULL) || \\\n\t\t (self->weakreflist != NULL)) {\n\t\t\tPyErr_SetString(PyExc_ValueError, \n\t\t\t\t\t\"cannot resize an array that has \"\\\n\t\t\t\t\t\"been referenced or is referencing\\n\"\\\n\t\t\t\t\t\"another array in this way. Use the \"\\\n\t\t\t\t\t\"resize function\");\n\t\t\treturn NULL;\n\t\t} \n\t\t\t\t\n\t\tif (newsize == 0) sd = self->descr->elsize;\t\n\t\telse sd = newsize * self->descr->elsize;\n\t\t/* Reallocate space if needed */\n\t\tnew_data = PyDataMem_RENEW(self->data, sd);\n\t\tif (new_data == NULL) {\n\t\t\tPyErr_SetString(PyExc_MemoryError, \n\t\t\t\t\t\"cannot allocate memory for array\");\n\t\t\treturn NULL;\n\t\t}\n\t\tself->data = new_data;\n\t}\n \n if ((newsize > oldsize) && PyArray_ISWRITEABLE(self)) { \n\t\t/* Fill new memory with zeros */\n elsize = self->descr->elsize;\n\t\tif ((PyArray_TYPE(self) == PyArray_OBJECT)) {\n\t\t\tPyObject *zero = PyInt_FromLong(0);\n PyObject **optr;\n\t\t\toptr = ((PyObject **)self->data) + oldsize;\n\t\t\tn = newsize - oldsize;\n\t\t\tfor (k=0; kdata+oldsize*elsize, 0, \n\t\t\t (newsize-oldsize)*elsize);\n\t\t}\n\t}\n \n if (self->nd != new_nd) { /* Different number of dimensions. */\n self->nd = new_nd;\n \n /* Need new dimensions and strides arrays */\n dimptr = PyDimMem_RENEW(self->dimensions, 2*new_nd);\n if (dimptr == NULL) {\n\t\t\tPyErr_SetString(PyExc_MemoryError, \n \"cannot allocate memory for array \" \\\n \"(array may be corrupted)\");\n return NULL;\n }\n self->dimensions = dimptr;\n\t\tself->strides = dimptr + new_nd;\n }\n\n /* make new_strides variable */\n sd = (intp) self->descr->elsize;\n sd = _array_fill_strides(new_strides, new_dimensions, new_nd, sd,\n 0, &(self->flags));\n\n \n memmove(self->dimensions, new_dimensions, new_nd*sizeof(intp));\n memmove(self->strides, new_strides, new_nd*sizeof(intp));\n\n Py_INCREF(Py_None);\t\n return Py_None;\n \n}\n\n\n/* Assumes contiguous */\n/*OBJECT_API*/\nstatic void\nPyArray_FillObjectArray(PyArrayObject *arr, PyObject *obj)\n{\n PyObject **optr;\n intp i,n;\n optr = (PyObject **)(arr->data);\n n = PyArray_SIZE(arr);\n if (obj == NULL) {\n for (i=0; ielsize;\n\tPy_INCREF(descr);\n\tnewarr = PyArray_FromAny(obj, descr, 0,0, ALIGNED, NULL);\n\tif (newarr == NULL) return -1;\n\tfromptr = PyArray_DATA(newarr);\n\tsize=PyArray_SIZE(arr);\n\tswap=!PyArray_ISNOTSWAPPED(arr);\n\tcopyswap = arr->descr->f->copyswap;\n\tif (PyArray_ISONESEGMENT(arr)) {\n\t\tchar *toptr=PyArray_DATA(arr);\n\t\twhile (size--) {\n\t\t\tcopyswap(toptr, fromptr, swap, itemsize);\n\t\t\ttoptr += itemsize;\n\t\t}\n\t}\n\telse {\n\t\tPyArrayIterObject *iter;\n\t\t\n\t\titer = (PyArrayIterObject *)\\\n\t\t\tPyArray_IterNew((PyObject *)arr);\n\t\tif (iter == NULL) {\n\t\t\tPy_DECREF(newarr);\n\t\t\treturn -1;\n\t\t}\n\t\twhile(size--) {\n\t\t\tcopyswap(iter->dataptr, fromptr, swap, itemsize);\n\t\t\tPyArray_ITER_NEXT(iter);\n\t\t}\n\t\tPy_DECREF(iter);\n\t}\n\tPy_DECREF(newarr);\n\treturn 0;\n}\n\nstatic PyObject *\narray_new(PyTypeObject *subtype, PyObject *args, PyObject *kwds) \n{\n\tstatic char *kwlist[] = {\"shape\", \"dtype\", \"buffer\", /* XXX ? */\n\t\t\t\t \"offset\", \"strides\",\n\t\t\t\t \"fortran\", NULL};\n\tPyArray_Descr *descr=NULL;\n\tint type_num;\n\tint itemsize;\n PyArray_Dims dims = {NULL, 0};\n PyArray_Dims strides = {NULL, 0};\n PyArray_Chunk buffer;\n\tlonglong offset=0;\n\tint fortran = 0;\n\tPyArrayObject *ret;\n\n\tbuffer.ptr = NULL; \n /* Usually called with shape and type\n but can also be called with buffer, strides, and swapped info\n */\n\n\t/* For now, let's just use this to create an empty, contiguous \n\t array of a specific type and shape. \n\t*/\t\n\n\tif (!PyArg_ParseTupleAndKeywords(args, kwds, \"O&|O&O&LO&i\",\n\t\t\t\t\t kwlist, PyArray_IntpConverter,\n &dims, \n PyArray_DescrConverter,\n\t\t\t\t\t &descr,\n PyArray_BufferConverter,\n &buffer,\n\t\t\t\t\t &offset,\n &PyArray_IntpConverter, \n &strides,\n &fortran)) \n\t\tgoto fail;\n\n\n\tif (descr == NULL)\n\t\tdescr = PyArray_DescrFromType(PyArray_LONG);\n\n\ttype_num = descr->type_num;\n\titemsize = descr->elsize;\n\n if (dims.ptr == NULL) {\n PyErr_SetString(PyExc_ValueError, \"need to give a \"\\\n \"valid shape as the first argument\");\n goto fail;\n }\n\n if (buffer.ptr == NULL) {\n ret = (PyArrayObject *)\\\n\t\t\tPyArray_NewFromDescr(subtype, descr,\n\t\t\t\t\t (int)dims.len, \n\t\t\t\t\t dims.ptr, \n\t\t\t\t\t NULL, NULL, fortran, NULL);\n if (ret == NULL) {descr=NULL;goto fail;}\n if (type_num == PyArray_OBJECT) { /* place Py_None */\n PyArray_FillObjectArray(ret, Py_None);\n }\n }\n else { /* buffer given -- use it */\n\t\tbuffer.len -= offset;\n\t\tbuffer.ptr += offset;\n if (dims.len == 1 && dims.ptr[0] == -1) {\n dims.ptr[0] = buffer.len / itemsize;\n }\n else if (buffer.len < itemsize* \\\n PyArray_MultiplyList(dims.ptr, dims.len)) {\n PyErr_SetString(PyExc_TypeError, \n \"buffer is too small for \" \\\n \"requested array\");\n goto fail;\n }\n if (strides.ptr != NULL) {\n\t\t\tif (strides.len != dims.len) {\n\t\t\t\tPyErr_SetString(PyExc_ValueError, \n\t\t\t\t\t\t\"strides, if given, must be \"\\\n\t\t\t\t\t\t\"the same length as shape\");\n\t\t\t\tgoto fail;\n\t\t\t}\n\t\t\tif (!PyArray_CheckStrides(itemsize, strides.len, \n\t\t\t\t\t\t buffer.len,\n\t\t\t\t\t\t dims.ptr, strides.ptr)) {\n\t\t\t\tPyErr_SetString(PyExc_ValueError, \n\t\t\t\t\t\t\"strides is incompatible \"\\\n\t\t\t\t\t\t\"with shape of requested\"\\\n\t\t\t\t\t\t\"array and size of buffer\");\n\t\t\t\tgoto fail;\n\t\t\t}\n }\n if (type_num == PyArray_OBJECT) {\n PyErr_SetString(PyExc_TypeError, \"cannot construct \"\\\n \"an object array from buffer data\");\n goto fail;\n }\n /* get writeable and aligned */\n if (fortran) buffer.flags |= FORTRAN;\n ret = (PyArrayObject *)\\\n\t\t\tPyArray_NewFromDescr(subtype, descr,\n\t\t\t\t\t dims.len, dims.ptr,\n\t\t\t\t\t strides.ptr,\n\t\t\t\t\t (char *)buffer.ptr, \n\t\t\t\t\t buffer.flags, NULL); \n if (ret == NULL) {descr=NULL; goto fail;}\n PyArray_UpdateFlags(ret, UPDATE_ALL_FLAGS);\n ret->base = buffer.base;\n Py_INCREF(buffer.base); \n }\n\n PyDimMem_FREE(dims.ptr);\n if (strides.ptr) PyDimMem_FREE(strides.ptr);\n return (PyObject *)ret;\n \n fail:\n\tPy_XDECREF(descr);\n if (dims.ptr) PyDimMem_FREE(dims.ptr);\n if (strides.ptr) PyDimMem_FREE(strides.ptr);\n return NULL;\n}\n\n\nstatic PyObject *\narray_iter(PyArrayObject *arr)\n{\n\tif (arr->nd == 0) {\n\t\tPyErr_SetString(PyExc_TypeError,\n\t\t\t\t\"iteration over a scalar (0-dim array)\");\n\t\treturn NULL;\n\t}\n\treturn PySeqIter_New((PyObject *)arr);\n}\n\n\n/******************* array attribute get and set routines ******************/\n\nstatic PyObject *\narray_ndim_get(PyArrayObject *self)\n{\n\treturn PyInt_FromLong(self->nd);\n}\n\nstatic PyObject *\narray_flags_get(PyArrayObject *self)\n{\n return PyObject_CallMethod(_numpy_internal, \"flagsobj\", \"Oii\", \n self, self->flags, 0);\n}\n\nstatic PyObject *\narray_shape_get(PyArrayObject *self)\n{\n\treturn PyArray_IntTupleFromIntp(self->nd, self->dimensions);\n}\n\n\nstatic int\narray_shape_set(PyArrayObject *self, PyObject *val)\n{\n \tint nd;\n\tPyObject *ret;\n\n\tret = PyArray_Reshape(self, val);\n\tif (ret == NULL) return -1;\n\n\t/* Free old dimensions and strides */\n\tPyDimMem_FREE(self->dimensions);\n\tnd = PyArray_NDIM(ret);\n\tself->nd = nd;\n\tif (nd > 0) { /* create new dimensions and strides */\n\t\tself->dimensions = PyDimMem_NEW(2*nd);\n\t\tif (self->dimensions == NULL) {\n\t\t\tPy_DECREF(ret);\n\t\t\tPyErr_SetString(PyExc_MemoryError,\"\");\n\t\t\treturn -1;\n\t\t}\n\t\tself->strides = self->dimensions + nd;\n\t\tmemcpy(self->dimensions, PyArray_DIMS(ret), \n\t\t nd*sizeof(intp));\n\t\tmemcpy(self->strides, PyArray_STRIDES(ret), \n\t\t nd*sizeof(intp));\n\t}\n\telse {self->dimensions=NULL; self->strides=NULL;}\n\tPy_DECREF(ret);\n\tPyArray_UpdateFlags(self, CONTIGUOUS | FORTRAN);\n\treturn 0;\n}\n\n\nstatic PyObject *\narray_strides_get(PyArrayObject *self)\n{\n\treturn PyArray_IntTupleFromIntp(self->nd, self->strides);\n}\n\nstatic int\narray_strides_set(PyArrayObject *self, PyObject *obj)\n{\n\tPyArray_Dims newstrides = {NULL, 0};\n\tPyArrayObject *new;\n\tintp numbytes;\n\n\tif (!PyArray_IntpConverter(obj, &newstrides) || \\\n\t newstrides.ptr == NULL) {\n\t\tPyErr_SetString(PyExc_TypeError, \"invalid strides\");\n\t\treturn -1;\n\t}\n\tif (newstrides.len != self->nd) {\n\t\tPyErr_Format(PyExc_ValueError, \"strides must be \"\t\\\n\t\t\t \" same length as shape (%d)\", self->nd);\n\t\tgoto fail;\n\t}\n\tnew = self;\n\twhile(new->base != NULL) {\n\t\tif (PyArray_Check(new->base)) \n\t\t\tnew = (PyArrayObject *)new->base;\n\t}\n\tnumbytes = PyArray_MultiplyList(new->dimensions, \n\t\t\t\t\tnew->nd)*new->descr->elsize;\n\t\n\tif (!PyArray_CheckStrides(self->descr->elsize, self->nd, numbytes, \n\t\t\t\t self->dimensions, newstrides.ptr)) {\n\t\tPyErr_SetString(PyExc_ValueError, \"strides is not \"\\\n\t\t\t\t\"compatible with available memory\");\n\t\tgoto fail;\n\t}\n\tmemcpy(self->strides, newstrides.ptr, sizeof(intp)*newstrides.len);\n\tPyArray_UpdateFlags(self, CONTIGUOUS | FORTRAN);\n\tPyDimMem_FREE(newstrides.ptr);\n\treturn 0;\n\n fail:\n\tPyDimMem_FREE(newstrides.ptr);\n\treturn -1;\n}\n\n\nstatic PyObject *\narray_protocol_strides_get(PyArrayObject *self)\n{\n\tif PyArray_ISCONTIGUOUS(self) {\n\t\tPy_INCREF(Py_None);\n\t\treturn Py_None;\n\t}\n\treturn PyArray_IntTupleFromIntp(self->nd, self->strides);\n}\n\nstatic PyObject *\narray_priority_get(PyArrayObject *self)\n{\n\tif (PyArray_CheckExact(self)) \n\t\treturn PyFloat_FromDouble(PyArray_PRIORITY);\n\telse if (PyBigArray_CheckExact(self)) \n\t\treturn PyFloat_FromDouble(PyArray_BIG_PRIORITY);\n\telse\n\t\treturn PyFloat_FromDouble(PyArray_SUBTYPE_PRIORITY);\n}\n\n\nstatic PyObject *\narray_dataptr_get(PyArrayObject *self)\n{\n\treturn Py_BuildValue(\"NO\",\n\t\t\t PyString_FromFormat(\"%p\", self->data),\n\t\t\t (self->flags & WRITEABLE ? Py_False :\n\t\t\t Py_True));\n}\n\nstatic PyObject *\narray_data_get(PyArrayObject *self)\n{\n\tintp nbytes;\n\tif (!(PyArray_ISONESEGMENT(self))) {\n\t\tPyErr_SetString(PyExc_AttributeError, \"cannot get single-\"\\\n\t\t\t\t\"segment buffer for discontiguous array\");\n\t\treturn NULL;\n\t}\t\t\n\tnbytes = PyArray_NBYTES(self);\n\tif PyArray_ISWRITEABLE(self) \n\t\treturn PyBuffer_FromReadWriteObject((PyObject *)self, 0, \n\t\t\t\t\t\t (int) nbytes);\n\telse\n\t\treturn PyBuffer_FromObject((PyObject *)self, 0, (int) nbytes);\n}\n\nstatic int\narray_data_set(PyArrayObject *self, PyObject *op)\n{\n\tvoid *buf;\n\tint buf_len;\n\tint writeable=1;\n\n\tif (PyObject_AsWriteBuffer(op, &buf, &buf_len) < 0) {\n\t\twriteable = 0;\n\t\tif (PyObject_AsReadBuffer(op, (const void **)&buf, \n\t\t\t\t\t &buf_len) < 0) {\n\t\t\tPyErr_SetString(PyExc_AttributeError, \n\t\t\t\t\t\"object does not have single-segment \" \\\n\t\t\t\t\t\"buffer interface\");\n\t\t\treturn -1;\n\t\t}\n\t}\n\tif (!PyArray_ISONESEGMENT(self)) {\n\t\tPyErr_SetString(PyExc_AttributeError, \"cannot set single-\" \\\n\t\t\t\t\"segment buffer for discontiguous array\");\n\t\treturn -1;\n\t}\n\tif (PyArray_NBYTES(self) > buf_len) {\n\t\tPyErr_SetString(PyExc_AttributeError, \n\t\t\t\t\"not enough data for array\");\n\t\treturn -1;\n\t}\n\tif (self->flags & OWN_DATA) {\n\t\tPyArray_XDECREF(self);\n\t\tPyDataMem_FREE(self->data);\n\t}\n\tif (self->base) {\n\t\tif (self->flags & UPDATEIFCOPY) {\n\t\t\t((PyArrayObject *)self->base)->flags |= WRITEABLE;\n\t\t\tself->flags &= ~UPDATEIFCOPY;\n\t\t}\n\t\tPy_DECREF(self->base);\n\t}\n\tPy_INCREF(op);\n\tself->base = op;\n\tself->data = buf;\n\tself->flags = CARRAY_FLAGS;\n\tif (!writeable)\n\t\tself->flags &= ~WRITEABLE;\n\treturn 0;\n}\n\n\nstatic PyObject *\narray_itemsize_get(PyArrayObject *self)\n{\n\treturn PyInt_FromLong((long) self->descr->elsize);\n}\n\nstatic PyObject *\narray_size_get(PyArrayObject *self)\n{\n\tintp size=PyArray_SIZE(self);\n#if SIZEOF_INTP <= SIZEOF_LONG\n return PyInt_FromLong((long) size);\n#else\n\tif (size > MAX_LONG || size < MIN_LONG)\n\t\treturn PyLong_FromLongLong(size);\n\telse \n\t\treturn PyInt_FromLong((long) size);\n#endif\n}\n\nstatic PyObject *\narray_nbytes_get(PyArrayObject *self)\n{\n intp nbytes = PyArray_NBYTES(self);\n#if SIZEOF_INTP <= SIZEOF_LONG\n return PyInt_FromLong((long) nbytes);\n#else\n\tif (nbytes > MAX_LONG || nbytes < MIN_LONG)\n\t\treturn PyLong_FromLongLong(nbytes);\n\telse \n\t\treturn PyInt_FromLong((long) nbytes);\n#endif\n}\n\n\nstatic PyObject *arraydescr_protocol_typestr_get(PyArray_Descr *);\n\nstatic PyObject *\narray_typestr_get(PyArrayObject *self)\n{\n\treturn arraydescr_protocol_typestr_get(self->descr);\n}\n\nstatic PyObject *\narray_descr_get(PyArrayObject *self) \n{\n\tPy_INCREF(self->descr);\n\treturn (PyObject *)self->descr;\n}\n\n\n/* If the type is changed. \n Also needing change: strides, itemsize\n\n Either itemsize is exactly the same\n or the array is single-segment (contiguous or fortran) with\n compatibile dimensions\n\n The shape and strides will be adjusted in that case as well.\n*/\n\nstatic int\narray_descr_set(PyArrayObject *self, PyObject *arg)\n{\n PyArray_Descr *newtype=NULL;\n intp newdim;\n int index;\n char *msg = \"new type not compatible with array.\";\n\n if (!(PyArray_DescrConverter(arg, &newtype)) ||\n newtype == NULL) {\n PyErr_SetString(PyExc_TypeError, \"invalid data-type for array\");\n\t\treturn -1;\n }\n\tif (newtype->type_num == PyArray_OBJECT || \\\n\t self->descr->type_num == PyArray_OBJECT) {\n\t\tPyErr_SetString(PyExc_TypeError, \\\n\t\t\t\t\"Cannot change descriptor for object\"\\\n\t\t\t\t\"array.\");\n\t\tPy_DECREF(newtype);\n\t\treturn -1;\n\t}\n\n\tif ((newtype->elsize != self->descr->elsize) &&\t\t\\\n\t (self->nd == 0 || !PyArray_ISONESEGMENT(self) || \\\n\t newtype->subarray)) goto fail;\n\t\n\tif (PyArray_ISCONTIGUOUS(self)) index = self->nd - 1;\n\telse index = 0;\n\t\n\tif (newtype->elsize < self->descr->elsize) {\n\t\t/* if it is compatible increase the size of the \n\t\t dimension at end (or at the front for FORTRAN)\n\t\t*/\n\t\tif (self->descr->elsize % newtype->elsize != 0) \n\t\t\tgoto fail;\n\t\tnewdim = self->descr->elsize / newtype->elsize;\n\t\tself->dimensions[index] *= newdim;\n\t\tself->strides[index] = newtype->elsize;\n\t}\n\t\n\telse if (newtype->elsize > self->descr->elsize) {\n\t\t\n\t\t/* Determine if last (or first if FORTRAN) dimension\n\t\t is compatible */\n\t\t\n\t\tnewdim = self->dimensions[index] * self->descr->elsize;\n\t\tif ((newdim % newtype->elsize) != 0) goto fail;\n\t\t\n\t\tself->dimensions[index] = newdim / newtype->elsize;\n\t\tself->strides[index] = newtype->elsize;\n\t}\n\n /* fall through -- adjust type*/\n\n\tPy_DECREF(self->descr);\n\tif (newtype->subarray) {\n\t\t/* create new array object from data and update \n\t\t dimensions, strides and descr from it */\n\t\tPyArrayObject *temp;\n\n\t\ttemp = (PyArrayObject *)\\\n\t\t\tPyArray_NewFromDescr(&PyArray_Type, newtype, self->nd,\n\t\t\t\t\t self->dimensions, self->strides,\n\t\t\t\t\t self->data, self->flags, NULL);\n\t\tPyDimMem_FREE(self->dimensions);\n\t\tself->dimensions = temp->dimensions;\n\t\tself->nd = temp->nd;\n\t\tself->strides = temp->strides;\n\t\tPy_DECREF(newtype);\n\t\tnewtype = temp->descr;\n\t\t/* Fool deallocator */\n\t\ttemp->nd = 0;\n\t\ttemp->dimensions = NULL;\n\t\ttemp->descr = NULL;\n\t\tPy_DECREF(temp);\n\t}\n\n\tself->descr = newtype; \n\tPyArray_UpdateFlags(self, UPDATE_ALL_FLAGS);\n\t\n return 0;\n\n fail:\n\tPyErr_SetString(PyExc_ValueError, msg);\n\tPy_DECREF(newtype);\n\treturn -1;\n}\n\nstatic PyObject *\narray_protocol_descr_get(PyArrayObject *self)\n{\n\tPyObject *res;\n\tPyObject *dobj;\n\t\n\tres = PyObject_GetAttrString((PyObject *)self->descr, \"descr\");\n\tif (res) return res;\n\tPyErr_Clear();\n\n\t/* get default */\n\tdobj = PyTuple_New(2);\n\tif (dobj == NULL) return NULL;\n\tPyTuple_SET_ITEM(dobj, 0, PyString_FromString(\"\"));\n\tPyTuple_SET_ITEM(dobj, 1, array_typestr_get(self));\n\tres = PyList_New(1);\n\tif (res == NULL) {Py_DECREF(dobj); return NULL;}\n\tPyList_SET_ITEM(res, 0, dobj);\n\treturn res;\n}\n\nstatic PyObject *\narray_struct_get(PyArrayObject *self)\n{\n PyArrayInterface *inter;\n \n inter = (PyArrayInterface *)_pya_malloc(sizeof(PyArrayInterface));\n inter->version = 2;\n inter->nd = self->nd;\n inter->typekind = self->descr->kind;\n inter->itemsize = self->descr->elsize;\n inter->flags = self->flags;\n /* reset unused flags */\n\tinter->flags &= ~(UPDATEIFCOPY | OWNDATA); \n\tif (PyArray_ISNOTSWAPPED(self)) inter->flags |= NOTSWAPPED;\n inter->strides = self->strides;\n inter->shape = self->dimensions;\n inter->data = self->data;\n\tPy_INCREF(self);\n return PyCObject_FromVoidPtrAndDesc(inter, self, gentype_struct_free);\n}\n\nstatic PyObject *\narray_base_get(PyArrayObject *self)\n{\n\tif (self->base == NULL) {\n\t\tPy_INCREF(Py_None);\n\t\treturn Py_None;\n\t}\n\telse {\n\t\tPy_INCREF(self->base);\n\t\treturn self->base;\n\t}\n}\n\n\nstatic PyObject *\narray_real_get(PyArrayObject *self)\n{\n\tPyArrayObject *ret;\n\n\tif (PyArray_ISCOMPLEX(self)) {\n\t\tret = (PyArrayObject *)PyArray_New(self->ob_type,\n\t\t\t\t\t\t self->nd,\n\t\t\t\t\t\t self->dimensions,\n\t\t\t\t\t\t self->descr->type_num - \\\n\t\t\t\t\t\t PyArray_NUM_FLOATTYPE,\n\t\t\t\t\t\t self->strides,\n\t\t\t\t\t\t self->data,\n\t\t\t\t\t\t 0,\n\t\t\t\t\t\t self->flags, (PyObject *)self);\n\t\tif (ret == NULL) return NULL;\n\t\tret->flags &= ~CONTIGUOUS;\n\t\tret->flags &= ~FORTRAN;\n\t\tPy_INCREF(self);\n\t\tret->base = (PyObject *)self;\n\t\treturn (PyObject *)ret;\n\t}\n\telse {\n\t\tPy_INCREF(self);\n\t\treturn (PyObject *)self;\n\t}\n}\n\n\nstatic int\narray_real_set(PyArrayObject *self, PyObject *val)\n{\n\tPyArrayObject *ret;\n\tPyArrayObject *new;\n\tint rint;\n\n\tnew = (PyArrayObject *)PyArray_FromAny(val, NULL, 0, 0, 0, NULL);\n\tif (new == NULL) return -1;\n\t\n\tif (PyArray_ISCOMPLEX(self)) {\n\t\tret = (PyArrayObject *)PyArray_New(self->ob_type,\n\t\t\t\t\t\t self->nd,\n\t\t\t\t\t\t self->dimensions,\n\t\t\t\t\t\t self->descr->type_num - \\\n\t\t\t\t\t\t PyArray_NUM_FLOATTYPE,\n\t\t\t\t\t\t self->strides,\n\t\t\t\t\t\t self->data,\n\t\t\t\t\t\t 0,\n\t\t\t\t\t\t self->flags, (PyObject *)self);\n\t\tif (ret == NULL) {Py_DECREF(new); return -1;}\n\t\tret->flags &= ~CONTIGUOUS;\n\t\tret->flags &= ~FORTRAN;\n\t\tPy_INCREF(self);\n\t\tret->base = (PyObject *)self;\n\t}\n\telse {\n\t\tPy_INCREF(self);\n\t\tret = self;\n\t}\t\n\trint = PyArray_CopyInto(ret, new);\n\tPy_DECREF(ret);\n\tPy_DECREF(new);\n\treturn rint;\n}\n\nstatic PyObject *\narray_imag_get(PyArrayObject *self)\n{\t\n\tPyArrayObject *ret;\n PyArray_Descr *type;\n\n\tif (PyArray_ISCOMPLEX(self)) {\n\t\ttype = PyArray_DescrFromType(self->descr->type_num - \n\t\t\t\t\t PyArray_NUM_FLOATTYPE);\n\t\tret = (PyArrayObject *)\t\t\t\t\\\n\t\t\tPyArray_NewFromDescr(self->ob_type,\n\t\t\t\t\t type,\n\t\t\t\t\t self->nd,\n\t\t\t\t\t self->dimensions,\n\t\t\t\t\t self->strides,\n\t\t\t\t\t self->data + type->elsize,\n\t\t\t\t\t self->flags, (PyObject *)self);\n\t\tif (ret == NULL) return NULL;\n\t\tret->flags &= ~CONTIGUOUS;\n\t\tret->flags &= ~FORTRAN;\n\t\tPy_INCREF(self);\n\t\tret->base = (PyObject *)self;\n\t\treturn (PyObject *) ret;\n\t}\n\telse {\n\t\ttype = self->descr;\n\t\tPy_INCREF(type);\n\t\tret = (PyArrayObject *)PyArray_Zeros(self->nd, \n\t\t\t\t\t\t self->dimensions,\n\t\t\t\t\t\t type, \n\t\t\t\t\t\t PyArray_ISFORTRAN(self));\n\t\tret->flags &= ~WRITEABLE;\n\t\treturn (PyObject *)ret;\n\t}\n}\n\nstatic int\narray_imag_set(PyArrayObject *self, PyObject *val)\n{\t\n\tif (PyArray_ISCOMPLEX(self)) {\n\t\tPyArrayObject *ret;\n\t\tPyArrayObject *new;\n\t\tint rint;\n\n\t\tnew = (PyArrayObject *)PyArray_FromAny(val, NULL, 0, 0, 0, NULL); \n\t\tif (new == NULL) return -1;\n\t\tret = (PyArrayObject *)PyArray_New(self->ob_type,\n\t\t\t\t\t\t self->nd,\n\t\t\t\t\t\t self->dimensions,\n\t\t\t\t\t\t self->descr->type_num - \\\n\t\t\t\t\t\t PyArray_NUM_FLOATTYPE,\n\t\t\t\t\t\t self->strides,\n \t\t\t\t\t\t self->data +\t\t\\\n\t\t\t\t\t\t (self->descr->elsize >> 1),\n\t\t\t\t\t\t 0,\n\t\t\t\t\t\t self->flags, (PyObject *)self);\n\t\tif (ret == NULL) {\n\t\t\tPy_DECREF(new); \n\t\t\treturn -1;\n\t\t}\n\t\tret->flags &= ~CONTIGUOUS;\n\t\tret->flags &= ~FORTRAN;\n\t\tPy_INCREF(self);\n\t\tret->base = (PyObject *)self;\n\t\trint = PyArray_CopyInto(ret, new);\n\t\tPy_DECREF(ret);\t\t\n\t\tPy_DECREF(new);\n\t\treturn rint;\n\t}\n\telse {\n\t\tPyErr_SetString(PyExc_TypeError, \"does not have imaginary \" \\\n\t\t\t\t\"part to set\");\n\t\treturn -1;\n\t}\n}\n\nstatic PyObject *\narray_flat_get(PyArrayObject *self)\n{\n return PyArray_IterNew((PyObject *)self);\n}\n\nstatic int \narray_flat_set(PyArrayObject *self, PyObject *val)\n{\n\tPyObject *arr=NULL;\n\tint retval = -1;\n\tPyArrayIterObject *selfit=NULL, *arrit=NULL;\n\tPyArray_Descr *typecode;\n int swap;\n PyArray_CopySwapFunc *copyswap;\n\n\ttypecode = self->descr;\n\tPy_INCREF(typecode);\n\tarr = PyArray_FromAny(val, typecode, \n\t\t\t 0, 0, FORCECAST | FORTRAN_IF(self), NULL);\n\tif (arr == NULL) return -1;\n\tarrit = (PyArrayIterObject *)PyArray_IterNew(arr);\n\tif (arrit == NULL) goto exit;\n\tselfit = (PyArrayIterObject *)PyArray_IterNew((PyObject *)self);\n\tif (selfit == NULL) goto exit;\n\n swap = PyArray_ISNOTSWAPPED(self) != PyArray_ISNOTSWAPPED(arr);\n copyswap = self->descr->f->copyswap;\n if (PyArray_ISOBJECT(self)) {\n while(selfit->index < selfit->size) {\n Py_XDECREF(*((PyObject **)selfit->dataptr));\n Py_INCREF(*((PyObject **)arrit->dataptr)); \n memmove(selfit->dataptr, arrit->dataptr, \n sizeof(PyObject *));\n PyArray_ITER_NEXT(selfit);\n PyArray_ITER_NEXT(arrit);\n if (arrit->index == arrit->size) \n PyArray_ITER_RESET(arrit);\n }\n retval = 0; \n goto exit;\n }\n\n\twhile(selfit->index < selfit->size) {\n\t\tmemmove(selfit->dataptr, arrit->dataptr, self->descr->elsize);\n copyswap(selfit->dataptr, NULL, swap, self->descr->elsize);\n\t\tPyArray_ITER_NEXT(selfit);\n\t\tPyArray_ITER_NEXT(arrit);\n\t\tif (arrit->index == arrit->size) \n\t\t\tPyArray_ITER_RESET(arrit);\n\t}\n\tretval = 0;\n exit:\n\tPy_XDECREF(selfit);\n\tPy_XDECREF(arrit);\n\tPy_XDECREF(arr);\n\treturn retval;\n}\n\nstatic PyGetSetDef array_getsetlist[] = {\n {\"ndim\", \n\t (getter)array_ndim_get, \n\t NULL, \n\t \"number of array dimensions\"},\n {\"flags\", \n\t (getter)array_flags_get, \n NULL,\n\t \"special dictionary of flags\"},\n {\"shape\", \n\t (getter)array_shape_get, \n\t (setter)array_shape_set, \n\t \"tuple of array dimensions\"},\n {\"strides\", \n\t (getter)array_strides_get, \n\t (setter)array_strides_set,\n\t \"tuple of bytes steps in each dimension\"},\n {\"data\", \n\t (getter)array_data_get, \n\t (setter)array_data_set, \n\t \"pointer to start of data\"},\n {\"itemsize\", \n\t (getter)array_itemsize_get, \n\t NULL,\n\t \"length of one element in bytes\"},\n {\"size\",\n (getter)array_size_get,\n\t NULL,\n \"number of elements in the array\"},\n {\"nbytes\",\n (getter)array_nbytes_get,\n NULL,\n \"number of bytes in the array\"},\n\t{\"base\",\n\t (getter)array_base_get,\n\t NULL,\n\t \"base object\"},\n\t{\"dtype\",\n\t (getter)array_descr_get,\n\t (setter)array_descr_set,\n\t \"get(set) data-type-descriptor for array\"},\n {\"real\", \n\t (getter)array_real_get, \n\t (setter)array_real_set, \n\t \"real part of array\"},\n {\"imag\", \n\t (getter)array_imag_get, \n\t (setter)array_imag_set, \n\t \"imaginary part of array\"},\n\t{\"flat\", \n\t (getter)array_flat_get, \n\t (setter)array_flat_set, \n\t \"a 1-d view of a contiguous array\"}, \n\t{\"__array_data__\", \n\t (getter)array_dataptr_get,\n\t NULL,\n\t \"Array protocol: data\"},\n\t{\"__array_typestr__\",\n\t (getter)array_typestr_get,\n\t NULL,\n\t \"Array protocol: typestr\"},\n\t{\"__array_descr__\",\n\t (getter)array_protocol_descr_get,\n\t NULL,\n\t \"Array protocol: descr\"},\n\t{\"__array_shape__\", \n\t (getter)array_shape_get,\n\t NULL,\n\t \"Array protocol: shape\"},\n\t{\"__array_strides__\",\n\t (getter)array_protocol_strides_get,\n\t NULL,\n\t \"Array protocol: strides\"},\n {\"__array_struct__\",\n (getter)array_struct_get,\n NULL,\n \"Array protocol: struct\"},\n\t{\"__array_priority__\",\n\t (getter)array_priority_get,\n\t NULL,\n\t \"Array priority\"},\n \t{NULL, NULL, NULL, NULL}, /* Sentinel */\n};\n\n/****************** end of attribute get and set routines *******************/\n\n\nstatic PyObject *\narray_alloc(PyTypeObject *type, int nitems)\n{\n PyObject *obj;\n /* nitems will always be 0 */ \n obj = (PyObject *)_pya_malloc(sizeof(PyArrayObject));\n PyObject_Init(obj, type);\n return obj;\n}\n\n\nstatic char Arraytype__doc__[] = \n \"A array object represents a multidimensional, homogeneous array\\n\"\n\t\" of fixed-size items. An associated data-type-descriptor object\\n\"\n\t\" details the data-type in an array (including byteorder and any\\n\"\n\t\" fields). An array can be constructed using the numpy.array\\n\"\n\t\" command. Arrays are sequence, mapping and numeric objects.\\n\"\n\t\" More information is available in the numpy module and by looking\\n\"\n\t\" at the methods and attributes of an array.\\n\\n\"\n\t\" ndarray.__new__(subtype, shape=, dtype=int_, buffer=None, \\n\"\n\t\" offset=0, strides=None, fortran=False)\\n\\n\"\n\t\" There are two modes of creating an array using __new__:\\n\"\n\t\" 1) If buffer is None, then only shape, dtype, and fortran \\n\"\n\t\" are used\\n\"\n\t\" 2) If buffer is an object exporting the buffer interface, then\\n\"\n\t\" all keywords are interpreted.\\n\"\n\t\" The dtype parameter can be any object that can be interpreted \\n\"\n\t\" as a numpy.dtype object.\\n\\n\"\n\t\" No __init__ method is needed because the array is fully \\n\"\n\t\" initialized after the __new__ method.\";\n\t\nstatic PyTypeObject PyBigArray_Type = { \n PyObject_HEAD_INIT(NULL)\n 0,\t\t\t\t\t /*ob_size*/\n \"numpy.bigndarray\",\t\t /*tp_name*/\n sizeof(PyArrayObject),\t\t /*tp_basicsize*/\n 0,\t\t\t\t\t /*tp_itemsize*/\n /* methods */\n (destructor)array_dealloc,\t\t /*tp_dealloc */\n (printfunc)NULL,\t\t\t /*tp_print*/\n 0,\t\t\t\t\t /*tp_getattr*/\n 0,\t\t\t\t\t /*tp_setattr*/\n (cmpfunc)0, \t\t /*tp_compare*/\n (reprfunc)array_repr,\t\t /*tp_repr*/\n &array_as_number,\t\t\t /*tp_as_number*/\n NULL, \t\t\t /*tp_as_sequence*/\n &array_as_mapping,\t\t\t /*tp_as_mapping*/\n (hashfunc)0,\t\t\t /*tp_hash*/\n (ternaryfunc)0,\t\t\t /*tp_call*/\n (reprfunc)array_str, \t /*tp_str*/\n\t\t\n (getattrofunc)0,\t\t\t /*tp_getattro*/\n (setattrofunc)0,\t\t\t /*tp_setattro*/\n NULL, \t /*tp_as_buffer*/\n (Py_TPFLAGS_DEFAULT \n | Py_TPFLAGS_BASETYPE\n | Py_TPFLAGS_CHECKTYPES), /*tp_flags*/\n /*Documentation string */\n Arraytype__doc__,\t\t\t /*tp_doc*/\n\n (traverseproc)0,\t\t\t /*tp_traverse */\n (inquiry)0,\t\t\t /*tp_clear */\n (richcmpfunc)array_richcompare,\t /*tp_richcompare */\n offsetof(PyArrayObject, weakreflist), /*tp_weaklistoffset */\n\n /* Iterator support (use standard) */\n\n (getiterfunc)array_iter, \t /* tp_iter */\n (iternextfunc)0,\t\t\t /* tp_iternext */\n\n /* Sub-classing (new-style object) support */\n\n array_methods,\t\t\t /* tp_methods */\n 0,\t\t\t\t\t /* tp_members */\n array_getsetlist,\t\t /* tp_getset */\n 0,\t\t\t\t\t /* tp_base */\n 0,\t\t\t\t\t /* tp_dict */\n 0,\t\t\t\t\t /* tp_descr_get */\n 0,\t\t\t\t\t /* tp_descr_set */\n 0,\t\t\t\t\t /* tp_dictoffset */\n (initproc)0,\t \t /* tp_init */\n array_alloc,\t /* tp_alloc */ \n (newfunc)array_new,\t\t /* tp_new */\n _pya_free, \t /* tp_free */\n 0,\t\t\t\t\t /* tp_is_gc */\n 0,\t\t\t\t\t /* tp_bases */\n 0,\t\t\t\t\t /* tp_mro */\n 0,\t\t\t\t\t /* tp_cache */\n 0,\t\t\t\t\t /* tp_subclasses */\n 0\t\t\t\t\t /* tp_weaklist */\n};\n\n/* A standard array will subclass from the Big Array and \n add the array_as_sequence table\n and the array_as_buffer table\n */\n\nstatic PyTypeObject PyArray_Type = { \n PyObject_HEAD_INIT(NULL)\n 0,\t\t\t\t\t /*ob_size*/\n \"numpy.ndarray\",\t\t\t /*tp_name*/\n sizeof(PyArrayObject),\t\t /*tp_basicsize*/\n 0,\t\t\t\t\t /*tp_itemsize*/\n};\n\n\n/* The rest of this code is to build the right kind of array from a python */\n/* object. */\n\nstatic int \ndiscover_depth(PyObject *s, int max, int stop_at_string, int stop_at_tuple) \n{\n int d=0;\n PyObject *e;\n\t\n if(max < 1) return -1;\n\n if(! PySequence_Check(s) || PyInstance_Check(s) || \\\n\t PySequence_Length(s) < 0) {\n PyErr_Clear(); return 0;\n }\n if (PyArray_Check(s))\n\t\treturn PyArray_NDIM(s);\n if(PyString_Check(s) || PyBuffer_Check(s) || PyUnicode_Check(s))\n\t\treturn stop_at_string ? 0:1;\n\tif (stop_at_tuple && PyTuple_Check(s)) return 0;\n\tif ((e=PyObject_GetAttrString(s, \"__array_shape__\")) != NULL) {\n\t\tif (PyTuple_Check(e)) d=PyTuple_GET_SIZE(e);\n\t\telse d=-1;\n\t\tPy_DECREF(e);\n\t\tif (d>-1) return d;\n\t}\n\telse PyErr_Clear();\n\n if (PySequence_Length(s) == 0) \n\t\treturn 1;\t\n if ((e=PySequence_GetItem(s,0)) == NULL) return -1;\n if(e!=s) {\n\t\td=discover_depth(e, max-1, stop_at_string, stop_at_tuple);\n\t\tif(d >= 0) d++;\n\t}\n Py_DECREF(e);\n return d;\n}\n\nstatic int\ndiscover_itemsize(PyObject *s, int nd, int *itemsize) \n{\n\tint n, r, i;\n\tPyObject *e;\n\t\n\tn = PyObject_Length(s);\n\n\tif ((nd == 0) || PyString_Check(s) ||\t\t\\\n\t PyUnicode_Check(s) || PyBuffer_Check(s)) {\n\t\tif PyUnicode_Check(s) \n\t\t\t*itemsize = MAX(*itemsize, sizeof(Py_UNICODE)*n);\n\t\telse\n\t\t\t*itemsize = MAX(*itemsize, n);\n\t\treturn 0;\n\t}\n\tfor (i=0; i n_lower) n_lower = d[1];\n }\n d[1] = n_lower;\n\t\n return 0;\n}\n\n/* new reference */\n/* doesn't alter refcount of chktype or mintype --- \n unless one of them is returned */\nstatic PyArray_Descr *\n_array_small_type(PyArray_Descr *chktype, PyArray_Descr* mintype)\n{\n\tPyArray_Descr *outtype;\n\n\tif (chktype->type_num > mintype->type_num) outtype = chktype;\n\telse outtype = mintype;\n\n\tPy_INCREF(outtype);\n\tif (PyTypeNum_ISEXTENDED(outtype->type_num) &&\t\t\\\n\t (PyTypeNum_ISEXTENDED(mintype->type_num) ||\t\t\\\n\t mintype->type_num==0)) {\n\t\tint testsize = outtype->elsize;\n\t\tregister int chksize, minsize;\n\t\tchksize = chktype->elsize;\n\t\tminsize = mintype->elsize;\n\t\t/* Handle string->unicode case separately \n\t\t because string itemsize is twice as large */\n\t\tif (outtype->type_num == PyArray_UNICODE && \n\t\t mintype->type_num == PyArray_STRING) {\n\t\t\ttestsize = MAX(chksize, 2*minsize);\n\t\t}\n\t\telse {\n\t\t\ttestsize = MAX(chksize, minsize);\n\t\t}\n\t\tif (testsize != outtype->elsize) {\n\t\t\tPyArray_DESCR_REPLACE(outtype);\n\t\t\touttype->elsize = testsize;\n\t\t\tPy_XDECREF(outtype->fields);\n\t\t\touttype->fields = NULL;\n\t\t}\n\t}\n\treturn outtype;\n}\n\n/* op is an object to be converted to an ndarray. \n\n minitype is the minimum type-descriptor needed. \n \n max is the maximum number of dimensions -- used for recursive call\n to avoid infinite recursion...\n \n*/\n\nstatic PyArray_Descr *\n_array_find_type(PyObject *op, PyArray_Descr *minitype, int max)\n{\n int l;\n PyObject *ip;\n\tPyArray_Descr *chktype=NULL;\n\tPyArray_Descr *outtype;\n\t\n\tif (minitype == NULL) \n\t\tminitype = PyArray_DescrFromType(PyArray_BOOL);\n\telse Py_INCREF(minitype);\n\t\n if (max < 0) goto deflt;\n\t\n if (PyArray_Check(op)) {\n\t\tchktype = PyArray_DESCR(op);\n\t\tPy_INCREF(chktype);\n\t\tgoto finish;\n\t}\n\t\n\tif (PyArray_IsScalar(op, Generic)) {\n\t\tchktype = PyArray_DescrFromScalar(op);\n\t\tgoto finish;\n\t}\n\n\tif ((ip=PyObject_GetAttrString(op, \"__array_typestr__\"))!=NULL) {\n\t\tif (PyString_Check(ip)) {\n\t\t\tchktype =_array_typedescr_fromstr(PyString_AS_STRING(ip));\n\t\t}\n\t\tPy_DECREF(ip);\n if (chktype) goto finish;\n\t}\n\telse PyErr_Clear();\n \n if ((ip=PyObject_GetAttrString(op, \"__array_struct__\")) != NULL) {\n PyArrayInterface *inter;\n char buf[40];\n if (PyCObject_Check(ip)) {\n inter=(PyArrayInterface *)PyCObject_AsVoidPtr(ip);\n if (inter->version == 2) {\n snprintf(buf, 40, \"|%c%d\", inter->typekind, \n\t\t\t\t\t inter->itemsize);\n\t\t\t\tchktype = _array_typedescr_fromstr(buf);\n }\n }\n Py_DECREF(ip);\n if (chktype) goto finish;\n }\n\telse PyErr_Clear();\n \t\n if (PyString_Check(op)) {\n\t\tchktype = PyArray_DescrNewFromType(PyArray_STRING);\n\t\tchktype->elsize = PyString_GET_SIZE(op);\n\t\tgoto finish;\n }\n\n\tif (PyUnicode_Check(op)) {\n\t\tchktype = PyArray_DescrNewFromType(PyArray_UNICODE);\n\t\tchktype->elsize = PyUnicode_GET_DATA_SIZE(op);\n\t\tgoto finish;\n\t}\n\n\tif (PyBuffer_Check(op)) {\n\t\tchktype = PyArray_DescrNewFromType(PyArray_VOID);\n\t\tchktype->elsize = op->ob_type->tp_as_sequence->sq_length(op);\n PyErr_Clear();\n\t\tgoto finish;\n\t}\n\n if (PyObject_HasAttrString(op, \"__array__\")) {\n ip = PyObject_CallMethod(op, \"__array__\", NULL);\n if(ip && PyArray_Check(ip)) {\n\t\t\tchktype = PyArray_DESCR(ip);\n\t\t\tPy_INCREF(chktype);\n Py_DECREF(ip);\n\t\t\tgoto finish;\n\t\t}\n Py_XDECREF(ip);\n\t\tif (PyErr_Occurred()) PyErr_Clear();\n } \n\n\tif (PyInstance_Check(op)) goto deflt;\n\t\n if (PySequence_Check(op)) {\n\n l = PyObject_Length(op);\n if (l < 0 && PyErr_Occurred()) { \n\t\t\tPyErr_Clear(); \n\t\t\tgoto deflt;\n\t\t}\n if (l == 0 && minitype->type_num == PyArray_BOOL) {\n\t\t\tPy_DECREF(minitype);\n\t\t\tminitype = PyArray_DescrFromType(PyArray_INTP);\n\t\t}\n while (--l >= 0) {\n\t\t\tPyArray_Descr *newtype;\n ip = PySequence_GetItem(op, l);\n if (ip==NULL) {\n\t\t\t\tPyErr_Clear(); \n\t\t\t\tgoto deflt;\n\t\t\t}\n\t\t\tchktype = _array_find_type(ip, minitype, max-1);\n\t\t\tnewtype = _array_small_type(chktype, minitype);\n\t\t\tPy_DECREF(minitype);\n\t\t\tminitype = newtype;\n\t\t\tPy_DECREF(chktype);\n Py_DECREF(ip);\n }\n\t\tchktype = minitype;\n\t\tPy_INCREF(minitype);\n\t\tgoto finish;\n }\n\t\n\tif (PyBool_Check(op)) {\n\t\tchktype = PyArray_DescrFromType(PyArray_BOOL);\n\t\tgoto finish;\t\t\n\t}\n else if (PyInt_Check(op)) {\n\t\tchktype = PyArray_DescrFromType(PyArray_LONG);\n\t\tgoto finish;\n\t} else if (PyLong_Check(op)) {\n\t\t/* if integer can fit into a longlong then return that\n\t\t*/\n\t\tif ((PyLong_AsLongLong(op) == -1) && PyErr_Occurred()) {\n\t\t\tPyErr_Clear();\n\t\t\tgoto deflt;\n\t\t}\n\t\tchktype = PyArray_DescrFromType(PyArray_LONGLONG);\n\t\tgoto finish;\n } else if (PyFloat_Check(op)) {\n\t\tchktype = PyArray_DescrFromType(PyArray_DOUBLE);\n\t\tgoto finish;\n\t} else if (PyComplex_Check(op)) {\n\t\tchktype = PyArray_DescrFromType(PyArray_CDOUBLE);\n\t\tgoto finish;\n\t}\n\n deflt:\n\tchktype = PyArray_DescrFromType(PyArray_OBJECT);\n\t\n finish:\n\t\n\touttype = _array_small_type(chktype, minitype);\n\tPy_DECREF(chktype);\n\tPy_DECREF(minitype);\n\treturn outtype; \n}\n\nstatic int \nAssign_Array(PyArrayObject *self, PyObject *v) \n{\n PyObject *e;\n int l, r;\n\t\n if (!PySequence_Check(v)) {\n PyErr_SetString(PyExc_ValueError,\n\t\t\t\t\"assignment from non-sequence\");\n return -1;\n }\n\t\n l=PyObject_Length(v);\n if(l < 0) return -1; \n\t\n while(--l >= 0)\n {\n e=PySequence_GetItem(v,l);\n if (e == NULL) return -1; \n\t\t\tr = PySequence_SetItem((PyObject*)self,l,e);\n Py_DECREF(e);\n if(r == -1) return -1;\n }\n return 0;\n}\n\n/* \"Array Scalars don't call this code\" */ \n/* steals reference to typecode -- no NULL*/\nstatic PyObject *\nArray_FromScalar(PyObject *op, PyArray_Descr *typecode) \n{\n PyArrayObject *ret;\n\tint itemsize; \n\tint type;\n\t\n\titemsize = typecode->elsize;\n\ttype = typecode->type_num;\n\n\tif (itemsize == 0 && PyTypeNum_ISEXTENDED(type)) {\n\t\titemsize = PyObject_Length(op);\n\t\tif (type == PyArray_UNICODE) itemsize *= sizeof(Py_UNICODE);\n\t}\n\n\tret = (PyArrayObject *)PyArray_NewFromDescr(&PyArray_Type, typecode,\n\t\t\t\t\t\t 0, NULL, \n\t\t\t\t\t\t NULL, NULL, 0, NULL);\n\n\tif (ret == NULL) return NULL;\n\tif (ret->nd > 0) {\n\t\tPyErr_SetString(PyExc_ValueError,\n\t\t\t\t\"shape-mismatch on array construction\");\n\t\tPy_DECREF(ret);\n\t\treturn NULL;\n\t}\n\n ret->descr->f->setitem(op, ret->data, ret);\n\t\n if (PyErr_Occurred()) {\n Py_DECREF(ret);\n return NULL;\n } else {\n return (PyObject *)ret;\n }\n}\n\n\n/* steals reference to typecode */\nstatic PyObject *\nArray_FromSequence(PyObject *s, PyArray_Descr *typecode, int fortran, \n\t\t int min_depth, int max_depth)\n{\n PyArrayObject *r;\n int nd;\n\tintp d[MAX_DIMS];\n\tint stop_at_string;\n\tint stop_at_tuple;\n\tint type = typecode->type_num;\n\tint itemsize = typecode->elsize;\n\t\n\tstop_at_string = ((type == PyArray_OBJECT) ||\t\\\n\t\t\t (type == PyArray_STRING) ||\t\\\n\t\t\t (type == PyArray_UNICODE) || \\\n\t\t\t (type == PyArray_VOID));\n\n\tstop_at_tuple = (type == PyArray_VOID && ((typecode->fields &&\t\\\n\t\t\t\t\t\t typecode->fields!=Py_None) \\\n\t\t\t\t\t\t || (typecode->subarray)));\n\t\n if (!((nd=discover_depth(s, MAX_DIMS+1, stop_at_string, \n\t\t\t\t stop_at_tuple)) > 0)) {\n\t\tif (nd==0)\n\t\t\treturn Array_FromScalar(s, typecode);\n PyErr_SetString(PyExc_ValueError, \n\t\t\t\t\"invalid input sequence\");\n\t\tgoto fail;\n }\n\t\n if ((max_depth && nd > max_depth) ||\t\\\n\t (min_depth && nd < min_depth)) {\n PyErr_SetString(PyExc_ValueError, \n\t\t\t\t\"invalid number of dimensions\");\n\t\tgoto fail;\n }\n\t\n\tif(discover_dimensions(s,nd,d, !stop_at_string) == -1) goto fail;\n\n\tif (itemsize == 0 && PyTypeNum_ISEXTENDED(type)) {\n\t\tif (discover_itemsize(s, nd, &itemsize) == -1) goto fail;\n\t\tif (type == PyArray_UNICODE) itemsize*=sizeof(Py_UNICODE);\n\t}\n\n\tif (itemsize != typecode->elsize) {\n\t\tPyArray_DESCR_REPLACE(typecode);\n\t\ttypecode->elsize = itemsize;\n\t}\n\t\n r=(PyArrayObject*)PyArray_NewFromDescr(&PyArray_Type, typecode,\n\t\t\t\t\t nd, d, \n\t\t\t\t\t NULL, NULL,\n\t\t\t\t\t fortran, NULL);\n\t\n if(!r) return NULL;\n if(Assign_Array(r,s) == -1) {\n\t\tPy_DECREF(r);\n\t\treturn NULL;\n\t}\n return (PyObject*)r;\n\n fail:\n\tPy_DECREF(typecode);\n\treturn NULL;\n}\n\n\n/*OBJECT_API\n Is the typenum valid?\n*/\nstatic int \nPyArray_ValidType(int type) \n{\n\tPyArray_Descr *descr;\n\tint res=TRUE;\n\t\n\tdescr = PyArray_DescrFromType(type);\n\tif (descr==NULL) res = FALSE;\n\tPy_DECREF(descr);\n\treturn res;\n}\n\n\n/* If the output is not a CARRAY, then it is buffered also */\n\nstatic int\n_bufferedcast(PyArrayObject *out, PyArrayObject *in)\n{\n\tchar *inbuffer, *bptr, *optr;\n\tchar *outbuffer=NULL;\n\tPyArrayIterObject *it_in=NULL, *it_out=NULL;\n\tregister intp i, index;\n\tintp ncopies = PyArray_SIZE(out) / PyArray_SIZE(in);\n\tint elsize=in->descr->elsize;\n\tint nels = PyArray_BUFSIZE;\n\tint el;\n\tint inswap, outswap=0;\n\tint obuf=!PyArray_ISCARRAY(out);\n\tint oelsize = out->descr->elsize;\n\tPyArray_VectorUnaryFunc *castfunc;\n PyArray_CopySwapFunc *in_csn;\n PyArray_CopySwapFunc *out_csn;\n\tint retval = -1;\n\n\tcastfunc = in->descr->f->cast[out->descr->type_num];\n in_csn = in->descr->f->copyswap;\n out_csn = out->descr->f->copyswap;\n\n\t/* If the input or output is STRING, UNICODE, or VOID */\n\t/* then getitem and setitem are used for the cast */\n\t/* and byteswapping is handled by those methods */\n\n\tinswap = !(PyArray_ISFLEXIBLE(in) || PyArray_ISNOTSWAPPED(in));\n\t\n\tinbuffer = PyDataMem_NEW(PyArray_BUFSIZE*elsize);\n\tif (inbuffer == NULL) return -1;\n\tif (PyArray_ISOBJECT(in)) \n\t\tmemset(inbuffer, 0, PyArray_BUFSIZE*elsize);\n\tit_in = (PyArrayIterObject *)PyArray_IterNew((PyObject *)in);\n\tif (it_in == NULL) goto exit;\n\n\tif (obuf) {\n\t\toutswap = !(PyArray_ISFLEXIBLE(out) || \\\n\t\t\t PyArray_ISNOTSWAPPED(out));\n\t\toutbuffer = PyDataMem_NEW(PyArray_BUFSIZE*oelsize);\n\t\tif (outbuffer == NULL) goto exit;\n\t\tif (PyArray_ISOBJECT(out))\n\t\t\tmemset(outbuffer, 0, PyArray_BUFSIZE*oelsize);\n\t\t\n\t\tit_out = (PyArrayIterObject *)PyArray_IterNew((PyObject *)out);\n\t\tif (it_out == NULL) goto exit;\n\n\t\tnels = MIN(nels, PyArray_BUFSIZE);\n\t}\n\t\n\toptr = (obuf) ? outbuffer: out->data;\n\tbptr = inbuffer;\n\tel = 0;\t\n\twhile(ncopies--) {\n\t\tindex = it_in->size;\n\t\tPyArray_ITER_RESET(it_in);\n\t\twhile(index--) {\n in_csn(bptr, it_in->dataptr, inswap, elsize);\n\t\t\tbptr += elsize;\n\t\t\tPyArray_ITER_NEXT(it_in);\n\t\t\tel += 1;\n\t\t\tif ((el == nels) || (index == 0)) {\n\t\t\t\t/* buffer filled, do cast */\n\t\t\t\t\n\t\t\t\tcastfunc(inbuffer, optr, el, in, out);\n\t\t\t\t\n\t\t\t\tif (obuf) {\n\t\t\t\t\t/* Copy from outbuffer to array */\n\t\t\t\t\tfor(i=0; idataptr,\n optr, outswap,\n oelsize);\n\t\t\t\t\t\toptr += oelsize;\n\t\t\t\t\t\tPyArray_ITER_NEXT(it_out);\n\t\t\t\t\t}\n\t\t\t\t\toptr = outbuffer;\n\t\t\t\t}\n\t\t\t\telse {\n\t\t\t\t\toptr += out->descr->elsize * nels;\n\t\t\t\t}\n\t\t\t\tel = 0;\n\t\t\t\tbptr = inbuffer;\n\t\t\t}\n\t\t}\n\t}\n\tretval = 0;\n exit:\n\tPy_XDECREF(it_in);\n\tPyDataMem_FREE(inbuffer);\n\tPyDataMem_FREE(outbuffer);\t\n\tif (obuf) {\n\t\tPy_XDECREF(it_out);\n\t}\n\treturn retval;\n}\n\n\n/* For backward compatibility */\n\n/* steals reference to at --- cannot be NULL*/\n/*OBJECT_API\n Cast an array using typecode structure.\n*/\nstatic PyObject * \nPyArray_CastToType(PyArrayObject *mp, PyArray_Descr *at, int fortran)\n{\n\tPyObject *out;\n\tint ret;\n\tPyArray_Descr *mpd;\n\n\tmpd = mp->descr;\n\n\tif (((mpd == at) || ((mpd->type_num == at->type_num) &&\t\t\\\n\t\t\t PyArray_EquivByteorders(mpd->byteorder,\\\n\t\t\t\t\t\t at->byteorder) &&\t\\\n\t\t\t ((mpd->elsize == at->elsize) ||\t\t\\\n\t\t\t (at->elsize==0)))) &&\t\t\t\\\n\t PyArray_ISBEHAVED_RO(mp)) {\n\t\tPy_DECREF(at);\n\t\tPy_INCREF(mp);\n\t\treturn (PyObject *)mp;\n\t}\n\t\t\n\tif (at->elsize == 0) {\n\t\tPyArray_DESCR_REPLACE(at);\n\t\tif (at == NULL) return NULL;\n\t\tif (mpd->type_num == PyArray_STRING &&\t\\\n\t\t at->type_num == PyArray_UNICODE)\n\t\t\tat->elsize = mpd->elsize*sizeof(Py_UNICODE);\n\t\tif (mpd->type_num == PyArray_UNICODE &&\n\t\t at->type_num == PyArray_STRING) \n\t\t\tat->elsize = mpd->elsize/sizeof(Py_UNICODE);\n\t\tif (at->type_num == PyArray_VOID)\n\t\t\tat->elsize = mpd->elsize;\n\t}\n\n\tout = PyArray_NewFromDescr(mp->ob_type, at,\n\t\t\t\t mp->nd, \n\t\t\t\t mp->dimensions, \n\t\t\t\t NULL, NULL, \n\t\t\t\t fortran,\n\t\t\t\t (PyObject *)mp);\n\n\tif (out == NULL) return NULL;\n\tret = PyArray_CastTo((PyArrayObject *)out, mp);\n\tif (ret != -1) return out;\n\t\n\tPy_DECREF(out);\n\treturn NULL;\n\t\n}\n\t \n/* The number of elements in out must be an integer multiple\n of the number of elements in mp. \n*/\n\n/*OBJECT_API\n Cast to an already created array.\n*/\nstatic int\nPyArray_CastTo(PyArrayObject *out, PyArrayObject *mp)\n{\n\n\tint simple;\n\tintp mpsize = PyArray_SIZE(mp);\n\tintp outsize = PyArray_SIZE(out);\n\n\tif (mpsize == 0) return 0;\n\tif (!PyArray_ISWRITEABLE(out)) {\n\t\tPyErr_SetString(PyExc_ValueError, \n\t\t\t\t\"output array is not writeable\");\n\t\treturn -1;\n\t}\n\tif (outsize % mpsize != 0) {\n\t\tPyErr_SetString(PyExc_ValueError, \n\t\t\t\t\"output array must have an integer-multiple\"\\\n\t\t\t\t\" of the number of elements in the input \"\\\n\t\t\t\t\"array\");\n\t\treturn -1; \n\t}\n\n\tif (out->descr->type_num >= PyArray_NTYPES) {\n\t\tPyErr_SetString(PyExc_ValueError, \n\t\t\t\t\"Can only cast to builtin types.\");\n\t\treturn -1;\n\t\t\t\t\n\t}\n\n\tsimple = ((PyArray_ISCARRAY_RO(mp) && PyArray_ISCARRAY(out)) || \\\n (PyArray_ISFARRAY_RO(mp) && PyArray_ISFARRAY(out)));\n\t\n\tif (simple) {\n\t\tchar *inptr;\n\t\tchar *optr = out->data;\n\t\tintp obytes = out->descr->elsize * outsize;\n\t\tintp ncopies = outsize / mpsize;\n\n\t\twhile(ncopies--) {\n\t\t\tinptr = mp->data;\n\t\t\tmp->descr->f->cast[out->descr->type_num](inptr, \n\t\t\t\t\t\t\t optr,\n\t\t\t\t\t\t\t mpsize,\n\t\t\t\t\t\t\t mp, out);\n\t\t\toptr += obytes;\n\t\t}\n\t\treturn 0;\n\t}\n\t\n\t/* If not a well-behaved cast, then use buffers */\n\tif (_bufferedcast(out, mp) == -1) {\n\t\treturn -1;\n\t}\n\treturn 0;\n}\n\n/* steals reference to newtype --- acc. NULL */\n/*OBJECT_API*/\nstatic PyObject *\nPyArray_FromArray(PyArrayObject *arr, PyArray_Descr *newtype, int flags) \n{\n\t\n\tPyArrayObject *ret=NULL;\n\tint type, itemsize;\n\tint copy = 0;\n\tint arrflags;\n\tPyArray_Descr *oldtype;\n\tchar *msg = \"cannot copy back to a read-only array\";\n PyTypeObject *subtype;\n\n\toldtype = PyArray_DESCR(arr);\n\n subtype = arr->ob_type;\n\t\n\tif (newtype == NULL) {newtype = oldtype; Py_INCREF(oldtype);}\n\ttype = newtype->type_num;\n\titemsize = newtype->elsize;\n\n\t/* Don't copy if sizes are compatible */\n\tif (PyArray_EquivTypes(oldtype, newtype)) {\n\t\tarrflags = arr->flags;\n\n\t\tcopy = (flags & ENSURECOPY) || \\\n\t\t\t((flags & CONTIGUOUS) && (!(arrflags & CONTIGUOUS))) \\\n\t\t\t|| ((flags & ALIGNED) && (!(arrflags & ALIGNED))) \\\n\t\t\t|| (arr->nd > 1 &&\t\t\t\t\\\n\t\t\t ((flags & FORTRAN) && (!(arrflags & FORTRAN)))) \\\n\t\t\t|| ((flags & WRITEABLE) && (!(arrflags & WRITEABLE)));\n\t\t\n\t\tif (copy) {\n if ((flags & UPDATEIFCOPY) && \\\n (!PyArray_ISWRITEABLE(arr))) {\n\t\t\t\tPy_DECREF(newtype);\n PyErr_SetString(PyExc_ValueError, msg);\n return NULL;\n }\n if ((flags & ENSUREARRAY) && \\\n (subtype != &PyBigArray_Type)) {\n subtype = &PyArray_Type;\n }\n\t\t\tret = (PyArrayObject *) \\\n\t\t\t\tPyArray_NewFromDescr(subtype, newtype,\n\t\t\t\t\t\t arr->nd, \n\t\t\t\t\t\t arr->dimensions,\n\t\t\t\t\t\t NULL, NULL, \n\t\t\t\t\t\t flags & FORTRAN,\n\t\t\t\t\t\t (PyObject *)arr);\n if (ret == NULL) return NULL;\n\t\t\tif (PyArray_CopyInto(ret, arr) == -1) \n\t\t\t\t{Py_DECREF(ret); return NULL;}\n\t\t\tif (flags & UPDATEIFCOPY) {\n\t\t\t\tret->flags |= UPDATEIFCOPY;\n\t\t\t\tret->base = (PyObject *)arr;\n PyArray_FLAGS(ret->base) &= ~WRITEABLE;\n\t\t\t\tPy_INCREF(arr);\n\t\t\t}\n\t\t} \n\t\t/* If no copy then just increase the reference\n\t\t count and return the input */\n\t\telse { \n if ((flags & ENSUREARRAY) && \\\n (subtype != &PyBigArray_Type)) {\n\t\t\t\tPy_DECREF(newtype);\n\t\t\t\tPy_INCREF(arr->descr);\n\t\t\t\tret = (PyArrayObject *)\t\t\t\\\n PyArray_NewFromDescr(&PyArray_Type,\n\t\t\t\t\t\t\t arr->descr,\n\t\t\t\t\t\t\t arr->nd,\n\t\t\t\t\t\t\t arr->dimensions,\n\t\t\t\t\t\t\t arr->strides,\n\t\t\t\t\t\t\t arr->data,\n\t\t\t\t\t\t\t arr->flags,NULL);\n if (ret == NULL) return NULL;\n ret->base = (PyObject *)arr;\n }\n else {\n ret = arr;\n }\n\t\t\tPy_INCREF(arr);\n\t\t}\n\t}\n\t\n\t/* The desired output type is different than the input\n\t array type */\n\telse {\n\t\t/* Cast to the desired type if we can do it safely\n\t\t Also cast if source is a ndim-0 array to mimic\n\t\t behavior with Python scalars */\n\t\tif (flags & FORCECAST || PyArray_NDIM(arr)==0 ||\n\t\t PyArray_CanCastTo(oldtype, newtype)) {\n if ((flags & UPDATEIFCOPY) &&\t\t\\\n (!PyArray_ISWRITEABLE(arr))) {\n\t\t\t\tPy_DECREF(newtype);\n PyErr_SetString(PyExc_ValueError, msg);\n return NULL;\n }\n if ((flags & ENSUREARRAY) && \\\n (subtype != &PyBigArray_Type)) {\n subtype = &PyArray_Type;\n }\n ret = (PyArrayObject *)\\\n PyArray_NewFromDescr(subtype, \n\t\t\t\t\t\t newtype, \n\t\t\t\t\t\t arr->nd,\n\t\t\t\t\t\t arr->dimensions, \n\t\t\t\t\t\t NULL, NULL, \n\t\t\t\t\t\t flags & FORTRAN,\n\t\t\t\t\t\t (PyObject *)arr);\n if (ret == NULL) return NULL;\n if (PyArray_CastTo(ret, arr) < 0) {\n Py_DECREF(ret);\n return NULL;\n }\n\t\t\tif (flags & UPDATEIFCOPY) {\n\t\t\t\tret->flags |= UPDATEIFCOPY;\n\t\t\t\tret->base = (PyObject *)arr;\n PyArray_FLAGS(ret->base) &= ~WRITEABLE;\n\t\t\t\tPy_INCREF(arr);\n\t\t\t}\n\t\t}\n\t\telse {\n\t\t\tPyErr_SetString(PyExc_TypeError, \n\t\t\t\t\t\"array cannot be safely cast \" \\\n\t\t\t\t\t\"to required type\");\n\t\t\tret = NULL;\n\t\t}\n\t}\n\treturn (PyObject *)ret;\n}\n\n/* new reference */\nstatic PyArray_Descr *\n_array_typedescr_fromstr(char *str)\n{\n\tPyArray_Descr *descr; \n\tint type_num;\n\tchar typechar;\n\tint size;\n\tchar msg[] = \"unsupported typestring\";\n\tint swap;\n\tchar swapchar;\n\n\tswapchar = str[0];\n\tstr += 1;\n\t\n#define _MY_FAIL {\t\t\t\t \\\n\t\tPyErr_SetString(PyExc_ValueError, msg); \\\n\t\treturn NULL;\t\t\t\t\\\n\t}\t\t\n\t\n\ttypechar = str[0];\n\tsize = atoi(str + 1);\n\tswitch (typechar) {\n\tcase 'b':\n\t\tif (size == sizeof(Bool))\n\t\t\ttype_num = PyArray_BOOL;\t \n\t\telse _MY_FAIL \n\t\t\tbreak;\t\t \n\tcase 'u':\n\t\tif (size == sizeof(uintp))\n\t\t\ttype_num = PyArray_UINTP;\n\t\telse if (size == sizeof(char))\n\t\t\ttype_num = PyArray_UBYTE;\n\t\telse if (size == sizeof(short)) \n\t\t\ttype_num = PyArray_USHORT;\n\t\telse if (size == sizeof(ulong)) \n\t\t\ttype_num = PyArray_ULONG;\n\t\telse if (size == sizeof(int)) \n\t\t\ttype_num = PyArray_UINT;\n\t\telse if (size == sizeof(ulonglong))\n\t\t\ttype_num = PyArray_ULONGLONG;\n\t\telse _MY_FAIL\n\t\t\tbreak;\t\t \n\tcase 'i':\n\t\tif (size == sizeof(intp))\n\t\t\ttype_num = PyArray_INTP;\n\t\telse if (size == sizeof(char)) \n\t\t type_num = PyArray_BYTE;\n\t\telse if (size == sizeof(short)) \n\t\t\ttype_num = PyArray_SHORT;\n\t\telse if (size == sizeof(long)) \n\t\t\ttype_num = PyArray_LONG;\n\t\telse if (size == sizeof(int))\n\t\t\ttype_num = PyArray_INT;\n\t\telse if (size == sizeof(longlong))\n\t\t\ttype_num = PyArray_LONGLONG;\n\t\telse _MY_FAIL\n\t\t\tbreak;\t\t \n\tcase 'f':\n\t\tif (size == sizeof(float))\n\t\t\ttype_num = PyArray_FLOAT;\n\t\telse if (size == sizeof(double))\n\t\t\ttype_num = PyArray_DOUBLE;\n\t\telse if (size == sizeof(longdouble))\n\t\t\ttype_num = PyArray_LONGDOUBLE;\n\t\telse _MY_FAIL\n\t\t\tbreak;\n\tcase 'c':\n\t\tif (size == sizeof(float)*2)\n\t\t\ttype_num = PyArray_CFLOAT;\n\t\telse if (size == sizeof(double)*2)\n\t\t\ttype_num = PyArray_CDOUBLE;\n\t\telse if (size == sizeof(longdouble)*2)\n\t\t\ttype_num = PyArray_CLONGDOUBLE;\n\t\telse _MY_FAIL\n\t\t\tbreak;\n\tcase 'O':\n\t\tif (size == sizeof(PyObject *))\n\t\t\ttype_num = PyArray_OBJECT;\n\t\telse _MY_FAIL\n\t\t\tbreak;\n\tcase 'S':\n\t\ttype_num = PyArray_STRING;\n\t\tbreak;\n\tcase 'U':\n\t\ttype_num = PyArray_UNICODE;\n\t\tsize *= sizeof(Py_UNICODE);\n\t\tbreak;\t \n\tcase 'V':\n\t\ttype_num = PyArray_VOID;\n\t\tbreak;\n\tdefault:\n\t\t_MY_FAIL\n\t}\n\t\n#undef _MY_FAIL\n\n descr = PyArray_DescrFromType(type_num);\n if (descr == NULL) return NULL;\n swap = !PyArray_ISNBO(swapchar);\n if (descr->elsize == 0 || swap) {\n\t /* Need to make a new PyArray_Descr */\n\t PyArray_DESCR_REPLACE(descr);\n\t if (descr==NULL) return NULL;\n\t if (descr->elsize == 0)\n\t\t descr->elsize = size;\n\t if (swap) \n\t\t descr->byteorder = swapchar;\n }\n return descr;\n}\n\n/* OBJECT_API */\nstatic PyObject *\nPyArray_FromStructInterface(PyObject *input)\n{\n\tPyArray_Descr *thetype;\n\tchar buf[40];\n\tPyArrayInterface *inter;\n\tPyObject *attr, *r;\n\tchar endian = PyArray_NATBYTE;\n \n attr = PyObject_GetAttrString(input, \"__array_struct__\");\n if (attr == NULL) {\n\t\tPyErr_Clear();\n\t\treturn Py_NotImplemented;\n\t}\n if (!PyCObject_Check(attr) || \\\n ((inter=((PyArrayInterface *)\\\n\t\t PyCObject_AsVoidPtr(attr)))->version != 2)) {\n PyErr_SetString(PyExc_ValueError, \"invalid __array_struct__\");\n\t\tPy_DECREF(attr);\n return NULL;\n }\n\tif ((inter->flags & NOTSWAPPED) != NOTSWAPPED) {\n\t\tendian = PyArray_OPPBYTE;\n\t\tinter->flags &= ~NOTSWAPPED;\n\t}\n\n snprintf(buf, 40, \"%c%c%d\", endian, inter->typekind, inter->itemsize);\n if (!(thetype=_array_typedescr_fromstr(buf))) {\n\t\tPy_DECREF(attr);\n return NULL;\n }\n\n r = PyArray_NewFromDescr(&PyArray_Type, thetype,\n\t\t\t\t inter->nd, inter->shape,\n\t\t\t\t inter->strides, inter->data,\n\t\t\t\t inter->flags, NULL);\n\tPy_INCREF(input);\n\tPyArray_BASE(r) = input;\n Py_DECREF(attr);\n PyArray_UpdateFlags((PyArrayObject *)r, UPDATE_ALL_FLAGS);\n return r;\n}\n\n/*OBJECT_API*/\nstatic PyObject *\nPyArray_FromInterface(PyObject *input)\n{\n\tPyObject *attr=NULL, *item=NULL;\n PyObject *tstr=NULL, *shape=NULL; \n PyArrayObject *ret;\n\tPyArray_Descr *type=NULL;\n\tchar *data;\n\tint buffer_len;\n\tint res, i, n;\n\tintp dims[MAX_DIMS], strides[MAX_DIMS];\n\tint dataflags = BEHAVED_FLAGS;\n\n\t/* Get the memory from __array_data__ and __array_offset__ */\n\t/* Get the shape */\n\t/* Get the typestring -- ignore array_descr */\n\t/* Get the strides */\n\t\n shape = PyObject_GetAttrString(input, \"__array_shape__\");\n if (shape == NULL) {PyErr_Clear(); return Py_NotImplemented;}\n tstr = PyObject_GetAttrString(input, \"__array_typestr__\");\n if (tstr == NULL) {Py_DECREF(shape); PyErr_Clear(); return Py_NotImplemented;}\n \n\tattr = PyObject_GetAttrString(input, \"__array_data__\");\n\tif ((attr == NULL) || (attr==Py_None) || (!PyTuple_Check(attr))) {\n\t\tif (attr && (attr != Py_None)) item=attr;\n\t\telse item=input;\n\t\tres = PyObject_AsWriteBuffer(item, (void **)&data, \n\t\t\t\t\t &buffer_len);\n\t\tif (res < 0) {\n\t\t\tPyErr_Clear();\n\t\t\tres = PyObject_AsReadBuffer(item, (const void **)&data,\n\t\t\t\t\t\t &buffer_len);\n\t\t\tif (res < 0) goto fail;\n\t\t\tdataflags &= ~WRITEABLE;\n\t\t}\n\t\tPy_XDECREF(attr);\n\t\tattr = PyObject_GetAttrString(input, \"__array_offset__\");\n\t\tif (attr) {\n\t\t\tlong num = PyInt_AsLong(attr);\n\t\t\tif (error_converting(num)) {\n\t\t\t\tPyErr_SetString(PyExc_TypeError, \n\t\t\t\t\t\t\"__array_offset__ \"\\\n\t\t\t\t\t\t\"must be an integer\");\n\t\t\t\tgoto fail;\n\t\t\t}\n\t\t\tdata += num;\n\t\t}\n\t\telse PyErr_Clear();\n\t}\n\telse {\n\t\tif (PyTuple_GET_SIZE(attr) != 2) {\n\t\t\tPyErr_SetString(PyExc_TypeError, \n\t\t\t\t\t\"__array_data__ must return \"\t\\\n\t\t\t\t\t\"a 2-tuple with ('data pointer \"\\\n\t\t\t\t\t\"string', read-only flag)\");\n\t\t\tgoto fail;\n\t\t}\n\t\tres = sscanf(PyString_AsString(PyTuple_GET_ITEM(attr,0)),\n\t\t\t \"%p\", (void **)&data);\n\t\tif (res < 1) {\n\t\t\tPyErr_SetString(PyExc_TypeError, \n\t\t\t\t\t\"__array_data__ string cannot be \" \\\n\t\t\t\t\t\"converted\");\n\t\t\tgoto fail;\n\t\t}\n\t\tif (PyObject_IsTrue(PyTuple_GET_ITEM(attr,1))) {\n\t\t\tdataflags &= ~WRITEABLE;\n\t\t}\n\t}\n\tPy_XDECREF(attr);\n\tattr = tstr;\n\tif (!PyString_Check(attr)) {\n\t\tPyErr_SetString(PyExc_TypeError, \"__array_typestr__ must be a string\");\n\t\tPy_INCREF(attr); /* decref'd twice below */\n\t\tgoto fail;\n\t}\n\ttype = _array_typedescr_fromstr(PyString_AS_STRING(attr)); \n\tPy_DECREF(attr); attr=NULL; tstr=NULL;\n\tif (type==NULL) goto fail;\n\tattr = shape;\n\tif (!PyTuple_Check(attr)) {\n\t\tPyErr_SetString(PyExc_TypeError, \"__array_shape__ must be a tuple\");\n\t\tPy_INCREF(attr); /* decref'd twice below */\n\t\tPy_DECREF(type);\n\t\tgoto fail;\n\t}\n\tn = PyTuple_GET_SIZE(attr);\n\tfor (i=0; ibase = input;\n \n\tattr = PyObject_GetAttrString(input, \"__array_strides__\");\n\tif (attr != NULL && attr != Py_None) {\n\t\tif (!PyTuple_Check(attr)) {\n\t\t\tPyErr_SetString(PyExc_TypeError, \n\t\t\t\t\t\"__array_strides__ must be a tuple\");\n\t\t\tPy_DECREF(attr);\n\t\t\tPy_DECREF(ret);\n\t\t\treturn NULL;\n\t\t}\n\t\tif (n != PyTuple_GET_SIZE(attr)) {\n\t\t\tPyErr_SetString(PyExc_ValueError, \n\t\t\t\t\t\"mismatch in length of \"\\\n\t\t\t\t\t\"__array_strides__ and \"\\\n\t\t\t\t\t\"__array_shape__\");\n\t\t\tPy_DECREF(attr);\n\t\t\tPy_DECREF(ret);\n\t\t\treturn NULL;\n\t\t}\n\t\tfor (i=0; istrides, strides, n*sizeof(intp));\n\t}\n\telse PyErr_Clear();\n\tPyArray_UpdateFlags(ret, UPDATE_ALL_FLAGS);\n\treturn (PyObject *)ret;\n\n fail:\n\tPy_XDECREF(attr);\n\tPy_XDECREF(shape);\n\tPy_XDECREF(tstr);\n\treturn NULL;\n}\n\n/* OBJECT_API*/\nstatic PyObject *\nPyArray_FromArrayAttr(PyObject *op, PyArray_Descr *typecode, PyObject *context) \n{\n PyObject *new;\n PyObject *array_meth;\n\n array_meth = PyObject_GetAttrString(op, \"__array__\");\n if (array_meth == NULL) {PyErr_Clear(); return Py_NotImplemented;}\n if (context == NULL) {\n if (typecode == NULL) new = PyObject_CallFunction(array_meth, NULL);\n else new = PyObject_CallFunction(array_meth, \"O\", typecode);\n }\n else {\n if (typecode == NULL) {\n new = PyObject_CallFunction(array_meth, \"OO\", Py_None, context);\n if (new == NULL && PyErr_ExceptionMatches(PyExc_TypeError)) {\n PyErr_Clear();\n new = PyObject_CallFunction(array_meth, \"\");\n }\n }\n else {\n new = PyObject_CallFunction(array_meth, \"OO\", typecode, context);\n if (new == NULL && PyErr_ExceptionMatches(PyExc_TypeError)) {\n PyErr_Clear();\n new = PyObject_CallFunction(array_meth, \"O\", typecode);\n }\n }\n }\n Py_DECREF(array_meth);\n if (new == NULL) return NULL;\n if (!PyArray_Check(new)) {\n PyErr_SetString(PyExc_ValueError, \n \"object __array__ method not \" \\\n \"producing an array\");\n Py_DECREF(new);\n return NULL;\n }\n return new;\n} \n\n/* Does not check for ENSURECOPY and NOTSWAPPED in flags */\n/* Steals a reference to newtype --- which can be NULL */\n/*OBJECT_API*/\nstatic PyObject *\nPyArray_FromAny(PyObject *op, PyArray_Descr *newtype, int min_depth, \n int max_depth, int flags, PyObject *context) \n{\n /* This is the main code to make a NumPy array from a Python\n Object. It is called from lot's of different places which\n is why there are so many checks. The comments try to\n explain some of the checks. */\n\n PyObject *r=NULL;\n int seq = FALSE;\n \n\t/* Is input object already an array? */\n\t/* This is where the flags are used */\n if (PyArray_Check(op)) \n\t\tr = PyArray_FromArray((PyArrayObject *)op, newtype, flags);\n\telse if (PyArray_IsScalar(op, Generic)) {\n\t\tr = PyArray_FromScalar(op, newtype);\n\t}\n else if (((r = PyArray_FromStructInterface(op))!=Py_NotImplemented)|| \\\n ((r = PyArray_FromInterface(op)) != Py_NotImplemented) || \\\n ((r = PyArray_FromArrayAttr(op, newtype, context)) \\\n != Py_NotImplemented)) {\n PyObject *new;\n if (r == NULL) return NULL;\n if (newtype != NULL || flags != 0) {\n new = PyArray_FromArray((PyArrayObject *)r, newtype, flags);\n Py_DECREF(r);\n r = new;\n }\n }\n\telse {\n\t\tif (newtype == NULL) {\n\t\t\tnewtype = _array_find_type(op, NULL, MAX_DIMS);\n\t\t}\n\t\tif (PySequence_Check(op)) {\n\t\t\t/* necessary but not sufficient */\n\n\t\t\tPy_INCREF(newtype);\n\t\t\tr = Array_FromSequence(op, newtype, flags & FORTRAN,\n\t\t\t\t\t min_depth, max_depth);\n\t\t\tif (PyErr_Occurred() && r == NULL) {\n /* It wasn't really a sequence after all.\n * Try interpreting it as a scalar */\n\t\t\t\tPyErr_Clear();\n\t\t\t}\n else {\n\t\t\t\tseq = TRUE;\n\t\t\t\tPy_DECREF(newtype);\n\t\t\t}\n }\n if (!seq)\n\t\t\tr = Array_FromScalar(op, newtype);\n\t}\n\n /* If we didn't succeed return NULL */\n if (r == NULL) return NULL;\n\t\n\t/* Be sure we succeed here */\n\t\n if(!PyArray_Check(r)) {\n PyErr_SetString(PyExc_RuntimeError, \n\t\t\t\t\"internal error: PyArray_FromAny \"\\\n\t\t\t\t\"not producing an array\");\n\t\tPy_DECREF(r);\n return NULL;\n }\n\n if (min_depth != 0 && ((PyArrayObject *)r)->nd < min_depth) {\n PyErr_SetString(PyExc_ValueError, \n \"object of too small depth for desired array\");\n Py_DECREF(r);\n return NULL;\n }\n if (max_depth != 0 && ((PyArrayObject *)r)->nd > max_depth) {\n PyErr_SetString(PyExc_ValueError, \n \"object too deep for desired array\");\n Py_DECREF(r);\n return NULL;\n }\n return r;\n}\n\n/* new reference -- accepts NULL for mintype*/\n/*OBJECT_API*/\nstatic PyArray_Descr *\nPyArray_DescrFromObject(PyObject *op, PyArray_Descr *mintype)\n{\n\treturn _array_find_type(op, mintype, MAX_DIMS);\n}\n\n/*OBJECT_API\n Return the typecode of the array a Python object would be converted\n to\n*/\nstatic int \nPyArray_ObjectType(PyObject *op, int minimum_type) \n{\n\tPyArray_Descr *intype;\n\tPyArray_Descr *outtype;\n\tint ret;\n\n\tintype = PyArray_DescrFromType(minimum_type);\n\tif (intype == NULL) PyErr_Clear();\n\touttype = _array_find_type(op, intype, MAX_DIMS);\n\tret = outtype->type_num;\n\tPy_DECREF(outtype);\n\tPy_DECREF(intype);\n\treturn ret;\n}\n\n\n/* flags is any of \n CONTIGUOUS, \n FORTRAN,\n ALIGNED, \n WRITEABLE, \n NOTSWAPPED,\n ENSURECOPY, \n UPDATEIFCOPY,\n FORCECAST,\n ENSUREARRAY\n\n or'd (|) together\n\n Any of these flags present means that the returned array should \n guarantee that aspect of the array. Otherwise the returned array\n won't guarantee it -- it will depend on the object as to whether or \n not it has such features. \n\n Note that ENSURECOPY is enough\n to guarantee CONTIGUOUS, ALIGNED and WRITEABLE\n and therefore it is redundant to include those as well. \n\n BEHAVED_FLAGS == ALIGNED | WRITEABLE\n CARRAY_FLAGS = CONTIGUOUS | BEHAVED_FLAGS\n FARRAY_FLAGS = FORTRAN | BEHAVED_FLAGS\n \n FORTRAN can be set in the FLAGS to request a FORTRAN array. \n Fortran arrays are always behaved (aligned, \n notswapped, and writeable) and not (C) CONTIGUOUS (if > 1d). \n\n UPDATEIFCOPY flag sets this flag in the returned array if a copy is\n made and the base argument points to the (possibly) misbehaved array.\n When the new array is deallocated, the original array held in base\n is updated with the contents of the new array. \n\n FORCECAST will cause a cast to occur regardless of whether or not\n it is safe. \n*/\n\n\n/* steals a reference to descr -- accepts NULL */\n/*OBJECT_API*/\nstatic PyObject *\nPyArray_CheckFromAny(PyObject *op, PyArray_Descr *descr, int min_depth, \n int max_depth, int requires, PyObject *context) \n{\n\tif (requires & NOTSWAPPED) {\n\t\tif (!descr && PyArray_Check(op) && \\\n\t\t !PyArray_ISNBO(PyArray_DESCR(op)->byteorder)) {\n\t\t\tdescr = PyArray_DescrNew(PyArray_DESCR(op));\n\t\t}\n\t\telse if ((descr && !PyArray_ISNBO(descr->byteorder))) {\n\t\t\tPyArray_DESCR_REPLACE(descr);\n\t\t}\n\t\tdescr->byteorder = PyArray_NATIVE;\n\t}\n\n\treturn PyArray_FromAny(op, descr, min_depth, max_depth,\n requires, context);\n}\n\n/* This is a quick wrapper around PyArray_FromAny(op, NULL, 0, 0, \n ENSUREARRAY) */\n/* that special cases Arrays and PyArray_Scalars up front */\n/* It *steals a reference* to the object */\n/* It also guarantees that the result is PyArray_Type or PyBigArray_Type */\n\n/* Because it decrefs op if any conversion needs to take place \n so it can be used like PyArray_EnsureArray(some_function(...)) */\n\n/*OBJECT_API*/\nstatic PyObject *\nPyArray_EnsureArray(PyObject *op)\n{\n PyObject *new;\n\n if (op == NULL) return NULL;\n\n if (PyArray_CheckExact(op) || PyBigArray_CheckExact(op)) return op;\n \n if (PyArray_IsScalar(op, Generic)) {\n new = PyArray_FromScalar(op, NULL);\n Py_DECREF(op);\n return new;\n }\n new = PyArray_FromAny(op, NULL, 0, 0, ENSUREARRAY, NULL);\n Py_DECREF(op);\n return new;\n}\n\n/*OBJECT_API\n Check the type coercion rules.\n*/\nstatic int \nPyArray_CanCastSafely(int fromtype, int totype) \n{\n\tPyArray_Descr *from, *to;\n\tregister int felsize, telsize;\n\n if (fromtype == totype) return 1;\n if (fromtype == PyArray_BOOL) return 1;\n\tif (totype == PyArray_BOOL) return 0;\n if (totype == PyArray_OBJECT || totype == PyArray_VOID) return 1;\n\tif (fromtype == PyArray_OBJECT || fromtype == PyArray_VOID) return 0;\n\n\tfrom = PyArray_DescrFromType(fromtype);\n\tto = PyArray_DescrFromType(totype);\n\ttelsize = to->elsize;\n\tfelsize = from->elsize;\n\tPy_DECREF(from);\n\tPy_DECREF(to);\n\n switch(fromtype) {\n case PyArray_BYTE:\n\tcase PyArray_SHORT:\n case PyArray_INT:\n case PyArray_LONG:\n\tcase PyArray_LONGLONG:\n\t\tif (PyTypeNum_ISINTEGER(totype)) {\n\t\t\tif (PyTypeNum_ISUNSIGNED(totype)) {\n\t\t\t\treturn (telsize > felsize);\n\t\t\t}\n\t\t\telse {\n\t\t\t\treturn (telsize >= felsize);\n\t\t\t}\n\t\t}\n\t\telse if (PyTypeNum_ISFLOAT(totype)) {\n if (felsize < 8)\n return (telsize > felsize);\n else\n return (telsize >= felsize);\n\t\t}\n\t\telse if (PyTypeNum_ISCOMPLEX(totype)) {\n if (felsize < 8)\n return ((telsize >> 1) > felsize);\n else\n return ((telsize >> 1) >= felsize);\n\t\t}\n\t\telse return totype > fromtype;\n case PyArray_UBYTE:\n case PyArray_USHORT:\n case PyArray_UINT:\n\tcase PyArray_ULONG:\n\tcase PyArray_ULONGLONG:\n\t\tif (PyTypeNum_ISINTEGER(totype)) {\n\t\t\tif (PyTypeNum_ISSIGNED(totype)) {\n\t\t\t\treturn (telsize > felsize);\n\t\t\t}\n\t\t\telse {\n\t\t\t\treturn (telsize >= felsize);\n\t\t\t}\n\t\t}\n\t\telse if (PyTypeNum_ISFLOAT(totype)) {\n if (felsize < 8)\n return (telsize > felsize);\n else\n return (telsize >= felsize);\n\t\t}\n\t\telse if (PyTypeNum_ISCOMPLEX(totype)) {\n if (felsize < 8)\n return ((telsize >> 1) > felsize);\n else\n return ((telsize >> 1) >= felsize);\n\t\t}\n\t\telse return totype > fromtype;\n case PyArray_FLOAT:\n case PyArray_DOUBLE:\n\tcase PyArray_LONGDOUBLE:\n\t\tif (PyTypeNum_ISCOMPLEX(totype)) \n\t\t\treturn ((telsize >> 1) >= felsize);\n\t\telse\n\t\t\treturn (totype > fromtype);\n case PyArray_CFLOAT:\n case PyArray_CDOUBLE:\n\tcase PyArray_CLONGDOUBLE:\n\t\treturn (totype > fromtype);\n\tcase PyArray_STRING:\n\tcase PyArray_UNICODE:\n\t\treturn (totype > fromtype);\n default:\n return 0;\n }\n}\n\n/* leaves reference count alone --- cannot be NULL*/\n/*OBJECT_API*/\nstatic Bool\nPyArray_CanCastTo(PyArray_Descr *from, PyArray_Descr *to)\n{\n\tint fromtype=from->type_num;\n\tint totype=to->type_num;\n\tBool ret;\n\n\tret = (Bool) PyArray_CanCastSafely(fromtype, totype);\n\tif (ret) { /* Check String and Unicode more closely */\n\t\tif (fromtype == PyArray_STRING) {\n\t\t\tif (totype == PyArray_STRING) {\n\t\t\t\tret = (from->elsize <= to->elsize);\n\t\t\t}\n\t\t\telse if (totype == PyArray_UNICODE) {\n\t\t\t\tret = (from->elsize * sizeof(Py_UNICODE)\\\n\t\t\t\t <= to->elsize);\n\t\t\t}\n\t\t}\n\t\telse if (fromtype == PyArray_UNICODE) {\n\t\t\tif (totype == PyArray_UNICODE) {\n\t\t\t\tret = (from->elsize <= to->elsize);\n\t\t\t}\n\t\t}\n\t\t/* TODO: If totype is STRING or unicode \n\t\t see if the length is long enough to hold the\n\t\t stringified value of the object.\t\t \n\t\t*/\n\t}\n\treturn ret;\n}\n\n\n\n/*********************** Element-wise Array Iterator ***********************/\n/* Aided by Peter J. Verveer's nd_image package and numpy's arraymap ****/\n/* and Python's array iterator ***/\n \n\n/*OBJECT_API\n Get Iterator.\n*/\nstatic PyObject *\nPyArray_IterNew(PyObject *obj)\n{\n PyArrayIterObject *it;\n\tint i, nd; \n\tPyArrayObject *ao = (PyArrayObject *)obj;\n\n if (!PyArray_Check(ao)) {\n PyErr_BadInternalCall();\n return NULL;\n }\n\n it = (PyArrayIterObject *)_pya_malloc(sizeof(PyArrayIterObject));\n PyObject_Init((PyObject *)it, &PyArrayIter_Type);\n /* it = PyObject_New(PyArrayIterObject, &PyArrayIter_Type);*/\n if (it == NULL)\n return NULL;\n\n\tnd = ao->nd;\n\tPyArray_UpdateFlags(ao, CONTIGUOUS);\n\tit->contiguous = 0;\n\tif PyArray_ISCONTIGUOUS(ao) it->contiguous = 1;\n Py_INCREF(ao);\n it->ao = ao;\n\tit->size = PyArray_SIZE(ao);\n\tit->nd_m1 = nd - 1;\n\tit->factors[nd-1] = 1;\n\tfor (i=0; i < nd; i++) {\n\t\tit->dims_m1[i] = it->ao->dimensions[i] - 1;\n\t\tit->strides[i] = it->ao->strides[i];\n\t\tit->backstrides[i] = it->strides[i] *\t\\\n\t\t\tit->dims_m1[i];\n\t\tif (i > 0)\n\t\t\tit->factors[nd-i-1] = it->factors[nd-i] *\t\\\n\t\t\t\tit->ao->dimensions[nd-i];\n\t}\n\tPyArray_ITER_RESET(it);\n\t\n return (PyObject *)it;\n}\n\n\n/*OBJECT_API\n Get Iterator that iterates over all but one axis (don't use this with\n PyArray_ITER_GOTO1D) \n*/\nstatic PyObject *\nPyArray_IterAllButAxis(PyObject *obj, int axis)\n{\n\tPyArrayIterObject *it;\n\tit = (PyArrayIterObject *)PyArray_IterNew(obj);\n\tif (it == NULL) return NULL;\n\t\n\t/* adjust so that will not iterate over axis */\n\tit->contiguous = 0;\n\tif (it->size != 0) {\n\t\tit->size /= PyArray_DIM(obj,axis);\n\t}\n\tit->dims_m1[axis] = 0;\n\tit->backstrides[axis] = 0;\n\t\n\t/* (won't fix factors so don't use\n\t PyArray_ITER_GOTO1D with this iterator) */\n\treturn (PyObject *)it;\n}\n\n/* Returns an array scalar holding the element desired */\n\nstatic PyObject *\narrayiter_next(PyArrayIterObject *it)\n{\n\tPyObject *ret;\n\n\tif (it->index < it->size) {\n\t\tret = PyArray_ToScalar(it->dataptr, it->ao);\n\t\tPyArray_ITER_NEXT(it);\n\t\treturn ret;\n\t}\n return NULL;\n}\n\nstatic void\narrayiter_dealloc(PyArrayIterObject *it)\n{\n Py_XDECREF(it->ao);\n _pya_free(it);\n}\n\nstatic int\niter_length(PyArrayIterObject *self) \n{\n return (int) self->size;\n}\n\n\nstatic PyObject *\niter_subscript_Bool(PyArrayIterObject *self, PyArrayObject *ind)\n{\n\tint index, strides, itemsize;\n\tintp count=0;\n\tchar *dptr, *optr;\n\tPyObject *r;\n\tint swap;\n PyArray_CopySwapFunc *copyswap;\n\n\n\tif (ind->nd != 1) {\n\t\tPyErr_SetString(PyExc_ValueError, \n\t\t\t\t\"boolean index array should have 1 dimension\");\n\t\treturn NULL;\n\t}\n\tindex = (ind->dimensions[0]);\n\tstrides = ind->strides[0];\n\tdptr = ind->data;\n\t/* Get size of return array */\n\twhile(index--) {\n\t\tif (*((Bool *)dptr) != 0)\n\t\t\tcount++;\n\t\tdptr += strides;\n\t}\n\titemsize = self->ao->descr->elsize;\n\tPy_INCREF(self->ao->descr);\n\tr = PyArray_NewFromDescr(self->ao->ob_type,\n\t\t\t\t self->ao->descr, 1, &count, \n\t\t\t\t NULL, NULL,\n\t\t\t\t 0, (PyObject *)self->ao);\n\tif (r==NULL) return NULL;\n\n\t/* Set up loop */\n\toptr = PyArray_DATA(r);\n\tindex = ind->dimensions[0];\n\tdptr = ind->data;\n\n copyswap = self->ao->descr->f->copyswap;\n\t/* Loop over Boolean array */\n\tswap = !(PyArray_ISNOTSWAPPED(self->ao));\n\twhile(index--) {\n\t\tif (*((Bool *)dptr) != 0) {\n copyswap(optr, self->dataptr, swap, itemsize);\n\t\t\toptr += itemsize;\n\t\t}\n\t\tdptr += strides;\n\t\tPyArray_ITER_NEXT(self);\n\t}\n\tPyArray_ITER_RESET(self);\n\treturn r;\n}\n\nstatic PyObject *\niter_subscript_int(PyArrayIterObject *self, PyArrayObject *ind)\n{\n\tintp num;\n\tPyObject *r;\n\tPyArrayIterObject *ind_it;\n\tint itemsize;\n\tint swap;\n\tchar *optr;\n\tint index;\n PyArray_CopySwapFunc *copyswap;\n\n\titemsize = self->ao->descr->elsize;\n\tif (ind->nd == 0) {\n\t\tnum = *((intp *)ind->data);\n\t\tPyArray_ITER_GOTO1D(self, num);\n\t\tr = PyArray_ToScalar(self->dataptr, self->ao);\n\t\tPyArray_ITER_RESET(self);\n\t\treturn r;\n\t}\n\t\n\tPy_INCREF(self->ao->descr);\n\tr = PyArray_NewFromDescr(self->ao->ob_type, self->ao->descr, \n\t\t\t\t ind->nd, ind->dimensions,\n\t\t\t\t NULL, NULL, \n\t\t\t\t 0, (PyObject *)self->ao);\n\tif (r==NULL) return NULL;\n\n\toptr = PyArray_DATA(r);\n\tind_it = (PyArrayIterObject *)PyArray_IterNew((PyObject *)ind);\n\tif (ind_it == NULL) {Py_DECREF(r); return NULL;}\n\tindex = ind_it->size;\n copyswap = PyArray_DESCR(r)->f->copyswap;\n swap = !PyArray_ISNOTSWAPPED(self->ao);\n\twhile(index--) {\n\t\tnum = *((intp *)(ind_it->dataptr));\n\t\tif (num < 0) num += self->size;\n\t\tif (num < 0 || num >= self->size) {\n\t\t\tPyErr_Format(PyExc_IndexError,\n\t\t\t\t \"index %d out of bounds\"\t\t\\\n\t\t\t\t \" 0<=index<%d\", (int) num, \n\t\t\t\t (int) self->size);\n\t\t\tPy_DECREF(ind_it);\n\t\t\tPy_DECREF(r);\n\t\t\tPyArray_ITER_RESET(self);\n\t\t\treturn NULL;\n\t\t}\n\t\tPyArray_ITER_GOTO1D(self, num);\n copyswap(optr, self->dataptr, swap, itemsize);\n\t\toptr += itemsize;\n\t\tPyArray_ITER_NEXT(ind_it);\n\t}\n\tPy_DECREF(ind_it);\n\tPyArray_ITER_RESET(self);\n\treturn r;\n}\n\n\nstatic PyObject *\niter_subscript(PyArrayIterObject *self, PyObject *ind)\n{\n\tPyArray_Descr *indtype=NULL;\n\tintp start, step_size;\n\tintp n_steps;\n\tPyObject *r;\n\tchar *dptr;\n\tint size;\n\tPyObject *obj = NULL;\n\tint swap;\n PyArray_CopySwapFunc *copyswap;\n\n\tif (ind == Py_Ellipsis) {\n\t\tind = PySlice_New(NULL, NULL, NULL);\n\t\tobj = iter_subscript(self, ind);\n\t\tPy_DECREF(ind);\n\t\treturn obj;\n\t}\n\tif (PyTuple_Check(ind)) {\n\t\tint len;\n\t\tlen = PyTuple_GET_SIZE(ind);\n\t\tif (len > 1) goto fail;\n\t\tind = PyTuple_GET_ITEM(ind, 0);\n\t}\n\n\t/* Tuples >1d not accepted --- i.e. no newaxis */\n\t/* Could implement this with adjusted strides\n\t and dimensions in iterator */\n\n\t/* Check for Boolean -- this is first becasue\n\t Bool is a subclass of Int */\n\tPyArray_ITER_RESET(self);\n\n\tif (PyBool_Check(ind)) {\n\t\tif (PyObject_IsTrue(ind)) {\n\t\t\treturn PyArray_ToScalar(self->dataptr, self->ao);\n\t\t}\n\t\telse { /* empty array */\n\t\t\tintp ii = 0;\n\t\t\tPy_INCREF(self->ao->descr);\n\t\t\tr = PyArray_NewFromDescr(self->ao->ob_type, \n\t\t\t\t\t\t self->ao->descr,\n\t\t\t\t\t\t 1, &ii, \n\t\t\t\t\t\t NULL, NULL, 0,\n\t\t\t\t\t\t (PyObject *)self->ao);\n\t\t\treturn r;\t\t\t\n\t\t}\n\t}\n\n\t/* Check for Integer or Slice */ \t\n\t\n\tif (PyLong_Check(ind) || PyInt_Check(ind) || PySlice_Check(ind)) {\n\t\tstart = parse_subindex(ind, &step_size, &n_steps, \n\t\t\t\t self->size);\n\t\tif (start == -1) \n\t\t\tgoto fail;\n\t\tif (n_steps == RubberIndex || n_steps == PseudoIndex) {\n\t\t\tPyErr_SetString(PyExc_IndexError, \n\t\t\t\t\t\"cannot use Ellipsis or newaxes here\");\n\t\t\tgoto fail;\n\t\t}\n\t\tPyArray_ITER_GOTO1D(self, start)\n\t\tif (n_steps == SingleIndex) { /* Integer */\n\t\t\tr = PyArray_ToScalar(self->dataptr, self->ao);\n\t\t\tPyArray_ITER_RESET(self);\n\t\t\treturn r;\n\t\t}\n\t\tsize = self->ao->descr->elsize;\n\t\tPy_INCREF(self->ao->descr);\n\t\tr = PyArray_NewFromDescr(self->ao->ob_type, \n\t\t\t\t\t self->ao->descr, \n\t\t\t\t\t 1, &n_steps, \n\t\t\t\t\t NULL, NULL,\n\t\t\t\t\t 0, (PyObject *)self->ao);\n\t\tif (r==NULL) goto fail; \n\t\tdptr = PyArray_DATA(r);\n swap = !PyArray_ISNOTSWAPPED(self->ao);\n copyswap = PyArray_DESCR(r)->f->copyswap;\n\t\twhile(n_steps--) {\n copyswap(dptr, self->dataptr, swap, size);\n\t\t\tstart += step_size;\n\t\t\tPyArray_ITER_GOTO1D(self, start)\n\t\t\tdptr += size;\n\t\t}\n\t\tPyArray_ITER_RESET(self);\n\t\treturn r;\n\t} \n\n\t/* convert to INTP array if Integer array scalar or List */\n\n\tindtype = PyArray_DescrFromType(PyArray_INTP);\n\tif (PyArray_IsScalar(ind, Integer) || PyList_Check(ind)) {\n\t\tPy_INCREF(indtype);\n\t\tobj = PyArray_FromAny(ind, indtype, 0, 0, FORCECAST, NULL);\n\t\tif (obj == NULL) goto fail;\n\t}\n\telse {\n\t\tPy_INCREF(ind);\n\t\tobj = ind;\n\t}\n\t\n\tif (PyArray_Check(obj)) {\n\t\t/* Check for Boolean object */\n\t\tif (PyArray_TYPE(obj)==PyArray_BOOL) {\n\t\t\tr = iter_subscript_Bool(self, (PyArrayObject *)obj);\n\t\t\tPy_DECREF(indtype);\n\t\t} \n\t\t/* Check for integer array */\n\t\telse if (PyArray_ISINTEGER(obj)) {\n\t\t\tPyObject *new;\n\t\t\tnew = PyArray_FromAny(obj, indtype, 0, 0, \n FORCECAST | ALIGNED, NULL);\n\t\t\tif (new==NULL) goto fail;\n Py_DECREF(obj);\n\t\t\tobj = new;\n\t\t\tr = iter_subscript_int(self, (PyArrayObject *)obj);\n\t\t}\n\t\telse {\n\t\t\tgoto fail;\n\t\t}\n\t\tPy_DECREF(obj);\n\t\treturn r;\n\t}\n\telse Py_DECREF(indtype);\n\n\n fail:\n\tif (!PyErr_Occurred())\n\t\tPyErr_SetString(PyExc_IndexError, \"unsupported iterator index\");\n\tPy_XDECREF(indtype);\n\tPy_XDECREF(obj);\n\treturn NULL;\n\n}\n\n\nstatic int\niter_ass_sub_Bool(PyArrayIterObject *self, PyArrayObject *ind,\n\t\t PyArrayIterObject *val, int swap)\n{\n\tint index, strides, itemsize;\n\tchar *dptr;\n PyArray_CopySwapFunc *copyswap;\n\n\tif (ind->nd != 1) {\n\t\tPyErr_SetString(PyExc_ValueError, \n\t\t\t\t\"boolean index array should have 1 dimension\");\n\t\treturn -1;\n\t}\n\titemsize = self->ao->descr->elsize;\n\tindex = ind->dimensions[0];\n\tstrides = ind->strides[0];\n\tdptr = ind->data;\n\tPyArray_ITER_RESET(self);\n\t/* Loop over Boolean array */\n copyswap = self->ao->descr->f->copyswap;\n\twhile(index--) {\n\t\tif (*((Bool *)dptr) != 0) {\n copyswap(self->dataptr, val->dataptr, swap,\n\t\t\t\t itemsize);\n\t\t\tPyArray_ITER_NEXT(val);\n\t\t\tif (val->index==val->size) \n\t\t\t\tPyArray_ITER_RESET(val);\n\t\t}\n\t\tdptr += strides;\n\t\tPyArray_ITER_NEXT(self);\n\t}\n\tPyArray_ITER_RESET(self);\n\treturn 0;\n}\n\nstatic int\niter_ass_sub_int(PyArrayIterObject *self, PyArrayObject *ind,\n\t\t PyArrayIterObject *val, int swap)\n{\n\tPyArray_Descr *typecode;\n\tintp num;\n\tPyArrayIterObject *ind_it;\n\tint itemsize;\n\tint index;\n PyArray_CopySwapFunc *copyswap;\n\n\ttypecode = self->ao->descr;\n\titemsize = typecode->elsize;\n copyswap = self->ao->descr->f->copyswap;\n\tif (ind->nd == 0) {\n\t\tnum = *((intp *)ind->data);\n\t\tPyArray_ITER_GOTO1D(self, num);\n copyswap(self->dataptr, val->dataptr, swap, itemsize);\n\t\treturn 0;\n\t}\n\tind_it = (PyArrayIterObject *)PyArray_IterNew((PyObject *)ind);\n\tif (ind_it == NULL) return -1;\n\tindex = ind_it->size;\n\twhile(index--) {\n\t\tnum = *((intp *)(ind_it->dataptr));\n\t\tif (num < 0) num += self->size;\n\t\tif ((num < 0) || (num >= self->size)) {\n\t\t\tPyErr_Format(PyExc_IndexError,\n\t\t\t\t \"index %d out of bounds\"\t\t\\\n\t\t\t\t \" 0<=index<%d\", (int) num, \n\t\t\t\t (int) self->size);\n\t\t\tPy_DECREF(ind_it);\n\t\t\treturn -1;\n\t\t}\n\t\tPyArray_ITER_GOTO1D(self, num);\n copyswap(self->dataptr, val->dataptr, swap, itemsize);\n\t\tPyArray_ITER_NEXT(ind_it);\n\t\tPyArray_ITER_NEXT(val);\n\t\tif (val->index == val->size) \n\t\t\tPyArray_ITER_RESET(val);\n\t}\n\tPy_DECREF(ind_it);\n\treturn 0;\n}\n\nstatic int\niter_ass_subscript(PyArrayIterObject *self, PyObject *ind, PyObject *val) \n{\n\tPyObject *arrval=NULL;\n\tPyArrayIterObject *val_it=NULL;\n\tPyArray_Descr *type;\n\tPyArray_Descr *indtype=NULL;\n\tint swap, retval=-1;\n\tint itemsize;\n\tintp start, step_size;\n\tintp n_steps;\n\tPyObject *obj=NULL;\n PyArray_CopySwapFunc *copyswap;\n\n\t\n\tif (ind == Py_Ellipsis) {\n\t\tind = PySlice_New(NULL, NULL, NULL);\n\t\tretval = iter_ass_subscript(self, ind, val);\n\t\tPy_DECREF(ind);\n\t\treturn retval;\n\t}\n\n\tif (PyTuple_Check(ind)) {\n\t\tint len;\n\t\tlen = PyTuple_GET_SIZE(ind);\n\t\tif (len > 1) goto finish;\n\t\tind = PyTuple_GET_ITEM(ind, 0);\n\t}\n\n\ttype = self->ao->descr;\n\titemsize = type->elsize;\n\t\n\tPy_INCREF(type);\n\tarrval = PyArray_FromAny(val, type, 0, 0, 0, NULL);\n\tif (arrval==NULL) return -1;\n\tval_it = (PyArrayIterObject *)PyArray_IterNew(arrval);\n\tif (val_it==NULL) goto finish;\n\n\t/* Check for Boolean -- this is first becasue\n\t Bool is a subclass of Int */\n\n copyswap = PyArray_DESCR(arrval)->f->copyswap;\n\tswap = (PyArray_ISNOTSWAPPED(self->ao)!=PyArray_ISNOTSWAPPED(arrval));\n\tif (PyBool_Check(ind)) {\n\t\tif (PyObject_IsTrue(ind)) {\n copyswap(self->dataptr, PyArray_DATA(arrval), \n swap, itemsize);\n\t\t}\n\t\tretval=0;\n\t\tgoto finish;\n\t}\n\n\t/* Check for Integer or Slice */\n\t\n\tif (PyLong_Check(ind) || PyInt_Check(ind) || PySlice_Check(ind)) {\n\t\tstart = parse_subindex(ind, &step_size, &n_steps, \n\t\t\t\t self->size);\n\t\tif (start == -1) goto finish;\n\t\tif (n_steps == RubberIndex || n_steps == PseudoIndex) {\n\t\t\tPyErr_SetString(PyExc_IndexError, \n\t\t\t\t\t\"cannot use Ellipsis or newaxes here\");\n\t\t\tgoto finish;\n\t\t}\n\t\tPyArray_ITER_GOTO1D(self, start);\n\t\tif (n_steps == SingleIndex) { /* Integer */\n copyswap(self->dataptr, PyArray_DATA(arrval),\n swap, itemsize);\n\t\t\tPyArray_ITER_RESET(self);\n\t\t\tretval=0;\n\t\t\tgoto finish;\n\t\t}\n\t\twhile(n_steps--) {\n copyswap(self->dataptr, val_it->dataptr,\n swap, itemsize);\n\t\t\tstart += step_size;\n\t\t\tPyArray_ITER_GOTO1D(self, start)\n\t\t\tPyArray_ITER_NEXT(val_it);\n\t\t\tif (val_it->index == val_it->size) \n\t\t\t\tPyArray_ITER_RESET(val_it);\n\t\t}\n\t\tPyArray_ITER_RESET(self);\n\t\tretval = 0;\n\t\tgoto finish;\n\t} \n\n\t/* convert to INTP array if Integer array scalar or List */\n\n\tindtype = PyArray_DescrFromType(PyArray_INTP);\n\tif (PyArray_IsScalar(ind, Integer)) {\n\t\tPy_INCREF(indtype);\n\t\tobj = PyArray_FromScalar(ind, indtype);\n\t}\n\telse if (PyList_Check(ind)) {\n\t\tPy_INCREF(indtype);\n\t\tobj = PyArray_FromAny(ind, indtype, 0, 0, FORCECAST, NULL);\n\t}\n\telse {\n\t\tPy_INCREF(ind);\n\t\tobj = ind;\n\t}\n\t\n\tif (PyArray_Check(obj)) {\n\t\t/* Check for Boolean object */\n\t\tif (PyArray_TYPE(obj)==PyArray_BOOL) {\n\t\t\tif (iter_ass_sub_Bool(self, (PyArrayObject *)obj,\n\t\t\t\t\t val_it, swap) < 0)\n\t\t\t\tgoto finish;\n\t\t\tretval=0;\n\t\t} \n\t\t/* Check for integer array */\n\t\telse if (PyArray_ISINTEGER(obj)) {\n\t\t\tPyObject *new;\n\t\t\tPy_INCREF(indtype);\n\t\t\tnew = PyArray_CheckFromAny(obj, indtype, 0, 0, \n FORCECAST | BEHAVED_NS_FLAGS, NULL);\n\t\t\tPy_DECREF(obj);\n\t\t\tobj = new;\n\t\t\tif (new==NULL) goto finish;\n\t\t\tif (iter_ass_sub_int(self, (PyArrayObject *)obj,\n\t\t\t\t\t val_it, swap) < 0)\n\t\t\t\tgoto finish;\n\t\t\tretval=0;\n\t\t}\n\t}\n\n finish:\n\tif (!PyErr_Occurred() && retval < 0)\n\t\tPyErr_SetString(PyExc_IndexError, \n\t\t\t\t\"unsupported iterator index\");\n\tPy_XDECREF(indtype);\n\tPy_XDECREF(obj);\n\tPy_XDECREF(val_it);\n\tPy_XDECREF(arrval);\n\treturn retval;\n\t\n}\n\n\nstatic PyMappingMethods iter_as_mapping = {\n (inquiry)iter_length,\t\t /*mp_length*/\n (binaryfunc)iter_subscript,\t /*mp_subscript*/\n (objobjargproc)iter_ass_subscript,\t/*mp_ass_subscript*/\n};\n\nstatic char doc_iter_array[] = \"__array__(type=None)\\n Get array \"\\\n \"from iterator\";\n\nstatic PyObject *\niter_array(PyArrayIterObject *it, PyObject *op) \n{\n \n PyObject *r;\n intp size;\n\n /* Any argument ignored */\n\n /* Two options: \n 1) underlying array is contiguous\n -- return 1-d wrapper around it \n 2) underlying array is not contiguous\n -- make new 1-d contiguous array with updateifcopy flag set\n to copy back to the old array\n */\n\n size = PyArray_SIZE(it->ao);\n\tPy_INCREF(it->ao->descr);\n if (PyArray_ISCONTIGUOUS(it->ao)) {\n r = PyArray_NewFromDescr(it->ao->ob_type, \n\t\t\t\t\t it->ao->descr,\n\t\t\t\t\t 1, &size, \n\t\t\t\t\t NULL, it->ao->data, \n\t\t\t\t\t it->ao->flags,\n\t\t\t\t\t (PyObject *)it->ao); \n\t\tif (r==NULL) return NULL;\n }\n else {\n r = PyArray_NewFromDescr(it->ao->ob_type, \n\t\t\t\t\t it->ao->descr,\n\t\t\t\t\t 1, &size, \n\t\t\t\t\t NULL, NULL, \n\t\t\t\t\t 0, (PyObject *)it->ao);\n\t\tif (r==NULL) return NULL;\n\t\tif (PyArray_CopyInto((PyArrayObject *)r, it->ao) < 0) {\n\t\t\tPy_DECREF(r); \n\t\t\treturn NULL;\n\t\t}\n PyArray_FLAGS(r) |= UPDATEIFCOPY;\n it->ao->flags &= ~WRITEABLE;\n }\n Py_INCREF(it->ao);\n PyArray_BASE(r) = (PyObject *)it->ao;\n return r;\n \n}\n\nstatic char doc_iter_copy[] = \"copy()\\n Get a copy of 1-d array\";\n\nstatic PyObject *\niter_copy(PyArrayIterObject *it, PyObject *args)\n{\n if (!PyArg_ParseTuple(args, \"\")) return NULL;\t\n\treturn PyArray_Flatten(it->ao, 0);\n}\n\nstatic PyMethodDef iter_methods[] = {\n /* to get array */\n {\"__array__\", (PyCFunction)iter_array, 1, doc_iter_array},\n\t{\"copy\", (PyCFunction)iter_copy, 1, doc_iter_copy},\n {NULL,\t\tNULL}\t\t/* sentinel */\n};\n\nstatic PyMemberDef iter_members[] = {\n\t{\"base\", T_OBJECT, offsetof(PyArrayIterObject, ao), RO, NULL},\n {\"index\", T_INT, offsetof(PyArrayIterObject, index), RO, NULL},\n\t{NULL},\n};\n\nstatic PyObject *\niter_coords_get(PyArrayIterObject *self)\n{\n int nd;\n nd = self->ao->nd;\n if (self->contiguous) { /* coordinates not kept track of --- need to generate\n from index */\n intp val;\n int i;\n val = self->index;\n for (i=0;icoordinates[i] = val / self->factors[i];\n val = val % self->factors[i];\n }\n }\n return PyArray_IntTupleFromIntp(nd, self->coordinates);\n}\n\nstatic PyGetSetDef iter_getsets[] = {\n\t{\"coords\", \n\t (getter)iter_coords_get,\n\t NULL,\n\t \"An N-d tuple of current coordinates.\"},\n\t{NULL, NULL, NULL, NULL},\n};\n\nstatic PyTypeObject PyArrayIter_Type = {\n PyObject_HEAD_INIT(NULL)\n 0,\t\t\t\t\t /* ob_size */\n \"numpy.flatiter\",\t\t /* tp_name */\n sizeof(PyArrayIterObject), /* tp_basicsize */\n 0,\t\t\t\t\t /* tp_itemsize */\n /* methods */\n (destructor)arrayiter_dealloc,\t\t/* tp_dealloc */\n 0,\t\t\t\t\t/* tp_print */\n 0,\t\t\t\t\t/* tp_getattr */\n 0,\t\t\t\t\t/* tp_setattr */\n 0,\t\t\t\t\t/* tp_compare */\n 0,\t\t\t\t\t/* tp_repr */\n 0,\t\t\t\t\t/* tp_as_number */\n 0, \t\t\t /* tp_as_sequence */\n &iter_as_mapping, \t /* tp_as_mapping */\n 0,\t\t\t\t\t/* tp_hash */\n 0,\t\t\t\t\t/* tp_call */\n 0,\t\t\t\t\t/* tp_str */\n 0,\t \t/* tp_getattro */\n 0,\t\t\t\t\t/* tp_setattro */\n 0,\t\t\t\t\t/* tp_as_buffer */\n Py_TPFLAGS_DEFAULT, /* tp_flags */\n 0,\t\t\t\t\t/* tp_doc */\n 0, \t /* tp_traverse */\n 0,\t\t\t\t\t/* tp_clear */\n 0,\t\t\t\t\t/* tp_richcompare */\n 0,\t\t\t\t\t/* tp_weaklistoffset */\n 0, \t /* tp_iter */\n (iternextfunc)arrayiter_next,\t\t/* tp_iternext */\n iter_methods,\t\t\t\t/* tp_methods */\n iter_members,\t \t /* tp_members */\n iter_getsets, /* tp_getset */\n\n};\n\n/** END of Array Iterator **/\n\n\n\n/*********************** Subscript Array Iterator *************************\n * *\n * This object handles subscript behavior for array objects. *\n * It is an iterator object with a next method *\n * It abstracts the n-dimensional mapping behavior to make the looping *\n * code more understandable (maybe) *\n * and so that indexing can be set up ahead of time *\n */ \n\n/* convert an indexing object to an INTP indexing array iterator\n if possible -- otherwise, it is a Slice or Ellipsis object\n and has to be interpreted on bind to a particular \n array so leave it NULL for now.\n */\nstatic int\n_convert_obj(PyObject *obj, PyArrayIterObject **iter)\n{\n\tPyArray_Descr *indtype;\n\tPyObject *arr;\n\n\tif (PySlice_Check(obj) || (obj == Py_Ellipsis))\n\t\t*iter = NULL;\n\telse {\n\t\tindtype = PyArray_DescrFromType(PyArray_INTP);\n\t\tarr = PyArray_FromAny(obj, indtype, 0, 0, FORCECAST, NULL);\n\t\tif (arr == NULL) return -1;\n\t\t*iter = (PyArrayIterObject *)PyArray_IterNew(arr);\n\t\tPy_DECREF(arr);\n\t\tif (*iter == NULL) return -1;\n\t}\n\treturn 0;\n}\n\n/* Adjust dimensionality and strides for index object iterators \n --- i.e. broadcast\n */\n/*OBJECT_API*/\nstatic int\nPyArray_Broadcast(PyArrayMultiIterObject *mit)\n{\n\tint i, nd, k, j;\n\tintp tmp;\n\tPyArrayIterObject *it;\n\t\n\t/* Discover the broadcast number of dimensions */\n\tfor (i=0, nd=0; inumiter; i++) \n\t\tnd = MAX(nd, mit->iters[i]->ao->nd);\n\tmit->nd = nd;\n\n\t/* Discover the broadcast shape in each dimension */\n\tfor (i=0; idimensions[i] = 1;\n\t\tfor (j=0; jnumiter; j++) {\n\t\t\tit = mit->iters[j];\n\t\t\t/* This prepends 1 to shapes not already \n\t\t\t equal to nd */\n\t\t\tk = i + it->ao->nd - nd;\n\t\t\tif (k>=0) {\n\t\t\t\ttmp = it->ao->dimensions[k];\n\t\t\t\tif (tmp == 1) continue;\n\t\t\t\tif (mit->dimensions[i] == 1) \n\t\t\t\t\tmit->dimensions[i] = tmp;\n\t\t\t\telse if (mit->dimensions[i] != tmp) {\n\t\t\t\t\tPyErr_SetString(PyExc_ValueError, \n\t\t\t\t\t\t\t\"index objects are \" \\\n\t\t\t\t\t\t\t\"not broadcastable \" \\\n\t\t\t\t\t\t\t\"to a single shape\");\n\t\t\t\t\treturn -1;\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t}\n\n\t/* Reset the iterator dimensions and strides of each iterator\n\t object -- using 0 valued strides for broadcasting */\n\n\ttmp = PyArray_MultiplyList(mit->dimensions, mit->nd);\n\tmit->size = tmp;\n\tfor (i=0; inumiter; i++) {\n\t\tit = mit->iters[i];\n\t\tit->nd_m1 = mit->nd - 1;\n\t\tit->size = tmp;\n\t\tnd = it->ao->nd;\n\t\tit->factors[mit->nd-1] = 1;\n\t\tfor (j=0; j < mit->nd; j++) {\n\t\t\tit->dims_m1[j] = mit->dimensions[j] - 1;\n\t\t\tk = j + nd - mit->nd;\n\t\t\t/* If this dimension was added or shape\n\t\t\t of underlying array was 1 */\n\t\t\tif ((k < 0) || \\\n\t\t\t it->ao->dimensions[k] != mit->dimensions[j]) {\n\t\t\t\tit->contiguous = 0;\n\t\t\t\tit->strides[j] = 0;\n\t\t\t}\n\t\t\telse {\n\t\t\t\tit->strides[j] = it->ao->strides[k];\n\t\t\t}\n\t\t\tit->backstrides[j] = it->strides[j] *\t\\\n\t\t\t\tit->dims_m1[j];\n\t\t\tif (j > 0)\n\t\t\t\tit->factors[mit->nd-j-1] =\t\t\\\n\t\t\t\t\tit->factors[mit->nd-j] *\t\\\n\t\t\t\t\tmit->dimensions[mit->nd-j];\n\t\t}\n\t\tPyArray_ITER_RESET(it);\n\t}\n\treturn 0;\n}\n\n/* Reset the map iterator to the beginning */\nstatic void\nPyArray_MapIterReset(PyArrayMapIterObject *mit)\n{\n\tint i,j; intp coord[MAX_DIMS];\n\tPyArrayIterObject *it;\n\tPyArray_CopySwapFunc *copyswap;\n\n\tmit->index = 0;\n\n\tcopyswap = mit->iters[0]->ao->descr->f->copyswap;\n\n\tif (mit->subspace != NULL) {\n\t\tmemcpy(coord, mit->bscoord, sizeof(intp)*mit->ait->ao->nd);\n\t\tPyArray_ITER_RESET(mit->subspace);\n\t\tfor (i=0; inumiter; i++) {\n\t\t\tit = mit->iters[i];\n\t\t\tPyArray_ITER_RESET(it);\n\t\t\tj = mit->iteraxes[i];\n\t\t\tcopyswap(coord+j,it->dataptr,\n\t\t\t\t !PyArray_ISNOTSWAPPED(it->ao),\n\t\t\t\t sizeof(intp));\n\t\t}\n\t\tPyArray_ITER_GOTO(mit->ait, coord);\n\t\tmit->subspace->dataptr = mit->ait->dataptr;\n\t\tmit->dataptr = mit->subspace->dataptr;\n\t}\n\telse {\n\t\tfor (i=0; inumiter; i++) {\n\t\t\tit = mit->iters[i];\n\t\t\tPyArray_ITER_RESET(it);\n\t\t\tcopyswap(coord+i,it->dataptr, \n\t\t\t\t !PyArray_ISNOTSWAPPED(it->ao),\n\t\t\t\t sizeof(intp));\n\t\t}\n\t\tPyArray_ITER_GOTO(mit->ait, coord);\n\t\tmit->dataptr = mit->ait->dataptr;\n\t}\n\treturn;\n}\n\n/* This function needs to update the state of the map iterator\n and point mit->dataptr to the memory-location of the next object\n*/\nstatic void\nPyArray_MapIterNext(PyArrayMapIterObject *mit)\n{\n\tint i, j;\n\tintp coord[MAX_DIMS];\n\tPyArrayIterObject *it;\n\tPyArray_CopySwapFunc *copyswap;\n\n\tmit->index += 1;\n\tif (mit->index >= mit->size) return;\n\tcopyswap = mit->iters[0]->ao->descr->f->copyswap;\n\t/* Sub-space iteration */\n\tif (mit->subspace != NULL) {\n\t\tPyArray_ITER_NEXT(mit->subspace);\n\t\tif (mit->subspace->index == mit->subspace->size) {\n\t\t\t/* reset coord to coordinates of \n\t\t\t beginning of the subspace */\n\t\t\tmemcpy(coord, mit->bscoord, \n\t\t\t sizeof(intp)*mit->ait->ao->nd);\n\t\t\tPyArray_ITER_RESET(mit->subspace);\n\t\t\tfor (i=0; inumiter; i++) {\n\t\t\t\tit = mit->iters[i];\n\t\t\t\tPyArray_ITER_NEXT(it);\n\t\t\t\tj = mit->iteraxes[i];\n\t\t\t\tcopyswap(coord+j,it->dataptr,\n\t\t\t\t\t !PyArray_ISNOTSWAPPED(it->ao),\n\t\t\t\t\t sizeof(intp));\n\t\t\t}\n\t\t\tPyArray_ITER_GOTO(mit->ait, coord);\n\t\t\tmit->subspace->dataptr = mit->ait->dataptr;\n\t\t}\n\t\tmit->dataptr = mit->subspace->dataptr;\n\t}\n\telse {\n\t\tfor (i=0; inumiter; i++) {\n\t\t\tit = mit->iters[i];\n\t\t\tPyArray_ITER_NEXT(it);\n\t\t\tcopyswap(coord+i,it->dataptr, \n\t\t\t\t !PyArray_ISNOTSWAPPED(it->ao),\n\t\t\t\t sizeof(intp));\n\t\t}\n\t\tPyArray_ITER_GOTO(mit->ait, coord);\n\t\tmit->dataptr = mit->ait->dataptr;\n\t}\n\treturn;\n}\n\n/* Bind a mapiteration to a particular array */\n\n/* Determine if subspace iteration is necessary. If so, \n 1) Fill in mit->iteraxes\n\t 2) Create subspace iterator\n\t 3) Update nd, dimensions, and size. \n\n Subspace iteration is necessary if: arr->nd > mit->numiter\n*/\n\n/* Need to check for index-errors somewhere. \n\n Let's do it at bind time and also convert all <0 values to >0 here\n as well. \n*/\nstatic void\nPyArray_MapIterBind(PyArrayMapIterObject *mit, PyArrayObject *arr)\n{\n\tint subnd;\n\tPyObject *sub, *obj=NULL;\n\tint i, j, n, curraxis, ellipexp, noellip;\n\tPyArrayIterObject *it;\n\tintp dimsize;\n\tintp *indptr;\n\t\n\tsubnd = arr->nd - mit->numiter;\n\tif (subnd < 0) {\n\t\tPyErr_SetString(PyExc_ValueError, \n\t\t\t\t\"too many indices for array\");\n\t\treturn;\n\t}\n\n\tmit->ait = (PyArrayIterObject *)PyArray_IterNew((PyObject *)arr);\n\tif (mit->ait == NULL) return;\n\n\t/* If this is just a view, then do nothing more */\n\t/* views are handled by just adjusting the strides\n\t and dimensions of the object.\n\t*/\n\t \n\t/* no subspace iteration needed. Finish up and Return */\n\tif (subnd == 0) {\n\t\tn = arr->nd;\n\t\tfor (i=0; iiteraxes[i] = i;\n\t\t}\n\t\tgoto finish;\n\t}\n\n\t/* all indexing arrays have been converted to 0 \n\t therefore we can extract the subspace with a simple\n\t getitem call which will use view semantics\n\t*/\n\t\n\tsub = PyObject_GetItem((PyObject *)arr, mit->indexobj);\n\tif (sub == NULL) goto fail;\n\tmit->subspace = (PyArrayIterObject *)PyArray_IterNew(sub);\n\tPy_DECREF(sub);\n\tif (mit->subspace == NULL) goto fail;\n\t\n\t/* Expand dimensions of result */\n\tn = mit->subspace->ao->nd;\n\tfor (i=0; idimensions[mit->nd+i] = mit->subspace->ao->dimensions[i];\n\tmit->nd += n;\n\n\t/* Now, we still need to interpret the ellipsis and slice objects \n\t to determine which axes the indexing arrays are referring to\n\t*/\n\tn = PyTuple_GET_SIZE(mit->indexobj);\n\n\t/* The number of dimensions an ellipsis takes up */\n\tellipexp = arr->nd - n + 1;\n\t/* Now fill in iteraxes -- remember indexing arrays have been \n converted to 0's in mit->indexobj */\n\tcurraxis = 0;\n\tj = 0;\n\tnoellip = 1; /* Only expand the first ellipsis */\n\tmemset(mit->bscoord, 0, sizeof(intp)*arr->nd);\n\tfor (i=0; iindexobj, i);\n\t\tif (PyInt_Check(obj) || PyLong_Check(obj)) \n\t\t\tmit->iteraxes[j++] = curraxis++;\n\t\telse if (noellip && obj == Py_Ellipsis) {\n\t\t\tcurraxis += ellipexp;\n\t\t\tnoellip = 0;\n\t\t}\n\t\telse {\n\t\t\tintp start=0;\n\t\t\tintp stop, step;\n\t\t\t/* Should be slice object or\n\t\t\t another Ellipsis */\n\t\t\tif (obj == Py_Ellipsis) {\n\t\t\t\tmit->bscoord[curraxis] = 0;\n\t\t\t}\n\t\t\telse if (!PySlice_Check(obj) || \\\n\t\t\t\t (slice_GetIndices((PySliceObject *)obj, \n\t\t\t\t\t\t arr->dimensions[curraxis],\n\t\t\t\t\t\t &start, &stop, &step,\n\t\t\t\t\t\t &dimsize) < 0)) {\n\t\t\t\tPyErr_Format(PyExc_ValueError, \n\t\t\t\t\t \"unexpected object \"\t\\\n\t\t\t\t\t \"(%s) in selection position %d\",\n\t\t\t\t\t obj->ob_type->tp_name, i);\n\t\t\t goto fail;\n\t\t\t}\n\t\t\telse {\n\t\t\t\tmit->bscoord[curraxis] = start;\n\t\t\t}\n\t\t\tcurraxis += 1; \n\t\t}\n\t}\n finish:\n\t/* Here check the indexes (now that we have iteraxes) */\n\tmit->size = PyArray_MultiplyList(mit->dimensions, mit->nd);\n\tfor (i=0; inumiter; i++) {\n\t\tit = mit->iters[i];\n\t\tPyArray_ITER_RESET(it);\n\t\tdimsize = arr->dimensions[mit->iteraxes[i]];\n\t\twhile(it->index < it->size) {\n\t\t\tindptr = ((intp *)it->dataptr);\n\t\t\tif (*indptr < 0) *indptr += dimsize;\n\t\t\tif (*indptr < 0 || *indptr >= dimsize) {\n\t\t\t\tPyErr_Format(PyExc_IndexError,\n\t\t\t\t\t \"index (%d) out of range \"\\\n\t\t\t\t\t \"(0<=index<=%d) in dimension %d\",\n\t\t\t\t\t (int) *indptr, (int) (dimsize-1), \n\t\t\t\t\t mit->iteraxes[i]);\n\t\t\t\tgoto fail;\n\t\t\t}\n\t\t\tPyArray_ITER_NEXT(it);\n\t\t} \n\t\tPyArray_ITER_RESET(it);\n\t}\n\treturn;\n\n fail:\n\tPy_XDECREF(mit->subspace);\n\tPy_XDECREF(mit->ait);\n\tmit->subspace = NULL;\n\tmit->ait = NULL;\n\treturn;\n}\n\n/* This function takes a Boolean array and constructs index objects and\n iterators as if nonzero(Bool) had been called\n*/\nstatic int\n_nonzero_indices(PyObject *myBool, PyArrayIterObject **iters)\n{\n\tPyArray_Descr *typecode;\n\tPyArrayObject *ba =NULL, *new=NULL;\n\tint nd, j;\n\tintp size, i, count;\n\tBool *ptr;\n\tintp coords[MAX_DIMS], dims_m1[MAX_DIMS];\n\tintp *dptr[MAX_DIMS];\n\n\ttypecode=PyArray_DescrFromType(PyArray_BOOL);\n\tba = (PyArrayObject *)PyArray_FromAny(myBool, typecode, 0, 0, \n\t\t\t\t\t CARRAY_FLAGS, NULL);\n\tif (ba == NULL) return -1;\n\tnd = ba->nd;\n\tfor (j=0; jdata;\n\tcount = 0;\n\n\t/* pre-determine how many nonzero entries there are */\n\tfor (i=0; iao->data;\n\t\tcoords[j] = 0;\n\t\tdims_m1[j] = ba->dimensions[j]-1;\n\t}\n\n\tptr = (Bool *)ba->data;\n\n\tif (count == 0) goto finish;\n\t\n\t/* Loop through the Boolean array and copy coordinates\n\t for non-zero entries */\n\tfor (i=0; i=0; j--) {\n\t\t\tif (coords[j] < dims_m1[j]) {\n\t\t\t\tcoords[j]++;\n\t\t\t\tbreak;\n\t\t\t}\n\t\t\telse {\n\t\t\t\tcoords[j] = 0;\n\t\t\t}\n\t\t}\n\t}\n\n finish:\n\tPy_DECREF(ba);\n\treturn nd;\n\n fail:\n\tfor (j=0; jiters[i] = NULL;\n \tmit->index = 0;\n \tmit->ait = NULL;\n \tmit->subspace = NULL;\n\tmit->numiter = 0;\n\tmit->consec = 1;\n\tPy_INCREF(indexobj);\n\tmit->indexobj = indexobj;\n\n\tif (fancy == SOBJ_LISTTUP) {\n\t\tPyObject *newobj;\n\t\tnewobj = PySequence_Tuple(indexobj);\n\t\tif (newobj == NULL) goto fail;\n\t\tPy_DECREF(indexobj);\n\t\tindexobj = newobj;\n\t\tmit->indexobj = indexobj;\n\t}\n\n#undef SOBJ_NOTFANCY \n#undef SOBJ_ISFANCY \n#undef SOBJ_BADARRAY \n#undef SOBJ_TOOMANY \n#undef SOBJ_LISTTUP \n \n\tif (oned) return (PyObject *)mit;\n\n\t/* Must have some kind of fancy indexing if we are here */\n\t/* indexobj is either a list, an arrayobject, or a tuple \n\t (with at least 1 list or arrayobject or Bool object), */\n\t\n\t/* convert all inputs to iterators */\n\tif (PyArray_Check(indexobj) &&\t\t\t\\\n\t (PyArray_TYPE(indexobj) == PyArray_BOOL)) {\n\t\tmit->numiter = _nonzero_indices(indexobj, mit->iters);\n\t\tif (mit->numiter < 0) goto fail;\n\t\tmit->nd = 1;\n\t\tmit->dimensions[0] = mit->iters[0]->dims_m1[0]+1;\n\t\tPy_DECREF(mit->indexobj);\n\t\tmit->indexobj = PyTuple_New(mit->numiter);\n\t\tif (mit->indexobj == NULL) goto fail;\n\t\tfor (i=0; inumiter; i++) {\n\t\t\tPyTuple_SET_ITEM(mit->indexobj, i, \n\t\t\t\t\t PyInt_FromLong(0));\n\t\t}\n\t}\n\n\telse if (PyArray_Check(indexobj) || !PyTuple_Check(indexobj)) {\n\t\tmit->numiter = 1;\n\t\tindtype = PyArray_DescrFromType(PyArray_INTP);\n\t\tarr = PyArray_FromAny(indexobj, indtype, 0, 0, FORCECAST, NULL);\n\t\tif (arr == NULL) goto fail;\n\t\tmit->iters[0] = (PyArrayIterObject *)PyArray_IterNew(arr);\n\t\tif (mit->iters[0] == NULL) {Py_DECREF(arr); goto fail;}\n\t\tmit->nd = PyArray_NDIM(arr);\n\t\tmemcpy(mit->dimensions,PyArray_DIMS(arr),mit->nd*sizeof(intp));\n\t\tmit->size = PyArray_SIZE(arr);\n\t\tPy_DECREF(arr);\n\t\tPy_DECREF(mit->indexobj);\n\t\tmit->indexobj = Py_BuildValue(\"(N)\", PyInt_FromLong(0));\n\t}\n\telse { /* must be a tuple */\n\t\tPyObject *obj;\n\t\tPyArrayIterObject *iter;\n\t\tPyObject *new;\n\t\t/* Make a copy of the tuple -- we will be replacing \n\t\t index objects with 0's */\n\t\tn = PyTuple_GET_SIZE(indexobj);\n\t\tnew = PyTuple_New(n);\n\t\tif (new == NULL) goto fail;\n\t\tstarted = 0;\n\t\tnonindex = 0;\n\t\tfor (i=0; iconsec = 0;\n\t\t\t\tmit->iters[(mit->numiter)++] = iter;\n\t\t\t\tPyTuple_SET_ITEM(new,i,\n\t\t\t\t\t\t PyInt_FromLong(0));\n\t\t\t}\n\t\t\telse {\n\t\t\t\tif (started) nonindex = 1;\n\t\t\t\tPy_INCREF(obj);\n\t\t\t\tPyTuple_SET_ITEM(new,i,obj);\n\t\t\t}\n\t\t}\n\t\tPy_DECREF(mit->indexobj);\n\t\tmit->indexobj = new;\n\t\t/* Store the number of iterators actually converted */\n\t\t/* These will be mapped to actual axes at bind time */\n\t\tif (PyArray_Broadcast((PyArrayMultiIterObject *)mit) < 0)\n\t\t\tgoto fail;\n\t}\n\n return (PyObject *)mit;\n \n fail:\n Py_DECREF(mit);\n\treturn NULL;\n}\n\n\nstatic void\narraymapiter_dealloc(PyArrayMapIterObject *mit)\n{\n\tint i;\n\tPy_XDECREF(mit->indexobj);\n Py_XDECREF(mit->ait);\n\tPy_XDECREF(mit->subspace);\n\tfor (i=0; inumiter; i++)\n\t\tPy_XDECREF(mit->iters[i]);\n _pya_free(mit);\n}\n\n/* The mapiter object must be created new each time. It does not work\n to bind to a new array, and continue.\n\n This was the orginal intention, but currently that does not work. \n Do not expose the MapIter_Type to Python.\n\n It's not very useful anyway, since mapiter(indexobj); mapiter.bind(a); \n mapiter is equivalent to a[indexobj].flat but the latter gets to use \n slice syntax.\n*/\n\nstatic PyTypeObject PyArrayMapIter_Type = {\n PyObject_HEAD_INIT(NULL)\n 0,\t\t\t\t\t /* ob_size */\n \"numpy.mapiter\",\t\t \t/* tp_name */\n sizeof(PyArrayIterObject), /* tp_basicsize */\n 0,\t\t\t\t\t /* tp_itemsize */\n /* methods */\n (destructor)arraymapiter_dealloc,\t/* tp_dealloc */\n 0,\t\t\t\t\t/* tp_print */\n 0,\t\t\t\t\t/* tp_getattr */\n 0,\t\t\t\t\t/* tp_setattr */\n 0,\t\t\t\t\t/* tp_compare */\n 0,\t\t\t\t\t/* tp_repr */\n 0,\t\t\t\t\t/* tp_as_number */\n 0,\t\t\t\t\t/* tp_as_sequence */\n 0,\t\t\t\t\t/* tp_as_mapping */\n 0,\t\t\t\t\t/* tp_hash */\n 0,\t\t\t\t\t/* tp_call */\n 0,\t\t\t\t\t/* tp_str */\n 0, \t\t/* tp_getattro */\n 0,\t\t\t\t\t/* tp_setattro */\n 0,\t\t\t\t\t/* tp_as_buffer */\n Py_TPFLAGS_DEFAULT, /* tp_flags */\n 0,\t\t\t\t\t/* tp_doc */\n (traverseproc)0, \t /* tp_traverse */\n 0,\t\t\t\t\t/* tp_clear */\n 0,\t\t\t\t\t/* tp_richcompare */\n 0,\t\t\t\t\t/* tp_weaklistoffset */\n 0,\t\t \t /* tp_iter */\n (iternextfunc)0, \t /* tp_iternext */\n 0, \t /* tp_methods */\n 0,\t\t\t\t\t /* tp_members */\n 0,\t\t\t /* tp_getset */\n 0,\t\t\t\t\t /* tp_base */\n 0,\t\t\t\t\t /* tp_dict */\n 0,\t\t\t\t\t /* tp_descr_get */\n 0,\t\t\t\t\t /* tp_descr_set */\n 0,\t\t\t\t\t /* tp_dictoffset */\n (initproc)0,\t \t /* tp_init */\n 0, \t /* tp_alloc */\n 0,\t /* tp_new */\n 0,\t /* tp_free */\n 0,\t\t\t\t\t /* tp_is_gc */\n 0,\t\t\t\t\t /* tp_bases */\n 0,\t\t\t\t\t /* tp_mro */\n 0,\t\t\t\t\t /* tp_cache */\n 0,\t\t\t\t\t /* tp_subclasses */\n 0\t\t\t\t\t /* tp_weaklist */\n\n};\n\n/** END of Subscript Iterator **/\n\n\n/*OBJECT_API\n Get MultiIterator,\n*/\nstatic PyObject *\nPyArray_MultiIterNew(int n, ...)\n{\n va_list va;\n\tPyArrayMultiIterObject *multi;\n\tPyObject *current;\n\tPyObject *arr;\n\t\n\tint i, err=0;\n\t\n\tif (n < 2 || n > MAX_DIMS) {\n\t\tPyErr_Format(PyExc_ValueError, \n\t\t\t \"Need between 2 and (%d) \"\t\t\t\\\n\t\t\t \"array objects (inclusive).\", MAX_DIMS);\n\t}\n\t\n /* fprintf(stderr, \"multi new...\");*/\n multi = PyObject_New(PyArrayMultiIterObject, &PyArrayMultiIter_Type);\n if (multi == NULL)\n return NULL;\n\t\n\tfor (i=0; iiters[i] = NULL;\n\tmulti->numiter = n;\n\tmulti->index = 0;\n\n va_start(va, n);\n\tfor (i=0; iiters[i] = (PyArrayIterObject *)PyArray_IterNew(arr);\n\t\t\tPy_DECREF(arr);\n\t\t}\n\t}\n\n\tva_end(va);\t\n\t\n\tif (!err && PyArray_Broadcast(multi) < 0) err=1;\n\n\tif (err) {\n Py_DECREF(multi);\n\t\treturn NULL;\n\t}\n\t\n\tPyArray_MultiIter_RESET(multi);\n\t\n return (PyObject *)multi;\n}\n\nstatic PyObject *\narraymultiter_new(PyTypeObject *subtype, PyObject *args, PyObject *kwds)\n{\n\t\n\tint n, i;\n\tPyArrayMultiIterObject *multi;\n\tPyObject *arr;\n\t\n\tif (kwds != NULL) {\n\t\tPyErr_SetString(PyExc_ValueError, \n\t\t\t\t\"keyword arguments not accepted.\");\n\t\treturn NULL;\n\t}\n\n\tn = PyTuple_Size(args);\n\tif (n < 2 || n > MAX_DIMS) {\n\t\tif (PyErr_Occurred()) return NULL;\n\t\tPyErr_Format(PyExc_ValueError, \n\t\t\t \"Need at least two and fewer than (%d) \"\t\\\n\t\t\t \"array objects.\", MAX_DIMS);\n\t\treturn NULL;\n\t}\n\t\n\tmulti = _pya_malloc(sizeof(PyArrayMultiIterObject));\n if (multi == NULL) return PyErr_NoMemory();\n\tPyObject_Init((PyObject *)multi, &PyArrayMultiIter_Type);\n\n\tmulti->numiter = n;\n\tmulti->index = 0;\n\tfor (i=0; iiters[i] = NULL;\n\tfor (i=0; iiters[i] =\t\t\t\t\t\\\n\t\t (PyArrayIterObject *)PyArray_IterNew(arr))==NULL) \n\t\t\tgoto fail;\n\t\tPy_DECREF(arr);\n\t}\n\tif (PyArray_Broadcast(multi) < 0) goto fail;\n\tPyArray_MultiIter_RESET(multi);\n\t\n return (PyObject *)multi;\n\t\n fail:\n Py_DECREF(multi);\n\treturn NULL;\n}\n\nstatic PyObject *\narraymultiter_next(PyArrayMultiIterObject *multi)\n{\n\tPyObject *ret;\n\tint i, n;\n\n\tn = multi->numiter;\n\tret = PyTuple_New(n);\n\tif (ret == NULL) return NULL;\n\tif (multi->index < multi->size) {\n\t\tfor (i=0; i < n; i++) {\n\t\t\tPyArrayIterObject *it=multi->iters[i];\n\t\t\tPyTuple_SET_ITEM(ret, i, \n\t\t\t\t\t PyArray_ToScalar(it->dataptr, it->ao));\n\t\t\tPyArray_ITER_NEXT(it);\n\t\t}\n\t\tmulti->index++;\n\t\treturn ret;\n\t}\n return NULL;\n}\n\nstatic void\narraymultiter_dealloc(PyArrayMultiIterObject *multi)\n{\n\tint i;\n\n\tfor (i=0; inumiter; i++) \n\t\tPy_XDECREF(multi->iters[i]);\n\t_pya_free(multi);\n}\n\nstatic PyObject *\narraymultiter_size_get(PyArrayMultiIterObject *self)\n{\n#if SIZEOF_INTP <= SIZEOF_LONG\n\treturn PyInt_FromLong((long) self->size);\n#else\n\tif (self->size < MAX_LONG)\n\t\treturn PyInt_FromLong((long) self->size);\n\telse\n\t\treturn PyLong_FromLongLong((longlong) self->size);\n#endif\n}\n\nstatic PyObject *\narraymultiter_index_get(PyArrayMultiIterObject *self)\n{\n#if SIZEOF_INTP <= SIZEOF_LONG\n\treturn PyInt_FromLong((long) self->index);\n#else\n\tif (self->size < MAX_LONG)\n\t\treturn PyInt_FromLong((long) self->index);\n\telse\n\t\treturn PyLong_FromLongLong((longlong) self->index);\n#endif\n}\n\nstatic PyObject *\narraymultiter_shape_get(PyArrayMultiIterObject *self)\n{\n\treturn PyArray_IntTupleFromIntp(self->nd, self->dimensions);\t\n}\n\nstatic PyObject *\narraymultiter_iters_get(PyArrayMultiIterObject *self)\n{\n\tPyObject *res;\n\tint i, n;\n\tn = self->numiter;\n\tres = PyTuple_New(n);\n\tif (res == NULL) return res;\n\tfor (i=0; iiters[i]);\n\t\tPyTuple_SET_ITEM(res, i, (PyObject *)self->iters[i]);\n\t}\n\treturn res;\n}\n\nstatic PyGetSetDef arraymultiter_getsetlist[] = {\n {\"size\", \n\t (getter)arraymultiter_size_get,\n\t NULL, \n\t \"total size of broadcasted result\"},\n {\"index\", \n\t (getter)arraymultiter_index_get, \n NULL,\n\t \"current index in broadcasted result\"},\n\t{\"shape\",\n\t (getter)arraymultiter_shape_get,\n\t NULL,\n\t \"shape of broadcasted result\"},\n\t{\"iters\",\n\t (getter)arraymultiter_iters_get,\n\t NULL,\n\t \"tuple of individual iterators\"},\n\t{NULL, NULL, NULL, NULL},\n};\n\nstatic PyMemberDef arraymultiter_members[] = {\n\t{\"numiter\", T_INT, offsetof(PyArrayMultiIterObject, numiter), \n\t RO, NULL},\n\t{\"nd\", T_INT, offsetof(PyArrayMultiIterObject, nd), RO, NULL},\n\t{NULL},\n};\n\nstatic PyObject *\narraymultiter_reset(PyArrayMultiIterObject *self, PyObject *args)\n{\n\tif (!PyArg_ParseTuple(args, \"\")) return NULL;\n\n\tPyArray_MultiIter_RESET(self);\n\tPy_INCREF(Py_None);\n\treturn Py_None;\n}\n\nstatic PyMethodDef arraymultiter_methods[] = {\n\t{\"reset\", (PyCFunction) arraymultiter_reset, METH_VARARGS, NULL},\n\t{NULL, NULL},\n};\n\nstatic PyTypeObject PyArrayMultiIter_Type = {\n PyObject_HEAD_INIT(NULL)\n 0,\t\t\t\t\t /* ob_size */\n \"numpy.broadcast\",\t\t \t /* tp_name */\n sizeof(PyArrayMultiIterObject), /* tp_basicsize */\n 0,\t\t\t\t\t /* tp_itemsize */\n /* methods */\n (destructor)arraymultiter_dealloc,\t/* tp_dealloc */\n 0,\t\t\t\t\t/* tp_print */\n 0,\t\t\t\t\t/* tp_getattr */\n 0,\t\t\t\t\t/* tp_setattr */\n 0,\t\t\t\t\t/* tp_compare */\n 0,\t\t\t\t\t/* tp_repr */\n 0,\t\t\t\t\t/* tp_as_number */\n 0, /* tp_as_sequence */\n 0, \t /* tp_as_mapping */\n 0,\t\t\t\t\t/* tp_hash */\n 0,\t\t\t\t\t/* tp_call */\n 0,\t\t\t\t\t/* tp_str */\n 0,\t \t/* tp_getattro */\n 0,\t\t\t\t\t/* tp_setattro */\n 0,\t\t\t\t\t/* tp_as_buffer */\n Py_TPFLAGS_DEFAULT, /* tp_flags */\n 0,\t\t\t\t\t/* tp_doc */\n 0, \t /* tp_traverse */\n 0,\t\t\t\t\t/* tp_clear */\n 0,\t\t\t\t\t/* tp_richcompare */\n 0,\t\t\t\t\t/* tp_weaklistoffset */\n 0, \t /* tp_iter */\n (iternextfunc)arraymultiter_next,\t/* tp_iternext */\n arraymultiter_methods, \t /* tp_methods */\n arraymultiter_members,\t \t /* tp_members */\n arraymultiter_getsetlist, /* tp_getset */\n 0,\t\t\t\t\t /* tp_base */\n 0,\t\t\t\t\t /* tp_dict */\n 0,\t\t\t\t\t /* tp_descr_get */\n 0,\t\t\t\t\t /* tp_descr_set */\n 0,\t\t\t\t\t /* tp_dictoffset */\n (initproc)0,\t \t /* tp_init */\n 0, \t /* tp_alloc */\n arraymultiter_new,\t /* tp_new */\n 0,\t /* tp_free */\n 0,\t\t\t\t\t /* tp_is_gc */\n 0,\t\t\t\t\t /* tp_bases */\n 0,\t\t\t\t\t /* tp_mro */\n 0,\t\t\t\t\t /* tp_cache */\n 0,\t\t\t\t\t /* tp_subclasses */\n 0\t\t\t\t\t /* tp_weaklist */\n};\n\n/*OBJECT_API*/\nstatic PyArray_Descr *\nPyArray_DescrNewFromType(int type_num)\n{\n\tPyArray_Descr *old;\n\tPyArray_Descr *new;\n\n\told = PyArray_DescrFromType(type_num);\n\tnew = PyArray_DescrNew(old);\n\tPy_DECREF(old);\n\treturn new;\t\n}\n\n/*** Array Descr Objects for dynamic types **/\n\n/** There are some statically-defined PyArray_Descr objects corresponding\n to the basic built-in types. \n These can and should be DECREF'd and INCREF'd as appropriate, anyway.\n If a mistake is made in reference counting, deallocation on these \n builtins will be attempted leading to problems. \n\n This let's us deal with all PyArray_Descr objects using reference\n counting (regardless of whether they are statically or dynamically \n allocated). \n**/\n\n/* base cannot be NULL */\n/*OBJECT_API*/\nstatic PyArray_Descr *\nPyArray_DescrNew(PyArray_Descr *base)\n{\n\tPyArray_Descr *new;\n\n\tnew = PyObject_New(PyArray_Descr, &PyArrayDescr_Type);\n\tif (new == NULL) return NULL;\n\t/* Don't copy PyObject_HEAD part */\n\tmemcpy((char *)new+sizeof(PyObject),\n\t (char *)base+sizeof(PyObject),\n\t sizeof(PyArray_Descr)-sizeof(PyObject));\n\n\tif (new->fields == Py_None) new->fields = NULL;\n\tPy_XINCREF(new->fields);\n\tif (new->subarray) {\n\t\tnew->subarray = _pya_malloc(sizeof(PyArray_ArrayDescr));\n\t\tmemcpy(new->subarray, base->subarray, \n\t\t sizeof(PyArray_ArrayDescr));\n\t\tPy_INCREF(new->subarray->shape);\n\t\tPy_INCREF(new->subarray->base);\n\t}\n\tPy_INCREF(new->typeobj);\n\treturn new;\n}\n\n/* should never be called for builtin-types unless \n there is a reference-count problem \n*/\nstatic void\narraydescr_dealloc(PyArray_Descr *self)\n{\n\tPy_XDECREF(self->typeobj);\n\tPy_XDECREF(self->fields);\n\tif (self->subarray) {\n\t\tPy_DECREF(self->subarray->shape);\n\t\tPy_DECREF(self->subarray->base);\n\t\t_pya_free(self->subarray);\n\t}\n\tself->ob_type->tp_free(self);\n}\n\n/* we need to be careful about setting attributes because these\n objects are pointed to by arrays that depend on them for interpreting\n data. Currently no attributes of dtype objects can be set. \n*/\nstatic PyMemberDef arraydescr_members[] = {\n\t{\"type\", T_OBJECT, offsetof(PyArray_Descr, typeobj), RO, NULL},\n\t{\"kind\", T_CHAR, offsetof(PyArray_Descr, kind), RO, NULL},\n\t{\"char\", T_CHAR, offsetof(PyArray_Descr, type), RO, NULL},\n\t{\"num\", T_INT, offsetof(PyArray_Descr, type_num), RO, NULL},\n\t{\"byteorder\", T_CHAR, offsetof(PyArray_Descr, byteorder), RO, NULL},\n\t{\"itemsize\", T_INT, offsetof(PyArray_Descr, elsize), RO, NULL},\n\t{\"alignment\", T_INT, offsetof(PyArray_Descr, alignment), RO, NULL},\n {\"hasobject\", T_UBYTE, offsetof(PyArray_Descr, hasobject), RO, NULL},\n\t{NULL}, \n};\n\nstatic PyObject *\narraydescr_subdescr_get(PyArray_Descr *self)\n{\n\tif (self->subarray == NULL) {\n\t\tPy_INCREF(Py_None);\n\t\treturn Py_None;\n\t}\n\treturn Py_BuildValue(\"OO\", (PyObject *)self->subarray->base, \n\t\t\t self->subarray->shape);\n}\n\nstatic PyObject *\narraydescr_protocol_typestr_get(PyArray_Descr *self)\n{\n char basic_=self->kind;\n char endian = self->byteorder;\n\n if (endian == '=') {\n endian = '<';\n if (!PyArray_IsNativeByteOrder(endian)) endian = '>';\n }\n\n return PyString_FromFormat(\"%c%c%d\", endian, basic_,\n self->elsize);\n}\n\nstatic PyObject *\narraydescr_typename_get(PyArray_Descr *self)\n{\n int len;\n PyTypeObject *typeobj = self->typeobj;\n\tPyObject *res;\n\n\t/* Both are equivalents, but second is more resistent to changes */\n/* \tlen = strlen(typeobj->tp_name) - 8; */\n\n\tif (PyTypeNum_ISUSERDEF(self->type_num)) {\n\t\tres = PyString_FromString(typeobj->tp_name);\n\t}\n\telse {\n\t\tlen = strchr(typeobj->tp_name, (int)'_')-(typeobj->tp_name);\n\t\tres = PyString_FromStringAndSize(typeobj->tp_name, len);\n\t}\n\tif (PyTypeNum_ISEXTENDED(self->type_num) && self->elsize != 0) {\n\t\tPyObject *p;\n\t\tp = PyString_FromFormat(\"%d\", self->elsize * 8);\n\t\tPyString_ConcatAndDel(&res, p);\n\t}\n\treturn res;\t\t\t\t\t\t \n}\n\nstatic PyObject *\narraydescr_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\t{\"name\",\n\t (getter)arraydescr_typename_get,\n\t NULL,\n\t \"The array_protocol typename.\"},\n\t{\"isbuiltin\",\n\t (getter)arraydescr_isbuiltin_get,\n\t NULL,\n\t \"Is this a buillt-in data-type descriptor?\"},\n\t{\"isnative\",\n\t (getter)arraydescr_isnative_get,\n\t NULL,\n\t \"Is the byte-order of this descriptor native?\"},\n\t{\"fields\",\n\t (getter)arraydescr_fields_get,\n\t NULL,\n\t NULL},\n\t{NULL, NULL, NULL, NULL},\n};\n\nstatic PyArray_Descr *_convert_from_list(PyObject *obj, int align, int try_descr);\nstatic PyArray_Descr *_convert_from_dict(PyObject *obj, int align);\nstatic PyArray_Descr *_convert_from_commastring(PyObject *obj, int align);\nstatic PyArray_Descr *_convert_from_array_descr(PyObject *obj);\n\nstatic PyObject *\narraydescr_new(PyTypeObject *subtype, PyObject *args, PyObject *kwds)\n{\n\tPyObject *odescr;\n\tPyArray_Descr *descr, *conv;\n\tint align=0;\n\tBool copy=FALSE;\n\tstatic char *kwlist[] = {\"dtype\", \"align\", \"copy\", NULL};\n\t\n\tif (!PyArg_ParseTupleAndKeywords(args, kwds, \"O|iO&\",\n\t\t\t\t\t kwlist, &odescr, &align,\n\t\t\t\t\t PyArray_BoolConverter, ©))\n\t\treturn NULL;\n\t\n\tif (align) {\n\t\tconv = NULL;\n\t\tif PyDict_Check(odescr) \n\t\t\tconv = _convert_from_dict(odescr, 1);\n\t\telse if PyList_Check(odescr) \n\t\t\tconv = _convert_from_list(odescr, 1, 0);\n\t\telse if PyString_Check(odescr)\n\t\t\tconv = _convert_from_commastring(odescr, 1);\n\t\telse {\n\t\t\tPyErr_SetString(PyExc_ValueError, \n\t\t\t\t\t\"align can only be non-zero for\" \\\n\t\t\t\t\t\"dictionary, list, and string objects.\");\n\t\t}\n\t\tif (conv) return (PyObject *)conv;\n\t\tif (!PyErr_Occurred()) {\n\t\t\tPyErr_SetString(PyExc_ValueError,\n\t\t\t\t\t\"data-type-descriptor not understood\");\n\t\t}\n\t\treturn NULL;\n\t}\n\n\tif PyList_Check(odescr) {\n\t\tconv = _convert_from_array_descr(odescr);\n\t\tif (!conv) {\n\t\t\tPyErr_Clear();\n\t\t\tconv = _convert_from_list(odescr, 0, 0);\n\t\t}\n\t\treturn (PyObject *)conv;\n\t}\n\n\tif (!PyArray_DescrConverter(odescr, &conv)) \n\t\treturn NULL;\n\t/* Get a new copy of it unless it's already a copy */\n\tif (copy && conv->fields == Py_None) {\n\t\tdescr = PyArray_DescrNew(conv);\n\t\tPy_DECREF(conv);\n\t\tconv = descr;\n\t}\n\treturn (PyObject *)conv;\n}\n\nstatic char doc_arraydescr_reduce[] = \"self.__reduce__() for pickling.\";\n\n/* return a tuple of (callable object, args, state) */\nstatic PyObject *\narraydescr_reduce(PyArray_Descr *self, PyObject *args)\n{\n\tPyObject *ret, *mod, *obj;\n\tPyObject *state;\n\tchar endian;\n\tint elsize, alignment;\n\n\tret = PyTuple_New(3);\n\tif (ret == NULL) return NULL;\n\tmod = PyImport_ImportModule(\"numpy.core.multiarray\");\n\tif (mod == NULL) {Py_DECREF(ret); return NULL;}\n\tobj = PyObject_GetAttrString(mod, \"dtype\");\n\tPy_DECREF(mod);\n\tif (obj == NULL) {Py_DECREF(ret); return NULL;}\n\tPyTuple_SET_ITEM(ret, 0, obj);\n\tif (PyTypeNum_ISUSERDEF(self->type_num) ||\t\t\\\n\t ((self->type_num == PyArray_VOID &&\t\t\t\\\n\t self->typeobj != &PyVoidArrType_Type))) {\n\t\tobj = (PyObject *)self->typeobj;\n\t\tPy_INCREF(obj);\n\t}\n\telse {\n\t\tobj = PyString_FromFormat(\"%c%d\",self->kind, self->elsize);\n\t}\n\tPyTuple_SET_ITEM(ret, 1, Py_BuildValue(\"(Nii)\", obj, 0, 1));\n\t\n\t/* Now return the state which is at least \n\t byteorder, subarray, and fields */\n\tendian = self->byteorder;\n\tif (endian == '=') {\n\t\tendian = '<';\n\t\tif (!PyArray_IsNativeByteOrder(endian)) endian = '>';\n\t}\n\tstate = PyTuple_New(5);\n\tPyTuple_SET_ITEM(state, 0, PyString_FromFormat(\"%c\", endian));\n\tPyTuple_SET_ITEM(state, 1, arraydescr_subdescr_get(self));\n\tif (self->fields && self->fields != Py_None) {\n\t\tPy_INCREF(self->fields);\n\t\tPyTuple_SET_ITEM(state, 2, self->fields);\n\t}\n\telse {\n\t\tPyTuple_SET_ITEM(state, 2, Py_None);\n\t\tPy_INCREF(Py_None);\n\t}\n\n\t/* for extended types it also includes elsize and alignment */\n\tif (PyTypeNum_ISEXTENDED(self->type_num)) {\n\t\telsize = self->elsize;\n\t\talignment = self->alignment;\n\t}\n\telse {elsize = -1; alignment = -1;}\n\n\tPyTuple_SET_ITEM(state, 3, PyInt_FromLong(elsize));\n\tPyTuple_SET_ITEM(state, 4, PyInt_FromLong(alignment));\n\n\tPyTuple_SET_ITEM(ret, 2, state);\n\treturn ret;\n}\n\n/* state is at least byteorder, subarray, and fields but could include elsize \n and alignment for EXTENDED arrays \n*/\nstatic char doc_arraydescr_setstate[] = \"self.__setstate__() for pickling.\";\n\nstatic PyObject *\narraydescr_setstate(PyArray_Descr *self, PyObject *args)\n{\n\tint elsize = -1, alignment = -1;\n\tchar endian;\n\tPyObject *subarray, *fields;\n\n\tif (self->fields == Py_None) {Py_INCREF(Py_None); return Py_None;}\n\n\tif (!PyArg_ParseTuple(args, \"(cOOii)\", &endian, &subarray, &fields,\n\t\t\t &elsize, &alignment)) return NULL;\n\t\n\tif (PyArray_IsNativeByteOrder(endian)) endian = '=';\n\n\tself->byteorder = endian;\n\tif (self->subarray) {\n\t\tPy_XDECREF(self->subarray->base);\n\t\tPy_XDECREF(self->subarray->shape);\n\t\t_pya_free(self->subarray);\n\t}\n\tself->subarray = NULL;\n\n\tif (subarray != Py_None) {\n\t\tself->subarray = _pya_malloc(sizeof(PyArray_ArrayDescr));\n\t\tself->subarray->base = (PyArray_Descr *)PyTuple_GET_ITEM(subarray, 0);\n\t\tPy_INCREF(self->subarray->base);\n\t\tself->subarray->shape = PyTuple_GET_ITEM(subarray, 1);\n\t\tPy_INCREF(self->subarray->shape);\n\t}\n\t\n\tif (fields != Py_None) {\n\t\tPy_XDECREF(self->fields);\n\t\tself->fields = fields;\n\t\tPy_INCREF(fields);\n\t}\n\t\n\tif (PyTypeNum_ISEXTENDED(self->type_num)) {\n\t\tself->elsize = elsize;\n\t\tself->alignment = alignment;\n\t}\n\t\n\tPy_INCREF(Py_None);\n\treturn Py_None;\n}\n\n\n/* returns a copy of the PyArray_Descr structure with the byteorder\n altered:\n no arguments: The byteorder is swapped (in all subfields as well)\n single argument: The byteorder is forced to the given state\n (in all subfields as well)\n\n Valid states: ('big', '>') or ('little' or '<')\n\t\t ('native', or '=')\n\n\t\t If a descr structure with | is encountered it's own\n\t\t byte-order is not changed but any fields are: \n*/\n\n/*OBJECT_API\n Deep bytorder change of a data-type descriptor\n*/\nstatic PyArray_Descr *\nPyArray_DescrNewByteorder(PyArray_Descr *self, char newendian)\n{\n\tPyArray_Descr *new;\n\tchar endian;\n\n\tnew = PyArray_DescrNew(self);\n\tendian = new->byteorder;\n\tif (endian != PyArray_IGNORE) {\n\t\tif (newendian == PyArray_SWAP) { /* swap byteorder */\n\t\t\tif PyArray_ISNBO(endian) endian = PyArray_OPPBYTE;\n\t\t\telse endian = PyArray_NATBYTE;\n\t\t\tnew->byteorder = endian;\n\t\t}\n\t\telse if (newendian != PyArray_IGNORE) {\n\t\t\tnew->byteorder = newendian;\n\t\t}\n\t}\n\tif (new->fields) {\n\t\tPyObject *newfields;\n\t\tPyObject *key, *value;\n\t\tPyObject *newvalue;\n\t\tPyObject *old;\n\t\tPyArray_Descr *newdescr;\n\t\tint pos = 0, len, i;\n\t\tnewfields = PyDict_New();\n\t\t/* make new dictionary with replaced */\n\t\t/* PyArray_Descr Objects */\n\t\twhile(PyDict_Next(self->fields, &pos, &key, &value)) {\n\t\t\tif (PyInt_Check(key) &&\t\t\t\\\n\t\t\t PyInt_AsLong(key) == -1) {\n\t\t\t\tPyDict_SetItem(newfields, key, value);\n\t\t\t\tcontinue;\n\t\t\t}\n\t\t\tif (!PyString_Check(key) ||\t \\\n\t\t\t !PyTuple_Check(value) ||\t\t\t\\\n\t\t\t ((len=PyTuple_GET_SIZE(value)) < 2))\n\t\t\t\tcontinue;\n\t\t\t\n\t\t\told = PyTuple_GET_ITEM(value, 0);\n\t\t\tif (!PyArray_DescrCheck(old)) continue;\n\t\t\tnewdescr = PyArray_DescrNewByteorder\t\t\\\n\t\t\t\t((PyArray_Descr *)old, newendian);\n\t\t\tif (newdescr == NULL) {\n\t\t\t\tPy_DECREF(newfields); Py_DECREF(new);\n\t\t\t\treturn NULL;\n\t\t\t}\n\t\t\tnewvalue = PyTuple_New(len);\n\t\t\tPyTuple_SET_ITEM(newvalue, 0,\t\t\\\n\t\t\t\t\t (PyObject *)newdescr);\n\t\t\tfor(i=1; ifields);\n\t\tnew->fields = newfields;\n\t}\n\tif (new->subarray) {\n\t\tPy_DECREF(new->subarray->base);\n\t\tnew->subarray->base = PyArray_DescrNewByteorder \\\n\t\t\t(self->subarray->base, newendian);\n\t}\n\treturn new;\n}\n\n\nstatic char doc_arraydescr_newbyteorder[] = \"self.newbyteorder()\"\n\t\" returns a copy of the dtype object\\n\"\n\t\" with altered byteorders. If is not given all byteorders\\n\"\n\t\" are swapped. Otherwise endian can be '>', '<', or '=' to force\\n\"\n\t\" a byteorder. Descriptors in all fields are also updated in the\\n\"\n\t\" new dtype object.\";\n\nstatic PyObject *\narraydescr_newbyteorder(PyArray_Descr *self, PyObject *args) \n{\n\tchar endian=PyArray_SWAP;\n\t\n\tif (!PyArg_ParseTuple(args, \"|O&\", PyArray_ByteorderConverter,\n\t\t\t &endian)) return NULL;\n\t\t\t\n\treturn (PyObject *)PyArray_DescrNewByteorder(self, endian);\n}\n\nstatic PyMethodDef arraydescr_methods[] = {\n /* for pickling */\n {\"__reduce__\", (PyCFunction)arraydescr_reduce, METH_VARARGS, \n\t doc_arraydescr_reduce},\n\t{\"__setstate__\", (PyCFunction)arraydescr_setstate, METH_VARARGS,\n\t doc_arraydescr_setstate},\n\n\t{\"newbyteorder\", (PyCFunction)arraydescr_newbyteorder, METH_VARARGS,\n\t doc_arraydescr_newbyteorder},\n {NULL,\t\tNULL}\t\t/* sentinel */\n};\n\nstatic PyObject *\narraydescr_str(PyArray_Descr *self)\n{\n\tPyObject *sub;\n\n\tif (self->fields && self->fields != Py_None) {\n\t\tPyObject *lst;\n\t\tlst = arraydescr_protocol_descr_get(self);\n\t\tif (!lst) {\n\t\t\tsub = PyString_FromString(\"\");\n\t\t\tPyErr_Clear();\n\t\t}\n\t\telse sub = PyObject_Str(lst);\n\t\tPy_XDECREF(lst);\n\t\tif (self->type_num != PyArray_VOID) {\n\t\t\tPyObject *p;\n\t\t\tPyObject *t=PyString_FromString(\"'\");\n\t\t\tp = arraydescr_protocol_typestr_get(self);\n\t\t\tPyString_Concat(&p, t);\n\t\t\tPyString_ConcatAndDel(&t, p);\n\t\t\tp = PyString_FromString(\"(\");\n\t\t\tPyString_ConcatAndDel(&p, t);\n\t\t\tPyString_ConcatAndDel(&p, PyString_FromString(\", \"));\n\t\t\tPyString_ConcatAndDel(&p, sub);\n\t\t\tPyString_ConcatAndDel(&p, PyString_FromString(\")\"));\n\t\t\tsub = p;\n\t\t}\n\t}\n\telse if (self->subarray) {\n\t\tPyObject *p;\n\t\tPyObject *t = PyString_FromString(\"(\");\n\t\tp = arraydescr_str(self->subarray->base);\n\t\tPyString_ConcatAndDel(&t, p);\n\t\tPyString_ConcatAndDel(&t, PyString_FromString(\",\"));\n\t\tPyString_ConcatAndDel(&t, PyObject_Str(self->subarray->shape));\n\t\tPyString_ConcatAndDel(&t, PyString_FromString(\")\"));\n\t\tsub = t;\n\t}\n\telse {\n\t\tPyObject *t=PyString_FromString(\"'\");\n\t\tsub = arraydescr_protocol_typestr_get(self);\n\t\tPyString_Concat(&sub, t);\n\t\tPyString_ConcatAndDel(&t, sub);\n\t\tsub = t;\n\t}\n\treturn sub;\n}\n\nstatic PyObject *\narraydescr_repr(PyArray_Descr *self)\n{\n\tPyObject *sub, *s;\n\ts = PyString_FromString(\"dtype(\");\n sub = arraydescr_str(self);\n\tPyString_ConcatAndDel(&s, sub);\n\tsub = PyString_FromString(\")\");\n\tPyString_ConcatAndDel(&s, sub);\n\treturn s;\n}\n\nstatic int\narraydescr_compare(PyArray_Descr *self, PyObject *other)\n{\n \tif (!PyArray_DescrCheck(other)) {\n\t\tPyErr_SetString(PyExc_TypeError,\n\t\t\t\t\"not a dtype object.\");\n\t\treturn -1;\n\t}\n\tif (PyArray_EquivTypes(self, (PyArray_Descr *)other)) return 0;\n\tif (PyArray_CanCastTo(self, (PyArray_Descr *)other)) return -1;\n\treturn 1;\n}\n\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 0, \t /* tp_as_mapping */\n 0,\t\t\t\t\t/* tp_hash */\n 0,\t\t\t\t\t/* tp_call */\n (reprfunc)arraydescr_str, /* tp_str */\n 0,\t \t/* tp_getattro */\n 0,\t\t\t\t\t/* tp_setattro */\n 0,\t\t\t\t\t/* tp_as_buffer */\n Py_TPFLAGS_DEFAULT, /* tp_flags */\n 0,\t\t\t\t\t/* tp_doc */\n 0, \t /* tp_traverse */\n 0,\t\t\t\t\t/* tp_clear */\n 0,\t\t\t\t\t/* tp_richcompare */\n 0,\t\t\t\t\t/* tp_weaklistoffset */\n 0, \t /* tp_iter */\n 0,\t \t/* tp_iternext */\n arraydescr_methods,\t \t /* tp_methods */\n arraydescr_members,\t /* tp_members */\n arraydescr_getsets, /* tp_getset */\n 0,\t\t\t\t\t /* tp_base */\n 0,\t\t\t\t\t /* tp_dict */\n 0,\t\t\t\t\t /* tp_descr_get */\n 0,\t\t\t\t\t /* tp_descr_set */\n 0,\t\t\t\t\t /* tp_dictoffset */\n 0, \t \t /* tp_init */\n 0, \t /* tp_alloc */\n arraydescr_new,\t /* tp_new */\n 0,\t /* tp_free */\n 0,\t\t\t\t\t /* tp_is_gc */\n 0,\t\t\t\t\t /* tp_bases */\n 0,\t\t\t\t\t /* tp_mro */\n 0,\t\t\t\t\t /* tp_cache */\n 0,\t\t\t\t\t /* tp_subclasses */\n 0\t\t\t\t\t /* tp_weaklist */\n};\n", + "source_code_before": "/*\n Provide multidimensional arrays as a basic object type in python. \n\nBased on Original Numeric implementation\nCopyright (c) 1995, 1996, 1997 Jim Hugunin, hugunin@mit.edu\n\nwith contributions from many Numeric Python developers 1995-2004 \n\nHeavily modified in 2005 with inspiration from Numarray \n\nby\n\nTravis Oliphant\nAssistant Professor at\nBrigham Young University \n\nmaintainer email: oliphant.travis@ieee.org\n\nNumarray design (which provided guidance) by \nSpace Science Telescope Institute \n (J. Todd Miller, Perry Greenfield, Rick White)\n*/\n\n/*OBJECT_API\n Get Priority from object\n*/\nstatic double\nPyArray_GetPriority(PyObject *obj, double default_) \n{\n PyObject *ret;\n double priority=PyArray_PRIORITY;\n\n\tif (PyArray_CheckExact(obj))\n\t\treturn priority;\n if (PyBigArray_CheckExact(obj)) \n return PyArray_BIG_PRIORITY;\n\n ret = PyObject_GetAttrString(obj, \"__array_priority__\");\n if (ret != NULL) priority = PyFloat_AsDouble(ret);\n if (PyErr_Occurred()) {\n PyErr_Clear(); \n priority = default_;\n }\n Py_XDECREF(ret);\n return priority; \n}\n\n/* Backward compatibility only */\n/* In both Zero and One\n\n ***You must free the memory once you are done with it\n using PyDataMem_FREE(ptr) or you create a memory leak***\n\n If arr is an Object array you are getting a \n BORROWED reference to Zero or One.\n Do not DECREF.\n Please INCREF if you will be hanging on to it.\n\n The memory for the ptr still must be freed in any case;\n*/\n\n\n/*OBJECT_API\n Get pointer to zero of correct type for array.\n*/\nstatic char *\nPyArray_Zero(PyArrayObject *arr)\n{\n char *zeroval;\n int ret, storeflags;\n PyObject *obj;\n\n zeroval = PyDataMem_NEW(arr->descr->elsize);\n if (zeroval == NULL) {\n PyErr_SetNone(PyExc_MemoryError);\n return NULL;\n }\n\n\tobj=PyInt_FromLong((long) 0);\n if (PyArray_ISOBJECT(arr)) {\n memcpy(zeroval, &obj, sizeof(PyObject *));\n Py_DECREF(obj);\n return zeroval;\n }\n\tstoreflags = arr->flags;\n\tarr->flags |= BEHAVED_FLAGS;\n ret = arr->descr->f->setitem(obj, zeroval, arr);\n\tarr->flags = storeflags;\n\tPy_DECREF(obj);\n\tif (ret < 0) {\n\t\tPyDataMem_FREE(zeroval);\n\t\treturn NULL;\n\t}\n return zeroval;\n}\n\n/*OBJECT_API\n Get pointer to one of correct type for array\n*/\nstatic char *\nPyArray_One(PyArrayObject *arr)\n{\n char *oneval;\n int ret, storeflags;\n PyObject *obj;\n\n oneval = PyDataMem_NEW(arr->descr->elsize);\n if (oneval == NULL) {\n PyErr_SetNone(PyExc_MemoryError);\n return NULL;\n }\n\n obj = PyInt_FromLong((long) 1);\n if (PyArray_ISOBJECT(arr)) {\n memcpy(oneval, &obj, sizeof(PyObject *));\n Py_DECREF(obj);\n return oneval;\n } \n\n\tstoreflags = arr->flags;\n\tarr->flags |= BEHAVED_FLAGS;\n ret = arr->descr->f->setitem(obj, oneval, arr);\n\tarr->flags = storeflags;\n Py_DECREF(obj);\n if (ret < 0) {\n PyDataMem_FREE(oneval);\n return NULL;\n }\n return oneval;\n}\n\n/* End deprecated */\n\n\nstatic int \ndo_sliced_copy(char *dest, intp *dest_strides, intp *dest_dimensions,\n\t int dest_nd, char *src, intp *src_strides, \n\t intp *src_dimensions, int src_nd, int elsize, \n\t int copies) {\n intp i, j;\n\t\n if (src_nd == 0 && dest_nd == 0) {\n for(j=0; j src_nd) {\n for(i=0; i<*dest_dimensions; i++, dest += *dest_strides) {\n if (do_sliced_copy(dest, dest_strides+1, \n dest_dimensions+1, dest_nd-1,\n src, src_strides, \n src_dimensions, src_nd, \n elsize, copies) == -1) \n return -1;\n }\n return 0;\n }\n\t\n if (dest_nd == 1) {\n if (*dest_dimensions != *src_dimensions) {\n PyErr_SetString(PyExc_ValueError, \n \"matrices are not aligned for copy\");\n return -1;\n }\n for(i=0; i<*dest_dimensions; i++, src += *src_strides) {\n for(j=0; j 0) {\n if (((*dest_strides)[*dest_nd-1] == *elsize) && \n ((*src_strides)[*src_nd-1] == *elsize)) {\n if ((*dest_dimensions)[*dest_nd-1] != \n (*src_dimensions)[*src_nd-1]) {\n\t\t\t\tPyErr_SetString(PyExc_ValueError, \n\t\t\t\t\t\t\"matrices are not aligned\");\n return -1;\n }\n *elsize *= (*dest_dimensions)[*dest_nd-1];\n *dest_nd-=1; *src_nd-=1;\n } else {\n break;\n }\n }\n if (*src_nd == 0) {\n while (*dest_nd > 0) {\n if (((*dest_strides)[*dest_nd-1] == *elsize)) {\n *copies *= (*dest_dimensions)[*dest_nd-1];\n *dest_nd-=1;\n } else {\n break;\n }\n }\n }\n return 0;\n}\n\nstatic char *\ncontiguous_data(PyArrayObject *src) \n{\n intp dest_strides[MAX_DIMS], *dest_strides_ptr;\n intp *dest_dimensions=src->dimensions;\n int dest_nd=src->nd;\n intp *src_strides = src->strides;\n intp *src_dimensions=src->dimensions;\n int src_nd=src->nd;\n int elsize=src->descr->elsize;\n int copies=1;\n int ret, i;\n intp stride=elsize;\n char *new_data;\n\t\n for(i=dest_nd-1; i>=0; i--) {\n dest_strides[i] = stride;\n stride *= dest_dimensions[i];\n }\n\t\n dest_strides_ptr = dest_strides;\n\t\n if (optimize_slices(&dest_strides_ptr, &dest_dimensions, &dest_nd,\n &src_strides, &src_dimensions, &src_nd,\n &elsize, &copies) == -1) \n return NULL;\n\t\n new_data = (char *)_pya_malloc(stride);\n\t\n ret = do_sliced_copy(new_data, dest_strides_ptr, dest_dimensions, \n dest_nd, src->data, src_strides, \n src_dimensions, src_nd, elsize, copies);\n\t\n if (ret != -1) { return new_data; }\n else { _pya_free(new_data); return NULL; }\n}\n\n/* end Helper functions */\n\n\nstatic PyObject *PyArray_New(PyTypeObject *, int nd, intp *, \n int, intp *, void *, int, int, PyObject *);\n\n/* C-API functions */\n\n/* Used for arrays of python objects to increment the reference count of */\n/* every python object in the array. */\n/*OBJECT_API\n For object arrays, increment all internal references.\n*/\nstatic int \nPyArray_INCREF(PyArrayObject *mp) \n{\n\tintp i, n;\n\n PyObject **data, **data2;\n\t\n if (mp->descr->type_num != PyArray_OBJECT) return 0;\n\t\n if (PyArray_ISONESEGMENT(mp)) {\n data = (PyObject **)mp->data;\n } else {\n if ((data = (PyObject **)contiguous_data(mp)) == NULL) \n return -1;\n }\n\t\n n = PyArray_SIZE(mp);\n data2 = data;\n for(i=0; idescr->type_num != PyArray_OBJECT) return 0;\n\t\n if (PyArray_ISONESEGMENT(mp)) {\n data = (PyObject **)mp->data;\n } else {\n if ((data = (PyObject **)contiguous_data(mp)) == NULL) \n return -1;\n }\n\t\n n = PyArray_SIZE(mp);\n data2 = data; \n for(i=0; i 0; n--, a += 1) {\n b = a + 1;\n c = *a; *a++ = *b; *b = c;\n }\n break;\n case 4:\n for (a = (char*)p ; n > 0; n--, a += 2) {\n b = a + 3;\n c = *a; *a++ = *b; *b-- = c;\n c = *a; *a++ = *b; *b = c;\n }\n break;\n case 8:\n for (a = (char*)p ; n > 0; n--, a += 4) {\n b = a + 7;\n c = *a; *a++ = *b; *b-- = c;\n c = *a; *a++ = *b; *b-- = c;\n c = *a; *a++ = *b; *b-- = c;\n c = *a; *a++ = *b; *b = c;\n }\n break;\n default:\n m = size / 2;\n for (a = (char *)p ; n > 0; n--, a += m) {\n b = a + (size-1);\n for (j=0; j 1, then dst must be contiguous */\nstatic void\ncopy_and_swap(void *dst, void *src, int itemsize, intp numitems,\n intp srcstrides, int swap) \n{\n int i;\n char *s1 = (char *)src;\n char *d1 = (char *)dst;\n \n\n if ((numitems == 1) || (itemsize == srcstrides)) \n memcpy(d1, s1, itemsize*numitems);\n else { \n for (i = 0; i < numitems; i++) {\n memcpy(d1, s1, itemsize);\n d1 += itemsize;\n s1 += srcstrides;\n } \n }\n\n if (swap)\n byte_swap_vector(d1, numitems, itemsize);\n}\n\nstatic PyArray_Descr **userdescrs=NULL;\n#define error_converting(x) (((x) == -1) && PyErr_Occurred())\n\n/* Computer-generated arraytype and scalartype code */\n#include \"scalartypes.inc\"\n#include \"arraytypes.inc\"\n\n\n/* Helper functions */\n\n/*OBJECT_API*/\nstatic intp\nPyArray_PyIntAsIntp(PyObject *o)\n{\n\tlonglong long_value = -1;\n\tPyObject *obj;\n\tstatic char *msg = \"an integer is required\";\n\tPyObject *arr;\n\tPyArray_Descr *descr;\n\tintp ret;\n\n\tif (!o) {\n\t\tPyErr_SetString(PyExc_TypeError, msg);\n\t\treturn -1;\n\t}\n\n\tif (PyInt_Check(o)) {\n\t\tlong_value = (longlong) PyInt_AS_LONG(o);\n\t\tgoto finish;\n\t} else if (PyLong_Check(o)) {\n\t\tlong_value = (longlong) PyLong_AsLongLong(o);\n\t\tgoto finish;\n\t}\n\n#if SIZEOF_INTP == SIZEOF_LONG \n\tdescr = &LONG_Descr;\n#elif SIZEOF_INTP == SIZEOF_INT\n\tdescr = &INT_Descr;\n#else\n\tdescr = &LONGLONG_DESCR;\n#endif\n\tarr = NULL;\n\n\tif (PyArray_Check(o)) {\n\t\tif (PyArray_SIZE(o)!=1 || !PyArray_ISINTEGER(o)) {\n\t\t\tPyErr_SetString(PyExc_TypeError, msg);\n\t\t\treturn -1;\n\t\t}\n\t\tPy_INCREF(descr);\n\t\tarr = PyArray_CastToType((PyArrayObject *)o, descr, 0);\n\t}\n\telse if (PyArray_IsScalar(o, Integer)) {\n\t\tPy_INCREF(descr);\n\t\tarr = PyArray_FromScalar(o, descr);\n\t}\n\tif (arr != NULL) {\n\t\tret = *((intp *)PyArray_DATA(arr));\n\t\tPy_DECREF(arr);\n\t\treturn ret;\n\t}\t\t\n\tif (o->ob_type->tp_as_number != NULL &&\t\t\t\\\n\t o->ob_type->tp_as_number->nb_long != NULL) {\n\t\tobj = o->ob_type->tp_as_number->nb_long(o);\n\t\tif (obj != NULL) {\n\t\t\tlong_value = (longlong) PyLong_AsLongLong(obj);\n\t\t\tPy_DECREF(obj);\n\t\t}\n\t}\n\telse if (o->ob_type->tp_as_number != NULL &&\t\t\\\n\t\t o->ob_type->tp_as_number->nb_int != NULL) {\n\t\tobj = o->ob_type->tp_as_number->nb_int(o);\n\t\tif (obj != NULL) {\n\t\t\tlong_value = (longlong) PyLong_AsLongLong(obj);\n\t\t\tPy_DECREF(obj);\n\t\t}\n\t}\n\telse {\n\t\tPyErr_SetString(PyExc_NotImplementedError,\"\");\n\t}\n\t\n finish:\n\tif error_converting(long_value) {\n\t\tPyErr_SetString(PyExc_TypeError, msg);\n\t\treturn -1;\n\t}\n\t\n#if (SIZEOF_LONGLONG > SIZEOF_INTP)\n\tif ((long_value < MIN_INTP) || (long_value > MAX_INTP)) {\n\t\tPyErr_SetString(PyExc_ValueError,\n\t\t\t\t\"integer won't fit into a C intp\");\n\t\treturn -1;\n\t}\n#endif\n\treturn (intp) long_value;\n}\n\n\nstatic PyObject *array_int(PyArrayObject *v);\n\n/*OBJECT_API*/\nstatic int\nPyArray_PyIntAsInt(PyObject *o)\n{\n\tlong long_value = -1;\n\tPyObject *obj;\n\tstatic char *msg = \"an integer is required\";\n\tPyObject *arr;\n\tPyArray_Descr *descr;\n\tint ret;\n\n\t\n\tif (!o) {\n\t\tPyErr_SetString(PyExc_TypeError, msg);\n\t\treturn -1;\n\t}\n\n\tif (PyInt_Check(o)) {\n\t\tlong_value = (long) PyInt_AS_LONG(o);\n\t\tgoto finish;\n\t} else if (PyLong_Check(o)) {\n\t\tlong_value = (long) PyLong_AsLong(o);\n\t\tgoto finish;\n\t}\n\n\tdescr = &INT_Descr;\n\tarr=NULL;\n\tif (PyArray_Check(o)) {\n\t\tif (PyArray_SIZE(o)!=1 || !PyArray_ISINTEGER(o)) {\n\t\t\tPyErr_SetString(PyExc_TypeError, msg);\n\t\t\treturn -1;\n\t\t}\n\t\tPy_INCREF(descr);\n\t\tarr = PyArray_CastToType((PyArrayObject *)o, descr, 0);\n\t}\n\tif (PyArray_IsScalar(o, Integer)) {\n\t\tPy_INCREF(descr);\n\t\tarr = PyArray_FromScalar(o, descr);\n\t}\n\tif (arr != NULL) {\n\t\tret = *((int *)PyArray_DATA(arr));\n\t\tPy_DECREF(arr);\n\t\treturn ret;\n\t}\t\t\n\tif (o->ob_type->tp_as_number != NULL &&\t\t\\\n\t o->ob_type->tp_as_number->nb_int != NULL) {\n\t\tobj = o->ob_type->tp_as_number->nb_int(o);\n\t\tif (obj == NULL) return -1;\n\t\tlong_value = (long) PyLong_AsLong(obj);\n\t\tPy_DECREF(obj);\n\t}\n\telse if (o->ob_type->tp_as_number != NULL &&\t\t\t\\\n\t\t o->ob_type->tp_as_number->nb_long != NULL) {\n\t\tobj = o->ob_type->tp_as_number->nb_long(o);\n\t\tif (obj == NULL) return -1;\n\t\tlong_value = (long) PyLong_AsLong(obj);\n\t\tPy_DECREF(obj);\n\t}\t\t\n\telse {\n\t\tPyErr_SetString(PyExc_NotImplementedError,\"\");\n\t}\n\n finish:\n\tif error_converting(long_value) {\n\t\tPyErr_SetString(PyExc_TypeError, msg);\n\t\treturn -1;\n\t}\n\t\n#if (SIZEOF_LONG > SIZEOF_INT)\n\tif ((long_value < INT_MIN) || (long_value > INT_MAX)) {\n\t\tPyErr_SetString(PyExc_ValueError,\n\t\t\t\t\"integer won't fit into a C int\");\n\t\treturn -1;\n\t}\n#endif\n\treturn (int) long_value;\n}\n\nstatic char *\nindex2ptr(PyArrayObject *mp, intp i) \n{\n\tif(mp->nd == 0) {\n\t\tPyErr_SetString(PyExc_IndexError, \n\t\t\t\t\"0-d arrays can't be indexed\");\n\t\treturn NULL;\n\t}\n\tif (i==0 && mp->dimensions[0] > 0)\n\t\treturn mp->data;\n\t\n if (mp->nd>0 && i>0 && i < mp->dimensions[0]) {\n return mp->data+i*mp->strides[0];\n }\n PyErr_SetString(PyExc_IndexError,\"index out of bounds\");\n return NULL;\n}\n\n/*OBJECT_API\n Compute the size of an array (in number of items)\n*/\nstatic intp \nPyArray_Size(PyObject *op) \n{\n if (PyArray_Check(op)) {\n return PyArray_SIZE((PyArrayObject *)op);\n } \n\telse {\n return 0;\n }\n}\n\n/* If destination is not the right type, then src \n will be cast to destination. \n*/\n\n/* Does a flat iterator-based copy. \n\n The arrays are assumed to have the same number of elements\n They can be different sizes and have different types however. \n*/\n\n/*OBJECT_API\n Copy an Array into another array.\n*/\nstatic int\nPyArray_CopyInto(PyArrayObject *dest, PyArrayObject *src)\n{\n intp dsize, ssize, sbytes, ncopies;\n\tint elsize, index;\n PyArrayIterObject *dit=NULL;\n PyArrayIterObject *sit=NULL;\n\tchar *dptr;\n\tint swap;\n PyArray_CopySwapFunc *copyswap;\n PyArray_CopySwapNFunc *copyswapn;\n \n if (!PyArray_ISWRITEABLE(dest)) {\n PyErr_SetString(PyExc_RuntimeError, \n \"cannot write to array\");\n return -1;\n }\n\n if (!PyArray_EquivArrTypes(dest, src)) {\n return PyArray_CastTo(dest, src);\n }\n\n dsize = PyArray_SIZE(dest);\n ssize = PyArray_SIZE(src);\n\tif (ssize == 0) return 0;\n if (dsize % ssize != 0) {\n PyErr_SetString(PyExc_ValueError, \n \"number of elements in destination must be \"\\\n \"integer multiple of number of \"\\\n \"elements in source\");\n return -1;\n }\n ncopies = (dsize / ssize);\n\n\tswap = PyArray_ISNOTSWAPPED(dest) != PyArray_ISNOTSWAPPED(src);\n\tcopyswap = dest->descr->f->copyswap;\n\tcopyswapn = dest->descr->f->copyswapn;\n\n elsize = dest->descr->elsize;\n\n if ((PyArray_ISCONTIGUOUS(dest) && PyArray_ISCONTIGUOUS(src))\t\\\n\t || (PyArray_ISFORTRAN(dest) && PyArray_ISFORTRAN(src))) {\n \n PyArray_XDECREF(dest);\n dptr = dest->data;\n sbytes = ssize * src->descr->elsize;\n while(ncopies--) {\n memmove(dptr, src->data, sbytes);\n dptr += sbytes;\n }\n\t\tif (swap)\n\t\t\tcopyswapn(dest->data, NULL, dsize, 1, elsize);\n PyArray_INCREF(dest);\n return 0;\n }\n\n dit = (PyArrayIterObject *)PyArray_IterNew((PyObject *)dest);\n sit = (PyArrayIterObject *)PyArray_IterNew((PyObject *)src);\n\n if ((dit == NULL) || (sit == NULL)) {\n Py_XDECREF(dit);\n Py_XDECREF(sit);\n return -1;\n }\n\n PyArray_XDECREF(dest);\n while(ncopies--) {\n index = ssize;\n while(index--) {\n memmove(dit->dataptr, sit->dataptr, elsize);\n\t\t\tif (swap)\n\t\t\t\tcopyswap(dit->dataptr, NULL, 1, elsize);\n PyArray_ITER_NEXT(dit);\n PyArray_ITER_NEXT(sit);\n }\n PyArray_ITER_RESET(sit);\n } \n PyArray_INCREF(dest);\n Py_DECREF(dit);\n Py_DECREF(sit);\n\treturn 0;\n}\n\n\nstatic int \nPyArray_CopyObject(PyArrayObject *dest, PyObject *src_object) \n{\n PyArrayObject *src;\n int ret;\n\n\tPy_INCREF(dest->descr);\n src = (PyArrayObject *)PyArray_FromAny(src_object,\n dest->descr, 0,\n dest->nd, FORTRAN_IF(dest), NULL);\n if (src == NULL) return -1;\n\n ret = PyArray_CopyInto(dest, src);\n Py_DECREF(src);\n return ret;\n}\n\n\n/* These are also old calls (should use PyArray_New) */\n\n/* They all zero-out the memory as previously done */\n\n/* steals reference to descr -- and enforces native byteorder on it.*/\n/*OBJECT_API\n Like FromDimsAndData but uses the Descr structure instead of typecode\n as input.\n*/\nstatic PyObject *\nPyArray_FromDimsAndDataAndDescr(int nd, int *d, \n PyArray_Descr *descr,\n char *data)\n{\n\tPyObject *ret;\n#if SIZEOF_INTP != SIZEOF_INT\n\tint i;\n\tintp newd[MAX_DIMS];\n#endif\n\n\tif (!PyArray_ISNBO(descr->byteorder))\n\t\tdescr->byteorder = '=';\n\t\n#if SIZEOF_INTP != SIZEOF_INT\n\tfor (i=0; itype_num != PyArray_OBJECT)) {\n\t\tmemset(PyArray_DATA(ret), 0, PyArray_NBYTES(ret));\n\t}\n\treturn ret;\n}\n\n/* end old calls */\n\n\n/*OBJECT_API\n Copy an array.\n*/\nstatic PyObject *\nPyArray_NewCopy(PyArrayObject *m1, int fortran)\n{\n\tPyArrayObject *ret;\n\tif (fortran < 0) fortran = PyArray_ISFORTRAN(m1);\n\t\n\tPy_INCREF(m1->descr);\n\tret = (PyArrayObject *)PyArray_NewFromDescr(m1->ob_type, \n\t\t\t\t\t\t m1->descr,\n\t\t\t\t\t\t m1->nd, \n\t\t\t\t\t\t m1->dimensions,\n\t\t\t\t\t\t NULL, NULL, \n\t\t\t\t\t\t fortran, \n\t\t\t\t\t\t (PyObject *)m1);\n\tif (ret == NULL) return NULL;\n if (PyArray_CopyInto(ret, m1) == -1) {\n Py_DECREF(ret);\n return NULL;\n }\n\t\n return (PyObject *)ret;\t\n}\n\nstatic PyObject *array_big_item(PyArrayObject *, intp);\n\n/* Does nothing with descr (cannot be NULL) */\n/*OBJECT_API\n Get scalar-equivalent to a region of memory described by a descriptor.\n*/\nstatic PyObject *\nPyArray_Scalar(void *data, PyArray_Descr *descr, PyObject *base)\n{\n\tPyTypeObject *type;\n\tPyObject *obj;\n void *destptr;\n PyArray_CopySwapFunc *copyswap;\n\tint type_num;\n\tint itemsize;\n\tint swap;\n\n\ttype_num = descr->type_num;\n\tif (type_num == PyArray_BOOL)\n\t\tPyArrayScalar_RETURN_BOOL_FROM_LONG(*(Bool*)data);\n\telse if (type_num == PyArray_OBJECT) {\n\t\tPy_INCREF(*((PyObject **)data));\n\t\treturn *((PyObject **)data);\n\t}\n\titemsize = descr->elsize;\n type = descr->typeobj;\n copyswap = descr->f->copyswap;\n\tswap = !PyArray_ISNBO(descr->byteorder);\n\tif (type->tp_itemsize != 0) /* String type */\n\t\tobj = type->tp_alloc(type, itemsize);\n\telse\n\t\tobj = type->tp_alloc(type, 0);\n\tif (obj == NULL) return NULL;\n\tif PyTypeNum_ISEXTENDED(type_num) { \n\t\tif (type_num == PyArray_STRING) {\n\t\t\tdestptr = PyString_AS_STRING(obj);\n\t\t\t((PyStringObject *)obj)->ob_shash = -1;\n\t\t\t((PyStringObject *)obj)->ob_sstate =\t\\\n\t\t\t\tSSTATE_NOT_INTERNED; \n\t\t}\n\t\telse if (type_num == PyArray_UNICODE) {\n\t\t\tPyUnicodeObject *uni = (PyUnicodeObject*)obj;\n\t\t\tint length = itemsize / sizeof(Py_UNICODE);\n\t\t\t/* Need an extra slot and need to use \n\t\t\t Python memory manager */\n\t\t\tuni->str = NULL;\n\t\t\tdestptr = PyMem_NEW(Py_UNICODE, length+1);\n\t\t\tif (destptr == NULL) {\n Py_DECREF(obj);\n\t\t\t\treturn PyErr_NoMemory();\n\t\t\t}\n\t\t\tuni->str = (Py_UNICODE *)destptr;\n\t\t\tuni->str[0] = 0;\n\t\t\tuni->str[length] = 0;\n\t\t\tuni->length = length;\n\t\t\tuni->hash = -1;\n\t\t\tuni->defenc = NULL;\n\t\t}\n\t\telse { \n\t\t\tPyVoidScalarObject *vobj = (PyVoidScalarObject *)obj;\n\t\t\tvobj->base = NULL;\n\t\t\tvobj->descr = descr;\n\t\t\tPy_INCREF(descr);\n\t\t\tvobj->obval = NULL;\n\t\t\tvobj->ob_size = itemsize;\n\t\t\tvobj->flags = BEHAVED_FLAGS | OWNDATA;\n\t\t\tswap = 0;\n\t\t\tif (descr->fields) {\n\t\t\t\tif (base) {\n\t\t\t\t\tPy_INCREF(base);\n\t\t\t\t\tvobj->base = base;\n\t\t\t\t\tvobj->flags = PyArray_FLAGS(base);\n\t\t\t\t\tvobj->flags &= ~OWNDATA;\n\t\t\t\t\tvobj->obval = data;\n\t\t\t\t\treturn obj;\n\t\t\t\t}\n\t\t\t}\n\t\t\tdestptr = PyDataMem_NEW(itemsize);\n\t\t\tif (destptr == NULL) {\n Py_DECREF(obj);\n\t\t\t\treturn PyErr_NoMemory();\n\t\t\t}\n\t\t\tvobj->obval = destptr;\n\t\t}\n\t}\n\telse {\n\t\tdestptr = _SOFFSET_(obj, type_num);\n\t}\n\t/* copyswap for OBJECT increments the reference count */\n copyswap(destptr, data, swap, itemsize);\n\treturn obj;\n}\n\n/* returns an Array-Scalar Object of the type of arr\n from the given pointer to memory -- main Scalar creation function\n default new method calls this. \n*/\n\n/* Ideally, here the descriptor would contain all the information needed.\n So, that we simply need the data and the descriptor, and perhaps\n a flag \n*/\n\n/*OBJECT_API\n Get scalar-equivalent to 0-d array\n*/\nstatic PyObject *\nPyArray_ToScalar(void *data, PyArrayObject *arr)\n{\n\treturn PyArray_Scalar(data, arr->descr, (PyObject *)arr);\n}\n\n\n/* Return Python scalar if 0-d array object is encountered */\n\n/*OBJECT_API\n Return either an array or the appropriate Python object if the array\n is 0d and matches a Python type.\n*/\nstatic PyObject *\nPyArray_Return(PyArrayObject *mp) \n{\n \n\n\tif (mp == NULL) return NULL;\n\n if (PyErr_Occurred()) {\n Py_XDECREF(mp);\n return NULL;\n }\n\n\tif (!PyArray_Check(mp)) return (PyObject *)mp;\n\t\n\tif (mp->nd == 0) {\n\t\tPyObject *ret;\n\t\tret = PyArray_ToScalar(mp->data, mp);\n\t\tPy_DECREF(mp);\n\t\treturn ret;\n\t}\n\telse {\n\t\treturn (PyObject *)mp;\n\t}\n}\n\n/*\n returns typenum to associate with this type >=PyArray_USERDEF.\n Also creates a copy of the VOID_DESCR table inserting it's typeobject in\n and it's typenum in the appropriate place.\n \n needs the userdecrs table and PyArray_NUMUSER variables\n defined in arratypes.inc\n*/\n/*OBJECT_API\n Register Data type\n*/\nstatic int \nPyArray_RegisterDataType(PyTypeObject *type)\n{\n\tPyArray_Descr *descr;\n\tPyObject *obj;\n\tint typenum;\n\tint i;\n\t\n\tif ((type == &PyVoidArrType_Type) ||\t\t\t\\\n\t !PyType_IsSubtype(type, &PyVoidArrType_Type)) {\n\t\tPyErr_SetString(PyExc_ValueError, \n\t\t\t\t\"can only register void subtypes\");\n\t\treturn -1;\n\t}\n\t/* See if this type is already registered */\n\tfor (i=0; itypeobj == type)\n\t\t\treturn descr->type_num;\n\t}\n\tdescr = PyArray_DescrNewFromType(PyArray_VOID);\n\ttypenum = PyArray_USERDEF + PyArray_NUMUSERTYPES;\n\tdescr->type_num = typenum;\n descr->typeobj = type;\n\tobj = PyObject_GetAttrString((PyObject *)type,\"itemsize\");\n\tif (obj) {\n\t\ti = PyInt_AsLong(obj);\n\t\tif ((i < 0) && (PyErr_Occurred())) PyErr_Clear();\n\t\telse descr->elsize = i;\n\t\tPy_DECREF(obj);\n\t}\n\tPy_INCREF(type);\n\tuserdescrs = realloc(userdescrs, \n\t\t\t (PyArray_NUMUSERTYPES+1)*sizeof(void *));\n if (userdescrs == NULL) {\n PyErr_SetString(PyExc_MemoryError, \"RegisterDataType\");\n\t\tPy_DECREF(descr);\n return -1;\n }\n\tuserdescrs[PyArray_NUMUSERTYPES++] = descr;\n\treturn typenum;\n}\n\n\n/* \n copyies over from the old descr table for anything\n NULL or zero in what is given. \n DECREF's the Descr already there.\n places a pointer to the new one into the slot.\n*/\n\n/* steals a reference to descr */\n/*OBJECT_API\n Insert Descr Table\n*/\nstatic int\nPyArray_RegisterDescrForType(int typenum, PyArray_Descr *descr)\n{\n\tPyArray_Descr *old;\n\n\tif (!PyTypeNum_ISUSERDEF(typenum)) {\n\t\tPyErr_SetString(PyExc_TypeError, \n\t\t\t\t\"data type not registered\");\n\t\tPy_DECREF(descr);\n\t\treturn -1;\n\t}\n\told = userdescrs[typenum-PyArray_USERDEF];\n\tdescr->typeobj = old->typeobj;\n\tdescr->type_num = typenum;\n\n\tif (descr->f == NULL) descr->f = old->f;\n\tif (descr->fields == NULL) {\n\t\tdescr->fields = old->fields;\n\t\tPy_XINCREF(descr->fields);\n\t}\n\tif (descr->subarray == NULL && old->subarray) {\n\t\tdescr->subarray = _pya_malloc(sizeof(PyArray_ArrayDescr));\n\t\tmemcpy(descr->subarray, old->subarray, \n\t\t sizeof(PyArray_ArrayDescr));\n\t\tPy_INCREF(descr->subarray->shape);\n\t\tPy_INCREF(descr->subarray->base);\n\t}\n Py_XINCREF(descr->typeobj);\n\n#define _ZERO_CHECK(member) \\\n\tif (descr->member == 0) descr->member = old->member\n\n\t_ZERO_CHECK(kind);\n\t_ZERO_CHECK(type);\n _ZERO_CHECK(byteorder);\n\t_ZERO_CHECK(elsize);\n\t_ZERO_CHECK(alignment);\n#undef _ZERO_CHECK\n\n\tPy_DECREF(old);\n\tuserdescrs[typenum-PyArray_USERDEF] = descr;\n\treturn 0;\n}\n\n\n/*OBJECT_API\n To File\n*/\nstatic int\nPyArray_ToFile(PyArrayObject *self, FILE *fp, char *sep, char *format) \n{\n intp size;\n intp n, n2;\n int n3, n4;\n PyArrayIterObject *it;\n PyObject *obj, *strobj, *tupobj;\n\n\tn3 = (sep ? strlen((const char *)sep) : 0);\n\tif (n3 == 0) { /* binary data */\n if (PyArray_ISOBJECT(self)) {\n PyErr_SetString(PyExc_ValueError, \"cannot write \"\\\n\t\t\t\t\t\"object arrays to a file in \"\t\\\n\t\t\t\t\t\"binary mode\");\n return -1;\n }\n\n if (PyArray_ISCONTIGUOUS(self)) {\n size = PyArray_SIZE(self);\n if ((n=fwrite((const void *)self->data, \n (size_t) self->descr->elsize,\n (size_t) size, fp)) < size) {\n PyErr_Format(PyExc_ValueError, \n \"%ld requested and %ld written\",\n (long) size, (long) n);\n return -1;\n }\n }\n else {\n it=(PyArrayIterObject *) \\\n PyArray_IterNew((PyObject *)self);\n while(it->index < it->size) {\n if (fwrite((const void *)it->dataptr, \n (size_t) self->descr->elsize,\n 1, fp) < 1) {\n PyErr_Format(PyExc_IOError, \n \"problem writing element\"\\\n \" %d to file\", \n\t\t\t\t\t\t (int)it->index);\n Py_DECREF(it);\n return -1;\n }\n PyArray_ITER_NEXT(it);\n }\n Py_DECREF(it);\n } \n }\n else { /* text data */\n it=(PyArrayIterObject *) \\\n PyArray_IterNew((PyObject *)self);\n\t\tn4 = (format ? strlen((const char *)format) : 0);\n while(it->index < it->size) {\n obj = self->descr->f->getitem(it->dataptr, self);\n if (obj == NULL) {Py_DECREF(it); return -1;}\n\t\t\tif (n4 == 0) { /* standard writing */\n\t\t\t\tstrobj = PyObject_Str(obj);\n\t\t\t\tPy_DECREF(obj);\n\t\t\t\tif (strobj == NULL) {Py_DECREF(it); return -1;}\n\t\t\t}\n\t\t\telse { /* use format string */\n\t\t\t\ttupobj = PyTuple_New(1);\n\t\t\t\tif (tupobj == NULL) {Py_DECREF(it); return -1;}\n\t\t\t\tPyTuple_SET_ITEM(tupobj,0,obj);\n\t\t\t\tobj = PyString_FromString((const char *)format);\n\t\t\t\tif (obj == NULL) {Py_DECREF(tupobj); \n\t\t\t\t\tPy_DECREF(it); return -1;}\n\t\t\t\tstrobj = PyString_Format(obj, tupobj);\n\t\t\t\tPy_DECREF(obj);\n\t\t\t\tPy_DECREF(tupobj);\n\t\t\t\tif (strobj == NULL) {Py_DECREF(it); return -1;}\n\t\t\t}\n if ((n=fwrite(PyString_AS_STRING(strobj), \n 1, n2=PyString_GET_SIZE(strobj),\n fp)) < n2) {\n PyErr_Format(PyExc_IOError,\n \"problem writing element %d\"\\\n \" to file\", \n\t\t\t\t\t (int) it->index);\n Py_DECREF(strobj);\n Py_DECREF(it);\n return -1;\n }\n /* write separator for all but last one */\n if (it->index != it->size-1) \n fwrite(sep, 1, n3, fp);\n Py_DECREF(strobj);\n PyArray_ITER_NEXT(it);\n }\n Py_DECREF(it);\n }\n return 0;\n}\n\n/*OBJECT_API\n To List\n*/\nstatic PyObject *\nPyArray_ToList(PyArrayObject *self) \n{\n PyObject *lp;\n PyArrayObject *v;\n intp sz, i;\n\t\n if (!PyArray_Check(self)) return (PyObject *)self;\n\n if (self->nd == 0) \n\t\treturn self->descr->f->getitem(self->data,self);\n\t\n sz = self->dimensions[0];\n lp = PyList_New(sz);\n\t\n for (i=0; ind >= self->nd) {\n\t\t\tPyErr_SetString(PyExc_RuntimeError,\n\t\t\t\t\t\"array_item not returning smaller-\" \\\n\t\t\t\t\t\"dimensional array\");\n Py_DECREF(v);\n\t\t\tPy_DECREF(lp);\n\t\t\treturn NULL;\n\t\t}\n PyList_SetItem(lp, i, PyArray_ToList(v));\n\t\tPy_DECREF(v);\n }\n\t\n return lp;\n}\n\nstatic PyObject *\nPyArray_ToString(PyArrayObject *self)\n{\n intp numbytes;\n intp index;\n char *dptr;\n int elsize;\n PyObject *ret;\n PyArrayIterObject *it;\n \n\t/* if (PyArray_TYPE(self) == PyArray_OBJECT) {\n\t\t PyErr_SetString(PyExc_ValueError, \"a string for the data\" \\\n\t\t \"in an object array is not appropriate\");\n\t\t return NULL;\n\t\t }\n\t*/\n\n numbytes = PyArray_NBYTES(self);\n if (PyArray_ISONESEGMENT(self)) {\n ret = PyString_FromStringAndSize(self->data, (int) numbytes);\n }\n else {\n it = (PyArrayIterObject *)PyArray_IterNew((PyObject *)self);\n if (it==NULL) return NULL;\n ret = PyString_FromStringAndSize(NULL, (int) numbytes);\n if (ret == NULL) {Py_DECREF(it); return NULL;}\n dptr = PyString_AS_STRING(ret);\n index = it->size;\n elsize = self->descr->elsize;\n while(index--) {\n memcpy(dptr, it->dataptr, elsize);\n dptr += elsize;\n PyArray_ITER_NEXT(it);\n }\n Py_DECREF(it);\n }\n\treturn ret;\n}\n\n\n/*********************** end C-API functions **********************/\n\n\n/* array object functions */\n\nstatic void \narray_dealloc(PyArrayObject *self) {\n\n if (self->weakreflist != NULL)\n PyObject_ClearWeakRefs((PyObject *)self);\n\n if(self->base) {\n\t\t/* UPDATEIFCOPY means that base points to an \n\t\t array that should be updated with the contents\n\t\t of this array upon destruction.\n self->base->flags must have been WRITEABLE \n (checked previously) and it was locked here\n thus, unlock it.\n\t\t*/\n\t\tif (self->flags & UPDATEIFCOPY) {\n ((PyArrayObject *)self->base)->flags |= WRITEABLE;\n\t\t\tPy_INCREF(self); /* hold on to self in next call */\n PyArray_CopyInto((PyArrayObject *)self->base, self);\n\t\t\t/* Don't need to DECREF -- because we are deleting\n\t\t\t self already... */\n\t\t}\n\t\t/* In any case base is pointing to something that we need\n\t\t to DECREF -- either a view or a buffer object */\n Py_DECREF(self->base);\n }\n \n if ((self->flags & OWN_DATA) && self->data) {\n\t\t/* Free internal references if an Object array */\n\t\tif (PyArray_ISOBJECT(self))\n\t\t\tPyArray_XDECREF(self);\n PyDataMem_FREE(self->data);\n }\n\t\n\tPyDimMem_FREE(self->dimensions);\n\n\tPy_DECREF(self->descr);\n\t\n self->ob_type->tp_free((PyObject *)self);\n}\n\n/*************************************************************************\n **************** Implement Mapping Protocol ***************************\n *************************************************************************/\n\nstatic int \narray_length(PyArrayObject *self) \n{\n if (self->nd != 0) {\n return self->dimensions[0];\n } else {\n\t\tPyErr_SetString(PyExc_TypeError, \"len() of unsized object\");\n\t\treturn -1;\n }\n}\n\nstatic PyObject *\narray_big_item(PyArrayObject *self, intp i) \n{\n\tchar *item;\n\tPyArrayObject *r;\n\t\t\n\tif(self->nd == 0) {\n\t\tPyErr_SetString(PyExc_IndexError, \n\t\t\t\t\"0-d arrays can't be indexed\");\n\t\treturn NULL;\n\t}\n if ((item = index2ptr(self, i)) == NULL) return NULL;\n\t\n\tPy_INCREF(self->descr);\n\tr = (PyArrayObject *)PyArray_NewFromDescr(self->ob_type, \n\t\t\t\t\t\t self->descr,\n\t\t\t\t\t\t self->nd-1, \n\t\t\t\t\t\t self->dimensions+1, \n\t\t\t\t\t\t self->strides+1, item, \n\t\t\t\t\t\t self->flags,\n\t\t\t\t\t\t (PyObject *)self);\n\tif (r == NULL) return NULL;\n\tPy_INCREF(self);\n\tr->base = (PyObject *)self;\n PyArray_UpdateFlags(r, CONTIGUOUS | FORTRAN);\n\treturn (PyObject *)r;\n}\n\nstatic PyObject *\narray_item_nice(PyArrayObject *self, int i) \n{\n\treturn PyArray_Return((PyArrayObject *)array_big_item(self, (intp) i));\n}\n\n\nstatic int \narray_ass_big_item(PyArrayObject *self, intp i, PyObject *v) \n{\n PyArrayObject *tmp;\n char *item;\n int ret;\n\n if (v == NULL) {\n PyErr_SetString(PyExc_ValueError, \n \"can't delete array elements\");\n return -1;\n }\n\tif (!PyArray_ISWRITEABLE(self)) {\n\t\tPyErr_SetString(PyExc_RuntimeError,\n\t\t\t\t\"array is not writeable\");\n\t\treturn -1;\n\t}\n if (self->nd == 0) {\n PyErr_SetString(PyExc_IndexError, \n \"0-d arrays can't be indexed.\");\n return -1;\n }\n\n if (i < 0) i = i+self->dimensions[0];\n\n if (self->nd > 1) {\n if((tmp = (PyArrayObject *)array_big_item(self, i)) == NULL)\n return -1;\n ret = PyArray_CopyObject(tmp, v);\n Py_DECREF(tmp);\n return ret; \n }\n\t\n if ((item = index2ptr(self, i)) == NULL) return -1;\n if (self->descr->f->setitem(v, item, self) == -1) return -1;\n return 0;\n}\n\n#if SIZEOF_INT == SIZEOF_INTP\n#define array_ass_item array_ass_big_item\n#else\nstatic int\narray_ass_item(PyArrayObject *self, int i, PyObject *v)\n{\n\treturn array_ass_big_item(self, (intp) i, v);\n}\n#endif\n\n\n/* -------------------------------------------------------------- */\nstatic int\nslice_coerce_index(PyObject *o, intp *v)\n{\n\t*v = PyArray_PyIntAsIntp(o);\n\tif (error_converting(*v)) {\n\t\tPyErr_Clear();\n\t\treturn 0;\n\t}\n\treturn 1;\n}\n\n\n/* This is basically PySlice_GetIndicesEx, but with our coercion\n * of indices to integers (plus, that function is new in Python 2.3) */\nstatic int\nslice_GetIndices(PySliceObject *r, intp length,\n intp *start, intp *stop, intp *step,\n intp *slicelength)\n{\n\tintp defstart, defstop;\n\t\n\tif (r->step == Py_None) {\n\t\t*step = 1;\n\t} else {\n\t\tif (!slice_coerce_index(r->step, step)) return -1;\n\t\tif (*step == 0) {\n\t\t\tPyErr_SetString(PyExc_ValueError, \n\t\t\t\t\t\"slice step cannot be zero\");\n\t\t\treturn -1;\n\t\t}\n\t}\n\t\n\tdefstart = *step < 0 ? length - 1 : 0;\n\tdefstop = *step < 0 ? -1 : length;\n\t\n\tif (r->start == Py_None) {\n\t\t*start = *step < 0 ? length-1 : 0;\n\t} else {\n\t\tif (!slice_coerce_index(r->start, start)) return -1;\n\t\tif (*start < 0) *start += length;\n\t\tif (*start < 0) *start = (*step < 0) ? -1 : 0;\n\t\tif (*start >= length) {\n\t\t\t*start = (*step < 0) ? length - 1 : length;\n\t\t}\n\t}\n\t\n\tif (r->stop == Py_None) {\n\t\t*stop = defstop;\n\t} else {\n\t\tif (!slice_coerce_index(r->stop, stop)) return -1;\n\t\tif (*stop < 0) *stop += length;\n if (*stop < 0) *stop = -1;\n if (*stop > length) *stop = length;\n\t}\n\t\n\tif ((*step < 0 && *stop >= *start) || \\\n\t (*step > 0 && *start >= *stop)) {\n\t\t*slicelength = 0;\n\t} else if (*step < 0) {\n\t\t*slicelength = (*stop - *start + 1) / (*step) + 1;\n\t} else {\n\t\t*slicelength = (*stop - *start - 1) / (*step) + 1;\n\t}\n\t\n\treturn 0;\n}\n\n#define PseudoIndex -1\n#define RubberIndex -2\n#define SingleIndex -3\n\nstatic intp\nparse_subindex(PyObject *op, intp *step_size, intp *n_steps, intp max)\n{\n\tintp index;\n\t\n\tif (op == Py_None) {\n\t\t*n_steps = PseudoIndex;\n\t\tindex = 0;\n\t} else if (op == Py_Ellipsis) {\n\t\t*n_steps = RubberIndex;\n\t\tindex = 0;\n\t} else if (PySlice_Check(op)) {\n\t\tintp stop;\n\t\tif (slice_GetIndices((PySliceObject *)op, max,\n\t\t\t\t &index, &stop, step_size, n_steps) < 0) {\n\t\t\tif (!PyErr_Occurred()) {\n\t\t\t\tPyErr_SetString(PyExc_IndexError, \n\t\t\t\t\t\t\"invalid slice\");\n\t\t\t}\n\t\t\tgoto fail;\n\t\t}\n\t\tif (*n_steps <= 0) {\n\t\t\t*n_steps = 0;\n\t\t\t*step_size = 1;\n\t\t\tindex = 0;\n\t\t}\n\t} else {\n\t\tindex = PyArray_PyIntAsIntp(op);\n\t\tif (error_converting(index)) {\n\t\t\tPyErr_SetString(PyExc_IndexError,\n\t\t\t\t\t\"each subindex must be either a \"\\\n\t\t\t\t\t\"slice, an integer, Ellipsis, or \"\\\n\t\t\t\t\t\"newaxis\");\n\t\t\tgoto fail;\n\t\t}\n\t\t*n_steps = SingleIndex;\n\t\t*step_size = 0;\n\t\tif (index < 0) index += max;\n\t\tif (index >= max || index < 0) {\n\t\t\tPyErr_SetString(PyExc_IndexError, \"invalid index\");\n\t\t\tgoto fail;\n\t\t}\n\t}\n\treturn index;\n fail:\n\treturn -1;\n}\n\n\nstatic int \nparse_index(PyArrayObject *self, PyObject *op, \n intp *dimensions, intp *strides, intp *offset_ptr)\n{\n int i, j, n;\n int nd_old, nd_new, n_add, n_pseudo;\n\tintp n_steps, start, offset, step_size;\n PyObject *op1=NULL;\n int is_slice;\n\n\n if (PySlice_Check(op) || op == Py_Ellipsis || op == Py_None) {\n n = 1;\n op1 = op;\n Py_INCREF(op);\t\n /* this relies on the fact that n==1 for loop below */\n is_slice = 1;\n }\n else {\n if (!PySequence_Check(op)) {\n PyErr_SetString(PyExc_IndexError, \n \"index must be either an int \"\\\n \"or a sequence\");\n return -1;\n }\n n = PySequence_Length(op);\n is_slice = 0;\n }\n\t\n nd_old = nd_new = 0;\n\t\n offset = 0;\n for(i=0; ind ? \\\n self->dimensions[nd_old] : 0);\n Py_DECREF(op1);\n if (start == -1) break;\n\t\t\n if (n_steps == PseudoIndex) {\n dimensions[nd_new] = 1; strides[nd_new] = 0; nd_new++;\n } else {\n if (n_steps == RubberIndex) {\n for(j=i+1, n_pseudo=0; jnd-(n-i-n_pseudo-1+nd_old);\n if (n_add < 0) {\n PyErr_SetString(PyExc_IndexError, \n \"too many indices\");\n return -1;\n }\n for(j=0; jdimensions[nd_old];\n strides[nd_new] = \\\n self->strides[nd_old];\n nd_new++; nd_old++;\n }\n } else {\n if (nd_old >= self->nd) {\n PyErr_SetString(PyExc_IndexError, \n \"too many indices\");\n return -1;\n }\n offset += self->strides[nd_old]*start;\n nd_old++;\n if (n_steps != SingleIndex) {\n dimensions[nd_new] = n_steps;\n strides[nd_new] = step_size * \\\n self->strides[nd_old-1];\n nd_new++;\n }\n }\n }\n }\n if (i < n) return -1;\n n_add = self->nd-nd_old;\n for(j=0; jdimensions[nd_old];\n strides[nd_new] = self->strides[nd_old];\n nd_new++; nd_old++;\n }\t \n *offset_ptr = offset;\n return nd_new;\n}\n\nstatic void\n_swap_axes(PyArrayMapIterObject *mit, PyArrayObject **ret)\n{\n\tPyObject *new;\n\tint n1, n2, n3, val;\n\tint i;\n\tPyArray_Dims permute;\n\tintp d[MAX_DIMS];\n\n\tpermute.ptr = d;\n\tpermute.len = mit->nd;\n\n\t/* tuple for transpose is \n\t (n1,..,n1+n2-1,0,..,n1-1,n1+n2,...,n3-1)\n\t n1 is the number of dimensions of \n\t the broadcasted index array \n\t n2 is the number of dimensions skipped at the\n\t start\n\t n3 is the number of dimensions of the \n\t result \n\t*/\n\tn1 = mit->iters[0]->nd_m1 + 1;\n\tn2 = mit->iteraxes[0];\n\tn3 = mit->nd;\n\tval = n1;\n\ti = 0;\n\twhile(val < n1+n2) \n\t\tpermute.ptr[i++] = val++;\n\tval = 0;\n\twhile(val < n1)\n\t\tpermute.ptr[i++] = val++;\n\tval = n1+n2;\n\twhile(val < n3)\n\t\tpermute.ptr[i++] = val++;\n\n\tnew = PyArray_Transpose(*ret, &permute);\n\tPy_DECREF(*ret);\n\t*ret = (PyArrayObject *)new;\n}\n\n/* Prototypes for Mapping calls --- not part of the C-API\n because only useful as part of a getitem call. \n*/\n\nstatic void PyArray_MapIterReset(PyArrayMapIterObject *);\nstatic void PyArray_MapIterNext(PyArrayMapIterObject *);\nstatic void PyArray_MapIterBind(PyArrayMapIterObject *, PyArrayObject *);\nstatic PyObject* PyArray_MapIterNew(PyObject *, int, int);\n\nstatic PyObject *\nPyArray_GetMap(PyArrayMapIterObject *mit)\n{\n\n\tPyArrayObject *ret, *temp;\n\tPyArrayIterObject *it;\n\tint index;\n\tint swap;\n PyArray_CopySwapFunc *copyswap;\n\n\t/* Unbound map iterator --- Bind should have been called */\n\tif (mit->ait == NULL) return NULL;\n\n\t/* This relies on the map iterator object telling us the shape\n\t of the new array in nd and dimensions.\n\t*/\n\ttemp = mit->ait->ao;\n\tPy_INCREF(temp->descr);\n\tret = (PyArrayObject *)\\\n\t\tPyArray_NewFromDescr(temp->ob_type, \n\t\t\t\t temp->descr,\n\t\t\t\t mit->nd, mit->dimensions, \n\t\t\t\t NULL, NULL, \n\t\t\t\t PyArray_ISFORTRAN(temp),\n\t\t\t\t (PyObject *)temp);\n\tif (ret == NULL) return NULL;\n\n\t/* Now just iterate through the new array filling it in\n\t with the next object from the original array as\n\t defined by the mapping iterator */\n\n\tif ((it = (PyArrayIterObject *)PyArray_IterNew((PyObject *)ret)) \n\t == NULL) {\n\t\tPy_DECREF(ret);\n\t\treturn NULL;\n\t}\n\tindex = it->size;\n\tswap = (PyArray_ISNOTSWAPPED(temp) != PyArray_ISNOTSWAPPED(ret));\n copyswap = ret->descr->f->copyswap;\n\tPyArray_MapIterReset(mit);\n\twhile (index--) {\n copyswap(it->dataptr, mit->dataptr, swap, ret->descr->elsize);\n\t\tPyArray_MapIterNext(mit);\n\t\tPyArray_ITER_NEXT(it);\n\t}\n\tPy_DECREF(it);\n\t\n\t/* check for consecutive axes */\n\tif ((mit->subspace != NULL) && (mit->consec)) {\n\t\tif (mit->iteraxes[0] > 0) { /* then we need to swap */\n\t\t\t_swap_axes(mit, &ret);\n\t\t}\n\t}\n\treturn (PyObject *)ret;\n}\n\nstatic int\nPyArray_SetMap(PyArrayMapIterObject *mit, PyObject *op)\n{\n\tPyObject *arr=NULL;\n\tPyArrayIterObject *it;\n\tint index;\n\tint swap;\n PyArray_CopySwapFunc *copyswap;\n\tPyArray_Descr *descr;\n\n\t/* Unbound Map Iterator */\n\tif (mit->ait == NULL) return -1;\n\n\tdescr = mit->ait->ao->descr;\n\tPy_INCREF(descr);\n\tarr = PyArray_FromAny(op, descr, 0, 0, FORCECAST, NULL);\n\tif (arr == NULL) return -1;\n\n\tif ((mit->subspace != NULL) && (mit->consec)) {\n\t\tif (mit->iteraxes[0] > 0) { /* then we need to swap */\n\t\t\t_swap_axes(mit, (PyArrayObject **)&arr);\n\t\t}\n\t}\n\t\n\tif ((it = (PyArrayIterObject *)PyArray_IterNew(arr))==NULL) {\n\t\tPy_DECREF(arr);\n\t\treturn -1;\n\t}\n\n\tindex = mit->size;\n\tswap = (PyArray_ISNOTSWAPPED(mit->ait->ao) != \\\n\t\t(PyArray_ISNOTSWAPPED(arr)));\n\n copyswap = PyArray_DESCR(arr)->f->copyswap;\n\tPyArray_MapIterReset(mit);\n /* Need to decref OBJECT arrays */\n if (PyTypeNum_ISOBJECT(descr->type_num)) {\n while (index--) {\n Py_XDECREF(*((PyObject **)mit->dataptr));\n Py_INCREF(*((PyObject **)it->dataptr));\n memmove(mit->dataptr, it->dataptr, sizeof(PyObject *));\n PyArray_MapIterNext(mit);\n PyArray_ITER_NEXT(it);\n if (it->index == it->size)\n PyArray_ITER_RESET(it);\n }\n\t\tPy_DECREF(arr);\n\t\tPy_DECREF(it);\n return 0;\n }\n\twhile(index--) {\n\t\tmemmove(mit->dataptr, it->dataptr, PyArray_ITEMSIZE(arr));\n copyswap(mit->dataptr, NULL, swap, PyArray_ITEMSIZE(arr));\n\t\tPyArray_MapIterNext(mit);\n\t\tPyArray_ITER_NEXT(it);\n\t\tif (it->index == it->size)\n\t\t\tPyArray_ITER_RESET(it);\n\t}\t\t\n\tPy_DECREF(arr);\n\tPy_DECREF(it);\n\treturn 0;\n}\n\nint\ncount_new_axes_0d(PyObject *tuple)\n{\n\tint i, argument_count;\n\tint ellipsis_count = 0;\n\tint newaxis_count = 0;\n\t\n\targument_count = PyTuple_GET_SIZE(tuple);\n\n\tfor (i = 0; i < argument_count; ++i) {\n\t\tPyObject *arg = PyTuple_GET_ITEM(tuple, i);\n\t\tif (arg == Py_Ellipsis && !ellipsis_count) ellipsis_count++;\n\t\telse if (arg == Py_None) newaxis_count++;\n\t\telse break;\n\t}\n\tif (i < argument_count) {\n\t\tPyErr_SetString(PyExc_IndexError,\n\t\t\t\t\"0-d arrays can only use a single ()\"\n\t\t\t\t\" or a list of newaxes (and a single ...)\"\n\t\t\t\t\" as an index\");\n\t\treturn -1;\n\t}\n\tif (newaxis_count > MAX_DIMS) {\n\t\tPyErr_SetString(PyExc_IndexError,\n\t\t\t\t\"too many dimensions\");\n\t\treturn -1;\n\t}\n\treturn newaxis_count;\n}\n\nstatic PyObject *\nadd_new_axes_0d(PyArrayObject *arr, int newaxis_count)\n{\n\tPyArrayObject *other;\n\tintp dimensions[MAX_DIMS]; \n\tint i;\n\tfor (i = 0; i < newaxis_count; ++i) {\n\t\tdimensions[i] = 1;\n\t}\n\tPy_INCREF(arr->descr);\n\tif ((other = (PyArrayObject *)\n\t PyArray_NewFromDescr(arr->ob_type, arr->descr,\n\t\t\t\t newaxis_count, dimensions,\n\t\t\t\t NULL, arr->data,\n\t\t\t\t arr->flags,\n\t\t\t\t (PyObject *)arr)) == NULL) \n\t\treturn NULL;\n\tother->base = (PyObject *)arr;\n\tPy_INCREF(arr);\n\treturn (PyObject *)other;\n}\n\n\n/* This checks the args for any fancy indexing objects */\n\n#define SOBJ_NOTFANCY 0 \n#define SOBJ_ISFANCY 1\n#define SOBJ_BADARRAY 2\n#define SOBJ_TOOMANY 3\n#define SOBJ_LISTTUP 4\n\nstatic int\nfancy_indexing_check(PyObject *args)\n{\n\tint i, n;\n\tPyObject *obj;\n\tint retval = SOBJ_NOTFANCY;\n\n\tif (PyTuple_Check(args)) {\n\t\tn = PyTuple_GET_SIZE(args);\n\t\tif (n >= MAX_DIMS) return SOBJ_TOOMANY;\n\t\tfor (i=0; i=MAX_DIMS) return SOBJ_ISFANCY;\n\t\tfor (i=0; i SOBJ_ISFANCY) return retval;\n\t\t}\n\t}\n\n\treturn retval;\n}\n\n/* Called when treating array object like a mapping -- called first from \n Python when using a[object] unless object is a standard slice object\n (not an extended one). \n\n*/\n\n/* There are two situations: \n\n 1 - the subscript is a standard view and a reference to the \n array can be returned\n\n 2 - the subscript uses Boolean masks or integer indexing and\n therefore a new array is created and returned. \n\n*/\n\n/* Always returns arrays */\n\nstatic PyObject *iter_subscript(PyArrayIterObject *, PyObject *); \n\n\nstatic PyObject *\narray_subscript(PyArrayObject *self, PyObject *op) \n{\n intp dimensions[MAX_DIMS], strides[MAX_DIMS];\n\tintp offset;\n int nd, oned, fancy;\n\tintp i;\n PyArrayObject *other;\n\tPyArrayMapIterObject *mit;\n\n\tif (PyString_Check(op) || PyUnicode_Check(op)) {\n\t\tif (self->descr->fields) {\n\t\t\tPyObject *obj;\n\t\t\tobj = PyDict_GetItem(self->descr->fields, op);\n\t\t\tif (obj != NULL) {\n\t\t\t\tPyArray_Descr *descr;\n\t\t\t\tint offset;\n\t\t\t\tPyObject *title;\n\t\t\t\t\n\t\t\t\tif (PyArg_ParseTuple(obj, \"Oi|O\",\n\t\t\t\t\t\t &descr, &offset, &title)) {\n\t\t\t\t\tPy_INCREF(descr);\n\t\t\t\t\treturn PyArray_GetField(self, descr, \n\t\t\t\t\t\t\t\toffset);\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t\t\n\t\tPyErr_Format(PyExc_ValueError, \n\t\t\t \"field named %s not found.\",\n\t\t\t PyString_AsString(op));\n\t\treturn NULL;\n\t}\n if (self->nd == 0) {\n\t\tif (op == Py_Ellipsis)\n\t\t\treturn PyArray_ToScalar(self->data, self);\n\t\tif (op == Py_None)\n\t\t\treturn add_new_axes_0d(self, 1);\n\t\tif (PyTuple_Check(op)) {\n\t\t\tif (0 == PyTuple_GET_SIZE(op))\n\t\t\t\treturn PyArray_ToScalar(self->data, self);\n\t\t\tif ((nd = count_new_axes_0d(op)) == -1)\n\t\t\t\treturn NULL;\n\t\t\treturn add_new_axes_0d(self, nd);\n\t\t}\n PyErr_SetString(PyExc_IndexError, \n \"0-d arrays can't be indexed.\");\n return NULL;\n }\n if (PyArray_IsScalar(op, Integer) || PyInt_Check(op) || \\\n PyLong_Check(op)) {\n intp value;\n value = PyArray_PyIntAsIntp(op);\n\t\tif (PyErr_Occurred())\n\t\t\tPyErr_Clear();\n else if (value >= 0) {\n\t\t\treturn array_big_item(self, value);\n }\n else /* (value < 0) */ {\n\t\t\tvalue += self->dimensions[0];\n\t\t\treturn array_big_item(self, value);\n\t\t}\n }\n\n\tfancy = fancy_indexing_check(op);\n\n\tif (fancy != SOBJ_NOTFANCY) { \n\t\toned = ((self->nd == 1) && !(PyTuple_Check(op) &&\t\\\n\t\t\t\t\t PyTuple_GET_SIZE(op) > 1));\n\n\t\t/* wrap arguments into a mapiter object */\n\t\tmit = (PyArrayMapIterObject *)\\\n\t\t\tPyArray_MapIterNew(op, oned, fancy);\n\t\tif (mit == NULL) return NULL;\n\t\tif (oned) {\n\t\t\tPyArrayIterObject *it;\n\t\t\tPyObject *rval;\n\t\t\tit = (PyArrayIterObject *)PyArray_IterNew((PyObject *)self);\n\t\t\tif (it == NULL) {Py_DECREF(mit); return NULL;}\n\t\t\trval = iter_subscript(it, mit->indexobj);\n\t\t\tPy_DECREF(it);\n\t\t\tPy_DECREF(mit);\n\t\t\treturn rval;\n\t\t}\n PyArray_MapIterBind(mit, self);\n other = (PyArrayObject *)PyArray_GetMap(mit);\n Py_DECREF(mit);\n return (PyObject *)other;\n }\n\n\ti = PyArray_PyIntAsIntp(op);\n\tif (!error_converting(i)) {\n\t\tif (i < 0 && self->nd > 0) i = i+self->dimensions[0];\n\t\treturn array_big_item(self, i);\n\t}\n\tPyErr_Clear();\n\n\t/* Standard (view-based) Indexing */\n if ((nd = parse_index(self, op, dimensions, strides, &offset)) \n == -1) \n return NULL;\n\n\t/* This will only work if new array will be a view */\n\tPy_INCREF(self->descr);\n\tif ((other = (PyArrayObject *)\t\t\t\t\t\\\n\t PyArray_NewFromDescr(self->ob_type, self->descr,\n\t\t\t\t nd, dimensions,\n\t\t\t\t strides, self->data+offset, \n\t\t\t\t self->flags,\n\t\t\t\t (PyObject *)self)) == NULL) \n\t\treturn NULL;\n\n\n\tother->base = (PyObject *)self;\n\tPy_INCREF(self);\n\t\n\tPyArray_UpdateFlags(other, UPDATE_ALL_FLAGS);\n\t\n\treturn (PyObject *)other;\n}\n\n\n/* Another assignment hacked by using CopyObject. */\n\n/* This only works if subscript returns a standard view. */\n\n/* Again there are two cases. In the first case, PyArray_CopyObject\n can be used. In the second case, a new indexing function has to be \n used.\n*/\n\nstatic int iter_ass_subscript(PyArrayIterObject *, PyObject *, PyObject *); \n\nstatic int \narray_ass_sub(PyArrayObject *self, PyObject *index, PyObject *op) \n{\n int ret, oned, fancy;\n\tintp i;\n PyArrayObject *tmp;\n\tPyArrayMapIterObject *mit;\n\t\n if (op == NULL) {\n PyErr_SetString(PyExc_ValueError, \n \"cannot delete array elements\");\n return -1;\n }\n\tif (!PyArray_ISWRITEABLE(self)) {\n\t\tPyErr_SetString(PyExc_RuntimeError,\n\t\t\t\t\"array is not writeable\");\n\t\treturn -1;\n\t}\n\t\n if (PyArray_IsScalar(index, Integer) || PyInt_Check(index) ||\t\\\n PyLong_Check(index)) {\n intp value;\n value = PyArray_PyIntAsIntp(index);\n if (PyErr_Occurred())\n PyErr_Clear();\n\t\telse\n\t\t\treturn array_ass_big_item(self, value, op);\n }\n\n\tif (PyString_Check(index) || PyUnicode_Check(index)) {\n\t\tif (self->descr->fields) {\n\t\t\tPyObject *obj;\n\t\t\tobj = PyDict_GetItem(self->descr->fields, index);\n\t\t\tif (obj != NULL) {\n\t\t\t\tPyArray_Descr *descr;\n\t\t\t\tint offset;\n\t\t\t\tPyObject *title;\n\t\t\t\t\n\t\t\t\tif (PyArg_ParseTuple(obj, \"Oi|O\",\n\t\t\t\t\t\t &descr, &offset, &title)) {\n\t\t\t\t\tPy_INCREF(descr);\n\t\t\t\t\treturn PyArray_SetField(self, descr, \n\t\t\t\t\t\t\t\toffset, op);\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t\t\n\t\tPyErr_Format(PyExc_ValueError, \n\t\t\t \"field named %s not found.\",\n\t\t\t PyString_AsString(index));\n\t\treturn -1;\n\t}\n\n if (self->nd == 0) {\n\t\tif (index == Py_Ellipsis || index == Py_None ||\t\t\\\n\t\t (PyTuple_Check(index) && (0 == PyTuple_GET_SIZE(index) || \\\n\t\t\t\t\t count_new_axes_0d(index) > 0)))\n\t\t\treturn self->descr->f->setitem(op, self->data, self);\n PyErr_SetString(PyExc_IndexError, \n \"0-d arrays can't be indexed.\");\n return -1;\n }\n\n\tfancy = fancy_indexing_check(index);\n\n\tif (fancy != SOBJ_NOTFANCY) { \n\t\toned = ((self->nd == 1) && !(PyTuple_Check(index) && \\\n\t\t\t\t\t PyTuple_GET_SIZE(index) > 1));\n\n\t\tmit = (PyArrayMapIterObject *)\t\t\t\\\n\t\t\tPyArray_MapIterNew(index, oned, fancy);\n\t\tif (mit == NULL) return -1;\n\t\tif (oned) {\n\t\t\tPyArrayIterObject *it;\n\t\t\tint rval;\n\t\t\tit = (PyArrayIterObject *)PyArray_IterNew((PyObject *)self);\n\t\t\tif (it == NULL) {Py_DECREF(mit); return -1;}\n\t\t\trval = iter_ass_subscript(it, mit->indexobj, op);\n\t\t\tPy_DECREF(it);\n\t\t\tPy_DECREF(mit);\n\t\t\treturn rval;\n\t\t}\n PyArray_MapIterBind(mit, self);\n ret = PyArray_SetMap(mit, op);\n Py_DECREF(mit);\n return ret;\n }\n\t\n\ti = PyArray_PyIntAsIntp(index);\n\tif (!error_converting(i)) {\n\t\treturn array_ass_big_item(self, i, op);\n\t}\n\tPyErr_Clear();\n\t\n\t/* Rest of standard (view-based) indexing */\n\n if ((tmp = (PyArrayObject *)array_subscript(self, index)) == NULL)\n return -1; \n\tif (PyArray_ISOBJECT(self) && (tmp->nd == 0)) {\n\t\tret = tmp->descr->f->setitem(op, tmp->data, tmp);\n\t}\n\telse {\n\t\tret = PyArray_CopyObject(tmp, op);\n\t}\n\tPy_DECREF(tmp);\n return ret;\n}\n\n\n/* There are places that require that array_subscript return a PyArrayObject\n and not possibly a scalar. Thus, this is the function exposed to \n Python so that 0-dim arrays are passed as scalars\n*/\n\nstatic PyObject *\narray_subscript_nice(PyArrayObject *self, PyObject *op) \n{\n\treturn PyArray_Return((PyArrayObject *)array_subscript(self, op));\n}\n\n\nstatic PyMappingMethods array_as_mapping = {\n (inquiry)array_length,\t\t /*mp_length*/\n (binaryfunc)array_subscript_nice,\t/*mp_subscript*/\n (objobjargproc)array_ass_sub,\t /*mp_ass_subscript*/\n};\n\n/****************** End of Mapping Protocol ******************************/\n\n\n/*************************************************************************\n **************** Implement Buffer Protocol ****************************\n *************************************************************************/\n\n/* removed multiple segment interface */\n\nstatic int \narray_getsegcount(PyArrayObject *self, int *lenp) \n{\n if (lenp)\n *lenp = PyArray_NBYTES(self);\n\n if (PyArray_ISONESEGMENT(self)) {\n return 1;\n }\n\n if (lenp)\n *lenp = 0;\n return 0;\n}\n\nstatic int \narray_getreadbuf(PyArrayObject *self, int segment, void **ptrptr) \n{\n if (segment != 0) {\n PyErr_SetString(PyExc_ValueError, \n \"accessing non-existing array segment\");\n return -1;\n }\n \n if (PyArray_ISONESEGMENT(self)) {\n *ptrptr = self->data;\n return PyArray_NBYTES(self);\n }\n PyErr_SetString(PyExc_ValueError, \"array is not a single segment\");\n *ptrptr = NULL;\n return -1;\n}\n\n\nstatic int \narray_getwritebuf(PyArrayObject *self, int segment, void **ptrptr) \n{\n if (PyArray_CHKFLAGS(self, WRITEABLE)) \n return array_getreadbuf(self, segment, (void **) ptrptr);\n else {\n PyErr_SetString(PyExc_ValueError, \"array cannot be \"\\\n \"accessed as a writeable buffer\");\n return -1;\n }\n}\n\nstatic int \narray_getcharbuf(PyArrayObject *self, int segment, const char **ptrptr) \n{\n if (self->descr->type_num == PyArray_STRING || \\\n\t self->descr->type_num == PyArray_UNICODE)\n return array_getreadbuf(self, segment, (void **) ptrptr);\n else {\n PyErr_SetString(PyExc_TypeError, \n \"non-character array cannot be interpreted \"\\\n \"as character buffer\");\n return -1;\n }\n}\n\nstatic PyBufferProcs array_as_buffer = {\n (getreadbufferproc)array_getreadbuf, /*bf_getreadbuffer*/\n (getwritebufferproc)array_getwritebuf, /*bf_getwritebuffer*/\n (getsegcountproc)array_getsegcount,\t /*bf_getsegcount*/\n (getcharbufferproc)array_getcharbuf, /*bf_getcharbuffer*/\n};\n\n/****************** End of Buffer Protocol *******************************/\n\n\n/*************************************************************************\n **************** Implement Number Protocol ****************************\n *************************************************************************/\n\n\ntypedef struct {\n PyObject *add,\n *subtract,\n *multiply,\n *divide,\n *remainder,\n *power,\n\t\t*sqrt,\n *negative,\n *absolute,\n *invert,\n *left_shift,\n *right_shift,\n *bitwise_and,\n *bitwise_xor,\n *bitwise_or,\n *less,\n *less_equal,\n *equal,\n *not_equal,\n *greater,\n *greater_equal,\n *floor_divide,\n *true_divide,\n\t\t*logical_or,\n\t\t*logical_and,\n\t\t*floor,\n\t\t*ceil,\n\t\t*maximum,\n\t\t*minimum;\t\n\t\n} NumericOps;\n\nstatic NumericOps n_ops = {NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, \n NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL,\n NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL,\n NULL, NULL, NULL, NULL, NULL};\n\n/* Dictionary can contain any of the numeric operations, by name. \n Those not present will not be changed\n */\n\n#define SET(op) temp=PyDict_GetItemString(dict, #op);\t\\\n\tif (temp != NULL) {\t\t\t\t\\\n\t\tif (!(PyCallable_Check(temp))) return -1; \\\n Py_XDECREF(n_ops.op); \\\n\t\tn_ops.op = temp; \\\n\t}\n\n \n/*OBJECT_API\n Set internal structure with number functions that all arrays will use\n*/\nint \nPyArray_SetNumericOps(PyObject *dict) \n{\n PyObject *temp = NULL;\n SET(add);\n SET(subtract);\n SET(multiply);\n SET(divide);\n SET(remainder);\n SET(power);\n\tSET(sqrt);\n SET(negative);\n SET(absolute);\n SET(invert);\n SET(left_shift);\n SET(right_shift);\n SET(bitwise_and);\n SET(bitwise_or);\n SET(bitwise_xor);\n SET(less);\t \n SET(less_equal);\n SET(equal);\n SET(not_equal);\n SET(greater);\n SET(greater_equal);\n SET(floor_divide);\t\n SET(true_divide);\t\n\tSET(logical_or);\n\tSET(logical_and);\n\tSET(floor);\n\tSET(ceil);\n\tSET(maximum);\n\tSET(minimum);\n return 0;\n}\n\n#define GET(op) if (n_ops.op &&\t\t\t\t\t\t\\\n\t\t (PyDict_SetItemString(dict, #op, n_ops.op)==-1))\t\\\n\t\tgoto fail;\n\n/*OBJECT_API\n Get dictionary showing number functions that all arrays will use\n*/\nstatic PyObject *\nPyArray_GetNumericOps(void) \n{\n\tPyObject *dict;\n\tif ((dict = PyDict_New())==NULL) \n\t\treturn NULL;\t\n\tGET(add);\n GET(subtract);\n GET(multiply);\n GET(divide);\n GET(remainder);\n GET(power);\n\tGET(sqrt);\n GET(negative);\n GET(absolute);\n GET(invert);\n GET(left_shift);\n GET(right_shift);\n GET(bitwise_and);\n GET(bitwise_or);\n GET(bitwise_xor);\n GET(less);\t \n GET(less_equal);\n GET(equal);\n GET(not_equal);\n GET(greater);\n GET(greater_equal);\n GET(floor_divide); \n GET(true_divide); \n\tGET(logical_or);\n\tGET(logical_and);\n\tGET(floor);\n\tGET(ceil);\n\tGET(maximum);\n\tGET(minimum);\n\treturn dict;\t\n\n fail:\n\tPy_DECREF(dict);\n\treturn NULL;\t\t\n}\n\nstatic PyObject *\nPyArray_GenericReduceFunction(PyArrayObject *m1, PyObject *op, int axis,\n\t\t\t int rtype)\n{\n\tPyObject *args, *ret=NULL, *meth;\n\tif (op == NULL) {\n\t\tPy_INCREF(Py_NotImplemented);\n\t\treturn Py_NotImplemented;\n\t}\n\tif (rtype == PyArray_NOTYPE) \n\t\targs = Py_BuildValue(\"(Oi)\", m1, axis);\n\telse {\n\t\tPyArray_Descr *descr;\n\t\tdescr = PyArray_DescrFromType(rtype);\n\t\targs = Py_BuildValue(\"(Oic)\", m1, axis, descr->type);\n\t\tPy_DECREF(descr);\n\t}\n\tmeth = PyObject_GetAttrString(op, \"reduce\");\n\tif (meth && PyCallable_Check(meth)) {\n\t\tret = PyObject_Call(meth, args, NULL);\n\t}\n\tPy_DECREF(args);\n\tPy_DECREF(meth);\n\treturn ret;\n}\t\n\n\nstatic PyObject *\nPyArray_GenericAccumulateFunction(PyArrayObject *m1, PyObject *op, int axis,\n\t\t\t\t int rtype)\n{\n\tPyObject *args, *ret=NULL, *meth;\n\tif (op == NULL) {\n\t\tPy_INCREF(Py_NotImplemented);\n\t\treturn Py_NotImplemented;\n\t}\n\tif (rtype == PyArray_NOTYPE) \n\t\targs = Py_BuildValue(\"(Oi)\", m1, axis);\n\telse {\n\t\tPyArray_Descr *descr;\n\t\tdescr = PyArray_DescrFromType(rtype);\n\t\targs = Py_BuildValue(\"(Oic)\", m1, axis, descr->type);\n\t\tPy_DECREF(descr);\n\t}\n\tmeth = PyObject_GetAttrString(op, \"accumulate\");\n\tif (meth && PyCallable_Check(meth)) {\n\t\tret = PyObject_Call(meth, args, NULL);\n\t}\n\tPy_DECREF(args);\n\tPy_DECREF(meth);\n\treturn ret;\n}\t\n\n\nstatic PyObject *\nPyArray_GenericBinaryFunction(PyArrayObject *m1, PyObject *m2, PyObject *op) \n{\n if (op == NULL) {\n Py_INCREF(Py_NotImplemented);\n return Py_NotImplemented; \n }\n return PyObject_CallFunction(op, \"OO\", m1, m2);\n}\n\nstatic PyObject *\nPyArray_GenericUnaryFunction(PyArrayObject *m1, PyObject *op) \n{\n if (op == NULL) {\n Py_INCREF(Py_NotImplemented);\n return Py_NotImplemented; \n }\n return PyObject_CallFunction(op, \"(O)\", m1);\n}\n\nstatic PyObject *\nPyArray_GenericInplaceBinaryFunction(PyArrayObject *m1, \n\t\t\t\t PyObject *m2, PyObject *op) \n{\n if (op == NULL) {\n Py_INCREF(Py_NotImplemented);\n return Py_NotImplemented; \n }\n return PyObject_CallFunction(op, \"OOO\", m1, m2, m1);\n}\n\nstatic PyObject *\narray_add(PyArrayObject *m1, PyObject *m2) \n{ \n return PyArray_GenericBinaryFunction(m1, m2, n_ops.add); \n}\n\nstatic PyObject *\narray_subtract(PyArrayObject *m1, PyObject *m2) \n{\n\treturn PyArray_GenericBinaryFunction(m1, m2, n_ops.subtract);\n}\n\nstatic PyObject *\narray_multiply(PyArrayObject *m1, PyObject *m2) \n{\n return PyArray_GenericBinaryFunction(m1, m2, n_ops.multiply);\n}\n\nstatic PyObject *\narray_divide(PyArrayObject *m1, PyObject *m2) \n{\n return PyArray_GenericBinaryFunction(m1, m2, n_ops.divide);\n}\n\nstatic PyObject *\narray_remainder(PyArrayObject *m1, PyObject *m2) \n{\n return PyArray_GenericBinaryFunction(m1, m2, n_ops.remainder);\n}\n\nstatic PyObject *\narray_power(PyArrayObject *m1, PyObject *m2) \n{\n return PyArray_GenericBinaryFunction(m1, m2, n_ops.power);\n}\n\nstatic PyObject *\narray_negative(PyArrayObject *m1) \n{ \n return PyArray_GenericUnaryFunction(m1, n_ops.negative);\n}\n\nstatic PyObject *\narray_absolute(PyArrayObject *m1) \n{ \n return PyArray_GenericUnaryFunction(m1, n_ops.absolute);\n}\n\nstatic PyObject *\narray_invert(PyArrayObject *m1) \n{ \n return PyArray_GenericUnaryFunction(m1, n_ops.invert);\n}\n\nstatic PyObject *\narray_left_shift(PyArrayObject *m1, PyObject *m2) \n{\n return PyArray_GenericBinaryFunction(m1, m2, n_ops.left_shift);\n}\n\nstatic PyObject *\narray_right_shift(PyArrayObject *m1, PyObject *m2) \n{\n return PyArray_GenericBinaryFunction(m1, m2, n_ops.right_shift);\n}\n\nstatic PyObject *\narray_bitwise_and(PyArrayObject *m1, PyObject *m2) \n{\n return PyArray_GenericBinaryFunction(m1, m2, n_ops.bitwise_and);\n}\n\nstatic PyObject *\narray_bitwise_or(PyArrayObject *m1, PyObject *m2) \n{\n return PyArray_GenericBinaryFunction(m1, m2, n_ops.bitwise_or);\n}\n\nstatic PyObject *\narray_bitwise_xor(PyArrayObject *m1, PyObject *m2) \n{\n return PyArray_GenericBinaryFunction(m1, m2, n_ops.bitwise_xor);\n}\n\nstatic PyObject *\narray_inplace_add(PyArrayObject *m1, PyObject *m2) \n{\n return PyArray_GenericInplaceBinaryFunction(m1, m2, n_ops.add);\n}\n\nstatic PyObject *\narray_inplace_subtract(PyArrayObject *m1, PyObject *m2) \n{\n return PyArray_GenericInplaceBinaryFunction(m1, m2, n_ops.subtract);\n}\n\nstatic PyObject *\narray_inplace_multiply(PyArrayObject *m1, PyObject *m2) \n{\n return PyArray_GenericInplaceBinaryFunction(m1, m2, n_ops.multiply);\n}\n\nstatic PyObject *\narray_inplace_divide(PyArrayObject *m1, PyObject *m2) \n{\n return PyArray_GenericInplaceBinaryFunction(m1, m2, n_ops.divide);\n}\n\nstatic PyObject *\narray_inplace_remainder(PyArrayObject *m1, PyObject *m2) \n{\n return PyArray_GenericInplaceBinaryFunction(m1, m2, n_ops.remainder);\n}\n\nstatic PyObject *\narray_inplace_power(PyArrayObject *m1, PyObject *m2) \n{\n return PyArray_GenericInplaceBinaryFunction(m1, m2, n_ops.power);\n}\n\nstatic PyObject *\narray_inplace_left_shift(PyArrayObject *m1, PyObject *m2) \n{\n return PyArray_GenericInplaceBinaryFunction(m1, m2, n_ops.left_shift);\n}\n\nstatic PyObject *\narray_inplace_right_shift(PyArrayObject *m1, PyObject *m2) \n{\n return PyArray_GenericInplaceBinaryFunction(m1, m2, n_ops.right_shift);\n}\n\nstatic PyObject *\narray_inplace_bitwise_and(PyArrayObject *m1, PyObject *m2) \n{\n return PyArray_GenericInplaceBinaryFunction(m1, m2, n_ops.bitwise_and);\n}\n\nstatic PyObject *\narray_inplace_bitwise_or(PyArrayObject *m1, PyObject *m2) \n{\n return PyArray_GenericInplaceBinaryFunction(m1, m2, n_ops.bitwise_or);\n}\n\nstatic PyObject *\narray_inplace_bitwise_xor(PyArrayObject *m1, PyObject *m2) \n{\n return PyArray_GenericInplaceBinaryFunction(m1, m2, n_ops.bitwise_xor);\n}\n\nstatic PyObject *\narray_floor_divide(PyArrayObject *m1, PyObject *m2) \n{\n return PyArray_GenericBinaryFunction(m1, m2, n_ops.floor_divide);\n}\n\nstatic PyObject *\narray_true_divide(PyArrayObject *m1, PyObject *m2) \n{\n return PyArray_GenericBinaryFunction(m1, m2, n_ops.true_divide);\n}\n\nstatic PyObject *\narray_inplace_floor_divide(PyArrayObject *m1, PyObject *m2) \n{\n return PyArray_GenericInplaceBinaryFunction(m1, m2, \n\t\t\t\t\t\t n_ops.floor_divide);\n}\n\nstatic PyObject *\narray_inplace_true_divide(PyArrayObject *m1, PyObject *m2) \n{\n return PyArray_GenericInplaceBinaryFunction(m1, m2, \n\t\t\t\t\t\t n_ops.true_divide);\n}\n\n/* Array evaluates as \"TRUE\" if any of the elements are non-zero*/\nstatic int \narray_any_nonzero(PyArrayObject *mp) \n{\n\tintp index;\n\tPyArrayIterObject *it;\n\tBool anyTRUE = FALSE;\n\t\n\tit = (PyArrayIterObject *)PyArray_IterNew((PyObject *)mp);\n\tif (it==NULL) return anyTRUE;\n\tindex = it->size;\n\twhile(index--) {\n\t\tif (mp->descr->f->nonzero(it->dataptr, mp)) {\n\t\t\tanyTRUE = TRUE;\n\t\t\tbreak;\n\t\t}\n\t\tPyArray_ITER_NEXT(it);\n\t}\n\tPy_DECREF(it);\n\treturn anyTRUE;\n}\n\nstatic int\n_array_nonzero(PyArrayObject *mp)\n{\n\tintp n;\n\tn = PyArray_SIZE(mp);\n\tif (n == 1) {\n\t\treturn mp->descr->f->nonzero(mp->data, mp);\n\t}\n\telse if (n == 0) {\n\t\treturn 0;\n\t}\n\telse {\n\t\tPyErr_SetString(PyExc_ValueError, \n\t\t\t\t\"The truth value of an array \" \\\n\t\t\t\t\"with more than one element is ambiguous. \" \\\n\t\t\t\t\"Use a.any() or a.all()\");\n\t\treturn -1;\n\t}\n}\n\n\n\nstatic PyObject *\narray_divmod(PyArrayObject *op1, PyObject *op2) \n{\n PyObject *divp, *modp, *result;\n\n divp = array_floor_divide(op1, op2);\n if (divp == NULL) return NULL;\n modp = array_remainder(op1, op2);\n if (modp == NULL) {\n Py_DECREF(divp);\n return NULL;\n }\n result = Py_BuildValue(\"OO\", divp, modp);\n Py_DECREF(divp);\n Py_DECREF(modp);\n return result;\n}\n\n\nstatic PyObject *\narray_int(PyArrayObject *v) \n{ \n PyObject *pv, *pv2;\n if (PyArray_SIZE(v) != 1) {\n PyErr_SetString(PyExc_TypeError, \"only length-1 arrays can be\"\\\n\t\t\t\t\" converted to Python scalars\");\n return NULL;\n }\n pv = v->descr->f->getitem(v->data, v);\n if (pv == NULL) return NULL;\n if (pv->ob_type->tp_as_number == 0) {\n PyErr_SetString(PyExc_TypeError, \"cannot convert to an int; \"\\\n\t\t\t\t\"scalar object is not a number\");\n Py_DECREF(pv);\n return NULL;\n }\n if (pv->ob_type->tp_as_number->nb_int == 0) {\n PyErr_SetString(PyExc_TypeError, \"don't know how to convert \"\\\n\t\t\t\t\"scalar number to int\");\n Py_DECREF(pv);\n return NULL;\n }\n\n pv2 = pv->ob_type->tp_as_number->nb_int(pv);\n Py_DECREF(pv);\n return pv2;\t \n}\n\nstatic PyObject *\narray_float(PyArrayObject *v) \n{\n PyObject *pv, *pv2;\n if (PyArray_SIZE(v) != 1) {\n PyErr_SetString(PyExc_TypeError, \"only length-1 arrays can \"\\\n\t\t\t\t\"be converted to Python scalars\");\n return NULL;\n }\n pv = v->descr->f->getitem(v->data, v);\n if (pv == NULL) return NULL;\n if (pv->ob_type->tp_as_number == 0) {\n PyErr_SetString(PyExc_TypeError, \"cannot convert to an \"\\\n\t\t\t\t\"int; scalar object is not a number\");\n Py_DECREF(pv);\n return NULL;\n }\n if (pv->ob_type->tp_as_number->nb_float == 0) {\n PyErr_SetString(PyExc_TypeError, \"don't know how to convert \"\\\n\t\t\t\t\"scalar number to float\");\n Py_DECREF(pv);\n return NULL;\n }\n pv2 = pv->ob_type->tp_as_number->nb_float(pv);\n Py_DECREF(pv);\n return pv2;\t \n}\n\nstatic PyObject *\narray_long(PyArrayObject *v) \n{ \n PyObject *pv, *pv2;\n if (PyArray_SIZE(v) != 1) {\n PyErr_SetString(PyExc_TypeError, \"only length-1 arrays can \"\\\n\t\t\t\t\"be converted to Python scalars\");\n return NULL;\n }\n pv = v->descr->f->getitem(v->data, v);\n if (pv->ob_type->tp_as_number == 0) {\n PyErr_SetString(PyExc_TypeError, \"cannot convert to an int; \"\\\n\t\t\t\t\"scalar object is not a number\");\n return NULL;\n }\n if (pv->ob_type->tp_as_number->nb_long == 0) {\n PyErr_SetString(PyExc_TypeError, \"don't know how to convert \"\\\n\t\t\t\t\"scalar number to long\");\n return NULL;\n }\n pv2 = pv->ob_type->tp_as_number->nb_long(pv);\n Py_DECREF(pv);\n return pv2;\t \n}\n\nstatic PyObject *\narray_oct(PyArrayObject *v) \n{\t \n PyObject *pv, *pv2;\n if (PyArray_SIZE(v) != 1) {\n PyErr_SetString(PyExc_TypeError, \"only length-1 arrays can \"\\\n\t\t\t\t\"be converted to Python scalars\");\n return NULL;\n }\n pv = v->descr->f->getitem(v->data, v);\n if (pv->ob_type->tp_as_number == 0) {\n PyErr_SetString(PyExc_TypeError, \"cannot convert to an int; \"\\\n\t\t\t\t\"scalar object is not a number\");\n return NULL;\n }\n if (pv->ob_type->tp_as_number->nb_oct == 0) {\n PyErr_SetString(PyExc_TypeError, \"don't know how to convert \"\\\n\t\t\t\t\"scalar number to oct\");\n return NULL;\n }\n pv2 = pv->ob_type->tp_as_number->nb_oct(pv);\n Py_DECREF(pv);\n return pv2;\t \n}\n\nstatic PyObject *\narray_hex(PyArrayObject *v) \n{ \n PyObject *pv, *pv2;\n if (PyArray_SIZE(v) != 1) {\n PyErr_SetString(PyExc_TypeError, \"only length-1 arrays can \"\\\n\t\t\t\t\"be converted to Python scalars\");\n return NULL;\n }\n pv = v->descr->f->getitem(v->data, v);\n if (pv->ob_type->tp_as_number == 0) {\n PyErr_SetString(PyExc_TypeError, \"cannot convert to an int; \"\\\n\t\t\t\t\"scalar object is not a number\");\n return NULL;\n }\n if (pv->ob_type->tp_as_number->nb_hex == 0) {\n PyErr_SetString(PyExc_TypeError, \"don't know how to convert \"\\\n\t\t\t\t\"scalar number to hex\");\n return NULL;\n }\n pv2 = pv->ob_type->tp_as_number->nb_hex(pv);\n Py_DECREF(pv);\n return pv2;\t \n}\n\nstatic PyObject *\n_array_copy_nice(PyArrayObject *self)\n{\n\treturn PyArray_Return((PyArrayObject *)\t\t\\\n\t\t\t PyArray_Copy(self));\n}\n\nstatic PyNumberMethods array_as_number = {\n (binaryfunc)array_add,\t\t /*nb_add*/\n (binaryfunc)array_subtract,\t\t /*nb_subtract*/\n (binaryfunc)array_multiply,\t\t /*nb_multiply*/\n (binaryfunc)array_divide,\t\t /*nb_divide*/\n (binaryfunc)array_remainder,\t /*nb_remainder*/\n (binaryfunc)array_divmod,\t\t /*nb_divmod*/\n (ternaryfunc)array_power,\t\t /*nb_power*/\n (unaryfunc)array_negative, /*nb_neg*/\t\n (unaryfunc)_array_copy_nice,\t\t /*nb_pos*/ \n (unaryfunc)array_absolute,\t\t /*(unaryfunc)array_abs,*/\n (inquiry)_array_nonzero,\t\t /*nb_nonzero*/\n (unaryfunc)array_invert,\t\t /*nb_invert*/\n (binaryfunc)array_left_shift,\t /*nb_lshift*/\n (binaryfunc)array_right_shift,\t /*nb_rshift*/\n (binaryfunc)array_bitwise_and,\t /*nb_and*/\n (binaryfunc)array_bitwise_xor,\t /*nb_xor*/\n (binaryfunc)array_bitwise_or,\t /*nb_or*/\n 0,\t\t /*nb_coerce*/\n (unaryfunc)array_int,\t\t /*nb_int*/\n (unaryfunc)array_long,\t\t /*nb_long*/\n (unaryfunc)array_float,\t\t /*nb_float*/\n (unaryfunc)array_oct,\t\t /*nb_oct*/\n (unaryfunc)array_hex,\t\t /*nb_hex*/\n\n /*This code adds augmented assignment functionality*/\n /*that was made available in Python 2.0*/\n (binaryfunc)array_inplace_add,\t /*inplace_add*/\n (binaryfunc)array_inplace_subtract,\t /*inplace_subtract*/\n (binaryfunc)array_inplace_multiply,\t /*inplace_multiply*/\n (binaryfunc)array_inplace_divide,\t /*inplace_divide*/\n (binaryfunc)array_inplace_remainder, /*inplace_remainder*/\n (ternaryfunc)array_inplace_power,\t /*inplace_power*/\n (binaryfunc)array_inplace_left_shift, /*inplace_lshift*/\n (binaryfunc)array_inplace_right_shift, /*inplace_rshift*/\n (binaryfunc)array_inplace_bitwise_and, /*inplace_and*/\n (binaryfunc)array_inplace_bitwise_xor, /*inplace_xor*/\n (binaryfunc)array_inplace_bitwise_or, /*inplace_or*/\n\n (binaryfunc)array_floor_divide,\t /*nb_floor_divide*/\n (binaryfunc)array_true_divide,\t /*nb_true_divide*/\n (binaryfunc)array_inplace_floor_divide, /*nb_inplace_floor_divide*/\n (binaryfunc)array_inplace_true_divide, /*nb_inplace_true_divide*/\n\n};\n\n/****************** End of Buffer Protocol *******************************/\n\n\n/*************************************************************************\n **************** Implement Sequence Protocol **************************\n *************************************************************************/\n\n/* Some of this is repeated in the array_as_mapping protocol. But\n we fill it in here so that PySequence_XXXX calls work as expected \n*/\n\n\nstatic PyObject * \narray_slice(PyArrayObject *self, int ilow, int ihigh) \n{\n PyArrayObject *r;\n int l;\n char *data;\n\n if (self->nd == 0) {\n PyErr_SetString(PyExc_ValueError, \"cannot slice a scalar\");\n return NULL;\n }\n \t\n l=self->dimensions[0];\n if (ihigh < 0) ihigh += l;\n if (ilow < 0) ilow += l;\n if (ilow < 0) ilow = 0;\n else if (ilow > l) ilow = l;\n if (ihigh < 0) ihigh = 0;\n else if (ihigh > l) ihigh = l;\n if (ihigh < ilow) ihigh = ilow;\n\n if (ihigh != ilow) {\n data = index2ptr(self, ilow);\n if (data == NULL) return NULL;\n } else {\n data = self->data;\n }\n\n self->dimensions[0] = ihigh-ilow;\n\tPy_INCREF(self->descr);\n r = (PyArrayObject *)\t\t\t\t\t\t\\\n\t\tPyArray_NewFromDescr(self->ob_type, self->descr,\n\t\t\t\t self->nd, self->dimensions, \n\t\t\t\t self->strides, data,\n\t\t\t\t self->flags, (PyObject *)self);\n\n self->dimensions[0] = l;\n r->base = (PyObject *)self;\n Py_INCREF(self);\n\tPyArray_UpdateFlags(r, UPDATE_ALL_FLAGS); \n return (PyObject *)r;\n}\n\n\nstatic int \narray_ass_slice(PyArrayObject *self, int ilow, int ihigh, PyObject *v) {\n int ret;\n PyArrayObject *tmp;\n\t\n if (v == NULL) {\n PyErr_SetString(PyExc_ValueError, \n \"cannot delete array elements\");\n return -1;\n }\n\tif (!PyArray_ISWRITEABLE(self)) {\n\t\tPyErr_SetString(PyExc_RuntimeError,\n\t\t\t\t\"array is not writeable\");\n\t\treturn -1;\n\t}\n if ((tmp = (PyArrayObject *)array_slice(self, ilow, ihigh)) \\\n == NULL) \n return -1; \n ret = PyArray_CopyObject(tmp, v);\n Py_DECREF(tmp);\n\t\n return ret;\n}\n\nstatic int\narray_contains(PyArrayObject *self, PyObject *el)\n{\n /* equivalent to (self == el).any() */\n\n PyObject *res; \n int ret;\n\n res = PyArray_EnsureArray(PyObject_RichCompare((PyObject *)self, el, Py_EQ));\n if (res == NULL) return -1;\n ret = array_any_nonzero((PyArrayObject *)res);\n Py_DECREF(res);\n return ret;\n}\n\n\nstatic PySequenceMethods array_as_sequence = {\n (inquiry)array_length,\t\t/*sq_length*/\n (binaryfunc)NULL, /* sq_concat is handled by nb_add*/\n (intargfunc)NULL, /* sq_repeat is handled nb_multiply*/\n (intargfunc)array_item_nice,\t\t/*sq_item*/\n (intintargfunc)array_slice,\t\t/*sq_slice*/\n (intobjargproc)array_ass_item,\t/*sq_ass_item*/\n (intintobjargproc)array_ass_slice,\t/*sq_ass_slice*/\n\t(objobjproc) array_contains, /* sq_contains */\n\t(binaryfunc) NULL, /* sg_inplace_concat */\n\t(intargfunc) NULL /* sg_inplace_repeat */\n};\n\n\n/****************** End of Sequence Protocol ****************************/\n\n\nstatic int \ndump_data(char **string, int *n, int *max_n, char *data, int nd, \n intp *dimensions, intp *strides, PyArrayObject* self) \n{\n PyArray_Descr *descr=self->descr;\n PyObject *op, *sp;\n char *ostring;\n int i, N;\n\t\n#define CHECK_MEMORY if (*n >= *max_n-16) { *max_n *= 2; \\\n\t\t*string = (char *)_pya_realloc(*string, *max_n); }\n\t\n if (nd == 0) {\n\t\t\n if ((op = descr->f->getitem(data, self)) == NULL) return -1;\n sp = PyObject_Repr(op);\n if (sp == NULL) {Py_DECREF(op); return -1;}\n ostring = PyString_AsString(sp);\n N = PyString_Size(sp)*sizeof(char);\n *n += N;\n CHECK_MEMORY\n memmove(*string+(*n-N), ostring, N);\n Py_DECREF(sp);\n Py_DECREF(op);\n return 0;\n } else {\n CHECK_MEMORY\n (*string)[*n] = '[';\n *n += 1;\n for(i=0; idata, \n\t\t self->nd, self->dimensions, \n self->strides, self) < 0) { \n\t\t_pya_free(string); return NULL; \n\t}\n\t\n\tif (PyArray_ISEXTENDED(self)) {\n\t\tchar buf[100];\n\t\tsnprintf(buf, sizeof(buf), \"%d\", self->descr->elsize);\n\t\tsprintf(string+n, \", '%c%s')\", self->descr->type, buf);\n\t\tret = PyString_FromStringAndSize(string, n+6+strlen(buf));\n\t}\n\telse {\n\t\tsprintf(string+n, \", '%c')\", self->descr->type);\n\t\tret = PyString_FromStringAndSize(string, n+6);\n\t}\n\t\n\n _pya_free(string);\n return ret;\n}\n\nstatic PyObject *PyArray_StrFunction=NULL;\nstatic PyObject *PyArray_ReprFunction=NULL;\n\n/*OBJECT_API\n Set the array print function to be a Python function.\n*/\nstatic void \nPyArray_SetStringFunction(PyObject *op, int repr) \n{\n if (repr) {\n\t\t/* Dispose of previous callback */\n Py_XDECREF(PyArray_ReprFunction); \n\t\t/* Add a reference to new callback */\n Py_XINCREF(op); \n\t\t/* Remember new callback */\n PyArray_ReprFunction = op; \n } else {\n\t\t/* Dispose of previous callback */\n Py_XDECREF(PyArray_StrFunction); \n\t\t/* Add a reference to new callback */\n Py_XINCREF(op); \n\t\t/* Remember new callback */\n PyArray_StrFunction = op; \n }\n}\n\nstatic PyObject *\narray_repr(PyArrayObject *self) \n{\n PyObject *s, *arglist;\n\t\n if (PyArray_ReprFunction == NULL) {\n s = array_repr_builtin(self);\n } else {\n arglist = Py_BuildValue(\"(O)\", self);\n s = PyEval_CallObject(PyArray_ReprFunction, arglist);\n Py_DECREF(arglist); \n }\n return s;\n}\n\nstatic PyObject *\narray_str(PyArrayObject *self) \n{\n PyObject *s, *arglist;\n\t\n if (PyArray_StrFunction == NULL) {\n s = array_repr(self);\n } else {\n arglist = Py_BuildValue(\"(O)\", self);\n s = PyEval_CallObject(PyArray_StrFunction, arglist);\n Py_DECREF(arglist); \n }\n return s;\n}\n\nstatic PyObject *\narray_richcompare(PyArrayObject *self, PyObject *other, int cmp_op) \n{\n PyObject *array_other, *result;\n\n switch (cmp_op) \n {\n case Py_LT:\n return PyArray_GenericBinaryFunction(self, other, \n\t\t\t\t\t\t\t n_ops.less);\n case Py_LE:\n return PyArray_GenericBinaryFunction(self, other, \n\t\t\t\t\t\t\t n_ops.less_equal);\n case Py_EQ:\n /* Try to convert other to an array */\n\t\t\tif (!PyArray_Check(other)) {\n\t\t\t\tarray_other = PyArray_FromObject(other, \n\t\t\t\t\t\t\t\t self->descr->type_num, 0, 0);\n\t\t\t\t/* If not successful, then return the integer\n\t\t\t\t object 0. This fixes code that used to\n\t\t\t\t allow equality comparisons between arrays\n\t\t\t\t and other objects which would give a result\n\t\t\t\t of 0\n\t\t\t\t*/\n\t\t\t\tif ((array_other == NULL) ||\t\\\n\t\t\t\t (array_other == Py_None)) {\n\t\t\t\t\tPy_XDECREF(array_other);\n\t\t\t\t\tPyErr_Clear();\n\t\t\t\t\tPy_INCREF(Py_False);\n\t\t\t\t\treturn Py_False;\n\t\t\t\t}\n\t\t\t}\n\t\t\telse {\n\t\t\t\tPy_INCREF(other);\n\t\t\t\tarray_other = other;\n\t\t\t}\n result = PyArray_GenericBinaryFunction(self, \n\t\t\t\t\t\t\t array_other, \n\t\t\t\t\t\t\t n_ops.equal);\n /* If the comparison results in NULL, then the \n\t\t\t two array objects can not be compared together so \n\t\t\t return zero \n */\n Py_DECREF(array_other);\n if (result == NULL) {\n PyErr_Clear();\n Py_INCREF(Py_False);\n return Py_False;\n }\n return result;\n case Py_NE:\n /* Try to convert other to an array */\n\t\t\tif (!PyArray_Check(other)) {\n\t\t\t\tarray_other = PyArray_FromObject(other, \n\t\t\t\t\t\t\t\t self->descr->type_num, 0, 0);\n\t\t\t\t/* If not successful, then objects cannot be \n\t\t\t\t compared and cannot be equal, therefore, \n\t\t\t\t return True;\n\t\t\t\t*/\n\t\t\t\tif ((array_other == NULL) ||\t\\\n\t\t\t\t (array_other == Py_None)) {\n\t\t\t\t\tPy_XDECREF(array_other);\n\t\t\t\t\tPyErr_Clear();\n\t\t\t\t\tPy_INCREF(Py_True);\n\t\t\t\t\treturn Py_True;\n\t\t\t\t}\n\t\t\t}\n\t\t\telse {\n\t\t\t\tPy_INCREF(other);\n\t\t\t\tarray_other = other;\n\t\t\t}\n\t\t\tresult = PyArray_GenericBinaryFunction(self, \n\t\t\t\t\t\t\t array_other, \n\t\t\t\t\t\t\t n_ops.not_equal);\n\t\t\tPy_DECREF(array_other);\n if (result == NULL) {\n PyErr_Clear();\n Py_INCREF(Py_True);\n return Py_True;\n }\n return result;\n case Py_GT:\n return PyArray_GenericBinaryFunction(self, other, \n\t\t\t\t\t\t\t n_ops.greater);\n case Py_GE:\n return PyArray_GenericBinaryFunction(self, \n\t\t\t\t\t\t\t other, \n\t\t\t\t\t \t n_ops.greater_equal);\n }\n return NULL;\n}\n\nstatic PyObject *\n_check_axis(PyArrayObject *arr, int *axis, int flags)\n{\n\tPyObject *temp;\n\tint n = arr->nd;\n\n\tif ((*axis >= MAX_DIMS) || (n==0)) {\n\t\ttemp = PyArray_Ravel(arr,0);\n\t\t*axis = PyArray_NDIM(temp)-1;\n\t\treturn temp;\n\t}\n\telse {\n\t\tif (flags) {\n\t\t\ttemp = PyArray_CheckFromAny((PyObject *)arr, NULL, \n 0, 0, flags, NULL);\n\t\t\tif (temp == NULL) return NULL;\n\t\t}\n\t\telse {\n\t\t\tPy_INCREF(arr);\n\t\t\ttemp = (PyObject *)arr;\n\t\t}\n\t}\n\tif (*axis < 0) *axis += n;\n\tif ((*axis < 0) || (*axis >= n)) {\n\t\tPyErr_Format(PyExc_ValueError, \n\t\t\t \"axis(=%d) out of bounds\", *axis);\n\t\tPy_DECREF(temp);\n\t\treturn NULL;\n\t}\n\treturn temp;\n}\n\n#include \"arraymethods.c\"\n\n/* Lifted from numarray */\nstatic PyObject *\nPyArray_IntTupleFromIntp(int len, intp *vals)\n{\n\tint i;\n PyObject *intTuple = PyTuple_New(len);\n if (!intTuple) goto fail;\n for(i=0; i= SIZEOF_INTP\n\t\tif (!(op = PyNumber_Int(seq))) return -1;\n#else\n\t\tif (!(op = PyNumber_Long(seq))) return -1;\n#endif\n\t\tnd = 1;\n#if SIZEOF_LONG >= SIZEOF_INTP\n\t\tvals[0] = (intp ) PyInt_AsLong(op);\n#else\n\t\tvals[0] = (intp ) PyLong_AsLongLong(op);\n#endif\n\t\tPy_DECREF(op);\n\t} else {\n\t\tfor(i=0; i < MIN(nd,maxvals); i++) {\n\t\t\top = PySequence_GetItem(seq, i);\n\t\t\tif (op == NULL) return -1;\n#if SIZEOF_LONG >= SIZEOF_INTP\n\t\t\tvals[i]=(intp )PyInt_AsLong(op);\n#else\n\t\t\tvals[i]=(intp )PyLong_AsLongLong(op);\n#endif\n\t\t\tPy_DECREF(op);\n\t\t\tif(PyErr_Occurred()) return -1;\n\t\t}\n\t}\n\treturn nd;\n}\n\n\n/* Check whether the given array is stored contiguously (row-wise) in\n memory. */\nstatic int\n_IsContiguous(PyArrayObject *ap) \n{\n\tregister intp sd;\n\tregister intp dim;\n\tregister int i;\n \n\n\tif (ap->nd == 0) return 1;\n\tsd = ap->descr->elsize;\n\tif (ap->nd == 1) return (ap->dimensions[0] == 1 || \\\n\t\t\t\t sd == ap->strides[0]);\n\tfor (i = ap->nd-1; i >= 0; --i) {\n\t\tdim = ap->dimensions[i];\n\t\t/* contiguous by definition */\n\t\tif (dim == 0) return 1;\n\t\tif (ap->strides[i] != sd) return 0;\n\t\tsd *= dim;\n\t}\n\treturn 1;\n}\n\n\nstatic int \n_IsFortranContiguous(PyArrayObject *ap) \n{\n\tregister intp sd;\n\tregister intp dim;\n\tregister int i;\n\t\n\tif (ap->nd == 0) return 1;\n\tsd = ap->descr->elsize;\n\tif (ap->nd == 1) return (ap->dimensions[0] == 1 || \\\n\t\t\t\t sd == ap->strides[0]);\n\tfor (i=0; i< ap->nd; ++i) {\n\t\tdim = ap->dimensions[i];\n\t\t/* contiguous by definition */\n\t\tif (dim == 0) return 1; \n\t\tif (ap->strides[i] != sd) return 0;\n\t\tsd *= dim;\n\t}\n\treturn 1;\n}\n\nstatic int\n_IsAligned(PyArrayObject *ap) \n{\n\tint i, alignment, aligned=1;\n\tintp ptr;\n\tint type = ap->descr->type_num;\n\n\tif ((type == PyArray_STRING) || (type == PyArray_VOID))\n\t\treturn 1;\n\n\talignment = ap->descr->alignment;\n\tif (alignment == 1) return 1;\n\n\tptr = (intp) ap->data;\n aligned = (ptr % alignment) == 0;\n for (i=0; i nd; i++)\n aligned &= ((ap->strides[i] % alignment) == 0);\n return aligned != 0;\n}\n\nstatic Bool\n_IsWriteable(PyArrayObject *ap)\n{\n\tPyObject *base=ap->base;\n\tvoid *dummy;\n\tint n;\n\n\t/* If we own our own data, then no-problem */\n\tif ((base == NULL) || (ap->flags & OWN_DATA)) return TRUE;\n\n\t/* Get to the final base object \n\t If it is a writeable array, then return TRUE\n\t If we can find an array object \n\t or a writeable buffer object as the final base object\n\t or a string object (for pickling support memory savings).\n\t - this last could be removed if a proper pickleable \n\t buffer was added to Python.\n\t*/\n\n\twhile(PyArray_Check(base)) {\n\t\tif (PyArray_CHKFLAGS(base, OWN_DATA)) \n\t\t\treturn (Bool) (PyArray_ISWRITEABLE(base));\n\t\tbase = PyArray_BASE(base);\n\t}\n\n\t/* here so pickle support works seamlessly \n\t and unpickled array can be set and reset writeable \n\t -- could be abused -- */\n\tif PyString_Check(base) return TRUE;\n\n\tif (PyObject_AsWriteBuffer(base, &dummy, &n) < 0)\n\t\treturn FALSE;\n\t\n\treturn TRUE;\n}\n\n\n/*OBJECT_API\n Update Several Flags at once.\n*/\nstatic void\nPyArray_UpdateFlags(PyArrayObject *ret, int flagmask)\n{\n\n\tif (flagmask & FORTRAN) {\n\t\tif (_IsFortranContiguous(ret)) {\n\t\t\tret->flags |= FORTRAN;\n\t\t\tif (ret->nd > 1) ret->flags &= ~CONTIGUOUS;\n\t\t}\n\t\telse ret->flags &= ~FORTRAN;\n\t}\n\tif (flagmask & CONTIGUOUS) {\n\t\tif (_IsContiguous(ret)) {\n\t\t\tret->flags |= CONTIGUOUS;\n\t\t\tif (ret->nd > 1) ret->flags &= ~FORTRAN;\n\t\t}\n\t\telse ret->flags &= ~CONTIGUOUS;\n\t}\n\tif (flagmask & ALIGNED) {\n\t\tif (_IsAligned(ret)) ret->flags |= ALIGNED;\n\t\telse ret->flags &= ~ALIGNED;\n\t}\n\t/* This is not checked by default WRITEABLE is not part of UPDATE_ALL_FLAGS */\n\tif (flagmask & WRITEABLE) {\n\t if (_IsWriteable(ret)) ret->flags |= WRITEABLE;\n\t \telse ret->flags &= ~WRITEABLE;\t\n }\n\treturn;\n}\n\n/* This routine checks to see if newstrides (of length nd) will not \n walk outside of the memory implied by a single segment array of the provided \n dimensions and element size. If numbytes is 0 it will be calculated from \n the provided shape and element size.\n*/\n/*OBJECT_API*/\nstatic Bool\nPyArray_CheckStrides(int elsize, int nd, intp numbytes, \n\t\t intp *dims, intp *newstrides)\n{\n\tint i;\n\t\n\tif (numbytes == 0) \n\t\tnumbytes = PyArray_MultiplyList(dims, nd) * elsize;\n\t\n\tfor (i=0; i numbytes) {\n\t\t\treturn FALSE;\n\t\t}\n\t}\n\treturn TRUE;\n\t\n}\n\n\n/* This is the main array creation routine. */\n\n/* Flags argument has multiple related meanings \n depending on data and strides: \n\n If data is given, then flags is flags associated with data. \n If strides is not given, then a contiguous strides array will be created\n and the CONTIGUOUS bit will be set. If the flags argument \n has the FORTRAN bit set, then a FORTRAN-style strides array will be\n created (and of course the FORTRAN flag bit will be set). \n\n If data is not given but created here, then flags will be DEFAULT_FLAGS\n and a non-zero flags argument can be used to indicate a FORTRAN style\n array is desired. \n*/\n\nstatic intp\n_array_fill_strides(intp *strides, intp *dims, int nd, intp itemsize, \n\t\t int inflag, int *objflags) \n{\n\tint i;\n\t/* Only make Fortran strides if not contiguous as well */\n\tif ((inflag & FORTRAN) && !(inflag & CONTIGUOUS)) {\n\t\tfor (i=0; i 1) *objflags &= ~CONTIGUOUS;\n\t\telse *objflags |= CONTIGUOUS;\n\t}\n\telse {\n\t\tfor (i=nd-1;i>=0;i--) {\n\t\t\tstrides[i] = itemsize;\n\t\t\titemsize *= dims[i] ? dims[i] : 1;\n\t\t}\n\t\t*objflags |= CONTIGUOUS;\n\t\tif (nd > 1) *objflags &= ~FORTRAN;\n\t\telse *objflags |= FORTRAN;\n\t}\n\treturn itemsize;\n}\n\n/*OBJECT_API\n Generic new array creation routine.\n*/\nstatic PyObject *\nPyArray_New(PyTypeObject *subtype, int nd, intp *dims, int type_num,\n intp *strides, void *data, int itemsize, int flags,\n\t PyObject *obj)\n{\n\tPyArray_Descr *descr;\n\tPyObject *new;\n\n\tdescr = PyArray_DescrFromType(type_num);\n\tif (descr == NULL) return NULL;\t\n\tif (descr->elsize == 0) {\n\t\tif (itemsize < 1) {\n\t\t\tPyErr_SetString(PyExc_ValueError,\n\t\t\t\t\t\"data type must provide an itemsize\");\n\t\t\tPy_DECREF(descr);\n\t\t\treturn NULL;\n\t\t}\n\t\tPyArray_DESCR_REPLACE(descr);\n\t\tdescr->elsize = itemsize;\n\t}\n\tnew = PyArray_NewFromDescr(subtype, descr, nd, dims, strides,\n\t\t\t\t data, flags, obj);\n\treturn new;\n}\n\n/* Change a sub-array field to the base descriptor */\nstatic int\n_update_descr_and_dimensions(PyArray_Descr **des, intp *newdims, \n\t\t\t intp *newstrides, int oldnd)\n{\n\tPyArray_Descr *old;\n\tint newnd;\n\tint numnew;\n\tintp *mydim;\n\tint i;\n\t\n\told = *des;\n\t*des = old->subarray->base;\n\n\tmydim = newdims + oldnd;\n\tif (PyTuple_Check(old->subarray->shape)) {\n\t\tnumnew = PyTuple_GET_SIZE(old->subarray->shape);\n\t\t\n\t\tfor (i=0; isubarray->shape, i));\n\t\t}\n\t}\n\telse {\n\t\tnumnew = 1;\n\t\tmydim[0] = (intp) PyInt_AsLong(old->subarray->shape);\n\t}\n\t\n\tnewnd = oldnd + numnew;\n\n\tif (newstrides) {\n\t\tintp tempsize;\n\t\tintp *mystrides;\n\t\tmystrides = newstrides + oldnd;\n\t\t/* Make new strides */\n\t\ttempsize = (*des)->elsize;\n\t\tfor (i=numnew-1; i>=0; i--) {\n\t\t\tmystrides[i] = tempsize;\n\t\t\ttempsize *= mydim[i] ? mydim[i] : 1;\n\t\t}\n\t}\n\tPy_INCREF(*des); \n\tPy_DECREF(old); \n\treturn newnd;\n}\n\n\n/* steals a reference to descr (even on failure) */\n/*OBJECT_API\n Generic new array creation routine.\n*/\nstatic PyObject *\nPyArray_NewFromDescr(PyTypeObject *subtype, PyArray_Descr *descr, int nd, \n\t\t intp *dims, intp *strides, void *data, \n\t\t int flags, PyObject *obj)\n{\t\n\tPyArrayObject *self;\n\tregister int i;\n\tintp sd;\n\n\tif (descr->subarray) {\n\t\tPyObject *ret;\n\t\tintp newdims[2*MAX_DIMS];\n\t\tintp *newstrides=NULL;\n\t\tmemcpy(newdims, dims, nd*sizeof(intp));\n\t\tif (strides) {\n\t\t\tnewstrides = newdims + MAX_DIMS;\n\t\t\tmemcpy(newstrides, strides, nd*sizeof(intp));\n\t\t}\n\t\tnd =_update_descr_and_dimensions(&descr, newdims, \n\t\t\t\t\t\t newstrides, nd);\n\t\tret = PyArray_NewFromDescr(subtype, descr, nd, newdims, \n\t\t\t\t\t newstrides,\n\t\t\t\t\t data, flags, obj);\n\t\treturn ret;\n\t}\n\n\tif (nd < 0) {\n\t\tPyErr_SetString(PyExc_ValueError,\n\t\t\t\t\"number of dimensions must be >=0\");\n\t\tPy_DECREF(descr);\n\t\treturn NULL;\n\t}\n if (nd > MAX_DIMS) {\n PyErr_Format(PyExc_ValueError,\n \"maximum number of dimensions is %d\", MAX_DIMS);\n\t\tPy_DECREF(descr);\n return NULL;\n\t}\n\n\t/* Check dimensions */\n\tfor (i=nd-1;i>=0;i--) {\n\t\tif (dims[i] < 0) {\n\t\t\tPyErr_SetString(PyExc_ValueError,\n\t\t\t\t\t\"negative dimensions \"\t\\\n\t\t\t\t\t\"are not allowed\");\n\t\t\tPy_DECREF(descr);\n\t\t\treturn NULL;\n\t\t}\n\t}\n\t\n\tself = (PyArrayObject *) subtype->tp_alloc(subtype, 0);\n\tif (self == NULL) {\n\t\tPy_DECREF(descr);\n\t\treturn NULL;\t\n\t}\n\tself->nd = nd;\n\tself->dimensions = NULL;\n\tself->data = NULL;\n\tif (data == NULL) { /* strides is NULL too */\n\t\tself->flags = DEFAULT_FLAGS;\n\t\tif (flags) {\n\t\t\tself->flags |= FORTRAN; \n\t\t\tif (nd > 1) self->flags &= ~CONTIGUOUS;\n\t\t\tflags = FORTRAN;\n\t\t}\n\t}\n\telse self->flags = (flags & ~UPDATEIFCOPY);\n\t\t\n\tsd = descr->elsize;\n\tself->descr = descr;\n\tself->base = (PyObject *)NULL;\n self->weakreflist = (PyObject *)NULL;\n\t\n\tif (nd > 0) {\n\t\tself->dimensions = PyDimMem_NEW(2*nd);\n\t\tif (self->dimensions == NULL) {\n\t\t\tPyErr_NoMemory();\n\t\t\tgoto fail;\n\t\t}\n\t\tself->strides = self->dimensions + nd;\n\t\tmemcpy(self->dimensions, dims, sizeof(intp)*nd);\n\t\tif (strides == NULL) { /* fill it in */\n\t\t\tsd = _array_fill_strides(self->strides, dims, nd, sd,\n\t\t\t\t\t\t flags, &(self->flags));\n\t\t}\n\t\telse {\n\t\t\tif (data == NULL) {\n\t\t\t\tPyErr_SetString(PyExc_ValueError, \n\t\t\t\t\t\t\"if 'strides' is given in \" \\\n\t\t\t\t\t\t\"array creation, data must \" \\\n\t\t\t\t\t\t\"be given too\");\n\t\t\t\tgoto fail;\n\t\t\t} \n\t\t\tmemcpy(self->strides, strides, sizeof(intp)*nd);\n\t\t}\n\t} \t\n\t\t\n\tif (data == NULL) {\n\n\t\t/* Allocate something even for zero-space arrays \n\t\t e.g. shape=(0,) -- otherwise buffer exposure \n\t\t (a.data) doesn't work as it should. */\n\n\t\tif (sd==0) sd = descr->elsize;\n\n\t\tif ((data = PyDataMem_NEW(sd))==NULL) {\n\t\t\tPyErr_NoMemory();\n\t\t\tgoto fail;\n\t\t}\n\t\tself->flags |= OWN_DATA;\n\n\t\t/* It is bad to have unitialized OBJECT pointers */\n /* which could also be sub-fields of a VOID array */\n\t\tif (descr->hasobject) {\n if (descr != &OBJECT_Descr) {\n PyErr_SetString(PyExc_TypeError,\n \"fields with object members \" \\\n \"not yet supported.\");\n goto fail;\n }\n\t\t\tmemset(data, 0, sd);\n\t\t}\n\t}\n\telse {\n self->flags &= ~OWN_DATA; /* If data is passed in, \n\t\t\t\t\t this object won't own it \n\t\t\t\t\t by default.\n\t\t\t\t\t Caller must arrange for \n\t\t\t\t\t this to be reset if truly\n\t\t\t\t\t desired */\n }\n self->data = data;\n\n /* call the __array_finalize__\n\t method if a subtype and some object passed in */\n\tif ((obj != NULL) && (subtype != &PyArray_Type) && \n\t (subtype != &PyBigArray_Type)) {\n\t\tPyObject *res, *func, *args;\n\t\tstatic PyObject *str=NULL;\n\n\t\tif (str == NULL) {\n\t\t\tstr = PyString_InternFromString(\"__array_finalize__\");\n\t\t}\n\t\tif (!(self->flags & OWNDATA)) { /* did not allocate own data */\n\t\t\t /* update flags before calling back into\n\t\t\t Python */\n\t\t\tPyArray_UpdateFlags(self, UPDATE_ALL_FLAGS);\n\t\t}\n\t\tfunc = PyObject_GetAttr((PyObject *)self, str);\n\t\tif (func) {\n\t\t\targs = PyTuple_New(1);\n\t\t\tPy_INCREF(obj);\n\t\t\tPyTuple_SET_ITEM(args, 0, obj);\n\t\t\tres = PyObject_Call(func, args, NULL);\n\t\t\tPy_DECREF(args);\n\t\t\tPy_DECREF(func);\n\t\t\tif (res == NULL) goto fail;\n\t\t\telse Py_DECREF(res);\n\t\t}\n\t}\n\t\n\treturn (PyObject *)self;\n\n fail:\n\tPy_DECREF(self);\n\treturn NULL;\n}\n\n\n\n/*OBJECT_API\n Resize (reallocate data). Only works if nothing else is referencing\n this array and it is contiguous.\n*/\nstatic PyObject * \nPyArray_Resize(PyArrayObject *self, PyArray_Dims *newshape)\n{\n intp oldsize, newsize;\n int new_nd=newshape->len, k, n, elsize;\n int refcnt;\n intp* new_dimensions=newshape->ptr;\n intp new_strides[MAX_DIMS];\n intp sd;\n intp *dimptr;\n char *new_data;\n\t\n if (!PyArray_ISCONTIGUOUS(self)) {\n PyErr_SetString(PyExc_ValueError, \n \"resize only works on contiguous arrays\");\n return NULL;\n }\n\n newsize = PyArray_MultiplyList(new_dimensions, new_nd);\n oldsize = PyArray_SIZE(self);\n \n\tif (oldsize != newsize) {\n\t\tif (!(self->flags & OWN_DATA)) {\n\t\t\tPyErr_SetString(PyExc_ValueError, \n\t\t\t\t\t\"cannot resize this array: \"\t\\\n\t\t\t\t\t\"it does not own its data\");\n\t\t\treturn NULL;\n\t\t}\n\t\t\n\t\trefcnt = REFCOUNT(self);\n\t\tif ((refcnt > 2) || (self->base != NULL) || \\\n\t\t (self->weakreflist != NULL)) {\n\t\t\tPyErr_SetString(PyExc_ValueError, \n\t\t\t\t\t\"cannot resize an array that has \"\\\n\t\t\t\t\t\"been referenced or is referencing\\n\"\\\n\t\t\t\t\t\"another array in this way. Use the \"\\\n\t\t\t\t\t\"resize function\");\n\t\t\treturn NULL;\n\t\t} \n\t\t\t\t\n\t\tif (newsize == 0) sd = self->descr->elsize;\t\n\t\telse sd = newsize * self->descr->elsize;\n\t\t/* Reallocate space if needed */\n\t\tnew_data = PyDataMem_RENEW(self->data, sd);\n\t\tif (new_data == NULL) {\n\t\t\tPyErr_SetString(PyExc_MemoryError, \n\t\t\t\t\t\"cannot allocate memory for array\");\n\t\t\treturn NULL;\n\t\t}\n\t\tself->data = new_data;\n\t}\n \n if ((newsize > oldsize) && PyArray_ISWRITEABLE(self)) { \n\t\t/* Fill new memory with zeros */\n elsize = self->descr->elsize;\n\t\tif ((PyArray_TYPE(self) == PyArray_OBJECT)) {\n\t\t\tPyObject *zero = PyInt_FromLong(0);\n PyObject **optr;\n\t\t\toptr = ((PyObject **)self->data) + oldsize;\n\t\t\tn = newsize - oldsize;\n\t\t\tfor (k=0; kdata+oldsize*elsize, 0, \n\t\t\t (newsize-oldsize)*elsize);\n\t\t}\n\t}\n \n if (self->nd != new_nd) { /* Different number of dimensions. */\n self->nd = new_nd;\n \n /* Need new dimensions and strides arrays */\n dimptr = PyDimMem_RENEW(self->dimensions, 2*new_nd);\n if (dimptr == NULL) {\n\t\t\tPyErr_SetString(PyExc_MemoryError, \n \"cannot allocate memory for array \" \\\n \"(array may be corrupted)\");\n return NULL;\n }\n self->dimensions = dimptr;\n\t\tself->strides = dimptr + new_nd;\n }\n\n /* make new_strides variable */\n sd = (intp) self->descr->elsize;\n sd = _array_fill_strides(new_strides, new_dimensions, new_nd, sd,\n 0, &(self->flags));\n\n \n memmove(self->dimensions, new_dimensions, new_nd*sizeof(intp));\n memmove(self->strides, new_strides, new_nd*sizeof(intp));\n\n Py_INCREF(Py_None);\t\n return Py_None;\n \n}\n\n\n/* Assumes contiguous */\n/*OBJECT_API*/\nstatic void\nPyArray_FillObjectArray(PyArrayObject *arr, PyObject *obj)\n{\n PyObject **optr;\n intp i,n;\n optr = (PyObject **)(arr->data);\n n = PyArray_SIZE(arr);\n if (obj == NULL) {\n for (i=0; ielsize;\n\tPy_INCREF(descr);\n\tnewarr = PyArray_FromAny(obj, descr, 0,0, ALIGNED, NULL);\n\tif (newarr == NULL) return -1;\n\tfromptr = PyArray_DATA(newarr);\n\tsize=PyArray_SIZE(arr);\n\tswap=!PyArray_ISNOTSWAPPED(arr);\n\tcopyswap = arr->descr->f->copyswap;\n\tif (PyArray_ISONESEGMENT(arr)) {\n\t\tchar *toptr=PyArray_DATA(arr);\n\t\twhile (size--) {\n\t\t\tcopyswap(toptr, fromptr, swap, itemsize);\n\t\t\ttoptr += itemsize;\n\t\t}\n\t}\n\telse {\n\t\tPyArrayIterObject *iter;\n\t\t\n\t\titer = (PyArrayIterObject *)\\\n\t\t\tPyArray_IterNew((PyObject *)arr);\n\t\tif (iter == NULL) {\n\t\t\tPy_DECREF(newarr);\n\t\t\treturn -1;\n\t\t}\n\t\twhile(size--) {\n\t\t\tcopyswap(iter->dataptr, fromptr, swap, itemsize);\n\t\t\tPyArray_ITER_NEXT(iter);\n\t\t}\n\t\tPy_DECREF(iter);\n\t}\n\tPy_DECREF(newarr);\n\treturn 0;\n}\n\nstatic PyObject *\narray_new(PyTypeObject *subtype, PyObject *args, PyObject *kwds) \n{\n\tstatic char *kwlist[] = {\"shape\", \"dtype\", \"buffer\", /* XXX ? */\n\t\t\t\t \"offset\", \"strides\",\n\t\t\t\t \"fortran\", NULL};\n\tPyArray_Descr *descr=NULL;\n\tint type_num;\n\tint itemsize;\n PyArray_Dims dims = {NULL, 0};\n PyArray_Dims strides = {NULL, 0};\n PyArray_Chunk buffer;\n\tlonglong offset=0;\n\tint fortran = 0;\n\tPyArrayObject *ret;\n\n\tbuffer.ptr = NULL; \n /* Usually called with shape and type\n but can also be called with buffer, strides, and swapped info\n */\n\n\t/* For now, let's just use this to create an empty, contiguous \n\t array of a specific type and shape. \n\t*/\t\n\n\tif (!PyArg_ParseTupleAndKeywords(args, kwds, \"O&|O&O&LO&i\",\n\t\t\t\t\t kwlist, PyArray_IntpConverter,\n &dims, \n PyArray_DescrConverter,\n\t\t\t\t\t &descr,\n PyArray_BufferConverter,\n &buffer,\n\t\t\t\t\t &offset,\n &PyArray_IntpConverter, \n &strides,\n &fortran)) \n\t\tgoto fail;\n\n\n\tif (descr == NULL)\n\t\tdescr = PyArray_DescrFromType(PyArray_LONG);\n\n\ttype_num = descr->type_num;\n\titemsize = descr->elsize;\n\n if (dims.ptr == NULL) {\n PyErr_SetString(PyExc_ValueError, \"need to give a \"\\\n \"valid shape as the first argument\");\n goto fail;\n }\n\n if (buffer.ptr == NULL) {\n ret = (PyArrayObject *)\\\n\t\t\tPyArray_NewFromDescr(subtype, descr,\n\t\t\t\t\t (int)dims.len, \n\t\t\t\t\t dims.ptr, \n\t\t\t\t\t NULL, NULL, fortran, NULL);\n if (ret == NULL) {descr=NULL;goto fail;}\n if (type_num == PyArray_OBJECT) { /* place Py_None */\n PyArray_FillObjectArray(ret, Py_None);\n }\n }\n else { /* buffer given -- use it */\n\t\tbuffer.len -= offset;\n\t\tbuffer.ptr += offset;\n if (dims.len == 1 && dims.ptr[0] == -1) {\n dims.ptr[0] = buffer.len / itemsize;\n }\n else if (buffer.len < itemsize* \\\n PyArray_MultiplyList(dims.ptr, dims.len)) {\n PyErr_SetString(PyExc_TypeError, \n \"buffer is too small for \" \\\n \"requested array\");\n goto fail;\n }\n if (strides.ptr != NULL) {\n\t\t\tif (strides.len != dims.len) {\n\t\t\t\tPyErr_SetString(PyExc_ValueError, \n\t\t\t\t\t\t\"strides, if given, must be \"\\\n\t\t\t\t\t\t\"the same length as shape\");\n\t\t\t\tgoto fail;\n\t\t\t}\n\t\t\tif (!PyArray_CheckStrides(itemsize, strides.len, \n\t\t\t\t\t\t buffer.len,\n\t\t\t\t\t\t dims.ptr, strides.ptr)) {\n\t\t\t\tPyErr_SetString(PyExc_ValueError, \n\t\t\t\t\t\t\"strides is incompatible \"\\\n\t\t\t\t\t\t\"with shape of requested\"\\\n\t\t\t\t\t\t\"array and size of buffer\");\n\t\t\t\tgoto fail;\n\t\t\t}\n }\n if (type_num == PyArray_OBJECT) {\n PyErr_SetString(PyExc_TypeError, \"cannot construct \"\\\n \"an object array from buffer data\");\n goto fail;\n }\n /* get writeable and aligned */\n if (fortran) buffer.flags |= FORTRAN;\n ret = (PyArrayObject *)\\\n\t\t\tPyArray_NewFromDescr(subtype, descr,\n\t\t\t\t\t dims.len, dims.ptr,\n\t\t\t\t\t strides.ptr,\n\t\t\t\t\t (char *)buffer.ptr, \n\t\t\t\t\t buffer.flags, NULL); \n if (ret == NULL) {descr=NULL; goto fail;}\n PyArray_UpdateFlags(ret, UPDATE_ALL_FLAGS);\n ret->base = buffer.base;\n Py_INCREF(buffer.base); \n }\n\n PyDimMem_FREE(dims.ptr);\n if (strides.ptr) PyDimMem_FREE(strides.ptr);\n return (PyObject *)ret;\n \n fail:\n\tPy_XDECREF(descr);\n if (dims.ptr) PyDimMem_FREE(dims.ptr);\n if (strides.ptr) PyDimMem_FREE(strides.ptr);\n return NULL;\n}\n\n\nstatic PyObject *\narray_iter(PyArrayObject *arr)\n{\n\tif (arr->nd == 0) {\n\t\tPyErr_SetString(PyExc_TypeError,\n\t\t\t\t\"iteration over a scalar (0-dim array)\");\n\t\treturn NULL;\n\t}\n\treturn PySeqIter_New((PyObject *)arr);\n}\n\n\n/******************* array attribute get and set routines ******************/\n\nstatic PyObject *\narray_ndim_get(PyArrayObject *self)\n{\n\treturn PyInt_FromLong(self->nd);\n}\n\nstatic PyObject *\narray_flags_get(PyArrayObject *self)\n{\n return PyObject_CallMethod(_numpy_internal, \"flagsobj\", \"Oii\", \n self, self->flags, 0);\n}\n\nstatic PyObject *\narray_shape_get(PyArrayObject *self)\n{\n\treturn PyArray_IntTupleFromIntp(self->nd, self->dimensions);\n}\n\n\nstatic int\narray_shape_set(PyArrayObject *self, PyObject *val)\n{\n \tint nd;\n\tPyObject *ret;\n\n\tret = PyArray_Reshape(self, val);\n\tif (ret == NULL) return -1;\n\n\t/* Free old dimensions and strides */\n\tPyDimMem_FREE(self->dimensions);\n\tnd = PyArray_NDIM(ret);\n\tself->nd = nd;\n\tif (nd > 0) { /* create new dimensions and strides */\n\t\tself->dimensions = PyDimMem_NEW(2*nd);\n\t\tif (self->dimensions == NULL) {\n\t\t\tPy_DECREF(ret);\n\t\t\tPyErr_SetString(PyExc_MemoryError,\"\");\n\t\t\treturn -1;\n\t\t}\n\t\tself->strides = self->dimensions + nd;\n\t\tmemcpy(self->dimensions, PyArray_DIMS(ret), \n\t\t nd*sizeof(intp));\n\t\tmemcpy(self->strides, PyArray_STRIDES(ret), \n\t\t nd*sizeof(intp));\n\t}\n\telse {self->dimensions=NULL; self->strides=NULL;}\n\tPy_DECREF(ret);\n\tPyArray_UpdateFlags(self, CONTIGUOUS | FORTRAN);\n\treturn 0;\n}\n\n\nstatic PyObject *\narray_strides_get(PyArrayObject *self)\n{\n\treturn PyArray_IntTupleFromIntp(self->nd, self->strides);\n}\n\nstatic int\narray_strides_set(PyArrayObject *self, PyObject *obj)\n{\n\tPyArray_Dims newstrides = {NULL, 0};\n\tPyArrayObject *new;\n\tintp numbytes;\n\n\tif (!PyArray_IntpConverter(obj, &newstrides) || \\\n\t newstrides.ptr == NULL) {\n\t\tPyErr_SetString(PyExc_TypeError, \"invalid strides\");\n\t\treturn -1;\n\t}\n\tif (newstrides.len != self->nd) {\n\t\tPyErr_Format(PyExc_ValueError, \"strides must be \"\t\\\n\t\t\t \" same length as shape (%d)\", self->nd);\n\t\tgoto fail;\n\t}\n\tnew = self;\n\twhile(new->base != NULL) {\n\t\tif (PyArray_Check(new->base)) \n\t\t\tnew = (PyArrayObject *)new->base;\n\t}\n\tnumbytes = PyArray_MultiplyList(new->dimensions, \n\t\t\t\t\tnew->nd)*new->descr->elsize;\n\t\n\tif (!PyArray_CheckStrides(self->descr->elsize, self->nd, numbytes, \n\t\t\t\t self->dimensions, newstrides.ptr)) {\n\t\tPyErr_SetString(PyExc_ValueError, \"strides is not \"\\\n\t\t\t\t\"compatible with available memory\");\n\t\tgoto fail;\n\t}\n\tmemcpy(self->strides, newstrides.ptr, sizeof(intp)*newstrides.len);\n\tPyArray_UpdateFlags(self, CONTIGUOUS | FORTRAN);\n\tPyDimMem_FREE(newstrides.ptr);\n\treturn 0;\n\n fail:\n\tPyDimMem_FREE(newstrides.ptr);\n\treturn -1;\n}\n\n\nstatic PyObject *\narray_protocol_strides_get(PyArrayObject *self)\n{\n\tif PyArray_ISCONTIGUOUS(self) {\n\t\tPy_INCREF(Py_None);\n\t\treturn Py_None;\n\t}\n\treturn PyArray_IntTupleFromIntp(self->nd, self->strides);\n}\n\nstatic PyObject *\narray_priority_get(PyArrayObject *self)\n{\n\tif (PyArray_CheckExact(self)) \n\t\treturn PyFloat_FromDouble(PyArray_PRIORITY);\n\telse if (PyBigArray_CheckExact(self)) \n\t\treturn PyFloat_FromDouble(PyArray_BIG_PRIORITY);\n\telse\n\t\treturn PyFloat_FromDouble(PyArray_SUBTYPE_PRIORITY);\n}\n\n\nstatic PyObject *\narray_dataptr_get(PyArrayObject *self)\n{\n\treturn Py_BuildValue(\"NO\",\n\t\t\t PyString_FromFormat(\"%p\", self->data),\n\t\t\t (self->flags & WRITEABLE ? Py_False :\n\t\t\t Py_True));\n}\n\nstatic PyObject *\narray_data_get(PyArrayObject *self)\n{\n\tintp nbytes;\n\tif (!(PyArray_ISONESEGMENT(self))) {\n\t\tPyErr_SetString(PyExc_AttributeError, \"cannot get single-\"\\\n\t\t\t\t\"segment buffer for discontiguous array\");\n\t\treturn NULL;\n\t}\t\t\n\tnbytes = PyArray_NBYTES(self);\n\tif PyArray_ISWRITEABLE(self) \n\t\treturn PyBuffer_FromReadWriteObject((PyObject *)self, 0, \n\t\t\t\t\t\t (int) nbytes);\n\telse\n\t\treturn PyBuffer_FromObject((PyObject *)self, 0, (int) nbytes);\n}\n\nstatic int\narray_data_set(PyArrayObject *self, PyObject *op)\n{\n\tvoid *buf;\n\tint buf_len;\n\tint writeable=1;\n\n\tif (PyObject_AsWriteBuffer(op, &buf, &buf_len) < 0) {\n\t\twriteable = 0;\n\t\tif (PyObject_AsReadBuffer(op, (const void **)&buf, \n\t\t\t\t\t &buf_len) < 0) {\n\t\t\tPyErr_SetString(PyExc_AttributeError, \n\t\t\t\t\t\"object does not have single-segment \" \\\n\t\t\t\t\t\"buffer interface\");\n\t\t\treturn -1;\n\t\t}\n\t}\n\tif (!PyArray_ISONESEGMENT(self)) {\n\t\tPyErr_SetString(PyExc_AttributeError, \"cannot set single-\" \\\n\t\t\t\t\"segment buffer for discontiguous array\");\n\t\treturn -1;\n\t}\n\tif (PyArray_NBYTES(self) > buf_len) {\n\t\tPyErr_SetString(PyExc_AttributeError, \n\t\t\t\t\"not enough data for array\");\n\t\treturn -1;\n\t}\n\tif (self->flags & OWN_DATA) {\n\t\tPyArray_XDECREF(self);\n\t\tPyDataMem_FREE(self->data);\n\t}\n\tif (self->base) {\n\t\tif (self->flags & UPDATEIFCOPY) {\n\t\t\t((PyArrayObject *)self->base)->flags |= WRITEABLE;\n\t\t\tself->flags &= ~UPDATEIFCOPY;\n\t\t}\n\t\tPy_DECREF(self->base);\n\t}\n\tPy_INCREF(op);\n\tself->base = op;\n\tself->data = buf;\n\tself->flags = CARRAY_FLAGS;\n\tif (!writeable)\n\t\tself->flags &= ~WRITEABLE;\n\treturn 0;\n}\n\n\nstatic PyObject *\narray_itemsize_get(PyArrayObject *self)\n{\n\treturn PyInt_FromLong((long) self->descr->elsize);\n}\n\nstatic PyObject *\narray_size_get(PyArrayObject *self)\n{\n\tintp size=PyArray_SIZE(self);\n#if SIZEOF_INTP <= SIZEOF_LONG\n return PyInt_FromLong((long) size);\n#else\n\tif (size > MAX_LONG || size < MIN_LONG)\n\t\treturn PyLong_FromLongLong(size);\n\telse \n\t\treturn PyInt_FromLong((long) size);\n#endif\n}\n\nstatic PyObject *\narray_nbytes_get(PyArrayObject *self)\n{\n intp nbytes = PyArray_NBYTES(self);\n#if SIZEOF_INTP <= SIZEOF_LONG\n return PyInt_FromLong((long) nbytes);\n#else\n\tif (nbytes > MAX_LONG || nbytes < MIN_LONG)\n\t\treturn PyLong_FromLongLong(nbytes);\n\telse \n\t\treturn PyInt_FromLong((long) nbytes);\n#endif\n}\n\n\nstatic PyObject *arraydescr_protocol_typestr_get(PyArray_Descr *);\n\nstatic PyObject *\narray_typestr_get(PyArrayObject *self)\n{\n\treturn arraydescr_protocol_typestr_get(self->descr);\n}\n\nstatic PyObject *\narray_descr_get(PyArrayObject *self) \n{\n\tPy_INCREF(self->descr);\n\treturn (PyObject *)self->descr;\n}\n\n\n/* If the type is changed. \n Also needing change: strides, itemsize\n\n Either itemsize is exactly the same\n or the array is single-segment (contiguous or fortran) with\n compatibile dimensions\n\n The shape and strides will be adjusted in that case as well.\n*/\n\nstatic int\narray_descr_set(PyArrayObject *self, PyObject *arg)\n{\n PyArray_Descr *newtype=NULL;\n intp newdim;\n int index;\n char *msg = \"new type not compatible with array.\";\n\n if (!(PyArray_DescrConverter(arg, &newtype)) ||\n newtype == NULL) {\n PyErr_SetString(PyExc_TypeError, \"invalid data-type for array\");\n\t\treturn -1;\n }\n\tif (newtype->type_num == PyArray_OBJECT || \\\n\t self->descr->type_num == PyArray_OBJECT) {\n\t\tPyErr_SetString(PyExc_TypeError, \\\n\t\t\t\t\"Cannot change descriptor for object\"\\\n\t\t\t\t\"array.\");\n\t\tPy_DECREF(newtype);\n\t\treturn -1;\n\t}\n\n\tif ((newtype->elsize != self->descr->elsize) &&\t\t\\\n\t (self->nd == 0 || !PyArray_ISONESEGMENT(self) || \\\n\t newtype->subarray)) goto fail;\n\t\n\tif (PyArray_ISCONTIGUOUS(self)) index = self->nd - 1;\n\telse index = 0;\n\t\n\tif (newtype->elsize < self->descr->elsize) {\n\t\t/* if it is compatible increase the size of the \n\t\t dimension at end (or at the front for FORTRAN)\n\t\t*/\n\t\tif (self->descr->elsize % newtype->elsize != 0) \n\t\t\tgoto fail;\n\t\tnewdim = self->descr->elsize / newtype->elsize;\n\t\tself->dimensions[index] *= newdim;\n\t\tself->strides[index] = newtype->elsize;\n\t}\n\t\n\telse if (newtype->elsize > self->descr->elsize) {\n\t\t\n\t\t/* Determine if last (or first if FORTRAN) dimension\n\t\t is compatible */\n\t\t\n\t\tnewdim = self->dimensions[index] * self->descr->elsize;\n\t\tif ((newdim % newtype->elsize) != 0) goto fail;\n\t\t\n\t\tself->dimensions[index] = newdim / newtype->elsize;\n\t\tself->strides[index] = newtype->elsize;\n\t}\n\n /* fall through -- adjust type*/\n\n\tPy_DECREF(self->descr);\n\tif (newtype->subarray) {\n\t\t/* create new array object from data and update \n\t\t dimensions, strides and descr from it */\n\t\tPyArrayObject *temp;\n\n\t\ttemp = (PyArrayObject *)\\\n\t\t\tPyArray_NewFromDescr(&PyArray_Type, newtype, self->nd,\n\t\t\t\t\t self->dimensions, self->strides,\n\t\t\t\t\t self->data, self->flags, NULL);\n\t\tPyDimMem_FREE(self->dimensions);\n\t\tself->dimensions = temp->dimensions;\n\t\tself->nd = temp->nd;\n\t\tself->strides = temp->strides;\n\t\tPy_DECREF(newtype);\n\t\tnewtype = temp->descr;\n\t\t/* Fool deallocator */\n\t\ttemp->nd = 0;\n\t\ttemp->dimensions = NULL;\n\t\ttemp->descr = NULL;\n\t\tPy_DECREF(temp);\n\t}\n\n\tself->descr = newtype; \n\tPyArray_UpdateFlags(self, UPDATE_ALL_FLAGS);\n\t\n return 0;\n\n fail:\n\tPyErr_SetString(PyExc_ValueError, msg);\n\tPy_DECREF(newtype);\n\treturn -1;\n}\n\nstatic PyObject *\narray_protocol_descr_get(PyArrayObject *self)\n{\n\tPyObject *res;\n\tPyObject *dobj;\n\t\n\tres = PyObject_GetAttrString((PyObject *)self->descr, \"descr\");\n\tif (res) return res;\n\tPyErr_Clear();\n\n\t/* get default */\n\tdobj = PyTuple_New(2);\n\tif (dobj == NULL) return NULL;\n\tPyTuple_SET_ITEM(dobj, 0, PyString_FromString(\"\"));\n\tPyTuple_SET_ITEM(dobj, 1, array_typestr_get(self));\n\tres = PyList_New(1);\n\tif (res == NULL) {Py_DECREF(dobj); return NULL;}\n\tPyList_SET_ITEM(res, 0, dobj);\n\treturn res;\n}\n\nstatic PyObject *\narray_struct_get(PyArrayObject *self)\n{\n PyArrayInterface *inter;\n \n inter = (PyArrayInterface *)_pya_malloc(sizeof(PyArrayInterface));\n inter->version = 2;\n inter->nd = self->nd;\n inter->typekind = self->descr->kind;\n inter->itemsize = self->descr->elsize;\n inter->flags = self->flags;\n /* reset unused flags */\n\tinter->flags &= ~(UPDATEIFCOPY | OWNDATA); \n\tif (PyArray_ISNOTSWAPPED(self)) inter->flags |= NOTSWAPPED;\n inter->strides = self->strides;\n inter->shape = self->dimensions;\n inter->data = self->data;\n\tPy_INCREF(self);\n return PyCObject_FromVoidPtrAndDesc(inter, self, gentype_struct_free);\n}\n\nstatic PyObject *\narray_base_get(PyArrayObject *self)\n{\n\tif (self->base == NULL) {\n\t\tPy_INCREF(Py_None);\n\t\treturn Py_None;\n\t}\n\telse {\n\t\tPy_INCREF(self->base);\n\t\treturn self->base;\n\t}\n}\n\n\nstatic PyObject *\narray_real_get(PyArrayObject *self)\n{\n\tPyArrayObject *ret;\n\n\tif (PyArray_ISCOMPLEX(self)) {\n\t\tret = (PyArrayObject *)PyArray_New(self->ob_type,\n\t\t\t\t\t\t self->nd,\n\t\t\t\t\t\t self->dimensions,\n\t\t\t\t\t\t self->descr->type_num - \\\n\t\t\t\t\t\t PyArray_NUM_FLOATTYPE,\n\t\t\t\t\t\t self->strides,\n\t\t\t\t\t\t self->data,\n\t\t\t\t\t\t 0,\n\t\t\t\t\t\t self->flags, (PyObject *)self);\n\t\tif (ret == NULL) return NULL;\n\t\tret->flags &= ~CONTIGUOUS;\n\t\tret->flags &= ~FORTRAN;\n\t\tPy_INCREF(self);\n\t\tret->base = (PyObject *)self;\n\t\treturn (PyObject *)ret;\n\t}\n\telse {\n\t\tPy_INCREF(self);\n\t\treturn (PyObject *)self;\n\t}\n}\n\n\nstatic int\narray_real_set(PyArrayObject *self, PyObject *val)\n{\n\tPyArrayObject *ret;\n\tPyArrayObject *new;\n\tint rint;\n\n\tnew = (PyArrayObject *)PyArray_FromAny(val, NULL, 0, 0, 0, NULL);\n\tif (new == NULL) return -1;\n\t\n\tif (PyArray_ISCOMPLEX(self)) {\n\t\tret = (PyArrayObject *)PyArray_New(self->ob_type,\n\t\t\t\t\t\t self->nd,\n\t\t\t\t\t\t self->dimensions,\n\t\t\t\t\t\t self->descr->type_num - \\\n\t\t\t\t\t\t PyArray_NUM_FLOATTYPE,\n\t\t\t\t\t\t self->strides,\n\t\t\t\t\t\t self->data,\n\t\t\t\t\t\t 0,\n\t\t\t\t\t\t self->flags, (PyObject *)self);\n\t\tif (ret == NULL) {Py_DECREF(new); return -1;}\n\t\tret->flags &= ~CONTIGUOUS;\n\t\tret->flags &= ~FORTRAN;\n\t\tPy_INCREF(self);\n\t\tret->base = (PyObject *)self;\n\t}\n\telse {\n\t\tPy_INCREF(self);\n\t\tret = self;\n\t}\t\n\trint = PyArray_CopyInto(ret, new);\n\tPy_DECREF(ret);\n\tPy_DECREF(new);\n\treturn rint;\n}\n\nstatic PyObject *\narray_imag_get(PyArrayObject *self)\n{\t\n\tPyArrayObject *ret;\n PyArray_Descr *type;\n\n\tif (PyArray_ISCOMPLEX(self)) {\n\t\ttype = PyArray_DescrFromType(self->descr->type_num - \n\t\t\t\t\t PyArray_NUM_FLOATTYPE);\n\t\tret = (PyArrayObject *)\t\t\t\t\\\n\t\t\tPyArray_NewFromDescr(self->ob_type,\n\t\t\t\t\t type,\n\t\t\t\t\t self->nd,\n\t\t\t\t\t self->dimensions,\n\t\t\t\t\t self->strides,\n\t\t\t\t\t self->data + type->elsize,\n\t\t\t\t\t self->flags, (PyObject *)self);\n\t\tif (ret == NULL) return NULL;\n\t\tret->flags &= ~CONTIGUOUS;\n\t\tret->flags &= ~FORTRAN;\n\t\tPy_INCREF(self);\n\t\tret->base = (PyObject *)self;\n\t\treturn (PyObject *) ret;\n\t}\n\telse {\n\t\ttype = self->descr;\n\t\tPy_INCREF(type);\n\t\tret = (PyArrayObject *)PyArray_Zeros(self->nd, \n\t\t\t\t\t\t self->dimensions,\n\t\t\t\t\t\t type, \n\t\t\t\t\t\t PyArray_ISFORTRAN(self));\n\t\tret->flags &= ~WRITEABLE;\n\t\treturn (PyObject *)ret;\n\t}\n}\n\nstatic int\narray_imag_set(PyArrayObject *self, PyObject *val)\n{\t\n\tif (PyArray_ISCOMPLEX(self)) {\n\t\tPyArrayObject *ret;\n\t\tPyArrayObject *new;\n\t\tint rint;\n\n\t\tnew = (PyArrayObject *)PyArray_FromAny(val, NULL, 0, 0, 0, NULL); \n\t\tif (new == NULL) return -1;\n\t\tret = (PyArrayObject *)PyArray_New(self->ob_type,\n\t\t\t\t\t\t self->nd,\n\t\t\t\t\t\t self->dimensions,\n\t\t\t\t\t\t self->descr->type_num - \\\n\t\t\t\t\t\t PyArray_NUM_FLOATTYPE,\n\t\t\t\t\t\t self->strides,\n \t\t\t\t\t\t self->data +\t\t\\\n\t\t\t\t\t\t (self->descr->elsize >> 1),\n\t\t\t\t\t\t 0,\n\t\t\t\t\t\t self->flags, (PyObject *)self);\n\t\tif (ret == NULL) {\n\t\t\tPy_DECREF(new); \n\t\t\treturn -1;\n\t\t}\n\t\tret->flags &= ~CONTIGUOUS;\n\t\tret->flags &= ~FORTRAN;\n\t\tPy_INCREF(self);\n\t\tret->base = (PyObject *)self;\n\t\trint = PyArray_CopyInto(ret, new);\n\t\tPy_DECREF(ret);\t\t\n\t\tPy_DECREF(new);\n\t\treturn rint;\n\t}\n\telse {\n\t\tPyErr_SetString(PyExc_TypeError, \"does not have imaginary \" \\\n\t\t\t\t\"part to set\");\n\t\treturn -1;\n\t}\n}\n\nstatic PyObject *\narray_flat_get(PyArrayObject *self)\n{\n return PyArray_IterNew((PyObject *)self);\n}\n\nstatic int \narray_flat_set(PyArrayObject *self, PyObject *val)\n{\n\tPyObject *arr=NULL;\n\tint retval = -1;\n\tPyArrayIterObject *selfit=NULL, *arrit=NULL;\n\tPyArray_Descr *typecode;\n int swap;\n PyArray_CopySwapFunc *copyswap;\n\n\ttypecode = self->descr;\n\tPy_INCREF(typecode);\n\tarr = PyArray_FromAny(val, typecode, \n\t\t\t 0, 0, FORCECAST | FORTRAN_IF(self), NULL);\n\tif (arr == NULL) return -1;\n\tarrit = (PyArrayIterObject *)PyArray_IterNew(arr);\n\tif (arrit == NULL) goto exit;\n\tselfit = (PyArrayIterObject *)PyArray_IterNew((PyObject *)self);\n\tif (selfit == NULL) goto exit;\n\n swap = PyArray_ISNOTSWAPPED(self) != PyArray_ISNOTSWAPPED(arr);\n copyswap = self->descr->f->copyswap;\n if (PyArray_ISOBJECT(self)) {\n while(selfit->index < selfit->size) {\n Py_XDECREF(*((PyObject **)selfit->dataptr));\n Py_INCREF(*((PyObject **)arrit->dataptr)); \n memmove(selfit->dataptr, arrit->dataptr, \n sizeof(PyObject *));\n PyArray_ITER_NEXT(selfit);\n PyArray_ITER_NEXT(arrit);\n if (arrit->index == arrit->size) \n PyArray_ITER_RESET(arrit);\n }\n retval = 0; \n goto exit;\n }\n\n\twhile(selfit->index < selfit->size) {\n\t\tmemmove(selfit->dataptr, arrit->dataptr, self->descr->elsize);\n copyswap(selfit->dataptr, NULL, swap, self->descr->elsize);\n\t\tPyArray_ITER_NEXT(selfit);\n\t\tPyArray_ITER_NEXT(arrit);\n\t\tif (arrit->index == arrit->size) \n\t\t\tPyArray_ITER_RESET(arrit);\n\t}\n\tretval = 0;\n exit:\n\tPy_XDECREF(selfit);\n\tPy_XDECREF(arrit);\n\tPy_XDECREF(arr);\n\treturn retval;\n}\n\nstatic PyGetSetDef array_getsetlist[] = {\n {\"ndim\", \n\t (getter)array_ndim_get, \n\t NULL, \n\t \"number of array dimensions\"},\n {\"flags\", \n\t (getter)array_flags_get, \n NULL,\n\t \"special dictionary of flags\"},\n {\"shape\", \n\t (getter)array_shape_get, \n\t (setter)array_shape_set, \n\t \"tuple of array dimensions\"},\n {\"strides\", \n\t (getter)array_strides_get, \n\t (setter)array_strides_set,\n\t \"tuple of bytes steps in each dimension\"},\n {\"data\", \n\t (getter)array_data_get, \n\t (setter)array_data_set, \n\t \"pointer to start of data\"},\n {\"itemsize\", \n\t (getter)array_itemsize_get, \n\t NULL,\n\t \"length of one element in bytes\"},\n {\"size\",\n (getter)array_size_get,\n\t NULL,\n \"number of elements in the array\"},\n {\"nbytes\",\n (getter)array_nbytes_get,\n NULL,\n \"number of bytes in the array\"},\n\t{\"base\",\n\t (getter)array_base_get,\n\t NULL,\n\t \"base object\"},\n\t{\"dtype\",\n\t (getter)array_descr_get,\n\t (setter)array_descr_set,\n\t \"get(set) data-type-descriptor for array\"},\n {\"real\", \n\t (getter)array_real_get, \n\t (setter)array_real_set, \n\t \"real part of array\"},\n {\"imag\", \n\t (getter)array_imag_get, \n\t (setter)array_imag_set, \n\t \"imaginary part of array\"},\n\t{\"flat\", \n\t (getter)array_flat_get, \n\t (setter)array_flat_set, \n\t \"a 1-d view of a contiguous array\"}, \n\t{\"__array_data__\", \n\t (getter)array_dataptr_get,\n\t NULL,\n\t \"Array protocol: data\"},\n\t{\"__array_typestr__\",\n\t (getter)array_typestr_get,\n\t NULL,\n\t \"Array protocol: typestr\"},\n\t{\"__array_descr__\",\n\t (getter)array_protocol_descr_get,\n\t NULL,\n\t \"Array protocol: descr\"},\n\t{\"__array_shape__\", \n\t (getter)array_shape_get,\n\t NULL,\n\t \"Array protocol: shape\"},\n\t{\"__array_strides__\",\n\t (getter)array_protocol_strides_get,\n\t NULL,\n\t \"Array protocol: strides\"},\n {\"__array_struct__\",\n (getter)array_struct_get,\n NULL,\n \"Array protocol: struct\"},\n\t{\"__array_priority__\",\n\t (getter)array_priority_get,\n\t NULL,\n\t \"Array priority\"},\n \t{NULL, NULL, NULL, NULL}, /* Sentinel */\n};\n\n/****************** end of attribute get and set routines *******************/\n\n\nstatic PyObject *\narray_alloc(PyTypeObject *type, int nitems)\n{\n PyObject *obj;\n /* nitems will always be 0 */ \n obj = (PyObject *)_pya_malloc(sizeof(PyArrayObject));\n PyObject_Init(obj, type);\n return obj;\n}\n\n\nstatic char Arraytype__doc__[] = \n \"A array object represents a multidimensional, homogeneous array\\n\"\n\t\" of fixed-size items. An associated data-type-descriptor object\\n\"\n\t\" details the data-type in an array (including byteorder and any\\n\"\n\t\" fields). An array can be constructed using the numpy.array\\n\"\n\t\" command. Arrays are sequence, mapping and numeric objects.\\n\"\n\t\" More information is available in the numpy module and by looking\\n\"\n\t\" at the methods and attributes of an array.\\n\\n\"\n\t\" ndarray.__new__(subtype, shape=, dtype=int_, buffer=None, \\n\"\n\t\" offset=0, strides=None, fortran=False)\\n\\n\"\n\t\" There are two modes of creating an array using __new__:\\n\"\n\t\" 1) If buffer is None, then only shape, dtype, and fortran \\n\"\n\t\" are used\\n\"\n\t\" 2) If buffer is an object exporting the buffer interface, then\\n\"\n\t\" all keywords are interpreted.\\n\"\n\t\" The dtype parameter can be any object that can be interpreted \\n\"\n\t\" as a numpy.dtype object.\\n\\n\"\n\t\" No __init__ method is needed because the array is fully \\n\"\n\t\" initialized after the __new__ method.\";\n\t\nstatic PyTypeObject PyBigArray_Type = { \n PyObject_HEAD_INIT(NULL)\n 0,\t\t\t\t\t /*ob_size*/\n \"numpy.bigndarray\",\t\t /*tp_name*/\n sizeof(PyArrayObject),\t\t /*tp_basicsize*/\n 0,\t\t\t\t\t /*tp_itemsize*/\n /* methods */\n (destructor)array_dealloc,\t\t /*tp_dealloc */\n (printfunc)NULL,\t\t\t /*tp_print*/\n 0,\t\t\t\t\t /*tp_getattr*/\n 0,\t\t\t\t\t /*tp_setattr*/\n (cmpfunc)0, \t\t /*tp_compare*/\n (reprfunc)array_repr,\t\t /*tp_repr*/\n &array_as_number,\t\t\t /*tp_as_number*/\n NULL, \t\t\t /*tp_as_sequence*/\n &array_as_mapping,\t\t\t /*tp_as_mapping*/\n (hashfunc)0,\t\t\t /*tp_hash*/\n (ternaryfunc)0,\t\t\t /*tp_call*/\n (reprfunc)array_str, \t /*tp_str*/\n\t\t\n (getattrofunc)0,\t\t\t /*tp_getattro*/\n (setattrofunc)0,\t\t\t /*tp_setattro*/\n NULL, \t /*tp_as_buffer*/\n (Py_TPFLAGS_DEFAULT \n | Py_TPFLAGS_BASETYPE\n | Py_TPFLAGS_CHECKTYPES), /*tp_flags*/\n /*Documentation string */\n Arraytype__doc__,\t\t\t /*tp_doc*/\n\n (traverseproc)0,\t\t\t /*tp_traverse */\n (inquiry)0,\t\t\t /*tp_clear */\n (richcmpfunc)array_richcompare,\t /*tp_richcompare */\n offsetof(PyArrayObject, weakreflist), /*tp_weaklistoffset */\n\n /* Iterator support (use standard) */\n\n (getiterfunc)array_iter, \t /* tp_iter */\n (iternextfunc)0,\t\t\t /* tp_iternext */\n\n /* Sub-classing (new-style object) support */\n\n array_methods,\t\t\t /* tp_methods */\n 0,\t\t\t\t\t /* tp_members */\n array_getsetlist,\t\t /* tp_getset */\n 0,\t\t\t\t\t /* tp_base */\n 0,\t\t\t\t\t /* tp_dict */\n 0,\t\t\t\t\t /* tp_descr_get */\n 0,\t\t\t\t\t /* tp_descr_set */\n 0,\t\t\t\t\t /* tp_dictoffset */\n (initproc)0,\t \t /* tp_init */\n array_alloc,\t /* tp_alloc */ \n (newfunc)array_new,\t\t /* tp_new */\n _pya_free, \t /* tp_free */\n 0,\t\t\t\t\t /* tp_is_gc */\n 0,\t\t\t\t\t /* tp_bases */\n 0,\t\t\t\t\t /* tp_mro */\n 0,\t\t\t\t\t /* tp_cache */\n 0,\t\t\t\t\t /* tp_subclasses */\n 0\t\t\t\t\t /* tp_weaklist */\n};\n\n/* A standard array will subclass from the Big Array and \n add the array_as_sequence table\n and the array_as_buffer table\n */\n\nstatic PyTypeObject PyArray_Type = { \n PyObject_HEAD_INIT(NULL)\n 0,\t\t\t\t\t /*ob_size*/\n \"numpy.ndarray\",\t\t\t /*tp_name*/\n sizeof(PyArrayObject),\t\t /*tp_basicsize*/\n 0,\t\t\t\t\t /*tp_itemsize*/\n};\n\n\n/* The rest of this code is to build the right kind of array from a python */\n/* object. */\n\nstatic int \ndiscover_depth(PyObject *s, int max, int stop_at_string, int stop_at_tuple) \n{\n int d=0;\n PyObject *e;\n\t\n if(max < 1) return -1;\n\n if(! PySequence_Check(s) || PyInstance_Check(s) || \\\n\t PySequence_Length(s) < 0) {\n PyErr_Clear(); return 0;\n }\n if (PyArray_Check(s))\n\t\treturn PyArray_NDIM(s);\n if(PyString_Check(s) || PyBuffer_Check(s) || PyUnicode_Check(s))\n\t\treturn stop_at_string ? 0:1;\n\tif (stop_at_tuple && PyTuple_Check(s)) return 0;\n\tif ((e=PyObject_GetAttrString(s, \"__array_shape__\")) != NULL) {\n\t\tif (PyTuple_Check(e)) d=PyTuple_GET_SIZE(e);\n\t\telse d=-1;\n\t\tPy_DECREF(e);\n\t\tif (d>-1) return d;\n\t}\n\telse PyErr_Clear();\n\n if (PySequence_Length(s) == 0) \n\t\treturn 1;\t\n if ((e=PySequence_GetItem(s,0)) == NULL) return -1;\n if(e!=s) {\n\t\td=discover_depth(e, max-1, stop_at_string, stop_at_tuple);\n\t\tif(d >= 0) d++;\n\t}\n Py_DECREF(e);\n return d;\n}\n\nstatic int\ndiscover_itemsize(PyObject *s, int nd, int *itemsize) \n{\n\tint n, r, i;\n\tPyObject *e;\n\t\n\tn = PyObject_Length(s);\n\n\tif ((nd == 0) || PyString_Check(s) ||\t\t\\\n\t PyUnicode_Check(s) || PyBuffer_Check(s)) {\n\t\tif PyUnicode_Check(s) \n\t\t\t*itemsize = MAX(*itemsize, sizeof(Py_UNICODE)*n);\n\t\telse\n\t\t\t*itemsize = MAX(*itemsize, n);\n\t\treturn 0;\n\t}\n\tfor (i=0; i n_lower) n_lower = d[1];\n }\n d[1] = n_lower;\n\t\n return 0;\n}\n\n/* new reference */\n/* doesn't alter refcount of chktype or mintype --- \n unless one of them is returned */\nstatic PyArray_Descr *\n_array_small_type(PyArray_Descr *chktype, PyArray_Descr* mintype)\n{\n\tPyArray_Descr *outtype;\n\n\tif (chktype->type_num > mintype->type_num) outtype = chktype;\n\telse outtype = mintype;\n\n\tPy_INCREF(outtype);\n\tif (PyTypeNum_ISEXTENDED(outtype->type_num) &&\t\t\\\n\t (PyTypeNum_ISEXTENDED(mintype->type_num) ||\t\t\\\n\t mintype->type_num==0)) {\n\t\tint testsize = outtype->elsize;\n\t\tregister int chksize, minsize;\n\t\tchksize = chktype->elsize;\n\t\tminsize = mintype->elsize;\n\t\t/* Handle string->unicode case separately \n\t\t because string itemsize is twice as large */\n\t\tif (outtype->type_num == PyArray_UNICODE && \n\t\t mintype->type_num == PyArray_STRING) {\n\t\t\ttestsize = MAX(chksize, 2*minsize);\n\t\t}\n\t\telse {\n\t\t\ttestsize = MAX(chksize, minsize);\n\t\t}\n\t\tif (testsize != outtype->elsize) {\n\t\t\tPyArray_DESCR_REPLACE(outtype);\n\t\t\touttype->elsize = testsize;\n\t\t\tPy_XDECREF(outtype->fields);\n\t\t\touttype->fields = NULL;\n\t\t}\n\t}\n\treturn outtype;\n}\n\n/* op is an object to be converted to an ndarray. \n\n minitype is the minimum type-descriptor needed. \n \n max is the maximum number of dimensions -- used for recursive call\n to avoid infinite recursion...\n \n*/\n\nstatic PyArray_Descr *\n_array_find_type(PyObject *op, PyArray_Descr *minitype, int max)\n{\n int l;\n PyObject *ip;\n\tPyArray_Descr *chktype=NULL;\n\tPyArray_Descr *outtype;\n\t\n\tif (minitype == NULL) \n\t\tminitype = PyArray_DescrFromType(PyArray_BOOL);\n\telse Py_INCREF(minitype);\n\t\n if (max < 0) goto deflt;\n\t\n if (PyArray_Check(op)) {\n\t\tchktype = PyArray_DESCR(op);\n\t\tPy_INCREF(chktype);\n\t\tgoto finish;\n\t}\n\t\n\tif (PyArray_IsScalar(op, Generic)) {\n\t\tchktype = PyArray_DescrFromScalar(op);\n\t\tgoto finish;\n\t}\n\n\tif ((ip=PyObject_GetAttrString(op, \"__array_typestr__\"))!=NULL) {\n\t\tif (PyString_Check(ip)) {\n\t\t\tchktype =_array_typedescr_fromstr(PyString_AS_STRING(ip));\n\t\t}\n\t\tPy_DECREF(ip);\n if (chktype) goto finish;\n\t}\n\telse PyErr_Clear();\n \n if ((ip=PyObject_GetAttrString(op, \"__array_struct__\")) != NULL) {\n PyArrayInterface *inter;\n char buf[40];\n if (PyCObject_Check(ip)) {\n inter=(PyArrayInterface *)PyCObject_AsVoidPtr(ip);\n if (inter->version == 2) {\n snprintf(buf, 40, \"|%c%d\", inter->typekind, \n\t\t\t\t\t inter->itemsize);\n\t\t\t\tchktype = _array_typedescr_fromstr(buf);\n }\n }\n Py_DECREF(ip);\n if (chktype) goto finish;\n }\n\telse PyErr_Clear();\n \t\n if (PyString_Check(op)) {\n\t\tchktype = PyArray_DescrNewFromType(PyArray_STRING);\n\t\tchktype->elsize = PyString_GET_SIZE(op);\n\t\tgoto finish;\n }\n\n\tif (PyUnicode_Check(op)) {\n\t\tchktype = PyArray_DescrNewFromType(PyArray_UNICODE);\n\t\tchktype->elsize = PyUnicode_GET_DATA_SIZE(op);\n\t\tgoto finish;\n\t}\n\n\tif (PyBuffer_Check(op)) {\n\t\tchktype = PyArray_DescrNewFromType(PyArray_VOID);\n\t\tchktype->elsize = op->ob_type->tp_as_sequence->sq_length(op);\n PyErr_Clear();\n\t\tgoto finish;\n\t}\n\n if (PyObject_HasAttrString(op, \"__array__\")) {\n ip = PyObject_CallMethod(op, \"__array__\", NULL);\n if(ip && PyArray_Check(ip)) {\n\t\t\tchktype = PyArray_DESCR(ip);\n\t\t\tPy_INCREF(chktype);\n Py_DECREF(ip);\n\t\t\tgoto finish;\n\t\t}\n Py_XDECREF(ip);\n\t\tif (PyErr_Occurred()) PyErr_Clear();\n } \n\n\tif (PyInstance_Check(op)) goto deflt;\n\t\n if (PySequence_Check(op)) {\n\n l = PyObject_Length(op);\n if (l < 0 && PyErr_Occurred()) { \n\t\t\tPyErr_Clear(); \n\t\t\tgoto deflt;\n\t\t}\n if (l == 0 && minitype->type_num == PyArray_BOOL) {\n\t\t\tPy_DECREF(minitype);\n\t\t\tminitype = PyArray_DescrFromType(PyArray_INTP);\n\t\t}\n while (--l >= 0) {\n\t\t\tPyArray_Descr *newtype;\n ip = PySequence_GetItem(op, l);\n if (ip==NULL) {\n\t\t\t\tPyErr_Clear(); \n\t\t\t\tgoto deflt;\n\t\t\t}\n\t\t\tchktype = _array_find_type(ip, minitype, max-1);\n\t\t\tnewtype = _array_small_type(chktype, minitype);\n\t\t\tPy_DECREF(minitype);\n\t\t\tminitype = newtype;\n\t\t\tPy_DECREF(chktype);\n Py_DECREF(ip);\n }\n\t\tchktype = minitype;\n\t\tPy_INCREF(minitype);\n\t\tgoto finish;\n }\n\t\n\tif (PyBool_Check(op)) {\n\t\tchktype = PyArray_DescrFromType(PyArray_BOOL);\n\t\tgoto finish;\t\t\n\t}\n else if (PyInt_Check(op)) {\n\t\tchktype = PyArray_DescrFromType(PyArray_LONG);\n\t\tgoto finish;\n\t} else if (PyLong_Check(op)) {\n\t\t/* if integer can fit into a longlong then return that\n\t\t*/\n\t\tif ((PyLong_AsLongLong(op) == -1) && PyErr_Occurred()) {\n\t\t\tPyErr_Clear();\n\t\t\tgoto deflt;\n\t\t}\n\t\tchktype = PyArray_DescrFromType(PyArray_LONGLONG);\n\t\tgoto finish;\n } else if (PyFloat_Check(op)) {\n\t\tchktype = PyArray_DescrFromType(PyArray_DOUBLE);\n\t\tgoto finish;\n\t} else if (PyComplex_Check(op)) {\n\t\tchktype = PyArray_DescrFromType(PyArray_CDOUBLE);\n\t\tgoto finish;\n\t}\n\n deflt:\n\tchktype = PyArray_DescrFromType(PyArray_OBJECT);\n\t\n finish:\n\t\n\touttype = _array_small_type(chktype, minitype);\n\tPy_DECREF(chktype);\n\tPy_DECREF(minitype);\n\treturn outtype; \n}\n\nstatic int \nAssign_Array(PyArrayObject *self, PyObject *v) \n{\n PyObject *e;\n int l, r;\n\t\n if (!PySequence_Check(v)) {\n PyErr_SetString(PyExc_ValueError,\n\t\t\t\t\"assignment from non-sequence\");\n return -1;\n }\n\t\n l=PyObject_Length(v);\n if(l < 0) return -1; \n\t\n while(--l >= 0)\n {\n e=PySequence_GetItem(v,l);\n if (e == NULL) return -1; \n\t\t\tr = PySequence_SetItem((PyObject*)self,l,e);\n Py_DECREF(e);\n if(r == -1) return -1;\n }\n return 0;\n}\n\n/* \"Array Scalars don't call this code\" */ \n/* steals reference to typecode -- no NULL*/\nstatic PyObject *\nArray_FromScalar(PyObject *op, PyArray_Descr *typecode) \n{\n PyArrayObject *ret;\n\tint itemsize; \n\tint type;\n\t\n\titemsize = typecode->elsize;\n\ttype = typecode->type_num;\n\n\tif (itemsize == 0 && PyTypeNum_ISEXTENDED(type)) {\n\t\titemsize = PyObject_Length(op);\n\t\tif (type == PyArray_UNICODE) itemsize *= sizeof(Py_UNICODE);\n\t}\n\n\tret = (PyArrayObject *)PyArray_NewFromDescr(&PyArray_Type, typecode,\n\t\t\t\t\t\t 0, NULL, \n\t\t\t\t\t\t NULL, NULL, 0, NULL);\n\n\tif (ret == NULL) return NULL;\n\n ret->descr->f->setitem(op, ret->data, ret);\n\t\n if (PyErr_Occurred()) {\n Py_DECREF(ret);\n return NULL;\n } else {\n return (PyObject *)ret;\n }\n}\n\n\n/* steals reference to typecode unless return value is NULL*/\nstatic PyObject *\nArray_FromSequence(PyObject *s, PyArray_Descr *typecode, int fortran, \n\t\t int min_depth, int max_depth)\n{\n PyArrayObject *r;\n int nd;\n\tintp d[MAX_DIMS];\n\tint stop_at_string;\n\tint stop_at_tuple;\n\tint type = typecode->type_num;\n\tint itemsize = typecode->elsize;\n\tPyArray_Descr *savetype=typecode;\n\t\n\tstop_at_string = ((type == PyArray_OBJECT) ||\t\\\n\t\t\t (type == PyArray_STRING) ||\t\\\n\t\t\t (type == PyArray_UNICODE) || \\\n\t\t\t (type == PyArray_VOID));\n\n\tstop_at_tuple = (type == PyArray_VOID && ((typecode->fields &&\t\\\n\t\t\t\t\t\t typecode->fields!=Py_None) \\\n\t\t\t\t\t\t || (typecode->subarray)));\n\t\n if (!((nd=discover_depth(s, MAX_DIMS+1, stop_at_string, \n\t\t\t\t stop_at_tuple)) > 0)) {\n\t\tif (nd==0)\n\t\t\treturn Array_FromScalar(s, typecode);\n PyErr_SetString(PyExc_ValueError, \n\t\t\t\t\"invalid input sequence\");\n return NULL;\n }\n\t\n if ((max_depth && nd > max_depth) ||\t\\\n\t (min_depth && nd < min_depth)) {\n PyErr_SetString(PyExc_ValueError, \n\t\t\t\t\"invalid number of dimensions\");\n return NULL;\n }\n\t\n\tif(discover_dimensions(s,nd,d, !stop_at_string) == -1) {\n\t\treturn NULL;\n\t}\n\tif (itemsize == 0 && PyTypeNum_ISEXTENDED(type)) {\n\t\tif (discover_itemsize(s, nd, &itemsize) == -1) {\n\t\t\treturn NULL;\n\t\t}\n\t\tif (type == PyArray_UNICODE) itemsize*=sizeof(Py_UNICODE);\n\t}\n\n\tif (itemsize != typecode->elsize) {\n\t\tPyArray_DESCR_REPLACE(typecode);\n\t\ttypecode->elsize = itemsize;\n\t}\n\t\n r=(PyArrayObject*)PyArray_NewFromDescr(&PyArray_Type, typecode,\n\t\t\t\t\t nd, d, \n\t\t\t\t\t NULL, NULL,\n\t\t\t\t\t fortran, NULL);\n\t\n if(!r) {Py_XINCREF(savetype); return NULL;}\n if(Assign_Array(r,s) == -1) {\n\t\tPy_XINCREF(savetype);\n\t\tPy_DECREF(r);\n\t\treturn NULL;\n\t}\n return (PyObject*)r;\n}\n\n\n/*OBJECT_API\n Is the typenum valid?\n*/\nstatic int \nPyArray_ValidType(int type) \n{\n\tPyArray_Descr *descr;\n\tint res=TRUE;\n\t\n\tdescr = PyArray_DescrFromType(type);\n\tif (descr==NULL) res = FALSE;\n\tPy_DECREF(descr);\n\treturn res;\n}\n\n\n/* If the output is not a CARRAY, then it is buffered also */\n\nstatic int\n_bufferedcast(PyArrayObject *out, PyArrayObject *in)\n{\n\tchar *inbuffer, *bptr, *optr;\n\tchar *outbuffer=NULL;\n\tPyArrayIterObject *it_in=NULL, *it_out=NULL;\n\tregister intp i, index;\n\tintp ncopies = PyArray_SIZE(out) / PyArray_SIZE(in);\n\tint elsize=in->descr->elsize;\n\tint nels = PyArray_BUFSIZE;\n\tint el;\n\tint inswap, outswap=0;\n\tint obuf=!PyArray_ISCARRAY(out);\n\tint oelsize = out->descr->elsize;\n\tPyArray_VectorUnaryFunc *castfunc;\n PyArray_CopySwapFunc *in_csn;\n PyArray_CopySwapFunc *out_csn;\n\tint retval = -1;\n\n\tcastfunc = in->descr->f->cast[out->descr->type_num];\n in_csn = in->descr->f->copyswap;\n out_csn = out->descr->f->copyswap;\n\n\t/* If the input or output is STRING, UNICODE, or VOID */\n\t/* then getitem and setitem are used for the cast */\n\t/* and byteswapping is handled by those methods */\n\n\tinswap = !(PyArray_ISFLEXIBLE(in) || PyArray_ISNOTSWAPPED(in));\n\t\n\tinbuffer = PyDataMem_NEW(PyArray_BUFSIZE*elsize);\n\tif (inbuffer == NULL) return -1;\n\tif (PyArray_ISOBJECT(in)) \n\t\tmemset(inbuffer, 0, PyArray_BUFSIZE*elsize);\n\tit_in = (PyArrayIterObject *)PyArray_IterNew((PyObject *)in);\n\tif (it_in == NULL) goto exit;\n\n\tif (obuf) {\n\t\toutswap = !(PyArray_ISFLEXIBLE(out) || \\\n\t\t\t PyArray_ISNOTSWAPPED(out));\n\t\toutbuffer = PyDataMem_NEW(PyArray_BUFSIZE*oelsize);\n\t\tif (outbuffer == NULL) goto exit;\n\t\tif (PyArray_ISOBJECT(out))\n\t\t\tmemset(outbuffer, 0, PyArray_BUFSIZE*oelsize);\n\t\t\n\t\tit_out = (PyArrayIterObject *)PyArray_IterNew((PyObject *)out);\n\t\tif (it_out == NULL) goto exit;\n\n\t\tnels = MIN(nels, PyArray_BUFSIZE);\n\t}\n\t\n\toptr = (obuf) ? outbuffer: out->data;\n\tbptr = inbuffer;\n\tel = 0;\t\n\twhile(ncopies--) {\n\t\tindex = it_in->size;\n\t\tPyArray_ITER_RESET(it_in);\n\t\twhile(index--) {\n in_csn(bptr, it_in->dataptr, inswap, elsize);\n\t\t\tbptr += elsize;\n\t\t\tPyArray_ITER_NEXT(it_in);\n\t\t\tel += 1;\n\t\t\tif ((el == nels) || (index == 0)) {\n\t\t\t\t/* buffer filled, do cast */\n\t\t\t\t\n\t\t\t\tcastfunc(inbuffer, optr, el, in, out);\n\t\t\t\t\n\t\t\t\tif (obuf) {\n\t\t\t\t\t/* Copy from outbuffer to array */\n\t\t\t\t\tfor(i=0; idataptr,\n optr, outswap,\n oelsize);\n\t\t\t\t\t\toptr += oelsize;\n\t\t\t\t\t\tPyArray_ITER_NEXT(it_out);\n\t\t\t\t\t}\n\t\t\t\t\toptr = outbuffer;\n\t\t\t\t}\n\t\t\t\telse {\n\t\t\t\t\toptr += out->descr->elsize * nels;\n\t\t\t\t}\n\t\t\t\tel = 0;\n\t\t\t\tbptr = inbuffer;\n\t\t\t}\n\t\t}\n\t}\n\tretval = 0;\n exit:\n\tPy_XDECREF(it_in);\n\tPyDataMem_FREE(inbuffer);\n\tPyDataMem_FREE(outbuffer);\t\n\tif (obuf) {\n\t\tPy_XDECREF(it_out);\n\t}\n\treturn retval;\n}\n\n\n/* For backward compatibility */\n\n/* steals reference to at --- cannot be NULL*/\n/*OBJECT_API\n Cast an array using typecode structure.\n*/\nstatic PyObject * \nPyArray_CastToType(PyArrayObject *mp, PyArray_Descr *at, int fortran)\n{\n\tPyObject *out;\n\tint ret;\n\tPyArray_Descr *mpd;\n\n\tmpd = mp->descr;\n\n\tif (((mpd == at) || ((mpd->type_num == at->type_num) &&\t\t\\\n\t\t\t PyArray_EquivByteorders(mpd->byteorder,\\\n\t\t\t\t\t\t at->byteorder) &&\t\\\n\t\t\t ((mpd->elsize == at->elsize) ||\t\t\\\n\t\t\t (at->elsize==0)))) &&\t\t\t\\\n\t PyArray_ISBEHAVED_RO(mp)) {\n\t\tPy_DECREF(at);\n\t\tPy_INCREF(mp);\n\t\treturn (PyObject *)mp;\n\t}\n\t\t\n\tif (at->elsize == 0) {\n\t\tPyArray_DESCR_REPLACE(at);\n\t\tif (at == NULL) return NULL;\n\t\tif (mpd->type_num == PyArray_STRING &&\t\\\n\t\t at->type_num == PyArray_UNICODE)\n\t\t\tat->elsize = mpd->elsize*sizeof(Py_UNICODE);\n\t\tif (mpd->type_num == PyArray_UNICODE &&\n\t\t at->type_num == PyArray_STRING) \n\t\t\tat->elsize = mpd->elsize/sizeof(Py_UNICODE);\n\t\tif (at->type_num == PyArray_VOID)\n\t\t\tat->elsize = mpd->elsize;\n\t}\n\n\tout = PyArray_NewFromDescr(mp->ob_type, at,\n\t\t\t\t mp->nd, \n\t\t\t\t mp->dimensions, \n\t\t\t\t NULL, NULL, \n\t\t\t\t fortran,\n\t\t\t\t (PyObject *)mp);\n\n\tif (out == NULL) return NULL;\n\tret = PyArray_CastTo((PyArrayObject *)out, mp);\n\tif (ret != -1) return out;\n\t\n\tPy_DECREF(out);\n\treturn NULL;\n\t\n}\n\t \n/* The number of elements in out must be an integer multiple\n of the number of elements in mp. \n*/\n\n/*OBJECT_API\n Cast to an already created array.\n*/\nstatic int\nPyArray_CastTo(PyArrayObject *out, PyArrayObject *mp)\n{\n\n\tint simple;\n\tintp mpsize = PyArray_SIZE(mp);\n\tintp outsize = PyArray_SIZE(out);\n\n\tif (mpsize == 0) return 0;\n\tif (!PyArray_ISWRITEABLE(out)) {\n\t\tPyErr_SetString(PyExc_ValueError, \n\t\t\t\t\"output array is not writeable\");\n\t\treturn -1;\n\t}\n\tif (outsize % mpsize != 0) {\n\t\tPyErr_SetString(PyExc_ValueError, \n\t\t\t\t\"output array must have an integer-multiple\"\\\n\t\t\t\t\" of the number of elements in the input \"\\\n\t\t\t\t\"array\");\n\t\treturn -1; \n\t}\n\n\tif (out->descr->type_num >= PyArray_NTYPES) {\n\t\tPyErr_SetString(PyExc_ValueError, \n\t\t\t\t\"Can only cast to builtin types.\");\n\t\treturn -1;\n\t\t\t\t\n\t}\n\n\tsimple = ((PyArray_ISCARRAY_RO(mp) && PyArray_ISCARRAY(out)) || \\\n (PyArray_ISFARRAY_RO(mp) && PyArray_ISFARRAY(out)));\n\t\n\tif (simple) {\n\t\tchar *inptr;\n\t\tchar *optr = out->data;\n\t\tintp obytes = out->descr->elsize * outsize;\n\t\tintp ncopies = outsize / mpsize;\n\n\t\twhile(ncopies--) {\n\t\t\tinptr = mp->data;\n\t\t\tmp->descr->f->cast[out->descr->type_num](inptr, \n\t\t\t\t\t\t\t optr,\n\t\t\t\t\t\t\t mpsize,\n\t\t\t\t\t\t\t mp, out);\n\t\t\toptr += obytes;\n\t\t}\n\t\treturn 0;\n\t}\n\t\n\t/* If not a well-behaved cast, then use buffers */\n\tif (_bufferedcast(out, mp) == -1) {\n\t\treturn -1;\n\t}\n\treturn 0;\n}\n\n/* steals reference to newtype --- acc. NULL */\n/*OBJECT_API*/\nstatic PyObject *\nPyArray_FromArray(PyArrayObject *arr, PyArray_Descr *newtype, int flags) \n{\n\t\n\tPyArrayObject *ret=NULL;\n\tint type, itemsize;\n\tint copy = 0;\n\tint arrflags;\n\tPyArray_Descr *oldtype;\n\tchar *msg = \"cannot copy back to a read-only array\";\n PyTypeObject *subtype;\n\n\toldtype = PyArray_DESCR(arr);\n\n subtype = arr->ob_type;\n\t\n\tif (newtype == NULL) {newtype = oldtype; Py_INCREF(oldtype);}\n\ttype = newtype->type_num;\n\titemsize = newtype->elsize;\n\n\t/* Don't copy if sizes are compatible */\n\tif (PyArray_EquivTypes(oldtype, newtype)) {\n\t\tarrflags = arr->flags;\n\n\t\tcopy = (flags & ENSURECOPY) || \\\n\t\t\t((flags & CONTIGUOUS) && (!(arrflags & CONTIGUOUS))) \\\n\t\t\t|| ((flags & ALIGNED) && (!(arrflags & ALIGNED))) \\\n\t\t\t|| (arr->nd > 1 &&\t\t\t\t\\\n\t\t\t ((flags & FORTRAN) && (!(arrflags & FORTRAN)))) \\\n\t\t\t|| ((flags & WRITEABLE) && (!(arrflags & WRITEABLE)));\n\t\t\n\t\tif (copy) {\n if ((flags & UPDATEIFCOPY) && \\\n (!PyArray_ISWRITEABLE(arr))) {\n\t\t\t\tPy_DECREF(newtype);\n PyErr_SetString(PyExc_ValueError, msg);\n return NULL;\n }\n if ((flags & ENSUREARRAY) && \\\n (subtype != &PyBigArray_Type)) {\n subtype = &PyArray_Type;\n }\n\t\t\tret = (PyArrayObject *) \\\n\t\t\t\tPyArray_NewFromDescr(subtype, newtype,\n\t\t\t\t\t\t arr->nd, \n\t\t\t\t\t\t arr->dimensions,\n\t\t\t\t\t\t NULL, NULL, \n\t\t\t\t\t\t flags & FORTRAN,\n\t\t\t\t\t\t (PyObject *)arr);\n if (ret == NULL) return NULL;\n\t\t\tif (PyArray_CopyInto(ret, arr) == -1) \n\t\t\t\t{Py_DECREF(ret); return NULL;}\n\t\t\tif (flags & UPDATEIFCOPY) {\n\t\t\t\tret->flags |= UPDATEIFCOPY;\n\t\t\t\tret->base = (PyObject *)arr;\n PyArray_FLAGS(ret->base) &= ~WRITEABLE;\n\t\t\t\tPy_INCREF(arr);\n\t\t\t}\n\t\t} \n\t\t/* If no copy then just increase the reference\n\t\t count and return the input */\n\t\telse { \n if ((flags & ENSUREARRAY) && \\\n (subtype != &PyBigArray_Type)) {\n\t\t\t\tPy_DECREF(newtype);\n\t\t\t\tPy_INCREF(arr->descr);\n\t\t\t\tret = (PyArrayObject *)\t\t\t\\\n PyArray_NewFromDescr(&PyArray_Type,\n\t\t\t\t\t\t\t arr->descr,\n\t\t\t\t\t\t\t arr->nd,\n\t\t\t\t\t\t\t arr->dimensions,\n\t\t\t\t\t\t\t arr->strides,\n\t\t\t\t\t\t\t arr->data,\n\t\t\t\t\t\t\t arr->flags,NULL);\n if (ret == NULL) return NULL;\n ret->base = (PyObject *)arr;\n }\n else {\n ret = arr;\n }\n\t\t\tPy_INCREF(arr);\n\t\t}\n\t}\n\t\n\t/* The desired output type is different than the input\n\t array type */\n\telse {\n\t\t/* Cast to the desired type if we can do it safely\n\t\t Also cast if source is a ndim-0 array to mimic\n\t\t behavior with Python scalars */\n\t\tif (flags & FORCECAST || PyArray_NDIM(arr)==0 ||\n\t\t PyArray_CanCastTo(oldtype, newtype)) {\n if ((flags & UPDATEIFCOPY) &&\t\t\\\n (!PyArray_ISWRITEABLE(arr))) {\n\t\t\t\tPy_DECREF(newtype);\n PyErr_SetString(PyExc_ValueError, msg);\n return NULL;\n }\n if ((flags & ENSUREARRAY) && \\\n (subtype != &PyBigArray_Type)) {\n subtype = &PyArray_Type;\n }\n ret = (PyArrayObject *)\\\n PyArray_NewFromDescr(subtype, \n\t\t\t\t\t\t newtype, \n\t\t\t\t\t\t arr->nd,\n\t\t\t\t\t\t arr->dimensions, \n\t\t\t\t\t\t NULL, NULL, \n\t\t\t\t\t\t flags & FORTRAN,\n\t\t\t\t\t\t (PyObject *)arr);\n if (ret == NULL) return NULL;\n if (PyArray_CastTo(ret, arr) < 0) {\n Py_DECREF(ret);\n return NULL;\n }\n\t\t\tif (flags & UPDATEIFCOPY) {\n\t\t\t\tret->flags |= UPDATEIFCOPY;\n\t\t\t\tret->base = (PyObject *)arr;\n PyArray_FLAGS(ret->base) &= ~WRITEABLE;\n\t\t\t\tPy_INCREF(arr);\n\t\t\t}\n\t\t}\n\t\telse {\n\t\t\tPyErr_SetString(PyExc_TypeError, \n\t\t\t\t\t\"array cannot be safely cast \" \\\n\t\t\t\t\t\"to required type\");\n\t\t\tret = NULL;\n\t\t}\n\t}\n\treturn (PyObject *)ret;\n}\n\n/* new reference */\nstatic PyArray_Descr *\n_array_typedescr_fromstr(char *str)\n{\n\tPyArray_Descr *descr; \n\tint type_num;\n\tchar typechar;\n\tint size;\n\tchar msg[] = \"unsupported typestring\";\n\tint swap;\n\tchar swapchar;\n\n\tswapchar = str[0];\n\tstr += 1;\n\t\n#define _MY_FAIL {\t\t\t\t \\\n\t\tPyErr_SetString(PyExc_ValueError, msg); \\\n\t\treturn NULL;\t\t\t\t\\\n\t}\t\t\n\t\n\ttypechar = str[0];\n\tsize = atoi(str + 1);\n\tswitch (typechar) {\n\tcase 'b':\n\t\tif (size == sizeof(Bool))\n\t\t\ttype_num = PyArray_BOOL;\t \n\t\telse _MY_FAIL \n\t\t\tbreak;\t\t \n\tcase 'u':\n\t\tif (size == sizeof(uintp))\n\t\t\ttype_num = PyArray_UINTP;\n\t\telse if (size == sizeof(char))\n\t\t\ttype_num = PyArray_UBYTE;\n\t\telse if (size == sizeof(short)) \n\t\t\ttype_num = PyArray_USHORT;\n\t\telse if (size == sizeof(ulong)) \n\t\t\ttype_num = PyArray_ULONG;\n\t\telse if (size == sizeof(int)) \n\t\t\ttype_num = PyArray_UINT;\n\t\telse if (size == sizeof(ulonglong))\n\t\t\ttype_num = PyArray_ULONGLONG;\n\t\telse _MY_FAIL\n\t\t\tbreak;\t\t \n\tcase 'i':\n\t\tif (size == sizeof(intp))\n\t\t\ttype_num = PyArray_INTP;\n\t\telse if (size == sizeof(char)) \n\t\t type_num = PyArray_BYTE;\n\t\telse if (size == sizeof(short)) \n\t\t\ttype_num = PyArray_SHORT;\n\t\telse if (size == sizeof(long)) \n\t\t\ttype_num = PyArray_LONG;\n\t\telse if (size == sizeof(int))\n\t\t\ttype_num = PyArray_INT;\n\t\telse if (size == sizeof(longlong))\n\t\t\ttype_num = PyArray_LONGLONG;\n\t\telse _MY_FAIL\n\t\t\tbreak;\t\t \n\tcase 'f':\n\t\tif (size == sizeof(float))\n\t\t\ttype_num = PyArray_FLOAT;\n\t\telse if (size == sizeof(double))\n\t\t\ttype_num = PyArray_DOUBLE;\n\t\telse if (size == sizeof(longdouble))\n\t\t\ttype_num = PyArray_LONGDOUBLE;\n\t\telse _MY_FAIL\n\t\t\tbreak;\n\tcase 'c':\n\t\tif (size == sizeof(float)*2)\n\t\t\ttype_num = PyArray_CFLOAT;\n\t\telse if (size == sizeof(double)*2)\n\t\t\ttype_num = PyArray_CDOUBLE;\n\t\telse if (size == sizeof(longdouble)*2)\n\t\t\ttype_num = PyArray_CLONGDOUBLE;\n\t\telse _MY_FAIL\n\t\t\tbreak;\n\tcase 'O':\n\t\tif (size == sizeof(PyObject *))\n\t\t\ttype_num = PyArray_OBJECT;\n\t\telse _MY_FAIL\n\t\t\tbreak;\n\tcase 'S':\n\t\ttype_num = PyArray_STRING;\n\t\tbreak;\n\tcase 'U':\n\t\ttype_num = PyArray_UNICODE;\n\t\tsize *= sizeof(Py_UNICODE);\n\t\tbreak;\t \n\tcase 'V':\n\t\ttype_num = PyArray_VOID;\n\t\tbreak;\n\tdefault:\n\t\t_MY_FAIL\n\t}\n\t\n#undef _MY_FAIL\n\n descr = PyArray_DescrFromType(type_num);\n if (descr == NULL) return NULL;\n swap = !PyArray_ISNBO(swapchar);\n if (descr->elsize == 0 || swap) {\n\t /* Need to make a new PyArray_Descr */\n\t PyArray_DESCR_REPLACE(descr);\n\t if (descr==NULL) return NULL;\n\t if (descr->elsize == 0)\n\t\t descr->elsize = size;\n\t if (swap) \n\t\t descr->byteorder = swapchar;\n }\n return descr;\n}\n\n/* OBJECT_API */\nstatic PyObject *\nPyArray_FromStructInterface(PyObject *input)\n{\n\tPyArray_Descr *thetype;\n\tchar buf[40];\n\tPyArrayInterface *inter;\n\tPyObject *attr, *r;\n\tchar endian = PyArray_NATBYTE;\n \n attr = PyObject_GetAttrString(input, \"__array_struct__\");\n if (attr == NULL) {\n\t\tPyErr_Clear();\n\t\treturn Py_NotImplemented;\n\t}\n if (!PyCObject_Check(attr) || \\\n ((inter=((PyArrayInterface *)\\\n\t\t PyCObject_AsVoidPtr(attr)))->version != 2)) {\n PyErr_SetString(PyExc_ValueError, \"invalid __array_struct__\");\n\t\tPy_DECREF(attr);\n return NULL;\n }\n\tif ((inter->flags & NOTSWAPPED) != NOTSWAPPED) {\n\t\tendian = PyArray_OPPBYTE;\n\t\tinter->flags &= ~NOTSWAPPED;\n\t}\n\n snprintf(buf, 40, \"%c%c%d\", endian, inter->typekind, inter->itemsize);\n if (!(thetype=_array_typedescr_fromstr(buf))) {\n\t\tPy_DECREF(attr);\n return NULL;\n }\n\n r = PyArray_NewFromDescr(&PyArray_Type, thetype,\n\t\t\t\t inter->nd, inter->shape,\n\t\t\t\t inter->strides, inter->data,\n\t\t\t\t inter->flags, NULL);\n\tPy_INCREF(input);\n\tPyArray_BASE(r) = input;\n Py_DECREF(attr);\n PyArray_UpdateFlags((PyArrayObject *)r, UPDATE_ALL_FLAGS);\n return r;\n}\n\n/*OBJECT_API*/\nstatic PyObject *\nPyArray_FromInterface(PyObject *input)\n{\n\tPyObject *attr=NULL, *item=NULL;\n PyObject *tstr=NULL, *shape=NULL; \n PyArrayObject *ret;\n\tPyArray_Descr *type=NULL;\n\tchar *data;\n\tint buffer_len;\n\tint res, i, n;\n\tintp dims[MAX_DIMS], strides[MAX_DIMS];\n\tint dataflags = BEHAVED_FLAGS;\n\n\t/* Get the memory from __array_data__ and __array_offset__ */\n\t/* Get the shape */\n\t/* Get the typestring -- ignore array_descr */\n\t/* Get the strides */\n\t\n shape = PyObject_GetAttrString(input, \"__array_shape__\");\n if (shape == NULL) {PyErr_Clear(); return Py_NotImplemented;}\n tstr = PyObject_GetAttrString(input, \"__array_typestr__\");\n if (tstr == NULL) {Py_DECREF(shape); PyErr_Clear(); return Py_NotImplemented;}\n \n\tattr = PyObject_GetAttrString(input, \"__array_data__\");\n\tif ((attr == NULL) || (attr==Py_None) || (!PyTuple_Check(attr))) {\n\t\tif (attr && (attr != Py_None)) item=attr;\n\t\telse item=input;\n\t\tres = PyObject_AsWriteBuffer(item, (void **)&data, \n\t\t\t\t\t &buffer_len);\n\t\tif (res < 0) {\n\t\t\tPyErr_Clear();\n\t\t\tres = PyObject_AsReadBuffer(item, (const void **)&data,\n\t\t\t\t\t\t &buffer_len);\n\t\t\tif (res < 0) goto fail;\n\t\t\tdataflags &= ~WRITEABLE;\n\t\t}\n\t\tPy_XDECREF(attr);\n\t\tattr = PyObject_GetAttrString(input, \"__array_offset__\");\n\t\tif (attr) {\n\t\t\tlong num = PyInt_AsLong(attr);\n\t\t\tif (error_converting(num)) {\n\t\t\t\tPyErr_SetString(PyExc_TypeError, \n\t\t\t\t\t\t\"__array_offset__ \"\\\n\t\t\t\t\t\t\"must be an integer\");\n\t\t\t\tgoto fail;\n\t\t\t}\n\t\t\tdata += num;\n\t\t}\n\t\telse PyErr_Clear();\n\t}\n\telse {\n\t\tif (PyTuple_GET_SIZE(attr) != 2) {\n\t\t\tPyErr_SetString(PyExc_TypeError, \n\t\t\t\t\t\"__array_data__ must return \"\t\\\n\t\t\t\t\t\"a 2-tuple with ('data pointer \"\\\n\t\t\t\t\t\"string', read-only flag)\");\n\t\t\tgoto fail;\n\t\t}\n\t\tres = sscanf(PyString_AsString(PyTuple_GET_ITEM(attr,0)),\n\t\t\t \"%p\", (void **)&data);\n\t\tif (res < 1) {\n\t\t\tPyErr_SetString(PyExc_TypeError, \n\t\t\t\t\t\"__array_data__ string cannot be \" \\\n\t\t\t\t\t\"converted\");\n\t\t\tgoto fail;\n\t\t}\n\t\tif (PyObject_IsTrue(PyTuple_GET_ITEM(attr,1))) {\n\t\t\tdataflags &= ~WRITEABLE;\n\t\t}\n\t}\n\tPy_XDECREF(attr);\n\tattr = tstr;\n\tif (!PyString_Check(attr)) {\n\t\tPyErr_SetString(PyExc_TypeError, \"__array_typestr__ must be a string\");\n\t\tPy_INCREF(attr); /* decref'd twice below */\n\t\tgoto fail;\n\t}\n\ttype = _array_typedescr_fromstr(PyString_AS_STRING(attr)); \n\tPy_DECREF(attr); attr=NULL; tstr=NULL;\n\tif (type==NULL) goto fail;\n\tattr = shape;\n\tif (!PyTuple_Check(attr)) {\n\t\tPyErr_SetString(PyExc_TypeError, \"__array_shape__ must be a tuple\");\n\t\tPy_INCREF(attr); /* decref'd twice below */\n\t\tPy_DECREF(type);\n\t\tgoto fail;\n\t}\n\tn = PyTuple_GET_SIZE(attr);\n\tfor (i=0; ibase = input;\n \n\tattr = PyObject_GetAttrString(input, \"__array_strides__\");\n\tif (attr != NULL && attr != Py_None) {\n\t\tif (!PyTuple_Check(attr)) {\n\t\t\tPyErr_SetString(PyExc_TypeError, \n\t\t\t\t\t\"__array_strides__ must be a tuple\");\n\t\t\tPy_DECREF(attr);\n\t\t\tPy_DECREF(ret);\n\t\t\treturn NULL;\n\t\t}\n\t\tif (n != PyTuple_GET_SIZE(attr)) {\n\t\t\tPyErr_SetString(PyExc_ValueError, \n\t\t\t\t\t\"mismatch in length of \"\\\n\t\t\t\t\t\"__array_strides__ and \"\\\n\t\t\t\t\t\"__array_shape__\");\n\t\t\tPy_DECREF(attr);\n\t\t\tPy_DECREF(ret);\n\t\t\treturn NULL;\n\t\t}\n\t\tfor (i=0; istrides, strides, n*sizeof(intp));\n\t}\n\telse PyErr_Clear();\n\tPyArray_UpdateFlags(ret, UPDATE_ALL_FLAGS);\n\treturn (PyObject *)ret;\n\n fail:\n\tPy_XDECREF(attr);\n\tPy_XDECREF(shape);\n\tPy_XDECREF(tstr);\n\treturn NULL;\n}\n\n/* OBJECT_API*/\nstatic PyObject *\nPyArray_FromArrayAttr(PyObject *op, PyArray_Descr *typecode, PyObject *context) \n{\n PyObject *new;\n PyObject *array_meth;\n\n array_meth = PyObject_GetAttrString(op, \"__array__\");\n if (array_meth == NULL) {PyErr_Clear(); return Py_NotImplemented;}\n if (context == NULL) {\n if (typecode == NULL) new = PyObject_CallFunction(array_meth, NULL);\n else new = PyObject_CallFunction(array_meth, \"O\", typecode);\n }\n else {\n if (typecode == NULL) {\n new = PyObject_CallFunction(array_meth, \"OO\", Py_None, context);\n if (new == NULL && PyErr_ExceptionMatches(PyExc_TypeError)) {\n PyErr_Clear();\n new = PyObject_CallFunction(array_meth, \"\");\n }\n }\n else {\n new = PyObject_CallFunction(array_meth, \"OO\", typecode, context);\n if (new == NULL && PyErr_ExceptionMatches(PyExc_TypeError)) {\n PyErr_Clear();\n new = PyObject_CallFunction(array_meth, \"O\", typecode);\n }\n }\n }\n Py_DECREF(array_meth);\n if (new == NULL) return NULL;\n if (!PyArray_Check(new)) {\n PyErr_SetString(PyExc_ValueError, \n \"object __array__ method not \" \\\n \"producing an array\");\n Py_DECREF(new);\n return NULL;\n }\n return new;\n} \n\n/* Does not check for ENSURECOPY and NOTSWAPPED in flags */\n/* Steals a reference to newtype --- which can be NULL */\n/*OBJECT_API*/\nstatic PyObject *\nPyArray_FromAny(PyObject *op, PyArray_Descr *newtype, int min_depth, \n int max_depth, int flags, PyObject *context) \n{\n /* This is the main code to make a NumPy array from a Python\n Object. It is called from lot's of different places which\n is why there are so many checks. The comments try to\n explain some of the checks. */\n\n PyObject *r=NULL;\n int seq = FALSE;\n \n\t/* Is input object already an array? */\n\t/* This is where the flags are used */\n if (PyArray_Check(op)) \n\t\tr = PyArray_FromArray((PyArrayObject *)op, newtype, flags);\n\telse if (PyArray_IsScalar(op, Generic)) {\n\t\tr = PyArray_FromScalar(op, newtype);\n\t}\n else if (((r = PyArray_FromStructInterface(op))!=Py_NotImplemented)|| \\\n ((r = PyArray_FromInterface(op)) != Py_NotImplemented) || \\\n ((r = PyArray_FromArrayAttr(op, newtype, context)) \\\n != Py_NotImplemented)) {\n PyObject *new;\n if (r == NULL) return NULL;\n if (newtype != NULL || flags != 0) {\n new = PyArray_FromArray((PyArrayObject *)r, newtype, flags);\n Py_DECREF(r);\n r = new;\n }\n }\n\telse {\n\t\tif (newtype == NULL) {\n\t\t\tnewtype = _array_find_type(op, NULL, MAX_DIMS);\n\t\t}\n\t\tif (PySequence_Check(op)) {\n\t\t\t/* necessary but not sufficient */\n\t\t\t\n\t\t\tr = Array_FromSequence(op, newtype, flags & FORTRAN,\n\t\t\t\t\t min_depth, max_depth);\n\t\t\tif (PyErr_Occurred() && r == NULL)\n /* It wasn't really a sequence after all.\n * Try interpreting it as a scalar */\n PyErr_Clear();\n else\n seq = TRUE;\n }\n if (!seq)\n\t\t\tr = Array_FromScalar(op, newtype);\n\t}\n\n /* If we didn't succeed return NULL */\n if (r == NULL) return NULL;\n\t\n\t/* Be sure we succeed here */\n\t\n if(!PyArray_Check(r)) {\n PyErr_SetString(PyExc_RuntimeError, \n\t\t\t\t\"internal error: PyArray_FromAny \"\\\n\t\t\t\t\"not producing an array\");\n\t\tPy_DECREF(r);\n return NULL;\n }\n\n if (min_depth != 0 && ((PyArrayObject *)r)->nd < min_depth) {\n PyErr_SetString(PyExc_ValueError, \n \"object of too small depth for desired array\");\n Py_DECREF(r);\n return NULL;\n }\n if (max_depth != 0 && ((PyArrayObject *)r)->nd > max_depth) {\n PyErr_SetString(PyExc_ValueError, \n \"object too deep for desired array\");\n Py_DECREF(r);\n return NULL;\n }\n return r;\n}\n\n/* new reference -- accepts NULL for mintype*/\n/*OBJECT_API*/\nstatic PyArray_Descr *\nPyArray_DescrFromObject(PyObject *op, PyArray_Descr *mintype)\n{\n\treturn _array_find_type(op, mintype, MAX_DIMS);\n}\n\n/*OBJECT_API\n Return the typecode of the array a Python object would be converted\n to\n*/\nstatic int \nPyArray_ObjectType(PyObject *op, int minimum_type) \n{\n\tPyArray_Descr *intype;\n\tPyArray_Descr *outtype;\n\tint ret;\n\n\tintype = PyArray_DescrFromType(minimum_type);\n\tif (intype == NULL) PyErr_Clear();\n\touttype = _array_find_type(op, intype, MAX_DIMS);\n\tret = outtype->type_num;\n\tPy_DECREF(outtype);\n\tPy_DECREF(intype);\n\treturn ret;\n}\n\n\n/* flags is any of \n CONTIGUOUS, \n FORTRAN,\n ALIGNED, \n WRITEABLE, \n NOTSWAPPED,\n ENSURECOPY, \n UPDATEIFCOPY,\n FORCECAST,\n ENSUREARRAY\n\n or'd (|) together\n\n Any of these flags present means that the returned array should \n guarantee that aspect of the array. Otherwise the returned array\n won't guarantee it -- it will depend on the object as to whether or \n not it has such features. \n\n Note that ENSURECOPY is enough\n to guarantee CONTIGUOUS, ALIGNED and WRITEABLE\n and therefore it is redundant to include those as well. \n\n BEHAVED_FLAGS == ALIGNED | WRITEABLE\n CARRAY_FLAGS = CONTIGUOUS | BEHAVED_FLAGS\n FARRAY_FLAGS = FORTRAN | BEHAVED_FLAGS\n \n FORTRAN can be set in the FLAGS to request a FORTRAN array. \n Fortran arrays are always behaved (aligned, \n notswapped, and writeable) and not (C) CONTIGUOUS (if > 1d). \n\n UPDATEIFCOPY flag sets this flag in the returned array if a copy is\n made and the base argument points to the (possibly) misbehaved array.\n When the new array is deallocated, the original array held in base\n is updated with the contents of the new array. \n\n FORCECAST will cause a cast to occur regardless of whether or not\n it is safe. \n*/\n\n\n/* steals a reference to descr -- accepts NULL */\n/*OBJECT_API*/\nstatic PyObject *\nPyArray_CheckFromAny(PyObject *op, PyArray_Descr *descr, int min_depth, \n int max_depth, int requires, PyObject *context) \n{\n\tif (requires & NOTSWAPPED) {\n\t\tif (!descr && PyArray_Check(op) && \\\n\t\t !PyArray_ISNBO(PyArray_DESCR(op)->byteorder)) {\n\t\t\tdescr = PyArray_DescrNew(PyArray_DESCR(op));\n\t\t}\n\t\telse if ((descr && !PyArray_ISNBO(descr->byteorder))) {\n\t\t\tPyArray_DESCR_REPLACE(descr);\n\t\t}\n\t\tdescr->byteorder = PyArray_NATIVE;\n\t}\n\n\treturn PyArray_FromAny(op, descr, min_depth, max_depth,\n requires, context);\n}\n\n/* This is a quick wrapper around PyArray_FromAny(op, NULL, 0, 0, \n ENSUREARRAY) */\n/* that special cases Arrays and PyArray_Scalars up front */\n/* It *steals a reference* to the object */\n/* It also guarantees that the result is PyArray_Type or PyBigArray_Type */\n\n/* Because it decrefs op if any conversion needs to take place \n so it can be used like PyArray_EnsureArray(some_function(...)) */\n\n/*OBJECT_API*/\nstatic PyObject *\nPyArray_EnsureArray(PyObject *op)\n{\n PyObject *new;\n\n if (op == NULL) return NULL;\n\n if (PyArray_CheckExact(op) || PyBigArray_CheckExact(op)) return op;\n \n if (PyArray_IsScalar(op, Generic)) {\n new = PyArray_FromScalar(op, NULL);\n Py_DECREF(op);\n return new;\n }\n new = PyArray_FromAny(op, NULL, 0, 0, ENSUREARRAY, NULL);\n Py_DECREF(op);\n return new;\n}\n\n/*OBJECT_API\n Check the type coercion rules.\n*/\nstatic int \nPyArray_CanCastSafely(int fromtype, int totype) \n{\n\tPyArray_Descr *from, *to;\n\tregister int felsize, telsize;\n\n if (fromtype == totype) return 1;\n if (fromtype == PyArray_BOOL) return 1;\n\tif (totype == PyArray_BOOL) return 0;\n if (totype == PyArray_OBJECT || totype == PyArray_VOID) return 1;\n\tif (fromtype == PyArray_OBJECT || fromtype == PyArray_VOID) return 0;\n\n\tfrom = PyArray_DescrFromType(fromtype);\n\tto = PyArray_DescrFromType(totype);\n\ttelsize = to->elsize;\n\tfelsize = from->elsize;\n\tPy_DECREF(from);\n\tPy_DECREF(to);\n\n switch(fromtype) {\n case PyArray_BYTE:\n\tcase PyArray_SHORT:\n case PyArray_INT:\n case PyArray_LONG:\n\tcase PyArray_LONGLONG:\n\t\tif (PyTypeNum_ISINTEGER(totype)) {\n\t\t\tif (PyTypeNum_ISUNSIGNED(totype)) {\n\t\t\t\treturn (telsize > felsize);\n\t\t\t}\n\t\t\telse {\n\t\t\t\treturn (telsize >= felsize);\n\t\t\t}\n\t\t}\n\t\telse if (PyTypeNum_ISFLOAT(totype)) {\n if (felsize < 8)\n return (telsize > felsize);\n else\n return (telsize >= felsize);\n\t\t}\n\t\telse if (PyTypeNum_ISCOMPLEX(totype)) {\n if (felsize < 8)\n return ((telsize >> 1) > felsize);\n else\n return ((telsize >> 1) >= felsize);\n\t\t}\n\t\telse return totype > fromtype;\n case PyArray_UBYTE:\n case PyArray_USHORT:\n case PyArray_UINT:\n\tcase PyArray_ULONG:\n\tcase PyArray_ULONGLONG:\n\t\tif (PyTypeNum_ISINTEGER(totype)) {\n\t\t\tif (PyTypeNum_ISSIGNED(totype)) {\n\t\t\t\treturn (telsize > felsize);\n\t\t\t}\n\t\t\telse {\n\t\t\t\treturn (telsize >= felsize);\n\t\t\t}\n\t\t}\n\t\telse if (PyTypeNum_ISFLOAT(totype)) {\n if (felsize < 8)\n return (telsize > felsize);\n else\n return (telsize >= felsize);\n\t\t}\n\t\telse if (PyTypeNum_ISCOMPLEX(totype)) {\n if (felsize < 8)\n return ((telsize >> 1) > felsize);\n else\n return ((telsize >> 1) >= felsize);\n\t\t}\n\t\telse return totype > fromtype;\n case PyArray_FLOAT:\n case PyArray_DOUBLE:\n\tcase PyArray_LONGDOUBLE:\n\t\tif (PyTypeNum_ISCOMPLEX(totype)) \n\t\t\treturn ((telsize >> 1) >= felsize);\n\t\telse\n\t\t\treturn (totype > fromtype);\n case PyArray_CFLOAT:\n case PyArray_CDOUBLE:\n\tcase PyArray_CLONGDOUBLE:\n\t\treturn (totype > fromtype);\n\tcase PyArray_STRING:\n\tcase PyArray_UNICODE:\n\t\treturn (totype > fromtype);\n default:\n return 0;\n }\n}\n\n/* leaves reference count alone --- cannot be NULL*/\n/*OBJECT_API*/\nstatic Bool\nPyArray_CanCastTo(PyArray_Descr *from, PyArray_Descr *to)\n{\n\tint fromtype=from->type_num;\n\tint totype=to->type_num;\n\tBool ret;\n\n\tret = (Bool) PyArray_CanCastSafely(fromtype, totype);\n\tif (ret) { /* Check String and Unicode more closely */\n\t\tif (fromtype == PyArray_STRING) {\n\t\t\tif (totype == PyArray_STRING) {\n\t\t\t\tret = (from->elsize <= to->elsize);\n\t\t\t}\n\t\t\telse if (totype == PyArray_UNICODE) {\n\t\t\t\tret = (from->elsize * sizeof(Py_UNICODE)\\\n\t\t\t\t <= to->elsize);\n\t\t\t}\n\t\t}\n\t\telse if (fromtype == PyArray_UNICODE) {\n\t\t\tif (totype == PyArray_UNICODE) {\n\t\t\t\tret = (from->elsize <= to->elsize);\n\t\t\t}\n\t\t}\n\t\t/* TODO: If totype is STRING or unicode \n\t\t see if the length is long enough to hold the\n\t\t stringified value of the object.\t\t \n\t\t*/\n\t}\n\treturn ret;\n}\n\n\n\n/*********************** Element-wise Array Iterator ***********************/\n/* Aided by Peter J. Verveer's nd_image package and numpy's arraymap ****/\n/* and Python's array iterator ***/\n \n\n/*OBJECT_API\n Get Iterator.\n*/\nstatic PyObject *\nPyArray_IterNew(PyObject *obj)\n{\n PyArrayIterObject *it;\n\tint i, nd; \n\tPyArrayObject *ao = (PyArrayObject *)obj;\n\n if (!PyArray_Check(ao)) {\n PyErr_BadInternalCall();\n return NULL;\n }\n\n it = (PyArrayIterObject *)_pya_malloc(sizeof(PyArrayIterObject));\n PyObject_Init((PyObject *)it, &PyArrayIter_Type);\n /* it = PyObject_New(PyArrayIterObject, &PyArrayIter_Type);*/\n if (it == NULL)\n return NULL;\n\n\tnd = ao->nd;\n\tPyArray_UpdateFlags(ao, CONTIGUOUS);\n\tit->contiguous = 0;\n\tif PyArray_ISCONTIGUOUS(ao) it->contiguous = 1;\n Py_INCREF(ao);\n it->ao = ao;\n\tit->size = PyArray_SIZE(ao);\n\tit->nd_m1 = nd - 1;\n\tit->factors[nd-1] = 1;\n\tfor (i=0; i < nd; i++) {\n\t\tit->dims_m1[i] = it->ao->dimensions[i] - 1;\n\t\tit->strides[i] = it->ao->strides[i];\n\t\tit->backstrides[i] = it->strides[i] *\t\\\n\t\t\tit->dims_m1[i];\n\t\tif (i > 0)\n\t\t\tit->factors[nd-i-1] = it->factors[nd-i] *\t\\\n\t\t\t\tit->ao->dimensions[nd-i];\n\t}\n\tPyArray_ITER_RESET(it);\n\t\n return (PyObject *)it;\n}\n\n\n/*OBJECT_API\n Get Iterator that iterates over all but one axis (don't use this with\n PyArray_ITER_GOTO1D) \n*/\nstatic PyObject *\nPyArray_IterAllButAxis(PyObject *obj, int axis)\n{\n\tPyArrayIterObject *it;\n\tit = (PyArrayIterObject *)PyArray_IterNew(obj);\n\tif (it == NULL) return NULL;\n\t\n\t/* adjust so that will not iterate over axis */\n\tit->contiguous = 0;\n\tif (it->size != 0) {\n\t\tit->size /= PyArray_DIM(obj,axis);\n\t}\n\tit->dims_m1[axis] = 0;\n\tit->backstrides[axis] = 0;\n\t\n\t/* (won't fix factors so don't use\n\t PyArray_ITER_GOTO1D with this iterator) */\n\treturn (PyObject *)it;\n}\n\n/* Returns an array scalar holding the element desired */\n\nstatic PyObject *\narrayiter_next(PyArrayIterObject *it)\n{\n\tPyObject *ret;\n\n\tif (it->index < it->size) {\n\t\tret = PyArray_ToScalar(it->dataptr, it->ao);\n\t\tPyArray_ITER_NEXT(it);\n\t\treturn ret;\n\t}\n return NULL;\n}\n\nstatic void\narrayiter_dealloc(PyArrayIterObject *it)\n{\n Py_XDECREF(it->ao);\n _pya_free(it);\n}\n\nstatic int\niter_length(PyArrayIterObject *self) \n{\n return (int) self->size;\n}\n\n\nstatic PyObject *\niter_subscript_Bool(PyArrayIterObject *self, PyArrayObject *ind)\n{\n\tint index, strides, itemsize;\n\tintp count=0;\n\tchar *dptr, *optr;\n\tPyObject *r;\n\tint swap;\n PyArray_CopySwapFunc *copyswap;\n\n\n\tif (ind->nd != 1) {\n\t\tPyErr_SetString(PyExc_ValueError, \n\t\t\t\t\"boolean index array should have 1 dimension\");\n\t\treturn NULL;\n\t}\n\tindex = (ind->dimensions[0]);\n\tstrides = ind->strides[0];\n\tdptr = ind->data;\n\t/* Get size of return array */\n\twhile(index--) {\n\t\tif (*((Bool *)dptr) != 0)\n\t\t\tcount++;\n\t\tdptr += strides;\n\t}\n\titemsize = self->ao->descr->elsize;\n\tPy_INCREF(self->ao->descr);\n\tr = PyArray_NewFromDescr(self->ao->ob_type,\n\t\t\t\t self->ao->descr, 1, &count, \n\t\t\t\t NULL, NULL,\n\t\t\t\t 0, (PyObject *)self->ao);\n\tif (r==NULL) return NULL;\n\n\t/* Set up loop */\n\toptr = PyArray_DATA(r);\n\tindex = ind->dimensions[0];\n\tdptr = ind->data;\n\n copyswap = self->ao->descr->f->copyswap;\n\t/* Loop over Boolean array */\n\tswap = !(PyArray_ISNOTSWAPPED(self->ao));\n\twhile(index--) {\n\t\tif (*((Bool *)dptr) != 0) {\n copyswap(optr, self->dataptr, swap, itemsize);\n\t\t\toptr += itemsize;\n\t\t}\n\t\tdptr += strides;\n\t\tPyArray_ITER_NEXT(self);\n\t}\n\tPyArray_ITER_RESET(self);\n\treturn r;\n}\n\nstatic PyObject *\niter_subscript_int(PyArrayIterObject *self, PyArrayObject *ind)\n{\n\tintp num;\n\tPyObject *r;\n\tPyArrayIterObject *ind_it;\n\tint itemsize;\n\tint swap;\n\tchar *optr;\n\tint index;\n PyArray_CopySwapFunc *copyswap;\n\n\titemsize = self->ao->descr->elsize;\n\tif (ind->nd == 0) {\n\t\tnum = *((intp *)ind->data);\n\t\tPyArray_ITER_GOTO1D(self, num);\n\t\tr = PyArray_ToScalar(self->dataptr, self->ao);\n\t\tPyArray_ITER_RESET(self);\n\t\treturn r;\n\t}\n\t\n\tPy_INCREF(self->ao->descr);\n\tr = PyArray_NewFromDescr(self->ao->ob_type, self->ao->descr, \n\t\t\t\t ind->nd, ind->dimensions,\n\t\t\t\t NULL, NULL, \n\t\t\t\t 0, (PyObject *)self->ao);\n\tif (r==NULL) return NULL;\n\n\toptr = PyArray_DATA(r);\n\tind_it = (PyArrayIterObject *)PyArray_IterNew((PyObject *)ind);\n\tif (ind_it == NULL) {Py_DECREF(r); return NULL;}\n\tindex = ind_it->size;\n copyswap = PyArray_DESCR(r)->f->copyswap;\n swap = !PyArray_ISNOTSWAPPED(self->ao);\n\twhile(index--) {\n\t\tnum = *((intp *)(ind_it->dataptr));\n\t\tif (num < 0) num += self->size;\n\t\tif (num < 0 || num >= self->size) {\n\t\t\tPyErr_Format(PyExc_IndexError,\n\t\t\t\t \"index %d out of bounds\"\t\t\\\n\t\t\t\t \" 0<=index<%d\", (int) num, \n\t\t\t\t (int) self->size);\n\t\t\tPy_DECREF(ind_it);\n\t\t\tPy_DECREF(r);\n\t\t\tPyArray_ITER_RESET(self);\n\t\t\treturn NULL;\n\t\t}\n\t\tPyArray_ITER_GOTO1D(self, num);\n copyswap(optr, self->dataptr, swap, itemsize);\n\t\toptr += itemsize;\n\t\tPyArray_ITER_NEXT(ind_it);\n\t}\n\tPy_DECREF(ind_it);\n\tPyArray_ITER_RESET(self);\n\treturn r;\n}\n\n\nstatic PyObject *\niter_subscript(PyArrayIterObject *self, PyObject *ind)\n{\n\tPyArray_Descr *indtype=NULL;\n\tintp start, step_size;\n\tintp n_steps;\n\tPyObject *r;\n\tchar *dptr;\n\tint size;\n\tPyObject *obj = NULL;\n\tint swap;\n PyArray_CopySwapFunc *copyswap;\n\n\tif (ind == Py_Ellipsis) {\n\t\tind = PySlice_New(NULL, NULL, NULL);\n\t\tobj = iter_subscript(self, ind);\n\t\tPy_DECREF(ind);\n\t\treturn obj;\n\t}\n\tif (PyTuple_Check(ind)) {\n\t\tint len;\n\t\tlen = PyTuple_GET_SIZE(ind);\n\t\tif (len > 1) goto fail;\n\t\tind = PyTuple_GET_ITEM(ind, 0);\n\t}\n\n\t/* Tuples >1d not accepted --- i.e. no newaxis */\n\t/* Could implement this with adjusted strides\n\t and dimensions in iterator */\n\n\t/* Check for Boolean -- this is first becasue\n\t Bool is a subclass of Int */\n\tPyArray_ITER_RESET(self);\n\n\tif (PyBool_Check(ind)) {\n\t\tif (PyObject_IsTrue(ind)) {\n\t\t\treturn PyArray_ToScalar(self->dataptr, self->ao);\n\t\t}\n\t\telse { /* empty array */\n\t\t\tintp ii = 0;\n\t\t\tPy_INCREF(self->ao->descr);\n\t\t\tr = PyArray_NewFromDescr(self->ao->ob_type, \n\t\t\t\t\t\t self->ao->descr,\n\t\t\t\t\t\t 1, &ii, \n\t\t\t\t\t\t NULL, NULL, 0,\n\t\t\t\t\t\t (PyObject *)self->ao);\n\t\t\treturn r;\t\t\t\n\t\t}\n\t}\n\n\t/* Check for Integer or Slice */ \t\n\t\n\tif (PyLong_Check(ind) || PyInt_Check(ind) || PySlice_Check(ind)) {\n\t\tstart = parse_subindex(ind, &step_size, &n_steps, \n\t\t\t\t self->size);\n\t\tif (start == -1) \n\t\t\tgoto fail;\n\t\tif (n_steps == RubberIndex || n_steps == PseudoIndex) {\n\t\t\tPyErr_SetString(PyExc_IndexError, \n\t\t\t\t\t\"cannot use Ellipsis or newaxes here\");\n\t\t\tgoto fail;\n\t\t}\n\t\tPyArray_ITER_GOTO1D(self, start)\n\t\tif (n_steps == SingleIndex) { /* Integer */\n\t\t\tr = PyArray_ToScalar(self->dataptr, self->ao);\n\t\t\tPyArray_ITER_RESET(self);\n\t\t\treturn r;\n\t\t}\n\t\tsize = self->ao->descr->elsize;\n\t\tPy_INCREF(self->ao->descr);\n\t\tr = PyArray_NewFromDescr(self->ao->ob_type, \n\t\t\t\t\t self->ao->descr, \n\t\t\t\t\t 1, &n_steps, \n\t\t\t\t\t NULL, NULL,\n\t\t\t\t\t 0, (PyObject *)self->ao);\n\t\tif (r==NULL) goto fail; \n\t\tdptr = PyArray_DATA(r);\n swap = !PyArray_ISNOTSWAPPED(self->ao);\n copyswap = PyArray_DESCR(r)->f->copyswap;\n\t\twhile(n_steps--) {\n copyswap(dptr, self->dataptr, swap, size);\n\t\t\tstart += step_size;\n\t\t\tPyArray_ITER_GOTO1D(self, start)\n\t\t\tdptr += size;\n\t\t}\n\t\tPyArray_ITER_RESET(self);\n\t\treturn r;\n\t} \n\n\t/* convert to INTP array if Integer array scalar or List */\n\n\tindtype = PyArray_DescrFromType(PyArray_INTP);\n\tif (PyArray_IsScalar(ind, Integer) || PyList_Check(ind)) {\n\t\tPy_INCREF(indtype);\n\t\tobj = PyArray_FromAny(ind, indtype, 0, 0, FORCECAST, NULL);\n\t\tif (obj == NULL) goto fail;\n\t}\n\telse {\n\t\tPy_INCREF(ind);\n\t\tobj = ind;\n\t}\n\t\n\tif (PyArray_Check(obj)) {\n\t\t/* Check for Boolean object */\n\t\tif (PyArray_TYPE(obj)==PyArray_BOOL) {\n\t\t\tr = iter_subscript_Bool(self, (PyArrayObject *)obj);\n\t\t\tPy_DECREF(indtype);\n\t\t} \n\t\t/* Check for integer array */\n\t\telse if (PyArray_ISINTEGER(obj)) {\n\t\t\tPyObject *new;\n\t\t\tnew = PyArray_FromAny(obj, indtype, 0, 0, \n FORCECAST | ALIGNED, NULL);\n\t\t\tif (new==NULL) goto fail;\n Py_DECREF(obj);\n\t\t\tobj = new;\n\t\t\tr = iter_subscript_int(self, (PyArrayObject *)obj);\n\t\t}\n\t\telse {\n\t\t\tgoto fail;\n\t\t}\n\t\tPy_DECREF(obj);\n\t\treturn r;\n\t}\n\telse Py_DECREF(indtype);\n\n\n fail:\n\tif (!PyErr_Occurred())\n\t\tPyErr_SetString(PyExc_IndexError, \"unsupported iterator index\");\n\tPy_XDECREF(indtype);\n\tPy_XDECREF(obj);\n\treturn NULL;\n\n}\n\n\nstatic int\niter_ass_sub_Bool(PyArrayIterObject *self, PyArrayObject *ind,\n\t\t PyArrayIterObject *val, int swap)\n{\n\tint index, strides, itemsize;\n\tchar *dptr;\n PyArray_CopySwapFunc *copyswap;\n\n\tif (ind->nd != 1) {\n\t\tPyErr_SetString(PyExc_ValueError, \n\t\t\t\t\"boolean index array should have 1 dimension\");\n\t\treturn -1;\n\t}\n\titemsize = self->ao->descr->elsize;\n\tindex = ind->dimensions[0];\n\tstrides = ind->strides[0];\n\tdptr = ind->data;\n\tPyArray_ITER_RESET(self);\n\t/* Loop over Boolean array */\n copyswap = self->ao->descr->f->copyswap;\n\twhile(index--) {\n\t\tif (*((Bool *)dptr) != 0) {\n copyswap(self->dataptr, val->dataptr, swap,\n\t\t\t\t itemsize);\n\t\t\tPyArray_ITER_NEXT(val);\n\t\t\tif (val->index==val->size) \n\t\t\t\tPyArray_ITER_RESET(val);\n\t\t}\n\t\tdptr += strides;\n\t\tPyArray_ITER_NEXT(self);\n\t}\n\tPyArray_ITER_RESET(self);\n\treturn 0;\n}\n\nstatic int\niter_ass_sub_int(PyArrayIterObject *self, PyArrayObject *ind,\n\t\t PyArrayIterObject *val, int swap)\n{\n\tPyArray_Descr *typecode;\n\tintp num;\n\tPyArrayIterObject *ind_it;\n\tint itemsize;\n\tint index;\n PyArray_CopySwapFunc *copyswap;\n\n\ttypecode = self->ao->descr;\n\titemsize = typecode->elsize;\n copyswap = self->ao->descr->f->copyswap;\n\tif (ind->nd == 0) {\n\t\tnum = *((intp *)ind->data);\n\t\tPyArray_ITER_GOTO1D(self, num);\n copyswap(self->dataptr, val->dataptr, swap, itemsize);\n\t\treturn 0;\n\t}\n\tind_it = (PyArrayIterObject *)PyArray_IterNew((PyObject *)ind);\n\tif (ind_it == NULL) return -1;\n\tindex = ind_it->size;\n\twhile(index--) {\n\t\tnum = *((intp *)(ind_it->dataptr));\n\t\tif (num < 0) num += self->size;\n\t\tif ((num < 0) || (num >= self->size)) {\n\t\t\tPyErr_Format(PyExc_IndexError,\n\t\t\t\t \"index %d out of bounds\"\t\t\\\n\t\t\t\t \" 0<=index<%d\", (int) num, \n\t\t\t\t (int) self->size);\n\t\t\tPy_DECREF(ind_it);\n\t\t\treturn -1;\n\t\t}\n\t\tPyArray_ITER_GOTO1D(self, num);\n copyswap(self->dataptr, val->dataptr, swap, itemsize);\n\t\tPyArray_ITER_NEXT(ind_it);\n\t\tPyArray_ITER_NEXT(val);\n\t\tif (val->index == val->size) \n\t\t\tPyArray_ITER_RESET(val);\n\t}\n\tPy_DECREF(ind_it);\n\treturn 0;\n}\n\nstatic int\niter_ass_subscript(PyArrayIterObject *self, PyObject *ind, PyObject *val) \n{\n\tPyObject *arrval=NULL;\n\tPyArrayIterObject *val_it=NULL;\n\tPyArray_Descr *type;\n\tPyArray_Descr *indtype=NULL;\n\tint swap, retval=-1;\n\tint itemsize;\n\tintp start, step_size;\n\tintp n_steps;\n\tPyObject *obj=NULL;\n PyArray_CopySwapFunc *copyswap;\n\n\t\n\tif (ind == Py_Ellipsis) {\n\t\tind = PySlice_New(NULL, NULL, NULL);\n\t\tretval = iter_ass_subscript(self, ind, val);\n\t\tPy_DECREF(ind);\n\t\treturn retval;\n\t}\n\n\tif (PyTuple_Check(ind)) {\n\t\tint len;\n\t\tlen = PyTuple_GET_SIZE(ind);\n\t\tif (len > 1) goto finish;\n\t\tind = PyTuple_GET_ITEM(ind, 0);\n\t}\n\n\ttype = self->ao->descr;\n\titemsize = type->elsize;\n\t\n\tPy_INCREF(type);\n\tarrval = PyArray_FromAny(val, type, 0, 0, 0, NULL);\n\tif (arrval==NULL) return -1;\n\tval_it = (PyArrayIterObject *)PyArray_IterNew(arrval);\n\tif (val_it==NULL) goto finish;\n\n\t/* Check for Boolean -- this is first becasue\n\t Bool is a subclass of Int */\n\n copyswap = PyArray_DESCR(arrval)->f->copyswap;\n\tswap = (PyArray_ISNOTSWAPPED(self->ao)!=PyArray_ISNOTSWAPPED(arrval));\n\tif (PyBool_Check(ind)) {\n\t\tif (PyObject_IsTrue(ind)) {\n copyswap(self->dataptr, PyArray_DATA(arrval), \n swap, itemsize);\n\t\t}\n\t\tretval=0;\n\t\tgoto finish;\n\t}\n\n\t/* Check for Integer or Slice */\n\t\n\tif (PyLong_Check(ind) || PyInt_Check(ind) || PySlice_Check(ind)) {\n\t\tstart = parse_subindex(ind, &step_size, &n_steps, \n\t\t\t\t self->size);\n\t\tif (start == -1) goto finish;\n\t\tif (n_steps == RubberIndex || n_steps == PseudoIndex) {\n\t\t\tPyErr_SetString(PyExc_IndexError, \n\t\t\t\t\t\"cannot use Ellipsis or newaxes here\");\n\t\t\tgoto finish;\n\t\t}\n\t\tPyArray_ITER_GOTO1D(self, start);\n\t\tif (n_steps == SingleIndex) { /* Integer */\n copyswap(self->dataptr, PyArray_DATA(arrval),\n swap, itemsize);\n\t\t\tPyArray_ITER_RESET(self);\n\t\t\tretval=0;\n\t\t\tgoto finish;\n\t\t}\n\t\twhile(n_steps--) {\n copyswap(self->dataptr, val_it->dataptr,\n swap, itemsize);\n\t\t\tstart += step_size;\n\t\t\tPyArray_ITER_GOTO1D(self, start)\n\t\t\tPyArray_ITER_NEXT(val_it);\n\t\t\tif (val_it->index == val_it->size) \n\t\t\t\tPyArray_ITER_RESET(val_it);\n\t\t}\n\t\tPyArray_ITER_RESET(self);\n\t\tretval = 0;\n\t\tgoto finish;\n\t} \n\n\t/* convert to INTP array if Integer array scalar or List */\n\n\tindtype = PyArray_DescrFromType(PyArray_INTP);\n\tif (PyArray_IsScalar(ind, Integer)) {\n\t\tPy_INCREF(indtype);\n\t\tobj = PyArray_FromScalar(ind, indtype);\n\t}\n\telse if (PyList_Check(ind)) {\n\t\tPy_INCREF(indtype);\n\t\tobj = PyArray_FromAny(ind, indtype, 0, 0, FORCECAST, NULL);\n\t}\n\telse {\n\t\tPy_INCREF(ind);\n\t\tobj = ind;\n\t}\n\t\n\tif (PyArray_Check(obj)) {\n\t\t/* Check for Boolean object */\n\t\tif (PyArray_TYPE(obj)==PyArray_BOOL) {\n\t\t\tif (iter_ass_sub_Bool(self, (PyArrayObject *)obj,\n\t\t\t\t\t val_it, swap) < 0)\n\t\t\t\tgoto finish;\n\t\t\tretval=0;\n\t\t} \n\t\t/* Check for integer array */\n\t\telse if (PyArray_ISINTEGER(obj)) {\n\t\t\tPyObject *new;\n\t\t\tPy_INCREF(indtype);\n\t\t\tnew = PyArray_CheckFromAny(obj, indtype, 0, 0, \n FORCECAST | BEHAVED_NS_FLAGS, NULL);\n\t\t\tPy_DECREF(obj);\n\t\t\tobj = new;\n\t\t\tif (new==NULL) goto finish;\n\t\t\tif (iter_ass_sub_int(self, (PyArrayObject *)obj,\n\t\t\t\t\t val_it, swap) < 0)\n\t\t\t\tgoto finish;\n\t\t\tretval=0;\n\t\t}\n\t}\n\n finish:\n\tif (!PyErr_Occurred() && retval < 0)\n\t\tPyErr_SetString(PyExc_IndexError, \n\t\t\t\t\"unsupported iterator index\");\n\tPy_XDECREF(indtype);\n\tPy_XDECREF(obj);\n\tPy_XDECREF(val_it);\n\tPy_XDECREF(arrval);\n\treturn retval;\n\t\n}\n\n\nstatic PyMappingMethods iter_as_mapping = {\n (inquiry)iter_length,\t\t /*mp_length*/\n (binaryfunc)iter_subscript,\t /*mp_subscript*/\n (objobjargproc)iter_ass_subscript,\t/*mp_ass_subscript*/\n};\n\nstatic char doc_iter_array[] = \"__array__(type=None)\\n Get array \"\\\n \"from iterator\";\n\nstatic PyObject *\niter_array(PyArrayIterObject *it, PyObject *op) \n{\n \n PyObject *r;\n intp size;\n\n /* Any argument ignored */\n\n /* Two options: \n 1) underlying array is contiguous\n -- return 1-d wrapper around it \n 2) underlying array is not contiguous\n -- make new 1-d contiguous array with updateifcopy flag set\n to copy back to the old array\n */\n\n size = PyArray_SIZE(it->ao);\n\tPy_INCREF(it->ao->descr);\n if (PyArray_ISCONTIGUOUS(it->ao)) {\n r = PyArray_NewFromDescr(it->ao->ob_type, \n\t\t\t\t\t it->ao->descr,\n\t\t\t\t\t 1, &size, \n\t\t\t\t\t NULL, it->ao->data, \n\t\t\t\t\t it->ao->flags,\n\t\t\t\t\t (PyObject *)it->ao); \n\t\tif (r==NULL) return NULL;\n }\n else {\n r = PyArray_NewFromDescr(it->ao->ob_type, \n\t\t\t\t\t it->ao->descr,\n\t\t\t\t\t 1, &size, \n\t\t\t\t\t NULL, NULL, \n\t\t\t\t\t 0, (PyObject *)it->ao);\n\t\tif (r==NULL) return NULL;\n\t\tif (PyArray_CopyInto((PyArrayObject *)r, it->ao) < 0) {\n\t\t\tPy_DECREF(r); \n\t\t\treturn NULL;\n\t\t}\n PyArray_FLAGS(r) |= UPDATEIFCOPY;\n it->ao->flags &= ~WRITEABLE;\n }\n Py_INCREF(it->ao);\n PyArray_BASE(r) = (PyObject *)it->ao;\n return r;\n \n}\n\nstatic char doc_iter_copy[] = \"copy()\\n Get a copy of 1-d array\";\n\nstatic PyObject *\niter_copy(PyArrayIterObject *it, PyObject *args)\n{\n if (!PyArg_ParseTuple(args, \"\")) return NULL;\t\n\treturn PyArray_Flatten(it->ao, 0);\n}\n\nstatic PyMethodDef iter_methods[] = {\n /* to get array */\n {\"__array__\", (PyCFunction)iter_array, 1, doc_iter_array},\n\t{\"copy\", (PyCFunction)iter_copy, 1, doc_iter_copy},\n {NULL,\t\tNULL}\t\t/* sentinel */\n};\n\nstatic PyMemberDef iter_members[] = {\n\t{\"base\", T_OBJECT, offsetof(PyArrayIterObject, ao), RO, NULL},\n {\"index\", T_INT, offsetof(PyArrayIterObject, index), RO, NULL},\n\t{NULL},\n};\n\nstatic PyObject *\niter_coords_get(PyArrayIterObject *self)\n{\n int nd;\n nd = self->ao->nd;\n if (self->contiguous) { /* coordinates not kept track of --- need to generate\n from index */\n intp val;\n int i;\n val = self->index;\n for (i=0;icoordinates[i] = val / self->factors[i];\n val = val % self->factors[i];\n }\n }\n return PyArray_IntTupleFromIntp(nd, self->coordinates);\n}\n\nstatic PyGetSetDef iter_getsets[] = {\n\t{\"coords\", \n\t (getter)iter_coords_get,\n\t NULL,\n\t \"An N-d tuple of current coordinates.\"},\n\t{NULL, NULL, NULL, NULL},\n};\n\nstatic PyTypeObject PyArrayIter_Type = {\n PyObject_HEAD_INIT(NULL)\n 0,\t\t\t\t\t /* ob_size */\n \"numpy.flatiter\",\t\t /* tp_name */\n sizeof(PyArrayIterObject), /* tp_basicsize */\n 0,\t\t\t\t\t /* tp_itemsize */\n /* methods */\n (destructor)arrayiter_dealloc,\t\t/* tp_dealloc */\n 0,\t\t\t\t\t/* tp_print */\n 0,\t\t\t\t\t/* tp_getattr */\n 0,\t\t\t\t\t/* tp_setattr */\n 0,\t\t\t\t\t/* tp_compare */\n 0,\t\t\t\t\t/* tp_repr */\n 0,\t\t\t\t\t/* tp_as_number */\n 0, \t\t\t /* tp_as_sequence */\n &iter_as_mapping, \t /* tp_as_mapping */\n 0,\t\t\t\t\t/* tp_hash */\n 0,\t\t\t\t\t/* tp_call */\n 0,\t\t\t\t\t/* tp_str */\n 0,\t \t/* tp_getattro */\n 0,\t\t\t\t\t/* tp_setattro */\n 0,\t\t\t\t\t/* tp_as_buffer */\n Py_TPFLAGS_DEFAULT, /* tp_flags */\n 0,\t\t\t\t\t/* tp_doc */\n 0, \t /* tp_traverse */\n 0,\t\t\t\t\t/* tp_clear */\n 0,\t\t\t\t\t/* tp_richcompare */\n 0,\t\t\t\t\t/* tp_weaklistoffset */\n 0, \t /* tp_iter */\n (iternextfunc)arrayiter_next,\t\t/* tp_iternext */\n iter_methods,\t\t\t\t/* tp_methods */\n iter_members,\t \t /* tp_members */\n iter_getsets, /* tp_getset */\n\n};\n\n/** END of Array Iterator **/\n\n\n\n/*********************** Subscript Array Iterator *************************\n * *\n * This object handles subscript behavior for array objects. *\n * It is an iterator object with a next method *\n * It abstracts the n-dimensional mapping behavior to make the looping *\n * code more understandable (maybe) *\n * and so that indexing can be set up ahead of time *\n */ \n\n/* convert an indexing object to an INTP indexing array iterator\n if possible -- otherwise, it is a Slice or Ellipsis object\n and has to be interpreted on bind to a particular \n array so leave it NULL for now.\n */\nstatic int\n_convert_obj(PyObject *obj, PyArrayIterObject **iter)\n{\n\tPyArray_Descr *indtype;\n\tPyObject *arr;\n\n\tif (PySlice_Check(obj) || (obj == Py_Ellipsis))\n\t\t*iter = NULL;\n\telse {\n\t\tindtype = PyArray_DescrFromType(PyArray_INTP);\n\t\tarr = PyArray_FromAny(obj, indtype, 0, 0, FORCECAST, NULL);\n\t\tif (arr == NULL) return -1;\n\t\t*iter = (PyArrayIterObject *)PyArray_IterNew(arr);\n\t\tPy_DECREF(arr);\n\t\tif (*iter == NULL) return -1;\n\t}\n\treturn 0;\n}\n\n/* Adjust dimensionality and strides for index object iterators \n --- i.e. broadcast\n */\n/*OBJECT_API*/\nstatic int\nPyArray_Broadcast(PyArrayMultiIterObject *mit)\n{\n\tint i, nd, k, j;\n\tintp tmp;\n\tPyArrayIterObject *it;\n\t\n\t/* Discover the broadcast number of dimensions */\n\tfor (i=0, nd=0; inumiter; i++) \n\t\tnd = MAX(nd, mit->iters[i]->ao->nd);\n\tmit->nd = nd;\n\n\t/* Discover the broadcast shape in each dimension */\n\tfor (i=0; idimensions[i] = 1;\n\t\tfor (j=0; jnumiter; j++) {\n\t\t\tit = mit->iters[j];\n\t\t\t/* This prepends 1 to shapes not already \n\t\t\t equal to nd */\n\t\t\tk = i + it->ao->nd - nd;\n\t\t\tif (k>=0) {\n\t\t\t\ttmp = it->ao->dimensions[k];\n\t\t\t\tif (tmp == 1) continue;\n\t\t\t\tif (mit->dimensions[i] == 1) \n\t\t\t\t\tmit->dimensions[i] = tmp;\n\t\t\t\telse if (mit->dimensions[i] != tmp) {\n\t\t\t\t\tPyErr_SetString(PyExc_ValueError, \n\t\t\t\t\t\t\t\"index objects are \" \\\n\t\t\t\t\t\t\t\"not broadcastable \" \\\n\t\t\t\t\t\t\t\"to a single shape\");\n\t\t\t\t\treturn -1;\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t}\n\n\t/* Reset the iterator dimensions and strides of each iterator\n\t object -- using 0 valued strides for broadcasting */\n\n\ttmp = PyArray_MultiplyList(mit->dimensions, mit->nd);\n\tmit->size = tmp;\n\tfor (i=0; inumiter; i++) {\n\t\tit = mit->iters[i];\n\t\tit->nd_m1 = mit->nd - 1;\n\t\tit->size = tmp;\n\t\tnd = it->ao->nd;\n\t\tit->factors[mit->nd-1] = 1;\n\t\tfor (j=0; j < mit->nd; j++) {\n\t\t\tit->dims_m1[j] = mit->dimensions[j] - 1;\n\t\t\tk = j + nd - mit->nd;\n\t\t\t/* If this dimension was added or shape\n\t\t\t of underlying array was 1 */\n\t\t\tif ((k < 0) || \\\n\t\t\t it->ao->dimensions[k] != mit->dimensions[j]) {\n\t\t\t\tit->contiguous = 0;\n\t\t\t\tit->strides[j] = 0;\n\t\t\t}\n\t\t\telse {\n\t\t\t\tit->strides[j] = it->ao->strides[k];\n\t\t\t}\n\t\t\tit->backstrides[j] = it->strides[j] *\t\\\n\t\t\t\tit->dims_m1[j];\n\t\t\tif (j > 0)\n\t\t\t\tit->factors[mit->nd-j-1] =\t\t\\\n\t\t\t\t\tit->factors[mit->nd-j] *\t\\\n\t\t\t\t\tmit->dimensions[mit->nd-j];\n\t\t}\n\t\tPyArray_ITER_RESET(it);\n\t}\n\treturn 0;\n}\n\n/* Reset the map iterator to the beginning */\nstatic void\nPyArray_MapIterReset(PyArrayMapIterObject *mit)\n{\n\tint i,j; intp coord[MAX_DIMS];\n\tPyArrayIterObject *it;\n\tPyArray_CopySwapFunc *copyswap;\n\n\tmit->index = 0;\n\n\tcopyswap = mit->iters[0]->ao->descr->f->copyswap;\n\n\tif (mit->subspace != NULL) {\n\t\tmemcpy(coord, mit->bscoord, sizeof(intp)*mit->ait->ao->nd);\n\t\tPyArray_ITER_RESET(mit->subspace);\n\t\tfor (i=0; inumiter; i++) {\n\t\t\tit = mit->iters[i];\n\t\t\tPyArray_ITER_RESET(it);\n\t\t\tj = mit->iteraxes[i];\n\t\t\tcopyswap(coord+j,it->dataptr,\n\t\t\t\t !PyArray_ISNOTSWAPPED(it->ao),\n\t\t\t\t sizeof(intp));\n\t\t}\n\t\tPyArray_ITER_GOTO(mit->ait, coord);\n\t\tmit->subspace->dataptr = mit->ait->dataptr;\n\t\tmit->dataptr = mit->subspace->dataptr;\n\t}\n\telse {\n\t\tfor (i=0; inumiter; i++) {\n\t\t\tit = mit->iters[i];\n\t\t\tPyArray_ITER_RESET(it);\n\t\t\tcopyswap(coord+i,it->dataptr, \n\t\t\t\t !PyArray_ISNOTSWAPPED(it->ao),\n\t\t\t\t sizeof(intp));\n\t\t}\n\t\tPyArray_ITER_GOTO(mit->ait, coord);\n\t\tmit->dataptr = mit->ait->dataptr;\n\t}\n\treturn;\n}\n\n/* This function needs to update the state of the map iterator\n and point mit->dataptr to the memory-location of the next object\n*/\nstatic void\nPyArray_MapIterNext(PyArrayMapIterObject *mit)\n{\n\tint i, j;\n\tintp coord[MAX_DIMS];\n\tPyArrayIterObject *it;\n\tPyArray_CopySwapFunc *copyswap;\n\n\tmit->index += 1;\n\tif (mit->index >= mit->size) return;\n\tcopyswap = mit->iters[0]->ao->descr->f->copyswap;\n\t/* Sub-space iteration */\n\tif (mit->subspace != NULL) {\n\t\tPyArray_ITER_NEXT(mit->subspace);\n\t\tif (mit->subspace->index == mit->subspace->size) {\n\t\t\t/* reset coord to coordinates of \n\t\t\t beginning of the subspace */\n\t\t\tmemcpy(coord, mit->bscoord, \n\t\t\t sizeof(intp)*mit->ait->ao->nd);\n\t\t\tPyArray_ITER_RESET(mit->subspace);\n\t\t\tfor (i=0; inumiter; i++) {\n\t\t\t\tit = mit->iters[i];\n\t\t\t\tPyArray_ITER_NEXT(it);\n\t\t\t\tj = mit->iteraxes[i];\n\t\t\t\tcopyswap(coord+j,it->dataptr,\n\t\t\t\t\t !PyArray_ISNOTSWAPPED(it->ao),\n\t\t\t\t\t sizeof(intp));\n\t\t\t}\n\t\t\tPyArray_ITER_GOTO(mit->ait, coord);\n\t\t\tmit->subspace->dataptr = mit->ait->dataptr;\n\t\t}\n\t\tmit->dataptr = mit->subspace->dataptr;\n\t}\n\telse {\n\t\tfor (i=0; inumiter; i++) {\n\t\t\tit = mit->iters[i];\n\t\t\tPyArray_ITER_NEXT(it);\n\t\t\tcopyswap(coord+i,it->dataptr, \n\t\t\t\t !PyArray_ISNOTSWAPPED(it->ao),\n\t\t\t\t sizeof(intp));\n\t\t}\n\t\tPyArray_ITER_GOTO(mit->ait, coord);\n\t\tmit->dataptr = mit->ait->dataptr;\n\t}\n\treturn;\n}\n\n/* Bind a mapiteration to a particular array */\n\n/* Determine if subspace iteration is necessary. If so, \n 1) Fill in mit->iteraxes\n\t 2) Create subspace iterator\n\t 3) Update nd, dimensions, and size. \n\n Subspace iteration is necessary if: arr->nd > mit->numiter\n*/\n\n/* Need to check for index-errors somewhere. \n\n Let's do it at bind time and also convert all <0 values to >0 here\n as well. \n*/\nstatic void\nPyArray_MapIterBind(PyArrayMapIterObject *mit, PyArrayObject *arr)\n{\n\tint subnd;\n\tPyObject *sub, *obj=NULL;\n\tint i, j, n, curraxis, ellipexp, noellip;\n\tPyArrayIterObject *it;\n\tintp dimsize;\n\tintp *indptr;\n\t\n\tsubnd = arr->nd - mit->numiter;\n\tif (subnd < 0) {\n\t\tPyErr_SetString(PyExc_ValueError, \n\t\t\t\t\"too many indices for array\");\n\t\treturn;\n\t}\n\n\tmit->ait = (PyArrayIterObject *)PyArray_IterNew((PyObject *)arr);\n\tif (mit->ait == NULL) return;\n\n\t/* If this is just a view, then do nothing more */\n\t/* views are handled by just adjusting the strides\n\t and dimensions of the object.\n\t*/\n\t \n\t/* no subspace iteration needed. Finish up and Return */\n\tif (subnd == 0) {\n\t\tn = arr->nd;\n\t\tfor (i=0; iiteraxes[i] = i;\n\t\t}\n\t\tgoto finish;\n\t}\n\n\t/* all indexing arrays have been converted to 0 \n\t therefore we can extract the subspace with a simple\n\t getitem call which will use view semantics\n\t*/\n\t\n\tsub = PyObject_GetItem((PyObject *)arr, mit->indexobj);\n\tif (sub == NULL) goto fail;\n\tmit->subspace = (PyArrayIterObject *)PyArray_IterNew(sub);\n\tPy_DECREF(sub);\n\tif (mit->subspace == NULL) goto fail;\n\t\n\t/* Expand dimensions of result */\n\tn = mit->subspace->ao->nd;\n\tfor (i=0; idimensions[mit->nd+i] = mit->subspace->ao->dimensions[i];\n\tmit->nd += n;\n\n\t/* Now, we still need to interpret the ellipsis and slice objects \n\t to determine which axes the indexing arrays are referring to\n\t*/\n\tn = PyTuple_GET_SIZE(mit->indexobj);\n\n\t/* The number of dimensions an ellipsis takes up */\n\tellipexp = arr->nd - n + 1;\n\t/* Now fill in iteraxes -- remember indexing arrays have been \n converted to 0's in mit->indexobj */\n\tcurraxis = 0;\n\tj = 0;\n\tnoellip = 1; /* Only expand the first ellipsis */\n\tmemset(mit->bscoord, 0, sizeof(intp)*arr->nd);\n\tfor (i=0; iindexobj, i);\n\t\tif (PyInt_Check(obj) || PyLong_Check(obj)) \n\t\t\tmit->iteraxes[j++] = curraxis++;\n\t\telse if (noellip && obj == Py_Ellipsis) {\n\t\t\tcurraxis += ellipexp;\n\t\t\tnoellip = 0;\n\t\t}\n\t\telse {\n\t\t\tintp start=0;\n\t\t\tintp stop, step;\n\t\t\t/* Should be slice object or\n\t\t\t another Ellipsis */\n\t\t\tif (obj == Py_Ellipsis) {\n\t\t\t\tmit->bscoord[curraxis] = 0;\n\t\t\t}\n\t\t\telse if (!PySlice_Check(obj) || \\\n\t\t\t\t (slice_GetIndices((PySliceObject *)obj, \n\t\t\t\t\t\t arr->dimensions[curraxis],\n\t\t\t\t\t\t &start, &stop, &step,\n\t\t\t\t\t\t &dimsize) < 0)) {\n\t\t\t\tPyErr_Format(PyExc_ValueError, \n\t\t\t\t\t \"unexpected object \"\t\\\n\t\t\t\t\t \"(%s) in selection position %d\",\n\t\t\t\t\t obj->ob_type->tp_name, i);\n\t\t\t goto fail;\n\t\t\t}\n\t\t\telse {\n\t\t\t\tmit->bscoord[curraxis] = start;\n\t\t\t}\n\t\t\tcurraxis += 1; \n\t\t}\n\t}\n finish:\n\t/* Here check the indexes (now that we have iteraxes) */\n\tmit->size = PyArray_MultiplyList(mit->dimensions, mit->nd);\n\tfor (i=0; inumiter; i++) {\n\t\tit = mit->iters[i];\n\t\tPyArray_ITER_RESET(it);\n\t\tdimsize = arr->dimensions[mit->iteraxes[i]];\n\t\twhile(it->index < it->size) {\n\t\t\tindptr = ((intp *)it->dataptr);\n\t\t\tif (*indptr < 0) *indptr += dimsize;\n\t\t\tif (*indptr < 0 || *indptr >= dimsize) {\n\t\t\t\tPyErr_Format(PyExc_IndexError,\n\t\t\t\t\t \"index (%d) out of range \"\\\n\t\t\t\t\t \"(0<=index<=%d) in dimension %d\",\n\t\t\t\t\t (int) *indptr, (int) (dimsize-1), \n\t\t\t\t\t mit->iteraxes[i]);\n\t\t\t\tgoto fail;\n\t\t\t}\n\t\t\tPyArray_ITER_NEXT(it);\n\t\t} \n\t\tPyArray_ITER_RESET(it);\n\t}\n\treturn;\n\n fail:\n\tPy_XDECREF(mit->subspace);\n\tPy_XDECREF(mit->ait);\n\tmit->subspace = NULL;\n\tmit->ait = NULL;\n\treturn;\n}\n\n/* This function takes a Boolean array and constructs index objects and\n iterators as if nonzero(Bool) had been called\n*/\nstatic int\n_nonzero_indices(PyObject *myBool, PyArrayIterObject **iters)\n{\n\tPyArray_Descr *typecode;\n\tPyArrayObject *ba =NULL, *new=NULL;\n\tint nd, j;\n\tintp size, i, count;\n\tBool *ptr;\n\tintp coords[MAX_DIMS], dims_m1[MAX_DIMS];\n\tintp *dptr[MAX_DIMS];\n\n\ttypecode=PyArray_DescrFromType(PyArray_BOOL);\n\tba = (PyArrayObject *)PyArray_FromAny(myBool, typecode, 0, 0, \n\t\t\t\t\t CARRAY_FLAGS, NULL);\n\tif (ba == NULL) return -1;\n\tnd = ba->nd;\n\tfor (j=0; jdata;\n\tcount = 0;\n\n\t/* pre-determine how many nonzero entries there are */\n\tfor (i=0; iao->data;\n\t\tcoords[j] = 0;\n\t\tdims_m1[j] = ba->dimensions[j]-1;\n\t}\n\n\tptr = (Bool *)ba->data;\n\n\tif (count == 0) goto finish;\n\t\n\t/* Loop through the Boolean array and copy coordinates\n\t for non-zero entries */\n\tfor (i=0; i=0; j--) {\n\t\t\tif (coords[j] < dims_m1[j]) {\n\t\t\t\tcoords[j]++;\n\t\t\t\tbreak;\n\t\t\t}\n\t\t\telse {\n\t\t\t\tcoords[j] = 0;\n\t\t\t}\n\t\t}\n\t}\n\n finish:\n\tPy_DECREF(ba);\n\treturn nd;\n\n fail:\n\tfor (j=0; jiters[i] = NULL;\n \tmit->index = 0;\n \tmit->ait = NULL;\n \tmit->subspace = NULL;\n\tmit->numiter = 0;\n\tmit->consec = 1;\n\tPy_INCREF(indexobj);\n\tmit->indexobj = indexobj;\n\n\tif (fancy == SOBJ_LISTTUP) {\n\t\tPyObject *newobj;\n\t\tnewobj = PySequence_Tuple(indexobj);\n\t\tif (newobj == NULL) goto fail;\n\t\tPy_DECREF(indexobj);\n\t\tindexobj = newobj;\n\t\tmit->indexobj = indexobj;\n\t}\n\n#undef SOBJ_NOTFANCY \n#undef SOBJ_ISFANCY \n#undef SOBJ_BADARRAY \n#undef SOBJ_TOOMANY \n#undef SOBJ_LISTTUP \n \n\tif (oned) return (PyObject *)mit;\n\n\t/* Must have some kind of fancy indexing if we are here */\n\t/* indexobj is either a list, an arrayobject, or a tuple \n\t (with at least 1 list or arrayobject or Bool object), */\n\t\n\t/* convert all inputs to iterators */\n\tif (PyArray_Check(indexobj) &&\t\t\t\\\n\t (PyArray_TYPE(indexobj) == PyArray_BOOL)) {\n\t\tmit->numiter = _nonzero_indices(indexobj, mit->iters);\n\t\tif (mit->numiter < 0) goto fail;\n\t\tmit->nd = 1;\n\t\tmit->dimensions[0] = mit->iters[0]->dims_m1[0]+1;\n\t\tPy_DECREF(mit->indexobj);\n\t\tmit->indexobj = PyTuple_New(mit->numiter);\n\t\tif (mit->indexobj == NULL) goto fail;\n\t\tfor (i=0; inumiter; i++) {\n\t\t\tPyTuple_SET_ITEM(mit->indexobj, i, \n\t\t\t\t\t PyInt_FromLong(0));\n\t\t}\n\t}\n\n\telse if (PyArray_Check(indexobj) || !PyTuple_Check(indexobj)) {\n\t\tmit->numiter = 1;\n\t\tindtype = PyArray_DescrFromType(PyArray_INTP);\n\t\tarr = PyArray_FromAny(indexobj, indtype, 0, 0, FORCECAST, NULL);\n\t\tif (arr == NULL) goto fail;\n\t\tmit->iters[0] = (PyArrayIterObject *)PyArray_IterNew(arr);\n\t\tif (mit->iters[0] == NULL) {Py_DECREF(arr); goto fail;}\n\t\tmit->nd = PyArray_NDIM(arr);\n\t\tmemcpy(mit->dimensions,PyArray_DIMS(arr),mit->nd*sizeof(intp));\n\t\tmit->size = PyArray_SIZE(arr);\n\t\tPy_DECREF(arr);\n\t\tPy_DECREF(mit->indexobj);\n\t\tmit->indexobj = Py_BuildValue(\"(N)\", PyInt_FromLong(0));\n\t}\n\telse { /* must be a tuple */\n\t\tPyObject *obj;\n\t\tPyArrayIterObject *iter;\n\t\tPyObject *new;\n\t\t/* Make a copy of the tuple -- we will be replacing \n\t\t index objects with 0's */\n\t\tn = PyTuple_GET_SIZE(indexobj);\n\t\tnew = PyTuple_New(n);\n\t\tif (new == NULL) goto fail;\n\t\tstarted = 0;\n\t\tnonindex = 0;\n\t\tfor (i=0; iconsec = 0;\n\t\t\t\tmit->iters[(mit->numiter)++] = iter;\n\t\t\t\tPyTuple_SET_ITEM(new,i,\n\t\t\t\t\t\t PyInt_FromLong(0));\n\t\t\t}\n\t\t\telse {\n\t\t\t\tif (started) nonindex = 1;\n\t\t\t\tPy_INCREF(obj);\n\t\t\t\tPyTuple_SET_ITEM(new,i,obj);\n\t\t\t}\n\t\t}\n\t\tPy_DECREF(mit->indexobj);\n\t\tmit->indexobj = new;\n\t\t/* Store the number of iterators actually converted */\n\t\t/* These will be mapped to actual axes at bind time */\n\t\tif (PyArray_Broadcast((PyArrayMultiIterObject *)mit) < 0)\n\t\t\tgoto fail;\n\t}\n\n return (PyObject *)mit;\n \n fail:\n Py_DECREF(mit);\n\treturn NULL;\n}\n\n\nstatic void\narraymapiter_dealloc(PyArrayMapIterObject *mit)\n{\n\tint i;\n\tPy_XDECREF(mit->indexobj);\n Py_XDECREF(mit->ait);\n\tPy_XDECREF(mit->subspace);\n\tfor (i=0; inumiter; i++)\n\t\tPy_XDECREF(mit->iters[i]);\n _pya_free(mit);\n}\n\n/* The mapiter object must be created new each time. It does not work\n to bind to a new array, and continue.\n\n This was the orginal intention, but currently that does not work. \n Do not expose the MapIter_Type to Python.\n\n It's not very useful anyway, since mapiter(indexobj); mapiter.bind(a); \n mapiter is equivalent to a[indexobj].flat but the latter gets to use \n slice syntax.\n*/\n\nstatic PyTypeObject PyArrayMapIter_Type = {\n PyObject_HEAD_INIT(NULL)\n 0,\t\t\t\t\t /* ob_size */\n \"numpy.mapiter\",\t\t \t/* tp_name */\n sizeof(PyArrayIterObject), /* tp_basicsize */\n 0,\t\t\t\t\t /* tp_itemsize */\n /* methods */\n (destructor)arraymapiter_dealloc,\t/* tp_dealloc */\n 0,\t\t\t\t\t/* tp_print */\n 0,\t\t\t\t\t/* tp_getattr */\n 0,\t\t\t\t\t/* tp_setattr */\n 0,\t\t\t\t\t/* tp_compare */\n 0,\t\t\t\t\t/* tp_repr */\n 0,\t\t\t\t\t/* tp_as_number */\n 0,\t\t\t\t\t/* tp_as_sequence */\n 0,\t\t\t\t\t/* tp_as_mapping */\n 0,\t\t\t\t\t/* tp_hash */\n 0,\t\t\t\t\t/* tp_call */\n 0,\t\t\t\t\t/* tp_str */\n 0, \t\t/* tp_getattro */\n 0,\t\t\t\t\t/* tp_setattro */\n 0,\t\t\t\t\t/* tp_as_buffer */\n Py_TPFLAGS_DEFAULT, /* tp_flags */\n 0,\t\t\t\t\t/* tp_doc */\n (traverseproc)0, \t /* tp_traverse */\n 0,\t\t\t\t\t/* tp_clear */\n 0,\t\t\t\t\t/* tp_richcompare */\n 0,\t\t\t\t\t/* tp_weaklistoffset */\n 0,\t\t \t /* tp_iter */\n (iternextfunc)0, \t /* tp_iternext */\n 0, \t /* tp_methods */\n 0,\t\t\t\t\t /* tp_members */\n 0,\t\t\t /* tp_getset */\n 0,\t\t\t\t\t /* tp_base */\n 0,\t\t\t\t\t /* tp_dict */\n 0,\t\t\t\t\t /* tp_descr_get */\n 0,\t\t\t\t\t /* tp_descr_set */\n 0,\t\t\t\t\t /* tp_dictoffset */\n (initproc)0,\t \t /* tp_init */\n 0, \t /* tp_alloc */\n 0,\t /* tp_new */\n 0,\t /* tp_free */\n 0,\t\t\t\t\t /* tp_is_gc */\n 0,\t\t\t\t\t /* tp_bases */\n 0,\t\t\t\t\t /* tp_mro */\n 0,\t\t\t\t\t /* tp_cache */\n 0,\t\t\t\t\t /* tp_subclasses */\n 0\t\t\t\t\t /* tp_weaklist */\n\n};\n\n/** END of Subscript Iterator **/\n\n\n/*OBJECT_API\n Get MultiIterator,\n*/\nstatic PyObject *\nPyArray_MultiIterNew(int n, ...)\n{\n va_list va;\n\tPyArrayMultiIterObject *multi;\n\tPyObject *current;\n\tPyObject *arr;\n\t\n\tint i, err=0;\n\t\n\tif (n < 2 || n > MAX_DIMS) {\n\t\tPyErr_Format(PyExc_ValueError, \n\t\t\t \"Need between 2 and (%d) \"\t\t\t\\\n\t\t\t \"array objects (inclusive).\", MAX_DIMS);\n\t}\n\t\n /* fprintf(stderr, \"multi new...\");*/\n multi = PyObject_New(PyArrayMultiIterObject, &PyArrayMultiIter_Type);\n if (multi == NULL)\n return NULL;\n\t\n\tfor (i=0; iiters[i] = NULL;\n\tmulti->numiter = n;\n\tmulti->index = 0;\n\n va_start(va, n);\n\tfor (i=0; iiters[i] = (PyArrayIterObject *)PyArray_IterNew(arr);\n\t\t\tPy_DECREF(arr);\n\t\t}\n\t}\n\n\tva_end(va);\t\n\t\n\tif (!err && PyArray_Broadcast(multi) < 0) err=1;\n\n\tif (err) {\n Py_DECREF(multi);\n\t\treturn NULL;\n\t}\n\t\n\tPyArray_MultiIter_RESET(multi);\n\t\n return (PyObject *)multi;\n}\n\nstatic PyObject *\narraymultiter_new(PyTypeObject *subtype, PyObject *args, PyObject *kwds)\n{\n\t\n\tint n, i;\n\tPyArrayMultiIterObject *multi;\n\tPyObject *arr;\n\t\n\tif (kwds != NULL) {\n\t\tPyErr_SetString(PyExc_ValueError, \n\t\t\t\t\"keyword arguments not accepted.\");\n\t\treturn NULL;\n\t}\n\n\tn = PyTuple_Size(args);\n\tif (n < 2 || n > MAX_DIMS) {\n\t\tif (PyErr_Occurred()) return NULL;\n\t\tPyErr_Format(PyExc_ValueError, \n\t\t\t \"Need at least two and fewer than (%d) \"\t\\\n\t\t\t \"array objects.\", MAX_DIMS);\n\t\treturn NULL;\n\t}\n\t\n\tmulti = _pya_malloc(sizeof(PyArrayMultiIterObject));\n if (multi == NULL) return PyErr_NoMemory();\n\tPyObject_Init((PyObject *)multi, &PyArrayMultiIter_Type);\n\n\tmulti->numiter = n;\n\tmulti->index = 0;\n\tfor (i=0; iiters[i] = NULL;\n\tfor (i=0; iiters[i] =\t\t\t\t\t\\\n\t\t (PyArrayIterObject *)PyArray_IterNew(arr))==NULL) \n\t\t\tgoto fail;\n\t\tPy_DECREF(arr);\n\t}\n\tif (PyArray_Broadcast(multi) < 0) goto fail;\n\tPyArray_MultiIter_RESET(multi);\n\t\n return (PyObject *)multi;\n\t\n fail:\n Py_DECREF(multi);\n\treturn NULL;\n}\n\nstatic PyObject *\narraymultiter_next(PyArrayMultiIterObject *multi)\n{\n\tPyObject *ret;\n\tint i, n;\n\n\tn = multi->numiter;\n\tret = PyTuple_New(n);\n\tif (ret == NULL) return NULL;\n\tif (multi->index < multi->size) {\n\t\tfor (i=0; i < n; i++) {\n\t\t\tPyArrayIterObject *it=multi->iters[i];\n\t\t\tPyTuple_SET_ITEM(ret, i, \n\t\t\t\t\t PyArray_ToScalar(it->dataptr, it->ao));\n\t\t\tPyArray_ITER_NEXT(it);\n\t\t}\n\t\tmulti->index++;\n\t\treturn ret;\n\t}\n return NULL;\n}\n\nstatic void\narraymultiter_dealloc(PyArrayMultiIterObject *multi)\n{\n\tint i;\n\n\tfor (i=0; inumiter; i++) \n\t\tPy_XDECREF(multi->iters[i]);\n\t_pya_free(multi);\n}\n\nstatic PyObject *\narraymultiter_size_get(PyArrayMultiIterObject *self)\n{\n#if SIZEOF_INTP <= SIZEOF_LONG\n\treturn PyInt_FromLong((long) self->size);\n#else\n\tif (self->size < MAX_LONG)\n\t\treturn PyInt_FromLong((long) self->size);\n\telse\n\t\treturn PyLong_FromLongLong((longlong) self->size);\n#endif\n}\n\nstatic PyObject *\narraymultiter_index_get(PyArrayMultiIterObject *self)\n{\n#if SIZEOF_INTP <= SIZEOF_LONG\n\treturn PyInt_FromLong((long) self->index);\n#else\n\tif (self->size < MAX_LONG)\n\t\treturn PyInt_FromLong((long) self->index);\n\telse\n\t\treturn PyLong_FromLongLong((longlong) self->index);\n#endif\n}\n\nstatic PyObject *\narraymultiter_shape_get(PyArrayMultiIterObject *self)\n{\n\treturn PyArray_IntTupleFromIntp(self->nd, self->dimensions);\t\n}\n\nstatic PyObject *\narraymultiter_iters_get(PyArrayMultiIterObject *self)\n{\n\tPyObject *res;\n\tint i, n;\n\tn = self->numiter;\n\tres = PyTuple_New(n);\n\tif (res == NULL) return res;\n\tfor (i=0; iiters[i]);\n\t\tPyTuple_SET_ITEM(res, i, (PyObject *)self->iters[i]);\n\t}\n\treturn res;\n}\n\nstatic PyGetSetDef arraymultiter_getsetlist[] = {\n {\"size\", \n\t (getter)arraymultiter_size_get,\n\t NULL, \n\t \"total size of broadcasted result\"},\n {\"index\", \n\t (getter)arraymultiter_index_get, \n NULL,\n\t \"current index in broadcasted result\"},\n\t{\"shape\",\n\t (getter)arraymultiter_shape_get,\n\t NULL,\n\t \"shape of broadcasted result\"},\n\t{\"iters\",\n\t (getter)arraymultiter_iters_get,\n\t NULL,\n\t \"tuple of individual iterators\"},\n\t{NULL, NULL, NULL, NULL},\n};\n\nstatic PyMemberDef arraymultiter_members[] = {\n\t{\"numiter\", T_INT, offsetof(PyArrayMultiIterObject, numiter), \n\t RO, NULL},\n\t{\"nd\", T_INT, offsetof(PyArrayMultiIterObject, nd), RO, NULL},\n\t{NULL},\n};\n\nstatic PyObject *\narraymultiter_reset(PyArrayMultiIterObject *self, PyObject *args)\n{\n\tif (!PyArg_ParseTuple(args, \"\")) return NULL;\n\n\tPyArray_MultiIter_RESET(self);\n\tPy_INCREF(Py_None);\n\treturn Py_None;\n}\n\nstatic PyMethodDef arraymultiter_methods[] = {\n\t{\"reset\", (PyCFunction) arraymultiter_reset, METH_VARARGS, NULL},\n\t{NULL, NULL},\n};\n\nstatic PyTypeObject PyArrayMultiIter_Type = {\n PyObject_HEAD_INIT(NULL)\n 0,\t\t\t\t\t /* ob_size */\n \"numpy.broadcast\",\t\t \t /* tp_name */\n sizeof(PyArrayMultiIterObject), /* tp_basicsize */\n 0,\t\t\t\t\t /* tp_itemsize */\n /* methods */\n (destructor)arraymultiter_dealloc,\t/* tp_dealloc */\n 0,\t\t\t\t\t/* tp_print */\n 0,\t\t\t\t\t/* tp_getattr */\n 0,\t\t\t\t\t/* tp_setattr */\n 0,\t\t\t\t\t/* tp_compare */\n 0,\t\t\t\t\t/* tp_repr */\n 0,\t\t\t\t\t/* tp_as_number */\n 0, /* tp_as_sequence */\n 0, \t /* tp_as_mapping */\n 0,\t\t\t\t\t/* tp_hash */\n 0,\t\t\t\t\t/* tp_call */\n 0,\t\t\t\t\t/* tp_str */\n 0,\t \t/* tp_getattro */\n 0,\t\t\t\t\t/* tp_setattro */\n 0,\t\t\t\t\t/* tp_as_buffer */\n Py_TPFLAGS_DEFAULT, /* tp_flags */\n 0,\t\t\t\t\t/* tp_doc */\n 0, \t /* tp_traverse */\n 0,\t\t\t\t\t/* tp_clear */\n 0,\t\t\t\t\t/* tp_richcompare */\n 0,\t\t\t\t\t/* tp_weaklistoffset */\n 0, \t /* tp_iter */\n (iternextfunc)arraymultiter_next,\t/* tp_iternext */\n arraymultiter_methods, \t /* tp_methods */\n arraymultiter_members,\t \t /* tp_members */\n arraymultiter_getsetlist, /* tp_getset */\n 0,\t\t\t\t\t /* tp_base */\n 0,\t\t\t\t\t /* tp_dict */\n 0,\t\t\t\t\t /* tp_descr_get */\n 0,\t\t\t\t\t /* tp_descr_set */\n 0,\t\t\t\t\t /* tp_dictoffset */\n (initproc)0,\t \t /* tp_init */\n 0, \t /* tp_alloc */\n arraymultiter_new,\t /* tp_new */\n 0,\t /* tp_free */\n 0,\t\t\t\t\t /* tp_is_gc */\n 0,\t\t\t\t\t /* tp_bases */\n 0,\t\t\t\t\t /* tp_mro */\n 0,\t\t\t\t\t /* tp_cache */\n 0,\t\t\t\t\t /* tp_subclasses */\n 0\t\t\t\t\t /* tp_weaklist */\n};\n\n/*OBJECT_API*/\nstatic PyArray_Descr *\nPyArray_DescrNewFromType(int type_num)\n{\n\tPyArray_Descr *old;\n\tPyArray_Descr *new;\n\n\told = PyArray_DescrFromType(type_num);\n\tnew = PyArray_DescrNew(old);\n\tPy_DECREF(old);\n\treturn new;\t\n}\n\n/*** Array Descr Objects for dynamic types **/\n\n/** There are some statically-defined PyArray_Descr objects corresponding\n to the basic built-in types. \n These can and should be DECREF'd and INCREF'd as appropriate, anyway.\n If a mistake is made in reference counting, deallocation on these \n builtins will be attempted leading to problems. \n\n This let's us deal with all PyArray_Descr objects using reference\n counting (regardless of whether they are statically or dynamically \n allocated). \n**/\n\n/* base cannot be NULL */\n/*OBJECT_API*/\nstatic PyArray_Descr *\nPyArray_DescrNew(PyArray_Descr *base)\n{\n\tPyArray_Descr *new;\n\n\tnew = PyObject_New(PyArray_Descr, &PyArrayDescr_Type);\n\tif (new == NULL) return NULL;\n\t/* Don't copy PyObject_HEAD part */\n\tmemcpy((char *)new+sizeof(PyObject),\n\t (char *)base+sizeof(PyObject),\n\t sizeof(PyArray_Descr)-sizeof(PyObject));\n\n\tif (new->fields == Py_None) new->fields = NULL;\n\tPy_XINCREF(new->fields);\n\tif (new->subarray) {\n\t\tnew->subarray = _pya_malloc(sizeof(PyArray_ArrayDescr));\n\t\tmemcpy(new->subarray, base->subarray, \n\t\t sizeof(PyArray_ArrayDescr));\n\t\tPy_INCREF(new->subarray->shape);\n\t\tPy_INCREF(new->subarray->base);\n\t}\n\tPy_INCREF(new->typeobj);\n\treturn new;\n}\n\n/* should never be called for builtin-types unless \n there is a reference-count problem \n*/\nstatic void\narraydescr_dealloc(PyArray_Descr *self)\n{\n\tPy_XDECREF(self->typeobj);\n\tPy_XDECREF(self->fields);\n\tif (self->subarray) {\n\t\tPy_DECREF(self->subarray->shape);\n\t\tPy_DECREF(self->subarray->base);\n\t\t_pya_free(self->subarray);\n\t}\n\tself->ob_type->tp_free(self);\n}\n\n/* we need to be careful about setting attributes because these\n objects are pointed to by arrays that depend on them for interpreting\n data. Currently no attributes of dtype objects can be set. \n*/\nstatic PyMemberDef arraydescr_members[] = {\n\t{\"type\", T_OBJECT, offsetof(PyArray_Descr, typeobj), RO, NULL},\n\t{\"kind\", T_CHAR, offsetof(PyArray_Descr, kind), RO, NULL},\n\t{\"char\", T_CHAR, offsetof(PyArray_Descr, type), RO, NULL},\n\t{\"num\", T_INT, offsetof(PyArray_Descr, type_num), RO, NULL},\n\t{\"byteorder\", T_CHAR, offsetof(PyArray_Descr, byteorder), RO, NULL},\n\t{\"itemsize\", T_INT, offsetof(PyArray_Descr, elsize), RO, NULL},\n\t{\"alignment\", T_INT, offsetof(PyArray_Descr, alignment), RO, NULL},\n {\"hasobject\", T_UBYTE, offsetof(PyArray_Descr, hasobject), RO, NULL},\n\t{NULL}, \n};\n\nstatic PyObject *\narraydescr_subdescr_get(PyArray_Descr *self)\n{\n\tif (self->subarray == NULL) {\n\t\tPy_INCREF(Py_None);\n\t\treturn Py_None;\n\t}\n\treturn Py_BuildValue(\"OO\", (PyObject *)self->subarray->base, \n\t\t\t self->subarray->shape);\n}\n\nstatic PyObject *\narraydescr_protocol_typestr_get(PyArray_Descr *self)\n{\n char basic_=self->kind;\n char endian = self->byteorder;\n\n if (endian == '=') {\n endian = '<';\n if (!PyArray_IsNativeByteOrder(endian)) endian = '>';\n }\n\n return PyString_FromFormat(\"%c%c%d\", endian, basic_,\n self->elsize);\n}\n\nstatic PyObject *\narraydescr_typename_get(PyArray_Descr *self)\n{\n int len;\n PyTypeObject *typeobj = self->typeobj;\n\tPyObject *res;\n\n\t/* Both are equivalents, but second is more resistent to changes */\n/* \tlen = strlen(typeobj->tp_name) - 8; */\n\n\tif (PyTypeNum_ISUSERDEF(self->type_num)) {\n\t\tres = PyString_FromString(typeobj->tp_name);\n\t}\n\telse {\n\t\tlen = strchr(typeobj->tp_name, (int)'_')-(typeobj->tp_name);\n\t\tres = PyString_FromStringAndSize(typeobj->tp_name, len);\n\t}\n\tif (PyTypeNum_ISEXTENDED(self->type_num) && self->elsize != 0) {\n\t\tPyObject *p;\n\t\tp = PyString_FromFormat(\"%d\", self->elsize * 8);\n\t\tPyString_ConcatAndDel(&res, p);\n\t}\n\treturn res;\t\t\t\t\t\t \n}\n\nstatic PyObject *\narraydescr_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\t{\"name\",\n\t (getter)arraydescr_typename_get,\n\t NULL,\n\t \"The array_protocol typename.\"},\n\t{\"isbuiltin\",\n\t (getter)arraydescr_isbuiltin_get,\n\t NULL,\n\t \"Is this a buillt-in data-type descriptor?\"},\n\t{\"isnative\",\n\t (getter)arraydescr_isnative_get,\n\t NULL,\n\t \"Is the byte-order of this descriptor native?\"},\n\t{\"fields\",\n\t (getter)arraydescr_fields_get,\n\t NULL,\n\t NULL},\n\t{NULL, NULL, NULL, NULL},\n};\n\nstatic PyArray_Descr *_convert_from_list(PyObject *obj, int align, int try_descr);\nstatic PyArray_Descr *_convert_from_dict(PyObject *obj, int align);\nstatic PyArray_Descr *_convert_from_commastring(PyObject *obj, int align);\nstatic PyArray_Descr *_convert_from_array_descr(PyObject *obj);\n\nstatic PyObject *\narraydescr_new(PyTypeObject *subtype, PyObject *args, PyObject *kwds)\n{\n\tPyObject *odescr;\n\tPyArray_Descr *descr, *conv;\n\tint align=0;\n\tBool copy=FALSE;\n\tstatic char *kwlist[] = {\"dtype\", \"align\", \"copy\", NULL};\n\t\n\tif (!PyArg_ParseTupleAndKeywords(args, kwds, \"O|iO&\",\n\t\t\t\t\t kwlist, &odescr, &align,\n\t\t\t\t\t PyArray_BoolConverter, ©))\n\t\treturn NULL;\n\t\n\tif (align) {\n\t\tconv = NULL;\n\t\tif PyDict_Check(odescr) \n\t\t\tconv = _convert_from_dict(odescr, 1);\n\t\telse if PyList_Check(odescr) \n\t\t\tconv = _convert_from_list(odescr, 1, 0);\n\t\telse if PyString_Check(odescr)\n\t\t\tconv = _convert_from_commastring(odescr, 1);\n\t\telse {\n\t\t\tPyErr_SetString(PyExc_ValueError, \n\t\t\t\t\t\"align can only be non-zero for\" \\\n\t\t\t\t\t\"dictionary, list, and string objects.\");\n\t\t}\n\t\tif (conv) return (PyObject *)conv;\n\t\tif (!PyErr_Occurred()) {\n\t\t\tPyErr_SetString(PyExc_ValueError,\n\t\t\t\t\t\"data-type-descriptor not understood\");\n\t\t}\n\t\treturn NULL;\n\t}\n\n\tif PyList_Check(odescr) {\n\t\tconv = _convert_from_array_descr(odescr);\n\t\tif (!conv) {\n\t\t\tPyErr_Clear();\n\t\t\tconv = _convert_from_list(odescr, 0, 0);\n\t\t}\n\t\treturn (PyObject *)conv;\n\t}\n\n\tif (!PyArray_DescrConverter(odescr, &conv)) \n\t\treturn NULL;\n\t/* Get a new copy of it unless it's already a copy */\n\tif (copy && conv->fields == Py_None) {\n\t\tdescr = PyArray_DescrNew(conv);\n\t\tPy_DECREF(conv);\n\t\tconv = descr;\n\t}\n\treturn (PyObject *)conv;\n}\n\nstatic char doc_arraydescr_reduce[] = \"self.__reduce__() for pickling.\";\n\n/* return a tuple of (callable object, args, state) */\nstatic PyObject *\narraydescr_reduce(PyArray_Descr *self, PyObject *args)\n{\n\tPyObject *ret, *mod, *obj;\n\tPyObject *state;\n\tchar endian;\n\tint elsize, alignment;\n\n\tret = PyTuple_New(3);\n\tif (ret == NULL) return NULL;\n\tmod = PyImport_ImportModule(\"numpy.core.multiarray\");\n\tif (mod == NULL) {Py_DECREF(ret); return NULL;}\n\tobj = PyObject_GetAttrString(mod, \"dtype\");\n\tPy_DECREF(mod);\n\tif (obj == NULL) {Py_DECREF(ret); return NULL;}\n\tPyTuple_SET_ITEM(ret, 0, obj);\n\tif (PyTypeNum_ISUSERDEF(self->type_num) ||\t\t\\\n\t ((self->type_num == PyArray_VOID &&\t\t\t\\\n\t self->typeobj != &PyVoidArrType_Type))) {\n\t\tobj = (PyObject *)self->typeobj;\n\t\tPy_INCREF(obj);\n\t}\n\telse {\n\t\tobj = PyString_FromFormat(\"%c%d\",self->kind, self->elsize);\n\t}\n\tPyTuple_SET_ITEM(ret, 1, Py_BuildValue(\"(Nii)\", obj, 0, 1));\n\t\n\t/* Now return the state which is at least \n\t byteorder, subarray, and fields */\n\tendian = self->byteorder;\n\tif (endian == '=') {\n\t\tendian = '<';\n\t\tif (!PyArray_IsNativeByteOrder(endian)) endian = '>';\n\t}\n\tstate = PyTuple_New(5);\n\tPyTuple_SET_ITEM(state, 0, PyString_FromFormat(\"%c\", endian));\n\tPyTuple_SET_ITEM(state, 1, arraydescr_subdescr_get(self));\n\tif (self->fields && self->fields != Py_None) {\n\t\tPy_INCREF(self->fields);\n\t\tPyTuple_SET_ITEM(state, 2, self->fields);\n\t}\n\telse {\n\t\tPyTuple_SET_ITEM(state, 2, Py_None);\n\t\tPy_INCREF(Py_None);\n\t}\n\n\t/* for extended types it also includes elsize and alignment */\n\tif (PyTypeNum_ISEXTENDED(self->type_num)) {\n\t\telsize = self->elsize;\n\t\talignment = self->alignment;\n\t}\n\telse {elsize = -1; alignment = -1;}\n\n\tPyTuple_SET_ITEM(state, 3, PyInt_FromLong(elsize));\n\tPyTuple_SET_ITEM(state, 4, PyInt_FromLong(alignment));\n\n\tPyTuple_SET_ITEM(ret, 2, state);\n\treturn ret;\n}\n\n/* state is at least byteorder, subarray, and fields but could include elsize \n and alignment for EXTENDED arrays \n*/\nstatic char doc_arraydescr_setstate[] = \"self.__setstate__() for pickling.\";\n\nstatic PyObject *\narraydescr_setstate(PyArray_Descr *self, PyObject *args)\n{\n\tint elsize = -1, alignment = -1;\n\tchar endian;\n\tPyObject *subarray, *fields;\n\n\tif (self->fields == Py_None) {Py_INCREF(Py_None); return Py_None;}\n\n\tif (!PyArg_ParseTuple(args, \"(cOOii)\", &endian, &subarray, &fields,\n\t\t\t &elsize, &alignment)) return NULL;\n\t\n\tif (PyArray_IsNativeByteOrder(endian)) endian = '=';\n\n\tself->byteorder = endian;\n\tif (self->subarray) {\n\t\tPy_XDECREF(self->subarray->base);\n\t\tPy_XDECREF(self->subarray->shape);\n\t\t_pya_free(self->subarray);\n\t}\n\tself->subarray = NULL;\n\n\tif (subarray != Py_None) {\n\t\tself->subarray = _pya_malloc(sizeof(PyArray_ArrayDescr));\n\t\tself->subarray->base = (PyArray_Descr *)PyTuple_GET_ITEM(subarray, 0);\n\t\tPy_INCREF(self->subarray->base);\n\t\tself->subarray->shape = PyTuple_GET_ITEM(subarray, 1);\n\t\tPy_INCREF(self->subarray->shape);\n\t}\n\t\n\tif (fields != Py_None) {\n\t\tPy_XDECREF(self->fields);\n\t\tself->fields = fields;\n\t\tPy_INCREF(fields);\n\t}\n\t\n\tif (PyTypeNum_ISEXTENDED(self->type_num)) {\n\t\tself->elsize = elsize;\n\t\tself->alignment = alignment;\n\t}\n\t\n\tPy_INCREF(Py_None);\n\treturn Py_None;\n}\n\n\n/* returns a copy of the PyArray_Descr structure with the byteorder\n altered:\n no arguments: The byteorder is swapped (in all subfields as well)\n single argument: The byteorder is forced to the given state\n (in all subfields as well)\n\n Valid states: ('big', '>') or ('little' or '<')\n\t\t ('native', or '=')\n\n\t\t If a descr structure with | is encountered it's own\n\t\t byte-order is not changed but any fields are: \n*/\n\n/*OBJECT_API\n Deep bytorder change of a data-type descriptor\n*/\nstatic PyArray_Descr *\nPyArray_DescrNewByteorder(PyArray_Descr *self, char newendian)\n{\n\tPyArray_Descr *new;\n\tchar endian;\n\n\tnew = PyArray_DescrNew(self);\n\tendian = new->byteorder;\n\tif (endian != PyArray_IGNORE) {\n\t\tif (newendian == PyArray_SWAP) { /* swap byteorder */\n\t\t\tif PyArray_ISNBO(endian) endian = PyArray_OPPBYTE;\n\t\t\telse endian = PyArray_NATBYTE;\n\t\t\tnew->byteorder = endian;\n\t\t}\n\t\telse if (newendian != PyArray_IGNORE) {\n\t\t\tnew->byteorder = newendian;\n\t\t}\n\t}\n\tif (new->fields) {\n\t\tPyObject *newfields;\n\t\tPyObject *key, *value;\n\t\tPyObject *newvalue;\n\t\tPyObject *old;\n\t\tPyArray_Descr *newdescr;\n\t\tint pos = 0, len, i;\n\t\tnewfields = PyDict_New();\n\t\t/* make new dictionary with replaced */\n\t\t/* PyArray_Descr Objects */\n\t\twhile(PyDict_Next(self->fields, &pos, &key, &value)) {\n\t\t\tif (PyInt_Check(key) &&\t\t\t\\\n\t\t\t PyInt_AsLong(key) == -1) {\n\t\t\t\tPyDict_SetItem(newfields, key, value);\n\t\t\t\tcontinue;\n\t\t\t}\n\t\t\tif (!PyString_Check(key) ||\t \\\n\t\t\t !PyTuple_Check(value) ||\t\t\t\\\n\t\t\t ((len=PyTuple_GET_SIZE(value)) < 2))\n\t\t\t\tcontinue;\n\t\t\t\n\t\t\told = PyTuple_GET_ITEM(value, 0);\n\t\t\tif (!PyArray_DescrCheck(old)) continue;\n\t\t\tnewdescr = PyArray_DescrNewByteorder\t\t\\\n\t\t\t\t((PyArray_Descr *)old, newendian);\n\t\t\tif (newdescr == NULL) {\n\t\t\t\tPy_DECREF(newfields); Py_DECREF(new);\n\t\t\t\treturn NULL;\n\t\t\t}\n\t\t\tnewvalue = PyTuple_New(len);\n\t\t\tPyTuple_SET_ITEM(newvalue, 0,\t\t\\\n\t\t\t\t\t (PyObject *)newdescr);\n\t\t\tfor(i=1; ifields);\n\t\tnew->fields = newfields;\n\t}\n\tif (new->subarray) {\n\t\tPy_DECREF(new->subarray->base);\n\t\tnew->subarray->base = PyArray_DescrNewByteorder \\\n\t\t\t(self->subarray->base, newendian);\n\t}\n\treturn new;\n}\n\n\nstatic char doc_arraydescr_newbyteorder[] = \"self.newbyteorder()\"\n\t\" returns a copy of the dtype object\\n\"\n\t\" with altered byteorders. If is not given all byteorders\\n\"\n\t\" are swapped. Otherwise endian can be '>', '<', or '=' to force\\n\"\n\t\" a byteorder. Descriptors in all fields are also updated in the\\n\"\n\t\" new dtype object.\";\n\nstatic PyObject *\narraydescr_newbyteorder(PyArray_Descr *self, PyObject *args) \n{\n\tchar endian=PyArray_SWAP;\n\t\n\tif (!PyArg_ParseTuple(args, \"|O&\", PyArray_ByteorderConverter,\n\t\t\t &endian)) return NULL;\n\t\t\t\n\treturn (PyObject *)PyArray_DescrNewByteorder(self, endian);\n}\n\nstatic PyMethodDef arraydescr_methods[] = {\n /* for pickling */\n {\"__reduce__\", (PyCFunction)arraydescr_reduce, METH_VARARGS, \n\t doc_arraydescr_reduce},\n\t{\"__setstate__\", (PyCFunction)arraydescr_setstate, METH_VARARGS,\n\t doc_arraydescr_setstate},\n\n\t{\"newbyteorder\", (PyCFunction)arraydescr_newbyteorder, METH_VARARGS,\n\t doc_arraydescr_newbyteorder},\n {NULL,\t\tNULL}\t\t/* sentinel */\n};\n\nstatic PyObject *\narraydescr_str(PyArray_Descr *self)\n{\n\tPyObject *sub;\n\n\tif (self->fields && self->fields != Py_None) {\n\t\tPyObject *lst;\n\t\tlst = arraydescr_protocol_descr_get(self);\n\t\tif (!lst) {\n\t\t\tsub = PyString_FromString(\"\");\n\t\t\tPyErr_Clear();\n\t\t}\n\t\telse sub = PyObject_Str(lst);\n\t\tPy_XDECREF(lst);\n\t\tif (self->type_num != PyArray_VOID) {\n\t\t\tPyObject *p;\n\t\t\tPyObject *t=PyString_FromString(\"'\");\n\t\t\tp = arraydescr_protocol_typestr_get(self);\n\t\t\tPyString_Concat(&p, t);\n\t\t\tPyString_ConcatAndDel(&t, p);\n\t\t\tp = PyString_FromString(\"(\");\n\t\t\tPyString_ConcatAndDel(&p, t);\n\t\t\tPyString_ConcatAndDel(&p, PyString_FromString(\", \"));\n\t\t\tPyString_ConcatAndDel(&p, sub);\n\t\t\tPyString_ConcatAndDel(&p, PyString_FromString(\")\"));\n\t\t\tsub = p;\n\t\t}\n\t}\n\telse if (self->subarray) {\n\t\tPyObject *p;\n\t\tPyObject *t = PyString_FromString(\"(\");\n\t\tp = arraydescr_str(self->subarray->base);\n\t\tPyString_ConcatAndDel(&t, p);\n\t\tPyString_ConcatAndDel(&t, PyString_FromString(\",\"));\n\t\tPyString_ConcatAndDel(&t, PyObject_Str(self->subarray->shape));\n\t\tPyString_ConcatAndDel(&t, PyString_FromString(\")\"));\n\t\tsub = t;\n\t}\n\telse {\n\t\tPyObject *t=PyString_FromString(\"'\");\n\t\tsub = arraydescr_protocol_typestr_get(self);\n\t\tPyString_Concat(&sub, t);\n\t\tPyString_ConcatAndDel(&t, sub);\n\t\tsub = t;\n\t}\n\treturn sub;\n}\n\nstatic PyObject *\narraydescr_repr(PyArray_Descr *self)\n{\n\tPyObject *sub, *s;\n\ts = PyString_FromString(\"dtype(\");\n sub = arraydescr_str(self);\n\tPyString_ConcatAndDel(&s, sub);\n\tsub = PyString_FromString(\")\");\n\tPyString_ConcatAndDel(&s, sub);\n\treturn s;\n}\n\nstatic int\narraydescr_compare(PyArray_Descr *self, PyObject *other)\n{\n \tif (!PyArray_DescrCheck(other)) {\n\t\tPyErr_SetString(PyExc_TypeError,\n\t\t\t\t\"not a dtype object.\");\n\t\treturn -1;\n\t}\n\tif (PyArray_EquivTypes(self, (PyArray_Descr *)other)) return 0;\n\tif (PyArray_CanCastTo(self, (PyArray_Descr *)other)) return -1;\n\treturn 1;\n}\n\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 0, \t /* tp_as_mapping */\n 0,\t\t\t\t\t/* tp_hash */\n 0,\t\t\t\t\t/* tp_call */\n (reprfunc)arraydescr_str, /* tp_str */\n 0,\t \t/* tp_getattro */\n 0,\t\t\t\t\t/* tp_setattro */\n 0,\t\t\t\t\t/* tp_as_buffer */\n Py_TPFLAGS_DEFAULT, /* tp_flags */\n 0,\t\t\t\t\t/* tp_doc */\n 0, \t /* tp_traverse */\n 0,\t\t\t\t\t/* tp_clear */\n 0,\t\t\t\t\t/* tp_richcompare */\n 0,\t\t\t\t\t/* tp_weaklistoffset */\n 0, \t /* tp_iter */\n 0,\t \t/* tp_iternext */\n arraydescr_methods,\t \t /* tp_methods */\n arraydescr_members,\t /* tp_members */\n arraydescr_getsets, /* tp_getset */\n 0,\t\t\t\t\t /* tp_base */\n 0,\t\t\t\t\t /* tp_dict */\n 0,\t\t\t\t\t /* tp_descr_get */\n 0,\t\t\t\t\t /* tp_descr_set */\n 0,\t\t\t\t\t /* tp_dictoffset */\n 0, \t \t /* tp_init */\n 0, \t /* tp_alloc */\n arraydescr_new,\t /* tp_new */\n 0,\t /* tp_free */\n 0,\t\t\t\t\t /* tp_is_gc */\n 0,\t\t\t\t\t /* tp_bases */\n 0,\t\t\t\t\t /* tp_mro */\n 0,\t\t\t\t\t /* tp_cache */\n 0,\t\t\t\t\t /* tp_subclasses */\n 0\t\t\t\t\t /* tp_weaklist */\n};\n", + "methods": [ + { + "name": "PyArray_GetPriority", + "long_name": "PyArray_GetPriority( PyObject * obj , double default_)", + "filename": "arrayobject.c", + "nloc": 17, + "complexity": 5, + "token_count": 86, + "parameters": [ + "obj", + "default_" + ], + "start_line": 28, + "end_line": 46, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 19, + "top_nesting_level": 0 + }, + { + "name": "PyArray_Zero", + "long_name": "PyArray_Zero( PyArrayObject * arr)", + "filename": "arrayobject.c", + "nloc": 27, + "complexity": 4, + "token_count": 148, + "parameters": [ + "arr" + ], + "start_line": 67, + "end_line": 95, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 29, + "top_nesting_level": 0 + }, + { + "name": "PyArray_One", + "long_name": "PyArray_One( PyArrayObject * arr)", + "filename": "arrayobject.c", + "nloc": 27, + "complexity": 4, + "token_count": 148, + "parameters": [ + "arr" + ], + "start_line": 101, + "end_line": 130, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 30, + "top_nesting_level": 0 + }, + { + "name": "do_sliced_copy", + "long_name": "do_sliced_copy( char * dest , intp * dest_strides , intp * dest_dimensions , int dest_nd , char * src , intp * src_strides , intp * src_dimensions , int src_nd , int elsize , int copies)", + "filename": "arrayobject.c", + "nloc": 48, + "complexity": 13, + "token_count": 313, + "parameters": [ + "dest", + "dest_strides", + "dest_dimensions", + "dest_nd", + "src", + "src_strides", + "src_dimensions", + "src_nd", + "elsize", + "copies" + ], + "start_line": 136, + "end_line": 186, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 51, + "top_nesting_level": 0 + }, + { + "name": "optimize_slices", + "long_name": "optimize_slices( intp ** dest_strides , intp ** dest_dimensions , int * dest_nd , intp ** src_strides , intp ** src_dimensions , int * src_nd , int * elsize , int * copies)", + "filename": "arrayobject.c", + "nloc": 32, + "complexity": 8, + "token_count": 214, + "parameters": [ + "dest_strides", + "dest_dimensions", + "dest_nd", + "src_strides", + "src_dimensions", + "src_nd", + "elsize", + "copies" + ], + "start_line": 209, + "end_line": 240, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 32, + "top_nesting_level": 0 + }, + { + "name": "contiguous_data", + "long_name": "contiguous_data( PyArrayObject * src)", + "filename": "arrayobject.c", + "nloc": 29, + "complexity": 4, + "token_count": 215, + "parameters": [ + "src" + ], + "start_line": 243, + "end_line": 277, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 35, + "top_nesting_level": 0 + }, + { + "name": "PyArray_INCREF", + "long_name": "PyArray_INCREF( PyArrayObject * mp)", + "filename": "arrayobject.c", + "nloc": 17, + "complexity": 6, + "token_count": 125, + "parameters": [ + "mp" + ], + "start_line": 293, + "end_line": 315, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 23, + "top_nesting_level": 0 + }, + { + "name": "PyArray_XDECREF", + "long_name": "PyArray_XDECREF( PyArrayObject * mp)", + "filename": "arrayobject.c", + "nloc": 17, + "complexity": 6, + "token_count": 125, + "parameters": [ + "mp" + ], + "start_line": 321, + "end_line": 342, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 22, + "top_nesting_level": 0 + }, + { + "name": "byte_swap_vector", + "long_name": "byte_swap_vector( * p , int n , int size)", + "filename": "arrayobject.c", + "nloc": 38, + "complexity": 10, + "token_count": 340, + "parameters": [ + "p", + "n", + "size" + ], + "start_line": 346, + "end_line": 384, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 39, + "top_nesting_level": 0 + }, + { + "name": "copy_and_swap", + "long_name": "copy_and_swap( * dst , * src , int itemsize , intp numitems , intp srcstrides , int swap)", + "filename": "arrayobject.c", + "nloc": 18, + "complexity": 5, + "token_count": 120, + "parameters": [ + "dst", + "src", + "itemsize", + "numitems", + "srcstrides", + "swap" + ], + "start_line": 389, + "end_line": 409, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 21, + "top_nesting_level": 0 + }, + { + "name": "PyArray_PyIntAsIntp", + "long_name": "PyArray_PyIntAsIntp( PyObject * o)", + "filename": "arrayobject.c", + "nloc": 71, + "complexity": 21, + "token_count": 413, + "parameters": [ + "o" + ], + "start_line": 423, + "end_line": 505, + "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": 512, + "end_line": 586, + "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": 589, + "end_line": 604, + "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": 610, + "end_line": 618, + "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": 634, + "end_line": 714, + "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": 718, + "end_line": 732, + "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": 745, + "end_line": 771, + "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": 777, + "end_line": 791, + "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": 800, + "end_line": 820, + "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": 81, + "complexity": 12, + "token_count": 483, + "parameters": [ + "data", + "descr", + "base" + ], + "start_line": 829, + "end_line": 913, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 85, + "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": 929, + "end_line": 932, + "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": 942, + "end_line": 964, + "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": 978, + "end_line": 1018, + "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": 1033, + "end_line": 1074, + "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": 1081, + "end_line": 1172, + "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": 1178, + "end_line": 1207, + "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": 1210, + "end_line": 1246, + "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": 1255, + "end_line": 1292, + "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": 1299, + "end_line": 1307, + "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": 1310, + "end_line": 1335, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 26, + "top_nesting_level": 0 + }, + { + "name": "array_item_nice", + "long_name": "array_item_nice( PyArrayObject * self , int i)", + "filename": "arrayobject.c", + "nloc": 4, + "complexity": 1, + "token_count": 29, + "parameters": [ + "self", + "i" + ], + "start_line": 1338, + "end_line": 1341, + "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": 1345, + "end_line": 1380, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 36, + "top_nesting_level": 0 + }, + { + "name": "array_ass_item", + "long_name": "array_ass_item( PyArrayObject * self , int i , PyObject * v)", + "filename": "arrayobject.c", + "nloc": 4, + "complexity": 1, + "token_count": 28, + "parameters": [ + "self", + "i", + "v" + ], + "start_line": 1386, + "end_line": 1389, + "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": 1395, + "end_line": 1403, + "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": 1409, + "end_line": 1459, + "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": 1466, + "end_line": 1511, + "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": 1515, + "end_line": 1609, + "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": 1612, + "end_line": 1649, + "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": 1661, + "end_line": 1714, + "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": 1717, + "end_line": 1777, + "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": 1780, + "end_line": 1807, + "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": 1810, + "end_line": 1829, + "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": 1841, + "end_line": 1903, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 63, + "top_nesting_level": 0 + }, + { + "name": "array_subscript", + "long_name": "array_subscript( PyArrayObject * self , PyObject * op)", + "filename": "arrayobject.c", + "nloc": 103, + "complexity": 28, + "token_count": 666, + "parameters": [ + "self", + "op" + ], + "start_line": 1927, + "end_line": 2045, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 119, + "top_nesting_level": 0 + }, + { + "name": "array_ass_sub", + "long_name": "array_ass_sub( PyArrayObject * self , PyObject * index , PyObject * op)", + "filename": "arrayobject.c", + "nloc": 93, + "complexity": 28, + "token_count": 588, + "parameters": [ + "self", + "index", + "op" + ], + "start_line": 2060, + "end_line": 2165, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 106, + "top_nesting_level": 0 + }, + { + "name": "array_subscript_nice", + "long_name": "array_subscript_nice( PyArrayObject * self , PyObject * op)", + "filename": "arrayobject.c", + "nloc": 4, + "complexity": 1, + "token_count": 27, + "parameters": [ + "self", + "op" + ], + "start_line": 2174, + "end_line": 2177, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 4, + "top_nesting_level": 0 + }, + { + "name": "array_getsegcount", + "long_name": "array_getsegcount( PyArrayObject * self , int * lenp)", + "filename": "arrayobject.c", + "nloc": 11, + "complexity": 4, + "token_count": 48, + "parameters": [ + "self", + "lenp" + ], + "start_line": 2196, + "end_line": 2208, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 13, + "top_nesting_level": 0 + }, + { + "name": "array_getreadbuf", + "long_name": "array_getreadbuf( PyArrayObject * self , int segment , ** ptrptr)", + "filename": "arrayobject.c", + "nloc": 15, + "complexity": 3, + "token_count": 72, + "parameters": [ + "self", + "segment", + "ptrptr" + ], + "start_line": 2211, + "end_line": 2226, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 16, + "top_nesting_level": 0 + }, + { + "name": "array_getwritebuf", + "long_name": "array_getwritebuf( PyArrayObject * self , int segment , ** ptrptr)", + "filename": "arrayobject.c", + "nloc": 10, + "complexity": 2, + "token_count": 54, + "parameters": [ + "self", + "segment", + "ptrptr" + ], + "start_line": 2230, + "end_line": 2239, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 10, + "top_nesting_level": 0 + }, + { + "name": "array_getcharbuf", + "long_name": "array_getcharbuf( PyArrayObject * self , int segment , const char ** ptrptr)", + "filename": "arrayobject.c", + "nloc": 12, + "complexity": 3, + "token_count": 65, + "parameters": [ + "self", + "segment", + "ptrptr" + ], + "start_line": 2242, + "end_line": 2253, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 12, + "top_nesting_level": 0 + }, + { + "name": "PyArray_SetNumericOps", + "long_name": "PyArray_SetNumericOps( PyObject * dict)", + "filename": "arrayobject.c", + "nloc": 34, + "complexity": 1, + "token_count": 162, + "parameters": [ + "dict" + ], + "start_line": 2324, + "end_line": 2357, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 34, + "top_nesting_level": 0 + }, + { + "name": "PyArray_GetNumericOps", + "long_name": "PyArray_GetNumericOps()", + "filename": "arrayobject.c", + "nloc": 39, + "complexity": 2, + "token_count": 183, + "parameters": [], + "start_line": 2367, + "end_line": 2406, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 40, + "top_nesting_level": 0 + }, + { + "name": "PyArray_GenericReduceFunction", + "long_name": "PyArray_GenericReduceFunction( PyArrayObject * m1 , PyObject * op , int axis , int rtype)", + "filename": "arrayobject.c", + "nloc": 24, + "complexity": 5, + "token_count": 141, + "parameters": [ + "m1", + "op", + "axis", + "rtype" + ], + "start_line": 2409, + "end_line": 2432, + "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": 2436, + "end_line": 2459, + "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": 2463, + "end_line": 2470, + "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": 2473, + "end_line": 2480, + "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": 2483, + "end_line": 2491, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 9, + "top_nesting_level": 0 + }, + { + "name": "array_add", + "long_name": "array_add( PyArrayObject * m1 , PyObject * m2)", + "filename": "arrayobject.c", + "nloc": 4, + "complexity": 1, + "token_count": 24, + "parameters": [ + "m1", + "m2" + ], + "start_line": 2494, + "end_line": 2497, + "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": 2500, + "end_line": 2503, + "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": 2506, + "end_line": 2509, + "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": 2512, + "end_line": 2515, + "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": 2518, + "end_line": 2521, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 4, + "top_nesting_level": 0 + }, + { + "name": "array_power", + "long_name": "array_power( PyArrayObject * m1 , PyObject * m2)", + "filename": "arrayobject.c", + "nloc": 4, + "complexity": 1, + "token_count": 24, + "parameters": [ + "m1", + "m2" + ], + "start_line": 2524, + "end_line": 2527, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 4, + "top_nesting_level": 0 + }, + { + "name": "array_negative", + "long_name": "array_negative( PyArrayObject * m1)", + "filename": "arrayobject.c", + "nloc": 4, + "complexity": 1, + "token_count": 18, + "parameters": [ + "m1" + ], + "start_line": 2530, + "end_line": 2533, + "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": 2536, + "end_line": 2539, + "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": 2542, + "end_line": 2545, + "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": 2548, + "end_line": 2551, + "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": 2554, + "end_line": 2557, + "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": 2560, + "end_line": 2563, + "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": 2566, + "end_line": 2569, + "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": 2572, + "end_line": 2575, + "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": 2578, + "end_line": 2581, + "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": 2584, + "end_line": 2587, + "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": 2590, + "end_line": 2593, + "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": 2596, + "end_line": 2599, + "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": 2602, + "end_line": 2605, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 4, + "top_nesting_level": 0 + }, + { + "name": "array_inplace_power", + "long_name": "array_inplace_power( PyArrayObject * m1 , PyObject * m2)", + "filename": "arrayobject.c", + "nloc": 4, + "complexity": 1, + "token_count": 24, + "parameters": [ + "m1", + "m2" + ], + "start_line": 2608, + "end_line": 2611, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 4, + "top_nesting_level": 0 + }, + { + "name": "array_inplace_left_shift", + "long_name": "array_inplace_left_shift( PyArrayObject * m1 , PyObject * m2)", + "filename": "arrayobject.c", + "nloc": 4, + "complexity": 1, + "token_count": 24, + "parameters": [ + "m1", + "m2" + ], + "start_line": 2614, + "end_line": 2617, + "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": 2620, + "end_line": 2623, + "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": 2626, + "end_line": 2629, + "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": 2632, + "end_line": 2635, + "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": 2638, + "end_line": 2641, + "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": 2644, + "end_line": 2647, + "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": 2650, + "end_line": 2653, + "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": 2656, + "end_line": 2660, + "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": 2663, + "end_line": 2667, + "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": 2671, + "end_line": 2689, + "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": 2692, + "end_line": 2709, + "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": 2714, + "end_line": 2729, + "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": 2733, + "end_line": 2759, + "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": 2762, + "end_line": 2787, + "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": 2790, + "end_line": 2812, + "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": 2815, + "end_line": 2837, + "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": 2840, + "end_line": 2862, + "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": 2865, + "end_line": 2869, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 5, + "top_nesting_level": 0 + }, + { + "name": "array_slice", + "long_name": "array_slice( PyArrayObject * self , int ilow , int ihigh)", + "filename": "arrayobject.c", + "nloc": 36, + "complexity": 11, + "token_count": 259, + "parameters": [ + "self", + "ilow", + "ihigh" + ], + "start_line": 2930, + "end_line": 2970, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 41, + "top_nesting_level": 0 + }, + { + "name": "array_ass_slice", + "long_name": "array_ass_slice( PyArrayObject * self , int ilow , int ihigh , PyObject * v)", + "filename": "arrayobject.c", + "nloc": 20, + "complexity": 4, + "token_count": 108, + "parameters": [ + "self", + "ilow", + "ihigh", + "v" + ], + "start_line": 2974, + "end_line": 2995, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 22, + "top_nesting_level": 0 + }, + { + "name": "array_contains", + "long_name": "array_contains( PyArrayObject * self , PyObject * el)", + "filename": "arrayobject.c", + "nloc": 10, + "complexity": 2, + "token_count": 66, + "parameters": [ + "self", + "el" + ], + "start_line": 2998, + "end_line": 3010, + "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": 3031, + "end_line": 3078, + "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": 3081, + "end_line": 3117, + "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": 3126, + "end_line": 3143, + "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": 3146, + "end_line": 3158, + "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": 3161, + "end_line": 3173, + "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": 73, + "complexity": 15, + "token_count": 325, + "parameters": [ + "self", + "other", + "cmp_op" + ], + "start_line": 3176, + "end_line": 3265, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 90, + "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": 3268, + "end_line": 3297, + "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": 3303, + "end_line": 3323, + "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": 3331, + "end_line": 3366, + "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": 3372, + "end_line": 3391, + "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": 3395, + "end_line": 3413, + "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": 3416, + "end_line": 3433, + "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": 3436, + "end_line": 3469, + "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": 3476, + "end_line": 3503, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 28, + "top_nesting_level": 0 + }, + { + "name": "PyArray_CheckStrides", + "long_name": "PyArray_CheckStrides( int elsize , int nd , intp numbytes , intp * dims , intp * newstrides)", + "filename": "arrayobject.c", + "nloc": 13, + "complexity": 4, + "token_count": 84, + "parameters": [ + "elsize", + "nd", + "numbytes", + "dims", + "newstrides" + ], + "start_line": 3512, + "end_line": 3527, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 16, + "top_nesting_level": 0 + }, + { + "name": "_array_fill_strides", + "long_name": "_array_fill_strides( intp * strides , intp * dims , int nd , intp itemsize , int inflag , int * objflags)", + "filename": "arrayobject.c", + "nloc": 24, + "complexity": 9, + "token_count": 171, + "parameters": [ + "strides", + "dims", + "nd", + "itemsize", + "inflag", + "objflags" + ], + "start_line": 3547, + "end_line": 3571, + "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": 3577, + "end_line": 3599, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 23, + "top_nesting_level": 0 + }, + { + "name": "_update_descr_and_dimensions", + "long_name": "_update_descr_and_dimensions( PyArray_Descr ** des , intp * newdims , intp * newstrides , int oldnd)", + "filename": "arrayobject.c", + "nloc": 37, + "complexity": 6, + "token_count": 229, + "parameters": [ + "des", + "newdims", + "newstrides", + "oldnd" + ], + "start_line": 3603, + "end_line": 3645, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 43, + "top_nesting_level": 0 + }, + { + "name": "PyArray_NewFromDescr", + "long_name": "PyArray_NewFromDescr( PyTypeObject * subtype , PyArray_Descr * descr , int nd , intp * dims , intp * strides , * data , int flags , PyObject * obj)", + "filename": "arrayobject.c", + "nloc": 136, + "complexity": 27, + "token_count": 781, + "parameters": [ + "subtype", + "descr", + "nd", + "dims", + "strides", + "data", + "flags", + "obj" + ], + "start_line": 3653, + "end_line": 3818, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 166, + "top_nesting_level": 0 + }, + { + "name": "PyArray_Resize", + "long_name": "PyArray_Resize( PyArrayObject * self , PyArray_Dims * newshape)", + "filename": "arrayobject.c", + "nloc": 82, + "complexity": 15, + "token_count": 497, + "parameters": [ + "self", + "newshape" + ], + "start_line": 3827, + "end_line": 3925, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 99, + "top_nesting_level": 0 + }, + { + "name": "PyArray_FillObjectArray", + "long_name": "PyArray_FillObjectArray( PyArrayObject * arr , PyObject * obj)", + "filename": "arrayobject.c", + "nloc": 18, + "complexity": 4, + "token_count": 98, + "parameters": [ + "arr", + "obj" + ], + "start_line": 3931, + "end_line": 3948, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 18, + "top_nesting_level": 0 + }, + { + "name": "PyArray_FillWithScalar", + "long_name": "PyArray_FillWithScalar( PyArrayObject * arr , PyObject * obj)", + "filename": "arrayobject.c", + "nloc": 41, + "complexity": 6, + "token_count": 231, + "parameters": [ + "arr", + "obj" + ], + "start_line": 3952, + "end_line": 3994, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 43, + "top_nesting_level": 0 + }, + { + "name": "array_new", + "long_name": "array_new( PyTypeObject * subtype , PyObject * args , PyObject * kwds)", + "filename": "arrayobject.c", + "nloc": 103, + "complexity": 19, + "token_count": 583, + "parameters": [ + "subtype", + "args", + "kwds" + ], + "start_line": 3997, + "end_line": 4116, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 120, + "top_nesting_level": 0 + }, + { + "name": "array_iter", + "long_name": "array_iter( PyArrayObject * arr)", + "filename": "arrayobject.c", + "nloc": 9, + "complexity": 2, + "token_count": 38, + "parameters": [ + "arr" + ], + "start_line": 4120, + "end_line": 4128, + "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": 4134, + "end_line": 4137, + "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": 4140, + "end_line": 4144, + "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": 4147, + "end_line": 4150, + "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": 4154, + "end_line": 4183, + "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": 4187, + "end_line": 4190, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 4, + "top_nesting_level": 0 + }, + { + "name": "array_strides_set", + "long_name": "array_strides_set( PyArrayObject * self , PyObject * obj)", + "filename": "arrayobject.c", + "nloc": 36, + "complexity": 7, + "token_count": 231, + "parameters": [ + "self", + "obj" + ], + "start_line": 4193, + "end_line": 4231, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 39, + "top_nesting_level": 0 + }, + { + "name": "array_protocol_strides_get", + "long_name": "array_protocol_strides_get( PyArrayObject * self)", + "filename": "arrayobject.c", + "nloc": 8, + "complexity": 2, + "token_count": 35, + "parameters": [ + "self" + ], + "start_line": 4235, + "end_line": 4242, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 8, + "top_nesting_level": 0 + }, + { + "name": "array_priority_get", + "long_name": "array_priority_get( PyArrayObject * self)", + "filename": "arrayobject.c", + "nloc": 9, + "complexity": 3, + "token_count": 42, + "parameters": [ + "self" + ], + "start_line": 4245, + "end_line": 4253, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 9, + "top_nesting_level": 0 + }, + { + "name": "array_dataptr_get", + "long_name": "array_dataptr_get( PyArrayObject * self)", + "filename": "arrayobject.c", + "nloc": 7, + "complexity": 2, + "token_count": 35, + "parameters": [ + "self" + ], + "start_line": 4257, + "end_line": 4263, + "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": 4266, + "end_line": 4280, + "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": 4283, + "end_line": 4327, + "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": 4331, + "end_line": 4334, + "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": 4337, + "end_line": 4348, + "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": 4351, + "end_line": 4362, + "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": 4368, + "end_line": 4371, + "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": 4374, + "end_line": 4378, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 5, + "top_nesting_level": 0 + }, + { + "name": "array_descr_set", + "long_name": "array_descr_set( PyArrayObject * self , PyObject * arg)", + "filename": "arrayobject.c", + "nloc": 63, + "complexity": 15, + "token_count": 443, + "parameters": [ + "self", + "arg" + ], + "start_line": 4392, + "end_line": 4477, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 86, + "top_nesting_level": 0 + }, + { + "name": "array_protocol_descr_get", + "long_name": "array_protocol_descr_get( PyArrayObject * self)", + "filename": "arrayobject.c", + "nloc": 16, + "complexity": 4, + "token_count": 117, + "parameters": [ + "self" + ], + "start_line": 4480, + "end_line": 4498, + "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": 4501, + "end_line": 4519, + "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": 4522, + "end_line": 4532, + "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": 4536, + "end_line": 4561, + "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": 4565, + "end_line": 4598, + "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": 4601, + "end_line": 4634, + "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": 4637, + "end_line": 4674, + "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": 4677, + "end_line": 4680, + "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": 4683, + "end_line": 4733, + "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": 4823, + "end_line": 4830, + "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": 4932, + "end_line": 4965, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 34, + "top_nesting_level": 0 + }, + { + "name": "discover_itemsize", + "long_name": "discover_itemsize( PyObject * s , int nd , int * itemsize)", + "filename": "arrayobject.c", + "nloc": 21, + "complexity": 9, + "token_count": 161, + "parameters": [ + "s", + "nd", + "itemsize" + ], + "start_line": 4968, + "end_line": 4990, + "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": 4997, + "end_line": 5023, + "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": 5029, + "end_line": 5061, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 33, + "top_nesting_level": 0 + }, + { + "name": "_array_find_type", + "long_name": "_array_find_type( PyObject * op , PyArray_Descr * minitype , int max)", + "filename": "arrayobject.c", + "nloc": 127, + "complexity": 34, + "token_count": 736, + "parameters": [ + "op", + "minitype", + "max" + ], + "start_line": 5073, + "end_line": 5218, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 146, + "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": 5221, + "end_line": 5244, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 24, + "top_nesting_level": 0 + }, + { + "name": "Array_FromScalar", + "long_name": "Array_FromScalar( PyObject * op , PyArray_Descr * typecode)", + "filename": "arrayobject.c", + "nloc": 29, + "complexity": 7, + "token_count": 171, + "parameters": [ + "op", + "typecode" + ], + "start_line": 5249, + "end_line": 5283, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 35, + "top_nesting_level": 0 + }, + { + "name": "Array_FromSequence", + "long_name": "Array_FromSequence( PyObject * s , PyArray_Descr * typecode , int fortran , int min_depth , int max_depth)", + "filename": "arrayobject.c", + "nloc": 54, + "complexity": 21, + "token_count": 355, + "parameters": [ + "s", + "typecode", + "fortran", + "min_depth", + "max_depth" + ], + "start_line": 5288, + "end_line": 5351, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 64, + "top_nesting_level": 0 + }, + { + "name": "PyArray_ValidType", + "long_name": "PyArray_ValidType( int type)", + "filename": "arrayobject.c", + "nloc": 9, + "complexity": 2, + "token_count": 41, + "parameters": [ + "type" + ], + "start_line": 5358, + "end_line": 5367, + "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": 5373, + "end_line": 5466, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 94, + "top_nesting_level": 0 + }, + { + "name": "PyArray_CastToType", + "long_name": "PyArray_CastToType( PyArrayObject * mp , PyArray_Descr * at , int fortran)", + "filename": "arrayobject.c", + "nloc": 40, + "complexity": 16, + "token_count": 280, + "parameters": [ + "mp", + "at", + "fortran" + ], + "start_line": 5476, + "end_line": 5522, + "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": 5532, + "end_line": 5585, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 54, + "top_nesting_level": 0 + }, + { + "name": "PyArray_FromArray", + "long_name": "PyArray_FromArray( PyArrayObject * arr , PyArray_Descr * newtype , int flags)", + "filename": "arrayobject.c", + "nloc": 114, + "complexity": 33, + "token_count": 676, + "parameters": [ + "arr", + "newtype", + "flags" + ], + "start_line": 5590, + "end_line": 5719, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 130, + "top_nesting_level": 0 + }, + { + "name": "_array_typedescr_fromstr", + "long_name": "_array_typedescr_fromstr( char * str)", + "filename": "arrayobject.c", + "nloc": 98, + "complexity": 36, + "token_count": 505, + "parameters": [ + "str" + ], + "start_line": 5723, + "end_line": 5831, + "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": 5835, + "end_line": 5875, + "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": 5879, + "end_line": 6017, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 139, + "top_nesting_level": 0 + }, + { + "name": "PyArray_FromArrayAttr", + "long_name": "PyArray_FromArrayAttr( PyObject * op , PyArray_Descr * typecode , PyObject * context)", + "filename": "arrayobject.c", + "nloc": 37, + "complexity": 11, + "token_count": 221, + "parameters": [ + "op", + "typecode", + "context" + ], + "start_line": 6021, + "end_line": 6058, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 38, + "top_nesting_level": 0 + }, + { + "name": "PyArray_FromAny", + "long_name": "PyArray_FromAny( PyObject * op , PyArray_Descr * newtype , int min_depth , int max_depth , int flags , PyObject * context)", + "filename": "arrayobject.c", + "nloc": 63, + "complexity": 20, + "token_count": 383, + "parameters": [ + "op", + "newtype", + "min_depth", + "max_depth", + "flags", + "context" + ], + "start_line": 6064, + "end_line": 6144, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 81, + "top_nesting_level": 0 + }, + { + "name": "PyArray_DescrFromObject", + "long_name": "PyArray_DescrFromObject( PyObject * op , PyArray_Descr * mintype)", + "filename": "arrayobject.c", + "nloc": 4, + "complexity": 1, + "token_count": 22, + "parameters": [ + "op", + "mintype" + ], + "start_line": 6149, + "end_line": 6152, + "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": 6159, + "end_line": 6172, + "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": 6218, + "end_line": 6234, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 17, + "top_nesting_level": 0 + }, + { + "name": "PyArray_EnsureArray", + "long_name": "PyArray_EnsureArray( PyObject * op)", + "filename": "arrayobject.c", + "nloc": 14, + "complexity": 5, + "token_count": 89, + "parameters": [ + "op" + ], + "start_line": 6247, + "end_line": 6263, + "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": 6269, + "end_line": 6357, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 89, + "top_nesting_level": 0 + }, + { + "name": "PyArray_CanCastTo", + "long_name": "PyArray_CanCastTo( PyArray_Descr * from , PyArray_Descr * to)", + "filename": "arrayobject.c", + "nloc": 24, + "complexity": 7, + "token_count": 134, + "parameters": [ + "from", + "to" + ], + "start_line": 6362, + "end_line": 6390, + "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": 6403, + "end_line": 6441, + "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": 6449, + "end_line": 6466, + "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": 6471, + "end_line": 6481, + "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": 6484, + "end_line": 6488, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 5, + "top_nesting_level": 0 + }, + { + "name": "iter_length", + "long_name": "iter_length( PyArrayIterObject * self)", + "filename": "arrayobject.c", + "nloc": 4, + "complexity": 1, + "token_count": 16, + "parameters": [ + "self" + ], + "start_line": 6491, + "end_line": 6494, + "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": 6498, + "end_line": 6548, + "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": 6551, + "end_line": 6605, + "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": 6609, + "end_line": 6742, + "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": 6746, + "end_line": 6778, + "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": 6781, + "end_line": 6823, + "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": 6826, + "end_line": 6960, + "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": 6973, + "end_line": 7018, + "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": 7023, + "end_line": 7027, + "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": 7043, + "end_line": 7058, + "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": 7123, + "end_line": 7139, + "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": 7146, + "end_line": 7215, + "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": 7219, + "end_line": 7256, + "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": 7262, + "end_line": 7306, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 45, + "top_nesting_level": 0 + }, + { + "name": "PyArray_MapIterBind", + "long_name": "PyArray_MapIterBind( PyArrayMapIterObject * mit , PyArrayObject * arr)", + "filename": "arrayobject.c", + "nloc": 98, + "complexity": 21, + "token_count": 662, + "parameters": [ + "mit", + "arr" + ], + "start_line": 7324, + "end_line": 7452, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 129, + "top_nesting_level": 0 + }, + { + "name": "_nonzero_indices", + "long_name": "_nonzero_indices( PyObject * myBool , PyArrayIterObject ** iters)", + "filename": "arrayobject.c", + "nloc": 60, + "complexity": 15, + "token_count": 462, + "parameters": [ + "myBool", + "iters" + ], + "start_line": 7458, + "end_line": 7530, + "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": 7533, + "end_line": 7659, + "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": 7663, + "end_line": 7672, + "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": 7743, + "end_line": 7792, + "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": 7795, + "end_line": 7840, + "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": 7843, + "end_line": 7862, + "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": 7865, + "end_line": 7872, + "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": 7875, + "end_line": 7885, + "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": 7888, + "end_line": 7898, + "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": 7901, + "end_line": 7904, + "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": 7907, + "end_line": 7919, + "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": 7949, + "end_line": 7956, + "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": 8015, + "end_line": 8024, + "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": 8042, + "end_line": 8064, + "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": 8070, + "end_line": 8080, + "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": 8099, + "end_line": 8107, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 9, + "top_nesting_level": 0 + }, + { + "name": "arraydescr_protocol_typestr_get", + "long_name": "arraydescr_protocol_typestr_get( PyArray_Descr * self)", + "filename": "arrayobject.c", + "nloc": 11, + "complexity": 3, + "token_count": 60, + "parameters": [ + "self" + ], + "start_line": 8110, + "end_line": 8122, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 13, + "top_nesting_level": 0 + }, + { + "name": "arraydescr_typename_get", + "long_name": "arraydescr_typename_get( PyArray_Descr * self)", + "filename": "arrayobject.c", + "nloc": 19, + "complexity": 4, + "token_count": 122, + "parameters": [ + "self" + ], + "start_line": 8125, + "end_line": 8147, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 23, + "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": 8150, + "end_line": 8169, + "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": 8176, + "end_line": 8183, + "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": 8186, + "end_line": 8193, + "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": 8196, + "end_line": 8203, + "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": 8243, + "end_line": 8295, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 53, + "top_nesting_level": 0 + }, + { + "name": "arraydescr_reduce", + "long_name": "arraydescr_reduce( PyArray_Descr * self , PyObject * args)", + "filename": "arrayobject.c", + "nloc": 50, + "complexity": 12, + "token_count": 377, + "parameters": [ + "self", + "args" + ], + "start_line": 8301, + "end_line": 8358, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 58, + "top_nesting_level": 0 + }, + { + "name": "arraydescr_setstate", + "long_name": "arraydescr_setstate( PyArray_Descr * self , PyObject * args)", + "filename": "arrayobject.c", + "nloc": 35, + "complexity": 8, + "token_count": 260, + "parameters": [ + "self", + "args" + ], + "start_line": 8366, + "end_line": 8408, + "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": 8428, + "end_line": 8494, + "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": 8505, + "end_line": 8513, + "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": 8528, + "end_line": 8573, + "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": 8576, + "end_line": 8585, + "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": 8588, + "end_line": 8598, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 11, + "top_nesting_level": 0 + } + ], + "methods_before": [ + { + "name": "PyArray_GetPriority", + "long_name": "PyArray_GetPriority( PyObject * obj , double default_)", + "filename": "arrayobject.c", + "nloc": 17, + "complexity": 5, + "token_count": 86, + "parameters": [ + "obj", + "default_" + ], + "start_line": 28, + "end_line": 46, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 19, + "top_nesting_level": 0 + }, + { + "name": "PyArray_Zero", + "long_name": "PyArray_Zero( PyArrayObject * arr)", + "filename": "arrayobject.c", + "nloc": 27, + "complexity": 4, + "token_count": 148, + "parameters": [ + "arr" + ], + "start_line": 67, + "end_line": 95, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 29, + "top_nesting_level": 0 + }, + { + "name": "PyArray_One", + "long_name": "PyArray_One( PyArrayObject * arr)", + "filename": "arrayobject.c", + "nloc": 27, + "complexity": 4, + "token_count": 148, + "parameters": [ + "arr" + ], + "start_line": 101, + "end_line": 130, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 30, + "top_nesting_level": 0 + }, + { + "name": "do_sliced_copy", + "long_name": "do_sliced_copy( char * dest , intp * dest_strides , intp * dest_dimensions , int dest_nd , char * src , intp * src_strides , intp * src_dimensions , int src_nd , int elsize , int copies)", + "filename": "arrayobject.c", + "nloc": 48, + "complexity": 13, + "token_count": 313, + "parameters": [ + "dest", + "dest_strides", + "dest_dimensions", + "dest_nd", + "src", + "src_strides", + "src_dimensions", + "src_nd", + "elsize", + "copies" + ], + "start_line": 136, + "end_line": 186, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 51, + "top_nesting_level": 0 + }, + { + "name": "optimize_slices", + "long_name": "optimize_slices( intp ** dest_strides , intp ** dest_dimensions , int * dest_nd , intp ** src_strides , intp ** src_dimensions , int * src_nd , int * elsize , int * copies)", + "filename": "arrayobject.c", + "nloc": 32, + "complexity": 8, + "token_count": 214, + "parameters": [ + "dest_strides", + "dest_dimensions", + "dest_nd", + "src_strides", + "src_dimensions", + "src_nd", + "elsize", + "copies" + ], + "start_line": 209, + "end_line": 240, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 32, + "top_nesting_level": 0 + }, + { + "name": "contiguous_data", + "long_name": "contiguous_data( PyArrayObject * src)", + "filename": "arrayobject.c", + "nloc": 29, + "complexity": 4, + "token_count": 215, + "parameters": [ + "src" + ], + "start_line": 243, + "end_line": 277, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 35, + "top_nesting_level": 0 + }, + { + "name": "PyArray_INCREF", + "long_name": "PyArray_INCREF( PyArrayObject * mp)", + "filename": "arrayobject.c", + "nloc": 17, + "complexity": 6, + "token_count": 125, + "parameters": [ + "mp" + ], + "start_line": 293, + "end_line": 315, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 23, + "top_nesting_level": 0 + }, + { + "name": "PyArray_XDECREF", + "long_name": "PyArray_XDECREF( PyArrayObject * mp)", + "filename": "arrayobject.c", + "nloc": 17, + "complexity": 6, + "token_count": 125, + "parameters": [ + "mp" + ], + "start_line": 321, + "end_line": 342, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 22, + "top_nesting_level": 0 + }, + { + "name": "byte_swap_vector", + "long_name": "byte_swap_vector( * p , int n , int size)", + "filename": "arrayobject.c", + "nloc": 38, + "complexity": 10, + "token_count": 340, + "parameters": [ + "p", + "n", + "size" + ], + "start_line": 346, + "end_line": 384, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 39, + "top_nesting_level": 0 + }, + { + "name": "copy_and_swap", + "long_name": "copy_and_swap( * dst , * src , int itemsize , intp numitems , intp srcstrides , int swap)", + "filename": "arrayobject.c", + "nloc": 18, + "complexity": 5, + "token_count": 120, + "parameters": [ + "dst", + "src", + "itemsize", + "numitems", + "srcstrides", + "swap" + ], + "start_line": 389, + "end_line": 409, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 21, + "top_nesting_level": 0 + }, + { + "name": "PyArray_PyIntAsIntp", + "long_name": "PyArray_PyIntAsIntp( PyObject * o)", + "filename": "arrayobject.c", + "nloc": 71, + "complexity": 21, + "token_count": 413, + "parameters": [ + "o" + ], + "start_line": 423, + "end_line": 505, + "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": 512, + "end_line": 586, + "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": 589, + "end_line": 604, + "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": 610, + "end_line": 618, + "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": 634, + "end_line": 714, + "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": 718, + "end_line": 732, + "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": 745, + "end_line": 771, + "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": 777, + "end_line": 791, + "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": 800, + "end_line": 820, + "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": 81, + "complexity": 12, + "token_count": 483, + "parameters": [ + "data", + "descr", + "base" + ], + "start_line": 829, + "end_line": 913, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 85, + "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": 929, + "end_line": 932, + "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": 942, + "end_line": 964, + "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": 978, + "end_line": 1018, + "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": 1033, + "end_line": 1074, + "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": 1081, + "end_line": 1172, + "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": 1178, + "end_line": 1207, + "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": 1210, + "end_line": 1246, + "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": 1255, + "end_line": 1292, + "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": 1299, + "end_line": 1307, + "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": 1310, + "end_line": 1335, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 26, + "top_nesting_level": 0 + }, + { + "name": "array_item_nice", + "long_name": "array_item_nice( PyArrayObject * self , int i)", + "filename": "arrayobject.c", + "nloc": 4, + "complexity": 1, + "token_count": 29, + "parameters": [ + "self", + "i" + ], + "start_line": 1338, + "end_line": 1341, + "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": 1345, + "end_line": 1380, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 36, + "top_nesting_level": 0 + }, + { + "name": "array_ass_item", + "long_name": "array_ass_item( PyArrayObject * self , int i , PyObject * v)", + "filename": "arrayobject.c", + "nloc": 4, + "complexity": 1, + "token_count": 28, + "parameters": [ + "self", + "i", + "v" + ], + "start_line": 1386, + "end_line": 1389, + "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": 1395, + "end_line": 1403, + "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": 1409, + "end_line": 1459, + "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": 1466, + "end_line": 1511, + "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": 1515, + "end_line": 1609, + "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": 1612, + "end_line": 1649, + "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": 1661, + "end_line": 1714, + "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": 1717, + "end_line": 1777, + "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": 1780, + "end_line": 1807, + "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": 1810, + "end_line": 1829, + "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": 1841, + "end_line": 1903, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 63, + "top_nesting_level": 0 + }, + { + "name": "array_subscript", + "long_name": "array_subscript( PyArrayObject * self , PyObject * op)", + "filename": "arrayobject.c", + "nloc": 103, + "complexity": 28, + "token_count": 666, + "parameters": [ + "self", + "op" + ], + "start_line": 1927, + "end_line": 2045, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 119, + "top_nesting_level": 0 + }, + { + "name": "array_ass_sub", + "long_name": "array_ass_sub( PyArrayObject * self , PyObject * index , PyObject * op)", + "filename": "arrayobject.c", + "nloc": 93, + "complexity": 28, + "token_count": 588, + "parameters": [ + "self", + "index", + "op" + ], + "start_line": 2060, + "end_line": 2165, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 106, + "top_nesting_level": 0 + }, + { + "name": "array_subscript_nice", + "long_name": "array_subscript_nice( PyArrayObject * self , PyObject * op)", + "filename": "arrayobject.c", + "nloc": 4, + "complexity": 1, + "token_count": 27, + "parameters": [ + "self", + "op" + ], + "start_line": 2174, + "end_line": 2177, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 4, + "top_nesting_level": 0 + }, + { + "name": "array_getsegcount", + "long_name": "array_getsegcount( PyArrayObject * self , int * lenp)", + "filename": "arrayobject.c", + "nloc": 11, + "complexity": 4, + "token_count": 48, + "parameters": [ + "self", + "lenp" + ], + "start_line": 2196, + "end_line": 2208, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 13, + "top_nesting_level": 0 + }, + { + "name": "array_getreadbuf", + "long_name": "array_getreadbuf( PyArrayObject * self , int segment , ** ptrptr)", + "filename": "arrayobject.c", + "nloc": 15, + "complexity": 3, + "token_count": 72, + "parameters": [ + "self", + "segment", + "ptrptr" + ], + "start_line": 2211, + "end_line": 2226, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 16, + "top_nesting_level": 0 + }, + { + "name": "array_getwritebuf", + "long_name": "array_getwritebuf( PyArrayObject * self , int segment , ** ptrptr)", + "filename": "arrayobject.c", + "nloc": 10, + "complexity": 2, + "token_count": 54, + "parameters": [ + "self", + "segment", + "ptrptr" + ], + "start_line": 2230, + "end_line": 2239, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 10, + "top_nesting_level": 0 + }, + { + "name": "array_getcharbuf", + "long_name": "array_getcharbuf( PyArrayObject * self , int segment , const char ** ptrptr)", + "filename": "arrayobject.c", + "nloc": 12, + "complexity": 3, + "token_count": 65, + "parameters": [ + "self", + "segment", + "ptrptr" + ], + "start_line": 2242, + "end_line": 2253, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 12, + "top_nesting_level": 0 + }, + { + "name": "PyArray_SetNumericOps", + "long_name": "PyArray_SetNumericOps( PyObject * dict)", + "filename": "arrayobject.c", + "nloc": 34, + "complexity": 1, + "token_count": 162, + "parameters": [ + "dict" + ], + "start_line": 2324, + "end_line": 2357, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 34, + "top_nesting_level": 0 + }, + { + "name": "PyArray_GetNumericOps", + "long_name": "PyArray_GetNumericOps()", + "filename": "arrayobject.c", + "nloc": 39, + "complexity": 2, + "token_count": 183, + "parameters": [], + "start_line": 2367, + "end_line": 2406, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 40, + "top_nesting_level": 0 + }, + { + "name": "PyArray_GenericReduceFunction", + "long_name": "PyArray_GenericReduceFunction( PyArrayObject * m1 , PyObject * op , int axis , int rtype)", + "filename": "arrayobject.c", + "nloc": 24, + "complexity": 5, + "token_count": 141, + "parameters": [ + "m1", + "op", + "axis", + "rtype" + ], + "start_line": 2409, + "end_line": 2432, + "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": 2436, + "end_line": 2459, + "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": 2463, + "end_line": 2470, + "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": 2473, + "end_line": 2480, + "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": 2483, + "end_line": 2491, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 9, + "top_nesting_level": 0 + }, + { + "name": "array_add", + "long_name": "array_add( PyArrayObject * m1 , PyObject * m2)", + "filename": "arrayobject.c", + "nloc": 4, + "complexity": 1, + "token_count": 24, + "parameters": [ + "m1", + "m2" + ], + "start_line": 2494, + "end_line": 2497, + "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": 2500, + "end_line": 2503, + "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": 2506, + "end_line": 2509, + "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": 2512, + "end_line": 2515, + "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": 2518, + "end_line": 2521, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 4, + "top_nesting_level": 0 + }, + { + "name": "array_power", + "long_name": "array_power( PyArrayObject * m1 , PyObject * m2)", + "filename": "arrayobject.c", + "nloc": 4, + "complexity": 1, + "token_count": 24, + "parameters": [ + "m1", + "m2" + ], + "start_line": 2524, + "end_line": 2527, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 4, + "top_nesting_level": 0 + }, + { + "name": "array_negative", + "long_name": "array_negative( PyArrayObject * m1)", + "filename": "arrayobject.c", + "nloc": 4, + "complexity": 1, + "token_count": 18, + "parameters": [ + "m1" + ], + "start_line": 2530, + "end_line": 2533, + "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": 2536, + "end_line": 2539, + "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": 2542, + "end_line": 2545, + "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": 2548, + "end_line": 2551, + "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": 2554, + "end_line": 2557, + "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": 2560, + "end_line": 2563, + "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": 2566, + "end_line": 2569, + "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": 2572, + "end_line": 2575, + "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": 2578, + "end_line": 2581, + "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": 2584, + "end_line": 2587, + "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": 2590, + "end_line": 2593, + "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": 2596, + "end_line": 2599, + "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": 2602, + "end_line": 2605, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 4, + "top_nesting_level": 0 + }, + { + "name": "array_inplace_power", + "long_name": "array_inplace_power( PyArrayObject * m1 , PyObject * m2)", + "filename": "arrayobject.c", + "nloc": 4, + "complexity": 1, + "token_count": 24, + "parameters": [ + "m1", + "m2" + ], + "start_line": 2608, + "end_line": 2611, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 4, + "top_nesting_level": 0 + }, + { + "name": "array_inplace_left_shift", + "long_name": "array_inplace_left_shift( PyArrayObject * m1 , PyObject * m2)", + "filename": "arrayobject.c", + "nloc": 4, + "complexity": 1, + "token_count": 24, + "parameters": [ + "m1", + "m2" + ], + "start_line": 2614, + "end_line": 2617, + "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": 2620, + "end_line": 2623, + "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": 2626, + "end_line": 2629, + "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": 2632, + "end_line": 2635, + "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": 2638, + "end_line": 2641, + "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": 2644, + "end_line": 2647, + "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": 2650, + "end_line": 2653, + "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": 2656, + "end_line": 2660, + "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": 2663, + "end_line": 2667, + "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": 2671, + "end_line": 2689, + "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": 2692, + "end_line": 2709, + "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": 2714, + "end_line": 2729, + "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": 2733, + "end_line": 2759, + "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": 2762, + "end_line": 2787, + "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": 2790, + "end_line": 2812, + "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": 2815, + "end_line": 2837, + "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": 2840, + "end_line": 2862, + "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": 2865, + "end_line": 2869, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 5, + "top_nesting_level": 0 + }, + { + "name": "array_slice", + "long_name": "array_slice( PyArrayObject * self , int ilow , int ihigh)", + "filename": "arrayobject.c", + "nloc": 36, + "complexity": 11, + "token_count": 259, + "parameters": [ + "self", + "ilow", + "ihigh" + ], + "start_line": 2930, + "end_line": 2970, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 41, + "top_nesting_level": 0 + }, + { + "name": "array_ass_slice", + "long_name": "array_ass_slice( PyArrayObject * self , int ilow , int ihigh , PyObject * v)", + "filename": "arrayobject.c", + "nloc": 20, + "complexity": 4, + "token_count": 108, + "parameters": [ + "self", + "ilow", + "ihigh", + "v" + ], + "start_line": 2974, + "end_line": 2995, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 22, + "top_nesting_level": 0 + }, + { + "name": "array_contains", + "long_name": "array_contains( PyArrayObject * self , PyObject * el)", + "filename": "arrayobject.c", + "nloc": 10, + "complexity": 2, + "token_count": 66, + "parameters": [ + "self", + "el" + ], + "start_line": 2998, + "end_line": 3010, + "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": 3031, + "end_line": 3078, + "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": 3081, + "end_line": 3117, + "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": 3126, + "end_line": 3143, + "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": 3146, + "end_line": 3158, + "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": 3161, + "end_line": 3173, + "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": 73, + "complexity": 15, + "token_count": 325, + "parameters": [ + "self", + "other", + "cmp_op" + ], + "start_line": 3176, + "end_line": 3265, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 90, + "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": 3268, + "end_line": 3297, + "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": 3303, + "end_line": 3323, + "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": 3331, + "end_line": 3366, + "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": 3372, + "end_line": 3391, + "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": 3395, + "end_line": 3413, + "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": 3416, + "end_line": 3433, + "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": 3436, + "end_line": 3469, + "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": 3476, + "end_line": 3503, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 28, + "top_nesting_level": 0 + }, + { + "name": "PyArray_CheckStrides", + "long_name": "PyArray_CheckStrides( int elsize , int nd , intp numbytes , intp * dims , intp * newstrides)", + "filename": "arrayobject.c", + "nloc": 13, + "complexity": 4, + "token_count": 84, + "parameters": [ + "elsize", + "nd", + "numbytes", + "dims", + "newstrides" + ], + "start_line": 3512, + "end_line": 3527, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 16, + "top_nesting_level": 0 + }, + { + "name": "_array_fill_strides", + "long_name": "_array_fill_strides( intp * strides , intp * dims , int nd , intp itemsize , int inflag , int * objflags)", + "filename": "arrayobject.c", + "nloc": 24, + "complexity": 9, + "token_count": 171, + "parameters": [ + "strides", + "dims", + "nd", + "itemsize", + "inflag", + "objflags" + ], + "start_line": 3547, + "end_line": 3571, + "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": 3577, + "end_line": 3599, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 23, + "top_nesting_level": 0 + }, + { + "name": "_update_descr_and_dimensions", + "long_name": "_update_descr_and_dimensions( PyArray_Descr ** des , intp * newdims , intp * newstrides , int oldnd)", + "filename": "arrayobject.c", + "nloc": 37, + "complexity": 6, + "token_count": 229, + "parameters": [ + "des", + "newdims", + "newstrides", + "oldnd" + ], + "start_line": 3603, + "end_line": 3645, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 43, + "top_nesting_level": 0 + }, + { + "name": "PyArray_NewFromDescr", + "long_name": "PyArray_NewFromDescr( PyTypeObject * subtype , PyArray_Descr * descr , int nd , intp * dims , intp * strides , * data , int flags , PyObject * obj)", + "filename": "arrayobject.c", + "nloc": 136, + "complexity": 27, + "token_count": 781, + "parameters": [ + "subtype", + "descr", + "nd", + "dims", + "strides", + "data", + "flags", + "obj" + ], + "start_line": 3653, + "end_line": 3818, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 166, + "top_nesting_level": 0 + }, + { + "name": "PyArray_Resize", + "long_name": "PyArray_Resize( PyArrayObject * self , PyArray_Dims * newshape)", + "filename": "arrayobject.c", + "nloc": 82, + "complexity": 15, + "token_count": 497, + "parameters": [ + "self", + "newshape" + ], + "start_line": 3827, + "end_line": 3925, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 99, + "top_nesting_level": 0 + }, + { + "name": "PyArray_FillObjectArray", + "long_name": "PyArray_FillObjectArray( PyArrayObject * arr , PyObject * obj)", + "filename": "arrayobject.c", + "nloc": 18, + "complexity": 4, + "token_count": 98, + "parameters": [ + "arr", + "obj" + ], + "start_line": 3931, + "end_line": 3948, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 18, + "top_nesting_level": 0 + }, + { + "name": "PyArray_FillWithScalar", + "long_name": "PyArray_FillWithScalar( PyArrayObject * arr , PyObject * obj)", + "filename": "arrayobject.c", + "nloc": 41, + "complexity": 6, + "token_count": 231, + "parameters": [ + "arr", + "obj" + ], + "start_line": 3952, + "end_line": 3994, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 43, + "top_nesting_level": 0 + }, + { + "name": "array_new", + "long_name": "array_new( PyTypeObject * subtype , PyObject * args , PyObject * kwds)", + "filename": "arrayobject.c", + "nloc": 103, + "complexity": 19, + "token_count": 583, + "parameters": [ + "subtype", + "args", + "kwds" + ], + "start_line": 3997, + "end_line": 4116, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 120, + "top_nesting_level": 0 + }, + { + "name": "array_iter", + "long_name": "array_iter( PyArrayObject * arr)", + "filename": "arrayobject.c", + "nloc": 9, + "complexity": 2, + "token_count": 38, + "parameters": [ + "arr" + ], + "start_line": 4120, + "end_line": 4128, + "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": 4134, + "end_line": 4137, + "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": 4140, + "end_line": 4144, + "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": 4147, + "end_line": 4150, + "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": 4154, + "end_line": 4183, + "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": 4187, + "end_line": 4190, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 4, + "top_nesting_level": 0 + }, + { + "name": "array_strides_set", + "long_name": "array_strides_set( PyArrayObject * self , PyObject * obj)", + "filename": "arrayobject.c", + "nloc": 36, + "complexity": 7, + "token_count": 231, + "parameters": [ + "self", + "obj" + ], + "start_line": 4193, + "end_line": 4231, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 39, + "top_nesting_level": 0 + }, + { + "name": "array_protocol_strides_get", + "long_name": "array_protocol_strides_get( PyArrayObject * self)", + "filename": "arrayobject.c", + "nloc": 8, + "complexity": 2, + "token_count": 35, + "parameters": [ + "self" + ], + "start_line": 4235, + "end_line": 4242, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 8, + "top_nesting_level": 0 + }, + { + "name": "array_priority_get", + "long_name": "array_priority_get( PyArrayObject * self)", + "filename": "arrayobject.c", + "nloc": 9, + "complexity": 3, + "token_count": 42, + "parameters": [ + "self" + ], + "start_line": 4245, + "end_line": 4253, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 9, + "top_nesting_level": 0 + }, + { + "name": "array_dataptr_get", + "long_name": "array_dataptr_get( PyArrayObject * self)", + "filename": "arrayobject.c", + "nloc": 7, + "complexity": 2, + "token_count": 35, + "parameters": [ + "self" + ], + "start_line": 4257, + "end_line": 4263, + "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": 4266, + "end_line": 4280, + "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": 4283, + "end_line": 4327, + "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": 4331, + "end_line": 4334, + "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": 4337, + "end_line": 4348, + "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": 4351, + "end_line": 4362, + "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": 4368, + "end_line": 4371, + "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": 4374, + "end_line": 4378, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 5, + "top_nesting_level": 0 + }, + { + "name": "array_descr_set", + "long_name": "array_descr_set( PyArrayObject * self , PyObject * arg)", + "filename": "arrayobject.c", + "nloc": 63, + "complexity": 15, + "token_count": 443, + "parameters": [ + "self", + "arg" + ], + "start_line": 4392, + "end_line": 4477, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 86, + "top_nesting_level": 0 + }, + { + "name": "array_protocol_descr_get", + "long_name": "array_protocol_descr_get( PyArrayObject * self)", + "filename": "arrayobject.c", + "nloc": 16, + "complexity": 4, + "token_count": 117, + "parameters": [ + "self" + ], + "start_line": 4480, + "end_line": 4498, + "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": 4501, + "end_line": 4519, + "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": 4522, + "end_line": 4532, + "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": 4536, + "end_line": 4561, + "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": 4565, + "end_line": 4598, + "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": 4601, + "end_line": 4634, + "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": 4637, + "end_line": 4674, + "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": 4677, + "end_line": 4680, + "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": 4683, + "end_line": 4733, + "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": 4823, + "end_line": 4830, + "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": 4932, + "end_line": 4965, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 34, + "top_nesting_level": 0 + }, + { + "name": "discover_itemsize", + "long_name": "discover_itemsize( PyObject * s , int nd , int * itemsize)", + "filename": "arrayobject.c", + "nloc": 21, + "complexity": 9, + "token_count": 161, + "parameters": [ + "s", + "nd", + "itemsize" + ], + "start_line": 4968, + "end_line": 4990, + "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": 4997, + "end_line": 5023, + "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": 5029, + "end_line": 5061, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 33, + "top_nesting_level": 0 + }, + { + "name": "_array_find_type", + "long_name": "_array_find_type( PyObject * op , PyArray_Descr * minitype , int max)", + "filename": "arrayobject.c", + "nloc": 127, + "complexity": 34, + "token_count": 736, + "parameters": [ + "op", + "minitype", + "max" + ], + "start_line": 5073, + "end_line": 5218, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 146, + "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": 5221, + "end_line": 5244, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 24, + "top_nesting_level": 0 + }, + { + "name": "Array_FromScalar", + "long_name": "Array_FromScalar( PyObject * op , PyArray_Descr * typecode)", + "filename": "arrayobject.c", + "nloc": 23, + "complexity": 6, + "token_count": 146, + "parameters": [ + "op", + "typecode" + ], + "start_line": 5249, + "end_line": 5277, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 29, + "top_nesting_level": 0 + }, + { + "name": "Array_FromSequence", + "long_name": "Array_FromSequence( PyObject * s , PyArray_Descr * typecode , int fortran , int min_depth , int max_depth)", + "filename": "arrayobject.c", + "nloc": 57, + "complexity": 21, + "token_count": 367, + "parameters": [ + "s", + "typecode", + "fortran", + "min_depth", + "max_depth" + ], + "start_line": 5282, + "end_line": 5346, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 65, + "top_nesting_level": 0 + }, + { + "name": "PyArray_ValidType", + "long_name": "PyArray_ValidType( int type)", + "filename": "arrayobject.c", + "nloc": 9, + "complexity": 2, + "token_count": 41, + "parameters": [ + "type" + ], + "start_line": 5353, + "end_line": 5362, + "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": 5368, + "end_line": 5461, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 94, + "top_nesting_level": 0 + }, + { + "name": "PyArray_CastToType", + "long_name": "PyArray_CastToType( PyArrayObject * mp , PyArray_Descr * at , int fortran)", + "filename": "arrayobject.c", + "nloc": 40, + "complexity": 16, + "token_count": 280, + "parameters": [ + "mp", + "at", + "fortran" + ], + "start_line": 5471, + "end_line": 5517, + "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": 5527, + "end_line": 5580, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 54, + "top_nesting_level": 0 + }, + { + "name": "PyArray_FromArray", + "long_name": "PyArray_FromArray( PyArrayObject * arr , PyArray_Descr * newtype , int flags)", + "filename": "arrayobject.c", + "nloc": 114, + "complexity": 33, + "token_count": 676, + "parameters": [ + "arr", + "newtype", + "flags" + ], + "start_line": 5585, + "end_line": 5714, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 130, + "top_nesting_level": 0 + }, + { + "name": "_array_typedescr_fromstr", + "long_name": "_array_typedescr_fromstr( char * str)", + "filename": "arrayobject.c", + "nloc": 98, + "complexity": 36, + "token_count": 505, + "parameters": [ + "str" + ], + "start_line": 5718, + "end_line": 5826, + "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": 5830, + "end_line": 5870, + "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": 5874, + "end_line": 6012, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 139, + "top_nesting_level": 0 + }, + { + "name": "PyArray_FromArrayAttr", + "long_name": "PyArray_FromArrayAttr( PyObject * op , PyArray_Descr * typecode , PyObject * context)", + "filename": "arrayobject.c", + "nloc": 37, + "complexity": 11, + "token_count": 221, + "parameters": [ + "op", + "typecode", + "context" + ], + "start_line": 6016, + "end_line": 6053, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 38, + "top_nesting_level": 0 + }, + { + "name": "PyArray_FromAny", + "long_name": "PyArray_FromAny( PyObject * op , PyArray_Descr * newtype , int min_depth , int max_depth , int flags , PyObject * context)", + "filename": "arrayobject.c", + "nloc": 59, + "complexity": 20, + "token_count": 369, + "parameters": [ + "op", + "newtype", + "min_depth", + "max_depth", + "flags", + "context" + ], + "start_line": 6059, + "end_line": 6135, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 77, + "top_nesting_level": 0 + }, + { + "name": "PyArray_DescrFromObject", + "long_name": "PyArray_DescrFromObject( PyObject * op , PyArray_Descr * mintype)", + "filename": "arrayobject.c", + "nloc": 4, + "complexity": 1, + "token_count": 22, + "parameters": [ + "op", + "mintype" + ], + "start_line": 6140, + "end_line": 6143, + "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": 6150, + "end_line": 6163, + "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": 6209, + "end_line": 6225, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 17, + "top_nesting_level": 0 + }, + { + "name": "PyArray_EnsureArray", + "long_name": "PyArray_EnsureArray( PyObject * op)", + "filename": "arrayobject.c", + "nloc": 14, + "complexity": 5, + "token_count": 89, + "parameters": [ + "op" + ], + "start_line": 6238, + "end_line": 6254, + "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": 6260, + "end_line": 6348, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 89, + "top_nesting_level": 0 + }, + { + "name": "PyArray_CanCastTo", + "long_name": "PyArray_CanCastTo( PyArray_Descr * from , PyArray_Descr * to)", + "filename": "arrayobject.c", + "nloc": 24, + "complexity": 7, + "token_count": 134, + "parameters": [ + "from", + "to" + ], + "start_line": 6353, + "end_line": 6381, + "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": 6394, + "end_line": 6432, + "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": 6440, + "end_line": 6457, + "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": 6462, + "end_line": 6472, + "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": 6475, + "end_line": 6479, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 5, + "top_nesting_level": 0 + }, + { + "name": "iter_length", + "long_name": "iter_length( PyArrayIterObject * self)", + "filename": "arrayobject.c", + "nloc": 4, + "complexity": 1, + "token_count": 16, + "parameters": [ + "self" + ], + "start_line": 6482, + "end_line": 6485, + "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": 6489, + "end_line": 6539, + "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": 6542, + "end_line": 6596, + "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": 6600, + "end_line": 6733, + "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": 6737, + "end_line": 6769, + "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": 6772, + "end_line": 6814, + "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": 6817, + "end_line": 6951, + "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": 6964, + "end_line": 7009, + "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": 7014, + "end_line": 7018, + "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": 7034, + "end_line": 7049, + "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": 7114, + "end_line": 7130, + "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": 7137, + "end_line": 7206, + "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": 7210, + "end_line": 7247, + "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": 7253, + "end_line": 7297, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 45, + "top_nesting_level": 0 + }, + { + "name": "PyArray_MapIterBind", + "long_name": "PyArray_MapIterBind( PyArrayMapIterObject * mit , PyArrayObject * arr)", + "filename": "arrayobject.c", + "nloc": 98, + "complexity": 21, + "token_count": 662, + "parameters": [ + "mit", + "arr" + ], + "start_line": 7315, + "end_line": 7443, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 129, + "top_nesting_level": 0 + }, + { + "name": "_nonzero_indices", + "long_name": "_nonzero_indices( PyObject * myBool , PyArrayIterObject ** iters)", + "filename": "arrayobject.c", + "nloc": 60, + "complexity": 15, + "token_count": 462, + "parameters": [ + "myBool", + "iters" + ], + "start_line": 7449, + "end_line": 7521, + "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": 7524, + "end_line": 7650, + "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": 7654, + "end_line": 7663, + "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": 7734, + "end_line": 7783, + "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": 7786, + "end_line": 7831, + "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": 7834, + "end_line": 7853, + "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": 7856, + "end_line": 7863, + "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": 7866, + "end_line": 7876, + "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": 7879, + "end_line": 7889, + "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": 7892, + "end_line": 7895, + "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": 7898, + "end_line": 7910, + "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": 7940, + "end_line": 7947, + "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": 8006, + "end_line": 8015, + "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": 8033, + "end_line": 8055, + "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": 8061, + "end_line": 8071, + "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": 8090, + "end_line": 8098, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 9, + "top_nesting_level": 0 + }, + { + "name": "arraydescr_protocol_typestr_get", + "long_name": "arraydescr_protocol_typestr_get( PyArray_Descr * self)", + "filename": "arrayobject.c", + "nloc": 11, + "complexity": 3, + "token_count": 60, + "parameters": [ + "self" + ], + "start_line": 8101, + "end_line": 8113, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 13, + "top_nesting_level": 0 + }, + { + "name": "arraydescr_typename_get", + "long_name": "arraydescr_typename_get( PyArray_Descr * self)", + "filename": "arrayobject.c", + "nloc": 19, + "complexity": 4, + "token_count": 122, + "parameters": [ + "self" + ], + "start_line": 8116, + "end_line": 8138, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 23, + "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": 8141, + "end_line": 8160, + "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": 8167, + "end_line": 8174, + "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": 8177, + "end_line": 8184, + "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": 8187, + "end_line": 8194, + "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": 8234, + "end_line": 8286, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 53, + "top_nesting_level": 0 + }, + { + "name": "arraydescr_reduce", + "long_name": "arraydescr_reduce( PyArray_Descr * self , PyObject * args)", + "filename": "arrayobject.c", + "nloc": 50, + "complexity": 12, + "token_count": 377, + "parameters": [ + "self", + "args" + ], + "start_line": 8292, + "end_line": 8349, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 58, + "top_nesting_level": 0 + }, + { + "name": "arraydescr_setstate", + "long_name": "arraydescr_setstate( PyArray_Descr * self , PyObject * args)", + "filename": "arrayobject.c", + "nloc": 35, + "complexity": 8, + "token_count": 260, + "parameters": [ + "self", + "args" + ], + "start_line": 8357, + "end_line": 8399, + "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": 8419, + "end_line": 8485, + "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": 8496, + "end_line": 8504, + "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": 8519, + "end_line": 8564, + "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": 8567, + "end_line": 8576, + "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": 8579, + "end_line": 8589, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 11, + "top_nesting_level": 0 + } + ], + "changed_methods": [ + { + "name": "Array_FromSequence", + "long_name": "Array_FromSequence( PyObject * s , PyArray_Descr * typecode , int fortran , int min_depth , int max_depth)", + "filename": "arrayobject.c", + "nloc": 54, + "complexity": 21, + "token_count": 355, + "parameters": [ + "s", + "typecode", + "fortran", + "min_depth", + "max_depth" + ], + "start_line": 5288, + "end_line": 5351, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 64, + "top_nesting_level": 0 + }, + { + "name": "Array_FromScalar", + "long_name": "Array_FromScalar( PyObject * op , PyArray_Descr * typecode)", + "filename": "arrayobject.c", + "nloc": 29, + "complexity": 7, + "token_count": 171, + "parameters": [ + "op", + "typecode" + ], + "start_line": 5249, + "end_line": 5283, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 35, + "top_nesting_level": 0 + }, + { + "name": "PyArray_FromAny", + "long_name": "PyArray_FromAny( PyObject * op , PyArray_Descr * newtype , int min_depth , int max_depth , int flags , PyObject * context)", + "filename": "arrayobject.c", + "nloc": 63, + "complexity": 20, + "token_count": 383, + "parameters": [ + "op", + "newtype", + "min_depth", + "max_depth", + "flags", + "context" + ], + "start_line": 6064, + "end_line": 6144, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 81, + "top_nesting_level": 0 + } + ], + "nloc": 6860, + "complexity": 1470, + "token_count": 40339, + "diff_parsed": { + "added": [ + "\tif (ret->nd > 0) {", + "\t\tPyErr_SetString(PyExc_ValueError,", + "\t\t\t\t\"shape-mismatch on array construction\");", + "\t\tPy_DECREF(ret);", + "\t\treturn NULL;", + "\t}", + "/* steals reference to typecode */", + "\t\tgoto fail;", + "\t\tgoto fail;", + "\tif(discover_dimensions(s,nd,d, !stop_at_string) == -1) goto fail;", + "", + "\t\tif (discover_itemsize(s, nd, &itemsize) == -1) goto fail;", + " if(!r) return NULL;", + "", + " fail:", + "\tPy_DECREF(typecode);", + "\treturn NULL;", + "", + "\t\t\tPy_INCREF(newtype);", + "\t\t\tif (PyErr_Occurred() && r == NULL) {", + "\t\t\t\tPyErr_Clear();", + "\t\t\t}", + " else {", + "\t\t\t\tseq = TRUE;", + "\t\t\t\tPy_DECREF(newtype);", + "\t\t\t}" + ], + "deleted": [ + "/* steals reference to typecode unless return value is NULL*/", + "\tPyArray_Descr *savetype=typecode;", + " return NULL;", + " return NULL;", + "\tif(discover_dimensions(s,nd,d, !stop_at_string) == -1) {", + "\t\treturn NULL;", + "\t}", + "\t\tif (discover_itemsize(s, nd, &itemsize) == -1) {", + "\t\t\treturn NULL;", + "\t\t}", + " if(!r) {Py_XINCREF(savetype); return NULL;}", + "\t\tPy_XINCREF(savetype);", + "", + "\t\t\tif (PyErr_Occurred() && r == NULL)", + " PyErr_Clear();", + " else", + " seq = TRUE;" + ] + } + }, + { + "old_path": "numpy/core/src/multiarraymodule.c", + "new_path": "numpy/core/src/multiarraymodule.c", + "filename": "multiarraymodule.c", + "extension": "c", + "change_type": "MODIFY", + "diff": "@@ -3393,6 +3393,7 @@ _convert_from_tuple(PyObject *obj)\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@@ -3517,8 +3518,13 @@ _convert_from_list(PyObject *obj, int align, int try_descr)\n \t\ttup = PyTuple_New(2);\n \t\tkey = PyString_FromFormat(\"f%d\", i+1);\n \t\tret = PyArray_DescrConverter(PyList_GET_ITEM(obj, i), &conv);\n- if (!hasobject && conv->hasobject)\n- hasobject=1; \n+\t\tif (ret == PY_FAIL) {\n+\t\t\tPy_DECREF(tup);\n+\t\t\tPy_DECREF(key);\n+\t\t\tgoto fail;\n+\t\t}\n+\t\tif (!hasobject && conv->hasobject)\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@@ -3531,7 +3537,6 @@ _convert_from_list(PyObject *obj, int align, int try_descr)\n \t\tPyDict_SetItem(fields, key, tup);\n \t\tPy_DECREF(tup);\n \t\tPyList_SET_ITEM(nameslist, i, key);\n-\t\tif (ret == PY_FAIL) goto fail;\n \t\ttotalsize += conv->elsize;\n \t}\n \tkey = PyInt_FromLong(-1);\n@@ -3686,8 +3691,6 @@ _convert_from_dict(PyObject *obj, int align)\n \t\ttup = PyTuple_New(len);\n \t\tdescr = PyObject_GetItem(descrs, index);\n \t\tret = PyArray_DescrConverter(descr, &newdescr);\n- if (!hasobject && newdescr->hasobject)\n- hasobject = 1;\n \t\tPy_DECREF(descr);\n \t\tPyTuple_SET_ITEM(tup, 0, (PyObject *)newdescr);\n \t\tif (offsets) {\n@@ -3727,6 +3730,8 @@ _convert_from_dict(PyObject *obj, int align)\n \t\tif (len == 3) PyDict_SetItem(fields, item, tup);\n \t\tPy_DECREF(tup);\n \t\tif ((ret == PY_FAIL) || (newdescr->elsize == 0)) goto fail;\n+ if (!hasobject && newdescr->hasobject)\n+ hasobject = 1;\n \t\ttotalsize += newdescr->elsize;\n \t}\n \n", + "added_lines": 10, + "deleted_lines": 5, + "source_code": "\n/*\n Python Multiarray Module -- A useful collection of functions for creating and\n using ndarrays\n\n Original file \n Copyright (c) 1995, 1996, 1997 Jim Hugunin, hugunin@mit.edu\n\n Modified for numpy_core in 2005 \n\n Travis E. Oliphant\n Assistant Professor at\n Brigham Young University\n \n*/\n\n/* $Id: multiarraymodule.c,v 1.36 2005/09/14 00:14:00 teoliphant Exp $ */\n\n#include \"Python.h\"\n#include \"structmember.h\"\n/*#include \n#include \n*/\n\n#define _MULTIARRAYMODULE\n#include \"numpy/arrayobject.h\"\n\n#define PyAO PyArrayObject\n\nstatic PyObject *typeDict=NULL; /* Must be explicitly loaded */\nstatic PyObject *_numpy_internal=NULL; /* A Python module for callbacks */\n\n\nstatic PyArray_Descr *\n_arraydescr_fromobj(PyObject *obj)\n{\n\tPyObject *dtypedescr;\n\tPyArray_Descr *new;\n\tint ret;\n\t\n\tdtypedescr = PyObject_GetAttrString(obj, \"dtype\");\n\tPyErr_Clear();\n\tif (dtypedescr) {\n\t\tret = PyArray_DescrConverter(dtypedescr, &new);\n\t\tPy_DECREF(dtypedescr);\n\t\tif (ret) return new;\n\t\tPyErr_Clear();\n\t}\n\treturn NULL;\n}\n\n\n/* Including this file is the only way I know how to declare functions\n static in each file, and store the pointers from functions in both\n arrayobject.c and multiarraymodule.c for the C-API \n\n Declarying an external pointer-containing variable in arrayobject.c\n and trying to copy it to PyArray_API, did not work.\n\n Think about two modules with a common api that import each other...\n\n This file would just be the module calls. \n*/\n\n#include \"arrayobject.c\"\n\n\n/* An Error object -- rarely used? */\nstatic PyObject *MultiArrayError;\n\n/*MULTIARRAY_API\n Multiply a List of ints\n*/\nstatic int\nPyArray_MultiplyIntList(register int *l1, register int n) \n{\n\tregister int s=1;\n while (n--) s *= (*l1++);\n return s;\n}\n\n/*MULTIARRAY_API\n Multiply a List\n*/\nstatic intp \nPyArray_MultiplyList(register intp *l1, register int n) \n{\n\tregister intp s=1;\n while (n--) s *= (*l1++);\n return s;\n}\n\n/*MULTIARRAY_API\n Produce a pointer into array\n*/\nstatic char *\nPyArray_GetPtr(PyArrayObject *obj, register intp* ind)\n{\n\tregister int n = obj->nd;\n\tregister intp *strides = obj->strides;\n\tregister char *dptr = obj->data;\n\t\n\twhile (n--) dptr += (*strides++) * (*ind++);\n\treturn dptr;\n}\n\n/*MULTIARRAY_API\n Get axis from an object (possibly None) -- a converter function,\n*/\nstatic int \nPyArray_AxisConverter(PyObject *obj, int *axis)\n{\n\tif (obj == Py_None) {\n\t\t*axis = MAX_DIMS;\n\t}\n\telse {\n\t\t*axis = (int) PyInt_AsLong(obj);\n\t\tif (PyErr_Occurred()) {\n\t\t\treturn PY_FAIL;\n\t\t}\n\t}\n\treturn PY_SUCCEED;\n}\n\n/*MULTIARRAY_API\n Compare Lists\n*/\nstatic int \nPyArray_CompareLists(intp *l1, intp *l2, int n) \n{\n int i;\n for(i=0;iob_type;\n\t\n\tPy_INCREF(self->descr);\n\tnew = PyArray_NewFromDescr(subtype,\n\t\t\t\t self->descr,\n\t\t\t\t self->nd, self->dimensions,\n\t\t\t\t self->strides,\n\t\t\t\t self->data,\n\t\t\t\t self->flags, (PyObject *)self);\n\t\n\tif (new==NULL) return NULL;\n\tPy_INCREF(self);\n PyArray_BASE(new) = (PyObject *)self;\n\t\n\tif (type != NULL) {\n\t\tif (PyObject_SetAttrString(new, \"dtype\",\n\t\t\t\t\t (PyObject *)type) < 0) {\n\t\t\tPy_DECREF(new);\n\t\t\tPy_DECREF(type);\n\t\t\treturn NULL;\n\t\t}\n\t\tPy_DECREF(type);\n\t}\n\treturn new;\t\n}\n\n/*MULTIARRAY_API\n Ravel\n*/\nstatic PyObject *\nPyArray_Ravel(PyArrayObject *a, int fortran)\n{\n\tPyArray_Dims newdim = {NULL,1};\n\tintp val[1] = {-1};\n\n\tif (fortran < 0) fortran = PyArray_ISFORTRAN(a);\n\n\tnewdim.ptr = val;\n\tif (!fortran && PyArray_ISCONTIGUOUS(a)) {\n\t\tif (a->nd == 1) {\n\t\t\tPy_INCREF(a);\n\t\t\treturn (PyObject *)a;\n\t\t}\n\t\treturn PyArray_Newshape(a, &newdim);\n\t}\n\telse\n\t return PyArray_Flatten(a, fortran);\n}\n\n/*MULTIARRAY_API\n Flatten\n*/\nstatic PyObject *\nPyArray_Flatten(PyArrayObject *a, int fortran)\n{\n\tPyObject *ret, *new;\n\tintp size;\n\n\tif (fortran < 0) fortran = PyArray_ISFORTRAN(a);\n\n\tsize = PyArray_SIZE(a);\n\tPy_INCREF(a->descr);\n\tret = PyArray_NewFromDescr(a->ob_type,\n\t\t\t\t a->descr,\n\t\t\t\t 1, &size,\n\t\t\t\t NULL,\n\t\t\t\t NULL,\n\t\t\t\t 0, (PyObject *)a);\n\t\n\tif (ret== NULL) return NULL;\n\tif (fortran) {\n\t\tnew = PyArray_Transpose(a, NULL);\n\t\tif (new == NULL) {\n\t\t\tPy_DECREF(ret);\n\t\t\treturn NULL;\n\t\t}\n\t}\n\telse {\n\t\tPy_INCREF(a);\n\t\tnew = (PyObject *)a;\n\t}\n\tif (PyArray_CopyInto((PyArrayObject *)ret, (PyArrayObject *)new) < 0) {\n\t\tPy_DECREF(ret);\n\t\tPy_DECREF(new);\n\t\treturn NULL;\n\t}\n\tPy_DECREF(new);\n\treturn ret;\n}\n\n\n/* For back-ward compatability *\n\n/ * Not recommended */\n\n/*MULTIARRAY_API\n Reshape an array\n*/\nstatic PyObject *\nPyArray_Reshape(PyArrayObject *self, PyObject *shape) \n{\n PyObject *ret;\n PyArray_Dims newdims;\n\n if (!PyArray_IntpConverter(shape, &newdims)) return NULL;\n ret = PyArray_Newshape(self, &newdims);\n PyDimMem_FREE(newdims.ptr);\n return ret;\n}\n\nstatic int\n_check_ones(PyArrayObject *self, int newnd, intp* newdims, intp *strides)\n{\n\tint nd;\n\tintp *dims;\n\tBool done=FALSE;\n\tint j, k;\n\n\tnd = self->nd;\n\tdims = self->dimensions;\n\n\tfor (k=0, j=0; !done && (jstrides[j];\n\t\t\tj++; k++;\n\t\t}\n\t\telse if ((kptr;\n PyArrayObject *ret;\n\tchar msg[] = \"total size of new array must be unchanged\";\n\tint n = newdims->len;\n Bool same;\n\tintp *strides = NULL;\n\tintp newstrides[MAX_DIMS];\n\n /* Quick check to make sure anything needs to be done */\n if (n == self->nd) {\n same = TRUE;\n i=0;\n while(same && i= 0) {\n\t\t\tif ((s_known == 0) || (s_original % s_known != 0)) {\n\t\t\t\tPyErr_SetString(PyExc_ValueError, msg);\n\t\t\t\treturn NULL;\n\t\t\t}\n\t\t\tdimensions[i_unknown] = s_original/s_known;\n\t\t} else {\n\t\t\tif (s_original != s_known) {\n\t\t\t\tPyErr_SetString(PyExc_ValueError, msg);\n\t\t\t\treturn NULL;\n\t\t\t}\n\t\t}\n\t}\n \n\tPy_INCREF(self->descr);\n\tret = (PyAO *)PyArray_NewFromDescr(self->ob_type,\n\t\t\t\t\t self->descr,\n\t\t\t\t\t n, dimensions,\n\t\t\t\t\t strides,\n\t\t\t\t\t self->data,\n\t\t\t\t\t self->flags, (PyObject *)self);\n\t\n\tif (ret== NULL) return NULL;\n\t\n Py_INCREF(self);\n ret->base = (PyObject *)self;\n\tPyArray_UpdateFlags(ret, CONTIGUOUS | FORTRAN);\n\t\n return (PyObject *)ret;\n}\n\n/* return a new view of the array object with all of its unit-length \n dimensions squeezed out if needed, otherwise\n return the same array.\n */\n\n/*MULTIARRAY_API*/\nstatic PyObject *\nPyArray_Squeeze(PyArrayObject *self)\n{\n\tint nd = self->nd;\n\tint newnd = nd;\n\tintp dimensions[MAX_DIMS];\n\tintp strides[MAX_DIMS];\n\tint i,j;\n\tPyObject *ret;\n\n\tif (nd == 0) {\n\t\tPy_INCREF(self);\n\t\treturn (PyObject *)self;\n\t}\n\tfor (j=0, i=0; idimensions[i] == 1) {\n\t\t\tnewnd -= 1;\n\t\t}\n\t\telse {\n\t\t\tdimensions[j] = self->dimensions[i];\n\t\t\tstrides[j++] = self->strides[i];\n\t\t}\n\t}\n\t\n\tPy_INCREF(self->descr);\n\tret = PyArray_NewFromDescr(self->ob_type, \n\t\t\t\t self->descr,\n\t\t\t\t newnd, dimensions, \n\t\t\t\t strides, self->data, \n\t\t\t\t self->flags,\n\t\t\t\t (PyObject *)self);\n\tif (ret == NULL) return NULL;\n\tPyArray_FLAGS(ret) &= ~OWN_DATA;\n\tPyArray_BASE(ret) = (PyObject *)self;\n\tPy_INCREF(self);\n\treturn (PyObject *)ret;\n}\n\n\n/*MULTIARRAY_API\n Mean\n*/\nstatic PyObject *\nPyArray_Mean(PyArrayObject *self, int axis, int rtype)\n{\n\tPyObject *obj1=NULL, *obj2=NULL;\n\tPyObject *new, *ret;\n\n\tif ((new = _check_axis(self, &axis, 0))==NULL) return NULL;\n\n\tobj1 = PyArray_GenericReduceFunction((PyAO *)new, n_ops.add, axis,\n\t\t\t\t\t rtype);\n\tobj2 = PyFloat_FromDouble((double) PyArray_DIM(new,axis));\n Py_DECREF(new);\n\tif (obj1 == NULL || obj2 == NULL) {\n\t\tPy_XDECREF(obj1);\n\t\tPy_XDECREF(obj2);\n\t\treturn NULL;\n\t}\n\n\tret = PyNumber_Divide(obj1, obj2);\n\tPy_DECREF(obj1);\n\tPy_DECREF(obj2);\n\treturn ret;\n}\n\n/* Set variance to 1 to by-pass square-root calculation and return variance */\n/*MULTIARRAY_API\n Std\n*/\nstatic PyObject *\nPyArray_Std(PyArrayObject *self, int axis, int rtype, int variance)\n{\n\tPyObject *obj1=NULL, *obj2=NULL, *new=NULL;\n\tPyObject *ret=NULL, *newshape=NULL;\n\tint i, n;\n\tintp val;\n\n\tif ((new = _check_axis(self, &axis, 0))==NULL) return NULL;\n\t\n\t/* Compute and reshape mean */\n\tobj1 = PyArray_EnsureArray(PyArray_Mean((PyAO *)new, axis, rtype));\n\tif (obj1 == NULL) {Py_DECREF(new); return NULL;} \n\tn = PyArray_NDIM(new);\n\tnewshape = PyTuple_New(n);\n\tif (newshape == NULL) {Py_DECREF(obj1); Py_DECREF(new); return NULL;}\n\tfor (i=0; ind != 1) {\n Py_DECREF(cond);\n PyErr_SetString(PyExc_ValueError, \n\t\t\t\t\"condition must be 1-d array\");\n return NULL;\n }\n\n res = PyArray_Nonzero(cond);\n Py_DECREF(cond);\n\tret = PyArray_Take(self, res, axis);\n\tPy_DECREF(res);\n\treturn ret;\n}\n\n/*MULTIARRAY_API\n Nonzero\n*/\nstatic PyObject *\nPyArray_Nonzero(PyArrayObject *self)\n{\n int n=self->nd, j;\n\tintp count=0, i, size;\n\tPyArrayIterObject *it=NULL;\n\tPyObject *ret=NULL, *item;\n\tintp *dptr[MAX_DIMS];\n\n\tit = (PyArrayIterObject *)PyArray_IterNew((PyObject *)self);\n\tif (it==NULL) return NULL;\n\n\tsize = it->size;\n\tfor (i=0; idescr->f->nonzero(it->dataptr, self)) count++;\n\t\tPyArray_ITER_NEXT(it);\n\t}\n\n\tPyArray_ITER_RESET(it);\n\tif (n==1) {\n\t\tret = PyArray_New(self->ob_type, 1, &count, PyArray_INTP, \n\t\t\t\t NULL, NULL, 0, 0, (PyObject *)self);\n\t\tif (ret == NULL) goto fail;\n\t\tdptr[0] = (intp *)PyArray_DATA(ret);\n\t\t\n\t\tfor (i=0; idescr->f->nonzero(it->dataptr, self)) \n\t\t\t\t*(dptr[0])++ = i;\n\t\t\tPyArray_ITER_NEXT(it);\n\t\t}\t\t\n\t}\n\telse {\n\t\tret = PyTuple_New(n);\n\t\tfor (j=0; job_type, 1, &count, \n\t\t\t\t\t PyArray_INTP, NULL, NULL, 0, 0,\n\t\t\t\t\t (PyObject *)self);\n\t\t\tif (item == NULL) goto fail;\n\t\t\tPyTuple_SET_ITEM(ret, j, item);\n\t\t\tdptr[j] = (intp *)PyArray_DATA(item);\n\t\t}\n\t\t\n\t\t/* reset contiguous so that coordinates gets updated */\n\t\tit->contiguous = 0;\n\t\tfor (i=0; idescr->f->nonzero(it->dataptr, self)) \n\t\t\t\tfor (j=0; jcoordinates[j];\n\t\t\tPyArray_ITER_NEXT(it);\n\t\t}\n\t}\n\n\tPy_DECREF(it);\n\treturn ret;\n\n fail:\n\tPy_XDECREF(ret);\n\tPy_XDECREF(it);\n\treturn NULL;\n \n}\n\n/*MULTIARRAY_API\n Clip\n*/\nstatic PyObject *\nPyArray_Clip(PyArrayObject *self, PyObject *min, PyObject *max)\n{\n\tPyObject *selector=NULL, *newtup=NULL, *ret=NULL;\n\tPyObject *res1=NULL, *res2=NULL, *res3=NULL;\n\tPyObject *two;\n\n\ttwo = PyInt_FromLong((long)2);\n\tres1 = PyArray_GenericBinaryFunction(self, max, n_ops.greater);\n\tres2 = PyArray_GenericBinaryFunction(self, min, n_ops.less);\n\tif ((res1 == NULL) || (res2 == NULL)) {\n\t\tPy_DECREF(two);\n\t\tPy_XDECREF(res1);\n\t\tPy_XDECREF(res2);\n\t}\n\tres3 = PyNumber_Multiply(two, res1);\n\tPy_DECREF(two); \n\tPy_DECREF(res1); \n\tif (res3 == NULL) return NULL;\n\n\tselector = PyArray_EnsureArray(PyNumber_Add(res2, res3));\n\tPy_DECREF(res2);\n\tPy_DECREF(res3);\n\tif (selector == NULL) return NULL;\n\n\tnewtup = Py_BuildValue(\"(OOO)\", (PyObject *)self, min, max);\n\tif (newtup == NULL) {Py_DECREF(selector); return NULL;}\n\tret = PyArray_Choose((PyAO *)selector, newtup);\n\tPy_DECREF(selector);\n\tPy_DECREF(newtup);\n\treturn ret;\n}\n\n/*MULTIARRAY_API\n Conjugate\n*/\nstatic PyObject *\nPyArray_Conjugate(PyArrayObject *self)\n{\n\tif (PyArray_ISCOMPLEX(self)) {\n\t\tPyObject *new;\n\t\tintp size, i;\n\t\t/* Make a copy */\n\t\tnew = PyArray_NewCopy(self, -1);\n\t\tif (new==NULL) return NULL;\n\t\tsize = PyArray_SIZE(new);\n\t\tif (self->descr->type_num == PyArray_CFLOAT) {\n\t\t\tcfloat *dptr = (cfloat *) PyArray_DATA(new);\n\t\t\tfor (i=0; iimag = -dptr->imag;\n\t\t\t\tdptr++;\n\t\t\t}\n\t\t}\n\t\telse if (self->descr->type_num == PyArray_CDOUBLE) {\n\t\t\tcdouble *dptr = (cdouble *)PyArray_DATA(new);\n\t\t\tfor (i=0; iimag = -dptr->imag;\n\t\t\t\tdptr++;\n\t\t\t}\n\t\t}\n\t\telse if (self->descr->type_num == PyArray_CLONGDOUBLE) {\n\t\t\tclongdouble *dptr = (clongdouble *)PyArray_DATA(new);\n\t\t\tfor (i=0; iimag = -dptr->imag;\n\t\t\t\tdptr++;\n\t\t\t}\t\t\t\n\t\t}\t\t\n\t\treturn new;\n\t}\n\telse {\n\t\tPy_INCREF(self);\n\t\treturn (PyObject *) self;\n\t}\n}\n\n/*MULTIARRAY_API\n Trace\n*/\nstatic PyObject *\nPyArray_Trace(PyArrayObject *self, int offset, int axis1, int axis2, \nint rtype)\n{\n\tPyObject *diag=NULL, *ret=NULL;\n\n\tdiag = PyArray_Diagonal(self, offset, axis1, axis2);\n\tif (diag == NULL) return NULL;\n\tret = PyArray_GenericReduceFunction((PyAO *)diag, n_ops.add, -1, rtype);\n\tPy_DECREF(diag);\n\treturn ret;\n}\n\n/*MULTIARRAY_API\n Diagonal\n*/\nstatic PyObject *\nPyArray_Diagonal(PyArrayObject *self, int offset, int axis1, int axis2)\n{\n\tint n = self->nd;\n\tPyObject *new;\n\tPyArray_Dims newaxes;\n\tintp dims[MAX_DIMS];\n\tint i, pos;\t\n\n\tnewaxes.ptr = dims;\n\tif (n < 2) {\n\t\tPyErr_SetString(PyExc_ValueError, \n\t\t\t\t\"array.ndim must be >= 2\");\n\t\treturn NULL;\n\t}\n\tif (axis1 < 0) axis1 += n;\n\tif (axis2 < 0) axis2 += n;\n\tif ((axis1 == axis2) || (axis1 < 0) || (axis1 >= n) ||\t\\\n\t (axis2 < 0) || (axis2 >= n)) {\n\t\tPyErr_Format(PyExc_ValueError, \"axis1(=%d) and axis2(=%d) \"\\\n\t\t\t \"must be different and within range (nd=%d)\",\n\t\t\t axis1, axis2, n);\n\t\treturn NULL;\n\t}\n \n\tnewaxes.len = n;\n\t/* insert at the end */\n\tnewaxes.ptr[n-2] = axis1;\n\tnewaxes.ptr[n-1] = axis2;\n\tpos = 0;\n\tfor (i=0; idimensions[0];\n\t\tn2 = self->dimensions[1];\n\t\tstep = n2+1;\n\t\tif (offset < 0) {\n\t\t\tstart = -n2 * offset;\n\t\t\tstop = MIN(n2, n1+offset)*(n2+1) - n2*offset;\n\t\t}\n\t\telse {\n\t\t\tstart = offset;\n\t\t\tstop = MIN(n1, n2-offset)*(n2+1) + offset;\n\t\t}\n\t\t\n\t\t/* count = ceil((stop-start)/step) */\n\t\tcount = ((stop-start) / step) + (((stop-start) % step) != 0);\n\t\t\t\n\t\tindices = PyArray_New(&PyArray_Type, 1, &count, \n\t\t\t\t PyArray_INTP, NULL, NULL, 0, 0, NULL);\n\t\tif (indices == NULL) {\n\t\t\tPy_DECREF(self); return NULL;\n\t\t}\n\t\tdptr = (intp *)PyArray_DATA(indices);\n\t\tfor (n1=start; n1descr;\n\n\t\tmydiagonal = PyList_New(0);\n\t\tif (mydiagonal == NULL) {Py_DECREF(self); return NULL;}\n\t\tn1 = self->dimensions[0];\n\t\tfor (i=0; i 3)) {\n\t\tPyErr_SetString(PyExc_ValueError,\n\t\t\t\t\"C arrays of only 1-3 dimensions available\");\n\t\tPy_XDECREF(typedescr);\n\t\treturn -1;\n\t}\n\tif ((ap = (PyArrayObject*)PyArray_FromAny(*op, typedescr, nd, nd,\n\t\t\t\t\t\t CARRAY_FLAGS, NULL)) == NULL)\n\t\treturn -1;\n\tswitch(nd) {\n\tcase 1:\n\t\t*((char **)ptr) = ap->data;\n\t\tbreak;\n\tcase 2:\n\t\tn = ap->dimensions[0];\n\t\tptr2 = (char **)_pya_malloc(n * sizeof(char *));\n\t\tif (!ptr2) goto fail;\n\t\tfor (i=0; idata + i*ap->strides[0];\n\t\t}\n\t\t*((char ***)ptr) = ptr2;\n\t\tbreak;\t\t\n\tcase 3:\n\t\tn = ap->dimensions[0];\n\t\tm = ap->dimensions[1];\n\t\tptr3 = (char ***)_pya_malloc(n*(m+1) * sizeof(char *));\n\t\tif (!ptr3) goto fail;\n\t\tfor (i=0; idata + i*ap->strides[0] + \\\n\t\t\t\t\tj*ap->strides[1];\n\t\t\t}\n\t\t}\n\t\t*((char ****)ptr) = ptr3;\n\t}\n\tmemcpy(dims, ap->dimensions, nd*sizeof(intp));\n\t*op = (PyObject *)ap;\n\treturn 0;\n\n fail:\n\tPyErr_SetString(PyExc_MemoryError, \"no memory\");\n\treturn -1;\n}\n\n/* Deprecated --- Use PyArray_AsCArray instead */\n\n/*MULTIARRAY_API\n Convert to a 1D C-array\n*/\nstatic int \nPyArray_As1D(PyObject **op, char **ptr, int *d1, int typecode) \n{\n\tintp newd1;\n\tPyArray_Descr *descr;\n\n\tdescr = PyArray_DescrFromType(typecode);\t\n\tif (PyArray_AsCArray(op, (void *)ptr, &newd1, 1, descr) == -1)\n\t\treturn -1;\t\n\t*d1 = (int) newd1;\n\treturn 0;\n}\n\n/*MULTIARRAY_API\n Convert to a 2D C-array\n*/\nstatic int \nPyArray_As2D(PyObject **op, char ***ptr, int *d1, int *d2, int typecode) \n{\n\tintp newdims[2];\n\tPyArray_Descr *descr;\n\n\tdescr = PyArray_DescrFromType(typecode);\t\n\tif (PyArray_AsCArray(op, (void *)ptr, newdims, 2, descr) == -1)\n\t\treturn -1;\n\n\t*d1 = (int ) newdims[0];\n\t*d2 = (int ) newdims[1];\n return 0;\n}\n\n/* End Deprecated */\n\n/*MULTIARRAY_API\n Free pointers created if As2D is called\n*/\nstatic int \nPyArray_Free(PyObject *op, void *ptr) \n{\n PyArrayObject *ap = (PyArrayObject *)op;\n\t\n if ((ap->nd < 1) || (ap->nd > 3)) \n\t\treturn -1;\n if (ap->nd >= 2) {\n\t\t_pya_free(ptr);\n }\n Py_DECREF(ap);\n return 0;\n}\n\n\nstatic PyObject *\n_swap_and_concat(PyObject *op, int axis, int n)\n{\n\tPyObject *newtup=NULL;\n\tPyObject *otmp, *arr;\n\tint i;\n\n\tnewtup = PyTuple_New(n);\n\tif (newtup==NULL) return NULL;\n\tfor (i=0; i= MAX_DIMS) {\n\t\t\totmp = PyArray_Ravel(mps[i],0);\n\t\t\tPy_DECREF(mps[i]);\n\t\t\tmps[i] = (PyArrayObject *)otmp;\n\t\t}\n\t\tif (mps[i]->ob_type != subtype) {\n\t\t\tprior2 = PyArray_GetPriority((PyObject *)(mps[i]), 0.0);\n\t\t\tif (prior2 > prior1) {\n\t\t\t\tprior1 = prior2;\n\t\t\t\tsubtype = mps[i]->ob_type;\n\t\t\t\tret = mps[i];\n\t\t\t}\n\t\t}\n\t}\n\t\n\tnew_dim = 0;\n\tfor(i=0; ind;\n\t\telse {\n\t\t\tif (nd != mps[i]->nd) {\n\t\t\t\tPyErr_SetString(PyExc_ValueError, \n\t\t\t\t\t\t\"arrays must have same \"\\\n\t\t\t\t\t\t\"number of dimensions\");\n\t\t\t\tgoto fail;\n\t\t\t}\n\t\t\tif (!PyArray_CompareLists(mps[0]->dimensions+1, \n\t\t\t\t\t\t mps[i]->dimensions+1, \n\t\t\t\t\t\t nd-1)) {\n\t\t\t\tPyErr_SetString(PyExc_ValueError, \n\t\t\t\t\t\t\"array dimensions must \"\\\n\t\t\t\t\t\t\"agree except for d_0\");\n\t\t\t\tgoto fail;\n\t\t\t}\n\t\t}\n\t\tif (nd == 0) {\n\t\t\tPyErr_SetString(PyExc_ValueError, \n\t\t\t\t\t\"0-d arrays can't be concatenated\");\n\t\t\tgoto fail;\n\t\t}\n\t\tnew_dim += mps[i]->dimensions[0];\n\t}\n\t\n\ttmp = mps[0]->dimensions[0];\n\tmps[0]->dimensions[0] = new_dim;\n\tPy_INCREF(mps[0]->descr);\n\tret = (PyArrayObject *)PyArray_NewFromDescr(subtype, \n\t\t\t\t\t\t mps[0]->descr, nd,\n\t\t\t\t\t\t mps[0]->dimensions, \n\t\t\t\t\t\t NULL, NULL, 0,\n\t\t\t\t\t\t (PyObject *)ret);\n\tmps[0]->dimensions[0] = tmp;\n\t\n\tif (ret == NULL) goto fail;\n\t\n\tdata = ret->data;\n\tfor(i=0; idata, numbytes);\n\t\tdata += numbytes;\n\t}\n\t\n\tPyArray_INCREF(ret);\n\tfor(i=0; ind;\n\tif (n <= 1) {\n\t\tPy_INCREF(ap);\n\t\treturn (PyObject *)ap;\n\t}\n\n\tif (a1 < 0) a1 += n;\n\tif (a2 < 0) a2 += n;\n\tif ((a1 < 0) || (a1 >= n)) {\n\t\tPyErr_SetString(PyExc_ValueError, \n\t\t\t\t\"bad axis1 argument to swapaxes\");\n\t\treturn NULL;\n\t}\n\tif ((a2 < 0) || (a2 >= n)) {\n\t\tPyErr_SetString(PyExc_ValueError, \n\t\t\t\t\"bad axis2 argument to swapaxes\");\n\t\treturn NULL;\n\t}\n\tnew_axes.ptr = dims;\n\tnew_axes.len = n;\n\n\tfor (i=0; ind;\n\t\tfor(i=0; ilen;\n\t\taxes = permute->ptr;\n\t\tif (n > ap->nd) {\n\t\t\tPyErr_SetString(PyExc_ValueError, \n\t\t\t\t\t\"too many axes for this array\");\n\t\t\treturn NULL;\n\t\t}\n\t\tfor(i=0; ind+axis;\n\t\t\tif (axis < 0 || axis >= ap->nd) {\n\t\t\t\tPyErr_SetString(PyExc_ValueError, \n\t\t\t\t\t\t\"invalid axis for this array\");\n\t\t\t\treturn NULL;\n\t\t\t}\n\t\t\tpermutation[i] = axis;\n\t\t}\n\t}\n\t\n\t/* this allocates memory for dimensions and strides (but fills them\n\t incorrectly), sets up descr, and points data at ap->data. */\n\tPy_INCREF(ap->descr);\n\tret = (PyArrayObject *)\\\n\t\tPyArray_NewFromDescr(ap->ob_type, \n\t\t\t\t ap->descr, \n\t\t\t\t n, permutation, \n\t\t\t\t NULL, ap->data, ap->flags,\n\t\t\t\t (PyObject *)ap);\n\tif (ret == NULL) return NULL;\n\t\n\t/* point at true owner of memory: */\n\tret->base = (PyObject *)ap;\n\tPy_INCREF(ap);\n\t\n\tfor(i=0; idimensions[i] = ap->dimensions[permutation[i]];\n\t\tret->strides[i] = ap->strides[permutation[i]];\n\t}\n\tPyArray_UpdateFlags(ret, CONTIGUOUS | FORTRAN);\t\n\n\treturn (PyObject *)ret;\t\n}\n\n/*MULTIARRAY_API\n Repeat the array.\n*/\nstatic PyObject *\nPyArray_Repeat(PyArrayObject *aop, PyObject *op, int axis)\n{\n\tintp *counts;\n\tintp n, n_outer, i, j, k, chunk, total;\n\tintp tmp;\n\tint nd;\n\tPyArrayObject *repeats=NULL;\n\tPyObject *ap=NULL;\n\tPyArrayObject *ret=NULL;\n\tchar *new_data, *old_data;\n\n\trepeats = (PyAO *)PyArray_ContiguousFromAny(op, PyArray_INTP, 0, 1);\n\tif (repeats == NULL) return NULL;\n\tnd = repeats->nd;\n\tcounts = (intp *)repeats->data;\n\n\tif ((ap=_check_axis(aop, &axis, CARRAY_FLAGS))==NULL) {\n\t\tPy_DECREF(repeats);\n\t\treturn NULL;\n\t}\n\n\taop = (PyAO *)ap;\n\n\tif (nd == 1)\n\t\tn = repeats->dimensions[0];\n\telse /* nd == 0 */\n\t\tn = aop->dimensions[axis];\n\n\tif (aop->dimensions[axis] != n) {\n\t\tPyErr_SetString(PyExc_ValueError, \n\t\t\t\t\"a.shape[axis] != len(repeats)\");\n\t\tgoto fail;\n\t}\n\n\t\n\tif (nd == 0) \n\t\ttotal = counts[0]*n;\n\telse {\n\t\t\n\t\ttotal = 0;\n\t\tfor(j=0; jdimensions[axis] = total;\n\tPy_INCREF(aop->descr);\n\tret = (PyArrayObject *)PyArray_NewFromDescr(aop->ob_type, \n\t\t\t\t\t\t aop->descr,\n\t\t\t\t\t\t aop->nd,\n\t\t\t\t\t\t aop->dimensions,\n\t\t\t\t\t\t NULL, NULL, 0,\n\t\t\t\t\t\t (PyObject *)aop);\n\taop->dimensions[axis] = n;\n\t\n\tif (ret == NULL) goto fail;\n\t\n\tnew_data = ret->data;\n\told_data = aop->data;\n\t\n\tchunk = aop->descr->elsize;\n\tfor(i=axis+1; ind; i++) {\n\t\tchunk *= aop->dimensions[i];\n\t}\n\t\n\tn_outer = 1;\n\tfor(i=0; idimensions[i];\n\n\tfor(i=0; ind < mps[i]->nd) {\n\t\t\tPyErr_SetString(PyExc_ValueError, \n\t\t\t\t\t\"too many dimensions\");\n\t\t\tgoto fail;\n\t\t}\n\t\tif (!PyArray_CompareLists(ap->dimensions+(ap->nd-mps[i]->nd),\n\t\t\t\t mps[i]->dimensions, mps[i]->nd)) {\n\t\t\tPyErr_SetString(PyExc_ValueError, \n\t\t\t\t\t\"array dimensions must agree\");\n\t\t\tgoto fail;\n\t\t}\n\t\tsizes[i] = PyArray_NBYTES(mps[i]);\n\t}\n\t\n\tPy_INCREF(mps[0]->descr);\n\tret = (PyArrayObject *)PyArray_NewFromDescr(ap->ob_type, \n\t\t\t\t\t\t mps[0]->descr,\n\t\t\t\t\t\t ap->nd,\n\t\t\t\t\t\t ap->dimensions, \n\t\t\t\t\t\t NULL, NULL, 0,\n\t\t\t\t\t\t (PyObject *)ap);\n\tif (ret == NULL) goto fail;\n\t\n\telsize = ret->descr->elsize;\n\tm = PyArray_SIZE(ret);\n\tself_data = (intp *)ap->data;\n\tret_data = ret->data;\n\t\n\tfor (i=0; i= n) {\n\t\t\tPyErr_SetString(PyExc_ValueError, \n\t\t\t\t\t\"invalid entry in choice array\");\n\t\t\tgoto fail;\n\t\t}\n\t\toffset = i*elsize;\n\t\tif (offset >= sizes[mi]) {offset = offset % sizes[mi]; }\n\t\tmemmove(ret_data, mps[mi]->data+offset, elsize);\n\t\tret_data += elsize; self_data++;\n\t}\n\t\n\tPyArray_INCREF(ret);\n\tfor(i=0; idescr->f->sort[which];\n\tsize = it->size;\n\tN = op->dimensions[axis];\n\telsize = op->descr->elsize;\n\tastride = op->strides[axis];\n\n\tneedcopy = !(op->flags & ALIGNED) || (astride != (intp) elsize);\n\n\tif (needcopy) {\n\t\tchar *buffer;\n\t\tbuffer = PyDataMem_NEW(N*elsize);\n\t\twhile (size--) {\n\t\t\t_strided_copy(buffer, (intp) elsize, it->dataptr, \n\t\t\t\t astride, N, elsize);\n\t\t\tif (sort(buffer, N, op) < 0) {\n\t\t\t\tPyDataMem_FREE(buffer); goto fail;\n\t\t\t}\n\t\t\t_strided_copy(it->dataptr, astride, buffer, \n\t\t\t\t (intp) elsize, N, elsize);\n\t\t\tPyArray_ITER_NEXT(it);\n\t\t}\n\t\tPyDataMem_FREE(buffer);\n\t}\n\telse {\n\t\twhile (size--) {\n\t\t\tif (sort(it->dataptr, N, op) < 0) goto fail;\n\t\t\tPyArray_ITER_NEXT(it);\n\t\t}\n\t}\t\n\t\n\tEND_THREADS\n\t\n\tPy_DECREF(it);\n\treturn 0;\n\n fail:\n\tEND_THREADS\n\n\tPy_DECREF(it);\n\treturn 0;\n}\n\nstatic PyObject*\n_new_argsort(PyArrayObject *op, int axis, PyArray_SORTKIND which) \n{\n\n\tPyArrayIterObject *it=NULL;\n\tPyArrayIterObject *rit=NULL;\n\tPyObject *ret;\n\tint needcopy=0, i;\n\tintp N, size;\n\tint elsize;\n\tintp astride, rstride, *iptr;\n\tPyArray_ArgSortFunc *argsort;\n\tBEGIN_THREADS_DEF \n\n\tret = PyArray_New(op->ob_type, op->nd,\n\t\t\t op->dimensions, PyArray_INTP,\n\t\t\t NULL, NULL, 0, 0, (PyObject *)op);\n\tif (ret == NULL) return NULL;\n\n\tit = (PyArrayIterObject *)PyArray_IterAllButAxis((PyObject *)op, axis);\n\trit = (PyArrayIterObject *)PyArray_IterAllButAxis(ret, axis);\n\tif (rit == NULL || it == NULL) goto fail;\n\n\tBEGIN_THREADS\n\n\targsort = op->descr->f->argsort[which];\n\tsize = it->size;\n\tN = op->dimensions[axis];\n\telsize = op->descr->elsize;\n\tastride = op->strides[axis];\n\trstride = PyArray_STRIDE(ret,axis);\n\n\tneedcopy = !(op->flags & ALIGNED) || (astride != (intp) elsize) || \\\n\t\t(rstride != sizeof(intp));\n\t\n\tif (needcopy) {\n\t\tchar *valbuffer, *indbuffer;\n\t\tvalbuffer = PyDataMem_NEW(N*(elsize+sizeof(intp)));\n\t\tindbuffer = valbuffer + (N*elsize);\n\t\twhile (size--) {\n\t\t\t_strided_copy(valbuffer, (intp) elsize, it->dataptr,\n\t\t\t\t astride, N, elsize);\n\t\t\tiptr = (intp *)indbuffer;\n\t\t\tfor (i=0; idataptr, rstride, indbuffer, \n\t\t\t\t sizeof(intp), N, sizeof(intp));\n\t\t\tPyArray_ITER_NEXT(it);\n\t\t\tPyArray_ITER_NEXT(rit);\n\t\t}\n\t\tPyDataMem_FREE(valbuffer);\n\t}\n\telse {\n\t\twhile (size--) {\n\t\t\tiptr = (intp *)rit->dataptr;\n\t\t\tfor (i=0; idataptr, (intp *)rit->dataptr, \n\t\t\t\t N, op) < 0) goto fail;\n\t\t\tPyArray_ITER_NEXT(it);\n\t\t\tPyArray_ITER_NEXT(rit);\n\t\t}\n\t}\n\t\n\tEND_THREADS\n\n\tPy_DECREF(it);\n\tPy_DECREF(rit);\n\treturn ret;\n\n fail:\n\n\tEND_THREADS\n\n\tPy_DECREF(ret);\n\tPy_XDECREF(it);\n\tPy_XDECREF(rit);\n\treturn NULL;\n}\n\n\n/* Be sure to save this global_compare when necessary */\n\nstatic PyArrayObject *global_obj;\n\nstatic int \nqsortCompare (const void *a, const void *b) \n{\n\treturn global_obj->descr->f->compare(a,b,global_obj);\n}\n\n/* Consumes reference to ap (op gets it)\n op contains a version of the array with axes swapped if\n local variable axis is not the last dimension.\n orign must be defined locally. \n*/\n\n#define SWAPAXES(op, ap) {\t\t\t\t\t\t\\\n\t\torign = (ap)->nd-1;\t\t\t\t\t\\\n\t\tif (axis != orign) {\t\t\t\t\t\\\n\t\t\t(op) = (PyAO *)PyArray_SwapAxes((ap), axis, orign); \\\n\t\t\tPy_DECREF((ap));\t\t\t\t\\\n\t\t\tif ((op) == NULL) return NULL;\t\t\t\\\n\t\t}\t\t\t\t\t\t\t\\\n\t\telse (op) = (ap);\t\t\t\t\t\\\n\t}\n\n/* Consumes reference to ap (op gets it)\n origin must be previously defined locally. \n SWAPAXES must have been called previously. \n op contains the swapped version of the array. \n*/\n#define SWAPBACK(op, ap) {\t \\\n\t\tif (axis != orign) { \\\n\t\t\t(op) = (PyAO *)PyArray_SwapAxes((ap), axis, orign); \\\n\t\t\tPy_DECREF((ap));\t\t\t\t\\\n\t\t\tif ((op) == NULL) return NULL;\t\t\t\\\n\t\t}\t\t\t\t\t\t\t\\\n\t\telse (op) = (ap);\t\t\t\t\t\\\n\t}\n\n/* These swap axes in-place if necessary */\n#define SWAPINTP(a,b) {intp c; c=(a); (a) = (b); (b) = c;}\n#define SWAPAXES2(ap) {\t\t\t\t\t\t\\\n\t\torign = (ap)->nd-1;\t\t\t\t\t\\\n\t\tif (axis != orign) {\t\t\t\t\t\\\n\t\t\tSWAPINTP(ap->dimensions[axis], ap->dimensions[orign]); \\\n\t\t\tSWAPINTP(ap->strides[axis], ap->strides[orign]); \\\n\t\t\tPyArray_UpdateFlags(ap, CONTIGUOUS | FORTRAN); \\\n\t\t}\t\t\t\t\t\t \\\n\t}\n\n#define SWAPBACK2(ap) {\t\t \\\n\t\tif (axis != orign) {\t\t\t\t\t\\\n\t\t\tSWAPINTP(ap->dimensions[axis], ap->dimensions[orign]); \\\n\t\t\tSWAPINTP(ap->strides[axis], ap->strides[orign]); \\\n\t\t\tPyArray_UpdateFlags(ap, CONTIGUOUS | FORTRAN);\t\\\n\t\t}\t\t\t\t\t\t\t\\\n\t}\n\n/*MULTIARRAY_API\n Sort an array in-place\n*/\nstatic int\nPyArray_Sort(PyArrayObject *op, int axis, PyArray_SORTKIND which) \n{\n\tPyArrayObject *ap=NULL, *store_arr=NULL;\n\tchar *ip;\n\tint i, n, m, elsize, orign;\n\n\tn = op->nd;\n\tif ((n==0) || (PyArray_SIZE(op)==1)) return 0;\n\n\tif (axis < 0) axis += n;\n\tif ((axis < 0) || (axis >= n)) {\n\t\tPyErr_Format(PyExc_ValueError, \n\t\t\t \"axis(=%d) out of bounds\", axis);\n\t\treturn -1;\n\t}\n\tif (!PyArray_ISWRITEABLE(op)) {\n\t\tPyErr_SetString(PyExc_RuntimeError, \n\t\t\t\t\"attempted sort on unwriteable array.\");\n\t\treturn -1;\n\t}\n\n\t/* Determine if we should use type-specific algorithm or not */\n\tif (op->descr->f->sort[which] != NULL) {\n\t\treturn _new_sort(op, axis, which);\n\t}\n\n\tif ((which != PyArray_QUICKSORT) || \\\n\t op->descr->f->compare == NULL) {\n\t\tPyErr_SetString(PyExc_TypeError, \n\t\t\t\t\"desired sort not supported for this type\");\n\t\treturn -1;\n\t}\n\n\tSWAPAXES2(op);\n\n ap = (PyArrayObject *)PyArray_FromAny((PyObject *)op, \n\t\t\t\t\t NULL, 1, 0, \n\t\t\t\t\t DEFAULT_FLAGS | UPDATEIFCOPY, NULL);\t\n\tif (ap == NULL) goto fail;\n\t\n\telsize = ap->descr->elsize;\n\tm = ap->dimensions[ap->nd-1];\n\tif (m == 0) goto finish;\n\n\tn = PyArray_SIZE(ap)/m;\n\n\t/* Store global -- allows re-entry -- restore before leaving*/\n\tstore_arr = global_obj; \n\tglobal_obj = ap;\n\t\n\tfor (ip=ap->data, i=0; idescr->elsize;\n\tconst intp *ipa = ip1;\n\tconst intp *ipb = ip2;\t\n\treturn global_obj->descr->f->compare(global_data + (isize * *ipa),\n global_data + (isize * *ipb), \n\t\t\t\t\t global_obj);\n}\n\n/*MULTIARRAY_API\n ArgSort an array\n*/\nstatic PyObject *\nPyArray_ArgSort(PyArrayObject *op, int axis, PyArray_SORTKIND which) \n{\n\tPyArrayObject *ap=NULL, *ret=NULL, *store;\n\tintp *ip;\n\tintp i, j, n, m, orign;\n\tint argsort_elsize;\n\tchar *store_ptr;\n\n\tn = op->nd;\n\tif ((n==0) || (PyArray_SIZE(op)==1)) {\n\t\tret = (PyArrayObject *)PyArray_New(op->ob_type, op->nd,\n\t\t\t\t\t\t op->dimensions, \n\t\t\t\t\t\t PyArray_INTP,\n\t\t\t\t\t\t NULL, NULL, 0, 0, \n\t\t\t\t\t\t (PyObject *)op);\n\t\tif (ret == NULL) return NULL;\n\t\t*((intp *)ret->data) = 0;\n\t\treturn (PyObject *)ret;\n\t}\n\tif (axis < 0) axis += n;\n\tif ((axis < 0) || (axis >= n)) {\n\t\tPyErr_Format(PyExc_ValueError, \n\t\t\t \"axis(=%d) out of bounds\", axis);\n\t\treturn NULL;\n\t}\n\n\t/* Determine if we should use new algorithm or not */\n\tif (op->descr->f->argsort[which] != NULL) {\n\t\treturn _new_argsort(op, axis, which);\n\t}\n\n\tif ((which != PyArray_QUICKSORT) || op->descr->f->compare == NULL) {\n\t\tPyErr_SetString(PyExc_TypeError, \n\t\t\t\t\"requested sort not available for type\");\n\t\tgoto fail;\n\t}\n\n\tSWAPAXES(ap, op);\n\n\top = (PyArrayObject *)PyArray_ContiguousFromAny((PyObject *)ap, \n\t\t\t\t\t\t\t PyArray_NOTYPE,\n\t\t\t\t\t\t\t 1, 0);\n\n\tif (op == NULL) return NULL;\n\t\n\tret = (PyArrayObject *)PyArray_New(op->ob_type, op->nd,\n\t\t\t\t\t op->dimensions, PyArray_INTP,\n\t\t\t\t\t NULL, NULL, 0, 0, (PyObject *)op);\n\tif (ret == NULL) goto fail;\n\t\n\t\n\tip = (intp *)ret->data;\n\targsort_elsize = op->descr->elsize;\n\tm = op->dimensions[op->nd-1];\n\tif (m == 0) goto finish;\n\n\tn = PyArray_SIZE(op)/m;\n\tstore_ptr = global_data;\n\tglobal_data = op->data;\n\tstore = global_obj;\n\tglobal_obj = op;\n\tfor (i=0; i 0 in lexsort\");\n\t\treturn NULL;\n\t}\n\tmps = (PyArrayObject **) _pya_malloc(n*sizeof(PyArrayObject));\n\tif (mps==NULL) return PyErr_NoMemory();\n\tits = (PyArrayIterObject **) _pya_malloc(n*sizeof(PyArrayIterObject));\n\tif (its == NULL) {_pya_free(mps); return PyErr_NoMemory();}\n\tfor (i=0; i0) {\n\t\t\tif ((mps[i]->nd != mps[0]->nd) ||\t\\\n\t\t\t (!PyArray_CompareLists(mps[i]->dimensions,\n\t\t\t\t\t\t mps[0]->dimensions,\n\t\t\t\t\t\t mps[0]->nd))) {\n\t\t\t\tPyErr_SetString(PyExc_ValueError,\n\t\t\t\t\t\t\"all keys need to be the same shape\");\n\t\t\t\tgoto fail;\n\t\t\t}\n\t\t}\n\t\tif (!mps[i]->descr->f->argsort[PyArray_MERGESORT]) {\n\t\t\tPyErr_Format(PyExc_TypeError, \n\t\t\t\t \"merge sort not available for item %d\", i);\n\t\t\tgoto fail;\n\t\t}\n\t\tits[i] = (PyArrayIterObject *)PyArray_IterAllButAxis\t\\\n\t\t\t((PyObject *)mps[i], axis);\n\t\tif (its[i]==NULL) goto fail;\n\t}\n\n\t/* Now we can check the axis */\n\tnd = mps[0]->nd;\n\tif ((nd==0) || (PyArray_SIZE(mps[0])==1)) {\n\t\tret = (PyArrayObject *)PyArray_New(&PyArray_Type, mps[0]->nd,\n\t\t\t\t\t\t mps[0]->dimensions, \n\t\t\t\t\t\t PyArray_INTP,\n\t\t\t\t\t\t NULL, NULL, 0, 0, NULL);\n\t\tif (ret == NULL) return NULL;\n\t\t*((intp *)(ret->data)) = 0;\n\t\treturn (PyObject *)ret;\n\t}\n\tif (axis < 0) axis += nd;\n\tif ((axis < 0) || (axis >= nd)) {\n\t\tPyErr_Format(PyExc_ValueError, \n\t\t\t \"axis(=%d) out of bounds\", axis);\n\t\tgoto fail;\n\t}\n\n\t/* Now do the sorting */\n\n\tret = (PyArrayObject *)PyArray_New(&PyArray_Type, mps[0]->nd,\n\t\t\t\t\t mps[0]->dimensions, PyArray_INTP,\n\t\t\t\t\t NULL, NULL, 0, 0, NULL);\n\tif (ret == NULL) goto fail;\n\n\trit = (PyArrayIterObject *)\\\n\t\tPyArray_IterAllButAxis((PyObject *)ret, axis);\n\tif (rit == NULL) goto fail;\n\n\tsize = rit->size;\n\tN = mps[0]->dimensions[axis];\n\trstride = PyArray_STRIDE(ret,axis);\n\n maxelsize = mps[0]->descr->elsize;\n\tneedcopy = (rstride != sizeof(intp));\n\tfor (j=0; jflags & ALIGNED) || \\\n\t\t\t(mps[j]->strides[axis] != (intp)mps[j]->descr->elsize);\n if (mps[j]->descr->elsize > maxelsize) \n maxelsize = mps[j]->descr->elsize;\n\t}\n\n\tif (needcopy) {\n\t\tchar *valbuffer, *indbuffer;\n\t\tvalbuffer = PyDataMem_NEW(N*(maxelsize+sizeof(intp)));\n\t\tindbuffer = valbuffer + (N*maxelsize);\n\t\twhile (size--) {\n\t\t\tiptr = (intp *)indbuffer;\n\t\t\tfor (i=0; idescr->elsize;\n\t\t\t\tastride = mps[j]->strides[axis];\t\n\t\t\t\targsort = mps[j]->descr->f->argsort[PyArray_MERGESORT];\n\t\t\t\t_strided_copy(valbuffer, (intp) elsize, its[j]->dataptr,\n\t\t\t\t\t astride, N, elsize);\n\t\t\t\tif (argsort(valbuffer, (intp *)indbuffer, N, mps[j]) < 0) {\n\t\t\t\t\tPyDataMem_FREE(valbuffer); goto fail;\n\t\t\t\t}\n\t\t\t\tPyArray_ITER_NEXT(its[j]);\n\t\t\t}\n\t\t\t_strided_copy(rit->dataptr, rstride, indbuffer,\n\t\t\t\t sizeof(intp), N, sizeof(intp));\n\t\t\tPyArray_ITER_NEXT(rit);\n\t\t}\n\t\tPyDataMem_FREE(valbuffer);\n\t}\n\telse {\n\t\twhile (size--) {\n\t\t\tiptr = (intp *)rit->dataptr;\n\t\t\tfor (i=0; idescr->f->argsort[PyArray_MERGESORT];\n\t\t\t\tif (argsort(its[j]->dataptr, (intp *)rit->dataptr,\n\t\t\t\t\t N, mps[j]) < 0) goto fail;\n\t\t\t\tPyArray_ITER_NEXT(its[j]);\n\t\t\t}\n\t\t\tPyArray_ITER_NEXT(rit);\n\t\t}\n\t}\n\n\tfor (i=0; idescr->f->compare;\n\tintp min_i, max_i, i, j;\n\tint location, elsize = ap1->descr->elsize;\n\tintp elements = ap1->dimensions[ap1->nd-1];\n\tintp n = PyArray_SIZE(ap2);\n\tintp *rp = (intp *)ret->data;\n\tchar *ip = ap2->data;\n\tchar *vp = ap1->data;\n\n\tfor (j=0; j 0) {\n\t\t\t\t\tif (compare(ip, vp+elsize*(--i), ap2) \\\n\t\t\t\t\t != 0) {\n\t\t\t\t\t\ti = i+1; break;\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t\tmin_i = i;\n\t\t\t\tbreak;\n\t\t\t}\n\t\t\telse if (location < 0) {\n\t\t\t\tmax_i = i;\n\t\t\t} else {\n\t\t\t\tmin_i = i+1;\n\t\t\t}\n\t\t}\n\t\t*rp = min_i;\n\t}\n}\n\n/*MULTIARRAY_API\n Numeric.searchsorted(a,v)\n*/\nstatic PyObject *\nPyArray_SearchSorted(PyArrayObject *op1, PyObject *op2) \n{\n\tPyArrayObject *ap1=NULL, *ap2=NULL, *ret=NULL;\n\tint typenum = 0;\n\n\t/* \n PyObject *args;\n args = Py_BuildValue(\"O\",op2);\n\tPy_DELEGATE_ARGS(((PyObject *)op1), searchsorted, args);\n Py_XDECREF(args);\n\t*/\n\n\ttypenum = PyArray_ObjectType((PyObject *)op1, 0);\n\ttypenum = PyArray_ObjectType(op2, typenum);\n\tret = NULL;\n\tap1 = (PyArrayObject *)PyArray_ContiguousFromAny((PyObject *)op1, \n\t\t\t\t\t\t\t typenum, \n\t\t\t\t\t\t\t 1, 1);\n\tif (ap1 == NULL) return NULL;\n\tap2 = (PyArrayObject *)PyArray_ContiguousFromAny(op2, typenum, \n\t\t\t\t\t\t\t 0, 0);\n\tif (ap2 == NULL) goto fail;\n\t\n\tret = (PyArrayObject *)PyArray_New(ap2->ob_type, ap2->nd, \n\t\t\t\t\t ap2->dimensions, PyArray_INTP,\n\t\t\t\t\t NULL, NULL, 0, 0, (PyObject *)ap2);\n\tif (ret == NULL) goto fail;\n\n\tif (ap2->descr->f->compare == NULL) {\n\t\tPyErr_SetString(PyExc_TypeError, \n\t\t\t\t\"compare not supported for type\");\n\t\tgoto fail;\n\t}\n\t\n\tlocal_where(ap1, ap2, ret); \n\t\n\tPy_DECREF(ap1);\n\tPy_DECREF(ap2);\n\treturn (PyObject *)ret;\n\t\n fail:\n\tPy_XDECREF(ap1);\n\tPy_XDECREF(ap2);\n\tPy_XDECREF(ret);\n\treturn NULL;\n}\n\n/*\n Make a new empty array, of the passed size, of a type that takes the\n priority of ap1 and ap2 into account.\n */\nstatic PyArrayObject *\nnew_array_for_sum(PyArrayObject *ap1, PyArrayObject *ap2,\n\t\t int nd, intp dimensions[], int typenum)\n{\n\tPyArrayObject *ret;\n\tPyTypeObject *subtype;\n\tdouble prior1, prior2;\n\t/* Need to choose an output array that can hold a sum \n\t -- use priority to determine which subtype.\n\t */\n\tif (ap2->ob_type != ap1->ob_type) {\n\t\tprior2 = PyArray_GetPriority((PyObject *)ap2, 0.0);\n\t\tprior1 = PyArray_GetPriority((PyObject *)ap1, 0.0);\n\n\t\tsubtype = (prior2 > prior1 ? ap2->ob_type : ap1->ob_type);\n\t} else {\n\t\tprior1 = prior2 = 0.0;\n\t\tsubtype = ap1->ob_type;\n\t}\n\n\tret = (PyArrayObject *)PyArray_New(subtype, nd, dimensions, \n\t\t\t\t\t typenum, NULL, NULL, 0, 0, \n (PyObject *)\n\t\t\t\t\t (prior2 > prior1 ? ap2 : ap1));\n\treturn ret;\n}\n\n/* Could perhaps be redone to not make contiguous arrays \n */\n\n/*MULTIARRAY_API\n Numeric.innerproduct(a,v)\n*/\nstatic PyObject *\nPyArray_InnerProduct(PyObject *op1, PyObject *op2) \n{\n\tPyArrayObject *ap1, *ap2, *ret=NULL;\n\tintp i, j, l, i1, i2, n1, n2;\n\tint typenum, nd;\n\tintp is1, is2, os;\n\tchar *ip1, *ip2, *op;\n\tintp dimensions[MAX_DIMS];\n\tPyArray_DotFunc *dot;\n\t\n\ttypenum = PyArray_ObjectType(op1, 0); \n\ttypenum = PyArray_ObjectType(op2, typenum);\n\t\t\n\tap1 = (PyArrayObject *)PyArray_ContiguousFromAny(op1, typenum, \n\t\t\t\t\t\t\t 0, 0);\n\tif (ap1 == NULL) return NULL;\n\tap2 = (PyArrayObject *)PyArray_ContiguousFromAny(op2, typenum, \n\t\t\t\t\t\t\t 0, 0);\n\tif (ap2 == NULL) goto fail;\n\t\n\tif (ap1->nd == 0 || ap2->nd == 0) {\n\t\tret = (ap1->nd == 0 ? ap1 : ap2);\n\t\tret = (PyArrayObject *)ret->ob_type->tp_as_number->\\\n\t\t\tnb_multiply((PyObject *)ap1, (PyObject *)ap2);\n\t\tPy_DECREF(ap1);\n\t\tPy_DECREF(ap2);\n\t\treturn (PyObject *)ret;\n\t}\n\t\n\tl = ap1->dimensions[ap1->nd-1];\n\t\n\tif (ap2->dimensions[ap2->nd-1] != l) {\n\t\tPyErr_SetString(PyExc_ValueError, \"matrices are not aligned\");\n\t\tgoto fail;\n\t}\n\t\n\tif (l == 0) n1 = n2 = 0;\n\telse {\n\t\tn1 = PyArray_SIZE(ap1)/l;\n\t\tn2 = PyArray_SIZE(ap2)/l;\n\t}\n\n\tnd = ap1->nd+ap2->nd-2;\n\tj = 0;\n\tfor(i=0; ind-1; i++) {\n\t\tdimensions[j++] = ap1->dimensions[i];\n\t}\n\tfor(i=0; ind-1; i++) {\n\t\tdimensions[j++] = ap2->dimensions[i];\n\t}\n\n\n\t/* Need to choose an output array that can hold a sum \n\t -- use priority to determine which subtype.\n\t */\n\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\n\t\n\tis1 = ap1->strides[ap1->nd-1]; \n\tis2 = ap2->strides[ap2->nd-1];\n\top = ret->data; os = ret->descr->elsize;\n\t\n\tip1 = ap1->data;\n\tfor(i1=0; i1data;\n\t\tfor(i2=0; i2nd == 0 || ap2->nd == 0) {\n\t\tret = (ap1->nd == 0 ? ap1 : ap2);\n\t\tret = (PyArrayObject *)ret->ob_type->tp_as_number->\\\n\t\t\tnb_multiply((PyObject *)ap1, (PyObject *)ap2);\n\t\tPy_DECREF(ap1);\n\t\tPy_DECREF(ap2);\n\t\treturn (PyObject *)ret;\n\t}\n\t\n\tl = ap1->dimensions[ap1->nd-1];\n\tif (ap2->nd > 1) {\n\t\tmatchDim = ap2->nd - 2;\n\t\totherDim = ap2->nd - 1;\n\t}\n\telse {\n\t\tmatchDim = 0;\n\t\totherDim = 0;\n\t}\n\n\tif (ap2->dimensions[matchDim] != l) {\n\t\tPyErr_SetString(PyExc_ValueError, \"objects are not aligned\");\n\t\tgoto fail;\n\t}\n\t\n\tif (l == 0) n1 = n2 = 0;\n\telse {\n\t\tn1 = PyArray_SIZE(ap1)/l;\n\t\tn2 = PyArray_SIZE(ap2)/l;\n\t}\n\n\tnd = ap1->nd+ap2->nd-2;\n\tj = 0;\n\tfor(i=0; ind-1; i++) {\n\t\tdimensions[j++] = ap1->dimensions[i];\n\t}\n\tfor(i=0; ind-2; i++) {\n\t\tdimensions[j++] = ap2->dimensions[i];\n\t}\n\tif(ap2->nd > 1) {\n\t\tdimensions[j++] = ap2->dimensions[ap2->nd-1];\n\t}\n\t/*\n\tfprintf(stderr, \"nd=%d dimensions=\", nd);\n\t for(i=0; i 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\tis1 = ap1->strides[ap1->nd-1]; is2 = ap2->strides[matchDim];\n\tif(ap1->nd > 1)\n\t\tis1r = ap1->strides[ap1->nd-2];\n\telse\n\t\tis1r = ap1->strides[ap1->nd-1];\n\tis2r = ap2->strides[otherDim];\n\n\top = ret->data; os = ret->descr->elsize;\n\n\tip1 = ap1->data;\n\tfor(i1=0; i1data;\n\t\tfor(i2=0; i2ob_type, \n\t\t\t\t PyArray_DESCR(arr),\n\t\t\t\t 2, dims, \n\t\t\t\t NULL, NULL, 0, arr);\n\n\tif (ret == NULL) {\n\t\tPy_DECREF(arr);\n\t\treturn NULL;\n\t}\n\t/* do 2-d loop */\n\toptr = PyArray_DATA(ret);\n\tstr2 = elsize*dims[0];\n\tfor (i=0; idimensions[0];\n\tn2 = ap2->dimensions[0];\n\n\tif (n1 < n2) { \n\t\tret = ap1; ap1 = ap2; ap2 = ret; \n\t\tret = NULL; i = n1;n1=n2;n2=i;\n\t}\n\tlength = n1;\n\tn = n2;\n\tswitch(mode) {\n\tcase 0:\t\n\t\tlength = length-n+1;\n\t\tn_left = n_right = 0;\n\t\tbreak;\n\tcase 1:\n\t\tn_left = (intp)(n/2);\n\t\tn_right = n-n_left-1;\n\t\tbreak;\n\tcase 2:\n\t\tn_right = n-1;\n\t\tn_left = n-1;\n\t\tlength = length+n-1;\n\t\tbreak;\n\tdefault:\n\t\tPyErr_SetString(PyExc_ValueError, \n\t\t\t\t\"mode must be 0, 1, or 2\");\n\t\tgoto fail;\n\t}\n\n\t/* Need to choose an output array that can hold a sum \n\t -- use priority to determine which subtype.\n\t */\n\tret = new_array_for_sum(ap1, ap2, 1, &length, typenum);\n\tif (ret == NULL) goto fail;\n\t\n\tdot = ret->descr->f->dotfunc;\n\tif (dot == NULL) {\n\t\tPyErr_SetString(PyExc_ValueError, \n\t\t\t\t\"function not available for this data type\");\n\t\tgoto fail;\n\t}\n\t\n\tis1 = ap1->strides[0]; is2 = ap2->strides[0];\n\top = ret->data; os = ret->descr->elsize;\n\t\n\tip1 = ap1->data; ip2 = ap2->data+n_left*is2;\n\tn = n-n_left;\n\tfor(i=0; idescr->type_num);\n\tPy_DECREF(arr);\n\treturn ret;\t \n}\n\n/*MULTIARRAY_API\n Min\n*/\nstatic PyObject *\nPyArray_Min(PyArrayObject *ap, int axis)\n{\n\tPyArrayObject *arr;\n\tPyObject *ret;\n\n\tif ((arr=(PyArrayObject *)_check_axis(ap, &axis, 0))==NULL)\n\t\treturn NULL;\n\tret = PyArray_GenericReduceFunction(arr, n_ops.minimum, axis,\n\t\t\t\t\t arr->descr->type_num);\n\tPy_DECREF(arr);\n\treturn ret;\t \n}\n\n/*MULTIARRAY_API\n Ptp\n*/\nstatic PyObject *\nPyArray_Ptp(PyArrayObject *ap, int axis)\n{\n\tPyArrayObject *arr;\n\tPyObject *ret;\n\tPyObject *obj1=NULL, *obj2=NULL;\n\n\tif ((arr=(PyArrayObject *)_check_axis(ap, &axis, 0))==NULL)\n\t\treturn NULL;\n\tobj1 = PyArray_Max(arr, axis);\n\tif (obj1 == NULL) goto fail;\n\tobj2 = PyArray_Min(arr, axis);\n\tif (obj2 == NULL) goto fail;\n\tPy_DECREF(arr);\n\tret = PyNumber_Subtract(obj1, obj2);\n\tPy_DECREF(obj1);\n\tPy_DECREF(obj2);\n\treturn ret;\n\n fail:\n\tPy_XDECREF(arr);\n\tPy_XDECREF(obj1);\n\tPy_XDECREF(obj2);\n\treturn NULL;\n}\n\n\n/*MULTIARRAY_API\n ArgMax\n*/\nstatic PyObject *\nPyArray_ArgMax(PyArrayObject *op, int axis) \n{\n\tPyArrayObject *ap=NULL, *rp=NULL;\n\tPyArray_ArgFunc* arg_func;\n\tchar *ip;\n\tintp *rptr;\n\tintp i, n, orign, m;\n\tint elsize;\n\t\n\tif ((ap=(PyAO *)_check_axis(op, &axis, 0))==NULL) return NULL;\n\n\tSWAPAXES(op, ap);\n\n\tap = (PyArrayObject *)\\\n\t\tPyArray_ContiguousFromAny((PyObject *)op, \n\t\t\t\t\t PyArray_NOTYPE, 1, 0);\n\n\tPy_DECREF(op);\n\tif (ap == NULL) return NULL;\n\t\n\targ_func = ap->descr->f->argmax;\n\tif (arg_func == NULL) {\n\t\tPyErr_SetString(PyExc_TypeError, \"data type not ordered\");\n\t\tgoto fail;\n\t}\n\n\trp = (PyArrayObject *)PyArray_New(ap->ob_type, ap->nd-1,\n\t\t\t\t\t ap->dimensions, PyArray_INTP,\n\t\t\t\t\t NULL, NULL, 0, 0, \n (PyObject *)ap);\n\tif (rp == NULL) goto fail;\n\n\n\telsize = ap->descr->elsize;\n\tm = ap->dimensions[ap->nd-1];\n\tif (m == 0) {\n\t\tPyErr_SetString(MultiArrayError, \n\t\t\t\t\"attempt to get argmax/argmin \"\\\n\t\t\t\t\"of an empty sequence??\");\n\t\tgoto fail;\n\t}\n\tn = PyArray_SIZE(ap)/m;\n\trptr = (intp *)rp->data;\n\tfor (ip = ap->data, i=0; ind + indices->nd - 1;\n for (i=0; i< nd; i++) {\n if (i < axis) {\n shape[i] = self->dimensions[i];\n n *= shape[i];\n } else {\n if (i < axis+indices->nd) {\n shape[i] = indices->dimensions[i-axis];\n m *= shape[i];\n } else {\n shape[i] = self->dimensions[i-indices->nd+1];\n chunk *= shape[i];\n }\n }\n }\n\tPy_INCREF(self->descr);\n ret = (PyArrayObject *)PyArray_NewFromDescr(self->ob_type, \n\t\t\t\t\t\t self->descr,\n\t\t\t\t\t\t nd, shape, \n\t\t\t\t\t\t NULL, NULL, 0, \n\t\t\t\t\t\t (PyObject *)self);\n\t\n if (ret == NULL) goto fail;\n\t\n max_item = self->dimensions[axis];\n chunk = chunk * ret->descr->elsize;\n src = self->data;\n dest = ret->data;\n\t\n for(i=0; idata))[j];\n if (tmp < 0) tmp = tmp+max_item;\n if ((tmp < 0) || (tmp >= max_item)) {\n PyErr_SetString(PyExc_IndexError, \n\t\t\t\t\t\t\"index out of range for \"\\\n\t\t\t\t\t\t\"array\");\n goto fail;\n }\n memmove(dest, src+tmp*chunk, chunk);\n dest += chunk;\n }\n src += chunk*max_item;\n }\n\t\n PyArray_INCREF(ret);\n\n Py_XDECREF(indices);\n Py_XDECREF(self);\n\n return (PyObject *)ret;\n\t\n\t\n fail:\n Py_XDECREF(ret);\n Py_XDECREF(indices);\n Py_XDECREF(self);\n return NULL;\n}\n\n/*MULTIARRAY_API\n Put values into an array\n*/\nstatic PyObject *\nPyArray_Put(PyArrayObject *self, PyObject* values0, PyObject *indices0) \n{\n PyArrayObject *indices, *values;\n int i, chunk, ni, max_item, nv, tmp, thistype; \n char *src, *dest;\n\n indices = NULL;\n values = NULL;\n\n if (!PyArray_Check(self)) {\n PyErr_SetString(PyExc_TypeError, \"put: first argument must be an array\");\n return NULL;\n }\n if (!PyArray_ISCONTIGUOUS(self)) {\n PyErr_SetString(PyExc_ValueError, \"put: first argument must be contiguous\");\n return NULL;\n }\n max_item = PyArray_SIZE(self);\n dest = self->data;\n chunk = self->descr->elsize;\n\n indices = (PyArrayObject *)PyArray_ContiguousFromAny(indices0, PyArray_INTP, 0, 0);\n if (indices == NULL) goto fail;\n ni = PyArray_SIZE(indices);\n\n\tthistype = self->descr->type_num;\n values = (PyArrayObject *)\\\n\t\tPyArray_ContiguousFromAny(values0, thistype, 0, 0);\n if (values == NULL) goto fail;\n nv = PyArray_SIZE(values);\n if (nv > 0) { /* nv == 0 for a null array */\n if (thistype == PyArray_OBJECT) { \n for(i=0; idata + chunk * (i % nv);\n tmp = ((intp *)(indices->data))[i];\n if (tmp < 0) tmp = tmp+max_item;\n if ((tmp < 0) || (tmp >= max_item)) {\n PyErr_SetString(PyExc_IndexError, \"index out of range for array\");\n goto fail;\n }\n Py_INCREF(*((PyObject **)src));\n Py_XDECREF(*((PyObject **)(dest+tmp*chunk)));\n memmove(dest + tmp * chunk, src, chunk);\n }\n }\n else {\n for(i=0; idata + chunk * (i % nv);\n tmp = ((intp *)(indices->data))[i];\n if (tmp < 0) tmp = tmp+max_item;\n if ((tmp < 0) || (tmp >= max_item)) {\n PyErr_SetString(PyExc_IndexError, \"index out of range for array\");\n goto fail;\n }\n memmove(dest + tmp * chunk, src, chunk);\n }\n }\n\n }\n\n Py_XDECREF(values);\n Py_XDECREF(indices);\n Py_INCREF(Py_None);\n return Py_None;\n\t\n fail:\n Py_XDECREF(indices);\n Py_XDECREF(values);\n return NULL;\n}\n\n/*MULTIARRAY_API\n Put values into an array according to a mask.\n*/\nstatic PyObject *\nPyArray_PutMask(PyArrayObject *self, PyObject* values0, PyObject* mask0) \n{\n PyArrayObject *mask, *values;\n int i, chunk, ni, max_item, nv, tmp, thistype;\n char *src, *dest;\n\n mask = NULL;\n values = NULL;\n\n if (!PyArray_Check(self)) {\n PyErr_SetString(PyExc_TypeError, \n\t\t\t\t\"putmask: first argument must \"\\\n\t\t\t\t\"be an array\");\n return NULL;\n }\n if (!PyArray_ISCONTIGUOUS(self)) {\n PyErr_SetString(PyExc_ValueError, \n\t\t\t\t\"putmask: first argument must be contiguous\");\n return NULL;\n }\n\n max_item = PyArray_SIZE(self);\n dest = self->data;\n chunk = self->descr->elsize;\n\n mask = (PyArrayObject *)\\\n\t\tPyArray_FROM_OTF(mask0, PyArray_BOOL, CARRAY_FLAGS | FORCECAST);\n\tif (mask == NULL) goto fail;\n ni = PyArray_SIZE(mask);\n if (ni != max_item) {\n PyErr_SetString(PyExc_ValueError, \n\t\t\t\t\"putmask: mask and data must be \"\\\n\t\t\t\t\"the same size\");\n goto fail;\n }\n\n\tthistype = self->descr->type_num;\n values = (PyArrayObject *)\\\n\t\tPyArray_ContiguousFromAny(values0, thistype, 0, 0);\n\tif (values == NULL) goto fail;\n nv = PyArray_SIZE(values);\t /* zero if null array */\n if (nv > 0) {\n if (thistype == PyArray_OBJECT) {\n for(i=0; idata + chunk * (i % nv);\n tmp = ((Bool *)(mask->data))[i];\n if (tmp) {\n\t\t\t\t\tPy_INCREF(*((PyObject **)src));\n Py_XDECREF(*((PyObject **)(dest+i*chunk)));\n memmove(dest + i * chunk, src, chunk);\n }\n\t\t\t}\n }\n else {\n for(i=0; idata + chunk * (i % nv);\n tmp = ((Bool *)(mask->data))[i];\n if (tmp) memmove(dest + i * chunk, src, chunk);\n\t\t\t}\n\t\t}\n }\n\n Py_XDECREF(values);\n Py_XDECREF(mask);\n Py_INCREF(Py_None);\n return Py_None;\n\t\n fail:\n Py_XDECREF(mask);\n Py_XDECREF(values);\n return NULL;\n}\n\n\n/* This conversion function can be used with the \"O&\" argument for\n PyArg_ParseTuple. It will immediately return an object of array type\n or will convert to a CARRAY any other object. \n\n If you use PyArray_Converter, you must DECREF the array when finished\n as you get a new reference to it.\n*/\n \n/*MULTIARRAY_API\n Useful to pass as converter function for O& processing in\n PyArgs_ParseTuple.\n*/\nstatic int \nPyArray_Converter(PyObject *object, PyObject **address) \n{\n if (PyArray_Check(object)) {\n *address = object;\n\t\tPy_INCREF(object);\n return PY_SUCCEED;\n }\n else {\n\t\t*address = PyArray_FromAny(object, NULL, 0, 0, CARRAY_FLAGS, NULL);\n\t\tif (*address == NULL) return PY_FAIL;\n\t\treturn PY_SUCCEED;\n }\n}\n\n/*MULTIARRAY_API\n Convert an object to true / false\n*/\nstatic int\nPyArray_BoolConverter(PyObject *object, Bool *val)\n{ \n if (PyObject_IsTrue(object))\n *val=TRUE;\n else *val=FALSE;\n if (PyErr_Occurred())\n return PY_FAIL;\n return PY_SUCCEED;\n}\n\n\n/*MULTIARRAY_API\n Typestr converter\n*/\nstatic int\nPyArray_TypestrConvert(int itemsize, int gentype)\n{\n\tregister int newtype = gentype;\n\t\n\tif (gentype == PyArray_GENBOOLLTR) {\n\t\tif (itemsize == 1)\n\t\t\tnewtype = PyArray_BOOL;\n\t\telse \n\t\t\tnewtype = PyArray_NOTYPE;\n\t}\n\telse if (gentype == PyArray_SIGNEDLTR) {\n\t\tswitch(itemsize) {\n\t\tcase 1:\n\t\t\tnewtype = PyArray_INT8;\n\t\t\tbreak;\n\t\tcase 2:\n\t\t\tnewtype = PyArray_INT16;\n\t\t\tbreak;\n\t\tcase 4:\n\t\t\tnewtype = PyArray_INT32;\n\t\t\tbreak;\n\t\tcase 8:\n\t\t\tnewtype = PyArray_INT64;\n\t\t\tbreak;\n#ifdef PyArray_INT128\n\t\tcase 16:\n\t\t\tnewtype = PyArray_INT128;\n\t\t\tbreak;\n#endif\n\t\tdefault:\n\t\t\tnewtype = PyArray_NOTYPE;\n\t\t}\n\t}\n\n\telse if (gentype == PyArray_UNSIGNEDLTR) {\n\t\tswitch(itemsize) {\n\t\tcase 1:\n\t\t\tnewtype = PyArray_UINT8;\n\t\t\tbreak;\n\t\tcase 2:\n\t\t\tnewtype = PyArray_UINT16;\n\t\t\tbreak;\n\t\tcase 4:\n\t\t\tnewtype = PyArray_UINT32;\n\t\t\tbreak;\n\t\tcase 8:\n\t\t\tnewtype = PyArray_UINT64;\n\t\t\tbreak;\n#ifdef PyArray_INT128\n\t\tcase 16:\n\t\t\tnewtype = PyArray_UINT128;\n\t\t\tbreak;\n#endif\n\t\tdefault:\n\t\t\tnewtype = PyArray_NOTYPE;\n\t\t\tbreak;\n\t\t}\n\t}\n\telse if (gentype == PyArray_FLOATINGLTR) {\n\t\tswitch(itemsize) {\n\t\tcase 4:\n\t\t\tnewtype = PyArray_FLOAT32;\n\t\t\tbreak;\n\t\tcase 8:\n\t\t\tnewtype = PyArray_FLOAT64;\n\t\t\tbreak;\n#ifdef PyArray_FLOAT80\n case 10:\n\t\t\tnewtype = PyArray_FLOAT80;\n\t\t\tbreak;\n#endif\n#ifdef PyArray_FLOAT96\n\t\tcase 12:\n\t\t\tnewtype = PyArray_FLOAT96;\n\t\t\tbreak;\n#endif\t\t \n#ifdef PyArray_FLOAT128\n\t\tcase 16:\n\t\t\tnewtype = PyArray_FLOAT128;\n\t\t\tbreak;\n#endif\n\t\tdefault:\n\t\t\tnewtype = PyArray_NOTYPE;\n\t\t}\t\t\n\t}\n\t\n\telse if (gentype == PyArray_COMPLEXLTR) {\n\t\tswitch(itemsize) {\n\t\tcase 8:\n\t\t\tnewtype = PyArray_COMPLEX64;\n\t\t\tbreak;\n\t\tcase 16:\n\t\t\tnewtype = PyArray_COMPLEX128;\n\t\t\tbreak;\n#ifdef PyArray_FLOAT80\n case 20:\n\t\t\tnewtype = PyArray_COMPLEX160;\n\t\t\tbreak;\n#endif\n#ifdef PyArray_FLOAT96\n\t\tcase 24:\n\t\t\tnewtype = PyArray_COMPLEX192;\t\t\t\n\t\t\tbreak;\n#endif\t\t \n#ifdef PyArray_FLOAT128\n\t\tcase 32:\n\t\t\tnewtype = PyArray_COMPLEX256;\n\t\t\tbreak;\n#endif\n\t\tdefault:\n\t\t\tnewtype = PyArray_NOTYPE;\n\t\t}\t\t\n\t}\n\n\treturn newtype;\n}\n\n\n/* this function takes a Python object which exposes the (single-segment)\n buffer interface and returns a pointer to the data segment\n \n You should increment the reference count by one of buf->base\n if you will hang on to a reference\n\n You only get a borrowed reference to the object. Do not free the\n memory...\n*/\n\n\n/*MULTIARRAY_API\n Get buffer chunk from object\n*/\nstatic int\nPyArray_BufferConverter(PyObject *obj, PyArray_Chunk *buf)\n{\n int buflen;\n\n buf->ptr = NULL;\n buf->flags = BEHAVED_FLAGS;\n buf->base = NULL;\n\n\tif (obj == Py_None)\n\t\treturn PY_SUCCEED;\n\n if (PyObject_AsWriteBuffer(obj, &(buf->ptr), &buflen) < 0) {\n PyErr_Clear();\n buf->flags &= ~WRITEABLE;\n if (PyObject_AsReadBuffer(obj, (const void **)&(buf->ptr), \n &buflen) < 0)\n return PY_FAIL;\n }\n buf->len = (intp) buflen;\n \n /* Point to the base of the buffer object if present */\n if (PyBuffer_Check(obj)) buf->base = ((PyArray_Chunk *)obj)->base;\n if (buf->base == NULL) buf->base = obj;\n \n return PY_SUCCEED; \n}\n\n\n\n/* This function takes a Python sequence object and allocates and\n fills in an intp array with the converted values.\n\n **Remember to free the pointer seq.ptr when done using\n PyDimMem_FREE(seq.ptr)**\n*/\n\n/*MULTIARRAY_API\n Get intp chunk from sequence\n*/\nstatic int\nPyArray_IntpConverter(PyObject *obj, PyArray_Dims *seq)\n{\n int len;\n int nd;\n\n seq->ptr = NULL;\n if (obj == Py_None) return PY_SUCCEED;\n len = PySequence_Size(obj);\n if (len == -1) { /* Check to see if it is a number */\n if (PyNumber_Check(obj)) len = 1;\n }\n if (len < 0) {\n PyErr_SetString(PyExc_TypeError, \n \"expected sequence object with len >= 0\");\n return PY_FAIL;\n }\n if (len > MAX_DIMS) {\n PyErr_Format(PyExc_ValueError, \"sequence too large; \" \\\n \"must be smaller than %d\", MAX_DIMS);\n return PY_FAIL;\n }\n\tif (len > 0) {\n\t\tseq->ptr = PyDimMem_NEW(len);\n\t\tif (seq->ptr == NULL) {\n\t\t\tPyErr_NoMemory();\n\t\t\treturn PY_FAIL;\n\t\t}\n\t}\n seq->len = len;\n nd = PyArray_IntpFromSequence(obj, (intp *)seq->ptr, len);\n if (nd == -1 || nd != len) {\n\t\tPyDimMem_FREE(seq->ptr);\n\t\tseq->ptr=NULL;\n\t\treturn PY_FAIL;\n\t}\n return PY_SUCCEED;\n}\n\n\n/* A tuple type would be either (generic typeobject, typesize) \n or (fixed-length data-type, shape) \n\n or (inheriting data-type, new-data-type)\n The new data-type must have the same itemsize as the inheriting data-type\n unless the latter is 0 \n \n Thus (int32, {'real':(int16,0),'imag',(int16,2)})\n\n is one way to specify a descriptor that will give \n a['real'] and a['imag'] to an int32 array.\n*/\n\n/* leave type reference alone */\nstatic PyArray_Descr *\n_use_inherit(PyArray_Descr *type, PyObject *newobj, int *errflag) \n{\n\tPyArray_Descr *new;\n\tPyArray_Descr *conv;\n\t\n\t*errflag = 0;\n\tif (!PyArray_DescrConverter(newobj, &conv)) {\n\t\treturn NULL;\n\t}\n\t*errflag = 1;\n\tif (type == &OBJECT_Descr) {\n\t\tPyErr_SetString(PyExc_ValueError,\n\t\t\t\t\"cannot base a new descriptor on an\"\\\n\t\t\t\t\" OBJECT descriptor.\");\n\t\treturn NULL;\n\t}\n\tnew = PyArray_DescrNew(type);\n\tif (new == NULL) return NULL;\n\n\tif (new->elsize && new->elsize != conv->elsize) {\n\t\tPyErr_SetString(PyExc_ValueError, \n\t\t\t\t\"mismatch in size of old\"\\\n\t\t\t\t\"and new data-descriptor\");\n\t\treturn NULL;\n\t}\n\tnew->elsize = conv->elsize;\n\tif (conv->fields != Py_None) {\n\t\tnew->fields = conv->fields;\n\t\tPy_XINCREF(new->fields);\n\t}\n\tPy_DECREF(conv);\n\t*errflag = 0;\n\treturn new;\n}\n\nstatic PyArray_Descr *\n_convert_from_tuple(PyObject *obj) \n{\n\tPyArray_Descr *type, *res;\n\tPyObject *val;\n\tint errflag;\n\t\n\tif (PyTuple_GET_SIZE(obj) != 2) return NULL;\n\n\tif (!PyArray_DescrConverter(PyTuple_GET_ITEM(obj,0), &type)) \n\t\treturn NULL;\n\tval = PyTuple_GET_ITEM(obj,1);\n\t/* try to interpret next item as a type */\n\tres = _use_inherit(type, val, &errflag);\n\tif (res || errflag) {\n\t\tPy_DECREF(type);\n\t\tif (res) return res;\n\t\telse return NULL;\n\t}\n\tPyErr_Clear();\n\t/* We get here if res was NULL but errflag wasn't set\n\t --- i.e. the conversion to a data-descr failed in _use_inherit\n\t*/\n\n\tif (type->elsize == 0) { /* interpret next item as a typesize */\n\t\tint itemsize;\n\t\titemsize = PyArray_PyIntAsInt(PyTuple_GET_ITEM(obj,1));\n\t\tif (error_converting(itemsize)) {\n\t\t\tPyErr_SetString(PyExc_ValueError, \n\t\t\t\t\t\"invalid itemsize in generic type \"\\\n\t\t\t\t\t\"tuple\");\n\t\t\tgoto fail;\n\t\t}\n\t\tPyArray_DESCR_REPLACE(type);\n\t\ttype->elsize = itemsize;\n\t}\n\telse {\n\t\t/* interpret next item as shape (if it's a tuple)\n\t\t and reset the type to PyArray_VOID with \n\t\t anew fields attribute. \n\t */\n\t\tPyArray_Dims shape={NULL,-1};\n\t\tPyArray_Descr *newdescr;\n\t\tif (!(PyArray_IntpConverter(val, &shape)) || \n\t\t (shape.len > MAX_DIMS)) {\n\t\t\tPyDimMem_FREE(shape.ptr);\n\t\t\tPyErr_SetString(PyExc_ValueError, \n\t\t\t\t\t\"invalid shape in fixed-type tuple.\");\n\t\t\tgoto fail;\n\t\t}\n\t\t/* If (type, 1) was given, it is equivalent to type... */\n\t\tif (shape.len == 1 && shape.ptr[0] == 1 && PyNumber_Check(val)) {\n\t\t\tPyDimMem_FREE(shape.ptr);\n\t\t\treturn type;\n\t\t}\n\t\tnewdescr = PyArray_DescrNewFromType(PyArray_VOID);\n\t\tif (newdescr == NULL) {PyDimMem_FREE(shape.ptr); goto fail;}\n\t\tnewdescr->elsize = type->elsize;\n\t\tnewdescr->elsize *= PyArray_MultiplyList(shape.ptr, \n\t\t\t\t\t\t\t shape.len);\n\t\tPyDimMem_FREE(shape.ptr);\n\t\tnewdescr->subarray = _pya_malloc(sizeof(PyArray_ArrayDescr));\n\t\tnewdescr->subarray->base = type;\n\t\tif (type->hasobject) newdescr->hasobject = 1;\n\t\tPy_INCREF(val);\n\t\tnewdescr->subarray->shape = val;\n\t\tPy_XDECREF(newdescr->fields);\n\t\tnewdescr->fields = NULL;\n\t\ttype = newdescr;\n\t}\n\treturn type;\n\n fail:\n\tPy_XDECREF(type);\n\treturn NULL;\n}\n\n/* obj is a list. Each item is a tuple with\n\n(field-name, data-type (either a list or a string), and an optional \n shape parameter).\n*/\nstatic PyArray_Descr *\n_convert_from_array_descr(PyObject *obj)\n{\n\tint n, i, totalsize;\n\tint ret;\n\tPyObject *fields, *item, *newobj;\n\tPyObject *name, *key, *tup;\n\tPyObject *nameslist;\n\tPyArray_Descr *new;\n\tPyArray_Descr *conv;\n int hasobject=0;\n\t\n\tn = PyList_GET_SIZE(obj);\t\n\tnameslist = PyList_New(n);\n\tif (!nameslist) return NULL;\n\ttotalsize = 0;\n\tfields = PyDict_New();\n\tfor (i=0; ihasobject)\n hasobject = 1;\n\t\ttup = PyTuple_New(2);\n\t\tPyTuple_SET_ITEM(tup, 0, (PyObject *)conv);\n\t\tPyTuple_SET_ITEM(tup, 1, PyInt_FromLong((long) totalsize));\n\t\ttotalsize += conv->elsize;\n\t\tPyDict_SetItem(fields, name, tup);\n\t\tPy_DECREF(tup);\n\t}\n\tkey = PyInt_FromLong(-1);\n\tPyDict_SetItem(fields, key, nameslist);\n\tPy_DECREF(key);\n\tPy_DECREF(nameslist);\n\tnew = PyArray_DescrNewFromType(PyArray_VOID);\n\tnew->fields = fields;\n\tnew->elsize = totalsize;\n new->hasobject=hasobject;\n\treturn new;\n \n fail:\n\tPy_DECREF(fields);\n\tPy_DECREF(nameslist);\n\treturn NULL;\n\n}\n\n/* a list specifying a data-type can just be\n a list of formats. The names for the fields\n will default to f1, f2, f3, and so forth.\n\n or it can be an array_descr format string -- in which case\n align must be 0. \n*/\n\nstatic PyArray_Descr *\n_convert_from_list(PyObject *obj, int align, int try_descr)\n{\n\tint n, i;\n\tint totalsize;\n\tPyObject *fields;\n\tPyArray_Descr *conv=NULL;\n\tPyArray_Descr *new;\n\tPyObject *key, *tup;\n\tPyObject *nameslist=NULL;\n \tint ret;\n\tint maxalign=0;\n int hasobject=0;\n\t\n\tn = PyList_GET_SIZE(obj);\n\ttotalsize = 0;\n\tif (n==0) return NULL;\n\tnameslist = PyList_New(n);\n\tif (!nameslist) return NULL;\n\tfields = PyDict_New();\n\tfor (i=0; ihasobject)\n\t\t\thasobject=1;\t\t\t\n\t\tPyTuple_SET_ITEM(tup, 0, (PyObject *)conv);\n\t\tif (align) {\n\t\t\tint _align;\n\t\t\t_align = conv->alignment;\n\t\t\tif (_align > 1) totalsize =\t\t\t\\\n\t\t\t\t((totalsize + _align - 1)/_align)*_align;\n\t\t\tmaxalign = MAX(maxalign, _align);\n\t\t}\n\t\tPyTuple_SET_ITEM(tup, 1, PyInt_FromLong((long) totalsize));\n\t\tPyDict_SetItem(fields, key, tup);\n\t\tPy_DECREF(tup);\n\t\tPyList_SET_ITEM(nameslist, i, key);\n\t\ttotalsize += conv->elsize;\n\t}\n\tkey = PyInt_FromLong(-1);\n\tPyDict_SetItem(fields, key, nameslist);\n\tPy_DECREF(key);\n\tPy_DECREF(nameslist);\n\tnew = PyArray_DescrNewFromType(PyArray_VOID);\n\tnew->fields = fields;\n new->hasobject=hasobject;\n\tif (maxalign > 1) {\n\t\ttotalsize = ((totalsize+maxalign-1)/maxalign)*maxalign;\n\t}\n\tif (align) new->alignment = maxalign;\n\tnew->elsize = totalsize;\n\treturn new;\n\n fail:\n\tPy_DECREF(nameslist);\n\tPy_DECREF(fields);\n\tif (!try_descr) return NULL;\n\tif (align) {\n\t\tPyErr_SetString(PyExc_ValueError, \n\t\t\t\t\"failed to convert from list of formats \"\\\n\t\t\t\t\"and align cannot be 1 for conversion from \"\\\n\t\t\t\t\"array_descr structure\");\n\t\treturn NULL;\n\t}\n\tPyErr_Clear();\n\treturn _convert_from_array_descr(obj);\n}\n\n\n/* comma-separated string */\n/* this is the format developed by the numarray records module */\n/* and implemented by the format parser in that module */\n/* this is an alternative implementation found in the _internal.py \n file patterned after that one -- the approach is to try to convert \n to a list (with tuples if any repeat information is present) \n and then call the _convert_from_list)\n*/\n\nstatic PyArray_Descr *\n_convert_from_commastring(PyObject *obj, int align)\n{\n\tPyObject *listobj;\n\tPyArray_Descr *res;\n\n\tif (!PyString_Check(obj)) return NULL;\n listobj = PyObject_CallMethod(_numpy_internal, \"_commastring\",\n\t\t\t\t \"O\", obj);\n\tif (!listobj) return NULL;\n\tres = _convert_from_list(listobj, align, 0);\n\tPy_DECREF(listobj);\n\tif (!res && !PyErr_Occurred()) {\n\t\tPyErr_SetString(PyExc_ValueError, \"invalid data-type\");\n\t\treturn NULL;\n\t}\n\treturn res;\n}\n\n\n\n/* a dictionary specifying a data-type\n must have at least two and up to four\n keys These must all be sequences of the same length.\n\n \"names\" --- field names \n \"formats\" --- the data-type descriptors for the field.\n \n Optional:\n\n \"offsets\" --- integers indicating the offset into the \n record of the start of the field.\n\t\t if not given, then \"consecutive offsets\" \n\t\t will be assumed and placed in the dictionary.\n \n \"titles\" --- Allows the use of an additional key\n for the fields dictionary.\n \nAttribute-lookup-based field names merely has to query the fields \ndictionary of the data-descriptor. Any result present can be used\nto return the correct field.\n\nSo, the notion of what is a name and what is a title is really quite\narbitrary. \n\nWhat does distinguish a title, however, is that if it is not None, \nit will be placed at the end of the tuple inserted into the \nfields dictionary.\n\nIf the dictionary does not have \"names\" and \"formats\" entries,\nthen it will be checked for conformity and used directly. \n*/\n\nstatic PyArray_Descr *\n_use_fields_dict(PyObject *obj, int align)\n{\n return (PyArray_Descr *)PyObject_CallMethod(_numpy_internal, \n\t\t\t\t\t\t \"_usefields\", \n\t\t\t\t\t\t \"Oi\", obj, align);\n}\n\nstatic PyArray_Descr *\n_convert_from_dict(PyObject *obj, int align)\n{\n\tPyArray_Descr *new;\n\tPyObject *fields=NULL;\n\tPyObject *names, *offsets, *descrs, *titles, *key;\n\tint n, i;\n\tint totalsize;\n\tint maxalign=0;\n int hasobject=0;\n\t\n\tfields = PyDict_New();\n\tif (fields == NULL) return (PyArray_Descr *)PyErr_NoMemory();\n\t\n\tnames = PyDict_GetItemString(obj, \"names\");\n\tdescrs = PyDict_GetItemString(obj, \"formats\");\n\n\tif (!names || !descrs) {\n\t\tPy_DECREF(fields);\n\t\treturn _use_fields_dict(obj, align);\n\t}\n\tn = PyObject_Length(names);\n\toffsets = PyDict_GetItemString(obj, \"offsets\");\n\ttitles = PyDict_GetItemString(obj, \"titles\");\n\tif ((n > PyObject_Length(descrs)) ||\t\t\t\\\n\t (offsets && (n > PyObject_Length(offsets))) ||\t\\\n\t (titles && (n > PyObject_Length(titles)))) {\n\t\tPyErr_SetString(PyExc_ValueError,\n\t\t\t\t\"all items in the dictionary must have\" \\\n\t\t\t\t\" the same length.\");\n\t\tgoto fail;\n\t}\n\n\ttotalsize = 0;\n\tfor(i=0; i totalsize) totalsize = offset;\n\t\t}\n\t\telse {\n\t\t\tif (align) {\n\t\t\t\tint _align = newdescr->alignment;\n\t\t\t\tif (_align > 1) totalsize =\t\t\\\n\t\t\t\t\t((totalsize + _align - 1)/_align)*_align;\n\t\t\t\tmaxalign = MAX(maxalign,_align);\n\t\t\t}\n\t\t\tPyTuple_SET_ITEM(tup, 1, PyInt_FromLong(totalsize));\n\t\t}\n\t\tif (len == 3) PyTuple_SET_ITEM(tup, 2, item);\n\t\tname = PyObject_GetItem(names, index);\n\t\tPy_DECREF(index);\n\n\t\t/* Insert into dictionary */\n\t\tif (PyDict_GetItem(fields, name) != NULL) {\n\t\t\tPyErr_SetString(PyExc_ValueError,\n\t\t\t\t\t\"two fields with the same name\");\n\t\t\tret = PY_FAIL;\n\t\t}\n\t\tPyDict_SetItem(fields, name, tup);\n\t\tPy_DECREF(name);\n\t\tif (len == 3) PyDict_SetItem(fields, item, tup);\n\t\tPy_DECREF(tup);\n\t\tif ((ret == PY_FAIL) || (newdescr->elsize == 0)) goto fail;\n if (!hasobject && newdescr->hasobject)\n hasobject = 1;\n\t\ttotalsize += newdescr->elsize;\n\t}\n\n\tnew = PyArray_DescrNewFromType(PyArray_VOID);\n\tif (new == NULL) goto fail;\n\tif (maxalign > 1)\n\t\ttotalsize = ((totalsize + maxalign - 1)/maxalign)*maxalign;\n\tif (align) new->alignment = maxalign;\n\tnew->elsize = totalsize;\n\tkey = PyInt_FromLong(-1);\n\tPyDict_SetItem(fields, key, names);\n\tPy_DECREF(key);\n\tnew->fields = fields;\n new->hasobject=hasobject;\n\treturn new;\n\n fail:\n\tPy_XDECREF(fields);\n\treturn NULL;\n}\n\n/* \n any object with \n the .fields attribute and/or .itemsize attribute \n (if the .fields attribute does not give\n the total size -- i.e. a partial record naming).\n If itemsize is given it must be >= size computed from fields\n \n The .fields attribute must return a convertible dictionary if \n present. Result inherits from PyArray_VOID.\n*/\n\n\n/*MULTIARRAY_API\n Get typenum from an object -- None goes to NULL\n*/\nstatic int\nPyArray_DescrConverter2(PyObject *obj, PyArray_Descr **at)\n{\n\tif (obj == Py_None) {\n\t\t*at = NULL;\n\t\treturn PY_SUCCEED;\n\t}\n\telse return PyArray_DescrConverter(obj, at);\n}\n\n/* This function takes a Python object representing a type and converts it \n to a the correct PyArray_Descr * structure to describe the type.\n \n Many objects can be used to represent a data-type which in NumPy is\n quite a flexible concept. \n\n This is the central code that converts Python objects to \n Type-descriptor objects that are used throughout numpy.\n */\n\n/* new reference in *at */\n/*MULTIARRAY_API\n Get typenum from an object -- None goes to &LONG_descr\n*/\nstatic int\nPyArray_DescrConverter(PyObject *obj, PyArray_Descr **at)\n{\n char *type;\n int check_num=PyArray_NOTYPE+10;\n\tint len;\n\tPyObject *item;\n\tint elsize = 0;\n\tchar endian = '=';\n\n\t*at=NULL;\n\t\n\t/* default */\n if (obj == Py_None) {\n\t\t*at = PyArray_DescrFromType(PyArray_LONG);\n\t\treturn PY_SUCCEED;\n\t}\n\t\n\tif (PyArray_DescrCheck(obj)) {\n\t\t*at = (PyArray_Descr *)obj;\n\t\tPy_INCREF(*at);\n\t\treturn PY_SUCCEED;\n\t}\n\t\n if (PyType_Check(obj)) {\n\t\tif (PyType_IsSubtype((PyTypeObject *)obj, \n\t\t\t\t &PyGenericArrType_Type)) {\n\t\t\t*at = PyArray_DescrFromTypeObject(obj);\n\t\t\tif (*at) return PY_SUCCEED;\n\t\t\telse return PY_FAIL;\n\t\t}\n\t\tcheck_num = PyArray_OBJECT;\n\t\tif (obj == (PyObject *)(&PyInt_Type))\n\t\t\tcheck_num = PyArray_LONG;\n\t\telse if (obj == (PyObject *)(&PyLong_Type))\n\t\t\tcheck_num = PyArray_LONGLONG;\n\t\telse if (obj == (PyObject *)(&PyFloat_Type)) \n\t\t\tcheck_num = PyArray_DOUBLE;\n\t\telse if (obj == (PyObject *)(&PyComplex_Type)) \n\t\t\tcheck_num = PyArray_CDOUBLE;\n\t\telse if (obj == (PyObject *)(&PyBool_Type))\n\t\t\tcheck_num = PyArray_BOOL;\n else if (obj == (PyObject *)(&PyString_Type))\n check_num = PyArray_STRING;\n else if (obj == (PyObject *)(&PyUnicode_Type))\n check_num = PyArray_UNICODE;\n\t\telse if (obj == (PyObject *)(&PyBuffer_Type))\n\t\t\tcheck_num = PyArray_VOID;\n\t\telse {\n\t\t\t*at = _arraydescr_fromobj(obj);\n\t\t\tif (*at) return PY_SUCCEED;\n\t\t}\n\t\tgoto finish;\n\t}\n\n\t/* or a typecode string */\n\n\tif (PyString_Check(obj)) {\n\t\t/* Check for a string typecode. */\n\t\ttype = PyString_AS_STRING(obj);\n\t\tlen = PyString_GET_SIZE(obj);\n\t\tif (len <= 0) goto fail;\n\t\tcheck_num = (int) type[0];\n\t\tif ((char) check_num == '>' || (char) check_num == '<' || \\\n\t\t (char) check_num == '|' || (char) check_num == '=') {\n\t\t\tif (len <= 1) goto fail;\n\t\t\tendian = (char) check_num;\n\t\t\ttype++; len--;\n\t\t\tcheck_num = (int) type[0];\n\t\t\tif (endian == '|') endian = '=';\n\t\t}\n\t\tif (len > 1) {\n\t\t\tint i;\n\t\t\telsize = atoi(type+1);\n\t\t\t/* check for commas present */\n\t\t\tfor (i=1;ielsize == 0) && (elsize != 0)) {\n\t\tPyArray_DESCR_REPLACE(*at);\n\t\t(*at)->elsize = elsize;\n\t}\n\tif (endian != '=' && PyArray_ISNBO(endian)) endian = '='; \n\t\n\tif (endian != '=' && (*at)->byteorder != '|' &&\t\\\n\t (*at)->byteorder != endian) {\n\t\tPyArray_DESCR_REPLACE(*at);\n\t\t(*at)->byteorder = endian;\n\t}\n\t\n return PY_SUCCEED;\n\n fail:\n\tPyErr_SetString(PyExc_TypeError, \n\t\t\t\"data type not understood\");\n\t*at=NULL;\n\treturn PY_FAIL;\n}\t\n\n/*MULTIARRAY_API\n Convert object to endian\n*/\nstatic int\nPyArray_ByteorderConverter(PyObject *obj, char *endian)\n{\n\tchar *str;\n\t*endian = PyArray_SWAP;\n\tstr = PyString_AsString(obj);\n\tif (!str) return PY_FAIL;\n\tif (strlen(str) < 1) {\n\t\tPyErr_SetString(PyExc_ValueError, \n\t\t\t\t\"Byteorder string must be at least length 1\");\n\t\treturn PY_FAIL;\n\t}\n\t*endian = str[0];\n\tif (str[0] != PyArray_BIG && str[0] != PyArray_LITTLE &&\t\\\n\t str[0] != PyArray_NATIVE) {\n\t\tif (str[0] == 'b' || str[0] == 'B')\n\t\t\t*endian = PyArray_BIG;\n\t\telse if (str[0] == 'l' || str[0] == 'L')\n\t\t\t*endian = PyArray_LITTLE;\n\t\telse if (str[0] == 'n' || str[0] == 'N')\n\t\t\t*endian = PyArray_NATIVE;\n\t\telse if (str[0] == 'i' || str[0] == 'I')\n\t\t\t*endian = PyArray_IGNORE;\n\t\telse if (str[0] == 's' || str[0] == 'S')\n\t\t\t*endian = PyArray_SWAP;\n\t\telse {\n\t\t\tPyErr_Format(PyExc_ValueError, \n\t\t\t\t \"%s is an unrecognized byteorder\",\n\t\t\t\t str);\n\t\t\treturn PY_FAIL;\n\t\t}\n\t}\n\treturn PY_SUCCEED;\n}\n\n/*MULTIARRAY_API\n Convert object to sort kind \n*/\nstatic int\nPyArray_SortkindConverter(PyObject *obj, PyArray_SORTKIND *sortkind)\n{\n\tchar *str;\n\t*sortkind = PyArray_QUICKSORT;\n\tstr = PyString_AsString(obj);\n\tif (!str) return PY_FAIL;\n\tif (strlen(str) < 1) {\n\t\tPyErr_SetString(PyExc_ValueError, \n\t\t\t\t\"Sort kind string must be at least length 1\");\n\t\treturn PY_FAIL;\n\t}\n\tif (str[0] == 'q' || str[0] == 'Q')\n\t\t*sortkind = PyArray_QUICKSORT;\n\telse if (str[0] == 'h' || str[0] == 'H')\n\t\t*sortkind = PyArray_HEAPSORT;\n\telse if (str[0] == 'm' || str[0] == 'M')\n\t\t*sortkind = PyArray_MERGESORT;\n\telse if (str[0] == 't' || str[0] == 'T')\n\t\t*sortkind = PyArray_TIMSORT;\n\telse {\n\t\tPyErr_Format(PyExc_ValueError, \n\t\t\t \"%s is an unrecognized kind of sort\",\n\t\t\t str);\n\t\treturn PY_FAIL;\n\t}\n\treturn PY_SUCCEED;\n}\n\n\n/* This function returns true if the two typecodes are \n equivalent (same basic kind and same itemsize).\n*/\n\n/*MULTIARRAY_API*/\nstatic Bool\nPyArray_EquivTypes(PyArray_Descr *typ1, PyArray_Descr *typ2)\n{\n\tregister int typenum1=typ1->type_num;\n\tregister int typenum2=typ2->type_num;\n\tregister int size1=typ1->elsize;\n\tregister int size2=typ2->elsize;\n\n\tif (size1 != size2) return FALSE;\n\tif (typ1->fields != typ2->fields) return FALSE;\n\tif (PyArray_ISNBO(typ1->byteorder) != PyArray_ISNBO(typ2->byteorder))\n\t\treturn FALSE;\n\n\tif (typenum1 == PyArray_VOID || \\\n\t typenum2 == PyArray_VOID) {\n\t\treturn ((typenum1 == typenum2) && \n\t\t\t(typ1->typeobj == typ2->typeobj) &&\n\t\t\t(typ1->fields == typ2->fields));\n\t}\n\treturn (typ1->kind == typ2->kind);\n}\n\n/*** END C-API FUNCTIONS **/\n\nstatic PyObject *\n_prepend_ones(PyArrayObject *arr, int nd, int ndmin)\n{\n\tintp newdims[MAX_DIMS];\n\tintp newstrides[MAX_DIMS];\n\tint i,k,num;\n\tPyObject *ret;\n\n\tnum = ndmin-nd;\n\tfor (i=0; idescr->elsize;\n\t}\n\tfor (i=num;idimensions[k];\n\t\tnewstrides[i] = arr->strides[k];\n\t}\n\tPy_INCREF(arr->descr);\n\tret = PyArray_NewFromDescr(arr->ob_type, arr->descr, ndmin,\n\t\t\t\t newdims, newstrides, arr->data, arr->flags,\n\t\t\t\t (PyObject *)arr);\n\t/* steals a reference to arr --- so don't increment\n\t here */\n\tPyArray_BASE(ret) = (PyObject *)arr;\n\treturn ret;\n}\n\n\n#define _ARET(x) PyArray_Return((PyArrayObject *)(x))\n\nstatic char doc_fromobject[] = \"array(object, dtype=None, copy=1, fortran=0, \"\\\n \"subok=0,ndmin=0)\\n\"\\\n \"will return a new array formed from the given object type given.\\n\"\\\n \"Object can anything with an __array__ method, or any object\\n\"\\\n \"exposing the array interface, or any (nested) sequence.\\n\"\\\n \"If no type is given, then the type will be determined as the\\n\"\\\n \"minimum type required to hold the objects in the sequence.\\n\"\\\n \"If copy is zero and sequence is already an array with the right \\n\"\\\n \"type, a reference will be returned. If the sequence is an array,\\n\"\\\n \"type can be used only to upcast the array. For downcasting \\n\"\\\n \"use .astype(t) method. If subok is true, then subclasses of the\\n\"\\\n \"array may be returned. Otherwise, a base-class ndarray is returned\\n\"\\\n\t\"The ndmin argument specifies how many dimensions the returned\\n\"\\\n\t\"array should have as a minimum. 1's will be pre-pended to the\\n\"\\\n\t\"shape as needed to meet this requirement.\";\n\nstatic PyObject *\n_array_fromobject(PyObject *ignored, PyObject *args, PyObject *kws)\n{\n\tPyObject *op, *ret=NULL;\n\tstatic char *kwd[]= {\"object\", \"dtype\", \"copy\", \"fortran\", \"subok\", \n\t\t\t \"ndmin\", NULL};\n Bool subok=FALSE;\n\tBool copy=TRUE;\n\tint ndmin=0, nd;\n\tPyArray_Descr *type=NULL;\n\tPyArray_Descr *oldtype=NULL;\n\tBool fortran=FALSE;\n\tint flags=0;\n\n\tif(!PyArg_ParseTupleAndKeywords(args, kws, \"O|O&O&O&O&i\", kwd, &op, \n\t\t\t\t\tPyArray_DescrConverter2,\n &type, \n\t\t\t\t\tPyArray_BoolConverter, ©, \n\t\t\t\t\tPyArray_BoolConverter, &fortran,\n PyArray_BoolConverter, &subok, \n\t\t\t\t\t&ndmin)) \n\t\treturn NULL;\n\n\t/* fast exit if simple call */\n\tif ((PyArray_CheckExact(op) || PyBigArray_CheckExact(op))) {\n\t\tif (type==NULL) {\n\t\t\tif (!copy && fortran==PyArray_ISFORTRAN(op)) {\n\t\t\t\tPy_INCREF(op);\n\t\t\t\tret = op;\n\t\t\t\tgoto finish;\n\t\t\t}\n\t\t\telse {\n\t\t\t\tret = PyArray_NewCopy((PyArrayObject*)op, \n\t\t\t\t\t\t fortran);\n\t\t\t\tgoto finish;\n\t\t\t}\n\t\t}\n\t\t/* One more chance */\n\t\toldtype = PyArray_DESCR(op);\n\t\tif (PyArray_EquivTypes(oldtype, type)) {\n\t\t\tif (!copy && fortran==PyArray_ISFORTRAN(op)) {\n\t\t\t\tPy_INCREF(op);\n\t\t\t\tret = op;\n\t\t\t\tgoto finish;\n\t\t\t}\n\t\t\telse {\n\t\t\t\tret = PyArray_NewCopy((PyArrayObject*)op,\n\t\t\t\t\t\t fortran);\n\t\t\t\tif (oldtype == type) return ret;\n\t\t\t\tPy_INCREF(oldtype);\n\t\t\t\tPy_DECREF(PyArray_DESCR(ret));\n\t\t\t\tPyArray_DESCR(ret) = oldtype;\n\t\t\t\tgoto finish;\n\t\t\t}\n\t\t}\n\t}\n\n\tif (copy) {\n\t\tflags = ENSURECOPY;\n\t}\n\tif (fortran) {\n\t\tflags |= FORTRAN;\n\t}\n if (!subok) {\n flags |= ENSUREARRAY;\n }\n\n\tif ((ret = PyArray_CheckFromAny(op, type, 0, 0, flags, NULL)) == NULL) \n\t\treturn NULL;\n\n finish:\n\n\tif ((nd=PyArray_NDIM(ret)) >= ndmin) return ret;\n\t/* create a new array from the same data with ones in the shape */\n\t/* steals a reference to ret */\n\treturn _prepend_ones((PyArrayObject *)ret, nd, ndmin);\n}\n\n/* accepts NULL type */\n/* steals referenct to type */\n/*MULTIARRAY_API\n Empty\n*/\nstatic PyObject *\nPyArray_Empty(int nd, intp *dims, PyArray_Descr *type, int fortran)\n{\n\tPyArrayObject *ret;\n \n\tif (!type) type = PyArray_DescrFromType(PyArray_LONG);\n\tret = (PyArrayObject *)PyArray_NewFromDescr(&PyArray_Type, \n\t\t\t\t\t\t type, nd, dims, \n\t\t\t\t\t\t NULL, NULL,\n\t\t\t\t\t\t fortran, NULL);\n\tif (ret == NULL) return NULL;\n \n\tif ((PyArray_TYPE(ret) == PyArray_OBJECT)) {\n PyArray_FillObjectArray(ret, Py_None);\n\t}\n\treturn (PyObject *)ret;\n}\n\n\nstatic char doc_empty[] = \"empty((d1,...,dn),dtype=int,fortran=0) will return a new array\\n of shape (d1,...,dn) and given type with all its entries uninitialized. This can be faster than zeros.\";\n\nstatic PyObject *\narray_empty(PyObject *ignored, PyObject *args, PyObject *kwds) \n{\n \n\tstatic char *kwlist[] = {\"shape\",\"dtype\",\"fortran\",NULL};\n\tPyArray_Descr *typecode=NULL;\n PyArray_Dims shape = {NULL, 0};\n\tBool fortran = FALSE;\t\n PyObject *ret=NULL;\n\n\tif (!PyArg_ParseTupleAndKeywords(args, kwds, \"O&|O&O&\",\n\t\t\t\t\t kwlist, PyArray_IntpConverter,\n &shape, \n PyArray_DescrConverter,\n\t\t\t\t\t &typecode, \n\t\t\t\t\t PyArray_BoolConverter, &fortran)) \n\t\tgoto fail;\n\n\tret = PyArray_Empty(shape.len, shape.ptr, typecode, fortran); \n PyDimMem_FREE(shape.ptr);\n return ret;\n\n fail:\n\tPyDimMem_FREE(shape.ptr);\n\treturn ret;\n}\n\nstatic char doc_scalar[] = \"scalar(dtype,obj) will return a new scalar array of the given type initialized with obj. Mainly for pickle support. The dtype must be a valid data-type descriptor. If dtype corresponds to an OBJECT descriptor, then obj can be any object, otherwise obj must be a string. If obj is not given it will be interpreted as None for object type and zeros for all other types.\";\n\nstatic PyObject *\narray_scalar(PyObject *ignored, PyObject *args, PyObject *kwds) \n{\n \n\tstatic char *kwlist[] = {\"dtype\",\"obj\", NULL};\n\tPyArray_Descr *typecode;\n\tPyObject *obj=NULL;\n\tint alloc=0;\n\tvoid *dptr;\n\tPyObject *ret;\n\n\t\n\tif (!PyArg_ParseTupleAndKeywords(args, kwds, \"O!|O\",\n\t\t\t\t\t kwlist, &PyArrayDescr_Type, \n\t\t\t\t\t &typecode,\n\t\t\t\t\t &obj)) \n\t\treturn NULL;\n\t\t\n\tif (typecode->elsize == 0) {\n\t\tPyErr_SetString(PyExc_ValueError,\t\t\\\n\t\t\t\t\"itemsize cannot be zero\");\n\t\treturn NULL;\n\t}\n\n\tif (typecode->type_num == PyArray_OBJECT) {\n\t\tif (obj == NULL) obj = Py_None;\n\t\tdptr = &obj;\n\t}\n\telse {\n\t\tif (obj == NULL) {\n\t\t\tdptr = _pya_malloc(typecode->elsize);\n\t\t\tif (dptr == NULL) {\n\t\t\t\treturn PyErr_NoMemory();\n\t\t\t}\n\t\t\tmemset(dptr, '\\0', typecode->elsize);\n\t\t\talloc = 1;\n\t\t}\n\t\telse {\n\t\t\tif (!PyString_Check(obj)) {\n\t\t\t\tPyErr_SetString(PyExc_TypeError, \n\t\t\t\t\t\t\"initializing object must \"\\\n\t\t\t\t\t\t\"be a string\");\n\t\t\t\treturn NULL;\n\t\t\t}\n\t\t\tif (PyString_GET_SIZE(obj) < typecode->elsize) {\n\t\t\t\tPyErr_SetString(PyExc_ValueError,\n\t\t\t\t\t\t\"initialization string is too\"\\\n\t\t\t\t\t\t\" small\");\n\t\t\t\treturn NULL;\n\t\t\t}\n\t\t\tdptr = PyString_AS_STRING(obj);\n\t\t}\n\t}\n\n\tret = PyArray_Scalar(dptr, typecode, NULL);\n\t\n\t/* free dptr which contains zeros */\n\tif (alloc) _pya_free(dptr);\n\treturn ret;\n}\n\n\n/* steal a reference */\n/* accepts NULL type */\n/*MULTIARRAY_API\n Zeros\n*/\nstatic PyObject *\nPyArray_Zeros(int nd, intp *dims, PyArray_Descr *type, int fortran)\n{\n\tPyArrayObject *ret;\n\tintp n;\n\n\tif (!type) type = PyArray_DescrFromType(PyArray_LONG);\n\tret = (PyArrayObject *)PyArray_NewFromDescr(&PyArray_Type, \n\t\t\t\t\t\t type,\n\t\t\t\t\t\t nd, dims, \n\t\t\t\t\t\t NULL, NULL, \n\t\t\t\t\t\t fortran, NULL);\n\tif (ret == NULL) return NULL;\n \n\tif ((PyArray_TYPE(ret) == PyArray_OBJECT)) {\n\t\tPyObject *zero = PyInt_FromLong(0);\n PyArray_FillObjectArray(ret, zero);\n Py_DECREF(zero);\n\t}\n\telse {\n\t\tn = PyArray_NBYTES(ret);\n\t\tmemset(ret->data, 0, n);\n\t}\n\treturn (PyObject *)ret;\n\n}\n\nstatic char doc_zeros[] = \"zeros((d1,...,dn),dtype=int,fortran=0) will return a new array of shape (d1,...,dn) and type typecode with all it's entries initialized to zero.\";\n\n\nstatic PyObject *\narray_zeros(PyObject *ignored, PyObject *args, PyObject *kwds) \n{\n\tstatic char *kwlist[] = {\"shape\",\"dtype\",\"fortran\",NULL}; /* XXX ? */\n\tPyArray_Descr *typecode=NULL;\n PyArray_Dims shape = {NULL, 0};\n\tBool fortran = FALSE;\t\n PyObject *ret=NULL;\n\n\tif (!PyArg_ParseTupleAndKeywords(args, kwds, \"O&|O&O&\",\n\t\t\t\t\t kwlist, PyArray_IntpConverter,\n &shape, \n PyArray_DescrConverter,\n\t\t\t\t\t &typecode, \n\t\t\t\t\t PyArray_BoolConverter,\n\t\t\t\t\t &fortran)) \n\t\tgoto fail;\n\n\tret = PyArray_Zeros(shape.len, shape.ptr, typecode, (int) fortran);\n PyDimMem_FREE(shape.ptr);\n return ret;\n\n fail:\n\tPyDimMem_FREE(shape.ptr);\n\treturn ret;\n}\n\nstatic char doc_set_typeDict[] = \"set_typeDict(dict) set the internal \"\\\n\t\"dictionary that can look up an array type using a registered \"\\\n\t\"code\";\n\nstatic PyObject *\narray_set_typeDict(PyObject *ignored, PyObject *args)\n{\n\tPyObject *dict;\n\tif (!PyArg_ParseTuple(args, \"O\", &dict)) return NULL;\n\tPy_XDECREF(typeDict); /* Decrement old reference (if any)*/\n\ttypeDict = dict;\n\tPy_INCREF(dict); /* Create an internal reference to it */\n\tPy_INCREF(Py_None);\n\treturn Py_None;\n}\n\nstatic int\n_skip_sep(char **ptr, char *sep)\n{\n\tchar *a;\n\tint n;\n\tn = strlen(sep);\n\ta = *ptr;\n\twhile(*a != '\\0' && (strncmp(a, sep, n) != 0))\n\t\ta++;\n\tif (*a == '\\0') return -1;\n\t*ptr = a+strlen(sep);\n\treturn 0;\n}\n\n/* steals a reference to dtype -- accepts NULL */\n/*OBJECT_API*/\nstatic PyObject *\nPyArray_FromString(char *data, intp slen, PyArray_Descr *dtype, \n\t\t intp n, char *sep)\n{\n\tint itemsize;\n\tPyArrayObject *ret;\n\tBool binary;\n\n\tif (dtype == NULL)\n\t\tdtype=PyArray_DescrFromType(PyArray_LONG);\n\t\n\titemsize = dtype->elsize;\n\tif (itemsize == 0) {\n\t\tPyErr_SetString(PyExc_ValueError, \"zero-valued itemsize\");\n\t\tPy_DECREF(dtype);\n\t\treturn NULL;\n\t}\n\n\tbinary = ((sep == NULL) || (strlen(sep) == 0));\t\n\n\tif (binary) {\n\t\tif (dtype == &OBJECT_Descr) {\n\t\t\tPyErr_SetString(PyExc_ValueError, \n\t\t\t\t\t\"Cannot create an object array from\"\\\n\t\t\t\t\t\" a binary string\");\n\t\t\tPy_DECREF(dtype);\n\t\t\treturn NULL;\n\t\t}\t\t\n\t\tif (n < 0 ) {\n\t\t\tif (slen % itemsize != 0) {\n\t\t\t\tPyErr_SetString(PyExc_ValueError, \n\t\t\t\t\t\t\"string size must be a \"\\\n\t\t\t\t\t\t\"multiple of element size\");\n\t\t\t\tPy_DECREF(dtype);\n\t\t\t\treturn NULL;\n\t\t\t}\n\t\t\tn = slen/itemsize;\n\t\t} else {\n\t\t\tif (slen < n*itemsize) {\n\t\t\t\tPyErr_SetString(PyExc_ValueError, \n\t\t\t\t\t\t\"string is smaller than \" \\\n\t\t\t\t\t\t\"requested size\");\n\t\t\t\tPy_DECREF(dtype);\n\t\t\t\treturn NULL;\n\t\t\t}\n\t\t}\n\t\n\t\tif ((ret = (PyArrayObject *)\\\n\t\t PyArray_NewFromDescr(&PyArray_Type, dtype,\n\t\t\t\t\t 1, &n, NULL, NULL,\n\t\t\t\t\t 0, NULL)) == NULL)\n\t\t\treturn NULL;\t\t\n\t\tmemcpy(ret->data, data, n*dtype->elsize);\n\t\treturn (PyObject *)ret;\n\t}\n\telse { /* read from character-based string */\n\t\tchar *ptr;\t\t\n\t\tPyArray_FromStrFunc *fromstr;\n\t\tchar *dptr;\n\t\tintp nread=0;\n\t\tintp index;\n\n\t\tfromstr = dtype->f->fromstr;\n\t\tif (fromstr == NULL) {\n\t\t\tPyErr_SetString(PyExc_ValueError, \n\t\t\t\t\t\"don't know how to read \"\t\\\n\t\t\t\t\t\"character strings for given \"\t\\\n\t\t\t\t\t\"array type\");\n\t\t\tPy_DECREF(dtype);\n\t\t\treturn NULL;\n\t\t}\n\n\t\tif (n!=-1) {\n\t\t\tret = (PyArrayObject *) \\\n\t\t\t\tPyArray_NewFromDescr(&PyArray_Type,\n\t\t\t\t\t\t dtype, 1, &n, NULL,\n\t\t\t\t\t\t NULL, 0, NULL);\n\t\t\tif (ret == NULL) return NULL;\n\t\t\tptr = data;\n\t\t\tdptr = ret->data;\n\t\t\tfor (index=0; index < n; index++) {\n\t\t\t\tif (fromstr(ptr, dptr, &ptr, ret) < 0)\n\t\t\t\t\tbreak;\n\t\t\t\tnread += 1;\n\t\t\t\tdptr += dtype->elsize;\n\t\t\t\tif (_skip_sep(&ptr, sep) < 0) \n\t\t\t\t\tbreak;\n\t\t\t}\n\t\t\tif (nread < n) {\n\t\t\t\tfprintf(stderr, \"%ld items requested but \"\\\n\t\t\t\t\t\"only %ld read\\n\", \n\t\t\t\t\t(long) n, (long) nread);\n\t\t\t\tret->data = \\\n\t\t\t\t\tPyDataMem_RENEW(ret->data, \n\t\t\t\t\t\t\tnread *\t\t\\\n\t\t\t\t\t\t\tret->descr->elsize);\n\t\t\t\tPyArray_DIM(ret,0) = nread;\n\t\t\t}\n\t\t}\n\t\telse {\n#define _FILEBUFNUM 4096\n\t\t\tintp thisbuf=0;\n\t\t\tintp size = _FILEBUFNUM;\n\t\t\tintp bytes;\n\t\t\tintp totalbytes;\n\t\t\tchar *end;\n\t\t\tint val;\n\n\t\t\tret = (PyArrayObject *)\\\n\t\t\t\tPyArray_NewFromDescr(&PyArray_Type, \n\t\t\t\t\t\t dtype,\n\t\t\t\t\t\t 1, &size, \n\t\t\t\t\t\t NULL, NULL, \n\t\t\t\t\t\t 0, NULL);\n\t\t\tif (ret==NULL) return NULL;\n\t\t\ttotalbytes = bytes = size * dtype->elsize;\n\t\t\tdptr = ret->data;\n\t\t\tptr = data;\n\t\t\tend = data+slen;\n\t\t\twhile (ptr < end) {\n\t\t\t\tval = fromstr(ptr, dptr, &ptr, ret);\n\t\t\t\tif (val < 0) break;\n\t\t\t\tnread += 1;\n\t\t\t\tval = _skip_sep(&ptr, sep);\n\t\t\t\tif (val < 0) break;\n\t\t\t\tthisbuf += 1;\n\t\t\t\tdptr += dtype->elsize;\n\t\t\t\tif (thisbuf == size) {\n\t\t\t\t\ttotalbytes += bytes;\n\t\t\t\t\tret->data = PyDataMem_RENEW(ret->data, \n\t\t\t\t\t\t\t\t totalbytes);\n\t\t\t\t\tdptr = ret->data + \\\n\t\t\t\t\t\t(totalbytes - bytes);\n\t\t\t\t\tthisbuf = 0;\n\t\t\t\t}\n\t\t\t}\n\t\t\tret->data = PyDataMem_RENEW(ret->data, \n\t\t\t\t\t\t nread*ret->descr->elsize);\n\t\t\tPyArray_DIM(ret,0) = nread;\n#undef _FILEBUFNUM\n\t\t}\n\t}\n\treturn (PyObject *)ret;\n}\n\nstatic char doc_fromString[] = \"fromstring(string, dtype=int, count=-1) returns a new 1d array initialized from the raw binary data in string. If count is positive, the new array will have count elements, otherwise it's size is determined by the size of string.\";\n\nstatic PyObject *\narray_fromString(PyObject *ignored, PyObject *args, PyObject *keywds)\n{\n\tchar *data;\n\tlonglong nin=-1;\n\tchar *sep=NULL;\n\tint s;\n\tstatic char *kwlist[] = {\"string\", \"dtype\", \"count\", \"sep\", NULL};\n\tPyArray_Descr *descr=NULL;\n\n\tif (!PyArg_ParseTupleAndKeywords(args, keywds, \"s#|O&Ls\", kwlist, \n\t\t\t\t\t &data, &s, \n\t\t\t\t\t PyArray_DescrConverter, &descr,\n\t\t\t\t\t &nin, &sep)) {\n\t\treturn NULL;\n\t}\n\n\treturn PyArray_FromString(data, (intp)s, descr, (intp)nin, sep);\n}\n\n/* This needs an open file object and reads it in directly. \n memory-mapped files handled differently through buffer interface.\n\nfile pointer number in resulting 1d array \n(can easily reshape later, -1 for to end of file)\ntype of array\nsep is a separator string for character-based data (or NULL for binary)\n \" \" means whitespace\n*/\n\n/*OBJECT_API*/\nstatic PyObject *\nPyArray_FromFile(FILE *fp, PyArray_Descr *typecode, intp num, char *sep)\n{\n\tPyArrayObject *r;\n\tsize_t nread = 0;\n\tPyArray_ScanFunc *scan;\n\tBool binary;\n\n\tif (typecode->elsize == 0) {\n\t\tPyErr_SetString(PyExc_ValueError, \"0-sized elements.\");\n\t\tPy_DECREF(typecode);\n\t\treturn NULL;\n\t}\n\n\tbinary = ((sep == NULL) || (strlen(sep) == 0));\n\tif (num == -1 && binary) { /* Get size for binary file*/\n\t\tintp start, numbytes;\n\t\tstart = (intp )ftell(fp);\n\t\tfseek(fp, 0, SEEK_END);\n\t\tnumbytes = (intp )ftell(fp) - start;\n\t\trewind(fp);\n\t\tif (numbytes == -1) {\n\t\t\tPyErr_SetString(PyExc_IOError, \n\t\t\t\t\t\"could not seek in file\");\n\t\t\tPy_DECREF(typecode);\n\t\t\treturn NULL;\n\t\t}\n\t\tnum = numbytes / typecode->elsize;\n\t}\n\t\n\tif (binary) { /* binary data */\n\t\tr = (PyArrayObject *)PyArray_NewFromDescr(&PyArray_Type, \n\t\t\t\t\t\t\t typecode,\n\t\t\t\t\t\t\t 1, &num, \n\t\t\t\t\t\t\t NULL, NULL, \n\t\t\t\t\t\t\t 0, NULL);\n\t\tif (r==NULL) return NULL;\n\t\tnread = fread(r->data, typecode->elsize, num, fp);\n\t}\n\telse { /* character reading */\n\t\tintp i;\n\t\tchar *dptr;\n\t\tint done=0;\n\n\t\tscan = typecode->f->scanfunc;\n\t\tif (scan == NULL) {\n\t\t\tPyErr_SetString(PyExc_ValueError, \n\t\t\t\t\t\"don't know how to read \"\t\\\n\t\t\t\t\t\"character files with that \"\t\\\n\t\t\t\t\t\"array type\");\n\t\t\tPy_DECREF(typecode);\n\t\t\treturn NULL;\n\t\t}\n\n\t\tif (num != -1) { /* number to read is known */\n\t\t\tr = (PyArrayObject *)\\\n\t\t\t\tPyArray_NewFromDescr(&PyArray_Type, \n\t\t\t\t\t\t typecode, \n\t\t\t\t\t\t 1, &num, \n\t\t\t\t\t\t NULL, NULL, \n\t\t\t\t\t\t 0, NULL);\n\t\t\tif (r==NULL) return NULL;\n\t\t\tdptr = r->data;\n\t\t\tfor (i=0; i < num; i++) {\n\t\t\t\tif (done) break;\n\t\t\t\tdone = scan(fp, dptr, sep, NULL);\n\t\t\t\tif (done < -2) break;\n\t\t\t\tnread += 1;\n\t\t\t\tdptr += r->descr->elsize;\n\t\t\t}\n\t\t\tif (PyErr_Occurred()) {\n\t\t\t\tPy_DECREF(r);\n\t\t\t\treturn NULL;\n\t\t\t}\n\t\t}\n\t\telse { /* we have to watch for the end of the file and \n\t\t\t reallocate at the end */\n#define _FILEBUFNUM 4096\n\t\t\tintp thisbuf=0;\n\t\t\tintp size = _FILEBUFNUM;\n\t\t\tintp bytes;\n\t\t\tintp totalbytes;\n\n\t\t\tr = (PyArrayObject *)\\\n\t\t\t\tPyArray_NewFromDescr(&PyArray_Type, \n\t\t\t\t\t\t typecode,\n\t\t\t\t\t\t 1, &size, \n\t\t\t\t\t\t NULL, NULL, \n\t\t\t\t\t\t 0, NULL);\n\t\t\tif (r==NULL) return NULL;\n\t\t\ttotalbytes = bytes = size * typecode->elsize;\n\t\t\tdptr = r->data;\n\t\t\twhile (!done) {\n\t\t\t\tdone = scan(fp, dptr, sep, NULL);\n\n\t\t\t\t/* end of file reached trying to \n\t\t\t\t scan value. done is 1 or 2\n\t\t\t\t if end of file reached trying to\n\t\t\t\t scan separator. Still good value.\n\t\t\t\t*/\n\t\t\t\tif (done < -2) break;\n\t\t\t\tthisbuf += 1;\n\t\t\t\tnread += 1;\n\t\t\t\tdptr += r->descr->elsize;\n\t\t\t\tif (!done && thisbuf == size) {\n\t\t\t\t\ttotalbytes += bytes;\n\t\t\t\t\tr->data = PyDataMem_RENEW(r->data, \n\t\t\t\t\t\t\t\t totalbytes);\n\t\t\t\t\tdptr = r->data + (totalbytes - bytes);\n\t\t\t\t\tthisbuf = 0;\n\t\t\t\t}\n\t\t\t}\n\t\t\tif (PyErr_Occurred()) {\n\t\t\t\tPy_DECREF(r);\n\t\t\t\treturn NULL;\n\t\t\t}\n\t\t\tr->data = PyDataMem_RENEW(r->data, nread*r->descr->elsize);\n\t\t\tPyArray_DIM(r,0) = nread;\n\t\t\tnum = nread;\n#undef _FILEBUFNUM\n\t\t}\n\t}\n\tif (nread < num) {\n\t\tfprintf(stderr, \"%ld items requested but only %ld read\\n\", \n\t\t\t(long) num, (long) nread);\n\t\tr->data = PyDataMem_RENEW(r->data, nread * r->descr->elsize);\n\t\tPyArray_DIM(r,0) = nread;\n\t}\n\treturn (PyObject *)r;\n}\n\nstatic char doc_fromfile[] = \\\n\t\"fromfile(file=, dtype=int, count=-1, sep='')\\n\"\t\\\n\t\"\\n\"\\\n\t\" Return an array of the given data type from a \\n\"\\\n\t\" (text or binary) file. The file argument can be an open file\\n\"\\\n\t\" or a string with the name of a file to read from. If\\n\"\\\n\t\" count==-1, then the entire file is read, otherwise count is\\n\"\\\n\t\" the number of items of the given type read in. If sep is ''\\n\"\\\n\t\" then read a binary file, otherwise it gives the separator\\n\"\\\n\t\" between elements in a text file.\\n\"\\\n\t\"\\n\"\\\n\t\" WARNING: This function should be used sparingly, as it is not\\n\"\\\n\t\" a platform-independent method of persistence. But it can be \\n\"\\\n\t\" useful to read in simply-formatted or binary data quickly.\";\n\nstatic PyObject *\narray_fromfile(PyObject *ignored, PyObject *args, PyObject *keywds)\n{\n\tPyObject *file=NULL, *ret;\n\tFILE *fp;\n\tchar *sep=\"\";\n\tchar *mode=NULL;\n\tlonglong nin=-1;\n\tstatic char *kwlist[] = {\"file\", \"dtype\", \"count\", \"sep\", NULL};\n\tPyArray_Descr *type=NULL;\n\t\n\tif (!PyArg_ParseTupleAndKeywords(args, keywds, \"O|O&Ls\", kwlist, \n\t\t\t\t\t &file,\n\t\t\t\t\t PyArray_DescrConverter, &type,\n\t\t\t\t\t &nin, &sep)) {\n\t\treturn NULL;\n\t}\n\n\tif (type == NULL) type = PyArray_DescrFromType(PyArray_LONG);\n\n\tif (PyString_Check(file)) {\n\t\tif (sep == \"\") mode=\"rb\";\n\t\telse mode=\"r\";\n\t\tfile = PyFile_FromString(PyString_AS_STRING(file), mode);\n\t\tif (file==NULL) return NULL;\n\t}\n\telse {\n\t\tPy_INCREF(file);\n\t}\n\tfp = PyFile_AsFile(file);\n\tif (fp == NULL) {\n\t\tPyErr_SetString(PyExc_IOError, \n\t\t\t\t\"first argument must be an open file\");\n\t\tPy_DECREF(file);\n\t\treturn NULL;\n\t}\n\tret = PyArray_FromFile(fp, type, (intp) nin, sep);\n\tPy_DECREF(file);\n\treturn ret;\n}\n\n/*OBJECT_API*/\nstatic PyObject *\nPyArray_FromBuffer(PyObject *buf, PyArray_Descr *type, \n\t\t intp count, intp offset) \n{\n\tPyArrayObject *ret;\n\tchar *data;\n\tint ts;\n\tintp s, n;\n\tint itemsize;\n\tint write=1;\n\n\n\tif (type->type_num == PyArray_OBJECT) {\n\t\tPyErr_SetString(PyExc_ValueError, \n\t\t\t\t\"cannot create an OBJECT array from memory\"\\\n\t\t\t\t\" buffer\");\n\t\tPy_DECREF(type);\n\t\treturn NULL;\n\t}\n\tif (type->elsize == 0) {\n\t\tPyErr_SetString(PyExc_ValueError, \n\t\t\t\t\"itemsize cannot be zero in type\");\n\t\tPy_DECREF(type);\n\t\treturn NULL; \t\t\n\t}\n\n\tif (buf->ob_type->tp_as_buffer == NULL || \\\n\t (buf->ob_type->tp_as_buffer->bf_getwritebuffer == NULL &&\t\\\n\t buf->ob_type->tp_as_buffer->bf_getreadbuffer == NULL)) {\n\t\tPyObject *newbuf;\n\t\tnewbuf = PyObject_GetAttrString(buf, \"__buffer__\");\n\t\tif (newbuf == NULL) {Py_DECREF(type); return NULL;}\n\t\tbuf = newbuf;\n\t}\n\telse {Py_INCREF(buf);}\n\n\tif (PyObject_AsWriteBuffer(buf, (void *)&data, &ts)==-1) {\n\t\twrite = 0;\n\t\tPyErr_Clear();\n\t\tif (PyObject_AsReadBuffer(buf, (void *)&data, &ts)==-1) {\n\t\t\tPy_DECREF(buf);\n\t\t\tPy_DECREF(type);\n\t\t\treturn NULL;\n\t\t}\n\t}\n\t\n\tif ((offset < 0) || (offset >= ts)) {\n\t\tPyErr_Format(PyExc_ValueError,\n\t\t\t \"offset must be positive and smaller than %\"\n\t\t\t INTP_FMT, (intp)ts);\n\t}\n\n\tdata += offset;\n\ts = (intp)ts - offset;\n\tn = (intp)count;\n\titemsize = type->elsize;\n\t\n\tif (n < 0 ) {\n\t\tif (s % itemsize != 0) {\n\t\t\tPyErr_SetString(PyExc_ValueError, \n\t\t\t\t\t\"buffer size must be a multiple\"\\\n\t\t\t\t\t\" of element size\");\n\t\t\tPy_DECREF(buf);\n\t\t\tPy_DECREF(type);\n\t\t\treturn NULL;\n\t\t}\n\t\tn = s/itemsize;\n\t} else {\n\t\tif (s < n*itemsize) {\n\t\t\tPyErr_SetString(PyExc_ValueError, \n\t\t\t\t\t\"buffer is smaller than requested\"\\\n\t\t\t\t\t\" size\");\n\t\t\tPy_DECREF(buf);\n\t\t\tPy_DECREF(type);\n\t\t\treturn NULL;\n\t\t}\n\t}\n\t\n\tif ((ret = (PyArrayObject *)PyArray_NewFromDescr(&PyArray_Type, \n\t\t\t\t\t\t\t type, \n\t\t\t\t\t\t\t 1, &n, \n\t\t\t\t\t\t\t NULL, data, \n\t\t\t\t\t\t\t DEFAULT_FLAGS,\n\t\t\t\t\t\t\t NULL)) == NULL) {\n\t\tPy_DECREF(buf);\n\t\treturn NULL;\n\t}\n\t\n\tif (!write) ret->flags &= ~WRITEABLE;\n\n\t/* Store a reference for decref on deallocation */\n\tret->base = buf;\n\tPyArray_UpdateFlags(ret, ALIGNED);\n\treturn (PyObject *)ret;\n}\n\nstatic char doc_frombuffer[] = \\\n\t\"frombuffer(buffer=, dtype=int, count=-1, offset=0)\\n\"\\\n\t\"\\n\"\t\t\t\t\t\t\t\t\\\n\t\" Returns a 1-d array of data type dtype from buffer. The buffer\\n\"\\\n\t\" argument must be an object that exposes the buffer interface.\\n\"\\\n\t\" If count is -1 then the entire buffer is used, otherwise, count\\n\"\\\n\t\" is the size of the output. If offset is given then jump that\\n\"\\\n\t\" far into the buffer. If the buffer has data that is out\\n\" \\\n\t\" not in machine byte-order, than use a propert data type\\n\"\\\n\t\" descriptor. The data will not\\n\" \\\n\t\" be byteswapped, but the array will manage it in future\\n\"\\\n\t\" operations.\\n\";\n\nstatic PyObject *\narray_frombuffer(PyObject *ignored, PyObject *args, PyObject *keywds)\n{\n\tPyObject *obj=NULL;\n\tlonglong nin=-1, offset=0;\n\tstatic char *kwlist[] = {\"buffer\", \"dtype\", \"count\", \"offset\", NULL};\n\tPyArray_Descr *type=NULL;\n\n\tif (!PyArg_ParseTupleAndKeywords(args, keywds, \"O|O&LL\", kwlist, \n\t\t\t\t\t &obj,\n\t\t\t\t\t PyArray_DescrConverter, &type,\n\t\t\t\t\t &nin, &offset)) {\n\t\treturn NULL;\n\t}\n\tif (type==NULL)\n\t\ttype = PyArray_DescrFromType(PyArray_LONG);\n\t\n\treturn PyArray_FromBuffer(obj, type, (intp)nin, (intp)offset);\n}\n\n\nstatic char doc_concatenate[] = \"concatenate((a1,a2,...),axis=None).\";\n\nstatic PyObject *\narray_concatenate(PyObject *dummy, PyObject *args, PyObject *kwds) \n{\n\tPyObject *a0;\n\tint axis=0;\n\tstatic char *kwlist[] = {\"seq\", \"axis\", NULL};\n\t\n\tif (!PyArg_ParseTupleAndKeywords(args, kwds, \"O|O&\", kwlist,\n\t\t\t\t\t &a0,\n\t\t\t\t\t PyArray_AxisConverter, &axis))\n\t\treturn NULL;\n\treturn PyArray_Concatenate(a0, axis);\n}\n\nstatic char doc_innerproduct[] = \\\n\t\"inner(a,b) returns the dot product of two arrays, which has\\n\"\\\n\t\"shape a.shape[:-1] + b.shape[:-1] with elements computed by\\n\" \\\n\t\"the product of the elements from the last dimensions of a and b.\";\n\nstatic PyObject *array_innerproduct(PyObject *dummy, PyObject *args) {\n\tPyObject *b0, *a0;\n\t\n\tif (!PyArg_ParseTuple(args, \"OO\", &a0, &b0)) return NULL;\n\t\n\treturn _ARET(PyArray_InnerProduct(a0, b0));\n}\n\nstatic char doc_matrixproduct[] = \\\n\t\"dot(a,v) returns matrix-multiplication between a and b. \\n\"\\\n\t\"The product-sum is over the last dimension of a and the \\n\"\\\n\t\"second-to-last dimension of b.\";\n\nstatic PyObject *array_matrixproduct(PyObject *dummy, PyObject *args) {\n\tPyObject *v, *a;\n\t\n\tif (!PyArg_ParseTuple(args, \"OO\", &a, &v)) return NULL;\n\t\n\treturn _ARET(PyArray_MatrixProduct(a, v));\n}\n\nstatic char doc_fastCopyAndTranspose[] = \"_fastCopyAndTranspose(a)\";\n\nstatic PyObject *array_fastCopyAndTranspose(PyObject *dummy, PyObject *args) {\n\tPyObject *a0;\n\t\n\tif (!PyArg_ParseTuple(args, \"O\", &a0)) return NULL;\n\t\n\treturn _ARET(PyArray_CopyAndTranspose(a0));\n}\n\nstatic char doc_correlate[] = \"cross_correlate(a,v, mode=0)\";\n\nstatic PyObject *array_correlate(PyObject *dummy, PyObject *args, PyObject *kwds) {\n\tPyObject *shape, *a0;\n\tint mode=0;\n\tstatic char *kwlist[] = {\"a\", \"v\", \"mode\", NULL};\n\t\n\tif (!PyArg_ParseTupleAndKeywords(args, kwds, \"OO|i\", kwlist, \n\t\t\t\t\t &a0, &shape, &mode)) return NULL;\n\t\n\treturn PyArray_Correlate(a0, shape, mode);\n}\n\n\n/*MULTIARRAY_API\n Arange, \n*/\nstatic PyObject *\nPyArray_Arange(double start, double stop, double step, int type_num)\n{\n\tintp length;\n\tPyObject *range;\n\tPyArray_ArrFuncs *funcs;\n\tPyObject *obj;\n\tint ret;\n\n\tlength = (intp ) ceil((stop - start)/step);\n \n\tif (length <= 0) {\n\t\tlength = 0;\n\t\treturn PyArray_New(&PyArray_Type, 1, &length, type_num,\n\t\t\t\t NULL, NULL, 0, 0, NULL);\n\t}\n\n\trange = PyArray_New(&PyArray_Type, 1, &length, type_num, \n\t\t\t NULL, NULL, 0, 0, NULL);\n\tif (range == NULL) return NULL;\n\n\tfuncs = PyArray_DESCR(range)->f; \n\n\t/* place start in the buffer and the next value in the second position */\n\t/* if length > 2, then call the inner loop, otherwise stop */\n\n\tobj = PyFloat_FromDouble(start);\n\tret = funcs->setitem(obj, PyArray_DATA(range), (PyArrayObject *)range);\n\tPy_DECREF(obj);\n\tif (ret < 0) goto fail;\n\tif (length == 1) return range;\n\n\tobj = PyFloat_FromDouble(start + step);\n\tret = funcs->setitem(obj, PyArray_DATA(range)+PyArray_ITEMSIZE(range), \n\t\t\t (PyArrayObject *)range);\n\tPy_DECREF(obj);\n\tif (ret < 0) goto fail;\n\tif (length == 2) return range;\n\n\tif (!funcs->fill) {\n\t\tPyErr_SetString(PyExc_ValueError, \"no fill-function for data-type.\");\n\t\tPy_DECREF(range);\n\t\treturn NULL;\n\t}\n\tfuncs->fill(PyArray_DATA(range), length, (PyArrayObject *)range);\n\tif (PyErr_Occurred()) goto fail;\n\t\n\treturn range;\n\n fail:\n\tPy_DECREF(range);\n\treturn NULL;\n}\n\n/* the formula is \n len = (intp) ceil((start - stop) / step);\n*/\nstatic intp\n_calc_length(PyObject *start, PyObject *stop, PyObject *step, PyObject **next, int cmplx)\n{\n\tintp len;\n\tPyObject *val;\n\tdouble value;\n\t\n\t*next = PyNumber_Subtract(stop, start);\n\tif (!(*next)) return -1;\n\tval = PyNumber_TrueDivide(*next, step);\n\tPy_DECREF(*next); *next=NULL;\n\tif (!val) return -1;\n\tif (cmplx && PyComplex_Check(val)) {\n\t\tvalue = PyComplex_RealAsDouble(val);\n\t\tif (error_converting(value)) {Py_DECREF(val); return -1;}\n\t\tlen = (intp) ceil(value);\n\t\tvalue = PyComplex_ImagAsDouble(val);\n\t\tPy_DECREF(val);\n\t\tif (error_converting(value)) return -1;\n\t\tlen = MIN(len, (intp) ceil(value));\n\t}\n\telse {\n\t\tvalue = PyFloat_AsDouble(val);\n\t\tPy_DECREF(val);\n\t\tif (error_converting(value)) return -1;\n\t\tlen = (intp) ceil(value);\n\t}\n\t\n\tif (len > 0) {\n\t\t*next = PyNumber_Add(start, step);\n\t\tif (!next) return -1;\n\t}\n\treturn len;\n}\n\n/* this doesn't change the references */\n/*MULTIARRAY_API\n ArangeObj,\n*/\nstatic PyObject *\nPyArray_ArangeObj(PyObject *start, PyObject *stop, PyObject *step, PyArray_Descr *dtype) \n{\n\tPyObject *range;\n\tPyArray_ArrFuncs *funcs;\n\tPyObject *next;\n\tintp length;\n\n\tif (!dtype) {\n\t\tPyArray_Descr *deftype;\n\t\tPyArray_Descr *newtype;\n\t\tdeftype = PyArray_DescrFromType(PyArray_LONG);\n\t\tnewtype = PyArray_DescrFromObject(start, deftype);\n\t\tPy_DECREF(deftype);\n\t\tdeftype = newtype;\n\t\tif (stop && stop != Py_None) {\n\t\t\tnewtype = PyArray_DescrFromObject(stop, deftype);\n\t\t\tPy_DECREF(deftype);\n\t\t\tdeftype = newtype;\n\t\t}\n\t\tif (step && step != Py_None) {\n\t\t\tnewtype = PyArray_DescrFromObject(step, deftype);\n\t\t\tPy_DECREF(deftype);\n\t\t\tdeftype = newtype;\n\t\t}\n\t\tdtype = deftype;\n\t}\n\telse Py_INCREF(dtype);\n\n\tif (!step || step == Py_None) {\n\t\tstep = PyInt_FromLong(1);\n\t}\n\telse Py_XINCREF(step);\n\n\tif (!stop || stop == Py_None) {\n\t\tstop = start;\n\t\tstart = PyInt_FromLong(0);\n\t}\n\telse Py_INCREF(start);\n\n\t/* calculate the length and next = start + step*/\n\tlength = _calc_length(start, stop, step, &next, \n\t\t\t PyTypeNum_ISCOMPLEX(dtype->type_num));\n\n\tif (PyErr_Occurred()) {Py_DECREF(dtype); goto fail;}\n\tif (length <= 0) {\n\t\tlength = 0;\n\t\trange = PyArray_SimpleNewFromDescr(1, &length, dtype);\n\t\tPy_DECREF(step); Py_DECREF(start); return range;\n\t}\n\n\trange = PyArray_SimpleNewFromDescr(1, &length, dtype);\n\tif (range == NULL) goto fail;\n\n\tfuncs = PyArray_DESCR(range)->f;\n\n\t/* place start in the buffer and the next value in the second position */\n\t/* if length > 2, then call the inner loop, otherwise stop */\n\n\tif (funcs->setitem(start, PyArray_DATA(range), (PyArrayObject *)range) < 0)\n\t\tgoto fail;\n\tif (length == 1) goto finish;\n\tif (funcs->setitem(next, PyArray_DATA(range)+PyArray_ITEMSIZE(range), \n\t\t\t (PyArrayObject *)range) < 0) goto fail;\n\tif (length == 2) goto finish;\n\n\tif (!funcs->fill) {\n\t\tPyErr_SetString(PyExc_ValueError, \"no fill-function for data-type.\");\n\t\tPy_DECREF(range);\n\t\tgoto fail;\n\t}\n\tfuncs->fill(PyArray_DATA(range), length, (PyArrayObject *)range);\n\tif (PyErr_Occurred()) goto fail;\n\n finish:\n\tPy_DECREF(start);\n\tPy_DECREF(step);\n\tPy_DECREF(next);\n\treturn range;\n\t\n fail:\n\tPy_DECREF(start);\n\tPy_DECREF(step);\n\tPy_XDECREF(next);\n\treturn NULL;\n}\n\n\nstatic char doc_arange[] = \"arange(start, stop=None, step=1, dtype=int)\\n\\n Just like range() except it returns an array whose type can be\\n specified by the keyword argument typecode.\";\n\nstatic PyObject *\narray_arange(PyObject *ignored, PyObject *args, PyObject *kws) {\n\tPyObject *o_start=NULL, *o_stop=NULL, *o_step=NULL;\n\tstatic char *kwd[]= {\"start\", \"stop\", \"step\", \"dtype\", NULL};\n\tPyArray_Descr *typecode=NULL;\n\t\n\tif(!PyArg_ParseTupleAndKeywords(args, kws, \"O|OOO&\", kwd, &o_start,\n\t\t\t\t\t&o_stop, &o_step, \n\t\t\t\t\tPyArray_DescrConverter2,\n\t\t\t\t\t&typecode)) \n\t\treturn NULL;\n\n\treturn PyArray_ArangeObj(o_start, o_stop, o_step, typecode);\n}\n\n/*MULTIARRAY_API\n GetNDArrayCVersion\n*/\nstatic unsigned int\nPyArray_GetNDArrayCVersion(void)\n{\n\treturn (unsigned int)NDARRAY_VERSION;\n}\n\nstatic char \ndoc__get_ndarray_c_version[] = \"_get_ndarray_c_version() gets the compile time NDARRAY_VERSION number\";\n\nstatic PyObject *\narray__get_ndarray_c_version(PyObject *dummy, PyObject *args, PyObject *kwds) \n{\n\tstatic char *kwlist[] = {NULL};\n\tif(!PyArg_ParseTupleAndKeywords(args, kwds, \"\", kwlist )) return NULL;\n\t\n\treturn PyInt_FromLong( (long) PyArray_GetNDArrayCVersion() );\n}\n\nstatic char \ndoc_set_string_function[] = \"set_string_function(f, repr=1) sets the python function f to be the function used to obtain a pretty printable string version of a array whenever a array is printed. f(M) should expect a array argument M, and should return a string consisting of the desired representation of M for printing.\";\n\nstatic PyObject *\narray_set_string_function(PyObject *dummy, PyObject *args, PyObject *kwds) \n{\n\tPyObject *op;\n\tint repr=1;\n\tstatic char *kwlist[] = {\"f\", \"repr\", NULL};\n\n\tif(!PyArg_ParseTupleAndKeywords(args, kwds, \"O|i\", kwlist, \n\t\t\t\t\t&op, &repr)) return NULL; \n\tif (!PyCallable_Check(op)) {\n\t\tPyErr_SetString(PyExc_TypeError, \n\t\t\t\t\"Argument must be callable.\");\n\t\treturn NULL;\n\t}\n\tPyArray_SetStringFunction(op, repr);\n\tPy_INCREF(Py_None);\n\treturn Py_None;\n}\n\nstatic char \ndoc_set_ops_function[] = \"set_numeric_ops(op=func, ...) sets some or all of the number methods for all array objects. Don't forget **dict can be used as the argument list. Returns the functions that were replaced -- can be stored and set later.\";\n\nstatic PyObject *\narray_set_ops_function(PyObject *self, PyObject *args, PyObject *kwds) \n{\n\tPyObject *oldops=NULL;\n\t\n\tif ((oldops = PyArray_GetNumericOps())==NULL) return NULL;\n\n\t/* Should probably ensure that objects are at least callable */\n\t/* Leave this to the caller for now --- error will be raised\n\t later when use is attempted \n\t*/\n\tif (kwds && PyArray_SetNumericOps(kwds) == -1) {\n\t\tPy_DECREF(oldops);\n\t\tPyErr_SetString(PyExc_ValueError, \n\t\t\t\t\"one or more objects not callable\");\n\t\treturn NULL;\n\t}\n\treturn oldops;\n}\n\n\n/*MULTIARRAY_API\n Where\n*/\nstatic PyObject *\nPyArray_Where(PyObject *condition, PyObject *x, PyObject *y)\n{\n\tPyArrayObject *arr;\n\tPyObject *tup=NULL, *obj=NULL;\n\tPyObject *ret=NULL, *zero=NULL;\n\n\n\tarr = (PyArrayObject *)PyArray_FromAny(condition, NULL, 0, 0, 0, NULL);\n\tif (arr == NULL) return NULL;\n\n\tif ((x==NULL) && (y==NULL)) {\n\t\tret = PyArray_Nonzero(arr);\n\t\tPy_DECREF(arr);\n\t\treturn ret;\n\t}\n\n\tif ((x==NULL) || (y==NULL)) {\n\t\tPy_DECREF(arr);\n\t\tPyErr_SetString(PyExc_ValueError, \"either both or neither \"\n\t\t\t\t\"of x and y should be given\");\n\t\treturn NULL;\n\t}\n\n\n\tzero = PyInt_FromLong((long) 0);\n\n\tobj = PyArray_EnsureArray(PyArray_GenericBinaryFunction(arr, zero, \n\t\t\t\t\t\t\t\tn_ops.not_equal));\n\tPy_DECREF(zero);\n\tPy_DECREF(arr);\n\tif (obj == NULL) return NULL;\n\n\ttup = Py_BuildValue(\"(OO)\", y, x);\n\tif (tup == NULL) {Py_DECREF(obj); return NULL;}\n\n\tret = PyArray_Choose((PyAO *)obj, tup);\n\n\tPy_DECREF(obj);\n\tPy_DECREF(tup);\n\treturn ret;\n}\n\nstatic char doc_where[] = \"where(condition, | x, y) is shaped like condition\"\\\n\t\" and has elements of x and y where condition is respectively true or\"\\\n\t\" false. If x or y are not given, then it is equivalent to\"\\\n\t\" nonzero(condition).\";\n\nstatic PyObject *\narray_where(PyObject *ignored, PyObject *args)\n{\n\tPyObject *obj=NULL, *x=NULL, *y=NULL;\n\t\n\tif (!PyArg_ParseTuple(args, \"O|OO\", &obj, &x, &y)) return NULL;\n\n\treturn PyArray_Where(obj, x, y);\n\n}\n\nstatic char doc_lexsort[] = \"lexsort(keys=, axis=-1) returns an array of indexes\"\\\n\t\" similar to argsort except the sorting is done using the provided sorting\"\\\n\t\" keys. First the sort is done using key[0], then the resulting list of\"\\\n\t\" indexes is further manipulated by sorting on key[0]. And so forth\"\\\n\t\" The result is a sort on multiple keys. If the keys represented columns\" \\\n\t\" of a spread-sheet, for example, this would sort using multiple columns.\"\\\n\t\" The keys argument must be a tuple of things that can be converted to \"\\\n\t\" arrays of the same shape.\";\n\nstatic PyObject *\narray_lexsort(PyObject *ignored, PyObject *args, PyObject *kwds)\n{\n\tint axis=-1;\n\tPyObject *obj;\n\tstatic char *kwlist[] = {\"keys\", \"axis\", NULL};\n\t\n\tif (!PyArg_ParseTupleAndKeywords(args, kwds, \"O!|i\", kwlist, \n\t\t\t\t\t &PyTuple_Type, &obj, &axis)) return NULL;\n\t\n\treturn _ARET(PyArray_LexSort(obj, axis));\n}\n\n#undef _ARET\n\n\nstatic char doc_register_dtype[] = \\\n\t\"register_dtype(a) registers a new type object -- gives it a typenum\";\n\nstatic PyObject *\narray_register_dtype(PyObject *dummy, PyObject *args)\n{\n\tPyObject *dtype;\n\tint ret;\n\t\n\tif (!PyArg_ParseTuple(args, \"O\", &dtype)) return NULL;\n\t\n\tret = PyArray_RegisterDataType((PyTypeObject *)dtype);\n\tif (ret < 0)\n\t\treturn NULL;\n\treturn PyInt_FromLong((long) ret);\n}\n\nstatic char doc_can_cast_safely[] = \\\n\t\"can_cast_safely(from=d1, to=d2) returns True if data type d1 \"\\\n\t\"can be cast to data type d2 without losing precision.\";\n\nstatic PyObject *\narray_can_cast_safely(PyObject *dummy, PyObject *args, PyObject *kwds)\n{\n\tPyArray_Descr *d1=NULL;\n\tPyArray_Descr *d2=NULL;\n\tBool ret;\n\tPyObject *retobj;\n\tstatic char *kwlist[] = {\"from\", \"to\", NULL};\n\n\tif(!PyArg_ParseTupleAndKeywords(args, kwds, \"O&O&\", kwlist, \n\t\t\t\t\tPyArray_DescrConverter, &d1,\n\t\t\t\t\tPyArray_DescrConverter, &d2))\n\t\treturn NULL;\n\tif (d1 == NULL || d2 == NULL) {\n\t\tPyErr_SetString(PyExc_TypeError, \n\t\t\t\t\"did not understand one of the types; \"\t\\\n\t\t\t\t\"'None' not accepted\");\n\t\treturn NULL;\n\t}\n\t\t\n\tret = PyArray_CanCastTo(d1, d2);\n\tretobj = (ret ? Py_True : Py_False);\n\tPy_INCREF(retobj);\n\treturn retobj;\n}\n\nstatic char doc_new_buffer[] = \\\n\t\"newbuffer(size) return a new uninitialized buffer object of size \"\n\t\"bytes\";\n\nstatic PyObject *\nnew_buffer(PyObject *dummy, PyObject *args)\n{\n\tint size;\n\n\tif(!PyArg_ParseTuple(args, \"i\", &size))\n\t\treturn NULL;\n\t\n\treturn PyBuffer_New(size);\n}\n\nstatic char doc_buffer_buffer[] = \\\n\t\"getbuffer(obj [,offset[, size]]) create a buffer object from the \"\\\n\t\"given object\\n referencing a slice of length size starting at \"\\\n\t\"offset. Default\\n is the entire buffer. A read-write buffer is \"\\\n\t\"attempted followed by a read-only buffer.\";\n\nstatic PyObject *\nbuffer_buffer(PyObject *dummy, PyObject *args, PyObject *kwds)\n{\n\tPyObject *obj;\n\tint offset=0, size=Py_END_OF_BUFFER, n;\n\tvoid *unused;\n\tstatic char *kwlist[] = {\"object\", \"offset\", \"size\", NULL};\n\t\n\tif (!PyArg_ParseTupleAndKeywords(args, kwds, \"O|ii\", kwlist, \n\t\t\t\t\t &obj, &offset, &size))\n\t\treturn NULL;\n\n\n\tif (PyObject_AsWriteBuffer(obj, &unused, &n) < 0) {\n\t\tPyErr_Clear();\n\t\treturn PyBuffer_FromObject(obj, offset, size);\t\t\n\t}\n\telse\n\t\treturn PyBuffer_FromReadWriteObject(obj, offset, size);\n}\n\n\nstatic struct PyMethodDef array_module_methods[] = {\n\t{\"_get_ndarray_c_version\", (PyCFunction)array__get_ndarray_c_version, \n\t METH_VARARGS|METH_KEYWORDS, doc__get_ndarray_c_version},\n\t{\"set_string_function\", (PyCFunction)array_set_string_function, \n\t METH_VARARGS|METH_KEYWORDS, doc_set_string_function},\n\t{\"set_numeric_ops\", (PyCFunction)array_set_ops_function,\n\t METH_VARARGS|METH_KEYWORDS, doc_set_ops_function},\n\t{\"set_typeDict\", (PyCFunction)array_set_typeDict,\n\t METH_VARARGS, doc_set_typeDict},\n\n\t{\"array\",\t(PyCFunction)_array_fromobject, \n\t METH_VARARGS|METH_KEYWORDS, doc_fromobject},\n\t{\"arange\", (PyCFunction)array_arange, \n\t METH_VARARGS|METH_KEYWORDS, doc_arange},\n\t{\"zeros\",\t(PyCFunction)array_zeros, \n\t METH_VARARGS|METH_KEYWORDS, doc_zeros},\n\t{\"empty\",\t(PyCFunction)array_empty, \n\t METH_VARARGS|METH_KEYWORDS, doc_empty},\n\t{\"scalar\", (PyCFunction)array_scalar,\n\t METH_VARARGS|METH_KEYWORDS, doc_scalar},\n\t{\"where\", (PyCFunction)array_where,\n\t METH_VARARGS, doc_where},\n\t{\"lexsort\", (PyCFunction)array_lexsort,\n\t METH_VARARGS | METH_KEYWORDS, doc_lexsort},\n\t{\"fromstring\",(PyCFunction)array_fromString,\n\t METH_VARARGS|METH_KEYWORDS, doc_fromString},\n\t{\"concatenate\", (PyCFunction)array_concatenate, \n\t METH_VARARGS|METH_KEYWORDS, doc_concatenate},\n\t{\"inner\", (PyCFunction)array_innerproduct, \n\t METH_VARARGS, doc_innerproduct}, \n\t{\"dot\", (PyCFunction)array_matrixproduct, \n\t METH_VARARGS, doc_matrixproduct}, \n\t{\"_fastCopyAndTranspose\", (PyCFunction)array_fastCopyAndTranspose, \n\t METH_VARARGS, doc_fastCopyAndTranspose},\n\t{\"correlate\", (PyCFunction)array_correlate, \n\t METH_VARARGS | METH_KEYWORDS, doc_correlate},\n\t{\"frombuffer\", (PyCFunction)array_frombuffer,\n\t METH_VARARGS | METH_KEYWORDS, doc_frombuffer},\n\t{\"fromfile\", (PyCFunction)array_fromfile,\n\t METH_VARARGS | METH_KEYWORDS, doc_fromfile},\n\t{\"register_dtype\", (PyCFunction)array_register_dtype,\n\t METH_VARARGS, doc_register_dtype},\n\t{\"can_cast\", (PyCFunction)array_can_cast_safely,\n\t METH_VARARGS | METH_KEYWORDS, doc_can_cast_safely},\t\t\n\t{\"newbuffer\", (PyCFunction)new_buffer,\n\t METH_VARARGS, doc_new_buffer},\t\n\t{\"getbuffer\", (PyCFunction)buffer_buffer,\n\t METH_VARARGS | METH_KEYWORDS, doc_buffer_buffer},\t\n\t{NULL,\t\tNULL, 0}\t\t/* sentinel */\n};\n\n#include \"__multiarray_api.c\"\n\n/* Establish scalar-type hierarchy */\n\n/* For dual inheritance we need to make sure that the objects being\n inherited from have the tp->mro object initialized. This is\n not necessarily true for the basic type objects of Python (it is \n checked for single inheritance but not dual in PyType_Ready).\n\n Thus, we call PyType_Ready on the standard Python Types, here.\n*/ \nstatic int\nsetup_scalartypes(PyObject *dict)\n{\n\n\tinitialize_numeric_types();\n\n if (PyType_Ready(&PyBool_Type) < 0) return -1;\n if (PyType_Ready(&PyInt_Type) < 0) return -1;\n if (PyType_Ready(&PyFloat_Type) < 0) return -1;\n if (PyType_Ready(&PyComplex_Type) < 0) return -1;\n if (PyType_Ready(&PyString_Type) < 0) return -1;\n if (PyType_Ready(&PyUnicode_Type) < 0) return -1;\n\n#define SINGLE_INHERIT(child, parent) \\\n Py##child##ArrType_Type.tp_base = &Py##parent##ArrType_Type;\t\\\n if (PyType_Ready(&Py##child##ArrType_Type) < 0) {\t\t\\\n PyErr_Print(); \\\n PyErr_Format(PyExc_SystemError, \\\n\t\t\t \"could not initialize Py%sArrType_Type\", \\\n #child); \\\n return -1;\t\t\t\t\t\t\\\n }\n \n if (PyType_Ready(&PyGenericArrType_Type) < 0)\n return -1;\n\n SINGLE_INHERIT(Number, Generic);\n SINGLE_INHERIT(Integer, Number);\n SINGLE_INHERIT(Inexact, Number);\n SINGLE_INHERIT(SignedInteger, Integer);\n SINGLE_INHERIT(UnsignedInteger, Integer);\n SINGLE_INHERIT(Floating, Inexact);\n SINGLE_INHERIT(ComplexFloating, Inexact);\n SINGLE_INHERIT(Flexible, Generic);\n SINGLE_INHERIT(Character, Flexible);\n\t\n#define DUAL_INHERIT(child, parent1, parent2) \\\n Py##child##ArrType_Type.tp_base = &Py##parent2##ArrType_Type;\t\\\n Py##child##ArrType_Type.tp_bases = \\\n Py_BuildValue(\"(OO)\", &Py##parent2##ArrType_Type,\t\\\n\t\t\t &Py##parent1##_Type);\t\t\t\\\n if (PyType_Ready(&Py##child##ArrType_Type) < 0) { \\\n PyErr_Print(); \\\n\t\tPyErr_Format(PyExc_SystemError, \\\n\t\t\t \"could not initialize Py%sArrType_Type\", \\\n #child); \\\n return -1; \\\n }\\\n Py##child##ArrType_Type.tp_hash = Py##parent1##_Type.tp_hash;\n\n#define DUAL_INHERIT2(child, parent1, parent2)\t\t\t\t\\\n Py##child##ArrType_Type.tp_base = &Py##parent1##_Type;\t\t\\\n Py##child##ArrType_Type.tp_bases = \\\n Py_BuildValue(\"(OO)\", &Py##parent1##_Type,\t\t\\\n\t\t\t &Py##parent2##ArrType_Type);\t\t\\\n\tPy##child##ArrType_Type.tp_richcompare =\t\t\t\\\n\t\tPy##parent1##_Type.tp_richcompare;\t\t\t\\\n\tPy##child##ArrType_Type.tp_compare =\t\t\t\t\\\n\t\tPy##parent1##_Type.tp_compare;\t\t\t\t\\\n Py##child##ArrType_Type.tp_hash = Py##parent1##_Type.tp_hash;\t\\\n if (PyType_Ready(&Py##child##ArrType_Type) < 0) { \\\n PyErr_Print(); \\\n\t\tPyErr_Format(PyExc_SystemError, \\\n\t\t\t \"could not initialize Py%sArrType_Type\", \\\n #child); \\\n return -1; \\\n }\n\n SINGLE_INHERIT(Bool, Generic);\n SINGLE_INHERIT(Byte, SignedInteger);\n SINGLE_INHERIT(Short, SignedInteger);\n#if SIZEOF_INT == SIZEOF_LONG\n DUAL_INHERIT(Int, Int, SignedInteger);\n#else\n SINGLE_INHERIT(Int, SignedInteger);\n#endif\n DUAL_INHERIT(Long, Int, SignedInteger);\n#if SIZEOF_LONGLONG == SIZEOF_LONG\n DUAL_INHERIT(LongLong, Int, SignedInteger);\n#else\n SINGLE_INHERIT(LongLong, SignedInteger);\n#endif\n\n /* fprintf(stderr, \"tp_free = %p, PyObject_Del = %p, int_tp_free = %p, base.tp_free = %p\\n\", PyIntArrType_Type.tp_free, PyObject_Del, PyInt_Type.tp_free, PySignedIntegerArrType_Type.tp_free);\n\t */\n\tSINGLE_INHERIT(UByte, UnsignedInteger);\n SINGLE_INHERIT(UShort, UnsignedInteger);\n SINGLE_INHERIT(UInt, UnsignedInteger);\n SINGLE_INHERIT(ULong, UnsignedInteger);\n SINGLE_INHERIT(ULongLong, UnsignedInteger);\n\n SINGLE_INHERIT(Float, Floating);\n DUAL_INHERIT(Double, Float, Floating);\n SINGLE_INHERIT(LongDouble, Floating);\n\n SINGLE_INHERIT(CFloat, ComplexFloating);\n DUAL_INHERIT(CDouble, Complex, ComplexFloating);\n SINGLE_INHERIT(CLongDouble, ComplexFloating);\n\n DUAL_INHERIT2(String, String, Character);\n DUAL_INHERIT2(Unicode, Unicode, Character);\n\t\n SINGLE_INHERIT(Void, Flexible);\n \n SINGLE_INHERIT(Object, Generic);\n\n return 0;\n\n#undef SINGLE_INHERIT\n#undef DUAL_INHERIT\n\n\t/* Clean up string and unicode array types so they act more like\n\t strings -- get their tables from the standard types.\n\t*/\n}\n\n/* place a flag dictionary in d */\n\nstatic void\nset_flaginfo(PyObject *d)\n{\n PyObject *s;\n PyObject *newd;\n \n newd = PyDict_New();\n\n PyDict_SetItemString(newd, \"OWNDATA\", s=PyInt_FromLong(OWNDATA));\n Py_DECREF(s);\n PyDict_SetItemString(newd, \"FORTRAN\", s=PyInt_FromLong(FORTRAN));\n Py_DECREF(s);\n PyDict_SetItemString(newd, \"CONTIGUOUS\", s=PyInt_FromLong(CONTIGUOUS));\n Py_DECREF(s);\n PyDict_SetItemString(newd, \"ALIGNED\", s=PyInt_FromLong(ALIGNED));\n Py_DECREF(s);\n\n PyDict_SetItemString(newd, \"UPDATEIFCOPY\", s=PyInt_FromLong(UPDATEIFCOPY));\n Py_DECREF(s);\n PyDict_SetItemString(newd, \"WRITEABLE\", s=PyInt_FromLong(WRITEABLE));\n Py_DECREF(s);\n \n PyDict_SetItemString(d, \"_flagdict\", newd);\n Py_DECREF(newd);\n return;\n}\n\n\n/* Initialization function for the module */\n\nDL_EXPORT(void) initmultiarray(void) {\n\tPyObject *m, *d, *s;\n\tPyObject *c_api;\n\t\n\t/* Create the module and add the functions */\n\tm = Py_InitModule(\"multiarray\", array_module_methods);\n\tif (!m) goto err;\n\n\t/* Add some symbolic constants to the module */\n\td = PyModule_GetDict(m);\n\tif (!d) goto err; \n\n\t/* Create the module and add the functions */\n\tif (PyType_Ready(&PyBigArray_Type) < 0) \n\t\treturn;\n\n PyArray_Type.tp_base = &PyBigArray_Type;\n\n PyArray_Type.tp_as_mapping = &array_as_mapping;\n\t/* Even though, this would be inherited, it needs to be set now\n\t so that the __getitem__ will map to the as_mapping descriptor\n\t*/\n PyArray_Type.tp_as_number = &array_as_number; \n\t/* For good measure */\n\tPyArray_Type.tp_as_sequence = &array_as_sequence;\n\tPyArray_Type.tp_as_buffer = &array_as_buffer;\t\n PyArray_Type.tp_flags = (Py_TPFLAGS_DEFAULT \n\t\t\t\t | Py_TPFLAGS_BASETYPE\n\t\t\t\t | Py_TPFLAGS_CHECKTYPES);\n PyArray_Type.tp_doc = Arraytype__doc__;\n\n\tif (PyType_Ready(&PyArray_Type) < 0)\n return;\n\n if (setup_scalartypes(d) < 0) goto err;\n\n\tPyArrayIter_Type.tp_iter = PyObject_SelfIter;\n\tPyArrayMultiIter_Type.tp_iter = PyObject_SelfIter;\n\tif (PyType_Ready(&PyArrayIter_Type) < 0)\n\t\treturn; \n \n\tif (PyType_Ready(&PyArrayMapIter_Type) < 0)\n return; \n\n\tif (PyType_Ready(&PyArrayMultiIter_Type) < 0)\n\t\treturn;\n\n\tif (PyType_Ready(&PyArrayDescr_Type) < 0)\n\t\treturn;\n\n\tc_api = PyCObject_FromVoidPtr((void *)PyArray_API, NULL);\n\tif (PyErr_Occurred()) goto err;\n\tPyDict_SetItemString(d, \"_ARRAY_API\", c_api);\n\tPy_DECREF(c_api);\n\tif (PyErr_Occurred()) goto err;\n\n\tMultiArrayError = PyString_FromString (\"multiarray.error\");\n\tPyDict_SetItemString (d, \"error\", MultiArrayError);\n\t\n\ts = PyString_FromString(\"3.0\");\n\tPyDict_SetItemString(d, \"__version__\", s);\n\tPy_DECREF(s);\n Py_INCREF(&PyBigArray_Type);\n\tPyDict_SetItemString(d, \"bigndarray\", (PyObject *)&PyBigArray_Type);\n Py_INCREF(&PyArray_Type);\n\tPyDict_SetItemString(d, \"ndarray\", (PyObject *)&PyArray_Type);\n Py_INCREF(&PyArrayIter_Type);\n\tPyDict_SetItemString(d, \"flatiter\", (PyObject *)&PyArrayIter_Type);\n Py_INCREF(&PyArrayMultiIter_Type);\n\tPyDict_SetItemString(d, \"broadcast\", \n\t\t\t (PyObject *)&PyArrayMultiIter_Type);\n\tPy_INCREF(&PyArrayDescr_Type);\n\tPyDict_SetItemString(d, \"dtype\", (PyObject *)&PyArrayDescr_Type);\n\n\t/* Doesn't need to be exposed to Python \n Py_INCREF(&PyArrayMapIter_Type);\n\tPyDict_SetItemString(d, \"mapiter\", (PyObject *)&PyArrayMapIter_Type);\n\t*/\n set_flaginfo(d);\n\n\tif (set_typeinfo(d) != 0) goto err;\n\n\t_numpy_internal =\t\t\t\t\t\t\\\n\t\tPyImport_ImportModule(\"numpy.core._internal\");\n\tif (_numpy_internal != NULL) return;\n\n err:\t\n\tif (!PyErr_Occurred()) {\n\t\tPyErr_SetString(PyExc_RuntimeError, \n\t\t\t\t\"cannot load multiarray module.\");\n\t}\n\treturn;\n}\n\n", + "source_code_before": "\n/*\n Python Multiarray Module -- A useful collection of functions for creating and\n using ndarrays\n\n Original file \n Copyright (c) 1995, 1996, 1997 Jim Hugunin, hugunin@mit.edu\n\n Modified for numpy_core in 2005 \n\n Travis E. Oliphant\n Assistant Professor at\n Brigham Young University\n \n*/\n\n/* $Id: multiarraymodule.c,v 1.36 2005/09/14 00:14:00 teoliphant Exp $ */\n\n#include \"Python.h\"\n#include \"structmember.h\"\n/*#include \n#include \n*/\n\n#define _MULTIARRAYMODULE\n#include \"numpy/arrayobject.h\"\n\n#define PyAO PyArrayObject\n\nstatic PyObject *typeDict=NULL; /* Must be explicitly loaded */\nstatic PyObject *_numpy_internal=NULL; /* A Python module for callbacks */\n\n\nstatic PyArray_Descr *\n_arraydescr_fromobj(PyObject *obj)\n{\n\tPyObject *dtypedescr;\n\tPyArray_Descr *new;\n\tint ret;\n\t\n\tdtypedescr = PyObject_GetAttrString(obj, \"dtype\");\n\tPyErr_Clear();\n\tif (dtypedescr) {\n\t\tret = PyArray_DescrConverter(dtypedescr, &new);\n\t\tPy_DECREF(dtypedescr);\n\t\tif (ret) return new;\n\t\tPyErr_Clear();\n\t}\n\treturn NULL;\n}\n\n\n/* Including this file is the only way I know how to declare functions\n static in each file, and store the pointers from functions in both\n arrayobject.c and multiarraymodule.c for the C-API \n\n Declarying an external pointer-containing variable in arrayobject.c\n and trying to copy it to PyArray_API, did not work.\n\n Think about two modules with a common api that import each other...\n\n This file would just be the module calls. \n*/\n\n#include \"arrayobject.c\"\n\n\n/* An Error object -- rarely used? */\nstatic PyObject *MultiArrayError;\n\n/*MULTIARRAY_API\n Multiply a List of ints\n*/\nstatic int\nPyArray_MultiplyIntList(register int *l1, register int n) \n{\n\tregister int s=1;\n while (n--) s *= (*l1++);\n return s;\n}\n\n/*MULTIARRAY_API\n Multiply a List\n*/\nstatic intp \nPyArray_MultiplyList(register intp *l1, register int n) \n{\n\tregister intp s=1;\n while (n--) s *= (*l1++);\n return s;\n}\n\n/*MULTIARRAY_API\n Produce a pointer into array\n*/\nstatic char *\nPyArray_GetPtr(PyArrayObject *obj, register intp* ind)\n{\n\tregister int n = obj->nd;\n\tregister intp *strides = obj->strides;\n\tregister char *dptr = obj->data;\n\t\n\twhile (n--) dptr += (*strides++) * (*ind++);\n\treturn dptr;\n}\n\n/*MULTIARRAY_API\n Get axis from an object (possibly None) -- a converter function,\n*/\nstatic int \nPyArray_AxisConverter(PyObject *obj, int *axis)\n{\n\tif (obj == Py_None) {\n\t\t*axis = MAX_DIMS;\n\t}\n\telse {\n\t\t*axis = (int) PyInt_AsLong(obj);\n\t\tif (PyErr_Occurred()) {\n\t\t\treturn PY_FAIL;\n\t\t}\n\t}\n\treturn PY_SUCCEED;\n}\n\n/*MULTIARRAY_API\n Compare Lists\n*/\nstatic int \nPyArray_CompareLists(intp *l1, intp *l2, int n) \n{\n int i;\n for(i=0;iob_type;\n\t\n\tPy_INCREF(self->descr);\n\tnew = PyArray_NewFromDescr(subtype,\n\t\t\t\t self->descr,\n\t\t\t\t self->nd, self->dimensions,\n\t\t\t\t self->strides,\n\t\t\t\t self->data,\n\t\t\t\t self->flags, (PyObject *)self);\n\t\n\tif (new==NULL) return NULL;\n\tPy_INCREF(self);\n PyArray_BASE(new) = (PyObject *)self;\n\t\n\tif (type != NULL) {\n\t\tif (PyObject_SetAttrString(new, \"dtype\",\n\t\t\t\t\t (PyObject *)type) < 0) {\n\t\t\tPy_DECREF(new);\n\t\t\tPy_DECREF(type);\n\t\t\treturn NULL;\n\t\t}\n\t\tPy_DECREF(type);\n\t}\n\treturn new;\t\n}\n\n/*MULTIARRAY_API\n Ravel\n*/\nstatic PyObject *\nPyArray_Ravel(PyArrayObject *a, int fortran)\n{\n\tPyArray_Dims newdim = {NULL,1};\n\tintp val[1] = {-1};\n\n\tif (fortran < 0) fortran = PyArray_ISFORTRAN(a);\n\n\tnewdim.ptr = val;\n\tif (!fortran && PyArray_ISCONTIGUOUS(a)) {\n\t\tif (a->nd == 1) {\n\t\t\tPy_INCREF(a);\n\t\t\treturn (PyObject *)a;\n\t\t}\n\t\treturn PyArray_Newshape(a, &newdim);\n\t}\n\telse\n\t return PyArray_Flatten(a, fortran);\n}\n\n/*MULTIARRAY_API\n Flatten\n*/\nstatic PyObject *\nPyArray_Flatten(PyArrayObject *a, int fortran)\n{\n\tPyObject *ret, *new;\n\tintp size;\n\n\tif (fortran < 0) fortran = PyArray_ISFORTRAN(a);\n\n\tsize = PyArray_SIZE(a);\n\tPy_INCREF(a->descr);\n\tret = PyArray_NewFromDescr(a->ob_type,\n\t\t\t\t a->descr,\n\t\t\t\t 1, &size,\n\t\t\t\t NULL,\n\t\t\t\t NULL,\n\t\t\t\t 0, (PyObject *)a);\n\t\n\tif (ret== NULL) return NULL;\n\tif (fortran) {\n\t\tnew = PyArray_Transpose(a, NULL);\n\t\tif (new == NULL) {\n\t\t\tPy_DECREF(ret);\n\t\t\treturn NULL;\n\t\t}\n\t}\n\telse {\n\t\tPy_INCREF(a);\n\t\tnew = (PyObject *)a;\n\t}\n\tif (PyArray_CopyInto((PyArrayObject *)ret, (PyArrayObject *)new) < 0) {\n\t\tPy_DECREF(ret);\n\t\tPy_DECREF(new);\n\t\treturn NULL;\n\t}\n\tPy_DECREF(new);\n\treturn ret;\n}\n\n\n/* For back-ward compatability *\n\n/ * Not recommended */\n\n/*MULTIARRAY_API\n Reshape an array\n*/\nstatic PyObject *\nPyArray_Reshape(PyArrayObject *self, PyObject *shape) \n{\n PyObject *ret;\n PyArray_Dims newdims;\n\n if (!PyArray_IntpConverter(shape, &newdims)) return NULL;\n ret = PyArray_Newshape(self, &newdims);\n PyDimMem_FREE(newdims.ptr);\n return ret;\n}\n\nstatic int\n_check_ones(PyArrayObject *self, int newnd, intp* newdims, intp *strides)\n{\n\tint nd;\n\tintp *dims;\n\tBool done=FALSE;\n\tint j, k;\n\n\tnd = self->nd;\n\tdims = self->dimensions;\n\n\tfor (k=0, j=0; !done && (jstrides[j];\n\t\t\tj++; k++;\n\t\t}\n\t\telse if ((kptr;\n PyArrayObject *ret;\n\tchar msg[] = \"total size of new array must be unchanged\";\n\tint n = newdims->len;\n Bool same;\n\tintp *strides = NULL;\n\tintp newstrides[MAX_DIMS];\n\n /* Quick check to make sure anything needs to be done */\n if (n == self->nd) {\n same = TRUE;\n i=0;\n while(same && i= 0) {\n\t\t\tif ((s_known == 0) || (s_original % s_known != 0)) {\n\t\t\t\tPyErr_SetString(PyExc_ValueError, msg);\n\t\t\t\treturn NULL;\n\t\t\t}\n\t\t\tdimensions[i_unknown] = s_original/s_known;\n\t\t} else {\n\t\t\tif (s_original != s_known) {\n\t\t\t\tPyErr_SetString(PyExc_ValueError, msg);\n\t\t\t\treturn NULL;\n\t\t\t}\n\t\t}\n\t}\n \n\tPy_INCREF(self->descr);\n\tret = (PyAO *)PyArray_NewFromDescr(self->ob_type,\n\t\t\t\t\t self->descr,\n\t\t\t\t\t n, dimensions,\n\t\t\t\t\t strides,\n\t\t\t\t\t self->data,\n\t\t\t\t\t self->flags, (PyObject *)self);\n\t\n\tif (ret== NULL) return NULL;\n\t\n Py_INCREF(self);\n ret->base = (PyObject *)self;\n\tPyArray_UpdateFlags(ret, CONTIGUOUS | FORTRAN);\n\t\n return (PyObject *)ret;\n}\n\n/* return a new view of the array object with all of its unit-length \n dimensions squeezed out if needed, otherwise\n return the same array.\n */\n\n/*MULTIARRAY_API*/\nstatic PyObject *\nPyArray_Squeeze(PyArrayObject *self)\n{\n\tint nd = self->nd;\n\tint newnd = nd;\n\tintp dimensions[MAX_DIMS];\n\tintp strides[MAX_DIMS];\n\tint i,j;\n\tPyObject *ret;\n\n\tif (nd == 0) {\n\t\tPy_INCREF(self);\n\t\treturn (PyObject *)self;\n\t}\n\tfor (j=0, i=0; idimensions[i] == 1) {\n\t\t\tnewnd -= 1;\n\t\t}\n\t\telse {\n\t\t\tdimensions[j] = self->dimensions[i];\n\t\t\tstrides[j++] = self->strides[i];\n\t\t}\n\t}\n\t\n\tPy_INCREF(self->descr);\n\tret = PyArray_NewFromDescr(self->ob_type, \n\t\t\t\t self->descr,\n\t\t\t\t newnd, dimensions, \n\t\t\t\t strides, self->data, \n\t\t\t\t self->flags,\n\t\t\t\t (PyObject *)self);\n\tif (ret == NULL) return NULL;\n\tPyArray_FLAGS(ret) &= ~OWN_DATA;\n\tPyArray_BASE(ret) = (PyObject *)self;\n\tPy_INCREF(self);\n\treturn (PyObject *)ret;\n}\n\n\n/*MULTIARRAY_API\n Mean\n*/\nstatic PyObject *\nPyArray_Mean(PyArrayObject *self, int axis, int rtype)\n{\n\tPyObject *obj1=NULL, *obj2=NULL;\n\tPyObject *new, *ret;\n\n\tif ((new = _check_axis(self, &axis, 0))==NULL) return NULL;\n\n\tobj1 = PyArray_GenericReduceFunction((PyAO *)new, n_ops.add, axis,\n\t\t\t\t\t rtype);\n\tobj2 = PyFloat_FromDouble((double) PyArray_DIM(new,axis));\n Py_DECREF(new);\n\tif (obj1 == NULL || obj2 == NULL) {\n\t\tPy_XDECREF(obj1);\n\t\tPy_XDECREF(obj2);\n\t\treturn NULL;\n\t}\n\n\tret = PyNumber_Divide(obj1, obj2);\n\tPy_DECREF(obj1);\n\tPy_DECREF(obj2);\n\treturn ret;\n}\n\n/* Set variance to 1 to by-pass square-root calculation and return variance */\n/*MULTIARRAY_API\n Std\n*/\nstatic PyObject *\nPyArray_Std(PyArrayObject *self, int axis, int rtype, int variance)\n{\n\tPyObject *obj1=NULL, *obj2=NULL, *new=NULL;\n\tPyObject *ret=NULL, *newshape=NULL;\n\tint i, n;\n\tintp val;\n\n\tif ((new = _check_axis(self, &axis, 0))==NULL) return NULL;\n\t\n\t/* Compute and reshape mean */\n\tobj1 = PyArray_EnsureArray(PyArray_Mean((PyAO *)new, axis, rtype));\n\tif (obj1 == NULL) {Py_DECREF(new); return NULL;} \n\tn = PyArray_NDIM(new);\n\tnewshape = PyTuple_New(n);\n\tif (newshape == NULL) {Py_DECREF(obj1); Py_DECREF(new); return NULL;}\n\tfor (i=0; ind != 1) {\n Py_DECREF(cond);\n PyErr_SetString(PyExc_ValueError, \n\t\t\t\t\"condition must be 1-d array\");\n return NULL;\n }\n\n res = PyArray_Nonzero(cond);\n Py_DECREF(cond);\n\tret = PyArray_Take(self, res, axis);\n\tPy_DECREF(res);\n\treturn ret;\n}\n\n/*MULTIARRAY_API\n Nonzero\n*/\nstatic PyObject *\nPyArray_Nonzero(PyArrayObject *self)\n{\n int n=self->nd, j;\n\tintp count=0, i, size;\n\tPyArrayIterObject *it=NULL;\n\tPyObject *ret=NULL, *item;\n\tintp *dptr[MAX_DIMS];\n\n\tit = (PyArrayIterObject *)PyArray_IterNew((PyObject *)self);\n\tif (it==NULL) return NULL;\n\n\tsize = it->size;\n\tfor (i=0; idescr->f->nonzero(it->dataptr, self)) count++;\n\t\tPyArray_ITER_NEXT(it);\n\t}\n\n\tPyArray_ITER_RESET(it);\n\tif (n==1) {\n\t\tret = PyArray_New(self->ob_type, 1, &count, PyArray_INTP, \n\t\t\t\t NULL, NULL, 0, 0, (PyObject *)self);\n\t\tif (ret == NULL) goto fail;\n\t\tdptr[0] = (intp *)PyArray_DATA(ret);\n\t\t\n\t\tfor (i=0; idescr->f->nonzero(it->dataptr, self)) \n\t\t\t\t*(dptr[0])++ = i;\n\t\t\tPyArray_ITER_NEXT(it);\n\t\t}\t\t\n\t}\n\telse {\n\t\tret = PyTuple_New(n);\n\t\tfor (j=0; job_type, 1, &count, \n\t\t\t\t\t PyArray_INTP, NULL, NULL, 0, 0,\n\t\t\t\t\t (PyObject *)self);\n\t\t\tif (item == NULL) goto fail;\n\t\t\tPyTuple_SET_ITEM(ret, j, item);\n\t\t\tdptr[j] = (intp *)PyArray_DATA(item);\n\t\t}\n\t\t\n\t\t/* reset contiguous so that coordinates gets updated */\n\t\tit->contiguous = 0;\n\t\tfor (i=0; idescr->f->nonzero(it->dataptr, self)) \n\t\t\t\tfor (j=0; jcoordinates[j];\n\t\t\tPyArray_ITER_NEXT(it);\n\t\t}\n\t}\n\n\tPy_DECREF(it);\n\treturn ret;\n\n fail:\n\tPy_XDECREF(ret);\n\tPy_XDECREF(it);\n\treturn NULL;\n \n}\n\n/*MULTIARRAY_API\n Clip\n*/\nstatic PyObject *\nPyArray_Clip(PyArrayObject *self, PyObject *min, PyObject *max)\n{\n\tPyObject *selector=NULL, *newtup=NULL, *ret=NULL;\n\tPyObject *res1=NULL, *res2=NULL, *res3=NULL;\n\tPyObject *two;\n\n\ttwo = PyInt_FromLong((long)2);\n\tres1 = PyArray_GenericBinaryFunction(self, max, n_ops.greater);\n\tres2 = PyArray_GenericBinaryFunction(self, min, n_ops.less);\n\tif ((res1 == NULL) || (res2 == NULL)) {\n\t\tPy_DECREF(two);\n\t\tPy_XDECREF(res1);\n\t\tPy_XDECREF(res2);\n\t}\n\tres3 = PyNumber_Multiply(two, res1);\n\tPy_DECREF(two); \n\tPy_DECREF(res1); \n\tif (res3 == NULL) return NULL;\n\n\tselector = PyArray_EnsureArray(PyNumber_Add(res2, res3));\n\tPy_DECREF(res2);\n\tPy_DECREF(res3);\n\tif (selector == NULL) return NULL;\n\n\tnewtup = Py_BuildValue(\"(OOO)\", (PyObject *)self, min, max);\n\tif (newtup == NULL) {Py_DECREF(selector); return NULL;}\n\tret = PyArray_Choose((PyAO *)selector, newtup);\n\tPy_DECREF(selector);\n\tPy_DECREF(newtup);\n\treturn ret;\n}\n\n/*MULTIARRAY_API\n Conjugate\n*/\nstatic PyObject *\nPyArray_Conjugate(PyArrayObject *self)\n{\n\tif (PyArray_ISCOMPLEX(self)) {\n\t\tPyObject *new;\n\t\tintp size, i;\n\t\t/* Make a copy */\n\t\tnew = PyArray_NewCopy(self, -1);\n\t\tif (new==NULL) return NULL;\n\t\tsize = PyArray_SIZE(new);\n\t\tif (self->descr->type_num == PyArray_CFLOAT) {\n\t\t\tcfloat *dptr = (cfloat *) PyArray_DATA(new);\n\t\t\tfor (i=0; iimag = -dptr->imag;\n\t\t\t\tdptr++;\n\t\t\t}\n\t\t}\n\t\telse if (self->descr->type_num == PyArray_CDOUBLE) {\n\t\t\tcdouble *dptr = (cdouble *)PyArray_DATA(new);\n\t\t\tfor (i=0; iimag = -dptr->imag;\n\t\t\t\tdptr++;\n\t\t\t}\n\t\t}\n\t\telse if (self->descr->type_num == PyArray_CLONGDOUBLE) {\n\t\t\tclongdouble *dptr = (clongdouble *)PyArray_DATA(new);\n\t\t\tfor (i=0; iimag = -dptr->imag;\n\t\t\t\tdptr++;\n\t\t\t}\t\t\t\n\t\t}\t\t\n\t\treturn new;\n\t}\n\telse {\n\t\tPy_INCREF(self);\n\t\treturn (PyObject *) self;\n\t}\n}\n\n/*MULTIARRAY_API\n Trace\n*/\nstatic PyObject *\nPyArray_Trace(PyArrayObject *self, int offset, int axis1, int axis2, \nint rtype)\n{\n\tPyObject *diag=NULL, *ret=NULL;\n\n\tdiag = PyArray_Diagonal(self, offset, axis1, axis2);\n\tif (diag == NULL) return NULL;\n\tret = PyArray_GenericReduceFunction((PyAO *)diag, n_ops.add, -1, rtype);\n\tPy_DECREF(diag);\n\treturn ret;\n}\n\n/*MULTIARRAY_API\n Diagonal\n*/\nstatic PyObject *\nPyArray_Diagonal(PyArrayObject *self, int offset, int axis1, int axis2)\n{\n\tint n = self->nd;\n\tPyObject *new;\n\tPyArray_Dims newaxes;\n\tintp dims[MAX_DIMS];\n\tint i, pos;\t\n\n\tnewaxes.ptr = dims;\n\tif (n < 2) {\n\t\tPyErr_SetString(PyExc_ValueError, \n\t\t\t\t\"array.ndim must be >= 2\");\n\t\treturn NULL;\n\t}\n\tif (axis1 < 0) axis1 += n;\n\tif (axis2 < 0) axis2 += n;\n\tif ((axis1 == axis2) || (axis1 < 0) || (axis1 >= n) ||\t\\\n\t (axis2 < 0) || (axis2 >= n)) {\n\t\tPyErr_Format(PyExc_ValueError, \"axis1(=%d) and axis2(=%d) \"\\\n\t\t\t \"must be different and within range (nd=%d)\",\n\t\t\t axis1, axis2, n);\n\t\treturn NULL;\n\t}\n \n\tnewaxes.len = n;\n\t/* insert at the end */\n\tnewaxes.ptr[n-2] = axis1;\n\tnewaxes.ptr[n-1] = axis2;\n\tpos = 0;\n\tfor (i=0; idimensions[0];\n\t\tn2 = self->dimensions[1];\n\t\tstep = n2+1;\n\t\tif (offset < 0) {\n\t\t\tstart = -n2 * offset;\n\t\t\tstop = MIN(n2, n1+offset)*(n2+1) - n2*offset;\n\t\t}\n\t\telse {\n\t\t\tstart = offset;\n\t\t\tstop = MIN(n1, n2-offset)*(n2+1) + offset;\n\t\t}\n\t\t\n\t\t/* count = ceil((stop-start)/step) */\n\t\tcount = ((stop-start) / step) + (((stop-start) % step) != 0);\n\t\t\t\n\t\tindices = PyArray_New(&PyArray_Type, 1, &count, \n\t\t\t\t PyArray_INTP, NULL, NULL, 0, 0, NULL);\n\t\tif (indices == NULL) {\n\t\t\tPy_DECREF(self); return NULL;\n\t\t}\n\t\tdptr = (intp *)PyArray_DATA(indices);\n\t\tfor (n1=start; n1descr;\n\n\t\tmydiagonal = PyList_New(0);\n\t\tif (mydiagonal == NULL) {Py_DECREF(self); return NULL;}\n\t\tn1 = self->dimensions[0];\n\t\tfor (i=0; i 3)) {\n\t\tPyErr_SetString(PyExc_ValueError,\n\t\t\t\t\"C arrays of only 1-3 dimensions available\");\n\t\tPy_XDECREF(typedescr);\n\t\treturn -1;\n\t}\n\tif ((ap = (PyArrayObject*)PyArray_FromAny(*op, typedescr, nd, nd,\n\t\t\t\t\t\t CARRAY_FLAGS, NULL)) == NULL)\n\t\treturn -1;\n\tswitch(nd) {\n\tcase 1:\n\t\t*((char **)ptr) = ap->data;\n\t\tbreak;\n\tcase 2:\n\t\tn = ap->dimensions[0];\n\t\tptr2 = (char **)_pya_malloc(n * sizeof(char *));\n\t\tif (!ptr2) goto fail;\n\t\tfor (i=0; idata + i*ap->strides[0];\n\t\t}\n\t\t*((char ***)ptr) = ptr2;\n\t\tbreak;\t\t\n\tcase 3:\n\t\tn = ap->dimensions[0];\n\t\tm = ap->dimensions[1];\n\t\tptr3 = (char ***)_pya_malloc(n*(m+1) * sizeof(char *));\n\t\tif (!ptr3) goto fail;\n\t\tfor (i=0; idata + i*ap->strides[0] + \\\n\t\t\t\t\tj*ap->strides[1];\n\t\t\t}\n\t\t}\n\t\t*((char ****)ptr) = ptr3;\n\t}\n\tmemcpy(dims, ap->dimensions, nd*sizeof(intp));\n\t*op = (PyObject *)ap;\n\treturn 0;\n\n fail:\n\tPyErr_SetString(PyExc_MemoryError, \"no memory\");\n\treturn -1;\n}\n\n/* Deprecated --- Use PyArray_AsCArray instead */\n\n/*MULTIARRAY_API\n Convert to a 1D C-array\n*/\nstatic int \nPyArray_As1D(PyObject **op, char **ptr, int *d1, int typecode) \n{\n\tintp newd1;\n\tPyArray_Descr *descr;\n\n\tdescr = PyArray_DescrFromType(typecode);\t\n\tif (PyArray_AsCArray(op, (void *)ptr, &newd1, 1, descr) == -1)\n\t\treturn -1;\t\n\t*d1 = (int) newd1;\n\treturn 0;\n}\n\n/*MULTIARRAY_API\n Convert to a 2D C-array\n*/\nstatic int \nPyArray_As2D(PyObject **op, char ***ptr, int *d1, int *d2, int typecode) \n{\n\tintp newdims[2];\n\tPyArray_Descr *descr;\n\n\tdescr = PyArray_DescrFromType(typecode);\t\n\tif (PyArray_AsCArray(op, (void *)ptr, newdims, 2, descr) == -1)\n\t\treturn -1;\n\n\t*d1 = (int ) newdims[0];\n\t*d2 = (int ) newdims[1];\n return 0;\n}\n\n/* End Deprecated */\n\n/*MULTIARRAY_API\n Free pointers created if As2D is called\n*/\nstatic int \nPyArray_Free(PyObject *op, void *ptr) \n{\n PyArrayObject *ap = (PyArrayObject *)op;\n\t\n if ((ap->nd < 1) || (ap->nd > 3)) \n\t\treturn -1;\n if (ap->nd >= 2) {\n\t\t_pya_free(ptr);\n }\n Py_DECREF(ap);\n return 0;\n}\n\n\nstatic PyObject *\n_swap_and_concat(PyObject *op, int axis, int n)\n{\n\tPyObject *newtup=NULL;\n\tPyObject *otmp, *arr;\n\tint i;\n\n\tnewtup = PyTuple_New(n);\n\tif (newtup==NULL) return NULL;\n\tfor (i=0; i= MAX_DIMS) {\n\t\t\totmp = PyArray_Ravel(mps[i],0);\n\t\t\tPy_DECREF(mps[i]);\n\t\t\tmps[i] = (PyArrayObject *)otmp;\n\t\t}\n\t\tif (mps[i]->ob_type != subtype) {\n\t\t\tprior2 = PyArray_GetPriority((PyObject *)(mps[i]), 0.0);\n\t\t\tif (prior2 > prior1) {\n\t\t\t\tprior1 = prior2;\n\t\t\t\tsubtype = mps[i]->ob_type;\n\t\t\t\tret = mps[i];\n\t\t\t}\n\t\t}\n\t}\n\t\n\tnew_dim = 0;\n\tfor(i=0; ind;\n\t\telse {\n\t\t\tif (nd != mps[i]->nd) {\n\t\t\t\tPyErr_SetString(PyExc_ValueError, \n\t\t\t\t\t\t\"arrays must have same \"\\\n\t\t\t\t\t\t\"number of dimensions\");\n\t\t\t\tgoto fail;\n\t\t\t}\n\t\t\tif (!PyArray_CompareLists(mps[0]->dimensions+1, \n\t\t\t\t\t\t mps[i]->dimensions+1, \n\t\t\t\t\t\t nd-1)) {\n\t\t\t\tPyErr_SetString(PyExc_ValueError, \n\t\t\t\t\t\t\"array dimensions must \"\\\n\t\t\t\t\t\t\"agree except for d_0\");\n\t\t\t\tgoto fail;\n\t\t\t}\n\t\t}\n\t\tif (nd == 0) {\n\t\t\tPyErr_SetString(PyExc_ValueError, \n\t\t\t\t\t\"0-d arrays can't be concatenated\");\n\t\t\tgoto fail;\n\t\t}\n\t\tnew_dim += mps[i]->dimensions[0];\n\t}\n\t\n\ttmp = mps[0]->dimensions[0];\n\tmps[0]->dimensions[0] = new_dim;\n\tPy_INCREF(mps[0]->descr);\n\tret = (PyArrayObject *)PyArray_NewFromDescr(subtype, \n\t\t\t\t\t\t mps[0]->descr, nd,\n\t\t\t\t\t\t mps[0]->dimensions, \n\t\t\t\t\t\t NULL, NULL, 0,\n\t\t\t\t\t\t (PyObject *)ret);\n\tmps[0]->dimensions[0] = tmp;\n\t\n\tif (ret == NULL) goto fail;\n\t\n\tdata = ret->data;\n\tfor(i=0; idata, numbytes);\n\t\tdata += numbytes;\n\t}\n\t\n\tPyArray_INCREF(ret);\n\tfor(i=0; ind;\n\tif (n <= 1) {\n\t\tPy_INCREF(ap);\n\t\treturn (PyObject *)ap;\n\t}\n\n\tif (a1 < 0) a1 += n;\n\tif (a2 < 0) a2 += n;\n\tif ((a1 < 0) || (a1 >= n)) {\n\t\tPyErr_SetString(PyExc_ValueError, \n\t\t\t\t\"bad axis1 argument to swapaxes\");\n\t\treturn NULL;\n\t}\n\tif ((a2 < 0) || (a2 >= n)) {\n\t\tPyErr_SetString(PyExc_ValueError, \n\t\t\t\t\"bad axis2 argument to swapaxes\");\n\t\treturn NULL;\n\t}\n\tnew_axes.ptr = dims;\n\tnew_axes.len = n;\n\n\tfor (i=0; ind;\n\t\tfor(i=0; ilen;\n\t\taxes = permute->ptr;\n\t\tif (n > ap->nd) {\n\t\t\tPyErr_SetString(PyExc_ValueError, \n\t\t\t\t\t\"too many axes for this array\");\n\t\t\treturn NULL;\n\t\t}\n\t\tfor(i=0; ind+axis;\n\t\t\tif (axis < 0 || axis >= ap->nd) {\n\t\t\t\tPyErr_SetString(PyExc_ValueError, \n\t\t\t\t\t\t\"invalid axis for this array\");\n\t\t\t\treturn NULL;\n\t\t\t}\n\t\t\tpermutation[i] = axis;\n\t\t}\n\t}\n\t\n\t/* this allocates memory for dimensions and strides (but fills them\n\t incorrectly), sets up descr, and points data at ap->data. */\n\tPy_INCREF(ap->descr);\n\tret = (PyArrayObject *)\\\n\t\tPyArray_NewFromDescr(ap->ob_type, \n\t\t\t\t ap->descr, \n\t\t\t\t n, permutation, \n\t\t\t\t NULL, ap->data, ap->flags,\n\t\t\t\t (PyObject *)ap);\n\tif (ret == NULL) return NULL;\n\t\n\t/* point at true owner of memory: */\n\tret->base = (PyObject *)ap;\n\tPy_INCREF(ap);\n\t\n\tfor(i=0; idimensions[i] = ap->dimensions[permutation[i]];\n\t\tret->strides[i] = ap->strides[permutation[i]];\n\t}\n\tPyArray_UpdateFlags(ret, CONTIGUOUS | FORTRAN);\t\n\n\treturn (PyObject *)ret;\t\n}\n\n/*MULTIARRAY_API\n Repeat the array.\n*/\nstatic PyObject *\nPyArray_Repeat(PyArrayObject *aop, PyObject *op, int axis)\n{\n\tintp *counts;\n\tintp n, n_outer, i, j, k, chunk, total;\n\tintp tmp;\n\tint nd;\n\tPyArrayObject *repeats=NULL;\n\tPyObject *ap=NULL;\n\tPyArrayObject *ret=NULL;\n\tchar *new_data, *old_data;\n\n\trepeats = (PyAO *)PyArray_ContiguousFromAny(op, PyArray_INTP, 0, 1);\n\tif (repeats == NULL) return NULL;\n\tnd = repeats->nd;\n\tcounts = (intp *)repeats->data;\n\n\tif ((ap=_check_axis(aop, &axis, CARRAY_FLAGS))==NULL) {\n\t\tPy_DECREF(repeats);\n\t\treturn NULL;\n\t}\n\n\taop = (PyAO *)ap;\n\n\tif (nd == 1)\n\t\tn = repeats->dimensions[0];\n\telse /* nd == 0 */\n\t\tn = aop->dimensions[axis];\n\n\tif (aop->dimensions[axis] != n) {\n\t\tPyErr_SetString(PyExc_ValueError, \n\t\t\t\t\"a.shape[axis] != len(repeats)\");\n\t\tgoto fail;\n\t}\n\n\t\n\tif (nd == 0) \n\t\ttotal = counts[0]*n;\n\telse {\n\t\t\n\t\ttotal = 0;\n\t\tfor(j=0; jdimensions[axis] = total;\n\tPy_INCREF(aop->descr);\n\tret = (PyArrayObject *)PyArray_NewFromDescr(aop->ob_type, \n\t\t\t\t\t\t aop->descr,\n\t\t\t\t\t\t aop->nd,\n\t\t\t\t\t\t aop->dimensions,\n\t\t\t\t\t\t NULL, NULL, 0,\n\t\t\t\t\t\t (PyObject *)aop);\n\taop->dimensions[axis] = n;\n\t\n\tif (ret == NULL) goto fail;\n\t\n\tnew_data = ret->data;\n\told_data = aop->data;\n\t\n\tchunk = aop->descr->elsize;\n\tfor(i=axis+1; ind; i++) {\n\t\tchunk *= aop->dimensions[i];\n\t}\n\t\n\tn_outer = 1;\n\tfor(i=0; idimensions[i];\n\n\tfor(i=0; ind < mps[i]->nd) {\n\t\t\tPyErr_SetString(PyExc_ValueError, \n\t\t\t\t\t\"too many dimensions\");\n\t\t\tgoto fail;\n\t\t}\n\t\tif (!PyArray_CompareLists(ap->dimensions+(ap->nd-mps[i]->nd),\n\t\t\t\t mps[i]->dimensions, mps[i]->nd)) {\n\t\t\tPyErr_SetString(PyExc_ValueError, \n\t\t\t\t\t\"array dimensions must agree\");\n\t\t\tgoto fail;\n\t\t}\n\t\tsizes[i] = PyArray_NBYTES(mps[i]);\n\t}\n\t\n\tPy_INCREF(mps[0]->descr);\n\tret = (PyArrayObject *)PyArray_NewFromDescr(ap->ob_type, \n\t\t\t\t\t\t mps[0]->descr,\n\t\t\t\t\t\t ap->nd,\n\t\t\t\t\t\t ap->dimensions, \n\t\t\t\t\t\t NULL, NULL, 0,\n\t\t\t\t\t\t (PyObject *)ap);\n\tif (ret == NULL) goto fail;\n\t\n\telsize = ret->descr->elsize;\n\tm = PyArray_SIZE(ret);\n\tself_data = (intp *)ap->data;\n\tret_data = ret->data;\n\t\n\tfor (i=0; i= n) {\n\t\t\tPyErr_SetString(PyExc_ValueError, \n\t\t\t\t\t\"invalid entry in choice array\");\n\t\t\tgoto fail;\n\t\t}\n\t\toffset = i*elsize;\n\t\tif (offset >= sizes[mi]) {offset = offset % sizes[mi]; }\n\t\tmemmove(ret_data, mps[mi]->data+offset, elsize);\n\t\tret_data += elsize; self_data++;\n\t}\n\t\n\tPyArray_INCREF(ret);\n\tfor(i=0; idescr->f->sort[which];\n\tsize = it->size;\n\tN = op->dimensions[axis];\n\telsize = op->descr->elsize;\n\tastride = op->strides[axis];\n\n\tneedcopy = !(op->flags & ALIGNED) || (astride != (intp) elsize);\n\n\tif (needcopy) {\n\t\tchar *buffer;\n\t\tbuffer = PyDataMem_NEW(N*elsize);\n\t\twhile (size--) {\n\t\t\t_strided_copy(buffer, (intp) elsize, it->dataptr, \n\t\t\t\t astride, N, elsize);\n\t\t\tif (sort(buffer, N, op) < 0) {\n\t\t\t\tPyDataMem_FREE(buffer); goto fail;\n\t\t\t}\n\t\t\t_strided_copy(it->dataptr, astride, buffer, \n\t\t\t\t (intp) elsize, N, elsize);\n\t\t\tPyArray_ITER_NEXT(it);\n\t\t}\n\t\tPyDataMem_FREE(buffer);\n\t}\n\telse {\n\t\twhile (size--) {\n\t\t\tif (sort(it->dataptr, N, op) < 0) goto fail;\n\t\t\tPyArray_ITER_NEXT(it);\n\t\t}\n\t}\t\n\t\n\tEND_THREADS\n\t\n\tPy_DECREF(it);\n\treturn 0;\n\n fail:\n\tEND_THREADS\n\n\tPy_DECREF(it);\n\treturn 0;\n}\n\nstatic PyObject*\n_new_argsort(PyArrayObject *op, int axis, PyArray_SORTKIND which) \n{\n\n\tPyArrayIterObject *it=NULL;\n\tPyArrayIterObject *rit=NULL;\n\tPyObject *ret;\n\tint needcopy=0, i;\n\tintp N, size;\n\tint elsize;\n\tintp astride, rstride, *iptr;\n\tPyArray_ArgSortFunc *argsort;\n\tBEGIN_THREADS_DEF \n\n\tret = PyArray_New(op->ob_type, op->nd,\n\t\t\t op->dimensions, PyArray_INTP,\n\t\t\t NULL, NULL, 0, 0, (PyObject *)op);\n\tif (ret == NULL) return NULL;\n\n\tit = (PyArrayIterObject *)PyArray_IterAllButAxis((PyObject *)op, axis);\n\trit = (PyArrayIterObject *)PyArray_IterAllButAxis(ret, axis);\n\tif (rit == NULL || it == NULL) goto fail;\n\n\tBEGIN_THREADS\n\n\targsort = op->descr->f->argsort[which];\n\tsize = it->size;\n\tN = op->dimensions[axis];\n\telsize = op->descr->elsize;\n\tastride = op->strides[axis];\n\trstride = PyArray_STRIDE(ret,axis);\n\n\tneedcopy = !(op->flags & ALIGNED) || (astride != (intp) elsize) || \\\n\t\t(rstride != sizeof(intp));\n\t\n\tif (needcopy) {\n\t\tchar *valbuffer, *indbuffer;\n\t\tvalbuffer = PyDataMem_NEW(N*(elsize+sizeof(intp)));\n\t\tindbuffer = valbuffer + (N*elsize);\n\t\twhile (size--) {\n\t\t\t_strided_copy(valbuffer, (intp) elsize, it->dataptr,\n\t\t\t\t astride, N, elsize);\n\t\t\tiptr = (intp *)indbuffer;\n\t\t\tfor (i=0; idataptr, rstride, indbuffer, \n\t\t\t\t sizeof(intp), N, sizeof(intp));\n\t\t\tPyArray_ITER_NEXT(it);\n\t\t\tPyArray_ITER_NEXT(rit);\n\t\t}\n\t\tPyDataMem_FREE(valbuffer);\n\t}\n\telse {\n\t\twhile (size--) {\n\t\t\tiptr = (intp *)rit->dataptr;\n\t\t\tfor (i=0; idataptr, (intp *)rit->dataptr, \n\t\t\t\t N, op) < 0) goto fail;\n\t\t\tPyArray_ITER_NEXT(it);\n\t\t\tPyArray_ITER_NEXT(rit);\n\t\t}\n\t}\n\t\n\tEND_THREADS\n\n\tPy_DECREF(it);\n\tPy_DECREF(rit);\n\treturn ret;\n\n fail:\n\n\tEND_THREADS\n\n\tPy_DECREF(ret);\n\tPy_XDECREF(it);\n\tPy_XDECREF(rit);\n\treturn NULL;\n}\n\n\n/* Be sure to save this global_compare when necessary */\n\nstatic PyArrayObject *global_obj;\n\nstatic int \nqsortCompare (const void *a, const void *b) \n{\n\treturn global_obj->descr->f->compare(a,b,global_obj);\n}\n\n/* Consumes reference to ap (op gets it)\n op contains a version of the array with axes swapped if\n local variable axis is not the last dimension.\n orign must be defined locally. \n*/\n\n#define SWAPAXES(op, ap) {\t\t\t\t\t\t\\\n\t\torign = (ap)->nd-1;\t\t\t\t\t\\\n\t\tif (axis != orign) {\t\t\t\t\t\\\n\t\t\t(op) = (PyAO *)PyArray_SwapAxes((ap), axis, orign); \\\n\t\t\tPy_DECREF((ap));\t\t\t\t\\\n\t\t\tif ((op) == NULL) return NULL;\t\t\t\\\n\t\t}\t\t\t\t\t\t\t\\\n\t\telse (op) = (ap);\t\t\t\t\t\\\n\t}\n\n/* Consumes reference to ap (op gets it)\n origin must be previously defined locally. \n SWAPAXES must have been called previously. \n op contains the swapped version of the array. \n*/\n#define SWAPBACK(op, ap) {\t \\\n\t\tif (axis != orign) { \\\n\t\t\t(op) = (PyAO *)PyArray_SwapAxes((ap), axis, orign); \\\n\t\t\tPy_DECREF((ap));\t\t\t\t\\\n\t\t\tif ((op) == NULL) return NULL;\t\t\t\\\n\t\t}\t\t\t\t\t\t\t\\\n\t\telse (op) = (ap);\t\t\t\t\t\\\n\t}\n\n/* These swap axes in-place if necessary */\n#define SWAPINTP(a,b) {intp c; c=(a); (a) = (b); (b) = c;}\n#define SWAPAXES2(ap) {\t\t\t\t\t\t\\\n\t\torign = (ap)->nd-1;\t\t\t\t\t\\\n\t\tif (axis != orign) {\t\t\t\t\t\\\n\t\t\tSWAPINTP(ap->dimensions[axis], ap->dimensions[orign]); \\\n\t\t\tSWAPINTP(ap->strides[axis], ap->strides[orign]); \\\n\t\t\tPyArray_UpdateFlags(ap, CONTIGUOUS | FORTRAN); \\\n\t\t}\t\t\t\t\t\t \\\n\t}\n\n#define SWAPBACK2(ap) {\t\t \\\n\t\tif (axis != orign) {\t\t\t\t\t\\\n\t\t\tSWAPINTP(ap->dimensions[axis], ap->dimensions[orign]); \\\n\t\t\tSWAPINTP(ap->strides[axis], ap->strides[orign]); \\\n\t\t\tPyArray_UpdateFlags(ap, CONTIGUOUS | FORTRAN);\t\\\n\t\t}\t\t\t\t\t\t\t\\\n\t}\n\n/*MULTIARRAY_API\n Sort an array in-place\n*/\nstatic int\nPyArray_Sort(PyArrayObject *op, int axis, PyArray_SORTKIND which) \n{\n\tPyArrayObject *ap=NULL, *store_arr=NULL;\n\tchar *ip;\n\tint i, n, m, elsize, orign;\n\n\tn = op->nd;\n\tif ((n==0) || (PyArray_SIZE(op)==1)) return 0;\n\n\tif (axis < 0) axis += n;\n\tif ((axis < 0) || (axis >= n)) {\n\t\tPyErr_Format(PyExc_ValueError, \n\t\t\t \"axis(=%d) out of bounds\", axis);\n\t\treturn -1;\n\t}\n\tif (!PyArray_ISWRITEABLE(op)) {\n\t\tPyErr_SetString(PyExc_RuntimeError, \n\t\t\t\t\"attempted sort on unwriteable array.\");\n\t\treturn -1;\n\t}\n\n\t/* Determine if we should use type-specific algorithm or not */\n\tif (op->descr->f->sort[which] != NULL) {\n\t\treturn _new_sort(op, axis, which);\n\t}\n\n\tif ((which != PyArray_QUICKSORT) || \\\n\t op->descr->f->compare == NULL) {\n\t\tPyErr_SetString(PyExc_TypeError, \n\t\t\t\t\"desired sort not supported for this type\");\n\t\treturn -1;\n\t}\n\n\tSWAPAXES2(op);\n\n ap = (PyArrayObject *)PyArray_FromAny((PyObject *)op, \n\t\t\t\t\t NULL, 1, 0, \n\t\t\t\t\t DEFAULT_FLAGS | UPDATEIFCOPY, NULL);\t\n\tif (ap == NULL) goto fail;\n\t\n\telsize = ap->descr->elsize;\n\tm = ap->dimensions[ap->nd-1];\n\tif (m == 0) goto finish;\n\n\tn = PyArray_SIZE(ap)/m;\n\n\t/* Store global -- allows re-entry -- restore before leaving*/\n\tstore_arr = global_obj; \n\tglobal_obj = ap;\n\t\n\tfor (ip=ap->data, i=0; idescr->elsize;\n\tconst intp *ipa = ip1;\n\tconst intp *ipb = ip2;\t\n\treturn global_obj->descr->f->compare(global_data + (isize * *ipa),\n global_data + (isize * *ipb), \n\t\t\t\t\t global_obj);\n}\n\n/*MULTIARRAY_API\n ArgSort an array\n*/\nstatic PyObject *\nPyArray_ArgSort(PyArrayObject *op, int axis, PyArray_SORTKIND which) \n{\n\tPyArrayObject *ap=NULL, *ret=NULL, *store;\n\tintp *ip;\n\tintp i, j, n, m, orign;\n\tint argsort_elsize;\n\tchar *store_ptr;\n\n\tn = op->nd;\n\tif ((n==0) || (PyArray_SIZE(op)==1)) {\n\t\tret = (PyArrayObject *)PyArray_New(op->ob_type, op->nd,\n\t\t\t\t\t\t op->dimensions, \n\t\t\t\t\t\t PyArray_INTP,\n\t\t\t\t\t\t NULL, NULL, 0, 0, \n\t\t\t\t\t\t (PyObject *)op);\n\t\tif (ret == NULL) return NULL;\n\t\t*((intp *)ret->data) = 0;\n\t\treturn (PyObject *)ret;\n\t}\n\tif (axis < 0) axis += n;\n\tif ((axis < 0) || (axis >= n)) {\n\t\tPyErr_Format(PyExc_ValueError, \n\t\t\t \"axis(=%d) out of bounds\", axis);\n\t\treturn NULL;\n\t}\n\n\t/* Determine if we should use new algorithm or not */\n\tif (op->descr->f->argsort[which] != NULL) {\n\t\treturn _new_argsort(op, axis, which);\n\t}\n\n\tif ((which != PyArray_QUICKSORT) || op->descr->f->compare == NULL) {\n\t\tPyErr_SetString(PyExc_TypeError, \n\t\t\t\t\"requested sort not available for type\");\n\t\tgoto fail;\n\t}\n\n\tSWAPAXES(ap, op);\n\n\top = (PyArrayObject *)PyArray_ContiguousFromAny((PyObject *)ap, \n\t\t\t\t\t\t\t PyArray_NOTYPE,\n\t\t\t\t\t\t\t 1, 0);\n\n\tif (op == NULL) return NULL;\n\t\n\tret = (PyArrayObject *)PyArray_New(op->ob_type, op->nd,\n\t\t\t\t\t op->dimensions, PyArray_INTP,\n\t\t\t\t\t NULL, NULL, 0, 0, (PyObject *)op);\n\tif (ret == NULL) goto fail;\n\t\n\t\n\tip = (intp *)ret->data;\n\targsort_elsize = op->descr->elsize;\n\tm = op->dimensions[op->nd-1];\n\tif (m == 0) goto finish;\n\n\tn = PyArray_SIZE(op)/m;\n\tstore_ptr = global_data;\n\tglobal_data = op->data;\n\tstore = global_obj;\n\tglobal_obj = op;\n\tfor (i=0; i 0 in lexsort\");\n\t\treturn NULL;\n\t}\n\tmps = (PyArrayObject **) _pya_malloc(n*sizeof(PyArrayObject));\n\tif (mps==NULL) return PyErr_NoMemory();\n\tits = (PyArrayIterObject **) _pya_malloc(n*sizeof(PyArrayIterObject));\n\tif (its == NULL) {_pya_free(mps); return PyErr_NoMemory();}\n\tfor (i=0; i0) {\n\t\t\tif ((mps[i]->nd != mps[0]->nd) ||\t\\\n\t\t\t (!PyArray_CompareLists(mps[i]->dimensions,\n\t\t\t\t\t\t mps[0]->dimensions,\n\t\t\t\t\t\t mps[0]->nd))) {\n\t\t\t\tPyErr_SetString(PyExc_ValueError,\n\t\t\t\t\t\t\"all keys need to be the same shape\");\n\t\t\t\tgoto fail;\n\t\t\t}\n\t\t}\n\t\tif (!mps[i]->descr->f->argsort[PyArray_MERGESORT]) {\n\t\t\tPyErr_Format(PyExc_TypeError, \n\t\t\t\t \"merge sort not available for item %d\", i);\n\t\t\tgoto fail;\n\t\t}\n\t\tits[i] = (PyArrayIterObject *)PyArray_IterAllButAxis\t\\\n\t\t\t((PyObject *)mps[i], axis);\n\t\tif (its[i]==NULL) goto fail;\n\t}\n\n\t/* Now we can check the axis */\n\tnd = mps[0]->nd;\n\tif ((nd==0) || (PyArray_SIZE(mps[0])==1)) {\n\t\tret = (PyArrayObject *)PyArray_New(&PyArray_Type, mps[0]->nd,\n\t\t\t\t\t\t mps[0]->dimensions, \n\t\t\t\t\t\t PyArray_INTP,\n\t\t\t\t\t\t NULL, NULL, 0, 0, NULL);\n\t\tif (ret == NULL) return NULL;\n\t\t*((intp *)(ret->data)) = 0;\n\t\treturn (PyObject *)ret;\n\t}\n\tif (axis < 0) axis += nd;\n\tif ((axis < 0) || (axis >= nd)) {\n\t\tPyErr_Format(PyExc_ValueError, \n\t\t\t \"axis(=%d) out of bounds\", axis);\n\t\tgoto fail;\n\t}\n\n\t/* Now do the sorting */\n\n\tret = (PyArrayObject *)PyArray_New(&PyArray_Type, mps[0]->nd,\n\t\t\t\t\t mps[0]->dimensions, PyArray_INTP,\n\t\t\t\t\t NULL, NULL, 0, 0, NULL);\n\tif (ret == NULL) goto fail;\n\n\trit = (PyArrayIterObject *)\\\n\t\tPyArray_IterAllButAxis((PyObject *)ret, axis);\n\tif (rit == NULL) goto fail;\n\n\tsize = rit->size;\n\tN = mps[0]->dimensions[axis];\n\trstride = PyArray_STRIDE(ret,axis);\n\n maxelsize = mps[0]->descr->elsize;\n\tneedcopy = (rstride != sizeof(intp));\n\tfor (j=0; jflags & ALIGNED) || \\\n\t\t\t(mps[j]->strides[axis] != (intp)mps[j]->descr->elsize);\n if (mps[j]->descr->elsize > maxelsize) \n maxelsize = mps[j]->descr->elsize;\n\t}\n\n\tif (needcopy) {\n\t\tchar *valbuffer, *indbuffer;\n\t\tvalbuffer = PyDataMem_NEW(N*(maxelsize+sizeof(intp)));\n\t\tindbuffer = valbuffer + (N*maxelsize);\n\t\twhile (size--) {\n\t\t\tiptr = (intp *)indbuffer;\n\t\t\tfor (i=0; idescr->elsize;\n\t\t\t\tastride = mps[j]->strides[axis];\t\n\t\t\t\targsort = mps[j]->descr->f->argsort[PyArray_MERGESORT];\n\t\t\t\t_strided_copy(valbuffer, (intp) elsize, its[j]->dataptr,\n\t\t\t\t\t astride, N, elsize);\n\t\t\t\tif (argsort(valbuffer, (intp *)indbuffer, N, mps[j]) < 0) {\n\t\t\t\t\tPyDataMem_FREE(valbuffer); goto fail;\n\t\t\t\t}\n\t\t\t\tPyArray_ITER_NEXT(its[j]);\n\t\t\t}\n\t\t\t_strided_copy(rit->dataptr, rstride, indbuffer,\n\t\t\t\t sizeof(intp), N, sizeof(intp));\n\t\t\tPyArray_ITER_NEXT(rit);\n\t\t}\n\t\tPyDataMem_FREE(valbuffer);\n\t}\n\telse {\n\t\twhile (size--) {\n\t\t\tiptr = (intp *)rit->dataptr;\n\t\t\tfor (i=0; idescr->f->argsort[PyArray_MERGESORT];\n\t\t\t\tif (argsort(its[j]->dataptr, (intp *)rit->dataptr,\n\t\t\t\t\t N, mps[j]) < 0) goto fail;\n\t\t\t\tPyArray_ITER_NEXT(its[j]);\n\t\t\t}\n\t\t\tPyArray_ITER_NEXT(rit);\n\t\t}\n\t}\n\n\tfor (i=0; idescr->f->compare;\n\tintp min_i, max_i, i, j;\n\tint location, elsize = ap1->descr->elsize;\n\tintp elements = ap1->dimensions[ap1->nd-1];\n\tintp n = PyArray_SIZE(ap2);\n\tintp *rp = (intp *)ret->data;\n\tchar *ip = ap2->data;\n\tchar *vp = ap1->data;\n\n\tfor (j=0; j 0) {\n\t\t\t\t\tif (compare(ip, vp+elsize*(--i), ap2) \\\n\t\t\t\t\t != 0) {\n\t\t\t\t\t\ti = i+1; break;\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t\tmin_i = i;\n\t\t\t\tbreak;\n\t\t\t}\n\t\t\telse if (location < 0) {\n\t\t\t\tmax_i = i;\n\t\t\t} else {\n\t\t\t\tmin_i = i+1;\n\t\t\t}\n\t\t}\n\t\t*rp = min_i;\n\t}\n}\n\n/*MULTIARRAY_API\n Numeric.searchsorted(a,v)\n*/\nstatic PyObject *\nPyArray_SearchSorted(PyArrayObject *op1, PyObject *op2) \n{\n\tPyArrayObject *ap1=NULL, *ap2=NULL, *ret=NULL;\n\tint typenum = 0;\n\n\t/* \n PyObject *args;\n args = Py_BuildValue(\"O\",op2);\n\tPy_DELEGATE_ARGS(((PyObject *)op1), searchsorted, args);\n Py_XDECREF(args);\n\t*/\n\n\ttypenum = PyArray_ObjectType((PyObject *)op1, 0);\n\ttypenum = PyArray_ObjectType(op2, typenum);\n\tret = NULL;\n\tap1 = (PyArrayObject *)PyArray_ContiguousFromAny((PyObject *)op1, \n\t\t\t\t\t\t\t typenum, \n\t\t\t\t\t\t\t 1, 1);\n\tif (ap1 == NULL) return NULL;\n\tap2 = (PyArrayObject *)PyArray_ContiguousFromAny(op2, typenum, \n\t\t\t\t\t\t\t 0, 0);\n\tif (ap2 == NULL) goto fail;\n\t\n\tret = (PyArrayObject *)PyArray_New(ap2->ob_type, ap2->nd, \n\t\t\t\t\t ap2->dimensions, PyArray_INTP,\n\t\t\t\t\t NULL, NULL, 0, 0, (PyObject *)ap2);\n\tif (ret == NULL) goto fail;\n\n\tif (ap2->descr->f->compare == NULL) {\n\t\tPyErr_SetString(PyExc_TypeError, \n\t\t\t\t\"compare not supported for type\");\n\t\tgoto fail;\n\t}\n\t\n\tlocal_where(ap1, ap2, ret); \n\t\n\tPy_DECREF(ap1);\n\tPy_DECREF(ap2);\n\treturn (PyObject *)ret;\n\t\n fail:\n\tPy_XDECREF(ap1);\n\tPy_XDECREF(ap2);\n\tPy_XDECREF(ret);\n\treturn NULL;\n}\n\n/*\n Make a new empty array, of the passed size, of a type that takes the\n priority of ap1 and ap2 into account.\n */\nstatic PyArrayObject *\nnew_array_for_sum(PyArrayObject *ap1, PyArrayObject *ap2,\n\t\t int nd, intp dimensions[], int typenum)\n{\n\tPyArrayObject *ret;\n\tPyTypeObject *subtype;\n\tdouble prior1, prior2;\n\t/* Need to choose an output array that can hold a sum \n\t -- use priority to determine which subtype.\n\t */\n\tif (ap2->ob_type != ap1->ob_type) {\n\t\tprior2 = PyArray_GetPriority((PyObject *)ap2, 0.0);\n\t\tprior1 = PyArray_GetPriority((PyObject *)ap1, 0.0);\n\n\t\tsubtype = (prior2 > prior1 ? ap2->ob_type : ap1->ob_type);\n\t} else {\n\t\tprior1 = prior2 = 0.0;\n\t\tsubtype = ap1->ob_type;\n\t}\n\n\tret = (PyArrayObject *)PyArray_New(subtype, nd, dimensions, \n\t\t\t\t\t typenum, NULL, NULL, 0, 0, \n (PyObject *)\n\t\t\t\t\t (prior2 > prior1 ? ap2 : ap1));\n\treturn ret;\n}\n\n/* Could perhaps be redone to not make contiguous arrays \n */\n\n/*MULTIARRAY_API\n Numeric.innerproduct(a,v)\n*/\nstatic PyObject *\nPyArray_InnerProduct(PyObject *op1, PyObject *op2) \n{\n\tPyArrayObject *ap1, *ap2, *ret=NULL;\n\tintp i, j, l, i1, i2, n1, n2;\n\tint typenum, nd;\n\tintp is1, is2, os;\n\tchar *ip1, *ip2, *op;\n\tintp dimensions[MAX_DIMS];\n\tPyArray_DotFunc *dot;\n\t\n\ttypenum = PyArray_ObjectType(op1, 0); \n\ttypenum = PyArray_ObjectType(op2, typenum);\n\t\t\n\tap1 = (PyArrayObject *)PyArray_ContiguousFromAny(op1, typenum, \n\t\t\t\t\t\t\t 0, 0);\n\tif (ap1 == NULL) return NULL;\n\tap2 = (PyArrayObject *)PyArray_ContiguousFromAny(op2, typenum, \n\t\t\t\t\t\t\t 0, 0);\n\tif (ap2 == NULL) goto fail;\n\t\n\tif (ap1->nd == 0 || ap2->nd == 0) {\n\t\tret = (ap1->nd == 0 ? ap1 : ap2);\n\t\tret = (PyArrayObject *)ret->ob_type->tp_as_number->\\\n\t\t\tnb_multiply((PyObject *)ap1, (PyObject *)ap2);\n\t\tPy_DECREF(ap1);\n\t\tPy_DECREF(ap2);\n\t\treturn (PyObject *)ret;\n\t}\n\t\n\tl = ap1->dimensions[ap1->nd-1];\n\t\n\tif (ap2->dimensions[ap2->nd-1] != l) {\n\t\tPyErr_SetString(PyExc_ValueError, \"matrices are not aligned\");\n\t\tgoto fail;\n\t}\n\t\n\tif (l == 0) n1 = n2 = 0;\n\telse {\n\t\tn1 = PyArray_SIZE(ap1)/l;\n\t\tn2 = PyArray_SIZE(ap2)/l;\n\t}\n\n\tnd = ap1->nd+ap2->nd-2;\n\tj = 0;\n\tfor(i=0; ind-1; i++) {\n\t\tdimensions[j++] = ap1->dimensions[i];\n\t}\n\tfor(i=0; ind-1; i++) {\n\t\tdimensions[j++] = ap2->dimensions[i];\n\t}\n\n\n\t/* Need to choose an output array that can hold a sum \n\t -- use priority to determine which subtype.\n\t */\n\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\n\t\n\tis1 = ap1->strides[ap1->nd-1]; \n\tis2 = ap2->strides[ap2->nd-1];\n\top = ret->data; os = ret->descr->elsize;\n\t\n\tip1 = ap1->data;\n\tfor(i1=0; i1data;\n\t\tfor(i2=0; i2nd == 0 || ap2->nd == 0) {\n\t\tret = (ap1->nd == 0 ? ap1 : ap2);\n\t\tret = (PyArrayObject *)ret->ob_type->tp_as_number->\\\n\t\t\tnb_multiply((PyObject *)ap1, (PyObject *)ap2);\n\t\tPy_DECREF(ap1);\n\t\tPy_DECREF(ap2);\n\t\treturn (PyObject *)ret;\n\t}\n\t\n\tl = ap1->dimensions[ap1->nd-1];\n\tif (ap2->nd > 1) {\n\t\tmatchDim = ap2->nd - 2;\n\t\totherDim = ap2->nd - 1;\n\t}\n\telse {\n\t\tmatchDim = 0;\n\t\totherDim = 0;\n\t}\n\n\tif (ap2->dimensions[matchDim] != l) {\n\t\tPyErr_SetString(PyExc_ValueError, \"objects are not aligned\");\n\t\tgoto fail;\n\t}\n\t\n\tif (l == 0) n1 = n2 = 0;\n\telse {\n\t\tn1 = PyArray_SIZE(ap1)/l;\n\t\tn2 = PyArray_SIZE(ap2)/l;\n\t}\n\n\tnd = ap1->nd+ap2->nd-2;\n\tj = 0;\n\tfor(i=0; ind-1; i++) {\n\t\tdimensions[j++] = ap1->dimensions[i];\n\t}\n\tfor(i=0; ind-2; i++) {\n\t\tdimensions[j++] = ap2->dimensions[i];\n\t}\n\tif(ap2->nd > 1) {\n\t\tdimensions[j++] = ap2->dimensions[ap2->nd-1];\n\t}\n\t/*\n\tfprintf(stderr, \"nd=%d dimensions=\", nd);\n\t for(i=0; i 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\tis1 = ap1->strides[ap1->nd-1]; is2 = ap2->strides[matchDim];\n\tif(ap1->nd > 1)\n\t\tis1r = ap1->strides[ap1->nd-2];\n\telse\n\t\tis1r = ap1->strides[ap1->nd-1];\n\tis2r = ap2->strides[otherDim];\n\n\top = ret->data; os = ret->descr->elsize;\n\n\tip1 = ap1->data;\n\tfor(i1=0; i1data;\n\t\tfor(i2=0; i2ob_type, \n\t\t\t\t PyArray_DESCR(arr),\n\t\t\t\t 2, dims, \n\t\t\t\t NULL, NULL, 0, arr);\n\n\tif (ret == NULL) {\n\t\tPy_DECREF(arr);\n\t\treturn NULL;\n\t}\n\t/* do 2-d loop */\n\toptr = PyArray_DATA(ret);\n\tstr2 = elsize*dims[0];\n\tfor (i=0; idimensions[0];\n\tn2 = ap2->dimensions[0];\n\n\tif (n1 < n2) { \n\t\tret = ap1; ap1 = ap2; ap2 = ret; \n\t\tret = NULL; i = n1;n1=n2;n2=i;\n\t}\n\tlength = n1;\n\tn = n2;\n\tswitch(mode) {\n\tcase 0:\t\n\t\tlength = length-n+1;\n\t\tn_left = n_right = 0;\n\t\tbreak;\n\tcase 1:\n\t\tn_left = (intp)(n/2);\n\t\tn_right = n-n_left-1;\n\t\tbreak;\n\tcase 2:\n\t\tn_right = n-1;\n\t\tn_left = n-1;\n\t\tlength = length+n-1;\n\t\tbreak;\n\tdefault:\n\t\tPyErr_SetString(PyExc_ValueError, \n\t\t\t\t\"mode must be 0, 1, or 2\");\n\t\tgoto fail;\n\t}\n\n\t/* Need to choose an output array that can hold a sum \n\t -- use priority to determine which subtype.\n\t */\n\tret = new_array_for_sum(ap1, ap2, 1, &length, typenum);\n\tif (ret == NULL) goto fail;\n\t\n\tdot = ret->descr->f->dotfunc;\n\tif (dot == NULL) {\n\t\tPyErr_SetString(PyExc_ValueError, \n\t\t\t\t\"function not available for this data type\");\n\t\tgoto fail;\n\t}\n\t\n\tis1 = ap1->strides[0]; is2 = ap2->strides[0];\n\top = ret->data; os = ret->descr->elsize;\n\t\n\tip1 = ap1->data; ip2 = ap2->data+n_left*is2;\n\tn = n-n_left;\n\tfor(i=0; idescr->type_num);\n\tPy_DECREF(arr);\n\treturn ret;\t \n}\n\n/*MULTIARRAY_API\n Min\n*/\nstatic PyObject *\nPyArray_Min(PyArrayObject *ap, int axis)\n{\n\tPyArrayObject *arr;\n\tPyObject *ret;\n\n\tif ((arr=(PyArrayObject *)_check_axis(ap, &axis, 0))==NULL)\n\t\treturn NULL;\n\tret = PyArray_GenericReduceFunction(arr, n_ops.minimum, axis,\n\t\t\t\t\t arr->descr->type_num);\n\tPy_DECREF(arr);\n\treturn ret;\t \n}\n\n/*MULTIARRAY_API\n Ptp\n*/\nstatic PyObject *\nPyArray_Ptp(PyArrayObject *ap, int axis)\n{\n\tPyArrayObject *arr;\n\tPyObject *ret;\n\tPyObject *obj1=NULL, *obj2=NULL;\n\n\tif ((arr=(PyArrayObject *)_check_axis(ap, &axis, 0))==NULL)\n\t\treturn NULL;\n\tobj1 = PyArray_Max(arr, axis);\n\tif (obj1 == NULL) goto fail;\n\tobj2 = PyArray_Min(arr, axis);\n\tif (obj2 == NULL) goto fail;\n\tPy_DECREF(arr);\n\tret = PyNumber_Subtract(obj1, obj2);\n\tPy_DECREF(obj1);\n\tPy_DECREF(obj2);\n\treturn ret;\n\n fail:\n\tPy_XDECREF(arr);\n\tPy_XDECREF(obj1);\n\tPy_XDECREF(obj2);\n\treturn NULL;\n}\n\n\n/*MULTIARRAY_API\n ArgMax\n*/\nstatic PyObject *\nPyArray_ArgMax(PyArrayObject *op, int axis) \n{\n\tPyArrayObject *ap=NULL, *rp=NULL;\n\tPyArray_ArgFunc* arg_func;\n\tchar *ip;\n\tintp *rptr;\n\tintp i, n, orign, m;\n\tint elsize;\n\t\n\tif ((ap=(PyAO *)_check_axis(op, &axis, 0))==NULL) return NULL;\n\n\tSWAPAXES(op, ap);\n\n\tap = (PyArrayObject *)\\\n\t\tPyArray_ContiguousFromAny((PyObject *)op, \n\t\t\t\t\t PyArray_NOTYPE, 1, 0);\n\n\tPy_DECREF(op);\n\tif (ap == NULL) return NULL;\n\t\n\targ_func = ap->descr->f->argmax;\n\tif (arg_func == NULL) {\n\t\tPyErr_SetString(PyExc_TypeError, \"data type not ordered\");\n\t\tgoto fail;\n\t}\n\n\trp = (PyArrayObject *)PyArray_New(ap->ob_type, ap->nd-1,\n\t\t\t\t\t ap->dimensions, PyArray_INTP,\n\t\t\t\t\t NULL, NULL, 0, 0, \n (PyObject *)ap);\n\tif (rp == NULL) goto fail;\n\n\n\telsize = ap->descr->elsize;\n\tm = ap->dimensions[ap->nd-1];\n\tif (m == 0) {\n\t\tPyErr_SetString(MultiArrayError, \n\t\t\t\t\"attempt to get argmax/argmin \"\\\n\t\t\t\t\"of an empty sequence??\");\n\t\tgoto fail;\n\t}\n\tn = PyArray_SIZE(ap)/m;\n\trptr = (intp *)rp->data;\n\tfor (ip = ap->data, i=0; ind + indices->nd - 1;\n for (i=0; i< nd; i++) {\n if (i < axis) {\n shape[i] = self->dimensions[i];\n n *= shape[i];\n } else {\n if (i < axis+indices->nd) {\n shape[i] = indices->dimensions[i-axis];\n m *= shape[i];\n } else {\n shape[i] = self->dimensions[i-indices->nd+1];\n chunk *= shape[i];\n }\n }\n }\n\tPy_INCREF(self->descr);\n ret = (PyArrayObject *)PyArray_NewFromDescr(self->ob_type, \n\t\t\t\t\t\t self->descr,\n\t\t\t\t\t\t nd, shape, \n\t\t\t\t\t\t NULL, NULL, 0, \n\t\t\t\t\t\t (PyObject *)self);\n\t\n if (ret == NULL) goto fail;\n\t\n max_item = self->dimensions[axis];\n chunk = chunk * ret->descr->elsize;\n src = self->data;\n dest = ret->data;\n\t\n for(i=0; idata))[j];\n if (tmp < 0) tmp = tmp+max_item;\n if ((tmp < 0) || (tmp >= max_item)) {\n PyErr_SetString(PyExc_IndexError, \n\t\t\t\t\t\t\"index out of range for \"\\\n\t\t\t\t\t\t\"array\");\n goto fail;\n }\n memmove(dest, src+tmp*chunk, chunk);\n dest += chunk;\n }\n src += chunk*max_item;\n }\n\t\n PyArray_INCREF(ret);\n\n Py_XDECREF(indices);\n Py_XDECREF(self);\n\n return (PyObject *)ret;\n\t\n\t\n fail:\n Py_XDECREF(ret);\n Py_XDECREF(indices);\n Py_XDECREF(self);\n return NULL;\n}\n\n/*MULTIARRAY_API\n Put values into an array\n*/\nstatic PyObject *\nPyArray_Put(PyArrayObject *self, PyObject* values0, PyObject *indices0) \n{\n PyArrayObject *indices, *values;\n int i, chunk, ni, max_item, nv, tmp, thistype; \n char *src, *dest;\n\n indices = NULL;\n values = NULL;\n\n if (!PyArray_Check(self)) {\n PyErr_SetString(PyExc_TypeError, \"put: first argument must be an array\");\n return NULL;\n }\n if (!PyArray_ISCONTIGUOUS(self)) {\n PyErr_SetString(PyExc_ValueError, \"put: first argument must be contiguous\");\n return NULL;\n }\n max_item = PyArray_SIZE(self);\n dest = self->data;\n chunk = self->descr->elsize;\n\n indices = (PyArrayObject *)PyArray_ContiguousFromAny(indices0, PyArray_INTP, 0, 0);\n if (indices == NULL) goto fail;\n ni = PyArray_SIZE(indices);\n\n\tthistype = self->descr->type_num;\n values = (PyArrayObject *)\\\n\t\tPyArray_ContiguousFromAny(values0, thistype, 0, 0);\n if (values == NULL) goto fail;\n nv = PyArray_SIZE(values);\n if (nv > 0) { /* nv == 0 for a null array */\n if (thistype == PyArray_OBJECT) { \n for(i=0; idata + chunk * (i % nv);\n tmp = ((intp *)(indices->data))[i];\n if (tmp < 0) tmp = tmp+max_item;\n if ((tmp < 0) || (tmp >= max_item)) {\n PyErr_SetString(PyExc_IndexError, \"index out of range for array\");\n goto fail;\n }\n Py_INCREF(*((PyObject **)src));\n Py_XDECREF(*((PyObject **)(dest+tmp*chunk)));\n memmove(dest + tmp * chunk, src, chunk);\n }\n }\n else {\n for(i=0; idata + chunk * (i % nv);\n tmp = ((intp *)(indices->data))[i];\n if (tmp < 0) tmp = tmp+max_item;\n if ((tmp < 0) || (tmp >= max_item)) {\n PyErr_SetString(PyExc_IndexError, \"index out of range for array\");\n goto fail;\n }\n memmove(dest + tmp * chunk, src, chunk);\n }\n }\n\n }\n\n Py_XDECREF(values);\n Py_XDECREF(indices);\n Py_INCREF(Py_None);\n return Py_None;\n\t\n fail:\n Py_XDECREF(indices);\n Py_XDECREF(values);\n return NULL;\n}\n\n/*MULTIARRAY_API\n Put values into an array according to a mask.\n*/\nstatic PyObject *\nPyArray_PutMask(PyArrayObject *self, PyObject* values0, PyObject* mask0) \n{\n PyArrayObject *mask, *values;\n int i, chunk, ni, max_item, nv, tmp, thistype;\n char *src, *dest;\n\n mask = NULL;\n values = NULL;\n\n if (!PyArray_Check(self)) {\n PyErr_SetString(PyExc_TypeError, \n\t\t\t\t\"putmask: first argument must \"\\\n\t\t\t\t\"be an array\");\n return NULL;\n }\n if (!PyArray_ISCONTIGUOUS(self)) {\n PyErr_SetString(PyExc_ValueError, \n\t\t\t\t\"putmask: first argument must be contiguous\");\n return NULL;\n }\n\n max_item = PyArray_SIZE(self);\n dest = self->data;\n chunk = self->descr->elsize;\n\n mask = (PyArrayObject *)\\\n\t\tPyArray_FROM_OTF(mask0, PyArray_BOOL, CARRAY_FLAGS | FORCECAST);\n\tif (mask == NULL) goto fail;\n ni = PyArray_SIZE(mask);\n if (ni != max_item) {\n PyErr_SetString(PyExc_ValueError, \n\t\t\t\t\"putmask: mask and data must be \"\\\n\t\t\t\t\"the same size\");\n goto fail;\n }\n\n\tthistype = self->descr->type_num;\n values = (PyArrayObject *)\\\n\t\tPyArray_ContiguousFromAny(values0, thistype, 0, 0);\n\tif (values == NULL) goto fail;\n nv = PyArray_SIZE(values);\t /* zero if null array */\n if (nv > 0) {\n if (thistype == PyArray_OBJECT) {\n for(i=0; idata + chunk * (i % nv);\n tmp = ((Bool *)(mask->data))[i];\n if (tmp) {\n\t\t\t\t\tPy_INCREF(*((PyObject **)src));\n Py_XDECREF(*((PyObject **)(dest+i*chunk)));\n memmove(dest + i * chunk, src, chunk);\n }\n\t\t\t}\n }\n else {\n for(i=0; idata + chunk * (i % nv);\n tmp = ((Bool *)(mask->data))[i];\n if (tmp) memmove(dest + i * chunk, src, chunk);\n\t\t\t}\n\t\t}\n }\n\n Py_XDECREF(values);\n Py_XDECREF(mask);\n Py_INCREF(Py_None);\n return Py_None;\n\t\n fail:\n Py_XDECREF(mask);\n Py_XDECREF(values);\n return NULL;\n}\n\n\n/* This conversion function can be used with the \"O&\" argument for\n PyArg_ParseTuple. It will immediately return an object of array type\n or will convert to a CARRAY any other object. \n\n If you use PyArray_Converter, you must DECREF the array when finished\n as you get a new reference to it.\n*/\n \n/*MULTIARRAY_API\n Useful to pass as converter function for O& processing in\n PyArgs_ParseTuple.\n*/\nstatic int \nPyArray_Converter(PyObject *object, PyObject **address) \n{\n if (PyArray_Check(object)) {\n *address = object;\n\t\tPy_INCREF(object);\n return PY_SUCCEED;\n }\n else {\n\t\t*address = PyArray_FromAny(object, NULL, 0, 0, CARRAY_FLAGS, NULL);\n\t\tif (*address == NULL) return PY_FAIL;\n\t\treturn PY_SUCCEED;\n }\n}\n\n/*MULTIARRAY_API\n Convert an object to true / false\n*/\nstatic int\nPyArray_BoolConverter(PyObject *object, Bool *val)\n{ \n if (PyObject_IsTrue(object))\n *val=TRUE;\n else *val=FALSE;\n if (PyErr_Occurred())\n return PY_FAIL;\n return PY_SUCCEED;\n}\n\n\n/*MULTIARRAY_API\n Typestr converter\n*/\nstatic int\nPyArray_TypestrConvert(int itemsize, int gentype)\n{\n\tregister int newtype = gentype;\n\t\n\tif (gentype == PyArray_GENBOOLLTR) {\n\t\tif (itemsize == 1)\n\t\t\tnewtype = PyArray_BOOL;\n\t\telse \n\t\t\tnewtype = PyArray_NOTYPE;\n\t}\n\telse if (gentype == PyArray_SIGNEDLTR) {\n\t\tswitch(itemsize) {\n\t\tcase 1:\n\t\t\tnewtype = PyArray_INT8;\n\t\t\tbreak;\n\t\tcase 2:\n\t\t\tnewtype = PyArray_INT16;\n\t\t\tbreak;\n\t\tcase 4:\n\t\t\tnewtype = PyArray_INT32;\n\t\t\tbreak;\n\t\tcase 8:\n\t\t\tnewtype = PyArray_INT64;\n\t\t\tbreak;\n#ifdef PyArray_INT128\n\t\tcase 16:\n\t\t\tnewtype = PyArray_INT128;\n\t\t\tbreak;\n#endif\n\t\tdefault:\n\t\t\tnewtype = PyArray_NOTYPE;\n\t\t}\n\t}\n\n\telse if (gentype == PyArray_UNSIGNEDLTR) {\n\t\tswitch(itemsize) {\n\t\tcase 1:\n\t\t\tnewtype = PyArray_UINT8;\n\t\t\tbreak;\n\t\tcase 2:\n\t\t\tnewtype = PyArray_UINT16;\n\t\t\tbreak;\n\t\tcase 4:\n\t\t\tnewtype = PyArray_UINT32;\n\t\t\tbreak;\n\t\tcase 8:\n\t\t\tnewtype = PyArray_UINT64;\n\t\t\tbreak;\n#ifdef PyArray_INT128\n\t\tcase 16:\n\t\t\tnewtype = PyArray_UINT128;\n\t\t\tbreak;\n#endif\n\t\tdefault:\n\t\t\tnewtype = PyArray_NOTYPE;\n\t\t\tbreak;\n\t\t}\n\t}\n\telse if (gentype == PyArray_FLOATINGLTR) {\n\t\tswitch(itemsize) {\n\t\tcase 4:\n\t\t\tnewtype = PyArray_FLOAT32;\n\t\t\tbreak;\n\t\tcase 8:\n\t\t\tnewtype = PyArray_FLOAT64;\n\t\t\tbreak;\n#ifdef PyArray_FLOAT80\n case 10:\n\t\t\tnewtype = PyArray_FLOAT80;\n\t\t\tbreak;\n#endif\n#ifdef PyArray_FLOAT96\n\t\tcase 12:\n\t\t\tnewtype = PyArray_FLOAT96;\n\t\t\tbreak;\n#endif\t\t \n#ifdef PyArray_FLOAT128\n\t\tcase 16:\n\t\t\tnewtype = PyArray_FLOAT128;\n\t\t\tbreak;\n#endif\n\t\tdefault:\n\t\t\tnewtype = PyArray_NOTYPE;\n\t\t}\t\t\n\t}\n\t\n\telse if (gentype == PyArray_COMPLEXLTR) {\n\t\tswitch(itemsize) {\n\t\tcase 8:\n\t\t\tnewtype = PyArray_COMPLEX64;\n\t\t\tbreak;\n\t\tcase 16:\n\t\t\tnewtype = PyArray_COMPLEX128;\n\t\t\tbreak;\n#ifdef PyArray_FLOAT80\n case 20:\n\t\t\tnewtype = PyArray_COMPLEX160;\n\t\t\tbreak;\n#endif\n#ifdef PyArray_FLOAT96\n\t\tcase 24:\n\t\t\tnewtype = PyArray_COMPLEX192;\t\t\t\n\t\t\tbreak;\n#endif\t\t \n#ifdef PyArray_FLOAT128\n\t\tcase 32:\n\t\t\tnewtype = PyArray_COMPLEX256;\n\t\t\tbreak;\n#endif\n\t\tdefault:\n\t\t\tnewtype = PyArray_NOTYPE;\n\t\t}\t\t\n\t}\n\n\treturn newtype;\n}\n\n\n/* this function takes a Python object which exposes the (single-segment)\n buffer interface and returns a pointer to the data segment\n \n You should increment the reference count by one of buf->base\n if you will hang on to a reference\n\n You only get a borrowed reference to the object. Do not free the\n memory...\n*/\n\n\n/*MULTIARRAY_API\n Get buffer chunk from object\n*/\nstatic int\nPyArray_BufferConverter(PyObject *obj, PyArray_Chunk *buf)\n{\n int buflen;\n\n buf->ptr = NULL;\n buf->flags = BEHAVED_FLAGS;\n buf->base = NULL;\n\n\tif (obj == Py_None)\n\t\treturn PY_SUCCEED;\n\n if (PyObject_AsWriteBuffer(obj, &(buf->ptr), &buflen) < 0) {\n PyErr_Clear();\n buf->flags &= ~WRITEABLE;\n if (PyObject_AsReadBuffer(obj, (const void **)&(buf->ptr), \n &buflen) < 0)\n return PY_FAIL;\n }\n buf->len = (intp) buflen;\n \n /* Point to the base of the buffer object if present */\n if (PyBuffer_Check(obj)) buf->base = ((PyArray_Chunk *)obj)->base;\n if (buf->base == NULL) buf->base = obj;\n \n return PY_SUCCEED; \n}\n\n\n\n/* This function takes a Python sequence object and allocates and\n fills in an intp array with the converted values.\n\n **Remember to free the pointer seq.ptr when done using\n PyDimMem_FREE(seq.ptr)**\n*/\n\n/*MULTIARRAY_API\n Get intp chunk from sequence\n*/\nstatic int\nPyArray_IntpConverter(PyObject *obj, PyArray_Dims *seq)\n{\n int len;\n int nd;\n\n seq->ptr = NULL;\n if (obj == Py_None) return PY_SUCCEED;\n len = PySequence_Size(obj);\n if (len == -1) { /* Check to see if it is a number */\n if (PyNumber_Check(obj)) len = 1;\n }\n if (len < 0) {\n PyErr_SetString(PyExc_TypeError, \n \"expected sequence object with len >= 0\");\n return PY_FAIL;\n }\n if (len > MAX_DIMS) {\n PyErr_Format(PyExc_ValueError, \"sequence too large; \" \\\n \"must be smaller than %d\", MAX_DIMS);\n return PY_FAIL;\n }\n\tif (len > 0) {\n\t\tseq->ptr = PyDimMem_NEW(len);\n\t\tif (seq->ptr == NULL) {\n\t\t\tPyErr_NoMemory();\n\t\t\treturn PY_FAIL;\n\t\t}\n\t}\n seq->len = len;\n nd = PyArray_IntpFromSequence(obj, (intp *)seq->ptr, len);\n if (nd == -1 || nd != len) {\n\t\tPyDimMem_FREE(seq->ptr);\n\t\tseq->ptr=NULL;\n\t\treturn PY_FAIL;\n\t}\n return PY_SUCCEED;\n}\n\n\n/* A tuple type would be either (generic typeobject, typesize) \n or (fixed-length data-type, shape) \n\n or (inheriting data-type, new-data-type)\n The new data-type must have the same itemsize as the inheriting data-type\n unless the latter is 0 \n \n Thus (int32, {'real':(int16,0),'imag',(int16,2)})\n\n is one way to specify a descriptor that will give \n a['real'] and a['imag'] to an int32 array.\n*/\n\n/* leave type reference alone */\nstatic PyArray_Descr *\n_use_inherit(PyArray_Descr *type, PyObject *newobj, int *errflag) \n{\n\tPyArray_Descr *new;\n\tPyArray_Descr *conv;\n\t\n\t*errflag = 0;\n\tif (!PyArray_DescrConverter(newobj, &conv)) {\n\t\treturn NULL;\n\t}\n\t*errflag = 1;\n\tif (type == &OBJECT_Descr) {\n\t\tPyErr_SetString(PyExc_ValueError,\n\t\t\t\t\"cannot base a new descriptor on an\"\\\n\t\t\t\t\" OBJECT descriptor.\");\n\t\treturn NULL;\n\t}\n\tnew = PyArray_DescrNew(type);\n\tif (new == NULL) return NULL;\n\n\tif (new->elsize && new->elsize != conv->elsize) {\n\t\tPyErr_SetString(PyExc_ValueError, \n\t\t\t\t\"mismatch in size of old\"\\\n\t\t\t\t\"and new data-descriptor\");\n\t\treturn NULL;\n\t}\n\tnew->elsize = conv->elsize;\n\tif (conv->fields != Py_None) {\n\t\tnew->fields = conv->fields;\n\t\tPy_XINCREF(new->fields);\n\t}\n\tPy_DECREF(conv);\n\t*errflag = 0;\n\treturn new;\n}\n\nstatic PyArray_Descr *\n_convert_from_tuple(PyObject *obj) \n{\n\tPyArray_Descr *type, *res;\n\tPyObject *val;\n\tint errflag;\n\t\n\tif (PyTuple_GET_SIZE(obj) != 2) return NULL;\n\n\tif (!PyArray_DescrConverter(PyTuple_GET_ITEM(obj,0), &type)) \n\t\treturn NULL;\n\tval = PyTuple_GET_ITEM(obj,1);\n\t/* try to interpret next item as a type */\n\tres = _use_inherit(type, val, &errflag);\n\tif (res || errflag) {\n\t\tPy_DECREF(type);\n\t\tif (res) return res;\n\t\telse return NULL;\n\t}\n\tPyErr_Clear();\n\t/* We get here if res was NULL but errflag wasn't set\n\t --- i.e. the conversion to a data-descr failed in _use_inherit\n\t*/\n\n\tif (type->elsize == 0) { /* interpret next item as a typesize */\n\t\tint itemsize;\n\t\titemsize = PyArray_PyIntAsInt(PyTuple_GET_ITEM(obj,1));\n\t\tif (error_converting(itemsize)) {\n\t\t\tPyErr_SetString(PyExc_ValueError, \n\t\t\t\t\t\"invalid itemsize in generic type \"\\\n\t\t\t\t\t\"tuple\");\n\t\t\tgoto fail;\n\t\t}\n\t\tPyArray_DESCR_REPLACE(type);\n\t\ttype->elsize = itemsize;\n\t}\n\telse {\n\t\t/* interpret next item as shape (if it's a tuple)\n\t\t and reset the type to PyArray_VOID with \n\t\t anew fields attribute. \n\t */\n\t\tPyArray_Dims shape={NULL,-1};\n\t\tPyArray_Descr *newdescr;\n\t\tif (!(PyArray_IntpConverter(val, &shape)) || \n\t\t (shape.len > MAX_DIMS)) {\n\t\t\tPyDimMem_FREE(shape.ptr);\n\t\t\tPyErr_SetString(PyExc_ValueError, \n\t\t\t\t\t\"invalid shape in fixed-type tuple.\");\n\t\t\tgoto fail;\n\t\t}\n\t\t/* If (type, 1) was given, it is equivalent to type... */\n\t\tif (shape.len == 1 && shape.ptr[0] == 1 && PyNumber_Check(val)) {\n\t\t\tPyDimMem_FREE(shape.ptr);\n\t\t\treturn type;\n\t\t}\n\t\tnewdescr = PyArray_DescrNewFromType(PyArray_VOID);\n\t\tif (newdescr == NULL) {PyDimMem_FREE(shape.ptr); goto fail;}\n\t\tnewdescr->elsize = type->elsize;\n\t\tnewdescr->elsize *= PyArray_MultiplyList(shape.ptr, \n\t\t\t\t\t\t\t shape.len);\n\t\tPyDimMem_FREE(shape.ptr);\n\t\tnewdescr->subarray = _pya_malloc(sizeof(PyArray_ArrayDescr));\n\t\tnewdescr->subarray->base = type;\n\t\tPy_INCREF(val);\n\t\tnewdescr->subarray->shape = val;\n\t\tPy_XDECREF(newdescr->fields);\n\t\tnewdescr->fields = NULL;\n\t\ttype = newdescr;\n\t}\n\treturn type;\n\n fail:\n\tPy_XDECREF(type);\n\treturn NULL;\n}\n\n/* obj is a list. Each item is a tuple with\n\n(field-name, data-type (either a list or a string), and an optional \n shape parameter).\n*/\nstatic PyArray_Descr *\n_convert_from_array_descr(PyObject *obj)\n{\n\tint n, i, totalsize;\n\tint ret;\n\tPyObject *fields, *item, *newobj;\n\tPyObject *name, *key, *tup;\n\tPyObject *nameslist;\n\tPyArray_Descr *new;\n\tPyArray_Descr *conv;\n int hasobject=0;\n\t\n\tn = PyList_GET_SIZE(obj);\t\n\tnameslist = PyList_New(n);\n\tif (!nameslist) return NULL;\n\ttotalsize = 0;\n\tfields = PyDict_New();\n\tfor (i=0; ihasobject)\n hasobject = 1;\n\t\ttup = PyTuple_New(2);\n\t\tPyTuple_SET_ITEM(tup, 0, (PyObject *)conv);\n\t\tPyTuple_SET_ITEM(tup, 1, PyInt_FromLong((long) totalsize));\n\t\ttotalsize += conv->elsize;\n\t\tPyDict_SetItem(fields, name, tup);\n\t\tPy_DECREF(tup);\n\t}\n\tkey = PyInt_FromLong(-1);\n\tPyDict_SetItem(fields, key, nameslist);\n\tPy_DECREF(key);\n\tPy_DECREF(nameslist);\n\tnew = PyArray_DescrNewFromType(PyArray_VOID);\n\tnew->fields = fields;\n\tnew->elsize = totalsize;\n new->hasobject=hasobject;\n\treturn new;\n \n fail:\n\tPy_DECREF(fields);\n\tPy_DECREF(nameslist);\n\treturn NULL;\n\n}\n\n/* a list specifying a data-type can just be\n a list of formats. The names for the fields\n will default to f1, f2, f3, and so forth.\n\n or it can be an array_descr format string -- in which case\n align must be 0. \n*/\n\nstatic PyArray_Descr *\n_convert_from_list(PyObject *obj, int align, int try_descr)\n{\n\tint n, i;\n\tint totalsize;\n\tPyObject *fields;\n\tPyArray_Descr *conv=NULL;\n\tPyArray_Descr *new;\n\tPyObject *key, *tup;\n\tPyObject *nameslist=NULL;\n \tint ret;\n\tint maxalign=0;\n int hasobject=0;\n\t\n\tn = PyList_GET_SIZE(obj);\n\ttotalsize = 0;\n\tif (n==0) return NULL;\n\tnameslist = PyList_New(n);\n\tif (!nameslist) return NULL;\n\tfields = PyDict_New();\n\tfor (i=0; ihasobject)\n hasobject=1; \n\t\tPyTuple_SET_ITEM(tup, 0, (PyObject *)conv);\n\t\tif (align) {\n\t\t\tint _align;\n\t\t\t_align = conv->alignment;\n\t\t\tif (_align > 1) totalsize =\t\t\t\\\n\t\t\t\t((totalsize + _align - 1)/_align)*_align;\n\t\t\tmaxalign = MAX(maxalign, _align);\n\t\t}\n\t\tPyTuple_SET_ITEM(tup, 1, PyInt_FromLong((long) totalsize));\n\t\tPyDict_SetItem(fields, key, tup);\n\t\tPy_DECREF(tup);\n\t\tPyList_SET_ITEM(nameslist, i, key);\n\t\tif (ret == PY_FAIL) goto fail;\n\t\ttotalsize += conv->elsize;\n\t}\n\tkey = PyInt_FromLong(-1);\n\tPyDict_SetItem(fields, key, nameslist);\n\tPy_DECREF(key);\n\tPy_DECREF(nameslist);\n\tnew = PyArray_DescrNewFromType(PyArray_VOID);\n\tnew->fields = fields;\n 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; ihasobject)\n hasobject = 1;\n\t\tPy_DECREF(descr);\n\t\tPyTuple_SET_ITEM(tup, 0, (PyObject *)newdescr);\n\t\tif (offsets) {\n\t\t\tlong offset;\n\t\t\toff = PyObject_GetItem(offsets, index);\n\t\t\toffset = PyInt_AsLong(off);\n\t\t\tPyTuple_SET_ITEM(tup, 1, off);\n\t\t\tif (offset < totalsize) {\n\t\t\t\tPyErr_SetString(PyExc_ValueError,\n\t\t\t\t\t\t\"invalid offset (must be \"\\\n\t\t\t\t\t\t\"ordered)\");\n\t\t\t\tret = PY_FAIL;\n\t\t\t}\n\t\t\tif (offset > totalsize) totalsize = offset;\n\t\t}\n\t\telse {\n\t\t\tif (align) {\n\t\t\t\tint _align = newdescr->alignment;\n\t\t\t\tif (_align > 1) totalsize =\t\t\\\n\t\t\t\t\t((totalsize + _align - 1)/_align)*_align;\n\t\t\t\tmaxalign = MAX(maxalign,_align);\n\t\t\t}\n\t\t\tPyTuple_SET_ITEM(tup, 1, PyInt_FromLong(totalsize));\n\t\t}\n\t\tif (len == 3) PyTuple_SET_ITEM(tup, 2, item);\n\t\tname = PyObject_GetItem(names, index);\n\t\tPy_DECREF(index);\n\n\t\t/* Insert into dictionary */\n\t\tif (PyDict_GetItem(fields, name) != NULL) {\n\t\t\tPyErr_SetString(PyExc_ValueError,\n\t\t\t\t\t\"two fields with the same name\");\n\t\t\tret = PY_FAIL;\n\t\t}\n\t\tPyDict_SetItem(fields, name, tup);\n\t\tPy_DECREF(name);\n\t\tif (len == 3) PyDict_SetItem(fields, item, tup);\n\t\tPy_DECREF(tup);\n\t\tif ((ret == PY_FAIL) || (newdescr->elsize == 0)) goto fail;\n\t\ttotalsize += newdescr->elsize;\n\t}\n\n\tnew = PyArray_DescrNewFromType(PyArray_VOID);\n\tif (new == NULL) goto fail;\n\tif (maxalign > 1)\n\t\ttotalsize = ((totalsize + maxalign - 1)/maxalign)*maxalign;\n\tif (align) new->alignment = maxalign;\n\tnew->elsize = totalsize;\n\tkey = PyInt_FromLong(-1);\n\tPyDict_SetItem(fields, key, names);\n\tPy_DECREF(key);\n\tnew->fields = fields;\n new->hasobject=hasobject;\n\treturn new;\n\n fail:\n\tPy_XDECREF(fields);\n\treturn NULL;\n}\n\n/* \n any object with \n the .fields attribute and/or .itemsize attribute \n (if the .fields attribute does not give\n the total size -- i.e. a partial record naming).\n If itemsize is given it must be >= size computed from fields\n \n The .fields attribute must return a convertible dictionary if \n present. Result inherits from PyArray_VOID.\n*/\n\n\n/*MULTIARRAY_API\n Get typenum from an object -- None goes to NULL\n*/\nstatic int\nPyArray_DescrConverter2(PyObject *obj, PyArray_Descr **at)\n{\n\tif (obj == Py_None) {\n\t\t*at = NULL;\n\t\treturn PY_SUCCEED;\n\t}\n\telse return PyArray_DescrConverter(obj, at);\n}\n\n/* This function takes a Python object representing a type and converts it \n to a the correct PyArray_Descr * structure to describe the type.\n \n Many objects can be used to represent a data-type which in NumPy is\n quite a flexible concept. \n\n This is the central code that converts Python objects to \n Type-descriptor objects that are used throughout numpy.\n */\n\n/* new reference in *at */\n/*MULTIARRAY_API\n Get typenum from an object -- None goes to &LONG_descr\n*/\nstatic int\nPyArray_DescrConverter(PyObject *obj, PyArray_Descr **at)\n{\n char *type;\n int check_num=PyArray_NOTYPE+10;\n\tint len;\n\tPyObject *item;\n\tint elsize = 0;\n\tchar endian = '=';\n\n\t*at=NULL;\n\t\n\t/* default */\n if (obj == Py_None) {\n\t\t*at = PyArray_DescrFromType(PyArray_LONG);\n\t\treturn PY_SUCCEED;\n\t}\n\t\n\tif (PyArray_DescrCheck(obj)) {\n\t\t*at = (PyArray_Descr *)obj;\n\t\tPy_INCREF(*at);\n\t\treturn PY_SUCCEED;\n\t}\n\t\n if (PyType_Check(obj)) {\n\t\tif (PyType_IsSubtype((PyTypeObject *)obj, \n\t\t\t\t &PyGenericArrType_Type)) {\n\t\t\t*at = PyArray_DescrFromTypeObject(obj);\n\t\t\tif (*at) return PY_SUCCEED;\n\t\t\telse return PY_FAIL;\n\t\t}\n\t\tcheck_num = PyArray_OBJECT;\n\t\tif (obj == (PyObject *)(&PyInt_Type))\n\t\t\tcheck_num = PyArray_LONG;\n\t\telse if (obj == (PyObject *)(&PyLong_Type))\n\t\t\tcheck_num = PyArray_LONGLONG;\n\t\telse if (obj == (PyObject *)(&PyFloat_Type)) \n\t\t\tcheck_num = PyArray_DOUBLE;\n\t\telse if (obj == (PyObject *)(&PyComplex_Type)) \n\t\t\tcheck_num = PyArray_CDOUBLE;\n\t\telse if (obj == (PyObject *)(&PyBool_Type))\n\t\t\tcheck_num = PyArray_BOOL;\n else if (obj == (PyObject *)(&PyString_Type))\n check_num = PyArray_STRING;\n else if (obj == (PyObject *)(&PyUnicode_Type))\n check_num = PyArray_UNICODE;\n\t\telse if (obj == (PyObject *)(&PyBuffer_Type))\n\t\t\tcheck_num = PyArray_VOID;\n\t\telse {\n\t\t\t*at = _arraydescr_fromobj(obj);\n\t\t\tif (*at) return PY_SUCCEED;\n\t\t}\n\t\tgoto finish;\n\t}\n\n\t/* or a typecode string */\n\n\tif (PyString_Check(obj)) {\n\t\t/* Check for a string typecode. */\n\t\ttype = PyString_AS_STRING(obj);\n\t\tlen = PyString_GET_SIZE(obj);\n\t\tif (len <= 0) goto fail;\n\t\tcheck_num = (int) type[0];\n\t\tif ((char) check_num == '>' || (char) check_num == '<' || \\\n\t\t (char) check_num == '|' || (char) check_num == '=') {\n\t\t\tif (len <= 1) goto fail;\n\t\t\tendian = (char) check_num;\n\t\t\ttype++; len--;\n\t\t\tcheck_num = (int) type[0];\n\t\t\tif (endian == '|') endian = '=';\n\t\t}\n\t\tif (len > 1) {\n\t\t\tint i;\n\t\t\telsize = atoi(type+1);\n\t\t\t/* check for commas present */\n\t\t\tfor (i=1;ielsize == 0) && (elsize != 0)) {\n\t\tPyArray_DESCR_REPLACE(*at);\n\t\t(*at)->elsize = elsize;\n\t}\n\tif (endian != '=' && PyArray_ISNBO(endian)) endian = '='; \n\t\n\tif (endian != '=' && (*at)->byteorder != '|' &&\t\\\n\t (*at)->byteorder != endian) {\n\t\tPyArray_DESCR_REPLACE(*at);\n\t\t(*at)->byteorder = endian;\n\t}\n\t\n return PY_SUCCEED;\n\n fail:\n\tPyErr_SetString(PyExc_TypeError, \n\t\t\t\"data type not understood\");\n\t*at=NULL;\n\treturn PY_FAIL;\n}\t\n\n/*MULTIARRAY_API\n Convert object to endian\n*/\nstatic int\nPyArray_ByteorderConverter(PyObject *obj, char *endian)\n{\n\tchar *str;\n\t*endian = PyArray_SWAP;\n\tstr = PyString_AsString(obj);\n\tif (!str) return PY_FAIL;\n\tif (strlen(str) < 1) {\n\t\tPyErr_SetString(PyExc_ValueError, \n\t\t\t\t\"Byteorder string must be at least length 1\");\n\t\treturn PY_FAIL;\n\t}\n\t*endian = str[0];\n\tif (str[0] != PyArray_BIG && str[0] != PyArray_LITTLE &&\t\\\n\t str[0] != PyArray_NATIVE) {\n\t\tif (str[0] == 'b' || str[0] == 'B')\n\t\t\t*endian = PyArray_BIG;\n\t\telse if (str[0] == 'l' || str[0] == 'L')\n\t\t\t*endian = PyArray_LITTLE;\n\t\telse if (str[0] == 'n' || str[0] == 'N')\n\t\t\t*endian = PyArray_NATIVE;\n\t\telse if (str[0] == 'i' || str[0] == 'I')\n\t\t\t*endian = PyArray_IGNORE;\n\t\telse if (str[0] == 's' || str[0] == 'S')\n\t\t\t*endian = PyArray_SWAP;\n\t\telse {\n\t\t\tPyErr_Format(PyExc_ValueError, \n\t\t\t\t \"%s is an unrecognized byteorder\",\n\t\t\t\t str);\n\t\t\treturn PY_FAIL;\n\t\t}\n\t}\n\treturn PY_SUCCEED;\n}\n\n/*MULTIARRAY_API\n Convert object to sort kind \n*/\nstatic int\nPyArray_SortkindConverter(PyObject *obj, PyArray_SORTKIND *sortkind)\n{\n\tchar *str;\n\t*sortkind = PyArray_QUICKSORT;\n\tstr = PyString_AsString(obj);\n\tif (!str) return PY_FAIL;\n\tif (strlen(str) < 1) {\n\t\tPyErr_SetString(PyExc_ValueError, \n\t\t\t\t\"Sort kind string must be at least length 1\");\n\t\treturn PY_FAIL;\n\t}\n\tif (str[0] == 'q' || str[0] == 'Q')\n\t\t*sortkind = PyArray_QUICKSORT;\n\telse if (str[0] == 'h' || str[0] == 'H')\n\t\t*sortkind = PyArray_HEAPSORT;\n\telse if (str[0] == 'm' || str[0] == 'M')\n\t\t*sortkind = PyArray_MERGESORT;\n\telse if (str[0] == 't' || str[0] == 'T')\n\t\t*sortkind = PyArray_TIMSORT;\n\telse {\n\t\tPyErr_Format(PyExc_ValueError, \n\t\t\t \"%s is an unrecognized kind of sort\",\n\t\t\t str);\n\t\treturn PY_FAIL;\n\t}\n\treturn PY_SUCCEED;\n}\n\n\n/* This function returns true if the two typecodes are \n equivalent (same basic kind and same itemsize).\n*/\n\n/*MULTIARRAY_API*/\nstatic Bool\nPyArray_EquivTypes(PyArray_Descr *typ1, PyArray_Descr *typ2)\n{\n\tregister int typenum1=typ1->type_num;\n\tregister int typenum2=typ2->type_num;\n\tregister int size1=typ1->elsize;\n\tregister int size2=typ2->elsize;\n\n\tif (size1 != size2) return FALSE;\n\tif (typ1->fields != typ2->fields) return FALSE;\n\tif (PyArray_ISNBO(typ1->byteorder) != PyArray_ISNBO(typ2->byteorder))\n\t\treturn FALSE;\n\n\tif (typenum1 == PyArray_VOID || \\\n\t typenum2 == PyArray_VOID) {\n\t\treturn ((typenum1 == typenum2) && \n\t\t\t(typ1->typeobj == typ2->typeobj) &&\n\t\t\t(typ1->fields == typ2->fields));\n\t}\n\treturn (typ1->kind == typ2->kind);\n}\n\n/*** END C-API FUNCTIONS **/\n\nstatic PyObject *\n_prepend_ones(PyArrayObject *arr, int nd, int ndmin)\n{\n\tintp newdims[MAX_DIMS];\n\tintp newstrides[MAX_DIMS];\n\tint i,k,num;\n\tPyObject *ret;\n\n\tnum = ndmin-nd;\n\tfor (i=0; idescr->elsize;\n\t}\n\tfor (i=num;idimensions[k];\n\t\tnewstrides[i] = arr->strides[k];\n\t}\n\tPy_INCREF(arr->descr);\n\tret = PyArray_NewFromDescr(arr->ob_type, arr->descr, ndmin,\n\t\t\t\t newdims, newstrides, arr->data, arr->flags,\n\t\t\t\t (PyObject *)arr);\n\t/* steals a reference to arr --- so don't increment\n\t here */\n\tPyArray_BASE(ret) = (PyObject *)arr;\n\treturn ret;\n}\n\n\n#define _ARET(x) PyArray_Return((PyArrayObject *)(x))\n\nstatic char doc_fromobject[] = \"array(object, dtype=None, copy=1, fortran=0, \"\\\n \"subok=0,ndmin=0)\\n\"\\\n \"will return a new array formed from the given object type given.\\n\"\\\n \"Object can anything with an __array__ method, or any object\\n\"\\\n \"exposing the array interface, or any (nested) sequence.\\n\"\\\n \"If no type is given, then the type will be determined as the\\n\"\\\n \"minimum type required to hold the objects in the sequence.\\n\"\\\n \"If copy is zero and sequence is already an array with the right \\n\"\\\n \"type, a reference will be returned. If the sequence is an array,\\n\"\\\n \"type can be used only to upcast the array. For downcasting \\n\"\\\n \"use .astype(t) method. If subok is true, then subclasses of the\\n\"\\\n \"array may be returned. Otherwise, a base-class ndarray is returned\\n\"\\\n\t\"The ndmin argument specifies how many dimensions the returned\\n\"\\\n\t\"array should have as a minimum. 1's will be pre-pended to the\\n\"\\\n\t\"shape as needed to meet this requirement.\";\n\nstatic PyObject *\n_array_fromobject(PyObject *ignored, PyObject *args, PyObject *kws)\n{\n\tPyObject *op, *ret=NULL;\n\tstatic char *kwd[]= {\"object\", \"dtype\", \"copy\", \"fortran\", \"subok\", \n\t\t\t \"ndmin\", NULL};\n Bool subok=FALSE;\n\tBool copy=TRUE;\n\tint ndmin=0, nd;\n\tPyArray_Descr *type=NULL;\n\tPyArray_Descr *oldtype=NULL;\n\tBool fortran=FALSE;\n\tint flags=0;\n\n\tif(!PyArg_ParseTupleAndKeywords(args, kws, \"O|O&O&O&O&i\", kwd, &op, \n\t\t\t\t\tPyArray_DescrConverter2,\n &type, \n\t\t\t\t\tPyArray_BoolConverter, ©, \n\t\t\t\t\tPyArray_BoolConverter, &fortran,\n PyArray_BoolConverter, &subok, \n\t\t\t\t\t&ndmin)) \n\t\treturn NULL;\n\n\t/* fast exit if simple call */\n\tif ((PyArray_CheckExact(op) || PyBigArray_CheckExact(op))) {\n\t\tif (type==NULL) {\n\t\t\tif (!copy && fortran==PyArray_ISFORTRAN(op)) {\n\t\t\t\tPy_INCREF(op);\n\t\t\t\tret = op;\n\t\t\t\tgoto finish;\n\t\t\t}\n\t\t\telse {\n\t\t\t\tret = PyArray_NewCopy((PyArrayObject*)op, \n\t\t\t\t\t\t fortran);\n\t\t\t\tgoto finish;\n\t\t\t}\n\t\t}\n\t\t/* One more chance */\n\t\toldtype = PyArray_DESCR(op);\n\t\tif (PyArray_EquivTypes(oldtype, type)) {\n\t\t\tif (!copy && fortran==PyArray_ISFORTRAN(op)) {\n\t\t\t\tPy_INCREF(op);\n\t\t\t\tret = op;\n\t\t\t\tgoto finish;\n\t\t\t}\n\t\t\telse {\n\t\t\t\tret = PyArray_NewCopy((PyArrayObject*)op,\n\t\t\t\t\t\t fortran);\n\t\t\t\tif (oldtype == type) return ret;\n\t\t\t\tPy_INCREF(oldtype);\n\t\t\t\tPy_DECREF(PyArray_DESCR(ret));\n\t\t\t\tPyArray_DESCR(ret) = oldtype;\n\t\t\t\tgoto finish;\n\t\t\t}\n\t\t}\n\t}\n\n\tif (copy) {\n\t\tflags = ENSURECOPY;\n\t}\n\tif (fortran) {\n\t\tflags |= FORTRAN;\n\t}\n if (!subok) {\n flags |= ENSUREARRAY;\n }\n\n\tif ((ret = PyArray_CheckFromAny(op, type, 0, 0, flags, NULL)) == NULL) \n\t\treturn NULL;\n\n finish:\n\n\tif ((nd=PyArray_NDIM(ret)) >= ndmin) return ret;\n\t/* create a new array from the same data with ones in the shape */\n\t/* steals a reference to ret */\n\treturn _prepend_ones((PyArrayObject *)ret, nd, ndmin);\n}\n\n/* accepts NULL type */\n/* steals referenct to type */\n/*MULTIARRAY_API\n Empty\n*/\nstatic PyObject *\nPyArray_Empty(int nd, intp *dims, PyArray_Descr *type, int fortran)\n{\n\tPyArrayObject *ret;\n \n\tif (!type) type = PyArray_DescrFromType(PyArray_LONG);\n\tret = (PyArrayObject *)PyArray_NewFromDescr(&PyArray_Type, \n\t\t\t\t\t\t type, nd, dims, \n\t\t\t\t\t\t NULL, NULL,\n\t\t\t\t\t\t fortran, NULL);\n\tif (ret == NULL) return NULL;\n \n\tif ((PyArray_TYPE(ret) == PyArray_OBJECT)) {\n PyArray_FillObjectArray(ret, Py_None);\n\t}\n\treturn (PyObject *)ret;\n}\n\n\nstatic char doc_empty[] = \"empty((d1,...,dn),dtype=int,fortran=0) will return a new array\\n of shape (d1,...,dn) and given type with all its entries uninitialized. This can be faster than zeros.\";\n\nstatic PyObject *\narray_empty(PyObject *ignored, PyObject *args, PyObject *kwds) \n{\n \n\tstatic char *kwlist[] = {\"shape\",\"dtype\",\"fortran\",NULL};\n\tPyArray_Descr *typecode=NULL;\n PyArray_Dims shape = {NULL, 0};\n\tBool fortran = FALSE;\t\n PyObject *ret=NULL;\n\n\tif (!PyArg_ParseTupleAndKeywords(args, kwds, \"O&|O&O&\",\n\t\t\t\t\t kwlist, PyArray_IntpConverter,\n &shape, \n PyArray_DescrConverter,\n\t\t\t\t\t &typecode, \n\t\t\t\t\t PyArray_BoolConverter, &fortran)) \n\t\tgoto fail;\n\n\tret = PyArray_Empty(shape.len, shape.ptr, typecode, fortran); \n PyDimMem_FREE(shape.ptr);\n return ret;\n\n fail:\n\tPyDimMem_FREE(shape.ptr);\n\treturn ret;\n}\n\nstatic char doc_scalar[] = \"scalar(dtype,obj) will return a new scalar array of the given type initialized with obj. Mainly for pickle support. The dtype must be a valid data-type descriptor. If dtype corresponds to an OBJECT descriptor, then obj can be any object, otherwise obj must be a string. If obj is not given it will be interpreted as None for object type and zeros for all other types.\";\n\nstatic PyObject *\narray_scalar(PyObject *ignored, PyObject *args, PyObject *kwds) \n{\n \n\tstatic char *kwlist[] = {\"dtype\",\"obj\", NULL};\n\tPyArray_Descr *typecode;\n\tPyObject *obj=NULL;\n\tint alloc=0;\n\tvoid *dptr;\n\tPyObject *ret;\n\n\t\n\tif (!PyArg_ParseTupleAndKeywords(args, kwds, \"O!|O\",\n\t\t\t\t\t kwlist, &PyArrayDescr_Type, \n\t\t\t\t\t &typecode,\n\t\t\t\t\t &obj)) \n\t\treturn NULL;\n\t\t\n\tif (typecode->elsize == 0) {\n\t\tPyErr_SetString(PyExc_ValueError,\t\t\\\n\t\t\t\t\"itemsize cannot be zero\");\n\t\treturn NULL;\n\t}\n\n\tif (typecode->type_num == PyArray_OBJECT) {\n\t\tif (obj == NULL) obj = Py_None;\n\t\tdptr = &obj;\n\t}\n\telse {\n\t\tif (obj == NULL) {\n\t\t\tdptr = _pya_malloc(typecode->elsize);\n\t\t\tif (dptr == NULL) {\n\t\t\t\treturn PyErr_NoMemory();\n\t\t\t}\n\t\t\tmemset(dptr, '\\0', typecode->elsize);\n\t\t\talloc = 1;\n\t\t}\n\t\telse {\n\t\t\tif (!PyString_Check(obj)) {\n\t\t\t\tPyErr_SetString(PyExc_TypeError, \n\t\t\t\t\t\t\"initializing object must \"\\\n\t\t\t\t\t\t\"be a string\");\n\t\t\t\treturn NULL;\n\t\t\t}\n\t\t\tif (PyString_GET_SIZE(obj) < typecode->elsize) {\n\t\t\t\tPyErr_SetString(PyExc_ValueError,\n\t\t\t\t\t\t\"initialization string is too\"\\\n\t\t\t\t\t\t\" small\");\n\t\t\t\treturn NULL;\n\t\t\t}\n\t\t\tdptr = PyString_AS_STRING(obj);\n\t\t}\n\t}\n\n\tret = PyArray_Scalar(dptr, typecode, NULL);\n\t\n\t/* free dptr which contains zeros */\n\tif (alloc) _pya_free(dptr);\n\treturn ret;\n}\n\n\n/* steal a reference */\n/* accepts NULL type */\n/*MULTIARRAY_API\n Zeros\n*/\nstatic PyObject *\nPyArray_Zeros(int nd, intp *dims, PyArray_Descr *type, int fortran)\n{\n\tPyArrayObject *ret;\n\tintp n;\n\n\tif (!type) type = PyArray_DescrFromType(PyArray_LONG);\n\tret = (PyArrayObject *)PyArray_NewFromDescr(&PyArray_Type, \n\t\t\t\t\t\t type,\n\t\t\t\t\t\t nd, dims, \n\t\t\t\t\t\t NULL, NULL, \n\t\t\t\t\t\t fortran, NULL);\n\tif (ret == NULL) return NULL;\n \n\tif ((PyArray_TYPE(ret) == PyArray_OBJECT)) {\n\t\tPyObject *zero = PyInt_FromLong(0);\n PyArray_FillObjectArray(ret, zero);\n Py_DECREF(zero);\n\t}\n\telse {\n\t\tn = PyArray_NBYTES(ret);\n\t\tmemset(ret->data, 0, n);\n\t}\n\treturn (PyObject *)ret;\n\n}\n\nstatic char doc_zeros[] = \"zeros((d1,...,dn),dtype=int,fortran=0) will return a new array of shape (d1,...,dn) and type typecode with all it's entries initialized to zero.\";\n\n\nstatic PyObject *\narray_zeros(PyObject *ignored, PyObject *args, PyObject *kwds) \n{\n\tstatic char *kwlist[] = {\"shape\",\"dtype\",\"fortran\",NULL}; /* XXX ? */\n\tPyArray_Descr *typecode=NULL;\n PyArray_Dims shape = {NULL, 0};\n\tBool fortran = FALSE;\t\n PyObject *ret=NULL;\n\n\tif (!PyArg_ParseTupleAndKeywords(args, kwds, \"O&|O&O&\",\n\t\t\t\t\t kwlist, PyArray_IntpConverter,\n &shape, \n PyArray_DescrConverter,\n\t\t\t\t\t &typecode, \n\t\t\t\t\t PyArray_BoolConverter,\n\t\t\t\t\t &fortran)) \n\t\tgoto fail;\n\n\tret = PyArray_Zeros(shape.len, shape.ptr, typecode, (int) fortran);\n PyDimMem_FREE(shape.ptr);\n return ret;\n\n fail:\n\tPyDimMem_FREE(shape.ptr);\n\treturn ret;\n}\n\nstatic char doc_set_typeDict[] = \"set_typeDict(dict) set the internal \"\\\n\t\"dictionary that can look up an array type using a registered \"\\\n\t\"code\";\n\nstatic PyObject *\narray_set_typeDict(PyObject *ignored, PyObject *args)\n{\n\tPyObject *dict;\n\tif (!PyArg_ParseTuple(args, \"O\", &dict)) return NULL;\n\tPy_XDECREF(typeDict); /* Decrement old reference (if any)*/\n\ttypeDict = dict;\n\tPy_INCREF(dict); /* Create an internal reference to it */\n\tPy_INCREF(Py_None);\n\treturn Py_None;\n}\n\nstatic int\n_skip_sep(char **ptr, char *sep)\n{\n\tchar *a;\n\tint n;\n\tn = strlen(sep);\n\ta = *ptr;\n\twhile(*a != '\\0' && (strncmp(a, sep, n) != 0))\n\t\ta++;\n\tif (*a == '\\0') return -1;\n\t*ptr = a+strlen(sep);\n\treturn 0;\n}\n\n/* steals a reference to dtype -- accepts NULL */\n/*OBJECT_API*/\nstatic PyObject *\nPyArray_FromString(char *data, intp slen, PyArray_Descr *dtype, \n\t\t intp n, char *sep)\n{\n\tint itemsize;\n\tPyArrayObject *ret;\n\tBool binary;\n\n\tif (dtype == NULL)\n\t\tdtype=PyArray_DescrFromType(PyArray_LONG);\n\t\n\titemsize = dtype->elsize;\n\tif (itemsize == 0) {\n\t\tPyErr_SetString(PyExc_ValueError, \"zero-valued itemsize\");\n\t\tPy_DECREF(dtype);\n\t\treturn NULL;\n\t}\n\n\tbinary = ((sep == NULL) || (strlen(sep) == 0));\t\n\n\tif (binary) {\n\t\tif (dtype == &OBJECT_Descr) {\n\t\t\tPyErr_SetString(PyExc_ValueError, \n\t\t\t\t\t\"Cannot create an object array from\"\\\n\t\t\t\t\t\" a binary string\");\n\t\t\tPy_DECREF(dtype);\n\t\t\treturn NULL;\n\t\t}\t\t\n\t\tif (n < 0 ) {\n\t\t\tif (slen % itemsize != 0) {\n\t\t\t\tPyErr_SetString(PyExc_ValueError, \n\t\t\t\t\t\t\"string size must be a \"\\\n\t\t\t\t\t\t\"multiple of element size\");\n\t\t\t\tPy_DECREF(dtype);\n\t\t\t\treturn NULL;\n\t\t\t}\n\t\t\tn = slen/itemsize;\n\t\t} else {\n\t\t\tif (slen < n*itemsize) {\n\t\t\t\tPyErr_SetString(PyExc_ValueError, \n\t\t\t\t\t\t\"string is smaller than \" \\\n\t\t\t\t\t\t\"requested size\");\n\t\t\t\tPy_DECREF(dtype);\n\t\t\t\treturn NULL;\n\t\t\t}\n\t\t}\n\t\n\t\tif ((ret = (PyArrayObject *)\\\n\t\t PyArray_NewFromDescr(&PyArray_Type, dtype,\n\t\t\t\t\t 1, &n, NULL, NULL,\n\t\t\t\t\t 0, NULL)) == NULL)\n\t\t\treturn NULL;\t\t\n\t\tmemcpy(ret->data, data, n*dtype->elsize);\n\t\treturn (PyObject *)ret;\n\t}\n\telse { /* read from character-based string */\n\t\tchar *ptr;\t\t\n\t\tPyArray_FromStrFunc *fromstr;\n\t\tchar *dptr;\n\t\tintp nread=0;\n\t\tintp index;\n\n\t\tfromstr = dtype->f->fromstr;\n\t\tif (fromstr == NULL) {\n\t\t\tPyErr_SetString(PyExc_ValueError, \n\t\t\t\t\t\"don't know how to read \"\t\\\n\t\t\t\t\t\"character strings for given \"\t\\\n\t\t\t\t\t\"array type\");\n\t\t\tPy_DECREF(dtype);\n\t\t\treturn NULL;\n\t\t}\n\n\t\tif (n!=-1) {\n\t\t\tret = (PyArrayObject *) \\\n\t\t\t\tPyArray_NewFromDescr(&PyArray_Type,\n\t\t\t\t\t\t dtype, 1, &n, NULL,\n\t\t\t\t\t\t NULL, 0, NULL);\n\t\t\tif (ret == NULL) return NULL;\n\t\t\tptr = data;\n\t\t\tdptr = ret->data;\n\t\t\tfor (index=0; index < n; index++) {\n\t\t\t\tif (fromstr(ptr, dptr, &ptr, ret) < 0)\n\t\t\t\t\tbreak;\n\t\t\t\tnread += 1;\n\t\t\t\tdptr += dtype->elsize;\n\t\t\t\tif (_skip_sep(&ptr, sep) < 0) \n\t\t\t\t\tbreak;\n\t\t\t}\n\t\t\tif (nread < n) {\n\t\t\t\tfprintf(stderr, \"%ld items requested but \"\\\n\t\t\t\t\t\"only %ld read\\n\", \n\t\t\t\t\t(long) n, (long) nread);\n\t\t\t\tret->data = \\\n\t\t\t\t\tPyDataMem_RENEW(ret->data, \n\t\t\t\t\t\t\tnread *\t\t\\\n\t\t\t\t\t\t\tret->descr->elsize);\n\t\t\t\tPyArray_DIM(ret,0) = nread;\n\t\t\t}\n\t\t}\n\t\telse {\n#define _FILEBUFNUM 4096\n\t\t\tintp thisbuf=0;\n\t\t\tintp size = _FILEBUFNUM;\n\t\t\tintp bytes;\n\t\t\tintp totalbytes;\n\t\t\tchar *end;\n\t\t\tint val;\n\n\t\t\tret = (PyArrayObject *)\\\n\t\t\t\tPyArray_NewFromDescr(&PyArray_Type, \n\t\t\t\t\t\t dtype,\n\t\t\t\t\t\t 1, &size, \n\t\t\t\t\t\t NULL, NULL, \n\t\t\t\t\t\t 0, NULL);\n\t\t\tif (ret==NULL) return NULL;\n\t\t\ttotalbytes = bytes = size * dtype->elsize;\n\t\t\tdptr = ret->data;\n\t\t\tptr = data;\n\t\t\tend = data+slen;\n\t\t\twhile (ptr < end) {\n\t\t\t\tval = fromstr(ptr, dptr, &ptr, ret);\n\t\t\t\tif (val < 0) break;\n\t\t\t\tnread += 1;\n\t\t\t\tval = _skip_sep(&ptr, sep);\n\t\t\t\tif (val < 0) break;\n\t\t\t\tthisbuf += 1;\n\t\t\t\tdptr += dtype->elsize;\n\t\t\t\tif (thisbuf == size) {\n\t\t\t\t\ttotalbytes += bytes;\n\t\t\t\t\tret->data = PyDataMem_RENEW(ret->data, \n\t\t\t\t\t\t\t\t totalbytes);\n\t\t\t\t\tdptr = ret->data + \\\n\t\t\t\t\t\t(totalbytes - bytes);\n\t\t\t\t\tthisbuf = 0;\n\t\t\t\t}\n\t\t\t}\n\t\t\tret->data = PyDataMem_RENEW(ret->data, \n\t\t\t\t\t\t nread*ret->descr->elsize);\n\t\t\tPyArray_DIM(ret,0) = nread;\n#undef _FILEBUFNUM\n\t\t}\n\t}\n\treturn (PyObject *)ret;\n}\n\nstatic char doc_fromString[] = \"fromstring(string, dtype=int, count=-1) returns a new 1d array initialized from the raw binary data in string. If count is positive, the new array will have count elements, otherwise it's size is determined by the size of string.\";\n\nstatic PyObject *\narray_fromString(PyObject *ignored, PyObject *args, PyObject *keywds)\n{\n\tchar *data;\n\tlonglong nin=-1;\n\tchar *sep=NULL;\n\tint s;\n\tstatic char *kwlist[] = {\"string\", \"dtype\", \"count\", \"sep\", NULL};\n\tPyArray_Descr *descr=NULL;\n\n\tif (!PyArg_ParseTupleAndKeywords(args, keywds, \"s#|O&Ls\", kwlist, \n\t\t\t\t\t &data, &s, \n\t\t\t\t\t PyArray_DescrConverter, &descr,\n\t\t\t\t\t &nin, &sep)) {\n\t\treturn NULL;\n\t}\n\n\treturn PyArray_FromString(data, (intp)s, descr, (intp)nin, sep);\n}\n\n/* This needs an open file object and reads it in directly. \n memory-mapped files handled differently through buffer interface.\n\nfile pointer number in resulting 1d array \n(can easily reshape later, -1 for to end of file)\ntype of array\nsep is a separator string for character-based data (or NULL for binary)\n \" \" means whitespace\n*/\n\n/*OBJECT_API*/\nstatic PyObject *\nPyArray_FromFile(FILE *fp, PyArray_Descr *typecode, intp num, char *sep)\n{\n\tPyArrayObject *r;\n\tsize_t nread = 0;\n\tPyArray_ScanFunc *scan;\n\tBool binary;\n\n\tif (typecode->elsize == 0) {\n\t\tPyErr_SetString(PyExc_ValueError, \"0-sized elements.\");\n\t\tPy_DECREF(typecode);\n\t\treturn NULL;\n\t}\n\n\tbinary = ((sep == NULL) || (strlen(sep) == 0));\n\tif (num == -1 && binary) { /* Get size for binary file*/\n\t\tintp start, numbytes;\n\t\tstart = (intp )ftell(fp);\n\t\tfseek(fp, 0, SEEK_END);\n\t\tnumbytes = (intp )ftell(fp) - start;\n\t\trewind(fp);\n\t\tif (numbytes == -1) {\n\t\t\tPyErr_SetString(PyExc_IOError, \n\t\t\t\t\t\"could not seek in file\");\n\t\t\tPy_DECREF(typecode);\n\t\t\treturn NULL;\n\t\t}\n\t\tnum = numbytes / typecode->elsize;\n\t}\n\t\n\tif (binary) { /* binary data */\n\t\tr = (PyArrayObject *)PyArray_NewFromDescr(&PyArray_Type, \n\t\t\t\t\t\t\t typecode,\n\t\t\t\t\t\t\t 1, &num, \n\t\t\t\t\t\t\t NULL, NULL, \n\t\t\t\t\t\t\t 0, NULL);\n\t\tif (r==NULL) return NULL;\n\t\tnread = fread(r->data, typecode->elsize, num, fp);\n\t}\n\telse { /* character reading */\n\t\tintp i;\n\t\tchar *dptr;\n\t\tint done=0;\n\n\t\tscan = typecode->f->scanfunc;\n\t\tif (scan == NULL) {\n\t\t\tPyErr_SetString(PyExc_ValueError, \n\t\t\t\t\t\"don't know how to read \"\t\\\n\t\t\t\t\t\"character files with that \"\t\\\n\t\t\t\t\t\"array type\");\n\t\t\tPy_DECREF(typecode);\n\t\t\treturn NULL;\n\t\t}\n\n\t\tif (num != -1) { /* number to read is known */\n\t\t\tr = (PyArrayObject *)\\\n\t\t\t\tPyArray_NewFromDescr(&PyArray_Type, \n\t\t\t\t\t\t typecode, \n\t\t\t\t\t\t 1, &num, \n\t\t\t\t\t\t NULL, NULL, \n\t\t\t\t\t\t 0, NULL);\n\t\t\tif (r==NULL) return NULL;\n\t\t\tdptr = r->data;\n\t\t\tfor (i=0; i < num; i++) {\n\t\t\t\tif (done) break;\n\t\t\t\tdone = scan(fp, dptr, sep, NULL);\n\t\t\t\tif (done < -2) break;\n\t\t\t\tnread += 1;\n\t\t\t\tdptr += r->descr->elsize;\n\t\t\t}\n\t\t\tif (PyErr_Occurred()) {\n\t\t\t\tPy_DECREF(r);\n\t\t\t\treturn NULL;\n\t\t\t}\n\t\t}\n\t\telse { /* we have to watch for the end of the file and \n\t\t\t reallocate at the end */\n#define _FILEBUFNUM 4096\n\t\t\tintp thisbuf=0;\n\t\t\tintp size = _FILEBUFNUM;\n\t\t\tintp bytes;\n\t\t\tintp totalbytes;\n\n\t\t\tr = (PyArrayObject *)\\\n\t\t\t\tPyArray_NewFromDescr(&PyArray_Type, \n\t\t\t\t\t\t typecode,\n\t\t\t\t\t\t 1, &size, \n\t\t\t\t\t\t NULL, NULL, \n\t\t\t\t\t\t 0, NULL);\n\t\t\tif (r==NULL) return NULL;\n\t\t\ttotalbytes = bytes = size * typecode->elsize;\n\t\t\tdptr = r->data;\n\t\t\twhile (!done) {\n\t\t\t\tdone = scan(fp, dptr, sep, NULL);\n\n\t\t\t\t/* end of file reached trying to \n\t\t\t\t scan value. done is 1 or 2\n\t\t\t\t if end of file reached trying to\n\t\t\t\t scan separator. Still good value.\n\t\t\t\t*/\n\t\t\t\tif (done < -2) break;\n\t\t\t\tthisbuf += 1;\n\t\t\t\tnread += 1;\n\t\t\t\tdptr += r->descr->elsize;\n\t\t\t\tif (!done && thisbuf == size) {\n\t\t\t\t\ttotalbytes += bytes;\n\t\t\t\t\tr->data = PyDataMem_RENEW(r->data, \n\t\t\t\t\t\t\t\t totalbytes);\n\t\t\t\t\tdptr = r->data + (totalbytes - bytes);\n\t\t\t\t\tthisbuf = 0;\n\t\t\t\t}\n\t\t\t}\n\t\t\tif (PyErr_Occurred()) {\n\t\t\t\tPy_DECREF(r);\n\t\t\t\treturn NULL;\n\t\t\t}\n\t\t\tr->data = PyDataMem_RENEW(r->data, nread*r->descr->elsize);\n\t\t\tPyArray_DIM(r,0) = nread;\n\t\t\tnum = nread;\n#undef _FILEBUFNUM\n\t\t}\n\t}\n\tif (nread < num) {\n\t\tfprintf(stderr, \"%ld items requested but only %ld read\\n\", \n\t\t\t(long) num, (long) nread);\n\t\tr->data = PyDataMem_RENEW(r->data, nread * r->descr->elsize);\n\t\tPyArray_DIM(r,0) = nread;\n\t}\n\treturn (PyObject *)r;\n}\n\nstatic char doc_fromfile[] = \\\n\t\"fromfile(file=, dtype=int, count=-1, sep='')\\n\"\t\\\n\t\"\\n\"\\\n\t\" Return an array of the given data type from a \\n\"\\\n\t\" (text or binary) file. The file argument can be an open file\\n\"\\\n\t\" or a string with the name of a file to read from. If\\n\"\\\n\t\" count==-1, then the entire file is read, otherwise count is\\n\"\\\n\t\" the number of items of the given type read in. If sep is ''\\n\"\\\n\t\" then read a binary file, otherwise it gives the separator\\n\"\\\n\t\" between elements in a text file.\\n\"\\\n\t\"\\n\"\\\n\t\" WARNING: This function should be used sparingly, as it is not\\n\"\\\n\t\" a platform-independent method of persistence. But it can be \\n\"\\\n\t\" useful to read in simply-formatted or binary data quickly.\";\n\nstatic PyObject *\narray_fromfile(PyObject *ignored, PyObject *args, PyObject *keywds)\n{\n\tPyObject *file=NULL, *ret;\n\tFILE *fp;\n\tchar *sep=\"\";\n\tchar *mode=NULL;\n\tlonglong nin=-1;\n\tstatic char *kwlist[] = {\"file\", \"dtype\", \"count\", \"sep\", NULL};\n\tPyArray_Descr *type=NULL;\n\t\n\tif (!PyArg_ParseTupleAndKeywords(args, keywds, \"O|O&Ls\", kwlist, \n\t\t\t\t\t &file,\n\t\t\t\t\t PyArray_DescrConverter, &type,\n\t\t\t\t\t &nin, &sep)) {\n\t\treturn NULL;\n\t}\n\n\tif (type == NULL) type = PyArray_DescrFromType(PyArray_LONG);\n\n\tif (PyString_Check(file)) {\n\t\tif (sep == \"\") mode=\"rb\";\n\t\telse mode=\"r\";\n\t\tfile = PyFile_FromString(PyString_AS_STRING(file), mode);\n\t\tif (file==NULL) return NULL;\n\t}\n\telse {\n\t\tPy_INCREF(file);\n\t}\n\tfp = PyFile_AsFile(file);\n\tif (fp == NULL) {\n\t\tPyErr_SetString(PyExc_IOError, \n\t\t\t\t\"first argument must be an open file\");\n\t\tPy_DECREF(file);\n\t\treturn NULL;\n\t}\n\tret = PyArray_FromFile(fp, type, (intp) nin, sep);\n\tPy_DECREF(file);\n\treturn ret;\n}\n\n/*OBJECT_API*/\nstatic PyObject *\nPyArray_FromBuffer(PyObject *buf, PyArray_Descr *type, \n\t\t intp count, intp offset) \n{\n\tPyArrayObject *ret;\n\tchar *data;\n\tint ts;\n\tintp s, n;\n\tint itemsize;\n\tint write=1;\n\n\n\tif (type->type_num == PyArray_OBJECT) {\n\t\tPyErr_SetString(PyExc_ValueError, \n\t\t\t\t\"cannot create an OBJECT array from memory\"\\\n\t\t\t\t\" buffer\");\n\t\tPy_DECREF(type);\n\t\treturn NULL;\n\t}\n\tif (type->elsize == 0) {\n\t\tPyErr_SetString(PyExc_ValueError, \n\t\t\t\t\"itemsize cannot be zero in type\");\n\t\tPy_DECREF(type);\n\t\treturn NULL; \t\t\n\t}\n\n\tif (buf->ob_type->tp_as_buffer == NULL || \\\n\t (buf->ob_type->tp_as_buffer->bf_getwritebuffer == NULL &&\t\\\n\t buf->ob_type->tp_as_buffer->bf_getreadbuffer == NULL)) {\n\t\tPyObject *newbuf;\n\t\tnewbuf = PyObject_GetAttrString(buf, \"__buffer__\");\n\t\tif (newbuf == NULL) {Py_DECREF(type); return NULL;}\n\t\tbuf = newbuf;\n\t}\n\telse {Py_INCREF(buf);}\n\n\tif (PyObject_AsWriteBuffer(buf, (void *)&data, &ts)==-1) {\n\t\twrite = 0;\n\t\tPyErr_Clear();\n\t\tif (PyObject_AsReadBuffer(buf, (void *)&data, &ts)==-1) {\n\t\t\tPy_DECREF(buf);\n\t\t\tPy_DECREF(type);\n\t\t\treturn NULL;\n\t\t}\n\t}\n\t\n\tif ((offset < 0) || (offset >= ts)) {\n\t\tPyErr_Format(PyExc_ValueError,\n\t\t\t \"offset must be positive and smaller than %\"\n\t\t\t INTP_FMT, (intp)ts);\n\t}\n\n\tdata += offset;\n\ts = (intp)ts - offset;\n\tn = (intp)count;\n\titemsize = type->elsize;\n\t\n\tif (n < 0 ) {\n\t\tif (s % itemsize != 0) {\n\t\t\tPyErr_SetString(PyExc_ValueError, \n\t\t\t\t\t\"buffer size must be a multiple\"\\\n\t\t\t\t\t\" of element size\");\n\t\t\tPy_DECREF(buf);\n\t\t\tPy_DECREF(type);\n\t\t\treturn NULL;\n\t\t}\n\t\tn = s/itemsize;\n\t} else {\n\t\tif (s < n*itemsize) {\n\t\t\tPyErr_SetString(PyExc_ValueError, \n\t\t\t\t\t\"buffer is smaller than requested\"\\\n\t\t\t\t\t\" size\");\n\t\t\tPy_DECREF(buf);\n\t\t\tPy_DECREF(type);\n\t\t\treturn NULL;\n\t\t}\n\t}\n\t\n\tif ((ret = (PyArrayObject *)PyArray_NewFromDescr(&PyArray_Type, \n\t\t\t\t\t\t\t type, \n\t\t\t\t\t\t\t 1, &n, \n\t\t\t\t\t\t\t NULL, data, \n\t\t\t\t\t\t\t DEFAULT_FLAGS,\n\t\t\t\t\t\t\t NULL)) == NULL) {\n\t\tPy_DECREF(buf);\n\t\treturn NULL;\n\t}\n\t\n\tif (!write) ret->flags &= ~WRITEABLE;\n\n\t/* Store a reference for decref on deallocation */\n\tret->base = buf;\n\tPyArray_UpdateFlags(ret, ALIGNED);\n\treturn (PyObject *)ret;\n}\n\nstatic char doc_frombuffer[] = \\\n\t\"frombuffer(buffer=, dtype=int, count=-1, offset=0)\\n\"\\\n\t\"\\n\"\t\t\t\t\t\t\t\t\\\n\t\" Returns a 1-d array of data type dtype from buffer. The buffer\\n\"\\\n\t\" argument must be an object that exposes the buffer interface.\\n\"\\\n\t\" If count is -1 then the entire buffer is used, otherwise, count\\n\"\\\n\t\" is the size of the output. If offset is given then jump that\\n\"\\\n\t\" far into the buffer. If the buffer has data that is out\\n\" \\\n\t\" not in machine byte-order, than use a propert data type\\n\"\\\n\t\" descriptor. The data will not\\n\" \\\n\t\" be byteswapped, but the array will manage it in future\\n\"\\\n\t\" operations.\\n\";\n\nstatic PyObject *\narray_frombuffer(PyObject *ignored, PyObject *args, PyObject *keywds)\n{\n\tPyObject *obj=NULL;\n\tlonglong nin=-1, offset=0;\n\tstatic char *kwlist[] = {\"buffer\", \"dtype\", \"count\", \"offset\", NULL};\n\tPyArray_Descr *type=NULL;\n\n\tif (!PyArg_ParseTupleAndKeywords(args, keywds, \"O|O&LL\", kwlist, \n\t\t\t\t\t &obj,\n\t\t\t\t\t PyArray_DescrConverter, &type,\n\t\t\t\t\t &nin, &offset)) {\n\t\treturn NULL;\n\t}\n\tif (type==NULL)\n\t\ttype = PyArray_DescrFromType(PyArray_LONG);\n\t\n\treturn PyArray_FromBuffer(obj, type, (intp)nin, (intp)offset);\n}\n\n\nstatic char doc_concatenate[] = \"concatenate((a1,a2,...),axis=None).\";\n\nstatic PyObject *\narray_concatenate(PyObject *dummy, PyObject *args, PyObject *kwds) \n{\n\tPyObject *a0;\n\tint axis=0;\n\tstatic char *kwlist[] = {\"seq\", \"axis\", NULL};\n\t\n\tif (!PyArg_ParseTupleAndKeywords(args, kwds, \"O|O&\", kwlist,\n\t\t\t\t\t &a0,\n\t\t\t\t\t PyArray_AxisConverter, &axis))\n\t\treturn NULL;\n\treturn PyArray_Concatenate(a0, axis);\n}\n\nstatic char doc_innerproduct[] = \\\n\t\"inner(a,b) returns the dot product of two arrays, which has\\n\"\\\n\t\"shape a.shape[:-1] + b.shape[:-1] with elements computed by\\n\" \\\n\t\"the product of the elements from the last dimensions of a and b.\";\n\nstatic PyObject *array_innerproduct(PyObject *dummy, PyObject *args) {\n\tPyObject *b0, *a0;\n\t\n\tif (!PyArg_ParseTuple(args, \"OO\", &a0, &b0)) return NULL;\n\t\n\treturn _ARET(PyArray_InnerProduct(a0, b0));\n}\n\nstatic char doc_matrixproduct[] = \\\n\t\"dot(a,v) returns matrix-multiplication between a and b. \\n\"\\\n\t\"The product-sum is over the last dimension of a and the \\n\"\\\n\t\"second-to-last dimension of b.\";\n\nstatic PyObject *array_matrixproduct(PyObject *dummy, PyObject *args) {\n\tPyObject *v, *a;\n\t\n\tif (!PyArg_ParseTuple(args, \"OO\", &a, &v)) return NULL;\n\t\n\treturn _ARET(PyArray_MatrixProduct(a, v));\n}\n\nstatic char doc_fastCopyAndTranspose[] = \"_fastCopyAndTranspose(a)\";\n\nstatic PyObject *array_fastCopyAndTranspose(PyObject *dummy, PyObject *args) {\n\tPyObject *a0;\n\t\n\tif (!PyArg_ParseTuple(args, \"O\", &a0)) return NULL;\n\t\n\treturn _ARET(PyArray_CopyAndTranspose(a0));\n}\n\nstatic char doc_correlate[] = \"cross_correlate(a,v, mode=0)\";\n\nstatic PyObject *array_correlate(PyObject *dummy, PyObject *args, PyObject *kwds) {\n\tPyObject *shape, *a0;\n\tint mode=0;\n\tstatic char *kwlist[] = {\"a\", \"v\", \"mode\", NULL};\n\t\n\tif (!PyArg_ParseTupleAndKeywords(args, kwds, \"OO|i\", kwlist, \n\t\t\t\t\t &a0, &shape, &mode)) return NULL;\n\t\n\treturn PyArray_Correlate(a0, shape, mode);\n}\n\n\n/*MULTIARRAY_API\n Arange, \n*/\nstatic PyObject *\nPyArray_Arange(double start, double stop, double step, int type_num)\n{\n\tintp length;\n\tPyObject *range;\n\tPyArray_ArrFuncs *funcs;\n\tPyObject *obj;\n\tint ret;\n\n\tlength = (intp ) ceil((stop - start)/step);\n \n\tif (length <= 0) {\n\t\tlength = 0;\n\t\treturn PyArray_New(&PyArray_Type, 1, &length, type_num,\n\t\t\t\t NULL, NULL, 0, 0, NULL);\n\t}\n\n\trange = PyArray_New(&PyArray_Type, 1, &length, type_num, \n\t\t\t NULL, NULL, 0, 0, NULL);\n\tif (range == NULL) return NULL;\n\n\tfuncs = PyArray_DESCR(range)->f; \n\n\t/* place start in the buffer and the next value in the second position */\n\t/* if length > 2, then call the inner loop, otherwise stop */\n\n\tobj = PyFloat_FromDouble(start);\n\tret = funcs->setitem(obj, PyArray_DATA(range), (PyArrayObject *)range);\n\tPy_DECREF(obj);\n\tif (ret < 0) goto fail;\n\tif (length == 1) return range;\n\n\tobj = PyFloat_FromDouble(start + step);\n\tret = funcs->setitem(obj, PyArray_DATA(range)+PyArray_ITEMSIZE(range), \n\t\t\t (PyArrayObject *)range);\n\tPy_DECREF(obj);\n\tif (ret < 0) goto fail;\n\tif (length == 2) return range;\n\n\tif (!funcs->fill) {\n\t\tPyErr_SetString(PyExc_ValueError, \"no fill-function for data-type.\");\n\t\tPy_DECREF(range);\n\t\treturn NULL;\n\t}\n\tfuncs->fill(PyArray_DATA(range), length, (PyArrayObject *)range);\n\tif (PyErr_Occurred()) goto fail;\n\t\n\treturn range;\n\n fail:\n\tPy_DECREF(range);\n\treturn NULL;\n}\n\n/* the formula is \n len = (intp) ceil((start - stop) / step);\n*/\nstatic intp\n_calc_length(PyObject *start, PyObject *stop, PyObject *step, PyObject **next, int cmplx)\n{\n\tintp len;\n\tPyObject *val;\n\tdouble value;\n\t\n\t*next = PyNumber_Subtract(stop, start);\n\tif (!(*next)) return -1;\n\tval = PyNumber_TrueDivide(*next, step);\n\tPy_DECREF(*next); *next=NULL;\n\tif (!val) return -1;\n\tif (cmplx && PyComplex_Check(val)) {\n\t\tvalue = PyComplex_RealAsDouble(val);\n\t\tif (error_converting(value)) {Py_DECREF(val); return -1;}\n\t\tlen = (intp) ceil(value);\n\t\tvalue = PyComplex_ImagAsDouble(val);\n\t\tPy_DECREF(val);\n\t\tif (error_converting(value)) return -1;\n\t\tlen = MIN(len, (intp) ceil(value));\n\t}\n\telse {\n\t\tvalue = PyFloat_AsDouble(val);\n\t\tPy_DECREF(val);\n\t\tif (error_converting(value)) return -1;\n\t\tlen = (intp) ceil(value);\n\t}\n\t\n\tif (len > 0) {\n\t\t*next = PyNumber_Add(start, step);\n\t\tif (!next) return -1;\n\t}\n\treturn len;\n}\n\n/* this doesn't change the references */\n/*MULTIARRAY_API\n ArangeObj,\n*/\nstatic PyObject *\nPyArray_ArangeObj(PyObject *start, PyObject *stop, PyObject *step, PyArray_Descr *dtype) \n{\n\tPyObject *range;\n\tPyArray_ArrFuncs *funcs;\n\tPyObject *next;\n\tintp length;\n\n\tif (!dtype) {\n\t\tPyArray_Descr *deftype;\n\t\tPyArray_Descr *newtype;\n\t\tdeftype = PyArray_DescrFromType(PyArray_LONG);\n\t\tnewtype = PyArray_DescrFromObject(start, deftype);\n\t\tPy_DECREF(deftype);\n\t\tdeftype = newtype;\n\t\tif (stop && stop != Py_None) {\n\t\t\tnewtype = PyArray_DescrFromObject(stop, deftype);\n\t\t\tPy_DECREF(deftype);\n\t\t\tdeftype = newtype;\n\t\t}\n\t\tif (step && step != Py_None) {\n\t\t\tnewtype = PyArray_DescrFromObject(step, deftype);\n\t\t\tPy_DECREF(deftype);\n\t\t\tdeftype = newtype;\n\t\t}\n\t\tdtype = deftype;\n\t}\n\telse Py_INCREF(dtype);\n\n\tif (!step || step == Py_None) {\n\t\tstep = PyInt_FromLong(1);\n\t}\n\telse Py_XINCREF(step);\n\n\tif (!stop || stop == Py_None) {\n\t\tstop = start;\n\t\tstart = PyInt_FromLong(0);\n\t}\n\telse Py_INCREF(start);\n\n\t/* calculate the length and next = start + step*/\n\tlength = _calc_length(start, stop, step, &next, \n\t\t\t PyTypeNum_ISCOMPLEX(dtype->type_num));\n\n\tif (PyErr_Occurred()) {Py_DECREF(dtype); goto fail;}\n\tif (length <= 0) {\n\t\tlength = 0;\n\t\trange = PyArray_SimpleNewFromDescr(1, &length, dtype);\n\t\tPy_DECREF(step); Py_DECREF(start); return range;\n\t}\n\n\trange = PyArray_SimpleNewFromDescr(1, &length, dtype);\n\tif (range == NULL) goto fail;\n\n\tfuncs = PyArray_DESCR(range)->f;\n\n\t/* place start in the buffer and the next value in the second position */\n\t/* if length > 2, then call the inner loop, otherwise stop */\n\n\tif (funcs->setitem(start, PyArray_DATA(range), (PyArrayObject *)range) < 0)\n\t\tgoto fail;\n\tif (length == 1) goto finish;\n\tif (funcs->setitem(next, PyArray_DATA(range)+PyArray_ITEMSIZE(range), \n\t\t\t (PyArrayObject *)range) < 0) goto fail;\n\tif (length == 2) goto finish;\n\n\tif (!funcs->fill) {\n\t\tPyErr_SetString(PyExc_ValueError, \"no fill-function for data-type.\");\n\t\tPy_DECREF(range);\n\t\tgoto fail;\n\t}\n\tfuncs->fill(PyArray_DATA(range), length, (PyArrayObject *)range);\n\tif (PyErr_Occurred()) goto fail;\n\n finish:\n\tPy_DECREF(start);\n\tPy_DECREF(step);\n\tPy_DECREF(next);\n\treturn range;\n\t\n fail:\n\tPy_DECREF(start);\n\tPy_DECREF(step);\n\tPy_XDECREF(next);\n\treturn NULL;\n}\n\n\nstatic char doc_arange[] = \"arange(start, stop=None, step=1, dtype=int)\\n\\n Just like range() except it returns an array whose type can be\\n specified by the keyword argument typecode.\";\n\nstatic PyObject *\narray_arange(PyObject *ignored, PyObject *args, PyObject *kws) {\n\tPyObject *o_start=NULL, *o_stop=NULL, *o_step=NULL;\n\tstatic char *kwd[]= {\"start\", \"stop\", \"step\", \"dtype\", NULL};\n\tPyArray_Descr *typecode=NULL;\n\t\n\tif(!PyArg_ParseTupleAndKeywords(args, kws, \"O|OOO&\", kwd, &o_start,\n\t\t\t\t\t&o_stop, &o_step, \n\t\t\t\t\tPyArray_DescrConverter2,\n\t\t\t\t\t&typecode)) \n\t\treturn NULL;\n\n\treturn PyArray_ArangeObj(o_start, o_stop, o_step, typecode);\n}\n\n/*MULTIARRAY_API\n GetNDArrayCVersion\n*/\nstatic unsigned int\nPyArray_GetNDArrayCVersion(void)\n{\n\treturn (unsigned int)NDARRAY_VERSION;\n}\n\nstatic char \ndoc__get_ndarray_c_version[] = \"_get_ndarray_c_version() gets the compile time NDARRAY_VERSION number\";\n\nstatic PyObject *\narray__get_ndarray_c_version(PyObject *dummy, PyObject *args, PyObject *kwds) \n{\n\tstatic char *kwlist[] = {NULL};\n\tif(!PyArg_ParseTupleAndKeywords(args, kwds, \"\", kwlist )) return NULL;\n\t\n\treturn PyInt_FromLong( (long) PyArray_GetNDArrayCVersion() );\n}\n\nstatic char \ndoc_set_string_function[] = \"set_string_function(f, repr=1) sets the python function f to be the function used to obtain a pretty printable string version of a array whenever a array is printed. f(M) should expect a array argument M, and should return a string consisting of the desired representation of M for printing.\";\n\nstatic PyObject *\narray_set_string_function(PyObject *dummy, PyObject *args, PyObject *kwds) \n{\n\tPyObject *op;\n\tint repr=1;\n\tstatic char *kwlist[] = {\"f\", \"repr\", NULL};\n\n\tif(!PyArg_ParseTupleAndKeywords(args, kwds, \"O|i\", kwlist, \n\t\t\t\t\t&op, &repr)) return NULL; \n\tif (!PyCallable_Check(op)) {\n\t\tPyErr_SetString(PyExc_TypeError, \n\t\t\t\t\"Argument must be callable.\");\n\t\treturn NULL;\n\t}\n\tPyArray_SetStringFunction(op, repr);\n\tPy_INCREF(Py_None);\n\treturn Py_None;\n}\n\nstatic char \ndoc_set_ops_function[] = \"set_numeric_ops(op=func, ...) sets some or all of the number methods for all array objects. Don't forget **dict can be used as the argument list. Returns the functions that were replaced -- can be stored and set later.\";\n\nstatic PyObject *\narray_set_ops_function(PyObject *self, PyObject *args, PyObject *kwds) \n{\n\tPyObject *oldops=NULL;\n\t\n\tif ((oldops = PyArray_GetNumericOps())==NULL) return NULL;\n\n\t/* Should probably ensure that objects are at least callable */\n\t/* Leave this to the caller for now --- error will be raised\n\t later when use is attempted \n\t*/\n\tif (kwds && PyArray_SetNumericOps(kwds) == -1) {\n\t\tPy_DECREF(oldops);\n\t\tPyErr_SetString(PyExc_ValueError, \n\t\t\t\t\"one or more objects not callable\");\n\t\treturn NULL;\n\t}\n\treturn oldops;\n}\n\n\n/*MULTIARRAY_API\n Where\n*/\nstatic PyObject *\nPyArray_Where(PyObject *condition, PyObject *x, PyObject *y)\n{\n\tPyArrayObject *arr;\n\tPyObject *tup=NULL, *obj=NULL;\n\tPyObject *ret=NULL, *zero=NULL;\n\n\n\tarr = (PyArrayObject *)PyArray_FromAny(condition, NULL, 0, 0, 0, NULL);\n\tif (arr == NULL) return NULL;\n\n\tif ((x==NULL) && (y==NULL)) {\n\t\tret = PyArray_Nonzero(arr);\n\t\tPy_DECREF(arr);\n\t\treturn ret;\n\t}\n\n\tif ((x==NULL) || (y==NULL)) {\n\t\tPy_DECREF(arr);\n\t\tPyErr_SetString(PyExc_ValueError, \"either both or neither \"\n\t\t\t\t\"of x and y should be given\");\n\t\treturn NULL;\n\t}\n\n\n\tzero = PyInt_FromLong((long) 0);\n\n\tobj = PyArray_EnsureArray(PyArray_GenericBinaryFunction(arr, zero, \n\t\t\t\t\t\t\t\tn_ops.not_equal));\n\tPy_DECREF(zero);\n\tPy_DECREF(arr);\n\tif (obj == NULL) return NULL;\n\n\ttup = Py_BuildValue(\"(OO)\", y, x);\n\tif (tup == NULL) {Py_DECREF(obj); return NULL;}\n\n\tret = PyArray_Choose((PyAO *)obj, tup);\n\n\tPy_DECREF(obj);\n\tPy_DECREF(tup);\n\treturn ret;\n}\n\nstatic char doc_where[] = \"where(condition, | x, y) is shaped like condition\"\\\n\t\" and has elements of x and y where condition is respectively true or\"\\\n\t\" false. If x or y are not given, then it is equivalent to\"\\\n\t\" nonzero(condition).\";\n\nstatic PyObject *\narray_where(PyObject *ignored, PyObject *args)\n{\n\tPyObject *obj=NULL, *x=NULL, *y=NULL;\n\t\n\tif (!PyArg_ParseTuple(args, \"O|OO\", &obj, &x, &y)) return NULL;\n\n\treturn PyArray_Where(obj, x, y);\n\n}\n\nstatic char doc_lexsort[] = \"lexsort(keys=, axis=-1) returns an array of indexes\"\\\n\t\" similar to argsort except the sorting is done using the provided sorting\"\\\n\t\" keys. First the sort is done using key[0], then the resulting list of\"\\\n\t\" indexes is further manipulated by sorting on key[0]. And so forth\"\\\n\t\" The result is a sort on multiple keys. If the keys represented columns\" \\\n\t\" of a spread-sheet, for example, this would sort using multiple columns.\"\\\n\t\" The keys argument must be a tuple of things that can be converted to \"\\\n\t\" arrays of the same shape.\";\n\nstatic PyObject *\narray_lexsort(PyObject *ignored, PyObject *args, PyObject *kwds)\n{\n\tint axis=-1;\n\tPyObject *obj;\n\tstatic char *kwlist[] = {\"keys\", \"axis\", NULL};\n\t\n\tif (!PyArg_ParseTupleAndKeywords(args, kwds, \"O!|i\", kwlist, \n\t\t\t\t\t &PyTuple_Type, &obj, &axis)) return NULL;\n\t\n\treturn _ARET(PyArray_LexSort(obj, axis));\n}\n\n#undef _ARET\n\n\nstatic char doc_register_dtype[] = \\\n\t\"register_dtype(a) registers a new type object -- gives it a typenum\";\n\nstatic PyObject *\narray_register_dtype(PyObject *dummy, PyObject *args)\n{\n\tPyObject *dtype;\n\tint ret;\n\t\n\tif (!PyArg_ParseTuple(args, \"O\", &dtype)) return NULL;\n\t\n\tret = PyArray_RegisterDataType((PyTypeObject *)dtype);\n\tif (ret < 0)\n\t\treturn NULL;\n\treturn PyInt_FromLong((long) ret);\n}\n\nstatic char doc_can_cast_safely[] = \\\n\t\"can_cast_safely(from=d1, to=d2) returns True if data type d1 \"\\\n\t\"can be cast to data type d2 without losing precision.\";\n\nstatic PyObject *\narray_can_cast_safely(PyObject *dummy, PyObject *args, PyObject *kwds)\n{\n\tPyArray_Descr *d1=NULL;\n\tPyArray_Descr *d2=NULL;\n\tBool ret;\n\tPyObject *retobj;\n\tstatic char *kwlist[] = {\"from\", \"to\", NULL};\n\n\tif(!PyArg_ParseTupleAndKeywords(args, kwds, \"O&O&\", kwlist, \n\t\t\t\t\tPyArray_DescrConverter, &d1,\n\t\t\t\t\tPyArray_DescrConverter, &d2))\n\t\treturn NULL;\n\tif (d1 == NULL || d2 == NULL) {\n\t\tPyErr_SetString(PyExc_TypeError, \n\t\t\t\t\"did not understand one of the types; \"\t\\\n\t\t\t\t\"'None' not accepted\");\n\t\treturn NULL;\n\t}\n\t\t\n\tret = PyArray_CanCastTo(d1, d2);\n\tretobj = (ret ? Py_True : Py_False);\n\tPy_INCREF(retobj);\n\treturn retobj;\n}\n\nstatic char doc_new_buffer[] = \\\n\t\"newbuffer(size) return a new uninitialized buffer object of size \"\n\t\"bytes\";\n\nstatic PyObject *\nnew_buffer(PyObject *dummy, PyObject *args)\n{\n\tint size;\n\n\tif(!PyArg_ParseTuple(args, \"i\", &size))\n\t\treturn NULL;\n\t\n\treturn PyBuffer_New(size);\n}\n\nstatic char doc_buffer_buffer[] = \\\n\t\"getbuffer(obj [,offset[, size]]) create a buffer object from the \"\\\n\t\"given object\\n referencing a slice of length size starting at \"\\\n\t\"offset. Default\\n is the entire buffer. A read-write buffer is \"\\\n\t\"attempted followed by a read-only buffer.\";\n\nstatic PyObject *\nbuffer_buffer(PyObject *dummy, PyObject *args, PyObject *kwds)\n{\n\tPyObject *obj;\n\tint offset=0, size=Py_END_OF_BUFFER, n;\n\tvoid *unused;\n\tstatic char *kwlist[] = {\"object\", \"offset\", \"size\", NULL};\n\t\n\tif (!PyArg_ParseTupleAndKeywords(args, kwds, \"O|ii\", kwlist, \n\t\t\t\t\t &obj, &offset, &size))\n\t\treturn NULL;\n\n\n\tif (PyObject_AsWriteBuffer(obj, &unused, &n) < 0) {\n\t\tPyErr_Clear();\n\t\treturn PyBuffer_FromObject(obj, offset, size);\t\t\n\t}\n\telse\n\t\treturn PyBuffer_FromReadWriteObject(obj, offset, size);\n}\n\n\nstatic struct PyMethodDef array_module_methods[] = {\n\t{\"_get_ndarray_c_version\", (PyCFunction)array__get_ndarray_c_version, \n\t METH_VARARGS|METH_KEYWORDS, doc__get_ndarray_c_version},\n\t{\"set_string_function\", (PyCFunction)array_set_string_function, \n\t METH_VARARGS|METH_KEYWORDS, doc_set_string_function},\n\t{\"set_numeric_ops\", (PyCFunction)array_set_ops_function,\n\t METH_VARARGS|METH_KEYWORDS, doc_set_ops_function},\n\t{\"set_typeDict\", (PyCFunction)array_set_typeDict,\n\t METH_VARARGS, doc_set_typeDict},\n\n\t{\"array\",\t(PyCFunction)_array_fromobject, \n\t METH_VARARGS|METH_KEYWORDS, doc_fromobject},\n\t{\"arange\", (PyCFunction)array_arange, \n\t METH_VARARGS|METH_KEYWORDS, doc_arange},\n\t{\"zeros\",\t(PyCFunction)array_zeros, \n\t METH_VARARGS|METH_KEYWORDS, doc_zeros},\n\t{\"empty\",\t(PyCFunction)array_empty, \n\t METH_VARARGS|METH_KEYWORDS, doc_empty},\n\t{\"scalar\", (PyCFunction)array_scalar,\n\t METH_VARARGS|METH_KEYWORDS, doc_scalar},\n\t{\"where\", (PyCFunction)array_where,\n\t METH_VARARGS, doc_where},\n\t{\"lexsort\", (PyCFunction)array_lexsort,\n\t METH_VARARGS | METH_KEYWORDS, doc_lexsort},\n\t{\"fromstring\",(PyCFunction)array_fromString,\n\t METH_VARARGS|METH_KEYWORDS, doc_fromString},\n\t{\"concatenate\", (PyCFunction)array_concatenate, \n\t METH_VARARGS|METH_KEYWORDS, doc_concatenate},\n\t{\"inner\", (PyCFunction)array_innerproduct, \n\t METH_VARARGS, doc_innerproduct}, \n\t{\"dot\", (PyCFunction)array_matrixproduct, \n\t METH_VARARGS, doc_matrixproduct}, \n\t{\"_fastCopyAndTranspose\", (PyCFunction)array_fastCopyAndTranspose, \n\t METH_VARARGS, doc_fastCopyAndTranspose},\n\t{\"correlate\", (PyCFunction)array_correlate, \n\t METH_VARARGS | METH_KEYWORDS, doc_correlate},\n\t{\"frombuffer\", (PyCFunction)array_frombuffer,\n\t METH_VARARGS | METH_KEYWORDS, doc_frombuffer},\n\t{\"fromfile\", (PyCFunction)array_fromfile,\n\t METH_VARARGS | METH_KEYWORDS, doc_fromfile},\n\t{\"register_dtype\", (PyCFunction)array_register_dtype,\n\t METH_VARARGS, doc_register_dtype},\n\t{\"can_cast\", (PyCFunction)array_can_cast_safely,\n\t METH_VARARGS | METH_KEYWORDS, doc_can_cast_safely},\t\t\n\t{\"newbuffer\", (PyCFunction)new_buffer,\n\t METH_VARARGS, doc_new_buffer},\t\n\t{\"getbuffer\", (PyCFunction)buffer_buffer,\n\t METH_VARARGS | METH_KEYWORDS, doc_buffer_buffer},\t\n\t{NULL,\t\tNULL, 0}\t\t/* sentinel */\n};\n\n#include \"__multiarray_api.c\"\n\n/* Establish scalar-type hierarchy */\n\n/* For dual inheritance we need to make sure that the objects being\n inherited from have the tp->mro object initialized. This is\n not necessarily true for the basic type objects of Python (it is \n checked for single inheritance but not dual in PyType_Ready).\n\n Thus, we call PyType_Ready on the standard Python Types, here.\n*/ \nstatic int\nsetup_scalartypes(PyObject *dict)\n{\n\n\tinitialize_numeric_types();\n\n if (PyType_Ready(&PyBool_Type) < 0) return -1;\n if (PyType_Ready(&PyInt_Type) < 0) return -1;\n if (PyType_Ready(&PyFloat_Type) < 0) return -1;\n if (PyType_Ready(&PyComplex_Type) < 0) return -1;\n if (PyType_Ready(&PyString_Type) < 0) return -1;\n if (PyType_Ready(&PyUnicode_Type) < 0) return -1;\n\n#define SINGLE_INHERIT(child, parent) \\\n Py##child##ArrType_Type.tp_base = &Py##parent##ArrType_Type;\t\\\n if (PyType_Ready(&Py##child##ArrType_Type) < 0) {\t\t\\\n PyErr_Print(); \\\n PyErr_Format(PyExc_SystemError, \\\n\t\t\t \"could not initialize Py%sArrType_Type\", \\\n #child); \\\n return -1;\t\t\t\t\t\t\\\n }\n \n if (PyType_Ready(&PyGenericArrType_Type) < 0)\n return -1;\n\n SINGLE_INHERIT(Number, Generic);\n SINGLE_INHERIT(Integer, Number);\n SINGLE_INHERIT(Inexact, Number);\n SINGLE_INHERIT(SignedInteger, Integer);\n SINGLE_INHERIT(UnsignedInteger, Integer);\n SINGLE_INHERIT(Floating, Inexact);\n SINGLE_INHERIT(ComplexFloating, Inexact);\n SINGLE_INHERIT(Flexible, Generic);\n SINGLE_INHERIT(Character, Flexible);\n\t\n#define DUAL_INHERIT(child, parent1, parent2) \\\n Py##child##ArrType_Type.tp_base = &Py##parent2##ArrType_Type;\t\\\n Py##child##ArrType_Type.tp_bases = \\\n Py_BuildValue(\"(OO)\", &Py##parent2##ArrType_Type,\t\\\n\t\t\t &Py##parent1##_Type);\t\t\t\\\n if (PyType_Ready(&Py##child##ArrType_Type) < 0) { \\\n PyErr_Print(); \\\n\t\tPyErr_Format(PyExc_SystemError, \\\n\t\t\t \"could not initialize Py%sArrType_Type\", \\\n #child); \\\n return -1; \\\n }\\\n Py##child##ArrType_Type.tp_hash = Py##parent1##_Type.tp_hash;\n\n#define DUAL_INHERIT2(child, parent1, parent2)\t\t\t\t\\\n Py##child##ArrType_Type.tp_base = &Py##parent1##_Type;\t\t\\\n Py##child##ArrType_Type.tp_bases = \\\n Py_BuildValue(\"(OO)\", &Py##parent1##_Type,\t\t\\\n\t\t\t &Py##parent2##ArrType_Type);\t\t\\\n\tPy##child##ArrType_Type.tp_richcompare =\t\t\t\\\n\t\tPy##parent1##_Type.tp_richcompare;\t\t\t\\\n\tPy##child##ArrType_Type.tp_compare =\t\t\t\t\\\n\t\tPy##parent1##_Type.tp_compare;\t\t\t\t\\\n Py##child##ArrType_Type.tp_hash = Py##parent1##_Type.tp_hash;\t\\\n if (PyType_Ready(&Py##child##ArrType_Type) < 0) { \\\n PyErr_Print(); \\\n\t\tPyErr_Format(PyExc_SystemError, \\\n\t\t\t \"could not initialize Py%sArrType_Type\", \\\n #child); \\\n return -1; \\\n }\n\n SINGLE_INHERIT(Bool, Generic);\n SINGLE_INHERIT(Byte, SignedInteger);\n SINGLE_INHERIT(Short, SignedInteger);\n#if SIZEOF_INT == SIZEOF_LONG\n DUAL_INHERIT(Int, Int, SignedInteger);\n#else\n SINGLE_INHERIT(Int, SignedInteger);\n#endif\n DUAL_INHERIT(Long, Int, SignedInteger);\n#if SIZEOF_LONGLONG == SIZEOF_LONG\n DUAL_INHERIT(LongLong, Int, SignedInteger);\n#else\n SINGLE_INHERIT(LongLong, SignedInteger);\n#endif\n\n /* fprintf(stderr, \"tp_free = %p, PyObject_Del = %p, int_tp_free = %p, base.tp_free = %p\\n\", PyIntArrType_Type.tp_free, PyObject_Del, PyInt_Type.tp_free, PySignedIntegerArrType_Type.tp_free);\n\t */\n\tSINGLE_INHERIT(UByte, UnsignedInteger);\n SINGLE_INHERIT(UShort, UnsignedInteger);\n SINGLE_INHERIT(UInt, UnsignedInteger);\n SINGLE_INHERIT(ULong, UnsignedInteger);\n SINGLE_INHERIT(ULongLong, UnsignedInteger);\n\n SINGLE_INHERIT(Float, Floating);\n DUAL_INHERIT(Double, Float, Floating);\n SINGLE_INHERIT(LongDouble, Floating);\n\n SINGLE_INHERIT(CFloat, ComplexFloating);\n DUAL_INHERIT(CDouble, Complex, ComplexFloating);\n SINGLE_INHERIT(CLongDouble, ComplexFloating);\n\n DUAL_INHERIT2(String, String, Character);\n DUAL_INHERIT2(Unicode, Unicode, Character);\n\t\n SINGLE_INHERIT(Void, Flexible);\n \n SINGLE_INHERIT(Object, Generic);\n\n return 0;\n\n#undef SINGLE_INHERIT\n#undef DUAL_INHERIT\n\n\t/* Clean up string and unicode array types so they act more like\n\t strings -- get their tables from the standard types.\n\t*/\n}\n\n/* place a flag dictionary in d */\n\nstatic void\nset_flaginfo(PyObject *d)\n{\n PyObject *s;\n PyObject *newd;\n \n newd = PyDict_New();\n\n PyDict_SetItemString(newd, \"OWNDATA\", s=PyInt_FromLong(OWNDATA));\n Py_DECREF(s);\n PyDict_SetItemString(newd, \"FORTRAN\", s=PyInt_FromLong(FORTRAN));\n Py_DECREF(s);\n PyDict_SetItemString(newd, \"CONTIGUOUS\", s=PyInt_FromLong(CONTIGUOUS));\n Py_DECREF(s);\n PyDict_SetItemString(newd, \"ALIGNED\", s=PyInt_FromLong(ALIGNED));\n Py_DECREF(s);\n\n PyDict_SetItemString(newd, \"UPDATEIFCOPY\", s=PyInt_FromLong(UPDATEIFCOPY));\n Py_DECREF(s);\n PyDict_SetItemString(newd, \"WRITEABLE\", s=PyInt_FromLong(WRITEABLE));\n Py_DECREF(s);\n \n PyDict_SetItemString(d, \"_flagdict\", newd);\n Py_DECREF(newd);\n return;\n}\n\n\n/* Initialization function for the module */\n\nDL_EXPORT(void) initmultiarray(void) {\n\tPyObject *m, *d, *s;\n\tPyObject *c_api;\n\t\n\t/* Create the module and add the functions */\n\tm = Py_InitModule(\"multiarray\", array_module_methods);\n\tif (!m) goto err;\n\n\t/* Add some symbolic constants to the module */\n\td = PyModule_GetDict(m);\n\tif (!d) goto err; \n\n\t/* Create the module and add the functions */\n\tif (PyType_Ready(&PyBigArray_Type) < 0) \n\t\treturn;\n\n PyArray_Type.tp_base = &PyBigArray_Type;\n\n PyArray_Type.tp_as_mapping = &array_as_mapping;\n\t/* Even though, this would be inherited, it needs to be set now\n\t so that the __getitem__ will map to the as_mapping descriptor\n\t*/\n PyArray_Type.tp_as_number = &array_as_number; \n\t/* For good measure */\n\tPyArray_Type.tp_as_sequence = &array_as_sequence;\n\tPyArray_Type.tp_as_buffer = &array_as_buffer;\t\n PyArray_Type.tp_flags = (Py_TPFLAGS_DEFAULT \n\t\t\t\t | Py_TPFLAGS_BASETYPE\n\t\t\t\t | Py_TPFLAGS_CHECKTYPES);\n PyArray_Type.tp_doc = Arraytype__doc__;\n\n\tif (PyType_Ready(&PyArray_Type) < 0)\n return;\n\n if (setup_scalartypes(d) < 0) goto err;\n\n\tPyArrayIter_Type.tp_iter = PyObject_SelfIter;\n\tPyArrayMultiIter_Type.tp_iter = PyObject_SelfIter;\n\tif (PyType_Ready(&PyArrayIter_Type) < 0)\n\t\treturn; \n \n\tif (PyType_Ready(&PyArrayMapIter_Type) < 0)\n return; \n\n\tif (PyType_Ready(&PyArrayMultiIter_Type) < 0)\n\t\treturn;\n\n\tif (PyType_Ready(&PyArrayDescr_Type) < 0)\n\t\treturn;\n\n\tc_api = PyCObject_FromVoidPtr((void *)PyArray_API, NULL);\n\tif (PyErr_Occurred()) goto err;\n\tPyDict_SetItemString(d, \"_ARRAY_API\", c_api);\n\tPy_DECREF(c_api);\n\tif (PyErr_Occurred()) goto err;\n\n\tMultiArrayError = PyString_FromString (\"multiarray.error\");\n\tPyDict_SetItemString (d, \"error\", MultiArrayError);\n\t\n\ts = PyString_FromString(\"3.0\");\n\tPyDict_SetItemString(d, \"__version__\", s);\n\tPy_DECREF(s);\n Py_INCREF(&PyBigArray_Type);\n\tPyDict_SetItemString(d, \"bigndarray\", (PyObject *)&PyBigArray_Type);\n Py_INCREF(&PyArray_Type);\n\tPyDict_SetItemString(d, \"ndarray\", (PyObject *)&PyArray_Type);\n Py_INCREF(&PyArrayIter_Type);\n\tPyDict_SetItemString(d, \"flatiter\", (PyObject *)&PyArrayIter_Type);\n Py_INCREF(&PyArrayMultiIter_Type);\n\tPyDict_SetItemString(d, \"broadcast\", \n\t\t\t (PyObject *)&PyArrayMultiIter_Type);\n\tPy_INCREF(&PyArrayDescr_Type);\n\tPyDict_SetItemString(d, \"dtype\", (PyObject *)&PyArrayDescr_Type);\n\n\t/* Doesn't need to be exposed to Python \n Py_INCREF(&PyArrayMapIter_Type);\n\tPyDict_SetItemString(d, \"mapiter\", (PyObject *)&PyArrayMapIter_Type);\n\t*/\n set_flaginfo(d);\n\n\tif (set_typeinfo(d) != 0) goto err;\n\n\t_numpy_internal =\t\t\t\t\t\t\\\n\t\tPyImport_ImportModule(\"numpy.core._internal\");\n\tif (_numpy_internal != NULL) return;\n\n err:\t\n\tif (!PyErr_Occurred()) {\n\t\tPyErr_SetString(PyExc_RuntimeError, \n\t\t\t\t\"cannot load multiarray module.\");\n\t}\n\treturn;\n}\n\n", + "methods": [ + { + "name": "_arraydescr_fromobj", + "long_name": "_arraydescr_fromobj( PyObject * obj)", + "filename": "multiarraymodule.c", + "nloc": 15, + "complexity": 3, + "token_count": 67, + "parameters": [ + "obj" + ], + "start_line": 35, + "end_line": 50, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 16, + "top_nesting_level": 0 + }, + { + "name": "PyArray_MultiplyIntList", + "long_name": "PyArray_MultiplyIntList( register int * l1 , register int n)", + "filename": "multiarraymodule.c", + "nloc": 6, + "complexity": 2, + "token_count": 36, + "parameters": [ + "l1", + "n" + ], + "start_line": 75, + "end_line": 80, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 6, + "top_nesting_level": 0 + }, + { + "name": "PyArray_MultiplyList", + "long_name": "PyArray_MultiplyList( register intp * l1 , register int n)", + "filename": "multiarraymodule.c", + "nloc": 6, + "complexity": 2, + "token_count": 36, + "parameters": [ + "l1", + "n" + ], + "start_line": 86, + "end_line": 91, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 6, + "top_nesting_level": 0 + }, + { + "name": "PyArray_GetPtr", + "long_name": "PyArray_GetPtr( PyArrayObject * obj , register intp * ind)", + "filename": "multiarraymodule.c", + "nloc": 8, + "complexity": 2, + "token_count": 61, + "parameters": [ + "obj", + "ind" + ], + "start_line": 97, + "end_line": 105, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 9, + "top_nesting_level": 0 + }, + { + "name": "PyArray_AxisConverter", + "long_name": "PyArray_AxisConverter( PyObject * obj , int * axis)", + "filename": "multiarraymodule.c", + "nloc": 13, + "complexity": 3, + "token_count": 53, + "parameters": [ + "obj", + "axis" + ], + "start_line": 111, + "end_line": 123, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 13, + "top_nesting_level": 0 + }, + { + "name": "PyArray_CompareLists", + "long_name": "PyArray_CompareLists( intp * l1 , intp * l2 , int n)", + "filename": "multiarraymodule.c", + "nloc": 8, + "complexity": 3, + "token_count": 51, + "parameters": [ + "l1", + "l2", + "n" + ], + "start_line": 129, + "end_line": 136, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 8, + "top_nesting_level": 0 + }, + { + "name": "PyArray_View", + "long_name": "PyArray_View( PyArrayObject * self , PyArray_Descr * type , PyTypeObject * pytype)", + "filename": "multiarraymodule.c", + "nloc": 27, + "complexity": 5, + "token_count": 158, + "parameters": [ + "self", + "type", + "pytype" + ], + "start_line": 143, + "end_line": 173, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 31, + "top_nesting_level": 0 + }, + { + "name": "PyArray_Ravel", + "long_name": "PyArray_Ravel( PyArrayObject * a , int fortran)", + "filename": "multiarraymodule.c", + "nloc": 16, + "complexity": 5, + "token_count": 102, + "parameters": [ + "a", + "fortran" + ], + "start_line": 179, + "end_line": 196, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 18, + "top_nesting_level": 0 + }, + { + "name": "PyArray_Flatten", + "long_name": "PyArray_Flatten( PyArrayObject * a , int fortran)", + "filename": "multiarraymodule.c", + "nloc": 33, + "complexity": 6, + "token_count": 176, + "parameters": [ + "a", + "fortran" + ], + "start_line": 202, + "end_line": 237, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 36, + "top_nesting_level": 0 + }, + { + "name": "PyArray_Reshape", + "long_name": "PyArray_Reshape( PyArrayObject * self , PyObject * shape)", + "filename": "multiarraymodule.c", + "nloc": 9, + "complexity": 2, + "token_count": 53, + "parameters": [ + "self", + "shape" + ], + "start_line": 248, + "end_line": 257, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 10, + "top_nesting_level": 0 + }, + { + "name": "_check_ones", + "long_name": "_check_ones( PyArrayObject * self , int newnd , intp * newdims , intp * strides)", + "filename": "multiarraymodule.c", + "nloc": 25, + "complexity": 12, + "token_count": 189, + "parameters": [ + "self", + "newnd", + "newdims", + "strides" + ], + "start_line": 260, + "end_line": 286, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 27, + "top_nesting_level": 0 + }, + { + "name": "PyArray_Newshape", + "long_name": "PyArray_Newshape( PyArrayObject * self , PyArray_Dims * newdims)", + "filename": "multiarraymodule.c", + "nloc": 72, + "complexity": 17, + "token_count": 409, + "parameters": [ + "self", + "newdims" + ], + "start_line": 297, + "end_line": 384, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 88, + "top_nesting_level": 0 + }, + { + "name": "PyArray_Squeeze", + "long_name": "PyArray_Squeeze( PyArrayObject * self)", + "filename": "multiarraymodule.c", + "nloc": 34, + "complexity": 5, + "token_count": 204, + "parameters": [ + "self" + ], + "start_line": 393, + "end_line": 428, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 36, + "top_nesting_level": 0 + }, + { + "name": "PyArray_Mean", + "long_name": "PyArray_Mean( PyArrayObject * self , int axis , int rtype)", + "filename": "multiarraymodule.c", + "nloc": 19, + "complexity": 4, + "token_count": 139, + "parameters": [ + "self", + "axis", + "rtype" + ], + "start_line": 435, + "end_line": 456, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 22, + "top_nesting_level": 0 + }, + { + "name": "PyArray_Std", + "long_name": "PyArray_Std( PyArrayObject * self , int axis , int rtype , int variance)", + "filename": "multiarraymodule.c", + "nloc": 45, + "complexity": 13, + "token_count": 450, + "parameters": [ + "self", + "axis", + "rtype", + "variance" + ], + "start_line": 463, + "end_line": 522, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 60, + "top_nesting_level": 0 + }, + { + "name": "PyArray_Sum", + "long_name": "PyArray_Sum( PyArrayObject * self , int axis , int rtype)", + "filename": "multiarraymodule.c", + "nloc": 9, + "complexity": 2, + "token_count": 69, + "parameters": [ + "self", + "axis", + "rtype" + ], + "start_line": 529, + "end_line": 539, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 11, + "top_nesting_level": 0 + }, + { + "name": "PyArray_Prod", + "long_name": "PyArray_Prod( PyArrayObject * self , int axis , int rtype)", + "filename": "multiarraymodule.c", + "nloc": 9, + "complexity": 2, + "token_count": 69, + "parameters": [ + "self", + "axis", + "rtype" + ], + "start_line": 545, + "end_line": 555, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 11, + "top_nesting_level": 0 + }, + { + "name": "PyArray_CumSum", + "long_name": "PyArray_CumSum( PyArrayObject * self , int axis , int rtype)", + "filename": "multiarraymodule.c", + "nloc": 9, + "complexity": 2, + "token_count": 69, + "parameters": [ + "self", + "axis", + "rtype" + ], + "start_line": 561, + "end_line": 571, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 11, + "top_nesting_level": 0 + }, + { + "name": "PyArray_CumProd", + "long_name": "PyArray_CumProd( PyArrayObject * self , int axis , int rtype)", + "filename": "multiarraymodule.c", + "nloc": 10, + "complexity": 2, + "token_count": 69, + "parameters": [ + "self", + "axis", + "rtype" + ], + "start_line": 577, + "end_line": 588, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 12, + "top_nesting_level": 0 + }, + { + "name": "PyArray_Any", + "long_name": "PyArray_Any( PyArrayObject * self , int axis)", + "filename": "multiarraymodule.c", + "nloc": 10, + "complexity": 2, + "token_count": 66, + "parameters": [ + "self", + "axis" + ], + "start_line": 594, + "end_line": 605, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 12, + "top_nesting_level": 0 + }, + { + "name": "PyArray_All", + "long_name": "PyArray_All( PyArrayObject * self , int axis)", + "filename": "multiarraymodule.c", + "nloc": 10, + "complexity": 2, + "token_count": 66, + "parameters": [ + "self", + "axis" + ], + "start_line": 611, + "end_line": 622, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 12, + "top_nesting_level": 0 + }, + { + "name": "PyArray_Compress", + "long_name": "PyArray_Compress( PyArrayObject * self , PyObject * condition , int axis)", + "filename": "multiarraymodule.c", + "nloc": 18, + "complexity": 3, + "token_count": 102, + "parameters": [ + "self", + "condition", + "axis" + ], + "start_line": 629, + "end_line": 649, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 21, + "top_nesting_level": 0 + }, + { + "name": "PyArray_Nonzero", + "long_name": "PyArray_Nonzero( PyArrayObject * self)", + "filename": "multiarraymodule.c", + "nloc": 51, + "complexity": 13, + "token_count": 414, + "parameters": [ + "self" + ], + "start_line": 655, + "end_line": 714, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 60, + "top_nesting_level": 0 + }, + { + "name": "PyArray_Clip", + "long_name": "PyArray_Clip( PyArrayObject * self , PyObject * min , PyObject * max)", + "filename": "multiarraymodule.c", + "nloc": 28, + "complexity": 6, + "token_count": 237, + "parameters": [ + "self", + "min", + "max" + ], + "start_line": 720, + "end_line": 750, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 31, + "top_nesting_level": 0 + }, + { + "name": "PyArray_Conjugate", + "long_name": "PyArray_Conjugate( PyArrayObject * self)", + "filename": "multiarraymodule.c", + "nloc": 36, + "complexity": 9, + "token_count": 228, + "parameters": [ + "self" + ], + "start_line": 756, + "end_line": 792, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 37, + "top_nesting_level": 0 + }, + { + "name": "PyArray_Trace", + "long_name": "PyArray_Trace( PyArrayObject * self , int offset , int axis1 , int axis2 , int rtype)", + "filename": "multiarraymodule.c", + "nloc": 10, + "complexity": 2, + "token_count": 81, + "parameters": [ + "self", + "offset", + "axis1", + "axis2", + "rtype" + ], + "start_line": 798, + "end_line": 808, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 11, + "top_nesting_level": 0 + }, + { + "name": "PyArray_Diagonal", + "long_name": "PyArray_Diagonal( PyArrayObject * self , int offset , int axis1 , int axis2)", + "filename": "multiarraymodule.c", + "nloc": 104, + "complexity": 23, + "token_count": 776, + "parameters": [ + "self", + "offset", + "axis1", + "axis2" + ], + "start_line": 814, + "end_line": 933, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 120, + "top_nesting_level": 0 + }, + { + "name": "PyArray_AsCArray", + "long_name": "PyArray_AsCArray( PyObject ** op , * ptr , intp * dims , int nd , PyArray_Descr * typedescr)", + "filename": "multiarraymodule.c", + "nloc": 50, + "complexity": 12, + "token_count": 402, + "parameters": [ + "op", + "ptr", + "dims", + "nd", + "typedescr" + ], + "start_line": 949, + "end_line": 1000, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 52, + "top_nesting_level": 0 + }, + { + "name": "PyArray_As1D", + "long_name": "PyArray_As1D( PyObject ** op , char ** ptr , int * d1 , int typecode)", + "filename": "multiarraymodule.c", + "nloc": 10, + "complexity": 2, + "token_count": 71, + "parameters": [ + "op", + "ptr", + "d1", + "typecode" + ], + "start_line": 1008, + "end_line": 1018, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 11, + "top_nesting_level": 0 + }, + { + "name": "PyArray_As2D", + "long_name": "PyArray_As2D( PyObject ** op , char ** * ptr , int * d1 , int * d2 , int typecode)", + "filename": "multiarraymodule.c", + "nloc": 11, + "complexity": 2, + "token_count": 92, + "parameters": [ + "op", + "ptr", + "d1", + "d2", + "typecode" + ], + "start_line": 1024, + "end_line": 1036, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 13, + "top_nesting_level": 0 + }, + { + "name": "PyArray_Free", + "long_name": "PyArray_Free( PyObject * op , * ptr)", + "filename": "multiarraymodule.c", + "nloc": 11, + "complexity": 4, + "token_count": 67, + "parameters": [ + "op", + "ptr" + ], + "start_line": 1044, + "end_line": 1055, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 12, + "top_nesting_level": 0 + }, + { + "name": "_swap_and_concat", + "long_name": "_swap_and_concat( PyObject * op , int axis , int n)", + "filename": "multiarraymodule.c", + "nloc": 27, + "complexity": 6, + "token_count": 185, + "parameters": [ + "op", + "axis", + "n" + ], + "start_line": 1059, + "end_line": 1087, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 29, + "top_nesting_level": 0 + }, + { + "name": "PyArray_Concatenate", + "long_name": "PyArray_Concatenate( PyObject * op , int axis)", + "filename": "multiarraymodule.c", + "nloc": 94, + "complexity": 21, + "token_count": 630, + "parameters": [ + "op", + "axis" + ], + "start_line": 1099, + "end_line": 1205, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 107, + "top_nesting_level": 0 + }, + { + "name": "PyArray_SwapAxes", + "long_name": "PyArray_SwapAxes( PyArrayObject * ap , int a1 , int a2)", + "filename": "multiarraymodule.c", + "nloc": 38, + "complexity": 12, + "token_count": 227, + "parameters": [ + "ap", + "a1", + "a2" + ], + "start_line": 1211, + "end_line": 1252, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 42, + "top_nesting_level": 0 + }, + { + "name": "PyArray_Transpose", + "long_name": "PyArray_Transpose( PyArrayObject * ap , PyArray_Dims * permute)", + "filename": "multiarraymodule.c", + "nloc": 46, + "complexity": 10, + "token_count": 309, + "parameters": [ + "ap", + "permute" + ], + "start_line": 1258, + "end_line": 1311, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 54, + "top_nesting_level": 0 + }, + { + "name": "PyArray_Repeat", + "long_name": "PyArray_Repeat( PyArrayObject * aop , PyObject * op , int axis)", + "filename": "multiarraymodule.c", + "nloc": 78, + "complexity": 15, + "token_count": 523, + "parameters": [ + "aop", + "op", + "axis" + ], + "start_line": 1317, + "end_line": 1412, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 96, + "top_nesting_level": 0 + }, + { + "name": "PyArray_ConvertToCommonType", + "long_name": "PyArray_ConvertToCommonType( PyObject * op , int * retn)", + "filename": "multiarraymodule.c", + "nloc": 65, + "complexity": 13, + "token_count": 439, + "parameters": [ + "op", + "retn" + ], + "start_line": 1416, + "end_line": 1487, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 72, + "top_nesting_level": 0 + }, + { + "name": "PyArray_Choose", + "long_name": "PyArray_Choose( PyArrayObject * ip , PyObject * op)", + "filename": "multiarraymodule.c", + "nloc": 70, + "complexity": 15, + "token_count": 518, + "parameters": [ + "ip", + "op" + ], + "start_line": 1494, + "end_line": 1575, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 82, + "top_nesting_level": 0 + }, + { + "name": "_strided_copy", + "long_name": "_strided_copy( char * dst , intp dststride , char * src , intp srcstride , intp num , int elsize)", + "filename": "multiarraymodule.c", + "nloc": 8, + "complexity": 2, + "token_count": 48, + "parameters": [ + "dst", + "dststride", + "src", + "srcstride", + "num", + "elsize" + ], + "start_line": 1578, + "end_line": 1585, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 8, + "top_nesting_level": 0 + }, + { + "name": "_new_sort", + "long_name": "_new_sort( PyArrayObject * op , int axis , PyArray_SORTKIND which)", + "filename": "multiarraymodule.c", + "nloc": 47, + "complexity": 8, + "token_count": 284, + "parameters": [ + "op", + "axis", + "which" + ], + "start_line": 1596, + "end_line": 1650, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 55, + "top_nesting_level": 0 + }, + { + "name": "_new_argsort", + "long_name": "_new_argsort( PyArrayObject * op , int axis , PyArray_SORTKIND which)", + "filename": "multiarraymodule.c", + "nloc": 67, + "complexity": 13, + "token_count": 498, + "parameters": [ + "op", + "axis", + "which" + ], + "start_line": 1653, + "end_line": 1731, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 79, + "top_nesting_level": 0 + }, + { + "name": "qsortCompare", + "long_name": "qsortCompare( const * a , const * b)", + "filename": "multiarraymodule.c", + "nloc": 4, + "complexity": 1, + "token_count": 30, + "parameters": [ + "a", + "b" + ], + "start_line": 1739, + "end_line": 1742, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 4, + "top_nesting_level": 0 + }, + { + "name": "PyArray_Sort", + "long_name": "PyArray_Sort( PyArrayObject * op , int axis , PyArray_SORTKIND which)", + "filename": "multiarraymodule.c", + "nloc": 52, + "complexity": 14, + "token_count": 355, + "parameters": [ + "op", + "axis", + "which" + ], + "start_line": 1797, + "end_line": 1863, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 67, + "top_nesting_level": 0 + }, + { + "name": "argsort_static_compare", + "long_name": "argsort_static_compare( const * ip1 , const * ip2)", + "filename": "multiarraymodule.c", + "nloc": 9, + "complexity": 1, + "token_count": 67, + "parameters": [ + "ip1", + "ip2" + ], + "start_line": 1869, + "end_line": 1877, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 9, + "top_nesting_level": 0 + }, + { + "name": "PyArray_ArgSort", + "long_name": "PyArray_ArgSort( PyArrayObject * op , int axis , PyArray_SORTKIND which)", + "filename": "multiarraymodule.c", + "nloc": 66, + "complexity": 15, + "token_count": 493, + "parameters": [ + "op", + "axis", + "which" + ], + "start_line": 1883, + "end_line": 1963, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 81, + "top_nesting_level": 0 + }, + { + "name": "PyArray_LexSort", + "long_name": "PyArray_LexSort( PyObject * sort_keys , int axis)", + "filename": "multiarraymodule.c", + "nloc": 132, + "complexity": 36, + "token_count": 1162, + "parameters": [ + "sort_keys", + "axis" + ], + "start_line": 1975, + "end_line": 2119, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 145, + "top_nesting_level": 0 + }, + { + "name": "local_where", + "long_name": "local_where( PyArrayObject * ap1 , PyArrayObject * ap2 , PyArrayObject * ret)", + "filename": "multiarraymodule.c", + "nloc": 35, + "complexity": 7, + "token_count": 243, + "parameters": [ + "ap1", + "ap2", + "ret" + ], + "start_line": 2123, + "end_line": 2158, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 36, + "top_nesting_level": 0 + }, + { + "name": "PyArray_SearchSorted", + "long_name": "PyArray_SearchSorted( PyArrayObject * op1 , PyObject * op2)", + "filename": "multiarraymodule.c", + "nloc": 33, + "complexity": 5, + "token_count": 231, + "parameters": [ + "op1", + "op2" + ], + "start_line": 2164, + "end_line": 2209, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 46, + "top_nesting_level": 0 + }, + { + "name": "new_array_for_sum", + "long_name": "new_array_for_sum( PyArrayObject * ap1 , PyArrayObject * ap2 , int nd , intp dimensions [ ] , int typenum)", + "filename": "multiarraymodule.c", + "nloc": 20, + "complexity": 4, + "token_count": 147, + "parameters": [ + "ap1", + "ap2", + "nd", + "typenum" + ], + "start_line": 2216, + "end_line": 2240, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 25, + "top_nesting_level": 0 + }, + { + "name": "PyArray_InnerProduct", + "long_name": "PyArray_InnerProduct( PyObject * op1 , PyObject * op2)", + "filename": "multiarraymodule.c", + "nloc": 74, + "complexity": 15, + "token_count": 584, + "parameters": [ + "op1", + "op2" + ], + "start_line": 2249, + "end_line": 2342, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 94, + "top_nesting_level": 0 + }, + { + "name": "PyArray_MatrixProduct", + "long_name": "PyArray_MatrixProduct( PyObject * op1 , PyObject * op2)", + "filename": "multiarraymodule.c", + "nloc": 94, + "complexity": 18, + "token_count": 733, + "parameters": [ + "op1", + "op2" + ], + "start_line": 2350, + "end_line": 2467, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 118, + "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": 2473, + "end_line": 2527, + "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": 2533, + "end_line": 2630, + "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": 2637, + "end_line": 2661, + "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": 2667, + "end_line": 2678, + "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": 2684, + "end_line": 2695, + "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": 2701, + "end_line": 2724, + "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": 2731, + "end_line": 2788, + "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": 2795, + "end_line": 2870, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 76, + "top_nesting_level": 0 + }, + { + "name": "PyArray_Put", + "long_name": "PyArray_Put( PyArrayObject * self , PyObject * values0 , PyObject * indices0)", + "filename": "multiarraymodule.c", + "nloc": 63, + "complexity": 15, + "token_count": 465, + "parameters": [ + "self", + "values0", + "indices0" + ], + "start_line": 2876, + "end_line": 2945, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 70, + "top_nesting_level": 0 + }, + { + "name": "PyArray_PutMask", + "long_name": "PyArray_PutMask( PyArrayObject * self , PyObject * values0 , PyObject * mask0)", + "filename": "multiarraymodule.c", + "nloc": 65, + "complexity": 12, + "token_count": 422, + "parameters": [ + "self", + "values0", + "mask0" + ], + "start_line": 2951, + "end_line": 3022, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 72, + "top_nesting_level": 0 + }, + { + "name": "PyArray_Converter", + "long_name": "PyArray_Converter( PyObject * object , PyObject ** address)", + "filename": "multiarraymodule.c", + "nloc": 13, + "complexity": 3, + "token_count": 68, + "parameters": [ + "object", + "address" + ], + "start_line": 3038, + "end_line": 3050, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 13, + "top_nesting_level": 0 + }, + { + "name": "PyArray_BoolConverter", + "long_name": "PyArray_BoolConverter( PyObject * object , Bool * val)", + "filename": "multiarraymodule.c", + "nloc": 9, + "complexity": 3, + "token_count": 42, + "parameters": [ + "object", + "val" + ], + "start_line": 3056, + "end_line": 3064, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 9, + "top_nesting_level": 0 + }, + { + "name": "PyArray_TypestrConvert", + "long_name": "PyArray_TypestrConvert( int itemsize , int gentype)", + "filename": "multiarraymodule.c", + "nloc": 96, + "complexity": 35, + "token_count": 308, + "parameters": [ + "itemsize", + "gentype" + ], + "start_line": 3071, + "end_line": 3186, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 116, + "top_nesting_level": 0 + }, + { + "name": "PyArray_BufferConverter", + "long_name": "PyArray_BufferConverter( PyObject * obj , PyArray_Chunk * buf)", + "filename": "multiarraymodule.c", + "nloc": 20, + "complexity": 6, + "token_count": 147, + "parameters": [ + "obj", + "buf" + ], + "start_line": 3204, + "end_line": 3229, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 26, + "top_nesting_level": 0 + }, + { + "name": "PyArray_IntpConverter", + "long_name": "PyArray_IntpConverter( PyObject * obj , PyArray_Dims * seq)", + "filename": "multiarraymodule.c", + "nloc": 36, + "complexity": 10, + "token_count": 189, + "parameters": [ + "obj", + "seq" + ], + "start_line": 3244, + "end_line": 3280, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 37, + "top_nesting_level": 0 + }, + { + "name": "_use_inherit", + "long_name": "_use_inherit( PyArray_Descr * type , PyObject * newobj , int * errflag)", + "filename": "multiarraymodule.c", + "nloc": 32, + "complexity": 7, + "token_count": 161, + "parameters": [ + "type", + "newobj", + "errflag" + ], + "start_line": 3298, + "end_line": 3331, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 34, + "top_nesting_level": 0 + }, + { + "name": "_convert_from_tuple", + "long_name": "_convert_from_tuple( PyObject * obj)", + "filename": "multiarraymodule.c", + "nloc": 62, + "complexity": 15, + "token_count": 381, + "parameters": [ + "obj" + ], + "start_line": 3334, + "end_line": 3408, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 75, + "top_nesting_level": 0 + }, + { + "name": "_convert_from_array_descr", + "long_name": "_convert_from_array_descr( PyObject * obj)", + "filename": "multiarraymodule.c", + "nloc": 69, + "complexity": 14, + "token_count": 442, + "parameters": [ + "obj" + ], + "start_line": 3416, + "end_line": 3487, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 72, + "top_nesting_level": 0 + }, + { + "name": "_convert_from_list", + "long_name": "_convert_from_list( PyObject * obj , int align , int try_descr)", + "filename": "multiarraymodule.c", + "nloc": 70, + "complexity": 13, + "token_count": 428, + "parameters": [ + "obj", + "align", + "try_descr" + ], + "start_line": 3498, + "end_line": 3569, + "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": 3582, + "end_line": 3598, + "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": 3635, + "end_line": 3640, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 6, + "top_nesting_level": 0 + }, + { + "name": "_convert_from_dict", + "long_name": "_convert_from_dict( PyObject * obj , int align)", + "filename": "multiarraymodule.c", + "nloc": 102, + "complexity": 28, + "token_count": 689, + "parameters": [ + "obj", + "align" + ], + "start_line": 3643, + "end_line": 3754, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 112, + "top_nesting_level": 0 + }, + { + "name": "PyArray_DescrConverter2", + "long_name": "PyArray_DescrConverter2( PyObject * obj , PyArray_Descr ** at)", + "filename": "multiarraymodule.c", + "nloc": 8, + "complexity": 2, + "token_count": 37, + "parameters": [ + "obj", + "at" + ], + "start_line": 3772, + "end_line": 3779, + "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": 146, + "complexity": 57, + "token_count": 916, + "parameters": [ + "obj", + "at" + ], + "start_line": 3796, + "end_line": 3976, + "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": 3982, + "end_line": 4014, + "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": 4020, + "end_line": 4046, + "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": 4055, + "end_line": 4074, + "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": 4079, + "end_line": 4104, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 26, + "top_nesting_level": 0 + }, + { + "name": "_array_fromobject", + "long_name": "_array_fromobject( PyObject * ignored , PyObject * args , PyObject * kws)", + "filename": "multiarraymodule.c", + "nloc": 66, + "complexity": 16, + "token_count": 380, + "parameters": [ + "ignored", + "args", + "kws" + ], + "start_line": 4126, + "end_line": 4201, + "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": 4209, + "end_line": 4224, + "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": 4230, + "end_line": 4254, + "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": 4259, + "end_line": 4317, + "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": 4326, + "end_line": 4350, + "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": 4356, + "end_line": 4380, + "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": 4387, + "end_line": 4396, + "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": 4399, + "end_line": 4410, + "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": 4415, + "end_line": 4557, + "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": 4562, + "end_line": 4579, + "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": 4593, + "end_line": 4721, + "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": 4739, + "end_line": 4777, + "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": 4781, + "end_line": 4874, + "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": 4890, + "end_line": 4907, + "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": 4913, + "end_line": 4924, + "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": 4931, + "end_line": 4937, + "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": 4944, + "end_line": 4950, + "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": 4954, + "end_line": 4960, + "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": 4964, + "end_line": 4973, + "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": 4980, + "end_line": 5031, + "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": 5037, + "end_line": 5069, + "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": 5076, + "end_line": 5160, + "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": 5166, + "end_line": 5178, + "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": 5184, + "end_line": 5187, + "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": 5193, + "end_line": 5199, + "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": 5205, + "end_line": 5221, + "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": 5227, + "end_line": 5244, + "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": 5251, + "end_line": 5291, + "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": 5299, + "end_line": 5307, + "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": 5319, + "end_line": 5329, + "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": 5338, + "end_line": 5349, + "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": 5356, + "end_line": 5379, + "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": 5386, + "end_line": 5394, + "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": 5403, + "end_line": 5421, + "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": 5487, + "end_line": 5600, + "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": 5605, + "end_line": 5629, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 25, + "top_nesting_level": 0 + }, + { + "name": "initmultiarray", + "long_name": "initmultiarray()", + "filename": "multiarraymodule.c", + "nloc": 64, + "complexity": 15, + "token_count": 435, + "parameters": [], + "start_line": 5634, + "end_line": 5726, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 93, + "top_nesting_level": 0 + } + ], + "methods_before": [ + { + "name": "_arraydescr_fromobj", + "long_name": "_arraydescr_fromobj( PyObject * obj)", + "filename": "multiarraymodule.c", + "nloc": 15, + "complexity": 3, + "token_count": 67, + "parameters": [ + "obj" + ], + "start_line": 35, + "end_line": 50, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 16, + "top_nesting_level": 0 + }, + { + "name": "PyArray_MultiplyIntList", + "long_name": "PyArray_MultiplyIntList( register int * l1 , register int n)", + "filename": "multiarraymodule.c", + "nloc": 6, + "complexity": 2, + "token_count": 36, + "parameters": [ + "l1", + "n" + ], + "start_line": 75, + "end_line": 80, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 6, + "top_nesting_level": 0 + }, + { + "name": "PyArray_MultiplyList", + "long_name": "PyArray_MultiplyList( register intp * l1 , register int n)", + "filename": "multiarraymodule.c", + "nloc": 6, + "complexity": 2, + "token_count": 36, + "parameters": [ + "l1", + "n" + ], + "start_line": 86, + "end_line": 91, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 6, + "top_nesting_level": 0 + }, + { + "name": "PyArray_GetPtr", + "long_name": "PyArray_GetPtr( PyArrayObject * obj , register intp * ind)", + "filename": "multiarraymodule.c", + "nloc": 8, + "complexity": 2, + "token_count": 61, + "parameters": [ + "obj", + "ind" + ], + "start_line": 97, + "end_line": 105, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 9, + "top_nesting_level": 0 + }, + { + "name": "PyArray_AxisConverter", + "long_name": "PyArray_AxisConverter( PyObject * obj , int * axis)", + "filename": "multiarraymodule.c", + "nloc": 13, + "complexity": 3, + "token_count": 53, + "parameters": [ + "obj", + "axis" + ], + "start_line": 111, + "end_line": 123, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 13, + "top_nesting_level": 0 + }, + { + "name": "PyArray_CompareLists", + "long_name": "PyArray_CompareLists( intp * l1 , intp * l2 , int n)", + "filename": "multiarraymodule.c", + "nloc": 8, + "complexity": 3, + "token_count": 51, + "parameters": [ + "l1", + "l2", + "n" + ], + "start_line": 129, + "end_line": 136, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 8, + "top_nesting_level": 0 + }, + { + "name": "PyArray_View", + "long_name": "PyArray_View( PyArrayObject * self , PyArray_Descr * type , PyTypeObject * pytype)", + "filename": "multiarraymodule.c", + "nloc": 27, + "complexity": 5, + "token_count": 158, + "parameters": [ + "self", + "type", + "pytype" + ], + "start_line": 143, + "end_line": 173, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 31, + "top_nesting_level": 0 + }, + { + "name": "PyArray_Ravel", + "long_name": "PyArray_Ravel( PyArrayObject * a , int fortran)", + "filename": "multiarraymodule.c", + "nloc": 16, + "complexity": 5, + "token_count": 102, + "parameters": [ + "a", + "fortran" + ], + "start_line": 179, + "end_line": 196, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 18, + "top_nesting_level": 0 + }, + { + "name": "PyArray_Flatten", + "long_name": "PyArray_Flatten( PyArrayObject * a , int fortran)", + "filename": "multiarraymodule.c", + "nloc": 33, + "complexity": 6, + "token_count": 176, + "parameters": [ + "a", + "fortran" + ], + "start_line": 202, + "end_line": 237, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 36, + "top_nesting_level": 0 + }, + { + "name": "PyArray_Reshape", + "long_name": "PyArray_Reshape( PyArrayObject * self , PyObject * shape)", + "filename": "multiarraymodule.c", + "nloc": 9, + "complexity": 2, + "token_count": 53, + "parameters": [ + "self", + "shape" + ], + "start_line": 248, + "end_line": 257, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 10, + "top_nesting_level": 0 + }, + { + "name": "_check_ones", + "long_name": "_check_ones( PyArrayObject * self , int newnd , intp * newdims , intp * strides)", + "filename": "multiarraymodule.c", + "nloc": 25, + "complexity": 12, + "token_count": 189, + "parameters": [ + "self", + "newnd", + "newdims", + "strides" + ], + "start_line": 260, + "end_line": 286, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 27, + "top_nesting_level": 0 + }, + { + "name": "PyArray_Newshape", + "long_name": "PyArray_Newshape( PyArrayObject * self , PyArray_Dims * newdims)", + "filename": "multiarraymodule.c", + "nloc": 72, + "complexity": 17, + "token_count": 409, + "parameters": [ + "self", + "newdims" + ], + "start_line": 297, + "end_line": 384, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 88, + "top_nesting_level": 0 + }, + { + "name": "PyArray_Squeeze", + "long_name": "PyArray_Squeeze( PyArrayObject * self)", + "filename": "multiarraymodule.c", + "nloc": 34, + "complexity": 5, + "token_count": 204, + "parameters": [ + "self" + ], + "start_line": 393, + "end_line": 428, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 36, + "top_nesting_level": 0 + }, + { + "name": "PyArray_Mean", + "long_name": "PyArray_Mean( PyArrayObject * self , int axis , int rtype)", + "filename": "multiarraymodule.c", + "nloc": 19, + "complexity": 4, + "token_count": 139, + "parameters": [ + "self", + "axis", + "rtype" + ], + "start_line": 435, + "end_line": 456, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 22, + "top_nesting_level": 0 + }, + { + "name": "PyArray_Std", + "long_name": "PyArray_Std( PyArrayObject * self , int axis , int rtype , int variance)", + "filename": "multiarraymodule.c", + "nloc": 45, + "complexity": 13, + "token_count": 450, + "parameters": [ + "self", + "axis", + "rtype", + "variance" + ], + "start_line": 463, + "end_line": 522, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 60, + "top_nesting_level": 0 + }, + { + "name": "PyArray_Sum", + "long_name": "PyArray_Sum( PyArrayObject * self , int axis , int rtype)", + "filename": "multiarraymodule.c", + "nloc": 9, + "complexity": 2, + "token_count": 69, + "parameters": [ + "self", + "axis", + "rtype" + ], + "start_line": 529, + "end_line": 539, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 11, + "top_nesting_level": 0 + }, + { + "name": "PyArray_Prod", + "long_name": "PyArray_Prod( PyArrayObject * self , int axis , int rtype)", + "filename": "multiarraymodule.c", + "nloc": 9, + "complexity": 2, + "token_count": 69, + "parameters": [ + "self", + "axis", + "rtype" + ], + "start_line": 545, + "end_line": 555, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 11, + "top_nesting_level": 0 + }, + { + "name": "PyArray_CumSum", + "long_name": "PyArray_CumSum( PyArrayObject * self , int axis , int rtype)", + "filename": "multiarraymodule.c", + "nloc": 9, + "complexity": 2, + "token_count": 69, + "parameters": [ + "self", + "axis", + "rtype" + ], + "start_line": 561, + "end_line": 571, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 11, + "top_nesting_level": 0 + }, + { + "name": "PyArray_CumProd", + "long_name": "PyArray_CumProd( PyArrayObject * self , int axis , int rtype)", + "filename": "multiarraymodule.c", + "nloc": 10, + "complexity": 2, + "token_count": 69, + "parameters": [ + "self", + "axis", + "rtype" + ], + "start_line": 577, + "end_line": 588, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 12, + "top_nesting_level": 0 + }, + { + "name": "PyArray_Any", + "long_name": "PyArray_Any( PyArrayObject * self , int axis)", + "filename": "multiarraymodule.c", + "nloc": 10, + "complexity": 2, + "token_count": 66, + "parameters": [ + "self", + "axis" + ], + "start_line": 594, + "end_line": 605, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 12, + "top_nesting_level": 0 + }, + { + "name": "PyArray_All", + "long_name": "PyArray_All( PyArrayObject * self , int axis)", + "filename": "multiarraymodule.c", + "nloc": 10, + "complexity": 2, + "token_count": 66, + "parameters": [ + "self", + "axis" + ], + "start_line": 611, + "end_line": 622, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 12, + "top_nesting_level": 0 + }, + { + "name": "PyArray_Compress", + "long_name": "PyArray_Compress( PyArrayObject * self , PyObject * condition , int axis)", + "filename": "multiarraymodule.c", + "nloc": 18, + "complexity": 3, + "token_count": 102, + "parameters": [ + "self", + "condition", + "axis" + ], + "start_line": 629, + "end_line": 649, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 21, + "top_nesting_level": 0 + }, + { + "name": "PyArray_Nonzero", + "long_name": "PyArray_Nonzero( PyArrayObject * self)", + "filename": "multiarraymodule.c", + "nloc": 51, + "complexity": 13, + "token_count": 414, + "parameters": [ + "self" + ], + "start_line": 655, + "end_line": 714, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 60, + "top_nesting_level": 0 + }, + { + "name": "PyArray_Clip", + "long_name": "PyArray_Clip( PyArrayObject * self , PyObject * min , PyObject * max)", + "filename": "multiarraymodule.c", + "nloc": 28, + "complexity": 6, + "token_count": 237, + "parameters": [ + "self", + "min", + "max" + ], + "start_line": 720, + "end_line": 750, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 31, + "top_nesting_level": 0 + }, + { + "name": "PyArray_Conjugate", + "long_name": "PyArray_Conjugate( PyArrayObject * self)", + "filename": "multiarraymodule.c", + "nloc": 36, + "complexity": 9, + "token_count": 228, + "parameters": [ + "self" + ], + "start_line": 756, + "end_line": 792, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 37, + "top_nesting_level": 0 + }, + { + "name": "PyArray_Trace", + "long_name": "PyArray_Trace( PyArrayObject * self , int offset , int axis1 , int axis2 , int rtype)", + "filename": "multiarraymodule.c", + "nloc": 10, + "complexity": 2, + "token_count": 81, + "parameters": [ + "self", + "offset", + "axis1", + "axis2", + "rtype" + ], + "start_line": 798, + "end_line": 808, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 11, + "top_nesting_level": 0 + }, + { + "name": "PyArray_Diagonal", + "long_name": "PyArray_Diagonal( PyArrayObject * self , int offset , int axis1 , int axis2)", + "filename": "multiarraymodule.c", + "nloc": 104, + "complexity": 23, + "token_count": 776, + "parameters": [ + "self", + "offset", + "axis1", + "axis2" + ], + "start_line": 814, + "end_line": 933, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 120, + "top_nesting_level": 0 + }, + { + "name": "PyArray_AsCArray", + "long_name": "PyArray_AsCArray( PyObject ** op , * ptr , intp * dims , int nd , PyArray_Descr * typedescr)", + "filename": "multiarraymodule.c", + "nloc": 50, + "complexity": 12, + "token_count": 402, + "parameters": [ + "op", + "ptr", + "dims", + "nd", + "typedescr" + ], + "start_line": 949, + "end_line": 1000, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 52, + "top_nesting_level": 0 + }, + { + "name": "PyArray_As1D", + "long_name": "PyArray_As1D( PyObject ** op , char ** ptr , int * d1 , int typecode)", + "filename": "multiarraymodule.c", + "nloc": 10, + "complexity": 2, + "token_count": 71, + "parameters": [ + "op", + "ptr", + "d1", + "typecode" + ], + "start_line": 1008, + "end_line": 1018, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 11, + "top_nesting_level": 0 + }, + { + "name": "PyArray_As2D", + "long_name": "PyArray_As2D( PyObject ** op , char ** * ptr , int * d1 , int * d2 , int typecode)", + "filename": "multiarraymodule.c", + "nloc": 11, + "complexity": 2, + "token_count": 92, + "parameters": [ + "op", + "ptr", + "d1", + "d2", + "typecode" + ], + "start_line": 1024, + "end_line": 1036, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 13, + "top_nesting_level": 0 + }, + { + "name": "PyArray_Free", + "long_name": "PyArray_Free( PyObject * op , * ptr)", + "filename": "multiarraymodule.c", + "nloc": 11, + "complexity": 4, + "token_count": 67, + "parameters": [ + "op", + "ptr" + ], + "start_line": 1044, + "end_line": 1055, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 12, + "top_nesting_level": 0 + }, + { + "name": "_swap_and_concat", + "long_name": "_swap_and_concat( PyObject * op , int axis , int n)", + "filename": "multiarraymodule.c", + "nloc": 27, + "complexity": 6, + "token_count": 185, + "parameters": [ + "op", + "axis", + "n" + ], + "start_line": 1059, + "end_line": 1087, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 29, + "top_nesting_level": 0 + }, + { + "name": "PyArray_Concatenate", + "long_name": "PyArray_Concatenate( PyObject * op , int axis)", + "filename": "multiarraymodule.c", + "nloc": 94, + "complexity": 21, + "token_count": 630, + "parameters": [ + "op", + "axis" + ], + "start_line": 1099, + "end_line": 1205, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 107, + "top_nesting_level": 0 + }, + { + "name": "PyArray_SwapAxes", + "long_name": "PyArray_SwapAxes( PyArrayObject * ap , int a1 , int a2)", + "filename": "multiarraymodule.c", + "nloc": 38, + "complexity": 12, + "token_count": 227, + "parameters": [ + "ap", + "a1", + "a2" + ], + "start_line": 1211, + "end_line": 1252, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 42, + "top_nesting_level": 0 + }, + { + "name": "PyArray_Transpose", + "long_name": "PyArray_Transpose( PyArrayObject * ap , PyArray_Dims * permute)", + "filename": "multiarraymodule.c", + "nloc": 46, + "complexity": 10, + "token_count": 309, + "parameters": [ + "ap", + "permute" + ], + "start_line": 1258, + "end_line": 1311, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 54, + "top_nesting_level": 0 + }, + { + "name": "PyArray_Repeat", + "long_name": "PyArray_Repeat( PyArrayObject * aop , PyObject * op , int axis)", + "filename": "multiarraymodule.c", + "nloc": 78, + "complexity": 15, + "token_count": 523, + "parameters": [ + "aop", + "op", + "axis" + ], + "start_line": 1317, + "end_line": 1412, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 96, + "top_nesting_level": 0 + }, + { + "name": "PyArray_ConvertToCommonType", + "long_name": "PyArray_ConvertToCommonType( PyObject * op , int * retn)", + "filename": "multiarraymodule.c", + "nloc": 65, + "complexity": 13, + "token_count": 439, + "parameters": [ + "op", + "retn" + ], + "start_line": 1416, + "end_line": 1487, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 72, + "top_nesting_level": 0 + }, + { + "name": "PyArray_Choose", + "long_name": "PyArray_Choose( PyArrayObject * ip , PyObject * op)", + "filename": "multiarraymodule.c", + "nloc": 70, + "complexity": 15, + "token_count": 518, + "parameters": [ + "ip", + "op" + ], + "start_line": 1494, + "end_line": 1575, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 82, + "top_nesting_level": 0 + }, + { + "name": "_strided_copy", + "long_name": "_strided_copy( char * dst , intp dststride , char * src , intp srcstride , intp num , int elsize)", + "filename": "multiarraymodule.c", + "nloc": 8, + "complexity": 2, + "token_count": 48, + "parameters": [ + "dst", + "dststride", + "src", + "srcstride", + "num", + "elsize" + ], + "start_line": 1578, + "end_line": 1585, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 8, + "top_nesting_level": 0 + }, + { + "name": "_new_sort", + "long_name": "_new_sort( PyArrayObject * op , int axis , PyArray_SORTKIND which)", + "filename": "multiarraymodule.c", + "nloc": 47, + "complexity": 8, + "token_count": 284, + "parameters": [ + "op", + "axis", + "which" + ], + "start_line": 1596, + "end_line": 1650, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 55, + "top_nesting_level": 0 + }, + { + "name": "_new_argsort", + "long_name": "_new_argsort( PyArrayObject * op , int axis , PyArray_SORTKIND which)", + "filename": "multiarraymodule.c", + "nloc": 67, + "complexity": 13, + "token_count": 498, + "parameters": [ + "op", + "axis", + "which" + ], + "start_line": 1653, + "end_line": 1731, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 79, + "top_nesting_level": 0 + }, + { + "name": "qsortCompare", + "long_name": "qsortCompare( const * a , const * b)", + "filename": "multiarraymodule.c", + "nloc": 4, + "complexity": 1, + "token_count": 30, + "parameters": [ + "a", + "b" + ], + "start_line": 1739, + "end_line": 1742, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 4, + "top_nesting_level": 0 + }, + { + "name": "PyArray_Sort", + "long_name": "PyArray_Sort( PyArrayObject * op , int axis , PyArray_SORTKIND which)", + "filename": "multiarraymodule.c", + "nloc": 52, + "complexity": 14, + "token_count": 355, + "parameters": [ + "op", + "axis", + "which" + ], + "start_line": 1797, + "end_line": 1863, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 67, + "top_nesting_level": 0 + }, + { + "name": "argsort_static_compare", + "long_name": "argsort_static_compare( const * ip1 , const * ip2)", + "filename": "multiarraymodule.c", + "nloc": 9, + "complexity": 1, + "token_count": 67, + "parameters": [ + "ip1", + "ip2" + ], + "start_line": 1869, + "end_line": 1877, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 9, + "top_nesting_level": 0 + }, + { + "name": "PyArray_ArgSort", + "long_name": "PyArray_ArgSort( PyArrayObject * op , int axis , PyArray_SORTKIND which)", + "filename": "multiarraymodule.c", + "nloc": 66, + "complexity": 15, + "token_count": 493, + "parameters": [ + "op", + "axis", + "which" + ], + "start_line": 1883, + "end_line": 1963, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 81, + "top_nesting_level": 0 + }, + { + "name": "PyArray_LexSort", + "long_name": "PyArray_LexSort( PyObject * sort_keys , int axis)", + "filename": "multiarraymodule.c", + "nloc": 132, + "complexity": 36, + "token_count": 1162, + "parameters": [ + "sort_keys", + "axis" + ], + "start_line": 1975, + "end_line": 2119, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 145, + "top_nesting_level": 0 + }, + { + "name": "local_where", + "long_name": "local_where( PyArrayObject * ap1 , PyArrayObject * ap2 , PyArrayObject * ret)", + "filename": "multiarraymodule.c", + "nloc": 35, + "complexity": 7, + "token_count": 243, + "parameters": [ + "ap1", + "ap2", + "ret" + ], + "start_line": 2123, + "end_line": 2158, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 36, + "top_nesting_level": 0 + }, + { + "name": "PyArray_SearchSorted", + "long_name": "PyArray_SearchSorted( PyArrayObject * op1 , PyObject * op2)", + "filename": "multiarraymodule.c", + "nloc": 33, + "complexity": 5, + "token_count": 231, + "parameters": [ + "op1", + "op2" + ], + "start_line": 2164, + "end_line": 2209, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 46, + "top_nesting_level": 0 + }, + { + "name": "new_array_for_sum", + "long_name": "new_array_for_sum( PyArrayObject * ap1 , PyArrayObject * ap2 , int nd , intp dimensions [ ] , int typenum)", + "filename": "multiarraymodule.c", + "nloc": 20, + "complexity": 4, + "token_count": 147, + "parameters": [ + "ap1", + "ap2", + "nd", + "typenum" + ], + "start_line": 2216, + "end_line": 2240, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 25, + "top_nesting_level": 0 + }, + { + "name": "PyArray_InnerProduct", + "long_name": "PyArray_InnerProduct( PyObject * op1 , PyObject * op2)", + "filename": "multiarraymodule.c", + "nloc": 74, + "complexity": 15, + "token_count": 584, + "parameters": [ + "op1", + "op2" + ], + "start_line": 2249, + "end_line": 2342, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 94, + "top_nesting_level": 0 + }, + { + "name": "PyArray_MatrixProduct", + "long_name": "PyArray_MatrixProduct( PyObject * op1 , PyObject * op2)", + "filename": "multiarraymodule.c", + "nloc": 94, + "complexity": 18, + "token_count": 733, + "parameters": [ + "op1", + "op2" + ], + "start_line": 2350, + "end_line": 2467, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 118, + "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": 2473, + "end_line": 2527, + "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": 2533, + "end_line": 2630, + "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": 2637, + "end_line": 2661, + "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": 2667, + "end_line": 2678, + "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": 2684, + "end_line": 2695, + "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": 2701, + "end_line": 2724, + "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": 2731, + "end_line": 2788, + "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": 2795, + "end_line": 2870, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 76, + "top_nesting_level": 0 + }, + { + "name": "PyArray_Put", + "long_name": "PyArray_Put( PyArrayObject * self , PyObject * values0 , PyObject * indices0)", + "filename": "multiarraymodule.c", + "nloc": 63, + "complexity": 15, + "token_count": 465, + "parameters": [ + "self", + "values0", + "indices0" + ], + "start_line": 2876, + "end_line": 2945, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 70, + "top_nesting_level": 0 + }, + { + "name": "PyArray_PutMask", + "long_name": "PyArray_PutMask( PyArrayObject * self , PyObject * values0 , PyObject * mask0)", + "filename": "multiarraymodule.c", + "nloc": 65, + "complexity": 12, + "token_count": 422, + "parameters": [ + "self", + "values0", + "mask0" + ], + "start_line": 2951, + "end_line": 3022, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 72, + "top_nesting_level": 0 + }, + { + "name": "PyArray_Converter", + "long_name": "PyArray_Converter( PyObject * object , PyObject ** address)", + "filename": "multiarraymodule.c", + "nloc": 13, + "complexity": 3, + "token_count": 68, + "parameters": [ + "object", + "address" + ], + "start_line": 3038, + "end_line": 3050, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 13, + "top_nesting_level": 0 + }, + { + "name": "PyArray_BoolConverter", + "long_name": "PyArray_BoolConverter( PyObject * object , Bool * val)", + "filename": "multiarraymodule.c", + "nloc": 9, + "complexity": 3, + "token_count": 42, + "parameters": [ + "object", + "val" + ], + "start_line": 3056, + "end_line": 3064, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 9, + "top_nesting_level": 0 + }, + { + "name": "PyArray_TypestrConvert", + "long_name": "PyArray_TypestrConvert( int itemsize , int gentype)", + "filename": "multiarraymodule.c", + "nloc": 96, + "complexity": 35, + "token_count": 308, + "parameters": [ + "itemsize", + "gentype" + ], + "start_line": 3071, + "end_line": 3186, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 116, + "top_nesting_level": 0 + }, + { + "name": "PyArray_BufferConverter", + "long_name": "PyArray_BufferConverter( PyObject * obj , PyArray_Chunk * buf)", + "filename": "multiarraymodule.c", + "nloc": 20, + "complexity": 6, + "token_count": 147, + "parameters": [ + "obj", + "buf" + ], + "start_line": 3204, + "end_line": 3229, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 26, + "top_nesting_level": 0 + }, + { + "name": "PyArray_IntpConverter", + "long_name": "PyArray_IntpConverter( PyObject * obj , PyArray_Dims * seq)", + "filename": "multiarraymodule.c", + "nloc": 36, + "complexity": 10, + "token_count": 189, + "parameters": [ + "obj", + "seq" + ], + "start_line": 3244, + "end_line": 3280, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 37, + "top_nesting_level": 0 + }, + { + "name": "_use_inherit", + "long_name": "_use_inherit( PyArray_Descr * type , PyObject * newobj , int * errflag)", + "filename": "multiarraymodule.c", + "nloc": 32, + "complexity": 7, + "token_count": 161, + "parameters": [ + "type", + "newobj", + "errflag" + ], + "start_line": 3298, + "end_line": 3331, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 34, + "top_nesting_level": 0 + }, + { + "name": "_convert_from_tuple", + "long_name": "_convert_from_tuple( PyObject * obj)", + "filename": "multiarraymodule.c", + "nloc": 61, + "complexity": 14, + "token_count": 369, + "parameters": [ + "obj" + ], + "start_line": 3334, + "end_line": 3407, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 74, + "top_nesting_level": 0 + }, + { + "name": "_convert_from_array_descr", + "long_name": "_convert_from_array_descr( PyObject * obj)", + "filename": "multiarraymodule.c", + "nloc": 69, + "complexity": 14, + "token_count": 442, + "parameters": [ + "obj" + ], + "start_line": 3415, + "end_line": 3486, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 72, + "top_nesting_level": 0 + }, + { + "name": "_convert_from_list", + "long_name": "_convert_from_list( PyObject * obj , int align , int try_descr)", + "filename": "multiarraymodule.c", + "nloc": 66, + "complexity": 13, + "token_count": 416, + "parameters": [ + "obj", + "align", + "try_descr" + ], + "start_line": 3497, + "end_line": 3564, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 68, + "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": 3577, + "end_line": 3593, + "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": 3630, + "end_line": 3635, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 6, + "top_nesting_level": 0 + }, + { + "name": "_convert_from_dict", + "long_name": "_convert_from_dict( PyObject * obj , int align)", + "filename": "multiarraymodule.c", + "nloc": 102, + "complexity": 28, + "token_count": 689, + "parameters": [ + "obj", + "align" + ], + "start_line": 3638, + "end_line": 3749, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 112, + "top_nesting_level": 0 + }, + { + "name": "PyArray_DescrConverter2", + "long_name": "PyArray_DescrConverter2( PyObject * obj , PyArray_Descr ** at)", + "filename": "multiarraymodule.c", + "nloc": 8, + "complexity": 2, + "token_count": 37, + "parameters": [ + "obj", + "at" + ], + "start_line": 3767, + "end_line": 3774, + "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": 146, + "complexity": 57, + "token_count": 916, + "parameters": [ + "obj", + "at" + ], + "start_line": 3791, + "end_line": 3971, + "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": 3977, + "end_line": 4009, + "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": 4015, + "end_line": 4041, + "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": 4050, + "end_line": 4069, + "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": 4074, + "end_line": 4099, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 26, + "top_nesting_level": 0 + }, + { + "name": "_array_fromobject", + "long_name": "_array_fromobject( PyObject * ignored , PyObject * args , PyObject * kws)", + "filename": "multiarraymodule.c", + "nloc": 66, + "complexity": 16, + "token_count": 380, + "parameters": [ + "ignored", + "args", + "kws" + ], + "start_line": 4121, + "end_line": 4196, + "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": 4204, + "end_line": 4219, + "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": 4225, + "end_line": 4249, + "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": 4254, + "end_line": 4312, + "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": 4321, + "end_line": 4345, + "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": 4351, + "end_line": 4375, + "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": 4382, + "end_line": 4391, + "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": 4394, + "end_line": 4405, + "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": 4410, + "end_line": 4552, + "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": 4557, + "end_line": 4574, + "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": 4588, + "end_line": 4716, + "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": 4734, + "end_line": 4772, + "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": 4776, + "end_line": 4869, + "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": 4885, + "end_line": 4902, + "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": 4908, + "end_line": 4919, + "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": 4926, + "end_line": 4932, + "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": 4939, + "end_line": 4945, + "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": 4949, + "end_line": 4955, + "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": 4959, + "end_line": 4968, + "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": 4975, + "end_line": 5026, + "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": 5032, + "end_line": 5064, + "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": 5071, + "end_line": 5155, + "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": 5161, + "end_line": 5173, + "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": 5179, + "end_line": 5182, + "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": 5188, + "end_line": 5194, + "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": 5200, + "end_line": 5216, + "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": 5222, + "end_line": 5239, + "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": 5246, + "end_line": 5286, + "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": 5294, + "end_line": 5302, + "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": 5314, + "end_line": 5324, + "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": 5333, + "end_line": 5344, + "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": 5351, + "end_line": 5374, + "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": 5381, + "end_line": 5389, + "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": 5398, + "end_line": 5416, + "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": 5482, + "end_line": 5595, + "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": 5600, + "end_line": 5624, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 25, + "top_nesting_level": 0 + }, + { + "name": "initmultiarray", + "long_name": "initmultiarray()", + "filename": "multiarraymodule.c", + "nloc": 64, + "complexity": 15, + "token_count": 435, + "parameters": [], + "start_line": 5629, + "end_line": 5721, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 93, + "top_nesting_level": 0 + } + ], + "changed_methods": [ + { + "name": "_convert_from_list", + "long_name": "_convert_from_list( PyObject * obj , int align , int try_descr)", + "filename": "multiarraymodule.c", + "nloc": 70, + "complexity": 13, + "token_count": 428, + "parameters": [ + "obj", + "align", + "try_descr" + ], + "start_line": 3498, + "end_line": 3569, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 72, + "top_nesting_level": 0 + }, + { + "name": "_convert_from_dict", + "long_name": "_convert_from_dict( PyObject * obj , int align)", + "filename": "multiarraymodule.c", + "nloc": 102, + "complexity": 28, + "token_count": 689, + "parameters": [ + "obj", + "align" + ], + "start_line": 3643, + "end_line": 3754, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 112, + "top_nesting_level": 0 + }, + { + "name": "_convert_from_tuple", + "long_name": "_convert_from_tuple( PyObject * obj)", + "filename": "multiarraymodule.c", + "nloc": 62, + "complexity": 15, + "token_count": 381, + "parameters": [ + "obj" + ], + "start_line": 3334, + "end_line": 3408, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 75, + "top_nesting_level": 0 + } + ], + "nloc": 4337, + "complexity": 945, + "token_count": 28221, + "diff_parsed": { + "added": [ + "\t\tif (type->hasobject) newdescr->hasobject = 1;", + "\t\tif (ret == PY_FAIL) {", + "\t\t\tPy_DECREF(tup);", + "\t\t\tPy_DECREF(key);", + "\t\t\tgoto fail;", + "\t\t}", + "\t\tif (!hasobject && conv->hasobject)", + "\t\t\thasobject=1;", + " if (!hasobject && newdescr->hasobject)", + " hasobject = 1;" + ], + "deleted": [ + " if (!hasobject && conv->hasobject)", + " hasobject=1;", + "\t\tif (ret == PY_FAIL) goto fail;", + " if (!hasobject && newdescr->hasobject)", + " hasobject = 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": "@@ -1616,9 +1616,23 @@ static void\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\n\n\n/* A whole slew of basic math functions are provided originally \n by Konrad Hinsen. */\n\n#if !defined(__STDC__) && !defined(_MSC_VER)\nextern double fmod (double, double);\nextern double frexp (double, int *);\nextern double ldexp (double, int);\nextern double modf (double, double *);\n#endif\n#ifndef M_PI\n#define M_PI 3.14159265358979323846264338328\n#endif\n\n\n#ifndef HAVE_INVERSE_HYPERBOLIC\nstatic double acosh(double x)\n{\n\treturn 2*log(sqrt((x+1.0)/2)+sqrt((x-1.0)/2));\n}\n\ndouble log1p(double);\nstatic double asinh(double xx)\n{\n\tdouble x, d;\n\tint sign;\n\tif (xx < 0.0) {\n\t\tsign = -1;\n\t\tx = -xx;\n\t}\n\telse {\n\t\tsign = 1;\n\t\tx = xx;\n\t}\n\tif (x > 1e8) {\n\t\td = x;\n\t} else {\n\t\td = sqrt(x*x + 1);\n\t}\n\treturn sign*log1p(x*(1.0 + x/(d+1)));\n}\n\nstatic double atanh(double x)\n{\n\treturn 0.5*log1p(2.0*x/(1.0-x));\n}\n#endif\n\n#if !defined(HAVE_INVERSE_HYPERBOLIC_FLOAT)\n#ifdef HAVE_FLOAT_FUNCS\nfloat log1pf(float);\nfloat logf(float);\nfloat sqrtf(float);\nstatic float acoshf(float x)\n{\n\treturn 2*logf(sqrtf((x+1.0)/2)+sqrtf((x-1.0)/2));\n}\n\nstatic float asinhf(float xx)\n{\n\tfloat x, d;\n\tint sign;\n\tif (xx < 0.0) {\n\t\tsign = -1;\n\t\tx = -xx;\n\t}\n\telse {\n\t\tsign = 1;\n\t\tx = xx;\n\t}\n\tif (x > 1e5) {\n\t\td = x;\n\t} else {\n\t\td = sqrtf(x*x + 1);\n\t}\n\treturn sign*log1pf(x*(1.0 + x/(d+1)));\n}\n\nstatic float atanhf(float x)\n{\n\treturn 0.5*log1pf(2.0*x/(1.0-x));\n}\n#else\nstatic float acoshf(float x)\n{\n return (float)acosh((double)(x));\n}\n\nstatic float asinhf(float x)\n{\n return (float)asinh((double)(x));\n}\n\nstatic float atanhf(float x)\n{\n return (float)atanh((double)(x));\n}\n#endif\n#endif\n\n\n#if !defined(HAVE_INVERSE_HYPERBOLIC_LONGDOUBLE)\n#ifdef HAVE_LONGDOUBLE_FUNCS\nlongdouble logl(longdouble);\nlongdouble sqrtl(longdouble);\nlongdouble log1pl(longdouble);\nstatic longdouble acoshl(longdouble x)\n{\n\treturn 2*logl(sqrtl((x+1.0)/2)+sqrtl((x-1.0)/2));\n}\n\nstatic longdouble asinhl(longdouble xx)\n{\n\tlongdouble x, d;\n\tint sign;\n\tif (xx < 0.0) {\n\t\tsign = -1;\n\t\tx = -xx;\n\t}\n\telse {\n\t\tsign = 1;\n\t\tx = xx;\n\t}\n\tif (x > 1e17) {\n\t\td = x;\n\t} else {\n\t\td = sqrtl(x*x + 1);\n\t}\n\treturn sign*log1pl(x*(1.0 + x/(d+1)));\n}\n\nstatic longdouble atanhl(longdouble x)\n{\n\treturn 0.5*log1pl(2.0*x/(1.0-x));\n}\n#else\nstatic longdouble acoshl(longdouble x)\n{\n return (longdouble)acosh((double)(x));\n}\n\nstatic longdouble asinhl(longdouble x)\n{\n return (longdouble)asinh((double)(x));\n}\n\nstatic longdouble atanhl(longdouble x)\n{\n return (longdouble)atanh((double)(x));\n}\n#endif\n#endif\n\n\n#ifdef HAVE_HYPOT\n#if !defined(NeXT) && !defined(_MSC_VER)\nextern double hypot(double, double);\n#endif\n#else\ndouble hypot(double x, double y)\n{\n\tdouble yx;\n\n\tx = fabs(x);\n\ty = fabs(y);\n\tif (x < y) {\n\t\tdouble temp = x;\n\t\tx = y;\n\t\ty = temp;\n\t}\n\tif (x == 0.)\n\t\treturn 0.;\n\telse {\n\t\tyx = y/x;\n\t\treturn x*sqrt(1.+yx*yx);\n\t}\n}\n#endif\n\n\n\n/* Define isnan, isinf, isfinite, signbit if needed */\n/* Use fpclassify if possible */\n/* isnan, isinf --\n these will use macros and then fpclassify if available before\n defaulting to a dumb convert-to-double version...\n\n isfinite -- define a macro if not already available\n signbit -- if macro available use it, otherwise define a function\n and a dumb convert-to-double version for other types.\n*/\n\n#if defined(fpclassify)\n\n#if !defined(isnan)\n#define isnan(x) (fpclassify(x) == FP_NAN)\n#endif\n#if !defined(isinf)\n#define isinf(x) (fpclassify(x) == FP_INFINITE)\n#endif\n\n#else /* check to see if already have a function like this */\n\n#if !defined(HAVE_ISNAN)\n\n#if !defined(isnan)\n#include \"_isnan.c\"\n#endif\n#endif /* HAVE_ISNAN */\n\n#if !defined(HAVE_ISINF)\n#if !defined(isinf)\n#define isinf(x) (!isnan((x)) && isnan((x)-(x)))\n#endif\n#endif /* HAVE_ISINF */\n\n#endif /* defined(fpclassify) */\n\n\n/* Define signbit if needed */\n#if !defined(signbit)\n#include \"_signbit.c\"\n#endif\n\n\n/* Now defined the extended type macros */\n\n#if !defined(isnan)\n\n#if !defined(HAVE_LONGDOUBLE_FUNCS) || !defined(HAVE_ISNAN)\n#define isnanl(x) isnan((double)(x))\n#endif\n\n#if !defined(HAVE_FLOAT_FUNCS) || !defined(HAVE_ISNAN)\n#define isnanf(x) isnan((double)(x))\n#endif\n\n#else /* !defined(isnan) */\n\n#define isnanl(x) isnan((x))\n#define isnanf(x) isnan((x))\n\n#endif /* !defined(isnan) */\n\n\n#if !defined(isinf)\n\n#if !defined(HAVE_LONGDOUBLE_FUNCS) || !defined(HAVE_ISINF)\n#define isinfl(x) (!isnanl((x)) && isnanl((x)-(x)))\n#endif\n\n#if !defined(HAVE_FLOAT_FUNCS) || !defined(HAVE_ISINF)\n#define isinff(x) (!isnanf((x)) && isnanf((x)-(x)))\n#endif\n\n#else /* !defined(isinf) */\n\n#define isinfl(x) isinf((x))\n#define isinff(x) isinf((x))\n\n#endif /* !defined(isinf) */\n\n\n#if !defined(signbit)\n#define signbitl(x) ((longdouble) signbit((double)(x)))\n#define signbitf(x) ((float) signbit((double) (x)))\n#else\n#define signbitl(x) signbit((x))\n#define signbitf(x) signbit((x))\n#endif\n\n#if !defined(isfinite)\n#define isfinite(x) (!(isinf((x)) || isnan((x))))\n#endif\n#define isfinitef(x) (!(isinff((x)) || isnanf((x))))\n#define isfinitel(x) (!(isinfl((x)) || isnanl((x))))\n\n\n/* First, the C functions that do the real work */\n\n/* if C99 extensions not available then define dummy functions that use the\n double versions for\n\n sin, cos, tan\n sinh, cosh, tanh,\n fabs, floor, ceil, fmod, sqrt, log10, log, exp, fabs\n asin, acos, atan,\n asinh, acosh, atanh\n\n hypot, atan2, pow\n*/\n\n/**begin repeat\n\n#kind=(sin,cos,tan,sinh,cosh,tanh,fabs,floor,ceil,sqrt,log10,log,exp,asin,acos,atan)*2#\n#typ=longdouble*16, float*16#\n#c=l*16,f*16#\n#TYPE=LONGDOUBLE*16, FLOAT*16#\n*/\n#ifndef HAVE_@TYPE@_FUNCS\n@typ@ @kind@@c@(@typ@ x) {\n\treturn (@typ@) @kind@((double)x);\n}\n#endif\n/**end repeat**/\n\n/**begin repeat\n\n#kind=(atan2,hypot,pow,fmod)*2#\n#typ=longdouble*4, float*4#\n#c=l*4,f*4#\n#TYPE=LONGDOUBLE*4,FLOAT*4#\n*/\n#ifndef HAVE_@TYPE@_FUNCS\n@typ@ @kind@@c@(@typ@ x, @typ@ y) {\n\treturn (@typ@) @kind@((double)x, (double) y);\n}\n#endif\n/**end repeat**/\n\n/**begin repeat\n#kind=modf*2#\n#typ=longdouble, float#\n#c=l,f#\n#TYPE=LONGDOUBLE, FLOAT#\n*/\n#ifndef HAVE_@TYPE@_FUNCS\n@typ@ modf@c@(@typ@ x, @typ@ *iptr) {\n double nx, niptr, y;\n nx = (double) x;\n y = modf(nx, &niptr);\n *iptr = (@typ@) niptr;\n return (@typ@) y;\n}\n#endif\n/**end repeat**/\n\n\n\n#ifndef HAVE_LOG1P\ndouble log1p(double x)\n{\n\tdouble u = 1. + x;\n\tif (u == 1.0) {\n\t\treturn x;\n\t} else {\n\t\treturn log(u) * x / (u-1.);\n\t}\n}\n#endif\n\n#if !defined(HAVE_LOG1P) || !defined(HAVE_LONGDOUBLE_FUNCS)\nlongdouble log1pl(longdouble x)\n{\n\tlongdouble u = 1. + x;\n\tif (u == 1.0) {\n\t\treturn x;\n\t} else {\n\t\treturn logl(u) * x / (u-1.);\n\t}\n}\n#endif\n\n#if !defined(HAVE_LOG1P) || !defined(HAVE_FLOAT_FUNCS)\nfloat log1pf(float x)\n{\n\tfloat u = 1. + x;\n\tif (u == 1.0) {\n\t\treturn x;\n\t} else {\n\t\treturn logf(u) * x / (u-1.);\n\t}\n}\n#endif\n\n#ifndef HAVE_EXPM1\nstatic double expm1(double x)\n{\n\tdouble u = exp(x);\n\tif (u == 1.0) {\n\t\treturn x;\n\t} else if (u-1.0 == -1.0) {\n\t\treturn -1;\n\t} else {\n\t\treturn (u-1.0) * x/log(u);\n\t}\n}\n#endif\n\n#if !defined(HAVE_EXPM1) || !defined(HAVE_LONGDOUBLE_FUNCS)\nstatic longdouble expm1l(longdouble x)\n{\n\tlongdouble u = expl(x);\n\tif (u == 1.0) {\n\t\treturn x;\n\t} else if (u-1.0 == -1.0) {\n\t\treturn -1;\n\t} else {\n\t\treturn (u-1.0) * x/logl(u);\n\t}\n}\n#endif\n\n#if !defined(HAVE_EXPM1) || !defined(HAVE_FLOAT_FUNCS)\nstatic float expm1f(float x)\n{\n\tfloat u = expf(x);\n\tif (u == 1.0) {\n\t\treturn x;\n\t} else if (u-1.0 == -1.0) {\n\t\treturn -1;\n\t} else {\n\t\treturn (u-1.0) * x/logf(u);\n\t}\n}\n#endif\n\n\n\n\n/* Don't pass structures between functions (only pointers) because how\n structures are passed is compiler dependent and could cause\n segfaults if ufuncobject.c is compiled with a different compiler\n than an extension that makes use of the UFUNC API\n*/\n\n/**begin repeat\n\n#typ=float, double, longdouble#\n#c=f,,l#\n*/\n\n/* constants */\nstatic c@typ@ nc_1@c@ = {1., 0.};\nstatic c@typ@ nc_half@c@ = {0.5, 0.};\nstatic c@typ@ nc_i@c@ = {0., 1.};\nstatic c@typ@ nc_i2@c@ = {0., 0.5};\n/*\nstatic c@typ@ nc_mi@c@ = {0., -1.};\nstatic c@typ@ nc_pi2@c@ = {M_PI/2., 0.};\n*/\n\nstatic void\nnc_sum@c@(c@typ@ *a, c@typ@ *b, c@typ@ *r)\n{\n\tr->real = a->real + b->real;\n\tr->imag = a->imag + b->imag;\n\treturn;\n}\n\nstatic void\nnc_diff@c@(c@typ@ *a, c@typ@ *b, c@typ@ *r)\n{\n\tr->real = a->real - b->real;\n\tr->imag = a->imag - b->imag;\n\treturn;\n}\n\nstatic void\nnc_neg@c@(c@typ@ *a, c@typ@ *r)\n{\n\tr->real = -a->real;\n\tr->imag = -a->imag;\n\treturn;\n}\n\nstatic void\nnc_prod@c@(c@typ@ *a, c@typ@ *b, c@typ@ *r)\n{\n\t@typ@ ar=a->real, br=b->real, ai=a->imag, bi=b->imag;\n\tr->real = ar*br - ai*bi;\n\tr->imag = ar*bi + ai*br;\n\treturn;\n}\n\nstatic void\nnc_quot@c@(c@typ@ *a, c@typ@ *b, c@typ@ *r)\n{\n\n\t@typ@ ar=a->real, br=b->real, ai=a->imag, bi=b->imag;\n\t@typ@ d = br*br + bi*bi;\n\tr->real = (ar*br + ai*bi)/d;\n\tr->imag = (ai*br - ar*bi)/d;\n\treturn;\n}\n\nstatic void\nnc_floor_quot@c@(c@typ@ *a, c@typ@ *b, c@typ@ *r)\n{\n\t@typ@ ar=a->real, br=b->real, ai=a->imag, bi=b->imag;\n\t@typ@ d = br*br + bi*bi;\n\tr->real = floor@c@((ar*br + ai*bi)/d);\n\tr->imag = 0;\n\treturn;\n}\n\nstatic void\nnc_sqrt@c@(c@typ@ *x, c@typ@ *r)\n{\n\t@typ@ s,d;\n\tif (x->real == 0. && x->imag == 0.)\n\t\t*r = *x;\n\telse {\n\t\ts = sqrt@c@(0.5*(fabs@c@(x->real) + hypot@c@(x->real,x->imag)));\n\t\td = 0.5*x->imag/s;\n\t\tif (x->real > 0.) {\n\t\t\tr->real = s;\n\t\t\tr->imag = d;\n\t\t}\n\t\telse if (x->imag >= 0.) {\n\t\t\tr->real = d;\n\t\t\tr->imag = s;\n\t\t}\n\t\telse {\n\t\t\tr->real = -d;\n\t\t\tr->imag = -s;\n\t\t}\n\t}\n\treturn;\n}\n\nstatic void\nnc_log@c@(c@typ@ *x, c@typ@ *r)\n{\n\t@typ@ l = hypot@c@(x->real,x->imag);\n\tr->imag = atan2@c@(x->imag, x->real);\n\tr->real = log@c@(l);\n\treturn;\n}\n\nstatic void\nnc_log1p@c@(c@typ@ *x, c@typ@ *r)\n{\n\t@typ@ l = hypot@c@(x->real + 1.0,x->imag);\n\tr->imag = atan2@c@(x->imag, x->real + 1.0);\n\tr->real = log@c@(l);\n\treturn;\n}\n\nstatic void\nnc_exp@c@(c@typ@ *x, c@typ@ *r)\n{\n\t@typ@ a = exp@c@(x->real);\n\tr->real = a*cos@c@(x->imag);\n\tr->imag = a*sin@c@(x->imag);\n\treturn;\n}\n\nstatic void\nnc_expm1@c@(c@typ@ *x, c@typ@ *r)\n{\n\t@typ@ a = exp@c@(x->real);\n\tr->real = a*cos@c@(x->imag) - 1.0;\n\tr->imag = a*sin@c@(x->imag);\n\treturn;\n}\n\nstatic void\nnc_pow@c@(c@typ@ *a, c@typ@ *b, c@typ@ *r)\n{\n\t@typ@ ar=a->real, br=b->real, ai=a->imag, bi=b->imag;\n\n\tif (br == 0. && bi == 0.) {\n\t\tr->real = 1.;\n\t\tr->imag = 0.;\n\t}\n\telse if (ar == 0. && ai == 0.) {\n\t\tr->real = 0.;\n\t\tr->imag = 0.;\n\t}\n\telse {\n\t\tnc_log@c@(a, r);\n\t\tnc_prod@c@(r, b, r);\n\t\tnc_exp@c@(r, r);\n\t}\n\treturn;\n}\n\n\nstatic void\nnc_prodi@c@(c@typ@ *x, c@typ@ *r)\n{\n\tr->real = -x->imag;\n\tr->imag = x->real;\n\treturn;\n}\n\n\nstatic void\nnc_acos@c@(c@typ@ *x, c@typ@ *r)\n{\n\tnc_prod@c@(x,x,r);\n\tnc_diff@c@(&nc_1@c@, r, r);\n\tnc_sqrt@c@(r, r);\n\tnc_prodi@c@(r, r);\n\tnc_sum@c@(x, r, r);\n\tnc_log@c@(r, r);\n\tnc_prodi@c@(r, r);\n\tnc_neg@c@(r, r);\n\treturn;\n\t/* return nc_neg(nc_prodi(nc_log(nc_sum(x,nc_prod(nc_i,\n\t nc_sqrt(nc_diff(nc_1,nc_prod(x,x))))))));\n\t*/\n}\n\nstatic void\nnc_acosh@c@(c@typ@ *x, c@typ@ *r)\n{\n\tnc_prod@c@(x, x, r);\n\tnc_diff@c@(&nc_1@c@, r, r);\n\tnc_sqrt@c@(r, r);\n\tnc_prodi@c@(r, r);\n\tnc_sum@c@(x, r, r);\n\tnc_log@c@(r, r);\n\treturn;\n\t/*\n\t return nc_log(nc_sum(x,nc_prod(nc_i,\n\t nc_sqrt(nc_diff(nc_1,nc_prod(x,x))))));\n\t*/\n}\n\nstatic void\nnc_asin@c@(c@typ@ *x, c@typ@ *r)\n{\n\tc@typ@ a, *pa=&a;\n\tnc_prod@c@(x, x, r);\n\tnc_diff@c@(&nc_1@c@, r, r);\n\tnc_sqrt@c@(r, r);\n\tnc_prodi@c@(x, pa);\n\tnc_sum@c@(pa, r, r);\n\tnc_log@c@(r, r);\n\tnc_prodi@c@(r, r);\n\tnc_neg@c@(r, r);\n\treturn;\n\t/*\n\t return nc_neg(nc_prodi(nc_log(nc_sum(nc_prod(nc_i,x),\n\t nc_sqrt(nc_diff(nc_1,nc_prod(x,x)))))));\n\t*/\n}\n\n\nstatic void\nnc_asinh@c@(c@typ@ *x, c@typ@ *r)\n{\n\tnc_prod@c@(x, x, r);\n\tnc_sum@c@(&nc_1@c@, r, r);\n\tnc_sqrt@c@(r, r);\n\tnc_diff@c@(r, x, r);\n\tnc_log@c@(r, r);\n\tnc_neg@c@(r, r);\n\treturn;\n\t/*\n\t return nc_neg(nc_log(nc_diff(nc_sqrt(nc_sum(nc_1,nc_prod(x,x))),x)));\n\t*/\n}\n\nstatic void\nnc_atan@c@(c@typ@ *x, c@typ@ *r)\n{\n\tc@typ@ a, *pa=&a;\n\tnc_diff@c@(&nc_i@c@, x, pa);\n\tnc_sum@c@(&nc_i@c@, x, r);\n\tnc_quot@c@(r, pa, r);\n\tnc_log@c@(r,r);\n\tnc_prod@c@(&nc_i2@c@, r, r);\n\treturn;\n\t/*\n\t return nc_prod(nc_i2,nc_log(nc_quot(nc_sum(nc_i,x),nc_diff(nc_i,x))));\n\t*/\n}\n\nstatic void\nnc_atanh@c@(c@typ@ *x, c@typ@ *r)\n{\n\tc@typ@ a, *pa=&a;\n\tnc_diff@c@(&nc_1@c@, x, r);\n\tnc_sum@c@(&nc_1@c@, x, pa);\n\tnc_quot@c@(pa, r, r);\n\tnc_log@c@(r, r);\n\tnc_prod@c@(&nc_half@c@, r, r);\n\treturn;\n\t/*\n\t return nc_prod(nc_half,nc_log(nc_quot(nc_sum(nc_1,x),nc_diff(nc_1,x))));\n\t*/\n}\n\nstatic void\nnc_cos@c@(c@typ@ *x, c@typ@ *r)\n{\n\t@typ@ xr=x->real, xi=x->imag;\n\tr->real = cos@c@(xr)*cosh@c@(xi);\n\tr->imag = -sin@c@(xr)*sinh@c@(xi);\n\treturn;\n}\n\nstatic void\nnc_cosh@c@(c@typ@ *x, c@typ@ *r)\n{\n\t@typ@ xr=x->real, xi=x->imag;\n\tr->real = cos(xi)*cosh(xr);\n\tr->imag = sin(xi)*sinh(xr);\n\treturn;\n}\n\n\n#define M_LOG10_E 0.434294481903251827651128918916605082294397\n\nstatic void\nnc_log10@c@(c@typ@ *x, c@typ@ *r)\n{\n\tnc_log@c@(x, r);\n\tr->real *= M_LOG10_E;\n\tr->imag *= M_LOG10_E;\n\treturn;\n}\n\nstatic void\nnc_sin@c@(c@typ@ *x, c@typ@ *r)\n{\n\t@typ@ xr=x->real, xi=x->imag;\n\tr->real = sin@c@(xr)*cosh@c@(xi);\n\tr->imag = cos@c@(xr)*sinh@c@(xi);\n\treturn;\n}\n\nstatic void\nnc_sinh@c@(c@typ@ *x, c@typ@ *r)\n{\n\t@typ@ xr=x->real, xi=x->imag;\n\tr->real = cos@c@(xi)*sinh@c@(xr);\n\tr->imag = sin@c@(xi)*cosh@c@(xr);\n\treturn;\n}\n\nstatic void\nnc_tan@c@(c@typ@ *x, c@typ@ *r)\n{\n\t@typ@ sr,cr,shi,chi;\n\t@typ@ rs,is,rc,ic;\n\t@typ@ d;\n\t@typ@ xr=x->real, xi=x->imag;\n\tsr = sin@c@(xr);\n\tcr = cos@c@(xr);\n\tshi = sinh(xi);\n\tchi = cosh(xi);\n\trs = sr*chi;\n\tis = cr*shi;\n\trc = cr*chi;\n\tic = -sr*shi;\n\td = rc*rc + ic*ic;\n\tr->real = (rs*rc+is*ic)/d;\n\tr->imag = (is*rc-rs*ic)/d;\n\treturn;\n}\n\nstatic void\nnc_tanh@c@(c@typ@ *x, c@typ@ *r)\n{\n\t@typ@ si,ci,shr,chr;\n\t@typ@ rs,is,rc,ic;\n\t@typ@ d;\n\t@typ@ xr=x->real, xi=x->imag;\n\tsi = sin@c@(xi);\n\tci = cos@c@(xi);\n\tshr = sinh@c@(xr);\n\tchr = cosh@c@(xr);\n\trs = ci*shr;\n\tis = si*chr;\n\trc = ci*chr;\n\tic = si*shr;\n\td = rc*rc + ic*ic;\n\tr->real = (rs*rc+is*ic)/d;\n\tr->imag = (is*rc-rs*ic)/d;\n\treturn;\n}\n\n/**end repeat**/\n\n\n/**begin repeat\n\n#TYPE=(BOOL, BYTE,UBYTE,SHORT,USHORT,INT,UINT,LONG,ULONG,LONGLONG,ULONGLONG,FLOAT,DOUBLE,LONGDOUBLE)*2#\n#OP=||, +*13, ^, -*13#\n#kind=add*14, subtract*14#\n#typ=(Bool, byte, ubyte, short, ushort, int, uint, long, ulong, longlong, ulonglong, float, double, longdouble)*2#\n*/\n\nstatic void\n@TYPE@_@kind@(char **args, intp *dimensions, intp *steps, void *func)\n{\n\tregister intp i;\n\tintp is1=steps[0],is2=steps[1],os=steps[2], n=dimensions[0];\n\tchar *i1=args[0], *i2=args[1], *op=args[2];\n\tfor(i=0; i> 32);\n\tal = (a & 0xFFFFFFFFL);\n\tbh = (b >> 32);\n\tbl = (b & 0xFFFFFFFFL);\n#elif SIZEOF_LONGLONG == 128\n\tah = (a >> 64);\n\tal = (a & 0xFFFFFFFFFFFFFFFFL);\n\tbh = (b >> 64);\n\tbl = (b & 0xFFFFFFFFFFFFFFFFL);\n#else\n\tah = al = bh = bl = 0;\n#endif\n\n /* 128-bit product: z*2**64 + (x+y)*2**32 + w */\n\tw = al*bl;\n\tx = bh*al;\n\ty = ah*bl;\n\tz = ah*bh;\n\n\t/* *c = ((x + y)<<32) + w; */\n#if SIZEOF_LONGLONG == 64\n\treturn z || (x>>32) || (y>>32) ||\n\t\t(((x & 0xFFFFFFFFL) + (y & 0xFFFFFFFFL) + (w >> 32)) >> 32);\n#elif SIZEOF_LONGLONG == 128\n\treturn z || (x>>64) || (y>>64) ||\n\t\t(((x & 0xFFFFFFFFFFFFFFFFL) + (y & 0xFFFFFFFFFFFFFFFFL) + (w >> 64)) >> 64);\n#else\n\treturn 0;\n#endif\n\n}\n\nstatic int slonglong_overflow(longlong a0, longlong b0)\n{\n\tulonglong a, b;\n ulonglong ah, al, bh, bl, w, x, y, z;\n\n /* Convert to non-negative quantities */\n\tif (a0 < 0) { a = -a0; } else { a = a0; }\n\tif (b0 < 0) { b = -b0; } else { b = b0; }\n\n\n#if SIZEOF_LONGLONG == 64\n\tah = (a >> 32);\n\tal = (a & 0xFFFFFFFFL);\n\tbh = (b >> 32);\n\tbl = (b & 0xFFFFFFFFL);\n#elif SIZEOF_LONGLONG == 128\n\tah = (a >> 64);\n\tal = (a & 0xFFFFFFFFFFFFFFFFL);\n\tbh = (b >> 64);\n\tbl = (b & 0xFFFFFFFFFFFFFFFFL);\n#else\n\tah = al = bh = bl = 0;\n#endif\n\n\tw = al*bl;\n\tx = bh*al;\n\ty = ah*bl;\n\tz = ah*bh;\n\n /*\n\t ulonglong c = ((x + y)<<32) + w;\n\t if ((a0 < 0) ^ (b0 < 0))\n\t *c = -c;\n\t else\n\t *c = c\n\t */\n\n#if SIZEOF_LONGLONG == 64\n\treturn z || (x>>31) || (y>>31) ||\n\t\t(((x & 0xFFFFFFFFL) + (y & 0xFFFFFFFFL) + (w >> 32)) >> 31);\n#elif SIZEOF_LONGLONG == 128\n\treturn z || (x>>63) || (y>>63) ||\n\t\t(((x & 0xFFFFFFFFFFFFFFFFL) + (y & 0xFFFFFFFFFFFFFFFFL) + (w >> 64)) >> 63);\n#else\n\treturn 0;\n#endif\n}\n\n/** end direct numarray code **/\n\nstatic void\nBOOL_multiply(char **args, intp *dimensions, intp *steps, void *func) {\n\tregister intp i;\n\tintp is1=steps[0], is2=steps[1], os=steps[2], n=dimensions[0];\n\tchar *i1=args[0], *i2=args[1], *op=args[2];\n\tfor (i=0; i MAX_@TYP@)\n\t\t\tgenerate_overflow_error();\n\t\t*((@typ@ *)op) = temp;\n\t}\n}\n\n/**end repeat**/\n\nstatic void\nULONGLONG_multiply(char **args, intp *dimensions, intp *steps, void *func)\n{\n\tregister intp i;\n\tintp is1=steps[0], is2=steps[1], os=steps[2], n=dimensions[0];\n\tchar *i1=args[0], *i2=args[1], *op=args[2];\n\tulonglong temp;\n\tfor (i=0; i MAX_@TYP@)\n\t\t\tgenerate_overflow_error();\n\t\telse if (temp < MIN_@TYP@)\n\t\t\tgenerate_overflow_error();\n\t\t*((@typ@ *)op) = temp;\n\t}\n}\n\n/**end repeat**/\n\nstatic void\nLONGLONG_multiply(char **args, intp *dimensions, intp *steps, void *func)\n{\n\tregister intp i;\n\tintp is1=steps[0], is2=steps[1], os=steps[2], n=dimensions[0];\n\tchar *i1=args[0], *i2=args[1], *op=args[2];\n\tlonglong temp;\n\tfor (i=0; i, >=, <, <=, ==, !=, &&, ||, &, |, ^#\n**/\nstatic void\nBOOL_@kind@(char **args, intp *dimensions, intp *steps, void *func)\n{\n\tregister intp i;\n\tintp is1=steps[0],is2=steps[1],os=steps[2], n=dimensions[0];\n\tchar *i1=args[0], *i2=args[1], *op=args[2];\n\tBool in1, in2;\n\tfor(i=0; i*13, >=*13, <*13, <=*13#\n#typ=(byte, ubyte, short, ushort, int, uint, long, ulong, longlong, ulonglong, float, double, longdouble)*4#\n#kind= greater*13, greater_equal*13, less*13, less_equal*13#\n*/\n\nstatic void\n@TYPE@_@kind@(char **args, intp *dimensions, intp *steps, void *func)\n{\n\tregister intp i;\n\tintp is1=steps[0],is2=steps[1],os=steps[2], n=dimensions[0];\n\tchar *i1=args[0], *i2=args[1], *op=args[2];\n\tfor(i=0; i*3, >=*3, <*3, <=*3#\n#typ=(cfloat, cdouble, clongdouble)*4#\n#kind= greater*3, greater_equal*3, less*3, less_equal*3#\n*/\n\nstatic void\n@TYPE@_@kind@(char **args, intp *dimensions, intp *steps, void *func)\n{\n\tregister intp i;\n\tintp is1=steps[0],is2=steps[1],os=steps[2], n=dimensions[0];\n\tchar *i1=args[0], *i2=args[1], *op=args[2];\n\tfor(i=0; ireal == ((@typ@ *)i2)->real)\n\t\t\t*((Bool *)op)=((@typ@ *)i1)->imag @OP@ \\\n\t\t\t\t((@typ@ *)i2)->imag;\n\t\telse\n\t\t\t*((Bool *)op)=((@typ@ *)i1)->real @OP@ \\\n\t\t\t\t((@typ@ *)i2)->real;\n\t}\n}\n/**end repeat**/\n\n\n/**begin repeat\n#TYPE=(BYTE,UBYTE,SHORT,USHORT,INT,UINT,LONG,ULONG,LONGLONG,ULONGLONG,FLOAT,DOUBLE,LONGDOUBLE)*4#\n#typ=(byte, ubyte, short, ushort, int, uint, long, ulong, longlong, ulonglong, float, double, longdouble)*4#\n#OP= ==*13, !=*13, &&*13, ||*13#\n#kind=equal*13, not_equal*13, logical_and*13, logical_or*13#\n*/\nstatic void\n@TYPE@_@kind@(char **args, intp *dimensions, intp *steps, void *func)\n{\n\tregister intp i;\n\tintp is1=steps[0],is2=steps[1],os=steps[2], n=dimensions[0];\n\tchar *i1=args[0], *i2=args[1], *op=args[2];\n\tfor(i=0; i 0 ? 1 : ((x) < 0 ? -1 : 0))\n#define _SIGN2(x) ((x) == 0 ? 0 : 1)\n#define _SIGNC(x) (((x).real > 0) ? 1 : ((x).real < 0 ? -1 : ((x).imag > 0 ? 1 : ((x).imag < 0) ? -1 : 0)))\n/**begin repeat\n#TYPE=BYTE,SHORT,INT,LONG,LONGLONG,FLOAT,DOUBLE,LONGDOUBLE,UBYTE,USHORT,UINT,ULONG,ULONGLONG#\n#typ=byte,short,int,long,longlong,float,double,longdouble,ubyte,ushort,uint,ulong,ulonglong#\n#func=_SIGN1*8,_SIGN2*5#\n */\nstatic void\n@TYPE@_sign(char **args, intp *dimensions, intp *steps, void *func)\n{\n\tregister intp i;\n\tintp is1=steps[0],os=steps[1], n=dimensions[0];\n\tchar *i1=args[0], *op=args[1];\n @typ@ t1;\n\tfor(i=0; ireal ||\t\\\n\t\t\t\t ((@typ@ *)i1)->imag);\n\t}\n}\n/**end repeat**/\n\n\n\n\n/**begin repeat\n#TYPE=BYTE,SHORT,INT,LONG,LONGLONG#\n#typ=byte, short, int, long, longlong#\n#ftyp=float*2,double*2,longdouble*1#\n#c=f*2,,,l*1#\n*/\nstatic void\n@TYPE@_remainder(char **args, intp *dimensions, intp *steps, void *func)\n{\n\tregister intp i;\n\tintp is1=steps[0],is2=steps[1],os=steps[2], n=dimensions[0];\n\tchar *i1=args[0], *i2=args[1], *op=args[2];\n\tregister @typ@ ix,iy, tmp;\n\tfor(i=0; i 0) == (iy > 0)) {\n\t\t\t*((@typ@ *)op) = ix % iy;\n\t\t}\n\t\telse { /* handle mixed case the way Python does */\n\t\t\ttmp = ix % iy;\n\t\t\tif (tmp) tmp += iy;\n\t\t\t*((@typ@ *)op)= tmp;\n\t\t}\n\t}\n}\n/**end repeat**/\n\n/**begin repeat\n#TYPE=UBYTE,USHORT,UINT,ULONG,ULONGLONG#\n#typ=ubyte, ushort, uint, ulong, ulonglong#\n*/\nstatic void\n@TYPE@_remainder(char **args, intp *dimensions, intp *steps, void *func)\n{\n\tregister intp i;\n\tintp is1=steps[0],is2=steps[1],os=steps[2], n=dimensions[0];\n\tchar *i1=args[0], *i2=args[1], *op=args[2];\n\tregister @typ@ ix,iy;\n\tfor(i=0; i>*10#\n#kind=bitwise_and*10, bitwise_or*10, bitwise_xor*10, left_shift*10, right_shift*10#\n\n*/\nstatic void\n@TYPE@_@kind@(char **args, intp *dimensions, intp *steps, void *func)\n{\n\tregister intp i;\n\tintp is1=steps[0],is2=steps[1],os=steps[2], n=dimensions[0];\n\tregister char *i1=args[0], *i2=args[1], *op=args[2];\n\tif (is1 == 0) {\n\t\tregister @typ@ t1 = *((@typ@ *)i1);\n\t\tfor (i=0; ireal || ((@typ@ *)i1)->imag;\n\t\tp2 = ((@typ@ *)i2)->real || ((@typ@ *)i2)->imag;\n\t\t*((Bool *)op)= (p1 || p2) && !(p1 && p2);\n\t}\n}\n/**end repeat**/\n\n\n\n/**begin repeat\n\n#TYPE=(BOOL,BYTE,UBYTE,SHORT,USHORT,INT,UINT,LONG,ULONG,LONGLONG,ULONGLONG,FLOAT,DOUBLE,LONGDOUBLE)*2#\n#OP= >*14, <*14#\n#typ=(Bool, byte, ubyte, short, ushort, int, uint, long, ulong, longlong, ulonglong, float, double, longdouble)*2#\n#kind= maximum*14, minimum*14#\n*/\nstatic void\n@TYPE@_@kind@(char **args, intp *dimensions, intp *steps, void *func)\n{\n\tregister intp i;\n\tintp is1=steps[0],is2=steps[1],os=steps[2], n=dimensions[0];\n\tchar *i1=args[0], *i2=args[1], *op=args[2];\n\tfor(i=0; i*3, <*3#\n#typ=(cfloat, cdouble, clongdouble)*2#\n#kind= maximum*3, minimum*3#\n*/\nstatic void\n@TYPE@_@kind@(char **args, intp *dimensions, intp *steps, void *func)\n{\n\tregister intp i;\n\tintp is1=steps[0],is2=steps[1],os=steps[2], n=dimensions[0];\n\tchar *i1=args[0], *i2=args[1], *op=args[2];\n @typ@ *i1c, *i2c;\n\tfor(i=0; ireal @OP@ i2c->real) || \\\n ((i1c->real==i2c->real) && (i1c->imag @OP@ i2c->imag)))\n memcpy(op, i1, sizeof(@typ@));\n else\n memcpy(op, i2, sizeof(@typ@));\n\t}\n}\n/**end repeat**/\n\n\n\n/*** isinf, isinf, isfinite, signbit ***/\n/**begin repeat\n#kind=isnan*3, isinf*3, isfinite*3, signbit*3#\n#TYPE=(FLOAT, DOUBLE, LONGDOUBLE)*4#\n#typ=(float, double, longdouble)*4#\n#c=(f,,l)*4#\n*/\nstatic void\n@TYPE@_@kind@(char **args, intp *dimensions, intp *steps, void *func)\n{\n register intp i;\n intp is=steps[0], os=steps[1], n=dimensions[0];\n char *ip=args[0], *op=args[1];\n for(i=0; i\n\n\n/* A whole slew of basic math functions are provided originally \n by Konrad Hinsen. */\n\n#if !defined(__STDC__) && !defined(_MSC_VER)\nextern double fmod (double, double);\nextern double frexp (double, int *);\nextern double ldexp (double, int);\nextern double modf (double, double *);\n#endif\n#ifndef M_PI\n#define M_PI 3.14159265358979323846264338328\n#endif\n\n\n#ifndef HAVE_INVERSE_HYPERBOLIC\nstatic double acosh(double x)\n{\n\treturn 2*log(sqrt((x+1.0)/2)+sqrt((x-1.0)/2));\n}\n\ndouble log1p(double);\nstatic double asinh(double xx)\n{\n\tdouble x, d;\n\tint sign;\n\tif (xx < 0.0) {\n\t\tsign = -1;\n\t\tx = -xx;\n\t}\n\telse {\n\t\tsign = 1;\n\t\tx = xx;\n\t}\n\tif (x > 1e8) {\n\t\td = x;\n\t} else {\n\t\td = sqrt(x*x + 1);\n\t}\n\treturn sign*log1p(x*(1.0 + x/(d+1)));\n}\n\nstatic double atanh(double x)\n{\n\treturn 0.5*log1p(2.0*x/(1.0-x));\n}\n#endif\n\n#if !defined(HAVE_INVERSE_HYPERBOLIC_FLOAT)\n#ifdef HAVE_FLOAT_FUNCS\nfloat log1pf(float);\nfloat logf(float);\nfloat sqrtf(float);\nstatic float acoshf(float x)\n{\n\treturn 2*logf(sqrtf((x+1.0)/2)+sqrtf((x-1.0)/2));\n}\n\nstatic float asinhf(float xx)\n{\n\tfloat x, d;\n\tint sign;\n\tif (xx < 0.0) {\n\t\tsign = -1;\n\t\tx = -xx;\n\t}\n\telse {\n\t\tsign = 1;\n\t\tx = xx;\n\t}\n\tif (x > 1e5) {\n\t\td = x;\n\t} else {\n\t\td = sqrtf(x*x + 1);\n\t}\n\treturn sign*log1pf(x*(1.0 + x/(d+1)));\n}\n\nstatic float atanhf(float x)\n{\n\treturn 0.5*log1pf(2.0*x/(1.0-x));\n}\n#else\nstatic float acoshf(float x)\n{\n return (float)acosh((double)(x));\n}\n\nstatic float asinhf(float x)\n{\n return (float)asinh((double)(x));\n}\n\nstatic float atanhf(float x)\n{\n return (float)atanh((double)(x));\n}\n#endif\n#endif\n\n\n#if !defined(HAVE_INVERSE_HYPERBOLIC_LONGDOUBLE)\n#ifdef HAVE_LONGDOUBLE_FUNCS\nlongdouble logl(longdouble);\nlongdouble sqrtl(longdouble);\nlongdouble log1pl(longdouble);\nstatic longdouble acoshl(longdouble x)\n{\n\treturn 2*logl(sqrtl((x+1.0)/2)+sqrtl((x-1.0)/2));\n}\n\nstatic longdouble asinhl(longdouble xx)\n{\n\tlongdouble x, d;\n\tint sign;\n\tif (xx < 0.0) {\n\t\tsign = -1;\n\t\tx = -xx;\n\t}\n\telse {\n\t\tsign = 1;\n\t\tx = xx;\n\t}\n\tif (x > 1e17) {\n\t\td = x;\n\t} else {\n\t\td = sqrtl(x*x + 1);\n\t}\n\treturn sign*log1pl(x*(1.0 + x/(d+1)));\n}\n\nstatic longdouble atanhl(longdouble x)\n{\n\treturn 0.5*log1pl(2.0*x/(1.0-x));\n}\n#else\nstatic longdouble acoshl(longdouble x)\n{\n return (longdouble)acosh((double)(x));\n}\n\nstatic longdouble asinhl(longdouble x)\n{\n return (longdouble)asinh((double)(x));\n}\n\nstatic longdouble atanhl(longdouble x)\n{\n return (longdouble)atanh((double)(x));\n}\n#endif\n#endif\n\n\n#ifdef HAVE_HYPOT\n#if !defined(NeXT) && !defined(_MSC_VER)\nextern double hypot(double, double);\n#endif\n#else\ndouble hypot(double x, double y)\n{\n\tdouble yx;\n\n\tx = fabs(x);\n\ty = fabs(y);\n\tif (x < y) {\n\t\tdouble temp = x;\n\t\tx = y;\n\t\ty = temp;\n\t}\n\tif (x == 0.)\n\t\treturn 0.;\n\telse {\n\t\tyx = y/x;\n\t\treturn x*sqrt(1.+yx*yx);\n\t}\n}\n#endif\n\n\n\n/* Define isnan, isinf, isfinite, signbit if needed */\n/* Use fpclassify if possible */\n/* isnan, isinf --\n these will use macros and then fpclassify if available before\n defaulting to a dumb convert-to-double version...\n\n isfinite -- define a macro if not already available\n signbit -- if macro available use it, otherwise define a function\n and a dumb convert-to-double version for other types.\n*/\n\n#if defined(fpclassify)\n\n#if !defined(isnan)\n#define isnan(x) (fpclassify(x) == FP_NAN)\n#endif\n#if !defined(isinf)\n#define isinf(x) (fpclassify(x) == FP_INFINITE)\n#endif\n\n#else /* check to see if already have a function like this */\n\n#if !defined(HAVE_ISNAN)\n\n#if !defined(isnan)\n#include \"_isnan.c\"\n#endif\n#endif /* HAVE_ISNAN */\n\n#if !defined(HAVE_ISINF)\n#if !defined(isinf)\n#define isinf(x) (!isnan((x)) && isnan((x)-(x)))\n#endif\n#endif /* HAVE_ISINF */\n\n#endif /* defined(fpclassify) */\n\n\n/* Define signbit if needed */\n#if !defined(signbit)\n#include \"_signbit.c\"\n#endif\n\n\n/* Now defined the extended type macros */\n\n#if !defined(isnan)\n\n#if !defined(HAVE_LONGDOUBLE_FUNCS) || !defined(HAVE_ISNAN)\n#define isnanl(x) isnan((double)(x))\n#endif\n\n#if !defined(HAVE_FLOAT_FUNCS) || !defined(HAVE_ISNAN)\n#define isnanf(x) isnan((double)(x))\n#endif\n\n#else /* !defined(isnan) */\n\n#define isnanl(x) isnan((x))\n#define isnanf(x) isnan((x))\n\n#endif /* !defined(isnan) */\n\n\n#if !defined(isinf)\n\n#if !defined(HAVE_LONGDOUBLE_FUNCS) || !defined(HAVE_ISINF)\n#define isinfl(x) (!isnanl((x)) && isnanl((x)-(x)))\n#endif\n\n#if !defined(HAVE_FLOAT_FUNCS) || !defined(HAVE_ISINF)\n#define isinff(x) (!isnanf((x)) && isnanf((x)-(x)))\n#endif\n\n#else /* !defined(isinf) */\n\n#define isinfl(x) isinf((x))\n#define isinff(x) isinf((x))\n\n#endif /* !defined(isinf) */\n\n\n#if !defined(signbit)\n#define signbitl(x) ((longdouble) signbit((double)(x)))\n#define signbitf(x) ((float) signbit((double) (x)))\n#else\n#define signbitl(x) signbit((x))\n#define signbitf(x) signbit((x))\n#endif\n\n#if !defined(isfinite)\n#define isfinite(x) (!(isinf((x)) || isnan((x))))\n#endif\n#define isfinitef(x) (!(isinff((x)) || isnanf((x))))\n#define isfinitel(x) (!(isinfl((x)) || isnanl((x))))\n\n\n/* First, the C functions that do the real work */\n\n/* if C99 extensions not available then define dummy functions that use the\n double versions for\n\n sin, cos, tan\n sinh, cosh, tanh,\n fabs, floor, ceil, fmod, sqrt, log10, log, exp, fabs\n asin, acos, atan,\n asinh, acosh, atanh\n\n hypot, atan2, pow\n*/\n\n/**begin repeat\n\n#kind=(sin,cos,tan,sinh,cosh,tanh,fabs,floor,ceil,sqrt,log10,log,exp,asin,acos,atan)*2#\n#typ=longdouble*16, float*16#\n#c=l*16,f*16#\n#TYPE=LONGDOUBLE*16, FLOAT*16#\n*/\n#ifndef HAVE_@TYPE@_FUNCS\n@typ@ @kind@@c@(@typ@ x) {\n\treturn (@typ@) @kind@((double)x);\n}\n#endif\n/**end repeat**/\n\n/**begin repeat\n\n#kind=(atan2,hypot,pow,fmod)*2#\n#typ=longdouble*4, float*4#\n#c=l*4,f*4#\n#TYPE=LONGDOUBLE*4,FLOAT*4#\n*/\n#ifndef HAVE_@TYPE@_FUNCS\n@typ@ @kind@@c@(@typ@ x, @typ@ y) {\n\treturn (@typ@) @kind@((double)x, (double) y);\n}\n#endif\n/**end repeat**/\n\n/**begin repeat\n#kind=modf*2#\n#typ=longdouble, float#\n#c=l,f#\n#TYPE=LONGDOUBLE, FLOAT#\n*/\n#ifndef HAVE_@TYPE@_FUNCS\n@typ@ modf@c@(@typ@ x, @typ@ *iptr) {\n double nx, niptr, y;\n nx = (double) x;\n y = modf(nx, &niptr);\n *iptr = (@typ@) niptr;\n return (@typ@) y;\n}\n#endif\n/**end repeat**/\n\n\n\n#ifndef HAVE_LOG1P\ndouble log1p(double x)\n{\n\tdouble u = 1. + x;\n\tif (u == 1.0) {\n\t\treturn x;\n\t} else {\n\t\treturn log(u) * x / (u-1.);\n\t}\n}\n#endif\n\n#if !defined(HAVE_LOG1P) || !defined(HAVE_LONGDOUBLE_FUNCS)\nlongdouble log1pl(longdouble x)\n{\n\tlongdouble u = 1. + x;\n\tif (u == 1.0) {\n\t\treturn x;\n\t} else {\n\t\treturn logl(u) * x / (u-1.);\n\t}\n}\n#endif\n\n#if !defined(HAVE_LOG1P) || !defined(HAVE_FLOAT_FUNCS)\nfloat log1pf(float x)\n{\n\tfloat u = 1. + x;\n\tif (u == 1.0) {\n\t\treturn x;\n\t} else {\n\t\treturn logf(u) * x / (u-1.);\n\t}\n}\n#endif\n\n#ifndef HAVE_EXPM1\nstatic double expm1(double x)\n{\n\tdouble u = exp(x);\n\tif (u == 1.0) {\n\t\treturn x;\n\t} else if (u-1.0 == -1.0) {\n\t\treturn -1;\n\t} else {\n\t\treturn (u-1.0) * x/log(u);\n\t}\n}\n#endif\n\n#if !defined(HAVE_EXPM1) || !defined(HAVE_LONGDOUBLE_FUNCS)\nstatic longdouble expm1l(longdouble x)\n{\n\tlongdouble u = expl(x);\n\tif (u == 1.0) {\n\t\treturn x;\n\t} else if (u-1.0 == -1.0) {\n\t\treturn -1;\n\t} else {\n\t\treturn (u-1.0) * x/logl(u);\n\t}\n}\n#endif\n\n#if !defined(HAVE_EXPM1) || !defined(HAVE_FLOAT_FUNCS)\nstatic float expm1f(float x)\n{\n\tfloat u = expf(x);\n\tif (u == 1.0) {\n\t\treturn x;\n\t} else if (u-1.0 == -1.0) {\n\t\treturn -1;\n\t} else {\n\t\treturn (u-1.0) * x/logf(u);\n\t}\n}\n#endif\n\n\n\n\n/* Don't pass structures between functions (only pointers) because how\n structures are passed is compiler dependent and could cause\n segfaults if ufuncobject.c is compiled with a different compiler\n than an extension that makes use of the UFUNC API\n*/\n\n/**begin repeat\n\n#typ=float, double, longdouble#\n#c=f,,l#\n*/\n\n/* constants */\nstatic c@typ@ nc_1@c@ = {1., 0.};\nstatic c@typ@ nc_half@c@ = {0.5, 0.};\nstatic c@typ@ nc_i@c@ = {0., 1.};\nstatic c@typ@ nc_i2@c@ = {0., 0.5};\n/*\nstatic c@typ@ nc_mi@c@ = {0., -1.};\nstatic c@typ@ nc_pi2@c@ = {M_PI/2., 0.};\n*/\n\nstatic void\nnc_sum@c@(c@typ@ *a, c@typ@ *b, c@typ@ *r)\n{\n\tr->real = a->real + b->real;\n\tr->imag = a->imag + b->imag;\n\treturn;\n}\n\nstatic void\nnc_diff@c@(c@typ@ *a, c@typ@ *b, c@typ@ *r)\n{\n\tr->real = a->real - b->real;\n\tr->imag = a->imag - b->imag;\n\treturn;\n}\n\nstatic void\nnc_neg@c@(c@typ@ *a, c@typ@ *r)\n{\n\tr->real = -a->real;\n\tr->imag = -a->imag;\n\treturn;\n}\n\nstatic void\nnc_prod@c@(c@typ@ *a, c@typ@ *b, c@typ@ *r)\n{\n\t@typ@ ar=a->real, br=b->real, ai=a->imag, bi=b->imag;\n\tr->real = ar*br - ai*bi;\n\tr->imag = ar*bi + ai*br;\n\treturn;\n}\n\nstatic void\nnc_quot@c@(c@typ@ *a, c@typ@ *b, c@typ@ *r)\n{\n\n\t@typ@ ar=a->real, br=b->real, ai=a->imag, bi=b->imag;\n\t@typ@ d = br*br + bi*bi;\n\tr->real = (ar*br + ai*bi)/d;\n\tr->imag = (ai*br - ar*bi)/d;\n\treturn;\n}\n\nstatic void\nnc_floor_quot@c@(c@typ@ *a, c@typ@ *b, c@typ@ *r)\n{\n\t@typ@ ar=a->real, br=b->real, ai=a->imag, bi=b->imag;\n\t@typ@ d = br*br + bi*bi;\n\tr->real = floor@c@((ar*br + ai*bi)/d);\n\tr->imag = 0;\n\treturn;\n}\n\nstatic void\nnc_sqrt@c@(c@typ@ *x, c@typ@ *r)\n{\n\t@typ@ s,d;\n\tif (x->real == 0. && x->imag == 0.)\n\t\t*r = *x;\n\telse {\n\t\ts = sqrt@c@(0.5*(fabs@c@(x->real) + hypot@c@(x->real,x->imag)));\n\t\td = 0.5*x->imag/s;\n\t\tif (x->real > 0.) {\n\t\t\tr->real = s;\n\t\t\tr->imag = d;\n\t\t}\n\t\telse if (x->imag >= 0.) {\n\t\t\tr->real = d;\n\t\t\tr->imag = s;\n\t\t}\n\t\telse {\n\t\t\tr->real = -d;\n\t\t\tr->imag = -s;\n\t\t}\n\t}\n\treturn;\n}\n\nstatic void\nnc_log@c@(c@typ@ *x, c@typ@ *r)\n{\n\t@typ@ l = hypot@c@(x->real,x->imag);\n\tr->imag = atan2@c@(x->imag, x->real);\n\tr->real = log@c@(l);\n\treturn;\n}\n\nstatic void\nnc_log1p@c@(c@typ@ *x, c@typ@ *r)\n{\n\t@typ@ l = hypot@c@(x->real + 1.0,x->imag);\n\tr->imag = atan2@c@(x->imag, x->real + 1.0);\n\tr->real = log@c@(l);\n\treturn;\n}\n\nstatic void\nnc_exp@c@(c@typ@ *x, c@typ@ *r)\n{\n\t@typ@ a = exp@c@(x->real);\n\tr->real = a*cos@c@(x->imag);\n\tr->imag = a*sin@c@(x->imag);\n\treturn;\n}\n\nstatic void\nnc_expm1@c@(c@typ@ *x, c@typ@ *r)\n{\n\t@typ@ a = exp@c@(x->real);\n\tr->real = a*cos@c@(x->imag) - 1.0;\n\tr->imag = a*sin@c@(x->imag);\n\treturn;\n}\n\nstatic void\nnc_pow@c@(c@typ@ *a, c@typ@ *b, c@typ@ *r)\n{\n\t@typ@ ar=a->real, br=b->real, ai=a->imag, bi=b->imag;\n\n\tif (br == 0. && bi == 0.) {\n\t\tr->real = 1.;\n\t\tr->imag = 0.;\n\t}\n\telse if (ar == 0. && ai == 0.) {\n\t\tr->real = 0.;\n\t\tr->imag = 0.;\n\t}\n\telse {\n\t\tnc_log@c@(a, r);\n\t\tnc_prod@c@(r, b, r);\n\t\tnc_exp@c@(r, r);\n\t}\n\treturn;\n}\n\n\nstatic void\nnc_prodi@c@(c@typ@ *x, c@typ@ *r)\n{\n\tr->real = -x->imag;\n\tr->imag = x->real;\n\treturn;\n}\n\n\nstatic void\nnc_acos@c@(c@typ@ *x, c@typ@ *r)\n{\n\tnc_prod@c@(x,x,r);\n\tnc_diff@c@(&nc_1@c@, r, r);\n\tnc_sqrt@c@(r, r);\n\tnc_prodi@c@(r, r);\n\tnc_sum@c@(x, r, r);\n\tnc_log@c@(r, r);\n\tnc_prodi@c@(r, r);\n\tnc_neg@c@(r, r);\n\treturn;\n\t/* return nc_neg(nc_prodi(nc_log(nc_sum(x,nc_prod(nc_i,\n\t nc_sqrt(nc_diff(nc_1,nc_prod(x,x))))))));\n\t*/\n}\n\nstatic void\nnc_acosh@c@(c@typ@ *x, c@typ@ *r)\n{\n\tnc_prod@c@(x, x, r);\n\tnc_diff@c@(&nc_1@c@, r, r);\n\tnc_sqrt@c@(r, r);\n\tnc_prodi@c@(r, r);\n\tnc_sum@c@(x, r, r);\n\tnc_log@c@(r, r);\n\treturn;\n\t/*\n\t return nc_log(nc_sum(x,nc_prod(nc_i,\n\t nc_sqrt(nc_diff(nc_1,nc_prod(x,x))))));\n\t*/\n}\n\nstatic void\nnc_asin@c@(c@typ@ *x, c@typ@ *r)\n{\n\tc@typ@ a, *pa=&a;\n\tnc_prod@c@(x, x, r);\n\tnc_diff@c@(&nc_1@c@, r, r);\n\tnc_sqrt@c@(r, r);\n\tnc_prodi@c@(x, pa);\n\tnc_sum@c@(pa, r, r);\n\tnc_log@c@(r, r);\n\tnc_prodi@c@(r, r);\n\tnc_neg@c@(r, r);\n\treturn;\n\t/*\n\t return nc_neg(nc_prodi(nc_log(nc_sum(nc_prod(nc_i,x),\n\t nc_sqrt(nc_diff(nc_1,nc_prod(x,x)))))));\n\t*/\n}\n\n\nstatic void\nnc_asinh@c@(c@typ@ *x, c@typ@ *r)\n{\n\tnc_prod@c@(x, x, r);\n\tnc_sum@c@(&nc_1@c@, r, r);\n\tnc_sqrt@c@(r, r);\n\tnc_diff@c@(r, x, r);\n\tnc_log@c@(r, r);\n\tnc_neg@c@(r, r);\n\treturn;\n\t/*\n\t return nc_neg(nc_log(nc_diff(nc_sqrt(nc_sum(nc_1,nc_prod(x,x))),x)));\n\t*/\n}\n\nstatic void\nnc_atan@c@(c@typ@ *x, c@typ@ *r)\n{\n\tc@typ@ a, *pa=&a;\n\tnc_diff@c@(&nc_i@c@, x, pa);\n\tnc_sum@c@(&nc_i@c@, x, r);\n\tnc_quot@c@(r, pa, r);\n\tnc_log@c@(r,r);\n\tnc_prod@c@(&nc_i2@c@, r, r);\n\treturn;\n\t/*\n\t return nc_prod(nc_i2,nc_log(nc_quot(nc_sum(nc_i,x),nc_diff(nc_i,x))));\n\t*/\n}\n\nstatic void\nnc_atanh@c@(c@typ@ *x, c@typ@ *r)\n{\n\tc@typ@ a, *pa=&a;\n\tnc_diff@c@(&nc_1@c@, x, r);\n\tnc_sum@c@(&nc_1@c@, x, pa);\n\tnc_quot@c@(pa, r, r);\n\tnc_log@c@(r, r);\n\tnc_prod@c@(&nc_half@c@, r, r);\n\treturn;\n\t/*\n\t return nc_prod(nc_half,nc_log(nc_quot(nc_sum(nc_1,x),nc_diff(nc_1,x))));\n\t*/\n}\n\nstatic void\nnc_cos@c@(c@typ@ *x, c@typ@ *r)\n{\n\t@typ@ xr=x->real, xi=x->imag;\n\tr->real = cos@c@(xr)*cosh@c@(xi);\n\tr->imag = -sin@c@(xr)*sinh@c@(xi);\n\treturn;\n}\n\nstatic void\nnc_cosh@c@(c@typ@ *x, c@typ@ *r)\n{\n\t@typ@ xr=x->real, xi=x->imag;\n\tr->real = cos(xi)*cosh(xr);\n\tr->imag = sin(xi)*sinh(xr);\n\treturn;\n}\n\n\n#define M_LOG10_E 0.434294481903251827651128918916605082294397\n\nstatic void\nnc_log10@c@(c@typ@ *x, c@typ@ *r)\n{\n\tnc_log@c@(x, r);\n\tr->real *= M_LOG10_E;\n\tr->imag *= M_LOG10_E;\n\treturn;\n}\n\nstatic void\nnc_sin@c@(c@typ@ *x, c@typ@ *r)\n{\n\t@typ@ xr=x->real, xi=x->imag;\n\tr->real = sin@c@(xr)*cosh@c@(xi);\n\tr->imag = cos@c@(xr)*sinh@c@(xi);\n\treturn;\n}\n\nstatic void\nnc_sinh@c@(c@typ@ *x, c@typ@ *r)\n{\n\t@typ@ xr=x->real, xi=x->imag;\n\tr->real = cos@c@(xi)*sinh@c@(xr);\n\tr->imag = sin@c@(xi)*cosh@c@(xr);\n\treturn;\n}\n\nstatic void\nnc_tan@c@(c@typ@ *x, c@typ@ *r)\n{\n\t@typ@ sr,cr,shi,chi;\n\t@typ@ rs,is,rc,ic;\n\t@typ@ d;\n\t@typ@ xr=x->real, xi=x->imag;\n\tsr = sin@c@(xr);\n\tcr = cos@c@(xr);\n\tshi = sinh(xi);\n\tchi = cosh(xi);\n\trs = sr*chi;\n\tis = cr*shi;\n\trc = cr*chi;\n\tic = -sr*shi;\n\td = rc*rc + ic*ic;\n\tr->real = (rs*rc+is*ic)/d;\n\tr->imag = (is*rc-rs*ic)/d;\n\treturn;\n}\n\nstatic void\nnc_tanh@c@(c@typ@ *x, c@typ@ *r)\n{\n\t@typ@ si,ci,shr,chr;\n\t@typ@ rs,is,rc,ic;\n\t@typ@ d;\n\t@typ@ xr=x->real, xi=x->imag;\n\tsi = sin@c@(xi);\n\tci = cos@c@(xi);\n\tshr = sinh@c@(xr);\n\tchr = cosh@c@(xr);\n\trs = ci*shr;\n\tis = si*chr;\n\trc = ci*chr;\n\tic = si*shr;\n\td = rc*rc + ic*ic;\n\tr->real = (rs*rc+is*ic)/d;\n\tr->imag = (is*rc-rs*ic)/d;\n\treturn;\n}\n\n/**end repeat**/\n\n\n/**begin repeat\n\n#TYPE=(BOOL, BYTE,UBYTE,SHORT,USHORT,INT,UINT,LONG,ULONG,LONGLONG,ULONGLONG,FLOAT,DOUBLE,LONGDOUBLE)*2#\n#OP=||, +*13, ^, -*13#\n#kind=add*14, subtract*14#\n#typ=(Bool, byte, ubyte, short, ushort, int, uint, long, ulong, longlong, ulonglong, float, double, longdouble)*2#\n*/\n\nstatic void\n@TYPE@_@kind@(char **args, intp *dimensions, intp *steps, void *func)\n{\n\tregister intp i;\n\tintp is1=steps[0],is2=steps[1],os=steps[2], n=dimensions[0];\n\tchar *i1=args[0], *i2=args[1], *op=args[2];\n\tfor(i=0; i> 32);\n\tal = (a & 0xFFFFFFFFL);\n\tbh = (b >> 32);\n\tbl = (b & 0xFFFFFFFFL);\n#elif SIZEOF_LONGLONG == 128\n\tah = (a >> 64);\n\tal = (a & 0xFFFFFFFFFFFFFFFFL);\n\tbh = (b >> 64);\n\tbl = (b & 0xFFFFFFFFFFFFFFFFL);\n#else\n\tah = al = bh = bl = 0;\n#endif\n\n /* 128-bit product: z*2**64 + (x+y)*2**32 + w */\n\tw = al*bl;\n\tx = bh*al;\n\ty = ah*bl;\n\tz = ah*bh;\n\n\t/* *c = ((x + y)<<32) + w; */\n#if SIZEOF_LONGLONG == 64\n\treturn z || (x>>32) || (y>>32) ||\n\t\t(((x & 0xFFFFFFFFL) + (y & 0xFFFFFFFFL) + (w >> 32)) >> 32);\n#elif SIZEOF_LONGLONG == 128\n\treturn z || (x>>64) || (y>>64) ||\n\t\t(((x & 0xFFFFFFFFFFFFFFFFL) + (y & 0xFFFFFFFFFFFFFFFFL) + (w >> 64)) >> 64);\n#else\n\treturn 0;\n#endif\n\n}\n\nstatic int slonglong_overflow(longlong a0, longlong b0)\n{\n\tulonglong a, b;\n ulonglong ah, al, bh, bl, w, x, y, z;\n\n /* Convert to non-negative quantities */\n\tif (a0 < 0) { a = -a0; } else { a = a0; }\n\tif (b0 < 0) { b = -b0; } else { b = b0; }\n\n\n#if SIZEOF_LONGLONG == 64\n\tah = (a >> 32);\n\tal = (a & 0xFFFFFFFFL);\n\tbh = (b >> 32);\n\tbl = (b & 0xFFFFFFFFL);\n#elif SIZEOF_LONGLONG == 128\n\tah = (a >> 64);\n\tal = (a & 0xFFFFFFFFFFFFFFFFL);\n\tbh = (b >> 64);\n\tbl = (b & 0xFFFFFFFFFFFFFFFFL);\n#else\n\tah = al = bh = bl = 0;\n#endif\n\n\tw = al*bl;\n\tx = bh*al;\n\ty = ah*bl;\n\tz = ah*bh;\n\n /*\n\t ulonglong c = ((x + y)<<32) + w;\n\t if ((a0 < 0) ^ (b0 < 0))\n\t *c = -c;\n\t else\n\t *c = c\n\t */\n\n#if SIZEOF_LONGLONG == 64\n\treturn z || (x>>31) || (y>>31) ||\n\t\t(((x & 0xFFFFFFFFL) + (y & 0xFFFFFFFFL) + (w >> 32)) >> 31);\n#elif SIZEOF_LONGLONG == 128\n\treturn z || (x>>63) || (y>>63) ||\n\t\t(((x & 0xFFFFFFFFFFFFFFFFL) + (y & 0xFFFFFFFFFFFFFFFFL) + (w >> 64)) >> 63);\n#else\n\treturn 0;\n#endif\n}\n\n/** end direct numarray code **/\n\nstatic void\nBOOL_multiply(char **args, intp *dimensions, intp *steps, void *func) {\n\tregister intp i;\n\tintp is1=steps[0], is2=steps[1], os=steps[2], n=dimensions[0];\n\tchar *i1=args[0], *i2=args[1], *op=args[2];\n\tfor (i=0; i MAX_@TYP@)\n\t\t\tgenerate_overflow_error();\n\t\t*((@typ@ *)op) = temp;\n\t}\n}\n\n/**end repeat**/\n\nstatic void\nULONGLONG_multiply(char **args, intp *dimensions, intp *steps, void *func)\n{\n\tregister intp i;\n\tintp is1=steps[0], is2=steps[1], os=steps[2], n=dimensions[0];\n\tchar *i1=args[0], *i2=args[1], *op=args[2];\n\tulonglong temp;\n\tfor (i=0; i MAX_@TYP@)\n\t\t\tgenerate_overflow_error();\n\t\telse if (temp < MIN_@TYP@)\n\t\t\tgenerate_overflow_error();\n\t\t*((@typ@ *)op) = temp;\n\t}\n}\n\n/**end repeat**/\n\nstatic void\nLONGLONG_multiply(char **args, intp *dimensions, intp *steps, void *func)\n{\n\tregister intp i;\n\tintp is1=steps[0], is2=steps[1], os=steps[2], n=dimensions[0];\n\tchar *i1=args[0], *i2=args[1], *op=args[2];\n\tlonglong temp;\n\tfor (i=0; i, >=, <, <=, ==, !=, &&, ||, &, |, ^#\n**/\nstatic void\nBOOL_@kind@(char **args, intp *dimensions, intp *steps, void *func)\n{\n\tregister intp i;\n\tintp is1=steps[0],is2=steps[1],os=steps[2], n=dimensions[0];\n\tchar *i1=args[0], *i2=args[1], *op=args[2];\n\tBool in1, in2;\n\tfor(i=0; i*13, >=*13, <*13, <=*13#\n#typ=(byte, ubyte, short, ushort, int, uint, long, ulong, longlong, ulonglong, float, double, longdouble)*4#\n#kind= greater*13, greater_equal*13, less*13, less_equal*13#\n*/\n\nstatic void\n@TYPE@_@kind@(char **args, intp *dimensions, intp *steps, void *func)\n{\n\tregister intp i;\n\tintp is1=steps[0],is2=steps[1],os=steps[2], n=dimensions[0];\n\tchar *i1=args[0], *i2=args[1], *op=args[2];\n\tfor(i=0; i*3, >=*3, <*3, <=*3#\n#typ=(cfloat, cdouble, clongdouble)*4#\n#kind= greater*3, greater_equal*3, less*3, less_equal*3#\n*/\n\nstatic void\n@TYPE@_@kind@(char **args, intp *dimensions, intp *steps, void *func)\n{\n\tregister intp i;\n\tintp is1=steps[0],is2=steps[1],os=steps[2], n=dimensions[0];\n\tchar *i1=args[0], *i2=args[1], *op=args[2];\n\tfor(i=0; ireal == ((@typ@ *)i2)->real)\n\t\t\t*((Bool *)op)=((@typ@ *)i1)->imag @OP@ \\\n\t\t\t\t((@typ@ *)i2)->imag;\n\t\telse\n\t\t\t*((Bool *)op)=((@typ@ *)i1)->real @OP@ \\\n\t\t\t\t((@typ@ *)i2)->real;\n\t}\n}\n/**end repeat**/\n\n\n/**begin repeat\n#TYPE=(BYTE,UBYTE,SHORT,USHORT,INT,UINT,LONG,ULONG,LONGLONG,ULONGLONG,FLOAT,DOUBLE,LONGDOUBLE)*4#\n#typ=(byte, ubyte, short, ushort, int, uint, long, ulong, longlong, ulonglong, float, double, longdouble)*4#\n#OP= ==*13, !=*13, &&*13, ||*13#\n#kind=equal*13, not_equal*13, logical_and*13, logical_or*13#\n*/\nstatic void\n@TYPE@_@kind@(char **args, intp *dimensions, intp *steps, void *func)\n{\n\tregister intp i;\n\tintp is1=steps[0],is2=steps[1],os=steps[2], n=dimensions[0];\n\tchar *i1=args[0], *i2=args[1], *op=args[2];\n\tfor(i=0; i 0 ? 1 : ((x) < 0 ? -1 : 0))\n#define _SIGN2(x) ((x) == 0 ? 0 : 1)\n#define _SIGNC(x) (((x).real > 0) ? 1 : ((x).real < 0 ? -1 : ((x).imag > 0 ? 1 : ((x).imag < 0) ? -1 : 0)))\n/**begin repeat\n#TYPE=BYTE,SHORT,INT,LONG,LONGLONG,FLOAT,DOUBLE,LONGDOUBLE,UBYTE,USHORT,UINT,ULONG,ULONGLONG#\n#typ=byte,short,int,long,longlong,float,double,longdouble,ubyte,ushort,uint,ulong,ulonglong#\n#func=_SIGN1*8,_SIGN2*5#\n */\nstatic void\n@TYPE@_sign(char **args, intp *dimensions, intp *steps, void *func)\n{\n\tregister intp i;\n\tintp is1=steps[0],os=steps[1], n=dimensions[0];\n\tchar *i1=args[0], *op=args[1];\n @typ@ t1;\n\tfor(i=0; ireal ||\t\\\n\t\t\t\t ((@typ@ *)i1)->imag);\n\t}\n}\n/**end repeat**/\n\n\n\n\n/**begin repeat\n#TYPE=BYTE,SHORT,INT,LONG,LONGLONG#\n#typ=byte, short, int, long, longlong#\n#ftyp=float*2,double*2,longdouble*1#\n#c=f*2,,,l*1#\n*/\nstatic void\n@TYPE@_remainder(char **args, intp *dimensions, intp *steps, void *func)\n{\n\tregister intp i;\n\tintp is1=steps[0],is2=steps[1],os=steps[2], n=dimensions[0];\n\tchar *i1=args[0], *i2=args[1], *op=args[2];\n\tregister @typ@ ix,iy, tmp;\n\tfor(i=0; i 0) == (iy > 0)) {\n\t\t\t*((@typ@ *)op) = ix % iy;\n\t\t}\n\t\telse { /* handle mixed case the way Python does */\n\t\t\ttmp = ix % iy;\n\t\t\tif (tmp) tmp += iy;\n\t\t\t*((@typ@ *)op)= tmp;\n\t\t}\n\t}\n}\n/**end repeat**/\n\n/**begin repeat\n#TYPE=UBYTE,USHORT,UINT,ULONG,ULONGLONG#\n#typ=ubyte, ushort, uint, ulong, ulonglong#\n*/\nstatic void\n@TYPE@_remainder(char **args, intp *dimensions, intp *steps, void *func)\n{\n\tregister intp i;\n\tintp is1=steps[0],is2=steps[1],os=steps[2], n=dimensions[0];\n\tchar *i1=args[0], *i2=args[1], *op=args[2];\n\tregister @typ@ ix,iy;\n\tfor(i=0; i>*10#\n#kind=bitwise_and*10, bitwise_or*10, bitwise_xor*10, left_shift*10, right_shift*10#\n\n*/\nstatic void\n@TYPE@_@kind@(char **args, intp *dimensions, intp *steps, void *func)\n{\n\tregister intp i;\n\tintp is1=steps[0],is2=steps[1],os=steps[2], n=dimensions[0];\n\tchar *i1=args[0], *i2=args[1], *op=args[2];\n\tfor(i=0; ireal || ((@typ@ *)i1)->imag;\n\t\tp2 = ((@typ@ *)i2)->real || ((@typ@ *)i2)->imag;\n\t\t*((Bool *)op)= (p1 || p2) && !(p1 && p2);\n\t}\n}\n/**end repeat**/\n\n\n\n/**begin repeat\n\n#TYPE=(BOOL,BYTE,UBYTE,SHORT,USHORT,INT,UINT,LONG,ULONG,LONGLONG,ULONGLONG,FLOAT,DOUBLE,LONGDOUBLE)*2#\n#OP= >*14, <*14#\n#typ=(Bool, byte, ubyte, short, ushort, int, uint, long, ulong, longlong, ulonglong, float, double, longdouble)*2#\n#kind= maximum*14, minimum*14#\n*/\nstatic void\n@TYPE@_@kind@(char **args, intp *dimensions, intp *steps, void *func)\n{\n\tregister intp i;\n\tintp is1=steps[0],is2=steps[1],os=steps[2], n=dimensions[0];\n\tchar *i1=args[0], *i2=args[1], *op=args[2];\n\tfor(i=0; i*3, <*3#\n#typ=(cfloat, cdouble, clongdouble)*2#\n#kind= maximum*3, minimum*3#\n*/\nstatic void\n@TYPE@_@kind@(char **args, intp *dimensions, intp *steps, void *func)\n{\n\tregister intp i;\n\tintp is1=steps[0],is2=steps[1],os=steps[2], n=dimensions[0];\n\tchar *i1=args[0], *i2=args[1], *op=args[2];\n @typ@ *i1c, *i2c;\n\tfor(i=0; ireal @OP@ i2c->real) || \\\n ((i1c->real==i2c->real) && (i1c->imag @OP@ i2c->imag)))\n memcpy(op, i1, sizeof(@typ@));\n else\n memcpy(op, i2, sizeof(@typ@));\n\t}\n}\n/**end repeat**/\n\n\n\n/*** isinf, isinf, isfinite, signbit ***/\n/**begin repeat\n#kind=isnan*3, isinf*3, isfinite*3, signbit*3#\n#TYPE=(FLOAT, DOUBLE, LONGDOUBLE)*4#\n#typ=(float, double, longdouble)*4#\n#c=(f,,l)*4#\n*/\nstatic void\n@TYPE@_@kind@(char **args, intp *dimensions, intp *steps, void *func)\n{\n register intp i;\n intp is=steps[0], os=steps[1], n=dimensions[0];\n char *ip=args[0], *op=args[1];\n for(i=0; 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 static char\n _scalar_kind(int typenum, PyArrayObject **arr) \n {\n-\tif (PyTypeNum_ISSIGNED(typenum)) return UFUNC_INTNEG_SCALAR;\n+\tif (PyTypeNum_ISSIGNED(typenum)) {\n+\t\tif (_signbit_set(*arr)) return UFUNC_INTNEG_SCALAR;\n+\t\telse return UFUNC_INTPOS_SCALAR;\n+\t}\n \tif (PyTypeNum_ISFLOAT(typenum)) return UFUNC_FLOAT_SCALAR;\n-\tif (PyTypeNum_ISCOMPLEX(typenum)) return UFUNC_COMPLEX_SCALAR;\n \tif (PyTypeNum_ISUNSIGNED(typenum)) return UFUNC_INTPOS_SCALAR;\n+\tif (PyTypeNum_ISCOMPLEX(typenum)) return UFUNC_COMPLEX_SCALAR;\n \tif (PyTypeNum_ISBOOL(typenum)) return UFUNC_BOOL_SCALAR;\n+\n \treturn UFUNC_OBJECT_SCALAR;\n }\n \n", + "added_lines": 25, + "deleted_lines": 2, + "source_code": "\n/*\n Python Universal Functions Object -- Math for all types, plus fast \n arrays math\n \n Full description\n \n This supports mathematical (and Boolean) functions on arrays and other python\n objects. Math on large arrays of basic C types is rather efficient.\n\n Travis E. Oliphant (2005)\n Assistant Professor\n Brigham Young University\n\n based on the \n\n Original Implementation: \n Copyright (c) 1995, 1996, 1997 Jim Hugunin, hugunin@mit.edu\n\n with inspiration and code from\n Numarray\n Space Science Telescope Institute\n J. Todd Miller\n Perry Greenfield\n Rick White\n \n*/\n\n\ntypedef double (DoubleBinaryFunc)(double x, double y);\ntypedef float (FloatBinaryFunc)(float x, float y);\ntypedef longdouble (LongdoubleBinaryFunc)(longdouble x, longdouble y);\n\ntypedef void (CdoubleBinaryFunc)(cdouble *x, cdouble *y, cdouble *res);\ntypedef void (CfloatBinaryFunc)(cfloat *x, cfloat *y, cfloat *res);\ntypedef void (ClongdoubleBinaryFunc)(clongdouble *x, clongdouble *y, \\\n\t\t\t\t clongdouble *res);\n\n/*UFUNC_API*/\nstatic void\nPyUFunc_ff_f_As_dd_d(char **args, intp *dimensions, intp *steps, void *func)\n{\n\tregister intp i, n=dimensions[0];\n\tregister intp is1=steps[0],is2=steps[1],os=steps[2];\n\tchar *ip1=args[0], *ip2=args[1], *op=args[2];\n\t\n\tfor(i=0; inin, nout=data->nout;\n int ntot;\n PyObject *tocall = data->callable; \n char *ptrs[MAX_ARGS];\n PyObject *arglist, *result;\n PyObject *in, **op;\n\n ntot = nin+nout;\n\n for (j=0; j < ntot; j++) ptrs[j] = args[j];\n\tfor(i=0; i> UFUNC_SHIFT_##NAME, \\\n\t\t\t\t\t errobj, str, retstatus) < 0) \\\n\t\t\t\treturn -1;\t\t \\\n\t\t\t}}\n\n\tif (errmask && retstatus) {\n\t\tHANDLEIT(DIVIDEBYZERO, \"divide by zero\");\n\t\tHANDLEIT(OVERFLOW, \"overflow\");\n\t\tHANDLEIT(UNDERFLOW, \"underflow\");\n\t\tHANDLEIT(INVALID, \"invalid\");\n\t}\n\n#undef HANDLEIT\n\n\treturn 0;\n}\n\n\n/* Checking the status flag clears it */\n/*UFUNC_API*/\nstatic void\nPyUFunc_clearfperr()\n{\n\tint retstatus;\n\n\tUFUNC_CHECK_STATUS(retstatus)\n}\n\n\n#define UFUNC_NOSCALAR 0\n#define UFUNC_BOOL_SCALAR 1\n#define UFUNC_INTPOS_SCALAR 2\n#define UFUNC_INTNEG_SCALAR 3\n#define UFUNC_FLOAT_SCALAR 4\n#define UFUNC_COMPLEX_SCALAR 5\n#define UFUNC_OBJECT_SCALAR 6\n\n#define NO_UFUNCLOOP 0\n#define ZERODIM_REDUCELOOP 0\n#define ONE_UFUNCLOOP 1\n#define ONEDIM_REDUCELOOP 1\n#define NOBUFFER_UFUNCLOOP 2\n#define NOBUFFER_REDUCELOOP 2\n#define BUFFER_UFUNCLOOP 3\n#define BUFFER_REDUCELOOP 3\n\n\nstatic char\n_lowest_type(char intype)\n{\n switch(intype) {\n\t/* case PyArray_BYTE */\n\tcase PyArray_SHORT:\n case PyArray_INT:\n case PyArray_LONG:\n\tcase PyArray_LONGLONG:\n\t\treturn PyArray_BYTE;\n\t/* case PyArray_UBYTE */\n case PyArray_USHORT:\n case PyArray_UINT:\n\tcase PyArray_ULONG:\n\tcase PyArray_ULONGLONG:\n\t\treturn PyArray_UBYTE;\n\t/* case PyArray_FLOAT:*/\n case PyArray_DOUBLE:\n\tcase PyArray_LONGDOUBLE:\n\t\treturn PyArray_FLOAT;\n\t/* case PyArray_CFLOAT:*/\n case PyArray_CDOUBLE:\n\tcase PyArray_CLONGDOUBLE:\n\t\treturn PyArray_CFLOAT;\n default:\n return intype;\n }\n}\n\n/* Called to determine coercion\n */\n\nstatic int \n_cancoerce(char thistype, char neededtype, char scalar) \n{\n\n\tswitch(scalar) {\n\tcase UFUNC_NOSCALAR:\n\tcase UFUNC_BOOL_SCALAR:\n\tcase UFUNC_OBJECT_SCALAR:\n\t\treturn PyArray_CanCastSafely(thistype, neededtype);\n\tcase UFUNC_INTPOS_SCALAR:\n\t\treturn (neededtype >= PyArray_UBYTE);\n\tcase UFUNC_INTNEG_SCALAR:\n\t\treturn (neededtype >= PyArray_BYTE) &&\t\t\\\n\t\t\t!(PyTypeNum_ISUNSIGNED(neededtype));\n\tcase UFUNC_FLOAT_SCALAR:\n\t\treturn (neededtype >= PyArray_FLOAT);\n\tcase UFUNC_COMPLEX_SCALAR:\n\t\treturn (neededtype >= PyArray_CFLOAT);\n\t}\n\tfprintf(stderr, \"\\n**Error** coerce fall through: %d %d %d\\n\\n\", \n\t\tthistype, neededtype, scalar);\n\treturn 1; /* should never get here... */ \n}\n\n\nstatic int \nselect_types(PyUFuncObject *self, int *arg_types, \n PyUFuncGenericFunction *function, void **data,\n\t char *scalars)\n{\n\n\tint i=0, j;\n\tchar start_type;\n\t\n\tif (PyTypeNum_ISUSERDEF((arg_types[0]))) {\n\t\tPyObject *key, *obj;\n\t\tfor (i=0; inin; i++) {\n\t\t\tif (arg_types[i] != arg_types[0]) {\n\t\t\t\tPyErr_SetString(PyExc_TypeError,\n\t\t\t\t\t\t\"ufuncs on user defined\" \\\n\t\t\t\t\t\t\" types don't support \"\\\n\t\t\t\t\t\t\"coercion\");\n\t\t\t\treturn -1;\n\t\t\t}\n\t\t}\n\t\tfor (i=self->nin; inargs; i++) {\n\t\t\targ_types[i] = arg_types[0];\n\t\t}\n\n\t\tobj = NULL;\n\t\tif (self->userloops) {\n\t\t\tkey = PyInt_FromLong((long) arg_types[0]);\n\t\t\tif (key == NULL) return -1;\n\t\t\tobj = PyDict_GetItem(self->userloops, key);\n\t\t\tPy_DECREF(key);\n\t\t}\n\t\tif (obj == NULL) {\n\t\t\tPyErr_SetString(PyExc_TypeError, \n\t\t\t\t\t\"no registered loop for this \"\t\\\n\t\t\t\t\t\"user-defined type\");\n\t\t\treturn -1;\t\t\t\n\t\t}\n\t\tif PyTuple_Check(obj) {\n\t\t\t*function = (PyUFuncGenericFunction) \\\n\t\t\t\tPyCObject_AsVoidPtr(PyTuple_GET_ITEM(obj, 0));\n\t\t\t*data = PyCObject_AsVoidPtr(PyTuple_GET_ITEM(obj, 1));\n\t\t}\n\t\telse {\n\t\t\t*function = (PyUFuncGenericFunction)\t\\\n\t\t\t\tPyCObject_AsVoidPtr(obj);\n\t\t\t*data = NULL;\n\t\t}\n Py_DECREF(obj);\n\t\treturn 0;\n\t}\n\t\n\n\tstart_type = arg_types[0];\n\t/* If the first argument is a scalar we need to place \n\t the start type as the lowest type in the class\n\t*/\n\tif (scalars[0] != UFUNC_NOSCALAR) {\n\t\tstart_type = _lowest_type(start_type);\n\t}\n\n\twhile (intypes && start_type > self->types[i*self->nargs]) \n\t\ti++;\n\n\tfor(;intypes; i++) {\n\t\tfor(j=0; jnin; j++) {\n\t\t\tif (!_cancoerce(arg_types[j], \n\t\t\t\t\tself->types[i*self->nargs+j],\n\t\t\t\t\tscalars[j]))\n\t\t\t\tbreak;\n\t\t}\n\t\tif (j == self->nin) break;\n\t}\n\tif(i>=self->ntypes) {\n\t\tPyErr_SetString(PyExc_TypeError, \n\t\t\t\t\"function not supported for these types, \"\\\n\t\t\t\t\"and can't coerce safely to supported types\");\n\t\treturn -1;\n\t}\n\tfor(j=0; jnargs; j++) \n\t\targ_types[j] = self->types[i*self->nargs+j];\n\n if (self->data)\n *data = self->data[i];\n else \n *data = NULL;\n\t*function = self->functions[i];\n\n\treturn 0;\n}\n\nstatic int PyUFunc_USEDEFAULTS=0;\n\n/*UFUNC_API*/\nstatic int\nPyUFunc_GetPyValues(char *name, int *bufsize, int *errmask, PyObject **errobj)\n{\n PyObject *thedict;\n PyObject *ref=NULL;\n\tPyObject *retval;\n\tstatic PyObject *thestring=NULL;\n\n\tif (!PyUFunc_USEDEFAULTS) {\n\t\tif (thestring == NULL) {\n\t\t\tthestring = PyString_InternFromString(UFUNC_PYVALS_NAME);\n\t\t}\n\t\tthedict = PyEval_GetLocals();\n\t\tref = PyDict_GetItem(thedict, thestring);\n\t\tif (ref == NULL) {\n\t\t\tthedict = PyEval_GetGlobals();\n\t\t\tref = PyDict_GetItem(thedict, thestring);\n\t\t}\n\t\tif (ref == NULL) {\n\t\t\tthedict = PyEval_GetBuiltins();\n\t\t\tref = PyDict_GetItem(thedict, thestring);\n\t\t}\n\t}\n\tif (ref == NULL) {\n\t\t*errmask = UFUNC_ERR_DEFAULT;\n\t\t*errobj = Py_BuildValue(\"NO\",\n\t\t\t\t\tPyString_FromString(name),\n\t\t\t\t\tPy_None);\n\t\t*bufsize = PyArray_BUFSIZE;\n\t\treturn 0;\n\t}\n\t*errobj = NULL;\n\tif (!PyList_Check(ref) || (PyList_GET_SIZE(ref)!=3)) {\n\t\tPyErr_Format(PyExc_TypeError, \"%s must be a length 3 list.\",\n\t\t\t UFUNC_PYVALS_NAME);\n\t\treturn -1;\n\t}\n\n\t*bufsize = PyInt_AsLong(PyList_GET_ITEM(ref, 0));\n\tif ((*bufsize == -1) && PyErr_Occurred()) return -1;\n\tif ((*bufsize < PyArray_MIN_BUFSIZE) ||\t\\\n\t (*bufsize > PyArray_MAX_BUFSIZE) || \\\n\t (*bufsize % 16 != 0)) {\n\t\tPyErr_Format(PyExc_ValueError, \n\t\t\t \"buffer size (%d) is not \"\t\\\n\t\t\t \"in range (%d - %d) or not a multiple of 16\", \n\t\t\t *bufsize, PyArray_MIN_BUFSIZE, \n\t\t\t PyArray_MAX_BUFSIZE);\n\t\treturn -1;\n\t}\n\n\t*errmask = PyInt_AsLong(PyList_GET_ITEM(ref, 1));\n\tif (*errmask < 0) {\n\t\tif (PyErr_Occurred()) return -1;\n\t\tPyErr_Format(PyExc_ValueError,\t\t\\\n\t\t\t \"invalid error mask (%d)\", \n\t\t\t *errmask);\n\t\treturn -1;\n\t}\n\t\n\tretval = PyList_GET_ITEM(ref, 2);\n\tif (retval != Py_None && !PyCallable_Check(retval)) {\n\t\tPyErr_SetString(PyExc_TypeError, \n\t\t\t\t\"callback function must be callable\");\n\t\treturn -1;\n\t}\n\n\t*errobj = Py_BuildValue(\"NO\", \n\t\t\t\tPyString_FromString(name),\n\t\t\t\tretval);\n\tif (*errobj == NULL) return -1;\n\t\n\treturn 0;\n}\n\nstatic int\n_signbit_set(PyArrayObject *arr)\n{\n\tstatic char bitmask = 0x80;\n\tchar *ptr; /* points to the byte to test */\n\tchar byteorder;\n\tint elsize;\n\n\telsize = arr->descr->elsize;\n\tbyteorder = arr->descr->byteorder;\n\tptr = arr->data;\n\tif (elsize > 1 && \\\n\t (byteorder == PyArray_LITTLE ||\t\\\n\t (byteorder == PyArray_NATIVE &&\n\t PyArray_ISNBO(PyArray_LITTLE))))\n\t\tptr += elsize-1;\n\t\n\treturn ((*ptr & bitmask) != 0);\t\n}\n\nstatic char\n_scalar_kind(int typenum, PyArrayObject **arr) \n{\n\tif (PyTypeNum_ISSIGNED(typenum)) {\n\t\tif (_signbit_set(*arr)) return UFUNC_INTNEG_SCALAR;\n\t\telse return UFUNC_INTPOS_SCALAR;\n\t}\n\tif (PyTypeNum_ISFLOAT(typenum)) return UFUNC_FLOAT_SCALAR;\n\tif (PyTypeNum_ISUNSIGNED(typenum)) return UFUNC_INTPOS_SCALAR;\n\tif (PyTypeNum_ISCOMPLEX(typenum)) return UFUNC_COMPLEX_SCALAR;\n\tif (PyTypeNum_ISBOOL(typenum)) return UFUNC_BOOL_SCALAR;\n\n\treturn UFUNC_OBJECT_SCALAR;\n}\n\n\n/* Create copies for any arrays that are less than loop->bufsize\n in total size and are mis-behaved or in need\n of casting.\n*/\n\nstatic int\n_create_copies(PyUFuncLoopObject *loop, int *arg_types, PyArrayObject **mps)\n{\n\tint nin = loop->ufunc->nin;\n\tint i;\n\tintp size;\n\tPyObject *new;\n\tPyArray_Descr *ntype; \n\tPyArray_Descr *atype;\n\n\tfor (i=0; idescr;\n\t\t\tatype = PyArray_DescrFromType(arg_types[i]);\n\t\t\tif (PyArray_EquivTypes(atype, ntype)) {\n\t\t\t\targ_types[i] = ntype->type_num;\n\t\t\t}\n\t\t\tPy_DECREF(atype);\n\t\t}\n\t\tif (size < loop->bufsize) {\n\t\t\tif (!(PyArray_ISBEHAVED_RO(mps[i])) ||\t\t\\\n\t\t\t PyArray_TYPE(mps[i]) != arg_types[i]) {\n\t\t\t\tntype = PyArray_DescrFromType(arg_types[i]);\n\t\t\t\tnew = PyArray_FromAny((PyObject *)mps[i], \n\t\t\t\t\t\t ntype, 0, 0,\n\t\t\t\t\t\t FORCECAST | ALIGNED, NULL);\n\t\t\t\tif (new == NULL) return -1;\n\t\t\t\tPy_DECREF(mps[i]);\n\t\t\t\tmps[i] = (PyArrayObject *)new;\n\t\t\t}\n\t\t}\n\t}\n\t\n\treturn 0;\n}\n\n#define _GETATTR_(str, rstr) if (strcmp(name, #str) == 0) { \\\n return PyObject_HasAttrString(op, \"__\" #rstr \"__\");}\n\nstatic int\n_has_reflected_op(PyObject *op, char *name)\n{\n _GETATTR_(add, radd)\n _GETATTR_(subtract, rsub)\n _GETATTR_(multiply, rmul)\n _GETATTR_(divide, rdiv)\n _GETATTR_(true_divide, rtruediv)\n _GETATTR_(floor_divide, rfloordiv)\n _GETATTR_(remainder, rmod)\n _GETATTR_(power, rpow)\n _GETATTR_(left_shift, rrlshift)\n _GETATTR_(right_shift, rrshift)\n _GETATTR_(bitwise_and, rand)\n _GETATTR_(bitwise_xor, rxor)\n _GETATTR_(bitwise_or, ror)\n return 0;\n}\n\n#undef _GETATTR_\n\nstatic int\nconstruct_matrices(PyUFuncLoopObject *loop, PyObject *args, PyArrayObject **mps)\n{\n int nargs, i, maxsize;\n int arg_types[MAX_ARGS];\n\tchar scalars[MAX_ARGS];\n\tPyUFuncObject *self=loop->ufunc;\n\tBool allscalars=TRUE;\n\tPyTypeObject *subtype=&PyArray_Type;\n PyObject *context=NULL;\n PyObject *obj;\n\n /* Check number of arguments */\n nargs = PyTuple_Size(args);\n if ((nargs != self->nin) && (nargs != self->nargs)) {\n PyErr_SetString(PyExc_ValueError, \n\t\t\t\t\"invalid number of arguments\");\n return -1;\n }\n\n /* Get each input argument */\n for (i=0; inin; i++) {\n obj = PyTuple_GET_ITEM(args,i);\n if (!PyArray_Check(obj) && !PyArray_IsScalar(obj, Generic)) {\n context = Py_BuildValue(\"OOi\", self, args, i);\n }\n else context = NULL;\n mps[i] = (PyArrayObject *)PyArray_FromAny(obj, NULL, 0, 0, 0, context);\n Py_XDECREF(context);\n if (mps[i] == NULL) return -1;\n arg_types[i] = PyArray_TYPE(mps[i]);\n if (PyTypeNum_ISFLEXIBLE(arg_types[i])) {\n\t\t\tloop->notimplemented = 1;\n\t\t\treturn nargs;\n }\n\t\t/*\n\t\tfprintf(stderr, \"array %d has reference %d\\n\", i, \n\t\t (mps[i])->ob_refcnt);\n\t\t*/\n\n\t\t/* Scalars are 0-dimensional arrays\n\t\t at this point\n\t\t*/\n\t\tif (mps[i]->nd > 0) {\n\t\t\tscalars[i] = UFUNC_NOSCALAR;\n\t\t\tallscalars=FALSE;\n\t\t}\n\t\telse scalars[i] = _scalar_kind(arg_types[i], &(mps[i]));\n\n\t\t/* If any input is a big-array */\n\t\tif (!PyType_IsSubtype(mps[i]->ob_type, &PyArray_Type)) {\n\t\t\tsubtype = &PyBigArray_Type;\n\t\t}\n }\n\n\t/* If everything is a scalar, then use normal coercion rules */\n\tif (allscalars) {\n\t\tfor (i=0; inin; i++) {\n\t\t\tscalars[i] = UFUNC_NOSCALAR;\n\t\t}\n\t}\n \n /* Select an appropriate function for these argument types. */\n if (select_types(loop->ufunc, arg_types, &(loop->function), \n &(loop->funcdata), scalars) == -1)\n\t\treturn -1;\n\n /* FAIL with NotImplemented if the other object has \n\t the __r__ method and has __array_priority__ as \n\t an attribute (signalling it can handle ndarray's) \n\t and is not already an ndarray or bigndarray\n\t*/\n if ((arg_types[1] == PyArray_OBJECT) &&\t\t\t\t\\\n (loop->ufunc->nin==2) && (loop->ufunc->nout == 1)) {\n\t\tPyObject *_obj = PyTuple_GET_ITEM(args, 1);\n if (!PyArray_CheckExact(_obj) &&\t\t\t\\\n\t\t !PyBigArray_CheckExact(_obj) &&\t\t\t\\\n\t\t PyObject_HasAttrString(_obj, \"__array_priority__\") && \\\n\t\t _has_reflected_op(_obj, loop->ufunc->name)) {\n loop->notimplemented = 1;\n return nargs;\n }\n }\n loop->notimplemented=0;\n \n\t/* Create copies for some of the arrays if appropriate */\n\tif (_create_copies(loop, arg_types, mps) < 0) return -1;\n\t\n\t/* Create Iterators for the Inputs */\n\tfor (i=0; inin; i++) {\n loop->iters[i] = (PyArrayIterObject *)\t\t\\\n\t\t\tPyArray_IterNew((PyObject *)mps[i]);\n if (loop->iters[i] == NULL) return -1;\n\t}\n \n /* Broadcast the result */\n loop->numiter = self->nin;\n if (PyArray_Broadcast((PyArrayMultiIterObject *)loop) < 0)\n\t\treturn -1;\n\t\n /* Get any return arguments */\n for (i=self->nin; idimensions, \n\t\t\t\t\t loop->dimensions, loop->nd)) {\n PyErr_SetString(PyExc_ValueError, \n \"invalid return array shape\");\n\t\t\tPy_DECREF(mps[i]);\n mps[i] = NULL;\n return -1;\n }\n if (!PyArray_ISWRITEABLE(mps[i])) {\n PyErr_SetString(PyExc_ValueError, \n \"return array is not writeable\");\n\t\t\tPy_DECREF(mps[i]);\n mps[i] = NULL;\n return -1;\n }\n }\n\n /* construct any missing return arrays and make output iterators */\n \n for (i=self->nin; inargs; i++) {\n\t\tPyArray_Descr *ntype;\n\n if (mps[i] == NULL) {\n mps[i] = (PyArrayObject *)PyArray_New(subtype,\n loop->nd, \n loop->dimensions,\n arg_types[i], \n NULL, NULL,\n 0, 0, NULL);\n if (mps[i] == NULL) return -1;\n }\n\n\t\t/* reset types for outputs that are equivalent \n\t\t -- no sense casting uselessly\n\t\t*/\n\t\telse {\n \t\t if (mps[i]->descr->type_num != arg_types[i]) {\n\t\t\t PyArray_Descr *atype;\n\t\t\t ntype = mps[i]->descr;\n\t\t\t atype = PyArray_DescrFromType(arg_types[i]);\n\t\t\t if (PyArray_EquivTypes(atype, ntype)) {\n\t\t\t\t arg_types[i] = ntype->type_num;\n\t\t\t }\n\t\t\t Py_DECREF(atype);\n\t\t }\n\t\t \n\t\t/* still not the same -- or will we have to use buffers?*/\n\t\t if (mps[i]->descr->type_num != arg_types[i] ||\n\t\t !PyArray_ISBEHAVED_RO(mps[i])) {\n\t\t\t if (loop->size < loop->bufsize) {\n\t\t\t\t PyObject *new;\n\t\t\t\t /* Copy the array to a temporary copy \n\t\t\t\t and set the UPDATEIFCOPY flag\n\t\t\t\t */\n\t\t\t\t ntype = PyArray_DescrFromType(arg_types[i]);\n\t\t\t\t new = PyArray_FromAny((PyObject *)mps[i],\n\t\t\t\t\t\t\tntype, 0, 0,\n\t\t\t\t\t\t\tFORCECAST | ALIGNED |\n\t\t\t\t\t\t\tUPDATEIFCOPY, NULL);\n\t\t\t\t if (new == NULL) return -1;\n\t\t\t\t Py_DECREF(mps[i]);\n\t\t\t\t mps[i] = (PyArrayObject *)new;\n\t\t\t }\n\t\t }\n\t\t}\n\t\t\n loop->iters[i] = (PyArrayIterObject *)\t\t\\\n\t\t\tPyArray_IterNew((PyObject *)mps[i]);\n if (loop->iters[i] == NULL) return -1;\n }\n\n\n /* If any of different type, or misaligned or swapped\n then must use buffers */\n\n loop->bufcnt = 0;\n\n loop->obj = 0;\n\n /* Determine looping method needed */\n loop->meth = NO_UFUNCLOOP;\n\n\tmaxsize = 0;\n for (i=0; inargs; i++) {\n\t\tloop->needbuffer[i] = 0;\n if (arg_types[i] != mps[i]->descr->type_num || \n\t\t !PyArray_ISBEHAVED_RO(mps[i])) {\n loop->meth = BUFFER_UFUNCLOOP;\n\t\t\tloop->needbuffer[i] = 1;\n }\n if (!loop->obj && mps[i]->descr->type_num == PyArray_OBJECT) {\n\t\t\tloop->obj = 1;\n\t\t}\n }\n \n if (loop->meth == NO_UFUNCLOOP) {\n \n loop->meth = ONE_UFUNCLOOP;\n\n /* All correct type and BEHAVED */\n /* Check for non-uniform stridedness */\n\n for (i=0; inargs; i++) {\n if (!(loop->iters[i]->contiguous)) {\n\t\t\t\t/* may still have uniform stride\n\t\t\t\t if (broadcated result) <= 1-d */\n\t\t\t\tif (mps[i]->nd != 0 &&\t\t\t\\\n\t\t\t\t (loop->iters[i]->nd_m1 > 0)) {\n\t\t\t\t\tloop->meth = NOBUFFER_UFUNCLOOP;\n\t\t\t\t\tbreak;\n\t\t\t\t}\n\t\t\t}\n }\n\t\tif (loop->meth == ONE_UFUNCLOOP) {\n\t\t\tfor (i=0; inargs; i++) {\n\t\t\t\tloop->bufptr[i] = mps[i]->data;\n\t\t\t}\n\t\t}\n }\n\n loop->numiter = self->nargs;\n\n /* Fill in steps */\n if (loop->meth != ONE_UFUNCLOOP) {\n\t\tint ldim = 0;\n\t\tintp maxdim=-1;\n\t\tPyArrayIterObject *it;\n\n /* Fix iterators */\n\n /* Find the **largest** dimension */\n \n\t\tmaxdim = -1;\n\t\tfor (i=loop->nd - 1; i>=0; i--) {\n\t\t\tif (loop->dimensions[i] > maxdim) {\n\t\t\t\tldim = i;\n\t\t\t\tmaxdim = loop->dimensions[i];\n\t\t\t}\n\t\t}\n\n\t\tloop->size /= maxdim;\n loop->bufcnt = maxdim;\n\t\tloop->lastdim = ldim;\n\n /* Fix the iterators so the inner loop occurs over the \n\t\t largest dimensions -- This can be done by \n\t\t setting the size to 1 in that dimension \n\t\t (just in the iterators)\n */\n\n\t\tfor (i=0; inumiter; i++) {\n\t\t\tit = loop->iters[i];\n it->contiguous = 0;\n\t\t\tit->size /= (it->dims_m1[ldim]+1);\n\t\t\tit->dims_m1[ldim] = 0;\n\t\t\tit->backstrides[ldim] = 0;\n\n\t\t\t/* (won't fix factors because we\n\t\t\t don't use PyArray_ITER_GOTO1D \n\t\t\t so don't change them) */\n\n\t\t\t/* Set the steps to the strides in that dimension */\n loop->steps[i] = it->strides[ldim];\n\t\t}\n\n\t\t/* fix up steps where we will be copying data to \n\t\t buffers and calculate the ninnerloops and leftover\n\t\t values -- if step size is already zero that is not changed... \n\t\t*/\n\t\tif (loop->meth == BUFFER_UFUNCLOOP) {\n\t\t\tloop->leftover = maxdim % loop->bufsize;\n\t\t\tloop->ninnerloops = (maxdim / loop->bufsize) + 1;\n\t\t\tfor (i=0; inargs; i++) {\n\t\t\t\tif (loop->needbuffer[i] && loop->steps[i]) {\n\t\t\t\t\tloop->steps[i] = mps[i]->descr->elsize;\n\t\t\t\t}\n\t\t\t\t/* These are changed later if casting is needed */\n\t\t\t}\n\t\t}\n }\n else { /* uniformly-strided case ONE_UFUNCLOOP */\n\t\tfor (i=0; inargs; i++) {\n\t\t\tif (PyArray_SIZE(mps[i]) == 1)\n\t\t\t\tloop->steps[i] = 0;\n\t\t\telse\n\t\t\t\tloop->steps[i] = mps[i]->strides[mps[i]->nd-1];\n\t\t}\n\t}\n \n\n\t/* Finally, create memory for buffers if we need them */\n\t\n\t/* buffers for scalars are specially made small -- scalars are\n\t not copied multiple times */\n\tif (loop->meth == BUFFER_UFUNCLOOP) {\n\t\tint cnt = 0, cntcast = 0; /* keeps track of bytes to allocate */\n\t\tint scnt = 0, scntcast = 0;\n\t\tchar *castptr;\n\t\tchar *bufptr;\n\t\tint last_was_scalar=0;\n\t\tint last_cast_was_scalar=0;\n\t\tint oldbufsize=0;\n\t\tint oldsize=0;\n\t\tint scbufsize = 4*sizeof(double);\n\t\tint memsize;\n PyArray_Descr *descr;\n\n\t\t/* compute the element size */\n\t\tfor (i=0; inargs;i++) {\n\t\t\tif (!loop->needbuffer) continue;\n\t\t\tif (arg_types[i] != mps[i]->descr->type_num) {\n\t\t\t\tdescr = PyArray_DescrFromType(arg_types[i]);\n\t\t\t\tif (loop->steps[i])\n\t\t\t\t\tcntcast += descr->elsize;\n\t\t\t\telse\n\t\t\t\t\tscntcast += descr->elsize;\n\t\t\t\tif (i < self->nin) {\n\t\t\t\t\tloop->cast[i] =\t\t\t\\\n\t\t\t\t\t\tmps[i]->descr->f->cast[arg_types[i]];\n\t\t\t\t}\n\t\t\t\telse {\n\t\t\t\t\tloop->cast[i] = descr->f->\t\\\n\t\t\t\t\t\tcast[mps[i]->descr->type_num];\n\t\t\t\t}\n\t\t\t\tPy_DECREF(descr);\n\t\t\t}\n\t\t\tloop->swap[i] = !(PyArray_ISNOTSWAPPED(mps[i]));\n\t\t\tif (loop->steps[i])\n\t\t\t\tcnt += mps[i]->descr->elsize;\n\t\t\telse\n\t\t\t\tscnt += mps[i]->descr->elsize;\n\t\t}\n\t\tmemsize = loop->bufsize*(cnt+cntcast) + scbufsize*(scnt+scntcast);\n \t\tloop->buffer[0] = PyDataMem_NEW(memsize);\n\n\t\t/* fprintf(stderr, \"Allocated buffer at %p of size %d, cnt=%d, cntcast=%d\\n\", loop->buffer[0], loop->bufsize * (cnt + cntcast), cnt, cntcast); */\n\n\t\tif (loop->buffer[0] == NULL) {PyErr_NoMemory(); return -1;}\n\t\tcastptr = loop->buffer[0] + loop->bufsize*cnt + scbufsize*scnt;\n\t\tbufptr = loop->buffer[0];\n\t\tfor (i=0; inargs; i++) {\n\t\t\tif (!loop->needbuffer[i]) continue;\n\t\t\tloop->buffer[i] = bufptr + (last_was_scalar ? scbufsize : \\\n\t\t\t\t\t\t loop->bufsize)*oldbufsize;\n\t\t\tlast_was_scalar = (loop->steps[i] == 0);\n\t\t\tbufptr = loop->buffer[i];\n\t\t\toldbufsize = mps[i]->descr->elsize;\n\t\t\t/* fprintf(stderr, \"buffer[%d] = %p\\n\", i, loop->buffer[i]); */\n\t\t\tif (loop->cast[i]) {\n\t\t\t\tPyArray_Descr *descr;\n\t\t\t\tloop->castbuf[i] = castptr + (last_cast_was_scalar ? scbufsize : \\\n\t\t\t\t\t\t\t loop->bufsize)*oldsize;\n\t\t\t\tlast_cast_was_scalar = last_was_scalar;\n\t\t\t\t/* fprintf(stderr, \"castbuf[%d] = %p\\n\", i, loop->castbuf[i]); */\n\t\t\t\tdescr = PyArray_DescrFromType(arg_types[i]);\n\t\t\t\toldsize = descr->elsize;\n\t\t\t\tPy_DECREF(descr);\n\t\t\t\tloop->bufptr[i] = loop->castbuf[i];\n\t\t\t\tcastptr = loop->castbuf[i];\n\t\t\t\tif (loop->steps[i])\n\t\t\t\t\tloop->steps[i] = oldsize;\n\t\t\t}\n\t\t\telse {\n\t\t\t\tloop->bufptr[i] = loop->buffer[i];\n\t\t\t}\n\t\t}\n\t}\n return nargs;\n}\n\nstatic void\nufuncreduce_dealloc(PyUFuncReduceObject *self)\n{\n if (self->ufunc) {\n Py_XDECREF(self->it);\n\t\tPy_XDECREF(self->rit);\n Py_XDECREF(self->ret);\n\t\tPy_XDECREF(self->errobj);\n\t\tPy_XDECREF(self->decref);\n if (self->buffer) PyDataMem_FREE(self->buffer);\n Py_DECREF(self->ufunc);\n }\n _pya_free(self);\n}\n\nstatic void\nufuncloop_dealloc(PyUFuncLoopObject *self)\n{\n\tint i;\n\t\n\tif (self->ufunc != NULL) {\n\t\tfor (i=0; iufunc->nargs; i++)\n\t\t\tPy_XDECREF(self->iters[i]);\n\t\tif (self->buffer[0]) PyDataMem_FREE(self->buffer[0]);\n\t\tPy_XDECREF(self->errobj);\n\t\tPy_DECREF(self->ufunc);\n\t}\n _pya_free(self);\n}\n\nstatic PyUFuncLoopObject *\nconstruct_loop(PyUFuncObject *self, PyObject *args, PyArrayObject **mps)\n{\n\tPyUFuncLoopObject *loop;\n\tint i;\n\t\n\tif (self == NULL) {\n\t\tPyErr_SetString(PyExc_ValueError, \"function not supported\");\n\t\treturn NULL;\n\t}\n if ((loop = _pya_malloc(sizeof(PyUFuncLoopObject)))==NULL) {\n PyErr_NoMemory(); return loop;\n }\n\t\n\tloop->index = 0;\n\tloop->ufunc = self;\n Py_INCREF(self);\n\tloop->buffer[0] = NULL;\n for (i=0; inargs; i++) {\n loop->iters[i] = NULL;\n loop->cast[i] = NULL;\n }\n\tloop->errobj = NULL;\n\n\tif (PyUFunc_GetPyValues((self->name ? self->name : \"\"),\n\t\t\t\t&(loop->bufsize), &(loop->errormask), \n\t\t\t\t&(loop->errobj)) < 0) goto fail;\n \n\t/* Setup the matrices */\n\tif (construct_matrices(loop, args, mps) < 0) goto fail;\n\n\tPyUFunc_clearfperr();\n\n\treturn loop;\n\n fail:\n ufuncloop_dealloc(loop);\n\treturn NULL;\n}\n\n\n/* \nstatic void\n_printbytebuf(PyUFuncLoopObject *loop, int bufnum) \n{ \n\tint i;\n\t\n \tfprintf(stderr, \"Printing byte buffer %d\\n\", bufnum);\n for (i=0; ibufcnt; i++) {\n\t \tfprintf(stderr, \" %d\\n\", *(((byte *)(loop->buffer[bufnum]))+i));\n\t} \n}\n\nstatic void\n_printlongbuf(PyUFuncLoopObject *loop, int bufnum) \n{ \n\tint i;\n\t\n \tfprintf(stderr, \"Printing long buffer %d\\n\", bufnum);\n for (i=0; ibufcnt; i++) {\n\t \tfprintf(stderr, \" %ld\\n\", *(((long *)(loop->buffer[bufnum]))+i));\n\t} \n}\n\nstatic void\n_printlongbufptr(PyUFuncLoopObject *loop, int bufnum) \n{ \n\tint i;\n\t\n \tfprintf(stderr, \"Printing long buffer %d\\n\", bufnum);\n for (i=0; ibufcnt; i++) {\n\t \tfprintf(stderr, \" %ld\\n\", *(((long *)(loop->bufptr[bufnum]))+i));\n\t} \n}\n\n\n \nstatic void\n_printcastbuf(PyUFuncLoopObject *loop, int bufnum) \n{ \n\tint i;\n\t\n \tfprintf(stderr, \"Printing long buffer %d\\n\", bufnum);\n for (i=0; ibufcnt; i++) {\n\t \tfprintf(stderr, \" %ld\\n\", *(((long *)(loop->castbuf[bufnum]))+i));\n\t} \n}\n\n*/\n\n\n\n\n/* currently generic ufuncs cannot be built for use on flexible arrays.\n\n The cast functions in the generic loop would need to be fixed to pass \n in something besides NULL, NULL.\n\n Also the underlying ufunc loops would not know the element-size unless\n that was passed in as data (which could be arranged).\n\n*/\n\n/* This generic function is called with the ufunc object, the arguments to it,\n and an array of (pointers to) PyArrayObjects which are NULL. The \n arguments are parsed and placed in mps in construct_loop (construct_matrices)\n*/\n\n/*UFUNC_API*/\nstatic int \nPyUFunc_GenericFunction(PyUFuncObject *self, PyObject *args, \n\t\t\tPyArrayObject **mps) \n{\n\tPyUFuncLoopObject *loop;\n\tint i;\n BEGIN_THREADS_DEF\n\n\tif (!(loop = construct_loop(self, args, mps))) return -1;\n if (loop->notimplemented) {ufuncloop_dealloc(loop); return -2;}\n\n\tLOOP_BEGIN_THREADS\n\n\tswitch(loop->meth) {\n\tcase ONE_UFUNCLOOP:\n\t\t/* Everything is contiguous, notswapped, aligned,\n\t\t and of the right type. -- Fastest.\n\t\t Or if not contiguous, then a single-stride\n\t\t increment moves through the entire array. \n\t\t*/\n /*fprintf(stderr, \"ONE...%d\\n\", loop->size);*/\n\t\tloop->function((char **)loop->bufptr, &(loop->size), \n\t\t\t loop->steps, loop->funcdata);\n\t\tUFUNC_CHECK_ERROR(loop);\n\t\tbreak;\n\tcase NOBUFFER_UFUNCLOOP:\n\t\t/* Everything is notswapped, aligned and of the \n\t\t right type but not contiguous. -- Almost as fast.\n\t\t*/\n /*fprintf(stderr, \"NOBUFFER...%d\\n\", loop->size);*/\n\t\twhile (loop->index < loop->size) {\n\t\t\tfor (i=0; inargs; i++) \n\t\t\t\tloop->bufptr[i] = loop->iters[i]->dataptr;\n\n\t\t\tloop->function((char **)loop->bufptr, &(loop->bufcnt),\n\t\t\t\t loop->steps, loop->funcdata);\n\t\t\tUFUNC_CHECK_ERROR(loop);\n\n\t\t\tfor (i=0; inargs; i++) {\n\t\t\t\tPyArray_ITER_NEXT(loop->iters[i]);\n\t\t\t}\n\t\t\tloop->index++;\n\t\t}\n\t\tbreak;\n\tcase BUFFER_UFUNCLOOP: {\n\t\tPyArray_CopySwapNFunc *copyswapn[MAX_ARGS];\n\t\tPyArrayIterObject **iters=loop->iters;\n\t\tint *swap=loop->swap;\n\t\tvoid **dptr=loop->dptr;\n\t\tint mpselsize[MAX_ARGS];\n\t\tintp laststrides[MAX_ARGS];\n\t\tint fastmemcpy[MAX_ARGS];\n\t\tint *needbuffer=loop->needbuffer;\n\t\tintp index=loop->index, size=loop->size;\n\t\tint bufsize;\n\t\tintp bufcnt;\n\t\tint copysizes[MAX_ARGS];\n\t\tvoid **bufptr = loop->bufptr;\n\t\tvoid **buffer = loop->buffer;\n\t\tvoid **castbuf = loop->castbuf;\n\t\tintp *steps = loop->steps;\n\t\tchar *tptr[MAX_ARGS];\n\t\tint ninnerloops = loop->ninnerloops;\n\t\tBool pyobject[MAX_ARGS];\n\t\tint datasize[MAX_ARGS];\n int i, j, k, stopcondition;\n\t\tchar *myptr1, *myptr2;\n\n\t\t\n\t\tfor (i=0; inargs; i++) {\n\t\t\tcopyswapn[i] = mps[i]->descr->f->copyswapn;\n\t\t\tmpselsize[i] = mps[i]->descr->elsize;\n\t\t\tpyobject[i] = (loop->obj && \\\n (mps[i]->descr->type_num == PyArray_OBJECT));\n\t\t\tlaststrides[i] = iters[i]->strides[loop->lastdim];\n\t\t\tif (steps[i] && laststrides[i] != mpselsize[i]) fastmemcpy[i] = 0;\n\t\t\telse fastmemcpy[i] = 1;\n\t\t}\n\t\t/* Do generic buffered looping here (works for any kind of\n\t\t arrays -- some need buffers, some don't. \n\t\t*/\n\t\t\n\t\t/* New algorithm: N is the largest dimension. B is the buffer-size.\n\t\t quotient is loop->ninnerloops-1\n\t\t remainder is loop->leftover\n\n\t\tCompute N = quotient * B + remainder. \n\t\tquotient = N / B # integer math \n\t\t(store quotient + 1) as the number of innerloops\n\t\tremainder = N % B # integer remainder\n\t\t\n\t\tOn the inner-dimension we will have (quotient + 1) loops where \n\t\tthe size of the inner function is B for all but the last when the niter size is\n\t\tremainder. \n\t\t\n\t\tSo, the code looks very similar to NOBUFFER_LOOP except the inner-most loop is \n\t\treplaced with...\n\t\t\n\t\tfor(i=0; isize, \n\t\t loop->ninnerloops, loop->leftover);\n\t\t*/\n\t\t/*\n\t\tfor (i=0; inargs; i++) {\n\t\t fprintf(stderr, \"iters[%d]->dataptr = %p, %p of size %d\\n\", i, \n\t\t\t iters[i], iters[i]->ao->data, PyArray_NBYTES(iters[i]->ao));\n\t\t}\n\t\t*/\n\n\t\tstopcondition = ninnerloops;\n\t\tif (loop->leftover == 0) stopcondition--;\n\t\twhile (index < size) {\n\t\t\tbufsize=loop->bufsize;\n\t\t\tfor (i=0; inargs; i++) {\n\t\t\t\ttptr[i] = loop->iters[i]->dataptr;\n\t\t\t\tif (needbuffer[i]) {\n\t\t\t\t\tdptr[i] = bufptr[i];\n\t\t\t\t\tdatasize[i] = (steps[i] ? bufsize : 1);\n\t\t\t\t\tcopysizes[i] = datasize[i] * mpselsize[i];\n\t\t\t\t}\n\t\t\t\telse {\n\t\t\t\t\tdptr[i] = tptr[i];\n\t\t\t\t}\n\t\t\t}\n\n\t\t\t/* This is the inner function over the last dimension */\n\t\t\tfor (k=1; k<=stopcondition; k++) {\n\t\t\t\tif (k==ninnerloops) {\n bufsize = loop->leftover;\n for (i=0; inargs;i++) {\n\t\t\t\t\t\tif (!needbuffer[i]) continue;\n datasize[i] = (steps[i] ? bufsize : 1);\n\t\t\t\t\t\tcopysizes[i] = datasize[i] * mpselsize[i];\n }\n }\n \n\t\t\t\tfor (i=0; inin; i++) {\n\t\t\t\t\tif (!needbuffer[i]) continue;\n\t\t\t\t\tif (fastmemcpy[i]) \n\t\t\t\t\t\tmemcpy(buffer[i], tptr[i],\n\t\t\t\t\t\t copysizes[i]);\n\t\t\t\t\telse {\n\t\t\t\t\t\tmyptr1 = buffer[i];\n\t\t\t\t\t\tmyptr2 = tptr[i];\n\t\t\t\t\t\tfor (j=0; jcast[i]) {\n\t\t\t\t\t\tloop->cast[i](buffer[i],\n\t\t\t\t\t\t\t castbuf[i],\n\t\t\t\t\t\t\t (intp) datasize[i],\n\t\t\t\t\t\t\t NULL, NULL);\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t\t\n\t\t\t\tbufcnt = (intp) bufsize;\n\t\t\t\tloop->function((char **)dptr, &bufcnt, steps, loop->funcdata);\n\t\t\t\t\n\t\t\t\tfor (i=self->nin; inargs; i++) {\n\t\t\t\t\tif (!needbuffer[i]) continue;\n\t\t\t\t\tif (loop->cast[i]) {\n\t\t\t\t\t\tloop->cast[i](castbuf[i],\n\t\t\t\t\t\t\t buffer[i],\n\t\t\t\t\t\t\t (intp) datasize[i],\n\t\t\t\t\t\t\t NULL, NULL);\n\t\t\t\t\t}\n\t\t\t\t\tif (swap[i]) {\n\t\t\t\t\t\tcopyswapn[i](buffer[i], NULL,\n\t\t\t\t\t\t\t (intp) datasize[i], 1, \n\t\t\t\t\t\t\t mpselsize[i]);\n\t\t\t\t\t}\n\t\t\t\t\t/* copy back to output arrays */\n\t\t\t\t\t/* decref what's already there for object arrays */\n\t\t\t\t\tif (pyobject[i]) {\n\t\t\t\t\t\tmyptr1 = tptr[i];\n\t\t\t\t\t\tfor (j=0; jnargs; i++) {\n\t\t\t\t\ttptr[i] += bufsize * laststrides[i];\n\t\t\t\t\tif (!needbuffer[i]) dptr[i] = tptr[i];\n\t\t\t\t}\n\t\t\t}\n\n\t\t\tif (loop->obj) { /* DECREF castbuf for object arrays */\n\t\t\t\tfor (i=0; inargs; i++) {\n\t\t\t\t\tif (pyobject[i]) {\n\t\t\t\t\t\tif (steps[i] == 0) {\n\t\t\t\t\t\t\tPy_XDECREF(*((PyObject **)castbuf[i]));\n\t\t\t\t\t\t}\n\t\t\t\t\t\telse {\n\t\t\t\t\t\t\tint size = loop->bufsize;\n\t\t\t\t\t\t\tPyObject **objptr = castbuf[i];\n\t\t\t\t\t\t\t/* size is loop->bufsize unless there\n\t\t\t\t\t\t\t was only one loop */\n\t\t\t\t\t\t\tif (ninnerloops == 1) \\\n\t\t\t\t\t\t\t\tsize = loop->leftover;\n\t\t\t\t\t\t\t\n\t\t\t\t\t\t\tfor (j=0; jnargs; i++) {\n\t\t\t\tPyArray_ITER_NEXT(loop->iters[i]);\n\t\t\t}\n\t\t\tindex++;\n }\n }\n }\n \n LOOP_END_THREADS\n \n ufuncloop_dealloc(loop);\n\treturn 0;\n\n fail:\n LOOP_END_THREADS\n\n\tif (loop) ufuncloop_dealloc(loop);\n\treturn -1;\n}\n\nstatic PyArrayObject *\n_getidentity(PyUFuncObject *self, int otype, char *str)\n{\n PyObject *obj, *arr;\n PyArray_Descr *typecode;\n\t\n if (self->identity == PyUFunc_None) {\n PyErr_Format(PyExc_ValueError, \n \"zero-size array to ufunc.%s \" \\\n \"without identity\", str);\n return NULL;\n }\n if (self->identity == PyUFunc_One) {\n obj = PyInt_FromLong((long) 1);\n } else {\n obj = PyInt_FromLong((long) 0);\n }\n\n\ttypecode = PyArray_DescrFromType(otype); \n arr = PyArray_FromAny(obj, typecode, 0, 0, CARRAY_FLAGS, NULL);\n Py_DECREF(obj);\n return (PyArrayObject *)arr;\n}\n\nstatic int\n_create_reduce_copy(PyUFuncReduceObject *loop, PyArrayObject **arr, int rtype)\n{\n\tintp maxsize;\n\tPyObject *new;\n\tPyArray_Descr *ntype;\n\t\n\tmaxsize = PyArray_SIZE(*arr);\n\t\n\tif (maxsize < loop->bufsize) {\n\t\tif (!(PyArray_ISBEHAVED_RO(*arr)) ||\t\\\n\t\t PyArray_TYPE(*arr) != rtype) {\n\t\t\tntype = PyArray_DescrFromType(rtype);\n\t\t\tnew = PyArray_FromAny((PyObject *)(*arr), \n\t\t\t\t\t ntype, 0, 0,\n\t\t\t\t\t FORCECAST | ALIGNED, NULL);\n\t\t\tif (new == NULL) return -1;\n\t\t\t*arr = (PyArrayObject *)new;\n\t\t\tloop->decref = new;\n\t\t}\n\t}\n\n\t/* Don't decref *arr before re-assigning\n\t because it was not going to be DECREF'd anyway.\n\t \n\t If a copy is made, then the copy will be removed\n\t on deallocation of the loop structure by setting \n\t loop->decref.\n\t*/\n\t\n\treturn 0;\n}\n\nstatic PyUFuncReduceObject *\nconstruct_reduce(PyUFuncObject *self, PyArrayObject **arr, int axis, \n\t\t int otype, int operation, intp ind_size, char *str)\n{\n PyUFuncReduceObject *loop;\n PyArrayObject *idarr;\n\tPyArrayObject *aar;\n intp loop_i[MAX_DIMS];\n int arg_types[3] = {otype, otype, otype};\n\tchar scalars[3] = {UFUNC_NOSCALAR, UFUNC_NOSCALAR, UFUNC_NOSCALAR};\n\tint i, j;\n\tint nd = (*arr)->nd;\n\t/* Reduce type is the type requested of the input \n\t during reduction */\n \n if ((loop = _pya_malloc(sizeof(PyUFuncReduceObject)))==NULL) {\n PyErr_NoMemory(); return loop;\n }\n \n loop->swap = 0;\n\tloop->index = 0;\n\tloop->ufunc = self;\n Py_INCREF(self);\n loop->cast = NULL;\n loop->buffer = NULL;\n loop->ret = NULL;\n\tloop->it = NULL;\n\tloop->rit = NULL;\n\tloop->errobj = NULL;\n\tloop->decref=NULL; \n loop->N = (*arr)->dimensions[axis];\n\tloop->instrides = (*arr)->strides[axis];\n\n\tif (select_types(loop->ufunc, arg_types, &(loop->function), \n\t\t\t &(loop->funcdata), scalars) == -1) goto fail; \n\t\n\t/* output type may change -- if it does \n\t reduction is forced into that type \n\t and we need to select the reduction function again\n\t*/\n\tif (otype != arg_types[2]) {\n\t\totype = arg_types[2];\n\t\targ_types[0] = otype;\n\t\targ_types[1] = otype;\n\t\tif (select_types(loop->ufunc, arg_types, &(loop->function), \n\t\t\t\t &(loop->funcdata), scalars) == -1) \n\t\t\tgoto fail; \t\t\n\t}\n\t\n\t/* get looping parameters from Python */\n\tif (PyUFunc_GetPyValues(str, &(loop->bufsize), &(loop->errormask), \n\t\t\t\t&(loop->errobj)) < 0) goto fail;\n\t\n\t/* Make copy if misbehaved or not otype for small arrays */\n\tif (_create_reduce_copy(loop, arr, otype) < 0) goto fail; \n\taar = *arr;\n\t\n if (loop->N == 0) {\n loop->meth = ZERODIM_REDUCELOOP;\n }\n else if (PyArray_ISBEHAVED_RO(aar) &&\t\t\\\n otype == (aar)->descr->type_num) {\n\t\tif (loop->N == 1) {\n\t\t\tloop->meth = ONEDIM_REDUCELOOP;\n\t\t}\n\t\telse {\n\t\t\tloop->meth = NOBUFFER_UFUNCLOOP;\n\t\t\tloop->steps[0] = (aar)->strides[axis];\n\t\t\tloop->N -= 1;\n\t\t}\n }\n else {\n loop->meth = BUFFER_UFUNCLOOP;\n loop->swap = !(PyArray_ISNOTSWAPPED(aar));\n }\n\n /* Determine if object arrays are involved */\n if (otype == PyArray_OBJECT || aar->descr->type_num == PyArray_OBJECT)\n loop->obj = 1;\n else\n loop->obj = 0;\n\n if (loop->meth == ZERODIM_REDUCELOOP) {\n idarr = _getidentity(self, otype, str);\n if (idarr == NULL) goto fail;\n if (idarr->descr->elsize > UFUNC_MAXIDENTITY) {\n PyErr_Format(PyExc_RuntimeError, \n\t\t\t\t \"UFUNC_MAXIDENTITY (%d)\"\t\t\\\n \" is too small (needs to be at least %d)\",\n UFUNC_MAXIDENTITY, idarr->descr->elsize);\n Py_DECREF(idarr);\n goto fail;\n }\n memcpy(loop->idptr, idarr->data, idarr->descr->elsize);\n Py_DECREF(idarr);\n }\n\t\n /* Construct return array */\n\tswitch(operation) {\n\tcase UFUNC_REDUCE:\n\t\tfor (j=0, i=0; idimensions[i];\n\t\t\t\n\t\t}\n\t\tloop->ret = (PyArrayObject *)\t\t\t\t\\\n\t\t\tPyArray_New(aar->ob_type, aar->nd-1, loop_i, otype, \n\t\t\t\t NULL, NULL, 0, 0, (PyObject *)aar);\n\t\tbreak;\n\tcase UFUNC_ACCUMULATE:\n\t\tloop->ret = (PyArrayObject *)\t\t\t\t\\\n\t\t\tPyArray_New(aar->ob_type, aar->nd, aar->dimensions, \n\t\t\t\t otype, NULL, NULL, 0, 0, (PyObject *)aar);\n\t\tbreak;\n\tcase UFUNC_REDUCEAT:\n\t\tmemcpy(loop_i, aar->dimensions, nd*sizeof(intp));\n\t\t/* Index is 1-d array */\n\t\tloop_i[axis] = ind_size; \n\t\tloop->ret = (PyArrayObject *)\\\n\t\t\tPyArray_New(aar->ob_type, aar->nd, loop_i, otype,\n\t\t\t\t NULL, NULL, 0, 0, (PyObject *)aar);\n\t\tif (loop->ret == NULL) goto fail;\n\t\tif (ind_size == 0) {\n\t\t\tloop->meth = ZERODIM_REDUCELOOP;\n\t\t\treturn loop;\n\t\t}\n\t\tif (loop->meth == ONEDIM_REDUCELOOP)\n\t\t\tloop->meth = NOBUFFER_REDUCELOOP;\n\t\tbreak;\n\t}\n if (loop->ret == NULL) goto fail;\n loop->insize = aar->descr->elsize;\n loop->outsize = loop->ret->descr->elsize;\n loop->bufptr[1] = loop->ret->data;\n\n\tif (loop->meth == ZERODIM_REDUCELOOP) {\n\t\tloop->size = PyArray_SIZE(loop->ret);\n\t\treturn loop;\n\t}\n\n\tloop->it = (PyArrayIterObject *)PyArray_IterNew((PyObject *)aar);\n if (loop->it == NULL) return NULL;\n\n\tif (loop->meth == ONEDIM_REDUCELOOP) {\n\t\tloop->size = loop->it->size;\t\t\n\t\treturn loop;\n\t}\n\n /* Fix iterator to loop over correct dimension */\n\t/* Set size in axis dimension to 1 */\n \n loop->it->contiguous = 0;\n loop->it->size /= (loop->it->dims_m1[axis]+1);\n loop->it->dims_m1[axis] = 0;\n loop->it->backstrides[axis] = 0;\n\n\n loop->size = loop->it->size;\n\n\tif (operation == UFUNC_REDUCE) {\n\t\tloop->steps[1] = 0;\n\t}\n\telse {\n\t\tloop->rit = (PyArrayIterObject *)\t\t\t\\\n\t\t\tPyArray_IterNew((PyObject *)(loop->ret));\n\t\tif (loop->rit == NULL) return NULL;\t\t\n\n\t\t/* Fix iterator to loop over correct dimension */\n\t\t/* Set size in axis dimension to 1 */\n\t\t\n\t\tloop->rit->contiguous = 0;\n\t\tloop->rit->size /= (loop->rit->dims_m1[axis]+1);\n\t\tloop->rit->dims_m1[axis] = 0;\n\t\tloop->rit->backstrides[axis] = 0;\n\n\t\tif (operation == UFUNC_ACCUMULATE)\n\t\t\tloop->steps[1] = loop->ret->strides[axis];\n\t\telse \n\t\t\tloop->steps[1] = 0;\n\t}\n\tloop->steps[2] = loop->steps[1];\n\tloop->bufptr[2] = loop->bufptr[1] + loop->steps[2];\n\n\t\n\tif (loop->meth == BUFFER_UFUNCLOOP) {\n\t\tint _size;\n\t\tloop->steps[0] = loop->outsize;\n if (otype != aar->descr->type_num) {\n\t\t\t_size=loop->bufsize*(loop->outsize +\t\t\\\n\t\t\t\t\t aar->descr->elsize);\n loop->buffer = PyDataMem_NEW(_size);\n if (loop->buffer == NULL) goto fail;\n\t\t\tif (loop->obj) memset(loop->buffer, 0, _size);\n loop->castbuf = loop->buffer + \\\n loop->bufsize*aar->descr->elsize;\n loop->bufptr[0] = loop->castbuf; \n loop->cast = aar->descr->f->cast[otype];\n }\n else {\n\t\t\t_size = loop->bufsize * loop->outsize;\n loop->buffer = PyDataMem_NEW(_size);\n if (loop->buffer == NULL) goto fail;\n\t\t\tif (loop->obj) memset(loop->buffer, 0, _size);\n loop->bufptr[0] = loop->buffer;\n }\n\t}\n\n\n\tPyUFunc_clearfperr();\n\treturn loop;\n\n fail:\n ufuncreduce_dealloc(loop);\n\treturn NULL;\t\n}\n\n\n/* We have two basic kinds of loops */\n/* One is used when arr is not-swapped and aligned and output type\n is the same as input type.\n and another using buffers when one of these is not satisfied.\n\n Zero-length and one-length axes-to-be-reduced are handled separately.\n*/\n\nstatic PyObject *\nPyUFunc_Reduce(PyUFuncObject *self, PyArrayObject *arr, int axis, int otype)\n{\n PyArrayObject *ret=NULL;\n PyUFuncReduceObject *loop;\n intp i, n;\n char *dptr;\n BEGIN_THREADS_DEF\n \t\n /* Construct loop object */\n loop = construct_reduce(self, &arr, axis, otype, UFUNC_REDUCE, 0,\n\t\t\t\t\"reduce\");\n\tif (!loop) return NULL;\n\n LOOP_BEGIN_THREADS\n switch(loop->meth) {\n case ZERODIM_REDUCELOOP:\n\t\t/* fprintf(stderr, \"ZERO..%d\\n\", loop->size); */\n\t\tfor(i=0; isize; i++) {\n\t\t\tif (loop->obj) Py_INCREF(*((PyObject **)loop->idptr));\n\t\t\tmemmove(loop->bufptr[1], loop->idptr, loop->outsize);\n\t\t\tloop->bufptr[1] += loop->outsize;\n\t\t}\n break;\n case ONEDIM_REDUCELOOP:\n\t\t/*fprintf(stderr, \"ONEDIM..%d\\n\", loop->size); */\n while(loop->index < loop->size) {\n\t\t\tif (loop->obj) Py_INCREF(*((PyObject **)loop->it->dataptr));\n memmove(loop->bufptr[1], loop->it->dataptr, \n loop->outsize);\n\t\t\tPyArray_ITER_NEXT(loop->it);\n\t\t\tloop->bufptr[1] += loop->outsize;\n\t\t\tloop->index++;\n\t\t}\t\t\n\t\tbreak;\n case NOBUFFER_UFUNCLOOP:\n\t\t/*fprintf(stderr, \"NOBUFFER..%d\\n\", loop->size); */\n while(loop->index < loop->size) {\n\t\t\t/* Copy first element to output */\n\t\t\tif (loop->obj) \n\t\t\t\tPy_INCREF(*((PyObject **)loop->it->dataptr));\n memmove(loop->bufptr[1], loop->it->dataptr, \n loop->outsize);\n\t\t\t/* Adjust input pointer */\n loop->bufptr[0] = loop->it->dataptr+loop->steps[0];\n loop->function((char **)loop->bufptr, \n\t\t\t\t &(loop->N),\n loop->steps, loop->funcdata);\n\t\t\tUFUNC_CHECK_ERROR(loop);\n\n PyArray_ITER_NEXT(loop->it)\n loop->bufptr[1] += loop->outsize;\n loop->bufptr[2] = loop->bufptr[1];\n loop->index++; \n }\n break;\n case BUFFER_UFUNCLOOP: \n /* use buffer for arr */\n /* \n For each row to reduce\n 1. copy first item over to output (casting if necessary)\n 2. Fill inner buffer \n 3. When buffer is filled or end of row\n a. Cast input buffers if needed\n b. Call inner function.\n 4. Repeat 2 until row is done.\n */\n\t\t/* fprintf(stderr, \"BUFFERED..%d %d\\n\", loop->size, \n\t\t loop->swap); */\n while(loop->index < loop->size) {\n loop->inptr = loop->it->dataptr;\t\t\t\n\t\t\t/* Copy (cast) First term over to output */\n\t\t\tif (loop->cast) {\n\t\t\t\t/* A little tricky because we need to\n\t\t\t\t cast it first */\n\t\t\t\tarr->descr->f->copyswap(loop->buffer,\n\t\t\t\t\t\t loop->inptr,\n\t\t\t\t\t\t loop->swap,\n\t\t\t\t\t\t loop->insize);\n\t\t\t\tloop->cast(loop->buffer, loop->castbuf,\n\t\t\t\t\t 1, NULL, NULL);\n\t\t\t\tif (loop->obj) \n\t\t\t\t\tPy_INCREF(*((PyObject **)loop->castbuf));\n\t\t\t\tmemcpy(loop->bufptr[1], loop->castbuf,\n\t\t\t\t loop->outsize);\n\t\t\t}\n\t\t\telse { /* Simple copy */\n\t\t\t\tarr->descr->f->copyswap(loop->bufptr[1], \n\t\t\t\t\t\t loop->inptr,\n\t\t\t\t\t\t loop->swap,\n\t\t\t\t\t\t loop->insize);\n\t\t\t}\n\t\t\tloop->inptr += loop->instrides;\n n = 1;\n while(n < loop->N) {\n /* Copy up to loop->bufsize elements to \n buffer */\n dptr = loop->buffer;\n for (i=0; ibufsize; i++, n++) {\n if (n == loop->N) break;\n arr->descr->f->copyswap(dptr,\n loop->inptr,\n loop->swap,\n loop->insize);\n loop->inptr += loop->instrides;\n dptr += loop->insize;\n }\n if (loop->cast)\n loop->cast(loop->buffer,\n loop->castbuf,\n i, NULL, NULL);\n loop->function((char **)loop->bufptr,\n &i, \n\t\t\t\t\t loop->steps, loop->funcdata);\n\t\t\t\tUFUNC_CHECK_ERROR(loop);\n } \n PyArray_ITER_NEXT(loop->it);\n loop->bufptr[1] += loop->outsize;\n loop->bufptr[2] = loop->bufptr[1]; \n loop->index++;\n }\n }\n\n LOOP_END_THREADS\n\n ret = loop->ret;\n\t/* Hang on to this reference -- will be decref'd with loop */\n Py_INCREF(ret);\n ufuncreduce_dealloc(loop);\n return (PyObject *)ret;\n\n fail:\n LOOP_END_THREADS\n\n if (loop) ufuncreduce_dealloc(loop);\n return NULL;\n}\n\n\nstatic PyObject *\nPyUFunc_Accumulate(PyUFuncObject *self, PyArrayObject *arr, int axis, \n\t\t int otype)\n{\n PyArrayObject *ret=NULL;\n PyUFuncReduceObject *loop;\n intp i, n;\n char *dptr;\n \n /* Construct loop object */\n loop = construct_reduce(self, &arr, axis, otype, UFUNC_ACCUMULATE, 0,\n\t\t\t\t\"accumulate\");\n\tif (!loop) return NULL;\n\n\tLOOP_BEGIN_THREADS\n switch(loop->meth) {\n case ZERODIM_REDUCELOOP: /* Accumulate */\n\t\t/* fprintf(stderr, \"ZERO..%d\\n\", loop->size); */\n\t\tfor(i=0; isize; i++) {\n\t\t\tif (loop->obj) \n\t\t\t\tPy_INCREF(*((PyObject **)loop->idptr));\n\t\t\tmemcpy(loop->bufptr[1], loop->idptr, loop->outsize);\n\t\t\tloop->bufptr[1] += loop->outsize;\n\t\t} \n break;\n case ONEDIM_REDUCELOOP: /* Accumulate */\n\t\t/* fprintf(stderr, \"ONEDIM..%d\\n\", loop->size); */\n while(loop->index < loop->size) {\n\t\t\tif (loop->obj) \n\t\t\t\tPy_INCREF(*((PyObject **)loop->it->dataptr));\n memcpy(loop->bufptr[1], loop->it->dataptr, \n loop->outsize);\n\t\t\tPyArray_ITER_NEXT(loop->it);\n\t\t\tloop->bufptr[1] += loop->outsize;\n\t\t\tloop->index++;\n\t\t}\t\t\n\t\tbreak;\n case NOBUFFER_UFUNCLOOP: /* Accumulate */\n\t\t/* fprintf(stderr, \"NOBUFFER..%d\\n\", loop->size); */\n while(loop->index < loop->size) {\n\t\t\t/* Copy first element to output */\n\t\t\tif (loop->obj) \n\t\t\t\tPy_INCREF(*((PyObject **)loop->it->dataptr));\n memcpy(loop->bufptr[1], loop->it->dataptr, \n loop->outsize);\n\t\t\t/* Adjust input pointer */\n loop->bufptr[0] = loop->it->dataptr+loop->steps[0];\n loop->function((char **)loop->bufptr, \n\t\t\t\t &(loop->N),\n loop->steps, loop->funcdata);\n\t\t\tUFUNC_CHECK_ERROR(loop);\n\n PyArray_ITER_NEXT(loop->it);\n\t\t\tPyArray_ITER_NEXT(loop->rit);\n loop->bufptr[1] = loop->rit->dataptr;\n\t\t\tloop->bufptr[2] = loop->bufptr[1] + loop->steps[1];\n loop->index++;\n }\n break;\n case BUFFER_UFUNCLOOP: /* Accumulate */\n /* use buffer for arr */\n /* \n For each row to reduce\n 1. copy identity over to output (casting if necessary)\n 2. Fill inner buffer \n 3. When buffer is filled or end of row\n a. Cast input buffers if needed\n b. Call inner function.\n 4. Repeat 2 until row is done.\n */\n\t\t/* fprintf(stderr, \"BUFFERED..%d %p\\n\", loop->size, \n\t\t loop->cast); */\n while(loop->index < loop->size) {\n loop->inptr = loop->it->dataptr;\t\t\t\n\t\t\t/* Copy (cast) First term over to output */\n\t\t\tif (loop->cast) {\n\t\t\t\t/* A little tricky because we need to\n\t\t\t\t cast it first */\n\t\t\t\tarr->descr->f->copyswap(loop->buffer,\n\t\t\t\t\t\t loop->inptr,\n\t\t\t\t\t\t loop->swap,\n\t\t\t\t\t\t loop->insize);\n\t\t\t\tloop->cast(loop->buffer, loop->castbuf,\n\t\t\t\t\t 1, NULL, NULL);\n\t\t\t\tif (loop->obj) \n\t\t\t\t\tPy_INCREF(*((PyObject **)loop->castbuf));\n\t\t\t\tmemcpy(loop->bufptr[1], loop->castbuf,\n\t\t\t\t loop->outsize);\n\t\t\t}\n\t\t\telse { /* Simple copy */\n\t\t\t\tarr->descr->f->copyswap(loop->bufptr[1], \n\t\t\t\t\t\t loop->inptr,\n\t\t\t\t\t\t loop->swap,\n\t\t\t\t\t\t loop->insize);\n\t\t\t}\n\t\t\tloop->inptr += loop->instrides;\n n = 1;\n while(n < loop->N) {\n /* Copy up to loop->bufsize elements to \n buffer */\n dptr = loop->buffer;\n for (i=0; ibufsize; i++, n++) {\n if (n == loop->N) break;\n arr->descr->f->copyswap(dptr,\n loop->inptr,\n loop->swap,\n loop->insize);\n loop->inptr += loop->instrides;\n dptr += loop->insize;\n }\n if (loop->cast)\n loop->cast(loop->buffer,\n loop->castbuf,\n i, NULL, NULL);\n loop->function((char **)loop->bufptr,\n &i, \n\t\t\t\t\t loop->steps, loop->funcdata);\n\t\t\t\tUFUNC_CHECK_ERROR(loop);\n } \n PyArray_ITER_NEXT(loop->it);\n\t\t\tPyArray_ITER_NEXT(loop->rit);\n loop->bufptr[1] = loop->rit->dataptr;\n\t\t\tloop->bufptr[2] = loop->bufptr[1] + loop->steps[1];\n loop->index++;\n }\n }\n\n\tLOOP_END_THREADS\n ret = loop->ret;\n\t/* Hang on to this reference -- will be decref'd with loop */\n Py_INCREF(ret);\n ufuncreduce_dealloc(loop);\n return (PyObject *)ret;\n\n fail:\n\tLOOP_END_THREADS\n\n if (loop) ufuncreduce_dealloc(loop);\n return NULL;\n}\n\n/* Reduceat performs a reduce over an axis using the indices as a guide\n\nop.reduceat(array,indices) computes\nop.reduce(array[indices[i]:indices[i+1]] \n for i=0..end with an implicit indices[i+1]=len(array)\n assumed when i=end-1\n\nif indices[i+1] <= indices[i]+1 \n then the result is array[indices[i]] for that value\n\nop.accumulate(array) is the same as\nop.reduceat(array,indices)[::2]\nwhere indices is range(len(array)-1) with a zero placed in every other sample\n indices = zeros(len(array)*2-1)\n indices[1::2] = range(1,len(array))\n\noutput shape is based on the size of indices\n */\n\nstatic PyObject *\nPyUFunc_Reduceat(PyUFuncObject *self, PyArrayObject *arr, PyArrayObject *ind, \n int axis, int otype)\n{\t\n\tPyArrayObject *ret;\n PyUFuncReduceObject *loop;\n\tintp *ptr=(intp *)ind->data;\n\tintp nn=ind->dimensions[0];\t\t\n\tintp mm=arr->dimensions[axis]-1;\n\tintp n, i, j;\n\tchar *dptr;\n\n\t/* Check for out-of-bounds values in indices array */\t\t\n\tfor (i=0; i mm)) {\n\t\t\tPyErr_Format(PyExc_IndexError, \n\t\t\t\t \"index out-of-bounds (0, %d)\", (int) mm);\n\t\t\treturn NULL;\n\t\t}\n\t\tptr++;\n\t}\n\t\n\tptr = (intp *)ind->data;\n /* Construct loop object */\n loop = construct_reduce(self, &arr, axis, otype, UFUNC_REDUCEAT, nn,\n\t\t\t\t\"reduceat\");\n\tif (!loop) return NULL;\n\n\tLOOP_BEGIN_THREADS\n\tswitch(loop->meth) {\n\t/* zero-length index -- return array immediately */\n\tcase ZERODIM_REDUCELOOP:\n\t\t/* fprintf(stderr, \"ZERO..\\n\"); */\n\t\tbreak;\n\t/* NOBUFFER -- behaved array and same type */\n\tcase NOBUFFER_UFUNCLOOP: \t /* Reduceat */\n\t\t/* fprintf(stderr, \"NOBUFFER..%d\\n\", loop->size); */\n\t\twhile(loop->index < loop->size) {\n\t\t\tptr = (intp *)ind->data;\n\t\t\tfor (i=0; ibufptr[0] = loop->it->dataptr +\t\\\n\t\t\t\t\t(*ptr)*loop->instrides;\n\t\t\t\tif (loop->obj) \n\t\t\t\t\tPy_INCREF(*((PyObject **)loop->bufptr[0]));\n\t\t\t\tmemcpy(loop->bufptr[1], loop->bufptr[0],\n\t\t\t\t loop->outsize);\n\t\t\t\tmm = (i==nn-1 ? arr->dimensions[axis]-*ptr : \\\n\t\t\t\t *(ptr+1) - *ptr) - 1;\n\t\t\t\tif (mm > 0) {\n\t\t\t\t\tloop->bufptr[0] += loop->instrides;\n\t\t\t\t\tloop->bufptr[2] = loop->bufptr[1];\n\t\t\t\t\tloop->function((char **)loop->bufptr,\n\t\t\t\t\t\t &mm, loop->steps,\n\t\t\t\t\t\t loop->funcdata);\n\t\t\t\t\tUFUNC_CHECK_ERROR(loop);\n\t\t\t\t}\t\n\t\t\t\tloop->bufptr[1] += loop->ret->strides[axis];\n\t\t\t\tptr++;\n\t\t\t}\n\t\t\tPyArray_ITER_NEXT(loop->it);\n\t\t\tPyArray_ITER_NEXT(loop->rit);\n\t\t\tloop->bufptr[1] = loop->rit->dataptr;\n\t\t\tloop->index++;\n\t\t}\n\t\tbreak;\n\n\t/* BUFFER -- misbehaved array or different types */ \n\tcase BUFFER_UFUNCLOOP: /* Reduceat */\n\t\t/* fprintf(stderr, \"BUFFERED..%d\\n\", loop->size); */\n\t\twhile(loop->index < loop->size) {\n\t\t\tptr = (intp *)ind->data;\n\t\t\tfor (i=0; iobj) \n\t\t\t\t\tPy_INCREF(*((PyObject **)loop->idptr));\n\t\t\t\tmemcpy(loop->bufptr[1], loop->idptr, \n\t\t\t\t loop->outsize);\n\t\t\t\tn = 0;\n\t\t\t\tmm = (i==nn-1 ? arr->dimensions[axis] - *ptr :\\\n\t\t\t\t *(ptr+1) - *ptr);\n\t\t\t\tif (mm < 1) mm = 1;\n\t\t\t\tloop->inptr = loop->it->dataptr + \\\n\t\t\t\t\t(*ptr)*loop->instrides;\n\t\t\t\twhile (n < mm) {\n\t\t\t\t\t/* Copy up to loop->bufsize elements\n\t\t\t\t\t to buffer */\n\t\t\t\t\tdptr = loop->buffer;\n\t\t\t\t\tfor (j=0; jbufsize; j++, n++) {\n\t\t\t\t\t\tif (n == mm) break;\n\t\t\t\t\t\tarr->descr->f->copyswap\\\n\t\t\t\t\t\t\t(dptr,\n\t\t\t\t\t\t\t loop->inptr,\n\t\t\t\t\t\t\t loop->swap,\n\t\t\t\t\t\t\t loop->insize);\n\t\t\t\t\t\tloop->inptr += loop->instrides;\n\t\t\t\t\t\tdptr += loop->insize;\n\t\t\t\t\t}\n\t\t\t\t\tif (loop->cast)\n\t\t\t\t\t\tloop->cast(loop->buffer,\n\t\t\t\t\t\t\t loop->castbuf,\n\t\t\t\t\t\t\t j, NULL, NULL);\n\t\t\t\t\tloop->bufptr[2] = loop->bufptr[1];\n\t\t\t\t\tloop->function((char **)loop->bufptr,\n\t\t\t\t\t\t &j, loop->steps,\n\t\t\t\t\t\t loop->funcdata);\n\t\t\t\t\tUFUNC_CHECK_ERROR(loop);\n\t\t\t\t} \n\t\t\t\tloop->bufptr[1] += loop->ret->strides[axis];\n\t\t\t\tptr++;\n\t\t\t}\n\t\t\tPyArray_ITER_NEXT(loop->it);\n\t\t\tPyArray_ITER_NEXT(loop->rit);\n\t\t\tloop->bufptr[1] = loop->rit->dataptr;\n\t\t\tloop->index++;\n\t\t}\n\t\tbreak;\n\t}\n\n\tLOOP_END_THREADS\n\t\n ret = loop->ret;\n\t/* Hang on to this reference -- will be decref'd with loop */\n Py_INCREF(ret);\n ufuncreduce_dealloc(loop);\n return (PyObject *)ret;\n\t\n fail:\n\tLOOP_END_THREADS\n\n if (loop) ufuncreduce_dealloc(loop);\n\treturn NULL;\n}\n\n\n/* This code handles reduce, reduceat, and accumulate \n (accumulate and reduce are special cases of the more general reduceat \n but they are handled separately for speed) \n*/\n\nstatic PyObject * \nPyUFunc_GenericReduction(PyUFuncObject *self, PyObject *args, \n PyObject *kwds, int operation) \n{\n\tint axis=0;\n\tPyArrayObject *mp, *ret = NULL;\n\tPyObject *op, *res=NULL;\n\tPyObject *obj_ind, *context; \n\tPyArrayObject *indices = NULL;\n\tPyArray_Descr *otype=NULL;\n\tstatic char *kwlist1[] = {\"array\", \"axis\", \"dtype\", NULL};\n\tstatic char *kwlist2[] = {\"array\", \"indices\", \"axis\", \"dtype\", NULL}; \n static char *_reduce_type[] = {\"reduce\", \"accumulate\", \\\n\t\t\t\t \"reduceat\", NULL};\n\tif (self == NULL) {\n\t\tPyErr_SetString(PyExc_ValueError, \"function not supported\");\n\t\treturn NULL;\n\t}\t\n\n\tif (self->nin != 2) {\n\t\tPyErr_Format(PyExc_ValueError, \n \"%s only supported for binary functions\",\n _reduce_type[operation]);\n\t\treturn NULL;\n\t}\n\tif (self->nout != 1) {\n\t\tPyErr_Format(PyExc_ValueError,\n \"%s only supported for functions \" \\\n \"returning a single value\",\n _reduce_type[operation]);\n\t\treturn NULL;\n\t}\n\n\tif (operation == UFUNC_REDUCEAT) {\n\t\tPyArray_Descr *indtype;\n\t\tindtype = PyArray_DescrFromType(PyArray_INTP);\n\t\tif(!PyArg_ParseTupleAndKeywords(args, kwds, \"OO|iO&\", kwlist2, \n\t\t\t\t\t\t&op, &obj_ind, &axis, \n\t\t\t\t\t\tPyArray_DescrConverter, \n\t\t\t\t\t\t&otype)) return NULL;\n indices = (PyArrayObject *)PyArray_FromAny(obj_ind, indtype, \n\t\t\t\t\t\t\t 1, 1, CARRAY_FLAGS, NULL);\n if (indices == NULL) return NULL;\n\t\tPy_DECREF(indtype);\t\t\n\t}\n\telse {\n\t\tif(!PyArg_ParseTupleAndKeywords(args, kwds, \"O|iO&\", kwlist1,\n\t\t\t\t\t\t&op, &axis, \n\t\t\t\t\t\tPyArray_DescrConverter, \n\t\t\t\t\t\t&otype)) return NULL;\n\t}\n\t\n\t/* Ensure input is an array */\t\n if (!PyArray_Check(op) && !PyArray_IsScalar(op, Generic)) {\n context = Py_BuildValue(\"O(O)i\", self, op, 0);\n }\n else {\n context = NULL;\n }\n\tmp = (PyArrayObject *)PyArray_FromAny(op, NULL, 0, 0, 0, context);\n Py_XDECREF(context);\n\tif (mp == NULL) return NULL;\n\n /* Check to see if input is zero-dimensional */\n if (mp->nd == 0) {\n PyErr_Format(PyExc_TypeError, \"cannot %s on a scalar\",\n _reduce_type[operation]);\n Py_DECREF(mp);\n return NULL; \n }\n\n /* Check to see that type (and otype) is not FLEXIBLE */\n\tif (PyArray_ISFLEXIBLE(mp) || (otype && PyTypeNum_ISFLEXIBLE(otype->type_num))) {\n PyErr_Format(PyExc_TypeError, \n\t\t\t \"cannot perform %s with flexible type\",\n _reduce_type[operation]);\n Py_DECREF(mp);\n return NULL;\n }\n\n\tif (axis < 0) axis += mp->nd;\n\tif (axis < 0 || axis >= mp->nd) {\n\t\tPyErr_SetString(PyExc_ValueError, \"axis not in array\");\n Py_DECREF(mp);\n\t\treturn NULL;\n\t}\n\n\t/* Get default type to reduce over if not given */\n if (otype == NULL) {\n\t\t/* For integer types --- makes sure at \n\t\t least a long is used */\n\t\tint typenum = PyArray_TYPE(mp);\n\t\tif (PyTypeNum_ISINTEGER(typenum) &&\t\\\n\t\t (mp->descr->elsize < sizeof(long))) {\n\t\t\tif (PyTypeNum_ISUNSIGNED(typenum))\n\t\t\t\ttypenum = PyArray_ULONG;\n\t\t\telse\n\t\t\t\ttypenum = PyArray_LONG;\n\t\t}\n\t\telse if (PyTypeNum_ISBOOL(typenum) && \\\n\t\t\t ((strcmp(self->name,\"add\")==0) ||\t\\\n\t\t\t (strcmp(self->name,\"multiply\")==0))) {\n\t\t\ttypenum = PyArray_LONG;\n\t\t}\n\t\totype = PyArray_DescrFromType(typenum);\n\t}\n\n switch(operation) {\n case UFUNC_REDUCE:\n ret = (PyArrayObject *)PyUFunc_Reduce(self, mp, axis, \n otype->type_num);\n\t\tbreak;\n case UFUNC_ACCUMULATE:\n ret = (PyArrayObject *)PyUFunc_Accumulate(self, mp, axis, \n otype->type_num);\n\t\tbreak;\n case UFUNC_REDUCEAT:\n ret = (PyArrayObject *)PyUFunc_Reduceat(self, mp, indices, \n axis, otype->type_num);\n Py_DECREF(indices);\n\t\tbreak;\n }\n Py_DECREF(mp);\n\tPy_DECREF(otype);\n\tif (ret==NULL) return NULL;\n\tif (op->ob_type != ret->ob_type) {\n\t\tres = PyObject_CallMethod(op, \"__array_wrap__\", \"O\", ret);\n\t\tif (res == NULL) PyErr_Clear();\n\t\telse if (res == Py_None) Py_DECREF(res);\n\t\telse {\n\t\t\tPy_DECREF(ret);\n\t\t\treturn res;\n\t\t}\t\n\t}\n\treturn PyArray_Return(ret);\n\t\n}\n\nstatic PyObject *\n_find_array_wrap(PyObject *args)\n{\n\tint nargs, i;\n\tint np = 0;\n\tdouble priority, maxpriority;\n\tPyObject *with_wrap[MAX_ARGS], *wraps[MAX_ARGS];\n\tPyObject *obj, *wrap = NULL;\n\n\tnargs = PyTuple_GET_SIZE(args);\n\tfor (i=0; i maxpriority) {\n\t\t\tmaxpriority = priority;\n\t\t\tPy_DECREF(wrap);\n\t\t\twrap = wraps[i];\n\t\t} else {\n\t\t\tPy_DECREF(wraps[i]);\n\t\t}\n\t}\n\treturn wrap;\n}\n\nstatic PyObject *\nufunc_generic_call(PyUFuncObject *self, PyObject *args) \n{\n\tint i;\n\tPyTupleObject *ret;\n\tPyArrayObject *mps[MAX_ARGS];\n\tPyObject *retobj[MAX_ARGS];\n\tPyObject *res;\n\tPyObject *wrap;\n int errval;\n \n\t/* Initialize all array objects to NULL to make cleanup easier \n\t if something goes wrong. */\n\tfor(i=0; inargs; i++) mps[i] = NULL;\n\t\n errval = PyUFunc_GenericFunction(self, args, mps);\n if (errval < 0) {\n\t\tfor(i=0; inargs; i++) Py_XDECREF(mps[i]);\n\t\tif (errval == -1)\n\t\t\treturn NULL;\n\t\telse {\n\t\t\tPy_INCREF(Py_NotImplemented);\n\t\t\treturn Py_NotImplemented;\n\t\t}\n }\n\t\n\tfor(i=0; inin; i++) Py_DECREF(mps[i]);\n\n\t/* Use __array_wrap__ on all outputs \n\t if present on one of the input arguments.\n\t If present for multiple inputs:\n\t use __array_wrap__ of input object with largest \n\t\t__array_priority__ (default = 0.0)\n\t */\n\twrap = _find_array_wrap(args);\n\t\n\t/* wrap outputs */\n\tfor (i=0; inout; i++) {\n\t\tint j=self->nin+i;\n\t\t/* check to see if any UPDATEIFCOPY flags are set \n\t\t which meant that a temporary output was generated \n\t\t*/\n\t\tif (mps[j]->flags & UPDATEIFCOPY) {\n\t\t\tPyObject *old = mps[j]->base;\n\t\t\tPy_INCREF(old); /* we want to hang on to this */\n\t\t\tPy_DECREF(mps[j]); /* should trigger the copy \n\t\t\t\t\t back into old */\n\t\t\tmps[j] = (PyArrayObject *)old;\n\t\t}\n\t\tif (wrap != NULL) {\n\t\t\tres = PyObject_CallFunction(wrap, \"O(OOi)\",\n\t\t\t\t\t\t mps[j], self, args, i);\n\t\t\tif (res == NULL && PyErr_ExceptionMatches(PyExc_TypeError)) {\n\t\t\t\tPyErr_Clear();\n\t\t\t\tres = PyObject_CallFunctionObjArgs(wrap, mps[j], NULL);\n\t\t\t}\n\t\t\tPy_DECREF(wrap);\n\t\t\tif (res == NULL) goto fail;\n\t\t\telse if (res == Py_None) Py_DECREF(res);\n\t\t\telse {\n\t\t\t\tPy_DECREF(mps[j]);\n\t\t\t\tretobj[i] = res;\n\t\t\t\tcontinue;\n\t\t\t}\n\t\t}\n\t\tretobj[i] = PyArray_Return(mps[j]);\n\t}\n\t\n\tif (self->nout == 1) { \n\t\treturn retobj[0];\n\t} else { \n\t\tret = (PyTupleObject *)PyTuple_New(self->nout);\n\t\tfor(i=0; inout; i++) {\n\t\t\tPyTuple_SET_ITEM(ret, i, retobj[i]);\n\t\t}\n\t\treturn (PyObject *)ret;\n\t}\n fail:\n\tfor(i=self->nin; inargs; i++) Py_XDECREF(mps[i]);\n\treturn NULL;\n}\n\nstatic PyObject *\nufunc_update_use_defaults(PyObject *dummy, PyObject *args)\n{\n\tPyObject *errobj;\n\tint errmask, bufsize;\n\n\tif (!PyArg_ParseTuple(args, \"\")) return NULL;\n\t\n\tPyUFunc_USEDEFAULTS = 0;\n\tif (PyUFunc_GetPyValues(\"test\", &bufsize, &errmask, &errobj) < 0) return NULL;\n\t\n\tif ((errmask == UFUNC_ERR_DEFAULT) &&\t\t\\\n\t (bufsize == PyArray_BUFSIZE) &&\t\t\\\n\t (PyTuple_GET_ITEM(errobj, 1) == Py_None)) {\n\t\tPyUFunc_USEDEFAULTS = 1;\n\t}\n\t\n\tPy_INCREF(Py_None);\n\treturn Py_None;\n}\n\nstatic PyUFuncGenericFunction pyfunc_functions[] = {PyUFunc_On_Om};\n\nstatic char \ndoc_frompyfunc[] = \"frompyfunc(func, nin, nout) take an arbitrary python function that takes nin objects as input and returns nout objects and return a universal function (ufunc). This ufunc always returns PyObject arrays\";\n\nstatic PyObject *\nufunc_frompyfunc(PyObject *dummy, PyObject *args, PyObject *kwds) {\n /* Keywords are ignored for now */\n \n PyObject *function, *pyname=NULL;\n int nin, nout, i;\n PyUFunc_PyFuncData *fdata;\n PyUFuncObject *self;\n char *fname, *str;\n int fname_len=-1;\n\tint offset[2];\n\n if (!PyArg_ParseTuple(args, \"Oii\", &function, &nin, &nout)) return NULL;\n\n if (!PyCallable_Check(function)) {\n PyErr_SetString(PyExc_TypeError, \"function must be callable\");\n return NULL;\n }\n\t\n self = _pya_malloc(sizeof(PyUFuncObject));\n if (self == NULL) return NULL;\n PyObject_Init((PyObject *)self, &PyUFunc_Type);\n\n\tself->userloops = NULL;\n\tself->nin = nin;\n\tself->nout = nout;\n\tself->nargs = nin+nout;\n\tself->identity = PyUFunc_None;\t\n\tself->functions = pyfunc_functions;\n\n\tself->ntypes = 1;\n\tself->check_return = 0;\n\n pyname = PyObject_GetAttrString(function, \"__name__\");\n if (pyname)\n (void) PyString_AsStringAndSize(pyname, &fname, &fname_len);\n \n if (PyErr_Occurred()) {\n fname = \"?\";\n fname_len = 1;\n PyErr_Clear();\n } \n Py_XDECREF(pyname);\n\n\n\n\t/* self->ptr holds a pointer for enough memory for\n\t self->data[0] (fdata)\n\t self->data\n\t self->name\n\t self->types\n\n\t To be safest, all of these need their memory aligned on void * pointers\n\t Therefore, we may need to allocate extra space.\n\t*/\n\toffset[0] = sizeof(PyUFunc_PyFuncData);\n\ti = (sizeof(PyUFunc_PyFuncData) % sizeof(void *));\n\tif (i) offset[0] += (sizeof(void *) - i);\n\toffset[1] = self->nargs;\n\ti = (self->nargs % sizeof(void *));\n\tif (i) offset[1] += (sizeof(void *)-i);\n\n self->ptr = _pya_malloc(offset[0] + offset[1] + sizeof(void *) + \\\n\t\t\t (fname_len+14));\n\n\tif (self->ptr == NULL) return PyErr_NoMemory();\n Py_INCREF(function);\n self->obj = function;\n\tfdata = (PyUFunc_PyFuncData *)(self->ptr);\n fdata->nin = nin;\n fdata->nout = nout;\n fdata->callable = function;\n \n self->data = (void **)(self->ptr + offset[0]);\n self->data[0] = (void *)fdata;\n\t\n\tself->types = (char *)self->data + sizeof(void *);\n for (i=0; inargs; i++) self->types[i] = PyArray_OBJECT;\n\n str = self->types + offset[1];\n memcpy(str, fname, fname_len);\n memcpy(str+fname_len, \" (vectorized)\", 14);\n \n self->name = str;\n\n /* Do a better job someday */\n self->doc = \"dynamic ufunc based on a python function\";\n \n\t\n\treturn (PyObject *)self;\n}\n\n\n/*UFUNC_API*/\nstatic PyObject *\nPyUFunc_FromFuncAndData(PyUFuncGenericFunction *func, void **data, \n\t\t\tchar *types, int ntypes,\n\t\t\tint nin, int nout, int identity, \n\t\t\tchar *name, char *doc, int check_return) \n{\n\tPyUFuncObject *self;\n\n self = _pya_malloc(sizeof(PyUFuncObject));\n if (self == NULL) return NULL;\n PyObject_Init((PyObject *)self, &PyUFunc_Type);\n\t\n\tself->nin = nin;\n\tself->nout = nout;\n\tself->nargs = nin+nout;\n\tself->identity = identity;\n\t\n\tself->functions = func;\n\tself->data = data;\n\tself->types = types;\n\tself->ntypes = ntypes;\n\tself->check_return = check_return;\n self->ptr = NULL;\n self->obj = NULL;\n\tself->userloops=NULL;\n\t\n\tif (name == NULL) self->name = \"?\";\n\telse self->name = name;\n\t\n if (doc == NULL) self->doc = \"NULL\";\n\telse self->doc = doc;\n\t\n\treturn (PyObject *)self;\n}\n\n/*UFUNC_API*/\nstatic int\nPyUFunc_RegisterLoopForType(PyUFuncObject *ufunc, \n\t\t\t int usertype,\n\t\t\t PyUFuncGenericFunction function,\n\t\t\t void *data)\n{\n\tPyArray_Descr *descr;\n \tPyObject *key, *cobj;\n\tint ret;\t\n\t\n\tdescr=PyArray_DescrFromType(usertype);\n\tif ((usertype < PyArray_USERDEF) || (descr==NULL)) {\n\t\tPyErr_SetString(PyExc_TypeError, \n\t\t\t\t\"unknown type\");\n\t\treturn -1;\n\t}\n\tPy_DECREF(descr);\n\t\n\tif (ufunc->userloops == NULL) {\n\t\tufunc->userloops = PyDict_New();\n\t}\n\tkey = PyInt_FromLong((long) usertype);\n\tif (key == NULL) return -1;\n\tcobj = PyCObject_FromVoidPtr((void *)function, NULL);\n\tif (cobj == NULL) {Py_DECREF(key); return -1;}\n\tif (data == NULL) {\n\t\tret = PyDict_SetItem(ufunc->userloops, key, cobj);\n\t\tPy_DECREF(cobj);\n\t\tPy_DECREF(key);\n\t\treturn ret;\n\t}\n\telse {\n\t\tPyObject *cobj2, *tmp;\n\t\tcobj2 = PyCObject_FromVoidPtr(data, NULL);\n\t\tif (cobj2 == NULL) {\n\t\t\tPy_DECREF(cobj); \n\t\t\tPy_DECREF(key);\n\t\t\treturn -1;\n\t\t}\n\t\ttmp=Py_BuildValue(\"NN\", cobj, cobj2);\n\t\tret = PyDict_SetItem(ufunc->userloops, key, tmp);\n\t\tPy_DECREF(tmp);\n\t\tPy_DECREF(key);\n\t\treturn ret;\n\t}\n}\n\nstatic void\nufunc_dealloc(PyUFuncObject *self)\n{\n if (self->ptr) _pya_free(self->ptr);\n\tPy_XDECREF(self->userloops);\n Py_XDECREF(self->obj);\n _pya_free(self);\n}\n\nstatic PyObject *\nufunc_repr(PyUFuncObject *self)\n{\n\tchar buf[100];\n\t\n\tsprintf(buf, \"\", self->name);\n\t\n\treturn PyString_FromString(buf);\n}\n\n\n/* -------------------------------------------------------- */\n\n/* op.outer(a,b) is equivalent to op(a[:,NewAxis,NewAxis,etc.],b)\n where a has b.ndim NewAxis terms appended.\n\n The result has dimensions a.ndim + b.ndim\n */\n\nstatic PyObject *\nufunc_outer(PyUFuncObject *self, PyObject *args) \n{\n\tint i;\n\tPyObject *ret;\n\tPyArrayObject *ap1=NULL, *ap2=NULL, *ap_new=NULL;\n\tPyObject *new_args, *tmp;\n\tPyObject *shape1, *shape2, *newshape;\n\n\tif(self->nin != 2) {\n\t\tPyErr_SetString(PyExc_ValueError,\n\t\t\t\t\"outer product only supported \"\\\n\t\t\t\t\"for binary functions\");\n\t\treturn NULL;\n\t}\n\t\n\tif (PySequence_Length(args) != 2) {\n\t\tPyErr_SetString(PyExc_TypeError,\n\t\t\t\t\"exactly two arguments expected\");\n\t\treturn NULL;\n\t}\n\t\n\ttmp = PySequence_GetItem(args, 0);\n\tif (tmp == NULL) return NULL;\n\tap1 = (PyArrayObject *)\t\t\t\t\t\\\n\t\tPyArray_FromObject(tmp, PyArray_NOTYPE, 0, 0);\n\tPy_DECREF(tmp);\n\tif (ap1 == NULL) return NULL;\n\t\n\ttmp = PySequence_GetItem(args, 1);\n\tif (tmp == NULL) return NULL;\n\tap2 = (PyArrayObject *)PyArray_FromObject(tmp, PyArray_NOTYPE, 0, 0);\n\tPy_DECREF(tmp);\n\tif (ap2 == NULL) {Py_DECREF(ap1); return NULL;}\n\n\t/* Construct new shape tuple */\n\tshape1 = PyTuple_New(ap1->nd);\n\tif (shape1 == NULL) goto fail;\n\tfor (i=0; ind; i++) \n\t\tPyTuple_SET_ITEM(shape1, i, \n\t\t\t\t PyLong_FromLongLong((longlong)ap1->\t\\\n\t\t\t\t\t\t dimensions[i]));\n\t\n\tshape2 = PyTuple_New(ap2->nd);\n\tfor (i=0; ind; i++) \n\t\tPyTuple_SET_ITEM(shape2, i, PyInt_FromLong((long) 1));\n\tif (shape2 == NULL) {Py_DECREF(shape1); goto fail;}\n\tnewshape = PyNumber_Add(shape1, shape2);\n\tPy_DECREF(shape1);\n\tPy_DECREF(shape2);\n\tif (newshape == NULL) goto fail;\n\t\n\tap_new = (PyArrayObject *)PyArray_Reshape(ap1, newshape);\n\tPy_DECREF(newshape);\n\tif (ap_new == NULL) goto fail;\n\t\n\tnew_args = Py_BuildValue(\"(OO)\", ap_new, ap2);\n\tPy_DECREF(ap1);\n\tPy_DECREF(ap2);\n\tPy_DECREF(ap_new);\t\n\tret = ufunc_generic_call(self, new_args);\n\tPy_DECREF(new_args);\n\treturn ret;\n\n fail:\n\tPy_XDECREF(ap1);\n\tPy_XDECREF(ap2);\n\tPy_XDECREF(ap_new);\n\treturn NULL;\n\n}\n\n\nstatic PyObject *\nufunc_reduce(PyUFuncObject *self, PyObject *args, PyObject *kwds) \n{\n\t\n\treturn PyUFunc_GenericReduction(self, args, kwds, UFUNC_REDUCE);\n}\n\nstatic PyObject *\nufunc_accumulate(PyUFuncObject *self, PyObject *args, PyObject *kwds) \n{\n\t\n\treturn PyUFunc_GenericReduction(self, args, kwds, UFUNC_ACCUMULATE);\n}\n\nstatic PyObject *\nufunc_reduceat(PyUFuncObject *self, PyObject *args, PyObject *kwds) \n{\t\n\treturn PyUFunc_GenericReduction(self, args, kwds, UFUNC_REDUCEAT);\n}\n\n\nstatic struct PyMethodDef ufunc_methods[] = {\n\t{\"reduce\", (PyCFunction)ufunc_reduce, METH_VARARGS | METH_KEYWORDS},\n\t{\"accumulate\", (PyCFunction)ufunc_accumulate, \n\t METH_VARARGS | METH_KEYWORDS},\n\t{\"reduceat\", (PyCFunction)ufunc_reduceat, \n\t METH_VARARGS | METH_KEYWORDS},\t\n\t{\"outer\", (PyCFunction)ufunc_outer, METH_VARARGS},\n\t{NULL,\t\tNULL}\t\t/* sentinel */\n};\n\n\n\n/* construct the string\n y1,y2,...,yn\n*/\n\nstatic void\n_makeargs(int num, char ltr, char *str) \n{\n\tint ind=0;\n\tint k;\n\tstatic char *digits=\"123456789ABCDE\";\n\n\tif (num == 1) {\n\t\tstr[0] = ltr;\n\t\tind = 1;\n\t}\n\telse {\n\t\tfor (k=0; ktype;\n\tPy_DECREF(descr);\n\treturn ret;\n} \n\nstatic PyObject *\nufunc_getattr(PyUFuncObject *self, char *name)\n{\n\tPyObject *obj;\n\t/* Put docstring first or FindMethod finds it...*/\n\t/* could so some introspection on name and nin + nout */\n\t/* to automate the first part of it */\n\t/* the doc string shouldn't need the calling convention */\n\tif (strcmp(name, \"__doc__\") == 0) {\n\t\tstatic char doc[256];\n\t\tstatic char tmp1[3*MAX_ARGS+2];\n\t\tstatic char tmp2[3*MAX_ARGS+2];\n\t\t/* construct \n\t\t y1,y2,,... = name(x1,x2,...) __doc__\n\t\t*/\t\t\n\t\t_makeargs(self->nout, 'y', tmp1);\n\t\t_makeargs(self->nin, 'x', tmp2);\n\t\tsnprintf(doc, 256, \"%s = %s(%s) %s\", tmp1, self->name, \n\t\t\t tmp2, self->doc);\n\t\treturn PyString_FromString(doc);\n\t}\n\tobj = Py_FindMethod(ufunc_methods, (PyObject *)self, name);\n\tif (obj != NULL) return obj;\n\tPyErr_Clear();\n\tif (strcmp(name, \"nin\") == 0) {\n\t\treturn PyInt_FromLong(self->nin);\n\t}\n\telse if (strcmp(name, \"nout\") == 0) {\n\t\treturn PyInt_FromLong(self->nout);\n\t}\n\telse if (strcmp(name, \"nargs\") == 0) {\n\t\treturn PyInt_FromLong(self->nargs);\n\t}\n\telse if (strcmp(name, \"ntypes\") == 0) {\n\t\treturn PyInt_FromLong(self->ntypes);\n\t}\n\telse if (strcmp(name, \"types\") == 0) {\n\t\t/* return a list with types grouped\n\t\t input->output */\n\t\tPyObject *list;\n\t\tPyObject *str;\n\t\tint k, j, n, nt=self->ntypes;\n\t\tint ni = self->nin;\n\t\tint no = self->nout;\n\t\tchar *t;\n\t\tlist = PyList_New(nt);\n\t\tif (list == NULL) return NULL;\n\t\tt = _pya_malloc(no+ni+2);\n\t\tn = 0;\n\t\tfor (k=0; ktypes[n]);\n\t\t\t\tn++;\n\t\t\t}\n\t\t\tt[ni] = '-';\n\t\t\tt[ni+1] = '>';\n\t\t\tfor (j=0; jtypes[n]);\n\t\t\t\tn++;\n\t\t\t}\n\t\t\tstr = PyString_FromStringAndSize(t, no+ni+2);\n\t\t\tPyList_SET_ITEM(list, k, str);\n\t\t}\n\t\t_pya_free(t);\n\t\treturn list;\n\t\t\n\t}\n\telse if (strcmp(name, \"__name__\") == 0) {\n\t\treturn PyString_FromString(self->name);\n\t}\n\telse if (strcmp(name, \"identity\") == 0) {\n\t\tswitch(self->identity) {\n\t\tcase PyUFunc_One:\n\t\t\treturn PyInt_FromLong(1);\n\t\tcase PyUFunc_Zero:\n\t\t\treturn PyInt_FromLong(0);\n\t\tdefault:\n\t\t\tPy_INCREF(Py_None);\n\t\t\treturn Py_None;\n\t\t}\n\t}\n\tPyErr_SetString(PyExc_AttributeError, name);\n\treturn NULL;\n}\n\n#undef _typecharfromnum\n\nstatic int\nufunc_setattr(PyUFuncObject *self, char *name, PyObject *v) \n{\n\treturn -1;\n}\n\nstatic char Ufunctype__doc__[] = \n\t\"Optimized functions make it possible to implement arithmetic \"\\\n\t\"with arrays efficiently\";\n\nstatic PyTypeObject PyUFunc_Type = {\n\tPyObject_HEAD_INIT(0)\n\t0,\t\t\t\t/*ob_size*/\n\t\"numpy.ufunc\",\t\t\t/*tp_name*/\n\tsizeof(PyUFuncObject),\t\t/*tp_basicsize*/\n\t0,\t\t\t\t/*tp_itemsize*/\n\t/* methods */\n\t(destructor)ufunc_dealloc,\t/*tp_dealloc*/\n\t(printfunc)0,\t\t /*tp_print*/\n\t(getattrfunc)ufunc_getattr,\t/*tp_getattr*/\n\t(setattrfunc)ufunc_setattr,\t/*tp_setattr*/\n\t(cmpfunc)0,\t \t/*tp_compare*/\n\t(reprfunc)ufunc_repr,\t\t/*tp_repr*/\n\t0,\t\t\t /*tp_as_number*/\n\t0,\t\t /*tp_as_sequence*/\n\t0,\t\t /*tp_as_mapping*/\n\t(hashfunc)0,\t\t/*tp_hash*/\n\t(ternaryfunc)ufunc_generic_call,\t\t/*tp_call*/\n\t(reprfunc)ufunc_repr,\t\t/*tp_str*/\n\t\t\n\t/* Space for future expansion */\n\t0L,0L,0L,0L,\n\tUfunctype__doc__ /* Documentation string */\n};\n\n/* End of code for ufunc objects */\n/* -------------------------------------------------------- */\n", + "source_code_before": "\n/*\n Python Universal Functions Object -- Math for all types, plus fast \n arrays math\n \n Full description\n \n This supports mathematical (and Boolean) functions on arrays and other python\n objects. Math on large arrays of basic C types is rather efficient.\n\n Travis E. Oliphant (2005)\n Assistant Professor\n Brigham Young University\n\n based on the \n\n Original Implementation: \n Copyright (c) 1995, 1996, 1997 Jim Hugunin, hugunin@mit.edu\n\n with inspiration and code from\n Numarray\n Space Science Telescope Institute\n J. Todd Miller\n Perry Greenfield\n Rick White\n \n*/\n\n\ntypedef double (DoubleBinaryFunc)(double x, double y);\ntypedef float (FloatBinaryFunc)(float x, float y);\ntypedef longdouble (LongdoubleBinaryFunc)(longdouble x, longdouble y);\n\ntypedef void (CdoubleBinaryFunc)(cdouble *x, cdouble *y, cdouble *res);\ntypedef void (CfloatBinaryFunc)(cfloat *x, cfloat *y, cfloat *res);\ntypedef void (ClongdoubleBinaryFunc)(clongdouble *x, clongdouble *y, \\\n\t\t\t\t clongdouble *res);\n\n/*UFUNC_API*/\nstatic void\nPyUFunc_ff_f_As_dd_d(char **args, intp *dimensions, intp *steps, void *func)\n{\n\tregister intp i, n=dimensions[0];\n\tregister intp is1=steps[0],is2=steps[1],os=steps[2];\n\tchar *ip1=args[0], *ip2=args[1], *op=args[2];\n\t\n\tfor(i=0; inin, nout=data->nout;\n int ntot;\n PyObject *tocall = data->callable; \n char *ptrs[MAX_ARGS];\n PyObject *arglist, *result;\n PyObject *in, **op;\n\n ntot = nin+nout;\n\n for (j=0; j < ntot; j++) ptrs[j] = args[j];\n\tfor(i=0; i> UFUNC_SHIFT_##NAME, \\\n\t\t\t\t\t errobj, str, retstatus) < 0) \\\n\t\t\t\treturn -1;\t\t \\\n\t\t\t}}\n\n\tif (errmask && retstatus) {\n\t\tHANDLEIT(DIVIDEBYZERO, \"divide by zero\");\n\t\tHANDLEIT(OVERFLOW, \"overflow\");\n\t\tHANDLEIT(UNDERFLOW, \"underflow\");\n\t\tHANDLEIT(INVALID, \"invalid\");\n\t}\n\n#undef HANDLEIT\n\n\treturn 0;\n}\n\n\n/* Checking the status flag clears it */\n/*UFUNC_API*/\nstatic void\nPyUFunc_clearfperr()\n{\n\tint retstatus;\n\n\tUFUNC_CHECK_STATUS(retstatus)\n}\n\n\n#define UFUNC_NOSCALAR 0\n#define UFUNC_BOOL_SCALAR 1\n#define UFUNC_INTPOS_SCALAR 2\n#define UFUNC_INTNEG_SCALAR 3\n#define UFUNC_FLOAT_SCALAR 4\n#define UFUNC_COMPLEX_SCALAR 5\n#define UFUNC_OBJECT_SCALAR 6\n\n#define NO_UFUNCLOOP 0\n#define ZERODIM_REDUCELOOP 0\n#define ONE_UFUNCLOOP 1\n#define ONEDIM_REDUCELOOP 1\n#define NOBUFFER_UFUNCLOOP 2\n#define NOBUFFER_REDUCELOOP 2\n#define BUFFER_UFUNCLOOP 3\n#define BUFFER_REDUCELOOP 3\n\n\nstatic char\n_lowest_type(char intype)\n{\n switch(intype) {\n\t/* case PyArray_BYTE */\n\tcase PyArray_SHORT:\n case PyArray_INT:\n case PyArray_LONG:\n\tcase PyArray_LONGLONG:\n\t\treturn PyArray_BYTE;\n\t/* case PyArray_UBYTE */\n case PyArray_USHORT:\n case PyArray_UINT:\n\tcase PyArray_ULONG:\n\tcase PyArray_ULONGLONG:\n\t\treturn PyArray_UBYTE;\n\t/* case PyArray_FLOAT:*/\n case PyArray_DOUBLE:\n\tcase PyArray_LONGDOUBLE:\n\t\treturn PyArray_FLOAT;\n\t/* case PyArray_CFLOAT:*/\n case PyArray_CDOUBLE:\n\tcase PyArray_CLONGDOUBLE:\n\t\treturn PyArray_CFLOAT;\n default:\n return intype;\n }\n}\n\n/* Called to determine coercion\n */\n\nstatic int \n_cancoerce(char thistype, char neededtype, char scalar) \n{\n\n\tswitch(scalar) {\n\tcase UFUNC_NOSCALAR:\n\tcase UFUNC_BOOL_SCALAR:\n\tcase UFUNC_OBJECT_SCALAR:\n\t\treturn PyArray_CanCastSafely(thistype, neededtype);\n\tcase UFUNC_INTPOS_SCALAR:\n\t\treturn (neededtype >= PyArray_UBYTE);\n\tcase UFUNC_INTNEG_SCALAR:\n\t\treturn (neededtype >= PyArray_BYTE) &&\t\t\\\n\t\t\t!(PyTypeNum_ISUNSIGNED(neededtype));\n\tcase UFUNC_FLOAT_SCALAR:\n\t\treturn (neededtype >= PyArray_FLOAT);\n\tcase UFUNC_COMPLEX_SCALAR:\n\t\treturn (neededtype >= PyArray_CFLOAT);\n\t}\n\tfprintf(stderr, \"\\n**Error** coerce fall through: %d %d %d\\n\\n\", \n\t\tthistype, neededtype, scalar);\n\treturn 1; /* should never get here... */ \n}\n\n\nstatic int \nselect_types(PyUFuncObject *self, int *arg_types, \n PyUFuncGenericFunction *function, void **data,\n\t char *scalars)\n{\n\n\tint i=0, j;\n\tchar start_type;\n\t\n\tif (PyTypeNum_ISUSERDEF((arg_types[0]))) {\n\t\tPyObject *key, *obj;\n\t\tfor (i=0; inin; i++) {\n\t\t\tif (arg_types[i] != arg_types[0]) {\n\t\t\t\tPyErr_SetString(PyExc_TypeError,\n\t\t\t\t\t\t\"ufuncs on user defined\" \\\n\t\t\t\t\t\t\" types don't support \"\\\n\t\t\t\t\t\t\"coercion\");\n\t\t\t\treturn -1;\n\t\t\t}\n\t\t}\n\t\tfor (i=self->nin; inargs; i++) {\n\t\t\targ_types[i] = arg_types[0];\n\t\t}\n\n\t\tobj = NULL;\n\t\tif (self->userloops) {\n\t\t\tkey = PyInt_FromLong((long) arg_types[0]);\n\t\t\tif (key == NULL) return -1;\n\t\t\tobj = PyDict_GetItem(self->userloops, key);\n\t\t\tPy_DECREF(key);\n\t\t}\n\t\tif (obj == NULL) {\n\t\t\tPyErr_SetString(PyExc_TypeError, \n\t\t\t\t\t\"no registered loop for this \"\t\\\n\t\t\t\t\t\"user-defined type\");\n\t\t\treturn -1;\t\t\t\n\t\t}\n\t\tif PyTuple_Check(obj) {\n\t\t\t*function = (PyUFuncGenericFunction) \\\n\t\t\t\tPyCObject_AsVoidPtr(PyTuple_GET_ITEM(obj, 0));\n\t\t\t*data = PyCObject_AsVoidPtr(PyTuple_GET_ITEM(obj, 1));\n\t\t}\n\t\telse {\n\t\t\t*function = (PyUFuncGenericFunction)\t\\\n\t\t\t\tPyCObject_AsVoidPtr(obj);\n\t\t\t*data = NULL;\n\t\t}\n Py_DECREF(obj);\n\t\treturn 0;\n\t}\n\t\n\n\tstart_type = arg_types[0];\n\t/* If the first argument is a scalar we need to place \n\t the start type as the lowest type in the class\n\t*/\n\tif (scalars[0] != UFUNC_NOSCALAR) {\n\t\tstart_type = _lowest_type(start_type);\n\t}\n\n\twhile (intypes && start_type > self->types[i*self->nargs]) \n\t\ti++;\n\n\tfor(;intypes; i++) {\n\t\tfor(j=0; jnin; j++) {\n\t\t\tif (!_cancoerce(arg_types[j], \n\t\t\t\t\tself->types[i*self->nargs+j],\n\t\t\t\t\tscalars[j]))\n\t\t\t\tbreak;\n\t\t}\n\t\tif (j == self->nin) break;\n\t}\n\tif(i>=self->ntypes) {\n\t\tPyErr_SetString(PyExc_TypeError, \n\t\t\t\t\"function not supported for these types, \"\\\n\t\t\t\t\"and can't coerce safely to supported types\");\n\t\treturn -1;\n\t}\n\tfor(j=0; jnargs; j++) \n\t\targ_types[j] = self->types[i*self->nargs+j];\n\n if (self->data)\n *data = self->data[i];\n else \n *data = NULL;\n\t*function = self->functions[i];\n\n\treturn 0;\n}\n\nstatic int PyUFunc_USEDEFAULTS=0;\n\n/*UFUNC_API*/\nstatic int\nPyUFunc_GetPyValues(char *name, int *bufsize, int *errmask, PyObject **errobj)\n{\n PyObject *thedict;\n PyObject *ref=NULL;\n\tPyObject *retval;\n\tstatic PyObject *thestring=NULL;\n\n\tif (!PyUFunc_USEDEFAULTS) {\n\t\tif (thestring == NULL) {\n\t\t\tthestring = PyString_InternFromString(UFUNC_PYVALS_NAME);\n\t\t}\n\t\tthedict = PyEval_GetLocals();\n\t\tref = PyDict_GetItem(thedict, thestring);\n\t\tif (ref == NULL) {\n\t\t\tthedict = PyEval_GetGlobals();\n\t\t\tref = PyDict_GetItem(thedict, thestring);\n\t\t}\n\t\tif (ref == NULL) {\n\t\t\tthedict = PyEval_GetBuiltins();\n\t\t\tref = PyDict_GetItem(thedict, thestring);\n\t\t}\n\t}\n\tif (ref == NULL) {\n\t\t*errmask = UFUNC_ERR_DEFAULT;\n\t\t*errobj = Py_BuildValue(\"NO\",\n\t\t\t\t\tPyString_FromString(name),\n\t\t\t\t\tPy_None);\n\t\t*bufsize = PyArray_BUFSIZE;\n\t\treturn 0;\n\t}\n\t*errobj = NULL;\n\tif (!PyList_Check(ref) || (PyList_GET_SIZE(ref)!=3)) {\n\t\tPyErr_Format(PyExc_TypeError, \"%s must be a length 3 list.\",\n\t\t\t UFUNC_PYVALS_NAME);\n\t\treturn -1;\n\t}\n\n\t*bufsize = PyInt_AsLong(PyList_GET_ITEM(ref, 0));\n\tif ((*bufsize == -1) && PyErr_Occurred()) return -1;\n\tif ((*bufsize < PyArray_MIN_BUFSIZE) ||\t\\\n\t (*bufsize > PyArray_MAX_BUFSIZE) || \\\n\t (*bufsize % 16 != 0)) {\n\t\tPyErr_Format(PyExc_ValueError, \n\t\t\t \"buffer size (%d) is not \"\t\\\n\t\t\t \"in range (%d - %d) or not a multiple of 16\", \n\t\t\t *bufsize, PyArray_MIN_BUFSIZE, \n\t\t\t PyArray_MAX_BUFSIZE);\n\t\treturn -1;\n\t}\n\n\t*errmask = PyInt_AsLong(PyList_GET_ITEM(ref, 1));\n\tif (*errmask < 0) {\n\t\tif (PyErr_Occurred()) return -1;\n\t\tPyErr_Format(PyExc_ValueError,\t\t\\\n\t\t\t \"invalid error mask (%d)\", \n\t\t\t *errmask);\n\t\treturn -1;\n\t}\n\t\n\tretval = PyList_GET_ITEM(ref, 2);\n\tif (retval != Py_None && !PyCallable_Check(retval)) {\n\t\tPyErr_SetString(PyExc_TypeError, \n\t\t\t\t\"callback function must be callable\");\n\t\treturn -1;\n\t}\n\n\t*errobj = Py_BuildValue(\"NO\", \n\t\t\t\tPyString_FromString(name),\n\t\t\t\tretval);\n\tif (*errobj == NULL) return -1;\n\t\n\treturn 0;\n}\n\n\nstatic char\n_scalar_kind(int typenum, PyArrayObject **arr) \n{\n\tif (PyTypeNum_ISSIGNED(typenum)) return UFUNC_INTNEG_SCALAR;\n\tif (PyTypeNum_ISFLOAT(typenum)) return UFUNC_FLOAT_SCALAR;\n\tif (PyTypeNum_ISCOMPLEX(typenum)) return UFUNC_COMPLEX_SCALAR;\n\tif (PyTypeNum_ISUNSIGNED(typenum)) return UFUNC_INTPOS_SCALAR;\n\tif (PyTypeNum_ISBOOL(typenum)) return UFUNC_BOOL_SCALAR;\n\treturn UFUNC_OBJECT_SCALAR;\n}\n\n\n/* Create copies for any arrays that are less than loop->bufsize\n in total size and are mis-behaved or in need\n of casting.\n*/\n\nstatic int\n_create_copies(PyUFuncLoopObject *loop, int *arg_types, PyArrayObject **mps)\n{\n\tint nin = loop->ufunc->nin;\n\tint i;\n\tintp size;\n\tPyObject *new;\n\tPyArray_Descr *ntype; \n\tPyArray_Descr *atype;\n\n\tfor (i=0; idescr;\n\t\t\tatype = PyArray_DescrFromType(arg_types[i]);\n\t\t\tif (PyArray_EquivTypes(atype, ntype)) {\n\t\t\t\targ_types[i] = ntype->type_num;\n\t\t\t}\n\t\t\tPy_DECREF(atype);\n\t\t}\n\t\tif (size < loop->bufsize) {\n\t\t\tif (!(PyArray_ISBEHAVED_RO(mps[i])) ||\t\t\\\n\t\t\t PyArray_TYPE(mps[i]) != arg_types[i]) {\n\t\t\t\tntype = PyArray_DescrFromType(arg_types[i]);\n\t\t\t\tnew = PyArray_FromAny((PyObject *)mps[i], \n\t\t\t\t\t\t ntype, 0, 0,\n\t\t\t\t\t\t FORCECAST | ALIGNED, NULL);\n\t\t\t\tif (new == NULL) return -1;\n\t\t\t\tPy_DECREF(mps[i]);\n\t\t\t\tmps[i] = (PyArrayObject *)new;\n\t\t\t}\n\t\t}\n\t}\n\t\n\treturn 0;\n}\n\n#define _GETATTR_(str, rstr) if (strcmp(name, #str) == 0) { \\\n return PyObject_HasAttrString(op, \"__\" #rstr \"__\");}\n\nstatic int\n_has_reflected_op(PyObject *op, char *name)\n{\n _GETATTR_(add, radd)\n _GETATTR_(subtract, rsub)\n _GETATTR_(multiply, rmul)\n _GETATTR_(divide, rdiv)\n _GETATTR_(true_divide, rtruediv)\n _GETATTR_(floor_divide, rfloordiv)\n _GETATTR_(remainder, rmod)\n _GETATTR_(power, rpow)\n _GETATTR_(left_shift, rrlshift)\n _GETATTR_(right_shift, rrshift)\n _GETATTR_(bitwise_and, rand)\n _GETATTR_(bitwise_xor, rxor)\n _GETATTR_(bitwise_or, ror)\n return 0;\n}\n\n#undef _GETATTR_\n\nstatic int\nconstruct_matrices(PyUFuncLoopObject *loop, PyObject *args, PyArrayObject **mps)\n{\n int nargs, i, maxsize;\n int arg_types[MAX_ARGS];\n\tchar scalars[MAX_ARGS];\n\tPyUFuncObject *self=loop->ufunc;\n\tBool allscalars=TRUE;\n\tPyTypeObject *subtype=&PyArray_Type;\n PyObject *context=NULL;\n PyObject *obj;\n\n /* Check number of arguments */\n nargs = PyTuple_Size(args);\n if ((nargs != self->nin) && (nargs != self->nargs)) {\n PyErr_SetString(PyExc_ValueError, \n\t\t\t\t\"invalid number of arguments\");\n return -1;\n }\n\n /* Get each input argument */\n for (i=0; inin; i++) {\n obj = PyTuple_GET_ITEM(args,i);\n if (!PyArray_Check(obj) && !PyArray_IsScalar(obj, Generic)) {\n context = Py_BuildValue(\"OOi\", self, args, i);\n }\n else context = NULL;\n mps[i] = (PyArrayObject *)PyArray_FromAny(obj, NULL, 0, 0, 0, context);\n Py_XDECREF(context);\n if (mps[i] == NULL) return -1;\n arg_types[i] = PyArray_TYPE(mps[i]);\n if (PyTypeNum_ISFLEXIBLE(arg_types[i])) {\n\t\t\tloop->notimplemented = 1;\n\t\t\treturn nargs;\n }\n\t\t/*\n\t\tfprintf(stderr, \"array %d has reference %d\\n\", i, \n\t\t (mps[i])->ob_refcnt);\n\t\t*/\n\n\t\t/* Scalars are 0-dimensional arrays\n\t\t at this point\n\t\t*/\n\t\tif (mps[i]->nd > 0) {\n\t\t\tscalars[i] = UFUNC_NOSCALAR;\n\t\t\tallscalars=FALSE;\n\t\t}\n\t\telse scalars[i] = _scalar_kind(arg_types[i], &(mps[i]));\n\n\t\t/* If any input is a big-array */\n\t\tif (!PyType_IsSubtype(mps[i]->ob_type, &PyArray_Type)) {\n\t\t\tsubtype = &PyBigArray_Type;\n\t\t}\n }\n\n\t/* If everything is a scalar, then use normal coercion rules */\n\tif (allscalars) {\n\t\tfor (i=0; inin; i++) {\n\t\t\tscalars[i] = UFUNC_NOSCALAR;\n\t\t}\n\t}\n \n /* Select an appropriate function for these argument types. */\n if (select_types(loop->ufunc, arg_types, &(loop->function), \n &(loop->funcdata), scalars) == -1)\n\t\treturn -1;\n\n /* FAIL with NotImplemented if the other object has \n\t the __r__ method and has __array_priority__ as \n\t an attribute (signalling it can handle ndarray's) \n\t and is not already an ndarray or bigndarray\n\t*/\n if ((arg_types[1] == PyArray_OBJECT) &&\t\t\t\t\\\n (loop->ufunc->nin==2) && (loop->ufunc->nout == 1)) {\n\t\tPyObject *_obj = PyTuple_GET_ITEM(args, 1);\n if (!PyArray_CheckExact(_obj) &&\t\t\t\\\n\t\t !PyBigArray_CheckExact(_obj) &&\t\t\t\\\n\t\t PyObject_HasAttrString(_obj, \"__array_priority__\") && \\\n\t\t _has_reflected_op(_obj, loop->ufunc->name)) {\n loop->notimplemented = 1;\n return nargs;\n }\n }\n loop->notimplemented=0;\n \n\t/* Create copies for some of the arrays if appropriate */\n\tif (_create_copies(loop, arg_types, mps) < 0) return -1;\n\t\n\t/* Create Iterators for the Inputs */\n\tfor (i=0; inin; i++) {\n loop->iters[i] = (PyArrayIterObject *)\t\t\\\n\t\t\tPyArray_IterNew((PyObject *)mps[i]);\n if (loop->iters[i] == NULL) return -1;\n\t}\n \n /* Broadcast the result */\n loop->numiter = self->nin;\n if (PyArray_Broadcast((PyArrayMultiIterObject *)loop) < 0)\n\t\treturn -1;\n\t\n /* Get any return arguments */\n for (i=self->nin; idimensions, \n\t\t\t\t\t loop->dimensions, loop->nd)) {\n PyErr_SetString(PyExc_ValueError, \n \"invalid return array shape\");\n\t\t\tPy_DECREF(mps[i]);\n mps[i] = NULL;\n return -1;\n }\n if (!PyArray_ISWRITEABLE(mps[i])) {\n PyErr_SetString(PyExc_ValueError, \n \"return array is not writeable\");\n\t\t\tPy_DECREF(mps[i]);\n mps[i] = NULL;\n return -1;\n }\n }\n\n /* construct any missing return arrays and make output iterators */\n \n for (i=self->nin; inargs; i++) {\n\t\tPyArray_Descr *ntype;\n\n if (mps[i] == NULL) {\n mps[i] = (PyArrayObject *)PyArray_New(subtype,\n loop->nd, \n loop->dimensions,\n arg_types[i], \n NULL, NULL,\n 0, 0, NULL);\n if (mps[i] == NULL) return -1;\n }\n\n\t\t/* reset types for outputs that are equivalent \n\t\t -- no sense casting uselessly\n\t\t*/\n\t\telse {\n \t\t if (mps[i]->descr->type_num != arg_types[i]) {\n\t\t\t PyArray_Descr *atype;\n\t\t\t ntype = mps[i]->descr;\n\t\t\t atype = PyArray_DescrFromType(arg_types[i]);\n\t\t\t if (PyArray_EquivTypes(atype, ntype)) {\n\t\t\t\t arg_types[i] = ntype->type_num;\n\t\t\t }\n\t\t\t Py_DECREF(atype);\n\t\t }\n\t\t \n\t\t/* still not the same -- or will we have to use buffers?*/\n\t\t if (mps[i]->descr->type_num != arg_types[i] ||\n\t\t !PyArray_ISBEHAVED_RO(mps[i])) {\n\t\t\t if (loop->size < loop->bufsize) {\n\t\t\t\t PyObject *new;\n\t\t\t\t /* Copy the array to a temporary copy \n\t\t\t\t and set the UPDATEIFCOPY flag\n\t\t\t\t */\n\t\t\t\t ntype = PyArray_DescrFromType(arg_types[i]);\n\t\t\t\t new = PyArray_FromAny((PyObject *)mps[i],\n\t\t\t\t\t\t\tntype, 0, 0,\n\t\t\t\t\t\t\tFORCECAST | ALIGNED |\n\t\t\t\t\t\t\tUPDATEIFCOPY, NULL);\n\t\t\t\t if (new == NULL) return -1;\n\t\t\t\t Py_DECREF(mps[i]);\n\t\t\t\t mps[i] = (PyArrayObject *)new;\n\t\t\t }\n\t\t }\n\t\t}\n\t\t\n loop->iters[i] = (PyArrayIterObject *)\t\t\\\n\t\t\tPyArray_IterNew((PyObject *)mps[i]);\n if (loop->iters[i] == NULL) return -1;\n }\n\n\n /* If any of different type, or misaligned or swapped\n then must use buffers */\n\n loop->bufcnt = 0;\n\n loop->obj = 0;\n\n /* Determine looping method needed */\n loop->meth = NO_UFUNCLOOP;\n\n\tmaxsize = 0;\n for (i=0; inargs; i++) {\n\t\tloop->needbuffer[i] = 0;\n if (arg_types[i] != mps[i]->descr->type_num || \n\t\t !PyArray_ISBEHAVED_RO(mps[i])) {\n loop->meth = BUFFER_UFUNCLOOP;\n\t\t\tloop->needbuffer[i] = 1;\n }\n if (!loop->obj && mps[i]->descr->type_num == PyArray_OBJECT) {\n\t\t\tloop->obj = 1;\n\t\t}\n }\n \n if (loop->meth == NO_UFUNCLOOP) {\n \n loop->meth = ONE_UFUNCLOOP;\n\n /* All correct type and BEHAVED */\n /* Check for non-uniform stridedness */\n\n for (i=0; inargs; i++) {\n if (!(loop->iters[i]->contiguous)) {\n\t\t\t\t/* may still have uniform stride\n\t\t\t\t if (broadcated result) <= 1-d */\n\t\t\t\tif (mps[i]->nd != 0 &&\t\t\t\\\n\t\t\t\t (loop->iters[i]->nd_m1 > 0)) {\n\t\t\t\t\tloop->meth = NOBUFFER_UFUNCLOOP;\n\t\t\t\t\tbreak;\n\t\t\t\t}\n\t\t\t}\n }\n\t\tif (loop->meth == ONE_UFUNCLOOP) {\n\t\t\tfor (i=0; inargs; i++) {\n\t\t\t\tloop->bufptr[i] = mps[i]->data;\n\t\t\t}\n\t\t}\n }\n\n loop->numiter = self->nargs;\n\n /* Fill in steps */\n if (loop->meth != ONE_UFUNCLOOP) {\n\t\tint ldim = 0;\n\t\tintp maxdim=-1;\n\t\tPyArrayIterObject *it;\n\n /* Fix iterators */\n\n /* Find the **largest** dimension */\n \n\t\tmaxdim = -1;\n\t\tfor (i=loop->nd - 1; i>=0; i--) {\n\t\t\tif (loop->dimensions[i] > maxdim) {\n\t\t\t\tldim = i;\n\t\t\t\tmaxdim = loop->dimensions[i];\n\t\t\t}\n\t\t}\n\n\t\tloop->size /= maxdim;\n loop->bufcnt = maxdim;\n\t\tloop->lastdim = ldim;\n\n /* Fix the iterators so the inner loop occurs over the \n\t\t largest dimensions -- This can be done by \n\t\t setting the size to 1 in that dimension \n\t\t (just in the iterators)\n */\n\n\t\tfor (i=0; inumiter; i++) {\n\t\t\tit = loop->iters[i];\n it->contiguous = 0;\n\t\t\tit->size /= (it->dims_m1[ldim]+1);\n\t\t\tit->dims_m1[ldim] = 0;\n\t\t\tit->backstrides[ldim] = 0;\n\n\t\t\t/* (won't fix factors because we\n\t\t\t don't use PyArray_ITER_GOTO1D \n\t\t\t so don't change them) */\n\n\t\t\t/* Set the steps to the strides in that dimension */\n loop->steps[i] = it->strides[ldim];\n\t\t}\n\n\t\t/* fix up steps where we will be copying data to \n\t\t buffers and calculate the ninnerloops and leftover\n\t\t values -- if step size is already zero that is not changed... \n\t\t*/\n\t\tif (loop->meth == BUFFER_UFUNCLOOP) {\n\t\t\tloop->leftover = maxdim % loop->bufsize;\n\t\t\tloop->ninnerloops = (maxdim / loop->bufsize) + 1;\n\t\t\tfor (i=0; inargs; i++) {\n\t\t\t\tif (loop->needbuffer[i] && loop->steps[i]) {\n\t\t\t\t\tloop->steps[i] = mps[i]->descr->elsize;\n\t\t\t\t}\n\t\t\t\t/* These are changed later if casting is needed */\n\t\t\t}\n\t\t}\n }\n else { /* uniformly-strided case ONE_UFUNCLOOP */\n\t\tfor (i=0; inargs; i++) {\n\t\t\tif (PyArray_SIZE(mps[i]) == 1)\n\t\t\t\tloop->steps[i] = 0;\n\t\t\telse\n\t\t\t\tloop->steps[i] = mps[i]->strides[mps[i]->nd-1];\n\t\t}\n\t}\n \n\n\t/* Finally, create memory for buffers if we need them */\n\t\n\t/* buffers for scalars are specially made small -- scalars are\n\t not copied multiple times */\n\tif (loop->meth == BUFFER_UFUNCLOOP) {\n\t\tint cnt = 0, cntcast = 0; /* keeps track of bytes to allocate */\n\t\tint scnt = 0, scntcast = 0;\n\t\tchar *castptr;\n\t\tchar *bufptr;\n\t\tint last_was_scalar=0;\n\t\tint last_cast_was_scalar=0;\n\t\tint oldbufsize=0;\n\t\tint oldsize=0;\n\t\tint scbufsize = 4*sizeof(double);\n\t\tint memsize;\n PyArray_Descr *descr;\n\n\t\t/* compute the element size */\n\t\tfor (i=0; inargs;i++) {\n\t\t\tif (!loop->needbuffer) continue;\n\t\t\tif (arg_types[i] != mps[i]->descr->type_num) {\n\t\t\t\tdescr = PyArray_DescrFromType(arg_types[i]);\n\t\t\t\tif (loop->steps[i])\n\t\t\t\t\tcntcast += descr->elsize;\n\t\t\t\telse\n\t\t\t\t\tscntcast += descr->elsize;\n\t\t\t\tif (i < self->nin) {\n\t\t\t\t\tloop->cast[i] =\t\t\t\\\n\t\t\t\t\t\tmps[i]->descr->f->cast[arg_types[i]];\n\t\t\t\t}\n\t\t\t\telse {\n\t\t\t\t\tloop->cast[i] = descr->f->\t\\\n\t\t\t\t\t\tcast[mps[i]->descr->type_num];\n\t\t\t\t}\n\t\t\t\tPy_DECREF(descr);\n\t\t\t}\n\t\t\tloop->swap[i] = !(PyArray_ISNOTSWAPPED(mps[i]));\n\t\t\tif (loop->steps[i])\n\t\t\t\tcnt += mps[i]->descr->elsize;\n\t\t\telse\n\t\t\t\tscnt += mps[i]->descr->elsize;\n\t\t}\n\t\tmemsize = loop->bufsize*(cnt+cntcast) + scbufsize*(scnt+scntcast);\n \t\tloop->buffer[0] = PyDataMem_NEW(memsize);\n\n\t\t/* fprintf(stderr, \"Allocated buffer at %p of size %d, cnt=%d, cntcast=%d\\n\", loop->buffer[0], loop->bufsize * (cnt + cntcast), cnt, cntcast); */\n\n\t\tif (loop->buffer[0] == NULL) {PyErr_NoMemory(); return -1;}\n\t\tcastptr = loop->buffer[0] + loop->bufsize*cnt + scbufsize*scnt;\n\t\tbufptr = loop->buffer[0];\n\t\tfor (i=0; inargs; i++) {\n\t\t\tif (!loop->needbuffer[i]) continue;\n\t\t\tloop->buffer[i] = bufptr + (last_was_scalar ? scbufsize : \\\n\t\t\t\t\t\t loop->bufsize)*oldbufsize;\n\t\t\tlast_was_scalar = (loop->steps[i] == 0);\n\t\t\tbufptr = loop->buffer[i];\n\t\t\toldbufsize = mps[i]->descr->elsize;\n\t\t\t/* fprintf(stderr, \"buffer[%d] = %p\\n\", i, loop->buffer[i]); */\n\t\t\tif (loop->cast[i]) {\n\t\t\t\tPyArray_Descr *descr;\n\t\t\t\tloop->castbuf[i] = castptr + (last_cast_was_scalar ? scbufsize : \\\n\t\t\t\t\t\t\t loop->bufsize)*oldsize;\n\t\t\t\tlast_cast_was_scalar = last_was_scalar;\n\t\t\t\t/* fprintf(stderr, \"castbuf[%d] = %p\\n\", i, loop->castbuf[i]); */\n\t\t\t\tdescr = PyArray_DescrFromType(arg_types[i]);\n\t\t\t\toldsize = descr->elsize;\n\t\t\t\tPy_DECREF(descr);\n\t\t\t\tloop->bufptr[i] = loop->castbuf[i];\n\t\t\t\tcastptr = loop->castbuf[i];\n\t\t\t\tif (loop->steps[i])\n\t\t\t\t\tloop->steps[i] = oldsize;\n\t\t\t}\n\t\t\telse {\n\t\t\t\tloop->bufptr[i] = loop->buffer[i];\n\t\t\t}\n\t\t}\n\t}\n return nargs;\n}\n\nstatic void\nufuncreduce_dealloc(PyUFuncReduceObject *self)\n{\n if (self->ufunc) {\n Py_XDECREF(self->it);\n\t\tPy_XDECREF(self->rit);\n Py_XDECREF(self->ret);\n\t\tPy_XDECREF(self->errobj);\n\t\tPy_XDECREF(self->decref);\n if (self->buffer) PyDataMem_FREE(self->buffer);\n Py_DECREF(self->ufunc);\n }\n _pya_free(self);\n}\n\nstatic void\nufuncloop_dealloc(PyUFuncLoopObject *self)\n{\n\tint i;\n\t\n\tif (self->ufunc != NULL) {\n\t\tfor (i=0; iufunc->nargs; i++)\n\t\t\tPy_XDECREF(self->iters[i]);\n\t\tif (self->buffer[0]) PyDataMem_FREE(self->buffer[0]);\n\t\tPy_XDECREF(self->errobj);\n\t\tPy_DECREF(self->ufunc);\n\t}\n _pya_free(self);\n}\n\nstatic PyUFuncLoopObject *\nconstruct_loop(PyUFuncObject *self, PyObject *args, PyArrayObject **mps)\n{\n\tPyUFuncLoopObject *loop;\n\tint i;\n\t\n\tif (self == NULL) {\n\t\tPyErr_SetString(PyExc_ValueError, \"function not supported\");\n\t\treturn NULL;\n\t}\n if ((loop = _pya_malloc(sizeof(PyUFuncLoopObject)))==NULL) {\n PyErr_NoMemory(); return loop;\n }\n\t\n\tloop->index = 0;\n\tloop->ufunc = self;\n Py_INCREF(self);\n\tloop->buffer[0] = NULL;\n for (i=0; inargs; i++) {\n loop->iters[i] = NULL;\n loop->cast[i] = NULL;\n }\n\tloop->errobj = NULL;\n\n\tif (PyUFunc_GetPyValues((self->name ? self->name : \"\"),\n\t\t\t\t&(loop->bufsize), &(loop->errormask), \n\t\t\t\t&(loop->errobj)) < 0) goto fail;\n \n\t/* Setup the matrices */\n\tif (construct_matrices(loop, args, mps) < 0) goto fail;\n\n\tPyUFunc_clearfperr();\n\n\treturn loop;\n\n fail:\n ufuncloop_dealloc(loop);\n\treturn NULL;\n}\n\n\n/* \nstatic void\n_printbytebuf(PyUFuncLoopObject *loop, int bufnum) \n{ \n\tint i;\n\t\n \tfprintf(stderr, \"Printing byte buffer %d\\n\", bufnum);\n for (i=0; ibufcnt; i++) {\n\t \tfprintf(stderr, \" %d\\n\", *(((byte *)(loop->buffer[bufnum]))+i));\n\t} \n}\n\nstatic void\n_printlongbuf(PyUFuncLoopObject *loop, int bufnum) \n{ \n\tint i;\n\t\n \tfprintf(stderr, \"Printing long buffer %d\\n\", bufnum);\n for (i=0; ibufcnt; i++) {\n\t \tfprintf(stderr, \" %ld\\n\", *(((long *)(loop->buffer[bufnum]))+i));\n\t} \n}\n\nstatic void\n_printlongbufptr(PyUFuncLoopObject *loop, int bufnum) \n{ \n\tint i;\n\t\n \tfprintf(stderr, \"Printing long buffer %d\\n\", bufnum);\n for (i=0; ibufcnt; i++) {\n\t \tfprintf(stderr, \" %ld\\n\", *(((long *)(loop->bufptr[bufnum]))+i));\n\t} \n}\n\n\n \nstatic void\n_printcastbuf(PyUFuncLoopObject *loop, int bufnum) \n{ \n\tint i;\n\t\n \tfprintf(stderr, \"Printing long buffer %d\\n\", bufnum);\n for (i=0; ibufcnt; i++) {\n\t \tfprintf(stderr, \" %ld\\n\", *(((long *)(loop->castbuf[bufnum]))+i));\n\t} \n}\n\n*/\n\n\n\n\n/* currently generic ufuncs cannot be built for use on flexible arrays.\n\n The cast functions in the generic loop would need to be fixed to pass \n in something besides NULL, NULL.\n\n Also the underlying ufunc loops would not know the element-size unless\n that was passed in as data (which could be arranged).\n\n*/\n\n/* This generic function is called with the ufunc object, the arguments to it,\n and an array of (pointers to) PyArrayObjects which are NULL. The \n arguments are parsed and placed in mps in construct_loop (construct_matrices)\n*/\n\n/*UFUNC_API*/\nstatic int \nPyUFunc_GenericFunction(PyUFuncObject *self, PyObject *args, \n\t\t\tPyArrayObject **mps) \n{\n\tPyUFuncLoopObject *loop;\n\tint i;\n BEGIN_THREADS_DEF\n\n\tif (!(loop = construct_loop(self, args, mps))) return -1;\n if (loop->notimplemented) {ufuncloop_dealloc(loop); return -2;}\n\n\tLOOP_BEGIN_THREADS\n\n\tswitch(loop->meth) {\n\tcase ONE_UFUNCLOOP:\n\t\t/* Everything is contiguous, notswapped, aligned,\n\t\t and of the right type. -- Fastest.\n\t\t Or if not contiguous, then a single-stride\n\t\t increment moves through the entire array. \n\t\t*/\n /*fprintf(stderr, \"ONE...%d\\n\", loop->size);*/\n\t\tloop->function((char **)loop->bufptr, &(loop->size), \n\t\t\t loop->steps, loop->funcdata);\n\t\tUFUNC_CHECK_ERROR(loop);\n\t\tbreak;\n\tcase NOBUFFER_UFUNCLOOP:\n\t\t/* Everything is notswapped, aligned and of the \n\t\t right type but not contiguous. -- Almost as fast.\n\t\t*/\n /*fprintf(stderr, \"NOBUFFER...%d\\n\", loop->size);*/\n\t\twhile (loop->index < loop->size) {\n\t\t\tfor (i=0; inargs; i++) \n\t\t\t\tloop->bufptr[i] = loop->iters[i]->dataptr;\n\n\t\t\tloop->function((char **)loop->bufptr, &(loop->bufcnt),\n\t\t\t\t loop->steps, loop->funcdata);\n\t\t\tUFUNC_CHECK_ERROR(loop);\n\n\t\t\tfor (i=0; inargs; i++) {\n\t\t\t\tPyArray_ITER_NEXT(loop->iters[i]);\n\t\t\t}\n\t\t\tloop->index++;\n\t\t}\n\t\tbreak;\n\tcase BUFFER_UFUNCLOOP: {\n\t\tPyArray_CopySwapNFunc *copyswapn[MAX_ARGS];\n\t\tPyArrayIterObject **iters=loop->iters;\n\t\tint *swap=loop->swap;\n\t\tvoid **dptr=loop->dptr;\n\t\tint mpselsize[MAX_ARGS];\n\t\tintp laststrides[MAX_ARGS];\n\t\tint fastmemcpy[MAX_ARGS];\n\t\tint *needbuffer=loop->needbuffer;\n\t\tintp index=loop->index, size=loop->size;\n\t\tint bufsize;\n\t\tintp bufcnt;\n\t\tint copysizes[MAX_ARGS];\n\t\tvoid **bufptr = loop->bufptr;\n\t\tvoid **buffer = loop->buffer;\n\t\tvoid **castbuf = loop->castbuf;\n\t\tintp *steps = loop->steps;\n\t\tchar *tptr[MAX_ARGS];\n\t\tint ninnerloops = loop->ninnerloops;\n\t\tBool pyobject[MAX_ARGS];\n\t\tint datasize[MAX_ARGS];\n int i, j, k, stopcondition;\n\t\tchar *myptr1, *myptr2;\n\n\t\t\n\t\tfor (i=0; inargs; i++) {\n\t\t\tcopyswapn[i] = mps[i]->descr->f->copyswapn;\n\t\t\tmpselsize[i] = mps[i]->descr->elsize;\n\t\t\tpyobject[i] = (loop->obj && \\\n (mps[i]->descr->type_num == PyArray_OBJECT));\n\t\t\tlaststrides[i] = iters[i]->strides[loop->lastdim];\n\t\t\tif (steps[i] && laststrides[i] != mpselsize[i]) fastmemcpy[i] = 0;\n\t\t\telse fastmemcpy[i] = 1;\n\t\t}\n\t\t/* Do generic buffered looping here (works for any kind of\n\t\t arrays -- some need buffers, some don't. \n\t\t*/\n\t\t\n\t\t/* New algorithm: N is the largest dimension. B is the buffer-size.\n\t\t quotient is loop->ninnerloops-1\n\t\t remainder is loop->leftover\n\n\t\tCompute N = quotient * B + remainder. \n\t\tquotient = N / B # integer math \n\t\t(store quotient + 1) as the number of innerloops\n\t\tremainder = N % B # integer remainder\n\t\t\n\t\tOn the inner-dimension we will have (quotient + 1) loops where \n\t\tthe size of the inner function is B for all but the last when the niter size is\n\t\tremainder. \n\t\t\n\t\tSo, the code looks very similar to NOBUFFER_LOOP except the inner-most loop is \n\t\treplaced with...\n\t\t\n\t\tfor(i=0; isize, \n\t\t loop->ninnerloops, loop->leftover);\n\t\t*/\n\t\t/*\n\t\tfor (i=0; inargs; i++) {\n\t\t fprintf(stderr, \"iters[%d]->dataptr = %p, %p of size %d\\n\", i, \n\t\t\t iters[i], iters[i]->ao->data, PyArray_NBYTES(iters[i]->ao));\n\t\t}\n\t\t*/\n\n\t\tstopcondition = ninnerloops;\n\t\tif (loop->leftover == 0) stopcondition--;\n\t\twhile (index < size) {\n\t\t\tbufsize=loop->bufsize;\n\t\t\tfor (i=0; inargs; i++) {\n\t\t\t\ttptr[i] = loop->iters[i]->dataptr;\n\t\t\t\tif (needbuffer[i]) {\n\t\t\t\t\tdptr[i] = bufptr[i];\n\t\t\t\t\tdatasize[i] = (steps[i] ? bufsize : 1);\n\t\t\t\t\tcopysizes[i] = datasize[i] * mpselsize[i];\n\t\t\t\t}\n\t\t\t\telse {\n\t\t\t\t\tdptr[i] = tptr[i];\n\t\t\t\t}\n\t\t\t}\n\n\t\t\t/* This is the inner function over the last dimension */\n\t\t\tfor (k=1; k<=stopcondition; k++) {\n\t\t\t\tif (k==ninnerloops) {\n bufsize = loop->leftover;\n for (i=0; inargs;i++) {\n\t\t\t\t\t\tif (!needbuffer[i]) continue;\n datasize[i] = (steps[i] ? bufsize : 1);\n\t\t\t\t\t\tcopysizes[i] = datasize[i] * mpselsize[i];\n }\n }\n \n\t\t\t\tfor (i=0; inin; i++) {\n\t\t\t\t\tif (!needbuffer[i]) continue;\n\t\t\t\t\tif (fastmemcpy[i]) \n\t\t\t\t\t\tmemcpy(buffer[i], tptr[i],\n\t\t\t\t\t\t copysizes[i]);\n\t\t\t\t\telse {\n\t\t\t\t\t\tmyptr1 = buffer[i];\n\t\t\t\t\t\tmyptr2 = tptr[i];\n\t\t\t\t\t\tfor (j=0; jcast[i]) {\n\t\t\t\t\t\tloop->cast[i](buffer[i],\n\t\t\t\t\t\t\t castbuf[i],\n\t\t\t\t\t\t\t (intp) datasize[i],\n\t\t\t\t\t\t\t NULL, NULL);\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t\t\n\t\t\t\tbufcnt = (intp) bufsize;\n\t\t\t\tloop->function((char **)dptr, &bufcnt, steps, loop->funcdata);\n\t\t\t\t\n\t\t\t\tfor (i=self->nin; inargs; i++) {\n\t\t\t\t\tif (!needbuffer[i]) continue;\n\t\t\t\t\tif (loop->cast[i]) {\n\t\t\t\t\t\tloop->cast[i](castbuf[i],\n\t\t\t\t\t\t\t buffer[i],\n\t\t\t\t\t\t\t (intp) datasize[i],\n\t\t\t\t\t\t\t NULL, NULL);\n\t\t\t\t\t}\n\t\t\t\t\tif (swap[i]) {\n\t\t\t\t\t\tcopyswapn[i](buffer[i], NULL,\n\t\t\t\t\t\t\t (intp) datasize[i], 1, \n\t\t\t\t\t\t\t mpselsize[i]);\n\t\t\t\t\t}\n\t\t\t\t\t/* copy back to output arrays */\n\t\t\t\t\t/* decref what's already there for object arrays */\n\t\t\t\t\tif (pyobject[i]) {\n\t\t\t\t\t\tmyptr1 = tptr[i];\n\t\t\t\t\t\tfor (j=0; jnargs; i++) {\n\t\t\t\t\ttptr[i] += bufsize * laststrides[i];\n\t\t\t\t\tif (!needbuffer[i]) dptr[i] = tptr[i];\n\t\t\t\t}\n\t\t\t}\n\n\t\t\tif (loop->obj) { /* DECREF castbuf for object arrays */\n\t\t\t\tfor (i=0; inargs; i++) {\n\t\t\t\t\tif (pyobject[i]) {\n\t\t\t\t\t\tif (steps[i] == 0) {\n\t\t\t\t\t\t\tPy_XDECREF(*((PyObject **)castbuf[i]));\n\t\t\t\t\t\t}\n\t\t\t\t\t\telse {\n\t\t\t\t\t\t\tint size = loop->bufsize;\n\t\t\t\t\t\t\tPyObject **objptr = castbuf[i];\n\t\t\t\t\t\t\t/* size is loop->bufsize unless there\n\t\t\t\t\t\t\t was only one loop */\n\t\t\t\t\t\t\tif (ninnerloops == 1) \\\n\t\t\t\t\t\t\t\tsize = loop->leftover;\n\t\t\t\t\t\t\t\n\t\t\t\t\t\t\tfor (j=0; jnargs; i++) {\n\t\t\t\tPyArray_ITER_NEXT(loop->iters[i]);\n\t\t\t}\n\t\t\tindex++;\n }\n }\n }\n \n LOOP_END_THREADS\n \n ufuncloop_dealloc(loop);\n\treturn 0;\n\n fail:\n LOOP_END_THREADS\n\n\tif (loop) ufuncloop_dealloc(loop);\n\treturn -1;\n}\n\nstatic PyArrayObject *\n_getidentity(PyUFuncObject *self, int otype, char *str)\n{\n PyObject *obj, *arr;\n PyArray_Descr *typecode;\n\t\n if (self->identity == PyUFunc_None) {\n PyErr_Format(PyExc_ValueError, \n \"zero-size array to ufunc.%s \" \\\n \"without identity\", str);\n return NULL;\n }\n if (self->identity == PyUFunc_One) {\n obj = PyInt_FromLong((long) 1);\n } else {\n obj = PyInt_FromLong((long) 0);\n }\n\n\ttypecode = PyArray_DescrFromType(otype); \n arr = PyArray_FromAny(obj, typecode, 0, 0, CARRAY_FLAGS, NULL);\n Py_DECREF(obj);\n return (PyArrayObject *)arr;\n}\n\nstatic int\n_create_reduce_copy(PyUFuncReduceObject *loop, PyArrayObject **arr, int rtype)\n{\n\tintp maxsize;\n\tPyObject *new;\n\tPyArray_Descr *ntype;\n\t\n\tmaxsize = PyArray_SIZE(*arr);\n\t\n\tif (maxsize < loop->bufsize) {\n\t\tif (!(PyArray_ISBEHAVED_RO(*arr)) ||\t\\\n\t\t PyArray_TYPE(*arr) != rtype) {\n\t\t\tntype = PyArray_DescrFromType(rtype);\n\t\t\tnew = PyArray_FromAny((PyObject *)(*arr), \n\t\t\t\t\t ntype, 0, 0,\n\t\t\t\t\t FORCECAST | ALIGNED, NULL);\n\t\t\tif (new == NULL) return -1;\n\t\t\t*arr = (PyArrayObject *)new;\n\t\t\tloop->decref = new;\n\t\t}\n\t}\n\n\t/* Don't decref *arr before re-assigning\n\t because it was not going to be DECREF'd anyway.\n\t \n\t If a copy is made, then the copy will be removed\n\t on deallocation of the loop structure by setting \n\t loop->decref.\n\t*/\n\t\n\treturn 0;\n}\n\nstatic PyUFuncReduceObject *\nconstruct_reduce(PyUFuncObject *self, PyArrayObject **arr, int axis, \n\t\t int otype, int operation, intp ind_size, char *str)\n{\n PyUFuncReduceObject *loop;\n PyArrayObject *idarr;\n\tPyArrayObject *aar;\n intp loop_i[MAX_DIMS];\n int arg_types[3] = {otype, otype, otype};\n\tchar scalars[3] = {UFUNC_NOSCALAR, UFUNC_NOSCALAR, UFUNC_NOSCALAR};\n\tint i, j;\n\tint nd = (*arr)->nd;\n\t/* Reduce type is the type requested of the input \n\t during reduction */\n \n if ((loop = _pya_malloc(sizeof(PyUFuncReduceObject)))==NULL) {\n PyErr_NoMemory(); return loop;\n }\n \n loop->swap = 0;\n\tloop->index = 0;\n\tloop->ufunc = self;\n Py_INCREF(self);\n loop->cast = NULL;\n loop->buffer = NULL;\n loop->ret = NULL;\n\tloop->it = NULL;\n\tloop->rit = NULL;\n\tloop->errobj = NULL;\n\tloop->decref=NULL; \n loop->N = (*arr)->dimensions[axis];\n\tloop->instrides = (*arr)->strides[axis];\n\n\tif (select_types(loop->ufunc, arg_types, &(loop->function), \n\t\t\t &(loop->funcdata), scalars) == -1) goto fail; \n\t\n\t/* output type may change -- if it does \n\t reduction is forced into that type \n\t and we need to select the reduction function again\n\t*/\n\tif (otype != arg_types[2]) {\n\t\totype = arg_types[2];\n\t\targ_types[0] = otype;\n\t\targ_types[1] = otype;\n\t\tif (select_types(loop->ufunc, arg_types, &(loop->function), \n\t\t\t\t &(loop->funcdata), scalars) == -1) \n\t\t\tgoto fail; \t\t\n\t}\n\t\n\t/* get looping parameters from Python */\n\tif (PyUFunc_GetPyValues(str, &(loop->bufsize), &(loop->errormask), \n\t\t\t\t&(loop->errobj)) < 0) goto fail;\n\t\n\t/* Make copy if misbehaved or not otype for small arrays */\n\tif (_create_reduce_copy(loop, arr, otype) < 0) goto fail; \n\taar = *arr;\n\t\n if (loop->N == 0) {\n loop->meth = ZERODIM_REDUCELOOP;\n }\n else if (PyArray_ISBEHAVED_RO(aar) &&\t\t\\\n otype == (aar)->descr->type_num) {\n\t\tif (loop->N == 1) {\n\t\t\tloop->meth = ONEDIM_REDUCELOOP;\n\t\t}\n\t\telse {\n\t\t\tloop->meth = NOBUFFER_UFUNCLOOP;\n\t\t\tloop->steps[0] = (aar)->strides[axis];\n\t\t\tloop->N -= 1;\n\t\t}\n }\n else {\n loop->meth = BUFFER_UFUNCLOOP;\n loop->swap = !(PyArray_ISNOTSWAPPED(aar));\n }\n\n /* Determine if object arrays are involved */\n if (otype == PyArray_OBJECT || aar->descr->type_num == PyArray_OBJECT)\n loop->obj = 1;\n else\n loop->obj = 0;\n\n if (loop->meth == ZERODIM_REDUCELOOP) {\n idarr = _getidentity(self, otype, str);\n if (idarr == NULL) goto fail;\n if (idarr->descr->elsize > UFUNC_MAXIDENTITY) {\n PyErr_Format(PyExc_RuntimeError, \n\t\t\t\t \"UFUNC_MAXIDENTITY (%d)\"\t\t\\\n \" is too small (needs to be at least %d)\",\n UFUNC_MAXIDENTITY, idarr->descr->elsize);\n Py_DECREF(idarr);\n goto fail;\n }\n memcpy(loop->idptr, idarr->data, idarr->descr->elsize);\n Py_DECREF(idarr);\n }\n\t\n /* Construct return array */\n\tswitch(operation) {\n\tcase UFUNC_REDUCE:\n\t\tfor (j=0, i=0; idimensions[i];\n\t\t\t\n\t\t}\n\t\tloop->ret = (PyArrayObject *)\t\t\t\t\\\n\t\t\tPyArray_New(aar->ob_type, aar->nd-1, loop_i, otype, \n\t\t\t\t NULL, NULL, 0, 0, (PyObject *)aar);\n\t\tbreak;\n\tcase UFUNC_ACCUMULATE:\n\t\tloop->ret = (PyArrayObject *)\t\t\t\t\\\n\t\t\tPyArray_New(aar->ob_type, aar->nd, aar->dimensions, \n\t\t\t\t otype, NULL, NULL, 0, 0, (PyObject *)aar);\n\t\tbreak;\n\tcase UFUNC_REDUCEAT:\n\t\tmemcpy(loop_i, aar->dimensions, nd*sizeof(intp));\n\t\t/* Index is 1-d array */\n\t\tloop_i[axis] = ind_size; \n\t\tloop->ret = (PyArrayObject *)\\\n\t\t\tPyArray_New(aar->ob_type, aar->nd, loop_i, otype,\n\t\t\t\t NULL, NULL, 0, 0, (PyObject *)aar);\n\t\tif (loop->ret == NULL) goto fail;\n\t\tif (ind_size == 0) {\n\t\t\tloop->meth = ZERODIM_REDUCELOOP;\n\t\t\treturn loop;\n\t\t}\n\t\tif (loop->meth == ONEDIM_REDUCELOOP)\n\t\t\tloop->meth = NOBUFFER_REDUCELOOP;\n\t\tbreak;\n\t}\n if (loop->ret == NULL) goto fail;\n loop->insize = aar->descr->elsize;\n loop->outsize = loop->ret->descr->elsize;\n loop->bufptr[1] = loop->ret->data;\n\n\tif (loop->meth == ZERODIM_REDUCELOOP) {\n\t\tloop->size = PyArray_SIZE(loop->ret);\n\t\treturn loop;\n\t}\n\n\tloop->it = (PyArrayIterObject *)PyArray_IterNew((PyObject *)aar);\n if (loop->it == NULL) return NULL;\n\n\tif (loop->meth == ONEDIM_REDUCELOOP) {\n\t\tloop->size = loop->it->size;\t\t\n\t\treturn loop;\n\t}\n\n /* Fix iterator to loop over correct dimension */\n\t/* Set size in axis dimension to 1 */\n \n loop->it->contiguous = 0;\n loop->it->size /= (loop->it->dims_m1[axis]+1);\n loop->it->dims_m1[axis] = 0;\n loop->it->backstrides[axis] = 0;\n\n\n loop->size = loop->it->size;\n\n\tif (operation == UFUNC_REDUCE) {\n\t\tloop->steps[1] = 0;\n\t}\n\telse {\n\t\tloop->rit = (PyArrayIterObject *)\t\t\t\\\n\t\t\tPyArray_IterNew((PyObject *)(loop->ret));\n\t\tif (loop->rit == NULL) return NULL;\t\t\n\n\t\t/* Fix iterator to loop over correct dimension */\n\t\t/* Set size in axis dimension to 1 */\n\t\t\n\t\tloop->rit->contiguous = 0;\n\t\tloop->rit->size /= (loop->rit->dims_m1[axis]+1);\n\t\tloop->rit->dims_m1[axis] = 0;\n\t\tloop->rit->backstrides[axis] = 0;\n\n\t\tif (operation == UFUNC_ACCUMULATE)\n\t\t\tloop->steps[1] = loop->ret->strides[axis];\n\t\telse \n\t\t\tloop->steps[1] = 0;\n\t}\n\tloop->steps[2] = loop->steps[1];\n\tloop->bufptr[2] = loop->bufptr[1] + loop->steps[2];\n\n\t\n\tif (loop->meth == BUFFER_UFUNCLOOP) {\n\t\tint _size;\n\t\tloop->steps[0] = loop->outsize;\n if (otype != aar->descr->type_num) {\n\t\t\t_size=loop->bufsize*(loop->outsize +\t\t\\\n\t\t\t\t\t aar->descr->elsize);\n loop->buffer = PyDataMem_NEW(_size);\n if (loop->buffer == NULL) goto fail;\n\t\t\tif (loop->obj) memset(loop->buffer, 0, _size);\n loop->castbuf = loop->buffer + \\\n loop->bufsize*aar->descr->elsize;\n loop->bufptr[0] = loop->castbuf; \n loop->cast = aar->descr->f->cast[otype];\n }\n else {\n\t\t\t_size = loop->bufsize * loop->outsize;\n loop->buffer = PyDataMem_NEW(_size);\n if (loop->buffer == NULL) goto fail;\n\t\t\tif (loop->obj) memset(loop->buffer, 0, _size);\n loop->bufptr[0] = loop->buffer;\n }\n\t}\n\n\n\tPyUFunc_clearfperr();\n\treturn loop;\n\n fail:\n ufuncreduce_dealloc(loop);\n\treturn NULL;\t\n}\n\n\n/* We have two basic kinds of loops */\n/* One is used when arr is not-swapped and aligned and output type\n is the same as input type.\n and another using buffers when one of these is not satisfied.\n\n Zero-length and one-length axes-to-be-reduced are handled separately.\n*/\n\nstatic PyObject *\nPyUFunc_Reduce(PyUFuncObject *self, PyArrayObject *arr, int axis, int otype)\n{\n PyArrayObject *ret=NULL;\n PyUFuncReduceObject *loop;\n intp i, n;\n char *dptr;\n BEGIN_THREADS_DEF\n \t\n /* Construct loop object */\n loop = construct_reduce(self, &arr, axis, otype, UFUNC_REDUCE, 0,\n\t\t\t\t\"reduce\");\n\tif (!loop) return NULL;\n\n LOOP_BEGIN_THREADS\n switch(loop->meth) {\n case ZERODIM_REDUCELOOP:\n\t\t/* fprintf(stderr, \"ZERO..%d\\n\", loop->size); */\n\t\tfor(i=0; isize; i++) {\n\t\t\tif (loop->obj) Py_INCREF(*((PyObject **)loop->idptr));\n\t\t\tmemmove(loop->bufptr[1], loop->idptr, loop->outsize);\n\t\t\tloop->bufptr[1] += loop->outsize;\n\t\t}\n break;\n case ONEDIM_REDUCELOOP:\n\t\t/*fprintf(stderr, \"ONEDIM..%d\\n\", loop->size); */\n while(loop->index < loop->size) {\n\t\t\tif (loop->obj) Py_INCREF(*((PyObject **)loop->it->dataptr));\n memmove(loop->bufptr[1], loop->it->dataptr, \n loop->outsize);\n\t\t\tPyArray_ITER_NEXT(loop->it);\n\t\t\tloop->bufptr[1] += loop->outsize;\n\t\t\tloop->index++;\n\t\t}\t\t\n\t\tbreak;\n case NOBUFFER_UFUNCLOOP:\n\t\t/*fprintf(stderr, \"NOBUFFER..%d\\n\", loop->size); */\n while(loop->index < loop->size) {\n\t\t\t/* Copy first element to output */\n\t\t\tif (loop->obj) \n\t\t\t\tPy_INCREF(*((PyObject **)loop->it->dataptr));\n memmove(loop->bufptr[1], loop->it->dataptr, \n loop->outsize);\n\t\t\t/* Adjust input pointer */\n loop->bufptr[0] = loop->it->dataptr+loop->steps[0];\n loop->function((char **)loop->bufptr, \n\t\t\t\t &(loop->N),\n loop->steps, loop->funcdata);\n\t\t\tUFUNC_CHECK_ERROR(loop);\n\n PyArray_ITER_NEXT(loop->it)\n loop->bufptr[1] += loop->outsize;\n loop->bufptr[2] = loop->bufptr[1];\n loop->index++; \n }\n break;\n case BUFFER_UFUNCLOOP: \n /* use buffer for arr */\n /* \n For each row to reduce\n 1. copy first item over to output (casting if necessary)\n 2. Fill inner buffer \n 3. When buffer is filled or end of row\n a. Cast input buffers if needed\n b. Call inner function.\n 4. Repeat 2 until row is done.\n */\n\t\t/* fprintf(stderr, \"BUFFERED..%d %d\\n\", loop->size, \n\t\t loop->swap); */\n while(loop->index < loop->size) {\n loop->inptr = loop->it->dataptr;\t\t\t\n\t\t\t/* Copy (cast) First term over to output */\n\t\t\tif (loop->cast) {\n\t\t\t\t/* A little tricky because we need to\n\t\t\t\t cast it first */\n\t\t\t\tarr->descr->f->copyswap(loop->buffer,\n\t\t\t\t\t\t loop->inptr,\n\t\t\t\t\t\t loop->swap,\n\t\t\t\t\t\t loop->insize);\n\t\t\t\tloop->cast(loop->buffer, loop->castbuf,\n\t\t\t\t\t 1, NULL, NULL);\n\t\t\t\tif (loop->obj) \n\t\t\t\t\tPy_INCREF(*((PyObject **)loop->castbuf));\n\t\t\t\tmemcpy(loop->bufptr[1], loop->castbuf,\n\t\t\t\t loop->outsize);\n\t\t\t}\n\t\t\telse { /* Simple copy */\n\t\t\t\tarr->descr->f->copyswap(loop->bufptr[1], \n\t\t\t\t\t\t loop->inptr,\n\t\t\t\t\t\t loop->swap,\n\t\t\t\t\t\t loop->insize);\n\t\t\t}\n\t\t\tloop->inptr += loop->instrides;\n n = 1;\n while(n < loop->N) {\n /* Copy up to loop->bufsize elements to \n buffer */\n dptr = loop->buffer;\n for (i=0; ibufsize; i++, n++) {\n if (n == loop->N) break;\n arr->descr->f->copyswap(dptr,\n loop->inptr,\n loop->swap,\n loop->insize);\n loop->inptr += loop->instrides;\n dptr += loop->insize;\n }\n if (loop->cast)\n loop->cast(loop->buffer,\n loop->castbuf,\n i, NULL, NULL);\n loop->function((char **)loop->bufptr,\n &i, \n\t\t\t\t\t loop->steps, loop->funcdata);\n\t\t\t\tUFUNC_CHECK_ERROR(loop);\n } \n PyArray_ITER_NEXT(loop->it);\n loop->bufptr[1] += loop->outsize;\n loop->bufptr[2] = loop->bufptr[1]; \n loop->index++;\n }\n }\n\n LOOP_END_THREADS\n\n ret = loop->ret;\n\t/* Hang on to this reference -- will be decref'd with loop */\n Py_INCREF(ret);\n ufuncreduce_dealloc(loop);\n return (PyObject *)ret;\n\n fail:\n LOOP_END_THREADS\n\n if (loop) ufuncreduce_dealloc(loop);\n return NULL;\n}\n\n\nstatic PyObject *\nPyUFunc_Accumulate(PyUFuncObject *self, PyArrayObject *arr, int axis, \n\t\t int otype)\n{\n PyArrayObject *ret=NULL;\n PyUFuncReduceObject *loop;\n intp i, n;\n char *dptr;\n \n /* Construct loop object */\n loop = construct_reduce(self, &arr, axis, otype, UFUNC_ACCUMULATE, 0,\n\t\t\t\t\"accumulate\");\n\tif (!loop) return NULL;\n\n\tLOOP_BEGIN_THREADS\n switch(loop->meth) {\n case ZERODIM_REDUCELOOP: /* Accumulate */\n\t\t/* fprintf(stderr, \"ZERO..%d\\n\", loop->size); */\n\t\tfor(i=0; isize; i++) {\n\t\t\tif (loop->obj) \n\t\t\t\tPy_INCREF(*((PyObject **)loop->idptr));\n\t\t\tmemcpy(loop->bufptr[1], loop->idptr, loop->outsize);\n\t\t\tloop->bufptr[1] += loop->outsize;\n\t\t} \n break;\n case ONEDIM_REDUCELOOP: /* Accumulate */\n\t\t/* fprintf(stderr, \"ONEDIM..%d\\n\", loop->size); */\n while(loop->index < loop->size) {\n\t\t\tif (loop->obj) \n\t\t\t\tPy_INCREF(*((PyObject **)loop->it->dataptr));\n memcpy(loop->bufptr[1], loop->it->dataptr, \n loop->outsize);\n\t\t\tPyArray_ITER_NEXT(loop->it);\n\t\t\tloop->bufptr[1] += loop->outsize;\n\t\t\tloop->index++;\n\t\t}\t\t\n\t\tbreak;\n case NOBUFFER_UFUNCLOOP: /* Accumulate */\n\t\t/* fprintf(stderr, \"NOBUFFER..%d\\n\", loop->size); */\n while(loop->index < loop->size) {\n\t\t\t/* Copy first element to output */\n\t\t\tif (loop->obj) \n\t\t\t\tPy_INCREF(*((PyObject **)loop->it->dataptr));\n memcpy(loop->bufptr[1], loop->it->dataptr, \n loop->outsize);\n\t\t\t/* Adjust input pointer */\n loop->bufptr[0] = loop->it->dataptr+loop->steps[0];\n loop->function((char **)loop->bufptr, \n\t\t\t\t &(loop->N),\n loop->steps, loop->funcdata);\n\t\t\tUFUNC_CHECK_ERROR(loop);\n\n PyArray_ITER_NEXT(loop->it);\n\t\t\tPyArray_ITER_NEXT(loop->rit);\n loop->bufptr[1] = loop->rit->dataptr;\n\t\t\tloop->bufptr[2] = loop->bufptr[1] + loop->steps[1];\n loop->index++;\n }\n break;\n case BUFFER_UFUNCLOOP: /* Accumulate */\n /* use buffer for arr */\n /* \n For each row to reduce\n 1. copy identity over to output (casting if necessary)\n 2. Fill inner buffer \n 3. When buffer is filled or end of row\n a. Cast input buffers if needed\n b. Call inner function.\n 4. Repeat 2 until row is done.\n */\n\t\t/* fprintf(stderr, \"BUFFERED..%d %p\\n\", loop->size, \n\t\t loop->cast); */\n while(loop->index < loop->size) {\n loop->inptr = loop->it->dataptr;\t\t\t\n\t\t\t/* Copy (cast) First term over to output */\n\t\t\tif (loop->cast) {\n\t\t\t\t/* A little tricky because we need to\n\t\t\t\t cast it first */\n\t\t\t\tarr->descr->f->copyswap(loop->buffer,\n\t\t\t\t\t\t loop->inptr,\n\t\t\t\t\t\t loop->swap,\n\t\t\t\t\t\t loop->insize);\n\t\t\t\tloop->cast(loop->buffer, loop->castbuf,\n\t\t\t\t\t 1, NULL, NULL);\n\t\t\t\tif (loop->obj) \n\t\t\t\t\tPy_INCREF(*((PyObject **)loop->castbuf));\n\t\t\t\tmemcpy(loop->bufptr[1], loop->castbuf,\n\t\t\t\t loop->outsize);\n\t\t\t}\n\t\t\telse { /* Simple copy */\n\t\t\t\tarr->descr->f->copyswap(loop->bufptr[1], \n\t\t\t\t\t\t loop->inptr,\n\t\t\t\t\t\t loop->swap,\n\t\t\t\t\t\t loop->insize);\n\t\t\t}\n\t\t\tloop->inptr += loop->instrides;\n n = 1;\n while(n < loop->N) {\n /* Copy up to loop->bufsize elements to \n buffer */\n dptr = loop->buffer;\n for (i=0; ibufsize; i++, n++) {\n if (n == loop->N) break;\n arr->descr->f->copyswap(dptr,\n loop->inptr,\n loop->swap,\n loop->insize);\n loop->inptr += loop->instrides;\n dptr += loop->insize;\n }\n if (loop->cast)\n loop->cast(loop->buffer,\n loop->castbuf,\n i, NULL, NULL);\n loop->function((char **)loop->bufptr,\n &i, \n\t\t\t\t\t loop->steps, loop->funcdata);\n\t\t\t\tUFUNC_CHECK_ERROR(loop);\n } \n PyArray_ITER_NEXT(loop->it);\n\t\t\tPyArray_ITER_NEXT(loop->rit);\n loop->bufptr[1] = loop->rit->dataptr;\n\t\t\tloop->bufptr[2] = loop->bufptr[1] + loop->steps[1];\n loop->index++;\n }\n }\n\n\tLOOP_END_THREADS\n ret = loop->ret;\n\t/* Hang on to this reference -- will be decref'd with loop */\n Py_INCREF(ret);\n ufuncreduce_dealloc(loop);\n return (PyObject *)ret;\n\n fail:\n\tLOOP_END_THREADS\n\n if (loop) ufuncreduce_dealloc(loop);\n return NULL;\n}\n\n/* Reduceat performs a reduce over an axis using the indices as a guide\n\nop.reduceat(array,indices) computes\nop.reduce(array[indices[i]:indices[i+1]] \n for i=0..end with an implicit indices[i+1]=len(array)\n assumed when i=end-1\n\nif indices[i+1] <= indices[i]+1 \n then the result is array[indices[i]] for that value\n\nop.accumulate(array) is the same as\nop.reduceat(array,indices)[::2]\nwhere indices is range(len(array)-1) with a zero placed in every other sample\n indices = zeros(len(array)*2-1)\n indices[1::2] = range(1,len(array))\n\noutput shape is based on the size of indices\n */\n\nstatic PyObject *\nPyUFunc_Reduceat(PyUFuncObject *self, PyArrayObject *arr, PyArrayObject *ind, \n int axis, int otype)\n{\t\n\tPyArrayObject *ret;\n PyUFuncReduceObject *loop;\n\tintp *ptr=(intp *)ind->data;\n\tintp nn=ind->dimensions[0];\t\t\n\tintp mm=arr->dimensions[axis]-1;\n\tintp n, i, j;\n\tchar *dptr;\n\n\t/* Check for out-of-bounds values in indices array */\t\t\n\tfor (i=0; i mm)) {\n\t\t\tPyErr_Format(PyExc_IndexError, \n\t\t\t\t \"index out-of-bounds (0, %d)\", (int) mm);\n\t\t\treturn NULL;\n\t\t}\n\t\tptr++;\n\t}\n\t\n\tptr = (intp *)ind->data;\n /* Construct loop object */\n loop = construct_reduce(self, &arr, axis, otype, UFUNC_REDUCEAT, nn,\n\t\t\t\t\"reduceat\");\n\tif (!loop) return NULL;\n\n\tLOOP_BEGIN_THREADS\n\tswitch(loop->meth) {\n\t/* zero-length index -- return array immediately */\n\tcase ZERODIM_REDUCELOOP:\n\t\t/* fprintf(stderr, \"ZERO..\\n\"); */\n\t\tbreak;\n\t/* NOBUFFER -- behaved array and same type */\n\tcase NOBUFFER_UFUNCLOOP: \t /* Reduceat */\n\t\t/* fprintf(stderr, \"NOBUFFER..%d\\n\", loop->size); */\n\t\twhile(loop->index < loop->size) {\n\t\t\tptr = (intp *)ind->data;\n\t\t\tfor (i=0; ibufptr[0] = loop->it->dataptr +\t\\\n\t\t\t\t\t(*ptr)*loop->instrides;\n\t\t\t\tif (loop->obj) \n\t\t\t\t\tPy_INCREF(*((PyObject **)loop->bufptr[0]));\n\t\t\t\tmemcpy(loop->bufptr[1], loop->bufptr[0],\n\t\t\t\t loop->outsize);\n\t\t\t\tmm = (i==nn-1 ? arr->dimensions[axis]-*ptr : \\\n\t\t\t\t *(ptr+1) - *ptr) - 1;\n\t\t\t\tif (mm > 0) {\n\t\t\t\t\tloop->bufptr[0] += loop->instrides;\n\t\t\t\t\tloop->bufptr[2] = loop->bufptr[1];\n\t\t\t\t\tloop->function((char **)loop->bufptr,\n\t\t\t\t\t\t &mm, loop->steps,\n\t\t\t\t\t\t loop->funcdata);\n\t\t\t\t\tUFUNC_CHECK_ERROR(loop);\n\t\t\t\t}\t\n\t\t\t\tloop->bufptr[1] += loop->ret->strides[axis];\n\t\t\t\tptr++;\n\t\t\t}\n\t\t\tPyArray_ITER_NEXT(loop->it);\n\t\t\tPyArray_ITER_NEXT(loop->rit);\n\t\t\tloop->bufptr[1] = loop->rit->dataptr;\n\t\t\tloop->index++;\n\t\t}\n\t\tbreak;\n\n\t/* BUFFER -- misbehaved array or different types */ \n\tcase BUFFER_UFUNCLOOP: /* Reduceat */\n\t\t/* fprintf(stderr, \"BUFFERED..%d\\n\", loop->size); */\n\t\twhile(loop->index < loop->size) {\n\t\t\tptr = (intp *)ind->data;\n\t\t\tfor (i=0; iobj) \n\t\t\t\t\tPy_INCREF(*((PyObject **)loop->idptr));\n\t\t\t\tmemcpy(loop->bufptr[1], loop->idptr, \n\t\t\t\t loop->outsize);\n\t\t\t\tn = 0;\n\t\t\t\tmm = (i==nn-1 ? arr->dimensions[axis] - *ptr :\\\n\t\t\t\t *(ptr+1) - *ptr);\n\t\t\t\tif (mm < 1) mm = 1;\n\t\t\t\tloop->inptr = loop->it->dataptr + \\\n\t\t\t\t\t(*ptr)*loop->instrides;\n\t\t\t\twhile (n < mm) {\n\t\t\t\t\t/* Copy up to loop->bufsize elements\n\t\t\t\t\t to buffer */\n\t\t\t\t\tdptr = loop->buffer;\n\t\t\t\t\tfor (j=0; jbufsize; j++, n++) {\n\t\t\t\t\t\tif (n == mm) break;\n\t\t\t\t\t\tarr->descr->f->copyswap\\\n\t\t\t\t\t\t\t(dptr,\n\t\t\t\t\t\t\t loop->inptr,\n\t\t\t\t\t\t\t loop->swap,\n\t\t\t\t\t\t\t loop->insize);\n\t\t\t\t\t\tloop->inptr += loop->instrides;\n\t\t\t\t\t\tdptr += loop->insize;\n\t\t\t\t\t}\n\t\t\t\t\tif (loop->cast)\n\t\t\t\t\t\tloop->cast(loop->buffer,\n\t\t\t\t\t\t\t loop->castbuf,\n\t\t\t\t\t\t\t j, NULL, NULL);\n\t\t\t\t\tloop->bufptr[2] = loop->bufptr[1];\n\t\t\t\t\tloop->function((char **)loop->bufptr,\n\t\t\t\t\t\t &j, loop->steps,\n\t\t\t\t\t\t loop->funcdata);\n\t\t\t\t\tUFUNC_CHECK_ERROR(loop);\n\t\t\t\t} \n\t\t\t\tloop->bufptr[1] += loop->ret->strides[axis];\n\t\t\t\tptr++;\n\t\t\t}\n\t\t\tPyArray_ITER_NEXT(loop->it);\n\t\t\tPyArray_ITER_NEXT(loop->rit);\n\t\t\tloop->bufptr[1] = loop->rit->dataptr;\n\t\t\tloop->index++;\n\t\t}\n\t\tbreak;\n\t}\n\n\tLOOP_END_THREADS\n\t\n ret = loop->ret;\n\t/* Hang on to this reference -- will be decref'd with loop */\n Py_INCREF(ret);\n ufuncreduce_dealloc(loop);\n return (PyObject *)ret;\n\t\n fail:\n\tLOOP_END_THREADS\n\n if (loop) ufuncreduce_dealloc(loop);\n\treturn NULL;\n}\n\n\n/* This code handles reduce, reduceat, and accumulate \n (accumulate and reduce are special cases of the more general reduceat \n but they are handled separately for speed) \n*/\n\nstatic PyObject * \nPyUFunc_GenericReduction(PyUFuncObject *self, PyObject *args, \n PyObject *kwds, int operation) \n{\n\tint axis=0;\n\tPyArrayObject *mp, *ret = NULL;\n\tPyObject *op, *res=NULL;\n\tPyObject *obj_ind, *context; \n\tPyArrayObject *indices = NULL;\n\tPyArray_Descr *otype=NULL;\n\tstatic char *kwlist1[] = {\"array\", \"axis\", \"dtype\", NULL};\n\tstatic char *kwlist2[] = {\"array\", \"indices\", \"axis\", \"dtype\", NULL}; \n static char *_reduce_type[] = {\"reduce\", \"accumulate\", \\\n\t\t\t\t \"reduceat\", NULL};\n\tif (self == NULL) {\n\t\tPyErr_SetString(PyExc_ValueError, \"function not supported\");\n\t\treturn NULL;\n\t}\t\n\n\tif (self->nin != 2) {\n\t\tPyErr_Format(PyExc_ValueError, \n \"%s only supported for binary functions\",\n _reduce_type[operation]);\n\t\treturn NULL;\n\t}\n\tif (self->nout != 1) {\n\t\tPyErr_Format(PyExc_ValueError,\n \"%s only supported for functions \" \\\n \"returning a single value\",\n _reduce_type[operation]);\n\t\treturn NULL;\n\t}\n\n\tif (operation == UFUNC_REDUCEAT) {\n\t\tPyArray_Descr *indtype;\n\t\tindtype = PyArray_DescrFromType(PyArray_INTP);\n\t\tif(!PyArg_ParseTupleAndKeywords(args, kwds, \"OO|iO&\", kwlist2, \n\t\t\t\t\t\t&op, &obj_ind, &axis, \n\t\t\t\t\t\tPyArray_DescrConverter, \n\t\t\t\t\t\t&otype)) return NULL;\n indices = (PyArrayObject *)PyArray_FromAny(obj_ind, indtype, \n\t\t\t\t\t\t\t 1, 1, CARRAY_FLAGS, NULL);\n if (indices == NULL) return NULL;\n\t\tPy_DECREF(indtype);\t\t\n\t}\n\telse {\n\t\tif(!PyArg_ParseTupleAndKeywords(args, kwds, \"O|iO&\", kwlist1,\n\t\t\t\t\t\t&op, &axis, \n\t\t\t\t\t\tPyArray_DescrConverter, \n\t\t\t\t\t\t&otype)) return NULL;\n\t}\n\t\n\t/* Ensure input is an array */\t\n if (!PyArray_Check(op) && !PyArray_IsScalar(op, Generic)) {\n context = Py_BuildValue(\"O(O)i\", self, op, 0);\n }\n else {\n context = NULL;\n }\n\tmp = (PyArrayObject *)PyArray_FromAny(op, NULL, 0, 0, 0, context);\n Py_XDECREF(context);\n\tif (mp == NULL) return NULL;\n\n /* Check to see if input is zero-dimensional */\n if (mp->nd == 0) {\n PyErr_Format(PyExc_TypeError, \"cannot %s on a scalar\",\n _reduce_type[operation]);\n Py_DECREF(mp);\n return NULL; \n }\n\n /* Check to see that type (and otype) is not FLEXIBLE */\n\tif (PyArray_ISFLEXIBLE(mp) || (otype && PyTypeNum_ISFLEXIBLE(otype->type_num))) {\n PyErr_Format(PyExc_TypeError, \n\t\t\t \"cannot perform %s with flexible type\",\n _reduce_type[operation]);\n Py_DECREF(mp);\n return NULL;\n }\n\n\tif (axis < 0) axis += mp->nd;\n\tif (axis < 0 || axis >= mp->nd) {\n\t\tPyErr_SetString(PyExc_ValueError, \"axis not in array\");\n Py_DECREF(mp);\n\t\treturn NULL;\n\t}\n\n\t/* Get default type to reduce over if not given */\n if (otype == NULL) {\n\t\t/* For integer types --- makes sure at \n\t\t least a long is used */\n\t\tint typenum = PyArray_TYPE(mp);\n\t\tif (PyTypeNum_ISINTEGER(typenum) &&\t\\\n\t\t (mp->descr->elsize < sizeof(long))) {\n\t\t\tif (PyTypeNum_ISUNSIGNED(typenum))\n\t\t\t\ttypenum = PyArray_ULONG;\n\t\t\telse\n\t\t\t\ttypenum = PyArray_LONG;\n\t\t}\n\t\telse if (PyTypeNum_ISBOOL(typenum) && \\\n\t\t\t ((strcmp(self->name,\"add\")==0) ||\t\\\n\t\t\t (strcmp(self->name,\"multiply\")==0))) {\n\t\t\ttypenum = PyArray_LONG;\n\t\t}\n\t\totype = PyArray_DescrFromType(typenum);\n\t}\n\n switch(operation) {\n case UFUNC_REDUCE:\n ret = (PyArrayObject *)PyUFunc_Reduce(self, mp, axis, \n otype->type_num);\n\t\tbreak;\n case UFUNC_ACCUMULATE:\n ret = (PyArrayObject *)PyUFunc_Accumulate(self, mp, axis, \n otype->type_num);\n\t\tbreak;\n case UFUNC_REDUCEAT:\n ret = (PyArrayObject *)PyUFunc_Reduceat(self, mp, indices, \n axis, otype->type_num);\n Py_DECREF(indices);\n\t\tbreak;\n }\n Py_DECREF(mp);\n\tPy_DECREF(otype);\n\tif (ret==NULL) return NULL;\n\tif (op->ob_type != ret->ob_type) {\n\t\tres = PyObject_CallMethod(op, \"__array_wrap__\", \"O\", ret);\n\t\tif (res == NULL) PyErr_Clear();\n\t\telse if (res == Py_None) Py_DECREF(res);\n\t\telse {\n\t\t\tPy_DECREF(ret);\n\t\t\treturn res;\n\t\t}\t\n\t}\n\treturn PyArray_Return(ret);\n\t\n}\n\nstatic PyObject *\n_find_array_wrap(PyObject *args)\n{\n\tint nargs, i;\n\tint np = 0;\n\tdouble priority, maxpriority;\n\tPyObject *with_wrap[MAX_ARGS], *wraps[MAX_ARGS];\n\tPyObject *obj, *wrap = NULL;\n\n\tnargs = PyTuple_GET_SIZE(args);\n\tfor (i=0; i maxpriority) {\n\t\t\tmaxpriority = priority;\n\t\t\tPy_DECREF(wrap);\n\t\t\twrap = wraps[i];\n\t\t} else {\n\t\t\tPy_DECREF(wraps[i]);\n\t\t}\n\t}\n\treturn wrap;\n}\n\nstatic PyObject *\nufunc_generic_call(PyUFuncObject *self, PyObject *args) \n{\n\tint i;\n\tPyTupleObject *ret;\n\tPyArrayObject *mps[MAX_ARGS];\n\tPyObject *retobj[MAX_ARGS];\n\tPyObject *res;\n\tPyObject *wrap;\n int errval;\n \n\t/* Initialize all array objects to NULL to make cleanup easier \n\t if something goes wrong. */\n\tfor(i=0; inargs; i++) mps[i] = NULL;\n\t\n errval = PyUFunc_GenericFunction(self, args, mps);\n if (errval < 0) {\n\t\tfor(i=0; inargs; i++) Py_XDECREF(mps[i]);\n\t\tif (errval == -1)\n\t\t\treturn NULL;\n\t\telse {\n\t\t\tPy_INCREF(Py_NotImplemented);\n\t\t\treturn Py_NotImplemented;\n\t\t}\n }\n\t\n\tfor(i=0; inin; i++) Py_DECREF(mps[i]);\n\n\t/* Use __array_wrap__ on all outputs \n\t if present on one of the input arguments.\n\t If present for multiple inputs:\n\t use __array_wrap__ of input object with largest \n\t\t__array_priority__ (default = 0.0)\n\t */\n\twrap = _find_array_wrap(args);\n\t\n\t/* wrap outputs */\n\tfor (i=0; inout; i++) {\n\t\tint j=self->nin+i;\n\t\t/* check to see if any UPDATEIFCOPY flags are set \n\t\t which meant that a temporary output was generated \n\t\t*/\n\t\tif (mps[j]->flags & UPDATEIFCOPY) {\n\t\t\tPyObject *old = mps[j]->base;\n\t\t\tPy_INCREF(old); /* we want to hang on to this */\n\t\t\tPy_DECREF(mps[j]); /* should trigger the copy \n\t\t\t\t\t back into old */\n\t\t\tmps[j] = (PyArrayObject *)old;\n\t\t}\n\t\tif (wrap != NULL) {\n\t\t\tres = PyObject_CallFunction(wrap, \"O(OOi)\",\n\t\t\t\t\t\t mps[j], self, args, i);\n\t\t\tif (res == NULL && PyErr_ExceptionMatches(PyExc_TypeError)) {\n\t\t\t\tPyErr_Clear();\n\t\t\t\tres = PyObject_CallFunctionObjArgs(wrap, mps[j], NULL);\n\t\t\t}\n\t\t\tPy_DECREF(wrap);\n\t\t\tif (res == NULL) goto fail;\n\t\t\telse if (res == Py_None) Py_DECREF(res);\n\t\t\telse {\n\t\t\t\tPy_DECREF(mps[j]);\n\t\t\t\tretobj[i] = res;\n\t\t\t\tcontinue;\n\t\t\t}\n\t\t}\n\t\tretobj[i] = PyArray_Return(mps[j]);\n\t}\n\t\n\tif (self->nout == 1) { \n\t\treturn retobj[0];\n\t} else { \n\t\tret = (PyTupleObject *)PyTuple_New(self->nout);\n\t\tfor(i=0; inout; i++) {\n\t\t\tPyTuple_SET_ITEM(ret, i, retobj[i]);\n\t\t}\n\t\treturn (PyObject *)ret;\n\t}\n fail:\n\tfor(i=self->nin; inargs; i++) Py_XDECREF(mps[i]);\n\treturn NULL;\n}\n\nstatic PyObject *\nufunc_update_use_defaults(PyObject *dummy, PyObject *args)\n{\n\tPyObject *errobj;\n\tint errmask, bufsize;\n\n\tif (!PyArg_ParseTuple(args, \"\")) return NULL;\n\t\n\tPyUFunc_USEDEFAULTS = 0;\n\tif (PyUFunc_GetPyValues(\"test\", &bufsize, &errmask, &errobj) < 0) return NULL;\n\t\n\tif ((errmask == UFUNC_ERR_DEFAULT) &&\t\t\\\n\t (bufsize == PyArray_BUFSIZE) &&\t\t\\\n\t (PyTuple_GET_ITEM(errobj, 1) == Py_None)) {\n\t\tPyUFunc_USEDEFAULTS = 1;\n\t}\n\t\n\tPy_INCREF(Py_None);\n\treturn Py_None;\n}\n\nstatic PyUFuncGenericFunction pyfunc_functions[] = {PyUFunc_On_Om};\n\nstatic char \ndoc_frompyfunc[] = \"frompyfunc(func, nin, nout) take an arbitrary python function that takes nin objects as input and returns nout objects and return a universal function (ufunc). This ufunc always returns PyObject arrays\";\n\nstatic PyObject *\nufunc_frompyfunc(PyObject *dummy, PyObject *args, PyObject *kwds) {\n /* Keywords are ignored for now */\n \n PyObject *function, *pyname=NULL;\n int nin, nout, i;\n PyUFunc_PyFuncData *fdata;\n PyUFuncObject *self;\n char *fname, *str;\n int fname_len=-1;\n\tint offset[2];\n\n if (!PyArg_ParseTuple(args, \"Oii\", &function, &nin, &nout)) return NULL;\n\n if (!PyCallable_Check(function)) {\n PyErr_SetString(PyExc_TypeError, \"function must be callable\");\n return NULL;\n }\n\t\n self = _pya_malloc(sizeof(PyUFuncObject));\n if (self == NULL) return NULL;\n PyObject_Init((PyObject *)self, &PyUFunc_Type);\n\n\tself->userloops = NULL;\n\tself->nin = nin;\n\tself->nout = nout;\n\tself->nargs = nin+nout;\n\tself->identity = PyUFunc_None;\t\n\tself->functions = pyfunc_functions;\n\n\tself->ntypes = 1;\n\tself->check_return = 0;\n\n pyname = PyObject_GetAttrString(function, \"__name__\");\n if (pyname)\n (void) PyString_AsStringAndSize(pyname, &fname, &fname_len);\n \n if (PyErr_Occurred()) {\n fname = \"?\";\n fname_len = 1;\n PyErr_Clear();\n } \n Py_XDECREF(pyname);\n\n\n\n\t/* self->ptr holds a pointer for enough memory for\n\t self->data[0] (fdata)\n\t self->data\n\t self->name\n\t self->types\n\n\t To be safest, all of these need their memory aligned on void * pointers\n\t Therefore, we may need to allocate extra space.\n\t*/\n\toffset[0] = sizeof(PyUFunc_PyFuncData);\n\ti = (sizeof(PyUFunc_PyFuncData) % sizeof(void *));\n\tif (i) offset[0] += (sizeof(void *) - i);\n\toffset[1] = self->nargs;\n\ti = (self->nargs % sizeof(void *));\n\tif (i) offset[1] += (sizeof(void *)-i);\n\n self->ptr = _pya_malloc(offset[0] + offset[1] + sizeof(void *) + \\\n\t\t\t (fname_len+14));\n\n\tif (self->ptr == NULL) return PyErr_NoMemory();\n Py_INCREF(function);\n self->obj = function;\n\tfdata = (PyUFunc_PyFuncData *)(self->ptr);\n fdata->nin = nin;\n fdata->nout = nout;\n fdata->callable = function;\n \n self->data = (void **)(self->ptr + offset[0]);\n self->data[0] = (void *)fdata;\n\t\n\tself->types = (char *)self->data + sizeof(void *);\n for (i=0; inargs; i++) self->types[i] = PyArray_OBJECT;\n\n str = self->types + offset[1];\n memcpy(str, fname, fname_len);\n memcpy(str+fname_len, \" (vectorized)\", 14);\n \n self->name = str;\n\n /* Do a better job someday */\n self->doc = \"dynamic ufunc based on a python function\";\n \n\t\n\treturn (PyObject *)self;\n}\n\n\n/*UFUNC_API*/\nstatic PyObject *\nPyUFunc_FromFuncAndData(PyUFuncGenericFunction *func, void **data, \n\t\t\tchar *types, int ntypes,\n\t\t\tint nin, int nout, int identity, \n\t\t\tchar *name, char *doc, int check_return) \n{\n\tPyUFuncObject *self;\n\n self = _pya_malloc(sizeof(PyUFuncObject));\n if (self == NULL) return NULL;\n PyObject_Init((PyObject *)self, &PyUFunc_Type);\n\t\n\tself->nin = nin;\n\tself->nout = nout;\n\tself->nargs = nin+nout;\n\tself->identity = identity;\n\t\n\tself->functions = func;\n\tself->data = data;\n\tself->types = types;\n\tself->ntypes = ntypes;\n\tself->check_return = check_return;\n self->ptr = NULL;\n self->obj = NULL;\n\tself->userloops=NULL;\n\t\n\tif (name == NULL) self->name = \"?\";\n\telse self->name = name;\n\t\n if (doc == NULL) self->doc = \"NULL\";\n\telse self->doc = doc;\n\t\n\treturn (PyObject *)self;\n}\n\n/*UFUNC_API*/\nstatic int\nPyUFunc_RegisterLoopForType(PyUFuncObject *ufunc, \n\t\t\t int usertype,\n\t\t\t PyUFuncGenericFunction function,\n\t\t\t void *data)\n{\n\tPyArray_Descr *descr;\n \tPyObject *key, *cobj;\n\tint ret;\t\n\t\n\tdescr=PyArray_DescrFromType(usertype);\n\tif ((usertype < PyArray_USERDEF) || (descr==NULL)) {\n\t\tPyErr_SetString(PyExc_TypeError, \n\t\t\t\t\"unknown type\");\n\t\treturn -1;\n\t}\n\tPy_DECREF(descr);\n\t\n\tif (ufunc->userloops == NULL) {\n\t\tufunc->userloops = PyDict_New();\n\t}\n\tkey = PyInt_FromLong((long) usertype);\n\tif (key == NULL) return -1;\n\tcobj = PyCObject_FromVoidPtr((void *)function, NULL);\n\tif (cobj == NULL) {Py_DECREF(key); return -1;}\n\tif (data == NULL) {\n\t\tret = PyDict_SetItem(ufunc->userloops, key, cobj);\n\t\tPy_DECREF(cobj);\n\t\tPy_DECREF(key);\n\t\treturn ret;\n\t}\n\telse {\n\t\tPyObject *cobj2, *tmp;\n\t\tcobj2 = PyCObject_FromVoidPtr(data, NULL);\n\t\tif (cobj2 == NULL) {\n\t\t\tPy_DECREF(cobj); \n\t\t\tPy_DECREF(key);\n\t\t\treturn -1;\n\t\t}\n\t\ttmp=Py_BuildValue(\"NN\", cobj, cobj2);\n\t\tret = PyDict_SetItem(ufunc->userloops, key, tmp);\n\t\tPy_DECREF(tmp);\n\t\tPy_DECREF(key);\n\t\treturn ret;\n\t}\n}\n\nstatic void\nufunc_dealloc(PyUFuncObject *self)\n{\n if (self->ptr) _pya_free(self->ptr);\n\tPy_XDECREF(self->userloops);\n Py_XDECREF(self->obj);\n _pya_free(self);\n}\n\nstatic PyObject *\nufunc_repr(PyUFuncObject *self)\n{\n\tchar buf[100];\n\t\n\tsprintf(buf, \"\", self->name);\n\t\n\treturn PyString_FromString(buf);\n}\n\n\n/* -------------------------------------------------------- */\n\n/* op.outer(a,b) is equivalent to op(a[:,NewAxis,NewAxis,etc.],b)\n where a has b.ndim NewAxis terms appended.\n\n The result has dimensions a.ndim + b.ndim\n */\n\nstatic PyObject *\nufunc_outer(PyUFuncObject *self, PyObject *args) \n{\n\tint i;\n\tPyObject *ret;\n\tPyArrayObject *ap1=NULL, *ap2=NULL, *ap_new=NULL;\n\tPyObject *new_args, *tmp;\n\tPyObject *shape1, *shape2, *newshape;\n\n\tif(self->nin != 2) {\n\t\tPyErr_SetString(PyExc_ValueError,\n\t\t\t\t\"outer product only supported \"\\\n\t\t\t\t\"for binary functions\");\n\t\treturn NULL;\n\t}\n\t\n\tif (PySequence_Length(args) != 2) {\n\t\tPyErr_SetString(PyExc_TypeError,\n\t\t\t\t\"exactly two arguments expected\");\n\t\treturn NULL;\n\t}\n\t\n\ttmp = PySequence_GetItem(args, 0);\n\tif (tmp == NULL) return NULL;\n\tap1 = (PyArrayObject *)\t\t\t\t\t\\\n\t\tPyArray_FromObject(tmp, PyArray_NOTYPE, 0, 0);\n\tPy_DECREF(tmp);\n\tif (ap1 == NULL) return NULL;\n\t\n\ttmp = PySequence_GetItem(args, 1);\n\tif (tmp == NULL) return NULL;\n\tap2 = (PyArrayObject *)PyArray_FromObject(tmp, PyArray_NOTYPE, 0, 0);\n\tPy_DECREF(tmp);\n\tif (ap2 == NULL) {Py_DECREF(ap1); return NULL;}\n\n\t/* Construct new shape tuple */\n\tshape1 = PyTuple_New(ap1->nd);\n\tif (shape1 == NULL) goto fail;\n\tfor (i=0; ind; i++) \n\t\tPyTuple_SET_ITEM(shape1, i, \n\t\t\t\t PyLong_FromLongLong((longlong)ap1->\t\\\n\t\t\t\t\t\t dimensions[i]));\n\t\n\tshape2 = PyTuple_New(ap2->nd);\n\tfor (i=0; ind; i++) \n\t\tPyTuple_SET_ITEM(shape2, i, PyInt_FromLong((long) 1));\n\tif (shape2 == NULL) {Py_DECREF(shape1); goto fail;}\n\tnewshape = PyNumber_Add(shape1, shape2);\n\tPy_DECREF(shape1);\n\tPy_DECREF(shape2);\n\tif (newshape == NULL) goto fail;\n\t\n\tap_new = (PyArrayObject *)PyArray_Reshape(ap1, newshape);\n\tPy_DECREF(newshape);\n\tif (ap_new == NULL) goto fail;\n\t\n\tnew_args = Py_BuildValue(\"(OO)\", ap_new, ap2);\n\tPy_DECREF(ap1);\n\tPy_DECREF(ap2);\n\tPy_DECREF(ap_new);\t\n\tret = ufunc_generic_call(self, new_args);\n\tPy_DECREF(new_args);\n\treturn ret;\n\n fail:\n\tPy_XDECREF(ap1);\n\tPy_XDECREF(ap2);\n\tPy_XDECREF(ap_new);\n\treturn NULL;\n\n}\n\n\nstatic PyObject *\nufunc_reduce(PyUFuncObject *self, PyObject *args, PyObject *kwds) \n{\n\t\n\treturn PyUFunc_GenericReduction(self, args, kwds, UFUNC_REDUCE);\n}\n\nstatic PyObject *\nufunc_accumulate(PyUFuncObject *self, PyObject *args, PyObject *kwds) \n{\n\t\n\treturn PyUFunc_GenericReduction(self, args, kwds, UFUNC_ACCUMULATE);\n}\n\nstatic PyObject *\nufunc_reduceat(PyUFuncObject *self, PyObject *args, PyObject *kwds) \n{\t\n\treturn PyUFunc_GenericReduction(self, args, kwds, UFUNC_REDUCEAT);\n}\n\n\nstatic struct PyMethodDef ufunc_methods[] = {\n\t{\"reduce\", (PyCFunction)ufunc_reduce, METH_VARARGS | METH_KEYWORDS},\n\t{\"accumulate\", (PyCFunction)ufunc_accumulate, \n\t METH_VARARGS | METH_KEYWORDS},\n\t{\"reduceat\", (PyCFunction)ufunc_reduceat, \n\t METH_VARARGS | METH_KEYWORDS},\t\n\t{\"outer\", (PyCFunction)ufunc_outer, METH_VARARGS},\n\t{NULL,\t\tNULL}\t\t/* sentinel */\n};\n\n\n\n/* construct the string\n y1,y2,...,yn\n*/\n\nstatic void\n_makeargs(int num, char ltr, char *str) \n{\n\tint ind=0;\n\tint k;\n\tstatic char *digits=\"123456789ABCDE\";\n\n\tif (num == 1) {\n\t\tstr[0] = ltr;\n\t\tind = 1;\n\t}\n\telse {\n\t\tfor (k=0; ktype;\n\tPy_DECREF(descr);\n\treturn ret;\n} \n\nstatic PyObject *\nufunc_getattr(PyUFuncObject *self, char *name)\n{\n\tPyObject *obj;\n\t/* Put docstring first or FindMethod finds it...*/\n\t/* could so some introspection on name and nin + nout */\n\t/* to automate the first part of it */\n\t/* the doc string shouldn't need the calling convention */\n\tif (strcmp(name, \"__doc__\") == 0) {\n\t\tstatic char doc[256];\n\t\tstatic char tmp1[3*MAX_ARGS+2];\n\t\tstatic char tmp2[3*MAX_ARGS+2];\n\t\t/* construct \n\t\t y1,y2,,... = name(x1,x2,...) __doc__\n\t\t*/\t\t\n\t\t_makeargs(self->nout, 'y', tmp1);\n\t\t_makeargs(self->nin, 'x', tmp2);\n\t\tsnprintf(doc, 256, \"%s = %s(%s) %s\", tmp1, self->name, \n\t\t\t tmp2, self->doc);\n\t\treturn PyString_FromString(doc);\n\t}\n\tobj = Py_FindMethod(ufunc_methods, (PyObject *)self, name);\n\tif (obj != NULL) return obj;\n\tPyErr_Clear();\n\tif (strcmp(name, \"nin\") == 0) {\n\t\treturn PyInt_FromLong(self->nin);\n\t}\n\telse if (strcmp(name, \"nout\") == 0) {\n\t\treturn PyInt_FromLong(self->nout);\n\t}\n\telse if (strcmp(name, \"nargs\") == 0) {\n\t\treturn PyInt_FromLong(self->nargs);\n\t}\n\telse if (strcmp(name, \"ntypes\") == 0) {\n\t\treturn PyInt_FromLong(self->ntypes);\n\t}\n\telse if (strcmp(name, \"types\") == 0) {\n\t\t/* return a list with types grouped\n\t\t input->output */\n\t\tPyObject *list;\n\t\tPyObject *str;\n\t\tint k, j, n, nt=self->ntypes;\n\t\tint ni = self->nin;\n\t\tint no = self->nout;\n\t\tchar *t;\n\t\tlist = PyList_New(nt);\n\t\tif (list == NULL) return NULL;\n\t\tt = _pya_malloc(no+ni+2);\n\t\tn = 0;\n\t\tfor (k=0; ktypes[n]);\n\t\t\t\tn++;\n\t\t\t}\n\t\t\tt[ni] = '-';\n\t\t\tt[ni+1] = '>';\n\t\t\tfor (j=0; jtypes[n]);\n\t\t\t\tn++;\n\t\t\t}\n\t\t\tstr = PyString_FromStringAndSize(t, no+ni+2);\n\t\t\tPyList_SET_ITEM(list, k, str);\n\t\t}\n\t\t_pya_free(t);\n\t\treturn list;\n\t\t\n\t}\n\telse if (strcmp(name, \"__name__\") == 0) {\n\t\treturn PyString_FromString(self->name);\n\t}\n\telse if (strcmp(name, \"identity\") == 0) {\n\t\tswitch(self->identity) {\n\t\tcase PyUFunc_One:\n\t\t\treturn PyInt_FromLong(1);\n\t\tcase PyUFunc_Zero:\n\t\t\treturn PyInt_FromLong(0);\n\t\tdefault:\n\t\t\tPy_INCREF(Py_None);\n\t\t\treturn Py_None;\n\t\t}\n\t}\n\tPyErr_SetString(PyExc_AttributeError, name);\n\treturn NULL;\n}\n\n#undef _typecharfromnum\n\nstatic int\nufunc_setattr(PyUFuncObject *self, char *name, PyObject *v) \n{\n\treturn -1;\n}\n\nstatic char Ufunctype__doc__[] = \n\t\"Optimized functions make it possible to implement arithmetic \"\\\n\t\"with arrays efficiently\";\n\nstatic PyTypeObject PyUFunc_Type = {\n\tPyObject_HEAD_INIT(0)\n\t0,\t\t\t\t/*ob_size*/\n\t\"numpy.ufunc\",\t\t\t/*tp_name*/\n\tsizeof(PyUFuncObject),\t\t/*tp_basicsize*/\n\t0,\t\t\t\t/*tp_itemsize*/\n\t/* methods */\n\t(destructor)ufunc_dealloc,\t/*tp_dealloc*/\n\t(printfunc)0,\t\t /*tp_print*/\n\t(getattrfunc)ufunc_getattr,\t/*tp_getattr*/\n\t(setattrfunc)ufunc_setattr,\t/*tp_setattr*/\n\t(cmpfunc)0,\t \t/*tp_compare*/\n\t(reprfunc)ufunc_repr,\t\t/*tp_repr*/\n\t0,\t\t\t /*tp_as_number*/\n\t0,\t\t /*tp_as_sequence*/\n\t0,\t\t /*tp_as_mapping*/\n\t(hashfunc)0,\t\t/*tp_hash*/\n\t(ternaryfunc)ufunc_generic_call,\t\t/*tp_call*/\n\t(reprfunc)ufunc_repr,\t\t/*tp_str*/\n\t\t\n\t/* Space for future expansion */\n\t0L,0L,0L,0L,\n\tUfunctype__doc__ /* Documentation string */\n};\n\n/* End of code for ufunc objects */\n/* -------------------------------------------------------- */\n", + "methods": [ + { + "name": "PyUFunc_ff_f_As_dd_d", + "long_name": "PyUFunc_ff_f_As_dd_d( char ** args , intp * dimensions , intp * steps , * func)", + "filename": "ufuncobject.c", + "nloc": 10, + "complexity": 2, + "token_count": 146, + "parameters": [ + "args", + "dimensions", + "steps", + "func" + ], + "start_line": 41, + "end_line": 51, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 11, + "top_nesting_level": 0 + }, + { + "name": "PyUFunc_ff_f", + "long_name": "PyUFunc_ff_f( char ** args , intp * dimensions , intp * steps , * func)", + "filename": "ufuncobject.c", + "nloc": 10, + "complexity": 2, + "token_count": 136, + "parameters": [ + "args", + "dimensions", + "steps", + "func" + ], + "start_line": 55, + "end_line": 66, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 12, + "top_nesting_level": 0 + }, + { + "name": "PyUFunc_dd_d", + "long_name": "PyUFunc_dd_d( char ** args , intp * dimensions , intp * steps , * func)", + "filename": "ufuncobject.c", + "nloc": 10, + "complexity": 2, + "token_count": 137, + "parameters": [ + "args", + "dimensions", + "steps", + "func" + ], + "start_line": 70, + "end_line": 81, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 12, + "top_nesting_level": 0 + }, + { + "name": "PyUFunc_gg_g", + "long_name": "PyUFunc_gg_g( char ** args , intp * dimensions , intp * steps , * func)", + "filename": "ufuncobject.c", + "nloc": 11, + "complexity": 2, + "token_count": 137, + "parameters": [ + "args", + "dimensions", + "steps", + "func" + ], + "start_line": 85, + "end_line": 96, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 12, + "top_nesting_level": 0 + }, + { + "name": "PyUFunc_FF_F_As_DD_D", + "long_name": "PyUFunc_FF_F_As_DD_D( char ** args , intp * dimensions , intp * steps , * func)", + "filename": "ufuncobject.c", + "nloc": 13, + "complexity": 2, + "token_count": 225, + "parameters": [ + "args", + "dimensions", + "steps", + "func" + ], + "start_line": 101, + "end_line": 114, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 14, + "top_nesting_level": 0 + }, + { + "name": "PyUFunc_DD_D", + "long_name": "PyUFunc_DD_D( char ** args , intp * dimensions , intp * steps , * func)", + "filename": "ufuncobject.c", + "nloc": 13, + "complexity": 2, + "token_count": 219, + "parameters": [ + "args", + "dimensions", + "steps", + "func" + ], + "start_line": 118, + "end_line": 131, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 14, + "top_nesting_level": 0 + }, + { + "name": "PyUFunc_FF_F", + "long_name": "PyUFunc_FF_F( char ** args , intp * dimensions , intp * steps , * func)", + "filename": "ufuncobject.c", + "nloc": 13, + "complexity": 2, + "token_count": 219, + "parameters": [ + "args", + "dimensions", + "steps", + "func" + ], + "start_line": 135, + "end_line": 148, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 14, + "top_nesting_level": 0 + }, + { + "name": "PyUFunc_GG_G", + "long_name": "PyUFunc_GG_G( char ** args , intp * dimensions , intp * steps , * func)", + "filename": "ufuncobject.c", + "nloc": 15, + "complexity": 2, + "token_count": 219, + "parameters": [ + "args", + "dimensions", + "steps", + "func" + ], + "start_line": 152, + "end_line": 167, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 16, + "top_nesting_level": 0 + }, + { + "name": "PyUFunc_OO_O", + "long_name": "PyUFunc_OO_O( char ** args , intp * dimensions , intp * steps , * func)", + "filename": "ufuncobject.c", + "nloc": 22, + "complexity": 6, + "token_count": 236, + "parameters": [ + "args", + "dimensions", + "steps", + "func" + ], + "start_line": 171, + "end_line": 193, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 23, + "top_nesting_level": 0 + }, + { + "name": "PyUFunc_f_f_As_d_d", + "long_name": "PyUFunc_f_f_As_d_d( char ** args , intp * dimensions , intp * steps , * func)", + "filename": "ufuncobject.c", + "nloc": 8, + "complexity": 2, + "token_count": 106, + "parameters": [ + "args", + "dimensions", + "steps", + "func" + ], + "start_line": 205, + "end_line": 212, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 8, + "top_nesting_level": 0 + }, + { + "name": "PyUFunc_d_d", + "long_name": "PyUFunc_d_d( char ** args , intp * dimensions , intp * steps , * func)", + "filename": "ufuncobject.c", + "nloc": 8, + "complexity": 2, + "token_count": 93, + "parameters": [ + "args", + "dimensions", + "steps", + "func" + ], + "start_line": 216, + "end_line": 223, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 8, + "top_nesting_level": 0 + }, + { + "name": "PyUFunc_f_f", + "long_name": "PyUFunc_f_f( char ** args , intp * dimensions , intp * steps , * func)", + "filename": "ufuncobject.c", + "nloc": 9, + "complexity": 2, + "token_count": 101, + "parameters": [ + "args", + "dimensions", + "steps", + "func" + ], + "start_line": 227, + "end_line": 235, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 9, + "top_nesting_level": 0 + }, + { + "name": "PyUFunc_g_g", + "long_name": "PyUFunc_g_g( char ** args , intp * dimensions , intp * steps , * func)", + "filename": "ufuncobject.c", + "nloc": 10, + "complexity": 2, + "token_count": 102, + "parameters": [ + "args", + "dimensions", + "steps", + "func" + ], + "start_line": 239, + "end_line": 248, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 10, + "top_nesting_level": 0 + }, + { + "name": "PyUFunc_F_F_As_D_D", + "long_name": "PyUFunc_F_F_As_D_D( char ** args , intp * dimensions , intp * steps , * func)", + "filename": "ufuncobject.c", + "nloc": 12, + "complexity": 2, + "token_count": 164, + "parameters": [ + "args", + "dimensions", + "steps", + "func" + ], + "start_line": 253, + "end_line": 264, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 12, + "top_nesting_level": 0 + }, + { + "name": "PyUFunc_F_F", + "long_name": "PyUFunc_F_F( char ** args , intp * dimensions , intp * steps , * func)", + "filename": "ufuncobject.c", + "nloc": 12, + "complexity": 2, + "token_count": 150, + "parameters": [ + "args", + "dimensions", + "steps", + "func" + ], + "start_line": 268, + "end_line": 279, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 12, + "top_nesting_level": 0 + }, + { + "name": "PyUFunc_D_D", + "long_name": "PyUFunc_D_D( char ** args , intp * dimensions , intp * steps , * func)", + "filename": "ufuncobject.c", + "nloc": 12, + "complexity": 2, + "token_count": 150, + "parameters": [ + "args", + "dimensions", + "steps", + "func" + ], + "start_line": 284, + "end_line": 295, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 12, + "top_nesting_level": 0 + }, + { + "name": "PyUFunc_G_G", + "long_name": "PyUFunc_G_G( char ** args , intp * dimensions , intp * steps , * func)", + "filename": "ufuncobject.c", + "nloc": 12, + "complexity": 2, + "token_count": 150, + "parameters": [ + "args", + "dimensions", + "steps", + "func" + ], + "start_line": 300, + "end_line": 311, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 12, + "top_nesting_level": 0 + }, + { + "name": "PyUFunc_O_O", + "long_name": "PyUFunc_O_O( char ** args , intp * dimensions , intp * steps , * func)", + "filename": "ufuncobject.c", + "nloc": 15, + "complexity": 5, + "token_count": 149, + "parameters": [ + "args", + "dimensions", + "steps", + "func" + ], + "start_line": 315, + "end_line": 330, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 16, + "top_nesting_level": 0 + }, + { + "name": "PyUFunc_O_O_method", + "long_name": "PyUFunc_O_O_method( char ** args , intp * dimensions , intp * steps , * func)", + "filename": "ufuncobject.c", + "nloc": 21, + "complexity": 6, + "token_count": 190, + "parameters": [ + "args", + "dimensions", + "steps", + "func" + ], + "start_line": 334, + "end_line": 356, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 23, + "top_nesting_level": 0 + }, + { + "name": "PyUFunc_On_Om", + "long_name": "PyUFunc_On_Om( char ** args , intp * dimensions , intp * steps , * func)", + "filename": "ufuncobject.c", + "nloc": 47, + "complexity": 11, + "token_count": 357, + "parameters": [ + "args", + "dimensions", + "steps", + "func" + ], + "start_line": 366, + "end_line": 414, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 49, + "top_nesting_level": 0 + }, + { + "name": "_error_handler", + "long_name": "_error_handler( int method , PyObject * errobj , char * errtype , int retstatus)", + "filename": "ufuncobject.c", + "nloc": 41, + "complexity": 8, + "token_count": 211, + "parameters": [ + "method", + "errobj", + "errtype", + "retstatus" + ], + "start_line": 438, + "end_line": 484, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 47, + "top_nesting_level": 0 + }, + { + "name": "PyUFunc_checkfperr", + "long_name": "PyUFunc_checkfperr( int errmask , PyObject * errobj)", + "filename": "ufuncobject.c", + "nloc": 13, + "complexity": 3, + "token_count": 60, + "parameters": [ + "errmask", + "errobj" + ], + "start_line": 489, + "end_line": 518, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 30, + "top_nesting_level": 0 + }, + { + "name": "PyUFunc_clearfperr", + "long_name": "PyUFunc_clearfperr()", + "filename": "ufuncobject.c", + "nloc": 5, + "complexity": 1, + "token_count": 12, + "parameters": [], + "start_line": 524, + "end_line": 529, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 6, + "top_nesting_level": 0 + }, + { + "name": "_lowest_type", + "long_name": "_lowest_type( char intype)", + "filename": "ufuncobject.c", + "nloc": 23, + "complexity": 13, + "token_count": 66, + "parameters": [ + "intype" + ], + "start_line": 551, + "end_line": 577, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 27, + "top_nesting_level": 0 + }, + { + "name": "_cancoerce", + "long_name": "_cancoerce( char thistype , char neededtype , char scalar)", + "filename": "ufuncobject.c", + "nloc": 21, + "complexity": 9, + "token_count": 101, + "parameters": [ + "thistype", + "neededtype", + "scalar" + ], + "start_line": 583, + "end_line": 604, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 22, + "top_nesting_level": 0 + }, + { + "name": "select_types", + "long_name": "select_types( PyUFuncObject * self , int * arg_types , PyUFuncGenericFunction * function , ** data , char * scalars)", + "filename": "ufuncobject.c", + "nloc": 76, + "complexity": 19, + "token_count": 479, + "parameters": [ + "self", + "arg_types", + "function", + "data", + "scalars" + ], + "start_line": 608, + "end_line": 695, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 88, + "top_nesting_level": 0 + }, + { + "name": "PyUFunc_GetPyValues", + "long_name": "PyUFunc_GetPyValues( char * name , int * bufsize , int * errmask , PyObject ** errobj)", + "filename": "ufuncobject.c", + "nloc": 67, + "complexity": 18, + "token_count": 387, + "parameters": [ + "name", + "bufsize", + "errmask", + "errobj" + ], + "start_line": 701, + "end_line": 773, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 73, + "top_nesting_level": 0 + }, + { + "name": "_signbit_set", + "long_name": "_signbit_set( PyArrayObject * arr)", + "filename": "ufuncobject.c", + "nloc": 16, + "complexity": 5, + "token_count": 89, + "parameters": [ + "arr" + ], + "start_line": 776, + "end_line": 793, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 18, + "top_nesting_level": 0 + }, + { + "name": "_scalar_kind", + "long_name": "_scalar_kind( int typenum , PyArrayObject ** arr)", + "filename": "ufuncobject.c", + "nloc": 12, + "complexity": 7, + "token_count": 78, + "parameters": [ + "typenum", + "arr" + ], + "start_line": 796, + "end_line": 808, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 13, + "top_nesting_level": 0 + }, + { + "name": "_create_copies", + "long_name": "_create_copies( PyUFuncLoopObject * loop , int * arg_types , PyArrayObject ** mps)", + "filename": "ufuncobject.c", + "nloc": 33, + "complexity": 8, + "token_count": 236, + "parameters": [ + "loop", + "arg_types", + "mps" + ], + "start_line": 817, + "end_line": 855, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 39, + "top_nesting_level": 0 + }, + { + "name": "_has_reflected_op", + "long_name": "_has_reflected_op( PyObject * op , char * name)", + "filename": "ufuncobject.c", + "nloc": 17, + "complexity": 1, + "token_count": 93, + "parameters": [ + "op", + "name" + ], + "start_line": 861, + "end_line": 877, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 17, + "top_nesting_level": 0 + }, + { + "name": "construct_matrices", + "long_name": "construct_matrices( PyUFuncLoopObject * loop , PyObject * args , PyArrayObject ** mps)", + "filename": "ufuncobject.c", + "nloc": 289, + "complexity": 76, + "token_count": 2255, + "parameters": [ + "loop", + "args", + "mps" + ], + "start_line": 882, + "end_line": 1274, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 393, + "top_nesting_level": 0 + }, + { + "name": "ufuncreduce_dealloc", + "long_name": "ufuncreduce_dealloc( PyUFuncReduceObject * self)", + "filename": "ufuncobject.c", + "nloc": 13, + "complexity": 3, + "token_count": 76, + "parameters": [ + "self" + ], + "start_line": 1277, + "end_line": 1289, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 13, + "top_nesting_level": 0 + }, + { + "name": "ufuncloop_dealloc", + "long_name": "ufuncloop_dealloc( PyUFuncLoopObject * self)", + "filename": "ufuncobject.c", + "nloc": 12, + "complexity": 4, + "token_count": 86, + "parameters": [ + "self" + ], + "start_line": 1292, + "end_line": 1304, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 13, + "top_nesting_level": 0 + }, + { + "name": "construct_loop", + "long_name": "construct_loop( PyUFuncObject * self , PyObject * args , PyArrayObject ** mps)", + "filename": "ufuncobject.c", + "nloc": 30, + "complexity": 7, + "token_count": 209, + "parameters": [ + "self", + "args", + "mps" + ], + "start_line": 1307, + "end_line": 1344, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 38, + "top_nesting_level": 0 + }, + { + "name": "PyUFunc_GenericFunction", + "long_name": "PyUFunc_GenericFunction( PyUFuncObject * self , PyObject * args , PyArrayObject ** mps)", + "filename": "ufuncobject.c", + "nloc": 186, + "complexity": 48, + "token_count": 1403, + "parameters": [ + "self", + "args", + "mps" + ], + "start_line": 1416, + "end_line": 1684, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 269, + "top_nesting_level": 0 + }, + { + "name": "_getidentity", + "long_name": "_getidentity( PyUFuncObject * self , int otype , char * str)", + "filename": "ufuncobject.c", + "nloc": 20, + "complexity": 3, + "token_count": 119, + "parameters": [ + "self", + "otype", + "str" + ], + "start_line": 1687, + "end_line": 1708, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 22, + "top_nesting_level": 0 + }, + { + "name": "_create_reduce_copy", + "long_name": "_create_reduce_copy( PyUFuncReduceObject * loop , PyArrayObject ** arr , int rtype)", + "filename": "ufuncobject.c", + "nloc": 20, + "complexity": 5, + "token_count": 127, + "parameters": [ + "loop", + "arr", + "rtype" + ], + "start_line": 1711, + "end_line": 1741, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 31, + "top_nesting_level": 0 + }, + { + "name": "construct_reduce", + "long_name": "construct_reduce( PyUFuncObject * self , PyArrayObject ** arr , int axis , int otype , int operation , intp ind_size , char * str)", + "filename": "ufuncobject.c", + "nloc": 172, + "complexity": 37, + "token_count": 1390, + "parameters": [ + "self", + "arr", + "axis", + "otype", + "operation", + "ind_size", + "str" + ], + "start_line": 1744, + "end_line": 1957, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 214, + "top_nesting_level": 0 + }, + { + "name": "PyUFunc_Reduce", + "long_name": "PyUFunc_Reduce( PyUFuncObject * self , PyArrayObject * arr , int axis , int otype)", + "filename": "ufuncobject.c", + "nloc": 105, + "complexity": 20, + "token_count": 747, + "parameters": [ + "self", + "arr", + "axis", + "otype" + ], + "start_line": 1969, + "end_line": 2104, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 136, + "top_nesting_level": 0 + }, + { + "name": "PyUFunc_Accumulate", + "long_name": "PyUFunc_Accumulate( PyUFuncObject * self , PyArrayObject * arr , int axis , int otype)", + "filename": "ufuncobject.c", + "nloc": 109, + "complexity": 20, + "token_count": 779, + "parameters": [ + "self", + "arr", + "axis", + "otype" + ], + "start_line": 2108, + "end_line": 2246, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 139, + "top_nesting_level": 0 + }, + { + "name": "PyUFunc_Reduceat", + "long_name": "PyUFunc_Reduceat( PyUFuncObject * self , PyArrayObject * arr , PyArrayObject * ind , int axis , int otype)", + "filename": "ufuncobject.c", + "nloc": 111, + "complexity": 23, + "token_count": 816, + "parameters": [ + "self", + "arr", + "ind", + "axis", + "otype" + ], + "start_line": 2268, + "end_line": 2397, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 130, + "top_nesting_level": 0 + }, + { + "name": "PyUFunc_GenericReduction", + "long_name": "PyUFunc_GenericReduction( PyUFuncObject * self , PyObject * args , PyObject * kwds , int operation)", + "filename": "ufuncobject.c", + "nloc": 121, + "complexity": 32, + "token_count": 759, + "parameters": [ + "self", + "args", + "kwds", + "operation" + ], + "start_line": 2406, + "end_line": 2541, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 136, + "top_nesting_level": 0 + }, + { + "name": "_find_array_wrap", + "long_name": "_find_array_wrap( PyObject * args)", + "filename": "ufuncobject.c", + "nloc": 44, + "complexity": 10, + "token_count": 244, + "parameters": [ + "args" + ], + "start_line": 2544, + "end_line": 2588, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 45, + "top_nesting_level": 0 + }, + { + "name": "ufunc_generic_call", + "long_name": "ufunc_generic_call( PyUFuncObject * self , PyObject * args)", + "filename": "ufuncobject.c", + "nloc": 61, + "complexity": 16, + "token_count": 449, + "parameters": [ + "self", + "args" + ], + "start_line": 2591, + "end_line": 2670, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 80, + "top_nesting_level": 0 + }, + { + "name": "ufunc_update_use_defaults", + "long_name": "ufunc_update_use_defaults( PyObject * dummy , PyObject * args)", + "filename": "ufuncobject.c", + "nloc": 15, + "complexity": 6, + "token_count": 100, + "parameters": [ + "dummy", + "args" + ], + "start_line": 2673, + "end_line": 2691, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 19, + "top_nesting_level": 0 + }, + { + "name": "ufunc_frompyfunc", + "long_name": "ufunc_frompyfunc( PyObject * dummy , PyObject * args , PyObject * kwds)", + "filename": "ufuncobject.c", + "nloc": 59, + "complexity": 10, + "token_count": 528, + "parameters": [ + "dummy", + "args", + "kwds" + ], + "start_line": 2699, + "end_line": 2788, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 90, + "top_nesting_level": 0 + }, + { + "name": "PyUFunc_FromFuncAndData", + "long_name": "PyUFunc_FromFuncAndData( PyUFuncGenericFunction * func , ** data , char * types , int ntypes , int nin , int nout , int identity , char * name , char * doc , int check_return)", + "filename": "ufuncobject.c", + "nloc": 27, + "complexity": 4, + "token_count": 193, + "parameters": [ + "func", + "data", + "types", + "ntypes", + "nin", + "nout", + "identity", + "name", + "doc", + "check_return" + ], + "start_line": 2793, + "end_line": 2825, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 33, + "top_nesting_level": 0 + }, + { + "name": "PyUFunc_RegisterLoopForType", + "long_name": "PyUFunc_RegisterLoopForType( PyUFuncObject * ufunc , int usertype , PyUFuncGenericFunction function , * data)", + "filename": "ufuncobject.c", + "nloc": 43, + "complexity": 8, + "token_count": 251, + "parameters": [ + "ufunc", + "usertype", + "function", + "data" + ], + "start_line": 2829, + "end_line": 2873, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 45, + "top_nesting_level": 0 + }, + { + "name": "ufunc_dealloc", + "long_name": "ufunc_dealloc( PyUFuncObject * self)", + "filename": "ufuncobject.c", + "nloc": 7, + "complexity": 2, + "token_count": 40, + "parameters": [ + "self" + ], + "start_line": 2876, + "end_line": 2882, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 7, + "top_nesting_level": 0 + }, + { + "name": "ufunc_repr", + "long_name": "ufunc_repr( PyUFuncObject * self)", + "filename": "ufuncobject.c", + "nloc": 6, + "complexity": 1, + "token_count": 31, + "parameters": [ + "self" + ], + "start_line": 2885, + "end_line": 2892, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 8, + "top_nesting_level": 0 + }, + { + "name": "ufunc_outer", + "long_name": "ufunc_outer( PyUFuncObject * self , PyObject * args)", + "filename": "ufuncobject.c", + "nloc": 59, + "complexity": 13, + "token_count": 428, + "parameters": [ + "self", + "args" + ], + "start_line": 2904, + "end_line": 2973, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 70, + "top_nesting_level": 0 + }, + { + "name": "ufunc_reduce", + "long_name": "ufunc_reduce( PyUFuncObject * self , PyObject * args , PyObject * kwds)", + "filename": "ufuncobject.c", + "nloc": 4, + "complexity": 1, + "token_count": 28, + "parameters": [ + "self", + "args", + "kwds" + ], + "start_line": 2977, + "end_line": 2981, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 5, + "top_nesting_level": 0 + }, + { + "name": "ufunc_accumulate", + "long_name": "ufunc_accumulate( PyUFuncObject * self , PyObject * args , PyObject * kwds)", + "filename": "ufuncobject.c", + "nloc": 4, + "complexity": 1, + "token_count": 28, + "parameters": [ + "self", + "args", + "kwds" + ], + "start_line": 2984, + "end_line": 2988, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 5, + "top_nesting_level": 0 + }, + { + "name": "ufunc_reduceat", + "long_name": "ufunc_reduceat( PyUFuncObject * self , PyObject * args , PyObject * kwds)", + "filename": "ufuncobject.c", + "nloc": 4, + "complexity": 1, + "token_count": 28, + "parameters": [ + "self", + "args", + "kwds" + ], + "start_line": 2991, + "end_line": 2994, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 4, + "top_nesting_level": 0 + }, + { + "name": "_makeargs", + "long_name": "_makeargs( int num , char ltr , char * str)", + "filename": "ufuncobject.c", + "nloc": 20, + "complexity": 3, + "token_count": 117, + "parameters": [ + "num", + "ltr", + "str" + ], + "start_line": 3014, + "end_line": 3036, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 23, + "top_nesting_level": 0 + }, + { + "name": "_typecharfromnum", + "long_name": "_typecharfromnum( int num)", + "filename": "ufuncobject.c", + "nloc": 8, + "complexity": 1, + "token_count": 35, + "parameters": [ + "num" + ], + "start_line": 3039, + "end_line": 3047, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 9, + "top_nesting_level": 0 + }, + { + "name": "ufunc_getattr", + "long_name": "ufunc_getattr( PyUFuncObject * self , char * name)", + "filename": "ufuncobject.c", + "nloc": 74, + "complexity": 16, + "token_count": 520, + "parameters": [ + "self", + "name" + ], + "start_line": 3050, + "end_line": 3133, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 84, + "top_nesting_level": 0 + }, + { + "name": "ufunc_setattr", + "long_name": "ufunc_setattr( PyUFuncObject * self , char * name , PyObject * v)", + "filename": "ufuncobject.c", + "nloc": 4, + "complexity": 1, + "token_count": 20, + "parameters": [ + "self", + "name", + "v" + ], + "start_line": 3138, + "end_line": 3141, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 4, + "top_nesting_level": 0 + } + ], + "methods_before": [ + { + "name": "PyUFunc_ff_f_As_dd_d", + "long_name": "PyUFunc_ff_f_As_dd_d( char ** args , intp * dimensions , intp * steps , * func)", + "filename": "ufuncobject.c", + "nloc": 10, + "complexity": 2, + "token_count": 146, + "parameters": [ + "args", + "dimensions", + "steps", + "func" + ], + "start_line": 41, + "end_line": 51, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 11, + "top_nesting_level": 0 + }, + { + "name": "PyUFunc_ff_f", + "long_name": "PyUFunc_ff_f( char ** args , intp * dimensions , intp * steps , * func)", + "filename": "ufuncobject.c", + "nloc": 10, + "complexity": 2, + "token_count": 136, + "parameters": [ + "args", + "dimensions", + "steps", + "func" + ], + "start_line": 55, + "end_line": 66, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 12, + "top_nesting_level": 0 + }, + { + "name": "PyUFunc_dd_d", + "long_name": "PyUFunc_dd_d( char ** args , intp * dimensions , intp * steps , * func)", + "filename": "ufuncobject.c", + "nloc": 10, + "complexity": 2, + "token_count": 137, + "parameters": [ + "args", + "dimensions", + "steps", + "func" + ], + "start_line": 70, + "end_line": 81, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 12, + "top_nesting_level": 0 + }, + { + "name": "PyUFunc_gg_g", + "long_name": "PyUFunc_gg_g( char ** args , intp * dimensions , intp * steps , * func)", + "filename": "ufuncobject.c", + "nloc": 11, + "complexity": 2, + "token_count": 137, + "parameters": [ + "args", + "dimensions", + "steps", + "func" + ], + "start_line": 85, + "end_line": 96, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 12, + "top_nesting_level": 0 + }, + { + "name": "PyUFunc_FF_F_As_DD_D", + "long_name": "PyUFunc_FF_F_As_DD_D( char ** args , intp * dimensions , intp * steps , * func)", + "filename": "ufuncobject.c", + "nloc": 13, + "complexity": 2, + "token_count": 225, + "parameters": [ + "args", + "dimensions", + "steps", + "func" + ], + "start_line": 101, + "end_line": 114, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 14, + "top_nesting_level": 0 + }, + { + "name": "PyUFunc_DD_D", + "long_name": "PyUFunc_DD_D( char ** args , intp * dimensions , intp * steps , * func)", + "filename": "ufuncobject.c", + "nloc": 13, + "complexity": 2, + "token_count": 219, + "parameters": [ + "args", + "dimensions", + "steps", + "func" + ], + "start_line": 118, + "end_line": 131, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 14, + "top_nesting_level": 0 + }, + { + "name": "PyUFunc_FF_F", + "long_name": "PyUFunc_FF_F( char ** args , intp * dimensions , intp * steps , * func)", + "filename": "ufuncobject.c", + "nloc": 13, + "complexity": 2, + "token_count": 219, + "parameters": [ + "args", + "dimensions", + "steps", + "func" + ], + "start_line": 135, + "end_line": 148, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 14, + "top_nesting_level": 0 + }, + { + "name": "PyUFunc_GG_G", + "long_name": "PyUFunc_GG_G( char ** args , intp * dimensions , intp * steps , * func)", + "filename": "ufuncobject.c", + "nloc": 15, + "complexity": 2, + "token_count": 219, + "parameters": [ + "args", + "dimensions", + "steps", + "func" + ], + "start_line": 152, + "end_line": 167, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 16, + "top_nesting_level": 0 + }, + { + "name": "PyUFunc_OO_O", + "long_name": "PyUFunc_OO_O( char ** args , intp * dimensions , intp * steps , * func)", + "filename": "ufuncobject.c", + "nloc": 22, + "complexity": 6, + "token_count": 236, + "parameters": [ + "args", + "dimensions", + "steps", + "func" + ], + "start_line": 171, + "end_line": 193, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 23, + "top_nesting_level": 0 + }, + { + "name": "PyUFunc_f_f_As_d_d", + "long_name": "PyUFunc_f_f_As_d_d( char ** args , intp * dimensions , intp * steps , * func)", + "filename": "ufuncobject.c", + "nloc": 8, + "complexity": 2, + "token_count": 106, + "parameters": [ + "args", + "dimensions", + "steps", + "func" + ], + "start_line": 205, + "end_line": 212, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 8, + "top_nesting_level": 0 + }, + { + "name": "PyUFunc_d_d", + "long_name": "PyUFunc_d_d( char ** args , intp * dimensions , intp * steps , * func)", + "filename": "ufuncobject.c", + "nloc": 8, + "complexity": 2, + "token_count": 93, + "parameters": [ + "args", + "dimensions", + "steps", + "func" + ], + "start_line": 216, + "end_line": 223, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 8, + "top_nesting_level": 0 + }, + { + "name": "PyUFunc_f_f", + "long_name": "PyUFunc_f_f( char ** args , intp * dimensions , intp * steps , * func)", + "filename": "ufuncobject.c", + "nloc": 9, + "complexity": 2, + "token_count": 101, + "parameters": [ + "args", + "dimensions", + "steps", + "func" + ], + "start_line": 227, + "end_line": 235, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 9, + "top_nesting_level": 0 + }, + { + "name": "PyUFunc_g_g", + "long_name": "PyUFunc_g_g( char ** args , intp * dimensions , intp * steps , * func)", + "filename": "ufuncobject.c", + "nloc": 10, + "complexity": 2, + "token_count": 102, + "parameters": [ + "args", + "dimensions", + "steps", + "func" + ], + "start_line": 239, + "end_line": 248, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 10, + "top_nesting_level": 0 + }, + { + "name": "PyUFunc_F_F_As_D_D", + "long_name": "PyUFunc_F_F_As_D_D( char ** args , intp * dimensions , intp * steps , * func)", + "filename": "ufuncobject.c", + "nloc": 12, + "complexity": 2, + "token_count": 164, + "parameters": [ + "args", + "dimensions", + "steps", + "func" + ], + "start_line": 253, + "end_line": 264, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 12, + "top_nesting_level": 0 + }, + { + "name": "PyUFunc_F_F", + "long_name": "PyUFunc_F_F( char ** args , intp * dimensions , intp * steps , * func)", + "filename": "ufuncobject.c", + "nloc": 12, + "complexity": 2, + "token_count": 150, + "parameters": [ + "args", + "dimensions", + "steps", + "func" + ], + "start_line": 268, + "end_line": 279, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 12, + "top_nesting_level": 0 + }, + { + "name": "PyUFunc_D_D", + "long_name": "PyUFunc_D_D( char ** args , intp * dimensions , intp * steps , * func)", + "filename": "ufuncobject.c", + "nloc": 12, + "complexity": 2, + "token_count": 150, + "parameters": [ + "args", + "dimensions", + "steps", + "func" + ], + "start_line": 284, + "end_line": 295, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 12, + "top_nesting_level": 0 + }, + { + "name": "PyUFunc_G_G", + "long_name": "PyUFunc_G_G( char ** args , intp * dimensions , intp * steps , * func)", + "filename": "ufuncobject.c", + "nloc": 12, + "complexity": 2, + "token_count": 150, + "parameters": [ + "args", + "dimensions", + "steps", + "func" + ], + "start_line": 300, + "end_line": 311, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 12, + "top_nesting_level": 0 + }, + { + "name": "PyUFunc_O_O", + "long_name": "PyUFunc_O_O( char ** args , intp * dimensions , intp * steps , * func)", + "filename": "ufuncobject.c", + "nloc": 15, + "complexity": 5, + "token_count": 149, + "parameters": [ + "args", + "dimensions", + "steps", + "func" + ], + "start_line": 315, + "end_line": 330, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 16, + "top_nesting_level": 0 + }, + { + "name": "PyUFunc_O_O_method", + "long_name": "PyUFunc_O_O_method( char ** args , intp * dimensions , intp * steps , * func)", + "filename": "ufuncobject.c", + "nloc": 21, + "complexity": 6, + "token_count": 190, + "parameters": [ + "args", + "dimensions", + "steps", + "func" + ], + "start_line": 334, + "end_line": 356, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 23, + "top_nesting_level": 0 + }, + { + "name": "PyUFunc_On_Om", + "long_name": "PyUFunc_On_Om( char ** args , intp * dimensions , intp * steps , * func)", + "filename": "ufuncobject.c", + "nloc": 47, + "complexity": 11, + "token_count": 357, + "parameters": [ + "args", + "dimensions", + "steps", + "func" + ], + "start_line": 366, + "end_line": 414, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 49, + "top_nesting_level": 0 + }, + { + "name": "_error_handler", + "long_name": "_error_handler( int method , PyObject * errobj , char * errtype , int retstatus)", + "filename": "ufuncobject.c", + "nloc": 41, + "complexity": 8, + "token_count": 211, + "parameters": [ + "method", + "errobj", + "errtype", + "retstatus" + ], + "start_line": 438, + "end_line": 484, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 47, + "top_nesting_level": 0 + }, + { + "name": "PyUFunc_checkfperr", + "long_name": "PyUFunc_checkfperr( int errmask , PyObject * errobj)", + "filename": "ufuncobject.c", + "nloc": 13, + "complexity": 3, + "token_count": 60, + "parameters": [ + "errmask", + "errobj" + ], + "start_line": 489, + "end_line": 518, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 30, + "top_nesting_level": 0 + }, + { + "name": "PyUFunc_clearfperr", + "long_name": "PyUFunc_clearfperr()", + "filename": "ufuncobject.c", + "nloc": 5, + "complexity": 1, + "token_count": 12, + "parameters": [], + "start_line": 524, + "end_line": 529, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 6, + "top_nesting_level": 0 + }, + { + "name": "_lowest_type", + "long_name": "_lowest_type( char intype)", + "filename": "ufuncobject.c", + "nloc": 23, + "complexity": 13, + "token_count": 66, + "parameters": [ + "intype" + ], + "start_line": 551, + "end_line": 577, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 27, + "top_nesting_level": 0 + }, + { + "name": "_cancoerce", + "long_name": "_cancoerce( char thistype , char neededtype , char scalar)", + "filename": "ufuncobject.c", + "nloc": 21, + "complexity": 9, + "token_count": 101, + "parameters": [ + "thistype", + "neededtype", + "scalar" + ], + "start_line": 583, + "end_line": 604, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 22, + "top_nesting_level": 0 + }, + { + "name": "select_types", + "long_name": "select_types( PyUFuncObject * self , int * arg_types , PyUFuncGenericFunction * function , ** data , char * scalars)", + "filename": "ufuncobject.c", + "nloc": 76, + "complexity": 19, + "token_count": 479, + "parameters": [ + "self", + "arg_types", + "function", + "data", + "scalars" + ], + "start_line": 608, + "end_line": 695, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 88, + "top_nesting_level": 0 + }, + { + "name": "PyUFunc_GetPyValues", + "long_name": "PyUFunc_GetPyValues( char * name , int * bufsize , int * errmask , PyObject ** errobj)", + "filename": "ufuncobject.c", + "nloc": 67, + "complexity": 18, + "token_count": 387, + "parameters": [ + "name", + "bufsize", + "errmask", + "errobj" + ], + "start_line": 701, + "end_line": 773, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 73, + "top_nesting_level": 0 + }, + { + "name": "_scalar_kind", + "long_name": "_scalar_kind( int typenum , PyArrayObject ** arr)", + "filename": "ufuncobject.c", + "nloc": 9, + "complexity": 6, + "token_count": 64, + "parameters": [ + "typenum", + "arr" + ], + "start_line": 777, + "end_line": 785, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 9, + "top_nesting_level": 0 + }, + { + "name": "_create_copies", + "long_name": "_create_copies( PyUFuncLoopObject * loop , int * arg_types , PyArrayObject ** mps)", + "filename": "ufuncobject.c", + "nloc": 33, + "complexity": 8, + "token_count": 236, + "parameters": [ + "loop", + "arg_types", + "mps" + ], + "start_line": 794, + "end_line": 832, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 39, + "top_nesting_level": 0 + }, + { + "name": "_has_reflected_op", + "long_name": "_has_reflected_op( PyObject * op , char * name)", + "filename": "ufuncobject.c", + "nloc": 17, + "complexity": 1, + "token_count": 93, + "parameters": [ + "op", + "name" + ], + "start_line": 838, + "end_line": 854, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 17, + "top_nesting_level": 0 + }, + { + "name": "construct_matrices", + "long_name": "construct_matrices( PyUFuncLoopObject * loop , PyObject * args , PyArrayObject ** mps)", + "filename": "ufuncobject.c", + "nloc": 289, + "complexity": 76, + "token_count": 2255, + "parameters": [ + "loop", + "args", + "mps" + ], + "start_line": 859, + "end_line": 1251, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 393, + "top_nesting_level": 0 + }, + { + "name": "ufuncreduce_dealloc", + "long_name": "ufuncreduce_dealloc( PyUFuncReduceObject * self)", + "filename": "ufuncobject.c", + "nloc": 13, + "complexity": 3, + "token_count": 76, + "parameters": [ + "self" + ], + "start_line": 1254, + "end_line": 1266, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 13, + "top_nesting_level": 0 + }, + { + "name": "ufuncloop_dealloc", + "long_name": "ufuncloop_dealloc( PyUFuncLoopObject * self)", + "filename": "ufuncobject.c", + "nloc": 12, + "complexity": 4, + "token_count": 86, + "parameters": [ + "self" + ], + "start_line": 1269, + "end_line": 1281, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 13, + "top_nesting_level": 0 + }, + { + "name": "construct_loop", + "long_name": "construct_loop( PyUFuncObject * self , PyObject * args , PyArrayObject ** mps)", + "filename": "ufuncobject.c", + "nloc": 30, + "complexity": 7, + "token_count": 209, + "parameters": [ + "self", + "args", + "mps" + ], + "start_line": 1284, + "end_line": 1321, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 38, + "top_nesting_level": 0 + }, + { + "name": "PyUFunc_GenericFunction", + "long_name": "PyUFunc_GenericFunction( PyUFuncObject * self , PyObject * args , PyArrayObject ** mps)", + "filename": "ufuncobject.c", + "nloc": 186, + "complexity": 48, + "token_count": 1403, + "parameters": [ + "self", + "args", + "mps" + ], + "start_line": 1393, + "end_line": 1661, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 269, + "top_nesting_level": 0 + }, + { + "name": "_getidentity", + "long_name": "_getidentity( PyUFuncObject * self , int otype , char * str)", + "filename": "ufuncobject.c", + "nloc": 20, + "complexity": 3, + "token_count": 119, + "parameters": [ + "self", + "otype", + "str" + ], + "start_line": 1664, + "end_line": 1685, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 22, + "top_nesting_level": 0 + }, + { + "name": "_create_reduce_copy", + "long_name": "_create_reduce_copy( PyUFuncReduceObject * loop , PyArrayObject ** arr , int rtype)", + "filename": "ufuncobject.c", + "nloc": 20, + "complexity": 5, + "token_count": 127, + "parameters": [ + "loop", + "arr", + "rtype" + ], + "start_line": 1688, + "end_line": 1718, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 31, + "top_nesting_level": 0 + }, + { + "name": "construct_reduce", + "long_name": "construct_reduce( PyUFuncObject * self , PyArrayObject ** arr , int axis , int otype , int operation , intp ind_size , char * str)", + "filename": "ufuncobject.c", + "nloc": 172, + "complexity": 37, + "token_count": 1390, + "parameters": [ + "self", + "arr", + "axis", + "otype", + "operation", + "ind_size", + "str" + ], + "start_line": 1721, + "end_line": 1934, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 214, + "top_nesting_level": 0 + }, + { + "name": "PyUFunc_Reduce", + "long_name": "PyUFunc_Reduce( PyUFuncObject * self , PyArrayObject * arr , int axis , int otype)", + "filename": "ufuncobject.c", + "nloc": 105, + "complexity": 20, + "token_count": 747, + "parameters": [ + "self", + "arr", + "axis", + "otype" + ], + "start_line": 1946, + "end_line": 2081, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 136, + "top_nesting_level": 0 + }, + { + "name": "PyUFunc_Accumulate", + "long_name": "PyUFunc_Accumulate( PyUFuncObject * self , PyArrayObject * arr , int axis , int otype)", + "filename": "ufuncobject.c", + "nloc": 109, + "complexity": 20, + "token_count": 779, + "parameters": [ + "self", + "arr", + "axis", + "otype" + ], + "start_line": 2085, + "end_line": 2223, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 139, + "top_nesting_level": 0 + }, + { + "name": "PyUFunc_Reduceat", + "long_name": "PyUFunc_Reduceat( PyUFuncObject * self , PyArrayObject * arr , PyArrayObject * ind , int axis , int otype)", + "filename": "ufuncobject.c", + "nloc": 111, + "complexity": 23, + "token_count": 816, + "parameters": [ + "self", + "arr", + "ind", + "axis", + "otype" + ], + "start_line": 2245, + "end_line": 2374, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 130, + "top_nesting_level": 0 + }, + { + "name": "PyUFunc_GenericReduction", + "long_name": "PyUFunc_GenericReduction( PyUFuncObject * self , PyObject * args , PyObject * kwds , int operation)", + "filename": "ufuncobject.c", + "nloc": 121, + "complexity": 32, + "token_count": 759, + "parameters": [ + "self", + "args", + "kwds", + "operation" + ], + "start_line": 2383, + "end_line": 2518, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 136, + "top_nesting_level": 0 + }, + { + "name": "_find_array_wrap", + "long_name": "_find_array_wrap( PyObject * args)", + "filename": "ufuncobject.c", + "nloc": 44, + "complexity": 10, + "token_count": 244, + "parameters": [ + "args" + ], + "start_line": 2521, + "end_line": 2565, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 45, + "top_nesting_level": 0 + }, + { + "name": "ufunc_generic_call", + "long_name": "ufunc_generic_call( PyUFuncObject * self , PyObject * args)", + "filename": "ufuncobject.c", + "nloc": 61, + "complexity": 16, + "token_count": 449, + "parameters": [ + "self", + "args" + ], + "start_line": 2568, + "end_line": 2647, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 80, + "top_nesting_level": 0 + }, + { + "name": "ufunc_update_use_defaults", + "long_name": "ufunc_update_use_defaults( PyObject * dummy , PyObject * args)", + "filename": "ufuncobject.c", + "nloc": 15, + "complexity": 6, + "token_count": 100, + "parameters": [ + "dummy", + "args" + ], + "start_line": 2650, + "end_line": 2668, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 19, + "top_nesting_level": 0 + }, + { + "name": "ufunc_frompyfunc", + "long_name": "ufunc_frompyfunc( PyObject * dummy , PyObject * args , PyObject * kwds)", + "filename": "ufuncobject.c", + "nloc": 59, + "complexity": 10, + "token_count": 528, + "parameters": [ + "dummy", + "args", + "kwds" + ], + "start_line": 2676, + "end_line": 2765, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 90, + "top_nesting_level": 0 + }, + { + "name": "PyUFunc_FromFuncAndData", + "long_name": "PyUFunc_FromFuncAndData( PyUFuncGenericFunction * func , ** data , char * types , int ntypes , int nin , int nout , int identity , char * name , char * doc , int check_return)", + "filename": "ufuncobject.c", + "nloc": 27, + "complexity": 4, + "token_count": 193, + "parameters": [ + "func", + "data", + "types", + "ntypes", + "nin", + "nout", + "identity", + "name", + "doc", + "check_return" + ], + "start_line": 2770, + "end_line": 2802, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 33, + "top_nesting_level": 0 + }, + { + "name": "PyUFunc_RegisterLoopForType", + "long_name": "PyUFunc_RegisterLoopForType( PyUFuncObject * ufunc , int usertype , PyUFuncGenericFunction function , * data)", + "filename": "ufuncobject.c", + "nloc": 43, + "complexity": 8, + "token_count": 251, + "parameters": [ + "ufunc", + "usertype", + "function", + "data" + ], + "start_line": 2806, + "end_line": 2850, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 45, + "top_nesting_level": 0 + }, + { + "name": "ufunc_dealloc", + "long_name": "ufunc_dealloc( PyUFuncObject * self)", + "filename": "ufuncobject.c", + "nloc": 7, + "complexity": 2, + "token_count": 40, + "parameters": [ + "self" + ], + "start_line": 2853, + "end_line": 2859, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 7, + "top_nesting_level": 0 + }, + { + "name": "ufunc_repr", + "long_name": "ufunc_repr( PyUFuncObject * self)", + "filename": "ufuncobject.c", + "nloc": 6, + "complexity": 1, + "token_count": 31, + "parameters": [ + "self" + ], + "start_line": 2862, + "end_line": 2869, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 8, + "top_nesting_level": 0 + }, + { + "name": "ufunc_outer", + "long_name": "ufunc_outer( PyUFuncObject * self , PyObject * args)", + "filename": "ufuncobject.c", + "nloc": 59, + "complexity": 13, + "token_count": 428, + "parameters": [ + "self", + "args" + ], + "start_line": 2881, + "end_line": 2950, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 70, + "top_nesting_level": 0 + }, + { + "name": "ufunc_reduce", + "long_name": "ufunc_reduce( PyUFuncObject * self , PyObject * args , PyObject * kwds)", + "filename": "ufuncobject.c", + "nloc": 4, + "complexity": 1, + "token_count": 28, + "parameters": [ + "self", + "args", + "kwds" + ], + "start_line": 2954, + "end_line": 2958, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 5, + "top_nesting_level": 0 + }, + { + "name": "ufunc_accumulate", + "long_name": "ufunc_accumulate( PyUFuncObject * self , PyObject * args , PyObject * kwds)", + "filename": "ufuncobject.c", + "nloc": 4, + "complexity": 1, + "token_count": 28, + "parameters": [ + "self", + "args", + "kwds" + ], + "start_line": 2961, + "end_line": 2965, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 5, + "top_nesting_level": 0 + }, + { + "name": "ufunc_reduceat", + "long_name": "ufunc_reduceat( PyUFuncObject * self , PyObject * args , PyObject * kwds)", + "filename": "ufuncobject.c", + "nloc": 4, + "complexity": 1, + "token_count": 28, + "parameters": [ + "self", + "args", + "kwds" + ], + "start_line": 2968, + "end_line": 2971, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 4, + "top_nesting_level": 0 + }, + { + "name": "_makeargs", + "long_name": "_makeargs( int num , char ltr , char * str)", + "filename": "ufuncobject.c", + "nloc": 20, + "complexity": 3, + "token_count": 117, + "parameters": [ + "num", + "ltr", + "str" + ], + "start_line": 2991, + "end_line": 3013, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 23, + "top_nesting_level": 0 + }, + { + "name": "_typecharfromnum", + "long_name": "_typecharfromnum( int num)", + "filename": "ufuncobject.c", + "nloc": 8, + "complexity": 1, + "token_count": 35, + "parameters": [ + "num" + ], + "start_line": 3016, + "end_line": 3024, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 9, + "top_nesting_level": 0 + }, + { + "name": "ufunc_getattr", + "long_name": "ufunc_getattr( PyUFuncObject * self , char * name)", + "filename": "ufuncobject.c", + "nloc": 74, + "complexity": 16, + "token_count": 520, + "parameters": [ + "self", + "name" + ], + "start_line": 3027, + "end_line": 3110, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 84, + "top_nesting_level": 0 + }, + { + "name": "ufunc_setattr", + "long_name": "ufunc_setattr( PyUFuncObject * self , char * name , PyObject * v)", + "filename": "ufuncobject.c", + "nloc": 4, + "complexity": 1, + "token_count": 20, + "parameters": [ + "self", + "name", + "v" + ], + "start_line": 3115, + "end_line": 3118, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 4, + "top_nesting_level": 0 + } + ], + "changed_methods": [ + { + "name": "_signbit_set", + "long_name": "_signbit_set( PyArrayObject * arr)", + "filename": "ufuncobject.c", + "nloc": 16, + "complexity": 5, + "token_count": 89, + "parameters": [ + "arr" + ], + "start_line": 776, + "end_line": 793, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 18, + "top_nesting_level": 0 + }, + { + "name": "_scalar_kind", + "long_name": "_scalar_kind( int typenum , PyArrayObject ** arr)", + "filename": "ufuncobject.c", + "nloc": 12, + "complexity": 7, + "token_count": 78, + "parameters": [ + "typenum", + "arr" + ], + "start_line": 796, + "end_line": 808, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 13, + "top_nesting_level": 0 + } + ], + "nloc": 2343, + "complexity": 524, + "token_count": 17481, + "diff_parsed": { + "added": [ + "static int", + "_signbit_set(PyArrayObject *arr)", + "{", + "\tstatic char bitmask = 0x80;", + "\tchar *ptr; /* points to the byte to test */", + "\tchar byteorder;", + "\tint elsize;", + "", + "\telsize = arr->descr->elsize;", + "\tbyteorder = arr->descr->byteorder;", + "\tptr = arr->data;", + "\tif (elsize > 1 && \\", + "\t (byteorder == PyArray_LITTLE ||\t\\", + "\t (byteorder == PyArray_NATIVE &&", + "\t PyArray_ISNBO(PyArray_LITTLE))))", + "\t\tptr += elsize-1;", + "", + "\treturn ((*ptr & bitmask) != 0);", + "}", + "\tif (PyTypeNum_ISSIGNED(typenum)) {", + "\t\tif (_signbit_set(*arr)) return UFUNC_INTNEG_SCALAR;", + "\t\telse return UFUNC_INTPOS_SCALAR;", + "\t}", + "\tif (PyTypeNum_ISCOMPLEX(typenum)) return UFUNC_COMPLEX_SCALAR;", + "" + ], + "deleted": [ + "\tif (PyTypeNum_ISSIGNED(typenum)) return UFUNC_INTNEG_SCALAR;", + "\tif (PyTypeNum_ISCOMPLEX(typenum)) return UFUNC_COMPLEX_SCALAR;" + ] + } + } + ] + }, + { + "hash": "ca90e3eba3c94de3bd13266ccfd9f96dbf23693a", + "msg": "Fix-up record arrays that were not of dtype.type record. Don't allow arbitrary objects with dtype attributes as data-type indicators.", + "author": { + "name": "Travis Oliphant", + "email": "oliphant@enthought.com" + }, + "committer": { + "name": "Travis Oliphant", + "email": "oliphant@enthought.com" + }, + "author_date": "2006-01-30T09:20:46+00:00", + "author_timezone": 0, + "committer_date": "2006-01-30T09:20:46+00:00", + "committer_timezone": 0, + "branches": [ + "main" + ], + "in_main_branch": true, + "merge": false, + "parents": [ + "624787ad6dbdf9cd73749f29092d05e0f716f12c" + ], + "project_name": "repo_copy", + "project_path": "/tmp/tmppy2o86q9/repo_copy", + "deletions": 4, + "insertions": 9, + "lines": 13, + "files": 2, + "dmm_unit_size": 1.0, + "dmm_unit_complexity": 1.0, + "dmm_unit_interfacing": 0.0, + "modified_files": [ + { + "old_path": "numpy/core/records.py", + "new_path": "numpy/core/records.py", + "filename": "records.py", + "extension": "py", + "change_type": "MODIFY", + "diff": "@@ -294,7 +294,10 @@ def fromrecords(recList, formats=None, names=None, titles=None, shape=None,\n if shape is not None and retval.shape != shape:\n retval.shape = shape\n \n- return retval.view(recarray)\n+ res = retval.view(recarray)\n+ res.dtype = sb.dtype((record, res.dtype))\n+ return res\n+ \n \n def fromstring(datastring, formats, shape=None, names=None, titles=None,\n byteorder=None, aligned=0, offset=0):\n@@ -406,6 +409,8 @@ def array(obj, formats=None, names=None, titles=None, shape=None,\n shape=shape, byteorder=byteorder, aligned=aligned,\n offset=offset)\n elif isinstance(obj, sb.ndarray):\n- return obj.view(recarray)\n+ res = obj.view(recarray)\n+ if issubclass(res.dtype, nt.void):\n+ res.dtype = sb.dtype((record, res.dtype))\n else:\n raise ValueError(\"Unknown input type\")\n", + "added_lines": 7, + "deleted_lines": 2, + "source_code": "__all__ = ['record', 'recarray','format_parser']\n\nimport numeric as sb\nfrom defchararray import chararray\nimport numerictypes as nt\nimport sys\nimport types\nimport stat, os\nimport _internal\n\n_byteorderconv = {'b':'>',\n 'l':'<',\n 'n':'=',\n 'B':'>',\n 'L':'<',\n 'N':'=',\n 'S':'s',\n 's':'s',\n '>':'>',\n '<':'<',\n '=':'=',\n '|':'|',\n 'I':'|',\n 'i':'|'}\n\n# formats regular expression\n# allows multidimension spec with a tuple syntax in front \n# of the letter code '(2,3)f4' and ' ( 2 , 3 ) f4 ' \n# are equally allowed\n\nnumfmt = nt.typeDict\n_typestr = nt._typestr\n\ndef find_duplicate(list):\n \"\"\"Find duplication in a list, return a list of duplicated elements\"\"\"\n dup = []\n for i in range(len(list)):\n if (list[i] in list[i+1:]):\n if (list[i] not in dup):\n dup.append(list[i])\n return dup\n\n\nclass format_parser:\n def __init__(self, formats, names, titles, aligned=False):\n self._parseFormats(formats, aligned)\n self._setfieldnames(names, titles)\n self._createdescr()\n\n def _parseFormats(self, formats, aligned=0):\n \"\"\" Parse the field formats \"\"\"\n\n dtype = sb.dtype(formats, aligned)\n fields = dtype.fields\n keys = fields[-1]\n self._f_formats = [fields[key][0] for key in keys]\n self._offsets = [fields[key][1] for key in keys]\n self._nfields = len(keys)\n\n def _setfieldnames(self, names, titles):\n \"\"\"convert input field names into a list and assign to the _names\n attribute \"\"\"\n\n if (names):\n if (type(names) in [types.ListType, types.TupleType]):\n pass\n elif (type(names) == types.StringType):\n names = names.split(',')\n else:\n raise NameError, \"illegal input names %s\" % `names`\n\n self._names = [n.strip() for n in names[:self._nfields]]\n else: \n self._names = []\n\n # if the names are not specified, they will be assigned as \"f1, f2,...\"\n # if not enough names are specified, they will be assigned as \"f[n+1],\n # f[n+2],...\" etc. where n is the number of specified names...\"\n self._names += ['f%d' % i for i in range(len(self._names)+1,\n self._nfields+1)]\n # check for redundant names\n _dup = find_duplicate(self._names)\n if _dup:\n raise ValueError, \"Duplicate field names: %s\" % _dup\n\n if (titles):\n self._titles = [n.strip() for n in titles[:self._nfields]]\n else:\n self._titles = []\n titles = []\n\n if (self._nfields > len(titles)):\n self._titles += [None]*(self._nfields-len(titles))\n \n def _createdescr(self):\n self._descr = sb.dtype({'names':self._names,\n 'formats':self._f_formats,\n 'offsets':self._offsets,\n 'titles':self._titles})\n \nclass record(nt.void):\n def __repr__(self):\n return self.__str__()\n \n def __str__(self):\n return str(self.item())\n\n def __getattribute__(self, attr):\n if attr in ['setfield', 'getfield', 'dtype']:\n return nt.void.__getattribute__(self, attr)\n fielddict = nt.void.__getattribute__(self, 'dtype').fields\n res = fielddict.get(attr,None)\n if res:\n return self.getfield(*res[:2])\n return nt.void.__getattribute__(self, attr)\n\n def __setattr__(self, attr, val):\n if attr in ['setfield', 'getfield', 'dtype']:\n raise AttributeError, \"Cannot set '%s' attribute\" % attr;\n fielddict = nt.void.__getattribute__(self,'dtype').fields\n res = fielddict.get(attr,None)\n if res:\n return self.setfield(val,*res[:2])\n\n return nt.void.__setattr__(self,attr,val)\n \n def __getitem__(self, obj):\n return self.getfield(*(self.dtype.fields[obj][:2]))\n \n def __setitem__(self, obj, val):\n return self.setfield(val, *(self.dtype.fields[obj][:2]))\n \n\n# The recarray is almost identical to a standard array (which supports\n# named fields already) The biggest difference is that it can use\n# attribute-lookup to find the fields and it is constructed using\n# a record.\n\n# If byteorder is given it forces a particular byteorder on all\n# the fields (and any subfields)\n\nclass recarray(sb.ndarray):\n def __new__(subtype, shape, formats, names=None, titles=None,\n buf=None, offset=0, strides=None, byteorder=None,\n aligned=0):\n\n if isinstance(formats, sb.dtype):\n descr = formats\n else:\n parsed = format_parser(formats, names, titles, aligned)\n descr = parsed._descr\n\n if (byteorder is not None):\n byteorder = _byteorderconv[byteorder[0]]\n descr = descr.newbyteorder(byteorder)\n\n if buf is None:\n self = sb.ndarray.__new__(subtype, shape, (record, descr))\n else:\n self = sb.ndarray.__new__(subtype, shape, (record, descr),\n buffer=buf, offset=offset,\n strides=strides)\n return self\n\n def __getattribute__(self, attr):\n fielddict = sb.ndarray.__getattribute__(self,'dtype').fields\n try:\n res = fielddict[attr][:2]\n except:\n return sb.ndarray.__getattribute__(self,attr)\n \n obj = self.getfield(*res)\n # if it has fields return a recarray, otherwise return\n # normal array\n if obj.dtype.fields:\n return obj\n if obj.dtype.char in 'SU':\n return obj.view(chararray)\n return obj.view(sb.ndarray)\n \n \n def __setattr__(self, attr, val):\n fielddict = sb.ndarray.__getattribute__(self,'dtype').fields\n try:\n res = fielddict[attr][:2]\n except:\n return sb.ndarray.__setattr__(self,attr,val)\n \n return self.setfield(val,*res)\n\n\ndef fromarrays(arrayList, formats=None, names=None, titles=None, shape=None,\n aligned=0):\n \"\"\" create a record array from a (flat) list of arrays\n\n >>> x1=array([1,2,3,4])\n >>> x2=array(['a','dd','xyz','12'])\n >>> x3=array([1.1,2,3,4])\n >>> r=fromarrays([x1,x2,x3],names='a,b,c')\n >>> print r[1]\n (2, 'dd', 2.0)\n >>> x1[1]=34\n >>> r.a\n array([1, 2, 3, 4])\n \"\"\"\n\n if shape is None or shape == 0:\n shape = arrayList[0].shape\n\n if isinstance(shape, int):\n shape = (shape,)\n \n if formats is None:\n # go through each object in the list to see if it is an ndarray\n # and determine the formats.\n formats = ''\n for obj in arrayList:\n if not isinstance(obj, sb.ndarray):\n raise ValueError, \"item in the array list must be an ndarray.\"\n formats += _typestr[obj.dtype.type]\n if issubclass(obj.dtype.type, nt.flexible):\n formats += `obj.itemsize`\n formats += ','\n formats=formats[:-1]\n\n for obj in arrayList:\n if obj.shape != shape:\n raise ValueError, \"array has different shape\"\n\n parsed = format_parser(formats, names, titles, aligned)\n _names = parsed._names\n _array = recarray(shape, parsed._descr)\n \n # populate the record array (makes a copy)\n for i in range(len(arrayList)):\n _array[_names[i]] = arrayList[i]\n\n return _array\n\n# shape must be 1-d if you use list of lists...\ndef fromrecords(recList, formats=None, names=None, titles=None, shape=None,\n aligned=0):\n \"\"\" create a recarray from a list of records in text form\n\n The data in the same field can be heterogeneous, they will be promoted\n to the highest data type. This method is intended for creating\n smaller record arrays. If used to create large array without formats\n defined\n\n r=fromrecords([(2,3.,'abc')]*100000)\n\n it can be slow.\n\n If formats is None, then this will auto-detect formats. Use list of\n tuples rather than list of lists for faster processing.\n\n >>> r=fromrecords([(456,'dbe',1.2),(2,'de',1.3)],names='col1,col2,col3')\n >>> print r[0]\n (456, 'dbe', 1.2)\n >>> r.col1\n array([456, 2])\n >>> r.col2\n chararray(['dbe', 'de'])\n >>> import cPickle\n >>> print cPickle.loads(cPickle.dumps(r))\n recarray[ \n (456, 'dbe', 1.2),\n (2, 'de', 1.3)\n ]\n \"\"\"\n\n nfields = len(recList[0])\n if formats is None: # slower\n obj = sb.array(recList,dtype=object)\n arrlist = [sb.array(obj[...,i].tolist()) for i in xrange(nfields)]\n return fromarrays(arrlist, formats=formats, shape=shape, names=names,\n titles=titles, aligned=aligned)\n\n parsed = format_parser(formats, names, titles, aligned)\n try:\n retval = sb.array(recList, dtype = parsed._descr)\n except TypeError: # list of lists instead of list of tuples\n if (shape is None or shape == 0):\n shape = len(recList)\n if isinstance(shape, (int, long)):\n shape = (shape,)\n if len(shape) > 1:\n raise ValueError, \"Can only deal with 1-d array.\"\n _array = recarray(shape, parsed._descr)\n for k in xrange(_array.size):\n _array[k] = tuple(recList[k])\n return _array\n else:\n if shape is not None and retval.shape != shape:\n retval.shape = shape\n\n res = retval.view(recarray)\n res.dtype = sb.dtype((record, res.dtype))\n return res\n \n\ndef fromstring(datastring, formats, shape=None, names=None, titles=None,\n byteorder=None, aligned=0, offset=0):\n \"\"\" create a (read-only) record array from binary data contained in\n a string\"\"\"\n\n parsed = format_parser(formats, names, titles, aligned)\n itemsize = parsed._descr.itemsize\n if (shape is None or shape == 0 or shape == -1):\n shape = (len(datastring)-offset) / itemsize\n \n _array = recarray(shape, parsed._descr, names=names,\n titles=titles, buf=datastring, offset=offset,\n byteorder=byteorder)\n return _array\n\ndef fromfile(fd, formats, shape=None, names=None, titles=None,\n byteorder=None, aligned=0, offset=0):\n \"\"\"Create an array from binary file data\n\n If file is a string then that file is opened, else it is assumed\n to be a file object.\n\n >>> import testdata, sys\n >>> fd=open(testdata.filename)\n >>> fd.seek(2880*2)\n >>> r=fromfile(fd, formats='f8,i4,a5', shape=3, byteorder='big')\n >>> print r[0]\n (5.1000000000000005, 61, 'abcde')\n >>> r._shape\n (3,)\n \"\"\"\n\n if (shape is None or shape == 0):\n shape = (-1,)\n elif isinstance(shape, (int, long)):\n shape = (shape,)\n\n name = 0\n if isinstance(fd, str):\n name = 1\n fd = open(fd, 'rb')\n if (offset > 0):\n fd.seek(offset, 1)\n try:\n size = os.fstat(fd.fileno())[stat.ST_SIZE] - fd.tell()\n except:\n size = os.path.getsize(fd.name) - fd.tell()\n\n parsed = format_parser(formats, names, titles, aligned)\n itemsize = parsed._descr.itemsize\n\n shapeprod = sb.array(shape).prod()\n shapesize = shapeprod*itemsize\n if shapesize < 0:\n shape = list(shape)\n shape[ shape.index(-1) ] = size / -shapesize\n shape = tuple(shape)\n shapeprod = sb.array(shape).prod()\n \n nbytes = shapeprod*itemsize\n\n if nbytes > size:\n raise ValueError(\n \"Not enough bytes left in file for specified shape and type\")\n\n # create the array\n _array = recarray(shape, parsed._descr, byteorder=byteorder)\n nbytesread = fd.readinto(_array.data)\n if nbytesread != nbytes:\n raise IOError(\"Didn't read as many bytes as expected\")\n if name:\n fd.close()\n \n return _array\n\n\ndef array(obj, formats=None, names=None, titles=None, shape=None,\n byteorder=None, aligned=0, offset=0, strides=None):\n \n if isinstance(obj, (type(None), str, file)) and (formats is None):\n raise ValueError(\"Must define formats if object is \"\\\n \"None, string, or an open file\")\n\n elif obj is None:\n if shape is None:\n raise ValueError(\"Must define a shape if obj is None\")\n return recarray(shape, formats, names=names, titles=titles,\n buf=obj, offset=offset, strides=strides,\n byteorder=byteorder, aligned=aligned)\n elif isinstance(obj, str):\n return fromstring(obj, formats, names=names, titles=titles,\n shape=shape, byteorder=byteorder, aligned=aligned,\n offset=offset)\n elif isinstance(obj, (list, tuple)):\n if isinstance(obj[0], sb.ndarray):\n return fromarrays(obj, formats=formats, names=names, titles=titles,\n shape=shape, aligned=aligned)\n else:\n return fromrecords(obj, formats=formats, names=names, titles=titles,\n shape=shape, aligned=aligned)\n elif isinstance(obj, recarray):\n new = obj.copy()\n parsed = format_parser(formats, names, titles, aligned)\n new.dtype = parsed._descr\n return new\n elif isinstance(obj, file):\n return fromfile(obj, formats=formats, names=names, titles=titles,\n shape=shape, byteorder=byteorder, aligned=aligned,\n offset=offset)\n elif isinstance(obj, sb.ndarray):\n res = obj.view(recarray)\n if issubclass(res.dtype, nt.void):\n res.dtype = sb.dtype((record, res.dtype))\n else:\n raise ValueError(\"Unknown input type\")\n", + "source_code_before": "__all__ = ['record', 'recarray','format_parser']\n\nimport numeric as sb\nfrom defchararray import chararray\nimport numerictypes as nt\nimport sys\nimport types\nimport stat, os\nimport _internal\n\n_byteorderconv = {'b':'>',\n 'l':'<',\n 'n':'=',\n 'B':'>',\n 'L':'<',\n 'N':'=',\n 'S':'s',\n 's':'s',\n '>':'>',\n '<':'<',\n '=':'=',\n '|':'|',\n 'I':'|',\n 'i':'|'}\n\n# formats regular expression\n# allows multidimension spec with a tuple syntax in front \n# of the letter code '(2,3)f4' and ' ( 2 , 3 ) f4 ' \n# are equally allowed\n\nnumfmt = nt.typeDict\n_typestr = nt._typestr\n\ndef find_duplicate(list):\n \"\"\"Find duplication in a list, return a list of duplicated elements\"\"\"\n dup = []\n for i in range(len(list)):\n if (list[i] in list[i+1:]):\n if (list[i] not in dup):\n dup.append(list[i])\n return dup\n\n\nclass format_parser:\n def __init__(self, formats, names, titles, aligned=False):\n self._parseFormats(formats, aligned)\n self._setfieldnames(names, titles)\n self._createdescr()\n\n def _parseFormats(self, formats, aligned=0):\n \"\"\" Parse the field formats \"\"\"\n\n dtype = sb.dtype(formats, aligned)\n fields = dtype.fields\n keys = fields[-1]\n self._f_formats = [fields[key][0] for key in keys]\n self._offsets = [fields[key][1] for key in keys]\n self._nfields = len(keys)\n\n def _setfieldnames(self, names, titles):\n \"\"\"convert input field names into a list and assign to the _names\n attribute \"\"\"\n\n if (names):\n if (type(names) in [types.ListType, types.TupleType]):\n pass\n elif (type(names) == types.StringType):\n names = names.split(',')\n else:\n raise NameError, \"illegal input names %s\" % `names`\n\n self._names = [n.strip() for n in names[:self._nfields]]\n else: \n self._names = []\n\n # if the names are not specified, they will be assigned as \"f1, f2,...\"\n # if not enough names are specified, they will be assigned as \"f[n+1],\n # f[n+2],...\" etc. where n is the number of specified names...\"\n self._names += ['f%d' % i for i in range(len(self._names)+1,\n self._nfields+1)]\n # check for redundant names\n _dup = find_duplicate(self._names)\n if _dup:\n raise ValueError, \"Duplicate field names: %s\" % _dup\n\n if (titles):\n self._titles = [n.strip() for n in titles[:self._nfields]]\n else:\n self._titles = []\n titles = []\n\n if (self._nfields > len(titles)):\n self._titles += [None]*(self._nfields-len(titles))\n \n def _createdescr(self):\n self._descr = sb.dtype({'names':self._names,\n 'formats':self._f_formats,\n 'offsets':self._offsets,\n 'titles':self._titles})\n \nclass record(nt.void):\n def __repr__(self):\n return self.__str__()\n \n def __str__(self):\n return str(self.item())\n\n def __getattribute__(self, attr):\n if attr in ['setfield', 'getfield', 'dtype']:\n return nt.void.__getattribute__(self, attr)\n fielddict = nt.void.__getattribute__(self, 'dtype').fields\n res = fielddict.get(attr,None)\n if res:\n return self.getfield(*res[:2])\n return nt.void.__getattribute__(self, attr)\n\n def __setattr__(self, attr, val):\n if attr in ['setfield', 'getfield', 'dtype']:\n raise AttributeError, \"Cannot set '%s' attribute\" % attr;\n fielddict = nt.void.__getattribute__(self,'dtype').fields\n res = fielddict.get(attr,None)\n if res:\n return self.setfield(val,*res[:2])\n\n return nt.void.__setattr__(self,attr,val)\n \n def __getitem__(self, obj):\n return self.getfield(*(self.dtype.fields[obj][:2]))\n \n def __setitem__(self, obj, val):\n return self.setfield(val, *(self.dtype.fields[obj][:2]))\n \n\n# The recarray is almost identical to a standard array (which supports\n# named fields already) The biggest difference is that it can use\n# attribute-lookup to find the fields and it is constructed using\n# a record.\n\n# If byteorder is given it forces a particular byteorder on all\n# the fields (and any subfields)\n\nclass recarray(sb.ndarray):\n def __new__(subtype, shape, formats, names=None, titles=None,\n buf=None, offset=0, strides=None, byteorder=None,\n aligned=0):\n\n if isinstance(formats, sb.dtype):\n descr = formats\n else:\n parsed = format_parser(formats, names, titles, aligned)\n descr = parsed._descr\n\n if (byteorder is not None):\n byteorder = _byteorderconv[byteorder[0]]\n descr = descr.newbyteorder(byteorder)\n\n if buf is None:\n self = sb.ndarray.__new__(subtype, shape, (record, descr))\n else:\n self = sb.ndarray.__new__(subtype, shape, (record, descr),\n buffer=buf, offset=offset,\n strides=strides)\n return self\n\n def __getattribute__(self, attr):\n fielddict = sb.ndarray.__getattribute__(self,'dtype').fields\n try:\n res = fielddict[attr][:2]\n except:\n return sb.ndarray.__getattribute__(self,attr)\n \n obj = self.getfield(*res)\n # if it has fields return a recarray, otherwise return\n # normal array\n if obj.dtype.fields:\n return obj\n if obj.dtype.char in 'SU':\n return obj.view(chararray)\n return obj.view(sb.ndarray)\n \n \n def __setattr__(self, attr, val):\n fielddict = sb.ndarray.__getattribute__(self,'dtype').fields\n try:\n res = fielddict[attr][:2]\n except:\n return sb.ndarray.__setattr__(self,attr,val)\n \n return self.setfield(val,*res)\n\n\ndef fromarrays(arrayList, formats=None, names=None, titles=None, shape=None,\n aligned=0):\n \"\"\" create a record array from a (flat) list of arrays\n\n >>> x1=array([1,2,3,4])\n >>> x2=array(['a','dd','xyz','12'])\n >>> x3=array([1.1,2,3,4])\n >>> r=fromarrays([x1,x2,x3],names='a,b,c')\n >>> print r[1]\n (2, 'dd', 2.0)\n >>> x1[1]=34\n >>> r.a\n array([1, 2, 3, 4])\n \"\"\"\n\n if shape is None or shape == 0:\n shape = arrayList[0].shape\n\n if isinstance(shape, int):\n shape = (shape,)\n \n if formats is None:\n # go through each object in the list to see if it is an ndarray\n # and determine the formats.\n formats = ''\n for obj in arrayList:\n if not isinstance(obj, sb.ndarray):\n raise ValueError, \"item in the array list must be an ndarray.\"\n formats += _typestr[obj.dtype.type]\n if issubclass(obj.dtype.type, nt.flexible):\n formats += `obj.itemsize`\n formats += ','\n formats=formats[:-1]\n\n for obj in arrayList:\n if obj.shape != shape:\n raise ValueError, \"array has different shape\"\n\n parsed = format_parser(formats, names, titles, aligned)\n _names = parsed._names\n _array = recarray(shape, parsed._descr)\n \n # populate the record array (makes a copy)\n for i in range(len(arrayList)):\n _array[_names[i]] = arrayList[i]\n\n return _array\n\n# shape must be 1-d if you use list of lists...\ndef fromrecords(recList, formats=None, names=None, titles=None, shape=None,\n aligned=0):\n \"\"\" create a recarray from a list of records in text form\n\n The data in the same field can be heterogeneous, they will be promoted\n to the highest data type. This method is intended for creating\n smaller record arrays. If used to create large array without formats\n defined\n\n r=fromrecords([(2,3.,'abc')]*100000)\n\n it can be slow.\n\n If formats is None, then this will auto-detect formats. Use list of\n tuples rather than list of lists for faster processing.\n\n >>> r=fromrecords([(456,'dbe',1.2),(2,'de',1.3)],names='col1,col2,col3')\n >>> print r[0]\n (456, 'dbe', 1.2)\n >>> r.col1\n array([456, 2])\n >>> r.col2\n chararray(['dbe', 'de'])\n >>> import cPickle\n >>> print cPickle.loads(cPickle.dumps(r))\n recarray[ \n (456, 'dbe', 1.2),\n (2, 'de', 1.3)\n ]\n \"\"\"\n\n nfields = len(recList[0])\n if formats is None: # slower\n obj = sb.array(recList,dtype=object)\n arrlist = [sb.array(obj[...,i].tolist()) for i in xrange(nfields)]\n return fromarrays(arrlist, formats=formats, shape=shape, names=names,\n titles=titles, aligned=aligned)\n\n parsed = format_parser(formats, names, titles, aligned)\n try:\n retval = sb.array(recList, dtype = parsed._descr)\n except TypeError: # list of lists instead of list of tuples\n if (shape is None or shape == 0):\n shape = len(recList)\n if isinstance(shape, (int, long)):\n shape = (shape,)\n if len(shape) > 1:\n raise ValueError, \"Can only deal with 1-d array.\"\n _array = recarray(shape, parsed._descr)\n for k in xrange(_array.size):\n _array[k] = tuple(recList[k])\n return _array\n else:\n if shape is not None and retval.shape != shape:\n retval.shape = shape\n\n return retval.view(recarray)\n\ndef fromstring(datastring, formats, shape=None, names=None, titles=None,\n byteorder=None, aligned=0, offset=0):\n \"\"\" create a (read-only) record array from binary data contained in\n a string\"\"\"\n\n parsed = format_parser(formats, names, titles, aligned)\n itemsize = parsed._descr.itemsize\n if (shape is None or shape == 0 or shape == -1):\n shape = (len(datastring)-offset) / itemsize\n \n _array = recarray(shape, parsed._descr, names=names,\n titles=titles, buf=datastring, offset=offset,\n byteorder=byteorder)\n return _array\n\ndef fromfile(fd, formats, shape=None, names=None, titles=None,\n byteorder=None, aligned=0, offset=0):\n \"\"\"Create an array from binary file data\n\n If file is a string then that file is opened, else it is assumed\n to be a file object.\n\n >>> import testdata, sys\n >>> fd=open(testdata.filename)\n >>> fd.seek(2880*2)\n >>> r=fromfile(fd, formats='f8,i4,a5', shape=3, byteorder='big')\n >>> print r[0]\n (5.1000000000000005, 61, 'abcde')\n >>> r._shape\n (3,)\n \"\"\"\n\n if (shape is None or shape == 0):\n shape = (-1,)\n elif isinstance(shape, (int, long)):\n shape = (shape,)\n\n name = 0\n if isinstance(fd, str):\n name = 1\n fd = open(fd, 'rb')\n if (offset > 0):\n fd.seek(offset, 1)\n try:\n size = os.fstat(fd.fileno())[stat.ST_SIZE] - fd.tell()\n except:\n size = os.path.getsize(fd.name) - fd.tell()\n\n parsed = format_parser(formats, names, titles, aligned)\n itemsize = parsed._descr.itemsize\n\n shapeprod = sb.array(shape).prod()\n shapesize = shapeprod*itemsize\n if shapesize < 0:\n shape = list(shape)\n shape[ shape.index(-1) ] = size / -shapesize\n shape = tuple(shape)\n shapeprod = sb.array(shape).prod()\n \n nbytes = shapeprod*itemsize\n\n if nbytes > size:\n raise ValueError(\n \"Not enough bytes left in file for specified shape and type\")\n\n # create the array\n _array = recarray(shape, parsed._descr, byteorder=byteorder)\n nbytesread = fd.readinto(_array.data)\n if nbytesread != nbytes:\n raise IOError(\"Didn't read as many bytes as expected\")\n if name:\n fd.close()\n \n return _array\n\n\ndef array(obj, formats=None, names=None, titles=None, shape=None,\n byteorder=None, aligned=0, offset=0, strides=None):\n \n if isinstance(obj, (type(None), str, file)) and (formats is None):\n raise ValueError(\"Must define formats if object is \"\\\n \"None, string, or an open file\")\n\n elif obj is None:\n if shape is None:\n raise ValueError(\"Must define a shape if obj is None\")\n return recarray(shape, formats, names=names, titles=titles,\n buf=obj, offset=offset, strides=strides,\n byteorder=byteorder, aligned=aligned)\n elif isinstance(obj, str):\n return fromstring(obj, formats, names=names, titles=titles,\n shape=shape, byteorder=byteorder, aligned=aligned,\n offset=offset)\n elif isinstance(obj, (list, tuple)):\n if isinstance(obj[0], sb.ndarray):\n return fromarrays(obj, formats=formats, names=names, titles=titles,\n shape=shape, aligned=aligned)\n else:\n return fromrecords(obj, formats=formats, names=names, titles=titles,\n shape=shape, aligned=aligned)\n elif isinstance(obj, recarray):\n new = obj.copy()\n parsed = format_parser(formats, names, titles, aligned)\n new.dtype = parsed._descr\n return new\n elif isinstance(obj, file):\n return fromfile(obj, formats=formats, names=names, titles=titles,\n shape=shape, byteorder=byteorder, aligned=aligned,\n offset=offset)\n elif isinstance(obj, sb.ndarray):\n return obj.view(recarray)\n else:\n raise ValueError(\"Unknown input type\")\n", + "methods": [ + { + "name": "find_duplicate", + "long_name": "find_duplicate( list )", + "filename": "records.py", + "nloc": 7, + "complexity": 4, + "token_count": 59, + "parameters": [ + "list" + ], + "start_line": 34, + "end_line": 41, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 8, + "top_nesting_level": 0 + }, + { + "name": "__init__", + "long_name": "__init__( self , formats , names , titles , aligned = False )", + "filename": "records.py", + "nloc": 4, + "complexity": 1, + "token_count": 36, + "parameters": [ + "self", + "formats", + "names", + "titles", + "aligned" + ], + "start_line": 45, + "end_line": 48, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 4, + "top_nesting_level": 1 + }, + { + "name": "_parseFormats", + "long_name": "_parseFormats( self , formats , aligned = 0 )", + "filename": "records.py", + "nloc": 7, + "complexity": 3, + "token_count": 76, + "parameters": [ + "self", + "formats", + "aligned" + ], + "start_line": 50, + "end_line": 58, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 9, + "top_nesting_level": 1 + }, + { + "name": "_setfieldnames", + "long_name": "_setfieldnames( self , names , titles )", + "filename": "records.py", + "nloc": 23, + "complexity": 10, + "token_count": 207, + "parameters": [ + "self", + "names", + "titles" + ], + "start_line": 60, + "end_line": 93, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 34, + "top_nesting_level": 1 + }, + { + "name": "_createdescr", + "long_name": "_createdescr( self )", + "filename": "records.py", + "nloc": 5, + "complexity": 1, + "token_count": 39, + "parameters": [ + "self" + ], + "start_line": 95, + "end_line": 99, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 5, + "top_nesting_level": 1 + }, + { + "name": "__repr__", + "long_name": "__repr__( self )", + "filename": "records.py", + "nloc": 2, + "complexity": 1, + "token_count": 11, + "parameters": [ + "self" + ], + "start_line": 102, + "end_line": 103, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 2, + "top_nesting_level": 1 + }, + { + "name": "__str__", + "long_name": "__str__( self )", + "filename": "records.py", + "nloc": 2, + "complexity": 1, + "token_count": 14, + "parameters": [ + "self" + ], + "start_line": 105, + "end_line": 106, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 2, + "top_nesting_level": 1 + }, + { + "name": "__getattribute__", + "long_name": "__getattribute__( self , attr )", + "filename": "records.py", + "nloc": 8, + "complexity": 3, + "token_count": 79, + "parameters": [ + "self", + "attr" + ], + "start_line": 108, + "end_line": 115, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 8, + "top_nesting_level": 1 + }, + { + "name": "__setattr__", + "long_name": "__setattr__( self , attr , val )", + "filename": "records.py", + "nloc": 8, + "complexity": 3, + "token_count": 81, + "parameters": [ + "self", + "attr", + "val" + ], + "start_line": 117, + "end_line": 125, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 9, + "top_nesting_level": 1 + }, + { + "name": "__getitem__", + "long_name": "__getitem__( self , obj )", + "filename": "records.py", + "nloc": 2, + "complexity": 1, + "token_count": 28, + "parameters": [ + "self", + "obj" + ], + "start_line": 127, + "end_line": 128, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 2, + "top_nesting_level": 1 + }, + { + "name": "__setitem__", + "long_name": "__setitem__( self , obj , val )", + "filename": "records.py", + "nloc": 2, + "complexity": 1, + "token_count": 32, + "parameters": [ + "self", + "obj", + "val" + ], + "start_line": 130, + "end_line": 131, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 2, + "top_nesting_level": 1 + }, + { + "name": "__new__", + "long_name": "__new__( subtype , shape , formats , names = None , titles = None , buf = None , offset = 0 , strides = None , byteorder = None , aligned = 0 )", + "filename": "records.py", + "nloc": 18, + "complexity": 4, + "token_count": 151, + "parameters": [ + "subtype", + "shape", + "formats", + "names", + "titles", + "buf", + "offset", + "strides", + "byteorder", + "aligned" + ], + "start_line": 143, + "end_line": 163, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 21, + "top_nesting_level": 1 + }, + { + "name": "__getattribute__", + "long_name": "__getattribute__( self , attr )", + "filename": "records.py", + "nloc": 12, + "complexity": 4, + "token_count": 89, + "parameters": [ + "self", + "attr" + ], + "start_line": 165, + "end_line": 179, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 15, + "top_nesting_level": 1 + }, + { + "name": "__setattr__", + "long_name": "__setattr__( self , attr , val )", + "filename": "records.py", + "nloc": 7, + "complexity": 2, + "token_count": 60, + "parameters": [ + "self", + "attr", + "val" + ], + "start_line": 182, + "end_line": 189, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 8, + "top_nesting_level": 1 + }, + { + "name": "fromarrays", + "long_name": "fromarrays( arrayList , formats = None , names = None , titles = None , shape = None , aligned = 0 )", + "filename": "records.py", + "nloc": 25, + "complexity": 11, + "token_count": 195, + "parameters": [ + "arrayList", + "formats", + "names", + "titles", + "shape", + "aligned" + ], + "start_line": 192, + "end_line": 238, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 47, + "top_nesting_level": 0 + }, + { + "name": "fromrecords", + "long_name": "fromrecords( recList , formats = None , names = None , titles = None , shape = None , aligned = 0 )", + "filename": "records.py", + "nloc": 28, + "complexity": 11, + "token_count": 260, + "parameters": [ + "recList", + "formats", + "names", + "titles", + "shape", + "aligned" + ], + "start_line": 241, + "end_line": 299, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 59, + "top_nesting_level": 0 + }, + { + "name": "fromstring", + "long_name": "fromstring( datastring , formats , shape = None , names = None , titles = None , byteorder = None , aligned = 0 , offset = 0 )", + "filename": "records.py", + "nloc": 10, + "complexity": 4, + "token_count": 111, + "parameters": [ + "datastring", + "formats", + "shape", + "names", + "titles", + "byteorder", + "aligned", + "offset" + ], + "start_line": 302, + "end_line": 315, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 14, + "top_nesting_level": 0 + }, + { + "name": "fromfile", + "long_name": "fromfile( fd , formats , shape = None , names = None , titles = None , byteorder = None , aligned = 0 , offset = 0 )", + "filename": "records.py", + "nloc": 36, + "complexity": 11, + "token_count": 289, + "parameters": [ + "fd", + "formats", + "shape", + "names", + "titles", + "byteorder", + "aligned", + "offset" + ], + "start_line": 317, + "end_line": 375, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 59, + "top_nesting_level": 0 + }, + { + "name": "array", + "long_name": "array( obj , formats = None , names = None , titles = None , shape = None , byteorder = None , aligned = 0 , offset = 0 , strides = None )", + "filename": "records.py", + "nloc": 37, + "complexity": 12, + "token_count": 363, + "parameters": [ + "obj", + "formats", + "names", + "titles", + "shape", + "byteorder", + "aligned", + "offset", + "strides" + ], + "start_line": 378, + "end_line": 416, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 39, + "top_nesting_level": 0 + } + ], + "methods_before": [ + { + "name": "find_duplicate", + "long_name": "find_duplicate( list )", + "filename": "records.py", + "nloc": 7, + "complexity": 4, + "token_count": 59, + "parameters": [ + "list" + ], + "start_line": 34, + "end_line": 41, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 8, + "top_nesting_level": 0 + }, + { + "name": "__init__", + "long_name": "__init__( self , formats , names , titles , aligned = False )", + "filename": "records.py", + "nloc": 4, + "complexity": 1, + "token_count": 36, + "parameters": [ + "self", + "formats", + "names", + "titles", + "aligned" + ], + "start_line": 45, + "end_line": 48, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 4, + "top_nesting_level": 1 + }, + { + "name": "_parseFormats", + "long_name": "_parseFormats( self , formats , aligned = 0 )", + "filename": "records.py", + "nloc": 7, + "complexity": 3, + "token_count": 76, + "parameters": [ + "self", + "formats", + "aligned" + ], + "start_line": 50, + "end_line": 58, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 9, + "top_nesting_level": 1 + }, + { + "name": "_setfieldnames", + "long_name": "_setfieldnames( self , names , titles )", + "filename": "records.py", + "nloc": 23, + "complexity": 10, + "token_count": 207, + "parameters": [ + "self", + "names", + "titles" + ], + "start_line": 60, + "end_line": 93, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 34, + "top_nesting_level": 1 + }, + { + "name": "_createdescr", + "long_name": "_createdescr( self )", + "filename": "records.py", + "nloc": 5, + "complexity": 1, + "token_count": 39, + "parameters": [ + "self" + ], + "start_line": 95, + "end_line": 99, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 5, + "top_nesting_level": 1 + }, + { + "name": "__repr__", + "long_name": "__repr__( self )", + "filename": "records.py", + "nloc": 2, + "complexity": 1, + "token_count": 11, + "parameters": [ + "self" + ], + "start_line": 102, + "end_line": 103, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 2, + "top_nesting_level": 1 + }, + { + "name": "__str__", + "long_name": "__str__( self )", + "filename": "records.py", + "nloc": 2, + "complexity": 1, + "token_count": 14, + "parameters": [ + "self" + ], + "start_line": 105, + "end_line": 106, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 2, + "top_nesting_level": 1 + }, + { + "name": "__getattribute__", + "long_name": "__getattribute__( self , attr )", + "filename": "records.py", + "nloc": 8, + "complexity": 3, + "token_count": 79, + "parameters": [ + "self", + "attr" + ], + "start_line": 108, + "end_line": 115, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 8, + "top_nesting_level": 1 + }, + { + "name": "__setattr__", + "long_name": "__setattr__( self , attr , val )", + "filename": "records.py", + "nloc": 8, + "complexity": 3, + "token_count": 81, + "parameters": [ + "self", + "attr", + "val" + ], + "start_line": 117, + "end_line": 125, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 9, + "top_nesting_level": 1 + }, + { + "name": "__getitem__", + "long_name": "__getitem__( self , obj )", + "filename": "records.py", + "nloc": 2, + "complexity": 1, + "token_count": 28, + "parameters": [ + "self", + "obj" + ], + "start_line": 127, + "end_line": 128, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 2, + "top_nesting_level": 1 + }, + { + "name": "__setitem__", + "long_name": "__setitem__( self , obj , val )", + "filename": "records.py", + "nloc": 2, + "complexity": 1, + "token_count": 32, + "parameters": [ + "self", + "obj", + "val" + ], + "start_line": 130, + "end_line": 131, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 2, + "top_nesting_level": 1 + }, + { + "name": "__new__", + "long_name": "__new__( subtype , shape , formats , names = None , titles = None , buf = None , offset = 0 , strides = None , byteorder = None , aligned = 0 )", + "filename": "records.py", + "nloc": 18, + "complexity": 4, + "token_count": 151, + "parameters": [ + "subtype", + "shape", + "formats", + "names", + "titles", + "buf", + "offset", + "strides", + "byteorder", + "aligned" + ], + "start_line": 143, + "end_line": 163, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 21, + "top_nesting_level": 1 + }, + { + "name": "__getattribute__", + "long_name": "__getattribute__( self , attr )", + "filename": "records.py", + "nloc": 12, + "complexity": 4, + "token_count": 89, + "parameters": [ + "self", + "attr" + ], + "start_line": 165, + "end_line": 179, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 15, + "top_nesting_level": 1 + }, + { + "name": "__setattr__", + "long_name": "__setattr__( self , attr , val )", + "filename": "records.py", + "nloc": 7, + "complexity": 2, + "token_count": 60, + "parameters": [ + "self", + "attr", + "val" + ], + "start_line": 182, + "end_line": 189, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 8, + "top_nesting_level": 1 + }, + { + "name": "fromarrays", + "long_name": "fromarrays( arrayList , formats = None , names = None , titles = None , shape = None , aligned = 0 )", + "filename": "records.py", + "nloc": 25, + "complexity": 11, + "token_count": 195, + "parameters": [ + "arrayList", + "formats", + "names", + "titles", + "shape", + "aligned" + ], + "start_line": 192, + "end_line": 238, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 47, + "top_nesting_level": 0 + }, + { + "name": "fromrecords", + "long_name": "fromrecords( recList , formats = None , names = None , titles = None , shape = None , aligned = 0 )", + "filename": "records.py", + "nloc": 26, + "complexity": 11, + "token_count": 241, + "parameters": [ + "recList", + "formats", + "names", + "titles", + "shape", + "aligned" + ], + "start_line": 241, + "end_line": 297, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 57, + "top_nesting_level": 0 + }, + { + "name": "fromstring", + "long_name": "fromstring( datastring , formats , shape = None , names = None , titles = None , byteorder = None , aligned = 0 , offset = 0 )", + "filename": "records.py", + "nloc": 10, + "complexity": 4, + "token_count": 111, + "parameters": [ + "datastring", + "formats", + "shape", + "names", + "titles", + "byteorder", + "aligned", + "offset" + ], + "start_line": 299, + "end_line": 312, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 14, + "top_nesting_level": 0 + }, + { + "name": "fromfile", + "long_name": "fromfile( fd , formats , shape = None , names = None , titles = None , byteorder = None , aligned = 0 , offset = 0 )", + "filename": "records.py", + "nloc": 36, + "complexity": 11, + "token_count": 289, + "parameters": [ + "fd", + "formats", + "shape", + "names", + "titles", + "byteorder", + "aligned", + "offset" + ], + "start_line": 314, + "end_line": 372, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 59, + "top_nesting_level": 0 + }, + { + "name": "array", + "long_name": "array( obj , formats = None , names = None , titles = None , shape = None , byteorder = None , aligned = 0 , offset = 0 , strides = None )", + "filename": "records.py", + "nloc": 35, + "complexity": 11, + "token_count": 334, + "parameters": [ + "obj", + "formats", + "names", + "titles", + "shape", + "byteorder", + "aligned", + "offset", + "strides" + ], + "start_line": 375, + "end_line": 411, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 37, + "top_nesting_level": 0 + } + ], + "changed_methods": [ + { + "name": "array", + "long_name": "array( obj , formats = None , names = None , titles = None , shape = None , byteorder = None , aligned = 0 , offset = 0 , strides = None )", + "filename": "records.py", + "nloc": 37, + "complexity": 12, + "token_count": 363, + "parameters": [ + "obj", + "formats", + "names", + "titles", + "shape", + "byteorder", + "aligned", + "offset", + "strides" + ], + "start_line": 378, + "end_line": 416, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 39, + "top_nesting_level": 0 + }, + { + "name": "fromrecords", + "long_name": "fromrecords( recList , formats = None , names = None , titles = None , shape = None , aligned = 0 )", + "filename": "records.py", + "nloc": 28, + "complexity": 11, + "token_count": 260, + "parameters": [ + "recList", + "formats", + "names", + "titles", + "shape", + "aligned" + ], + "start_line": 241, + "end_line": 299, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 59, + "top_nesting_level": 0 + } + ], + "nloc": 270, + "complexity": 88, + "token_count": 2318, + "diff_parsed": { + "added": [ + " res = retval.view(recarray)", + " res.dtype = sb.dtype((record, res.dtype))", + " return res", + "", + " res = obj.view(recarray)", + " if issubclass(res.dtype, nt.void):", + " res.dtype = sb.dtype((record, res.dtype))" + ], + "deleted": [ + " return retval.view(recarray)", + " return obj.view(recarray)" + ] + } + }, + { + "old_path": "numpy/core/src/multiarraymodule.c", + "new_path": "numpy/core/src/multiarraymodule.c", + "filename": "multiarraymodule.c", + "extension": "c", + "change_type": "MODIFY", + "diff": "@@ -3930,12 +3930,12 @@ PyArray_DescrConverter(PyObject *obj, PyArray_Descr **at)\n \t\t}\n \t\treturn PY_SUCCEED;\n \t}\n- else {\n+ else goto fail; /*{\n \t\t*at = _arraydescr_fromobj(obj);\n \t\tif (*at) return PY_SUCCEED;\n \t\tif (PyErr_Occurred()) return PY_FAIL;\n \t\tgoto fail;\n-\t}\n+\t\t} */\n \tif (PyErr_Occurred()) goto fail;\n \n \t/*\n", + "added_lines": 2, + "deleted_lines": 2, + "source_code": "\n/*\n Python Multiarray Module -- A useful collection of functions for creating and\n using ndarrays\n\n Original file \n Copyright (c) 1995, 1996, 1997 Jim Hugunin, hugunin@mit.edu\n\n Modified for numpy_core in 2005 \n\n Travis E. Oliphant\n Assistant Professor at\n Brigham Young University\n \n*/\n\n/* $Id: multiarraymodule.c,v 1.36 2005/09/14 00:14:00 teoliphant Exp $ */\n\n#include \"Python.h\"\n#include \"structmember.h\"\n/*#include \n#include \n*/\n\n#define _MULTIARRAYMODULE\n#include \"numpy/arrayobject.h\"\n\n#define PyAO PyArrayObject\n\nstatic PyObject *typeDict=NULL; /* Must be explicitly loaded */\nstatic PyObject *_numpy_internal=NULL; /* A Python module for callbacks */\n\n\nstatic PyArray_Descr *\n_arraydescr_fromobj(PyObject *obj)\n{\n\tPyObject *dtypedescr;\n\tPyArray_Descr *new;\n\tint ret;\n\t\n\tdtypedescr = PyObject_GetAttrString(obj, \"dtype\");\n\tPyErr_Clear();\n\tif (dtypedescr) {\n\t\tret = PyArray_DescrConverter(dtypedescr, &new);\n\t\tPy_DECREF(dtypedescr);\n\t\tif (ret) return new;\n\t\tPyErr_Clear();\n\t}\n\treturn NULL;\n}\n\n\n/* Including this file is the only way I know how to declare functions\n static in each file, and store the pointers from functions in both\n arrayobject.c and multiarraymodule.c for the C-API \n\n Declarying an external pointer-containing variable in arrayobject.c\n and trying to copy it to PyArray_API, did not work.\n\n Think about two modules with a common api that import each other...\n\n This file would just be the module calls. \n*/\n\n#include \"arrayobject.c\"\n\n\n/* An Error object -- rarely used? */\nstatic PyObject *MultiArrayError;\n\n/*MULTIARRAY_API\n Multiply a List of ints\n*/\nstatic int\nPyArray_MultiplyIntList(register int *l1, register int n) \n{\n\tregister int s=1;\n while (n--) s *= (*l1++);\n return s;\n}\n\n/*MULTIARRAY_API\n Multiply a List\n*/\nstatic intp \nPyArray_MultiplyList(register intp *l1, register int n) \n{\n\tregister intp s=1;\n while (n--) s *= (*l1++);\n return s;\n}\n\n/*MULTIARRAY_API\n Produce a pointer into array\n*/\nstatic char *\nPyArray_GetPtr(PyArrayObject *obj, register intp* ind)\n{\n\tregister int n = obj->nd;\n\tregister intp *strides = obj->strides;\n\tregister char *dptr = obj->data;\n\t\n\twhile (n--) dptr += (*strides++) * (*ind++);\n\treturn dptr;\n}\n\n/*MULTIARRAY_API\n Get axis from an object (possibly None) -- a converter function,\n*/\nstatic int \nPyArray_AxisConverter(PyObject *obj, int *axis)\n{\n\tif (obj == Py_None) {\n\t\t*axis = MAX_DIMS;\n\t}\n\telse {\n\t\t*axis = (int) PyInt_AsLong(obj);\n\t\tif (PyErr_Occurred()) {\n\t\t\treturn PY_FAIL;\n\t\t}\n\t}\n\treturn PY_SUCCEED;\n}\n\n/*MULTIARRAY_API\n Compare Lists\n*/\nstatic int \nPyArray_CompareLists(intp *l1, intp *l2, int n) \n{\n int i;\n for(i=0;iob_type;\n\t\n\tPy_INCREF(self->descr);\n\tnew = PyArray_NewFromDescr(subtype,\n\t\t\t\t self->descr,\n\t\t\t\t self->nd, self->dimensions,\n\t\t\t\t self->strides,\n\t\t\t\t self->data,\n\t\t\t\t self->flags, (PyObject *)self);\n\t\n\tif (new==NULL) return NULL;\n\tPy_INCREF(self);\n PyArray_BASE(new) = (PyObject *)self;\n\t\n\tif (type != NULL) {\n\t\tif (PyObject_SetAttrString(new, \"dtype\",\n\t\t\t\t\t (PyObject *)type) < 0) {\n\t\t\tPy_DECREF(new);\n\t\t\tPy_DECREF(type);\n\t\t\treturn NULL;\n\t\t}\n\t\tPy_DECREF(type);\n\t}\n\treturn new;\t\n}\n\n/*MULTIARRAY_API\n Ravel\n*/\nstatic PyObject *\nPyArray_Ravel(PyArrayObject *a, int fortran)\n{\n\tPyArray_Dims newdim = {NULL,1};\n\tintp val[1] = {-1};\n\n\tif (fortran < 0) fortran = PyArray_ISFORTRAN(a);\n\n\tnewdim.ptr = val;\n\tif (!fortran && PyArray_ISCONTIGUOUS(a)) {\n\t\tif (a->nd == 1) {\n\t\t\tPy_INCREF(a);\n\t\t\treturn (PyObject *)a;\n\t\t}\n\t\treturn PyArray_Newshape(a, &newdim);\n\t}\n\telse\n\t return PyArray_Flatten(a, fortran);\n}\n\n/*MULTIARRAY_API\n Flatten\n*/\nstatic PyObject *\nPyArray_Flatten(PyArrayObject *a, int fortran)\n{\n\tPyObject *ret, *new;\n\tintp size;\n\n\tif (fortran < 0) fortran = PyArray_ISFORTRAN(a);\n\n\tsize = PyArray_SIZE(a);\n\tPy_INCREF(a->descr);\n\tret = PyArray_NewFromDescr(a->ob_type,\n\t\t\t\t a->descr,\n\t\t\t\t 1, &size,\n\t\t\t\t NULL,\n\t\t\t\t NULL,\n\t\t\t\t 0, (PyObject *)a);\n\t\n\tif (ret== NULL) return NULL;\n\tif (fortran) {\n\t\tnew = PyArray_Transpose(a, NULL);\n\t\tif (new == NULL) {\n\t\t\tPy_DECREF(ret);\n\t\t\treturn NULL;\n\t\t}\n\t}\n\telse {\n\t\tPy_INCREF(a);\n\t\tnew = (PyObject *)a;\n\t}\n\tif (PyArray_CopyInto((PyArrayObject *)ret, (PyArrayObject *)new) < 0) {\n\t\tPy_DECREF(ret);\n\t\tPy_DECREF(new);\n\t\treturn NULL;\n\t}\n\tPy_DECREF(new);\n\treturn ret;\n}\n\n\n/* For back-ward compatability *\n\n/ * Not recommended */\n\n/*MULTIARRAY_API\n Reshape an array\n*/\nstatic PyObject *\nPyArray_Reshape(PyArrayObject *self, PyObject *shape) \n{\n PyObject *ret;\n PyArray_Dims newdims;\n\n if (!PyArray_IntpConverter(shape, &newdims)) return NULL;\n ret = PyArray_Newshape(self, &newdims);\n PyDimMem_FREE(newdims.ptr);\n return ret;\n}\n\nstatic int\n_check_ones(PyArrayObject *self, int newnd, intp* newdims, intp *strides)\n{\n\tint nd;\n\tintp *dims;\n\tBool done=FALSE;\n\tint j, k;\n\n\tnd = self->nd;\n\tdims = self->dimensions;\n\n\tfor (k=0, j=0; !done && (jstrides[j];\n\t\t\tj++; k++;\n\t\t}\n\t\telse if ((kptr;\n PyArrayObject *ret;\n\tchar msg[] = \"total size of new array must be unchanged\";\n\tint n = newdims->len;\n Bool same;\n\tintp *strides = NULL;\n\tintp newstrides[MAX_DIMS];\n\n /* Quick check to make sure anything needs to be done */\n if (n == self->nd) {\n same = TRUE;\n i=0;\n while(same && i= 0) {\n\t\t\tif ((s_known == 0) || (s_original % s_known != 0)) {\n\t\t\t\tPyErr_SetString(PyExc_ValueError, msg);\n\t\t\t\treturn NULL;\n\t\t\t}\n\t\t\tdimensions[i_unknown] = s_original/s_known;\n\t\t} else {\n\t\t\tif (s_original != s_known) {\n\t\t\t\tPyErr_SetString(PyExc_ValueError, msg);\n\t\t\t\treturn NULL;\n\t\t\t}\n\t\t}\n\t}\n \n\tPy_INCREF(self->descr);\n\tret = (PyAO *)PyArray_NewFromDescr(self->ob_type,\n\t\t\t\t\t self->descr,\n\t\t\t\t\t n, dimensions,\n\t\t\t\t\t strides,\n\t\t\t\t\t self->data,\n\t\t\t\t\t self->flags, (PyObject *)self);\n\t\n\tif (ret== NULL) return NULL;\n\t\n Py_INCREF(self);\n ret->base = (PyObject *)self;\n\tPyArray_UpdateFlags(ret, CONTIGUOUS | FORTRAN);\n\t\n return (PyObject *)ret;\n}\n\n/* return a new view of the array object with all of its unit-length \n dimensions squeezed out if needed, otherwise\n return the same array.\n */\n\n/*MULTIARRAY_API*/\nstatic PyObject *\nPyArray_Squeeze(PyArrayObject *self)\n{\n\tint nd = self->nd;\n\tint newnd = nd;\n\tintp dimensions[MAX_DIMS];\n\tintp strides[MAX_DIMS];\n\tint i,j;\n\tPyObject *ret;\n\n\tif (nd == 0) {\n\t\tPy_INCREF(self);\n\t\treturn (PyObject *)self;\n\t}\n\tfor (j=0, i=0; idimensions[i] == 1) {\n\t\t\tnewnd -= 1;\n\t\t}\n\t\telse {\n\t\t\tdimensions[j] = self->dimensions[i];\n\t\t\tstrides[j++] = self->strides[i];\n\t\t}\n\t}\n\t\n\tPy_INCREF(self->descr);\n\tret = PyArray_NewFromDescr(self->ob_type, \n\t\t\t\t self->descr,\n\t\t\t\t newnd, dimensions, \n\t\t\t\t strides, self->data, \n\t\t\t\t self->flags,\n\t\t\t\t (PyObject *)self);\n\tif (ret == NULL) return NULL;\n\tPyArray_FLAGS(ret) &= ~OWN_DATA;\n\tPyArray_BASE(ret) = (PyObject *)self;\n\tPy_INCREF(self);\n\treturn (PyObject *)ret;\n}\n\n\n/*MULTIARRAY_API\n Mean\n*/\nstatic PyObject *\nPyArray_Mean(PyArrayObject *self, int axis, int rtype)\n{\n\tPyObject *obj1=NULL, *obj2=NULL;\n\tPyObject *new, *ret;\n\n\tif ((new = _check_axis(self, &axis, 0))==NULL) return NULL;\n\n\tobj1 = PyArray_GenericReduceFunction((PyAO *)new, n_ops.add, axis,\n\t\t\t\t\t rtype);\n\tobj2 = PyFloat_FromDouble((double) PyArray_DIM(new,axis));\n Py_DECREF(new);\n\tif (obj1 == NULL || obj2 == NULL) {\n\t\tPy_XDECREF(obj1);\n\t\tPy_XDECREF(obj2);\n\t\treturn NULL;\n\t}\n\n\tret = PyNumber_Divide(obj1, obj2);\n\tPy_DECREF(obj1);\n\tPy_DECREF(obj2);\n\treturn ret;\n}\n\n/* Set variance to 1 to by-pass square-root calculation and return variance */\n/*MULTIARRAY_API\n Std\n*/\nstatic PyObject *\nPyArray_Std(PyArrayObject *self, int axis, int rtype, int variance)\n{\n\tPyObject *obj1=NULL, *obj2=NULL, *new=NULL;\n\tPyObject *ret=NULL, *newshape=NULL;\n\tint i, n;\n\tintp val;\n\n\tif ((new = _check_axis(self, &axis, 0))==NULL) return NULL;\n\t\n\t/* Compute and reshape mean */\n\tobj1 = PyArray_EnsureArray(PyArray_Mean((PyAO *)new, axis, rtype));\n\tif (obj1 == NULL) {Py_DECREF(new); return NULL;} \n\tn = PyArray_NDIM(new);\n\tnewshape = PyTuple_New(n);\n\tif (newshape == NULL) {Py_DECREF(obj1); Py_DECREF(new); return NULL;}\n\tfor (i=0; ind != 1) {\n Py_DECREF(cond);\n PyErr_SetString(PyExc_ValueError, \n\t\t\t\t\"condition must be 1-d array\");\n return NULL;\n }\n\n res = PyArray_Nonzero(cond);\n Py_DECREF(cond);\n\tret = PyArray_Take(self, res, axis);\n\tPy_DECREF(res);\n\treturn ret;\n}\n\n/*MULTIARRAY_API\n Nonzero\n*/\nstatic PyObject *\nPyArray_Nonzero(PyArrayObject *self)\n{\n int n=self->nd, j;\n\tintp count=0, i, size;\n\tPyArrayIterObject *it=NULL;\n\tPyObject *ret=NULL, *item;\n\tintp *dptr[MAX_DIMS];\n\n\tit = (PyArrayIterObject *)PyArray_IterNew((PyObject *)self);\n\tif (it==NULL) return NULL;\n\n\tsize = it->size;\n\tfor (i=0; idescr->f->nonzero(it->dataptr, self)) count++;\n\t\tPyArray_ITER_NEXT(it);\n\t}\n\n\tPyArray_ITER_RESET(it);\n\tif (n==1) {\n\t\tret = PyArray_New(self->ob_type, 1, &count, PyArray_INTP, \n\t\t\t\t NULL, NULL, 0, 0, (PyObject *)self);\n\t\tif (ret == NULL) goto fail;\n\t\tdptr[0] = (intp *)PyArray_DATA(ret);\n\t\t\n\t\tfor (i=0; idescr->f->nonzero(it->dataptr, self)) \n\t\t\t\t*(dptr[0])++ = i;\n\t\t\tPyArray_ITER_NEXT(it);\n\t\t}\t\t\n\t}\n\telse {\n\t\tret = PyTuple_New(n);\n\t\tfor (j=0; job_type, 1, &count, \n\t\t\t\t\t PyArray_INTP, NULL, NULL, 0, 0,\n\t\t\t\t\t (PyObject *)self);\n\t\t\tif (item == NULL) goto fail;\n\t\t\tPyTuple_SET_ITEM(ret, j, item);\n\t\t\tdptr[j] = (intp *)PyArray_DATA(item);\n\t\t}\n\t\t\n\t\t/* reset contiguous so that coordinates gets updated */\n\t\tit->contiguous = 0;\n\t\tfor (i=0; idescr->f->nonzero(it->dataptr, self)) \n\t\t\t\tfor (j=0; jcoordinates[j];\n\t\t\tPyArray_ITER_NEXT(it);\n\t\t}\n\t}\n\n\tPy_DECREF(it);\n\treturn ret;\n\n fail:\n\tPy_XDECREF(ret);\n\tPy_XDECREF(it);\n\treturn NULL;\n \n}\n\n/*MULTIARRAY_API\n Clip\n*/\nstatic PyObject *\nPyArray_Clip(PyArrayObject *self, PyObject *min, PyObject *max)\n{\n\tPyObject *selector=NULL, *newtup=NULL, *ret=NULL;\n\tPyObject *res1=NULL, *res2=NULL, *res3=NULL;\n\tPyObject *two;\n\n\ttwo = PyInt_FromLong((long)2);\n\tres1 = PyArray_GenericBinaryFunction(self, max, n_ops.greater);\n\tres2 = PyArray_GenericBinaryFunction(self, min, n_ops.less);\n\tif ((res1 == NULL) || (res2 == NULL)) {\n\t\tPy_DECREF(two);\n\t\tPy_XDECREF(res1);\n\t\tPy_XDECREF(res2);\n\t}\n\tres3 = PyNumber_Multiply(two, res1);\n\tPy_DECREF(two); \n\tPy_DECREF(res1); \n\tif (res3 == NULL) return NULL;\n\n\tselector = PyArray_EnsureArray(PyNumber_Add(res2, res3));\n\tPy_DECREF(res2);\n\tPy_DECREF(res3);\n\tif (selector == NULL) return NULL;\n\n\tnewtup = Py_BuildValue(\"(OOO)\", (PyObject *)self, min, max);\n\tif (newtup == NULL) {Py_DECREF(selector); return NULL;}\n\tret = PyArray_Choose((PyAO *)selector, newtup);\n\tPy_DECREF(selector);\n\tPy_DECREF(newtup);\n\treturn ret;\n}\n\n/*MULTIARRAY_API\n Conjugate\n*/\nstatic PyObject *\nPyArray_Conjugate(PyArrayObject *self)\n{\n\tif (PyArray_ISCOMPLEX(self)) {\n\t\tPyObject *new;\n\t\tintp size, i;\n\t\t/* Make a copy */\n\t\tnew = PyArray_NewCopy(self, -1);\n\t\tif (new==NULL) return NULL;\n\t\tsize = PyArray_SIZE(new);\n\t\tif (self->descr->type_num == PyArray_CFLOAT) {\n\t\t\tcfloat *dptr = (cfloat *) PyArray_DATA(new);\n\t\t\tfor (i=0; iimag = -dptr->imag;\n\t\t\t\tdptr++;\n\t\t\t}\n\t\t}\n\t\telse if (self->descr->type_num == PyArray_CDOUBLE) {\n\t\t\tcdouble *dptr = (cdouble *)PyArray_DATA(new);\n\t\t\tfor (i=0; iimag = -dptr->imag;\n\t\t\t\tdptr++;\n\t\t\t}\n\t\t}\n\t\telse if (self->descr->type_num == PyArray_CLONGDOUBLE) {\n\t\t\tclongdouble *dptr = (clongdouble *)PyArray_DATA(new);\n\t\t\tfor (i=0; iimag = -dptr->imag;\n\t\t\t\tdptr++;\n\t\t\t}\t\t\t\n\t\t}\t\t\n\t\treturn new;\n\t}\n\telse {\n\t\tPy_INCREF(self);\n\t\treturn (PyObject *) self;\n\t}\n}\n\n/*MULTIARRAY_API\n Trace\n*/\nstatic PyObject *\nPyArray_Trace(PyArrayObject *self, int offset, int axis1, int axis2, \nint rtype)\n{\n\tPyObject *diag=NULL, *ret=NULL;\n\n\tdiag = PyArray_Diagonal(self, offset, axis1, axis2);\n\tif (diag == NULL) return NULL;\n\tret = PyArray_GenericReduceFunction((PyAO *)diag, n_ops.add, -1, rtype);\n\tPy_DECREF(diag);\n\treturn ret;\n}\n\n/*MULTIARRAY_API\n Diagonal\n*/\nstatic PyObject *\nPyArray_Diagonal(PyArrayObject *self, int offset, int axis1, int axis2)\n{\n\tint n = self->nd;\n\tPyObject *new;\n\tPyArray_Dims newaxes;\n\tintp dims[MAX_DIMS];\n\tint i, pos;\t\n\n\tnewaxes.ptr = dims;\n\tif (n < 2) {\n\t\tPyErr_SetString(PyExc_ValueError, \n\t\t\t\t\"array.ndim must be >= 2\");\n\t\treturn NULL;\n\t}\n\tif (axis1 < 0) axis1 += n;\n\tif (axis2 < 0) axis2 += n;\n\tif ((axis1 == axis2) || (axis1 < 0) || (axis1 >= n) ||\t\\\n\t (axis2 < 0) || (axis2 >= n)) {\n\t\tPyErr_Format(PyExc_ValueError, \"axis1(=%d) and axis2(=%d) \"\\\n\t\t\t \"must be different and within range (nd=%d)\",\n\t\t\t axis1, axis2, n);\n\t\treturn NULL;\n\t}\n \n\tnewaxes.len = n;\n\t/* insert at the end */\n\tnewaxes.ptr[n-2] = axis1;\n\tnewaxes.ptr[n-1] = axis2;\n\tpos = 0;\n\tfor (i=0; idimensions[0];\n\t\tn2 = self->dimensions[1];\n\t\tstep = n2+1;\n\t\tif (offset < 0) {\n\t\t\tstart = -n2 * offset;\n\t\t\tstop = MIN(n2, n1+offset)*(n2+1) - n2*offset;\n\t\t}\n\t\telse {\n\t\t\tstart = offset;\n\t\t\tstop = MIN(n1, n2-offset)*(n2+1) + offset;\n\t\t}\n\t\t\n\t\t/* count = ceil((stop-start)/step) */\n\t\tcount = ((stop-start) / step) + (((stop-start) % step) != 0);\n\t\t\t\n\t\tindices = PyArray_New(&PyArray_Type, 1, &count, \n\t\t\t\t PyArray_INTP, NULL, NULL, 0, 0, NULL);\n\t\tif (indices == NULL) {\n\t\t\tPy_DECREF(self); return NULL;\n\t\t}\n\t\tdptr = (intp *)PyArray_DATA(indices);\n\t\tfor (n1=start; n1descr;\n\n\t\tmydiagonal = PyList_New(0);\n\t\tif (mydiagonal == NULL) {Py_DECREF(self); return NULL;}\n\t\tn1 = self->dimensions[0];\n\t\tfor (i=0; i 3)) {\n\t\tPyErr_SetString(PyExc_ValueError,\n\t\t\t\t\"C arrays of only 1-3 dimensions available\");\n\t\tPy_XDECREF(typedescr);\n\t\treturn -1;\n\t}\n\tif ((ap = (PyArrayObject*)PyArray_FromAny(*op, typedescr, nd, nd,\n\t\t\t\t\t\t CARRAY_FLAGS, NULL)) == NULL)\n\t\treturn -1;\n\tswitch(nd) {\n\tcase 1:\n\t\t*((char **)ptr) = ap->data;\n\t\tbreak;\n\tcase 2:\n\t\tn = ap->dimensions[0];\n\t\tptr2 = (char **)_pya_malloc(n * sizeof(char *));\n\t\tif (!ptr2) goto fail;\n\t\tfor (i=0; idata + i*ap->strides[0];\n\t\t}\n\t\t*((char ***)ptr) = ptr2;\n\t\tbreak;\t\t\n\tcase 3:\n\t\tn = ap->dimensions[0];\n\t\tm = ap->dimensions[1];\n\t\tptr3 = (char ***)_pya_malloc(n*(m+1) * sizeof(char *));\n\t\tif (!ptr3) goto fail;\n\t\tfor (i=0; idata + i*ap->strides[0] + \\\n\t\t\t\t\tj*ap->strides[1];\n\t\t\t}\n\t\t}\n\t\t*((char ****)ptr) = ptr3;\n\t}\n\tmemcpy(dims, ap->dimensions, nd*sizeof(intp));\n\t*op = (PyObject *)ap;\n\treturn 0;\n\n fail:\n\tPyErr_SetString(PyExc_MemoryError, \"no memory\");\n\treturn -1;\n}\n\n/* Deprecated --- Use PyArray_AsCArray instead */\n\n/*MULTIARRAY_API\n Convert to a 1D C-array\n*/\nstatic int \nPyArray_As1D(PyObject **op, char **ptr, int *d1, int typecode) \n{\n\tintp newd1;\n\tPyArray_Descr *descr;\n\n\tdescr = PyArray_DescrFromType(typecode);\t\n\tif (PyArray_AsCArray(op, (void *)ptr, &newd1, 1, descr) == -1)\n\t\treturn -1;\t\n\t*d1 = (int) newd1;\n\treturn 0;\n}\n\n/*MULTIARRAY_API\n Convert to a 2D C-array\n*/\nstatic int \nPyArray_As2D(PyObject **op, char ***ptr, int *d1, int *d2, int typecode) \n{\n\tintp newdims[2];\n\tPyArray_Descr *descr;\n\n\tdescr = PyArray_DescrFromType(typecode);\t\n\tif (PyArray_AsCArray(op, (void *)ptr, newdims, 2, descr) == -1)\n\t\treturn -1;\n\n\t*d1 = (int ) newdims[0];\n\t*d2 = (int ) newdims[1];\n return 0;\n}\n\n/* End Deprecated */\n\n/*MULTIARRAY_API\n Free pointers created if As2D is called\n*/\nstatic int \nPyArray_Free(PyObject *op, void *ptr) \n{\n PyArrayObject *ap = (PyArrayObject *)op;\n\t\n if ((ap->nd < 1) || (ap->nd > 3)) \n\t\treturn -1;\n if (ap->nd >= 2) {\n\t\t_pya_free(ptr);\n }\n Py_DECREF(ap);\n return 0;\n}\n\n\nstatic PyObject *\n_swap_and_concat(PyObject *op, int axis, int n)\n{\n\tPyObject *newtup=NULL;\n\tPyObject *otmp, *arr;\n\tint i;\n\n\tnewtup = PyTuple_New(n);\n\tif (newtup==NULL) return NULL;\n\tfor (i=0; i= MAX_DIMS) {\n\t\t\totmp = PyArray_Ravel(mps[i],0);\n\t\t\tPy_DECREF(mps[i]);\n\t\t\tmps[i] = (PyArrayObject *)otmp;\n\t\t}\n\t\tif (mps[i]->ob_type != subtype) {\n\t\t\tprior2 = PyArray_GetPriority((PyObject *)(mps[i]), 0.0);\n\t\t\tif (prior2 > prior1) {\n\t\t\t\tprior1 = prior2;\n\t\t\t\tsubtype = mps[i]->ob_type;\n\t\t\t\tret = mps[i];\n\t\t\t}\n\t\t}\n\t}\n\t\n\tnew_dim = 0;\n\tfor(i=0; ind;\n\t\telse {\n\t\t\tif (nd != mps[i]->nd) {\n\t\t\t\tPyErr_SetString(PyExc_ValueError, \n\t\t\t\t\t\t\"arrays must have same \"\\\n\t\t\t\t\t\t\"number of dimensions\");\n\t\t\t\tgoto fail;\n\t\t\t}\n\t\t\tif (!PyArray_CompareLists(mps[0]->dimensions+1, \n\t\t\t\t\t\t mps[i]->dimensions+1, \n\t\t\t\t\t\t nd-1)) {\n\t\t\t\tPyErr_SetString(PyExc_ValueError, \n\t\t\t\t\t\t\"array dimensions must \"\\\n\t\t\t\t\t\t\"agree except for d_0\");\n\t\t\t\tgoto fail;\n\t\t\t}\n\t\t}\n\t\tif (nd == 0) {\n\t\t\tPyErr_SetString(PyExc_ValueError, \n\t\t\t\t\t\"0-d arrays can't be concatenated\");\n\t\t\tgoto fail;\n\t\t}\n\t\tnew_dim += mps[i]->dimensions[0];\n\t}\n\t\n\ttmp = mps[0]->dimensions[0];\n\tmps[0]->dimensions[0] = new_dim;\n\tPy_INCREF(mps[0]->descr);\n\tret = (PyArrayObject *)PyArray_NewFromDescr(subtype, \n\t\t\t\t\t\t mps[0]->descr, nd,\n\t\t\t\t\t\t mps[0]->dimensions, \n\t\t\t\t\t\t NULL, NULL, 0,\n\t\t\t\t\t\t (PyObject *)ret);\n\tmps[0]->dimensions[0] = tmp;\n\t\n\tif (ret == NULL) goto fail;\n\t\n\tdata = ret->data;\n\tfor(i=0; idata, numbytes);\n\t\tdata += numbytes;\n\t}\n\t\n\tPyArray_INCREF(ret);\n\tfor(i=0; ind;\n\tif (n <= 1) {\n\t\tPy_INCREF(ap);\n\t\treturn (PyObject *)ap;\n\t}\n\n\tif (a1 < 0) a1 += n;\n\tif (a2 < 0) a2 += n;\n\tif ((a1 < 0) || (a1 >= n)) {\n\t\tPyErr_SetString(PyExc_ValueError, \n\t\t\t\t\"bad axis1 argument to swapaxes\");\n\t\treturn NULL;\n\t}\n\tif ((a2 < 0) || (a2 >= n)) {\n\t\tPyErr_SetString(PyExc_ValueError, \n\t\t\t\t\"bad axis2 argument to swapaxes\");\n\t\treturn NULL;\n\t}\n\tnew_axes.ptr = dims;\n\tnew_axes.len = n;\n\n\tfor (i=0; ind;\n\t\tfor(i=0; ilen;\n\t\taxes = permute->ptr;\n\t\tif (n > ap->nd) {\n\t\t\tPyErr_SetString(PyExc_ValueError, \n\t\t\t\t\t\"too many axes for this array\");\n\t\t\treturn NULL;\n\t\t}\n\t\tfor(i=0; ind+axis;\n\t\t\tif (axis < 0 || axis >= ap->nd) {\n\t\t\t\tPyErr_SetString(PyExc_ValueError, \n\t\t\t\t\t\t\"invalid axis for this array\");\n\t\t\t\treturn NULL;\n\t\t\t}\n\t\t\tpermutation[i] = axis;\n\t\t}\n\t}\n\t\n\t/* this allocates memory for dimensions and strides (but fills them\n\t incorrectly), sets up descr, and points data at ap->data. */\n\tPy_INCREF(ap->descr);\n\tret = (PyArrayObject *)\\\n\t\tPyArray_NewFromDescr(ap->ob_type, \n\t\t\t\t ap->descr, \n\t\t\t\t n, permutation, \n\t\t\t\t NULL, ap->data, ap->flags,\n\t\t\t\t (PyObject *)ap);\n\tif (ret == NULL) return NULL;\n\t\n\t/* point at true owner of memory: */\n\tret->base = (PyObject *)ap;\n\tPy_INCREF(ap);\n\t\n\tfor(i=0; idimensions[i] = ap->dimensions[permutation[i]];\n\t\tret->strides[i] = ap->strides[permutation[i]];\n\t}\n\tPyArray_UpdateFlags(ret, CONTIGUOUS | FORTRAN);\t\n\n\treturn (PyObject *)ret;\t\n}\n\n/*MULTIARRAY_API\n Repeat the array.\n*/\nstatic PyObject *\nPyArray_Repeat(PyArrayObject *aop, PyObject *op, int axis)\n{\n\tintp *counts;\n\tintp n, n_outer, i, j, k, chunk, total;\n\tintp tmp;\n\tint nd;\n\tPyArrayObject *repeats=NULL;\n\tPyObject *ap=NULL;\n\tPyArrayObject *ret=NULL;\n\tchar *new_data, *old_data;\n\n\trepeats = (PyAO *)PyArray_ContiguousFromAny(op, PyArray_INTP, 0, 1);\n\tif (repeats == NULL) return NULL;\n\tnd = repeats->nd;\n\tcounts = (intp *)repeats->data;\n\n\tif ((ap=_check_axis(aop, &axis, CARRAY_FLAGS))==NULL) {\n\t\tPy_DECREF(repeats);\n\t\treturn NULL;\n\t}\n\n\taop = (PyAO *)ap;\n\n\tif (nd == 1)\n\t\tn = repeats->dimensions[0];\n\telse /* nd == 0 */\n\t\tn = aop->dimensions[axis];\n\n\tif (aop->dimensions[axis] != n) {\n\t\tPyErr_SetString(PyExc_ValueError, \n\t\t\t\t\"a.shape[axis] != len(repeats)\");\n\t\tgoto fail;\n\t}\n\n\t\n\tif (nd == 0) \n\t\ttotal = counts[0]*n;\n\telse {\n\t\t\n\t\ttotal = 0;\n\t\tfor(j=0; jdimensions[axis] = total;\n\tPy_INCREF(aop->descr);\n\tret = (PyArrayObject *)PyArray_NewFromDescr(aop->ob_type, \n\t\t\t\t\t\t aop->descr,\n\t\t\t\t\t\t aop->nd,\n\t\t\t\t\t\t aop->dimensions,\n\t\t\t\t\t\t NULL, NULL, 0,\n\t\t\t\t\t\t (PyObject *)aop);\n\taop->dimensions[axis] = n;\n\t\n\tif (ret == NULL) goto fail;\n\t\n\tnew_data = ret->data;\n\told_data = aop->data;\n\t\n\tchunk = aop->descr->elsize;\n\tfor(i=axis+1; ind; i++) {\n\t\tchunk *= aop->dimensions[i];\n\t}\n\t\n\tn_outer = 1;\n\tfor(i=0; idimensions[i];\n\n\tfor(i=0; ind < mps[i]->nd) {\n\t\t\tPyErr_SetString(PyExc_ValueError, \n\t\t\t\t\t\"too many dimensions\");\n\t\t\tgoto fail;\n\t\t}\n\t\tif (!PyArray_CompareLists(ap->dimensions+(ap->nd-mps[i]->nd),\n\t\t\t\t mps[i]->dimensions, mps[i]->nd)) {\n\t\t\tPyErr_SetString(PyExc_ValueError, \n\t\t\t\t\t\"array dimensions must agree\");\n\t\t\tgoto fail;\n\t\t}\n\t\tsizes[i] = PyArray_NBYTES(mps[i]);\n\t}\n\t\n\tPy_INCREF(mps[0]->descr);\n\tret = (PyArrayObject *)PyArray_NewFromDescr(ap->ob_type, \n\t\t\t\t\t\t mps[0]->descr,\n\t\t\t\t\t\t ap->nd,\n\t\t\t\t\t\t ap->dimensions, \n\t\t\t\t\t\t NULL, NULL, 0,\n\t\t\t\t\t\t (PyObject *)ap);\n\tif (ret == NULL) goto fail;\n\t\n\telsize = ret->descr->elsize;\n\tm = PyArray_SIZE(ret);\n\tself_data = (intp *)ap->data;\n\tret_data = ret->data;\n\t\n\tfor (i=0; i= n) {\n\t\t\tPyErr_SetString(PyExc_ValueError, \n\t\t\t\t\t\"invalid entry in choice array\");\n\t\t\tgoto fail;\n\t\t}\n\t\toffset = i*elsize;\n\t\tif (offset >= sizes[mi]) {offset = offset % sizes[mi]; }\n\t\tmemmove(ret_data, mps[mi]->data+offset, elsize);\n\t\tret_data += elsize; self_data++;\n\t}\n\t\n\tPyArray_INCREF(ret);\n\tfor(i=0; idescr->f->sort[which];\n\tsize = it->size;\n\tN = op->dimensions[axis];\n\telsize = op->descr->elsize;\n\tastride = op->strides[axis];\n\n\tneedcopy = !(op->flags & ALIGNED) || (astride != (intp) elsize);\n\n\tif (needcopy) {\n\t\tchar *buffer;\n\t\tbuffer = PyDataMem_NEW(N*elsize);\n\t\twhile (size--) {\n\t\t\t_strided_copy(buffer, (intp) elsize, it->dataptr, \n\t\t\t\t astride, N, elsize);\n\t\t\tif (sort(buffer, N, op) < 0) {\n\t\t\t\tPyDataMem_FREE(buffer); goto fail;\n\t\t\t}\n\t\t\t_strided_copy(it->dataptr, astride, buffer, \n\t\t\t\t (intp) elsize, N, elsize);\n\t\t\tPyArray_ITER_NEXT(it);\n\t\t}\n\t\tPyDataMem_FREE(buffer);\n\t}\n\telse {\n\t\twhile (size--) {\n\t\t\tif (sort(it->dataptr, N, op) < 0) goto fail;\n\t\t\tPyArray_ITER_NEXT(it);\n\t\t}\n\t}\t\n\t\n\tEND_THREADS\n\t\n\tPy_DECREF(it);\n\treturn 0;\n\n fail:\n\tEND_THREADS\n\n\tPy_DECREF(it);\n\treturn 0;\n}\n\nstatic PyObject*\n_new_argsort(PyArrayObject *op, int axis, PyArray_SORTKIND which) \n{\n\n\tPyArrayIterObject *it=NULL;\n\tPyArrayIterObject *rit=NULL;\n\tPyObject *ret;\n\tint needcopy=0, i;\n\tintp N, size;\n\tint elsize;\n\tintp astride, rstride, *iptr;\n\tPyArray_ArgSortFunc *argsort;\n\tBEGIN_THREADS_DEF \n\n\tret = PyArray_New(op->ob_type, op->nd,\n\t\t\t op->dimensions, PyArray_INTP,\n\t\t\t NULL, NULL, 0, 0, (PyObject *)op);\n\tif (ret == NULL) return NULL;\n\n\tit = (PyArrayIterObject *)PyArray_IterAllButAxis((PyObject *)op, axis);\n\trit = (PyArrayIterObject *)PyArray_IterAllButAxis(ret, axis);\n\tif (rit == NULL || it == NULL) goto fail;\n\n\tBEGIN_THREADS\n\n\targsort = op->descr->f->argsort[which];\n\tsize = it->size;\n\tN = op->dimensions[axis];\n\telsize = op->descr->elsize;\n\tastride = op->strides[axis];\n\trstride = PyArray_STRIDE(ret,axis);\n\n\tneedcopy = !(op->flags & ALIGNED) || (astride != (intp) elsize) || \\\n\t\t(rstride != sizeof(intp));\n\t\n\tif (needcopy) {\n\t\tchar *valbuffer, *indbuffer;\n\t\tvalbuffer = PyDataMem_NEW(N*(elsize+sizeof(intp)));\n\t\tindbuffer = valbuffer + (N*elsize);\n\t\twhile (size--) {\n\t\t\t_strided_copy(valbuffer, (intp) elsize, it->dataptr,\n\t\t\t\t astride, N, elsize);\n\t\t\tiptr = (intp *)indbuffer;\n\t\t\tfor (i=0; idataptr, rstride, indbuffer, \n\t\t\t\t sizeof(intp), N, sizeof(intp));\n\t\t\tPyArray_ITER_NEXT(it);\n\t\t\tPyArray_ITER_NEXT(rit);\n\t\t}\n\t\tPyDataMem_FREE(valbuffer);\n\t}\n\telse {\n\t\twhile (size--) {\n\t\t\tiptr = (intp *)rit->dataptr;\n\t\t\tfor (i=0; idataptr, (intp *)rit->dataptr, \n\t\t\t\t N, op) < 0) goto fail;\n\t\t\tPyArray_ITER_NEXT(it);\n\t\t\tPyArray_ITER_NEXT(rit);\n\t\t}\n\t}\n\t\n\tEND_THREADS\n\n\tPy_DECREF(it);\n\tPy_DECREF(rit);\n\treturn ret;\n\n fail:\n\n\tEND_THREADS\n\n\tPy_DECREF(ret);\n\tPy_XDECREF(it);\n\tPy_XDECREF(rit);\n\treturn NULL;\n}\n\n\n/* Be sure to save this global_compare when necessary */\n\nstatic PyArrayObject *global_obj;\n\nstatic int \nqsortCompare (const void *a, const void *b) \n{\n\treturn global_obj->descr->f->compare(a,b,global_obj);\n}\n\n/* Consumes reference to ap (op gets it)\n op contains a version of the array with axes swapped if\n local variable axis is not the last dimension.\n orign must be defined locally. \n*/\n\n#define SWAPAXES(op, ap) {\t\t\t\t\t\t\\\n\t\torign = (ap)->nd-1;\t\t\t\t\t\\\n\t\tif (axis != orign) {\t\t\t\t\t\\\n\t\t\t(op) = (PyAO *)PyArray_SwapAxes((ap), axis, orign); \\\n\t\t\tPy_DECREF((ap));\t\t\t\t\\\n\t\t\tif ((op) == NULL) return NULL;\t\t\t\\\n\t\t}\t\t\t\t\t\t\t\\\n\t\telse (op) = (ap);\t\t\t\t\t\\\n\t}\n\n/* Consumes reference to ap (op gets it)\n origin must be previously defined locally. \n SWAPAXES must have been called previously. \n op contains the swapped version of the array. \n*/\n#define SWAPBACK(op, ap) {\t \\\n\t\tif (axis != orign) { \\\n\t\t\t(op) = (PyAO *)PyArray_SwapAxes((ap), axis, orign); \\\n\t\t\tPy_DECREF((ap));\t\t\t\t\\\n\t\t\tif ((op) == NULL) return NULL;\t\t\t\\\n\t\t}\t\t\t\t\t\t\t\\\n\t\telse (op) = (ap);\t\t\t\t\t\\\n\t}\n\n/* These swap axes in-place if necessary */\n#define SWAPINTP(a,b) {intp c; c=(a); (a) = (b); (b) = c;}\n#define SWAPAXES2(ap) {\t\t\t\t\t\t\\\n\t\torign = (ap)->nd-1;\t\t\t\t\t\\\n\t\tif (axis != orign) {\t\t\t\t\t\\\n\t\t\tSWAPINTP(ap->dimensions[axis], ap->dimensions[orign]); \\\n\t\t\tSWAPINTP(ap->strides[axis], ap->strides[orign]); \\\n\t\t\tPyArray_UpdateFlags(ap, CONTIGUOUS | FORTRAN); \\\n\t\t}\t\t\t\t\t\t \\\n\t}\n\n#define SWAPBACK2(ap) {\t\t \\\n\t\tif (axis != orign) {\t\t\t\t\t\\\n\t\t\tSWAPINTP(ap->dimensions[axis], ap->dimensions[orign]); \\\n\t\t\tSWAPINTP(ap->strides[axis], ap->strides[orign]); \\\n\t\t\tPyArray_UpdateFlags(ap, CONTIGUOUS | FORTRAN);\t\\\n\t\t}\t\t\t\t\t\t\t\\\n\t}\n\n/*MULTIARRAY_API\n Sort an array in-place\n*/\nstatic int\nPyArray_Sort(PyArrayObject *op, int axis, PyArray_SORTKIND which) \n{\n\tPyArrayObject *ap=NULL, *store_arr=NULL;\n\tchar *ip;\n\tint i, n, m, elsize, orign;\n\n\tn = op->nd;\n\tif ((n==0) || (PyArray_SIZE(op)==1)) return 0;\n\n\tif (axis < 0) axis += n;\n\tif ((axis < 0) || (axis >= n)) {\n\t\tPyErr_Format(PyExc_ValueError, \n\t\t\t \"axis(=%d) out of bounds\", axis);\n\t\treturn -1;\n\t}\n\tif (!PyArray_ISWRITEABLE(op)) {\n\t\tPyErr_SetString(PyExc_RuntimeError, \n\t\t\t\t\"attempted sort on unwriteable array.\");\n\t\treturn -1;\n\t}\n\n\t/* Determine if we should use type-specific algorithm or not */\n\tif (op->descr->f->sort[which] != NULL) {\n\t\treturn _new_sort(op, axis, which);\n\t}\n\n\tif ((which != PyArray_QUICKSORT) || \\\n\t op->descr->f->compare == NULL) {\n\t\tPyErr_SetString(PyExc_TypeError, \n\t\t\t\t\"desired sort not supported for this type\");\n\t\treturn -1;\n\t}\n\n\tSWAPAXES2(op);\n\n ap = (PyArrayObject *)PyArray_FromAny((PyObject *)op, \n\t\t\t\t\t NULL, 1, 0, \n\t\t\t\t\t DEFAULT_FLAGS | UPDATEIFCOPY, NULL);\t\n\tif (ap == NULL) goto fail;\n\t\n\telsize = ap->descr->elsize;\n\tm = ap->dimensions[ap->nd-1];\n\tif (m == 0) goto finish;\n\n\tn = PyArray_SIZE(ap)/m;\n\n\t/* Store global -- allows re-entry -- restore before leaving*/\n\tstore_arr = global_obj; \n\tglobal_obj = ap;\n\t\n\tfor (ip=ap->data, i=0; idescr->elsize;\n\tconst intp *ipa = ip1;\n\tconst intp *ipb = ip2;\t\n\treturn global_obj->descr->f->compare(global_data + (isize * *ipa),\n global_data + (isize * *ipb), \n\t\t\t\t\t global_obj);\n}\n\n/*MULTIARRAY_API\n ArgSort an array\n*/\nstatic PyObject *\nPyArray_ArgSort(PyArrayObject *op, int axis, PyArray_SORTKIND which) \n{\n\tPyArrayObject *ap=NULL, *ret=NULL, *store;\n\tintp *ip;\n\tintp i, j, n, m, orign;\n\tint argsort_elsize;\n\tchar *store_ptr;\n\n\tn = op->nd;\n\tif ((n==0) || (PyArray_SIZE(op)==1)) {\n\t\tret = (PyArrayObject *)PyArray_New(op->ob_type, op->nd,\n\t\t\t\t\t\t op->dimensions, \n\t\t\t\t\t\t PyArray_INTP,\n\t\t\t\t\t\t NULL, NULL, 0, 0, \n\t\t\t\t\t\t (PyObject *)op);\n\t\tif (ret == NULL) return NULL;\n\t\t*((intp *)ret->data) = 0;\n\t\treturn (PyObject *)ret;\n\t}\n\tif (axis < 0) axis += n;\n\tif ((axis < 0) || (axis >= n)) {\n\t\tPyErr_Format(PyExc_ValueError, \n\t\t\t \"axis(=%d) out of bounds\", axis);\n\t\treturn NULL;\n\t}\n\n\t/* Determine if we should use new algorithm or not */\n\tif (op->descr->f->argsort[which] != NULL) {\n\t\treturn _new_argsort(op, axis, which);\n\t}\n\n\tif ((which != PyArray_QUICKSORT) || op->descr->f->compare == NULL) {\n\t\tPyErr_SetString(PyExc_TypeError, \n\t\t\t\t\"requested sort not available for type\");\n\t\tgoto fail;\n\t}\n\n\tSWAPAXES(ap, op);\n\n\top = (PyArrayObject *)PyArray_ContiguousFromAny((PyObject *)ap, \n\t\t\t\t\t\t\t PyArray_NOTYPE,\n\t\t\t\t\t\t\t 1, 0);\n\n\tif (op == NULL) return NULL;\n\t\n\tret = (PyArrayObject *)PyArray_New(op->ob_type, op->nd,\n\t\t\t\t\t op->dimensions, PyArray_INTP,\n\t\t\t\t\t NULL, NULL, 0, 0, (PyObject *)op);\n\tif (ret == NULL) goto fail;\n\t\n\t\n\tip = (intp *)ret->data;\n\targsort_elsize = op->descr->elsize;\n\tm = op->dimensions[op->nd-1];\n\tif (m == 0) goto finish;\n\n\tn = PyArray_SIZE(op)/m;\n\tstore_ptr = global_data;\n\tglobal_data = op->data;\n\tstore = global_obj;\n\tglobal_obj = op;\n\tfor (i=0; i 0 in lexsort\");\n\t\treturn NULL;\n\t}\n\tmps = (PyArrayObject **) _pya_malloc(n*sizeof(PyArrayObject));\n\tif (mps==NULL) return PyErr_NoMemory();\n\tits = (PyArrayIterObject **) _pya_malloc(n*sizeof(PyArrayIterObject));\n\tif (its == NULL) {_pya_free(mps); return PyErr_NoMemory();}\n\tfor (i=0; i0) {\n\t\t\tif ((mps[i]->nd != mps[0]->nd) ||\t\\\n\t\t\t (!PyArray_CompareLists(mps[i]->dimensions,\n\t\t\t\t\t\t mps[0]->dimensions,\n\t\t\t\t\t\t mps[0]->nd))) {\n\t\t\t\tPyErr_SetString(PyExc_ValueError,\n\t\t\t\t\t\t\"all keys need to be the same shape\");\n\t\t\t\tgoto fail;\n\t\t\t}\n\t\t}\n\t\tif (!mps[i]->descr->f->argsort[PyArray_MERGESORT]) {\n\t\t\tPyErr_Format(PyExc_TypeError, \n\t\t\t\t \"merge sort not available for item %d\", i);\n\t\t\tgoto fail;\n\t\t}\n\t\tits[i] = (PyArrayIterObject *)PyArray_IterAllButAxis\t\\\n\t\t\t((PyObject *)mps[i], axis);\n\t\tif (its[i]==NULL) goto fail;\n\t}\n\n\t/* Now we can check the axis */\n\tnd = mps[0]->nd;\n\tif ((nd==0) || (PyArray_SIZE(mps[0])==1)) {\n\t\tret = (PyArrayObject *)PyArray_New(&PyArray_Type, mps[0]->nd,\n\t\t\t\t\t\t mps[0]->dimensions, \n\t\t\t\t\t\t PyArray_INTP,\n\t\t\t\t\t\t NULL, NULL, 0, 0, NULL);\n\t\tif (ret == NULL) return NULL;\n\t\t*((intp *)(ret->data)) = 0;\n\t\treturn (PyObject *)ret;\n\t}\n\tif (axis < 0) axis += nd;\n\tif ((axis < 0) || (axis >= nd)) {\n\t\tPyErr_Format(PyExc_ValueError, \n\t\t\t \"axis(=%d) out of bounds\", axis);\n\t\tgoto fail;\n\t}\n\n\t/* Now do the sorting */\n\n\tret = (PyArrayObject *)PyArray_New(&PyArray_Type, mps[0]->nd,\n\t\t\t\t\t mps[0]->dimensions, PyArray_INTP,\n\t\t\t\t\t NULL, NULL, 0, 0, NULL);\n\tif (ret == NULL) goto fail;\n\n\trit = (PyArrayIterObject *)\\\n\t\tPyArray_IterAllButAxis((PyObject *)ret, axis);\n\tif (rit == NULL) goto fail;\n\n\tsize = rit->size;\n\tN = mps[0]->dimensions[axis];\n\trstride = PyArray_STRIDE(ret,axis);\n\n maxelsize = mps[0]->descr->elsize;\n\tneedcopy = (rstride != sizeof(intp));\n\tfor (j=0; jflags & ALIGNED) || \\\n\t\t\t(mps[j]->strides[axis] != (intp)mps[j]->descr->elsize);\n if (mps[j]->descr->elsize > maxelsize) \n maxelsize = mps[j]->descr->elsize;\n\t}\n\n\tif (needcopy) {\n\t\tchar *valbuffer, *indbuffer;\n\t\tvalbuffer = PyDataMem_NEW(N*(maxelsize+sizeof(intp)));\n\t\tindbuffer = valbuffer + (N*maxelsize);\n\t\twhile (size--) {\n\t\t\tiptr = (intp *)indbuffer;\n\t\t\tfor (i=0; idescr->elsize;\n\t\t\t\tastride = mps[j]->strides[axis];\t\n\t\t\t\targsort = mps[j]->descr->f->argsort[PyArray_MERGESORT];\n\t\t\t\t_strided_copy(valbuffer, (intp) elsize, its[j]->dataptr,\n\t\t\t\t\t astride, N, elsize);\n\t\t\t\tif (argsort(valbuffer, (intp *)indbuffer, N, mps[j]) < 0) {\n\t\t\t\t\tPyDataMem_FREE(valbuffer); goto fail;\n\t\t\t\t}\n\t\t\t\tPyArray_ITER_NEXT(its[j]);\n\t\t\t}\n\t\t\t_strided_copy(rit->dataptr, rstride, indbuffer,\n\t\t\t\t sizeof(intp), N, sizeof(intp));\n\t\t\tPyArray_ITER_NEXT(rit);\n\t\t}\n\t\tPyDataMem_FREE(valbuffer);\n\t}\n\telse {\n\t\twhile (size--) {\n\t\t\tiptr = (intp *)rit->dataptr;\n\t\t\tfor (i=0; idescr->f->argsort[PyArray_MERGESORT];\n\t\t\t\tif (argsort(its[j]->dataptr, (intp *)rit->dataptr,\n\t\t\t\t\t N, mps[j]) < 0) goto fail;\n\t\t\t\tPyArray_ITER_NEXT(its[j]);\n\t\t\t}\n\t\t\tPyArray_ITER_NEXT(rit);\n\t\t}\n\t}\n\n\tfor (i=0; idescr->f->compare;\n\tintp min_i, max_i, i, j;\n\tint location, elsize = ap1->descr->elsize;\n\tintp elements = ap1->dimensions[ap1->nd-1];\n\tintp n = PyArray_SIZE(ap2);\n\tintp *rp = (intp *)ret->data;\n\tchar *ip = ap2->data;\n\tchar *vp = ap1->data;\n\n\tfor (j=0; j 0) {\n\t\t\t\t\tif (compare(ip, vp+elsize*(--i), ap2) \\\n\t\t\t\t\t != 0) {\n\t\t\t\t\t\ti = i+1; break;\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t\tmin_i = i;\n\t\t\t\tbreak;\n\t\t\t}\n\t\t\telse if (location < 0) {\n\t\t\t\tmax_i = i;\n\t\t\t} else {\n\t\t\t\tmin_i = i+1;\n\t\t\t}\n\t\t}\n\t\t*rp = min_i;\n\t}\n}\n\n/*MULTIARRAY_API\n Numeric.searchsorted(a,v)\n*/\nstatic PyObject *\nPyArray_SearchSorted(PyArrayObject *op1, PyObject *op2) \n{\n\tPyArrayObject *ap1=NULL, *ap2=NULL, *ret=NULL;\n\tint typenum = 0;\n\n\t/* \n PyObject *args;\n args = Py_BuildValue(\"O\",op2);\n\tPy_DELEGATE_ARGS(((PyObject *)op1), searchsorted, args);\n Py_XDECREF(args);\n\t*/\n\n\ttypenum = PyArray_ObjectType((PyObject *)op1, 0);\n\ttypenum = PyArray_ObjectType(op2, typenum);\n\tret = NULL;\n\tap1 = (PyArrayObject *)PyArray_ContiguousFromAny((PyObject *)op1, \n\t\t\t\t\t\t\t typenum, \n\t\t\t\t\t\t\t 1, 1);\n\tif (ap1 == NULL) return NULL;\n\tap2 = (PyArrayObject *)PyArray_ContiguousFromAny(op2, typenum, \n\t\t\t\t\t\t\t 0, 0);\n\tif (ap2 == NULL) goto fail;\n\t\n\tret = (PyArrayObject *)PyArray_New(ap2->ob_type, ap2->nd, \n\t\t\t\t\t ap2->dimensions, PyArray_INTP,\n\t\t\t\t\t NULL, NULL, 0, 0, (PyObject *)ap2);\n\tif (ret == NULL) goto fail;\n\n\tif (ap2->descr->f->compare == NULL) {\n\t\tPyErr_SetString(PyExc_TypeError, \n\t\t\t\t\"compare not supported for type\");\n\t\tgoto fail;\n\t}\n\t\n\tlocal_where(ap1, ap2, ret); \n\t\n\tPy_DECREF(ap1);\n\tPy_DECREF(ap2);\n\treturn (PyObject *)ret;\n\t\n fail:\n\tPy_XDECREF(ap1);\n\tPy_XDECREF(ap2);\n\tPy_XDECREF(ret);\n\treturn NULL;\n}\n\n/*\n Make a new empty array, of the passed size, of a type that takes the\n priority of ap1 and ap2 into account.\n */\nstatic PyArrayObject *\nnew_array_for_sum(PyArrayObject *ap1, PyArrayObject *ap2,\n\t\t int nd, intp dimensions[], int typenum)\n{\n\tPyArrayObject *ret;\n\tPyTypeObject *subtype;\n\tdouble prior1, prior2;\n\t/* Need to choose an output array that can hold a sum \n\t -- use priority to determine which subtype.\n\t */\n\tif (ap2->ob_type != ap1->ob_type) {\n\t\tprior2 = PyArray_GetPriority((PyObject *)ap2, 0.0);\n\t\tprior1 = PyArray_GetPriority((PyObject *)ap1, 0.0);\n\n\t\tsubtype = (prior2 > prior1 ? ap2->ob_type : ap1->ob_type);\n\t} else {\n\t\tprior1 = prior2 = 0.0;\n\t\tsubtype = ap1->ob_type;\n\t}\n\n\tret = (PyArrayObject *)PyArray_New(subtype, nd, dimensions, \n\t\t\t\t\t typenum, NULL, NULL, 0, 0, \n (PyObject *)\n\t\t\t\t\t (prior2 > prior1 ? ap2 : ap1));\n\treturn ret;\n}\n\n/* Could perhaps be redone to not make contiguous arrays \n */\n\n/*MULTIARRAY_API\n Numeric.innerproduct(a,v)\n*/\nstatic PyObject *\nPyArray_InnerProduct(PyObject *op1, PyObject *op2) \n{\n\tPyArrayObject *ap1, *ap2, *ret=NULL;\n\tintp i, j, l, i1, i2, n1, n2;\n\tint typenum, nd;\n\tintp is1, is2, os;\n\tchar *ip1, *ip2, *op;\n\tintp dimensions[MAX_DIMS];\n\tPyArray_DotFunc *dot;\n\t\n\ttypenum = PyArray_ObjectType(op1, 0); \n\ttypenum = PyArray_ObjectType(op2, typenum);\n\t\t\n\tap1 = (PyArrayObject *)PyArray_ContiguousFromAny(op1, typenum, \n\t\t\t\t\t\t\t 0, 0);\n\tif (ap1 == NULL) return NULL;\n\tap2 = (PyArrayObject *)PyArray_ContiguousFromAny(op2, typenum, \n\t\t\t\t\t\t\t 0, 0);\n\tif (ap2 == NULL) goto fail;\n\t\n\tif (ap1->nd == 0 || ap2->nd == 0) {\n\t\tret = (ap1->nd == 0 ? ap1 : ap2);\n\t\tret = (PyArrayObject *)ret->ob_type->tp_as_number->\\\n\t\t\tnb_multiply((PyObject *)ap1, (PyObject *)ap2);\n\t\tPy_DECREF(ap1);\n\t\tPy_DECREF(ap2);\n\t\treturn (PyObject *)ret;\n\t}\n\t\n\tl = ap1->dimensions[ap1->nd-1];\n\t\n\tif (ap2->dimensions[ap2->nd-1] != l) {\n\t\tPyErr_SetString(PyExc_ValueError, \"matrices are not aligned\");\n\t\tgoto fail;\n\t}\n\t\n\tif (l == 0) n1 = n2 = 0;\n\telse {\n\t\tn1 = PyArray_SIZE(ap1)/l;\n\t\tn2 = PyArray_SIZE(ap2)/l;\n\t}\n\n\tnd = ap1->nd+ap2->nd-2;\n\tj = 0;\n\tfor(i=0; ind-1; i++) {\n\t\tdimensions[j++] = ap1->dimensions[i];\n\t}\n\tfor(i=0; ind-1; i++) {\n\t\tdimensions[j++] = ap2->dimensions[i];\n\t}\n\n\n\t/* Need to choose an output array that can hold a sum \n\t -- use priority to determine which subtype.\n\t */\n\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\n\t\n\tis1 = ap1->strides[ap1->nd-1]; \n\tis2 = ap2->strides[ap2->nd-1];\n\top = ret->data; os = ret->descr->elsize;\n\t\n\tip1 = ap1->data;\n\tfor(i1=0; i1data;\n\t\tfor(i2=0; i2nd == 0 || ap2->nd == 0) {\n\t\tret = (ap1->nd == 0 ? ap1 : ap2);\n\t\tret = (PyArrayObject *)ret->ob_type->tp_as_number->\\\n\t\t\tnb_multiply((PyObject *)ap1, (PyObject *)ap2);\n\t\tPy_DECREF(ap1);\n\t\tPy_DECREF(ap2);\n\t\treturn (PyObject *)ret;\n\t}\n\t\n\tl = ap1->dimensions[ap1->nd-1];\n\tif (ap2->nd > 1) {\n\t\tmatchDim = ap2->nd - 2;\n\t\totherDim = ap2->nd - 1;\n\t}\n\telse {\n\t\tmatchDim = 0;\n\t\totherDim = 0;\n\t}\n\n\tif (ap2->dimensions[matchDim] != l) {\n\t\tPyErr_SetString(PyExc_ValueError, \"objects are not aligned\");\n\t\tgoto fail;\n\t}\n\t\n\tif (l == 0) n1 = n2 = 0;\n\telse {\n\t\tn1 = PyArray_SIZE(ap1)/l;\n\t\tn2 = PyArray_SIZE(ap2)/l;\n\t}\n\n\tnd = ap1->nd+ap2->nd-2;\n\tj = 0;\n\tfor(i=0; ind-1; i++) {\n\t\tdimensions[j++] = ap1->dimensions[i];\n\t}\n\tfor(i=0; ind-2; i++) {\n\t\tdimensions[j++] = ap2->dimensions[i];\n\t}\n\tif(ap2->nd > 1) {\n\t\tdimensions[j++] = ap2->dimensions[ap2->nd-1];\n\t}\n\t/*\n\tfprintf(stderr, \"nd=%d dimensions=\", nd);\n\t for(i=0; i 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\tis1 = ap1->strides[ap1->nd-1]; is2 = ap2->strides[matchDim];\n\tif(ap1->nd > 1)\n\t\tis1r = ap1->strides[ap1->nd-2];\n\telse\n\t\tis1r = ap1->strides[ap1->nd-1];\n\tis2r = ap2->strides[otherDim];\n\n\top = ret->data; os = ret->descr->elsize;\n\n\tip1 = ap1->data;\n\tfor(i1=0; i1data;\n\t\tfor(i2=0; i2ob_type, \n\t\t\t\t PyArray_DESCR(arr),\n\t\t\t\t 2, dims, \n\t\t\t\t NULL, NULL, 0, arr);\n\n\tif (ret == NULL) {\n\t\tPy_DECREF(arr);\n\t\treturn NULL;\n\t}\n\t/* do 2-d loop */\n\toptr = PyArray_DATA(ret);\n\tstr2 = elsize*dims[0];\n\tfor (i=0; idimensions[0];\n\tn2 = ap2->dimensions[0];\n\n\tif (n1 < n2) { \n\t\tret = ap1; ap1 = ap2; ap2 = ret; \n\t\tret = NULL; i = n1;n1=n2;n2=i;\n\t}\n\tlength = n1;\n\tn = n2;\n\tswitch(mode) {\n\tcase 0:\t\n\t\tlength = length-n+1;\n\t\tn_left = n_right = 0;\n\t\tbreak;\n\tcase 1:\n\t\tn_left = (intp)(n/2);\n\t\tn_right = n-n_left-1;\n\t\tbreak;\n\tcase 2:\n\t\tn_right = n-1;\n\t\tn_left = n-1;\n\t\tlength = length+n-1;\n\t\tbreak;\n\tdefault:\n\t\tPyErr_SetString(PyExc_ValueError, \n\t\t\t\t\"mode must be 0, 1, or 2\");\n\t\tgoto fail;\n\t}\n\n\t/* Need to choose an output array that can hold a sum \n\t -- use priority to determine which subtype.\n\t */\n\tret = new_array_for_sum(ap1, ap2, 1, &length, typenum);\n\tif (ret == NULL) goto fail;\n\t\n\tdot = ret->descr->f->dotfunc;\n\tif (dot == NULL) {\n\t\tPyErr_SetString(PyExc_ValueError, \n\t\t\t\t\"function not available for this data type\");\n\t\tgoto fail;\n\t}\n\t\n\tis1 = ap1->strides[0]; is2 = ap2->strides[0];\n\top = ret->data; os = ret->descr->elsize;\n\t\n\tip1 = ap1->data; ip2 = ap2->data+n_left*is2;\n\tn = n-n_left;\n\tfor(i=0; idescr->type_num);\n\tPy_DECREF(arr);\n\treturn ret;\t \n}\n\n/*MULTIARRAY_API\n Min\n*/\nstatic PyObject *\nPyArray_Min(PyArrayObject *ap, int axis)\n{\n\tPyArrayObject *arr;\n\tPyObject *ret;\n\n\tif ((arr=(PyArrayObject *)_check_axis(ap, &axis, 0))==NULL)\n\t\treturn NULL;\n\tret = PyArray_GenericReduceFunction(arr, n_ops.minimum, axis,\n\t\t\t\t\t arr->descr->type_num);\n\tPy_DECREF(arr);\n\treturn ret;\t \n}\n\n/*MULTIARRAY_API\n Ptp\n*/\nstatic PyObject *\nPyArray_Ptp(PyArrayObject *ap, int axis)\n{\n\tPyArrayObject *arr;\n\tPyObject *ret;\n\tPyObject *obj1=NULL, *obj2=NULL;\n\n\tif ((arr=(PyArrayObject *)_check_axis(ap, &axis, 0))==NULL)\n\t\treturn NULL;\n\tobj1 = PyArray_Max(arr, axis);\n\tif (obj1 == NULL) goto fail;\n\tobj2 = PyArray_Min(arr, axis);\n\tif (obj2 == NULL) goto fail;\n\tPy_DECREF(arr);\n\tret = PyNumber_Subtract(obj1, obj2);\n\tPy_DECREF(obj1);\n\tPy_DECREF(obj2);\n\treturn ret;\n\n fail:\n\tPy_XDECREF(arr);\n\tPy_XDECREF(obj1);\n\tPy_XDECREF(obj2);\n\treturn NULL;\n}\n\n\n/*MULTIARRAY_API\n ArgMax\n*/\nstatic PyObject *\nPyArray_ArgMax(PyArrayObject *op, int axis) \n{\n\tPyArrayObject *ap=NULL, *rp=NULL;\n\tPyArray_ArgFunc* arg_func;\n\tchar *ip;\n\tintp *rptr;\n\tintp i, n, orign, m;\n\tint elsize;\n\t\n\tif ((ap=(PyAO *)_check_axis(op, &axis, 0))==NULL) return NULL;\n\n\tSWAPAXES(op, ap);\n\n\tap = (PyArrayObject *)\\\n\t\tPyArray_ContiguousFromAny((PyObject *)op, \n\t\t\t\t\t PyArray_NOTYPE, 1, 0);\n\n\tPy_DECREF(op);\n\tif (ap == NULL) return NULL;\n\t\n\targ_func = ap->descr->f->argmax;\n\tif (arg_func == NULL) {\n\t\tPyErr_SetString(PyExc_TypeError, \"data type not ordered\");\n\t\tgoto fail;\n\t}\n\n\trp = (PyArrayObject *)PyArray_New(ap->ob_type, ap->nd-1,\n\t\t\t\t\t ap->dimensions, PyArray_INTP,\n\t\t\t\t\t NULL, NULL, 0, 0, \n (PyObject *)ap);\n\tif (rp == NULL) goto fail;\n\n\n\telsize = ap->descr->elsize;\n\tm = ap->dimensions[ap->nd-1];\n\tif (m == 0) {\n\t\tPyErr_SetString(MultiArrayError, \n\t\t\t\t\"attempt to get argmax/argmin \"\\\n\t\t\t\t\"of an empty sequence??\");\n\t\tgoto fail;\n\t}\n\tn = PyArray_SIZE(ap)/m;\n\trptr = (intp *)rp->data;\n\tfor (ip = ap->data, i=0; ind + indices->nd - 1;\n for (i=0; i< nd; i++) {\n if (i < axis) {\n shape[i] = self->dimensions[i];\n n *= shape[i];\n } else {\n if (i < axis+indices->nd) {\n shape[i] = indices->dimensions[i-axis];\n m *= shape[i];\n } else {\n shape[i] = self->dimensions[i-indices->nd+1];\n chunk *= shape[i];\n }\n }\n }\n\tPy_INCREF(self->descr);\n ret = (PyArrayObject *)PyArray_NewFromDescr(self->ob_type, \n\t\t\t\t\t\t self->descr,\n\t\t\t\t\t\t nd, shape, \n\t\t\t\t\t\t NULL, NULL, 0, \n\t\t\t\t\t\t (PyObject *)self);\n\t\n if (ret == NULL) goto fail;\n\t\n max_item = self->dimensions[axis];\n chunk = chunk * ret->descr->elsize;\n src = self->data;\n dest = ret->data;\n\t\n for(i=0; idata))[j];\n if (tmp < 0) tmp = tmp+max_item;\n if ((tmp < 0) || (tmp >= max_item)) {\n PyErr_SetString(PyExc_IndexError, \n\t\t\t\t\t\t\"index out of range for \"\\\n\t\t\t\t\t\t\"array\");\n goto fail;\n }\n memmove(dest, src+tmp*chunk, chunk);\n dest += chunk;\n }\n src += chunk*max_item;\n }\n\t\n PyArray_INCREF(ret);\n\n Py_XDECREF(indices);\n Py_XDECREF(self);\n\n return (PyObject *)ret;\n\t\n\t\n fail:\n Py_XDECREF(ret);\n Py_XDECREF(indices);\n Py_XDECREF(self);\n return NULL;\n}\n\n/*MULTIARRAY_API\n Put values into an array\n*/\nstatic PyObject *\nPyArray_Put(PyArrayObject *self, PyObject* values0, PyObject *indices0) \n{\n PyArrayObject *indices, *values;\n int i, chunk, ni, max_item, nv, tmp, thistype; \n char *src, *dest;\n\n indices = NULL;\n values = NULL;\n\n if (!PyArray_Check(self)) {\n PyErr_SetString(PyExc_TypeError, \"put: first argument must be an array\");\n return NULL;\n }\n if (!PyArray_ISCONTIGUOUS(self)) {\n PyErr_SetString(PyExc_ValueError, \"put: first argument must be contiguous\");\n return NULL;\n }\n max_item = PyArray_SIZE(self);\n dest = self->data;\n chunk = self->descr->elsize;\n\n indices = (PyArrayObject *)PyArray_ContiguousFromAny(indices0, PyArray_INTP, 0, 0);\n if (indices == NULL) goto fail;\n ni = PyArray_SIZE(indices);\n\n\tthistype = self->descr->type_num;\n values = (PyArrayObject *)\\\n\t\tPyArray_ContiguousFromAny(values0, thistype, 0, 0);\n if (values == NULL) goto fail;\n nv = PyArray_SIZE(values);\n if (nv > 0) { /* nv == 0 for a null array */\n if (thistype == PyArray_OBJECT) { \n for(i=0; idata + chunk * (i % nv);\n tmp = ((intp *)(indices->data))[i];\n if (tmp < 0) tmp = tmp+max_item;\n if ((tmp < 0) || (tmp >= max_item)) {\n PyErr_SetString(PyExc_IndexError, \"index out of range for array\");\n goto fail;\n }\n Py_INCREF(*((PyObject **)src));\n Py_XDECREF(*((PyObject **)(dest+tmp*chunk)));\n memmove(dest + tmp * chunk, src, chunk);\n }\n }\n else {\n for(i=0; idata + chunk * (i % nv);\n tmp = ((intp *)(indices->data))[i];\n if (tmp < 0) tmp = tmp+max_item;\n if ((tmp < 0) || (tmp >= max_item)) {\n PyErr_SetString(PyExc_IndexError, \"index out of range for array\");\n goto fail;\n }\n memmove(dest + tmp * chunk, src, chunk);\n }\n }\n\n }\n\n Py_XDECREF(values);\n Py_XDECREF(indices);\n Py_INCREF(Py_None);\n return Py_None;\n\t\n fail:\n Py_XDECREF(indices);\n Py_XDECREF(values);\n return NULL;\n}\n\n/*MULTIARRAY_API\n Put values into an array according to a mask.\n*/\nstatic PyObject *\nPyArray_PutMask(PyArrayObject *self, PyObject* values0, PyObject* mask0) \n{\n PyArrayObject *mask, *values;\n int i, chunk, ni, max_item, nv, tmp, thistype;\n char *src, *dest;\n\n mask = NULL;\n values = NULL;\n\n if (!PyArray_Check(self)) {\n PyErr_SetString(PyExc_TypeError, \n\t\t\t\t\"putmask: first argument must \"\\\n\t\t\t\t\"be an array\");\n return NULL;\n }\n if (!PyArray_ISCONTIGUOUS(self)) {\n PyErr_SetString(PyExc_ValueError, \n\t\t\t\t\"putmask: first argument must be contiguous\");\n return NULL;\n }\n\n max_item = PyArray_SIZE(self);\n dest = self->data;\n chunk = self->descr->elsize;\n\n mask = (PyArrayObject *)\\\n\t\tPyArray_FROM_OTF(mask0, PyArray_BOOL, CARRAY_FLAGS | FORCECAST);\n\tif (mask == NULL) goto fail;\n ni = PyArray_SIZE(mask);\n if (ni != max_item) {\n PyErr_SetString(PyExc_ValueError, \n\t\t\t\t\"putmask: mask and data must be \"\\\n\t\t\t\t\"the same size\");\n goto fail;\n }\n\n\tthistype = self->descr->type_num;\n values = (PyArrayObject *)\\\n\t\tPyArray_ContiguousFromAny(values0, thistype, 0, 0);\n\tif (values == NULL) goto fail;\n nv = PyArray_SIZE(values);\t /* zero if null array */\n if (nv > 0) {\n if (thistype == PyArray_OBJECT) {\n for(i=0; idata + chunk * (i % nv);\n tmp = ((Bool *)(mask->data))[i];\n if (tmp) {\n\t\t\t\t\tPy_INCREF(*((PyObject **)src));\n Py_XDECREF(*((PyObject **)(dest+i*chunk)));\n memmove(dest + i * chunk, src, chunk);\n }\n\t\t\t}\n }\n else {\n for(i=0; idata + chunk * (i % nv);\n tmp = ((Bool *)(mask->data))[i];\n if (tmp) memmove(dest + i * chunk, src, chunk);\n\t\t\t}\n\t\t}\n }\n\n Py_XDECREF(values);\n Py_XDECREF(mask);\n Py_INCREF(Py_None);\n return Py_None;\n\t\n fail:\n Py_XDECREF(mask);\n Py_XDECREF(values);\n return NULL;\n}\n\n\n/* This conversion function can be used with the \"O&\" argument for\n PyArg_ParseTuple. It will immediately return an object of array type\n or will convert to a CARRAY any other object. \n\n If you use PyArray_Converter, you must DECREF the array when finished\n as you get a new reference to it.\n*/\n \n/*MULTIARRAY_API\n Useful to pass as converter function for O& processing in\n PyArgs_ParseTuple.\n*/\nstatic int \nPyArray_Converter(PyObject *object, PyObject **address) \n{\n if (PyArray_Check(object)) {\n *address = object;\n\t\tPy_INCREF(object);\n return PY_SUCCEED;\n }\n else {\n\t\t*address = PyArray_FromAny(object, NULL, 0, 0, CARRAY_FLAGS, NULL);\n\t\tif (*address == NULL) return PY_FAIL;\n\t\treturn PY_SUCCEED;\n }\n}\n\n/*MULTIARRAY_API\n Convert an object to true / false\n*/\nstatic int\nPyArray_BoolConverter(PyObject *object, Bool *val)\n{ \n if (PyObject_IsTrue(object))\n *val=TRUE;\n else *val=FALSE;\n if (PyErr_Occurred())\n return PY_FAIL;\n return PY_SUCCEED;\n}\n\n\n/*MULTIARRAY_API\n Typestr converter\n*/\nstatic int\nPyArray_TypestrConvert(int itemsize, int gentype)\n{\n\tregister int newtype = gentype;\n\t\n\tif (gentype == PyArray_GENBOOLLTR) {\n\t\tif (itemsize == 1)\n\t\t\tnewtype = PyArray_BOOL;\n\t\telse \n\t\t\tnewtype = PyArray_NOTYPE;\n\t}\n\telse if (gentype == PyArray_SIGNEDLTR) {\n\t\tswitch(itemsize) {\n\t\tcase 1:\n\t\t\tnewtype = PyArray_INT8;\n\t\t\tbreak;\n\t\tcase 2:\n\t\t\tnewtype = PyArray_INT16;\n\t\t\tbreak;\n\t\tcase 4:\n\t\t\tnewtype = PyArray_INT32;\n\t\t\tbreak;\n\t\tcase 8:\n\t\t\tnewtype = PyArray_INT64;\n\t\t\tbreak;\n#ifdef PyArray_INT128\n\t\tcase 16:\n\t\t\tnewtype = PyArray_INT128;\n\t\t\tbreak;\n#endif\n\t\tdefault:\n\t\t\tnewtype = PyArray_NOTYPE;\n\t\t}\n\t}\n\n\telse if (gentype == PyArray_UNSIGNEDLTR) {\n\t\tswitch(itemsize) {\n\t\tcase 1:\n\t\t\tnewtype = PyArray_UINT8;\n\t\t\tbreak;\n\t\tcase 2:\n\t\t\tnewtype = PyArray_UINT16;\n\t\t\tbreak;\n\t\tcase 4:\n\t\t\tnewtype = PyArray_UINT32;\n\t\t\tbreak;\n\t\tcase 8:\n\t\t\tnewtype = PyArray_UINT64;\n\t\t\tbreak;\n#ifdef PyArray_INT128\n\t\tcase 16:\n\t\t\tnewtype = PyArray_UINT128;\n\t\t\tbreak;\n#endif\n\t\tdefault:\n\t\t\tnewtype = PyArray_NOTYPE;\n\t\t\tbreak;\n\t\t}\n\t}\n\telse if (gentype == PyArray_FLOATINGLTR) {\n\t\tswitch(itemsize) {\n\t\tcase 4:\n\t\t\tnewtype = PyArray_FLOAT32;\n\t\t\tbreak;\n\t\tcase 8:\n\t\t\tnewtype = PyArray_FLOAT64;\n\t\t\tbreak;\n#ifdef PyArray_FLOAT80\n case 10:\n\t\t\tnewtype = PyArray_FLOAT80;\n\t\t\tbreak;\n#endif\n#ifdef PyArray_FLOAT96\n\t\tcase 12:\n\t\t\tnewtype = PyArray_FLOAT96;\n\t\t\tbreak;\n#endif\t\t \n#ifdef PyArray_FLOAT128\n\t\tcase 16:\n\t\t\tnewtype = PyArray_FLOAT128;\n\t\t\tbreak;\n#endif\n\t\tdefault:\n\t\t\tnewtype = PyArray_NOTYPE;\n\t\t}\t\t\n\t}\n\t\n\telse if (gentype == PyArray_COMPLEXLTR) {\n\t\tswitch(itemsize) {\n\t\tcase 8:\n\t\t\tnewtype = PyArray_COMPLEX64;\n\t\t\tbreak;\n\t\tcase 16:\n\t\t\tnewtype = PyArray_COMPLEX128;\n\t\t\tbreak;\n#ifdef PyArray_FLOAT80\n case 20:\n\t\t\tnewtype = PyArray_COMPLEX160;\n\t\t\tbreak;\n#endif\n#ifdef PyArray_FLOAT96\n\t\tcase 24:\n\t\t\tnewtype = PyArray_COMPLEX192;\t\t\t\n\t\t\tbreak;\n#endif\t\t \n#ifdef PyArray_FLOAT128\n\t\tcase 32:\n\t\t\tnewtype = PyArray_COMPLEX256;\n\t\t\tbreak;\n#endif\n\t\tdefault:\n\t\t\tnewtype = PyArray_NOTYPE;\n\t\t}\t\t\n\t}\n\n\treturn newtype;\n}\n\n\n/* this function takes a Python object which exposes the (single-segment)\n buffer interface and returns a pointer to the data segment\n \n You should increment the reference count by one of buf->base\n if you will hang on to a reference\n\n You only get a borrowed reference to the object. Do not free the\n memory...\n*/\n\n\n/*MULTIARRAY_API\n Get buffer chunk from object\n*/\nstatic int\nPyArray_BufferConverter(PyObject *obj, PyArray_Chunk *buf)\n{\n int buflen;\n\n buf->ptr = NULL;\n buf->flags = BEHAVED_FLAGS;\n buf->base = NULL;\n\n\tif (obj == Py_None)\n\t\treturn PY_SUCCEED;\n\n if (PyObject_AsWriteBuffer(obj, &(buf->ptr), &buflen) < 0) {\n PyErr_Clear();\n buf->flags &= ~WRITEABLE;\n if (PyObject_AsReadBuffer(obj, (const void **)&(buf->ptr), \n &buflen) < 0)\n return PY_FAIL;\n }\n buf->len = (intp) buflen;\n \n /* Point to the base of the buffer object if present */\n if (PyBuffer_Check(obj)) buf->base = ((PyArray_Chunk *)obj)->base;\n if (buf->base == NULL) buf->base = obj;\n \n return PY_SUCCEED; \n}\n\n\n\n/* This function takes a Python sequence object and allocates and\n fills in an intp array with the converted values.\n\n **Remember to free the pointer seq.ptr when done using\n PyDimMem_FREE(seq.ptr)**\n*/\n\n/*MULTIARRAY_API\n Get intp chunk from sequence\n*/\nstatic int\nPyArray_IntpConverter(PyObject *obj, PyArray_Dims *seq)\n{\n int len;\n int nd;\n\n seq->ptr = NULL;\n if (obj == Py_None) return PY_SUCCEED;\n len = PySequence_Size(obj);\n if (len == -1) { /* Check to see if it is a number */\n if (PyNumber_Check(obj)) len = 1;\n }\n if (len < 0) {\n PyErr_SetString(PyExc_TypeError, \n \"expected sequence object with len >= 0\");\n return PY_FAIL;\n }\n if (len > MAX_DIMS) {\n PyErr_Format(PyExc_ValueError, \"sequence too large; \" \\\n \"must be smaller than %d\", MAX_DIMS);\n return PY_FAIL;\n }\n\tif (len > 0) {\n\t\tseq->ptr = PyDimMem_NEW(len);\n\t\tif (seq->ptr == NULL) {\n\t\t\tPyErr_NoMemory();\n\t\t\treturn PY_FAIL;\n\t\t}\n\t}\n seq->len = len;\n nd = PyArray_IntpFromSequence(obj, (intp *)seq->ptr, len);\n if (nd == -1 || nd != len) {\n\t\tPyDimMem_FREE(seq->ptr);\n\t\tseq->ptr=NULL;\n\t\treturn PY_FAIL;\n\t}\n return PY_SUCCEED;\n}\n\n\n/* A tuple type would be either (generic typeobject, typesize) \n or (fixed-length data-type, shape) \n\n or (inheriting data-type, new-data-type)\n The new data-type must have the same itemsize as the inheriting data-type\n unless the latter is 0 \n \n Thus (int32, {'real':(int16,0),'imag',(int16,2)})\n\n is one way to specify a descriptor that will give \n a['real'] and a['imag'] to an int32 array.\n*/\n\n/* leave type reference alone */\nstatic PyArray_Descr *\n_use_inherit(PyArray_Descr *type, PyObject *newobj, int *errflag) \n{\n\tPyArray_Descr *new;\n\tPyArray_Descr *conv;\n\t\n\t*errflag = 0;\n\tif (!PyArray_DescrConverter(newobj, &conv)) {\n\t\treturn NULL;\n\t}\n\t*errflag = 1;\n\tif (type == &OBJECT_Descr) {\n\t\tPyErr_SetString(PyExc_ValueError,\n\t\t\t\t\"cannot base a new descriptor on an\"\\\n\t\t\t\t\" OBJECT descriptor.\");\n\t\treturn NULL;\n\t}\n\tnew = PyArray_DescrNew(type);\n\tif (new == NULL) return NULL;\n\n\tif (new->elsize && new->elsize != conv->elsize) {\n\t\tPyErr_SetString(PyExc_ValueError, \n\t\t\t\t\"mismatch in size of old\"\\\n\t\t\t\t\"and new data-descriptor\");\n\t\treturn NULL;\n\t}\n\tnew->elsize = conv->elsize;\n\tif (conv->fields != Py_None) {\n\t\tnew->fields = conv->fields;\n\t\tPy_XINCREF(new->fields);\n\t}\n\tPy_DECREF(conv);\n\t*errflag = 0;\n\treturn new;\n}\n\nstatic PyArray_Descr *\n_convert_from_tuple(PyObject *obj) \n{\n\tPyArray_Descr *type, *res;\n\tPyObject *val;\n\tint errflag;\n\t\n\tif (PyTuple_GET_SIZE(obj) != 2) return NULL;\n\n\tif (!PyArray_DescrConverter(PyTuple_GET_ITEM(obj,0), &type)) \n\t\treturn NULL;\n\tval = PyTuple_GET_ITEM(obj,1);\n\t/* try to interpret next item as a type */\n\tres = _use_inherit(type, val, &errflag);\n\tif (res || errflag) {\n\t\tPy_DECREF(type);\n\t\tif (res) return res;\n\t\telse return NULL;\n\t}\n\tPyErr_Clear();\n\t/* We get here if res was NULL but errflag wasn't set\n\t --- i.e. the conversion to a data-descr failed in _use_inherit\n\t*/\n\n\tif (type->elsize == 0) { /* interpret next item as a typesize */\n\t\tint itemsize;\n\t\titemsize = PyArray_PyIntAsInt(PyTuple_GET_ITEM(obj,1));\n\t\tif (error_converting(itemsize)) {\n\t\t\tPyErr_SetString(PyExc_ValueError, \n\t\t\t\t\t\"invalid itemsize in generic type \"\\\n\t\t\t\t\t\"tuple\");\n\t\t\tgoto fail;\n\t\t}\n\t\tPyArray_DESCR_REPLACE(type);\n\t\ttype->elsize = itemsize;\n\t}\n\telse {\n\t\t/* interpret next item as shape (if it's a tuple)\n\t\t and reset the type to PyArray_VOID with \n\t\t anew fields attribute. \n\t */\n\t\tPyArray_Dims shape={NULL,-1};\n\t\tPyArray_Descr *newdescr;\n\t\tif (!(PyArray_IntpConverter(val, &shape)) || \n\t\t (shape.len > MAX_DIMS)) {\n\t\t\tPyDimMem_FREE(shape.ptr);\n\t\t\tPyErr_SetString(PyExc_ValueError, \n\t\t\t\t\t\"invalid shape in fixed-type tuple.\");\n\t\t\tgoto fail;\n\t\t}\n\t\t/* If (type, 1) was given, it is equivalent to type... */\n\t\tif (shape.len == 1 && shape.ptr[0] == 1 && PyNumber_Check(val)) {\n\t\t\tPyDimMem_FREE(shape.ptr);\n\t\t\treturn type;\n\t\t}\n\t\tnewdescr = PyArray_DescrNewFromType(PyArray_VOID);\n\t\tif (newdescr == NULL) {PyDimMem_FREE(shape.ptr); goto fail;}\n\t\tnewdescr->elsize = type->elsize;\n\t\tnewdescr->elsize *= PyArray_MultiplyList(shape.ptr, \n\t\t\t\t\t\t\t shape.len);\n\t\tPyDimMem_FREE(shape.ptr);\n\t\tnewdescr->subarray = _pya_malloc(sizeof(PyArray_ArrayDescr));\n\t\tnewdescr->subarray->base = type;\n\t\tif (type->hasobject) newdescr->hasobject = 1;\n\t\tPy_INCREF(val);\n\t\tnewdescr->subarray->shape = val;\n\t\tPy_XDECREF(newdescr->fields);\n\t\tnewdescr->fields = NULL;\n\t\ttype = newdescr;\n\t}\n\treturn type;\n\n fail:\n\tPy_XDECREF(type);\n\treturn NULL;\n}\n\n/* obj is a list. Each item is a tuple with\n\n(field-name, data-type (either a list or a string), and an optional \n shape parameter).\n*/\nstatic PyArray_Descr *\n_convert_from_array_descr(PyObject *obj)\n{\n\tint n, i, totalsize;\n\tint ret;\n\tPyObject *fields, *item, *newobj;\n\tPyObject *name, *key, *tup;\n\tPyObject *nameslist;\n\tPyArray_Descr *new;\n\tPyArray_Descr *conv;\n int hasobject=0;\n\t\n\tn = PyList_GET_SIZE(obj);\t\n\tnameslist = PyList_New(n);\n\tif (!nameslist) return NULL;\n\ttotalsize = 0;\n\tfields = PyDict_New();\n\tfor (i=0; ihasobject)\n hasobject = 1;\n\t\ttup = PyTuple_New(2);\n\t\tPyTuple_SET_ITEM(tup, 0, (PyObject *)conv);\n\t\tPyTuple_SET_ITEM(tup, 1, PyInt_FromLong((long) totalsize));\n\t\ttotalsize += conv->elsize;\n\t\tPyDict_SetItem(fields, name, tup);\n\t\tPy_DECREF(tup);\n\t}\n\tkey = PyInt_FromLong(-1);\n\tPyDict_SetItem(fields, key, nameslist);\n\tPy_DECREF(key);\n\tPy_DECREF(nameslist);\n\tnew = PyArray_DescrNewFromType(PyArray_VOID);\n\tnew->fields = fields;\n\tnew->elsize = totalsize;\n new->hasobject=hasobject;\n\treturn new;\n \n fail:\n\tPy_DECREF(fields);\n\tPy_DECREF(nameslist);\n\treturn NULL;\n\n}\n\n/* a list specifying a data-type can just be\n a list of formats. The names for the fields\n will default to f1, f2, f3, and so forth.\n\n or it can be an array_descr format string -- in which case\n align must be 0. \n*/\n\nstatic PyArray_Descr *\n_convert_from_list(PyObject *obj, int align, int try_descr)\n{\n\tint n, i;\n\tint totalsize;\n\tPyObject *fields;\n\tPyArray_Descr *conv=NULL;\n\tPyArray_Descr *new;\n\tPyObject *key, *tup;\n\tPyObject *nameslist=NULL;\n \tint ret;\n\tint maxalign=0;\n int hasobject=0;\n\t\n\tn = PyList_GET_SIZE(obj);\n\ttotalsize = 0;\n\tif (n==0) return NULL;\n\tnameslist = PyList_New(n);\n\tif (!nameslist) return NULL;\n\tfields = PyDict_New();\n\tfor (i=0; ihasobject)\n\t\t\thasobject=1;\t\t\t\n\t\tPyTuple_SET_ITEM(tup, 0, (PyObject *)conv);\n\t\tif (align) {\n\t\t\tint _align;\n\t\t\t_align = conv->alignment;\n\t\t\tif (_align > 1) totalsize =\t\t\t\\\n\t\t\t\t((totalsize + _align - 1)/_align)*_align;\n\t\t\tmaxalign = MAX(maxalign, _align);\n\t\t}\n\t\tPyTuple_SET_ITEM(tup, 1, PyInt_FromLong((long) totalsize));\n\t\tPyDict_SetItem(fields, key, tup);\n\t\tPy_DECREF(tup);\n\t\tPyList_SET_ITEM(nameslist, i, key);\n\t\ttotalsize += conv->elsize;\n\t}\n\tkey = PyInt_FromLong(-1);\n\tPyDict_SetItem(fields, key, nameslist);\n\tPy_DECREF(key);\n\tPy_DECREF(nameslist);\n\tnew = PyArray_DescrNewFromType(PyArray_VOID);\n\tnew->fields = fields;\n new->hasobject=hasobject;\n\tif (maxalign > 1) {\n\t\ttotalsize = ((totalsize+maxalign-1)/maxalign)*maxalign;\n\t}\n\tif (align) new->alignment = maxalign;\n\tnew->elsize = totalsize;\n\treturn new;\n\n fail:\n\tPy_DECREF(nameslist);\n\tPy_DECREF(fields);\n\tif (!try_descr) return NULL;\n\tif (align) {\n\t\tPyErr_SetString(PyExc_ValueError, \n\t\t\t\t\"failed to convert from list of formats \"\\\n\t\t\t\t\"and align cannot be 1 for conversion from \"\\\n\t\t\t\t\"array_descr structure\");\n\t\treturn NULL;\n\t}\n\tPyErr_Clear();\n\treturn _convert_from_array_descr(obj);\n}\n\n\n/* comma-separated string */\n/* this is the format developed by the numarray records module */\n/* and implemented by the format parser in that module */\n/* this is an alternative implementation found in the _internal.py \n file patterned after that one -- the approach is to try to convert \n to a list (with tuples if any repeat information is present) \n and then call the _convert_from_list)\n*/\n\nstatic PyArray_Descr *\n_convert_from_commastring(PyObject *obj, int align)\n{\n\tPyObject *listobj;\n\tPyArray_Descr *res;\n\n\tif (!PyString_Check(obj)) return NULL;\n listobj = PyObject_CallMethod(_numpy_internal, \"_commastring\",\n\t\t\t\t \"O\", obj);\n\tif (!listobj) return NULL;\n\tres = _convert_from_list(listobj, align, 0);\n\tPy_DECREF(listobj);\n\tif (!res && !PyErr_Occurred()) {\n\t\tPyErr_SetString(PyExc_ValueError, \"invalid data-type\");\n\t\treturn NULL;\n\t}\n\treturn res;\n}\n\n\n\n/* a dictionary specifying a data-type\n must have at least two and up to four\n keys These must all be sequences of the same length.\n\n \"names\" --- field names \n \"formats\" --- the data-type descriptors for the field.\n \n Optional:\n\n \"offsets\" --- integers indicating the offset into the \n record of the start of the field.\n\t\t if not given, then \"consecutive offsets\" \n\t\t will be assumed and placed in the dictionary.\n \n \"titles\" --- Allows the use of an additional key\n for the fields dictionary.\n \nAttribute-lookup-based field names merely has to query the fields \ndictionary of the data-descriptor. Any result present can be used\nto return the correct field.\n\nSo, the notion of what is a name and what is a title is really quite\narbitrary. \n\nWhat does distinguish a title, however, is that if it is not None, \nit will be placed at the end of the tuple inserted into the \nfields dictionary.\n\nIf the dictionary does not have \"names\" and \"formats\" entries,\nthen it will be checked for conformity and used directly. \n*/\n\nstatic PyArray_Descr *\n_use_fields_dict(PyObject *obj, int align)\n{\n return (PyArray_Descr *)PyObject_CallMethod(_numpy_internal, \n\t\t\t\t\t\t \"_usefields\", \n\t\t\t\t\t\t \"Oi\", obj, align);\n}\n\nstatic PyArray_Descr *\n_convert_from_dict(PyObject *obj, int align)\n{\n\tPyArray_Descr *new;\n\tPyObject *fields=NULL;\n\tPyObject *names, *offsets, *descrs, *titles, *key;\n\tint n, i;\n\tint totalsize;\n\tint maxalign=0;\n int hasobject=0;\n\t\n\tfields = PyDict_New();\n\tif (fields == NULL) return (PyArray_Descr *)PyErr_NoMemory();\n\t\n\tnames = PyDict_GetItemString(obj, \"names\");\n\tdescrs = PyDict_GetItemString(obj, \"formats\");\n\n\tif (!names || !descrs) {\n\t\tPy_DECREF(fields);\n\t\treturn _use_fields_dict(obj, align);\n\t}\n\tn = PyObject_Length(names);\n\toffsets = PyDict_GetItemString(obj, \"offsets\");\n\ttitles = PyDict_GetItemString(obj, \"titles\");\n\tif ((n > PyObject_Length(descrs)) ||\t\t\t\\\n\t (offsets && (n > PyObject_Length(offsets))) ||\t\\\n\t (titles && (n > PyObject_Length(titles)))) {\n\t\tPyErr_SetString(PyExc_ValueError,\n\t\t\t\t\"all items in the dictionary must have\" \\\n\t\t\t\t\" the same length.\");\n\t\tgoto fail;\n\t}\n\n\ttotalsize = 0;\n\tfor(i=0; i totalsize) totalsize = offset;\n\t\t}\n\t\telse {\n\t\t\tif (align) {\n\t\t\t\tint _align = newdescr->alignment;\n\t\t\t\tif (_align > 1) totalsize =\t\t\\\n\t\t\t\t\t((totalsize + _align - 1)/_align)*_align;\n\t\t\t\tmaxalign = MAX(maxalign,_align);\n\t\t\t}\n\t\t\tPyTuple_SET_ITEM(tup, 1, PyInt_FromLong(totalsize));\n\t\t}\n\t\tif (len == 3) PyTuple_SET_ITEM(tup, 2, item);\n\t\tname = PyObject_GetItem(names, index);\n\t\tPy_DECREF(index);\n\n\t\t/* Insert into dictionary */\n\t\tif (PyDict_GetItem(fields, name) != NULL) {\n\t\t\tPyErr_SetString(PyExc_ValueError,\n\t\t\t\t\t\"two fields with the same name\");\n\t\t\tret = PY_FAIL;\n\t\t}\n\t\tPyDict_SetItem(fields, name, tup);\n\t\tPy_DECREF(name);\n\t\tif (len == 3) PyDict_SetItem(fields, item, tup);\n\t\tPy_DECREF(tup);\n\t\tif ((ret == PY_FAIL) || (newdescr->elsize == 0)) goto fail;\n if (!hasobject && newdescr->hasobject)\n hasobject = 1;\n\t\ttotalsize += newdescr->elsize;\n\t}\n\n\tnew = PyArray_DescrNewFromType(PyArray_VOID);\n\tif (new == NULL) goto fail;\n\tif (maxalign > 1)\n\t\ttotalsize = ((totalsize + maxalign - 1)/maxalign)*maxalign;\n\tif (align) new->alignment = maxalign;\n\tnew->elsize = totalsize;\n\tkey = PyInt_FromLong(-1);\n\tPyDict_SetItem(fields, key, names);\n\tPy_DECREF(key);\n\tnew->fields = fields;\n new->hasobject=hasobject;\n\treturn new;\n\n fail:\n\tPy_XDECREF(fields);\n\treturn NULL;\n}\n\n/* \n any object with \n the .fields attribute and/or .itemsize attribute \n (if the .fields attribute does not give\n the total size -- i.e. a partial record naming).\n If itemsize is given it must be >= size computed from fields\n \n The .fields attribute must return a convertible dictionary if \n present. Result inherits from PyArray_VOID.\n*/\n\n\n/*MULTIARRAY_API\n Get typenum from an object -- None goes to NULL\n*/\nstatic int\nPyArray_DescrConverter2(PyObject *obj, PyArray_Descr **at)\n{\n\tif (obj == Py_None) {\n\t\t*at = NULL;\n\t\treturn PY_SUCCEED;\n\t}\n\telse return PyArray_DescrConverter(obj, at);\n}\n\n/* This function takes a Python object representing a type and converts it \n to a the correct PyArray_Descr * structure to describe the type.\n \n Many objects can be used to represent a data-type which in NumPy is\n quite a flexible concept. \n\n This is the central code that converts Python objects to \n Type-descriptor objects that are used throughout numpy.\n */\n\n/* new reference in *at */\n/*MULTIARRAY_API\n Get typenum from an object -- None goes to &LONG_descr\n*/\nstatic int\nPyArray_DescrConverter(PyObject *obj, PyArray_Descr **at)\n{\n char *type;\n int check_num=PyArray_NOTYPE+10;\n\tint len;\n\tPyObject *item;\n\tint elsize = 0;\n\tchar endian = '=';\n\n\t*at=NULL;\n\t\n\t/* default */\n if (obj == Py_None) {\n\t\t*at = PyArray_DescrFromType(PyArray_LONG);\n\t\treturn PY_SUCCEED;\n\t}\n\t\n\tif (PyArray_DescrCheck(obj)) {\n\t\t*at = (PyArray_Descr *)obj;\n\t\tPy_INCREF(*at);\n\t\treturn PY_SUCCEED;\n\t}\n\t\n if (PyType_Check(obj)) {\n\t\tif (PyType_IsSubtype((PyTypeObject *)obj, \n\t\t\t\t &PyGenericArrType_Type)) {\n\t\t\t*at = PyArray_DescrFromTypeObject(obj);\n\t\t\tif (*at) return PY_SUCCEED;\n\t\t\telse return PY_FAIL;\n\t\t}\n\t\tcheck_num = PyArray_OBJECT;\n\t\tif (obj == (PyObject *)(&PyInt_Type))\n\t\t\tcheck_num = PyArray_LONG;\n\t\telse if (obj == (PyObject *)(&PyLong_Type))\n\t\t\tcheck_num = PyArray_LONGLONG;\n\t\telse if (obj == (PyObject *)(&PyFloat_Type)) \n\t\t\tcheck_num = PyArray_DOUBLE;\n\t\telse if (obj == (PyObject *)(&PyComplex_Type)) \n\t\t\tcheck_num = PyArray_CDOUBLE;\n\t\telse if (obj == (PyObject *)(&PyBool_Type))\n\t\t\tcheck_num = PyArray_BOOL;\n else if (obj == (PyObject *)(&PyString_Type))\n check_num = PyArray_STRING;\n else if (obj == (PyObject *)(&PyUnicode_Type))\n check_num = PyArray_UNICODE;\n\t\telse if (obj == (PyObject *)(&PyBuffer_Type))\n\t\t\tcheck_num = PyArray_VOID;\n\t\telse {\n\t\t\t*at = _arraydescr_fromobj(obj);\n\t\t\tif (*at) return PY_SUCCEED;\n\t\t}\n\t\tgoto finish;\n\t}\n\n\t/* or a typecode string */\n\n\tif (PyString_Check(obj)) {\n\t\t/* Check for a string typecode. */\n\t\ttype = PyString_AS_STRING(obj);\n\t\tlen = PyString_GET_SIZE(obj);\n\t\tif (len <= 0) goto fail;\n\t\tcheck_num = (int) type[0];\n\t\tif ((char) check_num == '>' || (char) check_num == '<' || \\\n\t\t (char) check_num == '|' || (char) check_num == '=') {\n\t\t\tif (len <= 1) goto fail;\n\t\t\tendian = (char) check_num;\n\t\t\ttype++; len--;\n\t\t\tcheck_num = (int) type[0];\n\t\t\tif (endian == '|') endian = '=';\n\t\t}\n\t\tif (len > 1) {\n\t\t\tint i;\n\t\t\telsize = atoi(type+1);\n\t\t\t/* check for commas present */\n\t\t\tfor (i=1;ielsize == 0) && (elsize != 0)) {\n\t\tPyArray_DESCR_REPLACE(*at);\n\t\t(*at)->elsize = elsize;\n\t}\n\tif (endian != '=' && PyArray_ISNBO(endian)) endian = '='; \n\t\n\tif (endian != '=' && (*at)->byteorder != '|' &&\t\\\n\t (*at)->byteorder != endian) {\n\t\tPyArray_DESCR_REPLACE(*at);\n\t\t(*at)->byteorder = endian;\n\t}\n\t\n return PY_SUCCEED;\n\n fail:\n\tPyErr_SetString(PyExc_TypeError, \n\t\t\t\"data type not understood\");\n\t*at=NULL;\n\treturn PY_FAIL;\n}\t\n\n/*MULTIARRAY_API\n Convert object to endian\n*/\nstatic int\nPyArray_ByteorderConverter(PyObject *obj, char *endian)\n{\n\tchar *str;\n\t*endian = PyArray_SWAP;\n\tstr = PyString_AsString(obj);\n\tif (!str) return PY_FAIL;\n\tif (strlen(str) < 1) {\n\t\tPyErr_SetString(PyExc_ValueError, \n\t\t\t\t\"Byteorder string must be at least length 1\");\n\t\treturn PY_FAIL;\n\t}\n\t*endian = str[0];\n\tif (str[0] != PyArray_BIG && str[0] != PyArray_LITTLE &&\t\\\n\t str[0] != PyArray_NATIVE) {\n\t\tif (str[0] == 'b' || str[0] == 'B')\n\t\t\t*endian = PyArray_BIG;\n\t\telse if (str[0] == 'l' || str[0] == 'L')\n\t\t\t*endian = PyArray_LITTLE;\n\t\telse if (str[0] == 'n' || str[0] == 'N')\n\t\t\t*endian = PyArray_NATIVE;\n\t\telse if (str[0] == 'i' || str[0] == 'I')\n\t\t\t*endian = PyArray_IGNORE;\n\t\telse if (str[0] == 's' || str[0] == 'S')\n\t\t\t*endian = PyArray_SWAP;\n\t\telse {\n\t\t\tPyErr_Format(PyExc_ValueError, \n\t\t\t\t \"%s is an unrecognized byteorder\",\n\t\t\t\t str);\n\t\t\treturn PY_FAIL;\n\t\t}\n\t}\n\treturn PY_SUCCEED;\n}\n\n/*MULTIARRAY_API\n Convert object to sort kind \n*/\nstatic int\nPyArray_SortkindConverter(PyObject *obj, PyArray_SORTKIND *sortkind)\n{\n\tchar *str;\n\t*sortkind = PyArray_QUICKSORT;\n\tstr = PyString_AsString(obj);\n\tif (!str) return PY_FAIL;\n\tif (strlen(str) < 1) {\n\t\tPyErr_SetString(PyExc_ValueError, \n\t\t\t\t\"Sort kind string must be at least length 1\");\n\t\treturn PY_FAIL;\n\t}\n\tif (str[0] == 'q' || str[0] == 'Q')\n\t\t*sortkind = PyArray_QUICKSORT;\n\telse if (str[0] == 'h' || str[0] == 'H')\n\t\t*sortkind = PyArray_HEAPSORT;\n\telse if (str[0] == 'm' || str[0] == 'M')\n\t\t*sortkind = PyArray_MERGESORT;\n\telse if (str[0] == 't' || str[0] == 'T')\n\t\t*sortkind = PyArray_TIMSORT;\n\telse {\n\t\tPyErr_Format(PyExc_ValueError, \n\t\t\t \"%s is an unrecognized kind of sort\",\n\t\t\t str);\n\t\treturn PY_FAIL;\n\t}\n\treturn PY_SUCCEED;\n}\n\n\n/* This function returns true if the two typecodes are \n equivalent (same basic kind and same itemsize).\n*/\n\n/*MULTIARRAY_API*/\nstatic Bool\nPyArray_EquivTypes(PyArray_Descr *typ1, PyArray_Descr *typ2)\n{\n\tregister int typenum1=typ1->type_num;\n\tregister int typenum2=typ2->type_num;\n\tregister int size1=typ1->elsize;\n\tregister int size2=typ2->elsize;\n\n\tif (size1 != size2) return FALSE;\n\tif (typ1->fields != typ2->fields) return FALSE;\n\tif (PyArray_ISNBO(typ1->byteorder) != PyArray_ISNBO(typ2->byteorder))\n\t\treturn FALSE;\n\n\tif (typenum1 == PyArray_VOID || \\\n\t typenum2 == PyArray_VOID) {\n\t\treturn ((typenum1 == typenum2) && \n\t\t\t(typ1->typeobj == typ2->typeobj) &&\n\t\t\t(typ1->fields == typ2->fields));\n\t}\n\treturn (typ1->kind == typ2->kind);\n}\n\n/*** END C-API FUNCTIONS **/\n\nstatic PyObject *\n_prepend_ones(PyArrayObject *arr, int nd, int ndmin)\n{\n\tintp newdims[MAX_DIMS];\n\tintp newstrides[MAX_DIMS];\n\tint i,k,num;\n\tPyObject *ret;\n\n\tnum = ndmin-nd;\n\tfor (i=0; idescr->elsize;\n\t}\n\tfor (i=num;idimensions[k];\n\t\tnewstrides[i] = arr->strides[k];\n\t}\n\tPy_INCREF(arr->descr);\n\tret = PyArray_NewFromDescr(arr->ob_type, arr->descr, ndmin,\n\t\t\t\t newdims, newstrides, arr->data, arr->flags,\n\t\t\t\t (PyObject *)arr);\n\t/* steals a reference to arr --- so don't increment\n\t here */\n\tPyArray_BASE(ret) = (PyObject *)arr;\n\treturn ret;\n}\n\n\n#define _ARET(x) PyArray_Return((PyArrayObject *)(x))\n\nstatic char doc_fromobject[] = \"array(object, dtype=None, copy=1, fortran=0, \"\\\n \"subok=0,ndmin=0)\\n\"\\\n \"will return a new array formed from the given object type given.\\n\"\\\n \"Object can anything with an __array__ method, or any object\\n\"\\\n \"exposing the array interface, or any (nested) sequence.\\n\"\\\n \"If no type is given, then the type will be determined as the\\n\"\\\n \"minimum type required to hold the objects in the sequence.\\n\"\\\n \"If copy is zero and sequence is already an array with the right \\n\"\\\n \"type, a reference will be returned. If the sequence is an array,\\n\"\\\n \"type can be used only to upcast the array. For downcasting \\n\"\\\n \"use .astype(t) method. If subok is true, then subclasses of the\\n\"\\\n \"array may be returned. Otherwise, a base-class ndarray is returned\\n\"\\\n\t\"The ndmin argument specifies how many dimensions the returned\\n\"\\\n\t\"array should have as a minimum. 1's will be pre-pended to the\\n\"\\\n\t\"shape as needed to meet this requirement.\";\n\nstatic PyObject *\n_array_fromobject(PyObject *ignored, PyObject *args, PyObject *kws)\n{\n\tPyObject *op, *ret=NULL;\n\tstatic char *kwd[]= {\"object\", \"dtype\", \"copy\", \"fortran\", \"subok\", \n\t\t\t \"ndmin\", NULL};\n Bool subok=FALSE;\n\tBool copy=TRUE;\n\tint ndmin=0, nd;\n\tPyArray_Descr *type=NULL;\n\tPyArray_Descr *oldtype=NULL;\n\tBool fortran=FALSE;\n\tint flags=0;\n\n\tif(!PyArg_ParseTupleAndKeywords(args, kws, \"O|O&O&O&O&i\", kwd, &op, \n\t\t\t\t\tPyArray_DescrConverter2,\n &type, \n\t\t\t\t\tPyArray_BoolConverter, ©, \n\t\t\t\t\tPyArray_BoolConverter, &fortran,\n PyArray_BoolConverter, &subok, \n\t\t\t\t\t&ndmin)) \n\t\treturn NULL;\n\n\t/* fast exit if simple call */\n\tif ((PyArray_CheckExact(op) || PyBigArray_CheckExact(op))) {\n\t\tif (type==NULL) {\n\t\t\tif (!copy && fortran==PyArray_ISFORTRAN(op)) {\n\t\t\t\tPy_INCREF(op);\n\t\t\t\tret = op;\n\t\t\t\tgoto finish;\n\t\t\t}\n\t\t\telse {\n\t\t\t\tret = PyArray_NewCopy((PyArrayObject*)op, \n\t\t\t\t\t\t fortran);\n\t\t\t\tgoto finish;\n\t\t\t}\n\t\t}\n\t\t/* One more chance */\n\t\toldtype = PyArray_DESCR(op);\n\t\tif (PyArray_EquivTypes(oldtype, type)) {\n\t\t\tif (!copy && fortran==PyArray_ISFORTRAN(op)) {\n\t\t\t\tPy_INCREF(op);\n\t\t\t\tret = op;\n\t\t\t\tgoto finish;\n\t\t\t}\n\t\t\telse {\n\t\t\t\tret = PyArray_NewCopy((PyArrayObject*)op,\n\t\t\t\t\t\t fortran);\n\t\t\t\tif (oldtype == type) return ret;\n\t\t\t\tPy_INCREF(oldtype);\n\t\t\t\tPy_DECREF(PyArray_DESCR(ret));\n\t\t\t\tPyArray_DESCR(ret) = oldtype;\n\t\t\t\tgoto finish;\n\t\t\t}\n\t\t}\n\t}\n\n\tif (copy) {\n\t\tflags = ENSURECOPY;\n\t}\n\tif (fortran) {\n\t\tflags |= FORTRAN;\n\t}\n if (!subok) {\n flags |= ENSUREARRAY;\n }\n\n\tif ((ret = PyArray_CheckFromAny(op, type, 0, 0, flags, NULL)) == NULL) \n\t\treturn NULL;\n\n finish:\n\n\tif ((nd=PyArray_NDIM(ret)) >= ndmin) return ret;\n\t/* create a new array from the same data with ones in the shape */\n\t/* steals a reference to ret */\n\treturn _prepend_ones((PyArrayObject *)ret, nd, ndmin);\n}\n\n/* accepts NULL type */\n/* steals referenct to type */\n/*MULTIARRAY_API\n Empty\n*/\nstatic PyObject *\nPyArray_Empty(int nd, intp *dims, PyArray_Descr *type, int fortran)\n{\n\tPyArrayObject *ret;\n \n\tif (!type) type = PyArray_DescrFromType(PyArray_LONG);\n\tret = (PyArrayObject *)PyArray_NewFromDescr(&PyArray_Type, \n\t\t\t\t\t\t type, nd, dims, \n\t\t\t\t\t\t NULL, NULL,\n\t\t\t\t\t\t fortran, NULL);\n\tif (ret == NULL) return NULL;\n \n\tif ((PyArray_TYPE(ret) == PyArray_OBJECT)) {\n PyArray_FillObjectArray(ret, Py_None);\n\t}\n\treturn (PyObject *)ret;\n}\n\n\nstatic char doc_empty[] = \"empty((d1,...,dn),dtype=int,fortran=0) will return a new array\\n of shape (d1,...,dn) and given type with all its entries uninitialized. This can be faster than zeros.\";\n\nstatic PyObject *\narray_empty(PyObject *ignored, PyObject *args, PyObject *kwds) \n{\n \n\tstatic char *kwlist[] = {\"shape\",\"dtype\",\"fortran\",NULL};\n\tPyArray_Descr *typecode=NULL;\n PyArray_Dims shape = {NULL, 0};\n\tBool fortran = FALSE;\t\n PyObject *ret=NULL;\n\n\tif (!PyArg_ParseTupleAndKeywords(args, kwds, \"O&|O&O&\",\n\t\t\t\t\t kwlist, PyArray_IntpConverter,\n &shape, \n PyArray_DescrConverter,\n\t\t\t\t\t &typecode, \n\t\t\t\t\t PyArray_BoolConverter, &fortran)) \n\t\tgoto fail;\n\n\tret = PyArray_Empty(shape.len, shape.ptr, typecode, fortran); \n PyDimMem_FREE(shape.ptr);\n return ret;\n\n fail:\n\tPyDimMem_FREE(shape.ptr);\n\treturn ret;\n}\n\nstatic char doc_scalar[] = \"scalar(dtype,obj) will return a new scalar array of the given type initialized with obj. Mainly for pickle support. The dtype must be a valid data-type descriptor. If dtype corresponds to an OBJECT descriptor, then obj can be any object, otherwise obj must be a string. If obj is not given it will be interpreted as None for object type and zeros for all other types.\";\n\nstatic PyObject *\narray_scalar(PyObject *ignored, PyObject *args, PyObject *kwds) \n{\n \n\tstatic char *kwlist[] = {\"dtype\",\"obj\", NULL};\n\tPyArray_Descr *typecode;\n\tPyObject *obj=NULL;\n\tint alloc=0;\n\tvoid *dptr;\n\tPyObject *ret;\n\n\t\n\tif (!PyArg_ParseTupleAndKeywords(args, kwds, \"O!|O\",\n\t\t\t\t\t kwlist, &PyArrayDescr_Type, \n\t\t\t\t\t &typecode,\n\t\t\t\t\t &obj)) \n\t\treturn NULL;\n\t\t\n\tif (typecode->elsize == 0) {\n\t\tPyErr_SetString(PyExc_ValueError,\t\t\\\n\t\t\t\t\"itemsize cannot be zero\");\n\t\treturn NULL;\n\t}\n\n\tif (typecode->type_num == PyArray_OBJECT) {\n\t\tif (obj == NULL) obj = Py_None;\n\t\tdptr = &obj;\n\t}\n\telse {\n\t\tif (obj == NULL) {\n\t\t\tdptr = _pya_malloc(typecode->elsize);\n\t\t\tif (dptr == NULL) {\n\t\t\t\treturn PyErr_NoMemory();\n\t\t\t}\n\t\t\tmemset(dptr, '\\0', typecode->elsize);\n\t\t\talloc = 1;\n\t\t}\n\t\telse {\n\t\t\tif (!PyString_Check(obj)) {\n\t\t\t\tPyErr_SetString(PyExc_TypeError, \n\t\t\t\t\t\t\"initializing object must \"\\\n\t\t\t\t\t\t\"be a string\");\n\t\t\t\treturn NULL;\n\t\t\t}\n\t\t\tif (PyString_GET_SIZE(obj) < typecode->elsize) {\n\t\t\t\tPyErr_SetString(PyExc_ValueError,\n\t\t\t\t\t\t\"initialization string is too\"\\\n\t\t\t\t\t\t\" small\");\n\t\t\t\treturn NULL;\n\t\t\t}\n\t\t\tdptr = PyString_AS_STRING(obj);\n\t\t}\n\t}\n\n\tret = PyArray_Scalar(dptr, typecode, NULL);\n\t\n\t/* free dptr which contains zeros */\n\tif (alloc) _pya_free(dptr);\n\treturn ret;\n}\n\n\n/* steal a reference */\n/* accepts NULL type */\n/*MULTIARRAY_API\n Zeros\n*/\nstatic PyObject *\nPyArray_Zeros(int nd, intp *dims, PyArray_Descr *type, int fortran)\n{\n\tPyArrayObject *ret;\n\tintp n;\n\n\tif (!type) type = PyArray_DescrFromType(PyArray_LONG);\n\tret = (PyArrayObject *)PyArray_NewFromDescr(&PyArray_Type, \n\t\t\t\t\t\t type,\n\t\t\t\t\t\t nd, dims, \n\t\t\t\t\t\t NULL, NULL, \n\t\t\t\t\t\t fortran, NULL);\n\tif (ret == NULL) return NULL;\n \n\tif ((PyArray_TYPE(ret) == PyArray_OBJECT)) {\n\t\tPyObject *zero = PyInt_FromLong(0);\n PyArray_FillObjectArray(ret, zero);\n Py_DECREF(zero);\n\t}\n\telse {\n\t\tn = PyArray_NBYTES(ret);\n\t\tmemset(ret->data, 0, n);\n\t}\n\treturn (PyObject *)ret;\n\n}\n\nstatic char doc_zeros[] = \"zeros((d1,...,dn),dtype=int,fortran=0) will return a new array of shape (d1,...,dn) and type typecode with all it's entries initialized to zero.\";\n\n\nstatic PyObject *\narray_zeros(PyObject *ignored, PyObject *args, PyObject *kwds) \n{\n\tstatic char *kwlist[] = {\"shape\",\"dtype\",\"fortran\",NULL}; /* XXX ? */\n\tPyArray_Descr *typecode=NULL;\n PyArray_Dims shape = {NULL, 0};\n\tBool fortran = FALSE;\t\n PyObject *ret=NULL;\n\n\tif (!PyArg_ParseTupleAndKeywords(args, kwds, \"O&|O&O&\",\n\t\t\t\t\t kwlist, PyArray_IntpConverter,\n &shape, \n PyArray_DescrConverter,\n\t\t\t\t\t &typecode, \n\t\t\t\t\t PyArray_BoolConverter,\n\t\t\t\t\t &fortran)) \n\t\tgoto fail;\n\n\tret = PyArray_Zeros(shape.len, shape.ptr, typecode, (int) fortran);\n PyDimMem_FREE(shape.ptr);\n return ret;\n\n fail:\n\tPyDimMem_FREE(shape.ptr);\n\treturn ret;\n}\n\nstatic char doc_set_typeDict[] = \"set_typeDict(dict) set the internal \"\\\n\t\"dictionary that can look up an array type using a registered \"\\\n\t\"code\";\n\nstatic PyObject *\narray_set_typeDict(PyObject *ignored, PyObject *args)\n{\n\tPyObject *dict;\n\tif (!PyArg_ParseTuple(args, \"O\", &dict)) return NULL;\n\tPy_XDECREF(typeDict); /* Decrement old reference (if any)*/\n\ttypeDict = dict;\n\tPy_INCREF(dict); /* Create an internal reference to it */\n\tPy_INCREF(Py_None);\n\treturn Py_None;\n}\n\nstatic int\n_skip_sep(char **ptr, char *sep)\n{\n\tchar *a;\n\tint n;\n\tn = strlen(sep);\n\ta = *ptr;\n\twhile(*a != '\\0' && (strncmp(a, sep, n) != 0))\n\t\ta++;\n\tif (*a == '\\0') return -1;\n\t*ptr = a+strlen(sep);\n\treturn 0;\n}\n\n/* steals a reference to dtype -- accepts NULL */\n/*OBJECT_API*/\nstatic PyObject *\nPyArray_FromString(char *data, intp slen, PyArray_Descr *dtype, \n\t\t intp n, char *sep)\n{\n\tint itemsize;\n\tPyArrayObject *ret;\n\tBool binary;\n\n\tif (dtype == NULL)\n\t\tdtype=PyArray_DescrFromType(PyArray_LONG);\n\t\n\titemsize = dtype->elsize;\n\tif (itemsize == 0) {\n\t\tPyErr_SetString(PyExc_ValueError, \"zero-valued itemsize\");\n\t\tPy_DECREF(dtype);\n\t\treturn NULL;\n\t}\n\n\tbinary = ((sep == NULL) || (strlen(sep) == 0));\t\n\n\tif (binary) {\n\t\tif (dtype == &OBJECT_Descr) {\n\t\t\tPyErr_SetString(PyExc_ValueError, \n\t\t\t\t\t\"Cannot create an object array from\"\\\n\t\t\t\t\t\" a binary string\");\n\t\t\tPy_DECREF(dtype);\n\t\t\treturn NULL;\n\t\t}\t\t\n\t\tif (n < 0 ) {\n\t\t\tif (slen % itemsize != 0) {\n\t\t\t\tPyErr_SetString(PyExc_ValueError, \n\t\t\t\t\t\t\"string size must be a \"\\\n\t\t\t\t\t\t\"multiple of element size\");\n\t\t\t\tPy_DECREF(dtype);\n\t\t\t\treturn NULL;\n\t\t\t}\n\t\t\tn = slen/itemsize;\n\t\t} else {\n\t\t\tif (slen < n*itemsize) {\n\t\t\t\tPyErr_SetString(PyExc_ValueError, \n\t\t\t\t\t\t\"string is smaller than \" \\\n\t\t\t\t\t\t\"requested size\");\n\t\t\t\tPy_DECREF(dtype);\n\t\t\t\treturn NULL;\n\t\t\t}\n\t\t}\n\t\n\t\tif ((ret = (PyArrayObject *)\\\n\t\t PyArray_NewFromDescr(&PyArray_Type, dtype,\n\t\t\t\t\t 1, &n, NULL, NULL,\n\t\t\t\t\t 0, NULL)) == NULL)\n\t\t\treturn NULL;\t\t\n\t\tmemcpy(ret->data, data, n*dtype->elsize);\n\t\treturn (PyObject *)ret;\n\t}\n\telse { /* read from character-based string */\n\t\tchar *ptr;\t\t\n\t\tPyArray_FromStrFunc *fromstr;\n\t\tchar *dptr;\n\t\tintp nread=0;\n\t\tintp index;\n\n\t\tfromstr = dtype->f->fromstr;\n\t\tif (fromstr == NULL) {\n\t\t\tPyErr_SetString(PyExc_ValueError, \n\t\t\t\t\t\"don't know how to read \"\t\\\n\t\t\t\t\t\"character strings for given \"\t\\\n\t\t\t\t\t\"array type\");\n\t\t\tPy_DECREF(dtype);\n\t\t\treturn NULL;\n\t\t}\n\n\t\tif (n!=-1) {\n\t\t\tret = (PyArrayObject *) \\\n\t\t\t\tPyArray_NewFromDescr(&PyArray_Type,\n\t\t\t\t\t\t dtype, 1, &n, NULL,\n\t\t\t\t\t\t NULL, 0, NULL);\n\t\t\tif (ret == NULL) return NULL;\n\t\t\tptr = data;\n\t\t\tdptr = ret->data;\n\t\t\tfor (index=0; index < n; index++) {\n\t\t\t\tif (fromstr(ptr, dptr, &ptr, ret) < 0)\n\t\t\t\t\tbreak;\n\t\t\t\tnread += 1;\n\t\t\t\tdptr += dtype->elsize;\n\t\t\t\tif (_skip_sep(&ptr, sep) < 0) \n\t\t\t\t\tbreak;\n\t\t\t}\n\t\t\tif (nread < n) {\n\t\t\t\tfprintf(stderr, \"%ld items requested but \"\\\n\t\t\t\t\t\"only %ld read\\n\", \n\t\t\t\t\t(long) n, (long) nread);\n\t\t\t\tret->data = \\\n\t\t\t\t\tPyDataMem_RENEW(ret->data, \n\t\t\t\t\t\t\tnread *\t\t\\\n\t\t\t\t\t\t\tret->descr->elsize);\n\t\t\t\tPyArray_DIM(ret,0) = nread;\n\t\t\t}\n\t\t}\n\t\telse {\n#define _FILEBUFNUM 4096\n\t\t\tintp thisbuf=0;\n\t\t\tintp size = _FILEBUFNUM;\n\t\t\tintp bytes;\n\t\t\tintp totalbytes;\n\t\t\tchar *end;\n\t\t\tint val;\n\n\t\t\tret = (PyArrayObject *)\\\n\t\t\t\tPyArray_NewFromDescr(&PyArray_Type, \n\t\t\t\t\t\t dtype,\n\t\t\t\t\t\t 1, &size, \n\t\t\t\t\t\t NULL, NULL, \n\t\t\t\t\t\t 0, NULL);\n\t\t\tif (ret==NULL) return NULL;\n\t\t\ttotalbytes = bytes = size * dtype->elsize;\n\t\t\tdptr = ret->data;\n\t\t\tptr = data;\n\t\t\tend = data+slen;\n\t\t\twhile (ptr < end) {\n\t\t\t\tval = fromstr(ptr, dptr, &ptr, ret);\n\t\t\t\tif (val < 0) break;\n\t\t\t\tnread += 1;\n\t\t\t\tval = _skip_sep(&ptr, sep);\n\t\t\t\tif (val < 0) break;\n\t\t\t\tthisbuf += 1;\n\t\t\t\tdptr += dtype->elsize;\n\t\t\t\tif (thisbuf == size) {\n\t\t\t\t\ttotalbytes += bytes;\n\t\t\t\t\tret->data = PyDataMem_RENEW(ret->data, \n\t\t\t\t\t\t\t\t totalbytes);\n\t\t\t\t\tdptr = ret->data + \\\n\t\t\t\t\t\t(totalbytes - bytes);\n\t\t\t\t\tthisbuf = 0;\n\t\t\t\t}\n\t\t\t}\n\t\t\tret->data = PyDataMem_RENEW(ret->data, \n\t\t\t\t\t\t nread*ret->descr->elsize);\n\t\t\tPyArray_DIM(ret,0) = nread;\n#undef _FILEBUFNUM\n\t\t}\n\t}\n\treturn (PyObject *)ret;\n}\n\nstatic char doc_fromString[] = \"fromstring(string, dtype=int, count=-1) returns a new 1d array initialized from the raw binary data in string. If count is positive, the new array will have count elements, otherwise it's size is determined by the size of string.\";\n\nstatic PyObject *\narray_fromString(PyObject *ignored, PyObject *args, PyObject *keywds)\n{\n\tchar *data;\n\tlonglong nin=-1;\n\tchar *sep=NULL;\n\tint s;\n\tstatic char *kwlist[] = {\"string\", \"dtype\", \"count\", \"sep\", NULL};\n\tPyArray_Descr *descr=NULL;\n\n\tif (!PyArg_ParseTupleAndKeywords(args, keywds, \"s#|O&Ls\", kwlist, \n\t\t\t\t\t &data, &s, \n\t\t\t\t\t PyArray_DescrConverter, &descr,\n\t\t\t\t\t &nin, &sep)) {\n\t\treturn NULL;\n\t}\n\n\treturn PyArray_FromString(data, (intp)s, descr, (intp)nin, sep);\n}\n\n/* This needs an open file object and reads it in directly. \n memory-mapped files handled differently through buffer interface.\n\nfile pointer number in resulting 1d array \n(can easily reshape later, -1 for to end of file)\ntype of array\nsep is a separator string for character-based data (or NULL for binary)\n \" \" means whitespace\n*/\n\n/*OBJECT_API*/\nstatic PyObject *\nPyArray_FromFile(FILE *fp, PyArray_Descr *typecode, intp num, char *sep)\n{\n\tPyArrayObject *r;\n\tsize_t nread = 0;\n\tPyArray_ScanFunc *scan;\n\tBool binary;\n\n\tif (typecode->elsize == 0) {\n\t\tPyErr_SetString(PyExc_ValueError, \"0-sized elements.\");\n\t\tPy_DECREF(typecode);\n\t\treturn NULL;\n\t}\n\n\tbinary = ((sep == NULL) || (strlen(sep) == 0));\n\tif (num == -1 && binary) { /* Get size for binary file*/\n\t\tintp start, numbytes;\n\t\tstart = (intp )ftell(fp);\n\t\tfseek(fp, 0, SEEK_END);\n\t\tnumbytes = (intp )ftell(fp) - start;\n\t\trewind(fp);\n\t\tif (numbytes == -1) {\n\t\t\tPyErr_SetString(PyExc_IOError, \n\t\t\t\t\t\"could not seek in file\");\n\t\t\tPy_DECREF(typecode);\n\t\t\treturn NULL;\n\t\t}\n\t\tnum = numbytes / typecode->elsize;\n\t}\n\t\n\tif (binary) { /* binary data */\n\t\tr = (PyArrayObject *)PyArray_NewFromDescr(&PyArray_Type, \n\t\t\t\t\t\t\t typecode,\n\t\t\t\t\t\t\t 1, &num, \n\t\t\t\t\t\t\t NULL, NULL, \n\t\t\t\t\t\t\t 0, NULL);\n\t\tif (r==NULL) return NULL;\n\t\tnread = fread(r->data, typecode->elsize, num, fp);\n\t}\n\telse { /* character reading */\n\t\tintp i;\n\t\tchar *dptr;\n\t\tint done=0;\n\n\t\tscan = typecode->f->scanfunc;\n\t\tif (scan == NULL) {\n\t\t\tPyErr_SetString(PyExc_ValueError, \n\t\t\t\t\t\"don't know how to read \"\t\\\n\t\t\t\t\t\"character files with that \"\t\\\n\t\t\t\t\t\"array type\");\n\t\t\tPy_DECREF(typecode);\n\t\t\treturn NULL;\n\t\t}\n\n\t\tif (num != -1) { /* number to read is known */\n\t\t\tr = (PyArrayObject *)\\\n\t\t\t\tPyArray_NewFromDescr(&PyArray_Type, \n\t\t\t\t\t\t typecode, \n\t\t\t\t\t\t 1, &num, \n\t\t\t\t\t\t NULL, NULL, \n\t\t\t\t\t\t 0, NULL);\n\t\t\tif (r==NULL) return NULL;\n\t\t\tdptr = r->data;\n\t\t\tfor (i=0; i < num; i++) {\n\t\t\t\tif (done) break;\n\t\t\t\tdone = scan(fp, dptr, sep, NULL);\n\t\t\t\tif (done < -2) break;\n\t\t\t\tnread += 1;\n\t\t\t\tdptr += r->descr->elsize;\n\t\t\t}\n\t\t\tif (PyErr_Occurred()) {\n\t\t\t\tPy_DECREF(r);\n\t\t\t\treturn NULL;\n\t\t\t}\n\t\t}\n\t\telse { /* we have to watch for the end of the file and \n\t\t\t reallocate at the end */\n#define _FILEBUFNUM 4096\n\t\t\tintp thisbuf=0;\n\t\t\tintp size = _FILEBUFNUM;\n\t\t\tintp bytes;\n\t\t\tintp totalbytes;\n\n\t\t\tr = (PyArrayObject *)\\\n\t\t\t\tPyArray_NewFromDescr(&PyArray_Type, \n\t\t\t\t\t\t typecode,\n\t\t\t\t\t\t 1, &size, \n\t\t\t\t\t\t NULL, NULL, \n\t\t\t\t\t\t 0, NULL);\n\t\t\tif (r==NULL) return NULL;\n\t\t\ttotalbytes = bytes = size * typecode->elsize;\n\t\t\tdptr = r->data;\n\t\t\twhile (!done) {\n\t\t\t\tdone = scan(fp, dptr, sep, NULL);\n\n\t\t\t\t/* end of file reached trying to \n\t\t\t\t scan value. done is 1 or 2\n\t\t\t\t if end of file reached trying to\n\t\t\t\t scan separator. Still good value.\n\t\t\t\t*/\n\t\t\t\tif (done < -2) break;\n\t\t\t\tthisbuf += 1;\n\t\t\t\tnread += 1;\n\t\t\t\tdptr += r->descr->elsize;\n\t\t\t\tif (!done && thisbuf == size) {\n\t\t\t\t\ttotalbytes += bytes;\n\t\t\t\t\tr->data = PyDataMem_RENEW(r->data, \n\t\t\t\t\t\t\t\t totalbytes);\n\t\t\t\t\tdptr = r->data + (totalbytes - bytes);\n\t\t\t\t\tthisbuf = 0;\n\t\t\t\t}\n\t\t\t}\n\t\t\tif (PyErr_Occurred()) {\n\t\t\t\tPy_DECREF(r);\n\t\t\t\treturn NULL;\n\t\t\t}\n\t\t\tr->data = PyDataMem_RENEW(r->data, nread*r->descr->elsize);\n\t\t\tPyArray_DIM(r,0) = nread;\n\t\t\tnum = nread;\n#undef _FILEBUFNUM\n\t\t}\n\t}\n\tif (nread < num) {\n\t\tfprintf(stderr, \"%ld items requested but only %ld read\\n\", \n\t\t\t(long) num, (long) nread);\n\t\tr->data = PyDataMem_RENEW(r->data, nread * r->descr->elsize);\n\t\tPyArray_DIM(r,0) = nread;\n\t}\n\treturn (PyObject *)r;\n}\n\nstatic char doc_fromfile[] = \\\n\t\"fromfile(file=, dtype=int, count=-1, sep='')\\n\"\t\\\n\t\"\\n\"\\\n\t\" Return an array of the given data type from a \\n\"\\\n\t\" (text or binary) file. The file argument can be an open file\\n\"\\\n\t\" or a string with the name of a file to read from. If\\n\"\\\n\t\" count==-1, then the entire file is read, otherwise count is\\n\"\\\n\t\" the number of items of the given type read in. If sep is ''\\n\"\\\n\t\" then read a binary file, otherwise it gives the separator\\n\"\\\n\t\" between elements in a text file.\\n\"\\\n\t\"\\n\"\\\n\t\" WARNING: This function should be used sparingly, as it is not\\n\"\\\n\t\" a platform-independent method of persistence. But it can be \\n\"\\\n\t\" useful to read in simply-formatted or binary data quickly.\";\n\nstatic PyObject *\narray_fromfile(PyObject *ignored, PyObject *args, PyObject *keywds)\n{\n\tPyObject *file=NULL, *ret;\n\tFILE *fp;\n\tchar *sep=\"\";\n\tchar *mode=NULL;\n\tlonglong nin=-1;\n\tstatic char *kwlist[] = {\"file\", \"dtype\", \"count\", \"sep\", NULL};\n\tPyArray_Descr *type=NULL;\n\t\n\tif (!PyArg_ParseTupleAndKeywords(args, keywds, \"O|O&Ls\", kwlist, \n\t\t\t\t\t &file,\n\t\t\t\t\t PyArray_DescrConverter, &type,\n\t\t\t\t\t &nin, &sep)) {\n\t\treturn NULL;\n\t}\n\n\tif (type == NULL) type = PyArray_DescrFromType(PyArray_LONG);\n\n\tif (PyString_Check(file)) {\n\t\tif (sep == \"\") mode=\"rb\";\n\t\telse mode=\"r\";\n\t\tfile = PyFile_FromString(PyString_AS_STRING(file), mode);\n\t\tif (file==NULL) return NULL;\n\t}\n\telse {\n\t\tPy_INCREF(file);\n\t}\n\tfp = PyFile_AsFile(file);\n\tif (fp == NULL) {\n\t\tPyErr_SetString(PyExc_IOError, \n\t\t\t\t\"first argument must be an open file\");\n\t\tPy_DECREF(file);\n\t\treturn NULL;\n\t}\n\tret = PyArray_FromFile(fp, type, (intp) nin, sep);\n\tPy_DECREF(file);\n\treturn ret;\n}\n\n/*OBJECT_API*/\nstatic PyObject *\nPyArray_FromBuffer(PyObject *buf, PyArray_Descr *type, \n\t\t intp count, intp offset) \n{\n\tPyArrayObject *ret;\n\tchar *data;\n\tint ts;\n\tintp s, n;\n\tint itemsize;\n\tint write=1;\n\n\n\tif (type->type_num == PyArray_OBJECT) {\n\t\tPyErr_SetString(PyExc_ValueError, \n\t\t\t\t\"cannot create an OBJECT array from memory\"\\\n\t\t\t\t\" buffer\");\n\t\tPy_DECREF(type);\n\t\treturn NULL;\n\t}\n\tif (type->elsize == 0) {\n\t\tPyErr_SetString(PyExc_ValueError, \n\t\t\t\t\"itemsize cannot be zero in type\");\n\t\tPy_DECREF(type);\n\t\treturn NULL; \t\t\n\t}\n\n\tif (buf->ob_type->tp_as_buffer == NULL || \\\n\t (buf->ob_type->tp_as_buffer->bf_getwritebuffer == NULL &&\t\\\n\t buf->ob_type->tp_as_buffer->bf_getreadbuffer == NULL)) {\n\t\tPyObject *newbuf;\n\t\tnewbuf = PyObject_GetAttrString(buf, \"__buffer__\");\n\t\tif (newbuf == NULL) {Py_DECREF(type); return NULL;}\n\t\tbuf = newbuf;\n\t}\n\telse {Py_INCREF(buf);}\n\n\tif (PyObject_AsWriteBuffer(buf, (void *)&data, &ts)==-1) {\n\t\twrite = 0;\n\t\tPyErr_Clear();\n\t\tif (PyObject_AsReadBuffer(buf, (void *)&data, &ts)==-1) {\n\t\t\tPy_DECREF(buf);\n\t\t\tPy_DECREF(type);\n\t\t\treturn NULL;\n\t\t}\n\t}\n\t\n\tif ((offset < 0) || (offset >= ts)) {\n\t\tPyErr_Format(PyExc_ValueError,\n\t\t\t \"offset must be positive and smaller than %\"\n\t\t\t INTP_FMT, (intp)ts);\n\t}\n\n\tdata += offset;\n\ts = (intp)ts - offset;\n\tn = (intp)count;\n\titemsize = type->elsize;\n\t\n\tif (n < 0 ) {\n\t\tif (s % itemsize != 0) {\n\t\t\tPyErr_SetString(PyExc_ValueError, \n\t\t\t\t\t\"buffer size must be a multiple\"\\\n\t\t\t\t\t\" of element size\");\n\t\t\tPy_DECREF(buf);\n\t\t\tPy_DECREF(type);\n\t\t\treturn NULL;\n\t\t}\n\t\tn = s/itemsize;\n\t} else {\n\t\tif (s < n*itemsize) {\n\t\t\tPyErr_SetString(PyExc_ValueError, \n\t\t\t\t\t\"buffer is smaller than requested\"\\\n\t\t\t\t\t\" size\");\n\t\t\tPy_DECREF(buf);\n\t\t\tPy_DECREF(type);\n\t\t\treturn NULL;\n\t\t}\n\t}\n\t\n\tif ((ret = (PyArrayObject *)PyArray_NewFromDescr(&PyArray_Type, \n\t\t\t\t\t\t\t type, \n\t\t\t\t\t\t\t 1, &n, \n\t\t\t\t\t\t\t NULL, data, \n\t\t\t\t\t\t\t DEFAULT_FLAGS,\n\t\t\t\t\t\t\t NULL)) == NULL) {\n\t\tPy_DECREF(buf);\n\t\treturn NULL;\n\t}\n\t\n\tif (!write) ret->flags &= ~WRITEABLE;\n\n\t/* Store a reference for decref on deallocation */\n\tret->base = buf;\n\tPyArray_UpdateFlags(ret, ALIGNED);\n\treturn (PyObject *)ret;\n}\n\nstatic char doc_frombuffer[] = \\\n\t\"frombuffer(buffer=, dtype=int, count=-1, offset=0)\\n\"\\\n\t\"\\n\"\t\t\t\t\t\t\t\t\\\n\t\" Returns a 1-d array of data type dtype from buffer. The buffer\\n\"\\\n\t\" argument must be an object that exposes the buffer interface.\\n\"\\\n\t\" If count is -1 then the entire buffer is used, otherwise, count\\n\"\\\n\t\" is the size of the output. If offset is given then jump that\\n\"\\\n\t\" far into the buffer. If the buffer has data that is out\\n\" \\\n\t\" not in machine byte-order, than use a propert data type\\n\"\\\n\t\" descriptor. The data will not\\n\" \\\n\t\" be byteswapped, but the array will manage it in future\\n\"\\\n\t\" operations.\\n\";\n\nstatic PyObject *\narray_frombuffer(PyObject *ignored, PyObject *args, PyObject *keywds)\n{\n\tPyObject *obj=NULL;\n\tlonglong nin=-1, offset=0;\n\tstatic char *kwlist[] = {\"buffer\", \"dtype\", \"count\", \"offset\", NULL};\n\tPyArray_Descr *type=NULL;\n\n\tif (!PyArg_ParseTupleAndKeywords(args, keywds, \"O|O&LL\", kwlist, \n\t\t\t\t\t &obj,\n\t\t\t\t\t PyArray_DescrConverter, &type,\n\t\t\t\t\t &nin, &offset)) {\n\t\treturn NULL;\n\t}\n\tif (type==NULL)\n\t\ttype = PyArray_DescrFromType(PyArray_LONG);\n\t\n\treturn PyArray_FromBuffer(obj, type, (intp)nin, (intp)offset);\n}\n\n\nstatic char doc_concatenate[] = \"concatenate((a1,a2,...),axis=None).\";\n\nstatic PyObject *\narray_concatenate(PyObject *dummy, PyObject *args, PyObject *kwds) \n{\n\tPyObject *a0;\n\tint axis=0;\n\tstatic char *kwlist[] = {\"seq\", \"axis\", NULL};\n\t\n\tif (!PyArg_ParseTupleAndKeywords(args, kwds, \"O|O&\", kwlist,\n\t\t\t\t\t &a0,\n\t\t\t\t\t PyArray_AxisConverter, &axis))\n\t\treturn NULL;\n\treturn PyArray_Concatenate(a0, axis);\n}\n\nstatic char doc_innerproduct[] = \\\n\t\"inner(a,b) returns the dot product of two arrays, which has\\n\"\\\n\t\"shape a.shape[:-1] + b.shape[:-1] with elements computed by\\n\" \\\n\t\"the product of the elements from the last dimensions of a and b.\";\n\nstatic PyObject *array_innerproduct(PyObject *dummy, PyObject *args) {\n\tPyObject *b0, *a0;\n\t\n\tif (!PyArg_ParseTuple(args, \"OO\", &a0, &b0)) return NULL;\n\t\n\treturn _ARET(PyArray_InnerProduct(a0, b0));\n}\n\nstatic char doc_matrixproduct[] = \\\n\t\"dot(a,v) returns matrix-multiplication between a and b. \\n\"\\\n\t\"The product-sum is over the last dimension of a and the \\n\"\\\n\t\"second-to-last dimension of b.\";\n\nstatic PyObject *array_matrixproduct(PyObject *dummy, PyObject *args) {\n\tPyObject *v, *a;\n\t\n\tif (!PyArg_ParseTuple(args, \"OO\", &a, &v)) return NULL;\n\t\n\treturn _ARET(PyArray_MatrixProduct(a, v));\n}\n\nstatic char doc_fastCopyAndTranspose[] = \"_fastCopyAndTranspose(a)\";\n\nstatic PyObject *array_fastCopyAndTranspose(PyObject *dummy, PyObject *args) {\n\tPyObject *a0;\n\t\n\tif (!PyArg_ParseTuple(args, \"O\", &a0)) return NULL;\n\t\n\treturn _ARET(PyArray_CopyAndTranspose(a0));\n}\n\nstatic char doc_correlate[] = \"cross_correlate(a,v, mode=0)\";\n\nstatic PyObject *array_correlate(PyObject *dummy, PyObject *args, PyObject *kwds) {\n\tPyObject *shape, *a0;\n\tint mode=0;\n\tstatic char *kwlist[] = {\"a\", \"v\", \"mode\", NULL};\n\t\n\tif (!PyArg_ParseTupleAndKeywords(args, kwds, \"OO|i\", kwlist, \n\t\t\t\t\t &a0, &shape, &mode)) return NULL;\n\t\n\treturn PyArray_Correlate(a0, shape, mode);\n}\n\n\n/*MULTIARRAY_API\n Arange, \n*/\nstatic PyObject *\nPyArray_Arange(double start, double stop, double step, int type_num)\n{\n\tintp length;\n\tPyObject *range;\n\tPyArray_ArrFuncs *funcs;\n\tPyObject *obj;\n\tint ret;\n\n\tlength = (intp ) ceil((stop - start)/step);\n \n\tif (length <= 0) {\n\t\tlength = 0;\n\t\treturn PyArray_New(&PyArray_Type, 1, &length, type_num,\n\t\t\t\t NULL, NULL, 0, 0, NULL);\n\t}\n\n\trange = PyArray_New(&PyArray_Type, 1, &length, type_num, \n\t\t\t NULL, NULL, 0, 0, NULL);\n\tif (range == NULL) return NULL;\n\n\tfuncs = PyArray_DESCR(range)->f; \n\n\t/* place start in the buffer and the next value in the second position */\n\t/* if length > 2, then call the inner loop, otherwise stop */\n\n\tobj = PyFloat_FromDouble(start);\n\tret = funcs->setitem(obj, PyArray_DATA(range), (PyArrayObject *)range);\n\tPy_DECREF(obj);\n\tif (ret < 0) goto fail;\n\tif (length == 1) return range;\n\n\tobj = PyFloat_FromDouble(start + step);\n\tret = funcs->setitem(obj, PyArray_DATA(range)+PyArray_ITEMSIZE(range), \n\t\t\t (PyArrayObject *)range);\n\tPy_DECREF(obj);\n\tif (ret < 0) goto fail;\n\tif (length == 2) return range;\n\n\tif (!funcs->fill) {\n\t\tPyErr_SetString(PyExc_ValueError, \"no fill-function for data-type.\");\n\t\tPy_DECREF(range);\n\t\treturn NULL;\n\t}\n\tfuncs->fill(PyArray_DATA(range), length, (PyArrayObject *)range);\n\tif (PyErr_Occurred()) goto fail;\n\t\n\treturn range;\n\n fail:\n\tPy_DECREF(range);\n\treturn NULL;\n}\n\n/* the formula is \n len = (intp) ceil((start - stop) / step);\n*/\nstatic intp\n_calc_length(PyObject *start, PyObject *stop, PyObject *step, PyObject **next, int cmplx)\n{\n\tintp len;\n\tPyObject *val;\n\tdouble value;\n\t\n\t*next = PyNumber_Subtract(stop, start);\n\tif (!(*next)) return -1;\n\tval = PyNumber_TrueDivide(*next, step);\n\tPy_DECREF(*next); *next=NULL;\n\tif (!val) return -1;\n\tif (cmplx && PyComplex_Check(val)) {\n\t\tvalue = PyComplex_RealAsDouble(val);\n\t\tif (error_converting(value)) {Py_DECREF(val); return -1;}\n\t\tlen = (intp) ceil(value);\n\t\tvalue = PyComplex_ImagAsDouble(val);\n\t\tPy_DECREF(val);\n\t\tif (error_converting(value)) return -1;\n\t\tlen = MIN(len, (intp) ceil(value));\n\t}\n\telse {\n\t\tvalue = PyFloat_AsDouble(val);\n\t\tPy_DECREF(val);\n\t\tif (error_converting(value)) return -1;\n\t\tlen = (intp) ceil(value);\n\t}\n\t\n\tif (len > 0) {\n\t\t*next = PyNumber_Add(start, step);\n\t\tif (!next) return -1;\n\t}\n\treturn len;\n}\n\n/* this doesn't change the references */\n/*MULTIARRAY_API\n ArangeObj,\n*/\nstatic PyObject *\nPyArray_ArangeObj(PyObject *start, PyObject *stop, PyObject *step, PyArray_Descr *dtype) \n{\n\tPyObject *range;\n\tPyArray_ArrFuncs *funcs;\n\tPyObject *next;\n\tintp length;\n\n\tif (!dtype) {\n\t\tPyArray_Descr *deftype;\n\t\tPyArray_Descr *newtype;\n\t\tdeftype = PyArray_DescrFromType(PyArray_LONG);\n\t\tnewtype = PyArray_DescrFromObject(start, deftype);\n\t\tPy_DECREF(deftype);\n\t\tdeftype = newtype;\n\t\tif (stop && stop != Py_None) {\n\t\t\tnewtype = PyArray_DescrFromObject(stop, deftype);\n\t\t\tPy_DECREF(deftype);\n\t\t\tdeftype = newtype;\n\t\t}\n\t\tif (step && step != Py_None) {\n\t\t\tnewtype = PyArray_DescrFromObject(step, deftype);\n\t\t\tPy_DECREF(deftype);\n\t\t\tdeftype = newtype;\n\t\t}\n\t\tdtype = deftype;\n\t}\n\telse Py_INCREF(dtype);\n\n\tif (!step || step == Py_None) {\n\t\tstep = PyInt_FromLong(1);\n\t}\n\telse Py_XINCREF(step);\n\n\tif (!stop || stop == Py_None) {\n\t\tstop = start;\n\t\tstart = PyInt_FromLong(0);\n\t}\n\telse Py_INCREF(start);\n\n\t/* calculate the length and next = start + step*/\n\tlength = _calc_length(start, stop, step, &next, \n\t\t\t PyTypeNum_ISCOMPLEX(dtype->type_num));\n\n\tif (PyErr_Occurred()) {Py_DECREF(dtype); goto fail;}\n\tif (length <= 0) {\n\t\tlength = 0;\n\t\trange = PyArray_SimpleNewFromDescr(1, &length, dtype);\n\t\tPy_DECREF(step); Py_DECREF(start); return range;\n\t}\n\n\trange = PyArray_SimpleNewFromDescr(1, &length, dtype);\n\tif (range == NULL) goto fail;\n\n\tfuncs = PyArray_DESCR(range)->f;\n\n\t/* place start in the buffer and the next value in the second position */\n\t/* if length > 2, then call the inner loop, otherwise stop */\n\n\tif (funcs->setitem(start, PyArray_DATA(range), (PyArrayObject *)range) < 0)\n\t\tgoto fail;\n\tif (length == 1) goto finish;\n\tif (funcs->setitem(next, PyArray_DATA(range)+PyArray_ITEMSIZE(range), \n\t\t\t (PyArrayObject *)range) < 0) goto fail;\n\tif (length == 2) goto finish;\n\n\tif (!funcs->fill) {\n\t\tPyErr_SetString(PyExc_ValueError, \"no fill-function for data-type.\");\n\t\tPy_DECREF(range);\n\t\tgoto fail;\n\t}\n\tfuncs->fill(PyArray_DATA(range), length, (PyArrayObject *)range);\n\tif (PyErr_Occurred()) goto fail;\n\n finish:\n\tPy_DECREF(start);\n\tPy_DECREF(step);\n\tPy_DECREF(next);\n\treturn range;\n\t\n fail:\n\tPy_DECREF(start);\n\tPy_DECREF(step);\n\tPy_XDECREF(next);\n\treturn NULL;\n}\n\n\nstatic char doc_arange[] = \"arange(start, stop=None, step=1, dtype=int)\\n\\n Just like range() except it returns an array whose type can be\\n specified by the keyword argument typecode.\";\n\nstatic PyObject *\narray_arange(PyObject *ignored, PyObject *args, PyObject *kws) {\n\tPyObject *o_start=NULL, *o_stop=NULL, *o_step=NULL;\n\tstatic char *kwd[]= {\"start\", \"stop\", \"step\", \"dtype\", NULL};\n\tPyArray_Descr *typecode=NULL;\n\t\n\tif(!PyArg_ParseTupleAndKeywords(args, kws, \"O|OOO&\", kwd, &o_start,\n\t\t\t\t\t&o_stop, &o_step, \n\t\t\t\t\tPyArray_DescrConverter2,\n\t\t\t\t\t&typecode)) \n\t\treturn NULL;\n\n\treturn PyArray_ArangeObj(o_start, o_stop, o_step, typecode);\n}\n\n/*MULTIARRAY_API\n GetNDArrayCVersion\n*/\nstatic unsigned int\nPyArray_GetNDArrayCVersion(void)\n{\n\treturn (unsigned int)NDARRAY_VERSION;\n}\n\nstatic char \ndoc__get_ndarray_c_version[] = \"_get_ndarray_c_version() gets the compile time NDARRAY_VERSION number\";\n\nstatic PyObject *\narray__get_ndarray_c_version(PyObject *dummy, PyObject *args, PyObject *kwds) \n{\n\tstatic char *kwlist[] = {NULL};\n\tif(!PyArg_ParseTupleAndKeywords(args, kwds, \"\", kwlist )) return NULL;\n\t\n\treturn PyInt_FromLong( (long) PyArray_GetNDArrayCVersion() );\n}\n\nstatic char \ndoc_set_string_function[] = \"set_string_function(f, repr=1) sets the python function f to be the function used to obtain a pretty printable string version of a array whenever a array is printed. f(M) should expect a array argument M, and should return a string consisting of the desired representation of M for printing.\";\n\nstatic PyObject *\narray_set_string_function(PyObject *dummy, PyObject *args, PyObject *kwds) \n{\n\tPyObject *op;\n\tint repr=1;\n\tstatic char *kwlist[] = {\"f\", \"repr\", NULL};\n\n\tif(!PyArg_ParseTupleAndKeywords(args, kwds, \"O|i\", kwlist, \n\t\t\t\t\t&op, &repr)) return NULL; \n\tif (!PyCallable_Check(op)) {\n\t\tPyErr_SetString(PyExc_TypeError, \n\t\t\t\t\"Argument must be callable.\");\n\t\treturn NULL;\n\t}\n\tPyArray_SetStringFunction(op, repr);\n\tPy_INCREF(Py_None);\n\treturn Py_None;\n}\n\nstatic char \ndoc_set_ops_function[] = \"set_numeric_ops(op=func, ...) sets some or all of the number methods for all array objects. Don't forget **dict can be used as the argument list. Returns the functions that were replaced -- can be stored and set later.\";\n\nstatic PyObject *\narray_set_ops_function(PyObject *self, PyObject *args, PyObject *kwds) \n{\n\tPyObject *oldops=NULL;\n\t\n\tif ((oldops = PyArray_GetNumericOps())==NULL) return NULL;\n\n\t/* Should probably ensure that objects are at least callable */\n\t/* Leave this to the caller for now --- error will be raised\n\t later when use is attempted \n\t*/\n\tif (kwds && PyArray_SetNumericOps(kwds) == -1) {\n\t\tPy_DECREF(oldops);\n\t\tPyErr_SetString(PyExc_ValueError, \n\t\t\t\t\"one or more objects not callable\");\n\t\treturn NULL;\n\t}\n\treturn oldops;\n}\n\n\n/*MULTIARRAY_API\n Where\n*/\nstatic PyObject *\nPyArray_Where(PyObject *condition, PyObject *x, PyObject *y)\n{\n\tPyArrayObject *arr;\n\tPyObject *tup=NULL, *obj=NULL;\n\tPyObject *ret=NULL, *zero=NULL;\n\n\n\tarr = (PyArrayObject *)PyArray_FromAny(condition, NULL, 0, 0, 0, NULL);\n\tif (arr == NULL) return NULL;\n\n\tif ((x==NULL) && (y==NULL)) {\n\t\tret = PyArray_Nonzero(arr);\n\t\tPy_DECREF(arr);\n\t\treturn ret;\n\t}\n\n\tif ((x==NULL) || (y==NULL)) {\n\t\tPy_DECREF(arr);\n\t\tPyErr_SetString(PyExc_ValueError, \"either both or neither \"\n\t\t\t\t\"of x and y should be given\");\n\t\treturn NULL;\n\t}\n\n\n\tzero = PyInt_FromLong((long) 0);\n\n\tobj = PyArray_EnsureArray(PyArray_GenericBinaryFunction(arr, zero, \n\t\t\t\t\t\t\t\tn_ops.not_equal));\n\tPy_DECREF(zero);\n\tPy_DECREF(arr);\n\tif (obj == NULL) return NULL;\n\n\ttup = Py_BuildValue(\"(OO)\", y, x);\n\tif (tup == NULL) {Py_DECREF(obj); return NULL;}\n\n\tret = PyArray_Choose((PyAO *)obj, tup);\n\n\tPy_DECREF(obj);\n\tPy_DECREF(tup);\n\treturn ret;\n}\n\nstatic char doc_where[] = \"where(condition, | x, y) is shaped like condition\"\\\n\t\" and has elements of x and y where condition is respectively true or\"\\\n\t\" false. If x or y are not given, then it is equivalent to\"\\\n\t\" nonzero(condition).\";\n\nstatic PyObject *\narray_where(PyObject *ignored, PyObject *args)\n{\n\tPyObject *obj=NULL, *x=NULL, *y=NULL;\n\t\n\tif (!PyArg_ParseTuple(args, \"O|OO\", &obj, &x, &y)) return NULL;\n\n\treturn PyArray_Where(obj, x, y);\n\n}\n\nstatic char doc_lexsort[] = \"lexsort(keys=, axis=-1) returns an array of indexes\"\\\n\t\" similar to argsort except the sorting is done using the provided sorting\"\\\n\t\" keys. First the sort is done using key[0], then the resulting list of\"\\\n\t\" indexes is further manipulated by sorting on key[0]. And so forth\"\\\n\t\" The result is a sort on multiple keys. If the keys represented columns\" \\\n\t\" of a spread-sheet, for example, this would sort using multiple columns.\"\\\n\t\" The keys argument must be a tuple of things that can be converted to \"\\\n\t\" arrays of the same shape.\";\n\nstatic PyObject *\narray_lexsort(PyObject *ignored, PyObject *args, PyObject *kwds)\n{\n\tint axis=-1;\n\tPyObject *obj;\n\tstatic char *kwlist[] = {\"keys\", \"axis\", NULL};\n\t\n\tif (!PyArg_ParseTupleAndKeywords(args, kwds, \"O!|i\", kwlist, \n\t\t\t\t\t &PyTuple_Type, &obj, &axis)) return NULL;\n\t\n\treturn _ARET(PyArray_LexSort(obj, axis));\n}\n\n#undef _ARET\n\n\nstatic char doc_register_dtype[] = \\\n\t\"register_dtype(a) registers a new type object -- gives it a typenum\";\n\nstatic PyObject *\narray_register_dtype(PyObject *dummy, PyObject *args)\n{\n\tPyObject *dtype;\n\tint ret;\n\t\n\tif (!PyArg_ParseTuple(args, \"O\", &dtype)) return NULL;\n\t\n\tret = PyArray_RegisterDataType((PyTypeObject *)dtype);\n\tif (ret < 0)\n\t\treturn NULL;\n\treturn PyInt_FromLong((long) ret);\n}\n\nstatic char doc_can_cast_safely[] = \\\n\t\"can_cast_safely(from=d1, to=d2) returns True if data type d1 \"\\\n\t\"can be cast to data type d2 without losing precision.\";\n\nstatic PyObject *\narray_can_cast_safely(PyObject *dummy, PyObject *args, PyObject *kwds)\n{\n\tPyArray_Descr *d1=NULL;\n\tPyArray_Descr *d2=NULL;\n\tBool ret;\n\tPyObject *retobj;\n\tstatic char *kwlist[] = {\"from\", \"to\", NULL};\n\n\tif(!PyArg_ParseTupleAndKeywords(args, kwds, \"O&O&\", kwlist, \n\t\t\t\t\tPyArray_DescrConverter, &d1,\n\t\t\t\t\tPyArray_DescrConverter, &d2))\n\t\treturn NULL;\n\tif (d1 == NULL || d2 == NULL) {\n\t\tPyErr_SetString(PyExc_TypeError, \n\t\t\t\t\"did not understand one of the types; \"\t\\\n\t\t\t\t\"'None' not accepted\");\n\t\treturn NULL;\n\t}\n\t\t\n\tret = PyArray_CanCastTo(d1, d2);\n\tretobj = (ret ? Py_True : Py_False);\n\tPy_INCREF(retobj);\n\treturn retobj;\n}\n\nstatic char doc_new_buffer[] = \\\n\t\"newbuffer(size) return a new uninitialized buffer object of size \"\n\t\"bytes\";\n\nstatic PyObject *\nnew_buffer(PyObject *dummy, PyObject *args)\n{\n\tint size;\n\n\tif(!PyArg_ParseTuple(args, \"i\", &size))\n\t\treturn NULL;\n\t\n\treturn PyBuffer_New(size);\n}\n\nstatic char doc_buffer_buffer[] = \\\n\t\"getbuffer(obj [,offset[, size]]) create a buffer object from the \"\\\n\t\"given object\\n referencing a slice of length size starting at \"\\\n\t\"offset. Default\\n is the entire buffer. A read-write buffer is \"\\\n\t\"attempted followed by a read-only buffer.\";\n\nstatic PyObject *\nbuffer_buffer(PyObject *dummy, PyObject *args, PyObject *kwds)\n{\n\tPyObject *obj;\n\tint offset=0, size=Py_END_OF_BUFFER, n;\n\tvoid *unused;\n\tstatic char *kwlist[] = {\"object\", \"offset\", \"size\", NULL};\n\t\n\tif (!PyArg_ParseTupleAndKeywords(args, kwds, \"O|ii\", kwlist, \n\t\t\t\t\t &obj, &offset, &size))\n\t\treturn NULL;\n\n\n\tif (PyObject_AsWriteBuffer(obj, &unused, &n) < 0) {\n\t\tPyErr_Clear();\n\t\treturn PyBuffer_FromObject(obj, offset, size);\t\t\n\t}\n\telse\n\t\treturn PyBuffer_FromReadWriteObject(obj, offset, size);\n}\n\n\nstatic struct PyMethodDef array_module_methods[] = {\n\t{\"_get_ndarray_c_version\", (PyCFunction)array__get_ndarray_c_version, \n\t METH_VARARGS|METH_KEYWORDS, doc__get_ndarray_c_version},\n\t{\"set_string_function\", (PyCFunction)array_set_string_function, \n\t METH_VARARGS|METH_KEYWORDS, doc_set_string_function},\n\t{\"set_numeric_ops\", (PyCFunction)array_set_ops_function,\n\t METH_VARARGS|METH_KEYWORDS, doc_set_ops_function},\n\t{\"set_typeDict\", (PyCFunction)array_set_typeDict,\n\t METH_VARARGS, doc_set_typeDict},\n\n\t{\"array\",\t(PyCFunction)_array_fromobject, \n\t METH_VARARGS|METH_KEYWORDS, doc_fromobject},\n\t{\"arange\", (PyCFunction)array_arange, \n\t METH_VARARGS|METH_KEYWORDS, doc_arange},\n\t{\"zeros\",\t(PyCFunction)array_zeros, \n\t METH_VARARGS|METH_KEYWORDS, doc_zeros},\n\t{\"empty\",\t(PyCFunction)array_empty, \n\t METH_VARARGS|METH_KEYWORDS, doc_empty},\n\t{\"scalar\", (PyCFunction)array_scalar,\n\t METH_VARARGS|METH_KEYWORDS, doc_scalar},\n\t{\"where\", (PyCFunction)array_where,\n\t METH_VARARGS, doc_where},\n\t{\"lexsort\", (PyCFunction)array_lexsort,\n\t METH_VARARGS | METH_KEYWORDS, doc_lexsort},\n\t{\"fromstring\",(PyCFunction)array_fromString,\n\t METH_VARARGS|METH_KEYWORDS, doc_fromString},\n\t{\"concatenate\", (PyCFunction)array_concatenate, \n\t METH_VARARGS|METH_KEYWORDS, doc_concatenate},\n\t{\"inner\", (PyCFunction)array_innerproduct, \n\t METH_VARARGS, doc_innerproduct}, \n\t{\"dot\", (PyCFunction)array_matrixproduct, \n\t METH_VARARGS, doc_matrixproduct}, \n\t{\"_fastCopyAndTranspose\", (PyCFunction)array_fastCopyAndTranspose, \n\t METH_VARARGS, doc_fastCopyAndTranspose},\n\t{\"correlate\", (PyCFunction)array_correlate, \n\t METH_VARARGS | METH_KEYWORDS, doc_correlate},\n\t{\"frombuffer\", (PyCFunction)array_frombuffer,\n\t METH_VARARGS | METH_KEYWORDS, doc_frombuffer},\n\t{\"fromfile\", (PyCFunction)array_fromfile,\n\t METH_VARARGS | METH_KEYWORDS, doc_fromfile},\n\t{\"register_dtype\", (PyCFunction)array_register_dtype,\n\t METH_VARARGS, doc_register_dtype},\n\t{\"can_cast\", (PyCFunction)array_can_cast_safely,\n\t METH_VARARGS | METH_KEYWORDS, doc_can_cast_safely},\t\t\n\t{\"newbuffer\", (PyCFunction)new_buffer,\n\t METH_VARARGS, doc_new_buffer},\t\n\t{\"getbuffer\", (PyCFunction)buffer_buffer,\n\t METH_VARARGS | METH_KEYWORDS, doc_buffer_buffer},\t\n\t{NULL,\t\tNULL, 0}\t\t/* sentinel */\n};\n\n#include \"__multiarray_api.c\"\n\n/* Establish scalar-type hierarchy */\n\n/* For dual inheritance we need to make sure that the objects being\n inherited from have the tp->mro object initialized. This is\n not necessarily true for the basic type objects of Python (it is \n checked for single inheritance but not dual in PyType_Ready).\n\n Thus, we call PyType_Ready on the standard Python Types, here.\n*/ \nstatic int\nsetup_scalartypes(PyObject *dict)\n{\n\n\tinitialize_numeric_types();\n\n if (PyType_Ready(&PyBool_Type) < 0) return -1;\n if (PyType_Ready(&PyInt_Type) < 0) return -1;\n if (PyType_Ready(&PyFloat_Type) < 0) return -1;\n if (PyType_Ready(&PyComplex_Type) < 0) return -1;\n if (PyType_Ready(&PyString_Type) < 0) return -1;\n if (PyType_Ready(&PyUnicode_Type) < 0) return -1;\n\n#define SINGLE_INHERIT(child, parent) \\\n Py##child##ArrType_Type.tp_base = &Py##parent##ArrType_Type;\t\\\n if (PyType_Ready(&Py##child##ArrType_Type) < 0) {\t\t\\\n PyErr_Print(); \\\n PyErr_Format(PyExc_SystemError, \\\n\t\t\t \"could not initialize Py%sArrType_Type\", \\\n #child); \\\n return -1;\t\t\t\t\t\t\\\n }\n \n if (PyType_Ready(&PyGenericArrType_Type) < 0)\n return -1;\n\n SINGLE_INHERIT(Number, Generic);\n SINGLE_INHERIT(Integer, Number);\n SINGLE_INHERIT(Inexact, Number);\n SINGLE_INHERIT(SignedInteger, Integer);\n SINGLE_INHERIT(UnsignedInteger, Integer);\n SINGLE_INHERIT(Floating, Inexact);\n SINGLE_INHERIT(ComplexFloating, Inexact);\n SINGLE_INHERIT(Flexible, Generic);\n SINGLE_INHERIT(Character, Flexible);\n\t\n#define DUAL_INHERIT(child, parent1, parent2) \\\n Py##child##ArrType_Type.tp_base = &Py##parent2##ArrType_Type;\t\\\n Py##child##ArrType_Type.tp_bases = \\\n Py_BuildValue(\"(OO)\", &Py##parent2##ArrType_Type,\t\\\n\t\t\t &Py##parent1##_Type);\t\t\t\\\n if (PyType_Ready(&Py##child##ArrType_Type) < 0) { \\\n PyErr_Print(); \\\n\t\tPyErr_Format(PyExc_SystemError, \\\n\t\t\t \"could not initialize Py%sArrType_Type\", \\\n #child); \\\n return -1; \\\n }\\\n Py##child##ArrType_Type.tp_hash = Py##parent1##_Type.tp_hash;\n\n#define DUAL_INHERIT2(child, parent1, parent2)\t\t\t\t\\\n Py##child##ArrType_Type.tp_base = &Py##parent1##_Type;\t\t\\\n Py##child##ArrType_Type.tp_bases = \\\n Py_BuildValue(\"(OO)\", &Py##parent1##_Type,\t\t\\\n\t\t\t &Py##parent2##ArrType_Type);\t\t\\\n\tPy##child##ArrType_Type.tp_richcompare =\t\t\t\\\n\t\tPy##parent1##_Type.tp_richcompare;\t\t\t\\\n\tPy##child##ArrType_Type.tp_compare =\t\t\t\t\\\n\t\tPy##parent1##_Type.tp_compare;\t\t\t\t\\\n Py##child##ArrType_Type.tp_hash = Py##parent1##_Type.tp_hash;\t\\\n if (PyType_Ready(&Py##child##ArrType_Type) < 0) { \\\n PyErr_Print(); \\\n\t\tPyErr_Format(PyExc_SystemError, \\\n\t\t\t \"could not initialize Py%sArrType_Type\", \\\n #child); \\\n return -1; \\\n }\n\n SINGLE_INHERIT(Bool, Generic);\n SINGLE_INHERIT(Byte, SignedInteger);\n SINGLE_INHERIT(Short, SignedInteger);\n#if SIZEOF_INT == SIZEOF_LONG\n DUAL_INHERIT(Int, Int, SignedInteger);\n#else\n SINGLE_INHERIT(Int, SignedInteger);\n#endif\n DUAL_INHERIT(Long, Int, SignedInteger);\n#if SIZEOF_LONGLONG == SIZEOF_LONG\n DUAL_INHERIT(LongLong, Int, SignedInteger);\n#else\n SINGLE_INHERIT(LongLong, SignedInteger);\n#endif\n\n /* fprintf(stderr, \"tp_free = %p, PyObject_Del = %p, int_tp_free = %p, base.tp_free = %p\\n\", PyIntArrType_Type.tp_free, PyObject_Del, PyInt_Type.tp_free, PySignedIntegerArrType_Type.tp_free);\n\t */\n\tSINGLE_INHERIT(UByte, UnsignedInteger);\n SINGLE_INHERIT(UShort, UnsignedInteger);\n SINGLE_INHERIT(UInt, UnsignedInteger);\n SINGLE_INHERIT(ULong, UnsignedInteger);\n SINGLE_INHERIT(ULongLong, UnsignedInteger);\n\n SINGLE_INHERIT(Float, Floating);\n DUAL_INHERIT(Double, Float, Floating);\n SINGLE_INHERIT(LongDouble, Floating);\n\n SINGLE_INHERIT(CFloat, ComplexFloating);\n DUAL_INHERIT(CDouble, Complex, ComplexFloating);\n SINGLE_INHERIT(CLongDouble, ComplexFloating);\n\n DUAL_INHERIT2(String, String, Character);\n DUAL_INHERIT2(Unicode, Unicode, Character);\n\t\n SINGLE_INHERIT(Void, Flexible);\n \n SINGLE_INHERIT(Object, Generic);\n\n return 0;\n\n#undef SINGLE_INHERIT\n#undef DUAL_INHERIT\n\n\t/* Clean up string and unicode array types so they act more like\n\t strings -- get their tables from the standard types.\n\t*/\n}\n\n/* place a flag dictionary in d */\n\nstatic void\nset_flaginfo(PyObject *d)\n{\n PyObject *s;\n PyObject *newd;\n \n newd = PyDict_New();\n\n PyDict_SetItemString(newd, \"OWNDATA\", s=PyInt_FromLong(OWNDATA));\n Py_DECREF(s);\n PyDict_SetItemString(newd, \"FORTRAN\", s=PyInt_FromLong(FORTRAN));\n Py_DECREF(s);\n PyDict_SetItemString(newd, \"CONTIGUOUS\", s=PyInt_FromLong(CONTIGUOUS));\n Py_DECREF(s);\n PyDict_SetItemString(newd, \"ALIGNED\", s=PyInt_FromLong(ALIGNED));\n Py_DECREF(s);\n\n PyDict_SetItemString(newd, \"UPDATEIFCOPY\", s=PyInt_FromLong(UPDATEIFCOPY));\n Py_DECREF(s);\n PyDict_SetItemString(newd, \"WRITEABLE\", s=PyInt_FromLong(WRITEABLE));\n Py_DECREF(s);\n \n PyDict_SetItemString(d, \"_flagdict\", newd);\n Py_DECREF(newd);\n return;\n}\n\n\n/* Initialization function for the module */\n\nDL_EXPORT(void) initmultiarray(void) {\n\tPyObject *m, *d, *s;\n\tPyObject *c_api;\n\t\n\t/* Create the module and add the functions */\n\tm = Py_InitModule(\"multiarray\", array_module_methods);\n\tif (!m) goto err;\n\n\t/* Add some symbolic constants to the module */\n\td = PyModule_GetDict(m);\n\tif (!d) goto err; \n\n\t/* Create the module and add the functions */\n\tif (PyType_Ready(&PyBigArray_Type) < 0) \n\t\treturn;\n\n PyArray_Type.tp_base = &PyBigArray_Type;\n\n PyArray_Type.tp_as_mapping = &array_as_mapping;\n\t/* Even though, this would be inherited, it needs to be set now\n\t so that the __getitem__ will map to the as_mapping descriptor\n\t*/\n PyArray_Type.tp_as_number = &array_as_number; \n\t/* For good measure */\n\tPyArray_Type.tp_as_sequence = &array_as_sequence;\n\tPyArray_Type.tp_as_buffer = &array_as_buffer;\t\n PyArray_Type.tp_flags = (Py_TPFLAGS_DEFAULT \n\t\t\t\t | Py_TPFLAGS_BASETYPE\n\t\t\t\t | Py_TPFLAGS_CHECKTYPES);\n PyArray_Type.tp_doc = Arraytype__doc__;\n\n\tif (PyType_Ready(&PyArray_Type) < 0)\n return;\n\n if (setup_scalartypes(d) < 0) goto err;\n\n\tPyArrayIter_Type.tp_iter = PyObject_SelfIter;\n\tPyArrayMultiIter_Type.tp_iter = PyObject_SelfIter;\n\tif (PyType_Ready(&PyArrayIter_Type) < 0)\n\t\treturn; \n \n\tif (PyType_Ready(&PyArrayMapIter_Type) < 0)\n return; \n\n\tif (PyType_Ready(&PyArrayMultiIter_Type) < 0)\n\t\treturn;\n\n\tif (PyType_Ready(&PyArrayDescr_Type) < 0)\n\t\treturn;\n\n\tc_api = PyCObject_FromVoidPtr((void *)PyArray_API, NULL);\n\tif (PyErr_Occurred()) goto err;\n\tPyDict_SetItemString(d, \"_ARRAY_API\", c_api);\n\tPy_DECREF(c_api);\n\tif (PyErr_Occurred()) goto err;\n\n\tMultiArrayError = PyString_FromString (\"multiarray.error\");\n\tPyDict_SetItemString (d, \"error\", MultiArrayError);\n\t\n\ts = PyString_FromString(\"3.0\");\n\tPyDict_SetItemString(d, \"__version__\", s);\n\tPy_DECREF(s);\n Py_INCREF(&PyBigArray_Type);\n\tPyDict_SetItemString(d, \"bigndarray\", (PyObject *)&PyBigArray_Type);\n Py_INCREF(&PyArray_Type);\n\tPyDict_SetItemString(d, \"ndarray\", (PyObject *)&PyArray_Type);\n Py_INCREF(&PyArrayIter_Type);\n\tPyDict_SetItemString(d, \"flatiter\", (PyObject *)&PyArrayIter_Type);\n Py_INCREF(&PyArrayMultiIter_Type);\n\tPyDict_SetItemString(d, \"broadcast\", \n\t\t\t (PyObject *)&PyArrayMultiIter_Type);\n\tPy_INCREF(&PyArrayDescr_Type);\n\tPyDict_SetItemString(d, \"dtype\", (PyObject *)&PyArrayDescr_Type);\n\n\t/* Doesn't need to be exposed to Python \n Py_INCREF(&PyArrayMapIter_Type);\n\tPyDict_SetItemString(d, \"mapiter\", (PyObject *)&PyArrayMapIter_Type);\n\t*/\n set_flaginfo(d);\n\n\tif (set_typeinfo(d) != 0) goto err;\n\n\t_numpy_internal =\t\t\t\t\t\t\\\n\t\tPyImport_ImportModule(\"numpy.core._internal\");\n\tif (_numpy_internal != NULL) return;\n\n err:\t\n\tif (!PyErr_Occurred()) {\n\t\tPyErr_SetString(PyExc_RuntimeError, \n\t\t\t\t\"cannot load multiarray module.\");\n\t}\n\treturn;\n}\n\n", + "source_code_before": "\n/*\n Python Multiarray Module -- A useful collection of functions for creating and\n using ndarrays\n\n Original file \n Copyright (c) 1995, 1996, 1997 Jim Hugunin, hugunin@mit.edu\n\n Modified for numpy_core in 2005 \n\n Travis E. Oliphant\n Assistant Professor at\n Brigham Young University\n \n*/\n\n/* $Id: multiarraymodule.c,v 1.36 2005/09/14 00:14:00 teoliphant Exp $ */\n\n#include \"Python.h\"\n#include \"structmember.h\"\n/*#include \n#include \n*/\n\n#define _MULTIARRAYMODULE\n#include \"numpy/arrayobject.h\"\n\n#define PyAO PyArrayObject\n\nstatic PyObject *typeDict=NULL; /* Must be explicitly loaded */\nstatic PyObject *_numpy_internal=NULL; /* A Python module for callbacks */\n\n\nstatic PyArray_Descr *\n_arraydescr_fromobj(PyObject *obj)\n{\n\tPyObject *dtypedescr;\n\tPyArray_Descr *new;\n\tint ret;\n\t\n\tdtypedescr = PyObject_GetAttrString(obj, \"dtype\");\n\tPyErr_Clear();\n\tif (dtypedescr) {\n\t\tret = PyArray_DescrConverter(dtypedescr, &new);\n\t\tPy_DECREF(dtypedescr);\n\t\tif (ret) return new;\n\t\tPyErr_Clear();\n\t}\n\treturn NULL;\n}\n\n\n/* Including this file is the only way I know how to declare functions\n static in each file, and store the pointers from functions in both\n arrayobject.c and multiarraymodule.c for the C-API \n\n Declarying an external pointer-containing variable in arrayobject.c\n and trying to copy it to PyArray_API, did not work.\n\n Think about two modules with a common api that import each other...\n\n This file would just be the module calls. \n*/\n\n#include \"arrayobject.c\"\n\n\n/* An Error object -- rarely used? */\nstatic PyObject *MultiArrayError;\n\n/*MULTIARRAY_API\n Multiply a List of ints\n*/\nstatic int\nPyArray_MultiplyIntList(register int *l1, register int n) \n{\n\tregister int s=1;\n while (n--) s *= (*l1++);\n return s;\n}\n\n/*MULTIARRAY_API\n Multiply a List\n*/\nstatic intp \nPyArray_MultiplyList(register intp *l1, register int n) \n{\n\tregister intp s=1;\n while (n--) s *= (*l1++);\n return s;\n}\n\n/*MULTIARRAY_API\n Produce a pointer into array\n*/\nstatic char *\nPyArray_GetPtr(PyArrayObject *obj, register intp* ind)\n{\n\tregister int n = obj->nd;\n\tregister intp *strides = obj->strides;\n\tregister char *dptr = obj->data;\n\t\n\twhile (n--) dptr += (*strides++) * (*ind++);\n\treturn dptr;\n}\n\n/*MULTIARRAY_API\n Get axis from an object (possibly None) -- a converter function,\n*/\nstatic int \nPyArray_AxisConverter(PyObject *obj, int *axis)\n{\n\tif (obj == Py_None) {\n\t\t*axis = MAX_DIMS;\n\t}\n\telse {\n\t\t*axis = (int) PyInt_AsLong(obj);\n\t\tif (PyErr_Occurred()) {\n\t\t\treturn PY_FAIL;\n\t\t}\n\t}\n\treturn PY_SUCCEED;\n}\n\n/*MULTIARRAY_API\n Compare Lists\n*/\nstatic int \nPyArray_CompareLists(intp *l1, intp *l2, int n) \n{\n int i;\n for(i=0;iob_type;\n\t\n\tPy_INCREF(self->descr);\n\tnew = PyArray_NewFromDescr(subtype,\n\t\t\t\t self->descr,\n\t\t\t\t self->nd, self->dimensions,\n\t\t\t\t self->strides,\n\t\t\t\t self->data,\n\t\t\t\t self->flags, (PyObject *)self);\n\t\n\tif (new==NULL) return NULL;\n\tPy_INCREF(self);\n PyArray_BASE(new) = (PyObject *)self;\n\t\n\tif (type != NULL) {\n\t\tif (PyObject_SetAttrString(new, \"dtype\",\n\t\t\t\t\t (PyObject *)type) < 0) {\n\t\t\tPy_DECREF(new);\n\t\t\tPy_DECREF(type);\n\t\t\treturn NULL;\n\t\t}\n\t\tPy_DECREF(type);\n\t}\n\treturn new;\t\n}\n\n/*MULTIARRAY_API\n Ravel\n*/\nstatic PyObject *\nPyArray_Ravel(PyArrayObject *a, int fortran)\n{\n\tPyArray_Dims newdim = {NULL,1};\n\tintp val[1] = {-1};\n\n\tif (fortran < 0) fortran = PyArray_ISFORTRAN(a);\n\n\tnewdim.ptr = val;\n\tif (!fortran && PyArray_ISCONTIGUOUS(a)) {\n\t\tif (a->nd == 1) {\n\t\t\tPy_INCREF(a);\n\t\t\treturn (PyObject *)a;\n\t\t}\n\t\treturn PyArray_Newshape(a, &newdim);\n\t}\n\telse\n\t return PyArray_Flatten(a, fortran);\n}\n\n/*MULTIARRAY_API\n Flatten\n*/\nstatic PyObject *\nPyArray_Flatten(PyArrayObject *a, int fortran)\n{\n\tPyObject *ret, *new;\n\tintp size;\n\n\tif (fortran < 0) fortran = PyArray_ISFORTRAN(a);\n\n\tsize = PyArray_SIZE(a);\n\tPy_INCREF(a->descr);\n\tret = PyArray_NewFromDescr(a->ob_type,\n\t\t\t\t a->descr,\n\t\t\t\t 1, &size,\n\t\t\t\t NULL,\n\t\t\t\t NULL,\n\t\t\t\t 0, (PyObject *)a);\n\t\n\tif (ret== NULL) return NULL;\n\tif (fortran) {\n\t\tnew = PyArray_Transpose(a, NULL);\n\t\tif (new == NULL) {\n\t\t\tPy_DECREF(ret);\n\t\t\treturn NULL;\n\t\t}\n\t}\n\telse {\n\t\tPy_INCREF(a);\n\t\tnew = (PyObject *)a;\n\t}\n\tif (PyArray_CopyInto((PyArrayObject *)ret, (PyArrayObject *)new) < 0) {\n\t\tPy_DECREF(ret);\n\t\tPy_DECREF(new);\n\t\treturn NULL;\n\t}\n\tPy_DECREF(new);\n\treturn ret;\n}\n\n\n/* For back-ward compatability *\n\n/ * Not recommended */\n\n/*MULTIARRAY_API\n Reshape an array\n*/\nstatic PyObject *\nPyArray_Reshape(PyArrayObject *self, PyObject *shape) \n{\n PyObject *ret;\n PyArray_Dims newdims;\n\n if (!PyArray_IntpConverter(shape, &newdims)) return NULL;\n ret = PyArray_Newshape(self, &newdims);\n PyDimMem_FREE(newdims.ptr);\n return ret;\n}\n\nstatic int\n_check_ones(PyArrayObject *self, int newnd, intp* newdims, intp *strides)\n{\n\tint nd;\n\tintp *dims;\n\tBool done=FALSE;\n\tint j, k;\n\n\tnd = self->nd;\n\tdims = self->dimensions;\n\n\tfor (k=0, j=0; !done && (jstrides[j];\n\t\t\tj++; k++;\n\t\t}\n\t\telse if ((kptr;\n PyArrayObject *ret;\n\tchar msg[] = \"total size of new array must be unchanged\";\n\tint n = newdims->len;\n Bool same;\n\tintp *strides = NULL;\n\tintp newstrides[MAX_DIMS];\n\n /* Quick check to make sure anything needs to be done */\n if (n == self->nd) {\n same = TRUE;\n i=0;\n while(same && i= 0) {\n\t\t\tif ((s_known == 0) || (s_original % s_known != 0)) {\n\t\t\t\tPyErr_SetString(PyExc_ValueError, msg);\n\t\t\t\treturn NULL;\n\t\t\t}\n\t\t\tdimensions[i_unknown] = s_original/s_known;\n\t\t} else {\n\t\t\tif (s_original != s_known) {\n\t\t\t\tPyErr_SetString(PyExc_ValueError, msg);\n\t\t\t\treturn NULL;\n\t\t\t}\n\t\t}\n\t}\n \n\tPy_INCREF(self->descr);\n\tret = (PyAO *)PyArray_NewFromDescr(self->ob_type,\n\t\t\t\t\t self->descr,\n\t\t\t\t\t n, dimensions,\n\t\t\t\t\t strides,\n\t\t\t\t\t self->data,\n\t\t\t\t\t self->flags, (PyObject *)self);\n\t\n\tif (ret== NULL) return NULL;\n\t\n Py_INCREF(self);\n ret->base = (PyObject *)self;\n\tPyArray_UpdateFlags(ret, CONTIGUOUS | FORTRAN);\n\t\n return (PyObject *)ret;\n}\n\n/* return a new view of the array object with all of its unit-length \n dimensions squeezed out if needed, otherwise\n return the same array.\n */\n\n/*MULTIARRAY_API*/\nstatic PyObject *\nPyArray_Squeeze(PyArrayObject *self)\n{\n\tint nd = self->nd;\n\tint newnd = nd;\n\tintp dimensions[MAX_DIMS];\n\tintp strides[MAX_DIMS];\n\tint i,j;\n\tPyObject *ret;\n\n\tif (nd == 0) {\n\t\tPy_INCREF(self);\n\t\treturn (PyObject *)self;\n\t}\n\tfor (j=0, i=0; idimensions[i] == 1) {\n\t\t\tnewnd -= 1;\n\t\t}\n\t\telse {\n\t\t\tdimensions[j] = self->dimensions[i];\n\t\t\tstrides[j++] = self->strides[i];\n\t\t}\n\t}\n\t\n\tPy_INCREF(self->descr);\n\tret = PyArray_NewFromDescr(self->ob_type, \n\t\t\t\t self->descr,\n\t\t\t\t newnd, dimensions, \n\t\t\t\t strides, self->data, \n\t\t\t\t self->flags,\n\t\t\t\t (PyObject *)self);\n\tif (ret == NULL) return NULL;\n\tPyArray_FLAGS(ret) &= ~OWN_DATA;\n\tPyArray_BASE(ret) = (PyObject *)self;\n\tPy_INCREF(self);\n\treturn (PyObject *)ret;\n}\n\n\n/*MULTIARRAY_API\n Mean\n*/\nstatic PyObject *\nPyArray_Mean(PyArrayObject *self, int axis, int rtype)\n{\n\tPyObject *obj1=NULL, *obj2=NULL;\n\tPyObject *new, *ret;\n\n\tif ((new = _check_axis(self, &axis, 0))==NULL) return NULL;\n\n\tobj1 = PyArray_GenericReduceFunction((PyAO *)new, n_ops.add, axis,\n\t\t\t\t\t rtype);\n\tobj2 = PyFloat_FromDouble((double) PyArray_DIM(new,axis));\n Py_DECREF(new);\n\tif (obj1 == NULL || obj2 == NULL) {\n\t\tPy_XDECREF(obj1);\n\t\tPy_XDECREF(obj2);\n\t\treturn NULL;\n\t}\n\n\tret = PyNumber_Divide(obj1, obj2);\n\tPy_DECREF(obj1);\n\tPy_DECREF(obj2);\n\treturn ret;\n}\n\n/* Set variance to 1 to by-pass square-root calculation and return variance */\n/*MULTIARRAY_API\n Std\n*/\nstatic PyObject *\nPyArray_Std(PyArrayObject *self, int axis, int rtype, int variance)\n{\n\tPyObject *obj1=NULL, *obj2=NULL, *new=NULL;\n\tPyObject *ret=NULL, *newshape=NULL;\n\tint i, n;\n\tintp val;\n\n\tif ((new = _check_axis(self, &axis, 0))==NULL) return NULL;\n\t\n\t/* Compute and reshape mean */\n\tobj1 = PyArray_EnsureArray(PyArray_Mean((PyAO *)new, axis, rtype));\n\tif (obj1 == NULL) {Py_DECREF(new); return NULL;} \n\tn = PyArray_NDIM(new);\n\tnewshape = PyTuple_New(n);\n\tif (newshape == NULL) {Py_DECREF(obj1); Py_DECREF(new); return NULL;}\n\tfor (i=0; ind != 1) {\n Py_DECREF(cond);\n PyErr_SetString(PyExc_ValueError, \n\t\t\t\t\"condition must be 1-d array\");\n return NULL;\n }\n\n res = PyArray_Nonzero(cond);\n Py_DECREF(cond);\n\tret = PyArray_Take(self, res, axis);\n\tPy_DECREF(res);\n\treturn ret;\n}\n\n/*MULTIARRAY_API\n Nonzero\n*/\nstatic PyObject *\nPyArray_Nonzero(PyArrayObject *self)\n{\n int n=self->nd, j;\n\tintp count=0, i, size;\n\tPyArrayIterObject *it=NULL;\n\tPyObject *ret=NULL, *item;\n\tintp *dptr[MAX_DIMS];\n\n\tit = (PyArrayIterObject *)PyArray_IterNew((PyObject *)self);\n\tif (it==NULL) return NULL;\n\n\tsize = it->size;\n\tfor (i=0; idescr->f->nonzero(it->dataptr, self)) count++;\n\t\tPyArray_ITER_NEXT(it);\n\t}\n\n\tPyArray_ITER_RESET(it);\n\tif (n==1) {\n\t\tret = PyArray_New(self->ob_type, 1, &count, PyArray_INTP, \n\t\t\t\t NULL, NULL, 0, 0, (PyObject *)self);\n\t\tif (ret == NULL) goto fail;\n\t\tdptr[0] = (intp *)PyArray_DATA(ret);\n\t\t\n\t\tfor (i=0; idescr->f->nonzero(it->dataptr, self)) \n\t\t\t\t*(dptr[0])++ = i;\n\t\t\tPyArray_ITER_NEXT(it);\n\t\t}\t\t\n\t}\n\telse {\n\t\tret = PyTuple_New(n);\n\t\tfor (j=0; job_type, 1, &count, \n\t\t\t\t\t PyArray_INTP, NULL, NULL, 0, 0,\n\t\t\t\t\t (PyObject *)self);\n\t\t\tif (item == NULL) goto fail;\n\t\t\tPyTuple_SET_ITEM(ret, j, item);\n\t\t\tdptr[j] = (intp *)PyArray_DATA(item);\n\t\t}\n\t\t\n\t\t/* reset contiguous so that coordinates gets updated */\n\t\tit->contiguous = 0;\n\t\tfor (i=0; idescr->f->nonzero(it->dataptr, self)) \n\t\t\t\tfor (j=0; jcoordinates[j];\n\t\t\tPyArray_ITER_NEXT(it);\n\t\t}\n\t}\n\n\tPy_DECREF(it);\n\treturn ret;\n\n fail:\n\tPy_XDECREF(ret);\n\tPy_XDECREF(it);\n\treturn NULL;\n \n}\n\n/*MULTIARRAY_API\n Clip\n*/\nstatic PyObject *\nPyArray_Clip(PyArrayObject *self, PyObject *min, PyObject *max)\n{\n\tPyObject *selector=NULL, *newtup=NULL, *ret=NULL;\n\tPyObject *res1=NULL, *res2=NULL, *res3=NULL;\n\tPyObject *two;\n\n\ttwo = PyInt_FromLong((long)2);\n\tres1 = PyArray_GenericBinaryFunction(self, max, n_ops.greater);\n\tres2 = PyArray_GenericBinaryFunction(self, min, n_ops.less);\n\tif ((res1 == NULL) || (res2 == NULL)) {\n\t\tPy_DECREF(two);\n\t\tPy_XDECREF(res1);\n\t\tPy_XDECREF(res2);\n\t}\n\tres3 = PyNumber_Multiply(two, res1);\n\tPy_DECREF(two); \n\tPy_DECREF(res1); \n\tif (res3 == NULL) return NULL;\n\n\tselector = PyArray_EnsureArray(PyNumber_Add(res2, res3));\n\tPy_DECREF(res2);\n\tPy_DECREF(res3);\n\tif (selector == NULL) return NULL;\n\n\tnewtup = Py_BuildValue(\"(OOO)\", (PyObject *)self, min, max);\n\tif (newtup == NULL) {Py_DECREF(selector); return NULL;}\n\tret = PyArray_Choose((PyAO *)selector, newtup);\n\tPy_DECREF(selector);\n\tPy_DECREF(newtup);\n\treturn ret;\n}\n\n/*MULTIARRAY_API\n Conjugate\n*/\nstatic PyObject *\nPyArray_Conjugate(PyArrayObject *self)\n{\n\tif (PyArray_ISCOMPLEX(self)) {\n\t\tPyObject *new;\n\t\tintp size, i;\n\t\t/* Make a copy */\n\t\tnew = PyArray_NewCopy(self, -1);\n\t\tif (new==NULL) return NULL;\n\t\tsize = PyArray_SIZE(new);\n\t\tif (self->descr->type_num == PyArray_CFLOAT) {\n\t\t\tcfloat *dptr = (cfloat *) PyArray_DATA(new);\n\t\t\tfor (i=0; iimag = -dptr->imag;\n\t\t\t\tdptr++;\n\t\t\t}\n\t\t}\n\t\telse if (self->descr->type_num == PyArray_CDOUBLE) {\n\t\t\tcdouble *dptr = (cdouble *)PyArray_DATA(new);\n\t\t\tfor (i=0; iimag = -dptr->imag;\n\t\t\t\tdptr++;\n\t\t\t}\n\t\t}\n\t\telse if (self->descr->type_num == PyArray_CLONGDOUBLE) {\n\t\t\tclongdouble *dptr = (clongdouble *)PyArray_DATA(new);\n\t\t\tfor (i=0; iimag = -dptr->imag;\n\t\t\t\tdptr++;\n\t\t\t}\t\t\t\n\t\t}\t\t\n\t\treturn new;\n\t}\n\telse {\n\t\tPy_INCREF(self);\n\t\treturn (PyObject *) self;\n\t}\n}\n\n/*MULTIARRAY_API\n Trace\n*/\nstatic PyObject *\nPyArray_Trace(PyArrayObject *self, int offset, int axis1, int axis2, \nint rtype)\n{\n\tPyObject *diag=NULL, *ret=NULL;\n\n\tdiag = PyArray_Diagonal(self, offset, axis1, axis2);\n\tif (diag == NULL) return NULL;\n\tret = PyArray_GenericReduceFunction((PyAO *)diag, n_ops.add, -1, rtype);\n\tPy_DECREF(diag);\n\treturn ret;\n}\n\n/*MULTIARRAY_API\n Diagonal\n*/\nstatic PyObject *\nPyArray_Diagonal(PyArrayObject *self, int offset, int axis1, int axis2)\n{\n\tint n = self->nd;\n\tPyObject *new;\n\tPyArray_Dims newaxes;\n\tintp dims[MAX_DIMS];\n\tint i, pos;\t\n\n\tnewaxes.ptr = dims;\n\tif (n < 2) {\n\t\tPyErr_SetString(PyExc_ValueError, \n\t\t\t\t\"array.ndim must be >= 2\");\n\t\treturn NULL;\n\t}\n\tif (axis1 < 0) axis1 += n;\n\tif (axis2 < 0) axis2 += n;\n\tif ((axis1 == axis2) || (axis1 < 0) || (axis1 >= n) ||\t\\\n\t (axis2 < 0) || (axis2 >= n)) {\n\t\tPyErr_Format(PyExc_ValueError, \"axis1(=%d) and axis2(=%d) \"\\\n\t\t\t \"must be different and within range (nd=%d)\",\n\t\t\t axis1, axis2, n);\n\t\treturn NULL;\n\t}\n \n\tnewaxes.len = n;\n\t/* insert at the end */\n\tnewaxes.ptr[n-2] = axis1;\n\tnewaxes.ptr[n-1] = axis2;\n\tpos = 0;\n\tfor (i=0; idimensions[0];\n\t\tn2 = self->dimensions[1];\n\t\tstep = n2+1;\n\t\tif (offset < 0) {\n\t\t\tstart = -n2 * offset;\n\t\t\tstop = MIN(n2, n1+offset)*(n2+1) - n2*offset;\n\t\t}\n\t\telse {\n\t\t\tstart = offset;\n\t\t\tstop = MIN(n1, n2-offset)*(n2+1) + offset;\n\t\t}\n\t\t\n\t\t/* count = ceil((stop-start)/step) */\n\t\tcount = ((stop-start) / step) + (((stop-start) % step) != 0);\n\t\t\t\n\t\tindices = PyArray_New(&PyArray_Type, 1, &count, \n\t\t\t\t PyArray_INTP, NULL, NULL, 0, 0, NULL);\n\t\tif (indices == NULL) {\n\t\t\tPy_DECREF(self); return NULL;\n\t\t}\n\t\tdptr = (intp *)PyArray_DATA(indices);\n\t\tfor (n1=start; n1descr;\n\n\t\tmydiagonal = PyList_New(0);\n\t\tif (mydiagonal == NULL) {Py_DECREF(self); return NULL;}\n\t\tn1 = self->dimensions[0];\n\t\tfor (i=0; i 3)) {\n\t\tPyErr_SetString(PyExc_ValueError,\n\t\t\t\t\"C arrays of only 1-3 dimensions available\");\n\t\tPy_XDECREF(typedescr);\n\t\treturn -1;\n\t}\n\tif ((ap = (PyArrayObject*)PyArray_FromAny(*op, typedescr, nd, nd,\n\t\t\t\t\t\t CARRAY_FLAGS, NULL)) == NULL)\n\t\treturn -1;\n\tswitch(nd) {\n\tcase 1:\n\t\t*((char **)ptr) = ap->data;\n\t\tbreak;\n\tcase 2:\n\t\tn = ap->dimensions[0];\n\t\tptr2 = (char **)_pya_malloc(n * sizeof(char *));\n\t\tif (!ptr2) goto fail;\n\t\tfor (i=0; idata + i*ap->strides[0];\n\t\t}\n\t\t*((char ***)ptr) = ptr2;\n\t\tbreak;\t\t\n\tcase 3:\n\t\tn = ap->dimensions[0];\n\t\tm = ap->dimensions[1];\n\t\tptr3 = (char ***)_pya_malloc(n*(m+1) * sizeof(char *));\n\t\tif (!ptr3) goto fail;\n\t\tfor (i=0; idata + i*ap->strides[0] + \\\n\t\t\t\t\tj*ap->strides[1];\n\t\t\t}\n\t\t}\n\t\t*((char ****)ptr) = ptr3;\n\t}\n\tmemcpy(dims, ap->dimensions, nd*sizeof(intp));\n\t*op = (PyObject *)ap;\n\treturn 0;\n\n fail:\n\tPyErr_SetString(PyExc_MemoryError, \"no memory\");\n\treturn -1;\n}\n\n/* Deprecated --- Use PyArray_AsCArray instead */\n\n/*MULTIARRAY_API\n Convert to a 1D C-array\n*/\nstatic int \nPyArray_As1D(PyObject **op, char **ptr, int *d1, int typecode) \n{\n\tintp newd1;\n\tPyArray_Descr *descr;\n\n\tdescr = PyArray_DescrFromType(typecode);\t\n\tif (PyArray_AsCArray(op, (void *)ptr, &newd1, 1, descr) == -1)\n\t\treturn -1;\t\n\t*d1 = (int) newd1;\n\treturn 0;\n}\n\n/*MULTIARRAY_API\n Convert to a 2D C-array\n*/\nstatic int \nPyArray_As2D(PyObject **op, char ***ptr, int *d1, int *d2, int typecode) \n{\n\tintp newdims[2];\n\tPyArray_Descr *descr;\n\n\tdescr = PyArray_DescrFromType(typecode);\t\n\tif (PyArray_AsCArray(op, (void *)ptr, newdims, 2, descr) == -1)\n\t\treturn -1;\n\n\t*d1 = (int ) newdims[0];\n\t*d2 = (int ) newdims[1];\n return 0;\n}\n\n/* End Deprecated */\n\n/*MULTIARRAY_API\n Free pointers created if As2D is called\n*/\nstatic int \nPyArray_Free(PyObject *op, void *ptr) \n{\n PyArrayObject *ap = (PyArrayObject *)op;\n\t\n if ((ap->nd < 1) || (ap->nd > 3)) \n\t\treturn -1;\n if (ap->nd >= 2) {\n\t\t_pya_free(ptr);\n }\n Py_DECREF(ap);\n return 0;\n}\n\n\nstatic PyObject *\n_swap_and_concat(PyObject *op, int axis, int n)\n{\n\tPyObject *newtup=NULL;\n\tPyObject *otmp, *arr;\n\tint i;\n\n\tnewtup = PyTuple_New(n);\n\tif (newtup==NULL) return NULL;\n\tfor (i=0; i= MAX_DIMS) {\n\t\t\totmp = PyArray_Ravel(mps[i],0);\n\t\t\tPy_DECREF(mps[i]);\n\t\t\tmps[i] = (PyArrayObject *)otmp;\n\t\t}\n\t\tif (mps[i]->ob_type != subtype) {\n\t\t\tprior2 = PyArray_GetPriority((PyObject *)(mps[i]), 0.0);\n\t\t\tif (prior2 > prior1) {\n\t\t\t\tprior1 = prior2;\n\t\t\t\tsubtype = mps[i]->ob_type;\n\t\t\t\tret = mps[i];\n\t\t\t}\n\t\t}\n\t}\n\t\n\tnew_dim = 0;\n\tfor(i=0; ind;\n\t\telse {\n\t\t\tif (nd != mps[i]->nd) {\n\t\t\t\tPyErr_SetString(PyExc_ValueError, \n\t\t\t\t\t\t\"arrays must have same \"\\\n\t\t\t\t\t\t\"number of dimensions\");\n\t\t\t\tgoto fail;\n\t\t\t}\n\t\t\tif (!PyArray_CompareLists(mps[0]->dimensions+1, \n\t\t\t\t\t\t mps[i]->dimensions+1, \n\t\t\t\t\t\t nd-1)) {\n\t\t\t\tPyErr_SetString(PyExc_ValueError, \n\t\t\t\t\t\t\"array dimensions must \"\\\n\t\t\t\t\t\t\"agree except for d_0\");\n\t\t\t\tgoto fail;\n\t\t\t}\n\t\t}\n\t\tif (nd == 0) {\n\t\t\tPyErr_SetString(PyExc_ValueError, \n\t\t\t\t\t\"0-d arrays can't be concatenated\");\n\t\t\tgoto fail;\n\t\t}\n\t\tnew_dim += mps[i]->dimensions[0];\n\t}\n\t\n\ttmp = mps[0]->dimensions[0];\n\tmps[0]->dimensions[0] = new_dim;\n\tPy_INCREF(mps[0]->descr);\n\tret = (PyArrayObject *)PyArray_NewFromDescr(subtype, \n\t\t\t\t\t\t mps[0]->descr, nd,\n\t\t\t\t\t\t mps[0]->dimensions, \n\t\t\t\t\t\t NULL, NULL, 0,\n\t\t\t\t\t\t (PyObject *)ret);\n\tmps[0]->dimensions[0] = tmp;\n\t\n\tif (ret == NULL) goto fail;\n\t\n\tdata = ret->data;\n\tfor(i=0; idata, numbytes);\n\t\tdata += numbytes;\n\t}\n\t\n\tPyArray_INCREF(ret);\n\tfor(i=0; ind;\n\tif (n <= 1) {\n\t\tPy_INCREF(ap);\n\t\treturn (PyObject *)ap;\n\t}\n\n\tif (a1 < 0) a1 += n;\n\tif (a2 < 0) a2 += n;\n\tif ((a1 < 0) || (a1 >= n)) {\n\t\tPyErr_SetString(PyExc_ValueError, \n\t\t\t\t\"bad axis1 argument to swapaxes\");\n\t\treturn NULL;\n\t}\n\tif ((a2 < 0) || (a2 >= n)) {\n\t\tPyErr_SetString(PyExc_ValueError, \n\t\t\t\t\"bad axis2 argument to swapaxes\");\n\t\treturn NULL;\n\t}\n\tnew_axes.ptr = dims;\n\tnew_axes.len = n;\n\n\tfor (i=0; ind;\n\t\tfor(i=0; ilen;\n\t\taxes = permute->ptr;\n\t\tif (n > ap->nd) {\n\t\t\tPyErr_SetString(PyExc_ValueError, \n\t\t\t\t\t\"too many axes for this array\");\n\t\t\treturn NULL;\n\t\t}\n\t\tfor(i=0; ind+axis;\n\t\t\tif (axis < 0 || axis >= ap->nd) {\n\t\t\t\tPyErr_SetString(PyExc_ValueError, \n\t\t\t\t\t\t\"invalid axis for this array\");\n\t\t\t\treturn NULL;\n\t\t\t}\n\t\t\tpermutation[i] = axis;\n\t\t}\n\t}\n\t\n\t/* this allocates memory for dimensions and strides (but fills them\n\t incorrectly), sets up descr, and points data at ap->data. */\n\tPy_INCREF(ap->descr);\n\tret = (PyArrayObject *)\\\n\t\tPyArray_NewFromDescr(ap->ob_type, \n\t\t\t\t ap->descr, \n\t\t\t\t n, permutation, \n\t\t\t\t NULL, ap->data, ap->flags,\n\t\t\t\t (PyObject *)ap);\n\tif (ret == NULL) return NULL;\n\t\n\t/* point at true owner of memory: */\n\tret->base = (PyObject *)ap;\n\tPy_INCREF(ap);\n\t\n\tfor(i=0; idimensions[i] = ap->dimensions[permutation[i]];\n\t\tret->strides[i] = ap->strides[permutation[i]];\n\t}\n\tPyArray_UpdateFlags(ret, CONTIGUOUS | FORTRAN);\t\n\n\treturn (PyObject *)ret;\t\n}\n\n/*MULTIARRAY_API\n Repeat the array.\n*/\nstatic PyObject *\nPyArray_Repeat(PyArrayObject *aop, PyObject *op, int axis)\n{\n\tintp *counts;\n\tintp n, n_outer, i, j, k, chunk, total;\n\tintp tmp;\n\tint nd;\n\tPyArrayObject *repeats=NULL;\n\tPyObject *ap=NULL;\n\tPyArrayObject *ret=NULL;\n\tchar *new_data, *old_data;\n\n\trepeats = (PyAO *)PyArray_ContiguousFromAny(op, PyArray_INTP, 0, 1);\n\tif (repeats == NULL) return NULL;\n\tnd = repeats->nd;\n\tcounts = (intp *)repeats->data;\n\n\tif ((ap=_check_axis(aop, &axis, CARRAY_FLAGS))==NULL) {\n\t\tPy_DECREF(repeats);\n\t\treturn NULL;\n\t}\n\n\taop = (PyAO *)ap;\n\n\tif (nd == 1)\n\t\tn = repeats->dimensions[0];\n\telse /* nd == 0 */\n\t\tn = aop->dimensions[axis];\n\n\tif (aop->dimensions[axis] != n) {\n\t\tPyErr_SetString(PyExc_ValueError, \n\t\t\t\t\"a.shape[axis] != len(repeats)\");\n\t\tgoto fail;\n\t}\n\n\t\n\tif (nd == 0) \n\t\ttotal = counts[0]*n;\n\telse {\n\t\t\n\t\ttotal = 0;\n\t\tfor(j=0; jdimensions[axis] = total;\n\tPy_INCREF(aop->descr);\n\tret = (PyArrayObject *)PyArray_NewFromDescr(aop->ob_type, \n\t\t\t\t\t\t aop->descr,\n\t\t\t\t\t\t aop->nd,\n\t\t\t\t\t\t aop->dimensions,\n\t\t\t\t\t\t NULL, NULL, 0,\n\t\t\t\t\t\t (PyObject *)aop);\n\taop->dimensions[axis] = n;\n\t\n\tif (ret == NULL) goto fail;\n\t\n\tnew_data = ret->data;\n\told_data = aop->data;\n\t\n\tchunk = aop->descr->elsize;\n\tfor(i=axis+1; ind; i++) {\n\t\tchunk *= aop->dimensions[i];\n\t}\n\t\n\tn_outer = 1;\n\tfor(i=0; idimensions[i];\n\n\tfor(i=0; ind < mps[i]->nd) {\n\t\t\tPyErr_SetString(PyExc_ValueError, \n\t\t\t\t\t\"too many dimensions\");\n\t\t\tgoto fail;\n\t\t}\n\t\tif (!PyArray_CompareLists(ap->dimensions+(ap->nd-mps[i]->nd),\n\t\t\t\t mps[i]->dimensions, mps[i]->nd)) {\n\t\t\tPyErr_SetString(PyExc_ValueError, \n\t\t\t\t\t\"array dimensions must agree\");\n\t\t\tgoto fail;\n\t\t}\n\t\tsizes[i] = PyArray_NBYTES(mps[i]);\n\t}\n\t\n\tPy_INCREF(mps[0]->descr);\n\tret = (PyArrayObject *)PyArray_NewFromDescr(ap->ob_type, \n\t\t\t\t\t\t mps[0]->descr,\n\t\t\t\t\t\t ap->nd,\n\t\t\t\t\t\t ap->dimensions, \n\t\t\t\t\t\t NULL, NULL, 0,\n\t\t\t\t\t\t (PyObject *)ap);\n\tif (ret == NULL) goto fail;\n\t\n\telsize = ret->descr->elsize;\n\tm = PyArray_SIZE(ret);\n\tself_data = (intp *)ap->data;\n\tret_data = ret->data;\n\t\n\tfor (i=0; i= n) {\n\t\t\tPyErr_SetString(PyExc_ValueError, \n\t\t\t\t\t\"invalid entry in choice array\");\n\t\t\tgoto fail;\n\t\t}\n\t\toffset = i*elsize;\n\t\tif (offset >= sizes[mi]) {offset = offset % sizes[mi]; }\n\t\tmemmove(ret_data, mps[mi]->data+offset, elsize);\n\t\tret_data += elsize; self_data++;\n\t}\n\t\n\tPyArray_INCREF(ret);\n\tfor(i=0; idescr->f->sort[which];\n\tsize = it->size;\n\tN = op->dimensions[axis];\n\telsize = op->descr->elsize;\n\tastride = op->strides[axis];\n\n\tneedcopy = !(op->flags & ALIGNED) || (astride != (intp) elsize);\n\n\tif (needcopy) {\n\t\tchar *buffer;\n\t\tbuffer = PyDataMem_NEW(N*elsize);\n\t\twhile (size--) {\n\t\t\t_strided_copy(buffer, (intp) elsize, it->dataptr, \n\t\t\t\t astride, N, elsize);\n\t\t\tif (sort(buffer, N, op) < 0) {\n\t\t\t\tPyDataMem_FREE(buffer); goto fail;\n\t\t\t}\n\t\t\t_strided_copy(it->dataptr, astride, buffer, \n\t\t\t\t (intp) elsize, N, elsize);\n\t\t\tPyArray_ITER_NEXT(it);\n\t\t}\n\t\tPyDataMem_FREE(buffer);\n\t}\n\telse {\n\t\twhile (size--) {\n\t\t\tif (sort(it->dataptr, N, op) < 0) goto fail;\n\t\t\tPyArray_ITER_NEXT(it);\n\t\t}\n\t}\t\n\t\n\tEND_THREADS\n\t\n\tPy_DECREF(it);\n\treturn 0;\n\n fail:\n\tEND_THREADS\n\n\tPy_DECREF(it);\n\treturn 0;\n}\n\nstatic PyObject*\n_new_argsort(PyArrayObject *op, int axis, PyArray_SORTKIND which) \n{\n\n\tPyArrayIterObject *it=NULL;\n\tPyArrayIterObject *rit=NULL;\n\tPyObject *ret;\n\tint needcopy=0, i;\n\tintp N, size;\n\tint elsize;\n\tintp astride, rstride, *iptr;\n\tPyArray_ArgSortFunc *argsort;\n\tBEGIN_THREADS_DEF \n\n\tret = PyArray_New(op->ob_type, op->nd,\n\t\t\t op->dimensions, PyArray_INTP,\n\t\t\t NULL, NULL, 0, 0, (PyObject *)op);\n\tif (ret == NULL) return NULL;\n\n\tit = (PyArrayIterObject *)PyArray_IterAllButAxis((PyObject *)op, axis);\n\trit = (PyArrayIterObject *)PyArray_IterAllButAxis(ret, axis);\n\tif (rit == NULL || it == NULL) goto fail;\n\n\tBEGIN_THREADS\n\n\targsort = op->descr->f->argsort[which];\n\tsize = it->size;\n\tN = op->dimensions[axis];\n\telsize = op->descr->elsize;\n\tastride = op->strides[axis];\n\trstride = PyArray_STRIDE(ret,axis);\n\n\tneedcopy = !(op->flags & ALIGNED) || (astride != (intp) elsize) || \\\n\t\t(rstride != sizeof(intp));\n\t\n\tif (needcopy) {\n\t\tchar *valbuffer, *indbuffer;\n\t\tvalbuffer = PyDataMem_NEW(N*(elsize+sizeof(intp)));\n\t\tindbuffer = valbuffer + (N*elsize);\n\t\twhile (size--) {\n\t\t\t_strided_copy(valbuffer, (intp) elsize, it->dataptr,\n\t\t\t\t astride, N, elsize);\n\t\t\tiptr = (intp *)indbuffer;\n\t\t\tfor (i=0; idataptr, rstride, indbuffer, \n\t\t\t\t sizeof(intp), N, sizeof(intp));\n\t\t\tPyArray_ITER_NEXT(it);\n\t\t\tPyArray_ITER_NEXT(rit);\n\t\t}\n\t\tPyDataMem_FREE(valbuffer);\n\t}\n\telse {\n\t\twhile (size--) {\n\t\t\tiptr = (intp *)rit->dataptr;\n\t\t\tfor (i=0; idataptr, (intp *)rit->dataptr, \n\t\t\t\t N, op) < 0) goto fail;\n\t\t\tPyArray_ITER_NEXT(it);\n\t\t\tPyArray_ITER_NEXT(rit);\n\t\t}\n\t}\n\t\n\tEND_THREADS\n\n\tPy_DECREF(it);\n\tPy_DECREF(rit);\n\treturn ret;\n\n fail:\n\n\tEND_THREADS\n\n\tPy_DECREF(ret);\n\tPy_XDECREF(it);\n\tPy_XDECREF(rit);\n\treturn NULL;\n}\n\n\n/* Be sure to save this global_compare when necessary */\n\nstatic PyArrayObject *global_obj;\n\nstatic int \nqsortCompare (const void *a, const void *b) \n{\n\treturn global_obj->descr->f->compare(a,b,global_obj);\n}\n\n/* Consumes reference to ap (op gets it)\n op contains a version of the array with axes swapped if\n local variable axis is not the last dimension.\n orign must be defined locally. \n*/\n\n#define SWAPAXES(op, ap) {\t\t\t\t\t\t\\\n\t\torign = (ap)->nd-1;\t\t\t\t\t\\\n\t\tif (axis != orign) {\t\t\t\t\t\\\n\t\t\t(op) = (PyAO *)PyArray_SwapAxes((ap), axis, orign); \\\n\t\t\tPy_DECREF((ap));\t\t\t\t\\\n\t\t\tif ((op) == NULL) return NULL;\t\t\t\\\n\t\t}\t\t\t\t\t\t\t\\\n\t\telse (op) = (ap);\t\t\t\t\t\\\n\t}\n\n/* Consumes reference to ap (op gets it)\n origin must be previously defined locally. \n SWAPAXES must have been called previously. \n op contains the swapped version of the array. \n*/\n#define SWAPBACK(op, ap) {\t \\\n\t\tif (axis != orign) { \\\n\t\t\t(op) = (PyAO *)PyArray_SwapAxes((ap), axis, orign); \\\n\t\t\tPy_DECREF((ap));\t\t\t\t\\\n\t\t\tif ((op) == NULL) return NULL;\t\t\t\\\n\t\t}\t\t\t\t\t\t\t\\\n\t\telse (op) = (ap);\t\t\t\t\t\\\n\t}\n\n/* These swap axes in-place if necessary */\n#define SWAPINTP(a,b) {intp c; c=(a); (a) = (b); (b) = c;}\n#define SWAPAXES2(ap) {\t\t\t\t\t\t\\\n\t\torign = (ap)->nd-1;\t\t\t\t\t\\\n\t\tif (axis != orign) {\t\t\t\t\t\\\n\t\t\tSWAPINTP(ap->dimensions[axis], ap->dimensions[orign]); \\\n\t\t\tSWAPINTP(ap->strides[axis], ap->strides[orign]); \\\n\t\t\tPyArray_UpdateFlags(ap, CONTIGUOUS | FORTRAN); \\\n\t\t}\t\t\t\t\t\t \\\n\t}\n\n#define SWAPBACK2(ap) {\t\t \\\n\t\tif (axis != orign) {\t\t\t\t\t\\\n\t\t\tSWAPINTP(ap->dimensions[axis], ap->dimensions[orign]); \\\n\t\t\tSWAPINTP(ap->strides[axis], ap->strides[orign]); \\\n\t\t\tPyArray_UpdateFlags(ap, CONTIGUOUS | FORTRAN);\t\\\n\t\t}\t\t\t\t\t\t\t\\\n\t}\n\n/*MULTIARRAY_API\n Sort an array in-place\n*/\nstatic int\nPyArray_Sort(PyArrayObject *op, int axis, PyArray_SORTKIND which) \n{\n\tPyArrayObject *ap=NULL, *store_arr=NULL;\n\tchar *ip;\n\tint i, n, m, elsize, orign;\n\n\tn = op->nd;\n\tif ((n==0) || (PyArray_SIZE(op)==1)) return 0;\n\n\tif (axis < 0) axis += n;\n\tif ((axis < 0) || (axis >= n)) {\n\t\tPyErr_Format(PyExc_ValueError, \n\t\t\t \"axis(=%d) out of bounds\", axis);\n\t\treturn -1;\n\t}\n\tif (!PyArray_ISWRITEABLE(op)) {\n\t\tPyErr_SetString(PyExc_RuntimeError, \n\t\t\t\t\"attempted sort on unwriteable array.\");\n\t\treturn -1;\n\t}\n\n\t/* Determine if we should use type-specific algorithm or not */\n\tif (op->descr->f->sort[which] != NULL) {\n\t\treturn _new_sort(op, axis, which);\n\t}\n\n\tif ((which != PyArray_QUICKSORT) || \\\n\t op->descr->f->compare == NULL) {\n\t\tPyErr_SetString(PyExc_TypeError, \n\t\t\t\t\"desired sort not supported for this type\");\n\t\treturn -1;\n\t}\n\n\tSWAPAXES2(op);\n\n ap = (PyArrayObject *)PyArray_FromAny((PyObject *)op, \n\t\t\t\t\t NULL, 1, 0, \n\t\t\t\t\t DEFAULT_FLAGS | UPDATEIFCOPY, NULL);\t\n\tif (ap == NULL) goto fail;\n\t\n\telsize = ap->descr->elsize;\n\tm = ap->dimensions[ap->nd-1];\n\tif (m == 0) goto finish;\n\n\tn = PyArray_SIZE(ap)/m;\n\n\t/* Store global -- allows re-entry -- restore before leaving*/\n\tstore_arr = global_obj; \n\tglobal_obj = ap;\n\t\n\tfor (ip=ap->data, i=0; idescr->elsize;\n\tconst intp *ipa = ip1;\n\tconst intp *ipb = ip2;\t\n\treturn global_obj->descr->f->compare(global_data + (isize * *ipa),\n global_data + (isize * *ipb), \n\t\t\t\t\t global_obj);\n}\n\n/*MULTIARRAY_API\n ArgSort an array\n*/\nstatic PyObject *\nPyArray_ArgSort(PyArrayObject *op, int axis, PyArray_SORTKIND which) \n{\n\tPyArrayObject *ap=NULL, *ret=NULL, *store;\n\tintp *ip;\n\tintp i, j, n, m, orign;\n\tint argsort_elsize;\n\tchar *store_ptr;\n\n\tn = op->nd;\n\tif ((n==0) || (PyArray_SIZE(op)==1)) {\n\t\tret = (PyArrayObject *)PyArray_New(op->ob_type, op->nd,\n\t\t\t\t\t\t op->dimensions, \n\t\t\t\t\t\t PyArray_INTP,\n\t\t\t\t\t\t NULL, NULL, 0, 0, \n\t\t\t\t\t\t (PyObject *)op);\n\t\tif (ret == NULL) return NULL;\n\t\t*((intp *)ret->data) = 0;\n\t\treturn (PyObject *)ret;\n\t}\n\tif (axis < 0) axis += n;\n\tif ((axis < 0) || (axis >= n)) {\n\t\tPyErr_Format(PyExc_ValueError, \n\t\t\t \"axis(=%d) out of bounds\", axis);\n\t\treturn NULL;\n\t}\n\n\t/* Determine if we should use new algorithm or not */\n\tif (op->descr->f->argsort[which] != NULL) {\n\t\treturn _new_argsort(op, axis, which);\n\t}\n\n\tif ((which != PyArray_QUICKSORT) || op->descr->f->compare == NULL) {\n\t\tPyErr_SetString(PyExc_TypeError, \n\t\t\t\t\"requested sort not available for type\");\n\t\tgoto fail;\n\t}\n\n\tSWAPAXES(ap, op);\n\n\top = (PyArrayObject *)PyArray_ContiguousFromAny((PyObject *)ap, \n\t\t\t\t\t\t\t PyArray_NOTYPE,\n\t\t\t\t\t\t\t 1, 0);\n\n\tif (op == NULL) return NULL;\n\t\n\tret = (PyArrayObject *)PyArray_New(op->ob_type, op->nd,\n\t\t\t\t\t op->dimensions, PyArray_INTP,\n\t\t\t\t\t NULL, NULL, 0, 0, (PyObject *)op);\n\tif (ret == NULL) goto fail;\n\t\n\t\n\tip = (intp *)ret->data;\n\targsort_elsize = op->descr->elsize;\n\tm = op->dimensions[op->nd-1];\n\tif (m == 0) goto finish;\n\n\tn = PyArray_SIZE(op)/m;\n\tstore_ptr = global_data;\n\tglobal_data = op->data;\n\tstore = global_obj;\n\tglobal_obj = op;\n\tfor (i=0; i 0 in lexsort\");\n\t\treturn NULL;\n\t}\n\tmps = (PyArrayObject **) _pya_malloc(n*sizeof(PyArrayObject));\n\tif (mps==NULL) return PyErr_NoMemory();\n\tits = (PyArrayIterObject **) _pya_malloc(n*sizeof(PyArrayIterObject));\n\tif (its == NULL) {_pya_free(mps); return PyErr_NoMemory();}\n\tfor (i=0; i0) {\n\t\t\tif ((mps[i]->nd != mps[0]->nd) ||\t\\\n\t\t\t (!PyArray_CompareLists(mps[i]->dimensions,\n\t\t\t\t\t\t mps[0]->dimensions,\n\t\t\t\t\t\t mps[0]->nd))) {\n\t\t\t\tPyErr_SetString(PyExc_ValueError,\n\t\t\t\t\t\t\"all keys need to be the same shape\");\n\t\t\t\tgoto fail;\n\t\t\t}\n\t\t}\n\t\tif (!mps[i]->descr->f->argsort[PyArray_MERGESORT]) {\n\t\t\tPyErr_Format(PyExc_TypeError, \n\t\t\t\t \"merge sort not available for item %d\", i);\n\t\t\tgoto fail;\n\t\t}\n\t\tits[i] = (PyArrayIterObject *)PyArray_IterAllButAxis\t\\\n\t\t\t((PyObject *)mps[i], axis);\n\t\tif (its[i]==NULL) goto fail;\n\t}\n\n\t/* Now we can check the axis */\n\tnd = mps[0]->nd;\n\tif ((nd==0) || (PyArray_SIZE(mps[0])==1)) {\n\t\tret = (PyArrayObject *)PyArray_New(&PyArray_Type, mps[0]->nd,\n\t\t\t\t\t\t mps[0]->dimensions, \n\t\t\t\t\t\t PyArray_INTP,\n\t\t\t\t\t\t NULL, NULL, 0, 0, NULL);\n\t\tif (ret == NULL) return NULL;\n\t\t*((intp *)(ret->data)) = 0;\n\t\treturn (PyObject *)ret;\n\t}\n\tif (axis < 0) axis += nd;\n\tif ((axis < 0) || (axis >= nd)) {\n\t\tPyErr_Format(PyExc_ValueError, \n\t\t\t \"axis(=%d) out of bounds\", axis);\n\t\tgoto fail;\n\t}\n\n\t/* Now do the sorting */\n\n\tret = (PyArrayObject *)PyArray_New(&PyArray_Type, mps[0]->nd,\n\t\t\t\t\t mps[0]->dimensions, PyArray_INTP,\n\t\t\t\t\t NULL, NULL, 0, 0, NULL);\n\tif (ret == NULL) goto fail;\n\n\trit = (PyArrayIterObject *)\\\n\t\tPyArray_IterAllButAxis((PyObject *)ret, axis);\n\tif (rit == NULL) goto fail;\n\n\tsize = rit->size;\n\tN = mps[0]->dimensions[axis];\n\trstride = PyArray_STRIDE(ret,axis);\n\n maxelsize = mps[0]->descr->elsize;\n\tneedcopy = (rstride != sizeof(intp));\n\tfor (j=0; jflags & ALIGNED) || \\\n\t\t\t(mps[j]->strides[axis] != (intp)mps[j]->descr->elsize);\n if (mps[j]->descr->elsize > maxelsize) \n maxelsize = mps[j]->descr->elsize;\n\t}\n\n\tif (needcopy) {\n\t\tchar *valbuffer, *indbuffer;\n\t\tvalbuffer = PyDataMem_NEW(N*(maxelsize+sizeof(intp)));\n\t\tindbuffer = valbuffer + (N*maxelsize);\n\t\twhile (size--) {\n\t\t\tiptr = (intp *)indbuffer;\n\t\t\tfor (i=0; idescr->elsize;\n\t\t\t\tastride = mps[j]->strides[axis];\t\n\t\t\t\targsort = mps[j]->descr->f->argsort[PyArray_MERGESORT];\n\t\t\t\t_strided_copy(valbuffer, (intp) elsize, its[j]->dataptr,\n\t\t\t\t\t astride, N, elsize);\n\t\t\t\tif (argsort(valbuffer, (intp *)indbuffer, N, mps[j]) < 0) {\n\t\t\t\t\tPyDataMem_FREE(valbuffer); goto fail;\n\t\t\t\t}\n\t\t\t\tPyArray_ITER_NEXT(its[j]);\n\t\t\t}\n\t\t\t_strided_copy(rit->dataptr, rstride, indbuffer,\n\t\t\t\t sizeof(intp), N, sizeof(intp));\n\t\t\tPyArray_ITER_NEXT(rit);\n\t\t}\n\t\tPyDataMem_FREE(valbuffer);\n\t}\n\telse {\n\t\twhile (size--) {\n\t\t\tiptr = (intp *)rit->dataptr;\n\t\t\tfor (i=0; idescr->f->argsort[PyArray_MERGESORT];\n\t\t\t\tif (argsort(its[j]->dataptr, (intp *)rit->dataptr,\n\t\t\t\t\t N, mps[j]) < 0) goto fail;\n\t\t\t\tPyArray_ITER_NEXT(its[j]);\n\t\t\t}\n\t\t\tPyArray_ITER_NEXT(rit);\n\t\t}\n\t}\n\n\tfor (i=0; idescr->f->compare;\n\tintp min_i, max_i, i, j;\n\tint location, elsize = ap1->descr->elsize;\n\tintp elements = ap1->dimensions[ap1->nd-1];\n\tintp n = PyArray_SIZE(ap2);\n\tintp *rp = (intp *)ret->data;\n\tchar *ip = ap2->data;\n\tchar *vp = ap1->data;\n\n\tfor (j=0; j 0) {\n\t\t\t\t\tif (compare(ip, vp+elsize*(--i), ap2) \\\n\t\t\t\t\t != 0) {\n\t\t\t\t\t\ti = i+1; break;\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t\tmin_i = i;\n\t\t\t\tbreak;\n\t\t\t}\n\t\t\telse if (location < 0) {\n\t\t\t\tmax_i = i;\n\t\t\t} else {\n\t\t\t\tmin_i = i+1;\n\t\t\t}\n\t\t}\n\t\t*rp = min_i;\n\t}\n}\n\n/*MULTIARRAY_API\n Numeric.searchsorted(a,v)\n*/\nstatic PyObject *\nPyArray_SearchSorted(PyArrayObject *op1, PyObject *op2) \n{\n\tPyArrayObject *ap1=NULL, *ap2=NULL, *ret=NULL;\n\tint typenum = 0;\n\n\t/* \n PyObject *args;\n args = Py_BuildValue(\"O\",op2);\n\tPy_DELEGATE_ARGS(((PyObject *)op1), searchsorted, args);\n Py_XDECREF(args);\n\t*/\n\n\ttypenum = PyArray_ObjectType((PyObject *)op1, 0);\n\ttypenum = PyArray_ObjectType(op2, typenum);\n\tret = NULL;\n\tap1 = (PyArrayObject *)PyArray_ContiguousFromAny((PyObject *)op1, \n\t\t\t\t\t\t\t typenum, \n\t\t\t\t\t\t\t 1, 1);\n\tif (ap1 == NULL) return NULL;\n\tap2 = (PyArrayObject *)PyArray_ContiguousFromAny(op2, typenum, \n\t\t\t\t\t\t\t 0, 0);\n\tif (ap2 == NULL) goto fail;\n\t\n\tret = (PyArrayObject *)PyArray_New(ap2->ob_type, ap2->nd, \n\t\t\t\t\t ap2->dimensions, PyArray_INTP,\n\t\t\t\t\t NULL, NULL, 0, 0, (PyObject *)ap2);\n\tif (ret == NULL) goto fail;\n\n\tif (ap2->descr->f->compare == NULL) {\n\t\tPyErr_SetString(PyExc_TypeError, \n\t\t\t\t\"compare not supported for type\");\n\t\tgoto fail;\n\t}\n\t\n\tlocal_where(ap1, ap2, ret); \n\t\n\tPy_DECREF(ap1);\n\tPy_DECREF(ap2);\n\treturn (PyObject *)ret;\n\t\n fail:\n\tPy_XDECREF(ap1);\n\tPy_XDECREF(ap2);\n\tPy_XDECREF(ret);\n\treturn NULL;\n}\n\n/*\n Make a new empty array, of the passed size, of a type that takes the\n priority of ap1 and ap2 into account.\n */\nstatic PyArrayObject *\nnew_array_for_sum(PyArrayObject *ap1, PyArrayObject *ap2,\n\t\t int nd, intp dimensions[], int typenum)\n{\n\tPyArrayObject *ret;\n\tPyTypeObject *subtype;\n\tdouble prior1, prior2;\n\t/* Need to choose an output array that can hold a sum \n\t -- use priority to determine which subtype.\n\t */\n\tif (ap2->ob_type != ap1->ob_type) {\n\t\tprior2 = PyArray_GetPriority((PyObject *)ap2, 0.0);\n\t\tprior1 = PyArray_GetPriority((PyObject *)ap1, 0.0);\n\n\t\tsubtype = (prior2 > prior1 ? ap2->ob_type : ap1->ob_type);\n\t} else {\n\t\tprior1 = prior2 = 0.0;\n\t\tsubtype = ap1->ob_type;\n\t}\n\n\tret = (PyArrayObject *)PyArray_New(subtype, nd, dimensions, \n\t\t\t\t\t typenum, NULL, NULL, 0, 0, \n (PyObject *)\n\t\t\t\t\t (prior2 > prior1 ? ap2 : ap1));\n\treturn ret;\n}\n\n/* Could perhaps be redone to not make contiguous arrays \n */\n\n/*MULTIARRAY_API\n Numeric.innerproduct(a,v)\n*/\nstatic PyObject *\nPyArray_InnerProduct(PyObject *op1, PyObject *op2) \n{\n\tPyArrayObject *ap1, *ap2, *ret=NULL;\n\tintp i, j, l, i1, i2, n1, n2;\n\tint typenum, nd;\n\tintp is1, is2, os;\n\tchar *ip1, *ip2, *op;\n\tintp dimensions[MAX_DIMS];\n\tPyArray_DotFunc *dot;\n\t\n\ttypenum = PyArray_ObjectType(op1, 0); \n\ttypenum = PyArray_ObjectType(op2, typenum);\n\t\t\n\tap1 = (PyArrayObject *)PyArray_ContiguousFromAny(op1, typenum, \n\t\t\t\t\t\t\t 0, 0);\n\tif (ap1 == NULL) return NULL;\n\tap2 = (PyArrayObject *)PyArray_ContiguousFromAny(op2, typenum, \n\t\t\t\t\t\t\t 0, 0);\n\tif (ap2 == NULL) goto fail;\n\t\n\tif (ap1->nd == 0 || ap2->nd == 0) {\n\t\tret = (ap1->nd == 0 ? ap1 : ap2);\n\t\tret = (PyArrayObject *)ret->ob_type->tp_as_number->\\\n\t\t\tnb_multiply((PyObject *)ap1, (PyObject *)ap2);\n\t\tPy_DECREF(ap1);\n\t\tPy_DECREF(ap2);\n\t\treturn (PyObject *)ret;\n\t}\n\t\n\tl = ap1->dimensions[ap1->nd-1];\n\t\n\tif (ap2->dimensions[ap2->nd-1] != l) {\n\t\tPyErr_SetString(PyExc_ValueError, \"matrices are not aligned\");\n\t\tgoto fail;\n\t}\n\t\n\tif (l == 0) n1 = n2 = 0;\n\telse {\n\t\tn1 = PyArray_SIZE(ap1)/l;\n\t\tn2 = PyArray_SIZE(ap2)/l;\n\t}\n\n\tnd = ap1->nd+ap2->nd-2;\n\tj = 0;\n\tfor(i=0; ind-1; i++) {\n\t\tdimensions[j++] = ap1->dimensions[i];\n\t}\n\tfor(i=0; ind-1; i++) {\n\t\tdimensions[j++] = ap2->dimensions[i];\n\t}\n\n\n\t/* Need to choose an output array that can hold a sum \n\t -- use priority to determine which subtype.\n\t */\n\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\n\t\n\tis1 = ap1->strides[ap1->nd-1]; \n\tis2 = ap2->strides[ap2->nd-1];\n\top = ret->data; os = ret->descr->elsize;\n\t\n\tip1 = ap1->data;\n\tfor(i1=0; i1data;\n\t\tfor(i2=0; i2nd == 0 || ap2->nd == 0) {\n\t\tret = (ap1->nd == 0 ? ap1 : ap2);\n\t\tret = (PyArrayObject *)ret->ob_type->tp_as_number->\\\n\t\t\tnb_multiply((PyObject *)ap1, (PyObject *)ap2);\n\t\tPy_DECREF(ap1);\n\t\tPy_DECREF(ap2);\n\t\treturn (PyObject *)ret;\n\t}\n\t\n\tl = ap1->dimensions[ap1->nd-1];\n\tif (ap2->nd > 1) {\n\t\tmatchDim = ap2->nd - 2;\n\t\totherDim = ap2->nd - 1;\n\t}\n\telse {\n\t\tmatchDim = 0;\n\t\totherDim = 0;\n\t}\n\n\tif (ap2->dimensions[matchDim] != l) {\n\t\tPyErr_SetString(PyExc_ValueError, \"objects are not aligned\");\n\t\tgoto fail;\n\t}\n\t\n\tif (l == 0) n1 = n2 = 0;\n\telse {\n\t\tn1 = PyArray_SIZE(ap1)/l;\n\t\tn2 = PyArray_SIZE(ap2)/l;\n\t}\n\n\tnd = ap1->nd+ap2->nd-2;\n\tj = 0;\n\tfor(i=0; ind-1; i++) {\n\t\tdimensions[j++] = ap1->dimensions[i];\n\t}\n\tfor(i=0; ind-2; i++) {\n\t\tdimensions[j++] = ap2->dimensions[i];\n\t}\n\tif(ap2->nd > 1) {\n\t\tdimensions[j++] = ap2->dimensions[ap2->nd-1];\n\t}\n\t/*\n\tfprintf(stderr, \"nd=%d dimensions=\", nd);\n\t for(i=0; i 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\tis1 = ap1->strides[ap1->nd-1]; is2 = ap2->strides[matchDim];\n\tif(ap1->nd > 1)\n\t\tis1r = ap1->strides[ap1->nd-2];\n\telse\n\t\tis1r = ap1->strides[ap1->nd-1];\n\tis2r = ap2->strides[otherDim];\n\n\top = ret->data; os = ret->descr->elsize;\n\n\tip1 = ap1->data;\n\tfor(i1=0; i1data;\n\t\tfor(i2=0; i2ob_type, \n\t\t\t\t PyArray_DESCR(arr),\n\t\t\t\t 2, dims, \n\t\t\t\t NULL, NULL, 0, arr);\n\n\tif (ret == NULL) {\n\t\tPy_DECREF(arr);\n\t\treturn NULL;\n\t}\n\t/* do 2-d loop */\n\toptr = PyArray_DATA(ret);\n\tstr2 = elsize*dims[0];\n\tfor (i=0; idimensions[0];\n\tn2 = ap2->dimensions[0];\n\n\tif (n1 < n2) { \n\t\tret = ap1; ap1 = ap2; ap2 = ret; \n\t\tret = NULL; i = n1;n1=n2;n2=i;\n\t}\n\tlength = n1;\n\tn = n2;\n\tswitch(mode) {\n\tcase 0:\t\n\t\tlength = length-n+1;\n\t\tn_left = n_right = 0;\n\t\tbreak;\n\tcase 1:\n\t\tn_left = (intp)(n/2);\n\t\tn_right = n-n_left-1;\n\t\tbreak;\n\tcase 2:\n\t\tn_right = n-1;\n\t\tn_left = n-1;\n\t\tlength = length+n-1;\n\t\tbreak;\n\tdefault:\n\t\tPyErr_SetString(PyExc_ValueError, \n\t\t\t\t\"mode must be 0, 1, or 2\");\n\t\tgoto fail;\n\t}\n\n\t/* Need to choose an output array that can hold a sum \n\t -- use priority to determine which subtype.\n\t */\n\tret = new_array_for_sum(ap1, ap2, 1, &length, typenum);\n\tif (ret == NULL) goto fail;\n\t\n\tdot = ret->descr->f->dotfunc;\n\tif (dot == NULL) {\n\t\tPyErr_SetString(PyExc_ValueError, \n\t\t\t\t\"function not available for this data type\");\n\t\tgoto fail;\n\t}\n\t\n\tis1 = ap1->strides[0]; is2 = ap2->strides[0];\n\top = ret->data; os = ret->descr->elsize;\n\t\n\tip1 = ap1->data; ip2 = ap2->data+n_left*is2;\n\tn = n-n_left;\n\tfor(i=0; idescr->type_num);\n\tPy_DECREF(arr);\n\treturn ret;\t \n}\n\n/*MULTIARRAY_API\n Min\n*/\nstatic PyObject *\nPyArray_Min(PyArrayObject *ap, int axis)\n{\n\tPyArrayObject *arr;\n\tPyObject *ret;\n\n\tif ((arr=(PyArrayObject *)_check_axis(ap, &axis, 0))==NULL)\n\t\treturn NULL;\n\tret = PyArray_GenericReduceFunction(arr, n_ops.minimum, axis,\n\t\t\t\t\t arr->descr->type_num);\n\tPy_DECREF(arr);\n\treturn ret;\t \n}\n\n/*MULTIARRAY_API\n Ptp\n*/\nstatic PyObject *\nPyArray_Ptp(PyArrayObject *ap, int axis)\n{\n\tPyArrayObject *arr;\n\tPyObject *ret;\n\tPyObject *obj1=NULL, *obj2=NULL;\n\n\tif ((arr=(PyArrayObject *)_check_axis(ap, &axis, 0))==NULL)\n\t\treturn NULL;\n\tobj1 = PyArray_Max(arr, axis);\n\tif (obj1 == NULL) goto fail;\n\tobj2 = PyArray_Min(arr, axis);\n\tif (obj2 == NULL) goto fail;\n\tPy_DECREF(arr);\n\tret = PyNumber_Subtract(obj1, obj2);\n\tPy_DECREF(obj1);\n\tPy_DECREF(obj2);\n\treturn ret;\n\n fail:\n\tPy_XDECREF(arr);\n\tPy_XDECREF(obj1);\n\tPy_XDECREF(obj2);\n\treturn NULL;\n}\n\n\n/*MULTIARRAY_API\n ArgMax\n*/\nstatic PyObject *\nPyArray_ArgMax(PyArrayObject *op, int axis) \n{\n\tPyArrayObject *ap=NULL, *rp=NULL;\n\tPyArray_ArgFunc* arg_func;\n\tchar *ip;\n\tintp *rptr;\n\tintp i, n, orign, m;\n\tint elsize;\n\t\n\tif ((ap=(PyAO *)_check_axis(op, &axis, 0))==NULL) return NULL;\n\n\tSWAPAXES(op, ap);\n\n\tap = (PyArrayObject *)\\\n\t\tPyArray_ContiguousFromAny((PyObject *)op, \n\t\t\t\t\t PyArray_NOTYPE, 1, 0);\n\n\tPy_DECREF(op);\n\tif (ap == NULL) return NULL;\n\t\n\targ_func = ap->descr->f->argmax;\n\tif (arg_func == NULL) {\n\t\tPyErr_SetString(PyExc_TypeError, \"data type not ordered\");\n\t\tgoto fail;\n\t}\n\n\trp = (PyArrayObject *)PyArray_New(ap->ob_type, ap->nd-1,\n\t\t\t\t\t ap->dimensions, PyArray_INTP,\n\t\t\t\t\t NULL, NULL, 0, 0, \n (PyObject *)ap);\n\tif (rp == NULL) goto fail;\n\n\n\telsize = ap->descr->elsize;\n\tm = ap->dimensions[ap->nd-1];\n\tif (m == 0) {\n\t\tPyErr_SetString(MultiArrayError, \n\t\t\t\t\"attempt to get argmax/argmin \"\\\n\t\t\t\t\"of an empty sequence??\");\n\t\tgoto fail;\n\t}\n\tn = PyArray_SIZE(ap)/m;\n\trptr = (intp *)rp->data;\n\tfor (ip = ap->data, i=0; ind + indices->nd - 1;\n for (i=0; i< nd; i++) {\n if (i < axis) {\n shape[i] = self->dimensions[i];\n n *= shape[i];\n } else {\n if (i < axis+indices->nd) {\n shape[i] = indices->dimensions[i-axis];\n m *= shape[i];\n } else {\n shape[i] = self->dimensions[i-indices->nd+1];\n chunk *= shape[i];\n }\n }\n }\n\tPy_INCREF(self->descr);\n ret = (PyArrayObject *)PyArray_NewFromDescr(self->ob_type, \n\t\t\t\t\t\t self->descr,\n\t\t\t\t\t\t nd, shape, \n\t\t\t\t\t\t NULL, NULL, 0, \n\t\t\t\t\t\t (PyObject *)self);\n\t\n if (ret == NULL) goto fail;\n\t\n max_item = self->dimensions[axis];\n chunk = chunk * ret->descr->elsize;\n src = self->data;\n dest = ret->data;\n\t\n for(i=0; idata))[j];\n if (tmp < 0) tmp = tmp+max_item;\n if ((tmp < 0) || (tmp >= max_item)) {\n PyErr_SetString(PyExc_IndexError, \n\t\t\t\t\t\t\"index out of range for \"\\\n\t\t\t\t\t\t\"array\");\n goto fail;\n }\n memmove(dest, src+tmp*chunk, chunk);\n dest += chunk;\n }\n src += chunk*max_item;\n }\n\t\n PyArray_INCREF(ret);\n\n Py_XDECREF(indices);\n Py_XDECREF(self);\n\n return (PyObject *)ret;\n\t\n\t\n fail:\n Py_XDECREF(ret);\n Py_XDECREF(indices);\n Py_XDECREF(self);\n return NULL;\n}\n\n/*MULTIARRAY_API\n Put values into an array\n*/\nstatic PyObject *\nPyArray_Put(PyArrayObject *self, PyObject* values0, PyObject *indices0) \n{\n PyArrayObject *indices, *values;\n int i, chunk, ni, max_item, nv, tmp, thistype; \n char *src, *dest;\n\n indices = NULL;\n values = NULL;\n\n if (!PyArray_Check(self)) {\n PyErr_SetString(PyExc_TypeError, \"put: first argument must be an array\");\n return NULL;\n }\n if (!PyArray_ISCONTIGUOUS(self)) {\n PyErr_SetString(PyExc_ValueError, \"put: first argument must be contiguous\");\n return NULL;\n }\n max_item = PyArray_SIZE(self);\n dest = self->data;\n chunk = self->descr->elsize;\n\n indices = (PyArrayObject *)PyArray_ContiguousFromAny(indices0, PyArray_INTP, 0, 0);\n if (indices == NULL) goto fail;\n ni = PyArray_SIZE(indices);\n\n\tthistype = self->descr->type_num;\n values = (PyArrayObject *)\\\n\t\tPyArray_ContiguousFromAny(values0, thistype, 0, 0);\n if (values == NULL) goto fail;\n nv = PyArray_SIZE(values);\n if (nv > 0) { /* nv == 0 for a null array */\n if (thistype == PyArray_OBJECT) { \n for(i=0; idata + chunk * (i % nv);\n tmp = ((intp *)(indices->data))[i];\n if (tmp < 0) tmp = tmp+max_item;\n if ((tmp < 0) || (tmp >= max_item)) {\n PyErr_SetString(PyExc_IndexError, \"index out of range for array\");\n goto fail;\n }\n Py_INCREF(*((PyObject **)src));\n Py_XDECREF(*((PyObject **)(dest+tmp*chunk)));\n memmove(dest + tmp * chunk, src, chunk);\n }\n }\n else {\n for(i=0; idata + chunk * (i % nv);\n tmp = ((intp *)(indices->data))[i];\n if (tmp < 0) tmp = tmp+max_item;\n if ((tmp < 0) || (tmp >= max_item)) {\n PyErr_SetString(PyExc_IndexError, \"index out of range for array\");\n goto fail;\n }\n memmove(dest + tmp * chunk, src, chunk);\n }\n }\n\n }\n\n Py_XDECREF(values);\n Py_XDECREF(indices);\n Py_INCREF(Py_None);\n return Py_None;\n\t\n fail:\n Py_XDECREF(indices);\n Py_XDECREF(values);\n return NULL;\n}\n\n/*MULTIARRAY_API\n Put values into an array according to a mask.\n*/\nstatic PyObject *\nPyArray_PutMask(PyArrayObject *self, PyObject* values0, PyObject* mask0) \n{\n PyArrayObject *mask, *values;\n int i, chunk, ni, max_item, nv, tmp, thistype;\n char *src, *dest;\n\n mask = NULL;\n values = NULL;\n\n if (!PyArray_Check(self)) {\n PyErr_SetString(PyExc_TypeError, \n\t\t\t\t\"putmask: first argument must \"\\\n\t\t\t\t\"be an array\");\n return NULL;\n }\n if (!PyArray_ISCONTIGUOUS(self)) {\n PyErr_SetString(PyExc_ValueError, \n\t\t\t\t\"putmask: first argument must be contiguous\");\n return NULL;\n }\n\n max_item = PyArray_SIZE(self);\n dest = self->data;\n chunk = self->descr->elsize;\n\n mask = (PyArrayObject *)\\\n\t\tPyArray_FROM_OTF(mask0, PyArray_BOOL, CARRAY_FLAGS | FORCECAST);\n\tif (mask == NULL) goto fail;\n ni = PyArray_SIZE(mask);\n if (ni != max_item) {\n PyErr_SetString(PyExc_ValueError, \n\t\t\t\t\"putmask: mask and data must be \"\\\n\t\t\t\t\"the same size\");\n goto fail;\n }\n\n\tthistype = self->descr->type_num;\n values = (PyArrayObject *)\\\n\t\tPyArray_ContiguousFromAny(values0, thistype, 0, 0);\n\tif (values == NULL) goto fail;\n nv = PyArray_SIZE(values);\t /* zero if null array */\n if (nv > 0) {\n if (thistype == PyArray_OBJECT) {\n for(i=0; idata + chunk * (i % nv);\n tmp = ((Bool *)(mask->data))[i];\n if (tmp) {\n\t\t\t\t\tPy_INCREF(*((PyObject **)src));\n Py_XDECREF(*((PyObject **)(dest+i*chunk)));\n memmove(dest + i * chunk, src, chunk);\n }\n\t\t\t}\n }\n else {\n for(i=0; idata + chunk * (i % nv);\n tmp = ((Bool *)(mask->data))[i];\n if (tmp) memmove(dest + i * chunk, src, chunk);\n\t\t\t}\n\t\t}\n }\n\n Py_XDECREF(values);\n Py_XDECREF(mask);\n Py_INCREF(Py_None);\n return Py_None;\n\t\n fail:\n Py_XDECREF(mask);\n Py_XDECREF(values);\n return NULL;\n}\n\n\n/* This conversion function can be used with the \"O&\" argument for\n PyArg_ParseTuple. It will immediately return an object of array type\n or will convert to a CARRAY any other object. \n\n If you use PyArray_Converter, you must DECREF the array when finished\n as you get a new reference to it.\n*/\n \n/*MULTIARRAY_API\n Useful to pass as converter function for O& processing in\n PyArgs_ParseTuple.\n*/\nstatic int \nPyArray_Converter(PyObject *object, PyObject **address) \n{\n if (PyArray_Check(object)) {\n *address = object;\n\t\tPy_INCREF(object);\n return PY_SUCCEED;\n }\n else {\n\t\t*address = PyArray_FromAny(object, NULL, 0, 0, CARRAY_FLAGS, NULL);\n\t\tif (*address == NULL) return PY_FAIL;\n\t\treturn PY_SUCCEED;\n }\n}\n\n/*MULTIARRAY_API\n Convert an object to true / false\n*/\nstatic int\nPyArray_BoolConverter(PyObject *object, Bool *val)\n{ \n if (PyObject_IsTrue(object))\n *val=TRUE;\n else *val=FALSE;\n if (PyErr_Occurred())\n return PY_FAIL;\n return PY_SUCCEED;\n}\n\n\n/*MULTIARRAY_API\n Typestr converter\n*/\nstatic int\nPyArray_TypestrConvert(int itemsize, int gentype)\n{\n\tregister int newtype = gentype;\n\t\n\tif (gentype == PyArray_GENBOOLLTR) {\n\t\tif (itemsize == 1)\n\t\t\tnewtype = PyArray_BOOL;\n\t\telse \n\t\t\tnewtype = PyArray_NOTYPE;\n\t}\n\telse if (gentype == PyArray_SIGNEDLTR) {\n\t\tswitch(itemsize) {\n\t\tcase 1:\n\t\t\tnewtype = PyArray_INT8;\n\t\t\tbreak;\n\t\tcase 2:\n\t\t\tnewtype = PyArray_INT16;\n\t\t\tbreak;\n\t\tcase 4:\n\t\t\tnewtype = PyArray_INT32;\n\t\t\tbreak;\n\t\tcase 8:\n\t\t\tnewtype = PyArray_INT64;\n\t\t\tbreak;\n#ifdef PyArray_INT128\n\t\tcase 16:\n\t\t\tnewtype = PyArray_INT128;\n\t\t\tbreak;\n#endif\n\t\tdefault:\n\t\t\tnewtype = PyArray_NOTYPE;\n\t\t}\n\t}\n\n\telse if (gentype == PyArray_UNSIGNEDLTR) {\n\t\tswitch(itemsize) {\n\t\tcase 1:\n\t\t\tnewtype = PyArray_UINT8;\n\t\t\tbreak;\n\t\tcase 2:\n\t\t\tnewtype = PyArray_UINT16;\n\t\t\tbreak;\n\t\tcase 4:\n\t\t\tnewtype = PyArray_UINT32;\n\t\t\tbreak;\n\t\tcase 8:\n\t\t\tnewtype = PyArray_UINT64;\n\t\t\tbreak;\n#ifdef PyArray_INT128\n\t\tcase 16:\n\t\t\tnewtype = PyArray_UINT128;\n\t\t\tbreak;\n#endif\n\t\tdefault:\n\t\t\tnewtype = PyArray_NOTYPE;\n\t\t\tbreak;\n\t\t}\n\t}\n\telse if (gentype == PyArray_FLOATINGLTR) {\n\t\tswitch(itemsize) {\n\t\tcase 4:\n\t\t\tnewtype = PyArray_FLOAT32;\n\t\t\tbreak;\n\t\tcase 8:\n\t\t\tnewtype = PyArray_FLOAT64;\n\t\t\tbreak;\n#ifdef PyArray_FLOAT80\n case 10:\n\t\t\tnewtype = PyArray_FLOAT80;\n\t\t\tbreak;\n#endif\n#ifdef PyArray_FLOAT96\n\t\tcase 12:\n\t\t\tnewtype = PyArray_FLOAT96;\n\t\t\tbreak;\n#endif\t\t \n#ifdef PyArray_FLOAT128\n\t\tcase 16:\n\t\t\tnewtype = PyArray_FLOAT128;\n\t\t\tbreak;\n#endif\n\t\tdefault:\n\t\t\tnewtype = PyArray_NOTYPE;\n\t\t}\t\t\n\t}\n\t\n\telse if (gentype == PyArray_COMPLEXLTR) {\n\t\tswitch(itemsize) {\n\t\tcase 8:\n\t\t\tnewtype = PyArray_COMPLEX64;\n\t\t\tbreak;\n\t\tcase 16:\n\t\t\tnewtype = PyArray_COMPLEX128;\n\t\t\tbreak;\n#ifdef PyArray_FLOAT80\n case 20:\n\t\t\tnewtype = PyArray_COMPLEX160;\n\t\t\tbreak;\n#endif\n#ifdef PyArray_FLOAT96\n\t\tcase 24:\n\t\t\tnewtype = PyArray_COMPLEX192;\t\t\t\n\t\t\tbreak;\n#endif\t\t \n#ifdef PyArray_FLOAT128\n\t\tcase 32:\n\t\t\tnewtype = PyArray_COMPLEX256;\n\t\t\tbreak;\n#endif\n\t\tdefault:\n\t\t\tnewtype = PyArray_NOTYPE;\n\t\t}\t\t\n\t}\n\n\treturn newtype;\n}\n\n\n/* this function takes a Python object which exposes the (single-segment)\n buffer interface and returns a pointer to the data segment\n \n You should increment the reference count by one of buf->base\n if you will hang on to a reference\n\n You only get a borrowed reference to the object. Do not free the\n memory...\n*/\n\n\n/*MULTIARRAY_API\n Get buffer chunk from object\n*/\nstatic int\nPyArray_BufferConverter(PyObject *obj, PyArray_Chunk *buf)\n{\n int buflen;\n\n buf->ptr = NULL;\n buf->flags = BEHAVED_FLAGS;\n buf->base = NULL;\n\n\tif (obj == Py_None)\n\t\treturn PY_SUCCEED;\n\n if (PyObject_AsWriteBuffer(obj, &(buf->ptr), &buflen) < 0) {\n PyErr_Clear();\n buf->flags &= ~WRITEABLE;\n if (PyObject_AsReadBuffer(obj, (const void **)&(buf->ptr), \n &buflen) < 0)\n return PY_FAIL;\n }\n buf->len = (intp) buflen;\n \n /* Point to the base of the buffer object if present */\n if (PyBuffer_Check(obj)) buf->base = ((PyArray_Chunk *)obj)->base;\n if (buf->base == NULL) buf->base = obj;\n \n return PY_SUCCEED; \n}\n\n\n\n/* This function takes a Python sequence object and allocates and\n fills in an intp array with the converted values.\n\n **Remember to free the pointer seq.ptr when done using\n PyDimMem_FREE(seq.ptr)**\n*/\n\n/*MULTIARRAY_API\n Get intp chunk from sequence\n*/\nstatic int\nPyArray_IntpConverter(PyObject *obj, PyArray_Dims *seq)\n{\n int len;\n int nd;\n\n seq->ptr = NULL;\n if (obj == Py_None) return PY_SUCCEED;\n len = PySequence_Size(obj);\n if (len == -1) { /* Check to see if it is a number */\n if (PyNumber_Check(obj)) len = 1;\n }\n if (len < 0) {\n PyErr_SetString(PyExc_TypeError, \n \"expected sequence object with len >= 0\");\n return PY_FAIL;\n }\n if (len > MAX_DIMS) {\n PyErr_Format(PyExc_ValueError, \"sequence too large; \" \\\n \"must be smaller than %d\", MAX_DIMS);\n return PY_FAIL;\n }\n\tif (len > 0) {\n\t\tseq->ptr = PyDimMem_NEW(len);\n\t\tif (seq->ptr == NULL) {\n\t\t\tPyErr_NoMemory();\n\t\t\treturn PY_FAIL;\n\t\t}\n\t}\n seq->len = len;\n nd = PyArray_IntpFromSequence(obj, (intp *)seq->ptr, len);\n if (nd == -1 || nd != len) {\n\t\tPyDimMem_FREE(seq->ptr);\n\t\tseq->ptr=NULL;\n\t\treturn PY_FAIL;\n\t}\n return PY_SUCCEED;\n}\n\n\n/* A tuple type would be either (generic typeobject, typesize) \n or (fixed-length data-type, shape) \n\n or (inheriting data-type, new-data-type)\n The new data-type must have the same itemsize as the inheriting data-type\n unless the latter is 0 \n \n Thus (int32, {'real':(int16,0),'imag',(int16,2)})\n\n is one way to specify a descriptor that will give \n a['real'] and a['imag'] to an int32 array.\n*/\n\n/* leave type reference alone */\nstatic PyArray_Descr *\n_use_inherit(PyArray_Descr *type, PyObject *newobj, int *errflag) \n{\n\tPyArray_Descr *new;\n\tPyArray_Descr *conv;\n\t\n\t*errflag = 0;\n\tif (!PyArray_DescrConverter(newobj, &conv)) {\n\t\treturn NULL;\n\t}\n\t*errflag = 1;\n\tif (type == &OBJECT_Descr) {\n\t\tPyErr_SetString(PyExc_ValueError,\n\t\t\t\t\"cannot base a new descriptor on an\"\\\n\t\t\t\t\" OBJECT descriptor.\");\n\t\treturn NULL;\n\t}\n\tnew = PyArray_DescrNew(type);\n\tif (new == NULL) return NULL;\n\n\tif (new->elsize && new->elsize != conv->elsize) {\n\t\tPyErr_SetString(PyExc_ValueError, \n\t\t\t\t\"mismatch in size of old\"\\\n\t\t\t\t\"and new data-descriptor\");\n\t\treturn NULL;\n\t}\n\tnew->elsize = conv->elsize;\n\tif (conv->fields != Py_None) {\n\t\tnew->fields = conv->fields;\n\t\tPy_XINCREF(new->fields);\n\t}\n\tPy_DECREF(conv);\n\t*errflag = 0;\n\treturn new;\n}\n\nstatic PyArray_Descr *\n_convert_from_tuple(PyObject *obj) \n{\n\tPyArray_Descr *type, *res;\n\tPyObject *val;\n\tint errflag;\n\t\n\tif (PyTuple_GET_SIZE(obj) != 2) return NULL;\n\n\tif (!PyArray_DescrConverter(PyTuple_GET_ITEM(obj,0), &type)) \n\t\treturn NULL;\n\tval = PyTuple_GET_ITEM(obj,1);\n\t/* try to interpret next item as a type */\n\tres = _use_inherit(type, val, &errflag);\n\tif (res || errflag) {\n\t\tPy_DECREF(type);\n\t\tif (res) return res;\n\t\telse return NULL;\n\t}\n\tPyErr_Clear();\n\t/* We get here if res was NULL but errflag wasn't set\n\t --- i.e. the conversion to a data-descr failed in _use_inherit\n\t*/\n\n\tif (type->elsize == 0) { /* interpret next item as a typesize */\n\t\tint itemsize;\n\t\titemsize = PyArray_PyIntAsInt(PyTuple_GET_ITEM(obj,1));\n\t\tif (error_converting(itemsize)) {\n\t\t\tPyErr_SetString(PyExc_ValueError, \n\t\t\t\t\t\"invalid itemsize in generic type \"\\\n\t\t\t\t\t\"tuple\");\n\t\t\tgoto fail;\n\t\t}\n\t\tPyArray_DESCR_REPLACE(type);\n\t\ttype->elsize = itemsize;\n\t}\n\telse {\n\t\t/* interpret next item as shape (if it's a tuple)\n\t\t and reset the type to PyArray_VOID with \n\t\t anew fields attribute. \n\t */\n\t\tPyArray_Dims shape={NULL,-1};\n\t\tPyArray_Descr *newdescr;\n\t\tif (!(PyArray_IntpConverter(val, &shape)) || \n\t\t (shape.len > MAX_DIMS)) {\n\t\t\tPyDimMem_FREE(shape.ptr);\n\t\t\tPyErr_SetString(PyExc_ValueError, \n\t\t\t\t\t\"invalid shape in fixed-type tuple.\");\n\t\t\tgoto fail;\n\t\t}\n\t\t/* If (type, 1) was given, it is equivalent to type... */\n\t\tif (shape.len == 1 && shape.ptr[0] == 1 && PyNumber_Check(val)) {\n\t\t\tPyDimMem_FREE(shape.ptr);\n\t\t\treturn type;\n\t\t}\n\t\tnewdescr = PyArray_DescrNewFromType(PyArray_VOID);\n\t\tif (newdescr == NULL) {PyDimMem_FREE(shape.ptr); goto fail;}\n\t\tnewdescr->elsize = type->elsize;\n\t\tnewdescr->elsize *= PyArray_MultiplyList(shape.ptr, \n\t\t\t\t\t\t\t shape.len);\n\t\tPyDimMem_FREE(shape.ptr);\n\t\tnewdescr->subarray = _pya_malloc(sizeof(PyArray_ArrayDescr));\n\t\tnewdescr->subarray->base = type;\n\t\tif (type->hasobject) newdescr->hasobject = 1;\n\t\tPy_INCREF(val);\n\t\tnewdescr->subarray->shape = val;\n\t\tPy_XDECREF(newdescr->fields);\n\t\tnewdescr->fields = NULL;\n\t\ttype = newdescr;\n\t}\n\treturn type;\n\n fail:\n\tPy_XDECREF(type);\n\treturn NULL;\n}\n\n/* obj is a list. Each item is a tuple with\n\n(field-name, data-type (either a list or a string), and an optional \n shape parameter).\n*/\nstatic PyArray_Descr *\n_convert_from_array_descr(PyObject *obj)\n{\n\tint n, i, totalsize;\n\tint ret;\n\tPyObject *fields, *item, *newobj;\n\tPyObject *name, *key, *tup;\n\tPyObject *nameslist;\n\tPyArray_Descr *new;\n\tPyArray_Descr *conv;\n int hasobject=0;\n\t\n\tn = PyList_GET_SIZE(obj);\t\n\tnameslist = PyList_New(n);\n\tif (!nameslist) return NULL;\n\ttotalsize = 0;\n\tfields = PyDict_New();\n\tfor (i=0; ihasobject)\n hasobject = 1;\n\t\ttup = PyTuple_New(2);\n\t\tPyTuple_SET_ITEM(tup, 0, (PyObject *)conv);\n\t\tPyTuple_SET_ITEM(tup, 1, PyInt_FromLong((long) totalsize));\n\t\ttotalsize += conv->elsize;\n\t\tPyDict_SetItem(fields, name, tup);\n\t\tPy_DECREF(tup);\n\t}\n\tkey = PyInt_FromLong(-1);\n\tPyDict_SetItem(fields, key, nameslist);\n\tPy_DECREF(key);\n\tPy_DECREF(nameslist);\n\tnew = PyArray_DescrNewFromType(PyArray_VOID);\n\tnew->fields = fields;\n\tnew->elsize = totalsize;\n new->hasobject=hasobject;\n\treturn new;\n \n fail:\n\tPy_DECREF(fields);\n\tPy_DECREF(nameslist);\n\treturn NULL;\n\n}\n\n/* a list specifying a data-type can just be\n a list of formats. The names for the fields\n will default to f1, f2, f3, and so forth.\n\n or it can be an array_descr format string -- in which case\n align must be 0. \n*/\n\nstatic PyArray_Descr *\n_convert_from_list(PyObject *obj, int align, int try_descr)\n{\n\tint n, i;\n\tint totalsize;\n\tPyObject *fields;\n\tPyArray_Descr *conv=NULL;\n\tPyArray_Descr *new;\n\tPyObject *key, *tup;\n\tPyObject *nameslist=NULL;\n \tint ret;\n\tint maxalign=0;\n int hasobject=0;\n\t\n\tn = PyList_GET_SIZE(obj);\n\ttotalsize = 0;\n\tif (n==0) return NULL;\n\tnameslist = PyList_New(n);\n\tif (!nameslist) return NULL;\n\tfields = PyDict_New();\n\tfor (i=0; ihasobject)\n\t\t\thasobject=1;\t\t\t\n\t\tPyTuple_SET_ITEM(tup, 0, (PyObject *)conv);\n\t\tif (align) {\n\t\t\tint _align;\n\t\t\t_align = conv->alignment;\n\t\t\tif (_align > 1) totalsize =\t\t\t\\\n\t\t\t\t((totalsize + _align - 1)/_align)*_align;\n\t\t\tmaxalign = MAX(maxalign, _align);\n\t\t}\n\t\tPyTuple_SET_ITEM(tup, 1, PyInt_FromLong((long) totalsize));\n\t\tPyDict_SetItem(fields, key, tup);\n\t\tPy_DECREF(tup);\n\t\tPyList_SET_ITEM(nameslist, i, key);\n\t\ttotalsize += conv->elsize;\n\t}\n\tkey = PyInt_FromLong(-1);\n\tPyDict_SetItem(fields, key, nameslist);\n\tPy_DECREF(key);\n\tPy_DECREF(nameslist);\n\tnew = PyArray_DescrNewFromType(PyArray_VOID);\n\tnew->fields = fields;\n new->hasobject=hasobject;\n\tif (maxalign > 1) {\n\t\ttotalsize = ((totalsize+maxalign-1)/maxalign)*maxalign;\n\t}\n\tif (align) new->alignment = maxalign;\n\tnew->elsize = totalsize;\n\treturn new;\n\n fail:\n\tPy_DECREF(nameslist);\n\tPy_DECREF(fields);\n\tif (!try_descr) return NULL;\n\tif (align) {\n\t\tPyErr_SetString(PyExc_ValueError, \n\t\t\t\t\"failed to convert from list of formats \"\\\n\t\t\t\t\"and align cannot be 1 for conversion from \"\\\n\t\t\t\t\"array_descr structure\");\n\t\treturn NULL;\n\t}\n\tPyErr_Clear();\n\treturn _convert_from_array_descr(obj);\n}\n\n\n/* comma-separated string */\n/* this is the format developed by the numarray records module */\n/* and implemented by the format parser in that module */\n/* this is an alternative implementation found in the _internal.py \n file patterned after that one -- the approach is to try to convert \n to a list (with tuples if any repeat information is present) \n and then call the _convert_from_list)\n*/\n\nstatic PyArray_Descr *\n_convert_from_commastring(PyObject *obj, int align)\n{\n\tPyObject *listobj;\n\tPyArray_Descr *res;\n\n\tif (!PyString_Check(obj)) return NULL;\n listobj = PyObject_CallMethod(_numpy_internal, \"_commastring\",\n\t\t\t\t \"O\", obj);\n\tif (!listobj) return NULL;\n\tres = _convert_from_list(listobj, align, 0);\n\tPy_DECREF(listobj);\n\tif (!res && !PyErr_Occurred()) {\n\t\tPyErr_SetString(PyExc_ValueError, \"invalid data-type\");\n\t\treturn NULL;\n\t}\n\treturn res;\n}\n\n\n\n/* a dictionary specifying a data-type\n must have at least two and up to four\n keys These must all be sequences of the same length.\n\n \"names\" --- field names \n \"formats\" --- the data-type descriptors for the field.\n \n Optional:\n\n \"offsets\" --- integers indicating the offset into the \n record of the start of the field.\n\t\t if not given, then \"consecutive offsets\" \n\t\t will be assumed and placed in the dictionary.\n \n \"titles\" --- Allows the use of an additional key\n for the fields dictionary.\n \nAttribute-lookup-based field names merely has to query the fields \ndictionary of the data-descriptor. Any result present can be used\nto return the correct field.\n\nSo, the notion of what is a name and what is a title is really quite\narbitrary. \n\nWhat does distinguish a title, however, is that if it is not None, \nit will be placed at the end of the tuple inserted into the \nfields dictionary.\n\nIf the dictionary does not have \"names\" and \"formats\" entries,\nthen it will be checked for conformity and used directly. \n*/\n\nstatic PyArray_Descr *\n_use_fields_dict(PyObject *obj, int align)\n{\n return (PyArray_Descr *)PyObject_CallMethod(_numpy_internal, \n\t\t\t\t\t\t \"_usefields\", \n\t\t\t\t\t\t \"Oi\", obj, align);\n}\n\nstatic PyArray_Descr *\n_convert_from_dict(PyObject *obj, int align)\n{\n\tPyArray_Descr *new;\n\tPyObject *fields=NULL;\n\tPyObject *names, *offsets, *descrs, *titles, *key;\n\tint n, i;\n\tint totalsize;\n\tint maxalign=0;\n int hasobject=0;\n\t\n\tfields = PyDict_New();\n\tif (fields == NULL) return (PyArray_Descr *)PyErr_NoMemory();\n\t\n\tnames = PyDict_GetItemString(obj, \"names\");\n\tdescrs = PyDict_GetItemString(obj, \"formats\");\n\n\tif (!names || !descrs) {\n\t\tPy_DECREF(fields);\n\t\treturn _use_fields_dict(obj, align);\n\t}\n\tn = PyObject_Length(names);\n\toffsets = PyDict_GetItemString(obj, \"offsets\");\n\ttitles = PyDict_GetItemString(obj, \"titles\");\n\tif ((n > PyObject_Length(descrs)) ||\t\t\t\\\n\t (offsets && (n > PyObject_Length(offsets))) ||\t\\\n\t (titles && (n > PyObject_Length(titles)))) {\n\t\tPyErr_SetString(PyExc_ValueError,\n\t\t\t\t\"all items in the dictionary must have\" \\\n\t\t\t\t\" the same length.\");\n\t\tgoto fail;\n\t}\n\n\ttotalsize = 0;\n\tfor(i=0; i totalsize) totalsize = offset;\n\t\t}\n\t\telse {\n\t\t\tif (align) {\n\t\t\t\tint _align = newdescr->alignment;\n\t\t\t\tif (_align > 1) totalsize =\t\t\\\n\t\t\t\t\t((totalsize + _align - 1)/_align)*_align;\n\t\t\t\tmaxalign = MAX(maxalign,_align);\n\t\t\t}\n\t\t\tPyTuple_SET_ITEM(tup, 1, PyInt_FromLong(totalsize));\n\t\t}\n\t\tif (len == 3) PyTuple_SET_ITEM(tup, 2, item);\n\t\tname = PyObject_GetItem(names, index);\n\t\tPy_DECREF(index);\n\n\t\t/* Insert into dictionary */\n\t\tif (PyDict_GetItem(fields, name) != NULL) {\n\t\t\tPyErr_SetString(PyExc_ValueError,\n\t\t\t\t\t\"two fields with the same name\");\n\t\t\tret = PY_FAIL;\n\t\t}\n\t\tPyDict_SetItem(fields, name, tup);\n\t\tPy_DECREF(name);\n\t\tif (len == 3) PyDict_SetItem(fields, item, tup);\n\t\tPy_DECREF(tup);\n\t\tif ((ret == PY_FAIL) || (newdescr->elsize == 0)) goto fail;\n if (!hasobject && newdescr->hasobject)\n hasobject = 1;\n\t\ttotalsize += newdescr->elsize;\n\t}\n\n\tnew = PyArray_DescrNewFromType(PyArray_VOID);\n\tif (new == NULL) goto fail;\n\tif (maxalign > 1)\n\t\ttotalsize = ((totalsize + maxalign - 1)/maxalign)*maxalign;\n\tif (align) new->alignment = maxalign;\n\tnew->elsize = totalsize;\n\tkey = PyInt_FromLong(-1);\n\tPyDict_SetItem(fields, key, names);\n\tPy_DECREF(key);\n\tnew->fields = fields;\n new->hasobject=hasobject;\n\treturn new;\n\n fail:\n\tPy_XDECREF(fields);\n\treturn NULL;\n}\n\n/* \n any object with \n the .fields attribute and/or .itemsize attribute \n (if the .fields attribute does not give\n the total size -- i.e. a partial record naming).\n If itemsize is given it must be >= size computed from fields\n \n The .fields attribute must return a convertible dictionary if \n present. Result inherits from PyArray_VOID.\n*/\n\n\n/*MULTIARRAY_API\n Get typenum from an object -- None goes to NULL\n*/\nstatic int\nPyArray_DescrConverter2(PyObject *obj, PyArray_Descr **at)\n{\n\tif (obj == Py_None) {\n\t\t*at = NULL;\n\t\treturn PY_SUCCEED;\n\t}\n\telse return PyArray_DescrConverter(obj, at);\n}\n\n/* This function takes a Python object representing a type and converts it \n to a the correct PyArray_Descr * structure to describe the type.\n \n Many objects can be used to represent a data-type which in NumPy is\n quite a flexible concept. \n\n This is the central code that converts Python objects to \n Type-descriptor objects that are used throughout numpy.\n */\n\n/* new reference in *at */\n/*MULTIARRAY_API\n Get typenum from an object -- None goes to &LONG_descr\n*/\nstatic int\nPyArray_DescrConverter(PyObject *obj, PyArray_Descr **at)\n{\n char *type;\n int check_num=PyArray_NOTYPE+10;\n\tint len;\n\tPyObject *item;\n\tint elsize = 0;\n\tchar endian = '=';\n\n\t*at=NULL;\n\t\n\t/* default */\n if (obj == Py_None) {\n\t\t*at = PyArray_DescrFromType(PyArray_LONG);\n\t\treturn PY_SUCCEED;\n\t}\n\t\n\tif (PyArray_DescrCheck(obj)) {\n\t\t*at = (PyArray_Descr *)obj;\n\t\tPy_INCREF(*at);\n\t\treturn PY_SUCCEED;\n\t}\n\t\n if (PyType_Check(obj)) {\n\t\tif (PyType_IsSubtype((PyTypeObject *)obj, \n\t\t\t\t &PyGenericArrType_Type)) {\n\t\t\t*at = PyArray_DescrFromTypeObject(obj);\n\t\t\tif (*at) return PY_SUCCEED;\n\t\t\telse return PY_FAIL;\n\t\t}\n\t\tcheck_num = PyArray_OBJECT;\n\t\tif (obj == (PyObject *)(&PyInt_Type))\n\t\t\tcheck_num = PyArray_LONG;\n\t\telse if (obj == (PyObject *)(&PyLong_Type))\n\t\t\tcheck_num = PyArray_LONGLONG;\n\t\telse if (obj == (PyObject *)(&PyFloat_Type)) \n\t\t\tcheck_num = PyArray_DOUBLE;\n\t\telse if (obj == (PyObject *)(&PyComplex_Type)) \n\t\t\tcheck_num = PyArray_CDOUBLE;\n\t\telse if (obj == (PyObject *)(&PyBool_Type))\n\t\t\tcheck_num = PyArray_BOOL;\n else if (obj == (PyObject *)(&PyString_Type))\n check_num = PyArray_STRING;\n else if (obj == (PyObject *)(&PyUnicode_Type))\n check_num = PyArray_UNICODE;\n\t\telse if (obj == (PyObject *)(&PyBuffer_Type))\n\t\t\tcheck_num = PyArray_VOID;\n\t\telse {\n\t\t\t*at = _arraydescr_fromobj(obj);\n\t\t\tif (*at) return PY_SUCCEED;\n\t\t}\n\t\tgoto finish;\n\t}\n\n\t/* or a typecode string */\n\n\tif (PyString_Check(obj)) {\n\t\t/* Check for a string typecode. */\n\t\ttype = PyString_AS_STRING(obj);\n\t\tlen = PyString_GET_SIZE(obj);\n\t\tif (len <= 0) goto fail;\n\t\tcheck_num = (int) type[0];\n\t\tif ((char) check_num == '>' || (char) check_num == '<' || \\\n\t\t (char) check_num == '|' || (char) check_num == '=') {\n\t\t\tif (len <= 1) goto fail;\n\t\t\tendian = (char) check_num;\n\t\t\ttype++; len--;\n\t\t\tcheck_num = (int) type[0];\n\t\t\tif (endian == '|') endian = '=';\n\t\t}\n\t\tif (len > 1) {\n\t\t\tint i;\n\t\t\telsize = atoi(type+1);\n\t\t\t/* check for commas present */\n\t\t\tfor (i=1;ielsize == 0) && (elsize != 0)) {\n\t\tPyArray_DESCR_REPLACE(*at);\n\t\t(*at)->elsize = elsize;\n\t}\n\tif (endian != '=' && PyArray_ISNBO(endian)) endian = '='; \n\t\n\tif (endian != '=' && (*at)->byteorder != '|' &&\t\\\n\t (*at)->byteorder != endian) {\n\t\tPyArray_DESCR_REPLACE(*at);\n\t\t(*at)->byteorder = endian;\n\t}\n\t\n return PY_SUCCEED;\n\n fail:\n\tPyErr_SetString(PyExc_TypeError, \n\t\t\t\"data type not understood\");\n\t*at=NULL;\n\treturn PY_FAIL;\n}\t\n\n/*MULTIARRAY_API\n Convert object to endian\n*/\nstatic int\nPyArray_ByteorderConverter(PyObject *obj, char *endian)\n{\n\tchar *str;\n\t*endian = PyArray_SWAP;\n\tstr = PyString_AsString(obj);\n\tif (!str) return PY_FAIL;\n\tif (strlen(str) < 1) {\n\t\tPyErr_SetString(PyExc_ValueError, \n\t\t\t\t\"Byteorder string must be at least length 1\");\n\t\treturn PY_FAIL;\n\t}\n\t*endian = str[0];\n\tif (str[0] != PyArray_BIG && str[0] != PyArray_LITTLE &&\t\\\n\t str[0] != PyArray_NATIVE) {\n\t\tif (str[0] == 'b' || str[0] == 'B')\n\t\t\t*endian = PyArray_BIG;\n\t\telse if (str[0] == 'l' || str[0] == 'L')\n\t\t\t*endian = PyArray_LITTLE;\n\t\telse if (str[0] == 'n' || str[0] == 'N')\n\t\t\t*endian = PyArray_NATIVE;\n\t\telse if (str[0] == 'i' || str[0] == 'I')\n\t\t\t*endian = PyArray_IGNORE;\n\t\telse if (str[0] == 's' || str[0] == 'S')\n\t\t\t*endian = PyArray_SWAP;\n\t\telse {\n\t\t\tPyErr_Format(PyExc_ValueError, \n\t\t\t\t \"%s is an unrecognized byteorder\",\n\t\t\t\t str);\n\t\t\treturn PY_FAIL;\n\t\t}\n\t}\n\treturn PY_SUCCEED;\n}\n\n/*MULTIARRAY_API\n Convert object to sort kind \n*/\nstatic int\nPyArray_SortkindConverter(PyObject *obj, PyArray_SORTKIND *sortkind)\n{\n\tchar *str;\n\t*sortkind = PyArray_QUICKSORT;\n\tstr = PyString_AsString(obj);\n\tif (!str) return PY_FAIL;\n\tif (strlen(str) < 1) {\n\t\tPyErr_SetString(PyExc_ValueError, \n\t\t\t\t\"Sort kind string must be at least length 1\");\n\t\treturn PY_FAIL;\n\t}\n\tif (str[0] == 'q' || str[0] == 'Q')\n\t\t*sortkind = PyArray_QUICKSORT;\n\telse if (str[0] == 'h' || str[0] == 'H')\n\t\t*sortkind = PyArray_HEAPSORT;\n\telse if (str[0] == 'm' || str[0] == 'M')\n\t\t*sortkind = PyArray_MERGESORT;\n\telse if (str[0] == 't' || str[0] == 'T')\n\t\t*sortkind = PyArray_TIMSORT;\n\telse {\n\t\tPyErr_Format(PyExc_ValueError, \n\t\t\t \"%s is an unrecognized kind of sort\",\n\t\t\t str);\n\t\treturn PY_FAIL;\n\t}\n\treturn PY_SUCCEED;\n}\n\n\n/* This function returns true if the two typecodes are \n equivalent (same basic kind and same itemsize).\n*/\n\n/*MULTIARRAY_API*/\nstatic Bool\nPyArray_EquivTypes(PyArray_Descr *typ1, PyArray_Descr *typ2)\n{\n\tregister int typenum1=typ1->type_num;\n\tregister int typenum2=typ2->type_num;\n\tregister int size1=typ1->elsize;\n\tregister int size2=typ2->elsize;\n\n\tif (size1 != size2) return FALSE;\n\tif (typ1->fields != typ2->fields) return FALSE;\n\tif (PyArray_ISNBO(typ1->byteorder) != PyArray_ISNBO(typ2->byteorder))\n\t\treturn FALSE;\n\n\tif (typenum1 == PyArray_VOID || \\\n\t typenum2 == PyArray_VOID) {\n\t\treturn ((typenum1 == typenum2) && \n\t\t\t(typ1->typeobj == typ2->typeobj) &&\n\t\t\t(typ1->fields == typ2->fields));\n\t}\n\treturn (typ1->kind == typ2->kind);\n}\n\n/*** END C-API FUNCTIONS **/\n\nstatic PyObject *\n_prepend_ones(PyArrayObject *arr, int nd, int ndmin)\n{\n\tintp newdims[MAX_DIMS];\n\tintp newstrides[MAX_DIMS];\n\tint i,k,num;\n\tPyObject *ret;\n\n\tnum = ndmin-nd;\n\tfor (i=0; idescr->elsize;\n\t}\n\tfor (i=num;idimensions[k];\n\t\tnewstrides[i] = arr->strides[k];\n\t}\n\tPy_INCREF(arr->descr);\n\tret = PyArray_NewFromDescr(arr->ob_type, arr->descr, ndmin,\n\t\t\t\t newdims, newstrides, arr->data, arr->flags,\n\t\t\t\t (PyObject *)arr);\n\t/* steals a reference to arr --- so don't increment\n\t here */\n\tPyArray_BASE(ret) = (PyObject *)arr;\n\treturn ret;\n}\n\n\n#define _ARET(x) PyArray_Return((PyArrayObject *)(x))\n\nstatic char doc_fromobject[] = \"array(object, dtype=None, copy=1, fortran=0, \"\\\n \"subok=0,ndmin=0)\\n\"\\\n \"will return a new array formed from the given object type given.\\n\"\\\n \"Object can anything with an __array__ method, or any object\\n\"\\\n \"exposing the array interface, or any (nested) sequence.\\n\"\\\n \"If no type is given, then the type will be determined as the\\n\"\\\n \"minimum type required to hold the objects in the sequence.\\n\"\\\n \"If copy is zero and sequence is already an array with the right \\n\"\\\n \"type, a reference will be returned. If the sequence is an array,\\n\"\\\n \"type can be used only to upcast the array. For downcasting \\n\"\\\n \"use .astype(t) method. If subok is true, then subclasses of the\\n\"\\\n \"array may be returned. Otherwise, a base-class ndarray is returned\\n\"\\\n\t\"The ndmin argument specifies how many dimensions the returned\\n\"\\\n\t\"array should have as a minimum. 1's will be pre-pended to the\\n\"\\\n\t\"shape as needed to meet this requirement.\";\n\nstatic PyObject *\n_array_fromobject(PyObject *ignored, PyObject *args, PyObject *kws)\n{\n\tPyObject *op, *ret=NULL;\n\tstatic char *kwd[]= {\"object\", \"dtype\", \"copy\", \"fortran\", \"subok\", \n\t\t\t \"ndmin\", NULL};\n Bool subok=FALSE;\n\tBool copy=TRUE;\n\tint ndmin=0, nd;\n\tPyArray_Descr *type=NULL;\n\tPyArray_Descr *oldtype=NULL;\n\tBool fortran=FALSE;\n\tint flags=0;\n\n\tif(!PyArg_ParseTupleAndKeywords(args, kws, \"O|O&O&O&O&i\", kwd, &op, \n\t\t\t\t\tPyArray_DescrConverter2,\n &type, \n\t\t\t\t\tPyArray_BoolConverter, ©, \n\t\t\t\t\tPyArray_BoolConverter, &fortran,\n PyArray_BoolConverter, &subok, \n\t\t\t\t\t&ndmin)) \n\t\treturn NULL;\n\n\t/* fast exit if simple call */\n\tif ((PyArray_CheckExact(op) || PyBigArray_CheckExact(op))) {\n\t\tif (type==NULL) {\n\t\t\tif (!copy && fortran==PyArray_ISFORTRAN(op)) {\n\t\t\t\tPy_INCREF(op);\n\t\t\t\tret = op;\n\t\t\t\tgoto finish;\n\t\t\t}\n\t\t\telse {\n\t\t\t\tret = PyArray_NewCopy((PyArrayObject*)op, \n\t\t\t\t\t\t fortran);\n\t\t\t\tgoto finish;\n\t\t\t}\n\t\t}\n\t\t/* One more chance */\n\t\toldtype = PyArray_DESCR(op);\n\t\tif (PyArray_EquivTypes(oldtype, type)) {\n\t\t\tif (!copy && fortran==PyArray_ISFORTRAN(op)) {\n\t\t\t\tPy_INCREF(op);\n\t\t\t\tret = op;\n\t\t\t\tgoto finish;\n\t\t\t}\n\t\t\telse {\n\t\t\t\tret = PyArray_NewCopy((PyArrayObject*)op,\n\t\t\t\t\t\t fortran);\n\t\t\t\tif (oldtype == type) return ret;\n\t\t\t\tPy_INCREF(oldtype);\n\t\t\t\tPy_DECREF(PyArray_DESCR(ret));\n\t\t\t\tPyArray_DESCR(ret) = oldtype;\n\t\t\t\tgoto finish;\n\t\t\t}\n\t\t}\n\t}\n\n\tif (copy) {\n\t\tflags = ENSURECOPY;\n\t}\n\tif (fortran) {\n\t\tflags |= FORTRAN;\n\t}\n if (!subok) {\n flags |= ENSUREARRAY;\n }\n\n\tif ((ret = PyArray_CheckFromAny(op, type, 0, 0, flags, NULL)) == NULL) \n\t\treturn NULL;\n\n finish:\n\n\tif ((nd=PyArray_NDIM(ret)) >= ndmin) return ret;\n\t/* create a new array from the same data with ones in the shape */\n\t/* steals a reference to ret */\n\treturn _prepend_ones((PyArrayObject *)ret, nd, ndmin);\n}\n\n/* accepts NULL type */\n/* steals referenct to type */\n/*MULTIARRAY_API\n Empty\n*/\nstatic PyObject *\nPyArray_Empty(int nd, intp *dims, PyArray_Descr *type, int fortran)\n{\n\tPyArrayObject *ret;\n \n\tif (!type) type = PyArray_DescrFromType(PyArray_LONG);\n\tret = (PyArrayObject *)PyArray_NewFromDescr(&PyArray_Type, \n\t\t\t\t\t\t type, nd, dims, \n\t\t\t\t\t\t NULL, NULL,\n\t\t\t\t\t\t fortran, NULL);\n\tif (ret == NULL) return NULL;\n \n\tif ((PyArray_TYPE(ret) == PyArray_OBJECT)) {\n PyArray_FillObjectArray(ret, Py_None);\n\t}\n\treturn (PyObject *)ret;\n}\n\n\nstatic char doc_empty[] = \"empty((d1,...,dn),dtype=int,fortran=0) will return a new array\\n of shape (d1,...,dn) and given type with all its entries uninitialized. This can be faster than zeros.\";\n\nstatic PyObject *\narray_empty(PyObject *ignored, PyObject *args, PyObject *kwds) \n{\n \n\tstatic char *kwlist[] = {\"shape\",\"dtype\",\"fortran\",NULL};\n\tPyArray_Descr *typecode=NULL;\n PyArray_Dims shape = {NULL, 0};\n\tBool fortran = FALSE;\t\n PyObject *ret=NULL;\n\n\tif (!PyArg_ParseTupleAndKeywords(args, kwds, \"O&|O&O&\",\n\t\t\t\t\t kwlist, PyArray_IntpConverter,\n &shape, \n PyArray_DescrConverter,\n\t\t\t\t\t &typecode, \n\t\t\t\t\t PyArray_BoolConverter, &fortran)) \n\t\tgoto fail;\n\n\tret = PyArray_Empty(shape.len, shape.ptr, typecode, fortran); \n PyDimMem_FREE(shape.ptr);\n return ret;\n\n fail:\n\tPyDimMem_FREE(shape.ptr);\n\treturn ret;\n}\n\nstatic char doc_scalar[] = \"scalar(dtype,obj) will return a new scalar array of the given type initialized with obj. Mainly for pickle support. The dtype must be a valid data-type descriptor. If dtype corresponds to an OBJECT descriptor, then obj can be any object, otherwise obj must be a string. If obj is not given it will be interpreted as None for object type and zeros for all other types.\";\n\nstatic PyObject *\narray_scalar(PyObject *ignored, PyObject *args, PyObject *kwds) \n{\n \n\tstatic char *kwlist[] = {\"dtype\",\"obj\", NULL};\n\tPyArray_Descr *typecode;\n\tPyObject *obj=NULL;\n\tint alloc=0;\n\tvoid *dptr;\n\tPyObject *ret;\n\n\t\n\tif (!PyArg_ParseTupleAndKeywords(args, kwds, \"O!|O\",\n\t\t\t\t\t kwlist, &PyArrayDescr_Type, \n\t\t\t\t\t &typecode,\n\t\t\t\t\t &obj)) \n\t\treturn NULL;\n\t\t\n\tif (typecode->elsize == 0) {\n\t\tPyErr_SetString(PyExc_ValueError,\t\t\\\n\t\t\t\t\"itemsize cannot be zero\");\n\t\treturn NULL;\n\t}\n\n\tif (typecode->type_num == PyArray_OBJECT) {\n\t\tif (obj == NULL) obj = Py_None;\n\t\tdptr = &obj;\n\t}\n\telse {\n\t\tif (obj == NULL) {\n\t\t\tdptr = _pya_malloc(typecode->elsize);\n\t\t\tif (dptr == NULL) {\n\t\t\t\treturn PyErr_NoMemory();\n\t\t\t}\n\t\t\tmemset(dptr, '\\0', typecode->elsize);\n\t\t\talloc = 1;\n\t\t}\n\t\telse {\n\t\t\tif (!PyString_Check(obj)) {\n\t\t\t\tPyErr_SetString(PyExc_TypeError, \n\t\t\t\t\t\t\"initializing object must \"\\\n\t\t\t\t\t\t\"be a string\");\n\t\t\t\treturn NULL;\n\t\t\t}\n\t\t\tif (PyString_GET_SIZE(obj) < typecode->elsize) {\n\t\t\t\tPyErr_SetString(PyExc_ValueError,\n\t\t\t\t\t\t\"initialization string is too\"\\\n\t\t\t\t\t\t\" small\");\n\t\t\t\treturn NULL;\n\t\t\t}\n\t\t\tdptr = PyString_AS_STRING(obj);\n\t\t}\n\t}\n\n\tret = PyArray_Scalar(dptr, typecode, NULL);\n\t\n\t/* free dptr which contains zeros */\n\tif (alloc) _pya_free(dptr);\n\treturn ret;\n}\n\n\n/* steal a reference */\n/* accepts NULL type */\n/*MULTIARRAY_API\n Zeros\n*/\nstatic PyObject *\nPyArray_Zeros(int nd, intp *dims, PyArray_Descr *type, int fortran)\n{\n\tPyArrayObject *ret;\n\tintp n;\n\n\tif (!type) type = PyArray_DescrFromType(PyArray_LONG);\n\tret = (PyArrayObject *)PyArray_NewFromDescr(&PyArray_Type, \n\t\t\t\t\t\t type,\n\t\t\t\t\t\t nd, dims, \n\t\t\t\t\t\t NULL, NULL, \n\t\t\t\t\t\t fortran, NULL);\n\tif (ret == NULL) return NULL;\n \n\tif ((PyArray_TYPE(ret) == PyArray_OBJECT)) {\n\t\tPyObject *zero = PyInt_FromLong(0);\n PyArray_FillObjectArray(ret, zero);\n Py_DECREF(zero);\n\t}\n\telse {\n\t\tn = PyArray_NBYTES(ret);\n\t\tmemset(ret->data, 0, n);\n\t}\n\treturn (PyObject *)ret;\n\n}\n\nstatic char doc_zeros[] = \"zeros((d1,...,dn),dtype=int,fortran=0) will return a new array of shape (d1,...,dn) and type typecode with all it's entries initialized to zero.\";\n\n\nstatic PyObject *\narray_zeros(PyObject *ignored, PyObject *args, PyObject *kwds) \n{\n\tstatic char *kwlist[] = {\"shape\",\"dtype\",\"fortran\",NULL}; /* XXX ? */\n\tPyArray_Descr *typecode=NULL;\n PyArray_Dims shape = {NULL, 0};\n\tBool fortran = FALSE;\t\n PyObject *ret=NULL;\n\n\tif (!PyArg_ParseTupleAndKeywords(args, kwds, \"O&|O&O&\",\n\t\t\t\t\t kwlist, PyArray_IntpConverter,\n &shape, \n PyArray_DescrConverter,\n\t\t\t\t\t &typecode, \n\t\t\t\t\t PyArray_BoolConverter,\n\t\t\t\t\t &fortran)) \n\t\tgoto fail;\n\n\tret = PyArray_Zeros(shape.len, shape.ptr, typecode, (int) fortran);\n PyDimMem_FREE(shape.ptr);\n return ret;\n\n fail:\n\tPyDimMem_FREE(shape.ptr);\n\treturn ret;\n}\n\nstatic char doc_set_typeDict[] = \"set_typeDict(dict) set the internal \"\\\n\t\"dictionary that can look up an array type using a registered \"\\\n\t\"code\";\n\nstatic PyObject *\narray_set_typeDict(PyObject *ignored, PyObject *args)\n{\n\tPyObject *dict;\n\tif (!PyArg_ParseTuple(args, \"O\", &dict)) return NULL;\n\tPy_XDECREF(typeDict); /* Decrement old reference (if any)*/\n\ttypeDict = dict;\n\tPy_INCREF(dict); /* Create an internal reference to it */\n\tPy_INCREF(Py_None);\n\treturn Py_None;\n}\n\nstatic int\n_skip_sep(char **ptr, char *sep)\n{\n\tchar *a;\n\tint n;\n\tn = strlen(sep);\n\ta = *ptr;\n\twhile(*a != '\\0' && (strncmp(a, sep, n) != 0))\n\t\ta++;\n\tif (*a == '\\0') return -1;\n\t*ptr = a+strlen(sep);\n\treturn 0;\n}\n\n/* steals a reference to dtype -- accepts NULL */\n/*OBJECT_API*/\nstatic PyObject *\nPyArray_FromString(char *data, intp slen, PyArray_Descr *dtype, \n\t\t intp n, char *sep)\n{\n\tint itemsize;\n\tPyArrayObject *ret;\n\tBool binary;\n\n\tif (dtype == NULL)\n\t\tdtype=PyArray_DescrFromType(PyArray_LONG);\n\t\n\titemsize = dtype->elsize;\n\tif (itemsize == 0) {\n\t\tPyErr_SetString(PyExc_ValueError, \"zero-valued itemsize\");\n\t\tPy_DECREF(dtype);\n\t\treturn NULL;\n\t}\n\n\tbinary = ((sep == NULL) || (strlen(sep) == 0));\t\n\n\tif (binary) {\n\t\tif (dtype == &OBJECT_Descr) {\n\t\t\tPyErr_SetString(PyExc_ValueError, \n\t\t\t\t\t\"Cannot create an object array from\"\\\n\t\t\t\t\t\" a binary string\");\n\t\t\tPy_DECREF(dtype);\n\t\t\treturn NULL;\n\t\t}\t\t\n\t\tif (n < 0 ) {\n\t\t\tif (slen % itemsize != 0) {\n\t\t\t\tPyErr_SetString(PyExc_ValueError, \n\t\t\t\t\t\t\"string size must be a \"\\\n\t\t\t\t\t\t\"multiple of element size\");\n\t\t\t\tPy_DECREF(dtype);\n\t\t\t\treturn NULL;\n\t\t\t}\n\t\t\tn = slen/itemsize;\n\t\t} else {\n\t\t\tif (slen < n*itemsize) {\n\t\t\t\tPyErr_SetString(PyExc_ValueError, \n\t\t\t\t\t\t\"string is smaller than \" \\\n\t\t\t\t\t\t\"requested size\");\n\t\t\t\tPy_DECREF(dtype);\n\t\t\t\treturn NULL;\n\t\t\t}\n\t\t}\n\t\n\t\tif ((ret = (PyArrayObject *)\\\n\t\t PyArray_NewFromDescr(&PyArray_Type, dtype,\n\t\t\t\t\t 1, &n, NULL, NULL,\n\t\t\t\t\t 0, NULL)) == NULL)\n\t\t\treturn NULL;\t\t\n\t\tmemcpy(ret->data, data, n*dtype->elsize);\n\t\treturn (PyObject *)ret;\n\t}\n\telse { /* read from character-based string */\n\t\tchar *ptr;\t\t\n\t\tPyArray_FromStrFunc *fromstr;\n\t\tchar *dptr;\n\t\tintp nread=0;\n\t\tintp index;\n\n\t\tfromstr = dtype->f->fromstr;\n\t\tif (fromstr == NULL) {\n\t\t\tPyErr_SetString(PyExc_ValueError, \n\t\t\t\t\t\"don't know how to read \"\t\\\n\t\t\t\t\t\"character strings for given \"\t\\\n\t\t\t\t\t\"array type\");\n\t\t\tPy_DECREF(dtype);\n\t\t\treturn NULL;\n\t\t}\n\n\t\tif (n!=-1) {\n\t\t\tret = (PyArrayObject *) \\\n\t\t\t\tPyArray_NewFromDescr(&PyArray_Type,\n\t\t\t\t\t\t dtype, 1, &n, NULL,\n\t\t\t\t\t\t NULL, 0, NULL);\n\t\t\tif (ret == NULL) return NULL;\n\t\t\tptr = data;\n\t\t\tdptr = ret->data;\n\t\t\tfor (index=0; index < n; index++) {\n\t\t\t\tif (fromstr(ptr, dptr, &ptr, ret) < 0)\n\t\t\t\t\tbreak;\n\t\t\t\tnread += 1;\n\t\t\t\tdptr += dtype->elsize;\n\t\t\t\tif (_skip_sep(&ptr, sep) < 0) \n\t\t\t\t\tbreak;\n\t\t\t}\n\t\t\tif (nread < n) {\n\t\t\t\tfprintf(stderr, \"%ld items requested but \"\\\n\t\t\t\t\t\"only %ld read\\n\", \n\t\t\t\t\t(long) n, (long) nread);\n\t\t\t\tret->data = \\\n\t\t\t\t\tPyDataMem_RENEW(ret->data, \n\t\t\t\t\t\t\tnread *\t\t\\\n\t\t\t\t\t\t\tret->descr->elsize);\n\t\t\t\tPyArray_DIM(ret,0) = nread;\n\t\t\t}\n\t\t}\n\t\telse {\n#define _FILEBUFNUM 4096\n\t\t\tintp thisbuf=0;\n\t\t\tintp size = _FILEBUFNUM;\n\t\t\tintp bytes;\n\t\t\tintp totalbytes;\n\t\t\tchar *end;\n\t\t\tint val;\n\n\t\t\tret = (PyArrayObject *)\\\n\t\t\t\tPyArray_NewFromDescr(&PyArray_Type, \n\t\t\t\t\t\t dtype,\n\t\t\t\t\t\t 1, &size, \n\t\t\t\t\t\t NULL, NULL, \n\t\t\t\t\t\t 0, NULL);\n\t\t\tif (ret==NULL) return NULL;\n\t\t\ttotalbytes = bytes = size * dtype->elsize;\n\t\t\tdptr = ret->data;\n\t\t\tptr = data;\n\t\t\tend = data+slen;\n\t\t\twhile (ptr < end) {\n\t\t\t\tval = fromstr(ptr, dptr, &ptr, ret);\n\t\t\t\tif (val < 0) break;\n\t\t\t\tnread += 1;\n\t\t\t\tval = _skip_sep(&ptr, sep);\n\t\t\t\tif (val < 0) break;\n\t\t\t\tthisbuf += 1;\n\t\t\t\tdptr += dtype->elsize;\n\t\t\t\tif (thisbuf == size) {\n\t\t\t\t\ttotalbytes += bytes;\n\t\t\t\t\tret->data = PyDataMem_RENEW(ret->data, \n\t\t\t\t\t\t\t\t totalbytes);\n\t\t\t\t\tdptr = ret->data + \\\n\t\t\t\t\t\t(totalbytes - bytes);\n\t\t\t\t\tthisbuf = 0;\n\t\t\t\t}\n\t\t\t}\n\t\t\tret->data = PyDataMem_RENEW(ret->data, \n\t\t\t\t\t\t nread*ret->descr->elsize);\n\t\t\tPyArray_DIM(ret,0) = nread;\n#undef _FILEBUFNUM\n\t\t}\n\t}\n\treturn (PyObject *)ret;\n}\n\nstatic char doc_fromString[] = \"fromstring(string, dtype=int, count=-1) returns a new 1d array initialized from the raw binary data in string. If count is positive, the new array will have count elements, otherwise it's size is determined by the size of string.\";\n\nstatic PyObject *\narray_fromString(PyObject *ignored, PyObject *args, PyObject *keywds)\n{\n\tchar *data;\n\tlonglong nin=-1;\n\tchar *sep=NULL;\n\tint s;\n\tstatic char *kwlist[] = {\"string\", \"dtype\", \"count\", \"sep\", NULL};\n\tPyArray_Descr *descr=NULL;\n\n\tif (!PyArg_ParseTupleAndKeywords(args, keywds, \"s#|O&Ls\", kwlist, \n\t\t\t\t\t &data, &s, \n\t\t\t\t\t PyArray_DescrConverter, &descr,\n\t\t\t\t\t &nin, &sep)) {\n\t\treturn NULL;\n\t}\n\n\treturn PyArray_FromString(data, (intp)s, descr, (intp)nin, sep);\n}\n\n/* This needs an open file object and reads it in directly. \n memory-mapped files handled differently through buffer interface.\n\nfile pointer number in resulting 1d array \n(can easily reshape later, -1 for to end of file)\ntype of array\nsep is a separator string for character-based data (or NULL for binary)\n \" \" means whitespace\n*/\n\n/*OBJECT_API*/\nstatic PyObject *\nPyArray_FromFile(FILE *fp, PyArray_Descr *typecode, intp num, char *sep)\n{\n\tPyArrayObject *r;\n\tsize_t nread = 0;\n\tPyArray_ScanFunc *scan;\n\tBool binary;\n\n\tif (typecode->elsize == 0) {\n\t\tPyErr_SetString(PyExc_ValueError, \"0-sized elements.\");\n\t\tPy_DECREF(typecode);\n\t\treturn NULL;\n\t}\n\n\tbinary = ((sep == NULL) || (strlen(sep) == 0));\n\tif (num == -1 && binary) { /* Get size for binary file*/\n\t\tintp start, numbytes;\n\t\tstart = (intp )ftell(fp);\n\t\tfseek(fp, 0, SEEK_END);\n\t\tnumbytes = (intp )ftell(fp) - start;\n\t\trewind(fp);\n\t\tif (numbytes == -1) {\n\t\t\tPyErr_SetString(PyExc_IOError, \n\t\t\t\t\t\"could not seek in file\");\n\t\t\tPy_DECREF(typecode);\n\t\t\treturn NULL;\n\t\t}\n\t\tnum = numbytes / typecode->elsize;\n\t}\n\t\n\tif (binary) { /* binary data */\n\t\tr = (PyArrayObject *)PyArray_NewFromDescr(&PyArray_Type, \n\t\t\t\t\t\t\t typecode,\n\t\t\t\t\t\t\t 1, &num, \n\t\t\t\t\t\t\t NULL, NULL, \n\t\t\t\t\t\t\t 0, NULL);\n\t\tif (r==NULL) return NULL;\n\t\tnread = fread(r->data, typecode->elsize, num, fp);\n\t}\n\telse { /* character reading */\n\t\tintp i;\n\t\tchar *dptr;\n\t\tint done=0;\n\n\t\tscan = typecode->f->scanfunc;\n\t\tif (scan == NULL) {\n\t\t\tPyErr_SetString(PyExc_ValueError, \n\t\t\t\t\t\"don't know how to read \"\t\\\n\t\t\t\t\t\"character files with that \"\t\\\n\t\t\t\t\t\"array type\");\n\t\t\tPy_DECREF(typecode);\n\t\t\treturn NULL;\n\t\t}\n\n\t\tif (num != -1) { /* number to read is known */\n\t\t\tr = (PyArrayObject *)\\\n\t\t\t\tPyArray_NewFromDescr(&PyArray_Type, \n\t\t\t\t\t\t typecode, \n\t\t\t\t\t\t 1, &num, \n\t\t\t\t\t\t NULL, NULL, \n\t\t\t\t\t\t 0, NULL);\n\t\t\tif (r==NULL) return NULL;\n\t\t\tdptr = r->data;\n\t\t\tfor (i=0; i < num; i++) {\n\t\t\t\tif (done) break;\n\t\t\t\tdone = scan(fp, dptr, sep, NULL);\n\t\t\t\tif (done < -2) break;\n\t\t\t\tnread += 1;\n\t\t\t\tdptr += r->descr->elsize;\n\t\t\t}\n\t\t\tif (PyErr_Occurred()) {\n\t\t\t\tPy_DECREF(r);\n\t\t\t\treturn NULL;\n\t\t\t}\n\t\t}\n\t\telse { /* we have to watch for the end of the file and \n\t\t\t reallocate at the end */\n#define _FILEBUFNUM 4096\n\t\t\tintp thisbuf=0;\n\t\t\tintp size = _FILEBUFNUM;\n\t\t\tintp bytes;\n\t\t\tintp totalbytes;\n\n\t\t\tr = (PyArrayObject *)\\\n\t\t\t\tPyArray_NewFromDescr(&PyArray_Type, \n\t\t\t\t\t\t typecode,\n\t\t\t\t\t\t 1, &size, \n\t\t\t\t\t\t NULL, NULL, \n\t\t\t\t\t\t 0, NULL);\n\t\t\tif (r==NULL) return NULL;\n\t\t\ttotalbytes = bytes = size * typecode->elsize;\n\t\t\tdptr = r->data;\n\t\t\twhile (!done) {\n\t\t\t\tdone = scan(fp, dptr, sep, NULL);\n\n\t\t\t\t/* end of file reached trying to \n\t\t\t\t scan value. done is 1 or 2\n\t\t\t\t if end of file reached trying to\n\t\t\t\t scan separator. Still good value.\n\t\t\t\t*/\n\t\t\t\tif (done < -2) break;\n\t\t\t\tthisbuf += 1;\n\t\t\t\tnread += 1;\n\t\t\t\tdptr += r->descr->elsize;\n\t\t\t\tif (!done && thisbuf == size) {\n\t\t\t\t\ttotalbytes += bytes;\n\t\t\t\t\tr->data = PyDataMem_RENEW(r->data, \n\t\t\t\t\t\t\t\t totalbytes);\n\t\t\t\t\tdptr = r->data + (totalbytes - bytes);\n\t\t\t\t\tthisbuf = 0;\n\t\t\t\t}\n\t\t\t}\n\t\t\tif (PyErr_Occurred()) {\n\t\t\t\tPy_DECREF(r);\n\t\t\t\treturn NULL;\n\t\t\t}\n\t\t\tr->data = PyDataMem_RENEW(r->data, nread*r->descr->elsize);\n\t\t\tPyArray_DIM(r,0) = nread;\n\t\t\tnum = nread;\n#undef _FILEBUFNUM\n\t\t}\n\t}\n\tif (nread < num) {\n\t\tfprintf(stderr, \"%ld items requested but only %ld read\\n\", \n\t\t\t(long) num, (long) nread);\n\t\tr->data = PyDataMem_RENEW(r->data, nread * r->descr->elsize);\n\t\tPyArray_DIM(r,0) = nread;\n\t}\n\treturn (PyObject *)r;\n}\n\nstatic char doc_fromfile[] = \\\n\t\"fromfile(file=, dtype=int, count=-1, sep='')\\n\"\t\\\n\t\"\\n\"\\\n\t\" Return an array of the given data type from a \\n\"\\\n\t\" (text or binary) file. The file argument can be an open file\\n\"\\\n\t\" or a string with the name of a file to read from. If\\n\"\\\n\t\" count==-1, then the entire file is read, otherwise count is\\n\"\\\n\t\" the number of items of the given type read in. If sep is ''\\n\"\\\n\t\" then read a binary file, otherwise it gives the separator\\n\"\\\n\t\" between elements in a text file.\\n\"\\\n\t\"\\n\"\\\n\t\" WARNING: This function should be used sparingly, as it is not\\n\"\\\n\t\" a platform-independent method of persistence. But it can be \\n\"\\\n\t\" useful to read in simply-formatted or binary data quickly.\";\n\nstatic PyObject *\narray_fromfile(PyObject *ignored, PyObject *args, PyObject *keywds)\n{\n\tPyObject *file=NULL, *ret;\n\tFILE *fp;\n\tchar *sep=\"\";\n\tchar *mode=NULL;\n\tlonglong nin=-1;\n\tstatic char *kwlist[] = {\"file\", \"dtype\", \"count\", \"sep\", NULL};\n\tPyArray_Descr *type=NULL;\n\t\n\tif (!PyArg_ParseTupleAndKeywords(args, keywds, \"O|O&Ls\", kwlist, \n\t\t\t\t\t &file,\n\t\t\t\t\t PyArray_DescrConverter, &type,\n\t\t\t\t\t &nin, &sep)) {\n\t\treturn NULL;\n\t}\n\n\tif (type == NULL) type = PyArray_DescrFromType(PyArray_LONG);\n\n\tif (PyString_Check(file)) {\n\t\tif (sep == \"\") mode=\"rb\";\n\t\telse mode=\"r\";\n\t\tfile = PyFile_FromString(PyString_AS_STRING(file), mode);\n\t\tif (file==NULL) return NULL;\n\t}\n\telse {\n\t\tPy_INCREF(file);\n\t}\n\tfp = PyFile_AsFile(file);\n\tif (fp == NULL) {\n\t\tPyErr_SetString(PyExc_IOError, \n\t\t\t\t\"first argument must be an open file\");\n\t\tPy_DECREF(file);\n\t\treturn NULL;\n\t}\n\tret = PyArray_FromFile(fp, type, (intp) nin, sep);\n\tPy_DECREF(file);\n\treturn ret;\n}\n\n/*OBJECT_API*/\nstatic PyObject *\nPyArray_FromBuffer(PyObject *buf, PyArray_Descr *type, \n\t\t intp count, intp offset) \n{\n\tPyArrayObject *ret;\n\tchar *data;\n\tint ts;\n\tintp s, n;\n\tint itemsize;\n\tint write=1;\n\n\n\tif (type->type_num == PyArray_OBJECT) {\n\t\tPyErr_SetString(PyExc_ValueError, \n\t\t\t\t\"cannot create an OBJECT array from memory\"\\\n\t\t\t\t\" buffer\");\n\t\tPy_DECREF(type);\n\t\treturn NULL;\n\t}\n\tif (type->elsize == 0) {\n\t\tPyErr_SetString(PyExc_ValueError, \n\t\t\t\t\"itemsize cannot be zero in type\");\n\t\tPy_DECREF(type);\n\t\treturn NULL; \t\t\n\t}\n\n\tif (buf->ob_type->tp_as_buffer == NULL || \\\n\t (buf->ob_type->tp_as_buffer->bf_getwritebuffer == NULL &&\t\\\n\t buf->ob_type->tp_as_buffer->bf_getreadbuffer == NULL)) {\n\t\tPyObject *newbuf;\n\t\tnewbuf = PyObject_GetAttrString(buf, \"__buffer__\");\n\t\tif (newbuf == NULL) {Py_DECREF(type); return NULL;}\n\t\tbuf = newbuf;\n\t}\n\telse {Py_INCREF(buf);}\n\n\tif (PyObject_AsWriteBuffer(buf, (void *)&data, &ts)==-1) {\n\t\twrite = 0;\n\t\tPyErr_Clear();\n\t\tif (PyObject_AsReadBuffer(buf, (void *)&data, &ts)==-1) {\n\t\t\tPy_DECREF(buf);\n\t\t\tPy_DECREF(type);\n\t\t\treturn NULL;\n\t\t}\n\t}\n\t\n\tif ((offset < 0) || (offset >= ts)) {\n\t\tPyErr_Format(PyExc_ValueError,\n\t\t\t \"offset must be positive and smaller than %\"\n\t\t\t INTP_FMT, (intp)ts);\n\t}\n\n\tdata += offset;\n\ts = (intp)ts - offset;\n\tn = (intp)count;\n\titemsize = type->elsize;\n\t\n\tif (n < 0 ) {\n\t\tif (s % itemsize != 0) {\n\t\t\tPyErr_SetString(PyExc_ValueError, \n\t\t\t\t\t\"buffer size must be a multiple\"\\\n\t\t\t\t\t\" of element size\");\n\t\t\tPy_DECREF(buf);\n\t\t\tPy_DECREF(type);\n\t\t\treturn NULL;\n\t\t}\n\t\tn = s/itemsize;\n\t} else {\n\t\tif (s < n*itemsize) {\n\t\t\tPyErr_SetString(PyExc_ValueError, \n\t\t\t\t\t\"buffer is smaller than requested\"\\\n\t\t\t\t\t\" size\");\n\t\t\tPy_DECREF(buf);\n\t\t\tPy_DECREF(type);\n\t\t\treturn NULL;\n\t\t}\n\t}\n\t\n\tif ((ret = (PyArrayObject *)PyArray_NewFromDescr(&PyArray_Type, \n\t\t\t\t\t\t\t type, \n\t\t\t\t\t\t\t 1, &n, \n\t\t\t\t\t\t\t NULL, data, \n\t\t\t\t\t\t\t DEFAULT_FLAGS,\n\t\t\t\t\t\t\t NULL)) == NULL) {\n\t\tPy_DECREF(buf);\n\t\treturn NULL;\n\t}\n\t\n\tif (!write) ret->flags &= ~WRITEABLE;\n\n\t/* Store a reference for decref on deallocation */\n\tret->base = buf;\n\tPyArray_UpdateFlags(ret, ALIGNED);\n\treturn (PyObject *)ret;\n}\n\nstatic char doc_frombuffer[] = \\\n\t\"frombuffer(buffer=, dtype=int, count=-1, offset=0)\\n\"\\\n\t\"\\n\"\t\t\t\t\t\t\t\t\\\n\t\" Returns a 1-d array of data type dtype from buffer. The buffer\\n\"\\\n\t\" argument must be an object that exposes the buffer interface.\\n\"\\\n\t\" If count is -1 then the entire buffer is used, otherwise, count\\n\"\\\n\t\" is the size of the output. If offset is given then jump that\\n\"\\\n\t\" far into the buffer. If the buffer has data that is out\\n\" \\\n\t\" not in machine byte-order, than use a propert data type\\n\"\\\n\t\" descriptor. The data will not\\n\" \\\n\t\" be byteswapped, but the array will manage it in future\\n\"\\\n\t\" operations.\\n\";\n\nstatic PyObject *\narray_frombuffer(PyObject *ignored, PyObject *args, PyObject *keywds)\n{\n\tPyObject *obj=NULL;\n\tlonglong nin=-1, offset=0;\n\tstatic char *kwlist[] = {\"buffer\", \"dtype\", \"count\", \"offset\", NULL};\n\tPyArray_Descr *type=NULL;\n\n\tif (!PyArg_ParseTupleAndKeywords(args, keywds, \"O|O&LL\", kwlist, \n\t\t\t\t\t &obj,\n\t\t\t\t\t PyArray_DescrConverter, &type,\n\t\t\t\t\t &nin, &offset)) {\n\t\treturn NULL;\n\t}\n\tif (type==NULL)\n\t\ttype = PyArray_DescrFromType(PyArray_LONG);\n\t\n\treturn PyArray_FromBuffer(obj, type, (intp)nin, (intp)offset);\n}\n\n\nstatic char doc_concatenate[] = \"concatenate((a1,a2,...),axis=None).\";\n\nstatic PyObject *\narray_concatenate(PyObject *dummy, PyObject *args, PyObject *kwds) \n{\n\tPyObject *a0;\n\tint axis=0;\n\tstatic char *kwlist[] = {\"seq\", \"axis\", NULL};\n\t\n\tif (!PyArg_ParseTupleAndKeywords(args, kwds, \"O|O&\", kwlist,\n\t\t\t\t\t &a0,\n\t\t\t\t\t PyArray_AxisConverter, &axis))\n\t\treturn NULL;\n\treturn PyArray_Concatenate(a0, axis);\n}\n\nstatic char doc_innerproduct[] = \\\n\t\"inner(a,b) returns the dot product of two arrays, which has\\n\"\\\n\t\"shape a.shape[:-1] + b.shape[:-1] with elements computed by\\n\" \\\n\t\"the product of the elements from the last dimensions of a and b.\";\n\nstatic PyObject *array_innerproduct(PyObject *dummy, PyObject *args) {\n\tPyObject *b0, *a0;\n\t\n\tif (!PyArg_ParseTuple(args, \"OO\", &a0, &b0)) return NULL;\n\t\n\treturn _ARET(PyArray_InnerProduct(a0, b0));\n}\n\nstatic char doc_matrixproduct[] = \\\n\t\"dot(a,v) returns matrix-multiplication between a and b. \\n\"\\\n\t\"The product-sum is over the last dimension of a and the \\n\"\\\n\t\"second-to-last dimension of b.\";\n\nstatic PyObject *array_matrixproduct(PyObject *dummy, PyObject *args) {\n\tPyObject *v, *a;\n\t\n\tif (!PyArg_ParseTuple(args, \"OO\", &a, &v)) return NULL;\n\t\n\treturn _ARET(PyArray_MatrixProduct(a, v));\n}\n\nstatic char doc_fastCopyAndTranspose[] = \"_fastCopyAndTranspose(a)\";\n\nstatic PyObject *array_fastCopyAndTranspose(PyObject *dummy, PyObject *args) {\n\tPyObject *a0;\n\t\n\tif (!PyArg_ParseTuple(args, \"O\", &a0)) return NULL;\n\t\n\treturn _ARET(PyArray_CopyAndTranspose(a0));\n}\n\nstatic char doc_correlate[] = \"cross_correlate(a,v, mode=0)\";\n\nstatic PyObject *array_correlate(PyObject *dummy, PyObject *args, PyObject *kwds) {\n\tPyObject *shape, *a0;\n\tint mode=0;\n\tstatic char *kwlist[] = {\"a\", \"v\", \"mode\", NULL};\n\t\n\tif (!PyArg_ParseTupleAndKeywords(args, kwds, \"OO|i\", kwlist, \n\t\t\t\t\t &a0, &shape, &mode)) return NULL;\n\t\n\treturn PyArray_Correlate(a0, shape, mode);\n}\n\n\n/*MULTIARRAY_API\n Arange, \n*/\nstatic PyObject *\nPyArray_Arange(double start, double stop, double step, int type_num)\n{\n\tintp length;\n\tPyObject *range;\n\tPyArray_ArrFuncs *funcs;\n\tPyObject *obj;\n\tint ret;\n\n\tlength = (intp ) ceil((stop - start)/step);\n \n\tif (length <= 0) {\n\t\tlength = 0;\n\t\treturn PyArray_New(&PyArray_Type, 1, &length, type_num,\n\t\t\t\t NULL, NULL, 0, 0, NULL);\n\t}\n\n\trange = PyArray_New(&PyArray_Type, 1, &length, type_num, \n\t\t\t NULL, NULL, 0, 0, NULL);\n\tif (range == NULL) return NULL;\n\n\tfuncs = PyArray_DESCR(range)->f; \n\n\t/* place start in the buffer and the next value in the second position */\n\t/* if length > 2, then call the inner loop, otherwise stop */\n\n\tobj = PyFloat_FromDouble(start);\n\tret = funcs->setitem(obj, PyArray_DATA(range), (PyArrayObject *)range);\n\tPy_DECREF(obj);\n\tif (ret < 0) goto fail;\n\tif (length == 1) return range;\n\n\tobj = PyFloat_FromDouble(start + step);\n\tret = funcs->setitem(obj, PyArray_DATA(range)+PyArray_ITEMSIZE(range), \n\t\t\t (PyArrayObject *)range);\n\tPy_DECREF(obj);\n\tif (ret < 0) goto fail;\n\tif (length == 2) return range;\n\n\tif (!funcs->fill) {\n\t\tPyErr_SetString(PyExc_ValueError, \"no fill-function for data-type.\");\n\t\tPy_DECREF(range);\n\t\treturn NULL;\n\t}\n\tfuncs->fill(PyArray_DATA(range), length, (PyArrayObject *)range);\n\tif (PyErr_Occurred()) goto fail;\n\t\n\treturn range;\n\n fail:\n\tPy_DECREF(range);\n\treturn NULL;\n}\n\n/* the formula is \n len = (intp) ceil((start - stop) / step);\n*/\nstatic intp\n_calc_length(PyObject *start, PyObject *stop, PyObject *step, PyObject **next, int cmplx)\n{\n\tintp len;\n\tPyObject *val;\n\tdouble value;\n\t\n\t*next = PyNumber_Subtract(stop, start);\n\tif (!(*next)) return -1;\n\tval = PyNumber_TrueDivide(*next, step);\n\tPy_DECREF(*next); *next=NULL;\n\tif (!val) return -1;\n\tif (cmplx && PyComplex_Check(val)) {\n\t\tvalue = PyComplex_RealAsDouble(val);\n\t\tif (error_converting(value)) {Py_DECREF(val); return -1;}\n\t\tlen = (intp) ceil(value);\n\t\tvalue = PyComplex_ImagAsDouble(val);\n\t\tPy_DECREF(val);\n\t\tif (error_converting(value)) return -1;\n\t\tlen = MIN(len, (intp) ceil(value));\n\t}\n\telse {\n\t\tvalue = PyFloat_AsDouble(val);\n\t\tPy_DECREF(val);\n\t\tif (error_converting(value)) return -1;\n\t\tlen = (intp) ceil(value);\n\t}\n\t\n\tif (len > 0) {\n\t\t*next = PyNumber_Add(start, step);\n\t\tif (!next) return -1;\n\t}\n\treturn len;\n}\n\n/* this doesn't change the references */\n/*MULTIARRAY_API\n ArangeObj,\n*/\nstatic PyObject *\nPyArray_ArangeObj(PyObject *start, PyObject *stop, PyObject *step, PyArray_Descr *dtype) \n{\n\tPyObject *range;\n\tPyArray_ArrFuncs *funcs;\n\tPyObject *next;\n\tintp length;\n\n\tif (!dtype) {\n\t\tPyArray_Descr *deftype;\n\t\tPyArray_Descr *newtype;\n\t\tdeftype = PyArray_DescrFromType(PyArray_LONG);\n\t\tnewtype = PyArray_DescrFromObject(start, deftype);\n\t\tPy_DECREF(deftype);\n\t\tdeftype = newtype;\n\t\tif (stop && stop != Py_None) {\n\t\t\tnewtype = PyArray_DescrFromObject(stop, deftype);\n\t\t\tPy_DECREF(deftype);\n\t\t\tdeftype = newtype;\n\t\t}\n\t\tif (step && step != Py_None) {\n\t\t\tnewtype = PyArray_DescrFromObject(step, deftype);\n\t\t\tPy_DECREF(deftype);\n\t\t\tdeftype = newtype;\n\t\t}\n\t\tdtype = deftype;\n\t}\n\telse Py_INCREF(dtype);\n\n\tif (!step || step == Py_None) {\n\t\tstep = PyInt_FromLong(1);\n\t}\n\telse Py_XINCREF(step);\n\n\tif (!stop || stop == Py_None) {\n\t\tstop = start;\n\t\tstart = PyInt_FromLong(0);\n\t}\n\telse Py_INCREF(start);\n\n\t/* calculate the length and next = start + step*/\n\tlength = _calc_length(start, stop, step, &next, \n\t\t\t PyTypeNum_ISCOMPLEX(dtype->type_num));\n\n\tif (PyErr_Occurred()) {Py_DECREF(dtype); goto fail;}\n\tif (length <= 0) {\n\t\tlength = 0;\n\t\trange = PyArray_SimpleNewFromDescr(1, &length, dtype);\n\t\tPy_DECREF(step); Py_DECREF(start); return range;\n\t}\n\n\trange = PyArray_SimpleNewFromDescr(1, &length, dtype);\n\tif (range == NULL) goto fail;\n\n\tfuncs = PyArray_DESCR(range)->f;\n\n\t/* place start in the buffer and the next value in the second position */\n\t/* if length > 2, then call the inner loop, otherwise stop */\n\n\tif (funcs->setitem(start, PyArray_DATA(range), (PyArrayObject *)range) < 0)\n\t\tgoto fail;\n\tif (length == 1) goto finish;\n\tif (funcs->setitem(next, PyArray_DATA(range)+PyArray_ITEMSIZE(range), \n\t\t\t (PyArrayObject *)range) < 0) goto fail;\n\tif (length == 2) goto finish;\n\n\tif (!funcs->fill) {\n\t\tPyErr_SetString(PyExc_ValueError, \"no fill-function for data-type.\");\n\t\tPy_DECREF(range);\n\t\tgoto fail;\n\t}\n\tfuncs->fill(PyArray_DATA(range), length, (PyArrayObject *)range);\n\tif (PyErr_Occurred()) goto fail;\n\n finish:\n\tPy_DECREF(start);\n\tPy_DECREF(step);\n\tPy_DECREF(next);\n\treturn range;\n\t\n fail:\n\tPy_DECREF(start);\n\tPy_DECREF(step);\n\tPy_XDECREF(next);\n\treturn NULL;\n}\n\n\nstatic char doc_arange[] = \"arange(start, stop=None, step=1, dtype=int)\\n\\n Just like range() except it returns an array whose type can be\\n specified by the keyword argument typecode.\";\n\nstatic PyObject *\narray_arange(PyObject *ignored, PyObject *args, PyObject *kws) {\n\tPyObject *o_start=NULL, *o_stop=NULL, *o_step=NULL;\n\tstatic char *kwd[]= {\"start\", \"stop\", \"step\", \"dtype\", NULL};\n\tPyArray_Descr *typecode=NULL;\n\t\n\tif(!PyArg_ParseTupleAndKeywords(args, kws, \"O|OOO&\", kwd, &o_start,\n\t\t\t\t\t&o_stop, &o_step, \n\t\t\t\t\tPyArray_DescrConverter2,\n\t\t\t\t\t&typecode)) \n\t\treturn NULL;\n\n\treturn PyArray_ArangeObj(o_start, o_stop, o_step, typecode);\n}\n\n/*MULTIARRAY_API\n GetNDArrayCVersion\n*/\nstatic unsigned int\nPyArray_GetNDArrayCVersion(void)\n{\n\treturn (unsigned int)NDARRAY_VERSION;\n}\n\nstatic char \ndoc__get_ndarray_c_version[] = \"_get_ndarray_c_version() gets the compile time NDARRAY_VERSION number\";\n\nstatic PyObject *\narray__get_ndarray_c_version(PyObject *dummy, PyObject *args, PyObject *kwds) \n{\n\tstatic char *kwlist[] = {NULL};\n\tif(!PyArg_ParseTupleAndKeywords(args, kwds, \"\", kwlist )) return NULL;\n\t\n\treturn PyInt_FromLong( (long) PyArray_GetNDArrayCVersion() );\n}\n\nstatic char \ndoc_set_string_function[] = \"set_string_function(f, repr=1) sets the python function f to be the function used to obtain a pretty printable string version of a array whenever a array is printed. f(M) should expect a array argument M, and should return a string consisting of the desired representation of M for printing.\";\n\nstatic PyObject *\narray_set_string_function(PyObject *dummy, PyObject *args, PyObject *kwds) \n{\n\tPyObject *op;\n\tint repr=1;\n\tstatic char *kwlist[] = {\"f\", \"repr\", NULL};\n\n\tif(!PyArg_ParseTupleAndKeywords(args, kwds, \"O|i\", kwlist, \n\t\t\t\t\t&op, &repr)) return NULL; \n\tif (!PyCallable_Check(op)) {\n\t\tPyErr_SetString(PyExc_TypeError, \n\t\t\t\t\"Argument must be callable.\");\n\t\treturn NULL;\n\t}\n\tPyArray_SetStringFunction(op, repr);\n\tPy_INCREF(Py_None);\n\treturn Py_None;\n}\n\nstatic char \ndoc_set_ops_function[] = \"set_numeric_ops(op=func, ...) sets some or all of the number methods for all array objects. Don't forget **dict can be used as the argument list. Returns the functions that were replaced -- can be stored and set later.\";\n\nstatic PyObject *\narray_set_ops_function(PyObject *self, PyObject *args, PyObject *kwds) \n{\n\tPyObject *oldops=NULL;\n\t\n\tif ((oldops = PyArray_GetNumericOps())==NULL) return NULL;\n\n\t/* Should probably ensure that objects are at least callable */\n\t/* Leave this to the caller for now --- error will be raised\n\t later when use is attempted \n\t*/\n\tif (kwds && PyArray_SetNumericOps(kwds) == -1) {\n\t\tPy_DECREF(oldops);\n\t\tPyErr_SetString(PyExc_ValueError, \n\t\t\t\t\"one or more objects not callable\");\n\t\treturn NULL;\n\t}\n\treturn oldops;\n}\n\n\n/*MULTIARRAY_API\n Where\n*/\nstatic PyObject *\nPyArray_Where(PyObject *condition, PyObject *x, PyObject *y)\n{\n\tPyArrayObject *arr;\n\tPyObject *tup=NULL, *obj=NULL;\n\tPyObject *ret=NULL, *zero=NULL;\n\n\n\tarr = (PyArrayObject *)PyArray_FromAny(condition, NULL, 0, 0, 0, NULL);\n\tif (arr == NULL) return NULL;\n\n\tif ((x==NULL) && (y==NULL)) {\n\t\tret = PyArray_Nonzero(arr);\n\t\tPy_DECREF(arr);\n\t\treturn ret;\n\t}\n\n\tif ((x==NULL) || (y==NULL)) {\n\t\tPy_DECREF(arr);\n\t\tPyErr_SetString(PyExc_ValueError, \"either both or neither \"\n\t\t\t\t\"of x and y should be given\");\n\t\treturn NULL;\n\t}\n\n\n\tzero = PyInt_FromLong((long) 0);\n\n\tobj = PyArray_EnsureArray(PyArray_GenericBinaryFunction(arr, zero, \n\t\t\t\t\t\t\t\tn_ops.not_equal));\n\tPy_DECREF(zero);\n\tPy_DECREF(arr);\n\tif (obj == NULL) return NULL;\n\n\ttup = Py_BuildValue(\"(OO)\", y, x);\n\tif (tup == NULL) {Py_DECREF(obj); return NULL;}\n\n\tret = PyArray_Choose((PyAO *)obj, tup);\n\n\tPy_DECREF(obj);\n\tPy_DECREF(tup);\n\treturn ret;\n}\n\nstatic char doc_where[] = \"where(condition, | x, y) is shaped like condition\"\\\n\t\" and has elements of x and y where condition is respectively true or\"\\\n\t\" false. If x or y are not given, then it is equivalent to\"\\\n\t\" nonzero(condition).\";\n\nstatic PyObject *\narray_where(PyObject *ignored, PyObject *args)\n{\n\tPyObject *obj=NULL, *x=NULL, *y=NULL;\n\t\n\tif (!PyArg_ParseTuple(args, \"O|OO\", &obj, &x, &y)) return NULL;\n\n\treturn PyArray_Where(obj, x, y);\n\n}\n\nstatic char doc_lexsort[] = \"lexsort(keys=, axis=-1) returns an array of indexes\"\\\n\t\" similar to argsort except the sorting is done using the provided sorting\"\\\n\t\" keys. First the sort is done using key[0], then the resulting list of\"\\\n\t\" indexes is further manipulated by sorting on key[0]. And so forth\"\\\n\t\" The result is a sort on multiple keys. If the keys represented columns\" \\\n\t\" of a spread-sheet, for example, this would sort using multiple columns.\"\\\n\t\" The keys argument must be a tuple of things that can be converted to \"\\\n\t\" arrays of the same shape.\";\n\nstatic PyObject *\narray_lexsort(PyObject *ignored, PyObject *args, PyObject *kwds)\n{\n\tint axis=-1;\n\tPyObject *obj;\n\tstatic char *kwlist[] = {\"keys\", \"axis\", NULL};\n\t\n\tif (!PyArg_ParseTupleAndKeywords(args, kwds, \"O!|i\", kwlist, \n\t\t\t\t\t &PyTuple_Type, &obj, &axis)) return NULL;\n\t\n\treturn _ARET(PyArray_LexSort(obj, axis));\n}\n\n#undef _ARET\n\n\nstatic char doc_register_dtype[] = \\\n\t\"register_dtype(a) registers a new type object -- gives it a typenum\";\n\nstatic PyObject *\narray_register_dtype(PyObject *dummy, PyObject *args)\n{\n\tPyObject *dtype;\n\tint ret;\n\t\n\tif (!PyArg_ParseTuple(args, \"O\", &dtype)) return NULL;\n\t\n\tret = PyArray_RegisterDataType((PyTypeObject *)dtype);\n\tif (ret < 0)\n\t\treturn NULL;\n\treturn PyInt_FromLong((long) ret);\n}\n\nstatic char doc_can_cast_safely[] = \\\n\t\"can_cast_safely(from=d1, to=d2) returns True if data type d1 \"\\\n\t\"can be cast to data type d2 without losing precision.\";\n\nstatic PyObject *\narray_can_cast_safely(PyObject *dummy, PyObject *args, PyObject *kwds)\n{\n\tPyArray_Descr *d1=NULL;\n\tPyArray_Descr *d2=NULL;\n\tBool ret;\n\tPyObject *retobj;\n\tstatic char *kwlist[] = {\"from\", \"to\", NULL};\n\n\tif(!PyArg_ParseTupleAndKeywords(args, kwds, \"O&O&\", kwlist, \n\t\t\t\t\tPyArray_DescrConverter, &d1,\n\t\t\t\t\tPyArray_DescrConverter, &d2))\n\t\treturn NULL;\n\tif (d1 == NULL || d2 == NULL) {\n\t\tPyErr_SetString(PyExc_TypeError, \n\t\t\t\t\"did not understand one of the types; \"\t\\\n\t\t\t\t\"'None' not accepted\");\n\t\treturn NULL;\n\t}\n\t\t\n\tret = PyArray_CanCastTo(d1, d2);\n\tretobj = (ret ? Py_True : Py_False);\n\tPy_INCREF(retobj);\n\treturn retobj;\n}\n\nstatic char doc_new_buffer[] = \\\n\t\"newbuffer(size) return a new uninitialized buffer object of size \"\n\t\"bytes\";\n\nstatic PyObject *\nnew_buffer(PyObject *dummy, PyObject *args)\n{\n\tint size;\n\n\tif(!PyArg_ParseTuple(args, \"i\", &size))\n\t\treturn NULL;\n\t\n\treturn PyBuffer_New(size);\n}\n\nstatic char doc_buffer_buffer[] = \\\n\t\"getbuffer(obj [,offset[, size]]) create a buffer object from the \"\\\n\t\"given object\\n referencing a slice of length size starting at \"\\\n\t\"offset. Default\\n is the entire buffer. A read-write buffer is \"\\\n\t\"attempted followed by a read-only buffer.\";\n\nstatic PyObject *\nbuffer_buffer(PyObject *dummy, PyObject *args, PyObject *kwds)\n{\n\tPyObject *obj;\n\tint offset=0, size=Py_END_OF_BUFFER, n;\n\tvoid *unused;\n\tstatic char *kwlist[] = {\"object\", \"offset\", \"size\", NULL};\n\t\n\tif (!PyArg_ParseTupleAndKeywords(args, kwds, \"O|ii\", kwlist, \n\t\t\t\t\t &obj, &offset, &size))\n\t\treturn NULL;\n\n\n\tif (PyObject_AsWriteBuffer(obj, &unused, &n) < 0) {\n\t\tPyErr_Clear();\n\t\treturn PyBuffer_FromObject(obj, offset, size);\t\t\n\t}\n\telse\n\t\treturn PyBuffer_FromReadWriteObject(obj, offset, size);\n}\n\n\nstatic struct PyMethodDef array_module_methods[] = {\n\t{\"_get_ndarray_c_version\", (PyCFunction)array__get_ndarray_c_version, \n\t METH_VARARGS|METH_KEYWORDS, doc__get_ndarray_c_version},\n\t{\"set_string_function\", (PyCFunction)array_set_string_function, \n\t METH_VARARGS|METH_KEYWORDS, doc_set_string_function},\n\t{\"set_numeric_ops\", (PyCFunction)array_set_ops_function,\n\t METH_VARARGS|METH_KEYWORDS, doc_set_ops_function},\n\t{\"set_typeDict\", (PyCFunction)array_set_typeDict,\n\t METH_VARARGS, doc_set_typeDict},\n\n\t{\"array\",\t(PyCFunction)_array_fromobject, \n\t METH_VARARGS|METH_KEYWORDS, doc_fromobject},\n\t{\"arange\", (PyCFunction)array_arange, \n\t METH_VARARGS|METH_KEYWORDS, doc_arange},\n\t{\"zeros\",\t(PyCFunction)array_zeros, \n\t METH_VARARGS|METH_KEYWORDS, doc_zeros},\n\t{\"empty\",\t(PyCFunction)array_empty, \n\t METH_VARARGS|METH_KEYWORDS, doc_empty},\n\t{\"scalar\", (PyCFunction)array_scalar,\n\t METH_VARARGS|METH_KEYWORDS, doc_scalar},\n\t{\"where\", (PyCFunction)array_where,\n\t METH_VARARGS, doc_where},\n\t{\"lexsort\", (PyCFunction)array_lexsort,\n\t METH_VARARGS | METH_KEYWORDS, doc_lexsort},\n\t{\"fromstring\",(PyCFunction)array_fromString,\n\t METH_VARARGS|METH_KEYWORDS, doc_fromString},\n\t{\"concatenate\", (PyCFunction)array_concatenate, \n\t METH_VARARGS|METH_KEYWORDS, doc_concatenate},\n\t{\"inner\", (PyCFunction)array_innerproduct, \n\t METH_VARARGS, doc_innerproduct}, \n\t{\"dot\", (PyCFunction)array_matrixproduct, \n\t METH_VARARGS, doc_matrixproduct}, \n\t{\"_fastCopyAndTranspose\", (PyCFunction)array_fastCopyAndTranspose, \n\t METH_VARARGS, doc_fastCopyAndTranspose},\n\t{\"correlate\", (PyCFunction)array_correlate, \n\t METH_VARARGS | METH_KEYWORDS, doc_correlate},\n\t{\"frombuffer\", (PyCFunction)array_frombuffer,\n\t METH_VARARGS | METH_KEYWORDS, doc_frombuffer},\n\t{\"fromfile\", (PyCFunction)array_fromfile,\n\t METH_VARARGS | METH_KEYWORDS, doc_fromfile},\n\t{\"register_dtype\", (PyCFunction)array_register_dtype,\n\t METH_VARARGS, doc_register_dtype},\n\t{\"can_cast\", (PyCFunction)array_can_cast_safely,\n\t METH_VARARGS | METH_KEYWORDS, doc_can_cast_safely},\t\t\n\t{\"newbuffer\", (PyCFunction)new_buffer,\n\t METH_VARARGS, doc_new_buffer},\t\n\t{\"getbuffer\", (PyCFunction)buffer_buffer,\n\t METH_VARARGS | METH_KEYWORDS, doc_buffer_buffer},\t\n\t{NULL,\t\tNULL, 0}\t\t/* sentinel */\n};\n\n#include \"__multiarray_api.c\"\n\n/* Establish scalar-type hierarchy */\n\n/* For dual inheritance we need to make sure that the objects being\n inherited from have the tp->mro object initialized. This is\n not necessarily true for the basic type objects of Python (it is \n checked for single inheritance but not dual in PyType_Ready).\n\n Thus, we call PyType_Ready on the standard Python Types, here.\n*/ \nstatic int\nsetup_scalartypes(PyObject *dict)\n{\n\n\tinitialize_numeric_types();\n\n if (PyType_Ready(&PyBool_Type) < 0) return -1;\n if (PyType_Ready(&PyInt_Type) < 0) return -1;\n if (PyType_Ready(&PyFloat_Type) < 0) return -1;\n if (PyType_Ready(&PyComplex_Type) < 0) return -1;\n if (PyType_Ready(&PyString_Type) < 0) return -1;\n if (PyType_Ready(&PyUnicode_Type) < 0) return -1;\n\n#define SINGLE_INHERIT(child, parent) \\\n Py##child##ArrType_Type.tp_base = &Py##parent##ArrType_Type;\t\\\n if (PyType_Ready(&Py##child##ArrType_Type) < 0) {\t\t\\\n PyErr_Print(); \\\n PyErr_Format(PyExc_SystemError, \\\n\t\t\t \"could not initialize Py%sArrType_Type\", \\\n #child); \\\n return -1;\t\t\t\t\t\t\\\n }\n \n if (PyType_Ready(&PyGenericArrType_Type) < 0)\n return -1;\n\n SINGLE_INHERIT(Number, Generic);\n SINGLE_INHERIT(Integer, Number);\n SINGLE_INHERIT(Inexact, Number);\n SINGLE_INHERIT(SignedInteger, Integer);\n SINGLE_INHERIT(UnsignedInteger, Integer);\n SINGLE_INHERIT(Floating, Inexact);\n SINGLE_INHERIT(ComplexFloating, Inexact);\n SINGLE_INHERIT(Flexible, Generic);\n SINGLE_INHERIT(Character, Flexible);\n\t\n#define DUAL_INHERIT(child, parent1, parent2) \\\n Py##child##ArrType_Type.tp_base = &Py##parent2##ArrType_Type;\t\\\n Py##child##ArrType_Type.tp_bases = \\\n Py_BuildValue(\"(OO)\", &Py##parent2##ArrType_Type,\t\\\n\t\t\t &Py##parent1##_Type);\t\t\t\\\n if (PyType_Ready(&Py##child##ArrType_Type) < 0) { \\\n PyErr_Print(); \\\n\t\tPyErr_Format(PyExc_SystemError, \\\n\t\t\t \"could not initialize Py%sArrType_Type\", \\\n #child); \\\n return -1; \\\n }\\\n Py##child##ArrType_Type.tp_hash = Py##parent1##_Type.tp_hash;\n\n#define DUAL_INHERIT2(child, parent1, parent2)\t\t\t\t\\\n Py##child##ArrType_Type.tp_base = &Py##parent1##_Type;\t\t\\\n Py##child##ArrType_Type.tp_bases = \\\n Py_BuildValue(\"(OO)\", &Py##parent1##_Type,\t\t\\\n\t\t\t &Py##parent2##ArrType_Type);\t\t\\\n\tPy##child##ArrType_Type.tp_richcompare =\t\t\t\\\n\t\tPy##parent1##_Type.tp_richcompare;\t\t\t\\\n\tPy##child##ArrType_Type.tp_compare =\t\t\t\t\\\n\t\tPy##parent1##_Type.tp_compare;\t\t\t\t\\\n Py##child##ArrType_Type.tp_hash = Py##parent1##_Type.tp_hash;\t\\\n if (PyType_Ready(&Py##child##ArrType_Type) < 0) { \\\n PyErr_Print(); \\\n\t\tPyErr_Format(PyExc_SystemError, \\\n\t\t\t \"could not initialize Py%sArrType_Type\", \\\n #child); \\\n return -1; \\\n }\n\n SINGLE_INHERIT(Bool, Generic);\n SINGLE_INHERIT(Byte, SignedInteger);\n SINGLE_INHERIT(Short, SignedInteger);\n#if SIZEOF_INT == SIZEOF_LONG\n DUAL_INHERIT(Int, Int, SignedInteger);\n#else\n SINGLE_INHERIT(Int, SignedInteger);\n#endif\n DUAL_INHERIT(Long, Int, SignedInteger);\n#if SIZEOF_LONGLONG == SIZEOF_LONG\n DUAL_INHERIT(LongLong, Int, SignedInteger);\n#else\n SINGLE_INHERIT(LongLong, SignedInteger);\n#endif\n\n /* fprintf(stderr, \"tp_free = %p, PyObject_Del = %p, int_tp_free = %p, base.tp_free = %p\\n\", PyIntArrType_Type.tp_free, PyObject_Del, PyInt_Type.tp_free, PySignedIntegerArrType_Type.tp_free);\n\t */\n\tSINGLE_INHERIT(UByte, UnsignedInteger);\n SINGLE_INHERIT(UShort, UnsignedInteger);\n SINGLE_INHERIT(UInt, UnsignedInteger);\n SINGLE_INHERIT(ULong, UnsignedInteger);\n SINGLE_INHERIT(ULongLong, UnsignedInteger);\n\n SINGLE_INHERIT(Float, Floating);\n DUAL_INHERIT(Double, Float, Floating);\n SINGLE_INHERIT(LongDouble, Floating);\n\n SINGLE_INHERIT(CFloat, ComplexFloating);\n DUAL_INHERIT(CDouble, Complex, ComplexFloating);\n SINGLE_INHERIT(CLongDouble, ComplexFloating);\n\n DUAL_INHERIT2(String, String, Character);\n DUAL_INHERIT2(Unicode, Unicode, Character);\n\t\n SINGLE_INHERIT(Void, Flexible);\n \n SINGLE_INHERIT(Object, Generic);\n\n return 0;\n\n#undef SINGLE_INHERIT\n#undef DUAL_INHERIT\n\n\t/* Clean up string and unicode array types so they act more like\n\t strings -- get their tables from the standard types.\n\t*/\n}\n\n/* place a flag dictionary in d */\n\nstatic void\nset_flaginfo(PyObject *d)\n{\n PyObject *s;\n PyObject *newd;\n \n newd = PyDict_New();\n\n PyDict_SetItemString(newd, \"OWNDATA\", s=PyInt_FromLong(OWNDATA));\n Py_DECREF(s);\n PyDict_SetItemString(newd, \"FORTRAN\", s=PyInt_FromLong(FORTRAN));\n Py_DECREF(s);\n PyDict_SetItemString(newd, \"CONTIGUOUS\", s=PyInt_FromLong(CONTIGUOUS));\n Py_DECREF(s);\n PyDict_SetItemString(newd, \"ALIGNED\", s=PyInt_FromLong(ALIGNED));\n Py_DECREF(s);\n\n PyDict_SetItemString(newd, \"UPDATEIFCOPY\", s=PyInt_FromLong(UPDATEIFCOPY));\n Py_DECREF(s);\n PyDict_SetItemString(newd, \"WRITEABLE\", s=PyInt_FromLong(WRITEABLE));\n Py_DECREF(s);\n \n PyDict_SetItemString(d, \"_flagdict\", newd);\n Py_DECREF(newd);\n return;\n}\n\n\n/* Initialization function for the module */\n\nDL_EXPORT(void) initmultiarray(void) {\n\tPyObject *m, *d, *s;\n\tPyObject *c_api;\n\t\n\t/* Create the module and add the functions */\n\tm = Py_InitModule(\"multiarray\", array_module_methods);\n\tif (!m) goto err;\n\n\t/* Add some symbolic constants to the module */\n\td = PyModule_GetDict(m);\n\tif (!d) goto err; \n\n\t/* Create the module and add the functions */\n\tif (PyType_Ready(&PyBigArray_Type) < 0) \n\t\treturn;\n\n PyArray_Type.tp_base = &PyBigArray_Type;\n\n PyArray_Type.tp_as_mapping = &array_as_mapping;\n\t/* Even though, this would be inherited, it needs to be set now\n\t so that the __getitem__ will map to the as_mapping descriptor\n\t*/\n PyArray_Type.tp_as_number = &array_as_number; \n\t/* For good measure */\n\tPyArray_Type.tp_as_sequence = &array_as_sequence;\n\tPyArray_Type.tp_as_buffer = &array_as_buffer;\t\n PyArray_Type.tp_flags = (Py_TPFLAGS_DEFAULT \n\t\t\t\t | Py_TPFLAGS_BASETYPE\n\t\t\t\t | Py_TPFLAGS_CHECKTYPES);\n PyArray_Type.tp_doc = Arraytype__doc__;\n\n\tif (PyType_Ready(&PyArray_Type) < 0)\n return;\n\n if (setup_scalartypes(d) < 0) goto err;\n\n\tPyArrayIter_Type.tp_iter = PyObject_SelfIter;\n\tPyArrayMultiIter_Type.tp_iter = PyObject_SelfIter;\n\tif (PyType_Ready(&PyArrayIter_Type) < 0)\n\t\treturn; \n \n\tif (PyType_Ready(&PyArrayMapIter_Type) < 0)\n return; \n\n\tif (PyType_Ready(&PyArrayMultiIter_Type) < 0)\n\t\treturn;\n\n\tif (PyType_Ready(&PyArrayDescr_Type) < 0)\n\t\treturn;\n\n\tc_api = PyCObject_FromVoidPtr((void *)PyArray_API, NULL);\n\tif (PyErr_Occurred()) goto err;\n\tPyDict_SetItemString(d, \"_ARRAY_API\", c_api);\n\tPy_DECREF(c_api);\n\tif (PyErr_Occurred()) goto err;\n\n\tMultiArrayError = PyString_FromString (\"multiarray.error\");\n\tPyDict_SetItemString (d, \"error\", MultiArrayError);\n\t\n\ts = PyString_FromString(\"3.0\");\n\tPyDict_SetItemString(d, \"__version__\", s);\n\tPy_DECREF(s);\n Py_INCREF(&PyBigArray_Type);\n\tPyDict_SetItemString(d, \"bigndarray\", (PyObject *)&PyBigArray_Type);\n Py_INCREF(&PyArray_Type);\n\tPyDict_SetItemString(d, \"ndarray\", (PyObject *)&PyArray_Type);\n Py_INCREF(&PyArrayIter_Type);\n\tPyDict_SetItemString(d, \"flatiter\", (PyObject *)&PyArrayIter_Type);\n Py_INCREF(&PyArrayMultiIter_Type);\n\tPyDict_SetItemString(d, \"broadcast\", \n\t\t\t (PyObject *)&PyArrayMultiIter_Type);\n\tPy_INCREF(&PyArrayDescr_Type);\n\tPyDict_SetItemString(d, \"dtype\", (PyObject *)&PyArrayDescr_Type);\n\n\t/* Doesn't need to be exposed to Python \n Py_INCREF(&PyArrayMapIter_Type);\n\tPyDict_SetItemString(d, \"mapiter\", (PyObject *)&PyArrayMapIter_Type);\n\t*/\n set_flaginfo(d);\n\n\tif (set_typeinfo(d) != 0) goto err;\n\n\t_numpy_internal =\t\t\t\t\t\t\\\n\t\tPyImport_ImportModule(\"numpy.core._internal\");\n\tif (_numpy_internal != NULL) return;\n\n err:\t\n\tif (!PyErr_Occurred()) {\n\t\tPyErr_SetString(PyExc_RuntimeError, \n\t\t\t\t\"cannot load multiarray module.\");\n\t}\n\treturn;\n}\n\n", + "methods": [ + { + "name": "_arraydescr_fromobj", + "long_name": "_arraydescr_fromobj( PyObject * obj)", + "filename": "multiarraymodule.c", + "nloc": 15, + "complexity": 3, + "token_count": 67, + "parameters": [ + "obj" + ], + "start_line": 35, + "end_line": 50, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 16, + "top_nesting_level": 0 + }, + { + "name": "PyArray_MultiplyIntList", + "long_name": "PyArray_MultiplyIntList( register int * l1 , register int n)", + "filename": "multiarraymodule.c", + "nloc": 6, + "complexity": 2, + "token_count": 36, + "parameters": [ + "l1", + "n" + ], + "start_line": 75, + "end_line": 80, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 6, + "top_nesting_level": 0 + }, + { + "name": "PyArray_MultiplyList", + "long_name": "PyArray_MultiplyList( register intp * l1 , register int n)", + "filename": "multiarraymodule.c", + "nloc": 6, + "complexity": 2, + "token_count": 36, + "parameters": [ + "l1", + "n" + ], + "start_line": 86, + "end_line": 91, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 6, + "top_nesting_level": 0 + }, + { + "name": "PyArray_GetPtr", + "long_name": "PyArray_GetPtr( PyArrayObject * obj , register intp * ind)", + "filename": "multiarraymodule.c", + "nloc": 8, + "complexity": 2, + "token_count": 61, + "parameters": [ + "obj", + "ind" + ], + "start_line": 97, + "end_line": 105, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 9, + "top_nesting_level": 0 + }, + { + "name": "PyArray_AxisConverter", + "long_name": "PyArray_AxisConverter( PyObject * obj , int * axis)", + "filename": "multiarraymodule.c", + "nloc": 13, + "complexity": 3, + "token_count": 53, + "parameters": [ + "obj", + "axis" + ], + "start_line": 111, + "end_line": 123, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 13, + "top_nesting_level": 0 + }, + { + "name": "PyArray_CompareLists", + "long_name": "PyArray_CompareLists( intp * l1 , intp * l2 , int n)", + "filename": "multiarraymodule.c", + "nloc": 8, + "complexity": 3, + "token_count": 51, + "parameters": [ + "l1", + "l2", + "n" + ], + "start_line": 129, + "end_line": 136, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 8, + "top_nesting_level": 0 + }, + { + "name": "PyArray_View", + "long_name": "PyArray_View( PyArrayObject * self , PyArray_Descr * type , PyTypeObject * pytype)", + "filename": "multiarraymodule.c", + "nloc": 27, + "complexity": 5, + "token_count": 158, + "parameters": [ + "self", + "type", + "pytype" + ], + "start_line": 143, + "end_line": 173, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 31, + "top_nesting_level": 0 + }, + { + "name": "PyArray_Ravel", + "long_name": "PyArray_Ravel( PyArrayObject * a , int fortran)", + "filename": "multiarraymodule.c", + "nloc": 16, + "complexity": 5, + "token_count": 102, + "parameters": [ + "a", + "fortran" + ], + "start_line": 179, + "end_line": 196, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 18, + "top_nesting_level": 0 + }, + { + "name": "PyArray_Flatten", + "long_name": "PyArray_Flatten( PyArrayObject * a , int fortran)", + "filename": "multiarraymodule.c", + "nloc": 33, + "complexity": 6, + "token_count": 176, + "parameters": [ + "a", + "fortran" + ], + "start_line": 202, + "end_line": 237, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 36, + "top_nesting_level": 0 + }, + { + "name": "PyArray_Reshape", + "long_name": "PyArray_Reshape( PyArrayObject * self , PyObject * shape)", + "filename": "multiarraymodule.c", + "nloc": 9, + "complexity": 2, + "token_count": 53, + "parameters": [ + "self", + "shape" + ], + "start_line": 248, + "end_line": 257, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 10, + "top_nesting_level": 0 + }, + { + "name": "_check_ones", + "long_name": "_check_ones( PyArrayObject * self , int newnd , intp * newdims , intp * strides)", + "filename": "multiarraymodule.c", + "nloc": 25, + "complexity": 12, + "token_count": 189, + "parameters": [ + "self", + "newnd", + "newdims", + "strides" + ], + "start_line": 260, + "end_line": 286, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 27, + "top_nesting_level": 0 + }, + { + "name": "PyArray_Newshape", + "long_name": "PyArray_Newshape( PyArrayObject * self , PyArray_Dims * newdims)", + "filename": "multiarraymodule.c", + "nloc": 72, + "complexity": 17, + "token_count": 409, + "parameters": [ + "self", + "newdims" + ], + "start_line": 297, + "end_line": 384, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 88, + "top_nesting_level": 0 + }, + { + "name": "PyArray_Squeeze", + "long_name": "PyArray_Squeeze( PyArrayObject * self)", + "filename": "multiarraymodule.c", + "nloc": 34, + "complexity": 5, + "token_count": 204, + "parameters": [ + "self" + ], + "start_line": 393, + "end_line": 428, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 36, + "top_nesting_level": 0 + }, + { + "name": "PyArray_Mean", + "long_name": "PyArray_Mean( PyArrayObject * self , int axis , int rtype)", + "filename": "multiarraymodule.c", + "nloc": 19, + "complexity": 4, + "token_count": 139, + "parameters": [ + "self", + "axis", + "rtype" + ], + "start_line": 435, + "end_line": 456, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 22, + "top_nesting_level": 0 + }, + { + "name": "PyArray_Std", + "long_name": "PyArray_Std( PyArrayObject * self , int axis , int rtype , int variance)", + "filename": "multiarraymodule.c", + "nloc": 45, + "complexity": 13, + "token_count": 450, + "parameters": [ + "self", + "axis", + "rtype", + "variance" + ], + "start_line": 463, + "end_line": 522, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 60, + "top_nesting_level": 0 + }, + { + "name": "PyArray_Sum", + "long_name": "PyArray_Sum( PyArrayObject * self , int axis , int rtype)", + "filename": "multiarraymodule.c", + "nloc": 9, + "complexity": 2, + "token_count": 69, + "parameters": [ + "self", + "axis", + "rtype" + ], + "start_line": 529, + "end_line": 539, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 11, + "top_nesting_level": 0 + }, + { + "name": "PyArray_Prod", + "long_name": "PyArray_Prod( PyArrayObject * self , int axis , int rtype)", + "filename": "multiarraymodule.c", + "nloc": 9, + "complexity": 2, + "token_count": 69, + "parameters": [ + "self", + "axis", + "rtype" + ], + "start_line": 545, + "end_line": 555, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 11, + "top_nesting_level": 0 + }, + { + "name": "PyArray_CumSum", + "long_name": "PyArray_CumSum( PyArrayObject * self , int axis , int rtype)", + "filename": "multiarraymodule.c", + "nloc": 9, + "complexity": 2, + "token_count": 69, + "parameters": [ + "self", + "axis", + "rtype" + ], + "start_line": 561, + "end_line": 571, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 11, + "top_nesting_level": 0 + }, + { + "name": "PyArray_CumProd", + "long_name": "PyArray_CumProd( PyArrayObject * self , int axis , int rtype)", + "filename": "multiarraymodule.c", + "nloc": 10, + "complexity": 2, + "token_count": 69, + "parameters": [ + "self", + "axis", + "rtype" + ], + "start_line": 577, + "end_line": 588, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 12, + "top_nesting_level": 0 + }, + { + "name": "PyArray_Any", + "long_name": "PyArray_Any( PyArrayObject * self , int axis)", + "filename": "multiarraymodule.c", + "nloc": 10, + "complexity": 2, + "token_count": 66, + "parameters": [ + "self", + "axis" + ], + "start_line": 594, + "end_line": 605, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 12, + "top_nesting_level": 0 + }, + { + "name": "PyArray_All", + "long_name": "PyArray_All( PyArrayObject * self , int axis)", + "filename": "multiarraymodule.c", + "nloc": 10, + "complexity": 2, + "token_count": 66, + "parameters": [ + "self", + "axis" + ], + "start_line": 611, + "end_line": 622, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 12, + "top_nesting_level": 0 + }, + { + "name": "PyArray_Compress", + "long_name": "PyArray_Compress( PyArrayObject * self , PyObject * condition , int axis)", + "filename": "multiarraymodule.c", + "nloc": 18, + "complexity": 3, + "token_count": 102, + "parameters": [ + "self", + "condition", + "axis" + ], + "start_line": 629, + "end_line": 649, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 21, + "top_nesting_level": 0 + }, + { + "name": "PyArray_Nonzero", + "long_name": "PyArray_Nonzero( PyArrayObject * self)", + "filename": "multiarraymodule.c", + "nloc": 51, + "complexity": 13, + "token_count": 414, + "parameters": [ + "self" + ], + "start_line": 655, + "end_line": 714, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 60, + "top_nesting_level": 0 + }, + { + "name": "PyArray_Clip", + "long_name": "PyArray_Clip( PyArrayObject * self , PyObject * min , PyObject * max)", + "filename": "multiarraymodule.c", + "nloc": 28, + "complexity": 6, + "token_count": 237, + "parameters": [ + "self", + "min", + "max" + ], + "start_line": 720, + "end_line": 750, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 31, + "top_nesting_level": 0 + }, + { + "name": "PyArray_Conjugate", + "long_name": "PyArray_Conjugate( PyArrayObject * self)", + "filename": "multiarraymodule.c", + "nloc": 36, + "complexity": 9, + "token_count": 228, + "parameters": [ + "self" + ], + "start_line": 756, + "end_line": 792, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 37, + "top_nesting_level": 0 + }, + { + "name": "PyArray_Trace", + "long_name": "PyArray_Trace( PyArrayObject * self , int offset , int axis1 , int axis2 , int rtype)", + "filename": "multiarraymodule.c", + "nloc": 10, + "complexity": 2, + "token_count": 81, + "parameters": [ + "self", + "offset", + "axis1", + "axis2", + "rtype" + ], + "start_line": 798, + "end_line": 808, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 11, + "top_nesting_level": 0 + }, + { + "name": "PyArray_Diagonal", + "long_name": "PyArray_Diagonal( PyArrayObject * self , int offset , int axis1 , int axis2)", + "filename": "multiarraymodule.c", + "nloc": 104, + "complexity": 23, + "token_count": 776, + "parameters": [ + "self", + "offset", + "axis1", + "axis2" + ], + "start_line": 814, + "end_line": 933, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 120, + "top_nesting_level": 0 + }, + { + "name": "PyArray_AsCArray", + "long_name": "PyArray_AsCArray( PyObject ** op , * ptr , intp * dims , int nd , PyArray_Descr * typedescr)", + "filename": "multiarraymodule.c", + "nloc": 50, + "complexity": 12, + "token_count": 402, + "parameters": [ + "op", + "ptr", + "dims", + "nd", + "typedescr" + ], + "start_line": 949, + "end_line": 1000, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 52, + "top_nesting_level": 0 + }, + { + "name": "PyArray_As1D", + "long_name": "PyArray_As1D( PyObject ** op , char ** ptr , int * d1 , int typecode)", + "filename": "multiarraymodule.c", + "nloc": 10, + "complexity": 2, + "token_count": 71, + "parameters": [ + "op", + "ptr", + "d1", + "typecode" + ], + "start_line": 1008, + "end_line": 1018, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 11, + "top_nesting_level": 0 + }, + { + "name": "PyArray_As2D", + "long_name": "PyArray_As2D( PyObject ** op , char ** * ptr , int * d1 , int * d2 , int typecode)", + "filename": "multiarraymodule.c", + "nloc": 11, + "complexity": 2, + "token_count": 92, + "parameters": [ + "op", + "ptr", + "d1", + "d2", + "typecode" + ], + "start_line": 1024, + "end_line": 1036, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 13, + "top_nesting_level": 0 + }, + { + "name": "PyArray_Free", + "long_name": "PyArray_Free( PyObject * op , * ptr)", + "filename": "multiarraymodule.c", + "nloc": 11, + "complexity": 4, + "token_count": 67, + "parameters": [ + "op", + "ptr" + ], + "start_line": 1044, + "end_line": 1055, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 12, + "top_nesting_level": 0 + }, + { + "name": "_swap_and_concat", + "long_name": "_swap_and_concat( PyObject * op , int axis , int n)", + "filename": "multiarraymodule.c", + "nloc": 27, + "complexity": 6, + "token_count": 185, + "parameters": [ + "op", + "axis", + "n" + ], + "start_line": 1059, + "end_line": 1087, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 29, + "top_nesting_level": 0 + }, + { + "name": "PyArray_Concatenate", + "long_name": "PyArray_Concatenate( PyObject * op , int axis)", + "filename": "multiarraymodule.c", + "nloc": 94, + "complexity": 21, + "token_count": 630, + "parameters": [ + "op", + "axis" + ], + "start_line": 1099, + "end_line": 1205, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 107, + "top_nesting_level": 0 + }, + { + "name": "PyArray_SwapAxes", + "long_name": "PyArray_SwapAxes( PyArrayObject * ap , int a1 , int a2)", + "filename": "multiarraymodule.c", + "nloc": 38, + "complexity": 12, + "token_count": 227, + "parameters": [ + "ap", + "a1", + "a2" + ], + "start_line": 1211, + "end_line": 1252, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 42, + "top_nesting_level": 0 + }, + { + "name": "PyArray_Transpose", + "long_name": "PyArray_Transpose( PyArrayObject * ap , PyArray_Dims * permute)", + "filename": "multiarraymodule.c", + "nloc": 46, + "complexity": 10, + "token_count": 309, + "parameters": [ + "ap", + "permute" + ], + "start_line": 1258, + "end_line": 1311, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 54, + "top_nesting_level": 0 + }, + { + "name": "PyArray_Repeat", + "long_name": "PyArray_Repeat( PyArrayObject * aop , PyObject * op , int axis)", + "filename": "multiarraymodule.c", + "nloc": 78, + "complexity": 15, + "token_count": 523, + "parameters": [ + "aop", + "op", + "axis" + ], + "start_line": 1317, + "end_line": 1412, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 96, + "top_nesting_level": 0 + }, + { + "name": "PyArray_ConvertToCommonType", + "long_name": "PyArray_ConvertToCommonType( PyObject * op , int * retn)", + "filename": "multiarraymodule.c", + "nloc": 65, + "complexity": 13, + "token_count": 439, + "parameters": [ + "op", + "retn" + ], + "start_line": 1416, + "end_line": 1487, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 72, + "top_nesting_level": 0 + }, + { + "name": "PyArray_Choose", + "long_name": "PyArray_Choose( PyArrayObject * ip , PyObject * op)", + "filename": "multiarraymodule.c", + "nloc": 70, + "complexity": 15, + "token_count": 518, + "parameters": [ + "ip", + "op" + ], + "start_line": 1494, + "end_line": 1575, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 82, + "top_nesting_level": 0 + }, + { + "name": "_strided_copy", + "long_name": "_strided_copy( char * dst , intp dststride , char * src , intp srcstride , intp num , int elsize)", + "filename": "multiarraymodule.c", + "nloc": 8, + "complexity": 2, + "token_count": 48, + "parameters": [ + "dst", + "dststride", + "src", + "srcstride", + "num", + "elsize" + ], + "start_line": 1578, + "end_line": 1585, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 8, + "top_nesting_level": 0 + }, + { + "name": "_new_sort", + "long_name": "_new_sort( PyArrayObject * op , int axis , PyArray_SORTKIND which)", + "filename": "multiarraymodule.c", + "nloc": 47, + "complexity": 8, + "token_count": 284, + "parameters": [ + "op", + "axis", + "which" + ], + "start_line": 1596, + "end_line": 1650, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 55, + "top_nesting_level": 0 + }, + { + "name": "_new_argsort", + "long_name": "_new_argsort( PyArrayObject * op , int axis , PyArray_SORTKIND which)", + "filename": "multiarraymodule.c", + "nloc": 67, + "complexity": 13, + "token_count": 498, + "parameters": [ + "op", + "axis", + "which" + ], + "start_line": 1653, + "end_line": 1731, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 79, + "top_nesting_level": 0 + }, + { + "name": "qsortCompare", + "long_name": "qsortCompare( const * a , const * b)", + "filename": "multiarraymodule.c", + "nloc": 4, + "complexity": 1, + "token_count": 30, + "parameters": [ + "a", + "b" + ], + "start_line": 1739, + "end_line": 1742, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 4, + "top_nesting_level": 0 + }, + { + "name": "PyArray_Sort", + "long_name": "PyArray_Sort( PyArrayObject * op , int axis , PyArray_SORTKIND which)", + "filename": "multiarraymodule.c", + "nloc": 52, + "complexity": 14, + "token_count": 355, + "parameters": [ + "op", + "axis", + "which" + ], + "start_line": 1797, + "end_line": 1863, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 67, + "top_nesting_level": 0 + }, + { + "name": "argsort_static_compare", + "long_name": "argsort_static_compare( const * ip1 , const * ip2)", + "filename": "multiarraymodule.c", + "nloc": 9, + "complexity": 1, + "token_count": 67, + "parameters": [ + "ip1", + "ip2" + ], + "start_line": 1869, + "end_line": 1877, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 9, + "top_nesting_level": 0 + }, + { + "name": "PyArray_ArgSort", + "long_name": "PyArray_ArgSort( PyArrayObject * op , int axis , PyArray_SORTKIND which)", + "filename": "multiarraymodule.c", + "nloc": 66, + "complexity": 15, + "token_count": 493, + "parameters": [ + "op", + "axis", + "which" + ], + "start_line": 1883, + "end_line": 1963, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 81, + "top_nesting_level": 0 + }, + { + "name": "PyArray_LexSort", + "long_name": "PyArray_LexSort( PyObject * sort_keys , int axis)", + "filename": "multiarraymodule.c", + "nloc": 132, + "complexity": 36, + "token_count": 1162, + "parameters": [ + "sort_keys", + "axis" + ], + "start_line": 1975, + "end_line": 2119, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 145, + "top_nesting_level": 0 + }, + { + "name": "local_where", + "long_name": "local_where( PyArrayObject * ap1 , PyArrayObject * ap2 , PyArrayObject * ret)", + "filename": "multiarraymodule.c", + "nloc": 35, + "complexity": 7, + "token_count": 243, + "parameters": [ + "ap1", + "ap2", + "ret" + ], + "start_line": 2123, + "end_line": 2158, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 36, + "top_nesting_level": 0 + }, + { + "name": "PyArray_SearchSorted", + "long_name": "PyArray_SearchSorted( PyArrayObject * op1 , PyObject * op2)", + "filename": "multiarraymodule.c", + "nloc": 33, + "complexity": 5, + "token_count": 231, + "parameters": [ + "op1", + "op2" + ], + "start_line": 2164, + "end_line": 2209, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 46, + "top_nesting_level": 0 + }, + { + "name": "new_array_for_sum", + "long_name": "new_array_for_sum( PyArrayObject * ap1 , PyArrayObject * ap2 , int nd , intp dimensions [ ] , int typenum)", + "filename": "multiarraymodule.c", + "nloc": 20, + "complexity": 4, + "token_count": 147, + "parameters": [ + "ap1", + "ap2", + "nd", + "typenum" + ], + "start_line": 2216, + "end_line": 2240, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 25, + "top_nesting_level": 0 + }, + { + "name": "PyArray_InnerProduct", + "long_name": "PyArray_InnerProduct( PyObject * op1 , PyObject * op2)", + "filename": "multiarraymodule.c", + "nloc": 74, + "complexity": 15, + "token_count": 584, + "parameters": [ + "op1", + "op2" + ], + "start_line": 2249, + "end_line": 2342, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 94, + "top_nesting_level": 0 + }, + { + "name": "PyArray_MatrixProduct", + "long_name": "PyArray_MatrixProduct( PyObject * op1 , PyObject * op2)", + "filename": "multiarraymodule.c", + "nloc": 94, + "complexity": 18, + "token_count": 733, + "parameters": [ + "op1", + "op2" + ], + "start_line": 2350, + "end_line": 2467, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 118, + "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": 2473, + "end_line": 2527, + "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": 2533, + "end_line": 2630, + "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": 2637, + "end_line": 2661, + "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": 2667, + "end_line": 2678, + "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": 2684, + "end_line": 2695, + "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": 2701, + "end_line": 2724, + "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": 2731, + "end_line": 2788, + "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": 2795, + "end_line": 2870, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 76, + "top_nesting_level": 0 + }, + { + "name": "PyArray_Put", + "long_name": "PyArray_Put( PyArrayObject * self , PyObject * values0 , PyObject * indices0)", + "filename": "multiarraymodule.c", + "nloc": 63, + "complexity": 15, + "token_count": 465, + "parameters": [ + "self", + "values0", + "indices0" + ], + "start_line": 2876, + "end_line": 2945, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 70, + "top_nesting_level": 0 + }, + { + "name": "PyArray_PutMask", + "long_name": "PyArray_PutMask( PyArrayObject * self , PyObject * values0 , PyObject * mask0)", + "filename": "multiarraymodule.c", + "nloc": 65, + "complexity": 12, + "token_count": 422, + "parameters": [ + "self", + "values0", + "mask0" + ], + "start_line": 2951, + "end_line": 3022, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 72, + "top_nesting_level": 0 + }, + { + "name": "PyArray_Converter", + "long_name": "PyArray_Converter( PyObject * object , PyObject ** address)", + "filename": "multiarraymodule.c", + "nloc": 13, + "complexity": 3, + "token_count": 68, + "parameters": [ + "object", + "address" + ], + "start_line": 3038, + "end_line": 3050, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 13, + "top_nesting_level": 0 + }, + { + "name": "PyArray_BoolConverter", + "long_name": "PyArray_BoolConverter( PyObject * object , Bool * val)", + "filename": "multiarraymodule.c", + "nloc": 9, + "complexity": 3, + "token_count": 42, + "parameters": [ + "object", + "val" + ], + "start_line": 3056, + "end_line": 3064, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 9, + "top_nesting_level": 0 + }, + { + "name": "PyArray_TypestrConvert", + "long_name": "PyArray_TypestrConvert( int itemsize , int gentype)", + "filename": "multiarraymodule.c", + "nloc": 96, + "complexity": 35, + "token_count": 308, + "parameters": [ + "itemsize", + "gentype" + ], + "start_line": 3071, + "end_line": 3186, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 116, + "top_nesting_level": 0 + }, + { + "name": "PyArray_BufferConverter", + "long_name": "PyArray_BufferConverter( PyObject * obj , PyArray_Chunk * buf)", + "filename": "multiarraymodule.c", + "nloc": 20, + "complexity": 6, + "token_count": 147, + "parameters": [ + "obj", + "buf" + ], + "start_line": 3204, + "end_line": 3229, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 26, + "top_nesting_level": 0 + }, + { + "name": "PyArray_IntpConverter", + "long_name": "PyArray_IntpConverter( PyObject * obj , PyArray_Dims * seq)", + "filename": "multiarraymodule.c", + "nloc": 36, + "complexity": 10, + "token_count": 189, + "parameters": [ + "obj", + "seq" + ], + "start_line": 3244, + "end_line": 3280, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 37, + "top_nesting_level": 0 + }, + { + "name": "_use_inherit", + "long_name": "_use_inherit( PyArray_Descr * type , PyObject * newobj , int * errflag)", + "filename": "multiarraymodule.c", + "nloc": 32, + "complexity": 7, + "token_count": 161, + "parameters": [ + "type", + "newobj", + "errflag" + ], + "start_line": 3298, + "end_line": 3331, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 34, + "top_nesting_level": 0 + }, + { + "name": "_convert_from_tuple", + "long_name": "_convert_from_tuple( PyObject * obj)", + "filename": "multiarraymodule.c", + "nloc": 62, + "complexity": 15, + "token_count": 381, + "parameters": [ + "obj" + ], + "start_line": 3334, + "end_line": 3408, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 75, + "top_nesting_level": 0 + }, + { + "name": "_convert_from_array_descr", + "long_name": "_convert_from_array_descr( PyObject * obj)", + "filename": "multiarraymodule.c", + "nloc": 69, + "complexity": 14, + "token_count": 442, + "parameters": [ + "obj" + ], + "start_line": 3416, + "end_line": 3487, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 72, + "top_nesting_level": 0 + }, + { + "name": "_convert_from_list", + "long_name": "_convert_from_list( PyObject * obj , int align , int try_descr)", + "filename": "multiarraymodule.c", + "nloc": 70, + "complexity": 13, + "token_count": 428, + "parameters": [ + "obj", + "align", + "try_descr" + ], + "start_line": 3498, + "end_line": 3569, + "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": 3582, + "end_line": 3598, + "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": 3635, + "end_line": 3640, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 6, + "top_nesting_level": 0 + }, + { + "name": "_convert_from_dict", + "long_name": "_convert_from_dict( PyObject * obj , int align)", + "filename": "multiarraymodule.c", + "nloc": 102, + "complexity": 28, + "token_count": 689, + "parameters": [ + "obj", + "align" + ], + "start_line": 3643, + "end_line": 3754, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 112, + "top_nesting_level": 0 + }, + { + "name": "PyArray_DescrConverter2", + "long_name": "PyArray_DescrConverter2( PyObject * obj , PyArray_Descr ** at)", + "filename": "multiarraymodule.c", + "nloc": 8, + "complexity": 2, + "token_count": 37, + "parameters": [ + "obj", + "at" + ], + "start_line": 3772, + "end_line": 3779, + "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": 889, + "parameters": [ + "obj", + "at" + ], + "start_line": 3796, + "end_line": 3976, + "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": 3982, + "end_line": 4014, + "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": 4020, + "end_line": 4046, + "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": 4055, + "end_line": 4074, + "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": 4079, + "end_line": 4104, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 26, + "top_nesting_level": 0 + }, + { + "name": "_array_fromobject", + "long_name": "_array_fromobject( PyObject * ignored , PyObject * args , PyObject * kws)", + "filename": "multiarraymodule.c", + "nloc": 66, + "complexity": 16, + "token_count": 380, + "parameters": [ + "ignored", + "args", + "kws" + ], + "start_line": 4126, + "end_line": 4201, + "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": 4209, + "end_line": 4224, + "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": 4230, + "end_line": 4254, + "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": 4259, + "end_line": 4317, + "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": 4326, + "end_line": 4350, + "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": 4356, + "end_line": 4380, + "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": 4387, + "end_line": 4396, + "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": 4399, + "end_line": 4410, + "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": 4415, + "end_line": 4557, + "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": 4562, + "end_line": 4579, + "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": 4593, + "end_line": 4721, + "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": 4739, + "end_line": 4777, + "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": 4781, + "end_line": 4874, + "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": 4890, + "end_line": 4907, + "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": 4913, + "end_line": 4924, + "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": 4931, + "end_line": 4937, + "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": 4944, + "end_line": 4950, + "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": 4954, + "end_line": 4960, + "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": 4964, + "end_line": 4973, + "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": 4980, + "end_line": 5031, + "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": 5037, + "end_line": 5069, + "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": 5076, + "end_line": 5160, + "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": 5166, + "end_line": 5178, + "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": 5184, + "end_line": 5187, + "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": 5193, + "end_line": 5199, + "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": 5205, + "end_line": 5221, + "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": 5227, + "end_line": 5244, + "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": 5251, + "end_line": 5291, + "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": 5299, + "end_line": 5307, + "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": 5319, + "end_line": 5329, + "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": 5338, + "end_line": 5349, + "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": 5356, + "end_line": 5379, + "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": 5386, + "end_line": 5394, + "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": 5403, + "end_line": 5421, + "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": 5487, + "end_line": 5600, + "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": 5605, + "end_line": 5629, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 25, + "top_nesting_level": 0 + }, + { + "name": "initmultiarray", + "long_name": "initmultiarray()", + "filename": "multiarraymodule.c", + "nloc": 64, + "complexity": 15, + "token_count": 435, + "parameters": [], + "start_line": 5634, + "end_line": 5726, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 93, + "top_nesting_level": 0 + } + ], + "methods_before": [ + { + "name": "_arraydescr_fromobj", + "long_name": "_arraydescr_fromobj( PyObject * obj)", + "filename": "multiarraymodule.c", + "nloc": 15, + "complexity": 3, + "token_count": 67, + "parameters": [ + "obj" + ], + "start_line": 35, + "end_line": 50, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 16, + "top_nesting_level": 0 + }, + { + "name": "PyArray_MultiplyIntList", + "long_name": "PyArray_MultiplyIntList( register int * l1 , register int n)", + "filename": "multiarraymodule.c", + "nloc": 6, + "complexity": 2, + "token_count": 36, + "parameters": [ + "l1", + "n" + ], + "start_line": 75, + "end_line": 80, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 6, + "top_nesting_level": 0 + }, + { + "name": "PyArray_MultiplyList", + "long_name": "PyArray_MultiplyList( register intp * l1 , register int n)", + "filename": "multiarraymodule.c", + "nloc": 6, + "complexity": 2, + "token_count": 36, + "parameters": [ + "l1", + "n" + ], + "start_line": 86, + "end_line": 91, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 6, + "top_nesting_level": 0 + }, + { + "name": "PyArray_GetPtr", + "long_name": "PyArray_GetPtr( PyArrayObject * obj , register intp * ind)", + "filename": "multiarraymodule.c", + "nloc": 8, + "complexity": 2, + "token_count": 61, + "parameters": [ + "obj", + "ind" + ], + "start_line": 97, + "end_line": 105, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 9, + "top_nesting_level": 0 + }, + { + "name": "PyArray_AxisConverter", + "long_name": "PyArray_AxisConverter( PyObject * obj , int * axis)", + "filename": "multiarraymodule.c", + "nloc": 13, + "complexity": 3, + "token_count": 53, + "parameters": [ + "obj", + "axis" + ], + "start_line": 111, + "end_line": 123, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 13, + "top_nesting_level": 0 + }, + { + "name": "PyArray_CompareLists", + "long_name": "PyArray_CompareLists( intp * l1 , intp * l2 , int n)", + "filename": "multiarraymodule.c", + "nloc": 8, + "complexity": 3, + "token_count": 51, + "parameters": [ + "l1", + "l2", + "n" + ], + "start_line": 129, + "end_line": 136, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 8, + "top_nesting_level": 0 + }, + { + "name": "PyArray_View", + "long_name": "PyArray_View( PyArrayObject * self , PyArray_Descr * type , PyTypeObject * pytype)", + "filename": "multiarraymodule.c", + "nloc": 27, + "complexity": 5, + "token_count": 158, + "parameters": [ + "self", + "type", + "pytype" + ], + "start_line": 143, + "end_line": 173, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 31, + "top_nesting_level": 0 + }, + { + "name": "PyArray_Ravel", + "long_name": "PyArray_Ravel( PyArrayObject * a , int fortran)", + "filename": "multiarraymodule.c", + "nloc": 16, + "complexity": 5, + "token_count": 102, + "parameters": [ + "a", + "fortran" + ], + "start_line": 179, + "end_line": 196, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 18, + "top_nesting_level": 0 + }, + { + "name": "PyArray_Flatten", + "long_name": "PyArray_Flatten( PyArrayObject * a , int fortran)", + "filename": "multiarraymodule.c", + "nloc": 33, + "complexity": 6, + "token_count": 176, + "parameters": [ + "a", + "fortran" + ], + "start_line": 202, + "end_line": 237, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 36, + "top_nesting_level": 0 + }, + { + "name": "PyArray_Reshape", + "long_name": "PyArray_Reshape( PyArrayObject * self , PyObject * shape)", + "filename": "multiarraymodule.c", + "nloc": 9, + "complexity": 2, + "token_count": 53, + "parameters": [ + "self", + "shape" + ], + "start_line": 248, + "end_line": 257, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 10, + "top_nesting_level": 0 + }, + { + "name": "_check_ones", + "long_name": "_check_ones( PyArrayObject * self , int newnd , intp * newdims , intp * strides)", + "filename": "multiarraymodule.c", + "nloc": 25, + "complexity": 12, + "token_count": 189, + "parameters": [ + "self", + "newnd", + "newdims", + "strides" + ], + "start_line": 260, + "end_line": 286, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 27, + "top_nesting_level": 0 + }, + { + "name": "PyArray_Newshape", + "long_name": "PyArray_Newshape( PyArrayObject * self , PyArray_Dims * newdims)", + "filename": "multiarraymodule.c", + "nloc": 72, + "complexity": 17, + "token_count": 409, + "parameters": [ + "self", + "newdims" + ], + "start_line": 297, + "end_line": 384, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 88, + "top_nesting_level": 0 + }, + { + "name": "PyArray_Squeeze", + "long_name": "PyArray_Squeeze( PyArrayObject * self)", + "filename": "multiarraymodule.c", + "nloc": 34, + "complexity": 5, + "token_count": 204, + "parameters": [ + "self" + ], + "start_line": 393, + "end_line": 428, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 36, + "top_nesting_level": 0 + }, + { + "name": "PyArray_Mean", + "long_name": "PyArray_Mean( PyArrayObject * self , int axis , int rtype)", + "filename": "multiarraymodule.c", + "nloc": 19, + "complexity": 4, + "token_count": 139, + "parameters": [ + "self", + "axis", + "rtype" + ], + "start_line": 435, + "end_line": 456, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 22, + "top_nesting_level": 0 + }, + { + "name": "PyArray_Std", + "long_name": "PyArray_Std( PyArrayObject * self , int axis , int rtype , int variance)", + "filename": "multiarraymodule.c", + "nloc": 45, + "complexity": 13, + "token_count": 450, + "parameters": [ + "self", + "axis", + "rtype", + "variance" + ], + "start_line": 463, + "end_line": 522, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 60, + "top_nesting_level": 0 + }, + { + "name": "PyArray_Sum", + "long_name": "PyArray_Sum( PyArrayObject * self , int axis , int rtype)", + "filename": "multiarraymodule.c", + "nloc": 9, + "complexity": 2, + "token_count": 69, + "parameters": [ + "self", + "axis", + "rtype" + ], + "start_line": 529, + "end_line": 539, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 11, + "top_nesting_level": 0 + }, + { + "name": "PyArray_Prod", + "long_name": "PyArray_Prod( PyArrayObject * self , int axis , int rtype)", + "filename": "multiarraymodule.c", + "nloc": 9, + "complexity": 2, + "token_count": 69, + "parameters": [ + "self", + "axis", + "rtype" + ], + "start_line": 545, + "end_line": 555, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 11, + "top_nesting_level": 0 + }, + { + "name": "PyArray_CumSum", + "long_name": "PyArray_CumSum( PyArrayObject * self , int axis , int rtype)", + "filename": "multiarraymodule.c", + "nloc": 9, + "complexity": 2, + "token_count": 69, + "parameters": [ + "self", + "axis", + "rtype" + ], + "start_line": 561, + "end_line": 571, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 11, + "top_nesting_level": 0 + }, + { + "name": "PyArray_CumProd", + "long_name": "PyArray_CumProd( PyArrayObject * self , int axis , int rtype)", + "filename": "multiarraymodule.c", + "nloc": 10, + "complexity": 2, + "token_count": 69, + "parameters": [ + "self", + "axis", + "rtype" + ], + "start_line": 577, + "end_line": 588, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 12, + "top_nesting_level": 0 + }, + { + "name": "PyArray_Any", + "long_name": "PyArray_Any( PyArrayObject * self , int axis)", + "filename": "multiarraymodule.c", + "nloc": 10, + "complexity": 2, + "token_count": 66, + "parameters": [ + "self", + "axis" + ], + "start_line": 594, + "end_line": 605, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 12, + "top_nesting_level": 0 + }, + { + "name": "PyArray_All", + "long_name": "PyArray_All( PyArrayObject * self , int axis)", + "filename": "multiarraymodule.c", + "nloc": 10, + "complexity": 2, + "token_count": 66, + "parameters": [ + "self", + "axis" + ], + "start_line": 611, + "end_line": 622, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 12, + "top_nesting_level": 0 + }, + { + "name": "PyArray_Compress", + "long_name": "PyArray_Compress( PyArrayObject * self , PyObject * condition , int axis)", + "filename": "multiarraymodule.c", + "nloc": 18, + "complexity": 3, + "token_count": 102, + "parameters": [ + "self", + "condition", + "axis" + ], + "start_line": 629, + "end_line": 649, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 21, + "top_nesting_level": 0 + }, + { + "name": "PyArray_Nonzero", + "long_name": "PyArray_Nonzero( PyArrayObject * self)", + "filename": "multiarraymodule.c", + "nloc": 51, + "complexity": 13, + "token_count": 414, + "parameters": [ + "self" + ], + "start_line": 655, + "end_line": 714, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 60, + "top_nesting_level": 0 + }, + { + "name": "PyArray_Clip", + "long_name": "PyArray_Clip( PyArrayObject * self , PyObject * min , PyObject * max)", + "filename": "multiarraymodule.c", + "nloc": 28, + "complexity": 6, + "token_count": 237, + "parameters": [ + "self", + "min", + "max" + ], + "start_line": 720, + "end_line": 750, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 31, + "top_nesting_level": 0 + }, + { + "name": "PyArray_Conjugate", + "long_name": "PyArray_Conjugate( PyArrayObject * self)", + "filename": "multiarraymodule.c", + "nloc": 36, + "complexity": 9, + "token_count": 228, + "parameters": [ + "self" + ], + "start_line": 756, + "end_line": 792, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 37, + "top_nesting_level": 0 + }, + { + "name": "PyArray_Trace", + "long_name": "PyArray_Trace( PyArrayObject * self , int offset , int axis1 , int axis2 , int rtype)", + "filename": "multiarraymodule.c", + "nloc": 10, + "complexity": 2, + "token_count": 81, + "parameters": [ + "self", + "offset", + "axis1", + "axis2", + "rtype" + ], + "start_line": 798, + "end_line": 808, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 11, + "top_nesting_level": 0 + }, + { + "name": "PyArray_Diagonal", + "long_name": "PyArray_Diagonal( PyArrayObject * self , int offset , int axis1 , int axis2)", + "filename": "multiarraymodule.c", + "nloc": 104, + "complexity": 23, + "token_count": 776, + "parameters": [ + "self", + "offset", + "axis1", + "axis2" + ], + "start_line": 814, + "end_line": 933, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 120, + "top_nesting_level": 0 + }, + { + "name": "PyArray_AsCArray", + "long_name": "PyArray_AsCArray( PyObject ** op , * ptr , intp * dims , int nd , PyArray_Descr * typedescr)", + "filename": "multiarraymodule.c", + "nloc": 50, + "complexity": 12, + "token_count": 402, + "parameters": [ + "op", + "ptr", + "dims", + "nd", + "typedescr" + ], + "start_line": 949, + "end_line": 1000, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 52, + "top_nesting_level": 0 + }, + { + "name": "PyArray_As1D", + "long_name": "PyArray_As1D( PyObject ** op , char ** ptr , int * d1 , int typecode)", + "filename": "multiarraymodule.c", + "nloc": 10, + "complexity": 2, + "token_count": 71, + "parameters": [ + "op", + "ptr", + "d1", + "typecode" + ], + "start_line": 1008, + "end_line": 1018, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 11, + "top_nesting_level": 0 + }, + { + "name": "PyArray_As2D", + "long_name": "PyArray_As2D( PyObject ** op , char ** * ptr , int * d1 , int * d2 , int typecode)", + "filename": "multiarraymodule.c", + "nloc": 11, + "complexity": 2, + "token_count": 92, + "parameters": [ + "op", + "ptr", + "d1", + "d2", + "typecode" + ], + "start_line": 1024, + "end_line": 1036, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 13, + "top_nesting_level": 0 + }, + { + "name": "PyArray_Free", + "long_name": "PyArray_Free( PyObject * op , * ptr)", + "filename": "multiarraymodule.c", + "nloc": 11, + "complexity": 4, + "token_count": 67, + "parameters": [ + "op", + "ptr" + ], + "start_line": 1044, + "end_line": 1055, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 12, + "top_nesting_level": 0 + }, + { + "name": "_swap_and_concat", + "long_name": "_swap_and_concat( PyObject * op , int axis , int n)", + "filename": "multiarraymodule.c", + "nloc": 27, + "complexity": 6, + "token_count": 185, + "parameters": [ + "op", + "axis", + "n" + ], + "start_line": 1059, + "end_line": 1087, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 29, + "top_nesting_level": 0 + }, + { + "name": "PyArray_Concatenate", + "long_name": "PyArray_Concatenate( PyObject * op , int axis)", + "filename": "multiarraymodule.c", + "nloc": 94, + "complexity": 21, + "token_count": 630, + "parameters": [ + "op", + "axis" + ], + "start_line": 1099, + "end_line": 1205, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 107, + "top_nesting_level": 0 + }, + { + "name": "PyArray_SwapAxes", + "long_name": "PyArray_SwapAxes( PyArrayObject * ap , int a1 , int a2)", + "filename": "multiarraymodule.c", + "nloc": 38, + "complexity": 12, + "token_count": 227, + "parameters": [ + "ap", + "a1", + "a2" + ], + "start_line": 1211, + "end_line": 1252, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 42, + "top_nesting_level": 0 + }, + { + "name": "PyArray_Transpose", + "long_name": "PyArray_Transpose( PyArrayObject * ap , PyArray_Dims * permute)", + "filename": "multiarraymodule.c", + "nloc": 46, + "complexity": 10, + "token_count": 309, + "parameters": [ + "ap", + "permute" + ], + "start_line": 1258, + "end_line": 1311, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 54, + "top_nesting_level": 0 + }, + { + "name": "PyArray_Repeat", + "long_name": "PyArray_Repeat( PyArrayObject * aop , PyObject * op , int axis)", + "filename": "multiarraymodule.c", + "nloc": 78, + "complexity": 15, + "token_count": 523, + "parameters": [ + "aop", + "op", + "axis" + ], + "start_line": 1317, + "end_line": 1412, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 96, + "top_nesting_level": 0 + }, + { + "name": "PyArray_ConvertToCommonType", + "long_name": "PyArray_ConvertToCommonType( PyObject * op , int * retn)", + "filename": "multiarraymodule.c", + "nloc": 65, + "complexity": 13, + "token_count": 439, + "parameters": [ + "op", + "retn" + ], + "start_line": 1416, + "end_line": 1487, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 72, + "top_nesting_level": 0 + }, + { + "name": "PyArray_Choose", + "long_name": "PyArray_Choose( PyArrayObject * ip , PyObject * op)", + "filename": "multiarraymodule.c", + "nloc": 70, + "complexity": 15, + "token_count": 518, + "parameters": [ + "ip", + "op" + ], + "start_line": 1494, + "end_line": 1575, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 82, + "top_nesting_level": 0 + }, + { + "name": "_strided_copy", + "long_name": "_strided_copy( char * dst , intp dststride , char * src , intp srcstride , intp num , int elsize)", + "filename": "multiarraymodule.c", + "nloc": 8, + "complexity": 2, + "token_count": 48, + "parameters": [ + "dst", + "dststride", + "src", + "srcstride", + "num", + "elsize" + ], + "start_line": 1578, + "end_line": 1585, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 8, + "top_nesting_level": 0 + }, + { + "name": "_new_sort", + "long_name": "_new_sort( PyArrayObject * op , int axis , PyArray_SORTKIND which)", + "filename": "multiarraymodule.c", + "nloc": 47, + "complexity": 8, + "token_count": 284, + "parameters": [ + "op", + "axis", + "which" + ], + "start_line": 1596, + "end_line": 1650, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 55, + "top_nesting_level": 0 + }, + { + "name": "_new_argsort", + "long_name": "_new_argsort( PyArrayObject * op , int axis , PyArray_SORTKIND which)", + "filename": "multiarraymodule.c", + "nloc": 67, + "complexity": 13, + "token_count": 498, + "parameters": [ + "op", + "axis", + "which" + ], + "start_line": 1653, + "end_line": 1731, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 79, + "top_nesting_level": 0 + }, + { + "name": "qsortCompare", + "long_name": "qsortCompare( const * a , const * b)", + "filename": "multiarraymodule.c", + "nloc": 4, + "complexity": 1, + "token_count": 30, + "parameters": [ + "a", + "b" + ], + "start_line": 1739, + "end_line": 1742, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 4, + "top_nesting_level": 0 + }, + { + "name": "PyArray_Sort", + "long_name": "PyArray_Sort( PyArrayObject * op , int axis , PyArray_SORTKIND which)", + "filename": "multiarraymodule.c", + "nloc": 52, + "complexity": 14, + "token_count": 355, + "parameters": [ + "op", + "axis", + "which" + ], + "start_line": 1797, + "end_line": 1863, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 67, + "top_nesting_level": 0 + }, + { + "name": "argsort_static_compare", + "long_name": "argsort_static_compare( const * ip1 , const * ip2)", + "filename": "multiarraymodule.c", + "nloc": 9, + "complexity": 1, + "token_count": 67, + "parameters": [ + "ip1", + "ip2" + ], + "start_line": 1869, + "end_line": 1877, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 9, + "top_nesting_level": 0 + }, + { + "name": "PyArray_ArgSort", + "long_name": "PyArray_ArgSort( PyArrayObject * op , int axis , PyArray_SORTKIND which)", + "filename": "multiarraymodule.c", + "nloc": 66, + "complexity": 15, + "token_count": 493, + "parameters": [ + "op", + "axis", + "which" + ], + "start_line": 1883, + "end_line": 1963, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 81, + "top_nesting_level": 0 + }, + { + "name": "PyArray_LexSort", + "long_name": "PyArray_LexSort( PyObject * sort_keys , int axis)", + "filename": "multiarraymodule.c", + "nloc": 132, + "complexity": 36, + "token_count": 1162, + "parameters": [ + "sort_keys", + "axis" + ], + "start_line": 1975, + "end_line": 2119, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 145, + "top_nesting_level": 0 + }, + { + "name": "local_where", + "long_name": "local_where( PyArrayObject * ap1 , PyArrayObject * ap2 , PyArrayObject * ret)", + "filename": "multiarraymodule.c", + "nloc": 35, + "complexity": 7, + "token_count": 243, + "parameters": [ + "ap1", + "ap2", + "ret" + ], + "start_line": 2123, + "end_line": 2158, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 36, + "top_nesting_level": 0 + }, + { + "name": "PyArray_SearchSorted", + "long_name": "PyArray_SearchSorted( PyArrayObject * op1 , PyObject * op2)", + "filename": "multiarraymodule.c", + "nloc": 33, + "complexity": 5, + "token_count": 231, + "parameters": [ + "op1", + "op2" + ], + "start_line": 2164, + "end_line": 2209, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 46, + "top_nesting_level": 0 + }, + { + "name": "new_array_for_sum", + "long_name": "new_array_for_sum( PyArrayObject * ap1 , PyArrayObject * ap2 , int nd , intp dimensions [ ] , int typenum)", + "filename": "multiarraymodule.c", + "nloc": 20, + "complexity": 4, + "token_count": 147, + "parameters": [ + "ap1", + "ap2", + "nd", + "typenum" + ], + "start_line": 2216, + "end_line": 2240, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 25, + "top_nesting_level": 0 + }, + { + "name": "PyArray_InnerProduct", + "long_name": "PyArray_InnerProduct( PyObject * op1 , PyObject * op2)", + "filename": "multiarraymodule.c", + "nloc": 74, + "complexity": 15, + "token_count": 584, + "parameters": [ + "op1", + "op2" + ], + "start_line": 2249, + "end_line": 2342, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 94, + "top_nesting_level": 0 + }, + { + "name": "PyArray_MatrixProduct", + "long_name": "PyArray_MatrixProduct( PyObject * op1 , PyObject * op2)", + "filename": "multiarraymodule.c", + "nloc": 94, + "complexity": 18, + "token_count": 733, + "parameters": [ + "op1", + "op2" + ], + "start_line": 2350, + "end_line": 2467, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 118, + "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": 2473, + "end_line": 2527, + "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": 2533, + "end_line": 2630, + "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": 2637, + "end_line": 2661, + "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": 2667, + "end_line": 2678, + "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": 2684, + "end_line": 2695, + "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": 2701, + "end_line": 2724, + "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": 2731, + "end_line": 2788, + "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": 2795, + "end_line": 2870, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 76, + "top_nesting_level": 0 + }, + { + "name": "PyArray_Put", + "long_name": "PyArray_Put( PyArrayObject * self , PyObject * values0 , PyObject * indices0)", + "filename": "multiarraymodule.c", + "nloc": 63, + "complexity": 15, + "token_count": 465, + "parameters": [ + "self", + "values0", + "indices0" + ], + "start_line": 2876, + "end_line": 2945, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 70, + "top_nesting_level": 0 + }, + { + "name": "PyArray_PutMask", + "long_name": "PyArray_PutMask( PyArrayObject * self , PyObject * values0 , PyObject * mask0)", + "filename": "multiarraymodule.c", + "nloc": 65, + "complexity": 12, + "token_count": 422, + "parameters": [ + "self", + "values0", + "mask0" + ], + "start_line": 2951, + "end_line": 3022, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 72, + "top_nesting_level": 0 + }, + { + "name": "PyArray_Converter", + "long_name": "PyArray_Converter( PyObject * object , PyObject ** address)", + "filename": "multiarraymodule.c", + "nloc": 13, + "complexity": 3, + "token_count": 68, + "parameters": [ + "object", + "address" + ], + "start_line": 3038, + "end_line": 3050, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 13, + "top_nesting_level": 0 + }, + { + "name": "PyArray_BoolConverter", + "long_name": "PyArray_BoolConverter( PyObject * object , Bool * val)", + "filename": "multiarraymodule.c", + "nloc": 9, + "complexity": 3, + "token_count": 42, + "parameters": [ + "object", + "val" + ], + "start_line": 3056, + "end_line": 3064, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 9, + "top_nesting_level": 0 + }, + { + "name": "PyArray_TypestrConvert", + "long_name": "PyArray_TypestrConvert( int itemsize , int gentype)", + "filename": "multiarraymodule.c", + "nloc": 96, + "complexity": 35, + "token_count": 308, + "parameters": [ + "itemsize", + "gentype" + ], + "start_line": 3071, + "end_line": 3186, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 116, + "top_nesting_level": 0 + }, + { + "name": "PyArray_BufferConverter", + "long_name": "PyArray_BufferConverter( PyObject * obj , PyArray_Chunk * buf)", + "filename": "multiarraymodule.c", + "nloc": 20, + "complexity": 6, + "token_count": 147, + "parameters": [ + "obj", + "buf" + ], + "start_line": 3204, + "end_line": 3229, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 26, + "top_nesting_level": 0 + }, + { + "name": "PyArray_IntpConverter", + "long_name": "PyArray_IntpConverter( PyObject * obj , PyArray_Dims * seq)", + "filename": "multiarraymodule.c", + "nloc": 36, + "complexity": 10, + "token_count": 189, + "parameters": [ + "obj", + "seq" + ], + "start_line": 3244, + "end_line": 3280, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 37, + "top_nesting_level": 0 + }, + { + "name": "_use_inherit", + "long_name": "_use_inherit( PyArray_Descr * type , PyObject * newobj , int * errflag)", + "filename": "multiarraymodule.c", + "nloc": 32, + "complexity": 7, + "token_count": 161, + "parameters": [ + "type", + "newobj", + "errflag" + ], + "start_line": 3298, + "end_line": 3331, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 34, + "top_nesting_level": 0 + }, + { + "name": "_convert_from_tuple", + "long_name": "_convert_from_tuple( PyObject * obj)", + "filename": "multiarraymodule.c", + "nloc": 62, + "complexity": 15, + "token_count": 381, + "parameters": [ + "obj" + ], + "start_line": 3334, + "end_line": 3408, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 75, + "top_nesting_level": 0 + }, + { + "name": "_convert_from_array_descr", + "long_name": "_convert_from_array_descr( PyObject * obj)", + "filename": "multiarraymodule.c", + "nloc": 69, + "complexity": 14, + "token_count": 442, + "parameters": [ + "obj" + ], + "start_line": 3416, + "end_line": 3487, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 72, + "top_nesting_level": 0 + }, + { + "name": "_convert_from_list", + "long_name": "_convert_from_list( PyObject * obj , int align , int try_descr)", + "filename": "multiarraymodule.c", + "nloc": 70, + "complexity": 13, + "token_count": 428, + "parameters": [ + "obj", + "align", + "try_descr" + ], + "start_line": 3498, + "end_line": 3569, + "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": 3582, + "end_line": 3598, + "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": 3635, + "end_line": 3640, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 6, + "top_nesting_level": 0 + }, + { + "name": "_convert_from_dict", + "long_name": "_convert_from_dict( PyObject * obj , int align)", + "filename": "multiarraymodule.c", + "nloc": 102, + "complexity": 28, + "token_count": 689, + "parameters": [ + "obj", + "align" + ], + "start_line": 3643, + "end_line": 3754, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 112, + "top_nesting_level": 0 + }, + { + "name": "PyArray_DescrConverter2", + "long_name": "PyArray_DescrConverter2( PyObject * obj , PyArray_Descr ** at)", + "filename": "multiarraymodule.c", + "nloc": 8, + "complexity": 2, + "token_count": 37, + "parameters": [ + "obj", + "at" + ], + "start_line": 3772, + "end_line": 3779, + "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": 146, + "complexity": 57, + "token_count": 916, + "parameters": [ + "obj", + "at" + ], + "start_line": 3796, + "end_line": 3976, + "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": 3982, + "end_line": 4014, + "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": 4020, + "end_line": 4046, + "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": 4055, + "end_line": 4074, + "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": 4079, + "end_line": 4104, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 26, + "top_nesting_level": 0 + }, + { + "name": "_array_fromobject", + "long_name": "_array_fromobject( PyObject * ignored , PyObject * args , PyObject * kws)", + "filename": "multiarraymodule.c", + "nloc": 66, + "complexity": 16, + "token_count": 380, + "parameters": [ + "ignored", + "args", + "kws" + ], + "start_line": 4126, + "end_line": 4201, + "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": 4209, + "end_line": 4224, + "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": 4230, + "end_line": 4254, + "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": 4259, + "end_line": 4317, + "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": 4326, + "end_line": 4350, + "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": 4356, + "end_line": 4380, + "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": 4387, + "end_line": 4396, + "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": 4399, + "end_line": 4410, + "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": 4415, + "end_line": 4557, + "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": 4562, + "end_line": 4579, + "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": 4593, + "end_line": 4721, + "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": 4739, + "end_line": 4777, + "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": 4781, + "end_line": 4874, + "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": 4890, + "end_line": 4907, + "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": 4913, + "end_line": 4924, + "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": 4931, + "end_line": 4937, + "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": 4944, + "end_line": 4950, + "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": 4954, + "end_line": 4960, + "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": 4964, + "end_line": 4973, + "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": 4980, + "end_line": 5031, + "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": 5037, + "end_line": 5069, + "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": 5076, + "end_line": 5160, + "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": 5166, + "end_line": 5178, + "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": 5184, + "end_line": 5187, + "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": 5193, + "end_line": 5199, + "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": 5205, + "end_line": 5221, + "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": 5227, + "end_line": 5244, + "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": 5251, + "end_line": 5291, + "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": 5299, + "end_line": 5307, + "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": 5319, + "end_line": 5329, + "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": 5338, + "end_line": 5349, + "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": 5356, + "end_line": 5379, + "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": 5386, + "end_line": 5394, + "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": 5403, + "end_line": 5421, + "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": 5487, + "end_line": 5600, + "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": 5605, + "end_line": 5629, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 25, + "top_nesting_level": 0 + }, + { + "name": "initmultiarray", + "long_name": "initmultiarray()", + "filename": "multiarraymodule.c", + "nloc": 64, + "complexity": 15, + "token_count": 435, + "parameters": [], + "start_line": 5634, + "end_line": 5726, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 93, + "top_nesting_level": 0 + } + ], + "changed_methods": [ + { + "name": "PyArray_DescrConverter", + "long_name": "PyArray_DescrConverter( PyObject * obj , PyArray_Descr ** at)", + "filename": "multiarraymodule.c", + "nloc": 141, + "complexity": 55, + "token_count": 889, + "parameters": [ + "obj", + "at" + ], + "start_line": 3796, + "end_line": 3976, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 181, + "top_nesting_level": 0 + } + ], + "nloc": 4332, + "complexity": 943, + "token_count": 28194, + "diff_parsed": { + "added": [ + " else goto fail; /*{", + "\t\t} */" + ], + "deleted": [ + " else {", + "\t}" + ] + } + } + ] + }, + { + "hash": "39ba8fc2bdf333811337d18d83c8611775649bb3", + "msg": "Handle setup.py help and display requests without noise.", + "author": { + "name": "Pearu Peterson", + "email": "pearu.peterson@gmail.com" + }, + "committer": { + "name": "Pearu Peterson", + "email": "pearu.peterson@gmail.com" + }, + "author_date": "2006-01-30T21:11:22+00:00", + "author_timezone": 0, + "committer_date": "2006-01-30T21:11:22+00:00", + "committer_timezone": 0, + "branches": [ + "main" + ], + "in_main_branch": true, + "merge": false, + "parents": [ + "ca90e3eba3c94de3bd13266ccfd9f96dbf23693a" + ], + "project_name": "repo_copy", + "project_path": "/tmp/tmppy2o86q9/repo_copy", + "deletions": 7, + "insertions": 41, + "lines": 48, + "files": 2, + "dmm_unit_size": 0.0, + "dmm_unit_complexity": 0.0, + "dmm_unit_interfacing": 1.0, + "modified_files": [ + { + "old_path": "numpy/distutils/misc_util.py", + "new_path": "numpy/distutils/misc_util.py", + "filename": "misc_util.py", + "extension": "py", + "change_type": "MODIFY", + "diff": "@@ -318,6 +318,24 @@ def get_frame(level=0):\n \n ######################\n \n+def command_line_ok(_cache=[]):\n+ \"\"\" Return True if command line does not contain any\n+ help or display requests.\n+ \"\"\"\n+ if _cache:\n+ return _cache[0]\n+ ok = True\n+ from distutils.dist import Distribution\n+ display_opts = ['--'+n for n in Distribution.display_option_names]\n+ for o in Distribution.display_options:\n+ if o[1]: display_opts.append('-'+o[1])\n+ for arg in sys.argv:\n+ if arg.startswith('--help') or arg=='-h' or arg in display_opts:\n+ ok = False\n+ break\n+ _cache.append(ok)\n+ return ok\n+\n class Configuration:\n \n _list_keys = ['packages','ext_modules','data_files','include_dirs',\n@@ -409,7 +427,7 @@ def info(self, message):\n print message\n \n def warn(self, message):\n- print 'Warning:',message\n+ print>>sys.stderr, 'Warning:',message\n \n def __dict__(self):\n return self.todict()\n@@ -786,8 +804,9 @@ def dict_append(self,**dict):\n known_keys = self.list_keys + self.dict_keys + self.extra_keys\n for key in dict.keys():\n if key not in known_keys and not hasattr(self,key):\n- print 'Inheriting attribute %r from %r' \\\n- % (key,dict.get('name','?'))\n+ if key not in ['version']:\n+ self.warn('Inheriting attribute %r from %r' \\\n+ % (key,dict.get('name','?')))\n setattr(self,key,dict[key])\n self.extra_keys.append(key)\n return\n@@ -971,6 +990,21 @@ def get_info(self,*names):\n dict_append(info_dict,**get_info(a))\n return info_dict\n \n+ if not command_line_ok():\n+ _do_nothing = lambda *args,**kws: None\n+ add_subpackage = _do_nothing\n+ add_extension = _do_nothing\n+ add_library = _do_nothing\n+ add_data_dir = _do_nothing\n+ add_data_files = _do_nothing\n+ add_scripts = _do_nothing\n+ add_headers = _do_nothing\n+ add_include_dirs = _do_nothing\n+ make_config_py = _do_nothing\n+ get_info = lambda *args,**kws:{}\n+ have_f77c = lambda *args,**kws: False\n+ have_f90c = lambda *args,**kws: False\n+\n def get_cmd(cmdname,_cache={}):\n if not _cache.has_key(cmdname):\n import distutils.core\n", + "added_lines": 37, + "deleted_lines": 3, + "source_code": "import os\nimport re\nimport sys\nimport imp\nimport copy\nimport glob\n\n__all__ = ['Configuration', 'get_numpy_include_dirs', 'default_config_dict',\n 'dict_append', 'appendpath', 'generate_config_py',\n 'generate_svn_version_py', 'get_cmd', 'allpath',\n 'terminal_has_colors', 'red_text', 'green_text', 'yellow_text',\n 'blue_text', 'cyan_text', 'cyg2win32', 'all_strings',\n 'has_f_sources', 'has_cxx_sources', 'filter_sources',\n 'get_dependencies', 'is_local_src_dir', 'get_ext_source_files',\n 'get_script_files', 'get_lib_source_files', 'get_data_files',\n 'dot_join', 'get_frame', 'minrelpath','njoin']\n\ndef allpath(name):\n \"Convert a /-separated pathname to one using the OS's path separator.\"\n splitted = name.split('/')\n return os.path.join(*splitted)\n\ndef get_path(mod_name,parent_path=None):\n \"\"\" Return path of the module.\n\n Returned path is relative to parent_path when given,\n otherwise it is absolute path.\n \"\"\"\n if mod_name == '__main__':\n d = os.path.abspath('.')\n elif mod_name == '__builtin__':\n #builtin if/then added by Pearu for use in core.run_setup.\n d = os.path.dirname(os.path.abspath(sys.argv[0]))\n else:\n __import__(mod_name)\n mod = sys.modules[mod_name]\n file = mod.__file__\n d = os.path.dirname(os.path.abspath(file))\n if parent_path is not None:\n pd = os.path.abspath(parent_path)\n if pd==d[:len(pd)]:\n d = d[len(pd)+1:]\n return d or '.'\n\ndef njoin(*path):\n \"\"\" Join two or more pathname components +\n - convert a /-separated pathname to one using the OS's path separator.\n - resolve `..` from path.\n \"\"\"\n if isinstance(path,tuple):\n path = os.path.join(*path)\n if not isinstance(path,str): return path\n if not ('/' == os.path.sep):\n path = path.replace('/',os.path.sep)\n return minrelpath(path)\n\ndef minrelpath(path):\n \"\"\" Resolve `..` from path.\n \"\"\"\n if not isinstance(path, str): return path\n if '..' not in path: return path\n l = path.split(os.sep)\n j = 1\n while l:\n try:\n i = l.index('..',j)\n except ValueError:\n break\n if l[i-1]=='..':\n j += 1\n else:\n del l[i],l[i-1]\n j = 1\n if not l: return ''\n return os.path.join(*l)\n\n# Hooks for colored terminal output.\n# See also http://www.livinglogic.de/Python/ansistyle\ndef terminal_has_colors():\n if sys.platform=='cygwin' and not os.environ.has_key('USE_COLOR'):\n # Avoid importing curses that causes illegal operation\n # with a message:\n # PYTHON2 caused an invalid page fault in\n # module CYGNURSES7.DLL as 015f:18bbfc28\n # Details: Python 2.3.3 [GCC 3.3.1 (cygming special)]\n # ssh to Win32 machine from debian\n # curses.version is 2.2\n # CYGWIN_98-4.10, release 1.5.7(0.109/3/2))\n return 0\n if hasattr(sys.stdout,'isatty') and sys.stdout.isatty():\n try:\n import curses\n curses.setupterm()\n if (curses.tigetnum(\"colors\") >= 0\n and curses.tigetnum(\"pairs\") >= 0\n and ((curses.tigetstr(\"setf\") is not None\n and curses.tigetstr(\"setb\") is not None)\n or (curses.tigetstr(\"setaf\") is not None\n and curses.tigetstr(\"setab\") is not None)\n or curses.tigetstr(\"scp\") is not None)):\n return 1\n except Exception,msg:\n pass\n return 0\n\nif terminal_has_colors():\n def red_text(s): return '\\x1b[31m%s\\x1b[0m'%s\n def green_text(s): return '\\x1b[32m%s\\x1b[0m'%s\n def yellow_text(s): return '\\x1b[33m%s\\x1b[0m'%s\n def blue_text(s): return '\\x1b[34m%s\\x1b[0m'%s\n def cyan_text(s): return '\\x1b[35m%s\\x1b[0m'%s\nelse:\n def red_text(s): return s\n def green_text(s): return s\n def yellow_text(s): return s\n def cyan_text(s): return s\n def blue_text(s): return s\n\n#########################\n\ndef cyg2win32(path):\n if sys.platform=='cygwin' and path.startswith('/cygdrive'):\n path = path[10] + ':' + os.path.normcase(path[11:])\n return path\n\n#########################\n\n#XXX need support for .C that is also C++\ncxx_ext_match = re.compile(r'.*[.](cpp|cxx|cc)\\Z',re.I).match\nfortran_ext_match = re.compile(r'.*[.](f90|f95|f77|for|ftn|f)\\Z',re.I).match\nf90_ext_match = re.compile(r'.*[.](f90|f95)\\Z',re.I).match\nf90_module_name_match = re.compile(r'\\s*module\\s*(?P[\\w_]+)',re.I).match\ndef _get_f90_modules(source):\n \"\"\" Return a list of Fortran f90 module names that\n given source file defines.\n \"\"\"\n if not f90_ext_match(source):\n return []\n modules = []\n f = open(source,'r')\n f_readlines = getattr(f,'xreadlines',f.readlines)\n for line in f_readlines():\n m = f90_module_name_match(line)\n if m:\n name = m.group('name')\n modules.append(name)\n # break # XXX can we assume that there is one module per file?\n f.close()\n return modules\n\ndef is_string(s):\n return isinstance(s, str)\n\ndef all_strings(lst):\n \"\"\" Return True if all items in lst are string objects. \"\"\"\n for item in lst:\n if not is_string(item):\n return False\n return True\n\ndef is_sequence(seq):\n if is_string(seq):\n return False\n try:\n len(seq)\n except:\n return False\n return True\n\ndef has_f_sources(sources):\n \"\"\" Return True if sources contains Fortran files \"\"\"\n for source in sources:\n if fortran_ext_match(source):\n return True\n return False\n\ndef has_cxx_sources(sources):\n \"\"\" Return True if sources contains C++ files \"\"\"\n for source in sources:\n if cxx_ext_match(source):\n return True\n return False\n\ndef filter_sources(sources):\n \"\"\" Return four lists of filenames containing\n C, C++, Fortran, and Fortran 90 module sources,\n respectively.\n \"\"\"\n c_sources = []\n cxx_sources = []\n f_sources = []\n fmodule_sources = []\n for source in sources:\n if fortran_ext_match(source):\n modules = _get_f90_modules(source)\n if modules:\n fmodule_sources.append(source)\n else:\n f_sources.append(source)\n elif cxx_ext_match(source):\n cxx_sources.append(source)\n else:\n c_sources.append(source)\n return c_sources, cxx_sources, f_sources, fmodule_sources\n\n\ndef _get_headers(directory_list):\n # get *.h files from list of directories\n headers = []\n for dir in directory_list:\n head = glob.glob(os.path.join(dir,\"*.h\")) #XXX: *.hpp files??\n headers.extend(head)\n return headers\n\ndef _get_directories(list_of_sources):\n # get unique directories from list of sources.\n direcs = []\n for file in list_of_sources:\n dir = os.path.split(file)\n if dir[0] != '' and not dir[0] in direcs:\n direcs.append(dir[0])\n return direcs\n\ndef get_dependencies(sources):\n #XXX scan sources for include statements\n return _get_headers(_get_directories(sources))\n\ndef is_local_src_dir(directory):\n \"\"\" Return true if directory is local directory.\n \"\"\"\n if not is_string(directory):\n return False\n abs_dir = os.path.abspath(directory)\n c = os.path.commonprefix([os.getcwd(),abs_dir])\n new_dir = abs_dir[len(c):].split(os.sep)\n if new_dir and not new_dir[0]:\n new_dir = new_dir[1:]\n if new_dir and new_dir[0]=='build':\n return False\n new_dir = os.sep.join(new_dir)\n return os.path.isdir(new_dir)\n\ndef _gsf_visit_func(filenames,dirname,names):\n if os.path.basename(dirname) in ['CVS','.svn','build']:\n names[:] = []\n return\n for name in names:\n if name[-1] in \"~#\":\n continue\n fullname = os.path.join(dirname,name)\n ext = os.path.splitext(fullname)[1]\n if ext and ext in ['.pyc','.o']:\n continue\n if os.path.isfile(fullname):\n filenames.append(fullname)\n\ndef get_ext_source_files(ext):\n # Get sources and any include files in the same directory.\n filenames = []\n sources = filter(is_string, ext.sources)\n filenames.extend(sources)\n filenames.extend(get_dependencies(sources))\n for d in ext.depends:\n if is_local_src_dir(d):\n os.path.walk(d,_gsf_visit_func,filenames)\n elif os.path.isfile(d):\n filenames.append(d)\n return filenames\n\ndef get_script_files(scripts):\n scripts = filter(is_string, scripts)\n return scripts\n\ndef get_lib_source_files(lib):\n filenames = []\n sources = lib[1].get('sources',[])\n sources = filter(is_string, sources)\n filenames.extend(sources)\n filenames.extend(get_dependencies(sources))\n depends = lib[1].get('depends',[])\n for d in depends:\n if is_local_src_dir(d):\n os.path.walk(d,_gsf_visit_func,filenames)\n elif os.path.isfile(d):\n filenames.append(d)\n return filenames\n\ndef get_data_files(data):\n if is_string(data):\n return [data]\n sources = data[1]\n filenames = []\n for s in sources:\n if callable(s):\n continue\n if is_local_src_dir(s):\n os.path.walk(s,_gsf_visit_func,filenames)\n elif is_string(s):\n if os.path.isfile(s):\n filenames.append(s)\n else:\n print 'Not existing data file:',s\n else:\n raise TypeError,repr(s)\n return filenames\n\ndef dot_join(*args):\n return '.'.join(filter(None,args))\n\ndef get_frame(level=0):\n try:\n return sys._getframe(level+1)\n except AttributeError:\n frame = sys.exc_info()[2].tb_frame\n for i in range(level+1):\n frame = frame.f_back\n return frame\n\n######################\n\ndef command_line_ok(_cache=[]):\n \"\"\" Return True if command line does not contain any\n help or display requests.\n \"\"\"\n if _cache:\n return _cache[0]\n ok = True\n from distutils.dist import Distribution\n display_opts = ['--'+n for n in Distribution.display_option_names]\n for o in Distribution.display_options:\n if o[1]: display_opts.append('-'+o[1])\n for arg in sys.argv:\n if arg.startswith('--help') or arg=='-h' or arg in display_opts:\n ok = False\n break\n _cache.append(ok)\n return ok\n\nclass Configuration:\n\n _list_keys = ['packages','ext_modules','data_files','include_dirs',\n 'libraries','headers','scripts','py_modules']\n _dict_keys = ['package_dir']\n\n numpy_include_dirs = []\n\n def __init__(self,\n package_name=None,\n parent_name=None,\n top_path=None,\n package_path=None,\n **attrs):\n \"\"\" Construct configuration instance of a package.\n\n package_name -- name of the package\n Ex.: 'distutils'\n parent_name -- name of the parent package\n Ex.: 'numpy'\n top_path -- directory of the toplevel package\n Ex.: the directory where the numpy package source sits\n package_path -- directory of package. Will be computed by magic from the\n directory of the caller module if not specified\n Ex.: the directory where numpy.distutils is\n \"\"\"\n self.name = dot_join(parent_name, package_name)\n\n caller_frame = get_frame(1)\n caller_name = eval('__name__',caller_frame.f_globals,caller_frame.f_locals)\n\n self.local_path = get_path(caller_name, top_path)\n if top_path is None:\n top_path = self.local_path\n if package_path is None:\n package_path = self.local_path\n elif os.path.isdir(njoin(self.local_path,package_path)):\n package_path = njoin(self.local_path,package_path)\n if not os.path.isdir(package_path):\n raise ValueError(\"%r is not a directory\" % (package_path,))\n self.top_path = top_path\n self.package_path = package_path\n # this is the relative path in the installed package\n self.path_in_package = os.path.join(*self.name.split('.'))\n\n self.list_keys = copy.copy(self._list_keys)\n self.dict_keys = copy.copy(self._dict_keys)\n\n for n in self.list_keys:\n setattr(self,n,copy.copy(attrs.get(n,[])))\n\n for n in self.dict_keys:\n setattr(self,n,copy.copy(attrs.get(n,{})))\n\n known_keys = self.list_keys + self.dict_keys\n self.extra_keys = []\n for n in attrs.keys():\n if n in known_keys:\n continue\n a = attrs[n]\n setattr(self,n,a)\n if isinstance(a, list):\n self.list_keys.append(n)\n elif isinstance(a, dict):\n self.dict_keys.append(n)\n else:\n self.extra_keys.append(n)\n\n if os.path.exists(njoin(package_path,'__init__.py')):\n self.packages.append(self.name)\n self.package_dir[self.name] = package_path\n\n return\n\n def todict(self):\n \"\"\" Return configuration distionary suitable for passing\n to distutils.core.setup() function.\n \"\"\"\n d = {}\n for n in self.list_keys + self.dict_keys + self.extra_keys:\n a = getattr(self,n)\n if a:\n d[n] = a\n if self.name:\n d['name'] = self.name\n return d\n\n def info(self, message):\n print message\n\n def warn(self, message):\n print>>sys.stderr, 'Warning:',message\n\n def __dict__(self):\n return self.todict()\n\n def get_distribution(self):\n import distutils.core\n dist = distutils.core._setup_distribution\n return dist\n\n def get_subpackage(self,subpackage_name,subpackage_path=None):\n \"\"\" Return subpackage configuration.\n \"\"\"\n if subpackage_name is None:\n assert subpackage_path is not None\n subpackage_name = os.path.basename(subpackage_path)\n l = subpackage_name.split('.')\n if subpackage_path is None:\n subpackage_path = njoin(*([self.local_path]+l))\n if '*' in subpackage_name:\n dirs = filter(os.path.isdir,glob.glob(subpackage_path))\n config_list = []\n for d in dirs:\n if not os.path.isfile(njoin(d,'__init__.py')):\n continue\n if 'build' in d.split(os.sep):\n continue\n n = '.'.join(d.split(os.sep)[-len(l):])\n c = self.get_subpackage(n)\n if c:\n config_list.append(c)\n return config_list\n else:\n subpackage_path = njoin(*([subpackage_path]+l[:-1]))\n subpackage_path = self._fix_paths([subpackage_path])[0]\n setup_py = njoin(subpackage_path,'setup.py')\n if not os.path.isfile(setup_py):\n setup_py = njoin(subpackage_path,'setup_%s.py' % (subpackage_name))\n\n if not os.path.isfile(setup_py):\n print 'Assuming default configuration '\\\n '(%s/{setup_%s,setup}.py was not found)' \\\n % (os.path.dirname(setup_py),subpackage_name)\n config = Configuration(subpackage_name,self.name,\n self.top_path,subpackage_path)\n else:\n # In case setup_py imports local modules:\n sys.path.insert(0,os.path.dirname(setup_py))\n try:\n info = (open(setup_py),setup_py,('.py','U',1))\n setup_name = os.path.splitext(os.path.basename(setup_py))[0]\n n = dot_join(self.name,setup_name)\n setup_module = imp.load_module('_'.join(n.split('.')),*info)\n\n if not hasattr(setup_module,'configuration'):\n print 'Assuming default configuration '\\\n '(%s does not define configuration())' % (setup_module)\n config = Configuration(subpackage_name,self.name,\n self.top_path,subpackage_path)\n else:\n args = (self.name,)\n if setup_module.configuration.func_code.co_argcount>1:\n args = args + (self.top_path,)\n config = setup_module.configuration(*args)\n\n finally:\n del sys.path[0]\n\n return config\n\n def add_subpackage(self,subpackage_name,subpackage_path=None):\n \"\"\" Add subpackage to configuration.\n \"\"\"\n config = self.get_subpackage(subpackage_name,subpackage_path)\n if not isinstance(config, list):\n config_list = [config]\n else:\n config_list = config\n for config in config_list:\n if not config:\n print 'No configuration returned, assuming unavailable.'\n else:\n if isinstance(config,Configuration):\n print 'Appending %s configuration to %s' % (config.name,self.name)\n self.dict_append(**config.todict())\n else:\n print 'Appending %s configuration to %s' % (config.get('name'),self.name)\n self.dict_append(**config)\n\n dist = self.get_distribution()\n if dist is not None:\n print 'distutils distribution has been initialized, it may be too late to add a subpackage', subpackage_name\n return\n\n def add_data_dir(self,data_path):\n \"\"\" Recursively add files under data_path to data_files list.\n Argument can be either\n - 2-sequence (,)\n - path to data directory where python datadir suffix defaults\n to package dir.\n If path is not absolute then it's datadir suffix is\n package dir + subdirname of the path.\n \"\"\"\n if is_sequence(data_path):\n d, data_path = data_path\n else:\n d = None\n if not is_string(data_path):\n raise TypeError(\"not a string: %r\" % (data_path,))\n for path in self.paths(data_path):\n if not os.path.exists(path):\n print 'Not existing data path',path\n continue\n filenames = []\n os.path.walk(path, _gsf_visit_func,filenames)\n if not os.path.isabs(path):\n npath = data_path\n if '*' in npath:\n npath = os.path.join(*(path.split(os.sep)[-len(npath.split(os.sep)):]))\n if d is None:\n d = self.path_in_package\n ds = os.path.join(d, npath)\n self.add_data_files((ds,filenames))\n else:\n if d is None:\n self.add_data_files(*filenames)\n else:\n self.add_data_files((d,filenames))\n return\n\n def add_data_files(self,*files):\n \"\"\" Add data files to configuration data_files.\n Argument(s) can be either\n - 2-sequence (,)\n - paths to data files where python datadir prefix defaults\n to package dir.\n If path is not absolute then it's datadir prefix is\n package dir + dirname of the path.\n \"\"\"\n data_dict = {}\n new_files = []\n for p in files:\n if not is_sequence(p):\n d = self.path_in_package\n if is_string(p) and not os.path.isabs(p):\n pd = os.path.dirname(p)\n if '*' in pd:\n pn = os.path.basename(p)\n n = len(pd.split(os.sep))\n for d1 in filter(os.path.isdir,self.paths(pd)):\n p = os.path.join(d1,pn)\n d1 = os.sep.join(d1.split(os.sep)[-n:])\n new_files.append((appendpath(d,d1),p))\n continue\n d = appendpath(d,pd)\n p = (d,p) \n new_files.append(p)\n \n files = []\n for prefix,filepattern in new_files:\n assert '*' not in prefix,`prefix,filepattern`\n if is_string(filepattern):\n file_list = self.paths(filepattern,include_non_existing=False)\n elif callable(filepattern):\n file_list = [filepattern]\n else:\n file_list = self.paths(*filepattern)\n\n nof_path_components = [len(f.split(os.sep))\n for f in file_list if is_string(f)]\n if nof_path_components:\n min_path_components = min(nof_path_components)-1\n else:\n min_path_components = 0\n\n for f in file_list:\n if is_string(f):\n extra_path_components = f.split(os.sep)[min_path_components:-1]\n p = njoin(*([prefix]+extra_path_components))\n else:\n p = prefix\n if not data_dict.has_key(p):\n data_dict[p] = [f]\n else:\n data_dict[p].append(f)\n\n dist = self.get_distribution()\n if dist is not None:\n dist.data_files.extend(data_dict.items())\n else:\n self.data_files.extend(data_dict.items())\n\n ### XXX Implement add_py_modules\n\n def add_include_dirs(self,*paths):\n \"\"\" Add paths to configuration include directories.\n \"\"\"\n include_dirs = self._fix_paths(paths)\n dist = self.get_distribution()\n if dist is not None:\n dist.include_dirs.extend(include_dirs)\n else:\n self.include_dirs.extend(include_dirs)\n return\n\n def add_headers(self,*files):\n \"\"\" Add installable headers to configuration.\n Argument(s) can be either\n - 2-sequence (,)\n - path(s) to header file(s) where python includedir suffix will default\n to package name.\n \"\"\"\n headers = []\n for path in files:\n if is_string(path):\n [headers.append((self.name,p)) for p in self.paths(path)]\n else:\n if not isinstance(path, (tuple, list)) or len(path) != 2:\n raise TypeError(repr(path))\n [headers.append((path[0],p)) for p in self.paths(path[1])]\n dist = self.get_distribution()\n if dist is not None:\n dist.headers.extend(headers)\n else:\n self.headers.extend(headers)\n return\n\n def _fix_paths(self,paths,include_non_existing=True):\n assert isinstance(paths,(list,tuple)),`type(paths)`\n new_paths = []\n for n in paths:\n if isinstance(n,str):\n if '*' in n or '?' in n:\n p = glob.glob(n)\n p2 = glob.glob(njoin(self.local_path,n))\n if p2:\n new_paths.extend(p2)\n elif p:\n new_paths.extend(p)\n else:\n if include_non_existing:\n new_paths.append(n)\n self.warn('could not resolve pattern: %r' % (n))\n else:\n n2 = njoin(self.local_path,n)\n if os.path.exists(n2):\n new_paths.append(n2)\n else:\n if os.path.exists(n):\n new_paths.append(n)\n elif include_non_existing:\n new_paths.append(n)\n if not os.path.exists(n):\n self.warn('not existing path: %r' % (n))\n else:\n new_paths.append(n)\n return map(minrelpath,new_paths)\n\n def paths(self,*paths,**kws):\n \"\"\" Apply glob to paths and prepend local_path if needed.\n \"\"\"\n include_non_existing = kws.get('include_non_existing',True)\n return self._fix_paths(paths,\n include_non_existing=include_non_existing)\n\n def add_extension(self,name,sources,**kw):\n \"\"\" Add extension to configuration.\n\n Keywords:\n include_dirs, define_macros, undef_macros,\n library_dirs, libraries, runtime_library_dirs,\n extra_objects, extra_compile_args, extra_link_args,\n export_symbols, swig_opts, depends, language,\n f2py_options, module_dirs\n extra_info - dict or list of dict of keywords to be\n appended to keywords.\n \"\"\"\n ext_args = copy.copy(kw)\n ext_args['name'] = dot_join(self.name,name)\n ext_args['sources'] = sources\n\n if ext_args.has_key('extra_info'):\n extra_info = ext_args['extra_info']\n del ext_args['extra_info']\n if type(extra_info) is type({}):\n extra_info = [extra_info]\n for info in extra_info:\n assert type(info) is type({}),`info`\n dict_append(ext_args,**info)\n\n for k in ext_args.keys():\n v = ext_args[k]\n if k in ['sources','depends','include_dirs','library_dirs',\n 'module_dirs','extra_objects']:\n new_v = self._fix_paths(v)\n ext_args[k] = new_v\n\n # Resolve out-of-tree dependencies\n libraries = ext_args.get('libraries',[])\n libnames = []\n ext_args['libraries'] = []\n for libname in libraries:\n if '@' in libname:\n lname,lpath = libname.split('@',1)\n lpath = os.path.abspath(njoin(self.local_path,lpath))\n if os.path.isdir(lpath):\n c = self.get_subpackage(None,lpath)\n if isinstance(c,Configuration):\n c = c.todict()\n for l in [l[0] for l in c.get('libraries',[])]:\n llname = l.split('__OF__',1)[0]\n if llname == lname:\n c.pop('name',None)\n dict_append(ext_args,**c)\n break\n continue\n libnames.append(libname)\n\n ext_args['libraries'] = libnames + ext_args['libraries']\n\n from numpy.distutils.core import Extension\n ext = Extension(**ext_args)\n self.ext_modules.append(ext)\n\n dist = self.get_distribution()\n if dist is not None:\n print 'distutils distribution has been initialized, it may be too late to add an extension', name\n return ext\n\n def add_library(self,name,sources,**build_info):\n \"\"\" Add library to configuration.\n\n Valid keywords for build_info:\n depends\n macros\n include_dirs\n extra_compiler_args\n f2py_options\n \"\"\"\n build_info = copy.copy(build_info)\n name = name #+ '__OF__' + self.name\n build_info['sources'] = sources\n\n for k in build_info.keys():\n v = build_info[k]\n if k in ['sources','depends','include_dirs','library_dirs',\n 'module_dirs','extra_objects']:\n new_v = self._fix_paths(v)\n build_info[k] = new_v\n self.libraries.append((name,build_info))\n\n dist = self.get_distribution()\n if dist is not None:\n print 'distutils distribution has been initialized, it may be too late to add a library', name\n return\n\n def add_scripts(self,*files):\n \"\"\" Add scripts to configuration.\n \"\"\"\n scripts = self._fix_paths(files)\n dist = self.get_distribution()\n if dist is not None:\n dist.scripts.extend(scripts)\n else:\n self.scripts.extend(scripts)\n return\n\n def dict_append(self,**dict):\n for key in self.list_keys:\n a = getattr(self,key)\n a.extend(dict.get(key,[]))\n for key in self.dict_keys:\n a = getattr(self,key)\n a.update(dict.get(key,{}))\n known_keys = self.list_keys + self.dict_keys + self.extra_keys\n for key in dict.keys():\n if key not in known_keys and not hasattr(self,key):\n if key not in ['version']:\n self.warn('Inheriting attribute %r from %r' \\\n % (key,dict.get('name','?')))\n setattr(self,key,dict[key])\n self.extra_keys.append(key)\n return\n\n def __str__(self):\n known_keys = self.list_keys + self.dict_keys + self.extra_keys\n s = '<'+5*'-' + '\\n'\n s += 'Configuration of '+self.name+':\\n'\n for k in known_keys:\n a = getattr(self,k,None)\n if a:\n s += '%s = %r\\n' % (k,a)\n s += 5*'-' + '>'\n return s\n\n def get_config_cmd(self):\n cmd = get_cmd('config')\n cmd.ensure_finalized()\n cmd.dump_source = 0\n cmd.noisy = 0\n old_path = os.environ.get('PATH')\n if old_path:\n path = os.pathsep.join(['.',old_path])\n os.environ['PATH'] = path\n return cmd\n\n def get_build_temp_dir(self):\n cmd = get_cmd('build')\n cmd.ensure_finalized()\n return cmd.build_temp\n\n def have_f77c(self):\n \"\"\" Check for availability of Fortran 77 compiler.\n Use it inside source generating function to ensure that\n setup distribution instance has been initialized.\n \"\"\"\n simple_fortran_subroutine = '''\n subroutine simple\n end\n '''\n config_cmd = self.get_config_cmd()\n flag = config_cmd.try_compile(simple_fortran_subroutine,lang='f77')\n return flag\n\n def have_f90c(self):\n \"\"\" Check for availability of Fortran 90 compiler.\n Use it inside source generating function to ensure that\n setup distribution instance has been initialized.\n \"\"\"\n simple_fortran_subroutine = '''\n subroutine simple\n end\n '''\n config_cmd = self.get_config_cmd()\n flag = config_cmd.try_compile(simple_fortran_subroutine,lang='f90')\n return flag\n\n def append_to(self, extlib):\n \"\"\" Append libraries, include_dirs to extension or library item.\n \"\"\"\n if is_sequence(extlib):\n lib_name, build_info = extlib\n dict_append(build_info,\n libraries=self.libraries,\n include_dirs=self.include_dirs)\n else:\n from numpy.distutils.core import Extension\n assert isinstance(extlib,Extension),`extlib`\n extlib.libraries.extend(self.libraries)\n extlib.include_dirs.extend(self.include_dirs)\n return\n\n def _get_svn_revision(self,path):\n \"\"\" Return path's SVN revision number.\n \"\"\"\n entries = njoin(path,'.svn','entries')\n revision = None\n if os.path.isfile(entries):\n f = open(entries)\n m = re.search(r'revision=\"(?P\\d+)\"',f.read())\n f.close()\n if m:\n revision = int(m.group('revision'))\n return revision\n\n def get_version(self):\n \"\"\" Try to get version string of a package.\n \"\"\"\n version = getattr(self,'version',None)\n if version is not None:\n return version\n\n # Get version from version file.\n files = ['__version__.py',\n self.name.split('.')[-1]+'_version.py',\n 'version.py',\n '__svn_version__.py']\n version_vars = ['version',\n '__version__',\n self.name.split('.')[-1]+'_version']\n for f in files:\n fn = njoin(self.local_path,f)\n if os.path.isfile(fn):\n info = (open(fn),fn,('.py','U',1))\n name = os.path.splitext(os.path.basename(fn))[0]\n n = dot_join(self.name,name)\n try:\n version_module = imp.load_module('_'.join(n.split('.')),*info)\n except ImportError,msg:\n print msg\n version_module = None\n if version_module is None:\n continue\n\n for a in version_vars:\n version = getattr(version_module,a,None)\n if version is not None:\n break\n if version is not None:\n break\n\n if version is not None:\n self.version = version\n return version\n\n # Get version as SVN revision number\n revision = self._get_svn_revision(self.local_path)\n if revision is not None:\n version = str(revision)\n self.version = version\n\n return version\n\n def make_svn_version_py(self):\n \"\"\" Generate package __svn_version__.py file from SVN revision number,\n it will be removed after python exits but will be available\n when sdist, etc commands are executed.\n\n If __svn_version__.py existed before, nothing is done.\n \"\"\"\n target = njoin(self.local_path,'__svn_version__.py')\n if os.path.isfile(target):\n return\n\n def generate_svn_version_py():\n if not os.path.isfile(target):\n revision = self._get_svn_revision(self.local_path)\n assert revision is not None,'hmm, why I am not inside SVN tree???'\n version = str(revision)\n print 'Creating %s (version=%r)' % (target,version)\n f = open(target,'w')\n f.write('version = %r\\n' % (version))\n f.close()\n\n import atexit\n def rm_file(f=target):\n try: os.remove(f); print 'removed',f\n except OSError: pass\n try: os.remove(f+'c'); print 'removed',f+'c'\n except OSError: pass\n atexit.register(rm_file)\n\n return target\n\n self.add_data_files((self.path_in_package, generate_svn_version_py()))\n return\n\n def make_config_py(self,name='__config__'):\n \"\"\" Generate package __config__.py file containing system_info\n information used during building the package.\n \"\"\"\n self.py_modules.append((self.name,name,generate_config_py))\n return\n\n def get_info(self,*names):\n \"\"\" Get resources information.\n \"\"\"\n from system_info import get_info, dict_append\n info_dict = {}\n for a in names:\n dict_append(info_dict,**get_info(a))\n return info_dict\n\n if not command_line_ok():\n _do_nothing = lambda *args,**kws: None\n add_subpackage = _do_nothing\n add_extension = _do_nothing\n add_library = _do_nothing\n add_data_dir = _do_nothing\n add_data_files = _do_nothing\n add_scripts = _do_nothing\n add_headers = _do_nothing\n add_include_dirs = _do_nothing\n make_config_py = _do_nothing\n get_info = lambda *args,**kws:{}\n have_f77c = lambda *args,**kws: False\n have_f90c = lambda *args,**kws: False\n\ndef get_cmd(cmdname,_cache={}):\n if not _cache.has_key(cmdname):\n import distutils.core\n dist = distutils.core._setup_distribution\n if dist is None:\n from distutils.errors import DistutilsInternalError\n raise DistutilsInternalError,\\\n 'setup distribution instance not initialized'\n cmd = dist.get_command_obj(cmdname)\n _cache[cmdname] = cmd\n return _cache[cmdname]\n\ndef get_numpy_include_dirs():\n # numpy_include_dirs are set by numpy/core/setup.py, otherwise []\n include_dirs = Configuration.numpy_include_dirs[:]\n if not include_dirs:\n import numpy\n if numpy.show_config is None:\n # running from numpy_core source directory\n include_dirs.append(njoin(os.path.dirname(numpy.__file__),\n 'core','include'))\n else:\n # using installed numpy core headers\n import numpy.core as core\n include_dirs.append(njoin(os.path.dirname(core.__file__),'include'))\n # else running numpy/core/setup.py\n return include_dirs\n\n#########################\n\ndef default_config_dict(name = None, parent_name = None, local_path=None):\n \"\"\" Return a configuration dictionary for usage in\n configuration() function defined in file setup_.py.\n \"\"\"\n import warnings\n warnings.warn('Use Configuration(%s,%s,top_path=%s) instead of '\\\n 'deprecated default_config_dict(%s,%s,%s)' \\\n % (`name`,`parent_name`,`local_path`,\n `name`,`parent_name`,`local_path`,\n ))\n c = Configuration(name, parent_name, local_path)\n return c.todict()\n\n\ndef dict_append(d,**kws):\n for k,v in kws.items():\n if d.has_key(k):\n d[k].extend(v)\n else:\n d[k] = v\n\ndef appendpath(prefix,path):\n if not ('/' == os.path.sep):\n prefix = prefix.replace('/',os.path.sep)\n path = path.replace('/',os.path.sep)\n drive = ''\n if os.path.isabs(path):\n drive = os.path.splitdrive(prefix)[0]\n absprefix = os.path.splitdrive(os.path.abspath(prefix))[1]\n pathdrive,path = os.path.splitdrive(path)\n d = os.path.commonprefix([absprefix,path])\n if os.path.join(absprefix[:len(d)],absprefix[len(d):])!=absprefix \\\n or os.path.join(path[:len(d)],path[len(d):])!=path:\n # Handle invalid paths\n d = os.path.dirname(d)\n subpath = path[len(d):]\n if os.path.isabs(subpath):\n subpath = subpath[1:]\n else:\n subpath = path\n return os.path.normpath(njoin(drive + prefix, subpath))\n\n\n\n\n\ndef generate_config_py(target):\n \"\"\" Generate config.py file containing system_info information\n used during building the package.\n\n Usage:\\\n config['py_modules'].append((packagename, '__config__',generate_config_py))\n \"\"\"\n from numpy.distutils.system_info import system_info\n from distutils.dir_util import mkpath\n mkpath(os.path.dirname(target))\n f = open(target,'w')\n f.write('# This file is generated by %s\\n' % (os.path.abspath(sys.argv[0])))\n f.write('# It contains system_info results at the time of building this package.\\n')\n f.write('__all__ = [\"get_info\",\"show\"]\\n\\n')\n for k,i in system_info.saved_results.items():\n f.write('%s=%r\\n' % (k,i))\n f.write('\\ndef get_info(name): g=globals(); return g.get(name,g.get(name+\"_info\",{}))\\n')\n f.write('''\ndef show():\n for name,info_dict in globals().items():\n if name[0]==\"_\" or type(info_dict) is not type({}): continue\n print name+\":\"\n if not info_dict:\n print \" NOT AVAILABLE\"\n for k,v in info_dict.items():\n v = str(v)\n if k==\\'sources\\' and len(v)>200: v = v[:60]+\\' ...\\\\n... \\'+v[-60:]\n print \\' %s = %s\\'%(k,v)\n print\n return\n ''')\n\n f.close()\n return target\n\ndef generate_svn_version_py(extension, build_dir):\n \"\"\" Generate __svn_version__.py file containing SVN\n revision number of a module.\n\n To use, add the following codelet to setup\n configuration(..) function\n\n ext = Extension(dot_join(config['name'],'__svn_version__'),\n sources=[generate_svn_version_py])\n ext.local_path = local_path\n config['ext_modules'].append(ext)\n\n \"\"\"\n from distutils import dep_util\n local_path = extension.local_path\n target = njoin(build_dir, '__svn_version__.py')\n entries = njoin(local_path,'.svn','entries')\n if os.path.isfile(entries):\n if not dep_util.newer(entries, target):\n return target\n elif os.path.isfile(target):\n return target\n\n revision = get_svn_revision(local_path)\n f = open(target,'w')\n f.write('revision=%s\\n' % (revision))\n f.close()\n return target\n", + "source_code_before": "import os\nimport re\nimport sys\nimport imp\nimport copy\nimport glob\n\n__all__ = ['Configuration', 'get_numpy_include_dirs', 'default_config_dict',\n 'dict_append', 'appendpath', 'generate_config_py',\n 'generate_svn_version_py', 'get_cmd', 'allpath',\n 'terminal_has_colors', 'red_text', 'green_text', 'yellow_text',\n 'blue_text', 'cyan_text', 'cyg2win32', 'all_strings',\n 'has_f_sources', 'has_cxx_sources', 'filter_sources',\n 'get_dependencies', 'is_local_src_dir', 'get_ext_source_files',\n 'get_script_files', 'get_lib_source_files', 'get_data_files',\n 'dot_join', 'get_frame', 'minrelpath','njoin']\n\ndef allpath(name):\n \"Convert a /-separated pathname to one using the OS's path separator.\"\n splitted = name.split('/')\n return os.path.join(*splitted)\n\ndef get_path(mod_name,parent_path=None):\n \"\"\" Return path of the module.\n\n Returned path is relative to parent_path when given,\n otherwise it is absolute path.\n \"\"\"\n if mod_name == '__main__':\n d = os.path.abspath('.')\n elif mod_name == '__builtin__':\n #builtin if/then added by Pearu for use in core.run_setup.\n d = os.path.dirname(os.path.abspath(sys.argv[0]))\n else:\n __import__(mod_name)\n mod = sys.modules[mod_name]\n file = mod.__file__\n d = os.path.dirname(os.path.abspath(file))\n if parent_path is not None:\n pd = os.path.abspath(parent_path)\n if pd==d[:len(pd)]:\n d = d[len(pd)+1:]\n return d or '.'\n\ndef njoin(*path):\n \"\"\" Join two or more pathname components +\n - convert a /-separated pathname to one using the OS's path separator.\n - resolve `..` from path.\n \"\"\"\n if isinstance(path,tuple):\n path = os.path.join(*path)\n if not isinstance(path,str): return path\n if not ('/' == os.path.sep):\n path = path.replace('/',os.path.sep)\n return minrelpath(path)\n\ndef minrelpath(path):\n \"\"\" Resolve `..` from path.\n \"\"\"\n if not isinstance(path, str): return path\n if '..' not in path: return path\n l = path.split(os.sep)\n j = 1\n while l:\n try:\n i = l.index('..',j)\n except ValueError:\n break\n if l[i-1]=='..':\n j += 1\n else:\n del l[i],l[i-1]\n j = 1\n if not l: return ''\n return os.path.join(*l)\n\n# Hooks for colored terminal output.\n# See also http://www.livinglogic.de/Python/ansistyle\ndef terminal_has_colors():\n if sys.platform=='cygwin' and not os.environ.has_key('USE_COLOR'):\n # Avoid importing curses that causes illegal operation\n # with a message:\n # PYTHON2 caused an invalid page fault in\n # module CYGNURSES7.DLL as 015f:18bbfc28\n # Details: Python 2.3.3 [GCC 3.3.1 (cygming special)]\n # ssh to Win32 machine from debian\n # curses.version is 2.2\n # CYGWIN_98-4.10, release 1.5.7(0.109/3/2))\n return 0\n if hasattr(sys.stdout,'isatty') and sys.stdout.isatty():\n try:\n import curses\n curses.setupterm()\n if (curses.tigetnum(\"colors\") >= 0\n and curses.tigetnum(\"pairs\") >= 0\n and ((curses.tigetstr(\"setf\") is not None\n and curses.tigetstr(\"setb\") is not None)\n or (curses.tigetstr(\"setaf\") is not None\n and curses.tigetstr(\"setab\") is not None)\n or curses.tigetstr(\"scp\") is not None)):\n return 1\n except Exception,msg:\n pass\n return 0\n\nif terminal_has_colors():\n def red_text(s): return '\\x1b[31m%s\\x1b[0m'%s\n def green_text(s): return '\\x1b[32m%s\\x1b[0m'%s\n def yellow_text(s): return '\\x1b[33m%s\\x1b[0m'%s\n def blue_text(s): return '\\x1b[34m%s\\x1b[0m'%s\n def cyan_text(s): return '\\x1b[35m%s\\x1b[0m'%s\nelse:\n def red_text(s): return s\n def green_text(s): return s\n def yellow_text(s): return s\n def cyan_text(s): return s\n def blue_text(s): return s\n\n#########################\n\ndef cyg2win32(path):\n if sys.platform=='cygwin' and path.startswith('/cygdrive'):\n path = path[10] + ':' + os.path.normcase(path[11:])\n return path\n\n#########################\n\n#XXX need support for .C that is also C++\ncxx_ext_match = re.compile(r'.*[.](cpp|cxx|cc)\\Z',re.I).match\nfortran_ext_match = re.compile(r'.*[.](f90|f95|f77|for|ftn|f)\\Z',re.I).match\nf90_ext_match = re.compile(r'.*[.](f90|f95)\\Z',re.I).match\nf90_module_name_match = re.compile(r'\\s*module\\s*(?P[\\w_]+)',re.I).match\ndef _get_f90_modules(source):\n \"\"\" Return a list of Fortran f90 module names that\n given source file defines.\n \"\"\"\n if not f90_ext_match(source):\n return []\n modules = []\n f = open(source,'r')\n f_readlines = getattr(f,'xreadlines',f.readlines)\n for line in f_readlines():\n m = f90_module_name_match(line)\n if m:\n name = m.group('name')\n modules.append(name)\n # break # XXX can we assume that there is one module per file?\n f.close()\n return modules\n\ndef is_string(s):\n return isinstance(s, str)\n\ndef all_strings(lst):\n \"\"\" Return True if all items in lst are string objects. \"\"\"\n for item in lst:\n if not is_string(item):\n return False\n return True\n\ndef is_sequence(seq):\n if is_string(seq):\n return False\n try:\n len(seq)\n except:\n return False\n return True\n\ndef has_f_sources(sources):\n \"\"\" Return True if sources contains Fortran files \"\"\"\n for source in sources:\n if fortran_ext_match(source):\n return True\n return False\n\ndef has_cxx_sources(sources):\n \"\"\" Return True if sources contains C++ files \"\"\"\n for source in sources:\n if cxx_ext_match(source):\n return True\n return False\n\ndef filter_sources(sources):\n \"\"\" Return four lists of filenames containing\n C, C++, Fortran, and Fortran 90 module sources,\n respectively.\n \"\"\"\n c_sources = []\n cxx_sources = []\n f_sources = []\n fmodule_sources = []\n for source in sources:\n if fortran_ext_match(source):\n modules = _get_f90_modules(source)\n if modules:\n fmodule_sources.append(source)\n else:\n f_sources.append(source)\n elif cxx_ext_match(source):\n cxx_sources.append(source)\n else:\n c_sources.append(source)\n return c_sources, cxx_sources, f_sources, fmodule_sources\n\n\ndef _get_headers(directory_list):\n # get *.h files from list of directories\n headers = []\n for dir in directory_list:\n head = glob.glob(os.path.join(dir,\"*.h\")) #XXX: *.hpp files??\n headers.extend(head)\n return headers\n\ndef _get_directories(list_of_sources):\n # get unique directories from list of sources.\n direcs = []\n for file in list_of_sources:\n dir = os.path.split(file)\n if dir[0] != '' and not dir[0] in direcs:\n direcs.append(dir[0])\n return direcs\n\ndef get_dependencies(sources):\n #XXX scan sources for include statements\n return _get_headers(_get_directories(sources))\n\ndef is_local_src_dir(directory):\n \"\"\" Return true if directory is local directory.\n \"\"\"\n if not is_string(directory):\n return False\n abs_dir = os.path.abspath(directory)\n c = os.path.commonprefix([os.getcwd(),abs_dir])\n new_dir = abs_dir[len(c):].split(os.sep)\n if new_dir and not new_dir[0]:\n new_dir = new_dir[1:]\n if new_dir and new_dir[0]=='build':\n return False\n new_dir = os.sep.join(new_dir)\n return os.path.isdir(new_dir)\n\ndef _gsf_visit_func(filenames,dirname,names):\n if os.path.basename(dirname) in ['CVS','.svn','build']:\n names[:] = []\n return\n for name in names:\n if name[-1] in \"~#\":\n continue\n fullname = os.path.join(dirname,name)\n ext = os.path.splitext(fullname)[1]\n if ext and ext in ['.pyc','.o']:\n continue\n if os.path.isfile(fullname):\n filenames.append(fullname)\n\ndef get_ext_source_files(ext):\n # Get sources and any include files in the same directory.\n filenames = []\n sources = filter(is_string, ext.sources)\n filenames.extend(sources)\n filenames.extend(get_dependencies(sources))\n for d in ext.depends:\n if is_local_src_dir(d):\n os.path.walk(d,_gsf_visit_func,filenames)\n elif os.path.isfile(d):\n filenames.append(d)\n return filenames\n\ndef get_script_files(scripts):\n scripts = filter(is_string, scripts)\n return scripts\n\ndef get_lib_source_files(lib):\n filenames = []\n sources = lib[1].get('sources',[])\n sources = filter(is_string, sources)\n filenames.extend(sources)\n filenames.extend(get_dependencies(sources))\n depends = lib[1].get('depends',[])\n for d in depends:\n if is_local_src_dir(d):\n os.path.walk(d,_gsf_visit_func,filenames)\n elif os.path.isfile(d):\n filenames.append(d)\n return filenames\n\ndef get_data_files(data):\n if is_string(data):\n return [data]\n sources = data[1]\n filenames = []\n for s in sources:\n if callable(s):\n continue\n if is_local_src_dir(s):\n os.path.walk(s,_gsf_visit_func,filenames)\n elif is_string(s):\n if os.path.isfile(s):\n filenames.append(s)\n else:\n print 'Not existing data file:',s\n else:\n raise TypeError,repr(s)\n return filenames\n\ndef dot_join(*args):\n return '.'.join(filter(None,args))\n\ndef get_frame(level=0):\n try:\n return sys._getframe(level+1)\n except AttributeError:\n frame = sys.exc_info()[2].tb_frame\n for i in range(level+1):\n frame = frame.f_back\n return frame\n\n######################\n\nclass Configuration:\n\n _list_keys = ['packages','ext_modules','data_files','include_dirs',\n 'libraries','headers','scripts','py_modules']\n _dict_keys = ['package_dir']\n\n numpy_include_dirs = []\n\n def __init__(self,\n package_name=None,\n parent_name=None,\n top_path=None,\n package_path=None,\n **attrs):\n \"\"\" Construct configuration instance of a package.\n\n package_name -- name of the package\n Ex.: 'distutils'\n parent_name -- name of the parent package\n Ex.: 'numpy'\n top_path -- directory of the toplevel package\n Ex.: the directory where the numpy package source sits\n package_path -- directory of package. Will be computed by magic from the\n directory of the caller module if not specified\n Ex.: the directory where numpy.distutils is\n \"\"\"\n self.name = dot_join(parent_name, package_name)\n\n caller_frame = get_frame(1)\n caller_name = eval('__name__',caller_frame.f_globals,caller_frame.f_locals)\n\n self.local_path = get_path(caller_name, top_path)\n if top_path is None:\n top_path = self.local_path\n if package_path is None:\n package_path = self.local_path\n elif os.path.isdir(njoin(self.local_path,package_path)):\n package_path = njoin(self.local_path,package_path)\n if not os.path.isdir(package_path):\n raise ValueError(\"%r is not a directory\" % (package_path,))\n self.top_path = top_path\n self.package_path = package_path\n # this is the relative path in the installed package\n self.path_in_package = os.path.join(*self.name.split('.'))\n\n self.list_keys = copy.copy(self._list_keys)\n self.dict_keys = copy.copy(self._dict_keys)\n\n for n in self.list_keys:\n setattr(self,n,copy.copy(attrs.get(n,[])))\n\n for n in self.dict_keys:\n setattr(self,n,copy.copy(attrs.get(n,{})))\n\n known_keys = self.list_keys + self.dict_keys\n self.extra_keys = []\n for n in attrs.keys():\n if n in known_keys:\n continue\n a = attrs[n]\n setattr(self,n,a)\n if isinstance(a, list):\n self.list_keys.append(n)\n elif isinstance(a, dict):\n self.dict_keys.append(n)\n else:\n self.extra_keys.append(n)\n\n if os.path.exists(njoin(package_path,'__init__.py')):\n self.packages.append(self.name)\n self.package_dir[self.name] = package_path\n\n return\n\n def todict(self):\n \"\"\" Return configuration distionary suitable for passing\n to distutils.core.setup() function.\n \"\"\"\n d = {}\n for n in self.list_keys + self.dict_keys + self.extra_keys:\n a = getattr(self,n)\n if a:\n d[n] = a\n if self.name:\n d['name'] = self.name\n return d\n\n def info(self, message):\n print message\n\n def warn(self, message):\n print 'Warning:',message\n\n def __dict__(self):\n return self.todict()\n\n def get_distribution(self):\n import distutils.core\n dist = distutils.core._setup_distribution\n return dist\n\n def get_subpackage(self,subpackage_name,subpackage_path=None):\n \"\"\" Return subpackage configuration.\n \"\"\"\n if subpackage_name is None:\n assert subpackage_path is not None\n subpackage_name = os.path.basename(subpackage_path)\n l = subpackage_name.split('.')\n if subpackage_path is None:\n subpackage_path = njoin(*([self.local_path]+l))\n if '*' in subpackage_name:\n dirs = filter(os.path.isdir,glob.glob(subpackage_path))\n config_list = []\n for d in dirs:\n if not os.path.isfile(njoin(d,'__init__.py')):\n continue\n if 'build' in d.split(os.sep):\n continue\n n = '.'.join(d.split(os.sep)[-len(l):])\n c = self.get_subpackage(n)\n if c:\n config_list.append(c)\n return config_list\n else:\n subpackage_path = njoin(*([subpackage_path]+l[:-1]))\n subpackage_path = self._fix_paths([subpackage_path])[0]\n setup_py = njoin(subpackage_path,'setup.py')\n if not os.path.isfile(setup_py):\n setup_py = njoin(subpackage_path,'setup_%s.py' % (subpackage_name))\n\n if not os.path.isfile(setup_py):\n print 'Assuming default configuration '\\\n '(%s/{setup_%s,setup}.py was not found)' \\\n % (os.path.dirname(setup_py),subpackage_name)\n config = Configuration(subpackage_name,self.name,\n self.top_path,subpackage_path)\n else:\n # In case setup_py imports local modules:\n sys.path.insert(0,os.path.dirname(setup_py))\n try:\n info = (open(setup_py),setup_py,('.py','U',1))\n setup_name = os.path.splitext(os.path.basename(setup_py))[0]\n n = dot_join(self.name,setup_name)\n setup_module = imp.load_module('_'.join(n.split('.')),*info)\n\n if not hasattr(setup_module,'configuration'):\n print 'Assuming default configuration '\\\n '(%s does not define configuration())' % (setup_module)\n config = Configuration(subpackage_name,self.name,\n self.top_path,subpackage_path)\n else:\n args = (self.name,)\n if setup_module.configuration.func_code.co_argcount>1:\n args = args + (self.top_path,)\n config = setup_module.configuration(*args)\n\n finally:\n del sys.path[0]\n\n return config\n\n def add_subpackage(self,subpackage_name,subpackage_path=None):\n \"\"\" Add subpackage to configuration.\n \"\"\"\n config = self.get_subpackage(subpackage_name,subpackage_path)\n if not isinstance(config, list):\n config_list = [config]\n else:\n config_list = config\n for config in config_list:\n if not config:\n print 'No configuration returned, assuming unavailable.'\n else:\n if isinstance(config,Configuration):\n print 'Appending %s configuration to %s' % (config.name,self.name)\n self.dict_append(**config.todict())\n else:\n print 'Appending %s configuration to %s' % (config.get('name'),self.name)\n self.dict_append(**config)\n\n dist = self.get_distribution()\n if dist is not None:\n print 'distutils distribution has been initialized, it may be too late to add a subpackage', subpackage_name\n return\n\n def add_data_dir(self,data_path):\n \"\"\" Recursively add files under data_path to data_files list.\n Argument can be either\n - 2-sequence (,)\n - path to data directory where python datadir suffix defaults\n to package dir.\n If path is not absolute then it's datadir suffix is\n package dir + subdirname of the path.\n \"\"\"\n if is_sequence(data_path):\n d, data_path = data_path\n else:\n d = None\n if not is_string(data_path):\n raise TypeError(\"not a string: %r\" % (data_path,))\n for path in self.paths(data_path):\n if not os.path.exists(path):\n print 'Not existing data path',path\n continue\n filenames = []\n os.path.walk(path, _gsf_visit_func,filenames)\n if not os.path.isabs(path):\n npath = data_path\n if '*' in npath:\n npath = os.path.join(*(path.split(os.sep)[-len(npath.split(os.sep)):]))\n if d is None:\n d = self.path_in_package\n ds = os.path.join(d, npath)\n self.add_data_files((ds,filenames))\n else:\n if d is None:\n self.add_data_files(*filenames)\n else:\n self.add_data_files((d,filenames))\n return\n\n def add_data_files(self,*files):\n \"\"\" Add data files to configuration data_files.\n Argument(s) can be either\n - 2-sequence (,)\n - paths to data files where python datadir prefix defaults\n to package dir.\n If path is not absolute then it's datadir prefix is\n package dir + dirname of the path.\n \"\"\"\n data_dict = {}\n new_files = []\n for p in files:\n if not is_sequence(p):\n d = self.path_in_package\n if is_string(p) and not os.path.isabs(p):\n pd = os.path.dirname(p)\n if '*' in pd:\n pn = os.path.basename(p)\n n = len(pd.split(os.sep))\n for d1 in filter(os.path.isdir,self.paths(pd)):\n p = os.path.join(d1,pn)\n d1 = os.sep.join(d1.split(os.sep)[-n:])\n new_files.append((appendpath(d,d1),p))\n continue\n d = appendpath(d,pd)\n p = (d,p) \n new_files.append(p)\n \n files = []\n for prefix,filepattern in new_files:\n assert '*' not in prefix,`prefix,filepattern`\n if is_string(filepattern):\n file_list = self.paths(filepattern,include_non_existing=False)\n elif callable(filepattern):\n file_list = [filepattern]\n else:\n file_list = self.paths(*filepattern)\n\n nof_path_components = [len(f.split(os.sep))\n for f in file_list if is_string(f)]\n if nof_path_components:\n min_path_components = min(nof_path_components)-1\n else:\n min_path_components = 0\n\n for f in file_list:\n if is_string(f):\n extra_path_components = f.split(os.sep)[min_path_components:-1]\n p = njoin(*([prefix]+extra_path_components))\n else:\n p = prefix\n if not data_dict.has_key(p):\n data_dict[p] = [f]\n else:\n data_dict[p].append(f)\n\n dist = self.get_distribution()\n if dist is not None:\n dist.data_files.extend(data_dict.items())\n else:\n self.data_files.extend(data_dict.items())\n\n ### XXX Implement add_py_modules\n\n def add_include_dirs(self,*paths):\n \"\"\" Add paths to configuration include directories.\n \"\"\"\n include_dirs = self._fix_paths(paths)\n dist = self.get_distribution()\n if dist is not None:\n dist.include_dirs.extend(include_dirs)\n else:\n self.include_dirs.extend(include_dirs)\n return\n\n def add_headers(self,*files):\n \"\"\" Add installable headers to configuration.\n Argument(s) can be either\n - 2-sequence (,)\n - path(s) to header file(s) where python includedir suffix will default\n to package name.\n \"\"\"\n headers = []\n for path in files:\n if is_string(path):\n [headers.append((self.name,p)) for p in self.paths(path)]\n else:\n if not isinstance(path, (tuple, list)) or len(path) != 2:\n raise TypeError(repr(path))\n [headers.append((path[0],p)) for p in self.paths(path[1])]\n dist = self.get_distribution()\n if dist is not None:\n dist.headers.extend(headers)\n else:\n self.headers.extend(headers)\n return\n\n def _fix_paths(self,paths,include_non_existing=True):\n assert isinstance(paths,(list,tuple)),`type(paths)`\n new_paths = []\n for n in paths:\n if isinstance(n,str):\n if '*' in n or '?' in n:\n p = glob.glob(n)\n p2 = glob.glob(njoin(self.local_path,n))\n if p2:\n new_paths.extend(p2)\n elif p:\n new_paths.extend(p)\n else:\n if include_non_existing:\n new_paths.append(n)\n self.warn('could not resolve pattern: %r' % (n))\n else:\n n2 = njoin(self.local_path,n)\n if os.path.exists(n2):\n new_paths.append(n2)\n else:\n if os.path.exists(n):\n new_paths.append(n)\n elif include_non_existing:\n new_paths.append(n)\n if not os.path.exists(n):\n self.warn('not existing path: %r' % (n))\n else:\n new_paths.append(n)\n return map(minrelpath,new_paths)\n\n def paths(self,*paths,**kws):\n \"\"\" Apply glob to paths and prepend local_path if needed.\n \"\"\"\n include_non_existing = kws.get('include_non_existing',True)\n return self._fix_paths(paths,\n include_non_existing=include_non_existing)\n\n def add_extension(self,name,sources,**kw):\n \"\"\" Add extension to configuration.\n\n Keywords:\n include_dirs, define_macros, undef_macros,\n library_dirs, libraries, runtime_library_dirs,\n extra_objects, extra_compile_args, extra_link_args,\n export_symbols, swig_opts, depends, language,\n f2py_options, module_dirs\n extra_info - dict or list of dict of keywords to be\n appended to keywords.\n \"\"\"\n ext_args = copy.copy(kw)\n ext_args['name'] = dot_join(self.name,name)\n ext_args['sources'] = sources\n\n if ext_args.has_key('extra_info'):\n extra_info = ext_args['extra_info']\n del ext_args['extra_info']\n if type(extra_info) is type({}):\n extra_info = [extra_info]\n for info in extra_info:\n assert type(info) is type({}),`info`\n dict_append(ext_args,**info)\n\n for k in ext_args.keys():\n v = ext_args[k]\n if k in ['sources','depends','include_dirs','library_dirs',\n 'module_dirs','extra_objects']:\n new_v = self._fix_paths(v)\n ext_args[k] = new_v\n\n # Resolve out-of-tree dependencies\n libraries = ext_args.get('libraries',[])\n libnames = []\n ext_args['libraries'] = []\n for libname in libraries:\n if '@' in libname:\n lname,lpath = libname.split('@',1)\n lpath = os.path.abspath(njoin(self.local_path,lpath))\n if os.path.isdir(lpath):\n c = self.get_subpackage(None,lpath)\n if isinstance(c,Configuration):\n c = c.todict()\n for l in [l[0] for l in c.get('libraries',[])]:\n llname = l.split('__OF__',1)[0]\n if llname == lname:\n c.pop('name',None)\n dict_append(ext_args,**c)\n break\n continue\n libnames.append(libname)\n\n ext_args['libraries'] = libnames + ext_args['libraries']\n\n from numpy.distutils.core import Extension\n ext = Extension(**ext_args)\n self.ext_modules.append(ext)\n\n dist = self.get_distribution()\n if dist is not None:\n print 'distutils distribution has been initialized, it may be too late to add an extension', name\n return ext\n\n def add_library(self,name,sources,**build_info):\n \"\"\" Add library to configuration.\n\n Valid keywords for build_info:\n depends\n macros\n include_dirs\n extra_compiler_args\n f2py_options\n \"\"\"\n build_info = copy.copy(build_info)\n name = name #+ '__OF__' + self.name\n build_info['sources'] = sources\n\n for k in build_info.keys():\n v = build_info[k]\n if k in ['sources','depends','include_dirs','library_dirs',\n 'module_dirs','extra_objects']:\n new_v = self._fix_paths(v)\n build_info[k] = new_v\n self.libraries.append((name,build_info))\n\n dist = self.get_distribution()\n if dist is not None:\n print 'distutils distribution has been initialized, it may be too late to add a library', name\n return\n\n def add_scripts(self,*files):\n \"\"\" Add scripts to configuration.\n \"\"\"\n scripts = self._fix_paths(files)\n dist = self.get_distribution()\n if dist is not None:\n dist.scripts.extend(scripts)\n else:\n self.scripts.extend(scripts)\n return\n\n def dict_append(self,**dict):\n for key in self.list_keys:\n a = getattr(self,key)\n a.extend(dict.get(key,[]))\n for key in self.dict_keys:\n a = getattr(self,key)\n a.update(dict.get(key,{}))\n known_keys = self.list_keys + self.dict_keys + self.extra_keys\n for key in dict.keys():\n if key not in known_keys and not hasattr(self,key):\n print 'Inheriting attribute %r from %r' \\\n % (key,dict.get('name','?'))\n setattr(self,key,dict[key])\n self.extra_keys.append(key)\n return\n\n def __str__(self):\n known_keys = self.list_keys + self.dict_keys + self.extra_keys\n s = '<'+5*'-' + '\\n'\n s += 'Configuration of '+self.name+':\\n'\n for k in known_keys:\n a = getattr(self,k,None)\n if a:\n s += '%s = %r\\n' % (k,a)\n s += 5*'-' + '>'\n return s\n\n def get_config_cmd(self):\n cmd = get_cmd('config')\n cmd.ensure_finalized()\n cmd.dump_source = 0\n cmd.noisy = 0\n old_path = os.environ.get('PATH')\n if old_path:\n path = os.pathsep.join(['.',old_path])\n os.environ['PATH'] = path\n return cmd\n\n def get_build_temp_dir(self):\n cmd = get_cmd('build')\n cmd.ensure_finalized()\n return cmd.build_temp\n\n def have_f77c(self):\n \"\"\" Check for availability of Fortran 77 compiler.\n Use it inside source generating function to ensure that\n setup distribution instance has been initialized.\n \"\"\"\n simple_fortran_subroutine = '''\n subroutine simple\n end\n '''\n config_cmd = self.get_config_cmd()\n flag = config_cmd.try_compile(simple_fortran_subroutine,lang='f77')\n return flag\n\n def have_f90c(self):\n \"\"\" Check for availability of Fortran 90 compiler.\n Use it inside source generating function to ensure that\n setup distribution instance has been initialized.\n \"\"\"\n simple_fortran_subroutine = '''\n subroutine simple\n end\n '''\n config_cmd = self.get_config_cmd()\n flag = config_cmd.try_compile(simple_fortran_subroutine,lang='f90')\n return flag\n\n def append_to(self, extlib):\n \"\"\" Append libraries, include_dirs to extension or library item.\n \"\"\"\n if is_sequence(extlib):\n lib_name, build_info = extlib\n dict_append(build_info,\n libraries=self.libraries,\n include_dirs=self.include_dirs)\n else:\n from numpy.distutils.core import Extension\n assert isinstance(extlib,Extension),`extlib`\n extlib.libraries.extend(self.libraries)\n extlib.include_dirs.extend(self.include_dirs)\n return\n\n def _get_svn_revision(self,path):\n \"\"\" Return path's SVN revision number.\n \"\"\"\n entries = njoin(path,'.svn','entries')\n revision = None\n if os.path.isfile(entries):\n f = open(entries)\n m = re.search(r'revision=\"(?P\\d+)\"',f.read())\n f.close()\n if m:\n revision = int(m.group('revision'))\n return revision\n\n def get_version(self):\n \"\"\" Try to get version string of a package.\n \"\"\"\n version = getattr(self,'version',None)\n if version is not None:\n return version\n\n # Get version from version file.\n files = ['__version__.py',\n self.name.split('.')[-1]+'_version.py',\n 'version.py',\n '__svn_version__.py']\n version_vars = ['version',\n '__version__',\n self.name.split('.')[-1]+'_version']\n for f in files:\n fn = njoin(self.local_path,f)\n if os.path.isfile(fn):\n info = (open(fn),fn,('.py','U',1))\n name = os.path.splitext(os.path.basename(fn))[0]\n n = dot_join(self.name,name)\n try:\n version_module = imp.load_module('_'.join(n.split('.')),*info)\n except ImportError,msg:\n print msg\n version_module = None\n if version_module is None:\n continue\n\n for a in version_vars:\n version = getattr(version_module,a,None)\n if version is not None:\n break\n if version is not None:\n break\n\n if version is not None:\n self.version = version\n return version\n\n # Get version as SVN revision number\n revision = self._get_svn_revision(self.local_path)\n if revision is not None:\n version = str(revision)\n self.version = version\n\n return version\n\n def make_svn_version_py(self):\n \"\"\" Generate package __svn_version__.py file from SVN revision number,\n it will be removed after python exits but will be available\n when sdist, etc commands are executed.\n\n If __svn_version__.py existed before, nothing is done.\n \"\"\"\n target = njoin(self.local_path,'__svn_version__.py')\n if os.path.isfile(target):\n return\n\n def generate_svn_version_py():\n if not os.path.isfile(target):\n revision = self._get_svn_revision(self.local_path)\n assert revision is not None,'hmm, why I am not inside SVN tree???'\n version = str(revision)\n print 'Creating %s (version=%r)' % (target,version)\n f = open(target,'w')\n f.write('version = %r\\n' % (version))\n f.close()\n\n import atexit\n def rm_file(f=target):\n try: os.remove(f); print 'removed',f\n except OSError: pass\n try: os.remove(f+'c'); print 'removed',f+'c'\n except OSError: pass\n atexit.register(rm_file)\n\n return target\n\n self.add_data_files((self.path_in_package, generate_svn_version_py()))\n return\n\n def make_config_py(self,name='__config__'):\n \"\"\" Generate package __config__.py file containing system_info\n information used during building the package.\n \"\"\"\n self.py_modules.append((self.name,name,generate_config_py))\n return\n\n def get_info(self,*names):\n \"\"\" Get resources information.\n \"\"\"\n from system_info import get_info, dict_append\n info_dict = {}\n for a in names:\n dict_append(info_dict,**get_info(a))\n return info_dict\n\ndef get_cmd(cmdname,_cache={}):\n if not _cache.has_key(cmdname):\n import distutils.core\n dist = distutils.core._setup_distribution\n if dist is None:\n from distutils.errors import DistutilsInternalError\n raise DistutilsInternalError,\\\n 'setup distribution instance not initialized'\n cmd = dist.get_command_obj(cmdname)\n _cache[cmdname] = cmd\n return _cache[cmdname]\n\ndef get_numpy_include_dirs():\n # numpy_include_dirs are set by numpy/core/setup.py, otherwise []\n include_dirs = Configuration.numpy_include_dirs[:]\n if not include_dirs:\n import numpy\n if numpy.show_config is None:\n # running from numpy_core source directory\n include_dirs.append(njoin(os.path.dirname(numpy.__file__),\n 'core','include'))\n else:\n # using installed numpy core headers\n import numpy.core as core\n include_dirs.append(njoin(os.path.dirname(core.__file__),'include'))\n # else running numpy/core/setup.py\n return include_dirs\n\n#########################\n\ndef default_config_dict(name = None, parent_name = None, local_path=None):\n \"\"\" Return a configuration dictionary for usage in\n configuration() function defined in file setup_.py.\n \"\"\"\n import warnings\n warnings.warn('Use Configuration(%s,%s,top_path=%s) instead of '\\\n 'deprecated default_config_dict(%s,%s,%s)' \\\n % (`name`,`parent_name`,`local_path`,\n `name`,`parent_name`,`local_path`,\n ))\n c = Configuration(name, parent_name, local_path)\n return c.todict()\n\n\ndef dict_append(d,**kws):\n for k,v in kws.items():\n if d.has_key(k):\n d[k].extend(v)\n else:\n d[k] = v\n\ndef appendpath(prefix,path):\n if not ('/' == os.path.sep):\n prefix = prefix.replace('/',os.path.sep)\n path = path.replace('/',os.path.sep)\n drive = ''\n if os.path.isabs(path):\n drive = os.path.splitdrive(prefix)[0]\n absprefix = os.path.splitdrive(os.path.abspath(prefix))[1]\n pathdrive,path = os.path.splitdrive(path)\n d = os.path.commonprefix([absprefix,path])\n if os.path.join(absprefix[:len(d)],absprefix[len(d):])!=absprefix \\\n or os.path.join(path[:len(d)],path[len(d):])!=path:\n # Handle invalid paths\n d = os.path.dirname(d)\n subpath = path[len(d):]\n if os.path.isabs(subpath):\n subpath = subpath[1:]\n else:\n subpath = path\n return os.path.normpath(njoin(drive + prefix, subpath))\n\n\n\n\n\ndef generate_config_py(target):\n \"\"\" Generate config.py file containing system_info information\n used during building the package.\n\n Usage:\\\n config['py_modules'].append((packagename, '__config__',generate_config_py))\n \"\"\"\n from numpy.distutils.system_info import system_info\n from distutils.dir_util import mkpath\n mkpath(os.path.dirname(target))\n f = open(target,'w')\n f.write('# This file is generated by %s\\n' % (os.path.abspath(sys.argv[0])))\n f.write('# It contains system_info results at the time of building this package.\\n')\n f.write('__all__ = [\"get_info\",\"show\"]\\n\\n')\n for k,i in system_info.saved_results.items():\n f.write('%s=%r\\n' % (k,i))\n f.write('\\ndef get_info(name): g=globals(); return g.get(name,g.get(name+\"_info\",{}))\\n')\n f.write('''\ndef show():\n for name,info_dict in globals().items():\n if name[0]==\"_\" or type(info_dict) is not type({}): continue\n print name+\":\"\n if not info_dict:\n print \" NOT AVAILABLE\"\n for k,v in info_dict.items():\n v = str(v)\n if k==\\'sources\\' and len(v)>200: v = v[:60]+\\' ...\\\\n... \\'+v[-60:]\n print \\' %s = %s\\'%(k,v)\n print\n return\n ''')\n\n f.close()\n return target\n\ndef generate_svn_version_py(extension, build_dir):\n \"\"\" Generate __svn_version__.py file containing SVN\n revision number of a module.\n\n To use, add the following codelet to setup\n configuration(..) function\n\n ext = Extension(dot_join(config['name'],'__svn_version__'),\n sources=[generate_svn_version_py])\n ext.local_path = local_path\n config['ext_modules'].append(ext)\n\n \"\"\"\n from distutils import dep_util\n local_path = extension.local_path\n target = njoin(build_dir, '__svn_version__.py')\n entries = njoin(local_path,'.svn','entries')\n if os.path.isfile(entries):\n if not dep_util.newer(entries, target):\n return target\n elif os.path.isfile(target):\n return target\n\n revision = get_svn_revision(local_path)\n f = open(target,'w')\n f.write('revision=%s\\n' % (revision))\n f.close()\n return target\n", + "methods": [ + { + "name": "allpath", + "long_name": "allpath( name )", + "filename": "misc_util.py", + "nloc": 4, + "complexity": 1, + "token_count": 24, + "parameters": [ + "name" + ], + "start_line": 18, + "end_line": 21, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 4, + "top_nesting_level": 0 + }, + { + "name": "get_path", + "long_name": "get_path( mod_name , parent_path = None )", + "filename": "misc_util.py", + "nloc": 15, + "complexity": 6, + "token_count": 132, + "parameters": [ + "mod_name", + "parent_path" + ], + "start_line": 23, + "end_line": 43, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 21, + "top_nesting_level": 0 + }, + { + "name": "njoin", + "long_name": "njoin( * path )", + "filename": "misc_util.py", + "nloc": 7, + "complexity": 4, + "token_count": 68, + "parameters": [ + "path" + ], + "start_line": 45, + "end_line": 55, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 11, + "top_nesting_level": 0 + }, + { + "name": "minrelpath", + "long_name": "minrelpath( path )", + "filename": "misc_util.py", + "nloc": 17, + "complexity": 7, + "token_count": 103, + "parameters": [ + "path" + ], + "start_line": 57, + "end_line": 75, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 19, + "top_nesting_level": 0 + }, + { + "name": "terminal_has_colors", + "long_name": "terminal_has_colors( )", + "filename": "misc_util.py", + "nloc": 18, + "complexity": 13, + "token_count": 137, + "parameters": [], + "start_line": 79, + "end_line": 104, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 26, + "top_nesting_level": 0 + }, + { + "name": "cyg2win32", + "long_name": "cyg2win32( path )", + "filename": "misc_util.py", + "nloc": 4, + "complexity": 3, + "token_count": 42, + "parameters": [ + "path" + ], + "start_line": 121, + "end_line": 124, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 4, + "top_nesting_level": 0 + }, + { + "name": "_get_f90_modules", + "long_name": "_get_f90_modules( source )", + "filename": "misc_util.py", + "nloc": 13, + "complexity": 4, + "token_count": 77, + "parameters": [ + "source" + ], + "start_line": 133, + "end_line": 149, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 17, + "top_nesting_level": 0 + }, + { + "name": "is_string", + "long_name": "is_string( s )", + "filename": "misc_util.py", + "nloc": 2, + "complexity": 1, + "token_count": 12, + "parameters": [ + "s" + ], + "start_line": 151, + "end_line": 152, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 2, + "top_nesting_level": 0 + }, + { + "name": "all_strings", + "long_name": "all_strings( lst )", + "filename": "misc_util.py", + "nloc": 5, + "complexity": 3, + "token_count": 22, + "parameters": [ + "lst" + ], + "start_line": 154, + "end_line": 159, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 6, + "top_nesting_level": 0 + }, + { + "name": "is_sequence", + "long_name": "is_sequence( seq )", + "filename": "misc_util.py", + "nloc": 8, + "complexity": 3, + "token_count": 25, + "parameters": [ + "seq" + ], + "start_line": 161, + "end_line": 168, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 8, + "top_nesting_level": 0 + }, + { + "name": "has_f_sources", + "long_name": "has_f_sources( sources )", + "filename": "misc_util.py", + "nloc": 5, + "complexity": 3, + "token_count": 21, + "parameters": [ + "sources" + ], + "start_line": 170, + "end_line": 175, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 6, + "top_nesting_level": 0 + }, + { + "name": "has_cxx_sources", + "long_name": "has_cxx_sources( sources )", + "filename": "misc_util.py", + "nloc": 5, + "complexity": 3, + "token_count": 21, + "parameters": [ + "sources" + ], + "start_line": 177, + "end_line": 182, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 6, + "top_nesting_level": 0 + }, + { + "name": "filter_sources", + "long_name": "filter_sources( sources )", + "filename": "misc_util.py", + "nloc": 17, + "complexity": 5, + "token_count": 84, + "parameters": [ + "sources" + ], + "start_line": 184, + "end_line": 204, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 21, + "top_nesting_level": 0 + }, + { + "name": "_get_headers", + "long_name": "_get_headers( directory_list )", + "filename": "misc_util.py", + "nloc": 6, + "complexity": 2, + "token_count": 39, + "parameters": [ + "directory_list" + ], + "start_line": 207, + "end_line": 213, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 7, + "top_nesting_level": 0 + }, + { + "name": "_get_directories", + "long_name": "_get_directories( list_of_sources )", + "filename": "misc_util.py", + "nloc": 7, + "complexity": 4, + "token_count": 51, + "parameters": [ + "list_of_sources" + ], + "start_line": 215, + "end_line": 222, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 8, + "top_nesting_level": 0 + }, + { + "name": "get_dependencies", + "long_name": "get_dependencies( sources )", + "filename": "misc_util.py", + "nloc": 2, + "complexity": 1, + "token_count": 13, + "parameters": [ + "sources" + ], + "start_line": 224, + "end_line": 226, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 3, + "top_nesting_level": 0 + }, + { + "name": "is_local_src_dir", + "long_name": "is_local_src_dir( directory )", + "filename": "misc_util.py", + "nloc": 12, + "complexity": 6, + "token_count": 107, + "parameters": [ + "directory" + ], + "start_line": 228, + "end_line": 241, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 14, + "top_nesting_level": 0 + }, + { + "name": "_gsf_visit_func", + "long_name": "_gsf_visit_func( filenames , dirname , names )", + "filename": "misc_util.py", + "nloc": 13, + "complexity": 7, + "token_count": 103, + "parameters": [ + "filenames", + "dirname", + "names" + ], + "start_line": 243, + "end_line": 255, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 13, + "top_nesting_level": 0 + }, + { + "name": "get_ext_source_files", + "long_name": "get_ext_source_files( ext )", + "filename": "misc_util.py", + "nloc": 11, + "complexity": 4, + "token_count": 77, + "parameters": [ + "ext" + ], + "start_line": 257, + "end_line": 268, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 12, + "top_nesting_level": 0 + }, + { + "name": "get_script_files", + "long_name": "get_script_files( scripts )", + "filename": "misc_util.py", + "nloc": 3, + "complexity": 1, + "token_count": 15, + "parameters": [ + "scripts" + ], + "start_line": 270, + "end_line": 272, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 3, + "top_nesting_level": 0 + }, + { + "name": "get_lib_source_files", + "long_name": "get_lib_source_files( lib )", + "filename": "misc_util.py", + "nloc": 13, + "complexity": 4, + "token_count": 101, + "parameters": [ + "lib" + ], + "start_line": 274, + "end_line": 286, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 13, + "top_nesting_level": 0 + }, + { + "name": "get_data_files", + "long_name": "get_data_files( data )", + "filename": "misc_util.py", + "nloc": 18, + "complexity": 7, + "token_count": 94, + "parameters": [ + "data" + ], + "start_line": 288, + "end_line": 305, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 18, + "top_nesting_level": 0 + }, + { + "name": "dot_join", + "long_name": "dot_join( * args )", + "filename": "misc_util.py", + "nloc": 2, + "complexity": 1, + "token_count": 18, + "parameters": [ + "args" + ], + "start_line": 307, + "end_line": 308, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 2, + "top_nesting_level": 0 + }, + { + "name": "get_frame", + "long_name": "get_frame( level = 0 )", + "filename": "misc_util.py", + "nloc": 8, + "complexity": 3, + "token_count": 50, + "parameters": [ + "level" + ], + "start_line": 310, + "end_line": 317, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 8, + "top_nesting_level": 0 + }, + { + "name": "command_line_ok", + "long_name": "command_line_ok( _cache = [ ] )", + "filename": "misc_util.py", + "nloc": 14, + "complexity": 9, + "token_count": 98, + "parameters": [ + "_cache" + ], + "start_line": 321, + "end_line": 337, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 17, + "top_nesting_level": 0 + }, + { + "name": "__init__", + "long_name": "__init__( self , package_name = None , parent_name = None , top_path = None , package_path = None , ** attrs )", + "filename": "misc_util.py", + "nloc": 44, + "complexity": 12, + "token_count": 365, + "parameters": [ + "self", + "package_name", + "parent_name", + "top_path", + "package_path", + "attrs" + ], + "start_line": 347, + "end_line": 411, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 65, + "top_nesting_level": 1 + }, + { + "name": "todict", + "long_name": "todict( self )", + "filename": "misc_util.py", + "nloc": 9, + "complexity": 4, + "token_count": 57, + "parameters": [ + "self" + ], + "start_line": 413, + "end_line": 424, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 12, + "top_nesting_level": 1 + }, + { + "name": "info", + "long_name": "info( self , message )", + "filename": "misc_util.py", + "nloc": 2, + "complexity": 1, + "token_count": 9, + "parameters": [ + "self", + "message" + ], + "start_line": 426, + "end_line": 427, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 2, + "top_nesting_level": 1 + }, + { + "name": "warn", + "long_name": "warn( self , message )", + "filename": "misc_util.py", + "nloc": 2, + "complexity": 1, + "token_count": 17, + "parameters": [ + "self", + "message" + ], + "start_line": 429, + "end_line": 430, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 2, + "top_nesting_level": 1 + }, + { + "name": "__dict__", + "long_name": "__dict__( self )", + "filename": "misc_util.py", + "nloc": 2, + "complexity": 1, + "token_count": 11, + "parameters": [ + "self" + ], + "start_line": 432, + "end_line": 433, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 2, + "top_nesting_level": 1 + }, + { + "name": "get_distribution", + "long_name": "get_distribution( self )", + "filename": "misc_util.py", + "nloc": 4, + "complexity": 1, + "token_count": 18, + "parameters": [ + "self" + ], + "start_line": 435, + "end_line": 438, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 4, + "top_nesting_level": 1 + }, + { + "name": "get_subpackage", + "long_name": "get_subpackage( self , subpackage_name , subpackage_path = None )", + "filename": "misc_util.py", + "nloc": 52, + "complexity": 13, + "token_count": 446, + "parameters": [ + "self", + "subpackage_name", + "subpackage_path" + ], + "start_line": 440, + "end_line": 498, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 59, + "top_nesting_level": 1 + }, + { + "name": "add_subpackage", + "long_name": "add_subpackage( self , subpackage_name , subpackage_path = None )", + "filename": "misc_util.py", + "nloc": 20, + "complexity": 6, + "token_count": 127, + "parameters": [ + "self", + "subpackage_name", + "subpackage_path" + ], + "start_line": 500, + "end_line": 522, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 23, + "top_nesting_level": 1 + }, + { + "name": "add_data_dir", + "long_name": "add_data_dir( self , data_path )", + "filename": "misc_util.py", + "nloc": 27, + "complexity": 9, + "token_count": 196, + "parameters": [ + "self", + "data_path" + ], + "start_line": 524, + "end_line": 558, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 35, + "top_nesting_level": 1 + }, + { + "name": "add_data_files", + "long_name": "add_data_files( self , * files )", + "filename": "misc_util.py", + "nloc": 49, + "complexity": 17, + "token_count": 392, + "parameters": [ + "self", + "files" + ], + "start_line": 560, + "end_line": 620, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 61, + "top_nesting_level": 1 + }, + { + "name": "add_include_dirs", + "long_name": "add_include_dirs( self , * paths )", + "filename": "misc_util.py", + "nloc": 8, + "complexity": 2, + "token_count": 49, + "parameters": [ + "self", + "paths" + ], + "start_line": 624, + "end_line": 633, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 10, + "top_nesting_level": 1 + }, + { + "name": "add_headers", + "long_name": "add_headers( self , * files )", + "filename": "misc_util.py", + "nloc": 15, + "complexity": 8, + "token_count": 136, + "parameters": [ + "self", + "files" + ], + "start_line": 635, + "end_line": 655, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 21, + "top_nesting_level": 1 + }, + { + "name": "_fix_paths", + "long_name": "_fix_paths( self , paths , include_non_existing = True )", + "filename": "misc_util.py", + "nloc": 30, + "complexity": 12, + "token_count": 208, + "parameters": [ + "self", + "paths", + "include_non_existing" + ], + "start_line": 657, + "end_line": 686, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 30, + "top_nesting_level": 1 + }, + { + "name": "paths", + "long_name": "paths( self , * paths , ** kws )", + "filename": "misc_util.py", + "nloc": 4, + "complexity": 1, + "token_count": 33, + "parameters": [ + "self", + "paths", + "kws" + ], + "start_line": 688, + "end_line": 693, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 6, + "top_nesting_level": 1 + }, + { + "name": "add_extension", + "long_name": "add_extension( self , name , sources , ** kw )", + "filename": "misc_util.py", + "nloc": 45, + "complexity": 14, + "token_count": 361, + "parameters": [ + "self", + "name", + "sources", + "kw" + ], + "start_line": 695, + "end_line": 757, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 63, + "top_nesting_level": 1 + }, + { + "name": "add_library", + "long_name": "add_library( self , name , sources , ** build_info )", + "filename": "misc_util.py", + "nloc": 15, + "complexity": 4, + "token_count": 106, + "parameters": [ + "self", + "name", + "sources", + "build_info" + ], + "start_line": 759, + "end_line": 784, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 26, + "top_nesting_level": 1 + }, + { + "name": "add_scripts", + "long_name": "add_scripts( self , * files )", + "filename": "misc_util.py", + "nloc": 8, + "complexity": 2, + "token_count": 49, + "parameters": [ + "self", + "files" + ], + "start_line": 786, + "end_line": 795, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 10, + "top_nesting_level": 1 + }, + { + "name": "dict_append", + "long_name": "dict_append( self , ** dict )", + "filename": "misc_util.py", + "nloc": 16, + "complexity": 7, + "token_count": 150, + "parameters": [ + "self", + "dict" + ], + "start_line": 797, + "end_line": 812, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 16, + "top_nesting_level": 1 + }, + { + "name": "__str__", + "long_name": "__str__( self )", + "filename": "misc_util.py", + "nloc": 10, + "complexity": 3, + "token_count": 72, + "parameters": [ + "self" + ], + "start_line": 814, + "end_line": 823, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 10, + "top_nesting_level": 1 + }, + { + "name": "get_config_cmd", + "long_name": "get_config_cmd( self )", + "filename": "misc_util.py", + "nloc": 10, + "complexity": 2, + "token_count": 63, + "parameters": [ + "self" + ], + "start_line": 825, + "end_line": 834, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 10, + "top_nesting_level": 1 + }, + { + "name": "get_build_temp_dir", + "long_name": "get_build_temp_dir( self )", + "filename": "misc_util.py", + "nloc": 4, + "complexity": 1, + "token_count": 20, + "parameters": [ + "self" + ], + "start_line": 836, + "end_line": 839, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 4, + "top_nesting_level": 1 + }, + { + "name": "have_f77c", + "long_name": "have_f77c( self )", + "filename": "misc_util.py", + "nloc": 8, + "complexity": 1, + "token_count": 30, + "parameters": [ + "self" + ], + "start_line": 841, + "end_line": 852, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 12, + "top_nesting_level": 1 + }, + { + "name": "have_f90c", + "long_name": "have_f90c( self )", + "filename": "misc_util.py", + "nloc": 8, + "complexity": 1, + "token_count": 30, + "parameters": [ + "self" + ], + "start_line": 854, + "end_line": 865, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 12, + "top_nesting_level": 1 + }, + { + "name": "append_to", + "long_name": "append_to( self , extlib )", + "filename": "misc_util.py", + "nloc": 12, + "complexity": 2, + "token_count": 77, + "parameters": [ + "self", + "extlib" + ], + "start_line": 867, + "end_line": 880, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 14, + "top_nesting_level": 1 + }, + { + "name": "_get_svn_revision", + "long_name": "_get_svn_revision( self , path )", + "filename": "misc_util.py", + "nloc": 10, + "complexity": 3, + "token_count": 73, + "parameters": [ + "self", + "path" + ], + "start_line": 882, + "end_line": 893, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 12, + "top_nesting_level": 1 + }, + { + "name": "get_version", + "long_name": "get_version( self )", + "filename": "misc_util.py", + "nloc": 38, + "complexity": 11, + "token_count": 253, + "parameters": [ + "self" + ], + "start_line": 895, + "end_line": 941, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 47, + "top_nesting_level": 1 + }, + { + "name": "make_svn_version_py.make_svn_version_py.generate_svn_version_py.rm_file", + "long_name": "make_svn_version_py.make_svn_version_py.generate_svn_version_py.rm_file( f = target )", + "filename": "misc_util.py", + "nloc": 5, + "complexity": 3, + "token_count": 45, + "parameters": [ + "f" + ], + "start_line": 965, + "end_line": 969, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 5, + "top_nesting_level": 3 + }, + { + "name": "make_svn_version_py.generate_svn_version_py", + "long_name": "make_svn_version_py.generate_svn_version_py( )", + "filename": "misc_util.py", + "nloc": 13, + "complexity": 2, + "token_count": 81, + "parameters": [], + "start_line": 954, + "end_line": 972, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 19, + "top_nesting_level": 2 + }, + { + "name": "make_svn_version_py", + "long_name": "make_svn_version_py( self )", + "filename": "misc_util.py", + "nloc": 7, + "complexity": 2, + "token_count": 44, + "parameters": [ + "self" + ], + "start_line": 943, + "end_line": 975, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 33, + "top_nesting_level": 1 + }, + { + "name": "make_config_py", + "long_name": "make_config_py( self , name = '__config__' )", + "filename": "misc_util.py", + "nloc": 3, + "complexity": 1, + "token_count": 27, + "parameters": [ + "self", + "name" + ], + "start_line": 977, + "end_line": 982, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 6, + "top_nesting_level": 1 + }, + { + "name": "get_info", + "long_name": "get_info( self , * names )", + "filename": "misc_util.py", + "nloc": 6, + "complexity": 2, + "token_count": 36, + "parameters": [ + "self", + "names" + ], + "start_line": 984, + "end_line": 991, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 8, + "top_nesting_level": 1 + }, + { + "name": "get_cmd", + "long_name": "get_cmd( cmdname , _cache = { } )", + "filename": "misc_util.py", + "nloc": 11, + "complexity": 3, + "token_count": 65, + "parameters": [ + "cmdname", + "_cache" + ], + "start_line": 1008, + "end_line": 1018, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 11, + "top_nesting_level": 0 + }, + { + "name": "get_numpy_include_dirs", + "long_name": "get_numpy_include_dirs( )", + "filename": "misc_util.py", + "nloc": 11, + "complexity": 3, + "token_count": 77, + "parameters": [], + "start_line": 1020, + "end_line": 1034, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 15, + "top_nesting_level": 0 + }, + { + "name": "default_config_dict", + "long_name": "default_config_dict( name = None , parent_name = None , local_path = None )", + "filename": "misc_util.py", + "nloc": 9, + "complexity": 1, + "token_count": 70, + "parameters": [ + "name", + "parent_name", + "local_path" + ], + "start_line": 1038, + "end_line": 1049, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 12, + "top_nesting_level": 0 + }, + { + "name": "dict_append", + "long_name": "dict_append( d , ** kws )", + "filename": "misc_util.py", + "nloc": 6, + "complexity": 3, + "token_count": 44, + "parameters": [ + "d", + "kws" + ], + "start_line": 1052, + "end_line": 1057, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 6, + "top_nesting_level": 0 + }, + { + "name": "appendpath", + "long_name": "appendpath( prefix , path )", + "filename": "misc_util.py", + "nloc": 19, + "complexity": 6, + "token_count": 233, + "parameters": [ + "prefix", + "path" + ], + "start_line": 1059, + "end_line": 1078, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 20, + "top_nesting_level": 0 + }, + { + "name": "generate_config_py", + "long_name": "generate_config_py( target )", + "filename": "misc_util.py", + "nloc": 27, + "complexity": 2, + "token_count": 117, + "parameters": [ + "target" + ], + "start_line": 1084, + "end_line": 1117, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 34, + "top_nesting_level": 0 + }, + { + "name": "generate_svn_version_py", + "long_name": "generate_svn_version_py( extension , build_dir )", + "filename": "misc_util.py", + "nloc": 15, + "complexity": 4, + "token_count": 101, + "parameters": [ + "extension", + "build_dir" + ], + "start_line": 1119, + "end_line": 1146, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 28, + "top_nesting_level": 0 + } + ], + "methods_before": [ + { + "name": "allpath", + "long_name": "allpath( name )", + "filename": "misc_util.py", + "nloc": 4, + "complexity": 1, + "token_count": 24, + "parameters": [ + "name" + ], + "start_line": 18, + "end_line": 21, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 4, + "top_nesting_level": 0 + }, + { + "name": "get_path", + "long_name": "get_path( mod_name , parent_path = None )", + "filename": "misc_util.py", + "nloc": 15, + "complexity": 6, + "token_count": 132, + "parameters": [ + "mod_name", + "parent_path" + ], + "start_line": 23, + "end_line": 43, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 21, + "top_nesting_level": 0 + }, + { + "name": "njoin", + "long_name": "njoin( * path )", + "filename": "misc_util.py", + "nloc": 7, + "complexity": 4, + "token_count": 68, + "parameters": [ + "path" + ], + "start_line": 45, + "end_line": 55, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 11, + "top_nesting_level": 0 + }, + { + "name": "minrelpath", + "long_name": "minrelpath( path )", + "filename": "misc_util.py", + "nloc": 17, + "complexity": 7, + "token_count": 103, + "parameters": [ + "path" + ], + "start_line": 57, + "end_line": 75, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 19, + "top_nesting_level": 0 + }, + { + "name": "terminal_has_colors", + "long_name": "terminal_has_colors( )", + "filename": "misc_util.py", + "nloc": 18, + "complexity": 13, + "token_count": 137, + "parameters": [], + "start_line": 79, + "end_line": 104, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 26, + "top_nesting_level": 0 + }, + { + "name": "cyg2win32", + "long_name": "cyg2win32( path )", + "filename": "misc_util.py", + "nloc": 4, + "complexity": 3, + "token_count": 42, + "parameters": [ + "path" + ], + "start_line": 121, + "end_line": 124, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 4, + "top_nesting_level": 0 + }, + { + "name": "_get_f90_modules", + "long_name": "_get_f90_modules( source )", + "filename": "misc_util.py", + "nloc": 13, + "complexity": 4, + "token_count": 77, + "parameters": [ + "source" + ], + "start_line": 133, + "end_line": 149, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 17, + "top_nesting_level": 0 + }, + { + "name": "is_string", + "long_name": "is_string( s )", + "filename": "misc_util.py", + "nloc": 2, + "complexity": 1, + "token_count": 12, + "parameters": [ + "s" + ], + "start_line": 151, + "end_line": 152, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 2, + "top_nesting_level": 0 + }, + { + "name": "all_strings", + "long_name": "all_strings( lst )", + "filename": "misc_util.py", + "nloc": 5, + "complexity": 3, + "token_count": 22, + "parameters": [ + "lst" + ], + "start_line": 154, + "end_line": 159, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 6, + "top_nesting_level": 0 + }, + { + "name": "is_sequence", + "long_name": "is_sequence( seq )", + "filename": "misc_util.py", + "nloc": 8, + "complexity": 3, + "token_count": 25, + "parameters": [ + "seq" + ], + "start_line": 161, + "end_line": 168, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 8, + "top_nesting_level": 0 + }, + { + "name": "has_f_sources", + "long_name": "has_f_sources( sources )", + "filename": "misc_util.py", + "nloc": 5, + "complexity": 3, + "token_count": 21, + "parameters": [ + "sources" + ], + "start_line": 170, + "end_line": 175, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 6, + "top_nesting_level": 0 + }, + { + "name": "has_cxx_sources", + "long_name": "has_cxx_sources( sources )", + "filename": "misc_util.py", + "nloc": 5, + "complexity": 3, + "token_count": 21, + "parameters": [ + "sources" + ], + "start_line": 177, + "end_line": 182, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 6, + "top_nesting_level": 0 + }, + { + "name": "filter_sources", + "long_name": "filter_sources( sources )", + "filename": "misc_util.py", + "nloc": 17, + "complexity": 5, + "token_count": 84, + "parameters": [ + "sources" + ], + "start_line": 184, + "end_line": 204, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 21, + "top_nesting_level": 0 + }, + { + "name": "_get_headers", + "long_name": "_get_headers( directory_list )", + "filename": "misc_util.py", + "nloc": 6, + "complexity": 2, + "token_count": 39, + "parameters": [ + "directory_list" + ], + "start_line": 207, + "end_line": 213, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 7, + "top_nesting_level": 0 + }, + { + "name": "_get_directories", + "long_name": "_get_directories( list_of_sources )", + "filename": "misc_util.py", + "nloc": 7, + "complexity": 4, + "token_count": 51, + "parameters": [ + "list_of_sources" + ], + "start_line": 215, + "end_line": 222, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 8, + "top_nesting_level": 0 + }, + { + "name": "get_dependencies", + "long_name": "get_dependencies( sources )", + "filename": "misc_util.py", + "nloc": 2, + "complexity": 1, + "token_count": 13, + "parameters": [ + "sources" + ], + "start_line": 224, + "end_line": 226, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 3, + "top_nesting_level": 0 + }, + { + "name": "is_local_src_dir", + "long_name": "is_local_src_dir( directory )", + "filename": "misc_util.py", + "nloc": 12, + "complexity": 6, + "token_count": 107, + "parameters": [ + "directory" + ], + "start_line": 228, + "end_line": 241, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 14, + "top_nesting_level": 0 + }, + { + "name": "_gsf_visit_func", + "long_name": "_gsf_visit_func( filenames , dirname , names )", + "filename": "misc_util.py", + "nloc": 13, + "complexity": 7, + "token_count": 103, + "parameters": [ + "filenames", + "dirname", + "names" + ], + "start_line": 243, + "end_line": 255, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 13, + "top_nesting_level": 0 + }, + { + "name": "get_ext_source_files", + "long_name": "get_ext_source_files( ext )", + "filename": "misc_util.py", + "nloc": 11, + "complexity": 4, + "token_count": 77, + "parameters": [ + "ext" + ], + "start_line": 257, + "end_line": 268, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 12, + "top_nesting_level": 0 + }, + { + "name": "get_script_files", + "long_name": "get_script_files( scripts )", + "filename": "misc_util.py", + "nloc": 3, + "complexity": 1, + "token_count": 15, + "parameters": [ + "scripts" + ], + "start_line": 270, + "end_line": 272, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 3, + "top_nesting_level": 0 + }, + { + "name": "get_lib_source_files", + "long_name": "get_lib_source_files( lib )", + "filename": "misc_util.py", + "nloc": 13, + "complexity": 4, + "token_count": 101, + "parameters": [ + "lib" + ], + "start_line": 274, + "end_line": 286, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 13, + "top_nesting_level": 0 + }, + { + "name": "get_data_files", + "long_name": "get_data_files( data )", + "filename": "misc_util.py", + "nloc": 18, + "complexity": 7, + "token_count": 94, + "parameters": [ + "data" + ], + "start_line": 288, + "end_line": 305, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 18, + "top_nesting_level": 0 + }, + { + "name": "dot_join", + "long_name": "dot_join( * args )", + "filename": "misc_util.py", + "nloc": 2, + "complexity": 1, + "token_count": 18, + "parameters": [ + "args" + ], + "start_line": 307, + "end_line": 308, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 2, + "top_nesting_level": 0 + }, + { + "name": "get_frame", + "long_name": "get_frame( level = 0 )", + "filename": "misc_util.py", + "nloc": 8, + "complexity": 3, + "token_count": 50, + "parameters": [ + "level" + ], + "start_line": 310, + "end_line": 317, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 8, + "top_nesting_level": 0 + }, + { + "name": "__init__", + "long_name": "__init__( self , package_name = None , parent_name = None , top_path = None , package_path = None , ** attrs )", + "filename": "misc_util.py", + "nloc": 44, + "complexity": 12, + "token_count": 365, + "parameters": [ + "self", + "package_name", + "parent_name", + "top_path", + "package_path", + "attrs" + ], + "start_line": 329, + "end_line": 393, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 65, + "top_nesting_level": 1 + }, + { + "name": "todict", + "long_name": "todict( self )", + "filename": "misc_util.py", + "nloc": 9, + "complexity": 4, + "token_count": 57, + "parameters": [ + "self" + ], + "start_line": 395, + "end_line": 406, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 12, + "top_nesting_level": 1 + }, + { + "name": "info", + "long_name": "info( self , message )", + "filename": "misc_util.py", + "nloc": 2, + "complexity": 1, + "token_count": 9, + "parameters": [ + "self", + "message" + ], + "start_line": 408, + "end_line": 409, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 2, + "top_nesting_level": 1 + }, + { + "name": "warn", + "long_name": "warn( self , message )", + "filename": "misc_util.py", + "nloc": 2, + "complexity": 1, + "token_count": 11, + "parameters": [ + "self", + "message" + ], + "start_line": 411, + "end_line": 412, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 2, + "top_nesting_level": 1 + }, + { + "name": "__dict__", + "long_name": "__dict__( self )", + "filename": "misc_util.py", + "nloc": 2, + "complexity": 1, + "token_count": 11, + "parameters": [ + "self" + ], + "start_line": 414, + "end_line": 415, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 2, + "top_nesting_level": 1 + }, + { + "name": "get_distribution", + "long_name": "get_distribution( self )", + "filename": "misc_util.py", + "nloc": 4, + "complexity": 1, + "token_count": 18, + "parameters": [ + "self" + ], + "start_line": 417, + "end_line": 420, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 4, + "top_nesting_level": 1 + }, + { + "name": "get_subpackage", + "long_name": "get_subpackage( self , subpackage_name , subpackage_path = None )", + "filename": "misc_util.py", + "nloc": 52, + "complexity": 13, + "token_count": 446, + "parameters": [ + "self", + "subpackage_name", + "subpackage_path" + ], + "start_line": 422, + "end_line": 480, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 59, + "top_nesting_level": 1 + }, + { + "name": "add_subpackage", + "long_name": "add_subpackage( self , subpackage_name , subpackage_path = None )", + "filename": "misc_util.py", + "nloc": 20, + "complexity": 6, + "token_count": 127, + "parameters": [ + "self", + "subpackage_name", + "subpackage_path" + ], + "start_line": 482, + "end_line": 504, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 23, + "top_nesting_level": 1 + }, + { + "name": "add_data_dir", + "long_name": "add_data_dir( self , data_path )", + "filename": "misc_util.py", + "nloc": 27, + "complexity": 9, + "token_count": 196, + "parameters": [ + "self", + "data_path" + ], + "start_line": 506, + "end_line": 540, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 35, + "top_nesting_level": 1 + }, + { + "name": "add_data_files", + "long_name": "add_data_files( self , * files )", + "filename": "misc_util.py", + "nloc": 49, + "complexity": 17, + "token_count": 392, + "parameters": [ + "self", + "files" + ], + "start_line": 542, + "end_line": 602, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 61, + "top_nesting_level": 1 + }, + { + "name": "add_include_dirs", + "long_name": "add_include_dirs( self , * paths )", + "filename": "misc_util.py", + "nloc": 8, + "complexity": 2, + "token_count": 49, + "parameters": [ + "self", + "paths" + ], + "start_line": 606, + "end_line": 615, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 10, + "top_nesting_level": 1 + }, + { + "name": "add_headers", + "long_name": "add_headers( self , * files )", + "filename": "misc_util.py", + "nloc": 15, + "complexity": 8, + "token_count": 136, + "parameters": [ + "self", + "files" + ], + "start_line": 617, + "end_line": 637, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 21, + "top_nesting_level": 1 + }, + { + "name": "_fix_paths", + "long_name": "_fix_paths( self , paths , include_non_existing = True )", + "filename": "misc_util.py", + "nloc": 30, + "complexity": 12, + "token_count": 208, + "parameters": [ + "self", + "paths", + "include_non_existing" + ], + "start_line": 639, + "end_line": 668, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 30, + "top_nesting_level": 1 + }, + { + "name": "paths", + "long_name": "paths( self , * paths , ** kws )", + "filename": "misc_util.py", + "nloc": 4, + "complexity": 1, + "token_count": 33, + "parameters": [ + "self", + "paths", + "kws" + ], + "start_line": 670, + "end_line": 675, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 6, + "top_nesting_level": 1 + }, + { + "name": "add_extension", + "long_name": "add_extension( self , name , sources , ** kw )", + "filename": "misc_util.py", + "nloc": 45, + "complexity": 14, + "token_count": 361, + "parameters": [ + "self", + "name", + "sources", + "kw" + ], + "start_line": 677, + "end_line": 739, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 63, + "top_nesting_level": 1 + }, + { + "name": "add_library", + "long_name": "add_library( self , name , sources , ** build_info )", + "filename": "misc_util.py", + "nloc": 15, + "complexity": 4, + "token_count": 106, + "parameters": [ + "self", + "name", + "sources", + "build_info" + ], + "start_line": 741, + "end_line": 766, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 26, + "top_nesting_level": 1 + }, + { + "name": "add_scripts", + "long_name": "add_scripts( self , * files )", + "filename": "misc_util.py", + "nloc": 8, + "complexity": 2, + "token_count": 49, + "parameters": [ + "self", + "files" + ], + "start_line": 768, + "end_line": 777, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 10, + "top_nesting_level": 1 + }, + { + "name": "dict_append", + "long_name": "dict_append( self , ** dict )", + "filename": "misc_util.py", + "nloc": 15, + "complexity": 6, + "token_count": 138, + "parameters": [ + "self", + "dict" + ], + "start_line": 779, + "end_line": 793, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 15, + "top_nesting_level": 1 + }, + { + "name": "__str__", + "long_name": "__str__( self )", + "filename": "misc_util.py", + "nloc": 10, + "complexity": 3, + "token_count": 72, + "parameters": [ + "self" + ], + "start_line": 795, + "end_line": 804, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 10, + "top_nesting_level": 1 + }, + { + "name": "get_config_cmd", + "long_name": "get_config_cmd( self )", + "filename": "misc_util.py", + "nloc": 10, + "complexity": 2, + "token_count": 63, + "parameters": [ + "self" + ], + "start_line": 806, + "end_line": 815, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 10, + "top_nesting_level": 1 + }, + { + "name": "get_build_temp_dir", + "long_name": "get_build_temp_dir( self )", + "filename": "misc_util.py", + "nloc": 4, + "complexity": 1, + "token_count": 20, + "parameters": [ + "self" + ], + "start_line": 817, + "end_line": 820, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 4, + "top_nesting_level": 1 + }, + { + "name": "have_f77c", + "long_name": "have_f77c( self )", + "filename": "misc_util.py", + "nloc": 8, + "complexity": 1, + "token_count": 30, + "parameters": [ + "self" + ], + "start_line": 822, + "end_line": 833, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 12, + "top_nesting_level": 1 + }, + { + "name": "have_f90c", + "long_name": "have_f90c( self )", + "filename": "misc_util.py", + "nloc": 8, + "complexity": 1, + "token_count": 30, + "parameters": [ + "self" + ], + "start_line": 835, + "end_line": 846, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 12, + "top_nesting_level": 1 + }, + { + "name": "append_to", + "long_name": "append_to( self , extlib )", + "filename": "misc_util.py", + "nloc": 12, + "complexity": 2, + "token_count": 77, + "parameters": [ + "self", + "extlib" + ], + "start_line": 848, + "end_line": 861, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 14, + "top_nesting_level": 1 + }, + { + "name": "_get_svn_revision", + "long_name": "_get_svn_revision( self , path )", + "filename": "misc_util.py", + "nloc": 10, + "complexity": 3, + "token_count": 73, + "parameters": [ + "self", + "path" + ], + "start_line": 863, + "end_line": 874, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 12, + "top_nesting_level": 1 + }, + { + "name": "get_version", + "long_name": "get_version( self )", + "filename": "misc_util.py", + "nloc": 38, + "complexity": 11, + "token_count": 253, + "parameters": [ + "self" + ], + "start_line": 876, + "end_line": 922, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 47, + "top_nesting_level": 1 + }, + { + "name": "make_svn_version_py.make_svn_version_py.generate_svn_version_py.rm_file", + "long_name": "make_svn_version_py.make_svn_version_py.generate_svn_version_py.rm_file( f = target )", + "filename": "misc_util.py", + "nloc": 5, + "complexity": 3, + "token_count": 45, + "parameters": [ + "f" + ], + "start_line": 946, + "end_line": 950, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 5, + "top_nesting_level": 3 + }, + { + "name": "make_svn_version_py.generate_svn_version_py", + "long_name": "make_svn_version_py.generate_svn_version_py( )", + "filename": "misc_util.py", + "nloc": 13, + "complexity": 2, + "token_count": 81, + "parameters": [], + "start_line": 935, + "end_line": 953, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 19, + "top_nesting_level": 2 + }, + { + "name": "make_svn_version_py", + "long_name": "make_svn_version_py( self )", + "filename": "misc_util.py", + "nloc": 7, + "complexity": 2, + "token_count": 44, + "parameters": [ + "self" + ], + "start_line": 924, + "end_line": 956, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 33, + "top_nesting_level": 1 + }, + { + "name": "make_config_py", + "long_name": "make_config_py( self , name = '__config__' )", + "filename": "misc_util.py", + "nloc": 3, + "complexity": 1, + "token_count": 27, + "parameters": [ + "self", + "name" + ], + "start_line": 958, + "end_line": 963, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 6, + "top_nesting_level": 1 + }, + { + "name": "get_info", + "long_name": "get_info( self , * names )", + "filename": "misc_util.py", + "nloc": 6, + "complexity": 2, + "token_count": 36, + "parameters": [ + "self", + "names" + ], + "start_line": 965, + "end_line": 972, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 8, + "top_nesting_level": 1 + }, + { + "name": "get_cmd", + "long_name": "get_cmd( cmdname , _cache = { } )", + "filename": "misc_util.py", + "nloc": 11, + "complexity": 3, + "token_count": 65, + "parameters": [ + "cmdname", + "_cache" + ], + "start_line": 974, + "end_line": 984, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 11, + "top_nesting_level": 0 + }, + { + "name": "get_numpy_include_dirs", + "long_name": "get_numpy_include_dirs( )", + "filename": "misc_util.py", + "nloc": 11, + "complexity": 3, + "token_count": 77, + "parameters": [], + "start_line": 986, + "end_line": 1000, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 15, + "top_nesting_level": 0 + }, + { + "name": "default_config_dict", + "long_name": "default_config_dict( name = None , parent_name = None , local_path = None )", + "filename": "misc_util.py", + "nloc": 9, + "complexity": 1, + "token_count": 70, + "parameters": [ + "name", + "parent_name", + "local_path" + ], + "start_line": 1004, + "end_line": 1015, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 12, + "top_nesting_level": 0 + }, + { + "name": "dict_append", + "long_name": "dict_append( d , ** kws )", + "filename": "misc_util.py", + "nloc": 6, + "complexity": 3, + "token_count": 44, + "parameters": [ + "d", + "kws" + ], + "start_line": 1018, + "end_line": 1023, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 6, + "top_nesting_level": 0 + }, + { + "name": "appendpath", + "long_name": "appendpath( prefix , path )", + "filename": "misc_util.py", + "nloc": 19, + "complexity": 6, + "token_count": 233, + "parameters": [ + "prefix", + "path" + ], + "start_line": 1025, + "end_line": 1044, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 20, + "top_nesting_level": 0 + }, + { + "name": "generate_config_py", + "long_name": "generate_config_py( target )", + "filename": "misc_util.py", + "nloc": 27, + "complexity": 2, + "token_count": 117, + "parameters": [ + "target" + ], + "start_line": 1050, + "end_line": 1083, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 34, + "top_nesting_level": 0 + }, + { + "name": "generate_svn_version_py", + "long_name": "generate_svn_version_py( extension , build_dir )", + "filename": "misc_util.py", + "nloc": 15, + "complexity": 4, + "token_count": 101, + "parameters": [ + "extension", + "build_dir" + ], + "start_line": 1085, + "end_line": 1112, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 28, + "top_nesting_level": 0 + } + ], + "changed_methods": [ + { + "name": "warn", + "long_name": "warn( self , message )", + "filename": "misc_util.py", + "nloc": 2, + "complexity": 1, + "token_count": 17, + "parameters": [ + "self", + "message" + ], + "start_line": 429, + "end_line": 430, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 2, + "top_nesting_level": 1 + }, + { + "name": "command_line_ok", + "long_name": "command_line_ok( _cache = [ ] )", + "filename": "misc_util.py", + "nloc": 14, + "complexity": 9, + "token_count": 98, + "parameters": [ + "_cache" + ], + "start_line": 321, + "end_line": 337, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 17, + "top_nesting_level": 0 + }, + { + "name": "dict_append", + "long_name": "dict_append( self , ** dict )", + "filename": "misc_util.py", + "nloc": 16, + "complexity": 7, + "token_count": 150, + "parameters": [ + "self", + "dict" + ], + "start_line": 797, + "end_line": 812, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 16, + "top_nesting_level": 1 + } + ], + "nloc": 861, + "complexity": 276, + "token_count": 6218, + "diff_parsed": { + "added": [ + "def command_line_ok(_cache=[]):", + " \"\"\" Return True if command line does not contain any", + " help or display requests.", + " \"\"\"", + " if _cache:", + " return _cache[0]", + " ok = True", + " from distutils.dist import Distribution", + " display_opts = ['--'+n for n in Distribution.display_option_names]", + " for o in Distribution.display_options:", + " if o[1]: display_opts.append('-'+o[1])", + " for arg in sys.argv:", + " if arg.startswith('--help') or arg=='-h' or arg in display_opts:", + " ok = False", + " break", + " _cache.append(ok)", + " return ok", + "", + " print>>sys.stderr, 'Warning:',message", + " if key not in ['version']:", + " self.warn('Inheriting attribute %r from %r' \\", + " % (key,dict.get('name','?')))", + " if not command_line_ok():", + " _do_nothing = lambda *args,**kws: None", + " add_subpackage = _do_nothing", + " add_extension = _do_nothing", + " add_library = _do_nothing", + " add_data_dir = _do_nothing", + " add_data_files = _do_nothing", + " add_scripts = _do_nothing", + " add_headers = _do_nothing", + " add_include_dirs = _do_nothing", + " make_config_py = _do_nothing", + " get_info = lambda *args,**kws:{}", + " have_f77c = lambda *args,**kws: False", + " have_f90c = lambda *args,**kws: False", + "" + ], + "deleted": [ + " print 'Warning:',message", + " print 'Inheriting attribute %r from %r' \\", + " % (key,dict.get('name','?'))" + ] + } + }, + { + "old_path": "setup.py", + "new_path": "setup.py", + "filename": "setup.py", + "extension": "py", + "change_type": "MODIFY", + "diff": "@@ -53,15 +53,15 @@ def setup_package():\n classifiers=filter(None, CLASSIFIERS.split('\\n')),\n author = \"Travis E. Oliphant, et.al.\",\n author_email = \"oliphant@ee.byu.edu\",\n- platforms = [\"Windows\", \"Linux\", \"Solaris\", \"Mac OS-X\", \"Unix\"]\n+ platforms = [\"Windows\", \"Linux\", \"Solaris\", \"Mac OS-X\", \"Unix\"],\n )\n- config.add_subpackage('numpy')\n \n+\n+ config.add_subpackage('numpy')\n from numpy.version import version\n config.name = 'numpy'\n config.dict_append(version=version)\n-\n- print config.name,'version',config.version\n+ #print config.name,'version',config.version\n \n setup( **config.todict() )\n finally:\n", + "added_lines": 4, + "deleted_lines": 4, + "source_code": "\"\"\"NumPy: array processing for numbers, strings, records, and objects.\n\nNumPy is a general-purpose array-processing package designed to\nefficiently manipulate large multi-dimensional arrays of arbitrary\nrecords without sacrificing too much speed for small multi-dimensional\narrays. NumPy is built on the Numeric code base and adds features\nintroduced by numarray as well as an extended C-API and the ability to\ncreate arrays of arbitrary type.\n\nThere are also basic facilities for discrete fourier transform,\nbasic linear algebra and random number generation.\n\"\"\"\n\nDOCLINES = __doc__.split(\"\\n\")\n\nimport os\nimport sys\n\nCLASSIFIERS = \"\"\"\\\nDevelopment Status :: 4 - Beta\nIntended Audience :: Science/Research\nIntended Audience :: Developers\nLicense :: OSI Approved\nProgramming Language :: C\nProgramming Language :: Python\nTopic :: Software Development\nTopic :: Scientific/Engineering\nOperating System :: Microsoft :: Windows\nOperating System :: POSIX\nOperating System :: Unix\nOperating System :: MacOS\n\"\"\"\n\ndef setup_package():\n\n from numpy.distutils.core import setup\n from numpy.distutils.misc_util import Configuration\n\n old_path = os.getcwd()\n local_path = os.path.dirname(os.path.abspath(sys.argv[0]))\n os.chdir(local_path)\n sys.path.insert(0,local_path)\n\n try:\n config = Configuration(\n maintainer = \"SciPy Developers\",\n maintainer_email = \"scipy-dev@scipy.org\",\n description = DOCLINES[0],\n long_description = \"\\n\".join(DOCLINES[2:]),\n url = \"http://numeric.scipy.org\",\n download_url = \"http://sourceforge.net/projects/numpy\",\n license = 'BSD',\n classifiers=filter(None, CLASSIFIERS.split('\\n')),\n author = \"Travis E. Oliphant, et.al.\",\n author_email = \"oliphant@ee.byu.edu\",\n platforms = [\"Windows\", \"Linux\", \"Solaris\", \"Mac OS-X\", \"Unix\"],\n )\n\n\n config.add_subpackage('numpy')\n from numpy.version import version\n config.name = 'numpy'\n config.dict_append(version=version)\n #print config.name,'version',config.version\n\n setup( **config.todict() )\n finally:\n del sys.path[0]\n os.chdir(old_path)\n return\n\nif __name__ == '__main__':\n setup_package()\n", + "source_code_before": "\"\"\"NumPy: array processing for numbers, strings, records, and objects.\n\nNumPy is a general-purpose array-processing package designed to\nefficiently manipulate large multi-dimensional arrays of arbitrary\nrecords without sacrificing too much speed for small multi-dimensional\narrays. NumPy is built on the Numeric code base and adds features\nintroduced by numarray as well as an extended C-API and the ability to\ncreate arrays of arbitrary type.\n\nThere are also basic facilities for discrete fourier transform,\nbasic linear algebra and random number generation.\n\"\"\"\n\nDOCLINES = __doc__.split(\"\\n\")\n\nimport os\nimport sys\n\nCLASSIFIERS = \"\"\"\\\nDevelopment Status :: 4 - Beta\nIntended Audience :: Science/Research\nIntended Audience :: Developers\nLicense :: OSI Approved\nProgramming Language :: C\nProgramming Language :: Python\nTopic :: Software Development\nTopic :: Scientific/Engineering\nOperating System :: Microsoft :: Windows\nOperating System :: POSIX\nOperating System :: Unix\nOperating System :: MacOS\n\"\"\"\n\ndef setup_package():\n\n from numpy.distutils.core import setup\n from numpy.distutils.misc_util import Configuration\n\n old_path = os.getcwd()\n local_path = os.path.dirname(os.path.abspath(sys.argv[0]))\n os.chdir(local_path)\n sys.path.insert(0,local_path)\n\n try:\n config = Configuration(\n maintainer = \"SciPy Developers\",\n maintainer_email = \"scipy-dev@scipy.org\",\n description = DOCLINES[0],\n long_description = \"\\n\".join(DOCLINES[2:]),\n url = \"http://numeric.scipy.org\",\n download_url = \"http://sourceforge.net/projects/numpy\",\n license = 'BSD',\n classifiers=filter(None, CLASSIFIERS.split('\\n')),\n author = \"Travis E. Oliphant, et.al.\",\n author_email = \"oliphant@ee.byu.edu\",\n platforms = [\"Windows\", \"Linux\", \"Solaris\", \"Mac OS-X\", \"Unix\"]\n )\n config.add_subpackage('numpy')\n\n from numpy.version import version\n config.name = 'numpy'\n config.dict_append(version=version)\n\n print config.name,'version',config.version\n\n setup( **config.todict() )\n finally:\n del sys.path[0]\n os.chdir(old_path)\n return\n\nif __name__ == '__main__':\n setup_package()\n", + "methods": [ + { + "name": "setup_package", + "long_name": "setup_package( )", + "filename": "setup.py", + "nloc": 30, + "complexity": 2, + "token_count": 198, + "parameters": [], + "start_line": 34, + "end_line": 70, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 37, + "top_nesting_level": 0 + } + ], + "methods_before": [ + { + "name": "setup_package", + "long_name": "setup_package( )", + "filename": "setup.py", + "nloc": 31, + "complexity": 2, + "token_count": 207, + "parameters": [], + "start_line": 34, + "end_line": 70, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 37, + "top_nesting_level": 0 + } + ], + "changed_methods": [ + { + "name": "setup_package", + "long_name": "setup_package( )", + "filename": "setup.py", + "nloc": 30, + "complexity": 2, + "token_count": 198, + "parameters": [], + "start_line": 34, + "end_line": 70, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 37, + "top_nesting_level": 0 + } + ], + "nloc": 61, + "complexity": 2, + "token_count": 223, + "diff_parsed": { + "added": [ + " platforms = [\"Windows\", \"Linux\", \"Solaris\", \"Mac OS-X\", \"Unix\"],", + "", + " config.add_subpackage('numpy')", + " #print config.name,'version',config.version" + ], + "deleted": [ + " platforms = [\"Windows\", \"Linux\", \"Solaris\", \"Mac OS-X\", \"Unix\"]", + " config.add_subpackage('numpy')", + "", + " print config.name,'version',config.version" + ] + } + } + ] + }, + { + "hash": "33279f11ed91b4175aaca16443ecd828b4b5c549", + "msg": "Added options to Configuration.", + "author": { + "name": "Pearu Peterson", + "email": "pearu.peterson@gmail.com" + }, + "committer": { + "name": "Pearu Peterson", + "email": "pearu.peterson@gmail.com" + }, + "author_date": "2006-01-31T09:22:35+00:00", + "author_timezone": 0, + "committer_date": "2006-01-31T09:22:35+00:00", + "committer_timezone": 0, + "branches": [ + "main" + ], + "in_main_branch": true, + "merge": false, + "parents": [ + "39ba8fc2bdf333811337d18d83c8611775649bb3" + ], + "project_name": "repo_copy", + "project_path": "/tmp/tmppy2o86q9/repo_copy", + "deletions": 22, + "insertions": 69, + "lines": 91, + "files": 2, + "dmm_unit_size": 0.0, + "dmm_unit_complexity": 0.35135135135135137, + "dmm_unit_interfacing": 0.32432432432432434, + "modified_files": [ + { + "old_path": "numpy/distutils/misc_util.py", + "new_path": "numpy/distutils/misc_util.py", + "filename": "misc_util.py", + "extension": "py", + "change_type": "MODIFY", + "diff": "@@ -408,6 +408,24 @@ def __init__(self,\n self.packages.append(self.name)\n self.package_dir[self.name] = package_path\n \n+ self.options = dict(\\\n+ ignore_setup_xxx_py = False,\n+ assume_default_configuration = False,\n+ delegate_options_to_subpackages = False,\n+ quiet = False,\n+ )\n+\n+ for i in range(1,3):\n+ f = get_frame(i)\n+ try:\n+ caller_instance = eval('self',f.f_globals,f.f_locals)\n+ break\n+ except NameError:\n+ caller_instance = None\n+ if isinstance(caller_instance, self.__class__):\n+ if caller_instance.options['delegate_options_to_subpackages']:\n+ self.set_options(**caller_instance.options)\n+\n return\n \n def todict(self):\n@@ -424,11 +442,28 @@ def todict(self):\n return d\n \n def info(self, message):\n- print message\n+ if not self.options['quiet']:\n+ print message\n \n def warn(self, message):\n print>>sys.stderr, 'Warning:',message\n \n+\n+ def set_options(self, **options):\n+ \"\"\" Configure Configuration instance.\n+\n+ The following options are available:\n+ - ignore_setup_xxx_py\n+ - assume_default_configuration\n+ - delegate_options_to_subpackages\n+ - quiet\n+ \"\"\"\n+ for key, value in options.items():\n+ if self.options.has_key(key):\n+ self.options[key] = value\n+ else:\n+ raise ValueError,'Unknown option: '+key\n+ return\n def __dict__(self):\n return self.todict()\n \n@@ -462,14 +497,17 @@ def get_subpackage(self,subpackage_name,subpackage_path=None):\n else:\n subpackage_path = njoin(*([subpackage_path]+l[:-1]))\n subpackage_path = self._fix_paths([subpackage_path])[0]\n+\n setup_py = njoin(subpackage_path,'setup.py')\n- if not os.path.isfile(setup_py):\n- setup_py = njoin(subpackage_path,'setup_%s.py' % (subpackage_name))\n+ if not self.options['ignore_setup_xxx_py']:\n+ if not os.path.isfile(setup_py):\n+ setup_py = njoin(subpackage_path,'setup_%s.py' % (subpackage_name))\n \n if not os.path.isfile(setup_py):\n- print 'Assuming default configuration '\\\n- '(%s/{setup_%s,setup}.py was not found)' \\\n- % (os.path.dirname(setup_py),subpackage_name)\n+ if not self.options['assume_default_configuration']:\n+ self.warn('Assuming default configuration '\\\n+ '(%s/{setup_%s,setup}.py was not found)' \\\n+ % (os.path.dirname(setup_py),subpackage_name))\n config = Configuration(subpackage_name,self.name,\n self.top_path,subpackage_path)\n else:\n@@ -482,8 +520,10 @@ def get_subpackage(self,subpackage_name,subpackage_path=None):\n setup_module = imp.load_module('_'.join(n.split('.')),*info)\n \n if not hasattr(setup_module,'configuration'):\n- print 'Assuming default configuration '\\\n- '(%s does not define configuration())' % (setup_module)\n+ if not self.options['assume_default_configuration']:\n+ self.warn('Assuming default configuration '\\\n+ '(%s does not define configuration())'\\\n+ % (setup_module))\n config = Configuration(subpackage_name,self.name,\n self.top_path,subpackage_path)\n else:\n@@ -507,18 +547,21 @@ def add_subpackage(self,subpackage_name,subpackage_path=None):\n config_list = config\n for config in config_list:\n if not config:\n- print 'No configuration returned, assuming unavailable.'\n+ self.warn('No configuration returned, assuming unavailable.')\n else:\n if isinstance(config,Configuration):\n- print 'Appending %s configuration to %s' % (config.name,self.name)\n+ self.info('Appending %s configuration to %s' \\\n+ % (config.name,self.name))\n self.dict_append(**config.todict())\n else:\n- print 'Appending %s configuration to %s' % (config.get('name'),self.name)\n+ self.info('Appending %s configuration to %s' \\\n+ % (config.get('name'),self.name))\n self.dict_append(**config)\n \n dist = self.get_distribution()\n if dist is not None:\n- print 'distutils distribution has been initialized, it may be too late to add a subpackage', subpackage_name\n+ self.warn('distutils distribution has been initialized,'\\\n+ ' it may be too late to add a subpackage '+ subpackage_name)\n return\n \n def add_data_dir(self,data_path):\n@@ -538,7 +581,7 @@ def add_data_dir(self,data_path):\n raise TypeError(\"not a string: %r\" % (data_path,))\n for path in self.paths(data_path):\n if not os.path.exists(path):\n- print 'Not existing data path',path\n+ self.warn('Not existing data path: '+path)\n continue\n filenames = []\n os.path.walk(path, _gsf_visit_func,filenames)\n@@ -753,7 +796,8 @@ def add_extension(self,name,sources,**kw):\n \n dist = self.get_distribution()\n if dist is not None:\n- print 'distutils distribution has been initialized, it may be too late to add an extension', name\n+ self.warn('distutils distribution has been initialized,'\\\n+ ' it may be too late to add an extension '+name)\n return ext\n \n def add_library(self,name,sources,**build_info):\n@@ -780,7 +824,8 @@ def add_library(self,name,sources,**build_info):\n \n dist = self.get_distribution()\n if dist is not None:\n- print 'distutils distribution has been initialized, it may be too late to add a library', name\n+ self.warn('distutils distribution has been initialized,'\\\n+ ' it may be too late to add a library '+ name)\n return\n \n def add_scripts(self,*files):\n@@ -916,7 +961,7 @@ def get_version(self):\n try:\n version_module = imp.load_module('_'.join(n.split('.')),*info)\n except ImportError,msg:\n- print msg\n+ self.warn(str(msg))\n version_module = None\n if version_module is None:\n continue\n@@ -950,22 +995,21 @@ def make_svn_version_py(self):\n target = njoin(self.local_path,'__svn_version__.py')\n if os.path.isfile(target):\n return\n-\n def generate_svn_version_py():\n if not os.path.isfile(target):\n revision = self._get_svn_revision(self.local_path)\n assert revision is not None,'hmm, why I am not inside SVN tree???'\n version = str(revision)\n- print 'Creating %s (version=%r)' % (target,version)\n+ self.info('Creating %s (version=%r)' % (target,version))\n f = open(target,'w')\n f.write('version = %r\\n' % (version))\n f.close()\n \n import atexit\n- def rm_file(f=target):\n- try: os.remove(f); print 'removed',f\n+ def rm_file(f=target,p=self.info):\n+ try: os.remove(f); p('removed '+f)\n except OSError: pass\n- try: os.remove(f+'c'); print 'removed',f+'c'\n+ try: os.remove(f+'c'); p('removed '+f+'c')\n except OSError: pass\n atexit.register(rm_file)\n \n", + "added_lines": 65, + "deleted_lines": 21, + "source_code": "import os\nimport re\nimport sys\nimport imp\nimport copy\nimport glob\n\n__all__ = ['Configuration', 'get_numpy_include_dirs', 'default_config_dict',\n 'dict_append', 'appendpath', 'generate_config_py',\n 'generate_svn_version_py', 'get_cmd', 'allpath',\n 'terminal_has_colors', 'red_text', 'green_text', 'yellow_text',\n 'blue_text', 'cyan_text', 'cyg2win32', 'all_strings',\n 'has_f_sources', 'has_cxx_sources', 'filter_sources',\n 'get_dependencies', 'is_local_src_dir', 'get_ext_source_files',\n 'get_script_files', 'get_lib_source_files', 'get_data_files',\n 'dot_join', 'get_frame', 'minrelpath','njoin']\n\ndef allpath(name):\n \"Convert a /-separated pathname to one using the OS's path separator.\"\n splitted = name.split('/')\n return os.path.join(*splitted)\n\ndef get_path(mod_name,parent_path=None):\n \"\"\" Return path of the module.\n\n Returned path is relative to parent_path when given,\n otherwise it is absolute path.\n \"\"\"\n if mod_name == '__main__':\n d = os.path.abspath('.')\n elif mod_name == '__builtin__':\n #builtin if/then added by Pearu for use in core.run_setup.\n d = os.path.dirname(os.path.abspath(sys.argv[0]))\n else:\n __import__(mod_name)\n mod = sys.modules[mod_name]\n file = mod.__file__\n d = os.path.dirname(os.path.abspath(file))\n if parent_path is not None:\n pd = os.path.abspath(parent_path)\n if pd==d[:len(pd)]:\n d = d[len(pd)+1:]\n return d or '.'\n\ndef njoin(*path):\n \"\"\" Join two or more pathname components +\n - convert a /-separated pathname to one using the OS's path separator.\n - resolve `..` from path.\n \"\"\"\n if isinstance(path,tuple):\n path = os.path.join(*path)\n if not isinstance(path,str): return path\n if not ('/' == os.path.sep):\n path = path.replace('/',os.path.sep)\n return minrelpath(path)\n\ndef minrelpath(path):\n \"\"\" Resolve `..` from path.\n \"\"\"\n if not isinstance(path, str): return path\n if '..' not in path: return path\n l = path.split(os.sep)\n j = 1\n while l:\n try:\n i = l.index('..',j)\n except ValueError:\n break\n if l[i-1]=='..':\n j += 1\n else:\n del l[i],l[i-1]\n j = 1\n if not l: return ''\n return os.path.join(*l)\n\n# Hooks for colored terminal output.\n# See also http://www.livinglogic.de/Python/ansistyle\ndef terminal_has_colors():\n if sys.platform=='cygwin' and not os.environ.has_key('USE_COLOR'):\n # Avoid importing curses that causes illegal operation\n # with a message:\n # PYTHON2 caused an invalid page fault in\n # module CYGNURSES7.DLL as 015f:18bbfc28\n # Details: Python 2.3.3 [GCC 3.3.1 (cygming special)]\n # ssh to Win32 machine from debian\n # curses.version is 2.2\n # CYGWIN_98-4.10, release 1.5.7(0.109/3/2))\n return 0\n if hasattr(sys.stdout,'isatty') and sys.stdout.isatty():\n try:\n import curses\n curses.setupterm()\n if (curses.tigetnum(\"colors\") >= 0\n and curses.tigetnum(\"pairs\") >= 0\n and ((curses.tigetstr(\"setf\") is not None\n and curses.tigetstr(\"setb\") is not None)\n or (curses.tigetstr(\"setaf\") is not None\n and curses.tigetstr(\"setab\") is not None)\n or curses.tigetstr(\"scp\") is not None)):\n return 1\n except Exception,msg:\n pass\n return 0\n\nif terminal_has_colors():\n def red_text(s): return '\\x1b[31m%s\\x1b[0m'%s\n def green_text(s): return '\\x1b[32m%s\\x1b[0m'%s\n def yellow_text(s): return '\\x1b[33m%s\\x1b[0m'%s\n def blue_text(s): return '\\x1b[34m%s\\x1b[0m'%s\n def cyan_text(s): return '\\x1b[35m%s\\x1b[0m'%s\nelse:\n def red_text(s): return s\n def green_text(s): return s\n def yellow_text(s): return s\n def cyan_text(s): return s\n def blue_text(s): return s\n\n#########################\n\ndef cyg2win32(path):\n if sys.platform=='cygwin' and path.startswith('/cygdrive'):\n path = path[10] + ':' + os.path.normcase(path[11:])\n return path\n\n#########################\n\n#XXX need support for .C that is also C++\ncxx_ext_match = re.compile(r'.*[.](cpp|cxx|cc)\\Z',re.I).match\nfortran_ext_match = re.compile(r'.*[.](f90|f95|f77|for|ftn|f)\\Z',re.I).match\nf90_ext_match = re.compile(r'.*[.](f90|f95)\\Z',re.I).match\nf90_module_name_match = re.compile(r'\\s*module\\s*(?P[\\w_]+)',re.I).match\ndef _get_f90_modules(source):\n \"\"\" Return a list of Fortran f90 module names that\n given source file defines.\n \"\"\"\n if not f90_ext_match(source):\n return []\n modules = []\n f = open(source,'r')\n f_readlines = getattr(f,'xreadlines',f.readlines)\n for line in f_readlines():\n m = f90_module_name_match(line)\n if m:\n name = m.group('name')\n modules.append(name)\n # break # XXX can we assume that there is one module per file?\n f.close()\n return modules\n\ndef is_string(s):\n return isinstance(s, str)\n\ndef all_strings(lst):\n \"\"\" Return True if all items in lst are string objects. \"\"\"\n for item in lst:\n if not is_string(item):\n return False\n return True\n\ndef is_sequence(seq):\n if is_string(seq):\n return False\n try:\n len(seq)\n except:\n return False\n return True\n\ndef has_f_sources(sources):\n \"\"\" Return True if sources contains Fortran files \"\"\"\n for source in sources:\n if fortran_ext_match(source):\n return True\n return False\n\ndef has_cxx_sources(sources):\n \"\"\" Return True if sources contains C++ files \"\"\"\n for source in sources:\n if cxx_ext_match(source):\n return True\n return False\n\ndef filter_sources(sources):\n \"\"\" Return four lists of filenames containing\n C, C++, Fortran, and Fortran 90 module sources,\n respectively.\n \"\"\"\n c_sources = []\n cxx_sources = []\n f_sources = []\n fmodule_sources = []\n for source in sources:\n if fortran_ext_match(source):\n modules = _get_f90_modules(source)\n if modules:\n fmodule_sources.append(source)\n else:\n f_sources.append(source)\n elif cxx_ext_match(source):\n cxx_sources.append(source)\n else:\n c_sources.append(source)\n return c_sources, cxx_sources, f_sources, fmodule_sources\n\n\ndef _get_headers(directory_list):\n # get *.h files from list of directories\n headers = []\n for dir in directory_list:\n head = glob.glob(os.path.join(dir,\"*.h\")) #XXX: *.hpp files??\n headers.extend(head)\n return headers\n\ndef _get_directories(list_of_sources):\n # get unique directories from list of sources.\n direcs = []\n for file in list_of_sources:\n dir = os.path.split(file)\n if dir[0] != '' and not dir[0] in direcs:\n direcs.append(dir[0])\n return direcs\n\ndef get_dependencies(sources):\n #XXX scan sources for include statements\n return _get_headers(_get_directories(sources))\n\ndef is_local_src_dir(directory):\n \"\"\" Return true if directory is local directory.\n \"\"\"\n if not is_string(directory):\n return False\n abs_dir = os.path.abspath(directory)\n c = os.path.commonprefix([os.getcwd(),abs_dir])\n new_dir = abs_dir[len(c):].split(os.sep)\n if new_dir and not new_dir[0]:\n new_dir = new_dir[1:]\n if new_dir and new_dir[0]=='build':\n return False\n new_dir = os.sep.join(new_dir)\n return os.path.isdir(new_dir)\n\ndef _gsf_visit_func(filenames,dirname,names):\n if os.path.basename(dirname) in ['CVS','.svn','build']:\n names[:] = []\n return\n for name in names:\n if name[-1] in \"~#\":\n continue\n fullname = os.path.join(dirname,name)\n ext = os.path.splitext(fullname)[1]\n if ext and ext in ['.pyc','.o']:\n continue\n if os.path.isfile(fullname):\n filenames.append(fullname)\n\ndef get_ext_source_files(ext):\n # Get sources and any include files in the same directory.\n filenames = []\n sources = filter(is_string, ext.sources)\n filenames.extend(sources)\n filenames.extend(get_dependencies(sources))\n for d in ext.depends:\n if is_local_src_dir(d):\n os.path.walk(d,_gsf_visit_func,filenames)\n elif os.path.isfile(d):\n filenames.append(d)\n return filenames\n\ndef get_script_files(scripts):\n scripts = filter(is_string, scripts)\n return scripts\n\ndef get_lib_source_files(lib):\n filenames = []\n sources = lib[1].get('sources',[])\n sources = filter(is_string, sources)\n filenames.extend(sources)\n filenames.extend(get_dependencies(sources))\n depends = lib[1].get('depends',[])\n for d in depends:\n if is_local_src_dir(d):\n os.path.walk(d,_gsf_visit_func,filenames)\n elif os.path.isfile(d):\n filenames.append(d)\n return filenames\n\ndef get_data_files(data):\n if is_string(data):\n return [data]\n sources = data[1]\n filenames = []\n for s in sources:\n if callable(s):\n continue\n if is_local_src_dir(s):\n os.path.walk(s,_gsf_visit_func,filenames)\n elif is_string(s):\n if os.path.isfile(s):\n filenames.append(s)\n else:\n print 'Not existing data file:',s\n else:\n raise TypeError,repr(s)\n return filenames\n\ndef dot_join(*args):\n return '.'.join(filter(None,args))\n\ndef get_frame(level=0):\n try:\n return sys._getframe(level+1)\n except AttributeError:\n frame = sys.exc_info()[2].tb_frame\n for i in range(level+1):\n frame = frame.f_back\n return frame\n\n######################\n\ndef command_line_ok(_cache=[]):\n \"\"\" Return True if command line does not contain any\n help or display requests.\n \"\"\"\n if _cache:\n return _cache[0]\n ok = True\n from distutils.dist import Distribution\n display_opts = ['--'+n for n in Distribution.display_option_names]\n for o in Distribution.display_options:\n if o[1]: display_opts.append('-'+o[1])\n for arg in sys.argv:\n if arg.startswith('--help') or arg=='-h' or arg in display_opts:\n ok = False\n break\n _cache.append(ok)\n return ok\n\nclass Configuration:\n\n _list_keys = ['packages','ext_modules','data_files','include_dirs',\n 'libraries','headers','scripts','py_modules']\n _dict_keys = ['package_dir']\n\n numpy_include_dirs = []\n\n def __init__(self,\n package_name=None,\n parent_name=None,\n top_path=None,\n package_path=None,\n **attrs):\n \"\"\" Construct configuration instance of a package.\n\n package_name -- name of the package\n Ex.: 'distutils'\n parent_name -- name of the parent package\n Ex.: 'numpy'\n top_path -- directory of the toplevel package\n Ex.: the directory where the numpy package source sits\n package_path -- directory of package. Will be computed by magic from the\n directory of the caller module if not specified\n Ex.: the directory where numpy.distutils is\n \"\"\"\n self.name = dot_join(parent_name, package_name)\n\n caller_frame = get_frame(1)\n caller_name = eval('__name__',caller_frame.f_globals,caller_frame.f_locals)\n\n self.local_path = get_path(caller_name, top_path)\n if top_path is None:\n top_path = self.local_path\n if package_path is None:\n package_path = self.local_path\n elif os.path.isdir(njoin(self.local_path,package_path)):\n package_path = njoin(self.local_path,package_path)\n if not os.path.isdir(package_path):\n raise ValueError(\"%r is not a directory\" % (package_path,))\n self.top_path = top_path\n self.package_path = package_path\n # this is the relative path in the installed package\n self.path_in_package = os.path.join(*self.name.split('.'))\n\n self.list_keys = copy.copy(self._list_keys)\n self.dict_keys = copy.copy(self._dict_keys)\n\n for n in self.list_keys:\n setattr(self,n,copy.copy(attrs.get(n,[])))\n\n for n in self.dict_keys:\n setattr(self,n,copy.copy(attrs.get(n,{})))\n\n known_keys = self.list_keys + self.dict_keys\n self.extra_keys = []\n for n in attrs.keys():\n if n in known_keys:\n continue\n a = attrs[n]\n setattr(self,n,a)\n if isinstance(a, list):\n self.list_keys.append(n)\n elif isinstance(a, dict):\n self.dict_keys.append(n)\n else:\n self.extra_keys.append(n)\n\n if os.path.exists(njoin(package_path,'__init__.py')):\n self.packages.append(self.name)\n self.package_dir[self.name] = package_path\n\n self.options = dict(\\\n ignore_setup_xxx_py = False,\n assume_default_configuration = False,\n delegate_options_to_subpackages = False,\n quiet = False,\n )\n\n for i in range(1,3):\n f = get_frame(i)\n try:\n caller_instance = eval('self',f.f_globals,f.f_locals)\n break\n except NameError:\n caller_instance = None\n if isinstance(caller_instance, self.__class__):\n if caller_instance.options['delegate_options_to_subpackages']:\n self.set_options(**caller_instance.options)\n\n return\n\n def todict(self):\n \"\"\" Return configuration distionary suitable for passing\n to distutils.core.setup() function.\n \"\"\"\n d = {}\n for n in self.list_keys + self.dict_keys + self.extra_keys:\n a = getattr(self,n)\n if a:\n d[n] = a\n if self.name:\n d['name'] = self.name\n return d\n\n def info(self, message):\n if not self.options['quiet']:\n print message\n\n def warn(self, message):\n print>>sys.stderr, 'Warning:',message\n\n\n def set_options(self, **options):\n \"\"\" Configure Configuration instance.\n\n The following options are available:\n - ignore_setup_xxx_py\n - assume_default_configuration\n - delegate_options_to_subpackages\n - quiet\n \"\"\"\n for key, value in options.items():\n if self.options.has_key(key):\n self.options[key] = value\n else:\n raise ValueError,'Unknown option: '+key\n return\n def __dict__(self):\n return self.todict()\n\n def get_distribution(self):\n import distutils.core\n dist = distutils.core._setup_distribution\n return dist\n\n def get_subpackage(self,subpackage_name,subpackage_path=None):\n \"\"\" Return subpackage configuration.\n \"\"\"\n if subpackage_name is None:\n assert subpackage_path is not None\n subpackage_name = os.path.basename(subpackage_path)\n l = subpackage_name.split('.')\n if subpackage_path is None:\n subpackage_path = njoin(*([self.local_path]+l))\n if '*' in subpackage_name:\n dirs = filter(os.path.isdir,glob.glob(subpackage_path))\n config_list = []\n for d in dirs:\n if not os.path.isfile(njoin(d,'__init__.py')):\n continue\n if 'build' in d.split(os.sep):\n continue\n n = '.'.join(d.split(os.sep)[-len(l):])\n c = self.get_subpackage(n)\n if c:\n config_list.append(c)\n return config_list\n else:\n subpackage_path = njoin(*([subpackage_path]+l[:-1]))\n subpackage_path = self._fix_paths([subpackage_path])[0]\n\n setup_py = njoin(subpackage_path,'setup.py')\n if not self.options['ignore_setup_xxx_py']:\n if not os.path.isfile(setup_py):\n setup_py = njoin(subpackage_path,'setup_%s.py' % (subpackage_name))\n\n if not os.path.isfile(setup_py):\n if not self.options['assume_default_configuration']:\n self.warn('Assuming default configuration '\\\n '(%s/{setup_%s,setup}.py was not found)' \\\n % (os.path.dirname(setup_py),subpackage_name))\n config = Configuration(subpackage_name,self.name,\n self.top_path,subpackage_path)\n else:\n # In case setup_py imports local modules:\n sys.path.insert(0,os.path.dirname(setup_py))\n try:\n info = (open(setup_py),setup_py,('.py','U',1))\n setup_name = os.path.splitext(os.path.basename(setup_py))[0]\n n = dot_join(self.name,setup_name)\n setup_module = imp.load_module('_'.join(n.split('.')),*info)\n\n if not hasattr(setup_module,'configuration'):\n if not self.options['assume_default_configuration']:\n self.warn('Assuming default configuration '\\\n '(%s does not define configuration())'\\\n % (setup_module))\n config = Configuration(subpackage_name,self.name,\n self.top_path,subpackage_path)\n else:\n args = (self.name,)\n if setup_module.configuration.func_code.co_argcount>1:\n args = args + (self.top_path,)\n config = setup_module.configuration(*args)\n\n finally:\n del sys.path[0]\n\n return config\n\n def add_subpackage(self,subpackage_name,subpackage_path=None):\n \"\"\" Add subpackage to configuration.\n \"\"\"\n config = self.get_subpackage(subpackage_name,subpackage_path)\n if not isinstance(config, list):\n config_list = [config]\n else:\n config_list = config\n for config in config_list:\n if not config:\n self.warn('No configuration returned, assuming unavailable.')\n else:\n if isinstance(config,Configuration):\n self.info('Appending %s configuration to %s' \\\n % (config.name,self.name))\n self.dict_append(**config.todict())\n else:\n self.info('Appending %s configuration to %s' \\\n % (config.get('name'),self.name))\n self.dict_append(**config)\n\n dist = self.get_distribution()\n if dist is not None:\n self.warn('distutils distribution has been initialized,'\\\n ' it may be too late to add a subpackage '+ subpackage_name)\n return\n\n def add_data_dir(self,data_path):\n \"\"\" Recursively add files under data_path to data_files list.\n Argument can be either\n - 2-sequence (,)\n - path to data directory where python datadir suffix defaults\n to package dir.\n If path is not absolute then it's datadir suffix is\n package dir + subdirname of the path.\n \"\"\"\n if is_sequence(data_path):\n d, data_path = data_path\n else:\n d = None\n if not is_string(data_path):\n raise TypeError(\"not a string: %r\" % (data_path,))\n for path in self.paths(data_path):\n if not os.path.exists(path):\n self.warn('Not existing data path: '+path)\n continue\n filenames = []\n os.path.walk(path, _gsf_visit_func,filenames)\n if not os.path.isabs(path):\n npath = data_path\n if '*' in npath:\n npath = os.path.join(*(path.split(os.sep)[-len(npath.split(os.sep)):]))\n if d is None:\n d = self.path_in_package\n ds = os.path.join(d, npath)\n self.add_data_files((ds,filenames))\n else:\n if d is None:\n self.add_data_files(*filenames)\n else:\n self.add_data_files((d,filenames))\n return\n\n def add_data_files(self,*files):\n \"\"\" Add data files to configuration data_files.\n Argument(s) can be either\n - 2-sequence (,)\n - paths to data files where python datadir prefix defaults\n to package dir.\n If path is not absolute then it's datadir prefix is\n package dir + dirname of the path.\n \"\"\"\n data_dict = {}\n new_files = []\n for p in files:\n if not is_sequence(p):\n d = self.path_in_package\n if is_string(p) and not os.path.isabs(p):\n pd = os.path.dirname(p)\n if '*' in pd:\n pn = os.path.basename(p)\n n = len(pd.split(os.sep))\n for d1 in filter(os.path.isdir,self.paths(pd)):\n p = os.path.join(d1,pn)\n d1 = os.sep.join(d1.split(os.sep)[-n:])\n new_files.append((appendpath(d,d1),p))\n continue\n d = appendpath(d,pd)\n p = (d,p) \n new_files.append(p)\n \n files = []\n for prefix,filepattern in new_files:\n assert '*' not in prefix,`prefix,filepattern`\n if is_string(filepattern):\n file_list = self.paths(filepattern,include_non_existing=False)\n elif callable(filepattern):\n file_list = [filepattern]\n else:\n file_list = self.paths(*filepattern)\n\n nof_path_components = [len(f.split(os.sep))\n for f in file_list if is_string(f)]\n if nof_path_components:\n min_path_components = min(nof_path_components)-1\n else:\n min_path_components = 0\n\n for f in file_list:\n if is_string(f):\n extra_path_components = f.split(os.sep)[min_path_components:-1]\n p = njoin(*([prefix]+extra_path_components))\n else:\n p = prefix\n if not data_dict.has_key(p):\n data_dict[p] = [f]\n else:\n data_dict[p].append(f)\n\n dist = self.get_distribution()\n if dist is not None:\n dist.data_files.extend(data_dict.items())\n else:\n self.data_files.extend(data_dict.items())\n\n ### XXX Implement add_py_modules\n\n def add_include_dirs(self,*paths):\n \"\"\" Add paths to configuration include directories.\n \"\"\"\n include_dirs = self._fix_paths(paths)\n dist = self.get_distribution()\n if dist is not None:\n dist.include_dirs.extend(include_dirs)\n else:\n self.include_dirs.extend(include_dirs)\n return\n\n def add_headers(self,*files):\n \"\"\" Add installable headers to configuration.\n Argument(s) can be either\n - 2-sequence (,)\n - path(s) to header file(s) where python includedir suffix will default\n to package name.\n \"\"\"\n headers = []\n for path in files:\n if is_string(path):\n [headers.append((self.name,p)) for p in self.paths(path)]\n else:\n if not isinstance(path, (tuple, list)) or len(path) != 2:\n raise TypeError(repr(path))\n [headers.append((path[0],p)) for p in self.paths(path[1])]\n dist = self.get_distribution()\n if dist is not None:\n dist.headers.extend(headers)\n else:\n self.headers.extend(headers)\n return\n\n def _fix_paths(self,paths,include_non_existing=True):\n assert isinstance(paths,(list,tuple)),`type(paths)`\n new_paths = []\n for n in paths:\n if isinstance(n,str):\n if '*' in n or '?' in n:\n p = glob.glob(n)\n p2 = glob.glob(njoin(self.local_path,n))\n if p2:\n new_paths.extend(p2)\n elif p:\n new_paths.extend(p)\n else:\n if include_non_existing:\n new_paths.append(n)\n self.warn('could not resolve pattern: %r' % (n))\n else:\n n2 = njoin(self.local_path,n)\n if os.path.exists(n2):\n new_paths.append(n2)\n else:\n if os.path.exists(n):\n new_paths.append(n)\n elif include_non_existing:\n new_paths.append(n)\n if not os.path.exists(n):\n self.warn('not existing path: %r' % (n))\n else:\n new_paths.append(n)\n return map(minrelpath,new_paths)\n\n def paths(self,*paths,**kws):\n \"\"\" Apply glob to paths and prepend local_path if needed.\n \"\"\"\n include_non_existing = kws.get('include_non_existing',True)\n return self._fix_paths(paths,\n include_non_existing=include_non_existing)\n\n def add_extension(self,name,sources,**kw):\n \"\"\" Add extension to configuration.\n\n Keywords:\n include_dirs, define_macros, undef_macros,\n library_dirs, libraries, runtime_library_dirs,\n extra_objects, extra_compile_args, extra_link_args,\n export_symbols, swig_opts, depends, language,\n f2py_options, module_dirs\n extra_info - dict or list of dict of keywords to be\n appended to keywords.\n \"\"\"\n ext_args = copy.copy(kw)\n ext_args['name'] = dot_join(self.name,name)\n ext_args['sources'] = sources\n\n if ext_args.has_key('extra_info'):\n extra_info = ext_args['extra_info']\n del ext_args['extra_info']\n if type(extra_info) is type({}):\n extra_info = [extra_info]\n for info in extra_info:\n assert type(info) is type({}),`info`\n dict_append(ext_args,**info)\n\n for k in ext_args.keys():\n v = ext_args[k]\n if k in ['sources','depends','include_dirs','library_dirs',\n 'module_dirs','extra_objects']:\n new_v = self._fix_paths(v)\n ext_args[k] = new_v\n\n # Resolve out-of-tree dependencies\n libraries = ext_args.get('libraries',[])\n libnames = []\n ext_args['libraries'] = []\n for libname in libraries:\n if '@' in libname:\n lname,lpath = libname.split('@',1)\n lpath = os.path.abspath(njoin(self.local_path,lpath))\n if os.path.isdir(lpath):\n c = self.get_subpackage(None,lpath)\n if isinstance(c,Configuration):\n c = c.todict()\n for l in [l[0] for l in c.get('libraries',[])]:\n llname = l.split('__OF__',1)[0]\n if llname == lname:\n c.pop('name',None)\n dict_append(ext_args,**c)\n break\n continue\n libnames.append(libname)\n\n ext_args['libraries'] = libnames + ext_args['libraries']\n\n from numpy.distutils.core import Extension\n ext = Extension(**ext_args)\n self.ext_modules.append(ext)\n\n dist = self.get_distribution()\n if dist is not None:\n self.warn('distutils distribution has been initialized,'\\\n ' it may be too late to add an extension '+name)\n return ext\n\n def add_library(self,name,sources,**build_info):\n \"\"\" Add library to configuration.\n\n Valid keywords for build_info:\n depends\n macros\n include_dirs\n extra_compiler_args\n f2py_options\n \"\"\"\n build_info = copy.copy(build_info)\n name = name #+ '__OF__' + self.name\n build_info['sources'] = sources\n\n for k in build_info.keys():\n v = build_info[k]\n if k in ['sources','depends','include_dirs','library_dirs',\n 'module_dirs','extra_objects']:\n new_v = self._fix_paths(v)\n build_info[k] = new_v\n self.libraries.append((name,build_info))\n\n dist = self.get_distribution()\n if dist is not None:\n self.warn('distutils distribution has been initialized,'\\\n ' it may be too late to add a library '+ name)\n return\n\n def add_scripts(self,*files):\n \"\"\" Add scripts to configuration.\n \"\"\"\n scripts = self._fix_paths(files)\n dist = self.get_distribution()\n if dist is not None:\n dist.scripts.extend(scripts)\n else:\n self.scripts.extend(scripts)\n return\n\n def dict_append(self,**dict):\n for key in self.list_keys:\n a = getattr(self,key)\n a.extend(dict.get(key,[]))\n for key in self.dict_keys:\n a = getattr(self,key)\n a.update(dict.get(key,{}))\n known_keys = self.list_keys + self.dict_keys + self.extra_keys\n for key in dict.keys():\n if key not in known_keys and not hasattr(self,key):\n if key not in ['version']:\n self.warn('Inheriting attribute %r from %r' \\\n % (key,dict.get('name','?')))\n setattr(self,key,dict[key])\n self.extra_keys.append(key)\n return\n\n def __str__(self):\n known_keys = self.list_keys + self.dict_keys + self.extra_keys\n s = '<'+5*'-' + '\\n'\n s += 'Configuration of '+self.name+':\\n'\n for k in known_keys:\n a = getattr(self,k,None)\n if a:\n s += '%s = %r\\n' % (k,a)\n s += 5*'-' + '>'\n return s\n\n def get_config_cmd(self):\n cmd = get_cmd('config')\n cmd.ensure_finalized()\n cmd.dump_source = 0\n cmd.noisy = 0\n old_path = os.environ.get('PATH')\n if old_path:\n path = os.pathsep.join(['.',old_path])\n os.environ['PATH'] = path\n return cmd\n\n def get_build_temp_dir(self):\n cmd = get_cmd('build')\n cmd.ensure_finalized()\n return cmd.build_temp\n\n def have_f77c(self):\n \"\"\" Check for availability of Fortran 77 compiler.\n Use it inside source generating function to ensure that\n setup distribution instance has been initialized.\n \"\"\"\n simple_fortran_subroutine = '''\n subroutine simple\n end\n '''\n config_cmd = self.get_config_cmd()\n flag = config_cmd.try_compile(simple_fortran_subroutine,lang='f77')\n return flag\n\n def have_f90c(self):\n \"\"\" Check for availability of Fortran 90 compiler.\n Use it inside source generating function to ensure that\n setup distribution instance has been initialized.\n \"\"\"\n simple_fortran_subroutine = '''\n subroutine simple\n end\n '''\n config_cmd = self.get_config_cmd()\n flag = config_cmd.try_compile(simple_fortran_subroutine,lang='f90')\n return flag\n\n def append_to(self, extlib):\n \"\"\" Append libraries, include_dirs to extension or library item.\n \"\"\"\n if is_sequence(extlib):\n lib_name, build_info = extlib\n dict_append(build_info,\n libraries=self.libraries,\n include_dirs=self.include_dirs)\n else:\n from numpy.distutils.core import Extension\n assert isinstance(extlib,Extension),`extlib`\n extlib.libraries.extend(self.libraries)\n extlib.include_dirs.extend(self.include_dirs)\n return\n\n def _get_svn_revision(self,path):\n \"\"\" Return path's SVN revision number.\n \"\"\"\n entries = njoin(path,'.svn','entries')\n revision = None\n if os.path.isfile(entries):\n f = open(entries)\n m = re.search(r'revision=\"(?P\\d+)\"',f.read())\n f.close()\n if m:\n revision = int(m.group('revision'))\n return revision\n\n def get_version(self):\n \"\"\" Try to get version string of a package.\n \"\"\"\n version = getattr(self,'version',None)\n if version is not None:\n return version\n\n # Get version from version file.\n files = ['__version__.py',\n self.name.split('.')[-1]+'_version.py',\n 'version.py',\n '__svn_version__.py']\n version_vars = ['version',\n '__version__',\n self.name.split('.')[-1]+'_version']\n for f in files:\n fn = njoin(self.local_path,f)\n if os.path.isfile(fn):\n info = (open(fn),fn,('.py','U',1))\n name = os.path.splitext(os.path.basename(fn))[0]\n n = dot_join(self.name,name)\n try:\n version_module = imp.load_module('_'.join(n.split('.')),*info)\n except ImportError,msg:\n self.warn(str(msg))\n version_module = None\n if version_module is None:\n continue\n\n for a in version_vars:\n version = getattr(version_module,a,None)\n if version is not None:\n break\n if version is not None:\n break\n\n if version is not None:\n self.version = version\n return version\n\n # Get version as SVN revision number\n revision = self._get_svn_revision(self.local_path)\n if revision is not None:\n version = str(revision)\n self.version = version\n\n return version\n\n def make_svn_version_py(self):\n \"\"\" Generate package __svn_version__.py file from SVN revision number,\n it will be removed after python exits but will be available\n when sdist, etc commands are executed.\n\n If __svn_version__.py existed before, nothing is done.\n \"\"\"\n target = njoin(self.local_path,'__svn_version__.py')\n if os.path.isfile(target):\n return\n def generate_svn_version_py():\n if not os.path.isfile(target):\n revision = self._get_svn_revision(self.local_path)\n assert revision is not None,'hmm, why I am not inside SVN tree???'\n version = str(revision)\n self.info('Creating %s (version=%r)' % (target,version))\n f = open(target,'w')\n f.write('version = %r\\n' % (version))\n f.close()\n\n import atexit\n def rm_file(f=target,p=self.info):\n try: os.remove(f); p('removed '+f)\n except OSError: pass\n try: os.remove(f+'c'); p('removed '+f+'c')\n except OSError: pass\n atexit.register(rm_file)\n\n return target\n\n self.add_data_files((self.path_in_package, generate_svn_version_py()))\n return\n\n def make_config_py(self,name='__config__'):\n \"\"\" Generate package __config__.py file containing system_info\n information used during building the package.\n \"\"\"\n self.py_modules.append((self.name,name,generate_config_py))\n return\n\n def get_info(self,*names):\n \"\"\" Get resources information.\n \"\"\"\n from system_info import get_info, dict_append\n info_dict = {}\n for a in names:\n dict_append(info_dict,**get_info(a))\n return info_dict\n\n if not command_line_ok():\n _do_nothing = lambda *args,**kws: None\n add_subpackage = _do_nothing\n add_extension = _do_nothing\n add_library = _do_nothing\n add_data_dir = _do_nothing\n add_data_files = _do_nothing\n add_scripts = _do_nothing\n add_headers = _do_nothing\n add_include_dirs = _do_nothing\n make_config_py = _do_nothing\n get_info = lambda *args,**kws:{}\n have_f77c = lambda *args,**kws: False\n have_f90c = lambda *args,**kws: False\n\ndef get_cmd(cmdname,_cache={}):\n if not _cache.has_key(cmdname):\n import distutils.core\n dist = distutils.core._setup_distribution\n if dist is None:\n from distutils.errors import DistutilsInternalError\n raise DistutilsInternalError,\\\n 'setup distribution instance not initialized'\n cmd = dist.get_command_obj(cmdname)\n _cache[cmdname] = cmd\n return _cache[cmdname]\n\ndef get_numpy_include_dirs():\n # numpy_include_dirs are set by numpy/core/setup.py, otherwise []\n include_dirs = Configuration.numpy_include_dirs[:]\n if not include_dirs:\n import numpy\n if numpy.show_config is None:\n # running from numpy_core source directory\n include_dirs.append(njoin(os.path.dirname(numpy.__file__),\n 'core','include'))\n else:\n # using installed numpy core headers\n import numpy.core as core\n include_dirs.append(njoin(os.path.dirname(core.__file__),'include'))\n # else running numpy/core/setup.py\n return include_dirs\n\n#########################\n\ndef default_config_dict(name = None, parent_name = None, local_path=None):\n \"\"\" Return a configuration dictionary for usage in\n configuration() function defined in file setup_.py.\n \"\"\"\n import warnings\n warnings.warn('Use Configuration(%s,%s,top_path=%s) instead of '\\\n 'deprecated default_config_dict(%s,%s,%s)' \\\n % (`name`,`parent_name`,`local_path`,\n `name`,`parent_name`,`local_path`,\n ))\n c = Configuration(name, parent_name, local_path)\n return c.todict()\n\n\ndef dict_append(d,**kws):\n for k,v in kws.items():\n if d.has_key(k):\n d[k].extend(v)\n else:\n d[k] = v\n\ndef appendpath(prefix,path):\n if not ('/' == os.path.sep):\n prefix = prefix.replace('/',os.path.sep)\n path = path.replace('/',os.path.sep)\n drive = ''\n if os.path.isabs(path):\n drive = os.path.splitdrive(prefix)[0]\n absprefix = os.path.splitdrive(os.path.abspath(prefix))[1]\n pathdrive,path = os.path.splitdrive(path)\n d = os.path.commonprefix([absprefix,path])\n if os.path.join(absprefix[:len(d)],absprefix[len(d):])!=absprefix \\\n or os.path.join(path[:len(d)],path[len(d):])!=path:\n # Handle invalid paths\n d = os.path.dirname(d)\n subpath = path[len(d):]\n if os.path.isabs(subpath):\n subpath = subpath[1:]\n else:\n subpath = path\n return os.path.normpath(njoin(drive + prefix, subpath))\n\n\n\n\n\ndef generate_config_py(target):\n \"\"\" Generate config.py file containing system_info information\n used during building the package.\n\n Usage:\\\n config['py_modules'].append((packagename, '__config__',generate_config_py))\n \"\"\"\n from numpy.distutils.system_info import system_info\n from distutils.dir_util import mkpath\n mkpath(os.path.dirname(target))\n f = open(target,'w')\n f.write('# This file is generated by %s\\n' % (os.path.abspath(sys.argv[0])))\n f.write('# It contains system_info results at the time of building this package.\\n')\n f.write('__all__ = [\"get_info\",\"show\"]\\n\\n')\n for k,i in system_info.saved_results.items():\n f.write('%s=%r\\n' % (k,i))\n f.write('\\ndef get_info(name): g=globals(); return g.get(name,g.get(name+\"_info\",{}))\\n')\n f.write('''\ndef show():\n for name,info_dict in globals().items():\n if name[0]==\"_\" or type(info_dict) is not type({}): continue\n print name+\":\"\n if not info_dict:\n print \" NOT AVAILABLE\"\n for k,v in info_dict.items():\n v = str(v)\n if k==\\'sources\\' and len(v)>200: v = v[:60]+\\' ...\\\\n... \\'+v[-60:]\n print \\' %s = %s\\'%(k,v)\n print\n return\n ''')\n\n f.close()\n return target\n\ndef generate_svn_version_py(extension, build_dir):\n \"\"\" Generate __svn_version__.py file containing SVN\n revision number of a module.\n\n To use, add the following codelet to setup\n configuration(..) function\n\n ext = Extension(dot_join(config['name'],'__svn_version__'),\n sources=[generate_svn_version_py])\n ext.local_path = local_path\n config['ext_modules'].append(ext)\n\n \"\"\"\n from distutils import dep_util\n local_path = extension.local_path\n target = njoin(build_dir, '__svn_version__.py')\n entries = njoin(local_path,'.svn','entries')\n if os.path.isfile(entries):\n if not dep_util.newer(entries, target):\n return target\n elif os.path.isfile(target):\n return target\n\n revision = get_svn_revision(local_path)\n f = open(target,'w')\n f.write('revision=%s\\n' % (revision))\n f.close()\n return target\n", + "source_code_before": "import os\nimport re\nimport sys\nimport imp\nimport copy\nimport glob\n\n__all__ = ['Configuration', 'get_numpy_include_dirs', 'default_config_dict',\n 'dict_append', 'appendpath', 'generate_config_py',\n 'generate_svn_version_py', 'get_cmd', 'allpath',\n 'terminal_has_colors', 'red_text', 'green_text', 'yellow_text',\n 'blue_text', 'cyan_text', 'cyg2win32', 'all_strings',\n 'has_f_sources', 'has_cxx_sources', 'filter_sources',\n 'get_dependencies', 'is_local_src_dir', 'get_ext_source_files',\n 'get_script_files', 'get_lib_source_files', 'get_data_files',\n 'dot_join', 'get_frame', 'minrelpath','njoin']\n\ndef allpath(name):\n \"Convert a /-separated pathname to one using the OS's path separator.\"\n splitted = name.split('/')\n return os.path.join(*splitted)\n\ndef get_path(mod_name,parent_path=None):\n \"\"\" Return path of the module.\n\n Returned path is relative to parent_path when given,\n otherwise it is absolute path.\n \"\"\"\n if mod_name == '__main__':\n d = os.path.abspath('.')\n elif mod_name == '__builtin__':\n #builtin if/then added by Pearu for use in core.run_setup.\n d = os.path.dirname(os.path.abspath(sys.argv[0]))\n else:\n __import__(mod_name)\n mod = sys.modules[mod_name]\n file = mod.__file__\n d = os.path.dirname(os.path.abspath(file))\n if parent_path is not None:\n pd = os.path.abspath(parent_path)\n if pd==d[:len(pd)]:\n d = d[len(pd)+1:]\n return d or '.'\n\ndef njoin(*path):\n \"\"\" Join two or more pathname components +\n - convert a /-separated pathname to one using the OS's path separator.\n - resolve `..` from path.\n \"\"\"\n if isinstance(path,tuple):\n path = os.path.join(*path)\n if not isinstance(path,str): return path\n if not ('/' == os.path.sep):\n path = path.replace('/',os.path.sep)\n return minrelpath(path)\n\ndef minrelpath(path):\n \"\"\" Resolve `..` from path.\n \"\"\"\n if not isinstance(path, str): return path\n if '..' not in path: return path\n l = path.split(os.sep)\n j = 1\n while l:\n try:\n i = l.index('..',j)\n except ValueError:\n break\n if l[i-1]=='..':\n j += 1\n else:\n del l[i],l[i-1]\n j = 1\n if not l: return ''\n return os.path.join(*l)\n\n# Hooks for colored terminal output.\n# See also http://www.livinglogic.de/Python/ansistyle\ndef terminal_has_colors():\n if sys.platform=='cygwin' and not os.environ.has_key('USE_COLOR'):\n # Avoid importing curses that causes illegal operation\n # with a message:\n # PYTHON2 caused an invalid page fault in\n # module CYGNURSES7.DLL as 015f:18bbfc28\n # Details: Python 2.3.3 [GCC 3.3.1 (cygming special)]\n # ssh to Win32 machine from debian\n # curses.version is 2.2\n # CYGWIN_98-4.10, release 1.5.7(0.109/3/2))\n return 0\n if hasattr(sys.stdout,'isatty') and sys.stdout.isatty():\n try:\n import curses\n curses.setupterm()\n if (curses.tigetnum(\"colors\") >= 0\n and curses.tigetnum(\"pairs\") >= 0\n and ((curses.tigetstr(\"setf\") is not None\n and curses.tigetstr(\"setb\") is not None)\n or (curses.tigetstr(\"setaf\") is not None\n and curses.tigetstr(\"setab\") is not None)\n or curses.tigetstr(\"scp\") is not None)):\n return 1\n except Exception,msg:\n pass\n return 0\n\nif terminal_has_colors():\n def red_text(s): return '\\x1b[31m%s\\x1b[0m'%s\n def green_text(s): return '\\x1b[32m%s\\x1b[0m'%s\n def yellow_text(s): return '\\x1b[33m%s\\x1b[0m'%s\n def blue_text(s): return '\\x1b[34m%s\\x1b[0m'%s\n def cyan_text(s): return '\\x1b[35m%s\\x1b[0m'%s\nelse:\n def red_text(s): return s\n def green_text(s): return s\n def yellow_text(s): return s\n def cyan_text(s): return s\n def blue_text(s): return s\n\n#########################\n\ndef cyg2win32(path):\n if sys.platform=='cygwin' and path.startswith('/cygdrive'):\n path = path[10] + ':' + os.path.normcase(path[11:])\n return path\n\n#########################\n\n#XXX need support for .C that is also C++\ncxx_ext_match = re.compile(r'.*[.](cpp|cxx|cc)\\Z',re.I).match\nfortran_ext_match = re.compile(r'.*[.](f90|f95|f77|for|ftn|f)\\Z',re.I).match\nf90_ext_match = re.compile(r'.*[.](f90|f95)\\Z',re.I).match\nf90_module_name_match = re.compile(r'\\s*module\\s*(?P[\\w_]+)',re.I).match\ndef _get_f90_modules(source):\n \"\"\" Return a list of Fortran f90 module names that\n given source file defines.\n \"\"\"\n if not f90_ext_match(source):\n return []\n modules = []\n f = open(source,'r')\n f_readlines = getattr(f,'xreadlines',f.readlines)\n for line in f_readlines():\n m = f90_module_name_match(line)\n if m:\n name = m.group('name')\n modules.append(name)\n # break # XXX can we assume that there is one module per file?\n f.close()\n return modules\n\ndef is_string(s):\n return isinstance(s, str)\n\ndef all_strings(lst):\n \"\"\" Return True if all items in lst are string objects. \"\"\"\n for item in lst:\n if not is_string(item):\n return False\n return True\n\ndef is_sequence(seq):\n if is_string(seq):\n return False\n try:\n len(seq)\n except:\n return False\n return True\n\ndef has_f_sources(sources):\n \"\"\" Return True if sources contains Fortran files \"\"\"\n for source in sources:\n if fortran_ext_match(source):\n return True\n return False\n\ndef has_cxx_sources(sources):\n \"\"\" Return True if sources contains C++ files \"\"\"\n for source in sources:\n if cxx_ext_match(source):\n return True\n return False\n\ndef filter_sources(sources):\n \"\"\" Return four lists of filenames containing\n C, C++, Fortran, and Fortran 90 module sources,\n respectively.\n \"\"\"\n c_sources = []\n cxx_sources = []\n f_sources = []\n fmodule_sources = []\n for source in sources:\n if fortran_ext_match(source):\n modules = _get_f90_modules(source)\n if modules:\n fmodule_sources.append(source)\n else:\n f_sources.append(source)\n elif cxx_ext_match(source):\n cxx_sources.append(source)\n else:\n c_sources.append(source)\n return c_sources, cxx_sources, f_sources, fmodule_sources\n\n\ndef _get_headers(directory_list):\n # get *.h files from list of directories\n headers = []\n for dir in directory_list:\n head = glob.glob(os.path.join(dir,\"*.h\")) #XXX: *.hpp files??\n headers.extend(head)\n return headers\n\ndef _get_directories(list_of_sources):\n # get unique directories from list of sources.\n direcs = []\n for file in list_of_sources:\n dir = os.path.split(file)\n if dir[0] != '' and not dir[0] in direcs:\n direcs.append(dir[0])\n return direcs\n\ndef get_dependencies(sources):\n #XXX scan sources for include statements\n return _get_headers(_get_directories(sources))\n\ndef is_local_src_dir(directory):\n \"\"\" Return true if directory is local directory.\n \"\"\"\n if not is_string(directory):\n return False\n abs_dir = os.path.abspath(directory)\n c = os.path.commonprefix([os.getcwd(),abs_dir])\n new_dir = abs_dir[len(c):].split(os.sep)\n if new_dir and not new_dir[0]:\n new_dir = new_dir[1:]\n if new_dir and new_dir[0]=='build':\n return False\n new_dir = os.sep.join(new_dir)\n return os.path.isdir(new_dir)\n\ndef _gsf_visit_func(filenames,dirname,names):\n if os.path.basename(dirname) in ['CVS','.svn','build']:\n names[:] = []\n return\n for name in names:\n if name[-1] in \"~#\":\n continue\n fullname = os.path.join(dirname,name)\n ext = os.path.splitext(fullname)[1]\n if ext and ext in ['.pyc','.o']:\n continue\n if os.path.isfile(fullname):\n filenames.append(fullname)\n\ndef get_ext_source_files(ext):\n # Get sources and any include files in the same directory.\n filenames = []\n sources = filter(is_string, ext.sources)\n filenames.extend(sources)\n filenames.extend(get_dependencies(sources))\n for d in ext.depends:\n if is_local_src_dir(d):\n os.path.walk(d,_gsf_visit_func,filenames)\n elif os.path.isfile(d):\n filenames.append(d)\n return filenames\n\ndef get_script_files(scripts):\n scripts = filter(is_string, scripts)\n return scripts\n\ndef get_lib_source_files(lib):\n filenames = []\n sources = lib[1].get('sources',[])\n sources = filter(is_string, sources)\n filenames.extend(sources)\n filenames.extend(get_dependencies(sources))\n depends = lib[1].get('depends',[])\n for d in depends:\n if is_local_src_dir(d):\n os.path.walk(d,_gsf_visit_func,filenames)\n elif os.path.isfile(d):\n filenames.append(d)\n return filenames\n\ndef get_data_files(data):\n if is_string(data):\n return [data]\n sources = data[1]\n filenames = []\n for s in sources:\n if callable(s):\n continue\n if is_local_src_dir(s):\n os.path.walk(s,_gsf_visit_func,filenames)\n elif is_string(s):\n if os.path.isfile(s):\n filenames.append(s)\n else:\n print 'Not existing data file:',s\n else:\n raise TypeError,repr(s)\n return filenames\n\ndef dot_join(*args):\n return '.'.join(filter(None,args))\n\ndef get_frame(level=0):\n try:\n return sys._getframe(level+1)\n except AttributeError:\n frame = sys.exc_info()[2].tb_frame\n for i in range(level+1):\n frame = frame.f_back\n return frame\n\n######################\n\ndef command_line_ok(_cache=[]):\n \"\"\" Return True if command line does not contain any\n help or display requests.\n \"\"\"\n if _cache:\n return _cache[0]\n ok = True\n from distutils.dist import Distribution\n display_opts = ['--'+n for n in Distribution.display_option_names]\n for o in Distribution.display_options:\n if o[1]: display_opts.append('-'+o[1])\n for arg in sys.argv:\n if arg.startswith('--help') or arg=='-h' or arg in display_opts:\n ok = False\n break\n _cache.append(ok)\n return ok\n\nclass Configuration:\n\n _list_keys = ['packages','ext_modules','data_files','include_dirs',\n 'libraries','headers','scripts','py_modules']\n _dict_keys = ['package_dir']\n\n numpy_include_dirs = []\n\n def __init__(self,\n package_name=None,\n parent_name=None,\n top_path=None,\n package_path=None,\n **attrs):\n \"\"\" Construct configuration instance of a package.\n\n package_name -- name of the package\n Ex.: 'distutils'\n parent_name -- name of the parent package\n Ex.: 'numpy'\n top_path -- directory of the toplevel package\n Ex.: the directory where the numpy package source sits\n package_path -- directory of package. Will be computed by magic from the\n directory of the caller module if not specified\n Ex.: the directory where numpy.distutils is\n \"\"\"\n self.name = dot_join(parent_name, package_name)\n\n caller_frame = get_frame(1)\n caller_name = eval('__name__',caller_frame.f_globals,caller_frame.f_locals)\n\n self.local_path = get_path(caller_name, top_path)\n if top_path is None:\n top_path = self.local_path\n if package_path is None:\n package_path = self.local_path\n elif os.path.isdir(njoin(self.local_path,package_path)):\n package_path = njoin(self.local_path,package_path)\n if not os.path.isdir(package_path):\n raise ValueError(\"%r is not a directory\" % (package_path,))\n self.top_path = top_path\n self.package_path = package_path\n # this is the relative path in the installed package\n self.path_in_package = os.path.join(*self.name.split('.'))\n\n self.list_keys = copy.copy(self._list_keys)\n self.dict_keys = copy.copy(self._dict_keys)\n\n for n in self.list_keys:\n setattr(self,n,copy.copy(attrs.get(n,[])))\n\n for n in self.dict_keys:\n setattr(self,n,copy.copy(attrs.get(n,{})))\n\n known_keys = self.list_keys + self.dict_keys\n self.extra_keys = []\n for n in attrs.keys():\n if n in known_keys:\n continue\n a = attrs[n]\n setattr(self,n,a)\n if isinstance(a, list):\n self.list_keys.append(n)\n elif isinstance(a, dict):\n self.dict_keys.append(n)\n else:\n self.extra_keys.append(n)\n\n if os.path.exists(njoin(package_path,'__init__.py')):\n self.packages.append(self.name)\n self.package_dir[self.name] = package_path\n\n return\n\n def todict(self):\n \"\"\" Return configuration distionary suitable for passing\n to distutils.core.setup() function.\n \"\"\"\n d = {}\n for n in self.list_keys + self.dict_keys + self.extra_keys:\n a = getattr(self,n)\n if a:\n d[n] = a\n if self.name:\n d['name'] = self.name\n return d\n\n def info(self, message):\n print message\n\n def warn(self, message):\n print>>sys.stderr, 'Warning:',message\n\n def __dict__(self):\n return self.todict()\n\n def get_distribution(self):\n import distutils.core\n dist = distutils.core._setup_distribution\n return dist\n\n def get_subpackage(self,subpackage_name,subpackage_path=None):\n \"\"\" Return subpackage configuration.\n \"\"\"\n if subpackage_name is None:\n assert subpackage_path is not None\n subpackage_name = os.path.basename(subpackage_path)\n l = subpackage_name.split('.')\n if subpackage_path is None:\n subpackage_path = njoin(*([self.local_path]+l))\n if '*' in subpackage_name:\n dirs = filter(os.path.isdir,glob.glob(subpackage_path))\n config_list = []\n for d in dirs:\n if not os.path.isfile(njoin(d,'__init__.py')):\n continue\n if 'build' in d.split(os.sep):\n continue\n n = '.'.join(d.split(os.sep)[-len(l):])\n c = self.get_subpackage(n)\n if c:\n config_list.append(c)\n return config_list\n else:\n subpackage_path = njoin(*([subpackage_path]+l[:-1]))\n subpackage_path = self._fix_paths([subpackage_path])[0]\n setup_py = njoin(subpackage_path,'setup.py')\n if not os.path.isfile(setup_py):\n setup_py = njoin(subpackage_path,'setup_%s.py' % (subpackage_name))\n\n if not os.path.isfile(setup_py):\n print 'Assuming default configuration '\\\n '(%s/{setup_%s,setup}.py was not found)' \\\n % (os.path.dirname(setup_py),subpackage_name)\n config = Configuration(subpackage_name,self.name,\n self.top_path,subpackage_path)\n else:\n # In case setup_py imports local modules:\n sys.path.insert(0,os.path.dirname(setup_py))\n try:\n info = (open(setup_py),setup_py,('.py','U',1))\n setup_name = os.path.splitext(os.path.basename(setup_py))[0]\n n = dot_join(self.name,setup_name)\n setup_module = imp.load_module('_'.join(n.split('.')),*info)\n\n if not hasattr(setup_module,'configuration'):\n print 'Assuming default configuration '\\\n '(%s does not define configuration())' % (setup_module)\n config = Configuration(subpackage_name,self.name,\n self.top_path,subpackage_path)\n else:\n args = (self.name,)\n if setup_module.configuration.func_code.co_argcount>1:\n args = args + (self.top_path,)\n config = setup_module.configuration(*args)\n\n finally:\n del sys.path[0]\n\n return config\n\n def add_subpackage(self,subpackage_name,subpackage_path=None):\n \"\"\" Add subpackage to configuration.\n \"\"\"\n config = self.get_subpackage(subpackage_name,subpackage_path)\n if not isinstance(config, list):\n config_list = [config]\n else:\n config_list = config\n for config in config_list:\n if not config:\n print 'No configuration returned, assuming unavailable.'\n else:\n if isinstance(config,Configuration):\n print 'Appending %s configuration to %s' % (config.name,self.name)\n self.dict_append(**config.todict())\n else:\n print 'Appending %s configuration to %s' % (config.get('name'),self.name)\n self.dict_append(**config)\n\n dist = self.get_distribution()\n if dist is not None:\n print 'distutils distribution has been initialized, it may be too late to add a subpackage', subpackage_name\n return\n\n def add_data_dir(self,data_path):\n \"\"\" Recursively add files under data_path to data_files list.\n Argument can be either\n - 2-sequence (,)\n - path to data directory where python datadir suffix defaults\n to package dir.\n If path is not absolute then it's datadir suffix is\n package dir + subdirname of the path.\n \"\"\"\n if is_sequence(data_path):\n d, data_path = data_path\n else:\n d = None\n if not is_string(data_path):\n raise TypeError(\"not a string: %r\" % (data_path,))\n for path in self.paths(data_path):\n if not os.path.exists(path):\n print 'Not existing data path',path\n continue\n filenames = []\n os.path.walk(path, _gsf_visit_func,filenames)\n if not os.path.isabs(path):\n npath = data_path\n if '*' in npath:\n npath = os.path.join(*(path.split(os.sep)[-len(npath.split(os.sep)):]))\n if d is None:\n d = self.path_in_package\n ds = os.path.join(d, npath)\n self.add_data_files((ds,filenames))\n else:\n if d is None:\n self.add_data_files(*filenames)\n else:\n self.add_data_files((d,filenames))\n return\n\n def add_data_files(self,*files):\n \"\"\" Add data files to configuration data_files.\n Argument(s) can be either\n - 2-sequence (,)\n - paths to data files where python datadir prefix defaults\n to package dir.\n If path is not absolute then it's datadir prefix is\n package dir + dirname of the path.\n \"\"\"\n data_dict = {}\n new_files = []\n for p in files:\n if not is_sequence(p):\n d = self.path_in_package\n if is_string(p) and not os.path.isabs(p):\n pd = os.path.dirname(p)\n if '*' in pd:\n pn = os.path.basename(p)\n n = len(pd.split(os.sep))\n for d1 in filter(os.path.isdir,self.paths(pd)):\n p = os.path.join(d1,pn)\n d1 = os.sep.join(d1.split(os.sep)[-n:])\n new_files.append((appendpath(d,d1),p))\n continue\n d = appendpath(d,pd)\n p = (d,p) \n new_files.append(p)\n \n files = []\n for prefix,filepattern in new_files:\n assert '*' not in prefix,`prefix,filepattern`\n if is_string(filepattern):\n file_list = self.paths(filepattern,include_non_existing=False)\n elif callable(filepattern):\n file_list = [filepattern]\n else:\n file_list = self.paths(*filepattern)\n\n nof_path_components = [len(f.split(os.sep))\n for f in file_list if is_string(f)]\n if nof_path_components:\n min_path_components = min(nof_path_components)-1\n else:\n min_path_components = 0\n\n for f in file_list:\n if is_string(f):\n extra_path_components = f.split(os.sep)[min_path_components:-1]\n p = njoin(*([prefix]+extra_path_components))\n else:\n p = prefix\n if not data_dict.has_key(p):\n data_dict[p] = [f]\n else:\n data_dict[p].append(f)\n\n dist = self.get_distribution()\n if dist is not None:\n dist.data_files.extend(data_dict.items())\n else:\n self.data_files.extend(data_dict.items())\n\n ### XXX Implement add_py_modules\n\n def add_include_dirs(self,*paths):\n \"\"\" Add paths to configuration include directories.\n \"\"\"\n include_dirs = self._fix_paths(paths)\n dist = self.get_distribution()\n if dist is not None:\n dist.include_dirs.extend(include_dirs)\n else:\n self.include_dirs.extend(include_dirs)\n return\n\n def add_headers(self,*files):\n \"\"\" Add installable headers to configuration.\n Argument(s) can be either\n - 2-sequence (,)\n - path(s) to header file(s) where python includedir suffix will default\n to package name.\n \"\"\"\n headers = []\n for path in files:\n if is_string(path):\n [headers.append((self.name,p)) for p in self.paths(path)]\n else:\n if not isinstance(path, (tuple, list)) or len(path) != 2:\n raise TypeError(repr(path))\n [headers.append((path[0],p)) for p in self.paths(path[1])]\n dist = self.get_distribution()\n if dist is not None:\n dist.headers.extend(headers)\n else:\n self.headers.extend(headers)\n return\n\n def _fix_paths(self,paths,include_non_existing=True):\n assert isinstance(paths,(list,tuple)),`type(paths)`\n new_paths = []\n for n in paths:\n if isinstance(n,str):\n if '*' in n or '?' in n:\n p = glob.glob(n)\n p2 = glob.glob(njoin(self.local_path,n))\n if p2:\n new_paths.extend(p2)\n elif p:\n new_paths.extend(p)\n else:\n if include_non_existing:\n new_paths.append(n)\n self.warn('could not resolve pattern: %r' % (n))\n else:\n n2 = njoin(self.local_path,n)\n if os.path.exists(n2):\n new_paths.append(n2)\n else:\n if os.path.exists(n):\n new_paths.append(n)\n elif include_non_existing:\n new_paths.append(n)\n if not os.path.exists(n):\n self.warn('not existing path: %r' % (n))\n else:\n new_paths.append(n)\n return map(minrelpath,new_paths)\n\n def paths(self,*paths,**kws):\n \"\"\" Apply glob to paths and prepend local_path if needed.\n \"\"\"\n include_non_existing = kws.get('include_non_existing',True)\n return self._fix_paths(paths,\n include_non_existing=include_non_existing)\n\n def add_extension(self,name,sources,**kw):\n \"\"\" Add extension to configuration.\n\n Keywords:\n include_dirs, define_macros, undef_macros,\n library_dirs, libraries, runtime_library_dirs,\n extra_objects, extra_compile_args, extra_link_args,\n export_symbols, swig_opts, depends, language,\n f2py_options, module_dirs\n extra_info - dict or list of dict of keywords to be\n appended to keywords.\n \"\"\"\n ext_args = copy.copy(kw)\n ext_args['name'] = dot_join(self.name,name)\n ext_args['sources'] = sources\n\n if ext_args.has_key('extra_info'):\n extra_info = ext_args['extra_info']\n del ext_args['extra_info']\n if type(extra_info) is type({}):\n extra_info = [extra_info]\n for info in extra_info:\n assert type(info) is type({}),`info`\n dict_append(ext_args,**info)\n\n for k in ext_args.keys():\n v = ext_args[k]\n if k in ['sources','depends','include_dirs','library_dirs',\n 'module_dirs','extra_objects']:\n new_v = self._fix_paths(v)\n ext_args[k] = new_v\n\n # Resolve out-of-tree dependencies\n libraries = ext_args.get('libraries',[])\n libnames = []\n ext_args['libraries'] = []\n for libname in libraries:\n if '@' in libname:\n lname,lpath = libname.split('@',1)\n lpath = os.path.abspath(njoin(self.local_path,lpath))\n if os.path.isdir(lpath):\n c = self.get_subpackage(None,lpath)\n if isinstance(c,Configuration):\n c = c.todict()\n for l in [l[0] for l in c.get('libraries',[])]:\n llname = l.split('__OF__',1)[0]\n if llname == lname:\n c.pop('name',None)\n dict_append(ext_args,**c)\n break\n continue\n libnames.append(libname)\n\n ext_args['libraries'] = libnames + ext_args['libraries']\n\n from numpy.distutils.core import Extension\n ext = Extension(**ext_args)\n self.ext_modules.append(ext)\n\n dist = self.get_distribution()\n if dist is not None:\n print 'distutils distribution has been initialized, it may be too late to add an extension', name\n return ext\n\n def add_library(self,name,sources,**build_info):\n \"\"\" Add library to configuration.\n\n Valid keywords for build_info:\n depends\n macros\n include_dirs\n extra_compiler_args\n f2py_options\n \"\"\"\n build_info = copy.copy(build_info)\n name = name #+ '__OF__' + self.name\n build_info['sources'] = sources\n\n for k in build_info.keys():\n v = build_info[k]\n if k in ['sources','depends','include_dirs','library_dirs',\n 'module_dirs','extra_objects']:\n new_v = self._fix_paths(v)\n build_info[k] = new_v\n self.libraries.append((name,build_info))\n\n dist = self.get_distribution()\n if dist is not None:\n print 'distutils distribution has been initialized, it may be too late to add a library', name\n return\n\n def add_scripts(self,*files):\n \"\"\" Add scripts to configuration.\n \"\"\"\n scripts = self._fix_paths(files)\n dist = self.get_distribution()\n if dist is not None:\n dist.scripts.extend(scripts)\n else:\n self.scripts.extend(scripts)\n return\n\n def dict_append(self,**dict):\n for key in self.list_keys:\n a = getattr(self,key)\n a.extend(dict.get(key,[]))\n for key in self.dict_keys:\n a = getattr(self,key)\n a.update(dict.get(key,{}))\n known_keys = self.list_keys + self.dict_keys + self.extra_keys\n for key in dict.keys():\n if key not in known_keys and not hasattr(self,key):\n if key not in ['version']:\n self.warn('Inheriting attribute %r from %r' \\\n % (key,dict.get('name','?')))\n setattr(self,key,dict[key])\n self.extra_keys.append(key)\n return\n\n def __str__(self):\n known_keys = self.list_keys + self.dict_keys + self.extra_keys\n s = '<'+5*'-' + '\\n'\n s += 'Configuration of '+self.name+':\\n'\n for k in known_keys:\n a = getattr(self,k,None)\n if a:\n s += '%s = %r\\n' % (k,a)\n s += 5*'-' + '>'\n return s\n\n def get_config_cmd(self):\n cmd = get_cmd('config')\n cmd.ensure_finalized()\n cmd.dump_source = 0\n cmd.noisy = 0\n old_path = os.environ.get('PATH')\n if old_path:\n path = os.pathsep.join(['.',old_path])\n os.environ['PATH'] = path\n return cmd\n\n def get_build_temp_dir(self):\n cmd = get_cmd('build')\n cmd.ensure_finalized()\n return cmd.build_temp\n\n def have_f77c(self):\n \"\"\" Check for availability of Fortran 77 compiler.\n Use it inside source generating function to ensure that\n setup distribution instance has been initialized.\n \"\"\"\n simple_fortran_subroutine = '''\n subroutine simple\n end\n '''\n config_cmd = self.get_config_cmd()\n flag = config_cmd.try_compile(simple_fortran_subroutine,lang='f77')\n return flag\n\n def have_f90c(self):\n \"\"\" Check for availability of Fortran 90 compiler.\n Use it inside source generating function to ensure that\n setup distribution instance has been initialized.\n \"\"\"\n simple_fortran_subroutine = '''\n subroutine simple\n end\n '''\n config_cmd = self.get_config_cmd()\n flag = config_cmd.try_compile(simple_fortran_subroutine,lang='f90')\n return flag\n\n def append_to(self, extlib):\n \"\"\" Append libraries, include_dirs to extension or library item.\n \"\"\"\n if is_sequence(extlib):\n lib_name, build_info = extlib\n dict_append(build_info,\n libraries=self.libraries,\n include_dirs=self.include_dirs)\n else:\n from numpy.distutils.core import Extension\n assert isinstance(extlib,Extension),`extlib`\n extlib.libraries.extend(self.libraries)\n extlib.include_dirs.extend(self.include_dirs)\n return\n\n def _get_svn_revision(self,path):\n \"\"\" Return path's SVN revision number.\n \"\"\"\n entries = njoin(path,'.svn','entries')\n revision = None\n if os.path.isfile(entries):\n f = open(entries)\n m = re.search(r'revision=\"(?P\\d+)\"',f.read())\n f.close()\n if m:\n revision = int(m.group('revision'))\n return revision\n\n def get_version(self):\n \"\"\" Try to get version string of a package.\n \"\"\"\n version = getattr(self,'version',None)\n if version is not None:\n return version\n\n # Get version from version file.\n files = ['__version__.py',\n self.name.split('.')[-1]+'_version.py',\n 'version.py',\n '__svn_version__.py']\n version_vars = ['version',\n '__version__',\n self.name.split('.')[-1]+'_version']\n for f in files:\n fn = njoin(self.local_path,f)\n if os.path.isfile(fn):\n info = (open(fn),fn,('.py','U',1))\n name = os.path.splitext(os.path.basename(fn))[0]\n n = dot_join(self.name,name)\n try:\n version_module = imp.load_module('_'.join(n.split('.')),*info)\n except ImportError,msg:\n print msg\n version_module = None\n if version_module is None:\n continue\n\n for a in version_vars:\n version = getattr(version_module,a,None)\n if version is not None:\n break\n if version is not None:\n break\n\n if version is not None:\n self.version = version\n return version\n\n # Get version as SVN revision number\n revision = self._get_svn_revision(self.local_path)\n if revision is not None:\n version = str(revision)\n self.version = version\n\n return version\n\n def make_svn_version_py(self):\n \"\"\" Generate package __svn_version__.py file from SVN revision number,\n it will be removed after python exits but will be available\n when sdist, etc commands are executed.\n\n If __svn_version__.py existed before, nothing is done.\n \"\"\"\n target = njoin(self.local_path,'__svn_version__.py')\n if os.path.isfile(target):\n return\n\n def generate_svn_version_py():\n if not os.path.isfile(target):\n revision = self._get_svn_revision(self.local_path)\n assert revision is not None,'hmm, why I am not inside SVN tree???'\n version = str(revision)\n print 'Creating %s (version=%r)' % (target,version)\n f = open(target,'w')\n f.write('version = %r\\n' % (version))\n f.close()\n\n import atexit\n def rm_file(f=target):\n try: os.remove(f); print 'removed',f\n except OSError: pass\n try: os.remove(f+'c'); print 'removed',f+'c'\n except OSError: pass\n atexit.register(rm_file)\n\n return target\n\n self.add_data_files((self.path_in_package, generate_svn_version_py()))\n return\n\n def make_config_py(self,name='__config__'):\n \"\"\" Generate package __config__.py file containing system_info\n information used during building the package.\n \"\"\"\n self.py_modules.append((self.name,name,generate_config_py))\n return\n\n def get_info(self,*names):\n \"\"\" Get resources information.\n \"\"\"\n from system_info import get_info, dict_append\n info_dict = {}\n for a in names:\n dict_append(info_dict,**get_info(a))\n return info_dict\n\n if not command_line_ok():\n _do_nothing = lambda *args,**kws: None\n add_subpackage = _do_nothing\n add_extension = _do_nothing\n add_library = _do_nothing\n add_data_dir = _do_nothing\n add_data_files = _do_nothing\n add_scripts = _do_nothing\n add_headers = _do_nothing\n add_include_dirs = _do_nothing\n make_config_py = _do_nothing\n get_info = lambda *args,**kws:{}\n have_f77c = lambda *args,**kws: False\n have_f90c = lambda *args,**kws: False\n\ndef get_cmd(cmdname,_cache={}):\n if not _cache.has_key(cmdname):\n import distutils.core\n dist = distutils.core._setup_distribution\n if dist is None:\n from distutils.errors import DistutilsInternalError\n raise DistutilsInternalError,\\\n 'setup distribution instance not initialized'\n cmd = dist.get_command_obj(cmdname)\n _cache[cmdname] = cmd\n return _cache[cmdname]\n\ndef get_numpy_include_dirs():\n # numpy_include_dirs are set by numpy/core/setup.py, otherwise []\n include_dirs = Configuration.numpy_include_dirs[:]\n if not include_dirs:\n import numpy\n if numpy.show_config is None:\n # running from numpy_core source directory\n include_dirs.append(njoin(os.path.dirname(numpy.__file__),\n 'core','include'))\n else:\n # using installed numpy core headers\n import numpy.core as core\n include_dirs.append(njoin(os.path.dirname(core.__file__),'include'))\n # else running numpy/core/setup.py\n return include_dirs\n\n#########################\n\ndef default_config_dict(name = None, parent_name = None, local_path=None):\n \"\"\" Return a configuration dictionary for usage in\n configuration() function defined in file setup_.py.\n \"\"\"\n import warnings\n warnings.warn('Use Configuration(%s,%s,top_path=%s) instead of '\\\n 'deprecated default_config_dict(%s,%s,%s)' \\\n % (`name`,`parent_name`,`local_path`,\n `name`,`parent_name`,`local_path`,\n ))\n c = Configuration(name, parent_name, local_path)\n return c.todict()\n\n\ndef dict_append(d,**kws):\n for k,v in kws.items():\n if d.has_key(k):\n d[k].extend(v)\n else:\n d[k] = v\n\ndef appendpath(prefix,path):\n if not ('/' == os.path.sep):\n prefix = prefix.replace('/',os.path.sep)\n path = path.replace('/',os.path.sep)\n drive = ''\n if os.path.isabs(path):\n drive = os.path.splitdrive(prefix)[0]\n absprefix = os.path.splitdrive(os.path.abspath(prefix))[1]\n pathdrive,path = os.path.splitdrive(path)\n d = os.path.commonprefix([absprefix,path])\n if os.path.join(absprefix[:len(d)],absprefix[len(d):])!=absprefix \\\n or os.path.join(path[:len(d)],path[len(d):])!=path:\n # Handle invalid paths\n d = os.path.dirname(d)\n subpath = path[len(d):]\n if os.path.isabs(subpath):\n subpath = subpath[1:]\n else:\n subpath = path\n return os.path.normpath(njoin(drive + prefix, subpath))\n\n\n\n\n\ndef generate_config_py(target):\n \"\"\" Generate config.py file containing system_info information\n used during building the package.\n\n Usage:\\\n config['py_modules'].append((packagename, '__config__',generate_config_py))\n \"\"\"\n from numpy.distutils.system_info import system_info\n from distutils.dir_util import mkpath\n mkpath(os.path.dirname(target))\n f = open(target,'w')\n f.write('# This file is generated by %s\\n' % (os.path.abspath(sys.argv[0])))\n f.write('# It contains system_info results at the time of building this package.\\n')\n f.write('__all__ = [\"get_info\",\"show\"]\\n\\n')\n for k,i in system_info.saved_results.items():\n f.write('%s=%r\\n' % (k,i))\n f.write('\\ndef get_info(name): g=globals(); return g.get(name,g.get(name+\"_info\",{}))\\n')\n f.write('''\ndef show():\n for name,info_dict in globals().items():\n if name[0]==\"_\" or type(info_dict) is not type({}): continue\n print name+\":\"\n if not info_dict:\n print \" NOT AVAILABLE\"\n for k,v in info_dict.items():\n v = str(v)\n if k==\\'sources\\' and len(v)>200: v = v[:60]+\\' ...\\\\n... \\'+v[-60:]\n print \\' %s = %s\\'%(k,v)\n print\n return\n ''')\n\n f.close()\n return target\n\ndef generate_svn_version_py(extension, build_dir):\n \"\"\" Generate __svn_version__.py file containing SVN\n revision number of a module.\n\n To use, add the following codelet to setup\n configuration(..) function\n\n ext = Extension(dot_join(config['name'],'__svn_version__'),\n sources=[generate_svn_version_py])\n ext.local_path = local_path\n config['ext_modules'].append(ext)\n\n \"\"\"\n from distutils import dep_util\n local_path = extension.local_path\n target = njoin(build_dir, '__svn_version__.py')\n entries = njoin(local_path,'.svn','entries')\n if os.path.isfile(entries):\n if not dep_util.newer(entries, target):\n return target\n elif os.path.isfile(target):\n return target\n\n revision = get_svn_revision(local_path)\n f = open(target,'w')\n f.write('revision=%s\\n' % (revision))\n f.close()\n return target\n", + "methods": [ + { + "name": "allpath", + "long_name": "allpath( name )", + "filename": "misc_util.py", + "nloc": 4, + "complexity": 1, + "token_count": 24, + "parameters": [ + "name" + ], + "start_line": 18, + "end_line": 21, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 4, + "top_nesting_level": 0 + }, + { + "name": "get_path", + "long_name": "get_path( mod_name , parent_path = None )", + "filename": "misc_util.py", + "nloc": 15, + "complexity": 6, + "token_count": 132, + "parameters": [ + "mod_name", + "parent_path" + ], + "start_line": 23, + "end_line": 43, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 21, + "top_nesting_level": 0 + }, + { + "name": "njoin", + "long_name": "njoin( * path )", + "filename": "misc_util.py", + "nloc": 7, + "complexity": 4, + "token_count": 68, + "parameters": [ + "path" + ], + "start_line": 45, + "end_line": 55, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 11, + "top_nesting_level": 0 + }, + { + "name": "minrelpath", + "long_name": "minrelpath( path )", + "filename": "misc_util.py", + "nloc": 17, + "complexity": 7, + "token_count": 103, + "parameters": [ + "path" + ], + "start_line": 57, + "end_line": 75, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 19, + "top_nesting_level": 0 + }, + { + "name": "terminal_has_colors", + "long_name": "terminal_has_colors( )", + "filename": "misc_util.py", + "nloc": 18, + "complexity": 13, + "token_count": 137, + "parameters": [], + "start_line": 79, + "end_line": 104, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 26, + "top_nesting_level": 0 + }, + { + "name": "cyg2win32", + "long_name": "cyg2win32( path )", + "filename": "misc_util.py", + "nloc": 4, + "complexity": 3, + "token_count": 42, + "parameters": [ + "path" + ], + "start_line": 121, + "end_line": 124, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 4, + "top_nesting_level": 0 + }, + { + "name": "_get_f90_modules", + "long_name": "_get_f90_modules( source )", + "filename": "misc_util.py", + "nloc": 13, + "complexity": 4, + "token_count": 77, + "parameters": [ + "source" + ], + "start_line": 133, + "end_line": 149, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 17, + "top_nesting_level": 0 + }, + { + "name": "is_string", + "long_name": "is_string( s )", + "filename": "misc_util.py", + "nloc": 2, + "complexity": 1, + "token_count": 12, + "parameters": [ + "s" + ], + "start_line": 151, + "end_line": 152, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 2, + "top_nesting_level": 0 + }, + { + "name": "all_strings", + "long_name": "all_strings( lst )", + "filename": "misc_util.py", + "nloc": 5, + "complexity": 3, + "token_count": 22, + "parameters": [ + "lst" + ], + "start_line": 154, + "end_line": 159, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 6, + "top_nesting_level": 0 + }, + { + "name": "is_sequence", + "long_name": "is_sequence( seq )", + "filename": "misc_util.py", + "nloc": 8, + "complexity": 3, + "token_count": 25, + "parameters": [ + "seq" + ], + "start_line": 161, + "end_line": 168, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 8, + "top_nesting_level": 0 + }, + { + "name": "has_f_sources", + "long_name": "has_f_sources( sources )", + "filename": "misc_util.py", + "nloc": 5, + "complexity": 3, + "token_count": 21, + "parameters": [ + "sources" + ], + "start_line": 170, + "end_line": 175, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 6, + "top_nesting_level": 0 + }, + { + "name": "has_cxx_sources", + "long_name": "has_cxx_sources( sources )", + "filename": "misc_util.py", + "nloc": 5, + "complexity": 3, + "token_count": 21, + "parameters": [ + "sources" + ], + "start_line": 177, + "end_line": 182, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 6, + "top_nesting_level": 0 + }, + { + "name": "filter_sources", + "long_name": "filter_sources( sources )", + "filename": "misc_util.py", + "nloc": 17, + "complexity": 5, + "token_count": 84, + "parameters": [ + "sources" + ], + "start_line": 184, + "end_line": 204, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 21, + "top_nesting_level": 0 + }, + { + "name": "_get_headers", + "long_name": "_get_headers( directory_list )", + "filename": "misc_util.py", + "nloc": 6, + "complexity": 2, + "token_count": 39, + "parameters": [ + "directory_list" + ], + "start_line": 207, + "end_line": 213, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 7, + "top_nesting_level": 0 + }, + { + "name": "_get_directories", + "long_name": "_get_directories( list_of_sources )", + "filename": "misc_util.py", + "nloc": 7, + "complexity": 4, + "token_count": 51, + "parameters": [ + "list_of_sources" + ], + "start_line": 215, + "end_line": 222, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 8, + "top_nesting_level": 0 + }, + { + "name": "get_dependencies", + "long_name": "get_dependencies( sources )", + "filename": "misc_util.py", + "nloc": 2, + "complexity": 1, + "token_count": 13, + "parameters": [ + "sources" + ], + "start_line": 224, + "end_line": 226, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 3, + "top_nesting_level": 0 + }, + { + "name": "is_local_src_dir", + "long_name": "is_local_src_dir( directory )", + "filename": "misc_util.py", + "nloc": 12, + "complexity": 6, + "token_count": 107, + "parameters": [ + "directory" + ], + "start_line": 228, + "end_line": 241, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 14, + "top_nesting_level": 0 + }, + { + "name": "_gsf_visit_func", + "long_name": "_gsf_visit_func( filenames , dirname , names )", + "filename": "misc_util.py", + "nloc": 13, + "complexity": 7, + "token_count": 103, + "parameters": [ + "filenames", + "dirname", + "names" + ], + "start_line": 243, + "end_line": 255, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 13, + "top_nesting_level": 0 + }, + { + "name": "get_ext_source_files", + "long_name": "get_ext_source_files( ext )", + "filename": "misc_util.py", + "nloc": 11, + "complexity": 4, + "token_count": 77, + "parameters": [ + "ext" + ], + "start_line": 257, + "end_line": 268, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 12, + "top_nesting_level": 0 + }, + { + "name": "get_script_files", + "long_name": "get_script_files( scripts )", + "filename": "misc_util.py", + "nloc": 3, + "complexity": 1, + "token_count": 15, + "parameters": [ + "scripts" + ], + "start_line": 270, + "end_line": 272, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 3, + "top_nesting_level": 0 + }, + { + "name": "get_lib_source_files", + "long_name": "get_lib_source_files( lib )", + "filename": "misc_util.py", + "nloc": 13, + "complexity": 4, + "token_count": 101, + "parameters": [ + "lib" + ], + "start_line": 274, + "end_line": 286, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 13, + "top_nesting_level": 0 + }, + { + "name": "get_data_files", + "long_name": "get_data_files( data )", + "filename": "misc_util.py", + "nloc": 18, + "complexity": 7, + "token_count": 94, + "parameters": [ + "data" + ], + "start_line": 288, + "end_line": 305, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 18, + "top_nesting_level": 0 + }, + { + "name": "dot_join", + "long_name": "dot_join( * args )", + "filename": "misc_util.py", + "nloc": 2, + "complexity": 1, + "token_count": 18, + "parameters": [ + "args" + ], + "start_line": 307, + "end_line": 308, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 2, + "top_nesting_level": 0 + }, + { + "name": "get_frame", + "long_name": "get_frame( level = 0 )", + "filename": "misc_util.py", + "nloc": 8, + "complexity": 3, + "token_count": 50, + "parameters": [ + "level" + ], + "start_line": 310, + "end_line": 317, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 8, + "top_nesting_level": 0 + }, + { + "name": "command_line_ok", + "long_name": "command_line_ok( _cache = [ ] )", + "filename": "misc_util.py", + "nloc": 14, + "complexity": 9, + "token_count": 98, + "parameters": [ + "_cache" + ], + "start_line": 321, + "end_line": 337, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 17, + "top_nesting_level": 0 + }, + { + "name": "__init__", + "long_name": "__init__( self , package_name = None , parent_name = None , top_path = None , package_path = None , ** attrs )", + "filename": "misc_util.py", + "nloc": 60, + "complexity": 16, + "token_count": 455, + "parameters": [ + "self", + "package_name", + "parent_name", + "top_path", + "package_path", + "attrs" + ], + "start_line": 347, + "end_line": 429, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 83, + "top_nesting_level": 1 + }, + { + "name": "todict", + "long_name": "todict( self )", + "filename": "misc_util.py", + "nloc": 9, + "complexity": 4, + "token_count": 57, + "parameters": [ + "self" + ], + "start_line": 431, + "end_line": 442, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 12, + "top_nesting_level": 1 + }, + { + "name": "info", + "long_name": "info( self , message )", + "filename": "misc_util.py", + "nloc": 3, + "complexity": 2, + "token_count": 18, + "parameters": [ + "self", + "message" + ], + "start_line": 444, + "end_line": 446, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 3, + "top_nesting_level": 1 + }, + { + "name": "warn", + "long_name": "warn( self , message )", + "filename": "misc_util.py", + "nloc": 2, + "complexity": 1, + "token_count": 17, + "parameters": [ + "self", + "message" + ], + "start_line": 448, + "end_line": 449, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 2, + "top_nesting_level": 1 + }, + { + "name": "set_options", + "long_name": "set_options( self , ** options )", + "filename": "misc_util.py", + "nloc": 7, + "complexity": 3, + "token_count": 47, + "parameters": [ + "self", + "options" + ], + "start_line": 452, + "end_line": 466, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 15, + "top_nesting_level": 1 + }, + { + "name": "__dict__", + "long_name": "__dict__( self )", + "filename": "misc_util.py", + "nloc": 2, + "complexity": 1, + "token_count": 11, + "parameters": [ + "self" + ], + "start_line": 467, + "end_line": 468, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 2, + "top_nesting_level": 1 + }, + { + "name": "get_distribution", + "long_name": "get_distribution( self )", + "filename": "misc_util.py", + "nloc": 4, + "complexity": 1, + "token_count": 18, + "parameters": [ + "self" + ], + "start_line": 470, + "end_line": 473, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 4, + "top_nesting_level": 1 + }, + { + "name": "get_subpackage", + "long_name": "get_subpackage( self , subpackage_name , subpackage_path = None )", + "filename": "misc_util.py", + "nloc": 56, + "complexity": 16, + "token_count": 482, + "parameters": [ + "self", + "subpackage_name", + "subpackage_path" + ], + "start_line": 475, + "end_line": 538, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 64, + "top_nesting_level": 1 + }, + { + "name": "add_subpackage", + "long_name": "add_subpackage( self , subpackage_name , subpackage_path = None )", + "filename": "misc_util.py", + "nloc": 23, + "complexity": 6, + "token_count": 147, + "parameters": [ + "self", + "subpackage_name", + "subpackage_path" + ], + "start_line": 540, + "end_line": 565, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 26, + "top_nesting_level": 1 + }, + { + "name": "add_data_dir", + "long_name": "add_data_dir( self , data_path )", + "filename": "misc_util.py", + "nloc": 27, + "complexity": 9, + "token_count": 200, + "parameters": [ + "self", + "data_path" + ], + "start_line": 567, + "end_line": 601, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 35, + "top_nesting_level": 1 + }, + { + "name": "add_data_files", + "long_name": "add_data_files( self , * files )", + "filename": "misc_util.py", + "nloc": 49, + "complexity": 17, + "token_count": 392, + "parameters": [ + "self", + "files" + ], + "start_line": 603, + "end_line": 663, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 61, + "top_nesting_level": 1 + }, + { + "name": "add_include_dirs", + "long_name": "add_include_dirs( self , * paths )", + "filename": "misc_util.py", + "nloc": 8, + "complexity": 2, + "token_count": 49, + "parameters": [ + "self", + "paths" + ], + "start_line": 667, + "end_line": 676, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 10, + "top_nesting_level": 1 + }, + { + "name": "add_headers", + "long_name": "add_headers( self , * files )", + "filename": "misc_util.py", + "nloc": 15, + "complexity": 8, + "token_count": 136, + "parameters": [ + "self", + "files" + ], + "start_line": 678, + "end_line": 698, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 21, + "top_nesting_level": 1 + }, + { + "name": "_fix_paths", + "long_name": "_fix_paths( self , paths , include_non_existing = True )", + "filename": "misc_util.py", + "nloc": 30, + "complexity": 12, + "token_count": 208, + "parameters": [ + "self", + "paths", + "include_non_existing" + ], + "start_line": 700, + "end_line": 729, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 30, + "top_nesting_level": 1 + }, + { + "name": "paths", + "long_name": "paths( self , * paths , ** kws )", + "filename": "misc_util.py", + "nloc": 4, + "complexity": 1, + "token_count": 33, + "parameters": [ + "self", + "paths", + "kws" + ], + "start_line": 731, + "end_line": 736, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 6, + "top_nesting_level": 1 + }, + { + "name": "add_extension", + "long_name": "add_extension( self , name , sources , ** kw )", + "filename": "misc_util.py", + "nloc": 46, + "complexity": 14, + "token_count": 367, + "parameters": [ + "self", + "name", + "sources", + "kw" + ], + "start_line": 738, + "end_line": 801, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 64, + "top_nesting_level": 1 + }, + { + "name": "add_library", + "long_name": "add_library( self , name , sources , ** build_info )", + "filename": "misc_util.py", + "nloc": 16, + "complexity": 4, + "token_count": 112, + "parameters": [ + "self", + "name", + "sources", + "build_info" + ], + "start_line": 803, + "end_line": 829, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 27, + "top_nesting_level": 1 + }, + { + "name": "add_scripts", + "long_name": "add_scripts( self , * files )", + "filename": "misc_util.py", + "nloc": 8, + "complexity": 2, + "token_count": 49, + "parameters": [ + "self", + "files" + ], + "start_line": 831, + "end_line": 840, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 10, + "top_nesting_level": 1 + }, + { + "name": "dict_append", + "long_name": "dict_append( self , ** dict )", + "filename": "misc_util.py", + "nloc": 16, + "complexity": 7, + "token_count": 150, + "parameters": [ + "self", + "dict" + ], + "start_line": 842, + "end_line": 857, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 16, + "top_nesting_level": 1 + }, + { + "name": "__str__", + "long_name": "__str__( self )", + "filename": "misc_util.py", + "nloc": 10, + "complexity": 3, + "token_count": 72, + "parameters": [ + "self" + ], + "start_line": 859, + "end_line": 868, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 10, + "top_nesting_level": 1 + }, + { + "name": "get_config_cmd", + "long_name": "get_config_cmd( self )", + "filename": "misc_util.py", + "nloc": 10, + "complexity": 2, + "token_count": 63, + "parameters": [ + "self" + ], + "start_line": 870, + "end_line": 879, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 10, + "top_nesting_level": 1 + }, + { + "name": "get_build_temp_dir", + "long_name": "get_build_temp_dir( self )", + "filename": "misc_util.py", + "nloc": 4, + "complexity": 1, + "token_count": 20, + "parameters": [ + "self" + ], + "start_line": 881, + "end_line": 884, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 4, + "top_nesting_level": 1 + }, + { + "name": "have_f77c", + "long_name": "have_f77c( self )", + "filename": "misc_util.py", + "nloc": 8, + "complexity": 1, + "token_count": 30, + "parameters": [ + "self" + ], + "start_line": 886, + "end_line": 897, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 12, + "top_nesting_level": 1 + }, + { + "name": "have_f90c", + "long_name": "have_f90c( self )", + "filename": "misc_util.py", + "nloc": 8, + "complexity": 1, + "token_count": 30, + "parameters": [ + "self" + ], + "start_line": 899, + "end_line": 910, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 12, + "top_nesting_level": 1 + }, + { + "name": "append_to", + "long_name": "append_to( self , extlib )", + "filename": "misc_util.py", + "nloc": 12, + "complexity": 2, + "token_count": 77, + "parameters": [ + "self", + "extlib" + ], + "start_line": 912, + "end_line": 925, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 14, + "top_nesting_level": 1 + }, + { + "name": "_get_svn_revision", + "long_name": "_get_svn_revision( self , path )", + "filename": "misc_util.py", + "nloc": 10, + "complexity": 3, + "token_count": 73, + "parameters": [ + "self", + "path" + ], + "start_line": 927, + "end_line": 938, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 12, + "top_nesting_level": 1 + }, + { + "name": "get_version", + "long_name": "get_version( self )", + "filename": "misc_util.py", + "nloc": 38, + "complexity": 11, + "token_count": 260, + "parameters": [ + "self" + ], + "start_line": 940, + "end_line": 986, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 47, + "top_nesting_level": 1 + }, + { + "name": "make_svn_version_py.make_svn_version_py.generate_svn_version_py.rm_file", + "long_name": "make_svn_version_py.make_svn_version_py.generate_svn_version_py.rm_file( f = target , p = self . info )", + "filename": "misc_util.py", + "nloc": 5, + "complexity": 3, + "token_count": 55, + "parameters": [ + "f", + "p" + ], + "start_line": 1009, + "end_line": 1013, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 5, + "top_nesting_level": 3 + }, + { + "name": "make_svn_version_py.generate_svn_version_py", + "long_name": "make_svn_version_py.generate_svn_version_py( )", + "filename": "misc_util.py", + "nloc": 13, + "complexity": 2, + "token_count": 85, + "parameters": [], + "start_line": 998, + "end_line": 1016, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 19, + "top_nesting_level": 2 + }, + { + "name": "make_svn_version_py", + "long_name": "make_svn_version_py( self )", + "filename": "misc_util.py", + "nloc": 7, + "complexity": 2, + "token_count": 44, + "parameters": [ + "self" + ], + "start_line": 988, + "end_line": 1019, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 32, + "top_nesting_level": 1 + }, + { + "name": "make_config_py", + "long_name": "make_config_py( self , name = '__config__' )", + "filename": "misc_util.py", + "nloc": 3, + "complexity": 1, + "token_count": 27, + "parameters": [ + "self", + "name" + ], + "start_line": 1021, + "end_line": 1026, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 6, + "top_nesting_level": 1 + }, + { + "name": "get_info", + "long_name": "get_info( self , * names )", + "filename": "misc_util.py", + "nloc": 6, + "complexity": 2, + "token_count": 36, + "parameters": [ + "self", + "names" + ], + "start_line": 1028, + "end_line": 1035, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 8, + "top_nesting_level": 1 + }, + { + "name": "get_cmd", + "long_name": "get_cmd( cmdname , _cache = { } )", + "filename": "misc_util.py", + "nloc": 11, + "complexity": 3, + "token_count": 65, + "parameters": [ + "cmdname", + "_cache" + ], + "start_line": 1052, + "end_line": 1062, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 11, + "top_nesting_level": 0 + }, + { + "name": "get_numpy_include_dirs", + "long_name": "get_numpy_include_dirs( )", + "filename": "misc_util.py", + "nloc": 11, + "complexity": 3, + "token_count": 77, + "parameters": [], + "start_line": 1064, + "end_line": 1078, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 15, + "top_nesting_level": 0 + }, + { + "name": "default_config_dict", + "long_name": "default_config_dict( name = None , parent_name = None , local_path = None )", + "filename": "misc_util.py", + "nloc": 9, + "complexity": 1, + "token_count": 70, + "parameters": [ + "name", + "parent_name", + "local_path" + ], + "start_line": 1082, + "end_line": 1093, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 12, + "top_nesting_level": 0 + }, + { + "name": "dict_append", + "long_name": "dict_append( d , ** kws )", + "filename": "misc_util.py", + "nloc": 6, + "complexity": 3, + "token_count": 44, + "parameters": [ + "d", + "kws" + ], + "start_line": 1096, + "end_line": 1101, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 6, + "top_nesting_level": 0 + }, + { + "name": "appendpath", + "long_name": "appendpath( prefix , path )", + "filename": "misc_util.py", + "nloc": 19, + "complexity": 6, + "token_count": 233, + "parameters": [ + "prefix", + "path" + ], + "start_line": 1103, + "end_line": 1122, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 20, + "top_nesting_level": 0 + }, + { + "name": "generate_config_py", + "long_name": "generate_config_py( target )", + "filename": "misc_util.py", + "nloc": 27, + "complexity": 2, + "token_count": 117, + "parameters": [ + "target" + ], + "start_line": 1128, + "end_line": 1161, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 34, + "top_nesting_level": 0 + }, + { + "name": "generate_svn_version_py", + "long_name": "generate_svn_version_py( extension , build_dir )", + "filename": "misc_util.py", + "nloc": 15, + "complexity": 4, + "token_count": 101, + "parameters": [ + "extension", + "build_dir" + ], + "start_line": 1163, + "end_line": 1190, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 28, + "top_nesting_level": 0 + } + ], + "methods_before": [ + { + "name": "allpath", + "long_name": "allpath( name )", + "filename": "misc_util.py", + "nloc": 4, + "complexity": 1, + "token_count": 24, + "parameters": [ + "name" + ], + "start_line": 18, + "end_line": 21, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 4, + "top_nesting_level": 0 + }, + { + "name": "get_path", + "long_name": "get_path( mod_name , parent_path = None )", + "filename": "misc_util.py", + "nloc": 15, + "complexity": 6, + "token_count": 132, + "parameters": [ + "mod_name", + "parent_path" + ], + "start_line": 23, + "end_line": 43, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 21, + "top_nesting_level": 0 + }, + { + "name": "njoin", + "long_name": "njoin( * path )", + "filename": "misc_util.py", + "nloc": 7, + "complexity": 4, + "token_count": 68, + "parameters": [ + "path" + ], + "start_line": 45, + "end_line": 55, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 11, + "top_nesting_level": 0 + }, + { + "name": "minrelpath", + "long_name": "minrelpath( path )", + "filename": "misc_util.py", + "nloc": 17, + "complexity": 7, + "token_count": 103, + "parameters": [ + "path" + ], + "start_line": 57, + "end_line": 75, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 19, + "top_nesting_level": 0 + }, + { + "name": "terminal_has_colors", + "long_name": "terminal_has_colors( )", + "filename": "misc_util.py", + "nloc": 18, + "complexity": 13, + "token_count": 137, + "parameters": [], + "start_line": 79, + "end_line": 104, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 26, + "top_nesting_level": 0 + }, + { + "name": "cyg2win32", + "long_name": "cyg2win32( path )", + "filename": "misc_util.py", + "nloc": 4, + "complexity": 3, + "token_count": 42, + "parameters": [ + "path" + ], + "start_line": 121, + "end_line": 124, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 4, + "top_nesting_level": 0 + }, + { + "name": "_get_f90_modules", + "long_name": "_get_f90_modules( source )", + "filename": "misc_util.py", + "nloc": 13, + "complexity": 4, + "token_count": 77, + "parameters": [ + "source" + ], + "start_line": 133, + "end_line": 149, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 17, + "top_nesting_level": 0 + }, + { + "name": "is_string", + "long_name": "is_string( s )", + "filename": "misc_util.py", + "nloc": 2, + "complexity": 1, + "token_count": 12, + "parameters": [ + "s" + ], + "start_line": 151, + "end_line": 152, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 2, + "top_nesting_level": 0 + }, + { + "name": "all_strings", + "long_name": "all_strings( lst )", + "filename": "misc_util.py", + "nloc": 5, + "complexity": 3, + "token_count": 22, + "parameters": [ + "lst" + ], + "start_line": 154, + "end_line": 159, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 6, + "top_nesting_level": 0 + }, + { + "name": "is_sequence", + "long_name": "is_sequence( seq )", + "filename": "misc_util.py", + "nloc": 8, + "complexity": 3, + "token_count": 25, + "parameters": [ + "seq" + ], + "start_line": 161, + "end_line": 168, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 8, + "top_nesting_level": 0 + }, + { + "name": "has_f_sources", + "long_name": "has_f_sources( sources )", + "filename": "misc_util.py", + "nloc": 5, + "complexity": 3, + "token_count": 21, + "parameters": [ + "sources" + ], + "start_line": 170, + "end_line": 175, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 6, + "top_nesting_level": 0 + }, + { + "name": "has_cxx_sources", + "long_name": "has_cxx_sources( sources )", + "filename": "misc_util.py", + "nloc": 5, + "complexity": 3, + "token_count": 21, + "parameters": [ + "sources" + ], + "start_line": 177, + "end_line": 182, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 6, + "top_nesting_level": 0 + }, + { + "name": "filter_sources", + "long_name": "filter_sources( sources )", + "filename": "misc_util.py", + "nloc": 17, + "complexity": 5, + "token_count": 84, + "parameters": [ + "sources" + ], + "start_line": 184, + "end_line": 204, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 21, + "top_nesting_level": 0 + }, + { + "name": "_get_headers", + "long_name": "_get_headers( directory_list )", + "filename": "misc_util.py", + "nloc": 6, + "complexity": 2, + "token_count": 39, + "parameters": [ + "directory_list" + ], + "start_line": 207, + "end_line": 213, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 7, + "top_nesting_level": 0 + }, + { + "name": "_get_directories", + "long_name": "_get_directories( list_of_sources )", + "filename": "misc_util.py", + "nloc": 7, + "complexity": 4, + "token_count": 51, + "parameters": [ + "list_of_sources" + ], + "start_line": 215, + "end_line": 222, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 8, + "top_nesting_level": 0 + }, + { + "name": "get_dependencies", + "long_name": "get_dependencies( sources )", + "filename": "misc_util.py", + "nloc": 2, + "complexity": 1, + "token_count": 13, + "parameters": [ + "sources" + ], + "start_line": 224, + "end_line": 226, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 3, + "top_nesting_level": 0 + }, + { + "name": "is_local_src_dir", + "long_name": "is_local_src_dir( directory )", + "filename": "misc_util.py", + "nloc": 12, + "complexity": 6, + "token_count": 107, + "parameters": [ + "directory" + ], + "start_line": 228, + "end_line": 241, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 14, + "top_nesting_level": 0 + }, + { + "name": "_gsf_visit_func", + "long_name": "_gsf_visit_func( filenames , dirname , names )", + "filename": "misc_util.py", + "nloc": 13, + "complexity": 7, + "token_count": 103, + "parameters": [ + "filenames", + "dirname", + "names" + ], + "start_line": 243, + "end_line": 255, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 13, + "top_nesting_level": 0 + }, + { + "name": "get_ext_source_files", + "long_name": "get_ext_source_files( ext )", + "filename": "misc_util.py", + "nloc": 11, + "complexity": 4, + "token_count": 77, + "parameters": [ + "ext" + ], + "start_line": 257, + "end_line": 268, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 12, + "top_nesting_level": 0 + }, + { + "name": "get_script_files", + "long_name": "get_script_files( scripts )", + "filename": "misc_util.py", + "nloc": 3, + "complexity": 1, + "token_count": 15, + "parameters": [ + "scripts" + ], + "start_line": 270, + "end_line": 272, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 3, + "top_nesting_level": 0 + }, + { + "name": "get_lib_source_files", + "long_name": "get_lib_source_files( lib )", + "filename": "misc_util.py", + "nloc": 13, + "complexity": 4, + "token_count": 101, + "parameters": [ + "lib" + ], + "start_line": 274, + "end_line": 286, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 13, + "top_nesting_level": 0 + }, + { + "name": "get_data_files", + "long_name": "get_data_files( data )", + "filename": "misc_util.py", + "nloc": 18, + "complexity": 7, + "token_count": 94, + "parameters": [ + "data" + ], + "start_line": 288, + "end_line": 305, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 18, + "top_nesting_level": 0 + }, + { + "name": "dot_join", + "long_name": "dot_join( * args )", + "filename": "misc_util.py", + "nloc": 2, + "complexity": 1, + "token_count": 18, + "parameters": [ + "args" + ], + "start_line": 307, + "end_line": 308, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 2, + "top_nesting_level": 0 + }, + { + "name": "get_frame", + "long_name": "get_frame( level = 0 )", + "filename": "misc_util.py", + "nloc": 8, + "complexity": 3, + "token_count": 50, + "parameters": [ + "level" + ], + "start_line": 310, + "end_line": 317, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 8, + "top_nesting_level": 0 + }, + { + "name": "command_line_ok", + "long_name": "command_line_ok( _cache = [ ] )", + "filename": "misc_util.py", + "nloc": 14, + "complexity": 9, + "token_count": 98, + "parameters": [ + "_cache" + ], + "start_line": 321, + "end_line": 337, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 17, + "top_nesting_level": 0 + }, + { + "name": "__init__", + "long_name": "__init__( self , package_name = None , parent_name = None , top_path = None , package_path = None , ** attrs )", + "filename": "misc_util.py", + "nloc": 44, + "complexity": 12, + "token_count": 365, + "parameters": [ + "self", + "package_name", + "parent_name", + "top_path", + "package_path", + "attrs" + ], + "start_line": 347, + "end_line": 411, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 65, + "top_nesting_level": 1 + }, + { + "name": "todict", + "long_name": "todict( self )", + "filename": "misc_util.py", + "nloc": 9, + "complexity": 4, + "token_count": 57, + "parameters": [ + "self" + ], + "start_line": 413, + "end_line": 424, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 12, + "top_nesting_level": 1 + }, + { + "name": "info", + "long_name": "info( self , message )", + "filename": "misc_util.py", + "nloc": 2, + "complexity": 1, + "token_count": 9, + "parameters": [ + "self", + "message" + ], + "start_line": 426, + "end_line": 427, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 2, + "top_nesting_level": 1 + }, + { + "name": "warn", + "long_name": "warn( self , message )", + "filename": "misc_util.py", + "nloc": 2, + "complexity": 1, + "token_count": 17, + "parameters": [ + "self", + "message" + ], + "start_line": 429, + "end_line": 430, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 2, + "top_nesting_level": 1 + }, + { + "name": "__dict__", + "long_name": "__dict__( self )", + "filename": "misc_util.py", + "nloc": 2, + "complexity": 1, + "token_count": 11, + "parameters": [ + "self" + ], + "start_line": 432, + "end_line": 433, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 2, + "top_nesting_level": 1 + }, + { + "name": "get_distribution", + "long_name": "get_distribution( self )", + "filename": "misc_util.py", + "nloc": 4, + "complexity": 1, + "token_count": 18, + "parameters": [ + "self" + ], + "start_line": 435, + "end_line": 438, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 4, + "top_nesting_level": 1 + }, + { + "name": "get_subpackage", + "long_name": "get_subpackage( self , subpackage_name , subpackage_path = None )", + "filename": "misc_util.py", + "nloc": 52, + "complexity": 13, + "token_count": 446, + "parameters": [ + "self", + "subpackage_name", + "subpackage_path" + ], + "start_line": 440, + "end_line": 498, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 59, + "top_nesting_level": 1 + }, + { + "name": "add_subpackage", + "long_name": "add_subpackage( self , subpackage_name , subpackage_path = None )", + "filename": "misc_util.py", + "nloc": 20, + "complexity": 6, + "token_count": 127, + "parameters": [ + "self", + "subpackage_name", + "subpackage_path" + ], + "start_line": 500, + "end_line": 522, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 23, + "top_nesting_level": 1 + }, + { + "name": "add_data_dir", + "long_name": "add_data_dir( self , data_path )", + "filename": "misc_util.py", + "nloc": 27, + "complexity": 9, + "token_count": 196, + "parameters": [ + "self", + "data_path" + ], + "start_line": 524, + "end_line": 558, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 35, + "top_nesting_level": 1 + }, + { + "name": "add_data_files", + "long_name": "add_data_files( self , * files )", + "filename": "misc_util.py", + "nloc": 49, + "complexity": 17, + "token_count": 392, + "parameters": [ + "self", + "files" + ], + "start_line": 560, + "end_line": 620, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 61, + "top_nesting_level": 1 + }, + { + "name": "add_include_dirs", + "long_name": "add_include_dirs( self , * paths )", + "filename": "misc_util.py", + "nloc": 8, + "complexity": 2, + "token_count": 49, + "parameters": [ + "self", + "paths" + ], + "start_line": 624, + "end_line": 633, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 10, + "top_nesting_level": 1 + }, + { + "name": "add_headers", + "long_name": "add_headers( self , * files )", + "filename": "misc_util.py", + "nloc": 15, + "complexity": 8, + "token_count": 136, + "parameters": [ + "self", + "files" + ], + "start_line": 635, + "end_line": 655, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 21, + "top_nesting_level": 1 + }, + { + "name": "_fix_paths", + "long_name": "_fix_paths( self , paths , include_non_existing = True )", + "filename": "misc_util.py", + "nloc": 30, + "complexity": 12, + "token_count": 208, + "parameters": [ + "self", + "paths", + "include_non_existing" + ], + "start_line": 657, + "end_line": 686, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 30, + "top_nesting_level": 1 + }, + { + "name": "paths", + "long_name": "paths( self , * paths , ** kws )", + "filename": "misc_util.py", + "nloc": 4, + "complexity": 1, + "token_count": 33, + "parameters": [ + "self", + "paths", + "kws" + ], + "start_line": 688, + "end_line": 693, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 6, + "top_nesting_level": 1 + }, + { + "name": "add_extension", + "long_name": "add_extension( self , name , sources , ** kw )", + "filename": "misc_util.py", + "nloc": 45, + "complexity": 14, + "token_count": 361, + "parameters": [ + "self", + "name", + "sources", + "kw" + ], + "start_line": 695, + "end_line": 757, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 63, + "top_nesting_level": 1 + }, + { + "name": "add_library", + "long_name": "add_library( self , name , sources , ** build_info )", + "filename": "misc_util.py", + "nloc": 15, + "complexity": 4, + "token_count": 106, + "parameters": [ + "self", + "name", + "sources", + "build_info" + ], + "start_line": 759, + "end_line": 784, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 26, + "top_nesting_level": 1 + }, + { + "name": "add_scripts", + "long_name": "add_scripts( self , * files )", + "filename": "misc_util.py", + "nloc": 8, + "complexity": 2, + "token_count": 49, + "parameters": [ + "self", + "files" + ], + "start_line": 786, + "end_line": 795, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 10, + "top_nesting_level": 1 + }, + { + "name": "dict_append", + "long_name": "dict_append( self , ** dict )", + "filename": "misc_util.py", + "nloc": 16, + "complexity": 7, + "token_count": 150, + "parameters": [ + "self", + "dict" + ], + "start_line": 797, + "end_line": 812, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 16, + "top_nesting_level": 1 + }, + { + "name": "__str__", + "long_name": "__str__( self )", + "filename": "misc_util.py", + "nloc": 10, + "complexity": 3, + "token_count": 72, + "parameters": [ + "self" + ], + "start_line": 814, + "end_line": 823, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 10, + "top_nesting_level": 1 + }, + { + "name": "get_config_cmd", + "long_name": "get_config_cmd( self )", + "filename": "misc_util.py", + "nloc": 10, + "complexity": 2, + "token_count": 63, + "parameters": [ + "self" + ], + "start_line": 825, + "end_line": 834, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 10, + "top_nesting_level": 1 + }, + { + "name": "get_build_temp_dir", + "long_name": "get_build_temp_dir( self )", + "filename": "misc_util.py", + "nloc": 4, + "complexity": 1, + "token_count": 20, + "parameters": [ + "self" + ], + "start_line": 836, + "end_line": 839, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 4, + "top_nesting_level": 1 + }, + { + "name": "have_f77c", + "long_name": "have_f77c( self )", + "filename": "misc_util.py", + "nloc": 8, + "complexity": 1, + "token_count": 30, + "parameters": [ + "self" + ], + "start_line": 841, + "end_line": 852, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 12, + "top_nesting_level": 1 + }, + { + "name": "have_f90c", + "long_name": "have_f90c( self )", + "filename": "misc_util.py", + "nloc": 8, + "complexity": 1, + "token_count": 30, + "parameters": [ + "self" + ], + "start_line": 854, + "end_line": 865, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 12, + "top_nesting_level": 1 + }, + { + "name": "append_to", + "long_name": "append_to( self , extlib )", + "filename": "misc_util.py", + "nloc": 12, + "complexity": 2, + "token_count": 77, + "parameters": [ + "self", + "extlib" + ], + "start_line": 867, + "end_line": 880, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 14, + "top_nesting_level": 1 + }, + { + "name": "_get_svn_revision", + "long_name": "_get_svn_revision( self , path )", + "filename": "misc_util.py", + "nloc": 10, + "complexity": 3, + "token_count": 73, + "parameters": [ + "self", + "path" + ], + "start_line": 882, + "end_line": 893, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 12, + "top_nesting_level": 1 + }, + { + "name": "get_version", + "long_name": "get_version( self )", + "filename": "misc_util.py", + "nloc": 38, + "complexity": 11, + "token_count": 253, + "parameters": [ + "self" + ], + "start_line": 895, + "end_line": 941, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 47, + "top_nesting_level": 1 + }, + { + "name": "make_svn_version_py.make_svn_version_py.generate_svn_version_py.rm_file", + "long_name": "make_svn_version_py.make_svn_version_py.generate_svn_version_py.rm_file( f = target )", + "filename": "misc_util.py", + "nloc": 5, + "complexity": 3, + "token_count": 45, + "parameters": [ + "f" + ], + "start_line": 965, + "end_line": 969, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 5, + "top_nesting_level": 3 + }, + { + "name": "make_svn_version_py.generate_svn_version_py", + "long_name": "make_svn_version_py.generate_svn_version_py( )", + "filename": "misc_util.py", + "nloc": 13, + "complexity": 2, + "token_count": 81, + "parameters": [], + "start_line": 954, + "end_line": 972, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 19, + "top_nesting_level": 2 + }, + { + "name": "make_svn_version_py", + "long_name": "make_svn_version_py( self )", + "filename": "misc_util.py", + "nloc": 7, + "complexity": 2, + "token_count": 44, + "parameters": [ + "self" + ], + "start_line": 943, + "end_line": 975, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 33, + "top_nesting_level": 1 + }, + { + "name": "make_config_py", + "long_name": "make_config_py( self , name = '__config__' )", + "filename": "misc_util.py", + "nloc": 3, + "complexity": 1, + "token_count": 27, + "parameters": [ + "self", + "name" + ], + "start_line": 977, + "end_line": 982, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 6, + "top_nesting_level": 1 + }, + { + "name": "get_info", + "long_name": "get_info( self , * names )", + "filename": "misc_util.py", + "nloc": 6, + "complexity": 2, + "token_count": 36, + "parameters": [ + "self", + "names" + ], + "start_line": 984, + "end_line": 991, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 8, + "top_nesting_level": 1 + }, + { + "name": "get_cmd", + "long_name": "get_cmd( cmdname , _cache = { } )", + "filename": "misc_util.py", + "nloc": 11, + "complexity": 3, + "token_count": 65, + "parameters": [ + "cmdname", + "_cache" + ], + "start_line": 1008, + "end_line": 1018, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 11, + "top_nesting_level": 0 + }, + { + "name": "get_numpy_include_dirs", + "long_name": "get_numpy_include_dirs( )", + "filename": "misc_util.py", + "nloc": 11, + "complexity": 3, + "token_count": 77, + "parameters": [], + "start_line": 1020, + "end_line": 1034, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 15, + "top_nesting_level": 0 + }, + { + "name": "default_config_dict", + "long_name": "default_config_dict( name = None , parent_name = None , local_path = None )", + "filename": "misc_util.py", + "nloc": 9, + "complexity": 1, + "token_count": 70, + "parameters": [ + "name", + "parent_name", + "local_path" + ], + "start_line": 1038, + "end_line": 1049, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 12, + "top_nesting_level": 0 + }, + { + "name": "dict_append", + "long_name": "dict_append( d , ** kws )", + "filename": "misc_util.py", + "nloc": 6, + "complexity": 3, + "token_count": 44, + "parameters": [ + "d", + "kws" + ], + "start_line": 1052, + "end_line": 1057, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 6, + "top_nesting_level": 0 + }, + { + "name": "appendpath", + "long_name": "appendpath( prefix , path )", + "filename": "misc_util.py", + "nloc": 19, + "complexity": 6, + "token_count": 233, + "parameters": [ + "prefix", + "path" + ], + "start_line": 1059, + "end_line": 1078, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 20, + "top_nesting_level": 0 + }, + { + "name": "generate_config_py", + "long_name": "generate_config_py( target )", + "filename": "misc_util.py", + "nloc": 27, + "complexity": 2, + "token_count": 117, + "parameters": [ + "target" + ], + "start_line": 1084, + "end_line": 1117, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 34, + "top_nesting_level": 0 + }, + { + "name": "generate_svn_version_py", + "long_name": "generate_svn_version_py( extension , build_dir )", + "filename": "misc_util.py", + "nloc": 15, + "complexity": 4, + "token_count": 101, + "parameters": [ + "extension", + "build_dir" + ], + "start_line": 1119, + "end_line": 1146, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 28, + "top_nesting_level": 0 + } + ], + "changed_methods": [ + { + "name": "get_version", + "long_name": "get_version( self )", + "filename": "misc_util.py", + "nloc": 38, + "complexity": 11, + "token_count": 260, + "parameters": [ + "self" + ], + "start_line": 940, + "end_line": 986, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 47, + "top_nesting_level": 1 + }, + { + "name": "add_data_dir", + "long_name": "add_data_dir( self , data_path )", + "filename": "misc_util.py", + "nloc": 27, + "complexity": 9, + "token_count": 200, + "parameters": [ + "self", + "data_path" + ], + "start_line": 567, + "end_line": 601, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 35, + "top_nesting_level": 1 + }, + { + "name": "get_subpackage", + "long_name": "get_subpackage( self , subpackage_name , subpackage_path = None )", + "filename": "misc_util.py", + "nloc": 56, + "complexity": 16, + "token_count": 482, + "parameters": [ + "self", + "subpackage_name", + "subpackage_path" + ], + "start_line": 475, + "end_line": 538, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 64, + "top_nesting_level": 1 + }, + { + "name": "info", + "long_name": "info( self , message )", + "filename": "misc_util.py", + "nloc": 3, + "complexity": 2, + "token_count": 18, + "parameters": [ + "self", + "message" + ], + "start_line": 444, + "end_line": 446, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 3, + "top_nesting_level": 1 + }, + { + "name": "set_options", + "long_name": "set_options( self , ** options )", + "filename": "misc_util.py", + "nloc": 7, + "complexity": 3, + "token_count": 47, + "parameters": [ + "self", + "options" + ], + "start_line": 452, + "end_line": 466, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 15, + "top_nesting_level": 1 + }, + { + "name": "add_extension", + "long_name": "add_extension( self , name , sources , ** kw )", + "filename": "misc_util.py", + "nloc": 46, + "complexity": 14, + "token_count": 367, + "parameters": [ + "self", + "name", + "sources", + "kw" + ], + "start_line": 738, + "end_line": 801, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 64, + "top_nesting_level": 1 + }, + { + "name": "add_subpackage", + "long_name": "add_subpackage( self , subpackage_name , subpackage_path = None )", + "filename": "misc_util.py", + "nloc": 23, + "complexity": 6, + "token_count": 147, + "parameters": [ + "self", + "subpackage_name", + "subpackage_path" + ], + "start_line": 540, + "end_line": 565, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 26, + "top_nesting_level": 1 + }, + { + "name": "make_svn_version_py.generate_svn_version_py", + "long_name": "make_svn_version_py.generate_svn_version_py( )", + "filename": "misc_util.py", + "nloc": 13, + "complexity": 2, + "token_count": 85, + "parameters": [], + "start_line": 998, + "end_line": 1016, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 19, + "top_nesting_level": 2 + }, + { + "name": "make_svn_version_py.make_svn_version_py.generate_svn_version_py.rm_file", + "long_name": "make_svn_version_py.make_svn_version_py.generate_svn_version_py.rm_file( f = target , p = self . info )", + "filename": "misc_util.py", + "nloc": 5, + "complexity": 3, + "token_count": 55, + "parameters": [ + "f", + "p" + ], + "start_line": 1009, + "end_line": 1013, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 5, + "top_nesting_level": 3 + }, + { + "name": "add_library", + "long_name": "add_library( self , name , sources , ** build_info )", + "filename": "misc_util.py", + "nloc": 16, + "complexity": 4, + "token_count": 112, + "parameters": [ + "self", + "name", + "sources", + "build_info" + ], + "start_line": 803, + "end_line": 829, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 27, + "top_nesting_level": 1 + }, + { + "name": "make_svn_version_py.make_svn_version_py.generate_svn_version_py.rm_file", + "long_name": "make_svn_version_py.make_svn_version_py.generate_svn_version_py.rm_file( f = target )", + "filename": "misc_util.py", + "nloc": 5, + "complexity": 3, + "token_count": 45, + "parameters": [ + "f" + ], + "start_line": 965, + "end_line": 969, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 5, + "top_nesting_level": 3 + }, + { + "name": "__init__", + "long_name": "__init__( self , package_name = None , parent_name = None , top_path = None , package_path = None , ** attrs )", + "filename": "misc_util.py", + "nloc": 60, + "complexity": 16, + "token_count": 455, + "parameters": [ + "self", + "package_name", + "parent_name", + "top_path", + "package_path", + "attrs" + ], + "start_line": 347, + "end_line": 429, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 83, + "top_nesting_level": 1 + }, + { + "name": "make_svn_version_py", + "long_name": "make_svn_version_py( self )", + "filename": "misc_util.py", + "nloc": 7, + "complexity": 2, + "token_count": 44, + "parameters": [ + "self" + ], + "start_line": 988, + "end_line": 1019, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 32, + "top_nesting_level": 1 + } + ], + "nloc": 894, + "complexity": 287, + "token_count": 6458, + "diff_parsed": { + "added": [ + " self.options = dict(\\", + " ignore_setup_xxx_py = False,", + " assume_default_configuration = False,", + " delegate_options_to_subpackages = False,", + " quiet = False,", + " )", + "", + " for i in range(1,3):", + " f = get_frame(i)", + " try:", + " caller_instance = eval('self',f.f_globals,f.f_locals)", + " break", + " except NameError:", + " caller_instance = None", + " if isinstance(caller_instance, self.__class__):", + " if caller_instance.options['delegate_options_to_subpackages']:", + " self.set_options(**caller_instance.options)", + "", + " if not self.options['quiet']:", + " print message", + "", + " def set_options(self, **options):", + " \"\"\" Configure Configuration instance.", + "", + " The following options are available:", + " - ignore_setup_xxx_py", + " - assume_default_configuration", + " - delegate_options_to_subpackages", + " - quiet", + " \"\"\"", + " for key, value in options.items():", + " if self.options.has_key(key):", + " self.options[key] = value", + " else:", + " raise ValueError,'Unknown option: '+key", + " return", + "", + " if not self.options['ignore_setup_xxx_py']:", + " if not os.path.isfile(setup_py):", + " setup_py = njoin(subpackage_path,'setup_%s.py' % (subpackage_name))", + " if not self.options['assume_default_configuration']:", + " self.warn('Assuming default configuration '\\", + " '(%s/{setup_%s,setup}.py was not found)' \\", + " % (os.path.dirname(setup_py),subpackage_name))", + " if not self.options['assume_default_configuration']:", + " self.warn('Assuming default configuration '\\", + " '(%s does not define configuration())'\\", + " % (setup_module))", + " self.warn('No configuration returned, assuming unavailable.')", + " self.info('Appending %s configuration to %s' \\", + " % (config.name,self.name))", + " self.info('Appending %s configuration to %s' \\", + " % (config.get('name'),self.name))", + " self.warn('distutils distribution has been initialized,'\\", + " ' it may be too late to add a subpackage '+ subpackage_name)", + " self.warn('Not existing data path: '+path)", + " self.warn('distutils distribution has been initialized,'\\", + " ' it may be too late to add an extension '+name)", + " self.warn('distutils distribution has been initialized,'\\", + " ' it may be too late to add a library '+ name)", + " self.warn(str(msg))", + " self.info('Creating %s (version=%r)' % (target,version))", + " def rm_file(f=target,p=self.info):", + " try: os.remove(f); p('removed '+f)", + " try: os.remove(f+'c'); p('removed '+f+'c')" + ], + "deleted": [ + " print message", + " if not os.path.isfile(setup_py):", + " setup_py = njoin(subpackage_path,'setup_%s.py' % (subpackage_name))", + " print 'Assuming default configuration '\\", + " '(%s/{setup_%s,setup}.py was not found)' \\", + " % (os.path.dirname(setup_py),subpackage_name)", + " print 'Assuming default configuration '\\", + " '(%s does not define configuration())' % (setup_module)", + " print 'No configuration returned, assuming unavailable.'", + " print 'Appending %s configuration to %s' % (config.name,self.name)", + " print 'Appending %s configuration to %s' % (config.get('name'),self.name)", + " print 'distutils distribution has been initialized, it may be too late to add a subpackage', subpackage_name", + " print 'Not existing data path',path", + " print 'distutils distribution has been initialized, it may be too late to add an extension', name", + " print 'distutils distribution has been initialized, it may be too late to add a library', name", + " print msg", + "", + " print 'Creating %s (version=%r)' % (target,version)", + " def rm_file(f=target):", + " try: os.remove(f); print 'removed',f", + " try: os.remove(f+'c'); print 'removed',f+'c'" + ] + } + }, + { + "old_path": "setup.py", + "new_path": "setup.py", + "filename": "setup.py", + "extension": "py", + "change_type": "MODIFY", + "diff": "@@ -55,7 +55,10 @@ def setup_package():\n author_email = \"oliphant@ee.byu.edu\",\n platforms = [\"Windows\", \"Linux\", \"Solaris\", \"Mac OS-X\", \"Unix\"],\n )\n-\n+ config.set_options(ignore_setup_xxx_py=True,\n+ assume_default_configuration=True,\n+ delegate_options_to_subpackages=True,\n+ quiet=True)\n \n config.add_subpackage('numpy')\n from numpy.version import version\n", + "added_lines": 4, + "deleted_lines": 1, + "source_code": "\"\"\"NumPy: array processing for numbers, strings, records, and objects.\n\nNumPy is a general-purpose array-processing package designed to\nefficiently manipulate large multi-dimensional arrays of arbitrary\nrecords without sacrificing too much speed for small multi-dimensional\narrays. NumPy is built on the Numeric code base and adds features\nintroduced by numarray as well as an extended C-API and the ability to\ncreate arrays of arbitrary type.\n\nThere are also basic facilities for discrete fourier transform,\nbasic linear algebra and random number generation.\n\"\"\"\n\nDOCLINES = __doc__.split(\"\\n\")\n\nimport os\nimport sys\n\nCLASSIFIERS = \"\"\"\\\nDevelopment Status :: 4 - Beta\nIntended Audience :: Science/Research\nIntended Audience :: Developers\nLicense :: OSI Approved\nProgramming Language :: C\nProgramming Language :: Python\nTopic :: Software Development\nTopic :: Scientific/Engineering\nOperating System :: Microsoft :: Windows\nOperating System :: POSIX\nOperating System :: Unix\nOperating System :: MacOS\n\"\"\"\n\ndef setup_package():\n\n from numpy.distutils.core import setup\n from numpy.distutils.misc_util import Configuration\n\n old_path = os.getcwd()\n local_path = os.path.dirname(os.path.abspath(sys.argv[0]))\n os.chdir(local_path)\n sys.path.insert(0,local_path)\n\n try:\n config = Configuration(\n maintainer = \"SciPy Developers\",\n maintainer_email = \"scipy-dev@scipy.org\",\n description = DOCLINES[0],\n long_description = \"\\n\".join(DOCLINES[2:]),\n url = \"http://numeric.scipy.org\",\n download_url = \"http://sourceforge.net/projects/numpy\",\n license = 'BSD',\n classifiers=filter(None, CLASSIFIERS.split('\\n')),\n author = \"Travis E. Oliphant, et.al.\",\n author_email = \"oliphant@ee.byu.edu\",\n platforms = [\"Windows\", \"Linux\", \"Solaris\", \"Mac OS-X\", \"Unix\"],\n )\n config.set_options(ignore_setup_xxx_py=True,\n assume_default_configuration=True,\n delegate_options_to_subpackages=True,\n quiet=True)\n\n config.add_subpackage('numpy')\n from numpy.version import version\n config.name = 'numpy'\n config.dict_append(version=version)\n #print config.name,'version',config.version\n\n setup( **config.todict() )\n finally:\n del sys.path[0]\n os.chdir(old_path)\n return\n\nif __name__ == '__main__':\n setup_package()\n", + "source_code_before": "\"\"\"NumPy: array processing for numbers, strings, records, and objects.\n\nNumPy is a general-purpose array-processing package designed to\nefficiently manipulate large multi-dimensional arrays of arbitrary\nrecords without sacrificing too much speed for small multi-dimensional\narrays. NumPy is built on the Numeric code base and adds features\nintroduced by numarray as well as an extended C-API and the ability to\ncreate arrays of arbitrary type.\n\nThere are also basic facilities for discrete fourier transform,\nbasic linear algebra and random number generation.\n\"\"\"\n\nDOCLINES = __doc__.split(\"\\n\")\n\nimport os\nimport sys\n\nCLASSIFIERS = \"\"\"\\\nDevelopment Status :: 4 - Beta\nIntended Audience :: Science/Research\nIntended Audience :: Developers\nLicense :: OSI Approved\nProgramming Language :: C\nProgramming Language :: Python\nTopic :: Software Development\nTopic :: Scientific/Engineering\nOperating System :: Microsoft :: Windows\nOperating System :: POSIX\nOperating System :: Unix\nOperating System :: MacOS\n\"\"\"\n\ndef setup_package():\n\n from numpy.distutils.core import setup\n from numpy.distutils.misc_util import Configuration\n\n old_path = os.getcwd()\n local_path = os.path.dirname(os.path.abspath(sys.argv[0]))\n os.chdir(local_path)\n sys.path.insert(0,local_path)\n\n try:\n config = Configuration(\n maintainer = \"SciPy Developers\",\n maintainer_email = \"scipy-dev@scipy.org\",\n description = DOCLINES[0],\n long_description = \"\\n\".join(DOCLINES[2:]),\n url = \"http://numeric.scipy.org\",\n download_url = \"http://sourceforge.net/projects/numpy\",\n license = 'BSD',\n classifiers=filter(None, CLASSIFIERS.split('\\n')),\n author = \"Travis E. Oliphant, et.al.\",\n author_email = \"oliphant@ee.byu.edu\",\n platforms = [\"Windows\", \"Linux\", \"Solaris\", \"Mac OS-X\", \"Unix\"],\n )\n\n\n config.add_subpackage('numpy')\n from numpy.version import version\n config.name = 'numpy'\n config.dict_append(version=version)\n #print config.name,'version',config.version\n\n setup( **config.todict() )\n finally:\n del sys.path[0]\n os.chdir(old_path)\n return\n\nif __name__ == '__main__':\n setup_package()\n", + "methods": [ + { + "name": "setup_package", + "long_name": "setup_package( )", + "filename": "setup.py", + "nloc": 34, + "complexity": 2, + "token_count": 218, + "parameters": [], + "start_line": 34, + "end_line": 73, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 40, + "top_nesting_level": 0 + } + ], + "methods_before": [ + { + "name": "setup_package", + "long_name": "setup_package( )", + "filename": "setup.py", + "nloc": 30, + "complexity": 2, + "token_count": 198, + "parameters": [], + "start_line": 34, + "end_line": 70, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 37, + "top_nesting_level": 0 + } + ], + "changed_methods": [ + { + "name": "setup_package", + "long_name": "setup_package( )", + "filename": "setup.py", + "nloc": 34, + "complexity": 2, + "token_count": 218, + "parameters": [], + "start_line": 34, + "end_line": 73, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 40, + "top_nesting_level": 0 + } + ], + "nloc": 65, + "complexity": 2, + "token_count": 243, + "diff_parsed": { + "added": [ + " config.set_options(ignore_setup_xxx_py=True,", + " assume_default_configuration=True,", + " delegate_options_to_subpackages=True,", + " quiet=True)" + ], + "deleted": [ + "" + ] + } + } + ] + }, + { + "hash": "71f74ba1e86be798f35d59f4d632b9042c53eeb5", + "msg": "Improved warn messages.", + "author": { + "name": "Pearu Peterson", + "email": "pearu.peterson@gmail.com" + }, + "committer": { + "name": "Pearu Peterson", + "email": "pearu.peterson@gmail.com" + }, + "author_date": "2006-01-31T09:31:22+00:00", + "author_timezone": 0, + "committer_date": "2006-01-31T09:31:22+00:00", + "committer_timezone": 0, + "branches": [ + "main" + ], + "in_main_branch": true, + "merge": false, + "parents": [ + "33279f11ed91b4175aaca16443ecd828b4b5c549" + ], + "project_name": "repo_copy", + "project_path": "/tmp/tmppy2o86q9/repo_copy", + "deletions": 3, + "insertions": 4, + "lines": 7, + "files": 1, + "dmm_unit_size": 0.0, + "dmm_unit_complexity": 0.0, + "dmm_unit_interfacing": 0.0, + "modified_files": [ + { + "old_path": "numpy/distutils/misc_util.py", + "new_path": "numpy/distutils/misc_util.py", + "filename": "misc_util.py", + "extension": "py", + "change_type": "MODIFY", + "diff": "@@ -581,7 +581,6 @@ def add_data_dir(self,data_path):\n raise TypeError(\"not a string: %r\" % (data_path,))\n for path in self.paths(data_path):\n if not os.path.exists(path):\n- self.warn('Not existing data path: '+path)\n continue\n filenames = []\n os.path.walk(path, _gsf_visit_func,filenames)\n@@ -712,7 +711,8 @@ def _fix_paths(self,paths,include_non_existing=True):\n else:\n if include_non_existing:\n new_paths.append(n)\n- self.warn('could not resolve pattern: %r' % (n))\n+ self.warn('could not resolve pattern in %s: %r' \\\n+ % (self.local_path,n))\n else:\n n2 = njoin(self.local_path,n)\n if os.path.exists(n2):\n@@ -723,7 +723,8 @@ def _fix_paths(self,paths,include_non_existing=True):\n elif include_non_existing:\n new_paths.append(n)\n if not os.path.exists(n):\n- self.warn('not existing path: %r' % (n))\n+ self.warn('not existing data path in %s: %s' \\\n+ % (self.local_path,n))\n else:\n new_paths.append(n)\n return map(minrelpath,new_paths)\n", + "added_lines": 4, + "deleted_lines": 3, + "source_code": "import os\nimport re\nimport sys\nimport imp\nimport copy\nimport glob\n\n__all__ = ['Configuration', 'get_numpy_include_dirs', 'default_config_dict',\n 'dict_append', 'appendpath', 'generate_config_py',\n 'generate_svn_version_py', 'get_cmd', 'allpath',\n 'terminal_has_colors', 'red_text', 'green_text', 'yellow_text',\n 'blue_text', 'cyan_text', 'cyg2win32', 'all_strings',\n 'has_f_sources', 'has_cxx_sources', 'filter_sources',\n 'get_dependencies', 'is_local_src_dir', 'get_ext_source_files',\n 'get_script_files', 'get_lib_source_files', 'get_data_files',\n 'dot_join', 'get_frame', 'minrelpath','njoin']\n\ndef allpath(name):\n \"Convert a /-separated pathname to one using the OS's path separator.\"\n splitted = name.split('/')\n return os.path.join(*splitted)\n\ndef get_path(mod_name,parent_path=None):\n \"\"\" Return path of the module.\n\n Returned path is relative to parent_path when given,\n otherwise it is absolute path.\n \"\"\"\n if mod_name == '__main__':\n d = os.path.abspath('.')\n elif mod_name == '__builtin__':\n #builtin if/then added by Pearu for use in core.run_setup.\n d = os.path.dirname(os.path.abspath(sys.argv[0]))\n else:\n __import__(mod_name)\n mod = sys.modules[mod_name]\n file = mod.__file__\n d = os.path.dirname(os.path.abspath(file))\n if parent_path is not None:\n pd = os.path.abspath(parent_path)\n if pd==d[:len(pd)]:\n d = d[len(pd)+1:]\n return d or '.'\n\ndef njoin(*path):\n \"\"\" Join two or more pathname components +\n - convert a /-separated pathname to one using the OS's path separator.\n - resolve `..` from path.\n \"\"\"\n if isinstance(path,tuple):\n path = os.path.join(*path)\n if not isinstance(path,str): return path\n if not ('/' == os.path.sep):\n path = path.replace('/',os.path.sep)\n return minrelpath(path)\n\ndef minrelpath(path):\n \"\"\" Resolve `..` from path.\n \"\"\"\n if not isinstance(path, str): return path\n if '..' not in path: return path\n l = path.split(os.sep)\n j = 1\n while l:\n try:\n i = l.index('..',j)\n except ValueError:\n break\n if l[i-1]=='..':\n j += 1\n else:\n del l[i],l[i-1]\n j = 1\n if not l: return ''\n return os.path.join(*l)\n\n# Hooks for colored terminal output.\n# See also http://www.livinglogic.de/Python/ansistyle\ndef terminal_has_colors():\n if sys.platform=='cygwin' and not os.environ.has_key('USE_COLOR'):\n # Avoid importing curses that causes illegal operation\n # with a message:\n # PYTHON2 caused an invalid page fault in\n # module CYGNURSES7.DLL as 015f:18bbfc28\n # Details: Python 2.3.3 [GCC 3.3.1 (cygming special)]\n # ssh to Win32 machine from debian\n # curses.version is 2.2\n # CYGWIN_98-4.10, release 1.5.7(0.109/3/2))\n return 0\n if hasattr(sys.stdout,'isatty') and sys.stdout.isatty():\n try:\n import curses\n curses.setupterm()\n if (curses.tigetnum(\"colors\") >= 0\n and curses.tigetnum(\"pairs\") >= 0\n and ((curses.tigetstr(\"setf\") is not None\n and curses.tigetstr(\"setb\") is not None)\n or (curses.tigetstr(\"setaf\") is not None\n and curses.tigetstr(\"setab\") is not None)\n or curses.tigetstr(\"scp\") is not None)):\n return 1\n except Exception,msg:\n pass\n return 0\n\nif terminal_has_colors():\n def red_text(s): return '\\x1b[31m%s\\x1b[0m'%s\n def green_text(s): return '\\x1b[32m%s\\x1b[0m'%s\n def yellow_text(s): return '\\x1b[33m%s\\x1b[0m'%s\n def blue_text(s): return '\\x1b[34m%s\\x1b[0m'%s\n def cyan_text(s): return '\\x1b[35m%s\\x1b[0m'%s\nelse:\n def red_text(s): return s\n def green_text(s): return s\n def yellow_text(s): return s\n def cyan_text(s): return s\n def blue_text(s): return s\n\n#########################\n\ndef cyg2win32(path):\n if sys.platform=='cygwin' and path.startswith('/cygdrive'):\n path = path[10] + ':' + os.path.normcase(path[11:])\n return path\n\n#########################\n\n#XXX need support for .C that is also C++\ncxx_ext_match = re.compile(r'.*[.](cpp|cxx|cc)\\Z',re.I).match\nfortran_ext_match = re.compile(r'.*[.](f90|f95|f77|for|ftn|f)\\Z',re.I).match\nf90_ext_match = re.compile(r'.*[.](f90|f95)\\Z',re.I).match\nf90_module_name_match = re.compile(r'\\s*module\\s*(?P[\\w_]+)',re.I).match\ndef _get_f90_modules(source):\n \"\"\" Return a list of Fortran f90 module names that\n given source file defines.\n \"\"\"\n if not f90_ext_match(source):\n return []\n modules = []\n f = open(source,'r')\n f_readlines = getattr(f,'xreadlines',f.readlines)\n for line in f_readlines():\n m = f90_module_name_match(line)\n if m:\n name = m.group('name')\n modules.append(name)\n # break # XXX can we assume that there is one module per file?\n f.close()\n return modules\n\ndef is_string(s):\n return isinstance(s, str)\n\ndef all_strings(lst):\n \"\"\" Return True if all items in lst are string objects. \"\"\"\n for item in lst:\n if not is_string(item):\n return False\n return True\n\ndef is_sequence(seq):\n if is_string(seq):\n return False\n try:\n len(seq)\n except:\n return False\n return True\n\ndef has_f_sources(sources):\n \"\"\" Return True if sources contains Fortran files \"\"\"\n for source in sources:\n if fortran_ext_match(source):\n return True\n return False\n\ndef has_cxx_sources(sources):\n \"\"\" Return True if sources contains C++ files \"\"\"\n for source in sources:\n if cxx_ext_match(source):\n return True\n return False\n\ndef filter_sources(sources):\n \"\"\" Return four lists of filenames containing\n C, C++, Fortran, and Fortran 90 module sources,\n respectively.\n \"\"\"\n c_sources = []\n cxx_sources = []\n f_sources = []\n fmodule_sources = []\n for source in sources:\n if fortran_ext_match(source):\n modules = _get_f90_modules(source)\n if modules:\n fmodule_sources.append(source)\n else:\n f_sources.append(source)\n elif cxx_ext_match(source):\n cxx_sources.append(source)\n else:\n c_sources.append(source)\n return c_sources, cxx_sources, f_sources, fmodule_sources\n\n\ndef _get_headers(directory_list):\n # get *.h files from list of directories\n headers = []\n for dir in directory_list:\n head = glob.glob(os.path.join(dir,\"*.h\")) #XXX: *.hpp files??\n headers.extend(head)\n return headers\n\ndef _get_directories(list_of_sources):\n # get unique directories from list of sources.\n direcs = []\n for file in list_of_sources:\n dir = os.path.split(file)\n if dir[0] != '' and not dir[0] in direcs:\n direcs.append(dir[0])\n return direcs\n\ndef get_dependencies(sources):\n #XXX scan sources for include statements\n return _get_headers(_get_directories(sources))\n\ndef is_local_src_dir(directory):\n \"\"\" Return true if directory is local directory.\n \"\"\"\n if not is_string(directory):\n return False\n abs_dir = os.path.abspath(directory)\n c = os.path.commonprefix([os.getcwd(),abs_dir])\n new_dir = abs_dir[len(c):].split(os.sep)\n if new_dir and not new_dir[0]:\n new_dir = new_dir[1:]\n if new_dir and new_dir[0]=='build':\n return False\n new_dir = os.sep.join(new_dir)\n return os.path.isdir(new_dir)\n\ndef _gsf_visit_func(filenames,dirname,names):\n if os.path.basename(dirname) in ['CVS','.svn','build']:\n names[:] = []\n return\n for name in names:\n if name[-1] in \"~#\":\n continue\n fullname = os.path.join(dirname,name)\n ext = os.path.splitext(fullname)[1]\n if ext and ext in ['.pyc','.o']:\n continue\n if os.path.isfile(fullname):\n filenames.append(fullname)\n\ndef get_ext_source_files(ext):\n # Get sources and any include files in the same directory.\n filenames = []\n sources = filter(is_string, ext.sources)\n filenames.extend(sources)\n filenames.extend(get_dependencies(sources))\n for d in ext.depends:\n if is_local_src_dir(d):\n os.path.walk(d,_gsf_visit_func,filenames)\n elif os.path.isfile(d):\n filenames.append(d)\n return filenames\n\ndef get_script_files(scripts):\n scripts = filter(is_string, scripts)\n return scripts\n\ndef get_lib_source_files(lib):\n filenames = []\n sources = lib[1].get('sources',[])\n sources = filter(is_string, sources)\n filenames.extend(sources)\n filenames.extend(get_dependencies(sources))\n depends = lib[1].get('depends',[])\n for d in depends:\n if is_local_src_dir(d):\n os.path.walk(d,_gsf_visit_func,filenames)\n elif os.path.isfile(d):\n filenames.append(d)\n return filenames\n\ndef get_data_files(data):\n if is_string(data):\n return [data]\n sources = data[1]\n filenames = []\n for s in sources:\n if callable(s):\n continue\n if is_local_src_dir(s):\n os.path.walk(s,_gsf_visit_func,filenames)\n elif is_string(s):\n if os.path.isfile(s):\n filenames.append(s)\n else:\n print 'Not existing data file:',s\n else:\n raise TypeError,repr(s)\n return filenames\n\ndef dot_join(*args):\n return '.'.join(filter(None,args))\n\ndef get_frame(level=0):\n try:\n return sys._getframe(level+1)\n except AttributeError:\n frame = sys.exc_info()[2].tb_frame\n for i in range(level+1):\n frame = frame.f_back\n return frame\n\n######################\n\ndef command_line_ok(_cache=[]):\n \"\"\" Return True if command line does not contain any\n help or display requests.\n \"\"\"\n if _cache:\n return _cache[0]\n ok = True\n from distutils.dist import Distribution\n display_opts = ['--'+n for n in Distribution.display_option_names]\n for o in Distribution.display_options:\n if o[1]: display_opts.append('-'+o[1])\n for arg in sys.argv:\n if arg.startswith('--help') or arg=='-h' or arg in display_opts:\n ok = False\n break\n _cache.append(ok)\n return ok\n\nclass Configuration:\n\n _list_keys = ['packages','ext_modules','data_files','include_dirs',\n 'libraries','headers','scripts','py_modules']\n _dict_keys = ['package_dir']\n\n numpy_include_dirs = []\n\n def __init__(self,\n package_name=None,\n parent_name=None,\n top_path=None,\n package_path=None,\n **attrs):\n \"\"\" Construct configuration instance of a package.\n\n package_name -- name of the package\n Ex.: 'distutils'\n parent_name -- name of the parent package\n Ex.: 'numpy'\n top_path -- directory of the toplevel package\n Ex.: the directory where the numpy package source sits\n package_path -- directory of package. Will be computed by magic from the\n directory of the caller module if not specified\n Ex.: the directory where numpy.distutils is\n \"\"\"\n self.name = dot_join(parent_name, package_name)\n\n caller_frame = get_frame(1)\n caller_name = eval('__name__',caller_frame.f_globals,caller_frame.f_locals)\n\n self.local_path = get_path(caller_name, top_path)\n if top_path is None:\n top_path = self.local_path\n if package_path is None:\n package_path = self.local_path\n elif os.path.isdir(njoin(self.local_path,package_path)):\n package_path = njoin(self.local_path,package_path)\n if not os.path.isdir(package_path):\n raise ValueError(\"%r is not a directory\" % (package_path,))\n self.top_path = top_path\n self.package_path = package_path\n # this is the relative path in the installed package\n self.path_in_package = os.path.join(*self.name.split('.'))\n\n self.list_keys = copy.copy(self._list_keys)\n self.dict_keys = copy.copy(self._dict_keys)\n\n for n in self.list_keys:\n setattr(self,n,copy.copy(attrs.get(n,[])))\n\n for n in self.dict_keys:\n setattr(self,n,copy.copy(attrs.get(n,{})))\n\n known_keys = self.list_keys + self.dict_keys\n self.extra_keys = []\n for n in attrs.keys():\n if n in known_keys:\n continue\n a = attrs[n]\n setattr(self,n,a)\n if isinstance(a, list):\n self.list_keys.append(n)\n elif isinstance(a, dict):\n self.dict_keys.append(n)\n else:\n self.extra_keys.append(n)\n\n if os.path.exists(njoin(package_path,'__init__.py')):\n self.packages.append(self.name)\n self.package_dir[self.name] = package_path\n\n self.options = dict(\\\n ignore_setup_xxx_py = False,\n assume_default_configuration = False,\n delegate_options_to_subpackages = False,\n quiet = False,\n )\n\n for i in range(1,3):\n f = get_frame(i)\n try:\n caller_instance = eval('self',f.f_globals,f.f_locals)\n break\n except NameError:\n caller_instance = None\n if isinstance(caller_instance, self.__class__):\n if caller_instance.options['delegate_options_to_subpackages']:\n self.set_options(**caller_instance.options)\n\n return\n\n def todict(self):\n \"\"\" Return configuration distionary suitable for passing\n to distutils.core.setup() function.\n \"\"\"\n d = {}\n for n in self.list_keys + self.dict_keys + self.extra_keys:\n a = getattr(self,n)\n if a:\n d[n] = a\n if self.name:\n d['name'] = self.name\n return d\n\n def info(self, message):\n if not self.options['quiet']:\n print message\n\n def warn(self, message):\n print>>sys.stderr, 'Warning:',message\n\n\n def set_options(self, **options):\n \"\"\" Configure Configuration instance.\n\n The following options are available:\n - ignore_setup_xxx_py\n - assume_default_configuration\n - delegate_options_to_subpackages\n - quiet\n \"\"\"\n for key, value in options.items():\n if self.options.has_key(key):\n self.options[key] = value\n else:\n raise ValueError,'Unknown option: '+key\n return\n def __dict__(self):\n return self.todict()\n\n def get_distribution(self):\n import distutils.core\n dist = distutils.core._setup_distribution\n return dist\n\n def get_subpackage(self,subpackage_name,subpackage_path=None):\n \"\"\" Return subpackage configuration.\n \"\"\"\n if subpackage_name is None:\n assert subpackage_path is not None\n subpackage_name = os.path.basename(subpackage_path)\n l = subpackage_name.split('.')\n if subpackage_path is None:\n subpackage_path = njoin(*([self.local_path]+l))\n if '*' in subpackage_name:\n dirs = filter(os.path.isdir,glob.glob(subpackage_path))\n config_list = []\n for d in dirs:\n if not os.path.isfile(njoin(d,'__init__.py')):\n continue\n if 'build' in d.split(os.sep):\n continue\n n = '.'.join(d.split(os.sep)[-len(l):])\n c = self.get_subpackage(n)\n if c:\n config_list.append(c)\n return config_list\n else:\n subpackage_path = njoin(*([subpackage_path]+l[:-1]))\n subpackage_path = self._fix_paths([subpackage_path])[0]\n\n setup_py = njoin(subpackage_path,'setup.py')\n if not self.options['ignore_setup_xxx_py']:\n if not os.path.isfile(setup_py):\n setup_py = njoin(subpackage_path,'setup_%s.py' % (subpackage_name))\n\n if not os.path.isfile(setup_py):\n if not self.options['assume_default_configuration']:\n self.warn('Assuming default configuration '\\\n '(%s/{setup_%s,setup}.py was not found)' \\\n % (os.path.dirname(setup_py),subpackage_name))\n config = Configuration(subpackage_name,self.name,\n self.top_path,subpackage_path)\n else:\n # In case setup_py imports local modules:\n sys.path.insert(0,os.path.dirname(setup_py))\n try:\n info = (open(setup_py),setup_py,('.py','U',1))\n setup_name = os.path.splitext(os.path.basename(setup_py))[0]\n n = dot_join(self.name,setup_name)\n setup_module = imp.load_module('_'.join(n.split('.')),*info)\n\n if not hasattr(setup_module,'configuration'):\n if not self.options['assume_default_configuration']:\n self.warn('Assuming default configuration '\\\n '(%s does not define configuration())'\\\n % (setup_module))\n config = Configuration(subpackage_name,self.name,\n self.top_path,subpackage_path)\n else:\n args = (self.name,)\n if setup_module.configuration.func_code.co_argcount>1:\n args = args + (self.top_path,)\n config = setup_module.configuration(*args)\n\n finally:\n del sys.path[0]\n\n return config\n\n def add_subpackage(self,subpackage_name,subpackage_path=None):\n \"\"\" Add subpackage to configuration.\n \"\"\"\n config = self.get_subpackage(subpackage_name,subpackage_path)\n if not isinstance(config, list):\n config_list = [config]\n else:\n config_list = config\n for config in config_list:\n if not config:\n self.warn('No configuration returned, assuming unavailable.')\n else:\n if isinstance(config,Configuration):\n self.info('Appending %s configuration to %s' \\\n % (config.name,self.name))\n self.dict_append(**config.todict())\n else:\n self.info('Appending %s configuration to %s' \\\n % (config.get('name'),self.name))\n self.dict_append(**config)\n\n dist = self.get_distribution()\n if dist is not None:\n self.warn('distutils distribution has been initialized,'\\\n ' it may be too late to add a subpackage '+ subpackage_name)\n return\n\n def add_data_dir(self,data_path):\n \"\"\" Recursively add files under data_path to data_files list.\n Argument can be either\n - 2-sequence (,)\n - path to data directory where python datadir suffix defaults\n to package dir.\n If path is not absolute then it's datadir suffix is\n package dir + subdirname of the path.\n \"\"\"\n if is_sequence(data_path):\n d, data_path = data_path\n else:\n d = None\n if not is_string(data_path):\n raise TypeError(\"not a string: %r\" % (data_path,))\n for path in self.paths(data_path):\n if not os.path.exists(path):\n continue\n filenames = []\n os.path.walk(path, _gsf_visit_func,filenames)\n if not os.path.isabs(path):\n npath = data_path\n if '*' in npath:\n npath = os.path.join(*(path.split(os.sep)[-len(npath.split(os.sep)):]))\n if d is None:\n d = self.path_in_package\n ds = os.path.join(d, npath)\n self.add_data_files((ds,filenames))\n else:\n if d is None:\n self.add_data_files(*filenames)\n else:\n self.add_data_files((d,filenames))\n return\n\n def add_data_files(self,*files):\n \"\"\" Add data files to configuration data_files.\n Argument(s) can be either\n - 2-sequence (,)\n - paths to data files where python datadir prefix defaults\n to package dir.\n If path is not absolute then it's datadir prefix is\n package dir + dirname of the path.\n \"\"\"\n data_dict = {}\n new_files = []\n for p in files:\n if not is_sequence(p):\n d = self.path_in_package\n if is_string(p) and not os.path.isabs(p):\n pd = os.path.dirname(p)\n if '*' in pd:\n pn = os.path.basename(p)\n n = len(pd.split(os.sep))\n for d1 in filter(os.path.isdir,self.paths(pd)):\n p = os.path.join(d1,pn)\n d1 = os.sep.join(d1.split(os.sep)[-n:])\n new_files.append((appendpath(d,d1),p))\n continue\n d = appendpath(d,pd)\n p = (d,p) \n new_files.append(p)\n \n files = []\n for prefix,filepattern in new_files:\n assert '*' not in prefix,`prefix,filepattern`\n if is_string(filepattern):\n file_list = self.paths(filepattern,include_non_existing=False)\n elif callable(filepattern):\n file_list = [filepattern]\n else:\n file_list = self.paths(*filepattern)\n\n nof_path_components = [len(f.split(os.sep))\n for f in file_list if is_string(f)]\n if nof_path_components:\n min_path_components = min(nof_path_components)-1\n else:\n min_path_components = 0\n\n for f in file_list:\n if is_string(f):\n extra_path_components = f.split(os.sep)[min_path_components:-1]\n p = njoin(*([prefix]+extra_path_components))\n else:\n p = prefix\n if not data_dict.has_key(p):\n data_dict[p] = [f]\n else:\n data_dict[p].append(f)\n\n dist = self.get_distribution()\n if dist is not None:\n dist.data_files.extend(data_dict.items())\n else:\n self.data_files.extend(data_dict.items())\n\n ### XXX Implement add_py_modules\n\n def add_include_dirs(self,*paths):\n \"\"\" Add paths to configuration include directories.\n \"\"\"\n include_dirs = self._fix_paths(paths)\n dist = self.get_distribution()\n if dist is not None:\n dist.include_dirs.extend(include_dirs)\n else:\n self.include_dirs.extend(include_dirs)\n return\n\n def add_headers(self,*files):\n \"\"\" Add installable headers to configuration.\n Argument(s) can be either\n - 2-sequence (,)\n - path(s) to header file(s) where python includedir suffix will default\n to package name.\n \"\"\"\n headers = []\n for path in files:\n if is_string(path):\n [headers.append((self.name,p)) for p in self.paths(path)]\n else:\n if not isinstance(path, (tuple, list)) or len(path) != 2:\n raise TypeError(repr(path))\n [headers.append((path[0],p)) for p in self.paths(path[1])]\n dist = self.get_distribution()\n if dist is not None:\n dist.headers.extend(headers)\n else:\n self.headers.extend(headers)\n return\n\n def _fix_paths(self,paths,include_non_existing=True):\n assert isinstance(paths,(list,tuple)),`type(paths)`\n new_paths = []\n for n in paths:\n if isinstance(n,str):\n if '*' in n or '?' in n:\n p = glob.glob(n)\n p2 = glob.glob(njoin(self.local_path,n))\n if p2:\n new_paths.extend(p2)\n elif p:\n new_paths.extend(p)\n else:\n if include_non_existing:\n new_paths.append(n)\n self.warn('could not resolve pattern in %s: %r' \\\n % (self.local_path,n))\n else:\n n2 = njoin(self.local_path,n)\n if os.path.exists(n2):\n new_paths.append(n2)\n else:\n if os.path.exists(n):\n new_paths.append(n)\n elif include_non_existing:\n new_paths.append(n)\n if not os.path.exists(n):\n self.warn('not existing data path in %s: %s' \\\n % (self.local_path,n))\n else:\n new_paths.append(n)\n return map(minrelpath,new_paths)\n\n def paths(self,*paths,**kws):\n \"\"\" Apply glob to paths and prepend local_path if needed.\n \"\"\"\n include_non_existing = kws.get('include_non_existing',True)\n return self._fix_paths(paths,\n include_non_existing=include_non_existing)\n\n def add_extension(self,name,sources,**kw):\n \"\"\" Add extension to configuration.\n\n Keywords:\n include_dirs, define_macros, undef_macros,\n library_dirs, libraries, runtime_library_dirs,\n extra_objects, extra_compile_args, extra_link_args,\n export_symbols, swig_opts, depends, language,\n f2py_options, module_dirs\n extra_info - dict or list of dict of keywords to be\n appended to keywords.\n \"\"\"\n ext_args = copy.copy(kw)\n ext_args['name'] = dot_join(self.name,name)\n ext_args['sources'] = sources\n\n if ext_args.has_key('extra_info'):\n extra_info = ext_args['extra_info']\n del ext_args['extra_info']\n if type(extra_info) is type({}):\n extra_info = [extra_info]\n for info in extra_info:\n assert type(info) is type({}),`info`\n dict_append(ext_args,**info)\n\n for k in ext_args.keys():\n v = ext_args[k]\n if k in ['sources','depends','include_dirs','library_dirs',\n 'module_dirs','extra_objects']:\n new_v = self._fix_paths(v)\n ext_args[k] = new_v\n\n # Resolve out-of-tree dependencies\n libraries = ext_args.get('libraries',[])\n libnames = []\n ext_args['libraries'] = []\n for libname in libraries:\n if '@' in libname:\n lname,lpath = libname.split('@',1)\n lpath = os.path.abspath(njoin(self.local_path,lpath))\n if os.path.isdir(lpath):\n c = self.get_subpackage(None,lpath)\n if isinstance(c,Configuration):\n c = c.todict()\n for l in [l[0] for l in c.get('libraries',[])]:\n llname = l.split('__OF__',1)[0]\n if llname == lname:\n c.pop('name',None)\n dict_append(ext_args,**c)\n break\n continue\n libnames.append(libname)\n\n ext_args['libraries'] = libnames + ext_args['libraries']\n\n from numpy.distutils.core import Extension\n ext = Extension(**ext_args)\n self.ext_modules.append(ext)\n\n dist = self.get_distribution()\n if dist is not None:\n self.warn('distutils distribution has been initialized,'\\\n ' it may be too late to add an extension '+name)\n return ext\n\n def add_library(self,name,sources,**build_info):\n \"\"\" Add library to configuration.\n\n Valid keywords for build_info:\n depends\n macros\n include_dirs\n extra_compiler_args\n f2py_options\n \"\"\"\n build_info = copy.copy(build_info)\n name = name #+ '__OF__' + self.name\n build_info['sources'] = sources\n\n for k in build_info.keys():\n v = build_info[k]\n if k in ['sources','depends','include_dirs','library_dirs',\n 'module_dirs','extra_objects']:\n new_v = self._fix_paths(v)\n build_info[k] = new_v\n self.libraries.append((name,build_info))\n\n dist = self.get_distribution()\n if dist is not None:\n self.warn('distutils distribution has been initialized,'\\\n ' it may be too late to add a library '+ name)\n return\n\n def add_scripts(self,*files):\n \"\"\" Add scripts to configuration.\n \"\"\"\n scripts = self._fix_paths(files)\n dist = self.get_distribution()\n if dist is not None:\n dist.scripts.extend(scripts)\n else:\n self.scripts.extend(scripts)\n return\n\n def dict_append(self,**dict):\n for key in self.list_keys:\n a = getattr(self,key)\n a.extend(dict.get(key,[]))\n for key in self.dict_keys:\n a = getattr(self,key)\n a.update(dict.get(key,{}))\n known_keys = self.list_keys + self.dict_keys + self.extra_keys\n for key in dict.keys():\n if key not in known_keys and not hasattr(self,key):\n if key not in ['version']:\n self.warn('Inheriting attribute %r from %r' \\\n % (key,dict.get('name','?')))\n setattr(self,key,dict[key])\n self.extra_keys.append(key)\n return\n\n def __str__(self):\n known_keys = self.list_keys + self.dict_keys + self.extra_keys\n s = '<'+5*'-' + '\\n'\n s += 'Configuration of '+self.name+':\\n'\n for k in known_keys:\n a = getattr(self,k,None)\n if a:\n s += '%s = %r\\n' % (k,a)\n s += 5*'-' + '>'\n return s\n\n def get_config_cmd(self):\n cmd = get_cmd('config')\n cmd.ensure_finalized()\n cmd.dump_source = 0\n cmd.noisy = 0\n old_path = os.environ.get('PATH')\n if old_path:\n path = os.pathsep.join(['.',old_path])\n os.environ['PATH'] = path\n return cmd\n\n def get_build_temp_dir(self):\n cmd = get_cmd('build')\n cmd.ensure_finalized()\n return cmd.build_temp\n\n def have_f77c(self):\n \"\"\" Check for availability of Fortran 77 compiler.\n Use it inside source generating function to ensure that\n setup distribution instance has been initialized.\n \"\"\"\n simple_fortran_subroutine = '''\n subroutine simple\n end\n '''\n config_cmd = self.get_config_cmd()\n flag = config_cmd.try_compile(simple_fortran_subroutine,lang='f77')\n return flag\n\n def have_f90c(self):\n \"\"\" Check for availability of Fortran 90 compiler.\n Use it inside source generating function to ensure that\n setup distribution instance has been initialized.\n \"\"\"\n simple_fortran_subroutine = '''\n subroutine simple\n end\n '''\n config_cmd = self.get_config_cmd()\n flag = config_cmd.try_compile(simple_fortran_subroutine,lang='f90')\n return flag\n\n def append_to(self, extlib):\n \"\"\" Append libraries, include_dirs to extension or library item.\n \"\"\"\n if is_sequence(extlib):\n lib_name, build_info = extlib\n dict_append(build_info,\n libraries=self.libraries,\n include_dirs=self.include_dirs)\n else:\n from numpy.distutils.core import Extension\n assert isinstance(extlib,Extension),`extlib`\n extlib.libraries.extend(self.libraries)\n extlib.include_dirs.extend(self.include_dirs)\n return\n\n def _get_svn_revision(self,path):\n \"\"\" Return path's SVN revision number.\n \"\"\"\n entries = njoin(path,'.svn','entries')\n revision = None\n if os.path.isfile(entries):\n f = open(entries)\n m = re.search(r'revision=\"(?P\\d+)\"',f.read())\n f.close()\n if m:\n revision = int(m.group('revision'))\n return revision\n\n def get_version(self):\n \"\"\" Try to get version string of a package.\n \"\"\"\n version = getattr(self,'version',None)\n if version is not None:\n return version\n\n # Get version from version file.\n files = ['__version__.py',\n self.name.split('.')[-1]+'_version.py',\n 'version.py',\n '__svn_version__.py']\n version_vars = ['version',\n '__version__',\n self.name.split('.')[-1]+'_version']\n for f in files:\n fn = njoin(self.local_path,f)\n if os.path.isfile(fn):\n info = (open(fn),fn,('.py','U',1))\n name = os.path.splitext(os.path.basename(fn))[0]\n n = dot_join(self.name,name)\n try:\n version_module = imp.load_module('_'.join(n.split('.')),*info)\n except ImportError,msg:\n self.warn(str(msg))\n version_module = None\n if version_module is None:\n continue\n\n for a in version_vars:\n version = getattr(version_module,a,None)\n if version is not None:\n break\n if version is not None:\n break\n\n if version is not None:\n self.version = version\n return version\n\n # Get version as SVN revision number\n revision = self._get_svn_revision(self.local_path)\n if revision is not None:\n version = str(revision)\n self.version = version\n\n return version\n\n def make_svn_version_py(self):\n \"\"\" Generate package __svn_version__.py file from SVN revision number,\n it will be removed after python exits but will be available\n when sdist, etc commands are executed.\n\n If __svn_version__.py existed before, nothing is done.\n \"\"\"\n target = njoin(self.local_path,'__svn_version__.py')\n if os.path.isfile(target):\n return\n def generate_svn_version_py():\n if not os.path.isfile(target):\n revision = self._get_svn_revision(self.local_path)\n assert revision is not None,'hmm, why I am not inside SVN tree???'\n version = str(revision)\n self.info('Creating %s (version=%r)' % (target,version))\n f = open(target,'w')\n f.write('version = %r\\n' % (version))\n f.close()\n\n import atexit\n def rm_file(f=target,p=self.info):\n try: os.remove(f); p('removed '+f)\n except OSError: pass\n try: os.remove(f+'c'); p('removed '+f+'c')\n except OSError: pass\n atexit.register(rm_file)\n\n return target\n\n self.add_data_files((self.path_in_package, generate_svn_version_py()))\n return\n\n def make_config_py(self,name='__config__'):\n \"\"\" Generate package __config__.py file containing system_info\n information used during building the package.\n \"\"\"\n self.py_modules.append((self.name,name,generate_config_py))\n return\n\n def get_info(self,*names):\n \"\"\" Get resources information.\n \"\"\"\n from system_info import get_info, dict_append\n info_dict = {}\n for a in names:\n dict_append(info_dict,**get_info(a))\n return info_dict\n\n if not command_line_ok():\n _do_nothing = lambda *args,**kws: None\n add_subpackage = _do_nothing\n add_extension = _do_nothing\n add_library = _do_nothing\n add_data_dir = _do_nothing\n add_data_files = _do_nothing\n add_scripts = _do_nothing\n add_headers = _do_nothing\n add_include_dirs = _do_nothing\n make_config_py = _do_nothing\n get_info = lambda *args,**kws:{}\n have_f77c = lambda *args,**kws: False\n have_f90c = lambda *args,**kws: False\n\ndef get_cmd(cmdname,_cache={}):\n if not _cache.has_key(cmdname):\n import distutils.core\n dist = distutils.core._setup_distribution\n if dist is None:\n from distutils.errors import DistutilsInternalError\n raise DistutilsInternalError,\\\n 'setup distribution instance not initialized'\n cmd = dist.get_command_obj(cmdname)\n _cache[cmdname] = cmd\n return _cache[cmdname]\n\ndef get_numpy_include_dirs():\n # numpy_include_dirs are set by numpy/core/setup.py, otherwise []\n include_dirs = Configuration.numpy_include_dirs[:]\n if not include_dirs:\n import numpy\n if numpy.show_config is None:\n # running from numpy_core source directory\n include_dirs.append(njoin(os.path.dirname(numpy.__file__),\n 'core','include'))\n else:\n # using installed numpy core headers\n import numpy.core as core\n include_dirs.append(njoin(os.path.dirname(core.__file__),'include'))\n # else running numpy/core/setup.py\n return include_dirs\n\n#########################\n\ndef default_config_dict(name = None, parent_name = None, local_path=None):\n \"\"\" Return a configuration dictionary for usage in\n configuration() function defined in file setup_.py.\n \"\"\"\n import warnings\n warnings.warn('Use Configuration(%s,%s,top_path=%s) instead of '\\\n 'deprecated default_config_dict(%s,%s,%s)' \\\n % (`name`,`parent_name`,`local_path`,\n `name`,`parent_name`,`local_path`,\n ))\n c = Configuration(name, parent_name, local_path)\n return c.todict()\n\n\ndef dict_append(d,**kws):\n for k,v in kws.items():\n if d.has_key(k):\n d[k].extend(v)\n else:\n d[k] = v\n\ndef appendpath(prefix,path):\n if not ('/' == os.path.sep):\n prefix = prefix.replace('/',os.path.sep)\n path = path.replace('/',os.path.sep)\n drive = ''\n if os.path.isabs(path):\n drive = os.path.splitdrive(prefix)[0]\n absprefix = os.path.splitdrive(os.path.abspath(prefix))[1]\n pathdrive,path = os.path.splitdrive(path)\n d = os.path.commonprefix([absprefix,path])\n if os.path.join(absprefix[:len(d)],absprefix[len(d):])!=absprefix \\\n or os.path.join(path[:len(d)],path[len(d):])!=path:\n # Handle invalid paths\n d = os.path.dirname(d)\n subpath = path[len(d):]\n if os.path.isabs(subpath):\n subpath = subpath[1:]\n else:\n subpath = path\n return os.path.normpath(njoin(drive + prefix, subpath))\n\n\n\n\n\ndef generate_config_py(target):\n \"\"\" Generate config.py file containing system_info information\n used during building the package.\n\n Usage:\\\n config['py_modules'].append((packagename, '__config__',generate_config_py))\n \"\"\"\n from numpy.distutils.system_info import system_info\n from distutils.dir_util import mkpath\n mkpath(os.path.dirname(target))\n f = open(target,'w')\n f.write('# This file is generated by %s\\n' % (os.path.abspath(sys.argv[0])))\n f.write('# It contains system_info results at the time of building this package.\\n')\n f.write('__all__ = [\"get_info\",\"show\"]\\n\\n')\n for k,i in system_info.saved_results.items():\n f.write('%s=%r\\n' % (k,i))\n f.write('\\ndef get_info(name): g=globals(); return g.get(name,g.get(name+\"_info\",{}))\\n')\n f.write('''\ndef show():\n for name,info_dict in globals().items():\n if name[0]==\"_\" or type(info_dict) is not type({}): continue\n print name+\":\"\n if not info_dict:\n print \" NOT AVAILABLE\"\n for k,v in info_dict.items():\n v = str(v)\n if k==\\'sources\\' and len(v)>200: v = v[:60]+\\' ...\\\\n... \\'+v[-60:]\n print \\' %s = %s\\'%(k,v)\n print\n return\n ''')\n\n f.close()\n return target\n\ndef generate_svn_version_py(extension, build_dir):\n \"\"\" Generate __svn_version__.py file containing SVN\n revision number of a module.\n\n To use, add the following codelet to setup\n configuration(..) function\n\n ext = Extension(dot_join(config['name'],'__svn_version__'),\n sources=[generate_svn_version_py])\n ext.local_path = local_path\n config['ext_modules'].append(ext)\n\n \"\"\"\n from distutils import dep_util\n local_path = extension.local_path\n target = njoin(build_dir, '__svn_version__.py')\n entries = njoin(local_path,'.svn','entries')\n if os.path.isfile(entries):\n if not dep_util.newer(entries, target):\n return target\n elif os.path.isfile(target):\n return target\n\n revision = get_svn_revision(local_path)\n f = open(target,'w')\n f.write('revision=%s\\n' % (revision))\n f.close()\n return target\n", + "source_code_before": "import os\nimport re\nimport sys\nimport imp\nimport copy\nimport glob\n\n__all__ = ['Configuration', 'get_numpy_include_dirs', 'default_config_dict',\n 'dict_append', 'appendpath', 'generate_config_py',\n 'generate_svn_version_py', 'get_cmd', 'allpath',\n 'terminal_has_colors', 'red_text', 'green_text', 'yellow_text',\n 'blue_text', 'cyan_text', 'cyg2win32', 'all_strings',\n 'has_f_sources', 'has_cxx_sources', 'filter_sources',\n 'get_dependencies', 'is_local_src_dir', 'get_ext_source_files',\n 'get_script_files', 'get_lib_source_files', 'get_data_files',\n 'dot_join', 'get_frame', 'minrelpath','njoin']\n\ndef allpath(name):\n \"Convert a /-separated pathname to one using the OS's path separator.\"\n splitted = name.split('/')\n return os.path.join(*splitted)\n\ndef get_path(mod_name,parent_path=None):\n \"\"\" Return path of the module.\n\n Returned path is relative to parent_path when given,\n otherwise it is absolute path.\n \"\"\"\n if mod_name == '__main__':\n d = os.path.abspath('.')\n elif mod_name == '__builtin__':\n #builtin if/then added by Pearu for use in core.run_setup.\n d = os.path.dirname(os.path.abspath(sys.argv[0]))\n else:\n __import__(mod_name)\n mod = sys.modules[mod_name]\n file = mod.__file__\n d = os.path.dirname(os.path.abspath(file))\n if parent_path is not None:\n pd = os.path.abspath(parent_path)\n if pd==d[:len(pd)]:\n d = d[len(pd)+1:]\n return d or '.'\n\ndef njoin(*path):\n \"\"\" Join two or more pathname components +\n - convert a /-separated pathname to one using the OS's path separator.\n - resolve `..` from path.\n \"\"\"\n if isinstance(path,tuple):\n path = os.path.join(*path)\n if not isinstance(path,str): return path\n if not ('/' == os.path.sep):\n path = path.replace('/',os.path.sep)\n return minrelpath(path)\n\ndef minrelpath(path):\n \"\"\" Resolve `..` from path.\n \"\"\"\n if not isinstance(path, str): return path\n if '..' not in path: return path\n l = path.split(os.sep)\n j = 1\n while l:\n try:\n i = l.index('..',j)\n except ValueError:\n break\n if l[i-1]=='..':\n j += 1\n else:\n del l[i],l[i-1]\n j = 1\n if not l: return ''\n return os.path.join(*l)\n\n# Hooks for colored terminal output.\n# See also http://www.livinglogic.de/Python/ansistyle\ndef terminal_has_colors():\n if sys.platform=='cygwin' and not os.environ.has_key('USE_COLOR'):\n # Avoid importing curses that causes illegal operation\n # with a message:\n # PYTHON2 caused an invalid page fault in\n # module CYGNURSES7.DLL as 015f:18bbfc28\n # Details: Python 2.3.3 [GCC 3.3.1 (cygming special)]\n # ssh to Win32 machine from debian\n # curses.version is 2.2\n # CYGWIN_98-4.10, release 1.5.7(0.109/3/2))\n return 0\n if hasattr(sys.stdout,'isatty') and sys.stdout.isatty():\n try:\n import curses\n curses.setupterm()\n if (curses.tigetnum(\"colors\") >= 0\n and curses.tigetnum(\"pairs\") >= 0\n and ((curses.tigetstr(\"setf\") is not None\n and curses.tigetstr(\"setb\") is not None)\n or (curses.tigetstr(\"setaf\") is not None\n and curses.tigetstr(\"setab\") is not None)\n or curses.tigetstr(\"scp\") is not None)):\n return 1\n except Exception,msg:\n pass\n return 0\n\nif terminal_has_colors():\n def red_text(s): return '\\x1b[31m%s\\x1b[0m'%s\n def green_text(s): return '\\x1b[32m%s\\x1b[0m'%s\n def yellow_text(s): return '\\x1b[33m%s\\x1b[0m'%s\n def blue_text(s): return '\\x1b[34m%s\\x1b[0m'%s\n def cyan_text(s): return '\\x1b[35m%s\\x1b[0m'%s\nelse:\n def red_text(s): return s\n def green_text(s): return s\n def yellow_text(s): return s\n def cyan_text(s): return s\n def blue_text(s): return s\n\n#########################\n\ndef cyg2win32(path):\n if sys.platform=='cygwin' and path.startswith('/cygdrive'):\n path = path[10] + ':' + os.path.normcase(path[11:])\n return path\n\n#########################\n\n#XXX need support for .C that is also C++\ncxx_ext_match = re.compile(r'.*[.](cpp|cxx|cc)\\Z',re.I).match\nfortran_ext_match = re.compile(r'.*[.](f90|f95|f77|for|ftn|f)\\Z',re.I).match\nf90_ext_match = re.compile(r'.*[.](f90|f95)\\Z',re.I).match\nf90_module_name_match = re.compile(r'\\s*module\\s*(?P[\\w_]+)',re.I).match\ndef _get_f90_modules(source):\n \"\"\" Return a list of Fortran f90 module names that\n given source file defines.\n \"\"\"\n if not f90_ext_match(source):\n return []\n modules = []\n f = open(source,'r')\n f_readlines = getattr(f,'xreadlines',f.readlines)\n for line in f_readlines():\n m = f90_module_name_match(line)\n if m:\n name = m.group('name')\n modules.append(name)\n # break # XXX can we assume that there is one module per file?\n f.close()\n return modules\n\ndef is_string(s):\n return isinstance(s, str)\n\ndef all_strings(lst):\n \"\"\" Return True if all items in lst are string objects. \"\"\"\n for item in lst:\n if not is_string(item):\n return False\n return True\n\ndef is_sequence(seq):\n if is_string(seq):\n return False\n try:\n len(seq)\n except:\n return False\n return True\n\ndef has_f_sources(sources):\n \"\"\" Return True if sources contains Fortran files \"\"\"\n for source in sources:\n if fortran_ext_match(source):\n return True\n return False\n\ndef has_cxx_sources(sources):\n \"\"\" Return True if sources contains C++ files \"\"\"\n for source in sources:\n if cxx_ext_match(source):\n return True\n return False\n\ndef filter_sources(sources):\n \"\"\" Return four lists of filenames containing\n C, C++, Fortran, and Fortran 90 module sources,\n respectively.\n \"\"\"\n c_sources = []\n cxx_sources = []\n f_sources = []\n fmodule_sources = []\n for source in sources:\n if fortran_ext_match(source):\n modules = _get_f90_modules(source)\n if modules:\n fmodule_sources.append(source)\n else:\n f_sources.append(source)\n elif cxx_ext_match(source):\n cxx_sources.append(source)\n else:\n c_sources.append(source)\n return c_sources, cxx_sources, f_sources, fmodule_sources\n\n\ndef _get_headers(directory_list):\n # get *.h files from list of directories\n headers = []\n for dir in directory_list:\n head = glob.glob(os.path.join(dir,\"*.h\")) #XXX: *.hpp files??\n headers.extend(head)\n return headers\n\ndef _get_directories(list_of_sources):\n # get unique directories from list of sources.\n direcs = []\n for file in list_of_sources:\n dir = os.path.split(file)\n if dir[0] != '' and not dir[0] in direcs:\n direcs.append(dir[0])\n return direcs\n\ndef get_dependencies(sources):\n #XXX scan sources for include statements\n return _get_headers(_get_directories(sources))\n\ndef is_local_src_dir(directory):\n \"\"\" Return true if directory is local directory.\n \"\"\"\n if not is_string(directory):\n return False\n abs_dir = os.path.abspath(directory)\n c = os.path.commonprefix([os.getcwd(),abs_dir])\n new_dir = abs_dir[len(c):].split(os.sep)\n if new_dir and not new_dir[0]:\n new_dir = new_dir[1:]\n if new_dir and new_dir[0]=='build':\n return False\n new_dir = os.sep.join(new_dir)\n return os.path.isdir(new_dir)\n\ndef _gsf_visit_func(filenames,dirname,names):\n if os.path.basename(dirname) in ['CVS','.svn','build']:\n names[:] = []\n return\n for name in names:\n if name[-1] in \"~#\":\n continue\n fullname = os.path.join(dirname,name)\n ext = os.path.splitext(fullname)[1]\n if ext and ext in ['.pyc','.o']:\n continue\n if os.path.isfile(fullname):\n filenames.append(fullname)\n\ndef get_ext_source_files(ext):\n # Get sources and any include files in the same directory.\n filenames = []\n sources = filter(is_string, ext.sources)\n filenames.extend(sources)\n filenames.extend(get_dependencies(sources))\n for d in ext.depends:\n if is_local_src_dir(d):\n os.path.walk(d,_gsf_visit_func,filenames)\n elif os.path.isfile(d):\n filenames.append(d)\n return filenames\n\ndef get_script_files(scripts):\n scripts = filter(is_string, scripts)\n return scripts\n\ndef get_lib_source_files(lib):\n filenames = []\n sources = lib[1].get('sources',[])\n sources = filter(is_string, sources)\n filenames.extend(sources)\n filenames.extend(get_dependencies(sources))\n depends = lib[1].get('depends',[])\n for d in depends:\n if is_local_src_dir(d):\n os.path.walk(d,_gsf_visit_func,filenames)\n elif os.path.isfile(d):\n filenames.append(d)\n return filenames\n\ndef get_data_files(data):\n if is_string(data):\n return [data]\n sources = data[1]\n filenames = []\n for s in sources:\n if callable(s):\n continue\n if is_local_src_dir(s):\n os.path.walk(s,_gsf_visit_func,filenames)\n elif is_string(s):\n if os.path.isfile(s):\n filenames.append(s)\n else:\n print 'Not existing data file:',s\n else:\n raise TypeError,repr(s)\n return filenames\n\ndef dot_join(*args):\n return '.'.join(filter(None,args))\n\ndef get_frame(level=0):\n try:\n return sys._getframe(level+1)\n except AttributeError:\n frame = sys.exc_info()[2].tb_frame\n for i in range(level+1):\n frame = frame.f_back\n return frame\n\n######################\n\ndef command_line_ok(_cache=[]):\n \"\"\" Return True if command line does not contain any\n help or display requests.\n \"\"\"\n if _cache:\n return _cache[0]\n ok = True\n from distutils.dist import Distribution\n display_opts = ['--'+n for n in Distribution.display_option_names]\n for o in Distribution.display_options:\n if o[1]: display_opts.append('-'+o[1])\n for arg in sys.argv:\n if arg.startswith('--help') or arg=='-h' or arg in display_opts:\n ok = False\n break\n _cache.append(ok)\n return ok\n\nclass Configuration:\n\n _list_keys = ['packages','ext_modules','data_files','include_dirs',\n 'libraries','headers','scripts','py_modules']\n _dict_keys = ['package_dir']\n\n numpy_include_dirs = []\n\n def __init__(self,\n package_name=None,\n parent_name=None,\n top_path=None,\n package_path=None,\n **attrs):\n \"\"\" Construct configuration instance of a package.\n\n package_name -- name of the package\n Ex.: 'distutils'\n parent_name -- name of the parent package\n Ex.: 'numpy'\n top_path -- directory of the toplevel package\n Ex.: the directory where the numpy package source sits\n package_path -- directory of package. Will be computed by magic from the\n directory of the caller module if not specified\n Ex.: the directory where numpy.distutils is\n \"\"\"\n self.name = dot_join(parent_name, package_name)\n\n caller_frame = get_frame(1)\n caller_name = eval('__name__',caller_frame.f_globals,caller_frame.f_locals)\n\n self.local_path = get_path(caller_name, top_path)\n if top_path is None:\n top_path = self.local_path\n if package_path is None:\n package_path = self.local_path\n elif os.path.isdir(njoin(self.local_path,package_path)):\n package_path = njoin(self.local_path,package_path)\n if not os.path.isdir(package_path):\n raise ValueError(\"%r is not a directory\" % (package_path,))\n self.top_path = top_path\n self.package_path = package_path\n # this is the relative path in the installed package\n self.path_in_package = os.path.join(*self.name.split('.'))\n\n self.list_keys = copy.copy(self._list_keys)\n self.dict_keys = copy.copy(self._dict_keys)\n\n for n in self.list_keys:\n setattr(self,n,copy.copy(attrs.get(n,[])))\n\n for n in self.dict_keys:\n setattr(self,n,copy.copy(attrs.get(n,{})))\n\n known_keys = self.list_keys + self.dict_keys\n self.extra_keys = []\n for n in attrs.keys():\n if n in known_keys:\n continue\n a = attrs[n]\n setattr(self,n,a)\n if isinstance(a, list):\n self.list_keys.append(n)\n elif isinstance(a, dict):\n self.dict_keys.append(n)\n else:\n self.extra_keys.append(n)\n\n if os.path.exists(njoin(package_path,'__init__.py')):\n self.packages.append(self.name)\n self.package_dir[self.name] = package_path\n\n self.options = dict(\\\n ignore_setup_xxx_py = False,\n assume_default_configuration = False,\n delegate_options_to_subpackages = False,\n quiet = False,\n )\n\n for i in range(1,3):\n f = get_frame(i)\n try:\n caller_instance = eval('self',f.f_globals,f.f_locals)\n break\n except NameError:\n caller_instance = None\n if isinstance(caller_instance, self.__class__):\n if caller_instance.options['delegate_options_to_subpackages']:\n self.set_options(**caller_instance.options)\n\n return\n\n def todict(self):\n \"\"\" Return configuration distionary suitable for passing\n to distutils.core.setup() function.\n \"\"\"\n d = {}\n for n in self.list_keys + self.dict_keys + self.extra_keys:\n a = getattr(self,n)\n if a:\n d[n] = a\n if self.name:\n d['name'] = self.name\n return d\n\n def info(self, message):\n if not self.options['quiet']:\n print message\n\n def warn(self, message):\n print>>sys.stderr, 'Warning:',message\n\n\n def set_options(self, **options):\n \"\"\" Configure Configuration instance.\n\n The following options are available:\n - ignore_setup_xxx_py\n - assume_default_configuration\n - delegate_options_to_subpackages\n - quiet\n \"\"\"\n for key, value in options.items():\n if self.options.has_key(key):\n self.options[key] = value\n else:\n raise ValueError,'Unknown option: '+key\n return\n def __dict__(self):\n return self.todict()\n\n def get_distribution(self):\n import distutils.core\n dist = distutils.core._setup_distribution\n return dist\n\n def get_subpackage(self,subpackage_name,subpackage_path=None):\n \"\"\" Return subpackage configuration.\n \"\"\"\n if subpackage_name is None:\n assert subpackage_path is not None\n subpackage_name = os.path.basename(subpackage_path)\n l = subpackage_name.split('.')\n if subpackage_path is None:\n subpackage_path = njoin(*([self.local_path]+l))\n if '*' in subpackage_name:\n dirs = filter(os.path.isdir,glob.glob(subpackage_path))\n config_list = []\n for d in dirs:\n if not os.path.isfile(njoin(d,'__init__.py')):\n continue\n if 'build' in d.split(os.sep):\n continue\n n = '.'.join(d.split(os.sep)[-len(l):])\n c = self.get_subpackage(n)\n if c:\n config_list.append(c)\n return config_list\n else:\n subpackage_path = njoin(*([subpackage_path]+l[:-1]))\n subpackage_path = self._fix_paths([subpackage_path])[0]\n\n setup_py = njoin(subpackage_path,'setup.py')\n if not self.options['ignore_setup_xxx_py']:\n if not os.path.isfile(setup_py):\n setup_py = njoin(subpackage_path,'setup_%s.py' % (subpackage_name))\n\n if not os.path.isfile(setup_py):\n if not self.options['assume_default_configuration']:\n self.warn('Assuming default configuration '\\\n '(%s/{setup_%s,setup}.py was not found)' \\\n % (os.path.dirname(setup_py),subpackage_name))\n config = Configuration(subpackage_name,self.name,\n self.top_path,subpackage_path)\n else:\n # In case setup_py imports local modules:\n sys.path.insert(0,os.path.dirname(setup_py))\n try:\n info = (open(setup_py),setup_py,('.py','U',1))\n setup_name = os.path.splitext(os.path.basename(setup_py))[0]\n n = dot_join(self.name,setup_name)\n setup_module = imp.load_module('_'.join(n.split('.')),*info)\n\n if not hasattr(setup_module,'configuration'):\n if not self.options['assume_default_configuration']:\n self.warn('Assuming default configuration '\\\n '(%s does not define configuration())'\\\n % (setup_module))\n config = Configuration(subpackage_name,self.name,\n self.top_path,subpackage_path)\n else:\n args = (self.name,)\n if setup_module.configuration.func_code.co_argcount>1:\n args = args + (self.top_path,)\n config = setup_module.configuration(*args)\n\n finally:\n del sys.path[0]\n\n return config\n\n def add_subpackage(self,subpackage_name,subpackage_path=None):\n \"\"\" Add subpackage to configuration.\n \"\"\"\n config = self.get_subpackage(subpackage_name,subpackage_path)\n if not isinstance(config, list):\n config_list = [config]\n else:\n config_list = config\n for config in config_list:\n if not config:\n self.warn('No configuration returned, assuming unavailable.')\n else:\n if isinstance(config,Configuration):\n self.info('Appending %s configuration to %s' \\\n % (config.name,self.name))\n self.dict_append(**config.todict())\n else:\n self.info('Appending %s configuration to %s' \\\n % (config.get('name'),self.name))\n self.dict_append(**config)\n\n dist = self.get_distribution()\n if dist is not None:\n self.warn('distutils distribution has been initialized,'\\\n ' it may be too late to add a subpackage '+ subpackage_name)\n return\n\n def add_data_dir(self,data_path):\n \"\"\" Recursively add files under data_path to data_files list.\n Argument can be either\n - 2-sequence (,)\n - path to data directory where python datadir suffix defaults\n to package dir.\n If path is not absolute then it's datadir suffix is\n package dir + subdirname of the path.\n \"\"\"\n if is_sequence(data_path):\n d, data_path = data_path\n else:\n d = None\n if not is_string(data_path):\n raise TypeError(\"not a string: %r\" % (data_path,))\n for path in self.paths(data_path):\n if not os.path.exists(path):\n self.warn('Not existing data path: '+path)\n continue\n filenames = []\n os.path.walk(path, _gsf_visit_func,filenames)\n if not os.path.isabs(path):\n npath = data_path\n if '*' in npath:\n npath = os.path.join(*(path.split(os.sep)[-len(npath.split(os.sep)):]))\n if d is None:\n d = self.path_in_package\n ds = os.path.join(d, npath)\n self.add_data_files((ds,filenames))\n else:\n if d is None:\n self.add_data_files(*filenames)\n else:\n self.add_data_files((d,filenames))\n return\n\n def add_data_files(self,*files):\n \"\"\" Add data files to configuration data_files.\n Argument(s) can be either\n - 2-sequence (,)\n - paths to data files where python datadir prefix defaults\n to package dir.\n If path is not absolute then it's datadir prefix is\n package dir + dirname of the path.\n \"\"\"\n data_dict = {}\n new_files = []\n for p in files:\n if not is_sequence(p):\n d = self.path_in_package\n if is_string(p) and not os.path.isabs(p):\n pd = os.path.dirname(p)\n if '*' in pd:\n pn = os.path.basename(p)\n n = len(pd.split(os.sep))\n for d1 in filter(os.path.isdir,self.paths(pd)):\n p = os.path.join(d1,pn)\n d1 = os.sep.join(d1.split(os.sep)[-n:])\n new_files.append((appendpath(d,d1),p))\n continue\n d = appendpath(d,pd)\n p = (d,p) \n new_files.append(p)\n \n files = []\n for prefix,filepattern in new_files:\n assert '*' not in prefix,`prefix,filepattern`\n if is_string(filepattern):\n file_list = self.paths(filepattern,include_non_existing=False)\n elif callable(filepattern):\n file_list = [filepattern]\n else:\n file_list = self.paths(*filepattern)\n\n nof_path_components = [len(f.split(os.sep))\n for f in file_list if is_string(f)]\n if nof_path_components:\n min_path_components = min(nof_path_components)-1\n else:\n min_path_components = 0\n\n for f in file_list:\n if is_string(f):\n extra_path_components = f.split(os.sep)[min_path_components:-1]\n p = njoin(*([prefix]+extra_path_components))\n else:\n p = prefix\n if not data_dict.has_key(p):\n data_dict[p] = [f]\n else:\n data_dict[p].append(f)\n\n dist = self.get_distribution()\n if dist is not None:\n dist.data_files.extend(data_dict.items())\n else:\n self.data_files.extend(data_dict.items())\n\n ### XXX Implement add_py_modules\n\n def add_include_dirs(self,*paths):\n \"\"\" Add paths to configuration include directories.\n \"\"\"\n include_dirs = self._fix_paths(paths)\n dist = self.get_distribution()\n if dist is not None:\n dist.include_dirs.extend(include_dirs)\n else:\n self.include_dirs.extend(include_dirs)\n return\n\n def add_headers(self,*files):\n \"\"\" Add installable headers to configuration.\n Argument(s) can be either\n - 2-sequence (,)\n - path(s) to header file(s) where python includedir suffix will default\n to package name.\n \"\"\"\n headers = []\n for path in files:\n if is_string(path):\n [headers.append((self.name,p)) for p in self.paths(path)]\n else:\n if not isinstance(path, (tuple, list)) or len(path) != 2:\n raise TypeError(repr(path))\n [headers.append((path[0],p)) for p in self.paths(path[1])]\n dist = self.get_distribution()\n if dist is not None:\n dist.headers.extend(headers)\n else:\n self.headers.extend(headers)\n return\n\n def _fix_paths(self,paths,include_non_existing=True):\n assert isinstance(paths,(list,tuple)),`type(paths)`\n new_paths = []\n for n in paths:\n if isinstance(n,str):\n if '*' in n or '?' in n:\n p = glob.glob(n)\n p2 = glob.glob(njoin(self.local_path,n))\n if p2:\n new_paths.extend(p2)\n elif p:\n new_paths.extend(p)\n else:\n if include_non_existing:\n new_paths.append(n)\n self.warn('could not resolve pattern: %r' % (n))\n else:\n n2 = njoin(self.local_path,n)\n if os.path.exists(n2):\n new_paths.append(n2)\n else:\n if os.path.exists(n):\n new_paths.append(n)\n elif include_non_existing:\n new_paths.append(n)\n if not os.path.exists(n):\n self.warn('not existing path: %r' % (n))\n else:\n new_paths.append(n)\n return map(minrelpath,new_paths)\n\n def paths(self,*paths,**kws):\n \"\"\" Apply glob to paths and prepend local_path if needed.\n \"\"\"\n include_non_existing = kws.get('include_non_existing',True)\n return self._fix_paths(paths,\n include_non_existing=include_non_existing)\n\n def add_extension(self,name,sources,**kw):\n \"\"\" Add extension to configuration.\n\n Keywords:\n include_dirs, define_macros, undef_macros,\n library_dirs, libraries, runtime_library_dirs,\n extra_objects, extra_compile_args, extra_link_args,\n export_symbols, swig_opts, depends, language,\n f2py_options, module_dirs\n extra_info - dict or list of dict of keywords to be\n appended to keywords.\n \"\"\"\n ext_args = copy.copy(kw)\n ext_args['name'] = dot_join(self.name,name)\n ext_args['sources'] = sources\n\n if ext_args.has_key('extra_info'):\n extra_info = ext_args['extra_info']\n del ext_args['extra_info']\n if type(extra_info) is type({}):\n extra_info = [extra_info]\n for info in extra_info:\n assert type(info) is type({}),`info`\n dict_append(ext_args,**info)\n\n for k in ext_args.keys():\n v = ext_args[k]\n if k in ['sources','depends','include_dirs','library_dirs',\n 'module_dirs','extra_objects']:\n new_v = self._fix_paths(v)\n ext_args[k] = new_v\n\n # Resolve out-of-tree dependencies\n libraries = ext_args.get('libraries',[])\n libnames = []\n ext_args['libraries'] = []\n for libname in libraries:\n if '@' in libname:\n lname,lpath = libname.split('@',1)\n lpath = os.path.abspath(njoin(self.local_path,lpath))\n if os.path.isdir(lpath):\n c = self.get_subpackage(None,lpath)\n if isinstance(c,Configuration):\n c = c.todict()\n for l in [l[0] for l in c.get('libraries',[])]:\n llname = l.split('__OF__',1)[0]\n if llname == lname:\n c.pop('name',None)\n dict_append(ext_args,**c)\n break\n continue\n libnames.append(libname)\n\n ext_args['libraries'] = libnames + ext_args['libraries']\n\n from numpy.distutils.core import Extension\n ext = Extension(**ext_args)\n self.ext_modules.append(ext)\n\n dist = self.get_distribution()\n if dist is not None:\n self.warn('distutils distribution has been initialized,'\\\n ' it may be too late to add an extension '+name)\n return ext\n\n def add_library(self,name,sources,**build_info):\n \"\"\" Add library to configuration.\n\n Valid keywords for build_info:\n depends\n macros\n include_dirs\n extra_compiler_args\n f2py_options\n \"\"\"\n build_info = copy.copy(build_info)\n name = name #+ '__OF__' + self.name\n build_info['sources'] = sources\n\n for k in build_info.keys():\n v = build_info[k]\n if k in ['sources','depends','include_dirs','library_dirs',\n 'module_dirs','extra_objects']:\n new_v = self._fix_paths(v)\n build_info[k] = new_v\n self.libraries.append((name,build_info))\n\n dist = self.get_distribution()\n if dist is not None:\n self.warn('distutils distribution has been initialized,'\\\n ' it may be too late to add a library '+ name)\n return\n\n def add_scripts(self,*files):\n \"\"\" Add scripts to configuration.\n \"\"\"\n scripts = self._fix_paths(files)\n dist = self.get_distribution()\n if dist is not None:\n dist.scripts.extend(scripts)\n else:\n self.scripts.extend(scripts)\n return\n\n def dict_append(self,**dict):\n for key in self.list_keys:\n a = getattr(self,key)\n a.extend(dict.get(key,[]))\n for key in self.dict_keys:\n a = getattr(self,key)\n a.update(dict.get(key,{}))\n known_keys = self.list_keys + self.dict_keys + self.extra_keys\n for key in dict.keys():\n if key not in known_keys and not hasattr(self,key):\n if key not in ['version']:\n self.warn('Inheriting attribute %r from %r' \\\n % (key,dict.get('name','?')))\n setattr(self,key,dict[key])\n self.extra_keys.append(key)\n return\n\n def __str__(self):\n known_keys = self.list_keys + self.dict_keys + self.extra_keys\n s = '<'+5*'-' + '\\n'\n s += 'Configuration of '+self.name+':\\n'\n for k in known_keys:\n a = getattr(self,k,None)\n if a:\n s += '%s = %r\\n' % (k,a)\n s += 5*'-' + '>'\n return s\n\n def get_config_cmd(self):\n cmd = get_cmd('config')\n cmd.ensure_finalized()\n cmd.dump_source = 0\n cmd.noisy = 0\n old_path = os.environ.get('PATH')\n if old_path:\n path = os.pathsep.join(['.',old_path])\n os.environ['PATH'] = path\n return cmd\n\n def get_build_temp_dir(self):\n cmd = get_cmd('build')\n cmd.ensure_finalized()\n return cmd.build_temp\n\n def have_f77c(self):\n \"\"\" Check for availability of Fortran 77 compiler.\n Use it inside source generating function to ensure that\n setup distribution instance has been initialized.\n \"\"\"\n simple_fortran_subroutine = '''\n subroutine simple\n end\n '''\n config_cmd = self.get_config_cmd()\n flag = config_cmd.try_compile(simple_fortran_subroutine,lang='f77')\n return flag\n\n def have_f90c(self):\n \"\"\" Check for availability of Fortran 90 compiler.\n Use it inside source generating function to ensure that\n setup distribution instance has been initialized.\n \"\"\"\n simple_fortran_subroutine = '''\n subroutine simple\n end\n '''\n config_cmd = self.get_config_cmd()\n flag = config_cmd.try_compile(simple_fortran_subroutine,lang='f90')\n return flag\n\n def append_to(self, extlib):\n \"\"\" Append libraries, include_dirs to extension or library item.\n \"\"\"\n if is_sequence(extlib):\n lib_name, build_info = extlib\n dict_append(build_info,\n libraries=self.libraries,\n include_dirs=self.include_dirs)\n else:\n from numpy.distutils.core import Extension\n assert isinstance(extlib,Extension),`extlib`\n extlib.libraries.extend(self.libraries)\n extlib.include_dirs.extend(self.include_dirs)\n return\n\n def _get_svn_revision(self,path):\n \"\"\" Return path's SVN revision number.\n \"\"\"\n entries = njoin(path,'.svn','entries')\n revision = None\n if os.path.isfile(entries):\n f = open(entries)\n m = re.search(r'revision=\"(?P\\d+)\"',f.read())\n f.close()\n if m:\n revision = int(m.group('revision'))\n return revision\n\n def get_version(self):\n \"\"\" Try to get version string of a package.\n \"\"\"\n version = getattr(self,'version',None)\n if version is not None:\n return version\n\n # Get version from version file.\n files = ['__version__.py',\n self.name.split('.')[-1]+'_version.py',\n 'version.py',\n '__svn_version__.py']\n version_vars = ['version',\n '__version__',\n self.name.split('.')[-1]+'_version']\n for f in files:\n fn = njoin(self.local_path,f)\n if os.path.isfile(fn):\n info = (open(fn),fn,('.py','U',1))\n name = os.path.splitext(os.path.basename(fn))[0]\n n = dot_join(self.name,name)\n try:\n version_module = imp.load_module('_'.join(n.split('.')),*info)\n except ImportError,msg:\n self.warn(str(msg))\n version_module = None\n if version_module is None:\n continue\n\n for a in version_vars:\n version = getattr(version_module,a,None)\n if version is not None:\n break\n if version is not None:\n break\n\n if version is not None:\n self.version = version\n return version\n\n # Get version as SVN revision number\n revision = self._get_svn_revision(self.local_path)\n if revision is not None:\n version = str(revision)\n self.version = version\n\n return version\n\n def make_svn_version_py(self):\n \"\"\" Generate package __svn_version__.py file from SVN revision number,\n it will be removed after python exits but will be available\n when sdist, etc commands are executed.\n\n If __svn_version__.py existed before, nothing is done.\n \"\"\"\n target = njoin(self.local_path,'__svn_version__.py')\n if os.path.isfile(target):\n return\n def generate_svn_version_py():\n if not os.path.isfile(target):\n revision = self._get_svn_revision(self.local_path)\n assert revision is not None,'hmm, why I am not inside SVN tree???'\n version = str(revision)\n self.info('Creating %s (version=%r)' % (target,version))\n f = open(target,'w')\n f.write('version = %r\\n' % (version))\n f.close()\n\n import atexit\n def rm_file(f=target,p=self.info):\n try: os.remove(f); p('removed '+f)\n except OSError: pass\n try: os.remove(f+'c'); p('removed '+f+'c')\n except OSError: pass\n atexit.register(rm_file)\n\n return target\n\n self.add_data_files((self.path_in_package, generate_svn_version_py()))\n return\n\n def make_config_py(self,name='__config__'):\n \"\"\" Generate package __config__.py file containing system_info\n information used during building the package.\n \"\"\"\n self.py_modules.append((self.name,name,generate_config_py))\n return\n\n def get_info(self,*names):\n \"\"\" Get resources information.\n \"\"\"\n from system_info import get_info, dict_append\n info_dict = {}\n for a in names:\n dict_append(info_dict,**get_info(a))\n return info_dict\n\n if not command_line_ok():\n _do_nothing = lambda *args,**kws: None\n add_subpackage = _do_nothing\n add_extension = _do_nothing\n add_library = _do_nothing\n add_data_dir = _do_nothing\n add_data_files = _do_nothing\n add_scripts = _do_nothing\n add_headers = _do_nothing\n add_include_dirs = _do_nothing\n make_config_py = _do_nothing\n get_info = lambda *args,**kws:{}\n have_f77c = lambda *args,**kws: False\n have_f90c = lambda *args,**kws: False\n\ndef get_cmd(cmdname,_cache={}):\n if not _cache.has_key(cmdname):\n import distutils.core\n dist = distutils.core._setup_distribution\n if dist is None:\n from distutils.errors import DistutilsInternalError\n raise DistutilsInternalError,\\\n 'setup distribution instance not initialized'\n cmd = dist.get_command_obj(cmdname)\n _cache[cmdname] = cmd\n return _cache[cmdname]\n\ndef get_numpy_include_dirs():\n # numpy_include_dirs are set by numpy/core/setup.py, otherwise []\n include_dirs = Configuration.numpy_include_dirs[:]\n if not include_dirs:\n import numpy\n if numpy.show_config is None:\n # running from numpy_core source directory\n include_dirs.append(njoin(os.path.dirname(numpy.__file__),\n 'core','include'))\n else:\n # using installed numpy core headers\n import numpy.core as core\n include_dirs.append(njoin(os.path.dirname(core.__file__),'include'))\n # else running numpy/core/setup.py\n return include_dirs\n\n#########################\n\ndef default_config_dict(name = None, parent_name = None, local_path=None):\n \"\"\" Return a configuration dictionary for usage in\n configuration() function defined in file setup_.py.\n \"\"\"\n import warnings\n warnings.warn('Use Configuration(%s,%s,top_path=%s) instead of '\\\n 'deprecated default_config_dict(%s,%s,%s)' \\\n % (`name`,`parent_name`,`local_path`,\n `name`,`parent_name`,`local_path`,\n ))\n c = Configuration(name, parent_name, local_path)\n return c.todict()\n\n\ndef dict_append(d,**kws):\n for k,v in kws.items():\n if d.has_key(k):\n d[k].extend(v)\n else:\n d[k] = v\n\ndef appendpath(prefix,path):\n if not ('/' == os.path.sep):\n prefix = prefix.replace('/',os.path.sep)\n path = path.replace('/',os.path.sep)\n drive = ''\n if os.path.isabs(path):\n drive = os.path.splitdrive(prefix)[0]\n absprefix = os.path.splitdrive(os.path.abspath(prefix))[1]\n pathdrive,path = os.path.splitdrive(path)\n d = os.path.commonprefix([absprefix,path])\n if os.path.join(absprefix[:len(d)],absprefix[len(d):])!=absprefix \\\n or os.path.join(path[:len(d)],path[len(d):])!=path:\n # Handle invalid paths\n d = os.path.dirname(d)\n subpath = path[len(d):]\n if os.path.isabs(subpath):\n subpath = subpath[1:]\n else:\n subpath = path\n return os.path.normpath(njoin(drive + prefix, subpath))\n\n\n\n\n\ndef generate_config_py(target):\n \"\"\" Generate config.py file containing system_info information\n used during building the package.\n\n Usage:\\\n config['py_modules'].append((packagename, '__config__',generate_config_py))\n \"\"\"\n from numpy.distutils.system_info import system_info\n from distutils.dir_util import mkpath\n mkpath(os.path.dirname(target))\n f = open(target,'w')\n f.write('# This file is generated by %s\\n' % (os.path.abspath(sys.argv[0])))\n f.write('# It contains system_info results at the time of building this package.\\n')\n f.write('__all__ = [\"get_info\",\"show\"]\\n\\n')\n for k,i in system_info.saved_results.items():\n f.write('%s=%r\\n' % (k,i))\n f.write('\\ndef get_info(name): g=globals(); return g.get(name,g.get(name+\"_info\",{}))\\n')\n f.write('''\ndef show():\n for name,info_dict in globals().items():\n if name[0]==\"_\" or type(info_dict) is not type({}): continue\n print name+\":\"\n if not info_dict:\n print \" NOT AVAILABLE\"\n for k,v in info_dict.items():\n v = str(v)\n if k==\\'sources\\' and len(v)>200: v = v[:60]+\\' ...\\\\n... \\'+v[-60:]\n print \\' %s = %s\\'%(k,v)\n print\n return\n ''')\n\n f.close()\n return target\n\ndef generate_svn_version_py(extension, build_dir):\n \"\"\" Generate __svn_version__.py file containing SVN\n revision number of a module.\n\n To use, add the following codelet to setup\n configuration(..) function\n\n ext = Extension(dot_join(config['name'],'__svn_version__'),\n sources=[generate_svn_version_py])\n ext.local_path = local_path\n config['ext_modules'].append(ext)\n\n \"\"\"\n from distutils import dep_util\n local_path = extension.local_path\n target = njoin(build_dir, '__svn_version__.py')\n entries = njoin(local_path,'.svn','entries')\n if os.path.isfile(entries):\n if not dep_util.newer(entries, target):\n return target\n elif os.path.isfile(target):\n return target\n\n revision = get_svn_revision(local_path)\n f = open(target,'w')\n f.write('revision=%s\\n' % (revision))\n f.close()\n return target\n", + "methods": [ + { + "name": "allpath", + "long_name": "allpath( name )", + "filename": "misc_util.py", + "nloc": 4, + "complexity": 1, + "token_count": 24, + "parameters": [ + "name" + ], + "start_line": 18, + "end_line": 21, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 4, + "top_nesting_level": 0 + }, + { + "name": "get_path", + "long_name": "get_path( mod_name , parent_path = None )", + "filename": "misc_util.py", + "nloc": 15, + "complexity": 6, + "token_count": 132, + "parameters": [ + "mod_name", + "parent_path" + ], + "start_line": 23, + "end_line": 43, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 21, + "top_nesting_level": 0 + }, + { + "name": "njoin", + "long_name": "njoin( * path )", + "filename": "misc_util.py", + "nloc": 7, + "complexity": 4, + "token_count": 68, + "parameters": [ + "path" + ], + "start_line": 45, + "end_line": 55, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 11, + "top_nesting_level": 0 + }, + { + "name": "minrelpath", + "long_name": "minrelpath( path )", + "filename": "misc_util.py", + "nloc": 17, + "complexity": 7, + "token_count": 103, + "parameters": [ + "path" + ], + "start_line": 57, + "end_line": 75, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 19, + "top_nesting_level": 0 + }, + { + "name": "terminal_has_colors", + "long_name": "terminal_has_colors( )", + "filename": "misc_util.py", + "nloc": 18, + "complexity": 13, + "token_count": 137, + "parameters": [], + "start_line": 79, + "end_line": 104, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 26, + "top_nesting_level": 0 + }, + { + "name": "cyg2win32", + "long_name": "cyg2win32( path )", + "filename": "misc_util.py", + "nloc": 4, + "complexity": 3, + "token_count": 42, + "parameters": [ + "path" + ], + "start_line": 121, + "end_line": 124, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 4, + "top_nesting_level": 0 + }, + { + "name": "_get_f90_modules", + "long_name": "_get_f90_modules( source )", + "filename": "misc_util.py", + "nloc": 13, + "complexity": 4, + "token_count": 77, + "parameters": [ + "source" + ], + "start_line": 133, + "end_line": 149, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 17, + "top_nesting_level": 0 + }, + { + "name": "is_string", + "long_name": "is_string( s )", + "filename": "misc_util.py", + "nloc": 2, + "complexity": 1, + "token_count": 12, + "parameters": [ + "s" + ], + "start_line": 151, + "end_line": 152, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 2, + "top_nesting_level": 0 + }, + { + "name": "all_strings", + "long_name": "all_strings( lst )", + "filename": "misc_util.py", + "nloc": 5, + "complexity": 3, + "token_count": 22, + "parameters": [ + "lst" + ], + "start_line": 154, + "end_line": 159, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 6, + "top_nesting_level": 0 + }, + { + "name": "is_sequence", + "long_name": "is_sequence( seq )", + "filename": "misc_util.py", + "nloc": 8, + "complexity": 3, + "token_count": 25, + "parameters": [ + "seq" + ], + "start_line": 161, + "end_line": 168, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 8, + "top_nesting_level": 0 + }, + { + "name": "has_f_sources", + "long_name": "has_f_sources( sources )", + "filename": "misc_util.py", + "nloc": 5, + "complexity": 3, + "token_count": 21, + "parameters": [ + "sources" + ], + "start_line": 170, + "end_line": 175, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 6, + "top_nesting_level": 0 + }, + { + "name": "has_cxx_sources", + "long_name": "has_cxx_sources( sources )", + "filename": "misc_util.py", + "nloc": 5, + "complexity": 3, + "token_count": 21, + "parameters": [ + "sources" + ], + "start_line": 177, + "end_line": 182, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 6, + "top_nesting_level": 0 + }, + { + "name": "filter_sources", + "long_name": "filter_sources( sources )", + "filename": "misc_util.py", + "nloc": 17, + "complexity": 5, + "token_count": 84, + "parameters": [ + "sources" + ], + "start_line": 184, + "end_line": 204, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 21, + "top_nesting_level": 0 + }, + { + "name": "_get_headers", + "long_name": "_get_headers( directory_list )", + "filename": "misc_util.py", + "nloc": 6, + "complexity": 2, + "token_count": 39, + "parameters": [ + "directory_list" + ], + "start_line": 207, + "end_line": 213, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 7, + "top_nesting_level": 0 + }, + { + "name": "_get_directories", + "long_name": "_get_directories( list_of_sources )", + "filename": "misc_util.py", + "nloc": 7, + "complexity": 4, + "token_count": 51, + "parameters": [ + "list_of_sources" + ], + "start_line": 215, + "end_line": 222, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 8, + "top_nesting_level": 0 + }, + { + "name": "get_dependencies", + "long_name": "get_dependencies( sources )", + "filename": "misc_util.py", + "nloc": 2, + "complexity": 1, + "token_count": 13, + "parameters": [ + "sources" + ], + "start_line": 224, + "end_line": 226, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 3, + "top_nesting_level": 0 + }, + { + "name": "is_local_src_dir", + "long_name": "is_local_src_dir( directory )", + "filename": "misc_util.py", + "nloc": 12, + "complexity": 6, + "token_count": 107, + "parameters": [ + "directory" + ], + "start_line": 228, + "end_line": 241, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 14, + "top_nesting_level": 0 + }, + { + "name": "_gsf_visit_func", + "long_name": "_gsf_visit_func( filenames , dirname , names )", + "filename": "misc_util.py", + "nloc": 13, + "complexity": 7, + "token_count": 103, + "parameters": [ + "filenames", + "dirname", + "names" + ], + "start_line": 243, + "end_line": 255, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 13, + "top_nesting_level": 0 + }, + { + "name": "get_ext_source_files", + "long_name": "get_ext_source_files( ext )", + "filename": "misc_util.py", + "nloc": 11, + "complexity": 4, + "token_count": 77, + "parameters": [ + "ext" + ], + "start_line": 257, + "end_line": 268, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 12, + "top_nesting_level": 0 + }, + { + "name": "get_script_files", + "long_name": "get_script_files( scripts )", + "filename": "misc_util.py", + "nloc": 3, + "complexity": 1, + "token_count": 15, + "parameters": [ + "scripts" + ], + "start_line": 270, + "end_line": 272, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 3, + "top_nesting_level": 0 + }, + { + "name": "get_lib_source_files", + "long_name": "get_lib_source_files( lib )", + "filename": "misc_util.py", + "nloc": 13, + "complexity": 4, + "token_count": 101, + "parameters": [ + "lib" + ], + "start_line": 274, + "end_line": 286, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 13, + "top_nesting_level": 0 + }, + { + "name": "get_data_files", + "long_name": "get_data_files( data )", + "filename": "misc_util.py", + "nloc": 18, + "complexity": 7, + "token_count": 94, + "parameters": [ + "data" + ], + "start_line": 288, + "end_line": 305, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 18, + "top_nesting_level": 0 + }, + { + "name": "dot_join", + "long_name": "dot_join( * args )", + "filename": "misc_util.py", + "nloc": 2, + "complexity": 1, + "token_count": 18, + "parameters": [ + "args" + ], + "start_line": 307, + "end_line": 308, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 2, + "top_nesting_level": 0 + }, + { + "name": "get_frame", + "long_name": "get_frame( level = 0 )", + "filename": "misc_util.py", + "nloc": 8, + "complexity": 3, + "token_count": 50, + "parameters": [ + "level" + ], + "start_line": 310, + "end_line": 317, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 8, + "top_nesting_level": 0 + }, + { + "name": "command_line_ok", + "long_name": "command_line_ok( _cache = [ ] )", + "filename": "misc_util.py", + "nloc": 14, + "complexity": 9, + "token_count": 98, + "parameters": [ + "_cache" + ], + "start_line": 321, + "end_line": 337, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 17, + "top_nesting_level": 0 + }, + { + "name": "__init__", + "long_name": "__init__( self , package_name = None , parent_name = None , top_path = None , package_path = None , ** attrs )", + "filename": "misc_util.py", + "nloc": 60, + "complexity": 16, + "token_count": 455, + "parameters": [ + "self", + "package_name", + "parent_name", + "top_path", + "package_path", + "attrs" + ], + "start_line": 347, + "end_line": 429, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 83, + "top_nesting_level": 1 + }, + { + "name": "todict", + "long_name": "todict( self )", + "filename": "misc_util.py", + "nloc": 9, + "complexity": 4, + "token_count": 57, + "parameters": [ + "self" + ], + "start_line": 431, + "end_line": 442, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 12, + "top_nesting_level": 1 + }, + { + "name": "info", + "long_name": "info( self , message )", + "filename": "misc_util.py", + "nloc": 3, + "complexity": 2, + "token_count": 18, + "parameters": [ + "self", + "message" + ], + "start_line": 444, + "end_line": 446, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 3, + "top_nesting_level": 1 + }, + { + "name": "warn", + "long_name": "warn( self , message )", + "filename": "misc_util.py", + "nloc": 2, + "complexity": 1, + "token_count": 17, + "parameters": [ + "self", + "message" + ], + "start_line": 448, + "end_line": 449, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 2, + "top_nesting_level": 1 + }, + { + "name": "set_options", + "long_name": "set_options( self , ** options )", + "filename": "misc_util.py", + "nloc": 7, + "complexity": 3, + "token_count": 47, + "parameters": [ + "self", + "options" + ], + "start_line": 452, + "end_line": 466, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 15, + "top_nesting_level": 1 + }, + { + "name": "__dict__", + "long_name": "__dict__( self )", + "filename": "misc_util.py", + "nloc": 2, + "complexity": 1, + "token_count": 11, + "parameters": [ + "self" + ], + "start_line": 467, + "end_line": 468, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 2, + "top_nesting_level": 1 + }, + { + "name": "get_distribution", + "long_name": "get_distribution( self )", + "filename": "misc_util.py", + "nloc": 4, + "complexity": 1, + "token_count": 18, + "parameters": [ + "self" + ], + "start_line": 470, + "end_line": 473, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 4, + "top_nesting_level": 1 + }, + { + "name": "get_subpackage", + "long_name": "get_subpackage( self , subpackage_name , subpackage_path = None )", + "filename": "misc_util.py", + "nloc": 56, + "complexity": 16, + "token_count": 482, + "parameters": [ + "self", + "subpackage_name", + "subpackage_path" + ], + "start_line": 475, + "end_line": 538, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 64, + "top_nesting_level": 1 + }, + { + "name": "add_subpackage", + "long_name": "add_subpackage( self , subpackage_name , subpackage_path = None )", + "filename": "misc_util.py", + "nloc": 23, + "complexity": 6, + "token_count": 147, + "parameters": [ + "self", + "subpackage_name", + "subpackage_path" + ], + "start_line": 540, + "end_line": 565, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 26, + "top_nesting_level": 1 + }, + { + "name": "add_data_dir", + "long_name": "add_data_dir( self , data_path )", + "filename": "misc_util.py", + "nloc": 26, + "complexity": 9, + "token_count": 192, + "parameters": [ + "self", + "data_path" + ], + "start_line": 567, + "end_line": 600, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 34, + "top_nesting_level": 1 + }, + { + "name": "add_data_files", + "long_name": "add_data_files( self , * files )", + "filename": "misc_util.py", + "nloc": 49, + "complexity": 17, + "token_count": 392, + "parameters": [ + "self", + "files" + ], + "start_line": 602, + "end_line": 662, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 61, + "top_nesting_level": 1 + }, + { + "name": "add_include_dirs", + "long_name": "add_include_dirs( self , * paths )", + "filename": "misc_util.py", + "nloc": 8, + "complexity": 2, + "token_count": 49, + "parameters": [ + "self", + "paths" + ], + "start_line": 666, + "end_line": 675, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 10, + "top_nesting_level": 1 + }, + { + "name": "add_headers", + "long_name": "add_headers( self , * files )", + "filename": "misc_util.py", + "nloc": 15, + "complexity": 8, + "token_count": 136, + "parameters": [ + "self", + "files" + ], + "start_line": 677, + "end_line": 697, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 21, + "top_nesting_level": 1 + }, + { + "name": "_fix_paths", + "long_name": "_fix_paths( self , paths , include_non_existing = True )", + "filename": "misc_util.py", + "nloc": 32, + "complexity": 12, + "token_count": 218, + "parameters": [ + "self", + "paths", + "include_non_existing" + ], + "start_line": 699, + "end_line": 730, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 32, + "top_nesting_level": 1 + }, + { + "name": "paths", + "long_name": "paths( self , * paths , ** kws )", + "filename": "misc_util.py", + "nloc": 4, + "complexity": 1, + "token_count": 33, + "parameters": [ + "self", + "paths", + "kws" + ], + "start_line": 732, + "end_line": 737, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 6, + "top_nesting_level": 1 + }, + { + "name": "add_extension", + "long_name": "add_extension( self , name , sources , ** kw )", + "filename": "misc_util.py", + "nloc": 46, + "complexity": 14, + "token_count": 367, + "parameters": [ + "self", + "name", + "sources", + "kw" + ], + "start_line": 739, + "end_line": 802, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 64, + "top_nesting_level": 1 + }, + { + "name": "add_library", + "long_name": "add_library( self , name , sources , ** build_info )", + "filename": "misc_util.py", + "nloc": 16, + "complexity": 4, + "token_count": 112, + "parameters": [ + "self", + "name", + "sources", + "build_info" + ], + "start_line": 804, + "end_line": 830, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 27, + "top_nesting_level": 1 + }, + { + "name": "add_scripts", + "long_name": "add_scripts( self , * files )", + "filename": "misc_util.py", + "nloc": 8, + "complexity": 2, + "token_count": 49, + "parameters": [ + "self", + "files" + ], + "start_line": 832, + "end_line": 841, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 10, + "top_nesting_level": 1 + }, + { + "name": "dict_append", + "long_name": "dict_append( self , ** dict )", + "filename": "misc_util.py", + "nloc": 16, + "complexity": 7, + "token_count": 150, + "parameters": [ + "self", + "dict" + ], + "start_line": 843, + "end_line": 858, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 16, + "top_nesting_level": 1 + }, + { + "name": "__str__", + "long_name": "__str__( self )", + "filename": "misc_util.py", + "nloc": 10, + "complexity": 3, + "token_count": 72, + "parameters": [ + "self" + ], + "start_line": 860, + "end_line": 869, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 10, + "top_nesting_level": 1 + }, + { + "name": "get_config_cmd", + "long_name": "get_config_cmd( self )", + "filename": "misc_util.py", + "nloc": 10, + "complexity": 2, + "token_count": 63, + "parameters": [ + "self" + ], + "start_line": 871, + "end_line": 880, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 10, + "top_nesting_level": 1 + }, + { + "name": "get_build_temp_dir", + "long_name": "get_build_temp_dir( self )", + "filename": "misc_util.py", + "nloc": 4, + "complexity": 1, + "token_count": 20, + "parameters": [ + "self" + ], + "start_line": 882, + "end_line": 885, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 4, + "top_nesting_level": 1 + }, + { + "name": "have_f77c", + "long_name": "have_f77c( self )", + "filename": "misc_util.py", + "nloc": 8, + "complexity": 1, + "token_count": 30, + "parameters": [ + "self" + ], + "start_line": 887, + "end_line": 898, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 12, + "top_nesting_level": 1 + }, + { + "name": "have_f90c", + "long_name": "have_f90c( self )", + "filename": "misc_util.py", + "nloc": 8, + "complexity": 1, + "token_count": 30, + "parameters": [ + "self" + ], + "start_line": 900, + "end_line": 911, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 12, + "top_nesting_level": 1 + }, + { + "name": "append_to", + "long_name": "append_to( self , extlib )", + "filename": "misc_util.py", + "nloc": 12, + "complexity": 2, + "token_count": 77, + "parameters": [ + "self", + "extlib" + ], + "start_line": 913, + "end_line": 926, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 14, + "top_nesting_level": 1 + }, + { + "name": "_get_svn_revision", + "long_name": "_get_svn_revision( self , path )", + "filename": "misc_util.py", + "nloc": 10, + "complexity": 3, + "token_count": 73, + "parameters": [ + "self", + "path" + ], + "start_line": 928, + "end_line": 939, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 12, + "top_nesting_level": 1 + }, + { + "name": "get_version", + "long_name": "get_version( self )", + "filename": "misc_util.py", + "nloc": 38, + "complexity": 11, + "token_count": 260, + "parameters": [ + "self" + ], + "start_line": 941, + "end_line": 987, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 47, + "top_nesting_level": 1 + }, + { + "name": "make_svn_version_py.make_svn_version_py.generate_svn_version_py.rm_file", + "long_name": "make_svn_version_py.make_svn_version_py.generate_svn_version_py.rm_file( f = target , p = self . info )", + "filename": "misc_util.py", + "nloc": 5, + "complexity": 3, + "token_count": 55, + "parameters": [ + "f", + "p" + ], + "start_line": 1010, + "end_line": 1014, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 5, + "top_nesting_level": 3 + }, + { + "name": "make_svn_version_py.generate_svn_version_py", + "long_name": "make_svn_version_py.generate_svn_version_py( )", + "filename": "misc_util.py", + "nloc": 13, + "complexity": 2, + "token_count": 85, + "parameters": [], + "start_line": 999, + "end_line": 1017, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 19, + "top_nesting_level": 2 + }, + { + "name": "make_svn_version_py", + "long_name": "make_svn_version_py( self )", + "filename": "misc_util.py", + "nloc": 7, + "complexity": 2, + "token_count": 44, + "parameters": [ + "self" + ], + "start_line": 989, + "end_line": 1020, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 32, + "top_nesting_level": 1 + }, + { + "name": "make_config_py", + "long_name": "make_config_py( self , name = '__config__' )", + "filename": "misc_util.py", + "nloc": 3, + "complexity": 1, + "token_count": 27, + "parameters": [ + "self", + "name" + ], + "start_line": 1022, + "end_line": 1027, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 6, + "top_nesting_level": 1 + }, + { + "name": "get_info", + "long_name": "get_info( self , * names )", + "filename": "misc_util.py", + "nloc": 6, + "complexity": 2, + "token_count": 36, + "parameters": [ + "self", + "names" + ], + "start_line": 1029, + "end_line": 1036, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 8, + "top_nesting_level": 1 + }, + { + "name": "get_cmd", + "long_name": "get_cmd( cmdname , _cache = { } )", + "filename": "misc_util.py", + "nloc": 11, + "complexity": 3, + "token_count": 65, + "parameters": [ + "cmdname", + "_cache" + ], + "start_line": 1053, + "end_line": 1063, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 11, + "top_nesting_level": 0 + }, + { + "name": "get_numpy_include_dirs", + "long_name": "get_numpy_include_dirs( )", + "filename": "misc_util.py", + "nloc": 11, + "complexity": 3, + "token_count": 77, + "parameters": [], + "start_line": 1065, + "end_line": 1079, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 15, + "top_nesting_level": 0 + }, + { + "name": "default_config_dict", + "long_name": "default_config_dict( name = None , parent_name = None , local_path = None )", + "filename": "misc_util.py", + "nloc": 9, + "complexity": 1, + "token_count": 70, + "parameters": [ + "name", + "parent_name", + "local_path" + ], + "start_line": 1083, + "end_line": 1094, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 12, + "top_nesting_level": 0 + }, + { + "name": "dict_append", + "long_name": "dict_append( d , ** kws )", + "filename": "misc_util.py", + "nloc": 6, + "complexity": 3, + "token_count": 44, + "parameters": [ + "d", + "kws" + ], + "start_line": 1097, + "end_line": 1102, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 6, + "top_nesting_level": 0 + }, + { + "name": "appendpath", + "long_name": "appendpath( prefix , path )", + "filename": "misc_util.py", + "nloc": 19, + "complexity": 6, + "token_count": 233, + "parameters": [ + "prefix", + "path" + ], + "start_line": 1104, + "end_line": 1123, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 20, + "top_nesting_level": 0 + }, + { + "name": "generate_config_py", + "long_name": "generate_config_py( target )", + "filename": "misc_util.py", + "nloc": 27, + "complexity": 2, + "token_count": 117, + "parameters": [ + "target" + ], + "start_line": 1129, + "end_line": 1162, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 34, + "top_nesting_level": 0 + }, + { + "name": "generate_svn_version_py", + "long_name": "generate_svn_version_py( extension , build_dir )", + "filename": "misc_util.py", + "nloc": 15, + "complexity": 4, + "token_count": 101, + "parameters": [ + "extension", + "build_dir" + ], + "start_line": 1164, + "end_line": 1191, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 28, + "top_nesting_level": 0 + } + ], + "methods_before": [ + { + "name": "allpath", + "long_name": "allpath( name )", + "filename": "misc_util.py", + "nloc": 4, + "complexity": 1, + "token_count": 24, + "parameters": [ + "name" + ], + "start_line": 18, + "end_line": 21, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 4, + "top_nesting_level": 0 + }, + { + "name": "get_path", + "long_name": "get_path( mod_name , parent_path = None )", + "filename": "misc_util.py", + "nloc": 15, + "complexity": 6, + "token_count": 132, + "parameters": [ + "mod_name", + "parent_path" + ], + "start_line": 23, + "end_line": 43, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 21, + "top_nesting_level": 0 + }, + { + "name": "njoin", + "long_name": "njoin( * path )", + "filename": "misc_util.py", + "nloc": 7, + "complexity": 4, + "token_count": 68, + "parameters": [ + "path" + ], + "start_line": 45, + "end_line": 55, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 11, + "top_nesting_level": 0 + }, + { + "name": "minrelpath", + "long_name": "minrelpath( path )", + "filename": "misc_util.py", + "nloc": 17, + "complexity": 7, + "token_count": 103, + "parameters": [ + "path" + ], + "start_line": 57, + "end_line": 75, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 19, + "top_nesting_level": 0 + }, + { + "name": "terminal_has_colors", + "long_name": "terminal_has_colors( )", + "filename": "misc_util.py", + "nloc": 18, + "complexity": 13, + "token_count": 137, + "parameters": [], + "start_line": 79, + "end_line": 104, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 26, + "top_nesting_level": 0 + }, + { + "name": "cyg2win32", + "long_name": "cyg2win32( path )", + "filename": "misc_util.py", + "nloc": 4, + "complexity": 3, + "token_count": 42, + "parameters": [ + "path" + ], + "start_line": 121, + "end_line": 124, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 4, + "top_nesting_level": 0 + }, + { + "name": "_get_f90_modules", + "long_name": "_get_f90_modules( source )", + "filename": "misc_util.py", + "nloc": 13, + "complexity": 4, + "token_count": 77, + "parameters": [ + "source" + ], + "start_line": 133, + "end_line": 149, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 17, + "top_nesting_level": 0 + }, + { + "name": "is_string", + "long_name": "is_string( s )", + "filename": "misc_util.py", + "nloc": 2, + "complexity": 1, + "token_count": 12, + "parameters": [ + "s" + ], + "start_line": 151, + "end_line": 152, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 2, + "top_nesting_level": 0 + }, + { + "name": "all_strings", + "long_name": "all_strings( lst )", + "filename": "misc_util.py", + "nloc": 5, + "complexity": 3, + "token_count": 22, + "parameters": [ + "lst" + ], + "start_line": 154, + "end_line": 159, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 6, + "top_nesting_level": 0 + }, + { + "name": "is_sequence", + "long_name": "is_sequence( seq )", + "filename": "misc_util.py", + "nloc": 8, + "complexity": 3, + "token_count": 25, + "parameters": [ + "seq" + ], + "start_line": 161, + "end_line": 168, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 8, + "top_nesting_level": 0 + }, + { + "name": "has_f_sources", + "long_name": "has_f_sources( sources )", + "filename": "misc_util.py", + "nloc": 5, + "complexity": 3, + "token_count": 21, + "parameters": [ + "sources" + ], + "start_line": 170, + "end_line": 175, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 6, + "top_nesting_level": 0 + }, + { + "name": "has_cxx_sources", + "long_name": "has_cxx_sources( sources )", + "filename": "misc_util.py", + "nloc": 5, + "complexity": 3, + "token_count": 21, + "parameters": [ + "sources" + ], + "start_line": 177, + "end_line": 182, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 6, + "top_nesting_level": 0 + }, + { + "name": "filter_sources", + "long_name": "filter_sources( sources )", + "filename": "misc_util.py", + "nloc": 17, + "complexity": 5, + "token_count": 84, + "parameters": [ + "sources" + ], + "start_line": 184, + "end_line": 204, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 21, + "top_nesting_level": 0 + }, + { + "name": "_get_headers", + "long_name": "_get_headers( directory_list )", + "filename": "misc_util.py", + "nloc": 6, + "complexity": 2, + "token_count": 39, + "parameters": [ + "directory_list" + ], + "start_line": 207, + "end_line": 213, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 7, + "top_nesting_level": 0 + }, + { + "name": "_get_directories", + "long_name": "_get_directories( list_of_sources )", + "filename": "misc_util.py", + "nloc": 7, + "complexity": 4, + "token_count": 51, + "parameters": [ + "list_of_sources" + ], + "start_line": 215, + "end_line": 222, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 8, + "top_nesting_level": 0 + }, + { + "name": "get_dependencies", + "long_name": "get_dependencies( sources )", + "filename": "misc_util.py", + "nloc": 2, + "complexity": 1, + "token_count": 13, + "parameters": [ + "sources" + ], + "start_line": 224, + "end_line": 226, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 3, + "top_nesting_level": 0 + }, + { + "name": "is_local_src_dir", + "long_name": "is_local_src_dir( directory )", + "filename": "misc_util.py", + "nloc": 12, + "complexity": 6, + "token_count": 107, + "parameters": [ + "directory" + ], + "start_line": 228, + "end_line": 241, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 14, + "top_nesting_level": 0 + }, + { + "name": "_gsf_visit_func", + "long_name": "_gsf_visit_func( filenames , dirname , names )", + "filename": "misc_util.py", + "nloc": 13, + "complexity": 7, + "token_count": 103, + "parameters": [ + "filenames", + "dirname", + "names" + ], + "start_line": 243, + "end_line": 255, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 13, + "top_nesting_level": 0 + }, + { + "name": "get_ext_source_files", + "long_name": "get_ext_source_files( ext )", + "filename": "misc_util.py", + "nloc": 11, + "complexity": 4, + "token_count": 77, + "parameters": [ + "ext" + ], + "start_line": 257, + "end_line": 268, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 12, + "top_nesting_level": 0 + }, + { + "name": "get_script_files", + "long_name": "get_script_files( scripts )", + "filename": "misc_util.py", + "nloc": 3, + "complexity": 1, + "token_count": 15, + "parameters": [ + "scripts" + ], + "start_line": 270, + "end_line": 272, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 3, + "top_nesting_level": 0 + }, + { + "name": "get_lib_source_files", + "long_name": "get_lib_source_files( lib )", + "filename": "misc_util.py", + "nloc": 13, + "complexity": 4, + "token_count": 101, + "parameters": [ + "lib" + ], + "start_line": 274, + "end_line": 286, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 13, + "top_nesting_level": 0 + }, + { + "name": "get_data_files", + "long_name": "get_data_files( data )", + "filename": "misc_util.py", + "nloc": 18, + "complexity": 7, + "token_count": 94, + "parameters": [ + "data" + ], + "start_line": 288, + "end_line": 305, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 18, + "top_nesting_level": 0 + }, + { + "name": "dot_join", + "long_name": "dot_join( * args )", + "filename": "misc_util.py", + "nloc": 2, + "complexity": 1, + "token_count": 18, + "parameters": [ + "args" + ], + "start_line": 307, + "end_line": 308, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 2, + "top_nesting_level": 0 + }, + { + "name": "get_frame", + "long_name": "get_frame( level = 0 )", + "filename": "misc_util.py", + "nloc": 8, + "complexity": 3, + "token_count": 50, + "parameters": [ + "level" + ], + "start_line": 310, + "end_line": 317, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 8, + "top_nesting_level": 0 + }, + { + "name": "command_line_ok", + "long_name": "command_line_ok( _cache = [ ] )", + "filename": "misc_util.py", + "nloc": 14, + "complexity": 9, + "token_count": 98, + "parameters": [ + "_cache" + ], + "start_line": 321, + "end_line": 337, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 17, + "top_nesting_level": 0 + }, + { + "name": "__init__", + "long_name": "__init__( self , package_name = None , parent_name = None , top_path = None , package_path = None , ** attrs )", + "filename": "misc_util.py", + "nloc": 60, + "complexity": 16, + "token_count": 455, + "parameters": [ + "self", + "package_name", + "parent_name", + "top_path", + "package_path", + "attrs" + ], + "start_line": 347, + "end_line": 429, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 83, + "top_nesting_level": 1 + }, + { + "name": "todict", + "long_name": "todict( self )", + "filename": "misc_util.py", + "nloc": 9, + "complexity": 4, + "token_count": 57, + "parameters": [ + "self" + ], + "start_line": 431, + "end_line": 442, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 12, + "top_nesting_level": 1 + }, + { + "name": "info", + "long_name": "info( self , message )", + "filename": "misc_util.py", + "nloc": 3, + "complexity": 2, + "token_count": 18, + "parameters": [ + "self", + "message" + ], + "start_line": 444, + "end_line": 446, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 3, + "top_nesting_level": 1 + }, + { + "name": "warn", + "long_name": "warn( self , message )", + "filename": "misc_util.py", + "nloc": 2, + "complexity": 1, + "token_count": 17, + "parameters": [ + "self", + "message" + ], + "start_line": 448, + "end_line": 449, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 2, + "top_nesting_level": 1 + }, + { + "name": "set_options", + "long_name": "set_options( self , ** options )", + "filename": "misc_util.py", + "nloc": 7, + "complexity": 3, + "token_count": 47, + "parameters": [ + "self", + "options" + ], + "start_line": 452, + "end_line": 466, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 15, + "top_nesting_level": 1 + }, + { + "name": "__dict__", + "long_name": "__dict__( self )", + "filename": "misc_util.py", + "nloc": 2, + "complexity": 1, + "token_count": 11, + "parameters": [ + "self" + ], + "start_line": 467, + "end_line": 468, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 2, + "top_nesting_level": 1 + }, + { + "name": "get_distribution", + "long_name": "get_distribution( self )", + "filename": "misc_util.py", + "nloc": 4, + "complexity": 1, + "token_count": 18, + "parameters": [ + "self" + ], + "start_line": 470, + "end_line": 473, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 4, + "top_nesting_level": 1 + }, + { + "name": "get_subpackage", + "long_name": "get_subpackage( self , subpackage_name , subpackage_path = None )", + "filename": "misc_util.py", + "nloc": 56, + "complexity": 16, + "token_count": 482, + "parameters": [ + "self", + "subpackage_name", + "subpackage_path" + ], + "start_line": 475, + "end_line": 538, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 64, + "top_nesting_level": 1 + }, + { + "name": "add_subpackage", + "long_name": "add_subpackage( self , subpackage_name , subpackage_path = None )", + "filename": "misc_util.py", + "nloc": 23, + "complexity": 6, + "token_count": 147, + "parameters": [ + "self", + "subpackage_name", + "subpackage_path" + ], + "start_line": 540, + "end_line": 565, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 26, + "top_nesting_level": 1 + }, + { + "name": "add_data_dir", + "long_name": "add_data_dir( self , data_path )", + "filename": "misc_util.py", + "nloc": 27, + "complexity": 9, + "token_count": 200, + "parameters": [ + "self", + "data_path" + ], + "start_line": 567, + "end_line": 601, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 35, + "top_nesting_level": 1 + }, + { + "name": "add_data_files", + "long_name": "add_data_files( self , * files )", + "filename": "misc_util.py", + "nloc": 49, + "complexity": 17, + "token_count": 392, + "parameters": [ + "self", + "files" + ], + "start_line": 603, + "end_line": 663, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 61, + "top_nesting_level": 1 + }, + { + "name": "add_include_dirs", + "long_name": "add_include_dirs( self , * paths )", + "filename": "misc_util.py", + "nloc": 8, + "complexity": 2, + "token_count": 49, + "parameters": [ + "self", + "paths" + ], + "start_line": 667, + "end_line": 676, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 10, + "top_nesting_level": 1 + }, + { + "name": "add_headers", + "long_name": "add_headers( self , * files )", + "filename": "misc_util.py", + "nloc": 15, + "complexity": 8, + "token_count": 136, + "parameters": [ + "self", + "files" + ], + "start_line": 678, + "end_line": 698, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 21, + "top_nesting_level": 1 + }, + { + "name": "_fix_paths", + "long_name": "_fix_paths( self , paths , include_non_existing = True )", + "filename": "misc_util.py", + "nloc": 30, + "complexity": 12, + "token_count": 208, + "parameters": [ + "self", + "paths", + "include_non_existing" + ], + "start_line": 700, + "end_line": 729, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 30, + "top_nesting_level": 1 + }, + { + "name": "paths", + "long_name": "paths( self , * paths , ** kws )", + "filename": "misc_util.py", + "nloc": 4, + "complexity": 1, + "token_count": 33, + "parameters": [ + "self", + "paths", + "kws" + ], + "start_line": 731, + "end_line": 736, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 6, + "top_nesting_level": 1 + }, + { + "name": "add_extension", + "long_name": "add_extension( self , name , sources , ** kw )", + "filename": "misc_util.py", + "nloc": 46, + "complexity": 14, + "token_count": 367, + "parameters": [ + "self", + "name", + "sources", + "kw" + ], + "start_line": 738, + "end_line": 801, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 64, + "top_nesting_level": 1 + }, + { + "name": "add_library", + "long_name": "add_library( self , name , sources , ** build_info )", + "filename": "misc_util.py", + "nloc": 16, + "complexity": 4, + "token_count": 112, + "parameters": [ + "self", + "name", + "sources", + "build_info" + ], + "start_line": 803, + "end_line": 829, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 27, + "top_nesting_level": 1 + }, + { + "name": "add_scripts", + "long_name": "add_scripts( self , * files )", + "filename": "misc_util.py", + "nloc": 8, + "complexity": 2, + "token_count": 49, + "parameters": [ + "self", + "files" + ], + "start_line": 831, + "end_line": 840, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 10, + "top_nesting_level": 1 + }, + { + "name": "dict_append", + "long_name": "dict_append( self , ** dict )", + "filename": "misc_util.py", + "nloc": 16, + "complexity": 7, + "token_count": 150, + "parameters": [ + "self", + "dict" + ], + "start_line": 842, + "end_line": 857, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 16, + "top_nesting_level": 1 + }, + { + "name": "__str__", + "long_name": "__str__( self )", + "filename": "misc_util.py", + "nloc": 10, + "complexity": 3, + "token_count": 72, + "parameters": [ + "self" + ], + "start_line": 859, + "end_line": 868, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 10, + "top_nesting_level": 1 + }, + { + "name": "get_config_cmd", + "long_name": "get_config_cmd( self )", + "filename": "misc_util.py", + "nloc": 10, + "complexity": 2, + "token_count": 63, + "parameters": [ + "self" + ], + "start_line": 870, + "end_line": 879, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 10, + "top_nesting_level": 1 + }, + { + "name": "get_build_temp_dir", + "long_name": "get_build_temp_dir( self )", + "filename": "misc_util.py", + "nloc": 4, + "complexity": 1, + "token_count": 20, + "parameters": [ + "self" + ], + "start_line": 881, + "end_line": 884, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 4, + "top_nesting_level": 1 + }, + { + "name": "have_f77c", + "long_name": "have_f77c( self )", + "filename": "misc_util.py", + "nloc": 8, + "complexity": 1, + "token_count": 30, + "parameters": [ + "self" + ], + "start_line": 886, + "end_line": 897, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 12, + "top_nesting_level": 1 + }, + { + "name": "have_f90c", + "long_name": "have_f90c( self )", + "filename": "misc_util.py", + "nloc": 8, + "complexity": 1, + "token_count": 30, + "parameters": [ + "self" + ], + "start_line": 899, + "end_line": 910, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 12, + "top_nesting_level": 1 + }, + { + "name": "append_to", + "long_name": "append_to( self , extlib )", + "filename": "misc_util.py", + "nloc": 12, + "complexity": 2, + "token_count": 77, + "parameters": [ + "self", + "extlib" + ], + "start_line": 912, + "end_line": 925, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 14, + "top_nesting_level": 1 + }, + { + "name": "_get_svn_revision", + "long_name": "_get_svn_revision( self , path )", + "filename": "misc_util.py", + "nloc": 10, + "complexity": 3, + "token_count": 73, + "parameters": [ + "self", + "path" + ], + "start_line": 927, + "end_line": 938, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 12, + "top_nesting_level": 1 + }, + { + "name": "get_version", + "long_name": "get_version( self )", + "filename": "misc_util.py", + "nloc": 38, + "complexity": 11, + "token_count": 260, + "parameters": [ + "self" + ], + "start_line": 940, + "end_line": 986, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 47, + "top_nesting_level": 1 + }, + { + "name": "make_svn_version_py.make_svn_version_py.generate_svn_version_py.rm_file", + "long_name": "make_svn_version_py.make_svn_version_py.generate_svn_version_py.rm_file( f = target , p = self . info )", + "filename": "misc_util.py", + "nloc": 5, + "complexity": 3, + "token_count": 55, + "parameters": [ + "f", + "p" + ], + "start_line": 1009, + "end_line": 1013, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 5, + "top_nesting_level": 3 + }, + { + "name": "make_svn_version_py.generate_svn_version_py", + "long_name": "make_svn_version_py.generate_svn_version_py( )", + "filename": "misc_util.py", + "nloc": 13, + "complexity": 2, + "token_count": 85, + "parameters": [], + "start_line": 998, + "end_line": 1016, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 19, + "top_nesting_level": 2 + }, + { + "name": "make_svn_version_py", + "long_name": "make_svn_version_py( self )", + "filename": "misc_util.py", + "nloc": 7, + "complexity": 2, + "token_count": 44, + "parameters": [ + "self" + ], + "start_line": 988, + "end_line": 1019, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 32, + "top_nesting_level": 1 + }, + { + "name": "make_config_py", + "long_name": "make_config_py( self , name = '__config__' )", + "filename": "misc_util.py", + "nloc": 3, + "complexity": 1, + "token_count": 27, + "parameters": [ + "self", + "name" + ], + "start_line": 1021, + "end_line": 1026, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 6, + "top_nesting_level": 1 + }, + { + "name": "get_info", + "long_name": "get_info( self , * names )", + "filename": "misc_util.py", + "nloc": 6, + "complexity": 2, + "token_count": 36, + "parameters": [ + "self", + "names" + ], + "start_line": 1028, + "end_line": 1035, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 8, + "top_nesting_level": 1 + }, + { + "name": "get_cmd", + "long_name": "get_cmd( cmdname , _cache = { } )", + "filename": "misc_util.py", + "nloc": 11, + "complexity": 3, + "token_count": 65, + "parameters": [ + "cmdname", + "_cache" + ], + "start_line": 1052, + "end_line": 1062, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 11, + "top_nesting_level": 0 + }, + { + "name": "get_numpy_include_dirs", + "long_name": "get_numpy_include_dirs( )", + "filename": "misc_util.py", + "nloc": 11, + "complexity": 3, + "token_count": 77, + "parameters": [], + "start_line": 1064, + "end_line": 1078, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 15, + "top_nesting_level": 0 + }, + { + "name": "default_config_dict", + "long_name": "default_config_dict( name = None , parent_name = None , local_path = None )", + "filename": "misc_util.py", + "nloc": 9, + "complexity": 1, + "token_count": 70, + "parameters": [ + "name", + "parent_name", + "local_path" + ], + "start_line": 1082, + "end_line": 1093, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 12, + "top_nesting_level": 0 + }, + { + "name": "dict_append", + "long_name": "dict_append( d , ** kws )", + "filename": "misc_util.py", + "nloc": 6, + "complexity": 3, + "token_count": 44, + "parameters": [ + "d", + "kws" + ], + "start_line": 1096, + "end_line": 1101, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 6, + "top_nesting_level": 0 + }, + { + "name": "appendpath", + "long_name": "appendpath( prefix , path )", + "filename": "misc_util.py", + "nloc": 19, + "complexity": 6, + "token_count": 233, + "parameters": [ + "prefix", + "path" + ], + "start_line": 1103, + "end_line": 1122, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 20, + "top_nesting_level": 0 + }, + { + "name": "generate_config_py", + "long_name": "generate_config_py( target )", + "filename": "misc_util.py", + "nloc": 27, + "complexity": 2, + "token_count": 117, + "parameters": [ + "target" + ], + "start_line": 1128, + "end_line": 1161, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 34, + "top_nesting_level": 0 + }, + { + "name": "generate_svn_version_py", + "long_name": "generate_svn_version_py( extension , build_dir )", + "filename": "misc_util.py", + "nloc": 15, + "complexity": 4, + "token_count": 101, + "parameters": [ + "extension", + "build_dir" + ], + "start_line": 1163, + "end_line": 1190, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 28, + "top_nesting_level": 0 + } + ], + "changed_methods": [ + { + "name": "add_data_dir", + "long_name": "add_data_dir( self , data_path )", + "filename": "misc_util.py", + "nloc": 27, + "complexity": 9, + "token_count": 200, + "parameters": [ + "self", + "data_path" + ], + "start_line": 567, + "end_line": 601, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 35, + "top_nesting_level": 1 + }, + { + "name": "_fix_paths", + "long_name": "_fix_paths( self , paths , include_non_existing = True )", + "filename": "misc_util.py", + "nloc": 32, + "complexity": 12, + "token_count": 218, + "parameters": [ + "self", + "paths", + "include_non_existing" + ], + "start_line": 699, + "end_line": 730, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 32, + "top_nesting_level": 1 + } + ], + "nloc": 895, + "complexity": 287, + "token_count": 6460, + "diff_parsed": { + "added": [ + " self.warn('could not resolve pattern in %s: %r' \\", + " % (self.local_path,n))", + " self.warn('not existing data path in %s: %s' \\", + " % (self.local_path,n))" + ], + "deleted": [ + " self.warn('Not existing data path: '+path)", + " self.warn('could not resolve pattern: %r' % (n))", + " self.warn('not existing path: %r' % (n))" + ] + } + } + ] + }, + { + "hash": "daf3e9fae50a559a9b731bbaa5e1532a08b5d5d7", + "msg": "Fixed pkgload: synced behaviours of postpone and postpone_import flags.", + "author": { + "name": "Pearu Peterson", + "email": "pearu.peterson@gmail.com" + }, + "committer": { + "name": "Pearu Peterson", + "email": "pearu.peterson@gmail.com" + }, + "author_date": "2006-01-31T10:21:40+00:00", + "author_timezone": 0, + "committer_date": "2006-01-31T10:21:40+00:00", + "committer_timezone": 0, + "branches": [ + "main" + ], + "in_main_branch": true, + "merge": false, + "parents": [ + "71f74ba1e86be798f35d59f4d632b9042c53eeb5" + ], + "project_name": "repo_copy", + "project_path": "/tmp/tmppy2o86q9/repo_copy", + "deletions": 2, + "insertions": 3, + "lines": 5, + "files": 1, + "dmm_unit_size": 0.0, + "dmm_unit_complexity": 0.0, + "dmm_unit_interfacing": 0.0, + "modified_files": [ + { + "old_path": "numpy/_import_tools.py", + "new_path": "numpy/_import_tools.py", + "filename": "_import_tools.py", + "extension": "py", + "change_type": "MODIFY", + "diff": "@@ -160,7 +160,7 @@ def __call__(self,*packages, **options):\n if options.get('force',False):\n self.imported_packages = []\n self.verbose = verbose = options.get('verbose',False)\n- postpone = options.get('postpone',False)\n+ postpone = options.get('postpone',None)\n self._init_info_modules(packages or None)\n \n self.log('Imports to %r namespace\\n----------------------------'\\\n@@ -172,7 +172,8 @@ def __call__(self,*packages, **options):\n info_module = self.info_modules[package_name]\n global_symbols = getattr(info_module,'global_symbols',[])\n postpone_import = getattr(info_module,'postpone_import',False)\n- if (postpone and not global_symbols) or postpone_import:\n+ if (postpone and not global_symbols) \\\n+ or (postpone_import and postpone is not None):\n self.log('__all__.append(%r)' % (package_name))\n if '.' not in package_name:\n self.parent_export_names.append(package_name)\n", + "added_lines": 3, + "deleted_lines": 2, + "source_code": "\nimport os\nimport sys\nimport imp\nfrom glob import glob\n\n__all__ = ['PackageLoader']\n\nclass PackageLoader:\n def __init__(self, verbose=False):\n \"\"\" Manages loading packages.\n \"\"\"\n\n self.parent_frame = frame = sys._getframe(1)\n self.parent_name = eval('__name__',frame.f_globals,frame.f_locals)\n self.parent_path = eval('__path__',frame.f_globals,frame.f_locals)\n if not frame.f_locals.has_key('__all__'):\n exec('__all__ = []',frame.f_globals,frame.f_locals)\n self.parent_export_names = eval('__all__',frame.f_globals,frame.f_locals)\n\n self.info_modules = {}\n self.imported_packages = []\n self.verbose = None\n\n def _get_info_files(self, package_dir, parent_path, parent_package=None):\n \"\"\" Return list of (package name,info.py file) from parent_path subdirectories.\n \"\"\"\n from glob import glob\n files = glob(os.path.join(parent_path,package_dir,'info.py'))\n for info_file in glob(os.path.join(parent_path,package_dir,'info.pyc')):\n if info_file[:-1] not in files:\n files.append(info_file)\n info_files = []\n for info_file in files:\n package_name = os.path.dirname(info_file[len(parent_path)+1:])\\\n .replace(os.sep,'.')\n if parent_package:\n package_name = parent_package + '.' + package_name\n info_files.append((package_name,info_file))\n info_files.extend(self._get_info_files('*',\n os.path.dirname(info_file),\n package_name))\n return info_files\n\n def _init_info_modules(self, packages=None):\n \"\"\"Initialize info_modules = {: }.\n \"\"\"\n import imp\n info_files = []\n if packages is None:\n for path in self.parent_path:\n info_files.extend(self._get_info_files('*',path))\n else:\n for package_name in packages:\n package_dir = os.path.join(*package_name.split('.'))\n for path in self.parent_path:\n names_files = self._get_info_files(package_dir, path)\n if names_files:\n info_files.extend(names_files)\n break\n else:\n self.warn('No scipy-style subpackage %r found in %s. Ignoring.'\\\n % (package_name,':'.join(self.parent_path)))\n\n info_modules = self.info_modules\n for package_name,info_file in info_files:\n if info_modules.has_key(package_name):\n continue\n fullname = self.parent_name +'.'+ package_name\n if info_file[-1]=='c':\n filedescriptor = ('.pyc','rb',2)\n else:\n filedescriptor = ('.py','U',1)\n\n try:\n info_module = imp.load_module(fullname+'.info',\n open(info_file,filedescriptor[1]),\n info_file,\n filedescriptor)\n except Exception,msg:\n self.error(msg)\n info_module = None\n\n if info_module is None or getattr(info_module,'ignore',False):\n info_modules.pop(package_name,None)\n else:\n self._init_info_modules(getattr(info_module,'depends',[]))\n info_modules[package_name] = info_module\n\n return\n\n def _get_sorted_names(self):\n \"\"\" Return package names sorted in the order as they should be\n imported due to dependence relations between packages. \n \"\"\"\n\n depend_dict = {}\n for name,info_module in self.info_modules.items():\n depend_dict[name] = getattr(info_module,'depends',[])\n package_names = []\n\n for name in depend_dict.keys():\n if not depend_dict[name]:\n package_names.append(name)\n del depend_dict[name]\n\n while depend_dict:\n for name, lst in depend_dict.items():\n new_lst = [n for n in lst if depend_dict.has_key(n)]\n if not new_lst:\n package_names.append(name)\n del depend_dict[name]\n else:\n depend_dict[name] = new_lst\n\n return package_names\n\n def __call__(self,*packages, **options):\n \"\"\"Load one or more packages into parent package top-level namespace.\n\n Usage:\n\n This function is intended to shorten the need to import many of\n subpackages, say of scipy, constantly with statements such as\n\n import scipy.linalg, scipy.fftpack, scipy.etc...\n\n Instead, you can say:\n\n import scipy\n scipy.pkgload('linalg','fftpack',...)\n\n or\n\n scipy.pkgload()\n\n to load all of them in one call.\n\n If a name which doesn't exist in scipy's namespace is\n given, a warning is shown.\n\n Inputs:\n\n - the names (one or more strings) of all the numpy modules one wishes to\n load into the top-level namespace.\n\n Optional keyword inputs:\n\n - verbose - integer specifying verbosity level [default: 0].\n verbose=-1 will suspend also warnings.\n - force - when True, force reloading loaded packages [default: False].\n - postpone - when True, don't load packages [default: False]\n\n If no input arguments are given, then all of scipy's subpackages are\n imported.\n\n \"\"\"\n frame = self.parent_frame\n self.info_modules = {}\n if options.get('force',False):\n self.imported_packages = []\n self.verbose = verbose = options.get('verbose',False)\n postpone = options.get('postpone',None)\n self._init_info_modules(packages or None)\n\n self.log('Imports to %r namespace\\n----------------------------'\\\n % self.parent_name)\n\n for package_name in self._get_sorted_names():\n if package_name in self.imported_packages:\n continue\n info_module = self.info_modules[package_name]\n global_symbols = getattr(info_module,'global_symbols',[])\n postpone_import = getattr(info_module,'postpone_import',False)\n if (postpone and not global_symbols) \\\n or (postpone_import and postpone is not None):\n self.log('__all__.append(%r)' % (package_name))\n if '.' not in package_name:\n self.parent_export_names.append(package_name)\n continue\n \n old_object = frame.f_locals.get(package_name,None)\n\n cmdstr = 'import '+package_name\n if self._execcmd(cmdstr):\n continue\n self.imported_packages.append(package_name)\n \n if verbose!=-1:\n new_object = frame.f_locals.get(package_name)\n if old_object is not None and old_object is not new_object:\n self.warn('Overwriting %s=%s (was %s)' \\\n % (package_name,self._obj2repr(new_object),\n self._obj2repr(old_object)))\n\n if '.' not in package_name:\n self.parent_export_names.append(package_name)\n\n for symbol in global_symbols:\n if symbol=='*':\n symbols = eval('getattr(%s,\"__all__\",None)'\\\n % (package_name),\n frame.f_globals,frame.f_locals)\n if symbols is None:\n symbols = eval('dir(%s)' % (package_name),\n frame.f_globals,frame.f_locals)\n symbols = filter(lambda s:not s.startswith('_'),symbols)\n else:\n symbols = [symbol]\n\n if verbose!=-1:\n old_objects = {}\n for s in symbols:\n if frame.f_locals.has_key(s):\n old_objects[s] = frame.f_locals[s]\n\n cmdstr = 'from '+package_name+' import '+symbol\n if self._execcmd(cmdstr):\n continue\n\n if verbose!=-1:\n for s,old_object in old_objects.items():\n new_object = frame.f_locals[s]\n if new_object is not old_object:\n self.warn('Overwriting %s=%s (was %s)' \\\n % (s,self._obj2repr(new_object),\n self._obj2repr(old_object)))\n\n if symbol=='*':\n self.parent_export_names.extend(symbols)\n else:\n self.parent_export_names.append(symbol)\n\n return\n\n def _execcmd(self,cmdstr):\n \"\"\" Execute command in parent_frame.\"\"\"\n frame = self.parent_frame\n try:\n exec (cmdstr, frame.f_globals,frame.f_locals)\n except Exception,msg:\n self.error('%s -> failed: %s' % (cmdstr,msg))\n return True\n else:\n self.log('%s -> success' % (cmdstr)) \n return\n\n def _obj2repr(self,obj):\n \"\"\" Return repr(obj) with\"\"\"\n module = getattr(obj,'__module__',None)\n file = getattr(obj,'__file__',None)\n if module is not None:\n return repr(obj) + ' from ' + module\n if file is not None:\n return repr(obj) + ' from ' + file\n return repr(obj)\n\n def log(self,mess):\n if self.verbose>1:\n print >> sys.stderr, str(mess)\n def warn(self,mess):\n if self.verbose>=0:\n print >> sys.stderr, str(mess)\n def error(self,mess):\n if self.verbose!=-1:\n print >> sys.stderr, str(mess)\n\n def _get_doc_title(self, info_module):\n \"\"\" Get the title from a package info.py file.\n \"\"\"\n title = getattr(info_module,'__doc_title__',None)\n if title is not None:\n return title\n title = getattr(info_module,'__doc__',None)\n if title is not None:\n title = title.lstrip().split('\\n',1)[0]\n return title\n return '* Not Available *'\n\n def _format_titles(self,titles,colsep='---'):\n display_window_width = 70 # How to determine the correct value in runtime??\n lengths = [len(name)-name.find('.')-1 for (name,title) in titles]\n max_length = max(lengths)\n lines = []\n for (name,title) in titles:\n name = name[name.find('.')+1:]\n w = max_length - len(name)\n words = title.split()\n line = '%s%s %s' % (name,w*' ',colsep)\n tab = len(line) * ' '\n while words:\n word = words.pop(0)\n if len(line)+len(word)>display_window_width:\n lines.append(line)\n line = tab\n line += ' ' + word\n else:\n lines.append(line)\n return '\\n'.join(lines)\n\n def get_pkgdocs(self):\n \"\"\" Return documentation summary of subpackages.\n \"\"\"\n import sys\n self.info_modules = {}\n self._init_info_modules(None)\n\n titles = []\n symbols = []\n for package_name, info_module in self.info_modules.items():\n global_symbols = getattr(info_module,'global_symbols',[])\n fullname = self.parent_name +'.'+ package_name\n note = ''\n if not sys.modules.has_key(fullname):\n note = ' [*]'\n titles.append((fullname,self._get_doc_title(info_module) + note))\n if global_symbols:\n symbols.append((package_name,', '.join(global_symbols)))\n\n retstr = self._format_titles(titles) +\\\n '\\n [*] - using a package requires explicit import (see pkgload)'\n\n\n if symbols:\n retstr += \"\"\"\\n\\nGlobal symbols from subpackages\"\"\"\\\n \"\"\"\\n-------------------------------\\n\"\"\" +\\\n self._format_titles(symbols,'-->')\n\n return retstr\n", + "source_code_before": "\nimport os\nimport sys\nimport imp\nfrom glob import glob\n\n__all__ = ['PackageLoader']\n\nclass PackageLoader:\n def __init__(self, verbose=False):\n \"\"\" Manages loading packages.\n \"\"\"\n\n self.parent_frame = frame = sys._getframe(1)\n self.parent_name = eval('__name__',frame.f_globals,frame.f_locals)\n self.parent_path = eval('__path__',frame.f_globals,frame.f_locals)\n if not frame.f_locals.has_key('__all__'):\n exec('__all__ = []',frame.f_globals,frame.f_locals)\n self.parent_export_names = eval('__all__',frame.f_globals,frame.f_locals)\n\n self.info_modules = {}\n self.imported_packages = []\n self.verbose = None\n\n def _get_info_files(self, package_dir, parent_path, parent_package=None):\n \"\"\" Return list of (package name,info.py file) from parent_path subdirectories.\n \"\"\"\n from glob import glob\n files = glob(os.path.join(parent_path,package_dir,'info.py'))\n for info_file in glob(os.path.join(parent_path,package_dir,'info.pyc')):\n if info_file[:-1] not in files:\n files.append(info_file)\n info_files = []\n for info_file in files:\n package_name = os.path.dirname(info_file[len(parent_path)+1:])\\\n .replace(os.sep,'.')\n if parent_package:\n package_name = parent_package + '.' + package_name\n info_files.append((package_name,info_file))\n info_files.extend(self._get_info_files('*',\n os.path.dirname(info_file),\n package_name))\n return info_files\n\n def _init_info_modules(self, packages=None):\n \"\"\"Initialize info_modules = {: }.\n \"\"\"\n import imp\n info_files = []\n if packages is None:\n for path in self.parent_path:\n info_files.extend(self._get_info_files('*',path))\n else:\n for package_name in packages:\n package_dir = os.path.join(*package_name.split('.'))\n for path in self.parent_path:\n names_files = self._get_info_files(package_dir, path)\n if names_files:\n info_files.extend(names_files)\n break\n else:\n self.warn('No scipy-style subpackage %r found in %s. Ignoring.'\\\n % (package_name,':'.join(self.parent_path)))\n\n info_modules = self.info_modules\n for package_name,info_file in info_files:\n if info_modules.has_key(package_name):\n continue\n fullname = self.parent_name +'.'+ package_name\n if info_file[-1]=='c':\n filedescriptor = ('.pyc','rb',2)\n else:\n filedescriptor = ('.py','U',1)\n\n try:\n info_module = imp.load_module(fullname+'.info',\n open(info_file,filedescriptor[1]),\n info_file,\n filedescriptor)\n except Exception,msg:\n self.error(msg)\n info_module = None\n\n if info_module is None or getattr(info_module,'ignore',False):\n info_modules.pop(package_name,None)\n else:\n self._init_info_modules(getattr(info_module,'depends',[]))\n info_modules[package_name] = info_module\n\n return\n\n def _get_sorted_names(self):\n \"\"\" Return package names sorted in the order as they should be\n imported due to dependence relations between packages. \n \"\"\"\n\n depend_dict = {}\n for name,info_module in self.info_modules.items():\n depend_dict[name] = getattr(info_module,'depends',[])\n package_names = []\n\n for name in depend_dict.keys():\n if not depend_dict[name]:\n package_names.append(name)\n del depend_dict[name]\n\n while depend_dict:\n for name, lst in depend_dict.items():\n new_lst = [n for n in lst if depend_dict.has_key(n)]\n if not new_lst:\n package_names.append(name)\n del depend_dict[name]\n else:\n depend_dict[name] = new_lst\n\n return package_names\n\n def __call__(self,*packages, **options):\n \"\"\"Load one or more packages into parent package top-level namespace.\n\n Usage:\n\n This function is intended to shorten the need to import many of\n subpackages, say of scipy, constantly with statements such as\n\n import scipy.linalg, scipy.fftpack, scipy.etc...\n\n Instead, you can say:\n\n import scipy\n scipy.pkgload('linalg','fftpack',...)\n\n or\n\n scipy.pkgload()\n\n to load all of them in one call.\n\n If a name which doesn't exist in scipy's namespace is\n given, a warning is shown.\n\n Inputs:\n\n - the names (one or more strings) of all the numpy modules one wishes to\n load into the top-level namespace.\n\n Optional keyword inputs:\n\n - verbose - integer specifying verbosity level [default: 0].\n verbose=-1 will suspend also warnings.\n - force - when True, force reloading loaded packages [default: False].\n - postpone - when True, don't load packages [default: False]\n\n If no input arguments are given, then all of scipy's subpackages are\n imported.\n\n \"\"\"\n frame = self.parent_frame\n self.info_modules = {}\n if options.get('force',False):\n self.imported_packages = []\n self.verbose = verbose = options.get('verbose',False)\n postpone = options.get('postpone',False)\n self._init_info_modules(packages or None)\n\n self.log('Imports to %r namespace\\n----------------------------'\\\n % self.parent_name)\n\n for package_name in self._get_sorted_names():\n if package_name in self.imported_packages:\n continue\n info_module = self.info_modules[package_name]\n global_symbols = getattr(info_module,'global_symbols',[])\n postpone_import = getattr(info_module,'postpone_import',False)\n if (postpone and not global_symbols) or postpone_import:\n self.log('__all__.append(%r)' % (package_name))\n if '.' not in package_name:\n self.parent_export_names.append(package_name)\n continue\n \n old_object = frame.f_locals.get(package_name,None)\n\n cmdstr = 'import '+package_name\n if self._execcmd(cmdstr):\n continue\n self.imported_packages.append(package_name)\n \n if verbose!=-1:\n new_object = frame.f_locals.get(package_name)\n if old_object is not None and old_object is not new_object:\n self.warn('Overwriting %s=%s (was %s)' \\\n % (package_name,self._obj2repr(new_object),\n self._obj2repr(old_object)))\n\n if '.' not in package_name:\n self.parent_export_names.append(package_name)\n\n for symbol in global_symbols:\n if symbol=='*':\n symbols = eval('getattr(%s,\"__all__\",None)'\\\n % (package_name),\n frame.f_globals,frame.f_locals)\n if symbols is None:\n symbols = eval('dir(%s)' % (package_name),\n frame.f_globals,frame.f_locals)\n symbols = filter(lambda s:not s.startswith('_'),symbols)\n else:\n symbols = [symbol]\n\n if verbose!=-1:\n old_objects = {}\n for s in symbols:\n if frame.f_locals.has_key(s):\n old_objects[s] = frame.f_locals[s]\n\n cmdstr = 'from '+package_name+' import '+symbol\n if self._execcmd(cmdstr):\n continue\n\n if verbose!=-1:\n for s,old_object in old_objects.items():\n new_object = frame.f_locals[s]\n if new_object is not old_object:\n self.warn('Overwriting %s=%s (was %s)' \\\n % (s,self._obj2repr(new_object),\n self._obj2repr(old_object)))\n\n if symbol=='*':\n self.parent_export_names.extend(symbols)\n else:\n self.parent_export_names.append(symbol)\n\n return\n\n def _execcmd(self,cmdstr):\n \"\"\" Execute command in parent_frame.\"\"\"\n frame = self.parent_frame\n try:\n exec (cmdstr, frame.f_globals,frame.f_locals)\n except Exception,msg:\n self.error('%s -> failed: %s' % (cmdstr,msg))\n return True\n else:\n self.log('%s -> success' % (cmdstr)) \n return\n\n def _obj2repr(self,obj):\n \"\"\" Return repr(obj) with\"\"\"\n module = getattr(obj,'__module__',None)\n file = getattr(obj,'__file__',None)\n if module is not None:\n return repr(obj) + ' from ' + module\n if file is not None:\n return repr(obj) + ' from ' + file\n return repr(obj)\n\n def log(self,mess):\n if self.verbose>1:\n print >> sys.stderr, str(mess)\n def warn(self,mess):\n if self.verbose>=0:\n print >> sys.stderr, str(mess)\n def error(self,mess):\n if self.verbose!=-1:\n print >> sys.stderr, str(mess)\n\n def _get_doc_title(self, info_module):\n \"\"\" Get the title from a package info.py file.\n \"\"\"\n title = getattr(info_module,'__doc_title__',None)\n if title is not None:\n return title\n title = getattr(info_module,'__doc__',None)\n if title is not None:\n title = title.lstrip().split('\\n',1)[0]\n return title\n return '* Not Available *'\n\n def _format_titles(self,titles,colsep='---'):\n display_window_width = 70 # How to determine the correct value in runtime??\n lengths = [len(name)-name.find('.')-1 for (name,title) in titles]\n max_length = max(lengths)\n lines = []\n for (name,title) in titles:\n name = name[name.find('.')+1:]\n w = max_length - len(name)\n words = title.split()\n line = '%s%s %s' % (name,w*' ',colsep)\n tab = len(line) * ' '\n while words:\n word = words.pop(0)\n if len(line)+len(word)>display_window_width:\n lines.append(line)\n line = tab\n line += ' ' + word\n else:\n lines.append(line)\n return '\\n'.join(lines)\n\n def get_pkgdocs(self):\n \"\"\" Return documentation summary of subpackages.\n \"\"\"\n import sys\n self.info_modules = {}\n self._init_info_modules(None)\n\n titles = []\n symbols = []\n for package_name, info_module in self.info_modules.items():\n global_symbols = getattr(info_module,'global_symbols',[])\n fullname = self.parent_name +'.'+ package_name\n note = ''\n if not sys.modules.has_key(fullname):\n note = ' [*]'\n titles.append((fullname,self._get_doc_title(info_module) + note))\n if global_symbols:\n symbols.append((package_name,', '.join(global_symbols)))\n\n retstr = self._format_titles(titles) +\\\n '\\n [*] - using a package requires explicit import (see pkgload)'\n\n\n if symbols:\n retstr += \"\"\"\\n\\nGlobal symbols from subpackages\"\"\"\\\n \"\"\"\\n-------------------------------\\n\"\"\" +\\\n self._format_titles(symbols,'-->')\n\n return retstr\n", + "methods": [ + { + "name": "__init__", + "long_name": "__init__( self , verbose = False )", + "filename": "_import_tools.py", + "nloc": 10, + "complexity": 2, + "token_count": 110, + "parameters": [ + "self", + "verbose" + ], + "start_line": 10, + "end_line": 23, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 14, + "top_nesting_level": 1 + }, + { + "name": "_get_info_files", + "long_name": "_get_info_files( self , package_dir , parent_path , parent_package = None )", + "filename": "_import_tools.py", + "nloc": 17, + "complexity": 5, + "token_count": 153, + "parameters": [ + "self", + "package_dir", + "parent_path", + "parent_package" + ], + "start_line": 25, + "end_line": 43, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 19, + "top_nesting_level": 1 + }, + { + "name": "_init_info_modules", + "long_name": "_init_info_modules( self , packages = None )", + "filename": "_import_tools.py", + "nloc": 40, + "complexity": 12, + "token_count": 257, + "parameters": [ + "self", + "packages" + ], + "start_line": 45, + "end_line": 90, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 46, + "top_nesting_level": 1 + }, + { + "name": "_get_sorted_names", + "long_name": "_get_sorted_names( self )", + "filename": "_import_tools.py", + "nloc": 18, + "complexity": 9, + "token_count": 123, + "parameters": [ + "self" + ], + "start_line": 92, + "end_line": 116, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 25, + "top_nesting_level": 1 + }, + { + "name": "__call__", + "long_name": "__call__( self , * packages , ** options )", + "filename": "_import_tools.py", + "nloc": 66, + "complexity": 26, + "token_count": 481, + "parameters": [ + "self", + "packages", + "options" + ], + "start_line": 118, + "end_line": 234, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 117, + "top_nesting_level": 1 + }, + { + "name": "_execcmd", + "long_name": "_execcmd( self , cmdstr )", + "filename": "_import_tools.py", + "nloc": 10, + "complexity": 2, + "token_count": 59, + "parameters": [ + "self", + "cmdstr" + ], + "start_line": 236, + "end_line": 246, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 11, + "top_nesting_level": 1 + }, + { + "name": "_obj2repr", + "long_name": "_obj2repr( self , obj )", + "filename": "_import_tools.py", + "nloc": 8, + "complexity": 3, + "token_count": 63, + "parameters": [ + "self", + "obj" + ], + "start_line": 248, + "end_line": 256, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 9, + "top_nesting_level": 1 + }, + { + "name": "log", + "long_name": "log( self , mess )", + "filename": "_import_tools.py", + "nloc": 3, + "complexity": 2, + "token_count": 25, + "parameters": [ + "self", + "mess" + ], + "start_line": 258, + "end_line": 260, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 3, + "top_nesting_level": 1 + }, + { + "name": "warn", + "long_name": "warn( self , mess )", + "filename": "_import_tools.py", + "nloc": 3, + "complexity": 2, + "token_count": 25, + "parameters": [ + "self", + "mess" + ], + "start_line": 261, + "end_line": 263, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 3, + "top_nesting_level": 1 + }, + { + "name": "error", + "long_name": "error( self , mess )", + "filename": "_import_tools.py", + "nloc": 3, + "complexity": 2, + "token_count": 26, + "parameters": [ + "self", + "mess" + ], + "start_line": 264, + "end_line": 266, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 3, + "top_nesting_level": 1 + }, + { + "name": "_get_doc_title", + "long_name": "_get_doc_title( self , info_module )", + "filename": "_import_tools.py", + "nloc": 9, + "complexity": 3, + "token_count": 63, + "parameters": [ + "self", + "info_module" + ], + "start_line": 268, + "end_line": 278, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 11, + "top_nesting_level": 1 + }, + { + "name": "_format_titles", + "long_name": "_format_titles( self , titles , colsep = '---' )", + "filename": "_import_tools.py", + "nloc": 20, + "complexity": 5, + "token_count": 161, + "parameters": [ + "self", + "titles", + "colsep" + ], + "start_line": 280, + "end_line": 299, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 20, + "top_nesting_level": 1 + }, + { + "name": "get_pkgdocs", + "long_name": "get_pkgdocs( self )", + "filename": "_import_tools.py", + "nloc": 22, + "complexity": 5, + "token_count": 144, + "parameters": [ + "self" + ], + "start_line": 301, + "end_line": 329, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 29, + "top_nesting_level": 1 + } + ], + "methods_before": [ + { + "name": "__init__", + "long_name": "__init__( self , verbose = False )", + "filename": "_import_tools.py", + "nloc": 10, + "complexity": 2, + "token_count": 110, + "parameters": [ + "self", + "verbose" + ], + "start_line": 10, + "end_line": 23, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 14, + "top_nesting_level": 1 + }, + { + "name": "_get_info_files", + "long_name": "_get_info_files( self , package_dir , parent_path , parent_package = None )", + "filename": "_import_tools.py", + "nloc": 17, + "complexity": 5, + "token_count": 153, + "parameters": [ + "self", + "package_dir", + "parent_path", + "parent_package" + ], + "start_line": 25, + "end_line": 43, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 19, + "top_nesting_level": 1 + }, + { + "name": "_init_info_modules", + "long_name": "_init_info_modules( self , packages = None )", + "filename": "_import_tools.py", + "nloc": 40, + "complexity": 12, + "token_count": 257, + "parameters": [ + "self", + "packages" + ], + "start_line": 45, + "end_line": 90, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 46, + "top_nesting_level": 1 + }, + { + "name": "_get_sorted_names", + "long_name": "_get_sorted_names( self )", + "filename": "_import_tools.py", + "nloc": 18, + "complexity": 9, + "token_count": 123, + "parameters": [ + "self" + ], + "start_line": 92, + "end_line": 116, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 25, + "top_nesting_level": 1 + }, + { + "name": "__call__", + "long_name": "__call__( self , * packages , ** options )", + "filename": "_import_tools.py", + "nloc": 65, + "complexity": 25, + "token_count": 473, + "parameters": [ + "self", + "packages", + "options" + ], + "start_line": 118, + "end_line": 233, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 116, + "top_nesting_level": 1 + }, + { + "name": "_execcmd", + "long_name": "_execcmd( self , cmdstr )", + "filename": "_import_tools.py", + "nloc": 10, + "complexity": 2, + "token_count": 59, + "parameters": [ + "self", + "cmdstr" + ], + "start_line": 235, + "end_line": 245, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 11, + "top_nesting_level": 1 + }, + { + "name": "_obj2repr", + "long_name": "_obj2repr( self , obj )", + "filename": "_import_tools.py", + "nloc": 8, + "complexity": 3, + "token_count": 63, + "parameters": [ + "self", + "obj" + ], + "start_line": 247, + "end_line": 255, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 9, + "top_nesting_level": 1 + }, + { + "name": "log", + "long_name": "log( self , mess )", + "filename": "_import_tools.py", + "nloc": 3, + "complexity": 2, + "token_count": 25, + "parameters": [ + "self", + "mess" + ], + "start_line": 257, + "end_line": 259, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 3, + "top_nesting_level": 1 + }, + { + "name": "warn", + "long_name": "warn( self , mess )", + "filename": "_import_tools.py", + "nloc": 3, + "complexity": 2, + "token_count": 25, + "parameters": [ + "self", + "mess" + ], + "start_line": 260, + "end_line": 262, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 3, + "top_nesting_level": 1 + }, + { + "name": "error", + "long_name": "error( self , mess )", + "filename": "_import_tools.py", + "nloc": 3, + "complexity": 2, + "token_count": 26, + "parameters": [ + "self", + "mess" + ], + "start_line": 263, + "end_line": 265, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 3, + "top_nesting_level": 1 + }, + { + "name": "_get_doc_title", + "long_name": "_get_doc_title( self , info_module )", + "filename": "_import_tools.py", + "nloc": 9, + "complexity": 3, + "token_count": 63, + "parameters": [ + "self", + "info_module" + ], + "start_line": 267, + "end_line": 277, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 11, + "top_nesting_level": 1 + }, + { + "name": "_format_titles", + "long_name": "_format_titles( self , titles , colsep = '---' )", + "filename": "_import_tools.py", + "nloc": 20, + "complexity": 5, + "token_count": 161, + "parameters": [ + "self", + "titles", + "colsep" + ], + "start_line": 279, + "end_line": 298, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 20, + "top_nesting_level": 1 + }, + { + "name": "get_pkgdocs", + "long_name": "get_pkgdocs( self )", + "filename": "_import_tools.py", + "nloc": 22, + "complexity": 5, + "token_count": 144, + "parameters": [ + "self" + ], + "start_line": 300, + "end_line": 328, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 29, + "top_nesting_level": 1 + } + ], + "changed_methods": [ + { + "name": "__call__", + "long_name": "__call__( self , * packages , ** options )", + "filename": "_import_tools.py", + "nloc": 66, + "complexity": 26, + "token_count": 481, + "parameters": [ + "self", + "packages", + "options" + ], + "start_line": 118, + "end_line": 234, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 117, + "top_nesting_level": 1 + } + ], + "nloc": 235, + "complexity": 78, + "token_count": 1721, + "diff_parsed": { + "added": [ + " postpone = options.get('postpone',None)", + " if (postpone and not global_symbols) \\", + " or (postpone_import and postpone is not None):" + ], + "deleted": [ + " postpone = options.get('postpone',False)", + " if (postpone and not global_symbols) or postpone_import:" + ] + } + } + ] + } +] \ No newline at end of file