[ { "hash": "bc2f8ecedb5d8a9ced56990d2add37db10c9a7d2", "msg": "Docs for livedocs", "author": { "name": "Pearu Peterson", "email": "pearu.peterson@gmail.com" }, "committer": { "name": "Pearu Peterson", "email": "pearu.peterson@gmail.com" }, "author_date": "2004-11-21T10:22:30+00:00", "author_timezone": 0, "committer_date": "2004-11-21T10:22:30+00:00", "committer_timezone": 0, "branches": [ "main" ], "in_main_branch": true, "merge": false, "parents": [ "34a21aee2e40d73183a4a1065cd087d2699e28ff" ], "project_name": "repo_copy", "project_path": "/tmp/tmpqop781_j/repo_copy", "deletions": 0, "insertions": 38, "lines": 38, "files": 3, "dmm_unit_size": null, "dmm_unit_complexity": null, "dmm_unit_interfacing": null, "modified_files": [ { "old_path": "scipy_test/__init__.py", "new_path": "scipy_test/__init__.py", "filename": "__init__.py", "extension": "py", "change_type": "MODIFY", "diff": "@@ -1,2 +1,3 @@\n \n+from info_scipy_test import __doc__\n from scipy_test_version import scipy_test_version as __version__\n", "added_lines": 1, "deleted_lines": 0, "source_code": "\nfrom info_scipy_test import __doc__\nfrom scipy_test_version import scipy_test_version as __version__\n", "source_code_before": "\nfrom scipy_test_version import scipy_test_version as __version__\n", "methods": [], "methods_before": [], "changed_methods": [], "nloc": 2, "complexity": 0, "token_count": 10, "diff_parsed": { "added": [ "from info_scipy_test import __doc__" ], "deleted": [] } }, { "old_path": "scipy_test/info_scipy_test.py", "new_path": "scipy_test/info_scipy_test.py", "filename": "info_scipy_test.py", "extension": "py", "change_type": "MODIFY", "diff": "@@ -1 +1,11 @@\n+\"\"\"\n+Scipy testing tools\n+===================\n+\n+Modules\n+-------\n+\n+ testing - useful tools for scipy-style testing sites.\n+\n+\"\"\"\n standalone = 1\n", "added_lines": 10, "deleted_lines": 0, "source_code": "\"\"\"\nScipy testing tools\n===================\n\nModules\n-------\n\n testing - useful tools for scipy-style testing sites.\n\n\"\"\"\nstandalone = 1\n", "source_code_before": "standalone = 1\n", "methods": [], "methods_before": [], "changed_methods": [], "nloc": 11, "complexity": 0, "token_count": 4, "diff_parsed": { "added": [ "\"\"\"", "Scipy testing tools", "===================", "", "Modules", "-------", "", " testing - useful tools for scipy-style testing sites.", "", "\"\"\"" ], "deleted": [] } }, { "old_path": "scipy_test/testing.py", "new_path": "scipy_test/testing.py", "filename": "testing.py", "extension": "py", "change_type": "MODIFY", "diff": "@@ -1,3 +1,30 @@\n+\"\"\"\n+Unit-testing\n+------------\n+\n+ ScipyTest - Scipy tests site manager\n+ ScipyTestCase - unittest.TestCase with measure method\n+ set_package_path - use it before importing a module to be tested\n+ restore_path - restore path after set_package_path\n+\n+Timing tools\n+------------\n+\n+ jiffies - return 1/100ths of a second that the current process has used\n+ memusage - virtual memory size in bytes of the running python [linux]\n+\n+Utility functions\n+-----------------\n+\n+ assert_equal\n+ assert_almost_equal\n+ assert_approx_equal\n+ assert_array_equal\n+ assert_array_almost_equal\n+ assert_array_less\n+ rand - array of random numbers from given shape\n+\n+\"\"\"\n \n __all__ = []\n \n", "added_lines": 27, "deleted_lines": 0, "source_code": "\"\"\"\nUnit-testing\n------------\n\n ScipyTest - Scipy tests site manager\n ScipyTestCase - unittest.TestCase with measure method\n set_package_path - use it before importing a module to be tested\n restore_path - restore path after set_package_path\n\nTiming tools\n------------\n\n jiffies - return 1/100ths of a second that the current process has used\n memusage - virtual memory size in bytes of the running python [linux]\n\nUtility functions\n-----------------\n\n assert_equal\n assert_almost_equal\n assert_approx_equal\n assert_array_equal\n assert_array_almost_equal\n assert_array_less\n rand - array of random numbers from given shape\n\n\"\"\"\n\n__all__ = []\n\nimport os,sys,time,glob,string,traceback,unittest\nimport types\nimport imp\n\ntry:\n # These are used by Numeric tests.\n # If Numeric and scipy_base are not available, then some of the\n # functions below will not be available.\n from Numeric import alltrue,equal,shape,ravel,around,zeros,Float64,asarray,\\\n less_equal,array2string,less\n # `import scipy_base.fastumath as math` must be at the end of this file.\nexcept ImportError,msg:\n print msg\n\nDEBUG = 0\n\n__all__.append('set_package_path')\ndef set_package_path(level=1):\n \"\"\" Prepend package directory to sys.path.\n\n set_package_path should be called from a test_file.py that\n satisfies the following tree structure:\n\n //test_file.py\n\n Then the first existing path name from the following list\n\n /build/lib.-\n /..\n\n is prepended to sys.path.\n The caller is responsible for removing this path by using\n\n restore_path()\n \"\"\"\n from distutils.util import get_platform\n from scipy_distutils.misc_util import get_frame\n f = get_frame(level)\n if f.f_locals['__name__']=='__main__':\n testfile = sys.argv[0]\n else:\n testfile = f.f_locals['__file__']\n d = os.path.dirname(os.path.dirname(os.path.abspath(testfile)))\n d1 = os.path.join(d,'build','lib.%s-%s'%(get_platform(),sys.version[:3]))\n if not os.path.isdir(d1):\n d1 = os.path.dirname(d)\n if DEBUG:\n print 'Inserting %r to sys.path' % (d1)\n sys.path.insert(0,d1)\n\n__all__.append('set_local_path')\ndef set_local_path(reldir='', level=1):\n \"\"\" Prepend local directory to sys.path.\n\n The caller is responsible for removing this path by using\n\n restore_path()\n \"\"\"\n from scipy_distutils.misc_util import get_frame\n f = get_frame(level)\n if f.f_locals['__name__']=='__main__':\n testfile = sys.argv[0]\n else:\n testfile = f.f_locals['__file__']\n local_path = os.path.join(os.path.dirname(os.path.abspath(testfile)),reldir)\n if DEBUG:\n print 'Inserting %r to sys.path' % (local_path)\n sys.path.insert(0,local_path)\n\n__all__.append('restore_path')\ndef restore_path():\n if DEBUG:\n print 'Removing %r from sys.path' % (sys.path[0])\n del sys.path[0]\n\nif sys.platform[:5]=='linux':\n def jiffies(_proc_pid_stat = '/proc/%s/stat'%(os.getpid()),\n _load_time=time.time()):\n \"\"\" Return number of jiffies (1/100ths of a second) that this\n process has been scheduled in user mode. See man 5 proc. \"\"\"\n try:\n f=open(_proc_pid_stat,'r')\n l = f.readline().split(' ')\n f.close()\n return int(l[13])\n except:\n return int(100*(time.time()-_load_time))\n\n def memusage(_proc_pid_stat = '/proc/%s/stat'%(os.getpid())):\n \"\"\" Return virtual memory size in bytes of the running python.\n \"\"\"\n try:\n f=open(_proc_pid_stat,'r')\n l = f.readline().split(' ')\n f.close()\n return int(l[22])\n except:\n return\nelse:\n # os.getpid is not in all platforms available.\n # Using time is safe but inaccurate, especially when process\n # was suspended or sleeping.\n def jiffies(_load_time=time.time()):\n \"\"\" Return number of jiffies (1/100ths of a second) that this\n process has been scheduled in user mode. [Emulation with time.time]. \"\"\"\n return int(100*(time.time()-_load_time))\n\n def memusage():\n \"\"\" Return memory usage of running python. [Not implemented]\"\"\"\n return\n\n__all__.append('ScipyTestCase')\nclass ScipyTestCase (unittest.TestCase):\n\n def measure(self,code_str,times=1):\n \"\"\" Return elapsed time for executing code_str in the\n namespace of the caller for given times.\n \"\"\"\n frame = sys._getframe(1)\n locs,globs = frame.f_locals,frame.f_globals\n code = compile(code_str,\n 'ScipyTestCase runner for '+self.__class__.__name__,\n 'exec')\n i = 0\n elapsed = jiffies()\n while i>> ScipyTest().test(level=1,verbosity=2)\n\n is package name or its module object.\n\n Package is supposed to contain a directory tests/\n with test_*.py files where * refers to the names of submodules.\n\n test_*.py files are supposed to define a classes, derived\n from ScipyTestCase or unittest.TestCase, with methods having\n names starting with test or bench or check.\n\n And that is it! No need to implement test or test_suite functions\n in each .py file.\n\n Also old styled test_suite(level=1) hooks are supported but\n soon to be removed.\n \"\"\"\n def __init__(self, package='__main__'):\n self.package = package\n\n def _module_str(self, module):\n filename = module.__file__[-30:]\n if filename!=module.__file__:\n filename = '...'+filename\n return '' % (`module.__name__`, `filename`)\n\n def _get_method_names(self,clsobj,level):\n names = []\n for mthname in _get_all_method_names(clsobj):\n if mthname[:5] not in ['bench','check'] \\\n and mthname[:4] not in ['test']:\n continue\n mth = getattr(clsobj, mthname)\n if type(mth) is not types.MethodType:\n continue\n d = mth.im_func.func_defaults\n if d is not None:\n mthlevel = d[0]\n else:\n mthlevel = 1\n if level>=mthlevel:\n if mthname not in names:\n names.append(mthname)\n for base in clsobj.__bases__:\n for n in self._get_method_names(base,level):\n if n not in names:\n names.append(n)\n return names\n\n def _get_module_tests(self,module,level):\n mstr = self._module_str\n d,f = os.path.split(module.__file__)\n\n short_module_name = os.path.splitext(os.path.basename(f))[0]\n if short_module_name=='__init__':\n short_module_name = module.__name__.split('.')[-1]\n\n test_dir = os.path.join(d,'tests')\n test_file = os.path.join(test_dir,'test_'+short_module_name+'.py')\n\n local_test_dir = os.path.join(os.getcwd(),'tests')\n local_test_file = os.path.join(local_test_dir,\n 'test_'+short_module_name+'.py')\n if os.path.basename(os.path.dirname(local_test_dir)) \\\n == os.path.basename(os.path.dirname(test_dir)) \\\n and os.path.isfile(local_test_file):\n test_file = local_test_file\n\n if not os.path.isfile(test_file):\n if short_module_name[:5]=='info_' \\\n and short_module_name[5:]==module.__name__.split('.')[-2]:\n return []\n if short_module_name in ['__cvs_version__','__svn_version__']:\n return []\n if short_module_name[-8:]=='_version' \\\n and short_module_name[:-8]==module.__name__.split('.')[-2]:\n return []\n print ' !! No test file %r found for %s' \\\n % (os.path.basename(test_file), mstr(module))\n return []\n\n try:\n if sys.version[:3]=='2.1':\n # Workaround for Python 2.1 .pyc file generator bug\n import random\n pref = '-nopyc'+`random.randint(1,100)`\n else:\n pref = ''\n f = open(test_file,'r')\n test_module = imp.load_module(\\\n module.__name__+'.test_'+short_module_name+pref,\n f, test_file+pref,('.py', 'r', 1))\n f.close()\n if sys.version[:3]=='2.1' and os.path.isfile(test_file+pref+'c'):\n os.remove(test_file+pref+'c')\n except:\n print ' !! FAILURE importing tests for ', mstr(module)\n print ' ',\n output_exception()\n return []\n return self._get_suite_list(test_module, level, module.__name__)\n\n def _get_suite_list(self, test_module, level, module_name='__main__'):\n mstr = self._module_str\n if hasattr(test_module,'test_suite'):\n # Using old styled test suite\n try:\n total_suite = test_module.test_suite(level)\n return total_suite._tests\n except:\n print ' !! FAILURE building tests for ', mstr(test_module)\n print ' ',\n output_exception()\n return []\n suite_list = []\n for name in dir(test_module):\n obj = getattr(test_module, name)\n if type(obj) is not type(unittest.TestCase) \\\n or not issubclass(obj, unittest.TestCase) \\\n or obj.__name__[:4] != 'test':\n continue\n suite_list.extend(map(obj,self._get_method_names(obj,level)))\n print ' Found',len(suite_list),'tests for',module_name\n return suite_list\n\n def _touch_ppimported(self, module):\n from scipy_base.ppimport import _ModuleLoader\n if os.path.isdir(os.path.join(os.path.dirname(module.__file__),'tests')):\n # only touching those modules that have tests/ directory\n try: module._pliuh_plauh\n except AttributeError: pass\n for name in dir(module):\n obj = getattr(module,name)\n if isinstance(obj,_ModuleLoader) \\\n and not hasattr(obj,'_ppimport_module') \\\n and not hasattr(obj,'_ppimport_exc_info'):\n self._touch_ppimported(obj)\n\n def test(self,level=1,verbosity=1):\n \"\"\" Run Scipy module test suite with level and verbosity.\n \"\"\"\n if type(self.package) is type(''):\n exec 'import %s as this_package' % (self.package)\n else:\n this_package = self.package\n\n self._touch_ppimported(this_package)\n\n package_name = this_package.__name__\n\n suites = []\n for name, module in sys.modules.items():\n if package_name != name[:len(package_name)] \\\n or module is None \\\n or os.path.basename(os.path.dirname(module.__file__))=='tests':\n continue\n suites.extend(self._get_module_tests(module, level))\n\n suites.extend(self._get_suite_list(sys.modules[package_name], level))\n\n all_tests = unittest.TestSuite(suites)\n runner = unittest.TextTestRunner(verbosity=verbosity)\n runner.run(all_tests)\n return runner\n\n def run(self):\n \"\"\" Run Scipy module test suite with level and verbosity\n taken from sys.argv. Requires optparse module.\n \"\"\"\n try:\n from optparse import OptionParser\n except ImportError:\n print 'Failed to import optparse module, ignoring.'\n return self.test()\n usage = r'usage: %prog [-v ] [-l ]'\n parser = OptionParser(usage)\n parser.add_option(\"-v\", \"--verbosity\",\n action=\"store\",\n dest=\"verbosity\",\n default=1,\n type='int')\n parser.add_option(\"-l\", \"--level\",\n action=\"store\",\n dest=\"level\",\n default=1,\n type='int')\n (options, args) = parser.parse_args()\n self.test(options.level,options.verbosity)\n\n#------------\n \ndef remove_ignored_patterns(files,pattern):\n from fnmatch import fnmatch\n good_files = []\n for file in files:\n if not fnmatch(file,pattern):\n good_files.append(file)\n return good_files\n\ndef remove_ignored_files(original,ignored_files,cur_dir):\n \"\"\" This is actually expanded to do pattern matching.\n\n \"\"\"\n if not ignored_files: ignored_files = []\n ignored_modules = map(lambda x: x+'.py',ignored_files)\n ignored_packages = ignored_files[:]\n # always ignore setup.py and __init__.py files\n ignored_files = ['setup.py','setup_*.py','__init__.py']\n ignored_files += ignored_modules + ignored_packages\n ignored_files = map(lambda x,cur_dir=cur_dir: os.path.join(cur_dir,x),\n ignored_files)\n #print 'ignored:', ignored_files\n #good_files = filter(lambda x,ignored = ignored_files: x not in ignored,\n # original)\n good_files = original\n for pattern in ignored_files:\n good_files = remove_ignored_patterns(good_files,pattern)\n\n return good_files\n\n__all__.append('harvest_modules')\ndef harvest_modules(package,ignore=None):\n \"\"\"* Retreive a list of all modules that live within a package.\n\n Only retreive files that are immediate children of the\n package -- do not recurse through child packages or\n directories. The returned list contains actual modules, not\n just their names.\n *\"\"\"\n d,f = os.path.split(package.__file__)\n\n # go through the directory and import every py file there.\n common_dir = os.path.join(d,'*.py')\n py_files = glob.glob(common_dir)\n #py_files.remove(os.path.join(d,'__init__.py'))\n #py_files.remove(os.path.join(d,'setup.py'))\n\n py_files = remove_ignored_files(py_files,ignore,d)\n #print 'py_files:', py_files\n try:\n prefix = package.__name__\n except:\n prefix = ''\n\n all_modules = []\n for file in py_files:\n d,f = os.path.split(file)\n base,ext = os.path.splitext(f)\n mod = prefix + '.' + base\n #print 'module: import ' + mod\n try:\n exec ('import ' + mod)\n all_modules.append(eval(mod))\n except:\n print 'FAILURE to import ' + mod\n output_exception()\n\n return all_modules\n\n__all__.append('harvest_packages')\ndef harvest_packages(package,ignore = None):\n \"\"\" Retreive a list of all sub-packages that live within a package.\n\n Only retreive packages that are immediate children of this\n package -- do not recurse through child packages or\n directories. The returned list contains actual package objects, not\n just their names.\n \"\"\"\n join = os.path.join\n\n d,f = os.path.split(package.__file__)\n\n common_dir = os.path.abspath(d)\n all_files = os.listdir(d)\n\n all_files = remove_ignored_files(all_files,ignore,'')\n #print 'all_files:', all_files\n try:\n prefix = package.__name__\n except:\n prefix = ''\n all_packages = []\n for directory in all_files:\n path = join(common_dir,directory)\n if os.path.isdir(path) and \\\n os.path.exists(join(path,'__init__.py')):\n sub_package = prefix + '.' + directory\n #print 'sub-package import ' + sub_package\n try:\n exec ('import ' + sub_package)\n all_packages.append(eval(sub_package))\n except:\n print 'FAILURE to import ' + sub_package\n output_exception()\n return all_packages\n\n__all__.append('harvest_modules_and_packages')\ndef harvest_modules_and_packages(package,ignore=None):\n \"\"\" Retreive list of all packages and modules that live within a package.\n\n See harvest_packages() and harvest_modules()\n \"\"\"\n all = harvest_modules(package,ignore) + harvest_packages(package,ignore)\n return all\n\n__all__.append('harvest_test_suites')\ndef harvest_test_suites(package,ignore = None,level=10):\n \"\"\"\n package -- the module to test. This is an actual module object\n (not a string)\n ignore -- a list of module names to omit from the tests\n level -- a value between 1 and 10. 1 will run the minimum number\n of tests. This is a fast \"smoke test\". Tests that take\n longer to run should have higher numbers ranging up to 10.\n \"\"\"\n suites=[]\n test_modules = harvest_modules_and_packages(package,ignore)\n #for i in test_modules:\n # print i.__name__\n for module in test_modules:\n if hasattr(module,'test_suite'):\n try:\n suite = module.test_suite(level=level)\n if suite:\n suites.append(suite)\n else:\n print \" !! FAILURE without error - shouldn't happen\",\n print module.__name__\n except:\n print ' !! FAILURE building test for ', module.__name__\n print ' ',\n output_exception()\n else:\n try:\n print 'No test suite found for ', module.__name__\n except AttributeError:\n # __version__.py getting replaced by a string throws a kink\n # in checking for modules, so we think is a module has\n # actually been overwritten\n print 'No test suite found for ', str(module)\n total_suite = unittest.TestSuite(suites)\n return total_suite\n\n__all__.append('module_test')\ndef module_test(mod_name,mod_file,level=10):\n \"\"\"*\n\n *\"\"\"\n #print 'testing', mod_name\n d,f = os.path.split(mod_file)\n\n # insert the tests directory to the python path\n test_dir = os.path.join(d,'tests')\n sys.path.insert(0,test_dir)\n\n # call the \"test_xxx.test()\" function for the appropriate\n # module.\n\n # This should deal with package naming issues correctly\n short_mod_name = string.split(mod_name,'.')[-1]\n test_module = 'test_' + short_mod_name\n test_string = 'import %s;reload(%s);%s.test(%d)' % \\\n ((test_module,)*3 + (level,))\n\n # This would be better cause it forces a reload of the orginal\n # module. It doesn't behave with packages however.\n #test_string = 'reload(%s);import %s;reload(%s);%s.test(%d)' % \\\n # ((mod_name,) + (test_module,)*3)\n exec(test_string)\n\n # remove test directory from python path.\n sys.path = sys.path[1:]\n\n__all__.append('module_test_suite')\ndef module_test_suite(mod_name,mod_file,level=10):\n #try:\n print ' creating test suite for:', mod_name\n d,f = os.path.split(mod_file)\n\n # insert the tests directory to the python path\n test_dir = os.path.join(d,'tests')\n sys.path.insert(0,test_dir)\n\n # call the \"test_xxx.test()\" function for the appropriate\n # module.\n\n # This should deal with package naming issues correctly\n short_mod_name = string.split(mod_name,'.')[-1]\n test_module = 'test_' + short_mod_name\n test_string = 'import %s;reload(%s);suite = %s.test_suite(%d)' % \\\n ((test_module,)*3+(level,))\n #print test_string\n exec(test_string)\n\n # remove test directory from python path.\n sys.path = sys.path[1:]\n return suite\n #except:\n # print ' !! FAILURE loading test suite from', test_module, ':'\n # print ' ',\n # output_exception()\n\n\n# Utility function to facilitate testing.\n\n__all__.append('assert_equal')\ndef assert_equal(actual,desired,err_msg='',verbose=1):\n \"\"\" Raise an assertion if two items are not\n equal. I think this should be part of unittest.py\n \"\"\"\n msg = '\\nItems are not equal:\\n' + err_msg\n try:\n if ( verbose and len(repr(desired)) < 100 and len(repr(actual)) ):\n msg = msg \\\n + 'DESIRED: ' + repr(desired) \\\n + '\\nACTUAL: ' + repr(actual)\n except:\n msg = msg \\\n + 'DESIRED: ' + repr(desired) \\\n + '\\nACTUAL: ' + repr(actual)\n assert desired == actual, msg\n\n__all__.append('assert_almost_equal')\ndef assert_almost_equal(actual,desired,decimal=7,err_msg='',verbose=1):\n \"\"\" Raise an assertion if two items are not\n equal. I think this should be part of unittest.py\n \"\"\"\n msg = '\\nItems are not equal:\\n' + err_msg\n try:\n if ( verbose and len(repr(desired)) < 100 and len(repr(actual)) ):\n msg = msg \\\n + 'DESIRED: ' + repr(desired) \\\n + '\\nACTUAL: ' + repr(actual)\n except:\n msg = msg \\\n + 'DESIRED: ' + repr(desired) \\\n + '\\nACTUAL: ' + repr(actual)\n assert round(abs(desired - actual),decimal) == 0, msg\n\n__all__.append('assert_approx_equal')\ndef assert_approx_equal(actual,desired,significant=7,err_msg='',verbose=1):\n \"\"\" Raise an assertion if two items are not\n equal. I think this should be part of unittest.py\n Approximately equal is defined as the number of significant digits\n correct\n \"\"\"\n msg = '\\nItems are not equal to %d significant digits:\\n' % significant\n msg += err_msg\n actual, desired = map(float, (actual, desired))\n # Normalized the numbers to be in range (-10.0,10.0)\n scale = pow(10,math.floor(math.log10(0.5*(abs(desired)+abs(actual)))))\n try:\n sc_desired = desired/scale\n except ZeroDivisionError:\n sc_desired = 0.0\n try:\n sc_actual = actual/scale\n except ZeroDivisionError:\n sc_actual = 0.0\n try:\n if ( verbose and len(repr(desired)) < 100 and len(repr(actual)) ):\n msg = msg \\\n + 'DESIRED: ' + repr(desired) \\\n + '\\nACTUAL: ' + repr(actual)\n except:\n msg = msg \\\n + 'DESIRED: ' + repr(desired) \\\n + '\\nACTUAL: ' + repr(actual)\n assert math.fabs(sc_desired - sc_actual) < pow(10.,-1*significant), msg\n\n\n__all__.append('assert_array_equal')\ndef assert_array_equal(x,y,err_msg=''):\n x,y = asarray(x), asarray(y)\n msg = '\\nArrays are not equal'\n try:\n assert 0 in [len(shape(x)),len(shape(y))] \\\n or (len(shape(x))==len(shape(y)) and \\\n alltrue(equal(shape(x),shape(y)))),\\\n msg + ' (shapes %s, %s mismatch):\\n\\t' \\\n % (shape(x),shape(y)) + err_msg\n reduced = ravel(equal(x,y))\n cond = alltrue(reduced)\n if not cond:\n s1 = array2string(x,precision=16)\n s2 = array2string(y,precision=16)\n if len(s1)>120: s1 = s1[:120] + '...'\n if len(s2)>120: s2 = s2[:120] + '...'\n match = 100-100.0*reduced.tolist().count(1)/len(reduced)\n msg = msg + ' (mismatch %s%%):\\n\\tArray 1: %s\\n\\tArray 2: %s' % (match,s1,s2)\n assert cond,\\\n msg + '\\n\\t' + err_msg\n except ValueError:\n raise ValueError, msg\n\n__all__.append('assert_array_almost_equal')\ndef assert_array_almost_equal(x,y,decimal=6,err_msg=''):\n x = asarray(x)\n y = asarray(y)\n msg = '\\nArrays are not almost equal'\n try:\n cond = alltrue(equal(shape(x),shape(y)))\n if not cond:\n msg = msg + ' (shapes mismatch):\\n\\t'\\\n 'Shape of array 1: %s\\n\\tShape of array 2: %s' % (shape(x),shape(y))\n assert cond, msg + '\\n\\t' + err_msg\n reduced = ravel(equal(less_equal(around(abs(x-y),decimal),10.0**(-decimal)),1))\n cond = alltrue(reduced)\n if not cond:\n s1 = array2string(x,precision=decimal+1)\n s2 = array2string(y,precision=decimal+1)\n if len(s1)>120: s1 = s1[:120] + '...'\n if len(s2)>120: s2 = s2[:120] + '...'\n match = 100-100.0*reduced.tolist().count(1)/len(reduced)\n msg = msg + ' (mismatch %s%%):\\n\\tArray 1: %s\\n\\tArray 2: %s' % (match,s1,s2)\n assert cond,\\\n msg + '\\n\\t' + err_msg\n except ValueError:\n print sys.exc_value\n print shape(x),shape(y)\n print x, y\n raise ValueError, 'arrays are not almost equal'\n\n__all__.append('assert_array_less')\ndef assert_array_less(x,y,err_msg=''):\n x,y = asarray(x), asarray(y)\n msg = '\\nArrays are not less-ordered'\n try:\n assert alltrue(equal(shape(x),shape(y))),\\\n msg + ' (shapes mismatch):\\n\\t' + err_msg\n reduced = ravel(less(x,y))\n cond = alltrue(reduced)\n if not cond:\n s1 = array2string(x,precision=16)\n s2 = array2string(y,precision=16)\n if len(s1)>120: s1 = s1[:120] + '...'\n if len(s2)>120: s2 = s2[:120] + '...'\n match = 100-100.0*reduced.tolist().count(1)/len(reduced)\n msg = msg + ' (mismatch %s%%):\\n\\tArray 1: %s\\n\\tArray 2: %s' % (match,s1,s2)\n assert cond,\\\n msg + '\\n\\t' + err_msg\n except ValueError:\n print shape(x),shape(y)\n raise ValueError, 'arrays are not less-ordered'\n\n__all__.append('rand')\ndef rand(*args):\n \"\"\" Returns an array of random numbers with the given shape.\n used for testing\n \"\"\"\n import random\n results = zeros(args,Float64)\n f = results.flat\n for i in range(len(f)):\n f[i] = random.random()\n return results\n\ndef output_exception():\n try:\n type, value, tb = sys.exc_info()\n info = traceback.extract_tb(tb)\n #this is more verbose\n #traceback.print_exc()\n filename, lineno, function, text = info[-1] # last line only\n print \"%s:%d: %s: %s (in %s)\" %\\\n (filename, lineno, type.__name__, str(value), function)\n finally:\n type = value = tb = None # clean up\n\ntry:\n import scipy_base.fastumath as math\nexcept ImportError,msg:\n print msg\n import math\n", "source_code_before": "\n__all__ = []\n\nimport os,sys,time,glob,string,traceback,unittest\nimport types\nimport imp\n\ntry:\n # These are used by Numeric tests.\n # If Numeric and scipy_base are not available, then some of the\n # functions below will not be available.\n from Numeric import alltrue,equal,shape,ravel,around,zeros,Float64,asarray,\\\n less_equal,array2string,less\n # `import scipy_base.fastumath as math` must be at the end of this file.\nexcept ImportError,msg:\n print msg\n\nDEBUG = 0\n\n__all__.append('set_package_path')\ndef set_package_path(level=1):\n \"\"\" Prepend package directory to sys.path.\n\n set_package_path should be called from a test_file.py that\n satisfies the following tree structure:\n\n //test_file.py\n\n Then the first existing path name from the following list\n\n /build/lib.-\n /..\n\n is prepended to sys.path.\n The caller is responsible for removing this path by using\n\n restore_path()\n \"\"\"\n from distutils.util import get_platform\n from scipy_distutils.misc_util import get_frame\n f = get_frame(level)\n if f.f_locals['__name__']=='__main__':\n testfile = sys.argv[0]\n else:\n testfile = f.f_locals['__file__']\n d = os.path.dirname(os.path.dirname(os.path.abspath(testfile)))\n d1 = os.path.join(d,'build','lib.%s-%s'%(get_platform(),sys.version[:3]))\n if not os.path.isdir(d1):\n d1 = os.path.dirname(d)\n if DEBUG:\n print 'Inserting %r to sys.path' % (d1)\n sys.path.insert(0,d1)\n\n__all__.append('set_local_path')\ndef set_local_path(reldir='', level=1):\n \"\"\" Prepend local directory to sys.path.\n\n The caller is responsible for removing this path by using\n\n restore_path()\n \"\"\"\n from scipy_distutils.misc_util import get_frame\n f = get_frame(level)\n if f.f_locals['__name__']=='__main__':\n testfile = sys.argv[0]\n else:\n testfile = f.f_locals['__file__']\n local_path = os.path.join(os.path.dirname(os.path.abspath(testfile)),reldir)\n if DEBUG:\n print 'Inserting %r to sys.path' % (local_path)\n sys.path.insert(0,local_path)\n\n__all__.append('restore_path')\ndef restore_path():\n if DEBUG:\n print 'Removing %r from sys.path' % (sys.path[0])\n del sys.path[0]\n\nif sys.platform[:5]=='linux':\n def jiffies(_proc_pid_stat = '/proc/%s/stat'%(os.getpid()),\n _load_time=time.time()):\n \"\"\" Return number of jiffies (1/100ths of a second) that this\n process has been scheduled in user mode. See man 5 proc. \"\"\"\n try:\n f=open(_proc_pid_stat,'r')\n l = f.readline().split(' ')\n f.close()\n return int(l[13])\n except:\n return int(100*(time.time()-_load_time))\n\n def memusage(_proc_pid_stat = '/proc/%s/stat'%(os.getpid())):\n \"\"\" Return virtual memory size in bytes of the running python.\n \"\"\"\n try:\n f=open(_proc_pid_stat,'r')\n l = f.readline().split(' ')\n f.close()\n return int(l[22])\n except:\n return\nelse:\n # os.getpid is not in all platforms available.\n # Using time is safe but inaccurate, especially when process\n # was suspended or sleeping.\n def jiffies(_load_time=time.time()):\n \"\"\" Return number of jiffies (1/100ths of a second) that this\n process has been scheduled in user mode. [Emulation with time.time]. \"\"\"\n return int(100*(time.time()-_load_time))\n\n def memusage():\n \"\"\" Return memory usage of running python. [Not implemented]\"\"\"\n return\n\n__all__.append('ScipyTestCase')\nclass ScipyTestCase (unittest.TestCase):\n\n def measure(self,code_str,times=1):\n \"\"\" Return elapsed time for executing code_str in the\n namespace of the caller for given times.\n \"\"\"\n frame = sys._getframe(1)\n locs,globs = frame.f_locals,frame.f_globals\n code = compile(code_str,\n 'ScipyTestCase runner for '+self.__class__.__name__,\n 'exec')\n i = 0\n elapsed = jiffies()\n while i>> ScipyTest().test(level=1,verbosity=2)\n\n is package name or its module object.\n\n Package is supposed to contain a directory tests/\n with test_*.py files where * refers to the names of submodules.\n\n test_*.py files are supposed to define a classes, derived\n from ScipyTestCase or unittest.TestCase, with methods having\n names starting with test or bench or check.\n\n And that is it! No need to implement test or test_suite functions\n in each .py file.\n\n Also old styled test_suite(level=1) hooks are supported but\n soon to be removed.\n \"\"\"\n def __init__(self, package='__main__'):\n self.package = package\n\n def _module_str(self, module):\n filename = module.__file__[-30:]\n if filename!=module.__file__:\n filename = '...'+filename\n return '' % (`module.__name__`, `filename`)\n\n def _get_method_names(self,clsobj,level):\n names = []\n for mthname in _get_all_method_names(clsobj):\n if mthname[:5] not in ['bench','check'] \\\n and mthname[:4] not in ['test']:\n continue\n mth = getattr(clsobj, mthname)\n if type(mth) is not types.MethodType:\n continue\n d = mth.im_func.func_defaults\n if d is not None:\n mthlevel = d[0]\n else:\n mthlevel = 1\n if level>=mthlevel:\n if mthname not in names:\n names.append(mthname)\n for base in clsobj.__bases__:\n for n in self._get_method_names(base,level):\n if n not in names:\n names.append(n)\n return names\n\n def _get_module_tests(self,module,level):\n mstr = self._module_str\n d,f = os.path.split(module.__file__)\n\n short_module_name = os.path.splitext(os.path.basename(f))[0]\n if short_module_name=='__init__':\n short_module_name = module.__name__.split('.')[-1]\n\n test_dir = os.path.join(d,'tests')\n test_file = os.path.join(test_dir,'test_'+short_module_name+'.py')\n\n local_test_dir = os.path.join(os.getcwd(),'tests')\n local_test_file = os.path.join(local_test_dir,\n 'test_'+short_module_name+'.py')\n if os.path.basename(os.path.dirname(local_test_dir)) \\\n == os.path.basename(os.path.dirname(test_dir)) \\\n and os.path.isfile(local_test_file):\n test_file = local_test_file\n\n if not os.path.isfile(test_file):\n if short_module_name[:5]=='info_' \\\n and short_module_name[5:]==module.__name__.split('.')[-2]:\n return []\n if short_module_name in ['__cvs_version__','__svn_version__']:\n return []\n if short_module_name[-8:]=='_version' \\\n and short_module_name[:-8]==module.__name__.split('.')[-2]:\n return []\n print ' !! No test file %r found for %s' \\\n % (os.path.basename(test_file), mstr(module))\n return []\n\n try:\n if sys.version[:3]=='2.1':\n # Workaround for Python 2.1 .pyc file generator bug\n import random\n pref = '-nopyc'+`random.randint(1,100)`\n else:\n pref = ''\n f = open(test_file,'r')\n test_module = imp.load_module(\\\n module.__name__+'.test_'+short_module_name+pref,\n f, test_file+pref,('.py', 'r', 1))\n f.close()\n if sys.version[:3]=='2.1' and os.path.isfile(test_file+pref+'c'):\n os.remove(test_file+pref+'c')\n except:\n print ' !! FAILURE importing tests for ', mstr(module)\n print ' ',\n output_exception()\n return []\n return self._get_suite_list(test_module, level, module.__name__)\n\n def _get_suite_list(self, test_module, level, module_name='__main__'):\n mstr = self._module_str\n if hasattr(test_module,'test_suite'):\n # Using old styled test suite\n try:\n total_suite = test_module.test_suite(level)\n return total_suite._tests\n except:\n print ' !! FAILURE building tests for ', mstr(test_module)\n print ' ',\n output_exception()\n return []\n suite_list = []\n for name in dir(test_module):\n obj = getattr(test_module, name)\n if type(obj) is not type(unittest.TestCase) \\\n or not issubclass(obj, unittest.TestCase) \\\n or obj.__name__[:4] != 'test':\n continue\n suite_list.extend(map(obj,self._get_method_names(obj,level)))\n print ' Found',len(suite_list),'tests for',module_name\n return suite_list\n\n def _touch_ppimported(self, module):\n from scipy_base.ppimport import _ModuleLoader\n if os.path.isdir(os.path.join(os.path.dirname(module.__file__),'tests')):\n # only touching those modules that have tests/ directory\n try: module._pliuh_plauh\n except AttributeError: pass\n for name in dir(module):\n obj = getattr(module,name)\n if isinstance(obj,_ModuleLoader) \\\n and not hasattr(obj,'_ppimport_module') \\\n and not hasattr(obj,'_ppimport_exc_info'):\n self._touch_ppimported(obj)\n\n def test(self,level=1,verbosity=1):\n \"\"\" Run Scipy module test suite with level and verbosity.\n \"\"\"\n if type(self.package) is type(''):\n exec 'import %s as this_package' % (self.package)\n else:\n this_package = self.package\n\n self._touch_ppimported(this_package)\n\n package_name = this_package.__name__\n\n suites = []\n for name, module in sys.modules.items():\n if package_name != name[:len(package_name)] \\\n or module is None \\\n or os.path.basename(os.path.dirname(module.__file__))=='tests':\n continue\n suites.extend(self._get_module_tests(module, level))\n\n suites.extend(self._get_suite_list(sys.modules[package_name], level))\n\n all_tests = unittest.TestSuite(suites)\n runner = unittest.TextTestRunner(verbosity=verbosity)\n runner.run(all_tests)\n return runner\n\n def run(self):\n \"\"\" Run Scipy module test suite with level and verbosity\n taken from sys.argv. Requires optparse module.\n \"\"\"\n try:\n from optparse import OptionParser\n except ImportError:\n print 'Failed to import optparse module, ignoring.'\n return self.test()\n usage = r'usage: %prog [-v ] [-l ]'\n parser = OptionParser(usage)\n parser.add_option(\"-v\", \"--verbosity\",\n action=\"store\",\n dest=\"verbosity\",\n default=1,\n type='int')\n parser.add_option(\"-l\", \"--level\",\n action=\"store\",\n dest=\"level\",\n default=1,\n type='int')\n (options, args) = parser.parse_args()\n self.test(options.level,options.verbosity)\n\n#------------\n \ndef remove_ignored_patterns(files,pattern):\n from fnmatch import fnmatch\n good_files = []\n for file in files:\n if not fnmatch(file,pattern):\n good_files.append(file)\n return good_files\n\ndef remove_ignored_files(original,ignored_files,cur_dir):\n \"\"\" This is actually expanded to do pattern matching.\n\n \"\"\"\n if not ignored_files: ignored_files = []\n ignored_modules = map(lambda x: x+'.py',ignored_files)\n ignored_packages = ignored_files[:]\n # always ignore setup.py and __init__.py files\n ignored_files = ['setup.py','setup_*.py','__init__.py']\n ignored_files += ignored_modules + ignored_packages\n ignored_files = map(lambda x,cur_dir=cur_dir: os.path.join(cur_dir,x),\n ignored_files)\n #print 'ignored:', ignored_files\n #good_files = filter(lambda x,ignored = ignored_files: x not in ignored,\n # original)\n good_files = original\n for pattern in ignored_files:\n good_files = remove_ignored_patterns(good_files,pattern)\n\n return good_files\n\n__all__.append('harvest_modules')\ndef harvest_modules(package,ignore=None):\n \"\"\"* Retreive a list of all modules that live within a package.\n\n Only retreive files that are immediate children of the\n package -- do not recurse through child packages or\n directories. The returned list contains actual modules, not\n just their names.\n *\"\"\"\n d,f = os.path.split(package.__file__)\n\n # go through the directory and import every py file there.\n common_dir = os.path.join(d,'*.py')\n py_files = glob.glob(common_dir)\n #py_files.remove(os.path.join(d,'__init__.py'))\n #py_files.remove(os.path.join(d,'setup.py'))\n\n py_files = remove_ignored_files(py_files,ignore,d)\n #print 'py_files:', py_files\n try:\n prefix = package.__name__\n except:\n prefix = ''\n\n all_modules = []\n for file in py_files:\n d,f = os.path.split(file)\n base,ext = os.path.splitext(f)\n mod = prefix + '.' + base\n #print 'module: import ' + mod\n try:\n exec ('import ' + mod)\n all_modules.append(eval(mod))\n except:\n print 'FAILURE to import ' + mod\n output_exception()\n\n return all_modules\n\n__all__.append('harvest_packages')\ndef harvest_packages(package,ignore = None):\n \"\"\" Retreive a list of all sub-packages that live within a package.\n\n Only retreive packages that are immediate children of this\n package -- do not recurse through child packages or\n directories. The returned list contains actual package objects, not\n just their names.\n \"\"\"\n join = os.path.join\n\n d,f = os.path.split(package.__file__)\n\n common_dir = os.path.abspath(d)\n all_files = os.listdir(d)\n\n all_files = remove_ignored_files(all_files,ignore,'')\n #print 'all_files:', all_files\n try:\n prefix = package.__name__\n except:\n prefix = ''\n all_packages = []\n for directory in all_files:\n path = join(common_dir,directory)\n if os.path.isdir(path) and \\\n os.path.exists(join(path,'__init__.py')):\n sub_package = prefix + '.' + directory\n #print 'sub-package import ' + sub_package\n try:\n exec ('import ' + sub_package)\n all_packages.append(eval(sub_package))\n except:\n print 'FAILURE to import ' + sub_package\n output_exception()\n return all_packages\n\n__all__.append('harvest_modules_and_packages')\ndef harvest_modules_and_packages(package,ignore=None):\n \"\"\" Retreive list of all packages and modules that live within a package.\n\n See harvest_packages() and harvest_modules()\n \"\"\"\n all = harvest_modules(package,ignore) + harvest_packages(package,ignore)\n return all\n\n__all__.append('harvest_test_suites')\ndef harvest_test_suites(package,ignore = None,level=10):\n \"\"\"\n package -- the module to test. This is an actual module object\n (not a string)\n ignore -- a list of module names to omit from the tests\n level -- a value between 1 and 10. 1 will run the minimum number\n of tests. This is a fast \"smoke test\". Tests that take\n longer to run should have higher numbers ranging up to 10.\n \"\"\"\n suites=[]\n test_modules = harvest_modules_and_packages(package,ignore)\n #for i in test_modules:\n # print i.__name__\n for module in test_modules:\n if hasattr(module,'test_suite'):\n try:\n suite = module.test_suite(level=level)\n if suite:\n suites.append(suite)\n else:\n print \" !! FAILURE without error - shouldn't happen\",\n print module.__name__\n except:\n print ' !! FAILURE building test for ', module.__name__\n print ' ',\n output_exception()\n else:\n try:\n print 'No test suite found for ', module.__name__\n except AttributeError:\n # __version__.py getting replaced by a string throws a kink\n # in checking for modules, so we think is a module has\n # actually been overwritten\n print 'No test suite found for ', str(module)\n total_suite = unittest.TestSuite(suites)\n return total_suite\n\n__all__.append('module_test')\ndef module_test(mod_name,mod_file,level=10):\n \"\"\"*\n\n *\"\"\"\n #print 'testing', mod_name\n d,f = os.path.split(mod_file)\n\n # insert the tests directory to the python path\n test_dir = os.path.join(d,'tests')\n sys.path.insert(0,test_dir)\n\n # call the \"test_xxx.test()\" function for the appropriate\n # module.\n\n # This should deal with package naming issues correctly\n short_mod_name = string.split(mod_name,'.')[-1]\n test_module = 'test_' + short_mod_name\n test_string = 'import %s;reload(%s);%s.test(%d)' % \\\n ((test_module,)*3 + (level,))\n\n # This would be better cause it forces a reload of the orginal\n # module. It doesn't behave with packages however.\n #test_string = 'reload(%s);import %s;reload(%s);%s.test(%d)' % \\\n # ((mod_name,) + (test_module,)*3)\n exec(test_string)\n\n # remove test directory from python path.\n sys.path = sys.path[1:]\n\n__all__.append('module_test_suite')\ndef module_test_suite(mod_name,mod_file,level=10):\n #try:\n print ' creating test suite for:', mod_name\n d,f = os.path.split(mod_file)\n\n # insert the tests directory to the python path\n test_dir = os.path.join(d,'tests')\n sys.path.insert(0,test_dir)\n\n # call the \"test_xxx.test()\" function for the appropriate\n # module.\n\n # This should deal with package naming issues correctly\n short_mod_name = string.split(mod_name,'.')[-1]\n test_module = 'test_' + short_mod_name\n test_string = 'import %s;reload(%s);suite = %s.test_suite(%d)' % \\\n ((test_module,)*3+(level,))\n #print test_string\n exec(test_string)\n\n # remove test directory from python path.\n sys.path = sys.path[1:]\n return suite\n #except:\n # print ' !! FAILURE loading test suite from', test_module, ':'\n # print ' ',\n # output_exception()\n\n\n# Utility function to facilitate testing.\n\n__all__.append('assert_equal')\ndef assert_equal(actual,desired,err_msg='',verbose=1):\n \"\"\" Raise an assertion if two items are not\n equal. I think this should be part of unittest.py\n \"\"\"\n msg = '\\nItems are not equal:\\n' + err_msg\n try:\n if ( verbose and len(repr(desired)) < 100 and len(repr(actual)) ):\n msg = msg \\\n + 'DESIRED: ' + repr(desired) \\\n + '\\nACTUAL: ' + repr(actual)\n except:\n msg = msg \\\n + 'DESIRED: ' + repr(desired) \\\n + '\\nACTUAL: ' + repr(actual)\n assert desired == actual, msg\n\n__all__.append('assert_almost_equal')\ndef assert_almost_equal(actual,desired,decimal=7,err_msg='',verbose=1):\n \"\"\" Raise an assertion if two items are not\n equal. I think this should be part of unittest.py\n \"\"\"\n msg = '\\nItems are not equal:\\n' + err_msg\n try:\n if ( verbose and len(repr(desired)) < 100 and len(repr(actual)) ):\n msg = msg \\\n + 'DESIRED: ' + repr(desired) \\\n + '\\nACTUAL: ' + repr(actual)\n except:\n msg = msg \\\n + 'DESIRED: ' + repr(desired) \\\n + '\\nACTUAL: ' + repr(actual)\n assert round(abs(desired - actual),decimal) == 0, msg\n\n__all__.append('assert_approx_equal')\ndef assert_approx_equal(actual,desired,significant=7,err_msg='',verbose=1):\n \"\"\" Raise an assertion if two items are not\n equal. I think this should be part of unittest.py\n Approximately equal is defined as the number of significant digits\n correct\n \"\"\"\n msg = '\\nItems are not equal to %d significant digits:\\n' % significant\n msg += err_msg\n actual, desired = map(float, (actual, desired))\n # Normalized the numbers to be in range (-10.0,10.0)\n scale = pow(10,math.floor(math.log10(0.5*(abs(desired)+abs(actual)))))\n try:\n sc_desired = desired/scale\n except ZeroDivisionError:\n sc_desired = 0.0\n try:\n sc_actual = actual/scale\n except ZeroDivisionError:\n sc_actual = 0.0\n try:\n if ( verbose and len(repr(desired)) < 100 and len(repr(actual)) ):\n msg = msg \\\n + 'DESIRED: ' + repr(desired) \\\n + '\\nACTUAL: ' + repr(actual)\n except:\n msg = msg \\\n + 'DESIRED: ' + repr(desired) \\\n + '\\nACTUAL: ' + repr(actual)\n assert math.fabs(sc_desired - sc_actual) < pow(10.,-1*significant), msg\n\n\n__all__.append('assert_array_equal')\ndef assert_array_equal(x,y,err_msg=''):\n x,y = asarray(x), asarray(y)\n msg = '\\nArrays are not equal'\n try:\n assert 0 in [len(shape(x)),len(shape(y))] \\\n or (len(shape(x))==len(shape(y)) and \\\n alltrue(equal(shape(x),shape(y)))),\\\n msg + ' (shapes %s, %s mismatch):\\n\\t' \\\n % (shape(x),shape(y)) + err_msg\n reduced = ravel(equal(x,y))\n cond = alltrue(reduced)\n if not cond:\n s1 = array2string(x,precision=16)\n s2 = array2string(y,precision=16)\n if len(s1)>120: s1 = s1[:120] + '...'\n if len(s2)>120: s2 = s2[:120] + '...'\n match = 100-100.0*reduced.tolist().count(1)/len(reduced)\n msg = msg + ' (mismatch %s%%):\\n\\tArray 1: %s\\n\\tArray 2: %s' % (match,s1,s2)\n assert cond,\\\n msg + '\\n\\t' + err_msg\n except ValueError:\n raise ValueError, msg\n\n__all__.append('assert_array_almost_equal')\ndef assert_array_almost_equal(x,y,decimal=6,err_msg=''):\n x = asarray(x)\n y = asarray(y)\n msg = '\\nArrays are not almost equal'\n try:\n cond = alltrue(equal(shape(x),shape(y)))\n if not cond:\n msg = msg + ' (shapes mismatch):\\n\\t'\\\n 'Shape of array 1: %s\\n\\tShape of array 2: %s' % (shape(x),shape(y))\n assert cond, msg + '\\n\\t' + err_msg\n reduced = ravel(equal(less_equal(around(abs(x-y),decimal),10.0**(-decimal)),1))\n cond = alltrue(reduced)\n if not cond:\n s1 = array2string(x,precision=decimal+1)\n s2 = array2string(y,precision=decimal+1)\n if len(s1)>120: s1 = s1[:120] + '...'\n if len(s2)>120: s2 = s2[:120] + '...'\n match = 100-100.0*reduced.tolist().count(1)/len(reduced)\n msg = msg + ' (mismatch %s%%):\\n\\tArray 1: %s\\n\\tArray 2: %s' % (match,s1,s2)\n assert cond,\\\n msg + '\\n\\t' + err_msg\n except ValueError:\n print sys.exc_value\n print shape(x),shape(y)\n print x, y\n raise ValueError, 'arrays are not almost equal'\n\n__all__.append('assert_array_less')\ndef assert_array_less(x,y,err_msg=''):\n x,y = asarray(x), asarray(y)\n msg = '\\nArrays are not less-ordered'\n try:\n assert alltrue(equal(shape(x),shape(y))),\\\n msg + ' (shapes mismatch):\\n\\t' + err_msg\n reduced = ravel(less(x,y))\n cond = alltrue(reduced)\n if not cond:\n s1 = array2string(x,precision=16)\n s2 = array2string(y,precision=16)\n if len(s1)>120: s1 = s1[:120] + '...'\n if len(s2)>120: s2 = s2[:120] + '...'\n match = 100-100.0*reduced.tolist().count(1)/len(reduced)\n msg = msg + ' (mismatch %s%%):\\n\\tArray 1: %s\\n\\tArray 2: %s' % (match,s1,s2)\n assert cond,\\\n msg + '\\n\\t' + err_msg\n except ValueError:\n print shape(x),shape(y)\n raise ValueError, 'arrays are not less-ordered'\n\n__all__.append('rand')\ndef rand(*args):\n \"\"\" Returns an array of random numbers with the given shape.\n used for testing\n \"\"\"\n import random\n results = zeros(args,Float64)\n f = results.flat\n for i in range(len(f)):\n f[i] = random.random()\n return results\n\ndef output_exception():\n try:\n type, value, tb = sys.exc_info()\n info = traceback.extract_tb(tb)\n #this is more verbose\n #traceback.print_exc()\n filename, lineno, function, text = info[-1] # last line only\n print \"%s:%d: %s: %s (in %s)\" %\\\n (filename, lineno, type.__name__, str(value), function)\n finally:\n type = value = tb = None # clean up\n\ntry:\n import scipy_base.fastumath as math\nexcept ImportError,msg:\n print msg\n import math\n", "methods": [ { "name": "set_package_path", "long_name": "set_package_path( level = 1 )", "filename": "testing.py", "nloc": 15, "complexity": 4, "token_count": 146, "parameters": [ "level" ], "start_line": 48, "end_line": 79, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 32, "top_nesting_level": 0 }, { "name": "set_local_path", "long_name": "set_local_path( reldir = '' , level = 1 )", "filename": "testing.py", "nloc": 11, "complexity": 3, "token_count": 97, "parameters": [ "reldir", "level" ], "start_line": 82, "end_line": 98, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 17, "top_nesting_level": 0 }, { "name": "restore_path", "long_name": "restore_path( )", "filename": "testing.py", "nloc": 4, "complexity": 2, "token_count": 25, "parameters": [], "start_line": 101, "end_line": 104, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 4, "top_nesting_level": 0 }, { "name": "jiffies", "long_name": "jiffies( _proc_pid_stat = '/proc/%s/stat' % ( os . getpid ( )", "filename": "testing.py", "nloc": 2, "complexity": 1, "token_count": 23, "parameters": [ "_proc_pid_stat" ], "start_line": 107, "end_line": 108, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 2, "top_nesting_level": 1 }, { "name": "memusage", "long_name": "memusage( _proc_pid_stat = '/proc/%s/stat' % ( os . getpid ( )", "filename": "testing.py", "nloc": 10, "complexity": 2, "token_count": 54, "parameters": [ "_proc_pid_stat" ], "start_line": 119, "end_line": 128, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 10, "top_nesting_level": 1 }, { "name": "jiffies", "long_name": "jiffies( _load_time = time . time ( )", "filename": "testing.py", "nloc": 4, "complexity": 1, "token_count": 27, "parameters": [ "_load_time" ], "start_line": 133, "end_line": 136, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 4, "top_nesting_level": 1 }, { "name": "memusage", "long_name": "memusage( )", "filename": "testing.py", "nloc": 2, "complexity": 1, "token_count": 6, "parameters": [], "start_line": 138, "end_line": 140, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 3, "top_nesting_level": 1 }, { "name": "measure", "long_name": "measure( self , code_str , times = 1 )", "filename": "testing.py", "nloc": 13, "complexity": 2, "token_count": 82, "parameters": [ "self", "code_str", "times" ], "start_line": 145, "end_line": 160, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 16, "top_nesting_level": 1 }, { "name": "__call__", "long_name": "__call__( self , result = None )", "filename": "testing.py", "nloc": 19, "complexity": 5, "token_count": 175, "parameters": [ "self", "result" ], "start_line": 162, "end_line": 181, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 20, "top_nesting_level": 1 }, { "name": "__init__", "long_name": "__init__( self )", "filename": "testing.py", "nloc": 2, "complexity": 1, "token_count": 11, "parameters": [ "self" ], "start_line": 184, "end_line": 185, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 2, "top_nesting_level": 1 }, { "name": "write", "long_name": "write( self , message )", "filename": "testing.py", "nloc": 2, "complexity": 1, "token_count": 15, "parameters": [ "self", "message" ], "start_line": 186, "end_line": 187, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 2, "top_nesting_level": 1 }, { "name": "writeln", "long_name": "writeln( self , message )", "filename": "testing.py", "nloc": 2, "complexity": 1, "token_count": 17, "parameters": [ "self", "message" ], "start_line": 188, "end_line": 189, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 2, "top_nesting_level": 1 }, { "name": "_get_all_method_names", "long_name": "_get_all_method_names( cls )", "filename": "testing.py", "nloc": 8, "complexity": 5, "token_count": 56, "parameters": [ "cls" ], "start_line": 197, "end_line": 204, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 8, "top_nesting_level": 0 }, { "name": "__init__", "long_name": "__init__( self , package = '__main__' )", "filename": "testing.py", "nloc": 2, "complexity": 1, "token_count": 14, "parameters": [ "self", "package" ], "start_line": 228, "end_line": 229, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 2, "top_nesting_level": 1 }, { "name": "_module_str", "long_name": "_module_str( self , module )", "filename": "testing.py", "nloc": 5, "complexity": 2, "token_count": 43, "parameters": [ "self", "module" ], "start_line": 231, "end_line": 235, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 5, "top_nesting_level": 1 }, { "name": "_get_method_names", "long_name": "_get_method_names( self , clsobj , level )", "filename": "testing.py", "nloc": 22, "complexity": 11, "token_count": 142, "parameters": [ "self", "clsobj", "level" ], "start_line": 237, "end_line": 258, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 22, "top_nesting_level": 1 }, { "name": "_get_module_tests", "long_name": "_get_module_tests( self , module , level )", "filename": "testing.py", "nloc": 46, "complexity": 14, "token_count": 428, "parameters": [ "self", "module", "level" ], "start_line": 260, "end_line": 311, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 52, "top_nesting_level": 1 }, { "name": "_get_suite_list", "long_name": "_get_suite_list( self , test_module , level , module_name = '__main__' )", "filename": "testing.py", "nloc": 21, "complexity": 7, "token_count": 146, "parameters": [ "self", "test_module", "level", "module_name" ], "start_line": 313, "end_line": 334, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 22, "top_nesting_level": 1 }, { "name": "_touch_ppimported", "long_name": "_touch_ppimported( self , module )", "filename": "testing.py", "nloc": 11, "complexity": 7, "token_count": 98, "parameters": [ "self", "module" ], "start_line": 336, "end_line": 347, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 12, "top_nesting_level": 1 }, { "name": "test", "long_name": "test( self , level = 1 , verbosity = 1 )", "filename": "testing.py", "nloc": 19, "complexity": 6, "token_count": 166, "parameters": [ "self", "level", "verbosity" ], "start_line": 349, "end_line": 374, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 26, "top_nesting_level": 1 }, { "name": "run", "long_name": "run( self )", "filename": "testing.py", "nloc": 20, "complexity": 2, "token_count": 104, "parameters": [ "self" ], "start_line": 376, "end_line": 398, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 23, "top_nesting_level": 1 }, { "name": "remove_ignored_patterns", "long_name": "remove_ignored_patterns( files , pattern )", "filename": "testing.py", "nloc": 7, "complexity": 3, "token_count": 37, "parameters": [ "files", "pattern" ], "start_line": 402, "end_line": 408, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 7, "top_nesting_level": 0 }, { "name": "remove_ignored_files", "long_name": "remove_ignored_files( original , ignored_files , cur_dir )", "filename": "testing.py", "nloc": 12, "complexity": 3, "token_count": 93, "parameters": [ "original", "ignored_files", "cur_dir" ], "start_line": 410, "end_line": 429, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 20, "top_nesting_level": 0 }, { "name": "harvest_modules", "long_name": "harvest_modules( package , ignore = None )", "filename": "testing.py", "nloc": 21, "complexity": 4, "token_count": 134, "parameters": [ "package", "ignore" ], "start_line": 432, "end_line": 468, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 37, "top_nesting_level": 0 }, { "name": "harvest_packages", "long_name": "harvest_packages( package , ignore = None )", "filename": "testing.py", "nloc": 23, "complexity": 6, "token_count": 148, "parameters": [ "package", "ignore" ], "start_line": 471, "end_line": 505, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 35, "top_nesting_level": 0 }, { "name": "harvest_modules_and_packages", "long_name": "harvest_modules_and_packages( package , ignore = None )", "filename": "testing.py", "nloc": 3, "complexity": 1, "token_count": 27, "parameters": [ "package", "ignore" ], "start_line": 508, "end_line": 514, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 7, "top_nesting_level": 0 }, { "name": "harvest_test_suites", "long_name": "harvest_test_suites( package , ignore = None , level = 10 )", "filename": "testing.py", "nloc": 23, "complexity": 6, "token_count": 113, "parameters": [ "package", "ignore", "level" ], "start_line": 517, "end_line": 552, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 36, "top_nesting_level": 0 }, { "name": "module_test", "long_name": "module_test( mod_name , mod_file , level = 10 )", "filename": "testing.py", "nloc": 10, "complexity": 1, "token_count": 98, "parameters": [ "mod_name", "mod_file", "level" ], "start_line": 555, "end_line": 582, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 28, "top_nesting_level": 0 }, { "name": "module_test_suite", "long_name": "module_test_suite( mod_name , mod_file , level = 10 )", "filename": "testing.py", "nloc": 12, "complexity": 1, "token_count": 103, "parameters": [ "mod_name", "mod_file", "level" ], "start_line": 585, "end_line": 607, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 23, "top_nesting_level": 0 }, { "name": "assert_equal", "long_name": "assert_equal( actual , desired , err_msg = '' , verbose = 1 )", "filename": "testing.py", "nloc": 12, "complexity": 5, "token_count": 92, "parameters": [ "actual", "desired", "err_msg", "verbose" ], "start_line": 617, "end_line": 631, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 15, "top_nesting_level": 0 }, { "name": "assert_almost_equal", "long_name": "assert_almost_equal( actual , desired , decimal = 7 , err_msg = '' , verbose = 1 )", "filename": "testing.py", "nloc": 12, "complexity": 5, "token_count": 106, "parameters": [ "actual", "desired", "decimal", "err_msg", "verbose" ], "start_line": 634, "end_line": 648, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 15, "top_nesting_level": 0 }, { "name": "assert_approx_equal", "long_name": "assert_approx_equal( actual , desired , significant = 7 , err_msg = '' , verbose = 1 )", "filename": "testing.py", "nloc": 23, "complexity": 7, "token_count": 191, "parameters": [ "actual", "desired", "significant", "err_msg", "verbose" ], "start_line": 651, "end_line": 679, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 29, "top_nesting_level": 0 }, { "name": "assert_array_equal", "long_name": "assert_array_equal( x , y , err_msg = '' )", "filename": "testing.py", "nloc": 22, "complexity": 7, "token_count": 232, "parameters": [ "x", "y", "err_msg" ], "start_line": 683, "end_line": 704, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 22, "top_nesting_level": 0 }, { "name": "assert_array_almost_equal", "long_name": "assert_array_almost_equal( x , y , decimal = 6 , err_msg = '' )", "filename": "testing.py", "nloc": 26, "complexity": 6, "token_count": 251, "parameters": [ "x", "y", "decimal", "err_msg" ], "start_line": 707, "end_line": 732, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 26, "top_nesting_level": 0 }, { "name": "assert_array_less", "long_name": "assert_array_less( x , y , err_msg = '' )", "filename": "testing.py", "nloc": 20, "complexity": 5, "token_count": 189, "parameters": [ "x", "y", "err_msg" ], "start_line": 735, "end_line": 754, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 20, "top_nesting_level": 0 }, { "name": "rand", "long_name": "rand( * args )", "filename": "testing.py", "nloc": 7, "complexity": 2, "token_count": 45, "parameters": [ "args" ], "start_line": 757, "end_line": 766, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 10, "top_nesting_level": 0 }, { "name": "output_exception", "long_name": "output_exception( )", "filename": "testing.py", "nloc": 9, "complexity": 2, "token_count": 67, "parameters": [], "start_line": 768, "end_line": 778, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 11, "top_nesting_level": 0 } ], "methods_before": [ { "name": "set_package_path", "long_name": "set_package_path( level = 1 )", "filename": "testing.py", "nloc": 15, "complexity": 4, "token_count": 146, "parameters": [ "level" ], "start_line": 21, "end_line": 52, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 32, "top_nesting_level": 0 }, { "name": "set_local_path", "long_name": "set_local_path( reldir = '' , level = 1 )", "filename": "testing.py", "nloc": 11, "complexity": 3, "token_count": 97, "parameters": [ "reldir", "level" ], "start_line": 55, "end_line": 71, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 17, "top_nesting_level": 0 }, { "name": "restore_path", "long_name": "restore_path( )", "filename": "testing.py", "nloc": 4, "complexity": 2, "token_count": 25, "parameters": [], "start_line": 74, "end_line": 77, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 4, "top_nesting_level": 0 }, { "name": "jiffies", "long_name": "jiffies( _proc_pid_stat = '/proc/%s/stat' % ( os . getpid ( )", "filename": "testing.py", "nloc": 2, "complexity": 1, "token_count": 23, "parameters": [ "_proc_pid_stat" ], "start_line": 80, "end_line": 81, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 2, "top_nesting_level": 1 }, { "name": "memusage", "long_name": "memusage( _proc_pid_stat = '/proc/%s/stat' % ( os . getpid ( )", "filename": "testing.py", "nloc": 10, "complexity": 2, "token_count": 54, "parameters": [ "_proc_pid_stat" ], "start_line": 92, "end_line": 101, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 10, "top_nesting_level": 1 }, { "name": "jiffies", "long_name": "jiffies( _load_time = time . time ( )", "filename": "testing.py", "nloc": 4, "complexity": 1, "token_count": 27, "parameters": [ "_load_time" ], "start_line": 106, "end_line": 109, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 4, "top_nesting_level": 1 }, { "name": "memusage", "long_name": "memusage( )", "filename": "testing.py", "nloc": 2, "complexity": 1, "token_count": 6, "parameters": [], "start_line": 111, "end_line": 113, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 3, "top_nesting_level": 1 }, { "name": "measure", "long_name": "measure( self , code_str , times = 1 )", "filename": "testing.py", "nloc": 13, "complexity": 2, "token_count": 82, "parameters": [ "self", "code_str", "times" ], "start_line": 118, "end_line": 133, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 16, "top_nesting_level": 1 }, { "name": "__call__", "long_name": "__call__( self , result = None )", "filename": "testing.py", "nloc": 19, "complexity": 5, "token_count": 175, "parameters": [ "self", "result" ], "start_line": 135, "end_line": 154, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 20, "top_nesting_level": 1 }, { "name": "__init__", "long_name": "__init__( self )", "filename": "testing.py", "nloc": 2, "complexity": 1, "token_count": 11, "parameters": [ "self" ], "start_line": 157, "end_line": 158, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 2, "top_nesting_level": 1 }, { "name": "write", "long_name": "write( self , message )", "filename": "testing.py", "nloc": 2, "complexity": 1, "token_count": 15, "parameters": [ "self", "message" ], "start_line": 159, "end_line": 160, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 2, "top_nesting_level": 1 }, { "name": "writeln", "long_name": "writeln( self , message )", "filename": "testing.py", "nloc": 2, "complexity": 1, "token_count": 17, "parameters": [ "self", "message" ], "start_line": 161, "end_line": 162, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 2, "top_nesting_level": 1 }, { "name": "_get_all_method_names", "long_name": "_get_all_method_names( cls )", "filename": "testing.py", "nloc": 8, "complexity": 5, "token_count": 56, "parameters": [ "cls" ], "start_line": 170, "end_line": 177, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 8, "top_nesting_level": 0 }, { "name": "__init__", "long_name": "__init__( self , package = '__main__' )", "filename": "testing.py", "nloc": 2, "complexity": 1, "token_count": 14, "parameters": [ "self", "package" ], "start_line": 201, "end_line": 202, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 2, "top_nesting_level": 1 }, { "name": "_module_str", "long_name": "_module_str( self , module )", "filename": "testing.py", "nloc": 5, "complexity": 2, "token_count": 43, "parameters": [ "self", "module" ], "start_line": 204, "end_line": 208, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 5, "top_nesting_level": 1 }, { "name": "_get_method_names", "long_name": "_get_method_names( self , clsobj , level )", "filename": "testing.py", "nloc": 22, "complexity": 11, "token_count": 142, "parameters": [ "self", "clsobj", "level" ], "start_line": 210, "end_line": 231, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 22, "top_nesting_level": 1 }, { "name": "_get_module_tests", "long_name": "_get_module_tests( self , module , level )", "filename": "testing.py", "nloc": 46, "complexity": 14, "token_count": 428, "parameters": [ "self", "module", "level" ], "start_line": 233, "end_line": 284, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 52, "top_nesting_level": 1 }, { "name": "_get_suite_list", "long_name": "_get_suite_list( self , test_module , level , module_name = '__main__' )", "filename": "testing.py", "nloc": 21, "complexity": 7, "token_count": 146, "parameters": [ "self", "test_module", "level", "module_name" ], "start_line": 286, "end_line": 307, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 22, "top_nesting_level": 1 }, { "name": "_touch_ppimported", "long_name": "_touch_ppimported( self , module )", "filename": "testing.py", "nloc": 11, "complexity": 7, "token_count": 98, "parameters": [ "self", "module" ], "start_line": 309, "end_line": 320, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 12, "top_nesting_level": 1 }, { "name": "test", "long_name": "test( self , level = 1 , verbosity = 1 )", "filename": "testing.py", "nloc": 19, "complexity": 6, "token_count": 166, "parameters": [ "self", "level", "verbosity" ], "start_line": 322, "end_line": 347, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 26, "top_nesting_level": 1 }, { "name": "run", "long_name": "run( self )", "filename": "testing.py", "nloc": 20, "complexity": 2, "token_count": 104, "parameters": [ "self" ], "start_line": 349, "end_line": 371, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 23, "top_nesting_level": 1 }, { "name": "remove_ignored_patterns", "long_name": "remove_ignored_patterns( files , pattern )", "filename": "testing.py", "nloc": 7, "complexity": 3, "token_count": 37, "parameters": [ "files", "pattern" ], "start_line": 375, "end_line": 381, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 7, "top_nesting_level": 0 }, { "name": "remove_ignored_files", "long_name": "remove_ignored_files( original , ignored_files , cur_dir )", "filename": "testing.py", "nloc": 12, "complexity": 3, "token_count": 93, "parameters": [ "original", "ignored_files", "cur_dir" ], "start_line": 383, "end_line": 402, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 20, "top_nesting_level": 0 }, { "name": "harvest_modules", "long_name": "harvest_modules( package , ignore = None )", "filename": "testing.py", "nloc": 21, "complexity": 4, "token_count": 134, "parameters": [ "package", "ignore" ], "start_line": 405, "end_line": 441, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 37, "top_nesting_level": 0 }, { "name": "harvest_packages", "long_name": "harvest_packages( package , ignore = None )", "filename": "testing.py", "nloc": 23, "complexity": 6, "token_count": 148, "parameters": [ "package", "ignore" ], "start_line": 444, "end_line": 478, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 35, "top_nesting_level": 0 }, { "name": "harvest_modules_and_packages", "long_name": "harvest_modules_and_packages( package , ignore = None )", "filename": "testing.py", "nloc": 3, "complexity": 1, "token_count": 27, "parameters": [ "package", "ignore" ], "start_line": 481, "end_line": 487, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 7, "top_nesting_level": 0 }, { "name": "harvest_test_suites", "long_name": "harvest_test_suites( package , ignore = None , level = 10 )", "filename": "testing.py", "nloc": 23, "complexity": 6, "token_count": 113, "parameters": [ "package", "ignore", "level" ], "start_line": 490, "end_line": 525, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 36, "top_nesting_level": 0 }, { "name": "module_test", "long_name": "module_test( mod_name , mod_file , level = 10 )", "filename": "testing.py", "nloc": 10, "complexity": 1, "token_count": 98, "parameters": [ "mod_name", "mod_file", "level" ], "start_line": 528, "end_line": 555, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 28, "top_nesting_level": 0 }, { "name": "module_test_suite", "long_name": "module_test_suite( mod_name , mod_file , level = 10 )", "filename": "testing.py", "nloc": 12, "complexity": 1, "token_count": 103, "parameters": [ "mod_name", "mod_file", "level" ], "start_line": 558, "end_line": 580, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 23, "top_nesting_level": 0 }, { "name": "assert_equal", "long_name": "assert_equal( actual , desired , err_msg = '' , verbose = 1 )", "filename": "testing.py", "nloc": 12, "complexity": 5, "token_count": 92, "parameters": [ "actual", "desired", "err_msg", "verbose" ], "start_line": 590, "end_line": 604, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 15, "top_nesting_level": 0 }, { "name": "assert_almost_equal", "long_name": "assert_almost_equal( actual , desired , decimal = 7 , err_msg = '' , verbose = 1 )", "filename": "testing.py", "nloc": 12, "complexity": 5, "token_count": 106, "parameters": [ "actual", "desired", "decimal", "err_msg", "verbose" ], "start_line": 607, "end_line": 621, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 15, "top_nesting_level": 0 }, { "name": "assert_approx_equal", "long_name": "assert_approx_equal( actual , desired , significant = 7 , err_msg = '' , verbose = 1 )", "filename": "testing.py", "nloc": 23, "complexity": 7, "token_count": 191, "parameters": [ "actual", "desired", "significant", "err_msg", "verbose" ], "start_line": 624, "end_line": 652, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 29, "top_nesting_level": 0 }, { "name": "assert_array_equal", "long_name": "assert_array_equal( x , y , err_msg = '' )", "filename": "testing.py", "nloc": 22, "complexity": 7, "token_count": 232, "parameters": [ "x", "y", "err_msg" ], "start_line": 656, "end_line": 677, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 22, "top_nesting_level": 0 }, { "name": "assert_array_almost_equal", "long_name": "assert_array_almost_equal( x , y , decimal = 6 , err_msg = '' )", "filename": "testing.py", "nloc": 26, "complexity": 6, "token_count": 251, "parameters": [ "x", "y", "decimal", "err_msg" ], "start_line": 680, "end_line": 705, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 26, "top_nesting_level": 0 }, { "name": "assert_array_less", "long_name": "assert_array_less( x , y , err_msg = '' )", "filename": "testing.py", "nloc": 20, "complexity": 5, "token_count": 189, "parameters": [ "x", "y", "err_msg" ], "start_line": 708, "end_line": 727, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 20, "top_nesting_level": 0 }, { "name": "rand", "long_name": "rand( * args )", "filename": "testing.py", "nloc": 7, "complexity": 2, "token_count": 45, "parameters": [ "args" ], "start_line": 730, "end_line": 739, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 10, "top_nesting_level": 0 }, { "name": "output_exception", "long_name": "output_exception( )", "filename": "testing.py", "nloc": 9, "complexity": 2, "token_count": 67, "parameters": [], "start_line": 741, "end_line": 751, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 11, "top_nesting_level": 0 } ], "changed_methods": [], "nloc": 579, "complexity": 143, "token_count": 4117, "diff_parsed": { "added": [ "\"\"\"", "Unit-testing", "------------", "", " ScipyTest - Scipy tests site manager", " ScipyTestCase - unittest.TestCase with measure method", " set_package_path - use it before importing a module to be tested", " restore_path - restore path after set_package_path", "", "Timing tools", "------------", "", " jiffies - return 1/100ths of a second that the current process has used", " memusage - virtual memory size in bytes of the running python [linux]", "", "Utility functions", "-----------------", "", " assert_equal", " assert_almost_equal", " assert_approx_equal", " assert_array_equal", " assert_array_almost_equal", " assert_array_less", " rand - array of random numbers from given shape", "", "\"\"\"" ], "deleted": [] } } ] }, { "hash": "ed2479c295044698c3e6fdc2b359aef67f49dd93", "msg": "ENH: Updated to support recent versions of SWIG in addition to the older\nversions. The SWIG runtime layout has changed recently (1.3.23). The\nchanges allow one to use both the older versions and the latest versions.", "author": { "name": "prabhu", "email": "prabhu@localhost" }, "committer": { "name": "prabhu", "email": "prabhu@localhost" }, "author_date": "2004-11-22T09:42:56+00:00", "author_timezone": 0, "committer_date": "2004-11-22T09:42:56+00:00", "committer_timezone": 0, "branches": [ "main" ], "in_main_branch": true, "merge": false, "parents": [ "bc2f8ecedb5d8a9ced56990d2add37db10c9a7d2" ], "project_name": "repo_copy", "project_path": "/tmp/tmpqop781_j/repo_copy", "deletions": 52, "insertions": 1394, "lines": 1446, "files": 2, "dmm_unit_size": 0.0, "dmm_unit_complexity": 0.0, "dmm_unit_interfacing": 0.8444444444444444, "modified_files": [ { "old_path": "weave/swig2_spec.py", "new_path": "weave/swig2_spec.py", "filename": "swig2_spec.py", "extension": "py", "change_type": "MODIFY", "diff": "@@ -7,41 +7,99 @@\n code that uses SWIG the user simply needs to override the defaults in\n the swig2_converter class. These special circumstances arise when one\n has wrapped code that uses C++ namespaces. However, for most\n-straightforward SWIG wrappers this converter should fine out of the\n-box.\n+straightforward SWIG wrappers this converter should work fine out of\n+the box.\n \n-This code also has support to automatically handle SWIG wrapped\n-objects that use SWIG_COBJECT_TYPES. These use a PyCObject instead of\n-a string to store the opaque pointer.\n+Newer versions of SWIG (>=1.3.22) represent the wrapped object using a\n+PyCObject and also a PySwigObject (>=1.3.24). This code supports all\n+of these options transparently.\n \n-By default this code assumes that the user will not link with the SWIG\n-runtime library (libswigpy under *nix). In this case no type checking\n-will be performed by SWIG.\n+Since SWIG-1.3.x is under intense development there are several issues\n+to consider when using the swig2_converter.\n \n-To turn on type checking and link with the SWIG runtime library, there\n-are two approaches.\n+ 1. For SWIG versions <= 1.3.19, the runtime code was built either\n+ into the module or into a separate library called libswigpy (or\n+ something like that). In the latter case, the users Python\n+ modules were linked to this library and shared type information\n+ (this was common for large projects with several modules that\n+ needed to share type information). If you are using multiple\n+ inheritance and want to be certain that type coercions from a\n+ derived class to a base class are done correctly, you will need to\n+ link to the libswigpy library. You will then need to add these to\n+ the keyword arguments passed along to `weave.inline`:\n \n- 1. If you are writing a customized converter based on this code then\n- in the overloaded init_info, just call swig2_converter.init_info\n- with runtime=1 and add the swig runtime library to the libraries\n- loaded.\n+ a. Add a define_macros=[('SWIG_NOINCLUDE', None)]\n \n- 2. If you are using the default swig2_converter you need to add two\n- keyword arguments to your weave.inline call:\n+ b. Add the swigpy library to the libraries like so:\n+ libraries=['swigpy']\n \n- a. Add a define_macros=[('SWIG_NOINCLUDE', None)]\n+ c. If the libswigpy is in a non-standard location add the path\n+ to the library_dirs argument as\n+ `library_dirs=['/usr/local/lib']` or whatever.\n \n- b. Add the swigpy library to the libraries like so:\n- libraries=['swigpy']\n+ OTOH if you do not need to link to libswigpy (this is likely if\n+ you are not using multiple inheritance), then you do not need the\n+ above. However you are likely to get an annoying message of the\n+ form::\n \n-Prabhu Ramachandran \n+ WARNING: swig_type_info is NULL.\n+\n+ for each SWIG object you are inlining (during each call). To\n+ avoid this add a define_macros=[('NO_SWIG_WARN', None)].\n+\n+ 2. Since keeping track of a separate runtime is a pain, for SWIG\n+ versions >= 1.3.23 the type information was stored inside a\n+ special module. Thus in these versions there is no need to link\n+ to this special SWIG runtime library. This module handles these\n+ cases automatically and nothing special need be done.\n+\n+ Using modules wrapped with different SWIG versions simultaneously.\n+ Lets say you have library 'A' that is wrapped using SWIG version\n+ 1.3.20. Then lets say you have a library 'B' wrapped using\n+ version 1.3.24. Now if you want to use both in weave.inline, we\n+ have a serious problem. The trouble is that both 'A' and 'B' may\n+ use different and incompatible runtime layouts. It is impossible\n+ to get the type conversions right in these cases. Thus it is\n+ strongly advised that you use one version of SWIG to wrap all of\n+ the code that you intend to inline using weave. Note that you can\n+ certainly use SWIG-1.3.23 for everything and do not have to use\n+ the latest and greatest SWIG to use weave.inline. Just make sure\n+ that when inlining SWIG wrapped objects that all such objects use\n+ the same runtime layout. By default, if you are using different\n+ versions and do need to inline these objects, the latest layout\n+ will be assumed. This might leave you with holes in your feet,\n+ but you have been warned. You can force the converter to use a\n+ specific runtime version if you want (see the\n+ `swig2_converter.__init__` method and its documentation).\n+\n+\n+Prabhu Ramachandran \n \"\"\"\n \n+import sys\n import common_info\n from c_spec import common_base_converter\n import converters\n import swigptr2\n \n+\n+#----------------------------------------------------------------------\n+# Commonly used functions for the type query. This is done mainly to\n+# avoid code duplication.\n+#----------------------------------------------------------------------\n+swig2_common_code = \\\n+'''\n+swig_type_info *\n+Weave_SWIG_TypeQuery(const char *name) {\n+ swig_type_info *ty = SWIG_TypeQuery(name);\n+#ifndef NO_SWIG_WARN\n+ if (ty == NULL) {\n+ printf(\"WARNING: swig_type_info is NULL.\\\\n\");\n+ }\n+#endif\n+ return ty;\n+}\n+'''\n #----------------------------------------------------------------------\n # This code obtains the C++ pointer given a a SWIG2 wrapped C++ object\n # in Python.\n@@ -55,7 +113,7 @@ class %(type_name)s_handler\n %(c_type)s convert_to_%(type_name)s(PyObject* py_obj, const char* name)\n {\n %(c_type)s c_ptr;\n- swig_type_info *ty = SWIG_TypeQuery(\"%(c_type)s\");\n+ swig_type_info *ty = Weave_SWIG_TypeQuery(\"%(c_type)s\");\n // work on this error reporting...\n if (SWIG_ConvertPtr(py_obj, (void **) &c_ptr, ty,\n SWIG_POINTER_EXCEPTION | 0) == -1) {\n@@ -68,7 +126,7 @@ class %(type_name)s_handler\n %(c_type)s py_to_%(type_name)s(PyObject* py_obj,const char* name)\n {\n %(c_type)s c_ptr;\n- swig_type_info *ty = SWIG_TypeQuery(\"%(c_type)s\");\n+ swig_type_info *ty = Weave_SWIG_TypeQuery(\"%(c_type)s\");\n // work on this error reporting...\n if (SWIG_ConvertPtr(py_obj, (void **) &c_ptr, ty,\n SWIG_POINTER_EXCEPTION | 0) == -1) {\n@@ -97,31 +155,85 @@ class %(type_name)s_handler\n swig2_c_to_py_template = \"\"\"\n PyObject* %(type_name)s_to_py(void *obj)\n {\n- swig_type_info *ty = SWIG_TypeQuery(\"%(c_type)s\");\n+ swig_type_info *ty = Weave_SWIG_TypeQuery(\"%(c_type)s\");\n return SWIG_NewPointerObj(obj, ty, 0);\n }\n \"\"\"\n \n class swig2_converter(common_base_converter):\n \"\"\" A converter for SWIG >= 1.3 wrapped objects.\"\"\"\n- def __init__(self, class_name=\"undefined\", pycobj=0):\n- \"\"\"If `pycobj` is True, then code is generated to deal with a\n- PyCObject.\n+ def __init__(self, class_name=\"undefined\", pycobj=0, runtime_version=None):\n+ \"\"\"Initializes the instance.\n+\n+ Parameters\n+ ----------\n+\n+ - class_name : `string`\n+\n+ Name of class, this is set dynamically at build time by the\n+ `type_spec` method.\n+\n+ - pycobj : `int`\n+\n+ If `pycobj` is 0 then code is generated to deal with string\n+ representations of the SWIG wrapped pointer. If it is 1,\n+ then code is generated to deal with a PyCObject. If it is 2\n+ then code is generated to deal with with PySwigObject.\n+\n+ - runtime_version : `int`\n+\n+ Specifies the SWIG_RUNTIME_VERSION to use. Defaults to\n+ `None`. In this case the runtime is automatically\n+ determined. This option is useful if you want to force the\n+ runtime_version to be a specific one and override the\n+ auto-detected one.\n \n \"\"\"\n self.class_name = class_name\n self.pycobj = pycobj # This is on if a PyCObject has been used.\n+ self.runtime_version = runtime_version\n common_base_converter.__init__(self)\n \n+ def _get_swig_runtime_version(self):\n+ \"\"\"This method tries to deduce the SWIG runtime version. If\n+ the SWIG runtime layout changes, the `SWIG_TypeQuery` function\n+ will not work properly.\n+ \"\"\"\n+ versions = []\n+ for key in sys.modules.keys():\n+ idx = key.find('swig_runtime_data')\n+ if idx > -1:\n+ ver = int(key[idx+17:])\n+ if ver not in versions:\n+ versions.append(ver)\n+ nver = len(versions)\n+ if nver == 0:\n+ return 0\n+ elif nver == 1:\n+ return versions[0]\n+ else:\n+ print \"WARNING: Multiple SWIG versions detected. No version was\"\n+ print \"explicitly specified. Using the highest possible version.\"\n+ return max(versions)\n+\n def init_info(self, runtime=0):\n \"\"\"Keyword arguments:\n \n runtime -- If false (default), the user does not need to\n- link to the swig runtime (libswipy). In this case no SWIG\n- type checking is performed. If true, the user must link to\n- the swipy runtime library and in this case type checking\n- will be performed. This option is useful when you derive a\n- subclass of this one for your object converters. \n+ link to the swig runtime (libswipy). Newer versions of SWIG\n+ (>=1.3.23) do not need to build a SWIG runtime library at\n+ all. In these versions of SWIG the swig_type_info is stored\n+ in a common module. swig_type_info stores the type\n+ information and the type converters to cast pointers\n+ correctly.\n+\n+ With earlier versions of SWIG (<1.3.22) one has to either\n+ link the weave module with a SWIG runtime library\n+ (libswigpy) in order to get the swig_type_info. Thus, if\n+ `runtime` is True, the user must link to the swipy runtime\n+ library and in this case type checking will be performed.\n+ With these versions of SWIG, if runtime is `False`, no type\n+ checking is done.\n \n \"\"\"\n common_base_converter.init_info(self)\n@@ -133,32 +245,68 @@ def init_info(self, runtime=0):\n self.to_c_return = None # not used\n self.check_func = None # not used\n \n- if self.pycobj:\n+ if self.pycobj == 1:\n self.define_macros.append((\"SWIG_COBJECT_TYPES\", None))\n+ self.define_macros.append((\"SWIG_COBJECT_PYTHON\", None))\n+ elif self.pycobj == 2:\n+ self.define_macros.append((\"SWIG_COBJECT_TYPES\", None))\n+ \n+ \n+ if self.runtime_version is None:\n+ self.runtime_version = self._get_swig_runtime_version()\n \n- if runtime:\n- self.define_macros.append((\"SWIG_NOINCLUDE\", None))\n- self.support_code.append(swigptr2.swigptr2_code)\n- \n- def type_match(self,value):\n- \"\"\" This is a generic type matcher for SWIG-1.3 objects. For\n- specific instances, override this method. The method also\n- handles cases where SWIG uses a PyCObject for the `this`\n- attribute and not a string.\n+ rv = self.runtime_version\n+ if rv == 0:\n+ # The runtime option is only useful for older versions of\n+ # SWIG.\n+ if runtime:\n+ self.define_macros.append((\"SWIG_NOINCLUDE\", None))\n+ self.support_code.append(swigptr2.swigptr2_code_v0)\n+ elif rv == 1:\n+ self.support_code.append(swigptr2.swigptr2_code_v1)\n+ else:\n+ raise AssertionError, \"Unsupported version of the SWIG runtime:\", rv\n \n+ self.support_code.append(swig2_common_code)\n+\n+ def _get_swig_type(self, value):\n+ \"\"\"Given the object in the form of `value`, this method\n+ returns information on the SWIG internal object repesentation\n+ type. Different versions of SWIG use different object\n+ representations. This method provides information on the type\n+ of internal representation.\n+\n+ Currently returns one of ['', 'str', 'pycobj', 'pyswig'].\n \"\"\"\n- is_match = 0\n+ swig_typ = ''\n if hasattr(value, 'this'):\n- if type(value.this) == type('str'):\n+ type_this = type(value.this)\n+ type_str = str(type_this)\n+ if type_this == type('str'):\n try:\n data = value.this.split('_')\n if data[2] == 'p':\n- is_match = 1\n+ swig_typ = 'str'\n except AttributeError:\n pass\n- elif str(type(value.this)) == \"\":\n- is_match = 1\n- return is_match\n+ elif type_str == \"\":\n+ swig_typ = 'pycobj'\n+ elif type_str.find('PySwig') > -1:\n+ swig_typ = 'pyswig'\n+\n+ return swig_typ \n+ \n+ def type_match(self,value):\n+ \"\"\" This is a generic type matcher for SWIG-1.3 objects. For\n+ specific instances, override this method. The method also\n+ handles cases where SWIG uses a PyCObject for the `this`\n+ attribute and not a string.\n+\n+ \"\"\"\n+ if self._get_swig_type(value):\n+ return 1\n+ else:\n+ return 0\n \n def generate_build_info(self):\n if self.class_name != \"undefined\":\n@@ -181,15 +329,23 @@ def type_spec(self,name,value):\n objects. For specific instances, override this function if\n necessary.\"\"\"\n # factory\n+ swig_ob_type = self._get_swig_type(value)\n pycobj = 0\n- if type(value.this) == type('str'):\n+ if swig_ob_type == 'str':\n class_name = value.this.split('_')[-1]\n- else: # PyCObject case\n+ elif swig_ob_type == 'pycobj':\n+ pycobj = 1\n+ elif swig_ob_type == 'pyswig':\n+ pycobj = 2\n+ else:\n+ raise AssertionError, \"Does not look like a SWIG object: %s\"%value\n+\n+ if pycobj:\n class_name = value.__class__.__name__\n if class_name[-3:] == 'Ptr':\n class_name = class_name[:-3]\n- pycobj = 1\n- new_spec = self.__class__(class_name, pycobj)\n+ \n+ new_spec = self.__class__(class_name, pycobj, self.runtime_version)\n new_spec.name = name\n return new_spec\n \n", "added_lines": 207, "deleted_lines": 51, "source_code": "\"\"\"\nThis module allows one to use SWIG2 (SWIG version >= 1.3) wrapped\nobjects from Weave. SWIG-1.3 wraps objects differently from SWIG-1.1.\n\nThe code here is based on wx_spec.py. However, this module is more\nlike a template for any SWIG2 wrapped converter. To wrap any special\ncode that uses SWIG the user simply needs to override the defaults in\nthe swig2_converter class. These special circumstances arise when one\nhas wrapped code that uses C++ namespaces. However, for most\nstraightforward SWIG wrappers this converter should work fine out of\nthe box.\n\nNewer versions of SWIG (>=1.3.22) represent the wrapped object using a\nPyCObject and also a PySwigObject (>=1.3.24). This code supports all\nof these options transparently.\n\nSince SWIG-1.3.x is under intense development there are several issues\nto consider when using the swig2_converter.\n\n 1. For SWIG versions <= 1.3.19, the runtime code was built either\n into the module or into a separate library called libswigpy (or\n something like that). In the latter case, the users Python\n modules were linked to this library and shared type information\n (this was common for large projects with several modules that\n needed to share type information). If you are using multiple\n inheritance and want to be certain that type coercions from a\n derived class to a base class are done correctly, you will need to\n link to the libswigpy library. You will then need to add these to\n the keyword arguments passed along to `weave.inline`:\n\n a. Add a define_macros=[('SWIG_NOINCLUDE', None)]\n\n b. Add the swigpy library to the libraries like so:\n libraries=['swigpy']\n\n c. If the libswigpy is in a non-standard location add the path\n to the library_dirs argument as\n `library_dirs=['/usr/local/lib']` or whatever.\n\n OTOH if you do not need to link to libswigpy (this is likely if\n you are not using multiple inheritance), then you do not need the\n above. However you are likely to get an annoying message of the\n form::\n\n WARNING: swig_type_info is NULL.\n\n for each SWIG object you are inlining (during each call). To\n avoid this add a define_macros=[('NO_SWIG_WARN', None)].\n\n 2. Since keeping track of a separate runtime is a pain, for SWIG\n versions >= 1.3.23 the type information was stored inside a\n special module. Thus in these versions there is no need to link\n to this special SWIG runtime library. This module handles these\n cases automatically and nothing special need be done.\n\n Using modules wrapped with different SWIG versions simultaneously.\n Lets say you have library 'A' that is wrapped using SWIG version\n 1.3.20. Then lets say you have a library 'B' wrapped using\n version 1.3.24. Now if you want to use both in weave.inline, we\n have a serious problem. The trouble is that both 'A' and 'B' may\n use different and incompatible runtime layouts. It is impossible\n to get the type conversions right in these cases. Thus it is\n strongly advised that you use one version of SWIG to wrap all of\n the code that you intend to inline using weave. Note that you can\n certainly use SWIG-1.3.23 for everything and do not have to use\n the latest and greatest SWIG to use weave.inline. Just make sure\n that when inlining SWIG wrapped objects that all such objects use\n the same runtime layout. By default, if you are using different\n versions and do need to inline these objects, the latest layout\n will be assumed. This might leave you with holes in your feet,\n but you have been warned. You can force the converter to use a\n specific runtime version if you want (see the\n `swig2_converter.__init__` method and its documentation).\n\n\nPrabhu Ramachandran \n\"\"\"\n\nimport sys\nimport common_info\nfrom c_spec import common_base_converter\nimport converters\nimport swigptr2\n\n\n#----------------------------------------------------------------------\n# Commonly used functions for the type query. This is done mainly to\n# avoid code duplication.\n#----------------------------------------------------------------------\nswig2_common_code = \\\n'''\nswig_type_info *\nWeave_SWIG_TypeQuery(const char *name) {\n swig_type_info *ty = SWIG_TypeQuery(name);\n#ifndef NO_SWIG_WARN\n if (ty == NULL) {\n printf(\"WARNING: swig_type_info is NULL.\\\\n\");\n }\n#endif\n return ty;\n}\n'''\n#----------------------------------------------------------------------\n# This code obtains the C++ pointer given a a SWIG2 wrapped C++ object\n# in Python.\n#----------------------------------------------------------------------\n\nswig2_py_to_c_template = \\\n\"\"\"\nclass %(type_name)s_handler\n{\npublic: \n %(c_type)s convert_to_%(type_name)s(PyObject* py_obj, const char* name)\n {\n %(c_type)s c_ptr;\n swig_type_info *ty = Weave_SWIG_TypeQuery(\"%(c_type)s\");\n // work on this error reporting...\n if (SWIG_ConvertPtr(py_obj, (void **) &c_ptr, ty,\n SWIG_POINTER_EXCEPTION | 0) == -1) {\n handle_conversion_error(py_obj,\"%(type_name)s\", name);\n }\n %(inc_ref_count)s\n return c_ptr;\n }\n \n %(c_type)s py_to_%(type_name)s(PyObject* py_obj,const char* name)\n {\n %(c_type)s c_ptr;\n swig_type_info *ty = Weave_SWIG_TypeQuery(\"%(c_type)s\");\n // work on this error reporting...\n if (SWIG_ConvertPtr(py_obj, (void **) &c_ptr, ty,\n SWIG_POINTER_EXCEPTION | 0) == -1) {\n handle_bad_type(py_obj,\"%(type_name)s\", name);\n }\n %(inc_ref_count)s\n return c_ptr;\n }\n};\n\n%(type_name)s_handler x__%(type_name)s_handler = %(type_name)s_handler();\n#define convert_to_%(type_name)s(py_obj,name) \\\\\n x__%(type_name)s_handler.convert_to_%(type_name)s(py_obj,name)\n#define py_to_%(type_name)s(py_obj,name) \\\\\n x__%(type_name)s_handler.py_to_%(type_name)s(py_obj,name)\n\n\"\"\"\n\n#----------------------------------------------------------------------\n# This code generates a new SWIG pointer object given a C++ pointer.\n#\n# Important note: The thisown flag of the returned object is set to 0\n# by default.\n#----------------------------------------------------------------------\n\nswig2_c_to_py_template = \"\"\"\nPyObject* %(type_name)s_to_py(void *obj)\n{\n swig_type_info *ty = Weave_SWIG_TypeQuery(\"%(c_type)s\");\n return SWIG_NewPointerObj(obj, ty, 0);\n}\n\"\"\"\n\nclass swig2_converter(common_base_converter):\n \"\"\" A converter for SWIG >= 1.3 wrapped objects.\"\"\"\n def __init__(self, class_name=\"undefined\", pycobj=0, runtime_version=None):\n \"\"\"Initializes the instance.\n\n Parameters\n ----------\n\n - class_name : `string`\n\n Name of class, this is set dynamically at build time by the\n `type_spec` method.\n\n - pycobj : `int`\n\n If `pycobj` is 0 then code is generated to deal with string\n representations of the SWIG wrapped pointer. If it is 1,\n then code is generated to deal with a PyCObject. If it is 2\n then code is generated to deal with with PySwigObject.\n\n - runtime_version : `int`\n\n Specifies the SWIG_RUNTIME_VERSION to use. Defaults to\n `None`. In this case the runtime is automatically\n determined. This option is useful if you want to force the\n runtime_version to be a specific one and override the\n auto-detected one.\n\n \"\"\"\n self.class_name = class_name\n self.pycobj = pycobj # This is on if a PyCObject has been used.\n self.runtime_version = runtime_version\n common_base_converter.__init__(self)\n\n def _get_swig_runtime_version(self):\n \"\"\"This method tries to deduce the SWIG runtime version. If\n the SWIG runtime layout changes, the `SWIG_TypeQuery` function\n will not work properly.\n \"\"\"\n versions = []\n for key in sys.modules.keys():\n idx = key.find('swig_runtime_data')\n if idx > -1:\n ver = int(key[idx+17:])\n if ver not in versions:\n versions.append(ver)\n nver = len(versions)\n if nver == 0:\n return 0\n elif nver == 1:\n return versions[0]\n else:\n print \"WARNING: Multiple SWIG versions detected. No version was\"\n print \"explicitly specified. Using the highest possible version.\"\n return max(versions)\n\n def init_info(self, runtime=0):\n \"\"\"Keyword arguments:\n \n runtime -- If false (default), the user does not need to\n link to the swig runtime (libswipy). Newer versions of SWIG\n (>=1.3.23) do not need to build a SWIG runtime library at\n all. In these versions of SWIG the swig_type_info is stored\n in a common module. swig_type_info stores the type\n information and the type converters to cast pointers\n correctly.\n\n With earlier versions of SWIG (<1.3.22) one has to either\n link the weave module with a SWIG runtime library\n (libswigpy) in order to get the swig_type_info. Thus, if\n `runtime` is True, the user must link to the swipy runtime\n library and in this case type checking will be performed.\n With these versions of SWIG, if runtime is `False`, no type\n checking is done.\n\n \"\"\"\n common_base_converter.init_info(self)\n # These are generated on the fly instead of defined at \n # the class level.\n self.type_name = self.class_name\n self.c_type = self.class_name + \"*\"\n self.return_type = self.class_name + \"*\"\n self.to_c_return = None # not used\n self.check_func = None # not used\n\n if self.pycobj == 1:\n self.define_macros.append((\"SWIG_COBJECT_TYPES\", None))\n self.define_macros.append((\"SWIG_COBJECT_PYTHON\", None))\n elif self.pycobj == 2:\n self.define_macros.append((\"SWIG_COBJECT_TYPES\", None))\n \n \n if self.runtime_version is None:\n self.runtime_version = self._get_swig_runtime_version()\n\n rv = self.runtime_version\n if rv == 0:\n # The runtime option is only useful for older versions of\n # SWIG.\n if runtime:\n self.define_macros.append((\"SWIG_NOINCLUDE\", None))\n self.support_code.append(swigptr2.swigptr2_code_v0)\n elif rv == 1:\n self.support_code.append(swigptr2.swigptr2_code_v1)\n else:\n raise AssertionError, \"Unsupported version of the SWIG runtime:\", rv\n\n self.support_code.append(swig2_common_code)\n\n def _get_swig_type(self, value):\n \"\"\"Given the object in the form of `value`, this method\n returns information on the SWIG internal object repesentation\n type. Different versions of SWIG use different object\n representations. This method provides information on the type\n of internal representation.\n\n Currently returns one of ['', 'str', 'pycobj', 'pyswig'].\n \"\"\"\n swig_typ = ''\n if hasattr(value, 'this'):\n type_this = type(value.this)\n type_str = str(type_this)\n if type_this == type('str'):\n try:\n data = value.this.split('_')\n if data[2] == 'p':\n swig_typ = 'str'\n except AttributeError:\n pass\n elif type_str == \"\":\n swig_typ = 'pycobj'\n elif type_str.find('PySwig') > -1:\n swig_typ = 'pyswig'\n\n return swig_typ \n \n def type_match(self,value):\n \"\"\" This is a generic type matcher for SWIG-1.3 objects. For\n specific instances, override this method. The method also\n handles cases where SWIG uses a PyCObject for the `this`\n attribute and not a string.\n\n \"\"\"\n if self._get_swig_type(value):\n return 1\n else:\n return 0\n\n def generate_build_info(self):\n if self.class_name != \"undefined\":\n res = common_base_converter.generate_build_info(self)\n else:\n # if there isn't a class_name, we don't want the\n # support_code to be included\n import base_info\n res = base_info.base_info()\n return res\n \n def py_to_c_code(self):\n return swig2_py_to_c_template % self.template_vars()\n\n def c_to_py_code(self):\n return swig2_c_to_py_template % self.template_vars()\n \n def type_spec(self,name,value):\n \"\"\" This returns a generic type converter for SWIG-1.3\n objects. For specific instances, override this function if\n necessary.\"\"\"\n # factory\n swig_ob_type = self._get_swig_type(value)\n pycobj = 0\n if swig_ob_type == 'str':\n class_name = value.this.split('_')[-1]\n elif swig_ob_type == 'pycobj':\n pycobj = 1\n elif swig_ob_type == 'pyswig':\n pycobj = 2\n else:\n raise AssertionError, \"Does not look like a SWIG object: %s\"%value\n\n if pycobj:\n class_name = value.__class__.__name__\n if class_name[-3:] == 'Ptr':\n class_name = class_name[:-3]\n \n new_spec = self.__class__(class_name, pycobj, self.runtime_version)\n new_spec.name = name\n return new_spec\n\n def __cmp__(self,other):\n #only works for equal\n res = -1\n try:\n res = cmp(self.name,other.name) or \\\n cmp(self.__class__, other.__class__) or \\\n cmp(self.class_name, other.class_name) or \\\n cmp(self.type_name,other.type_name)\n except:\n pass\n return res\n\n#----------------------------------------------------------------------\n# Uncomment the next line if you want this to be a default converter\n# that is magically invoked by inline.\n#----------------------------------------------------------------------\n#converters.default.insert(0, swig2_converter())\n", "source_code_before": "\"\"\"\nThis module allows one to use SWIG2 (SWIG version >= 1.3) wrapped\nobjects from Weave. SWIG-1.3 wraps objects differently from SWIG-1.1.\n\nThe code here is based on wx_spec.py. However, this module is more\nlike a template for any SWIG2 wrapped converter. To wrap any special\ncode that uses SWIG the user simply needs to override the defaults in\nthe swig2_converter class. These special circumstances arise when one\nhas wrapped code that uses C++ namespaces. However, for most\nstraightforward SWIG wrappers this converter should fine out of the\nbox.\n\nThis code also has support to automatically handle SWIG wrapped\nobjects that use SWIG_COBJECT_TYPES. These use a PyCObject instead of\na string to store the opaque pointer.\n\nBy default this code assumes that the user will not link with the SWIG\nruntime library (libswigpy under *nix). In this case no type checking\nwill be performed by SWIG.\n\nTo turn on type checking and link with the SWIG runtime library, there\nare two approaches.\n\n 1. If you are writing a customized converter based on this code then\n in the overloaded init_info, just call swig2_converter.init_info\n with runtime=1 and add the swig runtime library to the libraries\n loaded.\n\n 2. If you are using the default swig2_converter you need to add two\n keyword arguments to your weave.inline call:\n\n a. Add a define_macros=[('SWIG_NOINCLUDE', None)]\n\n b. Add the swigpy library to the libraries like so:\n libraries=['swigpy']\n\nPrabhu Ramachandran \n\"\"\"\n\nimport common_info\nfrom c_spec import common_base_converter\nimport converters\nimport swigptr2\n\n#----------------------------------------------------------------------\n# This code obtains the C++ pointer given a a SWIG2 wrapped C++ object\n# in Python.\n#----------------------------------------------------------------------\n\nswig2_py_to_c_template = \\\n\"\"\"\nclass %(type_name)s_handler\n{\npublic: \n %(c_type)s convert_to_%(type_name)s(PyObject* py_obj, const char* name)\n {\n %(c_type)s c_ptr;\n swig_type_info *ty = SWIG_TypeQuery(\"%(c_type)s\");\n // work on this error reporting...\n if (SWIG_ConvertPtr(py_obj, (void **) &c_ptr, ty,\n SWIG_POINTER_EXCEPTION | 0) == -1) {\n handle_conversion_error(py_obj,\"%(type_name)s\", name);\n }\n %(inc_ref_count)s\n return c_ptr;\n }\n \n %(c_type)s py_to_%(type_name)s(PyObject* py_obj,const char* name)\n {\n %(c_type)s c_ptr;\n swig_type_info *ty = SWIG_TypeQuery(\"%(c_type)s\");\n // work on this error reporting...\n if (SWIG_ConvertPtr(py_obj, (void **) &c_ptr, ty,\n SWIG_POINTER_EXCEPTION | 0) == -1) {\n handle_bad_type(py_obj,\"%(type_name)s\", name);\n }\n %(inc_ref_count)s\n return c_ptr;\n }\n};\n\n%(type_name)s_handler x__%(type_name)s_handler = %(type_name)s_handler();\n#define convert_to_%(type_name)s(py_obj,name) \\\\\n x__%(type_name)s_handler.convert_to_%(type_name)s(py_obj,name)\n#define py_to_%(type_name)s(py_obj,name) \\\\\n x__%(type_name)s_handler.py_to_%(type_name)s(py_obj,name)\n\n\"\"\"\n\n#----------------------------------------------------------------------\n# This code generates a new SWIG pointer object given a C++ pointer.\n#\n# Important note: The thisown flag of the returned object is set to 0\n# by default.\n#----------------------------------------------------------------------\n\nswig2_c_to_py_template = \"\"\"\nPyObject* %(type_name)s_to_py(void *obj)\n{\n swig_type_info *ty = SWIG_TypeQuery(\"%(c_type)s\");\n return SWIG_NewPointerObj(obj, ty, 0);\n}\n\"\"\"\n\nclass swig2_converter(common_base_converter):\n \"\"\" A converter for SWIG >= 1.3 wrapped objects.\"\"\"\n def __init__(self, class_name=\"undefined\", pycobj=0):\n \"\"\"If `pycobj` is True, then code is generated to deal with a\n PyCObject.\n\n \"\"\"\n self.class_name = class_name\n self.pycobj = pycobj # This is on if a PyCObject has been used.\n common_base_converter.__init__(self)\n\n def init_info(self, runtime=0):\n \"\"\"Keyword arguments:\n \n runtime -- If false (default), the user does not need to\n link to the swig runtime (libswipy). In this case no SWIG\n type checking is performed. If true, the user must link to\n the swipy runtime library and in this case type checking\n will be performed. This option is useful when you derive a\n subclass of this one for your object converters. \n\n \"\"\"\n common_base_converter.init_info(self)\n # These are generated on the fly instead of defined at \n # the class level.\n self.type_name = self.class_name\n self.c_type = self.class_name + \"*\"\n self.return_type = self.class_name + \"*\"\n self.to_c_return = None # not used\n self.check_func = None # not used\n\n if self.pycobj:\n self.define_macros.append((\"SWIG_COBJECT_TYPES\", None))\n\n if runtime:\n self.define_macros.append((\"SWIG_NOINCLUDE\", None))\n self.support_code.append(swigptr2.swigptr2_code)\n \n def type_match(self,value):\n \"\"\" This is a generic type matcher for SWIG-1.3 objects. For\n specific instances, override this method. The method also\n handles cases where SWIG uses a PyCObject for the `this`\n attribute and not a string.\n\n \"\"\"\n is_match = 0\n if hasattr(value, 'this'):\n if type(value.this) == type('str'):\n try:\n data = value.this.split('_')\n if data[2] == 'p':\n is_match = 1\n except AttributeError:\n pass\n elif str(type(value.this)) == \"\":\n is_match = 1\n return is_match\n\n def generate_build_info(self):\n if self.class_name != \"undefined\":\n res = common_base_converter.generate_build_info(self)\n else:\n # if there isn't a class_name, we don't want the\n # support_code to be included\n import base_info\n res = base_info.base_info()\n return res\n \n def py_to_c_code(self):\n return swig2_py_to_c_template % self.template_vars()\n\n def c_to_py_code(self):\n return swig2_c_to_py_template % self.template_vars()\n \n def type_spec(self,name,value):\n \"\"\" This returns a generic type converter for SWIG-1.3\n objects. For specific instances, override this function if\n necessary.\"\"\"\n # factory\n pycobj = 0\n if type(value.this) == type('str'):\n class_name = value.this.split('_')[-1]\n else: # PyCObject case\n class_name = value.__class__.__name__\n if class_name[-3:] == 'Ptr':\n class_name = class_name[:-3]\n pycobj = 1\n new_spec = self.__class__(class_name, pycobj)\n new_spec.name = name\n return new_spec\n\n def __cmp__(self,other):\n #only works for equal\n res = -1\n try:\n res = cmp(self.name,other.name) or \\\n cmp(self.__class__, other.__class__) or \\\n cmp(self.class_name, other.class_name) or \\\n cmp(self.type_name,other.type_name)\n except:\n pass\n return res\n\n#----------------------------------------------------------------------\n# Uncomment the next line if you want this to be a default converter\n# that is magically invoked by inline.\n#----------------------------------------------------------------------\n#converters.default.insert(0, swig2_converter())\n", "methods": [ { "name": "__init__", "long_name": "__init__( self , class_name = \"undefined\" , pycobj = 0 , runtime_version = None )", "filename": "swig2_spec.py", "nloc": 5, "complexity": 1, "token_count": 39, "parameters": [ "self", "class_name", "pycobj", "runtime_version" ], "start_line": 165, "end_line": 195, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 31, "top_nesting_level": 1 }, { "name": "_get_swig_runtime_version", "long_name": "_get_swig_runtime_version( self )", "filename": "swig2_spec.py", "nloc": 17, "complexity": 6, "token_count": 93, "parameters": [ "self" ], "start_line": 197, "end_line": 217, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 21, "top_nesting_level": 1 }, { "name": "init_info", "long_name": "init_info( self , runtime = 0 )", "filename": "swig2_spec.py", "nloc": 24, "complexity": 7, "token_count": 183, "parameters": [ "self", "runtime" ], "start_line": 219, "end_line": 270, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 52, "top_nesting_level": 1 }, { "name": "_get_swig_type", "long_name": "_get_swig_type( self , value )", "filename": "swig2_spec.py", "nloc": 17, "complexity": 7, "token_count": 92, "parameters": [ "self", "value" ], "start_line": 272, "end_line": 297, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 26, "top_nesting_level": 1 }, { "name": "type_match", "long_name": "type_match( self , value )", "filename": "swig2_spec.py", "nloc": 5, "complexity": 2, "token_count": 22, "parameters": [ "self", "value" ], "start_line": 299, "end_line": 309, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 11, "top_nesting_level": 1 }, { "name": "generate_build_info", "long_name": "generate_build_info( self )", "filename": "swig2_spec.py", "nloc": 7, "complexity": 2, "token_count": 33, "parameters": [ "self" ], "start_line": 311, "end_line": 319, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 9, "top_nesting_level": 1 }, { "name": "py_to_c_code", "long_name": "py_to_c_code( self )", "filename": "swig2_spec.py", "nloc": 2, "complexity": 1, "token_count": 13, "parameters": [ "self" ], "start_line": 321, "end_line": 322, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 2, "top_nesting_level": 1 }, { "name": "c_to_py_code", "long_name": "c_to_py_code( self )", "filename": "swig2_spec.py", "nloc": 2, "complexity": 1, "token_count": 13, "parameters": [ "self" ], "start_line": 324, "end_line": 325, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 2, "top_nesting_level": 1 }, { "name": "type_spec", "long_name": "type_spec( self , name , value )", "filename": "swig2_spec.py", "nloc": 18, "complexity": 6, "token_count": 113, "parameters": [ "self", "name", "value" ], "start_line": 327, "end_line": 350, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 24, "top_nesting_level": 1 }, { "name": "__cmp__", "long_name": "__cmp__( self , other )", "filename": "swig2_spec.py", "nloc": 10, "complexity": 5, "token_count": 66, "parameters": [ "self", "other" ], "start_line": 352, "end_line": 362, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 11, "top_nesting_level": 1 } ], "methods_before": [ { "name": "__init__", "long_name": "__init__( self , class_name = \"undefined\" , pycobj = 0 )", "filename": "swig2_spec.py", "nloc": 4, "complexity": 1, "token_count": 30, "parameters": [ "self", "class_name", "pycobj" ], "start_line": 107, "end_line": 114, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 8, "top_nesting_level": 1 }, { "name": "init_info", "long_name": "init_info( self , runtime = 0 )", "filename": "swig2_spec.py", "nloc": 12, "complexity": 3, "token_count": 93, "parameters": [ "self", "runtime" ], "start_line": 116, "end_line": 141, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 26, "top_nesting_level": 1 }, { "name": "type_match", "long_name": "type_match( self , value )", "filename": "swig2_spec.py", "nloc": 13, "complexity": 6, "token_count": 77, "parameters": [ "self", "value" ], "start_line": 143, "end_line": 161, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 19, "top_nesting_level": 1 }, { "name": "generate_build_info", "long_name": "generate_build_info( self )", "filename": "swig2_spec.py", "nloc": 7, "complexity": 2, "token_count": 33, "parameters": [ "self" ], "start_line": 163, "end_line": 171, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 9, "top_nesting_level": 1 }, { "name": "py_to_c_code", "long_name": "py_to_c_code( self )", "filename": "swig2_spec.py", "nloc": 2, "complexity": 1, "token_count": 13, "parameters": [ "self" ], "start_line": 173, "end_line": 174, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 2, "top_nesting_level": 1 }, { "name": "c_to_py_code", "long_name": "c_to_py_code( self )", "filename": "swig2_spec.py", "nloc": 2, "complexity": 1, "token_count": 13, "parameters": [ "self" ], "start_line": 176, "end_line": 177, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 2, "top_nesting_level": 1 }, { "name": "type_spec", "long_name": "type_spec( self , name , value )", "filename": "swig2_spec.py", "nloc": 12, "complexity": 3, "token_count": 87, "parameters": [ "self", "name", "value" ], "start_line": 179, "end_line": 194, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 16, "top_nesting_level": 1 }, { "name": "__cmp__", "long_name": "__cmp__( self , other )", "filename": "swig2_spec.py", "nloc": 10, "complexity": 5, "token_count": 66, "parameters": [ "self", "other" ], "start_line": 196, "end_line": 206, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 11, "top_nesting_level": 1 } ], "changed_methods": [ { "name": "type_spec", "long_name": "type_spec( self , name , value )", "filename": "swig2_spec.py", "nloc": 18, "complexity": 6, "token_count": 113, "parameters": [ "self", "name", "value" ], "start_line": 327, "end_line": 350, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 24, "top_nesting_level": 1 }, { "name": "__init__", "long_name": "__init__( self , class_name = \"undefined\" , pycobj = 0 , runtime_version = None )", "filename": "swig2_spec.py", "nloc": 5, "complexity": 1, "token_count": 39, "parameters": [ "self", "class_name", "pycobj", "runtime_version" ], "start_line": 165, "end_line": 195, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 31, "top_nesting_level": 1 }, { "name": "type_match", "long_name": "type_match( self , value )", "filename": "swig2_spec.py", "nloc": 5, "complexity": 2, "token_count": 22, "parameters": [ "self", "value" ], "start_line": 299, "end_line": 309, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 11, "top_nesting_level": 1 }, { "name": "__init__", "long_name": "__init__( self , class_name = \"undefined\" , pycobj = 0 )", "filename": "swig2_spec.py", "nloc": 4, "complexity": 1, "token_count": 30, "parameters": [ "self", "class_name", "pycobj" ], "start_line": 107, "end_line": 114, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 8, "top_nesting_level": 1 }, { "name": "init_info", "long_name": "init_info( self , runtime = 0 )", "filename": "swig2_spec.py", "nloc": 24, "complexity": 7, "token_count": 183, "parameters": [ "self", "runtime" ], "start_line": 219, "end_line": 270, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 52, "top_nesting_level": 1 }, { "name": "_get_swig_runtime_version", "long_name": "_get_swig_runtime_version( self )", "filename": "swig2_spec.py", "nloc": 17, "complexity": 6, "token_count": 93, "parameters": [ "self" ], "start_line": 197, "end_line": 217, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 21, "top_nesting_level": 1 }, { "name": "_get_swig_type", "long_name": "_get_swig_type( self , value )", "filename": "swig2_spec.py", "nloc": 17, "complexity": 7, "token_count": 92, "parameters": [ "self", "value" ], "start_line": 272, "end_line": 297, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 26, "top_nesting_level": 1 } ], "nloc": 250, "complexity": 38, "token_count": 708, "diff_parsed": { "added": [ "straightforward SWIG wrappers this converter should work fine out of", "the box.", "Newer versions of SWIG (>=1.3.22) represent the wrapped object using a", "PyCObject and also a PySwigObject (>=1.3.24). This code supports all", "of these options transparently.", "Since SWIG-1.3.x is under intense development there are several issues", "to consider when using the swig2_converter.", " 1. For SWIG versions <= 1.3.19, the runtime code was built either", " into the module or into a separate library called libswigpy (or", " something like that). In the latter case, the users Python", " modules were linked to this library and shared type information", " (this was common for large projects with several modules that", " needed to share type information). If you are using multiple", " inheritance and want to be certain that type coercions from a", " derived class to a base class are done correctly, you will need to", " link to the libswigpy library. You will then need to add these to", " the keyword arguments passed along to `weave.inline`:", " a. Add a define_macros=[('SWIG_NOINCLUDE', None)]", " b. Add the swigpy library to the libraries like so:", " libraries=['swigpy']", " c. If the libswigpy is in a non-standard location add the path", " to the library_dirs argument as", " `library_dirs=['/usr/local/lib']` or whatever.", " OTOH if you do not need to link to libswigpy (this is likely if", " you are not using multiple inheritance), then you do not need the", " above. However you are likely to get an annoying message of the", " form::", " WARNING: swig_type_info is NULL.", "", " for each SWIG object you are inlining (during each call). To", " avoid this add a define_macros=[('NO_SWIG_WARN', None)].", "", " 2. Since keeping track of a separate runtime is a pain, for SWIG", " versions >= 1.3.23 the type information was stored inside a", " special module. Thus in these versions there is no need to link", " to this special SWIG runtime library. This module handles these", " cases automatically and nothing special need be done.", "", " Using modules wrapped with different SWIG versions simultaneously.", " Lets say you have library 'A' that is wrapped using SWIG version", " 1.3.20. Then lets say you have a library 'B' wrapped using", " version 1.3.24. Now if you want to use both in weave.inline, we", " have a serious problem. The trouble is that both 'A' and 'B' may", " use different and incompatible runtime layouts. It is impossible", " to get the type conversions right in these cases. Thus it is", " strongly advised that you use one version of SWIG to wrap all of", " the code that you intend to inline using weave. Note that you can", " certainly use SWIG-1.3.23 for everything and do not have to use", " the latest and greatest SWIG to use weave.inline. Just make sure", " that when inlining SWIG wrapped objects that all such objects use", " the same runtime layout. By default, if you are using different", " versions and do need to inline these objects, the latest layout", " will be assumed. This might leave you with holes in your feet,", " but you have been warned. You can force the converter to use a", " specific runtime version if you want (see the", " `swig2_converter.__init__` method and its documentation).", "", "", "Prabhu Ramachandran ", "import sys", "", "#----------------------------------------------------------------------", "# Commonly used functions for the type query. This is done mainly to", "# avoid code duplication.", "#----------------------------------------------------------------------", "swig2_common_code = \\", "'''", "swig_type_info *", "Weave_SWIG_TypeQuery(const char *name) {", " swig_type_info *ty = SWIG_TypeQuery(name);", "#ifndef NO_SWIG_WARN", " if (ty == NULL) {", " printf(\"WARNING: swig_type_info is NULL.\\\\n\");", " }", "#endif", " return ty;", "}", "'''", " swig_type_info *ty = Weave_SWIG_TypeQuery(\"%(c_type)s\");", " swig_type_info *ty = Weave_SWIG_TypeQuery(\"%(c_type)s\");", " swig_type_info *ty = Weave_SWIG_TypeQuery(\"%(c_type)s\");", " def __init__(self, class_name=\"undefined\", pycobj=0, runtime_version=None):", " \"\"\"Initializes the instance.", "", " Parameters", " ----------", "", " - class_name : `string`", "", " Name of class, this is set dynamically at build time by the", " `type_spec` method.", "", " - pycobj : `int`", "", " If `pycobj` is 0 then code is generated to deal with string", " representations of the SWIG wrapped pointer. If it is 1,", " then code is generated to deal with a PyCObject. If it is 2", " then code is generated to deal with with PySwigObject.", "", " - runtime_version : `int`", "", " Specifies the SWIG_RUNTIME_VERSION to use. Defaults to", " `None`. In this case the runtime is automatically", " determined. This option is useful if you want to force the", " runtime_version to be a specific one and override the", " auto-detected one.", " self.runtime_version = runtime_version", " def _get_swig_runtime_version(self):", " \"\"\"This method tries to deduce the SWIG runtime version. If", " the SWIG runtime layout changes, the `SWIG_TypeQuery` function", " will not work properly.", " \"\"\"", " versions = []", " for key in sys.modules.keys():", " idx = key.find('swig_runtime_data')", " if idx > -1:", " ver = int(key[idx+17:])", " if ver not in versions:", " versions.append(ver)", " nver = len(versions)", " if nver == 0:", " return 0", " elif nver == 1:", " return versions[0]", " else:", " print \"WARNING: Multiple SWIG versions detected. No version was\"", " print \"explicitly specified. Using the highest possible version.\"", " return max(versions)", "", " link to the swig runtime (libswipy). Newer versions of SWIG", " (>=1.3.23) do not need to build a SWIG runtime library at", " all. In these versions of SWIG the swig_type_info is stored", " in a common module. swig_type_info stores the type", " information and the type converters to cast pointers", " correctly.", "", " With earlier versions of SWIG (<1.3.22) one has to either", " link the weave module with a SWIG runtime library", " (libswigpy) in order to get the swig_type_info. Thus, if", " `runtime` is True, the user must link to the swipy runtime", " library and in this case type checking will be performed.", " With these versions of SWIG, if runtime is `False`, no type", " checking is done.", " if self.pycobj == 1:", " self.define_macros.append((\"SWIG_COBJECT_PYTHON\", None))", " elif self.pycobj == 2:", " self.define_macros.append((\"SWIG_COBJECT_TYPES\", None))", "", "", " if self.runtime_version is None:", " self.runtime_version = self._get_swig_runtime_version()", " rv = self.runtime_version", " if rv == 0:", " # The runtime option is only useful for older versions of", " # SWIG.", " if runtime:", " self.define_macros.append((\"SWIG_NOINCLUDE\", None))", " self.support_code.append(swigptr2.swigptr2_code_v0)", " elif rv == 1:", " self.support_code.append(swigptr2.swigptr2_code_v1)", " else:", " raise AssertionError, \"Unsupported version of the SWIG runtime:\", rv", " self.support_code.append(swig2_common_code)", "", " def _get_swig_type(self, value):", " \"\"\"Given the object in the form of `value`, this method", " returns information on the SWIG internal object repesentation", " type. Different versions of SWIG use different object", " representations. This method provides information on the type", " of internal representation.", "", " Currently returns one of ['', 'str', 'pycobj', 'pyswig'].", " swig_typ = ''", " type_this = type(value.this)", " type_str = str(type_this)", " if type_this == type('str'):", " swig_typ = 'str'", " elif type_str == \"\":", " swig_typ = 'pycobj'", " elif type_str.find('PySwig') > -1:", " swig_typ = 'pyswig'", "", " return swig_typ", "", " def type_match(self,value):", " \"\"\" This is a generic type matcher for SWIG-1.3 objects. For", " specific instances, override this method. The method also", " handles cases where SWIG uses a PyCObject for the `this`", " attribute and not a string.", "", " \"\"\"", " if self._get_swig_type(value):", " return 1", " else:", " return 0", " swig_ob_type = self._get_swig_type(value)", " if swig_ob_type == 'str':", " elif swig_ob_type == 'pycobj':", " pycobj = 1", " elif swig_ob_type == 'pyswig':", " pycobj = 2", " else:", " raise AssertionError, \"Does not look like a SWIG object: %s\"%value", "", " if pycobj:", "", " new_spec = self.__class__(class_name, pycobj, self.runtime_version)" ], "deleted": [ "straightforward SWIG wrappers this converter should fine out of the", "box.", "This code also has support to automatically handle SWIG wrapped", "objects that use SWIG_COBJECT_TYPES. These use a PyCObject instead of", "a string to store the opaque pointer.", "By default this code assumes that the user will not link with the SWIG", "runtime library (libswigpy under *nix). In this case no type checking", "will be performed by SWIG.", "To turn on type checking and link with the SWIG runtime library, there", "are two approaches.", " 1. If you are writing a customized converter based on this code then", " in the overloaded init_info, just call swig2_converter.init_info", " with runtime=1 and add the swig runtime library to the libraries", " loaded.", " 2. If you are using the default swig2_converter you need to add two", " keyword arguments to your weave.inline call:", " a. Add a define_macros=[('SWIG_NOINCLUDE', None)]", " b. Add the swigpy library to the libraries like so:", " libraries=['swigpy']", "Prabhu Ramachandran ", " swig_type_info *ty = SWIG_TypeQuery(\"%(c_type)s\");", " swig_type_info *ty = SWIG_TypeQuery(\"%(c_type)s\");", " swig_type_info *ty = SWIG_TypeQuery(\"%(c_type)s\");", " def __init__(self, class_name=\"undefined\", pycobj=0):", " \"\"\"If `pycobj` is True, then code is generated to deal with a", " PyCObject.", " link to the swig runtime (libswipy). In this case no SWIG", " type checking is performed. If true, the user must link to", " the swipy runtime library and in this case type checking", " will be performed. This option is useful when you derive a", " subclass of this one for your object converters.", " if self.pycobj:", " if runtime:", " self.define_macros.append((\"SWIG_NOINCLUDE\", None))", " self.support_code.append(swigptr2.swigptr2_code)", "", " def type_match(self,value):", " \"\"\" This is a generic type matcher for SWIG-1.3 objects. For", " specific instances, override this method. The method also", " handles cases where SWIG uses a PyCObject for the `this`", " attribute and not a string.", " is_match = 0", " if type(value.this) == type('str'):", " is_match = 1", " elif str(type(value.this)) == \"\":", " is_match = 1", " return is_match", " if type(value.this) == type('str'):", " else: # PyCObject case", " pycobj = 1", " new_spec = self.__class__(class_name, pycobj)" ] } }, { "old_path": "weave/swigptr2.py", "new_path": "weave/swigptr2.py", "filename": "swigptr2.py", "extension": "py", "change_type": "MODIFY", "diff": "@@ -5,7 +5,10 @@\n #\n # Prabhu Ramachandran \n \n-swigptr2_code = \"\"\"\n+######################################################################\n+# This is for SWIG-1.3.x where x < 22.\n+# Essentially, SWIG_RUNTIME_VERSION was not yet used.\n+swigptr2_code_v0 = \"\"\"\n \n #include \"Python.h\"\n \n@@ -439,3 +442,1186 @@\n #endif\n \n \"\"\"\n+\n+\n+######################################################################\n+# This is for SWIG-1.3.x where x >= 23.\n+# SWIG_RUNTIME_VERSION == \"1\"\n+\n+# All this does is to include (cut/paste): \n+# and \n+swigptr2_code_v1 = \"\"\"\n+/***********************************************************************\n+ * swigrun.swg\n+ *\n+ * This file contains generic CAPI SWIG runtime support for pointer\n+ * type checking.\n+ *\n+ ************************************************************************/\n+\n+/* This should only be incremented when either the layout of swig_type_info changes,\n+ or for whatever reason, the runtime changes incompatibly */\n+#define SWIG_RUNTIME_VERSION \"1\"\n+\n+/* define SWIG_TYPE_TABLE_NAME as \"SWIG_TYPE_TABLE\" */\n+#ifdef SWIG_TYPE_TABLE\n+#define SWIG_QUOTE_STRING(x) #x\n+#define SWIG_EXPAND_AND_QUOTE_STRING(x) SWIG_QUOTE_STRING(x)\n+#define SWIG_TYPE_TABLE_NAME SWIG_EXPAND_AND_QUOTE_STRING(SWIG_TYPE_TABLE)\n+#else\n+#define SWIG_TYPE_TABLE_NAME\n+#endif\n+\n+#include \n+\n+#ifndef SWIGINLINE\n+#if defined(__cplusplus) || (defined(__GNUC__) && !defined(__STRICT_ANSI__))\n+# define SWIGINLINE inline\n+#else\n+# define SWIGINLINE\n+#endif\n+#endif\n+\n+/*\n+ You can use the SWIGRUNTIME and SWIGRUNTIMEINLINE macros for\n+ creating a static or dynamic library from the swig runtime code.\n+ In 99.9% of the cases, swig just needs to declare them as 'static'.\n+ \n+ But only do this if is strictly necessary, ie, if you have problems\n+ with your compiler or so.\n+*/\n+#ifndef SWIGRUNTIME\n+#define SWIGRUNTIME static\n+#endif\n+#ifndef SWIGRUNTIMEINLINE\n+#define SWIGRUNTIMEINLINE SWIGRUNTIME SWIGINLINE\n+#endif\n+\n+#ifdef __cplusplus\n+extern \"C\" {\n+#endif\n+\n+typedef void *(*swig_converter_func)(void *);\n+typedef struct swig_type_info *(*swig_dycast_func)(void **);\n+\n+typedef struct swig_type_info {\n+ const char *name;\n+ swig_converter_func converter;\n+ const char *str;\n+ void *clientdata;\n+ swig_dycast_func dcast;\n+ struct swig_type_info *next;\n+ struct swig_type_info *prev;\n+} swig_type_info;\n+\n+/* \n+ Compare two type names skipping the space characters, therefore\n+ \"char*\" == \"char *\" and \"Class\" == \"Class\", etc.\n+\n+ Return 0 when the two name types are equivalent, as in\n+ strncmp, but skipping ' '.\n+*/\n+SWIGRUNTIME int\n+SWIG_TypeNameComp(const char *f1, const char *l1,\n+\t\t const char *f2, const char *l2) {\n+ for (;(f1 != l1) && (f2 != l2); ++f1, ++f2) {\n+ while ((*f1 == ' ') && (f1 != l1)) ++f1;\n+ while ((*f2 == ' ') && (f2 != l2)) ++f2;\n+ if (*f1 != *f2) return *f1 - *f2;\n+ }\n+ return (l1 - f1) - (l2 - f2);\n+}\n+\n+/*\n+ Check type equivalence in a name list like ||...\n+*/\n+SWIGRUNTIME int\n+SWIG_TypeEquiv(const char *nb, const char *tb) {\n+ int equiv = 0;\n+ const char* te = tb + strlen(tb);\n+ const char* ne = nb;\n+ while (!equiv && *ne) {\n+ for (nb = ne; *ne; ++ne) {\n+ if (*ne == '|') break;\n+ }\n+ equiv = SWIG_TypeNameComp(nb, ne, tb, te) == 0;\n+ if (*ne) ++ne;\n+ }\n+ return equiv;\n+}\n+\n+/*\n+ Register a type mapping with the type-checking\n+*/\n+SWIGRUNTIME swig_type_info *\n+SWIG_TypeRegisterTL(swig_type_info **tl, swig_type_info *ti) {\n+ swig_type_info *tc, *head, *ret, *next;\n+ /* Check to see if this type has already been registered */\n+ tc = *tl;\n+ while (tc) {\n+ /* check simple type equivalence */\n+ int typeequiv = (strcmp(tc->name, ti->name) == 0); \n+ /* check full type equivalence, resolving typedefs */\n+ if (!typeequiv) {\n+ /* only if tc is not a typedef (no '|' on it) */\n+ if (tc->str && ti->str && !strstr(tc->str,\"|\")) {\n+\ttypeequiv = SWIG_TypeEquiv(ti->str,tc->str);\n+ }\n+ }\n+ if (typeequiv) {\n+ /* Already exists in the table. Just add additional types to the list */\n+ if (ti->clientdata) tc->clientdata = ti->clientdata;\n+ head = tc;\n+ next = tc->next;\n+ goto l1;\n+ }\n+ tc = tc->prev;\n+ }\n+ head = ti;\n+ next = 0;\n+\n+ /* Place in list */\n+ ti->prev = *tl;\n+ *tl = ti;\n+\n+ /* Build linked lists */\n+ l1:\n+ ret = head;\n+ tc = ti + 1;\n+ /* Patch up the rest of the links */\n+ while (tc->name) {\n+ head->next = tc;\n+ tc->prev = head;\n+ head = tc;\n+ tc++;\n+ }\n+ if (next) next->prev = head;\n+ head->next = next;\n+\n+ return ret;\n+}\n+\n+/*\n+ Check the typename\n+*/\n+SWIGRUNTIME swig_type_info *\n+SWIG_TypeCheck(const char *c, swig_type_info *ty) {\n+ swig_type_info *s;\n+ if (!ty) return 0; /* Void pointer */\n+ s = ty->next; /* First element always just a name */\n+ do {\n+ if (strcmp(s->name,c) == 0) {\n+ if (s == ty->next) return s;\n+ /* Move s to the top of the linked list */\n+ s->prev->next = s->next;\n+ if (s->next) {\n+ s->next->prev = s->prev;\n+ }\n+ /* Insert s as second element in the list */\n+ s->next = ty->next;\n+ if (ty->next) ty->next->prev = s;\n+ ty->next = s;\n+ s->prev = ty;\n+ return s;\n+ }\n+ s = s->next;\n+ } while (s && (s != ty->next));\n+ return 0;\n+}\n+\n+/*\n+ Cast a pointer up an inheritance hierarchy\n+*/\n+SWIGRUNTIMEINLINE void *\n+SWIG_TypeCast(swig_type_info *ty, void *ptr) {\n+ return ((!ty) || (!ty->converter)) ? ptr : (*ty->converter)(ptr);\n+}\n+\n+/* \n+ Dynamic pointer casting. Down an inheritance hierarchy\n+*/\n+SWIGRUNTIME swig_type_info *\n+SWIG_TypeDynamicCast(swig_type_info *ty, void **ptr) {\n+ swig_type_info *lastty = ty;\n+ if (!ty || !ty->dcast) return ty;\n+ while (ty && (ty->dcast)) {\n+ ty = (*ty->dcast)(ptr);\n+ if (ty) lastty = ty;\n+ }\n+ return lastty;\n+}\n+\n+/*\n+ Return the name associated with this type\n+*/\n+SWIGRUNTIMEINLINE const char *\n+SWIG_TypeName(const swig_type_info *ty) {\n+ return ty->name;\n+}\n+\n+/*\n+ Return the pretty name associated with this type,\n+ that is an unmangled type name in a form presentable to the user.\n+*/\n+SWIGRUNTIME const char *\n+SWIG_TypePrettyName(const swig_type_info *type) {\n+ /* The \"str\" field contains the equivalent pretty names of the\n+ type, separated by vertical-bar characters. We choose\n+ to print the last name, as it is often (?) the most\n+ specific. */\n+ if (type->str != NULL) {\n+ const char *last_name = type->str;\n+ const char *s;\n+ for (s = type->str; *s; s++)\n+ if (*s == '|') last_name = s+1;\n+ return last_name;\n+ }\n+ else\n+ return type->name;\n+}\n+\n+/*\n+ Search for a swig_type_info structure\n+*/\n+SWIGRUNTIME swig_type_info *\n+SWIG_TypeQueryTL(swig_type_info *tl, const char *name) {\n+ swig_type_info *ty = tl;\n+ while (ty) {\n+ if (ty->str && (SWIG_TypeEquiv(ty->str,name))) return ty;\n+ if (ty->name && (strcmp(name,ty->name) == 0)) return ty;\n+ ty = ty->prev;\n+ }\n+ return 0;\n+}\n+\n+/* \n+ Set the clientdata field for a type\n+*/\n+SWIGRUNTIME void\n+SWIG_TypeClientDataTL(swig_type_info *tl, swig_type_info *ti, void *clientdata) {\n+ swig_type_info *tc, *equiv;\n+ if (ti->clientdata) return;\n+ /* if (ti->clientdata == clientdata) return; */\n+ ti->clientdata = clientdata;\n+ equiv = ti->next;\n+ while (equiv) {\n+ if (!equiv->converter) {\n+ tc = tl;\n+ while (tc) {\n+ if ((strcmp(tc->name, equiv->name) == 0))\n+ SWIG_TypeClientDataTL(tl,tc,clientdata);\n+ tc = tc->prev;\n+ }\n+ }\n+ equiv = equiv->next;\n+ }\n+}\n+\n+/* \n+ Pack binary data into a string\n+*/\n+SWIGRUNTIME char *\n+SWIG_PackData(char *c, void *ptr, size_t sz) {\n+ static char hex[17] = \"0123456789abcdef\";\n+ unsigned char *u = (unsigned char *) ptr;\n+ const unsigned char *eu = u + sz;\n+ register unsigned char uu;\n+ for (; u != eu; ++u) {\n+ uu = *u;\n+ *(c++) = hex[(uu & 0xf0) >> 4];\n+ *(c++) = hex[uu & 0xf];\n+ }\n+ return c;\n+}\n+\n+/* \n+ Unpack binary data from a string\n+*/\n+SWIGRUNTIME const char *\n+SWIG_UnpackData(const char *c, void *ptr, size_t sz) {\n+ register unsigned char *u = (unsigned char *) ptr;\n+ register const unsigned char *eu = u + sz;\n+ for (; u != eu; ++u) {\n+ register int d = *(c++);\n+ register unsigned char uu = 0;\n+ if ((d >= '0') && (d <= '9'))\n+ uu = ((d - '0') << 4);\n+ else if ((d >= 'a') && (d <= 'f'))\n+ uu = ((d - ('a'-10)) << 4);\n+ else \n+ return (char *) 0;\n+ d = *(c++);\n+ if ((d >= '0') && (d <= '9'))\n+ uu |= (d - '0');\n+ else if ((d >= 'a') && (d <= 'f'))\n+ uu |= (d - ('a'-10));\n+ else \n+ return (char *) 0;\n+ *u = uu;\n+ }\n+ return c;\n+}\n+\n+/*\n+ This function will propagate the clientdata field of type to any new\n+ swig_type_info structures that have been added into the list of\n+ equivalent types. It is like calling SWIG_TypeClientData(type,\n+ clientdata) a second time.\n+*/\n+SWIGRUNTIME void\n+SWIG_PropagateClientDataTL(swig_type_info *tl, swig_type_info *type) {\n+ swig_type_info *equiv = type->next;\n+ swig_type_info *tc;\n+ if (!type->clientdata) return;\n+ while (equiv) {\n+ if (!equiv->converter) {\n+ tc = tl;\n+ while (tc) {\n+ if ((strcmp(tc->name, equiv->name) == 0) && !tc->clientdata)\n+ SWIG_TypeClientDataTL(tl,tc, type->clientdata);\n+ tc = tc->prev;\n+ }\n+ }\n+ equiv = equiv->next;\n+ }\n+}\n+\n+/* \n+ Pack 'void *' into a string buffer.\n+*/\n+SWIGRUNTIME char *\n+SWIG_PackVoidPtr(char *buff, void *ptr, const char *name, size_t bsz) {\n+ char *r = buff;\n+ if ((2*sizeof(void *) + 2) > bsz) return 0;\n+ *(r++) = '_';\n+ r = SWIG_PackData(r,&ptr,sizeof(void *));\n+ if (strlen(name) + 1 > (bsz - (r - buff))) return 0;\n+ strcpy(r,name);\n+ return buff;\n+}\n+\n+SWIGRUNTIME const char *\n+SWIG_UnpackVoidPtr(const char *c, void **ptr, const char *name) {\n+ if (*c != '_') {\n+ if (strcmp(c,\"NULL\") == 0) {\n+ *ptr = (void *) 0;\n+ return name;\n+ } else {\n+ return 0;\n+ }\n+ }\n+ return SWIG_UnpackData(++c,ptr,sizeof(void *));\n+}\n+\n+SWIGRUNTIME char *\n+SWIG_PackDataName(char *buff, void *ptr, size_t sz, const char *name, size_t bsz) {\n+ char *r = buff;\n+ size_t lname = (name ? strlen(name) : 0);\n+ if ((2*sz + 2 + lname) > bsz) return 0;\n+ *(r++) = '_';\n+ r = SWIG_PackData(r,ptr,sz);\n+ if (lname) {\n+ strncpy(r,name,lname+1);\n+ } else {\n+ *r = 0;\n+ }\n+ return buff;\n+}\n+\n+SWIGRUNTIME const char *\n+SWIG_UnpackDataName(const char *c, void *ptr, size_t sz, const char *name) {\n+ if (*c != '_') {\n+ if (strcmp(c,\"NULL\") == 0) {\n+ memset(ptr,0,sz);\n+ return name;\n+ } else {\n+ return 0;\n+ }\n+ }\n+ return SWIG_UnpackData(++c,ptr,sz);\n+}\n+\n+#ifdef __cplusplus\n+}\n+#endif\n+\n+/***********************************************************************\n+ * pyrun.swg\n+ *\n+ * This file contains the runtime support for Python modules\n+ * and includes code for managing global variables and pointer\n+ * type checking.\n+ *\n+ * Author : David Beazley (beazley@cs.uchicago.edu)\n+ ************************************************************************/\n+\n+/* Common SWIG API */\n+#define SWIG_ConvertPtr(obj, pp, type, flags) SWIG_Python_ConvertPtr(obj, pp, type, flags)\n+#define SWIG_NewPointerObj(p, type, flags) SWIG_Python_NewPointerObj(p, type, flags)\n+#define SWIG_MustGetPtr(p, type, argnum, flags) SWIG_Python_MustGetPtr(p, type, argnum, flags)\n+ \n+\n+/* Python-specific SWIG API */\n+#define SWIG_ConvertPacked(obj, ptr, sz, ty, flags) SWIG_Python_ConvertPacked(obj, ptr, sz, ty, flags)\n+#define SWIG_NewPackedObj(ptr, sz, type) SWIG_Python_NewPackedObj(ptr, sz, type)\n+\n+\n+/* -----------------------------------------------------------------------------\n+ * Pointer declarations\n+ * ----------------------------------------------------------------------------- */\n+/*\n+ Use SWIG_NO_COBJECT_TYPES to force the use of strings to represent\n+ C/C++ pointers in the python side. Very useful for debugging, but\n+ not always safe.\n+*/\n+#if !defined(SWIG_NO_COBJECT_TYPES) && !defined(SWIG_COBJECT_TYPES)\n+# define SWIG_COBJECT_TYPES\n+#endif\n+\n+/* Flags for pointer conversion */\n+#define SWIG_POINTER_EXCEPTION 0x1\n+#define SWIG_POINTER_DISOWN 0x2\n+\n+\n+#ifdef __cplusplus\n+extern \"C\" {\n+#endif\n+\n+/* -----------------------------------------------------------------------------\n+ * Create a new pointer string \n+ * ----------------------------------------------------------------------------- */\n+\n+#ifndef SWIG_BUFFER_SIZE\n+#define SWIG_BUFFER_SIZE 1024\n+#endif\n+\n+#if defined(SWIG_COBJECT_TYPES)\n+#if !defined(SWIG_COBJECT_PYTHON)\n+/* -----------------------------------------------------------------------------\n+ * Implements a simple Swig Object type, and use it instead of PyCObject\n+ * ----------------------------------------------------------------------------- */\n+\n+typedef struct {\n+ PyObject_HEAD\n+ void *ptr;\n+ const char *desc;\n+} PySwigObject;\n+\n+/* Declarations for objects of type PySwigObject */\n+\n+SWIGRUNTIME int\n+PySwigObject_print(PySwigObject *v, FILE *fp, int flags)\n+{\n+ char result[SWIG_BUFFER_SIZE];\n+ if (SWIG_PackVoidPtr(result, v->ptr, v->desc, sizeof(result))) {\n+ fputs(\"\", fp);\n+ return 0; \n+ } else {\n+ return 1; \n+ }\n+}\n+ \n+SWIGRUNTIME PyObject *\n+PySwigObject_repr(PySwigObject *v)\n+{\n+ char result[SWIG_BUFFER_SIZE];\n+ return SWIG_PackVoidPtr(result, v->ptr, v->desc, sizeof(result)) ?\n+ PyString_FromFormat(\"\", result) : 0;\n+}\n+\n+SWIGRUNTIME PyObject *\n+PySwigObject_str(PySwigObject *v)\n+{\n+ char result[SWIG_BUFFER_SIZE];\n+ return SWIG_PackVoidPtr(result, v->ptr, v->desc, sizeof(result)) ?\n+ PyString_FromString(result) : 0;\n+}\n+\n+SWIGRUNTIME PyObject *\n+PySwigObject_long(PySwigObject *v)\n+{\n+ return PyLong_FromUnsignedLong((unsigned long) v->ptr);\n+}\n+\n+SWIGRUNTIME PyObject *\n+PySwigObject_oct(PySwigObject *v)\n+{\n+ char buf[100];\n+ unsigned long x = (unsigned long)v->ptr;\n+ if (x == 0)\n+ strcpy(buf, \"0\");\n+ else\n+ PyOS_snprintf(buf, sizeof(buf), \"0%lo\", x);\n+ return PyString_FromString(buf);\n+}\n+\n+SWIGRUNTIME PyObject *\n+PySwigObject_hex(PySwigObject *v)\n+{\n+ char buf[100];\n+ PyOS_snprintf(buf, sizeof(buf), \"0x%lx\", (unsigned long)v->ptr);\n+ return PyString_FromString(buf);\n+}\n+\n+SWIGRUNTIME int\n+PySwigObject_compare(PySwigObject *v, PySwigObject *w)\n+{\n+ int c = strcmp(v->desc, w->desc);\n+ if (c) {\n+ return c;\n+ } else {\n+ void *i = v->ptr;\n+ void *j = w->ptr;\n+ return (i < j) ? -1 : (i > j) ? 1 : 0;\n+ }\n+}\n+\n+SWIGRUNTIME void\n+PySwigObject_dealloc(PySwigObject *self)\n+{\n+ PyObject_DEL(self);\n+}\n+\n+SWIGRUNTIME PyTypeObject*\n+PySwigObject_GetType() {\n+ static char PySwigObject_Type__doc__[] = \n+ \"Swig object carries a C/C++ instance pointer\";\n+ \n+ static PyNumberMethods PySwigObject_as_number = {\n+ (binaryfunc)0, /*nb_add*/\n+ (binaryfunc)0, /*nb_subtract*/\n+ (binaryfunc)0, /*nb_multiply*/\n+ (binaryfunc)0, /*nb_divide*/\n+ (binaryfunc)0, /*nb_remainder*/\n+ (binaryfunc)0, /*nb_divmod*/\n+ (ternaryfunc)0,/*nb_power*/\n+ (unaryfunc)0, /*nb_negative*/\n+ (unaryfunc)0, /*nb_positive*/\n+ (unaryfunc)0, /*nb_absolute*/\n+ (inquiry)0, /*nb_nonzero*/\n+ 0,\t\t /*nb_invert*/\n+ 0,\t\t /*nb_lshift*/\n+ 0,\t\t /*nb_rshift*/\n+ 0,\t\t /*nb_and*/\n+ 0,\t\t /*nb_xor*/\n+ 0,\t\t /*nb_or*/\n+ (coercion)0, /*nb_coerce*/\n+ (unaryfunc)PySwigObject_long, /*nb_int*/\n+ (unaryfunc)PySwigObject_long, /*nb_long*/\n+ (unaryfunc)0, /*nb_float*/\n+ (unaryfunc)PySwigObject_oct, /*nb_oct*/\n+ (unaryfunc)PySwigObject_hex, /*nb_hex*/\n+#if PY_VERSION_HEX >= 0x02000000\n+ 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0 /* nb_inplace_add -> nb_inplace_true_divide */ \n+#endif\n+ };\n+\n+ static PyTypeObject PySwigObject_Type = {\n+ PyObject_HEAD_INIT(&PyType_Type)\n+ 0,\t\t\t\t\t/*ob_size*/\n+ \"PySwigObject\",\t\t\t/*tp_name*/\n+ sizeof(PySwigObject),\t\t/*tp_basicsize*/\n+ 0,\t\t\t\t\t/*tp_itemsize*/\n+ /* methods */\n+ (destructor)PySwigObject_dealloc,\t/*tp_dealloc*/\n+ (printfunc)PySwigObject_print,\t/*tp_print*/\n+ (getattrfunc)0,\t\t\t/*tp_getattr*/\n+ (setattrfunc)0,\t\t\t/*tp_setattr*/\n+ (cmpfunc)PySwigObject_compare,\t/*tp_compare*/\n+ (reprfunc)PySwigObject_repr,\t/*tp_repr*/\n+ &PySwigObject_as_number,\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+ (hashfunc)0,\t\t\t/*tp_hash*/\n+ (ternaryfunc)0,\t\t\t/*tp_call*/\n+ (reprfunc)PySwigObject_str,\t\t/*tp_str*/\n+ /* Space for future expansion */\n+ 0L,0L,0L,0L,\n+ PySwigObject_Type__doc__, \t /* Documentation string */\n+#if PY_VERSION_HEX >= 0x02000000\n+ 0, /* tp_traverse */\n+ 0, /* tp_clear */\n+#endif\n+#if PY_VERSION_HEX >= 0x02010000\n+ 0, /* tp_richcompare */\n+ 0, /* tp_weaklistoffset */\n+#endif\n+#if PY_VERSION_HEX >= 0x02020000\n+ 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, /* tp_iter -> tp_weaklist */\n+#endif\n+#if PY_VERSION_HEX >= 0x02030000\n+ 0, /* tp_del */\n+#endif\n+#ifdef COUNT_ALLOCS\n+ 0,0,0,0 /* tp_alloc -> tp_next */\n+#endif\n+ };\n+\n+ return &PySwigObject_Type;\n+}\n+\n+SWIGRUNTIME PyObject *\n+PySwigObject_FromVoidPtrAndDesc(void *ptr, const char *desc)\n+{\n+ PySwigObject *self = PyObject_NEW(PySwigObject, PySwigObject_GetType());\n+ if (self == NULL) return NULL;\n+ self->ptr = ptr;\n+ self->desc = desc;\n+ return (PyObject *)self;\n+}\n+\n+SWIGRUNTIMEINLINE void *\n+PySwigObject_AsVoidPtr(PyObject *self)\n+{\n+ return ((PySwigObject *)self)->ptr;\n+}\n+\n+SWIGRUNTIMEINLINE const char *\n+PySwigObject_GetDesc(PyObject *self)\n+{\n+ return ((PySwigObject *)self)->desc;\n+}\n+\n+SWIGRUNTIMEINLINE int\n+PySwigObject_Check(PyObject *op) {\n+ return ((op)->ob_type == PySwigObject_GetType()) \n+ || (strcmp((op)->ob_type->tp_name,\"PySwigObject\") == 0);\n+}\n+\n+/* -----------------------------------------------------------------------------\n+ * Implements a simple Swig Packed type, and use it instead of string\n+ * ----------------------------------------------------------------------------- */\n+\n+typedef struct {\n+ PyObject_HEAD\n+ void *pack;\n+ const char *desc;\n+ size_t size;\n+} PySwigPacked;\n+\n+SWIGRUNTIME int\n+PySwigPacked_print(PySwigPacked *v, FILE *fp, int flags)\n+{\n+ char result[SWIG_BUFFER_SIZE];\n+ fputs(\"pack, v->size, 0, sizeof(result))) {\n+ fputs(\"at \", fp); \n+ fputs(result, fp); \n+ }\n+ fputs(v->desc,fp); \n+ fputs(\">\", fp);\n+ return 0; \n+}\n+ \n+SWIGRUNTIME PyObject *\n+PySwigPacked_repr(PySwigPacked *v)\n+{\n+ char result[SWIG_BUFFER_SIZE];\n+ if (SWIG_PackDataName(result, v->pack, v->size, 0, sizeof(result))) {\n+ return PyString_FromFormat(\"\", result, v->desc);\n+ } else {\n+ return PyString_FromFormat(\"\", v->desc);\n+ } \n+}\n+\n+SWIGRUNTIME PyObject *\n+PySwigPacked_str(PySwigPacked *v)\n+{\n+ char result[SWIG_BUFFER_SIZE];\n+ if (SWIG_PackDataName(result, v->pack, v->size, 0, sizeof(result))){\n+ return PyString_FromFormat(\"%s%s\", result, v->desc);\n+ } else {\n+ return PyString_FromFormat(\"%s\", v->desc);\n+ } \n+}\n+\n+SWIGRUNTIME int\n+PySwigPacked_compare(PySwigPacked *v, PySwigPacked *w)\n+{\n+ int c = strcmp(v->desc, w->desc);\n+ if (c) {\n+ return c;\n+ } else {\n+ size_t i = v->size;\n+ size_t j = w->size;\n+ int s = (i < j) ? -1 : (i > j) ? 1 : 0;\n+ return s ? s : strncmp((char *)v->pack, (char *)w->pack, 2*v->size);\n+ }\n+}\n+\n+SWIGRUNTIME void\n+PySwigPacked_dealloc(PySwigPacked *self)\n+{\n+ free(self->pack);\n+ PyObject_DEL(self);\n+}\n+\n+SWIGRUNTIME PyTypeObject*\n+PySwigPacked_GetType() {\n+ static char PySwigPacked_Type__doc__[] = \n+ \"Swig object carries a C/C++ instance pointer\";\n+ \n+ static PyTypeObject PySwigPacked_Type = {\n+ PyObject_HEAD_INIT(&PyType_Type)\n+ 0,\t\t\t\t\t/*ob_size*/\n+ \"PySwigPacked\",\t\t\t/*tp_name*/\n+ sizeof(PySwigPacked),\t\t/*tp_basicsize*/\n+ 0,\t\t\t\t\t/*tp_itemsize*/\n+ /* methods */\n+ (destructor)PySwigPacked_dealloc,\t/*tp_dealloc*/\n+ (printfunc)PySwigPacked_print,\t/*tp_print*/\n+ (getattrfunc)0,\t\t\t/*tp_getattr*/\n+ (setattrfunc)0,\t\t\t/*tp_setattr*/\n+ (cmpfunc)PySwigPacked_compare,\t/*tp_compare*/\n+ (reprfunc)PySwigPacked_repr,\t/*tp_repr*/\n+ 0,\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+ (hashfunc)0,\t\t\t/*tp_hash*/\n+ (ternaryfunc)0,\t\t\t/*tp_call*/\n+ (reprfunc)PySwigPacked_str,\t\t/*tp_str*/\n+ /* Space for future expansion */\n+ 0L,0L,0L,0L,\n+ PySwigPacked_Type__doc__, \t /* Documentation string */\n+#if PY_VERSION_HEX >= 0x02000000\n+ 0, /* tp_traverse */\n+ 0, /* tp_clear */\n+#endif\n+#if PY_VERSION_HEX >= 0x02010000\n+ 0, /* tp_richcompare */\n+ 0, /* tp_weaklistoffset */\n+#endif\n+#if PY_VERSION_HEX >= 0x02020000 \n+ 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, /* tp_iter -> tp_weaklist */\n+#endif\n+#if PY_VERSION_HEX >= 0x02030000\n+ 0, /* tp_del */\n+#endif\n+#ifdef COUNT_ALLOCS\n+ 0,0,0,0 /* tp_alloc -> tp_next */\n+#endif\n+ };\n+\n+ return &PySwigPacked_Type;\n+}\n+\n+SWIGRUNTIME PyObject *\n+PySwigPacked_FromDataAndDesc(void *ptr, size_t size, const char *desc)\n+{\n+ PySwigPacked *self = PyObject_NEW(PySwigPacked, PySwigPacked_GetType());\n+ if (self == NULL) {\n+ return NULL;\n+ } else {\n+ void *pack = malloc(size);\n+ memcpy(pack, ptr, size);\n+ self->pack = pack;\n+ self->desc = desc;\n+ self->size = size;\n+ return (PyObject *) self;\n+ }\n+}\n+\n+SWIGRUNTIMEINLINE const char *\n+PySwigPacked_UnpackData(PyObject *obj, void *ptr, size_t size)\n+{\n+ PySwigPacked *self = (PySwigPacked *)obj;\n+ if (self->size != size) return 0;\n+ memcpy(ptr, self->pack, size);\n+ return self->desc;\n+}\n+\n+SWIGRUNTIMEINLINE const char *\n+PySwigPacked_GetDesc(PyObject *self)\n+{\n+ return ((PySwigPacked *)self)->desc;\n+}\n+\n+SWIGRUNTIMEINLINE int\n+PySwigPacked_Check(PyObject *op) {\n+ return ((op)->ob_type == PySwigPacked_GetType()) \n+ || (strcmp((op)->ob_type->tp_name,\"PySwigPacked\") == 0);\n+}\n+\n+#else\n+/* -----------------------------------------------------------------------------\n+ * Use the old Python PyCObject instead of PySwigObject\n+ * ----------------------------------------------------------------------------- */\n+\n+#define PySwigObject_GetDesc(obj)\t PyCObject_GetDesc(obj)\n+#define PySwigObject_Check(obj)\t PyCObject_Check(obj)\n+#define PySwigObject_AsVoidPtr(obj)\t PyCObject_AsVoidPtr(obj)\n+#define PySwigObject_FromVoidPtrAndDesc(p, d) PyCObject_FromVoidPtrAndDesc(p, d, NULL)\n+\n+#endif\n+\n+#endif\n+\n+/* -----------------------------------------------------------------------------\n+ * errors manipulation\n+ * ----------------------------------------------------------------------------- */\n+\n+SWIGRUNTIME void\n+SWIG_Python_TypeError(const char *type, PyObject *obj)\n+{\n+ if (type) {\n+#if defined(SWIG_COBJECT_TYPES)\n+ if (PySwigObject_Check(obj)) {\n+ const char *otype = (const char *) PySwigObject_GetDesc(obj);\n+ if (otype) {\n+\tPyErr_Format(PyExc_TypeError, \"a '%s' is expected, 'PySwigObject(%s)' is received\",\n+\t\t type, otype);\n+\treturn;\n+ }\n+ } else \n+#endif \n+ {\n+ const char *otype = (obj ? obj->ob_type->tp_name : 0); \n+ if (otype) {\n+\tPyObject *str = PyObject_Str(obj);\n+\tconst char *cstr = str ? PyString_AsString(str) : 0;\n+\tif (cstr) {\n+\t PyErr_Format(PyExc_TypeError, \"a '%s' is expected, '%s(%s)' is received\",\n+\t\t type, otype, cstr);\n+\t} else {\n+\t PyErr_Format(PyExc_TypeError, \"a '%s' is expected, '%s' is received\",\n+\t\t type, otype);\n+\t}\n+\tPy_DECREF(str);\n+\treturn;\n+ }\n+ } \n+ PyErr_Format(PyExc_TypeError, \"a '%s' is expected\", type);\n+ } else {\n+ PyErr_Format(PyExc_TypeError, \"unexpected type is received\");\n+ }\n+}\n+\n+SWIGRUNTIMEINLINE void\n+SWIG_Python_NullRef(const char *type)\n+{\n+ if (type) {\n+ PyErr_Format(PyExc_TypeError, \"null reference of type '%s' was received\",type);\n+ } else {\n+ PyErr_Format(PyExc_TypeError, \"null reference was received\");\n+ }\n+}\n+\n+SWIGRUNTIME int\n+SWIG_Python_AddErrMesg(const char* mesg, int infront)\n+{\n+ if (PyErr_Occurred()) {\n+ PyObject *type = 0;\n+ PyObject *value = 0;\n+ PyObject *traceback = 0;\n+ PyErr_Fetch(&type, &value, &traceback);\n+ if (value) {\n+ PyObject *old_str = PyObject_Str(value);\n+ Py_XINCREF(type);\n+ PyErr_Clear();\n+ if (infront) {\n+\tPyErr_Format(type, \"%s %s\", mesg, PyString_AsString(old_str));\n+ } else {\n+\tPyErr_Format(type, \"%s %s\", PyString_AsString(old_str), mesg);\n+ }\n+ Py_DECREF(old_str);\n+ }\n+ return 1;\n+ } else {\n+ return 0;\n+ }\n+}\n+\n+SWIGRUNTIME int\n+SWIG_Python_ArgFail(int argnum)\n+{\n+ if (PyErr_Occurred()) {\n+ /* add information about failing argument */\n+ char mesg[256];\n+ sprintf(mesg, \"argument number %d:\", argnum);\n+ return SWIG_Python_AddErrMesg(mesg, 1);\n+ } else {\n+ return 0;\n+ }\n+}\n+\n+\n+/* -----------------------------------------------------------------------------\n+ * pointers/data manipulation\n+ * ----------------------------------------------------------------------------- */\n+\n+/* Convert a pointer value */\n+SWIGRUNTIME int\n+SWIG_Python_ConvertPtr(PyObject *obj, void **ptr, swig_type_info *ty, int flags) {\n+ swig_type_info *tc;\n+ const char *c = 0;\n+ static PyObject *SWIG_this = 0;\n+ int newref = 0;\n+ PyObject *pyobj = 0;\n+ void *vptr;\n+ \n+ if (!obj) return 0;\n+ if (obj == Py_None) {\n+ *ptr = 0;\n+ return 0;\n+ }\n+\n+#ifdef SWIG_COBJECT_TYPES\n+ if (!(PySwigObject_Check(obj))) {\n+ if (!SWIG_this)\n+ SWIG_this = PyString_FromString(\"this\");\n+ pyobj = obj;\n+ obj = PyObject_GetAttr(obj,SWIG_this);\n+ newref = 1;\n+ if (!obj) goto type_error;\n+ if (!PySwigObject_Check(obj)) {\n+ Py_DECREF(obj);\n+ goto type_error;\n+ }\n+ } \n+ vptr = PySwigObject_AsVoidPtr(obj);\n+ c = (const char *) PySwigObject_GetDesc(obj);\n+ if (newref) { Py_DECREF(obj); }\n+ goto type_check;\n+#else\n+ if (!(PyString_Check(obj))) {\n+ if (!SWIG_this)\n+ SWIG_this = PyString_FromString(\"this\");\n+ pyobj = obj;\n+ obj = PyObject_GetAttr(obj,SWIG_this);\n+ newref = 1;\n+ if (!obj) goto type_error;\n+ if (!PyString_Check(obj)) {\n+ Py_DECREF(obj);\n+ goto type_error;\n+ }\n+ } \n+ c = PyString_AS_STRING(obj);\n+ /* Pointer values must start with leading underscore */\n+ c = SWIG_UnpackVoidPtr(c, &vptr, ty->name);\n+ if (newref) { Py_DECREF(obj); }\n+ if (!c) goto type_error;\n+#endif\n+\n+type_check:\n+\n+ if (ty) {\n+ tc = SWIG_TypeCheck(c,ty);\n+ if (!tc) goto type_error;\n+ *ptr = SWIG_TypeCast(tc,vptr);\n+ }\n+\n+ if ((pyobj) && (flags & SWIG_POINTER_DISOWN)) {\n+ PyObject_SetAttrString(pyobj,(char*)\"thisown\",Py_False);\n+ }\n+ return 0;\n+\n+type_error:\n+ PyErr_Clear();\n+ if (pyobj && !obj) { \n+ obj = pyobj;\n+ if (PyCFunction_Check(obj)) {\n+ /* here we get the method pointer for callbacks */\n+ char *doc = (((PyCFunctionObject *)obj) -> m_ml -> ml_doc);\n+ c = doc ? strstr(doc, \"swig_ptr: \") : 0;\n+ if (c) {\n+\tc = SWIG_UnpackVoidPtr(c + 10, &vptr, ty->name);\n+\tif (!c) goto type_error;\n+\tgoto type_check;\n+ }\n+ }\n+ }\n+ if (flags & SWIG_POINTER_EXCEPTION) {\n+ if (ty) {\n+ SWIG_Python_TypeError(SWIG_TypePrettyName(ty), obj);\n+ } else {\n+ SWIG_Python_TypeError(\"C/C++ pointer\", obj);\n+ }\n+ }\n+ return -1;\n+}\n+\n+/* Convert a pointer value, signal an exception on a type mismatch */\n+SWIGRUNTIME void *\n+SWIG_Python_MustGetPtr(PyObject *obj, swig_type_info *ty, int argnum, int flags) {\n+ void *result;\n+ if (SWIG_Python_ConvertPtr(obj, &result, ty, flags) == -1) {\n+ PyErr_Clear();\n+ if (flags & SWIG_POINTER_EXCEPTION) {\n+ SWIG_Python_TypeError(SWIG_TypePrettyName(ty), obj);\n+ SWIG_Python_ArgFail(argnum);\n+ }\n+ }\n+ return result;\n+}\n+\n+/* Convert a packed value value */\n+SWIGRUNTIME int\n+SWIG_Python_ConvertPacked(PyObject *obj, void *ptr, size_t sz, swig_type_info *ty, int flags) {\n+ swig_type_info *tc;\n+ const char *c = 0;\n+\n+#if defined(SWIG_COBJECT_TYPES) && !defined(SWIG_COBJECT_PYTHON)\n+ c = PySwigPacked_UnpackData(obj, ptr, sz);\n+#else\n+ if ((!obj) || (!PyString_Check(obj))) goto type_error;\n+ c = PyString_AS_STRING(obj);\n+ /* Pointer values must start with leading underscore */\n+ c = SWIG_UnpackDataName(c, ptr, sz, ty->name);\n+#endif\n+ if (!c) goto type_error;\n+ if (ty) {\n+ tc = SWIG_TypeCheck(c,ty);\n+ if (!tc) goto type_error;\n+ }\n+ return 0;\n+\n+type_error:\n+ PyErr_Clear();\n+ if (flags & SWIG_POINTER_EXCEPTION) {\n+ if (ty) {\n+ SWIG_Python_TypeError(SWIG_TypePrettyName(ty), obj);\n+ } else {\n+ SWIG_Python_TypeError(\"C/C++ packed data\", obj);\n+ }\n+ }\n+ return -1;\n+} \n+\n+/* Create a new array object */\n+SWIGRUNTIME PyObject *\n+SWIG_Python_NewPointerObj(void *ptr, swig_type_info *type, int own) {\n+ PyObject *robj = 0;\n+ if (!ptr) {\n+ Py_INCREF(Py_None);\n+ return Py_None;\n+ }\n+#ifdef SWIG_COBJECT_TYPES\n+ robj = PySwigObject_FromVoidPtrAndDesc((void *) ptr, (char *)type->name);\n+#else\n+ {\n+ char result[SWIG_BUFFER_SIZE];\n+ robj = SWIG_PackVoidPtr(result, ptr, type->name, sizeof(result)) ?\n+ PyString_FromString(result) : 0;\n+ }\n+#endif\n+ if (!robj || (robj == Py_None)) return robj;\n+ if (type->clientdata) {\n+ PyObject *inst;\n+ PyObject *args = Py_BuildValue((char*)\"(O)\", robj);\n+ Py_DECREF(robj);\n+ inst = PyObject_CallObject((PyObject *) type->clientdata, args);\n+ Py_DECREF(args);\n+ if (inst) {\n+ if (own) {\n+ PyObject_SetAttrString(inst,(char*)\"thisown\",Py_True);\n+ }\n+ robj = inst;\n+ }\n+ }\n+ return robj;\n+}\n+\n+SWIGRUNTIME PyObject *\n+SWIG_Python_NewPackedObj(void *ptr, size_t sz, swig_type_info *type) {\n+ PyObject *robj = 0;\n+ if (!ptr) {\n+ Py_INCREF(Py_None);\n+ return Py_None;\n+ }\n+#if defined(SWIG_COBJECT_TYPES) && !defined(SWIG_COBJECT_PYTHON)\n+ robj = PySwigPacked_FromDataAndDesc((void *) ptr, sz, (char *)type->name);\n+#else\n+ {\n+ char result[SWIG_BUFFER_SIZE];\n+ robj = SWIG_PackDataName(result, ptr, sz, type->name, sizeof(result)) ?\n+ PyString_FromString(result) : 0;\n+ }\n+#endif\n+ return robj;\n+}\n+\n+/* -----------------------------------------------------------------------------*\n+ * Get type list \n+ * -----------------------------------------------------------------------------*/\n+\n+#ifdef SWIG_LINK_RUNTIME\n+void *SWIG_ReturnGlobalTypeList(void *);\n+#endif\n+\n+SWIGRUNTIME swig_type_info **\n+SWIG_Python_GetTypeListHandle() {\n+ static void *type_pointer = (void *)0;\n+ /* first check if module already created */\n+ if (!type_pointer) {\n+#ifdef SWIG_LINK_RUNTIME\n+ type_pointer = SWIG_ReturnGlobalTypeList((void *)0);\n+#else\n+ type_pointer = PyCObject_Import((char*)\"swig_runtime_data\" SWIG_RUNTIME_VERSION,\n+\t\t\t\t (char*)\"type_pointer\" SWIG_TYPE_TABLE_NAME);\n+ if (PyErr_Occurred()) {\n+ PyErr_Clear();\n+ type_pointer = (void *)0;\n+ }\n+ }\n+#endif\n+ return (swig_type_info **) type_pointer;\n+}\n+\n+/*\n+ Search for a swig_type_info structure\n+ */\n+SWIGRUNTIMEINLINE swig_type_info *\n+SWIG_Python_GetTypeList() {\n+ swig_type_info **tlh = SWIG_Python_GetTypeListHandle();\n+ return tlh ? *tlh : (swig_type_info*)0;\n+}\n+\n+#define SWIG_Runtime_GetTypeList SWIG_Python_GetTypeList \n+\n+#ifdef __cplusplus\n+}\n+#endif\n+\n+/* -----------------------------------------------------------------------------*\n+ Standard SWIG API for use inside user code.\n+ \n+ You need to include in your code as follow:\n+\n+#include // or using your favorite language \n+#include \n+#include // or using your favorite language \n+#include \n+ \n+ * -----------------------------------------------------------------------------*/\n+\n+SWIGRUNTIMEINLINE swig_type_info *\n+SWIG_Runtime_TypeQuery(const char *name) {\n+ swig_type_info *tl = SWIG_Runtime_GetTypeList();\n+ return SWIG_TypeQueryTL(tl, name);\n+}\n+\n+SWIGRUNTIMEINLINE swig_type_info *\n+SWIG_Runtime_TypeRegister(swig_type_info *ti) {\n+ swig_type_info *tl = SWIG_Runtime_GetTypeList();\n+ return SWIG_TypeRegisterTL(&tl, ti);\n+}\n+\n+SWIGRUNTIMEINLINE void\n+SWIG_Runtime_TypeClientData(swig_type_info *ti, void *clientdata) {\n+ swig_type_info *tl = SWIG_Runtime_GetTypeList();\n+ SWIG_TypeClientDataTL(tl, ti, clientdata);\n+}\n+\n+SWIGRUNTIMEINLINE void\n+SWIG_Runtime_PropagateClientData(swig_type_info *type) {\n+ swig_type_info *tl = SWIG_Runtime_GetTypeList();\n+ SWIG_PropagateClientDataTL(tl, type);\n+}\n+\n+#define SWIG_GetTypeList() SWIG_Runtime_GetTypeList()\n+#define SWIG_TypeQuery(name) SWIG_Runtime_TypeQuery(name)\n+#define SWIG_TypeRegister(ti) SWIG_Runtime_TypeRegister(ti)\n+#define SWIG_TypeClientData(ti, cd) SWIG_Runtime_TypeClientData(ti, cd)\n+#define SWIG_PropagateClientData(ti) SWIG_Runtime_PropagateClientData(ti)\n+\n+\"\"\"\n", "added_lines": 1187, "deleted_lines": 1, "source_code": "# This code allows one to use SWIG wrapped objects from weave. This\n# code is specific to SWIG-1.3 and above where things are different.\n# The code is basically all copied out from the SWIG wrapper code but\n# it has been hand edited for brevity.\n#\n# Prabhu Ramachandran \n\n######################################################################\n# This is for SWIG-1.3.x where x < 22.\n# Essentially, SWIG_RUNTIME_VERSION was not yet used.\nswigptr2_code_v0 = \"\"\"\n\n#include \"Python.h\"\n\n/*************************************************************** -*- c -*-\n * python/precommon.swg\n *\n * Rename all exported symbols from common.swg, to avoid symbol\n * clashes if multiple interpreters are included\n *\n ************************************************************************/\n\n#define SWIG_TypeCheck SWIG_Python_TypeCheck\n#define SWIG_TypeCast SWIG_Python_TypeCast\n#define SWIG_TypeName SWIG_Python_TypeName\n#define SWIG_TypeQuery SWIG_Python_TypeQuery\n#define SWIG_PackData SWIG_Python_PackData \n#define SWIG_UnpackData SWIG_Python_UnpackData \n\n\n/***********************************************************************\n * common.swg\n *\n * This file contains generic SWIG runtime support for pointer\n * type checking as well as a few commonly used macros to control\n * external linkage.\n *\n * Author : David Beazley (beazley@cs.uchicago.edu)\n *\n * Copyright (c) 1999-2000, The University of Chicago\n * \n * This file may be freely redistributed without license or fee provided\n * this copyright message remains intact.\n ************************************************************************/\n\n#include \n\n#if defined(_WIN32) || defined(__WIN32__) || defined(__CYGWIN__)\n# if defined(_MSC_VER) || defined(__GNUC__)\n# if defined(STATIC_LINKED)\n# define SWIGEXPORT(a) a\n# define SWIGIMPORT(a) extern a\n# else\n# define SWIGEXPORT(a) __declspec(dllexport) a\n# define SWIGIMPORT(a) extern a\n# endif\n# else\n# if defined(__BORLANDC__)\n# define SWIGEXPORT(a) a _export\n# define SWIGIMPORT(a) a _export\n# else\n# define SWIGEXPORT(a) a\n# define SWIGIMPORT(a) a\n# endif\n# endif\n#else\n# define SWIGEXPORT(a) a\n# define SWIGIMPORT(a) a\n#endif\n\n#ifdef SWIG_GLOBAL\n# define SWIGRUNTIME(a) SWIGEXPORT(a)\n#else\n# define SWIGRUNTIME(a) static a\n#endif\n\n#ifdef __cplusplus\nextern \"C\" {\n#endif\n\ntypedef void *(*swig_converter_func)(void *);\ntypedef struct swig_type_info *(*swig_dycast_func)(void **);\n\ntypedef struct swig_type_info {\n const char *name;\n swig_converter_func converter;\n const char *str;\n void *clientdata;\n swig_dycast_func dcast;\n struct swig_type_info *next;\n struct swig_type_info *prev;\n} swig_type_info;\n\n#ifdef SWIG_NOINCLUDE\n\nSWIGIMPORT(swig_type_info *) SWIG_TypeCheck(char *c, swig_type_info *);\nSWIGIMPORT(void *) SWIG_TypeCast(swig_type_info *, void *);\nSWIGIMPORT(const char *) SWIG_TypeName(const swig_type_info *);\nSWIGIMPORT(swig_type_info *) SWIG_TypeQuery(const char *);\nSWIGIMPORT(char *) SWIG_PackData(char *, void *, int);\nSWIGIMPORT(char *) SWIG_UnpackData(char *, void *, int);\n\n#else\n\nstatic swig_type_info *swig_type_list = 0;\n\n/* Check the typename */\nSWIGRUNTIME(swig_type_info *) \nSWIG_TypeCheck(char *c, swig_type_info *ty) {\n swig_type_info *s;\n if (!ty) return 0; /* Void pointer */\n s = ty->next; /* First element always just a name */\n do {\n if (strcmp(s->name,c) == 0) {\n if (s == ty->next) return s;\n /* Move s to the top of the linked list */\n s->prev->next = s->next;\n if (s->next) {\n s->next->prev = s->prev;\n }\n /* Insert s as second element in the list */\n s->next = ty->next;\n if (ty->next) ty->next->prev = s;\n ty->next = s;\n s->prev = ty;\n return s;\n }\n s = s->next;\n } while (s && (s != ty->next));\n return 0;\n}\n\n/* Cast a pointer up an inheritance hierarchy */\nSWIGRUNTIME(void *) \nSWIG_TypeCast(swig_type_info *ty, void *ptr) {\n if ((!ty) || (!ty->converter)) return ptr;\n return (*ty->converter)(ptr);\n}\n\n/* Return the name associated with this type */\nSWIGRUNTIME(const char *)\nSWIG_TypeName(const swig_type_info *ty) {\n return ty->name;\n}\n\n/* \n Compare two type names skipping the space characters, therefore\n \"char*\" == \"char *\" and \"Class\" == \"Class\", etc.\n\n Return 0 when the two name types are equivalent, as in\n strncmp, but skipping ' '.\n*/\nstatic int\nSWIG_TypeNameComp(const char *f1, const char *l1,\n\t\t const char *f2, const char *l2) {\n for (;(f1 != l1) && (f2 != l2); ++f1, ++f2) {\n while ((*f1 == ' ') && (f1 != l1)) ++f1;\n while ((*f2 == ' ') && (f2 != l2)) ++f2;\n if (*f1 != *f2) return *f1 - *f2;\n }\n return (l1 - f1) - (l2 - f2);\n}\n\n/*\n Check type equivalence in a name list like ||...\n*/\nstatic int\nSWIG_TypeEquiv(const char *nb, const char *tb) {\n int equiv = 0;\n const char* te = tb + strlen(tb);\n const char* ne = nb;\n while (!equiv && *ne) {\n for (nb = ne; *ne; ++ne) {\n if (*ne == '|') break;\n }\n equiv = SWIG_TypeNameComp(nb, ne, tb, te) == 0;\n if (*ne) ++ne;\n }\n return equiv;\n}\n \n\n/* Search for a swig_type_info structure */\nSWIGRUNTIME(swig_type_info *)\nSWIG_TypeQuery(const char *name) {\n swig_type_info *ty = swig_type_list;\n while (ty) {\n if (ty->str && (SWIG_TypeEquiv(ty->str,name))) return ty;\n if (ty->name && (strcmp(name,ty->name) == 0)) return ty;\n ty = ty->prev;\n }\n return 0;\n}\n\n/* Pack binary data into a string */\nSWIGRUNTIME(char *)\nSWIG_PackData(char *c, void *ptr, int sz) {\n static char hex[17] = \"0123456789abcdef\";\n int i;\n unsigned char *u = (unsigned char *) ptr;\n register unsigned char uu;\n for (i = 0; i < sz; i++,u++) {\n uu = *u;\n *(c++) = hex[(uu & 0xf0) >> 4];\n *(c++) = hex[uu & 0xf];\n }\n return c;\n}\n\n/* Unpack binary data from a string */\nSWIGRUNTIME(char *)\nSWIG_UnpackData(char *c, void *ptr, int sz) {\n register unsigned char uu = 0;\n register int d;\n unsigned char *u = (unsigned char *) ptr;\n int i;\n for (i = 0; i < sz; i++, u++) {\n d = *(c++);\n if ((d >= '0') && (d <= '9'))\n uu = ((d - '0') << 4);\n else if ((d >= 'a') && (d <= 'f'))\n uu = ((d - ('a'-10)) << 4);\n d = *(c++);\n if ((d >= '0') && (d <= '9'))\n uu |= (d - '0');\n else if ((d >= 'a') && (d <= 'f'))\n uu |= (d - ('a'-10));\n *u = uu;\n }\n return c;\n}\n\n#endif\n\n#ifdef __cplusplus\n}\n#endif\n\n/***********************************************************************\n * python.swg\n *\n * This file contains the runtime support for Python modules\n * and includes code for managing global variables and pointer\n * type checking.\n *\n * Author : David Beazley (beazley@cs.uchicago.edu)\n ************************************************************************/\n\n#include \"Python.h\"\n\n#ifdef __cplusplus\nextern \"C\" {\n#endif\n\n#define SWIG_PY_INT 1\n#define SWIG_PY_FLOAT 2\n#define SWIG_PY_STRING 3\n#define SWIG_PY_POINTER 4\n#define SWIG_PY_BINARY 5\n\n/* Flags for pointer conversion */\n\n#define SWIG_POINTER_EXCEPTION 0x1\n#define SWIG_POINTER_DISOWN 0x2\n\n/* Exception handling in wrappers */\n#define SWIG_fail goto fail\n\n/* Constant information structure */\ntypedef struct swig_const_info {\n int type;\n char *name;\n long lvalue;\n double dvalue;\n void *pvalue;\n swig_type_info **ptype;\n} swig_const_info;\n\n/* Common SWIG API */\n#define SWIG_ConvertPtr(obj, pp, type, flags) \\\n SWIG_Python_ConvertPtr(obj, pp, type, flags)\n#define SWIG_NewPointerObj(p, type, flags) \\\n SWIG_Python_NewPointerObj(p, type, flags)\n#define SWIG_MustGetPtr(p, type, argnum, flags) \\\n SWIG_Python_MustGetPtr(p, type, argnum, flags)\n \n\ntypedef double (*py_objasdbl_conv)(PyObject *obj);\n\n#ifdef SWIG_NOINCLUDE\n\nSWIGIMPORT(int) SWIG_Python_ConvertPtr(PyObject *, void **, swig_type_info *, int);\nSWIGIMPORT(PyObject *) SWIG_Python_NewPointerObj(void *, swig_type_info *,int own);\nSWIGIMPORT(void *) SWIG_Python_MustGetPtr(PyObject *, swig_type_info *, int, int);\n\n#else\n\n\n/* Convert a pointer value */\nSWIGRUNTIME(int)\nSWIG_Python_ConvertPtr(PyObject *obj, void **ptr, swig_type_info *ty, int flags) {\n swig_type_info *tc;\n char *c = 0;\n static PyObject *SWIG_this = 0;\n int newref = 0;\n PyObject *pyobj = 0;\n\n if (!obj) return 0;\n if (obj == Py_None) {\n *ptr = 0;\n return 0;\n }\n#ifdef SWIG_COBJECT_TYPES\n if (!(PyCObject_Check(obj))) {\n if (!SWIG_this)\n SWIG_this = PyString_FromString(\"this\");\n pyobj = obj;\n obj = PyObject_GetAttr(obj,SWIG_this);\n newref = 1;\n if (!obj) goto type_error;\n if (!PyCObject_Check(obj)) {\n Py_DECREF(obj);\n goto type_error;\n }\n } \n *ptr = PyCObject_AsVoidPtr(obj);\n c = (char *) PyCObject_GetDesc(obj);\n if (newref) Py_DECREF(obj);\n goto cobject;\n#else\n if (!(PyString_Check(obj))) {\n if (!SWIG_this)\n SWIG_this = PyString_FromString(\"this\");\n pyobj = obj;\n obj = PyObject_GetAttr(obj,SWIG_this);\n newref = 1;\n if (!obj) goto type_error;\n if (!PyString_Check(obj)) {\n Py_DECREF(obj);\n goto type_error;\n }\n } \n c = PyString_AsString(obj);\n /* Pointer values must start with leading underscore */\n if (*c != '_') {\n *ptr = (void *) 0;\n if (strcmp(c,\"NULL\") == 0) {\n if (newref) { Py_DECREF(obj); }\n return 0;\n } else {\n if (newref) { Py_DECREF(obj); }\n goto type_error;\n }\n }\n c++;\n c = SWIG_UnpackData(c,ptr,sizeof(void *));\n if (newref) { Py_DECREF(obj); }\n#endif\n\n#ifdef SWIG_COBJECT_TYPES\ncobject:\n#endif\n\n if (ty) {\n tc = SWIG_TypeCheck(c,ty);\n if (!tc) goto type_error;\n *ptr = SWIG_TypeCast(tc,(void*) *ptr);\n }\n\n if ((pyobj) && (flags & SWIG_POINTER_DISOWN)) {\n PyObject *zero = PyInt_FromLong(0);\n PyObject_SetAttrString(pyobj,(char*)\"thisown\",zero);\n Py_DECREF(zero);\n }\n return 0;\n\ntype_error:\n PyErr_Clear();\n if (flags & SWIG_POINTER_EXCEPTION) {\n if (ty && c) {\n PyErr_Format(PyExc_TypeError, \n\t\t \"Type error. Got %s, expected %s\",\n\t\t c, ty->name);\n } else {\n PyErr_SetString(PyExc_TypeError,\"Expected a pointer\");\n }\n }\n return -1;\n}\n\n/* Convert a pointer value, signal an exception on a type mismatch */\nSWIGRUNTIME(void *)\nSWIG_Python_MustGetPtr(PyObject *obj, swig_type_info *ty, int argnum, int flags) {\n void *result;\n SWIG_Python_ConvertPtr(obj, &result, ty, flags | SWIG_POINTER_EXCEPTION);\n return result;\n}\n\n/* Create a new pointer object */\nSWIGRUNTIME(PyObject *)\nSWIG_Python_NewPointerObj(void *ptr, swig_type_info *type, int own) {\n PyObject *robj;\n if (!ptr) {\n Py_INCREF(Py_None);\n return Py_None;\n }\n#ifdef SWIG_COBJECT_TYPES\n robj = PyCObject_FromVoidPtrAndDesc((void *) ptr, (char *) type->name, NULL);\n#else\n {\n char result[1024];\n char *r = result;\n *(r++) = '_';\n r = SWIG_PackData(r,&ptr,sizeof(void *));\n strcpy(r,type->name);\n robj = PyString_FromString(result);\n }\n#endif\n if (!robj || (robj == Py_None)) return robj;\n if (type->clientdata) {\n PyObject *inst;\n PyObject *args = Py_BuildValue((char*)\"(O)\", robj);\n Py_DECREF(robj);\n inst = PyObject_CallObject((PyObject *) type->clientdata, args);\n Py_DECREF(args);\n if (inst) {\n if (own) {\n PyObject *n = PyInt_FromLong(1);\n PyObject_SetAttrString(inst,(char*)\"thisown\",n);\n Py_DECREF(n);\n }\n robj = inst;\n }\n }\n return robj;\n}\n\n#endif\n\n#ifdef __cplusplus\n}\n#endif\n\n\"\"\"\n\n\n######################################################################\n# This is for SWIG-1.3.x where x >= 23.\n# SWIG_RUNTIME_VERSION == \"1\"\n\n# All this does is to include (cut/paste): \n# and \nswigptr2_code_v1 = \"\"\"\n/***********************************************************************\n * swigrun.swg\n *\n * This file contains generic CAPI SWIG runtime support for pointer\n * type checking.\n *\n ************************************************************************/\n\n/* This should only be incremented when either the layout of swig_type_info changes,\n or for whatever reason, the runtime changes incompatibly */\n#define SWIG_RUNTIME_VERSION \"1\"\n\n/* define SWIG_TYPE_TABLE_NAME as \"SWIG_TYPE_TABLE\" */\n#ifdef SWIG_TYPE_TABLE\n#define SWIG_QUOTE_STRING(x) #x\n#define SWIG_EXPAND_AND_QUOTE_STRING(x) SWIG_QUOTE_STRING(x)\n#define SWIG_TYPE_TABLE_NAME SWIG_EXPAND_AND_QUOTE_STRING(SWIG_TYPE_TABLE)\n#else\n#define SWIG_TYPE_TABLE_NAME\n#endif\n\n#include \n\n#ifndef SWIGINLINE\n#if defined(__cplusplus) || (defined(__GNUC__) && !defined(__STRICT_ANSI__))\n# define SWIGINLINE inline\n#else\n# define SWIGINLINE\n#endif\n#endif\n\n/*\n You can use the SWIGRUNTIME and SWIGRUNTIMEINLINE macros for\n creating a static or dynamic library from the swig runtime code.\n In 99.9% of the cases, swig just needs to declare them as 'static'.\n \n But only do this if is strictly necessary, ie, if you have problems\n with your compiler or so.\n*/\n#ifndef SWIGRUNTIME\n#define SWIGRUNTIME static\n#endif\n#ifndef SWIGRUNTIMEINLINE\n#define SWIGRUNTIMEINLINE SWIGRUNTIME SWIGINLINE\n#endif\n\n#ifdef __cplusplus\nextern \"C\" {\n#endif\n\ntypedef void *(*swig_converter_func)(void *);\ntypedef struct swig_type_info *(*swig_dycast_func)(void **);\n\ntypedef struct swig_type_info {\n const char *name;\n swig_converter_func converter;\n const char *str;\n void *clientdata;\n swig_dycast_func dcast;\n struct swig_type_info *next;\n struct swig_type_info *prev;\n} swig_type_info;\n\n/* \n Compare two type names skipping the space characters, therefore\n \"char*\" == \"char *\" and \"Class\" == \"Class\", etc.\n\n Return 0 when the two name types are equivalent, as in\n strncmp, but skipping ' '.\n*/\nSWIGRUNTIME int\nSWIG_TypeNameComp(const char *f1, const char *l1,\n\t\t const char *f2, const char *l2) {\n for (;(f1 != l1) && (f2 != l2); ++f1, ++f2) {\n while ((*f1 == ' ') && (f1 != l1)) ++f1;\n while ((*f2 == ' ') && (f2 != l2)) ++f2;\n if (*f1 != *f2) return *f1 - *f2;\n }\n return (l1 - f1) - (l2 - f2);\n}\n\n/*\n Check type equivalence in a name list like ||...\n*/\nSWIGRUNTIME int\nSWIG_TypeEquiv(const char *nb, const char *tb) {\n int equiv = 0;\n const char* te = tb + strlen(tb);\n const char* ne = nb;\n while (!equiv && *ne) {\n for (nb = ne; *ne; ++ne) {\n if (*ne == '|') break;\n }\n equiv = SWIG_TypeNameComp(nb, ne, tb, te) == 0;\n if (*ne) ++ne;\n }\n return equiv;\n}\n\n/*\n Register a type mapping with the type-checking\n*/\nSWIGRUNTIME swig_type_info *\nSWIG_TypeRegisterTL(swig_type_info **tl, swig_type_info *ti) {\n swig_type_info *tc, *head, *ret, *next;\n /* Check to see if this type has already been registered */\n tc = *tl;\n while (tc) {\n /* check simple type equivalence */\n int typeequiv = (strcmp(tc->name, ti->name) == 0); \n /* check full type equivalence, resolving typedefs */\n if (!typeequiv) {\n /* only if tc is not a typedef (no '|' on it) */\n if (tc->str && ti->str && !strstr(tc->str,\"|\")) {\n\ttypeequiv = SWIG_TypeEquiv(ti->str,tc->str);\n }\n }\n if (typeequiv) {\n /* Already exists in the table. Just add additional types to the list */\n if (ti->clientdata) tc->clientdata = ti->clientdata;\n head = tc;\n next = tc->next;\n goto l1;\n }\n tc = tc->prev;\n }\n head = ti;\n next = 0;\n\n /* Place in list */\n ti->prev = *tl;\n *tl = ti;\n\n /* Build linked lists */\n l1:\n ret = head;\n tc = ti + 1;\n /* Patch up the rest of the links */\n while (tc->name) {\n head->next = tc;\n tc->prev = head;\n head = tc;\n tc++;\n }\n if (next) next->prev = head;\n head->next = next;\n\n return ret;\n}\n\n/*\n Check the typename\n*/\nSWIGRUNTIME swig_type_info *\nSWIG_TypeCheck(const char *c, swig_type_info *ty) {\n swig_type_info *s;\n if (!ty) return 0; /* Void pointer */\n s = ty->next; /* First element always just a name */\n do {\n if (strcmp(s->name,c) == 0) {\n if (s == ty->next) return s;\n /* Move s to the top of the linked list */\n s->prev->next = s->next;\n if (s->next) {\n s->next->prev = s->prev;\n }\n /* Insert s as second element in the list */\n s->next = ty->next;\n if (ty->next) ty->next->prev = s;\n ty->next = s;\n s->prev = ty;\n return s;\n }\n s = s->next;\n } while (s && (s != ty->next));\n return 0;\n}\n\n/*\n Cast a pointer up an inheritance hierarchy\n*/\nSWIGRUNTIMEINLINE void *\nSWIG_TypeCast(swig_type_info *ty, void *ptr) {\n return ((!ty) || (!ty->converter)) ? ptr : (*ty->converter)(ptr);\n}\n\n/* \n Dynamic pointer casting. Down an inheritance hierarchy\n*/\nSWIGRUNTIME swig_type_info *\nSWIG_TypeDynamicCast(swig_type_info *ty, void **ptr) {\n swig_type_info *lastty = ty;\n if (!ty || !ty->dcast) return ty;\n while (ty && (ty->dcast)) {\n ty = (*ty->dcast)(ptr);\n if (ty) lastty = ty;\n }\n return lastty;\n}\n\n/*\n Return the name associated with this type\n*/\nSWIGRUNTIMEINLINE const char *\nSWIG_TypeName(const swig_type_info *ty) {\n return ty->name;\n}\n\n/*\n Return the pretty name associated with this type,\n that is an unmangled type name in a form presentable to the user.\n*/\nSWIGRUNTIME const char *\nSWIG_TypePrettyName(const swig_type_info *type) {\n /* The \"str\" field contains the equivalent pretty names of the\n type, separated by vertical-bar characters. We choose\n to print the last name, as it is often (?) the most\n specific. */\n if (type->str != NULL) {\n const char *last_name = type->str;\n const char *s;\n for (s = type->str; *s; s++)\n if (*s == '|') last_name = s+1;\n return last_name;\n }\n else\n return type->name;\n}\n\n/*\n Search for a swig_type_info structure\n*/\nSWIGRUNTIME swig_type_info *\nSWIG_TypeQueryTL(swig_type_info *tl, const char *name) {\n swig_type_info *ty = tl;\n while (ty) {\n if (ty->str && (SWIG_TypeEquiv(ty->str,name))) return ty;\n if (ty->name && (strcmp(name,ty->name) == 0)) return ty;\n ty = ty->prev;\n }\n return 0;\n}\n\n/* \n Set the clientdata field for a type\n*/\nSWIGRUNTIME void\nSWIG_TypeClientDataTL(swig_type_info *tl, swig_type_info *ti, void *clientdata) {\n swig_type_info *tc, *equiv;\n if (ti->clientdata) return;\n /* if (ti->clientdata == clientdata) return; */\n ti->clientdata = clientdata;\n equiv = ti->next;\n while (equiv) {\n if (!equiv->converter) {\n tc = tl;\n while (tc) {\n if ((strcmp(tc->name, equiv->name) == 0))\n SWIG_TypeClientDataTL(tl,tc,clientdata);\n tc = tc->prev;\n }\n }\n equiv = equiv->next;\n }\n}\n\n/* \n Pack binary data into a string\n*/\nSWIGRUNTIME char *\nSWIG_PackData(char *c, void *ptr, size_t sz) {\n static char hex[17] = \"0123456789abcdef\";\n unsigned char *u = (unsigned char *) ptr;\n const unsigned char *eu = u + sz;\n register unsigned char uu;\n for (; u != eu; ++u) {\n uu = *u;\n *(c++) = hex[(uu & 0xf0) >> 4];\n *(c++) = hex[uu & 0xf];\n }\n return c;\n}\n\n/* \n Unpack binary data from a string\n*/\nSWIGRUNTIME const char *\nSWIG_UnpackData(const char *c, void *ptr, size_t sz) {\n register unsigned char *u = (unsigned char *) ptr;\n register const unsigned char *eu = u + sz;\n for (; u != eu; ++u) {\n register int d = *(c++);\n register unsigned char uu = 0;\n if ((d >= '0') && (d <= '9'))\n uu = ((d - '0') << 4);\n else if ((d >= 'a') && (d <= 'f'))\n uu = ((d - ('a'-10)) << 4);\n else \n return (char *) 0;\n d = *(c++);\n if ((d >= '0') && (d <= '9'))\n uu |= (d - '0');\n else if ((d >= 'a') && (d <= 'f'))\n uu |= (d - ('a'-10));\n else \n return (char *) 0;\n *u = uu;\n }\n return c;\n}\n\n/*\n This function will propagate the clientdata field of type to any new\n swig_type_info structures that have been added into the list of\n equivalent types. It is like calling SWIG_TypeClientData(type,\n clientdata) a second time.\n*/\nSWIGRUNTIME void\nSWIG_PropagateClientDataTL(swig_type_info *tl, swig_type_info *type) {\n swig_type_info *equiv = type->next;\n swig_type_info *tc;\n if (!type->clientdata) return;\n while (equiv) {\n if (!equiv->converter) {\n tc = tl;\n while (tc) {\n if ((strcmp(tc->name, equiv->name) == 0) && !tc->clientdata)\n SWIG_TypeClientDataTL(tl,tc, type->clientdata);\n tc = tc->prev;\n }\n }\n equiv = equiv->next;\n }\n}\n\n/* \n Pack 'void *' into a string buffer.\n*/\nSWIGRUNTIME char *\nSWIG_PackVoidPtr(char *buff, void *ptr, const char *name, size_t bsz) {\n char *r = buff;\n if ((2*sizeof(void *) + 2) > bsz) return 0;\n *(r++) = '_';\n r = SWIG_PackData(r,&ptr,sizeof(void *));\n if (strlen(name) + 1 > (bsz - (r - buff))) return 0;\n strcpy(r,name);\n return buff;\n}\n\nSWIGRUNTIME const char *\nSWIG_UnpackVoidPtr(const char *c, void **ptr, const char *name) {\n if (*c != '_') {\n if (strcmp(c,\"NULL\") == 0) {\n *ptr = (void *) 0;\n return name;\n } else {\n return 0;\n }\n }\n return SWIG_UnpackData(++c,ptr,sizeof(void *));\n}\n\nSWIGRUNTIME char *\nSWIG_PackDataName(char *buff, void *ptr, size_t sz, const char *name, size_t bsz) {\n char *r = buff;\n size_t lname = (name ? strlen(name) : 0);\n if ((2*sz + 2 + lname) > bsz) return 0;\n *(r++) = '_';\n r = SWIG_PackData(r,ptr,sz);\n if (lname) {\n strncpy(r,name,lname+1);\n } else {\n *r = 0;\n }\n return buff;\n}\n\nSWIGRUNTIME const char *\nSWIG_UnpackDataName(const char *c, void *ptr, size_t sz, const char *name) {\n if (*c != '_') {\n if (strcmp(c,\"NULL\") == 0) {\n memset(ptr,0,sz);\n return name;\n } else {\n return 0;\n }\n }\n return SWIG_UnpackData(++c,ptr,sz);\n}\n\n#ifdef __cplusplus\n}\n#endif\n\n/***********************************************************************\n * pyrun.swg\n *\n * This file contains the runtime support for Python modules\n * and includes code for managing global variables and pointer\n * type checking.\n *\n * Author : David Beazley (beazley@cs.uchicago.edu)\n ************************************************************************/\n\n/* Common SWIG API */\n#define SWIG_ConvertPtr(obj, pp, type, flags) SWIG_Python_ConvertPtr(obj, pp, type, flags)\n#define SWIG_NewPointerObj(p, type, flags) SWIG_Python_NewPointerObj(p, type, flags)\n#define SWIG_MustGetPtr(p, type, argnum, flags) SWIG_Python_MustGetPtr(p, type, argnum, flags)\n \n\n/* Python-specific SWIG API */\n#define SWIG_ConvertPacked(obj, ptr, sz, ty, flags) SWIG_Python_ConvertPacked(obj, ptr, sz, ty, flags)\n#define SWIG_NewPackedObj(ptr, sz, type) SWIG_Python_NewPackedObj(ptr, sz, type)\n\n\n/* -----------------------------------------------------------------------------\n * Pointer declarations\n * ----------------------------------------------------------------------------- */\n/*\n Use SWIG_NO_COBJECT_TYPES to force the use of strings to represent\n C/C++ pointers in the python side. Very useful for debugging, but\n not always safe.\n*/\n#if !defined(SWIG_NO_COBJECT_TYPES) && !defined(SWIG_COBJECT_TYPES)\n# define SWIG_COBJECT_TYPES\n#endif\n\n/* Flags for pointer conversion */\n#define SWIG_POINTER_EXCEPTION 0x1\n#define SWIG_POINTER_DISOWN 0x2\n\n\n#ifdef __cplusplus\nextern \"C\" {\n#endif\n\n/* -----------------------------------------------------------------------------\n * Create a new pointer string \n * ----------------------------------------------------------------------------- */\n\n#ifndef SWIG_BUFFER_SIZE\n#define SWIG_BUFFER_SIZE 1024\n#endif\n\n#if defined(SWIG_COBJECT_TYPES)\n#if !defined(SWIG_COBJECT_PYTHON)\n/* -----------------------------------------------------------------------------\n * Implements a simple Swig Object type, and use it instead of PyCObject\n * ----------------------------------------------------------------------------- */\n\ntypedef struct {\n PyObject_HEAD\n void *ptr;\n const char *desc;\n} PySwigObject;\n\n/* Declarations for objects of type PySwigObject */\n\nSWIGRUNTIME int\nPySwigObject_print(PySwigObject *v, FILE *fp, int flags)\n{\n char result[SWIG_BUFFER_SIZE];\n if (SWIG_PackVoidPtr(result, v->ptr, v->desc, sizeof(result))) {\n fputs(\"\", fp);\n return 0; \n } else {\n return 1; \n }\n}\n \nSWIGRUNTIME PyObject *\nPySwigObject_repr(PySwigObject *v)\n{\n char result[SWIG_BUFFER_SIZE];\n return SWIG_PackVoidPtr(result, v->ptr, v->desc, sizeof(result)) ?\n PyString_FromFormat(\"\", result) : 0;\n}\n\nSWIGRUNTIME PyObject *\nPySwigObject_str(PySwigObject *v)\n{\n char result[SWIG_BUFFER_SIZE];\n return SWIG_PackVoidPtr(result, v->ptr, v->desc, sizeof(result)) ?\n PyString_FromString(result) : 0;\n}\n\nSWIGRUNTIME PyObject *\nPySwigObject_long(PySwigObject *v)\n{\n return PyLong_FromUnsignedLong((unsigned long) v->ptr);\n}\n\nSWIGRUNTIME PyObject *\nPySwigObject_oct(PySwigObject *v)\n{\n char buf[100];\n unsigned long x = (unsigned long)v->ptr;\n if (x == 0)\n strcpy(buf, \"0\");\n else\n PyOS_snprintf(buf, sizeof(buf), \"0%lo\", x);\n return PyString_FromString(buf);\n}\n\nSWIGRUNTIME PyObject *\nPySwigObject_hex(PySwigObject *v)\n{\n char buf[100];\n PyOS_snprintf(buf, sizeof(buf), \"0x%lx\", (unsigned long)v->ptr);\n return PyString_FromString(buf);\n}\n\nSWIGRUNTIME int\nPySwigObject_compare(PySwigObject *v, PySwigObject *w)\n{\n int c = strcmp(v->desc, w->desc);\n if (c) {\n return c;\n } else {\n void *i = v->ptr;\n void *j = w->ptr;\n return (i < j) ? -1 : (i > j) ? 1 : 0;\n }\n}\n\nSWIGRUNTIME void\nPySwigObject_dealloc(PySwigObject *self)\n{\n PyObject_DEL(self);\n}\n\nSWIGRUNTIME PyTypeObject*\nPySwigObject_GetType() {\n static char PySwigObject_Type__doc__[] = \n \"Swig object carries a C/C++ instance pointer\";\n \n static PyNumberMethods PySwigObject_as_number = {\n (binaryfunc)0, /*nb_add*/\n (binaryfunc)0, /*nb_subtract*/\n (binaryfunc)0, /*nb_multiply*/\n (binaryfunc)0, /*nb_divide*/\n (binaryfunc)0, /*nb_remainder*/\n (binaryfunc)0, /*nb_divmod*/\n (ternaryfunc)0,/*nb_power*/\n (unaryfunc)0, /*nb_negative*/\n (unaryfunc)0, /*nb_positive*/\n (unaryfunc)0, /*nb_absolute*/\n (inquiry)0, /*nb_nonzero*/\n 0,\t\t /*nb_invert*/\n 0,\t\t /*nb_lshift*/\n 0,\t\t /*nb_rshift*/\n 0,\t\t /*nb_and*/\n 0,\t\t /*nb_xor*/\n 0,\t\t /*nb_or*/\n (coercion)0, /*nb_coerce*/\n (unaryfunc)PySwigObject_long, /*nb_int*/\n (unaryfunc)PySwigObject_long, /*nb_long*/\n (unaryfunc)0, /*nb_float*/\n (unaryfunc)PySwigObject_oct, /*nb_oct*/\n (unaryfunc)PySwigObject_hex, /*nb_hex*/\n#if PY_VERSION_HEX >= 0x02000000\n 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0 /* nb_inplace_add -> nb_inplace_true_divide */ \n#endif\n };\n\n static PyTypeObject PySwigObject_Type = {\n PyObject_HEAD_INIT(&PyType_Type)\n 0,\t\t\t\t\t/*ob_size*/\n \"PySwigObject\",\t\t\t/*tp_name*/\n sizeof(PySwigObject),\t\t/*tp_basicsize*/\n 0,\t\t\t\t\t/*tp_itemsize*/\n /* methods */\n (destructor)PySwigObject_dealloc,\t/*tp_dealloc*/\n (printfunc)PySwigObject_print,\t/*tp_print*/\n (getattrfunc)0,\t\t\t/*tp_getattr*/\n (setattrfunc)0,\t\t\t/*tp_setattr*/\n (cmpfunc)PySwigObject_compare,\t/*tp_compare*/\n (reprfunc)PySwigObject_repr,\t/*tp_repr*/\n &PySwigObject_as_number,\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 (hashfunc)0,\t\t\t/*tp_hash*/\n (ternaryfunc)0,\t\t\t/*tp_call*/\n (reprfunc)PySwigObject_str,\t\t/*tp_str*/\n /* Space for future expansion */\n 0L,0L,0L,0L,\n PySwigObject_Type__doc__, \t /* Documentation string */\n#if PY_VERSION_HEX >= 0x02000000\n 0, /* tp_traverse */\n 0, /* tp_clear */\n#endif\n#if PY_VERSION_HEX >= 0x02010000\n 0, /* tp_richcompare */\n 0, /* tp_weaklistoffset */\n#endif\n#if PY_VERSION_HEX >= 0x02020000\n 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, /* tp_iter -> tp_weaklist */\n#endif\n#if PY_VERSION_HEX >= 0x02030000\n 0, /* tp_del */\n#endif\n#ifdef COUNT_ALLOCS\n 0,0,0,0 /* tp_alloc -> tp_next */\n#endif\n };\n\n return &PySwigObject_Type;\n}\n\nSWIGRUNTIME PyObject *\nPySwigObject_FromVoidPtrAndDesc(void *ptr, const char *desc)\n{\n PySwigObject *self = PyObject_NEW(PySwigObject, PySwigObject_GetType());\n if (self == NULL) return NULL;\n self->ptr = ptr;\n self->desc = desc;\n return (PyObject *)self;\n}\n\nSWIGRUNTIMEINLINE void *\nPySwigObject_AsVoidPtr(PyObject *self)\n{\n return ((PySwigObject *)self)->ptr;\n}\n\nSWIGRUNTIMEINLINE const char *\nPySwigObject_GetDesc(PyObject *self)\n{\n return ((PySwigObject *)self)->desc;\n}\n\nSWIGRUNTIMEINLINE int\nPySwigObject_Check(PyObject *op) {\n return ((op)->ob_type == PySwigObject_GetType()) \n || (strcmp((op)->ob_type->tp_name,\"PySwigObject\") == 0);\n}\n\n/* -----------------------------------------------------------------------------\n * Implements a simple Swig Packed type, and use it instead of string\n * ----------------------------------------------------------------------------- */\n\ntypedef struct {\n PyObject_HEAD\n void *pack;\n const char *desc;\n size_t size;\n} PySwigPacked;\n\nSWIGRUNTIME int\nPySwigPacked_print(PySwigPacked *v, FILE *fp, int flags)\n{\n char result[SWIG_BUFFER_SIZE];\n fputs(\"pack, v->size, 0, sizeof(result))) {\n fputs(\"at \", fp); \n fputs(result, fp); \n }\n fputs(v->desc,fp); \n fputs(\">\", fp);\n return 0; \n}\n \nSWIGRUNTIME PyObject *\nPySwigPacked_repr(PySwigPacked *v)\n{\n char result[SWIG_BUFFER_SIZE];\n if (SWIG_PackDataName(result, v->pack, v->size, 0, sizeof(result))) {\n return PyString_FromFormat(\"\", result, v->desc);\n } else {\n return PyString_FromFormat(\"\", v->desc);\n } \n}\n\nSWIGRUNTIME PyObject *\nPySwigPacked_str(PySwigPacked *v)\n{\n char result[SWIG_BUFFER_SIZE];\n if (SWIG_PackDataName(result, v->pack, v->size, 0, sizeof(result))){\n return PyString_FromFormat(\"%s%s\", result, v->desc);\n } else {\n return PyString_FromFormat(\"%s\", v->desc);\n } \n}\n\nSWIGRUNTIME int\nPySwigPacked_compare(PySwigPacked *v, PySwigPacked *w)\n{\n int c = strcmp(v->desc, w->desc);\n if (c) {\n return c;\n } else {\n size_t i = v->size;\n size_t j = w->size;\n int s = (i < j) ? -1 : (i > j) ? 1 : 0;\n return s ? s : strncmp((char *)v->pack, (char *)w->pack, 2*v->size);\n }\n}\n\nSWIGRUNTIME void\nPySwigPacked_dealloc(PySwigPacked *self)\n{\n free(self->pack);\n PyObject_DEL(self);\n}\n\nSWIGRUNTIME PyTypeObject*\nPySwigPacked_GetType() {\n static char PySwigPacked_Type__doc__[] = \n \"Swig object carries a C/C++ instance pointer\";\n \n static PyTypeObject PySwigPacked_Type = {\n PyObject_HEAD_INIT(&PyType_Type)\n 0,\t\t\t\t\t/*ob_size*/\n \"PySwigPacked\",\t\t\t/*tp_name*/\n sizeof(PySwigPacked),\t\t/*tp_basicsize*/\n 0,\t\t\t\t\t/*tp_itemsize*/\n /* methods */\n (destructor)PySwigPacked_dealloc,\t/*tp_dealloc*/\n (printfunc)PySwigPacked_print,\t/*tp_print*/\n (getattrfunc)0,\t\t\t/*tp_getattr*/\n (setattrfunc)0,\t\t\t/*tp_setattr*/\n (cmpfunc)PySwigPacked_compare,\t/*tp_compare*/\n (reprfunc)PySwigPacked_repr,\t/*tp_repr*/\n 0,\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 (hashfunc)0,\t\t\t/*tp_hash*/\n (ternaryfunc)0,\t\t\t/*tp_call*/\n (reprfunc)PySwigPacked_str,\t\t/*tp_str*/\n /* Space for future expansion */\n 0L,0L,0L,0L,\n PySwigPacked_Type__doc__, \t /* Documentation string */\n#if PY_VERSION_HEX >= 0x02000000\n 0, /* tp_traverse */\n 0, /* tp_clear */\n#endif\n#if PY_VERSION_HEX >= 0x02010000\n 0, /* tp_richcompare */\n 0, /* tp_weaklistoffset */\n#endif\n#if PY_VERSION_HEX >= 0x02020000 \n 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, /* tp_iter -> tp_weaklist */\n#endif\n#if PY_VERSION_HEX >= 0x02030000\n 0, /* tp_del */\n#endif\n#ifdef COUNT_ALLOCS\n 0,0,0,0 /* tp_alloc -> tp_next */\n#endif\n };\n\n return &PySwigPacked_Type;\n}\n\nSWIGRUNTIME PyObject *\nPySwigPacked_FromDataAndDesc(void *ptr, size_t size, const char *desc)\n{\n PySwigPacked *self = PyObject_NEW(PySwigPacked, PySwigPacked_GetType());\n if (self == NULL) {\n return NULL;\n } else {\n void *pack = malloc(size);\n memcpy(pack, ptr, size);\n self->pack = pack;\n self->desc = desc;\n self->size = size;\n return (PyObject *) self;\n }\n}\n\nSWIGRUNTIMEINLINE const char *\nPySwigPacked_UnpackData(PyObject *obj, void *ptr, size_t size)\n{\n PySwigPacked *self = (PySwigPacked *)obj;\n if (self->size != size) return 0;\n memcpy(ptr, self->pack, size);\n return self->desc;\n}\n\nSWIGRUNTIMEINLINE const char *\nPySwigPacked_GetDesc(PyObject *self)\n{\n return ((PySwigPacked *)self)->desc;\n}\n\nSWIGRUNTIMEINLINE int\nPySwigPacked_Check(PyObject *op) {\n return ((op)->ob_type == PySwigPacked_GetType()) \n || (strcmp((op)->ob_type->tp_name,\"PySwigPacked\") == 0);\n}\n\n#else\n/* -----------------------------------------------------------------------------\n * Use the old Python PyCObject instead of PySwigObject\n * ----------------------------------------------------------------------------- */\n\n#define PySwigObject_GetDesc(obj)\t PyCObject_GetDesc(obj)\n#define PySwigObject_Check(obj)\t PyCObject_Check(obj)\n#define PySwigObject_AsVoidPtr(obj)\t PyCObject_AsVoidPtr(obj)\n#define PySwigObject_FromVoidPtrAndDesc(p, d) PyCObject_FromVoidPtrAndDesc(p, d, NULL)\n\n#endif\n\n#endif\n\n/* -----------------------------------------------------------------------------\n * errors manipulation\n * ----------------------------------------------------------------------------- */\n\nSWIGRUNTIME void\nSWIG_Python_TypeError(const char *type, PyObject *obj)\n{\n if (type) {\n#if defined(SWIG_COBJECT_TYPES)\n if (PySwigObject_Check(obj)) {\n const char *otype = (const char *) PySwigObject_GetDesc(obj);\n if (otype) {\n\tPyErr_Format(PyExc_TypeError, \"a '%s' is expected, 'PySwigObject(%s)' is received\",\n\t\t type, otype);\n\treturn;\n }\n } else \n#endif \n {\n const char *otype = (obj ? obj->ob_type->tp_name : 0); \n if (otype) {\n\tPyObject *str = PyObject_Str(obj);\n\tconst char *cstr = str ? PyString_AsString(str) : 0;\n\tif (cstr) {\n\t PyErr_Format(PyExc_TypeError, \"a '%s' is expected, '%s(%s)' is received\",\n\t\t type, otype, cstr);\n\t} else {\n\t PyErr_Format(PyExc_TypeError, \"a '%s' is expected, '%s' is received\",\n\t\t type, otype);\n\t}\n\tPy_DECREF(str);\n\treturn;\n }\n } \n PyErr_Format(PyExc_TypeError, \"a '%s' is expected\", type);\n } else {\n PyErr_Format(PyExc_TypeError, \"unexpected type is received\");\n }\n}\n\nSWIGRUNTIMEINLINE void\nSWIG_Python_NullRef(const char *type)\n{\n if (type) {\n PyErr_Format(PyExc_TypeError, \"null reference of type '%s' was received\",type);\n } else {\n PyErr_Format(PyExc_TypeError, \"null reference was received\");\n }\n}\n\nSWIGRUNTIME int\nSWIG_Python_AddErrMesg(const char* mesg, int infront)\n{\n if (PyErr_Occurred()) {\n PyObject *type = 0;\n PyObject *value = 0;\n PyObject *traceback = 0;\n PyErr_Fetch(&type, &value, &traceback);\n if (value) {\n PyObject *old_str = PyObject_Str(value);\n Py_XINCREF(type);\n PyErr_Clear();\n if (infront) {\n\tPyErr_Format(type, \"%s %s\", mesg, PyString_AsString(old_str));\n } else {\n\tPyErr_Format(type, \"%s %s\", PyString_AsString(old_str), mesg);\n }\n Py_DECREF(old_str);\n }\n return 1;\n } else {\n return 0;\n }\n}\n\nSWIGRUNTIME int\nSWIG_Python_ArgFail(int argnum)\n{\n if (PyErr_Occurred()) {\n /* add information about failing argument */\n char mesg[256];\n sprintf(mesg, \"argument number %d:\", argnum);\n return SWIG_Python_AddErrMesg(mesg, 1);\n } else {\n return 0;\n }\n}\n\n\n/* -----------------------------------------------------------------------------\n * pointers/data manipulation\n * ----------------------------------------------------------------------------- */\n\n/* Convert a pointer value */\nSWIGRUNTIME int\nSWIG_Python_ConvertPtr(PyObject *obj, void **ptr, swig_type_info *ty, int flags) {\n swig_type_info *tc;\n const char *c = 0;\n static PyObject *SWIG_this = 0;\n int newref = 0;\n PyObject *pyobj = 0;\n void *vptr;\n \n if (!obj) return 0;\n if (obj == Py_None) {\n *ptr = 0;\n return 0;\n }\n\n#ifdef SWIG_COBJECT_TYPES\n if (!(PySwigObject_Check(obj))) {\n if (!SWIG_this)\n SWIG_this = PyString_FromString(\"this\");\n pyobj = obj;\n obj = PyObject_GetAttr(obj,SWIG_this);\n newref = 1;\n if (!obj) goto type_error;\n if (!PySwigObject_Check(obj)) {\n Py_DECREF(obj);\n goto type_error;\n }\n } \n vptr = PySwigObject_AsVoidPtr(obj);\n c = (const char *) PySwigObject_GetDesc(obj);\n if (newref) { Py_DECREF(obj); }\n goto type_check;\n#else\n if (!(PyString_Check(obj))) {\n if (!SWIG_this)\n SWIG_this = PyString_FromString(\"this\");\n pyobj = obj;\n obj = PyObject_GetAttr(obj,SWIG_this);\n newref = 1;\n if (!obj) goto type_error;\n if (!PyString_Check(obj)) {\n Py_DECREF(obj);\n goto type_error;\n }\n } \n c = PyString_AS_STRING(obj);\n /* Pointer values must start with leading underscore */\n c = SWIG_UnpackVoidPtr(c, &vptr, ty->name);\n if (newref) { Py_DECREF(obj); }\n if (!c) goto type_error;\n#endif\n\ntype_check:\n\n if (ty) {\n tc = SWIG_TypeCheck(c,ty);\n if (!tc) goto type_error;\n *ptr = SWIG_TypeCast(tc,vptr);\n }\n\n if ((pyobj) && (flags & SWIG_POINTER_DISOWN)) {\n PyObject_SetAttrString(pyobj,(char*)\"thisown\",Py_False);\n }\n return 0;\n\ntype_error:\n PyErr_Clear();\n if (pyobj && !obj) { \n obj = pyobj;\n if (PyCFunction_Check(obj)) {\n /* here we get the method pointer for callbacks */\n char *doc = (((PyCFunctionObject *)obj) -> m_ml -> ml_doc);\n c = doc ? strstr(doc, \"swig_ptr: \") : 0;\n if (c) {\n\tc = SWIG_UnpackVoidPtr(c + 10, &vptr, ty->name);\n\tif (!c) goto type_error;\n\tgoto type_check;\n }\n }\n }\n if (flags & SWIG_POINTER_EXCEPTION) {\n if (ty) {\n SWIG_Python_TypeError(SWIG_TypePrettyName(ty), obj);\n } else {\n SWIG_Python_TypeError(\"C/C++ pointer\", obj);\n }\n }\n return -1;\n}\n\n/* Convert a pointer value, signal an exception on a type mismatch */\nSWIGRUNTIME void *\nSWIG_Python_MustGetPtr(PyObject *obj, swig_type_info *ty, int argnum, int flags) {\n void *result;\n if (SWIG_Python_ConvertPtr(obj, &result, ty, flags) == -1) {\n PyErr_Clear();\n if (flags & SWIG_POINTER_EXCEPTION) {\n SWIG_Python_TypeError(SWIG_TypePrettyName(ty), obj);\n SWIG_Python_ArgFail(argnum);\n }\n }\n return result;\n}\n\n/* Convert a packed value value */\nSWIGRUNTIME int\nSWIG_Python_ConvertPacked(PyObject *obj, void *ptr, size_t sz, swig_type_info *ty, int flags) {\n swig_type_info *tc;\n const char *c = 0;\n\n#if defined(SWIG_COBJECT_TYPES) && !defined(SWIG_COBJECT_PYTHON)\n c = PySwigPacked_UnpackData(obj, ptr, sz);\n#else\n if ((!obj) || (!PyString_Check(obj))) goto type_error;\n c = PyString_AS_STRING(obj);\n /* Pointer values must start with leading underscore */\n c = SWIG_UnpackDataName(c, ptr, sz, ty->name);\n#endif\n if (!c) goto type_error;\n if (ty) {\n tc = SWIG_TypeCheck(c,ty);\n if (!tc) goto type_error;\n }\n return 0;\n\ntype_error:\n PyErr_Clear();\n if (flags & SWIG_POINTER_EXCEPTION) {\n if (ty) {\n SWIG_Python_TypeError(SWIG_TypePrettyName(ty), obj);\n } else {\n SWIG_Python_TypeError(\"C/C++ packed data\", obj);\n }\n }\n return -1;\n} \n\n/* Create a new array object */\nSWIGRUNTIME PyObject *\nSWIG_Python_NewPointerObj(void *ptr, swig_type_info *type, int own) {\n PyObject *robj = 0;\n if (!ptr) {\n Py_INCREF(Py_None);\n return Py_None;\n }\n#ifdef SWIG_COBJECT_TYPES\n robj = PySwigObject_FromVoidPtrAndDesc((void *) ptr, (char *)type->name);\n#else\n {\n char result[SWIG_BUFFER_SIZE];\n robj = SWIG_PackVoidPtr(result, ptr, type->name, sizeof(result)) ?\n PyString_FromString(result) : 0;\n }\n#endif\n if (!robj || (robj == Py_None)) return robj;\n if (type->clientdata) {\n PyObject *inst;\n PyObject *args = Py_BuildValue((char*)\"(O)\", robj);\n Py_DECREF(robj);\n inst = PyObject_CallObject((PyObject *) type->clientdata, args);\n Py_DECREF(args);\n if (inst) {\n if (own) {\n PyObject_SetAttrString(inst,(char*)\"thisown\",Py_True);\n }\n robj = inst;\n }\n }\n return robj;\n}\n\nSWIGRUNTIME PyObject *\nSWIG_Python_NewPackedObj(void *ptr, size_t sz, swig_type_info *type) {\n PyObject *robj = 0;\n if (!ptr) {\n Py_INCREF(Py_None);\n return Py_None;\n }\n#if defined(SWIG_COBJECT_TYPES) && !defined(SWIG_COBJECT_PYTHON)\n robj = PySwigPacked_FromDataAndDesc((void *) ptr, sz, (char *)type->name);\n#else\n {\n char result[SWIG_BUFFER_SIZE];\n robj = SWIG_PackDataName(result, ptr, sz, type->name, sizeof(result)) ?\n PyString_FromString(result) : 0;\n }\n#endif\n return robj;\n}\n\n/* -----------------------------------------------------------------------------*\n * Get type list \n * -----------------------------------------------------------------------------*/\n\n#ifdef SWIG_LINK_RUNTIME\nvoid *SWIG_ReturnGlobalTypeList(void *);\n#endif\n\nSWIGRUNTIME swig_type_info **\nSWIG_Python_GetTypeListHandle() {\n static void *type_pointer = (void *)0;\n /* first check if module already created */\n if (!type_pointer) {\n#ifdef SWIG_LINK_RUNTIME\n type_pointer = SWIG_ReturnGlobalTypeList((void *)0);\n#else\n type_pointer = PyCObject_Import((char*)\"swig_runtime_data\" SWIG_RUNTIME_VERSION,\n\t\t\t\t (char*)\"type_pointer\" SWIG_TYPE_TABLE_NAME);\n if (PyErr_Occurred()) {\n PyErr_Clear();\n type_pointer = (void *)0;\n }\n }\n#endif\n return (swig_type_info **) type_pointer;\n}\n\n/*\n Search for a swig_type_info structure\n */\nSWIGRUNTIMEINLINE swig_type_info *\nSWIG_Python_GetTypeList() {\n swig_type_info **tlh = SWIG_Python_GetTypeListHandle();\n return tlh ? *tlh : (swig_type_info*)0;\n}\n\n#define SWIG_Runtime_GetTypeList SWIG_Python_GetTypeList \n\n#ifdef __cplusplus\n}\n#endif\n\n/* -----------------------------------------------------------------------------*\n Standard SWIG API for use inside user code.\n \n You need to include in your code as follow:\n\n#include // or using your favorite language \n#include \n#include // or using your favorite language \n#include \n \n * -----------------------------------------------------------------------------*/\n\nSWIGRUNTIMEINLINE swig_type_info *\nSWIG_Runtime_TypeQuery(const char *name) {\n swig_type_info *tl = SWIG_Runtime_GetTypeList();\n return SWIG_TypeQueryTL(tl, name);\n}\n\nSWIGRUNTIMEINLINE swig_type_info *\nSWIG_Runtime_TypeRegister(swig_type_info *ti) {\n swig_type_info *tl = SWIG_Runtime_GetTypeList();\n return SWIG_TypeRegisterTL(&tl, ti);\n}\n\nSWIGRUNTIMEINLINE void\nSWIG_Runtime_TypeClientData(swig_type_info *ti, void *clientdata) {\n swig_type_info *tl = SWIG_Runtime_GetTypeList();\n SWIG_TypeClientDataTL(tl, ti, clientdata);\n}\n\nSWIGRUNTIMEINLINE void\nSWIG_Runtime_PropagateClientData(swig_type_info *type) {\n swig_type_info *tl = SWIG_Runtime_GetTypeList();\n SWIG_PropagateClientDataTL(tl, type);\n}\n\n#define SWIG_GetTypeList() SWIG_Runtime_GetTypeList()\n#define SWIG_TypeQuery(name) SWIG_Runtime_TypeQuery(name)\n#define SWIG_TypeRegister(ti) SWIG_Runtime_TypeRegister(ti)\n#define SWIG_TypeClientData(ti, cd) SWIG_Runtime_TypeClientData(ti, cd)\n#define SWIG_PropagateClientData(ti) SWIG_Runtime_PropagateClientData(ti)\n\n\"\"\"\n", "source_code_before": "# This code allows one to use SWIG wrapped objects from weave. This\n# code is specific to SWIG-1.3 and above where things are different.\n# The code is basically all copied out from the SWIG wrapper code but\n# it has been hand edited for brevity.\n#\n# Prabhu Ramachandran \n\nswigptr2_code = \"\"\"\n\n#include \"Python.h\"\n\n/*************************************************************** -*- c -*-\n * python/precommon.swg\n *\n * Rename all exported symbols from common.swg, to avoid symbol\n * clashes if multiple interpreters are included\n *\n ************************************************************************/\n\n#define SWIG_TypeCheck SWIG_Python_TypeCheck\n#define SWIG_TypeCast SWIG_Python_TypeCast\n#define SWIG_TypeName SWIG_Python_TypeName\n#define SWIG_TypeQuery SWIG_Python_TypeQuery\n#define SWIG_PackData SWIG_Python_PackData \n#define SWIG_UnpackData SWIG_Python_UnpackData \n\n\n/***********************************************************************\n * common.swg\n *\n * This file contains generic SWIG runtime support for pointer\n * type checking as well as a few commonly used macros to control\n * external linkage.\n *\n * Author : David Beazley (beazley@cs.uchicago.edu)\n *\n * Copyright (c) 1999-2000, The University of Chicago\n * \n * This file may be freely redistributed without license or fee provided\n * this copyright message remains intact.\n ************************************************************************/\n\n#include \n\n#if defined(_WIN32) || defined(__WIN32__) || defined(__CYGWIN__)\n# if defined(_MSC_VER) || defined(__GNUC__)\n# if defined(STATIC_LINKED)\n# define SWIGEXPORT(a) a\n# define SWIGIMPORT(a) extern a\n# else\n# define SWIGEXPORT(a) __declspec(dllexport) a\n# define SWIGIMPORT(a) extern a\n# endif\n# else\n# if defined(__BORLANDC__)\n# define SWIGEXPORT(a) a _export\n# define SWIGIMPORT(a) a _export\n# else\n# define SWIGEXPORT(a) a\n# define SWIGIMPORT(a) a\n# endif\n# endif\n#else\n# define SWIGEXPORT(a) a\n# define SWIGIMPORT(a) a\n#endif\n\n#ifdef SWIG_GLOBAL\n# define SWIGRUNTIME(a) SWIGEXPORT(a)\n#else\n# define SWIGRUNTIME(a) static a\n#endif\n\n#ifdef __cplusplus\nextern \"C\" {\n#endif\n\ntypedef void *(*swig_converter_func)(void *);\ntypedef struct swig_type_info *(*swig_dycast_func)(void **);\n\ntypedef struct swig_type_info {\n const char *name;\n swig_converter_func converter;\n const char *str;\n void *clientdata;\n swig_dycast_func dcast;\n struct swig_type_info *next;\n struct swig_type_info *prev;\n} swig_type_info;\n\n#ifdef SWIG_NOINCLUDE\n\nSWIGIMPORT(swig_type_info *) SWIG_TypeCheck(char *c, swig_type_info *);\nSWIGIMPORT(void *) SWIG_TypeCast(swig_type_info *, void *);\nSWIGIMPORT(const char *) SWIG_TypeName(const swig_type_info *);\nSWIGIMPORT(swig_type_info *) SWIG_TypeQuery(const char *);\nSWIGIMPORT(char *) SWIG_PackData(char *, void *, int);\nSWIGIMPORT(char *) SWIG_UnpackData(char *, void *, int);\n\n#else\n\nstatic swig_type_info *swig_type_list = 0;\n\n/* Check the typename */\nSWIGRUNTIME(swig_type_info *) \nSWIG_TypeCheck(char *c, swig_type_info *ty) {\n swig_type_info *s;\n if (!ty) return 0; /* Void pointer */\n s = ty->next; /* First element always just a name */\n do {\n if (strcmp(s->name,c) == 0) {\n if (s == ty->next) return s;\n /* Move s to the top of the linked list */\n s->prev->next = s->next;\n if (s->next) {\n s->next->prev = s->prev;\n }\n /* Insert s as second element in the list */\n s->next = ty->next;\n if (ty->next) ty->next->prev = s;\n ty->next = s;\n s->prev = ty;\n return s;\n }\n s = s->next;\n } while (s && (s != ty->next));\n return 0;\n}\n\n/* Cast a pointer up an inheritance hierarchy */\nSWIGRUNTIME(void *) \nSWIG_TypeCast(swig_type_info *ty, void *ptr) {\n if ((!ty) || (!ty->converter)) return ptr;\n return (*ty->converter)(ptr);\n}\n\n/* Return the name associated with this type */\nSWIGRUNTIME(const char *)\nSWIG_TypeName(const swig_type_info *ty) {\n return ty->name;\n}\n\n/* \n Compare two type names skipping the space characters, therefore\n \"char*\" == \"char *\" and \"Class\" == \"Class\", etc.\n\n Return 0 when the two name types are equivalent, as in\n strncmp, but skipping ' '.\n*/\nstatic int\nSWIG_TypeNameComp(const char *f1, const char *l1,\n\t\t const char *f2, const char *l2) {\n for (;(f1 != l1) && (f2 != l2); ++f1, ++f2) {\n while ((*f1 == ' ') && (f1 != l1)) ++f1;\n while ((*f2 == ' ') && (f2 != l2)) ++f2;\n if (*f1 != *f2) return *f1 - *f2;\n }\n return (l1 - f1) - (l2 - f2);\n}\n\n/*\n Check type equivalence in a name list like ||...\n*/\nstatic int\nSWIG_TypeEquiv(const char *nb, const char *tb) {\n int equiv = 0;\n const char* te = tb + strlen(tb);\n const char* ne = nb;\n while (!equiv && *ne) {\n for (nb = ne; *ne; ++ne) {\n if (*ne == '|') break;\n }\n equiv = SWIG_TypeNameComp(nb, ne, tb, te) == 0;\n if (*ne) ++ne;\n }\n return equiv;\n}\n \n\n/* Search for a swig_type_info structure */\nSWIGRUNTIME(swig_type_info *)\nSWIG_TypeQuery(const char *name) {\n swig_type_info *ty = swig_type_list;\n while (ty) {\n if (ty->str && (SWIG_TypeEquiv(ty->str,name))) return ty;\n if (ty->name && (strcmp(name,ty->name) == 0)) return ty;\n ty = ty->prev;\n }\n return 0;\n}\n\n/* Pack binary data into a string */\nSWIGRUNTIME(char *)\nSWIG_PackData(char *c, void *ptr, int sz) {\n static char hex[17] = \"0123456789abcdef\";\n int i;\n unsigned char *u = (unsigned char *) ptr;\n register unsigned char uu;\n for (i = 0; i < sz; i++,u++) {\n uu = *u;\n *(c++) = hex[(uu & 0xf0) >> 4];\n *(c++) = hex[uu & 0xf];\n }\n return c;\n}\n\n/* Unpack binary data from a string */\nSWIGRUNTIME(char *)\nSWIG_UnpackData(char *c, void *ptr, int sz) {\n register unsigned char uu = 0;\n register int d;\n unsigned char *u = (unsigned char *) ptr;\n int i;\n for (i = 0; i < sz; i++, u++) {\n d = *(c++);\n if ((d >= '0') && (d <= '9'))\n uu = ((d - '0') << 4);\n else if ((d >= 'a') && (d <= 'f'))\n uu = ((d - ('a'-10)) << 4);\n d = *(c++);\n if ((d >= '0') && (d <= '9'))\n uu |= (d - '0');\n else if ((d >= 'a') && (d <= 'f'))\n uu |= (d - ('a'-10));\n *u = uu;\n }\n return c;\n}\n\n#endif\n\n#ifdef __cplusplus\n}\n#endif\n\n/***********************************************************************\n * python.swg\n *\n * This file contains the runtime support for Python modules\n * and includes code for managing global variables and pointer\n * type checking.\n *\n * Author : David Beazley (beazley@cs.uchicago.edu)\n ************************************************************************/\n\n#include \"Python.h\"\n\n#ifdef __cplusplus\nextern \"C\" {\n#endif\n\n#define SWIG_PY_INT 1\n#define SWIG_PY_FLOAT 2\n#define SWIG_PY_STRING 3\n#define SWIG_PY_POINTER 4\n#define SWIG_PY_BINARY 5\n\n/* Flags for pointer conversion */\n\n#define SWIG_POINTER_EXCEPTION 0x1\n#define SWIG_POINTER_DISOWN 0x2\n\n/* Exception handling in wrappers */\n#define SWIG_fail goto fail\n\n/* Constant information structure */\ntypedef struct swig_const_info {\n int type;\n char *name;\n long lvalue;\n double dvalue;\n void *pvalue;\n swig_type_info **ptype;\n} swig_const_info;\n\n/* Common SWIG API */\n#define SWIG_ConvertPtr(obj, pp, type, flags) \\\n SWIG_Python_ConvertPtr(obj, pp, type, flags)\n#define SWIG_NewPointerObj(p, type, flags) \\\n SWIG_Python_NewPointerObj(p, type, flags)\n#define SWIG_MustGetPtr(p, type, argnum, flags) \\\n SWIG_Python_MustGetPtr(p, type, argnum, flags)\n \n\ntypedef double (*py_objasdbl_conv)(PyObject *obj);\n\n#ifdef SWIG_NOINCLUDE\n\nSWIGIMPORT(int) SWIG_Python_ConvertPtr(PyObject *, void **, swig_type_info *, int);\nSWIGIMPORT(PyObject *) SWIG_Python_NewPointerObj(void *, swig_type_info *,int own);\nSWIGIMPORT(void *) SWIG_Python_MustGetPtr(PyObject *, swig_type_info *, int, int);\n\n#else\n\n\n/* Convert a pointer value */\nSWIGRUNTIME(int)\nSWIG_Python_ConvertPtr(PyObject *obj, void **ptr, swig_type_info *ty, int flags) {\n swig_type_info *tc;\n char *c = 0;\n static PyObject *SWIG_this = 0;\n int newref = 0;\n PyObject *pyobj = 0;\n\n if (!obj) return 0;\n if (obj == Py_None) {\n *ptr = 0;\n return 0;\n }\n#ifdef SWIG_COBJECT_TYPES\n if (!(PyCObject_Check(obj))) {\n if (!SWIG_this)\n SWIG_this = PyString_FromString(\"this\");\n pyobj = obj;\n obj = PyObject_GetAttr(obj,SWIG_this);\n newref = 1;\n if (!obj) goto type_error;\n if (!PyCObject_Check(obj)) {\n Py_DECREF(obj);\n goto type_error;\n }\n } \n *ptr = PyCObject_AsVoidPtr(obj);\n c = (char *) PyCObject_GetDesc(obj);\n if (newref) Py_DECREF(obj);\n goto cobject;\n#else\n if (!(PyString_Check(obj))) {\n if (!SWIG_this)\n SWIG_this = PyString_FromString(\"this\");\n pyobj = obj;\n obj = PyObject_GetAttr(obj,SWIG_this);\n newref = 1;\n if (!obj) goto type_error;\n if (!PyString_Check(obj)) {\n Py_DECREF(obj);\n goto type_error;\n }\n } \n c = PyString_AsString(obj);\n /* Pointer values must start with leading underscore */\n if (*c != '_') {\n *ptr = (void *) 0;\n if (strcmp(c,\"NULL\") == 0) {\n if (newref) { Py_DECREF(obj); }\n return 0;\n } else {\n if (newref) { Py_DECREF(obj); }\n goto type_error;\n }\n }\n c++;\n c = SWIG_UnpackData(c,ptr,sizeof(void *));\n if (newref) { Py_DECREF(obj); }\n#endif\n\n#ifdef SWIG_COBJECT_TYPES\ncobject:\n#endif\n\n if (ty) {\n tc = SWIG_TypeCheck(c,ty);\n if (!tc) goto type_error;\n *ptr = SWIG_TypeCast(tc,(void*) *ptr);\n }\n\n if ((pyobj) && (flags & SWIG_POINTER_DISOWN)) {\n PyObject *zero = PyInt_FromLong(0);\n PyObject_SetAttrString(pyobj,(char*)\"thisown\",zero);\n Py_DECREF(zero);\n }\n return 0;\n\ntype_error:\n PyErr_Clear();\n if (flags & SWIG_POINTER_EXCEPTION) {\n if (ty && c) {\n PyErr_Format(PyExc_TypeError, \n\t\t \"Type error. Got %s, expected %s\",\n\t\t c, ty->name);\n } else {\n PyErr_SetString(PyExc_TypeError,\"Expected a pointer\");\n }\n }\n return -1;\n}\n\n/* Convert a pointer value, signal an exception on a type mismatch */\nSWIGRUNTIME(void *)\nSWIG_Python_MustGetPtr(PyObject *obj, swig_type_info *ty, int argnum, int flags) {\n void *result;\n SWIG_Python_ConvertPtr(obj, &result, ty, flags | SWIG_POINTER_EXCEPTION);\n return result;\n}\n\n/* Create a new pointer object */\nSWIGRUNTIME(PyObject *)\nSWIG_Python_NewPointerObj(void *ptr, swig_type_info *type, int own) {\n PyObject *robj;\n if (!ptr) {\n Py_INCREF(Py_None);\n return Py_None;\n }\n#ifdef SWIG_COBJECT_TYPES\n robj = PyCObject_FromVoidPtrAndDesc((void *) ptr, (char *) type->name, NULL);\n#else\n {\n char result[1024];\n char *r = result;\n *(r++) = '_';\n r = SWIG_PackData(r,&ptr,sizeof(void *));\n strcpy(r,type->name);\n robj = PyString_FromString(result);\n }\n#endif\n if (!robj || (robj == Py_None)) return robj;\n if (type->clientdata) {\n PyObject *inst;\n PyObject *args = Py_BuildValue((char*)\"(O)\", robj);\n Py_DECREF(robj);\n inst = PyObject_CallObject((PyObject *) type->clientdata, args);\n Py_DECREF(args);\n if (inst) {\n if (own) {\n PyObject *n = PyInt_FromLong(1);\n PyObject_SetAttrString(inst,(char*)\"thisown\",n);\n Py_DECREF(n);\n }\n robj = inst;\n }\n }\n return robj;\n}\n\n#endif\n\n#ifdef __cplusplus\n}\n#endif\n\n\"\"\"\n", "methods": [], "methods_before": [], "changed_methods": [], "nloc": 1609, "complexity": 0, "token_count": 6, "diff_parsed": { "added": [ "######################################################################", "# This is for SWIG-1.3.x where x < 22.", "# Essentially, SWIG_RUNTIME_VERSION was not yet used.", "swigptr2_code_v0 = \"\"\"", "", "", "######################################################################", "# This is for SWIG-1.3.x where x >= 23.", "# SWIG_RUNTIME_VERSION == \"1\"", "", "# All this does is to include (cut/paste): ", "# and ", "swigptr2_code_v1 = \"\"\"", "/***********************************************************************", " * swigrun.swg", " *", " * This file contains generic CAPI SWIG runtime support for pointer", " * type checking.", " *", " ************************************************************************/", "", "/* This should only be incremented when either the layout of swig_type_info changes,", " or for whatever reason, the runtime changes incompatibly */", "#define SWIG_RUNTIME_VERSION \"1\"", "", "/* define SWIG_TYPE_TABLE_NAME as \"SWIG_TYPE_TABLE\" */", "#ifdef SWIG_TYPE_TABLE", "#define SWIG_QUOTE_STRING(x) #x", "#define SWIG_EXPAND_AND_QUOTE_STRING(x) SWIG_QUOTE_STRING(x)", "#define SWIG_TYPE_TABLE_NAME SWIG_EXPAND_AND_QUOTE_STRING(SWIG_TYPE_TABLE)", "#else", "#define SWIG_TYPE_TABLE_NAME", "#endif", "", "#include ", "", "#ifndef SWIGINLINE", "#if defined(__cplusplus) || (defined(__GNUC__) && !defined(__STRICT_ANSI__))", "# define SWIGINLINE inline", "#else", "# define SWIGINLINE", "#endif", "#endif", "", "/*", " You can use the SWIGRUNTIME and SWIGRUNTIMEINLINE macros for", " creating a static or dynamic library from the swig runtime code.", " In 99.9% of the cases, swig just needs to declare them as 'static'.", "", " But only do this if is strictly necessary, ie, if you have problems", " with your compiler or so.", "*/", "#ifndef SWIGRUNTIME", "#define SWIGRUNTIME static", "#endif", "#ifndef SWIGRUNTIMEINLINE", "#define SWIGRUNTIMEINLINE SWIGRUNTIME SWIGINLINE", "#endif", "", "#ifdef __cplusplus", "extern \"C\" {", "#endif", "", "typedef void *(*swig_converter_func)(void *);", "typedef struct swig_type_info *(*swig_dycast_func)(void **);", "", "typedef struct swig_type_info {", " const char *name;", " swig_converter_func converter;", " const char *str;", " void *clientdata;", " swig_dycast_func dcast;", " struct swig_type_info *next;", " struct swig_type_info *prev;", "} swig_type_info;", "", "/*", " Compare two type names skipping the space characters, therefore", " \"char*\" == \"char *\" and \"Class\" == \"Class\", etc.", "", " Return 0 when the two name types are equivalent, as in", " strncmp, but skipping ' '.", "*/", "SWIGRUNTIME int", "SWIG_TypeNameComp(const char *f1, const char *l1,", "\t\t const char *f2, const char *l2) {", " for (;(f1 != l1) && (f2 != l2); ++f1, ++f2) {", " while ((*f1 == ' ') && (f1 != l1)) ++f1;", " while ((*f2 == ' ') && (f2 != l2)) ++f2;", " if (*f1 != *f2) return *f1 - *f2;", " }", " return (l1 - f1) - (l2 - f2);", "}", "", "/*", " Check type equivalence in a name list like ||...", "*/", "SWIGRUNTIME int", "SWIG_TypeEquiv(const char *nb, const char *tb) {", " int equiv = 0;", " const char* te = tb + strlen(tb);", " const char* ne = nb;", " while (!equiv && *ne) {", " for (nb = ne; *ne; ++ne) {", " if (*ne == '|') break;", " }", " equiv = SWIG_TypeNameComp(nb, ne, tb, te) == 0;", " if (*ne) ++ne;", " }", " return equiv;", "}", "", "/*", " Register a type mapping with the type-checking", "*/", "SWIGRUNTIME swig_type_info *", "SWIG_TypeRegisterTL(swig_type_info **tl, swig_type_info *ti) {", " swig_type_info *tc, *head, *ret, *next;", " /* Check to see if this type has already been registered */", " tc = *tl;", " while (tc) {", " /* check simple type equivalence */", " int typeequiv = (strcmp(tc->name, ti->name) == 0);", " /* check full type equivalence, resolving typedefs */", " if (!typeequiv) {", " /* only if tc is not a typedef (no '|' on it) */", " if (tc->str && ti->str && !strstr(tc->str,\"|\")) {", "\ttypeequiv = SWIG_TypeEquiv(ti->str,tc->str);", " }", " }", " if (typeequiv) {", " /* Already exists in the table. Just add additional types to the list */", " if (ti->clientdata) tc->clientdata = ti->clientdata;", " head = tc;", " next = tc->next;", " goto l1;", " }", " tc = tc->prev;", " }", " head = ti;", " next = 0;", "", " /* Place in list */", " ti->prev = *tl;", " *tl = ti;", "", " /* Build linked lists */", " l1:", " ret = head;", " tc = ti + 1;", " /* Patch up the rest of the links */", " while (tc->name) {", " head->next = tc;", " tc->prev = head;", " head = tc;", " tc++;", " }", " if (next) next->prev = head;", " head->next = next;", "", " return ret;", "}", "", "/*", " Check the typename", "*/", "SWIGRUNTIME swig_type_info *", "SWIG_TypeCheck(const char *c, swig_type_info *ty) {", " swig_type_info *s;", " if (!ty) return 0; /* Void pointer */", " s = ty->next; /* First element always just a name */", " do {", " if (strcmp(s->name,c) == 0) {", " if (s == ty->next) return s;", " /* Move s to the top of the linked list */", " s->prev->next = s->next;", " if (s->next) {", " s->next->prev = s->prev;", " }", " /* Insert s as second element in the list */", " s->next = ty->next;", " if (ty->next) ty->next->prev = s;", " ty->next = s;", " s->prev = ty;", " return s;", " }", " s = s->next;", " } while (s && (s != ty->next));", " return 0;", "}", "", "/*", " Cast a pointer up an inheritance hierarchy", "*/", "SWIGRUNTIMEINLINE void *", "SWIG_TypeCast(swig_type_info *ty, void *ptr) {", " return ((!ty) || (!ty->converter)) ? ptr : (*ty->converter)(ptr);", "}", "", "/*", " Dynamic pointer casting. Down an inheritance hierarchy", "*/", "SWIGRUNTIME swig_type_info *", "SWIG_TypeDynamicCast(swig_type_info *ty, void **ptr) {", " swig_type_info *lastty = ty;", " if (!ty || !ty->dcast) return ty;", " while (ty && (ty->dcast)) {", " ty = (*ty->dcast)(ptr);", " if (ty) lastty = ty;", " }", " return lastty;", "}", "", "/*", " Return the name associated with this type", "*/", "SWIGRUNTIMEINLINE const char *", "SWIG_TypeName(const swig_type_info *ty) {", " return ty->name;", "}", "", "/*", " Return the pretty name associated with this type,", " that is an unmangled type name in a form presentable to the user.", "*/", "SWIGRUNTIME const char *", "SWIG_TypePrettyName(const swig_type_info *type) {", " /* The \"str\" field contains the equivalent pretty names of the", " type, separated by vertical-bar characters. We choose", " to print the last name, as it is often (?) the most", " specific. */", " if (type->str != NULL) {", " const char *last_name = type->str;", " const char *s;", " for (s = type->str; *s; s++)", " if (*s == '|') last_name = s+1;", " return last_name;", " }", " else", " return type->name;", "}", "", "/*", " Search for a swig_type_info structure", "*/", "SWIGRUNTIME swig_type_info *", "SWIG_TypeQueryTL(swig_type_info *tl, const char *name) {", " swig_type_info *ty = tl;", " while (ty) {", " if (ty->str && (SWIG_TypeEquiv(ty->str,name))) return ty;", " if (ty->name && (strcmp(name,ty->name) == 0)) return ty;", " ty = ty->prev;", " }", " return 0;", "}", "", "/*", " Set the clientdata field for a type", "*/", "SWIGRUNTIME void", "SWIG_TypeClientDataTL(swig_type_info *tl, swig_type_info *ti, void *clientdata) {", " swig_type_info *tc, *equiv;", " if (ti->clientdata) return;", " /* if (ti->clientdata == clientdata) return; */", " ti->clientdata = clientdata;", " equiv = ti->next;", " while (equiv) {", " if (!equiv->converter) {", " tc = tl;", " while (tc) {", " if ((strcmp(tc->name, equiv->name) == 0))", " SWIG_TypeClientDataTL(tl,tc,clientdata);", " tc = tc->prev;", " }", " }", " equiv = equiv->next;", " }", "}", "", "/*", " Pack binary data into a string", "*/", "SWIGRUNTIME char *", "SWIG_PackData(char *c, void *ptr, size_t sz) {", " static char hex[17] = \"0123456789abcdef\";", " unsigned char *u = (unsigned char *) ptr;", " const unsigned char *eu = u + sz;", " register unsigned char uu;", " for (; u != eu; ++u) {", " uu = *u;", " *(c++) = hex[(uu & 0xf0) >> 4];", " *(c++) = hex[uu & 0xf];", " }", " return c;", "}", "", "/*", " Unpack binary data from a string", "*/", "SWIGRUNTIME const char *", "SWIG_UnpackData(const char *c, void *ptr, size_t sz) {", " register unsigned char *u = (unsigned char *) ptr;", " register const unsigned char *eu = u + sz;", " for (; u != eu; ++u) {", " register int d = *(c++);", " register unsigned char uu = 0;", " if ((d >= '0') && (d <= '9'))", " uu = ((d - '0') << 4);", " else if ((d >= 'a') && (d <= 'f'))", " uu = ((d - ('a'-10)) << 4);", " else", " return (char *) 0;", " d = *(c++);", " if ((d >= '0') && (d <= '9'))", " uu |= (d - '0');", " else if ((d >= 'a') && (d <= 'f'))", " uu |= (d - ('a'-10));", " else", " return (char *) 0;", " *u = uu;", " }", " return c;", "}", "", "/*", " This function will propagate the clientdata field of type to any new", " swig_type_info structures that have been added into the list of", " equivalent types. It is like calling SWIG_TypeClientData(type,", " clientdata) a second time.", "*/", "SWIGRUNTIME void", "SWIG_PropagateClientDataTL(swig_type_info *tl, swig_type_info *type) {", " swig_type_info *equiv = type->next;", " swig_type_info *tc;", " if (!type->clientdata) return;", " while (equiv) {", " if (!equiv->converter) {", " tc = tl;", " while (tc) {", " if ((strcmp(tc->name, equiv->name) == 0) && !tc->clientdata)", " SWIG_TypeClientDataTL(tl,tc, type->clientdata);", " tc = tc->prev;", " }", " }", " equiv = equiv->next;", " }", "}", "", "/*", " Pack 'void *' into a string buffer.", "*/", "SWIGRUNTIME char *", "SWIG_PackVoidPtr(char *buff, void *ptr, const char *name, size_t bsz) {", " char *r = buff;", " if ((2*sizeof(void *) + 2) > bsz) return 0;", " *(r++) = '_';", " r = SWIG_PackData(r,&ptr,sizeof(void *));", " if (strlen(name) + 1 > (bsz - (r - buff))) return 0;", " strcpy(r,name);", " return buff;", "}", "", "SWIGRUNTIME const char *", "SWIG_UnpackVoidPtr(const char *c, void **ptr, const char *name) {", " if (*c != '_') {", " if (strcmp(c,\"NULL\") == 0) {", " *ptr = (void *) 0;", " return name;", " } else {", " return 0;", " }", " }", " return SWIG_UnpackData(++c,ptr,sizeof(void *));", "}", "", "SWIGRUNTIME char *", "SWIG_PackDataName(char *buff, void *ptr, size_t sz, const char *name, size_t bsz) {", " char *r = buff;", " size_t lname = (name ? strlen(name) : 0);", " if ((2*sz + 2 + lname) > bsz) return 0;", " *(r++) = '_';", " r = SWIG_PackData(r,ptr,sz);", " if (lname) {", " strncpy(r,name,lname+1);", " } else {", " *r = 0;", " }", " return buff;", "}", "", "SWIGRUNTIME const char *", "SWIG_UnpackDataName(const char *c, void *ptr, size_t sz, const char *name) {", " if (*c != '_') {", " if (strcmp(c,\"NULL\") == 0) {", " memset(ptr,0,sz);", " return name;", " } else {", " return 0;", " }", " }", " return SWIG_UnpackData(++c,ptr,sz);", "}", "", "#ifdef __cplusplus", "}", "#endif", "", "/***********************************************************************", " * pyrun.swg", " *", " * This file contains the runtime support for Python modules", " * and includes code for managing global variables and pointer", " * type checking.", " *", " * Author : David Beazley (beazley@cs.uchicago.edu)", " ************************************************************************/", "", "/* Common SWIG API */", "#define SWIG_ConvertPtr(obj, pp, type, flags) SWIG_Python_ConvertPtr(obj, pp, type, flags)", "#define SWIG_NewPointerObj(p, type, flags) SWIG_Python_NewPointerObj(p, type, flags)", "#define SWIG_MustGetPtr(p, type, argnum, flags) SWIG_Python_MustGetPtr(p, type, argnum, flags)", "", "", "/* Python-specific SWIG API */", "#define SWIG_ConvertPacked(obj, ptr, sz, ty, flags) SWIG_Python_ConvertPacked(obj, ptr, sz, ty, flags)", "#define SWIG_NewPackedObj(ptr, sz, type) SWIG_Python_NewPackedObj(ptr, sz, type)", "", "", "/* -----------------------------------------------------------------------------", " * Pointer declarations", " * ----------------------------------------------------------------------------- */", "/*", " Use SWIG_NO_COBJECT_TYPES to force the use of strings to represent", " C/C++ pointers in the python side. Very useful for debugging, but", " not always safe.", "*/", "#if !defined(SWIG_NO_COBJECT_TYPES) && !defined(SWIG_COBJECT_TYPES)", "# define SWIG_COBJECT_TYPES", "#endif", "", "/* Flags for pointer conversion */", "#define SWIG_POINTER_EXCEPTION 0x1", "#define SWIG_POINTER_DISOWN 0x2", "", "", "#ifdef __cplusplus", "extern \"C\" {", "#endif", "", "/* -----------------------------------------------------------------------------", " * Create a new pointer string", " * ----------------------------------------------------------------------------- */", "", "#ifndef SWIG_BUFFER_SIZE", "#define SWIG_BUFFER_SIZE 1024", "#endif", "", "#if defined(SWIG_COBJECT_TYPES)", "#if !defined(SWIG_COBJECT_PYTHON)", "/* -----------------------------------------------------------------------------", " * Implements a simple Swig Object type, and use it instead of PyCObject", " * ----------------------------------------------------------------------------- */", "", "typedef struct {", " PyObject_HEAD", " void *ptr;", " const char *desc;", "} PySwigObject;", "", "/* Declarations for objects of type PySwigObject */", "", "SWIGRUNTIME int", "PySwigObject_print(PySwigObject *v, FILE *fp, int flags)", "{", " char result[SWIG_BUFFER_SIZE];", " if (SWIG_PackVoidPtr(result, v->ptr, v->desc, sizeof(result))) {", " fputs(\"\", fp);", " return 0;", " } else {", " return 1;", " }", "}", "", "SWIGRUNTIME PyObject *", "PySwigObject_repr(PySwigObject *v)", "{", " char result[SWIG_BUFFER_SIZE];", " return SWIG_PackVoidPtr(result, v->ptr, v->desc, sizeof(result)) ?", " PyString_FromFormat(\"\", result) : 0;", "}", "", "SWIGRUNTIME PyObject *", "PySwigObject_str(PySwigObject *v)", "{", " char result[SWIG_BUFFER_SIZE];", " return SWIG_PackVoidPtr(result, v->ptr, v->desc, sizeof(result)) ?", " PyString_FromString(result) : 0;", "}", "", "SWIGRUNTIME PyObject *", "PySwigObject_long(PySwigObject *v)", "{", " return PyLong_FromUnsignedLong((unsigned long) v->ptr);", "}", "", "SWIGRUNTIME PyObject *", "PySwigObject_oct(PySwigObject *v)", "{", " char buf[100];", " unsigned long x = (unsigned long)v->ptr;", " if (x == 0)", " strcpy(buf, \"0\");", " else", " PyOS_snprintf(buf, sizeof(buf), \"0%lo\", x);", " return PyString_FromString(buf);", "}", "", "SWIGRUNTIME PyObject *", "PySwigObject_hex(PySwigObject *v)", "{", " char buf[100];", " PyOS_snprintf(buf, sizeof(buf), \"0x%lx\", (unsigned long)v->ptr);", " return PyString_FromString(buf);", "}", "", "SWIGRUNTIME int", "PySwigObject_compare(PySwigObject *v, PySwigObject *w)", "{", " int c = strcmp(v->desc, w->desc);", " if (c) {", " return c;", " } else {", " void *i = v->ptr;", " void *j = w->ptr;", " return (i < j) ? -1 : (i > j) ? 1 : 0;", " }", "}", "", "SWIGRUNTIME void", "PySwigObject_dealloc(PySwigObject *self)", "{", " PyObject_DEL(self);", "}", "", "SWIGRUNTIME PyTypeObject*", "PySwigObject_GetType() {", " static char PySwigObject_Type__doc__[] =", " \"Swig object carries a C/C++ instance pointer\";", "", " static PyNumberMethods PySwigObject_as_number = {", " (binaryfunc)0, /*nb_add*/", " (binaryfunc)0, /*nb_subtract*/", " (binaryfunc)0, /*nb_multiply*/", " (binaryfunc)0, /*nb_divide*/", " (binaryfunc)0, /*nb_remainder*/", " (binaryfunc)0, /*nb_divmod*/", " (ternaryfunc)0,/*nb_power*/", " (unaryfunc)0, /*nb_negative*/", " (unaryfunc)0, /*nb_positive*/", " (unaryfunc)0, /*nb_absolute*/", " (inquiry)0, /*nb_nonzero*/", " 0,\t\t /*nb_invert*/", " 0,\t\t /*nb_lshift*/", " 0,\t\t /*nb_rshift*/", " 0,\t\t /*nb_and*/", " 0,\t\t /*nb_xor*/", " 0,\t\t /*nb_or*/", " (coercion)0, /*nb_coerce*/", " (unaryfunc)PySwigObject_long, /*nb_int*/", " (unaryfunc)PySwigObject_long, /*nb_long*/", " (unaryfunc)0, /*nb_float*/", " (unaryfunc)PySwigObject_oct, /*nb_oct*/", " (unaryfunc)PySwigObject_hex, /*nb_hex*/", "#if PY_VERSION_HEX >= 0x02000000", " 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0 /* nb_inplace_add -> nb_inplace_true_divide */", "#endif", " };", "", " static PyTypeObject PySwigObject_Type = {", " PyObject_HEAD_INIT(&PyType_Type)", " 0,\t\t\t\t\t/*ob_size*/", " \"PySwigObject\",\t\t\t/*tp_name*/", " sizeof(PySwigObject),\t\t/*tp_basicsize*/", " 0,\t\t\t\t\t/*tp_itemsize*/", " /* methods */", " (destructor)PySwigObject_dealloc,\t/*tp_dealloc*/", " (printfunc)PySwigObject_print,\t/*tp_print*/", " (getattrfunc)0,\t\t\t/*tp_getattr*/", " (setattrfunc)0,\t\t\t/*tp_setattr*/", " (cmpfunc)PySwigObject_compare,\t/*tp_compare*/", " (reprfunc)PySwigObject_repr,\t/*tp_repr*/", " &PySwigObject_as_number,\t /*tp_as_number*/", " 0,\t\t\t\t\t/*tp_as_sequence*/", " 0,\t\t\t\t\t/*tp_as_mapping*/", " (hashfunc)0,\t\t\t/*tp_hash*/", " (ternaryfunc)0,\t\t\t/*tp_call*/", " (reprfunc)PySwigObject_str,\t\t/*tp_str*/", " /* Space for future expansion */", " 0L,0L,0L,0L,", " PySwigObject_Type__doc__, \t /* Documentation string */", "#if PY_VERSION_HEX >= 0x02000000", " 0, /* tp_traverse */", " 0, /* tp_clear */", "#endif", "#if PY_VERSION_HEX >= 0x02010000", " 0, /* tp_richcompare */", " 0, /* tp_weaklistoffset */", "#endif", "#if PY_VERSION_HEX >= 0x02020000", " 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, /* tp_iter -> tp_weaklist */", "#endif", "#if PY_VERSION_HEX >= 0x02030000", " 0, /* tp_del */", "#endif", "#ifdef COUNT_ALLOCS", " 0,0,0,0 /* tp_alloc -> tp_next */", "#endif", " };", "", " return &PySwigObject_Type;", "}", "", "SWIGRUNTIME PyObject *", "PySwigObject_FromVoidPtrAndDesc(void *ptr, const char *desc)", "{", " PySwigObject *self = PyObject_NEW(PySwigObject, PySwigObject_GetType());", " if (self == NULL) return NULL;", " self->ptr = ptr;", " self->desc = desc;", " return (PyObject *)self;", "}", "", "SWIGRUNTIMEINLINE void *", "PySwigObject_AsVoidPtr(PyObject *self)", "{", " return ((PySwigObject *)self)->ptr;", "}", "", "SWIGRUNTIMEINLINE const char *", "PySwigObject_GetDesc(PyObject *self)", "{", " return ((PySwigObject *)self)->desc;", "}", "", "SWIGRUNTIMEINLINE int", "PySwigObject_Check(PyObject *op) {", " return ((op)->ob_type == PySwigObject_GetType())", " || (strcmp((op)->ob_type->tp_name,\"PySwigObject\") == 0);", "}", "", "/* -----------------------------------------------------------------------------", " * Implements a simple Swig Packed type, and use it instead of string", " * ----------------------------------------------------------------------------- */", "", "typedef struct {", " PyObject_HEAD", " void *pack;", " const char *desc;", " size_t size;", "} PySwigPacked;", "", "SWIGRUNTIME int", "PySwigPacked_print(PySwigPacked *v, FILE *fp, int flags)", "{", " char result[SWIG_BUFFER_SIZE];", " fputs(\"pack, v->size, 0, sizeof(result))) {", " fputs(\"at \", fp);", " fputs(result, fp);", " }", " fputs(v->desc,fp);", " fputs(\">\", fp);", " return 0;", "}", "", "SWIGRUNTIME PyObject *", "PySwigPacked_repr(PySwigPacked *v)", "{", " char result[SWIG_BUFFER_SIZE];", " if (SWIG_PackDataName(result, v->pack, v->size, 0, sizeof(result))) {", " return PyString_FromFormat(\"\", result, v->desc);", " } else {", " return PyString_FromFormat(\"\", v->desc);", " }", "}", "", "SWIGRUNTIME PyObject *", "PySwigPacked_str(PySwigPacked *v)", "{", " char result[SWIG_BUFFER_SIZE];", " if (SWIG_PackDataName(result, v->pack, v->size, 0, sizeof(result))){", " return PyString_FromFormat(\"%s%s\", result, v->desc);", " } else {", " return PyString_FromFormat(\"%s\", v->desc);", " }", "}", "", "SWIGRUNTIME int", "PySwigPacked_compare(PySwigPacked *v, PySwigPacked *w)", "{", " int c = strcmp(v->desc, w->desc);", " if (c) {", " return c;", " } else {", " size_t i = v->size;", " size_t j = w->size;", " int s = (i < j) ? -1 : (i > j) ? 1 : 0;", " return s ? s : strncmp((char *)v->pack, (char *)w->pack, 2*v->size);", " }", "}", "", "SWIGRUNTIME void", "PySwigPacked_dealloc(PySwigPacked *self)", "{", " free(self->pack);", " PyObject_DEL(self);", "}", "", "SWIGRUNTIME PyTypeObject*", "PySwigPacked_GetType() {", " static char PySwigPacked_Type__doc__[] =", " \"Swig object carries a C/C++ instance pointer\";", "", " static PyTypeObject PySwigPacked_Type = {", " PyObject_HEAD_INIT(&PyType_Type)", " 0,\t\t\t\t\t/*ob_size*/", " \"PySwigPacked\",\t\t\t/*tp_name*/", " sizeof(PySwigPacked),\t\t/*tp_basicsize*/", " 0,\t\t\t\t\t/*tp_itemsize*/", " /* methods */", " (destructor)PySwigPacked_dealloc,\t/*tp_dealloc*/", " (printfunc)PySwigPacked_print,\t/*tp_print*/", " (getattrfunc)0,\t\t\t/*tp_getattr*/", " (setattrfunc)0,\t\t\t/*tp_setattr*/", " (cmpfunc)PySwigPacked_compare,\t/*tp_compare*/", " (reprfunc)PySwigPacked_repr,\t/*tp_repr*/", " 0,\t /*tp_as_number*/", " 0,\t\t\t\t\t/*tp_as_sequence*/", " 0,\t\t\t\t\t/*tp_as_mapping*/", " (hashfunc)0,\t\t\t/*tp_hash*/", " (ternaryfunc)0,\t\t\t/*tp_call*/", " (reprfunc)PySwigPacked_str,\t\t/*tp_str*/", " /* Space for future expansion */", " 0L,0L,0L,0L,", " PySwigPacked_Type__doc__, \t /* Documentation string */", "#if PY_VERSION_HEX >= 0x02000000", " 0, /* tp_traverse */", " 0, /* tp_clear */", "#endif", "#if PY_VERSION_HEX >= 0x02010000", " 0, /* tp_richcompare */", " 0, /* tp_weaklistoffset */", "#endif", "#if PY_VERSION_HEX >= 0x02020000", " 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, /* tp_iter -> tp_weaklist */", "#endif", "#if PY_VERSION_HEX >= 0x02030000", " 0, /* tp_del */", "#endif", "#ifdef COUNT_ALLOCS", " 0,0,0,0 /* tp_alloc -> tp_next */", "#endif", " };", "", " return &PySwigPacked_Type;", "}", "", "SWIGRUNTIME PyObject *", "PySwigPacked_FromDataAndDesc(void *ptr, size_t size, const char *desc)", "{", " PySwigPacked *self = PyObject_NEW(PySwigPacked, PySwigPacked_GetType());", " if (self == NULL) {", " return NULL;", " } else {", " void *pack = malloc(size);", " memcpy(pack, ptr, size);", " self->pack = pack;", " self->desc = desc;", " self->size = size;", " return (PyObject *) self;", " }", "}", "", "SWIGRUNTIMEINLINE const char *", "PySwigPacked_UnpackData(PyObject *obj, void *ptr, size_t size)", "{", " PySwigPacked *self = (PySwigPacked *)obj;", " if (self->size != size) return 0;", " memcpy(ptr, self->pack, size);", " return self->desc;", "}", "", "SWIGRUNTIMEINLINE const char *", "PySwigPacked_GetDesc(PyObject *self)", "{", " return ((PySwigPacked *)self)->desc;", "}", "", "SWIGRUNTIMEINLINE int", "PySwigPacked_Check(PyObject *op) {", " return ((op)->ob_type == PySwigPacked_GetType())", " || (strcmp((op)->ob_type->tp_name,\"PySwigPacked\") == 0);", "}", "", "#else", "/* -----------------------------------------------------------------------------", " * Use the old Python PyCObject instead of PySwigObject", " * ----------------------------------------------------------------------------- */", "", "#define PySwigObject_GetDesc(obj)\t PyCObject_GetDesc(obj)", "#define PySwigObject_Check(obj)\t PyCObject_Check(obj)", "#define PySwigObject_AsVoidPtr(obj)\t PyCObject_AsVoidPtr(obj)", "#define PySwigObject_FromVoidPtrAndDesc(p, d) PyCObject_FromVoidPtrAndDesc(p, d, NULL)", "", "#endif", "", "#endif", "", "/* -----------------------------------------------------------------------------", " * errors manipulation", " * ----------------------------------------------------------------------------- */", "", "SWIGRUNTIME void", "SWIG_Python_TypeError(const char *type, PyObject *obj)", "{", " if (type) {", "#if defined(SWIG_COBJECT_TYPES)", " if (PySwigObject_Check(obj)) {", " const char *otype = (const char *) PySwigObject_GetDesc(obj);", " if (otype) {", "\tPyErr_Format(PyExc_TypeError, \"a '%s' is expected, 'PySwigObject(%s)' is received\",", "\t\t type, otype);", "\treturn;", " }", " } else", "#endif", " {", " const char *otype = (obj ? obj->ob_type->tp_name : 0);", " if (otype) {", "\tPyObject *str = PyObject_Str(obj);", "\tconst char *cstr = str ? PyString_AsString(str) : 0;", "\tif (cstr) {", "\t PyErr_Format(PyExc_TypeError, \"a '%s' is expected, '%s(%s)' is received\",", "\t\t type, otype, cstr);", "\t} else {", "\t PyErr_Format(PyExc_TypeError, \"a '%s' is expected, '%s' is received\",", "\t\t type, otype);", "\t}", "\tPy_DECREF(str);", "\treturn;", " }", " }", " PyErr_Format(PyExc_TypeError, \"a '%s' is expected\", type);", " } else {", " PyErr_Format(PyExc_TypeError, \"unexpected type is received\");", " }", "}", "", "SWIGRUNTIMEINLINE void", "SWIG_Python_NullRef(const char *type)", "{", " if (type) {", " PyErr_Format(PyExc_TypeError, \"null reference of type '%s' was received\",type);", " } else {", " PyErr_Format(PyExc_TypeError, \"null reference was received\");", " }", "}", "", "SWIGRUNTIME int", "SWIG_Python_AddErrMesg(const char* mesg, int infront)", "{", " if (PyErr_Occurred()) {", " PyObject *type = 0;", " PyObject *value = 0;", " PyObject *traceback = 0;", " PyErr_Fetch(&type, &value, &traceback);", " if (value) {", " PyObject *old_str = PyObject_Str(value);", " Py_XINCREF(type);", " PyErr_Clear();", " if (infront) {", "\tPyErr_Format(type, \"%s %s\", mesg, PyString_AsString(old_str));", " } else {", "\tPyErr_Format(type, \"%s %s\", PyString_AsString(old_str), mesg);", " }", " Py_DECREF(old_str);", " }", " return 1;", " } else {", " return 0;", " }", "}", "", "SWIGRUNTIME int", "SWIG_Python_ArgFail(int argnum)", "{", " if (PyErr_Occurred()) {", " /* add information about failing argument */", " char mesg[256];", " sprintf(mesg, \"argument number %d:\", argnum);", " return SWIG_Python_AddErrMesg(mesg, 1);", " } else {", " return 0;", " }", "}", "", "", "/* -----------------------------------------------------------------------------", " * pointers/data manipulation", " * ----------------------------------------------------------------------------- */", "", "/* Convert a pointer value */", "SWIGRUNTIME int", "SWIG_Python_ConvertPtr(PyObject *obj, void **ptr, swig_type_info *ty, int flags) {", " swig_type_info *tc;", " const char *c = 0;", " static PyObject *SWIG_this = 0;", " int newref = 0;", " PyObject *pyobj = 0;", " void *vptr;", "", " if (!obj) return 0;", " if (obj == Py_None) {", " *ptr = 0;", " return 0;", " }", "", "#ifdef SWIG_COBJECT_TYPES", " if (!(PySwigObject_Check(obj))) {", " if (!SWIG_this)", " SWIG_this = PyString_FromString(\"this\");", " pyobj = obj;", " obj = PyObject_GetAttr(obj,SWIG_this);", " newref = 1;", " if (!obj) goto type_error;", " if (!PySwigObject_Check(obj)) {", " Py_DECREF(obj);", " goto type_error;", " }", " }", " vptr = PySwigObject_AsVoidPtr(obj);", " c = (const char *) PySwigObject_GetDesc(obj);", " if (newref) { Py_DECREF(obj); }", " goto type_check;", "#else", " if (!(PyString_Check(obj))) {", " if (!SWIG_this)", " SWIG_this = PyString_FromString(\"this\");", " pyobj = obj;", " obj = PyObject_GetAttr(obj,SWIG_this);", " newref = 1;", " if (!obj) goto type_error;", " if (!PyString_Check(obj)) {", " Py_DECREF(obj);", " goto type_error;", " }", " }", " c = PyString_AS_STRING(obj);", " /* Pointer values must start with leading underscore */", " c = SWIG_UnpackVoidPtr(c, &vptr, ty->name);", " if (newref) { Py_DECREF(obj); }", " if (!c) goto type_error;", "#endif", "", "type_check:", "", " if (ty) {", " tc = SWIG_TypeCheck(c,ty);", " if (!tc) goto type_error;", " *ptr = SWIG_TypeCast(tc,vptr);", " }", "", " if ((pyobj) && (flags & SWIG_POINTER_DISOWN)) {", " PyObject_SetAttrString(pyobj,(char*)\"thisown\",Py_False);", " }", " return 0;", "", "type_error:", " PyErr_Clear();", " if (pyobj && !obj) {", " obj = pyobj;", " if (PyCFunction_Check(obj)) {", " /* here we get the method pointer for callbacks */", " char *doc = (((PyCFunctionObject *)obj) -> m_ml -> ml_doc);", " c = doc ? strstr(doc, \"swig_ptr: \") : 0;", " if (c) {", "\tc = SWIG_UnpackVoidPtr(c + 10, &vptr, ty->name);", "\tif (!c) goto type_error;", "\tgoto type_check;", " }", " }", " }", " if (flags & SWIG_POINTER_EXCEPTION) {", " if (ty) {", " SWIG_Python_TypeError(SWIG_TypePrettyName(ty), obj);", " } else {", " SWIG_Python_TypeError(\"C/C++ pointer\", obj);", " }", " }", " return -1;", "}", "", "/* Convert a pointer value, signal an exception on a type mismatch */", "SWIGRUNTIME void *", "SWIG_Python_MustGetPtr(PyObject *obj, swig_type_info *ty, int argnum, int flags) {", " void *result;", " if (SWIG_Python_ConvertPtr(obj, &result, ty, flags) == -1) {", " PyErr_Clear();", " if (flags & SWIG_POINTER_EXCEPTION) {", " SWIG_Python_TypeError(SWIG_TypePrettyName(ty), obj);", " SWIG_Python_ArgFail(argnum);", " }", " }", " return result;", "}", "", "/* Convert a packed value value */", "SWIGRUNTIME int", "SWIG_Python_ConvertPacked(PyObject *obj, void *ptr, size_t sz, swig_type_info *ty, int flags) {", " swig_type_info *tc;", " const char *c = 0;", "", "#if defined(SWIG_COBJECT_TYPES) && !defined(SWIG_COBJECT_PYTHON)", " c = PySwigPacked_UnpackData(obj, ptr, sz);", "#else", " if ((!obj) || (!PyString_Check(obj))) goto type_error;", " c = PyString_AS_STRING(obj);", " /* Pointer values must start with leading underscore */", " c = SWIG_UnpackDataName(c, ptr, sz, ty->name);", "#endif", " if (!c) goto type_error;", " if (ty) {", " tc = SWIG_TypeCheck(c,ty);", " if (!tc) goto type_error;", " }", " return 0;", "", "type_error:", " PyErr_Clear();", " if (flags & SWIG_POINTER_EXCEPTION) {", " if (ty) {", " SWIG_Python_TypeError(SWIG_TypePrettyName(ty), obj);", " } else {", " SWIG_Python_TypeError(\"C/C++ packed data\", obj);", " }", " }", " return -1;", "}", "", "/* Create a new array object */", "SWIGRUNTIME PyObject *", "SWIG_Python_NewPointerObj(void *ptr, swig_type_info *type, int own) {", " PyObject *robj = 0;", " if (!ptr) {", " Py_INCREF(Py_None);", " return Py_None;", " }", "#ifdef SWIG_COBJECT_TYPES", " robj = PySwigObject_FromVoidPtrAndDesc((void *) ptr, (char *)type->name);", "#else", " {", " char result[SWIG_BUFFER_SIZE];", " robj = SWIG_PackVoidPtr(result, ptr, type->name, sizeof(result)) ?", " PyString_FromString(result) : 0;", " }", "#endif", " if (!robj || (robj == Py_None)) return robj;", " if (type->clientdata) {", " PyObject *inst;", " PyObject *args = Py_BuildValue((char*)\"(O)\", robj);", " Py_DECREF(robj);", " inst = PyObject_CallObject((PyObject *) type->clientdata, args);", " Py_DECREF(args);", " if (inst) {", " if (own) {", " PyObject_SetAttrString(inst,(char*)\"thisown\",Py_True);", " }", " robj = inst;", " }", " }", " return robj;", "}", "", "SWIGRUNTIME PyObject *", "SWIG_Python_NewPackedObj(void *ptr, size_t sz, swig_type_info *type) {", " PyObject *robj = 0;", " if (!ptr) {", " Py_INCREF(Py_None);", " return Py_None;", " }", "#if defined(SWIG_COBJECT_TYPES) && !defined(SWIG_COBJECT_PYTHON)", " robj = PySwigPacked_FromDataAndDesc((void *) ptr, sz, (char *)type->name);", "#else", " {", " char result[SWIG_BUFFER_SIZE];", " robj = SWIG_PackDataName(result, ptr, sz, type->name, sizeof(result)) ?", " PyString_FromString(result) : 0;", " }", "#endif", " return robj;", "}", "", "/* -----------------------------------------------------------------------------*", " * Get type list", " * -----------------------------------------------------------------------------*/", "", "#ifdef SWIG_LINK_RUNTIME", "void *SWIG_ReturnGlobalTypeList(void *);", "#endif", "", "SWIGRUNTIME swig_type_info **", "SWIG_Python_GetTypeListHandle() {", " static void *type_pointer = (void *)0;", " /* first check if module already created */", " if (!type_pointer) {", "#ifdef SWIG_LINK_RUNTIME", " type_pointer = SWIG_ReturnGlobalTypeList((void *)0);", "#else", " type_pointer = PyCObject_Import((char*)\"swig_runtime_data\" SWIG_RUNTIME_VERSION,", "\t\t\t\t (char*)\"type_pointer\" SWIG_TYPE_TABLE_NAME);", " if (PyErr_Occurred()) {", " PyErr_Clear();", " type_pointer = (void *)0;", " }", " }", "#endif", " return (swig_type_info **) type_pointer;", "}", "", "/*", " Search for a swig_type_info structure", " */", "SWIGRUNTIMEINLINE swig_type_info *", "SWIG_Python_GetTypeList() {", " swig_type_info **tlh = SWIG_Python_GetTypeListHandle();", " return tlh ? *tlh : (swig_type_info*)0;", "}", "", "#define SWIG_Runtime_GetTypeList SWIG_Python_GetTypeList", "", "#ifdef __cplusplus", "}", "#endif", "", "/* -----------------------------------------------------------------------------*", " Standard SWIG API for use inside user code.", "", " You need to include in your code as follow:", "", "#include // or using your favorite language", "#include ", "#include // or using your favorite language", "#include ", "", " * -----------------------------------------------------------------------------*/", "", "SWIGRUNTIMEINLINE swig_type_info *", "SWIG_Runtime_TypeQuery(const char *name) {", " swig_type_info *tl = SWIG_Runtime_GetTypeList();", " return SWIG_TypeQueryTL(tl, name);", "}", "", "SWIGRUNTIMEINLINE swig_type_info *", "SWIG_Runtime_TypeRegister(swig_type_info *ti) {", " swig_type_info *tl = SWIG_Runtime_GetTypeList();", " return SWIG_TypeRegisterTL(&tl, ti);", "}", "", "SWIGRUNTIMEINLINE void", "SWIG_Runtime_TypeClientData(swig_type_info *ti, void *clientdata) {", " swig_type_info *tl = SWIG_Runtime_GetTypeList();", " SWIG_TypeClientDataTL(tl, ti, clientdata);", "}", "", "SWIGRUNTIMEINLINE void", "SWIG_Runtime_PropagateClientData(swig_type_info *type) {", " swig_type_info *tl = SWIG_Runtime_GetTypeList();", " SWIG_PropagateClientDataTL(tl, type);", "}", "", "#define SWIG_GetTypeList() SWIG_Runtime_GetTypeList()", "#define SWIG_TypeQuery(name) SWIG_Runtime_TypeQuery(name)", "#define SWIG_TypeRegister(ti) SWIG_Runtime_TypeRegister(ti)", "#define SWIG_TypeClientData(ti, cd) SWIG_Runtime_TypeClientData(ti, cd)", "#define SWIG_PropagateClientData(ti) SWIG_Runtime_PropagateClientData(ti)", "", "\"\"\"" ], "deleted": [ "swigptr2_code = \"\"\"" ] } } ] }, { "hash": "537e4ea67dde56d26165d7351677d83fad016189", "msg": "mintypecode() supports array arguments.", "author": { "name": "Pearu Peterson", "email": "pearu.peterson@gmail.com" }, "committer": { "name": "Pearu Peterson", "email": "pearu.peterson@gmail.com" }, "author_date": "2004-11-22T20:24:01+00:00", "author_timezone": 0, "committer_date": "2004-11-22T20:24:01+00:00", "committer_timezone": 0, "branches": [ "main" ], "in_main_branch": true, "merge": false, "parents": [ "ed2479c295044698c3e6fdc2b359aef67f49dd93" ], "project_name": "repo_copy", "project_path": "/tmp/tmpqop781_j/repo_copy", "deletions": 1, "insertions": 4, "lines": 5, "files": 2, "dmm_unit_size": 1.0, "dmm_unit_complexity": 0.0, "dmm_unit_interfacing": 0.0, "modified_files": [ { "old_path": "scipy_base/type_check.py", "new_path": "scipy_base/type_check.py", "filename": "type_check.py", "extension": "py", "change_type": "MODIFY", "diff": "@@ -25,7 +25,9 @@ def mintypecode(typecodes,typeset='DFdf',default='d',savespace=0):\n intersect with typeset then default is returned.\n As a special case, if savespace is False then 'D' is returned\n whenever typecodes contain 'F' and 'd'.\n+ If t in typecodes is not a string then t=t.typecode() is applied.\n \"\"\"\n+ typecodes = [(type(t) is type('') and t) or t.typecode() for t in typecodes]\n intersection = [t for t in typecodes if t in typeset]\n if not intersection:\n return default\n", "added_lines": 2, "deleted_lines": 0, "source_code": "\nimport types\nimport Numeric\nfrom fastumath import isinf, isnan, isfinite\nfrom Numeric import ArrayType, array, multiarray\n\ntry:\n from Numeric import UfuncType\nexcept ImportError:\n UfuncType = type(Numeric.sin)\n\n__all__ = ['ScalarType','iscomplexobj','isrealobj','imag','iscomplex',\n 'isscalar','isneginf','isposinf','isnan','isinf','isfinite',\n 'isreal','nan_to_num','real','real_if_close',\n 'typename','cast','common_type','typecodes', 'asarray',\n 'asfarray', 'ArrayType', 'UfuncType','mintypecode']\n\n_typecodes_by_elsize = 'DFdfluiwsb1c'\ndef mintypecode(typecodes,typeset='DFdf',default='d',savespace=0):\n \"\"\" Return a typecode in typeset such that for each\n t in typecodes\n array(typecode=typecode)[:] = array(typecode=t)\n is valid, looses no information, and array(typecode=typecode)\n element size is minimal unless when typecodes does not\n intersect with typeset then default is returned.\n As a special case, if savespace is False then 'D' is returned\n whenever typecodes contain 'F' and 'd'.\n If t in typecodes is not a string then t=t.typecode() is applied.\n \"\"\"\n typecodes = [(type(t) is type('') and t) or t.typecode() for t in typecodes]\n intersection = [t for t in typecodes if t in typeset]\n if not intersection:\n return default\n if not savespace and 'F' in intersection and 'd' in intersection:\n return 'D'\n l = []\n for t in intersection:\n i = _typecodes_by_elsize.index(t)\n l.append((i,t))\n l.sort()\n return l[0][1]\n\ndef asarray(a, typecode=None, savespace=None):\n \"\"\"asarray(a,typecode=None, savespace=0) returns a as a NumPy array.\n Unlike array(), no copy is performed if a is already an array.\n \"\"\"\n if type(a) is ArrayType:\n if typecode is None or typecode == a.typecode():\n if savespace is None or a.spacesaver()==savespace:\n return a\n else:\n r = a.astype(typecode)\n if not (savespace is None or a.spacesaver()==savespace):\n r.savespace(savespace)\n return r\n return multiarray.array(a,typecode,copy=0,savespace=savespace or 0)\n\ndef asfarray(a, typecode=None, savespace=None):\n \"\"\"asfarray(a,typecode=None, savespace=0) returns a as a NumPy float array.\"\"\"\n a = asarray(a,typecode,savespace)\n if typecode is None and a.typecode() not in 'CFfd':\n return a.astype('d')\n return a\n\nScalarType = [types.IntType, types.LongType, types.FloatType, types.ComplexType]\n\ntypecodes = Numeric.typecodes\ntypecodes['AllInteger'] = '1silbwu'\n\ntry:\n Char = Numeric.Character\nexcept AttributeError:\n Char = 'c'\n\ntoChar = lambda x: asarray(x).astype(Char)\ntoInt8 = lambda x: asarray(x).astype(Numeric.Int8)# or use variable names such as Byte\ntoUInt8 = lambda x: asarray(x).astype(Numeric.UnsignedInt8)\n_unsigned = 0\nif hasattr(Numeric,'UnsignedInt16'):\n toUInt16 = lambda x: asarray(x).astype(Numeric.UnsignedInt16)\n toUInt32 = lambda x: asarray(x).astype(Numeric.UnsignedInt32)\n _unsigned = 1\n \ntoInt16 = lambda x: asarray(x).astype(Numeric.Int16)\ntoInt32 = lambda x: asarray(x).astype(Numeric.Int32)\ntoInt = lambda x: asarray(x).astype(Numeric.Int)\ntoFloat32 = lambda x: asarray(x).astype(Numeric.Float32)\ntoFloat64 = lambda x: asarray(x).astype(Numeric.Float64)\ntoComplex32 = lambda x: asarray(x).astype(Numeric.Complex32)\ntoComplex64 = lambda x: asarray(x).astype(Numeric.Complex64)\n\n# This is for pre Numeric 21.x compatiblity. Adding it is harmless.\nif not hasattr(Numeric,'Character'):\n Numeric.Character = 'c'\n \ncast = {Numeric.Character: toChar,\n Numeric.UnsignedInt8: toUInt8,\n Numeric.Int8: toInt8,\n Numeric.Int16: toInt16,\n Numeric.Int32: toInt32,\n Numeric.Int: toInt,\n Numeric.Float32: toFloat32,\n Numeric.Float64: toFloat64,\n Numeric.Complex32: toComplex32,\n Numeric.Complex64: toComplex64}\n\nif _unsigned:\n cast[Numeric.UnsignedInt16] = toUInt16\n cast[Numeric.UnsignedInt32] = toUInt32\n \n\ndef isscalar(num):\n if isinstance(num, ArrayType):\n return len(num.shape) == 0 and num.typecode() != 'O'\n return type(num) in ScalarType\n\ndef real(val):\n aval = asarray(val)\n if aval.typecode() in ['F', 'D']:\n return aval.real\n else:\n return aval\n\ndef imag(val):\n aval = asarray(val)\n if aval.typecode() in ['F', 'D']:\n return aval.imag\n else:\n return array(0,aval.typecode())*aval\n\ndef iscomplex(x):\n return imag(x) != Numeric.zeros(asarray(x).shape)\n\ndef isreal(x):\n return imag(x) == Numeric.zeros(asarray(x).shape)\n\ndef iscomplexobj(x):\n return asarray(x).typecode() in ['F', 'D']\n\ndef isrealobj(x):\n return not asarray(x).typecode() in ['F', 'D']\n\n#-----------------------------------------------------------------------------\n\n##def isnan(val):\n## # fast, but apparently not portable (according to notes by Tim Peters)\n## #return val != val\n## # very slow -- should really use cephes methods or *something* different\n## import ieee_754\n## vals = ravel(val)\n## if array_iscomplex(vals):\n## r = array(map(ieee_754.isnan,real(vals))) \n## i = array(map(ieee_754.isnan,imag(vals)))\n## results = Numeric.logical_or(r,i)\n## else: \n## results = array(map(ieee_754.isnan,vals))\n## if isscalar(val):\n## results = results[0]\n## return results\n\ndef isposinf(val):\n return isinf(val) & (val > 0)\n \ndef isneginf(val):\n return isinf(val) & (val < 0)\n \n##def isinf(val):\n## return Numeric.logical_or(isposinf(val),isneginf(val))\n\n##def isfinite(val):\n## vals = asarray(val)\n## if iscomplexobj(vals):\n## r = isfinite(real(vals))\n## i = isfinite(imag(vals))\n## results = Numeric.logical_and(r,i)\n## else: \n## fin = Numeric.logical_not(isinf(val))\n## an = Numeric.logical_not(isnan(val))\n## results = Numeric.logical_and(fin,an)\n## return results \n\ndef nan_to_num(x):\n # mapping:\n # NaN -> 0\n # Inf -> limits.double_max\n # -Inf -> limits.double_min\n # complex not handled currently\n import limits\n try:\n t = x.typecode()\n except AttributeError:\n t = type(x)\n if t in [types.ComplexType,'F','D']: \n y = nan_to_num(x.real) + 1j * nan_to_num(x.imag)\n else: \n x = asarray(x)\n are_inf = isposinf(x)\n are_neg_inf = isneginf(x)\n are_nan = isnan(x)\n choose_array = are_neg_inf + are_nan * 2 + are_inf * 3\n y = Numeric.choose(choose_array,\n (x,limits.double_min, 0., limits.double_max))\n return y\n\n#-----------------------------------------------------------------------------\n\ndef real_if_close(a,tol=1e-13):\n a = asarray(a)\n if a.typecode() in ['F','D'] and Numeric.allclose(a.imag, 0, atol=tol):\n a = a.real\n return a\n\n\n#-----------------------------------------------------------------------------\n\n_namefromtype = {'c' : 'character',\n '1' : 'signed char',\n 'b' : 'unsigned char',\n 's' : 'short',\n 'w' : 'unsigned short',\n 'i' : 'integer',\n 'u' : 'unsigned integer',\n 'l' : 'long integer',\n 'f' : 'float',\n 'd' : 'double',\n 'F' : 'complex float',\n 'D' : 'complex double',\n 'O' : 'object'\n }\n\ndef typename(char):\n \"\"\"Return an english name for the given typecode character.\n \"\"\"\n return _namefromtype[char]\n\n#-----------------------------------------------------------------------------\n\n#determine the \"minimum common type code\" for a group of arrays.\narray_kind = {'i':0, 'l': 0, 'f': 0, 'd': 0, 'F': 1, 'D': 1}\narray_precision = {'i': 1, 'l': 1, 'f': 0, 'd': 1, 'F': 0, 'D': 1}\narray_type = [['f', 'd'], ['F', 'D']]\ndef common_type(*arrays):\n kind = 0\n precision = 0\n for a in arrays:\n t = a.typecode()\n kind = max(kind, array_kind[t])\n precision = max(precision, array_precision[t])\n return array_type[kind][precision]\n\nif __name__ == '__main__':\n print 'float epsilon:',float_epsilon\n print 'float tiny:',float_tiny\n print 'double epsilon:',double_epsilon\n print 'double tiny:',double_tiny\n", "source_code_before": "\nimport types\nimport Numeric\nfrom fastumath import isinf, isnan, isfinite\nfrom Numeric import ArrayType, array, multiarray\n\ntry:\n from Numeric import UfuncType\nexcept ImportError:\n UfuncType = type(Numeric.sin)\n\n__all__ = ['ScalarType','iscomplexobj','isrealobj','imag','iscomplex',\n 'isscalar','isneginf','isposinf','isnan','isinf','isfinite',\n 'isreal','nan_to_num','real','real_if_close',\n 'typename','cast','common_type','typecodes', 'asarray',\n 'asfarray', 'ArrayType', 'UfuncType','mintypecode']\n\n_typecodes_by_elsize = 'DFdfluiwsb1c'\ndef mintypecode(typecodes,typeset='DFdf',default='d',savespace=0):\n \"\"\" Return a typecode in typeset such that for each\n t in typecodes\n array(typecode=typecode)[:] = array(typecode=t)\n is valid, looses no information, and array(typecode=typecode)\n element size is minimal unless when typecodes does not\n intersect with typeset then default is returned.\n As a special case, if savespace is False then 'D' is returned\n whenever typecodes contain 'F' and 'd'.\n \"\"\"\n intersection = [t for t in typecodes if t in typeset]\n if not intersection:\n return default\n if not savespace and 'F' in intersection and 'd' in intersection:\n return 'D'\n l = []\n for t in intersection:\n i = _typecodes_by_elsize.index(t)\n l.append((i,t))\n l.sort()\n return l[0][1]\n\ndef asarray(a, typecode=None, savespace=None):\n \"\"\"asarray(a,typecode=None, savespace=0) returns a as a NumPy array.\n Unlike array(), no copy is performed if a is already an array.\n \"\"\"\n if type(a) is ArrayType:\n if typecode is None or typecode == a.typecode():\n if savespace is None or a.spacesaver()==savespace:\n return a\n else:\n r = a.astype(typecode)\n if not (savespace is None or a.spacesaver()==savespace):\n r.savespace(savespace)\n return r\n return multiarray.array(a,typecode,copy=0,savespace=savespace or 0)\n\ndef asfarray(a, typecode=None, savespace=None):\n \"\"\"asfarray(a,typecode=None, savespace=0) returns a as a NumPy float array.\"\"\"\n a = asarray(a,typecode,savespace)\n if typecode is None and a.typecode() not in 'CFfd':\n return a.astype('d')\n return a\n\nScalarType = [types.IntType, types.LongType, types.FloatType, types.ComplexType]\n\ntypecodes = Numeric.typecodes\ntypecodes['AllInteger'] = '1silbwu'\n\ntry:\n Char = Numeric.Character\nexcept AttributeError:\n Char = 'c'\n\ntoChar = lambda x: asarray(x).astype(Char)\ntoInt8 = lambda x: asarray(x).astype(Numeric.Int8)# or use variable names such as Byte\ntoUInt8 = lambda x: asarray(x).astype(Numeric.UnsignedInt8)\n_unsigned = 0\nif hasattr(Numeric,'UnsignedInt16'):\n toUInt16 = lambda x: asarray(x).astype(Numeric.UnsignedInt16)\n toUInt32 = lambda x: asarray(x).astype(Numeric.UnsignedInt32)\n _unsigned = 1\n \ntoInt16 = lambda x: asarray(x).astype(Numeric.Int16)\ntoInt32 = lambda x: asarray(x).astype(Numeric.Int32)\ntoInt = lambda x: asarray(x).astype(Numeric.Int)\ntoFloat32 = lambda x: asarray(x).astype(Numeric.Float32)\ntoFloat64 = lambda x: asarray(x).astype(Numeric.Float64)\ntoComplex32 = lambda x: asarray(x).astype(Numeric.Complex32)\ntoComplex64 = lambda x: asarray(x).astype(Numeric.Complex64)\n\n# This is for pre Numeric 21.x compatiblity. Adding it is harmless.\nif not hasattr(Numeric,'Character'):\n Numeric.Character = 'c'\n \ncast = {Numeric.Character: toChar,\n Numeric.UnsignedInt8: toUInt8,\n Numeric.Int8: toInt8,\n Numeric.Int16: toInt16,\n Numeric.Int32: toInt32,\n Numeric.Int: toInt,\n Numeric.Float32: toFloat32,\n Numeric.Float64: toFloat64,\n Numeric.Complex32: toComplex32,\n Numeric.Complex64: toComplex64}\n\nif _unsigned:\n cast[Numeric.UnsignedInt16] = toUInt16\n cast[Numeric.UnsignedInt32] = toUInt32\n \n\ndef isscalar(num):\n if isinstance(num, ArrayType):\n return len(num.shape) == 0 and num.typecode() != 'O'\n return type(num) in ScalarType\n\ndef real(val):\n aval = asarray(val)\n if aval.typecode() in ['F', 'D']:\n return aval.real\n else:\n return aval\n\ndef imag(val):\n aval = asarray(val)\n if aval.typecode() in ['F', 'D']:\n return aval.imag\n else:\n return array(0,aval.typecode())*aval\n\ndef iscomplex(x):\n return imag(x) != Numeric.zeros(asarray(x).shape)\n\ndef isreal(x):\n return imag(x) == Numeric.zeros(asarray(x).shape)\n\ndef iscomplexobj(x):\n return asarray(x).typecode() in ['F', 'D']\n\ndef isrealobj(x):\n return not asarray(x).typecode() in ['F', 'D']\n\n#-----------------------------------------------------------------------------\n\n##def isnan(val):\n## # fast, but apparently not portable (according to notes by Tim Peters)\n## #return val != val\n## # very slow -- should really use cephes methods or *something* different\n## import ieee_754\n## vals = ravel(val)\n## if array_iscomplex(vals):\n## r = array(map(ieee_754.isnan,real(vals))) \n## i = array(map(ieee_754.isnan,imag(vals)))\n## results = Numeric.logical_or(r,i)\n## else: \n## results = array(map(ieee_754.isnan,vals))\n## if isscalar(val):\n## results = results[0]\n## return results\n\ndef isposinf(val):\n return isinf(val) & (val > 0)\n \ndef isneginf(val):\n return isinf(val) & (val < 0)\n \n##def isinf(val):\n## return Numeric.logical_or(isposinf(val),isneginf(val))\n\n##def isfinite(val):\n## vals = asarray(val)\n## if iscomplexobj(vals):\n## r = isfinite(real(vals))\n## i = isfinite(imag(vals))\n## results = Numeric.logical_and(r,i)\n## else: \n## fin = Numeric.logical_not(isinf(val))\n## an = Numeric.logical_not(isnan(val))\n## results = Numeric.logical_and(fin,an)\n## return results \n\ndef nan_to_num(x):\n # mapping:\n # NaN -> 0\n # Inf -> limits.double_max\n # -Inf -> limits.double_min\n # complex not handled currently\n import limits\n try:\n t = x.typecode()\n except AttributeError:\n t = type(x)\n if t in [types.ComplexType,'F','D']: \n y = nan_to_num(x.real) + 1j * nan_to_num(x.imag)\n else: \n x = asarray(x)\n are_inf = isposinf(x)\n are_neg_inf = isneginf(x)\n are_nan = isnan(x)\n choose_array = are_neg_inf + are_nan * 2 + are_inf * 3\n y = Numeric.choose(choose_array,\n (x,limits.double_min, 0., limits.double_max))\n return y\n\n#-----------------------------------------------------------------------------\n\ndef real_if_close(a,tol=1e-13):\n a = asarray(a)\n if a.typecode() in ['F','D'] and Numeric.allclose(a.imag, 0, atol=tol):\n a = a.real\n return a\n\n\n#-----------------------------------------------------------------------------\n\n_namefromtype = {'c' : 'character',\n '1' : 'signed char',\n 'b' : 'unsigned char',\n 's' : 'short',\n 'w' : 'unsigned short',\n 'i' : 'integer',\n 'u' : 'unsigned integer',\n 'l' : 'long integer',\n 'f' : 'float',\n 'd' : 'double',\n 'F' : 'complex float',\n 'D' : 'complex double',\n 'O' : 'object'\n }\n\ndef typename(char):\n \"\"\"Return an english name for the given typecode character.\n \"\"\"\n return _namefromtype[char]\n\n#-----------------------------------------------------------------------------\n\n#determine the \"minimum common type code\" for a group of arrays.\narray_kind = {'i':0, 'l': 0, 'f': 0, 'd': 0, 'F': 1, 'D': 1}\narray_precision = {'i': 1, 'l': 1, 'f': 0, 'd': 1, 'F': 0, 'D': 1}\narray_type = [['f', 'd'], ['F', 'D']]\ndef common_type(*arrays):\n kind = 0\n precision = 0\n for a in arrays:\n t = a.typecode()\n kind = max(kind, array_kind[t])\n precision = max(precision, array_precision[t])\n return array_type[kind][precision]\n\nif __name__ == '__main__':\n print 'float epsilon:',float_epsilon\n print 'float tiny:',float_tiny\n print 'double epsilon:',double_epsilon\n print 'double tiny:',double_tiny\n", "methods": [ { "name": "mintypecode", "long_name": "mintypecode( typecodes , typeset = 'DFdf' , default = 'd' , savespace = 0 )", "filename": "type_check.py", "nloc": 13, "complexity": 11, "token_count": 118, "parameters": [ "typecodes", "typeset", "default", "savespace" ], "start_line": 19, "end_line": 41, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 23, "top_nesting_level": 0 }, { "name": "asarray", "long_name": "asarray( a , typecode = None , savespace = None )", "filename": "type_check.py", "nloc": 11, "complexity": 9, "token_count": 103, "parameters": [ "a", "typecode", "savespace" ], "start_line": 43, "end_line": 56, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 14, "top_nesting_level": 0 }, { "name": "asfarray", "long_name": "asfarray( a , typecode = None , savespace = None )", "filename": "type_check.py", "nloc": 5, "complexity": 3, "token_count": 47, "parameters": [ "a", "typecode", "savespace" ], "start_line": 58, "end_line": 63, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 6, "top_nesting_level": 0 }, { "name": "isscalar", "long_name": "isscalar( num )", "filename": "type_check.py", "nloc": 4, "complexity": 3, "token_count": 37, "parameters": [ "num" ], "start_line": 112, "end_line": 115, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 4, "top_nesting_level": 0 }, { "name": "real", "long_name": "real( val )", "filename": "type_check.py", "nloc": 6, "complexity": 2, "token_count": 32, "parameters": [ "val" ], "start_line": 117, "end_line": 122, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 6, "top_nesting_level": 0 }, { "name": "imag", "long_name": "imag( val )", "filename": "type_check.py", "nloc": 6, "complexity": 2, "token_count": 43, "parameters": [ "val" ], "start_line": 124, "end_line": 129, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 6, "top_nesting_level": 0 }, { "name": "iscomplex", "long_name": "iscomplex( x )", "filename": "type_check.py", "nloc": 2, "complexity": 1, "token_count": 22, "parameters": [ "x" ], "start_line": 131, "end_line": 132, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 2, "top_nesting_level": 0 }, { "name": "isreal", "long_name": "isreal( x )", "filename": "type_check.py", "nloc": 2, "complexity": 1, "token_count": 22, "parameters": [ "x" ], "start_line": 134, "end_line": 135, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 2, "top_nesting_level": 0 }, { "name": "iscomplexobj", "long_name": "iscomplexobj( x )", "filename": "type_check.py", "nloc": 2, "complexity": 1, "token_count": 20, "parameters": [ "x" ], "start_line": 137, "end_line": 138, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 2, "top_nesting_level": 0 }, { "name": "isrealobj", "long_name": "isrealobj( x )", "filename": "type_check.py", "nloc": 2, "complexity": 1, "token_count": 21, "parameters": [ "x" ], "start_line": 140, "end_line": 141, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 2, "top_nesting_level": 0 }, { "name": "isposinf", "long_name": "isposinf( val )", "filename": "type_check.py", "nloc": 2, "complexity": 1, "token_count": 16, "parameters": [ "val" ], "start_line": 161, "end_line": 162, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 2, "top_nesting_level": 0 }, { "name": "isneginf", "long_name": "isneginf( val )", "filename": "type_check.py", "nloc": 2, "complexity": 1, "token_count": 16, "parameters": [ "val" ], "start_line": 164, "end_line": 165, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 2, "top_nesting_level": 0 }, { "name": "nan_to_num", "long_name": "nan_to_num( x )", "filename": "type_check.py", "nloc": 17, "complexity": 3, "token_count": 117, "parameters": [ "x" ], "start_line": 182, "end_line": 203, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 22, "top_nesting_level": 0 }, { "name": "real_if_close", "long_name": "real_if_close( a , tol = 1e - 13 )", "filename": "type_check.py", "nloc": 5, "complexity": 3, "token_count": 52, "parameters": [ "a", "tol" ], "start_line": 207, "end_line": 211, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 5, "top_nesting_level": 0 }, { "name": "typename", "long_name": "typename( char )", "filename": "type_check.py", "nloc": 2, "complexity": 1, "token_count": 11, "parameters": [ "char" ], "start_line": 231, "end_line": 234, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 4, "top_nesting_level": 0 }, { "name": "common_type", "long_name": "common_type( * arrays )", "filename": "type_check.py", "nloc": 8, "complexity": 2, "token_count": 54, "parameters": [ "arrays" ], "start_line": 242, "end_line": 249, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 8, "top_nesting_level": 0 } ], "methods_before": [ { "name": "mintypecode", "long_name": "mintypecode( typecodes , typeset = 'DFdf' , default = 'd' , savespace = 0 )", "filename": "type_check.py", "nloc": 12, "complexity": 8, "token_count": 91, "parameters": [ "typecodes", "typeset", "default", "savespace" ], "start_line": 19, "end_line": 39, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 21, "top_nesting_level": 0 }, { "name": "asarray", "long_name": "asarray( a , typecode = None , savespace = None )", "filename": "type_check.py", "nloc": 11, "complexity": 9, "token_count": 103, "parameters": [ "a", "typecode", "savespace" ], "start_line": 41, "end_line": 54, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 14, "top_nesting_level": 0 }, { "name": "asfarray", "long_name": "asfarray( a , typecode = None , savespace = None )", "filename": "type_check.py", "nloc": 5, "complexity": 3, "token_count": 47, "parameters": [ "a", "typecode", "savespace" ], "start_line": 56, "end_line": 61, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 6, "top_nesting_level": 0 }, { "name": "isscalar", "long_name": "isscalar( num )", "filename": "type_check.py", "nloc": 4, "complexity": 3, "token_count": 37, "parameters": [ "num" ], "start_line": 110, "end_line": 113, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 4, "top_nesting_level": 0 }, { "name": "real", "long_name": "real( val )", "filename": "type_check.py", "nloc": 6, "complexity": 2, "token_count": 32, "parameters": [ "val" ], "start_line": 115, "end_line": 120, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 6, "top_nesting_level": 0 }, { "name": "imag", "long_name": "imag( val )", "filename": "type_check.py", "nloc": 6, "complexity": 2, "token_count": 43, "parameters": [ "val" ], "start_line": 122, "end_line": 127, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 6, "top_nesting_level": 0 }, { "name": "iscomplex", "long_name": "iscomplex( x )", "filename": "type_check.py", "nloc": 2, "complexity": 1, "token_count": 22, "parameters": [ "x" ], "start_line": 129, "end_line": 130, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 2, "top_nesting_level": 0 }, { "name": "isreal", "long_name": "isreal( x )", "filename": "type_check.py", "nloc": 2, "complexity": 1, "token_count": 22, "parameters": [ "x" ], "start_line": 132, "end_line": 133, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 2, "top_nesting_level": 0 }, { "name": "iscomplexobj", "long_name": "iscomplexobj( x )", "filename": "type_check.py", "nloc": 2, "complexity": 1, "token_count": 20, "parameters": [ "x" ], "start_line": 135, "end_line": 136, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 2, "top_nesting_level": 0 }, { "name": "isrealobj", "long_name": "isrealobj( x )", "filename": "type_check.py", "nloc": 2, "complexity": 1, "token_count": 21, "parameters": [ "x" ], "start_line": 138, "end_line": 139, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 2, "top_nesting_level": 0 }, { "name": "isposinf", "long_name": "isposinf( val )", "filename": "type_check.py", "nloc": 2, "complexity": 1, "token_count": 16, "parameters": [ "val" ], "start_line": 159, "end_line": 160, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 2, "top_nesting_level": 0 }, { "name": "isneginf", "long_name": "isneginf( val )", "filename": "type_check.py", "nloc": 2, "complexity": 1, "token_count": 16, "parameters": [ "val" ], "start_line": 162, "end_line": 163, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 2, "top_nesting_level": 0 }, { "name": "nan_to_num", "long_name": "nan_to_num( x )", "filename": "type_check.py", "nloc": 17, "complexity": 3, "token_count": 117, "parameters": [ "x" ], "start_line": 180, "end_line": 201, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 22, "top_nesting_level": 0 }, { "name": "real_if_close", "long_name": "real_if_close( a , tol = 1e - 13 )", "filename": "type_check.py", "nloc": 5, "complexity": 3, "token_count": 52, "parameters": [ "a", "tol" ], "start_line": 205, "end_line": 209, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 5, "top_nesting_level": 0 }, { "name": "typename", "long_name": "typename( char )", "filename": "type_check.py", "nloc": 2, "complexity": 1, "token_count": 11, "parameters": [ "char" ], "start_line": 229, "end_line": 232, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 4, "top_nesting_level": 0 }, { "name": "common_type", "long_name": "common_type( * arrays )", "filename": "type_check.py", "nloc": 8, "complexity": 2, "token_count": 54, "parameters": [ "arrays" ], "start_line": 240, "end_line": 247, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 8, "top_nesting_level": 0 } ], "changed_methods": [ { "name": "mintypecode", "long_name": "mintypecode( typecodes , typeset = 'DFdf' , default = 'd' , savespace = 0 )", "filename": "type_check.py", "nloc": 13, "complexity": 11, "token_count": 118, "parameters": [ "typecodes", "typeset", "default", "savespace" ], "start_line": 19, "end_line": 41, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 23, "top_nesting_level": 0 } ], "nloc": 162, "complexity": 45, "token_count": 1326, "diff_parsed": { "added": [ " If t in typecodes is not a string then t=t.typecode() is applied.", " typecodes = [(type(t) is type('') and t) or t.typecode() for t in typecodes]" ], "deleted": [] } }, { "old_path": "scipy_test/testing.py", "new_path": "scipy_test/testing.py", "filename": "testing.py", "extension": "py", "change_type": "MODIFY", "diff": "@@ -4,7 +4,8 @@\n \n ScipyTest - Scipy tests site manager\n ScipyTestCase - unittest.TestCase with measure method\n- set_package_path - use it before importing a module to be tested\n+ set_package_path - prepend package build directory to path\n+ set_local_path - prepend local directory (to tests files) to path\n restore_path - restore path after set_package_path\n \n Timing tools\n", "added_lines": 2, "deleted_lines": 1, "source_code": "\"\"\"\nUnit-testing\n------------\n\n ScipyTest - Scipy tests site manager\n ScipyTestCase - unittest.TestCase with measure method\n set_package_path - prepend package build directory to path\n set_local_path - prepend local directory (to tests files) to path\n restore_path - restore path after set_package_path\n\nTiming tools\n------------\n\n jiffies - return 1/100ths of a second that the current process has used\n memusage - virtual memory size in bytes of the running python [linux]\n\nUtility functions\n-----------------\n\n assert_equal\n assert_almost_equal\n assert_approx_equal\n assert_array_equal\n assert_array_almost_equal\n assert_array_less\n rand - array of random numbers from given shape\n\n\"\"\"\n\n__all__ = []\n\nimport os,sys,time,glob,string,traceback,unittest\nimport types\nimport imp\n\ntry:\n # These are used by Numeric tests.\n # If Numeric and scipy_base are not available, then some of the\n # functions below will not be available.\n from Numeric import alltrue,equal,shape,ravel,around,zeros,Float64,asarray,\\\n less_equal,array2string,less\n # `import scipy_base.fastumath as math` must be at the end of this file.\nexcept ImportError,msg:\n print msg\n\nDEBUG = 0\n\n__all__.append('set_package_path')\ndef set_package_path(level=1):\n \"\"\" Prepend package directory to sys.path.\n\n set_package_path should be called from a test_file.py that\n satisfies the following tree structure:\n\n //test_file.py\n\n Then the first existing path name from the following list\n\n /build/lib.-\n /..\n\n is prepended to sys.path.\n The caller is responsible for removing this path by using\n\n restore_path()\n \"\"\"\n from distutils.util import get_platform\n from scipy_distutils.misc_util import get_frame\n f = get_frame(level)\n if f.f_locals['__name__']=='__main__':\n testfile = sys.argv[0]\n else:\n testfile = f.f_locals['__file__']\n d = os.path.dirname(os.path.dirname(os.path.abspath(testfile)))\n d1 = os.path.join(d,'build','lib.%s-%s'%(get_platform(),sys.version[:3]))\n if not os.path.isdir(d1):\n d1 = os.path.dirname(d)\n if DEBUG:\n print 'Inserting %r to sys.path' % (d1)\n sys.path.insert(0,d1)\n\n__all__.append('set_local_path')\ndef set_local_path(reldir='', level=1):\n \"\"\" Prepend local directory to sys.path.\n\n The caller is responsible for removing this path by using\n\n restore_path()\n \"\"\"\n from scipy_distutils.misc_util import get_frame\n f = get_frame(level)\n if f.f_locals['__name__']=='__main__':\n testfile = sys.argv[0]\n else:\n testfile = f.f_locals['__file__']\n local_path = os.path.join(os.path.dirname(os.path.abspath(testfile)),reldir)\n if DEBUG:\n print 'Inserting %r to sys.path' % (local_path)\n sys.path.insert(0,local_path)\n\n__all__.append('restore_path')\ndef restore_path():\n if DEBUG:\n print 'Removing %r from sys.path' % (sys.path[0])\n del sys.path[0]\n\nif sys.platform[:5]=='linux':\n def jiffies(_proc_pid_stat = '/proc/%s/stat'%(os.getpid()),\n _load_time=time.time()):\n \"\"\" Return number of jiffies (1/100ths of a second) that this\n process has been scheduled in user mode. See man 5 proc. \"\"\"\n try:\n f=open(_proc_pid_stat,'r')\n l = f.readline().split(' ')\n f.close()\n return int(l[13])\n except:\n return int(100*(time.time()-_load_time))\n\n def memusage(_proc_pid_stat = '/proc/%s/stat'%(os.getpid())):\n \"\"\" Return virtual memory size in bytes of the running python.\n \"\"\"\n try:\n f=open(_proc_pid_stat,'r')\n l = f.readline().split(' ')\n f.close()\n return int(l[22])\n except:\n return\nelse:\n # os.getpid is not in all platforms available.\n # Using time is safe but inaccurate, especially when process\n # was suspended or sleeping.\n def jiffies(_load_time=time.time()):\n \"\"\" Return number of jiffies (1/100ths of a second) that this\n process has been scheduled in user mode. [Emulation with time.time]. \"\"\"\n return int(100*(time.time()-_load_time))\n\n def memusage():\n \"\"\" Return memory usage of running python. [Not implemented]\"\"\"\n return\n\n__all__.append('ScipyTestCase')\nclass ScipyTestCase (unittest.TestCase):\n\n def measure(self,code_str,times=1):\n \"\"\" Return elapsed time for executing code_str in the\n namespace of the caller for given times.\n \"\"\"\n frame = sys._getframe(1)\n locs,globs = frame.f_locals,frame.f_globals\n code = compile(code_str,\n 'ScipyTestCase runner for '+self.__class__.__name__,\n 'exec')\n i = 0\n elapsed = jiffies()\n while i>> ScipyTest().test(level=1,verbosity=2)\n\n is package name or its module object.\n\n Package is supposed to contain a directory tests/\n with test_*.py files where * refers to the names of submodules.\n\n test_*.py files are supposed to define a classes, derived\n from ScipyTestCase or unittest.TestCase, with methods having\n names starting with test or bench or check.\n\n And that is it! No need to implement test or test_suite functions\n in each .py file.\n\n Also old styled test_suite(level=1) hooks are supported but\n soon to be removed.\n \"\"\"\n def __init__(self, package='__main__'):\n self.package = package\n\n def _module_str(self, module):\n filename = module.__file__[-30:]\n if filename!=module.__file__:\n filename = '...'+filename\n return '' % (`module.__name__`, `filename`)\n\n def _get_method_names(self,clsobj,level):\n names = []\n for mthname in _get_all_method_names(clsobj):\n if mthname[:5] not in ['bench','check'] \\\n and mthname[:4] not in ['test']:\n continue\n mth = getattr(clsobj, mthname)\n if type(mth) is not types.MethodType:\n continue\n d = mth.im_func.func_defaults\n if d is not None:\n mthlevel = d[0]\n else:\n mthlevel = 1\n if level>=mthlevel:\n if mthname not in names:\n names.append(mthname)\n for base in clsobj.__bases__:\n for n in self._get_method_names(base,level):\n if n not in names:\n names.append(n)\n return names\n\n def _get_module_tests(self,module,level):\n mstr = self._module_str\n d,f = os.path.split(module.__file__)\n\n short_module_name = os.path.splitext(os.path.basename(f))[0]\n if short_module_name=='__init__':\n short_module_name = module.__name__.split('.')[-1]\n\n test_dir = os.path.join(d,'tests')\n test_file = os.path.join(test_dir,'test_'+short_module_name+'.py')\n\n local_test_dir = os.path.join(os.getcwd(),'tests')\n local_test_file = os.path.join(local_test_dir,\n 'test_'+short_module_name+'.py')\n if os.path.basename(os.path.dirname(local_test_dir)) \\\n == os.path.basename(os.path.dirname(test_dir)) \\\n and os.path.isfile(local_test_file):\n test_file = local_test_file\n\n if not os.path.isfile(test_file):\n if short_module_name[:5]=='info_' \\\n and short_module_name[5:]==module.__name__.split('.')[-2]:\n return []\n if short_module_name in ['__cvs_version__','__svn_version__']:\n return []\n if short_module_name[-8:]=='_version' \\\n and short_module_name[:-8]==module.__name__.split('.')[-2]:\n return []\n print ' !! No test file %r found for %s' \\\n % (os.path.basename(test_file), mstr(module))\n return []\n\n try:\n if sys.version[:3]=='2.1':\n # Workaround for Python 2.1 .pyc file generator bug\n import random\n pref = '-nopyc'+`random.randint(1,100)`\n else:\n pref = ''\n f = open(test_file,'r')\n test_module = imp.load_module(\\\n module.__name__+'.test_'+short_module_name+pref,\n f, test_file+pref,('.py', 'r', 1))\n f.close()\n if sys.version[:3]=='2.1' and os.path.isfile(test_file+pref+'c'):\n os.remove(test_file+pref+'c')\n except:\n print ' !! FAILURE importing tests for ', mstr(module)\n print ' ',\n output_exception()\n return []\n return self._get_suite_list(test_module, level, module.__name__)\n\n def _get_suite_list(self, test_module, level, module_name='__main__'):\n mstr = self._module_str\n if hasattr(test_module,'test_suite'):\n # Using old styled test suite\n try:\n total_suite = test_module.test_suite(level)\n return total_suite._tests\n except:\n print ' !! FAILURE building tests for ', mstr(test_module)\n print ' ',\n output_exception()\n return []\n suite_list = []\n for name in dir(test_module):\n obj = getattr(test_module, name)\n if type(obj) is not type(unittest.TestCase) \\\n or not issubclass(obj, unittest.TestCase) \\\n or obj.__name__[:4] != 'test':\n continue\n suite_list.extend(map(obj,self._get_method_names(obj,level)))\n print ' Found',len(suite_list),'tests for',module_name\n return suite_list\n\n def _touch_ppimported(self, module):\n from scipy_base.ppimport import _ModuleLoader\n if os.path.isdir(os.path.join(os.path.dirname(module.__file__),'tests')):\n # only touching those modules that have tests/ directory\n try: module._pliuh_plauh\n except AttributeError: pass\n for name in dir(module):\n obj = getattr(module,name)\n if isinstance(obj,_ModuleLoader) \\\n and not hasattr(obj,'_ppimport_module') \\\n and not hasattr(obj,'_ppimport_exc_info'):\n self._touch_ppimported(obj)\n\n def test(self,level=1,verbosity=1):\n \"\"\" Run Scipy module test suite with level and verbosity.\n \"\"\"\n if type(self.package) is type(''):\n exec 'import %s as this_package' % (self.package)\n else:\n this_package = self.package\n\n self._touch_ppimported(this_package)\n\n package_name = this_package.__name__\n\n suites = []\n for name, module in sys.modules.items():\n if package_name != name[:len(package_name)] \\\n or module is None \\\n or os.path.basename(os.path.dirname(module.__file__))=='tests':\n continue\n suites.extend(self._get_module_tests(module, level))\n\n suites.extend(self._get_suite_list(sys.modules[package_name], level))\n\n all_tests = unittest.TestSuite(suites)\n runner = unittest.TextTestRunner(verbosity=verbosity)\n runner.run(all_tests)\n return runner\n\n def run(self):\n \"\"\" Run Scipy module test suite with level and verbosity\n taken from sys.argv. Requires optparse module.\n \"\"\"\n try:\n from optparse import OptionParser\n except ImportError:\n print 'Failed to import optparse module, ignoring.'\n return self.test()\n usage = r'usage: %prog [-v ] [-l ]'\n parser = OptionParser(usage)\n parser.add_option(\"-v\", \"--verbosity\",\n action=\"store\",\n dest=\"verbosity\",\n default=1,\n type='int')\n parser.add_option(\"-l\", \"--level\",\n action=\"store\",\n dest=\"level\",\n default=1,\n type='int')\n (options, args) = parser.parse_args()\n self.test(options.level,options.verbosity)\n\n#------------\n \ndef remove_ignored_patterns(files,pattern):\n from fnmatch import fnmatch\n good_files = []\n for file in files:\n if not fnmatch(file,pattern):\n good_files.append(file)\n return good_files\n\ndef remove_ignored_files(original,ignored_files,cur_dir):\n \"\"\" This is actually expanded to do pattern matching.\n\n \"\"\"\n if not ignored_files: ignored_files = []\n ignored_modules = map(lambda x: x+'.py',ignored_files)\n ignored_packages = ignored_files[:]\n # always ignore setup.py and __init__.py files\n ignored_files = ['setup.py','setup_*.py','__init__.py']\n ignored_files += ignored_modules + ignored_packages\n ignored_files = map(lambda x,cur_dir=cur_dir: os.path.join(cur_dir,x),\n ignored_files)\n #print 'ignored:', ignored_files\n #good_files = filter(lambda x,ignored = ignored_files: x not in ignored,\n # original)\n good_files = original\n for pattern in ignored_files:\n good_files = remove_ignored_patterns(good_files,pattern)\n\n return good_files\n\n__all__.append('harvest_modules')\ndef harvest_modules(package,ignore=None):\n \"\"\"* Retreive a list of all modules that live within a package.\n\n Only retreive files that are immediate children of the\n package -- do not recurse through child packages or\n directories. The returned list contains actual modules, not\n just their names.\n *\"\"\"\n d,f = os.path.split(package.__file__)\n\n # go through the directory and import every py file there.\n common_dir = os.path.join(d,'*.py')\n py_files = glob.glob(common_dir)\n #py_files.remove(os.path.join(d,'__init__.py'))\n #py_files.remove(os.path.join(d,'setup.py'))\n\n py_files = remove_ignored_files(py_files,ignore,d)\n #print 'py_files:', py_files\n try:\n prefix = package.__name__\n except:\n prefix = ''\n\n all_modules = []\n for file in py_files:\n d,f = os.path.split(file)\n base,ext = os.path.splitext(f)\n mod = prefix + '.' + base\n #print 'module: import ' + mod\n try:\n exec ('import ' + mod)\n all_modules.append(eval(mod))\n except:\n print 'FAILURE to import ' + mod\n output_exception()\n\n return all_modules\n\n__all__.append('harvest_packages')\ndef harvest_packages(package,ignore = None):\n \"\"\" Retreive a list of all sub-packages that live within a package.\n\n Only retreive packages that are immediate children of this\n package -- do not recurse through child packages or\n directories. The returned list contains actual package objects, not\n just their names.\n \"\"\"\n join = os.path.join\n\n d,f = os.path.split(package.__file__)\n\n common_dir = os.path.abspath(d)\n all_files = os.listdir(d)\n\n all_files = remove_ignored_files(all_files,ignore,'')\n #print 'all_files:', all_files\n try:\n prefix = package.__name__\n except:\n prefix = ''\n all_packages = []\n for directory in all_files:\n path = join(common_dir,directory)\n if os.path.isdir(path) and \\\n os.path.exists(join(path,'__init__.py')):\n sub_package = prefix + '.' + directory\n #print 'sub-package import ' + sub_package\n try:\n exec ('import ' + sub_package)\n all_packages.append(eval(sub_package))\n except:\n print 'FAILURE to import ' + sub_package\n output_exception()\n return all_packages\n\n__all__.append('harvest_modules_and_packages')\ndef harvest_modules_and_packages(package,ignore=None):\n \"\"\" Retreive list of all packages and modules that live within a package.\n\n See harvest_packages() and harvest_modules()\n \"\"\"\n all = harvest_modules(package,ignore) + harvest_packages(package,ignore)\n return all\n\n__all__.append('harvest_test_suites')\ndef harvest_test_suites(package,ignore = None,level=10):\n \"\"\"\n package -- the module to test. This is an actual module object\n (not a string)\n ignore -- a list of module names to omit from the tests\n level -- a value between 1 and 10. 1 will run the minimum number\n of tests. This is a fast \"smoke test\". Tests that take\n longer to run should have higher numbers ranging up to 10.\n \"\"\"\n suites=[]\n test_modules = harvest_modules_and_packages(package,ignore)\n #for i in test_modules:\n # print i.__name__\n for module in test_modules:\n if hasattr(module,'test_suite'):\n try:\n suite = module.test_suite(level=level)\n if suite:\n suites.append(suite)\n else:\n print \" !! FAILURE without error - shouldn't happen\",\n print module.__name__\n except:\n print ' !! FAILURE building test for ', module.__name__\n print ' ',\n output_exception()\n else:\n try:\n print 'No test suite found for ', module.__name__\n except AttributeError:\n # __version__.py getting replaced by a string throws a kink\n # in checking for modules, so we think is a module has\n # actually been overwritten\n print 'No test suite found for ', str(module)\n total_suite = unittest.TestSuite(suites)\n return total_suite\n\n__all__.append('module_test')\ndef module_test(mod_name,mod_file,level=10):\n \"\"\"*\n\n *\"\"\"\n #print 'testing', mod_name\n d,f = os.path.split(mod_file)\n\n # insert the tests directory to the python path\n test_dir = os.path.join(d,'tests')\n sys.path.insert(0,test_dir)\n\n # call the \"test_xxx.test()\" function for the appropriate\n # module.\n\n # This should deal with package naming issues correctly\n short_mod_name = string.split(mod_name,'.')[-1]\n test_module = 'test_' + short_mod_name\n test_string = 'import %s;reload(%s);%s.test(%d)' % \\\n ((test_module,)*3 + (level,))\n\n # This would be better cause it forces a reload of the orginal\n # module. It doesn't behave with packages however.\n #test_string = 'reload(%s);import %s;reload(%s);%s.test(%d)' % \\\n # ((mod_name,) + (test_module,)*3)\n exec(test_string)\n\n # remove test directory from python path.\n sys.path = sys.path[1:]\n\n__all__.append('module_test_suite')\ndef module_test_suite(mod_name,mod_file,level=10):\n #try:\n print ' creating test suite for:', mod_name\n d,f = os.path.split(mod_file)\n\n # insert the tests directory to the python path\n test_dir = os.path.join(d,'tests')\n sys.path.insert(0,test_dir)\n\n # call the \"test_xxx.test()\" function for the appropriate\n # module.\n\n # This should deal with package naming issues correctly\n short_mod_name = string.split(mod_name,'.')[-1]\n test_module = 'test_' + short_mod_name\n test_string = 'import %s;reload(%s);suite = %s.test_suite(%d)' % \\\n ((test_module,)*3+(level,))\n #print test_string\n exec(test_string)\n\n # remove test directory from python path.\n sys.path = sys.path[1:]\n return suite\n #except:\n # print ' !! FAILURE loading test suite from', test_module, ':'\n # print ' ',\n # output_exception()\n\n\n# Utility function to facilitate testing.\n\n__all__.append('assert_equal')\ndef assert_equal(actual,desired,err_msg='',verbose=1):\n \"\"\" Raise an assertion if two items are not\n equal. I think this should be part of unittest.py\n \"\"\"\n msg = '\\nItems are not equal:\\n' + err_msg\n try:\n if ( verbose and len(repr(desired)) < 100 and len(repr(actual)) ):\n msg = msg \\\n + 'DESIRED: ' + repr(desired) \\\n + '\\nACTUAL: ' + repr(actual)\n except:\n msg = msg \\\n + 'DESIRED: ' + repr(desired) \\\n + '\\nACTUAL: ' + repr(actual)\n assert desired == actual, msg\n\n__all__.append('assert_almost_equal')\ndef assert_almost_equal(actual,desired,decimal=7,err_msg='',verbose=1):\n \"\"\" Raise an assertion if two items are not\n equal. I think this should be part of unittest.py\n \"\"\"\n msg = '\\nItems are not equal:\\n' + err_msg\n try:\n if ( verbose and len(repr(desired)) < 100 and len(repr(actual)) ):\n msg = msg \\\n + 'DESIRED: ' + repr(desired) \\\n + '\\nACTUAL: ' + repr(actual)\n except:\n msg = msg \\\n + 'DESIRED: ' + repr(desired) \\\n + '\\nACTUAL: ' + repr(actual)\n assert round(abs(desired - actual),decimal) == 0, msg\n\n__all__.append('assert_approx_equal')\ndef assert_approx_equal(actual,desired,significant=7,err_msg='',verbose=1):\n \"\"\" Raise an assertion if two items are not\n equal. I think this should be part of unittest.py\n Approximately equal is defined as the number of significant digits\n correct\n \"\"\"\n msg = '\\nItems are not equal to %d significant digits:\\n' % significant\n msg += err_msg\n actual, desired = map(float, (actual, desired))\n # Normalized the numbers to be in range (-10.0,10.0)\n scale = pow(10,math.floor(math.log10(0.5*(abs(desired)+abs(actual)))))\n try:\n sc_desired = desired/scale\n except ZeroDivisionError:\n sc_desired = 0.0\n try:\n sc_actual = actual/scale\n except ZeroDivisionError:\n sc_actual = 0.0\n try:\n if ( verbose and len(repr(desired)) < 100 and len(repr(actual)) ):\n msg = msg \\\n + 'DESIRED: ' + repr(desired) \\\n + '\\nACTUAL: ' + repr(actual)\n except:\n msg = msg \\\n + 'DESIRED: ' + repr(desired) \\\n + '\\nACTUAL: ' + repr(actual)\n assert math.fabs(sc_desired - sc_actual) < pow(10.,-1*significant), msg\n\n\n__all__.append('assert_array_equal')\ndef assert_array_equal(x,y,err_msg=''):\n x,y = asarray(x), asarray(y)\n msg = '\\nArrays are not equal'\n try:\n assert 0 in [len(shape(x)),len(shape(y))] \\\n or (len(shape(x))==len(shape(y)) and \\\n alltrue(equal(shape(x),shape(y)))),\\\n msg + ' (shapes %s, %s mismatch):\\n\\t' \\\n % (shape(x),shape(y)) + err_msg\n reduced = ravel(equal(x,y))\n cond = alltrue(reduced)\n if not cond:\n s1 = array2string(x,precision=16)\n s2 = array2string(y,precision=16)\n if len(s1)>120: s1 = s1[:120] + '...'\n if len(s2)>120: s2 = s2[:120] + '...'\n match = 100-100.0*reduced.tolist().count(1)/len(reduced)\n msg = msg + ' (mismatch %s%%):\\n\\tArray 1: %s\\n\\tArray 2: %s' % (match,s1,s2)\n assert cond,\\\n msg + '\\n\\t' + err_msg\n except ValueError:\n raise ValueError, msg\n\n__all__.append('assert_array_almost_equal')\ndef assert_array_almost_equal(x,y,decimal=6,err_msg=''):\n x = asarray(x)\n y = asarray(y)\n msg = '\\nArrays are not almost equal'\n try:\n cond = alltrue(equal(shape(x),shape(y)))\n if not cond:\n msg = msg + ' (shapes mismatch):\\n\\t'\\\n 'Shape of array 1: %s\\n\\tShape of array 2: %s' % (shape(x),shape(y))\n assert cond, msg + '\\n\\t' + err_msg\n reduced = ravel(equal(less_equal(around(abs(x-y),decimal),10.0**(-decimal)),1))\n cond = alltrue(reduced)\n if not cond:\n s1 = array2string(x,precision=decimal+1)\n s2 = array2string(y,precision=decimal+1)\n if len(s1)>120: s1 = s1[:120] + '...'\n if len(s2)>120: s2 = s2[:120] + '...'\n match = 100-100.0*reduced.tolist().count(1)/len(reduced)\n msg = msg + ' (mismatch %s%%):\\n\\tArray 1: %s\\n\\tArray 2: %s' % (match,s1,s2)\n assert cond,\\\n msg + '\\n\\t' + err_msg\n except ValueError:\n print sys.exc_value\n print shape(x),shape(y)\n print x, y\n raise ValueError, 'arrays are not almost equal'\n\n__all__.append('assert_array_less')\ndef assert_array_less(x,y,err_msg=''):\n x,y = asarray(x), asarray(y)\n msg = '\\nArrays are not less-ordered'\n try:\n assert alltrue(equal(shape(x),shape(y))),\\\n msg + ' (shapes mismatch):\\n\\t' + err_msg\n reduced = ravel(less(x,y))\n cond = alltrue(reduced)\n if not cond:\n s1 = array2string(x,precision=16)\n s2 = array2string(y,precision=16)\n if len(s1)>120: s1 = s1[:120] + '...'\n if len(s2)>120: s2 = s2[:120] + '...'\n match = 100-100.0*reduced.tolist().count(1)/len(reduced)\n msg = msg + ' (mismatch %s%%):\\n\\tArray 1: %s\\n\\tArray 2: %s' % (match,s1,s2)\n assert cond,\\\n msg + '\\n\\t' + err_msg\n except ValueError:\n print shape(x),shape(y)\n raise ValueError, 'arrays are not less-ordered'\n\n__all__.append('rand')\ndef rand(*args):\n \"\"\" Returns an array of random numbers with the given shape.\n used for testing\n \"\"\"\n import random\n results = zeros(args,Float64)\n f = results.flat\n for i in range(len(f)):\n f[i] = random.random()\n return results\n\ndef output_exception():\n try:\n type, value, tb = sys.exc_info()\n info = traceback.extract_tb(tb)\n #this is more verbose\n #traceback.print_exc()\n filename, lineno, function, text = info[-1] # last line only\n print \"%s:%d: %s: %s (in %s)\" %\\\n (filename, lineno, type.__name__, str(value), function)\n finally:\n type = value = tb = None # clean up\n\ntry:\n import scipy_base.fastumath as math\nexcept ImportError,msg:\n print msg\n import math\n", "source_code_before": "\"\"\"\nUnit-testing\n------------\n\n ScipyTest - Scipy tests site manager\n ScipyTestCase - unittest.TestCase with measure method\n set_package_path - use it before importing a module to be tested\n restore_path - restore path after set_package_path\n\nTiming tools\n------------\n\n jiffies - return 1/100ths of a second that the current process has used\n memusage - virtual memory size in bytes of the running python [linux]\n\nUtility functions\n-----------------\n\n assert_equal\n assert_almost_equal\n assert_approx_equal\n assert_array_equal\n assert_array_almost_equal\n assert_array_less\n rand - array of random numbers from given shape\n\n\"\"\"\n\n__all__ = []\n\nimport os,sys,time,glob,string,traceback,unittest\nimport types\nimport imp\n\ntry:\n # These are used by Numeric tests.\n # If Numeric and scipy_base are not available, then some of the\n # functions below will not be available.\n from Numeric import alltrue,equal,shape,ravel,around,zeros,Float64,asarray,\\\n less_equal,array2string,less\n # `import scipy_base.fastumath as math` must be at the end of this file.\nexcept ImportError,msg:\n print msg\n\nDEBUG = 0\n\n__all__.append('set_package_path')\ndef set_package_path(level=1):\n \"\"\" Prepend package directory to sys.path.\n\n set_package_path should be called from a test_file.py that\n satisfies the following tree structure:\n\n //test_file.py\n\n Then the first existing path name from the following list\n\n /build/lib.-\n /..\n\n is prepended to sys.path.\n The caller is responsible for removing this path by using\n\n restore_path()\n \"\"\"\n from distutils.util import get_platform\n from scipy_distutils.misc_util import get_frame\n f = get_frame(level)\n if f.f_locals['__name__']=='__main__':\n testfile = sys.argv[0]\n else:\n testfile = f.f_locals['__file__']\n d = os.path.dirname(os.path.dirname(os.path.abspath(testfile)))\n d1 = os.path.join(d,'build','lib.%s-%s'%(get_platform(),sys.version[:3]))\n if not os.path.isdir(d1):\n d1 = os.path.dirname(d)\n if DEBUG:\n print 'Inserting %r to sys.path' % (d1)\n sys.path.insert(0,d1)\n\n__all__.append('set_local_path')\ndef set_local_path(reldir='', level=1):\n \"\"\" Prepend local directory to sys.path.\n\n The caller is responsible for removing this path by using\n\n restore_path()\n \"\"\"\n from scipy_distutils.misc_util import get_frame\n f = get_frame(level)\n if f.f_locals['__name__']=='__main__':\n testfile = sys.argv[0]\n else:\n testfile = f.f_locals['__file__']\n local_path = os.path.join(os.path.dirname(os.path.abspath(testfile)),reldir)\n if DEBUG:\n print 'Inserting %r to sys.path' % (local_path)\n sys.path.insert(0,local_path)\n\n__all__.append('restore_path')\ndef restore_path():\n if DEBUG:\n print 'Removing %r from sys.path' % (sys.path[0])\n del sys.path[0]\n\nif sys.platform[:5]=='linux':\n def jiffies(_proc_pid_stat = '/proc/%s/stat'%(os.getpid()),\n _load_time=time.time()):\n \"\"\" Return number of jiffies (1/100ths of a second) that this\n process has been scheduled in user mode. See man 5 proc. \"\"\"\n try:\n f=open(_proc_pid_stat,'r')\n l = f.readline().split(' ')\n f.close()\n return int(l[13])\n except:\n return int(100*(time.time()-_load_time))\n\n def memusage(_proc_pid_stat = '/proc/%s/stat'%(os.getpid())):\n \"\"\" Return virtual memory size in bytes of the running python.\n \"\"\"\n try:\n f=open(_proc_pid_stat,'r')\n l = f.readline().split(' ')\n f.close()\n return int(l[22])\n except:\n return\nelse:\n # os.getpid is not in all platforms available.\n # Using time is safe but inaccurate, especially when process\n # was suspended or sleeping.\n def jiffies(_load_time=time.time()):\n \"\"\" Return number of jiffies (1/100ths of a second) that this\n process has been scheduled in user mode. [Emulation with time.time]. \"\"\"\n return int(100*(time.time()-_load_time))\n\n def memusage():\n \"\"\" Return memory usage of running python. [Not implemented]\"\"\"\n return\n\n__all__.append('ScipyTestCase')\nclass ScipyTestCase (unittest.TestCase):\n\n def measure(self,code_str,times=1):\n \"\"\" Return elapsed time for executing code_str in the\n namespace of the caller for given times.\n \"\"\"\n frame = sys._getframe(1)\n locs,globs = frame.f_locals,frame.f_globals\n code = compile(code_str,\n 'ScipyTestCase runner for '+self.__class__.__name__,\n 'exec')\n i = 0\n elapsed = jiffies()\n while i>> ScipyTest().test(level=1,verbosity=2)\n\n is package name or its module object.\n\n Package is supposed to contain a directory tests/\n with test_*.py files where * refers to the names of submodules.\n\n test_*.py files are supposed to define a classes, derived\n from ScipyTestCase or unittest.TestCase, with methods having\n names starting with test or bench or check.\n\n And that is it! No need to implement test or test_suite functions\n in each .py file.\n\n Also old styled test_suite(level=1) hooks are supported but\n soon to be removed.\n \"\"\"\n def __init__(self, package='__main__'):\n self.package = package\n\n def _module_str(self, module):\n filename = module.__file__[-30:]\n if filename!=module.__file__:\n filename = '...'+filename\n return '' % (`module.__name__`, `filename`)\n\n def _get_method_names(self,clsobj,level):\n names = []\n for mthname in _get_all_method_names(clsobj):\n if mthname[:5] not in ['bench','check'] \\\n and mthname[:4] not in ['test']:\n continue\n mth = getattr(clsobj, mthname)\n if type(mth) is not types.MethodType:\n continue\n d = mth.im_func.func_defaults\n if d is not None:\n mthlevel = d[0]\n else:\n mthlevel = 1\n if level>=mthlevel:\n if mthname not in names:\n names.append(mthname)\n for base in clsobj.__bases__:\n for n in self._get_method_names(base,level):\n if n not in names:\n names.append(n)\n return names\n\n def _get_module_tests(self,module,level):\n mstr = self._module_str\n d,f = os.path.split(module.__file__)\n\n short_module_name = os.path.splitext(os.path.basename(f))[0]\n if short_module_name=='__init__':\n short_module_name = module.__name__.split('.')[-1]\n\n test_dir = os.path.join(d,'tests')\n test_file = os.path.join(test_dir,'test_'+short_module_name+'.py')\n\n local_test_dir = os.path.join(os.getcwd(),'tests')\n local_test_file = os.path.join(local_test_dir,\n 'test_'+short_module_name+'.py')\n if os.path.basename(os.path.dirname(local_test_dir)) \\\n == os.path.basename(os.path.dirname(test_dir)) \\\n and os.path.isfile(local_test_file):\n test_file = local_test_file\n\n if not os.path.isfile(test_file):\n if short_module_name[:5]=='info_' \\\n and short_module_name[5:]==module.__name__.split('.')[-2]:\n return []\n if short_module_name in ['__cvs_version__','__svn_version__']:\n return []\n if short_module_name[-8:]=='_version' \\\n and short_module_name[:-8]==module.__name__.split('.')[-2]:\n return []\n print ' !! No test file %r found for %s' \\\n % (os.path.basename(test_file), mstr(module))\n return []\n\n try:\n if sys.version[:3]=='2.1':\n # Workaround for Python 2.1 .pyc file generator bug\n import random\n pref = '-nopyc'+`random.randint(1,100)`\n else:\n pref = ''\n f = open(test_file,'r')\n test_module = imp.load_module(\\\n module.__name__+'.test_'+short_module_name+pref,\n f, test_file+pref,('.py', 'r', 1))\n f.close()\n if sys.version[:3]=='2.1' and os.path.isfile(test_file+pref+'c'):\n os.remove(test_file+pref+'c')\n except:\n print ' !! FAILURE importing tests for ', mstr(module)\n print ' ',\n output_exception()\n return []\n return self._get_suite_list(test_module, level, module.__name__)\n\n def _get_suite_list(self, test_module, level, module_name='__main__'):\n mstr = self._module_str\n if hasattr(test_module,'test_suite'):\n # Using old styled test suite\n try:\n total_suite = test_module.test_suite(level)\n return total_suite._tests\n except:\n print ' !! FAILURE building tests for ', mstr(test_module)\n print ' ',\n output_exception()\n return []\n suite_list = []\n for name in dir(test_module):\n obj = getattr(test_module, name)\n if type(obj) is not type(unittest.TestCase) \\\n or not issubclass(obj, unittest.TestCase) \\\n or obj.__name__[:4] != 'test':\n continue\n suite_list.extend(map(obj,self._get_method_names(obj,level)))\n print ' Found',len(suite_list),'tests for',module_name\n return suite_list\n\n def _touch_ppimported(self, module):\n from scipy_base.ppimport import _ModuleLoader\n if os.path.isdir(os.path.join(os.path.dirname(module.__file__),'tests')):\n # only touching those modules that have tests/ directory\n try: module._pliuh_plauh\n except AttributeError: pass\n for name in dir(module):\n obj = getattr(module,name)\n if isinstance(obj,_ModuleLoader) \\\n and not hasattr(obj,'_ppimport_module') \\\n and not hasattr(obj,'_ppimport_exc_info'):\n self._touch_ppimported(obj)\n\n def test(self,level=1,verbosity=1):\n \"\"\" Run Scipy module test suite with level and verbosity.\n \"\"\"\n if type(self.package) is type(''):\n exec 'import %s as this_package' % (self.package)\n else:\n this_package = self.package\n\n self._touch_ppimported(this_package)\n\n package_name = this_package.__name__\n\n suites = []\n for name, module in sys.modules.items():\n if package_name != name[:len(package_name)] \\\n or module is None \\\n or os.path.basename(os.path.dirname(module.__file__))=='tests':\n continue\n suites.extend(self._get_module_tests(module, level))\n\n suites.extend(self._get_suite_list(sys.modules[package_name], level))\n\n all_tests = unittest.TestSuite(suites)\n runner = unittest.TextTestRunner(verbosity=verbosity)\n runner.run(all_tests)\n return runner\n\n def run(self):\n \"\"\" Run Scipy module test suite with level and verbosity\n taken from sys.argv. Requires optparse module.\n \"\"\"\n try:\n from optparse import OptionParser\n except ImportError:\n print 'Failed to import optparse module, ignoring.'\n return self.test()\n usage = r'usage: %prog [-v ] [-l ]'\n parser = OptionParser(usage)\n parser.add_option(\"-v\", \"--verbosity\",\n action=\"store\",\n dest=\"verbosity\",\n default=1,\n type='int')\n parser.add_option(\"-l\", \"--level\",\n action=\"store\",\n dest=\"level\",\n default=1,\n type='int')\n (options, args) = parser.parse_args()\n self.test(options.level,options.verbosity)\n\n#------------\n \ndef remove_ignored_patterns(files,pattern):\n from fnmatch import fnmatch\n good_files = []\n for file in files:\n if not fnmatch(file,pattern):\n good_files.append(file)\n return good_files\n\ndef remove_ignored_files(original,ignored_files,cur_dir):\n \"\"\" This is actually expanded to do pattern matching.\n\n \"\"\"\n if not ignored_files: ignored_files = []\n ignored_modules = map(lambda x: x+'.py',ignored_files)\n ignored_packages = ignored_files[:]\n # always ignore setup.py and __init__.py files\n ignored_files = ['setup.py','setup_*.py','__init__.py']\n ignored_files += ignored_modules + ignored_packages\n ignored_files = map(lambda x,cur_dir=cur_dir: os.path.join(cur_dir,x),\n ignored_files)\n #print 'ignored:', ignored_files\n #good_files = filter(lambda x,ignored = ignored_files: x not in ignored,\n # original)\n good_files = original\n for pattern in ignored_files:\n good_files = remove_ignored_patterns(good_files,pattern)\n\n return good_files\n\n__all__.append('harvest_modules')\ndef harvest_modules(package,ignore=None):\n \"\"\"* Retreive a list of all modules that live within a package.\n\n Only retreive files that are immediate children of the\n package -- do not recurse through child packages or\n directories. The returned list contains actual modules, not\n just their names.\n *\"\"\"\n d,f = os.path.split(package.__file__)\n\n # go through the directory and import every py file there.\n common_dir = os.path.join(d,'*.py')\n py_files = glob.glob(common_dir)\n #py_files.remove(os.path.join(d,'__init__.py'))\n #py_files.remove(os.path.join(d,'setup.py'))\n\n py_files = remove_ignored_files(py_files,ignore,d)\n #print 'py_files:', py_files\n try:\n prefix = package.__name__\n except:\n prefix = ''\n\n all_modules = []\n for file in py_files:\n d,f = os.path.split(file)\n base,ext = os.path.splitext(f)\n mod = prefix + '.' + base\n #print 'module: import ' + mod\n try:\n exec ('import ' + mod)\n all_modules.append(eval(mod))\n except:\n print 'FAILURE to import ' + mod\n output_exception()\n\n return all_modules\n\n__all__.append('harvest_packages')\ndef harvest_packages(package,ignore = None):\n \"\"\" Retreive a list of all sub-packages that live within a package.\n\n Only retreive packages that are immediate children of this\n package -- do not recurse through child packages or\n directories. The returned list contains actual package objects, not\n just their names.\n \"\"\"\n join = os.path.join\n\n d,f = os.path.split(package.__file__)\n\n common_dir = os.path.abspath(d)\n all_files = os.listdir(d)\n\n all_files = remove_ignored_files(all_files,ignore,'')\n #print 'all_files:', all_files\n try:\n prefix = package.__name__\n except:\n prefix = ''\n all_packages = []\n for directory in all_files:\n path = join(common_dir,directory)\n if os.path.isdir(path) and \\\n os.path.exists(join(path,'__init__.py')):\n sub_package = prefix + '.' + directory\n #print 'sub-package import ' + sub_package\n try:\n exec ('import ' + sub_package)\n all_packages.append(eval(sub_package))\n except:\n print 'FAILURE to import ' + sub_package\n output_exception()\n return all_packages\n\n__all__.append('harvest_modules_and_packages')\ndef harvest_modules_and_packages(package,ignore=None):\n \"\"\" Retreive list of all packages and modules that live within a package.\n\n See harvest_packages() and harvest_modules()\n \"\"\"\n all = harvest_modules(package,ignore) + harvest_packages(package,ignore)\n return all\n\n__all__.append('harvest_test_suites')\ndef harvest_test_suites(package,ignore = None,level=10):\n \"\"\"\n package -- the module to test. This is an actual module object\n (not a string)\n ignore -- a list of module names to omit from the tests\n level -- a value between 1 and 10. 1 will run the minimum number\n of tests. This is a fast \"smoke test\". Tests that take\n longer to run should have higher numbers ranging up to 10.\n \"\"\"\n suites=[]\n test_modules = harvest_modules_and_packages(package,ignore)\n #for i in test_modules:\n # print i.__name__\n for module in test_modules:\n if hasattr(module,'test_suite'):\n try:\n suite = module.test_suite(level=level)\n if suite:\n suites.append(suite)\n else:\n print \" !! FAILURE without error - shouldn't happen\",\n print module.__name__\n except:\n print ' !! FAILURE building test for ', module.__name__\n print ' ',\n output_exception()\n else:\n try:\n print 'No test suite found for ', module.__name__\n except AttributeError:\n # __version__.py getting replaced by a string throws a kink\n # in checking for modules, so we think is a module has\n # actually been overwritten\n print 'No test suite found for ', str(module)\n total_suite = unittest.TestSuite(suites)\n return total_suite\n\n__all__.append('module_test')\ndef module_test(mod_name,mod_file,level=10):\n \"\"\"*\n\n *\"\"\"\n #print 'testing', mod_name\n d,f = os.path.split(mod_file)\n\n # insert the tests directory to the python path\n test_dir = os.path.join(d,'tests')\n sys.path.insert(0,test_dir)\n\n # call the \"test_xxx.test()\" function for the appropriate\n # module.\n\n # This should deal with package naming issues correctly\n short_mod_name = string.split(mod_name,'.')[-1]\n test_module = 'test_' + short_mod_name\n test_string = 'import %s;reload(%s);%s.test(%d)' % \\\n ((test_module,)*3 + (level,))\n\n # This would be better cause it forces a reload of the orginal\n # module. It doesn't behave with packages however.\n #test_string = 'reload(%s);import %s;reload(%s);%s.test(%d)' % \\\n # ((mod_name,) + (test_module,)*3)\n exec(test_string)\n\n # remove test directory from python path.\n sys.path = sys.path[1:]\n\n__all__.append('module_test_suite')\ndef module_test_suite(mod_name,mod_file,level=10):\n #try:\n print ' creating test suite for:', mod_name\n d,f = os.path.split(mod_file)\n\n # insert the tests directory to the python path\n test_dir = os.path.join(d,'tests')\n sys.path.insert(0,test_dir)\n\n # call the \"test_xxx.test()\" function for the appropriate\n # module.\n\n # This should deal with package naming issues correctly\n short_mod_name = string.split(mod_name,'.')[-1]\n test_module = 'test_' + short_mod_name\n test_string = 'import %s;reload(%s);suite = %s.test_suite(%d)' % \\\n ((test_module,)*3+(level,))\n #print test_string\n exec(test_string)\n\n # remove test directory from python path.\n sys.path = sys.path[1:]\n return suite\n #except:\n # print ' !! FAILURE loading test suite from', test_module, ':'\n # print ' ',\n # output_exception()\n\n\n# Utility function to facilitate testing.\n\n__all__.append('assert_equal')\ndef assert_equal(actual,desired,err_msg='',verbose=1):\n \"\"\" Raise an assertion if two items are not\n equal. I think this should be part of unittest.py\n \"\"\"\n msg = '\\nItems are not equal:\\n' + err_msg\n try:\n if ( verbose and len(repr(desired)) < 100 and len(repr(actual)) ):\n msg = msg \\\n + 'DESIRED: ' + repr(desired) \\\n + '\\nACTUAL: ' + repr(actual)\n except:\n msg = msg \\\n + 'DESIRED: ' + repr(desired) \\\n + '\\nACTUAL: ' + repr(actual)\n assert desired == actual, msg\n\n__all__.append('assert_almost_equal')\ndef assert_almost_equal(actual,desired,decimal=7,err_msg='',verbose=1):\n \"\"\" Raise an assertion if two items are not\n equal. I think this should be part of unittest.py\n \"\"\"\n msg = '\\nItems are not equal:\\n' + err_msg\n try:\n if ( verbose and len(repr(desired)) < 100 and len(repr(actual)) ):\n msg = msg \\\n + 'DESIRED: ' + repr(desired) \\\n + '\\nACTUAL: ' + repr(actual)\n except:\n msg = msg \\\n + 'DESIRED: ' + repr(desired) \\\n + '\\nACTUAL: ' + repr(actual)\n assert round(abs(desired - actual),decimal) == 0, msg\n\n__all__.append('assert_approx_equal')\ndef assert_approx_equal(actual,desired,significant=7,err_msg='',verbose=1):\n \"\"\" Raise an assertion if two items are not\n equal. I think this should be part of unittest.py\n Approximately equal is defined as the number of significant digits\n correct\n \"\"\"\n msg = '\\nItems are not equal to %d significant digits:\\n' % significant\n msg += err_msg\n actual, desired = map(float, (actual, desired))\n # Normalized the numbers to be in range (-10.0,10.0)\n scale = pow(10,math.floor(math.log10(0.5*(abs(desired)+abs(actual)))))\n try:\n sc_desired = desired/scale\n except ZeroDivisionError:\n sc_desired = 0.0\n try:\n sc_actual = actual/scale\n except ZeroDivisionError:\n sc_actual = 0.0\n try:\n if ( verbose and len(repr(desired)) < 100 and len(repr(actual)) ):\n msg = msg \\\n + 'DESIRED: ' + repr(desired) \\\n + '\\nACTUAL: ' + repr(actual)\n except:\n msg = msg \\\n + 'DESIRED: ' + repr(desired) \\\n + '\\nACTUAL: ' + repr(actual)\n assert math.fabs(sc_desired - sc_actual) < pow(10.,-1*significant), msg\n\n\n__all__.append('assert_array_equal')\ndef assert_array_equal(x,y,err_msg=''):\n x,y = asarray(x), asarray(y)\n msg = '\\nArrays are not equal'\n try:\n assert 0 in [len(shape(x)),len(shape(y))] \\\n or (len(shape(x))==len(shape(y)) and \\\n alltrue(equal(shape(x),shape(y)))),\\\n msg + ' (shapes %s, %s mismatch):\\n\\t' \\\n % (shape(x),shape(y)) + err_msg\n reduced = ravel(equal(x,y))\n cond = alltrue(reduced)\n if not cond:\n s1 = array2string(x,precision=16)\n s2 = array2string(y,precision=16)\n if len(s1)>120: s1 = s1[:120] + '...'\n if len(s2)>120: s2 = s2[:120] + '...'\n match = 100-100.0*reduced.tolist().count(1)/len(reduced)\n msg = msg + ' (mismatch %s%%):\\n\\tArray 1: %s\\n\\tArray 2: %s' % (match,s1,s2)\n assert cond,\\\n msg + '\\n\\t' + err_msg\n except ValueError:\n raise ValueError, msg\n\n__all__.append('assert_array_almost_equal')\ndef assert_array_almost_equal(x,y,decimal=6,err_msg=''):\n x = asarray(x)\n y = asarray(y)\n msg = '\\nArrays are not almost equal'\n try:\n cond = alltrue(equal(shape(x),shape(y)))\n if not cond:\n msg = msg + ' (shapes mismatch):\\n\\t'\\\n 'Shape of array 1: %s\\n\\tShape of array 2: %s' % (shape(x),shape(y))\n assert cond, msg + '\\n\\t' + err_msg\n reduced = ravel(equal(less_equal(around(abs(x-y),decimal),10.0**(-decimal)),1))\n cond = alltrue(reduced)\n if not cond:\n s1 = array2string(x,precision=decimal+1)\n s2 = array2string(y,precision=decimal+1)\n if len(s1)>120: s1 = s1[:120] + '...'\n if len(s2)>120: s2 = s2[:120] + '...'\n match = 100-100.0*reduced.tolist().count(1)/len(reduced)\n msg = msg + ' (mismatch %s%%):\\n\\tArray 1: %s\\n\\tArray 2: %s' % (match,s1,s2)\n assert cond,\\\n msg + '\\n\\t' + err_msg\n except ValueError:\n print sys.exc_value\n print shape(x),shape(y)\n print x, y\n raise ValueError, 'arrays are not almost equal'\n\n__all__.append('assert_array_less')\ndef assert_array_less(x,y,err_msg=''):\n x,y = asarray(x), asarray(y)\n msg = '\\nArrays are not less-ordered'\n try:\n assert alltrue(equal(shape(x),shape(y))),\\\n msg + ' (shapes mismatch):\\n\\t' + err_msg\n reduced = ravel(less(x,y))\n cond = alltrue(reduced)\n if not cond:\n s1 = array2string(x,precision=16)\n s2 = array2string(y,precision=16)\n if len(s1)>120: s1 = s1[:120] + '...'\n if len(s2)>120: s2 = s2[:120] + '...'\n match = 100-100.0*reduced.tolist().count(1)/len(reduced)\n msg = msg + ' (mismatch %s%%):\\n\\tArray 1: %s\\n\\tArray 2: %s' % (match,s1,s2)\n assert cond,\\\n msg + '\\n\\t' + err_msg\n except ValueError:\n print shape(x),shape(y)\n raise ValueError, 'arrays are not less-ordered'\n\n__all__.append('rand')\ndef rand(*args):\n \"\"\" Returns an array of random numbers with the given shape.\n used for testing\n \"\"\"\n import random\n results = zeros(args,Float64)\n f = results.flat\n for i in range(len(f)):\n f[i] = random.random()\n return results\n\ndef output_exception():\n try:\n type, value, tb = sys.exc_info()\n info = traceback.extract_tb(tb)\n #this is more verbose\n #traceback.print_exc()\n filename, lineno, function, text = info[-1] # last line only\n print \"%s:%d: %s: %s (in %s)\" %\\\n (filename, lineno, type.__name__, str(value), function)\n finally:\n type = value = tb = None # clean up\n\ntry:\n import scipy_base.fastumath as math\nexcept ImportError,msg:\n print msg\n import math\n", "methods": [ { "name": "set_package_path", "long_name": "set_package_path( level = 1 )", "filename": "testing.py", "nloc": 15, "complexity": 4, "token_count": 146, "parameters": [ "level" ], "start_line": 49, "end_line": 80, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 32, "top_nesting_level": 0 }, { "name": "set_local_path", "long_name": "set_local_path( reldir = '' , level = 1 )", "filename": "testing.py", "nloc": 11, "complexity": 3, "token_count": 97, "parameters": [ "reldir", "level" ], "start_line": 83, "end_line": 99, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 17, "top_nesting_level": 0 }, { "name": "restore_path", "long_name": "restore_path( )", "filename": "testing.py", "nloc": 4, "complexity": 2, "token_count": 25, "parameters": [], "start_line": 102, "end_line": 105, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 4, "top_nesting_level": 0 }, { "name": "jiffies", "long_name": "jiffies( _proc_pid_stat = '/proc/%s/stat' % ( os . getpid ( )", "filename": "testing.py", "nloc": 2, "complexity": 1, "token_count": 23, "parameters": [ "_proc_pid_stat" ], "start_line": 108, "end_line": 109, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 2, "top_nesting_level": 1 }, { "name": "memusage", "long_name": "memusage( _proc_pid_stat = '/proc/%s/stat' % ( os . getpid ( )", "filename": "testing.py", "nloc": 10, "complexity": 2, "token_count": 54, "parameters": [ "_proc_pid_stat" ], "start_line": 120, "end_line": 129, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 10, "top_nesting_level": 1 }, { "name": "jiffies", "long_name": "jiffies( _load_time = time . time ( )", "filename": "testing.py", "nloc": 4, "complexity": 1, "token_count": 27, "parameters": [ "_load_time" ], "start_line": 134, "end_line": 137, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 4, "top_nesting_level": 1 }, { "name": "memusage", "long_name": "memusage( )", "filename": "testing.py", "nloc": 2, "complexity": 1, "token_count": 6, "parameters": [], "start_line": 139, "end_line": 141, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 3, "top_nesting_level": 1 }, { "name": "measure", "long_name": "measure( self , code_str , times = 1 )", "filename": "testing.py", "nloc": 13, "complexity": 2, "token_count": 82, "parameters": [ "self", "code_str", "times" ], "start_line": 146, "end_line": 161, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 16, "top_nesting_level": 1 }, { "name": "__call__", "long_name": "__call__( self , result = None )", "filename": "testing.py", "nloc": 19, "complexity": 5, "token_count": 175, "parameters": [ "self", "result" ], "start_line": 163, "end_line": 182, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 20, "top_nesting_level": 1 }, { "name": "__init__", "long_name": "__init__( self )", "filename": "testing.py", "nloc": 2, "complexity": 1, "token_count": 11, "parameters": [ "self" ], "start_line": 185, "end_line": 186, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 2, "top_nesting_level": 1 }, { "name": "write", "long_name": "write( self , message )", "filename": "testing.py", "nloc": 2, "complexity": 1, "token_count": 15, "parameters": [ "self", "message" ], "start_line": 187, "end_line": 188, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 2, "top_nesting_level": 1 }, { "name": "writeln", "long_name": "writeln( self , message )", "filename": "testing.py", "nloc": 2, "complexity": 1, "token_count": 17, "parameters": [ "self", "message" ], "start_line": 189, "end_line": 190, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 2, "top_nesting_level": 1 }, { "name": "_get_all_method_names", "long_name": "_get_all_method_names( cls )", "filename": "testing.py", "nloc": 8, "complexity": 5, "token_count": 56, "parameters": [ "cls" ], "start_line": 198, "end_line": 205, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 8, "top_nesting_level": 0 }, { "name": "__init__", "long_name": "__init__( self , package = '__main__' )", "filename": "testing.py", "nloc": 2, "complexity": 1, "token_count": 14, "parameters": [ "self", "package" ], "start_line": 229, "end_line": 230, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 2, "top_nesting_level": 1 }, { "name": "_module_str", "long_name": "_module_str( self , module )", "filename": "testing.py", "nloc": 5, "complexity": 2, "token_count": 43, "parameters": [ "self", "module" ], "start_line": 232, "end_line": 236, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 5, "top_nesting_level": 1 }, { "name": "_get_method_names", "long_name": "_get_method_names( self , clsobj , level )", "filename": "testing.py", "nloc": 22, "complexity": 11, "token_count": 142, "parameters": [ "self", "clsobj", "level" ], "start_line": 238, "end_line": 259, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 22, "top_nesting_level": 1 }, { "name": "_get_module_tests", "long_name": "_get_module_tests( self , module , level )", "filename": "testing.py", "nloc": 46, "complexity": 14, "token_count": 428, "parameters": [ "self", "module", "level" ], "start_line": 261, "end_line": 312, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 52, "top_nesting_level": 1 }, { "name": "_get_suite_list", "long_name": "_get_suite_list( self , test_module , level , module_name = '__main__' )", "filename": "testing.py", "nloc": 21, "complexity": 7, "token_count": 146, "parameters": [ "self", "test_module", "level", "module_name" ], "start_line": 314, "end_line": 335, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 22, "top_nesting_level": 1 }, { "name": "_touch_ppimported", "long_name": "_touch_ppimported( self , module )", "filename": "testing.py", "nloc": 11, "complexity": 7, "token_count": 98, "parameters": [ "self", "module" ], "start_line": 337, "end_line": 348, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 12, "top_nesting_level": 1 }, { "name": "test", "long_name": "test( self , level = 1 , verbosity = 1 )", "filename": "testing.py", "nloc": 19, "complexity": 6, "token_count": 166, "parameters": [ "self", "level", "verbosity" ], "start_line": 350, "end_line": 375, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 26, "top_nesting_level": 1 }, { "name": "run", "long_name": "run( self )", "filename": "testing.py", "nloc": 20, "complexity": 2, "token_count": 104, "parameters": [ "self" ], "start_line": 377, "end_line": 399, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 23, "top_nesting_level": 1 }, { "name": "remove_ignored_patterns", "long_name": "remove_ignored_patterns( files , pattern )", "filename": "testing.py", "nloc": 7, "complexity": 3, "token_count": 37, "parameters": [ "files", "pattern" ], "start_line": 403, "end_line": 409, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 7, "top_nesting_level": 0 }, { "name": "remove_ignored_files", "long_name": "remove_ignored_files( original , ignored_files , cur_dir )", "filename": "testing.py", "nloc": 12, "complexity": 3, "token_count": 93, "parameters": [ "original", "ignored_files", "cur_dir" ], "start_line": 411, "end_line": 430, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 20, "top_nesting_level": 0 }, { "name": "harvest_modules", "long_name": "harvest_modules( package , ignore = None )", "filename": "testing.py", "nloc": 21, "complexity": 4, "token_count": 134, "parameters": [ "package", "ignore" ], "start_line": 433, "end_line": 469, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 37, "top_nesting_level": 0 }, { "name": "harvest_packages", "long_name": "harvest_packages( package , ignore = None )", "filename": "testing.py", "nloc": 23, "complexity": 6, "token_count": 148, "parameters": [ "package", "ignore" ], "start_line": 472, "end_line": 506, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 35, "top_nesting_level": 0 }, { "name": "harvest_modules_and_packages", "long_name": "harvest_modules_and_packages( package , ignore = None )", "filename": "testing.py", "nloc": 3, "complexity": 1, "token_count": 27, "parameters": [ "package", "ignore" ], "start_line": 509, "end_line": 515, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 7, "top_nesting_level": 0 }, { "name": "harvest_test_suites", "long_name": "harvest_test_suites( package , ignore = None , level = 10 )", "filename": "testing.py", "nloc": 23, "complexity": 6, "token_count": 113, "parameters": [ "package", "ignore", "level" ], "start_line": 518, "end_line": 553, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 36, "top_nesting_level": 0 }, { "name": "module_test", "long_name": "module_test( mod_name , mod_file , level = 10 )", "filename": "testing.py", "nloc": 10, "complexity": 1, "token_count": 98, "parameters": [ "mod_name", "mod_file", "level" ], "start_line": 556, "end_line": 583, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 28, "top_nesting_level": 0 }, { "name": "module_test_suite", "long_name": "module_test_suite( mod_name , mod_file , level = 10 )", "filename": "testing.py", "nloc": 12, "complexity": 1, "token_count": 103, "parameters": [ "mod_name", "mod_file", "level" ], "start_line": 586, "end_line": 608, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 23, "top_nesting_level": 0 }, { "name": "assert_equal", "long_name": "assert_equal( actual , desired , err_msg = '' , verbose = 1 )", "filename": "testing.py", "nloc": 12, "complexity": 5, "token_count": 92, "parameters": [ "actual", "desired", "err_msg", "verbose" ], "start_line": 618, "end_line": 632, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 15, "top_nesting_level": 0 }, { "name": "assert_almost_equal", "long_name": "assert_almost_equal( actual , desired , decimal = 7 , err_msg = '' , verbose = 1 )", "filename": "testing.py", "nloc": 12, "complexity": 5, "token_count": 106, "parameters": [ "actual", "desired", "decimal", "err_msg", "verbose" ], "start_line": 635, "end_line": 649, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 15, "top_nesting_level": 0 }, { "name": "assert_approx_equal", "long_name": "assert_approx_equal( actual , desired , significant = 7 , err_msg = '' , verbose = 1 )", "filename": "testing.py", "nloc": 23, "complexity": 7, "token_count": 191, "parameters": [ "actual", "desired", "significant", "err_msg", "verbose" ], "start_line": 652, "end_line": 680, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 29, "top_nesting_level": 0 }, { "name": "assert_array_equal", "long_name": "assert_array_equal( x , y , err_msg = '' )", "filename": "testing.py", "nloc": 22, "complexity": 7, "token_count": 232, "parameters": [ "x", "y", "err_msg" ], "start_line": 684, "end_line": 705, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 22, "top_nesting_level": 0 }, { "name": "assert_array_almost_equal", "long_name": "assert_array_almost_equal( x , y , decimal = 6 , err_msg = '' )", "filename": "testing.py", "nloc": 26, "complexity": 6, "token_count": 251, "parameters": [ "x", "y", "decimal", "err_msg" ], "start_line": 708, "end_line": 733, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 26, "top_nesting_level": 0 }, { "name": "assert_array_less", "long_name": "assert_array_less( x , y , err_msg = '' )", "filename": "testing.py", "nloc": 20, "complexity": 5, "token_count": 189, "parameters": [ "x", "y", "err_msg" ], "start_line": 736, "end_line": 755, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 20, "top_nesting_level": 0 }, { "name": "rand", "long_name": "rand( * args )", "filename": "testing.py", "nloc": 7, "complexity": 2, "token_count": 45, "parameters": [ "args" ], "start_line": 758, "end_line": 767, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 10, "top_nesting_level": 0 }, { "name": "output_exception", "long_name": "output_exception( )", "filename": "testing.py", "nloc": 9, "complexity": 2, "token_count": 67, "parameters": [], "start_line": 769, "end_line": 779, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 11, "top_nesting_level": 0 } ], "methods_before": [ { "name": "set_package_path", "long_name": "set_package_path( level = 1 )", "filename": "testing.py", "nloc": 15, "complexity": 4, "token_count": 146, "parameters": [ "level" ], "start_line": 48, "end_line": 79, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 32, "top_nesting_level": 0 }, { "name": "set_local_path", "long_name": "set_local_path( reldir = '' , level = 1 )", "filename": "testing.py", "nloc": 11, "complexity": 3, "token_count": 97, "parameters": [ "reldir", "level" ], "start_line": 82, "end_line": 98, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 17, "top_nesting_level": 0 }, { "name": "restore_path", "long_name": "restore_path( )", "filename": "testing.py", "nloc": 4, "complexity": 2, "token_count": 25, "parameters": [], "start_line": 101, "end_line": 104, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 4, "top_nesting_level": 0 }, { "name": "jiffies", "long_name": "jiffies( _proc_pid_stat = '/proc/%s/stat' % ( os . getpid ( )", "filename": "testing.py", "nloc": 2, "complexity": 1, "token_count": 23, "parameters": [ "_proc_pid_stat" ], "start_line": 107, "end_line": 108, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 2, "top_nesting_level": 1 }, { "name": "memusage", "long_name": "memusage( _proc_pid_stat = '/proc/%s/stat' % ( os . getpid ( )", "filename": "testing.py", "nloc": 10, "complexity": 2, "token_count": 54, "parameters": [ "_proc_pid_stat" ], "start_line": 119, "end_line": 128, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 10, "top_nesting_level": 1 }, { "name": "jiffies", "long_name": "jiffies( _load_time = time . time ( )", "filename": "testing.py", "nloc": 4, "complexity": 1, "token_count": 27, "parameters": [ "_load_time" ], "start_line": 133, "end_line": 136, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 4, "top_nesting_level": 1 }, { "name": "memusage", "long_name": "memusage( )", "filename": "testing.py", "nloc": 2, "complexity": 1, "token_count": 6, "parameters": [], "start_line": 138, "end_line": 140, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 3, "top_nesting_level": 1 }, { "name": "measure", "long_name": "measure( self , code_str , times = 1 )", "filename": "testing.py", "nloc": 13, "complexity": 2, "token_count": 82, "parameters": [ "self", "code_str", "times" ], "start_line": 145, "end_line": 160, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 16, "top_nesting_level": 1 }, { "name": "__call__", "long_name": "__call__( self , result = None )", "filename": "testing.py", "nloc": 19, "complexity": 5, "token_count": 175, "parameters": [ "self", "result" ], "start_line": 162, "end_line": 181, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 20, "top_nesting_level": 1 }, { "name": "__init__", "long_name": "__init__( self )", "filename": "testing.py", "nloc": 2, "complexity": 1, "token_count": 11, "parameters": [ "self" ], "start_line": 184, "end_line": 185, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 2, "top_nesting_level": 1 }, { "name": "write", "long_name": "write( self , message )", "filename": "testing.py", "nloc": 2, "complexity": 1, "token_count": 15, "parameters": [ "self", "message" ], "start_line": 186, "end_line": 187, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 2, "top_nesting_level": 1 }, { "name": "writeln", "long_name": "writeln( self , message )", "filename": "testing.py", "nloc": 2, "complexity": 1, "token_count": 17, "parameters": [ "self", "message" ], "start_line": 188, "end_line": 189, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 2, "top_nesting_level": 1 }, { "name": "_get_all_method_names", "long_name": "_get_all_method_names( cls )", "filename": "testing.py", "nloc": 8, "complexity": 5, "token_count": 56, "parameters": [ "cls" ], "start_line": 197, "end_line": 204, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 8, "top_nesting_level": 0 }, { "name": "__init__", "long_name": "__init__( self , package = '__main__' )", "filename": "testing.py", "nloc": 2, "complexity": 1, "token_count": 14, "parameters": [ "self", "package" ], "start_line": 228, "end_line": 229, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 2, "top_nesting_level": 1 }, { "name": "_module_str", "long_name": "_module_str( self , module )", "filename": "testing.py", "nloc": 5, "complexity": 2, "token_count": 43, "parameters": [ "self", "module" ], "start_line": 231, "end_line": 235, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 5, "top_nesting_level": 1 }, { "name": "_get_method_names", "long_name": "_get_method_names( self , clsobj , level )", "filename": "testing.py", "nloc": 22, "complexity": 11, "token_count": 142, "parameters": [ "self", "clsobj", "level" ], "start_line": 237, "end_line": 258, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 22, "top_nesting_level": 1 }, { "name": "_get_module_tests", "long_name": "_get_module_tests( self , module , level )", "filename": "testing.py", "nloc": 46, "complexity": 14, "token_count": 428, "parameters": [ "self", "module", "level" ], "start_line": 260, "end_line": 311, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 52, "top_nesting_level": 1 }, { "name": "_get_suite_list", "long_name": "_get_suite_list( self , test_module , level , module_name = '__main__' )", "filename": "testing.py", "nloc": 21, "complexity": 7, "token_count": 146, "parameters": [ "self", "test_module", "level", "module_name" ], "start_line": 313, "end_line": 334, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 22, "top_nesting_level": 1 }, { "name": "_touch_ppimported", "long_name": "_touch_ppimported( self , module )", "filename": "testing.py", "nloc": 11, "complexity": 7, "token_count": 98, "parameters": [ "self", "module" ], "start_line": 336, "end_line": 347, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 12, "top_nesting_level": 1 }, { "name": "test", "long_name": "test( self , level = 1 , verbosity = 1 )", "filename": "testing.py", "nloc": 19, "complexity": 6, "token_count": 166, "parameters": [ "self", "level", "verbosity" ], "start_line": 349, "end_line": 374, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 26, "top_nesting_level": 1 }, { "name": "run", "long_name": "run( self )", "filename": "testing.py", "nloc": 20, "complexity": 2, "token_count": 104, "parameters": [ "self" ], "start_line": 376, "end_line": 398, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 23, "top_nesting_level": 1 }, { "name": "remove_ignored_patterns", "long_name": "remove_ignored_patterns( files , pattern )", "filename": "testing.py", "nloc": 7, "complexity": 3, "token_count": 37, "parameters": [ "files", "pattern" ], "start_line": 402, "end_line": 408, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 7, "top_nesting_level": 0 }, { "name": "remove_ignored_files", "long_name": "remove_ignored_files( original , ignored_files , cur_dir )", "filename": "testing.py", "nloc": 12, "complexity": 3, "token_count": 93, "parameters": [ "original", "ignored_files", "cur_dir" ], "start_line": 410, "end_line": 429, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 20, "top_nesting_level": 0 }, { "name": "harvest_modules", "long_name": "harvest_modules( package , ignore = None )", "filename": "testing.py", "nloc": 21, "complexity": 4, "token_count": 134, "parameters": [ "package", "ignore" ], "start_line": 432, "end_line": 468, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 37, "top_nesting_level": 0 }, { "name": "harvest_packages", "long_name": "harvest_packages( package , ignore = None )", "filename": "testing.py", "nloc": 23, "complexity": 6, "token_count": 148, "parameters": [ "package", "ignore" ], "start_line": 471, "end_line": 505, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 35, "top_nesting_level": 0 }, { "name": "harvest_modules_and_packages", "long_name": "harvest_modules_and_packages( package , ignore = None )", "filename": "testing.py", "nloc": 3, "complexity": 1, "token_count": 27, "parameters": [ "package", "ignore" ], "start_line": 508, "end_line": 514, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 7, "top_nesting_level": 0 }, { "name": "harvest_test_suites", "long_name": "harvest_test_suites( package , ignore = None , level = 10 )", "filename": "testing.py", "nloc": 23, "complexity": 6, "token_count": 113, "parameters": [ "package", "ignore", "level" ], "start_line": 517, "end_line": 552, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 36, "top_nesting_level": 0 }, { "name": "module_test", "long_name": "module_test( mod_name , mod_file , level = 10 )", "filename": "testing.py", "nloc": 10, "complexity": 1, "token_count": 98, "parameters": [ "mod_name", "mod_file", "level" ], "start_line": 555, "end_line": 582, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 28, "top_nesting_level": 0 }, { "name": "module_test_suite", "long_name": "module_test_suite( mod_name , mod_file , level = 10 )", "filename": "testing.py", "nloc": 12, "complexity": 1, "token_count": 103, "parameters": [ "mod_name", "mod_file", "level" ], "start_line": 585, "end_line": 607, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 23, "top_nesting_level": 0 }, { "name": "assert_equal", "long_name": "assert_equal( actual , desired , err_msg = '' , verbose = 1 )", "filename": "testing.py", "nloc": 12, "complexity": 5, "token_count": 92, "parameters": [ "actual", "desired", "err_msg", "verbose" ], "start_line": 617, "end_line": 631, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 15, "top_nesting_level": 0 }, { "name": "assert_almost_equal", "long_name": "assert_almost_equal( actual , desired , decimal = 7 , err_msg = '' , verbose = 1 )", "filename": "testing.py", "nloc": 12, "complexity": 5, "token_count": 106, "parameters": [ "actual", "desired", "decimal", "err_msg", "verbose" ], "start_line": 634, "end_line": 648, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 15, "top_nesting_level": 0 }, { "name": "assert_approx_equal", "long_name": "assert_approx_equal( actual , desired , significant = 7 , err_msg = '' , verbose = 1 )", "filename": "testing.py", "nloc": 23, "complexity": 7, "token_count": 191, "parameters": [ "actual", "desired", "significant", "err_msg", "verbose" ], "start_line": 651, "end_line": 679, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 29, "top_nesting_level": 0 }, { "name": "assert_array_equal", "long_name": "assert_array_equal( x , y , err_msg = '' )", "filename": "testing.py", "nloc": 22, "complexity": 7, "token_count": 232, "parameters": [ "x", "y", "err_msg" ], "start_line": 683, "end_line": 704, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 22, "top_nesting_level": 0 }, { "name": "assert_array_almost_equal", "long_name": "assert_array_almost_equal( x , y , decimal = 6 , err_msg = '' )", "filename": "testing.py", "nloc": 26, "complexity": 6, "token_count": 251, "parameters": [ "x", "y", "decimal", "err_msg" ], "start_line": 707, "end_line": 732, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 26, "top_nesting_level": 0 }, { "name": "assert_array_less", "long_name": "assert_array_less( x , y , err_msg = '' )", "filename": "testing.py", "nloc": 20, "complexity": 5, "token_count": 189, "parameters": [ "x", "y", "err_msg" ], "start_line": 735, "end_line": 754, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 20, "top_nesting_level": 0 }, { "name": "rand", "long_name": "rand( * args )", "filename": "testing.py", "nloc": 7, "complexity": 2, "token_count": 45, "parameters": [ "args" ], "start_line": 757, "end_line": 766, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 10, "top_nesting_level": 0 }, { "name": "output_exception", "long_name": "output_exception( )", "filename": "testing.py", "nloc": 9, "complexity": 2, "token_count": 67, "parameters": [], "start_line": 768, "end_line": 778, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 11, "top_nesting_level": 0 } ], "changed_methods": [], "nloc": 580, "complexity": 143, "token_count": 4117, "diff_parsed": { "added": [ " set_package_path - prepend package build directory to path", " set_local_path - prepend local directory (to tests files) to path" ], "deleted": [ " set_package_path - use it before importing a module to be tested" ] } } ] }, { "hash": "afdbe1880e03014b8a1076005af858d4e52e85fa", "msg": "Join code segments with newlines in between.", "author": { "name": "Robert Kern", "email": "robert.kern@gmail.com" }, "committer": { "name": "Robert Kern", "email": "robert.kern@gmail.com" }, "author_date": "2004-11-24T01:17:46+00:00", "author_timezone": 0, "committer_date": "2004-11-24T01:17:46+00:00", "committer_timezone": 0, "branches": [ "main" ], "in_main_branch": true, "merge": false, "parents": [ "537e4ea67dde56d26165d7351677d83fad016189" ], "project_name": "repo_copy", "project_path": "/tmp/tmpqop781_j/repo_copy", "deletions": 6, "insertions": 6, "lines": 12, "files": 1, "dmm_unit_size": null, "dmm_unit_complexity": null, "dmm_unit_interfacing": null, "modified_files": [ { "old_path": "weave/ext_tools.py", "new_path": "weave/ext_tools.py", "filename": "ext_tools.py", "extension": "py", "change_type": "MODIFY", "diff": "@@ -191,12 +191,12 @@ def __init__(self,name,compiler=''):\n def add_function(self,func):\n self.functions.append(func)\n def module_code(self):\n- code = self.warning_code() + \\\n- self.header_code() + \\\n- self.support_code() + \\\n- self.function_code() + \\\n- self.python_function_definition_code() + \\\n- self.module_init_code()\n+ code = '\\n'.join([self.warning_code(),\n+ self.header_code(),\n+ self.support_code(),\n+ self.function_code(),\n+ self.python_function_definition_code(),\n+ self.module_init_code()])\n return code\n \n def arg_specs(self):\n", "added_lines": 6, "deleted_lines": 6, "source_code": "import os, sys\nimport string, re\n\nimport catalog \nimport build_tools\nimport converters\nimport base_spec\n\nclass ext_function_from_specs:\n def __init__(self,name,code_block,arg_specs):\n self.name = name\n self.arg_specs = base_spec.arg_spec_list(arg_specs)\n self.code_block = code_block\n self.compiler = ''\n self.customize = base_info.custom_info()\n \n def header_code(self):\n pass\n\n def function_declaration_code(self):\n code = 'static PyObject* %s(PyObject*self, PyObject* args,' \\\n ' PyObject* kywds)\\n{\\n'\n return code % self.name\n\n def template_declaration_code(self):\n code = 'template\\n' \\\n 'static PyObject* %s(PyObject*self, PyObject* args,' \\\n ' PyObject* kywds)\\n{\\n'\n return code % self.name\n\n #def cpp_function_declaration_code(self):\n # pass\n #def cpp_function_call_code(self):\n #s pass\n \n def parse_tuple_code(self):\n \"\"\" Create code block for PyArg_ParseTuple. Variable declarations\n for all PyObjects are done also.\n \n This code got a lot uglier when I added local_dict...\n \"\"\"\n join = string.join\n\n declare_return = 'py::object return_val;\\n' \\\n 'int exception_occured = 0;\\n' \\\n 'PyObject *py_local_dict = NULL;\\n'\n arg_string_list = self.arg_specs.variable_as_strings() + ['\"local_dict\"']\n arg_strings = join(arg_string_list,',')\n if arg_strings: arg_strings += ','\n declare_kwlist = 'static char *kwlist[] = {%s NULL};\\n' % arg_strings\n\n py_objects = join(self.arg_specs.py_pointers(),', ')\n init_flags = join(self.arg_specs.init_flags(),', ')\n init_flags_init = join(self.arg_specs.init_flags(),'= ')\n py_vars = join(self.arg_specs.py_variables(),' = ')\n if py_objects:\n declare_py_objects = 'PyObject ' + py_objects +';\\n'\n declare_py_objects += 'int '+ init_flags + ';\\n' \n init_values = py_vars + ' = NULL;\\n'\n init_values += init_flags_init + ' = 0;\\n\\n'\n else:\n declare_py_objects = ''\n init_values = '' \n\n #Each variable is in charge of its own cleanup now.\n #cnt = len(arg_list)\n #declare_cleanup = \"blitz::TinyVector clean_up(0);\\n\" % cnt\n\n ref_string = join(self.arg_specs.py_references(),', ')\n if ref_string:\n ref_string += ', &py_local_dict'\n else:\n ref_string = '&py_local_dict'\n \n format = \"O\"* len(self.arg_specs) + \"|O\" + ':' + self.name\n parse_tuple = 'if(!PyArg_ParseTupleAndKeywords(args,' \\\n 'kywds,\"%s\",kwlist,%s))\\n' % (format,ref_string)\n parse_tuple += ' return NULL;\\n'\n\n return declare_return + declare_kwlist + declare_py_objects \\\n + init_values + parse_tuple\n\n def arg_declaration_code(self):\n arg_strings = []\n for arg in self.arg_specs:\n arg_strings.append(arg.declaration_code())\n arg_strings.append(arg.init_flag() +\" = 1;\\n\")\n code = string.join(arg_strings,\"\")\n return code\n\n def arg_cleanup_code(self):\n arg_strings = []\n have_cleanup = filter(lambda x:x.cleanup_code(),self.arg_specs)\n for arg in have_cleanup:\n code = \"if(%s)\\n\" % arg.init_flag()\n code += \"{\\n\"\n code += indent(arg.cleanup_code(),4)\n code += \"}\\n\"\n arg_strings.append(code)\n code = string.join(arg_strings,\"\")\n return code\n\n def arg_local_dict_code(self):\n arg_strings = []\n for arg in self.arg_specs:\n arg_strings.append(arg.local_dict_code())\n code = string.join(arg_strings,\"\")\n return code\n \n def function_code(self):\n decl_code = indent(self.arg_declaration_code(),4)\n cleanup_code = indent(self.arg_cleanup_code(),4)\n function_code = indent(self.code_block,4)\n local_dict_code = indent(self.arg_local_dict_code(),4)\n\n dict_code = \"if(py_local_dict) \\n\" \\\n \"{ \\n\" \\\n \" py::dict local_dict = py::dict(py_local_dict); \\n\" + \\\n local_dict_code + \\\n \"} \\n\"\n\n try_code = \"try \\n\" \\\n \"{ \\n\" + \\\n decl_code + \\\n \" /**/ \\n\" + \\\n function_code + \\\n indent(dict_code,4) + \\\n \"\\n} \\n\"\n catch_code = \"catch(...) \\n\" \\\n \"{ \\n\" + \\\n \" return_val = py::object(); \\n\" \\\n \" exception_occured = 1; \\n\" \\\n \"} \\n\"\n\n return_code = \" /*cleanup code*/ \\n\" + \\\n cleanup_code + \\\n ' if(!(PyObject*)return_val && !exception_occured)\\n' \\\n ' {\\n \\n' \\\n ' return_val = Py_None; \\n' \\\n ' }\\n \\n' \\\n ' return return_val.disown(); \\n' \\\n '} \\n'\n\n all_code = self.function_declaration_code() + \\\n indent(self.parse_tuple_code(),4) + \\\n indent(try_code,4) + \\\n indent(catch_code,4) + \\\n return_code\n\n return all_code\n\n def python_function_definition_code(self):\n args = (self.name, self.name)\n function_decls = '{\"%s\",(PyCFunction)%s , METH_VARARGS|' \\\n 'METH_KEYWORDS},\\n' % args\n return function_decls\n\n def set_compiler(self,compiler):\n self.compiler = compiler\n for arg in self.arg_specs:\n arg.set_compiler(compiler)\n\n\nclass ext_function(ext_function_from_specs):\n def __init__(self,name,code_block, args, local_dict=None, global_dict=None,\n auto_downcast=1, type_converters=None):\n \n call_frame = sys._getframe().f_back\n if local_dict is None:\n local_dict = call_frame.f_locals\n if global_dict is None:\n global_dict = call_frame.f_globals\n if type_converters is None:\n type_converters = converters.default\n arg_specs = assign_variable_types(args,local_dict, global_dict,\n auto_downcast, type_converters)\n ext_function_from_specs.__init__(self,name,code_block,arg_specs)\n \n \nimport base_info\n\nclass ext_module:\n def __init__(self,name,compiler=''):\n standard_info = converters.standard_info\n self.name = name\n self.functions = []\n self.compiler = compiler\n self.customize = base_info.custom_info()\n self._build_information = base_info.info_list(standard_info)\n \n def add_function(self,func):\n self.functions.append(func)\n def module_code(self):\n code = '\\n'.join([self.warning_code(),\n self.header_code(),\n self.support_code(),\n self.function_code(),\n self.python_function_definition_code(),\n self.module_init_code()])\n return code\n\n def arg_specs(self):\n all_arg_specs = base_spec.arg_spec_list()\n for func in self.functions:\n all_arg_specs += func.arg_specs\n return all_arg_specs\n\n def build_information(self):\n info = self._build_information + [self.customize] + \\\n self.arg_specs().build_information()\n for func in self.functions:\n info.append(func.customize)\n #redundant, but easiest place to make sure compiler is set\n for i in info:\n i.set_compiler(self.compiler)\n return info\n \n def get_headers(self):\n all_headers = self.build_information().headers()\n\n # blitz/array.h always needs to be first so we hack that here...\n if '\"blitz/array.h\"' in all_headers:\n all_headers.remove('\"blitz/array.h\"')\n all_headers.insert(0,'\"blitz/array.h\"')\n return all_headers\n\n def warning_code(self):\n all_warnings = self.build_information().warnings()\n w=map(lambda x: \"#pragma warning(%s)\\n\" % x,all_warnings)\n return ''.join(w)\n \n def header_code(self):\n h = self.get_headers()\n h= map(lambda x: '#include ' + x + '\\n',h)\n return ''.join(h) + '\\n'\n\n def support_code(self):\n code = self.build_information().support_code()\n return ''.join(code) + '\\n'\n\n def function_code(self):\n all_function_code = \"\"\n for func in self.functions:\n all_function_code += func.function_code()\n return ''.join(all_function_code) + '\\n'\n\n def python_function_definition_code(self):\n all_definition_code = \"\"\n for func in self.functions:\n all_definition_code += func.python_function_definition_code()\n all_definition_code = indent(''.join(all_definition_code),4)\n code = 'static PyMethodDef compiled_methods[] = \\n' \\\n '{\\n' \\\n '%s' \\\n ' {NULL, NULL} /* Sentinel */\\n' \\\n '};\\n'\n return code % (all_definition_code)\n\n def module_init_code(self):\n init_code_list = self.build_information().module_init_code()\n init_code = indent(''.join(init_code_list),4)\n code = 'extern \"C\" void init%s()\\n' \\\n '{\\n' \\\n '%s' \\\n ' (void) Py_InitModule(\"%s\", compiled_methods);\\n' \\\n '}\\n' % (self.name,init_code,self.name)\n return code\n\n def generate_file(self,file_name=\"\",location='.'):\n code = self.module_code()\n if not file_name:\n file_name = self.name + '.cpp'\n name = generate_file_name(file_name,location)\n #return name\n return generate_module(code,name)\n\n def set_compiler(self,compiler):\n # This is not used anymore -- I think we should ditch it.\n #for i in self.arg_specs()\n # i.set_compiler(compiler)\n for i in self.build_information():\n i.set_compiler(compiler) \n for i in self.functions:\n i.set_compiler(compiler)\n self.compiler = compiler \n\n def build_kw_and_file(self,location,kw): \n arg_specs = self.arg_specs()\n info = self.build_information()\n _source_files = info.sources()\n # remove duplicates\n source_files = {}\n for i in _source_files:\n source_files[i] = None\n source_files = source_files.keys()\n \n # add internally specified macros, includes, etc. to the key words\n # values of the same names so that distutils will use them.\n kw['define_macros'] = kw.get('define_macros',[]) + \\\n info.define_macros()\n kw['include_dirs'] = kw.get('include_dirs',[]) + info.include_dirs()\n kw['libraries'] = kw.get('libraries',[]) + info.libraries()\n kw['library_dirs'] = kw.get('library_dirs',[]) + info.library_dirs()\n kw['extra_compile_args'] = kw.get('extra_compile_args',[]) + \\\n info.extra_compile_args()\n kw['extra_link_args'] = kw.get('extra_link_args',[]) + \\\n info.extra_link_args()\n kw['sources'] = kw.get('sources',[]) + source_files \n file = self.generate_file(location=location)\n return kw,file\n \n def setup_extension(self,location='.',**kw):\n kw,file = self.build_kw_and_file(location,kw)\n return build_tools.create_extension(file, **kw)\n \n def compile(self,location='.',compiler=None, verbose = 0, **kw):\n \n if compiler is not None:\n self.compiler = compiler\n \n # !! removed -- we don't have any compiler dependent code\n # currently in spec or info classes \n # hmm. Is there a cleaner way to do this? Seems like\n # choosing the compiler spagettis around a little. \n #compiler = build_tools.choose_compiler(self.compiler) \n #self.set_compiler(compiler)\n \n kw,file = self.build_kw_and_file(location,kw)\n \n # This is needed so that files build correctly even when different\n # versions of Python are running around.\n # Imported at beginning of file now to help with test paths.\n # import catalog \n #temp = catalog.default_temp_dir()\n # for speed, build in the machines temp directory\n temp = catalog.intermediate_dir()\n \n success = build_tools.build_extension(file, temp_dir = temp,\n compiler_name = compiler,\n verbose = verbose, **kw)\n if not success:\n raise SystemError, 'Compilation failed'\n\ndef generate_file_name(module_name,module_location):\n module_file = os.path.join(module_location,module_name)\n return os.path.abspath(module_file)\n\ndef generate_module(module_string, module_file):\n \"\"\" generate the source code file. Only overwrite\n the existing file if the actual source has changed.\n \"\"\"\n file_changed = 1\n if os.path.exists(module_file):\n f =open(module_file,'r')\n old_string = f.read()\n f.close()\n if old_string == module_string:\n file_changed = 0\n if file_changed:\n f =open(module_file,'w')\n f.write(module_string)\n f.close()\n return module_file\n\ndef assign_variable_types(variables,local_dict = {}, global_dict = {},\n auto_downcast = 1,\n type_converters = converters.default):\n incoming_vars = {}\n incoming_vars.update(global_dict)\n incoming_vars.update(local_dict)\n variable_specs = []\n errors={}\n for var in variables:\n try:\n example_type = incoming_vars[var]\n\n # look through possible type specs to find which one\n # should be used to for example_type\n spec = None\n for factory in type_converters:\n if factory.type_match(example_type):\n spec = factory.type_spec(var,example_type)\n break \n if not spec:\n # should really define our own type.\n raise IndexError\n else:\n variable_specs.append(spec)\n except KeyError:\n errors[var] = (\"The type and dimensionality specifications\" +\n \"for variable '\" + var + \"' are missing.\")\n except IndexError:\n errors[var] = (\"Unable to convert variable '\"+ var +\n \"' to a C++ type.\")\n if errors:\n raise TypeError, format_error_msg(errors)\n\n if auto_downcast:\n variable_specs = downcast(variable_specs)\n return variable_specs\n\ndef downcast(var_specs):\n \"\"\" Cast python scalars down to most common type of\n arrays used.\n\n Right now, focus on complex and float types. Ignore int types.\n Require all arrays to have same type before forcing downcasts.\n\n Note: var_specs are currently altered in place (horrors...!)\n \"\"\"\n numeric_types = []\n\n #grab all the numeric types associated with a variables.\n for var in var_specs:\n if hasattr(var,'numeric_type'):\n numeric_types.append(var.numeric_type)\n\n # if arrays are present, but none of them are double precision,\n # make all numeric types float or complex(float)\n if ( ('f' in numeric_types or 'F' in numeric_types) and\n not ('d' in numeric_types or 'D' in numeric_types) ):\n for var in var_specs:\n if hasattr(var,'numeric_type'):\n # really should do this some other way...\n if var.numeric_type == type(1+1j):\n var.numeric_type = 'F'\n elif var.numeric_type == type(1.):\n var.numeric_type = 'f'\n return var_specs\n\ndef indent(st,spaces):\n indention = ' '*spaces\n indented = indention + string.replace(st,'\\n','\\n'+indention)\n # trim off any trailing spaces\n indented = re.sub(r' +$',r'',indented)\n return indented\n\ndef format_error_msg(errors):\n #minimum effort right now...\n import pprint,cStringIO\n msg = cStringIO.StringIO()\n pprint.pprint(errors,msg)\n return msg.getvalue()\n", "source_code_before": "import os, sys\nimport string, re\n\nimport catalog \nimport build_tools\nimport converters\nimport base_spec\n\nclass ext_function_from_specs:\n def __init__(self,name,code_block,arg_specs):\n self.name = name\n self.arg_specs = base_spec.arg_spec_list(arg_specs)\n self.code_block = code_block\n self.compiler = ''\n self.customize = base_info.custom_info()\n \n def header_code(self):\n pass\n\n def function_declaration_code(self):\n code = 'static PyObject* %s(PyObject*self, PyObject* args,' \\\n ' PyObject* kywds)\\n{\\n'\n return code % self.name\n\n def template_declaration_code(self):\n code = 'template\\n' \\\n 'static PyObject* %s(PyObject*self, PyObject* args,' \\\n ' PyObject* kywds)\\n{\\n'\n return code % self.name\n\n #def cpp_function_declaration_code(self):\n # pass\n #def cpp_function_call_code(self):\n #s pass\n \n def parse_tuple_code(self):\n \"\"\" Create code block for PyArg_ParseTuple. Variable declarations\n for all PyObjects are done also.\n \n This code got a lot uglier when I added local_dict...\n \"\"\"\n join = string.join\n\n declare_return = 'py::object return_val;\\n' \\\n 'int exception_occured = 0;\\n' \\\n 'PyObject *py_local_dict = NULL;\\n'\n arg_string_list = self.arg_specs.variable_as_strings() + ['\"local_dict\"']\n arg_strings = join(arg_string_list,',')\n if arg_strings: arg_strings += ','\n declare_kwlist = 'static char *kwlist[] = {%s NULL};\\n' % arg_strings\n\n py_objects = join(self.arg_specs.py_pointers(),', ')\n init_flags = join(self.arg_specs.init_flags(),', ')\n init_flags_init = join(self.arg_specs.init_flags(),'= ')\n py_vars = join(self.arg_specs.py_variables(),' = ')\n if py_objects:\n declare_py_objects = 'PyObject ' + py_objects +';\\n'\n declare_py_objects += 'int '+ init_flags + ';\\n' \n init_values = py_vars + ' = NULL;\\n'\n init_values += init_flags_init + ' = 0;\\n\\n'\n else:\n declare_py_objects = ''\n init_values = '' \n\n #Each variable is in charge of its own cleanup now.\n #cnt = len(arg_list)\n #declare_cleanup = \"blitz::TinyVector clean_up(0);\\n\" % cnt\n\n ref_string = join(self.arg_specs.py_references(),', ')\n if ref_string:\n ref_string += ', &py_local_dict'\n else:\n ref_string = '&py_local_dict'\n \n format = \"O\"* len(self.arg_specs) + \"|O\" + ':' + self.name\n parse_tuple = 'if(!PyArg_ParseTupleAndKeywords(args,' \\\n 'kywds,\"%s\",kwlist,%s))\\n' % (format,ref_string)\n parse_tuple += ' return NULL;\\n'\n\n return declare_return + declare_kwlist + declare_py_objects \\\n + init_values + parse_tuple\n\n def arg_declaration_code(self):\n arg_strings = []\n for arg in self.arg_specs:\n arg_strings.append(arg.declaration_code())\n arg_strings.append(arg.init_flag() +\" = 1;\\n\")\n code = string.join(arg_strings,\"\")\n return code\n\n def arg_cleanup_code(self):\n arg_strings = []\n have_cleanup = filter(lambda x:x.cleanup_code(),self.arg_specs)\n for arg in have_cleanup:\n code = \"if(%s)\\n\" % arg.init_flag()\n code += \"{\\n\"\n code += indent(arg.cleanup_code(),4)\n code += \"}\\n\"\n arg_strings.append(code)\n code = string.join(arg_strings,\"\")\n return code\n\n def arg_local_dict_code(self):\n arg_strings = []\n for arg in self.arg_specs:\n arg_strings.append(arg.local_dict_code())\n code = string.join(arg_strings,\"\")\n return code\n \n def function_code(self):\n decl_code = indent(self.arg_declaration_code(),4)\n cleanup_code = indent(self.arg_cleanup_code(),4)\n function_code = indent(self.code_block,4)\n local_dict_code = indent(self.arg_local_dict_code(),4)\n\n dict_code = \"if(py_local_dict) \\n\" \\\n \"{ \\n\" \\\n \" py::dict local_dict = py::dict(py_local_dict); \\n\" + \\\n local_dict_code + \\\n \"} \\n\"\n\n try_code = \"try \\n\" \\\n \"{ \\n\" + \\\n decl_code + \\\n \" /**/ \\n\" + \\\n function_code + \\\n indent(dict_code,4) + \\\n \"\\n} \\n\"\n catch_code = \"catch(...) \\n\" \\\n \"{ \\n\" + \\\n \" return_val = py::object(); \\n\" \\\n \" exception_occured = 1; \\n\" \\\n \"} \\n\"\n\n return_code = \" /*cleanup code*/ \\n\" + \\\n cleanup_code + \\\n ' if(!(PyObject*)return_val && !exception_occured)\\n' \\\n ' {\\n \\n' \\\n ' return_val = Py_None; \\n' \\\n ' }\\n \\n' \\\n ' return return_val.disown(); \\n' \\\n '} \\n'\n\n all_code = self.function_declaration_code() + \\\n indent(self.parse_tuple_code(),4) + \\\n indent(try_code,4) + \\\n indent(catch_code,4) + \\\n return_code\n\n return all_code\n\n def python_function_definition_code(self):\n args = (self.name, self.name)\n function_decls = '{\"%s\",(PyCFunction)%s , METH_VARARGS|' \\\n 'METH_KEYWORDS},\\n' % args\n return function_decls\n\n def set_compiler(self,compiler):\n self.compiler = compiler\n for arg in self.arg_specs:\n arg.set_compiler(compiler)\n\n\nclass ext_function(ext_function_from_specs):\n def __init__(self,name,code_block, args, local_dict=None, global_dict=None,\n auto_downcast=1, type_converters=None):\n \n call_frame = sys._getframe().f_back\n if local_dict is None:\n local_dict = call_frame.f_locals\n if global_dict is None:\n global_dict = call_frame.f_globals\n if type_converters is None:\n type_converters = converters.default\n arg_specs = assign_variable_types(args,local_dict, global_dict,\n auto_downcast, type_converters)\n ext_function_from_specs.__init__(self,name,code_block,arg_specs)\n \n \nimport base_info\n\nclass ext_module:\n def __init__(self,name,compiler=''):\n standard_info = converters.standard_info\n self.name = name\n self.functions = []\n self.compiler = compiler\n self.customize = base_info.custom_info()\n self._build_information = base_info.info_list(standard_info)\n \n def add_function(self,func):\n self.functions.append(func)\n def module_code(self):\n code = self.warning_code() + \\\n self.header_code() + \\\n self.support_code() + \\\n self.function_code() + \\\n self.python_function_definition_code() + \\\n self.module_init_code()\n return code\n\n def arg_specs(self):\n all_arg_specs = base_spec.arg_spec_list()\n for func in self.functions:\n all_arg_specs += func.arg_specs\n return all_arg_specs\n\n def build_information(self):\n info = self._build_information + [self.customize] + \\\n self.arg_specs().build_information()\n for func in self.functions:\n info.append(func.customize)\n #redundant, but easiest place to make sure compiler is set\n for i in info:\n i.set_compiler(self.compiler)\n return info\n \n def get_headers(self):\n all_headers = self.build_information().headers()\n\n # blitz/array.h always needs to be first so we hack that here...\n if '\"blitz/array.h\"' in all_headers:\n all_headers.remove('\"blitz/array.h\"')\n all_headers.insert(0,'\"blitz/array.h\"')\n return all_headers\n\n def warning_code(self):\n all_warnings = self.build_information().warnings()\n w=map(lambda x: \"#pragma warning(%s)\\n\" % x,all_warnings)\n return ''.join(w)\n \n def header_code(self):\n h = self.get_headers()\n h= map(lambda x: '#include ' + x + '\\n',h)\n return ''.join(h) + '\\n'\n\n def support_code(self):\n code = self.build_information().support_code()\n return ''.join(code) + '\\n'\n\n def function_code(self):\n all_function_code = \"\"\n for func in self.functions:\n all_function_code += func.function_code()\n return ''.join(all_function_code) + '\\n'\n\n def python_function_definition_code(self):\n all_definition_code = \"\"\n for func in self.functions:\n all_definition_code += func.python_function_definition_code()\n all_definition_code = indent(''.join(all_definition_code),4)\n code = 'static PyMethodDef compiled_methods[] = \\n' \\\n '{\\n' \\\n '%s' \\\n ' {NULL, NULL} /* Sentinel */\\n' \\\n '};\\n'\n return code % (all_definition_code)\n\n def module_init_code(self):\n init_code_list = self.build_information().module_init_code()\n init_code = indent(''.join(init_code_list),4)\n code = 'extern \"C\" void init%s()\\n' \\\n '{\\n' \\\n '%s' \\\n ' (void) Py_InitModule(\"%s\", compiled_methods);\\n' \\\n '}\\n' % (self.name,init_code,self.name)\n return code\n\n def generate_file(self,file_name=\"\",location='.'):\n code = self.module_code()\n if not file_name:\n file_name = self.name + '.cpp'\n name = generate_file_name(file_name,location)\n #return name\n return generate_module(code,name)\n\n def set_compiler(self,compiler):\n # This is not used anymore -- I think we should ditch it.\n #for i in self.arg_specs()\n # i.set_compiler(compiler)\n for i in self.build_information():\n i.set_compiler(compiler) \n for i in self.functions:\n i.set_compiler(compiler)\n self.compiler = compiler \n\n def build_kw_and_file(self,location,kw): \n arg_specs = self.arg_specs()\n info = self.build_information()\n _source_files = info.sources()\n # remove duplicates\n source_files = {}\n for i in _source_files:\n source_files[i] = None\n source_files = source_files.keys()\n \n # add internally specified macros, includes, etc. to the key words\n # values of the same names so that distutils will use them.\n kw['define_macros'] = kw.get('define_macros',[]) + \\\n info.define_macros()\n kw['include_dirs'] = kw.get('include_dirs',[]) + info.include_dirs()\n kw['libraries'] = kw.get('libraries',[]) + info.libraries()\n kw['library_dirs'] = kw.get('library_dirs',[]) + info.library_dirs()\n kw['extra_compile_args'] = kw.get('extra_compile_args',[]) + \\\n info.extra_compile_args()\n kw['extra_link_args'] = kw.get('extra_link_args',[]) + \\\n info.extra_link_args()\n kw['sources'] = kw.get('sources',[]) + source_files \n file = self.generate_file(location=location)\n return kw,file\n \n def setup_extension(self,location='.',**kw):\n kw,file = self.build_kw_and_file(location,kw)\n return build_tools.create_extension(file, **kw)\n \n def compile(self,location='.',compiler=None, verbose = 0, **kw):\n \n if compiler is not None:\n self.compiler = compiler\n \n # !! removed -- we don't have any compiler dependent code\n # currently in spec or info classes \n # hmm. Is there a cleaner way to do this? Seems like\n # choosing the compiler spagettis around a little. \n #compiler = build_tools.choose_compiler(self.compiler) \n #self.set_compiler(compiler)\n \n kw,file = self.build_kw_and_file(location,kw)\n \n # This is needed so that files build correctly even when different\n # versions of Python are running around.\n # Imported at beginning of file now to help with test paths.\n # import catalog \n #temp = catalog.default_temp_dir()\n # for speed, build in the machines temp directory\n temp = catalog.intermediate_dir()\n \n success = build_tools.build_extension(file, temp_dir = temp,\n compiler_name = compiler,\n verbose = verbose, **kw)\n if not success:\n raise SystemError, 'Compilation failed'\n\ndef generate_file_name(module_name,module_location):\n module_file = os.path.join(module_location,module_name)\n return os.path.abspath(module_file)\n\ndef generate_module(module_string, module_file):\n \"\"\" generate the source code file. Only overwrite\n the existing file if the actual source has changed.\n \"\"\"\n file_changed = 1\n if os.path.exists(module_file):\n f =open(module_file,'r')\n old_string = f.read()\n f.close()\n if old_string == module_string:\n file_changed = 0\n if file_changed:\n f =open(module_file,'w')\n f.write(module_string)\n f.close()\n return module_file\n\ndef assign_variable_types(variables,local_dict = {}, global_dict = {},\n auto_downcast = 1,\n type_converters = converters.default):\n incoming_vars = {}\n incoming_vars.update(global_dict)\n incoming_vars.update(local_dict)\n variable_specs = []\n errors={}\n for var in variables:\n try:\n example_type = incoming_vars[var]\n\n # look through possible type specs to find which one\n # should be used to for example_type\n spec = None\n for factory in type_converters:\n if factory.type_match(example_type):\n spec = factory.type_spec(var,example_type)\n break \n if not spec:\n # should really define our own type.\n raise IndexError\n else:\n variable_specs.append(spec)\n except KeyError:\n errors[var] = (\"The type and dimensionality specifications\" +\n \"for variable '\" + var + \"' are missing.\")\n except IndexError:\n errors[var] = (\"Unable to convert variable '\"+ var +\n \"' to a C++ type.\")\n if errors:\n raise TypeError, format_error_msg(errors)\n\n if auto_downcast:\n variable_specs = downcast(variable_specs)\n return variable_specs\n\ndef downcast(var_specs):\n \"\"\" Cast python scalars down to most common type of\n arrays used.\n\n Right now, focus on complex and float types. Ignore int types.\n Require all arrays to have same type before forcing downcasts.\n\n Note: var_specs are currently altered in place (horrors...!)\n \"\"\"\n numeric_types = []\n\n #grab all the numeric types associated with a variables.\n for var in var_specs:\n if hasattr(var,'numeric_type'):\n numeric_types.append(var.numeric_type)\n\n # if arrays are present, but none of them are double precision,\n # make all numeric types float or complex(float)\n if ( ('f' in numeric_types or 'F' in numeric_types) and\n not ('d' in numeric_types or 'D' in numeric_types) ):\n for var in var_specs:\n if hasattr(var,'numeric_type'):\n # really should do this some other way...\n if var.numeric_type == type(1+1j):\n var.numeric_type = 'F'\n elif var.numeric_type == type(1.):\n var.numeric_type = 'f'\n return var_specs\n\ndef indent(st,spaces):\n indention = ' '*spaces\n indented = indention + string.replace(st,'\\n','\\n'+indention)\n # trim off any trailing spaces\n indented = re.sub(r' +$',r'',indented)\n return indented\n\ndef format_error_msg(errors):\n #minimum effort right now...\n import pprint,cStringIO\n msg = cStringIO.StringIO()\n pprint.pprint(errors,msg)\n return msg.getvalue()\n", "methods": [ { "name": "__init__", "long_name": "__init__( self , name , code_block , arg_specs )", "filename": "ext_tools.py", "nloc": 6, "complexity": 1, "token_count": 45, "parameters": [ "self", "name", "code_block", "arg_specs" ], "start_line": 10, "end_line": 15, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 6, "top_nesting_level": 1 }, { "name": "header_code", "long_name": "header_code( self )", "filename": "ext_tools.py", "nloc": 2, "complexity": 1, "token_count": 6, "parameters": [ "self" ], "start_line": 17, "end_line": 18, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 2, "top_nesting_level": 1 }, { "name": "function_declaration_code", "long_name": "function_declaration_code( self )", "filename": "ext_tools.py", "nloc": 4, "complexity": 1, "token_count": 16, "parameters": [ "self" ], "start_line": 20, "end_line": 23, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 4, "top_nesting_level": 1 }, { "name": "template_declaration_code", "long_name": "template_declaration_code( self )", "filename": "ext_tools.py", "nloc": 5, "complexity": 1, "token_count": 18, "parameters": [ "self" ], "start_line": 25, "end_line": 29, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 5, "top_nesting_level": 1 }, { "name": "parse_tuple_code", "long_name": "parse_tuple_code( self )", "filename": "ext_tools.py", "nloc": 32, "complexity": 4, "token_count": 209, "parameters": [ "self" ], "start_line": 36, "end_line": 81, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 46, "top_nesting_level": 1 }, { "name": "arg_declaration_code", "long_name": "arg_declaration_code( self )", "filename": "ext_tools.py", "nloc": 7, "complexity": 2, "token_count": 50, "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": "arg_cleanup_code", "long_name": "arg_cleanup_code( self )", "filename": "ext_tools.py", "nloc": 11, "complexity": 2, "token_count": 76, "parameters": [ "self" ], "start_line": 91, "end_line": 101, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 11, "top_nesting_level": 1 }, { "name": "arg_local_dict_code", "long_name": "arg_local_dict_code( self )", "filename": "ext_tools.py", "nloc": 6, "complexity": 2, "token_count": 38, "parameters": [ "self" ], "start_line": 103, "end_line": 108, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 6, "top_nesting_level": 1 }, { "name": "function_code", "long_name": "function_code( self )", "filename": "ext_tools.py", "nloc": 36, "complexity": 1, "token_count": 160, "parameters": [ "self" ], "start_line": 110, "end_line": 150, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 41, "top_nesting_level": 1 }, { "name": "python_function_definition_code", "long_name": "python_function_definition_code( self )", "filename": "ext_tools.py", "nloc": 5, "complexity": 1, "token_count": 25, "parameters": [ "self" ], "start_line": 152, "end_line": 156, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 5, "top_nesting_level": 1 }, { "name": "set_compiler", "long_name": "set_compiler( self , compiler )", "filename": "ext_tools.py", "nloc": 4, "complexity": 2, "token_count": 25, "parameters": [ "self", "compiler" ], "start_line": 158, "end_line": 161, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 4, "top_nesting_level": 1 }, { "name": "__init__", "long_name": "__init__( self , name , code_block , args , local_dict = None , global_dict = None , auto_downcast = 1 , type_converters = None )", "filename": "ext_tools.py", "nloc": 12, "complexity": 4, "token_count": 92, "parameters": [ "self", "name", "code_block", "args", "local_dict", "global_dict", "auto_downcast", "type_converters" ], "start_line": 165, "end_line": 177, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 13, "top_nesting_level": 1 }, { "name": "__init__", "long_name": "__init__( self , name , compiler = '' )", "filename": "ext_tools.py", "nloc": 7, "complexity": 1, "token_count": 51, "parameters": [ "self", "name", "compiler" ], "start_line": 183, "end_line": 189, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 7, "top_nesting_level": 1 }, { "name": "add_function", "long_name": "add_function( self , func )", "filename": "ext_tools.py", "nloc": 2, "complexity": 1, "token_count": 15, "parameters": [ "self", "func" ], "start_line": 191, "end_line": 192, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 2, "top_nesting_level": 1 }, { "name": "module_code", "long_name": "module_code( self )", "filename": "ext_tools.py", "nloc": 8, "complexity": 1, "token_count": 51, "parameters": [ "self" ], "start_line": 193, "end_line": 200, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 8, "top_nesting_level": 1 }, { "name": "arg_specs", "long_name": "arg_specs( self )", "filename": "ext_tools.py", "nloc": 5, "complexity": 2, "token_count": 26, "parameters": [ "self" ], "start_line": 202, "end_line": 206, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 5, "top_nesting_level": 1 }, { "name": "build_information", "long_name": "build_information( self )", "filename": "ext_tools.py", "nloc": 8, "complexity": 3, "token_count": 57, "parameters": [ "self" ], "start_line": 208, "end_line": 216, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 9, "top_nesting_level": 1 }, { "name": "get_headers", "long_name": "get_headers( self )", "filename": "ext_tools.py", "nloc": 6, "complexity": 2, "token_count": 37, "parameters": [ "self" ], "start_line": 218, "end_line": 225, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 8, "top_nesting_level": 1 }, { "name": "warning_code", "long_name": "warning_code( self )", "filename": "ext_tools.py", "nloc": 4, "complexity": 1, "token_count": 36, "parameters": [ "self" ], "start_line": 227, "end_line": 230, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 4, "top_nesting_level": 1 }, { "name": "header_code", "long_name": "header_code( self )", "filename": "ext_tools.py", "nloc": 4, "complexity": 1, "token_count": 36, "parameters": [ "self" ], "start_line": 232, "end_line": 235, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 4, "top_nesting_level": 1 }, { "name": "support_code", "long_name": "support_code( self )", "filename": "ext_tools.py", "nloc": 3, "complexity": 1, "token_count": 25, "parameters": [ "self" ], "start_line": 237, "end_line": 239, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 3, "top_nesting_level": 1 }, { "name": "function_code", "long_name": "function_code( self )", "filename": "ext_tools.py", "nloc": 5, "complexity": 2, "token_count": 31, "parameters": [ "self" ], "start_line": 241, "end_line": 245, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 5, "top_nesting_level": 1 }, { "name": "python_function_definition_code", "long_name": "python_function_definition_code( self )", "filename": "ext_tools.py", "nloc": 11, "complexity": 2, "token_count": 52, "parameters": [ "self" ], "start_line": 247, "end_line": 257, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 11, "top_nesting_level": 1 }, { "name": "module_init_code", "long_name": "module_init_code( self )", "filename": "ext_tools.py", "nloc": 9, "complexity": 1, "token_count": 54, "parameters": [ "self" ], "start_line": 259, "end_line": 267, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 9, "top_nesting_level": 1 }, { "name": "generate_file", "long_name": "generate_file( self , file_name = \"\" , location = '.' )", "filename": "ext_tools.py", "nloc": 6, "complexity": 2, "token_count": 46, "parameters": [ "self", "file_name", "location" ], "start_line": 269, "end_line": 275, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 7, "top_nesting_level": 1 }, { "name": "set_compiler", "long_name": "set_compiler( self , compiler )", "filename": "ext_tools.py", "nloc": 6, "complexity": 3, "token_count": 40, "parameters": [ "self", "compiler" ], "start_line": 277, "end_line": 285, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 9, "top_nesting_level": 1 }, { "name": "build_kw_and_file", "long_name": "build_kw_and_file( self , location , kw )", "filename": "ext_tools.py", "nloc": 20, "complexity": 2, "token_count": 205, "parameters": [ "self", "location", "kw" ], "start_line": 287, "end_line": 310, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 24, "top_nesting_level": 1 }, { "name": "setup_extension", "long_name": "setup_extension( self , location = '.' , ** kw )", "filename": "ext_tools.py", "nloc": 3, "complexity": 1, "token_count": 34, "parameters": [ "self", "location", "kw" ], "start_line": 312, "end_line": 314, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 3, "top_nesting_level": 1 }, { "name": "compile", "long_name": "compile( self , location = '.' , compiler = None , verbose = 0 , ** kw )", "filename": "ext_tools.py", "nloc": 10, "complexity": 3, "token_count": 81, "parameters": [ "self", "location", "compiler", "verbose", "kw" ], "start_line": 316, "end_line": 342, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 27, "top_nesting_level": 1 }, { "name": "generate_file_name", "long_name": "generate_file_name( module_name , module_location )", "filename": "ext_tools.py", "nloc": 3, "complexity": 1, "token_count": 28, "parameters": [ "module_name", "module_location" ], "start_line": 344, "end_line": 346, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 3, "top_nesting_level": 0 }, { "name": "generate_module", "long_name": "generate_module( module_string , module_file )", "filename": "ext_tools.py", "nloc": 13, "complexity": 4, "token_count": 73, "parameters": [ "module_string", "module_file" ], "start_line": 348, "end_line": 363, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 16, "top_nesting_level": 0 }, { "name": "assign_variable_types", "long_name": "assign_variable_types( variables , local_dict = { } , global_dict = { } , auto_downcast = 1 , type_converters = converters . default )", "filename": "ext_tools.py", "nloc": 31, "complexity": 9, "token_count": 156, "parameters": [ "variables", "local_dict", "global_dict", "auto_downcast", "type_converters" ], "start_line": 365, "end_line": 400, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 36, "top_nesting_level": 0 }, { "name": "downcast", "long_name": "downcast( var_specs )", "filename": "ext_tools.py", "nloc": 14, "complexity": 11, "token_count": 103, "parameters": [ "var_specs" ], "start_line": 402, "end_line": 429, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 28, "top_nesting_level": 0 }, { "name": "indent", "long_name": "indent( st , spaces )", "filename": "ext_tools.py", "nloc": 5, "complexity": 1, "token_count": 44, "parameters": [ "st", "spaces" ], "start_line": 431, "end_line": 436, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 6, "top_nesting_level": 0 }, { "name": "format_error_msg", "long_name": "format_error_msg( errors )", "filename": "ext_tools.py", "nloc": 5, "complexity": 1, "token_count": 30, "parameters": [ "errors" ], "start_line": 438, "end_line": 443, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 6, "top_nesting_level": 0 } ], "methods_before": [ { "name": "__init__", "long_name": "__init__( self , name , code_block , arg_specs )", "filename": "ext_tools.py", "nloc": 6, "complexity": 1, "token_count": 45, "parameters": [ "self", "name", "code_block", "arg_specs" ], "start_line": 10, "end_line": 15, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 6, "top_nesting_level": 1 }, { "name": "header_code", "long_name": "header_code( self )", "filename": "ext_tools.py", "nloc": 2, "complexity": 1, "token_count": 6, "parameters": [ "self" ], "start_line": 17, "end_line": 18, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 2, "top_nesting_level": 1 }, { "name": "function_declaration_code", "long_name": "function_declaration_code( self )", "filename": "ext_tools.py", "nloc": 4, "complexity": 1, "token_count": 16, "parameters": [ "self" ], "start_line": 20, "end_line": 23, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 4, "top_nesting_level": 1 }, { "name": "template_declaration_code", "long_name": "template_declaration_code( self )", "filename": "ext_tools.py", "nloc": 5, "complexity": 1, "token_count": 18, "parameters": [ "self" ], "start_line": 25, "end_line": 29, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 5, "top_nesting_level": 1 }, { "name": "parse_tuple_code", "long_name": "parse_tuple_code( self )", "filename": "ext_tools.py", "nloc": 32, "complexity": 4, "token_count": 209, "parameters": [ "self" ], "start_line": 36, "end_line": 81, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 46, "top_nesting_level": 1 }, { "name": "arg_declaration_code", "long_name": "arg_declaration_code( self )", "filename": "ext_tools.py", "nloc": 7, "complexity": 2, "token_count": 50, "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": "arg_cleanup_code", "long_name": "arg_cleanup_code( self )", "filename": "ext_tools.py", "nloc": 11, "complexity": 2, "token_count": 76, "parameters": [ "self" ], "start_line": 91, "end_line": 101, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 11, "top_nesting_level": 1 }, { "name": "arg_local_dict_code", "long_name": "arg_local_dict_code( self )", "filename": "ext_tools.py", "nloc": 6, "complexity": 2, "token_count": 38, "parameters": [ "self" ], "start_line": 103, "end_line": 108, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 6, "top_nesting_level": 1 }, { "name": "function_code", "long_name": "function_code( self )", "filename": "ext_tools.py", "nloc": 36, "complexity": 1, "token_count": 160, "parameters": [ "self" ], "start_line": 110, "end_line": 150, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 41, "top_nesting_level": 1 }, { "name": "python_function_definition_code", "long_name": "python_function_definition_code( self )", "filename": "ext_tools.py", "nloc": 5, "complexity": 1, "token_count": 25, "parameters": [ "self" ], "start_line": 152, "end_line": 156, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 5, "top_nesting_level": 1 }, { "name": "set_compiler", "long_name": "set_compiler( self , compiler )", "filename": "ext_tools.py", "nloc": 4, "complexity": 2, "token_count": 25, "parameters": [ "self", "compiler" ], "start_line": 158, "end_line": 161, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 4, "top_nesting_level": 1 }, { "name": "__init__", "long_name": "__init__( self , name , code_block , args , local_dict = None , global_dict = None , auto_downcast = 1 , type_converters = None )", "filename": "ext_tools.py", "nloc": 12, "complexity": 4, "token_count": 92, "parameters": [ "self", "name", "code_block", "args", "local_dict", "global_dict", "auto_downcast", "type_converters" ], "start_line": 165, "end_line": 177, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 13, "top_nesting_level": 1 }, { "name": "__init__", "long_name": "__init__( self , name , compiler = '' )", "filename": "ext_tools.py", "nloc": 7, "complexity": 1, "token_count": 51, "parameters": [ "self", "name", "compiler" ], "start_line": 183, "end_line": 189, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 7, "top_nesting_level": 1 }, { "name": "add_function", "long_name": "add_function( self , func )", "filename": "ext_tools.py", "nloc": 2, "complexity": 1, "token_count": 15, "parameters": [ "self", "func" ], "start_line": 191, "end_line": 192, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 2, "top_nesting_level": 1 }, { "name": "module_code", "long_name": "module_code( self )", "filename": "ext_tools.py", "nloc": 8, "complexity": 1, "token_count": 49, "parameters": [ "self" ], "start_line": 193, "end_line": 200, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 8, "top_nesting_level": 1 }, { "name": "arg_specs", "long_name": "arg_specs( self )", "filename": "ext_tools.py", "nloc": 5, "complexity": 2, "token_count": 26, "parameters": [ "self" ], "start_line": 202, "end_line": 206, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 5, "top_nesting_level": 1 }, { "name": "build_information", "long_name": "build_information( self )", "filename": "ext_tools.py", "nloc": 8, "complexity": 3, "token_count": 57, "parameters": [ "self" ], "start_line": 208, "end_line": 216, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 9, "top_nesting_level": 1 }, { "name": "get_headers", "long_name": "get_headers( self )", "filename": "ext_tools.py", "nloc": 6, "complexity": 2, "token_count": 37, "parameters": [ "self" ], "start_line": 218, "end_line": 225, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 8, "top_nesting_level": 1 }, { "name": "warning_code", "long_name": "warning_code( self )", "filename": "ext_tools.py", "nloc": 4, "complexity": 1, "token_count": 36, "parameters": [ "self" ], "start_line": 227, "end_line": 230, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 4, "top_nesting_level": 1 }, { "name": "header_code", "long_name": "header_code( self )", "filename": "ext_tools.py", "nloc": 4, "complexity": 1, "token_count": 36, "parameters": [ "self" ], "start_line": 232, "end_line": 235, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 4, "top_nesting_level": 1 }, { "name": "support_code", "long_name": "support_code( self )", "filename": "ext_tools.py", "nloc": 3, "complexity": 1, "token_count": 25, "parameters": [ "self" ], "start_line": 237, "end_line": 239, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 3, "top_nesting_level": 1 }, { "name": "function_code", "long_name": "function_code( self )", "filename": "ext_tools.py", "nloc": 5, "complexity": 2, "token_count": 31, "parameters": [ "self" ], "start_line": 241, "end_line": 245, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 5, "top_nesting_level": 1 }, { "name": "python_function_definition_code", "long_name": "python_function_definition_code( self )", "filename": "ext_tools.py", "nloc": 11, "complexity": 2, "token_count": 52, "parameters": [ "self" ], "start_line": 247, "end_line": 257, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 11, "top_nesting_level": 1 }, { "name": "module_init_code", "long_name": "module_init_code( self )", "filename": "ext_tools.py", "nloc": 9, "complexity": 1, "token_count": 54, "parameters": [ "self" ], "start_line": 259, "end_line": 267, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 9, "top_nesting_level": 1 }, { "name": "generate_file", "long_name": "generate_file( self , file_name = \"\" , location = '.' )", "filename": "ext_tools.py", "nloc": 6, "complexity": 2, "token_count": 46, "parameters": [ "self", "file_name", "location" ], "start_line": 269, "end_line": 275, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 7, "top_nesting_level": 1 }, { "name": "set_compiler", "long_name": "set_compiler( self , compiler )", "filename": "ext_tools.py", "nloc": 6, "complexity": 3, "token_count": 40, "parameters": [ "self", "compiler" ], "start_line": 277, "end_line": 285, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 9, "top_nesting_level": 1 }, { "name": "build_kw_and_file", "long_name": "build_kw_and_file( self , location , kw )", "filename": "ext_tools.py", "nloc": 20, "complexity": 2, "token_count": 205, "parameters": [ "self", "location", "kw" ], "start_line": 287, "end_line": 310, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 24, "top_nesting_level": 1 }, { "name": "setup_extension", "long_name": "setup_extension( self , location = '.' , ** kw )", "filename": "ext_tools.py", "nloc": 3, "complexity": 1, "token_count": 34, "parameters": [ "self", "location", "kw" ], "start_line": 312, "end_line": 314, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 3, "top_nesting_level": 1 }, { "name": "compile", "long_name": "compile( self , location = '.' , compiler = None , verbose = 0 , ** kw )", "filename": "ext_tools.py", "nloc": 10, "complexity": 3, "token_count": 81, "parameters": [ "self", "location", "compiler", "verbose", "kw" ], "start_line": 316, "end_line": 342, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 27, "top_nesting_level": 1 }, { "name": "generate_file_name", "long_name": "generate_file_name( module_name , module_location )", "filename": "ext_tools.py", "nloc": 3, "complexity": 1, "token_count": 28, "parameters": [ "module_name", "module_location" ], "start_line": 344, "end_line": 346, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 3, "top_nesting_level": 0 }, { "name": "generate_module", "long_name": "generate_module( module_string , module_file )", "filename": "ext_tools.py", "nloc": 13, "complexity": 4, "token_count": 73, "parameters": [ "module_string", "module_file" ], "start_line": 348, "end_line": 363, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 16, "top_nesting_level": 0 }, { "name": "assign_variable_types", "long_name": "assign_variable_types( variables , local_dict = { } , global_dict = { } , auto_downcast = 1 , type_converters = converters . default )", "filename": "ext_tools.py", "nloc": 31, "complexity": 9, "token_count": 156, "parameters": [ "variables", "local_dict", "global_dict", "auto_downcast", "type_converters" ], "start_line": 365, "end_line": 400, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 36, "top_nesting_level": 0 }, { "name": "downcast", "long_name": "downcast( var_specs )", "filename": "ext_tools.py", "nloc": 14, "complexity": 11, "token_count": 103, "parameters": [ "var_specs" ], "start_line": 402, "end_line": 429, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 28, "top_nesting_level": 0 }, { "name": "indent", "long_name": "indent( st , spaces )", "filename": "ext_tools.py", "nloc": 5, "complexity": 1, "token_count": 44, "parameters": [ "st", "spaces" ], "start_line": 431, "end_line": 436, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 6, "top_nesting_level": 0 }, { "name": "format_error_msg", "long_name": "format_error_msg( errors )", "filename": "ext_tools.py", "nloc": 5, "complexity": 1, "token_count": 30, "parameters": [ "errors" ], "start_line": 438, "end_line": 443, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 6, "top_nesting_level": 0 } ], "changed_methods": [ { "name": "module_code", "long_name": "module_code( self )", "filename": "ext_tools.py", "nloc": 8, "complexity": 1, "token_count": 51, "parameters": [ "self" ], "start_line": 193, "end_line": 200, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 8, "top_nesting_level": 1 } ], "nloc": 328, "complexity": 78, "token_count": 2136, "diff_parsed": { "added": [ " code = '\\n'.join([self.warning_code(),", " self.header_code(),", " self.support_code(),", " self.function_code(),", " self.python_function_definition_code(),", " self.module_init_code()])" ], "deleted": [ " code = self.warning_code() + \\", " self.header_code() + \\", " self.support_code() + \\", " self.function_code() + \\", " self.python_function_definition_code() + \\", " self.module_init_code()" ] } } ] }, { "hash": "55d5de4c0bafe946e5030f0687a34ed5fac05277", "msg": "Doc fixes for livedocs.", "author": { "name": "Pearu Peterson", "email": "pearu.peterson@gmail.com" }, "committer": { "name": "Pearu Peterson", "email": "pearu.peterson@gmail.com" }, "author_date": "2004-11-27T15:47:17+00:00", "author_timezone": 0, "committer_date": "2004-11-27T15:47:17+00:00", "committer_timezone": 0, "branches": [ "main" ], "in_main_branch": true, "merge": false, "parents": [ "afdbe1880e03014b8a1076005af858d4e52e85fa" ], "project_name": "repo_copy", "project_path": "/tmp/tmpqop781_j/repo_copy", "deletions": 38, "insertions": 40, "lines": 78, "files": 4, "dmm_unit_size": 1.0, "dmm_unit_complexity": 0.0, "dmm_unit_interfacing": 0.0, "modified_files": [ { "old_path": "scipy_base/type_check.py", "new_path": "scipy_base/type_check.py", "filename": "type_check.py", "extension": "py", "change_type": "MODIFY", "diff": "@@ -27,7 +27,8 @@ def mintypecode(typecodes,typeset='DFdf',default='d',savespace=0):\n whenever typecodes contain 'F' and 'd'.\n If t in typecodes is not a string then t=t.typecode() is applied.\n \"\"\"\n- typecodes = [(type(t) is type('') and t) or t.typecode() for t in typecodes]\n+ typecodes = [(type(t) is type('') and t) or asarray(t).typecode()\\\n+ for t in typecodes]\n intersection = [t for t in typecodes if t in typeset]\n if not intersection:\n return default\n", "added_lines": 2, "deleted_lines": 1, "source_code": "\nimport types\nimport Numeric\nfrom fastumath import isinf, isnan, isfinite\nfrom Numeric import ArrayType, array, multiarray\n\ntry:\n from Numeric import UfuncType\nexcept ImportError:\n UfuncType = type(Numeric.sin)\n\n__all__ = ['ScalarType','iscomplexobj','isrealobj','imag','iscomplex',\n 'isscalar','isneginf','isposinf','isnan','isinf','isfinite',\n 'isreal','nan_to_num','real','real_if_close',\n 'typename','cast','common_type','typecodes', 'asarray',\n 'asfarray', 'ArrayType', 'UfuncType','mintypecode']\n\n_typecodes_by_elsize = 'DFdfluiwsb1c'\ndef mintypecode(typecodes,typeset='DFdf',default='d',savespace=0):\n \"\"\" Return a typecode in typeset such that for each\n t in typecodes\n array(typecode=typecode)[:] = array(typecode=t)\n is valid, looses no information, and array(typecode=typecode)\n element size is minimal unless when typecodes does not\n intersect with typeset then default is returned.\n As a special case, if savespace is False then 'D' is returned\n whenever typecodes contain 'F' and 'd'.\n If t in typecodes is not a string then t=t.typecode() is applied.\n \"\"\"\n typecodes = [(type(t) is type('') and t) or asarray(t).typecode()\\\n for t in typecodes]\n intersection = [t for t in typecodes if t in typeset]\n if not intersection:\n return default\n if not savespace and 'F' in intersection and 'd' in intersection:\n return 'D'\n l = []\n for t in intersection:\n i = _typecodes_by_elsize.index(t)\n l.append((i,t))\n l.sort()\n return l[0][1]\n\ndef asarray(a, typecode=None, savespace=None):\n \"\"\"asarray(a,typecode=None, savespace=0) returns a as a NumPy array.\n Unlike array(), no copy is performed if a is already an array.\n \"\"\"\n if type(a) is ArrayType:\n if typecode is None or typecode == a.typecode():\n if savespace is None or a.spacesaver()==savespace:\n return a\n else:\n r = a.astype(typecode)\n if not (savespace is None or a.spacesaver()==savespace):\n r.savespace(savespace)\n return r\n return multiarray.array(a,typecode,copy=0,savespace=savespace or 0)\n\ndef asfarray(a, typecode=None, savespace=None):\n \"\"\"asfarray(a,typecode=None, savespace=0) returns a as a NumPy float array.\"\"\"\n a = asarray(a,typecode,savespace)\n if typecode is None and a.typecode() not in 'CFfd':\n return a.astype('d')\n return a\n\nScalarType = [types.IntType, types.LongType, types.FloatType, types.ComplexType]\n\ntypecodes = Numeric.typecodes\ntypecodes['AllInteger'] = '1silbwu'\n\ntry:\n Char = Numeric.Character\nexcept AttributeError:\n Char = 'c'\n\ntoChar = lambda x: asarray(x).astype(Char)\ntoInt8 = lambda x: asarray(x).astype(Numeric.Int8)# or use variable names such as Byte\ntoUInt8 = lambda x: asarray(x).astype(Numeric.UnsignedInt8)\n_unsigned = 0\nif hasattr(Numeric,'UnsignedInt16'):\n toUInt16 = lambda x: asarray(x).astype(Numeric.UnsignedInt16)\n toUInt32 = lambda x: asarray(x).astype(Numeric.UnsignedInt32)\n _unsigned = 1\n \ntoInt16 = lambda x: asarray(x).astype(Numeric.Int16)\ntoInt32 = lambda x: asarray(x).astype(Numeric.Int32)\ntoInt = lambda x: asarray(x).astype(Numeric.Int)\ntoFloat32 = lambda x: asarray(x).astype(Numeric.Float32)\ntoFloat64 = lambda x: asarray(x).astype(Numeric.Float64)\ntoComplex32 = lambda x: asarray(x).astype(Numeric.Complex32)\ntoComplex64 = lambda x: asarray(x).astype(Numeric.Complex64)\n\n# This is for pre Numeric 21.x compatiblity. Adding it is harmless.\nif not hasattr(Numeric,'Character'):\n Numeric.Character = 'c'\n \ncast = {Numeric.Character: toChar,\n Numeric.UnsignedInt8: toUInt8,\n Numeric.Int8: toInt8,\n Numeric.Int16: toInt16,\n Numeric.Int32: toInt32,\n Numeric.Int: toInt,\n Numeric.Float32: toFloat32,\n Numeric.Float64: toFloat64,\n Numeric.Complex32: toComplex32,\n Numeric.Complex64: toComplex64}\n\nif _unsigned:\n cast[Numeric.UnsignedInt16] = toUInt16\n cast[Numeric.UnsignedInt32] = toUInt32\n \n\ndef isscalar(num):\n if isinstance(num, ArrayType):\n return len(num.shape) == 0 and num.typecode() != 'O'\n return type(num) in ScalarType\n\ndef real(val):\n aval = asarray(val)\n if aval.typecode() in ['F', 'D']:\n return aval.real\n else:\n return aval\n\ndef imag(val):\n aval = asarray(val)\n if aval.typecode() in ['F', 'D']:\n return aval.imag\n else:\n return array(0,aval.typecode())*aval\n\ndef iscomplex(x):\n return imag(x) != Numeric.zeros(asarray(x).shape)\n\ndef isreal(x):\n return imag(x) == Numeric.zeros(asarray(x).shape)\n\ndef iscomplexobj(x):\n return asarray(x).typecode() in ['F', 'D']\n\ndef isrealobj(x):\n return not asarray(x).typecode() in ['F', 'D']\n\n#-----------------------------------------------------------------------------\n\n##def isnan(val):\n## # fast, but apparently not portable (according to notes by Tim Peters)\n## #return val != val\n## # very slow -- should really use cephes methods or *something* different\n## import ieee_754\n## vals = ravel(val)\n## if array_iscomplex(vals):\n## r = array(map(ieee_754.isnan,real(vals))) \n## i = array(map(ieee_754.isnan,imag(vals)))\n## results = Numeric.logical_or(r,i)\n## else: \n## results = array(map(ieee_754.isnan,vals))\n## if isscalar(val):\n## results = results[0]\n## return results\n\ndef isposinf(val):\n return isinf(val) & (val > 0)\n \ndef isneginf(val):\n return isinf(val) & (val < 0)\n \n##def isinf(val):\n## return Numeric.logical_or(isposinf(val),isneginf(val))\n\n##def isfinite(val):\n## vals = asarray(val)\n## if iscomplexobj(vals):\n## r = isfinite(real(vals))\n## i = isfinite(imag(vals))\n## results = Numeric.logical_and(r,i)\n## else: \n## fin = Numeric.logical_not(isinf(val))\n## an = Numeric.logical_not(isnan(val))\n## results = Numeric.logical_and(fin,an)\n## return results \n\ndef nan_to_num(x):\n # mapping:\n # NaN -> 0\n # Inf -> limits.double_max\n # -Inf -> limits.double_min\n # complex not handled currently\n import limits\n try:\n t = x.typecode()\n except AttributeError:\n t = type(x)\n if t in [types.ComplexType,'F','D']: \n y = nan_to_num(x.real) + 1j * nan_to_num(x.imag)\n else: \n x = asarray(x)\n are_inf = isposinf(x)\n are_neg_inf = isneginf(x)\n are_nan = isnan(x)\n choose_array = are_neg_inf + are_nan * 2 + are_inf * 3\n y = Numeric.choose(choose_array,\n (x,limits.double_min, 0., limits.double_max))\n return y\n\n#-----------------------------------------------------------------------------\n\ndef real_if_close(a,tol=1e-13):\n a = asarray(a)\n if a.typecode() in ['F','D'] and Numeric.allclose(a.imag, 0, atol=tol):\n a = a.real\n return a\n\n\n#-----------------------------------------------------------------------------\n\n_namefromtype = {'c' : 'character',\n '1' : 'signed char',\n 'b' : 'unsigned char',\n 's' : 'short',\n 'w' : 'unsigned short',\n 'i' : 'integer',\n 'u' : 'unsigned integer',\n 'l' : 'long integer',\n 'f' : 'float',\n 'd' : 'double',\n 'F' : 'complex float',\n 'D' : 'complex double',\n 'O' : 'object'\n }\n\ndef typename(char):\n \"\"\"Return an english name for the given typecode character.\n \"\"\"\n return _namefromtype[char]\n\n#-----------------------------------------------------------------------------\n\n#determine the \"minimum common type code\" for a group of arrays.\narray_kind = {'i':0, 'l': 0, 'f': 0, 'd': 0, 'F': 1, 'D': 1}\narray_precision = {'i': 1, 'l': 1, 'f': 0, 'd': 1, 'F': 0, 'D': 1}\narray_type = [['f', 'd'], ['F', 'D']]\ndef common_type(*arrays):\n kind = 0\n precision = 0\n for a in arrays:\n t = a.typecode()\n kind = max(kind, array_kind[t])\n precision = max(precision, array_precision[t])\n return array_type[kind][precision]\n\nif __name__ == '__main__':\n print 'float epsilon:',float_epsilon\n print 'float tiny:',float_tiny\n print 'double epsilon:',double_epsilon\n print 'double tiny:',double_tiny\n", "source_code_before": "\nimport types\nimport Numeric\nfrom fastumath import isinf, isnan, isfinite\nfrom Numeric import ArrayType, array, multiarray\n\ntry:\n from Numeric import UfuncType\nexcept ImportError:\n UfuncType = type(Numeric.sin)\n\n__all__ = ['ScalarType','iscomplexobj','isrealobj','imag','iscomplex',\n 'isscalar','isneginf','isposinf','isnan','isinf','isfinite',\n 'isreal','nan_to_num','real','real_if_close',\n 'typename','cast','common_type','typecodes', 'asarray',\n 'asfarray', 'ArrayType', 'UfuncType','mintypecode']\n\n_typecodes_by_elsize = 'DFdfluiwsb1c'\ndef mintypecode(typecodes,typeset='DFdf',default='d',savespace=0):\n \"\"\" Return a typecode in typeset such that for each\n t in typecodes\n array(typecode=typecode)[:] = array(typecode=t)\n is valid, looses no information, and array(typecode=typecode)\n element size is minimal unless when typecodes does not\n intersect with typeset then default is returned.\n As a special case, if savespace is False then 'D' is returned\n whenever typecodes contain 'F' and 'd'.\n If t in typecodes is not a string then t=t.typecode() is applied.\n \"\"\"\n typecodes = [(type(t) is type('') and t) or t.typecode() for t in typecodes]\n intersection = [t for t in typecodes if t in typeset]\n if not intersection:\n return default\n if not savespace and 'F' in intersection and 'd' in intersection:\n return 'D'\n l = []\n for t in intersection:\n i = _typecodes_by_elsize.index(t)\n l.append((i,t))\n l.sort()\n return l[0][1]\n\ndef asarray(a, typecode=None, savespace=None):\n \"\"\"asarray(a,typecode=None, savespace=0) returns a as a NumPy array.\n Unlike array(), no copy is performed if a is already an array.\n \"\"\"\n if type(a) is ArrayType:\n if typecode is None or typecode == a.typecode():\n if savespace is None or a.spacesaver()==savespace:\n return a\n else:\n r = a.astype(typecode)\n if not (savespace is None or a.spacesaver()==savespace):\n r.savespace(savespace)\n return r\n return multiarray.array(a,typecode,copy=0,savespace=savespace or 0)\n\ndef asfarray(a, typecode=None, savespace=None):\n \"\"\"asfarray(a,typecode=None, savespace=0) returns a as a NumPy float array.\"\"\"\n a = asarray(a,typecode,savespace)\n if typecode is None and a.typecode() not in 'CFfd':\n return a.astype('d')\n return a\n\nScalarType = [types.IntType, types.LongType, types.FloatType, types.ComplexType]\n\ntypecodes = Numeric.typecodes\ntypecodes['AllInteger'] = '1silbwu'\n\ntry:\n Char = Numeric.Character\nexcept AttributeError:\n Char = 'c'\n\ntoChar = lambda x: asarray(x).astype(Char)\ntoInt8 = lambda x: asarray(x).astype(Numeric.Int8)# or use variable names such as Byte\ntoUInt8 = lambda x: asarray(x).astype(Numeric.UnsignedInt8)\n_unsigned = 0\nif hasattr(Numeric,'UnsignedInt16'):\n toUInt16 = lambda x: asarray(x).astype(Numeric.UnsignedInt16)\n toUInt32 = lambda x: asarray(x).astype(Numeric.UnsignedInt32)\n _unsigned = 1\n \ntoInt16 = lambda x: asarray(x).astype(Numeric.Int16)\ntoInt32 = lambda x: asarray(x).astype(Numeric.Int32)\ntoInt = lambda x: asarray(x).astype(Numeric.Int)\ntoFloat32 = lambda x: asarray(x).astype(Numeric.Float32)\ntoFloat64 = lambda x: asarray(x).astype(Numeric.Float64)\ntoComplex32 = lambda x: asarray(x).astype(Numeric.Complex32)\ntoComplex64 = lambda x: asarray(x).astype(Numeric.Complex64)\n\n# This is for pre Numeric 21.x compatiblity. Adding it is harmless.\nif not hasattr(Numeric,'Character'):\n Numeric.Character = 'c'\n \ncast = {Numeric.Character: toChar,\n Numeric.UnsignedInt8: toUInt8,\n Numeric.Int8: toInt8,\n Numeric.Int16: toInt16,\n Numeric.Int32: toInt32,\n Numeric.Int: toInt,\n Numeric.Float32: toFloat32,\n Numeric.Float64: toFloat64,\n Numeric.Complex32: toComplex32,\n Numeric.Complex64: toComplex64}\n\nif _unsigned:\n cast[Numeric.UnsignedInt16] = toUInt16\n cast[Numeric.UnsignedInt32] = toUInt32\n \n\ndef isscalar(num):\n if isinstance(num, ArrayType):\n return len(num.shape) == 0 and num.typecode() != 'O'\n return type(num) in ScalarType\n\ndef real(val):\n aval = asarray(val)\n if aval.typecode() in ['F', 'D']:\n return aval.real\n else:\n return aval\n\ndef imag(val):\n aval = asarray(val)\n if aval.typecode() in ['F', 'D']:\n return aval.imag\n else:\n return array(0,aval.typecode())*aval\n\ndef iscomplex(x):\n return imag(x) != Numeric.zeros(asarray(x).shape)\n\ndef isreal(x):\n return imag(x) == Numeric.zeros(asarray(x).shape)\n\ndef iscomplexobj(x):\n return asarray(x).typecode() in ['F', 'D']\n\ndef isrealobj(x):\n return not asarray(x).typecode() in ['F', 'D']\n\n#-----------------------------------------------------------------------------\n\n##def isnan(val):\n## # fast, but apparently not portable (according to notes by Tim Peters)\n## #return val != val\n## # very slow -- should really use cephes methods or *something* different\n## import ieee_754\n## vals = ravel(val)\n## if array_iscomplex(vals):\n## r = array(map(ieee_754.isnan,real(vals))) \n## i = array(map(ieee_754.isnan,imag(vals)))\n## results = Numeric.logical_or(r,i)\n## else: \n## results = array(map(ieee_754.isnan,vals))\n## if isscalar(val):\n## results = results[0]\n## return results\n\ndef isposinf(val):\n return isinf(val) & (val > 0)\n \ndef isneginf(val):\n return isinf(val) & (val < 0)\n \n##def isinf(val):\n## return Numeric.logical_or(isposinf(val),isneginf(val))\n\n##def isfinite(val):\n## vals = asarray(val)\n## if iscomplexobj(vals):\n## r = isfinite(real(vals))\n## i = isfinite(imag(vals))\n## results = Numeric.logical_and(r,i)\n## else: \n## fin = Numeric.logical_not(isinf(val))\n## an = Numeric.logical_not(isnan(val))\n## results = Numeric.logical_and(fin,an)\n## return results \n\ndef nan_to_num(x):\n # mapping:\n # NaN -> 0\n # Inf -> limits.double_max\n # -Inf -> limits.double_min\n # complex not handled currently\n import limits\n try:\n t = x.typecode()\n except AttributeError:\n t = type(x)\n if t in [types.ComplexType,'F','D']: \n y = nan_to_num(x.real) + 1j * nan_to_num(x.imag)\n else: \n x = asarray(x)\n are_inf = isposinf(x)\n are_neg_inf = isneginf(x)\n are_nan = isnan(x)\n choose_array = are_neg_inf + are_nan * 2 + are_inf * 3\n y = Numeric.choose(choose_array,\n (x,limits.double_min, 0., limits.double_max))\n return y\n\n#-----------------------------------------------------------------------------\n\ndef real_if_close(a,tol=1e-13):\n a = asarray(a)\n if a.typecode() in ['F','D'] and Numeric.allclose(a.imag, 0, atol=tol):\n a = a.real\n return a\n\n\n#-----------------------------------------------------------------------------\n\n_namefromtype = {'c' : 'character',\n '1' : 'signed char',\n 'b' : 'unsigned char',\n 's' : 'short',\n 'w' : 'unsigned short',\n 'i' : 'integer',\n 'u' : 'unsigned integer',\n 'l' : 'long integer',\n 'f' : 'float',\n 'd' : 'double',\n 'F' : 'complex float',\n 'D' : 'complex double',\n 'O' : 'object'\n }\n\ndef typename(char):\n \"\"\"Return an english name for the given typecode character.\n \"\"\"\n return _namefromtype[char]\n\n#-----------------------------------------------------------------------------\n\n#determine the \"minimum common type code\" for a group of arrays.\narray_kind = {'i':0, 'l': 0, 'f': 0, 'd': 0, 'F': 1, 'D': 1}\narray_precision = {'i': 1, 'l': 1, 'f': 0, 'd': 1, 'F': 0, 'D': 1}\narray_type = [['f', 'd'], ['F', 'D']]\ndef common_type(*arrays):\n kind = 0\n precision = 0\n for a in arrays:\n t = a.typecode()\n kind = max(kind, array_kind[t])\n precision = max(precision, array_precision[t])\n return array_type[kind][precision]\n\nif __name__ == '__main__':\n print 'float epsilon:',float_epsilon\n print 'float tiny:',float_tiny\n print 'double epsilon:',double_epsilon\n print 'double tiny:',double_tiny\n", "methods": [ { "name": "mintypecode", "long_name": "mintypecode( typecodes , typeset = 'DFdf' , default = 'd' , savespace = 0 )", "filename": "type_check.py", "nloc": 14, "complexity": 11, "token_count": 122, "parameters": [ "typecodes", "typeset", "default", "savespace" ], "start_line": 19, "end_line": 42, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 24, "top_nesting_level": 0 }, { "name": "asarray", "long_name": "asarray( a , typecode = None , savespace = None )", "filename": "type_check.py", "nloc": 11, "complexity": 9, "token_count": 103, "parameters": [ "a", "typecode", "savespace" ], "start_line": 44, "end_line": 57, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 14, "top_nesting_level": 0 }, { "name": "asfarray", "long_name": "asfarray( a , typecode = None , savespace = None )", "filename": "type_check.py", "nloc": 5, "complexity": 3, "token_count": 47, "parameters": [ "a", "typecode", "savespace" ], "start_line": 59, "end_line": 64, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 6, "top_nesting_level": 0 }, { "name": "isscalar", "long_name": "isscalar( num )", "filename": "type_check.py", "nloc": 4, "complexity": 3, "token_count": 37, "parameters": [ "num" ], "start_line": 113, "end_line": 116, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 4, "top_nesting_level": 0 }, { "name": "real", "long_name": "real( val )", "filename": "type_check.py", "nloc": 6, "complexity": 2, "token_count": 32, "parameters": [ "val" ], "start_line": 118, "end_line": 123, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 6, "top_nesting_level": 0 }, { "name": "imag", "long_name": "imag( val )", "filename": "type_check.py", "nloc": 6, "complexity": 2, "token_count": 43, "parameters": [ "val" ], "start_line": 125, "end_line": 130, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 6, "top_nesting_level": 0 }, { "name": "iscomplex", "long_name": "iscomplex( x )", "filename": "type_check.py", "nloc": 2, "complexity": 1, "token_count": 22, "parameters": [ "x" ], "start_line": 132, "end_line": 133, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 2, "top_nesting_level": 0 }, { "name": "isreal", "long_name": "isreal( x )", "filename": "type_check.py", "nloc": 2, "complexity": 1, "token_count": 22, "parameters": [ "x" ], "start_line": 135, "end_line": 136, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 2, "top_nesting_level": 0 }, { "name": "iscomplexobj", "long_name": "iscomplexobj( x )", "filename": "type_check.py", "nloc": 2, "complexity": 1, "token_count": 20, "parameters": [ "x" ], "start_line": 138, "end_line": 139, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 2, "top_nesting_level": 0 }, { "name": "isrealobj", "long_name": "isrealobj( x )", "filename": "type_check.py", "nloc": 2, "complexity": 1, "token_count": 21, "parameters": [ "x" ], "start_line": 141, "end_line": 142, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 2, "top_nesting_level": 0 }, { "name": "isposinf", "long_name": "isposinf( val )", "filename": "type_check.py", "nloc": 2, "complexity": 1, "token_count": 16, "parameters": [ "val" ], "start_line": 162, "end_line": 163, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 2, "top_nesting_level": 0 }, { "name": "isneginf", "long_name": "isneginf( val )", "filename": "type_check.py", "nloc": 2, "complexity": 1, "token_count": 16, "parameters": [ "val" ], "start_line": 165, "end_line": 166, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 2, "top_nesting_level": 0 }, { "name": "nan_to_num", "long_name": "nan_to_num( x )", "filename": "type_check.py", "nloc": 17, "complexity": 3, "token_count": 117, "parameters": [ "x" ], "start_line": 183, "end_line": 204, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 22, "top_nesting_level": 0 }, { "name": "real_if_close", "long_name": "real_if_close( a , tol = 1e - 13 )", "filename": "type_check.py", "nloc": 5, "complexity": 3, "token_count": 52, "parameters": [ "a", "tol" ], "start_line": 208, "end_line": 212, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 5, "top_nesting_level": 0 }, { "name": "typename", "long_name": "typename( char )", "filename": "type_check.py", "nloc": 2, "complexity": 1, "token_count": 11, "parameters": [ "char" ], "start_line": 232, "end_line": 235, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 4, "top_nesting_level": 0 }, { "name": "common_type", "long_name": "common_type( * arrays )", "filename": "type_check.py", "nloc": 8, "complexity": 2, "token_count": 54, "parameters": [ "arrays" ], "start_line": 243, "end_line": 250, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 8, "top_nesting_level": 0 } ], "methods_before": [ { "name": "mintypecode", "long_name": "mintypecode( typecodes , typeset = 'DFdf' , default = 'd' , savespace = 0 )", "filename": "type_check.py", "nloc": 13, "complexity": 11, "token_count": 118, "parameters": [ "typecodes", "typeset", "default", "savespace" ], "start_line": 19, "end_line": 41, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 23, "top_nesting_level": 0 }, { "name": "asarray", "long_name": "asarray( a , typecode = None , savespace = None )", "filename": "type_check.py", "nloc": 11, "complexity": 9, "token_count": 103, "parameters": [ "a", "typecode", "savespace" ], "start_line": 43, "end_line": 56, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 14, "top_nesting_level": 0 }, { "name": "asfarray", "long_name": "asfarray( a , typecode = None , savespace = None )", "filename": "type_check.py", "nloc": 5, "complexity": 3, "token_count": 47, "parameters": [ "a", "typecode", "savespace" ], "start_line": 58, "end_line": 63, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 6, "top_nesting_level": 0 }, { "name": "isscalar", "long_name": "isscalar( num )", "filename": "type_check.py", "nloc": 4, "complexity": 3, "token_count": 37, "parameters": [ "num" ], "start_line": 112, "end_line": 115, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 4, "top_nesting_level": 0 }, { "name": "real", "long_name": "real( val )", "filename": "type_check.py", "nloc": 6, "complexity": 2, "token_count": 32, "parameters": [ "val" ], "start_line": 117, "end_line": 122, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 6, "top_nesting_level": 0 }, { "name": "imag", "long_name": "imag( val )", "filename": "type_check.py", "nloc": 6, "complexity": 2, "token_count": 43, "parameters": [ "val" ], "start_line": 124, "end_line": 129, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 6, "top_nesting_level": 0 }, { "name": "iscomplex", "long_name": "iscomplex( x )", "filename": "type_check.py", "nloc": 2, "complexity": 1, "token_count": 22, "parameters": [ "x" ], "start_line": 131, "end_line": 132, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 2, "top_nesting_level": 0 }, { "name": "isreal", "long_name": "isreal( x )", "filename": "type_check.py", "nloc": 2, "complexity": 1, "token_count": 22, "parameters": [ "x" ], "start_line": 134, "end_line": 135, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 2, "top_nesting_level": 0 }, { "name": "iscomplexobj", "long_name": "iscomplexobj( x )", "filename": "type_check.py", "nloc": 2, "complexity": 1, "token_count": 20, "parameters": [ "x" ], "start_line": 137, "end_line": 138, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 2, "top_nesting_level": 0 }, { "name": "isrealobj", "long_name": "isrealobj( x )", "filename": "type_check.py", "nloc": 2, "complexity": 1, "token_count": 21, "parameters": [ "x" ], "start_line": 140, "end_line": 141, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 2, "top_nesting_level": 0 }, { "name": "isposinf", "long_name": "isposinf( val )", "filename": "type_check.py", "nloc": 2, "complexity": 1, "token_count": 16, "parameters": [ "val" ], "start_line": 161, "end_line": 162, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 2, "top_nesting_level": 0 }, { "name": "isneginf", "long_name": "isneginf( val )", "filename": "type_check.py", "nloc": 2, "complexity": 1, "token_count": 16, "parameters": [ "val" ], "start_line": 164, "end_line": 165, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 2, "top_nesting_level": 0 }, { "name": "nan_to_num", "long_name": "nan_to_num( x )", "filename": "type_check.py", "nloc": 17, "complexity": 3, "token_count": 117, "parameters": [ "x" ], "start_line": 182, "end_line": 203, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 22, "top_nesting_level": 0 }, { "name": "real_if_close", "long_name": "real_if_close( a , tol = 1e - 13 )", "filename": "type_check.py", "nloc": 5, "complexity": 3, "token_count": 52, "parameters": [ "a", "tol" ], "start_line": 207, "end_line": 211, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 5, "top_nesting_level": 0 }, { "name": "typename", "long_name": "typename( char )", "filename": "type_check.py", "nloc": 2, "complexity": 1, "token_count": 11, "parameters": [ "char" ], "start_line": 231, "end_line": 234, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 4, "top_nesting_level": 0 }, { "name": "common_type", "long_name": "common_type( * arrays )", "filename": "type_check.py", "nloc": 8, "complexity": 2, "token_count": 54, "parameters": [ "arrays" ], "start_line": 242, "end_line": 249, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 8, "top_nesting_level": 0 } ], "changed_methods": [ { "name": "mintypecode", "long_name": "mintypecode( typecodes , typeset = 'DFdf' , default = 'd' , savespace = 0 )", "filename": "type_check.py", "nloc": 14, "complexity": 11, "token_count": 122, "parameters": [ "typecodes", "typeset", "default", "savespace" ], "start_line": 19, "end_line": 42, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 24, "top_nesting_level": 0 } ], "nloc": 163, "complexity": 45, "token_count": 1330, "diff_parsed": { "added": [ " typecodes = [(type(t) is type('') and t) or asarray(t).typecode()\\", " for t in typecodes]" ], "deleted": [ " typecodes = [(type(t) is type('') and t) or t.typecode() for t in typecodes]" ] } }, { "old_path": "scipy_distutils/info_scipy_distutils.py", "new_path": "scipy_distutils/info_scipy_distutils.py", "filename": "info_scipy_distutils.py", "extension": "py", "change_type": "MODIFY", "diff": "@@ -8,36 +8,36 @@\n Useful standalone modules\n -------------------------\n \n- system_info - get information about system resources\n- cpuinfo - query CPU information\n- from_template - process Fortran or signature template files\n- exec_command - provides highly portable commands.getstatusoutput\n+ system_info -- get information about system resources\n+ cpuinfo -- query CPU information\n+ from_template -- process Fortran or signature template files\n+ exec_command -- provides highly portable commands.getstatusoutput\n \n Modules to support Fortran compilers\n ------------------------------------\n \n- fcompiler - base class for Fortran compiler abstraction model\n- absoftfcompiler - Absoft Fortran 77/90 compiler\n- compaqfcompiler - Compaq Fortran 77/90 compiler\n- gnufcompiler - GNU Fortran 77 compiler\n- hpuxfcompiler - HPUX Fortran 90 compiler\n- ibmfcompiler - IBM XL Fortran 90/95 compiler\n- intelfcompiler - Intel Fortran 90 compilers\n- laheyfcompiler - Lahey/Fujitsu Fortran 95 compiler\n- mipsfcompiler - MIPSpro Fortran 77/90 compilers\n- nagfcompiler - NAGWare Fortran 95 compiler\n- pgfcompiler - Portland Group 77/90 compilers\n- sunfcompiler - Sun|Forte Developer|WorkShop 90 compilers\n- vastfcompile - Pacific-Sierra Research Fortran 90 compiler\n+ fcompiler -- base class for Fortran compiler abstraction model\n+ absoftfcompiler -- Absoft Fortran 77/90 compiler\n+ compaqfcompiler -- Compaq Fortran 77/90 compiler\n+ gnufcompiler -- GNU Fortran 77 compiler\n+ hpuxfcompiler -- HPUX Fortran 90 compiler\n+ ibmfcompiler -- IBM XL Fortran 90/95 compiler\n+ intelfcompiler -- Intel Fortran 90 compilers\n+ laheyfcompiler -- Lahey/Fujitsu Fortran 95 compiler\n+ mipsfcompiler -- MIPSpro Fortran 77/90 compilers\n+ nagfcompiler -- NAGWare Fortran 95 compiler\n+ pgfcompiler -- Portland Group 77/90 compilers\n+ sunfcompiler -- Sun|Forte Developer|WorkShop 90 compilers\n+ vastfcompile -- Pacific-Sierra Research Fortran 90 compiler\n \n Modules extending distutils\n ---------------------------\n \n- misc_util - various useful tools for scipy-style setup.py files.\n- lib2def - generate DEF from MSVC-compiled DLL\n- mingw32ccompiler - MingW32 compiler compatible with an MSVC built Python\n- command/config_compiler - support enhancing compiler flags\n- command/build_src - build swig, f2py, weave, callback sources\n+ misc_util -- various useful tools for scipy-style setup.py files.\n+ lib2def -- generate DEF from MSVC-compiled DLL\n+ mingw32ccompiler -- MingW32 compiler compatible with an MSVC built Python\n+ command.config_compiler -- support enhancing compiler flags\n+ command.build_src -- build swig, f2py, weave, callback sources\n \n \"\"\"\n standalone = 1\n", "added_lines": 22, "deleted_lines": 22, "source_code": "\"\"\"\nscipy_distutils\n===============\n\nModified version of distutils to handle fortran source code, f2py,\nand other issues in the scipy build process.\n\nUseful standalone modules\n-------------------------\n\n system_info -- get information about system resources\n cpuinfo -- query CPU information\n from_template -- process Fortran or signature template files\n exec_command -- provides highly portable commands.getstatusoutput\n\nModules to support Fortran compilers\n------------------------------------\n\n fcompiler -- base class for Fortran compiler abstraction model\n absoftfcompiler -- Absoft Fortran 77/90 compiler\n compaqfcompiler -- Compaq Fortran 77/90 compiler\n gnufcompiler -- GNU Fortran 77 compiler\n hpuxfcompiler -- HPUX Fortran 90 compiler\n ibmfcompiler -- IBM XL Fortran 90/95 compiler\n intelfcompiler -- Intel Fortran 90 compilers\n laheyfcompiler -- Lahey/Fujitsu Fortran 95 compiler\n mipsfcompiler -- MIPSpro Fortran 77/90 compilers\n nagfcompiler -- NAGWare Fortran 95 compiler\n pgfcompiler -- Portland Group 77/90 compilers\n sunfcompiler -- Sun|Forte Developer|WorkShop 90 compilers\n vastfcompile -- Pacific-Sierra Research Fortran 90 compiler\n\nModules extending distutils\n---------------------------\n\n misc_util -- various useful tools for scipy-style setup.py files.\n lib2def -- generate DEF from MSVC-compiled DLL\n mingw32ccompiler -- MingW32 compiler compatible with an MSVC built Python\n command.config_compiler -- support enhancing compiler flags\n command.build_src -- build swig, f2py, weave, callback sources\n\n\"\"\"\nstandalone = 1\n", "source_code_before": "\"\"\"\nscipy_distutils\n===============\n\nModified version of distutils to handle fortran source code, f2py,\nand other issues in the scipy build process.\n\nUseful standalone modules\n-------------------------\n\n system_info - get information about system resources\n cpuinfo - query CPU information\n from_template - process Fortran or signature template files\n exec_command - provides highly portable commands.getstatusoutput\n\nModules to support Fortran compilers\n------------------------------------\n\n fcompiler - base class for Fortran compiler abstraction model\n absoftfcompiler - Absoft Fortran 77/90 compiler\n compaqfcompiler - Compaq Fortran 77/90 compiler\n gnufcompiler - GNU Fortran 77 compiler\n hpuxfcompiler - HPUX Fortran 90 compiler\n ibmfcompiler - IBM XL Fortran 90/95 compiler\n intelfcompiler - Intel Fortran 90 compilers\n laheyfcompiler - Lahey/Fujitsu Fortran 95 compiler\n mipsfcompiler - MIPSpro Fortran 77/90 compilers\n nagfcompiler - NAGWare Fortran 95 compiler\n pgfcompiler - Portland Group 77/90 compilers\n sunfcompiler - Sun|Forte Developer|WorkShop 90 compilers\n vastfcompile - Pacific-Sierra Research Fortran 90 compiler\n\nModules extending distutils\n---------------------------\n\n misc_util - various useful tools for scipy-style setup.py files.\n lib2def - generate DEF from MSVC-compiled DLL\n mingw32ccompiler - MingW32 compiler compatible with an MSVC built Python\n command/config_compiler - support enhancing compiler flags\n command/build_src - build swig, f2py, weave, callback sources\n\n\"\"\"\nstandalone = 1\n", "methods": [], "methods_before": [], "changed_methods": [], "nloc": 43, "complexity": 0, "token_count": 4, "diff_parsed": { "added": [ " system_info -- get information about system resources", " cpuinfo -- query CPU information", " from_template -- process Fortran or signature template files", " exec_command -- provides highly portable commands.getstatusoutput", " fcompiler -- base class for Fortran compiler abstraction model", " absoftfcompiler -- Absoft Fortran 77/90 compiler", " compaqfcompiler -- Compaq Fortran 77/90 compiler", " gnufcompiler -- GNU Fortran 77 compiler", " hpuxfcompiler -- HPUX Fortran 90 compiler", " ibmfcompiler -- IBM XL Fortran 90/95 compiler", " intelfcompiler -- Intel Fortran 90 compilers", " laheyfcompiler -- Lahey/Fujitsu Fortran 95 compiler", " mipsfcompiler -- MIPSpro Fortran 77/90 compilers", " nagfcompiler -- NAGWare Fortran 95 compiler", " pgfcompiler -- Portland Group 77/90 compilers", " sunfcompiler -- Sun|Forte Developer|WorkShop 90 compilers", " vastfcompile -- Pacific-Sierra Research Fortran 90 compiler", " misc_util -- various useful tools for scipy-style setup.py files.", " lib2def -- generate DEF from MSVC-compiled DLL", " mingw32ccompiler -- MingW32 compiler compatible with an MSVC built Python", " command.config_compiler -- support enhancing compiler flags", " command.build_src -- build swig, f2py, weave, callback sources" ], "deleted": [ " system_info - get information about system resources", " cpuinfo - query CPU information", " from_template - process Fortran or signature template files", " exec_command - provides highly portable commands.getstatusoutput", " fcompiler - base class for Fortran compiler abstraction model", " absoftfcompiler - Absoft Fortran 77/90 compiler", " compaqfcompiler - Compaq Fortran 77/90 compiler", " gnufcompiler - GNU Fortran 77 compiler", " hpuxfcompiler - HPUX Fortran 90 compiler", " ibmfcompiler - IBM XL Fortran 90/95 compiler", " intelfcompiler - Intel Fortran 90 compilers", " laheyfcompiler - Lahey/Fujitsu Fortran 95 compiler", " mipsfcompiler - MIPSpro Fortran 77/90 compilers", " nagfcompiler - NAGWare Fortran 95 compiler", " pgfcompiler - Portland Group 77/90 compilers", " sunfcompiler - Sun|Forte Developer|WorkShop 90 compilers", " vastfcompile - Pacific-Sierra Research Fortran 90 compiler", " misc_util - various useful tools for scipy-style setup.py files.", " lib2def - generate DEF from MSVC-compiled DLL", " mingw32ccompiler - MingW32 compiler compatible with an MSVC built Python", " command/config_compiler - support enhancing compiler flags", " command/build_src - build swig, f2py, weave, callback sources" ] } }, { "old_path": "scipy_test/info_scipy_test.py", "new_path": "scipy_test/info_scipy_test.py", "filename": "info_scipy_test.py", "extension": "py", "change_type": "MODIFY", "diff": "@@ -5,7 +5,7 @@\n Modules\n -------\n \n- testing - useful tools for scipy-style testing sites.\n+ testing -- useful tools for scipy-style testing sites.\n \n \"\"\"\n standalone = 1\n", "added_lines": 1, "deleted_lines": 1, "source_code": "\"\"\"\nScipy testing tools\n===================\n\nModules\n-------\n\n testing -- useful tools for scipy-style testing sites.\n\n\"\"\"\nstandalone = 1\n", "source_code_before": "\"\"\"\nScipy testing tools\n===================\n\nModules\n-------\n\n testing - useful tools for scipy-style testing sites.\n\n\"\"\"\nstandalone = 1\n", "methods": [], "methods_before": [], "changed_methods": [], "nloc": 11, "complexity": 0, "token_count": 4, "diff_parsed": { "added": [ " testing -- useful tools for scipy-style testing sites." ], "deleted": [ " testing - useful tools for scipy-style testing sites." ] } }, { "old_path": "scipy_test/testing.py", "new_path": "scipy_test/testing.py", "filename": "testing.py", "extension": "py", "change_type": "MODIFY", "diff": "@@ -2,28 +2,28 @@\n Unit-testing\n ------------\n \n- ScipyTest - Scipy tests site manager\n- ScipyTestCase - unittest.TestCase with measure method\n- set_package_path - prepend package build directory to path\n- set_local_path - prepend local directory (to tests files) to path\n- restore_path - restore path after set_package_path\n+ ScipyTest -- Scipy tests site manager\n+ ScipyTestCase -- unittest.TestCase with measure method\n+ set_package_path -- prepend package build directory to path\n+ set_local_path -- prepend local directory (to tests files) to path\n+ restore_path -- restore path after set_package_path\n \n Timing tools\n ------------\n \n- jiffies - return 1/100ths of a second that the current process has used\n- memusage - virtual memory size in bytes of the running python [linux]\n+ jiffies -- return 1/100ths of a second that the current process has used\n+ memusage -- virtual memory size in bytes of the running python [linux]\n \n Utility functions\n -----------------\n \n- assert_equal\n- assert_almost_equal\n- assert_approx_equal\n- assert_array_equal\n- assert_array_almost_equal\n- assert_array_less\n- rand - array of random numbers from given shape\n+ assert_equal --\n+ assert_almost_equal --\n+ assert_approx_equal --\n+ assert_array_equal --\n+ assert_array_almost_equal --\n+ assert_array_less --\n+ rand -- array of random numbers from given shape\n \n \"\"\"\n \n@@ -104,6 +104,7 @@ def restore_path():\n print 'Removing %r from sys.path' % (sys.path[0])\n del sys.path[0]\n \n+__all__.extend(['jiffies','memusage'])\n if sys.platform[:5]=='linux':\n def jiffies(_proc_pid_stat = '/proc/%s/stat'%(os.getpid()),\n _load_time=time.time()):\n", "added_lines": 15, "deleted_lines": 14, "source_code": "\"\"\"\nUnit-testing\n------------\n\n ScipyTest -- Scipy tests site manager\n ScipyTestCase -- unittest.TestCase with measure method\n set_package_path -- prepend package build directory to path\n set_local_path -- prepend local directory (to tests files) to path\n restore_path -- restore path after set_package_path\n\nTiming tools\n------------\n\n jiffies -- return 1/100ths of a second that the current process has used\n memusage -- virtual memory size in bytes of the running python [linux]\n\nUtility functions\n-----------------\n\n assert_equal --\n assert_almost_equal --\n assert_approx_equal --\n assert_array_equal --\n assert_array_almost_equal --\n assert_array_less --\n rand -- array of random numbers from given shape\n\n\"\"\"\n\n__all__ = []\n\nimport os,sys,time,glob,string,traceback,unittest\nimport types\nimport imp\n\ntry:\n # These are used by Numeric tests.\n # If Numeric and scipy_base are not available, then some of the\n # functions below will not be available.\n from Numeric import alltrue,equal,shape,ravel,around,zeros,Float64,asarray,\\\n less_equal,array2string,less\n # `import scipy_base.fastumath as math` must be at the end of this file.\nexcept ImportError,msg:\n print msg\n\nDEBUG = 0\n\n__all__.append('set_package_path')\ndef set_package_path(level=1):\n \"\"\" Prepend package directory to sys.path.\n\n set_package_path should be called from a test_file.py that\n satisfies the following tree structure:\n\n //test_file.py\n\n Then the first existing path name from the following list\n\n /build/lib.-\n /..\n\n is prepended to sys.path.\n The caller is responsible for removing this path by using\n\n restore_path()\n \"\"\"\n from distutils.util import get_platform\n from scipy_distutils.misc_util import get_frame\n f = get_frame(level)\n if f.f_locals['__name__']=='__main__':\n testfile = sys.argv[0]\n else:\n testfile = f.f_locals['__file__']\n d = os.path.dirname(os.path.dirname(os.path.abspath(testfile)))\n d1 = os.path.join(d,'build','lib.%s-%s'%(get_platform(),sys.version[:3]))\n if not os.path.isdir(d1):\n d1 = os.path.dirname(d)\n if DEBUG:\n print 'Inserting %r to sys.path' % (d1)\n sys.path.insert(0,d1)\n\n__all__.append('set_local_path')\ndef set_local_path(reldir='', level=1):\n \"\"\" Prepend local directory to sys.path.\n\n The caller is responsible for removing this path by using\n\n restore_path()\n \"\"\"\n from scipy_distutils.misc_util import get_frame\n f = get_frame(level)\n if f.f_locals['__name__']=='__main__':\n testfile = sys.argv[0]\n else:\n testfile = f.f_locals['__file__']\n local_path = os.path.join(os.path.dirname(os.path.abspath(testfile)),reldir)\n if DEBUG:\n print 'Inserting %r to sys.path' % (local_path)\n sys.path.insert(0,local_path)\n\n__all__.append('restore_path')\ndef restore_path():\n if DEBUG:\n print 'Removing %r from sys.path' % (sys.path[0])\n del sys.path[0]\n\n__all__.extend(['jiffies','memusage'])\nif sys.platform[:5]=='linux':\n def jiffies(_proc_pid_stat = '/proc/%s/stat'%(os.getpid()),\n _load_time=time.time()):\n \"\"\" Return number of jiffies (1/100ths of a second) that this\n process has been scheduled in user mode. See man 5 proc. \"\"\"\n try:\n f=open(_proc_pid_stat,'r')\n l = f.readline().split(' ')\n f.close()\n return int(l[13])\n except:\n return int(100*(time.time()-_load_time))\n\n def memusage(_proc_pid_stat = '/proc/%s/stat'%(os.getpid())):\n \"\"\" Return virtual memory size in bytes of the running python.\n \"\"\"\n try:\n f=open(_proc_pid_stat,'r')\n l = f.readline().split(' ')\n f.close()\n return int(l[22])\n except:\n return\nelse:\n # os.getpid is not in all platforms available.\n # Using time is safe but inaccurate, especially when process\n # was suspended or sleeping.\n def jiffies(_load_time=time.time()):\n \"\"\" Return number of jiffies (1/100ths of a second) that this\n process has been scheduled in user mode. [Emulation with time.time]. \"\"\"\n return int(100*(time.time()-_load_time))\n\n def memusage():\n \"\"\" Return memory usage of running python. [Not implemented]\"\"\"\n return\n\n__all__.append('ScipyTestCase')\nclass ScipyTestCase (unittest.TestCase):\n\n def measure(self,code_str,times=1):\n \"\"\" Return elapsed time for executing code_str in the\n namespace of the caller for given times.\n \"\"\"\n frame = sys._getframe(1)\n locs,globs = frame.f_locals,frame.f_globals\n code = compile(code_str,\n 'ScipyTestCase runner for '+self.__class__.__name__,\n 'exec')\n i = 0\n elapsed = jiffies()\n while i>> ScipyTest().test(level=1,verbosity=2)\n\n is package name or its module object.\n\n Package is supposed to contain a directory tests/\n with test_*.py files where * refers to the names of submodules.\n\n test_*.py files are supposed to define a classes, derived\n from ScipyTestCase or unittest.TestCase, with methods having\n names starting with test or bench or check.\n\n And that is it! No need to implement test or test_suite functions\n in each .py file.\n\n Also old styled test_suite(level=1) hooks are supported but\n soon to be removed.\n \"\"\"\n def __init__(self, package='__main__'):\n self.package = package\n\n def _module_str(self, module):\n filename = module.__file__[-30:]\n if filename!=module.__file__:\n filename = '...'+filename\n return '' % (`module.__name__`, `filename`)\n\n def _get_method_names(self,clsobj,level):\n names = []\n for mthname in _get_all_method_names(clsobj):\n if mthname[:5] not in ['bench','check'] \\\n and mthname[:4] not in ['test']:\n continue\n mth = getattr(clsobj, mthname)\n if type(mth) is not types.MethodType:\n continue\n d = mth.im_func.func_defaults\n if d is not None:\n mthlevel = d[0]\n else:\n mthlevel = 1\n if level>=mthlevel:\n if mthname not in names:\n names.append(mthname)\n for base in clsobj.__bases__:\n for n in self._get_method_names(base,level):\n if n not in names:\n names.append(n)\n return names\n\n def _get_module_tests(self,module,level):\n mstr = self._module_str\n d,f = os.path.split(module.__file__)\n\n short_module_name = os.path.splitext(os.path.basename(f))[0]\n if short_module_name=='__init__':\n short_module_name = module.__name__.split('.')[-1]\n\n test_dir = os.path.join(d,'tests')\n test_file = os.path.join(test_dir,'test_'+short_module_name+'.py')\n\n local_test_dir = os.path.join(os.getcwd(),'tests')\n local_test_file = os.path.join(local_test_dir,\n 'test_'+short_module_name+'.py')\n if os.path.basename(os.path.dirname(local_test_dir)) \\\n == os.path.basename(os.path.dirname(test_dir)) \\\n and os.path.isfile(local_test_file):\n test_file = local_test_file\n\n if not os.path.isfile(test_file):\n if short_module_name[:5]=='info_' \\\n and short_module_name[5:]==module.__name__.split('.')[-2]:\n return []\n if short_module_name in ['__cvs_version__','__svn_version__']:\n return []\n if short_module_name[-8:]=='_version' \\\n and short_module_name[:-8]==module.__name__.split('.')[-2]:\n return []\n print ' !! No test file %r found for %s' \\\n % (os.path.basename(test_file), mstr(module))\n return []\n\n try:\n if sys.version[:3]=='2.1':\n # Workaround for Python 2.1 .pyc file generator bug\n import random\n pref = '-nopyc'+`random.randint(1,100)`\n else:\n pref = ''\n f = open(test_file,'r')\n test_module = imp.load_module(\\\n module.__name__+'.test_'+short_module_name+pref,\n f, test_file+pref,('.py', 'r', 1))\n f.close()\n if sys.version[:3]=='2.1' and os.path.isfile(test_file+pref+'c'):\n os.remove(test_file+pref+'c')\n except:\n print ' !! FAILURE importing tests for ', mstr(module)\n print ' ',\n output_exception()\n return []\n return self._get_suite_list(test_module, level, module.__name__)\n\n def _get_suite_list(self, test_module, level, module_name='__main__'):\n mstr = self._module_str\n if hasattr(test_module,'test_suite'):\n # Using old styled test suite\n try:\n total_suite = test_module.test_suite(level)\n return total_suite._tests\n except:\n print ' !! FAILURE building tests for ', mstr(test_module)\n print ' ',\n output_exception()\n return []\n suite_list = []\n for name in dir(test_module):\n obj = getattr(test_module, name)\n if type(obj) is not type(unittest.TestCase) \\\n or not issubclass(obj, unittest.TestCase) \\\n or obj.__name__[:4] != 'test':\n continue\n suite_list.extend(map(obj,self._get_method_names(obj,level)))\n print ' Found',len(suite_list),'tests for',module_name\n return suite_list\n\n def _touch_ppimported(self, module):\n from scipy_base.ppimport import _ModuleLoader\n if os.path.isdir(os.path.join(os.path.dirname(module.__file__),'tests')):\n # only touching those modules that have tests/ directory\n try: module._pliuh_plauh\n except AttributeError: pass\n for name in dir(module):\n obj = getattr(module,name)\n if isinstance(obj,_ModuleLoader) \\\n and not hasattr(obj,'_ppimport_module') \\\n and not hasattr(obj,'_ppimport_exc_info'):\n self._touch_ppimported(obj)\n\n def test(self,level=1,verbosity=1):\n \"\"\" Run Scipy module test suite with level and verbosity.\n \"\"\"\n if type(self.package) is type(''):\n exec 'import %s as this_package' % (self.package)\n else:\n this_package = self.package\n\n self._touch_ppimported(this_package)\n\n package_name = this_package.__name__\n\n suites = []\n for name, module in sys.modules.items():\n if package_name != name[:len(package_name)] \\\n or module is None \\\n or os.path.basename(os.path.dirname(module.__file__))=='tests':\n continue\n suites.extend(self._get_module_tests(module, level))\n\n suites.extend(self._get_suite_list(sys.modules[package_name], level))\n\n all_tests = unittest.TestSuite(suites)\n runner = unittest.TextTestRunner(verbosity=verbosity)\n runner.run(all_tests)\n return runner\n\n def run(self):\n \"\"\" Run Scipy module test suite with level and verbosity\n taken from sys.argv. Requires optparse module.\n \"\"\"\n try:\n from optparse import OptionParser\n except ImportError:\n print 'Failed to import optparse module, ignoring.'\n return self.test()\n usage = r'usage: %prog [-v ] [-l ]'\n parser = OptionParser(usage)\n parser.add_option(\"-v\", \"--verbosity\",\n action=\"store\",\n dest=\"verbosity\",\n default=1,\n type='int')\n parser.add_option(\"-l\", \"--level\",\n action=\"store\",\n dest=\"level\",\n default=1,\n type='int')\n (options, args) = parser.parse_args()\n self.test(options.level,options.verbosity)\n\n#------------\n \ndef remove_ignored_patterns(files,pattern):\n from fnmatch import fnmatch\n good_files = []\n for file in files:\n if not fnmatch(file,pattern):\n good_files.append(file)\n return good_files\n\ndef remove_ignored_files(original,ignored_files,cur_dir):\n \"\"\" This is actually expanded to do pattern matching.\n\n \"\"\"\n if not ignored_files: ignored_files = []\n ignored_modules = map(lambda x: x+'.py',ignored_files)\n ignored_packages = ignored_files[:]\n # always ignore setup.py and __init__.py files\n ignored_files = ['setup.py','setup_*.py','__init__.py']\n ignored_files += ignored_modules + ignored_packages\n ignored_files = map(lambda x,cur_dir=cur_dir: os.path.join(cur_dir,x),\n ignored_files)\n #print 'ignored:', ignored_files\n #good_files = filter(lambda x,ignored = ignored_files: x not in ignored,\n # original)\n good_files = original\n for pattern in ignored_files:\n good_files = remove_ignored_patterns(good_files,pattern)\n\n return good_files\n\n__all__.append('harvest_modules')\ndef harvest_modules(package,ignore=None):\n \"\"\"* Retreive a list of all modules that live within a package.\n\n Only retreive files that are immediate children of the\n package -- do not recurse through child packages or\n directories. The returned list contains actual modules, not\n just their names.\n *\"\"\"\n d,f = os.path.split(package.__file__)\n\n # go through the directory and import every py file there.\n common_dir = os.path.join(d,'*.py')\n py_files = glob.glob(common_dir)\n #py_files.remove(os.path.join(d,'__init__.py'))\n #py_files.remove(os.path.join(d,'setup.py'))\n\n py_files = remove_ignored_files(py_files,ignore,d)\n #print 'py_files:', py_files\n try:\n prefix = package.__name__\n except:\n prefix = ''\n\n all_modules = []\n for file in py_files:\n d,f = os.path.split(file)\n base,ext = os.path.splitext(f)\n mod = prefix + '.' + base\n #print 'module: import ' + mod\n try:\n exec ('import ' + mod)\n all_modules.append(eval(mod))\n except:\n print 'FAILURE to import ' + mod\n output_exception()\n\n return all_modules\n\n__all__.append('harvest_packages')\ndef harvest_packages(package,ignore = None):\n \"\"\" Retreive a list of all sub-packages that live within a package.\n\n Only retreive packages that are immediate children of this\n package -- do not recurse through child packages or\n directories. The returned list contains actual package objects, not\n just their names.\n \"\"\"\n join = os.path.join\n\n d,f = os.path.split(package.__file__)\n\n common_dir = os.path.abspath(d)\n all_files = os.listdir(d)\n\n all_files = remove_ignored_files(all_files,ignore,'')\n #print 'all_files:', all_files\n try:\n prefix = package.__name__\n except:\n prefix = ''\n all_packages = []\n for directory in all_files:\n path = join(common_dir,directory)\n if os.path.isdir(path) and \\\n os.path.exists(join(path,'__init__.py')):\n sub_package = prefix + '.' + directory\n #print 'sub-package import ' + sub_package\n try:\n exec ('import ' + sub_package)\n all_packages.append(eval(sub_package))\n except:\n print 'FAILURE to import ' + sub_package\n output_exception()\n return all_packages\n\n__all__.append('harvest_modules_and_packages')\ndef harvest_modules_and_packages(package,ignore=None):\n \"\"\" Retreive list of all packages and modules that live within a package.\n\n See harvest_packages() and harvest_modules()\n \"\"\"\n all = harvest_modules(package,ignore) + harvest_packages(package,ignore)\n return all\n\n__all__.append('harvest_test_suites')\ndef harvest_test_suites(package,ignore = None,level=10):\n \"\"\"\n package -- the module to test. This is an actual module object\n (not a string)\n ignore -- a list of module names to omit from the tests\n level -- a value between 1 and 10. 1 will run the minimum number\n of tests. This is a fast \"smoke test\". Tests that take\n longer to run should have higher numbers ranging up to 10.\n \"\"\"\n suites=[]\n test_modules = harvest_modules_and_packages(package,ignore)\n #for i in test_modules:\n # print i.__name__\n for module in test_modules:\n if hasattr(module,'test_suite'):\n try:\n suite = module.test_suite(level=level)\n if suite:\n suites.append(suite)\n else:\n print \" !! FAILURE without error - shouldn't happen\",\n print module.__name__\n except:\n print ' !! FAILURE building test for ', module.__name__\n print ' ',\n output_exception()\n else:\n try:\n print 'No test suite found for ', module.__name__\n except AttributeError:\n # __version__.py getting replaced by a string throws a kink\n # in checking for modules, so we think is a module has\n # actually been overwritten\n print 'No test suite found for ', str(module)\n total_suite = unittest.TestSuite(suites)\n return total_suite\n\n__all__.append('module_test')\ndef module_test(mod_name,mod_file,level=10):\n \"\"\"*\n\n *\"\"\"\n #print 'testing', mod_name\n d,f = os.path.split(mod_file)\n\n # insert the tests directory to the python path\n test_dir = os.path.join(d,'tests')\n sys.path.insert(0,test_dir)\n\n # call the \"test_xxx.test()\" function for the appropriate\n # module.\n\n # This should deal with package naming issues correctly\n short_mod_name = string.split(mod_name,'.')[-1]\n test_module = 'test_' + short_mod_name\n test_string = 'import %s;reload(%s);%s.test(%d)' % \\\n ((test_module,)*3 + (level,))\n\n # This would be better cause it forces a reload of the orginal\n # module. It doesn't behave with packages however.\n #test_string = 'reload(%s);import %s;reload(%s);%s.test(%d)' % \\\n # ((mod_name,) + (test_module,)*3)\n exec(test_string)\n\n # remove test directory from python path.\n sys.path = sys.path[1:]\n\n__all__.append('module_test_suite')\ndef module_test_suite(mod_name,mod_file,level=10):\n #try:\n print ' creating test suite for:', mod_name\n d,f = os.path.split(mod_file)\n\n # insert the tests directory to the python path\n test_dir = os.path.join(d,'tests')\n sys.path.insert(0,test_dir)\n\n # call the \"test_xxx.test()\" function for the appropriate\n # module.\n\n # This should deal with package naming issues correctly\n short_mod_name = string.split(mod_name,'.')[-1]\n test_module = 'test_' + short_mod_name\n test_string = 'import %s;reload(%s);suite = %s.test_suite(%d)' % \\\n ((test_module,)*3+(level,))\n #print test_string\n exec(test_string)\n\n # remove test directory from python path.\n sys.path = sys.path[1:]\n return suite\n #except:\n # print ' !! FAILURE loading test suite from', test_module, ':'\n # print ' ',\n # output_exception()\n\n\n# Utility function to facilitate testing.\n\n__all__.append('assert_equal')\ndef assert_equal(actual,desired,err_msg='',verbose=1):\n \"\"\" Raise an assertion if two items are not\n equal. I think this should be part of unittest.py\n \"\"\"\n msg = '\\nItems are not equal:\\n' + err_msg\n try:\n if ( verbose and len(repr(desired)) < 100 and len(repr(actual)) ):\n msg = msg \\\n + 'DESIRED: ' + repr(desired) \\\n + '\\nACTUAL: ' + repr(actual)\n except:\n msg = msg \\\n + 'DESIRED: ' + repr(desired) \\\n + '\\nACTUAL: ' + repr(actual)\n assert desired == actual, msg\n\n__all__.append('assert_almost_equal')\ndef assert_almost_equal(actual,desired,decimal=7,err_msg='',verbose=1):\n \"\"\" Raise an assertion if two items are not\n equal. I think this should be part of unittest.py\n \"\"\"\n msg = '\\nItems are not equal:\\n' + err_msg\n try:\n if ( verbose and len(repr(desired)) < 100 and len(repr(actual)) ):\n msg = msg \\\n + 'DESIRED: ' + repr(desired) \\\n + '\\nACTUAL: ' + repr(actual)\n except:\n msg = msg \\\n + 'DESIRED: ' + repr(desired) \\\n + '\\nACTUAL: ' + repr(actual)\n assert round(abs(desired - actual),decimal) == 0, msg\n\n__all__.append('assert_approx_equal')\ndef assert_approx_equal(actual,desired,significant=7,err_msg='',verbose=1):\n \"\"\" Raise an assertion if two items are not\n equal. I think this should be part of unittest.py\n Approximately equal is defined as the number of significant digits\n correct\n \"\"\"\n msg = '\\nItems are not equal to %d significant digits:\\n' % significant\n msg += err_msg\n actual, desired = map(float, (actual, desired))\n # Normalized the numbers to be in range (-10.0,10.0)\n scale = pow(10,math.floor(math.log10(0.5*(abs(desired)+abs(actual)))))\n try:\n sc_desired = desired/scale\n except ZeroDivisionError:\n sc_desired = 0.0\n try:\n sc_actual = actual/scale\n except ZeroDivisionError:\n sc_actual = 0.0\n try:\n if ( verbose and len(repr(desired)) < 100 and len(repr(actual)) ):\n msg = msg \\\n + 'DESIRED: ' + repr(desired) \\\n + '\\nACTUAL: ' + repr(actual)\n except:\n msg = msg \\\n + 'DESIRED: ' + repr(desired) \\\n + '\\nACTUAL: ' + repr(actual)\n assert math.fabs(sc_desired - sc_actual) < pow(10.,-1*significant), msg\n\n\n__all__.append('assert_array_equal')\ndef assert_array_equal(x,y,err_msg=''):\n x,y = asarray(x), asarray(y)\n msg = '\\nArrays are not equal'\n try:\n assert 0 in [len(shape(x)),len(shape(y))] \\\n or (len(shape(x))==len(shape(y)) and \\\n alltrue(equal(shape(x),shape(y)))),\\\n msg + ' (shapes %s, %s mismatch):\\n\\t' \\\n % (shape(x),shape(y)) + err_msg\n reduced = ravel(equal(x,y))\n cond = alltrue(reduced)\n if not cond:\n s1 = array2string(x,precision=16)\n s2 = array2string(y,precision=16)\n if len(s1)>120: s1 = s1[:120] + '...'\n if len(s2)>120: s2 = s2[:120] + '...'\n match = 100-100.0*reduced.tolist().count(1)/len(reduced)\n msg = msg + ' (mismatch %s%%):\\n\\tArray 1: %s\\n\\tArray 2: %s' % (match,s1,s2)\n assert cond,\\\n msg + '\\n\\t' + err_msg\n except ValueError:\n raise ValueError, msg\n\n__all__.append('assert_array_almost_equal')\ndef assert_array_almost_equal(x,y,decimal=6,err_msg=''):\n x = asarray(x)\n y = asarray(y)\n msg = '\\nArrays are not almost equal'\n try:\n cond = alltrue(equal(shape(x),shape(y)))\n if not cond:\n msg = msg + ' (shapes mismatch):\\n\\t'\\\n 'Shape of array 1: %s\\n\\tShape of array 2: %s' % (shape(x),shape(y))\n assert cond, msg + '\\n\\t' + err_msg\n reduced = ravel(equal(less_equal(around(abs(x-y),decimal),10.0**(-decimal)),1))\n cond = alltrue(reduced)\n if not cond:\n s1 = array2string(x,precision=decimal+1)\n s2 = array2string(y,precision=decimal+1)\n if len(s1)>120: s1 = s1[:120] + '...'\n if len(s2)>120: s2 = s2[:120] + '...'\n match = 100-100.0*reduced.tolist().count(1)/len(reduced)\n msg = msg + ' (mismatch %s%%):\\n\\tArray 1: %s\\n\\tArray 2: %s' % (match,s1,s2)\n assert cond,\\\n msg + '\\n\\t' + err_msg\n except ValueError:\n print sys.exc_value\n print shape(x),shape(y)\n print x, y\n raise ValueError, 'arrays are not almost equal'\n\n__all__.append('assert_array_less')\ndef assert_array_less(x,y,err_msg=''):\n x,y = asarray(x), asarray(y)\n msg = '\\nArrays are not less-ordered'\n try:\n assert alltrue(equal(shape(x),shape(y))),\\\n msg + ' (shapes mismatch):\\n\\t' + err_msg\n reduced = ravel(less(x,y))\n cond = alltrue(reduced)\n if not cond:\n s1 = array2string(x,precision=16)\n s2 = array2string(y,precision=16)\n if len(s1)>120: s1 = s1[:120] + '...'\n if len(s2)>120: s2 = s2[:120] + '...'\n match = 100-100.0*reduced.tolist().count(1)/len(reduced)\n msg = msg + ' (mismatch %s%%):\\n\\tArray 1: %s\\n\\tArray 2: %s' % (match,s1,s2)\n assert cond,\\\n msg + '\\n\\t' + err_msg\n except ValueError:\n print shape(x),shape(y)\n raise ValueError, 'arrays are not less-ordered'\n\n__all__.append('rand')\ndef rand(*args):\n \"\"\" Returns an array of random numbers with the given shape.\n used for testing\n \"\"\"\n import random\n results = zeros(args,Float64)\n f = results.flat\n for i in range(len(f)):\n f[i] = random.random()\n return results\n\ndef output_exception():\n try:\n type, value, tb = sys.exc_info()\n info = traceback.extract_tb(tb)\n #this is more verbose\n #traceback.print_exc()\n filename, lineno, function, text = info[-1] # last line only\n print \"%s:%d: %s: %s (in %s)\" %\\\n (filename, lineno, type.__name__, str(value), function)\n finally:\n type = value = tb = None # clean up\n\ntry:\n import scipy_base.fastumath as math\nexcept ImportError,msg:\n print msg\n import math\n", "source_code_before": "\"\"\"\nUnit-testing\n------------\n\n ScipyTest - Scipy tests site manager\n ScipyTestCase - unittest.TestCase with measure method\n set_package_path - prepend package build directory to path\n set_local_path - prepend local directory (to tests files) to path\n restore_path - restore path after set_package_path\n\nTiming tools\n------------\n\n jiffies - return 1/100ths of a second that the current process has used\n memusage - virtual memory size in bytes of the running python [linux]\n\nUtility functions\n-----------------\n\n assert_equal\n assert_almost_equal\n assert_approx_equal\n assert_array_equal\n assert_array_almost_equal\n assert_array_less\n rand - array of random numbers from given shape\n\n\"\"\"\n\n__all__ = []\n\nimport os,sys,time,glob,string,traceback,unittest\nimport types\nimport imp\n\ntry:\n # These are used by Numeric tests.\n # If Numeric and scipy_base are not available, then some of the\n # functions below will not be available.\n from Numeric import alltrue,equal,shape,ravel,around,zeros,Float64,asarray,\\\n less_equal,array2string,less\n # `import scipy_base.fastumath as math` must be at the end of this file.\nexcept ImportError,msg:\n print msg\n\nDEBUG = 0\n\n__all__.append('set_package_path')\ndef set_package_path(level=1):\n \"\"\" Prepend package directory to sys.path.\n\n set_package_path should be called from a test_file.py that\n satisfies the following tree structure:\n\n //test_file.py\n\n Then the first existing path name from the following list\n\n /build/lib.-\n /..\n\n is prepended to sys.path.\n The caller is responsible for removing this path by using\n\n restore_path()\n \"\"\"\n from distutils.util import get_platform\n from scipy_distutils.misc_util import get_frame\n f = get_frame(level)\n if f.f_locals['__name__']=='__main__':\n testfile = sys.argv[0]\n else:\n testfile = f.f_locals['__file__']\n d = os.path.dirname(os.path.dirname(os.path.abspath(testfile)))\n d1 = os.path.join(d,'build','lib.%s-%s'%(get_platform(),sys.version[:3]))\n if not os.path.isdir(d1):\n d1 = os.path.dirname(d)\n if DEBUG:\n print 'Inserting %r to sys.path' % (d1)\n sys.path.insert(0,d1)\n\n__all__.append('set_local_path')\ndef set_local_path(reldir='', level=1):\n \"\"\" Prepend local directory to sys.path.\n\n The caller is responsible for removing this path by using\n\n restore_path()\n \"\"\"\n from scipy_distutils.misc_util import get_frame\n f = get_frame(level)\n if f.f_locals['__name__']=='__main__':\n testfile = sys.argv[0]\n else:\n testfile = f.f_locals['__file__']\n local_path = os.path.join(os.path.dirname(os.path.abspath(testfile)),reldir)\n if DEBUG:\n print 'Inserting %r to sys.path' % (local_path)\n sys.path.insert(0,local_path)\n\n__all__.append('restore_path')\ndef restore_path():\n if DEBUG:\n print 'Removing %r from sys.path' % (sys.path[0])\n del sys.path[0]\n\nif sys.platform[:5]=='linux':\n def jiffies(_proc_pid_stat = '/proc/%s/stat'%(os.getpid()),\n _load_time=time.time()):\n \"\"\" Return number of jiffies (1/100ths of a second) that this\n process has been scheduled in user mode. See man 5 proc. \"\"\"\n try:\n f=open(_proc_pid_stat,'r')\n l = f.readline().split(' ')\n f.close()\n return int(l[13])\n except:\n return int(100*(time.time()-_load_time))\n\n def memusage(_proc_pid_stat = '/proc/%s/stat'%(os.getpid())):\n \"\"\" Return virtual memory size in bytes of the running python.\n \"\"\"\n try:\n f=open(_proc_pid_stat,'r')\n l = f.readline().split(' ')\n f.close()\n return int(l[22])\n except:\n return\nelse:\n # os.getpid is not in all platforms available.\n # Using time is safe but inaccurate, especially when process\n # was suspended or sleeping.\n def jiffies(_load_time=time.time()):\n \"\"\" Return number of jiffies (1/100ths of a second) that this\n process has been scheduled in user mode. [Emulation with time.time]. \"\"\"\n return int(100*(time.time()-_load_time))\n\n def memusage():\n \"\"\" Return memory usage of running python. [Not implemented]\"\"\"\n return\n\n__all__.append('ScipyTestCase')\nclass ScipyTestCase (unittest.TestCase):\n\n def measure(self,code_str,times=1):\n \"\"\" Return elapsed time for executing code_str in the\n namespace of the caller for given times.\n \"\"\"\n frame = sys._getframe(1)\n locs,globs = frame.f_locals,frame.f_globals\n code = compile(code_str,\n 'ScipyTestCase runner for '+self.__class__.__name__,\n 'exec')\n i = 0\n elapsed = jiffies()\n while i>> ScipyTest().test(level=1,verbosity=2)\n\n is package name or its module object.\n\n Package is supposed to contain a directory tests/\n with test_*.py files where * refers to the names of submodules.\n\n test_*.py files are supposed to define a classes, derived\n from ScipyTestCase or unittest.TestCase, with methods having\n names starting with test or bench or check.\n\n And that is it! No need to implement test or test_suite functions\n in each .py file.\n\n Also old styled test_suite(level=1) hooks are supported but\n soon to be removed.\n \"\"\"\n def __init__(self, package='__main__'):\n self.package = package\n\n def _module_str(self, module):\n filename = module.__file__[-30:]\n if filename!=module.__file__:\n filename = '...'+filename\n return '' % (`module.__name__`, `filename`)\n\n def _get_method_names(self,clsobj,level):\n names = []\n for mthname in _get_all_method_names(clsobj):\n if mthname[:5] not in ['bench','check'] \\\n and mthname[:4] not in ['test']:\n continue\n mth = getattr(clsobj, mthname)\n if type(mth) is not types.MethodType:\n continue\n d = mth.im_func.func_defaults\n if d is not None:\n mthlevel = d[0]\n else:\n mthlevel = 1\n if level>=mthlevel:\n if mthname not in names:\n names.append(mthname)\n for base in clsobj.__bases__:\n for n in self._get_method_names(base,level):\n if n not in names:\n names.append(n)\n return names\n\n def _get_module_tests(self,module,level):\n mstr = self._module_str\n d,f = os.path.split(module.__file__)\n\n short_module_name = os.path.splitext(os.path.basename(f))[0]\n if short_module_name=='__init__':\n short_module_name = module.__name__.split('.')[-1]\n\n test_dir = os.path.join(d,'tests')\n test_file = os.path.join(test_dir,'test_'+short_module_name+'.py')\n\n local_test_dir = os.path.join(os.getcwd(),'tests')\n local_test_file = os.path.join(local_test_dir,\n 'test_'+short_module_name+'.py')\n if os.path.basename(os.path.dirname(local_test_dir)) \\\n == os.path.basename(os.path.dirname(test_dir)) \\\n and os.path.isfile(local_test_file):\n test_file = local_test_file\n\n if not os.path.isfile(test_file):\n if short_module_name[:5]=='info_' \\\n and short_module_name[5:]==module.__name__.split('.')[-2]:\n return []\n if short_module_name in ['__cvs_version__','__svn_version__']:\n return []\n if short_module_name[-8:]=='_version' \\\n and short_module_name[:-8]==module.__name__.split('.')[-2]:\n return []\n print ' !! No test file %r found for %s' \\\n % (os.path.basename(test_file), mstr(module))\n return []\n\n try:\n if sys.version[:3]=='2.1':\n # Workaround for Python 2.1 .pyc file generator bug\n import random\n pref = '-nopyc'+`random.randint(1,100)`\n else:\n pref = ''\n f = open(test_file,'r')\n test_module = imp.load_module(\\\n module.__name__+'.test_'+short_module_name+pref,\n f, test_file+pref,('.py', 'r', 1))\n f.close()\n if sys.version[:3]=='2.1' and os.path.isfile(test_file+pref+'c'):\n os.remove(test_file+pref+'c')\n except:\n print ' !! FAILURE importing tests for ', mstr(module)\n print ' ',\n output_exception()\n return []\n return self._get_suite_list(test_module, level, module.__name__)\n\n def _get_suite_list(self, test_module, level, module_name='__main__'):\n mstr = self._module_str\n if hasattr(test_module,'test_suite'):\n # Using old styled test suite\n try:\n total_suite = test_module.test_suite(level)\n return total_suite._tests\n except:\n print ' !! FAILURE building tests for ', mstr(test_module)\n print ' ',\n output_exception()\n return []\n suite_list = []\n for name in dir(test_module):\n obj = getattr(test_module, name)\n if type(obj) is not type(unittest.TestCase) \\\n or not issubclass(obj, unittest.TestCase) \\\n or obj.__name__[:4] != 'test':\n continue\n suite_list.extend(map(obj,self._get_method_names(obj,level)))\n print ' Found',len(suite_list),'tests for',module_name\n return suite_list\n\n def _touch_ppimported(self, module):\n from scipy_base.ppimport import _ModuleLoader\n if os.path.isdir(os.path.join(os.path.dirname(module.__file__),'tests')):\n # only touching those modules that have tests/ directory\n try: module._pliuh_plauh\n except AttributeError: pass\n for name in dir(module):\n obj = getattr(module,name)\n if isinstance(obj,_ModuleLoader) \\\n and not hasattr(obj,'_ppimport_module') \\\n and not hasattr(obj,'_ppimport_exc_info'):\n self._touch_ppimported(obj)\n\n def test(self,level=1,verbosity=1):\n \"\"\" Run Scipy module test suite with level and verbosity.\n \"\"\"\n if type(self.package) is type(''):\n exec 'import %s as this_package' % (self.package)\n else:\n this_package = self.package\n\n self._touch_ppimported(this_package)\n\n package_name = this_package.__name__\n\n suites = []\n for name, module in sys.modules.items():\n if package_name != name[:len(package_name)] \\\n or module is None \\\n or os.path.basename(os.path.dirname(module.__file__))=='tests':\n continue\n suites.extend(self._get_module_tests(module, level))\n\n suites.extend(self._get_suite_list(sys.modules[package_name], level))\n\n all_tests = unittest.TestSuite(suites)\n runner = unittest.TextTestRunner(verbosity=verbosity)\n runner.run(all_tests)\n return runner\n\n def run(self):\n \"\"\" Run Scipy module test suite with level and verbosity\n taken from sys.argv. Requires optparse module.\n \"\"\"\n try:\n from optparse import OptionParser\n except ImportError:\n print 'Failed to import optparse module, ignoring.'\n return self.test()\n usage = r'usage: %prog [-v ] [-l ]'\n parser = OptionParser(usage)\n parser.add_option(\"-v\", \"--verbosity\",\n action=\"store\",\n dest=\"verbosity\",\n default=1,\n type='int')\n parser.add_option(\"-l\", \"--level\",\n action=\"store\",\n dest=\"level\",\n default=1,\n type='int')\n (options, args) = parser.parse_args()\n self.test(options.level,options.verbosity)\n\n#------------\n \ndef remove_ignored_patterns(files,pattern):\n from fnmatch import fnmatch\n good_files = []\n for file in files:\n if not fnmatch(file,pattern):\n good_files.append(file)\n return good_files\n\ndef remove_ignored_files(original,ignored_files,cur_dir):\n \"\"\" This is actually expanded to do pattern matching.\n\n \"\"\"\n if not ignored_files: ignored_files = []\n ignored_modules = map(lambda x: x+'.py',ignored_files)\n ignored_packages = ignored_files[:]\n # always ignore setup.py and __init__.py files\n ignored_files = ['setup.py','setup_*.py','__init__.py']\n ignored_files += ignored_modules + ignored_packages\n ignored_files = map(lambda x,cur_dir=cur_dir: os.path.join(cur_dir,x),\n ignored_files)\n #print 'ignored:', ignored_files\n #good_files = filter(lambda x,ignored = ignored_files: x not in ignored,\n # original)\n good_files = original\n for pattern in ignored_files:\n good_files = remove_ignored_patterns(good_files,pattern)\n\n return good_files\n\n__all__.append('harvest_modules')\ndef harvest_modules(package,ignore=None):\n \"\"\"* Retreive a list of all modules that live within a package.\n\n Only retreive files that are immediate children of the\n package -- do not recurse through child packages or\n directories. The returned list contains actual modules, not\n just their names.\n *\"\"\"\n d,f = os.path.split(package.__file__)\n\n # go through the directory and import every py file there.\n common_dir = os.path.join(d,'*.py')\n py_files = glob.glob(common_dir)\n #py_files.remove(os.path.join(d,'__init__.py'))\n #py_files.remove(os.path.join(d,'setup.py'))\n\n py_files = remove_ignored_files(py_files,ignore,d)\n #print 'py_files:', py_files\n try:\n prefix = package.__name__\n except:\n prefix = ''\n\n all_modules = []\n for file in py_files:\n d,f = os.path.split(file)\n base,ext = os.path.splitext(f)\n mod = prefix + '.' + base\n #print 'module: import ' + mod\n try:\n exec ('import ' + mod)\n all_modules.append(eval(mod))\n except:\n print 'FAILURE to import ' + mod\n output_exception()\n\n return all_modules\n\n__all__.append('harvest_packages')\ndef harvest_packages(package,ignore = None):\n \"\"\" Retreive a list of all sub-packages that live within a package.\n\n Only retreive packages that are immediate children of this\n package -- do not recurse through child packages or\n directories. The returned list contains actual package objects, not\n just their names.\n \"\"\"\n join = os.path.join\n\n d,f = os.path.split(package.__file__)\n\n common_dir = os.path.abspath(d)\n all_files = os.listdir(d)\n\n all_files = remove_ignored_files(all_files,ignore,'')\n #print 'all_files:', all_files\n try:\n prefix = package.__name__\n except:\n prefix = ''\n all_packages = []\n for directory in all_files:\n path = join(common_dir,directory)\n if os.path.isdir(path) and \\\n os.path.exists(join(path,'__init__.py')):\n sub_package = prefix + '.' + directory\n #print 'sub-package import ' + sub_package\n try:\n exec ('import ' + sub_package)\n all_packages.append(eval(sub_package))\n except:\n print 'FAILURE to import ' + sub_package\n output_exception()\n return all_packages\n\n__all__.append('harvest_modules_and_packages')\ndef harvest_modules_and_packages(package,ignore=None):\n \"\"\" Retreive list of all packages and modules that live within a package.\n\n See harvest_packages() and harvest_modules()\n \"\"\"\n all = harvest_modules(package,ignore) + harvest_packages(package,ignore)\n return all\n\n__all__.append('harvest_test_suites')\ndef harvest_test_suites(package,ignore = None,level=10):\n \"\"\"\n package -- the module to test. This is an actual module object\n (not a string)\n ignore -- a list of module names to omit from the tests\n level -- a value between 1 and 10. 1 will run the minimum number\n of tests. This is a fast \"smoke test\". Tests that take\n longer to run should have higher numbers ranging up to 10.\n \"\"\"\n suites=[]\n test_modules = harvest_modules_and_packages(package,ignore)\n #for i in test_modules:\n # print i.__name__\n for module in test_modules:\n if hasattr(module,'test_suite'):\n try:\n suite = module.test_suite(level=level)\n if suite:\n suites.append(suite)\n else:\n print \" !! FAILURE without error - shouldn't happen\",\n print module.__name__\n except:\n print ' !! FAILURE building test for ', module.__name__\n print ' ',\n output_exception()\n else:\n try:\n print 'No test suite found for ', module.__name__\n except AttributeError:\n # __version__.py getting replaced by a string throws a kink\n # in checking for modules, so we think is a module has\n # actually been overwritten\n print 'No test suite found for ', str(module)\n total_suite = unittest.TestSuite(suites)\n return total_suite\n\n__all__.append('module_test')\ndef module_test(mod_name,mod_file,level=10):\n \"\"\"*\n\n *\"\"\"\n #print 'testing', mod_name\n d,f = os.path.split(mod_file)\n\n # insert the tests directory to the python path\n test_dir = os.path.join(d,'tests')\n sys.path.insert(0,test_dir)\n\n # call the \"test_xxx.test()\" function for the appropriate\n # module.\n\n # This should deal with package naming issues correctly\n short_mod_name = string.split(mod_name,'.')[-1]\n test_module = 'test_' + short_mod_name\n test_string = 'import %s;reload(%s);%s.test(%d)' % \\\n ((test_module,)*3 + (level,))\n\n # This would be better cause it forces a reload of the orginal\n # module. It doesn't behave with packages however.\n #test_string = 'reload(%s);import %s;reload(%s);%s.test(%d)' % \\\n # ((mod_name,) + (test_module,)*3)\n exec(test_string)\n\n # remove test directory from python path.\n sys.path = sys.path[1:]\n\n__all__.append('module_test_suite')\ndef module_test_suite(mod_name,mod_file,level=10):\n #try:\n print ' creating test suite for:', mod_name\n d,f = os.path.split(mod_file)\n\n # insert the tests directory to the python path\n test_dir = os.path.join(d,'tests')\n sys.path.insert(0,test_dir)\n\n # call the \"test_xxx.test()\" function for the appropriate\n # module.\n\n # This should deal with package naming issues correctly\n short_mod_name = string.split(mod_name,'.')[-1]\n test_module = 'test_' + short_mod_name\n test_string = 'import %s;reload(%s);suite = %s.test_suite(%d)' % \\\n ((test_module,)*3+(level,))\n #print test_string\n exec(test_string)\n\n # remove test directory from python path.\n sys.path = sys.path[1:]\n return suite\n #except:\n # print ' !! FAILURE loading test suite from', test_module, ':'\n # print ' ',\n # output_exception()\n\n\n# Utility function to facilitate testing.\n\n__all__.append('assert_equal')\ndef assert_equal(actual,desired,err_msg='',verbose=1):\n \"\"\" Raise an assertion if two items are not\n equal. I think this should be part of unittest.py\n \"\"\"\n msg = '\\nItems are not equal:\\n' + err_msg\n try:\n if ( verbose and len(repr(desired)) < 100 and len(repr(actual)) ):\n msg = msg \\\n + 'DESIRED: ' + repr(desired) \\\n + '\\nACTUAL: ' + repr(actual)\n except:\n msg = msg \\\n + 'DESIRED: ' + repr(desired) \\\n + '\\nACTUAL: ' + repr(actual)\n assert desired == actual, msg\n\n__all__.append('assert_almost_equal')\ndef assert_almost_equal(actual,desired,decimal=7,err_msg='',verbose=1):\n \"\"\" Raise an assertion if two items are not\n equal. I think this should be part of unittest.py\n \"\"\"\n msg = '\\nItems are not equal:\\n' + err_msg\n try:\n if ( verbose and len(repr(desired)) < 100 and len(repr(actual)) ):\n msg = msg \\\n + 'DESIRED: ' + repr(desired) \\\n + '\\nACTUAL: ' + repr(actual)\n except:\n msg = msg \\\n + 'DESIRED: ' + repr(desired) \\\n + '\\nACTUAL: ' + repr(actual)\n assert round(abs(desired - actual),decimal) == 0, msg\n\n__all__.append('assert_approx_equal')\ndef assert_approx_equal(actual,desired,significant=7,err_msg='',verbose=1):\n \"\"\" Raise an assertion if two items are not\n equal. I think this should be part of unittest.py\n Approximately equal is defined as the number of significant digits\n correct\n \"\"\"\n msg = '\\nItems are not equal to %d significant digits:\\n' % significant\n msg += err_msg\n actual, desired = map(float, (actual, desired))\n # Normalized the numbers to be in range (-10.0,10.0)\n scale = pow(10,math.floor(math.log10(0.5*(abs(desired)+abs(actual)))))\n try:\n sc_desired = desired/scale\n except ZeroDivisionError:\n sc_desired = 0.0\n try:\n sc_actual = actual/scale\n except ZeroDivisionError:\n sc_actual = 0.0\n try:\n if ( verbose and len(repr(desired)) < 100 and len(repr(actual)) ):\n msg = msg \\\n + 'DESIRED: ' + repr(desired) \\\n + '\\nACTUAL: ' + repr(actual)\n except:\n msg = msg \\\n + 'DESIRED: ' + repr(desired) \\\n + '\\nACTUAL: ' + repr(actual)\n assert math.fabs(sc_desired - sc_actual) < pow(10.,-1*significant), msg\n\n\n__all__.append('assert_array_equal')\ndef assert_array_equal(x,y,err_msg=''):\n x,y = asarray(x), asarray(y)\n msg = '\\nArrays are not equal'\n try:\n assert 0 in [len(shape(x)),len(shape(y))] \\\n or (len(shape(x))==len(shape(y)) and \\\n alltrue(equal(shape(x),shape(y)))),\\\n msg + ' (shapes %s, %s mismatch):\\n\\t' \\\n % (shape(x),shape(y)) + err_msg\n reduced = ravel(equal(x,y))\n cond = alltrue(reduced)\n if not cond:\n s1 = array2string(x,precision=16)\n s2 = array2string(y,precision=16)\n if len(s1)>120: s1 = s1[:120] + '...'\n if len(s2)>120: s2 = s2[:120] + '...'\n match = 100-100.0*reduced.tolist().count(1)/len(reduced)\n msg = msg + ' (mismatch %s%%):\\n\\tArray 1: %s\\n\\tArray 2: %s' % (match,s1,s2)\n assert cond,\\\n msg + '\\n\\t' + err_msg\n except ValueError:\n raise ValueError, msg\n\n__all__.append('assert_array_almost_equal')\ndef assert_array_almost_equal(x,y,decimal=6,err_msg=''):\n x = asarray(x)\n y = asarray(y)\n msg = '\\nArrays are not almost equal'\n try:\n cond = alltrue(equal(shape(x),shape(y)))\n if not cond:\n msg = msg + ' (shapes mismatch):\\n\\t'\\\n 'Shape of array 1: %s\\n\\tShape of array 2: %s' % (shape(x),shape(y))\n assert cond, msg + '\\n\\t' + err_msg\n reduced = ravel(equal(less_equal(around(abs(x-y),decimal),10.0**(-decimal)),1))\n cond = alltrue(reduced)\n if not cond:\n s1 = array2string(x,precision=decimal+1)\n s2 = array2string(y,precision=decimal+1)\n if len(s1)>120: s1 = s1[:120] + '...'\n if len(s2)>120: s2 = s2[:120] + '...'\n match = 100-100.0*reduced.tolist().count(1)/len(reduced)\n msg = msg + ' (mismatch %s%%):\\n\\tArray 1: %s\\n\\tArray 2: %s' % (match,s1,s2)\n assert cond,\\\n msg + '\\n\\t' + err_msg\n except ValueError:\n print sys.exc_value\n print shape(x),shape(y)\n print x, y\n raise ValueError, 'arrays are not almost equal'\n\n__all__.append('assert_array_less')\ndef assert_array_less(x,y,err_msg=''):\n x,y = asarray(x), asarray(y)\n msg = '\\nArrays are not less-ordered'\n try:\n assert alltrue(equal(shape(x),shape(y))),\\\n msg + ' (shapes mismatch):\\n\\t' + err_msg\n reduced = ravel(less(x,y))\n cond = alltrue(reduced)\n if not cond:\n s1 = array2string(x,precision=16)\n s2 = array2string(y,precision=16)\n if len(s1)>120: s1 = s1[:120] + '...'\n if len(s2)>120: s2 = s2[:120] + '...'\n match = 100-100.0*reduced.tolist().count(1)/len(reduced)\n msg = msg + ' (mismatch %s%%):\\n\\tArray 1: %s\\n\\tArray 2: %s' % (match,s1,s2)\n assert cond,\\\n msg + '\\n\\t' + err_msg\n except ValueError:\n print shape(x),shape(y)\n raise ValueError, 'arrays are not less-ordered'\n\n__all__.append('rand')\ndef rand(*args):\n \"\"\" Returns an array of random numbers with the given shape.\n used for testing\n \"\"\"\n import random\n results = zeros(args,Float64)\n f = results.flat\n for i in range(len(f)):\n f[i] = random.random()\n return results\n\ndef output_exception():\n try:\n type, value, tb = sys.exc_info()\n info = traceback.extract_tb(tb)\n #this is more verbose\n #traceback.print_exc()\n filename, lineno, function, text = info[-1] # last line only\n print \"%s:%d: %s: %s (in %s)\" %\\\n (filename, lineno, type.__name__, str(value), function)\n finally:\n type = value = tb = None # clean up\n\ntry:\n import scipy_base.fastumath as math\nexcept ImportError,msg:\n print msg\n import math\n", "methods": [ { "name": "set_package_path", "long_name": "set_package_path( level = 1 )", "filename": "testing.py", "nloc": 15, "complexity": 4, "token_count": 146, "parameters": [ "level" ], "start_line": 49, "end_line": 80, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 32, "top_nesting_level": 0 }, { "name": "set_local_path", "long_name": "set_local_path( reldir = '' , level = 1 )", "filename": "testing.py", "nloc": 11, "complexity": 3, "token_count": 97, "parameters": [ "reldir", "level" ], "start_line": 83, "end_line": 99, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 17, "top_nesting_level": 0 }, { "name": "restore_path", "long_name": "restore_path( )", "filename": "testing.py", "nloc": 4, "complexity": 2, "token_count": 25, "parameters": [], "start_line": 102, "end_line": 105, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 4, "top_nesting_level": 0 }, { "name": "jiffies", "long_name": "jiffies( _proc_pid_stat = '/proc/%s/stat' % ( os . getpid ( )", "filename": "testing.py", "nloc": 2, "complexity": 1, "token_count": 23, "parameters": [ "_proc_pid_stat" ], "start_line": 109, "end_line": 110, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 2, "top_nesting_level": 1 }, { "name": "memusage", "long_name": "memusage( _proc_pid_stat = '/proc/%s/stat' % ( os . getpid ( )", "filename": "testing.py", "nloc": 10, "complexity": 2, "token_count": 54, "parameters": [ "_proc_pid_stat" ], "start_line": 121, "end_line": 130, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 10, "top_nesting_level": 1 }, { "name": "jiffies", "long_name": "jiffies( _load_time = time . time ( )", "filename": "testing.py", "nloc": 4, "complexity": 1, "token_count": 27, "parameters": [ "_load_time" ], "start_line": 135, "end_line": 138, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 4, "top_nesting_level": 1 }, { "name": "memusage", "long_name": "memusage( )", "filename": "testing.py", "nloc": 2, "complexity": 1, "token_count": 6, "parameters": [], "start_line": 140, "end_line": 142, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 3, "top_nesting_level": 1 }, { "name": "measure", "long_name": "measure( self , code_str , times = 1 )", "filename": "testing.py", "nloc": 13, "complexity": 2, "token_count": 82, "parameters": [ "self", "code_str", "times" ], "start_line": 147, "end_line": 162, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 16, "top_nesting_level": 1 }, { "name": "__call__", "long_name": "__call__( self , result = None )", "filename": "testing.py", "nloc": 19, "complexity": 5, "token_count": 175, "parameters": [ "self", "result" ], "start_line": 164, "end_line": 183, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 20, "top_nesting_level": 1 }, { "name": "__init__", "long_name": "__init__( self )", "filename": "testing.py", "nloc": 2, "complexity": 1, "token_count": 11, "parameters": [ "self" ], "start_line": 186, "end_line": 187, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 2, "top_nesting_level": 1 }, { "name": "write", "long_name": "write( self , message )", "filename": "testing.py", "nloc": 2, "complexity": 1, "token_count": 15, "parameters": [ "self", "message" ], "start_line": 188, "end_line": 189, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 2, "top_nesting_level": 1 }, { "name": "writeln", "long_name": "writeln( self , message )", "filename": "testing.py", "nloc": 2, "complexity": 1, "token_count": 17, "parameters": [ "self", "message" ], "start_line": 190, "end_line": 191, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 2, "top_nesting_level": 1 }, { "name": "_get_all_method_names", "long_name": "_get_all_method_names( cls )", "filename": "testing.py", "nloc": 8, "complexity": 5, "token_count": 56, "parameters": [ "cls" ], "start_line": 199, "end_line": 206, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 8, "top_nesting_level": 0 }, { "name": "__init__", "long_name": "__init__( self , package = '__main__' )", "filename": "testing.py", "nloc": 2, "complexity": 1, "token_count": 14, "parameters": [ "self", "package" ], "start_line": 230, "end_line": 231, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 2, "top_nesting_level": 1 }, { "name": "_module_str", "long_name": "_module_str( self , module )", "filename": "testing.py", "nloc": 5, "complexity": 2, "token_count": 43, "parameters": [ "self", "module" ], "start_line": 233, "end_line": 237, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 5, "top_nesting_level": 1 }, { "name": "_get_method_names", "long_name": "_get_method_names( self , clsobj , level )", "filename": "testing.py", "nloc": 22, "complexity": 11, "token_count": 142, "parameters": [ "self", "clsobj", "level" ], "start_line": 239, "end_line": 260, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 22, "top_nesting_level": 1 }, { "name": "_get_module_tests", "long_name": "_get_module_tests( self , module , level )", "filename": "testing.py", "nloc": 46, "complexity": 14, "token_count": 428, "parameters": [ "self", "module", "level" ], "start_line": 262, "end_line": 313, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 52, "top_nesting_level": 1 }, { "name": "_get_suite_list", "long_name": "_get_suite_list( self , test_module , level , module_name = '__main__' )", "filename": "testing.py", "nloc": 21, "complexity": 7, "token_count": 146, "parameters": [ "self", "test_module", "level", "module_name" ], "start_line": 315, "end_line": 336, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 22, "top_nesting_level": 1 }, { "name": "_touch_ppimported", "long_name": "_touch_ppimported( self , module )", "filename": "testing.py", "nloc": 11, "complexity": 7, "token_count": 98, "parameters": [ "self", "module" ], "start_line": 338, "end_line": 349, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 12, "top_nesting_level": 1 }, { "name": "test", "long_name": "test( self , level = 1 , verbosity = 1 )", "filename": "testing.py", "nloc": 19, "complexity": 6, "token_count": 166, "parameters": [ "self", "level", "verbosity" ], "start_line": 351, "end_line": 376, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 26, "top_nesting_level": 1 }, { "name": "run", "long_name": "run( self )", "filename": "testing.py", "nloc": 20, "complexity": 2, "token_count": 104, "parameters": [ "self" ], "start_line": 378, "end_line": 400, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 23, "top_nesting_level": 1 }, { "name": "remove_ignored_patterns", "long_name": "remove_ignored_patterns( files , pattern )", "filename": "testing.py", "nloc": 7, "complexity": 3, "token_count": 37, "parameters": [ "files", "pattern" ], "start_line": 404, "end_line": 410, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 7, "top_nesting_level": 0 }, { "name": "remove_ignored_files", "long_name": "remove_ignored_files( original , ignored_files , cur_dir )", "filename": "testing.py", "nloc": 12, "complexity": 3, "token_count": 93, "parameters": [ "original", "ignored_files", "cur_dir" ], "start_line": 412, "end_line": 431, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 20, "top_nesting_level": 0 }, { "name": "harvest_modules", "long_name": "harvest_modules( package , ignore = None )", "filename": "testing.py", "nloc": 21, "complexity": 4, "token_count": 134, "parameters": [ "package", "ignore" ], "start_line": 434, "end_line": 470, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 37, "top_nesting_level": 0 }, { "name": "harvest_packages", "long_name": "harvest_packages( package , ignore = None )", "filename": "testing.py", "nloc": 23, "complexity": 6, "token_count": 148, "parameters": [ "package", "ignore" ], "start_line": 473, "end_line": 507, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 35, "top_nesting_level": 0 }, { "name": "harvest_modules_and_packages", "long_name": "harvest_modules_and_packages( package , ignore = None )", "filename": "testing.py", "nloc": 3, "complexity": 1, "token_count": 27, "parameters": [ "package", "ignore" ], "start_line": 510, "end_line": 516, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 7, "top_nesting_level": 0 }, { "name": "harvest_test_suites", "long_name": "harvest_test_suites( package , ignore = None , level = 10 )", "filename": "testing.py", "nloc": 23, "complexity": 6, "token_count": 113, "parameters": [ "package", "ignore", "level" ], "start_line": 519, "end_line": 554, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 36, "top_nesting_level": 0 }, { "name": "module_test", "long_name": "module_test( mod_name , mod_file , level = 10 )", "filename": "testing.py", "nloc": 10, "complexity": 1, "token_count": 98, "parameters": [ "mod_name", "mod_file", "level" ], "start_line": 557, "end_line": 584, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 28, "top_nesting_level": 0 }, { "name": "module_test_suite", "long_name": "module_test_suite( mod_name , mod_file , level = 10 )", "filename": "testing.py", "nloc": 12, "complexity": 1, "token_count": 103, "parameters": [ "mod_name", "mod_file", "level" ], "start_line": 587, "end_line": 609, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 23, "top_nesting_level": 0 }, { "name": "assert_equal", "long_name": "assert_equal( actual , desired , err_msg = '' , verbose = 1 )", "filename": "testing.py", "nloc": 12, "complexity": 5, "token_count": 92, "parameters": [ "actual", "desired", "err_msg", "verbose" ], "start_line": 619, "end_line": 633, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 15, "top_nesting_level": 0 }, { "name": "assert_almost_equal", "long_name": "assert_almost_equal( actual , desired , decimal = 7 , err_msg = '' , verbose = 1 )", "filename": "testing.py", "nloc": 12, "complexity": 5, "token_count": 106, "parameters": [ "actual", "desired", "decimal", "err_msg", "verbose" ], "start_line": 636, "end_line": 650, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 15, "top_nesting_level": 0 }, { "name": "assert_approx_equal", "long_name": "assert_approx_equal( actual , desired , significant = 7 , err_msg = '' , verbose = 1 )", "filename": "testing.py", "nloc": 23, "complexity": 7, "token_count": 191, "parameters": [ "actual", "desired", "significant", "err_msg", "verbose" ], "start_line": 653, "end_line": 681, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 29, "top_nesting_level": 0 }, { "name": "assert_array_equal", "long_name": "assert_array_equal( x , y , err_msg = '' )", "filename": "testing.py", "nloc": 22, "complexity": 7, "token_count": 232, "parameters": [ "x", "y", "err_msg" ], "start_line": 685, "end_line": 706, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 22, "top_nesting_level": 0 }, { "name": "assert_array_almost_equal", "long_name": "assert_array_almost_equal( x , y , decimal = 6 , err_msg = '' )", "filename": "testing.py", "nloc": 26, "complexity": 6, "token_count": 251, "parameters": [ "x", "y", "decimal", "err_msg" ], "start_line": 709, "end_line": 734, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 26, "top_nesting_level": 0 }, { "name": "assert_array_less", "long_name": "assert_array_less( x , y , err_msg = '' )", "filename": "testing.py", "nloc": 20, "complexity": 5, "token_count": 189, "parameters": [ "x", "y", "err_msg" ], "start_line": 737, "end_line": 756, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 20, "top_nesting_level": 0 }, { "name": "rand", "long_name": "rand( * args )", "filename": "testing.py", "nloc": 7, "complexity": 2, "token_count": 45, "parameters": [ "args" ], "start_line": 759, "end_line": 768, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 10, "top_nesting_level": 0 }, { "name": "output_exception", "long_name": "output_exception( )", "filename": "testing.py", "nloc": 9, "complexity": 2, "token_count": 67, "parameters": [], "start_line": 770, "end_line": 780, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 11, "top_nesting_level": 0 } ], "methods_before": [ { "name": "set_package_path", "long_name": "set_package_path( level = 1 )", "filename": "testing.py", "nloc": 15, "complexity": 4, "token_count": 146, "parameters": [ "level" ], "start_line": 49, "end_line": 80, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 32, "top_nesting_level": 0 }, { "name": "set_local_path", "long_name": "set_local_path( reldir = '' , level = 1 )", "filename": "testing.py", "nloc": 11, "complexity": 3, "token_count": 97, "parameters": [ "reldir", "level" ], "start_line": 83, "end_line": 99, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 17, "top_nesting_level": 0 }, { "name": "restore_path", "long_name": "restore_path( )", "filename": "testing.py", "nloc": 4, "complexity": 2, "token_count": 25, "parameters": [], "start_line": 102, "end_line": 105, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 4, "top_nesting_level": 0 }, { "name": "jiffies", "long_name": "jiffies( _proc_pid_stat = '/proc/%s/stat' % ( os . getpid ( )", "filename": "testing.py", "nloc": 2, "complexity": 1, "token_count": 23, "parameters": [ "_proc_pid_stat" ], "start_line": 108, "end_line": 109, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 2, "top_nesting_level": 1 }, { "name": "memusage", "long_name": "memusage( _proc_pid_stat = '/proc/%s/stat' % ( os . getpid ( )", "filename": "testing.py", "nloc": 10, "complexity": 2, "token_count": 54, "parameters": [ "_proc_pid_stat" ], "start_line": 120, "end_line": 129, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 10, "top_nesting_level": 1 }, { "name": "jiffies", "long_name": "jiffies( _load_time = time . time ( )", "filename": "testing.py", "nloc": 4, "complexity": 1, "token_count": 27, "parameters": [ "_load_time" ], "start_line": 134, "end_line": 137, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 4, "top_nesting_level": 1 }, { "name": "memusage", "long_name": "memusage( )", "filename": "testing.py", "nloc": 2, "complexity": 1, "token_count": 6, "parameters": [], "start_line": 139, "end_line": 141, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 3, "top_nesting_level": 1 }, { "name": "measure", "long_name": "measure( self , code_str , times = 1 )", "filename": "testing.py", "nloc": 13, "complexity": 2, "token_count": 82, "parameters": [ "self", "code_str", "times" ], "start_line": 146, "end_line": 161, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 16, "top_nesting_level": 1 }, { "name": "__call__", "long_name": "__call__( self , result = None )", "filename": "testing.py", "nloc": 19, "complexity": 5, "token_count": 175, "parameters": [ "self", "result" ], "start_line": 163, "end_line": 182, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 20, "top_nesting_level": 1 }, { "name": "__init__", "long_name": "__init__( self )", "filename": "testing.py", "nloc": 2, "complexity": 1, "token_count": 11, "parameters": [ "self" ], "start_line": 185, "end_line": 186, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 2, "top_nesting_level": 1 }, { "name": "write", "long_name": "write( self , message )", "filename": "testing.py", "nloc": 2, "complexity": 1, "token_count": 15, "parameters": [ "self", "message" ], "start_line": 187, "end_line": 188, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 2, "top_nesting_level": 1 }, { "name": "writeln", "long_name": "writeln( self , message )", "filename": "testing.py", "nloc": 2, "complexity": 1, "token_count": 17, "parameters": [ "self", "message" ], "start_line": 189, "end_line": 190, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 2, "top_nesting_level": 1 }, { "name": "_get_all_method_names", "long_name": "_get_all_method_names( cls )", "filename": "testing.py", "nloc": 8, "complexity": 5, "token_count": 56, "parameters": [ "cls" ], "start_line": 198, "end_line": 205, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 8, "top_nesting_level": 0 }, { "name": "__init__", "long_name": "__init__( self , package = '__main__' )", "filename": "testing.py", "nloc": 2, "complexity": 1, "token_count": 14, "parameters": [ "self", "package" ], "start_line": 229, "end_line": 230, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 2, "top_nesting_level": 1 }, { "name": "_module_str", "long_name": "_module_str( self , module )", "filename": "testing.py", "nloc": 5, "complexity": 2, "token_count": 43, "parameters": [ "self", "module" ], "start_line": 232, "end_line": 236, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 5, "top_nesting_level": 1 }, { "name": "_get_method_names", "long_name": "_get_method_names( self , clsobj , level )", "filename": "testing.py", "nloc": 22, "complexity": 11, "token_count": 142, "parameters": [ "self", "clsobj", "level" ], "start_line": 238, "end_line": 259, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 22, "top_nesting_level": 1 }, { "name": "_get_module_tests", "long_name": "_get_module_tests( self , module , level )", "filename": "testing.py", "nloc": 46, "complexity": 14, "token_count": 428, "parameters": [ "self", "module", "level" ], "start_line": 261, "end_line": 312, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 52, "top_nesting_level": 1 }, { "name": "_get_suite_list", "long_name": "_get_suite_list( self , test_module , level , module_name = '__main__' )", "filename": "testing.py", "nloc": 21, "complexity": 7, "token_count": 146, "parameters": [ "self", "test_module", "level", "module_name" ], "start_line": 314, "end_line": 335, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 22, "top_nesting_level": 1 }, { "name": "_touch_ppimported", "long_name": "_touch_ppimported( self , module )", "filename": "testing.py", "nloc": 11, "complexity": 7, "token_count": 98, "parameters": [ "self", "module" ], "start_line": 337, "end_line": 348, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 12, "top_nesting_level": 1 }, { "name": "test", "long_name": "test( self , level = 1 , verbosity = 1 )", "filename": "testing.py", "nloc": 19, "complexity": 6, "token_count": 166, "parameters": [ "self", "level", "verbosity" ], "start_line": 350, "end_line": 375, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 26, "top_nesting_level": 1 }, { "name": "run", "long_name": "run( self )", "filename": "testing.py", "nloc": 20, "complexity": 2, "token_count": 104, "parameters": [ "self" ], "start_line": 377, "end_line": 399, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 23, "top_nesting_level": 1 }, { "name": "remove_ignored_patterns", "long_name": "remove_ignored_patterns( files , pattern )", "filename": "testing.py", "nloc": 7, "complexity": 3, "token_count": 37, "parameters": [ "files", "pattern" ], "start_line": 403, "end_line": 409, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 7, "top_nesting_level": 0 }, { "name": "remove_ignored_files", "long_name": "remove_ignored_files( original , ignored_files , cur_dir )", "filename": "testing.py", "nloc": 12, "complexity": 3, "token_count": 93, "parameters": [ "original", "ignored_files", "cur_dir" ], "start_line": 411, "end_line": 430, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 20, "top_nesting_level": 0 }, { "name": "harvest_modules", "long_name": "harvest_modules( package , ignore = None )", "filename": "testing.py", "nloc": 21, "complexity": 4, "token_count": 134, "parameters": [ "package", "ignore" ], "start_line": 433, "end_line": 469, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 37, "top_nesting_level": 0 }, { "name": "harvest_packages", "long_name": "harvest_packages( package , ignore = None )", "filename": "testing.py", "nloc": 23, "complexity": 6, "token_count": 148, "parameters": [ "package", "ignore" ], "start_line": 472, "end_line": 506, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 35, "top_nesting_level": 0 }, { "name": "harvest_modules_and_packages", "long_name": "harvest_modules_and_packages( package , ignore = None )", "filename": "testing.py", "nloc": 3, "complexity": 1, "token_count": 27, "parameters": [ "package", "ignore" ], "start_line": 509, "end_line": 515, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 7, "top_nesting_level": 0 }, { "name": "harvest_test_suites", "long_name": "harvest_test_suites( package , ignore = None , level = 10 )", "filename": "testing.py", "nloc": 23, "complexity": 6, "token_count": 113, "parameters": [ "package", "ignore", "level" ], "start_line": 518, "end_line": 553, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 36, "top_nesting_level": 0 }, { "name": "module_test", "long_name": "module_test( mod_name , mod_file , level = 10 )", "filename": "testing.py", "nloc": 10, "complexity": 1, "token_count": 98, "parameters": [ "mod_name", "mod_file", "level" ], "start_line": 556, "end_line": 583, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 28, "top_nesting_level": 0 }, { "name": "module_test_suite", "long_name": "module_test_suite( mod_name , mod_file , level = 10 )", "filename": "testing.py", "nloc": 12, "complexity": 1, "token_count": 103, "parameters": [ "mod_name", "mod_file", "level" ], "start_line": 586, "end_line": 608, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 23, "top_nesting_level": 0 }, { "name": "assert_equal", "long_name": "assert_equal( actual , desired , err_msg = '' , verbose = 1 )", "filename": "testing.py", "nloc": 12, "complexity": 5, "token_count": 92, "parameters": [ "actual", "desired", "err_msg", "verbose" ], "start_line": 618, "end_line": 632, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 15, "top_nesting_level": 0 }, { "name": "assert_almost_equal", "long_name": "assert_almost_equal( actual , desired , decimal = 7 , err_msg = '' , verbose = 1 )", "filename": "testing.py", "nloc": 12, "complexity": 5, "token_count": 106, "parameters": [ "actual", "desired", "decimal", "err_msg", "verbose" ], "start_line": 635, "end_line": 649, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 15, "top_nesting_level": 0 }, { "name": "assert_approx_equal", "long_name": "assert_approx_equal( actual , desired , significant = 7 , err_msg = '' , verbose = 1 )", "filename": "testing.py", "nloc": 23, "complexity": 7, "token_count": 191, "parameters": [ "actual", "desired", "significant", "err_msg", "verbose" ], "start_line": 652, "end_line": 680, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 29, "top_nesting_level": 0 }, { "name": "assert_array_equal", "long_name": "assert_array_equal( x , y , err_msg = '' )", "filename": "testing.py", "nloc": 22, "complexity": 7, "token_count": 232, "parameters": [ "x", "y", "err_msg" ], "start_line": 684, "end_line": 705, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 22, "top_nesting_level": 0 }, { "name": "assert_array_almost_equal", "long_name": "assert_array_almost_equal( x , y , decimal = 6 , err_msg = '' )", "filename": "testing.py", "nloc": 26, "complexity": 6, "token_count": 251, "parameters": [ "x", "y", "decimal", "err_msg" ], "start_line": 708, "end_line": 733, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 26, "top_nesting_level": 0 }, { "name": "assert_array_less", "long_name": "assert_array_less( x , y , err_msg = '' )", "filename": "testing.py", "nloc": 20, "complexity": 5, "token_count": 189, "parameters": [ "x", "y", "err_msg" ], "start_line": 736, "end_line": 755, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 20, "top_nesting_level": 0 }, { "name": "rand", "long_name": "rand( * args )", "filename": "testing.py", "nloc": 7, "complexity": 2, "token_count": 45, "parameters": [ "args" ], "start_line": 758, "end_line": 767, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 10, "top_nesting_level": 0 }, { "name": "output_exception", "long_name": "output_exception( )", "filename": "testing.py", "nloc": 9, "complexity": 2, "token_count": 67, "parameters": [], "start_line": 769, "end_line": 779, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 11, "top_nesting_level": 0 } ], "changed_methods": [], "nloc": 581, "complexity": 143, "token_count": 4127, "diff_parsed": { "added": [ " ScipyTest -- Scipy tests site manager", " ScipyTestCase -- unittest.TestCase with measure method", " set_package_path -- prepend package build directory to path", " set_local_path -- prepend local directory (to tests files) to path", " restore_path -- restore path after set_package_path", " jiffies -- return 1/100ths of a second that the current process has used", " memusage -- virtual memory size in bytes of the running python [linux]", " assert_equal --", " assert_almost_equal --", " assert_approx_equal --", " assert_array_equal --", " assert_array_almost_equal --", " assert_array_less --", " rand -- array of random numbers from given shape", "__all__.extend(['jiffies','memusage'])" ], "deleted": [ " ScipyTest - Scipy tests site manager", " ScipyTestCase - unittest.TestCase with measure method", " set_package_path - prepend package build directory to path", " set_local_path - prepend local directory (to tests files) to path", " restore_path - restore path after set_package_path", " jiffies - return 1/100ths of a second that the current process has used", " memusage - virtual memory size in bytes of the running python [linux]", " assert_equal", " assert_almost_equal", " assert_approx_equal", " assert_array_equal", " assert_array_almost_equal", " assert_array_less", " rand - array of random numbers from given shape" ] } } ] }, { "hash": "77c240ac4ddb6afb56caf729f85b07660d35fa1e", "msg": "Expose ppresolve.", "author": { "name": "Pearu Peterson", "email": "pearu.peterson@gmail.com" }, "committer": { "name": "Pearu Peterson", "email": "pearu.peterson@gmail.com" }, "author_date": "2004-11-27T15:55:23+00:00", "author_timezone": 0, "committer_date": "2004-11-27T15:55:23+00:00", "committer_timezone": 0, "branches": [ "main" ], "in_main_branch": true, "merge": false, "parents": [ "55d5de4c0bafe946e5030f0687a34ed5fac05277" ], "project_name": "repo_copy", "project_path": "/tmp/tmpqop781_j/repo_copy", "deletions": 1, "insertions": 2, "lines": 3, "files": 2, "dmm_unit_size": null, "dmm_unit_complexity": null, "dmm_unit_interfacing": null, "modified_files": [ { "old_path": "scipy_base/__init__.py", "new_path": "scipy_base/__init__.py", "filename": "__init__.py", "extension": "py", "change_type": "MODIFY", "diff": "@@ -2,7 +2,7 @@\n from info_scipy_base import __doc__\n from scipy_base_version import scipy_base_version as __version__\n \n-from ppimport import ppimport, ppimport_attr\n+from ppimport import ppimport, ppimport_attr, ppresolve\n \n # The following statement is equivalent to\n #\n", "added_lines": 1, "deleted_lines": 1, "source_code": "\nfrom info_scipy_base import __doc__\nfrom scipy_base_version import scipy_base_version as __version__\n\nfrom ppimport import ppimport, ppimport_attr, ppresolve\n\n# The following statement is equivalent to\n#\n# from Matrix import Matrix as mat\n#\n# but avoids expensive LinearAlgebra import when\n# Matrix is not used.\nmat = ppimport_attr(ppimport('Matrix'), 'Matrix')\n\n# Force Numeric to use scipy_base.fastumath instead of Numeric.umath.\nimport fastumath # no need to use scipy_base.fastumath\nimport sys as _sys\n_sys.modules['umath'] = fastumath\n\nimport Numeric\nfrom Numeric import *\n\nimport limits\nfrom type_check import *\nfrom index_tricks import *\nfrom function_base import *\nfrom shape_base import *\nfrom matrix_base import *\n\n\n\nfrom polynomial import *\nfrom scimath import *\nfrom machar import *\nfrom pexec import *\n\nif Numeric.__version__ < '23.5':\n matrixmultiply=dot\n\nInf = inf = fastumath.PINF\ntry:\n NAN = NaN = nan = fastumath.NAN\nexcept AttributeError:\n NaN = NAN = nan = fastumath.PINF/fastumath.PINF\n\nfrom scipy_test.testing import ScipyTest\ntest = ScipyTest('scipy_base').test\n\nif _sys.modules.has_key('scipy_base.Matrix') \\\n and _sys.modules['scipy_base.Matrix'] is None:\n del _sys.modules['scipy_base.Matrix']\n\n", "source_code_before": "\nfrom info_scipy_base import __doc__\nfrom scipy_base_version import scipy_base_version as __version__\n\nfrom ppimport import ppimport, ppimport_attr\n\n# The following statement is equivalent to\n#\n# from Matrix import Matrix as mat\n#\n# but avoids expensive LinearAlgebra import when\n# Matrix is not used.\nmat = ppimport_attr(ppimport('Matrix'), 'Matrix')\n\n# Force Numeric to use scipy_base.fastumath instead of Numeric.umath.\nimport fastumath # no need to use scipy_base.fastumath\nimport sys as _sys\n_sys.modules['umath'] = fastumath\n\nimport Numeric\nfrom Numeric import *\n\nimport limits\nfrom type_check import *\nfrom index_tricks import *\nfrom function_base import *\nfrom shape_base import *\nfrom matrix_base import *\n\n\n\nfrom polynomial import *\nfrom scimath import *\nfrom machar import *\nfrom pexec import *\n\nif Numeric.__version__ < '23.5':\n matrixmultiply=dot\n\nInf = inf = fastumath.PINF\ntry:\n NAN = NaN = nan = fastumath.NAN\nexcept AttributeError:\n NaN = NAN = nan = fastumath.PINF/fastumath.PINF\n\nfrom scipy_test.testing import ScipyTest\ntest = ScipyTest('scipy_base').test\n\nif _sys.modules.has_key('scipy_base.Matrix') \\\n and _sys.modules['scipy_base.Matrix'] is None:\n del _sys.modules['scipy_base.Matrix']\n\n", "methods": [], "methods_before": [], "changed_methods": [], "nloc": 31, "complexity": 0, "token_count": 172, "diff_parsed": { "added": [ "from ppimport import ppimport, ppimport_attr, ppresolve" ], "deleted": [ "from ppimport import ppimport, ppimport_attr" ] } }, { "old_path": "scipy_base/info_scipy_base.py", "new_path": "scipy_base/info_scipy_base.py", "filename": "info_scipy_base.py", "extension": "py", "change_type": "MODIFY", "diff": "@@ -111,6 +111,7 @@\n ppimport -- Postpone module import until trying to use it\n ppimport_attr -- Postpone module import until trying to use its\n attribute\n+ppresolve -- Import postponed module and return it.\n \n Machine arithmetics\n ===================\n", "added_lines": 1, "deleted_lines": 0, "source_code": "\"\"\" Basic functions used by several sub-packages and useful to have in the\nmain name-space\n\nType handling\n==============\niscomplexobj -- Test for complex object, scalar result\nisrealobj -- Test for real object, scalar result\niscomplex -- Test for complex elements, array result\nisreal -- Test for real elements, array result\nimag -- Imaginary part\nreal -- Real part\nreal_if_close -- Turns complex number with tiny imaginary part to real\nisneginf -- Tests for negative infinity ---|\nisposinf -- Tests for positive infinity |\nisnan -- Tests for nans |---- array results\nisinf -- Tests for infinity |\nisfinite -- Tests for finite numbers ---| \nisscalar -- True if argument is a scalar\nnan_to_num -- Replaces NaN's with 0 and infinities with large numbers\ntypename -- Return english name for given typecode character\ncast -- Dictionary of functions to force cast to each type\ncommon_type -- Determine the 'minimum common type code' for a group\n of arrays\nmintypecode -- Return minimal allowed common typecode.\n\nIndex tricks\n==================\nmgrid -- Method which allows easy construction of N-d 'mesh-grids'\nr_ -- Append and construct arrays: turns slice objects into\n ranges and concatenates them, for 2d arrays appends\n rows.\nc_ -- Append and construct arrays: for 2d arrays appends\n columns.\nrow -- Like r_ except ensure (row) Matrix return\ncol -- Like c_ except ensure (column) Matrix return\n\nindex_exp -- Konrad Hinsen's index_expression class instance which\n can be useful for building complicated slicing syntax.\n\nUseful functions\n==================\nselect -- Extension of where to multiple conditions and choices\nextract -- Extract 1d array from flattened array according to mask\ninsert -- Insert 1d array of values into Nd array according to mask\nlinspace -- Evenly spaced samples in linear space\nlogspace -- Evenly spaced samples in logarithmic space\nfix -- Round x to nearest integer towards zero\nmod -- Modulo mod(x,y) = x % y except keeps sign of y\namax -- Array maximum along axis\namin -- Array minimum along axis\nptp -- Array max-min along axis\ncumsum -- Cumulative sum along axis\nprod -- Product of elements along axis\ncumprod -- Cumluative product along axis\ndiff -- Discrete differences along axis\nangle -- Returns angle of complex argument\nunwrap -- Unwrap phase along given axis (1-d algorithm)\nsort_complex -- Sort a complex-array (based on real, then imaginary)\ntrim_zeros -- trim the leading and trailing zeros from 1D array.\n\nvectorize -- a class that wraps a Python function taking scalar\n arguments into a generalized function which\n can handle arrays of arguments using the broadcast\n rules of Numeric Python.\n\nalter_numeric -- enhance numeric array behavior\nrestore_numeric -- restore alterations done by alter_numeric\n\nShape manipulation\n===================\nsqueeze -- Return a with length-one dimensions removed.\natleast_1d -- Force arrays to be > 1D\natleast_2d -- Force arrays to be > 2D\natleast_3d -- Force arrays to be > 3D\nvstack -- Stack arrays vertically (row on row)\nhstack -- Stack arrays horizontally (column on column)\ncolumn_stack -- Stack 1D arrays as columns into 2D array\ndstack -- Stack arrays depthwise (along third dimension)\nsplit -- Divide array into a list of sub-arrays\nhsplit -- Split into columns\nvsplit -- Split into rows\ndsplit -- Split along third dimension\n\nMatrix (2d array) manipluations\n===============================\nfliplr -- 2D array with columns flipped\nflipud -- 2D array with rows flipped\nrot90 -- Rotate a 2D array a multiple of 90 degrees\neye -- Return a 2D array with ones down a given diagonal\ndiag -- Construct a 2D array from a vector, or return a given\n diagonal from a 2D array. \nmat -- Construct a Matrix\nbmat -- Build a Matrix from blocks\n\nPolynomials\n============\npoly1d -- A one-dimensional polynomial class\n\npoly -- Return polynomial coefficients from roots\nroots -- Find roots of polynomial given coefficients\npolyint -- Integrate polynomial\npolyder -- Differentiate polynomial\npolyadd -- Add polynomials\npolysub -- Substract polynomials\npolymul -- Multiply polynomials\npolydiv -- Divide polynomials\npolyval -- Evaluate polynomial at given argument\n\nImport tricks\n=============\nppimport -- Postpone module import until trying to use it\nppimport_attr -- Postpone module import until trying to use its\n attribute\nppresolve -- Import postponed module and return it.\n\nMachine arithmetics\n===================\nmachar_single -- MachAr instance storing the parameters of system\n single precision floating point arithmetics\nmachar_double -- MachAr instance storing the parameters of system\n double precision floating point arithmetics\n\nThreading tricks\n================\nParallelExec -- Execute commands in parallel thread.\n\"\"\"\n\nstandalone = 1\n", "source_code_before": "\"\"\" Basic functions used by several sub-packages and useful to have in the\nmain name-space\n\nType handling\n==============\niscomplexobj -- Test for complex object, scalar result\nisrealobj -- Test for real object, scalar result\niscomplex -- Test for complex elements, array result\nisreal -- Test for real elements, array result\nimag -- Imaginary part\nreal -- Real part\nreal_if_close -- Turns complex number with tiny imaginary part to real\nisneginf -- Tests for negative infinity ---|\nisposinf -- Tests for positive infinity |\nisnan -- Tests for nans |---- array results\nisinf -- Tests for infinity |\nisfinite -- Tests for finite numbers ---| \nisscalar -- True if argument is a scalar\nnan_to_num -- Replaces NaN's with 0 and infinities with large numbers\ntypename -- Return english name for given typecode character\ncast -- Dictionary of functions to force cast to each type\ncommon_type -- Determine the 'minimum common type code' for a group\n of arrays\nmintypecode -- Return minimal allowed common typecode.\n\nIndex tricks\n==================\nmgrid -- Method which allows easy construction of N-d 'mesh-grids'\nr_ -- Append and construct arrays: turns slice objects into\n ranges and concatenates them, for 2d arrays appends\n rows.\nc_ -- Append and construct arrays: for 2d arrays appends\n columns.\nrow -- Like r_ except ensure (row) Matrix return\ncol -- Like c_ except ensure (column) Matrix return\n\nindex_exp -- Konrad Hinsen's index_expression class instance which\n can be useful for building complicated slicing syntax.\n\nUseful functions\n==================\nselect -- Extension of where to multiple conditions and choices\nextract -- Extract 1d array from flattened array according to mask\ninsert -- Insert 1d array of values into Nd array according to mask\nlinspace -- Evenly spaced samples in linear space\nlogspace -- Evenly spaced samples in logarithmic space\nfix -- Round x to nearest integer towards zero\nmod -- Modulo mod(x,y) = x % y except keeps sign of y\namax -- Array maximum along axis\namin -- Array minimum along axis\nptp -- Array max-min along axis\ncumsum -- Cumulative sum along axis\nprod -- Product of elements along axis\ncumprod -- Cumluative product along axis\ndiff -- Discrete differences along axis\nangle -- Returns angle of complex argument\nunwrap -- Unwrap phase along given axis (1-d algorithm)\nsort_complex -- Sort a complex-array (based on real, then imaginary)\ntrim_zeros -- trim the leading and trailing zeros from 1D array.\n\nvectorize -- a class that wraps a Python function taking scalar\n arguments into a generalized function which\n can handle arrays of arguments using the broadcast\n rules of Numeric Python.\n\nalter_numeric -- enhance numeric array behavior\nrestore_numeric -- restore alterations done by alter_numeric\n\nShape manipulation\n===================\nsqueeze -- Return a with length-one dimensions removed.\natleast_1d -- Force arrays to be > 1D\natleast_2d -- Force arrays to be > 2D\natleast_3d -- Force arrays to be > 3D\nvstack -- Stack arrays vertically (row on row)\nhstack -- Stack arrays horizontally (column on column)\ncolumn_stack -- Stack 1D arrays as columns into 2D array\ndstack -- Stack arrays depthwise (along third dimension)\nsplit -- Divide array into a list of sub-arrays\nhsplit -- Split into columns\nvsplit -- Split into rows\ndsplit -- Split along third dimension\n\nMatrix (2d array) manipluations\n===============================\nfliplr -- 2D array with columns flipped\nflipud -- 2D array with rows flipped\nrot90 -- Rotate a 2D array a multiple of 90 degrees\neye -- Return a 2D array with ones down a given diagonal\ndiag -- Construct a 2D array from a vector, or return a given\n diagonal from a 2D array. \nmat -- Construct a Matrix\nbmat -- Build a Matrix from blocks\n\nPolynomials\n============\npoly1d -- A one-dimensional polynomial class\n\npoly -- Return polynomial coefficients from roots\nroots -- Find roots of polynomial given coefficients\npolyint -- Integrate polynomial\npolyder -- Differentiate polynomial\npolyadd -- Add polynomials\npolysub -- Substract polynomials\npolymul -- Multiply polynomials\npolydiv -- Divide polynomials\npolyval -- Evaluate polynomial at given argument\n\nImport tricks\n=============\nppimport -- Postpone module import until trying to use it\nppimport_attr -- Postpone module import until trying to use its\n attribute\n\nMachine arithmetics\n===================\nmachar_single -- MachAr instance storing the parameters of system\n single precision floating point arithmetics\nmachar_double -- MachAr instance storing the parameters of system\n double precision floating point arithmetics\n\nThreading tricks\n================\nParallelExec -- Execute commands in parallel thread.\n\"\"\"\n\nstandalone = 1\n", "methods": [], "methods_before": [], "changed_methods": [], "nloc": 127, "complexity": 0, "token_count": 4, "diff_parsed": { "added": [ "ppresolve -- Import postponed module and return it." ], "deleted": [] } } ] }, { "hash": "c1361c857a2f28db25e4af652e0fc6de3fd3ad76", "msg": "Fixed getfile wrapper and wrapped inspect.getsource.", "author": { "name": "Pearu Peterson", "email": "pearu.peterson@gmail.com" }, "committer": { "name": "Pearu Peterson", "email": "pearu.peterson@gmail.com" }, "author_date": "2004-11-27T21:23:27+00:00", "author_timezone": 0, "committer_date": "2004-11-27T21:23:27+00:00", "committer_timezone": 0, "branches": [ "main" ], "in_main_branch": true, "merge": false, "parents": [ "77c240ac4ddb6afb56caf729f85b07660d35fa1e" ], "project_name": "repo_copy", "project_path": "/tmp/tmpqop781_j/repo_copy", "deletions": 1, "insertions": 7, "lines": 8, "files": 1, "dmm_unit_size": 1.0, "dmm_unit_complexity": 1.0, "dmm_unit_interfacing": 1.0, "modified_files": [ { "old_path": "scipy_base/ppimport.py", "new_path": "scipy_base/ppimport.py", "filename": "ppimport.py", "extension": "py", "change_type": "MODIFY", "diff": "@@ -410,7 +410,7 @@ def _ppimport_pydoc_describe(object):\n def _ppimport_inspect_getfile(object):\n if isinstance(object,_ModuleLoader):\n return object.__dict__['__file__']\n- return _old_inspect_getfile(object)\n+ return _old_inspect_getfile(_ppresolve_ignore_failure(object))\n _ppimport_inspect_getfile.__doc__ = _old_inspect_getfile.__doc__\n _inspect.getfile = _ppimport_inspect_getfile\n \n@@ -420,6 +420,12 @@ def _ppimport_inspect_getdoc(object):\n _ppimport_inspect_getdoc.__doc__ = _old_inspect_getdoc.__doc__\n _inspect.getdoc = _ppimport_inspect_getdoc\n \n+_old_inspect_getsource = _inspect.getsource\n+def _ppimport_inspect_getsource(object):\n+ return _old_inspect_getsource(_ppresolve_ignore_failure(object))\n+_ppimport_inspect_getsource.__doc__ = _old_inspect_getsource.__doc__\n+_inspect.getsource = _ppimport_inspect_getsource\n+\n import __builtin__ as _builtin\n _old_builtin_dir = _builtin.dir\n def _ppimport_builtin_dir(*arg):\n", "added_lines": 7, "deleted_lines": 1, "source_code": "#!/usr/bin/env python\n\"\"\"\nPostpone module import to future.\n\nPython versions: 1.5.2 - 2.3.x\nAuthor: Pearu Peterson \nCreated: March 2003\n$Revision$\n$Date$\n\"\"\"\n__all__ = ['ppimport','ppimport_attr','ppresolve']\n\nimport os\nimport sys\nimport string\nimport types\nimport traceback\n\nDEBUG=0\n\n_ppimport_is_enabled = 1\ndef enable():\n \"\"\" Enable postponed importing.\"\"\"\n global _ppimport_is_enabled\n _ppimport_is_enabled = 1\n\ndef disable():\n \"\"\" Disable postponed importing.\"\"\"\n global _ppimport_is_enabled\n _ppimport_is_enabled = 0\n\nclass PPImportError(ImportError):\n pass\n\ndef _get_so_ext(_cache={}):\n so_ext = _cache.get('so_ext')\n if so_ext is None:\n if sys.platform[:5]=='linux':\n so_ext = '.so'\n else:\n try:\n # if possible, avoid expensive get_config_vars call\n from distutils.sysconfig import get_config_vars\n so_ext = get_config_vars('SO')[0] or ''\n except ImportError:\n #XXX: implement hooks for .sl, .dll to fully support\n # Python 1.5.x \n so_ext = '.so'\n _cache['so_ext'] = so_ext\n return so_ext\n\ndef _get_frame(level=0):\n try:\n return sys._getframe(level+1)\n except AttributeError:\n # Python<=2.0 support\n frame = sys.exc_info()[2].tb_frame\n for i in range(level+1):\n frame = frame.f_back\n return frame\n\ndef ppimport_attr(module, name):\n \"\"\" ppimport(module, name) is 'postponed' getattr(module, name)\n \"\"\"\n global _ppimport_is_enabled\n if _ppimport_is_enabled and isinstance(module, _ModuleLoader):\n return _AttrLoader(module, name)\n return getattr(module, name)\n\nclass _AttrLoader:\n def __init__(self, module, name):\n self.__dict__['_ppimport_attr_module'] = module\n self.__dict__['_ppimport_attr_name'] = name\n\n def _ppimport_attr_getter(self):\n module = self.__dict__['_ppimport_attr_module']\n if isinstance(module, _ModuleLoader):\n # in case pp module was loaded by other means\n module = sys.modules[module.__name__]\n attr = getattr(module,\n self.__dict__['_ppimport_attr_name'])\n try:\n d = attr.__dict__\n if d is not None:\n self.__dict__ = d\n except AttributeError:\n pass\n self.__dict__['_ppimport_attr'] = attr\n\n return attr\n\n def __nonzero__(self):\n return 1\n\n def __getattr__(self, name):\n try:\n attr = self.__dict__['_ppimport_attr']\n except KeyError:\n attr = self._ppimport_attr_getter()\n if name=='_ppimport_attr':\n return attr\n return getattr(attr, name)\n\n def __repr__(self):\n if self.__dict__.has_key('_ppimport_attr'):\n return repr(self._ppimport_attr)\n module = self.__dict__['_ppimport_attr_module']\n name = self.__dict__['_ppimport_attr_name']\n return \"\" % (`name`,`module`)\n\n __str__ = __repr__\n\n # For function and class attributes.\n def __call__(self, *args, **kwds):\n return self._ppimport_attr(*args,**kwds)\n\n\n\ndef _is_local_module(p_dir,name,suffices):\n base = os.path.join(p_dir,name)\n for suffix in suffices:\n if os.path.isfile(base+suffix):\n if p_dir:\n return base+suffix\n return name+suffix\n\ndef ppimport(name):\n \"\"\" ppimport(name) -> module or module wrapper\n\n If name has been imported before, return module. Otherwise\n return ModuleLoader instance that transparently postpones\n module import until the first attempt to access module name\n attributes.\n \"\"\"\n global _ppimport_is_enabled\n\n level = 1\n parent_frame = p_frame = _get_frame(level)\n while not p_frame.f_locals.has_key('__name__'):\n level = level + 1\n p_frame = _get_frame(level)\n\n p_name = p_frame.f_locals['__name__']\n if p_name=='__main__':\n p_dir = ''\n fullname = name\n elif p_frame.f_locals.has_key('__path__'):\n # python package\n p_path = p_frame.f_locals['__path__']\n p_dir = p_path[0]\n fullname = p_name + '.' + name\n else:\n # python module\n p_file = p_frame.f_locals['__file__']\n p_dir = os.path.dirname(p_file)\n fullname = p_name + '.' + name\n\n # module may be imported already\n module = sys.modules.get(fullname)\n if module is not None:\n if _ppimport_is_enabled or isinstance(module, types.ModuleType):\n return module\n return module._ppimport_importer()\n\n so_ext = _get_so_ext()\n py_exts = ('.py','.pyc','.pyo')\n so_exts = (so_ext,'module'+so_ext)\n\n for d,n,fn,e in [\\\n # name is local python module or local extension module\n (p_dir, name, fullname, py_exts+so_exts),\n # name is local package\n (os.path.join(p_dir, name), '__init__', fullname, py_exts),\n # name is package in parent directory (scipy specific)\n (os.path.join(os.path.dirname(p_dir), name), '__init__', name, py_exts),\n ]:\n location = _is_local_module(d, n, e)\n if location is not None:\n fullname = fn\n break\n\n if location is None:\n # name is to be looked in python sys.path.\n fullname = name\n location = 'sys.path'\n\n # Try once more if module is imported.\n # This covers the case when importing from python module\n module = sys.modules.get(fullname)\n\n if module is not None:\n if _ppimport_is_enabled or isinstance(module,types.ModuleType):\n return module\n return module._ppimport_importer()\n # It is OK if name does not exists. The ImportError is\n # postponed until trying to use the module.\n\n loader = _ModuleLoader(fullname,location,p_frame=parent_frame)\n if _ppimport_is_enabled:\n return loader\n\n return loader._ppimport_importer()\n\ndef _get_frame_code(frame):\n filename = frame.f_code.co_filename\n lineno = frame.f_lineno\n result = '%s in %s:\\n' % (filename,frame.f_code.co_name)\n if not os.path.isfile(filename):\n return result\n f = open(filename)\n i = 1\n line = f.readline()\n while line:\n line = f.readline()\n i = i + 1\n if (abs(i-lineno)<2):\n result += '#%d: %s\\n' % (i,line.rstrip())\n if i>lineno+3:\n break\n f.close()\n return result\n\ndef frame_traceback(frame):\n if not frame:\n return\n blocks = []\n f = frame\n while f:\n blocks.insert(0,_get_frame_code(f))\n f = f.f_back\n print '='*50\n print '\\n'.join(blocks)\n print '='*50 \n\nclass _ModuleLoader:\n # Don't use it directly. Use ppimport instead.\n\n def __init__(self,name,location,p_frame=None):\n\n # set attributes, avoid calling __setattr__\n self.__dict__['__name__'] = name\n self.__dict__['__file__'] = location\n self.__dict__['_ppimport_p_frame'] = p_frame\n\n if location != 'sys.path':\n from scipy_test.testing import ScipyTest\n self.__dict__['test'] = ScipyTest(self).test\n\n # install loader\n sys.modules[name] = self\n\n def _ppimport_importer(self):\n name = self.__name__\n\n try:\n module = sys.modules[name]\n\texcept KeyError:\n raise ImportError,self.__dict__.get('_ppimport_exc_info')[1]\n if module is not self:\n exc_info = self.__dict__.get('_ppimport_exc_info')\n if exc_info is not None:\n raise PPImportError,\\\n ''.join(traceback.format_exception(*exc_info))\n else:\n assert module is self,`(module, self)`\n\n # uninstall loader\n del sys.modules[name]\n\n if DEBUG:\n print 'Executing postponed import for %s' %(name)\n try:\n module = __import__(name,None,None,['*'])\n except Exception,msg: # ImportError:\n if DEBUG:\n p_frame = self.__dict__.get('_ppimport_p_frame',None)\n frame_traceback(p_frame)\n self.__dict__['_ppimport_exc_info'] = sys.exc_info()\n raise\n\n assert isinstance(module,types.ModuleType),`module`\n\n self.__dict__ = module.__dict__\n self.__dict__['_ppimport_module'] = module\n\n # XXX: Should we check the existence of module.test? Warn?\n from scipy_test.testing import ScipyTest\n module.test = ScipyTest(module).test\n\n return module\n\n def __setattr__(self, name, value):\n try:\n module = self.__dict__['_ppimport_module']\n except KeyError:\n module = self._ppimport_importer()\n return setattr(module, name, value)\n\n def __getattr__(self, name):\n try:\n module = self.__dict__['_ppimport_module']\n except KeyError:\n module = self._ppimport_importer()\n return getattr(module, name)\n\n def __repr__(self):\n global _ppimport_is_enabled\n if not _ppimport_is_enabled:\n try:\n module = self.__dict__['_ppimport_module']\n except KeyError:\n module = self._ppimport_importer()\n return module.__repr__()\n if self.__dict__.has_key('_ppimport_module'):\n status = 'imported'\n elif self.__dict__.has_key('_ppimport_exc_info'):\n status = 'import error'\n else:\n status = 'import postponed'\n return '' \\\n % (`self.__name__`,`self.__file__`, status)\n\n __str__ = __repr__\n\ndef ppresolve(a,ignore_failure=None):\n \"\"\" Return resolved object a.\n\n a can be module name, postponed module, postponed modules\n attribute, string representing module attribute, or any\n Python object.\n \"\"\"\n global _ppimport_is_enabled\n if _ppimport_is_enabled:\n disable()\n a = ppresolve(a,ignore_failure=ignore_failure)\n enable()\n return a\n if type(a) is type(''):\n ns = a.split('.')\n if ignore_failure:\n try:\n a = ppimport(ns[0])\n except:\n return a\n else:\n a = ppimport(ns[0])\n b = [ns[0]]\n del ns[0]\n while ns:\n if hasattr(a,'_ppimport_importer') or \\\n hasattr(a,'_ppimport_module'):\n a = getattr(a,'_ppimport_module',a)\n if hasattr(a,'_ppimport_attr'):\n a = a._ppimport_attr\n b.append(ns[0])\n del ns[0]\n if ignore_failure and not hasattr(a, b[-1]):\n a = '.'.join(ns+b)\n b = '.'.join(b)\n if sys.modules.has_key(b) and sys.modules[b] is None:\n del sys.modules[b]\n return a\n a = getattr(a,b[-1])\n if hasattr(a,'_ppimport_importer') or \\\n hasattr(a,'_ppimport_module'):\n a = getattr(a,'_ppimport_module',a)\n if hasattr(a,'_ppimport_attr'):\n a = a._ppimport_attr\n return a\n\ndef _ppresolve_ignore_failure(a):\n return ppresolve(a,ignore_failure=1)\n\ntry:\n import pydoc as _pydoc\nexcept ImportError:\n _pydoc = None\n\nif _pydoc is not None:\n # Redefine __call__ method of help.__class__ to\n # support ppimport.\n import new as _new\n\n _old_pydoc_help_call = _pydoc.help.__class__.__call__\n def _ppimport_pydoc_help_call(self,*args,**kwds):\n return _old_pydoc_help_call(self, *map(_ppresolve_ignore_failure,args),\n **kwds)\n _ppimport_pydoc_help_call.__doc__ = _old_pydoc_help_call.__doc__\n _pydoc.help.__class__.__call__ = _new.instancemethod(_ppimport_pydoc_help_call,\n None,\n _pydoc.help.__class__)\n\n _old_pydoc_Doc_document = _pydoc.Doc.document\n def _ppimport_pydoc_Doc_document(self,*args,**kwds):\n args = (_ppresolve_ignore_failure(args[0]),) + args[1:]\n return _old_pydoc_Doc_document(self,*args,**kwds)\n _ppimport_pydoc_Doc_document.__doc__ = _old_pydoc_Doc_document.__doc__\n _pydoc.Doc.document = _new.instancemethod(_ppimport_pydoc_Doc_document,\n None,\n _pydoc.Doc)\n\n _old_pydoc_describe = _pydoc.describe\n def _ppimport_pydoc_describe(object):\n return _old_pydoc_describe(_ppresolve_ignore_failure(object))\n _ppimport_pydoc_describe.__doc__ = _old_pydoc_describe.__doc__\n _pydoc.describe = _ppimport_pydoc_describe\n\nimport inspect as _inspect\n_old_inspect_getfile = _inspect.getfile\ndef _ppimport_inspect_getfile(object):\n if isinstance(object,_ModuleLoader):\n return object.__dict__['__file__']\n return _old_inspect_getfile(_ppresolve_ignore_failure(object))\n_ppimport_inspect_getfile.__doc__ = _old_inspect_getfile.__doc__\n_inspect.getfile = _ppimport_inspect_getfile\n\n_old_inspect_getdoc = _inspect.getdoc\ndef _ppimport_inspect_getdoc(object):\n return _old_inspect_getdoc(_ppresolve_ignore_failure(object))\n_ppimport_inspect_getdoc.__doc__ = _old_inspect_getdoc.__doc__\n_inspect.getdoc = _ppimport_inspect_getdoc\n\n_old_inspect_getsource = _inspect.getsource\ndef _ppimport_inspect_getsource(object):\n return _old_inspect_getsource(_ppresolve_ignore_failure(object))\n_ppimport_inspect_getsource.__doc__ = _old_inspect_getsource.__doc__\n_inspect.getsource = _ppimport_inspect_getsource\n\nimport __builtin__ as _builtin\n_old_builtin_dir = _builtin.dir\ndef _ppimport_builtin_dir(*arg):\n if not arg:\n p_frame = _get_frame(1)\n g = p_frame.f_globals\n l = p_frame.f_locals\n l['_ppimport_old_builtin_dir'] = _old_builtin_dir\n r = eval('_ppimport_old_builtin_dir()',g,l)\n del r[r.index('_ppimport_old_builtin_dir')]\n return r\n return _old_builtin_dir(*map(_ppresolve_ignore_failure,arg))\n_ppimport_builtin_dir.__doc__ = _old_builtin_dir.__doc__\n_builtin.dir = _ppimport_builtin_dir\n", "source_code_before": "#!/usr/bin/env python\n\"\"\"\nPostpone module import to future.\n\nPython versions: 1.5.2 - 2.3.x\nAuthor: Pearu Peterson \nCreated: March 2003\n$Revision$\n$Date$\n\"\"\"\n__all__ = ['ppimport','ppimport_attr','ppresolve']\n\nimport os\nimport sys\nimport string\nimport types\nimport traceback\n\nDEBUG=0\n\n_ppimport_is_enabled = 1\ndef enable():\n \"\"\" Enable postponed importing.\"\"\"\n global _ppimport_is_enabled\n _ppimport_is_enabled = 1\n\ndef disable():\n \"\"\" Disable postponed importing.\"\"\"\n global _ppimport_is_enabled\n _ppimport_is_enabled = 0\n\nclass PPImportError(ImportError):\n pass\n\ndef _get_so_ext(_cache={}):\n so_ext = _cache.get('so_ext')\n if so_ext is None:\n if sys.platform[:5]=='linux':\n so_ext = '.so'\n else:\n try:\n # if possible, avoid expensive get_config_vars call\n from distutils.sysconfig import get_config_vars\n so_ext = get_config_vars('SO')[0] or ''\n except ImportError:\n #XXX: implement hooks for .sl, .dll to fully support\n # Python 1.5.x \n so_ext = '.so'\n _cache['so_ext'] = so_ext\n return so_ext\n\ndef _get_frame(level=0):\n try:\n return sys._getframe(level+1)\n except AttributeError:\n # Python<=2.0 support\n frame = sys.exc_info()[2].tb_frame\n for i in range(level+1):\n frame = frame.f_back\n return frame\n\ndef ppimport_attr(module, name):\n \"\"\" ppimport(module, name) is 'postponed' getattr(module, name)\n \"\"\"\n global _ppimport_is_enabled\n if _ppimport_is_enabled and isinstance(module, _ModuleLoader):\n return _AttrLoader(module, name)\n return getattr(module, name)\n\nclass _AttrLoader:\n def __init__(self, module, name):\n self.__dict__['_ppimport_attr_module'] = module\n self.__dict__['_ppimport_attr_name'] = name\n\n def _ppimport_attr_getter(self):\n module = self.__dict__['_ppimport_attr_module']\n if isinstance(module, _ModuleLoader):\n # in case pp module was loaded by other means\n module = sys.modules[module.__name__]\n attr = getattr(module,\n self.__dict__['_ppimport_attr_name'])\n try:\n d = attr.__dict__\n if d is not None:\n self.__dict__ = d\n except AttributeError:\n pass\n self.__dict__['_ppimport_attr'] = attr\n\n return attr\n\n def __nonzero__(self):\n return 1\n\n def __getattr__(self, name):\n try:\n attr = self.__dict__['_ppimport_attr']\n except KeyError:\n attr = self._ppimport_attr_getter()\n if name=='_ppimport_attr':\n return attr\n return getattr(attr, name)\n\n def __repr__(self):\n if self.__dict__.has_key('_ppimport_attr'):\n return repr(self._ppimport_attr)\n module = self.__dict__['_ppimport_attr_module']\n name = self.__dict__['_ppimport_attr_name']\n return \"\" % (`name`,`module`)\n\n __str__ = __repr__\n\n # For function and class attributes.\n def __call__(self, *args, **kwds):\n return self._ppimport_attr(*args,**kwds)\n\n\n\ndef _is_local_module(p_dir,name,suffices):\n base = os.path.join(p_dir,name)\n for suffix in suffices:\n if os.path.isfile(base+suffix):\n if p_dir:\n return base+suffix\n return name+suffix\n\ndef ppimport(name):\n \"\"\" ppimport(name) -> module or module wrapper\n\n If name has been imported before, return module. Otherwise\n return ModuleLoader instance that transparently postpones\n module import until the first attempt to access module name\n attributes.\n \"\"\"\n global _ppimport_is_enabled\n\n level = 1\n parent_frame = p_frame = _get_frame(level)\n while not p_frame.f_locals.has_key('__name__'):\n level = level + 1\n p_frame = _get_frame(level)\n\n p_name = p_frame.f_locals['__name__']\n if p_name=='__main__':\n p_dir = ''\n fullname = name\n elif p_frame.f_locals.has_key('__path__'):\n # python package\n p_path = p_frame.f_locals['__path__']\n p_dir = p_path[0]\n fullname = p_name + '.' + name\n else:\n # python module\n p_file = p_frame.f_locals['__file__']\n p_dir = os.path.dirname(p_file)\n fullname = p_name + '.' + name\n\n # module may be imported already\n module = sys.modules.get(fullname)\n if module is not None:\n if _ppimport_is_enabled or isinstance(module, types.ModuleType):\n return module\n return module._ppimport_importer()\n\n so_ext = _get_so_ext()\n py_exts = ('.py','.pyc','.pyo')\n so_exts = (so_ext,'module'+so_ext)\n\n for d,n,fn,e in [\\\n # name is local python module or local extension module\n (p_dir, name, fullname, py_exts+so_exts),\n # name is local package\n (os.path.join(p_dir, name), '__init__', fullname, py_exts),\n # name is package in parent directory (scipy specific)\n (os.path.join(os.path.dirname(p_dir), name), '__init__', name, py_exts),\n ]:\n location = _is_local_module(d, n, e)\n if location is not None:\n fullname = fn\n break\n\n if location is None:\n # name is to be looked in python sys.path.\n fullname = name\n location = 'sys.path'\n\n # Try once more if module is imported.\n # This covers the case when importing from python module\n module = sys.modules.get(fullname)\n\n if module is not None:\n if _ppimport_is_enabled or isinstance(module,types.ModuleType):\n return module\n return module._ppimport_importer()\n # It is OK if name does not exists. The ImportError is\n # postponed until trying to use the module.\n\n loader = _ModuleLoader(fullname,location,p_frame=parent_frame)\n if _ppimport_is_enabled:\n return loader\n\n return loader._ppimport_importer()\n\ndef _get_frame_code(frame):\n filename = frame.f_code.co_filename\n lineno = frame.f_lineno\n result = '%s in %s:\\n' % (filename,frame.f_code.co_name)\n if not os.path.isfile(filename):\n return result\n f = open(filename)\n i = 1\n line = f.readline()\n while line:\n line = f.readline()\n i = i + 1\n if (abs(i-lineno)<2):\n result += '#%d: %s\\n' % (i,line.rstrip())\n if i>lineno+3:\n break\n f.close()\n return result\n\ndef frame_traceback(frame):\n if not frame:\n return\n blocks = []\n f = frame\n while f:\n blocks.insert(0,_get_frame_code(f))\n f = f.f_back\n print '='*50\n print '\\n'.join(blocks)\n print '='*50 \n\nclass _ModuleLoader:\n # Don't use it directly. Use ppimport instead.\n\n def __init__(self,name,location,p_frame=None):\n\n # set attributes, avoid calling __setattr__\n self.__dict__['__name__'] = name\n self.__dict__['__file__'] = location\n self.__dict__['_ppimport_p_frame'] = p_frame\n\n if location != 'sys.path':\n from scipy_test.testing import ScipyTest\n self.__dict__['test'] = ScipyTest(self).test\n\n # install loader\n sys.modules[name] = self\n\n def _ppimport_importer(self):\n name = self.__name__\n\n try:\n module = sys.modules[name]\n\texcept KeyError:\n raise ImportError,self.__dict__.get('_ppimport_exc_info')[1]\n if module is not self:\n exc_info = self.__dict__.get('_ppimport_exc_info')\n if exc_info is not None:\n raise PPImportError,\\\n ''.join(traceback.format_exception(*exc_info))\n else:\n assert module is self,`(module, self)`\n\n # uninstall loader\n del sys.modules[name]\n\n if DEBUG:\n print 'Executing postponed import for %s' %(name)\n try:\n module = __import__(name,None,None,['*'])\n except Exception,msg: # ImportError:\n if DEBUG:\n p_frame = self.__dict__.get('_ppimport_p_frame',None)\n frame_traceback(p_frame)\n self.__dict__['_ppimport_exc_info'] = sys.exc_info()\n raise\n\n assert isinstance(module,types.ModuleType),`module`\n\n self.__dict__ = module.__dict__\n self.__dict__['_ppimport_module'] = module\n\n # XXX: Should we check the existence of module.test? Warn?\n from scipy_test.testing import ScipyTest\n module.test = ScipyTest(module).test\n\n return module\n\n def __setattr__(self, name, value):\n try:\n module = self.__dict__['_ppimport_module']\n except KeyError:\n module = self._ppimport_importer()\n return setattr(module, name, value)\n\n def __getattr__(self, name):\n try:\n module = self.__dict__['_ppimport_module']\n except KeyError:\n module = self._ppimport_importer()\n return getattr(module, name)\n\n def __repr__(self):\n global _ppimport_is_enabled\n if not _ppimport_is_enabled:\n try:\n module = self.__dict__['_ppimport_module']\n except KeyError:\n module = self._ppimport_importer()\n return module.__repr__()\n if self.__dict__.has_key('_ppimport_module'):\n status = 'imported'\n elif self.__dict__.has_key('_ppimport_exc_info'):\n status = 'import error'\n else:\n status = 'import postponed'\n return '' \\\n % (`self.__name__`,`self.__file__`, status)\n\n __str__ = __repr__\n\ndef ppresolve(a,ignore_failure=None):\n \"\"\" Return resolved object a.\n\n a can be module name, postponed module, postponed modules\n attribute, string representing module attribute, or any\n Python object.\n \"\"\"\n global _ppimport_is_enabled\n if _ppimport_is_enabled:\n disable()\n a = ppresolve(a,ignore_failure=ignore_failure)\n enable()\n return a\n if type(a) is type(''):\n ns = a.split('.')\n if ignore_failure:\n try:\n a = ppimport(ns[0])\n except:\n return a\n else:\n a = ppimport(ns[0])\n b = [ns[0]]\n del ns[0]\n while ns:\n if hasattr(a,'_ppimport_importer') or \\\n hasattr(a,'_ppimport_module'):\n a = getattr(a,'_ppimport_module',a)\n if hasattr(a,'_ppimport_attr'):\n a = a._ppimport_attr\n b.append(ns[0])\n del ns[0]\n if ignore_failure and not hasattr(a, b[-1]):\n a = '.'.join(ns+b)\n b = '.'.join(b)\n if sys.modules.has_key(b) and sys.modules[b] is None:\n del sys.modules[b]\n return a\n a = getattr(a,b[-1])\n if hasattr(a,'_ppimport_importer') or \\\n hasattr(a,'_ppimport_module'):\n a = getattr(a,'_ppimport_module',a)\n if hasattr(a,'_ppimport_attr'):\n a = a._ppimport_attr\n return a\n\ndef _ppresolve_ignore_failure(a):\n return ppresolve(a,ignore_failure=1)\n\ntry:\n import pydoc as _pydoc\nexcept ImportError:\n _pydoc = None\n\nif _pydoc is not None:\n # Redefine __call__ method of help.__class__ to\n # support ppimport.\n import new as _new\n\n _old_pydoc_help_call = _pydoc.help.__class__.__call__\n def _ppimport_pydoc_help_call(self,*args,**kwds):\n return _old_pydoc_help_call(self, *map(_ppresolve_ignore_failure,args),\n **kwds)\n _ppimport_pydoc_help_call.__doc__ = _old_pydoc_help_call.__doc__\n _pydoc.help.__class__.__call__ = _new.instancemethod(_ppimport_pydoc_help_call,\n None,\n _pydoc.help.__class__)\n\n _old_pydoc_Doc_document = _pydoc.Doc.document\n def _ppimport_pydoc_Doc_document(self,*args,**kwds):\n args = (_ppresolve_ignore_failure(args[0]),) + args[1:]\n return _old_pydoc_Doc_document(self,*args,**kwds)\n _ppimport_pydoc_Doc_document.__doc__ = _old_pydoc_Doc_document.__doc__\n _pydoc.Doc.document = _new.instancemethod(_ppimport_pydoc_Doc_document,\n None,\n _pydoc.Doc)\n\n _old_pydoc_describe = _pydoc.describe\n def _ppimport_pydoc_describe(object):\n return _old_pydoc_describe(_ppresolve_ignore_failure(object))\n _ppimport_pydoc_describe.__doc__ = _old_pydoc_describe.__doc__\n _pydoc.describe = _ppimport_pydoc_describe\n\nimport inspect as _inspect\n_old_inspect_getfile = _inspect.getfile\ndef _ppimport_inspect_getfile(object):\n if isinstance(object,_ModuleLoader):\n return object.__dict__['__file__']\n return _old_inspect_getfile(object)\n_ppimport_inspect_getfile.__doc__ = _old_inspect_getfile.__doc__\n_inspect.getfile = _ppimport_inspect_getfile\n\n_old_inspect_getdoc = _inspect.getdoc\ndef _ppimport_inspect_getdoc(object):\n return _old_inspect_getdoc(_ppresolve_ignore_failure(object))\n_ppimport_inspect_getdoc.__doc__ = _old_inspect_getdoc.__doc__\n_inspect.getdoc = _ppimport_inspect_getdoc\n\nimport __builtin__ as _builtin\n_old_builtin_dir = _builtin.dir\ndef _ppimport_builtin_dir(*arg):\n if not arg:\n p_frame = _get_frame(1)\n g = p_frame.f_globals\n l = p_frame.f_locals\n l['_ppimport_old_builtin_dir'] = _old_builtin_dir\n r = eval('_ppimport_old_builtin_dir()',g,l)\n del r[r.index('_ppimport_old_builtin_dir')]\n return r\n return _old_builtin_dir(*map(_ppresolve_ignore_failure,arg))\n_ppimport_builtin_dir.__doc__ = _old_builtin_dir.__doc__\n_builtin.dir = _ppimport_builtin_dir\n", "methods": [ { "name": "enable", "long_name": "enable( )", "filename": "ppimport.py", "nloc": 3, "complexity": 1, "token_count": 10, "parameters": [], "start_line": 22, "end_line": 25, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 4, "top_nesting_level": 0 }, { "name": "disable", "long_name": "disable( )", "filename": "ppimport.py", "nloc": 3, "complexity": 1, "token_count": 10, "parameters": [], "start_line": 27, "end_line": 30, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 4, "top_nesting_level": 0 }, { "name": "_get_so_ext", "long_name": "_get_so_ext( _cache = { } )", "filename": "ppimport.py", "nloc": 13, "complexity": 5, "token_count": 70, "parameters": [ "_cache" ], "start_line": 35, "end_line": 50, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 16, "top_nesting_level": 0 }, { "name": "_get_frame", "long_name": "_get_frame( level = 0 )", "filename": "ppimport.py", "nloc": 8, "complexity": 3, "token_count": 50, "parameters": [ "level" ], "start_line": 52, "end_line": 60, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 9, "top_nesting_level": 0 }, { "name": "ppimport_attr", "long_name": "ppimport_attr( module , name )", "filename": "ppimport.py", "nloc": 5, "complexity": 3, "token_count": 34, "parameters": [ "module", "name" ], "start_line": 62, "end_line": 68, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 7, "top_nesting_level": 0 }, { "name": "__init__", "long_name": "__init__( self , module , name )", "filename": "ppimport.py", "nloc": 3, "complexity": 1, "token_count": 25, "parameters": [ "self", "module", "name" ], "start_line": 71, "end_line": 73, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 3, "top_nesting_level": 1 }, { "name": "_ppimport_attr_getter", "long_name": "_ppimport_attr_getter( self )", "filename": "ppimport.py", "nloc": 14, "complexity": 4, "token_count": 76, "parameters": [ "self" ], "start_line": 75, "end_line": 90, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 16, "top_nesting_level": 1 }, { "name": "__nonzero__", "long_name": "__nonzero__( self )", "filename": "ppimport.py", "nloc": 2, "complexity": 1, "token_count": 7, "parameters": [ "self" ], "start_line": 92, "end_line": 93, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 2, "top_nesting_level": 1 }, { "name": "__getattr__", "long_name": "__getattr__( self , name )", "filename": "ppimport.py", "nloc": 8, "complexity": 3, "token_count": 41, "parameters": [ "self", "name" ], "start_line": 95, "end_line": 102, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 8, "top_nesting_level": 1 }, { "name": "__repr__", "long_name": "__repr__( self )", "filename": "ppimport.py", "nloc": 6, "complexity": 2, "token_count": 50, "parameters": [ "self" ], "start_line": 104, "end_line": 109, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 6, "top_nesting_level": 1 }, { "name": "__call__", "long_name": "__call__( self , * args , ** kwds )", "filename": "ppimport.py", "nloc": 2, "complexity": 1, "token_count": 22, "parameters": [ "self", "args", "kwds" ], "start_line": 114, "end_line": 115, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 2, "top_nesting_level": 1 }, { "name": "_is_local_module", "long_name": "_is_local_module( p_dir , name , suffices )", "filename": "ppimport.py", "nloc": 7, "complexity": 4, "token_count": 49, "parameters": [ "p_dir", "name", "suffices" ], "start_line": 119, "end_line": 125, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 7, "top_nesting_level": 0 }, { "name": "ppimport", "long_name": "ppimport( name )", "filename": "ppimport.py", "nloc": 49, "complexity": 14, "token_count": 337, "parameters": [ "name" ], "start_line": 127, "end_line": 202, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 76, "top_nesting_level": 0 }, { "name": "_get_frame_code", "long_name": "_get_frame_code( frame )", "filename": "ppimport.py", "nloc": 18, "complexity": 5, "token_count": 114, "parameters": [ "frame" ], "start_line": 204, "end_line": 221, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 18, "top_nesting_level": 0 }, { "name": "frame_traceback", "long_name": "frame_traceback( frame )", "filename": "ppimport.py", "nloc": 11, "complexity": 3, "token_count": 51, "parameters": [ "frame" ], "start_line": 223, "end_line": 233, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 11, "top_nesting_level": 0 }, { "name": "__init__", "long_name": "__init__( self , name , location , p_frame = None )", "filename": "ppimport.py", "nloc": 8, "complexity": 2, "token_count": 69, "parameters": [ "self", "name", "location", "p_frame" ], "start_line": 238, "end_line": 250, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 13, "top_nesting_level": 1 }, { "name": "_ppimport_importer", "long_name": "_ppimport_importer( self )", "filename": "ppimport.py", "nloc": 30, "complexity": 7, "token_count": 204, "parameters": [ "self" ], "start_line": 252, "end_line": 290, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 39, "top_nesting_level": 1 }, { "name": "__setattr__", "long_name": "__setattr__( self , name , value )", "filename": "ppimport.py", "nloc": 6, "complexity": 2, "token_count": 38, "parameters": [ "self", "name", "value" ], "start_line": 292, "end_line": 297, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 6, "top_nesting_level": 1 }, { "name": "__getattr__", "long_name": "__getattr__( self , name )", "filename": "ppimport.py", "nloc": 6, "complexity": 2, "token_count": 34, "parameters": [ "self", "name" ], "start_line": 299, "end_line": 304, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 6, "top_nesting_level": 1 }, { "name": "__repr__", "long_name": "__repr__( self )", "filename": "ppimport.py", "nloc": 16, "complexity": 5, "token_count": 87, "parameters": [ "self" ], "start_line": 306, "end_line": 321, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 16, "top_nesting_level": 1 }, { "name": "ppresolve", "long_name": "ppresolve( a , ignore_failure = None )", "filename": "ppimport.py", "nloc": 39, "complexity": 16, "token_count": 264, "parameters": [ "a", "ignore_failure" ], "start_line": 325, "end_line": 369, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 45, "top_nesting_level": 0 }, { "name": "_ppresolve_ignore_failure", "long_name": "_ppresolve_ignore_failure( a )", "filename": "ppimport.py", "nloc": 2, "complexity": 1, "token_count": 14, "parameters": [ "a" ], "start_line": 371, "end_line": 372, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 2, "top_nesting_level": 0 }, { "name": "_ppimport_pydoc_help_call", "long_name": "_ppimport_pydoc_help_call( self , * args , ** kwds )", "filename": "ppimport.py", "nloc": 3, "complexity": 1, "token_count": 27, "parameters": [ "self", "args", "kwds" ], "start_line": 385, "end_line": 387, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 3, "top_nesting_level": 1 }, { "name": "_ppimport_pydoc_Doc_document", "long_name": "_ppimport_pydoc_Doc_document( self , * args , ** kwds )", "filename": "ppimport.py", "nloc": 3, "complexity": 1, "token_count": 40, "parameters": [ "self", "args", "kwds" ], "start_line": 394, "end_line": 396, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 3, "top_nesting_level": 1 }, { "name": "_ppimport_pydoc_describe", "long_name": "_ppimport_pydoc_describe( object )", "filename": "ppimport.py", "nloc": 2, "complexity": 1, "token_count": 13, "parameters": [ "object" ], "start_line": 403, "end_line": 404, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 2, "top_nesting_level": 1 }, { "name": "_ppimport_inspect_getfile", "long_name": "_ppimport_inspect_getfile( object )", "filename": "ppimport.py", "nloc": 4, "complexity": 2, "token_count": 28, "parameters": [ "object" ], "start_line": 410, "end_line": 413, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 4, "top_nesting_level": 0 }, { "name": "_ppimport_inspect_getdoc", "long_name": "_ppimport_inspect_getdoc( object )", "filename": "ppimport.py", "nloc": 2, "complexity": 1, "token_count": 13, "parameters": [ "object" ], "start_line": 418, "end_line": 419, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 2, "top_nesting_level": 0 }, { "name": "_ppimport_inspect_getsource", "long_name": "_ppimport_inspect_getsource( object )", "filename": "ppimport.py", "nloc": 2, "complexity": 1, "token_count": 13, "parameters": [ "object" ], "start_line": 424, "end_line": 425, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 2, "top_nesting_level": 0 }, { "name": "_ppimport_builtin_dir", "long_name": "_ppimport_builtin_dir( * arg )", "filename": "ppimport.py", "nloc": 10, "complexity": 2, "token_count": 65, "parameters": [ "arg" ], "start_line": 431, "end_line": 440, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 10, "top_nesting_level": 0 } ], "methods_before": [ { "name": "enable", "long_name": "enable( )", "filename": "ppimport.py", "nloc": 3, "complexity": 1, "token_count": 10, "parameters": [], "start_line": 22, "end_line": 25, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 4, "top_nesting_level": 0 }, { "name": "disable", "long_name": "disable( )", "filename": "ppimport.py", "nloc": 3, "complexity": 1, "token_count": 10, "parameters": [], "start_line": 27, "end_line": 30, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 4, "top_nesting_level": 0 }, { "name": "_get_so_ext", "long_name": "_get_so_ext( _cache = { } )", "filename": "ppimport.py", "nloc": 13, "complexity": 5, "token_count": 70, "parameters": [ "_cache" ], "start_line": 35, "end_line": 50, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 16, "top_nesting_level": 0 }, { "name": "_get_frame", "long_name": "_get_frame( level = 0 )", "filename": "ppimport.py", "nloc": 8, "complexity": 3, "token_count": 50, "parameters": [ "level" ], "start_line": 52, "end_line": 60, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 9, "top_nesting_level": 0 }, { "name": "ppimport_attr", "long_name": "ppimport_attr( module , name )", "filename": "ppimport.py", "nloc": 5, "complexity": 3, "token_count": 34, "parameters": [ "module", "name" ], "start_line": 62, "end_line": 68, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 7, "top_nesting_level": 0 }, { "name": "__init__", "long_name": "__init__( self , module , name )", "filename": "ppimport.py", "nloc": 3, "complexity": 1, "token_count": 25, "parameters": [ "self", "module", "name" ], "start_line": 71, "end_line": 73, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 3, "top_nesting_level": 1 }, { "name": "_ppimport_attr_getter", "long_name": "_ppimport_attr_getter( self )", "filename": "ppimport.py", "nloc": 14, "complexity": 4, "token_count": 76, "parameters": [ "self" ], "start_line": 75, "end_line": 90, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 16, "top_nesting_level": 1 }, { "name": "__nonzero__", "long_name": "__nonzero__( self )", "filename": "ppimport.py", "nloc": 2, "complexity": 1, "token_count": 7, "parameters": [ "self" ], "start_line": 92, "end_line": 93, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 2, "top_nesting_level": 1 }, { "name": "__getattr__", "long_name": "__getattr__( self , name )", "filename": "ppimport.py", "nloc": 8, "complexity": 3, "token_count": 41, "parameters": [ "self", "name" ], "start_line": 95, "end_line": 102, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 8, "top_nesting_level": 1 }, { "name": "__repr__", "long_name": "__repr__( self )", "filename": "ppimport.py", "nloc": 6, "complexity": 2, "token_count": 50, "parameters": [ "self" ], "start_line": 104, "end_line": 109, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 6, "top_nesting_level": 1 }, { "name": "__call__", "long_name": "__call__( self , * args , ** kwds )", "filename": "ppimport.py", "nloc": 2, "complexity": 1, "token_count": 22, "parameters": [ "self", "args", "kwds" ], "start_line": 114, "end_line": 115, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 2, "top_nesting_level": 1 }, { "name": "_is_local_module", "long_name": "_is_local_module( p_dir , name , suffices )", "filename": "ppimport.py", "nloc": 7, "complexity": 4, "token_count": 49, "parameters": [ "p_dir", "name", "suffices" ], "start_line": 119, "end_line": 125, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 7, "top_nesting_level": 0 }, { "name": "ppimport", "long_name": "ppimport( name )", "filename": "ppimport.py", "nloc": 49, "complexity": 14, "token_count": 337, "parameters": [ "name" ], "start_line": 127, "end_line": 202, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 76, "top_nesting_level": 0 }, { "name": "_get_frame_code", "long_name": "_get_frame_code( frame )", "filename": "ppimport.py", "nloc": 18, "complexity": 5, "token_count": 114, "parameters": [ "frame" ], "start_line": 204, "end_line": 221, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 18, "top_nesting_level": 0 }, { "name": "frame_traceback", "long_name": "frame_traceback( frame )", "filename": "ppimport.py", "nloc": 11, "complexity": 3, "token_count": 51, "parameters": [ "frame" ], "start_line": 223, "end_line": 233, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 11, "top_nesting_level": 0 }, { "name": "__init__", "long_name": "__init__( self , name , location , p_frame = None )", "filename": "ppimport.py", "nloc": 8, "complexity": 2, "token_count": 69, "parameters": [ "self", "name", "location", "p_frame" ], "start_line": 238, "end_line": 250, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 13, "top_nesting_level": 1 }, { "name": "_ppimport_importer", "long_name": "_ppimport_importer( self )", "filename": "ppimport.py", "nloc": 30, "complexity": 7, "token_count": 204, "parameters": [ "self" ], "start_line": 252, "end_line": 290, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 39, "top_nesting_level": 1 }, { "name": "__setattr__", "long_name": "__setattr__( self , name , value )", "filename": "ppimport.py", "nloc": 6, "complexity": 2, "token_count": 38, "parameters": [ "self", "name", "value" ], "start_line": 292, "end_line": 297, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 6, "top_nesting_level": 1 }, { "name": "__getattr__", "long_name": "__getattr__( self , name )", "filename": "ppimport.py", "nloc": 6, "complexity": 2, "token_count": 34, "parameters": [ "self", "name" ], "start_line": 299, "end_line": 304, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 6, "top_nesting_level": 1 }, { "name": "__repr__", "long_name": "__repr__( self )", "filename": "ppimport.py", "nloc": 16, "complexity": 5, "token_count": 87, "parameters": [ "self" ], "start_line": 306, "end_line": 321, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 16, "top_nesting_level": 1 }, { "name": "ppresolve", "long_name": "ppresolve( a , ignore_failure = None )", "filename": "ppimport.py", "nloc": 39, "complexity": 16, "token_count": 264, "parameters": [ "a", "ignore_failure" ], "start_line": 325, "end_line": 369, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 45, "top_nesting_level": 0 }, { "name": "_ppresolve_ignore_failure", "long_name": "_ppresolve_ignore_failure( a )", "filename": "ppimport.py", "nloc": 2, "complexity": 1, "token_count": 14, "parameters": [ "a" ], "start_line": 371, "end_line": 372, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 2, "top_nesting_level": 0 }, { "name": "_ppimport_pydoc_help_call", "long_name": "_ppimport_pydoc_help_call( self , * args , ** kwds )", "filename": "ppimport.py", "nloc": 3, "complexity": 1, "token_count": 27, "parameters": [ "self", "args", "kwds" ], "start_line": 385, "end_line": 387, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 3, "top_nesting_level": 1 }, { "name": "_ppimport_pydoc_Doc_document", "long_name": "_ppimport_pydoc_Doc_document( self , * args , ** kwds )", "filename": "ppimport.py", "nloc": 3, "complexity": 1, "token_count": 40, "parameters": [ "self", "args", "kwds" ], "start_line": 394, "end_line": 396, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 3, "top_nesting_level": 1 }, { "name": "_ppimport_pydoc_describe", "long_name": "_ppimport_pydoc_describe( object )", "filename": "ppimport.py", "nloc": 2, "complexity": 1, "token_count": 13, "parameters": [ "object" ], "start_line": 403, "end_line": 404, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 2, "top_nesting_level": 1 }, { "name": "_ppimport_inspect_getfile", "long_name": "_ppimport_inspect_getfile( object )", "filename": "ppimport.py", "nloc": 4, "complexity": 2, "token_count": 25, "parameters": [ "object" ], "start_line": 410, "end_line": 413, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 4, "top_nesting_level": 0 }, { "name": "_ppimport_inspect_getdoc", "long_name": "_ppimport_inspect_getdoc( object )", "filename": "ppimport.py", "nloc": 2, "complexity": 1, "token_count": 13, "parameters": [ "object" ], "start_line": 418, "end_line": 419, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 2, "top_nesting_level": 0 }, { "name": "_ppimport_builtin_dir", "long_name": "_ppimport_builtin_dir( * arg )", "filename": "ppimport.py", "nloc": 10, "complexity": 2, "token_count": 65, "parameters": [ "arg" ], "start_line": 425, "end_line": 434, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 10, "top_nesting_level": 0 } ], "changed_methods": [ { "name": "_ppimport_inspect_getfile", "long_name": "_ppimport_inspect_getfile( object )", "filename": "ppimport.py", "nloc": 4, "complexity": 2, "token_count": 28, "parameters": [ "object" ], "start_line": 410, "end_line": 413, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 4, "top_nesting_level": 0 }, { "name": "_ppimport_inspect_getsource", "long_name": "_ppimport_inspect_getsource( object )", "filename": "ppimport.py", "nloc": 2, "complexity": 1, "token_count": 13, "parameters": [ "object" ], "start_line": 424, "end_line": 425, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 2, "top_nesting_level": 0 } ], "nloc": 341, "complexity": 95, "token_count": 2114, "diff_parsed": { "added": [ " return _old_inspect_getfile(_ppresolve_ignore_failure(object))", "_old_inspect_getsource = _inspect.getsource", "def _ppimport_inspect_getsource(object):", " return _old_inspect_getsource(_ppresolve_ignore_failure(object))", "_ppimport_inspect_getsource.__doc__ = _old_inspect_getsource.__doc__", "_inspect.getsource = _ppimport_inspect_getsource", "" ], "deleted": [ " return _old_inspect_getfile(object)" ] } } ] }, { "hash": "47a598cc76731b33f96aaba91f1f7b94535c7bcc", "msg": "Introduced HideException. Fixed docs.", "author": { "name": "Pearu Peterson", "email": "pearu.peterson@gmail.com" }, "committer": { "name": "Pearu Peterson", "email": "pearu.peterson@gmail.com" }, "author_date": "2004-11-29T17:46:30+00:00", "author_timezone": 0, "committer_date": "2004-11-29T17:46:30+00:00", "committer_timezone": 0, "branches": [ "main" ], "in_main_branch": true, "merge": false, "parents": [ "c1361c857a2f28db25e4af652e0fc6de3fd3ad76" ], "project_name": "repo_copy", "project_path": "/tmp/tmpqop781_j/repo_copy", "deletions": 9, "insertions": 30, "lines": 39, "files": 1, "dmm_unit_size": 0.0, "dmm_unit_complexity": 0.0, "dmm_unit_interfacing": 1.0, "modified_files": [ { "old_path": "scipy_test/testing.py", "new_path": "scipy_test/testing.py", "filename": "testing.py", "extension": "py", "change_type": "MODIFY", "diff": "@@ -4,6 +4,8 @@\n \n ScipyTest -- Scipy tests site manager\n ScipyTestCase -- unittest.TestCase with measure method\n+ IgnoreException -- raise when checking disabled feature ('ignoring' is displayed)\n+ HideException -- raise when checking disabled feature (nothing is displayed)\n set_package_path -- prepend package build directory to path\n set_local_path -- prepend local directory (to tests files) to path\n restore_path -- restore path after set_package_path\n@@ -17,12 +19,12 @@\n Utility functions\n -----------------\n \n- assert_equal --\n- assert_almost_equal --\n- assert_approx_equal --\n- assert_array_equal --\n- assert_array_almost_equal --\n- assert_array_less --\n+ assert_equal -- assert equality\n+ assert_almost_equal -- assert equality with decimal tolerance\n+ assert_approx_equal -- assert equality with significant digits tolerance\n+ assert_array_equal -- assert arrays equality\n+ assert_array_almost_equal -- assert arrays equality with decimal tolerance\n+ assert_array_less -- assert arrays less-ordering\n rand -- array of random numbers from given shape\n \n \"\"\"\n@@ -175,10 +177,25 @@ def __call__(self, result=None):\n errstr = str(errstr[0])\n else:\n errstr = errstr.split('\\n')[-2]\n+ l = len(result.stream.data)\n if errstr.startswith('IgnoreException:'):\n- assert result.stream.data[-1]=='E',`result.stream.data`\n- result.stream.data[-1] = 'i'\n- del result.errors[-1]\n+ if l==1:\n+ assert result.stream.data[-1]=='E',`result.stream.data`\n+ result.stream.data[-1] = 'i'\n+ del result.errors[-1]\n+ else:\n+ assert result.stream.data[-1]=='ERROR\\n',`result.stream.data`\n+ result.stream.data[-1] = 'ignoring\\n'\n+ del result.errors[-1]\n+ elif errstr.startswith('HideException:'):\n+ if l==1:\n+ assert result.stream.data[-1]=='E',`result.stream.data`\n+ result.stream.data[-1] = ''\n+ del result.errors[-1]\n+ else:\n+ assert result.stream.data[-1]=='ERROR\\n',`result.stream.data`\n+ result.stream.data = []\n+ del result.errors[-1]\n map(save_stream.write, result.stream.data)\n result.stream = save_stream\n \n@@ -194,6 +211,10 @@ def writeln(self,message):\n class IgnoreException(Exception):\n \"Ignoring this exception due to disabled feature\"\n \n+__all__.append('HideException')\n+class HideException(Exception):\n+ \"Hide this exception due to disabled feature\"\n+\n #------------\n \n def _get_all_method_names(cls):\n", "added_lines": 30, "deleted_lines": 9, "source_code": "\"\"\"\nUnit-testing\n------------\n\n ScipyTest -- Scipy tests site manager\n ScipyTestCase -- unittest.TestCase with measure method\n IgnoreException -- raise when checking disabled feature ('ignoring' is displayed)\n HideException -- raise when checking disabled feature (nothing is displayed)\n set_package_path -- prepend package build directory to path\n set_local_path -- prepend local directory (to tests files) to path\n restore_path -- restore path after set_package_path\n\nTiming tools\n------------\n\n jiffies -- return 1/100ths of a second that the current process has used\n memusage -- virtual memory size in bytes of the running python [linux]\n\nUtility functions\n-----------------\n\n assert_equal -- assert equality\n assert_almost_equal -- assert equality with decimal tolerance\n assert_approx_equal -- assert equality with significant digits tolerance\n assert_array_equal -- assert arrays equality\n assert_array_almost_equal -- assert arrays equality with decimal tolerance\n assert_array_less -- assert arrays less-ordering\n rand -- array of random numbers from given shape\n\n\"\"\"\n\n__all__ = []\n\nimport os,sys,time,glob,string,traceback,unittest\nimport types\nimport imp\n\ntry:\n # These are used by Numeric tests.\n # If Numeric and scipy_base are not available, then some of the\n # functions below will not be available.\n from Numeric import alltrue,equal,shape,ravel,around,zeros,Float64,asarray,\\\n less_equal,array2string,less\n # `import scipy_base.fastumath as math` must be at the end of this file.\nexcept ImportError,msg:\n print msg\n\nDEBUG = 0\n\n__all__.append('set_package_path')\ndef set_package_path(level=1):\n \"\"\" Prepend package directory to sys.path.\n\n set_package_path should be called from a test_file.py that\n satisfies the following tree structure:\n\n //test_file.py\n\n Then the first existing path name from the following list\n\n /build/lib.-\n /..\n\n is prepended to sys.path.\n The caller is responsible for removing this path by using\n\n restore_path()\n \"\"\"\n from distutils.util import get_platform\n from scipy_distutils.misc_util import get_frame\n f = get_frame(level)\n if f.f_locals['__name__']=='__main__':\n testfile = sys.argv[0]\n else:\n testfile = f.f_locals['__file__']\n d = os.path.dirname(os.path.dirname(os.path.abspath(testfile)))\n d1 = os.path.join(d,'build','lib.%s-%s'%(get_platform(),sys.version[:3]))\n if not os.path.isdir(d1):\n d1 = os.path.dirname(d)\n if DEBUG:\n print 'Inserting %r to sys.path' % (d1)\n sys.path.insert(0,d1)\n\n__all__.append('set_local_path')\ndef set_local_path(reldir='', level=1):\n \"\"\" Prepend local directory to sys.path.\n\n The caller is responsible for removing this path by using\n\n restore_path()\n \"\"\"\n from scipy_distutils.misc_util import get_frame\n f = get_frame(level)\n if f.f_locals['__name__']=='__main__':\n testfile = sys.argv[0]\n else:\n testfile = f.f_locals['__file__']\n local_path = os.path.join(os.path.dirname(os.path.abspath(testfile)),reldir)\n if DEBUG:\n print 'Inserting %r to sys.path' % (local_path)\n sys.path.insert(0,local_path)\n\n__all__.append('restore_path')\ndef restore_path():\n if DEBUG:\n print 'Removing %r from sys.path' % (sys.path[0])\n del sys.path[0]\n\n__all__.extend(['jiffies','memusage'])\nif sys.platform[:5]=='linux':\n def jiffies(_proc_pid_stat = '/proc/%s/stat'%(os.getpid()),\n _load_time=time.time()):\n \"\"\" Return number of jiffies (1/100ths of a second) that this\n process has been scheduled in user mode. See man 5 proc. \"\"\"\n try:\n f=open(_proc_pid_stat,'r')\n l = f.readline().split(' ')\n f.close()\n return int(l[13])\n except:\n return int(100*(time.time()-_load_time))\n\n def memusage(_proc_pid_stat = '/proc/%s/stat'%(os.getpid())):\n \"\"\" Return virtual memory size in bytes of the running python.\n \"\"\"\n try:\n f=open(_proc_pid_stat,'r')\n l = f.readline().split(' ')\n f.close()\n return int(l[22])\n except:\n return\nelse:\n # os.getpid is not in all platforms available.\n # Using time is safe but inaccurate, especially when process\n # was suspended or sleeping.\n def jiffies(_load_time=time.time()):\n \"\"\" Return number of jiffies (1/100ths of a second) that this\n process has been scheduled in user mode. [Emulation with time.time]. \"\"\"\n return int(100*(time.time()-_load_time))\n\n def memusage():\n \"\"\" Return memory usage of running python. [Not implemented]\"\"\"\n return\n\n__all__.append('ScipyTestCase')\nclass ScipyTestCase (unittest.TestCase):\n\n def measure(self,code_str,times=1):\n \"\"\" Return elapsed time for executing code_str in the\n namespace of the caller for given times.\n \"\"\"\n frame = sys._getframe(1)\n locs,globs = frame.f_locals,frame.f_globals\n code = compile(code_str,\n 'ScipyTestCase runner for '+self.__class__.__name__,\n 'exec')\n i = 0\n elapsed = jiffies()\n while i>> ScipyTest().test(level=1,verbosity=2)\n\n is package name or its module object.\n\n Package is supposed to contain a directory tests/\n with test_*.py files where * refers to the names of submodules.\n\n test_*.py files are supposed to define a classes, derived\n from ScipyTestCase or unittest.TestCase, with methods having\n names starting with test or bench or check.\n\n And that is it! No need to implement test or test_suite functions\n in each .py file.\n\n Also old styled test_suite(level=1) hooks are supported but\n soon to be removed.\n \"\"\"\n def __init__(self, package='__main__'):\n self.package = package\n\n def _module_str(self, module):\n filename = module.__file__[-30:]\n if filename!=module.__file__:\n filename = '...'+filename\n return '' % (`module.__name__`, `filename`)\n\n def _get_method_names(self,clsobj,level):\n names = []\n for mthname in _get_all_method_names(clsobj):\n if mthname[:5] not in ['bench','check'] \\\n and mthname[:4] not in ['test']:\n continue\n mth = getattr(clsobj, mthname)\n if type(mth) is not types.MethodType:\n continue\n d = mth.im_func.func_defaults\n if d is not None:\n mthlevel = d[0]\n else:\n mthlevel = 1\n if level>=mthlevel:\n if mthname not in names:\n names.append(mthname)\n for base in clsobj.__bases__:\n for n in self._get_method_names(base,level):\n if n not in names:\n names.append(n)\n return names\n\n def _get_module_tests(self,module,level):\n mstr = self._module_str\n d,f = os.path.split(module.__file__)\n\n short_module_name = os.path.splitext(os.path.basename(f))[0]\n if short_module_name=='__init__':\n short_module_name = module.__name__.split('.')[-1]\n\n test_dir = os.path.join(d,'tests')\n test_file = os.path.join(test_dir,'test_'+short_module_name+'.py')\n\n local_test_dir = os.path.join(os.getcwd(),'tests')\n local_test_file = os.path.join(local_test_dir,\n 'test_'+short_module_name+'.py')\n if os.path.basename(os.path.dirname(local_test_dir)) \\\n == os.path.basename(os.path.dirname(test_dir)) \\\n and os.path.isfile(local_test_file):\n test_file = local_test_file\n\n if not os.path.isfile(test_file):\n if short_module_name[:5]=='info_' \\\n and short_module_name[5:]==module.__name__.split('.')[-2]:\n return []\n if short_module_name in ['__cvs_version__','__svn_version__']:\n return []\n if short_module_name[-8:]=='_version' \\\n and short_module_name[:-8]==module.__name__.split('.')[-2]:\n return []\n print ' !! No test file %r found for %s' \\\n % (os.path.basename(test_file), mstr(module))\n return []\n\n try:\n if sys.version[:3]=='2.1':\n # Workaround for Python 2.1 .pyc file generator bug\n import random\n pref = '-nopyc'+`random.randint(1,100)`\n else:\n pref = ''\n f = open(test_file,'r')\n test_module = imp.load_module(\\\n module.__name__+'.test_'+short_module_name+pref,\n f, test_file+pref,('.py', 'r', 1))\n f.close()\n if sys.version[:3]=='2.1' and os.path.isfile(test_file+pref+'c'):\n os.remove(test_file+pref+'c')\n except:\n print ' !! FAILURE importing tests for ', mstr(module)\n print ' ',\n output_exception()\n return []\n return self._get_suite_list(test_module, level, module.__name__)\n\n def _get_suite_list(self, test_module, level, module_name='__main__'):\n mstr = self._module_str\n if hasattr(test_module,'test_suite'):\n # Using old styled test suite\n try:\n total_suite = test_module.test_suite(level)\n return total_suite._tests\n except:\n print ' !! FAILURE building tests for ', mstr(test_module)\n print ' ',\n output_exception()\n return []\n suite_list = []\n for name in dir(test_module):\n obj = getattr(test_module, name)\n if type(obj) is not type(unittest.TestCase) \\\n or not issubclass(obj, unittest.TestCase) \\\n or obj.__name__[:4] != 'test':\n continue\n suite_list.extend(map(obj,self._get_method_names(obj,level)))\n print ' Found',len(suite_list),'tests for',module_name\n return suite_list\n\n def _touch_ppimported(self, module):\n from scipy_base.ppimport import _ModuleLoader\n if os.path.isdir(os.path.join(os.path.dirname(module.__file__),'tests')):\n # only touching those modules that have tests/ directory\n try: module._pliuh_plauh\n except AttributeError: pass\n for name in dir(module):\n obj = getattr(module,name)\n if isinstance(obj,_ModuleLoader) \\\n and not hasattr(obj,'_ppimport_module') \\\n and not hasattr(obj,'_ppimport_exc_info'):\n self._touch_ppimported(obj)\n\n def test(self,level=1,verbosity=1):\n \"\"\" Run Scipy module test suite with level and verbosity.\n \"\"\"\n if type(self.package) is type(''):\n exec 'import %s as this_package' % (self.package)\n else:\n this_package = self.package\n\n self._touch_ppimported(this_package)\n\n package_name = this_package.__name__\n\n suites = []\n for name, module in sys.modules.items():\n if package_name != name[:len(package_name)] \\\n or module is None \\\n or os.path.basename(os.path.dirname(module.__file__))=='tests':\n continue\n suites.extend(self._get_module_tests(module, level))\n\n suites.extend(self._get_suite_list(sys.modules[package_name], level))\n\n all_tests = unittest.TestSuite(suites)\n runner = unittest.TextTestRunner(verbosity=verbosity)\n runner.run(all_tests)\n return runner\n\n def run(self):\n \"\"\" Run Scipy module test suite with level and verbosity\n taken from sys.argv. Requires optparse module.\n \"\"\"\n try:\n from optparse import OptionParser\n except ImportError:\n print 'Failed to import optparse module, ignoring.'\n return self.test()\n usage = r'usage: %prog [-v ] [-l ]'\n parser = OptionParser(usage)\n parser.add_option(\"-v\", \"--verbosity\",\n action=\"store\",\n dest=\"verbosity\",\n default=1,\n type='int')\n parser.add_option(\"-l\", \"--level\",\n action=\"store\",\n dest=\"level\",\n default=1,\n type='int')\n (options, args) = parser.parse_args()\n self.test(options.level,options.verbosity)\n\n#------------\n \ndef remove_ignored_patterns(files,pattern):\n from fnmatch import fnmatch\n good_files = []\n for file in files:\n if not fnmatch(file,pattern):\n good_files.append(file)\n return good_files\n\ndef remove_ignored_files(original,ignored_files,cur_dir):\n \"\"\" This is actually expanded to do pattern matching.\n\n \"\"\"\n if not ignored_files: ignored_files = []\n ignored_modules = map(lambda x: x+'.py',ignored_files)\n ignored_packages = ignored_files[:]\n # always ignore setup.py and __init__.py files\n ignored_files = ['setup.py','setup_*.py','__init__.py']\n ignored_files += ignored_modules + ignored_packages\n ignored_files = map(lambda x,cur_dir=cur_dir: os.path.join(cur_dir,x),\n ignored_files)\n #print 'ignored:', ignored_files\n #good_files = filter(lambda x,ignored = ignored_files: x not in ignored,\n # original)\n good_files = original\n for pattern in ignored_files:\n good_files = remove_ignored_patterns(good_files,pattern)\n\n return good_files\n\n__all__.append('harvest_modules')\ndef harvest_modules(package,ignore=None):\n \"\"\"* Retreive a list of all modules that live within a package.\n\n Only retreive files that are immediate children of the\n package -- do not recurse through child packages or\n directories. The returned list contains actual modules, not\n just their names.\n *\"\"\"\n d,f = os.path.split(package.__file__)\n\n # go through the directory and import every py file there.\n common_dir = os.path.join(d,'*.py')\n py_files = glob.glob(common_dir)\n #py_files.remove(os.path.join(d,'__init__.py'))\n #py_files.remove(os.path.join(d,'setup.py'))\n\n py_files = remove_ignored_files(py_files,ignore,d)\n #print 'py_files:', py_files\n try:\n prefix = package.__name__\n except:\n prefix = ''\n\n all_modules = []\n for file in py_files:\n d,f = os.path.split(file)\n base,ext = os.path.splitext(f)\n mod = prefix + '.' + base\n #print 'module: import ' + mod\n try:\n exec ('import ' + mod)\n all_modules.append(eval(mod))\n except:\n print 'FAILURE to import ' + mod\n output_exception()\n\n return all_modules\n\n__all__.append('harvest_packages')\ndef harvest_packages(package,ignore = None):\n \"\"\" Retreive a list of all sub-packages that live within a package.\n\n Only retreive packages that are immediate children of this\n package -- do not recurse through child packages or\n directories. The returned list contains actual package objects, not\n just their names.\n \"\"\"\n join = os.path.join\n\n d,f = os.path.split(package.__file__)\n\n common_dir = os.path.abspath(d)\n all_files = os.listdir(d)\n\n all_files = remove_ignored_files(all_files,ignore,'')\n #print 'all_files:', all_files\n try:\n prefix = package.__name__\n except:\n prefix = ''\n all_packages = []\n for directory in all_files:\n path = join(common_dir,directory)\n if os.path.isdir(path) and \\\n os.path.exists(join(path,'__init__.py')):\n sub_package = prefix + '.' + directory\n #print 'sub-package import ' + sub_package\n try:\n exec ('import ' + sub_package)\n all_packages.append(eval(sub_package))\n except:\n print 'FAILURE to import ' + sub_package\n output_exception()\n return all_packages\n\n__all__.append('harvest_modules_and_packages')\ndef harvest_modules_and_packages(package,ignore=None):\n \"\"\" Retreive list of all packages and modules that live within a package.\n\n See harvest_packages() and harvest_modules()\n \"\"\"\n all = harvest_modules(package,ignore) + harvest_packages(package,ignore)\n return all\n\n__all__.append('harvest_test_suites')\ndef harvest_test_suites(package,ignore = None,level=10):\n \"\"\"\n package -- the module to test. This is an actual module object\n (not a string)\n ignore -- a list of module names to omit from the tests\n level -- a value between 1 and 10. 1 will run the minimum number\n of tests. This is a fast \"smoke test\". Tests that take\n longer to run should have higher numbers ranging up to 10.\n \"\"\"\n suites=[]\n test_modules = harvest_modules_and_packages(package,ignore)\n #for i in test_modules:\n # print i.__name__\n for module in test_modules:\n if hasattr(module,'test_suite'):\n try:\n suite = module.test_suite(level=level)\n if suite:\n suites.append(suite)\n else:\n print \" !! FAILURE without error - shouldn't happen\",\n print module.__name__\n except:\n print ' !! FAILURE building test for ', module.__name__\n print ' ',\n output_exception()\n else:\n try:\n print 'No test suite found for ', module.__name__\n except AttributeError:\n # __version__.py getting replaced by a string throws a kink\n # in checking for modules, so we think is a module has\n # actually been overwritten\n print 'No test suite found for ', str(module)\n total_suite = unittest.TestSuite(suites)\n return total_suite\n\n__all__.append('module_test')\ndef module_test(mod_name,mod_file,level=10):\n \"\"\"*\n\n *\"\"\"\n #print 'testing', mod_name\n d,f = os.path.split(mod_file)\n\n # insert the tests directory to the python path\n test_dir = os.path.join(d,'tests')\n sys.path.insert(0,test_dir)\n\n # call the \"test_xxx.test()\" function for the appropriate\n # module.\n\n # This should deal with package naming issues correctly\n short_mod_name = string.split(mod_name,'.')[-1]\n test_module = 'test_' + short_mod_name\n test_string = 'import %s;reload(%s);%s.test(%d)' % \\\n ((test_module,)*3 + (level,))\n\n # This would be better cause it forces a reload of the orginal\n # module. It doesn't behave with packages however.\n #test_string = 'reload(%s);import %s;reload(%s);%s.test(%d)' % \\\n # ((mod_name,) + (test_module,)*3)\n exec(test_string)\n\n # remove test directory from python path.\n sys.path = sys.path[1:]\n\n__all__.append('module_test_suite')\ndef module_test_suite(mod_name,mod_file,level=10):\n #try:\n print ' creating test suite for:', mod_name\n d,f = os.path.split(mod_file)\n\n # insert the tests directory to the python path\n test_dir = os.path.join(d,'tests')\n sys.path.insert(0,test_dir)\n\n # call the \"test_xxx.test()\" function for the appropriate\n # module.\n\n # This should deal with package naming issues correctly\n short_mod_name = string.split(mod_name,'.')[-1]\n test_module = 'test_' + short_mod_name\n test_string = 'import %s;reload(%s);suite = %s.test_suite(%d)' % \\\n ((test_module,)*3+(level,))\n #print test_string\n exec(test_string)\n\n # remove test directory from python path.\n sys.path = sys.path[1:]\n return suite\n #except:\n # print ' !! FAILURE loading test suite from', test_module, ':'\n # print ' ',\n # output_exception()\n\n\n# Utility function to facilitate testing.\n\n__all__.append('assert_equal')\ndef assert_equal(actual,desired,err_msg='',verbose=1):\n \"\"\" Raise an assertion if two items are not\n equal. I think this should be part of unittest.py\n \"\"\"\n msg = '\\nItems are not equal:\\n' + err_msg\n try:\n if ( verbose and len(repr(desired)) < 100 and len(repr(actual)) ):\n msg = msg \\\n + 'DESIRED: ' + repr(desired) \\\n + '\\nACTUAL: ' + repr(actual)\n except:\n msg = msg \\\n + 'DESIRED: ' + repr(desired) \\\n + '\\nACTUAL: ' + repr(actual)\n assert desired == actual, msg\n\n__all__.append('assert_almost_equal')\ndef assert_almost_equal(actual,desired,decimal=7,err_msg='',verbose=1):\n \"\"\" Raise an assertion if two items are not\n equal. I think this should be part of unittest.py\n \"\"\"\n msg = '\\nItems are not equal:\\n' + err_msg\n try:\n if ( verbose and len(repr(desired)) < 100 and len(repr(actual)) ):\n msg = msg \\\n + 'DESIRED: ' + repr(desired) \\\n + '\\nACTUAL: ' + repr(actual)\n except:\n msg = msg \\\n + 'DESIRED: ' + repr(desired) \\\n + '\\nACTUAL: ' + repr(actual)\n assert round(abs(desired - actual),decimal) == 0, msg\n\n__all__.append('assert_approx_equal')\ndef assert_approx_equal(actual,desired,significant=7,err_msg='',verbose=1):\n \"\"\" Raise an assertion if two items are not\n equal. I think this should be part of unittest.py\n Approximately equal is defined as the number of significant digits\n correct\n \"\"\"\n msg = '\\nItems are not equal to %d significant digits:\\n' % significant\n msg += err_msg\n actual, desired = map(float, (actual, desired))\n # Normalized the numbers to be in range (-10.0,10.0)\n scale = pow(10,math.floor(math.log10(0.5*(abs(desired)+abs(actual)))))\n try:\n sc_desired = desired/scale\n except ZeroDivisionError:\n sc_desired = 0.0\n try:\n sc_actual = actual/scale\n except ZeroDivisionError:\n sc_actual = 0.0\n try:\n if ( verbose and len(repr(desired)) < 100 and len(repr(actual)) ):\n msg = msg \\\n + 'DESIRED: ' + repr(desired) \\\n + '\\nACTUAL: ' + repr(actual)\n except:\n msg = msg \\\n + 'DESIRED: ' + repr(desired) \\\n + '\\nACTUAL: ' + repr(actual)\n assert math.fabs(sc_desired - sc_actual) < pow(10.,-1*significant), msg\n\n\n__all__.append('assert_array_equal')\ndef assert_array_equal(x,y,err_msg=''):\n x,y = asarray(x), asarray(y)\n msg = '\\nArrays are not equal'\n try:\n assert 0 in [len(shape(x)),len(shape(y))] \\\n or (len(shape(x))==len(shape(y)) and \\\n alltrue(equal(shape(x),shape(y)))),\\\n msg + ' (shapes %s, %s mismatch):\\n\\t' \\\n % (shape(x),shape(y)) + err_msg\n reduced = ravel(equal(x,y))\n cond = alltrue(reduced)\n if not cond:\n s1 = array2string(x,precision=16)\n s2 = array2string(y,precision=16)\n if len(s1)>120: s1 = s1[:120] + '...'\n if len(s2)>120: s2 = s2[:120] + '...'\n match = 100-100.0*reduced.tolist().count(1)/len(reduced)\n msg = msg + ' (mismatch %s%%):\\n\\tArray 1: %s\\n\\tArray 2: %s' % (match,s1,s2)\n assert cond,\\\n msg + '\\n\\t' + err_msg\n except ValueError:\n raise ValueError, msg\n\n__all__.append('assert_array_almost_equal')\ndef assert_array_almost_equal(x,y,decimal=6,err_msg=''):\n x = asarray(x)\n y = asarray(y)\n msg = '\\nArrays are not almost equal'\n try:\n cond = alltrue(equal(shape(x),shape(y)))\n if not cond:\n msg = msg + ' (shapes mismatch):\\n\\t'\\\n 'Shape of array 1: %s\\n\\tShape of array 2: %s' % (shape(x),shape(y))\n assert cond, msg + '\\n\\t' + err_msg\n reduced = ravel(equal(less_equal(around(abs(x-y),decimal),10.0**(-decimal)),1))\n cond = alltrue(reduced)\n if not cond:\n s1 = array2string(x,precision=decimal+1)\n s2 = array2string(y,precision=decimal+1)\n if len(s1)>120: s1 = s1[:120] + '...'\n if len(s2)>120: s2 = s2[:120] + '...'\n match = 100-100.0*reduced.tolist().count(1)/len(reduced)\n msg = msg + ' (mismatch %s%%):\\n\\tArray 1: %s\\n\\tArray 2: %s' % (match,s1,s2)\n assert cond,\\\n msg + '\\n\\t' + err_msg\n except ValueError:\n print sys.exc_value\n print shape(x),shape(y)\n print x, y\n raise ValueError, 'arrays are not almost equal'\n\n__all__.append('assert_array_less')\ndef assert_array_less(x,y,err_msg=''):\n x,y = asarray(x), asarray(y)\n msg = '\\nArrays are not less-ordered'\n try:\n assert alltrue(equal(shape(x),shape(y))),\\\n msg + ' (shapes mismatch):\\n\\t' + err_msg\n reduced = ravel(less(x,y))\n cond = alltrue(reduced)\n if not cond:\n s1 = array2string(x,precision=16)\n s2 = array2string(y,precision=16)\n if len(s1)>120: s1 = s1[:120] + '...'\n if len(s2)>120: s2 = s2[:120] + '...'\n match = 100-100.0*reduced.tolist().count(1)/len(reduced)\n msg = msg + ' (mismatch %s%%):\\n\\tArray 1: %s\\n\\tArray 2: %s' % (match,s1,s2)\n assert cond,\\\n msg + '\\n\\t' + err_msg\n except ValueError:\n print shape(x),shape(y)\n raise ValueError, 'arrays are not less-ordered'\n\n__all__.append('rand')\ndef rand(*args):\n \"\"\" Returns an array of random numbers with the given shape.\n used for testing\n \"\"\"\n import random\n results = zeros(args,Float64)\n f = results.flat\n for i in range(len(f)):\n f[i] = random.random()\n return results\n\ndef output_exception():\n try:\n type, value, tb = sys.exc_info()\n info = traceback.extract_tb(tb)\n #this is more verbose\n #traceback.print_exc()\n filename, lineno, function, text = info[-1] # last line only\n print \"%s:%d: %s: %s (in %s)\" %\\\n (filename, lineno, type.__name__, str(value), function)\n finally:\n type = value = tb = None # clean up\n\ntry:\n import scipy_base.fastumath as math\nexcept ImportError,msg:\n print msg\n import math\n", "source_code_before": "\"\"\"\nUnit-testing\n------------\n\n ScipyTest -- Scipy tests site manager\n ScipyTestCase -- unittest.TestCase with measure method\n set_package_path -- prepend package build directory to path\n set_local_path -- prepend local directory (to tests files) to path\n restore_path -- restore path after set_package_path\n\nTiming tools\n------------\n\n jiffies -- return 1/100ths of a second that the current process has used\n memusage -- virtual memory size in bytes of the running python [linux]\n\nUtility functions\n-----------------\n\n assert_equal --\n assert_almost_equal --\n assert_approx_equal --\n assert_array_equal --\n assert_array_almost_equal --\n assert_array_less --\n rand -- array of random numbers from given shape\n\n\"\"\"\n\n__all__ = []\n\nimport os,sys,time,glob,string,traceback,unittest\nimport types\nimport imp\n\ntry:\n # These are used by Numeric tests.\n # If Numeric and scipy_base are not available, then some of the\n # functions below will not be available.\n from Numeric import alltrue,equal,shape,ravel,around,zeros,Float64,asarray,\\\n less_equal,array2string,less\n # `import scipy_base.fastumath as math` must be at the end of this file.\nexcept ImportError,msg:\n print msg\n\nDEBUG = 0\n\n__all__.append('set_package_path')\ndef set_package_path(level=1):\n \"\"\" Prepend package directory to sys.path.\n\n set_package_path should be called from a test_file.py that\n satisfies the following tree structure:\n\n //test_file.py\n\n Then the first existing path name from the following list\n\n /build/lib.-\n /..\n\n is prepended to sys.path.\n The caller is responsible for removing this path by using\n\n restore_path()\n \"\"\"\n from distutils.util import get_platform\n from scipy_distutils.misc_util import get_frame\n f = get_frame(level)\n if f.f_locals['__name__']=='__main__':\n testfile = sys.argv[0]\n else:\n testfile = f.f_locals['__file__']\n d = os.path.dirname(os.path.dirname(os.path.abspath(testfile)))\n d1 = os.path.join(d,'build','lib.%s-%s'%(get_platform(),sys.version[:3]))\n if not os.path.isdir(d1):\n d1 = os.path.dirname(d)\n if DEBUG:\n print 'Inserting %r to sys.path' % (d1)\n sys.path.insert(0,d1)\n\n__all__.append('set_local_path')\ndef set_local_path(reldir='', level=1):\n \"\"\" Prepend local directory to sys.path.\n\n The caller is responsible for removing this path by using\n\n restore_path()\n \"\"\"\n from scipy_distutils.misc_util import get_frame\n f = get_frame(level)\n if f.f_locals['__name__']=='__main__':\n testfile = sys.argv[0]\n else:\n testfile = f.f_locals['__file__']\n local_path = os.path.join(os.path.dirname(os.path.abspath(testfile)),reldir)\n if DEBUG:\n print 'Inserting %r to sys.path' % (local_path)\n sys.path.insert(0,local_path)\n\n__all__.append('restore_path')\ndef restore_path():\n if DEBUG:\n print 'Removing %r from sys.path' % (sys.path[0])\n del sys.path[0]\n\n__all__.extend(['jiffies','memusage'])\nif sys.platform[:5]=='linux':\n def jiffies(_proc_pid_stat = '/proc/%s/stat'%(os.getpid()),\n _load_time=time.time()):\n \"\"\" Return number of jiffies (1/100ths of a second) that this\n process has been scheduled in user mode. See man 5 proc. \"\"\"\n try:\n f=open(_proc_pid_stat,'r')\n l = f.readline().split(' ')\n f.close()\n return int(l[13])\n except:\n return int(100*(time.time()-_load_time))\n\n def memusage(_proc_pid_stat = '/proc/%s/stat'%(os.getpid())):\n \"\"\" Return virtual memory size in bytes of the running python.\n \"\"\"\n try:\n f=open(_proc_pid_stat,'r')\n l = f.readline().split(' ')\n f.close()\n return int(l[22])\n except:\n return\nelse:\n # os.getpid is not in all platforms available.\n # Using time is safe but inaccurate, especially when process\n # was suspended or sleeping.\n def jiffies(_load_time=time.time()):\n \"\"\" Return number of jiffies (1/100ths of a second) that this\n process has been scheduled in user mode. [Emulation with time.time]. \"\"\"\n return int(100*(time.time()-_load_time))\n\n def memusage():\n \"\"\" Return memory usage of running python. [Not implemented]\"\"\"\n return\n\n__all__.append('ScipyTestCase')\nclass ScipyTestCase (unittest.TestCase):\n\n def measure(self,code_str,times=1):\n \"\"\" Return elapsed time for executing code_str in the\n namespace of the caller for given times.\n \"\"\"\n frame = sys._getframe(1)\n locs,globs = frame.f_locals,frame.f_globals\n code = compile(code_str,\n 'ScipyTestCase runner for '+self.__class__.__name__,\n 'exec')\n i = 0\n elapsed = jiffies()\n while i>> ScipyTest().test(level=1,verbosity=2)\n\n is package name or its module object.\n\n Package is supposed to contain a directory tests/\n with test_*.py files where * refers to the names of submodules.\n\n test_*.py files are supposed to define a classes, derived\n from ScipyTestCase or unittest.TestCase, with methods having\n names starting with test or bench or check.\n\n And that is it! No need to implement test or test_suite functions\n in each .py file.\n\n Also old styled test_suite(level=1) hooks are supported but\n soon to be removed.\n \"\"\"\n def __init__(self, package='__main__'):\n self.package = package\n\n def _module_str(self, module):\n filename = module.__file__[-30:]\n if filename!=module.__file__:\n filename = '...'+filename\n return '' % (`module.__name__`, `filename`)\n\n def _get_method_names(self,clsobj,level):\n names = []\n for mthname in _get_all_method_names(clsobj):\n if mthname[:5] not in ['bench','check'] \\\n and mthname[:4] not in ['test']:\n continue\n mth = getattr(clsobj, mthname)\n if type(mth) is not types.MethodType:\n continue\n d = mth.im_func.func_defaults\n if d is not None:\n mthlevel = d[0]\n else:\n mthlevel = 1\n if level>=mthlevel:\n if mthname not in names:\n names.append(mthname)\n for base in clsobj.__bases__:\n for n in self._get_method_names(base,level):\n if n not in names:\n names.append(n)\n return names\n\n def _get_module_tests(self,module,level):\n mstr = self._module_str\n d,f = os.path.split(module.__file__)\n\n short_module_name = os.path.splitext(os.path.basename(f))[0]\n if short_module_name=='__init__':\n short_module_name = module.__name__.split('.')[-1]\n\n test_dir = os.path.join(d,'tests')\n test_file = os.path.join(test_dir,'test_'+short_module_name+'.py')\n\n local_test_dir = os.path.join(os.getcwd(),'tests')\n local_test_file = os.path.join(local_test_dir,\n 'test_'+short_module_name+'.py')\n if os.path.basename(os.path.dirname(local_test_dir)) \\\n == os.path.basename(os.path.dirname(test_dir)) \\\n and os.path.isfile(local_test_file):\n test_file = local_test_file\n\n if not os.path.isfile(test_file):\n if short_module_name[:5]=='info_' \\\n and short_module_name[5:]==module.__name__.split('.')[-2]:\n return []\n if short_module_name in ['__cvs_version__','__svn_version__']:\n return []\n if short_module_name[-8:]=='_version' \\\n and short_module_name[:-8]==module.__name__.split('.')[-2]:\n return []\n print ' !! No test file %r found for %s' \\\n % (os.path.basename(test_file), mstr(module))\n return []\n\n try:\n if sys.version[:3]=='2.1':\n # Workaround for Python 2.1 .pyc file generator bug\n import random\n pref = '-nopyc'+`random.randint(1,100)`\n else:\n pref = ''\n f = open(test_file,'r')\n test_module = imp.load_module(\\\n module.__name__+'.test_'+short_module_name+pref,\n f, test_file+pref,('.py', 'r', 1))\n f.close()\n if sys.version[:3]=='2.1' and os.path.isfile(test_file+pref+'c'):\n os.remove(test_file+pref+'c')\n except:\n print ' !! FAILURE importing tests for ', mstr(module)\n print ' ',\n output_exception()\n return []\n return self._get_suite_list(test_module, level, module.__name__)\n\n def _get_suite_list(self, test_module, level, module_name='__main__'):\n mstr = self._module_str\n if hasattr(test_module,'test_suite'):\n # Using old styled test suite\n try:\n total_suite = test_module.test_suite(level)\n return total_suite._tests\n except:\n print ' !! FAILURE building tests for ', mstr(test_module)\n print ' ',\n output_exception()\n return []\n suite_list = []\n for name in dir(test_module):\n obj = getattr(test_module, name)\n if type(obj) is not type(unittest.TestCase) \\\n or not issubclass(obj, unittest.TestCase) \\\n or obj.__name__[:4] != 'test':\n continue\n suite_list.extend(map(obj,self._get_method_names(obj,level)))\n print ' Found',len(suite_list),'tests for',module_name\n return suite_list\n\n def _touch_ppimported(self, module):\n from scipy_base.ppimport import _ModuleLoader\n if os.path.isdir(os.path.join(os.path.dirname(module.__file__),'tests')):\n # only touching those modules that have tests/ directory\n try: module._pliuh_plauh\n except AttributeError: pass\n for name in dir(module):\n obj = getattr(module,name)\n if isinstance(obj,_ModuleLoader) \\\n and not hasattr(obj,'_ppimport_module') \\\n and not hasattr(obj,'_ppimport_exc_info'):\n self._touch_ppimported(obj)\n\n def test(self,level=1,verbosity=1):\n \"\"\" Run Scipy module test suite with level and verbosity.\n \"\"\"\n if type(self.package) is type(''):\n exec 'import %s as this_package' % (self.package)\n else:\n this_package = self.package\n\n self._touch_ppimported(this_package)\n\n package_name = this_package.__name__\n\n suites = []\n for name, module in sys.modules.items():\n if package_name != name[:len(package_name)] \\\n or module is None \\\n or os.path.basename(os.path.dirname(module.__file__))=='tests':\n continue\n suites.extend(self._get_module_tests(module, level))\n\n suites.extend(self._get_suite_list(sys.modules[package_name], level))\n\n all_tests = unittest.TestSuite(suites)\n runner = unittest.TextTestRunner(verbosity=verbosity)\n runner.run(all_tests)\n return runner\n\n def run(self):\n \"\"\" Run Scipy module test suite with level and verbosity\n taken from sys.argv. Requires optparse module.\n \"\"\"\n try:\n from optparse import OptionParser\n except ImportError:\n print 'Failed to import optparse module, ignoring.'\n return self.test()\n usage = r'usage: %prog [-v ] [-l ]'\n parser = OptionParser(usage)\n parser.add_option(\"-v\", \"--verbosity\",\n action=\"store\",\n dest=\"verbosity\",\n default=1,\n type='int')\n parser.add_option(\"-l\", \"--level\",\n action=\"store\",\n dest=\"level\",\n default=1,\n type='int')\n (options, args) = parser.parse_args()\n self.test(options.level,options.verbosity)\n\n#------------\n \ndef remove_ignored_patterns(files,pattern):\n from fnmatch import fnmatch\n good_files = []\n for file in files:\n if not fnmatch(file,pattern):\n good_files.append(file)\n return good_files\n\ndef remove_ignored_files(original,ignored_files,cur_dir):\n \"\"\" This is actually expanded to do pattern matching.\n\n \"\"\"\n if not ignored_files: ignored_files = []\n ignored_modules = map(lambda x: x+'.py',ignored_files)\n ignored_packages = ignored_files[:]\n # always ignore setup.py and __init__.py files\n ignored_files = ['setup.py','setup_*.py','__init__.py']\n ignored_files += ignored_modules + ignored_packages\n ignored_files = map(lambda x,cur_dir=cur_dir: os.path.join(cur_dir,x),\n ignored_files)\n #print 'ignored:', ignored_files\n #good_files = filter(lambda x,ignored = ignored_files: x not in ignored,\n # original)\n good_files = original\n for pattern in ignored_files:\n good_files = remove_ignored_patterns(good_files,pattern)\n\n return good_files\n\n__all__.append('harvest_modules')\ndef harvest_modules(package,ignore=None):\n \"\"\"* Retreive a list of all modules that live within a package.\n\n Only retreive files that are immediate children of the\n package -- do not recurse through child packages or\n directories. The returned list contains actual modules, not\n just their names.\n *\"\"\"\n d,f = os.path.split(package.__file__)\n\n # go through the directory and import every py file there.\n common_dir = os.path.join(d,'*.py')\n py_files = glob.glob(common_dir)\n #py_files.remove(os.path.join(d,'__init__.py'))\n #py_files.remove(os.path.join(d,'setup.py'))\n\n py_files = remove_ignored_files(py_files,ignore,d)\n #print 'py_files:', py_files\n try:\n prefix = package.__name__\n except:\n prefix = ''\n\n all_modules = []\n for file in py_files:\n d,f = os.path.split(file)\n base,ext = os.path.splitext(f)\n mod = prefix + '.' + base\n #print 'module: import ' + mod\n try:\n exec ('import ' + mod)\n all_modules.append(eval(mod))\n except:\n print 'FAILURE to import ' + mod\n output_exception()\n\n return all_modules\n\n__all__.append('harvest_packages')\ndef harvest_packages(package,ignore = None):\n \"\"\" Retreive a list of all sub-packages that live within a package.\n\n Only retreive packages that are immediate children of this\n package -- do not recurse through child packages or\n directories. The returned list contains actual package objects, not\n just their names.\n \"\"\"\n join = os.path.join\n\n d,f = os.path.split(package.__file__)\n\n common_dir = os.path.abspath(d)\n all_files = os.listdir(d)\n\n all_files = remove_ignored_files(all_files,ignore,'')\n #print 'all_files:', all_files\n try:\n prefix = package.__name__\n except:\n prefix = ''\n all_packages = []\n for directory in all_files:\n path = join(common_dir,directory)\n if os.path.isdir(path) and \\\n os.path.exists(join(path,'__init__.py')):\n sub_package = prefix + '.' + directory\n #print 'sub-package import ' + sub_package\n try:\n exec ('import ' + sub_package)\n all_packages.append(eval(sub_package))\n except:\n print 'FAILURE to import ' + sub_package\n output_exception()\n return all_packages\n\n__all__.append('harvest_modules_and_packages')\ndef harvest_modules_and_packages(package,ignore=None):\n \"\"\" Retreive list of all packages and modules that live within a package.\n\n See harvest_packages() and harvest_modules()\n \"\"\"\n all = harvest_modules(package,ignore) + harvest_packages(package,ignore)\n return all\n\n__all__.append('harvest_test_suites')\ndef harvest_test_suites(package,ignore = None,level=10):\n \"\"\"\n package -- the module to test. This is an actual module object\n (not a string)\n ignore -- a list of module names to omit from the tests\n level -- a value between 1 and 10. 1 will run the minimum number\n of tests. This is a fast \"smoke test\". Tests that take\n longer to run should have higher numbers ranging up to 10.\n \"\"\"\n suites=[]\n test_modules = harvest_modules_and_packages(package,ignore)\n #for i in test_modules:\n # print i.__name__\n for module in test_modules:\n if hasattr(module,'test_suite'):\n try:\n suite = module.test_suite(level=level)\n if suite:\n suites.append(suite)\n else:\n print \" !! FAILURE without error - shouldn't happen\",\n print module.__name__\n except:\n print ' !! FAILURE building test for ', module.__name__\n print ' ',\n output_exception()\n else:\n try:\n print 'No test suite found for ', module.__name__\n except AttributeError:\n # __version__.py getting replaced by a string throws a kink\n # in checking for modules, so we think is a module has\n # actually been overwritten\n print 'No test suite found for ', str(module)\n total_suite = unittest.TestSuite(suites)\n return total_suite\n\n__all__.append('module_test')\ndef module_test(mod_name,mod_file,level=10):\n \"\"\"*\n\n *\"\"\"\n #print 'testing', mod_name\n d,f = os.path.split(mod_file)\n\n # insert the tests directory to the python path\n test_dir = os.path.join(d,'tests')\n sys.path.insert(0,test_dir)\n\n # call the \"test_xxx.test()\" function for the appropriate\n # module.\n\n # This should deal with package naming issues correctly\n short_mod_name = string.split(mod_name,'.')[-1]\n test_module = 'test_' + short_mod_name\n test_string = 'import %s;reload(%s);%s.test(%d)' % \\\n ((test_module,)*3 + (level,))\n\n # This would be better cause it forces a reload of the orginal\n # module. It doesn't behave with packages however.\n #test_string = 'reload(%s);import %s;reload(%s);%s.test(%d)' % \\\n # ((mod_name,) + (test_module,)*3)\n exec(test_string)\n\n # remove test directory from python path.\n sys.path = sys.path[1:]\n\n__all__.append('module_test_suite')\ndef module_test_suite(mod_name,mod_file,level=10):\n #try:\n print ' creating test suite for:', mod_name\n d,f = os.path.split(mod_file)\n\n # insert the tests directory to the python path\n test_dir = os.path.join(d,'tests')\n sys.path.insert(0,test_dir)\n\n # call the \"test_xxx.test()\" function for the appropriate\n # module.\n\n # This should deal with package naming issues correctly\n short_mod_name = string.split(mod_name,'.')[-1]\n test_module = 'test_' + short_mod_name\n test_string = 'import %s;reload(%s);suite = %s.test_suite(%d)' % \\\n ((test_module,)*3+(level,))\n #print test_string\n exec(test_string)\n\n # remove test directory from python path.\n sys.path = sys.path[1:]\n return suite\n #except:\n # print ' !! FAILURE loading test suite from', test_module, ':'\n # print ' ',\n # output_exception()\n\n\n# Utility function to facilitate testing.\n\n__all__.append('assert_equal')\ndef assert_equal(actual,desired,err_msg='',verbose=1):\n \"\"\" Raise an assertion if two items are not\n equal. I think this should be part of unittest.py\n \"\"\"\n msg = '\\nItems are not equal:\\n' + err_msg\n try:\n if ( verbose and len(repr(desired)) < 100 and len(repr(actual)) ):\n msg = msg \\\n + 'DESIRED: ' + repr(desired) \\\n + '\\nACTUAL: ' + repr(actual)\n except:\n msg = msg \\\n + 'DESIRED: ' + repr(desired) \\\n + '\\nACTUAL: ' + repr(actual)\n assert desired == actual, msg\n\n__all__.append('assert_almost_equal')\ndef assert_almost_equal(actual,desired,decimal=7,err_msg='',verbose=1):\n \"\"\" Raise an assertion if two items are not\n equal. I think this should be part of unittest.py\n \"\"\"\n msg = '\\nItems are not equal:\\n' + err_msg\n try:\n if ( verbose and len(repr(desired)) < 100 and len(repr(actual)) ):\n msg = msg \\\n + 'DESIRED: ' + repr(desired) \\\n + '\\nACTUAL: ' + repr(actual)\n except:\n msg = msg \\\n + 'DESIRED: ' + repr(desired) \\\n + '\\nACTUAL: ' + repr(actual)\n assert round(abs(desired - actual),decimal) == 0, msg\n\n__all__.append('assert_approx_equal')\ndef assert_approx_equal(actual,desired,significant=7,err_msg='',verbose=1):\n \"\"\" Raise an assertion if two items are not\n equal. I think this should be part of unittest.py\n Approximately equal is defined as the number of significant digits\n correct\n \"\"\"\n msg = '\\nItems are not equal to %d significant digits:\\n' % significant\n msg += err_msg\n actual, desired = map(float, (actual, desired))\n # Normalized the numbers to be in range (-10.0,10.0)\n scale = pow(10,math.floor(math.log10(0.5*(abs(desired)+abs(actual)))))\n try:\n sc_desired = desired/scale\n except ZeroDivisionError:\n sc_desired = 0.0\n try:\n sc_actual = actual/scale\n except ZeroDivisionError:\n sc_actual = 0.0\n try:\n if ( verbose and len(repr(desired)) < 100 and len(repr(actual)) ):\n msg = msg \\\n + 'DESIRED: ' + repr(desired) \\\n + '\\nACTUAL: ' + repr(actual)\n except:\n msg = msg \\\n + 'DESIRED: ' + repr(desired) \\\n + '\\nACTUAL: ' + repr(actual)\n assert math.fabs(sc_desired - sc_actual) < pow(10.,-1*significant), msg\n\n\n__all__.append('assert_array_equal')\ndef assert_array_equal(x,y,err_msg=''):\n x,y = asarray(x), asarray(y)\n msg = '\\nArrays are not equal'\n try:\n assert 0 in [len(shape(x)),len(shape(y))] \\\n or (len(shape(x))==len(shape(y)) and \\\n alltrue(equal(shape(x),shape(y)))),\\\n msg + ' (shapes %s, %s mismatch):\\n\\t' \\\n % (shape(x),shape(y)) + err_msg\n reduced = ravel(equal(x,y))\n cond = alltrue(reduced)\n if not cond:\n s1 = array2string(x,precision=16)\n s2 = array2string(y,precision=16)\n if len(s1)>120: s1 = s1[:120] + '...'\n if len(s2)>120: s2 = s2[:120] + '...'\n match = 100-100.0*reduced.tolist().count(1)/len(reduced)\n msg = msg + ' (mismatch %s%%):\\n\\tArray 1: %s\\n\\tArray 2: %s' % (match,s1,s2)\n assert cond,\\\n msg + '\\n\\t' + err_msg\n except ValueError:\n raise ValueError, msg\n\n__all__.append('assert_array_almost_equal')\ndef assert_array_almost_equal(x,y,decimal=6,err_msg=''):\n x = asarray(x)\n y = asarray(y)\n msg = '\\nArrays are not almost equal'\n try:\n cond = alltrue(equal(shape(x),shape(y)))\n if not cond:\n msg = msg + ' (shapes mismatch):\\n\\t'\\\n 'Shape of array 1: %s\\n\\tShape of array 2: %s' % (shape(x),shape(y))\n assert cond, msg + '\\n\\t' + err_msg\n reduced = ravel(equal(less_equal(around(abs(x-y),decimal),10.0**(-decimal)),1))\n cond = alltrue(reduced)\n if not cond:\n s1 = array2string(x,precision=decimal+1)\n s2 = array2string(y,precision=decimal+1)\n if len(s1)>120: s1 = s1[:120] + '...'\n if len(s2)>120: s2 = s2[:120] + '...'\n match = 100-100.0*reduced.tolist().count(1)/len(reduced)\n msg = msg + ' (mismatch %s%%):\\n\\tArray 1: %s\\n\\tArray 2: %s' % (match,s1,s2)\n assert cond,\\\n msg + '\\n\\t' + err_msg\n except ValueError:\n print sys.exc_value\n print shape(x),shape(y)\n print x, y\n raise ValueError, 'arrays are not almost equal'\n\n__all__.append('assert_array_less')\ndef assert_array_less(x,y,err_msg=''):\n x,y = asarray(x), asarray(y)\n msg = '\\nArrays are not less-ordered'\n try:\n assert alltrue(equal(shape(x),shape(y))),\\\n msg + ' (shapes mismatch):\\n\\t' + err_msg\n reduced = ravel(less(x,y))\n cond = alltrue(reduced)\n if not cond:\n s1 = array2string(x,precision=16)\n s2 = array2string(y,precision=16)\n if len(s1)>120: s1 = s1[:120] + '...'\n if len(s2)>120: s2 = s2[:120] + '...'\n match = 100-100.0*reduced.tolist().count(1)/len(reduced)\n msg = msg + ' (mismatch %s%%):\\n\\tArray 1: %s\\n\\tArray 2: %s' % (match,s1,s2)\n assert cond,\\\n msg + '\\n\\t' + err_msg\n except ValueError:\n print shape(x),shape(y)\n raise ValueError, 'arrays are not less-ordered'\n\n__all__.append('rand')\ndef rand(*args):\n \"\"\" Returns an array of random numbers with the given shape.\n used for testing\n \"\"\"\n import random\n results = zeros(args,Float64)\n f = results.flat\n for i in range(len(f)):\n f[i] = random.random()\n return results\n\ndef output_exception():\n try:\n type, value, tb = sys.exc_info()\n info = traceback.extract_tb(tb)\n #this is more verbose\n #traceback.print_exc()\n filename, lineno, function, text = info[-1] # last line only\n print \"%s:%d: %s: %s (in %s)\" %\\\n (filename, lineno, type.__name__, str(value), function)\n finally:\n type = value = tb = None # clean up\n\ntry:\n import scipy_base.fastumath as math\nexcept ImportError,msg:\n print msg\n import math\n", "methods": [ { "name": "set_package_path", "long_name": "set_package_path( level = 1 )", "filename": "testing.py", "nloc": 15, "complexity": 4, "token_count": 146, "parameters": [ "level" ], "start_line": 51, "end_line": 82, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 32, "top_nesting_level": 0 }, { "name": "set_local_path", "long_name": "set_local_path( reldir = '' , level = 1 )", "filename": "testing.py", "nloc": 11, "complexity": 3, "token_count": 97, "parameters": [ "reldir", "level" ], "start_line": 85, "end_line": 101, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 17, "top_nesting_level": 0 }, { "name": "restore_path", "long_name": "restore_path( )", "filename": "testing.py", "nloc": 4, "complexity": 2, "token_count": 25, "parameters": [], "start_line": 104, "end_line": 107, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 4, "top_nesting_level": 0 }, { "name": "jiffies", "long_name": "jiffies( _proc_pid_stat = '/proc/%s/stat' % ( os . getpid ( )", "filename": "testing.py", "nloc": 2, "complexity": 1, "token_count": 23, "parameters": [ "_proc_pid_stat" ], "start_line": 111, "end_line": 112, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 2, "top_nesting_level": 1 }, { "name": "memusage", "long_name": "memusage( _proc_pid_stat = '/proc/%s/stat' % ( os . getpid ( )", "filename": "testing.py", "nloc": 10, "complexity": 2, "token_count": 54, "parameters": [ "_proc_pid_stat" ], "start_line": 123, "end_line": 132, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 10, "top_nesting_level": 1 }, { "name": "jiffies", "long_name": "jiffies( _load_time = time . time ( )", "filename": "testing.py", "nloc": 4, "complexity": 1, "token_count": 27, "parameters": [ "_load_time" ], "start_line": 137, "end_line": 140, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 4, "top_nesting_level": 1 }, { "name": "memusage", "long_name": "memusage( )", "filename": "testing.py", "nloc": 2, "complexity": 1, "token_count": 6, "parameters": [], "start_line": 142, "end_line": 144, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 3, "top_nesting_level": 1 }, { "name": "measure", "long_name": "measure( self , code_str , times = 1 )", "filename": "testing.py", "nloc": 13, "complexity": 2, "token_count": 82, "parameters": [ "self", "code_str", "times" ], "start_line": 149, "end_line": 164, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 16, "top_nesting_level": 1 }, { "name": "__call__", "long_name": "__call__( self , result = None )", "filename": "testing.py", "nloc": 34, "complexity": 8, "token_count": 321, "parameters": [ "self", "result" ], "start_line": 166, "end_line": 200, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 35, "top_nesting_level": 1 }, { "name": "__init__", "long_name": "__init__( self )", "filename": "testing.py", "nloc": 2, "complexity": 1, "token_count": 11, "parameters": [ "self" ], "start_line": 203, "end_line": 204, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 2, "top_nesting_level": 1 }, { "name": "write", "long_name": "write( self , message )", "filename": "testing.py", "nloc": 2, "complexity": 1, "token_count": 15, "parameters": [ "self", "message" ], "start_line": 205, "end_line": 206, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 2, "top_nesting_level": 1 }, { "name": "writeln", "long_name": "writeln( self , message )", "filename": "testing.py", "nloc": 2, "complexity": 1, "token_count": 17, "parameters": [ "self", "message" ], "start_line": 207, "end_line": 208, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 2, "top_nesting_level": 1 }, { "name": "_get_all_method_names", "long_name": "_get_all_method_names( cls )", "filename": "testing.py", "nloc": 8, "complexity": 5, "token_count": 56, "parameters": [ "cls" ], "start_line": 220, "end_line": 227, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 8, "top_nesting_level": 0 }, { "name": "__init__", "long_name": "__init__( self , package = '__main__' )", "filename": "testing.py", "nloc": 2, "complexity": 1, "token_count": 14, "parameters": [ "self", "package" ], "start_line": 251, "end_line": 252, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 2, "top_nesting_level": 1 }, { "name": "_module_str", "long_name": "_module_str( self , module )", "filename": "testing.py", "nloc": 5, "complexity": 2, "token_count": 43, "parameters": [ "self", "module" ], "start_line": 254, "end_line": 258, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 5, "top_nesting_level": 1 }, { "name": "_get_method_names", "long_name": "_get_method_names( self , clsobj , level )", "filename": "testing.py", "nloc": 22, "complexity": 11, "token_count": 142, "parameters": [ "self", "clsobj", "level" ], "start_line": 260, "end_line": 281, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 22, "top_nesting_level": 1 }, { "name": "_get_module_tests", "long_name": "_get_module_tests( self , module , level )", "filename": "testing.py", "nloc": 46, "complexity": 14, "token_count": 428, "parameters": [ "self", "module", "level" ], "start_line": 283, "end_line": 334, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 52, "top_nesting_level": 1 }, { "name": "_get_suite_list", "long_name": "_get_suite_list( self , test_module , level , module_name = '__main__' )", "filename": "testing.py", "nloc": 21, "complexity": 7, "token_count": 146, "parameters": [ "self", "test_module", "level", "module_name" ], "start_line": 336, "end_line": 357, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 22, "top_nesting_level": 1 }, { "name": "_touch_ppimported", "long_name": "_touch_ppimported( self , module )", "filename": "testing.py", "nloc": 11, "complexity": 7, "token_count": 98, "parameters": [ "self", "module" ], "start_line": 359, "end_line": 370, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 12, "top_nesting_level": 1 }, { "name": "test", "long_name": "test( self , level = 1 , verbosity = 1 )", "filename": "testing.py", "nloc": 19, "complexity": 6, "token_count": 166, "parameters": [ "self", "level", "verbosity" ], "start_line": 372, "end_line": 397, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 26, "top_nesting_level": 1 }, { "name": "run", "long_name": "run( self )", "filename": "testing.py", "nloc": 20, "complexity": 2, "token_count": 104, "parameters": [ "self" ], "start_line": 399, "end_line": 421, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 23, "top_nesting_level": 1 }, { "name": "remove_ignored_patterns", "long_name": "remove_ignored_patterns( files , pattern )", "filename": "testing.py", "nloc": 7, "complexity": 3, "token_count": 37, "parameters": [ "files", "pattern" ], "start_line": 425, "end_line": 431, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 7, "top_nesting_level": 0 }, { "name": "remove_ignored_files", "long_name": "remove_ignored_files( original , ignored_files , cur_dir )", "filename": "testing.py", "nloc": 12, "complexity": 3, "token_count": 93, "parameters": [ "original", "ignored_files", "cur_dir" ], "start_line": 433, "end_line": 452, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 20, "top_nesting_level": 0 }, { "name": "harvest_modules", "long_name": "harvest_modules( package , ignore = None )", "filename": "testing.py", "nloc": 21, "complexity": 4, "token_count": 134, "parameters": [ "package", "ignore" ], "start_line": 455, "end_line": 491, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 37, "top_nesting_level": 0 }, { "name": "harvest_packages", "long_name": "harvest_packages( package , ignore = None )", "filename": "testing.py", "nloc": 23, "complexity": 6, "token_count": 148, "parameters": [ "package", "ignore" ], "start_line": 494, "end_line": 528, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 35, "top_nesting_level": 0 }, { "name": "harvest_modules_and_packages", "long_name": "harvest_modules_and_packages( package , ignore = None )", "filename": "testing.py", "nloc": 3, "complexity": 1, "token_count": 27, "parameters": [ "package", "ignore" ], "start_line": 531, "end_line": 537, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 7, "top_nesting_level": 0 }, { "name": "harvest_test_suites", "long_name": "harvest_test_suites( package , ignore = None , level = 10 )", "filename": "testing.py", "nloc": 23, "complexity": 6, "token_count": 113, "parameters": [ "package", "ignore", "level" ], "start_line": 540, "end_line": 575, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 36, "top_nesting_level": 0 }, { "name": "module_test", "long_name": "module_test( mod_name , mod_file , level = 10 )", "filename": "testing.py", "nloc": 10, "complexity": 1, "token_count": 98, "parameters": [ "mod_name", "mod_file", "level" ], "start_line": 578, "end_line": 605, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 28, "top_nesting_level": 0 }, { "name": "module_test_suite", "long_name": "module_test_suite( mod_name , mod_file , level = 10 )", "filename": "testing.py", "nloc": 12, "complexity": 1, "token_count": 103, "parameters": [ "mod_name", "mod_file", "level" ], "start_line": 608, "end_line": 630, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 23, "top_nesting_level": 0 }, { "name": "assert_equal", "long_name": "assert_equal( actual , desired , err_msg = '' , verbose = 1 )", "filename": "testing.py", "nloc": 12, "complexity": 5, "token_count": 92, "parameters": [ "actual", "desired", "err_msg", "verbose" ], "start_line": 640, "end_line": 654, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 15, "top_nesting_level": 0 }, { "name": "assert_almost_equal", "long_name": "assert_almost_equal( actual , desired , decimal = 7 , err_msg = '' , verbose = 1 )", "filename": "testing.py", "nloc": 12, "complexity": 5, "token_count": 106, "parameters": [ "actual", "desired", "decimal", "err_msg", "verbose" ], "start_line": 657, "end_line": 671, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 15, "top_nesting_level": 0 }, { "name": "assert_approx_equal", "long_name": "assert_approx_equal( actual , desired , significant = 7 , err_msg = '' , verbose = 1 )", "filename": "testing.py", "nloc": 23, "complexity": 7, "token_count": 191, "parameters": [ "actual", "desired", "significant", "err_msg", "verbose" ], "start_line": 674, "end_line": 702, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 29, "top_nesting_level": 0 }, { "name": "assert_array_equal", "long_name": "assert_array_equal( x , y , err_msg = '' )", "filename": "testing.py", "nloc": 22, "complexity": 7, "token_count": 232, "parameters": [ "x", "y", "err_msg" ], "start_line": 706, "end_line": 727, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 22, "top_nesting_level": 0 }, { "name": "assert_array_almost_equal", "long_name": "assert_array_almost_equal( x , y , decimal = 6 , err_msg = '' )", "filename": "testing.py", "nloc": 26, "complexity": 6, "token_count": 251, "parameters": [ "x", "y", "decimal", "err_msg" ], "start_line": 730, "end_line": 755, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 26, "top_nesting_level": 0 }, { "name": "assert_array_less", "long_name": "assert_array_less( x , y , err_msg = '' )", "filename": "testing.py", "nloc": 20, "complexity": 5, "token_count": 189, "parameters": [ "x", "y", "err_msg" ], "start_line": 758, "end_line": 777, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 20, "top_nesting_level": 0 }, { "name": "rand", "long_name": "rand( * args )", "filename": "testing.py", "nloc": 7, "complexity": 2, "token_count": 45, "parameters": [ "args" ], "start_line": 780, "end_line": 789, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 10, "top_nesting_level": 0 }, { "name": "output_exception", "long_name": "output_exception( )", "filename": "testing.py", "nloc": 9, "complexity": 2, "token_count": 67, "parameters": [], "start_line": 791, "end_line": 801, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 11, "top_nesting_level": 0 } ], "methods_before": [ { "name": "set_package_path", "long_name": "set_package_path( level = 1 )", "filename": "testing.py", "nloc": 15, "complexity": 4, "token_count": 146, "parameters": [ "level" ], "start_line": 49, "end_line": 80, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 32, "top_nesting_level": 0 }, { "name": "set_local_path", "long_name": "set_local_path( reldir = '' , level = 1 )", "filename": "testing.py", "nloc": 11, "complexity": 3, "token_count": 97, "parameters": [ "reldir", "level" ], "start_line": 83, "end_line": 99, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 17, "top_nesting_level": 0 }, { "name": "restore_path", "long_name": "restore_path( )", "filename": "testing.py", "nloc": 4, "complexity": 2, "token_count": 25, "parameters": [], "start_line": 102, "end_line": 105, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 4, "top_nesting_level": 0 }, { "name": "jiffies", "long_name": "jiffies( _proc_pid_stat = '/proc/%s/stat' % ( os . getpid ( )", "filename": "testing.py", "nloc": 2, "complexity": 1, "token_count": 23, "parameters": [ "_proc_pid_stat" ], "start_line": 109, "end_line": 110, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 2, "top_nesting_level": 1 }, { "name": "memusage", "long_name": "memusage( _proc_pid_stat = '/proc/%s/stat' % ( os . getpid ( )", "filename": "testing.py", "nloc": 10, "complexity": 2, "token_count": 54, "parameters": [ "_proc_pid_stat" ], "start_line": 121, "end_line": 130, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 10, "top_nesting_level": 1 }, { "name": "jiffies", "long_name": "jiffies( _load_time = time . time ( )", "filename": "testing.py", "nloc": 4, "complexity": 1, "token_count": 27, "parameters": [ "_load_time" ], "start_line": 135, "end_line": 138, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 4, "top_nesting_level": 1 }, { "name": "memusage", "long_name": "memusage( )", "filename": "testing.py", "nloc": 2, "complexity": 1, "token_count": 6, "parameters": [], "start_line": 140, "end_line": 142, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 3, "top_nesting_level": 1 }, { "name": "measure", "long_name": "measure( self , code_str , times = 1 )", "filename": "testing.py", "nloc": 13, "complexity": 2, "token_count": 82, "parameters": [ "self", "code_str", "times" ], "start_line": 147, "end_line": 162, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 16, "top_nesting_level": 1 }, { "name": "__call__", "long_name": "__call__( self , result = None )", "filename": "testing.py", "nloc": 19, "complexity": 5, "token_count": 175, "parameters": [ "self", "result" ], "start_line": 164, "end_line": 183, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 20, "top_nesting_level": 1 }, { "name": "__init__", "long_name": "__init__( self )", "filename": "testing.py", "nloc": 2, "complexity": 1, "token_count": 11, "parameters": [ "self" ], "start_line": 186, "end_line": 187, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 2, "top_nesting_level": 1 }, { "name": "write", "long_name": "write( self , message )", "filename": "testing.py", "nloc": 2, "complexity": 1, "token_count": 15, "parameters": [ "self", "message" ], "start_line": 188, "end_line": 189, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 2, "top_nesting_level": 1 }, { "name": "writeln", "long_name": "writeln( self , message )", "filename": "testing.py", "nloc": 2, "complexity": 1, "token_count": 17, "parameters": [ "self", "message" ], "start_line": 190, "end_line": 191, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 2, "top_nesting_level": 1 }, { "name": "_get_all_method_names", "long_name": "_get_all_method_names( cls )", "filename": "testing.py", "nloc": 8, "complexity": 5, "token_count": 56, "parameters": [ "cls" ], "start_line": 199, "end_line": 206, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 8, "top_nesting_level": 0 }, { "name": "__init__", "long_name": "__init__( self , package = '__main__' )", "filename": "testing.py", "nloc": 2, "complexity": 1, "token_count": 14, "parameters": [ "self", "package" ], "start_line": 230, "end_line": 231, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 2, "top_nesting_level": 1 }, { "name": "_module_str", "long_name": "_module_str( self , module )", "filename": "testing.py", "nloc": 5, "complexity": 2, "token_count": 43, "parameters": [ "self", "module" ], "start_line": 233, "end_line": 237, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 5, "top_nesting_level": 1 }, { "name": "_get_method_names", "long_name": "_get_method_names( self , clsobj , level )", "filename": "testing.py", "nloc": 22, "complexity": 11, "token_count": 142, "parameters": [ "self", "clsobj", "level" ], "start_line": 239, "end_line": 260, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 22, "top_nesting_level": 1 }, { "name": "_get_module_tests", "long_name": "_get_module_tests( self , module , level )", "filename": "testing.py", "nloc": 46, "complexity": 14, "token_count": 428, "parameters": [ "self", "module", "level" ], "start_line": 262, "end_line": 313, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 52, "top_nesting_level": 1 }, { "name": "_get_suite_list", "long_name": "_get_suite_list( self , test_module , level , module_name = '__main__' )", "filename": "testing.py", "nloc": 21, "complexity": 7, "token_count": 146, "parameters": [ "self", "test_module", "level", "module_name" ], "start_line": 315, "end_line": 336, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 22, "top_nesting_level": 1 }, { "name": "_touch_ppimported", "long_name": "_touch_ppimported( self , module )", "filename": "testing.py", "nloc": 11, "complexity": 7, "token_count": 98, "parameters": [ "self", "module" ], "start_line": 338, "end_line": 349, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 12, "top_nesting_level": 1 }, { "name": "test", "long_name": "test( self , level = 1 , verbosity = 1 )", "filename": "testing.py", "nloc": 19, "complexity": 6, "token_count": 166, "parameters": [ "self", "level", "verbosity" ], "start_line": 351, "end_line": 376, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 26, "top_nesting_level": 1 }, { "name": "run", "long_name": "run( self )", "filename": "testing.py", "nloc": 20, "complexity": 2, "token_count": 104, "parameters": [ "self" ], "start_line": 378, "end_line": 400, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 23, "top_nesting_level": 1 }, { "name": "remove_ignored_patterns", "long_name": "remove_ignored_patterns( files , pattern )", "filename": "testing.py", "nloc": 7, "complexity": 3, "token_count": 37, "parameters": [ "files", "pattern" ], "start_line": 404, "end_line": 410, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 7, "top_nesting_level": 0 }, { "name": "remove_ignored_files", "long_name": "remove_ignored_files( original , ignored_files , cur_dir )", "filename": "testing.py", "nloc": 12, "complexity": 3, "token_count": 93, "parameters": [ "original", "ignored_files", "cur_dir" ], "start_line": 412, "end_line": 431, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 20, "top_nesting_level": 0 }, { "name": "harvest_modules", "long_name": "harvest_modules( package , ignore = None )", "filename": "testing.py", "nloc": 21, "complexity": 4, "token_count": 134, "parameters": [ "package", "ignore" ], "start_line": 434, "end_line": 470, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 37, "top_nesting_level": 0 }, { "name": "harvest_packages", "long_name": "harvest_packages( package , ignore = None )", "filename": "testing.py", "nloc": 23, "complexity": 6, "token_count": 148, "parameters": [ "package", "ignore" ], "start_line": 473, "end_line": 507, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 35, "top_nesting_level": 0 }, { "name": "harvest_modules_and_packages", "long_name": "harvest_modules_and_packages( package , ignore = None )", "filename": "testing.py", "nloc": 3, "complexity": 1, "token_count": 27, "parameters": [ "package", "ignore" ], "start_line": 510, "end_line": 516, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 7, "top_nesting_level": 0 }, { "name": "harvest_test_suites", "long_name": "harvest_test_suites( package , ignore = None , level = 10 )", "filename": "testing.py", "nloc": 23, "complexity": 6, "token_count": 113, "parameters": [ "package", "ignore", "level" ], "start_line": 519, "end_line": 554, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 36, "top_nesting_level": 0 }, { "name": "module_test", "long_name": "module_test( mod_name , mod_file , level = 10 )", "filename": "testing.py", "nloc": 10, "complexity": 1, "token_count": 98, "parameters": [ "mod_name", "mod_file", "level" ], "start_line": 557, "end_line": 584, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 28, "top_nesting_level": 0 }, { "name": "module_test_suite", "long_name": "module_test_suite( mod_name , mod_file , level = 10 )", "filename": "testing.py", "nloc": 12, "complexity": 1, "token_count": 103, "parameters": [ "mod_name", "mod_file", "level" ], "start_line": 587, "end_line": 609, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 23, "top_nesting_level": 0 }, { "name": "assert_equal", "long_name": "assert_equal( actual , desired , err_msg = '' , verbose = 1 )", "filename": "testing.py", "nloc": 12, "complexity": 5, "token_count": 92, "parameters": [ "actual", "desired", "err_msg", "verbose" ], "start_line": 619, "end_line": 633, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 15, "top_nesting_level": 0 }, { "name": "assert_almost_equal", "long_name": "assert_almost_equal( actual , desired , decimal = 7 , err_msg = '' , verbose = 1 )", "filename": "testing.py", "nloc": 12, "complexity": 5, "token_count": 106, "parameters": [ "actual", "desired", "decimal", "err_msg", "verbose" ], "start_line": 636, "end_line": 650, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 15, "top_nesting_level": 0 }, { "name": "assert_approx_equal", "long_name": "assert_approx_equal( actual , desired , significant = 7 , err_msg = '' , verbose = 1 )", "filename": "testing.py", "nloc": 23, "complexity": 7, "token_count": 191, "parameters": [ "actual", "desired", "significant", "err_msg", "verbose" ], "start_line": 653, "end_line": 681, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 29, "top_nesting_level": 0 }, { "name": "assert_array_equal", "long_name": "assert_array_equal( x , y , err_msg = '' )", "filename": "testing.py", "nloc": 22, "complexity": 7, "token_count": 232, "parameters": [ "x", "y", "err_msg" ], "start_line": 685, "end_line": 706, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 22, "top_nesting_level": 0 }, { "name": "assert_array_almost_equal", "long_name": "assert_array_almost_equal( x , y , decimal = 6 , err_msg = '' )", "filename": "testing.py", "nloc": 26, "complexity": 6, "token_count": 251, "parameters": [ "x", "y", "decimal", "err_msg" ], "start_line": 709, "end_line": 734, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 26, "top_nesting_level": 0 }, { "name": "assert_array_less", "long_name": "assert_array_less( x , y , err_msg = '' )", "filename": "testing.py", "nloc": 20, "complexity": 5, "token_count": 189, "parameters": [ "x", "y", "err_msg" ], "start_line": 737, "end_line": 756, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 20, "top_nesting_level": 0 }, { "name": "rand", "long_name": "rand( * args )", "filename": "testing.py", "nloc": 7, "complexity": 2, "token_count": 45, "parameters": [ "args" ], "start_line": 759, "end_line": 768, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 10, "top_nesting_level": 0 }, { "name": "output_exception", "long_name": "output_exception( )", "filename": "testing.py", "nloc": 9, "complexity": 2, "token_count": 67, "parameters": [], "start_line": 770, "end_line": 780, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 11, "top_nesting_level": 0 } ], "changed_methods": [ { "name": "__call__", "long_name": "__call__( self , result = None )", "filename": "testing.py", "nloc": 34, "complexity": 8, "token_count": 321, "parameters": [ "self", "result" ], "start_line": 166, "end_line": 200, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 35, "top_nesting_level": 1 } ], "nloc": 601, "complexity": 146, "token_count": 4286, "diff_parsed": { "added": [ " IgnoreException -- raise when checking disabled feature ('ignoring' is displayed)", " HideException -- raise when checking disabled feature (nothing is displayed)", " assert_equal -- assert equality", " assert_almost_equal -- assert equality with decimal tolerance", " assert_approx_equal -- assert equality with significant digits tolerance", " assert_array_equal -- assert arrays equality", " assert_array_almost_equal -- assert arrays equality with decimal tolerance", " assert_array_less -- assert arrays less-ordering", " l = len(result.stream.data)", " if l==1:", " assert result.stream.data[-1]=='E',`result.stream.data`", " result.stream.data[-1] = 'i'", " del result.errors[-1]", " else:", " assert result.stream.data[-1]=='ERROR\\n',`result.stream.data`", " result.stream.data[-1] = 'ignoring\\n'", " del result.errors[-1]", " elif errstr.startswith('HideException:'):", " if l==1:", " assert result.stream.data[-1]=='E',`result.stream.data`", " result.stream.data[-1] = ''", " del result.errors[-1]", " else:", " assert result.stream.data[-1]=='ERROR\\n',`result.stream.data`", " result.stream.data = []", " del result.errors[-1]", "__all__.append('HideException')", "class HideException(Exception):", " \"Hide this exception due to disabled feature\"", "" ], "deleted": [ " assert_equal --", " assert_almost_equal --", " assert_approx_equal --", " assert_array_equal --", " assert_array_almost_equal --", " assert_array_less --", " assert result.stream.data[-1]=='E',`result.stream.data`", " result.stream.data[-1] = 'i'", " del result.errors[-1]" ] } } ] }, { "hash": "b89d967cf6cc65a24695cf0ef60817c638d52f7c", "msg": "Fixed displayed number of tests.", "author": { "name": "Pearu Peterson", "email": "pearu.peterson@gmail.com" }, "committer": { "name": "Pearu Peterson", "email": "pearu.peterson@gmail.com" }, "author_date": "2004-11-29T18:09:51+00:00", "author_timezone": 0, "committer_date": "2004-11-29T18:09:51+00:00", "committer_timezone": 0, "branches": [ "main" ], "in_main_branch": true, "merge": false, "parents": [ "47a598cc76731b33f96aaba91f1f7b94535c7bcc" ], "project_name": "repo_copy", "project_path": "/tmp/tmpqop781_j/repo_copy", "deletions": 5, "insertions": 4, "lines": 9, "files": 1, "dmm_unit_size": 1.0, "dmm_unit_complexity": 1.0, "dmm_unit_interfacing": 0.0, "modified_files": [ { "old_path": "scipy_test/testing.py", "new_path": "scipy_test/testing.py", "filename": "testing.py", "extension": "py", "change_type": "MODIFY", "diff": "@@ -5,7 +5,7 @@\n ScipyTest -- Scipy tests site manager\n ScipyTestCase -- unittest.TestCase with measure method\n IgnoreException -- raise when checking disabled feature ('ignoring' is displayed)\n- HideException -- raise when checking disabled feature (nothing is displayed)\n+ HideException -- raise when checking irrelevant feature (nothing is displayed)\n set_package_path -- prepend package build directory to path\n set_local_path -- prepend local directory (to tests files) to path\n restore_path -- restore path after set_package_path\n@@ -182,20 +182,19 @@ def __call__(self, result=None):\n if l==1:\n assert result.stream.data[-1]=='E',`result.stream.data`\n result.stream.data[-1] = 'i'\n- del result.errors[-1]\n else:\n assert result.stream.data[-1]=='ERROR\\n',`result.stream.data`\n result.stream.data[-1] = 'ignoring\\n'\n- del result.errors[-1]\n+ del result.errors[-1]\n elif errstr.startswith('HideException:'):\n if l==1:\n assert result.stream.data[-1]=='E',`result.stream.data`\n result.stream.data[-1] = ''\n- del result.errors[-1]\n else:\n assert result.stream.data[-1]=='ERROR\\n',`result.stream.data`\n result.stream.data = []\n- del result.errors[-1]\n+ del result.errors[-1]\n+ result.testsRun = result.testsRun - 1\n map(save_stream.write, result.stream.data)\n result.stream = save_stream\n \n", "added_lines": 4, "deleted_lines": 5, "source_code": "\"\"\"\nUnit-testing\n------------\n\n ScipyTest -- Scipy tests site manager\n ScipyTestCase -- unittest.TestCase with measure method\n IgnoreException -- raise when checking disabled feature ('ignoring' is displayed)\n HideException -- raise when checking irrelevant feature (nothing is displayed)\n set_package_path -- prepend package build directory to path\n set_local_path -- prepend local directory (to tests files) to path\n restore_path -- restore path after set_package_path\n\nTiming tools\n------------\n\n jiffies -- return 1/100ths of a second that the current process has used\n memusage -- virtual memory size in bytes of the running python [linux]\n\nUtility functions\n-----------------\n\n assert_equal -- assert equality\n assert_almost_equal -- assert equality with decimal tolerance\n assert_approx_equal -- assert equality with significant digits tolerance\n assert_array_equal -- assert arrays equality\n assert_array_almost_equal -- assert arrays equality with decimal tolerance\n assert_array_less -- assert arrays less-ordering\n rand -- array of random numbers from given shape\n\n\"\"\"\n\n__all__ = []\n\nimport os,sys,time,glob,string,traceback,unittest\nimport types\nimport imp\n\ntry:\n # These are used by Numeric tests.\n # If Numeric and scipy_base are not available, then some of the\n # functions below will not be available.\n from Numeric import alltrue,equal,shape,ravel,around,zeros,Float64,asarray,\\\n less_equal,array2string,less\n # `import scipy_base.fastumath as math` must be at the end of this file.\nexcept ImportError,msg:\n print msg\n\nDEBUG = 0\n\n__all__.append('set_package_path')\ndef set_package_path(level=1):\n \"\"\" Prepend package directory to sys.path.\n\n set_package_path should be called from a test_file.py that\n satisfies the following tree structure:\n\n //test_file.py\n\n Then the first existing path name from the following list\n\n /build/lib.-\n /..\n\n is prepended to sys.path.\n The caller is responsible for removing this path by using\n\n restore_path()\n \"\"\"\n from distutils.util import get_platform\n from scipy_distutils.misc_util import get_frame\n f = get_frame(level)\n if f.f_locals['__name__']=='__main__':\n testfile = sys.argv[0]\n else:\n testfile = f.f_locals['__file__']\n d = os.path.dirname(os.path.dirname(os.path.abspath(testfile)))\n d1 = os.path.join(d,'build','lib.%s-%s'%(get_platform(),sys.version[:3]))\n if not os.path.isdir(d1):\n d1 = os.path.dirname(d)\n if DEBUG:\n print 'Inserting %r to sys.path' % (d1)\n sys.path.insert(0,d1)\n\n__all__.append('set_local_path')\ndef set_local_path(reldir='', level=1):\n \"\"\" Prepend local directory to sys.path.\n\n The caller is responsible for removing this path by using\n\n restore_path()\n \"\"\"\n from scipy_distutils.misc_util import get_frame\n f = get_frame(level)\n if f.f_locals['__name__']=='__main__':\n testfile = sys.argv[0]\n else:\n testfile = f.f_locals['__file__']\n local_path = os.path.join(os.path.dirname(os.path.abspath(testfile)),reldir)\n if DEBUG:\n print 'Inserting %r to sys.path' % (local_path)\n sys.path.insert(0,local_path)\n\n__all__.append('restore_path')\ndef restore_path():\n if DEBUG:\n print 'Removing %r from sys.path' % (sys.path[0])\n del sys.path[0]\n\n__all__.extend(['jiffies','memusage'])\nif sys.platform[:5]=='linux':\n def jiffies(_proc_pid_stat = '/proc/%s/stat'%(os.getpid()),\n _load_time=time.time()):\n \"\"\" Return number of jiffies (1/100ths of a second) that this\n process has been scheduled in user mode. See man 5 proc. \"\"\"\n try:\n f=open(_proc_pid_stat,'r')\n l = f.readline().split(' ')\n f.close()\n return int(l[13])\n except:\n return int(100*(time.time()-_load_time))\n\n def memusage(_proc_pid_stat = '/proc/%s/stat'%(os.getpid())):\n \"\"\" Return virtual memory size in bytes of the running python.\n \"\"\"\n try:\n f=open(_proc_pid_stat,'r')\n l = f.readline().split(' ')\n f.close()\n return int(l[22])\n except:\n return\nelse:\n # os.getpid is not in all platforms available.\n # Using time is safe but inaccurate, especially when process\n # was suspended or sleeping.\n def jiffies(_load_time=time.time()):\n \"\"\" Return number of jiffies (1/100ths of a second) that this\n process has been scheduled in user mode. [Emulation with time.time]. \"\"\"\n return int(100*(time.time()-_load_time))\n\n def memusage():\n \"\"\" Return memory usage of running python. [Not implemented]\"\"\"\n return\n\n__all__.append('ScipyTestCase')\nclass ScipyTestCase (unittest.TestCase):\n\n def measure(self,code_str,times=1):\n \"\"\" Return elapsed time for executing code_str in the\n namespace of the caller for given times.\n \"\"\"\n frame = sys._getframe(1)\n locs,globs = frame.f_locals,frame.f_globals\n code = compile(code_str,\n 'ScipyTestCase runner for '+self.__class__.__name__,\n 'exec')\n i = 0\n elapsed = jiffies()\n while i>> ScipyTest().test(level=1,verbosity=2)\n\n is package name or its module object.\n\n Package is supposed to contain a directory tests/\n with test_*.py files where * refers to the names of submodules.\n\n test_*.py files are supposed to define a classes, derived\n from ScipyTestCase or unittest.TestCase, with methods having\n names starting with test or bench or check.\n\n And that is it! No need to implement test or test_suite functions\n in each .py file.\n\n Also old styled test_suite(level=1) hooks are supported but\n soon to be removed.\n \"\"\"\n def __init__(self, package='__main__'):\n self.package = package\n\n def _module_str(self, module):\n filename = module.__file__[-30:]\n if filename!=module.__file__:\n filename = '...'+filename\n return '' % (`module.__name__`, `filename`)\n\n def _get_method_names(self,clsobj,level):\n names = []\n for mthname in _get_all_method_names(clsobj):\n if mthname[:5] not in ['bench','check'] \\\n and mthname[:4] not in ['test']:\n continue\n mth = getattr(clsobj, mthname)\n if type(mth) is not types.MethodType:\n continue\n d = mth.im_func.func_defaults\n if d is not None:\n mthlevel = d[0]\n else:\n mthlevel = 1\n if level>=mthlevel:\n if mthname not in names:\n names.append(mthname)\n for base in clsobj.__bases__:\n for n in self._get_method_names(base,level):\n if n not in names:\n names.append(n)\n return names\n\n def _get_module_tests(self,module,level):\n mstr = self._module_str\n d,f = os.path.split(module.__file__)\n\n short_module_name = os.path.splitext(os.path.basename(f))[0]\n if short_module_name=='__init__':\n short_module_name = module.__name__.split('.')[-1]\n\n test_dir = os.path.join(d,'tests')\n test_file = os.path.join(test_dir,'test_'+short_module_name+'.py')\n\n local_test_dir = os.path.join(os.getcwd(),'tests')\n local_test_file = os.path.join(local_test_dir,\n 'test_'+short_module_name+'.py')\n if os.path.basename(os.path.dirname(local_test_dir)) \\\n == os.path.basename(os.path.dirname(test_dir)) \\\n and os.path.isfile(local_test_file):\n test_file = local_test_file\n\n if not os.path.isfile(test_file):\n if short_module_name[:5]=='info_' \\\n and short_module_name[5:]==module.__name__.split('.')[-2]:\n return []\n if short_module_name in ['__cvs_version__','__svn_version__']:\n return []\n if short_module_name[-8:]=='_version' \\\n and short_module_name[:-8]==module.__name__.split('.')[-2]:\n return []\n print ' !! No test file %r found for %s' \\\n % (os.path.basename(test_file), mstr(module))\n return []\n\n try:\n if sys.version[:3]=='2.1':\n # Workaround for Python 2.1 .pyc file generator bug\n import random\n pref = '-nopyc'+`random.randint(1,100)`\n else:\n pref = ''\n f = open(test_file,'r')\n test_module = imp.load_module(\\\n module.__name__+'.test_'+short_module_name+pref,\n f, test_file+pref,('.py', 'r', 1))\n f.close()\n if sys.version[:3]=='2.1' and os.path.isfile(test_file+pref+'c'):\n os.remove(test_file+pref+'c')\n except:\n print ' !! FAILURE importing tests for ', mstr(module)\n print ' ',\n output_exception()\n return []\n return self._get_suite_list(test_module, level, module.__name__)\n\n def _get_suite_list(self, test_module, level, module_name='__main__'):\n mstr = self._module_str\n if hasattr(test_module,'test_suite'):\n # Using old styled test suite\n try:\n total_suite = test_module.test_suite(level)\n return total_suite._tests\n except:\n print ' !! FAILURE building tests for ', mstr(test_module)\n print ' ',\n output_exception()\n return []\n suite_list = []\n for name in dir(test_module):\n obj = getattr(test_module, name)\n if type(obj) is not type(unittest.TestCase) \\\n or not issubclass(obj, unittest.TestCase) \\\n or obj.__name__[:4] != 'test':\n continue\n suite_list.extend(map(obj,self._get_method_names(obj,level)))\n print ' Found',len(suite_list),'tests for',module_name\n return suite_list\n\n def _touch_ppimported(self, module):\n from scipy_base.ppimport import _ModuleLoader\n if os.path.isdir(os.path.join(os.path.dirname(module.__file__),'tests')):\n # only touching those modules that have tests/ directory\n try: module._pliuh_plauh\n except AttributeError: pass\n for name in dir(module):\n obj = getattr(module,name)\n if isinstance(obj,_ModuleLoader) \\\n and not hasattr(obj,'_ppimport_module') \\\n and not hasattr(obj,'_ppimport_exc_info'):\n self._touch_ppimported(obj)\n\n def test(self,level=1,verbosity=1):\n \"\"\" Run Scipy module test suite with level and verbosity.\n \"\"\"\n if type(self.package) is type(''):\n exec 'import %s as this_package' % (self.package)\n else:\n this_package = self.package\n\n self._touch_ppimported(this_package)\n\n package_name = this_package.__name__\n\n suites = []\n for name, module in sys.modules.items():\n if package_name != name[:len(package_name)] \\\n or module is None \\\n or os.path.basename(os.path.dirname(module.__file__))=='tests':\n continue\n suites.extend(self._get_module_tests(module, level))\n\n suites.extend(self._get_suite_list(sys.modules[package_name], level))\n\n all_tests = unittest.TestSuite(suites)\n runner = unittest.TextTestRunner(verbosity=verbosity)\n runner.run(all_tests)\n return runner\n\n def run(self):\n \"\"\" Run Scipy module test suite with level and verbosity\n taken from sys.argv. Requires optparse module.\n \"\"\"\n try:\n from optparse import OptionParser\n except ImportError:\n print 'Failed to import optparse module, ignoring.'\n return self.test()\n usage = r'usage: %prog [-v ] [-l ]'\n parser = OptionParser(usage)\n parser.add_option(\"-v\", \"--verbosity\",\n action=\"store\",\n dest=\"verbosity\",\n default=1,\n type='int')\n parser.add_option(\"-l\", \"--level\",\n action=\"store\",\n dest=\"level\",\n default=1,\n type='int')\n (options, args) = parser.parse_args()\n self.test(options.level,options.verbosity)\n\n#------------\n \ndef remove_ignored_patterns(files,pattern):\n from fnmatch import fnmatch\n good_files = []\n for file in files:\n if not fnmatch(file,pattern):\n good_files.append(file)\n return good_files\n\ndef remove_ignored_files(original,ignored_files,cur_dir):\n \"\"\" This is actually expanded to do pattern matching.\n\n \"\"\"\n if not ignored_files: ignored_files = []\n ignored_modules = map(lambda x: x+'.py',ignored_files)\n ignored_packages = ignored_files[:]\n # always ignore setup.py and __init__.py files\n ignored_files = ['setup.py','setup_*.py','__init__.py']\n ignored_files += ignored_modules + ignored_packages\n ignored_files = map(lambda x,cur_dir=cur_dir: os.path.join(cur_dir,x),\n ignored_files)\n #print 'ignored:', ignored_files\n #good_files = filter(lambda x,ignored = ignored_files: x not in ignored,\n # original)\n good_files = original\n for pattern in ignored_files:\n good_files = remove_ignored_patterns(good_files,pattern)\n\n return good_files\n\n__all__.append('harvest_modules')\ndef harvest_modules(package,ignore=None):\n \"\"\"* Retreive a list of all modules that live within a package.\n\n Only retreive files that are immediate children of the\n package -- do not recurse through child packages or\n directories. The returned list contains actual modules, not\n just their names.\n *\"\"\"\n d,f = os.path.split(package.__file__)\n\n # go through the directory and import every py file there.\n common_dir = os.path.join(d,'*.py')\n py_files = glob.glob(common_dir)\n #py_files.remove(os.path.join(d,'__init__.py'))\n #py_files.remove(os.path.join(d,'setup.py'))\n\n py_files = remove_ignored_files(py_files,ignore,d)\n #print 'py_files:', py_files\n try:\n prefix = package.__name__\n except:\n prefix = ''\n\n all_modules = []\n for file in py_files:\n d,f = os.path.split(file)\n base,ext = os.path.splitext(f)\n mod = prefix + '.' + base\n #print 'module: import ' + mod\n try:\n exec ('import ' + mod)\n all_modules.append(eval(mod))\n except:\n print 'FAILURE to import ' + mod\n output_exception()\n\n return all_modules\n\n__all__.append('harvest_packages')\ndef harvest_packages(package,ignore = None):\n \"\"\" Retreive a list of all sub-packages that live within a package.\n\n Only retreive packages that are immediate children of this\n package -- do not recurse through child packages or\n directories. The returned list contains actual package objects, not\n just their names.\n \"\"\"\n join = os.path.join\n\n d,f = os.path.split(package.__file__)\n\n common_dir = os.path.abspath(d)\n all_files = os.listdir(d)\n\n all_files = remove_ignored_files(all_files,ignore,'')\n #print 'all_files:', all_files\n try:\n prefix = package.__name__\n except:\n prefix = ''\n all_packages = []\n for directory in all_files:\n path = join(common_dir,directory)\n if os.path.isdir(path) and \\\n os.path.exists(join(path,'__init__.py')):\n sub_package = prefix + '.' + directory\n #print 'sub-package import ' + sub_package\n try:\n exec ('import ' + sub_package)\n all_packages.append(eval(sub_package))\n except:\n print 'FAILURE to import ' + sub_package\n output_exception()\n return all_packages\n\n__all__.append('harvest_modules_and_packages')\ndef harvest_modules_and_packages(package,ignore=None):\n \"\"\" Retreive list of all packages and modules that live within a package.\n\n See harvest_packages() and harvest_modules()\n \"\"\"\n all = harvest_modules(package,ignore) + harvest_packages(package,ignore)\n return all\n\n__all__.append('harvest_test_suites')\ndef harvest_test_suites(package,ignore = None,level=10):\n \"\"\"\n package -- the module to test. This is an actual module object\n (not a string)\n ignore -- a list of module names to omit from the tests\n level -- a value between 1 and 10. 1 will run the minimum number\n of tests. This is a fast \"smoke test\". Tests that take\n longer to run should have higher numbers ranging up to 10.\n \"\"\"\n suites=[]\n test_modules = harvest_modules_and_packages(package,ignore)\n #for i in test_modules:\n # print i.__name__\n for module in test_modules:\n if hasattr(module,'test_suite'):\n try:\n suite = module.test_suite(level=level)\n if suite:\n suites.append(suite)\n else:\n print \" !! FAILURE without error - shouldn't happen\",\n print module.__name__\n except:\n print ' !! FAILURE building test for ', module.__name__\n print ' ',\n output_exception()\n else:\n try:\n print 'No test suite found for ', module.__name__\n except AttributeError:\n # __version__.py getting replaced by a string throws a kink\n # in checking for modules, so we think is a module has\n # actually been overwritten\n print 'No test suite found for ', str(module)\n total_suite = unittest.TestSuite(suites)\n return total_suite\n\n__all__.append('module_test')\ndef module_test(mod_name,mod_file,level=10):\n \"\"\"*\n\n *\"\"\"\n #print 'testing', mod_name\n d,f = os.path.split(mod_file)\n\n # insert the tests directory to the python path\n test_dir = os.path.join(d,'tests')\n sys.path.insert(0,test_dir)\n\n # call the \"test_xxx.test()\" function for the appropriate\n # module.\n\n # This should deal with package naming issues correctly\n short_mod_name = string.split(mod_name,'.')[-1]\n test_module = 'test_' + short_mod_name\n test_string = 'import %s;reload(%s);%s.test(%d)' % \\\n ((test_module,)*3 + (level,))\n\n # This would be better cause it forces a reload of the orginal\n # module. It doesn't behave with packages however.\n #test_string = 'reload(%s);import %s;reload(%s);%s.test(%d)' % \\\n # ((mod_name,) + (test_module,)*3)\n exec(test_string)\n\n # remove test directory from python path.\n sys.path = sys.path[1:]\n\n__all__.append('module_test_suite')\ndef module_test_suite(mod_name,mod_file,level=10):\n #try:\n print ' creating test suite for:', mod_name\n d,f = os.path.split(mod_file)\n\n # insert the tests directory to the python path\n test_dir = os.path.join(d,'tests')\n sys.path.insert(0,test_dir)\n\n # call the \"test_xxx.test()\" function for the appropriate\n # module.\n\n # This should deal with package naming issues correctly\n short_mod_name = string.split(mod_name,'.')[-1]\n test_module = 'test_' + short_mod_name\n test_string = 'import %s;reload(%s);suite = %s.test_suite(%d)' % \\\n ((test_module,)*3+(level,))\n #print test_string\n exec(test_string)\n\n # remove test directory from python path.\n sys.path = sys.path[1:]\n return suite\n #except:\n # print ' !! FAILURE loading test suite from', test_module, ':'\n # print ' ',\n # output_exception()\n\n\n# Utility function to facilitate testing.\n\n__all__.append('assert_equal')\ndef assert_equal(actual,desired,err_msg='',verbose=1):\n \"\"\" Raise an assertion if two items are not\n equal. I think this should be part of unittest.py\n \"\"\"\n msg = '\\nItems are not equal:\\n' + err_msg\n try:\n if ( verbose and len(repr(desired)) < 100 and len(repr(actual)) ):\n msg = msg \\\n + 'DESIRED: ' + repr(desired) \\\n + '\\nACTUAL: ' + repr(actual)\n except:\n msg = msg \\\n + 'DESIRED: ' + repr(desired) \\\n + '\\nACTUAL: ' + repr(actual)\n assert desired == actual, msg\n\n__all__.append('assert_almost_equal')\ndef assert_almost_equal(actual,desired,decimal=7,err_msg='',verbose=1):\n \"\"\" Raise an assertion if two items are not\n equal. I think this should be part of unittest.py\n \"\"\"\n msg = '\\nItems are not equal:\\n' + err_msg\n try:\n if ( verbose and len(repr(desired)) < 100 and len(repr(actual)) ):\n msg = msg \\\n + 'DESIRED: ' + repr(desired) \\\n + '\\nACTUAL: ' + repr(actual)\n except:\n msg = msg \\\n + 'DESIRED: ' + repr(desired) \\\n + '\\nACTUAL: ' + repr(actual)\n assert round(abs(desired - actual),decimal) == 0, msg\n\n__all__.append('assert_approx_equal')\ndef assert_approx_equal(actual,desired,significant=7,err_msg='',verbose=1):\n \"\"\" Raise an assertion if two items are not\n equal. I think this should be part of unittest.py\n Approximately equal is defined as the number of significant digits\n correct\n \"\"\"\n msg = '\\nItems are not equal to %d significant digits:\\n' % significant\n msg += err_msg\n actual, desired = map(float, (actual, desired))\n # Normalized the numbers to be in range (-10.0,10.0)\n scale = pow(10,math.floor(math.log10(0.5*(abs(desired)+abs(actual)))))\n try:\n sc_desired = desired/scale\n except ZeroDivisionError:\n sc_desired = 0.0\n try:\n sc_actual = actual/scale\n except ZeroDivisionError:\n sc_actual = 0.0\n try:\n if ( verbose and len(repr(desired)) < 100 and len(repr(actual)) ):\n msg = msg \\\n + 'DESIRED: ' + repr(desired) \\\n + '\\nACTUAL: ' + repr(actual)\n except:\n msg = msg \\\n + 'DESIRED: ' + repr(desired) \\\n + '\\nACTUAL: ' + repr(actual)\n assert math.fabs(sc_desired - sc_actual) < pow(10.,-1*significant), msg\n\n\n__all__.append('assert_array_equal')\ndef assert_array_equal(x,y,err_msg=''):\n x,y = asarray(x), asarray(y)\n msg = '\\nArrays are not equal'\n try:\n assert 0 in [len(shape(x)),len(shape(y))] \\\n or (len(shape(x))==len(shape(y)) and \\\n alltrue(equal(shape(x),shape(y)))),\\\n msg + ' (shapes %s, %s mismatch):\\n\\t' \\\n % (shape(x),shape(y)) + err_msg\n reduced = ravel(equal(x,y))\n cond = alltrue(reduced)\n if not cond:\n s1 = array2string(x,precision=16)\n s2 = array2string(y,precision=16)\n if len(s1)>120: s1 = s1[:120] + '...'\n if len(s2)>120: s2 = s2[:120] + '...'\n match = 100-100.0*reduced.tolist().count(1)/len(reduced)\n msg = msg + ' (mismatch %s%%):\\n\\tArray 1: %s\\n\\tArray 2: %s' % (match,s1,s2)\n assert cond,\\\n msg + '\\n\\t' + err_msg\n except ValueError:\n raise ValueError, msg\n\n__all__.append('assert_array_almost_equal')\ndef assert_array_almost_equal(x,y,decimal=6,err_msg=''):\n x = asarray(x)\n y = asarray(y)\n msg = '\\nArrays are not almost equal'\n try:\n cond = alltrue(equal(shape(x),shape(y)))\n if not cond:\n msg = msg + ' (shapes mismatch):\\n\\t'\\\n 'Shape of array 1: %s\\n\\tShape of array 2: %s' % (shape(x),shape(y))\n assert cond, msg + '\\n\\t' + err_msg\n reduced = ravel(equal(less_equal(around(abs(x-y),decimal),10.0**(-decimal)),1))\n cond = alltrue(reduced)\n if not cond:\n s1 = array2string(x,precision=decimal+1)\n s2 = array2string(y,precision=decimal+1)\n if len(s1)>120: s1 = s1[:120] + '...'\n if len(s2)>120: s2 = s2[:120] + '...'\n match = 100-100.0*reduced.tolist().count(1)/len(reduced)\n msg = msg + ' (mismatch %s%%):\\n\\tArray 1: %s\\n\\tArray 2: %s' % (match,s1,s2)\n assert cond,\\\n msg + '\\n\\t' + err_msg\n except ValueError:\n print sys.exc_value\n print shape(x),shape(y)\n print x, y\n raise ValueError, 'arrays are not almost equal'\n\n__all__.append('assert_array_less')\ndef assert_array_less(x,y,err_msg=''):\n x,y = asarray(x), asarray(y)\n msg = '\\nArrays are not less-ordered'\n try:\n assert alltrue(equal(shape(x),shape(y))),\\\n msg + ' (shapes mismatch):\\n\\t' + err_msg\n reduced = ravel(less(x,y))\n cond = alltrue(reduced)\n if not cond:\n s1 = array2string(x,precision=16)\n s2 = array2string(y,precision=16)\n if len(s1)>120: s1 = s1[:120] + '...'\n if len(s2)>120: s2 = s2[:120] + '...'\n match = 100-100.0*reduced.tolist().count(1)/len(reduced)\n msg = msg + ' (mismatch %s%%):\\n\\tArray 1: %s\\n\\tArray 2: %s' % (match,s1,s2)\n assert cond,\\\n msg + '\\n\\t' + err_msg\n except ValueError:\n print shape(x),shape(y)\n raise ValueError, 'arrays are not less-ordered'\n\n__all__.append('rand')\ndef rand(*args):\n \"\"\" Returns an array of random numbers with the given shape.\n used for testing\n \"\"\"\n import random\n results = zeros(args,Float64)\n f = results.flat\n for i in range(len(f)):\n f[i] = random.random()\n return results\n\ndef output_exception():\n try:\n type, value, tb = sys.exc_info()\n info = traceback.extract_tb(tb)\n #this is more verbose\n #traceback.print_exc()\n filename, lineno, function, text = info[-1] # last line only\n print \"%s:%d: %s: %s (in %s)\" %\\\n (filename, lineno, type.__name__, str(value), function)\n finally:\n type = value = tb = None # clean up\n\ntry:\n import scipy_base.fastumath as math\nexcept ImportError,msg:\n print msg\n import math\n", "source_code_before": "\"\"\"\nUnit-testing\n------------\n\n ScipyTest -- Scipy tests site manager\n ScipyTestCase -- unittest.TestCase with measure method\n IgnoreException -- raise when checking disabled feature ('ignoring' is displayed)\n HideException -- raise when checking disabled feature (nothing is displayed)\n set_package_path -- prepend package build directory to path\n set_local_path -- prepend local directory (to tests files) to path\n restore_path -- restore path after set_package_path\n\nTiming tools\n------------\n\n jiffies -- return 1/100ths of a second that the current process has used\n memusage -- virtual memory size in bytes of the running python [linux]\n\nUtility functions\n-----------------\n\n assert_equal -- assert equality\n assert_almost_equal -- assert equality with decimal tolerance\n assert_approx_equal -- assert equality with significant digits tolerance\n assert_array_equal -- assert arrays equality\n assert_array_almost_equal -- assert arrays equality with decimal tolerance\n assert_array_less -- assert arrays less-ordering\n rand -- array of random numbers from given shape\n\n\"\"\"\n\n__all__ = []\n\nimport os,sys,time,glob,string,traceback,unittest\nimport types\nimport imp\n\ntry:\n # These are used by Numeric tests.\n # If Numeric and scipy_base are not available, then some of the\n # functions below will not be available.\n from Numeric import alltrue,equal,shape,ravel,around,zeros,Float64,asarray,\\\n less_equal,array2string,less\n # `import scipy_base.fastumath as math` must be at the end of this file.\nexcept ImportError,msg:\n print msg\n\nDEBUG = 0\n\n__all__.append('set_package_path')\ndef set_package_path(level=1):\n \"\"\" Prepend package directory to sys.path.\n\n set_package_path should be called from a test_file.py that\n satisfies the following tree structure:\n\n //test_file.py\n\n Then the first existing path name from the following list\n\n /build/lib.-\n /..\n\n is prepended to sys.path.\n The caller is responsible for removing this path by using\n\n restore_path()\n \"\"\"\n from distutils.util import get_platform\n from scipy_distutils.misc_util import get_frame\n f = get_frame(level)\n if f.f_locals['__name__']=='__main__':\n testfile = sys.argv[0]\n else:\n testfile = f.f_locals['__file__']\n d = os.path.dirname(os.path.dirname(os.path.abspath(testfile)))\n d1 = os.path.join(d,'build','lib.%s-%s'%(get_platform(),sys.version[:3]))\n if not os.path.isdir(d1):\n d1 = os.path.dirname(d)\n if DEBUG:\n print 'Inserting %r to sys.path' % (d1)\n sys.path.insert(0,d1)\n\n__all__.append('set_local_path')\ndef set_local_path(reldir='', level=1):\n \"\"\" Prepend local directory to sys.path.\n\n The caller is responsible for removing this path by using\n\n restore_path()\n \"\"\"\n from scipy_distutils.misc_util import get_frame\n f = get_frame(level)\n if f.f_locals['__name__']=='__main__':\n testfile = sys.argv[0]\n else:\n testfile = f.f_locals['__file__']\n local_path = os.path.join(os.path.dirname(os.path.abspath(testfile)),reldir)\n if DEBUG:\n print 'Inserting %r to sys.path' % (local_path)\n sys.path.insert(0,local_path)\n\n__all__.append('restore_path')\ndef restore_path():\n if DEBUG:\n print 'Removing %r from sys.path' % (sys.path[0])\n del sys.path[0]\n\n__all__.extend(['jiffies','memusage'])\nif sys.platform[:5]=='linux':\n def jiffies(_proc_pid_stat = '/proc/%s/stat'%(os.getpid()),\n _load_time=time.time()):\n \"\"\" Return number of jiffies (1/100ths of a second) that this\n process has been scheduled in user mode. See man 5 proc. \"\"\"\n try:\n f=open(_proc_pid_stat,'r')\n l = f.readline().split(' ')\n f.close()\n return int(l[13])\n except:\n return int(100*(time.time()-_load_time))\n\n def memusage(_proc_pid_stat = '/proc/%s/stat'%(os.getpid())):\n \"\"\" Return virtual memory size in bytes of the running python.\n \"\"\"\n try:\n f=open(_proc_pid_stat,'r')\n l = f.readline().split(' ')\n f.close()\n return int(l[22])\n except:\n return\nelse:\n # os.getpid is not in all platforms available.\n # Using time is safe but inaccurate, especially when process\n # was suspended or sleeping.\n def jiffies(_load_time=time.time()):\n \"\"\" Return number of jiffies (1/100ths of a second) that this\n process has been scheduled in user mode. [Emulation with time.time]. \"\"\"\n return int(100*(time.time()-_load_time))\n\n def memusage():\n \"\"\" Return memory usage of running python. [Not implemented]\"\"\"\n return\n\n__all__.append('ScipyTestCase')\nclass ScipyTestCase (unittest.TestCase):\n\n def measure(self,code_str,times=1):\n \"\"\" Return elapsed time for executing code_str in the\n namespace of the caller for given times.\n \"\"\"\n frame = sys._getframe(1)\n locs,globs = frame.f_locals,frame.f_globals\n code = compile(code_str,\n 'ScipyTestCase runner for '+self.__class__.__name__,\n 'exec')\n i = 0\n elapsed = jiffies()\n while i>> ScipyTest().test(level=1,verbosity=2)\n\n is package name or its module object.\n\n Package is supposed to contain a directory tests/\n with test_*.py files where * refers to the names of submodules.\n\n test_*.py files are supposed to define a classes, derived\n from ScipyTestCase or unittest.TestCase, with methods having\n names starting with test or bench or check.\n\n And that is it! No need to implement test or test_suite functions\n in each .py file.\n\n Also old styled test_suite(level=1) hooks are supported but\n soon to be removed.\n \"\"\"\n def __init__(self, package='__main__'):\n self.package = package\n\n def _module_str(self, module):\n filename = module.__file__[-30:]\n if filename!=module.__file__:\n filename = '...'+filename\n return '' % (`module.__name__`, `filename`)\n\n def _get_method_names(self,clsobj,level):\n names = []\n for mthname in _get_all_method_names(clsobj):\n if mthname[:5] not in ['bench','check'] \\\n and mthname[:4] not in ['test']:\n continue\n mth = getattr(clsobj, mthname)\n if type(mth) is not types.MethodType:\n continue\n d = mth.im_func.func_defaults\n if d is not None:\n mthlevel = d[0]\n else:\n mthlevel = 1\n if level>=mthlevel:\n if mthname not in names:\n names.append(mthname)\n for base in clsobj.__bases__:\n for n in self._get_method_names(base,level):\n if n not in names:\n names.append(n)\n return names\n\n def _get_module_tests(self,module,level):\n mstr = self._module_str\n d,f = os.path.split(module.__file__)\n\n short_module_name = os.path.splitext(os.path.basename(f))[0]\n if short_module_name=='__init__':\n short_module_name = module.__name__.split('.')[-1]\n\n test_dir = os.path.join(d,'tests')\n test_file = os.path.join(test_dir,'test_'+short_module_name+'.py')\n\n local_test_dir = os.path.join(os.getcwd(),'tests')\n local_test_file = os.path.join(local_test_dir,\n 'test_'+short_module_name+'.py')\n if os.path.basename(os.path.dirname(local_test_dir)) \\\n == os.path.basename(os.path.dirname(test_dir)) \\\n and os.path.isfile(local_test_file):\n test_file = local_test_file\n\n if not os.path.isfile(test_file):\n if short_module_name[:5]=='info_' \\\n and short_module_name[5:]==module.__name__.split('.')[-2]:\n return []\n if short_module_name in ['__cvs_version__','__svn_version__']:\n return []\n if short_module_name[-8:]=='_version' \\\n and short_module_name[:-8]==module.__name__.split('.')[-2]:\n return []\n print ' !! No test file %r found for %s' \\\n % (os.path.basename(test_file), mstr(module))\n return []\n\n try:\n if sys.version[:3]=='2.1':\n # Workaround for Python 2.1 .pyc file generator bug\n import random\n pref = '-nopyc'+`random.randint(1,100)`\n else:\n pref = ''\n f = open(test_file,'r')\n test_module = imp.load_module(\\\n module.__name__+'.test_'+short_module_name+pref,\n f, test_file+pref,('.py', 'r', 1))\n f.close()\n if sys.version[:3]=='2.1' and os.path.isfile(test_file+pref+'c'):\n os.remove(test_file+pref+'c')\n except:\n print ' !! FAILURE importing tests for ', mstr(module)\n print ' ',\n output_exception()\n return []\n return self._get_suite_list(test_module, level, module.__name__)\n\n def _get_suite_list(self, test_module, level, module_name='__main__'):\n mstr = self._module_str\n if hasattr(test_module,'test_suite'):\n # Using old styled test suite\n try:\n total_suite = test_module.test_suite(level)\n return total_suite._tests\n except:\n print ' !! FAILURE building tests for ', mstr(test_module)\n print ' ',\n output_exception()\n return []\n suite_list = []\n for name in dir(test_module):\n obj = getattr(test_module, name)\n if type(obj) is not type(unittest.TestCase) \\\n or not issubclass(obj, unittest.TestCase) \\\n or obj.__name__[:4] != 'test':\n continue\n suite_list.extend(map(obj,self._get_method_names(obj,level)))\n print ' Found',len(suite_list),'tests for',module_name\n return suite_list\n\n def _touch_ppimported(self, module):\n from scipy_base.ppimport import _ModuleLoader\n if os.path.isdir(os.path.join(os.path.dirname(module.__file__),'tests')):\n # only touching those modules that have tests/ directory\n try: module._pliuh_plauh\n except AttributeError: pass\n for name in dir(module):\n obj = getattr(module,name)\n if isinstance(obj,_ModuleLoader) \\\n and not hasattr(obj,'_ppimport_module') \\\n and not hasattr(obj,'_ppimport_exc_info'):\n self._touch_ppimported(obj)\n\n def test(self,level=1,verbosity=1):\n \"\"\" Run Scipy module test suite with level and verbosity.\n \"\"\"\n if type(self.package) is type(''):\n exec 'import %s as this_package' % (self.package)\n else:\n this_package = self.package\n\n self._touch_ppimported(this_package)\n\n package_name = this_package.__name__\n\n suites = []\n for name, module in sys.modules.items():\n if package_name != name[:len(package_name)] \\\n or module is None \\\n or os.path.basename(os.path.dirname(module.__file__))=='tests':\n continue\n suites.extend(self._get_module_tests(module, level))\n\n suites.extend(self._get_suite_list(sys.modules[package_name], level))\n\n all_tests = unittest.TestSuite(suites)\n runner = unittest.TextTestRunner(verbosity=verbosity)\n runner.run(all_tests)\n return runner\n\n def run(self):\n \"\"\" Run Scipy module test suite with level and verbosity\n taken from sys.argv. Requires optparse module.\n \"\"\"\n try:\n from optparse import OptionParser\n except ImportError:\n print 'Failed to import optparse module, ignoring.'\n return self.test()\n usage = r'usage: %prog [-v ] [-l ]'\n parser = OptionParser(usage)\n parser.add_option(\"-v\", \"--verbosity\",\n action=\"store\",\n dest=\"verbosity\",\n default=1,\n type='int')\n parser.add_option(\"-l\", \"--level\",\n action=\"store\",\n dest=\"level\",\n default=1,\n type='int')\n (options, args) = parser.parse_args()\n self.test(options.level,options.verbosity)\n\n#------------\n \ndef remove_ignored_patterns(files,pattern):\n from fnmatch import fnmatch\n good_files = []\n for file in files:\n if not fnmatch(file,pattern):\n good_files.append(file)\n return good_files\n\ndef remove_ignored_files(original,ignored_files,cur_dir):\n \"\"\" This is actually expanded to do pattern matching.\n\n \"\"\"\n if not ignored_files: ignored_files = []\n ignored_modules = map(lambda x: x+'.py',ignored_files)\n ignored_packages = ignored_files[:]\n # always ignore setup.py and __init__.py files\n ignored_files = ['setup.py','setup_*.py','__init__.py']\n ignored_files += ignored_modules + ignored_packages\n ignored_files = map(lambda x,cur_dir=cur_dir: os.path.join(cur_dir,x),\n ignored_files)\n #print 'ignored:', ignored_files\n #good_files = filter(lambda x,ignored = ignored_files: x not in ignored,\n # original)\n good_files = original\n for pattern in ignored_files:\n good_files = remove_ignored_patterns(good_files,pattern)\n\n return good_files\n\n__all__.append('harvest_modules')\ndef harvest_modules(package,ignore=None):\n \"\"\"* Retreive a list of all modules that live within a package.\n\n Only retreive files that are immediate children of the\n package -- do not recurse through child packages or\n directories. The returned list contains actual modules, not\n just their names.\n *\"\"\"\n d,f = os.path.split(package.__file__)\n\n # go through the directory and import every py file there.\n common_dir = os.path.join(d,'*.py')\n py_files = glob.glob(common_dir)\n #py_files.remove(os.path.join(d,'__init__.py'))\n #py_files.remove(os.path.join(d,'setup.py'))\n\n py_files = remove_ignored_files(py_files,ignore,d)\n #print 'py_files:', py_files\n try:\n prefix = package.__name__\n except:\n prefix = ''\n\n all_modules = []\n for file in py_files:\n d,f = os.path.split(file)\n base,ext = os.path.splitext(f)\n mod = prefix + '.' + base\n #print 'module: import ' + mod\n try:\n exec ('import ' + mod)\n all_modules.append(eval(mod))\n except:\n print 'FAILURE to import ' + mod\n output_exception()\n\n return all_modules\n\n__all__.append('harvest_packages')\ndef harvest_packages(package,ignore = None):\n \"\"\" Retreive a list of all sub-packages that live within a package.\n\n Only retreive packages that are immediate children of this\n package -- do not recurse through child packages or\n directories. The returned list contains actual package objects, not\n just their names.\n \"\"\"\n join = os.path.join\n\n d,f = os.path.split(package.__file__)\n\n common_dir = os.path.abspath(d)\n all_files = os.listdir(d)\n\n all_files = remove_ignored_files(all_files,ignore,'')\n #print 'all_files:', all_files\n try:\n prefix = package.__name__\n except:\n prefix = ''\n all_packages = []\n for directory in all_files:\n path = join(common_dir,directory)\n if os.path.isdir(path) and \\\n os.path.exists(join(path,'__init__.py')):\n sub_package = prefix + '.' + directory\n #print 'sub-package import ' + sub_package\n try:\n exec ('import ' + sub_package)\n all_packages.append(eval(sub_package))\n except:\n print 'FAILURE to import ' + sub_package\n output_exception()\n return all_packages\n\n__all__.append('harvest_modules_and_packages')\ndef harvest_modules_and_packages(package,ignore=None):\n \"\"\" Retreive list of all packages and modules that live within a package.\n\n See harvest_packages() and harvest_modules()\n \"\"\"\n all = harvest_modules(package,ignore) + harvest_packages(package,ignore)\n return all\n\n__all__.append('harvest_test_suites')\ndef harvest_test_suites(package,ignore = None,level=10):\n \"\"\"\n package -- the module to test. This is an actual module object\n (not a string)\n ignore -- a list of module names to omit from the tests\n level -- a value between 1 and 10. 1 will run the minimum number\n of tests. This is a fast \"smoke test\". Tests that take\n longer to run should have higher numbers ranging up to 10.\n \"\"\"\n suites=[]\n test_modules = harvest_modules_and_packages(package,ignore)\n #for i in test_modules:\n # print i.__name__\n for module in test_modules:\n if hasattr(module,'test_suite'):\n try:\n suite = module.test_suite(level=level)\n if suite:\n suites.append(suite)\n else:\n print \" !! FAILURE without error - shouldn't happen\",\n print module.__name__\n except:\n print ' !! FAILURE building test for ', module.__name__\n print ' ',\n output_exception()\n else:\n try:\n print 'No test suite found for ', module.__name__\n except AttributeError:\n # __version__.py getting replaced by a string throws a kink\n # in checking for modules, so we think is a module has\n # actually been overwritten\n print 'No test suite found for ', str(module)\n total_suite = unittest.TestSuite(suites)\n return total_suite\n\n__all__.append('module_test')\ndef module_test(mod_name,mod_file,level=10):\n \"\"\"*\n\n *\"\"\"\n #print 'testing', mod_name\n d,f = os.path.split(mod_file)\n\n # insert the tests directory to the python path\n test_dir = os.path.join(d,'tests')\n sys.path.insert(0,test_dir)\n\n # call the \"test_xxx.test()\" function for the appropriate\n # module.\n\n # This should deal with package naming issues correctly\n short_mod_name = string.split(mod_name,'.')[-1]\n test_module = 'test_' + short_mod_name\n test_string = 'import %s;reload(%s);%s.test(%d)' % \\\n ((test_module,)*3 + (level,))\n\n # This would be better cause it forces a reload of the orginal\n # module. It doesn't behave with packages however.\n #test_string = 'reload(%s);import %s;reload(%s);%s.test(%d)' % \\\n # ((mod_name,) + (test_module,)*3)\n exec(test_string)\n\n # remove test directory from python path.\n sys.path = sys.path[1:]\n\n__all__.append('module_test_suite')\ndef module_test_suite(mod_name,mod_file,level=10):\n #try:\n print ' creating test suite for:', mod_name\n d,f = os.path.split(mod_file)\n\n # insert the tests directory to the python path\n test_dir = os.path.join(d,'tests')\n sys.path.insert(0,test_dir)\n\n # call the \"test_xxx.test()\" function for the appropriate\n # module.\n\n # This should deal with package naming issues correctly\n short_mod_name = string.split(mod_name,'.')[-1]\n test_module = 'test_' + short_mod_name\n test_string = 'import %s;reload(%s);suite = %s.test_suite(%d)' % \\\n ((test_module,)*3+(level,))\n #print test_string\n exec(test_string)\n\n # remove test directory from python path.\n sys.path = sys.path[1:]\n return suite\n #except:\n # print ' !! FAILURE loading test suite from', test_module, ':'\n # print ' ',\n # output_exception()\n\n\n# Utility function to facilitate testing.\n\n__all__.append('assert_equal')\ndef assert_equal(actual,desired,err_msg='',verbose=1):\n \"\"\" Raise an assertion if two items are not\n equal. I think this should be part of unittest.py\n \"\"\"\n msg = '\\nItems are not equal:\\n' + err_msg\n try:\n if ( verbose and len(repr(desired)) < 100 and len(repr(actual)) ):\n msg = msg \\\n + 'DESIRED: ' + repr(desired) \\\n + '\\nACTUAL: ' + repr(actual)\n except:\n msg = msg \\\n + 'DESIRED: ' + repr(desired) \\\n + '\\nACTUAL: ' + repr(actual)\n assert desired == actual, msg\n\n__all__.append('assert_almost_equal')\ndef assert_almost_equal(actual,desired,decimal=7,err_msg='',verbose=1):\n \"\"\" Raise an assertion if two items are not\n equal. I think this should be part of unittest.py\n \"\"\"\n msg = '\\nItems are not equal:\\n' + err_msg\n try:\n if ( verbose and len(repr(desired)) < 100 and len(repr(actual)) ):\n msg = msg \\\n + 'DESIRED: ' + repr(desired) \\\n + '\\nACTUAL: ' + repr(actual)\n except:\n msg = msg \\\n + 'DESIRED: ' + repr(desired) \\\n + '\\nACTUAL: ' + repr(actual)\n assert round(abs(desired - actual),decimal) == 0, msg\n\n__all__.append('assert_approx_equal')\ndef assert_approx_equal(actual,desired,significant=7,err_msg='',verbose=1):\n \"\"\" Raise an assertion if two items are not\n equal. I think this should be part of unittest.py\n Approximately equal is defined as the number of significant digits\n correct\n \"\"\"\n msg = '\\nItems are not equal to %d significant digits:\\n' % significant\n msg += err_msg\n actual, desired = map(float, (actual, desired))\n # Normalized the numbers to be in range (-10.0,10.0)\n scale = pow(10,math.floor(math.log10(0.5*(abs(desired)+abs(actual)))))\n try:\n sc_desired = desired/scale\n except ZeroDivisionError:\n sc_desired = 0.0\n try:\n sc_actual = actual/scale\n except ZeroDivisionError:\n sc_actual = 0.0\n try:\n if ( verbose and len(repr(desired)) < 100 and len(repr(actual)) ):\n msg = msg \\\n + 'DESIRED: ' + repr(desired) \\\n + '\\nACTUAL: ' + repr(actual)\n except:\n msg = msg \\\n + 'DESIRED: ' + repr(desired) \\\n + '\\nACTUAL: ' + repr(actual)\n assert math.fabs(sc_desired - sc_actual) < pow(10.,-1*significant), msg\n\n\n__all__.append('assert_array_equal')\ndef assert_array_equal(x,y,err_msg=''):\n x,y = asarray(x), asarray(y)\n msg = '\\nArrays are not equal'\n try:\n assert 0 in [len(shape(x)),len(shape(y))] \\\n or (len(shape(x))==len(shape(y)) and \\\n alltrue(equal(shape(x),shape(y)))),\\\n msg + ' (shapes %s, %s mismatch):\\n\\t' \\\n % (shape(x),shape(y)) + err_msg\n reduced = ravel(equal(x,y))\n cond = alltrue(reduced)\n if not cond:\n s1 = array2string(x,precision=16)\n s2 = array2string(y,precision=16)\n if len(s1)>120: s1 = s1[:120] + '...'\n if len(s2)>120: s2 = s2[:120] + '...'\n match = 100-100.0*reduced.tolist().count(1)/len(reduced)\n msg = msg + ' (mismatch %s%%):\\n\\tArray 1: %s\\n\\tArray 2: %s' % (match,s1,s2)\n assert cond,\\\n msg + '\\n\\t' + err_msg\n except ValueError:\n raise ValueError, msg\n\n__all__.append('assert_array_almost_equal')\ndef assert_array_almost_equal(x,y,decimal=6,err_msg=''):\n x = asarray(x)\n y = asarray(y)\n msg = '\\nArrays are not almost equal'\n try:\n cond = alltrue(equal(shape(x),shape(y)))\n if not cond:\n msg = msg + ' (shapes mismatch):\\n\\t'\\\n 'Shape of array 1: %s\\n\\tShape of array 2: %s' % (shape(x),shape(y))\n assert cond, msg + '\\n\\t' + err_msg\n reduced = ravel(equal(less_equal(around(abs(x-y),decimal),10.0**(-decimal)),1))\n cond = alltrue(reduced)\n if not cond:\n s1 = array2string(x,precision=decimal+1)\n s2 = array2string(y,precision=decimal+1)\n if len(s1)>120: s1 = s1[:120] + '...'\n if len(s2)>120: s2 = s2[:120] + '...'\n match = 100-100.0*reduced.tolist().count(1)/len(reduced)\n msg = msg + ' (mismatch %s%%):\\n\\tArray 1: %s\\n\\tArray 2: %s' % (match,s1,s2)\n assert cond,\\\n msg + '\\n\\t' + err_msg\n except ValueError:\n print sys.exc_value\n print shape(x),shape(y)\n print x, y\n raise ValueError, 'arrays are not almost equal'\n\n__all__.append('assert_array_less')\ndef assert_array_less(x,y,err_msg=''):\n x,y = asarray(x), asarray(y)\n msg = '\\nArrays are not less-ordered'\n try:\n assert alltrue(equal(shape(x),shape(y))),\\\n msg + ' (shapes mismatch):\\n\\t' + err_msg\n reduced = ravel(less(x,y))\n cond = alltrue(reduced)\n if not cond:\n s1 = array2string(x,precision=16)\n s2 = array2string(y,precision=16)\n if len(s1)>120: s1 = s1[:120] + '...'\n if len(s2)>120: s2 = s2[:120] + '...'\n match = 100-100.0*reduced.tolist().count(1)/len(reduced)\n msg = msg + ' (mismatch %s%%):\\n\\tArray 1: %s\\n\\tArray 2: %s' % (match,s1,s2)\n assert cond,\\\n msg + '\\n\\t' + err_msg\n except ValueError:\n print shape(x),shape(y)\n raise ValueError, 'arrays are not less-ordered'\n\n__all__.append('rand')\ndef rand(*args):\n \"\"\" Returns an array of random numbers with the given shape.\n used for testing\n \"\"\"\n import random\n results = zeros(args,Float64)\n f = results.flat\n for i in range(len(f)):\n f[i] = random.random()\n return results\n\ndef output_exception():\n try:\n type, value, tb = sys.exc_info()\n info = traceback.extract_tb(tb)\n #this is more verbose\n #traceback.print_exc()\n filename, lineno, function, text = info[-1] # last line only\n print \"%s:%d: %s: %s (in %s)\" %\\\n (filename, lineno, type.__name__, str(value), function)\n finally:\n type = value = tb = None # clean up\n\ntry:\n import scipy_base.fastumath as math\nexcept ImportError,msg:\n print msg\n import math\n", "methods": [ { "name": "set_package_path", "long_name": "set_package_path( level = 1 )", "filename": "testing.py", "nloc": 15, "complexity": 4, "token_count": 146, "parameters": [ "level" ], "start_line": 51, "end_line": 82, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 32, "top_nesting_level": 0 }, { "name": "set_local_path", "long_name": "set_local_path( reldir = '' , level = 1 )", "filename": "testing.py", "nloc": 11, "complexity": 3, "token_count": 97, "parameters": [ "reldir", "level" ], "start_line": 85, "end_line": 101, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 17, "top_nesting_level": 0 }, { "name": "restore_path", "long_name": "restore_path( )", "filename": "testing.py", "nloc": 4, "complexity": 2, "token_count": 25, "parameters": [], "start_line": 104, "end_line": 107, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 4, "top_nesting_level": 0 }, { "name": "jiffies", "long_name": "jiffies( _proc_pid_stat = '/proc/%s/stat' % ( os . getpid ( )", "filename": "testing.py", "nloc": 2, "complexity": 1, "token_count": 23, "parameters": [ "_proc_pid_stat" ], "start_line": 111, "end_line": 112, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 2, "top_nesting_level": 1 }, { "name": "memusage", "long_name": "memusage( _proc_pid_stat = '/proc/%s/stat' % ( os . getpid ( )", "filename": "testing.py", "nloc": 10, "complexity": 2, "token_count": 54, "parameters": [ "_proc_pid_stat" ], "start_line": 123, "end_line": 132, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 10, "top_nesting_level": 1 }, { "name": "jiffies", "long_name": "jiffies( _load_time = time . time ( )", "filename": "testing.py", "nloc": 4, "complexity": 1, "token_count": 27, "parameters": [ "_load_time" ], "start_line": 137, "end_line": 140, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 4, "top_nesting_level": 1 }, { "name": "memusage", "long_name": "memusage( )", "filename": "testing.py", "nloc": 2, "complexity": 1, "token_count": 6, "parameters": [], "start_line": 142, "end_line": 144, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 3, "top_nesting_level": 1 }, { "name": "measure", "long_name": "measure( self , code_str , times = 1 )", "filename": "testing.py", "nloc": 13, "complexity": 2, "token_count": 82, "parameters": [ "self", "code_str", "times" ], "start_line": 149, "end_line": 164, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 16, "top_nesting_level": 1 }, { "name": "__call__", "long_name": "__call__( self , result = None )", "filename": "testing.py", "nloc": 33, "complexity": 8, "token_count": 314, "parameters": [ "self", "result" ], "start_line": 166, "end_line": 199, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 34, "top_nesting_level": 1 }, { "name": "__init__", "long_name": "__init__( self )", "filename": "testing.py", "nloc": 2, "complexity": 1, "token_count": 11, "parameters": [ "self" ], "start_line": 202, "end_line": 203, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 2, "top_nesting_level": 1 }, { "name": "write", "long_name": "write( self , message )", "filename": "testing.py", "nloc": 2, "complexity": 1, "token_count": 15, "parameters": [ "self", "message" ], "start_line": 204, "end_line": 205, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 2, "top_nesting_level": 1 }, { "name": "writeln", "long_name": "writeln( self , message )", "filename": "testing.py", "nloc": 2, "complexity": 1, "token_count": 17, "parameters": [ "self", "message" ], "start_line": 206, "end_line": 207, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 2, "top_nesting_level": 1 }, { "name": "_get_all_method_names", "long_name": "_get_all_method_names( cls )", "filename": "testing.py", "nloc": 8, "complexity": 5, "token_count": 56, "parameters": [ "cls" ], "start_line": 219, "end_line": 226, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 8, "top_nesting_level": 0 }, { "name": "__init__", "long_name": "__init__( self , package = '__main__' )", "filename": "testing.py", "nloc": 2, "complexity": 1, "token_count": 14, "parameters": [ "self", "package" ], "start_line": 250, "end_line": 251, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 2, "top_nesting_level": 1 }, { "name": "_module_str", "long_name": "_module_str( self , module )", "filename": "testing.py", "nloc": 5, "complexity": 2, "token_count": 43, "parameters": [ "self", "module" ], "start_line": 253, "end_line": 257, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 5, "top_nesting_level": 1 }, { "name": "_get_method_names", "long_name": "_get_method_names( self , clsobj , level )", "filename": "testing.py", "nloc": 22, "complexity": 11, "token_count": 142, "parameters": [ "self", "clsobj", "level" ], "start_line": 259, "end_line": 280, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 22, "top_nesting_level": 1 }, { "name": "_get_module_tests", "long_name": "_get_module_tests( self , module , level )", "filename": "testing.py", "nloc": 46, "complexity": 14, "token_count": 428, "parameters": [ "self", "module", "level" ], "start_line": 282, "end_line": 333, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 52, "top_nesting_level": 1 }, { "name": "_get_suite_list", "long_name": "_get_suite_list( self , test_module , level , module_name = '__main__' )", "filename": "testing.py", "nloc": 21, "complexity": 7, "token_count": 146, "parameters": [ "self", "test_module", "level", "module_name" ], "start_line": 335, "end_line": 356, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 22, "top_nesting_level": 1 }, { "name": "_touch_ppimported", "long_name": "_touch_ppimported( self , module )", "filename": "testing.py", "nloc": 11, "complexity": 7, "token_count": 98, "parameters": [ "self", "module" ], "start_line": 358, "end_line": 369, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 12, "top_nesting_level": 1 }, { "name": "test", "long_name": "test( self , level = 1 , verbosity = 1 )", "filename": "testing.py", "nloc": 19, "complexity": 6, "token_count": 166, "parameters": [ "self", "level", "verbosity" ], "start_line": 371, "end_line": 396, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 26, "top_nesting_level": 1 }, { "name": "run", "long_name": "run( self )", "filename": "testing.py", "nloc": 20, "complexity": 2, "token_count": 104, "parameters": [ "self" ], "start_line": 398, "end_line": 420, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 23, "top_nesting_level": 1 }, { "name": "remove_ignored_patterns", "long_name": "remove_ignored_patterns( files , pattern )", "filename": "testing.py", "nloc": 7, "complexity": 3, "token_count": 37, "parameters": [ "files", "pattern" ], "start_line": 424, "end_line": 430, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 7, "top_nesting_level": 0 }, { "name": "remove_ignored_files", "long_name": "remove_ignored_files( original , ignored_files , cur_dir )", "filename": "testing.py", "nloc": 12, "complexity": 3, "token_count": 93, "parameters": [ "original", "ignored_files", "cur_dir" ], "start_line": 432, "end_line": 451, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 20, "top_nesting_level": 0 }, { "name": "harvest_modules", "long_name": "harvest_modules( package , ignore = None )", "filename": "testing.py", "nloc": 21, "complexity": 4, "token_count": 134, "parameters": [ "package", "ignore" ], "start_line": 454, "end_line": 490, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 37, "top_nesting_level": 0 }, { "name": "harvest_packages", "long_name": "harvest_packages( package , ignore = None )", "filename": "testing.py", "nloc": 23, "complexity": 6, "token_count": 148, "parameters": [ "package", "ignore" ], "start_line": 493, "end_line": 527, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 35, "top_nesting_level": 0 }, { "name": "harvest_modules_and_packages", "long_name": "harvest_modules_and_packages( package , ignore = None )", "filename": "testing.py", "nloc": 3, "complexity": 1, "token_count": 27, "parameters": [ "package", "ignore" ], "start_line": 530, "end_line": 536, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 7, "top_nesting_level": 0 }, { "name": "harvest_test_suites", "long_name": "harvest_test_suites( package , ignore = None , level = 10 )", "filename": "testing.py", "nloc": 23, "complexity": 6, "token_count": 113, "parameters": [ "package", "ignore", "level" ], "start_line": 539, "end_line": 574, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 36, "top_nesting_level": 0 }, { "name": "module_test", "long_name": "module_test( mod_name , mod_file , level = 10 )", "filename": "testing.py", "nloc": 10, "complexity": 1, "token_count": 98, "parameters": [ "mod_name", "mod_file", "level" ], "start_line": 577, "end_line": 604, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 28, "top_nesting_level": 0 }, { "name": "module_test_suite", "long_name": "module_test_suite( mod_name , mod_file , level = 10 )", "filename": "testing.py", "nloc": 12, "complexity": 1, "token_count": 103, "parameters": [ "mod_name", "mod_file", "level" ], "start_line": 607, "end_line": 629, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 23, "top_nesting_level": 0 }, { "name": "assert_equal", "long_name": "assert_equal( actual , desired , err_msg = '' , verbose = 1 )", "filename": "testing.py", "nloc": 12, "complexity": 5, "token_count": 92, "parameters": [ "actual", "desired", "err_msg", "verbose" ], "start_line": 639, "end_line": 653, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 15, "top_nesting_level": 0 }, { "name": "assert_almost_equal", "long_name": "assert_almost_equal( actual , desired , decimal = 7 , err_msg = '' , verbose = 1 )", "filename": "testing.py", "nloc": 12, "complexity": 5, "token_count": 106, "parameters": [ "actual", "desired", "decimal", "err_msg", "verbose" ], "start_line": 656, "end_line": 670, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 15, "top_nesting_level": 0 }, { "name": "assert_approx_equal", "long_name": "assert_approx_equal( actual , desired , significant = 7 , err_msg = '' , verbose = 1 )", "filename": "testing.py", "nloc": 23, "complexity": 7, "token_count": 191, "parameters": [ "actual", "desired", "significant", "err_msg", "verbose" ], "start_line": 673, "end_line": 701, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 29, "top_nesting_level": 0 }, { "name": "assert_array_equal", "long_name": "assert_array_equal( x , y , err_msg = '' )", "filename": "testing.py", "nloc": 22, "complexity": 7, "token_count": 232, "parameters": [ "x", "y", "err_msg" ], "start_line": 705, "end_line": 726, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 22, "top_nesting_level": 0 }, { "name": "assert_array_almost_equal", "long_name": "assert_array_almost_equal( x , y , decimal = 6 , err_msg = '' )", "filename": "testing.py", "nloc": 26, "complexity": 6, "token_count": 251, "parameters": [ "x", "y", "decimal", "err_msg" ], "start_line": 729, "end_line": 754, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 26, "top_nesting_level": 0 }, { "name": "assert_array_less", "long_name": "assert_array_less( x , y , err_msg = '' )", "filename": "testing.py", "nloc": 20, "complexity": 5, "token_count": 189, "parameters": [ "x", "y", "err_msg" ], "start_line": 757, "end_line": 776, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 20, "top_nesting_level": 0 }, { "name": "rand", "long_name": "rand( * args )", "filename": "testing.py", "nloc": 7, "complexity": 2, "token_count": 45, "parameters": [ "args" ], "start_line": 779, "end_line": 788, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 10, "top_nesting_level": 0 }, { "name": "output_exception", "long_name": "output_exception( )", "filename": "testing.py", "nloc": 9, "complexity": 2, "token_count": 67, "parameters": [], "start_line": 790, "end_line": 800, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 11, "top_nesting_level": 0 } ], "methods_before": [ { "name": "set_package_path", "long_name": "set_package_path( level = 1 )", "filename": "testing.py", "nloc": 15, "complexity": 4, "token_count": 146, "parameters": [ "level" ], "start_line": 51, "end_line": 82, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 32, "top_nesting_level": 0 }, { "name": "set_local_path", "long_name": "set_local_path( reldir = '' , level = 1 )", "filename": "testing.py", "nloc": 11, "complexity": 3, "token_count": 97, "parameters": [ "reldir", "level" ], "start_line": 85, "end_line": 101, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 17, "top_nesting_level": 0 }, { "name": "restore_path", "long_name": "restore_path( )", "filename": "testing.py", "nloc": 4, "complexity": 2, "token_count": 25, "parameters": [], "start_line": 104, "end_line": 107, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 4, "top_nesting_level": 0 }, { "name": "jiffies", "long_name": "jiffies( _proc_pid_stat = '/proc/%s/stat' % ( os . getpid ( )", "filename": "testing.py", "nloc": 2, "complexity": 1, "token_count": 23, "parameters": [ "_proc_pid_stat" ], "start_line": 111, "end_line": 112, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 2, "top_nesting_level": 1 }, { "name": "memusage", "long_name": "memusage( _proc_pid_stat = '/proc/%s/stat' % ( os . getpid ( )", "filename": "testing.py", "nloc": 10, "complexity": 2, "token_count": 54, "parameters": [ "_proc_pid_stat" ], "start_line": 123, "end_line": 132, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 10, "top_nesting_level": 1 }, { "name": "jiffies", "long_name": "jiffies( _load_time = time . time ( )", "filename": "testing.py", "nloc": 4, "complexity": 1, "token_count": 27, "parameters": [ "_load_time" ], "start_line": 137, "end_line": 140, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 4, "top_nesting_level": 1 }, { "name": "memusage", "long_name": "memusage( )", "filename": "testing.py", "nloc": 2, "complexity": 1, "token_count": 6, "parameters": [], "start_line": 142, "end_line": 144, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 3, "top_nesting_level": 1 }, { "name": "measure", "long_name": "measure( self , code_str , times = 1 )", "filename": "testing.py", "nloc": 13, "complexity": 2, "token_count": 82, "parameters": [ "self", "code_str", "times" ], "start_line": 149, "end_line": 164, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 16, "top_nesting_level": 1 }, { "name": "__call__", "long_name": "__call__( self , result = None )", "filename": "testing.py", "nloc": 34, "complexity": 8, "token_count": 321, "parameters": [ "self", "result" ], "start_line": 166, "end_line": 200, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 35, "top_nesting_level": 1 }, { "name": "__init__", "long_name": "__init__( self )", "filename": "testing.py", "nloc": 2, "complexity": 1, "token_count": 11, "parameters": [ "self" ], "start_line": 203, "end_line": 204, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 2, "top_nesting_level": 1 }, { "name": "write", "long_name": "write( self , message )", "filename": "testing.py", "nloc": 2, "complexity": 1, "token_count": 15, "parameters": [ "self", "message" ], "start_line": 205, "end_line": 206, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 2, "top_nesting_level": 1 }, { "name": "writeln", "long_name": "writeln( self , message )", "filename": "testing.py", "nloc": 2, "complexity": 1, "token_count": 17, "parameters": [ "self", "message" ], "start_line": 207, "end_line": 208, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 2, "top_nesting_level": 1 }, { "name": "_get_all_method_names", "long_name": "_get_all_method_names( cls )", "filename": "testing.py", "nloc": 8, "complexity": 5, "token_count": 56, "parameters": [ "cls" ], "start_line": 220, "end_line": 227, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 8, "top_nesting_level": 0 }, { "name": "__init__", "long_name": "__init__( self , package = '__main__' )", "filename": "testing.py", "nloc": 2, "complexity": 1, "token_count": 14, "parameters": [ "self", "package" ], "start_line": 251, "end_line": 252, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 2, "top_nesting_level": 1 }, { "name": "_module_str", "long_name": "_module_str( self , module )", "filename": "testing.py", "nloc": 5, "complexity": 2, "token_count": 43, "parameters": [ "self", "module" ], "start_line": 254, "end_line": 258, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 5, "top_nesting_level": 1 }, { "name": "_get_method_names", "long_name": "_get_method_names( self , clsobj , level )", "filename": "testing.py", "nloc": 22, "complexity": 11, "token_count": 142, "parameters": [ "self", "clsobj", "level" ], "start_line": 260, "end_line": 281, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 22, "top_nesting_level": 1 }, { "name": "_get_module_tests", "long_name": "_get_module_tests( self , module , level )", "filename": "testing.py", "nloc": 46, "complexity": 14, "token_count": 428, "parameters": [ "self", "module", "level" ], "start_line": 283, "end_line": 334, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 52, "top_nesting_level": 1 }, { "name": "_get_suite_list", "long_name": "_get_suite_list( self , test_module , level , module_name = '__main__' )", "filename": "testing.py", "nloc": 21, "complexity": 7, "token_count": 146, "parameters": [ "self", "test_module", "level", "module_name" ], "start_line": 336, "end_line": 357, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 22, "top_nesting_level": 1 }, { "name": "_touch_ppimported", "long_name": "_touch_ppimported( self , module )", "filename": "testing.py", "nloc": 11, "complexity": 7, "token_count": 98, "parameters": [ "self", "module" ], "start_line": 359, "end_line": 370, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 12, "top_nesting_level": 1 }, { "name": "test", "long_name": "test( self , level = 1 , verbosity = 1 )", "filename": "testing.py", "nloc": 19, "complexity": 6, "token_count": 166, "parameters": [ "self", "level", "verbosity" ], "start_line": 372, "end_line": 397, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 26, "top_nesting_level": 1 }, { "name": "run", "long_name": "run( self )", "filename": "testing.py", "nloc": 20, "complexity": 2, "token_count": 104, "parameters": [ "self" ], "start_line": 399, "end_line": 421, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 23, "top_nesting_level": 1 }, { "name": "remove_ignored_patterns", "long_name": "remove_ignored_patterns( files , pattern )", "filename": "testing.py", "nloc": 7, "complexity": 3, "token_count": 37, "parameters": [ "files", "pattern" ], "start_line": 425, "end_line": 431, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 7, "top_nesting_level": 0 }, { "name": "remove_ignored_files", "long_name": "remove_ignored_files( original , ignored_files , cur_dir )", "filename": "testing.py", "nloc": 12, "complexity": 3, "token_count": 93, "parameters": [ "original", "ignored_files", "cur_dir" ], "start_line": 433, "end_line": 452, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 20, "top_nesting_level": 0 }, { "name": "harvest_modules", "long_name": "harvest_modules( package , ignore = None )", "filename": "testing.py", "nloc": 21, "complexity": 4, "token_count": 134, "parameters": [ "package", "ignore" ], "start_line": 455, "end_line": 491, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 37, "top_nesting_level": 0 }, { "name": "harvest_packages", "long_name": "harvest_packages( package , ignore = None )", "filename": "testing.py", "nloc": 23, "complexity": 6, "token_count": 148, "parameters": [ "package", "ignore" ], "start_line": 494, "end_line": 528, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 35, "top_nesting_level": 0 }, { "name": "harvest_modules_and_packages", "long_name": "harvest_modules_and_packages( package , ignore = None )", "filename": "testing.py", "nloc": 3, "complexity": 1, "token_count": 27, "parameters": [ "package", "ignore" ], "start_line": 531, "end_line": 537, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 7, "top_nesting_level": 0 }, { "name": "harvest_test_suites", "long_name": "harvest_test_suites( package , ignore = None , level = 10 )", "filename": "testing.py", "nloc": 23, "complexity": 6, "token_count": 113, "parameters": [ "package", "ignore", "level" ], "start_line": 540, "end_line": 575, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 36, "top_nesting_level": 0 }, { "name": "module_test", "long_name": "module_test( mod_name , mod_file , level = 10 )", "filename": "testing.py", "nloc": 10, "complexity": 1, "token_count": 98, "parameters": [ "mod_name", "mod_file", "level" ], "start_line": 578, "end_line": 605, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 28, "top_nesting_level": 0 }, { "name": "module_test_suite", "long_name": "module_test_suite( mod_name , mod_file , level = 10 )", "filename": "testing.py", "nloc": 12, "complexity": 1, "token_count": 103, "parameters": [ "mod_name", "mod_file", "level" ], "start_line": 608, "end_line": 630, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 23, "top_nesting_level": 0 }, { "name": "assert_equal", "long_name": "assert_equal( actual , desired , err_msg = '' , verbose = 1 )", "filename": "testing.py", "nloc": 12, "complexity": 5, "token_count": 92, "parameters": [ "actual", "desired", "err_msg", "verbose" ], "start_line": 640, "end_line": 654, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 15, "top_nesting_level": 0 }, { "name": "assert_almost_equal", "long_name": "assert_almost_equal( actual , desired , decimal = 7 , err_msg = '' , verbose = 1 )", "filename": "testing.py", "nloc": 12, "complexity": 5, "token_count": 106, "parameters": [ "actual", "desired", "decimal", "err_msg", "verbose" ], "start_line": 657, "end_line": 671, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 15, "top_nesting_level": 0 }, { "name": "assert_approx_equal", "long_name": "assert_approx_equal( actual , desired , significant = 7 , err_msg = '' , verbose = 1 )", "filename": "testing.py", "nloc": 23, "complexity": 7, "token_count": 191, "parameters": [ "actual", "desired", "significant", "err_msg", "verbose" ], "start_line": 674, "end_line": 702, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 29, "top_nesting_level": 0 }, { "name": "assert_array_equal", "long_name": "assert_array_equal( x , y , err_msg = '' )", "filename": "testing.py", "nloc": 22, "complexity": 7, "token_count": 232, "parameters": [ "x", "y", "err_msg" ], "start_line": 706, "end_line": 727, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 22, "top_nesting_level": 0 }, { "name": "assert_array_almost_equal", "long_name": "assert_array_almost_equal( x , y , decimal = 6 , err_msg = '' )", "filename": "testing.py", "nloc": 26, "complexity": 6, "token_count": 251, "parameters": [ "x", "y", "decimal", "err_msg" ], "start_line": 730, "end_line": 755, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 26, "top_nesting_level": 0 }, { "name": "assert_array_less", "long_name": "assert_array_less( x , y , err_msg = '' )", "filename": "testing.py", "nloc": 20, "complexity": 5, "token_count": 189, "parameters": [ "x", "y", "err_msg" ], "start_line": 758, "end_line": 777, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 20, "top_nesting_level": 0 }, { "name": "rand", "long_name": "rand( * args )", "filename": "testing.py", "nloc": 7, "complexity": 2, "token_count": 45, "parameters": [ "args" ], "start_line": 780, "end_line": 789, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 10, "top_nesting_level": 0 }, { "name": "output_exception", "long_name": "output_exception( )", "filename": "testing.py", "nloc": 9, "complexity": 2, "token_count": 67, "parameters": [], "start_line": 791, "end_line": 801, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 11, "top_nesting_level": 0 } ], "changed_methods": [ { "name": "__call__", "long_name": "__call__( self , result = None )", "filename": "testing.py", "nloc": 33, "complexity": 8, "token_count": 314, "parameters": [ "self", "result" ], "start_line": 166, "end_line": 199, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 34, "top_nesting_level": 1 } ], "nloc": 600, "complexity": 146, "token_count": 4279, "diff_parsed": { "added": [ " HideException -- raise when checking irrelevant feature (nothing is displayed)", " del result.errors[-1]", " del result.errors[-1]", " result.testsRun = result.testsRun - 1" ], "deleted": [ " HideException -- raise when checking disabled feature (nothing is displayed)", " del result.errors[-1]", " del result.errors[-1]", " del result.errors[-1]", " del result.errors[-1]" ] } } ] }, { "hash": "c2920f65f6ed634c65cce600d6f0f050a843ed3c", "msg": "Using -O2 with gcc-3.3.3 to avoid test failures.", "author": { "name": "Pearu Peterson", "email": "pearu.peterson@gmail.com" }, "committer": { "name": "Pearu Peterson", "email": "pearu.peterson@gmail.com" }, "author_date": "2004-11-30T12:53:50+00:00", "author_timezone": 0, "committer_date": "2004-11-30T12:53:50+00:00", "committer_timezone": 0, "branches": [ "main" ], "in_main_branch": true, "merge": false, "parents": [ "b89d967cf6cc65a24695cf0ef60817c638d52f7c" ], "project_name": "repo_copy", "project_path": "/tmp/tmpqop781_j/repo_copy", "deletions": 1, "insertions": 7, "lines": 8, "files": 1, "dmm_unit_size": 1.0, "dmm_unit_complexity": 1.0, "dmm_unit_interfacing": 1.0, "modified_files": [ { "old_path": "scipy_distutils/gnufcompiler.py", "new_path": "scipy_distutils/gnufcompiler.py", "filename": "gnufcompiler.py", "extension": "py", "change_type": "MODIFY", "diff": "@@ -102,7 +102,13 @@ def get_flags_debug(self):\n return ['-g']\n \n def get_flags_opt(self):\n- opt = ['-O3','-funroll-loops']\n+ if self.get_version()=='3.3.3':\n+ # With this compiler version building Fortran BLAS/LAPACK\n+ # with -O3 caused failures in lib.lapack heevr,syevr tests.\n+ opt = ['-O2']\n+ else:\n+ opt = ['-O3']\n+ opt.append('-funroll-loops')\n return opt\n \n def get_flags_arch(self):\n", "added_lines": 7, "deleted_lines": 1, "source_code": "\nimport re\nimport os\nimport sys\n\nfrom cpuinfo import cpu\nfrom fcompiler import FCompiler\nfrom exec_command import exec_command, find_executable\n\nclass GnuFCompiler(FCompiler):\n\n compiler_type = 'gnu'\n version_pattern = r'GNU Fortran ((\\(GCC[^\\)]*(\\)\\)|\\)))|)\\s*'\\\n '(?P[^\\s*\\)]+)'\n\n # 'g77 --version' results\n # SunOS: GNU Fortran (GCC 3.2) 3.2 20020814 (release)\n # Debian: GNU Fortran (GCC) 3.3.3 20040110 (prerelease) (Debian)\n # GNU Fortran (GCC) 3.3.3 (Debian 20040401)\n # GNU Fortran 0.5.25 20010319 (prerelease)\n # Redhat: GNU Fortran (GCC 3.2.2 20030222 (Red Hat Linux 3.2.2-5)) 3.2.2 20030222 (Red Hat Linux 3.2.2-5)\n\n for fc_exe in map(find_executable,['g77','f77']):\n if os.path.isfile(fc_exe):\n break\n executables = {\n 'version_cmd' : [fc_exe,\"--version\"],\n 'compiler_f77' : [fc_exe,\"-Wall\",\"-fno-second-underscore\"],\n 'compiler_f90' : None,\n 'compiler_fix' : None,\n 'linker_so' : [fc_exe],\n 'archiver' : [\"ar\", \"-cr\"],\n 'ranlib' : [\"ranlib\"],\n }\n module_dir_switch = None\n module_include_switch = None\n\n # Cygwin: f771: warning: -fPIC ignored for target (all code is position independent)\n if os.name != 'nt' and sys.platform!='cygwin':\n pic_flags = ['-fPIC']\n\n #def get_linker_so(self):\n # # win32 linking should be handled by standard linker\n # # Darwin g77 cannot be used as a linker.\n # #if re.match(r'(darwin)', sys.platform):\n # # return\n # return FCompiler.get_linker_so(self)\n\n def get_flags_linker_so(self):\n opt = []\n if sys.platform=='darwin':\n if os.path.realpath(sys.executable).startswith('/System'):\n # This is when Python is from Apple framework\n opt.extend([\"-Wl,-framework\",\"-Wl,Python\"])\n #else we are running in Fink python.\n opt.extend([\"-lcc_dynamic\",\"-bundle\"])\n else:\n opt.append(\"-shared\")\n if sys.platform[:5]=='sunos':\n # SunOS often has dynamically loaded symbols defined in the\n # static library libg2c.a The linker doesn't like this. To\n # ignore the problem, use the -mimpure-text flag. It isn't\n # the safest thing, but seems to work. 'man gcc' says:\n # \".. Instead of using -mimpure-text, you should compile all\n # source code with -fpic or -fPIC.\"\n opt.append('-mimpure-text')\n return opt\n\n def get_libgcc_dir(self):\n status, output = exec_command('%s -print-libgcc-file-name' \\\n % (self.compiler_f77[0]),use_tee=0) \n if not status:\n return os.path.dirname(output)\n return\n\n def get_library_dirs(self):\n opt = []\n if sys.platform[:5] != 'linux':\n d = self.get_libgcc_dir()\n if d:\n opt.append(d)\n return opt\n\n def get_libraries(self):\n opt = []\n d = self.get_libgcc_dir()\n if d is not None:\n g2c = 'g2c-pic'\n f = self.static_lib_format % (g2c, self.static_lib_extension)\n if not os.path.isfile(os.path.join(d,f)):\n g2c = 'g2c'\n else:\n g2c = 'g2c'\n \n if sys.platform=='win32':\n opt.append('gcc')\n if g2c is not None:\n opt.append(g2c)\n return opt\n\n def get_flags_debug(self):\n return ['-g']\n\n def get_flags_opt(self):\n if self.get_version()=='3.3.3':\n # With this compiler version building Fortran BLAS/LAPACK\n # with -O3 caused failures in lib.lapack heevr,syevr tests.\n opt = ['-O2']\n else:\n opt = ['-O3']\n opt.append('-funroll-loops')\n return opt\n\n def get_flags_arch(self):\n opt = []\n if sys.platform=='darwin':\n if os.name != 'posix':\n # this should presumably correspond to Apple\n if cpu.is_ppc():\n opt.append('-arch ppc')\n elif cpu.is_i386():\n opt.append('-arch i386')\n for a in '601 602 603 603e 604 604e 620 630 740 7400 7450 750'\\\n '403 505 801 821 823 860'.split():\n if getattr(cpu,'is_ppc%s'%a)():\n opt.append('-mcpu='+a)\n opt.append('-mtune='+a)\n break \n return opt\n march_flag = 1\n # 0.5.25 corresponds to 2.95.x\n if self.get_version() == '0.5.26': # gcc 3.0\n if cpu.is_AthlonK6():\n opt.append('-march=k6')\n elif cpu.is_AthlonK7():\n opt.append('-march=athlon')\n else:\n march_flag = 0\n # Note: gcc 3.2 on win32 has breakage with -march specified\n elif self.get_version() >= '3.1.1' \\\n and not sys.platform=='win32': # gcc >= 3.1.1\n if cpu.is_AthlonK6():\n opt.append('-march=k6')\n elif cpu.is_AthlonK6_2():\n opt.append('-march=k6-2')\n elif cpu.is_AthlonK6_3():\n opt.append('-march=k6-3')\n elif cpu.is_AthlonK7():\n opt.append('-march=athlon')\n elif cpu.is_AthlonMP():\n opt.append('-march=athlon-mp')\n # there's also: athlon-tbird, athlon-4, athlon-xp\n elif cpu.is_PentiumIV():\n opt.append('-march=pentium4')\n elif cpu.is_PentiumIII():\n opt.append('-march=pentium3')\n elif cpu.is_PentiumII():\n opt.append('-march=pentium2')\n else:\n march_flag = 0\n if self.get_version() >= '3.4' and not march_flag:\n march_flag = 1\n if cpu.is_Opteron():\n opt.append('-march=opteron')\n elif cpu.is_Athlon64():\n opt.append('-march=athlon64')\n else:\n march_flag = 0\n if cpu.has_mmx(): opt.append('-mmmx') \n if self.get_version() > '3.2.2':\n if cpu.has_sse2(): opt.append('-msse2')\n if cpu.has_sse(): opt.append('-msse')\n if self.get_version() >= '3.4':\n if cpu.has_sse3(): opt.append('-msse3')\n if cpu.has_3dnow(): opt.append('-m3dnow')\n else:\n march_flag = 0\n if march_flag:\n pass\n elif cpu.is_i686():\n opt.append('-march=i686')\n elif cpu.is_i586():\n opt.append('-march=i586')\n elif cpu.is_i486():\n opt.append('-march=i486')\n elif cpu.is_i386():\n opt.append('-march=i386')\n if cpu.is_Intel():\n opt.extend(['-malign-double','-fomit-frame-pointer'])\n return opt\n\nif __name__ == '__main__':\n from scipy_distutils import log\n log.set_verbosity(2)\n from fcompiler import new_fcompiler\n #compiler = new_fcompiler(compiler='gnu')\n compiler = GnuFCompiler()\n compiler.customize()\n print compiler.get_version()\n", "source_code_before": "\nimport re\nimport os\nimport sys\n\nfrom cpuinfo import cpu\nfrom fcompiler import FCompiler\nfrom exec_command import exec_command, find_executable\n\nclass GnuFCompiler(FCompiler):\n\n compiler_type = 'gnu'\n version_pattern = r'GNU Fortran ((\\(GCC[^\\)]*(\\)\\)|\\)))|)\\s*'\\\n '(?P[^\\s*\\)]+)'\n\n # 'g77 --version' results\n # SunOS: GNU Fortran (GCC 3.2) 3.2 20020814 (release)\n # Debian: GNU Fortran (GCC) 3.3.3 20040110 (prerelease) (Debian)\n # GNU Fortran (GCC) 3.3.3 (Debian 20040401)\n # GNU Fortran 0.5.25 20010319 (prerelease)\n # Redhat: GNU Fortran (GCC 3.2.2 20030222 (Red Hat Linux 3.2.2-5)) 3.2.2 20030222 (Red Hat Linux 3.2.2-5)\n\n for fc_exe in map(find_executable,['g77','f77']):\n if os.path.isfile(fc_exe):\n break\n executables = {\n 'version_cmd' : [fc_exe,\"--version\"],\n 'compiler_f77' : [fc_exe,\"-Wall\",\"-fno-second-underscore\"],\n 'compiler_f90' : None,\n 'compiler_fix' : None,\n 'linker_so' : [fc_exe],\n 'archiver' : [\"ar\", \"-cr\"],\n 'ranlib' : [\"ranlib\"],\n }\n module_dir_switch = None\n module_include_switch = None\n\n # Cygwin: f771: warning: -fPIC ignored for target (all code is position independent)\n if os.name != 'nt' and sys.platform!='cygwin':\n pic_flags = ['-fPIC']\n\n #def get_linker_so(self):\n # # win32 linking should be handled by standard linker\n # # Darwin g77 cannot be used as a linker.\n # #if re.match(r'(darwin)', sys.platform):\n # # return\n # return FCompiler.get_linker_so(self)\n\n def get_flags_linker_so(self):\n opt = []\n if sys.platform=='darwin':\n if os.path.realpath(sys.executable).startswith('/System'):\n # This is when Python is from Apple framework\n opt.extend([\"-Wl,-framework\",\"-Wl,Python\"])\n #else we are running in Fink python.\n opt.extend([\"-lcc_dynamic\",\"-bundle\"])\n else:\n opt.append(\"-shared\")\n if sys.platform[:5]=='sunos':\n # SunOS often has dynamically loaded symbols defined in the\n # static library libg2c.a The linker doesn't like this. To\n # ignore the problem, use the -mimpure-text flag. It isn't\n # the safest thing, but seems to work. 'man gcc' says:\n # \".. Instead of using -mimpure-text, you should compile all\n # source code with -fpic or -fPIC.\"\n opt.append('-mimpure-text')\n return opt\n\n def get_libgcc_dir(self):\n status, output = exec_command('%s -print-libgcc-file-name' \\\n % (self.compiler_f77[0]),use_tee=0) \n if not status:\n return os.path.dirname(output)\n return\n\n def get_library_dirs(self):\n opt = []\n if sys.platform[:5] != 'linux':\n d = self.get_libgcc_dir()\n if d:\n opt.append(d)\n return opt\n\n def get_libraries(self):\n opt = []\n d = self.get_libgcc_dir()\n if d is not None:\n g2c = 'g2c-pic'\n f = self.static_lib_format % (g2c, self.static_lib_extension)\n if not os.path.isfile(os.path.join(d,f)):\n g2c = 'g2c'\n else:\n g2c = 'g2c'\n \n if sys.platform=='win32':\n opt.append('gcc')\n if g2c is not None:\n opt.append(g2c)\n return opt\n\n def get_flags_debug(self):\n return ['-g']\n\n def get_flags_opt(self):\n opt = ['-O3','-funroll-loops']\n return opt\n\n def get_flags_arch(self):\n opt = []\n if sys.platform=='darwin':\n if os.name != 'posix':\n # this should presumably correspond to Apple\n if cpu.is_ppc():\n opt.append('-arch ppc')\n elif cpu.is_i386():\n opt.append('-arch i386')\n for a in '601 602 603 603e 604 604e 620 630 740 7400 7450 750'\\\n '403 505 801 821 823 860'.split():\n if getattr(cpu,'is_ppc%s'%a)():\n opt.append('-mcpu='+a)\n opt.append('-mtune='+a)\n break \n return opt\n march_flag = 1\n # 0.5.25 corresponds to 2.95.x\n if self.get_version() == '0.5.26': # gcc 3.0\n if cpu.is_AthlonK6():\n opt.append('-march=k6')\n elif cpu.is_AthlonK7():\n opt.append('-march=athlon')\n else:\n march_flag = 0\n # Note: gcc 3.2 on win32 has breakage with -march specified\n elif self.get_version() >= '3.1.1' \\\n and not sys.platform=='win32': # gcc >= 3.1.1\n if cpu.is_AthlonK6():\n opt.append('-march=k6')\n elif cpu.is_AthlonK6_2():\n opt.append('-march=k6-2')\n elif cpu.is_AthlonK6_3():\n opt.append('-march=k6-3')\n elif cpu.is_AthlonK7():\n opt.append('-march=athlon')\n elif cpu.is_AthlonMP():\n opt.append('-march=athlon-mp')\n # there's also: athlon-tbird, athlon-4, athlon-xp\n elif cpu.is_PentiumIV():\n opt.append('-march=pentium4')\n elif cpu.is_PentiumIII():\n opt.append('-march=pentium3')\n elif cpu.is_PentiumII():\n opt.append('-march=pentium2')\n else:\n march_flag = 0\n if self.get_version() >= '3.4' and not march_flag:\n march_flag = 1\n if cpu.is_Opteron():\n opt.append('-march=opteron')\n elif cpu.is_Athlon64():\n opt.append('-march=athlon64')\n else:\n march_flag = 0\n if cpu.has_mmx(): opt.append('-mmmx') \n if self.get_version() > '3.2.2':\n if cpu.has_sse2(): opt.append('-msse2')\n if cpu.has_sse(): opt.append('-msse')\n if self.get_version() >= '3.4':\n if cpu.has_sse3(): opt.append('-msse3')\n if cpu.has_3dnow(): opt.append('-m3dnow')\n else:\n march_flag = 0\n if march_flag:\n pass\n elif cpu.is_i686():\n opt.append('-march=i686')\n elif cpu.is_i586():\n opt.append('-march=i586')\n elif cpu.is_i486():\n opt.append('-march=i486')\n elif cpu.is_i386():\n opt.append('-march=i386')\n if cpu.is_Intel():\n opt.extend(['-malign-double','-fomit-frame-pointer'])\n return opt\n\nif __name__ == '__main__':\n from scipy_distutils import log\n log.set_verbosity(2)\n from fcompiler import new_fcompiler\n #compiler = new_fcompiler(compiler='gnu')\n compiler = GnuFCompiler()\n compiler.customize()\n print compiler.get_version()\n", "methods": [ { "name": "get_flags_linker_so", "long_name": "get_flags_linker_so( self )", "filename": "gnufcompiler.py", "nloc": 11, "complexity": 4, "token_count": 80, "parameters": [ "self" ], "start_line": 49, "end_line": 67, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 19, "top_nesting_level": 1 }, { "name": "get_libgcc_dir", "long_name": "get_libgcc_dir( self )", "filename": "gnufcompiler.py", "nloc": 6, "complexity": 2, "token_count": 41, "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": "get_library_dirs", "long_name": "get_library_dirs( self )", "filename": "gnufcompiler.py", "nloc": 7, "complexity": 3, "token_count": 38, "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": "get_libraries", "long_name": "get_libraries( self )", "filename": "gnufcompiler.py", "nloc": 15, "complexity": 5, "token_count": 93, "parameters": [ "self" ], "start_line": 84, "end_line": 99, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 16, "top_nesting_level": 1 }, { "name": "get_flags_debug", "long_name": "get_flags_debug( self )", "filename": "gnufcompiler.py", "nloc": 2, "complexity": 1, "token_count": 9, "parameters": [ "self" ], "start_line": 101, "end_line": 102, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 2, "top_nesting_level": 1 }, { "name": "get_flags_opt", "long_name": "get_flags_opt( self )", "filename": "gnufcompiler.py", "nloc": 7, "complexity": 2, "token_count": 34, "parameters": [ "self" ], "start_line": 104, "end_line": 112, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 9, "top_nesting_level": 1 }, { "name": "get_flags_arch", "long_name": "get_flags_arch( self )", "filename": "gnufcompiler.py", "nloc": 73, "complexity": 37, "token_count": 469, "parameters": [ "self" ], "start_line": 114, "end_line": 190, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 77, "top_nesting_level": 1 } ], "methods_before": [ { "name": "get_flags_linker_so", "long_name": "get_flags_linker_so( self )", "filename": "gnufcompiler.py", "nloc": 11, "complexity": 4, "token_count": 80, "parameters": [ "self" ], "start_line": 49, "end_line": 67, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 19, "top_nesting_level": 1 }, { "name": "get_libgcc_dir", "long_name": "get_libgcc_dir( self )", "filename": "gnufcompiler.py", "nloc": 6, "complexity": 2, "token_count": 41, "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": "get_library_dirs", "long_name": "get_library_dirs( self )", "filename": "gnufcompiler.py", "nloc": 7, "complexity": 3, "token_count": 38, "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": "get_libraries", "long_name": "get_libraries( self )", "filename": "gnufcompiler.py", "nloc": 15, "complexity": 5, "token_count": 93, "parameters": [ "self" ], "start_line": 84, "end_line": 99, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 16, "top_nesting_level": 1 }, { "name": "get_flags_debug", "long_name": "get_flags_debug( self )", "filename": "gnufcompiler.py", "nloc": 2, "complexity": 1, "token_count": 9, "parameters": [ "self" ], "start_line": 101, "end_line": 102, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 2, "top_nesting_level": 1 }, { "name": "get_flags_opt", "long_name": "get_flags_opt( self )", "filename": "gnufcompiler.py", "nloc": 3, "complexity": 1, "token_count": 14, "parameters": [ "self" ], "start_line": 104, "end_line": 106, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 3, "top_nesting_level": 1 }, { "name": "get_flags_arch", "long_name": "get_flags_arch( self )", "filename": "gnufcompiler.py", "nloc": 73, "complexity": 37, "token_count": 469, "parameters": [ "self" ], "start_line": 108, "end_line": 184, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 77, "top_nesting_level": 1 } ], "changed_methods": [ { "name": "get_flags_opt", "long_name": "get_flags_opt( self )", "filename": "gnufcompiler.py", "nloc": 7, "complexity": 2, "token_count": 34, "parameters": [ "self" ], "start_line": 104, "end_line": 112, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 9, "top_nesting_level": 1 } ], "nloc": 154, "complexity": 54, "token_count": 940, "diff_parsed": { "added": [ " if self.get_version()=='3.3.3':", " # With this compiler version building Fortran BLAS/LAPACK", " # with -O3 caused failures in lib.lapack heevr,syevr tests.", " opt = ['-O2']", " else:", " opt = ['-O3']", " opt.append('-funroll-loops')" ], "deleted": [ " opt = ['-O3','-funroll-loops']" ] } } ] }, { "hash": "7d87fa78d5658ae8ea96e3676970c1fbfd5f4743", "msg": "Removed HideException feature. Using isrunnable hooks instead to get the number of test suites correct.", "author": { "name": "Pearu Peterson", "email": "pearu.peterson@gmail.com" }, "committer": { "name": "Pearu Peterson", "email": "pearu.peterson@gmail.com" }, "author_date": "2004-12-01T07:08:51+00:00", "author_timezone": 0, "committer_date": "2004-12-01T07:08:51+00:00", "committer_timezone": 0, "branches": [ "main" ], "in_main_branch": true, "merge": false, "parents": [ "c2920f65f6ed634c65cce600d6f0f050a843ed3c" ], "project_name": "repo_copy", "project_path": "/tmp/tmpqop781_j/repo_copy", "deletions": 19, "insertions": 13, "lines": 32, "files": 1, "dmm_unit_size": 1.0, "dmm_unit_complexity": 1.0, "dmm_unit_interfacing": 0.0, "modified_files": [ { "old_path": "scipy_test/testing.py", "new_path": "scipy_test/testing.py", "filename": "testing.py", "extension": "py", "change_type": "MODIFY", "diff": "@@ -5,7 +5,6 @@\n ScipyTest -- Scipy tests site manager\n ScipyTestCase -- unittest.TestCase with measure method\n IgnoreException -- raise when checking disabled feature ('ignoring' is displayed)\n- HideException -- raise when checking irrelevant feature (nothing is displayed)\n set_package_path -- prepend package build directory to path\n set_local_path -- prepend local directory (to tests files) to path\n restore_path -- restore path after set_package_path\n@@ -169,7 +168,7 @@ def __call__(self, result=None):\n \n nof_errors = len(result.errors)\n save_stream = result.stream\n- result.stream = _dummy_stream()\n+ result.stream = _dummy_stream(save_stream)\n unittest.TestCase.__call__(self, result)\n if nof_errors != len(result.errors):\n test, errstr = result.errors[-1]\n@@ -186,34 +185,26 @@ def __call__(self, result=None):\n assert result.stream.data[-1]=='ERROR\\n',`result.stream.data`\n result.stream.data[-1] = 'ignoring\\n'\n del result.errors[-1]\n- elif errstr.startswith('HideException:'):\n- if l==1:\n- assert result.stream.data[-1]=='E',`result.stream.data`\n- result.stream.data[-1] = ''\n- else:\n- assert result.stream.data[-1]=='ERROR\\n',`result.stream.data`\n- result.stream.data = []\n- del result.errors[-1]\n- result.testsRun = result.testsRun - 1\n map(save_stream.write, result.stream.data)\n result.stream = save_stream\n \n class _dummy_stream:\n- def __init__(self):\n+ def __init__(self,stream):\n self.data = []\n+ self.stream = stream\n def write(self,message):\n+ if not self.data and not message.startswith('E'):\n+ self.stream.write(message)\n+ self.stream.flush()\n+ message = ''\n self.data.append(message)\n def writeln(self,message):\n- self.data.append(message+'\\n')\n+ self.write(message+'\\n')\n \n __all__.append('IgnoreException')\n class IgnoreException(Exception):\n \"Ignoring this exception due to disabled feature\"\n \n-__all__.append('HideException')\n-class HideException(Exception):\n- \"Hide this exception due to disabled feature\"\n-\n #------------\n \n def _get_all_method_names(cls):\n@@ -276,7 +267,7 @@ def _get_method_names(self,clsobj,level):\n for base in clsobj.__bases__:\n for n in self._get_method_names(base,level):\n if n not in names:\n- names.append(n)\n+ names.append(n) \n return names\n \n def _get_module_tests(self,module,level):\n@@ -351,7 +342,10 @@ def _get_suite_list(self, test_module, level, module_name='__main__'):\n or not issubclass(obj, unittest.TestCase) \\\n or obj.__name__[:4] != 'test':\n continue\n- suite_list.extend(map(obj,self._get_method_names(obj,level)))\n+ for mthname in self._get_method_names(obj,level):\n+ suite = obj(mthname)\n+ if getattr(suite,'isrunnable',lambda mthname:1)(mthname):\n+ suite_list.append(suite)\n print ' Found',len(suite_list),'tests for',module_name\n return suite_list\n \n", "added_lines": 13, "deleted_lines": 19, "source_code": "\"\"\"\nUnit-testing\n------------\n\n ScipyTest -- Scipy tests site manager\n ScipyTestCase -- unittest.TestCase with measure method\n IgnoreException -- raise when checking disabled feature ('ignoring' is displayed)\n set_package_path -- prepend package build directory to path\n set_local_path -- prepend local directory (to tests files) to path\n restore_path -- restore path after set_package_path\n\nTiming tools\n------------\n\n jiffies -- return 1/100ths of a second that the current process has used\n memusage -- virtual memory size in bytes of the running python [linux]\n\nUtility functions\n-----------------\n\n assert_equal -- assert equality\n assert_almost_equal -- assert equality with decimal tolerance\n assert_approx_equal -- assert equality with significant digits tolerance\n assert_array_equal -- assert arrays equality\n assert_array_almost_equal -- assert arrays equality with decimal tolerance\n assert_array_less -- assert arrays less-ordering\n rand -- array of random numbers from given shape\n\n\"\"\"\n\n__all__ = []\n\nimport os,sys,time,glob,string,traceback,unittest\nimport types\nimport imp\n\ntry:\n # These are used by Numeric tests.\n # If Numeric and scipy_base are not available, then some of the\n # functions below will not be available.\n from Numeric import alltrue,equal,shape,ravel,around,zeros,Float64,asarray,\\\n less_equal,array2string,less\n # `import scipy_base.fastumath as math` must be at the end of this file.\nexcept ImportError,msg:\n print msg\n\nDEBUG = 0\n\n__all__.append('set_package_path')\ndef set_package_path(level=1):\n \"\"\" Prepend package directory to sys.path.\n\n set_package_path should be called from a test_file.py that\n satisfies the following tree structure:\n\n //test_file.py\n\n Then the first existing path name from the following list\n\n /build/lib.-\n /..\n\n is prepended to sys.path.\n The caller is responsible for removing this path by using\n\n restore_path()\n \"\"\"\n from distutils.util import get_platform\n from scipy_distutils.misc_util import get_frame\n f = get_frame(level)\n if f.f_locals['__name__']=='__main__':\n testfile = sys.argv[0]\n else:\n testfile = f.f_locals['__file__']\n d = os.path.dirname(os.path.dirname(os.path.abspath(testfile)))\n d1 = os.path.join(d,'build','lib.%s-%s'%(get_platform(),sys.version[:3]))\n if not os.path.isdir(d1):\n d1 = os.path.dirname(d)\n if DEBUG:\n print 'Inserting %r to sys.path' % (d1)\n sys.path.insert(0,d1)\n\n__all__.append('set_local_path')\ndef set_local_path(reldir='', level=1):\n \"\"\" Prepend local directory to sys.path.\n\n The caller is responsible for removing this path by using\n\n restore_path()\n \"\"\"\n from scipy_distutils.misc_util import get_frame\n f = get_frame(level)\n if f.f_locals['__name__']=='__main__':\n testfile = sys.argv[0]\n else:\n testfile = f.f_locals['__file__']\n local_path = os.path.join(os.path.dirname(os.path.abspath(testfile)),reldir)\n if DEBUG:\n print 'Inserting %r to sys.path' % (local_path)\n sys.path.insert(0,local_path)\n\n__all__.append('restore_path')\ndef restore_path():\n if DEBUG:\n print 'Removing %r from sys.path' % (sys.path[0])\n del sys.path[0]\n\n__all__.extend(['jiffies','memusage'])\nif sys.platform[:5]=='linux':\n def jiffies(_proc_pid_stat = '/proc/%s/stat'%(os.getpid()),\n _load_time=time.time()):\n \"\"\" Return number of jiffies (1/100ths of a second) that this\n process has been scheduled in user mode. See man 5 proc. \"\"\"\n try:\n f=open(_proc_pid_stat,'r')\n l = f.readline().split(' ')\n f.close()\n return int(l[13])\n except:\n return int(100*(time.time()-_load_time))\n\n def memusage(_proc_pid_stat = '/proc/%s/stat'%(os.getpid())):\n \"\"\" Return virtual memory size in bytes of the running python.\n \"\"\"\n try:\n f=open(_proc_pid_stat,'r')\n l = f.readline().split(' ')\n f.close()\n return int(l[22])\n except:\n return\nelse:\n # os.getpid is not in all platforms available.\n # Using time is safe but inaccurate, especially when process\n # was suspended or sleeping.\n def jiffies(_load_time=time.time()):\n \"\"\" Return number of jiffies (1/100ths of a second) that this\n process has been scheduled in user mode. [Emulation with time.time]. \"\"\"\n return int(100*(time.time()-_load_time))\n\n def memusage():\n \"\"\" Return memory usage of running python. [Not implemented]\"\"\"\n return\n\n__all__.append('ScipyTestCase')\nclass ScipyTestCase (unittest.TestCase):\n\n def measure(self,code_str,times=1):\n \"\"\" Return elapsed time for executing code_str in the\n namespace of the caller for given times.\n \"\"\"\n frame = sys._getframe(1)\n locs,globs = frame.f_locals,frame.f_globals\n code = compile(code_str,\n 'ScipyTestCase runner for '+self.__class__.__name__,\n 'exec')\n i = 0\n elapsed = jiffies()\n while i>> ScipyTest().test(level=1,verbosity=2)\n\n is package name or its module object.\n\n Package is supposed to contain a directory tests/\n with test_*.py files where * refers to the names of submodules.\n\n test_*.py files are supposed to define a classes, derived\n from ScipyTestCase or unittest.TestCase, with methods having\n names starting with test or bench or check.\n\n And that is it! No need to implement test or test_suite functions\n in each .py file.\n\n Also old styled test_suite(level=1) hooks are supported but\n soon to be removed.\n \"\"\"\n def __init__(self, package='__main__'):\n self.package = package\n\n def _module_str(self, module):\n filename = module.__file__[-30:]\n if filename!=module.__file__:\n filename = '...'+filename\n return '' % (`module.__name__`, `filename`)\n\n def _get_method_names(self,clsobj,level):\n names = []\n for mthname in _get_all_method_names(clsobj):\n if mthname[:5] not in ['bench','check'] \\\n and mthname[:4] not in ['test']:\n continue\n mth = getattr(clsobj, mthname)\n if type(mth) is not types.MethodType:\n continue\n d = mth.im_func.func_defaults\n if d is not None:\n mthlevel = d[0]\n else:\n mthlevel = 1\n if level>=mthlevel:\n if mthname not in names:\n names.append(mthname)\n for base in clsobj.__bases__:\n for n in self._get_method_names(base,level):\n if n not in names:\n names.append(n) \n return names\n\n def _get_module_tests(self,module,level):\n mstr = self._module_str\n d,f = os.path.split(module.__file__)\n\n short_module_name = os.path.splitext(os.path.basename(f))[0]\n if short_module_name=='__init__':\n short_module_name = module.__name__.split('.')[-1]\n\n test_dir = os.path.join(d,'tests')\n test_file = os.path.join(test_dir,'test_'+short_module_name+'.py')\n\n local_test_dir = os.path.join(os.getcwd(),'tests')\n local_test_file = os.path.join(local_test_dir,\n 'test_'+short_module_name+'.py')\n if os.path.basename(os.path.dirname(local_test_dir)) \\\n == os.path.basename(os.path.dirname(test_dir)) \\\n and os.path.isfile(local_test_file):\n test_file = local_test_file\n\n if not os.path.isfile(test_file):\n if short_module_name[:5]=='info_' \\\n and short_module_name[5:]==module.__name__.split('.')[-2]:\n return []\n if short_module_name in ['__cvs_version__','__svn_version__']:\n return []\n if short_module_name[-8:]=='_version' \\\n and short_module_name[:-8]==module.__name__.split('.')[-2]:\n return []\n print ' !! No test file %r found for %s' \\\n % (os.path.basename(test_file), mstr(module))\n return []\n\n try:\n if sys.version[:3]=='2.1':\n # Workaround for Python 2.1 .pyc file generator bug\n import random\n pref = '-nopyc'+`random.randint(1,100)`\n else:\n pref = ''\n f = open(test_file,'r')\n test_module = imp.load_module(\\\n module.__name__+'.test_'+short_module_name+pref,\n f, test_file+pref,('.py', 'r', 1))\n f.close()\n if sys.version[:3]=='2.1' and os.path.isfile(test_file+pref+'c'):\n os.remove(test_file+pref+'c')\n except:\n print ' !! FAILURE importing tests for ', mstr(module)\n print ' ',\n output_exception()\n return []\n return self._get_suite_list(test_module, level, module.__name__)\n\n def _get_suite_list(self, test_module, level, module_name='__main__'):\n mstr = self._module_str\n if hasattr(test_module,'test_suite'):\n # Using old styled test suite\n try:\n total_suite = test_module.test_suite(level)\n return total_suite._tests\n except:\n print ' !! FAILURE building tests for ', mstr(test_module)\n print ' ',\n output_exception()\n return []\n suite_list = []\n for name in dir(test_module):\n obj = getattr(test_module, name)\n if type(obj) is not type(unittest.TestCase) \\\n or not issubclass(obj, unittest.TestCase) \\\n or obj.__name__[:4] != 'test':\n continue\n for mthname in self._get_method_names(obj,level):\n suite = obj(mthname)\n if getattr(suite,'isrunnable',lambda mthname:1)(mthname):\n suite_list.append(suite)\n print ' Found',len(suite_list),'tests for',module_name\n return suite_list\n\n def _touch_ppimported(self, module):\n from scipy_base.ppimport import _ModuleLoader\n if os.path.isdir(os.path.join(os.path.dirname(module.__file__),'tests')):\n # only touching those modules that have tests/ directory\n try: module._pliuh_plauh\n except AttributeError: pass\n for name in dir(module):\n obj = getattr(module,name)\n if isinstance(obj,_ModuleLoader) \\\n and not hasattr(obj,'_ppimport_module') \\\n and not hasattr(obj,'_ppimport_exc_info'):\n self._touch_ppimported(obj)\n\n def test(self,level=1,verbosity=1):\n \"\"\" Run Scipy module test suite with level and verbosity.\n \"\"\"\n if type(self.package) is type(''):\n exec 'import %s as this_package' % (self.package)\n else:\n this_package = self.package\n\n self._touch_ppimported(this_package)\n\n package_name = this_package.__name__\n\n suites = []\n for name, module in sys.modules.items():\n if package_name != name[:len(package_name)] \\\n or module is None \\\n or os.path.basename(os.path.dirname(module.__file__))=='tests':\n continue\n suites.extend(self._get_module_tests(module, level))\n\n suites.extend(self._get_suite_list(sys.modules[package_name], level))\n\n all_tests = unittest.TestSuite(suites)\n runner = unittest.TextTestRunner(verbosity=verbosity)\n runner.run(all_tests)\n return runner\n\n def run(self):\n \"\"\" Run Scipy module test suite with level and verbosity\n taken from sys.argv. Requires optparse module.\n \"\"\"\n try:\n from optparse import OptionParser\n except ImportError:\n print 'Failed to import optparse module, ignoring.'\n return self.test()\n usage = r'usage: %prog [-v ] [-l ]'\n parser = OptionParser(usage)\n parser.add_option(\"-v\", \"--verbosity\",\n action=\"store\",\n dest=\"verbosity\",\n default=1,\n type='int')\n parser.add_option(\"-l\", \"--level\",\n action=\"store\",\n dest=\"level\",\n default=1,\n type='int')\n (options, args) = parser.parse_args()\n self.test(options.level,options.verbosity)\n\n#------------\n \ndef remove_ignored_patterns(files,pattern):\n from fnmatch import fnmatch\n good_files = []\n for file in files:\n if not fnmatch(file,pattern):\n good_files.append(file)\n return good_files\n\ndef remove_ignored_files(original,ignored_files,cur_dir):\n \"\"\" This is actually expanded to do pattern matching.\n\n \"\"\"\n if not ignored_files: ignored_files = []\n ignored_modules = map(lambda x: x+'.py',ignored_files)\n ignored_packages = ignored_files[:]\n # always ignore setup.py and __init__.py files\n ignored_files = ['setup.py','setup_*.py','__init__.py']\n ignored_files += ignored_modules + ignored_packages\n ignored_files = map(lambda x,cur_dir=cur_dir: os.path.join(cur_dir,x),\n ignored_files)\n #print 'ignored:', ignored_files\n #good_files = filter(lambda x,ignored = ignored_files: x not in ignored,\n # original)\n good_files = original\n for pattern in ignored_files:\n good_files = remove_ignored_patterns(good_files,pattern)\n\n return good_files\n\n__all__.append('harvest_modules')\ndef harvest_modules(package,ignore=None):\n \"\"\"* Retreive a list of all modules that live within a package.\n\n Only retreive files that are immediate children of the\n package -- do not recurse through child packages or\n directories. The returned list contains actual modules, not\n just their names.\n *\"\"\"\n d,f = os.path.split(package.__file__)\n\n # go through the directory and import every py file there.\n common_dir = os.path.join(d,'*.py')\n py_files = glob.glob(common_dir)\n #py_files.remove(os.path.join(d,'__init__.py'))\n #py_files.remove(os.path.join(d,'setup.py'))\n\n py_files = remove_ignored_files(py_files,ignore,d)\n #print 'py_files:', py_files\n try:\n prefix = package.__name__\n except:\n prefix = ''\n\n all_modules = []\n for file in py_files:\n d,f = os.path.split(file)\n base,ext = os.path.splitext(f)\n mod = prefix + '.' + base\n #print 'module: import ' + mod\n try:\n exec ('import ' + mod)\n all_modules.append(eval(mod))\n except:\n print 'FAILURE to import ' + mod\n output_exception()\n\n return all_modules\n\n__all__.append('harvest_packages')\ndef harvest_packages(package,ignore = None):\n \"\"\" Retreive a list of all sub-packages that live within a package.\n\n Only retreive packages that are immediate children of this\n package -- do not recurse through child packages or\n directories. The returned list contains actual package objects, not\n just their names.\n \"\"\"\n join = os.path.join\n\n d,f = os.path.split(package.__file__)\n\n common_dir = os.path.abspath(d)\n all_files = os.listdir(d)\n\n all_files = remove_ignored_files(all_files,ignore,'')\n #print 'all_files:', all_files\n try:\n prefix = package.__name__\n except:\n prefix = ''\n all_packages = []\n for directory in all_files:\n path = join(common_dir,directory)\n if os.path.isdir(path) and \\\n os.path.exists(join(path,'__init__.py')):\n sub_package = prefix + '.' + directory\n #print 'sub-package import ' + sub_package\n try:\n exec ('import ' + sub_package)\n all_packages.append(eval(sub_package))\n except:\n print 'FAILURE to import ' + sub_package\n output_exception()\n return all_packages\n\n__all__.append('harvest_modules_and_packages')\ndef harvest_modules_and_packages(package,ignore=None):\n \"\"\" Retreive list of all packages and modules that live within a package.\n\n See harvest_packages() and harvest_modules()\n \"\"\"\n all = harvest_modules(package,ignore) + harvest_packages(package,ignore)\n return all\n\n__all__.append('harvest_test_suites')\ndef harvest_test_suites(package,ignore = None,level=10):\n \"\"\"\n package -- the module to test. This is an actual module object\n (not a string)\n ignore -- a list of module names to omit from the tests\n level -- a value between 1 and 10. 1 will run the minimum number\n of tests. This is a fast \"smoke test\". Tests that take\n longer to run should have higher numbers ranging up to 10.\n \"\"\"\n suites=[]\n test_modules = harvest_modules_and_packages(package,ignore)\n #for i in test_modules:\n # print i.__name__\n for module in test_modules:\n if hasattr(module,'test_suite'):\n try:\n suite = module.test_suite(level=level)\n if suite:\n suites.append(suite)\n else:\n print \" !! FAILURE without error - shouldn't happen\",\n print module.__name__\n except:\n print ' !! FAILURE building test for ', module.__name__\n print ' ',\n output_exception()\n else:\n try:\n print 'No test suite found for ', module.__name__\n except AttributeError:\n # __version__.py getting replaced by a string throws a kink\n # in checking for modules, so we think is a module has\n # actually been overwritten\n print 'No test suite found for ', str(module)\n total_suite = unittest.TestSuite(suites)\n return total_suite\n\n__all__.append('module_test')\ndef module_test(mod_name,mod_file,level=10):\n \"\"\"*\n\n *\"\"\"\n #print 'testing', mod_name\n d,f = os.path.split(mod_file)\n\n # insert the tests directory to the python path\n test_dir = os.path.join(d,'tests')\n sys.path.insert(0,test_dir)\n\n # call the \"test_xxx.test()\" function for the appropriate\n # module.\n\n # This should deal with package naming issues correctly\n short_mod_name = string.split(mod_name,'.')[-1]\n test_module = 'test_' + short_mod_name\n test_string = 'import %s;reload(%s);%s.test(%d)' % \\\n ((test_module,)*3 + (level,))\n\n # This would be better cause it forces a reload of the orginal\n # module. It doesn't behave with packages however.\n #test_string = 'reload(%s);import %s;reload(%s);%s.test(%d)' % \\\n # ((mod_name,) + (test_module,)*3)\n exec(test_string)\n\n # remove test directory from python path.\n sys.path = sys.path[1:]\n\n__all__.append('module_test_suite')\ndef module_test_suite(mod_name,mod_file,level=10):\n #try:\n print ' creating test suite for:', mod_name\n d,f = os.path.split(mod_file)\n\n # insert the tests directory to the python path\n test_dir = os.path.join(d,'tests')\n sys.path.insert(0,test_dir)\n\n # call the \"test_xxx.test()\" function for the appropriate\n # module.\n\n # This should deal with package naming issues correctly\n short_mod_name = string.split(mod_name,'.')[-1]\n test_module = 'test_' + short_mod_name\n test_string = 'import %s;reload(%s);suite = %s.test_suite(%d)' % \\\n ((test_module,)*3+(level,))\n #print test_string\n exec(test_string)\n\n # remove test directory from python path.\n sys.path = sys.path[1:]\n return suite\n #except:\n # print ' !! FAILURE loading test suite from', test_module, ':'\n # print ' ',\n # output_exception()\n\n\n# Utility function to facilitate testing.\n\n__all__.append('assert_equal')\ndef assert_equal(actual,desired,err_msg='',verbose=1):\n \"\"\" Raise an assertion if two items are not\n equal. I think this should be part of unittest.py\n \"\"\"\n msg = '\\nItems are not equal:\\n' + err_msg\n try:\n if ( verbose and len(repr(desired)) < 100 and len(repr(actual)) ):\n msg = msg \\\n + 'DESIRED: ' + repr(desired) \\\n + '\\nACTUAL: ' + repr(actual)\n except:\n msg = msg \\\n + 'DESIRED: ' + repr(desired) \\\n + '\\nACTUAL: ' + repr(actual)\n assert desired == actual, msg\n\n__all__.append('assert_almost_equal')\ndef assert_almost_equal(actual,desired,decimal=7,err_msg='',verbose=1):\n \"\"\" Raise an assertion if two items are not\n equal. I think this should be part of unittest.py\n \"\"\"\n msg = '\\nItems are not equal:\\n' + err_msg\n try:\n if ( verbose and len(repr(desired)) < 100 and len(repr(actual)) ):\n msg = msg \\\n + 'DESIRED: ' + repr(desired) \\\n + '\\nACTUAL: ' + repr(actual)\n except:\n msg = msg \\\n + 'DESIRED: ' + repr(desired) \\\n + '\\nACTUAL: ' + repr(actual)\n assert round(abs(desired - actual),decimal) == 0, msg\n\n__all__.append('assert_approx_equal')\ndef assert_approx_equal(actual,desired,significant=7,err_msg='',verbose=1):\n \"\"\" Raise an assertion if two items are not\n equal. I think this should be part of unittest.py\n Approximately equal is defined as the number of significant digits\n correct\n \"\"\"\n msg = '\\nItems are not equal to %d significant digits:\\n' % significant\n msg += err_msg\n actual, desired = map(float, (actual, desired))\n # Normalized the numbers to be in range (-10.0,10.0)\n scale = pow(10,math.floor(math.log10(0.5*(abs(desired)+abs(actual)))))\n try:\n sc_desired = desired/scale\n except ZeroDivisionError:\n sc_desired = 0.0\n try:\n sc_actual = actual/scale\n except ZeroDivisionError:\n sc_actual = 0.0\n try:\n if ( verbose and len(repr(desired)) < 100 and len(repr(actual)) ):\n msg = msg \\\n + 'DESIRED: ' + repr(desired) \\\n + '\\nACTUAL: ' + repr(actual)\n except:\n msg = msg \\\n + 'DESIRED: ' + repr(desired) \\\n + '\\nACTUAL: ' + repr(actual)\n assert math.fabs(sc_desired - sc_actual) < pow(10.,-1*significant), msg\n\n\n__all__.append('assert_array_equal')\ndef assert_array_equal(x,y,err_msg=''):\n x,y = asarray(x), asarray(y)\n msg = '\\nArrays are not equal'\n try:\n assert 0 in [len(shape(x)),len(shape(y))] \\\n or (len(shape(x))==len(shape(y)) and \\\n alltrue(equal(shape(x),shape(y)))),\\\n msg + ' (shapes %s, %s mismatch):\\n\\t' \\\n % (shape(x),shape(y)) + err_msg\n reduced = ravel(equal(x,y))\n cond = alltrue(reduced)\n if not cond:\n s1 = array2string(x,precision=16)\n s2 = array2string(y,precision=16)\n if len(s1)>120: s1 = s1[:120] + '...'\n if len(s2)>120: s2 = s2[:120] + '...'\n match = 100-100.0*reduced.tolist().count(1)/len(reduced)\n msg = msg + ' (mismatch %s%%):\\n\\tArray 1: %s\\n\\tArray 2: %s' % (match,s1,s2)\n assert cond,\\\n msg + '\\n\\t' + err_msg\n except ValueError:\n raise ValueError, msg\n\n__all__.append('assert_array_almost_equal')\ndef assert_array_almost_equal(x,y,decimal=6,err_msg=''):\n x = asarray(x)\n y = asarray(y)\n msg = '\\nArrays are not almost equal'\n try:\n cond = alltrue(equal(shape(x),shape(y)))\n if not cond:\n msg = msg + ' (shapes mismatch):\\n\\t'\\\n 'Shape of array 1: %s\\n\\tShape of array 2: %s' % (shape(x),shape(y))\n assert cond, msg + '\\n\\t' + err_msg\n reduced = ravel(equal(less_equal(around(abs(x-y),decimal),10.0**(-decimal)),1))\n cond = alltrue(reduced)\n if not cond:\n s1 = array2string(x,precision=decimal+1)\n s2 = array2string(y,precision=decimal+1)\n if len(s1)>120: s1 = s1[:120] + '...'\n if len(s2)>120: s2 = s2[:120] + '...'\n match = 100-100.0*reduced.tolist().count(1)/len(reduced)\n msg = msg + ' (mismatch %s%%):\\n\\tArray 1: %s\\n\\tArray 2: %s' % (match,s1,s2)\n assert cond,\\\n msg + '\\n\\t' + err_msg\n except ValueError:\n print sys.exc_value\n print shape(x),shape(y)\n print x, y\n raise ValueError, 'arrays are not almost equal'\n\n__all__.append('assert_array_less')\ndef assert_array_less(x,y,err_msg=''):\n x,y = asarray(x), asarray(y)\n msg = '\\nArrays are not less-ordered'\n try:\n assert alltrue(equal(shape(x),shape(y))),\\\n msg + ' (shapes mismatch):\\n\\t' + err_msg\n reduced = ravel(less(x,y))\n cond = alltrue(reduced)\n if not cond:\n s1 = array2string(x,precision=16)\n s2 = array2string(y,precision=16)\n if len(s1)>120: s1 = s1[:120] + '...'\n if len(s2)>120: s2 = s2[:120] + '...'\n match = 100-100.0*reduced.tolist().count(1)/len(reduced)\n msg = msg + ' (mismatch %s%%):\\n\\tArray 1: %s\\n\\tArray 2: %s' % (match,s1,s2)\n assert cond,\\\n msg + '\\n\\t' + err_msg\n except ValueError:\n print shape(x),shape(y)\n raise ValueError, 'arrays are not less-ordered'\n\n__all__.append('rand')\ndef rand(*args):\n \"\"\" Returns an array of random numbers with the given shape.\n used for testing\n \"\"\"\n import random\n results = zeros(args,Float64)\n f = results.flat\n for i in range(len(f)):\n f[i] = random.random()\n return results\n\ndef output_exception():\n try:\n type, value, tb = sys.exc_info()\n info = traceback.extract_tb(tb)\n #this is more verbose\n #traceback.print_exc()\n filename, lineno, function, text = info[-1] # last line only\n print \"%s:%d: %s: %s (in %s)\" %\\\n (filename, lineno, type.__name__, str(value), function)\n finally:\n type = value = tb = None # clean up\n\ntry:\n import scipy_base.fastumath as math\nexcept ImportError,msg:\n print msg\n import math\n", "source_code_before": "\"\"\"\nUnit-testing\n------------\n\n ScipyTest -- Scipy tests site manager\n ScipyTestCase -- unittest.TestCase with measure method\n IgnoreException -- raise when checking disabled feature ('ignoring' is displayed)\n HideException -- raise when checking irrelevant feature (nothing is displayed)\n set_package_path -- prepend package build directory to path\n set_local_path -- prepend local directory (to tests files) to path\n restore_path -- restore path after set_package_path\n\nTiming tools\n------------\n\n jiffies -- return 1/100ths of a second that the current process has used\n memusage -- virtual memory size in bytes of the running python [linux]\n\nUtility functions\n-----------------\n\n assert_equal -- assert equality\n assert_almost_equal -- assert equality with decimal tolerance\n assert_approx_equal -- assert equality with significant digits tolerance\n assert_array_equal -- assert arrays equality\n assert_array_almost_equal -- assert arrays equality with decimal tolerance\n assert_array_less -- assert arrays less-ordering\n rand -- array of random numbers from given shape\n\n\"\"\"\n\n__all__ = []\n\nimport os,sys,time,glob,string,traceback,unittest\nimport types\nimport imp\n\ntry:\n # These are used by Numeric tests.\n # If Numeric and scipy_base are not available, then some of the\n # functions below will not be available.\n from Numeric import alltrue,equal,shape,ravel,around,zeros,Float64,asarray,\\\n less_equal,array2string,less\n # `import scipy_base.fastumath as math` must be at the end of this file.\nexcept ImportError,msg:\n print msg\n\nDEBUG = 0\n\n__all__.append('set_package_path')\ndef set_package_path(level=1):\n \"\"\" Prepend package directory to sys.path.\n\n set_package_path should be called from a test_file.py that\n satisfies the following tree structure:\n\n //test_file.py\n\n Then the first existing path name from the following list\n\n /build/lib.-\n /..\n\n is prepended to sys.path.\n The caller is responsible for removing this path by using\n\n restore_path()\n \"\"\"\n from distutils.util import get_platform\n from scipy_distutils.misc_util import get_frame\n f = get_frame(level)\n if f.f_locals['__name__']=='__main__':\n testfile = sys.argv[0]\n else:\n testfile = f.f_locals['__file__']\n d = os.path.dirname(os.path.dirname(os.path.abspath(testfile)))\n d1 = os.path.join(d,'build','lib.%s-%s'%(get_platform(),sys.version[:3]))\n if not os.path.isdir(d1):\n d1 = os.path.dirname(d)\n if DEBUG:\n print 'Inserting %r to sys.path' % (d1)\n sys.path.insert(0,d1)\n\n__all__.append('set_local_path')\ndef set_local_path(reldir='', level=1):\n \"\"\" Prepend local directory to sys.path.\n\n The caller is responsible for removing this path by using\n\n restore_path()\n \"\"\"\n from scipy_distutils.misc_util import get_frame\n f = get_frame(level)\n if f.f_locals['__name__']=='__main__':\n testfile = sys.argv[0]\n else:\n testfile = f.f_locals['__file__']\n local_path = os.path.join(os.path.dirname(os.path.abspath(testfile)),reldir)\n if DEBUG:\n print 'Inserting %r to sys.path' % (local_path)\n sys.path.insert(0,local_path)\n\n__all__.append('restore_path')\ndef restore_path():\n if DEBUG:\n print 'Removing %r from sys.path' % (sys.path[0])\n del sys.path[0]\n\n__all__.extend(['jiffies','memusage'])\nif sys.platform[:5]=='linux':\n def jiffies(_proc_pid_stat = '/proc/%s/stat'%(os.getpid()),\n _load_time=time.time()):\n \"\"\" Return number of jiffies (1/100ths of a second) that this\n process has been scheduled in user mode. See man 5 proc. \"\"\"\n try:\n f=open(_proc_pid_stat,'r')\n l = f.readline().split(' ')\n f.close()\n return int(l[13])\n except:\n return int(100*(time.time()-_load_time))\n\n def memusage(_proc_pid_stat = '/proc/%s/stat'%(os.getpid())):\n \"\"\" Return virtual memory size in bytes of the running python.\n \"\"\"\n try:\n f=open(_proc_pid_stat,'r')\n l = f.readline().split(' ')\n f.close()\n return int(l[22])\n except:\n return\nelse:\n # os.getpid is not in all platforms available.\n # Using time is safe but inaccurate, especially when process\n # was suspended or sleeping.\n def jiffies(_load_time=time.time()):\n \"\"\" Return number of jiffies (1/100ths of a second) that this\n process has been scheduled in user mode. [Emulation with time.time]. \"\"\"\n return int(100*(time.time()-_load_time))\n\n def memusage():\n \"\"\" Return memory usage of running python. [Not implemented]\"\"\"\n return\n\n__all__.append('ScipyTestCase')\nclass ScipyTestCase (unittest.TestCase):\n\n def measure(self,code_str,times=1):\n \"\"\" Return elapsed time for executing code_str in the\n namespace of the caller for given times.\n \"\"\"\n frame = sys._getframe(1)\n locs,globs = frame.f_locals,frame.f_globals\n code = compile(code_str,\n 'ScipyTestCase runner for '+self.__class__.__name__,\n 'exec')\n i = 0\n elapsed = jiffies()\n while i>> ScipyTest().test(level=1,verbosity=2)\n\n is package name or its module object.\n\n Package is supposed to contain a directory tests/\n with test_*.py files where * refers to the names of submodules.\n\n test_*.py files are supposed to define a classes, derived\n from ScipyTestCase or unittest.TestCase, with methods having\n names starting with test or bench or check.\n\n And that is it! No need to implement test or test_suite functions\n in each .py file.\n\n Also old styled test_suite(level=1) hooks are supported but\n soon to be removed.\n \"\"\"\n def __init__(self, package='__main__'):\n self.package = package\n\n def _module_str(self, module):\n filename = module.__file__[-30:]\n if filename!=module.__file__:\n filename = '...'+filename\n return '' % (`module.__name__`, `filename`)\n\n def _get_method_names(self,clsobj,level):\n names = []\n for mthname in _get_all_method_names(clsobj):\n if mthname[:5] not in ['bench','check'] \\\n and mthname[:4] not in ['test']:\n continue\n mth = getattr(clsobj, mthname)\n if type(mth) is not types.MethodType:\n continue\n d = mth.im_func.func_defaults\n if d is not None:\n mthlevel = d[0]\n else:\n mthlevel = 1\n if level>=mthlevel:\n if mthname not in names:\n names.append(mthname)\n for base in clsobj.__bases__:\n for n in self._get_method_names(base,level):\n if n not in names:\n names.append(n)\n return names\n\n def _get_module_tests(self,module,level):\n mstr = self._module_str\n d,f = os.path.split(module.__file__)\n\n short_module_name = os.path.splitext(os.path.basename(f))[0]\n if short_module_name=='__init__':\n short_module_name = module.__name__.split('.')[-1]\n\n test_dir = os.path.join(d,'tests')\n test_file = os.path.join(test_dir,'test_'+short_module_name+'.py')\n\n local_test_dir = os.path.join(os.getcwd(),'tests')\n local_test_file = os.path.join(local_test_dir,\n 'test_'+short_module_name+'.py')\n if os.path.basename(os.path.dirname(local_test_dir)) \\\n == os.path.basename(os.path.dirname(test_dir)) \\\n and os.path.isfile(local_test_file):\n test_file = local_test_file\n\n if not os.path.isfile(test_file):\n if short_module_name[:5]=='info_' \\\n and short_module_name[5:]==module.__name__.split('.')[-2]:\n return []\n if short_module_name in ['__cvs_version__','__svn_version__']:\n return []\n if short_module_name[-8:]=='_version' \\\n and short_module_name[:-8]==module.__name__.split('.')[-2]:\n return []\n print ' !! No test file %r found for %s' \\\n % (os.path.basename(test_file), mstr(module))\n return []\n\n try:\n if sys.version[:3]=='2.1':\n # Workaround for Python 2.1 .pyc file generator bug\n import random\n pref = '-nopyc'+`random.randint(1,100)`\n else:\n pref = ''\n f = open(test_file,'r')\n test_module = imp.load_module(\\\n module.__name__+'.test_'+short_module_name+pref,\n f, test_file+pref,('.py', 'r', 1))\n f.close()\n if sys.version[:3]=='2.1' and os.path.isfile(test_file+pref+'c'):\n os.remove(test_file+pref+'c')\n except:\n print ' !! FAILURE importing tests for ', mstr(module)\n print ' ',\n output_exception()\n return []\n return self._get_suite_list(test_module, level, module.__name__)\n\n def _get_suite_list(self, test_module, level, module_name='__main__'):\n mstr = self._module_str\n if hasattr(test_module,'test_suite'):\n # Using old styled test suite\n try:\n total_suite = test_module.test_suite(level)\n return total_suite._tests\n except:\n print ' !! FAILURE building tests for ', mstr(test_module)\n print ' ',\n output_exception()\n return []\n suite_list = []\n for name in dir(test_module):\n obj = getattr(test_module, name)\n if type(obj) is not type(unittest.TestCase) \\\n or not issubclass(obj, unittest.TestCase) \\\n or obj.__name__[:4] != 'test':\n continue\n suite_list.extend(map(obj,self._get_method_names(obj,level)))\n print ' Found',len(suite_list),'tests for',module_name\n return suite_list\n\n def _touch_ppimported(self, module):\n from scipy_base.ppimport import _ModuleLoader\n if os.path.isdir(os.path.join(os.path.dirname(module.__file__),'tests')):\n # only touching those modules that have tests/ directory\n try: module._pliuh_plauh\n except AttributeError: pass\n for name in dir(module):\n obj = getattr(module,name)\n if isinstance(obj,_ModuleLoader) \\\n and not hasattr(obj,'_ppimport_module') \\\n and not hasattr(obj,'_ppimport_exc_info'):\n self._touch_ppimported(obj)\n\n def test(self,level=1,verbosity=1):\n \"\"\" Run Scipy module test suite with level and verbosity.\n \"\"\"\n if type(self.package) is type(''):\n exec 'import %s as this_package' % (self.package)\n else:\n this_package = self.package\n\n self._touch_ppimported(this_package)\n\n package_name = this_package.__name__\n\n suites = []\n for name, module in sys.modules.items():\n if package_name != name[:len(package_name)] \\\n or module is None \\\n or os.path.basename(os.path.dirname(module.__file__))=='tests':\n continue\n suites.extend(self._get_module_tests(module, level))\n\n suites.extend(self._get_suite_list(sys.modules[package_name], level))\n\n all_tests = unittest.TestSuite(suites)\n runner = unittest.TextTestRunner(verbosity=verbosity)\n runner.run(all_tests)\n return runner\n\n def run(self):\n \"\"\" Run Scipy module test suite with level and verbosity\n taken from sys.argv. Requires optparse module.\n \"\"\"\n try:\n from optparse import OptionParser\n except ImportError:\n print 'Failed to import optparse module, ignoring.'\n return self.test()\n usage = r'usage: %prog [-v ] [-l ]'\n parser = OptionParser(usage)\n parser.add_option(\"-v\", \"--verbosity\",\n action=\"store\",\n dest=\"verbosity\",\n default=1,\n type='int')\n parser.add_option(\"-l\", \"--level\",\n action=\"store\",\n dest=\"level\",\n default=1,\n type='int')\n (options, args) = parser.parse_args()\n self.test(options.level,options.verbosity)\n\n#------------\n \ndef remove_ignored_patterns(files,pattern):\n from fnmatch import fnmatch\n good_files = []\n for file in files:\n if not fnmatch(file,pattern):\n good_files.append(file)\n return good_files\n\ndef remove_ignored_files(original,ignored_files,cur_dir):\n \"\"\" This is actually expanded to do pattern matching.\n\n \"\"\"\n if not ignored_files: ignored_files = []\n ignored_modules = map(lambda x: x+'.py',ignored_files)\n ignored_packages = ignored_files[:]\n # always ignore setup.py and __init__.py files\n ignored_files = ['setup.py','setup_*.py','__init__.py']\n ignored_files += ignored_modules + ignored_packages\n ignored_files = map(lambda x,cur_dir=cur_dir: os.path.join(cur_dir,x),\n ignored_files)\n #print 'ignored:', ignored_files\n #good_files = filter(lambda x,ignored = ignored_files: x not in ignored,\n # original)\n good_files = original\n for pattern in ignored_files:\n good_files = remove_ignored_patterns(good_files,pattern)\n\n return good_files\n\n__all__.append('harvest_modules')\ndef harvest_modules(package,ignore=None):\n \"\"\"* Retreive a list of all modules that live within a package.\n\n Only retreive files that are immediate children of the\n package -- do not recurse through child packages or\n directories. The returned list contains actual modules, not\n just their names.\n *\"\"\"\n d,f = os.path.split(package.__file__)\n\n # go through the directory and import every py file there.\n common_dir = os.path.join(d,'*.py')\n py_files = glob.glob(common_dir)\n #py_files.remove(os.path.join(d,'__init__.py'))\n #py_files.remove(os.path.join(d,'setup.py'))\n\n py_files = remove_ignored_files(py_files,ignore,d)\n #print 'py_files:', py_files\n try:\n prefix = package.__name__\n except:\n prefix = ''\n\n all_modules = []\n for file in py_files:\n d,f = os.path.split(file)\n base,ext = os.path.splitext(f)\n mod = prefix + '.' + base\n #print 'module: import ' + mod\n try:\n exec ('import ' + mod)\n all_modules.append(eval(mod))\n except:\n print 'FAILURE to import ' + mod\n output_exception()\n\n return all_modules\n\n__all__.append('harvest_packages')\ndef harvest_packages(package,ignore = None):\n \"\"\" Retreive a list of all sub-packages that live within a package.\n\n Only retreive packages that are immediate children of this\n package -- do not recurse through child packages or\n directories. The returned list contains actual package objects, not\n just their names.\n \"\"\"\n join = os.path.join\n\n d,f = os.path.split(package.__file__)\n\n common_dir = os.path.abspath(d)\n all_files = os.listdir(d)\n\n all_files = remove_ignored_files(all_files,ignore,'')\n #print 'all_files:', all_files\n try:\n prefix = package.__name__\n except:\n prefix = ''\n all_packages = []\n for directory in all_files:\n path = join(common_dir,directory)\n if os.path.isdir(path) and \\\n os.path.exists(join(path,'__init__.py')):\n sub_package = prefix + '.' + directory\n #print 'sub-package import ' + sub_package\n try:\n exec ('import ' + sub_package)\n all_packages.append(eval(sub_package))\n except:\n print 'FAILURE to import ' + sub_package\n output_exception()\n return all_packages\n\n__all__.append('harvest_modules_and_packages')\ndef harvest_modules_and_packages(package,ignore=None):\n \"\"\" Retreive list of all packages and modules that live within a package.\n\n See harvest_packages() and harvest_modules()\n \"\"\"\n all = harvest_modules(package,ignore) + harvest_packages(package,ignore)\n return all\n\n__all__.append('harvest_test_suites')\ndef harvest_test_suites(package,ignore = None,level=10):\n \"\"\"\n package -- the module to test. This is an actual module object\n (not a string)\n ignore -- a list of module names to omit from the tests\n level -- a value between 1 and 10. 1 will run the minimum number\n of tests. This is a fast \"smoke test\". Tests that take\n longer to run should have higher numbers ranging up to 10.\n \"\"\"\n suites=[]\n test_modules = harvest_modules_and_packages(package,ignore)\n #for i in test_modules:\n # print i.__name__\n for module in test_modules:\n if hasattr(module,'test_suite'):\n try:\n suite = module.test_suite(level=level)\n if suite:\n suites.append(suite)\n else:\n print \" !! FAILURE without error - shouldn't happen\",\n print module.__name__\n except:\n print ' !! FAILURE building test for ', module.__name__\n print ' ',\n output_exception()\n else:\n try:\n print 'No test suite found for ', module.__name__\n except AttributeError:\n # __version__.py getting replaced by a string throws a kink\n # in checking for modules, so we think is a module has\n # actually been overwritten\n print 'No test suite found for ', str(module)\n total_suite = unittest.TestSuite(suites)\n return total_suite\n\n__all__.append('module_test')\ndef module_test(mod_name,mod_file,level=10):\n \"\"\"*\n\n *\"\"\"\n #print 'testing', mod_name\n d,f = os.path.split(mod_file)\n\n # insert the tests directory to the python path\n test_dir = os.path.join(d,'tests')\n sys.path.insert(0,test_dir)\n\n # call the \"test_xxx.test()\" function for the appropriate\n # module.\n\n # This should deal with package naming issues correctly\n short_mod_name = string.split(mod_name,'.')[-1]\n test_module = 'test_' + short_mod_name\n test_string = 'import %s;reload(%s);%s.test(%d)' % \\\n ((test_module,)*3 + (level,))\n\n # This would be better cause it forces a reload of the orginal\n # module. It doesn't behave with packages however.\n #test_string = 'reload(%s);import %s;reload(%s);%s.test(%d)' % \\\n # ((mod_name,) + (test_module,)*3)\n exec(test_string)\n\n # remove test directory from python path.\n sys.path = sys.path[1:]\n\n__all__.append('module_test_suite')\ndef module_test_suite(mod_name,mod_file,level=10):\n #try:\n print ' creating test suite for:', mod_name\n d,f = os.path.split(mod_file)\n\n # insert the tests directory to the python path\n test_dir = os.path.join(d,'tests')\n sys.path.insert(0,test_dir)\n\n # call the \"test_xxx.test()\" function for the appropriate\n # module.\n\n # This should deal with package naming issues correctly\n short_mod_name = string.split(mod_name,'.')[-1]\n test_module = 'test_' + short_mod_name\n test_string = 'import %s;reload(%s);suite = %s.test_suite(%d)' % \\\n ((test_module,)*3+(level,))\n #print test_string\n exec(test_string)\n\n # remove test directory from python path.\n sys.path = sys.path[1:]\n return suite\n #except:\n # print ' !! FAILURE loading test suite from', test_module, ':'\n # print ' ',\n # output_exception()\n\n\n# Utility function to facilitate testing.\n\n__all__.append('assert_equal')\ndef assert_equal(actual,desired,err_msg='',verbose=1):\n \"\"\" Raise an assertion if two items are not\n equal. I think this should be part of unittest.py\n \"\"\"\n msg = '\\nItems are not equal:\\n' + err_msg\n try:\n if ( verbose and len(repr(desired)) < 100 and len(repr(actual)) ):\n msg = msg \\\n + 'DESIRED: ' + repr(desired) \\\n + '\\nACTUAL: ' + repr(actual)\n except:\n msg = msg \\\n + 'DESIRED: ' + repr(desired) \\\n + '\\nACTUAL: ' + repr(actual)\n assert desired == actual, msg\n\n__all__.append('assert_almost_equal')\ndef assert_almost_equal(actual,desired,decimal=7,err_msg='',verbose=1):\n \"\"\" Raise an assertion if two items are not\n equal. I think this should be part of unittest.py\n \"\"\"\n msg = '\\nItems are not equal:\\n' + err_msg\n try:\n if ( verbose and len(repr(desired)) < 100 and len(repr(actual)) ):\n msg = msg \\\n + 'DESIRED: ' + repr(desired) \\\n + '\\nACTUAL: ' + repr(actual)\n except:\n msg = msg \\\n + 'DESIRED: ' + repr(desired) \\\n + '\\nACTUAL: ' + repr(actual)\n assert round(abs(desired - actual),decimal) == 0, msg\n\n__all__.append('assert_approx_equal')\ndef assert_approx_equal(actual,desired,significant=7,err_msg='',verbose=1):\n \"\"\" Raise an assertion if two items are not\n equal. I think this should be part of unittest.py\n Approximately equal is defined as the number of significant digits\n correct\n \"\"\"\n msg = '\\nItems are not equal to %d significant digits:\\n' % significant\n msg += err_msg\n actual, desired = map(float, (actual, desired))\n # Normalized the numbers to be in range (-10.0,10.0)\n scale = pow(10,math.floor(math.log10(0.5*(abs(desired)+abs(actual)))))\n try:\n sc_desired = desired/scale\n except ZeroDivisionError:\n sc_desired = 0.0\n try:\n sc_actual = actual/scale\n except ZeroDivisionError:\n sc_actual = 0.0\n try:\n if ( verbose and len(repr(desired)) < 100 and len(repr(actual)) ):\n msg = msg \\\n + 'DESIRED: ' + repr(desired) \\\n + '\\nACTUAL: ' + repr(actual)\n except:\n msg = msg \\\n + 'DESIRED: ' + repr(desired) \\\n + '\\nACTUAL: ' + repr(actual)\n assert math.fabs(sc_desired - sc_actual) < pow(10.,-1*significant), msg\n\n\n__all__.append('assert_array_equal')\ndef assert_array_equal(x,y,err_msg=''):\n x,y = asarray(x), asarray(y)\n msg = '\\nArrays are not equal'\n try:\n assert 0 in [len(shape(x)),len(shape(y))] \\\n or (len(shape(x))==len(shape(y)) and \\\n alltrue(equal(shape(x),shape(y)))),\\\n msg + ' (shapes %s, %s mismatch):\\n\\t' \\\n % (shape(x),shape(y)) + err_msg\n reduced = ravel(equal(x,y))\n cond = alltrue(reduced)\n if not cond:\n s1 = array2string(x,precision=16)\n s2 = array2string(y,precision=16)\n if len(s1)>120: s1 = s1[:120] + '...'\n if len(s2)>120: s2 = s2[:120] + '...'\n match = 100-100.0*reduced.tolist().count(1)/len(reduced)\n msg = msg + ' (mismatch %s%%):\\n\\tArray 1: %s\\n\\tArray 2: %s' % (match,s1,s2)\n assert cond,\\\n msg + '\\n\\t' + err_msg\n except ValueError:\n raise ValueError, msg\n\n__all__.append('assert_array_almost_equal')\ndef assert_array_almost_equal(x,y,decimal=6,err_msg=''):\n x = asarray(x)\n y = asarray(y)\n msg = '\\nArrays are not almost equal'\n try:\n cond = alltrue(equal(shape(x),shape(y)))\n if not cond:\n msg = msg + ' (shapes mismatch):\\n\\t'\\\n 'Shape of array 1: %s\\n\\tShape of array 2: %s' % (shape(x),shape(y))\n assert cond, msg + '\\n\\t' + err_msg\n reduced = ravel(equal(less_equal(around(abs(x-y),decimal),10.0**(-decimal)),1))\n cond = alltrue(reduced)\n if not cond:\n s1 = array2string(x,precision=decimal+1)\n s2 = array2string(y,precision=decimal+1)\n if len(s1)>120: s1 = s1[:120] + '...'\n if len(s2)>120: s2 = s2[:120] + '...'\n match = 100-100.0*reduced.tolist().count(1)/len(reduced)\n msg = msg + ' (mismatch %s%%):\\n\\tArray 1: %s\\n\\tArray 2: %s' % (match,s1,s2)\n assert cond,\\\n msg + '\\n\\t' + err_msg\n except ValueError:\n print sys.exc_value\n print shape(x),shape(y)\n print x, y\n raise ValueError, 'arrays are not almost equal'\n\n__all__.append('assert_array_less')\ndef assert_array_less(x,y,err_msg=''):\n x,y = asarray(x), asarray(y)\n msg = '\\nArrays are not less-ordered'\n try:\n assert alltrue(equal(shape(x),shape(y))),\\\n msg + ' (shapes mismatch):\\n\\t' + err_msg\n reduced = ravel(less(x,y))\n cond = alltrue(reduced)\n if not cond:\n s1 = array2string(x,precision=16)\n s2 = array2string(y,precision=16)\n if len(s1)>120: s1 = s1[:120] + '...'\n if len(s2)>120: s2 = s2[:120] + '...'\n match = 100-100.0*reduced.tolist().count(1)/len(reduced)\n msg = msg + ' (mismatch %s%%):\\n\\tArray 1: %s\\n\\tArray 2: %s' % (match,s1,s2)\n assert cond,\\\n msg + '\\n\\t' + err_msg\n except ValueError:\n print shape(x),shape(y)\n raise ValueError, 'arrays are not less-ordered'\n\n__all__.append('rand')\ndef rand(*args):\n \"\"\" Returns an array of random numbers with the given shape.\n used for testing\n \"\"\"\n import random\n results = zeros(args,Float64)\n f = results.flat\n for i in range(len(f)):\n f[i] = random.random()\n return results\n\ndef output_exception():\n try:\n type, value, tb = sys.exc_info()\n info = traceback.extract_tb(tb)\n #this is more verbose\n #traceback.print_exc()\n filename, lineno, function, text = info[-1] # last line only\n print \"%s:%d: %s: %s (in %s)\" %\\\n (filename, lineno, type.__name__, str(value), function)\n finally:\n type = value = tb = None # clean up\n\ntry:\n import scipy_base.fastumath as math\nexcept ImportError,msg:\n print msg\n import math\n", "methods": [ { "name": "set_package_path", "long_name": "set_package_path( level = 1 )", "filename": "testing.py", "nloc": 15, "complexity": 4, "token_count": 146, "parameters": [ "level" ], "start_line": 50, "end_line": 81, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 32, "top_nesting_level": 0 }, { "name": "set_local_path", "long_name": "set_local_path( reldir = '' , level = 1 )", "filename": "testing.py", "nloc": 11, "complexity": 3, "token_count": 97, "parameters": [ "reldir", "level" ], "start_line": 84, "end_line": 100, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 17, "top_nesting_level": 0 }, { "name": "restore_path", "long_name": "restore_path( )", "filename": "testing.py", "nloc": 4, "complexity": 2, "token_count": 25, "parameters": [], "start_line": 103, "end_line": 106, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 4, "top_nesting_level": 0 }, { "name": "jiffies", "long_name": "jiffies( _proc_pid_stat = '/proc/%s/stat' % ( os . getpid ( )", "filename": "testing.py", "nloc": 2, "complexity": 1, "token_count": 23, "parameters": [ "_proc_pid_stat" ], "start_line": 110, "end_line": 111, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 2, "top_nesting_level": 1 }, { "name": "memusage", "long_name": "memusage( _proc_pid_stat = '/proc/%s/stat' % ( os . getpid ( )", "filename": "testing.py", "nloc": 10, "complexity": 2, "token_count": 54, "parameters": [ "_proc_pid_stat" ], "start_line": 122, "end_line": 131, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 10, "top_nesting_level": 1 }, { "name": "jiffies", "long_name": "jiffies( _load_time = time . time ( )", "filename": "testing.py", "nloc": 4, "complexity": 1, "token_count": 27, "parameters": [ "_load_time" ], "start_line": 136, "end_line": 139, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 4, "top_nesting_level": 1 }, { "name": "memusage", "long_name": "memusage( )", "filename": "testing.py", "nloc": 2, "complexity": 1, "token_count": 6, "parameters": [], "start_line": 141, "end_line": 143, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 3, "top_nesting_level": 1 }, { "name": "measure", "long_name": "measure( self , code_str , times = 1 )", "filename": "testing.py", "nloc": 13, "complexity": 2, "token_count": 82, "parameters": [ "self", "code_str", "times" ], "start_line": 148, "end_line": 163, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 16, "top_nesting_level": 1 }, { "name": "__call__", "long_name": "__call__( self , result = None )", "filename": "testing.py", "nloc": 24, "complexity": 6, "token_count": 224, "parameters": [ "self", "result" ], "start_line": 165, "end_line": 189, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 25, "top_nesting_level": 1 }, { "name": "__init__", "long_name": "__init__( self , stream )", "filename": "testing.py", "nloc": 3, "complexity": 1, "token_count": 18, "parameters": [ "self", "stream" ], "start_line": 192, "end_line": 194, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 3, "top_nesting_level": 1 }, { "name": "write", "long_name": "write( self , message )", "filename": "testing.py", "nloc": 6, "complexity": 3, "token_count": 47, "parameters": [ "self", "message" ], "start_line": 195, "end_line": 200, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 6, "top_nesting_level": 1 }, { "name": "writeln", "long_name": "writeln( self , message )", "filename": "testing.py", "nloc": 2, "complexity": 1, "token_count": 15, "parameters": [ "self", "message" ], "start_line": 201, "end_line": 202, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 2, "top_nesting_level": 1 }, { "name": "_get_all_method_names", "long_name": "_get_all_method_names( cls )", "filename": "testing.py", "nloc": 8, "complexity": 5, "token_count": 56, "parameters": [ "cls" ], "start_line": 210, "end_line": 217, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 8, "top_nesting_level": 0 }, { "name": "__init__", "long_name": "__init__( self , package = '__main__' )", "filename": "testing.py", "nloc": 2, "complexity": 1, "token_count": 14, "parameters": [ "self", "package" ], "start_line": 241, "end_line": 242, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 2, "top_nesting_level": 1 }, { "name": "_module_str", "long_name": "_module_str( self , module )", "filename": "testing.py", "nloc": 5, "complexity": 2, "token_count": 43, "parameters": [ "self", "module" ], "start_line": 244, "end_line": 248, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 5, "top_nesting_level": 1 }, { "name": "_get_method_names", "long_name": "_get_method_names( self , clsobj , level )", "filename": "testing.py", "nloc": 22, "complexity": 11, "token_count": 142, "parameters": [ "self", "clsobj", "level" ], "start_line": 250, "end_line": 271, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 22, "top_nesting_level": 1 }, { "name": "_get_module_tests", "long_name": "_get_module_tests( self , module , level )", "filename": "testing.py", "nloc": 46, "complexity": 14, "token_count": 428, "parameters": [ "self", "module", "level" ], "start_line": 273, "end_line": 324, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 52, "top_nesting_level": 1 }, { "name": "_get_suite_list", "long_name": "_get_suite_list( self , test_module , level , module_name = '__main__' )", "filename": "testing.py", "nloc": 24, "complexity": 9, "token_count": 168, "parameters": [ "self", "test_module", "level", "module_name" ], "start_line": 326, "end_line": 350, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 25, "top_nesting_level": 1 }, { "name": "_touch_ppimported", "long_name": "_touch_ppimported( self , module )", "filename": "testing.py", "nloc": 11, "complexity": 7, "token_count": 98, "parameters": [ "self", "module" ], "start_line": 352, "end_line": 363, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 12, "top_nesting_level": 1 }, { "name": "test", "long_name": "test( self , level = 1 , verbosity = 1 )", "filename": "testing.py", "nloc": 19, "complexity": 6, "token_count": 166, "parameters": [ "self", "level", "verbosity" ], "start_line": 365, "end_line": 390, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 26, "top_nesting_level": 1 }, { "name": "run", "long_name": "run( self )", "filename": "testing.py", "nloc": 20, "complexity": 2, "token_count": 104, "parameters": [ "self" ], "start_line": 392, "end_line": 414, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 23, "top_nesting_level": 1 }, { "name": "remove_ignored_patterns", "long_name": "remove_ignored_patterns( files , pattern )", "filename": "testing.py", "nloc": 7, "complexity": 3, "token_count": 37, "parameters": [ "files", "pattern" ], "start_line": 418, "end_line": 424, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 7, "top_nesting_level": 0 }, { "name": "remove_ignored_files", "long_name": "remove_ignored_files( original , ignored_files , cur_dir )", "filename": "testing.py", "nloc": 12, "complexity": 3, "token_count": 93, "parameters": [ "original", "ignored_files", "cur_dir" ], "start_line": 426, "end_line": 445, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 20, "top_nesting_level": 0 }, { "name": "harvest_modules", "long_name": "harvest_modules( package , ignore = None )", "filename": "testing.py", "nloc": 21, "complexity": 4, "token_count": 134, "parameters": [ "package", "ignore" ], "start_line": 448, "end_line": 484, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 37, "top_nesting_level": 0 }, { "name": "harvest_packages", "long_name": "harvest_packages( package , ignore = None )", "filename": "testing.py", "nloc": 23, "complexity": 6, "token_count": 148, "parameters": [ "package", "ignore" ], "start_line": 487, "end_line": 521, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 35, "top_nesting_level": 0 }, { "name": "harvest_modules_and_packages", "long_name": "harvest_modules_and_packages( package , ignore = None )", "filename": "testing.py", "nloc": 3, "complexity": 1, "token_count": 27, "parameters": [ "package", "ignore" ], "start_line": 524, "end_line": 530, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 7, "top_nesting_level": 0 }, { "name": "harvest_test_suites", "long_name": "harvest_test_suites( package , ignore = None , level = 10 )", "filename": "testing.py", "nloc": 23, "complexity": 6, "token_count": 113, "parameters": [ "package", "ignore", "level" ], "start_line": 533, "end_line": 568, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 36, "top_nesting_level": 0 }, { "name": "module_test", "long_name": "module_test( mod_name , mod_file , level = 10 )", "filename": "testing.py", "nloc": 10, "complexity": 1, "token_count": 98, "parameters": [ "mod_name", "mod_file", "level" ], "start_line": 571, "end_line": 598, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 28, "top_nesting_level": 0 }, { "name": "module_test_suite", "long_name": "module_test_suite( mod_name , mod_file , level = 10 )", "filename": "testing.py", "nloc": 12, "complexity": 1, "token_count": 103, "parameters": [ "mod_name", "mod_file", "level" ], "start_line": 601, "end_line": 623, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 23, "top_nesting_level": 0 }, { "name": "assert_equal", "long_name": "assert_equal( actual , desired , err_msg = '' , verbose = 1 )", "filename": "testing.py", "nloc": 12, "complexity": 5, "token_count": 92, "parameters": [ "actual", "desired", "err_msg", "verbose" ], "start_line": 633, "end_line": 647, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 15, "top_nesting_level": 0 }, { "name": "assert_almost_equal", "long_name": "assert_almost_equal( actual , desired , decimal = 7 , err_msg = '' , verbose = 1 )", "filename": "testing.py", "nloc": 12, "complexity": 5, "token_count": 106, "parameters": [ "actual", "desired", "decimal", "err_msg", "verbose" ], "start_line": 650, "end_line": 664, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 15, "top_nesting_level": 0 }, { "name": "assert_approx_equal", "long_name": "assert_approx_equal( actual , desired , significant = 7 , err_msg = '' , verbose = 1 )", "filename": "testing.py", "nloc": 23, "complexity": 7, "token_count": 191, "parameters": [ "actual", "desired", "significant", "err_msg", "verbose" ], "start_line": 667, "end_line": 695, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 29, "top_nesting_level": 0 }, { "name": "assert_array_equal", "long_name": "assert_array_equal( x , y , err_msg = '' )", "filename": "testing.py", "nloc": 22, "complexity": 7, "token_count": 232, "parameters": [ "x", "y", "err_msg" ], "start_line": 699, "end_line": 720, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 22, "top_nesting_level": 0 }, { "name": "assert_array_almost_equal", "long_name": "assert_array_almost_equal( x , y , decimal = 6 , err_msg = '' )", "filename": "testing.py", "nloc": 26, "complexity": 6, "token_count": 251, "parameters": [ "x", "y", "decimal", "err_msg" ], "start_line": 723, "end_line": 748, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 26, "top_nesting_level": 0 }, { "name": "assert_array_less", "long_name": "assert_array_less( x , y , err_msg = '' )", "filename": "testing.py", "nloc": 20, "complexity": 5, "token_count": 189, "parameters": [ "x", "y", "err_msg" ], "start_line": 751, "end_line": 770, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 20, "top_nesting_level": 0 }, { "name": "rand", "long_name": "rand( * args )", "filename": "testing.py", "nloc": 7, "complexity": 2, "token_count": 45, "parameters": [ "args" ], "start_line": 773, "end_line": 782, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 10, "top_nesting_level": 0 }, { "name": "output_exception", "long_name": "output_exception( )", "filename": "testing.py", "nloc": 9, "complexity": 2, "token_count": 67, "parameters": [], "start_line": 784, "end_line": 794, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 11, "top_nesting_level": 0 } ], "methods_before": [ { "name": "set_package_path", "long_name": "set_package_path( level = 1 )", "filename": "testing.py", "nloc": 15, "complexity": 4, "token_count": 146, "parameters": [ "level" ], "start_line": 51, "end_line": 82, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 32, "top_nesting_level": 0 }, { "name": "set_local_path", "long_name": "set_local_path( reldir = '' , level = 1 )", "filename": "testing.py", "nloc": 11, "complexity": 3, "token_count": 97, "parameters": [ "reldir", "level" ], "start_line": 85, "end_line": 101, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 17, "top_nesting_level": 0 }, { "name": "restore_path", "long_name": "restore_path( )", "filename": "testing.py", "nloc": 4, "complexity": 2, "token_count": 25, "parameters": [], "start_line": 104, "end_line": 107, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 4, "top_nesting_level": 0 }, { "name": "jiffies", "long_name": "jiffies( _proc_pid_stat = '/proc/%s/stat' % ( os . getpid ( )", "filename": "testing.py", "nloc": 2, "complexity": 1, "token_count": 23, "parameters": [ "_proc_pid_stat" ], "start_line": 111, "end_line": 112, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 2, "top_nesting_level": 1 }, { "name": "memusage", "long_name": "memusage( _proc_pid_stat = '/proc/%s/stat' % ( os . getpid ( )", "filename": "testing.py", "nloc": 10, "complexity": 2, "token_count": 54, "parameters": [ "_proc_pid_stat" ], "start_line": 123, "end_line": 132, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 10, "top_nesting_level": 1 }, { "name": "jiffies", "long_name": "jiffies( _load_time = time . time ( )", "filename": "testing.py", "nloc": 4, "complexity": 1, "token_count": 27, "parameters": [ "_load_time" ], "start_line": 137, "end_line": 140, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 4, "top_nesting_level": 1 }, { "name": "memusage", "long_name": "memusage( )", "filename": "testing.py", "nloc": 2, "complexity": 1, "token_count": 6, "parameters": [], "start_line": 142, "end_line": 144, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 3, "top_nesting_level": 1 }, { "name": "measure", "long_name": "measure( self , code_str , times = 1 )", "filename": "testing.py", "nloc": 13, "complexity": 2, "token_count": 82, "parameters": [ "self", "code_str", "times" ], "start_line": 149, "end_line": 164, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 16, "top_nesting_level": 1 }, { "name": "__call__", "long_name": "__call__( self , result = None )", "filename": "testing.py", "nloc": 33, "complexity": 8, "token_count": 314, "parameters": [ "self", "result" ], "start_line": 166, "end_line": 199, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 34, "top_nesting_level": 1 }, { "name": "__init__", "long_name": "__init__( self )", "filename": "testing.py", "nloc": 2, "complexity": 1, "token_count": 11, "parameters": [ "self" ], "start_line": 202, "end_line": 203, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 2, "top_nesting_level": 1 }, { "name": "write", "long_name": "write( self , message )", "filename": "testing.py", "nloc": 2, "complexity": 1, "token_count": 15, "parameters": [ "self", "message" ], "start_line": 204, "end_line": 205, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 2, "top_nesting_level": 1 }, { "name": "writeln", "long_name": "writeln( self , message )", "filename": "testing.py", "nloc": 2, "complexity": 1, "token_count": 17, "parameters": [ "self", "message" ], "start_line": 206, "end_line": 207, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 2, "top_nesting_level": 1 }, { "name": "_get_all_method_names", "long_name": "_get_all_method_names( cls )", "filename": "testing.py", "nloc": 8, "complexity": 5, "token_count": 56, "parameters": [ "cls" ], "start_line": 219, "end_line": 226, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 8, "top_nesting_level": 0 }, { "name": "__init__", "long_name": "__init__( self , package = '__main__' )", "filename": "testing.py", "nloc": 2, "complexity": 1, "token_count": 14, "parameters": [ "self", "package" ], "start_line": 250, "end_line": 251, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 2, "top_nesting_level": 1 }, { "name": "_module_str", "long_name": "_module_str( self , module )", "filename": "testing.py", "nloc": 5, "complexity": 2, "token_count": 43, "parameters": [ "self", "module" ], "start_line": 253, "end_line": 257, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 5, "top_nesting_level": 1 }, { "name": "_get_method_names", "long_name": "_get_method_names( self , clsobj , level )", "filename": "testing.py", "nloc": 22, "complexity": 11, "token_count": 142, "parameters": [ "self", "clsobj", "level" ], "start_line": 259, "end_line": 280, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 22, "top_nesting_level": 1 }, { "name": "_get_module_tests", "long_name": "_get_module_tests( self , module , level )", "filename": "testing.py", "nloc": 46, "complexity": 14, "token_count": 428, "parameters": [ "self", "module", "level" ], "start_line": 282, "end_line": 333, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 52, "top_nesting_level": 1 }, { "name": "_get_suite_list", "long_name": "_get_suite_list( self , test_module , level , module_name = '__main__' )", "filename": "testing.py", "nloc": 21, "complexity": 7, "token_count": 146, "parameters": [ "self", "test_module", "level", "module_name" ], "start_line": 335, "end_line": 356, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 22, "top_nesting_level": 1 }, { "name": "_touch_ppimported", "long_name": "_touch_ppimported( self , module )", "filename": "testing.py", "nloc": 11, "complexity": 7, "token_count": 98, "parameters": [ "self", "module" ], "start_line": 358, "end_line": 369, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 12, "top_nesting_level": 1 }, { "name": "test", "long_name": "test( self , level = 1 , verbosity = 1 )", "filename": "testing.py", "nloc": 19, "complexity": 6, "token_count": 166, "parameters": [ "self", "level", "verbosity" ], "start_line": 371, "end_line": 396, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 26, "top_nesting_level": 1 }, { "name": "run", "long_name": "run( self )", "filename": "testing.py", "nloc": 20, "complexity": 2, "token_count": 104, "parameters": [ "self" ], "start_line": 398, "end_line": 420, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 23, "top_nesting_level": 1 }, { "name": "remove_ignored_patterns", "long_name": "remove_ignored_patterns( files , pattern )", "filename": "testing.py", "nloc": 7, "complexity": 3, "token_count": 37, "parameters": [ "files", "pattern" ], "start_line": 424, "end_line": 430, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 7, "top_nesting_level": 0 }, { "name": "remove_ignored_files", "long_name": "remove_ignored_files( original , ignored_files , cur_dir )", "filename": "testing.py", "nloc": 12, "complexity": 3, "token_count": 93, "parameters": [ "original", "ignored_files", "cur_dir" ], "start_line": 432, "end_line": 451, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 20, "top_nesting_level": 0 }, { "name": "harvest_modules", "long_name": "harvest_modules( package , ignore = None )", "filename": "testing.py", "nloc": 21, "complexity": 4, "token_count": 134, "parameters": [ "package", "ignore" ], "start_line": 454, "end_line": 490, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 37, "top_nesting_level": 0 }, { "name": "harvest_packages", "long_name": "harvest_packages( package , ignore = None )", "filename": "testing.py", "nloc": 23, "complexity": 6, "token_count": 148, "parameters": [ "package", "ignore" ], "start_line": 493, "end_line": 527, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 35, "top_nesting_level": 0 }, { "name": "harvest_modules_and_packages", "long_name": "harvest_modules_and_packages( package , ignore = None )", "filename": "testing.py", "nloc": 3, "complexity": 1, "token_count": 27, "parameters": [ "package", "ignore" ], "start_line": 530, "end_line": 536, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 7, "top_nesting_level": 0 }, { "name": "harvest_test_suites", "long_name": "harvest_test_suites( package , ignore = None , level = 10 )", "filename": "testing.py", "nloc": 23, "complexity": 6, "token_count": 113, "parameters": [ "package", "ignore", "level" ], "start_line": 539, "end_line": 574, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 36, "top_nesting_level": 0 }, { "name": "module_test", "long_name": "module_test( mod_name , mod_file , level = 10 )", "filename": "testing.py", "nloc": 10, "complexity": 1, "token_count": 98, "parameters": [ "mod_name", "mod_file", "level" ], "start_line": 577, "end_line": 604, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 28, "top_nesting_level": 0 }, { "name": "module_test_suite", "long_name": "module_test_suite( mod_name , mod_file , level = 10 )", "filename": "testing.py", "nloc": 12, "complexity": 1, "token_count": 103, "parameters": [ "mod_name", "mod_file", "level" ], "start_line": 607, "end_line": 629, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 23, "top_nesting_level": 0 }, { "name": "assert_equal", "long_name": "assert_equal( actual , desired , err_msg = '' , verbose = 1 )", "filename": "testing.py", "nloc": 12, "complexity": 5, "token_count": 92, "parameters": [ "actual", "desired", "err_msg", "verbose" ], "start_line": 639, "end_line": 653, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 15, "top_nesting_level": 0 }, { "name": "assert_almost_equal", "long_name": "assert_almost_equal( actual , desired , decimal = 7 , err_msg = '' , verbose = 1 )", "filename": "testing.py", "nloc": 12, "complexity": 5, "token_count": 106, "parameters": [ "actual", "desired", "decimal", "err_msg", "verbose" ], "start_line": 656, "end_line": 670, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 15, "top_nesting_level": 0 }, { "name": "assert_approx_equal", "long_name": "assert_approx_equal( actual , desired , significant = 7 , err_msg = '' , verbose = 1 )", "filename": "testing.py", "nloc": 23, "complexity": 7, "token_count": 191, "parameters": [ "actual", "desired", "significant", "err_msg", "verbose" ], "start_line": 673, "end_line": 701, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 29, "top_nesting_level": 0 }, { "name": "assert_array_equal", "long_name": "assert_array_equal( x , y , err_msg = '' )", "filename": "testing.py", "nloc": 22, "complexity": 7, "token_count": 232, "parameters": [ "x", "y", "err_msg" ], "start_line": 705, "end_line": 726, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 22, "top_nesting_level": 0 }, { "name": "assert_array_almost_equal", "long_name": "assert_array_almost_equal( x , y , decimal = 6 , err_msg = '' )", "filename": "testing.py", "nloc": 26, "complexity": 6, "token_count": 251, "parameters": [ "x", "y", "decimal", "err_msg" ], "start_line": 729, "end_line": 754, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 26, "top_nesting_level": 0 }, { "name": "assert_array_less", "long_name": "assert_array_less( x , y , err_msg = '' )", "filename": "testing.py", "nloc": 20, "complexity": 5, "token_count": 189, "parameters": [ "x", "y", "err_msg" ], "start_line": 757, "end_line": 776, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 20, "top_nesting_level": 0 }, { "name": "rand", "long_name": "rand( * args )", "filename": "testing.py", "nloc": 7, "complexity": 2, "token_count": 45, "parameters": [ "args" ], "start_line": 779, "end_line": 788, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 10, "top_nesting_level": 0 }, { "name": "output_exception", "long_name": "output_exception( )", "filename": "testing.py", "nloc": 9, "complexity": 2, "token_count": 67, "parameters": [], "start_line": 790, "end_line": 800, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 11, "top_nesting_level": 0 } ], "changed_methods": [ { "name": "writeln", "long_name": "writeln( self , message )", "filename": "testing.py", "nloc": 2, "complexity": 1, "token_count": 15, "parameters": [ "self", "message" ], "start_line": 201, "end_line": 202, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 2, "top_nesting_level": 1 }, { "name": "_get_suite_list", "long_name": "_get_suite_list( self , test_module , level , module_name = '__main__' )", "filename": "testing.py", "nloc": 24, "complexity": 9, "token_count": 168, "parameters": [ "self", "test_module", "level", "module_name" ], "start_line": 326, "end_line": 350, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 25, "top_nesting_level": 1 }, { "name": "_get_method_names", "long_name": "_get_method_names( self , clsobj , level )", "filename": "testing.py", "nloc": 22, "complexity": 11, "token_count": 142, "parameters": [ "self", "clsobj", "level" ], "start_line": 250, "end_line": 271, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 22, "top_nesting_level": 1 }, { "name": "write", "long_name": "write( self , message )", "filename": "testing.py", "nloc": 6, "complexity": 3, "token_count": 47, "parameters": [ "self", "message" ], "start_line": 195, "end_line": 200, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 6, "top_nesting_level": 1 }, { "name": "__init__", "long_name": "__init__( self )", "filename": "testing.py", "nloc": 2, "complexity": 1, "token_count": 11, "parameters": [ "self" ], "start_line": 202, "end_line": 203, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 2, "top_nesting_level": 1 }, { "name": "__init__", "long_name": "__init__( self , stream )", "filename": "testing.py", "nloc": 3, "complexity": 1, "token_count": 18, "parameters": [ "self", "stream" ], "start_line": 192, "end_line": 194, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 3, "top_nesting_level": 1 }, { "name": "__call__", "long_name": "__call__( self , result = None )", "filename": "testing.py", "nloc": 24, "complexity": 6, "token_count": 224, "parameters": [ "self", "result" ], "start_line": 165, "end_line": 189, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 25, "top_nesting_level": 1 } ], "nloc": 595, "complexity": 148, "token_count": 4235, "diff_parsed": { "added": [ " result.stream = _dummy_stream(save_stream)", " def __init__(self,stream):", " self.stream = stream", " if not self.data and not message.startswith('E'):", " self.stream.write(message)", " self.stream.flush()", " message = ''", " self.write(message+'\\n')", " names.append(n)", " for mthname in self._get_method_names(obj,level):", " suite = obj(mthname)", " if getattr(suite,'isrunnable',lambda mthname:1)(mthname):", " suite_list.append(suite)" ], "deleted": [ " HideException -- raise when checking irrelevant feature (nothing is displayed)", " result.stream = _dummy_stream()", " elif errstr.startswith('HideException:'):", " if l==1:", " assert result.stream.data[-1]=='E',`result.stream.data`", " result.stream.data[-1] = ''", " else:", " assert result.stream.data[-1]=='ERROR\\n',`result.stream.data`", " result.stream.data = []", " del result.errors[-1]", " result.testsRun = result.testsRun - 1", " def __init__(self):", " self.data.append(message+'\\n')", "__all__.append('HideException')", "class HideException(Exception):", " \"Hide this exception due to disabled feature\"", "", " names.append(n)", " suite_list.extend(map(obj,self._get_method_names(obj,level)))" ] } } ] }, { "hash": "5b13d29c4a5612eb182418e5de55c8374619ee5c", "msg": "numarray port \"first draft\" changes.", "author": { "name": "jmiller", "email": "jmiller@localhost" }, "committer": { "name": "jmiller", "email": "jmiller@localhost" }, "author_date": "2004-12-03T22:41:55+00:00", "author_timezone": 0, "committer_date": "2004-12-03T22:41:55+00:00", "committer_timezone": 0, "branches": [ "main" ], "in_main_branch": true, "merge": false, "parents": [ "7d87fa78d5658ae8ea96e3676970c1fbfd5f4743" ], "project_name": "repo_copy", "project_path": "/tmp/tmpqop781_j/repo_copy", "deletions": 640, "insertions": 976, "lines": 1616, "files": 23, "dmm_unit_size": 0.08333333333333333, "dmm_unit_complexity": 0.6111111111111112, "dmm_unit_interfacing": 0.0, "modified_files": [ { "old_path": "scipy_base/__init__.py", "new_path": "scipy_base/__init__.py", "filename": "__init__.py", "extension": "py", "change_type": "MODIFY", "diff": "@@ -2,23 +2,8 @@\n from info_scipy_base import __doc__\n from scipy_base_version import scipy_base_version as __version__\n \n-from ppimport import ppimport, ppimport_attr, ppresolve\n-\n-# The following statement is equivalent to\n-#\n-# from Matrix import Matrix as mat\n-#\n-# but avoids expensive LinearAlgebra import when\n-# Matrix is not used.\n-mat = ppimport_attr(ppimport('Matrix'), 'Matrix')\n-\n-# Force Numeric to use scipy_base.fastumath instead of Numeric.umath.\n-import fastumath # no need to use scipy_base.fastumath\n-import sys as _sys\n-_sys.modules['umath'] = fastumath\n-\n-import Numeric\n-from Numeric import *\n+import numerix\n+from numerix import *\n \n import limits\n from type_check import *\n@@ -27,25 +12,15 @@\n from shape_base import *\n from matrix_base import *\n \n-\n-\n from polynomial import *\n from scimath import *\n from machar import *\n from pexec import *\n \n-if Numeric.__version__ < '23.5':\n- matrixmultiply=dot\n-\n-Inf = inf = fastumath.PINF\n-try:\n- NAN = NaN = nan = fastumath.NAN\n-except AttributeError:\n- NaN = NAN = nan = fastumath.PINF/fastumath.PINF\n-\n from scipy_test.testing import ScipyTest\n test = ScipyTest('scipy_base').test\n \n+import sys as _sys\n if _sys.modules.has_key('scipy_base.Matrix') \\\n and _sys.modules['scipy_base.Matrix'] is None:\n del _sys.modules['scipy_base.Matrix']\n", "added_lines": 3, "deleted_lines": 28, "source_code": "\nfrom info_scipy_base import __doc__\nfrom scipy_base_version import scipy_base_version as __version__\n\nimport numerix\nfrom numerix import *\n\nimport limits\nfrom type_check import *\nfrom index_tricks import *\nfrom function_base import *\nfrom shape_base import *\nfrom matrix_base import *\n\nfrom polynomial import *\nfrom scimath import *\nfrom machar import *\nfrom pexec import *\n\nfrom scipy_test.testing import ScipyTest\ntest = ScipyTest('scipy_base').test\n\nimport sys as _sys\nif _sys.modules.has_key('scipy_base.Matrix') \\\n and _sys.modules['scipy_base.Matrix'] is None:\n del _sys.modules['scipy_base.Matrix']\n\n", "source_code_before": "\nfrom info_scipy_base import __doc__\nfrom scipy_base_version import scipy_base_version as __version__\n\nfrom ppimport import ppimport, ppimport_attr, ppresolve\n\n# The following statement is equivalent to\n#\n# from Matrix import Matrix as mat\n#\n# but avoids expensive LinearAlgebra import when\n# Matrix is not used.\nmat = ppimport_attr(ppimport('Matrix'), 'Matrix')\n\n# Force Numeric to use scipy_base.fastumath instead of Numeric.umath.\nimport fastumath # no need to use scipy_base.fastumath\nimport sys as _sys\n_sys.modules['umath'] = fastumath\n\nimport Numeric\nfrom Numeric import *\n\nimport limits\nfrom type_check import *\nfrom index_tricks import *\nfrom function_base import *\nfrom shape_base import *\nfrom matrix_base import *\n\n\n\nfrom polynomial import *\nfrom scimath import *\nfrom machar import *\nfrom pexec import *\n\nif Numeric.__version__ < '23.5':\n matrixmultiply=dot\n\nInf = inf = fastumath.PINF\ntry:\n NAN = NaN = nan = fastumath.NAN\nexcept AttributeError:\n NaN = NAN = nan = fastumath.PINF/fastumath.PINF\n\nfrom scipy_test.testing import ScipyTest\ntest = ScipyTest('scipy_base').test\n\nif _sys.modules.has_key('scipy_base.Matrix') \\\n and _sys.modules['scipy_base.Matrix'] is None:\n del _sys.modules['scipy_base.Matrix']\n\n", "methods": [], "methods_before": [], "changed_methods": [], "nloc": 20, "complexity": 0, "token_count": 99, "diff_parsed": { "added": [ "import numerix", "from numerix import *", "import sys as _sys" ], "deleted": [ "from ppimport import ppimport, ppimport_attr, ppresolve", "", "# The following statement is equivalent to", "#", "# from Matrix import Matrix as mat", "#", "# but avoids expensive LinearAlgebra import when", "# Matrix is not used.", "mat = ppimport_attr(ppimport('Matrix'), 'Matrix')", "", "# Force Numeric to use scipy_base.fastumath instead of Numeric.umath.", "import fastumath # no need to use scipy_base.fastumath", "import sys as _sys", "_sys.modules['umath'] = fastumath", "", "import Numeric", "from Numeric import *", "", "", "if Numeric.__version__ < '23.5':", " matrixmultiply=dot", "", "Inf = inf = fastumath.PINF", "try:", " NAN = NaN = nan = fastumath.NAN", "except AttributeError:", " NaN = NAN = nan = fastumath.PINF/fastumath.PINF", "" ] } }, { "old_path": "scipy_base/_compiled_base.c", "new_path": "scipy_base/_compiled_base.c", "filename": "_compiled_base.c", "extension": "c", "change_type": "MODIFY", "diff": "@@ -1,11 +1,22 @@\n-\n #include \"Python.h\"\n-#include \"Numeric/arrayobject.h\"\n-#include \"Numeric/ufuncobject.h\"\n-\n+#include \"numerix.h\"\n+\n+/* Copy of PyArray_Converter... */\n+static int \n+_Converter(PyObject *object, PyObject **address) {\n+\tif (PyArray_Check(object)) {\n+\t\t*address = object;\n+\t\treturn 1;\n+\t}\n+\telse {\n+\t\tPyErr_SetString(\n+\t\t\tPyExc_TypeError,\n+\t\t\t\"expected Array object in one of the arguments\");\n+\t\treturn 0;\n+\t}\n+}\n \n static char doc_base_unique[] = \"Return the unique elements of a 1-D sequence.\";\n-\n static PyObject *base_unique(PyObject *self, PyObject *args, PyObject *kwdict)\n {\n /* Returns a 1-D array containing the unique elements of a 1-D sequence.\n@@ -21,8 +32,9 @@ static PyObject *base_unique(PyObject *self, PyObject *args, PyObject *kwdict)\n \n static char *kwlist[] = {\"input\", NULL};\n \n- if (!PyArg_ParseTupleAndKeywords(args, kwdict, \"O!\", kwlist, &PyArray_Type, &ainput)) \n- return NULL;\n+ if (!PyArg_ParseTupleAndKeywords(\n+\t args, kwdict, \"O&\", kwlist, _Converter, &ainput)) \n+\t return NULL;\n \n if (ainput->nd > 1) {\n PyErr_SetString(PyExc_ValueError, \"Input array must be < 1 dimensional\");\n@@ -84,7 +96,6 @@ static PyObject *base_insert(PyObject *self, PyObject *args, PyObject *kwdict)\n /* Returns input array with values inserted sequentially into places \n indicated by the mask\n */\n-\n PyObject *mask=NULL, *vals=NULL;\n PyArrayObject *ainput=NULL, *amask=NULL, *avals=NULL, *avalscast=NULL, *tmp=NULL;\n int numvals, totmask, sameshape;\n@@ -95,7 +106,8 @@ static PyObject *base_insert(PyObject *self, PyObject *args, PyObject *kwdict)\n \n static char *kwlist[] = {\"input\",\"mask\",\"vals\",NULL};\n \n- if (!PyArg_ParseTupleAndKeywords(args, kwdict, \"O!OO\", kwlist, &PyArray_Type, &ainput, &mask, &vals))\n+ if (!PyArg_ParseTupleAndKeywords(\n+\t args, kwdict, \"O&OO\", kwlist, _Converter, &ainput, &mask, &vals))\n return NULL;\n \n /* Fixed problem with OBJECT ARRAYS\n@@ -105,7 +117,8 @@ static PyObject *base_insert(PyObject *self, PyObject *args, PyObject *kwdict)\n }\n */\n \n- amask = (PyArrayObject *)PyArray_ContiguousFromObject(mask, PyArray_NOTYPE, 0, 0);\n+ amask = (PyArrayObject *) PyArray_ContiguousFromObject(\n+\t mask, PyArray_NOTYPE, 0, 0);\n if (amask == NULL) return NULL;\n /* Cast an object array */\n if (amask->descr->type_num == PyArray_OBJECT) {\n@@ -143,7 +156,7 @@ static PyObject *base_insert(PyObject *self, PyObject *args, PyObject *kwdict)\n melsize = amask->descr->elsize;\n vptr = avalscast->data;\n delsize = avalscast->descr->elsize;\n- zero = amask->descr->zero;\n+ zero = NX_ZERO(amask);\n objarray = (ainput->descr->type_num == PyArray_OBJECT);\n \n /* Handle zero-dimensional case separately */\n@@ -369,8 +382,6 @@ static int type_from_char(char typechar)\n }\n }\n \n-\n-\n /* This sets up the output arrays by calling the function with arguments \n the first element of each input arrays. If otypes is NULL, the\n returned value type is used to establish the type of the output\n@@ -399,7 +410,7 @@ static int setup_output_arrays(PyObject *func, PyArrayObject **inarr, int nin, P\n for (i=0; i < nin; i++) {\n tmparr = inarr[i];\n /* Get first data point */\n- tmpobject = tmparr->descr->getitem((void *)tmparr->data);\n+ tmpobject = NX_GETITEM(tmparr, tmparr->data);\n if (NULL == tmpobject) {\n \tPy_DECREF(arglist);\n \treturn -1;\n@@ -552,68 +563,70 @@ static int loop_over_arrays(PyObject *func, PyArrayObject **inarr, int nin, PyAr\n loop_index = PyArray_Size((PyObject *)in); /* Total number of Python function calls */\n \n while(loop_index--) { \n- /* Create input argument list with current element from the input\n- arrays \n- */\n- for (i=0; i < nin; i++) {\n-\n- tmparr = inarr[i];\n- /* Find linear index into this input array */\n- CALCINDEX(indx_in,nd_index,tmparr->strides,in->nd);\n- /* Get object at this index */\n- tmpobj = tmparr->descr->getitem((void *)(tmparr->data+indx_in));\n- if (NULL == tmpobj) {\n-\tPy_DECREF(arglist);\n-\tfree(nd_index);\n-\treturn -1;\n- }\n- /* This steals reference of tmpobj */\n- PyTuple_SET_ITEM(arglist, i, tmpobj); \n- }\n-\n- /* Call Python Function for this set of inputs */\n- if ((result=PyEval_CallObject(func, arglist))==NULL) {\n- Py_DECREF(arglist);\n- free(nd_index);\n- return -1;\n- } \n-\n-\n-\n- /* Find index into (all) output arrays */\n- CALCINDEX(indx_out,nd_index,out->strides,out->nd);\n-\n- /* Copy the results to the output arrays */\n- if (1==nout) {\n- if ((outarr[0]->descr->setitem(result,(outarr[0]->data+indx_out)))==-1) {\n-\tfree(nd_index);\n-\tPy_DECREF(arglist);\n-\tPy_DECREF(result);\n-\treturn -1;\n- }\n- }\n- else if (PyTuple_Check(result)) {\n- for (i=0; idescr->setitem(PyTuple_GET_ITEM(result,i),(outarr[i]->data+indx_out)))==-1) {\n-\t free(nd_index);\n-\t Py_DECREF(arglist);\n+\t /* Create input argument list with current element from the input\n+\t arrays \n+\t */\n+\t for (i=0; i < nin; i++) {\n+\t\t \n+\t\t tmparr = inarr[i];\n+\t\t /* Find linear index into this input array */\n+\t\t CALCINDEX(indx_in,nd_index,tmparr->strides,in->nd);\n+\t\t /* Get object at this index */\n+\t\t tmpobj = NX_GETITEM(tmparr, (tmparr->data+indx_in));\n+\t\t if (NULL == tmpobj) {\n+\t\t\t Py_DECREF(arglist);\n+\t\t\t free(nd_index);\n+\t\t\t return -1;\n+\t\t }\n+\t\t /* This steals reference of tmpobj */\n+\t\t PyTuple_SET_ITEM(arglist, i, tmpobj); \n+\t }\n+\t \n+\t /* Call Python Function for this set of inputs */\n+\t if ((result=PyEval_CallObject(func, arglist))==NULL) {\n+\t\t Py_DECREF(arglist);\n+\t\t free(nd_index);\n+\t\t return -1;\n+\t } \n+\t \n+\t /* Find index into (all) output arrays */\n+\t CALCINDEX(indx_out,nd_index,out->strides,out->nd);\n+\t \n+\t /* Copy the results to the output arrays */\n+\t if (1==nout) {\n+\t\t int rval = NX_SETITEM(\n+\t\t\t outarr[0], (outarr[0]->data+indx_out), result);\n+\t\t if (rval==-1) {\n+\t\t\t free(nd_index);\n+\t\t\t Py_DECREF(arglist);\n+\t\t\t Py_DECREF(result);\n+\t\t\t return -1;\n+\t\t }\n+\t }\n+\t else if (PyTuple_Check(result)) {\n+\t\t for (i=0; idata+indx_out), \n+\t\t\t\t PyTuple_GET_ITEM(result,i));\n+\t\t\t free(nd_index);\n+\t\t\t Py_DECREF(arglist);\n+\t\t\t Py_DECREF(result);\n+\t\t\t return -1;\n+\t\t }\n+\t \n+\t } else { \n+\t\t PyErr_SetString(PyExc_ValueError,\"arraymap: Function output of incorrect type.\");\n+\t\t free(nd_index);\n+\t\t Py_DECREF(arglist);\n+\t\t Py_DECREF(result);\n+\t\t return -1;\n+\t }\n+\n+\t /* Increment the index counter */\n+\t INCREMENT(nd_index,in->nd,in->dimensions);\n \t Py_DECREF(result);\n- return -1;\n-\t}\n- }\n- }\n- else { \n- PyErr_SetString(PyExc_ValueError,\"arraymap: Function output of incorrect type.\");\n- free(nd_index);\n- Py_DECREF(arglist);\n- Py_DECREF(result);\n- return -1;\n- }\n-\n- /* Increment the index counter */\n- INCREMENT(nd_index,in->nd,in->dimensions);\n- Py_DECREF(result);\n-\n+\t \n }\n Py_DECREF(arglist);\n free(nd_index);\n@@ -688,234 +701,42 @@ static PyObject *map_PyFunc(PyObject *self, PyObject *args)\n return out;\n }\n \n-/* CODE BELOW is used to Update Numeric object behavior */\n-\n-/* A copy of the original PyArrayType structure is kept and can be used\n- to restore the original Numeric behavior at any time. \n-*/\n-\n-static PyTypeObject BackupPyArray_Type;\n-static PyTypeObject BackupPyUFunc_Type;\n-static PyNumberMethods backup_array_as_number;\n-static PySequenceMethods backup_array_as_sequence;\n-static PyMappingMethods backup_array_as_mapping;\n-static PyBufferProcs backup_array_as_buffer;\n-static int scipy_numeric_stored = 0;\n-\n-#ifndef PyUFunc_Type\n-#define PyUFunc_Type PyUfunc_Type /* fix bug in Numeric < 23.3 */\n-#endif\n-\n-/* make sure memory copy is going on with this */\n-void scipy_numeric_save() {\n-\n- /* we just save copies of things we may alter. */\n- if (!scipy_numeric_stored) {\n- BackupPyUFunc_Type.tp_name = (PyUFunc_Type).tp_name;\n- BackupPyUFunc_Type.tp_call = (PyUFunc_Type).tp_call;\n-\n-\tBackupPyArray_Type.tp_name = (PyArray_Type).tp_name;\n-\tBackupPyArray_Type.tp_getattr = (PyArray_Type).tp_getattr;\n-\n-\tmemcpy(&backup_array_as_number, (PyArray_Type).tp_as_number,\n-\t sizeof(PyNumberMethods));\n-\tmemcpy(&backup_array_as_sequence, (PyArray_Type).tp_as_sequence,\n-\t sizeof(PySequenceMethods));\n-\tmemcpy(&backup_array_as_mapping, (PyArray_Type).tp_as_mapping,\n-\t sizeof(PyMappingMethods));\n-\tmemcpy(&backup_array_as_buffer, (PyArray_Type).tp_as_buffer,\n-\t sizeof(PyBufferProcs));\n-\tscipy_numeric_stored = 1;\n- }\n-}\n-\n-void scipy_numeric_restore() {\n-\n- /* restore only what was copied */\n- if (scipy_numeric_stored) {\n-\t(PyUFunc_Type).tp_name = BackupPyUFunc_Type.tp_name;\n-\t(PyUFunc_Type).tp_call = BackupPyUFunc_Type.tp_call;\t\n-\n-\t(PyArray_Type).tp_name = BackupPyArray_Type.tp_name;\n-\t(PyArray_Type).tp_getattr = BackupPyArray_Type.tp_getattr;\n-\n-\tmemcpy((PyArray_Type).tp_as_number, &backup_array_as_number, \n-\t sizeof(PyNumberMethods));\n-\tmemcpy((PyArray_Type).tp_as_sequence, &backup_array_as_sequence, \n-\t sizeof(PySequenceMethods));\n-\tmemcpy((PyArray_Type).tp_as_mapping, &backup_array_as_mapping,\n-\t sizeof(PyMappingMethods));\n-\tmemcpy((PyArray_Type).tp_as_buffer, &backup_array_as_buffer,\n-\t sizeof(PyBufferProcs));\n- }\n-}\n-\n-static const char *_scipy_array_str = \"array (scipy)\";\n-static const char *_scipy_ufunc_str = \"ufunc (scipy)\";\n-\n-#define MAX_DIMS 30\n-#include \"_scipy_mapping.c\"\n-\n-static PyMappingMethods scipy_array_as_mapping = {\n- (inquiry)scipy_array_length,\t\t/*mp_length*/\n- (binaryfunc)scipy_array_subscript_nice, /*mp_subscript*/\n- (objobjargproc)scipy_array_ass_sub,\t /*mp_ass_subscript*/\n-};\n-\n-#define MAX_ARGS 10\n-#include \"_scipy_number.c\"\n-\n-static PyNumberMethods scipy_array_as_number = {\n- (binaryfunc)scipy_array_add, /*nb_add*/\n- (binaryfunc)scipy_array_subtract, /*nb_subtract*/\n- (binaryfunc)scipy_array_multiply, /*nb_multiply*/\n- (binaryfunc)scipy_array_divide, /*nb_divide*/\n- (binaryfunc)scipy_array_remainder, /*nb_remainder*/\n- (binaryfunc)scipy_array_divmod, /*nb_divmod*/\n- (ternaryfunc)scipy_array_power, /*nb_power*/\n- (unaryfunc)scipy_array_negative, \n- (unaryfunc)scipy_array_copy, /*nb_pos*/ \n- (unaryfunc)scipy_array_absolute, /*(unaryfunc)scipy_array_abs,*/\n- (inquiry)scipy_array_nonzero, /*nb_nonzero*/\n- (unaryfunc)scipy_array_invert, /*nb_invert*/\n- (binaryfunc)scipy_array_left_shift, /*nb_lshift*/\n- (binaryfunc)scipy_array_right_shift, /*nb_rshift*/\n- (binaryfunc)scipy_array_bitwise_and, /*nb_and*/\n- (binaryfunc)scipy_array_bitwise_xor, /*nb_xor*/\n- (binaryfunc)scipy_array_bitwise_or, /*nb_or*/\n- (coercion)scipy_array_coerce, /*nb_coerce*/\n- (unaryfunc)scipy_array_int, /*nb_int*/\n- (unaryfunc)scipy_array_long, /*nb_long*/\n- (unaryfunc)scipy_array_float, /*nb_float*/\n- (unaryfunc)scipy_array_oct,\t /*nb_oct*/\n- (unaryfunc)scipy_array_hex,\t /*nb_hex*/\n-\n- /*This code adds augmented assignment functionality*/\n- /*that was made available in Python 2.0*/\n- (binaryfunc)scipy_array_inplace_add, /*inplace_add*/\n- (binaryfunc)scipy_array_inplace_subtract, /*inplace_subtract*/\n- (binaryfunc)scipy_array_inplace_multiply, /*inplace_multiply*/\n- (binaryfunc)scipy_array_inplace_divide, /*inplace_divide*/\n- (binaryfunc)scipy_array_inplace_remainder, /*inplace_remainder*/\n- (ternaryfunc)scipy_array_inplace_power, /*inplace_power*/\n- (binaryfunc)scipy_array_inplace_left_shift, /*inplace_lshift*/\n- (binaryfunc)scipy_array_inplace_right_shift, /*inplace_rshift*/\n- (binaryfunc)scipy_array_inplace_bitwise_and, /*inplace_and*/\n- (binaryfunc)scipy_array_inplace_bitwise_xor, /*inplace_xor*/\n- (binaryfunc)scipy_array_inplace_bitwise_or, /*inplace_or*/\n-\n- /* Added in release 2.2 */\n-\t/* The following require the Py_TPFLAGS_HAVE_CLASS flag */\n-#if PY_VERSION_HEX >= 0x02020000\n-\t(binaryfunc)scipy_array_floor_divide, /*nb_floor_divide*/\n-\t(binaryfunc)scipy_array_true_divide, /*nb_true_divide*/\n-\t(binaryfunc)scipy_array_inplace_floor_divide, /*nb_inplace_floor_divide*/\n-\t(binaryfunc)scipy_array_inplace_true_divide, /*nb_inplace_true_divide*/\n-#endif\n-};\n-\n-static PyObject *_scipy_getattr(PyArrayObject *self, char *name) {\n- PyArrayObject *ret;\n-\t\n- if (strcmp(name, \"M\") == 0) {\n-\tPyObject *fm, *o;\n-\t\n- /* Call the array constructor registered as matrix_base.matrix\n-\t or else raise exception if nothing registered */\n-\t\t\n-\t/* Import matrix_base module */\n-\tfm = PyImport_ImportModule(\"scipy_base.matrix_base\");\n-\to = PyObject_CallMethod(fm,\"matrix\",\"O\",(PyObject *)self);\n-\tif (ret == NULL) {\n-\t PyErr_SetString(PyExc_ReferenceError, \"Error using scipy_base.matrix_base.matrix to construct matrix representation\");\n-\t Py_XDECREF(fm);\n-\t return NULL;\n-\t}\n-\tPy_XDECREF(fm);\t\n-\treturn o;\n- }\n-\n- return (BackupPyArray_Type.tp_getattr)((void *)self, name);\n-}\n-\n-\n-void scipy_numeric_alter() {\n- \n- (PyArray_Type).tp_name = _scipy_array_str;\n- (PyArray_Type).tp_getattr = (getattrfunc)_scipy_getattr;\n- memcpy((PyArray_Type).tp_as_mapping, &scipy_array_as_mapping,\n-\t sizeof(PyMappingMethods));\n- memcpy((PyArray_Type).tp_as_number, &scipy_array_as_number,\n- sizeof(PyNumberMethods));\n-\n- (PyUFunc_Type).tp_call = (ternaryfunc)scipy_ufunc_call;\n- (PyUFunc_Type).tp_name = _scipy_ufunc_str;\n-}\n-\n-static char numeric_alter_doc[] = \"alter_numeric() update the behavior of Numeric objects.\\n\\n 1. Change coercion rules so that multiplying by a scalar does not upcast.\\n 2. Add index and mask slicing capability to Numeric arrays.\\n 3. Add .M attribute to Numeric arrays for returning a Matrix 4. (TODO) Speed enhancements.\\n\\nThis call changes the behavior for ALL Numeric arrays currently defined\\n and to be defined in the future. The old behavior can be restored for ALL\\n arrays using numeric_restore().\";\n-\n-static PyObject *numeric_behavior_alter(PyObject *self, PyObject *args)\n-{\n-\n- if (!PyArg_ParseTuple ( args, \"\")) return NULL;\n-\n- scipy_numeric_save();\n- scipy_numeric_alter();\n- Py_INCREF(Py_None);\n- return Py_None;\n-}\n-\n-static char numeric_restore_doc[] = \"restore_numeric() restore the default behavior of Numeric objects.\\n\\n SEE alter_numeric.\\n\";\n-\n-static PyObject *numeric_behavior_restore(PyObject *self, PyObject *args)\n-{\n-\n- if (!PyArg_ParseTuple ( args, \"\")) return NULL;\n- scipy_numeric_restore();\n- Py_INCREF(Py_None);\n- return Py_None;\n-}\n-\n-\n static struct PyMethodDef methods[] = {\n {\"arraymap\", map_PyFunc, METH_VARARGS, arraymap_doc},\n {\"_unique\",\t (PyCFunction)base_unique, METH_VARARGS | METH_KEYWORDS, \n doc_base_unique},\n {\"_insert\",\t (PyCFunction)base_insert, METH_VARARGS | METH_KEYWORDS, \n doc_base_insert},\n- {\"alter_numeric\", numeric_behavior_alter, METH_VARARGS, \n- numeric_alter_doc},\n- {\"restore_numeric\", numeric_behavior_restore, METH_VARARGS, \n- numeric_restore_doc},\n {NULL, NULL} /* sentinel */\n };\n \n /* Initialization function for the module (*must* be called initArray) */\n \n-DL_EXPORT(void) init_compiled_base(void) {\n- PyObject *m, *d, *s, *fm=NULL, *fd=NULL;\n+#if defined(NUMERIC)\n+DL_EXPORT(void) init_nc_compiled_base(void) {\n+#else\n+DL_EXPORT(void) init_na_compiled_base(void) {\n+#endif\n+ PyObject *m, *d, *s;\n \n /* Create the module and add the functions */\n- m = Py_InitModule(\"_compiled_base\", methods); \n+#if defined(NUMERIC)\n+ m = Py_InitModule(\"_nc_compiled_base\", methods); \n+#else\n+ m = Py_InitModule(\"_na_compiled_base\", methods); \n+#endif\n \n /* Import the array and ufunc objects */\n import_array();\n- import_ufunc();\n \n /* Add some symbolic constants to the module */\n d = PyModule_GetDict(m);\n \n- /* Import Fastumath module */\n- fm = PyImport_ImportModule(\"fastumath\");\n- fd = PyModule_GetDict(fm);\n- scipy_SetNumericOps(fd);\n- Py_XDECREF(fm);\n-\n- s = PyString_FromString(\"0.2\");\n+ s = PyString_FromString(\"0.3\");\n PyDict_SetItemString(d, \"__version__\", s);\n Py_DECREF(s);\n \n /* Check for errors */\n if (PyErr_Occurred())\n-\tPy_FatalError(\"can't initialize module _compiled_base\");\n+\t Py_FatalError(\"can't initialize module _compiled_base\");\n }\n", "added_lines": 101, "deleted_lines": 280, "source_code": "#include \"Python.h\"\n#include \"numerix.h\"\n\n/* Copy of PyArray_Converter... */\nstatic int \n_Converter(PyObject *object, PyObject **address) {\n\tif (PyArray_Check(object)) {\n\t\t*address = object;\n\t\treturn 1;\n\t}\n\telse {\n\t\tPyErr_SetString(\n\t\t\tPyExc_TypeError,\n\t\t\t\"expected Array object in one of the arguments\");\n\t\treturn 0;\n\t}\n}\n\nstatic char doc_base_unique[] = \"Return the unique elements of a 1-D sequence.\";\nstatic PyObject *base_unique(PyObject *self, PyObject *args, PyObject *kwdict)\n{\n /* Returns a 1-D array containing the unique elements of a 1-D sequence.\n */\n\n void *new_mem=NULL;\n PyArrayObject *ainput=NULL, *aoutput=NULL;\n int asize, abytes, new;\n int copied=0, nd;\n int instride=0, elsize, k, j, dims[1];\n char *ip, *op; /* Current memory buffer */\n char *op2;\n \n static char *kwlist[] = {\"input\", NULL};\n\n if (!PyArg_ParseTupleAndKeywords(\n\t args, kwdict, \"O&\", kwlist, _Converter, &ainput)) \n\t return NULL;\n \n if (ainput->nd > 1) {\n PyErr_SetString(PyExc_ValueError, \"Input array must be < 1 dimensional\");\n return NULL;\n }\n asize = PyArray_SIZE(ainput);\n elsize = ainput->descr->elsize;\n abytes = asize * elsize;\n nd = ainput->nd;\n if (nd > 0) {\n instride = ainput->strides[0];\n }\n\n new_mem = (void *)PyMem_Malloc((size_t) abytes);\n if (new_mem == NULL) {\n return PyErr_NoMemory();\n }\n \n ip = ainput->data;\n op = new_mem;\n for (k=0; k < asize; k++,ip+=instride) {\n new = 1; /* Assume it is new */\n op2 = new_mem;\n for (j=0; j < copied; j++,op2+=elsize) {\n if (memcmp(op2,ip,elsize) == 0) { /* Is a match found? */\n new = 0;\n break;\n }\n }\n /* No match found, copy this one over */\n if (new) {\n memcpy(op,ip,elsize);\n copied += 1;\n op += elsize; /* Get ready to put next match */\n }\n }\n\n dims[0] = copied;\n /* Make output array */\n if ((aoutput = (PyArrayObject *)PyArray_FromDims(nd, \n dims, ainput->descr->type_num))==NULL) goto fail;\n\n memcpy(aoutput->data,new_mem,elsize*copied);\n /* Reallocate memory to new-size */\n PyMem_Free(new_mem);\n return PyArray_Return(aoutput); \n \n fail:\n if (new_mem != NULL) PyMem_Free(new_mem);\n Py_XDECREF(aoutput);\n return NULL;\n}\n\n\nstatic char doc_base_insert[] = \"Insert vals sequenctially into equivalent 1-d positions indicated by mask.\";\n\nstatic PyObject *base_insert(PyObject *self, PyObject *args, PyObject *kwdict)\n{\n /* Returns input array with values inserted sequentially into places \n indicated by the mask\n */\n PyObject *mask=NULL, *vals=NULL;\n PyArrayObject *ainput=NULL, *amask=NULL, *avals=NULL, *avalscast=NULL, *tmp=NULL;\n int numvals, totmask, sameshape;\n char *input_data, *mptr, *vptr, *zero;\n int melsize, delsize, copied, nd;\n int *instrides, *inshape;\n int mindx, rem_indx, indx, i, k, objarray;\n \n static char *kwlist[] = {\"input\",\"mask\",\"vals\",NULL};\n\n if (!PyArg_ParseTupleAndKeywords(\n\t args, kwdict, \"O&OO\", kwlist, _Converter, &ainput, &mask, &vals))\n return NULL;\n\n /* Fixed problem with OBJECT ARRAYS\n if (ainput->descr->type_num == PyArray_OBJECT) {\n PyErr_SetString(PyExc_ValueError, \"Not currently supported for Object arrays.\");\n return NULL;\n }\n */\n\n amask = (PyArrayObject *) PyArray_ContiguousFromObject(\n\t mask, PyArray_NOTYPE, 0, 0);\n if (amask == NULL) return NULL;\n /* Cast an object array */\n if (amask->descr->type_num == PyArray_OBJECT) {\n tmp = (PyArrayObject *)PyArray_Cast(amask, PyArray_LONG);\n if (tmp == NULL) goto fail;\n Py_DECREF(amask);\n amask = tmp;\n }\n\n sameshape = 1;\n if (amask->nd == ainput->nd) {\n for (k=0; k < amask->nd; k++) \n if (amask->dimensions[k] != ainput->dimensions[k])\n sameshape = 0;\n }\n else { /* Test to see if amask is 1d */\n if (amask->nd != 1) sameshape = 0;\n else if ((PyArray_SIZE(ainput)) != PyArray_SIZE(amask)) sameshape = 0;\n }\n if (!sameshape) {\n PyErr_SetString(PyExc_ValueError, \"Mask array must be 1D or same shape as input array.\");\n goto fail;\n }\n\n avals = (PyArrayObject *)PyArray_FromObject(vals, PyArray_NOTYPE, 0, 1);\n if (avals == NULL) goto fail;\n avalscast = (PyArrayObject *)PyArray_Cast(avals, ainput->descr->type_num);\n if (avalscast == NULL) goto fail;\n Py_DECREF(avals);\n\n numvals = PyArray_SIZE(avalscast);\n nd = ainput->nd;\n input_data = ainput->data;\n mptr = amask->data;\n melsize = amask->descr->elsize;\n vptr = avalscast->data;\n delsize = avalscast->descr->elsize;\n zero = NX_ZERO(amask);\n objarray = (ainput->descr->type_num == PyArray_OBJECT);\n \n /* Handle zero-dimensional case separately */\n if (nd == 0) {\n if (memcmp(mptr,zero,melsize) != 0) {\n /* Copy value element over to input array */\n memcpy(input_data,vptr,delsize);\n if (objarray) Py_INCREF(*((PyObject **)vptr));\n }\n Py_DECREF(amask);\n Py_DECREF(avalscast);\n Py_INCREF(Py_None);\n return Py_None;\n }\n\n /* Walk through mask array, when non-zero is encountered\n copy next value in the vals array to the input array.\n If we get through the value array, repeat it as necessary. \n */\n totmask = PyArray_SIZE(amask);\n copied = 0;\n instrides = ainput->strides;\n inshape = ainput->dimensions;\n for (mindx = 0; mindx < totmask; mindx++) { \n if (memcmp(mptr,zero,melsize) != 0) { \n /* compute indx into input array \n */\n rem_indx = mindx;\n indx = 0;\n for(i=nd-1; i > 0; --i) {\n indx += (rem_indx % inshape[i]) * instrides[i];\n rem_indx /= inshape[i];\n }\n indx += rem_indx * instrides[0];\n /* fprintf(stderr, \"mindx = %d, indx=%d\\n\", mindx, indx); */\n /* Copy value element over to input array */\n memcpy(input_data+indx,vptr,delsize);\n if (objarray) Py_INCREF(*((PyObject **)vptr));\n vptr += delsize;\n copied += 1;\n /* If we move past value data. Reset */\n if (copied >= numvals) vptr = avalscast->data;\n }\n mptr += melsize;\n }\n\n Py_DECREF(amask);\n Py_DECREF(avalscast);\n Py_INCREF(Py_None);\n return Py_None;\n \n fail:\n Py_XDECREF(amask);\n Py_XDECREF(avals);\n Py_XDECREF(avalscast);\n return NULL;\n}\n\n\n/* Decrement the reference count of all objects in **arrays. */\nstatic void cleanup_arrays(PyArrayObject **arrays, int number)\n{\n int k;\n for (k=0; k < number; k++)\n Py_XDECREF((PyObject *)arrays[k]);\n return;\n}\n\n/* All rank-0 arrays are converted to rank-1 arrays */\n/* The number of dimensions of each array with rank less than\n the rank of the array with the most dimensions is increased by \n prepending with a dimenson length of one so that all arrays have\n the same rank. */\n/* Dimensions are checked and unmatched dimensions triggers an error */\n/* Strides for dimensions whose real length is one is set to zero but the dimension\n length is set to the maximum dimensions for the collection of inputs */\nstatic int setup_input_arrays(PyTupleObject *inputs, PyArrayObject **inputarrays, int nin)\n{\n int i, k;\n int maxrank=1;\n int *maxdims;\n PyObject *inputobj;\n PyArrayObject *ain, *tmparray;\n\n /* Convert nested sequences to arrays or just increase reference count\n if already an array */\n for (i=0; i < nin; i++) {\n ain = NULL;\n inputobj = PyTuple_GET_ITEM(inputs,i);\n ain = (PyArrayObject *)PyArray_FromObject(inputobj,PyArray_ObjectType(inputobj,0),0,0);\n if (NULL == ain) {\n cleanup_arrays(inputarrays,i);\n return -1;\n }\n if (PyArray_SIZE(ain)==0) {\n cleanup_arrays(inputarrays,i);\n PyErr_SetString(PyExc_IndexError,\"arraymap: Input arrays of zero-dimensions not supported.\");\n return -1;\n }\n if (ain->nd > maxrank) maxrank = ain->nd;\n if (ain->nd == 0) { /* turn into 1-d array */\n /* convert to rank-1 array */\n if ((ain->dimensions = (int *)malloc(sizeof(int))) == NULL) {\n PyErr_SetString(PyExc_MemoryError, \"arraymap: can't allocate memory for input arrays\");\n cleanup_arrays(inputarrays,i);\n return -1;\n }\n if ((ain->strides = (int *)malloc(sizeof(int))) == NULL) {\n PyErr_SetString(PyExc_MemoryError, \"arraymap: can't allocate memory for input arrays\");\n cleanup_arrays(inputarrays,i);\n free(ain->dimensions);\n return -1;\n }\n ain->nd = 1;\n ain->dimensions[0] = 1;\n ain->strides[0] = ain->descr->elsize;\n }\n inputarrays[i] = ain;\n }\n\n maxdims = (int*)malloc(2*sizeof(int)*maxrank);\n if (NULL == maxdims) {\n PyErr_SetString(PyExc_MemoryError, \"arraymap: can't allocate memory for input arrays\");\n cleanup_arrays(inputarrays,nin);\n return -1;\n }\n\n\n /* Reshape all arrays so they have the same rank (pre-pend with length 1 dimensions) */\n /* We want to replace the header information without copying the data. \n Keeping the reference count correct can be tricky.\n We want to make a new array object with a different header and decrease the \n reference count of the old one without deallocating the data section */\n for (i=0; i < nin; i++) {\n ain = inputarrays[i];\n\n /* Initialize all dimensions to 1 */\n /* Change array shape */\n for (k=0; k < maxrank; k++) \n maxdims[k] = 1; \n for (k=maxrank-ain->nd; k< maxrank; k++) \n maxdims[k] = ain->dimensions[k-maxrank+ain->nd];\n\n tmparray = (PyArrayObject *)PyArray_FromDimsAndData(maxrank,maxdims,ain->descr->type,ain->data);\n if (NULL == tmparray) {\n free(maxdims);\n cleanup_arrays(inputarrays,nin);\n return -1;\n }\n /* tmparray->strides will be zero where new dimensions were added */\n memmove(tmparray->strides+(maxrank-ain->nd),ain->strides,sizeof(int)*ain->nd);\n tmparray->base = (PyObject *)ain; /* When tmparray is deallocated ain will be too */\n inputarrays[i] = tmparray; /* tmparray is new array */\n }\n\n /* Find dimension length for the output arrays (maximum length for each\n dimension) */\n for (k=0; k < maxrank; k++) { \n maxdims[k] = 1;\n for (i=0; i < nin; i++) \n if (inputarrays[i]->dimensions[k] > maxdims[k])\n\tmaxdims[k] = inputarrays[i]->dimensions[k];\n }\n\n\n /* Now set all lengths for input array dimensions to maxdims \n and make strides equal to zero for arrays whose\n real length is 1 for a particular dimension\n */\n\n for (i=0; idimensions[k]) {\n\tain->strides[k] = 0;\n\tain->dimensions[k] = maxdims[k];\n }\n else if (ain->dimensions[k] != maxdims[k]) {\n\tPyErr_SetString(PyExc_ValueError,\"arraymap: Frames are not aligned (mismatched dimensions).\");\n\tcleanup_arrays(inputarrays,nin);\n\tfree(maxdims);\n\treturn -1;\n }\n }\n }\n\n free(maxdims);\n return 0;\n\n}\n\nstatic int type_from_object(PyObject *obj)\n{\n if (PyArray_Check(obj))\n return ((PyArrayObject *)obj)->descr->type_num;\n if (PyComplex_Check(obj)) return PyArray_CDOUBLE;\n if (PyFloat_Check(obj)) return PyArray_DOUBLE;\n if (PyInt_Check(obj) || PyLong_Check(obj)) return PyArray_LONG;\n PyErr_SetString(PyExc_ValueError, \"arraymap: Invalid type for output array.\");\n return -1;\n}\n\nstatic int type_from_char(char typechar)\n{\n switch(typechar) {\n case 'c': return PyArray_CHAR;\n case 'b': return PyArray_UBYTE;\n case '1': return PyArray_SBYTE;\n case 's': return PyArray_SHORT;\n case 'i': return PyArray_INT;\n#ifdef PyArray_UNSIGNED_TYPES\n case 'w': return PyArray_USHORT;\n case 'u': return PyArray_UINT;\n#endif\n case 'l': return PyArray_LONG;\n case 'f': return PyArray_FLOAT;\n case 'd': return PyArray_DOUBLE;\n case 'F': return PyArray_CFLOAT;\n case 'D': return PyArray_CDOUBLE;\n default:\n PyErr_SetString(PyExc_ValueError, \"arraymap: Invalid type for array\");\n return -1;\n }\n}\n\n/* This sets up the output arrays by calling the function with arguments \n the first element of each input arrays. If otypes is NULL, the\n returned value type is used to establish the type of the output\n arrays, otherwise the characters in otypes determine the\n output types */\nstatic int setup_output_arrays(PyObject *func, PyArrayObject **inarr, int nin, PyArrayObject ***outarr, char *otypes, int numtypes)\n{\n PyObject *arglist, *result;\n PyObject *tmpobject;\n PyArrayObject *tmparr;\n int i, nout;\n int nd, *dimensions, type_num;\n\n nd = inarr[0]->nd;\n dimensions = inarr[0]->dimensions;\n\n if ((numtypes == 0) || (otypes == NULL)) { \n /* Call function to get number of outputs */\n\n /* Build argument list */\n if ((arglist = PyTuple_New(nin)) == NULL) {\n return -1;\n }\n /* Construct input argument by creating a tuple with an element\n from each input array (cast to an appropriate Python Object) */\n for (i=0; i < nin; i++) {\n tmparr = inarr[i];\n /* Get first data point */\n tmpobject = NX_GETITEM(tmparr, tmparr->data);\n if (NULL == tmpobject) {\n\tPy_DECREF(arglist);\n\treturn -1;\n }\n PyTuple_SET_ITEM(arglist, i, tmpobject); /* arg1 owns reference to tmpobj now */\n } \n /* Call Python Function */\n if ((result=PyEval_CallObject(func, arglist))==NULL) {\n Py_DECREF(arglist);\n return -1;\n }\n\n Py_DECREF(arglist);\n\n /* If result is a tuple, create output_arrays according \n to output. */\n if (PyTuple_Check(result)) {\n nout = PyTuple_GET_SIZE(result);\n *outarr = (PyArrayObject **)malloc(nout*sizeof(PyArrayObject *));\n if (NULL == *outarr) {\n\tPyErr_SetString(PyExc_MemoryError, \"arraymap: Cannot allocate memory for output arrays.\");\n\tPy_DECREF(result);\n\treturn -1;\n }\n /* Create nout output arrays */\n for (i=0; i < nout; i++) {\n\t/* Determine type */\n\tif ((type_num=type_from_object(PyTuple_GET_ITEM(result, i)))==-1) {\n\t cleanup_arrays(*outarr,i);\n\t Py_DECREF(result);\n\t free(*outarr);\n\t return -1;\n\t}\n\t/* Create output array */\n\t(*outarr)[i] = (PyArrayObject *)PyArray_FromDims(nd,dimensions,type_num);\n\tif (NULL == (*outarr)[i]) {\n\t cleanup_arrays(*outarr,i);\n\t Py_DECREF(result);\n\t free(*outarr);\n\t return -1;\n\t}\n }\n }\n else { /* Only a single output result */\n nout = 1;\n *outarr = (PyArrayObject **)malloc(nout*sizeof(PyArrayObject *));\n if (NULL==*outarr) {\n\tPyErr_SetString(PyExc_MemoryError,\"arraymap: Cannot allocate memory for output arrays.\");\n\tPy_DECREF(result);\n\treturn -1;\n }\n if ((type_num = type_from_object(result))==-1) {\n\tPy_DECREF(result);\n\tfree(*outarr);\n\treturn -1;\n }\n (*outarr)[0] = (PyArrayObject *)PyArray_FromDims(nd,dimensions,type_num);\n if (NULL == (*outarr)[0]) {\n\tPy_DECREF(result);\n\tfree(*outarr);\n\treturn -1;\n }\n }\n Py_DECREF(result);\n }\n\n else { /* Character output types entered */\n nout = numtypes;\n *outarr = (PyArrayObject **)malloc(nout*sizeof(PyArrayObject *));\n if (NULL==*outarr) {\n PyErr_SetString(PyExc_MemoryError,\"arraymap: Cannot allocate memory for output arrays.\");\n return -1;\n }\n /* Create Output arrays */\n for (i=0; i < nout; i++) {\n /* Get type */\n if ((type_num = type_from_char(otypes[i]))==-1) {\n\tcleanup_arrays(*outarr,i);\n\tfree(*outarr);\n\treturn -1;\n }\n /* Create array */\n (*outarr)[i] = (PyArrayObject *)PyArray_FromDims(nd,dimensions,type_num);\n if (NULL == (*outarr)[i]) {\n\tcleanup_arrays(*outarr,i);\n\tfree(*outarr);\n\treturn -1;\n }\n } \n } \n return nout;\n}\n\n\n/* Corresponding dimensions are assumed to match, check before calling. */\n/* No rank-0 arrays (make them rank-1 arrays) */\n\n/* This replicates the standard Ufunc broadcasting rule that if the\n dimension length is one, incrementing does not occur for that dimension. \n\n This is currently done by setting the stride in that dimension to\n zero during input array setup.\n\n The purpose of this function is to perform a for loop over arbitrary\n discontiguous N-D arrays, call the Python function for each set of \n corresponding elements and place the results in the output_array.\n*/ \n#define INCREMENT(ret_ind, nd, max_ind) \\\n{ \\\n int k; \\\n k = (nd) - 1; \\\n if (++(ret_ind)[k] >= (max_ind)[k]) { \\\n while (k >= 0 && ((ret_ind)[k] >= (max_ind)[k]-1)) \\\n (ret_ind)[k--] = 0; \\\n if (k >= 0) (ret_ind)[k]++; \\\n else (ret_ind)[0] = (max_ind)[0]; \\\n } \\\n}\n\n#define CALCINDEX(indx, nd_index, strides, ndim) \\\n{ \\\n int i; \\\n \\\n indx = 0; \\\n for (i=0; i < (ndim); i++) \\\n indx += (nd_index)[i]*(strides)[i]; \\\n} \n\nstatic int loop_over_arrays(PyObject *func, PyArrayObject **inarr, int nin, PyArrayObject **outarr, int nout)\n{\n int i, loop_index;\n int *nd_index, indx_in, indx_out;\n PyArrayObject *in, *out, *tmparr;\n PyObject *result, *tmpobj, *arglist;\n\n in = inarr[0]; /* For any shape information needed */\n out = outarr[0];\n /* Allocate the N-D index initalized to zero. */\n nd_index = (int *)calloc(in->nd,sizeof(int));\n if (NULL == nd_index) {\n PyErr_SetString(PyExc_MemoryError,\"arraymap: Cannot allocate memory for arrays.\");\n return -1;\n }\n /* Build argument list */\n if ((arglist = PyTuple_New(nin)) == NULL) {\n free(nd_index);\n return -1;\n }\n\n loop_index = PyArray_Size((PyObject *)in); /* Total number of Python function calls */\n\n while(loop_index--) { \n\t /* Create input argument list with current element from the input\n\t arrays \n\t */\n\t for (i=0; i < nin; i++) {\n\t\t \n\t\t tmparr = inarr[i];\n\t\t /* Find linear index into this input array */\n\t\t CALCINDEX(indx_in,nd_index,tmparr->strides,in->nd);\n\t\t /* Get object at this index */\n\t\t tmpobj = NX_GETITEM(tmparr, (tmparr->data+indx_in));\n\t\t if (NULL == tmpobj) {\n\t\t\t Py_DECREF(arglist);\n\t\t\t free(nd_index);\n\t\t\t return -1;\n\t\t }\n\t\t /* This steals reference of tmpobj */\n\t\t PyTuple_SET_ITEM(arglist, i, tmpobj); \n\t }\n\t \n\t /* Call Python Function for this set of inputs */\n\t if ((result=PyEval_CallObject(func, arglist))==NULL) {\n\t\t Py_DECREF(arglist);\n\t\t free(nd_index);\n\t\t return -1;\n\t } \n\t \n\t /* Find index into (all) output arrays */\n\t CALCINDEX(indx_out,nd_index,out->strides,out->nd);\n\t \n\t /* Copy the results to the output arrays */\n\t if (1==nout) {\n\t\t int rval = NX_SETITEM(\n\t\t\t outarr[0], (outarr[0]->data+indx_out), result);\n\t\t if (rval==-1) {\n\t\t\t free(nd_index);\n\t\t\t Py_DECREF(arglist);\n\t\t\t Py_DECREF(result);\n\t\t\t return -1;\n\t\t }\n\t }\n\t else if (PyTuple_Check(result)) {\n\t\t for (i=0; idata+indx_out), \n\t\t\t\t PyTuple_GET_ITEM(result,i));\n\t\t\t free(nd_index);\n\t\t\t Py_DECREF(arglist);\n\t\t\t Py_DECREF(result);\n\t\t\t return -1;\n\t\t }\n\t \n\t } else { \n\t\t PyErr_SetString(PyExc_ValueError,\"arraymap: Function output of incorrect type.\");\n\t\t free(nd_index);\n\t\t Py_DECREF(arglist);\n\t\t Py_DECREF(result);\n\t\t return -1;\n\t }\n\n\t /* Increment the index counter */\n\t INCREMENT(nd_index,in->nd,in->dimensions);\n\t Py_DECREF(result);\n\t \n }\n Py_DECREF(arglist);\n free(nd_index);\n return 0;\n} \n\nstatic PyObject *build_output(PyArrayObject **outarr,int nout)\n{\n int i;\n PyObject *out;\n\n if (1==nout) return PyArray_Return(outarr[0]);\n if ((out=PyTuple_New(nout))==NULL) return NULL;\n for (i=0; ind > 1) {\n PyErr_SetString(PyExc_ValueError, \"Input array must be < 1 dimensional\");\n return NULL;\n }\n asize = PyArray_SIZE(ainput);\n elsize = ainput->descr->elsize;\n abytes = asize * elsize;\n nd = ainput->nd;\n if (nd > 0) {\n instride = ainput->strides[0];\n }\n\n new_mem = (void *)PyMem_Malloc((size_t) abytes);\n if (new_mem == NULL) {\n return PyErr_NoMemory();\n }\n \n ip = ainput->data;\n op = new_mem;\n for (k=0; k < asize; k++,ip+=instride) {\n new = 1; /* Assume it is new */\n op2 = new_mem;\n for (j=0; j < copied; j++,op2+=elsize) {\n if (memcmp(op2,ip,elsize) == 0) { /* Is a match found? */\n new = 0;\n break;\n }\n }\n /* No match found, copy this one over */\n if (new) {\n memcpy(op,ip,elsize);\n copied += 1;\n op += elsize; /* Get ready to put next match */\n }\n }\n\n dims[0] = copied;\n /* Make output array */\n if ((aoutput = (PyArrayObject *)PyArray_FromDims(nd, \n dims, ainput->descr->type_num))==NULL) goto fail;\n\n memcpy(aoutput->data,new_mem,elsize*copied);\n /* Reallocate memory to new-size */\n PyMem_Free(new_mem);\n return PyArray_Return(aoutput); \n \n fail:\n if (new_mem != NULL) PyMem_Free(new_mem);\n Py_XDECREF(aoutput);\n return NULL;\n}\n\n\nstatic char doc_base_insert[] = \"Insert vals sequenctially into equivalent 1-d positions indicated by mask.\";\n\nstatic PyObject *base_insert(PyObject *self, PyObject *args, PyObject *kwdict)\n{\n /* Returns input array with values inserted sequentially into places \n indicated by the mask\n */\n\n PyObject *mask=NULL, *vals=NULL;\n PyArrayObject *ainput=NULL, *amask=NULL, *avals=NULL, *avalscast=NULL, *tmp=NULL;\n int numvals, totmask, sameshape;\n char *input_data, *mptr, *vptr, *zero;\n int melsize, delsize, copied, nd;\n int *instrides, *inshape;\n int mindx, rem_indx, indx, i, k, objarray;\n \n static char *kwlist[] = {\"input\",\"mask\",\"vals\",NULL};\n\n if (!PyArg_ParseTupleAndKeywords(args, kwdict, \"O!OO\", kwlist, &PyArray_Type, &ainput, &mask, &vals))\n return NULL;\n\n /* Fixed problem with OBJECT ARRAYS\n if (ainput->descr->type_num == PyArray_OBJECT) {\n PyErr_SetString(PyExc_ValueError, \"Not currently supported for Object arrays.\");\n return NULL;\n }\n */\n\n amask = (PyArrayObject *)PyArray_ContiguousFromObject(mask, PyArray_NOTYPE, 0, 0);\n if (amask == NULL) return NULL;\n /* Cast an object array */\n if (amask->descr->type_num == PyArray_OBJECT) {\n tmp = (PyArrayObject *)PyArray_Cast(amask, PyArray_LONG);\n if (tmp == NULL) goto fail;\n Py_DECREF(amask);\n amask = tmp;\n }\n\n sameshape = 1;\n if (amask->nd == ainput->nd) {\n for (k=0; k < amask->nd; k++) \n if (amask->dimensions[k] != ainput->dimensions[k])\n sameshape = 0;\n }\n else { /* Test to see if amask is 1d */\n if (amask->nd != 1) sameshape = 0;\n else if ((PyArray_SIZE(ainput)) != PyArray_SIZE(amask)) sameshape = 0;\n }\n if (!sameshape) {\n PyErr_SetString(PyExc_ValueError, \"Mask array must be 1D or same shape as input array.\");\n goto fail;\n }\n\n avals = (PyArrayObject *)PyArray_FromObject(vals, PyArray_NOTYPE, 0, 1);\n if (avals == NULL) goto fail;\n avalscast = (PyArrayObject *)PyArray_Cast(avals, ainput->descr->type_num);\n if (avalscast == NULL) goto fail;\n Py_DECREF(avals);\n\n numvals = PyArray_SIZE(avalscast);\n nd = ainput->nd;\n input_data = ainput->data;\n mptr = amask->data;\n melsize = amask->descr->elsize;\n vptr = avalscast->data;\n delsize = avalscast->descr->elsize;\n zero = amask->descr->zero;\n objarray = (ainput->descr->type_num == PyArray_OBJECT);\n \n /* Handle zero-dimensional case separately */\n if (nd == 0) {\n if (memcmp(mptr,zero,melsize) != 0) {\n /* Copy value element over to input array */\n memcpy(input_data,vptr,delsize);\n if (objarray) Py_INCREF(*((PyObject **)vptr));\n }\n Py_DECREF(amask);\n Py_DECREF(avalscast);\n Py_INCREF(Py_None);\n return Py_None;\n }\n\n /* Walk through mask array, when non-zero is encountered\n copy next value in the vals array to the input array.\n If we get through the value array, repeat it as necessary. \n */\n totmask = PyArray_SIZE(amask);\n copied = 0;\n instrides = ainput->strides;\n inshape = ainput->dimensions;\n for (mindx = 0; mindx < totmask; mindx++) { \n if (memcmp(mptr,zero,melsize) != 0) { \n /* compute indx into input array \n */\n rem_indx = mindx;\n indx = 0;\n for(i=nd-1; i > 0; --i) {\n indx += (rem_indx % inshape[i]) * instrides[i];\n rem_indx /= inshape[i];\n }\n indx += rem_indx * instrides[0];\n /* fprintf(stderr, \"mindx = %d, indx=%d\\n\", mindx, indx); */\n /* Copy value element over to input array */\n memcpy(input_data+indx,vptr,delsize);\n if (objarray) Py_INCREF(*((PyObject **)vptr));\n vptr += delsize;\n copied += 1;\n /* If we move past value data. Reset */\n if (copied >= numvals) vptr = avalscast->data;\n }\n mptr += melsize;\n }\n\n Py_DECREF(amask);\n Py_DECREF(avalscast);\n Py_INCREF(Py_None);\n return Py_None;\n \n fail:\n Py_XDECREF(amask);\n Py_XDECREF(avals);\n Py_XDECREF(avalscast);\n return NULL;\n}\n\n\n/* Decrement the reference count of all objects in **arrays. */\nstatic void cleanup_arrays(PyArrayObject **arrays, int number)\n{\n int k;\n for (k=0; k < number; k++)\n Py_XDECREF((PyObject *)arrays[k]);\n return;\n}\n\n/* All rank-0 arrays are converted to rank-1 arrays */\n/* The number of dimensions of each array with rank less than\n the rank of the array with the most dimensions is increased by \n prepending with a dimenson length of one so that all arrays have\n the same rank. */\n/* Dimensions are checked and unmatched dimensions triggers an error */\n/* Strides for dimensions whose real length is one is set to zero but the dimension\n length is set to the maximum dimensions for the collection of inputs */\nstatic int setup_input_arrays(PyTupleObject *inputs, PyArrayObject **inputarrays, int nin)\n{\n int i, k;\n int maxrank=1;\n int *maxdims;\n PyObject *inputobj;\n PyArrayObject *ain, *tmparray;\n\n /* Convert nested sequences to arrays or just increase reference count\n if already an array */\n for (i=0; i < nin; i++) {\n ain = NULL;\n inputobj = PyTuple_GET_ITEM(inputs,i);\n ain = (PyArrayObject *)PyArray_FromObject(inputobj,PyArray_ObjectType(inputobj,0),0,0);\n if (NULL == ain) {\n cleanup_arrays(inputarrays,i);\n return -1;\n }\n if (PyArray_SIZE(ain)==0) {\n cleanup_arrays(inputarrays,i);\n PyErr_SetString(PyExc_IndexError,\"arraymap: Input arrays of zero-dimensions not supported.\");\n return -1;\n }\n if (ain->nd > maxrank) maxrank = ain->nd;\n if (ain->nd == 0) { /* turn into 1-d array */\n /* convert to rank-1 array */\n if ((ain->dimensions = (int *)malloc(sizeof(int))) == NULL) {\n PyErr_SetString(PyExc_MemoryError, \"arraymap: can't allocate memory for input arrays\");\n cleanup_arrays(inputarrays,i);\n return -1;\n }\n if ((ain->strides = (int *)malloc(sizeof(int))) == NULL) {\n PyErr_SetString(PyExc_MemoryError, \"arraymap: can't allocate memory for input arrays\");\n cleanup_arrays(inputarrays,i);\n free(ain->dimensions);\n return -1;\n }\n ain->nd = 1;\n ain->dimensions[0] = 1;\n ain->strides[0] = ain->descr->elsize;\n }\n inputarrays[i] = ain;\n }\n\n maxdims = (int*)malloc(2*sizeof(int)*maxrank);\n if (NULL == maxdims) {\n PyErr_SetString(PyExc_MemoryError, \"arraymap: can't allocate memory for input arrays\");\n cleanup_arrays(inputarrays,nin);\n return -1;\n }\n\n\n /* Reshape all arrays so they have the same rank (pre-pend with length 1 dimensions) */\n /* We want to replace the header information without copying the data. \n Keeping the reference count correct can be tricky.\n We want to make a new array object with a different header and decrease the \n reference count of the old one without deallocating the data section */\n for (i=0; i < nin; i++) {\n ain = inputarrays[i];\n\n /* Initialize all dimensions to 1 */\n /* Change array shape */\n for (k=0; k < maxrank; k++) \n maxdims[k] = 1; \n for (k=maxrank-ain->nd; k< maxrank; k++) \n maxdims[k] = ain->dimensions[k-maxrank+ain->nd];\n\n tmparray = (PyArrayObject *)PyArray_FromDimsAndData(maxrank,maxdims,ain->descr->type,ain->data);\n if (NULL == tmparray) {\n free(maxdims);\n cleanup_arrays(inputarrays,nin);\n return -1;\n }\n /* tmparray->strides will be zero where new dimensions were added */\n memmove(tmparray->strides+(maxrank-ain->nd),ain->strides,sizeof(int)*ain->nd);\n tmparray->base = (PyObject *)ain; /* When tmparray is deallocated ain will be too */\n inputarrays[i] = tmparray; /* tmparray is new array */\n }\n\n /* Find dimension length for the output arrays (maximum length for each\n dimension) */\n for (k=0; k < maxrank; k++) { \n maxdims[k] = 1;\n for (i=0; i < nin; i++) \n if (inputarrays[i]->dimensions[k] > maxdims[k])\n\tmaxdims[k] = inputarrays[i]->dimensions[k];\n }\n\n\n /* Now set all lengths for input array dimensions to maxdims \n and make strides equal to zero for arrays whose\n real length is 1 for a particular dimension\n */\n\n for (i=0; idimensions[k]) {\n\tain->strides[k] = 0;\n\tain->dimensions[k] = maxdims[k];\n }\n else if (ain->dimensions[k] != maxdims[k]) {\n\tPyErr_SetString(PyExc_ValueError,\"arraymap: Frames are not aligned (mismatched dimensions).\");\n\tcleanup_arrays(inputarrays,nin);\n\tfree(maxdims);\n\treturn -1;\n }\n }\n }\n\n free(maxdims);\n return 0;\n\n}\n\nstatic int type_from_object(PyObject *obj)\n{\n if (PyArray_Check(obj))\n return ((PyArrayObject *)obj)->descr->type_num;\n if (PyComplex_Check(obj)) return PyArray_CDOUBLE;\n if (PyFloat_Check(obj)) return PyArray_DOUBLE;\n if (PyInt_Check(obj) || PyLong_Check(obj)) return PyArray_LONG;\n PyErr_SetString(PyExc_ValueError, \"arraymap: Invalid type for output array.\");\n return -1;\n}\n\nstatic int type_from_char(char typechar)\n{\n switch(typechar) {\n case 'c': return PyArray_CHAR;\n case 'b': return PyArray_UBYTE;\n case '1': return PyArray_SBYTE;\n case 's': return PyArray_SHORT;\n case 'i': return PyArray_INT;\n#ifdef PyArray_UNSIGNED_TYPES\n case 'w': return PyArray_USHORT;\n case 'u': return PyArray_UINT;\n#endif\n case 'l': return PyArray_LONG;\n case 'f': return PyArray_FLOAT;\n case 'd': return PyArray_DOUBLE;\n case 'F': return PyArray_CFLOAT;\n case 'D': return PyArray_CDOUBLE;\n default:\n PyErr_SetString(PyExc_ValueError, \"arraymap: Invalid type for array\");\n return -1;\n }\n}\n\n\n\n/* This sets up the output arrays by calling the function with arguments \n the first element of each input arrays. If otypes is NULL, the\n returned value type is used to establish the type of the output\n arrays, otherwise the characters in otypes determine the\n output types */\nstatic int setup_output_arrays(PyObject *func, PyArrayObject **inarr, int nin, PyArrayObject ***outarr, char *otypes, int numtypes)\n{\n PyObject *arglist, *result;\n PyObject *tmpobject;\n PyArrayObject *tmparr;\n int i, nout;\n int nd, *dimensions, type_num;\n\n nd = inarr[0]->nd;\n dimensions = inarr[0]->dimensions;\n\n if ((numtypes == 0) || (otypes == NULL)) { \n /* Call function to get number of outputs */\n\n /* Build argument list */\n if ((arglist = PyTuple_New(nin)) == NULL) {\n return -1;\n }\n /* Construct input argument by creating a tuple with an element\n from each input array (cast to an appropriate Python Object) */\n for (i=0; i < nin; i++) {\n tmparr = inarr[i];\n /* Get first data point */\n tmpobject = tmparr->descr->getitem((void *)tmparr->data);\n if (NULL == tmpobject) {\n\tPy_DECREF(arglist);\n\treturn -1;\n }\n PyTuple_SET_ITEM(arglist, i, tmpobject); /* arg1 owns reference to tmpobj now */\n } \n /* Call Python Function */\n if ((result=PyEval_CallObject(func, arglist))==NULL) {\n Py_DECREF(arglist);\n return -1;\n }\n\n Py_DECREF(arglist);\n\n /* If result is a tuple, create output_arrays according \n to output. */\n if (PyTuple_Check(result)) {\n nout = PyTuple_GET_SIZE(result);\n *outarr = (PyArrayObject **)malloc(nout*sizeof(PyArrayObject *));\n if (NULL == *outarr) {\n\tPyErr_SetString(PyExc_MemoryError, \"arraymap: Cannot allocate memory for output arrays.\");\n\tPy_DECREF(result);\n\treturn -1;\n }\n /* Create nout output arrays */\n for (i=0; i < nout; i++) {\n\t/* Determine type */\n\tif ((type_num=type_from_object(PyTuple_GET_ITEM(result, i)))==-1) {\n\t cleanup_arrays(*outarr,i);\n\t Py_DECREF(result);\n\t free(*outarr);\n\t return -1;\n\t}\n\t/* Create output array */\n\t(*outarr)[i] = (PyArrayObject *)PyArray_FromDims(nd,dimensions,type_num);\n\tif (NULL == (*outarr)[i]) {\n\t cleanup_arrays(*outarr,i);\n\t Py_DECREF(result);\n\t free(*outarr);\n\t return -1;\n\t}\n }\n }\n else { /* Only a single output result */\n nout = 1;\n *outarr = (PyArrayObject **)malloc(nout*sizeof(PyArrayObject *));\n if (NULL==*outarr) {\n\tPyErr_SetString(PyExc_MemoryError,\"arraymap: Cannot allocate memory for output arrays.\");\n\tPy_DECREF(result);\n\treturn -1;\n }\n if ((type_num = type_from_object(result))==-1) {\n\tPy_DECREF(result);\n\tfree(*outarr);\n\treturn -1;\n }\n (*outarr)[0] = (PyArrayObject *)PyArray_FromDims(nd,dimensions,type_num);\n if (NULL == (*outarr)[0]) {\n\tPy_DECREF(result);\n\tfree(*outarr);\n\treturn -1;\n }\n }\n Py_DECREF(result);\n }\n\n else { /* Character output types entered */\n nout = numtypes;\n *outarr = (PyArrayObject **)malloc(nout*sizeof(PyArrayObject *));\n if (NULL==*outarr) {\n PyErr_SetString(PyExc_MemoryError,\"arraymap: Cannot allocate memory for output arrays.\");\n return -1;\n }\n /* Create Output arrays */\n for (i=0; i < nout; i++) {\n /* Get type */\n if ((type_num = type_from_char(otypes[i]))==-1) {\n\tcleanup_arrays(*outarr,i);\n\tfree(*outarr);\n\treturn -1;\n }\n /* Create array */\n (*outarr)[i] = (PyArrayObject *)PyArray_FromDims(nd,dimensions,type_num);\n if (NULL == (*outarr)[i]) {\n\tcleanup_arrays(*outarr,i);\n\tfree(*outarr);\n\treturn -1;\n }\n } \n } \n return nout;\n}\n\n\n/* Corresponding dimensions are assumed to match, check before calling. */\n/* No rank-0 arrays (make them rank-1 arrays) */\n\n/* This replicates the standard Ufunc broadcasting rule that if the\n dimension length is one, incrementing does not occur for that dimension. \n\n This is currently done by setting the stride in that dimension to\n zero during input array setup.\n\n The purpose of this function is to perform a for loop over arbitrary\n discontiguous N-D arrays, call the Python function for each set of \n corresponding elements and place the results in the output_array.\n*/ \n#define INCREMENT(ret_ind, nd, max_ind) \\\n{ \\\n int k; \\\n k = (nd) - 1; \\\n if (++(ret_ind)[k] >= (max_ind)[k]) { \\\n while (k >= 0 && ((ret_ind)[k] >= (max_ind)[k]-1)) \\\n (ret_ind)[k--] = 0; \\\n if (k >= 0) (ret_ind)[k]++; \\\n else (ret_ind)[0] = (max_ind)[0]; \\\n } \\\n}\n\n#define CALCINDEX(indx, nd_index, strides, ndim) \\\n{ \\\n int i; \\\n \\\n indx = 0; \\\n for (i=0; i < (ndim); i++) \\\n indx += (nd_index)[i]*(strides)[i]; \\\n} \n\nstatic int loop_over_arrays(PyObject *func, PyArrayObject **inarr, int nin, PyArrayObject **outarr, int nout)\n{\n int i, loop_index;\n int *nd_index, indx_in, indx_out;\n PyArrayObject *in, *out, *tmparr;\n PyObject *result, *tmpobj, *arglist;\n\n in = inarr[0]; /* For any shape information needed */\n out = outarr[0];\n /* Allocate the N-D index initalized to zero. */\n nd_index = (int *)calloc(in->nd,sizeof(int));\n if (NULL == nd_index) {\n PyErr_SetString(PyExc_MemoryError,\"arraymap: Cannot allocate memory for arrays.\");\n return -1;\n }\n /* Build argument list */\n if ((arglist = PyTuple_New(nin)) == NULL) {\n free(nd_index);\n return -1;\n }\n\n loop_index = PyArray_Size((PyObject *)in); /* Total number of Python function calls */\n\n while(loop_index--) { \n /* Create input argument list with current element from the input\n arrays \n */\n for (i=0; i < nin; i++) {\n\n tmparr = inarr[i];\n /* Find linear index into this input array */\n CALCINDEX(indx_in,nd_index,tmparr->strides,in->nd);\n /* Get object at this index */\n tmpobj = tmparr->descr->getitem((void *)(tmparr->data+indx_in));\n if (NULL == tmpobj) {\n\tPy_DECREF(arglist);\n\tfree(nd_index);\n\treturn -1;\n }\n /* This steals reference of tmpobj */\n PyTuple_SET_ITEM(arglist, i, tmpobj); \n }\n\n /* Call Python Function for this set of inputs */\n if ((result=PyEval_CallObject(func, arglist))==NULL) {\n Py_DECREF(arglist);\n free(nd_index);\n return -1;\n } \n\n\n\n /* Find index into (all) output arrays */\n CALCINDEX(indx_out,nd_index,out->strides,out->nd);\n\n /* Copy the results to the output arrays */\n if (1==nout) {\n if ((outarr[0]->descr->setitem(result,(outarr[0]->data+indx_out)))==-1) {\n\tfree(nd_index);\n\tPy_DECREF(arglist);\n\tPy_DECREF(result);\n\treturn -1;\n }\n }\n else if (PyTuple_Check(result)) {\n for (i=0; idescr->setitem(PyTuple_GET_ITEM(result,i),(outarr[i]->data+indx_out)))==-1) {\n\t free(nd_index);\n\t Py_DECREF(arglist);\n\t Py_DECREF(result);\n return -1;\n\t}\n }\n }\n else { \n PyErr_SetString(PyExc_ValueError,\"arraymap: Function output of incorrect type.\");\n free(nd_index);\n Py_DECREF(arglist);\n Py_DECREF(result);\n return -1;\n }\n\n /* Increment the index counter */\n INCREMENT(nd_index,in->nd,in->dimensions);\n Py_DECREF(result);\n\n }\n Py_DECREF(arglist);\n free(nd_index);\n return 0;\n} \n\nstatic PyObject *build_output(PyArrayObject **outarr,int nout)\n{\n int i;\n PyObject *out;\n\n if (1==nout) return PyArray_Return(outarr[0]);\n if ((out=PyTuple_New(nout))==NULL) return NULL;\n for (i=0; i= 0x02020000\n\t(binaryfunc)scipy_array_floor_divide, /*nb_floor_divide*/\n\t(binaryfunc)scipy_array_true_divide, /*nb_true_divide*/\n\t(binaryfunc)scipy_array_inplace_floor_divide, /*nb_inplace_floor_divide*/\n\t(binaryfunc)scipy_array_inplace_true_divide, /*nb_inplace_true_divide*/\n#endif\n};\n\nstatic PyObject *_scipy_getattr(PyArrayObject *self, char *name) {\n PyArrayObject *ret;\n\t\n if (strcmp(name, \"M\") == 0) {\n\tPyObject *fm, *o;\n\t\n /* Call the array constructor registered as matrix_base.matrix\n\t or else raise exception if nothing registered */\n\t\t\n\t/* Import matrix_base module */\n\tfm = PyImport_ImportModule(\"scipy_base.matrix_base\");\n\to = PyObject_CallMethod(fm,\"matrix\",\"O\",(PyObject *)self);\n\tif (ret == NULL) {\n\t PyErr_SetString(PyExc_ReferenceError, \"Error using scipy_base.matrix_base.matrix to construct matrix representation\");\n\t Py_XDECREF(fm);\n\t return NULL;\n\t}\n\tPy_XDECREF(fm);\t\n\treturn o;\n }\n\n return (BackupPyArray_Type.tp_getattr)((void *)self, name);\n}\n\n\nvoid scipy_numeric_alter() {\n \n (PyArray_Type).tp_name = _scipy_array_str;\n (PyArray_Type).tp_getattr = (getattrfunc)_scipy_getattr;\n memcpy((PyArray_Type).tp_as_mapping, &scipy_array_as_mapping,\n\t sizeof(PyMappingMethods));\n memcpy((PyArray_Type).tp_as_number, &scipy_array_as_number,\n sizeof(PyNumberMethods));\n\n (PyUFunc_Type).tp_call = (ternaryfunc)scipy_ufunc_call;\n (PyUFunc_Type).tp_name = _scipy_ufunc_str;\n}\n\nstatic char numeric_alter_doc[] = \"alter_numeric() update the behavior of Numeric objects.\\n\\n 1. Change coercion rules so that multiplying by a scalar does not upcast.\\n 2. Add index and mask slicing capability to Numeric arrays.\\n 3. Add .M attribute to Numeric arrays for returning a Matrix 4. (TODO) Speed enhancements.\\n\\nThis call changes the behavior for ALL Numeric arrays currently defined\\n and to be defined in the future. The old behavior can be restored for ALL\\n arrays using numeric_restore().\";\n\nstatic PyObject *numeric_behavior_alter(PyObject *self, PyObject *args)\n{\n\n if (!PyArg_ParseTuple ( args, \"\")) return NULL;\n\n scipy_numeric_save();\n scipy_numeric_alter();\n Py_INCREF(Py_None);\n return Py_None;\n}\n\nstatic char numeric_restore_doc[] = \"restore_numeric() restore the default behavior of Numeric objects.\\n\\n SEE alter_numeric.\\n\";\n\nstatic PyObject *numeric_behavior_restore(PyObject *self, PyObject *args)\n{\n\n if (!PyArg_ParseTuple ( args, \"\")) return NULL;\n scipy_numeric_restore();\n Py_INCREF(Py_None);\n return Py_None;\n}\n\n\nstatic struct PyMethodDef methods[] = {\n {\"arraymap\", map_PyFunc, METH_VARARGS, arraymap_doc},\n {\"_unique\",\t (PyCFunction)base_unique, METH_VARARGS | METH_KEYWORDS, \n doc_base_unique},\n {\"_insert\",\t (PyCFunction)base_insert, METH_VARARGS | METH_KEYWORDS, \n doc_base_insert},\n {\"alter_numeric\", numeric_behavior_alter, METH_VARARGS, \n numeric_alter_doc},\n {\"restore_numeric\", numeric_behavior_restore, METH_VARARGS, \n numeric_restore_doc},\n {NULL, NULL} /* sentinel */\n};\n\n/* Initialization function for the module (*must* be called initArray) */\n\nDL_EXPORT(void) init_compiled_base(void) {\n PyObject *m, *d, *s, *fm=NULL, *fd=NULL;\n \n /* Create the module and add the functions */\n m = Py_InitModule(\"_compiled_base\", methods); \n\n /* Import the array and ufunc objects */\n import_array();\n import_ufunc();\n\n /* Add some symbolic constants to the module */\n d = PyModule_GetDict(m);\n\n /* Import Fastumath module */\n fm = PyImport_ImportModule(\"fastumath\");\n fd = PyModule_GetDict(fm);\n scipy_SetNumericOps(fd);\n Py_XDECREF(fm);\n\n s = PyString_FromString(\"0.2\");\n PyDict_SetItemString(d, \"__version__\", s);\n Py_DECREF(s);\n\n /* Check for errors */\n if (PyErr_Occurred())\n\tPy_FatalError(\"can't initialize module _compiled_base\");\n}\n", "methods": [ { "name": "_Converter", "long_name": "_Converter( PyObject * object , PyObject ** address)", "filename": "_compiled_base.c", "nloc": 12, "complexity": 2, "token_count": 42, "parameters": [ "object", "address" ], "start_line": 6, "end_line": 17, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 12, "top_nesting_level": 0 }, { "name": "base_unique", "long_name": "base_unique( PyObject * self , PyObject * args , PyObject * kwdict)", "filename": "_compiled_base.c", "nloc": 56, "complexity": 11, "token_count": 380, "parameters": [ "self", "args", "kwdict" ], "start_line": 20, "end_line": 89, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 70, "top_nesting_level": 0 }, { "name": "base_insert", "long_name": "base_insert( PyObject * self , PyObject * args , PyObject * kwdict)", "filename": "_compiled_base.c", "nloc": 91, "complexity": 21, "token_count": 707, "parameters": [ "self", "args", "kwdict" ], "start_line": 94, "end_line": 216, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 123, "top_nesting_level": 0 }, { "name": "cleanup_arrays", "long_name": "cleanup_arrays( PyArrayObject ** arrays , int number)", "filename": "_compiled_base.c", "nloc": 7, "complexity": 2, "token_count": 41, "parameters": [ "arrays", "number" ], "start_line": 220, "end_line": 226, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 7, "top_nesting_level": 0 }, { "name": "setup_input_arrays", "long_name": "setup_input_arrays( PyTupleObject * inputs , PyArrayObject ** inputarrays , int nin)", "filename": "_compiled_base.c", "nloc": 85, "complexity": 20, "token_count": 687, "parameters": [ "inputs", "inputarrays", "nin" ], "start_line": 236, "end_line": 349, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 114, "top_nesting_level": 0 }, { "name": "type_from_object", "long_name": "type_from_object( PyObject * obj)", "filename": "_compiled_base.c", "nloc": 10, "complexity": 6, "token_count": 74, "parameters": [ "obj" ], "start_line": 351, "end_line": 360, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 10, "top_nesting_level": 0 }, { "name": "type_from_char", "long_name": "type_from_char( char typechar)", "filename": "_compiled_base.c", "nloc": 20, "complexity": 14, "token_count": 98, "parameters": [ "typechar" ], "start_line": 362, "end_line": 383, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 22, "top_nesting_level": 0 }, { "name": "setup_output_arrays", "long_name": "setup_output_arrays( PyObject * func , PyArrayObject ** inarr , int nin , PyArrayObject ** * outarr , char * otypes , int numtypes)", "filename": "_compiled_base.c", "nloc": 96, "complexity": 19, "token_count": 663, "parameters": [ "func", "inarr", "nin", "outarr", "otypes", "numtypes" ], "start_line": 390, "end_line": 505, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 116, "top_nesting_level": 0 }, { "name": "loop_over_arrays", "long_name": "loop_over_arrays( PyObject * func , PyArrayObject ** inarr , int nin , PyArrayObject ** outarr , int nout)", "filename": "_compiled_base.c", "nloc": 71, "complexity": 11, "token_count": 472, "parameters": [ "func", "inarr", "nin", "outarr", "nout" ], "start_line": 542, "end_line": 634, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 93, "top_nesting_level": 0 }, { "name": "build_output", "long_name": "build_output( PyArrayObject ** outarr , int nout)", "filename": "_compiled_base.c", "nloc": 9, "complexity": 4, "token_count": 83, "parameters": [ "outarr", "nout" ], "start_line": 636, "end_line": 645, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 10, "top_nesting_level": 0 }, { "name": "map_PyFunc", "long_name": "map_PyFunc( PyObject * self , PyObject * args)", "filename": "_compiled_base.c", "nloc": 44, "complexity": 8, "token_count": 300, "parameters": [ "self", "args" ], "start_line": 649, "end_line": 702, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 54, "top_nesting_level": 0 } ], "methods_before": [ { "name": "base_unique", "long_name": "base_unique( PyObject * self , PyObject * args , PyObject * kwdict)", "filename": "_compiled_base.c", "nloc": 55, "complexity": 11, "token_count": 381, "parameters": [ "self", "args", "kwdict" ], "start_line": 9, "end_line": 77, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 69, "top_nesting_level": 0 }, { "name": "base_insert", "long_name": "base_insert( PyObject * self , PyObject * args , PyObject * kwdict)", "filename": "_compiled_base.c", "nloc": 89, "complexity": 21, "token_count": 709, "parameters": [ "self", "args", "kwdict" ], "start_line": 82, "end_line": 203, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 122, "top_nesting_level": 0 }, { "name": "cleanup_arrays", "long_name": "cleanup_arrays( PyArrayObject ** arrays , int number)", "filename": "_compiled_base.c", "nloc": 7, "complexity": 2, "token_count": 41, "parameters": [ "arrays", "number" ], "start_line": 207, "end_line": 213, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 7, "top_nesting_level": 0 }, { "name": "setup_input_arrays", "long_name": "setup_input_arrays( PyTupleObject * inputs , PyArrayObject ** inputarrays , int nin)", "filename": "_compiled_base.c", "nloc": 85, "complexity": 20, "token_count": 687, "parameters": [ "inputs", "inputarrays", "nin" ], "start_line": 223, "end_line": 336, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 114, "top_nesting_level": 0 }, { "name": "type_from_object", "long_name": "type_from_object( PyObject * obj)", "filename": "_compiled_base.c", "nloc": 10, "complexity": 6, "token_count": 74, "parameters": [ "obj" ], "start_line": 338, "end_line": 347, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 10, "top_nesting_level": 0 }, { "name": "type_from_char", "long_name": "type_from_char( char typechar)", "filename": "_compiled_base.c", "nloc": 20, "complexity": 14, "token_count": 98, "parameters": [ "typechar" ], "start_line": 349, "end_line": 370, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 22, "top_nesting_level": 0 }, { "name": "setup_output_arrays", "long_name": "setup_output_arrays( PyObject * func , PyArrayObject ** inarr , int nin , PyArrayObject ** * outarr , char * otypes , int numtypes)", "filename": "_compiled_base.c", "nloc": 96, "complexity": 19, "token_count": 669, "parameters": [ "func", "inarr", "nin", "outarr", "otypes", "numtypes" ], "start_line": 379, "end_line": 494, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 116, "top_nesting_level": 0 }, { "name": "loop_over_arrays", "long_name": "loop_over_arrays( PyObject * func , PyArrayObject ** inarr , int nin , PyArrayObject ** outarr , int nout)", "filename": "_compiled_base.c", "nloc": 68, "complexity": 12, "token_count": 483, "parameters": [ "func", "inarr", "nin", "outarr", "nout" ], "start_line": 531, "end_line": 621, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 91, "top_nesting_level": 0 }, { "name": "build_output", "long_name": "build_output( PyArrayObject ** outarr , int nout)", "filename": "_compiled_base.c", "nloc": 9, "complexity": 4, "token_count": 83, "parameters": [ "outarr", "nout" ], "start_line": 623, "end_line": 632, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 10, "top_nesting_level": 0 }, { "name": "map_PyFunc", "long_name": "map_PyFunc( PyObject * self , PyObject * args)", "filename": "_compiled_base.c", "nloc": 44, "complexity": 8, "token_count": 300, "parameters": [ "self", "args" ], "start_line": 636, "end_line": 689, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 54, "top_nesting_level": 0 }, { "name": "scipy_numeric_save", "long_name": "scipy_numeric_save()", "filename": "_compiled_base.c", "nloc": 17, "complexity": 2, "token_count": 124, "parameters": [], "start_line": 710, "end_line": 730, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 21, "top_nesting_level": 0 }, { "name": "scipy_numeric_restore", "long_name": "scipy_numeric_restore()", "filename": "_compiled_base.c", "nloc": 16, "complexity": 2, "token_count": 119, "parameters": [], "start_line": 732, "end_line": 751, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 20, "top_nesting_level": 0 }, { "name": "_scipy_getattr", "long_name": "_scipy_getattr( PyArrayObject * self , char * name)", "filename": "_compiled_base.c", "nloc": 16, "complexity": 3, "token_count": 107, "parameters": [ "self", "name" ], "start_line": 817, "end_line": 839, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 23, "top_nesting_level": 0 }, { "name": "scipy_numeric_alter", "long_name": "scipy_numeric_alter()", "filename": "_compiled_base.c", "nloc": 10, "complexity": 1, "token_count": 77, "parameters": [], "start_line": 842, "end_line": 853, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 12, "top_nesting_level": 0 }, { "name": "numeric_behavior_alter", "long_name": "numeric_behavior_alter( PyObject * self , PyObject * args)", "filename": "_compiled_base.c", "nloc": 8, "complexity": 2, "token_count": 41, "parameters": [ "self", "args" ], "start_line": 857, "end_line": 866, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 10, "top_nesting_level": 0 }, { "name": "numeric_behavior_restore", "long_name": "numeric_behavior_restore( PyObject * self , PyObject * args)", "filename": "_compiled_base.c", "nloc": 7, "complexity": 2, "token_count": 37, "parameters": [ "self", "args" ], "start_line": 870, "end_line": 877, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 8, "top_nesting_level": 0 }, { "name": "init_compiled_base", "long_name": "init_compiled_base()", "filename": "_compiled_base.c", "nloc": 16, "complexity": 2, "token_count": 105, "parameters": [], "start_line": 895, "end_line": 921, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 27, "top_nesting_level": 0 } ], "changed_methods": [ { "name": "scipy_numeric_restore", "long_name": "scipy_numeric_restore()", "filename": "_compiled_base.c", "nloc": 16, "complexity": 2, "token_count": 119, "parameters": [], "start_line": 732, "end_line": 751, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 20, "top_nesting_level": 0 }, { "name": "base_insert", "long_name": "base_insert( PyObject * self , PyObject * args , PyObject * kwdict)", "filename": "_compiled_base.c", "nloc": 91, "complexity": 21, "token_count": 707, "parameters": [ "self", "args", "kwdict" ], "start_line": 94, "end_line": 216, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 123, "top_nesting_level": 0 }, { "name": "scipy_numeric_alter", "long_name": "scipy_numeric_alter()", "filename": "_compiled_base.c", "nloc": 10, "complexity": 1, "token_count": 77, "parameters": [], "start_line": 842, "end_line": 853, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 12, "top_nesting_level": 0 }, { "name": "base_unique", "long_name": "base_unique( PyObject * self , PyObject * args , PyObject * kwdict)", "filename": "_compiled_base.c", "nloc": 56, "complexity": 11, "token_count": 380, "parameters": [ "self", "args", "kwdict" ], "start_line": 20, "end_line": 89, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 70, "top_nesting_level": 0 }, { "name": "numeric_behavior_alter", "long_name": "numeric_behavior_alter( PyObject * self , PyObject * args)", "filename": "_compiled_base.c", "nloc": 8, "complexity": 2, "token_count": 41, "parameters": [ "self", "args" ], "start_line": 857, "end_line": 866, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 10, "top_nesting_level": 0 }, { "name": "loop_over_arrays", "long_name": "loop_over_arrays( PyObject * func , PyArrayObject ** inarr , int nin , PyArrayObject ** outarr , int nout)", "filename": "_compiled_base.c", "nloc": 71, "complexity": 11, "token_count": 472, "parameters": [ "func", "inarr", "nin", "outarr", "nout" ], "start_line": 542, "end_line": 634, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 93, "top_nesting_level": 0 }, { "name": "numeric_behavior_restore", "long_name": "numeric_behavior_restore( PyObject * self , PyObject * args)", "filename": "_compiled_base.c", "nloc": 7, "complexity": 2, "token_count": 37, "parameters": [ "self", "args" ], "start_line": 870, "end_line": 877, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 8, "top_nesting_level": 0 }, { "name": "scipy_numeric_save", "long_name": "scipy_numeric_save()", "filename": "_compiled_base.c", "nloc": 17, "complexity": 2, "token_count": 124, "parameters": [], "start_line": 710, "end_line": 730, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 21, "top_nesting_level": 0 }, { "name": "setup_output_arrays", "long_name": "setup_output_arrays( PyObject * func , PyArrayObject ** inarr , int nin , PyArrayObject ** * outarr , char * otypes , int numtypes)", "filename": "_compiled_base.c", "nloc": 96, "complexity": 19, "token_count": 663, "parameters": [ "func", "inarr", "nin", "outarr", "otypes", "numtypes" ], "start_line": 390, "end_line": 505, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 116, "top_nesting_level": 0 }, { "name": "_Converter", "long_name": "_Converter( PyObject * object , PyObject ** address)", "filename": "_compiled_base.c", "nloc": 12, "complexity": 2, "token_count": 42, "parameters": [ "object", "address" ], "start_line": 6, "end_line": 17, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 12, "top_nesting_level": 0 }, { "name": "_scipy_getattr", "long_name": "_scipy_getattr( PyArrayObject * self , char * name)", "filename": "_compiled_base.c", "nloc": 16, "complexity": 3, "token_count": 107, "parameters": [ "self", "name" ], "start_line": 817, "end_line": 839, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 23, "top_nesting_level": 0 }, { "name": "init_compiled_base", "long_name": "init_compiled_base()", "filename": "_compiled_base.c", "nloc": 16, "complexity": 2, "token_count": 105, "parameters": [], "start_line": 895, "end_line": 921, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 27, "top_nesting_level": 0 } ], "nloc": 528, "complexity": 118, "token_count": 3746, "diff_parsed": { "added": [ "#include \"numerix.h\"", "", "/* Copy of PyArray_Converter... */", "static int", "_Converter(PyObject *object, PyObject **address) {", "\tif (PyArray_Check(object)) {", "\t\t*address = object;", "\t\treturn 1;", "\t}", "\telse {", "\t\tPyErr_SetString(", "\t\t\tPyExc_TypeError,", "\t\t\t\"expected Array object in one of the arguments\");", "\t\treturn 0;", "\t}", "}", " if (!PyArg_ParseTupleAndKeywords(", "\t args, kwdict, \"O&\", kwlist, _Converter, &ainput))", "\t return NULL;", " if (!PyArg_ParseTupleAndKeywords(", "\t args, kwdict, \"O&OO\", kwlist, _Converter, &ainput, &mask, &vals))", " amask = (PyArrayObject *) PyArray_ContiguousFromObject(", "\t mask, PyArray_NOTYPE, 0, 0);", " zero = NX_ZERO(amask);", " tmpobject = NX_GETITEM(tmparr, tmparr->data);", "\t /* Create input argument list with current element from the input", "\t arrays", "\t */", "\t for (i=0; i < nin; i++) {", "", "\t\t tmparr = inarr[i];", "\t\t /* Find linear index into this input array */", "\t\t CALCINDEX(indx_in,nd_index,tmparr->strides,in->nd);", "\t\t /* Get object at this index */", "\t\t tmpobj = NX_GETITEM(tmparr, (tmparr->data+indx_in));", "\t\t if (NULL == tmpobj) {", "\t\t\t Py_DECREF(arglist);", "\t\t\t free(nd_index);", "\t\t\t return -1;", "\t\t }", "\t\t /* This steals reference of tmpobj */", "\t\t PyTuple_SET_ITEM(arglist, i, tmpobj);", "\t }", "", "\t /* Call Python Function for this set of inputs */", "\t if ((result=PyEval_CallObject(func, arglist))==NULL) {", "\t\t Py_DECREF(arglist);", "\t\t free(nd_index);", "\t\t return -1;", "\t }", "", "\t /* Find index into (all) output arrays */", "\t CALCINDEX(indx_out,nd_index,out->strides,out->nd);", "", "\t /* Copy the results to the output arrays */", "\t if (1==nout) {", "\t\t int rval = NX_SETITEM(", "\t\t\t outarr[0], (outarr[0]->data+indx_out), result);", "\t\t if (rval==-1) {", "\t\t\t free(nd_index);", "\t\t\t Py_DECREF(arglist);", "\t\t\t Py_DECREF(result);", "\t\t\t return -1;", "\t\t }", "\t }", "\t else if (PyTuple_Check(result)) {", "\t\t for (i=0; idata+indx_out),", "\t\t\t\t PyTuple_GET_ITEM(result,i));", "\t\t\t free(nd_index);", "\t\t\t Py_DECREF(arglist);", "\t\t\t Py_DECREF(result);", "\t\t\t return -1;", "\t\t }", "", "\t } else {", "\t\t PyErr_SetString(PyExc_ValueError,\"arraymap: Function output of incorrect type.\");", "\t\t free(nd_index);", "\t\t Py_DECREF(arglist);", "\t\t Py_DECREF(result);", "\t\t return -1;", "\t }", "", "\t /* Increment the index counter */", "\t INCREMENT(nd_index,in->nd,in->dimensions);", "", "#if defined(NUMERIC)", "DL_EXPORT(void) init_nc_compiled_base(void) {", "#else", "DL_EXPORT(void) init_na_compiled_base(void) {", "#endif", " PyObject *m, *d, *s;", "#if defined(NUMERIC)", " m = Py_InitModule(\"_nc_compiled_base\", methods);", "#else", " m = Py_InitModule(\"_na_compiled_base\", methods);", "#endif", " s = PyString_FromString(\"0.3\");", "\t Py_FatalError(\"can't initialize module _compiled_base\");" ], "deleted": [ "", "#include \"Numeric/arrayobject.h\"", "#include \"Numeric/ufuncobject.h\"", "", "", " if (!PyArg_ParseTupleAndKeywords(args, kwdict, \"O!\", kwlist, &PyArray_Type, &ainput))", " return NULL;", "", " if (!PyArg_ParseTupleAndKeywords(args, kwdict, \"O!OO\", kwlist, &PyArray_Type, &ainput, &mask, &vals))", " amask = (PyArrayObject *)PyArray_ContiguousFromObject(mask, PyArray_NOTYPE, 0, 0);", " zero = amask->descr->zero;", "", "", " tmpobject = tmparr->descr->getitem((void *)tmparr->data);", " /* Create input argument list with current element from the input", " arrays", " */", " for (i=0; i < nin; i++) {", "", " tmparr = inarr[i];", " /* Find linear index into this input array */", " CALCINDEX(indx_in,nd_index,tmparr->strides,in->nd);", " /* Get object at this index */", " tmpobj = tmparr->descr->getitem((void *)(tmparr->data+indx_in));", " if (NULL == tmpobj) {", "\tPy_DECREF(arglist);", "\tfree(nd_index);", "\treturn -1;", " }", " /* This steals reference of tmpobj */", " PyTuple_SET_ITEM(arglist, i, tmpobj);", " }", "", " /* Call Python Function for this set of inputs */", " if ((result=PyEval_CallObject(func, arglist))==NULL) {", " Py_DECREF(arglist);", " free(nd_index);", " return -1;", " }", "", "", "", " /* Find index into (all) output arrays */", " CALCINDEX(indx_out,nd_index,out->strides,out->nd);", "", " /* Copy the results to the output arrays */", " if (1==nout) {", " if ((outarr[0]->descr->setitem(result,(outarr[0]->data+indx_out)))==-1) {", "\tfree(nd_index);", "\tPy_DECREF(arglist);", "\tPy_DECREF(result);", "\treturn -1;", " }", " }", " else if (PyTuple_Check(result)) {", " for (i=0; idescr->setitem(PyTuple_GET_ITEM(result,i),(outarr[i]->data+indx_out)))==-1) {", "\t free(nd_index);", "\t Py_DECREF(arglist);", " return -1;", "\t}", " }", " }", " else {", " PyErr_SetString(PyExc_ValueError,\"arraymap: Function output of incorrect type.\");", " free(nd_index);", " Py_DECREF(arglist);", " Py_DECREF(result);", " return -1;", " }", "", " /* Increment the index counter */", " INCREMENT(nd_index,in->nd,in->dimensions);", " Py_DECREF(result);", "", "/* CODE BELOW is used to Update Numeric object behavior */", "", "/* A copy of the original PyArrayType structure is kept and can be used", " to restore the original Numeric behavior at any time.", "*/", "", "static PyTypeObject BackupPyArray_Type;", "static PyTypeObject BackupPyUFunc_Type;", "static PyNumberMethods backup_array_as_number;", "static PySequenceMethods backup_array_as_sequence;", "static PyMappingMethods backup_array_as_mapping;", "static PyBufferProcs backup_array_as_buffer;", "static int scipy_numeric_stored = 0;", "", "#ifndef PyUFunc_Type", "#define PyUFunc_Type PyUfunc_Type /* fix bug in Numeric < 23.3 */", "#endif", "", "/* make sure memory copy is going on with this */", "void scipy_numeric_save() {", "", " /* we just save copies of things we may alter. */", " if (!scipy_numeric_stored) {", " BackupPyUFunc_Type.tp_name = (PyUFunc_Type).tp_name;", " BackupPyUFunc_Type.tp_call = (PyUFunc_Type).tp_call;", "", "\tBackupPyArray_Type.tp_name = (PyArray_Type).tp_name;", "\tBackupPyArray_Type.tp_getattr = (PyArray_Type).tp_getattr;", "", "\tmemcpy(&backup_array_as_number, (PyArray_Type).tp_as_number,", "\t sizeof(PyNumberMethods));", "\tmemcpy(&backup_array_as_sequence, (PyArray_Type).tp_as_sequence,", "\t sizeof(PySequenceMethods));", "\tmemcpy(&backup_array_as_mapping, (PyArray_Type).tp_as_mapping,", "\t sizeof(PyMappingMethods));", "\tmemcpy(&backup_array_as_buffer, (PyArray_Type).tp_as_buffer,", "\t sizeof(PyBufferProcs));", "\tscipy_numeric_stored = 1;", " }", "}", "", "void scipy_numeric_restore() {", "", " /* restore only what was copied */", " if (scipy_numeric_stored) {", "\t(PyUFunc_Type).tp_name = BackupPyUFunc_Type.tp_name;", "\t(PyUFunc_Type).tp_call = BackupPyUFunc_Type.tp_call;", "", "\t(PyArray_Type).tp_name = BackupPyArray_Type.tp_name;", "\t(PyArray_Type).tp_getattr = BackupPyArray_Type.tp_getattr;", "", "\tmemcpy((PyArray_Type).tp_as_number, &backup_array_as_number,", "\t sizeof(PyNumberMethods));", "\tmemcpy((PyArray_Type).tp_as_sequence, &backup_array_as_sequence,", "\t sizeof(PySequenceMethods));", "\tmemcpy((PyArray_Type).tp_as_mapping, &backup_array_as_mapping,", "\t sizeof(PyMappingMethods));", "\tmemcpy((PyArray_Type).tp_as_buffer, &backup_array_as_buffer,", "\t sizeof(PyBufferProcs));", " }", "}", "", "static const char *_scipy_array_str = \"array (scipy)\";", "static const char *_scipy_ufunc_str = \"ufunc (scipy)\";", "", "#define MAX_DIMS 30", "#include \"_scipy_mapping.c\"", "", "static PyMappingMethods scipy_array_as_mapping = {", " (inquiry)scipy_array_length,\t\t/*mp_length*/", " (binaryfunc)scipy_array_subscript_nice, /*mp_subscript*/", " (objobjargproc)scipy_array_ass_sub,\t /*mp_ass_subscript*/", "};", "", "#define MAX_ARGS 10", "#include \"_scipy_number.c\"", "", "static PyNumberMethods scipy_array_as_number = {", " (binaryfunc)scipy_array_add, /*nb_add*/", " (binaryfunc)scipy_array_subtract, /*nb_subtract*/", " (binaryfunc)scipy_array_multiply, /*nb_multiply*/", " (binaryfunc)scipy_array_divide, /*nb_divide*/", " (binaryfunc)scipy_array_remainder, /*nb_remainder*/", " (binaryfunc)scipy_array_divmod, /*nb_divmod*/", " (ternaryfunc)scipy_array_power, /*nb_power*/", " (unaryfunc)scipy_array_negative,", " (unaryfunc)scipy_array_copy, /*nb_pos*/", " (unaryfunc)scipy_array_absolute, /*(unaryfunc)scipy_array_abs,*/", " (inquiry)scipy_array_nonzero, /*nb_nonzero*/", " (unaryfunc)scipy_array_invert, /*nb_invert*/", " (binaryfunc)scipy_array_left_shift, /*nb_lshift*/", " (binaryfunc)scipy_array_right_shift, /*nb_rshift*/", " (binaryfunc)scipy_array_bitwise_and, /*nb_and*/", " (binaryfunc)scipy_array_bitwise_xor, /*nb_xor*/", " (binaryfunc)scipy_array_bitwise_or, /*nb_or*/", " (coercion)scipy_array_coerce, /*nb_coerce*/", " (unaryfunc)scipy_array_int, /*nb_int*/", " (unaryfunc)scipy_array_long, /*nb_long*/", " (unaryfunc)scipy_array_float, /*nb_float*/", " (unaryfunc)scipy_array_oct,\t /*nb_oct*/", " (unaryfunc)scipy_array_hex,\t /*nb_hex*/", "", " /*This code adds augmented assignment functionality*/", " /*that was made available in Python 2.0*/", " (binaryfunc)scipy_array_inplace_add, /*inplace_add*/", " (binaryfunc)scipy_array_inplace_subtract, /*inplace_subtract*/", " (binaryfunc)scipy_array_inplace_multiply, /*inplace_multiply*/", " (binaryfunc)scipy_array_inplace_divide, /*inplace_divide*/", " (binaryfunc)scipy_array_inplace_remainder, /*inplace_remainder*/", " (ternaryfunc)scipy_array_inplace_power, /*inplace_power*/", " (binaryfunc)scipy_array_inplace_left_shift, /*inplace_lshift*/", " (binaryfunc)scipy_array_inplace_right_shift, /*inplace_rshift*/", " (binaryfunc)scipy_array_inplace_bitwise_and, /*inplace_and*/", " (binaryfunc)scipy_array_inplace_bitwise_xor, /*inplace_xor*/", " (binaryfunc)scipy_array_inplace_bitwise_or, /*inplace_or*/", "", " /* Added in release 2.2 */", "\t/* The following require the Py_TPFLAGS_HAVE_CLASS flag */", "#if PY_VERSION_HEX >= 0x02020000", "\t(binaryfunc)scipy_array_floor_divide, /*nb_floor_divide*/", "\t(binaryfunc)scipy_array_true_divide, /*nb_true_divide*/", "\t(binaryfunc)scipy_array_inplace_floor_divide, /*nb_inplace_floor_divide*/", "\t(binaryfunc)scipy_array_inplace_true_divide, /*nb_inplace_true_divide*/", "#endif", "};", "", "static PyObject *_scipy_getattr(PyArrayObject *self, char *name) {", " PyArrayObject *ret;", "", " if (strcmp(name, \"M\") == 0) {", "\tPyObject *fm, *o;", "", " /* Call the array constructor registered as matrix_base.matrix", "\t or else raise exception if nothing registered */", "", "\t/* Import matrix_base module */", "\tfm = PyImport_ImportModule(\"scipy_base.matrix_base\");", "\to = PyObject_CallMethod(fm,\"matrix\",\"O\",(PyObject *)self);", "\tif (ret == NULL) {", "\t PyErr_SetString(PyExc_ReferenceError, \"Error using scipy_base.matrix_base.matrix to construct matrix representation\");", "\t Py_XDECREF(fm);", "\t return NULL;", "\t}", "\tPy_XDECREF(fm);", "\treturn o;", " }", "", " return (BackupPyArray_Type.tp_getattr)((void *)self, name);", "}", "", "", "void scipy_numeric_alter() {", "", " (PyArray_Type).tp_name = _scipy_array_str;", " (PyArray_Type).tp_getattr = (getattrfunc)_scipy_getattr;", " memcpy((PyArray_Type).tp_as_mapping, &scipy_array_as_mapping,", "\t sizeof(PyMappingMethods));", " memcpy((PyArray_Type).tp_as_number, &scipy_array_as_number,", " sizeof(PyNumberMethods));", "", " (PyUFunc_Type).tp_call = (ternaryfunc)scipy_ufunc_call;", " (PyUFunc_Type).tp_name = _scipy_ufunc_str;", "}", "", "static char numeric_alter_doc[] = \"alter_numeric() update the behavior of Numeric objects.\\n\\n 1. Change coercion rules so that multiplying by a scalar does not upcast.\\n 2. Add index and mask slicing capability to Numeric arrays.\\n 3. Add .M attribute to Numeric arrays for returning a Matrix 4. (TODO) Speed enhancements.\\n\\nThis call changes the behavior for ALL Numeric arrays currently defined\\n and to be defined in the future. The old behavior can be restored for ALL\\n arrays using numeric_restore().\";", "", "static PyObject *numeric_behavior_alter(PyObject *self, PyObject *args)", "{", "", " if (!PyArg_ParseTuple ( args, \"\")) return NULL;", "", " scipy_numeric_save();", " scipy_numeric_alter();", " Py_INCREF(Py_None);", " return Py_None;", "}", "", "static char numeric_restore_doc[] = \"restore_numeric() restore the default behavior of Numeric objects.\\n\\n SEE alter_numeric.\\n\";", "", "static PyObject *numeric_behavior_restore(PyObject *self, PyObject *args)", "{", "", " if (!PyArg_ParseTuple ( args, \"\")) return NULL;", " scipy_numeric_restore();", " Py_INCREF(Py_None);", " return Py_None;", "}", "", "", " {\"alter_numeric\", numeric_behavior_alter, METH_VARARGS,", " numeric_alter_doc},", " {\"restore_numeric\", numeric_behavior_restore, METH_VARARGS,", " numeric_restore_doc},", "DL_EXPORT(void) init_compiled_base(void) {", " PyObject *m, *d, *s, *fm=NULL, *fd=NULL;", " m = Py_InitModule(\"_compiled_base\", methods);", " import_ufunc();", " /* Import Fastumath module */", " fm = PyImport_ImportModule(\"fastumath\");", " fd = PyModule_GetDict(fm);", " scipy_SetNumericOps(fd);", " Py_XDECREF(fm);", "", " s = PyString_FromString(\"0.2\");", "\tPy_FatalError(\"can't initialize module _compiled_base\");" ] } }, { "old_path": null, "new_path": "scipy_base/_na_imports.py", "filename": "_na_imports.py", "extension": "py", "change_type": "ADD", "diff": "@@ -0,0 +1,100 @@\n+\"\"\"Imports from numarray for numerix, the numarray/Numeric interchangeability\n+module. These array functions are used when numarray is chosen.\n+\"\"\"\n+from ppimport import ppimport, ppimport_attr\n+import numarray as _na\n+from numarray.numeric import *\n+import numarray.ufunc as fastumath\n+\n+import _na_compiled_base\n+from _na_compiled_base import arraymap, _unique, _insert\n+\n+from numarray.ieeespecial import isinf, isnan, isfinite\n+from numarray.ieeespecial import \\\n+ plus_inf as PINF, \\\n+ minus_inf as NINF, \\\n+ plus_zero as PZERO, \\\n+ minus_zero as NZERO, \\\n+ inf, \\\n+ inf as infty, \\\n+ inf as Infinity, \\\n+ nan, \\\n+ nan as NAN, \\\n+ nan as Nan\n+\n+import numarray.linear_algebra as LinearAlgebra\n+import numarray.linear_algebra.mlab as MLab\n+import numarray.random_array as RandomArray\n+from numarray.fft import fft\n+from numarray.matrix import Matrix\n+from numarray.linear_algebra import inverse, eigenvectors\n+from numarray.convolve import convolve\n+\n+# LinearAlgebra = ppimport(\"numarray.linear_algebra\")\n+# MLab = ppimport(\"numarray.mlab\")\n+# inverse = ppimport_from(\"numarray.linear_algebra.inverse\")\n+# eigenvectors = ppimport_from(\"numarray.linear_algebra.eigenvectors\")\n+# convolve = ppimport_from(\"numarray.convolve.convolve\")\n+# fft = ppimport_from(\"numarray.fft.fft\")\n+# Matrix = ppimport_from(\"numarray.matrix.Matrix\")\n+# RandomArray = ppimport(\"numarray.random_array\")\n+\n+class _TypeNamespace:\n+ \"\"\"Numeric compatible type aliases for use with extension functions.\"\"\"\n+ Int8 = typecode[Int8]\n+ UInt8 = typecode[UInt8]\n+ Int16 = typecode[Int16]\n+ UInt16 = typecode[UInt16]\n+ Int32 = typecode[Int32]\n+ UInt32 = typecode[UInt32] \n+ Float32 = typecode[Float32]\n+ Float64 = typecode[Float64]\n+ Complex32 = typecode[Complex32]\n+ Complex64 = typecode[Complex64]\n+\n+nx = _TypeNamespace()\n+\n+def alter_numeric():\n+ pass\n+\n+def restore_numeric():\n+ pass\n+\n+conj = conjugate\n+\n+UnsignedInt8 = UInt8\n+UnsignedInt16 = UInt16\n+UnsignedInt32 = UInt32\n+\n+NUMERIX_HEADER = \"numarray/arrayobject.h\"\n+\n+class UfuncType(object):\n+ \"\"\"numarray ufuncs work differently than Numeric ufuncs and\n+ have no single UfuncType... TBD\"\"\"\n+ pass\n+\n+\n+def zeros(shape, typecode='l', savespace=0):\n+ \"\"\"scipy version of numarray.zeros() which supports creation of object\n+ arrays as well as numerical arrays.\n+ \"\"\"\n+ if typecode == 'O':\n+ import numarray.objects as obj\n+ z = obj.ObjectArray(shape=shape)\n+ z[:] = 0\n+ else:\n+ z = _na.zeros(shape=shape, type=typecode)\n+ return z\n+\n+# _Error.setMode(dividebyzero=\"ignore\", invalid=\"ignore\")\n+Error.setMode(all=\"ignore\")\n+\n+# Must appear after all public definititions\n+__all__ = []\n+for k in globals().keys():\n+ if k[0] != \"_\":\n+ __all__.append(k)\n+__all__.append(\"_insert\")\n+__all__.append(\"_unique\")\n+\n+\n", "added_lines": 100, "deleted_lines": 0, "source_code": "\"\"\"Imports from numarray for numerix, the numarray/Numeric interchangeability\nmodule. These array functions are used when numarray is chosen.\n\"\"\"\nfrom ppimport import ppimport, ppimport_attr\nimport numarray as _na\nfrom numarray.numeric import *\nimport numarray.ufunc as fastumath\n\nimport _na_compiled_base\nfrom _na_compiled_base import arraymap, _unique, _insert\n\nfrom numarray.ieeespecial import isinf, isnan, isfinite\nfrom numarray.ieeespecial import \\\n plus_inf as PINF, \\\n minus_inf as NINF, \\\n plus_zero as PZERO, \\\n minus_zero as NZERO, \\\n inf, \\\n inf as infty, \\\n inf as Infinity, \\\n nan, \\\n nan as NAN, \\\n nan as Nan\n\nimport numarray.linear_algebra as LinearAlgebra\nimport numarray.linear_algebra.mlab as MLab\nimport numarray.random_array as RandomArray\nfrom numarray.fft import fft\nfrom numarray.matrix import Matrix\nfrom numarray.linear_algebra import inverse, eigenvectors\nfrom numarray.convolve import convolve\n\n# LinearAlgebra = ppimport(\"numarray.linear_algebra\")\n# MLab = ppimport(\"numarray.mlab\")\n# inverse = ppimport_from(\"numarray.linear_algebra.inverse\")\n# eigenvectors = ppimport_from(\"numarray.linear_algebra.eigenvectors\")\n# convolve = ppimport_from(\"numarray.convolve.convolve\")\n# fft = ppimport_from(\"numarray.fft.fft\")\n# Matrix = ppimport_from(\"numarray.matrix.Matrix\")\n# RandomArray = ppimport(\"numarray.random_array\")\n\nclass _TypeNamespace:\n \"\"\"Numeric compatible type aliases for use with extension functions.\"\"\"\n Int8 = typecode[Int8]\n UInt8 = typecode[UInt8]\n Int16 = typecode[Int16]\n UInt16 = typecode[UInt16]\n Int32 = typecode[Int32]\n UInt32 = typecode[UInt32] \n Float32 = typecode[Float32]\n Float64 = typecode[Float64]\n Complex32 = typecode[Complex32]\n Complex64 = typecode[Complex64]\n\nnx = _TypeNamespace()\n\ndef alter_numeric():\n pass\n\ndef restore_numeric():\n pass\n\nconj = conjugate\n\nUnsignedInt8 = UInt8\nUnsignedInt16 = UInt16\nUnsignedInt32 = UInt32\n\nNUMERIX_HEADER = \"numarray/arrayobject.h\"\n\nclass UfuncType(object):\n \"\"\"numarray ufuncs work differently than Numeric ufuncs and\n have no single UfuncType... TBD\"\"\"\n pass\n\n\ndef zeros(shape, typecode='l', savespace=0):\n \"\"\"scipy version of numarray.zeros() which supports creation of object\n arrays as well as numerical arrays.\n \"\"\"\n if typecode == 'O':\n import numarray.objects as obj\n z = obj.ObjectArray(shape=shape)\n z[:] = 0\n else:\n z = _na.zeros(shape=shape, type=typecode)\n return z\n\n# _Error.setMode(dividebyzero=\"ignore\", invalid=\"ignore\")\nError.setMode(all=\"ignore\")\n\n# Must appear after all public definititions\n__all__ = []\nfor k in globals().keys():\n if k[0] != \"_\":\n __all__.append(k)\n__all__.append(\"_insert\")\n__all__.append(\"_unique\")\n\n\n", "source_code_before": null, "methods": [ { "name": "alter_numeric", "long_name": "alter_numeric( )", "filename": "_na_imports.py", "nloc": 2, "complexity": 1, "token_count": 5, "parameters": [], "start_line": 57, "end_line": 58, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 2, "top_nesting_level": 0 }, { "name": "restore_numeric", "long_name": "restore_numeric( )", "filename": "_na_imports.py", "nloc": 2, "complexity": 1, "token_count": 5, "parameters": [], "start_line": 60, "end_line": 61, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 2, "top_nesting_level": 0 }, { "name": "zeros", "long_name": "zeros( shape , typecode = 'l' , savespace = 0 )", "filename": "_na_imports.py", "nloc": 8, "complexity": 2, "token_count": 59, "parameters": [ "shape", "typecode", "savespace" ], "start_line": 77, "end_line": 87, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 11, "top_nesting_level": 0 } ], "methods_before": [], "changed_methods": [ { "name": "restore_numeric", "long_name": "restore_numeric( )", "filename": "_na_imports.py", "nloc": 2, "complexity": 1, "token_count": 5, "parameters": [], "start_line": 60, "end_line": 61, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 2, "top_nesting_level": 0 }, { "name": "zeros", "long_name": "zeros( shape , typecode = 'l' , savespace = 0 )", "filename": "_na_imports.py", "nloc": 8, "complexity": 2, "token_count": 59, "parameters": [ "shape", "typecode", "savespace" ], "start_line": 77, "end_line": 87, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 11, "top_nesting_level": 0 }, { "name": "alter_numeric", "long_name": "alter_numeric( )", "filename": "_na_imports.py", "nloc": 2, "complexity": 1, "token_count": 5, "parameters": [], "start_line": 57, "end_line": 58, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 2, "top_nesting_level": 0 } ], "nloc": 69, "complexity": 4, "token_count": 352, "diff_parsed": { "added": [ "\"\"\"Imports from numarray for numerix, the numarray/Numeric interchangeability", "module. These array functions are used when numarray is chosen.", "\"\"\"", "from ppimport import ppimport, ppimport_attr", "import numarray as _na", "from numarray.numeric import *", "import numarray.ufunc as fastumath", "", "import _na_compiled_base", "from _na_compiled_base import arraymap, _unique, _insert", "", "from numarray.ieeespecial import isinf, isnan, isfinite", "from numarray.ieeespecial import \\", " plus_inf as PINF, \\", " minus_inf as NINF, \\", " plus_zero as PZERO, \\", " minus_zero as NZERO, \\", " inf, \\", " inf as infty, \\", " inf as Infinity, \\", " nan, \\", " nan as NAN, \\", " nan as Nan", "", "import numarray.linear_algebra as LinearAlgebra", "import numarray.linear_algebra.mlab as MLab", "import numarray.random_array as RandomArray", "from numarray.fft import fft", "from numarray.matrix import Matrix", "from numarray.linear_algebra import inverse, eigenvectors", "from numarray.convolve import convolve", "", "# LinearAlgebra = ppimport(\"numarray.linear_algebra\")", "# MLab = ppimport(\"numarray.mlab\")", "# inverse = ppimport_from(\"numarray.linear_algebra.inverse\")", "# eigenvectors = ppimport_from(\"numarray.linear_algebra.eigenvectors\")", "# convolve = ppimport_from(\"numarray.convolve.convolve\")", "# fft = ppimport_from(\"numarray.fft.fft\")", "# Matrix = ppimport_from(\"numarray.matrix.Matrix\")", "# RandomArray = ppimport(\"numarray.random_array\")", "", "class _TypeNamespace:", " \"\"\"Numeric compatible type aliases for use with extension functions.\"\"\"", " Int8 = typecode[Int8]", " UInt8 = typecode[UInt8]", " Int16 = typecode[Int16]", " UInt16 = typecode[UInt16]", " Int32 = typecode[Int32]", " UInt32 = typecode[UInt32]", " Float32 = typecode[Float32]", " Float64 = typecode[Float64]", " Complex32 = typecode[Complex32]", " Complex64 = typecode[Complex64]", "", "nx = _TypeNamespace()", "", "def alter_numeric():", " pass", "", "def restore_numeric():", " pass", "", "conj = conjugate", "", "UnsignedInt8 = UInt8", "UnsignedInt16 = UInt16", "UnsignedInt32 = UInt32", "", "NUMERIX_HEADER = \"numarray/arrayobject.h\"", "", "class UfuncType(object):", " \"\"\"numarray ufuncs work differently than Numeric ufuncs and", " have no single UfuncType... TBD\"\"\"", " pass", "", "", "def zeros(shape, typecode='l', savespace=0):", " \"\"\"scipy version of numarray.zeros() which supports creation of object", " arrays as well as numerical arrays.", " \"\"\"", " if typecode == 'O':", " import numarray.objects as obj", " z = obj.ObjectArray(shape=shape)", " z[:] = 0", " else:", " z = _na.zeros(shape=shape, type=typecode)", " return z", "", "# _Error.setMode(dividebyzero=\"ignore\", invalid=\"ignore\")", "Error.setMode(all=\"ignore\")", "", "# Must appear after all public definititions", "__all__ = []", "for k in globals().keys():", " if k[0] != \"_\":", " __all__.append(k)", "__all__.append(\"_insert\")", "__all__.append(\"_unique\")", "", "" ], "deleted": [] } }, { "old_path": null, "new_path": "scipy_base/_nc_imports.py", "filename": "_nc_imports.py", "extension": "py", "change_type": "ADD", "diff": "@@ -0,0 +1,81 @@\n+\"\"\"Imports from Numeric for numerix, the numarray/Numeric interchangeability\n+module. These array functions are used when Numeric is chosen.\n+\"\"\"\n+import Numeric\n+from Numeric import *\n+\n+import fastumath\n+from fastumath import *\n+from fastumath import PINF as inf\n+from fastumath import alter_numeric, restore_numeric\n+\n+import _nc_compiled_base\n+from _nc_compiled_base import arraymap, _unique, _insert\n+\n+from ppimport import ppimport, ppimport_attr\n+\n+class _TypeNamespace:\n+ \"\"\"Numeric compatible type aliases for use with extension functions.\"\"\"\n+ Int8 = Int8\n+ UInt8 = UInt8\n+ Int16 = Int16\n+ UInt16 = UInt16\n+ Int32 = Int32\n+ UInt32 = UInt32\n+ Float32 = Float32\n+ Float64 = Float64\n+ Complex32 = Complex32\n+ Complex64 = Complex64\n+\n+nx = _TypeNamespace()\n+\n+# inf is useful for testing infinities in results of array divisions\n+# (which don't raise exceptions)\n+\n+inf = infty = Infinity = (array([1])/0.0)[0]\n+\n+# The following import statements are equivalent to\n+#\n+# from Matrix import Matrix as mat\n+#\n+# but avoids expensive LinearAlgebra import when\n+# Matrix is not used.\n+#\n+LinearAlgebra = ppimport('LinearAlgebra')\n+inverse = ppimport_attr(LinearAlgebra, 'inverse')\n+eigenvectors = ppimport_attr(LinearAlgebra, 'eigenvectors')\n+Matrix = mat = ppimport_attr(ppimport('Matrix'), 'Matrix')\n+fft = ppimport_attr(ppimport('FFT'), 'fft')\n+RandomArray = ppimport('RandomArray')\n+MLab = ppimport('MLab')\n+\n+NUMERIX_HEADER = \"Numeric/arrayobject.h\"\n+\n+#\n+# Force numerix to use scipy_base.fastumath instead of numerix.umath.\n+#\n+import sys as _sys\n+_sys.modules['umath'] = fastumath\n+\n+\n+if Numeric.__version__ < '23.5':\n+ matrixmultiply=dot\n+\n+Inf = inf = fastumath.PINF\n+try:\n+ NAN = NaN = nan = fastumath.NAN\n+except AttributeError:\n+ NaN = NAN = nan = fastumath.PINF/fastumath.PINF\n+\n+try:\n+ from Numeric import UfuncType\n+except ImportError:\n+ UfuncType = type(Numeric.sin)\n+\n+__all__ = []\n+for k in globals().keys():\n+ if k[0] != \"_\":\n+ __all__.append(k)\n+__all__.append(\"_insert\")\n+__all__.append(\"_unique\")\n+\n", "added_lines": 81, "deleted_lines": 0, "source_code": "\"\"\"Imports from Numeric for numerix, the numarray/Numeric interchangeability\nmodule. These array functions are used when Numeric is chosen.\n\"\"\"\nimport Numeric\nfrom Numeric import *\n\nimport fastumath\nfrom fastumath import *\nfrom fastumath import PINF as inf\nfrom fastumath import alter_numeric, restore_numeric\n\nimport _nc_compiled_base\nfrom _nc_compiled_base import arraymap, _unique, _insert\n\nfrom ppimport import ppimport, ppimport_attr\n\nclass _TypeNamespace:\n \"\"\"Numeric compatible type aliases for use with extension functions.\"\"\"\n Int8 = Int8\n UInt8 = UInt8\n Int16 = Int16\n UInt16 = UInt16\n Int32 = Int32\n UInt32 = UInt32\n Float32 = Float32\n Float64 = Float64\n Complex32 = Complex32\n Complex64 = Complex64\n\nnx = _TypeNamespace()\n\n# inf is useful for testing infinities in results of array divisions\n# (which don't raise exceptions)\n\ninf = infty = Infinity = (array([1])/0.0)[0]\n\n# The following import statements are equivalent to\n#\n# from Matrix import Matrix as mat\n#\n# but avoids expensive LinearAlgebra import when\n# Matrix is not used.\n#\nLinearAlgebra = ppimport('LinearAlgebra')\ninverse = ppimport_attr(LinearAlgebra, 'inverse')\neigenvectors = ppimport_attr(LinearAlgebra, 'eigenvectors')\nMatrix = mat = ppimport_attr(ppimport('Matrix'), 'Matrix')\nfft = ppimport_attr(ppimport('FFT'), 'fft')\nRandomArray = ppimport('RandomArray')\nMLab = ppimport('MLab')\n\nNUMERIX_HEADER = \"Numeric/arrayobject.h\"\n\n#\n# Force numerix to use scipy_base.fastumath instead of numerix.umath.\n#\nimport sys as _sys\n_sys.modules['umath'] = fastumath\n\n\nif Numeric.__version__ < '23.5':\n matrixmultiply=dot\n\nInf = inf = fastumath.PINF\ntry:\n NAN = NaN = nan = fastumath.NAN\nexcept AttributeError:\n NaN = NAN = nan = fastumath.PINF/fastumath.PINF\n\ntry:\n from Numeric import UfuncType\nexcept ImportError:\n UfuncType = type(Numeric.sin)\n\n__all__ = []\nfor k in globals().keys():\n if k[0] != \"_\":\n __all__.append(k)\n__all__.append(\"_insert\")\n__all__.append(\"_unique\")\n\n", "source_code_before": null, "methods": [], "methods_before": [], "changed_methods": [], "nloc": 53, "complexity": 0, "token_count": 276, "diff_parsed": { "added": [ "\"\"\"Imports from Numeric for numerix, the numarray/Numeric interchangeability", "module. These array functions are used when Numeric is chosen.", "\"\"\"", "import Numeric", "from Numeric import *", "", "import fastumath", "from fastumath import *", "from fastumath import PINF as inf", "from fastumath import alter_numeric, restore_numeric", "", "import _nc_compiled_base", "from _nc_compiled_base import arraymap, _unique, _insert", "", "from ppimport import ppimport, ppimport_attr", "", "class _TypeNamespace:", " \"\"\"Numeric compatible type aliases for use with extension functions.\"\"\"", " Int8 = Int8", " UInt8 = UInt8", " Int16 = Int16", " UInt16 = UInt16", " Int32 = Int32", " UInt32 = UInt32", " Float32 = Float32", " Float64 = Float64", " Complex32 = Complex32", " Complex64 = Complex64", "", "nx = _TypeNamespace()", "", "# inf is useful for testing infinities in results of array divisions", "# (which don't raise exceptions)", "", "inf = infty = Infinity = (array([1])/0.0)[0]", "", "# The following import statements are equivalent to", "#", "# from Matrix import Matrix as mat", "#", "# but avoids expensive LinearAlgebra import when", "# Matrix is not used.", "#", "LinearAlgebra = ppimport('LinearAlgebra')", "inverse = ppimport_attr(LinearAlgebra, 'inverse')", "eigenvectors = ppimport_attr(LinearAlgebra, 'eigenvectors')", "Matrix = mat = ppimport_attr(ppimport('Matrix'), 'Matrix')", "fft = ppimport_attr(ppimport('FFT'), 'fft')", "RandomArray = ppimport('RandomArray')", "MLab = ppimport('MLab')", "", "NUMERIX_HEADER = \"Numeric/arrayobject.h\"", "", "#", "# Force numerix to use scipy_base.fastumath instead of numerix.umath.", "#", "import sys as _sys", "_sys.modules['umath'] = fastumath", "", "", "if Numeric.__version__ < '23.5':", " matrixmultiply=dot", "", "Inf = inf = fastumath.PINF", "try:", " NAN = NaN = nan = fastumath.NAN", "except AttributeError:", " NaN = NAN = nan = fastumath.PINF/fastumath.PINF", "", "try:", " from Numeric import UfuncType", "except ImportError:", " UfuncType = type(Numeric.sin)", "", "__all__ = []", "for k in globals().keys():", " if k[0] != \"_\":", " __all__.append(k)", "__all__.append(\"_insert\")", "__all__.append(\"_unique\")", "" ], "deleted": [] } }, { "old_path": "scipy_base/_scipy_mapping.c", "new_path": "scipy_base/_scipy_mapping.c", "filename": "_scipy_mapping.c", "extension": "c", "change_type": "MODIFY", "diff": "@@ -319,7 +319,6 @@ static int scipy_array_length(PyArrayObject *self) {\n \n static int scipy_makecontiguous(PyArrayObject *self) {\n PyArrayObject *tmp;\n- int ret;\n \n tmp = (PyArrayObject *)PyArray_ContiguousFromObject((PyObject *)self, \n \t\t\t\t\t\t\tself->descr->type_num, \n", "added_lines": 0, "deleted_lines": 1, "source_code": "char *scipy_index2ptr(PyArrayObject *mp, int i) {\n if (i==0 && (mp->nd == 0 || mp->dimensions[0] > 0)) \n\treturn mp->data;\n\t\n if (mp->nd>0 && i>0 && i < mp->dimensions[0]) {\n\treturn mp->data+i*mp->strides[0];\n }\n PyErr_SetString(PyExc_IndexError,\"index out of bounds\"); \n return NULL;\n}\n\nstatic PyObject *scipy_array_item(PyArrayObject *self, int i) {\n char *item;\n\n if ((item = scipy_index2ptr(self, i)) == NULL) return NULL;\n\t\n if(self->nd > 1) {\n\tPyArrayObject *r;\n r = (PyArrayObject *)PyArray_FromDimsAndDataAndDescr(self->nd-1,\n self->dimensions+1,\n self->descr,\n item);\n if (r == NULL) return NULL;\n memmove(r->strides, self->strides+1, sizeof(int)*(r->nd));\n\tr->base = (PyObject *)self;\n\tr->flags = (self->flags & (CONTIGUOUS | SAVESPACE));\n r->flags |= OWN_DIMENSIONS | OWN_STRIDES;\n\tPy_INCREF(self);\n\treturn (PyObject*)r;\n } else {\n\n\t/* I would like to do this, but it requires a fix to several places of code.\n\t fprintf(stderr,\"Getting a Python scalar by indexing a rank-0 array is obsolete: use a.toscalar().\\n\");\n\t*/\n\treturn self->descr->getitem(item);\n } \n}\n\nstatic int scipy_PyArray_CopyObject(PyArrayObject *dest, PyObject *src_object) {\n PyArrayObject *src;\n PyObject *tmp;\n int ret, n_new, n_old;\n char *new_string;\n\t\n /* Special function added here to try and make arrays of strings\n work out. */\n if ((dest->descr->type_num == PyArray_CHAR) && dest->nd > 0 \n\t&& PyString_Check(src_object)) {\n\tn_new = dest->dimensions[dest->nd-1];\n\tn_old = PyString_Size(src_object); \n\tif (n_new > n_old) {\n\t new_string = (char *)malloc(n_new*sizeof(char));\n\t memmove(new_string, \n\t\t PyString_AS_STRING((PyStringObject *)src_object),\n\t\t n_old);\n\t memset(new_string+n_old, ' ', n_new-n_old);\n\t tmp = PyString_FromStringAndSize(new_string, \n\t\t\t\t\t n_new);\n\t free(new_string);\n\t src_object = tmp;\n\t}\n }\n src = (PyArrayObject *)PyArray_FromObject(src_object,\n\t\t\t\t\t dest->descr->type_num, 0,\n\t\t\t\t\t dest->nd);\n if (src == NULL) return -1;\n\t\n ret = PyArray_CopyArray(dest, src);\n Py_DECREF(src);\n return ret;\n}\n\n\nstatic int scipy_array_ass_item(PyArrayObject *self, int i, PyObject *v) {\n PyObject *c=NULL;\n PyArrayObject *tmp;\n char *item;\n int ret;\n\n if (v == NULL) {\n\tPyErr_SetString(PyExc_ValueError, \"Can't delete array elements.\");\n\treturn -1;\n }\n\n if (i < 0) i = i+self->dimensions[0];\n\n if (self->nd > 1) {\n\tif((tmp = (PyArrayObject *)scipy_array_item(self, i)) == NULL) return -1;\n\tret = scipy_PyArray_CopyObject(tmp, v);\n\tPy_DECREF(tmp);\n\treturn ret; \n }\n\t\n if ((item = scipy_index2ptr(self, i)) == NULL) return -1;\n\n if(self->descr->type_num != PyArray_OBJECT && PyString_Check(v) && PyObject_Length(v) == 1) {\n\tchar *s;\n\tif ((s=PyString_AsString(v)) == NULL) return -1;\n\tif(self->descr->type == 'c') {\n\t ((char*)self->data)[i]=*s;\n\t return 0;\n\t}\n\tif(s) c=PyInt_FromLong((long)*s);\n\tif(c) v=c;\n }\n\n self->descr->setitem(v, item);\n if(c) {Py_DECREF(c);}\n if(PyErr_Occurred()) return -1;\n return 0;\n}\n\n\n\nstatic int scipy_slice_GetIndices(PySliceObject *r, int length, \n\t\t\t\t int *start, int *stop, int *step)\n{\n if (r->step == Py_None) {\n\t*step = 1;\n } else {\n\tif (!PyInt_Check(r->step)) return -1;\n\t*step = PyInt_AsLong(r->step);\n }\n if (r->start == Py_None) {\n\t*start = *step < 0 ? length-1 : 0;\n } else {\n\tif (!PyInt_Check(r->start)) return -1;\n\t*start = PyInt_AsLong(r->start);\n\tif (*start < 0) *start += length;\n }\n if (r->stop == Py_None) {\n\t*stop = *step < 0 ? -1 : length;\n } else {\n\tif (!PyInt_Check(r->stop)) return -1;\n\t*stop = PyInt_AsLong(r->stop);\n\tif (*stop < 0) *stop += length;\n }\n if (*step < 0) {\n if (*start > (length-1)) *start = length-1;\n } else {\n if (*start > length) *start = length;\n }\n if (*start < 0) *start = 0;\n if (*stop < -1) *stop = -1;\n else if (*stop > length) *stop = length;\n return 0;\n}\n\n\n\nstatic int scipy_get_slice(PyObject *op, int max, int *np, int *sp) {\n int start, stop, step;\n\t\n if (PySlice_Check(op)) {\n\tif (scipy_slice_GetIndices((PySliceObject *)op, max, \n\t\t\t\t &start, &stop, &step) == -1) return -1;\n\t\t\n\tif (step != 0) {\n\t if (step < 0) *np = (stop-start+1+step)/step;\n\t else *np = (stop-start-1+step)/step;\n\t} else {\n\t if (stop == start) {\n\t\t*np = 0; step = 1;\n\t }\n\t else return -1;\n\t}\n\tif (*np < 0) *np = 0;\n\t*sp = step;\n\treturn start;\n } \n return -1;\n}\n\n#define PseudoIndex -1\n#define RubberIndex -2\n#define SingleIndex -3\n\nstatic int scipy_parse_subindex(PyObject *op, int *step_size, int *n_steps, int max) {\n int i, tmp;\n\t\n if (op == Py_None) {\n\t*n_steps = PseudoIndex;\n\treturn 0;\n }\n\t\n if (op == Py_Ellipsis) {\n\t*n_steps = RubberIndex;\n\treturn 0;\n }\n\t\n if (PySlice_Check(op)) {\n\tif ((i = scipy_get_slice(op, max, n_steps, step_size)) >= 0) {\n\t return i;\n\t} else {\n\t PyErr_SetString(PyExc_IndexError, \"invalid slice\");\n\t return -1;\n\t}\n }\n\t\n if (PyInt_Check(op)) {\n\t*n_steps=SingleIndex;\n\t*step_size=0;\n\ttmp = PyInt_AsLong(op);\n\tif (tmp < 0) tmp += max;\n\tif (tmp >= max || tmp < 0) {\n\t PyErr_SetString(PyExc_IndexError, \"invalid index\");\n\t return -1;\n\t}\n\treturn tmp;\n } \n\n PyErr_SetString(PyExc_IndexError, \n\t\t \"each subindex must be either a slice, an integer, Ellipsis, or NewAxis\");\n return -1;\n}\n\n\nstatic int scipy_parse_index(PyArrayObject *self, PyObject *op, \n\t\t\t int *dimensions, int *strides, int *offset_ptr) {\n int i, j, n;\n int nd_old, nd_new, start, offset, n_add, n_pseudo;\n int step_size, n_steps;\n PyObject *op1=NULL;\n int is_slice;\n\n\n if (PySlice_Check(op) || op == Py_Ellipsis) {\n\tn = 1;\n\top1 = op;\n\tPy_INCREF(op); \n\t/* this relies on the fact that n==1 for loop below */\n\tis_slice = 1;\n }\n else {\n\tif (!PySequence_Check(op)) {\n\t PyErr_SetString(PyExc_IndexError, \n\t\t\t \"index must be either an int or a sequence\");\n\t return -1;\n\t}\n\tn = PySequence_Length(op);\n\tis_slice = 0;\n }\n\t\n nd_old = nd_new = 0;\n\t\n offset = 0;\n for(i=0; ind ? self->dimensions[nd_old] : 0);\n\tPy_DECREF(op1);\n\tif (start == -1) break;\n\t\t\n\tif (n_steps == PseudoIndex) {\n\t dimensions[nd_new] = 1; strides[nd_new] = 0; nd_new++;\n\t} else {\n\t if (n_steps == RubberIndex) {\n\t\tfor(j=i+1, n_pseudo=0; jnd-(n-i-n_pseudo-1+nd_old);\n\t\tif (n_add < 0) {\n\t\t PyErr_SetString(PyExc_IndexError, \"too many indices\");\n\t\t return -1;\n\t\t}\n\t\tfor(j=0; jdimensions[nd_old];\n\t\t strides[nd_new] = self->strides[nd_old];\n\t\t nd_new++; nd_old++;\n\t\t}\n\t } else {\n\t\tif (nd_old >= self->nd) {\n\t\t PyErr_SetString(PyExc_IndexError, \"too many indices\");\n\t\t return -1;\n\t\t}\n\t\toffset += self->strides[nd_old]*start;\n\t\tnd_old++;\n\t\tif (n_steps != SingleIndex) {\n\t\t dimensions[nd_new] = n_steps;\n\t\t strides[nd_new] = step_size*self->strides[nd_old-1];\n\t\t nd_new++;\n\t\t}\n\t }\n\t}\n }\n if (i < n) return -1;\n n_add = self->nd-nd_old;\n for(j=0; jdimensions[nd_old];\n\tstrides[nd_new] = self->strides[nd_old];\n\tnd_new++; nd_old++;\n } \n *offset_ptr = offset;\n return nd_new;\n}\n\n\n\n\n\n/* Code to handle accessing Array objects as sequence objects */\nstatic int scipy_array_length(PyArrayObject *self) {\n if (self->nd != 0) {\n\treturn self->dimensions[0];\n } else {\n\treturn 1; /* Because a[0] works on 0d arrays. */\n }\n}\n\n#define SWAP(a, b, type) { type t = (a); (a) = (b); (b) = t; }\n\nstatic int scipy_makecontiguous(PyArrayObject *self) {\n PyArrayObject *tmp;\n \n tmp = (PyArrayObject *)PyArray_ContiguousFromObject((PyObject *)self, \n\t\t\t\t\t\t\tself->descr->type_num, \n\t\t\t\t\t\t\t0, 0);\n if (tmp==NULL) return -1;\n\n /* Now, swap the fields of tmp and self */\n SWAP(tmp->data, self->data, char *);\n SWAP(tmp->strides, self->strides, int *);\n SWAP(tmp->base, self->base, PyObject *);\n SWAP(tmp->flags, self->flags, int); \n \n /* Decrement tmp (will actually be self fields) */\n Py_DECREF(tmp);\n return 0;\n}\n\nstatic PyArrayObject *scipy_onearray_index(PyArrayObject *self, PyObject *op, int typenum) {\n PyObject *tup, *tmp, *optmp;\n PyArrayObject *opa, *other;\n int i, Nel, Nout, elsize, dims[1];\n unsigned char *ptr;\n char *inptr, *optr;\n\n if (!PyArray_ISCONTIGUOUS(self)) {\t\t\n\tif (scipy_makecontiguous(self)==-1) return NULL;\n }\n opa = (PyArrayObject *)PyArray_ContiguousFromObject \n\t(op,((PyArrayObject *)op)->descr->type_num, 0, 0);\n if (opa==NULL) return NULL;\n tup = Py_BuildValue(\"(i)\",-1);\n if (tup==NULL) { Py_DECREF(opa); return NULL;}\n tmp = PyArray_Reshape(self, tup);\n optmp = PyArray_Reshape(opa, tup);\n Py_DECREF(tup);\n if ((tmp==NULL) || (optmp == NULL)) { \n\tPy_DECREF(opa);\n\tPy_XDECREF(tmp);\n\tPy_XDECREF(optmp); \n\treturn NULL;\n }\n if ( typenum == PyArray_UBYTE) {\n\tNel = PyArray_SIZE((PyArrayObject *)tmp);\n\tif (Nel != PyArray_SIZE((PyArrayObject *)optmp)) {\n\t PyErr_SetString(PyExc_IndexError,\"shape mismatch between array and mask\"); \n\t Py_DECREF(opa); Py_DECREF(tmp); Py_DECREF(optmp);\n\t return NULL;\n\t}\n\t\n\t/* count size of 1-d output array */\n\tNout = 0;\n\tptr = (unsigned char *)((PyArrayObject *)optmp)->data;\n\tfor (i = 0; i < Nel; i++) {\n\t if (*ptr != 0) Nout++;\n\t ptr++;\n\t}\n\t\n\t/* construct output array */\n\tdims[0] = Nout;\n\tother = (PyArrayObject *)PyArray_FromDims \n\t (1, dims, ((PyArrayObject *)tmp)->descr->type_num);\n\t\n\t/* populate output array (other) */\n\tptr = (unsigned char *)((PyArrayObject *)optmp)->data;\n\tinptr = ((PyArrayObject *)tmp)->data;\n\toptr = other->data;\n\telsize = other->descr->elsize;\n\tfor (i=0; i < Nel; i++) {\n\t if (*ptr != 0) {\n\t\tmemcpy(optr, inptr, elsize);\n\t\toptr += elsize;\n\t }\n\t ptr++;\n\t inptr += elsize;\n\t}\n }\n else {\n\tother = (PyArrayObject *) PyArray_Take(tmp, optmp, 0);\n }\n Py_DECREF(tmp);\n Py_DECREF(optmp);\n Py_DECREF(opa);\n return other; \n\n}\n\n\n/* Called when treating array object like a mapping -- called first from \n Python when using a[object] */\nstatic PyObject *scipy_array_subscript(PyArrayObject *self, PyObject *op) {\n int dimensions[MAX_DIMS], strides[MAX_DIMS];\n int nd, offset, i, elsize, typenum;\n unsigned char flag;\n PyArrayObject *other;\n \n\t\n if (PyInt_Check(op)) {\n\ti = PyInt_AsLong(op);\n\tif (i < 0 && self->nd > 0) i = i+self->dimensions[0]; \n\treturn scipy_array_item(self, i);\n }\n \n if (PyArray_Check(op)) {\n\ttypenum = ((PyArrayObject*)op)->descr->type_num;\n\tflag = ((typenum == PyArray_INT) || (typenum == PyArray_LONG));\n\tflag |= ((typenum == PyArray_UBYTE));\n\tflag |= ((typenum == PyArray_SHORT) || (typenum == PyArray_SBYTE));\n#ifdef PyArray_UNSIGNED_TYPES\n\tflag |= ((typenum == PyArray_UINT) || (typenum == PyArray_USHORT));\n#endif\n\tif (flag) {\n\t other = scipy_onearray_index(self, op, typenum);\n\t if (other == NULL) return NULL;\n\t return (PyObject *)other;\n\t}\n }\n\t\n if ((nd = scipy_parse_index(self, op, dimensions, strides, &offset)) \n\t== -1) {\n\treturn NULL;\n }\n\t\n if ((other = (PyArrayObject *)PyArray_FromDimsAndDataAndDescr(nd, \n\t\t\t\t\t\t\t\t dimensions,\n\t\t\t\t\t\t\t\t self->descr,\n\t\t\t\t\t\t\t\t self->data+offset)) == NULL) {\n\treturn NULL;\n }\n memmove(other->strides, strides, sizeof(int)*other->nd);\n other->base = (PyObject *)self;\n Py_INCREF(self);\n\t\n elsize=other->descr->elsize;\n /* Check to see if other is CONTIGUOUS: see if strides match \n dimensions */\n for (i=other->nd-1; i>=0; i--) {\n\tif (other->strides[i] == elsize) {\n\t elsize *= other->dimensions[i];\n\t} else {\n\t break;\n\t}\n }\n if (i >= 0) other->flags &= ~CONTIGUOUS; \n\n /* Maintain SAVESPACE flag on selection */\n if (self->flags & SAVESPACE) other->flags |= SAVESPACE;\n\t\n return (PyObject *)other;\n}\n\nstatic PyObject *scipy_array_subscript_nice(PyArrayObject *self, PyObject *op) {\n PyObject *ret;\n \n if ((ret = scipy_array_subscript(self, op)) == NULL) return NULL;\n if (PyArray_Check(ret)) return PyArray_Return((PyArrayObject *)ret);\n else return ret;\n}\n\n\n/* Similar to PyArray_PutMask but it doesn't check for contiguous ArrayObject self\n and uses UBYTE instead of LONG in the mask\n */\nstatic PyObject *scipy_PyArray_PutMask(PyArrayObject *self, PyObject *mask0, \n\t\t\t\t PyObject* values0) {\n PyArrayObject *mask, *values;\n int i, chunk, ni, max_item, nv;\n char *src, *dest;\n unsigned char *ptr;\n\n mask = NULL;\n values = NULL;\n max_item = PyArray_SIZE(self);\n dest = self->data;\n chunk = self->descr->elsize;\n\n if (!PyArray_ISCONTIGUOUS(((PyArrayObject *)mask0))) {\n\tmask = (PyArrayObject *)PyArray_ContiguousFromObject(mask0, PyArray_UBYTE, 0, 0);\n\tif (mask == NULL) goto fail;\n }\n else {\n mask = (PyArrayObject *)mask0;\n\tPy_INCREF(mask);\n }\n ni = PyArray_SIZE(mask);\n if (ni != max_item) {\n\tPyErr_SetString(PyExc_IndexError, \"mask and data must be the same size.\");\n\tgoto fail;\n }\n\n values = (PyArrayObject *)PyArray_ContiguousFromObject(values0, \n\t\t\t\t\t\t\t self->descr->type, 0, 0);\n if (values == NULL) goto fail;\n nv = PyArray_SIZE(values); /* zero if null array */\n ptr = (unsigned char *)mask->data;\n if (nv > 0) {\n for(i=0; idata + chunk * (i % nv);\n if (*ptr) {\n memmove(dest + i * chunk, src, chunk);\n }\n\t ptr++;\n }\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/* Another assignment hacked by using CopyObject. */\n\nstatic int scipy_array_ass_sub(PyArrayObject *self, PyObject *index, PyObject *op) {\n int ret;\n PyArrayObject *tmp;\n int typenum;\n unsigned char flag;\n\t\n if (op == NULL) {\n\tPyErr_SetString(PyExc_ValueError, \n\t\t\t\"Can't delete array elements.\");\n\treturn -1;\n }\n\t\n if (PyInt_Check(index)) \n\treturn scipy_array_ass_item(self, PyInt_AsLong(index), op);\n\n if (PyArray_Check(index)) {\n\ttypenum = ((PyArrayObject*)index)->descr->type_num;\n\t/* if index is typecode 'b' -- unsigned byte then use putmask */\n\tif ( typenum == PyArray_UBYTE) {\n\t if (!PyArray_ISCONTIGUOUS(self)) {\n\t\tret = scipy_makecontiguous(self);\n\t\tif (ret == -1) return -1;\n\t }\n\t /* XXXX This will upcast index to long unnecessarily --- may need to write own XXXX */\n\t tmp = (PyArrayObject *)scipy_PyArray_PutMask(self, index, op);\n\t if (tmp == NULL) return -1;\n\t Py_DECREF(tmp);\n\t return 0;\n\t}\n\tflag = ((typenum == PyArray_INT) || (typenum == PyArray_LONG));\n\tflag |= ((typenum == PyArray_SHORT) || (typenum == PyArray_SBYTE));\n#ifdef PyArray_UNSIGNED_TYPES\n\tflag |= ((typenum == PyArray_UINT) || (typenum == PyArray_USHORT));\n#endif\n\tif (flag) {\n\t /* put index */\n\t if (!PyArray_ISCONTIGUOUS(self)) {\n\t\tret = scipy_makecontiguous(self);\n\t\tif (ret == -1) return -1;\n\t }\n\t tmp = (PyArrayObject *)PyArray_Put((PyObject *)self, index, op);\n\t if (tmp == NULL) return -1;\n\t Py_DECREF(tmp);\n\t return 0;\n }\n }\n\n if ((tmp = (PyArrayObject *)scipy_array_subscript(self, index)) == NULL)\n\treturn -1; \n ret = scipy_PyArray_CopyObject(tmp, op);\n Py_DECREF(tmp);\n\t\n return ret;\n}\n", "source_code_before": "char *scipy_index2ptr(PyArrayObject *mp, int i) {\n if (i==0 && (mp->nd == 0 || mp->dimensions[0] > 0)) \n\treturn mp->data;\n\t\n if (mp->nd>0 && i>0 && i < mp->dimensions[0]) {\n\treturn mp->data+i*mp->strides[0];\n }\n PyErr_SetString(PyExc_IndexError,\"index out of bounds\"); \n return NULL;\n}\n\nstatic PyObject *scipy_array_item(PyArrayObject *self, int i) {\n char *item;\n\n if ((item = scipy_index2ptr(self, i)) == NULL) return NULL;\n\t\n if(self->nd > 1) {\n\tPyArrayObject *r;\n r = (PyArrayObject *)PyArray_FromDimsAndDataAndDescr(self->nd-1,\n self->dimensions+1,\n self->descr,\n item);\n if (r == NULL) return NULL;\n memmove(r->strides, self->strides+1, sizeof(int)*(r->nd));\n\tr->base = (PyObject *)self;\n\tr->flags = (self->flags & (CONTIGUOUS | SAVESPACE));\n r->flags |= OWN_DIMENSIONS | OWN_STRIDES;\n\tPy_INCREF(self);\n\treturn (PyObject*)r;\n } else {\n\n\t/* I would like to do this, but it requires a fix to several places of code.\n\t fprintf(stderr,\"Getting a Python scalar by indexing a rank-0 array is obsolete: use a.toscalar().\\n\");\n\t*/\n\treturn self->descr->getitem(item);\n } \n}\n\nstatic int scipy_PyArray_CopyObject(PyArrayObject *dest, PyObject *src_object) {\n PyArrayObject *src;\n PyObject *tmp;\n int ret, n_new, n_old;\n char *new_string;\n\t\n /* Special function added here to try and make arrays of strings\n work out. */\n if ((dest->descr->type_num == PyArray_CHAR) && dest->nd > 0 \n\t&& PyString_Check(src_object)) {\n\tn_new = dest->dimensions[dest->nd-1];\n\tn_old = PyString_Size(src_object); \n\tif (n_new > n_old) {\n\t new_string = (char *)malloc(n_new*sizeof(char));\n\t memmove(new_string, \n\t\t PyString_AS_STRING((PyStringObject *)src_object),\n\t\t n_old);\n\t memset(new_string+n_old, ' ', n_new-n_old);\n\t tmp = PyString_FromStringAndSize(new_string, \n\t\t\t\t\t n_new);\n\t free(new_string);\n\t src_object = tmp;\n\t}\n }\n src = (PyArrayObject *)PyArray_FromObject(src_object,\n\t\t\t\t\t dest->descr->type_num, 0,\n\t\t\t\t\t dest->nd);\n if (src == NULL) return -1;\n\t\n ret = PyArray_CopyArray(dest, src);\n Py_DECREF(src);\n return ret;\n}\n\n\nstatic int scipy_array_ass_item(PyArrayObject *self, int i, PyObject *v) {\n PyObject *c=NULL;\n PyArrayObject *tmp;\n char *item;\n int ret;\n\n if (v == NULL) {\n\tPyErr_SetString(PyExc_ValueError, \"Can't delete array elements.\");\n\treturn -1;\n }\n\n if (i < 0) i = i+self->dimensions[0];\n\n if (self->nd > 1) {\n\tif((tmp = (PyArrayObject *)scipy_array_item(self, i)) == NULL) return -1;\n\tret = scipy_PyArray_CopyObject(tmp, v);\n\tPy_DECREF(tmp);\n\treturn ret; \n }\n\t\n if ((item = scipy_index2ptr(self, i)) == NULL) return -1;\n\n if(self->descr->type_num != PyArray_OBJECT && PyString_Check(v) && PyObject_Length(v) == 1) {\n\tchar *s;\n\tif ((s=PyString_AsString(v)) == NULL) return -1;\n\tif(self->descr->type == 'c') {\n\t ((char*)self->data)[i]=*s;\n\t return 0;\n\t}\n\tif(s) c=PyInt_FromLong((long)*s);\n\tif(c) v=c;\n }\n\n self->descr->setitem(v, item);\n if(c) {Py_DECREF(c);}\n if(PyErr_Occurred()) return -1;\n return 0;\n}\n\n\n\nstatic int scipy_slice_GetIndices(PySliceObject *r, int length, \n\t\t\t\t int *start, int *stop, int *step)\n{\n if (r->step == Py_None) {\n\t*step = 1;\n } else {\n\tif (!PyInt_Check(r->step)) return -1;\n\t*step = PyInt_AsLong(r->step);\n }\n if (r->start == Py_None) {\n\t*start = *step < 0 ? length-1 : 0;\n } else {\n\tif (!PyInt_Check(r->start)) return -1;\n\t*start = PyInt_AsLong(r->start);\n\tif (*start < 0) *start += length;\n }\n if (r->stop == Py_None) {\n\t*stop = *step < 0 ? -1 : length;\n } else {\n\tif (!PyInt_Check(r->stop)) return -1;\n\t*stop = PyInt_AsLong(r->stop);\n\tif (*stop < 0) *stop += length;\n }\n if (*step < 0) {\n if (*start > (length-1)) *start = length-1;\n } else {\n if (*start > length) *start = length;\n }\n if (*start < 0) *start = 0;\n if (*stop < -1) *stop = -1;\n else if (*stop > length) *stop = length;\n return 0;\n}\n\n\n\nstatic int scipy_get_slice(PyObject *op, int max, int *np, int *sp) {\n int start, stop, step;\n\t\n if (PySlice_Check(op)) {\n\tif (scipy_slice_GetIndices((PySliceObject *)op, max, \n\t\t\t\t &start, &stop, &step) == -1) return -1;\n\t\t\n\tif (step != 0) {\n\t if (step < 0) *np = (stop-start+1+step)/step;\n\t else *np = (stop-start-1+step)/step;\n\t} else {\n\t if (stop == start) {\n\t\t*np = 0; step = 1;\n\t }\n\t else return -1;\n\t}\n\tif (*np < 0) *np = 0;\n\t*sp = step;\n\treturn start;\n } \n return -1;\n}\n\n#define PseudoIndex -1\n#define RubberIndex -2\n#define SingleIndex -3\n\nstatic int scipy_parse_subindex(PyObject *op, int *step_size, int *n_steps, int max) {\n int i, tmp;\n\t\n if (op == Py_None) {\n\t*n_steps = PseudoIndex;\n\treturn 0;\n }\n\t\n if (op == Py_Ellipsis) {\n\t*n_steps = RubberIndex;\n\treturn 0;\n }\n\t\n if (PySlice_Check(op)) {\n\tif ((i = scipy_get_slice(op, max, n_steps, step_size)) >= 0) {\n\t return i;\n\t} else {\n\t PyErr_SetString(PyExc_IndexError, \"invalid slice\");\n\t return -1;\n\t}\n }\n\t\n if (PyInt_Check(op)) {\n\t*n_steps=SingleIndex;\n\t*step_size=0;\n\ttmp = PyInt_AsLong(op);\n\tif (tmp < 0) tmp += max;\n\tif (tmp >= max || tmp < 0) {\n\t PyErr_SetString(PyExc_IndexError, \"invalid index\");\n\t return -1;\n\t}\n\treturn tmp;\n } \n\n PyErr_SetString(PyExc_IndexError, \n\t\t \"each subindex must be either a slice, an integer, Ellipsis, or NewAxis\");\n return -1;\n}\n\n\nstatic int scipy_parse_index(PyArrayObject *self, PyObject *op, \n\t\t\t int *dimensions, int *strides, int *offset_ptr) {\n int i, j, n;\n int nd_old, nd_new, start, offset, n_add, n_pseudo;\n int step_size, n_steps;\n PyObject *op1=NULL;\n int is_slice;\n\n\n if (PySlice_Check(op) || op == Py_Ellipsis) {\n\tn = 1;\n\top1 = op;\n\tPy_INCREF(op); \n\t/* this relies on the fact that n==1 for loop below */\n\tis_slice = 1;\n }\n else {\n\tif (!PySequence_Check(op)) {\n\t PyErr_SetString(PyExc_IndexError, \n\t\t\t \"index must be either an int or a sequence\");\n\t return -1;\n\t}\n\tn = PySequence_Length(op);\n\tis_slice = 0;\n }\n\t\n nd_old = nd_new = 0;\n\t\n offset = 0;\n for(i=0; ind ? self->dimensions[nd_old] : 0);\n\tPy_DECREF(op1);\n\tif (start == -1) break;\n\t\t\n\tif (n_steps == PseudoIndex) {\n\t dimensions[nd_new] = 1; strides[nd_new] = 0; nd_new++;\n\t} else {\n\t if (n_steps == RubberIndex) {\n\t\tfor(j=i+1, n_pseudo=0; jnd-(n-i-n_pseudo-1+nd_old);\n\t\tif (n_add < 0) {\n\t\t PyErr_SetString(PyExc_IndexError, \"too many indices\");\n\t\t return -1;\n\t\t}\n\t\tfor(j=0; jdimensions[nd_old];\n\t\t strides[nd_new] = self->strides[nd_old];\n\t\t nd_new++; nd_old++;\n\t\t}\n\t } else {\n\t\tif (nd_old >= self->nd) {\n\t\t PyErr_SetString(PyExc_IndexError, \"too many indices\");\n\t\t return -1;\n\t\t}\n\t\toffset += self->strides[nd_old]*start;\n\t\tnd_old++;\n\t\tif (n_steps != SingleIndex) {\n\t\t dimensions[nd_new] = n_steps;\n\t\t strides[nd_new] = step_size*self->strides[nd_old-1];\n\t\t nd_new++;\n\t\t}\n\t }\n\t}\n }\n if (i < n) return -1;\n n_add = self->nd-nd_old;\n for(j=0; jdimensions[nd_old];\n\tstrides[nd_new] = self->strides[nd_old];\n\tnd_new++; nd_old++;\n } \n *offset_ptr = offset;\n return nd_new;\n}\n\n\n\n\n\n/* Code to handle accessing Array objects as sequence objects */\nstatic int scipy_array_length(PyArrayObject *self) {\n if (self->nd != 0) {\n\treturn self->dimensions[0];\n } else {\n\treturn 1; /* Because a[0] works on 0d arrays. */\n }\n}\n\n#define SWAP(a, b, type) { type t = (a); (a) = (b); (b) = t; }\n\nstatic int scipy_makecontiguous(PyArrayObject *self) {\n PyArrayObject *tmp;\n int ret;\n \n tmp = (PyArrayObject *)PyArray_ContiguousFromObject((PyObject *)self, \n\t\t\t\t\t\t\tself->descr->type_num, \n\t\t\t\t\t\t\t0, 0);\n if (tmp==NULL) return -1;\n\n /* Now, swap the fields of tmp and self */\n SWAP(tmp->data, self->data, char *);\n SWAP(tmp->strides, self->strides, int *);\n SWAP(tmp->base, self->base, PyObject *);\n SWAP(tmp->flags, self->flags, int); \n \n /* Decrement tmp (will actually be self fields) */\n Py_DECREF(tmp);\n return 0;\n}\n\nstatic PyArrayObject *scipy_onearray_index(PyArrayObject *self, PyObject *op, int typenum) {\n PyObject *tup, *tmp, *optmp;\n PyArrayObject *opa, *other;\n int i, Nel, Nout, elsize, dims[1];\n unsigned char *ptr;\n char *inptr, *optr;\n\n if (!PyArray_ISCONTIGUOUS(self)) {\t\t\n\tif (scipy_makecontiguous(self)==-1) return NULL;\n }\n opa = (PyArrayObject *)PyArray_ContiguousFromObject \n\t(op,((PyArrayObject *)op)->descr->type_num, 0, 0);\n if (opa==NULL) return NULL;\n tup = Py_BuildValue(\"(i)\",-1);\n if (tup==NULL) { Py_DECREF(opa); return NULL;}\n tmp = PyArray_Reshape(self, tup);\n optmp = PyArray_Reshape(opa, tup);\n Py_DECREF(tup);\n if ((tmp==NULL) || (optmp == NULL)) { \n\tPy_DECREF(opa);\n\tPy_XDECREF(tmp);\n\tPy_XDECREF(optmp); \n\treturn NULL;\n }\n if ( typenum == PyArray_UBYTE) {\n\tNel = PyArray_SIZE((PyArrayObject *)tmp);\n\tif (Nel != PyArray_SIZE((PyArrayObject *)optmp)) {\n\t PyErr_SetString(PyExc_IndexError,\"shape mismatch between array and mask\"); \n\t Py_DECREF(opa); Py_DECREF(tmp); Py_DECREF(optmp);\n\t return NULL;\n\t}\n\t\n\t/* count size of 1-d output array */\n\tNout = 0;\n\tptr = (unsigned char *)((PyArrayObject *)optmp)->data;\n\tfor (i = 0; i < Nel; i++) {\n\t if (*ptr != 0) Nout++;\n\t ptr++;\n\t}\n\t\n\t/* construct output array */\n\tdims[0] = Nout;\n\tother = (PyArrayObject *)PyArray_FromDims \n\t (1, dims, ((PyArrayObject *)tmp)->descr->type_num);\n\t\n\t/* populate output array (other) */\n\tptr = (unsigned char *)((PyArrayObject *)optmp)->data;\n\tinptr = ((PyArrayObject *)tmp)->data;\n\toptr = other->data;\n\telsize = other->descr->elsize;\n\tfor (i=0; i < Nel; i++) {\n\t if (*ptr != 0) {\n\t\tmemcpy(optr, inptr, elsize);\n\t\toptr += elsize;\n\t }\n\t ptr++;\n\t inptr += elsize;\n\t}\n }\n else {\n\tother = (PyArrayObject *) PyArray_Take(tmp, optmp, 0);\n }\n Py_DECREF(tmp);\n Py_DECREF(optmp);\n Py_DECREF(opa);\n return other; \n\n}\n\n\n/* Called when treating array object like a mapping -- called first from \n Python when using a[object] */\nstatic PyObject *scipy_array_subscript(PyArrayObject *self, PyObject *op) {\n int dimensions[MAX_DIMS], strides[MAX_DIMS];\n int nd, offset, i, elsize, typenum;\n unsigned char flag;\n PyArrayObject *other;\n \n\t\n if (PyInt_Check(op)) {\n\ti = PyInt_AsLong(op);\n\tif (i < 0 && self->nd > 0) i = i+self->dimensions[0]; \n\treturn scipy_array_item(self, i);\n }\n \n if (PyArray_Check(op)) {\n\ttypenum = ((PyArrayObject*)op)->descr->type_num;\n\tflag = ((typenum == PyArray_INT) || (typenum == PyArray_LONG));\n\tflag |= ((typenum == PyArray_UBYTE));\n\tflag |= ((typenum == PyArray_SHORT) || (typenum == PyArray_SBYTE));\n#ifdef PyArray_UNSIGNED_TYPES\n\tflag |= ((typenum == PyArray_UINT) || (typenum == PyArray_USHORT));\n#endif\n\tif (flag) {\n\t other = scipy_onearray_index(self, op, typenum);\n\t if (other == NULL) return NULL;\n\t return (PyObject *)other;\n\t}\n }\n\t\n if ((nd = scipy_parse_index(self, op, dimensions, strides, &offset)) \n\t== -1) {\n\treturn NULL;\n }\n\t\n if ((other = (PyArrayObject *)PyArray_FromDimsAndDataAndDescr(nd, \n\t\t\t\t\t\t\t\t dimensions,\n\t\t\t\t\t\t\t\t self->descr,\n\t\t\t\t\t\t\t\t self->data+offset)) == NULL) {\n\treturn NULL;\n }\n memmove(other->strides, strides, sizeof(int)*other->nd);\n other->base = (PyObject *)self;\n Py_INCREF(self);\n\t\n elsize=other->descr->elsize;\n /* Check to see if other is CONTIGUOUS: see if strides match \n dimensions */\n for (i=other->nd-1; i>=0; i--) {\n\tif (other->strides[i] == elsize) {\n\t elsize *= other->dimensions[i];\n\t} else {\n\t break;\n\t}\n }\n if (i >= 0) other->flags &= ~CONTIGUOUS; \n\n /* Maintain SAVESPACE flag on selection */\n if (self->flags & SAVESPACE) other->flags |= SAVESPACE;\n\t\n return (PyObject *)other;\n}\n\nstatic PyObject *scipy_array_subscript_nice(PyArrayObject *self, PyObject *op) {\n PyObject *ret;\n \n if ((ret = scipy_array_subscript(self, op)) == NULL) return NULL;\n if (PyArray_Check(ret)) return PyArray_Return((PyArrayObject *)ret);\n else return ret;\n}\n\n\n/* Similar to PyArray_PutMask but it doesn't check for contiguous ArrayObject self\n and uses UBYTE instead of LONG in the mask\n */\nstatic PyObject *scipy_PyArray_PutMask(PyArrayObject *self, PyObject *mask0, \n\t\t\t\t PyObject* values0) {\n PyArrayObject *mask, *values;\n int i, chunk, ni, max_item, nv;\n char *src, *dest;\n unsigned char *ptr;\n\n mask = NULL;\n values = NULL;\n max_item = PyArray_SIZE(self);\n dest = self->data;\n chunk = self->descr->elsize;\n\n if (!PyArray_ISCONTIGUOUS(((PyArrayObject *)mask0))) {\n\tmask = (PyArrayObject *)PyArray_ContiguousFromObject(mask0, PyArray_UBYTE, 0, 0);\n\tif (mask == NULL) goto fail;\n }\n else {\n mask = (PyArrayObject *)mask0;\n\tPy_INCREF(mask);\n }\n ni = PyArray_SIZE(mask);\n if (ni != max_item) {\n\tPyErr_SetString(PyExc_IndexError, \"mask and data must be the same size.\");\n\tgoto fail;\n }\n\n values = (PyArrayObject *)PyArray_ContiguousFromObject(values0, \n\t\t\t\t\t\t\t self->descr->type, 0, 0);\n if (values == NULL) goto fail;\n nv = PyArray_SIZE(values); /* zero if null array */\n ptr = (unsigned char *)mask->data;\n if (nv > 0) {\n for(i=0; idata + chunk * (i % nv);\n if (*ptr) {\n memmove(dest + i * chunk, src, chunk);\n }\n\t ptr++;\n }\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/* Another assignment hacked by using CopyObject. */\n\nstatic int scipy_array_ass_sub(PyArrayObject *self, PyObject *index, PyObject *op) {\n int ret;\n PyArrayObject *tmp;\n int typenum;\n unsigned char flag;\n\t\n if (op == NULL) {\n\tPyErr_SetString(PyExc_ValueError, \n\t\t\t\"Can't delete array elements.\");\n\treturn -1;\n }\n\t\n if (PyInt_Check(index)) \n\treturn scipy_array_ass_item(self, PyInt_AsLong(index), op);\n\n if (PyArray_Check(index)) {\n\ttypenum = ((PyArrayObject*)index)->descr->type_num;\n\t/* if index is typecode 'b' -- unsigned byte then use putmask */\n\tif ( typenum == PyArray_UBYTE) {\n\t if (!PyArray_ISCONTIGUOUS(self)) {\n\t\tret = scipy_makecontiguous(self);\n\t\tif (ret == -1) return -1;\n\t }\n\t /* XXXX This will upcast index to long unnecessarily --- may need to write own XXXX */\n\t tmp = (PyArrayObject *)scipy_PyArray_PutMask(self, index, op);\n\t if (tmp == NULL) return -1;\n\t Py_DECREF(tmp);\n\t return 0;\n\t}\n\tflag = ((typenum == PyArray_INT) || (typenum == PyArray_LONG));\n\tflag |= ((typenum == PyArray_SHORT) || (typenum == PyArray_SBYTE));\n#ifdef PyArray_UNSIGNED_TYPES\n\tflag |= ((typenum == PyArray_UINT) || (typenum == PyArray_USHORT));\n#endif\n\tif (flag) {\n\t /* put index */\n\t if (!PyArray_ISCONTIGUOUS(self)) {\n\t\tret = scipy_makecontiguous(self);\n\t\tif (ret == -1) return -1;\n\t }\n\t tmp = (PyArrayObject *)PyArray_Put((PyObject *)self, index, op);\n\t if (tmp == NULL) return -1;\n\t Py_DECREF(tmp);\n\t return 0;\n }\n }\n\n if ((tmp = (PyArrayObject *)scipy_array_subscript(self, index)) == NULL)\n\treturn -1; \n ret = scipy_PyArray_CopyObject(tmp, op);\n Py_DECREF(tmp);\n\t\n return ret;\n}\n", "methods": [ { "name": "scipy_index2ptr", "long_name": "scipy_index2ptr( PyArrayObject * mp , int i)", "filename": "_scipy_mapping.c", "nloc": 9, "complexity": 7, "token_count": 86, "parameters": [ "mp", "i" ], "start_line": 1, "end_line": 10, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 10, "top_nesting_level": 0 }, { "name": "scipy_array_item", "long_name": "scipy_array_item( PyArrayObject * self , int i)", "filename": "_scipy_mapping.c", "nloc": 20, "complexity": 4, "token_count": 166, "parameters": [ "self", "i" ], "start_line": 12, "end_line": 37, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 26, "top_nesting_level": 0 }, { "name": "scipy_PyArray_CopyObject", "long_name": "scipy_PyArray_CopyObject( PyArrayObject * dest , PyObject * src_object)", "filename": "_scipy_mapping.c", "nloc": 29, "complexity": 6, "token_count": 197, "parameters": [ "dest", "src_object" ], "start_line": 39, "end_line": 71, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 33, "top_nesting_level": 0 }, { "name": "scipy_array_ass_item", "long_name": "scipy_array_ass_item( PyArrayObject * self , int i , PyObject * v)", "filename": "_scipy_mapping.c", "nloc": 32, "complexity": 15, "token_count": 271, "parameters": [ "self", "i", "v" ], "start_line": 74, "end_line": 111, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 38, "top_nesting_level": 0 }, { "name": "scipy_slice_GetIndices", "long_name": "scipy_slice_GetIndices( PySliceObject * r , int length , int * start , int * stop , int * step)", "filename": "_scipy_mapping.c", "nloc": 33, "complexity": 17, "token_count": 274, "parameters": [ "r", "length", "start", "stop", "step" ], "start_line": 115, "end_line": 147, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 33, "top_nesting_level": 0 }, { "name": "scipy_get_slice", "long_name": "scipy_get_slice( PyObject * op , int max , int * np , int * sp)", "filename": "_scipy_mapping.c", "nloc": 20, "complexity": 7, "token_count": 158, "parameters": [ "op", "max", "np", "sp" ], "start_line": 151, "end_line": 172, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 22, "top_nesting_level": 0 }, { "name": "scipy_parse_subindex", "long_name": "scipy_parse_subindex( PyObject * op , int * step_size , int * n_steps , int max)", "filename": "_scipy_mapping.c", "nloc": 33, "complexity": 9, "token_count": 176, "parameters": [ "op", "step_size", "n_steps", "max" ], "start_line": 178, "end_line": 215, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 38, "top_nesting_level": 0 }, { "name": "scipy_parse_index", "long_name": "scipy_parse_index( PyArrayObject * self , PyObject * op , int * dimensions , int * strides , int * offset_ptr)", "filename": "_scipy_mapping.c", "nloc": 79, "complexity": 19, "token_count": 529, "parameters": [ "self", "op", "dimensions", "strides", "offset_ptr" ], "start_line": 218, "end_line": 303, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 86, "top_nesting_level": 0 }, { "name": "scipy_array_length", "long_name": "scipy_array_length( PyArrayObject * self)", "filename": "_scipy_mapping.c", "nloc": 7, "complexity": 2, "token_count": 32, "parameters": [ "self" ], "start_line": 310, "end_line": 316, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 7, "top_nesting_level": 0 }, { "name": "scipy_makecontiguous", "long_name": "scipy_makecontiguous( PyArrayObject * self)", "filename": "_scipy_mapping.c", "nloc": 13, "complexity": 2, "token_count": 110, "parameters": [ "self" ], "start_line": 320, "end_line": 337, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 18, "top_nesting_level": 0 }, { "name": "scipy_onearray_index", "long_name": "scipy_onearray_index( PyArrayObject * self , PyObject * op , int typenum)", "filename": "_scipy_mapping.c", "nloc": 60, "complexity": 13, "token_count": 463, "parameters": [ "self", "op", "typenum" ], "start_line": 339, "end_line": 406, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 68, "top_nesting_level": 0 }, { "name": "scipy_array_subscript", "long_name": "scipy_array_subscript( PyArrayObject * self , PyObject * op)", "filename": "_scipy_mapping.c", "nloc": 47, "complexity": 17, "token_count": 386, "parameters": [ "self", "op" ], "start_line": 411, "end_line": 470, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 60, "top_nesting_level": 0 }, { "name": "scipy_array_subscript_nice", "long_name": "scipy_array_subscript_nice( PyArrayObject * self , PyObject * op)", "filename": "_scipy_mapping.c", "nloc": 6, "complexity": 3, "token_count": 55, "parameters": [ "self", "op" ], "start_line": 472, "end_line": 478, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 7, "top_nesting_level": 0 }, { "name": "scipy_PyArray_PutMask", "long_name": "scipy_PyArray_PutMask( PyArrayObject * self , PyObject * mask0 , PyObject * values0)", "filename": "_scipy_mapping.c", "nloc": 47, "complexity": 8, "token_count": 299, "parameters": [ "self", "mask0", "values0" ], "start_line": 484, "end_line": 535, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 52, "top_nesting_level": 0 }, { "name": "scipy_array_ass_sub", "long_name": "scipy_array_ass_sub( PyArrayObject * self , PyObject * index , PyObject * op)", "filename": "_scipy_mapping.c", "nloc": 44, "complexity": 17, "token_count": 320, "parameters": [ "self", "index", "op" ], "start_line": 540, "end_line": 593, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 54, "top_nesting_level": 0 } ], "methods_before": [ { "name": "scipy_index2ptr", "long_name": "scipy_index2ptr( PyArrayObject * mp , int i)", "filename": "_scipy_mapping.c", "nloc": 9, "complexity": 7, "token_count": 86, "parameters": [ "mp", "i" ], "start_line": 1, "end_line": 10, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 10, "top_nesting_level": 0 }, { "name": "scipy_array_item", "long_name": "scipy_array_item( PyArrayObject * self , int i)", "filename": "_scipy_mapping.c", "nloc": 20, "complexity": 4, "token_count": 166, "parameters": [ "self", "i" ], "start_line": 12, "end_line": 37, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 26, "top_nesting_level": 0 }, { "name": "scipy_PyArray_CopyObject", "long_name": "scipy_PyArray_CopyObject( PyArrayObject * dest , PyObject * src_object)", "filename": "_scipy_mapping.c", "nloc": 29, "complexity": 6, "token_count": 197, "parameters": [ "dest", "src_object" ], "start_line": 39, "end_line": 71, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 33, "top_nesting_level": 0 }, { "name": "scipy_array_ass_item", "long_name": "scipy_array_ass_item( PyArrayObject * self , int i , PyObject * v)", "filename": "_scipy_mapping.c", "nloc": 32, "complexity": 15, "token_count": 271, "parameters": [ "self", "i", "v" ], "start_line": 74, "end_line": 111, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 38, "top_nesting_level": 0 }, { "name": "scipy_slice_GetIndices", "long_name": "scipy_slice_GetIndices( PySliceObject * r , int length , int * start , int * stop , int * step)", "filename": "_scipy_mapping.c", "nloc": 33, "complexity": 17, "token_count": 274, "parameters": [ "r", "length", "start", "stop", "step" ], "start_line": 115, "end_line": 147, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 33, "top_nesting_level": 0 }, { "name": "scipy_get_slice", "long_name": "scipy_get_slice( PyObject * op , int max , int * np , int * sp)", "filename": "_scipy_mapping.c", "nloc": 20, "complexity": 7, "token_count": 158, "parameters": [ "op", "max", "np", "sp" ], "start_line": 151, "end_line": 172, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 22, "top_nesting_level": 0 }, { "name": "scipy_parse_subindex", "long_name": "scipy_parse_subindex( PyObject * op , int * step_size , int * n_steps , int max)", "filename": "_scipy_mapping.c", "nloc": 33, "complexity": 9, "token_count": 176, "parameters": [ "op", "step_size", "n_steps", "max" ], "start_line": 178, "end_line": 215, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 38, "top_nesting_level": 0 }, { "name": "scipy_parse_index", "long_name": "scipy_parse_index( PyArrayObject * self , PyObject * op , int * dimensions , int * strides , int * offset_ptr)", "filename": "_scipy_mapping.c", "nloc": 79, "complexity": 19, "token_count": 529, "parameters": [ "self", "op", "dimensions", "strides", "offset_ptr" ], "start_line": 218, "end_line": 303, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 86, "top_nesting_level": 0 }, { "name": "scipy_array_length", "long_name": "scipy_array_length( PyArrayObject * self)", "filename": "_scipy_mapping.c", "nloc": 7, "complexity": 2, "token_count": 32, "parameters": [ "self" ], "start_line": 310, "end_line": 316, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 7, "top_nesting_level": 0 }, { "name": "scipy_makecontiguous", "long_name": "scipy_makecontiguous( PyArrayObject * self)", "filename": "_scipy_mapping.c", "nloc": 14, "complexity": 2, "token_count": 113, "parameters": [ "self" ], "start_line": 320, "end_line": 338, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 19, "top_nesting_level": 0 }, { "name": "scipy_onearray_index", "long_name": "scipy_onearray_index( PyArrayObject * self , PyObject * op , int typenum)", "filename": "_scipy_mapping.c", "nloc": 60, "complexity": 13, "token_count": 463, "parameters": [ "self", "op", "typenum" ], "start_line": 340, "end_line": 407, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 68, "top_nesting_level": 0 }, { "name": "scipy_array_subscript", "long_name": "scipy_array_subscript( PyArrayObject * self , PyObject * op)", "filename": "_scipy_mapping.c", "nloc": 47, "complexity": 17, "token_count": 386, "parameters": [ "self", "op" ], "start_line": 412, "end_line": 471, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 60, "top_nesting_level": 0 }, { "name": "scipy_array_subscript_nice", "long_name": "scipy_array_subscript_nice( PyArrayObject * self , PyObject * op)", "filename": "_scipy_mapping.c", "nloc": 6, "complexity": 3, "token_count": 55, "parameters": [ "self", "op" ], "start_line": 473, "end_line": 479, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 7, "top_nesting_level": 0 }, { "name": "scipy_PyArray_PutMask", "long_name": "scipy_PyArray_PutMask( PyArrayObject * self , PyObject * mask0 , PyObject * values0)", "filename": "_scipy_mapping.c", "nloc": 47, "complexity": 8, "token_count": 299, "parameters": [ "self", "mask0", "values0" ], "start_line": 485, "end_line": 536, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 52, "top_nesting_level": 0 }, { "name": "scipy_array_ass_sub", "long_name": "scipy_array_ass_sub( PyArrayObject * self , PyObject * index , PyObject * op)", "filename": "_scipy_mapping.c", "nloc": 44, "complexity": 17, "token_count": 320, "parameters": [ "self", "index", "op" ], "start_line": 541, "end_line": 594, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 54, "top_nesting_level": 0 } ], "changed_methods": [ { "name": "scipy_makecontiguous", "long_name": "scipy_makecontiguous( PyArrayObject * self)", "filename": "_scipy_mapping.c", "nloc": 14, "complexity": 2, "token_count": 113, "parameters": [ "self" ], "start_line": 320, "end_line": 338, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 19, "top_nesting_level": 0 } ], "nloc": 479, "complexity": 146, "token_count": 3557, "diff_parsed": { "added": [], "deleted": [ " int ret;" ] } }, { "old_path": "scipy_base/_scipy_number.c", "new_path": "scipy_base/_scipy_number.c", "filename": "_scipy_number.c", "extension": "c", "change_type": "MODIFY", "diff": "@@ -759,7 +759,11 @@ static PyObject *scipy_ufunc_call(PyUFuncObject *self, PyObject *args) {\n for(i=0; inargs; i++) mps[i] = NULL;\n \t\n if (scipy_PyUFunc_GenericFunction(self, args, mps) == -1) {\n-\tfor(i=0; inargs; i++) if (mps[i] != NULL) Py_DECREF(mps[i]);\n+\t for(i=0; inargs; i++) { \n+\t\t if (mps[i] != NULL) { \n+\t\t\t Py_DECREF(mps[i]); \n+\t\t }\n+\t }\n \treturn NULL;\n }\n \t\n", "added_lines": 5, "deleted_lines": 1, "source_code": "/* Numeric's source code for array-object ufuncs\n\n Only thing changed is the coercion model (select_types and setup_matrices)\n\n When no savespace bit is present then...\n Scalars (Python Objects) only change INT to FLOAT or FLOAT to COMPLEX but\n otherwise do not cause upcasting. \n\n*/\n\n#define SIZE(mp) (_PyArray_multiply_list((mp)->dimensions, (mp)->nd))\n#define NBYTES(mp) ((mp)->descr->elsize * SIZE(mp))\n/* Obviously this needs some work. */\n#define ISCONTIGUOUS(m) ((m)->flags & CONTIGUOUS)\n#define PyArray_CONTIGUOUS(m) (ISCONTIGUOUS(m) ? Py_INCREF(m), m : \\\n(PyArrayObject *)(PyArray_ContiguousFromObject((PyObject *)(m), \\\n(m)->descr->type_num, 0,0)))\n\n#ifndef max\n#define max(x,y) (x)>(y)?(x):(y)\n#endif\n#ifndef min\n#define min(x,y) (x)>(y)?(y):(x)\n#endif\n\nstatic int scipy_compare_lists(int *l1, int *l2, int n) {\n int i;\n for(i=0;istrides[d];\n}\n\n\nstatic PyObject *scipy_array_copy(PyArrayObject *m1) {\n PyArrayObject *ret = \n\t(PyArrayObject *)PyArray_FromDims(m1->nd, m1->dimensions, m1->descr->type_num);\n\t\n if (PyArray_CopyArray(ret, m1) == -1) return NULL;\n\t\n return (PyObject *)ret;\n}\n\n#define SCALARBIT 2048\n#define MAKEFROMSCALAR(obj) (((PyArrayObject *)(obj))->descr->type_num |= SCALARBIT)\n#define PyArray_ISFROMSCALAR(obj) ((((PyArrayObject*)(obj))->descr->type_num & SCALARBIT))\n#define OFFSCALAR(obj) (((PyArrayObject *)(obj))->descr->type_num &= ~((int) SCALARBIT))\n#define PYNOSCALAR 0\n#define PYINTPOS 1\n#define PYINTNEG 2\n#define PYFLOAT 3\n#define PYCOMPLEX 4\n\n\n/* This function is called while searching for an appropriate ufunc\n\n It should return a 0 if coercion of thistype to neededtype is not safe.\n\n It uses PyArray_CanCastSafely but adds special logic to allow Python \n scalars to be downcast within the same kind if they are in the presence\n of arrays.\n\n */\nstatic int scipy_cancoerce(char thistype, char neededtype, char scalar) {\n\n if (scalar==PYNOSCALAR) return PyArray_CanCastSafely(thistype, neededtype);\n if (scalar==PYINTPOS) \n return (neededtype >= PyArray_UBYTE);\n if (scalar==PYINTNEG)\n\treturn ((neededtype >= PyArray_SBYTE) && (neededtype != PyArray_USHORT) && (neededtype != PyArray_UINT));\n if (scalar==PYFLOAT)\n return (neededtype >= PyArray_FLOAT);\n if (scalar==PYCOMPLEX)\n return (neededtype >= PyArray_CFLOAT);\n return 1; /* should never get here... */ \n}\n\nstatic int scipy_select_types(PyUFuncObject *self, char *arg_types, void **data, \n\t\t\t PyUFuncGenericFunction *function, char *scalars) {\n int i=0, j;\n int k=0;\n char largest_savespace = 0, real_type;\n\n for (j=0; jnin; j++) {\n\treal_type = arg_types[j] & ~((char )SAVESPACEBIT);\n\tif ((arg_types[j] & SAVESPACEBIT) && (real_type > largest_savespace)) \n\t largest_savespace = real_type;\n }\n\n if (largest_savespace == 0) {\n\n /* start search for signature at first reasonable choice (first array-based\n type --- won't use scalar for this check)*/\n while(knin && scalars[k] != PYNOSCALAR) k++;\n if (k == self->nin) { /* no arrays */\n\t /* so use usual coercion rules -- ignore scalar handling */\n\t for (j=0; jnin; j++) {\n\t\tscalars[j] = PYNOSCALAR;\n\t }\n\t k = 0;\n\t}\n while (intypes && arg_types[k] > self->types[i*self->nargs+k]) i++;\n \n /* Signature search */\n for(;intypes; i++) {\n for(j=0; jnin; j++) {\n if (!scipy_cancoerce(arg_types[j], self->types[i*self->nargs+j],\n scalars[j])) break;\n }\n if (j == self->nin) break; /* Found signature that will work */\n /* Otherwise, increment i and check next signature */\n }\n if(i>=self->ntypes) {\n PyErr_SetString(PyExc_TypeError, \n \"function not supported for these types, and can't coerce to supported types\");\n return -1;\n }\n\n /* reset arg_types to those needed for this signature */\n for(j=0; jnargs; j++) \n arg_types[j] = (self->types[i*self->nargs+j] & ~((char )SAVESPACEBIT));\n }\n else {\n\twhile(intypes && largest_savespace > self->types[i*self->nargs]) i++;\n\tif (i>=self->ntypes || largest_savespace < self->types[i*self->nargs]) {\n\t PyErr_SetString(PyExc_TypeError,\n\t\t\t \"function not supported for the spacesaver array with the largest typecode.\");\n\t return -1;\n\t}\n\t\t\n\tfor(j=0; jnargs; j++) /* Input arguments */\n\t arg_types[j] = (self->types[i*self->nargs+j] | SAVESPACEBIT); \n }\n \n \n *data = self->data[i];\n *function = self->functions[i];\n\t\n return 0;\n}\n\nstatic int scipy_setup_matrices(PyUFuncObject *self, PyObject *args, \n\t\t\t\tPyUFuncGenericFunction *function, void **data,\n\t\t\t\tPyArrayObject **mps, char *arg_types) {\n int nargs, i;\n char *scalars=NULL;\n PyObject *obj;\n int temp;\n\t \n nargs = PyTuple_Size(args);\n if ((nargs != self->nin) && (nargs != self->nin+self->nout)) {\n\tPyErr_SetString(PyExc_ValueError, \"invalid number of arguments\");\n\treturn -1;\n }\n\n scalars = calloc(self->nin, sizeof(char));\n if (scalars == NULL) {\n PyErr_NoMemory();\n return -1;\n }\n\n /* Determine the types of the input arguments. */\n for(i=0; inin; i++) {\n obj = PyTuple_GET_ITEM(args,i);\n\targ_types[i] = (char)PyArray_ObjectType(obj, 0);\n\tif (PyArray_Check(obj)) {\n\t if (PyArray_ISSPACESAVER(obj)) \n\t\targ_types[i] |= SAVESPACEBIT;\n\t else if (PyArray_ISFROMSCALAR(obj)) {\n\t\ttemp = OFFSCALAR(obj);\n\t\tif (temp == PyArray_LONG) {\n\t\t if (((long *)(((PyArrayObject *)obj)->data))[0] < 0) \n\t\t\tscalars[i] = PYINTNEG;\n\t\t else scalars[i] = PYINTPOS;\n\t\t}\n\t\telse if (temp == PyArray_DOUBLE) scalars[i] = PYFLOAT;\n\t\telse if (temp == PyArray_CDOUBLE) scalars[i] = PYCOMPLEX;\n\t }\n\t}\n\telse {\n\t if (PyInt_Check(obj)) {\n\t\tif (PyInt_AS_LONG(obj) < 0) scalars[i] = PYINTNEG;\n\t\telse scalars[i] = PYINTPOS;\n\t }\n\t else if (PyFloat_Check(obj)) scalars[i] = PYFLOAT;\n\t else if (PyComplex_Check(obj)) scalars[i] = PYCOMPLEX;\n\t}\n }\n\t\n\n /* Select an appropriate function for these argument types. */\n temp = scipy_select_types(self, arg_types, data, function, scalars);\n free(scalars);\n if (temp == -1) return -1;\n\n /* Coerce input arguments to the right types. */\n for(i=0; inin; i++) {\n\tif ((mps[i] = (PyArrayObject *)PyArray_FromObject(PyTuple_GET_ITEM(args,\n\t\t\t\t\t\t\t\t\t i),\n\t\t\t\t\t\t\t arg_types[i], 0, 0)) == NULL) {\n\t return -1;\n\t}\n }\n\t\n /* Check the return arguments, and INCREF. */\n for(i = self->nin;idescr->type_num != (arg_types[i] & ~((char )SAVESPACEBIT))) {\n\t PyErr_SetString(PyExc_TypeError, \"return array has incorrect type\");\n\t return -1;\n\t}\n }\n\t\n return nargs;\n}\n\nstatic int scipy_setup_return(PyUFuncObject *self, int nd, int *dimensions, int steps[MAX_DIMS][MAX_ARGS], \n PyArrayObject **mps, char *arg_types) {\n int i, j;\n\t\n\t\n /* Initialize the return matrices, or check if provided. */\n for(i=self->nin; inargs; i++) {\n\tif (mps[i] == NULL) {\n\t if ((mps[i] = (PyArrayObject *)PyArray_FromDims(nd, dimensions,\n\t\t\t\t\t\t\t arg_types[i])) == NULL)\n\t\treturn -1;\n\t} else {\n\t if (!scipy_compare_lists(mps[i]->dimensions, dimensions, nd)) {\n\t\tPyErr_SetString(PyExc_ValueError, \"invalid return array shape\");\n\t\treturn -1;\n\t }\n\t}\n\tfor(j=0; jnd; j++) {\n\t steps[j][i] = scipy_get_stride(mps[i], j+mps[i]->nd-nd);\n\t}\n\t/* Small hack to keep purify happy (no UMR's for 0d array's) */\n\tif (mps[i]->nd == 0) steps[0][i] = 0;\n }\n return 0;\n}\n\nstatic int scipy_optimize_loop(int steps[MAX_DIMS][MAX_ARGS], int *loop_n, int n_loops) {\n int j, tmp;\n\t\n#define swap(x, y) tmp = (x), (x) = (y), (y) = tmp\n\t\n /* Here should go some code to \"compress\" the loops. */\n\t\n if (n_loops > 1 && (loop_n[n_loops-1] < loop_n[n_loops-2]) ) {\n\tswap(loop_n[n_loops-1], loop_n[n_loops-2]);\n\tfor (j=0; jnin; i++) nd = max(nd, mps[i]->nd);\n\t\n /* Setup the loop. This can be optimized later. */\n n_loops = 0;\n\t\n for(i=0; inin; j++) {\n\t if (i + mps[j]->nd-nd >= 0) tmp = mps[j]->dimensions[i + mps[j]->nd-nd];\n\t else tmp = 1; \n\t\t\t\n\t if (tmp == 1) { \n\t\tsteps[n_loops][j] = 0;\n\t } else {\n\t\tif (dimensions[i] == 1) dimensions[i] = tmp;\n\t\telse if (dimensions[i] != tmp) {\n\t\t PyErr_SetString(PyExc_ValueError, \"frames are not aligned\");\n\t\t return -1;\n\t\t}\n\t\tsteps[n_loops][j] = scipy_get_stride(mps[j], i + mps[j]->nd-nd);\n\t }\n\t}\n\tloop_n[n_loops] = dimensions[i];\n\tn_loops++;\n }\n\t\n /* Small hack to keep purify happy (no UMR's for 0d array's) */\n if (nd == 0) {\n\tfor(j=0; jnin; j++) steps[0][j] = 0;\n }\n\t\n if (scipy_setup_return(self, nd, dimensions, steps, mps, arg_types) == -1) return -1;\n\t\n n_loops = scipy_optimize_loop(steps, loop_n, n_loops);\n\t\n return n_loops;\n}\n\nstatic int scipy_PyUFunc_GenericFunction(PyUFuncObject *self, PyObject *args, PyArrayObject **mps) {\n int steps[MAX_DIMS][MAX_ARGS];\n int i, loop, n_loops, loop_i[MAX_DIMS], loop_n[MAX_DIMS];\n char *pointers[MAX_ARGS], *resets[MAX_DIMS][MAX_ARGS];\n void *data;\n PyUFuncGenericFunction function;\n\t\n if (self == NULL) {\n\tPyErr_SetString(PyExc_ValueError, \"function not supported\");\n\treturn -1;\n }\n\t\n n_loops = scipy_setup_loop(self, args, &function, &data, steps, loop_n, mps);\n if (n_loops == -1) return -1;\n\t\n for(i=0; inargs; i++) pointers[i] = mps[i]->data;\n\t\n errno = 0;\n if (n_loops == 0) {\n\tn_loops = 1;\n\tfunction(pointers, &n_loops, steps[0], data);\n } else {\n\t/* This is the inner loop to actually do the computation. */\n\tloop=-1;\n\twhile(1) {\n\t while (loop < n_loops-2) {\n\t\tloop++;\n\t\tloop_i[loop] = 0;\n\t\tfor(i=0; inin+self->nout; i++) { resets[loop][i] = pointers[i]; }\n\t }\n\t\t\t\n\t function(pointers, loop_n+(n_loops-1), steps[n_loops-1], data);\n\t\t\t\n\t while (loop >= 0 && !(++loop_i[loop] < loop_n[loop]) && loop >= 0) loop--;\n\t if (loop < 0) break;\n\t for(i=0; inin+self->nout; i++) { pointers[i] = resets[loop][i] + steps[loop][i]*loop_i[loop]; }\n\t}\n }\n if (PyErr_Occurred()) return -1;\n\t\n /* Cleanup the returned matrices so that scalars will be returned as python scalars */\n /* We don't use this in SciPy --- will disable checking for all ufuncs */\n /*\n if (self->check_return) {\n for(i=self->nin; inout+self->nin; i++) check_array(mps[i]);\n if (errno != 0) {\n math_error();\n return -1;\n }\n }\n */\n\n return 0;\n}\n\n/* -------------------------------------------------------------- */\n\ntypedef struct {\n PyUFuncObject *add, \n\t*subtract, \n\t*multiply, \n\t*divide, \n\t*remainder, \n\t*power, \n\t*negative, \n\t*absolute;\n PyUFuncObject *invert, \n\t*left_shift, \n\t*right_shift, \n\t*bitwise_and, \n\t*bitwise_xor,\n\t*bitwise_or;\n PyUFuncObject *less, /* Added by Scott N. Gunyan */\n *less_equal, /* for rich comparisons */\n *equal,\n *not_equal,\n *greater,\n *greater_equal;\n PyUFuncObject *floor_divide, /* Added by Bruce Sherwood */\n *true_divide; /* for floor and true divide */\n} NumericOps;\n\n\nstatic NumericOps sn_ops;\n\n#define GET(op) sn_ops.op = (PyUFuncObject *)PyDict_GetItemString(dict, #op)\n\nstatic int scipy_SetNumericOps(PyObject *dict) {\n GET(add);\n GET(subtract);\n GET(multiply);\n GET(divide);\n GET(remainder);\n GET(power);\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); /* Added by Scott N. Gunyan */\n GET(less_equal); /* for rich comparisons */\n GET(equal);\n GET(not_equal);\n GET(greater);\n GET(greater_equal);\n GET(floor_divide); /* Added by Bruce Sherwood */\n GET(true_divide); /* for floor and true divide */\n return 0;\n}\n\n/* This is getting called */ \nstatic int scipy_array_coerce(PyArrayObject **pm, PyObject **pw) {\n PyObject *new_op;\n char isscalar = 0;\n\n if (PyInt_Check(*pw) || PyFloat_Check(*pw) || PyComplex_Check(*pw)) {\n\tisscalar = 1;\n }\n if ((new_op = PyArray_FromObject(*pw, PyArray_NOTYPE, 0, 0)) \n\t== NULL) \n\treturn -1;\n Py_INCREF(*pm);\n *pw = new_op;\n if (isscalar) MAKEFROMSCALAR(*pw);\n return 0;\n }\n\nstatic PyObject *PyUFunc_BinaryFunction(PyUFuncObject *s, PyArrayObject *mp1, PyObject *mp2) {\n PyObject *arglist;\n PyArrayObject *mps[3];\n\n arglist = Py_BuildValue(\"(OO)\", mp1, mp2);\n mps[0] = mps[1] = mps[2] = NULL;\n if (scipy_PyUFunc_GenericFunction(s, arglist, mps) == -1) {\n\tPy_DECREF(arglist);\n\tPy_XDECREF(mps[0]); Py_XDECREF(mps[1]); Py_XDECREF(mps[2]);\n\treturn NULL;\n }\n\t\n Py_DECREF(mps[0]); Py_DECREF(mps[1]);\n Py_DECREF(arglist);\n return PyArray_Return(mps[2]);\n}\n\n/*This method adds the augmented assignment*/\n/*functionality that was made available in Python 2.0*/\nstatic PyObject *PyUFunc_InplaceBinaryFunction(PyUFuncObject *s, PyArrayObject *mp1, PyObject *mp2) {\n PyObject *arglist;\n PyArrayObject *mps[3];\n\t\n arglist = Py_BuildValue(\"(OOO)\", mp1, mp2, mp1);\n\t\n mps[0] = mps[1] = mps[2] = NULL;\n if (scipy_PyUFunc_GenericFunction(s, arglist, mps) == -1) {\n\tPy_DECREF(arglist);\n\tPy_XDECREF(mps[0]); Py_XDECREF(mps[1]); Py_XDECREF(mps[2]);\n\treturn NULL;\n }\n\t\n Py_DECREF(mps[0]); Py_DECREF(mps[1]);\n Py_DECREF(arglist);\n return PyArray_Return(mps[2]);\n}\n\nstatic PyObject *PyUFunc_UnaryFunction(PyUFuncObject *s, PyArrayObject *mp1) {\n PyObject *arglist;\n PyArrayObject *mps[3];\n\t\n arglist = Py_BuildValue(\"(O)\", mp1);\n\t\n mps[0] = mps[1] = NULL;\n if (scipy_PyUFunc_GenericFunction(s, arglist, mps) == -1) {\n\tPy_DECREF(arglist);\n\tPy_XDECREF(mps[0]); Py_XDECREF(mps[1]);\n\treturn NULL;\n }\n\t\n Py_DECREF(mps[0]);\n Py_DECREF(arglist);\n return PyArray_Return(mps[1]);\n}\n\n/* Could add potential optimizations here for special casing certain conditions...*/\n\nstatic PyObject *scipy_array_add(PyArrayObject *m1, PyObject *m2) {\n return PyUFunc_BinaryFunction(sn_ops.add, m1, m2);\n}\nstatic PyObject *scipy_array_subtract(PyArrayObject *m1, PyObject *m2) {\n return PyUFunc_BinaryFunction(sn_ops.subtract, m1, m2);\n}\nstatic PyObject *scipy_array_multiply(PyArrayObject *m1, PyObject *m2) {\n return PyUFunc_BinaryFunction(sn_ops.multiply, m1, m2);\n}\nstatic PyObject *scipy_array_divide(PyArrayObject *m1, PyObject *m2) {\n return PyUFunc_BinaryFunction(sn_ops.divide, m1, m2);\n}\nstatic PyObject *scipy_array_remainder(PyArrayObject *m1, PyObject *m2) {\n return PyUFunc_BinaryFunction(sn_ops.remainder, m1, m2);\n}\nstatic PyObject *scipy_array_power(PyArrayObject *m1, PyObject *m2) {\n return PyUFunc_BinaryFunction(sn_ops.power, m1, m2);\n}\nstatic PyObject *scipy_array_negative(PyArrayObject *m1) { \n return PyUFunc_UnaryFunction(sn_ops.negative, m1);\n}\nstatic PyObject *scipy_array_absolute(PyArrayObject *m1) { \n return PyUFunc_UnaryFunction(sn_ops.absolute, m1);\n}\nstatic PyObject *scipy_array_invert(PyArrayObject *m1) { \n return PyUFunc_UnaryFunction(sn_ops.invert, m1);\n}\nstatic PyObject *scipy_array_left_shift(PyArrayObject *m1, PyObject *m2) {\n return PyUFunc_BinaryFunction(sn_ops.left_shift, m1, m2);\n}\nstatic PyObject *scipy_array_right_shift(PyArrayObject *m1, PyObject *m2) {\n return PyUFunc_BinaryFunction(sn_ops.right_shift, m1, m2);\n}\nstatic PyObject *scipy_array_bitwise_and(PyArrayObject *m1, PyObject *m2) {\n return PyUFunc_BinaryFunction(sn_ops.bitwise_and, m1, m2);\n}\nstatic PyObject *scipy_array_bitwise_or(PyArrayObject *m1, PyObject *m2) {\n return PyUFunc_BinaryFunction(sn_ops.bitwise_or, m1, m2);\n}\nstatic PyObject *scipy_array_bitwise_xor(PyArrayObject *m1, PyObject *m2) {\n return PyUFunc_BinaryFunction(sn_ops.bitwise_xor, m1, m2);\n}\n\n\n/*These methods add the augmented assignment*/\n/*functionality that was made available in Python 2.0*/\nstatic PyObject *scipy_array_inplace_add(PyArrayObject *m1, PyObject *m2) {\n return PyUFunc_InplaceBinaryFunction(sn_ops.add, m1, m2);\n}\nstatic PyObject *scipy_array_inplace_subtract(PyArrayObject *m1, PyObject *m2) {\n return PyUFunc_InplaceBinaryFunction(sn_ops.subtract, m1, m2);\n}\nstatic PyObject *scipy_array_inplace_multiply(PyArrayObject *m1, PyObject *m2) {\n return PyUFunc_InplaceBinaryFunction(sn_ops.multiply, m1, m2);\n}\nstatic PyObject *scipy_array_inplace_divide(PyArrayObject *m1, PyObject *m2) {\n return PyUFunc_InplaceBinaryFunction(sn_ops.divide, m1, m2);\n}\nstatic PyObject *scipy_array_inplace_remainder(PyArrayObject *m1, PyObject *m2) {\n return PyUFunc_InplaceBinaryFunction(sn_ops.remainder, m1, m2);\n}\nstatic PyObject *scipy_array_inplace_power(PyArrayObject *m1, PyObject *m2) {\n return PyUFunc_InplaceBinaryFunction(sn_ops.power, m1, m2);\n}\nstatic PyObject *scipy_array_inplace_left_shift(PyArrayObject *m1, PyObject *m2) {\n return PyUFunc_InplaceBinaryFunction(sn_ops.left_shift, m1, m2);\n}\nstatic PyObject *scipy_array_inplace_right_shift(PyArrayObject *m1, PyObject *m2) {\n return PyUFunc_InplaceBinaryFunction(sn_ops.right_shift, m1, m2);\n}\nstatic PyObject *scipy_array_inplace_bitwise_and(PyArrayObject *m1, PyObject *m2) {\n return PyUFunc_InplaceBinaryFunction(sn_ops.bitwise_and, m1, m2);\n}\nstatic PyObject *scipy_array_inplace_bitwise_or(PyArrayObject *m1, PyObject *m2) {\n return PyUFunc_InplaceBinaryFunction(sn_ops.bitwise_or, m1, m2);\n}\nstatic PyObject *scipy_array_inplace_bitwise_xor(PyArrayObject *m1, PyObject *m2) {\n return PyUFunc_InplaceBinaryFunction(sn_ops.bitwise_xor, m1, m2);\n}\n\n/*Added by Bruce Sherwood Dec 2001*/\n/*These methods add the floor and true division*/\n/*functionality that was made available in Python 2.2*/\nstatic PyObject *scipy_array_floor_divide(PyArrayObject *m1, PyObject *m2) {\n return PyUFunc_BinaryFunction(sn_ops.floor_divide, m1, m2);\n}\nstatic PyObject *scipy_array_true_divide(PyArrayObject *m1, PyObject *m2) {\n return PyUFunc_BinaryFunction(sn_ops.true_divide, m1, m2);\n}\nstatic PyObject *scipy_array_inplace_floor_divide(PyArrayObject *m1, PyObject *m2) {\n return PyUFunc_InplaceBinaryFunction(sn_ops.floor_divide, m1, m2);\n}\nstatic PyObject *scipy_array_inplace_true_divide(PyArrayObject *m1, PyObject *m2) {\n return PyUFunc_InplaceBinaryFunction(sn_ops.true_divide, m1, m2);\n}\n/*End of methods added by Bruce Sherwood*/\n\n/* Array evaluates as \"true\" if any of the elements are non-zero */\nstatic int scipy_array_nonzero(PyArrayObject *mp) {\n char *zero;\n PyArrayObject *self;\n char *data;\n int i, s, elsize;\n\t\n self = PyArray_CONTIGUOUS(mp);\n zero = self->descr->zero;\n\n s = SIZE(self);\n elsize = self->descr->elsize;\n data = self->data;\n for(i=0; idescr->getitem(v->data);\n if (pv == NULL) return NULL;\n if (pv->ob_type->tp_as_number == 0) {\n\tPyErr_SetString(PyExc_TypeError, \"cannot convert to an int, scalar object is not a number.\");\n\tPy_DECREF(pv);\n\treturn NULL;\n }\n if (pv->ob_type->tp_as_number->nb_int == 0) {\n\tPyErr_SetString(PyExc_TypeError, \"don't know how to convert scalar number to int\");\n\tPy_DECREF(pv);\n\treturn NULL;\n }\n\n pv2 = pv->ob_type->tp_as_number->nb_int(pv);\n Py_DECREF(pv);\n return pv2; \n}\n\nstatic PyObject *scipy_array_float(PyArrayObject *v) {\n PyObject *pv, *pv2;\n if (PyArray_SIZE(v) != 1) {\n\tPyErr_SetString(PyExc_TypeError, \"only length-1 arrays can be converted to Python scalars.\");\n\treturn NULL;\n }\n pv = v->descr->getitem(v->data);\n if (pv == NULL) return NULL;\n if (pv->ob_type->tp_as_number == 0) {\n\tPyErr_SetString(PyExc_TypeError, \"cannot convert to an int, scalar object is not a number.\");\n\tPy_DECREF(pv);\n\treturn NULL;\n }\n if (pv->ob_type->tp_as_number->nb_float == 0) {\n\tPyErr_SetString(PyExc_TypeError, \"don't know how to convert scalar number to float\");\n\tPy_DECREF(pv);\n\treturn NULL;\n }\n pv2 = pv->ob_type->tp_as_number->nb_float(pv);\n Py_DECREF(pv);\n return pv2; \n}\n\nstatic PyObject *scipy_array_long(PyArrayObject *v) { \n PyObject *pv, *pv2;\n if (PyArray_SIZE(v) != 1) {\n\tPyErr_SetString(PyExc_TypeError, \"only length-1 arrays can be converted to Python scalars.\");\n\treturn NULL;\n }\n pv = v->descr->getitem(v->data);\n if (pv->ob_type->tp_as_number == 0) {\n\tPyErr_SetString(PyExc_TypeError, \"cannot convert to an int, scalar object is not a number.\");\n\treturn NULL;\n }\n if (pv->ob_type->tp_as_number->nb_long == 0) {\n\tPyErr_SetString(PyExc_TypeError, \"don't know how to convert scalar number to long\");\n\treturn NULL;\n }\n pv2 = pv->ob_type->tp_as_number->nb_long(pv);\n Py_DECREF(pv);\n return pv2; \n}\n\nstatic PyObject *scipy_array_oct(PyArrayObject *v) { \n PyObject *pv, *pv2;\n if (PyArray_SIZE(v) != 1) {\n\tPyErr_SetString(PyExc_TypeError, \"only length-1 arrays can be converted to Python scalars.\");\n\treturn NULL;\n }\n pv = v->descr->getitem(v->data);\n if (pv->ob_type->tp_as_number == 0) {\n\tPyErr_SetString(PyExc_TypeError, \"cannot convert to an int, scalar object is not a number.\");\n\treturn NULL;\n }\n if (pv->ob_type->tp_as_number->nb_oct == 0) {\n\tPyErr_SetString(PyExc_TypeError, \"don't know how to convert scalar number to oct\");\n\treturn NULL;\n }\n pv2 = pv->ob_type->tp_as_number->nb_oct(pv);\n Py_DECREF(pv);\n return pv2; \n}\n\nstatic PyObject *scipy_array_hex(PyArrayObject *v) { \n PyObject *pv, *pv2;\n if (PyArray_SIZE(v) != 1) {\n\tPyErr_SetString(PyExc_TypeError, \"only length-1 arrays can be converted to Python scalars.\");\n\treturn NULL;\n }\n pv = v->descr->getitem(v->data);\n if (pv->ob_type->tp_as_number == 0) {\n\tPyErr_SetString(PyExc_TypeError, \"cannot convert to an int, scalar object is not a number.\");\n\treturn NULL;\n }\n if (pv->ob_type->tp_as_number->nb_hex == 0) {\n\tPyErr_SetString(PyExc_TypeError, \"don't know how to convert scalar number to hex\");\n\treturn NULL;\n }\n pv2 = pv->ob_type->tp_as_number->nb_hex(pv);\n Py_DECREF(pv);\n return pv2; \n}\n\n\n\n/* ---------- */\n\nstatic PyObject *scipy_ufunc_call(PyUFuncObject *self, PyObject *args) {\n int i;\n PyTupleObject *ret;\n PyArrayObject *mps[MAX_ARGS];\n\t\n /* Initialize all array objects to NULL to make cleanup easier if something goes wrong. */\n for(i=0; inargs; i++) mps[i] = NULL;\n\t\n if (scipy_PyUFunc_GenericFunction(self, args, mps) == -1) {\n\t for(i=0; inargs; i++) { \n\t\t if (mps[i] != NULL) { \n\t\t\t Py_DECREF(mps[i]); \n\t\t }\n\t }\n\treturn NULL;\n }\n\t\n for(i=0; inin; i++) Py_DECREF(mps[i]);\n\t\n if (self->nout == 1) { \n\treturn PyArray_Return(mps[self->nin]); \n } else { \n\tret = (PyTupleObject *)PyTuple_New(self->nout);\n\tfor(i=0; inout; i++) {\n\t PyTuple_SET_ITEM(ret, i, PyArray_Return(mps[i+self->nin]));\n\t}\n\treturn (PyObject *)ret;\n }\n}\n", "source_code_before": "/* Numeric's source code for array-object ufuncs\n\n Only thing changed is the coercion model (select_types and setup_matrices)\n\n When no savespace bit is present then...\n Scalars (Python Objects) only change INT to FLOAT or FLOAT to COMPLEX but\n otherwise do not cause upcasting. \n\n*/\n\n#define SIZE(mp) (_PyArray_multiply_list((mp)->dimensions, (mp)->nd))\n#define NBYTES(mp) ((mp)->descr->elsize * SIZE(mp))\n/* Obviously this needs some work. */\n#define ISCONTIGUOUS(m) ((m)->flags & CONTIGUOUS)\n#define PyArray_CONTIGUOUS(m) (ISCONTIGUOUS(m) ? Py_INCREF(m), m : \\\n(PyArrayObject *)(PyArray_ContiguousFromObject((PyObject *)(m), \\\n(m)->descr->type_num, 0,0)))\n\n#ifndef max\n#define max(x,y) (x)>(y)?(x):(y)\n#endif\n#ifndef min\n#define min(x,y) (x)>(y)?(y):(x)\n#endif\n\nstatic int scipy_compare_lists(int *l1, int *l2, int n) {\n int i;\n for(i=0;istrides[d];\n}\n\n\nstatic PyObject *scipy_array_copy(PyArrayObject *m1) {\n PyArrayObject *ret = \n\t(PyArrayObject *)PyArray_FromDims(m1->nd, m1->dimensions, m1->descr->type_num);\n\t\n if (PyArray_CopyArray(ret, m1) == -1) return NULL;\n\t\n return (PyObject *)ret;\n}\n\n#define SCALARBIT 2048\n#define MAKEFROMSCALAR(obj) (((PyArrayObject *)(obj))->descr->type_num |= SCALARBIT)\n#define PyArray_ISFROMSCALAR(obj) ((((PyArrayObject*)(obj))->descr->type_num & SCALARBIT))\n#define OFFSCALAR(obj) (((PyArrayObject *)(obj))->descr->type_num &= ~((int) SCALARBIT))\n#define PYNOSCALAR 0\n#define PYINTPOS 1\n#define PYINTNEG 2\n#define PYFLOAT 3\n#define PYCOMPLEX 4\n\n\n/* This function is called while searching for an appropriate ufunc\n\n It should return a 0 if coercion of thistype to neededtype is not safe.\n\n It uses PyArray_CanCastSafely but adds special logic to allow Python \n scalars to be downcast within the same kind if they are in the presence\n of arrays.\n\n */\nstatic int scipy_cancoerce(char thistype, char neededtype, char scalar) {\n\n if (scalar==PYNOSCALAR) return PyArray_CanCastSafely(thistype, neededtype);\n if (scalar==PYINTPOS) \n return (neededtype >= PyArray_UBYTE);\n if (scalar==PYINTNEG)\n\treturn ((neededtype >= PyArray_SBYTE) && (neededtype != PyArray_USHORT) && (neededtype != PyArray_UINT));\n if (scalar==PYFLOAT)\n return (neededtype >= PyArray_FLOAT);\n if (scalar==PYCOMPLEX)\n return (neededtype >= PyArray_CFLOAT);\n return 1; /* should never get here... */ \n}\n\nstatic int scipy_select_types(PyUFuncObject *self, char *arg_types, void **data, \n\t\t\t PyUFuncGenericFunction *function, char *scalars) {\n int i=0, j;\n int k=0;\n char largest_savespace = 0, real_type;\n\n for (j=0; jnin; j++) {\n\treal_type = arg_types[j] & ~((char )SAVESPACEBIT);\n\tif ((arg_types[j] & SAVESPACEBIT) && (real_type > largest_savespace)) \n\t largest_savespace = real_type;\n }\n\n if (largest_savespace == 0) {\n\n /* start search for signature at first reasonable choice (first array-based\n type --- won't use scalar for this check)*/\n while(knin && scalars[k] != PYNOSCALAR) k++;\n if (k == self->nin) { /* no arrays */\n\t /* so use usual coercion rules -- ignore scalar handling */\n\t for (j=0; jnin; j++) {\n\t\tscalars[j] = PYNOSCALAR;\n\t }\n\t k = 0;\n\t}\n while (intypes && arg_types[k] > self->types[i*self->nargs+k]) i++;\n \n /* Signature search */\n for(;intypes; i++) {\n for(j=0; jnin; j++) {\n if (!scipy_cancoerce(arg_types[j], self->types[i*self->nargs+j],\n scalars[j])) break;\n }\n if (j == self->nin) break; /* Found signature that will work */\n /* Otherwise, increment i and check next signature */\n }\n if(i>=self->ntypes) {\n PyErr_SetString(PyExc_TypeError, \n \"function not supported for these types, and can't coerce to supported types\");\n return -1;\n }\n\n /* reset arg_types to those needed for this signature */\n for(j=0; jnargs; j++) \n arg_types[j] = (self->types[i*self->nargs+j] & ~((char )SAVESPACEBIT));\n }\n else {\n\twhile(intypes && largest_savespace > self->types[i*self->nargs]) i++;\n\tif (i>=self->ntypes || largest_savespace < self->types[i*self->nargs]) {\n\t PyErr_SetString(PyExc_TypeError,\n\t\t\t \"function not supported for the spacesaver array with the largest typecode.\");\n\t return -1;\n\t}\n\t\t\n\tfor(j=0; jnargs; j++) /* Input arguments */\n\t arg_types[j] = (self->types[i*self->nargs+j] | SAVESPACEBIT); \n }\n \n \n *data = self->data[i];\n *function = self->functions[i];\n\t\n return 0;\n}\n\nstatic int scipy_setup_matrices(PyUFuncObject *self, PyObject *args, \n\t\t\t\tPyUFuncGenericFunction *function, void **data,\n\t\t\t\tPyArrayObject **mps, char *arg_types) {\n int nargs, i;\n char *scalars=NULL;\n PyObject *obj;\n int temp;\n\t \n nargs = PyTuple_Size(args);\n if ((nargs != self->nin) && (nargs != self->nin+self->nout)) {\n\tPyErr_SetString(PyExc_ValueError, \"invalid number of arguments\");\n\treturn -1;\n }\n\n scalars = calloc(self->nin, sizeof(char));\n if (scalars == NULL) {\n PyErr_NoMemory();\n return -1;\n }\n\n /* Determine the types of the input arguments. */\n for(i=0; inin; i++) {\n obj = PyTuple_GET_ITEM(args,i);\n\targ_types[i] = (char)PyArray_ObjectType(obj, 0);\n\tif (PyArray_Check(obj)) {\n\t if (PyArray_ISSPACESAVER(obj)) \n\t\targ_types[i] |= SAVESPACEBIT;\n\t else if (PyArray_ISFROMSCALAR(obj)) {\n\t\ttemp = OFFSCALAR(obj);\n\t\tif (temp == PyArray_LONG) {\n\t\t if (((long *)(((PyArrayObject *)obj)->data))[0] < 0) \n\t\t\tscalars[i] = PYINTNEG;\n\t\t else scalars[i] = PYINTPOS;\n\t\t}\n\t\telse if (temp == PyArray_DOUBLE) scalars[i] = PYFLOAT;\n\t\telse if (temp == PyArray_CDOUBLE) scalars[i] = PYCOMPLEX;\n\t }\n\t}\n\telse {\n\t if (PyInt_Check(obj)) {\n\t\tif (PyInt_AS_LONG(obj) < 0) scalars[i] = PYINTNEG;\n\t\telse scalars[i] = PYINTPOS;\n\t }\n\t else if (PyFloat_Check(obj)) scalars[i] = PYFLOAT;\n\t else if (PyComplex_Check(obj)) scalars[i] = PYCOMPLEX;\n\t}\n }\n\t\n\n /* Select an appropriate function for these argument types. */\n temp = scipy_select_types(self, arg_types, data, function, scalars);\n free(scalars);\n if (temp == -1) return -1;\n\n /* Coerce input arguments to the right types. */\n for(i=0; inin; i++) {\n\tif ((mps[i] = (PyArrayObject *)PyArray_FromObject(PyTuple_GET_ITEM(args,\n\t\t\t\t\t\t\t\t\t i),\n\t\t\t\t\t\t\t arg_types[i], 0, 0)) == NULL) {\n\t return -1;\n\t}\n }\n\t\n /* Check the return arguments, and INCREF. */\n for(i = self->nin;idescr->type_num != (arg_types[i] & ~((char )SAVESPACEBIT))) {\n\t PyErr_SetString(PyExc_TypeError, \"return array has incorrect type\");\n\t return -1;\n\t}\n }\n\t\n return nargs;\n}\n\nstatic int scipy_setup_return(PyUFuncObject *self, int nd, int *dimensions, int steps[MAX_DIMS][MAX_ARGS], \n PyArrayObject **mps, char *arg_types) {\n int i, j;\n\t\n\t\n /* Initialize the return matrices, or check if provided. */\n for(i=self->nin; inargs; i++) {\n\tif (mps[i] == NULL) {\n\t if ((mps[i] = (PyArrayObject *)PyArray_FromDims(nd, dimensions,\n\t\t\t\t\t\t\t arg_types[i])) == NULL)\n\t\treturn -1;\n\t} else {\n\t if (!scipy_compare_lists(mps[i]->dimensions, dimensions, nd)) {\n\t\tPyErr_SetString(PyExc_ValueError, \"invalid return array shape\");\n\t\treturn -1;\n\t }\n\t}\n\tfor(j=0; jnd; j++) {\n\t steps[j][i] = scipy_get_stride(mps[i], j+mps[i]->nd-nd);\n\t}\n\t/* Small hack to keep purify happy (no UMR's for 0d array's) */\n\tif (mps[i]->nd == 0) steps[0][i] = 0;\n }\n return 0;\n}\n\nstatic int scipy_optimize_loop(int steps[MAX_DIMS][MAX_ARGS], int *loop_n, int n_loops) {\n int j, tmp;\n\t\n#define swap(x, y) tmp = (x), (x) = (y), (y) = tmp\n\t\n /* Here should go some code to \"compress\" the loops. */\n\t\n if (n_loops > 1 && (loop_n[n_loops-1] < loop_n[n_loops-2]) ) {\n\tswap(loop_n[n_loops-1], loop_n[n_loops-2]);\n\tfor (j=0; jnin; i++) nd = max(nd, mps[i]->nd);\n\t\n /* Setup the loop. This can be optimized later. */\n n_loops = 0;\n\t\n for(i=0; inin; j++) {\n\t if (i + mps[j]->nd-nd >= 0) tmp = mps[j]->dimensions[i + mps[j]->nd-nd];\n\t else tmp = 1; \n\t\t\t\n\t if (tmp == 1) { \n\t\tsteps[n_loops][j] = 0;\n\t } else {\n\t\tif (dimensions[i] == 1) dimensions[i] = tmp;\n\t\telse if (dimensions[i] != tmp) {\n\t\t PyErr_SetString(PyExc_ValueError, \"frames are not aligned\");\n\t\t return -1;\n\t\t}\n\t\tsteps[n_loops][j] = scipy_get_stride(mps[j], i + mps[j]->nd-nd);\n\t }\n\t}\n\tloop_n[n_loops] = dimensions[i];\n\tn_loops++;\n }\n\t\n /* Small hack to keep purify happy (no UMR's for 0d array's) */\n if (nd == 0) {\n\tfor(j=0; jnin; j++) steps[0][j] = 0;\n }\n\t\n if (scipy_setup_return(self, nd, dimensions, steps, mps, arg_types) == -1) return -1;\n\t\n n_loops = scipy_optimize_loop(steps, loop_n, n_loops);\n\t\n return n_loops;\n}\n\nstatic int scipy_PyUFunc_GenericFunction(PyUFuncObject *self, PyObject *args, PyArrayObject **mps) {\n int steps[MAX_DIMS][MAX_ARGS];\n int i, loop, n_loops, loop_i[MAX_DIMS], loop_n[MAX_DIMS];\n char *pointers[MAX_ARGS], *resets[MAX_DIMS][MAX_ARGS];\n void *data;\n PyUFuncGenericFunction function;\n\t\n if (self == NULL) {\n\tPyErr_SetString(PyExc_ValueError, \"function not supported\");\n\treturn -1;\n }\n\t\n n_loops = scipy_setup_loop(self, args, &function, &data, steps, loop_n, mps);\n if (n_loops == -1) return -1;\n\t\n for(i=0; inargs; i++) pointers[i] = mps[i]->data;\n\t\n errno = 0;\n if (n_loops == 0) {\n\tn_loops = 1;\n\tfunction(pointers, &n_loops, steps[0], data);\n } else {\n\t/* This is the inner loop to actually do the computation. */\n\tloop=-1;\n\twhile(1) {\n\t while (loop < n_loops-2) {\n\t\tloop++;\n\t\tloop_i[loop] = 0;\n\t\tfor(i=0; inin+self->nout; i++) { resets[loop][i] = pointers[i]; }\n\t }\n\t\t\t\n\t function(pointers, loop_n+(n_loops-1), steps[n_loops-1], data);\n\t\t\t\n\t while (loop >= 0 && !(++loop_i[loop] < loop_n[loop]) && loop >= 0) loop--;\n\t if (loop < 0) break;\n\t for(i=0; inin+self->nout; i++) { pointers[i] = resets[loop][i] + steps[loop][i]*loop_i[loop]; }\n\t}\n }\n if (PyErr_Occurred()) return -1;\n\t\n /* Cleanup the returned matrices so that scalars will be returned as python scalars */\n /* We don't use this in SciPy --- will disable checking for all ufuncs */\n /*\n if (self->check_return) {\n for(i=self->nin; inout+self->nin; i++) check_array(mps[i]);\n if (errno != 0) {\n math_error();\n return -1;\n }\n }\n */\n\n return 0;\n}\n\n/* -------------------------------------------------------------- */\n\ntypedef struct {\n PyUFuncObject *add, \n\t*subtract, \n\t*multiply, \n\t*divide, \n\t*remainder, \n\t*power, \n\t*negative, \n\t*absolute;\n PyUFuncObject *invert, \n\t*left_shift, \n\t*right_shift, \n\t*bitwise_and, \n\t*bitwise_xor,\n\t*bitwise_or;\n PyUFuncObject *less, /* Added by Scott N. Gunyan */\n *less_equal, /* for rich comparisons */\n *equal,\n *not_equal,\n *greater,\n *greater_equal;\n PyUFuncObject *floor_divide, /* Added by Bruce Sherwood */\n *true_divide; /* for floor and true divide */\n} NumericOps;\n\n\nstatic NumericOps sn_ops;\n\n#define GET(op) sn_ops.op = (PyUFuncObject *)PyDict_GetItemString(dict, #op)\n\nstatic int scipy_SetNumericOps(PyObject *dict) {\n GET(add);\n GET(subtract);\n GET(multiply);\n GET(divide);\n GET(remainder);\n GET(power);\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); /* Added by Scott N. Gunyan */\n GET(less_equal); /* for rich comparisons */\n GET(equal);\n GET(not_equal);\n GET(greater);\n GET(greater_equal);\n GET(floor_divide); /* Added by Bruce Sherwood */\n GET(true_divide); /* for floor and true divide */\n return 0;\n}\n\n/* This is getting called */ \nstatic int scipy_array_coerce(PyArrayObject **pm, PyObject **pw) {\n PyObject *new_op;\n char isscalar = 0;\n\n if (PyInt_Check(*pw) || PyFloat_Check(*pw) || PyComplex_Check(*pw)) {\n\tisscalar = 1;\n }\n if ((new_op = PyArray_FromObject(*pw, PyArray_NOTYPE, 0, 0)) \n\t== NULL) \n\treturn -1;\n Py_INCREF(*pm);\n *pw = new_op;\n if (isscalar) MAKEFROMSCALAR(*pw);\n return 0;\n }\n\nstatic PyObject *PyUFunc_BinaryFunction(PyUFuncObject *s, PyArrayObject *mp1, PyObject *mp2) {\n PyObject *arglist;\n PyArrayObject *mps[3];\n\n arglist = Py_BuildValue(\"(OO)\", mp1, mp2);\n mps[0] = mps[1] = mps[2] = NULL;\n if (scipy_PyUFunc_GenericFunction(s, arglist, mps) == -1) {\n\tPy_DECREF(arglist);\n\tPy_XDECREF(mps[0]); Py_XDECREF(mps[1]); Py_XDECREF(mps[2]);\n\treturn NULL;\n }\n\t\n Py_DECREF(mps[0]); Py_DECREF(mps[1]);\n Py_DECREF(arglist);\n return PyArray_Return(mps[2]);\n}\n\n/*This method adds the augmented assignment*/\n/*functionality that was made available in Python 2.0*/\nstatic PyObject *PyUFunc_InplaceBinaryFunction(PyUFuncObject *s, PyArrayObject *mp1, PyObject *mp2) {\n PyObject *arglist;\n PyArrayObject *mps[3];\n\t\n arglist = Py_BuildValue(\"(OOO)\", mp1, mp2, mp1);\n\t\n mps[0] = mps[1] = mps[2] = NULL;\n if (scipy_PyUFunc_GenericFunction(s, arglist, mps) == -1) {\n\tPy_DECREF(arglist);\n\tPy_XDECREF(mps[0]); Py_XDECREF(mps[1]); Py_XDECREF(mps[2]);\n\treturn NULL;\n }\n\t\n Py_DECREF(mps[0]); Py_DECREF(mps[1]);\n Py_DECREF(arglist);\n return PyArray_Return(mps[2]);\n}\n\nstatic PyObject *PyUFunc_UnaryFunction(PyUFuncObject *s, PyArrayObject *mp1) {\n PyObject *arglist;\n PyArrayObject *mps[3];\n\t\n arglist = Py_BuildValue(\"(O)\", mp1);\n\t\n mps[0] = mps[1] = NULL;\n if (scipy_PyUFunc_GenericFunction(s, arglist, mps) == -1) {\n\tPy_DECREF(arglist);\n\tPy_XDECREF(mps[0]); Py_XDECREF(mps[1]);\n\treturn NULL;\n }\n\t\n Py_DECREF(mps[0]);\n Py_DECREF(arglist);\n return PyArray_Return(mps[1]);\n}\n\n/* Could add potential optimizations here for special casing certain conditions...*/\n\nstatic PyObject *scipy_array_add(PyArrayObject *m1, PyObject *m2) {\n return PyUFunc_BinaryFunction(sn_ops.add, m1, m2);\n}\nstatic PyObject *scipy_array_subtract(PyArrayObject *m1, PyObject *m2) {\n return PyUFunc_BinaryFunction(sn_ops.subtract, m1, m2);\n}\nstatic PyObject *scipy_array_multiply(PyArrayObject *m1, PyObject *m2) {\n return PyUFunc_BinaryFunction(sn_ops.multiply, m1, m2);\n}\nstatic PyObject *scipy_array_divide(PyArrayObject *m1, PyObject *m2) {\n return PyUFunc_BinaryFunction(sn_ops.divide, m1, m2);\n}\nstatic PyObject *scipy_array_remainder(PyArrayObject *m1, PyObject *m2) {\n return PyUFunc_BinaryFunction(sn_ops.remainder, m1, m2);\n}\nstatic PyObject *scipy_array_power(PyArrayObject *m1, PyObject *m2) {\n return PyUFunc_BinaryFunction(sn_ops.power, m1, m2);\n}\nstatic PyObject *scipy_array_negative(PyArrayObject *m1) { \n return PyUFunc_UnaryFunction(sn_ops.negative, m1);\n}\nstatic PyObject *scipy_array_absolute(PyArrayObject *m1) { \n return PyUFunc_UnaryFunction(sn_ops.absolute, m1);\n}\nstatic PyObject *scipy_array_invert(PyArrayObject *m1) { \n return PyUFunc_UnaryFunction(sn_ops.invert, m1);\n}\nstatic PyObject *scipy_array_left_shift(PyArrayObject *m1, PyObject *m2) {\n return PyUFunc_BinaryFunction(sn_ops.left_shift, m1, m2);\n}\nstatic PyObject *scipy_array_right_shift(PyArrayObject *m1, PyObject *m2) {\n return PyUFunc_BinaryFunction(sn_ops.right_shift, m1, m2);\n}\nstatic PyObject *scipy_array_bitwise_and(PyArrayObject *m1, PyObject *m2) {\n return PyUFunc_BinaryFunction(sn_ops.bitwise_and, m1, m2);\n}\nstatic PyObject *scipy_array_bitwise_or(PyArrayObject *m1, PyObject *m2) {\n return PyUFunc_BinaryFunction(sn_ops.bitwise_or, m1, m2);\n}\nstatic PyObject *scipy_array_bitwise_xor(PyArrayObject *m1, PyObject *m2) {\n return PyUFunc_BinaryFunction(sn_ops.bitwise_xor, m1, m2);\n}\n\n\n/*These methods add the augmented assignment*/\n/*functionality that was made available in Python 2.0*/\nstatic PyObject *scipy_array_inplace_add(PyArrayObject *m1, PyObject *m2) {\n return PyUFunc_InplaceBinaryFunction(sn_ops.add, m1, m2);\n}\nstatic PyObject *scipy_array_inplace_subtract(PyArrayObject *m1, PyObject *m2) {\n return PyUFunc_InplaceBinaryFunction(sn_ops.subtract, m1, m2);\n}\nstatic PyObject *scipy_array_inplace_multiply(PyArrayObject *m1, PyObject *m2) {\n return PyUFunc_InplaceBinaryFunction(sn_ops.multiply, m1, m2);\n}\nstatic PyObject *scipy_array_inplace_divide(PyArrayObject *m1, PyObject *m2) {\n return PyUFunc_InplaceBinaryFunction(sn_ops.divide, m1, m2);\n}\nstatic PyObject *scipy_array_inplace_remainder(PyArrayObject *m1, PyObject *m2) {\n return PyUFunc_InplaceBinaryFunction(sn_ops.remainder, m1, m2);\n}\nstatic PyObject *scipy_array_inplace_power(PyArrayObject *m1, PyObject *m2) {\n return PyUFunc_InplaceBinaryFunction(sn_ops.power, m1, m2);\n}\nstatic PyObject *scipy_array_inplace_left_shift(PyArrayObject *m1, PyObject *m2) {\n return PyUFunc_InplaceBinaryFunction(sn_ops.left_shift, m1, m2);\n}\nstatic PyObject *scipy_array_inplace_right_shift(PyArrayObject *m1, PyObject *m2) {\n return PyUFunc_InplaceBinaryFunction(sn_ops.right_shift, m1, m2);\n}\nstatic PyObject *scipy_array_inplace_bitwise_and(PyArrayObject *m1, PyObject *m2) {\n return PyUFunc_InplaceBinaryFunction(sn_ops.bitwise_and, m1, m2);\n}\nstatic PyObject *scipy_array_inplace_bitwise_or(PyArrayObject *m1, PyObject *m2) {\n return PyUFunc_InplaceBinaryFunction(sn_ops.bitwise_or, m1, m2);\n}\nstatic PyObject *scipy_array_inplace_bitwise_xor(PyArrayObject *m1, PyObject *m2) {\n return PyUFunc_InplaceBinaryFunction(sn_ops.bitwise_xor, m1, m2);\n}\n\n/*Added by Bruce Sherwood Dec 2001*/\n/*These methods add the floor and true division*/\n/*functionality that was made available in Python 2.2*/\nstatic PyObject *scipy_array_floor_divide(PyArrayObject *m1, PyObject *m2) {\n return PyUFunc_BinaryFunction(sn_ops.floor_divide, m1, m2);\n}\nstatic PyObject *scipy_array_true_divide(PyArrayObject *m1, PyObject *m2) {\n return PyUFunc_BinaryFunction(sn_ops.true_divide, m1, m2);\n}\nstatic PyObject *scipy_array_inplace_floor_divide(PyArrayObject *m1, PyObject *m2) {\n return PyUFunc_InplaceBinaryFunction(sn_ops.floor_divide, m1, m2);\n}\nstatic PyObject *scipy_array_inplace_true_divide(PyArrayObject *m1, PyObject *m2) {\n return PyUFunc_InplaceBinaryFunction(sn_ops.true_divide, m1, m2);\n}\n/*End of methods added by Bruce Sherwood*/\n\n/* Array evaluates as \"true\" if any of the elements are non-zero */\nstatic int scipy_array_nonzero(PyArrayObject *mp) {\n char *zero;\n PyArrayObject *self;\n char *data;\n int i, s, elsize;\n\t\n self = PyArray_CONTIGUOUS(mp);\n zero = self->descr->zero;\n\n s = SIZE(self);\n elsize = self->descr->elsize;\n data = self->data;\n for(i=0; idescr->getitem(v->data);\n if (pv == NULL) return NULL;\n if (pv->ob_type->tp_as_number == 0) {\n\tPyErr_SetString(PyExc_TypeError, \"cannot convert to an int, scalar object is not a number.\");\n\tPy_DECREF(pv);\n\treturn NULL;\n }\n if (pv->ob_type->tp_as_number->nb_int == 0) {\n\tPyErr_SetString(PyExc_TypeError, \"don't know how to convert scalar number to int\");\n\tPy_DECREF(pv);\n\treturn NULL;\n }\n\n pv2 = pv->ob_type->tp_as_number->nb_int(pv);\n Py_DECREF(pv);\n return pv2; \n}\n\nstatic PyObject *scipy_array_float(PyArrayObject *v) {\n PyObject *pv, *pv2;\n if (PyArray_SIZE(v) != 1) {\n\tPyErr_SetString(PyExc_TypeError, \"only length-1 arrays can be converted to Python scalars.\");\n\treturn NULL;\n }\n pv = v->descr->getitem(v->data);\n if (pv == NULL) return NULL;\n if (pv->ob_type->tp_as_number == 0) {\n\tPyErr_SetString(PyExc_TypeError, \"cannot convert to an int, scalar object is not a number.\");\n\tPy_DECREF(pv);\n\treturn NULL;\n }\n if (pv->ob_type->tp_as_number->nb_float == 0) {\n\tPyErr_SetString(PyExc_TypeError, \"don't know how to convert scalar number to float\");\n\tPy_DECREF(pv);\n\treturn NULL;\n }\n pv2 = pv->ob_type->tp_as_number->nb_float(pv);\n Py_DECREF(pv);\n return pv2; \n}\n\nstatic PyObject *scipy_array_long(PyArrayObject *v) { \n PyObject *pv, *pv2;\n if (PyArray_SIZE(v) != 1) {\n\tPyErr_SetString(PyExc_TypeError, \"only length-1 arrays can be converted to Python scalars.\");\n\treturn NULL;\n }\n pv = v->descr->getitem(v->data);\n if (pv->ob_type->tp_as_number == 0) {\n\tPyErr_SetString(PyExc_TypeError, \"cannot convert to an int, scalar object is not a number.\");\n\treturn NULL;\n }\n if (pv->ob_type->tp_as_number->nb_long == 0) {\n\tPyErr_SetString(PyExc_TypeError, \"don't know how to convert scalar number to long\");\n\treturn NULL;\n }\n pv2 = pv->ob_type->tp_as_number->nb_long(pv);\n Py_DECREF(pv);\n return pv2; \n}\n\nstatic PyObject *scipy_array_oct(PyArrayObject *v) { \n PyObject *pv, *pv2;\n if (PyArray_SIZE(v) != 1) {\n\tPyErr_SetString(PyExc_TypeError, \"only length-1 arrays can be converted to Python scalars.\");\n\treturn NULL;\n }\n pv = v->descr->getitem(v->data);\n if (pv->ob_type->tp_as_number == 0) {\n\tPyErr_SetString(PyExc_TypeError, \"cannot convert to an int, scalar object is not a number.\");\n\treturn NULL;\n }\n if (pv->ob_type->tp_as_number->nb_oct == 0) {\n\tPyErr_SetString(PyExc_TypeError, \"don't know how to convert scalar number to oct\");\n\treturn NULL;\n }\n pv2 = pv->ob_type->tp_as_number->nb_oct(pv);\n Py_DECREF(pv);\n return pv2; \n}\n\nstatic PyObject *scipy_array_hex(PyArrayObject *v) { \n PyObject *pv, *pv2;\n if (PyArray_SIZE(v) != 1) {\n\tPyErr_SetString(PyExc_TypeError, \"only length-1 arrays can be converted to Python scalars.\");\n\treturn NULL;\n }\n pv = v->descr->getitem(v->data);\n if (pv->ob_type->tp_as_number == 0) {\n\tPyErr_SetString(PyExc_TypeError, \"cannot convert to an int, scalar object is not a number.\");\n\treturn NULL;\n }\n if (pv->ob_type->tp_as_number->nb_hex == 0) {\n\tPyErr_SetString(PyExc_TypeError, \"don't know how to convert scalar number to hex\");\n\treturn NULL;\n }\n pv2 = pv->ob_type->tp_as_number->nb_hex(pv);\n Py_DECREF(pv);\n return pv2; \n}\n\n\n\n/* ---------- */\n\nstatic PyObject *scipy_ufunc_call(PyUFuncObject *self, PyObject *args) {\n int i;\n PyTupleObject *ret;\n PyArrayObject *mps[MAX_ARGS];\n\t\n /* Initialize all array objects to NULL to make cleanup easier if something goes wrong. */\n for(i=0; inargs; i++) mps[i] = NULL;\n\t\n if (scipy_PyUFunc_GenericFunction(self, args, mps) == -1) {\n\tfor(i=0; inargs; i++) if (mps[i] != NULL) Py_DECREF(mps[i]);\n\treturn NULL;\n }\n\t\n for(i=0; inin; i++) Py_DECREF(mps[i]);\n\t\n if (self->nout == 1) { \n\treturn PyArray_Return(mps[self->nin]); \n } else { \n\tret = (PyTupleObject *)PyTuple_New(self->nout);\n\tfor(i=0; inout; i++) {\n\t PyTuple_SET_ITEM(ret, i, PyArray_Return(mps[i+self->nin]));\n\t}\n\treturn (PyObject *)ret;\n }\n}\n", "methods": [ { "name": "scipy_compare_lists", "long_name": "scipy_compare_lists( int * l1 , int * l2 , int n)", "filename": "_scipy_number.c", "nloc": 7, "complexity": 3, "token_count": 51, "parameters": [ "l1", "l2", "n" ], "start_line": 26, "end_line": 32, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 7, "top_nesting_level": 0 }, { "name": "scipy_get_stride", "long_name": "scipy_get_stride( PyArrayObject * mp , int d)", "filename": "_scipy_number.c", "nloc": 3, "complexity": 1, "token_count": 19, "parameters": [ "mp", "d" ], "start_line": 34, "end_line": 36, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 3, "top_nesting_level": 0 }, { "name": "scipy_array_copy", "long_name": "scipy_array_copy( PyArrayObject * m1)", "filename": "_scipy_number.c", "nloc": 6, "complexity": 2, "token_count": 55, "parameters": [ "m1" ], "start_line": 39, "end_line": 46, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 8, "top_nesting_level": 0 }, { "name": "scipy_cancoerce", "long_name": "scipy_cancoerce( char thistype , char neededtype , char scalar)", "filename": "_scipy_number.c", "nloc": 12, "complexity": 8, "token_count": 96, "parameters": [ "thistype", "neededtype", "scalar" ], "start_line": 68, "end_line": 80, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 13, "top_nesting_level": 0 }, { "name": "scipy_select_types", "long_name": "scipy_select_types( PyUFuncObject * self , char * arg_types , ** data , PyUFuncGenericFunction * function , char * scalars)", "filename": "_scipy_number.c", "nloc": 48, "complexity": 22, "token_count": 444, "parameters": [ "self", "arg_types", "data", "function", "scalars" ], "start_line": 82, "end_line": 144, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 63, "top_nesting_level": 0 }, { "name": "scipy_setup_matrices", "long_name": "scipy_setup_matrices( PyUFuncObject * self , PyObject * args , PyUFuncGenericFunction * function , ** data , PyArrayObject ** mps , char * arg_types)", "filename": "_scipy_number.c", "nloc": 67, "complexity": 22, "token_count": 539, "parameters": [ "self", "args", "function", "data", "mps", "arg_types" ], "start_line": 146, "end_line": 224, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 79, "top_nesting_level": 0 }, { "name": "scipy_setup_return", "long_name": "scipy_setup_return( PyUFuncObject * self , int nd , int * dimensions , int steps [ MAX_DIMS ] [ MAX_ARGS ] , PyArrayObject ** mps , char * arg_types)", "filename": "_scipy_number.c", "nloc": 21, "complexity": 7, "token_count": 202, "parameters": [ "self", "nd", "dimensions", "mps", "arg_types" ], "start_line": 226, "end_line": 250, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 25, "top_nesting_level": 0 }, { "name": "scipy_optimize_loop", "long_name": "scipy_optimize_loop( int steps [ MAX_DIMS ] [ MAX_ARGS ] , int * loop_n , int n_loops)", "filename": "_scipy_number.c", "nloc": 10, "complexity": 4, "token_count": 107, "parameters": [ "loop_n", "n_loops" ], "start_line": 252, "end_line": 268, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 17, "top_nesting_level": 0 }, { "name": "scipy_setup_loop", "long_name": "scipy_setup_loop( PyUFuncObject * self , PyObject * args , PyUFuncGenericFunction * function , ** data , int steps [ MAX_DIMS ] [ MAX_ARGS ] , int * loop_n , PyArrayObject ** mps)", "filename": "_scipy_number.c", "nloc": 35, "complexity": 12, "token_count": 377, "parameters": [ "self", "args", "function", "data", "loop_n", "mps" ], "start_line": 271, "end_line": 317, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 47, "top_nesting_level": 0 }, { "name": "scipy_PyUFunc_GenericFunction", "long_name": "scipy_PyUFunc_GenericFunction( PyUFuncObject * self , PyObject * args , PyArrayObject ** mps)", "filename": "_scipy_number.c", "nloc": 34, "complexity": 14, "token_count": 359, "parameters": [ "self", "args", "mps" ], "start_line": 319, "end_line": 372, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 54, "top_nesting_level": 0 }, { "name": "scipy_SetNumericOps", "long_name": "scipy_SetNumericOps( PyObject * dict)", "filename": "_scipy_number.c", "nloc": 25, "complexity": 1, "token_count": 121, "parameters": [ "dict" ], "start_line": 406, "end_line": 430, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 25, "top_nesting_level": 0 }, { "name": "scipy_array_coerce", "long_name": "scipy_array_coerce( PyArrayObject ** pm , PyObject ** pw)", "filename": "_scipy_number.c", "nloc": 14, "complexity": 6, "token_count": 95, "parameters": [ "pm", "pw" ], "start_line": 433, "end_line": 447, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 15, "top_nesting_level": 0 }, { "name": "PyUFunc_BinaryFunction", "long_name": "PyUFunc_BinaryFunction( PyUFuncObject * s , PyArrayObject * mp1 , PyObject * mp2)", "filename": "_scipy_number.c", "nloc": 14, "complexity": 2, "token_count": 133, "parameters": [ "s", "mp1", "mp2" ], "start_line": 449, "end_line": 464, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 16, "top_nesting_level": 0 }, { "name": "PyUFunc_InplaceBinaryFunction", "long_name": "PyUFunc_InplaceBinaryFunction( PyUFuncObject * s , PyArrayObject * mp1 , PyObject * mp2)", "filename": "_scipy_number.c", "nloc": 14, "complexity": 2, "token_count": 135, "parameters": [ "s", "mp1", "mp2" ], "start_line": 468, "end_line": 484, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 17, "top_nesting_level": 0 }, { "name": "PyUFunc_UnaryFunction", "long_name": "PyUFunc_UnaryFunction( PyUFuncObject * s , PyArrayObject * mp1)", "filename": "_scipy_number.c", "nloc": 14, "complexity": 2, "token_count": 106, "parameters": [ "s", "mp1" ], "start_line": 486, "end_line": 502, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 17, "top_nesting_level": 0 }, { "name": "scipy_array_add", "long_name": "scipy_array_add( PyArrayObject * m1 , PyObject * m2)", "filename": "_scipy_number.c", "nloc": 3, "complexity": 1, "token_count": 24, "parameters": [ "m1", "m2" ], "start_line": 506, "end_line": 508, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 3, "top_nesting_level": 0 }, { "name": "scipy_array_subtract", "long_name": "scipy_array_subtract( PyArrayObject * m1 , PyObject * m2)", "filename": "_scipy_number.c", "nloc": 3, "complexity": 1, "token_count": 24, "parameters": [ "m1", "m2" ], "start_line": 509, "end_line": 511, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 3, "top_nesting_level": 0 }, { "name": "scipy_array_multiply", "long_name": "scipy_array_multiply( PyArrayObject * m1 , PyObject * m2)", "filename": "_scipy_number.c", "nloc": 3, "complexity": 1, "token_count": 24, "parameters": [ "m1", "m2" ], "start_line": 512, "end_line": 514, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 3, "top_nesting_level": 0 }, { "name": "scipy_array_divide", "long_name": "scipy_array_divide( PyArrayObject * m1 , PyObject * m2)", "filename": "_scipy_number.c", "nloc": 3, "complexity": 1, "token_count": 24, "parameters": [ "m1", "m2" ], "start_line": 515, "end_line": 517, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 3, "top_nesting_level": 0 }, { "name": "scipy_array_remainder", "long_name": "scipy_array_remainder( PyArrayObject * m1 , PyObject * m2)", "filename": "_scipy_number.c", "nloc": 3, "complexity": 1, "token_count": 24, "parameters": [ "m1", "m2" ], "start_line": 518, "end_line": 520, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 3, "top_nesting_level": 0 }, { "name": "scipy_array_power", "long_name": "scipy_array_power( PyArrayObject * m1 , PyObject * m2)", "filename": "_scipy_number.c", "nloc": 3, "complexity": 1, "token_count": 24, "parameters": [ "m1", "m2" ], "start_line": 521, "end_line": 523, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 3, "top_nesting_level": 0 }, { "name": "scipy_array_negative", "long_name": "scipy_array_negative( PyArrayObject * m1)", "filename": "_scipy_number.c", "nloc": 3, "complexity": 1, "token_count": 18, "parameters": [ "m1" ], "start_line": 524, "end_line": 526, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 3, "top_nesting_level": 0 }, { "name": "scipy_array_absolute", "long_name": "scipy_array_absolute( PyArrayObject * m1)", "filename": "_scipy_number.c", "nloc": 3, "complexity": 1, "token_count": 18, "parameters": [ "m1" ], "start_line": 527, "end_line": 529, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 3, "top_nesting_level": 0 }, { "name": "scipy_array_invert", "long_name": "scipy_array_invert( PyArrayObject * m1)", "filename": "_scipy_number.c", "nloc": 3, "complexity": 1, "token_count": 18, "parameters": [ "m1" ], "start_line": 530, "end_line": 532, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 3, "top_nesting_level": 0 }, { "name": "scipy_array_left_shift", "long_name": "scipy_array_left_shift( PyArrayObject * m1 , PyObject * m2)", "filename": "_scipy_number.c", "nloc": 3, "complexity": 1, "token_count": 24, "parameters": [ "m1", "m2" ], "start_line": 533, "end_line": 535, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 3, "top_nesting_level": 0 }, { "name": "scipy_array_right_shift", "long_name": "scipy_array_right_shift( PyArrayObject * m1 , PyObject * m2)", "filename": "_scipy_number.c", "nloc": 3, "complexity": 1, "token_count": 24, "parameters": [ "m1", "m2" ], "start_line": 536, "end_line": 538, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 3, "top_nesting_level": 0 }, { "name": "scipy_array_bitwise_and", "long_name": "scipy_array_bitwise_and( PyArrayObject * m1 , PyObject * m2)", "filename": "_scipy_number.c", "nloc": 3, "complexity": 1, "token_count": 24, "parameters": [ "m1", "m2" ], "start_line": 539, "end_line": 541, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 3, "top_nesting_level": 0 }, { "name": "scipy_array_bitwise_or", "long_name": "scipy_array_bitwise_or( PyArrayObject * m1 , PyObject * m2)", "filename": "_scipy_number.c", "nloc": 3, "complexity": 1, "token_count": 24, "parameters": [ "m1", "m2" ], "start_line": 542, "end_line": 544, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 3, "top_nesting_level": 0 }, { "name": "scipy_array_bitwise_xor", "long_name": "scipy_array_bitwise_xor( PyArrayObject * m1 , PyObject * m2)", "filename": "_scipy_number.c", "nloc": 3, "complexity": 1, "token_count": 24, "parameters": [ "m1", "m2" ], "start_line": 545, "end_line": 547, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 3, "top_nesting_level": 0 }, { "name": "scipy_array_inplace_add", "long_name": "scipy_array_inplace_add( PyArrayObject * m1 , PyObject * m2)", "filename": "_scipy_number.c", "nloc": 3, "complexity": 1, "token_count": 24, "parameters": [ "m1", "m2" ], "start_line": 552, "end_line": 554, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 3, "top_nesting_level": 0 }, { "name": "scipy_array_inplace_subtract", "long_name": "scipy_array_inplace_subtract( PyArrayObject * m1 , PyObject * m2)", "filename": "_scipy_number.c", "nloc": 3, "complexity": 1, "token_count": 24, "parameters": [ "m1", "m2" ], "start_line": 555, "end_line": 557, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 3, "top_nesting_level": 0 }, { "name": "scipy_array_inplace_multiply", "long_name": "scipy_array_inplace_multiply( PyArrayObject * m1 , PyObject * m2)", "filename": "_scipy_number.c", "nloc": 3, "complexity": 1, "token_count": 24, "parameters": [ "m1", "m2" ], "start_line": 558, "end_line": 560, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 3, "top_nesting_level": 0 }, { "name": "scipy_array_inplace_divide", "long_name": "scipy_array_inplace_divide( PyArrayObject * m1 , PyObject * m2)", "filename": "_scipy_number.c", "nloc": 3, "complexity": 1, "token_count": 24, "parameters": [ "m1", "m2" ], "start_line": 561, "end_line": 563, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 3, "top_nesting_level": 0 }, { "name": "scipy_array_inplace_remainder", "long_name": "scipy_array_inplace_remainder( PyArrayObject * m1 , PyObject * m2)", "filename": "_scipy_number.c", "nloc": 3, "complexity": 1, "token_count": 24, "parameters": [ "m1", "m2" ], "start_line": 564, "end_line": 566, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 3, "top_nesting_level": 0 }, { "name": "scipy_array_inplace_power", "long_name": "scipy_array_inplace_power( PyArrayObject * m1 , PyObject * m2)", "filename": "_scipy_number.c", "nloc": 3, "complexity": 1, "token_count": 24, "parameters": [ "m1", "m2" ], "start_line": 567, "end_line": 569, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 3, "top_nesting_level": 0 }, { "name": "scipy_array_inplace_left_shift", "long_name": "scipy_array_inplace_left_shift( PyArrayObject * m1 , PyObject * m2)", "filename": "_scipy_number.c", "nloc": 3, "complexity": 1, "token_count": 24, "parameters": [ "m1", "m2" ], "start_line": 570, "end_line": 572, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 3, "top_nesting_level": 0 }, { "name": "scipy_array_inplace_right_shift", "long_name": "scipy_array_inplace_right_shift( PyArrayObject * m1 , PyObject * m2)", "filename": "_scipy_number.c", "nloc": 3, "complexity": 1, "token_count": 24, "parameters": [ "m1", "m2" ], "start_line": 573, "end_line": 575, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 3, "top_nesting_level": 0 }, { "name": "scipy_array_inplace_bitwise_and", "long_name": "scipy_array_inplace_bitwise_and( PyArrayObject * m1 , PyObject * m2)", "filename": "_scipy_number.c", "nloc": 3, "complexity": 1, "token_count": 24, "parameters": [ "m1", "m2" ], "start_line": 576, "end_line": 578, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 3, "top_nesting_level": 0 }, { "name": "scipy_array_inplace_bitwise_or", "long_name": "scipy_array_inplace_bitwise_or( PyArrayObject * m1 , PyObject * m2)", "filename": "_scipy_number.c", "nloc": 3, "complexity": 1, "token_count": 24, "parameters": [ "m1", "m2" ], "start_line": 579, "end_line": 581, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 3, "top_nesting_level": 0 }, { "name": "scipy_array_inplace_bitwise_xor", "long_name": "scipy_array_inplace_bitwise_xor( PyArrayObject * m1 , PyObject * m2)", "filename": "_scipy_number.c", "nloc": 3, "complexity": 1, "token_count": 24, "parameters": [ "m1", "m2" ], "start_line": 582, "end_line": 584, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 3, "top_nesting_level": 0 }, { "name": "scipy_array_floor_divide", "long_name": "scipy_array_floor_divide( PyArrayObject * m1 , PyObject * m2)", "filename": "_scipy_number.c", "nloc": 3, "complexity": 1, "token_count": 24, "parameters": [ "m1", "m2" ], "start_line": 589, "end_line": 591, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 3, "top_nesting_level": 0 }, { "name": "scipy_array_true_divide", "long_name": "scipy_array_true_divide( PyArrayObject * m1 , PyObject * m2)", "filename": "_scipy_number.c", "nloc": 3, "complexity": 1, "token_count": 24, "parameters": [ "m1", "m2" ], "start_line": 592, "end_line": 594, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 3, "top_nesting_level": 0 }, { "name": "scipy_array_inplace_floor_divide", "long_name": "scipy_array_inplace_floor_divide( PyArrayObject * m1 , PyObject * m2)", "filename": "_scipy_number.c", "nloc": 3, "complexity": 1, "token_count": 24, "parameters": [ "m1", "m2" ], "start_line": 595, "end_line": 597, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 3, "top_nesting_level": 0 }, { "name": "scipy_array_inplace_true_divide", "long_name": "scipy_array_inplace_true_divide( PyArrayObject * m1 , PyObject * m2)", "filename": "_scipy_number.c", "nloc": 3, "complexity": 1, "token_count": 24, "parameters": [ "m1", "m2" ], "start_line": 598, "end_line": 600, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 3, "top_nesting_level": 0 }, { "name": "scipy_array_nonzero", "long_name": "scipy_array_nonzero( PyArrayObject * mp)", "filename": "_scipy_number.c", "nloc": 16, "complexity": 3, "token_count": 107, "parameters": [ "mp" ], "start_line": 604, "end_line": 623, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 20, "top_nesting_level": 0 }, { "name": "scipy_array_divmod", "long_name": "scipy_array_divmod( PyArrayObject * op1 , PyObject * op2)", "filename": "_scipy_number.c", "nloc": 14, "complexity": 3, "token_count": 89, "parameters": [ "op1", "op2" ], "start_line": 625, "end_line": 639, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 15, "top_nesting_level": 0 }, { "name": "scipy_array_int", "long_name": "scipy_array_int( PyArrayObject * v)", "filename": "_scipy_number.c", "nloc": 22, "complexity": 5, "token_count": 135, "parameters": [ "v" ], "start_line": 642, "end_line": 664, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 23, "top_nesting_level": 0 }, { "name": "scipy_array_float", "long_name": "scipy_array_float( PyArrayObject * v)", "filename": "_scipy_number.c", "nloc": 22, "complexity": 5, "token_count": 135, "parameters": [ "v" ], "start_line": 666, "end_line": 687, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 22, "top_nesting_level": 0 }, { "name": "scipy_array_long", "long_name": "scipy_array_long( PyArrayObject * v)", "filename": "_scipy_number.c", "nloc": 19, "complexity": 4, "token_count": 116, "parameters": [ "v" ], "start_line": 689, "end_line": 707, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 19, "top_nesting_level": 0 }, { "name": "scipy_array_oct", "long_name": "scipy_array_oct( PyArrayObject * v)", "filename": "_scipy_number.c", "nloc": 19, "complexity": 4, "token_count": 116, "parameters": [ "v" ], "start_line": 709, "end_line": 727, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 19, "top_nesting_level": 0 }, { "name": "scipy_array_hex", "long_name": "scipy_array_hex( PyArrayObject * v)", "filename": "_scipy_number.c", "nloc": 19, "complexity": 4, "token_count": 116, "parameters": [ "v" ], "start_line": 729, "end_line": 747, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 19, "top_nesting_level": 0 }, { "name": "scipy_ufunc_call", "long_name": "scipy_ufunc_call( PyUFuncObject * self , PyObject * args)", "filename": "_scipy_number.c", "nloc": 24, "complexity": 8, "token_count": 206, "parameters": [ "self", "args" ], "start_line": 753, "end_line": 781, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 29, "top_nesting_level": 0 } ], "methods_before": [ { "name": "scipy_compare_lists", "long_name": "scipy_compare_lists( int * l1 , int * l2 , int n)", "filename": "_scipy_number.c", "nloc": 7, "complexity": 3, "token_count": 51, "parameters": [ "l1", "l2", "n" ], "start_line": 26, "end_line": 32, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 7, "top_nesting_level": 0 }, { "name": "scipy_get_stride", "long_name": "scipy_get_stride( PyArrayObject * mp , int d)", "filename": "_scipy_number.c", "nloc": 3, "complexity": 1, "token_count": 19, "parameters": [ "mp", "d" ], "start_line": 34, "end_line": 36, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 3, "top_nesting_level": 0 }, { "name": "scipy_array_copy", "long_name": "scipy_array_copy( PyArrayObject * m1)", "filename": "_scipy_number.c", "nloc": 6, "complexity": 2, "token_count": 55, "parameters": [ "m1" ], "start_line": 39, "end_line": 46, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 8, "top_nesting_level": 0 }, { "name": "scipy_cancoerce", "long_name": "scipy_cancoerce( char thistype , char neededtype , char scalar)", "filename": "_scipy_number.c", "nloc": 12, "complexity": 8, "token_count": 96, "parameters": [ "thistype", "neededtype", "scalar" ], "start_line": 68, "end_line": 80, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 13, "top_nesting_level": 0 }, { "name": "scipy_select_types", "long_name": "scipy_select_types( PyUFuncObject * self , char * arg_types , ** data , PyUFuncGenericFunction * function , char * scalars)", "filename": "_scipy_number.c", "nloc": 48, "complexity": 22, "token_count": 444, "parameters": [ "self", "arg_types", "data", "function", "scalars" ], "start_line": 82, "end_line": 144, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 63, "top_nesting_level": 0 }, { "name": "scipy_setup_matrices", "long_name": "scipy_setup_matrices( PyUFuncObject * self , PyObject * args , PyUFuncGenericFunction * function , ** data , PyArrayObject ** mps , char * arg_types)", "filename": "_scipy_number.c", "nloc": 67, "complexity": 22, "token_count": 539, "parameters": [ "self", "args", "function", "data", "mps", "arg_types" ], "start_line": 146, "end_line": 224, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 79, "top_nesting_level": 0 }, { "name": "scipy_setup_return", "long_name": "scipy_setup_return( PyUFuncObject * self , int nd , int * dimensions , int steps [ MAX_DIMS ] [ MAX_ARGS ] , PyArrayObject ** mps , char * arg_types)", "filename": "_scipy_number.c", "nloc": 21, "complexity": 7, "token_count": 202, "parameters": [ "self", "nd", "dimensions", "mps", "arg_types" ], "start_line": 226, "end_line": 250, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 25, "top_nesting_level": 0 }, { "name": "scipy_optimize_loop", "long_name": "scipy_optimize_loop( int steps [ MAX_DIMS ] [ MAX_ARGS ] , int * loop_n , int n_loops)", "filename": "_scipy_number.c", "nloc": 10, "complexity": 4, "token_count": 107, "parameters": [ "loop_n", "n_loops" ], "start_line": 252, "end_line": 268, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 17, "top_nesting_level": 0 }, { "name": "scipy_setup_loop", "long_name": "scipy_setup_loop( PyUFuncObject * self , PyObject * args , PyUFuncGenericFunction * function , ** data , int steps [ MAX_DIMS ] [ MAX_ARGS ] , int * loop_n , PyArrayObject ** mps)", "filename": "_scipy_number.c", "nloc": 35, "complexity": 12, "token_count": 377, "parameters": [ "self", "args", "function", "data", "loop_n", "mps" ], "start_line": 271, "end_line": 317, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 47, "top_nesting_level": 0 }, { "name": "scipy_PyUFunc_GenericFunction", "long_name": "scipy_PyUFunc_GenericFunction( PyUFuncObject * self , PyObject * args , PyArrayObject ** mps)", "filename": "_scipy_number.c", "nloc": 34, "complexity": 14, "token_count": 359, "parameters": [ "self", "args", "mps" ], "start_line": 319, "end_line": 372, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 54, "top_nesting_level": 0 }, { "name": "scipy_SetNumericOps", "long_name": "scipy_SetNumericOps( PyObject * dict)", "filename": "_scipy_number.c", "nloc": 25, "complexity": 1, "token_count": 121, "parameters": [ "dict" ], "start_line": 406, "end_line": 430, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 25, "top_nesting_level": 0 }, { "name": "scipy_array_coerce", "long_name": "scipy_array_coerce( PyArrayObject ** pm , PyObject ** pw)", "filename": "_scipy_number.c", "nloc": 14, "complexity": 6, "token_count": 95, "parameters": [ "pm", "pw" ], "start_line": 433, "end_line": 447, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 15, "top_nesting_level": 0 }, { "name": "PyUFunc_BinaryFunction", "long_name": "PyUFunc_BinaryFunction( PyUFuncObject * s , PyArrayObject * mp1 , PyObject * mp2)", "filename": "_scipy_number.c", "nloc": 14, "complexity": 2, "token_count": 133, "parameters": [ "s", "mp1", "mp2" ], "start_line": 449, "end_line": 464, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 16, "top_nesting_level": 0 }, { "name": "PyUFunc_InplaceBinaryFunction", "long_name": "PyUFunc_InplaceBinaryFunction( PyUFuncObject * s , PyArrayObject * mp1 , PyObject * mp2)", "filename": "_scipy_number.c", "nloc": 14, "complexity": 2, "token_count": 135, "parameters": [ "s", "mp1", "mp2" ], "start_line": 468, "end_line": 484, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 17, "top_nesting_level": 0 }, { "name": "PyUFunc_UnaryFunction", "long_name": "PyUFunc_UnaryFunction( PyUFuncObject * s , PyArrayObject * mp1)", "filename": "_scipy_number.c", "nloc": 14, "complexity": 2, "token_count": 106, "parameters": [ "s", "mp1" ], "start_line": 486, "end_line": 502, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 17, "top_nesting_level": 0 }, { "name": "scipy_array_add", "long_name": "scipy_array_add( PyArrayObject * m1 , PyObject * m2)", "filename": "_scipy_number.c", "nloc": 3, "complexity": 1, "token_count": 24, "parameters": [ "m1", "m2" ], "start_line": 506, "end_line": 508, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 3, "top_nesting_level": 0 }, { "name": "scipy_array_subtract", "long_name": "scipy_array_subtract( PyArrayObject * m1 , PyObject * m2)", "filename": "_scipy_number.c", "nloc": 3, "complexity": 1, "token_count": 24, "parameters": [ "m1", "m2" ], "start_line": 509, "end_line": 511, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 3, "top_nesting_level": 0 }, { "name": "scipy_array_multiply", "long_name": "scipy_array_multiply( PyArrayObject * m1 , PyObject * m2)", "filename": "_scipy_number.c", "nloc": 3, "complexity": 1, "token_count": 24, "parameters": [ "m1", "m2" ], "start_line": 512, "end_line": 514, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 3, "top_nesting_level": 0 }, { "name": "scipy_array_divide", "long_name": "scipy_array_divide( PyArrayObject * m1 , PyObject * m2)", "filename": "_scipy_number.c", "nloc": 3, "complexity": 1, "token_count": 24, "parameters": [ "m1", "m2" ], "start_line": 515, "end_line": 517, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 3, "top_nesting_level": 0 }, { "name": "scipy_array_remainder", "long_name": "scipy_array_remainder( PyArrayObject * m1 , PyObject * m2)", "filename": "_scipy_number.c", "nloc": 3, "complexity": 1, "token_count": 24, "parameters": [ "m1", "m2" ], "start_line": 518, "end_line": 520, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 3, "top_nesting_level": 0 }, { "name": "scipy_array_power", "long_name": "scipy_array_power( PyArrayObject * m1 , PyObject * m2)", "filename": "_scipy_number.c", "nloc": 3, "complexity": 1, "token_count": 24, "parameters": [ "m1", "m2" ], "start_line": 521, "end_line": 523, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 3, "top_nesting_level": 0 }, { "name": "scipy_array_negative", "long_name": "scipy_array_negative( PyArrayObject * m1)", "filename": "_scipy_number.c", "nloc": 3, "complexity": 1, "token_count": 18, "parameters": [ "m1" ], "start_line": 524, "end_line": 526, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 3, "top_nesting_level": 0 }, { "name": "scipy_array_absolute", "long_name": "scipy_array_absolute( PyArrayObject * m1)", "filename": "_scipy_number.c", "nloc": 3, "complexity": 1, "token_count": 18, "parameters": [ "m1" ], "start_line": 527, "end_line": 529, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 3, "top_nesting_level": 0 }, { "name": "scipy_array_invert", "long_name": "scipy_array_invert( PyArrayObject * m1)", "filename": "_scipy_number.c", "nloc": 3, "complexity": 1, "token_count": 18, "parameters": [ "m1" ], "start_line": 530, "end_line": 532, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 3, "top_nesting_level": 0 }, { "name": "scipy_array_left_shift", "long_name": "scipy_array_left_shift( PyArrayObject * m1 , PyObject * m2)", "filename": "_scipy_number.c", "nloc": 3, "complexity": 1, "token_count": 24, "parameters": [ "m1", "m2" ], "start_line": 533, "end_line": 535, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 3, "top_nesting_level": 0 }, { "name": "scipy_array_right_shift", "long_name": "scipy_array_right_shift( PyArrayObject * m1 , PyObject * m2)", "filename": "_scipy_number.c", "nloc": 3, "complexity": 1, "token_count": 24, "parameters": [ "m1", "m2" ], "start_line": 536, "end_line": 538, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 3, "top_nesting_level": 0 }, { "name": "scipy_array_bitwise_and", "long_name": "scipy_array_bitwise_and( PyArrayObject * m1 , PyObject * m2)", "filename": "_scipy_number.c", "nloc": 3, "complexity": 1, "token_count": 24, "parameters": [ "m1", "m2" ], "start_line": 539, "end_line": 541, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 3, "top_nesting_level": 0 }, { "name": "scipy_array_bitwise_or", "long_name": "scipy_array_bitwise_or( PyArrayObject * m1 , PyObject * m2)", "filename": "_scipy_number.c", "nloc": 3, "complexity": 1, "token_count": 24, "parameters": [ "m1", "m2" ], "start_line": 542, "end_line": 544, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 3, "top_nesting_level": 0 }, { "name": "scipy_array_bitwise_xor", "long_name": "scipy_array_bitwise_xor( PyArrayObject * m1 , PyObject * m2)", "filename": "_scipy_number.c", "nloc": 3, "complexity": 1, "token_count": 24, "parameters": [ "m1", "m2" ], "start_line": 545, "end_line": 547, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 3, "top_nesting_level": 0 }, { "name": "scipy_array_inplace_add", "long_name": "scipy_array_inplace_add( PyArrayObject * m1 , PyObject * m2)", "filename": "_scipy_number.c", "nloc": 3, "complexity": 1, "token_count": 24, "parameters": [ "m1", "m2" ], "start_line": 552, "end_line": 554, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 3, "top_nesting_level": 0 }, { "name": "scipy_array_inplace_subtract", "long_name": "scipy_array_inplace_subtract( PyArrayObject * m1 , PyObject * m2)", "filename": "_scipy_number.c", "nloc": 3, "complexity": 1, "token_count": 24, "parameters": [ "m1", "m2" ], "start_line": 555, "end_line": 557, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 3, "top_nesting_level": 0 }, { "name": "scipy_array_inplace_multiply", "long_name": "scipy_array_inplace_multiply( PyArrayObject * m1 , PyObject * m2)", "filename": "_scipy_number.c", "nloc": 3, "complexity": 1, "token_count": 24, "parameters": [ "m1", "m2" ], "start_line": 558, "end_line": 560, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 3, "top_nesting_level": 0 }, { "name": "scipy_array_inplace_divide", "long_name": "scipy_array_inplace_divide( PyArrayObject * m1 , PyObject * m2)", "filename": "_scipy_number.c", "nloc": 3, "complexity": 1, "token_count": 24, "parameters": [ "m1", "m2" ], "start_line": 561, "end_line": 563, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 3, "top_nesting_level": 0 }, { "name": "scipy_array_inplace_remainder", "long_name": "scipy_array_inplace_remainder( PyArrayObject * m1 , PyObject * m2)", "filename": "_scipy_number.c", "nloc": 3, "complexity": 1, "token_count": 24, "parameters": [ "m1", "m2" ], "start_line": 564, "end_line": 566, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 3, "top_nesting_level": 0 }, { "name": "scipy_array_inplace_power", "long_name": "scipy_array_inplace_power( PyArrayObject * m1 , PyObject * m2)", "filename": "_scipy_number.c", "nloc": 3, "complexity": 1, "token_count": 24, "parameters": [ "m1", "m2" ], "start_line": 567, "end_line": 569, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 3, "top_nesting_level": 0 }, { "name": "scipy_array_inplace_left_shift", "long_name": "scipy_array_inplace_left_shift( PyArrayObject * m1 , PyObject * m2)", "filename": "_scipy_number.c", "nloc": 3, "complexity": 1, "token_count": 24, "parameters": [ "m1", "m2" ], "start_line": 570, "end_line": 572, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 3, "top_nesting_level": 0 }, { "name": "scipy_array_inplace_right_shift", "long_name": "scipy_array_inplace_right_shift( PyArrayObject * m1 , PyObject * m2)", "filename": "_scipy_number.c", "nloc": 3, "complexity": 1, "token_count": 24, "parameters": [ "m1", "m2" ], "start_line": 573, "end_line": 575, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 3, "top_nesting_level": 0 }, { "name": "scipy_array_inplace_bitwise_and", "long_name": "scipy_array_inplace_bitwise_and( PyArrayObject * m1 , PyObject * m2)", "filename": "_scipy_number.c", "nloc": 3, "complexity": 1, "token_count": 24, "parameters": [ "m1", "m2" ], "start_line": 576, "end_line": 578, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 3, "top_nesting_level": 0 }, { "name": "scipy_array_inplace_bitwise_or", "long_name": "scipy_array_inplace_bitwise_or( PyArrayObject * m1 , PyObject * m2)", "filename": "_scipy_number.c", "nloc": 3, "complexity": 1, "token_count": 24, "parameters": [ "m1", "m2" ], "start_line": 579, "end_line": 581, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 3, "top_nesting_level": 0 }, { "name": "scipy_array_inplace_bitwise_xor", "long_name": "scipy_array_inplace_bitwise_xor( PyArrayObject * m1 , PyObject * m2)", "filename": "_scipy_number.c", "nloc": 3, "complexity": 1, "token_count": 24, "parameters": [ "m1", "m2" ], "start_line": 582, "end_line": 584, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 3, "top_nesting_level": 0 }, { "name": "scipy_array_floor_divide", "long_name": "scipy_array_floor_divide( PyArrayObject * m1 , PyObject * m2)", "filename": "_scipy_number.c", "nloc": 3, "complexity": 1, "token_count": 24, "parameters": [ "m1", "m2" ], "start_line": 589, "end_line": 591, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 3, "top_nesting_level": 0 }, { "name": "scipy_array_true_divide", "long_name": "scipy_array_true_divide( PyArrayObject * m1 , PyObject * m2)", "filename": "_scipy_number.c", "nloc": 3, "complexity": 1, "token_count": 24, "parameters": [ "m1", "m2" ], "start_line": 592, "end_line": 594, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 3, "top_nesting_level": 0 }, { "name": "scipy_array_inplace_floor_divide", "long_name": "scipy_array_inplace_floor_divide( PyArrayObject * m1 , PyObject * m2)", "filename": "_scipy_number.c", "nloc": 3, "complexity": 1, "token_count": 24, "parameters": [ "m1", "m2" ], "start_line": 595, "end_line": 597, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 3, "top_nesting_level": 0 }, { "name": "scipy_array_inplace_true_divide", "long_name": "scipy_array_inplace_true_divide( PyArrayObject * m1 , PyObject * m2)", "filename": "_scipy_number.c", "nloc": 3, "complexity": 1, "token_count": 24, "parameters": [ "m1", "m2" ], "start_line": 598, "end_line": 600, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 3, "top_nesting_level": 0 }, { "name": "scipy_array_nonzero", "long_name": "scipy_array_nonzero( PyArrayObject * mp)", "filename": "_scipy_number.c", "nloc": 16, "complexity": 3, "token_count": 107, "parameters": [ "mp" ], "start_line": 604, "end_line": 623, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 20, "top_nesting_level": 0 }, { "name": "scipy_array_divmod", "long_name": "scipy_array_divmod( PyArrayObject * op1 , PyObject * op2)", "filename": "_scipy_number.c", "nloc": 14, "complexity": 3, "token_count": 89, "parameters": [ "op1", "op2" ], "start_line": 625, "end_line": 639, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 15, "top_nesting_level": 0 }, { "name": "scipy_array_int", "long_name": "scipy_array_int( PyArrayObject * v)", "filename": "_scipy_number.c", "nloc": 22, "complexity": 5, "token_count": 135, "parameters": [ "v" ], "start_line": 642, "end_line": 664, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 23, "top_nesting_level": 0 }, { "name": "scipy_array_float", "long_name": "scipy_array_float( PyArrayObject * v)", "filename": "_scipy_number.c", "nloc": 22, "complexity": 5, "token_count": 135, "parameters": [ "v" ], "start_line": 666, "end_line": 687, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 22, "top_nesting_level": 0 }, { "name": "scipy_array_long", "long_name": "scipy_array_long( PyArrayObject * v)", "filename": "_scipy_number.c", "nloc": 19, "complexity": 4, "token_count": 116, "parameters": [ "v" ], "start_line": 689, "end_line": 707, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 19, "top_nesting_level": 0 }, { "name": "scipy_array_oct", "long_name": "scipy_array_oct( PyArrayObject * v)", "filename": "_scipy_number.c", "nloc": 19, "complexity": 4, "token_count": 116, "parameters": [ "v" ], "start_line": 709, "end_line": 727, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 19, "top_nesting_level": 0 }, { "name": "scipy_array_hex", "long_name": "scipy_array_hex( PyArrayObject * v)", "filename": "_scipy_number.c", "nloc": 19, "complexity": 4, "token_count": 116, "parameters": [ "v" ], "start_line": 729, "end_line": 747, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 19, "top_nesting_level": 0 }, { "name": "scipy_ufunc_call", "long_name": "scipy_ufunc_call( PyUFuncObject * self , PyObject * args)", "filename": "_scipy_number.c", "nloc": 20, "complexity": 8, "token_count": 202, "parameters": [ "self", "args" ], "start_line": 753, "end_line": 777, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 25, "top_nesting_level": 0 } ], "changed_methods": [ { "name": "scipy_ufunc_call", "long_name": "scipy_ufunc_call( PyUFuncObject * self , PyObject * args)", "filename": "_scipy_number.c", "nloc": 24, "complexity": 8, "token_count": 206, "parameters": [ "self", "args" ], "start_line": 753, "end_line": 781, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 29, "top_nesting_level": 0 } ], "nloc": 591, "complexity": 173, "token_count": 4761, "diff_parsed": { "added": [ "\t for(i=0; inargs; i++) {", "\t\t if (mps[i] != NULL) {", "\t\t\t Py_DECREF(mps[i]);", "\t\t }", "\t }" ], "deleted": [ "\tfor(i=0; inargs; i++) if (mps[i] != NULL) Py_DECREF(mps[i]);" ] } }, { "old_path": "scipy_base/fastumath_unsigned.inc", "new_path": "scipy_base/fastumath_unsigned.inc", "filename": "fastumath_unsigned.inc", "extension": "inc", "change_type": "MODIFY", "diff": "@@ -1799,6 +1799,8 @@ static void DOUBLE_logical_and(char **args, int *dimensions, int *steps, void *f\n \t*((double *)op)=(double)(*((double *)i1) && *((double *)i2));\n }\n }\n+\n+#if 0\n static void CFLOAT_logical_and(char **args, int *dimensions, int *steps, void *func) {\n int i, is1=steps[0],is2=steps[1],os=steps[2], n=dimensions[0];\n char *i1=args[0], *i2=args[1], *op=args[2];\n@@ -1813,6 +1815,8 @@ static void CDOUBLE_logical_and(char **args, int *dimensions, int *steps, void *\n \t*((double *)op)=(double)(*((double *)i1) && *((double *)i2));\n }\n }\n+#endif\n+\n static void UBYTE_logical_or(char **args, int *dimensions, int *steps, void *func) {\n int i, is1=steps[0],is2=steps[1],os=steps[2], n=dimensions[0];\n char *i1=args[0], *i2=args[1], *op=args[2];\n@@ -1876,6 +1880,8 @@ static void DOUBLE_logical_or(char **args, int *dimensions, int *steps, void *fu\n \t*((double *)op)=(double)(*((double *)i1) || *((double *)i2));\n }\n }\n+\n+#if 0\n static void CFLOAT_logical_or(char **args, int *dimensions, int *steps, void *func) {\n int i, is1=steps[0],is2=steps[1],os=steps[2], n=dimensions[0];\n char *i1=args[0], *i2=args[1], *op=args[2];\n@@ -1890,6 +1896,8 @@ static void CDOUBLE_logical_or(char **args, int *dimensions, int *steps, void *f\n \t*((double *)op)=(double)(*((double *)i1) || *((double *)i2));\n }\n }\n+#endif\n+\n static void UBYTE_logical_xor(char **args, int *dimensions, int *steps, void *func) {\n int i, is1=steps[0],is2=steps[1],os=steps[2], n=dimensions[0];\n char *i1=args[0], *i2=args[1], *op=args[2];\n@@ -1953,6 +1961,8 @@ static void DOUBLE_logical_xor(char **args, int *dimensions, int *steps, void *f\n \t*((double*)op)=(double)(*((double *)i1) || *((double *)i2)) && !(*((double *)i1) && *((double *)i2));\n }\n }\n+\n+#if 0\n static void CFLOAT_logical_xor(char **args, int *dimensions, int *steps, void *func) {\n int i, is1=steps[0],is2=steps[1],os=steps[2], n=dimensions[0];\n char *i1=args[0], *i2=args[1], *op=args[2];\n@@ -1967,6 +1977,8 @@ static void CDOUBLE_logical_xor(char **args, int *dimensions, int *steps, void *\n \t*((double*)op)=(double)(*((double *)i1) || *((double *)i2)) && !(*((double *)i1) && *((double *)i2));\n }\n }\n+#endif\n+\n static void UBYTE_logical_not(char **args, int *dimensions, int *steps, void *func) \n {int i; char *i1=args[0], *op=args[1]; for(i=0; i<*dimensions; i++, i1+=steps[0], op+=steps[1]) {*((unsigned char *)op)=!*((unsigned char *)i1);}}\n static void SBYTE_logical_not(char **args, int *dimensions, int *steps, void *func) \n@@ -1985,10 +1997,14 @@ static void FLOAT_logical_not(char **args, int *dimensions, int *steps, void *fu\n {int i; char *i1=args[0], *op=args[1]; for(i=0; i<*dimensions; i++, i1+=steps[0], op+=steps[1]) {*((unsigned char*)op)=(!*((float *)i1));}}\n static void DOUBLE_logical_not(char **args, int *dimensions, int *steps, void *func) \n {int i; char *i1=args[0], *op=args[1]; for(i=0; i<*dimensions; i++, i1+=steps[0], op+=steps[1]) {*((unsigned char *)op)=!*((double *)i1);}}\n+\n+#if 0\n static void CFLOAT_logical_not(char **args, int *dimensions, int *steps, void *func) \n {int i; char *i1=args[0], *op=args[1]; for(i=0; i<*dimensions; i++, i1+=steps[0], op+=steps[1]) {*((unsigned char*)op)=(!*((float *)i1));}}\n static void CDOUBLE_logical_not(char **args, int *dimensions, int *steps, void *func) \n {int i; char *i1=args[0], *op=args[1]; for(i=0; i<*dimensions; i++, i1+=steps[0], op+=steps[1]) {*((unsigned char *)op)=!*((double *)i1);}}\n+#endif\n+\n static void UBYTE_maximum(char **args, int *dimensions, int *steps, void *func) {\n int i, is1=steps[0],is2=steps[1],os=steps[2], n=dimensions[0];\n char *i1=args[0], *i2=args[1], *op=args[2];\n", "added_lines": 16, "deleted_lines": 0, "source_code": "/* -*- c -*- */\n/* Fast umath module whose functions do not check for range and domain errors.\n\n Replacement for umath + additions for isnan, isfinite, and isinf\n Also allows comparison operations on complex numbers (just compares the \n real part) and logical operations.\n\n All logical operations return UBYTE arrays.\n\n This version supports unsigned types. \n */\n\n#ifndef CHAR_BIT\n#define CHAR_BIT 8\n#endif\n\n#ifndef LONG_BIT\n#define LONG_BIT (CHAR_BIT * sizeof(long))\n#endif\n\n#ifndef INT_BIT\n#define INT_BIT (CHAR_BIT * sizeof(int))\n#endif\n\n#ifndef SHORT_BIT\n#define SHORT_BIT (CHAR_BIT * sizeof(short))\n#endif\n\n#ifndef UINT_BIT\n#define UINT_BIT (CHAR_BIT * sizeof(unsigned int))\n#endif\n\n#ifndef USHORT_BIT\n#define USHORT_BIT (CHAR_BIT * sizeof(unsigned short))\n#endif\n\n/* A whole slew of basic math functions are provided 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\n#ifndef M_PI\n#define M_PI 3.1415926535897931\n#endif\n\n#define ABS(x) ((x) < 0 ? -(x) : (x))\n\n/* isnan and isinf and isfinite functions */\nstatic void FLOAT_isnan(char **args, int *dimensions, int *steps, void *func) {\n int i, is1=steps[0], os=steps[1], n=dimensions[0];\n char *i1=args[0], *op=args[1];\n for (i=0; i < n; i++, i1+=is1, op+=os) {\n\t*((unsigned char *)op) = (unsigned char) ABS(isnan((double)(*((float *)i1))));\n }\n}\n\nstatic void DOUBLE_isnan(char **args, int *dimensions, int *steps, void *func) {\n int i, is1=steps[0], os=steps[1], n=dimensions[0];\n char *i1=args[0], *op=args[1];\n for (i=0; i < n; i++, i1+=is1, op+=os) {\n\t*((unsigned char *)op) = (unsigned char) ABS(isnan((double)(*((double *)i1))));\n }\n}\n\nstatic void CFLOAT_isnan(char **args, int *dimensions, int *steps, void *func) {\n int i, is1=steps[0], os=steps[1], n=dimensions[0];\n char *i1=args[0], *op=args[1];\n for (i=0; i < n; i++, i1+=is1, op+=os) {\n\t*((unsigned char *)op) = (unsigned char) isnan((double)((float *)i1)[0]) || isnan((double)((float *)i1)[1]);\n }\n}\n\nstatic void CDOUBLE_isnan(char **args, int *dimensions, int *steps, void *func) {\n int i, is1=steps[0], os=steps[1], n=dimensions[0];\n char *i1=args[0], *op=args[1];\n for (i=0; i < n; i++, i1+=is1, op+=os) {\n\t*((unsigned char *)op) = (unsigned char) isnan((double)((double *)i1)[0]) || isnan((double)((double *)i1)[1]);\n }\n}\n\n\nstatic void FLOAT_isinf(char **args, int *dimensions, int *steps, void *func) {\n int i, is1=steps[0], os=steps[1], n=dimensions[0];\n char *i1=args[0], *op=args[1];\n for (i=0; i < n; i++, i1+=is1, op+=os) {\n\t*((unsigned char *)op) = (unsigned char) !(isfinite((double)(*((float *)i1))) || isnan((double)(*((float *)i1))));\n }\n}\n\nstatic void DOUBLE_isinf(char **args, int *dimensions, int *steps, void *func) {\n int i, is1=steps[0], os=steps[1], n=dimensions[0];\n char *i1=args[0], *op=args[1];\n for (i=0; i < n; i++, i1+=is1, op+=os) {\n\t*((unsigned char *)op)= (unsigned char) !(isfinite((double)(*((double *)i1))) || isnan((double)(*((double *)i1))));\n }\n}\n\nstatic void CFLOAT_isinf(char **args, int *dimensions, int *steps, void *func) {\n int i, is1=steps[0], os=steps[1], n=dimensions[0];\n char *i1=args[0], *op=args[1];\n for (i=0; i < n; i++, i1+=is1, op+=os) {\n\t*((unsigned char *)op)= (unsigned char) !((isfinite((double)(((float *)i1)[0])) && isfinite((double)(((float *)i1)[1]))) || isnan((double)(((float *)i1)[0])) || isnan((double)(((float *)i1)[1])));\n }\n}\n\nstatic void CDOUBLE_isinf(char **args, int *dimensions, int *steps, void *func) {\n int i, is1=steps[0], os=steps[1], n=dimensions[0];\n char *i1=args[0], *op=args[1];\n for (i=0; i < n; i++, i1+=is1, op+=os) {\n\t*((unsigned char *)op)= (unsigned char) !((isfinite((double)(((double *)i1)[0])) && isfinite((double)(((double *)i1)[1]))) || isnan((double)(((double *)i1)[0])) || isnan((double)(((double *)i1)[1])));\n }\n}\n\n\nstatic void FLOAT_isfinite(char **args, int *dimensions, int *steps, void *func) {\n int i, is1=steps[0], os=steps[1], n=dimensions[0];\n char *i1=args[0], *op=args[1];\n for (i=0; i < n; i++, i1+=is1, op+=os) {\n\t*((unsigned char *)op) = (unsigned char) isfinite((double)(*((float *)i1)));\n }\n}\n\nstatic void DOUBLE_isfinite(char **args, int *dimensions, int *steps, void *func) {\n int i, is1=steps[0], os=steps[1], n=dimensions[0];\n char *i1=args[0], *op=args[1];\n for (i=0; i < n; i++, i1+=is1, op+=os) {\n\t*((unsigned char *)op) = (unsigned char) isfinite((double)(*((double *)i1)));\n }\n}\n\nstatic void CFLOAT_isfinite(char **args, int *dimensions, int *steps, void *func) {\n int i, is1=steps[0], os=steps[1], n=dimensions[0];\n char *i1=args[0], *op=args[1];\n for (i=0; i < n; i++, i1+=is1, op+=os) {\n\t*((unsigned char *)op) = (unsigned char) isfinite((double)((float *)i1)[0]) && isfinite((double)((float *)i1)[1]);\n }\n}\n\nstatic void CDOUBLE_isfinite(char **args, int *dimensions, int *steps, void *func) {\n int i, is1=steps[0], os=steps[1], n=dimensions[0];\n char *i1=args[0], *op=args[1];\n for (i=0; i < n; i++, i1+=is1, op+=os) {\n\t*((unsigned char *)op) = (unsigned char) isfinite((double)((double *)i1)[0]) && isfinite((double)((double *)i1)[1]);\n }\n}\n\nstatic PyUFuncGenericFunction isnan_functions[] = {FLOAT_isnan, DOUBLE_isnan, CFLOAT_isnan, CDOUBLE_isnan, NULL};\nstatic PyUFuncGenericFunction isinf_functions[] = {FLOAT_isinf, DOUBLE_isinf, CFLOAT_isinf, CDOUBLE_isinf, NULL};\nstatic PyUFuncGenericFunction isfinite_functions[] = {FLOAT_isfinite, DOUBLE_isfinite, CFLOAT_isfinite, CDOUBLE_isfinite, NULL};\n\nstatic char isinf_signatures[] = { PyArray_FLOAT, PyArray_UBYTE, PyArray_DOUBLE, PyArray_UBYTE, PyArray_CFLOAT, PyArray_UBYTE, PyArray_CDOUBLE, PyArray_UBYTE, };\n\nstatic void * isnan_data[] = {(void *)NULL, (void *)NULL, (void *)NULL, (void *)NULL};\nstatic void * isinf_data[] = {(void *)NULL, (void *)NULL, (void *)NULL, (void *)NULL};\nstatic void * isfinite_data[] = {(void *)NULL, (void *)NULL, (void *)NULL, (void *)NULL};\n\n\n\n/* Some functions needed from ufunc object, so that Py_complex's aren't being returned \nbetween code possibly compiled with different compilers.\n*/\n\ntypedef Py_complex ComplexBinaryFunc(Py_complex x, Py_complex y);\ntypedef Py_complex ComplexUnaryFunc(Py_complex x);\n\nstatic void fastumath_F_F_As_D_D(char **args, int *dimensions, int *steps, void *func) {\n int i; Py_complex x;\n char *ip1=args[0], *op=args[1];\n for(i=0; i<*dimensions; i++, ip1+=steps[0], op+=steps[1]) {\n\tx.real = ((float *)ip1)[0]; x.imag = ((float *)ip1)[1];\n\tx = ((ComplexUnaryFunc *)func)(x);\n\t((float *)op)[0] = (float)x.real;\n\t((float *)op)[1] = (float)x.imag;\n }\n}\n\nstatic void fastumath_D_D(char **args, int *dimensions, int *steps, void *func) {\n int i; Py_complex x;\n char *ip1=args[0], *op=args[1];\n for(i=0; i<*dimensions; i++, ip1+=steps[0], op+=steps[1]) {\n\tx.real = ((double *)ip1)[0]; x.imag = ((double *)ip1)[1];\n\tx = ((ComplexUnaryFunc *)func)(x);\n\t((double *)op)[0] = x.real;\n\t((double *)op)[1] = x.imag;\n }\n}\n\n\nstatic void fastumath_FF_F_As_DD_D(char **args, int *dimensions, int *steps, void *func) {\n int i, is1=steps[0],is2=steps[1],os=steps[2];\n char *ip1=args[0], *ip2=args[1], *op=args[2];\n int n=dimensions[0];\n Py_complex x, y;\n\t\n for(i=0; i nbits. */\n{\n long r = 1;\n long p = x;\n double logtwox;\n long mask = 1;\n if (n < 0) PyErr_SetString(PyExc_ValueError, \"Integer to a negative power\");\n if (x != 0) {\n\tlogtwox = log10 (fabs ( (double) x))/log10 ( (double) 2.0);\n\tif (logtwox * (double) n > (double) nbits)\n\t PyErr_SetString(PyExc_ArithmeticError, \"Integer overflow in power.\");\n }\n while (mask > 0 && n >= mask) {\n\tif (n & mask)\n\t r *= p;\n\tmask <<= 1;\n\tp *= p;\n }\n return r;\n}\n\n\nstatic void UBYTE_add(char **args, int *dimensions, int *steps, void *func) {\n int i, is1=steps[0],is2=steps[1],os=steps[2], n=dimensions[0];\n char *i1=args[0], *i2=args[1], *op=args[2];\n for(i=0; i 255) {\n\t PyErr_SetString (PyExc_ArithmeticError, \"Integer overflow in multiply.\");\n\t return;\n\t}\n\t*((unsigned char *)op)=(unsigned char) x;\n }\n}\nstatic void SBYTE_multiply(char **args, int *dimensions, int *steps, void *func) {\n int i, is1=steps[0],is2=steps[1],os=steps[2], n=dimensions[0];\n char *i1=args[0], *i2=args[1], *op=args[2];\n int x;\n for(i=0; i 127 || x < -128) {\n\t PyErr_SetString (PyExc_ArithmeticError, \"Integer overflow in multiply.\");\n\t return;\n\t}\n\t*((signed char *)op)=(signed char) x;\n }\n}\nstatic void SHORT_multiply(char **args, int *dimensions, int *steps, void *func) {\n int i, is1=steps[0],is2=steps[1],os=steps[2], n=dimensions[0];\n char *i1=args[0], *i2=args[1], *op=args[2];\n short a, b, ah, bh, x, y;\n int s;\n for(i=0; i> (SHORT_BIT/2);\n\tbh = b >> (SHORT_BIT/2);\n\t/* Quick test for common case: two small positive shorts */\n\tif (ah == 0 && bh == 0) {\n\t if ((x=a*b) < 0) {\n\t\tPyErr_SetString (PyExc_ArithmeticError, \"Integer overflow in multiply.\");\n\t\treturn;\n\t }\n\t else {\n\t\t*((short *)op)=x;\n\t\tcontinue;\n\t }\n\t}\n\t/* Arrange that a >= b >= 0 */\n\tif (a < 0) {\n\t a = -a;\n\t if (a < 0) {\n\t\t/* Largest negative */\n\t\tif (b == 0 || b == 1) {\n\t\t *((short *)op)=a*b;\n\t\t continue;\n\t\t}\n\t\telse {\n\t\t PyErr_SetString (PyExc_ArithmeticError, \"Integer overflow in multiply.\");\n\t\t return;\n\t\t}\n\t }\n\t s = -s;\n\t ah = a >> (SHORT_BIT/2);\n\t}\n\tif (b < 0) {\n\t b = -b;\n\t if (b < 0) {\n\t\t/* Largest negative */\n\t\tif (a == 0 || a == 1) {\n\t\t *((short *)op)=a*b;\n\t\t continue;\n\t\t}\n\t\telse {\n\t\t PyErr_SetString (PyExc_ArithmeticError, \"Integer overflow in multiply.\");\n\t\t return;\n\t\t}\n\t }\n\t s = -s;\n\t bh = b >> (SHORT_BIT/2);\n\t}\n\t/* 1) both ah and bh > 0 : then report overflow */\n\tif (ah != 0 && bh != 0) {\n\t PyErr_SetString (PyExc_ArithmeticError, \"Integer overflow in multiply.\");\n\t return;\n\t}\n\t/* 2) both ah and bh = 0 : then compute a*b and report\n\t overflow if it comes out negative */\n\tif (ah == 0 && bh == 0) {\n\t if ((x=a*b) < 0) {\n\t\tPyErr_SetString (PyExc_ArithmeticError, \"Integer overflow in multiply.\");\n\t\treturn;\n\t }\n\t else {\n\t\t*((short *)op)=s * x;\n\t\tcontinue;\n\t }\n\t}\n\tif (a < b) {\n\t /* Swap */\n\t x = a;\n\t a = b;\n\t b = x;\n\t ah = bh;\n\t /* bh not used beyond this point */\n\t}\n\t/* 3) ah > 0 and bh = 0 : compute ah*bl and report overflow if\n\t it's >= 2^31\n\t compute al*bl and report overflow if it's negative\n\t add (ah*bl)<<32 to al*bl and report overflow if\n\t it's negative\n\t (NB b == bl in this case, and we make a = al) */\n\ty = ah*b;\n\tif (y >= (1 << (SHORT_BIT/2 - 1))) {\n\t PyErr_SetString (PyExc_ArithmeticError, \"Integer overflow in multiply.\");\n\t return;\n\t}\n\ta &= (1 << (SHORT_BIT/2)) - 1;\n\tx = a*b;\n\tif (x < 0) {\n\t PyErr_SetString (PyExc_ArithmeticError, \"Integer overflow in multiply.\");\n\t return;\n\t}\n\tx += y << (SHORT_BIT/2);\n\tif (x < 0) {\n\t PyErr_SetString (PyExc_ArithmeticError, \"Integer overflow in multiply.\");\n\t return;\n\t}\n\t*((short *)op)=s*x;\n }\n}\nstatic void USHORT_multiply(char **args, int *dimensions, int *steps, void *func) {\n int i, is1=steps[0],is2=steps[1],os=steps[2], n=dimensions[0];\n char *i1=args[0], *i2=args[1], *op=args[2];\n unsigned int x;\n for(i=0; i 65535) {\n\t PyErr_SetString (PyExc_ArithmeticError, \"Integer overflow in multiply.\");\n\t return;\n\t}\n\t*((unsigned short *)op)=(unsigned short) x;\n }\n}\nstatic void INT_multiply(char **args, int *dimensions, int *steps, void *func) {\n int i, is1=steps[0],is2=steps[1],os=steps[2], n=dimensions[0];\n char *i1=args[0], *i2=args[1], *op=args[2];\n int a, b, ah, bh, x, y;\n int s;\n for(i=0; i> (INT_BIT/2);\n\tbh = b >> (INT_BIT/2);\n\t/* Quick test for common case: two small positive ints */\n\tif (ah == 0 && bh == 0) {\n\t if ((x=a*b) < 0) {\n\t\tPyErr_SetString (PyExc_ArithmeticError, \"Integer overflow in multiply.\");\n\t\treturn;\n\t }\n\t else {\n\t\t*((int *)op)=x;\n\t\tcontinue;\n\t }\n\t}\n\t/* Arrange that a >= b >= 0 */\n\tif (a < 0) {\n\t a = -a;\n\t if (a < 0) {\n\t\t/* Largest negative */\n\t\tif (b == 0 || b == 1) {\n\t\t *((int *)op)=a*b;\n\t\t continue;\n\t\t}\n\t\telse {\n\t\t PyErr_SetString (PyExc_ArithmeticError, \"Integer overflow in multiply.\");\n\t\t return;\n\t\t}\n\t }\n\t s = -s;\n\t ah = a >> (INT_BIT/2);\n\t}\n\tif (b < 0) {\n\t b = -b;\n\t if (b < 0) {\n\t\t/* Largest negative */\n\t\tif (a == 0 || a == 1) {\n\t\t *((int *)op)=a*b;\n\t\t continue;\n\t\t}\n\t\telse {\n\t\t PyErr_SetString (PyExc_ArithmeticError, \"Integer overflow in multiply.\");\n\t\t return;\n\t\t}\n\t }\n\t s = -s;\n\t bh = b >> (INT_BIT/2);\n\t}\n\t/* 1) both ah and bh > 0 : then report overflow */\n\tif (ah != 0 && bh != 0) {\n\t PyErr_SetString (PyExc_ArithmeticError, \"Integer overflow in multiply.\");\n\t return;\n\t}\n\t/* 2) both ah and bh = 0 : then compute a*b and report\n\t overflow if it comes out negative */\n\tif (ah == 0 && bh == 0) {\n\t if ((x=a*b) < 0) {\n\t\tPyErr_SetString (PyExc_ArithmeticError, \"Integer overflow in multiply.\");\n\t\treturn;\n\t }\n\t else {\n\t\t*((int *)op)=s * x;\n\t\tcontinue;\n\t }\n\t}\n\tif (a < b) {\n\t /* Swap */\n\t x = a;\n\t a = b;\n\t b = x;\n\t ah = bh;\n\t /* bh not used beyond this point */\n\t}\n\t/* 3) ah > 0 and bh = 0 : compute ah*bl and report overflow if\n\t it's >= 2^31\n\t compute al*bl and report overflow if it's negative\n\t add (ah*bl)<<32 to al*bl and report overflow if\n\t it's negative\n\t (NB b == bl in this case, and we make a = al) */\n\ty = ah*b;\n\tif (y >= (1 << (INT_BIT/2 - 1))) {\n\t PyErr_SetString (PyExc_ArithmeticError, \"Integer overflow in multiply.\");\n\t return;\n\t}\n\ta &= (1 << (INT_BIT/2)) - 1;\n\tx = a*b;\n\tif (x < 0) {\n\t PyErr_SetString (PyExc_ArithmeticError, \"Integer overflow in multiply.\");\n\t return;\n\t}\n\tx += y << (INT_BIT/2);\n\tif (x < 0) {\n\t PyErr_SetString (PyExc_ArithmeticError, \"Integer overflow in multiply.\");\n\t return;\n\t}\n\t*((int *)op)=s*x;\n }\n}\nstatic void UINT_multiply(char **args, int *dimensions, int *steps, void *func) {\n int i, is1=steps[0],is2=steps[1],os=steps[2], n=dimensions[0];\n char *i1=args[0], *i2=args[1], *op=args[2];\n unsigned int a, b, ah, bh, x, y;\n for(i=0; i> (INT_BIT/2);\n\tbh = b >> (INT_BIT/2);\n\t/* Quick test for common case: two small positive ints */\n\tif (ah == 0 && bh == 0) { /* result should fit into bits available. */\n\t x = a*b;\n *((unsigned int *)op)=x;\n continue;\n }\n\t/* 1) both ah and bh > 0 : then report overflow */\n\tif (ah != 0 && bh != 0) {\n\t PyErr_SetString (PyExc_ArithmeticError, \"Integer overflow in multiply.\");\n\t return;\n\t}\n /* Otherwise one and only one of ah or bh is non-zero. Make it so a > b (ah >0 and bh=0) */\n\tif (a < b) { \n\t /* Swap */\n\t x = a;\n\t a = b;\n\t b = x;\n\t ah = bh;\n\t /* bh not used beyond this point */\n\t}\n /* Now a = ah */\n\t/* 3) ah > 0 and bh = 0 : compute ah*bl and report overflow if\n\t it's >= 2^(INT_BIT/2) -- shifted_version won't fit in unsigned int.\n\n Then compute al*bl (this should fit in the allotated space)\n\n\t compute al*bl and report overflow if it's negative\n\t add (ah*bl)<<32 to al*bl and report overflow if\n\t it's negative\n\t (NB b == bl in this case, and we make a = al) */\n\ty = ah*b;\n\tif (y >= (1 << (INT_BIT/2))) {\n\t PyErr_SetString (PyExc_ArithmeticError, \"Integer overflow in multiply.\");\n\t return;\n\t}\n\ta &= (1 << (INT_BIT/2)) - 1; /* mask off ah so a is now al */\n\tx = a*b; /* al * bl */\n\tx += y << (INT_BIT/2); /* add ah * bl * 2^SHIFT */\n /* This could have caused overflow. One way to know is to check to see if x < al \n Not sure if this get's all cases */\n\tif (x < a) {\n\t PyErr_SetString (PyExc_ArithmeticError, \"Integer overflow in multiply.\");\n\t return;\n\t}\n\t*((unsigned int *)op)=x;\n }\n}\nstatic void LONG_multiply(char **args, int *dimensions, int *steps, void *func) {\n int i, is1=steps[0],is2=steps[1],os=steps[2], n=dimensions[0];\n char *i1=args[0], *i2=args[1], *op=args[2];\n long a, b, ah, bh, x, y;\n int s;\n for(i=0; i> (LONG_BIT/2);\n\tbh = b >> (LONG_BIT/2);\n\t/* Quick test for common case: two small positive ints */\n\tif (ah == 0 && bh == 0) {\n\t if ((x=a*b) < 0) {\n\t\tPyErr_SetString (PyExc_ArithmeticError, \"Integer overflow in multiply.\");\n\t\treturn;\n\t }\n\t else {\n\t\t*((long *)op)=x;\n\t\tcontinue;\n\t }\n\t}\n\t/* Arrange that a >= b >= 0 */\n\tif (a < 0) {\n\t a = -a;\n\t if (a < 0) {\n\t\t/* Largest negative */\n\t\tif (b == 0 || b == 1) {\n\t\t *((long *)op)=a*b;\n\t\t continue;\n\t\t}\n\t\telse {\n\t\t PyErr_SetString (PyExc_ArithmeticError, \"Integer overflow in multiply.\");\n\t\t return;\n\t\t}\n\t }\n\t s = -s;\n\t ah = a >> (LONG_BIT/2);\n\t}\n\tif (b < 0) {\n\t b = -b;\n\t if (b < 0) {\n\t\t/* Largest negative */\n\t\tif (a == 0 || a == 1) {\n\t\t *((long *)op)=a*b;\n\t\t continue;\n\t\t}\n\t\telse {\n\t\t PyErr_SetString (PyExc_ArithmeticError, \"Integer overflow in multiply.\");\n\t\t return;\n\t\t}\n\t }\n\t s = -s;\n\t bh = b >> (LONG_BIT/2);\n\t}\n\t/* 1) both ah and bh > 0 : then report overflow */\n\tif (ah != 0 && bh != 0) {\n\t PyErr_SetString (PyExc_ArithmeticError, \"Integer overflow in multiply.\");\n\t return;\n\t}\n\t/* 2) both ah and bh = 0 : then compute a*b and report\n\t overflow if it comes out negative */\n\tif (ah == 0 && bh == 0) {\n\t if ((x=a*b) < 0) {\n\t\tPyErr_SetString (PyExc_ArithmeticError, \"Integer overflow in multiply.\");\n\t\treturn;\n\t }\n\t else {\n\t\t*((long *)op)=s * x;\n\t\tcontinue;\n\t }\n\t}\n\tif (a < b) {\n\t /* Swap */\n\t x = a;\n\t a = b;\n\t b = x;\n\t ah = bh;\n\t /* bh not used beyond this point */\n\t}\n\t/* 3) ah > 0 and bh = 0 : compute ah*bl and report overflow if\n\t it's >= 2^31\n\t compute al*bl and report overflow if it's negative\n\t add (ah*bl)<<32 to al*bl and report overflow if\n\t it's negative\n\t (NB b == bl in this case, and we make a = al) */\n\ty = ah*b;\n\tif (y >= (1L << (LONG_BIT/2 - 1))) {\n\t PyErr_SetString (PyExc_ArithmeticError, \"Integer overflow in multiply.\");\n\t return;\n\t}\n\ta &= (1L << (LONG_BIT/2)) - 1;\n\tx = a*b;\n\tif (x < 0) {\n\t PyErr_SetString (PyExc_ArithmeticError, \"Integer overflow in multiply.\");\n\t return;\n\t}\n\tx += y << (LONG_BIT/2);\n\tif (x < 0) {\n\t PyErr_SetString (PyExc_ArithmeticError, \"Integer overflow in multiply.\");\n\t return;\n\t}\n\t*((long *)op)=s*x;\n }\n}\nstatic void FLOAT_multiply(char **args, int *dimensions, int *steps, void *func) {\n int i, is1=steps[0],is2=steps[1],os=steps[2], n=dimensions[0];\n char *i1=args[0], *i2=args[1], *op=args[2];\n for(i=0; i= 0x02020000\nstatic void UBYTE_floor_divide(char **args, int *dimensions, int *steps, void *func) {\n int i, is1=steps[0],is2=steps[1],os=steps[2], n=dimensions[0];\n char *i1=args[0], *i2=args[1], *op=args[2];\n for(i=0; i *((unsigned char *)i2);\n }\n}\nstatic void SBYTE_greater(char **args, int *dimensions, int *steps, void *func) {\n int i, is1=steps[0],is2=steps[1],os=steps[2], n=dimensions[0];\n char *i1=args[0], *i2=args[1], *op=args[2];\n for(i=0; i *((signed char *)i2);\n }\n}\nstatic void SHORT_greater(char **args, int *dimensions, int *steps, void *func) {\n int i, is1=steps[0],is2=steps[1],os=steps[2], n=dimensions[0];\n char *i1=args[0], *i2=args[1], *op=args[2];\n for(i=0; i *((short *)i2);\n }\n}\nstatic void USHORT_greater(char **args, int *dimensions, int *steps, void *func) {\n int i, is1=steps[0],is2=steps[1],os=steps[2], n=dimensions[0];\n char *i1=args[0], *i2=args[1], *op=args[2];\n for(i=0; i *((unsigned short *)i2);\n }\n}\nstatic void INT_greater(char **args, int *dimensions, int *steps, void *func) {\n int i, is1=steps[0],is2=steps[1],os=steps[2], n=dimensions[0];\n char *i1=args[0], *i2=args[1], *op=args[2];\n for(i=0; i *((int *)i2);\n }\n}\nstatic void UINT_greater(char **args, int *dimensions, int *steps, void *func) {\n int i, is1=steps[0],is2=steps[1],os=steps[2], n=dimensions[0];\n char *i1=args[0], *i2=args[1], *op=args[2];\n for(i=0; i *((unsigned int *)i2);\n }\n}\nstatic void LONG_greater(char **args, int *dimensions, int *steps, void *func) {\n int i, is1=steps[0],is2=steps[1],os=steps[2], n=dimensions[0];\n char *i1=args[0], *i2=args[1], *op=args[2];\n for(i=0; i *((long *)i2);\n }\n}\nstatic void FLOAT_greater(char **args, int *dimensions, int *steps, void *func) {\n int i, is1=steps[0],is2=steps[1],os=steps[2], n=dimensions[0];\n char *i1=args[0], *i2=args[1], *op=args[2];\n for(i=0; i *((float *)i2);\n }\n}\nstatic void DOUBLE_greater(char **args, int *dimensions, int *steps, void *func) {\n int i, is1=steps[0],is2=steps[1],os=steps[2], n=dimensions[0];\n char *i1=args[0], *i2=args[1], *op=args[2];\n for(i=0; i *((double *)i2);\n }\n}\n\n/* complex numbers are compared by there real parts. */\nstatic void CFLOAT_greater(char **args, int *dimensions, int *steps, void *func) {\n int i, is1=steps[0],is2=steps[1],os=steps[2], n=dimensions[0];\n char *i1=args[0], *i2=args[1], *op=args[2];\n for(i=0; i ((float *)i2)[0];\n }\n}\nstatic void CDOUBLE_greater(char **args, int *dimensions, int *steps, void *func) {\n int i, is1=steps[0],is2=steps[1],os=steps[2], n=dimensions[0];\n char *i1=args[0], *i2=args[1], *op=args[2];\n for(i=0; i ((double *)i2)[0];\n }\n}\n\nstatic void UBYTE_greater_equal(char **args, int *dimensions, int *steps, void *func) {\n int i, is1=steps[0],is2=steps[1],os=steps[2], n=dimensions[0];\n char *i1=args[0], *i2=args[1], *op=args[2];\n for(i=0; i= *((unsigned char *)i2);\n }\n}\nstatic void SBYTE_greater_equal(char **args, int *dimensions, int *steps, void *func) {\n int i, is1=steps[0],is2=steps[1],os=steps[2], n=dimensions[0];\n char *i1=args[0], *i2=args[1], *op=args[2];\n for(i=0; i= *((signed char *)i2);\n }\n}\nstatic void SHORT_greater_equal(char **args, int *dimensions, int *steps, void *func) {\n int i, is1=steps[0],is2=steps[1],os=steps[2], n=dimensions[0];\n char *i1=args[0], *i2=args[1], *op=args[2];\n for(i=0; i= *((short *)i2);\n }\n}\nstatic void USHORT_greater_equal(char **args, int *dimensions, int *steps, void *func) {\n int i, is1=steps[0],is2=steps[1],os=steps[2], n=dimensions[0];\n char *i1=args[0], *i2=args[1], *op=args[2];\n for(i=0; i= *((unsigned short *)i2);\n }\n}\nstatic void INT_greater_equal(char **args, int *dimensions, int *steps, void *func) {\n int i, is1=steps[0],is2=steps[1],os=steps[2], n=dimensions[0];\n char *i1=args[0], *i2=args[1], *op=args[2];\n for(i=0; i= *((int *)i2);\n }\n}\nstatic void UINT_greater_equal(char **args, int *dimensions, int *steps, void *func) {\n int i, is1=steps[0],is2=steps[1],os=steps[2], n=dimensions[0];\n char *i1=args[0], *i2=args[1], *op=args[2];\n for(i=0; i= *((unsigned int *)i2);\n }\n}\nstatic void LONG_greater_equal(char **args, int *dimensions, int *steps, void *func) {\n int i, is1=steps[0],is2=steps[1],os=steps[2], n=dimensions[0];\n char *i1=args[0], *i2=args[1], *op=args[2];\n for(i=0; i= *((long *)i2);\n }\n}\nstatic void FLOAT_greater_equal(char **args, int *dimensions, int *steps, void *func) {\n int i, is1=steps[0],is2=steps[1],os=steps[2], n=dimensions[0];\n char *i1=args[0], *i2=args[1], *op=args[2];\n for(i=0; i= *((float *)i2);\n }\n}\nstatic void DOUBLE_greater_equal(char **args, int *dimensions, int *steps, void *func) {\n int i, is1=steps[0],is2=steps[1],os=steps[2], n=dimensions[0];\n char *i1=args[0], *i2=args[1], *op=args[2];\n for(i=0; i= *((double *)i2);\n }\n}\nstatic void CFLOAT_greater_equal(char **args, int *dimensions, int *steps, void *func) {\n int i, is1=steps[0],is2=steps[1],os=steps[2], n=dimensions[0];\n char *i1=args[0], *i2=args[1], *op=args[2];\n for(i=0; i= *((float *)i2);\n }\n}\nstatic void CDOUBLE_greater_equal(char **args, int *dimensions, int *steps, void *func) {\n int i, is1=steps[0],is2=steps[1],os=steps[2], n=dimensions[0];\n char *i1=args[0], *i2=args[1], *op=args[2];\n for(i=0; i= *((double *)i2);\n }\n}\n\nstatic void UBYTE_less(char **args, int *dimensions, int *steps, void *func) {\n int i, is1=steps[0],is2=steps[1],os=steps[2], n=dimensions[0];\n char *i1=args[0], *i2=args[1], *op=args[2];\n for(i=0; i *((unsigned char *)i2) ? *((unsigned char *)i1) : *((unsigned char *)i2);\n }\n}\nstatic void SBYTE_maximum(char **args, int *dimensions, int *steps, void *func) {\n int i, is1=steps[0],is2=steps[1],os=steps[2], n=dimensions[0];\n char *i1=args[0], *i2=args[1], *op=args[2];\n for(i=0; i *((signed char *)i2) ? *((signed char *)i1) : *((signed char *)i2);\n }\n}\nstatic void SHORT_maximum(char **args, int *dimensions, int *steps, void *func) {\n int i, is1=steps[0],is2=steps[1],os=steps[2], n=dimensions[0];\n char *i1=args[0], *i2=args[1], *op=args[2];\n for(i=0; i *((short *)i2) ? *((short *)i1) : *((short *)i2);\n }\n}\nstatic void USHORT_maximum(char **args, int *dimensions, int *steps, void *func) {\n int i, is1=steps[0],is2=steps[1],os=steps[2], n=dimensions[0];\n char *i1=args[0], *i2=args[1], *op=args[2];\n for(i=0; i *((unsigned short *)i2) ? *((unsigned short *)i1) : *((unsigned short *)i2);\n }\n}\nstatic void INT_maximum(char **args, int *dimensions, int *steps, void *func) {\n int i, is1=steps[0],is2=steps[1],os=steps[2], n=dimensions[0];\n char *i1=args[0], *i2=args[1], *op=args[2];\n for(i=0; i *((int *)i2) ? *((int *)i1) : *((int *)i2);\n }\n}\nstatic void UINT_maximum(char **args, int *dimensions, int *steps, void *func) {\n int i, is1=steps[0],is2=steps[1],os=steps[2], n=dimensions[0];\n char *i1=args[0], *i2=args[1], *op=args[2];\n for(i=0; i *((unsigned int *)i2) ? *((unsigned int *)i1) : *((unsigned int *)i2);\n }\n}\nstatic void LONG_maximum(char **args, int *dimensions, int *steps, void *func) {\n int i, is1=steps[0],is2=steps[1],os=steps[2], n=dimensions[0];\n char *i1=args[0], *i2=args[1], *op=args[2];\n for(i=0; i *((long *)i2) ? *((long *)i1) : *((long *)i2);\n }\n}\nstatic void FLOAT_maximum(char **args, int *dimensions, int *steps, void *func) {\n int i, is1=steps[0],is2=steps[1],os=steps[2], n=dimensions[0];\n char *i1=args[0], *i2=args[1], *op=args[2];\n for(i=0; i *((float *)i2) ? *((float *)i1) : *((float *)i2);\n }\n}\nstatic void DOUBLE_maximum(char **args, int *dimensions, int *steps, void *func) {\n int i, is1=steps[0],is2=steps[1],os=steps[2], n=dimensions[0];\n char *i1=args[0], *i2=args[1], *op=args[2];\n for(i=0; i *((double *)i2) ? *((double *)i1) : *((double *)i2);\n }\n}\nstatic void CFLOAT_maximum(char **args, int *dimensions, int *steps, void *func) {\n int i, is1=steps[0],is2=steps[1],os=steps[2], n=dimensions[0];\n char *i1=args[0], *i2=args[1], *op=args[2];\n for(i=0; i *((float *)i2) ? *((float *)i1) : *((float *)i2);\n\t((float *)op)[1]=*((float *)i1) > *((float *)i2) ? ((float *)i1)[1] : ((float *)i2)[1];\n }\n}\nstatic void CDOUBLE_maximum(char **args, int *dimensions, int *steps, void *func) {\n int i, is1=steps[0],is2=steps[1],os=steps[2], n=dimensions[0];\n char *i1=args[0], *i2=args[1], *op=args[2];\n for(i=0; i *((double *)i2) ? *((double *)i1) : *((double *)i2);\n\t((double *)op)[1]=*((double *)i1) > *((double *)i2) ? ((double *)i1)[1] : ((double *)i2)[1];\n }\n}\nstatic void UBYTE_minimum(char **args, int *dimensions, int *steps, void *func) {\n int i, is1=steps[0],is2=steps[1],os=steps[2], n=dimensions[0];\n char *i1=args[0], *i2=args[1], *op=args[2];\n for(i=0; i> *((unsigned char *)i2);\n }\n}\nstatic void SBYTE_right_shift(char **args, int *dimensions, int *steps, void *func) {\n int i, is1=steps[0],is2=steps[1],os=steps[2], n=dimensions[0];\n char *i1=args[0], *i2=args[1], *op=args[2];\n for(i=0; i> *((signed char *)i2);\n }\n}\nstatic void SHORT_right_shift(char **args, int *dimensions, int *steps, void *func) {\n int i, is1=steps[0],is2=steps[1],os=steps[2], n=dimensions[0];\n char *i1=args[0], *i2=args[1], *op=args[2];\n for(i=0; i> *((short *)i2);\n }\n}\nstatic void USHORT_right_shift(char **args, int *dimensions, int *steps, void *func) {\n int i, is1=steps[0],is2=steps[1],os=steps[2], n=dimensions[0];\n char *i1=args[0], *i2=args[1], *op=args[2];\n for(i=0; i> *((unsigned short *)i2);\n }\n}\nstatic void INT_right_shift(char **args, int *dimensions, int *steps, void *func) {\n int i, is1=steps[0],is2=steps[1],os=steps[2], n=dimensions[0];\n char *i1=args[0], *i2=args[1], *op=args[2];\n for(i=0; i> *((int *)i2);\n }\n}\nstatic void UINT_right_shift(char **args, int *dimensions, int *steps, void *func) {\n int i, is1=steps[0],is2=steps[1],os=steps[2], n=dimensions[0];\n char *i1=args[0], *i2=args[1], *op=args[2];\n for(i=0; i> *((unsigned int *)i2);\n }\n}\nstatic void LONG_right_shift(char **args, int *dimensions, int *steps, void *func) {\n int i, is1=steps[0],is2=steps[1],os=steps[2], n=dimensions[0];\n char *i1=args[0], *i2=args[1], *op=args[2];\n for(i=0; i> *((long *)i2);\n }\n}\n\nstatic PyUFuncGenericFunction add_functions[] = { UBYTE_add, SBYTE_add, SHORT_add, USHORT_add, INT_add, UINT_add, LONG_add, FLOAT_add, DOUBLE_add, CFLOAT_add, CDOUBLE_add, NULL, };\nstatic PyUFuncGenericFunction subtract_functions[] = { UBYTE_subtract, SBYTE_subtract, SHORT_subtract, USHORT_subtract, INT_subtract, UINT_subtract, LONG_subtract, FLOAT_subtract, DOUBLE_subtract, CFLOAT_subtract, CDOUBLE_subtract, NULL, };\nstatic PyUFuncGenericFunction multiply_functions[] = { UBYTE_multiply, SBYTE_multiply, SHORT_multiply, USHORT_multiply, INT_multiply, UINT_multiply, LONG_multiply, FLOAT_multiply, DOUBLE_multiply, NULL, NULL, NULL, };\nstatic PyUFuncGenericFunction divide_functions[] = { UBYTE_divide, SBYTE_divide, SHORT_divide, USHORT_divide, INT_divide, UINT_divide, LONG_divide, FLOAT_divide, DOUBLE_divide, NULL, NULL, NULL, };\n#if PY_VERSION_HEX >= 0x02020000\nstatic PyUFuncGenericFunction floor_divide_functions[] = { UBYTE_floor_divide, SBYTE_floor_divide, SHORT_floor_divide, USHORT_floor_divide, INT_floor_divide, UINT_floor_divide, LONG_floor_divide, FLOAT_floor_divide, DOUBLE_floor_divide, NULL, NULL, NULL, };\nstatic PyUFuncGenericFunction true_divide_functions[] = { UBYTE_true_divide, SBYTE_true_divide, SHORT_true_divide, USHORT_true_divide, INT_true_divide, UINT_true_divide, LONG_true_divide, FLOAT_true_divide, DOUBLE_true_divide, NULL, NULL, NULL, };\n#endif\nstatic PyUFuncGenericFunction divide_safe_functions[] = { UBYTE_divide_safe, SBYTE_divide_safe, SHORT_divide_safe, USHORT_divide_safe, INT_divide_safe, UINT_divide_safe, LONG_divide_safe, FLOAT_divide_safe, DOUBLE_divide_safe, };\nstatic PyUFuncGenericFunction conjugate_functions[] = { UBYTE_conjugate, SBYTE_conjugate, SHORT_conjugate, USHORT_conjugate, INT_conjugate, UINT_conjugate, LONG_conjugate, FLOAT_conjugate, DOUBLE_conjugate, CFLOAT_conjugate, CDOUBLE_conjugate, NULL, };\nstatic PyUFuncGenericFunction remainder_functions[] = { UBYTE_remainder, SBYTE_remainder, SHORT_remainder, USHORT_remainder, INT_remainder, UINT_remainder, LONG_remainder, NULL, NULL, NULL, };\nstatic PyUFuncGenericFunction power_functions[] = { UBYTE_power, SBYTE_power, SHORT_power, USHORT_power, INT_power, UINT_power, LONG_power, NULL, NULL, NULL, NULL, NULL, };\nstatic PyUFuncGenericFunction absolute_functions[] = { UBYTE_absolute, SBYTE_absolute, SHORT_absolute, USHORT_absolute, INT_absolute, UINT_absolute, LONG_absolute, FLOAT_absolute, DOUBLE_absolute, CFLOAT_absolute, CDOUBLE_absolute, NULL, };\nstatic PyUFuncGenericFunction negative_functions[] = { UBYTE_negative, SBYTE_negative, SHORT_negative, USHORT_negative, INT_negative, UINT_negative, LONG_negative, FLOAT_negative, DOUBLE_negative, CFLOAT_negative, CDOUBLE_negative, NULL, };\nstatic PyUFuncGenericFunction greater_functions[] = { UBYTE_greater, SBYTE_greater, SHORT_greater, USHORT_greater, INT_greater, UINT_greater, LONG_greater, FLOAT_greater, DOUBLE_greater, CFLOAT_greater, CDOUBLE_greater, };\nstatic PyUFuncGenericFunction greater_equal_functions[] = { UBYTE_greater_equal, SBYTE_greater_equal, SHORT_greater_equal, USHORT_greater_equal, INT_greater_equal, UINT_greater_equal, LONG_greater_equal, FLOAT_greater_equal, DOUBLE_greater_equal, CFLOAT_greater_equal, CDOUBLE_greater_equal, };\nstatic PyUFuncGenericFunction less_functions[] = { UBYTE_less, SBYTE_less, SHORT_less, USHORT_less, INT_less, UINT_less, LONG_less, FLOAT_less, DOUBLE_less, CFLOAT_less, CDOUBLE_less, };\nstatic PyUFuncGenericFunction less_equal_functions[] = { UBYTE_less_equal, SBYTE_less_equal, SHORT_less_equal, USHORT_less_equal, INT_less_equal, UINT_less_equal, LONG_less_equal, FLOAT_less_equal, DOUBLE_less_equal, CFLOAT_less_equal, CDOUBLE_less_equal, };\nstatic PyUFuncGenericFunction equal_functions[] = { CHAR_equal, UBYTE_equal, SBYTE_equal, SHORT_equal, USHORT_equal, INT_equal, UINT_equal, LONG_equal, FLOAT_equal, DOUBLE_equal, CFLOAT_equal, CDOUBLE_equal, OBJECT_equal};\nstatic PyUFuncGenericFunction not_equal_functions[] = { CHAR_not_equal, UBYTE_not_equal, SBYTE_not_equal, SHORT_not_equal, USHORT_not_equal, INT_not_equal, UINT_not_equal, LONG_not_equal, FLOAT_not_equal, DOUBLE_not_equal, CFLOAT_not_equal, CDOUBLE_not_equal, OBJECT_not_equal};\nstatic PyUFuncGenericFunction logical_and_functions[] = { UBYTE_logical_and, SBYTE_logical_and, SHORT_logical_and, USHORT_logical_and, INT_logical_and, UINT_logical_and, LONG_logical_and, FLOAT_logical_and, DOUBLE_logical_and, };\nstatic PyUFuncGenericFunction logical_or_functions[] = { UBYTE_logical_or, SBYTE_logical_or, SHORT_logical_or, USHORT_logical_or, INT_logical_or, UINT_logical_or, LONG_logical_or, FLOAT_logical_or, DOUBLE_logical_or, };\nstatic PyUFuncGenericFunction logical_xor_functions[] = { UBYTE_logical_xor, SBYTE_logical_xor, SHORT_logical_xor, USHORT_logical_xor, INT_logical_xor, UINT_logical_xor, LONG_logical_xor, FLOAT_logical_xor, DOUBLE_logical_xor, };\nstatic PyUFuncGenericFunction logical_not_functions[] = { UBYTE_logical_not, SBYTE_logical_not, SHORT_logical_not, USHORT_logical_not, INT_logical_not, UINT_logical_not, LONG_logical_not, FLOAT_logical_not, DOUBLE_logical_not, };\nstatic PyUFuncGenericFunction maximum_functions[] = { UBYTE_maximum, SBYTE_maximum, SHORT_maximum, USHORT_maximum, INT_maximum, UINT_maximum, LONG_maximum, FLOAT_maximum, DOUBLE_maximum, CFLOAT_maximum, CDOUBLE_maximum, };\nstatic PyUFuncGenericFunction minimum_functions[] = { UBYTE_minimum, SBYTE_minimum, SHORT_minimum, USHORT_minimum, INT_minimum, UINT_minimum, LONG_minimum, FLOAT_minimum, DOUBLE_minimum, CFLOAT_minimum, CDOUBLE_minimum, };\nstatic PyUFuncGenericFunction bitwise_and_functions[] = { UBYTE_bitwise_and, SBYTE_bitwise_and, SHORT_bitwise_and, USHORT_bitwise_and, INT_bitwise_and, UINT_bitwise_and, LONG_bitwise_and, NULL, };\nstatic PyUFuncGenericFunction bitwise_or_functions[] = { UBYTE_bitwise_or, SBYTE_bitwise_or, SHORT_bitwise_or, USHORT_bitwise_or, INT_bitwise_or, UINT_bitwise_or, LONG_bitwise_or, NULL, };\nstatic PyUFuncGenericFunction bitwise_xor_functions[] = { UBYTE_bitwise_xor, SBYTE_bitwise_xor, SHORT_bitwise_xor, USHORT_bitwise_xor, INT_bitwise_xor, UINT_bitwise_xor, LONG_bitwise_xor, NULL, };\nstatic PyUFuncGenericFunction invert_functions[] = { UBYTE_invert, SBYTE_invert, SHORT_invert, USHORT_invert, INT_invert, UINT_invert, LONG_invert, NULL, };\nstatic PyUFuncGenericFunction left_shift_functions[] = { UBYTE_left_shift, SBYTE_left_shift, SHORT_left_shift, USHORT_left_shift, INT_left_shift, UINT_left_shift, LONG_left_shift, NULL, };\nstatic PyUFuncGenericFunction right_shift_functions[] = { UBYTE_right_shift, SBYTE_right_shift, SHORT_right_shift, USHORT_right_shift, INT_right_shift, UINT_right_shift, LONG_right_shift, NULL, };\n\nstatic PyUFuncGenericFunction arccos_functions[] = { NULL, NULL, NULL, NULL, NULL, };\nstatic PyUFuncGenericFunction ceil_functions[] = { NULL, NULL, NULL, };\nstatic PyUFuncGenericFunction arctan2_functions[] = { NULL, NULL, NULL, };\n\n\nstatic void * add_data[] = { (void *)NULL, (void *)NULL, (void *)NULL, (void *)NULL, (void *)NULL, (void *)NULL, (void *)NULL, (void *)NULL, (void *)NULL, (void *)NULL, (void *)NULL, (void *)NULL};\nstatic void * subtract_data[] = { (void *)NULL, (void *)NULL, (void *)NULL, (void *)NULL, (void *)NULL, (void *)NULL, (void *)NULL, (void *)NULL, (void *)NULL, (void *)NULL, (void *)NULL, (void *)NULL};\nstatic void * multiply_data[] = { (void *)NULL, (void *)NULL, (void *)NULL, (void *)NULL, (void *)NULL, (void *)NULL, (void *)NULL, (void *)NULL, (void *)NULL, (void *)NULL, (void *)NULL, (void *)NULL};\nstatic void * divide_data[] = { (void *)NULL, (void *)NULL, (void *)NULL, (void *)NULL, (void *)NULL, (void *)NULL, (void *)NULL, (void *)NULL, (void *)NULL, (void *)NULL, (void *)NULL, (void *)NULL};\n#if PY_VERSION_HEX >= 0x02020000\nstatic void * floor_divide_data[] = { (void *)NULL, (void *)NULL, (void *)NULL, (void *)NULL, (void *)NULL, (void *)NULL, (void *)NULL, (void *)NULL, (void *)NULL, (void *)NULL, (void *)NULL, (void *)NULL};\nstatic void * true_divide_data[] = { (void *)NULL, (void *)NULL, (void *)NULL, (void *)NULL, (void *)NULL, (void *)NULL, (void *)NULL, (void *)NULL, (void *)NULL, (void *)NULL, (void *)NULL, (void *)NULL };\n#endif\nstatic void * divide_safe_data[] = { (void *)NULL, (void *)NULL, (void *)NULL, (void *)NULL, (void *)NULL, (void *)NULL, (void *)NULL, (void *)NULL, (void *)NULL, (void *)NULL, (void *) NULL, (void *) NULL };\nstatic void * conjugate_data[] = { (void *)NULL, (void *)NULL, (void *)NULL, (void *)NULL, (void *)NULL, (void *)NULL, (void *)NULL, (void *)NULL, (void *)NULL, (void *)NULL, (void *)NULL, (void *)NULL };\nstatic void * remainder_data[] = { (void *)NULL, (void *)NULL, (void *)NULL, (void *)NULL, (void *)NULL, (void *)NULL, (void *)NULL, (void *)NULL, (void *)NULL, (void *)NULL, };\nstatic void * power_data[] = { (void *)NULL, (void *)NULL, (void *)NULL, (void *)NULL, (void *)NULL, (void *)NULL, (void *)NULL, (void *)NULL, (void *)NULL, (void *)NULL, (void *)NULL, (void *)NULL,};\nstatic void * absolute_data[] = { (void *)NULL, (void *)NULL, (void *)NULL, (void *)NULL, (void *)NULL, (void *)NULL, (void *)NULL, (void *)NULL, (void *)NULL, (void *)NULL, (void *)NULL, (void *)NULL};\nstatic void * negative_data[] = { (void *)NULL, (void *)NULL, (void *)NULL, (void *)NULL, (void *)NULL, (void *)NULL, (void *)NULL, (void *)NULL, (void *)NULL, (void *)NULL, (void *)NULL, (void *)NULL,};\nstatic void * equal_data[] = { (void *)NULL, (void *)NULL, (void *)NULL, (void *)NULL, (void *)NULL, (void *)NULL, (void *)NULL, (void *)NULL, (void *)NULL, (void *)NULL, (void *)NULL, (void *)NULL, (void *)NULL, }; \nstatic void * bitwise_and_data[] = { (void *)NULL, (void *)NULL, (void *)NULL, (void *)NULL, (void *)NULL, (void *)NULL, (void *)NULL, (void *)NULL, };\nstatic void * bitwise_or_data[] = { (void *)NULL, (void *)NULL, (void *)NULL, (void *)NULL, (void *)NULL, (void *)NULL, (void *)NULL, (void *)NULL, };\nstatic void * bitwise_xor_data[] = { (void *)NULL, (void *)NULL, (void *)NULL, (void *)NULL, (void *)NULL, (void *)NULL, (void *)NULL, (void *)NULL, };\nstatic void * invert_data[] = { (void *)NULL, (void *)NULL, (void *)NULL, (void *)NULL, (void *)NULL, (void *)NULL, (void *)NULL, (void *)NULL,};\nstatic void * left_shift_data[] = { (void *)NULL, (void *)NULL, (void *)NULL, (void *)NULL, (void *)NULL, (void *)NULL, (void *)NULL, (void *)NULL,};\nstatic void * right_shift_data[] = { (void *)NULL, (void *)NULL, (void *)NULL, (void *)NULL, (void *)NULL, (void *)NULL, (void *)NULL, (void *)NULL,};\n\nstatic void * arccos_data[] = { (void *)acos, (void *)acos, (void *)c_acos, (void *)c_acos, (void *)\"arccos\", };\nstatic void * arcsin_data[] = { (void *)asin, (void *)asin, (void *)c_asin, (void *)c_asin, (void *)\"arcsin\", };\nstatic void * arctan_data[] = { (void *)atan, (void *)atan, (void *)c_atan, (void *)c_atan, (void *)\"arctan\", };\nstatic void * arccosh_data[] = { (void *)acosh, (void *)acosh, (void *)c_acosh, (void *)c_acosh, (void *)\"arccosh\", };\nstatic void * arcsinh_data[] = { (void *)asinh, (void *)asinh, (void *)c_asinh, (void *)c_asinh, (void *)\"arcsinh\", };\nstatic void * arctanh_data[] = { (void *)atanh, (void *)atanh, (void *)c_atanh, (void *)c_atanh, (void *)\"arctanh\", };\nstatic void * cos_data[] = { (void *)cos, (void *)cos, (void *)c_cos, (void *)c_cos, (void *)\"cos\", };\nstatic void * cosh_data[] = { (void *)cosh, (void *)cosh, (void *)c_cosh, (void *)c_cosh, (void *)\"cosh\", };\nstatic void * exp_data[] = { (void *)exp, (void *)exp, (void *)c_exp, (void *)c_exp, (void *)\"exp\", };\nstatic void * log_data[] = { (void *)log, (void *)log, (void *)c_log, (void *)c_log, (void *)\"log\", };\nstatic void * log10_data[] = { (void *)log10, (void *)log10, (void *)c_log10, (void *)c_log10, (void *)\"log10\", };\nstatic void * sin_data[] = { (void *)sin, (void *)sin, (void *)c_sin, (void *)c_sin, (void *)\"sin\", };\nstatic void * sinh_data[] = { (void *)sinh, (void *)sinh, (void *)c_sinh, (void *)c_sinh, (void *)\"sinh\", };\nstatic void * sqrt_data[] = { (void *)sqrt, (void *)sqrt, (void *)c_sqrt, (void *)c_sqrt, (void *)\"sqrt\", };\nstatic void * tan_data[] = { (void *)tan, (void *)tan, (void *)c_tan, (void *)c_tan, (void *)\"tan\", };\nstatic void * tanh_data[] = { (void *)tanh, (void *)tanh, (void *)c_tanh, (void *)c_tanh, (void *)\"tanh\", };\nstatic void * ceil_data[] = { (void *)ceil, (void *)ceil, (void *)\"ceil\", };\nstatic void * fabs_data[] = { (void *)fabs, (void *)fabs, (void *)\"fabs\", };\nstatic void * floor_data[] = { (void *)floor, (void *)floor, (void *)\"floor\", };\nstatic void * arctan2_data[] = { (void *)atan2, (void *)atan2, (void *)\"arctan2\", };\nstatic void * fmod_data[] = { (void *)fmod, (void *)fmod, (void *)\"fmod\", };\nstatic void * hypot_data[] = { (void *)hypot, (void *)hypot, (void *)\"hypot\", };\n\nstatic char add_signatures[] = { PyArray_UBYTE, PyArray_UBYTE, PyArray_UBYTE, PyArray_SBYTE, PyArray_SBYTE, PyArray_SBYTE, PyArray_SHORT, PyArray_SHORT, PyArray_SHORT, PyArray_USHORT, PyArray_USHORT, PyArray_USHORT, PyArray_INT, PyArray_INT, PyArray_INT, PyArray_UINT, PyArray_UINT, PyArray_UINT, PyArray_LONG, PyArray_LONG, PyArray_LONG, PyArray_FLOAT, PyArray_FLOAT, PyArray_FLOAT, PyArray_DOUBLE, PyArray_DOUBLE, PyArray_DOUBLE, PyArray_CFLOAT, PyArray_CFLOAT, PyArray_CFLOAT, PyArray_CDOUBLE, PyArray_CDOUBLE, PyArray_CDOUBLE, PyArray_OBJECT, PyArray_OBJECT, PyArray_OBJECT, };\n#if PY_VERSION_HEX >= 0x02020000\nstatic char floor_divide_signatures[] = { PyArray_UBYTE, PyArray_UBYTE, PyArray_UBYTE, PyArray_SBYTE, PyArray_SBYTE, PyArray_SBYTE, PyArray_SHORT, PyArray_SHORT, PyArray_SHORT, PyArray_USHORT, PyArray_USHORT, PyArray_USHORT, PyArray_INT, PyArray_INT, PyArray_INT, PyArray_UINT, PyArray_UINT, PyArray_UINT, PyArray_LONG, PyArray_LONG, PyArray_LONG, PyArray_FLOAT, PyArray_FLOAT, PyArray_FLOAT, PyArray_DOUBLE, PyArray_DOUBLE, PyArray_DOUBLE, };\nstatic char true_divide_signatures[] = { PyArray_UBYTE, PyArray_UBYTE, PyArray_FLOAT, PyArray_SBYTE, PyArray_SBYTE, PyArray_FLOAT, PyArray_SHORT, PyArray_SHORT, PyArray_FLOAT, PyArray_USHORT, PyArray_USHORT, PyArray_FLOAT, PyArray_INT, PyArray_INT, PyArray_DOUBLE, PyArray_UINT, PyArray_UINT, PyArray_DOUBLE, PyArray_LONG, PyArray_LONG, PyArray_DOUBLE, PyArray_FLOAT, PyArray_FLOAT, PyArray_FLOAT, PyArray_DOUBLE, PyArray_DOUBLE, PyArray_DOUBLE, PyArray_CFLOAT, PyArray_CFLOAT, PyArray_CFLOAT, PyArray_CDOUBLE, PyArray_CDOUBLE, PyArray_CDOUBLE, PyArray_OBJECT, PyArray_OBJECT, PyArray_OBJECT, };\n#endif\nstatic char divide_safe_signatures[] = { PyArray_UBYTE, PyArray_UBYTE, PyArray_UBYTE, PyArray_SBYTE, PyArray_SBYTE, PyArray_SBYTE, PyArray_SHORT, PyArray_SHORT, PyArray_SHORT, PyArray_USHORT, PyArray_USHORT, PyArray_USHORT, PyArray_INT, PyArray_INT, PyArray_INT, PyArray_UINT, PyArray_UINT, PyArray_UINT, PyArray_LONG, PyArray_LONG, PyArray_LONG, PyArray_FLOAT, PyArray_FLOAT, PyArray_FLOAT, PyArray_DOUBLE, PyArray_DOUBLE, PyArray_DOUBLE, };\nstatic char conjugate_signatures[] = { PyArray_UBYTE, PyArray_UBYTE, PyArray_SBYTE, PyArray_SBYTE, PyArray_SHORT, PyArray_SHORT, PyArray_USHORT, PyArray_USHORT, PyArray_INT, PyArray_INT, PyArray_UINT, PyArray_UINT, PyArray_LONG, PyArray_LONG, PyArray_FLOAT, PyArray_FLOAT, PyArray_DOUBLE, PyArray_DOUBLE, PyArray_CFLOAT, PyArray_CFLOAT, PyArray_CDOUBLE, PyArray_CDOUBLE, PyArray_OBJECT, PyArray_OBJECT, };\nstatic char remainder_signatures[] = { PyArray_UBYTE, PyArray_UBYTE, PyArray_UBYTE, PyArray_SBYTE, PyArray_SBYTE, PyArray_SBYTE, PyArray_SHORT, PyArray_SHORT, PyArray_SHORT, PyArray_USHORT, PyArray_USHORT, PyArray_USHORT, PyArray_INT, PyArray_INT, PyArray_INT, PyArray_UINT, PyArray_UINT, PyArray_UINT, PyArray_LONG, PyArray_LONG, PyArray_LONG, PyArray_FLOAT, PyArray_FLOAT, PyArray_FLOAT, PyArray_DOUBLE, PyArray_DOUBLE, PyArray_DOUBLE, PyArray_OBJECT, PyArray_OBJECT, PyArray_OBJECT, };\nstatic char absolute_signatures[] = { PyArray_UBYTE, PyArray_UBYTE, PyArray_SBYTE, PyArray_SBYTE, PyArray_SHORT, PyArray_SHORT, PyArray_USHORT, PyArray_USHORT, PyArray_INT, PyArray_INT, PyArray_UINT, PyArray_UINT, PyArray_LONG, PyArray_LONG, PyArray_FLOAT, PyArray_FLOAT, PyArray_DOUBLE, PyArray_DOUBLE, PyArray_CFLOAT, PyArray_FLOAT, PyArray_CDOUBLE, PyArray_DOUBLE, PyArray_OBJECT, PyArray_OBJECT, };\nstatic char negative_signatures[] = { PyArray_UBYTE, PyArray_UBYTE, PyArray_SBYTE, PyArray_SBYTE, PyArray_SHORT, PyArray_SHORT, PyArray_USHORT, PyArray_USHORT, PyArray_INT, PyArray_INT, PyArray_UINT, PyArray_UINT, PyArray_LONG, PyArray_LONG, PyArray_FLOAT, PyArray_FLOAT, PyArray_DOUBLE, PyArray_DOUBLE, PyArray_CFLOAT, PyArray_CFLOAT, PyArray_CDOUBLE, PyArray_CDOUBLE, PyArray_OBJECT, PyArray_OBJECT, };\nstatic char equal_signatures[] = { PyArray_CHAR, PyArray_CHAR, PyArray_UBYTE, PyArray_UBYTE, PyArray_UBYTE, PyArray_UBYTE, PyArray_SBYTE, PyArray_SBYTE, PyArray_UBYTE, PyArray_SHORT, PyArray_SHORT, PyArray_UBYTE, PyArray_USHORT, PyArray_USHORT, PyArray_UBYTE, PyArray_INT, PyArray_INT, PyArray_UBYTE, PyArray_UINT, PyArray_UINT, PyArray_UBYTE, PyArray_LONG, PyArray_LONG, PyArray_UBYTE, PyArray_FLOAT, PyArray_FLOAT, PyArray_UBYTE, PyArray_DOUBLE, PyArray_DOUBLE, PyArray_UBYTE, PyArray_CFLOAT, PyArray_CFLOAT, PyArray_UBYTE, PyArray_CDOUBLE, PyArray_CDOUBLE, PyArray_UBYTE, PyArray_OBJECT, PyArray_OBJECT, PyArray_UBYTE,};\nstatic char greater_signatures[] = { PyArray_UBYTE, PyArray_UBYTE, PyArray_UBYTE, PyArray_SBYTE, PyArray_SBYTE, PyArray_UBYTE, PyArray_SHORT, PyArray_SHORT, PyArray_UBYTE, PyArray_USHORT, PyArray_USHORT, PyArray_UBYTE, PyArray_INT, PyArray_INT, PyArray_UBYTE, PyArray_UINT, PyArray_UINT, PyArray_UBYTE, PyArray_LONG, PyArray_LONG, PyArray_UBYTE, PyArray_FLOAT, PyArray_FLOAT, PyArray_UBYTE, PyArray_DOUBLE, PyArray_DOUBLE, PyArray_UBYTE, PyArray_CFLOAT, PyArray_CFLOAT, PyArray_UBYTE, PyArray_CDOUBLE, PyArray_CDOUBLE, PyArray_UBYTE };\nstatic char logical_signatures[] = { PyArray_UBYTE, PyArray_UBYTE, PyArray_UBYTE, PyArray_SBYTE, PyArray_SBYTE, PyArray_SBYTE, PyArray_SHORT, PyArray_SHORT, PyArray_SHORT, PyArray_USHORT, PyArray_USHORT, PyArray_USHORT, PyArray_INT, PyArray_INT, PyArray_INT, PyArray_UINT, PyArray_UINT, PyArray_UINT, PyArray_LONG, PyArray_LONG, PyArray_LONG, PyArray_FLOAT, PyArray_FLOAT, PyArray_FLOAT, PyArray_DOUBLE, PyArray_DOUBLE, PyArray_DOUBLE, PyArray_CFLOAT, PyArray_CFLOAT, PyArray_CFLOAT, PyArray_CDOUBLE, PyArray_CDOUBLE, PyArray_CDOUBLE };\nstatic char logical_not_signatures[] = { PyArray_UBYTE, PyArray_UBYTE, PyArray_SBYTE, PyArray_UBYTE, PyArray_SHORT, PyArray_UBYTE, PyArray_USHORT, PyArray_UBYTE, PyArray_INT, PyArray_UBYTE, PyArray_UINT, PyArray_UBYTE, PyArray_LONG, PyArray_UBYTE, PyArray_FLOAT, PyArray_UBYTE, PyArray_DOUBLE, PyArray_UBYTE, };\nstatic char maximum_signatures[] = { PyArray_UBYTE, PyArray_UBYTE, PyArray_UBYTE, PyArray_SBYTE, PyArray_SBYTE, PyArray_SBYTE, PyArray_SHORT, PyArray_SHORT, PyArray_SHORT, PyArray_USHORT, PyArray_USHORT, PyArray_USHORT, PyArray_INT, PyArray_INT, PyArray_INT, PyArray_UINT, PyArray_UINT, PyArray_UINT, PyArray_LONG, PyArray_LONG, PyArray_LONG, PyArray_FLOAT, PyArray_FLOAT, PyArray_FLOAT, PyArray_DOUBLE, PyArray_DOUBLE, PyArray_DOUBLE, PyArray_CFLOAT, PyArray_CFLOAT, PyArray_CFLOAT, PyArray_CDOUBLE, PyArray_CDOUBLE, PyArray_CDOUBLE, };\nstatic char bitwise_and_signatures[] = { PyArray_UBYTE, PyArray_UBYTE, PyArray_UBYTE, PyArray_SBYTE, PyArray_SBYTE, PyArray_SBYTE, PyArray_SHORT, PyArray_SHORT, PyArray_SHORT, PyArray_USHORT, PyArray_USHORT, PyArray_USHORT, PyArray_INT, PyArray_INT, PyArray_INT, PyArray_UINT, PyArray_UINT, PyArray_UINT, PyArray_LONG, PyArray_LONG, PyArray_LONG, PyArray_OBJECT, PyArray_OBJECT, PyArray_OBJECT, };\nstatic char invert_signatures[] = { PyArray_UBYTE, PyArray_UBYTE, PyArray_SBYTE, PyArray_SBYTE, PyArray_SHORT, PyArray_SHORT, PyArray_USHORT, PyArray_USHORT, PyArray_INT, PyArray_INT, PyArray_UINT, PyArray_UINT, PyArray_LONG, PyArray_LONG, PyArray_OBJECT, PyArray_OBJECT, };\n\nstatic char arccos_signatures[] = { PyArray_FLOAT, PyArray_FLOAT, PyArray_DOUBLE, PyArray_DOUBLE, PyArray_CFLOAT, PyArray_CFLOAT, PyArray_CDOUBLE, PyArray_CDOUBLE, PyArray_OBJECT, PyArray_OBJECT, };\nstatic char ceil_signatures[] = { PyArray_FLOAT, PyArray_FLOAT, PyArray_DOUBLE, PyArray_DOUBLE, PyArray_OBJECT, PyArray_OBJECT, };\nstatic char arctan2_signatures[] = { PyArray_FLOAT, PyArray_FLOAT, PyArray_FLOAT, PyArray_DOUBLE, PyArray_DOUBLE, PyArray_DOUBLE, PyArray_OBJECT, PyArray_OBJECT, };\n\nstatic void InitOperators(PyObject *dictionary) {\n PyObject *f;\n\n add_data[11] =(void *)PyNumber_Add;\n subtract_data[11] = (void *)PyNumber_Subtract;\n multiply_data[9] = (void *)c_prod_;\n multiply_data[10] = (void *)c_prod_;\n multiply_data[11] = (void *)PyNumber_Multiply;\n divide_data[9] = (void *)c_quot_fast;\n divide_data[10] = (void *)c_quot_fast;\n divide_data[11] = (void *)PyNumber_Divide;\n /* need to add and worry \n divide_safe_data[9] = (void *)c_quot;\n divide_safe_data[10] = (void *)c_quot;\n divide_safe_data[11] = (void *)PyNumber_Divide;\n */\n conjugate_data[11] = (void *)\"conjugate\";\n remainder_data[7] = (void *)fmod;\n remainder_data[8] = (void *)fmod;\n remainder_data[9] = (void *)PyNumber_Remainder;\n power_data[7] = (void *)pow;\n power_data[8] = (void *)pow;\n power_data[9] = (void *)c_pow_;\n power_data[10] = (void *)c_pow_;\n power_data[11] = (void *)PyNumber_Power;\n absolute_data[11] = (void *)PyNumber_Absolute;\n negative_data[11] = (void *)PyNumber_Negative;\n bitwise_and_data[7] = (void *)PyNumber_And;\n bitwise_or_data[7] = (void *)PyNumber_Or;\n bitwise_xor_data[7] = (void *)PyNumber_Xor;\n invert_data[7] = (void *)PyNumber_Invert;\n left_shift_data[7] = (void *)PyNumber_Lshift;\n right_shift_data[7] = (void *)PyNumber_Rshift;\n\n add_functions[11] = PyUFunc_OO_O;\n subtract_functions[11] = PyUFunc_OO_O;\n multiply_functions[9] = fastumath_FF_F_As_DD_D;\n multiply_functions[10] = fastumath_DD_D;\n multiply_functions[11] = PyUFunc_OO_O;\n divide_functions[9] = fastumath_FF_F_As_DD_D;\n divide_functions[10] = fastumath_DD_D;\n divide_functions[11] = PyUFunc_OO_O;\n\n\n#if PY_VERSION_HEX >= 0x02020000\n true_divide_data[9] = (void *)c_quot_fast;\n true_divide_data[10] = (void *)c_quot_fast;\n true_divide_data[11] = (void *)PyNumber_TrueDivide;\n true_divide_functions[9] = fastumath_FF_F_As_DD_D;\n true_divide_functions[10] = fastumath_DD_D;\n true_divide_functions[11] = PyUFunc_OO_O;\n\n floor_divide_data[9] = (void *)c_quot_floor_fast;\n floor_divide_data[10] = (void *)c_quot_floor_fast;\n floor_divide_data[11] = (void *)PyNumber_FloorDivide;\n floor_divide_functions[9] = fastumath_FF_F_As_DD_D;\n floor_divide_functions[10] = fastumath_DD_D;\n floor_divide_functions[11] = PyUFunc_OO_O;\n#endif\n\n conjugate_functions[11] = PyUFunc_O_O_method;\n remainder_functions[7] = PyUFunc_ff_f_As_dd_d;\n remainder_functions[8] = PyUFunc_dd_d;\n remainder_functions[9] = PyUFunc_OO_O;\n power_functions[7] = PyUFunc_ff_f_As_dd_d;\n power_functions[8] = PyUFunc_dd_d;\n power_functions[9] = fastumath_FF_F_As_DD_D;\n power_functions[10] = fastumath_DD_D;\n power_functions[11] = PyUFunc_OO_O;\n absolute_functions[11] = PyUFunc_O_O;\n negative_functions[11] = PyUFunc_O_O;\n bitwise_and_functions[7] = PyUFunc_OO_O;\n bitwise_or_functions[7] = PyUFunc_OO_O;\n bitwise_xor_functions[7] = PyUFunc_OO_O;\n invert_functions[7] = PyUFunc_O_O;\n left_shift_functions[7] = PyUFunc_OO_O;\n right_shift_functions[7] = PyUFunc_OO_O;\n\n arccos_functions[0] = PyUFunc_f_f_As_d_d;\n arccos_functions[1] = PyUFunc_d_d;\n arccos_functions[2] = fastumath_F_F_As_D_D;\n arccos_functions[3] = fastumath_D_D;\n arccos_functions[4] = PyUFunc_O_O_method;\n ceil_functions[0] = PyUFunc_f_f_As_d_d;\n ceil_functions[1] = PyUFunc_d_d;\n ceil_functions[2] = PyUFunc_O_O_method;\n arctan2_functions[0] = PyUFunc_ff_f_As_dd_d;\n arctan2_functions[1] = PyUFunc_dd_d;\n arctan2_functions[2] = PyUFunc_O_O_method;\n\n\n f = PyUFunc_FromFuncAndData(isinf_functions, isinf_data, isinf_signatures, \n 4, 1, 1, PyUFunc_None, \"isinf\", \n \"isinf(x) returns non-zero if x is infinity.\", 0);\n PyDict_SetItemString(dictionary, \"isinf\", f);\n Py_DECREF(f);\n\n f = PyUFunc_FromFuncAndData(isfinite_functions, isfinite_data, isinf_signatures, \n 4, 1, 1, PyUFunc_None, \"isfinite\", \n \"isfinite(x) returns non-zero if x is not infinity or not a number.\", 0);\n PyDict_SetItemString(dictionary, \"isfinite\", f);\n Py_DECREF(f);\n\n f = PyUFunc_FromFuncAndData(isnan_functions, isnan_data, isinf_signatures, \n 4, 1, 1, PyUFunc_None, \"isnan\", \n \"isnan(x) returns non-zero if x is not a number.\", 0);\n PyDict_SetItemString(dictionary, \"isnan\", f);\n Py_DECREF(f);\n\n\n f = PyUFunc_FromFuncAndData(add_functions, add_data, add_signatures, 12, \n\t\t\t\t2, 1, PyUFunc_Zero, \"add\", \n\t\t\t\t\"Add the arguments elementwise.\", 0);\n PyDict_SetItemString(dictionary, \"add\", f);\n Py_DECREF(f);\n f = PyUFunc_FromFuncAndData(subtract_functions, subtract_data, add_signatures, \n\t\t\t\t12, 2, 1, PyUFunc_Zero, \"subtract\", \n\t\t\t\t\"Subtract the arguments elementwise.\", 0);\n PyDict_SetItemString(dictionary, \"subtract\", f);\n Py_DECREF(f);\n f = PyUFunc_FromFuncAndData(multiply_functions, multiply_data, add_signatures, \n\t\t\t\t12, 2, 1, PyUFunc_One, \"multiply\", \n\t\t\t\t\"Multiply the arguments elementwise.\", 0);\n PyDict_SetItemString(dictionary, \"multiply\", f);\n Py_DECREF(f);\n f = PyUFunc_FromFuncAndData(divide_functions, divide_data, add_signatures, \n\t\t\t\t12, 2, 1, PyUFunc_One, \"divide\", \n\t\t\t\t\"Divide the arguments elementwise.\", 0);\n PyDict_SetItemString(dictionary, \"divide\", f);\n Py_DECREF(f);\n#if PY_VERSION_HEX >= 0x02020000\n f = PyUFunc_FromFuncAndData(floor_divide_functions, floor_divide_data, floor_divide_signatures, \n\t\t\t\t12, 2, 1, PyUFunc_One, \"floor_divide\", \n\t\t\t\t\"Floor divide the arguments elementwise.\", 0);\n PyDict_SetItemString(dictionary, \"floor_divide\", f);\n Py_DECREF(f);\n f = PyUFunc_FromFuncAndData(true_divide_functions, true_divide_data, true_divide_signatures, \n\t\t\t\t12, 2, 1, PyUFunc_One, \"true_divide\", \n\t\t\t\t\"True divide the arguments elementwise.\", 0);\n PyDict_SetItemString(dictionary, \"true_divide\", f);\n Py_DECREF(f);\n#endif\n\n f = PyUFunc_FromFuncAndData(divide_safe_functions, divide_safe_data, divide_safe_signatures, \n\t\t\t\t9, 2, 1, PyUFunc_One, \"divide_safe\", \n\t\t\t\t\"Divide elementwise, ZeroDivision exception thrown if necessary.\", 0);\n PyDict_SetItemString(dictionary, \"divide_safe\", f);\n Py_DECREF(f);\n f = PyUFunc_FromFuncAndData(conjugate_functions, conjugate_data, conjugate_signatures, \n\t\t\t\t12, 1, 1, PyUFunc_None, \"conjugate\", \n\t\t\t\t\"returns conjugate of each element\", 0);\n PyDict_SetItemString(dictionary, \"conjugate\", f);\n Py_DECREF(f);\n f = PyUFunc_FromFuncAndData(remainder_functions, remainder_data, remainder_signatures, \n\t\t\t\t10, 2, 1, PyUFunc_Zero, \"remainder\", \n\t\t\t\t\"returns remainder of division elementwise\", 0);\n PyDict_SetItemString(dictionary, \"remainder\", f);\n Py_DECREF(f);\n f = PyUFunc_FromFuncAndData(power_functions, power_data, add_signatures, \n\t\t\t\t12, 2, 1, PyUFunc_One, \"power\", \n\t\t\t\t\"power(x,y) = x**y elementwise.\", 0);\n PyDict_SetItemString(dictionary, \"power\", f);\n Py_DECREF(f);\n f = PyUFunc_FromFuncAndData(absolute_functions, absolute_data, absolute_signatures, \n\t\t\t\t12, 1, 1, PyUFunc_None, \"absolute\", \n\t\t\t\t\"returns absolute value of each element\", 0);\n PyDict_SetItemString(dictionary, \"absolute\", f);\n Py_DECREF(f);\n f = PyUFunc_FromFuncAndData(negative_functions, negative_data, negative_signatures, \n\t\t\t\t12, 1, 1, PyUFunc_None, \"negative\", \n\t\t\t\t\"negative(x) == -x elementwise.\", 0);\n PyDict_SetItemString(dictionary, \"negative\", f);\n Py_DECREF(f);\n f = PyUFunc_FromFuncAndData(greater_functions, divide_safe_data, greater_signatures, \n\t\t\t\t11, 2, 1, PyUFunc_None, \"greater\", \n\t\t\t\t\"greater(x,y) is array of 1's where x > y, 0 otherwise.\",1);\n PyDict_SetItemString(dictionary, \"greater\", f);\n Py_DECREF(f);\n f = PyUFunc_FromFuncAndData(greater_equal_functions, divide_safe_data, greater_signatures, \n\t\t\t\t11, 2, 1, PyUFunc_None, \"greater_equal\", \n\t\t\t\t\"greater_equal(x,y) is array of 1's where x >=y, 0 otherwise.\", 0);\n PyDict_SetItemString(dictionary, \"greater_equal\", f);\n Py_DECREF(f);\n f = PyUFunc_FromFuncAndData(less_functions, divide_safe_data, greater_signatures, \n\t\t\t\t11, 2, 1, PyUFunc_None, \"less\", \n\t\t\t\t\"less(x,y) is array of 1's where x < y, 0 otherwise.\", 0);\n PyDict_SetItemString(dictionary, \"less\", f);\n Py_DECREF(f);\n f = PyUFunc_FromFuncAndData(less_equal_functions, divide_safe_data, greater_signatures, \n\t\t\t\t11, 2, 1, PyUFunc_None, \"less_equal\", \n\t\t\t\t\"less_equal(x,y) is array of 1's where x <= y, 0 otherwise.\", 0);\n PyDict_SetItemString(dictionary, \"less_equal\", f);\n Py_DECREF(f);\n f = PyUFunc_FromFuncAndData(equal_functions, equal_data, equal_signatures, \n\t\t\t\t13, 2, 1, PyUFunc_One, \"equal\", \n\t\t\t\t\"equal(x,y) is array of 1's where x == y, 0 otherwise.\", 0);\n PyDict_SetItemString(dictionary, \"equal\", f);\n Py_DECREF(f);\n f = PyUFunc_FromFuncAndData(not_equal_functions, equal_data, equal_signatures, \n\t\t\t\t13, 2, 1, PyUFunc_None, \"not_equal\", \n\t\t\t\t\"not_equal(x,y) is array of 0's where x == y, 1 otherwise.\", 0);\n PyDict_SetItemString(dictionary, \"not_equal\", f);\n Py_DECREF(f);\n f = PyUFunc_FromFuncAndData(logical_and_functions, divide_safe_data, logical_signatures, \n\t\t\t\t9, 2, 1, PyUFunc_One, \"logical_and\", \n\t\t\t\t\"logical_and(x,y) returns array of 1's where x and y both true.\", 0);\n PyDict_SetItemString(dictionary, \"logical_and\", f);\n Py_DECREF(f);\n f = PyUFunc_FromFuncAndData(logical_or_functions, divide_safe_data, logical_signatures, \n\t\t\t\t9, 2, 1, PyUFunc_Zero, \"logical_or\", \n\t\t\t\t\"logical_or(x,y) returns array of 1's where x or y or both are true.\", 0);\n PyDict_SetItemString(dictionary, \"logical_or\", f);\n Py_DECREF(f);\n f = PyUFunc_FromFuncAndData(logical_xor_functions, divide_safe_data, logical_signatures, \n\t\t\t\t9, 2, 1, PyUFunc_None, \"logical_xor\", \n\t\t\t\t\"logical_xor(x,y) returns array of 1's where exactly one of x or y is true.\", 0);\n PyDict_SetItemString(dictionary, \"logical_xor\", f);\n Py_DECREF(f);\n f = PyUFunc_FromFuncAndData(logical_not_functions, divide_safe_data, logical_not_signatures, \n\t\t\t\t9, 1, 1, PyUFunc_None, \"logical_not\", \n\t\t\t\t\"logical_not(x) returns array of 1's where x is false, 0 otherwise.\", 0);\n PyDict_SetItemString(dictionary, \"logical_not\", f);\n Py_DECREF(f);\n f = PyUFunc_FromFuncAndData(maximum_functions, divide_safe_data, maximum_signatures, \n\t\t\t\t11, 2, 1, PyUFunc_None, \"maximum\", \n\t\t\t\t\"maximum(x,y) returns maximum of x and y taken elementwise.\", 0);\n PyDict_SetItemString(dictionary, \"maximum\", f);\n Py_DECREF(f);\n f = PyUFunc_FromFuncAndData(minimum_functions, divide_safe_data, maximum_signatures,\n\t\t\t\t11, 2, 1, PyUFunc_None, \"minimum\", \n\t\t\t\t\"minimum(x,y) returns minimum of x and y taken elementwise.\", 0);\n PyDict_SetItemString(dictionary, \"minimum\", f);\n Py_DECREF(f);\n f = PyUFunc_FromFuncAndData(bitwise_and_functions, bitwise_and_data, bitwise_and_signatures, \n\t\t\t\t8, 2, 1, PyUFunc_One, \"bitwise_and\", \n\t\t\t\t\"bitwise_and(x,y) returns array of bitwise-and of respective elements.\", 0);\n PyDict_SetItemString(dictionary, \"bitwise_and\", f);\n Py_DECREF(f);\n f = PyUFunc_FromFuncAndData(bitwise_or_functions, bitwise_or_data, bitwise_and_signatures, \n\t\t\t\t8, 2, 1, PyUFunc_Zero, \"bitwise_or\", \n\t\t\t\t\"bitwise_or(x,y) returns array of bitwise-or of respective elements.\", 0);\n PyDict_SetItemString(dictionary, \"bitwise_or\", f);\n Py_DECREF(f);\n f = PyUFunc_FromFuncAndData(bitwise_xor_functions, bitwise_xor_data, bitwise_and_signatures, \n\t\t\t\t8, 2, 1, PyUFunc_None, \"bitwise_xor\", \n\t\t\t\t\"bitwise_xor(x,y) returns array of bitwise exclusive or of respective elements.\", 0);\n PyDict_SetItemString(dictionary, \"bitwise_xor\", f);\n Py_DECREF(f);\n f = PyUFunc_FromFuncAndData(invert_functions, invert_data, invert_signatures, \n\t\t\t\t8, 1, 1, PyUFunc_None, \"invert\", \n\t\t\t\t\"invert(n) returns array of bit inversion elementwise.\", 0);\n PyDict_SetItemString(dictionary, \"invert\", f);\n Py_DECREF(f);\n f = PyUFunc_FromFuncAndData(left_shift_functions, left_shift_data, bitwise_and_signatures, \n\t\t\t\t8, 2, 1, PyUFunc_None, \"left_shift\", \n\t\t\t\t\"left_shift(n, m) is n << m elementwise.\", 0);\n PyDict_SetItemString(dictionary, \"left_shift\", f);\n Py_DECREF(f);\n f = PyUFunc_FromFuncAndData(right_shift_functions, right_shift_data, bitwise_and_signatures, \n\t\t\t\t8, 2, 1, PyUFunc_None, \"right_shift\", \n\t\t\t\t\"right_shift(n, m) is n >> m elementwise.\", 0);\n PyDict_SetItemString(dictionary, \"right_shift\", f);\n Py_DECREF(f);\n\n f = PyUFunc_FromFuncAndData(arccos_functions, arccos_data, arccos_signatures, \n\t\t\t\t5, 1, 1, PyUFunc_None, \"arccos\", \n\t\t\t\t\"arccos(x) returns array of elementwise inverse cosines.\", 0);\n PyDict_SetItemString(dictionary, \"arccos\", f);\n Py_DECREF(f);\n f = PyUFunc_FromFuncAndData(arccos_functions, arcsin_data, arccos_signatures, \n\t\t\t\t5, 1, 1, PyUFunc_None, \"arcsin\", \n\t\t\t\t\"arcsin(x) returns array of elementwise inverse sines.\", 0);\n PyDict_SetItemString(dictionary, \"arcsin\", f);\n Py_DECREF(f);\n f = PyUFunc_FromFuncAndData(arccos_functions, arctan_data, arccos_signatures, \n\t\t\t\t5, 1, 1, PyUFunc_None, \"arctan\", \n\t\t\t\t\"arctan(x) returns array of elementwise inverse tangents.\", 0);\n PyDict_SetItemString(dictionary, \"arctan\", f);\n Py_DECREF(f);\n f = PyUFunc_FromFuncAndData(arccos_functions, arctanh_data, arccos_signatures, \n\t\t\t\t5, 1, 1, PyUFunc_None, \"arctanh\",\n\t\t\t\t\"arctanh(x) returns array of elementwise inverse hyperbolic tangents.\", 0);\n PyDict_SetItemString(dictionary, \"arctanh\", f);\n Py_DECREF(f);\n f = PyUFunc_FromFuncAndData(arccos_functions, arccosh_data, arccos_signatures, \n\t\t\t\t5, 1, 1, PyUFunc_None, \"arccosh\",\n\t\t\t\t\"arccosh(x) returns array of elementwise inverse hyperbolic cosines.\", 0);\n PyDict_SetItemString(dictionary, \"arccosh\", f);\n Py_DECREF(f);\n f = PyUFunc_FromFuncAndData(arccos_functions, arcsinh_data, arccos_signatures, \n\t\t\t\t5, 1, 1, PyUFunc_None, \"arcsinh\",\n\t\t\t\t\"arcsinh(x) returns array of elementwise inverse hyperbolic sines.\", 0);\n PyDict_SetItemString(dictionary, \"arcsinh\", f);\n Py_DECREF(f);\n f = PyUFunc_FromFuncAndData(arccos_functions, cos_data, arccos_signatures, \n\t\t\t\t5, 1, 1, PyUFunc_None, \"cos\", \n\t\t\t\t\"cos(x) returns array of elementwise cosines.\", 0);\n PyDict_SetItemString(dictionary, \"cos\", f);\n Py_DECREF(f);\n f = PyUFunc_FromFuncAndData(arccos_functions, cosh_data, arccos_signatures, \n\t\t\t\t5, 1, 1, PyUFunc_None, \"cosh\", \n\t\t\t\t\"cosh(x) returns array of elementwise hyberbolic cosines.\", 0);\n PyDict_SetItemString(dictionary, \"cosh\", f);\n Py_DECREF(f);\n f = PyUFunc_FromFuncAndData(arccos_functions, exp_data, arccos_signatures, \n\t\t\t\t5, 1, 1, PyUFunc_None, \"exp\", \n\t\t\t\t\"exp(x) returns array of elementwise e**x.\", 0);\n PyDict_SetItemString(dictionary, \"exp\", f);\n Py_DECREF(f);\n f = PyUFunc_FromFuncAndData(arccos_functions, log_data, arccos_signatures, \n\t\t\t\t5, 1, 1, PyUFunc_None, \"log\", \n\t\t\t\t\"log(x) returns array of elementwise natural logarithms.\", 0);\n PyDict_SetItemString(dictionary, \"log\", f);\n Py_DECREF(f);\n f = PyUFunc_FromFuncAndData(arccos_functions, log10_data, arccos_signatures, \n\t\t\t\t5, 1, 1, PyUFunc_None, \"log10\", \n\t\t\t\t\"log10(x) returns array of elementwise base-10 logarithms.\", 0);\n PyDict_SetItemString(dictionary, \"log10\", f);\n Py_DECREF(f);\n f = PyUFunc_FromFuncAndData(arccos_functions, sin_data, arccos_signatures, \n\t\t\t\t5, 1, 1, PyUFunc_None, \"sin\", \n\t\t\t\t\"sin(x) returns array of elementwise sines.\", 0);\n PyDict_SetItemString(dictionary, \"sin\", f);\n Py_DECREF(f);\n f = PyUFunc_FromFuncAndData(arccos_functions, sinh_data, arccos_signatures, \n\t\t\t\t5, 1, 1, PyUFunc_None, \"sinh\", \n\t\t\t\t\"sinh(x) returns array of elementwise hyperbolic sines.\", 0);\n PyDict_SetItemString(dictionary, \"sinh\", f);\n Py_DECREF(f);\n f = PyUFunc_FromFuncAndData(arccos_functions, sqrt_data, arccos_signatures, \n\t\t\t\t5, 1, 1, PyUFunc_None, \"sqrt\",\n\t\t\t\t\"sqrt(x) returns array of elementwise square roots.\", 0);\n PyDict_SetItemString(dictionary, \"sqrt\", f);\n Py_DECREF(f);\n f = PyUFunc_FromFuncAndData(arccos_functions, tan_data, arccos_signatures, \n\t\t\t\t5, 1, 1, PyUFunc_None, \"tan\", \n\t\t\t\t\"tan(x) returns array of elementwise tangents.\", 0);\n PyDict_SetItemString(dictionary, \"tan\", f);\n Py_DECREF(f);\n f = PyUFunc_FromFuncAndData(arccos_functions, tanh_data, arccos_signatures, \n\t\t\t\t5, 1, 1, PyUFunc_None, \"tanh\", \n\t\t\t\t\"tanh(x) returns array of elementwise hyperbolic tangents.\", 0);\n PyDict_SetItemString(dictionary, \"tanh\", f);\n Py_DECREF(f);\n f = PyUFunc_FromFuncAndData(ceil_functions, ceil_data, ceil_signatures, \n\t\t\t\t3, 1, 1, PyUFunc_None, \"ceil\", \n\t\t\t\t\"ceil(x) returns array of elementwise least whole number >= x.\", 0);\n PyDict_SetItemString(dictionary, \"ceil\", f);\n Py_DECREF(f);\n f = PyUFunc_FromFuncAndData(ceil_functions, fabs_data, ceil_signatures, \n\t\t\t\t3, 1, 1, PyUFunc_None, \"fabs\", \n\t\t\t\t\"fabs(x) returns array of elementwise absolute values, 32 bit if x is.\", 0);\n\n PyDict_SetItemString(dictionary, \"fabs\", f);\n Py_DECREF(f);\n f = PyUFunc_FromFuncAndData(ceil_functions, floor_data, ceil_signatures, \n\t\t\t\t3, 1, 1, PyUFunc_None, \"floor\", \n\t\t\t\t\"floor(x) returns array of elementwise least whole number <= x.\", 0);\n PyDict_SetItemString(dictionary, \"floor\", f);\n Py_DECREF(f);\n f = PyUFunc_FromFuncAndData(arctan2_functions, arctan2_data, arctan2_signatures, \n\t\t\t\t3, 2, 1, PyUFunc_None, \"arctan2\", \n\t\t\t\t\"arctan2(x,y) is a safe and correct tan(x/y).\", 0);\n PyDict_SetItemString(dictionary, \"arctan2\", f);\n Py_DECREF(f);\n f = PyUFunc_FromFuncAndData(arctan2_functions, fmod_data, arctan2_signatures, \n\t\t\t\t3, 2, 1, PyUFunc_None, \"fmod\", \n\t\t\t\t\"fmod(x,y) is remainder(x,y)\", 0);\n PyDict_SetItemString(dictionary, \"fmod\", f);\n Py_DECREF(f);\n f = PyUFunc_FromFuncAndData(arctan2_functions, hypot_data, arctan2_signatures, \n\t\t\t\t3, 2, 1, PyUFunc_None, \"hypot\", \n\t\t\t\t\"hypot(x,y) = sqrt(x**2 + y**2), elementwise.\", 0);\n PyDict_SetItemString(dictionary, \"hypot\", f);\n Py_DECREF(f);\n}\n\n\n", "source_code_before": "/* -*- c -*- */\n/* Fast umath module whose functions do not check for range and domain errors.\n\n Replacement for umath + additions for isnan, isfinite, and isinf\n Also allows comparison operations on complex numbers (just compares the \n real part) and logical operations.\n\n All logical operations return UBYTE arrays.\n\n This version supports unsigned types. \n */\n\n#ifndef CHAR_BIT\n#define CHAR_BIT 8\n#endif\n\n#ifndef LONG_BIT\n#define LONG_BIT (CHAR_BIT * sizeof(long))\n#endif\n\n#ifndef INT_BIT\n#define INT_BIT (CHAR_BIT * sizeof(int))\n#endif\n\n#ifndef SHORT_BIT\n#define SHORT_BIT (CHAR_BIT * sizeof(short))\n#endif\n\n#ifndef UINT_BIT\n#define UINT_BIT (CHAR_BIT * sizeof(unsigned int))\n#endif\n\n#ifndef USHORT_BIT\n#define USHORT_BIT (CHAR_BIT * sizeof(unsigned short))\n#endif\n\n/* A whole slew of basic math functions are provided 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\n#ifndef M_PI\n#define M_PI 3.1415926535897931\n#endif\n\n#define ABS(x) ((x) < 0 ? -(x) : (x))\n\n/* isnan and isinf and isfinite functions */\nstatic void FLOAT_isnan(char **args, int *dimensions, int *steps, void *func) {\n int i, is1=steps[0], os=steps[1], n=dimensions[0];\n char *i1=args[0], *op=args[1];\n for (i=0; i < n; i++, i1+=is1, op+=os) {\n\t*((unsigned char *)op) = (unsigned char) ABS(isnan((double)(*((float *)i1))));\n }\n}\n\nstatic void DOUBLE_isnan(char **args, int *dimensions, int *steps, void *func) {\n int i, is1=steps[0], os=steps[1], n=dimensions[0];\n char *i1=args[0], *op=args[1];\n for (i=0; i < n; i++, i1+=is1, op+=os) {\n\t*((unsigned char *)op) = (unsigned char) ABS(isnan((double)(*((double *)i1))));\n }\n}\n\nstatic void CFLOAT_isnan(char **args, int *dimensions, int *steps, void *func) {\n int i, is1=steps[0], os=steps[1], n=dimensions[0];\n char *i1=args[0], *op=args[1];\n for (i=0; i < n; i++, i1+=is1, op+=os) {\n\t*((unsigned char *)op) = (unsigned char) isnan((double)((float *)i1)[0]) || isnan((double)((float *)i1)[1]);\n }\n}\n\nstatic void CDOUBLE_isnan(char **args, int *dimensions, int *steps, void *func) {\n int i, is1=steps[0], os=steps[1], n=dimensions[0];\n char *i1=args[0], *op=args[1];\n for (i=0; i < n; i++, i1+=is1, op+=os) {\n\t*((unsigned char *)op) = (unsigned char) isnan((double)((double *)i1)[0]) || isnan((double)((double *)i1)[1]);\n }\n}\n\n\nstatic void FLOAT_isinf(char **args, int *dimensions, int *steps, void *func) {\n int i, is1=steps[0], os=steps[1], n=dimensions[0];\n char *i1=args[0], *op=args[1];\n for (i=0; i < n; i++, i1+=is1, op+=os) {\n\t*((unsigned char *)op) = (unsigned char) !(isfinite((double)(*((float *)i1))) || isnan((double)(*((float *)i1))));\n }\n}\n\nstatic void DOUBLE_isinf(char **args, int *dimensions, int *steps, void *func) {\n int i, is1=steps[0], os=steps[1], n=dimensions[0];\n char *i1=args[0], *op=args[1];\n for (i=0; i < n; i++, i1+=is1, op+=os) {\n\t*((unsigned char *)op)= (unsigned char) !(isfinite((double)(*((double *)i1))) || isnan((double)(*((double *)i1))));\n }\n}\n\nstatic void CFLOAT_isinf(char **args, int *dimensions, int *steps, void *func) {\n int i, is1=steps[0], os=steps[1], n=dimensions[0];\n char *i1=args[0], *op=args[1];\n for (i=0; i < n; i++, i1+=is1, op+=os) {\n\t*((unsigned char *)op)= (unsigned char) !((isfinite((double)(((float *)i1)[0])) && isfinite((double)(((float *)i1)[1]))) || isnan((double)(((float *)i1)[0])) || isnan((double)(((float *)i1)[1])));\n }\n}\n\nstatic void CDOUBLE_isinf(char **args, int *dimensions, int *steps, void *func) {\n int i, is1=steps[0], os=steps[1], n=dimensions[0];\n char *i1=args[0], *op=args[1];\n for (i=0; i < n; i++, i1+=is1, op+=os) {\n\t*((unsigned char *)op)= (unsigned char) !((isfinite((double)(((double *)i1)[0])) && isfinite((double)(((double *)i1)[1]))) || isnan((double)(((double *)i1)[0])) || isnan((double)(((double *)i1)[1])));\n }\n}\n\n\nstatic void FLOAT_isfinite(char **args, int *dimensions, int *steps, void *func) {\n int i, is1=steps[0], os=steps[1], n=dimensions[0];\n char *i1=args[0], *op=args[1];\n for (i=0; i < n; i++, i1+=is1, op+=os) {\n\t*((unsigned char *)op) = (unsigned char) isfinite((double)(*((float *)i1)));\n }\n}\n\nstatic void DOUBLE_isfinite(char **args, int *dimensions, int *steps, void *func) {\n int i, is1=steps[0], os=steps[1], n=dimensions[0];\n char *i1=args[0], *op=args[1];\n for (i=0; i < n; i++, i1+=is1, op+=os) {\n\t*((unsigned char *)op) = (unsigned char) isfinite((double)(*((double *)i1)));\n }\n}\n\nstatic void CFLOAT_isfinite(char **args, int *dimensions, int *steps, void *func) {\n int i, is1=steps[0], os=steps[1], n=dimensions[0];\n char *i1=args[0], *op=args[1];\n for (i=0; i < n; i++, i1+=is1, op+=os) {\n\t*((unsigned char *)op) = (unsigned char) isfinite((double)((float *)i1)[0]) && isfinite((double)((float *)i1)[1]);\n }\n}\n\nstatic void CDOUBLE_isfinite(char **args, int *dimensions, int *steps, void *func) {\n int i, is1=steps[0], os=steps[1], n=dimensions[0];\n char *i1=args[0], *op=args[1];\n for (i=0; i < n; i++, i1+=is1, op+=os) {\n\t*((unsigned char *)op) = (unsigned char) isfinite((double)((double *)i1)[0]) && isfinite((double)((double *)i1)[1]);\n }\n}\n\nstatic PyUFuncGenericFunction isnan_functions[] = {FLOAT_isnan, DOUBLE_isnan, CFLOAT_isnan, CDOUBLE_isnan, NULL};\nstatic PyUFuncGenericFunction isinf_functions[] = {FLOAT_isinf, DOUBLE_isinf, CFLOAT_isinf, CDOUBLE_isinf, NULL};\nstatic PyUFuncGenericFunction isfinite_functions[] = {FLOAT_isfinite, DOUBLE_isfinite, CFLOAT_isfinite, CDOUBLE_isfinite, NULL};\n\nstatic char isinf_signatures[] = { PyArray_FLOAT, PyArray_UBYTE, PyArray_DOUBLE, PyArray_UBYTE, PyArray_CFLOAT, PyArray_UBYTE, PyArray_CDOUBLE, PyArray_UBYTE, };\n\nstatic void * isnan_data[] = {(void *)NULL, (void *)NULL, (void *)NULL, (void *)NULL};\nstatic void * isinf_data[] = {(void *)NULL, (void *)NULL, (void *)NULL, (void *)NULL};\nstatic void * isfinite_data[] = {(void *)NULL, (void *)NULL, (void *)NULL, (void *)NULL};\n\n\n\n/* Some functions needed from ufunc object, so that Py_complex's aren't being returned \nbetween code possibly compiled with different compilers.\n*/\n\ntypedef Py_complex ComplexBinaryFunc(Py_complex x, Py_complex y);\ntypedef Py_complex ComplexUnaryFunc(Py_complex x);\n\nstatic void fastumath_F_F_As_D_D(char **args, int *dimensions, int *steps, void *func) {\n int i; Py_complex x;\n char *ip1=args[0], *op=args[1];\n for(i=0; i<*dimensions; i++, ip1+=steps[0], op+=steps[1]) {\n\tx.real = ((float *)ip1)[0]; x.imag = ((float *)ip1)[1];\n\tx = ((ComplexUnaryFunc *)func)(x);\n\t((float *)op)[0] = (float)x.real;\n\t((float *)op)[1] = (float)x.imag;\n }\n}\n\nstatic void fastumath_D_D(char **args, int *dimensions, int *steps, void *func) {\n int i; Py_complex x;\n char *ip1=args[0], *op=args[1];\n for(i=0; i<*dimensions; i++, ip1+=steps[0], op+=steps[1]) {\n\tx.real = ((double *)ip1)[0]; x.imag = ((double *)ip1)[1];\n\tx = ((ComplexUnaryFunc *)func)(x);\n\t((double *)op)[0] = x.real;\n\t((double *)op)[1] = x.imag;\n }\n}\n\n\nstatic void fastumath_FF_F_As_DD_D(char **args, int *dimensions, int *steps, void *func) {\n int i, is1=steps[0],is2=steps[1],os=steps[2];\n char *ip1=args[0], *ip2=args[1], *op=args[2];\n int n=dimensions[0];\n Py_complex x, y;\n\t\n for(i=0; i nbits. */\n{\n long r = 1;\n long p = x;\n double logtwox;\n long mask = 1;\n if (n < 0) PyErr_SetString(PyExc_ValueError, \"Integer to a negative power\");\n if (x != 0) {\n\tlogtwox = log10 (fabs ( (double) x))/log10 ( (double) 2.0);\n\tif (logtwox * (double) n > (double) nbits)\n\t PyErr_SetString(PyExc_ArithmeticError, \"Integer overflow in power.\");\n }\n while (mask > 0 && n >= mask) {\n\tif (n & mask)\n\t r *= p;\n\tmask <<= 1;\n\tp *= p;\n }\n return r;\n}\n\n\nstatic void UBYTE_add(char **args, int *dimensions, int *steps, void *func) {\n int i, is1=steps[0],is2=steps[1],os=steps[2], n=dimensions[0];\n char *i1=args[0], *i2=args[1], *op=args[2];\n for(i=0; i 255) {\n\t PyErr_SetString (PyExc_ArithmeticError, \"Integer overflow in multiply.\");\n\t return;\n\t}\n\t*((unsigned char *)op)=(unsigned char) x;\n }\n}\nstatic void SBYTE_multiply(char **args, int *dimensions, int *steps, void *func) {\n int i, is1=steps[0],is2=steps[1],os=steps[2], n=dimensions[0];\n char *i1=args[0], *i2=args[1], *op=args[2];\n int x;\n for(i=0; i 127 || x < -128) {\n\t PyErr_SetString (PyExc_ArithmeticError, \"Integer overflow in multiply.\");\n\t return;\n\t}\n\t*((signed char *)op)=(signed char) x;\n }\n}\nstatic void SHORT_multiply(char **args, int *dimensions, int *steps, void *func) {\n int i, is1=steps[0],is2=steps[1],os=steps[2], n=dimensions[0];\n char *i1=args[0], *i2=args[1], *op=args[2];\n short a, b, ah, bh, x, y;\n int s;\n for(i=0; i> (SHORT_BIT/2);\n\tbh = b >> (SHORT_BIT/2);\n\t/* Quick test for common case: two small positive shorts */\n\tif (ah == 0 && bh == 0) {\n\t if ((x=a*b) < 0) {\n\t\tPyErr_SetString (PyExc_ArithmeticError, \"Integer overflow in multiply.\");\n\t\treturn;\n\t }\n\t else {\n\t\t*((short *)op)=x;\n\t\tcontinue;\n\t }\n\t}\n\t/* Arrange that a >= b >= 0 */\n\tif (a < 0) {\n\t a = -a;\n\t if (a < 0) {\n\t\t/* Largest negative */\n\t\tif (b == 0 || b == 1) {\n\t\t *((short *)op)=a*b;\n\t\t continue;\n\t\t}\n\t\telse {\n\t\t PyErr_SetString (PyExc_ArithmeticError, \"Integer overflow in multiply.\");\n\t\t return;\n\t\t}\n\t }\n\t s = -s;\n\t ah = a >> (SHORT_BIT/2);\n\t}\n\tif (b < 0) {\n\t b = -b;\n\t if (b < 0) {\n\t\t/* Largest negative */\n\t\tif (a == 0 || a == 1) {\n\t\t *((short *)op)=a*b;\n\t\t continue;\n\t\t}\n\t\telse {\n\t\t PyErr_SetString (PyExc_ArithmeticError, \"Integer overflow in multiply.\");\n\t\t return;\n\t\t}\n\t }\n\t s = -s;\n\t bh = b >> (SHORT_BIT/2);\n\t}\n\t/* 1) both ah and bh > 0 : then report overflow */\n\tif (ah != 0 && bh != 0) {\n\t PyErr_SetString (PyExc_ArithmeticError, \"Integer overflow in multiply.\");\n\t return;\n\t}\n\t/* 2) both ah and bh = 0 : then compute a*b and report\n\t overflow if it comes out negative */\n\tif (ah == 0 && bh == 0) {\n\t if ((x=a*b) < 0) {\n\t\tPyErr_SetString (PyExc_ArithmeticError, \"Integer overflow in multiply.\");\n\t\treturn;\n\t }\n\t else {\n\t\t*((short *)op)=s * x;\n\t\tcontinue;\n\t }\n\t}\n\tif (a < b) {\n\t /* Swap */\n\t x = a;\n\t a = b;\n\t b = x;\n\t ah = bh;\n\t /* bh not used beyond this point */\n\t}\n\t/* 3) ah > 0 and bh = 0 : compute ah*bl and report overflow if\n\t it's >= 2^31\n\t compute al*bl and report overflow if it's negative\n\t add (ah*bl)<<32 to al*bl and report overflow if\n\t it's negative\n\t (NB b == bl in this case, and we make a = al) */\n\ty = ah*b;\n\tif (y >= (1 << (SHORT_BIT/2 - 1))) {\n\t PyErr_SetString (PyExc_ArithmeticError, \"Integer overflow in multiply.\");\n\t return;\n\t}\n\ta &= (1 << (SHORT_BIT/2)) - 1;\n\tx = a*b;\n\tif (x < 0) {\n\t PyErr_SetString (PyExc_ArithmeticError, \"Integer overflow in multiply.\");\n\t return;\n\t}\n\tx += y << (SHORT_BIT/2);\n\tif (x < 0) {\n\t PyErr_SetString (PyExc_ArithmeticError, \"Integer overflow in multiply.\");\n\t return;\n\t}\n\t*((short *)op)=s*x;\n }\n}\nstatic void USHORT_multiply(char **args, int *dimensions, int *steps, void *func) {\n int i, is1=steps[0],is2=steps[1],os=steps[2], n=dimensions[0];\n char *i1=args[0], *i2=args[1], *op=args[2];\n unsigned int x;\n for(i=0; i 65535) {\n\t PyErr_SetString (PyExc_ArithmeticError, \"Integer overflow in multiply.\");\n\t return;\n\t}\n\t*((unsigned short *)op)=(unsigned short) x;\n }\n}\nstatic void INT_multiply(char **args, int *dimensions, int *steps, void *func) {\n int i, is1=steps[0],is2=steps[1],os=steps[2], n=dimensions[0];\n char *i1=args[0], *i2=args[1], *op=args[2];\n int a, b, ah, bh, x, y;\n int s;\n for(i=0; i> (INT_BIT/2);\n\tbh = b >> (INT_BIT/2);\n\t/* Quick test for common case: two small positive ints */\n\tif (ah == 0 && bh == 0) {\n\t if ((x=a*b) < 0) {\n\t\tPyErr_SetString (PyExc_ArithmeticError, \"Integer overflow in multiply.\");\n\t\treturn;\n\t }\n\t else {\n\t\t*((int *)op)=x;\n\t\tcontinue;\n\t }\n\t}\n\t/* Arrange that a >= b >= 0 */\n\tif (a < 0) {\n\t a = -a;\n\t if (a < 0) {\n\t\t/* Largest negative */\n\t\tif (b == 0 || b == 1) {\n\t\t *((int *)op)=a*b;\n\t\t continue;\n\t\t}\n\t\telse {\n\t\t PyErr_SetString (PyExc_ArithmeticError, \"Integer overflow in multiply.\");\n\t\t return;\n\t\t}\n\t }\n\t s = -s;\n\t ah = a >> (INT_BIT/2);\n\t}\n\tif (b < 0) {\n\t b = -b;\n\t if (b < 0) {\n\t\t/* Largest negative */\n\t\tif (a == 0 || a == 1) {\n\t\t *((int *)op)=a*b;\n\t\t continue;\n\t\t}\n\t\telse {\n\t\t PyErr_SetString (PyExc_ArithmeticError, \"Integer overflow in multiply.\");\n\t\t return;\n\t\t}\n\t }\n\t s = -s;\n\t bh = b >> (INT_BIT/2);\n\t}\n\t/* 1) both ah and bh > 0 : then report overflow */\n\tif (ah != 0 && bh != 0) {\n\t PyErr_SetString (PyExc_ArithmeticError, \"Integer overflow in multiply.\");\n\t return;\n\t}\n\t/* 2) both ah and bh = 0 : then compute a*b and report\n\t overflow if it comes out negative */\n\tif (ah == 0 && bh == 0) {\n\t if ((x=a*b) < 0) {\n\t\tPyErr_SetString (PyExc_ArithmeticError, \"Integer overflow in multiply.\");\n\t\treturn;\n\t }\n\t else {\n\t\t*((int *)op)=s * x;\n\t\tcontinue;\n\t }\n\t}\n\tif (a < b) {\n\t /* Swap */\n\t x = a;\n\t a = b;\n\t b = x;\n\t ah = bh;\n\t /* bh not used beyond this point */\n\t}\n\t/* 3) ah > 0 and bh = 0 : compute ah*bl and report overflow if\n\t it's >= 2^31\n\t compute al*bl and report overflow if it's negative\n\t add (ah*bl)<<32 to al*bl and report overflow if\n\t it's negative\n\t (NB b == bl in this case, and we make a = al) */\n\ty = ah*b;\n\tif (y >= (1 << (INT_BIT/2 - 1))) {\n\t PyErr_SetString (PyExc_ArithmeticError, \"Integer overflow in multiply.\");\n\t return;\n\t}\n\ta &= (1 << (INT_BIT/2)) - 1;\n\tx = a*b;\n\tif (x < 0) {\n\t PyErr_SetString (PyExc_ArithmeticError, \"Integer overflow in multiply.\");\n\t return;\n\t}\n\tx += y << (INT_BIT/2);\n\tif (x < 0) {\n\t PyErr_SetString (PyExc_ArithmeticError, \"Integer overflow in multiply.\");\n\t return;\n\t}\n\t*((int *)op)=s*x;\n }\n}\nstatic void UINT_multiply(char **args, int *dimensions, int *steps, void *func) {\n int i, is1=steps[0],is2=steps[1],os=steps[2], n=dimensions[0];\n char *i1=args[0], *i2=args[1], *op=args[2];\n unsigned int a, b, ah, bh, x, y;\n for(i=0; i> (INT_BIT/2);\n\tbh = b >> (INT_BIT/2);\n\t/* Quick test for common case: two small positive ints */\n\tif (ah == 0 && bh == 0) { /* result should fit into bits available. */\n\t x = a*b;\n *((unsigned int *)op)=x;\n continue;\n }\n\t/* 1) both ah and bh > 0 : then report overflow */\n\tif (ah != 0 && bh != 0) {\n\t PyErr_SetString (PyExc_ArithmeticError, \"Integer overflow in multiply.\");\n\t return;\n\t}\n /* Otherwise one and only one of ah or bh is non-zero. Make it so a > b (ah >0 and bh=0) */\n\tif (a < b) { \n\t /* Swap */\n\t x = a;\n\t a = b;\n\t b = x;\n\t ah = bh;\n\t /* bh not used beyond this point */\n\t}\n /* Now a = ah */\n\t/* 3) ah > 0 and bh = 0 : compute ah*bl and report overflow if\n\t it's >= 2^(INT_BIT/2) -- shifted_version won't fit in unsigned int.\n\n Then compute al*bl (this should fit in the allotated space)\n\n\t compute al*bl and report overflow if it's negative\n\t add (ah*bl)<<32 to al*bl and report overflow if\n\t it's negative\n\t (NB b == bl in this case, and we make a = al) */\n\ty = ah*b;\n\tif (y >= (1 << (INT_BIT/2))) {\n\t PyErr_SetString (PyExc_ArithmeticError, \"Integer overflow in multiply.\");\n\t return;\n\t}\n\ta &= (1 << (INT_BIT/2)) - 1; /* mask off ah so a is now al */\n\tx = a*b; /* al * bl */\n\tx += y << (INT_BIT/2); /* add ah * bl * 2^SHIFT */\n /* This could have caused overflow. One way to know is to check to see if x < al \n Not sure if this get's all cases */\n\tif (x < a) {\n\t PyErr_SetString (PyExc_ArithmeticError, \"Integer overflow in multiply.\");\n\t return;\n\t}\n\t*((unsigned int *)op)=x;\n }\n}\nstatic void LONG_multiply(char **args, int *dimensions, int *steps, void *func) {\n int i, is1=steps[0],is2=steps[1],os=steps[2], n=dimensions[0];\n char *i1=args[0], *i2=args[1], *op=args[2];\n long a, b, ah, bh, x, y;\n int s;\n for(i=0; i> (LONG_BIT/2);\n\tbh = b >> (LONG_BIT/2);\n\t/* Quick test for common case: two small positive ints */\n\tif (ah == 0 && bh == 0) {\n\t if ((x=a*b) < 0) {\n\t\tPyErr_SetString (PyExc_ArithmeticError, \"Integer overflow in multiply.\");\n\t\treturn;\n\t }\n\t else {\n\t\t*((long *)op)=x;\n\t\tcontinue;\n\t }\n\t}\n\t/* Arrange that a >= b >= 0 */\n\tif (a < 0) {\n\t a = -a;\n\t if (a < 0) {\n\t\t/* Largest negative */\n\t\tif (b == 0 || b == 1) {\n\t\t *((long *)op)=a*b;\n\t\t continue;\n\t\t}\n\t\telse {\n\t\t PyErr_SetString (PyExc_ArithmeticError, \"Integer overflow in multiply.\");\n\t\t return;\n\t\t}\n\t }\n\t s = -s;\n\t ah = a >> (LONG_BIT/2);\n\t}\n\tif (b < 0) {\n\t b = -b;\n\t if (b < 0) {\n\t\t/* Largest negative */\n\t\tif (a == 0 || a == 1) {\n\t\t *((long *)op)=a*b;\n\t\t continue;\n\t\t}\n\t\telse {\n\t\t PyErr_SetString (PyExc_ArithmeticError, \"Integer overflow in multiply.\");\n\t\t return;\n\t\t}\n\t }\n\t s = -s;\n\t bh = b >> (LONG_BIT/2);\n\t}\n\t/* 1) both ah and bh > 0 : then report overflow */\n\tif (ah != 0 && bh != 0) {\n\t PyErr_SetString (PyExc_ArithmeticError, \"Integer overflow in multiply.\");\n\t return;\n\t}\n\t/* 2) both ah and bh = 0 : then compute a*b and report\n\t overflow if it comes out negative */\n\tif (ah == 0 && bh == 0) {\n\t if ((x=a*b) < 0) {\n\t\tPyErr_SetString (PyExc_ArithmeticError, \"Integer overflow in multiply.\");\n\t\treturn;\n\t }\n\t else {\n\t\t*((long *)op)=s * x;\n\t\tcontinue;\n\t }\n\t}\n\tif (a < b) {\n\t /* Swap */\n\t x = a;\n\t a = b;\n\t b = x;\n\t ah = bh;\n\t /* bh not used beyond this point */\n\t}\n\t/* 3) ah > 0 and bh = 0 : compute ah*bl and report overflow if\n\t it's >= 2^31\n\t compute al*bl and report overflow if it's negative\n\t add (ah*bl)<<32 to al*bl and report overflow if\n\t it's negative\n\t (NB b == bl in this case, and we make a = al) */\n\ty = ah*b;\n\tif (y >= (1L << (LONG_BIT/2 - 1))) {\n\t PyErr_SetString (PyExc_ArithmeticError, \"Integer overflow in multiply.\");\n\t return;\n\t}\n\ta &= (1L << (LONG_BIT/2)) - 1;\n\tx = a*b;\n\tif (x < 0) {\n\t PyErr_SetString (PyExc_ArithmeticError, \"Integer overflow in multiply.\");\n\t return;\n\t}\n\tx += y << (LONG_BIT/2);\n\tif (x < 0) {\n\t PyErr_SetString (PyExc_ArithmeticError, \"Integer overflow in multiply.\");\n\t return;\n\t}\n\t*((long *)op)=s*x;\n }\n}\nstatic void FLOAT_multiply(char **args, int *dimensions, int *steps, void *func) {\n int i, is1=steps[0],is2=steps[1],os=steps[2], n=dimensions[0];\n char *i1=args[0], *i2=args[1], *op=args[2];\n for(i=0; i= 0x02020000\nstatic void UBYTE_floor_divide(char **args, int *dimensions, int *steps, void *func) {\n int i, is1=steps[0],is2=steps[1],os=steps[2], n=dimensions[0];\n char *i1=args[0], *i2=args[1], *op=args[2];\n for(i=0; i *((unsigned char *)i2);\n }\n}\nstatic void SBYTE_greater(char **args, int *dimensions, int *steps, void *func) {\n int i, is1=steps[0],is2=steps[1],os=steps[2], n=dimensions[0];\n char *i1=args[0], *i2=args[1], *op=args[2];\n for(i=0; i *((signed char *)i2);\n }\n}\nstatic void SHORT_greater(char **args, int *dimensions, int *steps, void *func) {\n int i, is1=steps[0],is2=steps[1],os=steps[2], n=dimensions[0];\n char *i1=args[0], *i2=args[1], *op=args[2];\n for(i=0; i *((short *)i2);\n }\n}\nstatic void USHORT_greater(char **args, int *dimensions, int *steps, void *func) {\n int i, is1=steps[0],is2=steps[1],os=steps[2], n=dimensions[0];\n char *i1=args[0], *i2=args[1], *op=args[2];\n for(i=0; i *((unsigned short *)i2);\n }\n}\nstatic void INT_greater(char **args, int *dimensions, int *steps, void *func) {\n int i, is1=steps[0],is2=steps[1],os=steps[2], n=dimensions[0];\n char *i1=args[0], *i2=args[1], *op=args[2];\n for(i=0; i *((int *)i2);\n }\n}\nstatic void UINT_greater(char **args, int *dimensions, int *steps, void *func) {\n int i, is1=steps[0],is2=steps[1],os=steps[2], n=dimensions[0];\n char *i1=args[0], *i2=args[1], *op=args[2];\n for(i=0; i *((unsigned int *)i2);\n }\n}\nstatic void LONG_greater(char **args, int *dimensions, int *steps, void *func) {\n int i, is1=steps[0],is2=steps[1],os=steps[2], n=dimensions[0];\n char *i1=args[0], *i2=args[1], *op=args[2];\n for(i=0; i *((long *)i2);\n }\n}\nstatic void FLOAT_greater(char **args, int *dimensions, int *steps, void *func) {\n int i, is1=steps[0],is2=steps[1],os=steps[2], n=dimensions[0];\n char *i1=args[0], *i2=args[1], *op=args[2];\n for(i=0; i *((float *)i2);\n }\n}\nstatic void DOUBLE_greater(char **args, int *dimensions, int *steps, void *func) {\n int i, is1=steps[0],is2=steps[1],os=steps[2], n=dimensions[0];\n char *i1=args[0], *i2=args[1], *op=args[2];\n for(i=0; i *((double *)i2);\n }\n}\n\n/* complex numbers are compared by there real parts. */\nstatic void CFLOAT_greater(char **args, int *dimensions, int *steps, void *func) {\n int i, is1=steps[0],is2=steps[1],os=steps[2], n=dimensions[0];\n char *i1=args[0], *i2=args[1], *op=args[2];\n for(i=0; i ((float *)i2)[0];\n }\n}\nstatic void CDOUBLE_greater(char **args, int *dimensions, int *steps, void *func) {\n int i, is1=steps[0],is2=steps[1],os=steps[2], n=dimensions[0];\n char *i1=args[0], *i2=args[1], *op=args[2];\n for(i=0; i ((double *)i2)[0];\n }\n}\n\nstatic void UBYTE_greater_equal(char **args, int *dimensions, int *steps, void *func) {\n int i, is1=steps[0],is2=steps[1],os=steps[2], n=dimensions[0];\n char *i1=args[0], *i2=args[1], *op=args[2];\n for(i=0; i= *((unsigned char *)i2);\n }\n}\nstatic void SBYTE_greater_equal(char **args, int *dimensions, int *steps, void *func) {\n int i, is1=steps[0],is2=steps[1],os=steps[2], n=dimensions[0];\n char *i1=args[0], *i2=args[1], *op=args[2];\n for(i=0; i= *((signed char *)i2);\n }\n}\nstatic void SHORT_greater_equal(char **args, int *dimensions, int *steps, void *func) {\n int i, is1=steps[0],is2=steps[1],os=steps[2], n=dimensions[0];\n char *i1=args[0], *i2=args[1], *op=args[2];\n for(i=0; i= *((short *)i2);\n }\n}\nstatic void USHORT_greater_equal(char **args, int *dimensions, int *steps, void *func) {\n int i, is1=steps[0],is2=steps[1],os=steps[2], n=dimensions[0];\n char *i1=args[0], *i2=args[1], *op=args[2];\n for(i=0; i= *((unsigned short *)i2);\n }\n}\nstatic void INT_greater_equal(char **args, int *dimensions, int *steps, void *func) {\n int i, is1=steps[0],is2=steps[1],os=steps[2], n=dimensions[0];\n char *i1=args[0], *i2=args[1], *op=args[2];\n for(i=0; i= *((int *)i2);\n }\n}\nstatic void UINT_greater_equal(char **args, int *dimensions, int *steps, void *func) {\n int i, is1=steps[0],is2=steps[1],os=steps[2], n=dimensions[0];\n char *i1=args[0], *i2=args[1], *op=args[2];\n for(i=0; i= *((unsigned int *)i2);\n }\n}\nstatic void LONG_greater_equal(char **args, int *dimensions, int *steps, void *func) {\n int i, is1=steps[0],is2=steps[1],os=steps[2], n=dimensions[0];\n char *i1=args[0], *i2=args[1], *op=args[2];\n for(i=0; i= *((long *)i2);\n }\n}\nstatic void FLOAT_greater_equal(char **args, int *dimensions, int *steps, void *func) {\n int i, is1=steps[0],is2=steps[1],os=steps[2], n=dimensions[0];\n char *i1=args[0], *i2=args[1], *op=args[2];\n for(i=0; i= *((float *)i2);\n }\n}\nstatic void DOUBLE_greater_equal(char **args, int *dimensions, int *steps, void *func) {\n int i, is1=steps[0],is2=steps[1],os=steps[2], n=dimensions[0];\n char *i1=args[0], *i2=args[1], *op=args[2];\n for(i=0; i= *((double *)i2);\n }\n}\nstatic void CFLOAT_greater_equal(char **args, int *dimensions, int *steps, void *func) {\n int i, is1=steps[0],is2=steps[1],os=steps[2], n=dimensions[0];\n char *i1=args[0], *i2=args[1], *op=args[2];\n for(i=0; i= *((float *)i2);\n }\n}\nstatic void CDOUBLE_greater_equal(char **args, int *dimensions, int *steps, void *func) {\n int i, is1=steps[0],is2=steps[1],os=steps[2], n=dimensions[0];\n char *i1=args[0], *i2=args[1], *op=args[2];\n for(i=0; i= *((double *)i2);\n }\n}\n\nstatic void UBYTE_less(char **args, int *dimensions, int *steps, void *func) {\n int i, is1=steps[0],is2=steps[1],os=steps[2], n=dimensions[0];\n char *i1=args[0], *i2=args[1], *op=args[2];\n for(i=0; i *((unsigned char *)i2) ? *((unsigned char *)i1) : *((unsigned char *)i2);\n }\n}\nstatic void SBYTE_maximum(char **args, int *dimensions, int *steps, void *func) {\n int i, is1=steps[0],is2=steps[1],os=steps[2], n=dimensions[0];\n char *i1=args[0], *i2=args[1], *op=args[2];\n for(i=0; i *((signed char *)i2) ? *((signed char *)i1) : *((signed char *)i2);\n }\n}\nstatic void SHORT_maximum(char **args, int *dimensions, int *steps, void *func) {\n int i, is1=steps[0],is2=steps[1],os=steps[2], n=dimensions[0];\n char *i1=args[0], *i2=args[1], *op=args[2];\n for(i=0; i *((short *)i2) ? *((short *)i1) : *((short *)i2);\n }\n}\nstatic void USHORT_maximum(char **args, int *dimensions, int *steps, void *func) {\n int i, is1=steps[0],is2=steps[1],os=steps[2], n=dimensions[0];\n char *i1=args[0], *i2=args[1], *op=args[2];\n for(i=0; i *((unsigned short *)i2) ? *((unsigned short *)i1) : *((unsigned short *)i2);\n }\n}\nstatic void INT_maximum(char **args, int *dimensions, int *steps, void *func) {\n int i, is1=steps[0],is2=steps[1],os=steps[2], n=dimensions[0];\n char *i1=args[0], *i2=args[1], *op=args[2];\n for(i=0; i *((int *)i2) ? *((int *)i1) : *((int *)i2);\n }\n}\nstatic void UINT_maximum(char **args, int *dimensions, int *steps, void *func) {\n int i, is1=steps[0],is2=steps[1],os=steps[2], n=dimensions[0];\n char *i1=args[0], *i2=args[1], *op=args[2];\n for(i=0; i *((unsigned int *)i2) ? *((unsigned int *)i1) : *((unsigned int *)i2);\n }\n}\nstatic void LONG_maximum(char **args, int *dimensions, int *steps, void *func) {\n int i, is1=steps[0],is2=steps[1],os=steps[2], n=dimensions[0];\n char *i1=args[0], *i2=args[1], *op=args[2];\n for(i=0; i *((long *)i2) ? *((long *)i1) : *((long *)i2);\n }\n}\nstatic void FLOAT_maximum(char **args, int *dimensions, int *steps, void *func) {\n int i, is1=steps[0],is2=steps[1],os=steps[2], n=dimensions[0];\n char *i1=args[0], *i2=args[1], *op=args[2];\n for(i=0; i *((float *)i2) ? *((float *)i1) : *((float *)i2);\n }\n}\nstatic void DOUBLE_maximum(char **args, int *dimensions, int *steps, void *func) {\n int i, is1=steps[0],is2=steps[1],os=steps[2], n=dimensions[0];\n char *i1=args[0], *i2=args[1], *op=args[2];\n for(i=0; i *((double *)i2) ? *((double *)i1) : *((double *)i2);\n }\n}\nstatic void CFLOAT_maximum(char **args, int *dimensions, int *steps, void *func) {\n int i, is1=steps[0],is2=steps[1],os=steps[2], n=dimensions[0];\n char *i1=args[0], *i2=args[1], *op=args[2];\n for(i=0; i *((float *)i2) ? *((float *)i1) : *((float *)i2);\n\t((float *)op)[1]=*((float *)i1) > *((float *)i2) ? ((float *)i1)[1] : ((float *)i2)[1];\n }\n}\nstatic void CDOUBLE_maximum(char **args, int *dimensions, int *steps, void *func) {\n int i, is1=steps[0],is2=steps[1],os=steps[2], n=dimensions[0];\n char *i1=args[0], *i2=args[1], *op=args[2];\n for(i=0; i *((double *)i2) ? *((double *)i1) : *((double *)i2);\n\t((double *)op)[1]=*((double *)i1) > *((double *)i2) ? ((double *)i1)[1] : ((double *)i2)[1];\n }\n}\nstatic void UBYTE_minimum(char **args, int *dimensions, int *steps, void *func) {\n int i, is1=steps[0],is2=steps[1],os=steps[2], n=dimensions[0];\n char *i1=args[0], *i2=args[1], *op=args[2];\n for(i=0; i> *((unsigned char *)i2);\n }\n}\nstatic void SBYTE_right_shift(char **args, int *dimensions, int *steps, void *func) {\n int i, is1=steps[0],is2=steps[1],os=steps[2], n=dimensions[0];\n char *i1=args[0], *i2=args[1], *op=args[2];\n for(i=0; i> *((signed char *)i2);\n }\n}\nstatic void SHORT_right_shift(char **args, int *dimensions, int *steps, void *func) {\n int i, is1=steps[0],is2=steps[1],os=steps[2], n=dimensions[0];\n char *i1=args[0], *i2=args[1], *op=args[2];\n for(i=0; i> *((short *)i2);\n }\n}\nstatic void USHORT_right_shift(char **args, int *dimensions, int *steps, void *func) {\n int i, is1=steps[0],is2=steps[1],os=steps[2], n=dimensions[0];\n char *i1=args[0], *i2=args[1], *op=args[2];\n for(i=0; i> *((unsigned short *)i2);\n }\n}\nstatic void INT_right_shift(char **args, int *dimensions, int *steps, void *func) {\n int i, is1=steps[0],is2=steps[1],os=steps[2], n=dimensions[0];\n char *i1=args[0], *i2=args[1], *op=args[2];\n for(i=0; i> *((int *)i2);\n }\n}\nstatic void UINT_right_shift(char **args, int *dimensions, int *steps, void *func) {\n int i, is1=steps[0],is2=steps[1],os=steps[2], n=dimensions[0];\n char *i1=args[0], *i2=args[1], *op=args[2];\n for(i=0; i> *((unsigned int *)i2);\n }\n}\nstatic void LONG_right_shift(char **args, int *dimensions, int *steps, void *func) {\n int i, is1=steps[0],is2=steps[1],os=steps[2], n=dimensions[0];\n char *i1=args[0], *i2=args[1], *op=args[2];\n for(i=0; i> *((long *)i2);\n }\n}\n\nstatic PyUFuncGenericFunction add_functions[] = { UBYTE_add, SBYTE_add, SHORT_add, USHORT_add, INT_add, UINT_add, LONG_add, FLOAT_add, DOUBLE_add, CFLOAT_add, CDOUBLE_add, NULL, };\nstatic PyUFuncGenericFunction subtract_functions[] = { UBYTE_subtract, SBYTE_subtract, SHORT_subtract, USHORT_subtract, INT_subtract, UINT_subtract, LONG_subtract, FLOAT_subtract, DOUBLE_subtract, CFLOAT_subtract, CDOUBLE_subtract, NULL, };\nstatic PyUFuncGenericFunction multiply_functions[] = { UBYTE_multiply, SBYTE_multiply, SHORT_multiply, USHORT_multiply, INT_multiply, UINT_multiply, LONG_multiply, FLOAT_multiply, DOUBLE_multiply, NULL, NULL, NULL, };\nstatic PyUFuncGenericFunction divide_functions[] = { UBYTE_divide, SBYTE_divide, SHORT_divide, USHORT_divide, INT_divide, UINT_divide, LONG_divide, FLOAT_divide, DOUBLE_divide, NULL, NULL, NULL, };\n#if PY_VERSION_HEX >= 0x02020000\nstatic PyUFuncGenericFunction floor_divide_functions[] = { UBYTE_floor_divide, SBYTE_floor_divide, SHORT_floor_divide, USHORT_floor_divide, INT_floor_divide, UINT_floor_divide, LONG_floor_divide, FLOAT_floor_divide, DOUBLE_floor_divide, NULL, NULL, NULL, };\nstatic PyUFuncGenericFunction true_divide_functions[] = { UBYTE_true_divide, SBYTE_true_divide, SHORT_true_divide, USHORT_true_divide, INT_true_divide, UINT_true_divide, LONG_true_divide, FLOAT_true_divide, DOUBLE_true_divide, NULL, NULL, NULL, };\n#endif\nstatic PyUFuncGenericFunction divide_safe_functions[] = { UBYTE_divide_safe, SBYTE_divide_safe, SHORT_divide_safe, USHORT_divide_safe, INT_divide_safe, UINT_divide_safe, LONG_divide_safe, FLOAT_divide_safe, DOUBLE_divide_safe, };\nstatic PyUFuncGenericFunction conjugate_functions[] = { UBYTE_conjugate, SBYTE_conjugate, SHORT_conjugate, USHORT_conjugate, INT_conjugate, UINT_conjugate, LONG_conjugate, FLOAT_conjugate, DOUBLE_conjugate, CFLOAT_conjugate, CDOUBLE_conjugate, NULL, };\nstatic PyUFuncGenericFunction remainder_functions[] = { UBYTE_remainder, SBYTE_remainder, SHORT_remainder, USHORT_remainder, INT_remainder, UINT_remainder, LONG_remainder, NULL, NULL, NULL, };\nstatic PyUFuncGenericFunction power_functions[] = { UBYTE_power, SBYTE_power, SHORT_power, USHORT_power, INT_power, UINT_power, LONG_power, NULL, NULL, NULL, NULL, NULL, };\nstatic PyUFuncGenericFunction absolute_functions[] = { UBYTE_absolute, SBYTE_absolute, SHORT_absolute, USHORT_absolute, INT_absolute, UINT_absolute, LONG_absolute, FLOAT_absolute, DOUBLE_absolute, CFLOAT_absolute, CDOUBLE_absolute, NULL, };\nstatic PyUFuncGenericFunction negative_functions[] = { UBYTE_negative, SBYTE_negative, SHORT_negative, USHORT_negative, INT_negative, UINT_negative, LONG_negative, FLOAT_negative, DOUBLE_negative, CFLOAT_negative, CDOUBLE_negative, NULL, };\nstatic PyUFuncGenericFunction greater_functions[] = { UBYTE_greater, SBYTE_greater, SHORT_greater, USHORT_greater, INT_greater, UINT_greater, LONG_greater, FLOAT_greater, DOUBLE_greater, CFLOAT_greater, CDOUBLE_greater, };\nstatic PyUFuncGenericFunction greater_equal_functions[] = { UBYTE_greater_equal, SBYTE_greater_equal, SHORT_greater_equal, USHORT_greater_equal, INT_greater_equal, UINT_greater_equal, LONG_greater_equal, FLOAT_greater_equal, DOUBLE_greater_equal, CFLOAT_greater_equal, CDOUBLE_greater_equal, };\nstatic PyUFuncGenericFunction less_functions[] = { UBYTE_less, SBYTE_less, SHORT_less, USHORT_less, INT_less, UINT_less, LONG_less, FLOAT_less, DOUBLE_less, CFLOAT_less, CDOUBLE_less, };\nstatic PyUFuncGenericFunction less_equal_functions[] = { UBYTE_less_equal, SBYTE_less_equal, SHORT_less_equal, USHORT_less_equal, INT_less_equal, UINT_less_equal, LONG_less_equal, FLOAT_less_equal, DOUBLE_less_equal, CFLOAT_less_equal, CDOUBLE_less_equal, };\nstatic PyUFuncGenericFunction equal_functions[] = { CHAR_equal, UBYTE_equal, SBYTE_equal, SHORT_equal, USHORT_equal, INT_equal, UINT_equal, LONG_equal, FLOAT_equal, DOUBLE_equal, CFLOAT_equal, CDOUBLE_equal, OBJECT_equal};\nstatic PyUFuncGenericFunction not_equal_functions[] = { CHAR_not_equal, UBYTE_not_equal, SBYTE_not_equal, SHORT_not_equal, USHORT_not_equal, INT_not_equal, UINT_not_equal, LONG_not_equal, FLOAT_not_equal, DOUBLE_not_equal, CFLOAT_not_equal, CDOUBLE_not_equal, OBJECT_not_equal};\nstatic PyUFuncGenericFunction logical_and_functions[] = { UBYTE_logical_and, SBYTE_logical_and, SHORT_logical_and, USHORT_logical_and, INT_logical_and, UINT_logical_and, LONG_logical_and, FLOAT_logical_and, DOUBLE_logical_and, };\nstatic PyUFuncGenericFunction logical_or_functions[] = { UBYTE_logical_or, SBYTE_logical_or, SHORT_logical_or, USHORT_logical_or, INT_logical_or, UINT_logical_or, LONG_logical_or, FLOAT_logical_or, DOUBLE_logical_or, };\nstatic PyUFuncGenericFunction logical_xor_functions[] = { UBYTE_logical_xor, SBYTE_logical_xor, SHORT_logical_xor, USHORT_logical_xor, INT_logical_xor, UINT_logical_xor, LONG_logical_xor, FLOAT_logical_xor, DOUBLE_logical_xor, };\nstatic PyUFuncGenericFunction logical_not_functions[] = { UBYTE_logical_not, SBYTE_logical_not, SHORT_logical_not, USHORT_logical_not, INT_logical_not, UINT_logical_not, LONG_logical_not, FLOAT_logical_not, DOUBLE_logical_not, };\nstatic PyUFuncGenericFunction maximum_functions[] = { UBYTE_maximum, SBYTE_maximum, SHORT_maximum, USHORT_maximum, INT_maximum, UINT_maximum, LONG_maximum, FLOAT_maximum, DOUBLE_maximum, CFLOAT_maximum, CDOUBLE_maximum, };\nstatic PyUFuncGenericFunction minimum_functions[] = { UBYTE_minimum, SBYTE_minimum, SHORT_minimum, USHORT_minimum, INT_minimum, UINT_minimum, LONG_minimum, FLOAT_minimum, DOUBLE_minimum, CFLOAT_minimum, CDOUBLE_minimum, };\nstatic PyUFuncGenericFunction bitwise_and_functions[] = { UBYTE_bitwise_and, SBYTE_bitwise_and, SHORT_bitwise_and, USHORT_bitwise_and, INT_bitwise_and, UINT_bitwise_and, LONG_bitwise_and, NULL, };\nstatic PyUFuncGenericFunction bitwise_or_functions[] = { UBYTE_bitwise_or, SBYTE_bitwise_or, SHORT_bitwise_or, USHORT_bitwise_or, INT_bitwise_or, UINT_bitwise_or, LONG_bitwise_or, NULL, };\nstatic PyUFuncGenericFunction bitwise_xor_functions[] = { UBYTE_bitwise_xor, SBYTE_bitwise_xor, SHORT_bitwise_xor, USHORT_bitwise_xor, INT_bitwise_xor, UINT_bitwise_xor, LONG_bitwise_xor, NULL, };\nstatic PyUFuncGenericFunction invert_functions[] = { UBYTE_invert, SBYTE_invert, SHORT_invert, USHORT_invert, INT_invert, UINT_invert, LONG_invert, NULL, };\nstatic PyUFuncGenericFunction left_shift_functions[] = { UBYTE_left_shift, SBYTE_left_shift, SHORT_left_shift, USHORT_left_shift, INT_left_shift, UINT_left_shift, LONG_left_shift, NULL, };\nstatic PyUFuncGenericFunction right_shift_functions[] = { UBYTE_right_shift, SBYTE_right_shift, SHORT_right_shift, USHORT_right_shift, INT_right_shift, UINT_right_shift, LONG_right_shift, NULL, };\n\nstatic PyUFuncGenericFunction arccos_functions[] = { NULL, NULL, NULL, NULL, NULL, };\nstatic PyUFuncGenericFunction ceil_functions[] = { NULL, NULL, NULL, };\nstatic PyUFuncGenericFunction arctan2_functions[] = { NULL, NULL, NULL, };\n\n\nstatic void * add_data[] = { (void *)NULL, (void *)NULL, (void *)NULL, (void *)NULL, (void *)NULL, (void *)NULL, (void *)NULL, (void *)NULL, (void *)NULL, (void *)NULL, (void *)NULL, (void *)NULL};\nstatic void * subtract_data[] = { (void *)NULL, (void *)NULL, (void *)NULL, (void *)NULL, (void *)NULL, (void *)NULL, (void *)NULL, (void *)NULL, (void *)NULL, (void *)NULL, (void *)NULL, (void *)NULL};\nstatic void * multiply_data[] = { (void *)NULL, (void *)NULL, (void *)NULL, (void *)NULL, (void *)NULL, (void *)NULL, (void *)NULL, (void *)NULL, (void *)NULL, (void *)NULL, (void *)NULL, (void *)NULL};\nstatic void * divide_data[] = { (void *)NULL, (void *)NULL, (void *)NULL, (void *)NULL, (void *)NULL, (void *)NULL, (void *)NULL, (void *)NULL, (void *)NULL, (void *)NULL, (void *)NULL, (void *)NULL};\n#if PY_VERSION_HEX >= 0x02020000\nstatic void * floor_divide_data[] = { (void *)NULL, (void *)NULL, (void *)NULL, (void *)NULL, (void *)NULL, (void *)NULL, (void *)NULL, (void *)NULL, (void *)NULL, (void *)NULL, (void *)NULL, (void *)NULL};\nstatic void * true_divide_data[] = { (void *)NULL, (void *)NULL, (void *)NULL, (void *)NULL, (void *)NULL, (void *)NULL, (void *)NULL, (void *)NULL, (void *)NULL, (void *)NULL, (void *)NULL, (void *)NULL };\n#endif\nstatic void * divide_safe_data[] = { (void *)NULL, (void *)NULL, (void *)NULL, (void *)NULL, (void *)NULL, (void *)NULL, (void *)NULL, (void *)NULL, (void *)NULL, (void *)NULL, (void *) NULL, (void *) NULL };\nstatic void * conjugate_data[] = { (void *)NULL, (void *)NULL, (void *)NULL, (void *)NULL, (void *)NULL, (void *)NULL, (void *)NULL, (void *)NULL, (void *)NULL, (void *)NULL, (void *)NULL, (void *)NULL };\nstatic void * remainder_data[] = { (void *)NULL, (void *)NULL, (void *)NULL, (void *)NULL, (void *)NULL, (void *)NULL, (void *)NULL, (void *)NULL, (void *)NULL, (void *)NULL, };\nstatic void * power_data[] = { (void *)NULL, (void *)NULL, (void *)NULL, (void *)NULL, (void *)NULL, (void *)NULL, (void *)NULL, (void *)NULL, (void *)NULL, (void *)NULL, (void *)NULL, (void *)NULL,};\nstatic void * absolute_data[] = { (void *)NULL, (void *)NULL, (void *)NULL, (void *)NULL, (void *)NULL, (void *)NULL, (void *)NULL, (void *)NULL, (void *)NULL, (void *)NULL, (void *)NULL, (void *)NULL};\nstatic void * negative_data[] = { (void *)NULL, (void *)NULL, (void *)NULL, (void *)NULL, (void *)NULL, (void *)NULL, (void *)NULL, (void *)NULL, (void *)NULL, (void *)NULL, (void *)NULL, (void *)NULL,};\nstatic void * equal_data[] = { (void *)NULL, (void *)NULL, (void *)NULL, (void *)NULL, (void *)NULL, (void *)NULL, (void *)NULL, (void *)NULL, (void *)NULL, (void *)NULL, (void *)NULL, (void *)NULL, (void *)NULL, }; \nstatic void * bitwise_and_data[] = { (void *)NULL, (void *)NULL, (void *)NULL, (void *)NULL, (void *)NULL, (void *)NULL, (void *)NULL, (void *)NULL, };\nstatic void * bitwise_or_data[] = { (void *)NULL, (void *)NULL, (void *)NULL, (void *)NULL, (void *)NULL, (void *)NULL, (void *)NULL, (void *)NULL, };\nstatic void * bitwise_xor_data[] = { (void *)NULL, (void *)NULL, (void *)NULL, (void *)NULL, (void *)NULL, (void *)NULL, (void *)NULL, (void *)NULL, };\nstatic void * invert_data[] = { (void *)NULL, (void *)NULL, (void *)NULL, (void *)NULL, (void *)NULL, (void *)NULL, (void *)NULL, (void *)NULL,};\nstatic void * left_shift_data[] = { (void *)NULL, (void *)NULL, (void *)NULL, (void *)NULL, (void *)NULL, (void *)NULL, (void *)NULL, (void *)NULL,};\nstatic void * right_shift_data[] = { (void *)NULL, (void *)NULL, (void *)NULL, (void *)NULL, (void *)NULL, (void *)NULL, (void *)NULL, (void *)NULL,};\n\nstatic void * arccos_data[] = { (void *)acos, (void *)acos, (void *)c_acos, (void *)c_acos, (void *)\"arccos\", };\nstatic void * arcsin_data[] = { (void *)asin, (void *)asin, (void *)c_asin, (void *)c_asin, (void *)\"arcsin\", };\nstatic void * arctan_data[] = { (void *)atan, (void *)atan, (void *)c_atan, (void *)c_atan, (void *)\"arctan\", };\nstatic void * arccosh_data[] = { (void *)acosh, (void *)acosh, (void *)c_acosh, (void *)c_acosh, (void *)\"arccosh\", };\nstatic void * arcsinh_data[] = { (void *)asinh, (void *)asinh, (void *)c_asinh, (void *)c_asinh, (void *)\"arcsinh\", };\nstatic void * arctanh_data[] = { (void *)atanh, (void *)atanh, (void *)c_atanh, (void *)c_atanh, (void *)\"arctanh\", };\nstatic void * cos_data[] = { (void *)cos, (void *)cos, (void *)c_cos, (void *)c_cos, (void *)\"cos\", };\nstatic void * cosh_data[] = { (void *)cosh, (void *)cosh, (void *)c_cosh, (void *)c_cosh, (void *)\"cosh\", };\nstatic void * exp_data[] = { (void *)exp, (void *)exp, (void *)c_exp, (void *)c_exp, (void *)\"exp\", };\nstatic void * log_data[] = { (void *)log, (void *)log, (void *)c_log, (void *)c_log, (void *)\"log\", };\nstatic void * log10_data[] = { (void *)log10, (void *)log10, (void *)c_log10, (void *)c_log10, (void *)\"log10\", };\nstatic void * sin_data[] = { (void *)sin, (void *)sin, (void *)c_sin, (void *)c_sin, (void *)\"sin\", };\nstatic void * sinh_data[] = { (void *)sinh, (void *)sinh, (void *)c_sinh, (void *)c_sinh, (void *)\"sinh\", };\nstatic void * sqrt_data[] = { (void *)sqrt, (void *)sqrt, (void *)c_sqrt, (void *)c_sqrt, (void *)\"sqrt\", };\nstatic void * tan_data[] = { (void *)tan, (void *)tan, (void *)c_tan, (void *)c_tan, (void *)\"tan\", };\nstatic void * tanh_data[] = { (void *)tanh, (void *)tanh, (void *)c_tanh, (void *)c_tanh, (void *)\"tanh\", };\nstatic void * ceil_data[] = { (void *)ceil, (void *)ceil, (void *)\"ceil\", };\nstatic void * fabs_data[] = { (void *)fabs, (void *)fabs, (void *)\"fabs\", };\nstatic void * floor_data[] = { (void *)floor, (void *)floor, (void *)\"floor\", };\nstatic void * arctan2_data[] = { (void *)atan2, (void *)atan2, (void *)\"arctan2\", };\nstatic void * fmod_data[] = { (void *)fmod, (void *)fmod, (void *)\"fmod\", };\nstatic void * hypot_data[] = { (void *)hypot, (void *)hypot, (void *)\"hypot\", };\n\nstatic char add_signatures[] = { PyArray_UBYTE, PyArray_UBYTE, PyArray_UBYTE, PyArray_SBYTE, PyArray_SBYTE, PyArray_SBYTE, PyArray_SHORT, PyArray_SHORT, PyArray_SHORT, PyArray_USHORT, PyArray_USHORT, PyArray_USHORT, PyArray_INT, PyArray_INT, PyArray_INT, PyArray_UINT, PyArray_UINT, PyArray_UINT, PyArray_LONG, PyArray_LONG, PyArray_LONG, PyArray_FLOAT, PyArray_FLOAT, PyArray_FLOAT, PyArray_DOUBLE, PyArray_DOUBLE, PyArray_DOUBLE, PyArray_CFLOAT, PyArray_CFLOAT, PyArray_CFLOAT, PyArray_CDOUBLE, PyArray_CDOUBLE, PyArray_CDOUBLE, PyArray_OBJECT, PyArray_OBJECT, PyArray_OBJECT, };\n#if PY_VERSION_HEX >= 0x02020000\nstatic char floor_divide_signatures[] = { PyArray_UBYTE, PyArray_UBYTE, PyArray_UBYTE, PyArray_SBYTE, PyArray_SBYTE, PyArray_SBYTE, PyArray_SHORT, PyArray_SHORT, PyArray_SHORT, PyArray_USHORT, PyArray_USHORT, PyArray_USHORT, PyArray_INT, PyArray_INT, PyArray_INT, PyArray_UINT, PyArray_UINT, PyArray_UINT, PyArray_LONG, PyArray_LONG, PyArray_LONG, PyArray_FLOAT, PyArray_FLOAT, PyArray_FLOAT, PyArray_DOUBLE, PyArray_DOUBLE, PyArray_DOUBLE, };\nstatic char true_divide_signatures[] = { PyArray_UBYTE, PyArray_UBYTE, PyArray_FLOAT, PyArray_SBYTE, PyArray_SBYTE, PyArray_FLOAT, PyArray_SHORT, PyArray_SHORT, PyArray_FLOAT, PyArray_USHORT, PyArray_USHORT, PyArray_FLOAT, PyArray_INT, PyArray_INT, PyArray_DOUBLE, PyArray_UINT, PyArray_UINT, PyArray_DOUBLE, PyArray_LONG, PyArray_LONG, PyArray_DOUBLE, PyArray_FLOAT, PyArray_FLOAT, PyArray_FLOAT, PyArray_DOUBLE, PyArray_DOUBLE, PyArray_DOUBLE, PyArray_CFLOAT, PyArray_CFLOAT, PyArray_CFLOAT, PyArray_CDOUBLE, PyArray_CDOUBLE, PyArray_CDOUBLE, PyArray_OBJECT, PyArray_OBJECT, PyArray_OBJECT, };\n#endif\nstatic char divide_safe_signatures[] = { PyArray_UBYTE, PyArray_UBYTE, PyArray_UBYTE, PyArray_SBYTE, PyArray_SBYTE, PyArray_SBYTE, PyArray_SHORT, PyArray_SHORT, PyArray_SHORT, PyArray_USHORT, PyArray_USHORT, PyArray_USHORT, PyArray_INT, PyArray_INT, PyArray_INT, PyArray_UINT, PyArray_UINT, PyArray_UINT, PyArray_LONG, PyArray_LONG, PyArray_LONG, PyArray_FLOAT, PyArray_FLOAT, PyArray_FLOAT, PyArray_DOUBLE, PyArray_DOUBLE, PyArray_DOUBLE, };\nstatic char conjugate_signatures[] = { PyArray_UBYTE, PyArray_UBYTE, PyArray_SBYTE, PyArray_SBYTE, PyArray_SHORT, PyArray_SHORT, PyArray_USHORT, PyArray_USHORT, PyArray_INT, PyArray_INT, PyArray_UINT, PyArray_UINT, PyArray_LONG, PyArray_LONG, PyArray_FLOAT, PyArray_FLOAT, PyArray_DOUBLE, PyArray_DOUBLE, PyArray_CFLOAT, PyArray_CFLOAT, PyArray_CDOUBLE, PyArray_CDOUBLE, PyArray_OBJECT, PyArray_OBJECT, };\nstatic char remainder_signatures[] = { PyArray_UBYTE, PyArray_UBYTE, PyArray_UBYTE, PyArray_SBYTE, PyArray_SBYTE, PyArray_SBYTE, PyArray_SHORT, PyArray_SHORT, PyArray_SHORT, PyArray_USHORT, PyArray_USHORT, PyArray_USHORT, PyArray_INT, PyArray_INT, PyArray_INT, PyArray_UINT, PyArray_UINT, PyArray_UINT, PyArray_LONG, PyArray_LONG, PyArray_LONG, PyArray_FLOAT, PyArray_FLOAT, PyArray_FLOAT, PyArray_DOUBLE, PyArray_DOUBLE, PyArray_DOUBLE, PyArray_OBJECT, PyArray_OBJECT, PyArray_OBJECT, };\nstatic char absolute_signatures[] = { PyArray_UBYTE, PyArray_UBYTE, PyArray_SBYTE, PyArray_SBYTE, PyArray_SHORT, PyArray_SHORT, PyArray_USHORT, PyArray_USHORT, PyArray_INT, PyArray_INT, PyArray_UINT, PyArray_UINT, PyArray_LONG, PyArray_LONG, PyArray_FLOAT, PyArray_FLOAT, PyArray_DOUBLE, PyArray_DOUBLE, PyArray_CFLOAT, PyArray_FLOAT, PyArray_CDOUBLE, PyArray_DOUBLE, PyArray_OBJECT, PyArray_OBJECT, };\nstatic char negative_signatures[] = { PyArray_UBYTE, PyArray_UBYTE, PyArray_SBYTE, PyArray_SBYTE, PyArray_SHORT, PyArray_SHORT, PyArray_USHORT, PyArray_USHORT, PyArray_INT, PyArray_INT, PyArray_UINT, PyArray_UINT, PyArray_LONG, PyArray_LONG, PyArray_FLOAT, PyArray_FLOAT, PyArray_DOUBLE, PyArray_DOUBLE, PyArray_CFLOAT, PyArray_CFLOAT, PyArray_CDOUBLE, PyArray_CDOUBLE, PyArray_OBJECT, PyArray_OBJECT, };\nstatic char equal_signatures[] = { PyArray_CHAR, PyArray_CHAR, PyArray_UBYTE, PyArray_UBYTE, PyArray_UBYTE, PyArray_UBYTE, PyArray_SBYTE, PyArray_SBYTE, PyArray_UBYTE, PyArray_SHORT, PyArray_SHORT, PyArray_UBYTE, PyArray_USHORT, PyArray_USHORT, PyArray_UBYTE, PyArray_INT, PyArray_INT, PyArray_UBYTE, PyArray_UINT, PyArray_UINT, PyArray_UBYTE, PyArray_LONG, PyArray_LONG, PyArray_UBYTE, PyArray_FLOAT, PyArray_FLOAT, PyArray_UBYTE, PyArray_DOUBLE, PyArray_DOUBLE, PyArray_UBYTE, PyArray_CFLOAT, PyArray_CFLOAT, PyArray_UBYTE, PyArray_CDOUBLE, PyArray_CDOUBLE, PyArray_UBYTE, PyArray_OBJECT, PyArray_OBJECT, PyArray_UBYTE,};\nstatic char greater_signatures[] = { PyArray_UBYTE, PyArray_UBYTE, PyArray_UBYTE, PyArray_SBYTE, PyArray_SBYTE, PyArray_UBYTE, PyArray_SHORT, PyArray_SHORT, PyArray_UBYTE, PyArray_USHORT, PyArray_USHORT, PyArray_UBYTE, PyArray_INT, PyArray_INT, PyArray_UBYTE, PyArray_UINT, PyArray_UINT, PyArray_UBYTE, PyArray_LONG, PyArray_LONG, PyArray_UBYTE, PyArray_FLOAT, PyArray_FLOAT, PyArray_UBYTE, PyArray_DOUBLE, PyArray_DOUBLE, PyArray_UBYTE, PyArray_CFLOAT, PyArray_CFLOAT, PyArray_UBYTE, PyArray_CDOUBLE, PyArray_CDOUBLE, PyArray_UBYTE };\nstatic char logical_signatures[] = { PyArray_UBYTE, PyArray_UBYTE, PyArray_UBYTE, PyArray_SBYTE, PyArray_SBYTE, PyArray_SBYTE, PyArray_SHORT, PyArray_SHORT, PyArray_SHORT, PyArray_USHORT, PyArray_USHORT, PyArray_USHORT, PyArray_INT, PyArray_INT, PyArray_INT, PyArray_UINT, PyArray_UINT, PyArray_UINT, PyArray_LONG, PyArray_LONG, PyArray_LONG, PyArray_FLOAT, PyArray_FLOAT, PyArray_FLOAT, PyArray_DOUBLE, PyArray_DOUBLE, PyArray_DOUBLE, PyArray_CFLOAT, PyArray_CFLOAT, PyArray_CFLOAT, PyArray_CDOUBLE, PyArray_CDOUBLE, PyArray_CDOUBLE };\nstatic char logical_not_signatures[] = { PyArray_UBYTE, PyArray_UBYTE, PyArray_SBYTE, PyArray_UBYTE, PyArray_SHORT, PyArray_UBYTE, PyArray_USHORT, PyArray_UBYTE, PyArray_INT, PyArray_UBYTE, PyArray_UINT, PyArray_UBYTE, PyArray_LONG, PyArray_UBYTE, PyArray_FLOAT, PyArray_UBYTE, PyArray_DOUBLE, PyArray_UBYTE, };\nstatic char maximum_signatures[] = { PyArray_UBYTE, PyArray_UBYTE, PyArray_UBYTE, PyArray_SBYTE, PyArray_SBYTE, PyArray_SBYTE, PyArray_SHORT, PyArray_SHORT, PyArray_SHORT, PyArray_USHORT, PyArray_USHORT, PyArray_USHORT, PyArray_INT, PyArray_INT, PyArray_INT, PyArray_UINT, PyArray_UINT, PyArray_UINT, PyArray_LONG, PyArray_LONG, PyArray_LONG, PyArray_FLOAT, PyArray_FLOAT, PyArray_FLOAT, PyArray_DOUBLE, PyArray_DOUBLE, PyArray_DOUBLE, PyArray_CFLOAT, PyArray_CFLOAT, PyArray_CFLOAT, PyArray_CDOUBLE, PyArray_CDOUBLE, PyArray_CDOUBLE, };\nstatic char bitwise_and_signatures[] = { PyArray_UBYTE, PyArray_UBYTE, PyArray_UBYTE, PyArray_SBYTE, PyArray_SBYTE, PyArray_SBYTE, PyArray_SHORT, PyArray_SHORT, PyArray_SHORT, PyArray_USHORT, PyArray_USHORT, PyArray_USHORT, PyArray_INT, PyArray_INT, PyArray_INT, PyArray_UINT, PyArray_UINT, PyArray_UINT, PyArray_LONG, PyArray_LONG, PyArray_LONG, PyArray_OBJECT, PyArray_OBJECT, PyArray_OBJECT, };\nstatic char invert_signatures[] = { PyArray_UBYTE, PyArray_UBYTE, PyArray_SBYTE, PyArray_SBYTE, PyArray_SHORT, PyArray_SHORT, PyArray_USHORT, PyArray_USHORT, PyArray_INT, PyArray_INT, PyArray_UINT, PyArray_UINT, PyArray_LONG, PyArray_LONG, PyArray_OBJECT, PyArray_OBJECT, };\n\nstatic char arccos_signatures[] = { PyArray_FLOAT, PyArray_FLOAT, PyArray_DOUBLE, PyArray_DOUBLE, PyArray_CFLOAT, PyArray_CFLOAT, PyArray_CDOUBLE, PyArray_CDOUBLE, PyArray_OBJECT, PyArray_OBJECT, };\nstatic char ceil_signatures[] = { PyArray_FLOAT, PyArray_FLOAT, PyArray_DOUBLE, PyArray_DOUBLE, PyArray_OBJECT, PyArray_OBJECT, };\nstatic char arctan2_signatures[] = { PyArray_FLOAT, PyArray_FLOAT, PyArray_FLOAT, PyArray_DOUBLE, PyArray_DOUBLE, PyArray_DOUBLE, PyArray_OBJECT, PyArray_OBJECT, };\n\nstatic void InitOperators(PyObject *dictionary) {\n PyObject *f;\n\n add_data[11] =(void *)PyNumber_Add;\n subtract_data[11] = (void *)PyNumber_Subtract;\n multiply_data[9] = (void *)c_prod_;\n multiply_data[10] = (void *)c_prod_;\n multiply_data[11] = (void *)PyNumber_Multiply;\n divide_data[9] = (void *)c_quot_fast;\n divide_data[10] = (void *)c_quot_fast;\n divide_data[11] = (void *)PyNumber_Divide;\n /* need to add and worry \n divide_safe_data[9] = (void *)c_quot;\n divide_safe_data[10] = (void *)c_quot;\n divide_safe_data[11] = (void *)PyNumber_Divide;\n */\n conjugate_data[11] = (void *)\"conjugate\";\n remainder_data[7] = (void *)fmod;\n remainder_data[8] = (void *)fmod;\n remainder_data[9] = (void *)PyNumber_Remainder;\n power_data[7] = (void *)pow;\n power_data[8] = (void *)pow;\n power_data[9] = (void *)c_pow_;\n power_data[10] = (void *)c_pow_;\n power_data[11] = (void *)PyNumber_Power;\n absolute_data[11] = (void *)PyNumber_Absolute;\n negative_data[11] = (void *)PyNumber_Negative;\n bitwise_and_data[7] = (void *)PyNumber_And;\n bitwise_or_data[7] = (void *)PyNumber_Or;\n bitwise_xor_data[7] = (void *)PyNumber_Xor;\n invert_data[7] = (void *)PyNumber_Invert;\n left_shift_data[7] = (void *)PyNumber_Lshift;\n right_shift_data[7] = (void *)PyNumber_Rshift;\n\n add_functions[11] = PyUFunc_OO_O;\n subtract_functions[11] = PyUFunc_OO_O;\n multiply_functions[9] = fastumath_FF_F_As_DD_D;\n multiply_functions[10] = fastumath_DD_D;\n multiply_functions[11] = PyUFunc_OO_O;\n divide_functions[9] = fastumath_FF_F_As_DD_D;\n divide_functions[10] = fastumath_DD_D;\n divide_functions[11] = PyUFunc_OO_O;\n\n\n#if PY_VERSION_HEX >= 0x02020000\n true_divide_data[9] = (void *)c_quot_fast;\n true_divide_data[10] = (void *)c_quot_fast;\n true_divide_data[11] = (void *)PyNumber_TrueDivide;\n true_divide_functions[9] = fastumath_FF_F_As_DD_D;\n true_divide_functions[10] = fastumath_DD_D;\n true_divide_functions[11] = PyUFunc_OO_O;\n\n floor_divide_data[9] = (void *)c_quot_floor_fast;\n floor_divide_data[10] = (void *)c_quot_floor_fast;\n floor_divide_data[11] = (void *)PyNumber_FloorDivide;\n floor_divide_functions[9] = fastumath_FF_F_As_DD_D;\n floor_divide_functions[10] = fastumath_DD_D;\n floor_divide_functions[11] = PyUFunc_OO_O;\n#endif\n\n conjugate_functions[11] = PyUFunc_O_O_method;\n remainder_functions[7] = PyUFunc_ff_f_As_dd_d;\n remainder_functions[8] = PyUFunc_dd_d;\n remainder_functions[9] = PyUFunc_OO_O;\n power_functions[7] = PyUFunc_ff_f_As_dd_d;\n power_functions[8] = PyUFunc_dd_d;\n power_functions[9] = fastumath_FF_F_As_DD_D;\n power_functions[10] = fastumath_DD_D;\n power_functions[11] = PyUFunc_OO_O;\n absolute_functions[11] = PyUFunc_O_O;\n negative_functions[11] = PyUFunc_O_O;\n bitwise_and_functions[7] = PyUFunc_OO_O;\n bitwise_or_functions[7] = PyUFunc_OO_O;\n bitwise_xor_functions[7] = PyUFunc_OO_O;\n invert_functions[7] = PyUFunc_O_O;\n left_shift_functions[7] = PyUFunc_OO_O;\n right_shift_functions[7] = PyUFunc_OO_O;\n\n arccos_functions[0] = PyUFunc_f_f_As_d_d;\n arccos_functions[1] = PyUFunc_d_d;\n arccos_functions[2] = fastumath_F_F_As_D_D;\n arccos_functions[3] = fastumath_D_D;\n arccos_functions[4] = PyUFunc_O_O_method;\n ceil_functions[0] = PyUFunc_f_f_As_d_d;\n ceil_functions[1] = PyUFunc_d_d;\n ceil_functions[2] = PyUFunc_O_O_method;\n arctan2_functions[0] = PyUFunc_ff_f_As_dd_d;\n arctan2_functions[1] = PyUFunc_dd_d;\n arctan2_functions[2] = PyUFunc_O_O_method;\n\n\n f = PyUFunc_FromFuncAndData(isinf_functions, isinf_data, isinf_signatures, \n 4, 1, 1, PyUFunc_None, \"isinf\", \n \"isinf(x) returns non-zero if x is infinity.\", 0);\n PyDict_SetItemString(dictionary, \"isinf\", f);\n Py_DECREF(f);\n\n f = PyUFunc_FromFuncAndData(isfinite_functions, isfinite_data, isinf_signatures, \n 4, 1, 1, PyUFunc_None, \"isfinite\", \n \"isfinite(x) returns non-zero if x is not infinity or not a number.\", 0);\n PyDict_SetItemString(dictionary, \"isfinite\", f);\n Py_DECREF(f);\n\n f = PyUFunc_FromFuncAndData(isnan_functions, isnan_data, isinf_signatures, \n 4, 1, 1, PyUFunc_None, \"isnan\", \n \"isnan(x) returns non-zero if x is not a number.\", 0);\n PyDict_SetItemString(dictionary, \"isnan\", f);\n Py_DECREF(f);\n\n\n f = PyUFunc_FromFuncAndData(add_functions, add_data, add_signatures, 12, \n\t\t\t\t2, 1, PyUFunc_Zero, \"add\", \n\t\t\t\t\"Add the arguments elementwise.\", 0);\n PyDict_SetItemString(dictionary, \"add\", f);\n Py_DECREF(f);\n f = PyUFunc_FromFuncAndData(subtract_functions, subtract_data, add_signatures, \n\t\t\t\t12, 2, 1, PyUFunc_Zero, \"subtract\", \n\t\t\t\t\"Subtract the arguments elementwise.\", 0);\n PyDict_SetItemString(dictionary, \"subtract\", f);\n Py_DECREF(f);\n f = PyUFunc_FromFuncAndData(multiply_functions, multiply_data, add_signatures, \n\t\t\t\t12, 2, 1, PyUFunc_One, \"multiply\", \n\t\t\t\t\"Multiply the arguments elementwise.\", 0);\n PyDict_SetItemString(dictionary, \"multiply\", f);\n Py_DECREF(f);\n f = PyUFunc_FromFuncAndData(divide_functions, divide_data, add_signatures, \n\t\t\t\t12, 2, 1, PyUFunc_One, \"divide\", \n\t\t\t\t\"Divide the arguments elementwise.\", 0);\n PyDict_SetItemString(dictionary, \"divide\", f);\n Py_DECREF(f);\n#if PY_VERSION_HEX >= 0x02020000\n f = PyUFunc_FromFuncAndData(floor_divide_functions, floor_divide_data, floor_divide_signatures, \n\t\t\t\t12, 2, 1, PyUFunc_One, \"floor_divide\", \n\t\t\t\t\"Floor divide the arguments elementwise.\", 0);\n PyDict_SetItemString(dictionary, \"floor_divide\", f);\n Py_DECREF(f);\n f = PyUFunc_FromFuncAndData(true_divide_functions, true_divide_data, true_divide_signatures, \n\t\t\t\t12, 2, 1, PyUFunc_One, \"true_divide\", \n\t\t\t\t\"True divide the arguments elementwise.\", 0);\n PyDict_SetItemString(dictionary, \"true_divide\", f);\n Py_DECREF(f);\n#endif\n\n f = PyUFunc_FromFuncAndData(divide_safe_functions, divide_safe_data, divide_safe_signatures, \n\t\t\t\t9, 2, 1, PyUFunc_One, \"divide_safe\", \n\t\t\t\t\"Divide elementwise, ZeroDivision exception thrown if necessary.\", 0);\n PyDict_SetItemString(dictionary, \"divide_safe\", f);\n Py_DECREF(f);\n f = PyUFunc_FromFuncAndData(conjugate_functions, conjugate_data, conjugate_signatures, \n\t\t\t\t12, 1, 1, PyUFunc_None, \"conjugate\", \n\t\t\t\t\"returns conjugate of each element\", 0);\n PyDict_SetItemString(dictionary, \"conjugate\", f);\n Py_DECREF(f);\n f = PyUFunc_FromFuncAndData(remainder_functions, remainder_data, remainder_signatures, \n\t\t\t\t10, 2, 1, PyUFunc_Zero, \"remainder\", \n\t\t\t\t\"returns remainder of division elementwise\", 0);\n PyDict_SetItemString(dictionary, \"remainder\", f);\n Py_DECREF(f);\n f = PyUFunc_FromFuncAndData(power_functions, power_data, add_signatures, \n\t\t\t\t12, 2, 1, PyUFunc_One, \"power\", \n\t\t\t\t\"power(x,y) = x**y elementwise.\", 0);\n PyDict_SetItemString(dictionary, \"power\", f);\n Py_DECREF(f);\n f = PyUFunc_FromFuncAndData(absolute_functions, absolute_data, absolute_signatures, \n\t\t\t\t12, 1, 1, PyUFunc_None, \"absolute\", \n\t\t\t\t\"returns absolute value of each element\", 0);\n PyDict_SetItemString(dictionary, \"absolute\", f);\n Py_DECREF(f);\n f = PyUFunc_FromFuncAndData(negative_functions, negative_data, negative_signatures, \n\t\t\t\t12, 1, 1, PyUFunc_None, \"negative\", \n\t\t\t\t\"negative(x) == -x elementwise.\", 0);\n PyDict_SetItemString(dictionary, \"negative\", f);\n Py_DECREF(f);\n f = PyUFunc_FromFuncAndData(greater_functions, divide_safe_data, greater_signatures, \n\t\t\t\t11, 2, 1, PyUFunc_None, \"greater\", \n\t\t\t\t\"greater(x,y) is array of 1's where x > y, 0 otherwise.\",1);\n PyDict_SetItemString(dictionary, \"greater\", f);\n Py_DECREF(f);\n f = PyUFunc_FromFuncAndData(greater_equal_functions, divide_safe_data, greater_signatures, \n\t\t\t\t11, 2, 1, PyUFunc_None, \"greater_equal\", \n\t\t\t\t\"greater_equal(x,y) is array of 1's where x >=y, 0 otherwise.\", 0);\n PyDict_SetItemString(dictionary, \"greater_equal\", f);\n Py_DECREF(f);\n f = PyUFunc_FromFuncAndData(less_functions, divide_safe_data, greater_signatures, \n\t\t\t\t11, 2, 1, PyUFunc_None, \"less\", \n\t\t\t\t\"less(x,y) is array of 1's where x < y, 0 otherwise.\", 0);\n PyDict_SetItemString(dictionary, \"less\", f);\n Py_DECREF(f);\n f = PyUFunc_FromFuncAndData(less_equal_functions, divide_safe_data, greater_signatures, \n\t\t\t\t11, 2, 1, PyUFunc_None, \"less_equal\", \n\t\t\t\t\"less_equal(x,y) is array of 1's where x <= y, 0 otherwise.\", 0);\n PyDict_SetItemString(dictionary, \"less_equal\", f);\n Py_DECREF(f);\n f = PyUFunc_FromFuncAndData(equal_functions, equal_data, equal_signatures, \n\t\t\t\t13, 2, 1, PyUFunc_One, \"equal\", \n\t\t\t\t\"equal(x,y) is array of 1's where x == y, 0 otherwise.\", 0);\n PyDict_SetItemString(dictionary, \"equal\", f);\n Py_DECREF(f);\n f = PyUFunc_FromFuncAndData(not_equal_functions, equal_data, equal_signatures, \n\t\t\t\t13, 2, 1, PyUFunc_None, \"not_equal\", \n\t\t\t\t\"not_equal(x,y) is array of 0's where x == y, 1 otherwise.\", 0);\n PyDict_SetItemString(dictionary, \"not_equal\", f);\n Py_DECREF(f);\n f = PyUFunc_FromFuncAndData(logical_and_functions, divide_safe_data, logical_signatures, \n\t\t\t\t9, 2, 1, PyUFunc_One, \"logical_and\", \n\t\t\t\t\"logical_and(x,y) returns array of 1's where x and y both true.\", 0);\n PyDict_SetItemString(dictionary, \"logical_and\", f);\n Py_DECREF(f);\n f = PyUFunc_FromFuncAndData(logical_or_functions, divide_safe_data, logical_signatures, \n\t\t\t\t9, 2, 1, PyUFunc_Zero, \"logical_or\", \n\t\t\t\t\"logical_or(x,y) returns array of 1's where x or y or both are true.\", 0);\n PyDict_SetItemString(dictionary, \"logical_or\", f);\n Py_DECREF(f);\n f = PyUFunc_FromFuncAndData(logical_xor_functions, divide_safe_data, logical_signatures, \n\t\t\t\t9, 2, 1, PyUFunc_None, \"logical_xor\", \n\t\t\t\t\"logical_xor(x,y) returns array of 1's where exactly one of x or y is true.\", 0);\n PyDict_SetItemString(dictionary, \"logical_xor\", f);\n Py_DECREF(f);\n f = PyUFunc_FromFuncAndData(logical_not_functions, divide_safe_data, logical_not_signatures, \n\t\t\t\t9, 1, 1, PyUFunc_None, \"logical_not\", \n\t\t\t\t\"logical_not(x) returns array of 1's where x is false, 0 otherwise.\", 0);\n PyDict_SetItemString(dictionary, \"logical_not\", f);\n Py_DECREF(f);\n f = PyUFunc_FromFuncAndData(maximum_functions, divide_safe_data, maximum_signatures, \n\t\t\t\t11, 2, 1, PyUFunc_None, \"maximum\", \n\t\t\t\t\"maximum(x,y) returns maximum of x and y taken elementwise.\", 0);\n PyDict_SetItemString(dictionary, \"maximum\", f);\n Py_DECREF(f);\n f = PyUFunc_FromFuncAndData(minimum_functions, divide_safe_data, maximum_signatures,\n\t\t\t\t11, 2, 1, PyUFunc_None, \"minimum\", \n\t\t\t\t\"minimum(x,y) returns minimum of x and y taken elementwise.\", 0);\n PyDict_SetItemString(dictionary, \"minimum\", f);\n Py_DECREF(f);\n f = PyUFunc_FromFuncAndData(bitwise_and_functions, bitwise_and_data, bitwise_and_signatures, \n\t\t\t\t8, 2, 1, PyUFunc_One, \"bitwise_and\", \n\t\t\t\t\"bitwise_and(x,y) returns array of bitwise-and of respective elements.\", 0);\n PyDict_SetItemString(dictionary, \"bitwise_and\", f);\n Py_DECREF(f);\n f = PyUFunc_FromFuncAndData(bitwise_or_functions, bitwise_or_data, bitwise_and_signatures, \n\t\t\t\t8, 2, 1, PyUFunc_Zero, \"bitwise_or\", \n\t\t\t\t\"bitwise_or(x,y) returns array of bitwise-or of respective elements.\", 0);\n PyDict_SetItemString(dictionary, \"bitwise_or\", f);\n Py_DECREF(f);\n f = PyUFunc_FromFuncAndData(bitwise_xor_functions, bitwise_xor_data, bitwise_and_signatures, \n\t\t\t\t8, 2, 1, PyUFunc_None, \"bitwise_xor\", \n\t\t\t\t\"bitwise_xor(x,y) returns array of bitwise exclusive or of respective elements.\", 0);\n PyDict_SetItemString(dictionary, \"bitwise_xor\", f);\n Py_DECREF(f);\n f = PyUFunc_FromFuncAndData(invert_functions, invert_data, invert_signatures, \n\t\t\t\t8, 1, 1, PyUFunc_None, \"invert\", \n\t\t\t\t\"invert(n) returns array of bit inversion elementwise.\", 0);\n PyDict_SetItemString(dictionary, \"invert\", f);\n Py_DECREF(f);\n f = PyUFunc_FromFuncAndData(left_shift_functions, left_shift_data, bitwise_and_signatures, \n\t\t\t\t8, 2, 1, PyUFunc_None, \"left_shift\", \n\t\t\t\t\"left_shift(n, m) is n << m elementwise.\", 0);\n PyDict_SetItemString(dictionary, \"left_shift\", f);\n Py_DECREF(f);\n f = PyUFunc_FromFuncAndData(right_shift_functions, right_shift_data, bitwise_and_signatures, \n\t\t\t\t8, 2, 1, PyUFunc_None, \"right_shift\", \n\t\t\t\t\"right_shift(n, m) is n >> m elementwise.\", 0);\n PyDict_SetItemString(dictionary, \"right_shift\", f);\n Py_DECREF(f);\n\n f = PyUFunc_FromFuncAndData(arccos_functions, arccos_data, arccos_signatures, \n\t\t\t\t5, 1, 1, PyUFunc_None, \"arccos\", \n\t\t\t\t\"arccos(x) returns array of elementwise inverse cosines.\", 0);\n PyDict_SetItemString(dictionary, \"arccos\", f);\n Py_DECREF(f);\n f = PyUFunc_FromFuncAndData(arccos_functions, arcsin_data, arccos_signatures, \n\t\t\t\t5, 1, 1, PyUFunc_None, \"arcsin\", \n\t\t\t\t\"arcsin(x) returns array of elementwise inverse sines.\", 0);\n PyDict_SetItemString(dictionary, \"arcsin\", f);\n Py_DECREF(f);\n f = PyUFunc_FromFuncAndData(arccos_functions, arctan_data, arccos_signatures, \n\t\t\t\t5, 1, 1, PyUFunc_None, \"arctan\", \n\t\t\t\t\"arctan(x) returns array of elementwise inverse tangents.\", 0);\n PyDict_SetItemString(dictionary, \"arctan\", f);\n Py_DECREF(f);\n f = PyUFunc_FromFuncAndData(arccos_functions, arctanh_data, arccos_signatures, \n\t\t\t\t5, 1, 1, PyUFunc_None, \"arctanh\",\n\t\t\t\t\"arctanh(x) returns array of elementwise inverse hyperbolic tangents.\", 0);\n PyDict_SetItemString(dictionary, \"arctanh\", f);\n Py_DECREF(f);\n f = PyUFunc_FromFuncAndData(arccos_functions, arccosh_data, arccos_signatures, \n\t\t\t\t5, 1, 1, PyUFunc_None, \"arccosh\",\n\t\t\t\t\"arccosh(x) returns array of elementwise inverse hyperbolic cosines.\", 0);\n PyDict_SetItemString(dictionary, \"arccosh\", f);\n Py_DECREF(f);\n f = PyUFunc_FromFuncAndData(arccos_functions, arcsinh_data, arccos_signatures, \n\t\t\t\t5, 1, 1, PyUFunc_None, \"arcsinh\",\n\t\t\t\t\"arcsinh(x) returns array of elementwise inverse hyperbolic sines.\", 0);\n PyDict_SetItemString(dictionary, \"arcsinh\", f);\n Py_DECREF(f);\n f = PyUFunc_FromFuncAndData(arccos_functions, cos_data, arccos_signatures, \n\t\t\t\t5, 1, 1, PyUFunc_None, \"cos\", \n\t\t\t\t\"cos(x) returns array of elementwise cosines.\", 0);\n PyDict_SetItemString(dictionary, \"cos\", f);\n Py_DECREF(f);\n f = PyUFunc_FromFuncAndData(arccos_functions, cosh_data, arccos_signatures, \n\t\t\t\t5, 1, 1, PyUFunc_None, \"cosh\", \n\t\t\t\t\"cosh(x) returns array of elementwise hyberbolic cosines.\", 0);\n PyDict_SetItemString(dictionary, \"cosh\", f);\n Py_DECREF(f);\n f = PyUFunc_FromFuncAndData(arccos_functions, exp_data, arccos_signatures, \n\t\t\t\t5, 1, 1, PyUFunc_None, \"exp\", \n\t\t\t\t\"exp(x) returns array of elementwise e**x.\", 0);\n PyDict_SetItemString(dictionary, \"exp\", f);\n Py_DECREF(f);\n f = PyUFunc_FromFuncAndData(arccos_functions, log_data, arccos_signatures, \n\t\t\t\t5, 1, 1, PyUFunc_None, \"log\", \n\t\t\t\t\"log(x) returns array of elementwise natural logarithms.\", 0);\n PyDict_SetItemString(dictionary, \"log\", f);\n Py_DECREF(f);\n f = PyUFunc_FromFuncAndData(arccos_functions, log10_data, arccos_signatures, \n\t\t\t\t5, 1, 1, PyUFunc_None, \"log10\", \n\t\t\t\t\"log10(x) returns array of elementwise base-10 logarithms.\", 0);\n PyDict_SetItemString(dictionary, \"log10\", f);\n Py_DECREF(f);\n f = PyUFunc_FromFuncAndData(arccos_functions, sin_data, arccos_signatures, \n\t\t\t\t5, 1, 1, PyUFunc_None, \"sin\", \n\t\t\t\t\"sin(x) returns array of elementwise sines.\", 0);\n PyDict_SetItemString(dictionary, \"sin\", f);\n Py_DECREF(f);\n f = PyUFunc_FromFuncAndData(arccos_functions, sinh_data, arccos_signatures, \n\t\t\t\t5, 1, 1, PyUFunc_None, \"sinh\", \n\t\t\t\t\"sinh(x) returns array of elementwise hyperbolic sines.\", 0);\n PyDict_SetItemString(dictionary, \"sinh\", f);\n Py_DECREF(f);\n f = PyUFunc_FromFuncAndData(arccos_functions, sqrt_data, arccos_signatures, \n\t\t\t\t5, 1, 1, PyUFunc_None, \"sqrt\",\n\t\t\t\t\"sqrt(x) returns array of elementwise square roots.\", 0);\n PyDict_SetItemString(dictionary, \"sqrt\", f);\n Py_DECREF(f);\n f = PyUFunc_FromFuncAndData(arccos_functions, tan_data, arccos_signatures, \n\t\t\t\t5, 1, 1, PyUFunc_None, \"tan\", \n\t\t\t\t\"tan(x) returns array of elementwise tangents.\", 0);\n PyDict_SetItemString(dictionary, \"tan\", f);\n Py_DECREF(f);\n f = PyUFunc_FromFuncAndData(arccos_functions, tanh_data, arccos_signatures, \n\t\t\t\t5, 1, 1, PyUFunc_None, \"tanh\", \n\t\t\t\t\"tanh(x) returns array of elementwise hyperbolic tangents.\", 0);\n PyDict_SetItemString(dictionary, \"tanh\", f);\n Py_DECREF(f);\n f = PyUFunc_FromFuncAndData(ceil_functions, ceil_data, ceil_signatures, \n\t\t\t\t3, 1, 1, PyUFunc_None, \"ceil\", \n\t\t\t\t\"ceil(x) returns array of elementwise least whole number >= x.\", 0);\n PyDict_SetItemString(dictionary, \"ceil\", f);\n Py_DECREF(f);\n f = PyUFunc_FromFuncAndData(ceil_functions, fabs_data, ceil_signatures, \n\t\t\t\t3, 1, 1, PyUFunc_None, \"fabs\", \n\t\t\t\t\"fabs(x) returns array of elementwise absolute values, 32 bit if x is.\", 0);\n\n PyDict_SetItemString(dictionary, \"fabs\", f);\n Py_DECREF(f);\n f = PyUFunc_FromFuncAndData(ceil_functions, floor_data, ceil_signatures, \n\t\t\t\t3, 1, 1, PyUFunc_None, \"floor\", \n\t\t\t\t\"floor(x) returns array of elementwise least whole number <= x.\", 0);\n PyDict_SetItemString(dictionary, \"floor\", f);\n Py_DECREF(f);\n f = PyUFunc_FromFuncAndData(arctan2_functions, arctan2_data, arctan2_signatures, \n\t\t\t\t3, 2, 1, PyUFunc_None, \"arctan2\", \n\t\t\t\t\"arctan2(x,y) is a safe and correct tan(x/y).\", 0);\n PyDict_SetItemString(dictionary, \"arctan2\", f);\n Py_DECREF(f);\n f = PyUFunc_FromFuncAndData(arctan2_functions, fmod_data, arctan2_signatures, \n\t\t\t\t3, 2, 1, PyUFunc_None, \"fmod\", \n\t\t\t\t\"fmod(x,y) is remainder(x,y)\", 0);\n PyDict_SetItemString(dictionary, \"fmod\", f);\n Py_DECREF(f);\n f = PyUFunc_FromFuncAndData(arctan2_functions, hypot_data, arctan2_signatures, \n\t\t\t\t3, 2, 1, PyUFunc_None, \"hypot\", \n\t\t\t\t\"hypot(x,y) = sqrt(x**2 + y**2), elementwise.\", 0);\n PyDict_SetItemString(dictionary, \"hypot\", f);\n Py_DECREF(f);\n}\n\n\n", "methods": [], "methods_before": [], "changed_methods": [], "nloc": null, "complexity": null, "token_count": null, "diff_parsed": { "added": [ "", "#if 0", "#endif", "", "", "#if 0", "#endif", "", "", "#if 0", "#endif", "", "", "#if 0", "#endif", "" ], "deleted": [] } }, { "old_path": "scipy_base/fastumathmodule.c", "new_path": "scipy_base/fastumathmodule.c", "filename": "fastumathmodule.c", "extension": "c", "change_type": "MODIFY", "diff": "@@ -22,7 +22,8 @@\n #define HAVE_INVERSE_HYPERBOLIC 1\n #endif\n \n-static PyObject *Array0d_FromDouble(double); \n+/* static PyObject *Array0d_FromDouble(double); */\n+\n /* Wrapper to include the correct version */\n \n /* Complex functions */\n@@ -419,12 +420,14 @@ c_tanh(Py_complex x)\n #include \"fastumath_nounsigned.inc\"\n #endif\n \n+/*\n static PyObject *Array0d_FromDouble(double val){\n PyArrayObject *a;\n a = (PyArrayObject *)PyArray_FromDims(0,NULL,PyArray_DOUBLE);\n- memcpy(a->data,(char *)(&val),a->descr->elsize);\n+ memcpy(a->data,(char *)(&val), sizeof(double));\n return (PyObject *)a;\n }\n+*/\n \n static double pinf_init(void) {\n double mul = 1e10;\n@@ -454,9 +457,201 @@ static double pzero_init(void) {\n return pinf;\n }\n \n-/* Initialization function for the module (*must* be called initArray) */\n+/* CODE BELOW is used to Update Numeric object behavior */\n+\n+/* A copy of the original PyArrayType structure is kept and can be used\n+ to restore the original Numeric behavior at any time. \n+*/\n+\n+static PyTypeObject BackupPyArray_Type;\n+static PyTypeObject BackupPyUFunc_Type;\n+static PyNumberMethods backup_array_as_number;\n+static PySequenceMethods backup_array_as_sequence;\n+static PyMappingMethods backup_array_as_mapping;\n+static PyBufferProcs backup_array_as_buffer;\n+static int scipy_numeric_stored = 0;\n+\n+#ifndef PyUFunc_Type\n+#define PyUFunc_Type PyUfunc_Type /* fix bug in Numeric < 23.3 */\n+#endif\n+\n+/* make sure memory copy is going on with this */\n+void scipy_numeric_save(void) {\n+\n+ /* we just save copies of things we may alter. */\n+ if (!scipy_numeric_stored) {\n+ BackupPyUFunc_Type.tp_name = (PyUFunc_Type).tp_name;\n+ BackupPyUFunc_Type.tp_call = (PyUFunc_Type).tp_call;\n+\n+\tBackupPyArray_Type.tp_name = (PyArray_Type).tp_name;\n+\tBackupPyArray_Type.tp_getattr = (PyArray_Type).tp_getattr;\n+\n+\tmemcpy(&backup_array_as_number, (PyArray_Type).tp_as_number,\n+\t sizeof(PyNumberMethods));\n+\tmemcpy(&backup_array_as_sequence, (PyArray_Type).tp_as_sequence,\n+\t sizeof(PySequenceMethods));\n+\tmemcpy(&backup_array_as_mapping, (PyArray_Type).tp_as_mapping,\n+\t sizeof(PyMappingMethods));\n+\tmemcpy(&backup_array_as_buffer, (PyArray_Type).tp_as_buffer,\n+\t sizeof(PyBufferProcs));\n+\tscipy_numeric_stored = 1;\n+ }\n+}\n+\n+void scipy_numeric_restore(void) {\n+\n+ /* restore only what was copied */\n+ if (scipy_numeric_stored) {\n+\t(PyUFunc_Type).tp_name = BackupPyUFunc_Type.tp_name;\n+\t(PyUFunc_Type).tp_call = BackupPyUFunc_Type.tp_call;\t\n+\n+\t(PyArray_Type).tp_name = BackupPyArray_Type.tp_name;\n+\t(PyArray_Type).tp_getattr = BackupPyArray_Type.tp_getattr;\n+\n+\tmemcpy((PyArray_Type).tp_as_number, &backup_array_as_number, \n+\t sizeof(PyNumberMethods));\n+\tmemcpy((PyArray_Type).tp_as_sequence, &backup_array_as_sequence, \n+\t sizeof(PySequenceMethods));\n+\tmemcpy((PyArray_Type).tp_as_mapping, &backup_array_as_mapping,\n+\t sizeof(PyMappingMethods));\n+\tmemcpy((PyArray_Type).tp_as_buffer, &backup_array_as_buffer,\n+\t sizeof(PyBufferProcs));\n+ }\n+}\n+\n+static char *_scipy_array_str = \"array (scipy)\";\n+static char *_scipy_ufunc_str = \"ufunc (scipy)\";\n+\n+#define MAX_DIMS 30\n+#include \"_scipy_mapping.c\"\n+\n+static PyMappingMethods scipy_array_as_mapping = {\n+ (inquiry)scipy_array_length,\t\t/*mp_length*/\n+ (binaryfunc)scipy_array_subscript_nice, /*mp_subscript*/\n+ (objobjargproc)scipy_array_ass_sub,\t /*mp_ass_subscript*/\n+};\n+\n+#define MAX_ARGS 10\n+#include \"_scipy_number.c\"\n+\n+static PyNumberMethods scipy_array_as_number = {\n+ (binaryfunc)scipy_array_add, /*nb_add*/\n+ (binaryfunc)scipy_array_subtract, /*nb_subtract*/\n+ (binaryfunc)scipy_array_multiply, /*nb_multiply*/\n+ (binaryfunc)scipy_array_divide, /*nb_divide*/\n+ (binaryfunc)scipy_array_remainder, /*nb_remainder*/\n+ (binaryfunc)scipy_array_divmod, /*nb_divmod*/\n+ (ternaryfunc)scipy_array_power, /*nb_power*/\n+ (unaryfunc)scipy_array_negative, \n+ (unaryfunc)scipy_array_copy, /*nb_pos*/ \n+ (unaryfunc)scipy_array_absolute, /*(unaryfunc)scipy_array_abs,*/\n+ (inquiry)scipy_array_nonzero, /*nb_nonzero*/\n+ (unaryfunc)scipy_array_invert, /*nb_invert*/\n+ (binaryfunc)scipy_array_left_shift, /*nb_lshift*/\n+ (binaryfunc)scipy_array_right_shift, /*nb_rshift*/\n+ (binaryfunc)scipy_array_bitwise_and, /*nb_and*/\n+ (binaryfunc)scipy_array_bitwise_xor, /*nb_xor*/\n+ (binaryfunc)scipy_array_bitwise_or, /*nb_or*/\n+ (coercion)scipy_array_coerce, /*nb_coerce*/\n+ (unaryfunc)scipy_array_int, /*nb_int*/\n+ (unaryfunc)scipy_array_long, /*nb_long*/\n+ (unaryfunc)scipy_array_float, /*nb_float*/\n+ (unaryfunc)scipy_array_oct,\t /*nb_oct*/\n+ (unaryfunc)scipy_array_hex,\t /*nb_hex*/\n+\n+ /*This code adds augmented assignment functionality*/\n+ /*that was made available in Python 2.0*/\n+ (binaryfunc)scipy_array_inplace_add, /*inplace_add*/\n+ (binaryfunc)scipy_array_inplace_subtract, /*inplace_subtract*/\n+ (binaryfunc)scipy_array_inplace_multiply, /*inplace_multiply*/\n+ (binaryfunc)scipy_array_inplace_divide, /*inplace_divide*/\n+ (binaryfunc)scipy_array_inplace_remainder, /*inplace_remainder*/\n+ (ternaryfunc)scipy_array_inplace_power, /*inplace_power*/\n+ (binaryfunc)scipy_array_inplace_left_shift, /*inplace_lshift*/\n+ (binaryfunc)scipy_array_inplace_right_shift, /*inplace_rshift*/\n+ (binaryfunc)scipy_array_inplace_bitwise_and, /*inplace_and*/\n+ (binaryfunc)scipy_array_inplace_bitwise_xor, /*inplace_xor*/\n+ (binaryfunc)scipy_array_inplace_bitwise_or, /*inplace_or*/\n+\n+ /* Added in release 2.2 */\n+\t/* The following require the Py_TPFLAGS_HAVE_CLASS flag */\n+#if PY_VERSION_HEX >= 0x02020000\n+\t(binaryfunc)scipy_array_floor_divide, /*nb_floor_divide*/\n+\t(binaryfunc)scipy_array_true_divide, /*nb_true_divide*/\n+\t(binaryfunc)scipy_array_inplace_floor_divide, /*nb_inplace_floor_divide*/\n+\t(binaryfunc)scipy_array_inplace_true_divide, /*nb_inplace_true_divide*/\n+#endif\n+};\n+\n+static PyObject *_scipy_getattr(PyArrayObject *self, char *name) {\n+ PyArrayObject *ret;\n+\t\n+ if (strcmp(name, \"M\") == 0) {\n+\tPyObject *fm, *o;\n+\t\n+ /* Call the array constructor registered as matrix_base.matrix\n+\t or else raise exception if nothing registered */\n+\t\t\n+\t/* Import matrix_base module */\n+\tfm = PyImport_ImportModule(\"scipy_base.matrix_base\");\n+\to = PyObject_CallMethod(fm,\"matrix\",\"O\",(PyObject *)self);\n+\tif (ret == NULL) {\n+\t PyErr_SetString(PyExc_ReferenceError, \"Error using scipy_base.matrix_base.matrix to construct matrix representation\");\n+\t Py_XDECREF(fm);\n+\t return NULL;\n+\t}\n+\tPy_XDECREF(fm);\t\n+\treturn o;\n+ }\n+\n+ return (BackupPyArray_Type.tp_getattr)((void *)self, name);\n+}\n+\n \n+void scipy_numeric_alter(void) {\n+ \n+ (PyArray_Type).tp_name = _scipy_array_str;\n+ (PyArray_Type).tp_getattr = (getattrfunc)_scipy_getattr;\n+ memcpy((PyArray_Type).tp_as_mapping, &scipy_array_as_mapping,\n+\t sizeof(PyMappingMethods));\n+ memcpy((PyArray_Type).tp_as_number, &scipy_array_as_number,\n+ sizeof(PyNumberMethods));\n+\n+ (PyUFunc_Type).tp_call = (ternaryfunc)scipy_ufunc_call;\n+ (PyUFunc_Type).tp_name = _scipy_ufunc_str;\n+}\n+\n+static char numeric_alter_doc[] = \"alter_numeric() update the behavior of Numeric objects.\\n\\n 1. Change coercion rules so that multiplying by a scalar does not upcast.\\n 2. Add index and mask slicing capability to Numeric arrays.\\n 3. Add .M attribute to Numeric arrays for returning a Matrix 4. (TODO) Speed enhancements.\\n\\nThis call changes the behavior for ALL Numeric arrays currently defined\\n and to be defined in the future. The old behavior can be restored for ALL\\n arrays using numeric_restore().\";\n+\n+static PyObject *numeric_behavior_alter(PyObject *self, PyObject *args)\n+{\n+\n+ if (!PyArg_ParseTuple ( args, \"\")) return NULL;\n+\n+ scipy_numeric_save();\n+ scipy_numeric_alter();\n+ Py_INCREF(Py_None);\n+ return Py_None;\n+}\n+\n+static char numeric_restore_doc[] = \"restore_numeric() restore the default behavior of Numeric objects.\\n\\n SEE alter_numeric.\\n\";\n+\n+static PyObject *numeric_behavior_restore(PyObject *self, PyObject *args)\n+{\n+\n+ if (!PyArg_ParseTuple ( args, \"\")) return NULL;\n+ scipy_numeric_restore();\n+ Py_INCREF(Py_None);\n+ return Py_None;\n+}\n+\n+\n+/* Initialization function for the module (*must* be called initArray) */\n static struct PyMethodDef methods[] = {\n+ {\"alter_numeric\", numeric_behavior_alter, METH_VARARGS, \n+ numeric_alter_doc},\n+ {\"restore_numeric\", numeric_behavior_restore, METH_VARARGS, \n+ numeric_restore_doc},\n {NULL,\t\tNULL, 0}\t\t/* sentinel */\n };\n \n@@ -481,6 +676,9 @@ DL_EXPORT(void) initfastumath(void) {\n /* Load the ufunc operators into the array module's namespace */\n InitOperators(d); \n \n+ /* Import Fastumath module */\n+ scipy_SetNumericOps(d);\n+\n PyDict_SetItemString(d, \"pi\", s = PyFloat_FromDouble(atan(1.0) * 4.0));\n Py_DECREF(s);\n PyDict_SetItemString(d, \"e\", s = PyFloat_FromDouble(exp(1.0)));\n", "added_lines": 201, "deleted_lines": 3, "source_code": "#include \n#include \"Python.h\"\n#include \"Numeric/arrayobject.h\"\n#include \"Numeric/ufuncobject.h\"\n#include \"abstract.h\"\n#include \"mconf_lite.h\"\n\n/* Fast umath module whose functions do not check for range and domain\n errors.\n\n Replacement for umath + additions for isnan, isfinite, and isinf\n Also allows comparison operations on complex numbers (just compares\n the real part) and logical operations.\n\n All logical operations return UBYTE arrays except for \n logical_and, logical_or, and logical_xor\n which return their type so that reduce works correctly on them....\n*/\n\n#if defined _ISOC99_SOURCE || defined _XOPEN_SOURCE_EXTENDED \\\n || defined _BSD_SOURCE || defined _SVID_SOURCE\n#define HAVE_INVERSE_HYPERBOLIC 1\n#endif\n\n/* static PyObject *Array0d_FromDouble(double); */\n\n/* Wrapper to include the correct version */\n\n/* Complex functions */\n\n\n#if !defined(HAVE_INVERSE_HYPERBOLIC)\nstatic double acosh(double x)\n{\n return log(x + sqrt((x-1.0)*(x+1.0)));\n}\n\nstatic double asinh(double xx)\n{\n double x;\n int sign;\n if (xx < 0.0) {\n\tsign = -1;\n\tx = -xx;\n }\n else {\n\tsign = 1;\n\tx = xx;\n }\n return sign*log(x + sqrt(x*x+1.0));\n}\n\nstatic double atanh(double x)\n{\n return 0.5*log((1.0+x)/(1.0-x));\n}\n#endif\n\n#if defined(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 double yx;\n\n x = fabs(x);\n y = fabs(y);\n if (x < y) {\n\tdouble temp = x;\n\tx = y;\n\ty = temp;\n }\n if (x == 0.)\n\treturn 0.;\n else {\n\tyx = y/x;\n\treturn x*sqrt(1.+yx*yx);\n }\n}\n#endif\n\n#ifdef i860\n/* Cray APP has bogus definition of HUGE_VAL in */\n#undef HUGE_VAL\n#endif\n\n#ifdef HUGE_VAL\n#define CHECK(x) if (errno != 0) ; \telse if (-HUGE_VAL <= (x) && (x) <= HUGE_VAL) ; \telse errno = ERANGE\n#else\n#define CHECK(x) /* Don't know how to check */\n#endif\n\n/* constants */\nstatic Py_complex c_1 = {1., 0.};\nstatic Py_complex c_half = {0.5, 0.};\nstatic Py_complex c_i = {0., 1.};\nstatic Py_complex c_i2 = {0., 0.5};\n/*\nstatic Py_complex c_mi = {0., -1.};\nstatic Py_complex c_pi2 = {M_PI/2., 0.};\n*/\n\nstatic Py_complex\nc_sum_(Py_complex a, Py_complex b)\n{\n Py_complex r;\n r.real = a.real + b.real;\n r.imag = a.imag + b.imag;\n return r;\n}\n\nstatic Py_complex\nc_diff_(Py_complex a, Py_complex b)\n{\n Py_complex r;\n r.real = a.real - b.real;\n r.imag = a.imag - b.imag;\n return r;\n}\n\nstatic Py_complex\nc_neg_(Py_complex a)\n{\n Py_complex r;\n r.real = -a.real;\n r.imag = -a.imag;\n return r;\n}\n\nstatic Py_complex\nc_prod_(Py_complex a, Py_complex b)\n{\n Py_complex r;\n r.real = a.real*b.real - a.imag*b.imag;\n r.imag = a.real*b.imag + a.imag*b.real;\n return r;\n}\n\nstatic Py_complex\nc_pow_(Py_complex a, Py_complex b)\n{\n Py_complex r;\n double vabs,len,at,phase;\n if (b.real == 0. && b.imag == 0.) {\n\tr.real = 1.;\n\tr.imag = 0.;\n }\n else if (a.real == 0. && a.imag == 0.) {\n\tif (b.imag != 0. || b.real < 0.)\n\t errno = EDOM;\n\tr.real = 0.;\n\tr.imag = 0.;\n }\n else {\n\tvabs = hypot(a.real,a.imag);\n\tlen = pow(vabs,b.real);\n\tat = atan2(a.imag, a.real);\n\tphase = at*b.real;\n\tif (b.imag != 0.0) {\n\t len /= exp(at*b.imag);\n\t phase += b.imag*log(vabs);\n\t}\n\tr.real = len*cos(phase);\n\tr.imag = len*sin(phase);\n }\n return r;\n}\n\n/* First, the C functions that do the real work */\n\nstatic Py_complex \nc_quot_fast(Py_complex a, Py_complex b)\n{\n /******************************************************************/\n \n /* This algorithm is better, and is pretty obvious: first divide the\n * numerators and denominator by whichever of {b.real, b.imag} has\n * larger magnitude. The earliest reference I found was to CACM\n * Algorithm 116 (Complex Division, Robert L. Smith, Stanford\n * University). As usual, though, we're still ignoring all IEEE\n * endcases.\n */\n Py_complex r; /* the result */\n\n const double abs_breal = b.real < 0 ? -b.real : b.real;\n const double abs_bimag = b.imag < 0 ? -b.imag : b.imag;\n\n if ((b.real == 0.0) && (b.imag == 0.0)) {\n r.real = a.real / b.real;\n r.imag = a.imag / b.imag;\n\t/* Using matlab's convention (x+0j is x):\n\t (0+0j)/0 -> nan+0j\n\t (0+xj)/0 -> nan+sign(x)*infj\n\t (x+0j)/0 -> sign(x)*inf+0j\n\t*/\n\tif (a.imag == 0.0) {r.imag = 0.0;}\n return r;\n }\n if (abs_breal >= abs_bimag) {\n\t/* divide tops and bottom by b.real */\n\tconst double ratio = b.imag / b.real;\n\tconst double denom = b.real + b.imag * ratio;\n\tr.real = (a.real + a.imag * ratio) / denom;\n\tr.imag = (a.imag - a.real * ratio) / denom;\n }\n else {\n\t/* divide tops and bottom by b.imag */\n\tconst double ratio = b.real / b.imag;\n\tconst double denom = b.real * ratio + b.imag;\n\tr.real = (a.real * ratio + a.imag) / denom;\n\tr.imag = (a.imag * ratio - a.real) / denom;\n }\n return r;\n}\n\n#if PY_VERSION_HEX >= 0x02020000\nstatic Py_complex \nc_quot_floor_fast(Py_complex a, Py_complex b)\n{\n /* Not really sure what to do here, but it looks like Python takes the \n floor of the real part and returns that as the answer. So, we will do the same.\n */\n Py_complex r;\n\n r = c_quot_fast(a, b);\n r.imag = 0.0;\n r.real = floor(r.real);\n return r;\n}\n#endif\n\nstatic Py_complex \nc_sqrt(Py_complex x)\n{\n Py_complex r;\n double s,d;\n if (x.real == 0. && x.imag == 0.)\n\tr = x;\n else {\n\ts = sqrt(0.5*(fabs(x.real) + hypot(x.real,x.imag)));\n\td = 0.5*x.imag/s;\n\tif (x.real > 0.) {\n\t r.real = s;\n\t r.imag = d;\n\t}\n\telse if (x.imag >= 0.) {\n\t r.real = d;\n\t r.imag = s;\n\t}\n\telse {\n\t r.real = -d;\n\t r.imag = -s;\n\t}\n }\n return r;\n}\n\nstatic Py_complex \nc_log(Py_complex x)\n{\n Py_complex r;\n double l = hypot(x.real,x.imag);\n r.imag = atan2(x.imag, x.real);\n r.real = log(l);\n return r;\n}\n\nstatic Py_complex \nc_prodi(Py_complex x)\n{\n Py_complex r;\n r.real = -x.imag;\n r.imag = x.real;\n return r;\n}\n\nstatic Py_complex \nc_acos(Py_complex x)\n{\n return c_neg_(c_prodi(c_log(c_sum_(x,c_prod_(c_i,\n\t\t\t\t\t c_sqrt(c_diff_(c_1,c_prod_(x,x))))))));\n}\n\nstatic Py_complex \nc_acosh(Py_complex x)\n{\n return c_log(c_sum_(x,c_prod_(c_i,\n\t\t\t\tc_sqrt(c_diff_(c_1,c_prod_(x,x))))));\n}\n\nstatic Py_complex \nc_asin(Py_complex x)\n{\n return c_neg_(c_prodi(c_log(c_sum_(c_prod_(c_i,x),\n\t\t\t\t c_sqrt(c_diff_(c_1,c_prod_(x,x)))))));\n}\n\nstatic Py_complex \nc_asinh(Py_complex x)\n{\n return c_neg_(c_log(c_diff_(c_sqrt(c_sum_(c_1,c_prod_(x,x))),x)));\n}\n\nstatic Py_complex \nc_atan(Py_complex x)\n{\n return c_prod_(c_i2,c_log(c_quot_fast(c_sum_(c_i,x),c_diff_(c_i,x))));\n}\n\nstatic Py_complex \nc_atanh(Py_complex x)\n{\n return c_prod_(c_half,c_log(c_quot_fast(c_sum_(c_1,x),c_diff_(c_1,x))));\n}\n\nstatic Py_complex \nc_cos(Py_complex x)\n{\n Py_complex r;\n r.real = cos(x.real)*cosh(x.imag);\n r.imag = -sin(x.real)*sinh(x.imag);\n return r;\n}\n\nstatic Py_complex \nc_cosh(Py_complex x)\n{\n Py_complex r;\n r.real = cos(x.imag)*cosh(x.real);\n r.imag = sin(x.imag)*sinh(x.real);\n return r;\n}\n\nstatic Py_complex \nc_exp(Py_complex x)\n{\n Py_complex r;\n double l = exp(x.real);\n r.real = l*cos(x.imag);\n r.imag = l*sin(x.imag);\n return r;\n}\n\nstatic Py_complex \nc_log10(Py_complex x)\n{\n Py_complex r;\n double l = hypot(x.real,x.imag);\n r.imag = atan2(x.imag, x.real)/log(10.);\n r.real = log10(l);\n return r;\n}\n\nstatic Py_complex \nc_sin(Py_complex x)\n{\n Py_complex r;\n r.real = sin(x.real)*cosh(x.imag);\n r.imag = cos(x.real)*sinh(x.imag);\n return r;\n}\n\nstatic Py_complex \nc_sinh(Py_complex x)\n{\n Py_complex r;\n r.real = cos(x.imag)*sinh(x.real);\n r.imag = sin(x.imag)*cosh(x.real);\n return r;\n}\n\nstatic Py_complex \nc_tan(Py_complex x)\n{\n Py_complex r;\n double sr,cr,shi,chi;\n double rs,is,rc,ic;\n double d;\n sr = sin(x.real);\n cr = cos(x.real);\n shi = sinh(x.imag);\n chi = cosh(x.imag);\n rs = sr*chi;\n is = cr*shi;\n rc = cr*chi;\n ic = -sr*shi;\n d = rc*rc + ic*ic;\n r.real = (rs*rc+is*ic)/d;\n r.imag = (is*rc-rs*ic)/d;\n return r;\n}\n\nstatic Py_complex \nc_tanh(Py_complex x)\n{\n Py_complex r;\n double si,ci,shr,chr;\n double rs,is,rc,ic;\n double d;\n si = sin(x.imag);\n ci = cos(x.imag);\n shr = sinh(x.real);\n chr = cosh(x.real);\n rs = ci*shr;\n is = si*chr;\n rc = ci*chr;\n ic = si*shr;\n d = rc*rc + ic*ic;\n r.real = (rs*rc+is*ic)/d;\n r.imag = (is*rc-rs*ic)/d;\n return r;\n}\n\n\n#ifdef PyArray_UNSIGNED_TYPES\n#include \"fastumath_unsigned.inc\"\n#else\n#include \"fastumath_nounsigned.inc\"\n#endif\n\n/*\nstatic PyObject *Array0d_FromDouble(double val){\n PyArrayObject *a;\n a = (PyArrayObject *)PyArray_FromDims(0,NULL,PyArray_DOUBLE);\n memcpy(a->data,(char *)(&val), sizeof(double));\n return (PyObject *)a;\n}\n*/\n\nstatic double pinf_init(void) {\n double mul = 1e10;\n double tmp = 0.0;\n double pinf;\n\n pinf = mul;\n for (;;) {\n\tpinf *= mul;\n\tif (pinf == tmp) break;\n\ttmp = pinf;\n }\n return pinf;\n}\n\nstatic double pzero_init(void) {\n double div = 1e10;\n double tmp = 0.0;\n double pinf;\n\n pinf = div;\n for (;;) {\n\tpinf /= div;\n\tif (pinf == tmp) break;\n\ttmp = pinf;\n }\n return pinf;\n}\n\n/* CODE BELOW is used to Update Numeric object behavior */\n\n/* A copy of the original PyArrayType structure is kept and can be used\n to restore the original Numeric behavior at any time. \n*/\n\nstatic PyTypeObject BackupPyArray_Type;\nstatic PyTypeObject BackupPyUFunc_Type;\nstatic PyNumberMethods backup_array_as_number;\nstatic PySequenceMethods backup_array_as_sequence;\nstatic PyMappingMethods backup_array_as_mapping;\nstatic PyBufferProcs backup_array_as_buffer;\nstatic int scipy_numeric_stored = 0;\n\n#ifndef PyUFunc_Type\n#define PyUFunc_Type PyUfunc_Type /* fix bug in Numeric < 23.3 */\n#endif\n\n/* make sure memory copy is going on with this */\nvoid scipy_numeric_save(void) {\n\n /* we just save copies of things we may alter. */\n if (!scipy_numeric_stored) {\n BackupPyUFunc_Type.tp_name = (PyUFunc_Type).tp_name;\n BackupPyUFunc_Type.tp_call = (PyUFunc_Type).tp_call;\n\n\tBackupPyArray_Type.tp_name = (PyArray_Type).tp_name;\n\tBackupPyArray_Type.tp_getattr = (PyArray_Type).tp_getattr;\n\n\tmemcpy(&backup_array_as_number, (PyArray_Type).tp_as_number,\n\t sizeof(PyNumberMethods));\n\tmemcpy(&backup_array_as_sequence, (PyArray_Type).tp_as_sequence,\n\t sizeof(PySequenceMethods));\n\tmemcpy(&backup_array_as_mapping, (PyArray_Type).tp_as_mapping,\n\t sizeof(PyMappingMethods));\n\tmemcpy(&backup_array_as_buffer, (PyArray_Type).tp_as_buffer,\n\t sizeof(PyBufferProcs));\n\tscipy_numeric_stored = 1;\n }\n}\n\nvoid scipy_numeric_restore(void) {\n\n /* restore only what was copied */\n if (scipy_numeric_stored) {\n\t(PyUFunc_Type).tp_name = BackupPyUFunc_Type.tp_name;\n\t(PyUFunc_Type).tp_call = BackupPyUFunc_Type.tp_call;\t\n\n\t(PyArray_Type).tp_name = BackupPyArray_Type.tp_name;\n\t(PyArray_Type).tp_getattr = BackupPyArray_Type.tp_getattr;\n\n\tmemcpy((PyArray_Type).tp_as_number, &backup_array_as_number, \n\t sizeof(PyNumberMethods));\n\tmemcpy((PyArray_Type).tp_as_sequence, &backup_array_as_sequence, \n\t sizeof(PySequenceMethods));\n\tmemcpy((PyArray_Type).tp_as_mapping, &backup_array_as_mapping,\n\t sizeof(PyMappingMethods));\n\tmemcpy((PyArray_Type).tp_as_buffer, &backup_array_as_buffer,\n\t sizeof(PyBufferProcs));\n }\n}\n\nstatic char *_scipy_array_str = \"array (scipy)\";\nstatic char *_scipy_ufunc_str = \"ufunc (scipy)\";\n\n#define MAX_DIMS 30\n#include \"_scipy_mapping.c\"\n\nstatic PyMappingMethods scipy_array_as_mapping = {\n (inquiry)scipy_array_length,\t\t/*mp_length*/\n (binaryfunc)scipy_array_subscript_nice, /*mp_subscript*/\n (objobjargproc)scipy_array_ass_sub,\t /*mp_ass_subscript*/\n};\n\n#define MAX_ARGS 10\n#include \"_scipy_number.c\"\n\nstatic PyNumberMethods scipy_array_as_number = {\n (binaryfunc)scipy_array_add, /*nb_add*/\n (binaryfunc)scipy_array_subtract, /*nb_subtract*/\n (binaryfunc)scipy_array_multiply, /*nb_multiply*/\n (binaryfunc)scipy_array_divide, /*nb_divide*/\n (binaryfunc)scipy_array_remainder, /*nb_remainder*/\n (binaryfunc)scipy_array_divmod, /*nb_divmod*/\n (ternaryfunc)scipy_array_power, /*nb_power*/\n (unaryfunc)scipy_array_negative, \n (unaryfunc)scipy_array_copy, /*nb_pos*/ \n (unaryfunc)scipy_array_absolute, /*(unaryfunc)scipy_array_abs,*/\n (inquiry)scipy_array_nonzero, /*nb_nonzero*/\n (unaryfunc)scipy_array_invert, /*nb_invert*/\n (binaryfunc)scipy_array_left_shift, /*nb_lshift*/\n (binaryfunc)scipy_array_right_shift, /*nb_rshift*/\n (binaryfunc)scipy_array_bitwise_and, /*nb_and*/\n (binaryfunc)scipy_array_bitwise_xor, /*nb_xor*/\n (binaryfunc)scipy_array_bitwise_or, /*nb_or*/\n (coercion)scipy_array_coerce, /*nb_coerce*/\n (unaryfunc)scipy_array_int, /*nb_int*/\n (unaryfunc)scipy_array_long, /*nb_long*/\n (unaryfunc)scipy_array_float, /*nb_float*/\n (unaryfunc)scipy_array_oct,\t /*nb_oct*/\n (unaryfunc)scipy_array_hex,\t /*nb_hex*/\n\n /*This code adds augmented assignment functionality*/\n /*that was made available in Python 2.0*/\n (binaryfunc)scipy_array_inplace_add, /*inplace_add*/\n (binaryfunc)scipy_array_inplace_subtract, /*inplace_subtract*/\n (binaryfunc)scipy_array_inplace_multiply, /*inplace_multiply*/\n (binaryfunc)scipy_array_inplace_divide, /*inplace_divide*/\n (binaryfunc)scipy_array_inplace_remainder, /*inplace_remainder*/\n (ternaryfunc)scipy_array_inplace_power, /*inplace_power*/\n (binaryfunc)scipy_array_inplace_left_shift, /*inplace_lshift*/\n (binaryfunc)scipy_array_inplace_right_shift, /*inplace_rshift*/\n (binaryfunc)scipy_array_inplace_bitwise_and, /*inplace_and*/\n (binaryfunc)scipy_array_inplace_bitwise_xor, /*inplace_xor*/\n (binaryfunc)scipy_array_inplace_bitwise_or, /*inplace_or*/\n\n /* Added in release 2.2 */\n\t/* The following require the Py_TPFLAGS_HAVE_CLASS flag */\n#if PY_VERSION_HEX >= 0x02020000\n\t(binaryfunc)scipy_array_floor_divide, /*nb_floor_divide*/\n\t(binaryfunc)scipy_array_true_divide, /*nb_true_divide*/\n\t(binaryfunc)scipy_array_inplace_floor_divide, /*nb_inplace_floor_divide*/\n\t(binaryfunc)scipy_array_inplace_true_divide, /*nb_inplace_true_divide*/\n#endif\n};\n\nstatic PyObject *_scipy_getattr(PyArrayObject *self, char *name) {\n PyArrayObject *ret;\n\t\n if (strcmp(name, \"M\") == 0) {\n\tPyObject *fm, *o;\n\t\n /* Call the array constructor registered as matrix_base.matrix\n\t or else raise exception if nothing registered */\n\t\t\n\t/* Import matrix_base module */\n\tfm = PyImport_ImportModule(\"scipy_base.matrix_base\");\n\to = PyObject_CallMethod(fm,\"matrix\",\"O\",(PyObject *)self);\n\tif (ret == NULL) {\n\t PyErr_SetString(PyExc_ReferenceError, \"Error using scipy_base.matrix_base.matrix to construct matrix representation\");\n\t Py_XDECREF(fm);\n\t return NULL;\n\t}\n\tPy_XDECREF(fm);\t\n\treturn o;\n }\n\n return (BackupPyArray_Type.tp_getattr)((void *)self, name);\n}\n\n\nvoid scipy_numeric_alter(void) {\n \n (PyArray_Type).tp_name = _scipy_array_str;\n (PyArray_Type).tp_getattr = (getattrfunc)_scipy_getattr;\n memcpy((PyArray_Type).tp_as_mapping, &scipy_array_as_mapping,\n\t sizeof(PyMappingMethods));\n memcpy((PyArray_Type).tp_as_number, &scipy_array_as_number,\n sizeof(PyNumberMethods));\n\n (PyUFunc_Type).tp_call = (ternaryfunc)scipy_ufunc_call;\n (PyUFunc_Type).tp_name = _scipy_ufunc_str;\n}\n\nstatic char numeric_alter_doc[] = \"alter_numeric() update the behavior of Numeric objects.\\n\\n 1. Change coercion rules so that multiplying by a scalar does not upcast.\\n 2. Add index and mask slicing capability to Numeric arrays.\\n 3. Add .M attribute to Numeric arrays for returning a Matrix 4. (TODO) Speed enhancements.\\n\\nThis call changes the behavior for ALL Numeric arrays currently defined\\n and to be defined in the future. The old behavior can be restored for ALL\\n arrays using numeric_restore().\";\n\nstatic PyObject *numeric_behavior_alter(PyObject *self, PyObject *args)\n{\n\n if (!PyArg_ParseTuple ( args, \"\")) return NULL;\n\n scipy_numeric_save();\n scipy_numeric_alter();\n Py_INCREF(Py_None);\n return Py_None;\n}\n\nstatic char numeric_restore_doc[] = \"restore_numeric() restore the default behavior of Numeric objects.\\n\\n SEE alter_numeric.\\n\";\n\nstatic PyObject *numeric_behavior_restore(PyObject *self, PyObject *args)\n{\n\n if (!PyArg_ParseTuple ( args, \"\")) return NULL;\n scipy_numeric_restore();\n Py_INCREF(Py_None);\n return Py_None;\n}\n\n\n/* Initialization function for the module (*must* be called initArray) */\nstatic struct PyMethodDef methods[] = {\n {\"alter_numeric\", numeric_behavior_alter, METH_VARARGS, \n numeric_alter_doc},\n {\"restore_numeric\", numeric_behavior_restore, METH_VARARGS, \n numeric_restore_doc},\n {NULL,\t\tNULL, 0}\t\t/* sentinel */\n};\n\nDL_EXPORT(void) initfastumath(void) {\n PyObject *m, *d, *s, *f1;\n double pinf, pzero, nan;\n \n /* Create the module and add the functions */\n m = Py_InitModule(\"fastumath\", methods); \n\n /* Import the array and ufunc objects */\n import_array();\n import_ufunc();\n\n /* Add some symbolic constants to the module */\n d = PyModule_GetDict(m);\n\n s = PyString_FromString(\"2.3\");\n PyDict_SetItemString(d, \"__version__\", s);\n Py_DECREF(s);\n\n /* Load the ufunc operators into the array module's namespace */\n InitOperators(d); \n \n /* Import Fastumath module */\n scipy_SetNumericOps(d);\n\n PyDict_SetItemString(d, \"pi\", s = PyFloat_FromDouble(atan(1.0) * 4.0));\n Py_DECREF(s);\n PyDict_SetItemString(d, \"e\", s = PyFloat_FromDouble(exp(1.0)));\n Py_DECREF(s);\n pinf = pinf_init();\n PyDict_SetItemString(d, \"PINF\", s = PyFloat_FromDouble(pinf));\n Py_DECREF(s);\n PyDict_SetItemString(d, \"NINF\", s = PyFloat_FromDouble(-pinf));\n Py_DECREF(s);\n pzero = pzero_init();\n PyDict_SetItemString(d, \"PZERO\", s = PyFloat_FromDouble(pzero));\n Py_DECREF(s);\n PyDict_SetItemString(d, \"NZERO\", s = PyFloat_FromDouble(-pzero));\n Py_DECREF(s);\n nan = pinf / pinf;\n PyDict_SetItemString(d, \"NAN\", s = PyFloat_FromDouble(nan));\n Py_DECREF(s);\n\n f1 = PyDict_GetItemString(d, \"conjugate\"); /* Borrowed reference */\n\n /* Setup the array object's numerical structures */\n PyArray_SetNumericOps(d);\n\n PyDict_SetItemString(d, \"conj\", f1); /* shorthand for conjugate */\n \n /* Check for errors */\n if (PyErr_Occurred())\n\tPy_FatalError(\"can't initialize module fastumath\");\n}\n\n", "source_code_before": "#include \n#include \"Python.h\"\n#include \"Numeric/arrayobject.h\"\n#include \"Numeric/ufuncobject.h\"\n#include \"abstract.h\"\n#include \"mconf_lite.h\"\n\n/* Fast umath module whose functions do not check for range and domain\n errors.\n\n Replacement for umath + additions for isnan, isfinite, and isinf\n Also allows comparison operations on complex numbers (just compares\n the real part) and logical operations.\n\n All logical operations return UBYTE arrays except for \n logical_and, logical_or, and logical_xor\n which return their type so that reduce works correctly on them....\n*/\n\n#if defined _ISOC99_SOURCE || defined _XOPEN_SOURCE_EXTENDED \\\n || defined _BSD_SOURCE || defined _SVID_SOURCE\n#define HAVE_INVERSE_HYPERBOLIC 1\n#endif\n\nstatic PyObject *Array0d_FromDouble(double); \n/* Wrapper to include the correct version */\n\n/* Complex functions */\n\n\n#if !defined(HAVE_INVERSE_HYPERBOLIC)\nstatic double acosh(double x)\n{\n return log(x + sqrt((x-1.0)*(x+1.0)));\n}\n\nstatic double asinh(double xx)\n{\n double x;\n int sign;\n if (xx < 0.0) {\n\tsign = -1;\n\tx = -xx;\n }\n else {\n\tsign = 1;\n\tx = xx;\n }\n return sign*log(x + sqrt(x*x+1.0));\n}\n\nstatic double atanh(double x)\n{\n return 0.5*log((1.0+x)/(1.0-x));\n}\n#endif\n\n#if defined(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 double yx;\n\n x = fabs(x);\n y = fabs(y);\n if (x < y) {\n\tdouble temp = x;\n\tx = y;\n\ty = temp;\n }\n if (x == 0.)\n\treturn 0.;\n else {\n\tyx = y/x;\n\treturn x*sqrt(1.+yx*yx);\n }\n}\n#endif\n\n#ifdef i860\n/* Cray APP has bogus definition of HUGE_VAL in */\n#undef HUGE_VAL\n#endif\n\n#ifdef HUGE_VAL\n#define CHECK(x) if (errno != 0) ; \telse if (-HUGE_VAL <= (x) && (x) <= HUGE_VAL) ; \telse errno = ERANGE\n#else\n#define CHECK(x) /* Don't know how to check */\n#endif\n\n/* constants */\nstatic Py_complex c_1 = {1., 0.};\nstatic Py_complex c_half = {0.5, 0.};\nstatic Py_complex c_i = {0., 1.};\nstatic Py_complex c_i2 = {0., 0.5};\n/*\nstatic Py_complex c_mi = {0., -1.};\nstatic Py_complex c_pi2 = {M_PI/2., 0.};\n*/\n\nstatic Py_complex\nc_sum_(Py_complex a, Py_complex b)\n{\n Py_complex r;\n r.real = a.real + b.real;\n r.imag = a.imag + b.imag;\n return r;\n}\n\nstatic Py_complex\nc_diff_(Py_complex a, Py_complex b)\n{\n Py_complex r;\n r.real = a.real - b.real;\n r.imag = a.imag - b.imag;\n return r;\n}\n\nstatic Py_complex\nc_neg_(Py_complex a)\n{\n Py_complex r;\n r.real = -a.real;\n r.imag = -a.imag;\n return r;\n}\n\nstatic Py_complex\nc_prod_(Py_complex a, Py_complex b)\n{\n Py_complex r;\n r.real = a.real*b.real - a.imag*b.imag;\n r.imag = a.real*b.imag + a.imag*b.real;\n return r;\n}\n\nstatic Py_complex\nc_pow_(Py_complex a, Py_complex b)\n{\n Py_complex r;\n double vabs,len,at,phase;\n if (b.real == 0. && b.imag == 0.) {\n\tr.real = 1.;\n\tr.imag = 0.;\n }\n else if (a.real == 0. && a.imag == 0.) {\n\tif (b.imag != 0. || b.real < 0.)\n\t errno = EDOM;\n\tr.real = 0.;\n\tr.imag = 0.;\n }\n else {\n\tvabs = hypot(a.real,a.imag);\n\tlen = pow(vabs,b.real);\n\tat = atan2(a.imag, a.real);\n\tphase = at*b.real;\n\tif (b.imag != 0.0) {\n\t len /= exp(at*b.imag);\n\t phase += b.imag*log(vabs);\n\t}\n\tr.real = len*cos(phase);\n\tr.imag = len*sin(phase);\n }\n return r;\n}\n\n/* First, the C functions that do the real work */\n\nstatic Py_complex \nc_quot_fast(Py_complex a, Py_complex b)\n{\n /******************************************************************/\n \n /* This algorithm is better, and is pretty obvious: first divide the\n * numerators and denominator by whichever of {b.real, b.imag} has\n * larger magnitude. The earliest reference I found was to CACM\n * Algorithm 116 (Complex Division, Robert L. Smith, Stanford\n * University). As usual, though, we're still ignoring all IEEE\n * endcases.\n */\n Py_complex r; /* the result */\n\n const double abs_breal = b.real < 0 ? -b.real : b.real;\n const double abs_bimag = b.imag < 0 ? -b.imag : b.imag;\n\n if ((b.real == 0.0) && (b.imag == 0.0)) {\n r.real = a.real / b.real;\n r.imag = a.imag / b.imag;\n\t/* Using matlab's convention (x+0j is x):\n\t (0+0j)/0 -> nan+0j\n\t (0+xj)/0 -> nan+sign(x)*infj\n\t (x+0j)/0 -> sign(x)*inf+0j\n\t*/\n\tif (a.imag == 0.0) {r.imag = 0.0;}\n return r;\n }\n if (abs_breal >= abs_bimag) {\n\t/* divide tops and bottom by b.real */\n\tconst double ratio = b.imag / b.real;\n\tconst double denom = b.real + b.imag * ratio;\n\tr.real = (a.real + a.imag * ratio) / denom;\n\tr.imag = (a.imag - a.real * ratio) / denom;\n }\n else {\n\t/* divide tops and bottom by b.imag */\n\tconst double ratio = b.real / b.imag;\n\tconst double denom = b.real * ratio + b.imag;\n\tr.real = (a.real * ratio + a.imag) / denom;\n\tr.imag = (a.imag * ratio - a.real) / denom;\n }\n return r;\n}\n\n#if PY_VERSION_HEX >= 0x02020000\nstatic Py_complex \nc_quot_floor_fast(Py_complex a, Py_complex b)\n{\n /* Not really sure what to do here, but it looks like Python takes the \n floor of the real part and returns that as the answer. So, we will do the same.\n */\n Py_complex r;\n\n r = c_quot_fast(a, b);\n r.imag = 0.0;\n r.real = floor(r.real);\n return r;\n}\n#endif\n\nstatic Py_complex \nc_sqrt(Py_complex x)\n{\n Py_complex r;\n double s,d;\n if (x.real == 0. && x.imag == 0.)\n\tr = x;\n else {\n\ts = sqrt(0.5*(fabs(x.real) + hypot(x.real,x.imag)));\n\td = 0.5*x.imag/s;\n\tif (x.real > 0.) {\n\t r.real = s;\n\t r.imag = d;\n\t}\n\telse if (x.imag >= 0.) {\n\t r.real = d;\n\t r.imag = s;\n\t}\n\telse {\n\t r.real = -d;\n\t r.imag = -s;\n\t}\n }\n return r;\n}\n\nstatic Py_complex \nc_log(Py_complex x)\n{\n Py_complex r;\n double l = hypot(x.real,x.imag);\n r.imag = atan2(x.imag, x.real);\n r.real = log(l);\n return r;\n}\n\nstatic Py_complex \nc_prodi(Py_complex x)\n{\n Py_complex r;\n r.real = -x.imag;\n r.imag = x.real;\n return r;\n}\n\nstatic Py_complex \nc_acos(Py_complex x)\n{\n return c_neg_(c_prodi(c_log(c_sum_(x,c_prod_(c_i,\n\t\t\t\t\t c_sqrt(c_diff_(c_1,c_prod_(x,x))))))));\n}\n\nstatic Py_complex \nc_acosh(Py_complex x)\n{\n return c_log(c_sum_(x,c_prod_(c_i,\n\t\t\t\tc_sqrt(c_diff_(c_1,c_prod_(x,x))))));\n}\n\nstatic Py_complex \nc_asin(Py_complex x)\n{\n return c_neg_(c_prodi(c_log(c_sum_(c_prod_(c_i,x),\n\t\t\t\t c_sqrt(c_diff_(c_1,c_prod_(x,x)))))));\n}\n\nstatic Py_complex \nc_asinh(Py_complex x)\n{\n return c_neg_(c_log(c_diff_(c_sqrt(c_sum_(c_1,c_prod_(x,x))),x)));\n}\n\nstatic Py_complex \nc_atan(Py_complex x)\n{\n return c_prod_(c_i2,c_log(c_quot_fast(c_sum_(c_i,x),c_diff_(c_i,x))));\n}\n\nstatic Py_complex \nc_atanh(Py_complex x)\n{\n return c_prod_(c_half,c_log(c_quot_fast(c_sum_(c_1,x),c_diff_(c_1,x))));\n}\n\nstatic Py_complex \nc_cos(Py_complex x)\n{\n Py_complex r;\n r.real = cos(x.real)*cosh(x.imag);\n r.imag = -sin(x.real)*sinh(x.imag);\n return r;\n}\n\nstatic Py_complex \nc_cosh(Py_complex x)\n{\n Py_complex r;\n r.real = cos(x.imag)*cosh(x.real);\n r.imag = sin(x.imag)*sinh(x.real);\n return r;\n}\n\nstatic Py_complex \nc_exp(Py_complex x)\n{\n Py_complex r;\n double l = exp(x.real);\n r.real = l*cos(x.imag);\n r.imag = l*sin(x.imag);\n return r;\n}\n\nstatic Py_complex \nc_log10(Py_complex x)\n{\n Py_complex r;\n double l = hypot(x.real,x.imag);\n r.imag = atan2(x.imag, x.real)/log(10.);\n r.real = log10(l);\n return r;\n}\n\nstatic Py_complex \nc_sin(Py_complex x)\n{\n Py_complex r;\n r.real = sin(x.real)*cosh(x.imag);\n r.imag = cos(x.real)*sinh(x.imag);\n return r;\n}\n\nstatic Py_complex \nc_sinh(Py_complex x)\n{\n Py_complex r;\n r.real = cos(x.imag)*sinh(x.real);\n r.imag = sin(x.imag)*cosh(x.real);\n return r;\n}\n\nstatic Py_complex \nc_tan(Py_complex x)\n{\n Py_complex r;\n double sr,cr,shi,chi;\n double rs,is,rc,ic;\n double d;\n sr = sin(x.real);\n cr = cos(x.real);\n shi = sinh(x.imag);\n chi = cosh(x.imag);\n rs = sr*chi;\n is = cr*shi;\n rc = cr*chi;\n ic = -sr*shi;\n d = rc*rc + ic*ic;\n r.real = (rs*rc+is*ic)/d;\n r.imag = (is*rc-rs*ic)/d;\n return r;\n}\n\nstatic Py_complex \nc_tanh(Py_complex x)\n{\n Py_complex r;\n double si,ci,shr,chr;\n double rs,is,rc,ic;\n double d;\n si = sin(x.imag);\n ci = cos(x.imag);\n shr = sinh(x.real);\n chr = cosh(x.real);\n rs = ci*shr;\n is = si*chr;\n rc = ci*chr;\n ic = si*shr;\n d = rc*rc + ic*ic;\n r.real = (rs*rc+is*ic)/d;\n r.imag = (is*rc-rs*ic)/d;\n return r;\n}\n\n\n#ifdef PyArray_UNSIGNED_TYPES\n#include \"fastumath_unsigned.inc\"\n#else\n#include \"fastumath_nounsigned.inc\"\n#endif\n\nstatic PyObject *Array0d_FromDouble(double val){\n PyArrayObject *a;\n a = (PyArrayObject *)PyArray_FromDims(0,NULL,PyArray_DOUBLE);\n memcpy(a->data,(char *)(&val),a->descr->elsize);\n return (PyObject *)a;\n}\n\nstatic double pinf_init(void) {\n double mul = 1e10;\n double tmp = 0.0;\n double pinf;\n\n pinf = mul;\n for (;;) {\n\tpinf *= mul;\n\tif (pinf == tmp) break;\n\ttmp = pinf;\n }\n return pinf;\n}\n\nstatic double pzero_init(void) {\n double div = 1e10;\n double tmp = 0.0;\n double pinf;\n\n pinf = div;\n for (;;) {\n\tpinf /= div;\n\tif (pinf == tmp) break;\n\ttmp = pinf;\n }\n return pinf;\n}\n\n/* Initialization function for the module (*must* be called initArray) */\n\nstatic struct PyMethodDef methods[] = {\n {NULL,\t\tNULL, 0}\t\t/* sentinel */\n};\n\nDL_EXPORT(void) initfastumath(void) {\n PyObject *m, *d, *s, *f1;\n double pinf, pzero, nan;\n \n /* Create the module and add the functions */\n m = Py_InitModule(\"fastumath\", methods); \n\n /* Import the array and ufunc objects */\n import_array();\n import_ufunc();\n\n /* Add some symbolic constants to the module */\n d = PyModule_GetDict(m);\n\n s = PyString_FromString(\"2.3\");\n PyDict_SetItemString(d, \"__version__\", s);\n Py_DECREF(s);\n\n /* Load the ufunc operators into the array module's namespace */\n InitOperators(d); \n \n PyDict_SetItemString(d, \"pi\", s = PyFloat_FromDouble(atan(1.0) * 4.0));\n Py_DECREF(s);\n PyDict_SetItemString(d, \"e\", s = PyFloat_FromDouble(exp(1.0)));\n Py_DECREF(s);\n pinf = pinf_init();\n PyDict_SetItemString(d, \"PINF\", s = PyFloat_FromDouble(pinf));\n Py_DECREF(s);\n PyDict_SetItemString(d, \"NINF\", s = PyFloat_FromDouble(-pinf));\n Py_DECREF(s);\n pzero = pzero_init();\n PyDict_SetItemString(d, \"PZERO\", s = PyFloat_FromDouble(pzero));\n Py_DECREF(s);\n PyDict_SetItemString(d, \"NZERO\", s = PyFloat_FromDouble(-pzero));\n Py_DECREF(s);\n nan = pinf / pinf;\n PyDict_SetItemString(d, \"NAN\", s = PyFloat_FromDouble(nan));\n Py_DECREF(s);\n\n f1 = PyDict_GetItemString(d, \"conjugate\"); /* Borrowed reference */\n\n /* Setup the array object's numerical structures */\n PyArray_SetNumericOps(d);\n\n PyDict_SetItemString(d, \"conj\", f1); /* shorthand for conjugate */\n \n /* Check for errors */\n if (PyErr_Occurred())\n\tPy_FatalError(\"can't initialize module fastumath\");\n}\n\n", "methods": [ { "name": "acosh", "long_name": "acosh( double x)", "filename": "fastumathmodule.c", "nloc": 4, "complexity": 1, "token_count": 28, "parameters": [ "x" ], "start_line": 33, "end_line": 36, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 4, "top_nesting_level": 0 }, { "name": "asinh", "long_name": "asinh( double xx)", "filename": "fastumathmodule.c", "nloc": 14, "complexity": 2, "token_count": 59, "parameters": [ "xx" ], "start_line": 38, "end_line": 51, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 14, "top_nesting_level": 0 }, { "name": "atanh", "long_name": "atanh( double x)", "filename": "fastumathmodule.c", "nloc": 4, "complexity": 1, "token_count": 25, "parameters": [ "x" ], "start_line": 53, "end_line": 56, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 4, "top_nesting_level": 0 }, { "name": "hypot", "long_name": "hypot( double x , double y)", "filename": "fastumathmodule.c", "nloc": 17, "complexity": 3, "token_count": 78, "parameters": [ "x", "y" ], "start_line": 64, "end_line": 81, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 18, "top_nesting_level": 0 }, { "name": "c_sum_", "long_name": "c_sum_( Py_complex a , Py_complex b)", "filename": "fastumathmodule.c", "nloc": 7, "complexity": 1, "token_count": 40, "parameters": [ "a", "b" ], "start_line": 106, "end_line": 112, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 7, "top_nesting_level": 0 }, { "name": "c_diff_", "long_name": "c_diff_( Py_complex a , Py_complex b)", "filename": "fastumathmodule.c", "nloc": 7, "complexity": 1, "token_count": 40, "parameters": [ "a", "b" ], "start_line": 115, "end_line": 121, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 7, "top_nesting_level": 0 }, { "name": "c_neg_", "long_name": "c_neg_( Py_complex a)", "filename": "fastumathmodule.c", "nloc": 7, "complexity": 1, "token_count": 31, "parameters": [ "a" ], "start_line": 124, "end_line": 130, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 7, "top_nesting_level": 0 }, { "name": "c_prod_", "long_name": "c_prod_( Py_complex a , Py_complex b)", "filename": "fastumathmodule.c", "nloc": 7, "complexity": 1, "token_count": 56, "parameters": [ "a", "b" ], "start_line": 133, "end_line": 139, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 7, "top_nesting_level": 0 }, { "name": "c_pow_", "long_name": "c_pow_( Py_complex a , Py_complex b)", "filename": "fastumathmodule.c", "nloc": 28, "complexity": 8, "token_count": 203, "parameters": [ "a", "b" ], "start_line": 142, "end_line": 169, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 28, "top_nesting_level": 0 }, { "name": "c_quot_fast", "long_name": "c_quot_fast( Py_complex a , Py_complex b)", "filename": "fastumathmodule.c", "nloc": 25, "complexity": 7, "token_count": 252, "parameters": [ "a", "b" ], "start_line": 174, "end_line": 216, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 43, "top_nesting_level": 0 }, { "name": "c_quot_floor_fast", "long_name": "c_quot_floor_fast( Py_complex a , Py_complex b)", "filename": "fastumathmodule.c", "nloc": 8, "complexity": 1, "token_count": 42, "parameters": [ "a", "b" ], "start_line": 220, "end_line": 231, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 12, "top_nesting_level": 0 }, { "name": "c_sqrt", "long_name": "c_sqrt( Py_complex x)", "filename": "fastumathmodule.c", "nloc": 24, "complexity": 5, "token_count": 138, "parameters": [ "x" ], "start_line": 235, "end_line": 258, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 24, "top_nesting_level": 0 }, { "name": "c_log", "long_name": "c_log( Py_complex x)", "filename": "fastumathmodule.c", "nloc": 8, "complexity": 1, "token_count": 51, "parameters": [ "x" ], "start_line": 261, "end_line": 268, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 8, "top_nesting_level": 0 }, { "name": "c_prodi", "long_name": "c_prodi( Py_complex x)", "filename": "fastumathmodule.c", "nloc": 7, "complexity": 1, "token_count": 30, "parameters": [ "x" ], "start_line": 271, "end_line": 277, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 7, "top_nesting_level": 0 }, { "name": "c_acos", "long_name": "c_acos( Py_complex x)", "filename": "fastumathmodule.c", "nloc": 5, "complexity": 1, "token_count": 42, "parameters": [ "x" ], "start_line": 280, "end_line": 284, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 5, "top_nesting_level": 0 }, { "name": "c_acosh", "long_name": "c_acosh( Py_complex x)", "filename": "fastumathmodule.c", "nloc": 5, "complexity": 1, "token_count": 36, "parameters": [ "x" ], "start_line": 287, "end_line": 291, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 5, "top_nesting_level": 0 }, { "name": "c_asin", "long_name": "c_asin( Py_complex x)", "filename": "fastumathmodule.c", "nloc": 5, "complexity": 1, "token_count": 42, "parameters": [ "x" ], "start_line": 294, "end_line": 298, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 5, "top_nesting_level": 0 }, { "name": "c_asinh", "long_name": "c_asinh( Py_complex x)", "filename": "fastumathmodule.c", "nloc": 4, "complexity": 1, "token_count": 34, "parameters": [ "x" ], "start_line": 301, "end_line": 304, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 4, "top_nesting_level": 0 }, { "name": "c_atan", "long_name": "c_atan( Py_complex x)", "filename": "fastumathmodule.c", "nloc": 4, "complexity": 1, "token_count": 33, "parameters": [ "x" ], "start_line": 307, "end_line": 310, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 4, "top_nesting_level": 0 }, { "name": "c_atanh", "long_name": "c_atanh( Py_complex x)", "filename": "fastumathmodule.c", "nloc": 4, "complexity": 1, "token_count": 33, "parameters": [ "x" ], "start_line": 313, "end_line": 316, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 4, "top_nesting_level": 0 }, { "name": "c_cos", "long_name": "c_cos( Py_complex x)", "filename": "fastumathmodule.c", "nloc": 7, "complexity": 1, "token_count": 50, "parameters": [ "x" ], "start_line": 319, "end_line": 325, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 7, "top_nesting_level": 0 }, { "name": "c_cosh", "long_name": "c_cosh( Py_complex x)", "filename": "fastumathmodule.c", "nloc": 7, "complexity": 1, "token_count": 49, "parameters": [ "x" ], "start_line": 328, "end_line": 334, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 7, "top_nesting_level": 0 }, { "name": "c_exp", "long_name": "c_exp( Py_complex x)", "filename": "fastumathmodule.c", "nloc": 8, "complexity": 1, "token_count": 49, "parameters": [ "x" ], "start_line": 337, "end_line": 344, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 8, "top_nesting_level": 0 }, { "name": "c_log10", "long_name": "c_log10( Py_complex x)", "filename": "fastumathmodule.c", "nloc": 8, "complexity": 1, "token_count": 56, "parameters": [ "x" ], "start_line": 347, "end_line": 354, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 8, "top_nesting_level": 0 }, { "name": "c_sin", "long_name": "c_sin( Py_complex x)", "filename": "fastumathmodule.c", "nloc": 7, "complexity": 1, "token_count": 49, "parameters": [ "x" ], "start_line": 357, "end_line": 363, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 7, "top_nesting_level": 0 }, { "name": "c_sinh", "long_name": "c_sinh( Py_complex x)", "filename": "fastumathmodule.c", "nloc": 7, "complexity": 1, "token_count": 49, "parameters": [ "x" ], "start_line": 366, "end_line": 372, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 7, "top_nesting_level": 0 }, { "name": "c_tan", "long_name": "c_tan( Py_complex x)", "filename": "fastumathmodule.c", "nloc": 19, "complexity": 1, "token_count": 137, "parameters": [ "x" ], "start_line": 375, "end_line": 393, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 19, "top_nesting_level": 0 }, { "name": "c_tanh", "long_name": "c_tanh( Py_complex x)", "filename": "fastumathmodule.c", "nloc": 19, "complexity": 1, "token_count": 136, "parameters": [ "x" ], "start_line": 396, "end_line": 414, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 19, "top_nesting_level": 0 }, { "name": "pinf_init", "long_name": "pinf_init()", "filename": "fastumathmodule.c", "nloc": 12, "complexity": 3, "token_count": 50, "parameters": [], "start_line": 432, "end_line": 444, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 13, "top_nesting_level": 0 }, { "name": "pzero_init", "long_name": "pzero_init()", "filename": "fastumathmodule.c", "nloc": 12, "complexity": 3, "token_count": 50, "parameters": [], "start_line": 446, "end_line": 458, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 13, "top_nesting_level": 0 }, { "name": "scipy_numeric_save", "long_name": "scipy_numeric_save()", "filename": "fastumathmodule.c", "nloc": 17, "complexity": 2, "token_count": 125, "parameters": [], "start_line": 479, "end_line": 499, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 21, "top_nesting_level": 0 }, { "name": "scipy_numeric_restore", "long_name": "scipy_numeric_restore()", "filename": "fastumathmodule.c", "nloc": 16, "complexity": 2, "token_count": 120, "parameters": [], "start_line": 501, "end_line": 520, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 20, "top_nesting_level": 0 }, { "name": "_scipy_getattr", "long_name": "_scipy_getattr( PyArrayObject * self , char * name)", "filename": "fastumathmodule.c", "nloc": 16, "complexity": 3, "token_count": 107, "parameters": [ "self", "name" ], "start_line": 586, "end_line": 608, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 23, "top_nesting_level": 0 }, { "name": "scipy_numeric_alter", "long_name": "scipy_numeric_alter()", "filename": "fastumathmodule.c", "nloc": 10, "complexity": 1, "token_count": 78, "parameters": [], "start_line": 611, "end_line": 622, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 12, "top_nesting_level": 0 }, { "name": "numeric_behavior_alter", "long_name": "numeric_behavior_alter( PyObject * self , PyObject * args)", "filename": "fastumathmodule.c", "nloc": 8, "complexity": 2, "token_count": 41, "parameters": [ "self", "args" ], "start_line": 626, "end_line": 635, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 10, "top_nesting_level": 0 }, { "name": "numeric_behavior_restore", "long_name": "numeric_behavior_restore( PyObject * self , PyObject * args)", "filename": "fastumathmodule.c", "nloc": 7, "complexity": 2, "token_count": 37, "parameters": [ "self", "args" ], "start_line": 639, "end_line": 646, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 8, "top_nesting_level": 0 }, { "name": "initfastumath", "long_name": "initfastumath()", "filename": "fastumathmodule.c", "nloc": 35, "complexity": 2, "token_count": 275, "parameters": [], "start_line": 658, "end_line": 710, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 53, "top_nesting_level": 0 } ], "methods_before": [ { "name": "acosh", "long_name": "acosh( double x)", "filename": "fastumathmodule.c", "nloc": 4, "complexity": 1, "token_count": 28, "parameters": [ "x" ], "start_line": 32, "end_line": 35, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 4, "top_nesting_level": 0 }, { "name": "asinh", "long_name": "asinh( double xx)", "filename": "fastumathmodule.c", "nloc": 14, "complexity": 2, "token_count": 59, "parameters": [ "xx" ], "start_line": 37, "end_line": 50, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 14, "top_nesting_level": 0 }, { "name": "atanh", "long_name": "atanh( double x)", "filename": "fastumathmodule.c", "nloc": 4, "complexity": 1, "token_count": 25, "parameters": [ "x" ], "start_line": 52, "end_line": 55, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 4, "top_nesting_level": 0 }, { "name": "hypot", "long_name": "hypot( double x , double y)", "filename": "fastumathmodule.c", "nloc": 17, "complexity": 3, "token_count": 78, "parameters": [ "x", "y" ], "start_line": 63, "end_line": 80, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 18, "top_nesting_level": 0 }, { "name": "c_sum_", "long_name": "c_sum_( Py_complex a , Py_complex b)", "filename": "fastumathmodule.c", "nloc": 7, "complexity": 1, "token_count": 40, "parameters": [ "a", "b" ], "start_line": 105, "end_line": 111, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 7, "top_nesting_level": 0 }, { "name": "c_diff_", "long_name": "c_diff_( Py_complex a , Py_complex b)", "filename": "fastumathmodule.c", "nloc": 7, "complexity": 1, "token_count": 40, "parameters": [ "a", "b" ], "start_line": 114, "end_line": 120, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 7, "top_nesting_level": 0 }, { "name": "c_neg_", "long_name": "c_neg_( Py_complex a)", "filename": "fastumathmodule.c", "nloc": 7, "complexity": 1, "token_count": 31, "parameters": [ "a" ], "start_line": 123, "end_line": 129, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 7, "top_nesting_level": 0 }, { "name": "c_prod_", "long_name": "c_prod_( Py_complex a , Py_complex b)", "filename": "fastumathmodule.c", "nloc": 7, "complexity": 1, "token_count": 56, "parameters": [ "a", "b" ], "start_line": 132, "end_line": 138, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 7, "top_nesting_level": 0 }, { "name": "c_pow_", "long_name": "c_pow_( Py_complex a , Py_complex b)", "filename": "fastumathmodule.c", "nloc": 28, "complexity": 8, "token_count": 203, "parameters": [ "a", "b" ], "start_line": 141, "end_line": 168, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 28, "top_nesting_level": 0 }, { "name": "c_quot_fast", "long_name": "c_quot_fast( Py_complex a , Py_complex b)", "filename": "fastumathmodule.c", "nloc": 25, "complexity": 7, "token_count": 252, "parameters": [ "a", "b" ], "start_line": 173, "end_line": 215, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 43, "top_nesting_level": 0 }, { "name": "c_quot_floor_fast", "long_name": "c_quot_floor_fast( Py_complex a , Py_complex b)", "filename": "fastumathmodule.c", "nloc": 8, "complexity": 1, "token_count": 42, "parameters": [ "a", "b" ], "start_line": 219, "end_line": 230, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 12, "top_nesting_level": 0 }, { "name": "c_sqrt", "long_name": "c_sqrt( Py_complex x)", "filename": "fastumathmodule.c", "nloc": 24, "complexity": 5, "token_count": 138, "parameters": [ "x" ], "start_line": 234, "end_line": 257, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 24, "top_nesting_level": 0 }, { "name": "c_log", "long_name": "c_log( Py_complex x)", "filename": "fastumathmodule.c", "nloc": 8, "complexity": 1, "token_count": 51, "parameters": [ "x" ], "start_line": 260, "end_line": 267, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 8, "top_nesting_level": 0 }, { "name": "c_prodi", "long_name": "c_prodi( Py_complex x)", "filename": "fastumathmodule.c", "nloc": 7, "complexity": 1, "token_count": 30, "parameters": [ "x" ], "start_line": 270, "end_line": 276, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 7, "top_nesting_level": 0 }, { "name": "c_acos", "long_name": "c_acos( Py_complex x)", "filename": "fastumathmodule.c", "nloc": 5, "complexity": 1, "token_count": 42, "parameters": [ "x" ], "start_line": 279, "end_line": 283, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 5, "top_nesting_level": 0 }, { "name": "c_acosh", "long_name": "c_acosh( Py_complex x)", "filename": "fastumathmodule.c", "nloc": 5, "complexity": 1, "token_count": 36, "parameters": [ "x" ], "start_line": 286, "end_line": 290, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 5, "top_nesting_level": 0 }, { "name": "c_asin", "long_name": "c_asin( Py_complex x)", "filename": "fastumathmodule.c", "nloc": 5, "complexity": 1, "token_count": 42, "parameters": [ "x" ], "start_line": 293, "end_line": 297, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 5, "top_nesting_level": 0 }, { "name": "c_asinh", "long_name": "c_asinh( Py_complex x)", "filename": "fastumathmodule.c", "nloc": 4, "complexity": 1, "token_count": 34, "parameters": [ "x" ], "start_line": 300, "end_line": 303, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 4, "top_nesting_level": 0 }, { "name": "c_atan", "long_name": "c_atan( Py_complex x)", "filename": "fastumathmodule.c", "nloc": 4, "complexity": 1, "token_count": 33, "parameters": [ "x" ], "start_line": 306, "end_line": 309, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 4, "top_nesting_level": 0 }, { "name": "c_atanh", "long_name": "c_atanh( Py_complex x)", "filename": "fastumathmodule.c", "nloc": 4, "complexity": 1, "token_count": 33, "parameters": [ "x" ], "start_line": 312, "end_line": 315, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 4, "top_nesting_level": 0 }, { "name": "c_cos", "long_name": "c_cos( Py_complex x)", "filename": "fastumathmodule.c", "nloc": 7, "complexity": 1, "token_count": 50, "parameters": [ "x" ], "start_line": 318, "end_line": 324, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 7, "top_nesting_level": 0 }, { "name": "c_cosh", "long_name": "c_cosh( Py_complex x)", "filename": "fastumathmodule.c", "nloc": 7, "complexity": 1, "token_count": 49, "parameters": [ "x" ], "start_line": 327, "end_line": 333, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 7, "top_nesting_level": 0 }, { "name": "c_exp", "long_name": "c_exp( Py_complex x)", "filename": "fastumathmodule.c", "nloc": 8, "complexity": 1, "token_count": 49, "parameters": [ "x" ], "start_line": 336, "end_line": 343, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 8, "top_nesting_level": 0 }, { "name": "c_log10", "long_name": "c_log10( Py_complex x)", "filename": "fastumathmodule.c", "nloc": 8, "complexity": 1, "token_count": 56, "parameters": [ "x" ], "start_line": 346, "end_line": 353, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 8, "top_nesting_level": 0 }, { "name": "c_sin", "long_name": "c_sin( Py_complex x)", "filename": "fastumathmodule.c", "nloc": 7, "complexity": 1, "token_count": 49, "parameters": [ "x" ], "start_line": 356, "end_line": 362, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 7, "top_nesting_level": 0 }, { "name": "c_sinh", "long_name": "c_sinh( Py_complex x)", "filename": "fastumathmodule.c", "nloc": 7, "complexity": 1, "token_count": 49, "parameters": [ "x" ], "start_line": 365, "end_line": 371, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 7, "top_nesting_level": 0 }, { "name": "c_tan", "long_name": "c_tan( Py_complex x)", "filename": "fastumathmodule.c", "nloc": 19, "complexity": 1, "token_count": 137, "parameters": [ "x" ], "start_line": 374, "end_line": 392, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 19, "top_nesting_level": 0 }, { "name": "c_tanh", "long_name": "c_tanh( Py_complex x)", "filename": "fastumathmodule.c", "nloc": 19, "complexity": 1, "token_count": 136, "parameters": [ "x" ], "start_line": 395, "end_line": 413, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 19, "top_nesting_level": 0 }, { "name": "Array0d_FromDouble", "long_name": "Array0d_FromDouble( double val)", "filename": "fastumathmodule.c", "nloc": 6, "complexity": 1, "token_count": 55, "parameters": [ "val" ], "start_line": 422, "end_line": 427, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 6, "top_nesting_level": 0 }, { "name": "pinf_init", "long_name": "pinf_init()", "filename": "fastumathmodule.c", "nloc": 12, "complexity": 3, "token_count": 50, "parameters": [], "start_line": 429, "end_line": 441, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 13, "top_nesting_level": 0 }, { "name": "pzero_init", "long_name": "pzero_init()", "filename": "fastumathmodule.c", "nloc": 12, "complexity": 3, "token_count": 50, "parameters": [], "start_line": 443, "end_line": 455, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 13, "top_nesting_level": 0 }, { "name": "initfastumath", "long_name": "initfastumath()", "filename": "fastumathmodule.c", "nloc": 34, "complexity": 2, "token_count": 270, "parameters": [], "start_line": 463, "end_line": 512, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 50, "top_nesting_level": 0 } ], "changed_methods": [ { "name": "scipy_numeric_restore", "long_name": "scipy_numeric_restore()", "filename": "fastumathmodule.c", "nloc": 16, "complexity": 2, "token_count": 120, "parameters": [], "start_line": 501, "end_line": 520, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 20, "top_nesting_level": 0 }, { "name": "Array0d_FromDouble", "long_name": "Array0d_FromDouble( double val)", "filename": "fastumathmodule.c", "nloc": 6, "complexity": 1, "token_count": 55, "parameters": [ "val" ], "start_line": 422, "end_line": 427, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 6, "top_nesting_level": 0 }, { "name": "scipy_numeric_alter", "long_name": "scipy_numeric_alter()", "filename": "fastumathmodule.c", "nloc": 10, "complexity": 1, "token_count": 78, "parameters": [], "start_line": 611, "end_line": 622, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 12, "top_nesting_level": 0 }, { "name": "initfastumath", "long_name": "initfastumath()", "filename": "fastumathmodule.c", "nloc": 35, "complexity": 2, "token_count": 275, "parameters": [], "start_line": 658, "end_line": 710, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 53, "top_nesting_level": 0 }, { "name": "numeric_behavior_alter", "long_name": "numeric_behavior_alter( PyObject * self , PyObject * args)", "filename": "fastumathmodule.c", "nloc": 8, "complexity": 2, "token_count": 41, "parameters": [ "self", "args" ], "start_line": 626, "end_line": 635, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 10, "top_nesting_level": 0 }, { "name": "numeric_behavior_restore", "long_name": "numeric_behavior_restore( PyObject * self , PyObject * args)", "filename": "fastumathmodule.c", "nloc": 7, "complexity": 2, "token_count": 37, "parameters": [ "self", "args" ], "start_line": 639, "end_line": 646, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 8, "top_nesting_level": 0 }, { "name": "scipy_numeric_save", "long_name": "scipy_numeric_save()", "filename": "fastumathmodule.c", "nloc": 17, "complexity": 2, "token_count": 125, "parameters": [], "start_line": 479, "end_line": 499, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 21, "top_nesting_level": 0 }, { "name": "_scipy_getattr", "long_name": "_scipy_getattr( PyArrayObject * self , char * name)", "filename": "fastumathmodule.c", "nloc": 16, "complexity": 3, "token_count": 107, "parameters": [ "self", "name" ], "start_line": 586, "end_line": 608, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 23, "top_nesting_level": 0 } ], "nloc": 511, "complexity": 68, "token_count": 3212, "diff_parsed": { "added": [ "/* static PyObject *Array0d_FromDouble(double); */", "", "/*", " memcpy(a->data,(char *)(&val), sizeof(double));", "*/", "/* CODE BELOW is used to Update Numeric object behavior */", "", "/* A copy of the original PyArrayType structure is kept and can be used", " to restore the original Numeric behavior at any time.", "*/", "", "static PyTypeObject BackupPyArray_Type;", "static PyTypeObject BackupPyUFunc_Type;", "static PyNumberMethods backup_array_as_number;", "static PySequenceMethods backup_array_as_sequence;", "static PyMappingMethods backup_array_as_mapping;", "static PyBufferProcs backup_array_as_buffer;", "static int scipy_numeric_stored = 0;", "", "#ifndef PyUFunc_Type", "#define PyUFunc_Type PyUfunc_Type /* fix bug in Numeric < 23.3 */", "#endif", "", "/* make sure memory copy is going on with this */", "void scipy_numeric_save(void) {", "", " /* we just save copies of things we may alter. */", " if (!scipy_numeric_stored) {", " BackupPyUFunc_Type.tp_name = (PyUFunc_Type).tp_name;", " BackupPyUFunc_Type.tp_call = (PyUFunc_Type).tp_call;", "", "\tBackupPyArray_Type.tp_name = (PyArray_Type).tp_name;", "\tBackupPyArray_Type.tp_getattr = (PyArray_Type).tp_getattr;", "", "\tmemcpy(&backup_array_as_number, (PyArray_Type).tp_as_number,", "\t sizeof(PyNumberMethods));", "\tmemcpy(&backup_array_as_sequence, (PyArray_Type).tp_as_sequence,", "\t sizeof(PySequenceMethods));", "\tmemcpy(&backup_array_as_mapping, (PyArray_Type).tp_as_mapping,", "\t sizeof(PyMappingMethods));", "\tmemcpy(&backup_array_as_buffer, (PyArray_Type).tp_as_buffer,", "\t sizeof(PyBufferProcs));", "\tscipy_numeric_stored = 1;", " }", "}", "", "void scipy_numeric_restore(void) {", "", " /* restore only what was copied */", " if (scipy_numeric_stored) {", "\t(PyUFunc_Type).tp_name = BackupPyUFunc_Type.tp_name;", "\t(PyUFunc_Type).tp_call = BackupPyUFunc_Type.tp_call;", "", "\t(PyArray_Type).tp_name = BackupPyArray_Type.tp_name;", "\t(PyArray_Type).tp_getattr = BackupPyArray_Type.tp_getattr;", "", "\tmemcpy((PyArray_Type).tp_as_number, &backup_array_as_number,", "\t sizeof(PyNumberMethods));", "\tmemcpy((PyArray_Type).tp_as_sequence, &backup_array_as_sequence,", "\t sizeof(PySequenceMethods));", "\tmemcpy((PyArray_Type).tp_as_mapping, &backup_array_as_mapping,", "\t sizeof(PyMappingMethods));", "\tmemcpy((PyArray_Type).tp_as_buffer, &backup_array_as_buffer,", "\t sizeof(PyBufferProcs));", " }", "}", "", "static char *_scipy_array_str = \"array (scipy)\";", "static char *_scipy_ufunc_str = \"ufunc (scipy)\";", "", "#define MAX_DIMS 30", "#include \"_scipy_mapping.c\"", "", "static PyMappingMethods scipy_array_as_mapping = {", " (inquiry)scipy_array_length,\t\t/*mp_length*/", " (binaryfunc)scipy_array_subscript_nice, /*mp_subscript*/", " (objobjargproc)scipy_array_ass_sub,\t /*mp_ass_subscript*/", "};", "", "#define MAX_ARGS 10", "#include \"_scipy_number.c\"", "", "static PyNumberMethods scipy_array_as_number = {", " (binaryfunc)scipy_array_add, /*nb_add*/", " (binaryfunc)scipy_array_subtract, /*nb_subtract*/", " (binaryfunc)scipy_array_multiply, /*nb_multiply*/", " (binaryfunc)scipy_array_divide, /*nb_divide*/", " (binaryfunc)scipy_array_remainder, /*nb_remainder*/", " (binaryfunc)scipy_array_divmod, /*nb_divmod*/", " (ternaryfunc)scipy_array_power, /*nb_power*/", " (unaryfunc)scipy_array_negative,", " (unaryfunc)scipy_array_copy, /*nb_pos*/", " (unaryfunc)scipy_array_absolute, /*(unaryfunc)scipy_array_abs,*/", " (inquiry)scipy_array_nonzero, /*nb_nonzero*/", " (unaryfunc)scipy_array_invert, /*nb_invert*/", " (binaryfunc)scipy_array_left_shift, /*nb_lshift*/", " (binaryfunc)scipy_array_right_shift, /*nb_rshift*/", " (binaryfunc)scipy_array_bitwise_and, /*nb_and*/", " (binaryfunc)scipy_array_bitwise_xor, /*nb_xor*/", " (binaryfunc)scipy_array_bitwise_or, /*nb_or*/", " (coercion)scipy_array_coerce, /*nb_coerce*/", " (unaryfunc)scipy_array_int, /*nb_int*/", " (unaryfunc)scipy_array_long, /*nb_long*/", " (unaryfunc)scipy_array_float, /*nb_float*/", " (unaryfunc)scipy_array_oct,\t /*nb_oct*/", " (unaryfunc)scipy_array_hex,\t /*nb_hex*/", "", " /*This code adds augmented assignment functionality*/", " /*that was made available in Python 2.0*/", " (binaryfunc)scipy_array_inplace_add, /*inplace_add*/", " (binaryfunc)scipy_array_inplace_subtract, /*inplace_subtract*/", " (binaryfunc)scipy_array_inplace_multiply, /*inplace_multiply*/", " (binaryfunc)scipy_array_inplace_divide, /*inplace_divide*/", " (binaryfunc)scipy_array_inplace_remainder, /*inplace_remainder*/", " (ternaryfunc)scipy_array_inplace_power, /*inplace_power*/", " (binaryfunc)scipy_array_inplace_left_shift, /*inplace_lshift*/", " (binaryfunc)scipy_array_inplace_right_shift, /*inplace_rshift*/", " (binaryfunc)scipy_array_inplace_bitwise_and, /*inplace_and*/", " (binaryfunc)scipy_array_inplace_bitwise_xor, /*inplace_xor*/", " (binaryfunc)scipy_array_inplace_bitwise_or, /*inplace_or*/", "", " /* Added in release 2.2 */", "\t/* The following require the Py_TPFLAGS_HAVE_CLASS flag */", "#if PY_VERSION_HEX >= 0x02020000", "\t(binaryfunc)scipy_array_floor_divide, /*nb_floor_divide*/", "\t(binaryfunc)scipy_array_true_divide, /*nb_true_divide*/", "\t(binaryfunc)scipy_array_inplace_floor_divide, /*nb_inplace_floor_divide*/", "\t(binaryfunc)scipy_array_inplace_true_divide, /*nb_inplace_true_divide*/", "#endif", "};", "", "static PyObject *_scipy_getattr(PyArrayObject *self, char *name) {", " PyArrayObject *ret;", "", " if (strcmp(name, \"M\") == 0) {", "\tPyObject *fm, *o;", "", " /* Call the array constructor registered as matrix_base.matrix", "\t or else raise exception if nothing registered */", "", "\t/* Import matrix_base module */", "\tfm = PyImport_ImportModule(\"scipy_base.matrix_base\");", "\to = PyObject_CallMethod(fm,\"matrix\",\"O\",(PyObject *)self);", "\tif (ret == NULL) {", "\t PyErr_SetString(PyExc_ReferenceError, \"Error using scipy_base.matrix_base.matrix to construct matrix representation\");", "\t Py_XDECREF(fm);", "\t return NULL;", "\t}", "\tPy_XDECREF(fm);", "\treturn o;", " }", "", " return (BackupPyArray_Type.tp_getattr)((void *)self, name);", "}", "", "void scipy_numeric_alter(void) {", "", " (PyArray_Type).tp_name = _scipy_array_str;", " (PyArray_Type).tp_getattr = (getattrfunc)_scipy_getattr;", " memcpy((PyArray_Type).tp_as_mapping, &scipy_array_as_mapping,", "\t sizeof(PyMappingMethods));", " memcpy((PyArray_Type).tp_as_number, &scipy_array_as_number,", " sizeof(PyNumberMethods));", "", " (PyUFunc_Type).tp_call = (ternaryfunc)scipy_ufunc_call;", " (PyUFunc_Type).tp_name = _scipy_ufunc_str;", "}", "", "static char numeric_alter_doc[] = \"alter_numeric() update the behavior of Numeric objects.\\n\\n 1. Change coercion rules so that multiplying by a scalar does not upcast.\\n 2. Add index and mask slicing capability to Numeric arrays.\\n 3. Add .M attribute to Numeric arrays for returning a Matrix 4. (TODO) Speed enhancements.\\n\\nThis call changes the behavior for ALL Numeric arrays currently defined\\n and to be defined in the future. The old behavior can be restored for ALL\\n arrays using numeric_restore().\";", "", "static PyObject *numeric_behavior_alter(PyObject *self, PyObject *args)", "{", "", " if (!PyArg_ParseTuple ( args, \"\")) return NULL;", "", " scipy_numeric_save();", " scipy_numeric_alter();", " Py_INCREF(Py_None);", " return Py_None;", "}", "", "static char numeric_restore_doc[] = \"restore_numeric() restore the default behavior of Numeric objects.\\n\\n SEE alter_numeric.\\n\";", "", "static PyObject *numeric_behavior_restore(PyObject *self, PyObject *args)", "{", "", " if (!PyArg_ParseTuple ( args, \"\")) return NULL;", " scipy_numeric_restore();", " Py_INCREF(Py_None);", " return Py_None;", "}", "", "", "/* Initialization function for the module (*must* be called initArray) */", " {\"alter_numeric\", numeric_behavior_alter, METH_VARARGS,", " numeric_alter_doc},", " {\"restore_numeric\", numeric_behavior_restore, METH_VARARGS,", " numeric_restore_doc},", " /* Import Fastumath module */", " scipy_SetNumericOps(d);", "" ], "deleted": [ "static PyObject *Array0d_FromDouble(double);", " memcpy(a->data,(char *)(&val),a->descr->elsize);", "/* Initialization function for the module (*must* be called initArray) */" ] } }, { "old_path": "scipy_base/function_base.py", "new_path": "scipy_base/function_base.py", "filename": "function_base.py", "extension": "py", "change_type": "MODIFY", "diff": "@@ -1,13 +1,10 @@\n-\n import types\n-import Numeric\n-from Numeric import ravel, nonzero, array, choose, ones, zeros, \\\n- sometrue, alltrue, reshape\n+import numerix as _nx\n+from numerix import ravel, nonzero, array, choose, ones, zeros, \\\n+ sometrue, alltrue, reshape, alter_numeric, restore_numeric, arraymap, \\\n+ pi, _insert, multiply, add, arctan2, maximum, minimum\n from type_check import ScalarType, isscalar, asarray\n from shape_base import squeeze, atleast_1d\n-from fastumath import PINF as inf\n-from fastumath import *\n-import _compiled_base\n \n __all__ = ['round','any','all','logspace','linspace','fix','mod',\n 'select','trim_zeros','amax','amin', 'alen', 'ptp','cumsum','take',\n@@ -16,14 +13,11 @@\n 'nanargmin','nanmin','sum','vectorize','asarray_chkfinite',\n 'alter_numeric', 'restore_numeric','isaltered']\n \n-alter_numeric = _compiled_base.alter_numeric\n-restore_numeric = _compiled_base.restore_numeric\n-\n def isaltered():\n- val = str(type(array([1])))\n+ val = str(type(_nx.array([1])))\n return 'scipy' in val\n \n-round = Numeric.around\n+round = _nx.around\n \n def asarray_chkfinite(x):\n \"\"\"Like asarray except it checks to be sure no NaNs or Infs are present.\n@@ -49,7 +43,7 @@ def sum(x,axis=0): # could change default axis here\n x = asarray(x)\n if x.typecode() in ['1','s','b','w']:\n x = x.astype('l')\n- return Numeric.sum(x,axis)\n+ return _nx.sum(x,axis)\n \n \n def logspace(start,stop,num=50,endpoint=1):\n@@ -61,11 +55,11 @@ def logspace(start,stop,num=50,endpoint=1):\n if num <= 0: return array([])\n if endpoint:\n step = (stop-start)/float((num-1))\n- y = Numeric.arange(0,num) * step + start\n+ y = _nx.arange(0,num) * step + start\n else:\n step = (stop-start)/float(num)\n- y = Numeric.arange(0,num) * step + start\n- return Numeric.power(10.0,y)\n+ y = _nx.arange(0,num) * step + start\n+ return _nx.power(10.0,y)\n \n def linspace(start,stop,num=50,endpoint=1,retstep=0):\n \"\"\" Evenly spaced samples.\n@@ -76,10 +70,10 @@ def linspace(start,stop,num=50,endpoint=1,retstep=0):\n if num <= 0: return array([])\n if endpoint:\n step = (stop-start)/float((num-1))\n- y = Numeric.arange(0,num) * step + start \n+ y = _nx.arange(0,num) * step + start \n else:\n step = (stop-start)/float(num)\n- y = Numeric.arange(0,num) * step + start\n+ y = _nx.arange(0,num) * step + start\n if retstep:\n return y, step\n else:\n@@ -89,8 +83,8 @@ def fix(x):\n \"\"\" Round x to nearest integer towards zero.\n \"\"\"\n x = asarray(x)\n- y = Numeric.floor(x)\n- return Numeric.where(x<0,y+1,y)\n+ y = _nx.floor(x)\n+ return _nx.where(x<0,y+1,y)\n \n def mod(x,y):\n \"\"\" x - y*floor(x/y)\n@@ -98,7 +92,7 @@ def mod(x,y):\n For numeric arrays, x % y has the same sign as x while\n mod(x,y) has the same sign as y.\n \"\"\"\n- return x - y*Numeric.floor(x*1.0/y)\n+ return x - y*_nx.floor(x*1.0/y)\n \n def select(condlist, choicelist, default=0):\n \"\"\" Returns an array comprised from different elements of choicelist\n@@ -165,31 +159,38 @@ def take(a, indices, axis=0):\n \"\"\"Selects the elements in indices from array a along given axis.\n \"\"\"\n try:\n- a = Numeric.take(a,indices,axis)\n+ a = _nx.take(a,indices,axis)\n except ValueError: # a is scalar\n pass\n return a\n- \n-# Basic operations\n-def amax(m,axis=-1):\n- \"\"\"Returns the maximum of m along dimension axis. \n- \"\"\"\n+\n+def _no_axis_is_all(function, m, axis):\n if axis is None:\n m = ravel(m)\n axis = 0\n else:\n m = _asarray1d(m)\n- return maximum.reduce(m,axis)\n+ if _nx.which[0] == \"numeric\":\n+ r = function(m, axis)\n+ else:\n+ import numarray as _na\n+ _na.Error.pushMode(overflow=\"raise\")\n+ try:\n+ r = function(m, axis)\n+ finally:\n+ _na.Error.popMode()\n+ return r\n+ \n+# Basic operations\n+def amax(m,axis=-1): \n+ \"\"\"Returns the maximum of m along dimension axis. \n+ \"\"\"\n+ return _no_axis_is_all(maximum.reduce, m, axis)\n \n def amin(m,axis=-1):\n \"\"\"Returns the minimum of m along dimension axis.\n \"\"\"\n- if axis is None:\n- m = ravel(m)\n- axis = 0\n- else: \n- m = _asarray1d(m)\n- return minimum.reduce(m,axis)\n+ return _no_axis_is_all(minimum.reduce, m, axis)\n \n def alen(m):\n \"\"\"Returns the length of a Python object interpreted as an array\n@@ -198,45 +199,28 @@ def alen(m):\n \n # Actually from Basis, but it fits in so naturally here...\n \n+def _amin_amax(m, axis):\n+ return amax(m,axis)-amin(m,axis)\n+\n def ptp(m,axis=-1):\n \"\"\"Returns the maximum - minimum along the the given dimension\n \"\"\"\n- if axis is None:\n- m = ravel(m)\n- axis = 0\n- else:\n- m = _asarray1d(m)\n- return amax(m,axis)-amin(m,axis)\n+ return _no_axis_is_all(_amin_amax, m, axis)\n \n def cumsum(m,axis=-1):\n \"\"\"Returns the cumulative sum of the elements along the given axis\n \"\"\"\n- if axis is None:\n- m = ravel(m)\n- axis = 0\n- else:\n- m = _asarray1d(m)\n- return add.accumulate(m,axis)\n+ return _no_axis_is_all(add.accumulate, m, axis)\n \n def prod(m,axis=-1):\n \"\"\"Returns the product of the elements along the given axis\n \"\"\"\n- if axis is None:\n- m = ravel(m)\n- axis = 0\n- else:\n- m = _asarray1d(m)\n- return multiply.reduce(m,axis)\n+ return _no_axis_is_all(multiply.reduce, m, axis)\n \n def cumprod(m,axis=-1):\n \"\"\"Returns the cumulative product of the elments along the given axis\n \"\"\"\n- if axis is None:\n- m = ravel(m)\n- axis = 0\n- else:\n- m = _asarray1d(m)\n- return multiply.accumulate(m,axis)\n+ return _no_axis_is_all(multiply.accumulate, m, axis)\n \n def diff(x, n=1,axis=-1):\n \"\"\"Calculates the nth order, discrete difference along given axis.\n@@ -255,7 +239,6 @@ def diff(x, n=1,axis=-1):\n return diff(x[slice1]-x[slice2], n-1, axis=axis)\n else:\n return x[slice1]-x[slice2]\n-\n \n def angle(z,deg=0):\n \"\"\"Return the angle of complex argument z.\"\"\"\n@@ -282,9 +265,9 @@ def unwrap(p,discont=pi,axis=-1):\n slice1 = [slice(None,None)]*nd # full slices\n slice1[axis] = slice(1,None)\n ddmod = mod(dd+pi,2*pi)-pi\n- Numeric.putmask(ddmod,(ddmod==-pi) & (dd > 0),pi)\n+ _nx.putmask(ddmod,(ddmod==-pi) & (dd > 0),pi)\n ph_correct = ddmod - dd;\n- Numeric.putmask(ph_correct,abs(dd) 1:\n return diff(x[slice1]-x[slice2], n-1, axis=axis)\n else:\n return x[slice1]-x[slice2]\n \ndef angle(z,deg=0):\n \"\"\"Return the angle of complex argument z.\"\"\"\n if deg:\n fact = 180/pi\n else:\n fact = 1.0\n z = asarray(z)\n if z.typecode() in ['D','F']:\n zimag = z.imag\n zreal = z.real\n else:\n zimag = 0\n zreal = z\n return arctan2(zimag,zreal) * fact\n\ndef unwrap(p,discont=pi,axis=-1):\n \"\"\"unwraps radian phase p by changing absolute jumps greater than\n discont to their 2*pi complement along the given axis.\n \"\"\"\n p = asarray(p)\n nd = len(p.shape)\n dd = diff(p,axis=axis)\n slice1 = [slice(None,None)]*nd # full slices\n slice1[axis] = slice(1,None)\n ddmod = mod(dd+pi,2*pi)-pi\n _nx.putmask(ddmod,(ddmod==-pi) & (dd > 0),pi)\n ph_correct = ddmod - dd;\n _nx.putmask(ph_correct,abs(dd)>> import scipy\n >>> a = array((0,0,0,1,2,3,2,1,0))\n >>> scipy.trim_zeros(a)\n array([1, 2, 3, 2, 1])\n \"\"\"\n first = 0\n if 'f' in trim or '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 or 'B' in trim:\n for i in filt[::-1]:\n if i != 0.: break\n else: last = last - 1\n return filt[first:last]\n\ndef unique(inseq):\n \"\"\"Returns unique items in 1-dimensional sequence.\n \"\"\"\n set = {}\n for item in inseq:\n set[item] = None\n return asarray(set.keys())\n\ndef where(condition,x=None,y=None):\n \"\"\"If x and y are both None, then return the (1-d equivalent) indices\n where condition is true. Otherwise, return an array shaped like\n condition with elements of x and y in the places where condition is\n true or false respectively.\n \"\"\"\n if (x is None) and (y is None):\n # Needs work for multidimensional arrays\n return nonzero(ravel(condition))\n else:\n return choose(not_equal(condition, 0), (y,x))\n \ndef extract(condition, arr):\n \"\"\"Elements of ravel(condition) where ravel(condition) is true (1-d)\n\n Equivalent of compress(ravel(condition), ravel(arr))\n \"\"\"\n return _nx.take(ravel(arr), nonzero(ravel(condition)))\n\ndef insert(arr, mask, vals):\n \"\"\"Similar to putmask arr[mask] = vals but 1d array vals has the\n same number of elements as the non-zero values of mask. Inverse of extract.\n \"\"\"\n return _nx._insert(arr, mask, vals)\n\ndef nansum(x,axis=-1):\n \"\"\"Sum the array over the given axis treating nans as missing values.\n \"\"\"\n x = _asarray1d(x).copy()\n _nx.putmask(x,isnan(x),0)\n return _nx.sum(x,axis)\n\ndef nanmin(x,axis=-1):\n \"\"\"Find the minimium over the given axis ignoring nans.\n \"\"\"\n x = _asarray1d(x).copy()\n _nx.putmask(x,isnan(x),inf)\n return amin(x,axis)\n\ndef nanargmin(x,axis=-1):\n \"\"\"Find the indices of the minimium over the given axis ignoring nans.\n \"\"\"\n x = _asarray1d(x).copy()\n _nx.putmask(x,isnan(x),inf)\n return argmin(x,axis)\n \n\ndef nanmax(x,axis=-1):\n \"\"\"Find the maximum over the given axis ignoring nans.\n \"\"\"\n x = _asarray1d(x).copy()\n _nx.putmask(x,isnan(x),-inf)\n return amax(x,axis)\n\ndef nanargmax(x,axis=-1):\n \"\"\"Find the maximum over the given axis ignoring nans.\n \"\"\"\n x = _asarray1d(x).copy()\n _nx.putmask(x,isnan(x),-inf)\n return argmax(x,axis)\n\ndef disp(mesg, device=None, linefeed=1):\n \"\"\"Display a message to device (default is sys.stdout) with(out) linefeed.\n \"\"\"\n if device is None:\n import sys\n device = sys.stdout\n if linefeed:\n device.write('%s\\n' % mesg)\n else:\n device.write('%s' % mesg)\n device.flush()\n return\n\nclass vectorize:\n \"\"\"\n vectorize(somefunction) Generalized Function class.\n\n Description:\n \n Define a vectorized function which takes nested sequence\n objects or numerix arrays as inputs and returns a\n numerix 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 numerix Python.\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=None,doc=None):\n if not callable(pyfunc) or type(pyfunc) is types.ClassType:\n raise TypeError, \"Object is not a callable Python object.\"\n self.thefunc = pyfunc\n if doc is None:\n self.__doc__ = pyfunc.__doc__\n else:\n self.__doc__ = doc\n if otypes is None:\n self.otypes=''\n else:\n if isinstance(otypes,types.StringType):\n self.otypes=otypes\n else:\n raise ValueError, \"Output types must be a string.\"\n\n def __call__(self,*args):\n try:\n return squeeze(arraymap(self.thefunc,args,self.otypes))\n except IndexError:\n return self.zerocall(*args)\n\n def zerocall(self,*args):\n # one of the args was a zeros array\n # return zeros for each output\n # first --- find number of outputs\n # get it from self.otypes if possible\n # otherwise evaluate function at 0.9\n N = len(self.otypes)\n if N==1:\n return zeros((0,),'d')\n elif N !=0:\n return (zeros((0,),'d'),)*N\n newargs = []\n args = atleast_1d(args)\n for arg in args:\n if arg.typecode() != 'O':\n newargs.append(0.9)\n else:\n newargs.append(arg[0])\n newargs = tuple(newargs)\n try:\n res = self.thefunc(*newargs)\n except:\n raise ValueError, \"Zerocall is failing. \"\\\n \"Try using otypes in vectorize.\"\n if isscalar(res):\n return zeros((0,),'d')\n else:\n return (zeros((0,),'d'),)*len(res)\n\n", "source_code_before": "\nimport types\nimport Numeric\nfrom Numeric import ravel, nonzero, array, choose, ones, zeros, \\\n sometrue, alltrue, reshape\nfrom type_check import ScalarType, isscalar, asarray\nfrom shape_base import squeeze, atleast_1d\nfrom fastumath import PINF as inf\nfrom fastumath import *\nimport _compiled_base\n\n__all__ = ['round','any','all','logspace','linspace','fix','mod',\n 'select','trim_zeros','amax','amin', 'alen', 'ptp','cumsum','take',\n 'copy', 'prod','cumprod','diff','angle','unwrap','sort_complex',\n 'disp','unique','extract','insert','nansum','nanmax','nanargmax',\n 'nanargmin','nanmin','sum','vectorize','asarray_chkfinite',\n 'alter_numeric', 'restore_numeric','isaltered']\n\nalter_numeric = _compiled_base.alter_numeric\nrestore_numeric = _compiled_base.restore_numeric\n\ndef isaltered():\n val = str(type(array([1])))\n return 'scipy' in val\n\nround = Numeric.around\n\ndef asarray_chkfinite(x):\n \"\"\"Like asarray except it checks to be sure no NaNs or Infs are present.\n \"\"\"\n x = asarray(x)\n if not all(isfinite(x)):\n raise ValueError, \"Array must not contain infs or nans.\"\n return x \n\ndef any(x):\n \"\"\"Return true if any elements of x are true: sometrue(ravel(x))\n \"\"\"\n return sometrue(ravel(x))\n\n\ndef all(x):\n \"\"\"Return true if all elements of x are true: alltrue(ravel(x))\n \"\"\"\n return alltrue(ravel(x))\n\n# Need this to change array type for low precision values\ndef sum(x,axis=0): # could change default axis here\n x = asarray(x)\n if x.typecode() in ['1','s','b','w']:\n x = x.astype('l')\n return Numeric.sum(x,axis)\n \n\ndef logspace(start,stop,num=50,endpoint=1):\n \"\"\" Evenly spaced samples on a logarithmic scale.\n\n Return num evenly spaced samples from 10**start to 10**stop. If\n endpoint=1 then last sample is 10**stop.\n \"\"\"\n if num <= 0: return array([])\n if endpoint:\n step = (stop-start)/float((num-1))\n y = Numeric.arange(0,num) * step + start\n else:\n step = (stop-start)/float(num)\n y = Numeric.arange(0,num) * step + start\n return Numeric.power(10.0,y)\n\ndef linspace(start,stop,num=50,endpoint=1,retstep=0):\n \"\"\" Evenly spaced samples.\n \n Return num evenly spaced samples from start to stop. If endpoint=1 then\n last sample is stop. If retstep is 1 then return the step value used.\n \"\"\"\n if num <= 0: return array([])\n if endpoint:\n step = (stop-start)/float((num-1))\n y = Numeric.arange(0,num) * step + start \n else:\n step = (stop-start)/float(num)\n y = Numeric.arange(0,num) * step + start\n if retstep:\n return y, step\n else:\n return y\n\ndef fix(x):\n \"\"\" Round x to nearest integer towards zero.\n \"\"\"\n x = asarray(x)\n y = Numeric.floor(x)\n return Numeric.where(x<0,y+1,y)\n\ndef mod(x,y):\n \"\"\" x - y*floor(x/y)\n \n For numeric arrays, x % y has the same sign as x while\n mod(x,y) has the same sign as y.\n \"\"\"\n return x - y*Numeric.floor(x*1.0/y)\n\ndef select(condlist, choicelist, default=0):\n \"\"\" Returns an array comprised from different elements of choicelist\n depending on the list of conditions.\n\n condlist is a list of condition arrays containing ones or zeros\n \n choicelist is a list of choice matrices (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 the 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):\n \"\"\"Ensure 1d array for one array.\n \"\"\"\n m = asarray(arr)\n if len(m.shape)==0:\n m = reshape(m,(1,))\n return m\n\ndef copy(a):\n \"\"\"Return an array copy of the object.\n \"\"\"\n return array(a,copy=1)\n\ndef take(a, indices, axis=0):\n \"\"\"Selects the elements in indices from array a along given axis.\n \"\"\"\n try:\n a = Numeric.take(a,indices,axis)\n except ValueError: # a is scalar\n pass\n return a\n \n# Basic operations\ndef amax(m,axis=-1):\n \"\"\"Returns the maximum of m along dimension axis. \n \"\"\"\n if axis is None:\n m = ravel(m)\n axis = 0\n else:\n m = _asarray1d(m)\n return maximum.reduce(m,axis)\n\ndef amin(m,axis=-1):\n \"\"\"Returns the minimum of m along dimension axis.\n \"\"\"\n if axis is None:\n m = ravel(m)\n axis = 0\n else: \n m = _asarray1d(m)\n return minimum.reduce(m,axis)\n\ndef alen(m):\n \"\"\"Returns the length of a Python object interpreted as an array\n \"\"\"\n return len(asarray(m))\n\n# Actually from Basis, but it fits in so naturally here...\n\ndef ptp(m,axis=-1):\n \"\"\"Returns the maximum - minimum along the the given dimension\n \"\"\"\n if axis is None:\n m = ravel(m)\n axis = 0\n else:\n m = _asarray1d(m)\n return amax(m,axis)-amin(m,axis)\n\ndef cumsum(m,axis=-1):\n \"\"\"Returns the cumulative sum of the elements along the given axis\n \"\"\"\n if axis is None:\n m = ravel(m)\n axis = 0\n else:\n m = _asarray1d(m)\n return add.accumulate(m,axis)\n\ndef prod(m,axis=-1):\n \"\"\"Returns the product of the elements along the given axis\n \"\"\"\n if axis is None:\n m = ravel(m)\n axis = 0\n else:\n m = _asarray1d(m)\n return multiply.reduce(m,axis)\n\ndef cumprod(m,axis=-1):\n \"\"\"Returns the cumulative product of the elments along the given axis\n \"\"\"\n if axis is None:\n m = ravel(m)\n axis = 0\n else:\n m = _asarray1d(m)\n return multiply.accumulate(m,axis)\n\ndef diff(x, n=1,axis=-1):\n \"\"\"Calculates the nth order, discrete difference along given axis.\n \"\"\"\n if n==0:\n return x\n if n<0:\n raise ValueError,'Order must be non-negative but got ' + `n`\n x = _asarray1d(x)\n nd = len(x.shape)\n slice1 = [slice(None)]*nd\n slice2 = [slice(None)]*nd\n slice1[axis] = slice(1,None)\n slice2[axis] = slice(None,-1)\n if n > 1:\n return diff(x[slice1]-x[slice2], n-1, axis=axis)\n else:\n return x[slice1]-x[slice2]\n\n \ndef angle(z,deg=0):\n \"\"\"Return the angle of complex argument z.\"\"\"\n if deg:\n fact = 180/pi\n else:\n fact = 1.0\n z = asarray(z)\n if z.typecode() in ['D','F']:\n zimag = z.imag\n zreal = z.real\n else:\n zimag = 0\n zreal = z\n return arctan2(zimag,zreal) * fact\n\ndef unwrap(p,discont=pi,axis=-1):\n \"\"\"unwraps radian phase p by changing absolute jumps greater than\n discont to their 2*pi complement along the given axis.\n \"\"\"\n p = asarray(p)\n nd = len(p.shape)\n dd = diff(p,axis=axis)\n slice1 = [slice(None,None)]*nd # full slices\n slice1[axis] = slice(1,None)\n ddmod = mod(dd+pi,2*pi)-pi\n Numeric.putmask(ddmod,(ddmod==-pi) & (dd > 0),pi)\n ph_correct = ddmod - dd;\n Numeric.putmask(ph_correct,abs(dd)>> import scipy\n >>> a = array((0,0,0,1,2,3,2,1,0))\n >>> scipy.trim_zeros(a)\n array([1, 2, 3, 2, 1])\n \"\"\"\n first = 0\n if 'f' in trim or '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 or 'B' in trim:\n for i in filt[::-1]:\n if i != 0.: break\n else: last = last - 1\n return filt[first:last]\n\ndef unique(inseq):\n \"\"\"Returns unique items in 1-dimensional sequence.\n \"\"\"\n set = {}\n for item in inseq:\n set[item] = None\n return asarray(set.keys())\n\ndef where(condition,x=None,y=None):\n \"\"\"If x and y are both None, then return the (1-d equivalent) indices\n where condition is true. Otherwise, return an array shaped like\n condition with elements of x and y in the places where condition is\n true or false respectively.\n \"\"\"\n if (x is None) and (y is None):\n # Needs work for multidimensional arrays\n return nonzero(ravel(condition))\n else:\n return choose(not_equal(condition, 0), (y,x))\n \ndef extract(condition, arr):\n \"\"\"Elements of ravel(condition) where ravel(condition) is true (1-d)\n\n Equivalent of compress(ravel(condition), ravel(arr))\n \"\"\"\n return Numeric.take(ravel(arr), nonzero(ravel(condition)))\n\ndef insert(arr, mask, vals):\n \"\"\"Similar to putmask arr[mask] = vals but 1d array vals has the\n same number of elements as the non-zero values of mask. Inverse of extract.\n \"\"\"\n return _compiled_base._insert(arr, mask, vals)\n\ndef nansum(x,axis=-1):\n \"\"\"Sum the array over the given axis treating nans as missing values.\n \"\"\"\n x = _asarray1d(x).copy()\n Numeric.putmask(x,isnan(x),0)\n return Numeric.sum(x,axis)\n\ndef nanmin(x,axis=-1):\n \"\"\"Find the minimium over the given axis ignoring nans.\n \"\"\"\n x = _asarray1d(x).copy()\n Numeric.putmask(x,isnan(x),inf)\n return amin(x,axis)\n\ndef nanargmin(x,axis=-1):\n \"\"\"Find the indices of the minimium over the given axis ignoring nans.\n \"\"\"\n x = _asarray1d(x).copy()\n Numeric.putmask(x,isnan(x),inf)\n return argmin(x,axis)\n \n\ndef nanmax(x,axis=-1):\n \"\"\"Find the maximum over the given axis ignoring nans.\n \"\"\"\n x = _asarray1d(x).copy()\n Numeric.putmask(x,isnan(x),-inf)\n return amax(x,axis)\n\ndef nanargmax(x,axis=-1):\n \"\"\"Find the maximum over the given axis ignoring nans.\n \"\"\"\n x = _asarray1d(x).copy()\n Numeric.putmask(x,isnan(x),-inf)\n return argmax(x,axis)\n\ndef disp(mesg, device=None, linefeed=1):\n \"\"\"Display a message to device (default is sys.stdout) with(out) linefeed.\n \"\"\"\n if device is None:\n import sys\n device = sys.stdout\n if linefeed:\n device.write('%s\\n' % mesg)\n else:\n device.write('%s' % mesg)\n device.flush()\n return\n\nfrom _compiled_base import arraymap\nclass vectorize:\n \"\"\"\n vectorize(somefunction) Generalized Function class.\n\n Description:\n \n Define a vectorized function which takes nested sequence\n objects or Numeric arrays as inputs and returns a\n Numeric 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 Numeric Python.\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=None,doc=None):\n if not callable(pyfunc) or type(pyfunc) is types.ClassType:\n raise TypeError, \"Object is not a callable Python object.\"\n self.thefunc = pyfunc\n if doc is None:\n self.__doc__ = pyfunc.__doc__\n else:\n self.__doc__ = doc\n if otypes is None:\n self.otypes=''\n else:\n if isinstance(otypes,types.StringType):\n self.otypes=otypes\n else:\n raise ValueError, \"Output types must be a string.\"\n\n def __call__(self,*args):\n try:\n return squeeze(arraymap(self.thefunc,args,self.otypes))\n except IndexError:\n return self.zerocall(*args)\n\n def zerocall(self,*args):\n # one of the args was a zeros array\n # return zeros for each output\n # first --- find number of outputs\n # get it from self.otypes if possible\n # otherwise evaluate function at 0.9\n N = len(self.otypes)\n if N==1:\n return zeros((0,),'d')\n elif N !=0:\n return (zeros((0,),'d'),)*N\n newargs = []\n args = atleast_1d(args)\n for arg in args:\n if arg.typecode() != 'O':\n newargs.append(0.9)\n else:\n newargs.append(arg[0])\n newargs = tuple(newargs)\n try:\n res = self.thefunc(*newargs)\n except:\n raise ValueError, \"Zerocall is failing. \"\\\n \"Try using otypes in vectorize.\"\n if isscalar(res):\n return zeros((0,),'d')\n else:\n return (zeros((0,),'d'),)*len(res)\n\n", "methods": [ { "name": "isaltered", "long_name": "isaltered( )", "filename": "function_base.py", "nloc": 3, "complexity": 1, "token_count": 24, "parameters": [], "start_line": 16, "end_line": 18, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 3, "top_nesting_level": 0 }, { "name": "asarray_chkfinite", "long_name": "asarray_chkfinite( x )", "filename": "function_base.py", "nloc": 5, "complexity": 2, "token_count": 28, "parameters": [ "x" ], "start_line": 22, "end_line": 28, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 7, "top_nesting_level": 0 }, { "name": "any", "long_name": "any( x )", "filename": "function_base.py", "nloc": 2, "complexity": 1, "token_count": 14, "parameters": [ "x" ], "start_line": 30, "end_line": 33, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 4, "top_nesting_level": 0 }, { "name": "all", "long_name": "all( x )", "filename": "function_base.py", "nloc": 2, "complexity": 1, "token_count": 14, "parameters": [ "x" ], "start_line": 36, "end_line": 39, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 4, "top_nesting_level": 0 }, { "name": "sum", "long_name": "sum( x , axis = 0 )", "filename": "function_base.py", "nloc": 5, "complexity": 2, "token_count": 49, "parameters": [ "x", "axis" ], "start_line": 42, "end_line": 46, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 5, "top_nesting_level": 0 }, { "name": "logspace", "long_name": "logspace( start , stop , num = 50 , endpoint = 1 )", "filename": "function_base.py", "nloc": 9, "complexity": 3, "token_count": 99, "parameters": [ "start", "stop", "num", "endpoint" ], "start_line": 49, "end_line": 62, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 14, "top_nesting_level": 0 }, { "name": "linspace", "long_name": "linspace( start , stop , num = 50 , endpoint = 1 , retstep = 0 )", "filename": "function_base.py", "nloc": 12, "complexity": 4, "token_count": 103, "parameters": [ "start", "stop", "num", "endpoint", "retstep" ], "start_line": 64, "end_line": 80, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 17, "top_nesting_level": 0 }, { "name": "fix", "long_name": "fix( x )", "filename": "function_base.py", "nloc": 4, "complexity": 1, "token_count": 35, "parameters": [ "x" ], "start_line": 82, "end_line": 87, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 6, "top_nesting_level": 0 }, { "name": "mod", "long_name": "mod( x , y )", "filename": "function_base.py", "nloc": 2, "complexity": 1, "token_count": 25, "parameters": [ "x", "y" ], "start_line": 89, "end_line": 95, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 7, "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": 97, "end_line": 143, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 47, "top_nesting_level": 0 }, { "name": "_asarray1d", "long_name": "_asarray1d( arr )", "filename": "function_base.py", "nloc": 5, "complexity": 2, "token_count": 35, "parameters": [ "arr" ], "start_line": 145, "end_line": 151, "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": 153, "end_line": 156, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 4, "top_nesting_level": 0 }, { "name": "take", "long_name": "take( a , indices , axis = 0 )", "filename": "function_base.py", "nloc": 6, "complexity": 2, "token_count": 32, "parameters": [ "a", "indices", "axis" ], "start_line": 158, "end_line": 165, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 8, "top_nesting_level": 0 }, { "name": "_no_axis_is_all", "long_name": "_no_axis_is_all( function , m , axis )", "filename": "function_base.py", "nloc": 16, "complexity": 4, "token_count": 86, "parameters": [ "function", "m", "axis" ], "start_line": 167, "end_line": 182, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 16, "top_nesting_level": 0 }, { "name": "amax", "long_name": "amax( m , axis = - 1 )", "filename": "function_base.py", "nloc": 2, "complexity": 1, "token_count": 22, "parameters": [ "m", "axis" ], "start_line": 185, "end_line": 188, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 4, "top_nesting_level": 0 }, { "name": "amin", "long_name": "amin( m , axis = - 1 )", "filename": "function_base.py", "nloc": 2, "complexity": 1, "token_count": 22, "parameters": [ "m", "axis" ], "start_line": 190, "end_line": 193, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 4, "top_nesting_level": 0 }, { "name": "alen", "long_name": "alen( m )", "filename": "function_base.py", "nloc": 2, "complexity": 1, "token_count": 14, "parameters": [ "m" ], "start_line": 195, "end_line": 198, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 4, "top_nesting_level": 0 }, { "name": "_amin_amax", "long_name": "_amin_amax( m , axis )", "filename": "function_base.py", "nloc": 2, "complexity": 1, "token_count": 21, "parameters": [ "m", "axis" ], "start_line": 202, "end_line": 203, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 2, "top_nesting_level": 0 }, { "name": "ptp", "long_name": "ptp( m , axis = - 1 )", "filename": "function_base.py", "nloc": 2, "complexity": 1, "token_count": 20, "parameters": [ "m", "axis" ], "start_line": 205, "end_line": 208, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 4, "top_nesting_level": 0 }, { "name": "cumsum", "long_name": "cumsum( m , axis = - 1 )", "filename": "function_base.py", "nloc": 2, "complexity": 1, "token_count": 22, "parameters": [ "m", "axis" ], "start_line": 210, "end_line": 213, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 4, "top_nesting_level": 0 }, { "name": "prod", "long_name": "prod( m , axis = - 1 )", "filename": "function_base.py", "nloc": 2, "complexity": 1, "token_count": 22, "parameters": [ "m", "axis" ], "start_line": 215, "end_line": 218, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 4, "top_nesting_level": 0 }, { "name": "cumprod", "long_name": "cumprod( m , axis = - 1 )", "filename": "function_base.py", "nloc": 2, "complexity": 1, "token_count": 22, "parameters": [ "m", "axis" ], "start_line": 220, "end_line": 223, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 4, "top_nesting_level": 0 }, { "name": "diff", "long_name": "diff( x , n = 1 , axis = - 1 )", "filename": "function_base.py", "nloc": 15, "complexity": 4, "token_count": 130, "parameters": [ "x", "n", "axis" ], "start_line": 225, "end_line": 241, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 17, "top_nesting_level": 0 }, { "name": "angle", "long_name": "angle( z , deg = 0 )", "filename": "function_base.py", "nloc": 13, "complexity": 3, "token_count": 71, "parameters": [ "z", "deg" ], "start_line": 243, "end_line": 256, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 14, "top_nesting_level": 0 }, { "name": "unwrap", "long_name": "unwrap( p , discont = pi , axis = - 1 )", "filename": "function_base.py", "nloc": 13, "complexity": 1, "token_count": 150, "parameters": [ "p", "discont", "axis" ], "start_line": 258, "end_line": 273, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 16, "top_nesting_level": 0 }, { "name": "sort_complex.complex_cmp", "long_name": "sort_complex.complex_cmp( x , y )", "filename": "function_base.py", "nloc": 5, "complexity": 2, "token_count": 38, "parameters": [ "x", "y" ], "start_line": 279, "end_line": 283, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 5, "top_nesting_level": 1 }, { "name": "sort_complex", "long_name": "sort_complex( a )", "filename": "function_base.py", "nloc": 6, "complexity": 1, "token_count": 44, "parameters": [ "a" ], "start_line": 275, "end_line": 286, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 12, "top_nesting_level": 0 }, { "name": "trim_zeros", "long_name": "trim_zeros( filt , trim = 'fb' )", "filename": "function_base.py", "nloc": 12, "complexity": 9, "token_count": 87, "parameters": [ "filt", "trim" ], "start_line": 288, "end_line": 307, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 20, "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": 309, "end_line": 315, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 7, "top_nesting_level": 0 }, { "name": "where", "long_name": "where( condition , x = None , y = None )", "filename": "function_base.py", "nloc": 5, "complexity": 3, "token_count": 53, "parameters": [ "condition", "x", "y" ], "start_line": 317, "end_line": 327, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 11, "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": 329, "end_line": 334, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 6, "top_nesting_level": 0 }, { "name": "insert", "long_name": "insert( arr , mask , vals )", "filename": "function_base.py", "nloc": 2, "complexity": 1, "token_count": 21, "parameters": [ "arr", "mask", "vals" ], "start_line": 336, "end_line": 340, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 5, "top_nesting_level": 0 }, { "name": "nansum", "long_name": "nansum( x , axis = - 1 )", "filename": "function_base.py", "nloc": 4, "complexity": 1, "token_count": 43, "parameters": [ "x", "axis" ], "start_line": 342, "end_line": 347, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 6, "top_nesting_level": 0 }, { "name": "nanmin", "long_name": "nanmin( x , axis = - 1 )", "filename": "function_base.py", "nloc": 4, "complexity": 1, "token_count": 41, "parameters": [ "x", "axis" ], "start_line": 349, "end_line": 354, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 6, "top_nesting_level": 0 }, { "name": "nanargmin", "long_name": "nanargmin( x , axis = - 1 )", "filename": "function_base.py", "nloc": 4, "complexity": 1, "token_count": 41, "parameters": [ "x", "axis" ], "start_line": 356, "end_line": 361, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 6, "top_nesting_level": 0 }, { "name": "nanmax", "long_name": "nanmax( x , axis = - 1 )", "filename": "function_base.py", "nloc": 4, "complexity": 1, "token_count": 42, "parameters": [ "x", "axis" ], "start_line": 364, "end_line": 369, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 6, "top_nesting_level": 0 }, { "name": "nanargmax", "long_name": "nanargmax( x , axis = - 1 )", "filename": "function_base.py", "nloc": 4, "complexity": 1, "token_count": 42, "parameters": [ "x", "axis" ], "start_line": 371, "end_line": 376, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 6, "top_nesting_level": 0 }, { "name": "disp", "long_name": "disp( mesg , device = None , linefeed = 1 )", "filename": "function_base.py", "nloc": 10, "complexity": 3, "token_count": 53, "parameters": [ "mesg", "device", "linefeed" ], "start_line": 378, "end_line": 389, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 12, "top_nesting_level": 0 }, { "name": "__init__", "long_name": "__init__( self , pyfunc , otypes = None , doc = None )", "filename": "function_base.py", "nloc": 15, "complexity": 6, "token_count": 92, "parameters": [ "self", "pyfunc", "otypes", "doc" ], "start_line": 421, "end_line": 435, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 15, "top_nesting_level": 1 }, { "name": "__call__", "long_name": "__call__( self , * args )", "filename": "function_base.py", "nloc": 5, "complexity": 2, "token_count": 37, "parameters": [ "self", "args" ], "start_line": 437, "end_line": 441, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 5, "top_nesting_level": 1 }, { "name": "zerocall", "long_name": "zerocall( self , * args )", "filename": "function_base.py", "nloc": 23, "complexity": 7, "token_count": 155, "parameters": [ "self", "args" ], "start_line": 443, "end_line": 470, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 28, "top_nesting_level": 1 } ], "methods_before": [ { "name": "isaltered", "long_name": "isaltered( )", "filename": "function_base.py", "nloc": 3, "complexity": 1, "token_count": 22, "parameters": [], "start_line": 22, "end_line": 24, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 3, "top_nesting_level": 0 }, { "name": "asarray_chkfinite", "long_name": "asarray_chkfinite( x )", "filename": "function_base.py", "nloc": 5, "complexity": 2, "token_count": 28, "parameters": [ "x" ], "start_line": 28, "end_line": 34, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 7, "top_nesting_level": 0 }, { "name": "any", "long_name": "any( x )", "filename": "function_base.py", "nloc": 2, "complexity": 1, "token_count": 14, "parameters": [ "x" ], "start_line": 36, "end_line": 39, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 4, "top_nesting_level": 0 }, { "name": "all", "long_name": "all( x )", "filename": "function_base.py", "nloc": 2, "complexity": 1, "token_count": 14, "parameters": [ "x" ], "start_line": 42, "end_line": 45, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 4, "top_nesting_level": 0 }, { "name": "sum", "long_name": "sum( x , axis = 0 )", "filename": "function_base.py", "nloc": 5, "complexity": 2, "token_count": 49, "parameters": [ "x", "axis" ], "start_line": 48, "end_line": 52, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 5, "top_nesting_level": 0 }, { "name": "logspace", "long_name": "logspace( start , stop , num = 50 , endpoint = 1 )", "filename": "function_base.py", "nloc": 9, "complexity": 3, "token_count": 99, "parameters": [ "start", "stop", "num", "endpoint" ], "start_line": 55, "end_line": 68, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 14, "top_nesting_level": 0 }, { "name": "linspace", "long_name": "linspace( start , stop , num = 50 , endpoint = 1 , retstep = 0 )", "filename": "function_base.py", "nloc": 12, "complexity": 4, "token_count": 103, "parameters": [ "start", "stop", "num", "endpoint", "retstep" ], "start_line": 70, "end_line": 86, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 17, "top_nesting_level": 0 }, { "name": "fix", "long_name": "fix( x )", "filename": "function_base.py", "nloc": 4, "complexity": 1, "token_count": 35, "parameters": [ "x" ], "start_line": 88, "end_line": 93, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 6, "top_nesting_level": 0 }, { "name": "mod", "long_name": "mod( x , y )", "filename": "function_base.py", "nloc": 2, "complexity": 1, "token_count": 25, "parameters": [ "x", "y" ], "start_line": 95, "end_line": 101, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 7, "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": 103, "end_line": 149, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 47, "top_nesting_level": 0 }, { "name": "_asarray1d", "long_name": "_asarray1d( arr )", "filename": "function_base.py", "nloc": 5, "complexity": 2, "token_count": 35, "parameters": [ "arr" ], "start_line": 151, "end_line": 157, "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": 159, "end_line": 162, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 4, "top_nesting_level": 0 }, { "name": "take", "long_name": "take( a , indices , axis = 0 )", "filename": "function_base.py", "nloc": 6, "complexity": 2, "token_count": 32, "parameters": [ "a", "indices", "axis" ], "start_line": 164, "end_line": 171, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 8, "top_nesting_level": 0 }, { "name": "amax", "long_name": "amax( m , axis = - 1 )", "filename": "function_base.py", "nloc": 7, "complexity": 2, "token_count": 42, "parameters": [ "m", "axis" ], "start_line": 174, "end_line": 182, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 9, "top_nesting_level": 0 }, { "name": "amin", "long_name": "amin( m , axis = - 1 )", "filename": "function_base.py", "nloc": 7, "complexity": 2, "token_count": 42, "parameters": [ "m", "axis" ], "start_line": 184, "end_line": 192, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 9, "top_nesting_level": 0 }, { "name": "alen", "long_name": "alen( m )", "filename": "function_base.py", "nloc": 2, "complexity": 1, "token_count": 14, "parameters": [ "m" ], "start_line": 194, "end_line": 197, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 4, "top_nesting_level": 0 }, { "name": "ptp", "long_name": "ptp( m , axis = - 1 )", "filename": "function_base.py", "nloc": 7, "complexity": 2, "token_count": 47, "parameters": [ "m", "axis" ], "start_line": 201, "end_line": 209, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 9, "top_nesting_level": 0 }, { "name": "cumsum", "long_name": "cumsum( m , axis = - 1 )", "filename": "function_base.py", "nloc": 7, "complexity": 2, "token_count": 42, "parameters": [ "m", "axis" ], "start_line": 211, "end_line": 219, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 9, "top_nesting_level": 0 }, { "name": "prod", "long_name": "prod( m , axis = - 1 )", "filename": "function_base.py", "nloc": 7, "complexity": 2, "token_count": 42, "parameters": [ "m", "axis" ], "start_line": 221, "end_line": 229, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 9, "top_nesting_level": 0 }, { "name": "cumprod", "long_name": "cumprod( m , axis = - 1 )", "filename": "function_base.py", "nloc": 7, "complexity": 2, "token_count": 42, "parameters": [ "m", "axis" ], "start_line": 231, "end_line": 239, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 9, "top_nesting_level": 0 }, { "name": "diff", "long_name": "diff( x , n = 1 , axis = - 1 )", "filename": "function_base.py", "nloc": 15, "complexity": 4, "token_count": 130, "parameters": [ "x", "n", "axis" ], "start_line": 241, "end_line": 257, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 17, "top_nesting_level": 0 }, { "name": "angle", "long_name": "angle( z , deg = 0 )", "filename": "function_base.py", "nloc": 13, "complexity": 3, "token_count": 71, "parameters": [ "z", "deg" ], "start_line": 260, "end_line": 273, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 14, "top_nesting_level": 0 }, { "name": "unwrap", "long_name": "unwrap( p , discont = pi , axis = - 1 )", "filename": "function_base.py", "nloc": 13, "complexity": 1, "token_count": 150, "parameters": [ "p", "discont", "axis" ], "start_line": 275, "end_line": 290, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 16, "top_nesting_level": 0 }, { "name": "sort_complex.complex_cmp", "long_name": "sort_complex.complex_cmp( x , y )", "filename": "function_base.py", "nloc": 5, "complexity": 2, "token_count": 38, "parameters": [ "x", "y" ], "start_line": 296, "end_line": 300, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 5, "top_nesting_level": 1 }, { "name": "sort_complex", "long_name": "sort_complex( a )", "filename": "function_base.py", "nloc": 6, "complexity": 1, "token_count": 44, "parameters": [ "a" ], "start_line": 292, "end_line": 303, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 12, "top_nesting_level": 0 }, { "name": "trim_zeros", "long_name": "trim_zeros( filt , trim = 'fb' )", "filename": "function_base.py", "nloc": 12, "complexity": 9, "token_count": 87, "parameters": [ "filt", "trim" ], "start_line": 305, "end_line": 324, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 20, "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": 326, "end_line": 332, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 7, "top_nesting_level": 0 }, { "name": "where", "long_name": "where( condition , x = None , y = None )", "filename": "function_base.py", "nloc": 5, "complexity": 3, "token_count": 53, "parameters": [ "condition", "x", "y" ], "start_line": 334, "end_line": 344, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 11, "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": 346, "end_line": 351, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 6, "top_nesting_level": 0 }, { "name": "insert", "long_name": "insert( arr , mask , vals )", "filename": "function_base.py", "nloc": 2, "complexity": 1, "token_count": 21, "parameters": [ "arr", "mask", "vals" ], "start_line": 353, "end_line": 357, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 5, "top_nesting_level": 0 }, { "name": "nansum", "long_name": "nansum( x , axis = - 1 )", "filename": "function_base.py", "nloc": 4, "complexity": 1, "token_count": 43, "parameters": [ "x", "axis" ], "start_line": 359, "end_line": 364, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 6, "top_nesting_level": 0 }, { "name": "nanmin", "long_name": "nanmin( x , axis = - 1 )", "filename": "function_base.py", "nloc": 4, "complexity": 1, "token_count": 41, "parameters": [ "x", "axis" ], "start_line": 366, "end_line": 371, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 6, "top_nesting_level": 0 }, { "name": "nanargmin", "long_name": "nanargmin( x , axis = - 1 )", "filename": "function_base.py", "nloc": 4, "complexity": 1, "token_count": 41, "parameters": [ "x", "axis" ], "start_line": 373, "end_line": 378, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 6, "top_nesting_level": 0 }, { "name": "nanmax", "long_name": "nanmax( x , axis = - 1 )", "filename": "function_base.py", "nloc": 4, "complexity": 1, "token_count": 42, "parameters": [ "x", "axis" ], "start_line": 381, "end_line": 386, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 6, "top_nesting_level": 0 }, { "name": "nanargmax", "long_name": "nanargmax( x , axis = - 1 )", "filename": "function_base.py", "nloc": 4, "complexity": 1, "token_count": 42, "parameters": [ "x", "axis" ], "start_line": 388, "end_line": 393, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 6, "top_nesting_level": 0 }, { "name": "disp", "long_name": "disp( mesg , device = None , linefeed = 1 )", "filename": "function_base.py", "nloc": 10, "complexity": 3, "token_count": 53, "parameters": [ "mesg", "device", "linefeed" ], "start_line": 395, "end_line": 406, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 12, "top_nesting_level": 0 }, { "name": "__init__", "long_name": "__init__( self , pyfunc , otypes = None , doc = None )", "filename": "function_base.py", "nloc": 15, "complexity": 6, "token_count": 92, "parameters": [ "self", "pyfunc", "otypes", "doc" ], "start_line": 439, "end_line": 453, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 15, "top_nesting_level": 1 }, { "name": "__call__", "long_name": "__call__( self , * args )", "filename": "function_base.py", "nloc": 5, "complexity": 2, "token_count": 37, "parameters": [ "self", "args" ], "start_line": 455, "end_line": 459, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 5, "top_nesting_level": 1 }, { "name": "zerocall", "long_name": "zerocall( self , * args )", "filename": "function_base.py", "nloc": 23, "complexity": 7, "token_count": 155, "parameters": [ "self", "args" ], "start_line": 461, "end_line": 488, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 28, "top_nesting_level": 1 } ], "changed_methods": [ { "name": "insert", "long_name": "insert( arr , mask , vals )", "filename": "function_base.py", "nloc": 2, "complexity": 1, "token_count": 21, "parameters": [ "arr", "mask", "vals" ], "start_line": 336, "end_line": 340, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 5, "top_nesting_level": 0 }, { "name": "nansum", "long_name": "nansum( x , axis = - 1 )", "filename": "function_base.py", "nloc": 4, "complexity": 1, "token_count": 43, "parameters": [ "x", "axis" ], "start_line": 342, "end_line": 347, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 6, "top_nesting_level": 0 }, { "name": "fix", "long_name": "fix( x )", "filename": "function_base.py", "nloc": 4, "complexity": 1, "token_count": 35, "parameters": [ "x" ], "start_line": 82, "end_line": 87, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 6, "top_nesting_level": 0 }, { "name": "take", "long_name": "take( a , indices , axis = 0 )", "filename": "function_base.py", "nloc": 6, "complexity": 2, "token_count": 32, "parameters": [ "a", "indices", "axis" ], "start_line": 158, "end_line": 165, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 8, "top_nesting_level": 0 }, { "name": "cumsum", "long_name": "cumsum( m , axis = - 1 )", "filename": "function_base.py", "nloc": 2, "complexity": 1, "token_count": 22, "parameters": [ "m", "axis" ], "start_line": 210, "end_line": 213, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 4, "top_nesting_level": 0 }, { "name": "mod", "long_name": "mod( x , y )", "filename": "function_base.py", "nloc": 2, "complexity": 1, "token_count": 25, "parameters": [ "x", "y" ], "start_line": 89, "end_line": 95, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 7, "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": 258, "end_line": 273, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 16, "top_nesting_level": 0 }, { "name": "prod", "long_name": "prod( m , axis = - 1 )", "filename": "function_base.py", "nloc": 2, "complexity": 1, "token_count": 22, "parameters": [ "m", "axis" ], "start_line": 215, "end_line": 218, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 4, "top_nesting_level": 0 }, { "name": "amin", "long_name": "amin( m , axis = - 1 )", "filename": "function_base.py", "nloc": 2, "complexity": 1, "token_count": 22, "parameters": [ "m", "axis" ], "start_line": 190, "end_line": 193, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 4, "top_nesting_level": 0 }, { "name": "cumprod", "long_name": "cumprod( m , axis = - 1 )", "filename": "function_base.py", "nloc": 2, "complexity": 1, "token_count": 22, "parameters": [ "m", "axis" ], "start_line": 220, "end_line": 223, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 4, "top_nesting_level": 0 }, { "name": "nanargmax", "long_name": "nanargmax( x , axis = - 1 )", "filename": "function_base.py", "nloc": 4, "complexity": 1, "token_count": 42, "parameters": [ "x", "axis" ], "start_line": 371, "end_line": 376, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 6, "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": 329, "end_line": 334, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 6, "top_nesting_level": 0 }, { "name": "nanmax", "long_name": "nanmax( x , axis = - 1 )", "filename": "function_base.py", "nloc": 4, "complexity": 1, "token_count": 42, "parameters": [ "x", "axis" ], "start_line": 364, "end_line": 369, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 6, "top_nesting_level": 0 }, { "name": "isaltered", "long_name": "isaltered( )", "filename": "function_base.py", "nloc": 3, "complexity": 1, "token_count": 24, "parameters": [], "start_line": 16, "end_line": 18, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 3, "top_nesting_level": 0 }, { "name": "logspace", "long_name": "logspace( start , stop , num = 50 , endpoint = 1 )", "filename": "function_base.py", "nloc": 9, "complexity": 3, "token_count": 99, "parameters": [ "start", "stop", "num", "endpoint" ], "start_line": 49, "end_line": 62, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 14, "top_nesting_level": 0 }, { "name": "_no_axis_is_all", "long_name": "_no_axis_is_all( function , m , axis )", "filename": "function_base.py", "nloc": 16, "complexity": 4, "token_count": 86, "parameters": [ "function", "m", "axis" ], "start_line": 167, "end_line": 182, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 16, "top_nesting_level": 0 }, { "name": "ptp", "long_name": "ptp( m , axis = - 1 )", "filename": "function_base.py", "nloc": 2, "complexity": 1, "token_count": 20, "parameters": [ "m", "axis" ], "start_line": 205, "end_line": 208, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 4, "top_nesting_level": 0 }, { "name": "linspace", "long_name": "linspace( start , stop , num = 50 , endpoint = 1 , retstep = 0 )", "filename": "function_base.py", "nloc": 12, "complexity": 4, "token_count": 103, "parameters": [ "start", "stop", "num", "endpoint", "retstep" ], "start_line": 64, "end_line": 80, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 17, "top_nesting_level": 0 }, { "name": "amax", "long_name": "amax( m , axis = - 1 )", "filename": "function_base.py", "nloc": 2, "complexity": 1, "token_count": 22, "parameters": [ "m", "axis" ], "start_line": 185, "end_line": 188, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 4, "top_nesting_level": 0 }, { "name": "nanargmin", "long_name": "nanargmin( x , axis = - 1 )", "filename": "function_base.py", "nloc": 4, "complexity": 1, "token_count": 41, "parameters": [ "x", "axis" ], "start_line": 356, "end_line": 361, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 6, "top_nesting_level": 0 }, { "name": "_amin_amax", "long_name": "_amin_amax( m , axis )", "filename": "function_base.py", "nloc": 2, "complexity": 1, "token_count": 21, "parameters": [ "m", "axis" ], "start_line": 202, "end_line": 203, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 2, "top_nesting_level": 0 }, { "name": "sum", "long_name": "sum( x , axis = 0 )", "filename": "function_base.py", "nloc": 5, "complexity": 2, "token_count": 49, "parameters": [ "x", "axis" ], "start_line": 42, "end_line": 46, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 5, "top_nesting_level": 0 }, { "name": "nanmin", "long_name": "nanmin( x , axis = - 1 )", "filename": "function_base.py", "nloc": 4, "complexity": 1, "token_count": 41, "parameters": [ "x", "axis" ], "start_line": 349, "end_line": 354, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 6, "top_nesting_level": 0 } ], "nloc": 301, "complexity": 90, "token_count": 2272, "diff_parsed": { "added": [ "import numerix as _nx", "from numerix import ravel, nonzero, array, choose, ones, zeros, \\", " sometrue, alltrue, reshape, alter_numeric, restore_numeric, arraymap, \\", " pi, _insert, multiply, add, arctan2, maximum, minimum", " val = str(type(_nx.array([1])))", "round = _nx.around", " return _nx.sum(x,axis)", " y = _nx.arange(0,num) * step + start", " y = _nx.arange(0,num) * step + start", " return _nx.power(10.0,y)", " y = _nx.arange(0,num) * step + start", " y = _nx.arange(0,num) * step + start", " y = _nx.floor(x)", " return _nx.where(x<0,y+1,y)", " return x - y*_nx.floor(x*1.0/y)", " a = _nx.take(a,indices,axis)", "", "def _no_axis_is_all(function, m, axis):", " if _nx.which[0] == \"numeric\":", " r = function(m, axis)", " else:", " import numarray as _na", " _na.Error.pushMode(overflow=\"raise\")", " try:", " r = function(m, axis)", " finally:", " _na.Error.popMode()", " return r", "", "# Basic operations", "def amax(m,axis=-1):", " \"\"\"Returns the maximum of m along dimension axis.", " \"\"\"", " return _no_axis_is_all(maximum.reduce, m, axis)", " return _no_axis_is_all(minimum.reduce, m, axis)", "def _amin_amax(m, axis):", " return amax(m,axis)-amin(m,axis)", "", " return _no_axis_is_all(_amin_amax, m, axis)", " return _no_axis_is_all(add.accumulate, m, axis)", " return _no_axis_is_all(multiply.reduce, m, axis)", " return _no_axis_is_all(multiply.accumulate, m, axis)", " _nx.putmask(ddmod,(ddmod==-pi) & (dd > 0),pi)", " _nx.putmask(ph_correct,abs(dd) 0),pi)", " Numeric.putmask(ph_correct,abs(dd)>> 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(1)\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=0):\n self.sparse = sparse\n def __getitem__(self,key):\n try:\n\t size = []\n typecode = _nx.Int\n\t for k in range(len(key)):\n\t 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,typecode=t),size,(typecode,)*len(size))\n else:\n nn = _nx.indices(size,typecode)\n\t 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\t 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\t \n def __getslice__(self,i,j):\n return _nx.arange(i,j)\n\n def __len__(self):\n return 0\n\nmgrid = nd_grid()\nogrid = nd_grid(1)\n\nimport sys\nclass concatenator:\n \"\"\" Translates slice objects to concatenation along an axis.\n \"\"\"\n def _retval(self, res):\n if not self.matrix:\n return res\n else:\n if self.axis == 0:\n return makemat(res)\n else:\n return makemat(res).T \n \n def __init__(self, axis=0, matrix=0):\n self.axis = axis\n self.matrix = matrix\n def __getitem__(self,key):\n if isinstance(key,types.StringType):\n frame = sys._getframe().f_back\n mymat = matrix_base.bmat(key,frame.f_globals,frame.f_locals)\n if self.matrix:\n return mymat\n else:\n return asarray(mymat)\n if type(key) is not types.TupleType:\n key = (key,)\n objs = []\n for k in range(len(key)):\n if type(key[k]) is types.SliceType:\n typecode = _nx.Int\n\t 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 typecode = _nx.Float\n newobj = function_base.linspace(start, stop, num=size)\n else:\n newobj = _nx.arange(start, stop, step)\n elif type(key[k]) in ScalarType:\n newobj = asarray([key[k]])\n else:\n newobj = key[k]\n objs.append(newobj)\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)\nc_=concatenator(-1)\nrow = concatenator(0,1)\ncol = concatenator(-1,1)\n\n# A nicer way to build up index tuples for arrays.\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#\n# For any index combination, including slicing and axis insertion,\n# 'a[indices]' is the same as 'a[index_expression[indices]]' for any\n# array 'a'. However, 'index_expression[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\nclass _index_expression_class:\n import sys\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": "import types\nimport Numeric\n__all__ = ['mgrid','ogrid','r_', 'row', 'c_', 'col', 'index_exp']\n\nfrom type_check import ScalarType, asarray\nimport function_base\nimport matrix_base\nmakemat = matrix_base.Matrix.Matrix\n\nclass nd_grid:\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 1, the mesh-grid is open or not\n fleshed out so that only one-dimension of each returned argument is\n 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(1)\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=0):\n self.sparse = sparse\n def __getitem__(self,key):\n try:\n\t size = []\n typecode = Numeric.Int\n\t for k in range(len(key)):\n\t 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 = Numeric.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 = Numeric.Float\n if self.sparse:\n nn = map(lambda x,t: Numeric.arange(x,typecode=t),size,(typecode,)*len(size))\n else:\n nn = Numeric.indices(size,typecode)\n\t 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 = [Numeric.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] = Numeric.NewAxis\n\t 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 Numeric.arange(0,length,1,Numeric.Float)*step + start\n else:\n return Numeric.arange(start, stop, step)\n\t \n def __getslice__(self,i,j):\n return Numeric.arange(i,j)\n\n def __len__(self):\n return 0\n\nmgrid = nd_grid()\nogrid = nd_grid(1)\n\nimport sys\nclass concatenator:\n \"\"\" Translates slice objects to concatenation along an axis.\n \"\"\"\n def _retval(self, res):\n if not self.matrix:\n return res\n else:\n if self.axis == 0:\n return makemat(res)\n else:\n return makemat(res).T \n \n def __init__(self, axis=0, matrix=0):\n self.axis = axis\n self.matrix = matrix\n def __getitem__(self,key):\n if isinstance(key,types.StringType):\n frame = sys._getframe().f_back\n mymat = matrix_base.bmat(key,frame.f_globals,frame.f_locals)\n if self.matrix:\n return mymat\n else:\n return asarray(mymat)\n if type(key) is not types.TupleType:\n key = (key,)\n objs = []\n for k in range(len(key)):\n if type(key[k]) is types.SliceType:\n typecode = Numeric.Int\n\t 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 typecode = Numeric.Float\n newobj = function_base.linspace(start, stop, num=size)\n else:\n newobj = Numeric.arange(start, stop, step)\n elif type(key[k]) in ScalarType:\n newobj = asarray([key[k]])\n else:\n newobj = key[k]\n objs.append(newobj)\n res = Numeric.concatenate(tuple(objs),axis=self.axis)\n return self._retval(res)\n \n def __getslice__(self,i,j):\n res = Numeric.arange(i,j)\n return self._retval(res)\n\n def __len__(self):\n return 0\n\nr_=concatenator(0)\nc_=concatenator(-1)\nrow = concatenator(0,1)\ncol = concatenator(-1,1)\n\n# A nicer way to build up index tuples for arrays.\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#\n# For any index combination, including slicing and axis insertion,\n# 'a[indices]' is the same as 'a[index_expression[indices]]' for any\n# array 'a'. However, 'index_expression[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\nclass _index_expression_class:\n import sys\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": "__init__", "long_name": "__init__( self , sparse = 0 )", "filename": "index_tricks.py", "nloc": 2, "complexity": 1, "token_count": 14, "parameters": [ "self", "sparse" ], "start_line": 48, "end_line": 49, "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": 50, "end_line": 100, "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": 102, "end_line": 103, "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": 105, "end_line": 106, "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": 8, "complexity": 3, "token_count": 38, "parameters": [ "self", "res" ], "start_line": 115, "end_line": 122, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 8, "top_nesting_level": 1 }, { "name": "__init__", "long_name": "__init__( self , axis = 0 , matrix = 0 )", "filename": "index_tricks.py", "nloc": 3, "complexity": 1, "token_count": 23, "parameters": [ "self", "axis", "matrix" ], "start_line": 124, "end_line": 126, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 3, "top_nesting_level": 1 }, { "name": "__getitem__", "long_name": "__getitem__( self , key )", "filename": "index_tricks.py", "nloc": 33, "complexity": 10, "token_count": 259, "parameters": [ "self", "key" ], "start_line": 127, "end_line": 159, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 33, "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": 161, "end_line": 163, "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": 165, "end_line": 166, "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": 199, "end_line": 203, "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": 205, "end_line": 206, "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": 208, "end_line": 211, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 4, "top_nesting_level": 1 } ], "methods_before": [ { "name": "__init__", "long_name": "__init__( self , sparse = 0 )", "filename": "index_tricks.py", "nloc": 2, "complexity": 1, "token_count": 14, "parameters": [ "self", "sparse" ], "start_line": 48, "end_line": 49, "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": 50, "end_line": 100, "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": 102, "end_line": 103, "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": 105, "end_line": 106, "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": 8, "complexity": 3, "token_count": 38, "parameters": [ "self", "res" ], "start_line": 115, "end_line": 122, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 8, "top_nesting_level": 1 }, { "name": "__init__", "long_name": "__init__( self , axis = 0 , matrix = 0 )", "filename": "index_tricks.py", "nloc": 3, "complexity": 1, "token_count": 23, "parameters": [ "self", "axis", "matrix" ], "start_line": 124, "end_line": 126, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 3, "top_nesting_level": 1 }, { "name": "__getitem__", "long_name": "__getitem__( self , key )", "filename": "index_tricks.py", "nloc": 33, "complexity": 10, "token_count": 259, "parameters": [ "self", "key" ], "start_line": 127, "end_line": 159, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 33, "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": 161, "end_line": 163, "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": 165, "end_line": 166, "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": 199, "end_line": 203, "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": 205, "end_line": 206, "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": 208, "end_line": 211, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 4, "top_nesting_level": 1 } ], "changed_methods": [ { "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": 102, "end_line": 103, "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": 50, "end_line": 100, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 51, "top_nesting_level": 1 } ], "nloc": 176, "complexity": 42, "token_count": 1045, "diff_parsed": { "added": [ "import numerix as _nx", "makemat = _nx.Matrix", " typecode = _nx.Int", " typecode = _nx.Float", " typecode = _nx.Float", " nn = map(lambda x,t: _nx.arange(x,typecode=t),size,(typecode,)*len(size))", " nn = _nx.indices(size,typecode)", " slobj = [_nx.NewAxis]*len(size)", " slobj[k] = _nx.NewAxis", " return _nx.arange(0,length,1,_nx.Float)*step + start", " return _nx.arange(start, stop, step)", " return _nx.arange(i,j)", " typecode = _nx.Int", " typecode = _nx.Float", " newobj = _nx.arange(start, stop, step)", " res = _nx.concatenate(tuple(objs),axis=self.axis)", "", " res = _nx.arange(i,j)" ], "deleted": [ "import Numeric", "makemat = matrix_base.Matrix.Matrix", " typecode = Numeric.Int", " typecode = Numeric.Float", " typecode = Numeric.Float", " nn = map(lambda x,t: Numeric.arange(x,typecode=t),size,(typecode,)*len(size))", " nn = Numeric.indices(size,typecode)", " slobj = [Numeric.NewAxis]*len(size)", " slobj[k] = Numeric.NewAxis", " return Numeric.arange(0,length,1,Numeric.Float)*step + start", " return Numeric.arange(start, stop, step)", " return Numeric.arange(i,j)", " typecode = Numeric.Int", " typecode = Numeric.Float", " newobj = Numeric.arange(start, stop, step)", " res = Numeric.concatenate(tuple(objs),axis=self.axis)", "", " res = Numeric.arange(i,j)" ] } }, { "old_path": "scipy_base/info_scipy_base.py", "new_path": "scipy_base/info_scipy_base.py", "filename": "info_scipy_base.py", "extension": "py", "change_type": "MODIFY", "diff": "@@ -61,7 +61,7 @@\n vectorize -- a class that wraps a Python function taking scalar\n arguments into a generalized function which\n can handle arrays of arguments using the broadcast\n- rules of Numeric Python.\n+ rules of numerix Python.\n \n alter_numeric -- enhance numeric array behavior\n restore_numeric -- restore alterations done by alter_numeric\n", "added_lines": 1, "deleted_lines": 1, "source_code": "\"\"\" Basic functions used by several sub-packages and useful to have in the\nmain name-space\n\nType handling\n==============\niscomplexobj -- Test for complex object, scalar result\nisrealobj -- Test for real object, scalar result\niscomplex -- Test for complex elements, array result\nisreal -- Test for real elements, array result\nimag -- Imaginary part\nreal -- Real part\nreal_if_close -- Turns complex number with tiny imaginary part to real\nisneginf -- Tests for negative infinity ---|\nisposinf -- Tests for positive infinity |\nisnan -- Tests for nans |---- array results\nisinf -- Tests for infinity |\nisfinite -- Tests for finite numbers ---| \nisscalar -- True if argument is a scalar\nnan_to_num -- Replaces NaN's with 0 and infinities with large numbers\ntypename -- Return english name for given typecode character\ncast -- Dictionary of functions to force cast to each type\ncommon_type -- Determine the 'minimum common type code' for a group\n of arrays\nmintypecode -- Return minimal allowed common typecode.\n\nIndex tricks\n==================\nmgrid -- Method which allows easy construction of N-d 'mesh-grids'\nr_ -- Append and construct arrays: turns slice objects into\n ranges and concatenates them, for 2d arrays appends\n rows.\nc_ -- Append and construct arrays: for 2d arrays appends\n columns.\nrow -- Like r_ except ensure (row) Matrix return\ncol -- Like c_ except ensure (column) Matrix return\n\nindex_exp -- Konrad Hinsen's index_expression class instance which\n can be useful for building complicated slicing syntax.\n\nUseful functions\n==================\nselect -- Extension of where to multiple conditions and choices\nextract -- Extract 1d array from flattened array according to mask\ninsert -- Insert 1d array of values into Nd array according to mask\nlinspace -- Evenly spaced samples in linear space\nlogspace -- Evenly spaced samples in logarithmic space\nfix -- Round x to nearest integer towards zero\nmod -- Modulo mod(x,y) = x % y except keeps sign of y\namax -- Array maximum along axis\namin -- Array minimum along axis\nptp -- Array max-min along axis\ncumsum -- Cumulative sum along axis\nprod -- Product of elements along axis\ncumprod -- Cumluative product along axis\ndiff -- Discrete differences along axis\nangle -- Returns angle of complex argument\nunwrap -- Unwrap phase along given axis (1-d algorithm)\nsort_complex -- Sort a complex-array (based on real, then imaginary)\ntrim_zeros -- trim the leading and trailing zeros from 1D array.\n\nvectorize -- a class that wraps a Python function taking scalar\n arguments into a generalized function which\n can handle arrays of arguments using the broadcast\n rules of numerix Python.\n\nalter_numeric -- enhance numeric array behavior\nrestore_numeric -- restore alterations done by alter_numeric\n\nShape manipulation\n===================\nsqueeze -- Return a with length-one dimensions removed.\natleast_1d -- Force arrays to be > 1D\natleast_2d -- Force arrays to be > 2D\natleast_3d -- Force arrays to be > 3D\nvstack -- Stack arrays vertically (row on row)\nhstack -- Stack arrays horizontally (column on column)\ncolumn_stack -- Stack 1D arrays as columns into 2D array\ndstack -- Stack arrays depthwise (along third dimension)\nsplit -- Divide array into a list of sub-arrays\nhsplit -- Split into columns\nvsplit -- Split into rows\ndsplit -- Split along third dimension\n\nMatrix (2d array) manipluations\n===============================\nfliplr -- 2D array with columns flipped\nflipud -- 2D array with rows flipped\nrot90 -- Rotate a 2D array a multiple of 90 degrees\neye -- Return a 2D array with ones down a given diagonal\ndiag -- Construct a 2D array from a vector, or return a given\n diagonal from a 2D array. \nmat -- Construct a Matrix\nbmat -- Build a Matrix from blocks\n\nPolynomials\n============\npoly1d -- A one-dimensional polynomial class\n\npoly -- Return polynomial coefficients from roots\nroots -- Find roots of polynomial given coefficients\npolyint -- Integrate polynomial\npolyder -- Differentiate polynomial\npolyadd -- Add polynomials\npolysub -- Substract polynomials\npolymul -- Multiply polynomials\npolydiv -- Divide polynomials\npolyval -- Evaluate polynomial at given argument\n\nImport tricks\n=============\nppimport -- Postpone module import until trying to use it\nppimport_attr -- Postpone module import until trying to use its\n attribute\nppresolve -- Import postponed module and return it.\n\nMachine arithmetics\n===================\nmachar_single -- MachAr instance storing the parameters of system\n single precision floating point arithmetics\nmachar_double -- MachAr instance storing the parameters of system\n double precision floating point arithmetics\n\nThreading tricks\n================\nParallelExec -- Execute commands in parallel thread.\n\"\"\"\n\nstandalone = 1\n", "source_code_before": "\"\"\" Basic functions used by several sub-packages and useful to have in the\nmain name-space\n\nType handling\n==============\niscomplexobj -- Test for complex object, scalar result\nisrealobj -- Test for real object, scalar result\niscomplex -- Test for complex elements, array result\nisreal -- Test for real elements, array result\nimag -- Imaginary part\nreal -- Real part\nreal_if_close -- Turns complex number with tiny imaginary part to real\nisneginf -- Tests for negative infinity ---|\nisposinf -- Tests for positive infinity |\nisnan -- Tests for nans |---- array results\nisinf -- Tests for infinity |\nisfinite -- Tests for finite numbers ---| \nisscalar -- True if argument is a scalar\nnan_to_num -- Replaces NaN's with 0 and infinities with large numbers\ntypename -- Return english name for given typecode character\ncast -- Dictionary of functions to force cast to each type\ncommon_type -- Determine the 'minimum common type code' for a group\n of arrays\nmintypecode -- Return minimal allowed common typecode.\n\nIndex tricks\n==================\nmgrid -- Method which allows easy construction of N-d 'mesh-grids'\nr_ -- Append and construct arrays: turns slice objects into\n ranges and concatenates them, for 2d arrays appends\n rows.\nc_ -- Append and construct arrays: for 2d arrays appends\n columns.\nrow -- Like r_ except ensure (row) Matrix return\ncol -- Like c_ except ensure (column) Matrix return\n\nindex_exp -- Konrad Hinsen's index_expression class instance which\n can be useful for building complicated slicing syntax.\n\nUseful functions\n==================\nselect -- Extension of where to multiple conditions and choices\nextract -- Extract 1d array from flattened array according to mask\ninsert -- Insert 1d array of values into Nd array according to mask\nlinspace -- Evenly spaced samples in linear space\nlogspace -- Evenly spaced samples in logarithmic space\nfix -- Round x to nearest integer towards zero\nmod -- Modulo mod(x,y) = x % y except keeps sign of y\namax -- Array maximum along axis\namin -- Array minimum along axis\nptp -- Array max-min along axis\ncumsum -- Cumulative sum along axis\nprod -- Product of elements along axis\ncumprod -- Cumluative product along axis\ndiff -- Discrete differences along axis\nangle -- Returns angle of complex argument\nunwrap -- Unwrap phase along given axis (1-d algorithm)\nsort_complex -- Sort a complex-array (based on real, then imaginary)\ntrim_zeros -- trim the leading and trailing zeros from 1D array.\n\nvectorize -- a class that wraps a Python function taking scalar\n arguments into a generalized function which\n can handle arrays of arguments using the broadcast\n rules of Numeric Python.\n\nalter_numeric -- enhance numeric array behavior\nrestore_numeric -- restore alterations done by alter_numeric\n\nShape manipulation\n===================\nsqueeze -- Return a with length-one dimensions removed.\natleast_1d -- Force arrays to be > 1D\natleast_2d -- Force arrays to be > 2D\natleast_3d -- Force arrays to be > 3D\nvstack -- Stack arrays vertically (row on row)\nhstack -- Stack arrays horizontally (column on column)\ncolumn_stack -- Stack 1D arrays as columns into 2D array\ndstack -- Stack arrays depthwise (along third dimension)\nsplit -- Divide array into a list of sub-arrays\nhsplit -- Split into columns\nvsplit -- Split into rows\ndsplit -- Split along third dimension\n\nMatrix (2d array) manipluations\n===============================\nfliplr -- 2D array with columns flipped\nflipud -- 2D array with rows flipped\nrot90 -- Rotate a 2D array a multiple of 90 degrees\neye -- Return a 2D array with ones down a given diagonal\ndiag -- Construct a 2D array from a vector, or return a given\n diagonal from a 2D array. \nmat -- Construct a Matrix\nbmat -- Build a Matrix from blocks\n\nPolynomials\n============\npoly1d -- A one-dimensional polynomial class\n\npoly -- Return polynomial coefficients from roots\nroots -- Find roots of polynomial given coefficients\npolyint -- Integrate polynomial\npolyder -- Differentiate polynomial\npolyadd -- Add polynomials\npolysub -- Substract polynomials\npolymul -- Multiply polynomials\npolydiv -- Divide polynomials\npolyval -- Evaluate polynomial at given argument\n\nImport tricks\n=============\nppimport -- Postpone module import until trying to use it\nppimport_attr -- Postpone module import until trying to use its\n attribute\nppresolve -- Import postponed module and return it.\n\nMachine arithmetics\n===================\nmachar_single -- MachAr instance storing the parameters of system\n single precision floating point arithmetics\nmachar_double -- MachAr instance storing the parameters of system\n double precision floating point arithmetics\n\nThreading tricks\n================\nParallelExec -- Execute commands in parallel thread.\n\"\"\"\n\nstandalone = 1\n", "methods": [], "methods_before": [], "changed_methods": [], "nloc": 127, "complexity": 0, "token_count": 4, "diff_parsed": { "added": [ " rules of numerix Python." ], "deleted": [ " rules of Numeric Python." ] } }, { "old_path": "scipy_base/machar.py", "new_path": "scipy_base/machar.py", "filename": "machar.py", "extension": "py", "change_type": "MODIFY", "diff": "@@ -7,7 +7,8 @@\n \n __all__ = ['MachAr','machar_double','machar_single']\n \n-from Numeric import array\n+from numerix import array\n+from function_base import any\n \n class MachAr:\n \"\"\"Diagnosing machine parameters.\n@@ -69,14 +70,14 @@ def __init__(self,\n a = a + a\n temp = a + one\n temp1 = temp - a\n- if temp1 - one != zero:\n+ if any(temp1 - one != zero):\n break\n b = one\n while 1:\n b = b + b\n temp = a + b\n itemp = int_conv(temp-a)\n- if itemp != 0:\n+ if any(itemp != 0):\n break\n ibeta = itemp\n beta = float_conv(ibeta)\n@@ -89,7 +90,7 @@ def __init__(self,\n b = b * beta\n temp = b + one\n temp1 = temp - b\n- if temp1 - one != zero:\n+ if any(temp1 - one != zero):\n break\n \n betah = beta / two\n@@ -98,15 +99,15 @@ def __init__(self,\n a = a + a\n temp = a + one\n temp1 = temp - a\n- if temp1 - one != zero:\n+ if any(temp1 - one != zero):\n break\n temp = a + betah\n irnd = 0\n- if temp-a != zero:\n+ if any(temp-a != zero):\n irnd = 1\n tempa = a + beta\n temp = tempa + betah\n- if irnd==0 and temp-tempa != zero:\n+ if irnd==0 and any(temp-tempa != zero):\n irnd = 2\n \n # Determine negep and epsneg\n@@ -118,7 +119,7 @@ def __init__(self,\n b = a\n while 1:\n temp = one - a\n- if temp-one != zero:\n+ if any(temp-one != zero):\n break\n a = a * beta\n negep = negep - 1\n@@ -131,7 +132,7 @@ def __init__(self,\n \n while 1:\n temp = one + a\n- if temp-one != zero:\n+ if any(temp-one != zero):\n break\n a = a * beta\n machep = machep + 1\n@@ -140,7 +141,7 @@ def __init__(self,\n # Determine ngrd\n ngrd = 0\n temp = one + eps\n- if irnd==0 and temp*one - one != zero:\n+ if irnd==0 and any(temp*one - one != zero):\n ngrd = 1\n \n # Determine iexp\n@@ -154,10 +155,10 @@ def __init__(self,\n z = y*y\n a = z*one # Check here for underflow\n temp = z*t\n- if a+a == zero or abs(z)>=y:\n+ if any(a+a == zero) or any(abs(z)>=y):\n break\n temp1 = temp * betain\n- if temp1*beta == z:\n+ if any(temp1*beta == z):\n break\n i = i + 1\n k = k + k\n@@ -178,10 +179,10 @@ def __init__(self,\n y = y * betain\n a = y * one\n temp = y * t\n- if a+a != zero and abs(y) < xmin:\n+ if any(a+a != zero) and any(abs(y) < xmin):\n k = k + 1\n temp1 = temp * betain\n- if temp1*beta == y and temp != y:\n+ if any(temp1*beta == y) and any(temp != y):\n nxres = 3\n xmin = y\n break\n@@ -202,10 +203,10 @@ def __init__(self,\n maxexp = maxexp - 1\n if i > 20:\n maxexp = maxexp - 1\n- if a != y:\n+ if any(a != y):\n maxexp = maxexp - 2\n xmax = one - epsneg\n- if xmax*one != xmax:\n+ if any(xmax*one != xmax):\n xmax = one - beta*epsneg\n xmax = xmax / (xmin*beta*beta*beta)\n i = maxexp + minexp + 3\n@@ -257,17 +258,24 @@ def __str__(self):\n ---------------------------------------------------------------------\n ''' % self.__dict__\n \n+def frz(a):\n+ \"\"\"fix rank-0 --> rank-1\"\"\"\n+ if len(a.shape) == 0:\n+ a = a.copy()\n+ a.shape = (1,)\n+ return a\n+\n machar_double = MachAr(lambda v:array([v],'d'),\n- lambda v:v.astype('i')[0],\n- lambda v:array(v[0],'d'),\n- lambda v:'%24.16e' % array(v[0],'d'),\n- 'Numeric double precision floating point number')\n+ lambda v:frz(v.astype('i'))[0],\n+ lambda v:array(frz(v)[0],'d'),\n+ lambda v:'%24.16e' % array(frz(v)[0],'d'),\n+ 'numerix double precision floating point number')\n \n machar_single = MachAr(lambda v:array([v],'f'),\n- lambda v:v.astype('i')[0],\n- lambda v:array(v[0],'f'), #\n- lambda v:'%15.7e' % array(v[0],'f'),\n- 'Numeric single precision floating point number')\n+ lambda v:frz(v.astype('i'))[0],\n+ lambda v:array(frz(v)[0],'f'), #\n+ lambda v:'%15.7e' % array(frz(v)[0],'f'),\n+ 'numerix single precision floating point number')\n \n if __name__ == '__main__':\n print MachAr()\n", "added_lines": 32, "deleted_lines": 24, "source_code": "#\n# Machine arithmetics - determine the parameters of the\n# floating-point arithmetic system\n#\n# Author: Pearu Peterson, September 2003\n#\n\n__all__ = ['MachAr','machar_double','machar_single']\n\nfrom numerix import array\nfrom function_base import any\n\nclass MachAr:\n \"\"\"Diagnosing machine parameters.\n\n The following attributes are available:\n\n ibeta - radix in which numbers are represented\n it - number of base-ibeta digits in the floating point mantissa M\n machep - exponent of the smallest (most negative) power of ibeta that,\n added to 1.0,\n gives something different from 1.0\n eps - floating-point number beta**machep (floating point precision)\n negep - exponent of the smallest power of ibeta that, substracted\n from 1.0, gives something different from 1.0\n epsneg - floating-point number beta**negep\n iexp - number of bits in the exponent (including its sign and bias)\n minexp - smallest (most negative) power of ibeta consistent with there\n being no leading zeros in the mantissa\n xmin - floating point number beta**minexp (the smallest (in\n magnitude) usable floating value)\n maxexp - smallest (positive) power of ibeta that causes overflow\n xmax - (1-epsneg)* beta**maxexp (the largest (in magnitude)\n usable floating value)\n irnd - in range(6), information on what kind of rounding is done\n in addition, and on how underflow is handled\n ngrd - number of 'guard digits' used when truncating the product\n of two mantissas to fit the representation\n\n epsilon - same as eps\n tiny - same as xmin\n huge - same as xmax\n precision - int(-log10(eps))\n resolution - 10**(-precision)\n\n Reference:\n Numerical Recipies.\n \"\"\"\n def __init__(self,\n float_conv=float,\n int_conv=int,\n float_to_float=float,\n float_to_str = lambda v:'%24.16e' % v,\n title = 'Python floating point number',\n ):\n \"\"\"\n float_conv - convert integer to float (array)\n int_conv - convert float (array) to integer\n float_to_float - convert float array to float\n float_to_str - convert array float to str\n title - description of used floating point numbers\n \"\"\"\n one = float_conv(1)\n two = one + one\n zero = one - one\n\n # Determine ibeta and beta\n a = one\n while 1:\n a = a + a\n temp = a + one\n temp1 = temp - a\n if any(temp1 - one != zero):\n break\n b = one\n while 1:\n b = b + b\n temp = a + b\n itemp = int_conv(temp-a)\n if any(itemp != 0):\n break\n ibeta = itemp\n beta = float_conv(ibeta)\n\n # Determine it and irnd\n it = 0\n b = one\n while 1:\n it = it + 1\n b = b * beta\n temp = b + one\n temp1 = temp - b\n if any(temp1 - one != zero):\n break\n\n betah = beta / two\n a = one\n while 1:\n a = a + a\n temp = a + one\n temp1 = temp - a\n if any(temp1 - one != zero):\n break\n temp = a + betah\n irnd = 0\n if any(temp-a != zero):\n irnd = 1\n tempa = a + beta\n temp = tempa + betah\n if irnd==0 and any(temp-tempa != zero):\n irnd = 2\n\n # Determine negep and epsneg\n negep = it + 3\n betain = one / beta\n a = one\n for i in range(negep):\n a = a * betain\n b = a\n while 1:\n temp = one - a\n if any(temp-one != zero):\n break\n a = a * beta\n negep = negep - 1\n negep = -negep\n epsneg = a\n\n # Determine machep and eps\n machep = - it - 3\n a = b\n\n while 1:\n temp = one + a\n if any(temp-one != zero):\n break\n a = a * beta\n machep = machep + 1\n eps = a\n\n # Determine ngrd\n ngrd = 0\n temp = one + eps\n if irnd==0 and any(temp*one - one != zero):\n ngrd = 1\n\n # Determine iexp\n i = 0\n k = 1\n z = betain\n t = one + eps\n nxres = 0\n while 1:\n y = z\n z = y*y\n a = z*one # Check here for underflow\n temp = z*t\n if any(a+a == zero) or any(abs(z)>=y):\n break\n temp1 = temp * betain\n if any(temp1*beta == z):\n break\n i = i + 1\n k = k + k\n if ibeta != 10:\n iexp = i + 1\n mx = k + k\n else:\n iexp = 2\n iz = ibeta\n while k >= iz:\n iz = iz * ibeta\n iexp = iexp + 1\n mx = iz + iz - 1\n\n # Determine minexp and xmin\n while 1:\n xmin = y\n y = y * betain\n a = y * one\n temp = y * t\n if any(a+a != zero) and any(abs(y) < xmin):\n k = k + 1\n temp1 = temp * betain\n if any(temp1*beta == y) and any(temp != y):\n nxres = 3\n xmin = y\n break\n else:\n break\n minexp = -k\n\n # Determine maxexp, xmax\n if mx <= k + k - 3 and ibeta != 10:\n mx = mx + mx\n iexp = iexp + 1\n maxexp = mx + minexp\n irnd = irnd + nxres\n if irnd >= 2:\n maxexp = maxexp - 2\n i = maxexp + minexp\n if ibeta == 2 and not i:\n maxexp = maxexp - 1\n if i > 20:\n maxexp = maxexp - 1\n if any(a != y):\n maxexp = maxexp - 2\n xmax = one - epsneg\n if any(xmax*one != xmax):\n xmax = one - beta*epsneg\n xmax = xmax / (xmin*beta*beta*beta)\n i = maxexp + minexp + 3\n for j in range(i):\n if ibeta==2:\n xmax = xmax + xmax\n else:\n xmax = xmax * beta\n\n self.ibeta = ibeta\n self.it = it\n self.negep = negep\n self.epsneg = float_to_float(epsneg)\n self._str_epsneg = float_to_str(epsneg)\n self.machep = machep\n self.eps = float_to_float(eps)\n self._str_eps = float_to_str(eps)\n self.ngrd = ngrd\n self.iexp = iexp\n self.minexp = minexp\n self.xmin = float_to_float(xmin)\n self._str_xmin = float_to_str(xmin)\n self.maxexp = maxexp\n self.xmax = float_to_float(xmax)\n self._str_xmax = float_to_str(xmax)\n self.irnd = irnd\n\n self.title = title\n # Commonly used parameters\n self.epsilon = self.eps\n self.tiny = self.xmin\n self.huge = self.xmax\n\n import math\n self.precision = int(-math.log10(float_to_float(self.eps)))\n ten = two + two + two + two + two\n resolution = ten ** (-self.precision)\n self.resolution = float_to_float(resolution)\n\n def __str__(self):\n return '''\\\nMachine parameters for %(title)s\n---------------------------------------------------------------------\nibeta=%(ibeta)s it=%(it)s iexp=%(iexp)s ngrd=%(ngrd)s irnd=%(irnd)s\nmachep=%(machep)s eps=%(_str_eps)s (beta**machep == epsilon)\nnegep =%(negep)s epsneg=%(_str_epsneg)s (beta**epsneg)\nminexp=%(minexp)s xmin=%(_str_xmin)s (beta**minexp == tiny)\nmaxexp=%(maxexp)s xmax=%(_str_xmax)s ((1-epsneg)*beta**maxexp == huge)\n---------------------------------------------------------------------\n''' % self.__dict__\n\ndef frz(a):\n \"\"\"fix rank-0 --> rank-1\"\"\"\n if len(a.shape) == 0:\n a = a.copy()\n a.shape = (1,)\n return a\n\nmachar_double = MachAr(lambda v:array([v],'d'),\n lambda v:frz(v.astype('i'))[0],\n lambda v:array(frz(v)[0],'d'),\n lambda v:'%24.16e' % array(frz(v)[0],'d'),\n 'numerix double precision floating point number')\n\nmachar_single = MachAr(lambda v:array([v],'f'),\n lambda v:frz(v.astype('i'))[0],\n lambda v:array(frz(v)[0],'f'), #\n lambda v:'%15.7e' % array(frz(v)[0],'f'),\n 'numerix single precision floating point number')\n\nif __name__ == '__main__':\n print MachAr()\n print machar_double\n print machar_single\n", "source_code_before": "#\n# Machine arithmetics - determine the parameters of the\n# floating-point arithmetic system\n#\n# Author: Pearu Peterson, September 2003\n#\n\n__all__ = ['MachAr','machar_double','machar_single']\n\nfrom Numeric import array\n\nclass MachAr:\n \"\"\"Diagnosing machine parameters.\n\n The following attributes are available:\n\n ibeta - radix in which numbers are represented\n it - number of base-ibeta digits in the floating point mantissa M\n machep - exponent of the smallest (most negative) power of ibeta that,\n added to 1.0,\n gives something different from 1.0\n eps - floating-point number beta**machep (floating point precision)\n negep - exponent of the smallest power of ibeta that, substracted\n from 1.0, gives something different from 1.0\n epsneg - floating-point number beta**negep\n iexp - number of bits in the exponent (including its sign and bias)\n minexp - smallest (most negative) power of ibeta consistent with there\n being no leading zeros in the mantissa\n xmin - floating point number beta**minexp (the smallest (in\n magnitude) usable floating value)\n maxexp - smallest (positive) power of ibeta that causes overflow\n xmax - (1-epsneg)* beta**maxexp (the largest (in magnitude)\n usable floating value)\n irnd - in range(6), information on what kind of rounding is done\n in addition, and on how underflow is handled\n ngrd - number of 'guard digits' used when truncating the product\n of two mantissas to fit the representation\n\n epsilon - same as eps\n tiny - same as xmin\n huge - same as xmax\n precision - int(-log10(eps))\n resolution - 10**(-precision)\n\n Reference:\n Numerical Recipies.\n \"\"\"\n def __init__(self,\n float_conv=float,\n int_conv=int,\n float_to_float=float,\n float_to_str = lambda v:'%24.16e' % v,\n title = 'Python floating point number',\n ):\n \"\"\"\n float_conv - convert integer to float (array)\n int_conv - convert float (array) to integer\n float_to_float - convert float array to float\n float_to_str - convert array float to str\n title - description of used floating point numbers\n \"\"\"\n one = float_conv(1)\n two = one + one\n zero = one - one\n\n # Determine ibeta and beta\n a = one\n while 1:\n a = a + a\n temp = a + one\n temp1 = temp - a\n if temp1 - one != zero:\n break\n b = one\n while 1:\n b = b + b\n temp = a + b\n itemp = int_conv(temp-a)\n if itemp != 0:\n break\n ibeta = itemp\n beta = float_conv(ibeta)\n\n # Determine it and irnd\n it = 0\n b = one\n while 1:\n it = it + 1\n b = b * beta\n temp = b + one\n temp1 = temp - b\n if temp1 - one != zero:\n break\n\n betah = beta / two\n a = one\n while 1:\n a = a + a\n temp = a + one\n temp1 = temp - a\n if temp1 - one != zero:\n break\n temp = a + betah\n irnd = 0\n if temp-a != zero:\n irnd = 1\n tempa = a + beta\n temp = tempa + betah\n if irnd==0 and temp-tempa != zero:\n irnd = 2\n\n # Determine negep and epsneg\n negep = it + 3\n betain = one / beta\n a = one\n for i in range(negep):\n a = a * betain\n b = a\n while 1:\n temp = one - a\n if temp-one != zero:\n break\n a = a * beta\n negep = negep - 1\n negep = -negep\n epsneg = a\n\n # Determine machep and eps\n machep = - it - 3\n a = b\n\n while 1:\n temp = one + a\n if temp-one != zero:\n break\n a = a * beta\n machep = machep + 1\n eps = a\n\n # Determine ngrd\n ngrd = 0\n temp = one + eps\n if irnd==0 and temp*one - one != zero:\n ngrd = 1\n\n # Determine iexp\n i = 0\n k = 1\n z = betain\n t = one + eps\n nxres = 0\n while 1:\n y = z\n z = y*y\n a = z*one # Check here for underflow\n temp = z*t\n if a+a == zero or abs(z)>=y:\n break\n temp1 = temp * betain\n if temp1*beta == z:\n break\n i = i + 1\n k = k + k\n if ibeta != 10:\n iexp = i + 1\n mx = k + k\n else:\n iexp = 2\n iz = ibeta\n while k >= iz:\n iz = iz * ibeta\n iexp = iexp + 1\n mx = iz + iz - 1\n\n # Determine minexp and xmin\n while 1:\n xmin = y\n y = y * betain\n a = y * one\n temp = y * t\n if a+a != zero and abs(y) < xmin:\n k = k + 1\n temp1 = temp * betain\n if temp1*beta == y and temp != y:\n nxres = 3\n xmin = y\n break\n else:\n break\n minexp = -k\n\n # Determine maxexp, xmax\n if mx <= k + k - 3 and ibeta != 10:\n mx = mx + mx\n iexp = iexp + 1\n maxexp = mx + minexp\n irnd = irnd + nxres\n if irnd >= 2:\n maxexp = maxexp - 2\n i = maxexp + minexp\n if ibeta == 2 and not i:\n maxexp = maxexp - 1\n if i > 20:\n maxexp = maxexp - 1\n if a != y:\n maxexp = maxexp - 2\n xmax = one - epsneg\n if xmax*one != xmax:\n xmax = one - beta*epsneg\n xmax = xmax / (xmin*beta*beta*beta)\n i = maxexp + minexp + 3\n for j in range(i):\n if ibeta==2:\n xmax = xmax + xmax\n else:\n xmax = xmax * beta\n\n self.ibeta = ibeta\n self.it = it\n self.negep = negep\n self.epsneg = float_to_float(epsneg)\n self._str_epsneg = float_to_str(epsneg)\n self.machep = machep\n self.eps = float_to_float(eps)\n self._str_eps = float_to_str(eps)\n self.ngrd = ngrd\n self.iexp = iexp\n self.minexp = minexp\n self.xmin = float_to_float(xmin)\n self._str_xmin = float_to_str(xmin)\n self.maxexp = maxexp\n self.xmax = float_to_float(xmax)\n self._str_xmax = float_to_str(xmax)\n self.irnd = irnd\n\n self.title = title\n # Commonly used parameters\n self.epsilon = self.eps\n self.tiny = self.xmin\n self.huge = self.xmax\n\n import math\n self.precision = int(-math.log10(float_to_float(self.eps)))\n ten = two + two + two + two + two\n resolution = ten ** (-self.precision)\n self.resolution = float_to_float(resolution)\n\n def __str__(self):\n return '''\\\nMachine parameters for %(title)s\n---------------------------------------------------------------------\nibeta=%(ibeta)s it=%(it)s iexp=%(iexp)s ngrd=%(ngrd)s irnd=%(irnd)s\nmachep=%(machep)s eps=%(_str_eps)s (beta**machep == epsilon)\nnegep =%(negep)s epsneg=%(_str_epsneg)s (beta**epsneg)\nminexp=%(minexp)s xmin=%(_str_xmin)s (beta**minexp == tiny)\nmaxexp=%(maxexp)s xmax=%(_str_xmax)s ((1-epsneg)*beta**maxexp == huge)\n---------------------------------------------------------------------\n''' % self.__dict__\n\nmachar_double = MachAr(lambda v:array([v],'d'),\n lambda v:v.astype('i')[0],\n lambda v:array(v[0],'d'),\n lambda v:'%24.16e' % array(v[0],'d'),\n 'Numeric double precision floating point number')\n\nmachar_single = MachAr(lambda v:array([v],'f'),\n lambda v:v.astype('i')[0],\n lambda v:array(v[0],'f'), #\n lambda v:'%15.7e' % array(v[0],'f'),\n 'Numeric single precision floating point number')\n\nif __name__ == '__main__':\n print MachAr()\n print machar_double\n print machar_single\n", "methods": [ { "name": "__init__", "long_name": "__init__( self , float_conv = float , int_conv = int , float_to_float = float , float_to_str = lambda v : '%24.16e' % v , title = 'Python floating point number' , )", "filename": "machar.py", "nloc": 170, "complexity": 40, "token_count": 928, "parameters": [ "self", "float_conv", "int_conv", "float_to_float", "float_to_str", "title" ], "start_line": 49, "end_line": 247, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 199, "top_nesting_level": 1 }, { "name": "__str__", "long_name": "__str__( self )", "filename": "machar.py", "nloc": 11, "complexity": 1, "token_count": 11, "parameters": [ "self" ], "start_line": 249, "end_line": 259, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 11, "top_nesting_level": 1 }, { "name": "frz", "long_name": "frz( a )", "filename": "machar.py", "nloc": 5, "complexity": 2, "token_count": 33, "parameters": [ "a" ], "start_line": 261, "end_line": 266, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 6, "top_nesting_level": 0 } ], "methods_before": [ { "name": "__init__", "long_name": "__init__( self , float_conv = float , int_conv = int , float_to_float = float , float_to_str = lambda v : '%24.16e' % v , title = 'Python floating point number' , )", "filename": "machar.py", "nloc": 170, "complexity": 40, "token_count": 874, "parameters": [ "self", "float_conv", "int_conv", "float_to_float", "float_to_str", "title" ], "start_line": 48, "end_line": 246, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 199, "top_nesting_level": 1 }, { "name": "__str__", "long_name": "__str__( self )", "filename": "machar.py", "nloc": 11, "complexity": 1, "token_count": 11, "parameters": [ "self" ], "start_line": 248, "end_line": 258, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 11, "top_nesting_level": 1 } ], "changed_methods": [ { "name": "__init__", "long_name": "__init__( self , float_conv = float , int_conv = int , float_to_float = float , float_to_str = lambda v : '%24.16e' % v , title = 'Python floating point number' , )", "filename": "machar.py", "nloc": 170, "complexity": 40, "token_count": 928, "parameters": [ "self", "float_conv", "int_conv", "float_to_float", "float_to_str", "title" ], "start_line": 49, "end_line": 247, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 199, "top_nesting_level": 1 }, { "name": "frz", "long_name": "frz( a )", "filename": "machar.py", "nloc": 5, "complexity": 2, "token_count": 33, "parameters": [ "a" ], "start_line": 261, "end_line": 266, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 6, "top_nesting_level": 0 } ], "nloc": 239, "complexity": 43, "token_count": 1145, "diff_parsed": { "added": [ "from numerix import array", "from function_base import any", " if any(temp1 - one != zero):", " if any(itemp != 0):", " if any(temp1 - one != zero):", " if any(temp1 - one != zero):", " if any(temp-a != zero):", " if irnd==0 and any(temp-tempa != zero):", " if any(temp-one != zero):", " if any(temp-one != zero):", " if irnd==0 and any(temp*one - one != zero):", " if any(a+a == zero) or any(abs(z)>=y):", " if any(temp1*beta == z):", " if any(a+a != zero) and any(abs(y) < xmin):", " if any(temp1*beta == y) and any(temp != y):", " if any(a != y):", " if any(xmax*one != xmax):", "def frz(a):", " \"\"\"fix rank-0 --> rank-1\"\"\"", " if len(a.shape) == 0:", " a = a.copy()", " a.shape = (1,)", " return a", "", " lambda v:frz(v.astype('i'))[0],", " lambda v:array(frz(v)[0],'d'),", " lambda v:'%24.16e' % array(frz(v)[0],'d'),", " 'numerix double precision floating point number')", " lambda v:frz(v.astype('i'))[0],", " lambda v:array(frz(v)[0],'f'), #", " lambda v:'%15.7e' % array(frz(v)[0],'f'),", " 'numerix single precision floating point number')" ], "deleted": [ "from Numeric import array", " if temp1 - one != zero:", " if itemp != 0:", " if temp1 - one != zero:", " if temp1 - one != zero:", " if temp-a != zero:", " if irnd==0 and temp-tempa != zero:", " if temp-one != zero:", " if temp-one != zero:", " if irnd==0 and temp*one - one != zero:", " if a+a == zero or abs(z)>=y:", " if temp1*beta == z:", " if a+a != zero and abs(y) < xmin:", " if temp1*beta == y and temp != y:", " if a != y:", " if xmax*one != xmax:", " lambda v:v.astype('i')[0],", " lambda v:array(v[0],'d'),", " lambda v:'%24.16e' % array(v[0],'d'),", " 'Numeric double precision floating point number')", " lambda v:v.astype('i')[0],", " lambda v:array(v[0],'f'), #", " lambda v:'%15.7e' % array(v[0],'f'),", " 'Numeric single precision floating point number')" ] } }, { "old_path": "scipy_base/matrix_base.py", "new_path": "scipy_base/matrix_base.py", "filename": "matrix_base.py", "extension": "py", "change_type": "MODIFY", "diff": "@@ -4,12 +4,11 @@\n \n __all__ = ['diag','eye','fliplr','flipud','rot90','bmat','matrix']\n \n-from Numeric import *\n+from numerix import *\n from type_check import asarray\n-import Matrix\n-\n-matrix = Matrix.Matrix\n+import sys\n \n+matrix = Matrix\n \n def fliplr(m):\n \"\"\" returns a 2-D matrix m with the rows preserved and columns flipped \n@@ -100,7 +99,6 @@ def _from_string(str,gdict,ldict):\n rowtup.append(concatenate(coltup,axis=-1))\n return concatenate(rowtup,axis=0)\n \n-import sys\n def bmat(obj,gdict=None,ldict=None):\n \"\"\"Build a matrix object from string, nested sequence, or array.\n \n", "added_lines": 3, "deleted_lines": 5, "source_code": "\"\"\" Basic functions for manipulating 2d arrays\n\n\"\"\"\n\n__all__ = ['diag','eye','fliplr','flipud','rot90','bmat','matrix']\n\nfrom numerix import *\nfrom type_check import asarray\nimport sys\n\nmatrix = Matrix\n\ndef fliplr(m):\n \"\"\" returns a 2-D matrix m with the rows preserved and columns flipped \n in the left/right direction. Only works with 2-D arrays.\n \"\"\"\n m = asarray(m)\n if len(m.shape) != 2:\n raise ValueError, \"Input must be 2-D.\"\n return m[:, ::-1]\n\ndef flipud(m):\n \"\"\" returns a 2-D matrix with the columns preserved and rows flipped in\n the up/down direction. Only works with 2-D arrays.\n \"\"\"\n m = asarray(m)\n if len(m.shape) != 2:\n raise ValueError, \"Input must be 2-D.\"\n return m[::-1]\n \n# reshape(x, m, n) is not used, instead use reshape(x, (m, n))\n\ndef rot90(m, k=1):\n \"\"\" returns the matrix found by rotating m by k*90 degrees in the \n counterclockwise direction.\n \"\"\"\n m = asarray(m)\n if len(m.shape) != 2:\n raise ValueError, \"Input must be 2-D.\"\n k = k % 4\n if k == 0: return m\n elif k == 1: return transpose(fliplr(m))\n elif k == 2: return fliplr(flipud(m))\n else: return fliplr(transpose(m)) # k==3\n \ndef eye(N, M=None, k=0, typecode='d'):\n \"\"\" eye returns a N-by-M matrix where the k-th diagonal is all ones, \n and everything else is zeros.\n \"\"\"\n if M is None: M = N\n if type(M) == type('d'): \n typecode = M\n M = N\n m = equal(subtract.outer(arange(N), arange(M)),-k)\n if typecode is None:\n return m\n else:\n return m.astype(typecode)\n\ndef diag(v, k=0):\n \"\"\" returns the k-th diagonal if v is a matrix or returns a matrix \n with v as the k-th diagonal if v is a vector.\n \"\"\"\n v = asarray(v)\n s = v.shape\n if len(s)==1:\n n = s[0]+abs(k)\n if k > 0:\n v = concatenate((zeros(k, v.typecode()),v))\n elif k < 0:\n v = concatenate((v,zeros(-k, v.typecode())))\n return eye(n, k=k)*v\n elif len(s)==2:\n v = add.reduce(eye(s[0], s[1], k=k)*v)\n if k > 0: return v[k:]\n elif k < 0: return v[:k]\n else: return v\n else:\n raise ValueError, \"Input must be 1- or 2-D.\"\n\n\ndef _from_string(str,gdict,ldict):\n rows = str.split(';')\n rowtup = []\n for row in rows:\n trow = row.split(',')\n coltup = []\n for col in trow:\n col = col.strip()\n try:\n thismat = gdict[col]\n except KeyError:\n try:\n thismat = ldict[col]\n except KeyError:\n raise KeyError, \"%s not found\" % (col,)\n \n coltup.append(thismat)\n rowtup.append(concatenate(coltup,axis=-1))\n return concatenate(rowtup,axis=0)\n\ndef bmat(obj,gdict=None,ldict=None):\n \"\"\"Build a matrix object from string, nested sequence, or array.\n\n Ex: F = bmat('A, B; C, D') \n F = bmat([[A,B],[C,D]])\n F = bmat(r_[c_[A,B],c_[C,D]])\n\n all produce the same Matrix Object [ A B ]\n [ C D ]\n \n if A, B, C, and D are appropriately shaped 2-d arrays.\n \"\"\"\n if isinstance(obj, types.StringType):\n if gdict is None:\n # get previous frame\n frame = sys._getframe().f_back\n glob_dict = frame.f_globals\n loc_dict = frame.f_locals\n else:\n glob_dict = gdict\n loc_dict = ldict\n \n return Matrix.Matrix(_from_string(obj, glob_dict, loc_dict))\n \n if isinstance(obj, (types.TupleType, types.ListType)):\n # [[A,B],[C,D]]\n arr_rows = []\n for row in obj:\n if isinstance(row, ArrayType): # not 2-d\n return Matrix.Matrix(concatenate(obj,axis=-1))\n else:\n arr_rows.append(concatenate(row,axis=-1))\n return Matrix.Matrix(concatenate(arr_rows,axis=0))\n if isinstance(obj, ArrayType):\n return Matrix.Matrix(obj)\n\n", "source_code_before": "\"\"\" Basic functions for manipulating 2d arrays\n\n\"\"\"\n\n__all__ = ['diag','eye','fliplr','flipud','rot90','bmat','matrix']\n\nfrom Numeric import *\nfrom type_check import asarray\nimport Matrix\n\nmatrix = Matrix.Matrix\n\n\ndef fliplr(m):\n \"\"\" returns a 2-D matrix m with the rows preserved and columns flipped \n in the left/right direction. Only works with 2-D arrays.\n \"\"\"\n m = asarray(m)\n if len(m.shape) != 2:\n raise ValueError, \"Input must be 2-D.\"\n return m[:, ::-1]\n\ndef flipud(m):\n \"\"\" returns a 2-D matrix with the columns preserved and rows flipped in\n the up/down direction. Only works with 2-D arrays.\n \"\"\"\n m = asarray(m)\n if len(m.shape) != 2:\n raise ValueError, \"Input must be 2-D.\"\n return m[::-1]\n \n# reshape(x, m, n) is not used, instead use reshape(x, (m, n))\n\ndef rot90(m, k=1):\n \"\"\" returns the matrix found by rotating m by k*90 degrees in the \n counterclockwise direction.\n \"\"\"\n m = asarray(m)\n if len(m.shape) != 2:\n raise ValueError, \"Input must be 2-D.\"\n k = k % 4\n if k == 0: return m\n elif k == 1: return transpose(fliplr(m))\n elif k == 2: return fliplr(flipud(m))\n else: return fliplr(transpose(m)) # k==3\n \ndef eye(N, M=None, k=0, typecode='d'):\n \"\"\" eye returns a N-by-M matrix where the k-th diagonal is all ones, \n and everything else is zeros.\n \"\"\"\n if M is None: M = N\n if type(M) == type('d'): \n typecode = M\n M = N\n m = equal(subtract.outer(arange(N), arange(M)),-k)\n if typecode is None:\n return m\n else:\n return m.astype(typecode)\n\ndef diag(v, k=0):\n \"\"\" returns the k-th diagonal if v is a matrix or returns a matrix \n with v as the k-th diagonal if v is a vector.\n \"\"\"\n v = asarray(v)\n s = v.shape\n if len(s)==1:\n n = s[0]+abs(k)\n if k > 0:\n v = concatenate((zeros(k, v.typecode()),v))\n elif k < 0:\n v = concatenate((v,zeros(-k, v.typecode())))\n return eye(n, k=k)*v\n elif len(s)==2:\n v = add.reduce(eye(s[0], s[1], k=k)*v)\n if k > 0: return v[k:]\n elif k < 0: return v[:k]\n else: return v\n else:\n raise ValueError, \"Input must be 1- or 2-D.\"\n\n\ndef _from_string(str,gdict,ldict):\n rows = str.split(';')\n rowtup = []\n for row in rows:\n trow = row.split(',')\n coltup = []\n for col in trow:\n col = col.strip()\n try:\n thismat = gdict[col]\n except KeyError:\n try:\n thismat = ldict[col]\n except KeyError:\n raise KeyError, \"%s not found\" % (col,)\n \n coltup.append(thismat)\n rowtup.append(concatenate(coltup,axis=-1))\n return concatenate(rowtup,axis=0)\n\nimport sys\ndef bmat(obj,gdict=None,ldict=None):\n \"\"\"Build a matrix object from string, nested sequence, or array.\n\n Ex: F = bmat('A, B; C, D') \n F = bmat([[A,B],[C,D]])\n F = bmat(r_[c_[A,B],c_[C,D]])\n\n all produce the same Matrix Object [ A B ]\n [ C D ]\n \n if A, B, C, and D are appropriately shaped 2-d arrays.\n \"\"\"\n if isinstance(obj, types.StringType):\n if gdict is None:\n # get previous frame\n frame = sys._getframe().f_back\n glob_dict = frame.f_globals\n loc_dict = frame.f_locals\n else:\n glob_dict = gdict\n loc_dict = ldict\n \n return Matrix.Matrix(_from_string(obj, glob_dict, loc_dict))\n \n if isinstance(obj, (types.TupleType, types.ListType)):\n # [[A,B],[C,D]]\n arr_rows = []\n for row in obj:\n if isinstance(row, ArrayType): # not 2-d\n return Matrix.Matrix(concatenate(obj,axis=-1))\n else:\n arr_rows.append(concatenate(row,axis=-1))\n return Matrix.Matrix(concatenate(arr_rows,axis=0))\n if isinstance(obj, ArrayType):\n return Matrix.Matrix(obj)\n\n", "methods": [ { "name": "fliplr", "long_name": "fliplr( m )", "filename": "matrix_base.py", "nloc": 5, "complexity": 2, "token_count": 35, "parameters": [ "m" ], "start_line": 13, "end_line": 20, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 8, "top_nesting_level": 0 }, { "name": "flipud", "long_name": "flipud( m )", "filename": "matrix_base.py", "nloc": 5, "complexity": 2, "token_count": 33, "parameters": [ "m" ], "start_line": 22, "end_line": 29, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 8, "top_nesting_level": 0 }, { "name": "rot90", "long_name": "rot90( m , k = 1 )", "filename": "matrix_base.py", "nloc": 9, "complexity": 5, "token_count": 78, "parameters": [ "m", "k" ], "start_line": 33, "end_line": 44, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 12, "top_nesting_level": 0 }, { "name": "eye", "long_name": "eye( N , M = None , k = 0 , typecode = 'd' )", "filename": "matrix_base.py", "nloc": 10, "complexity": 4, "token_count": 81, "parameters": [ "N", "M", "k", "typecode" ], "start_line": 46, "end_line": 58, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 13, "top_nesting_level": 0 }, { "name": "diag", "long_name": "diag( v , k = 0 )", "filename": "matrix_base.py", "nloc": 17, "complexity": 7, "token_count": 165, "parameters": [ "v", "k" ], "start_line": 60, "end_line": 79, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 20, "top_nesting_level": 0 }, { "name": "_from_string", "long_name": "_from_string( str , gdict , ldict )", "filename": "matrix_base.py", "nloc": 18, "complexity": 5, "token_count": 110, "parameters": [ "str", "gdict", "ldict" ], "start_line": 82, "end_line": 100, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 19, "top_nesting_level": 0 }, { "name": "bmat", "long_name": "bmat( obj , gdict = None , ldict = None )", "filename": "matrix_base.py", "nloc": 20, "complexity": 7, "token_count": 163, "parameters": [ "obj", "gdict", "ldict" ], "start_line": 102, "end_line": 136, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 35, "top_nesting_level": 0 } ], "methods_before": [ { "name": "fliplr", "long_name": "fliplr( m )", "filename": "matrix_base.py", "nloc": 5, "complexity": 2, "token_count": 35, "parameters": [ "m" ], "start_line": 14, "end_line": 21, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 8, "top_nesting_level": 0 }, { "name": "flipud", "long_name": "flipud( m )", "filename": "matrix_base.py", "nloc": 5, "complexity": 2, "token_count": 33, "parameters": [ "m" ], "start_line": 23, "end_line": 30, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 8, "top_nesting_level": 0 }, { "name": "rot90", "long_name": "rot90( m , k = 1 )", "filename": "matrix_base.py", "nloc": 9, "complexity": 5, "token_count": 78, "parameters": [ "m", "k" ], "start_line": 34, "end_line": 45, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 12, "top_nesting_level": 0 }, { "name": "eye", "long_name": "eye( N , M = None , k = 0 , typecode = 'd' )", "filename": "matrix_base.py", "nloc": 10, "complexity": 4, "token_count": 81, "parameters": [ "N", "M", "k", "typecode" ], "start_line": 47, "end_line": 59, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 13, "top_nesting_level": 0 }, { "name": "diag", "long_name": "diag( v , k = 0 )", "filename": "matrix_base.py", "nloc": 17, "complexity": 7, "token_count": 165, "parameters": [ "v", "k" ], "start_line": 61, "end_line": 80, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 20, "top_nesting_level": 0 }, { "name": "_from_string", "long_name": "_from_string( str , gdict , ldict )", "filename": "matrix_base.py", "nloc": 18, "complexity": 5, "token_count": 110, "parameters": [ "str", "gdict", "ldict" ], "start_line": 83, "end_line": 101, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 19, "top_nesting_level": 0 }, { "name": "bmat", "long_name": "bmat( obj , gdict = None , ldict = None )", "filename": "matrix_base.py", "nloc": 20, "complexity": 7, "token_count": 163, "parameters": [ "obj", "gdict", "ldict" ], "start_line": 104, "end_line": 138, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 35, "top_nesting_level": 0 } ], "changed_methods": [], "nloc": 92, "complexity": 32, "token_count": 703, "diff_parsed": { "added": [ "from numerix import *", "import sys", "matrix = Matrix" ], "deleted": [ "from Numeric import *", "import Matrix", "", "matrix = Matrix.Matrix", "import sys" ] } }, { "old_path": null, "new_path": "scipy_base/numerix.h", "filename": "numerix.h", "extension": "h", "change_type": "ADD", "diff": "@@ -0,0 +1,34 @@\n+#if !defined(_NUMERIX_)\n+#define _NUMERIX_\n+\n+#if defined(NUMARRAY)\n+# include \"numarray/arrayobject.h\"\n+#else\n+# include \"Numeric/arrayobject.h\"\n+#endif\n+\n+#if defined(NUMARRAY)\n+# define NX_ZERO(a) PyArray_Zero(a)\n+#else\n+# define NX_ZERO(a) (a)->descr->zero\n+#endif\n+\n+#if defined(NUMARRAY)\n+# define NX_ONE(a) PyArray_One(a)\n+#else\n+# define NX_ONE(a) (a)->descr->one\n+#endif\n+\n+#if defined(NUMARRAY)\n+# define NX_GETITEM(a, ptr) (a)->descr->_get((a), ((char*)ptr)-(a)->data)\n+#else\n+# define NX_GETITEM(a, ptr) (a)->descr->getitem(ptr)\n+#endif\n+\n+#if defined(NUMARRAY)\n+# define NX_SETITEM(a, ptr, value) (a)->descr->_set((a), ((char*)ptr)-(a)->data, value)\n+#else\n+# define NX_SETITEM(a, ptr, value) (a)->descr->setitem(value, ptr)\n+#endif\n+\n+#endif\n", "added_lines": 34, "deleted_lines": 0, "source_code": "#if !defined(_NUMERIX_)\n#define _NUMERIX_\n\n#if defined(NUMARRAY)\n# include \"numarray/arrayobject.h\"\n#else\n# include \"Numeric/arrayobject.h\"\n#endif\n\n#if defined(NUMARRAY)\n# define NX_ZERO(a) PyArray_Zero(a)\n#else\n# define NX_ZERO(a) (a)->descr->zero\n#endif\n\n#if defined(NUMARRAY)\n# define NX_ONE(a) PyArray_One(a)\n#else\n# define NX_ONE(a) (a)->descr->one\n#endif\n\n#if defined(NUMARRAY)\n# define NX_GETITEM(a, ptr) (a)->descr->_get((a), ((char*)ptr)-(a)->data)\n#else\n# define NX_GETITEM(a, ptr) (a)->descr->getitem(ptr)\n#endif\n\n#if defined(NUMARRAY)\n# define NX_SETITEM(a, ptr, value) (a)->descr->_set((a), ((char*)ptr)-(a)->data, value)\n#else\n# define NX_SETITEM(a, ptr, value) (a)->descr->setitem(value, ptr)\n#endif\n\n#endif\n", "source_code_before": null, "methods": [], "methods_before": [], "changed_methods": [], "nloc": 2, "complexity": 0, "token_count": 4, "diff_parsed": { "added": [ "#if !defined(_NUMERIX_)", "#define _NUMERIX_", "", "#if defined(NUMARRAY)", "# include \"numarray/arrayobject.h\"", "#else", "# include \"Numeric/arrayobject.h\"", "#endif", "", "#if defined(NUMARRAY)", "# define NX_ZERO(a) PyArray_Zero(a)", "#else", "# define NX_ZERO(a) (a)->descr->zero", "#endif", "", "#if defined(NUMARRAY)", "# define NX_ONE(a) PyArray_One(a)", "#else", "# define NX_ONE(a) (a)->descr->one", "#endif", "", "#if defined(NUMARRAY)", "# define NX_GETITEM(a, ptr) (a)->descr->_get((a), ((char*)ptr)-(a)->data)", "#else", "# define NX_GETITEM(a, ptr) (a)->descr->getitem(ptr)", "#endif", "", "#if defined(NUMARRAY)", "# define NX_SETITEM(a, ptr, value) (a)->descr->_set((a), ((char*)ptr)-(a)->data, value)", "#else", "# define NX_SETITEM(a, ptr, value) (a)->descr->setitem(value, ptr)", "#endif", "", "#endif" ], "deleted": [] } }, { "old_path": null, "new_path": "scipy_base/numerix.py", "filename": "numerix.py", "extension": "py", "change_type": "ADD", "diff": "@@ -0,0 +1,85 @@\n+\"\"\"numerix imports either Numeric or numarray based on various selectors.\n+\n+0. If the value \"--numarray\" or \"--Numeric\" is specified on the\n+command line, then numerix imports the specified array package.\n+\n+1. If the environment variable NUMERIX exists, it's value is used to\n+choose Numeric or numarray.\n+\n+2. The value of numerix in ~/.matplotlibrc: either Numeric or numarray\n+\n+\n+3. If none of the above is done, the default array package is Numeric.\n+Because the .matplotlibrc always provides *some* value for numerix (it\n+has it's own system of default values), this default is most likely\n+never used.\n+\n+To summarize: the commandline is examined first, the rc file second,\n+and the default array package is Numeric. \n+\"\"\"\n+\n+import sys, os\n+# from matplotlib import rcParams, verbose\n+\n+which = None, None\n+\n+# First, see if --numarray or --Numeric was specified on the command\n+# line:\n+if hasattr(sys, 'argv'): #Once again, Apache mod_python has no argv\n+ for a in sys.argv:\n+ if a in [\"--Numeric\", \"--numeric\", \"--NUMERIC\",\n+ \"--Numarray\", \"--numarray\", \"--NUMARRAY\"]:\n+ which = a[2:], \"command line\"\n+ break\n+ del a\n+\n+if os.getenv(\"NUMERIX\"):\n+ which = os.getenv(\"NUMERIX\"), \"environment var\"\n+\n+# if which[0] is None: \n+# try: # In theory, rcParams always has *some* value for numerix.\n+# which = rcParams['numerix'], \"rc\"\n+# except KeyError:\n+# pass\n+\n+# If all the above fail, default to Numeric.\n+if which[0] is None:\n+ which = \"numeric\", \"defaulted\"\n+\n+which = which[0].strip().lower(), which[1]\n+if which[0] not in [\"numeric\", \"numarray\"]:\n+ verbose.report_error(__doc__)\n+ raise ValueError(\"numerix selector must be either 'Numeric' or 'numarray' but the value obtained from the %s was '%s'.\" % (which[1], which[0]))\n+\n+if which[0] == \"numarray\":\n+ from _na_imports import *\n+ import numarray\n+ version = 'numarray %s'%numarray.__version__\n+\n+elif which[0] == \"numeric\":\n+ from _nc_imports import *\n+ import Numeric\n+ version = 'Numeric %s'%Numeric.__version__\n+else:\n+ raise RuntimeError(\"invalid numerix selector\")\n+\n+print 'numerix %s'%version\n+\n+# ---------------------------------------------------------------\n+# Common imports and fixes\n+# ---------------------------------------------------------------\n+\n+# a bug fix for blas numeric suggested by Fernando Perez\n+matrixmultiply=dot\n+\n+from function_base import any, all\n+\n+def _import_fail_message(module, version):\n+ \"\"\"Prints a message when the array package specific version of an extension\n+ fails to import correctly.\n+ \"\"\"\n+ _dict = { \"which\" : which[0],\n+ \"module\" : module,\n+ \"specific\" : version + module\n+ }\n+ print \"\"\"\\nThe import of the %(which)s version of the %(module)s module, %(specific)s, failed.\\nThis is either because %(which)s was unavailable when scipy was compiled,\\nor because a dependency of %(specific)s could not be satisfied.\\nIf it appears that %(specific)s was not built, make sure you have a working copy of\\n%(which)s and then re-install scipy. Otherwise, the following traceback gives more details:\\n\"\"\" % _dict\n", "added_lines": 85, "deleted_lines": 0, "source_code": "\"\"\"numerix imports either Numeric or numarray based on various selectors.\n\n0. If the value \"--numarray\" or \"--Numeric\" is specified on the\ncommand line, then numerix imports the specified array package.\n\n1. If the environment variable NUMERIX exists, it's value is used to\nchoose Numeric or numarray.\n\n2. The value of numerix in ~/.matplotlibrc: either Numeric or numarray\n\n\n3. If none of the above is done, the default array package is Numeric.\nBecause the .matplotlibrc always provides *some* value for numerix (it\nhas it's own system of default values), this default is most likely\nnever used.\n\nTo summarize: the commandline is examined first, the rc file second,\nand the default array package is Numeric. \n\"\"\"\n\nimport sys, os\n# from matplotlib import rcParams, verbose\n\nwhich = None, None\n\n# First, see if --numarray or --Numeric was specified on the command\n# line:\nif hasattr(sys, 'argv'): #Once again, Apache mod_python has no argv\n for a in sys.argv:\n if a in [\"--Numeric\", \"--numeric\", \"--NUMERIC\",\n \"--Numarray\", \"--numarray\", \"--NUMARRAY\"]:\n which = a[2:], \"command line\"\n break\n del a\n\nif os.getenv(\"NUMERIX\"):\n which = os.getenv(\"NUMERIX\"), \"environment var\"\n\n# if which[0] is None: \n# try: # In theory, rcParams always has *some* value for numerix.\n# which = rcParams['numerix'], \"rc\"\n# except KeyError:\n# pass\n\n# If all the above fail, default to Numeric.\nif which[0] is None:\n which = \"numeric\", \"defaulted\"\n\nwhich = which[0].strip().lower(), which[1]\nif which[0] not in [\"numeric\", \"numarray\"]:\n verbose.report_error(__doc__)\n raise ValueError(\"numerix selector must be either 'Numeric' or 'numarray' but the value obtained from the %s was '%s'.\" % (which[1], which[0]))\n\nif which[0] == \"numarray\":\n from _na_imports import *\n import numarray\n version = 'numarray %s'%numarray.__version__\n\nelif which[0] == \"numeric\":\n from _nc_imports import *\n import Numeric\n version = 'Numeric %s'%Numeric.__version__\nelse:\n raise RuntimeError(\"invalid numerix selector\")\n\nprint 'numerix %s'%version\n\n# ---------------------------------------------------------------\n# Common imports and fixes\n# ---------------------------------------------------------------\n\n# a bug fix for blas numeric suggested by Fernando Perez\nmatrixmultiply=dot\n\nfrom function_base import any, all\n\ndef _import_fail_message(module, version):\n \"\"\"Prints a message when the array package specific version of an extension\n fails to import correctly.\n \"\"\"\n _dict = { \"which\" : which[0],\n \"module\" : module,\n \"specific\" : version + module\n }\n print \"\"\"\\nThe import of the %(which)s version of the %(module)s module, %(specific)s, failed.\\nThis is either because %(which)s was unavailable when scipy was compiled,\\nor because a dependency of %(specific)s could not be satisfied.\\nIf it appears that %(specific)s was not built, make sure you have a working copy of\\n%(which)s and then re-install scipy. Otherwise, the following traceback gives more details:\\n\"\"\" % _dict\n", "source_code_before": null, "methods": [ { "name": "_import_fail_message", "long_name": "_import_fail_message( module , version )", "filename": "numerix.py", "nloc": 6, "complexity": 1, "token_count": 32, "parameters": [ "module", "version" ], "start_line": 77, "end_line": 85, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 9, "top_nesting_level": 0 } ], "methods_before": [], "changed_methods": [ { "name": "_import_fail_message", "long_name": "_import_fail_message( module , version )", "filename": "numerix.py", "nloc": 6, "complexity": 1, "token_count": 32, "parameters": [ "module", "version" ], "start_line": 77, "end_line": 85, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 9, "top_nesting_level": 0 } ], "nloc": 55, "complexity": 1, "token_count": 235, "diff_parsed": { "added": [ "\"\"\"numerix imports either Numeric or numarray based on various selectors.", "", "0. If the value \"--numarray\" or \"--Numeric\" is specified on the", "command line, then numerix imports the specified array package.", "", "1. If the environment variable NUMERIX exists, it's value is used to", "choose Numeric or numarray.", "", "2. The value of numerix in ~/.matplotlibrc: either Numeric or numarray", "", "", "3. If none of the above is done, the default array package is Numeric.", "Because the .matplotlibrc always provides *some* value for numerix (it", "has it's own system of default values), this default is most likely", "never used.", "", "To summarize: the commandline is examined first, the rc file second,", "and the default array package is Numeric.", "\"\"\"", "", "import sys, os", "# from matplotlib import rcParams, verbose", "", "which = None, None", "", "# First, see if --numarray or --Numeric was specified on the command", "# line:", "if hasattr(sys, 'argv'): #Once again, Apache mod_python has no argv", " for a in sys.argv:", " if a in [\"--Numeric\", \"--numeric\", \"--NUMERIC\",", " \"--Numarray\", \"--numarray\", \"--NUMARRAY\"]:", " which = a[2:], \"command line\"", " break", " del a", "", "if os.getenv(\"NUMERIX\"):", " which = os.getenv(\"NUMERIX\"), \"environment var\"", "", "# if which[0] is None:", "# try: # In theory, rcParams always has *some* value for numerix.", "# which = rcParams['numerix'], \"rc\"", "# except KeyError:", "# pass", "", "# If all the above fail, default to Numeric.", "if which[0] is None:", " which = \"numeric\", \"defaulted\"", "", "which = which[0].strip().lower(), which[1]", "if which[0] not in [\"numeric\", \"numarray\"]:", " verbose.report_error(__doc__)", " raise ValueError(\"numerix selector must be either 'Numeric' or 'numarray' but the value obtained from the %s was '%s'.\" % (which[1], which[0]))", "", "if which[0] == \"numarray\":", " from _na_imports import *", " import numarray", " version = 'numarray %s'%numarray.__version__", "", "elif which[0] == \"numeric\":", " from _nc_imports import *", " import Numeric", " version = 'Numeric %s'%Numeric.__version__", "else:", " raise RuntimeError(\"invalid numerix selector\")", "", "print 'numerix %s'%version", "", "# ---------------------------------------------------------------", "# Common imports and fixes", "# ---------------------------------------------------------------", "", "# a bug fix for blas numeric suggested by Fernando Perez", "matrixmultiply=dot", "", "from function_base import any, all", "", "def _import_fail_message(module, version):", " \"\"\"Prints a message when the array package specific version of an extension", " fails to import correctly.", " \"\"\"", " _dict = { \"which\" : which[0],", " \"module\" : module,", " \"specific\" : version + module", " }", " print \"\"\"\\nThe import of the %(which)s version of the %(module)s module, %(specific)s, failed.\\nThis is either because %(which)s was unavailable when scipy was compiled,\\nor because a dependency of %(specific)s could not be satisfied.\\nIf it appears that %(specific)s was not built, make sure you have a working copy of\\n%(which)s and then re-install scipy. Otherwise, the following traceback gives more details:\\n\"\"\" % _dict" ], "deleted": [] } }, { "old_path": "scipy_base/polynomial.py", "new_path": "scipy_base/polynomial.py", "filename": "polynomial.py", "extension": "py", "change_type": "MODIFY", "diff": "@@ -1,5 +1,5 @@\n-import Numeric\n-from Numeric import *\n+import numerix as _nx\n+from numerix import *\n from scimath import *\n \n from type_check import isscalar, asarray\n@@ -55,7 +55,6 @@ def poly(seq_of_zeros):\n a = [1]\n for k in range(len(seq_of_zeros)):\n a = convolve(a,[1, -seq_of_zeros[k]], mode=2)\n-\n \n if a.typecode() in ['F','D']:\n # if complex roots are all complex conjugates, the roots are real.\n@@ -119,10 +118,10 @@ def polyint(p,m=1,k=None):\n if m < 0:\n raise ValueError, \"Order of integral must be positive (see polyder)\"\n if k is None:\n- k = Numeric.zeros(m)\n+ k = _nx.zeros(m)\n k = atleast_1d(k)\n if len(k) == 1 and m > 1:\n- k = k[0]*Numeric.ones(m)\n+ k = k[0]*_nx.ones(m)\n if len(k) < m:\n raise ValueError, \\\n \"k must be a scalar or a rank-1 array of length 1 or >m.\"\n@@ -131,8 +130,8 @@ def polyint(p,m=1,k=None):\n else:\n truepoly = isinstance(p,poly1d)\n p = asarray(p)\n- y = Numeric.zeros(len(p)+1,'d')\n- y[:-1] = p*1.0/Numeric.arange(len(p),0,-1)\n+ y = _nx.zeros(len(p)+1,'d')\n+ y[:-1] = p*1.0/_nx.arange(len(p),0,-1)\n y[-1] = k[0] \n val = polyint(y,m-1,k=k[1:])\n if truepoly:\n@@ -146,7 +145,7 @@ def polyder(p,m=1):\n truepoly = isinstance(p,poly1d)\n p = asarray(p)\n n = len(p)-1\n- y = p[:-1] * Numeric.arange(n,0,-1)\n+ y = p[:-1] * _nx.arange(n,0,-1)\n if m < 0:\n raise ValueError, \"Order of derivative must be positive (see polyint)\"\n if m == 0:\n@@ -174,7 +173,7 @@ def polyval(p,x):\n y = 0\n else:\n x = asarray(x)\n- y = Numeric.zeros(x.shape,x.typecode())\n+ y = _nx.zeros(x.shape,x.typecode())\n for i in range(len(p)):\n y = x * y + p[i]\n return y\n@@ -188,11 +187,11 @@ def polyadd(a1,a2):\n if diff == 0:\n return a1 + a2\n elif diff > 0:\n- zr = Numeric.zeros(diff)\n- val = Numeric.concatenate((zr,a1)) + a2\n+ zr = _nx.zeros(diff)\n+ val = _nx.concatenate((zr,a1)) + a2\n else:\n- zr = Numeric.zeros(abs(diff))\n- val = a1 + Numeric.concatenate((zr,a2))\n+ zr = _nx.zeros(abs(diff))\n+ val = a1 + _nx.concatenate((zr,a2))\n if truepoly:\n val = poly1d(val)\n return val\n@@ -206,11 +205,11 @@ def polysub(a1,a2):\n if diff == 0:\n return a1 - a2\n elif diff > 0:\n- zr = Numeric.zeros(diff)\n- val = Numeric.concatenate((zr,a1)) - a2\n+ zr = _nx.zeros(diff)\n+ val = _nx.concatenate((zr,a1)) - a2\n else:\n- zr = Numeric.zeros(abs(diff))\n- val = a1 - Numeric.concatenate((zr,a2))\n+ zr = _nx.zeros(abs(diff))\n+ val = a1 - _nx.concatenate((zr,a2))\n if truepoly:\n val = poly1d(val)\n return val\n@@ -220,7 +219,7 @@ def polymul(a1,a2):\n \"\"\"Multiplies two polynomials represented as lists.\n \"\"\"\n truepoly = (isinstance(a1,poly1d) or isinstance(a2,poly1d))\n- val = Numeric.convolve(a1,a2)\n+ val = _nx.convolve(a1,a2)\n if truepoly:\n val = poly1d(val)\n return val\n@@ -230,7 +229,7 @@ def polydiv(a1,a2):\n \"\"\"\n truepoly = (isinstance(a1,poly1d) or isinstance(a2,poly1d))\n q, r = deconvolve(a1,a2)\n- while Numeric.allclose(r[0], 0, rtol=1e-14) and (r.shape[-1] > 1):\n+ while _nx.allclose(r[0], 0, rtol=1e-14) and (r.shape[-1] > 1):\n r = r[1:]\n if truepoly:\n q, r = map(poly1d,(q,r))\n@@ -251,10 +250,10 @@ def deconvolve(signal, divisor):\n quot = [];\n rem = num;\n else:\n- input = Numeric.ones(N-D+1,Numeric.Float)\n+ input = _nx.ones(N-D+1,_nx.Float)\n input[1:] = 0\n quot = scipy.signal.lfilter(num, den, input)\n- rem = num - Numeric.convolve(den,quot,mode=2)\n+ rem = num - _nx.convolve(den,quot,mode=2)\n return quot, rem\n \n import re\n@@ -315,7 +314,7 @@ def __init__(self, c_or_r, r=0):\n raise ValueError, \"Polynomial must be 1d only.\"\n c_or_r = trim_zeros(c_or_r, trim='f')\n if len(c_or_r) == 0:\n- c_or_r = Numeric.array([0])\n+ c_or_r = _nx.array([0])\n self.__dict__['coeffs'] = c_or_r\n self.__dict__['order'] = len(c_or_r) - 1\n \n@@ -461,8 +460,8 @@ def __setitem__(self, key, val):\n if key < 0:\n raise ValueError, \"Does not support negative powers.\"\n if key > self.order:\n- zr = Numeric.zeros(key-self.order,self.coeffs.typecode())\n- self.__dict__['coeffs'] = Numeric.concatenate((zr,self.coeffs))\n+ zr = _nx.zeros(key-self.order,self.coeffs.typecode())\n+ self.__dict__['coeffs'] = _nx.concatenate((zr,self.coeffs))\n self.__dict__['order'] = key\n ind = 0\n self.__dict__['coeffs'][ind] = val\n", "added_lines": 23, "deleted_lines": 24, "source_code": "import numerix as _nx\nfrom numerix import *\nfrom scimath import *\n\nfrom type_check import isscalar, asarray\nfrom matrix_base import diag\nfrom shape_base import hstack, atleast_1d\nfrom function_base import trim_zeros, sort_complex\n\n__all__ = ['poly','roots','polyint','polyder','polyadd','polysub','polymul',\n 'polydiv','polyval','poly1d']\n \ndef get_eigval_func():\n try:\n import scipy.linalg\n eigvals = scipy.linalg.eigvals\n except ImportError:\n try:\n import linalg\n eigvals = linalg.eigvals\n except ImportError:\n try:\n import LinearAlgebra\n eigvals = LinearAlgebra.eigenvalues\n except:\n raise ImportError, \\\n \"You must have scipy.linalg or LinearAlgebra to \"\\\n \"use this function.\"\n return eigvals\n\ndef poly(seq_of_zeros):\n \"\"\" Return a sequence representing a polynomial given a sequence of roots.\n\n If the input is a matrix, return the characteristic polynomial.\n \n Example:\n \n >>> b = roots([1,3,1,5,6])\n >>> poly(b)\n array([1., 3., 1., 5., 6.])\n \"\"\"\n seq_of_zeros = atleast_1d(seq_of_zeros) \n sh = shape(seq_of_zeros)\n if len(sh) == 2 and sh[0] == sh[1]:\n eig = get_eigval_func()\n seq_of_zeros=eig(seq_of_zeros)\n elif len(sh) ==1:\n pass\n else:\n raise ValueError, \"input must be 1d or square 2d array.\"\n\n if len(seq_of_zeros) == 0:\n return 1.0\n\n a = [1]\n for k in range(len(seq_of_zeros)):\n a = convolve(a,[1, -seq_of_zeros[k]], mode=2)\n \n if a.typecode() in ['F','D']:\n # if complex roots are all complex conjugates, the roots are real.\n roots = asarray(seq_of_zeros,'D')\n pos_roots = sort_complex(compress(roots.imag > 0,roots))\n neg_roots = conjugate(sort_complex(compress(roots.imag < 0,roots)))\n if (len(pos_roots) == len(neg_roots) and\n alltrue(neg_roots == pos_roots)):\n a = a.real.copy()\n\n return a\n\ndef roots(p):\n \"\"\" Return the roots of the polynomial coefficients in p.\n\n The values in the rank-1 array p are coefficients of a polynomial.\n If the length of p is n+1 then the polynomial is\n p[0] * x**n + p[1] * x**(n-1) + ... + p[n-1]*x + p[n]\n \"\"\"\n # If input is scalar, this makes it an array\n eig = get_eigval_func()\n p = atleast_1d(p)\n if len(p.shape) != 1:\n raise ValueError,\"Input must be a rank-1 array.\"\n \n # find non-zero array entries\n non_zero = nonzero(ravel(p))\n\n # find the number of trailing zeros -- this is the number of roots at 0.\n trailing_zeros = len(p) - non_zero[-1] - 1\n\n # strip leading and trailing zeros\n p = p[int(non_zero[0]):int(non_zero[-1])+1]\n \n # casting: if incoming array isn't floating point, make it floating point.\n if p.typecode() not in ['f','d','F','D']:\n p = p.astype('d')\n\n N = len(p)\n if N > 1:\n # build companion matrix and find its eigenvalues (the roots)\n A = diag(ones((N-2,),p.typecode()),-1)\n A[0,:] = -p[1:] / p[0]\n roots = eig(A)\n else:\n return array([])\n\n # tack any zeros onto the back of the array \n roots = hstack((roots,zeros(trailing_zeros,roots.typecode())))\n return roots\n\ndef polyint(p,m=1,k=None):\n \"\"\"Return the mth analytical integral of the polynomial p.\n\n If k is None, then zero-valued constants of integration are used.\n otherwise, k should be a list of length m (or a scalar if m=1) to\n represent the constants of integration to use for each integration\n (starting with k[0])\n \"\"\"\n m = int(m)\n if m < 0:\n raise ValueError, \"Order of integral must be positive (see polyder)\"\n if k is None:\n k = _nx.zeros(m)\n k = atleast_1d(k)\n if len(k) == 1 and m > 1:\n k = k[0]*_nx.ones(m)\n if len(k) < m:\n raise ValueError, \\\n \"k must be a scalar or a rank-1 array of length 1 or >m.\"\n if m == 0:\n return p\n else:\n truepoly = isinstance(p,poly1d)\n p = asarray(p)\n y = _nx.zeros(len(p)+1,'d')\n y[:-1] = p*1.0/_nx.arange(len(p),0,-1)\n y[-1] = k[0] \n val = polyint(y,m-1,k=k[1:])\n if truepoly:\n val = poly1d(val)\n return val\n \ndef polyder(p,m=1):\n \"\"\"Return the mth derivative of the polynomial p.\n \"\"\"\n m = int(m)\n truepoly = isinstance(p,poly1d)\n p = asarray(p)\n n = len(p)-1\n y = p[:-1] * _nx.arange(n,0,-1)\n if m < 0:\n raise ValueError, \"Order of derivative must be positive (see polyint)\"\n if m == 0:\n return p\n else:\n val = polyder(y,m-1)\n if truepoly:\n val = poly1d(val)\n return val\n\ndef polyval(p,x):\n \"\"\"Evaluate the polynomial p at x. If x is a polynomial then composition.\n\n Description:\n\n If p is of length N, this function returns the value:\n p[0]*(x**N-1) + p[1]*(x**N-2) + ... + p[N-2]*x + p[N-1]\n\n x can be a sequence and p(x) will be returned for all elements of x.\n or x can be another polynomial and the composite polynomial p(x) will be\n returned.\n \"\"\"\n p = asarray(p)\n if isinstance(x,poly1d):\n y = 0\n else:\n x = asarray(x)\n y = _nx.zeros(x.shape,x.typecode())\n for i in range(len(p)):\n y = x * y + p[i]\n return y\n\ndef polyadd(a1,a2):\n \"\"\"Adds two polynomials represented as lists\n \"\"\"\n truepoly = (isinstance(a1,poly1d) or isinstance(a2,poly1d))\n a1,a2 = map(atleast_1d,(a1,a2))\n diff = len(a2) - len(a1)\n if diff == 0:\n return a1 + a2\n elif diff > 0:\n zr = _nx.zeros(diff)\n val = _nx.concatenate((zr,a1)) + a2\n else:\n zr = _nx.zeros(abs(diff))\n val = a1 + _nx.concatenate((zr,a2))\n if truepoly:\n val = poly1d(val)\n return val\n\ndef polysub(a1,a2):\n \"\"\"Subtracts two polynomials represented as lists\n \"\"\"\n truepoly = (isinstance(a1,poly1d) or isinstance(a2,poly1d))\n a1,a2 = map(atleast_1d,(a1,a2))\n diff = len(a2) - len(a1)\n if diff == 0:\n return a1 - a2\n elif diff > 0:\n zr = _nx.zeros(diff)\n val = _nx.concatenate((zr,a1)) - a2\n else:\n zr = _nx.zeros(abs(diff))\n val = a1 - _nx.concatenate((zr,a2))\n if truepoly:\n val = poly1d(val)\n return val\n\n\ndef polymul(a1,a2):\n \"\"\"Multiplies two polynomials represented as lists.\n \"\"\"\n truepoly = (isinstance(a1,poly1d) or isinstance(a2,poly1d))\n val = _nx.convolve(a1,a2)\n if truepoly:\n val = poly1d(val)\n return val\n\ndef polydiv(a1,a2):\n \"\"\"Computes q and r polynomials so that a1(s) = q(s)*a2(s) + r(s)\n \"\"\"\n truepoly = (isinstance(a1,poly1d) or isinstance(a2,poly1d))\n q, r = deconvolve(a1,a2)\n while _nx.allclose(r[0], 0, rtol=1e-14) and (r.shape[-1] > 1):\n r = r[1:]\n if truepoly:\n q, r = map(poly1d,(q,r))\n return q, r\n\ndef deconvolve(signal, divisor):\n \"\"\"Deconvolves divisor out of signal.\n \"\"\"\n try:\n import scipy.signal\n except:\n print \"You need scipy.signal to use this function.\"\n num = atleast_1d(signal)\n den = atleast_1d(divisor)\n N = len(num)\n D = len(den)\n if D > N:\n quot = [];\n rem = num;\n else:\n input = _nx.ones(N-D+1,_nx.Float)\n input[1:] = 0\n quot = scipy.signal.lfilter(num, den, input)\n rem = num - _nx.convolve(den,quot,mode=2)\n return quot, rem\n\nimport re\n_poly_mat = re.compile(r\"[*][*]([0-9]*)\")\ndef _raise_power(astr, wrap=70):\n n = 0\n line1 = ''\n line2 = ''\n output = ' '\n while 1:\n mat = _poly_mat.search(astr,n)\n if mat is None:\n break\n span = mat.span()\n power = mat.groups()[0]\n partstr = astr[n:span[0]]\n n = span[1]\n toadd2 = partstr + ' '*(len(power)-1)\n toadd1 = ' '*(len(partstr)-1) + power\n if ((len(line2)+len(toadd2) > wrap) or \\\n (len(line1)+len(toadd1) > wrap)):\n output += line1 + \"\\n\" + line2 + \"\\n \"\n line1 = toadd1\n line2 = toadd2\n else: \n line2 += partstr + ' '*(len(power)-1)\n line1 += ' '*(len(partstr)-1) + power\n output += line1 + \"\\n\" + line2\n return output + astr[n:]\n \n \nclass poly1d:\n \"\"\"A one-dimensional polynomial class.\n\n p = poly1d([1,2,3]) constructs the polynomial x**2 + 2 x + 3\n\n p(0.5) evaluates the polynomial at the location\n p.r is a list of roots\n p.c is the coefficient array [1,2,3]\n p.order is the polynomial order (after leading zeros in p.c are removed)\n p[k] is the coefficient on the kth power of x (backwards from\n sequencing the coefficient array.\n\n polynomials can be added, substracted, multplied and divided (returns\n quotient and remainder).\n asarray(p) will also give the coefficient array, so polynomials can\n be used in all functions that accept arrays.\n \"\"\"\n def __init__(self, c_or_r, r=0):\n if isinstance(c_or_r,poly1d):\n for key in c_or_r.__dict__.keys():\n self.__dict__[key] = c_or_r.__dict__[key]\n return\n if r:\n c_or_r = poly(c_or_r)\n c_or_r = atleast_1d(c_or_r)\n if len(c_or_r.shape) > 1:\n raise ValueError, \"Polynomial must be 1d only.\"\n c_or_r = trim_zeros(c_or_r, trim='f')\n if len(c_or_r) == 0:\n c_or_r = _nx.array([0])\n self.__dict__['coeffs'] = c_or_r\n self.__dict__['order'] = len(c_or_r) - 1\n\n def __array__(self,t=None):\n if t:\n return asarray(self.coeffs,t)\n else:\n return asarray(self.coeffs)\n\n def __coerce__(self,other):\n return None\n \n def __repr__(self):\n vals = repr(self.coeffs)\n vals = vals[6:-1]\n return \"poly1d(%s)\" % vals\n\n def __len__(self):\n return self.order\n\n def __str__(self):\n N = self.order\n thestr = \"0\"\n for k in range(len(self.coeffs)):\n coefstr ='%.4g' % abs(self.coeffs[k])\n if coefstr[-4:] == '0000':\n coefstr = coefstr[:-5]\n power = (N-k)\n if power == 0:\n if coefstr != '0':\n newstr = '%s' % (coefstr,)\n else:\n if k == 0:\n newstr = '0'\n else:\n newstr = ''\n elif power == 1:\n if coefstr == '0':\n newstr = ''\n elif coefstr == '1':\n newstr = 'x'\n else: \n newstr = '%s x' % (coefstr,)\n else:\n if coefstr == '0':\n newstr = ''\n elif coefstr == '1':\n newstr = 'x**%d' % (power,)\n else: \n newstr = '%s x**%d' % (coefstr, power)\n\n if k > 0:\n if newstr != '':\n if self.coeffs[k] < 0:\n thestr = \"%s - %s\" % (thestr, newstr)\n else:\n thestr = \"%s + %s\" % (thestr, newstr)\n elif (k == 0) and (newstr != '') and (self.coeffs[k] < 0):\n thestr = \"-%s\" % (newstr,)\n else:\n thestr = newstr\n return _raise_power(thestr)\n \n\n def __call__(self, val):\n return polyval(self.coeffs, val)\n\n def __mul__(self, other):\n if isscalar(other):\n return poly1d(self.coeffs * other)\n else:\n other = poly1d(other)\n return poly1d(polymul(self.coeffs, other.coeffs))\n\n def __rmul__(self, other):\n if isscalar(other):\n return poly1d(other * self.coeffs)\n else:\n other = poly1d(other)\n return poly1d(polymul(self.coeffs, other.coeffs)) \n \n def __add__(self, other):\n other = poly1d(other)\n return poly1d(polyadd(self.coeffs, other.coeffs)) \n \n def __radd__(self, other):\n other = poly1d(other)\n return poly1d(polyadd(self.coeffs, other.coeffs))\n\n def __pow__(self, val):\n if not isscalar(val) or int(val) != val or val < 0:\n raise ValueError, \"Power to non-negative integers only.\"\n res = [1]\n for k in range(val):\n res = polymul(self.coeffs, res)\n return poly1d(res)\n\n def __sub__(self, other):\n other = poly1d(other)\n return poly1d(polysub(self.coeffs, other.coeffs))\n\n def __rsub__(self, other):\n other = poly1d(other)\n return poly1d(polysub(other.coeffs, self.coeffs))\n\n def __div__(self, other):\n if isscalar(other):\n return poly1d(self.coeffs/other)\n else:\n other = poly1d(other)\n return map(poly1d,polydiv(self.coeffs, other.coeffs))\n\n def __rdiv__(self, other):\n if isscalar(other):\n return poly1d(other/self.coeffs)\n else:\n other = poly1d(other)\n return map(poly1d,polydiv(other.coeffs, self.coeffs))\n\n def __setattr__(self, key, val):\n raise ValueError, \"Attributes cannot be changed this way.\"\n\n def __getattr__(self, key):\n if key in ['r','roots']:\n return roots(self.coeffs)\n elif key in ['c','coef','coefficients']:\n return self.coeffs\n elif key in ['o']:\n return self.order\n else:\n return self.__dict__[key]\n \n def __getitem__(self, val):\n ind = self.order - val\n if val > self.order:\n return 0\n if val < 0:\n return 0\n return self.coeffs[ind]\n\n def __setitem__(self, key, val):\n ind = self.order - key\n if key < 0:\n raise ValueError, \"Does not support negative powers.\"\n if key > self.order:\n zr = _nx.zeros(key-self.order,self.coeffs.typecode())\n self.__dict__['coeffs'] = _nx.concatenate((zr,self.coeffs))\n self.__dict__['order'] = key\n ind = 0\n self.__dict__['coeffs'][ind] = val\n return\n\n def integ(self, m=1, k=0):\n return poly1d(polyint(self.coeffs,m=m,k=k))\n\n def deriv(self, m=1):\n return poly1d(polyder(self.coeffs,m=m))\n", "source_code_before": "import Numeric\nfrom Numeric import *\nfrom scimath import *\n\nfrom type_check import isscalar, asarray\nfrom matrix_base import diag\nfrom shape_base import hstack, atleast_1d\nfrom function_base import trim_zeros, sort_complex\n\n__all__ = ['poly','roots','polyint','polyder','polyadd','polysub','polymul',\n 'polydiv','polyval','poly1d']\n \ndef get_eigval_func():\n try:\n import scipy.linalg\n eigvals = scipy.linalg.eigvals\n except ImportError:\n try:\n import linalg\n eigvals = linalg.eigvals\n except ImportError:\n try:\n import LinearAlgebra\n eigvals = LinearAlgebra.eigenvalues\n except:\n raise ImportError, \\\n \"You must have scipy.linalg or LinearAlgebra to \"\\\n \"use this function.\"\n return eigvals\n\ndef poly(seq_of_zeros):\n \"\"\" Return a sequence representing a polynomial given a sequence of roots.\n\n If the input is a matrix, return the characteristic polynomial.\n \n Example:\n \n >>> b = roots([1,3,1,5,6])\n >>> poly(b)\n array([1., 3., 1., 5., 6.])\n \"\"\"\n seq_of_zeros = atleast_1d(seq_of_zeros) \n sh = shape(seq_of_zeros)\n if len(sh) == 2 and sh[0] == sh[1]:\n eig = get_eigval_func()\n seq_of_zeros=eig(seq_of_zeros)\n elif len(sh) ==1:\n pass\n else:\n raise ValueError, \"input must be 1d or square 2d array.\"\n\n if len(seq_of_zeros) == 0:\n return 1.0\n\n a = [1]\n for k in range(len(seq_of_zeros)):\n a = convolve(a,[1, -seq_of_zeros[k]], mode=2)\n\n \n if a.typecode() in ['F','D']:\n # if complex roots are all complex conjugates, the roots are real.\n roots = asarray(seq_of_zeros,'D')\n pos_roots = sort_complex(compress(roots.imag > 0,roots))\n neg_roots = conjugate(sort_complex(compress(roots.imag < 0,roots)))\n if (len(pos_roots) == len(neg_roots) and\n alltrue(neg_roots == pos_roots)):\n a = a.real.copy()\n\n return a\n\ndef roots(p):\n \"\"\" Return the roots of the polynomial coefficients in p.\n\n The values in the rank-1 array p are coefficients of a polynomial.\n If the length of p is n+1 then the polynomial is\n p[0] * x**n + p[1] * x**(n-1) + ... + p[n-1]*x + p[n]\n \"\"\"\n # If input is scalar, this makes it an array\n eig = get_eigval_func()\n p = atleast_1d(p)\n if len(p.shape) != 1:\n raise ValueError,\"Input must be a rank-1 array.\"\n \n # find non-zero array entries\n non_zero = nonzero(ravel(p))\n\n # find the number of trailing zeros -- this is the number of roots at 0.\n trailing_zeros = len(p) - non_zero[-1] - 1\n\n # strip leading and trailing zeros\n p = p[int(non_zero[0]):int(non_zero[-1])+1]\n \n # casting: if incoming array isn't floating point, make it floating point.\n if p.typecode() not in ['f','d','F','D']:\n p = p.astype('d')\n\n N = len(p)\n if N > 1:\n # build companion matrix and find its eigenvalues (the roots)\n A = diag(ones((N-2,),p.typecode()),-1)\n A[0,:] = -p[1:] / p[0]\n roots = eig(A)\n else:\n return array([])\n\n # tack any zeros onto the back of the array \n roots = hstack((roots,zeros(trailing_zeros,roots.typecode())))\n return roots\n\ndef polyint(p,m=1,k=None):\n \"\"\"Return the mth analytical integral of the polynomial p.\n\n If k is None, then zero-valued constants of integration are used.\n otherwise, k should be a list of length m (or a scalar if m=1) to\n represent the constants of integration to use for each integration\n (starting with k[0])\n \"\"\"\n m = int(m)\n if m < 0:\n raise ValueError, \"Order of integral must be positive (see polyder)\"\n if k is None:\n k = Numeric.zeros(m)\n k = atleast_1d(k)\n if len(k) == 1 and m > 1:\n k = k[0]*Numeric.ones(m)\n if len(k) < m:\n raise ValueError, \\\n \"k must be a scalar or a rank-1 array of length 1 or >m.\"\n if m == 0:\n return p\n else:\n truepoly = isinstance(p,poly1d)\n p = asarray(p)\n y = Numeric.zeros(len(p)+1,'d')\n y[:-1] = p*1.0/Numeric.arange(len(p),0,-1)\n y[-1] = k[0] \n val = polyint(y,m-1,k=k[1:])\n if truepoly:\n val = poly1d(val)\n return val\n \ndef polyder(p,m=1):\n \"\"\"Return the mth derivative of the polynomial p.\n \"\"\"\n m = int(m)\n truepoly = isinstance(p,poly1d)\n p = asarray(p)\n n = len(p)-1\n y = p[:-1] * Numeric.arange(n,0,-1)\n if m < 0:\n raise ValueError, \"Order of derivative must be positive (see polyint)\"\n if m == 0:\n return p\n else:\n val = polyder(y,m-1)\n if truepoly:\n val = poly1d(val)\n return val\n\ndef polyval(p,x):\n \"\"\"Evaluate the polynomial p at x. If x is a polynomial then composition.\n\n Description:\n\n If p is of length N, this function returns the value:\n p[0]*(x**N-1) + p[1]*(x**N-2) + ... + p[N-2]*x + p[N-1]\n\n x can be a sequence and p(x) will be returned for all elements of x.\n or x can be another polynomial and the composite polynomial p(x) will be\n returned.\n \"\"\"\n p = asarray(p)\n if isinstance(x,poly1d):\n y = 0\n else:\n x = asarray(x)\n y = Numeric.zeros(x.shape,x.typecode())\n for i in range(len(p)):\n y = x * y + p[i]\n return y\n\ndef polyadd(a1,a2):\n \"\"\"Adds two polynomials represented as lists\n \"\"\"\n truepoly = (isinstance(a1,poly1d) or isinstance(a2,poly1d))\n a1,a2 = map(atleast_1d,(a1,a2))\n diff = len(a2) - len(a1)\n if diff == 0:\n return a1 + a2\n elif diff > 0:\n zr = Numeric.zeros(diff)\n val = Numeric.concatenate((zr,a1)) + a2\n else:\n zr = Numeric.zeros(abs(diff))\n val = a1 + Numeric.concatenate((zr,a2))\n if truepoly:\n val = poly1d(val)\n return val\n\ndef polysub(a1,a2):\n \"\"\"Subtracts two polynomials represented as lists\n \"\"\"\n truepoly = (isinstance(a1,poly1d) or isinstance(a2,poly1d))\n a1,a2 = map(atleast_1d,(a1,a2))\n diff = len(a2) - len(a1)\n if diff == 0:\n return a1 - a2\n elif diff > 0:\n zr = Numeric.zeros(diff)\n val = Numeric.concatenate((zr,a1)) - a2\n else:\n zr = Numeric.zeros(abs(diff))\n val = a1 - Numeric.concatenate((zr,a2))\n if truepoly:\n val = poly1d(val)\n return val\n\n\ndef polymul(a1,a2):\n \"\"\"Multiplies two polynomials represented as lists.\n \"\"\"\n truepoly = (isinstance(a1,poly1d) or isinstance(a2,poly1d))\n val = Numeric.convolve(a1,a2)\n if truepoly:\n val = poly1d(val)\n return val\n\ndef polydiv(a1,a2):\n \"\"\"Computes q and r polynomials so that a1(s) = q(s)*a2(s) + r(s)\n \"\"\"\n truepoly = (isinstance(a1,poly1d) or isinstance(a2,poly1d))\n q, r = deconvolve(a1,a2)\n while Numeric.allclose(r[0], 0, rtol=1e-14) and (r.shape[-1] > 1):\n r = r[1:]\n if truepoly:\n q, r = map(poly1d,(q,r))\n return q, r\n\ndef deconvolve(signal, divisor):\n \"\"\"Deconvolves divisor out of signal.\n \"\"\"\n try:\n import scipy.signal\n except:\n print \"You need scipy.signal to use this function.\"\n num = atleast_1d(signal)\n den = atleast_1d(divisor)\n N = len(num)\n D = len(den)\n if D > N:\n quot = [];\n rem = num;\n else:\n input = Numeric.ones(N-D+1,Numeric.Float)\n input[1:] = 0\n quot = scipy.signal.lfilter(num, den, input)\n rem = num - Numeric.convolve(den,quot,mode=2)\n return quot, rem\n\nimport re\n_poly_mat = re.compile(r\"[*][*]([0-9]*)\")\ndef _raise_power(astr, wrap=70):\n n = 0\n line1 = ''\n line2 = ''\n output = ' '\n while 1:\n mat = _poly_mat.search(astr,n)\n if mat is None:\n break\n span = mat.span()\n power = mat.groups()[0]\n partstr = astr[n:span[0]]\n n = span[1]\n toadd2 = partstr + ' '*(len(power)-1)\n toadd1 = ' '*(len(partstr)-1) + power\n if ((len(line2)+len(toadd2) > wrap) or \\\n (len(line1)+len(toadd1) > wrap)):\n output += line1 + \"\\n\" + line2 + \"\\n \"\n line1 = toadd1\n line2 = toadd2\n else: \n line2 += partstr + ' '*(len(power)-1)\n line1 += ' '*(len(partstr)-1) + power\n output += line1 + \"\\n\" + line2\n return output + astr[n:]\n \n \nclass poly1d:\n \"\"\"A one-dimensional polynomial class.\n\n p = poly1d([1,2,3]) constructs the polynomial x**2 + 2 x + 3\n\n p(0.5) evaluates the polynomial at the location\n p.r is a list of roots\n p.c is the coefficient array [1,2,3]\n p.order is the polynomial order (after leading zeros in p.c are removed)\n p[k] is the coefficient on the kth power of x (backwards from\n sequencing the coefficient array.\n\n polynomials can be added, substracted, multplied and divided (returns\n quotient and remainder).\n asarray(p) will also give the coefficient array, so polynomials can\n be used in all functions that accept arrays.\n \"\"\"\n def __init__(self, c_or_r, r=0):\n if isinstance(c_or_r,poly1d):\n for key in c_or_r.__dict__.keys():\n self.__dict__[key] = c_or_r.__dict__[key]\n return\n if r:\n c_or_r = poly(c_or_r)\n c_or_r = atleast_1d(c_or_r)\n if len(c_or_r.shape) > 1:\n raise ValueError, \"Polynomial must be 1d only.\"\n c_or_r = trim_zeros(c_or_r, trim='f')\n if len(c_or_r) == 0:\n c_or_r = Numeric.array([0])\n self.__dict__['coeffs'] = c_or_r\n self.__dict__['order'] = len(c_or_r) - 1\n\n def __array__(self,t=None):\n if t:\n return asarray(self.coeffs,t)\n else:\n return asarray(self.coeffs)\n\n def __coerce__(self,other):\n return None\n \n def __repr__(self):\n vals = repr(self.coeffs)\n vals = vals[6:-1]\n return \"poly1d(%s)\" % vals\n\n def __len__(self):\n return self.order\n\n def __str__(self):\n N = self.order\n thestr = \"0\"\n for k in range(len(self.coeffs)):\n coefstr ='%.4g' % abs(self.coeffs[k])\n if coefstr[-4:] == '0000':\n coefstr = coefstr[:-5]\n power = (N-k)\n if power == 0:\n if coefstr != '0':\n newstr = '%s' % (coefstr,)\n else:\n if k == 0:\n newstr = '0'\n else:\n newstr = ''\n elif power == 1:\n if coefstr == '0':\n newstr = ''\n elif coefstr == '1':\n newstr = 'x'\n else: \n newstr = '%s x' % (coefstr,)\n else:\n if coefstr == '0':\n newstr = ''\n elif coefstr == '1':\n newstr = 'x**%d' % (power,)\n else: \n newstr = '%s x**%d' % (coefstr, power)\n\n if k > 0:\n if newstr != '':\n if self.coeffs[k] < 0:\n thestr = \"%s - %s\" % (thestr, newstr)\n else:\n thestr = \"%s + %s\" % (thestr, newstr)\n elif (k == 0) and (newstr != '') and (self.coeffs[k] < 0):\n thestr = \"-%s\" % (newstr,)\n else:\n thestr = newstr\n return _raise_power(thestr)\n \n\n def __call__(self, val):\n return polyval(self.coeffs, val)\n\n def __mul__(self, other):\n if isscalar(other):\n return poly1d(self.coeffs * other)\n else:\n other = poly1d(other)\n return poly1d(polymul(self.coeffs, other.coeffs))\n\n def __rmul__(self, other):\n if isscalar(other):\n return poly1d(other * self.coeffs)\n else:\n other = poly1d(other)\n return poly1d(polymul(self.coeffs, other.coeffs)) \n \n def __add__(self, other):\n other = poly1d(other)\n return poly1d(polyadd(self.coeffs, other.coeffs)) \n \n def __radd__(self, other):\n other = poly1d(other)\n return poly1d(polyadd(self.coeffs, other.coeffs))\n\n def __pow__(self, val):\n if not isscalar(val) or int(val) != val or val < 0:\n raise ValueError, \"Power to non-negative integers only.\"\n res = [1]\n for k in range(val):\n res = polymul(self.coeffs, res)\n return poly1d(res)\n\n def __sub__(self, other):\n other = poly1d(other)\n return poly1d(polysub(self.coeffs, other.coeffs))\n\n def __rsub__(self, other):\n other = poly1d(other)\n return poly1d(polysub(other.coeffs, self.coeffs))\n\n def __div__(self, other):\n if isscalar(other):\n return poly1d(self.coeffs/other)\n else:\n other = poly1d(other)\n return map(poly1d,polydiv(self.coeffs, other.coeffs))\n\n def __rdiv__(self, other):\n if isscalar(other):\n return poly1d(other/self.coeffs)\n else:\n other = poly1d(other)\n return map(poly1d,polydiv(other.coeffs, self.coeffs))\n\n def __setattr__(self, key, val):\n raise ValueError, \"Attributes cannot be changed this way.\"\n\n def __getattr__(self, key):\n if key in ['r','roots']:\n return roots(self.coeffs)\n elif key in ['c','coef','coefficients']:\n return self.coeffs\n elif key in ['o']:\n return self.order\n else:\n return self.__dict__[key]\n \n def __getitem__(self, val):\n ind = self.order - val\n if val > self.order:\n return 0\n if val < 0:\n return 0\n return self.coeffs[ind]\n\n def __setitem__(self, key, val):\n ind = self.order - key\n if key < 0:\n raise ValueError, \"Does not support negative powers.\"\n if key > self.order:\n zr = Numeric.zeros(key-self.order,self.coeffs.typecode())\n self.__dict__['coeffs'] = Numeric.concatenate((zr,self.coeffs))\n self.__dict__['order'] = key\n ind = 0\n self.__dict__['coeffs'][ind] = val\n return\n\n def integ(self, m=1, k=0):\n return poly1d(polyint(self.coeffs,m=m,k=k))\n\n def deriv(self, m=1):\n return poly1d(polyder(self.coeffs,m=m))\n", "methods": [ { "name": "get_eigval_func", "long_name": "get_eigval_func( )", "filename": "polynomial.py", "nloc": 17, "complexity": 4, "token_count": 52, "parameters": [], "start_line": 13, "end_line": 29, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 17, "top_nesting_level": 0 }, { "name": "poly", "long_name": "poly( seq_of_zeros )", "filename": "polynomial.py", "nloc": 23, "complexity": 9, "token_count": 195, "parameters": [ "seq_of_zeros" ], "start_line": 31, "end_line": 68, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 38, "top_nesting_level": 0 }, { "name": "roots", "long_name": "roots( p )", "filename": "polynomial.py", "nloc": 19, "complexity": 4, "token_count": 190, "parameters": [ "p" ], "start_line": 70, "end_line": 107, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 38, "top_nesting_level": 0 }, { "name": "polyint", "long_name": "polyint( p , m = 1 , k = None )", "filename": "polynomial.py", "nloc": 24, "complexity": 8, "token_count": 190, "parameters": [ "p", "m", "k" ], "start_line": 109, "end_line": 139, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 31, "top_nesting_level": 0 }, { "name": "polyder", "long_name": "polyder( p , m = 1 )", "filename": "polynomial.py", "nloc": 15, "complexity": 4, "token_count": 97, "parameters": [ "p", "m" ], "start_line": 141, "end_line": 157, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 17, "top_nesting_level": 0 }, { "name": "polyval", "long_name": "polyval( p , x )", "filename": "polynomial.py", "nloc": 10, "complexity": 3, "token_count": 72, "parameters": [ "p", "x" ], "start_line": 159, "end_line": 179, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 21, "top_nesting_level": 0 }, { "name": "polyadd", "long_name": "polyadd( a1 , a2 )", "filename": "polynomial.py", "nloc": 15, "complexity": 5, "token_count": 124, "parameters": [ "a1", "a2" ], "start_line": 181, "end_line": 197, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 17, "top_nesting_level": 0 }, { "name": "polysub", "long_name": "polysub( a1 , a2 )", "filename": "polynomial.py", "nloc": 15, "complexity": 5, "token_count": 124, "parameters": [ "a1", "a2" ], "start_line": 199, "end_line": 215, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 17, "top_nesting_level": 0 }, { "name": "polymul", "long_name": "polymul( a1 , a2 )", "filename": "polynomial.py", "nloc": 6, "complexity": 3, "token_count": 46, "parameters": [ "a1", "a2" ], "start_line": 218, "end_line": 225, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 8, "top_nesting_level": 0 }, { "name": "polydiv", "long_name": "polydiv( a1 , a2 )", "filename": "polynomial.py", "nloc": 8, "complexity": 5, "token_count": 94, "parameters": [ "a1", "a2" ], "start_line": 227, "end_line": 236, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 10, "top_nesting_level": 0 }, { "name": "deconvolve", "long_name": "deconvolve( signal , divisor )", "filename": "polynomial.py", "nloc": 18, "complexity": 3, "token_count": 115, "parameters": [ "signal", "divisor" ], "start_line": 238, "end_line": 257, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 20, "top_nesting_level": 0 }, { "name": "_raise_power", "long_name": "_raise_power( astr , wrap = 70 )", "filename": "polynomial.py", "nloc": 25, "complexity": 5, "token_count": 194, "parameters": [ "astr", "wrap" ], "start_line": 261, "end_line": 285, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 25, "top_nesting_level": 0 }, { "name": "__init__", "long_name": "__init__( self , c_or_r , r = 0 )", "filename": "polynomial.py", "nloc": 15, "complexity": 6, "token_count": 122, "parameters": [ "self", "c_or_r", "r" ], "start_line": 305, "end_line": 319, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 15, "top_nesting_level": 1 }, { "name": "__array__", "long_name": "__array__( self , t = None )", "filename": "polynomial.py", "nloc": 5, "complexity": 2, "token_count": 30, "parameters": [ "self", "t" ], "start_line": 321, "end_line": 325, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 5, "top_nesting_level": 1 }, { "name": "__coerce__", "long_name": "__coerce__( self , other )", "filename": "polynomial.py", "nloc": 2, "complexity": 1, "token_count": 9, "parameters": [ "self", "other" ], "start_line": 327, "end_line": 328, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 2, "top_nesting_level": 1 }, { "name": "__repr__", "long_name": "__repr__( self )", "filename": "polynomial.py", "nloc": 4, "complexity": 1, "token_count": 26, "parameters": [ "self" ], "start_line": 330, "end_line": 333, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 4, "top_nesting_level": 1 }, { "name": "__len__", "long_name": "__len__( self )", "filename": "polynomial.py", "nloc": 2, "complexity": 1, "token_count": 9, "parameters": [ "self" ], "start_line": 335, "end_line": 336, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 2, "top_nesting_level": 1 }, { "name": "__str__", "long_name": "__str__( self )", "filename": "polynomial.py", "nloc": 41, "complexity": 17, "token_count": 244, "parameters": [ "self" ], "start_line": 338, "end_line": 379, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 42, "top_nesting_level": 1 }, { "name": "__call__", "long_name": "__call__( self , val )", "filename": "polynomial.py", "nloc": 2, "complexity": 1, "token_count": 16, "parameters": [ "self", "val" ], "start_line": 382, "end_line": 383, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 2, "top_nesting_level": 1 }, { "name": "__mul__", "long_name": "__mul__( self , other )", "filename": "polynomial.py", "nloc": 6, "complexity": 2, "token_count": 44, "parameters": [ "self", "other" ], "start_line": 385, "end_line": 390, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 6, "top_nesting_level": 1 }, { "name": "__rmul__", "long_name": "__rmul__( self , other )", "filename": "polynomial.py", "nloc": 6, "complexity": 2, "token_count": 44, "parameters": [ "self", "other" ], "start_line": 392, "end_line": 397, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 6, "top_nesting_level": 1 }, { "name": "__add__", "long_name": "__add__( self , other )", "filename": "polynomial.py", "nloc": 3, "complexity": 1, "token_count": 27, "parameters": [ "self", "other" ], "start_line": 399, "end_line": 401, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 3, "top_nesting_level": 1 }, { "name": "__radd__", "long_name": "__radd__( self , other )", "filename": "polynomial.py", "nloc": 3, "complexity": 1, "token_count": 27, "parameters": [ "self", "other" ], "start_line": 403, "end_line": 405, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 3, "top_nesting_level": 1 }, { "name": "__pow__", "long_name": "__pow__( self , val )", "filename": "polynomial.py", "nloc": 7, "complexity": 5, "token_count": 57, "parameters": [ "self", "val" ], "start_line": 407, "end_line": 413, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 7, "top_nesting_level": 1 }, { "name": "__sub__", "long_name": "__sub__( self , other )", "filename": "polynomial.py", "nloc": 3, "complexity": 1, "token_count": 27, "parameters": [ "self", "other" ], "start_line": 415, "end_line": 417, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 3, "top_nesting_level": 1 }, { "name": "__rsub__", "long_name": "__rsub__( self , other )", "filename": "polynomial.py", "nloc": 3, "complexity": 1, "token_count": 27, "parameters": [ "self", "other" ], "start_line": 419, "end_line": 421, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 3, "top_nesting_level": 1 }, { "name": "__div__", "long_name": "__div__( self , other )", "filename": "polynomial.py", "nloc": 6, "complexity": 2, "token_count": 46, "parameters": [ "self", "other" ], "start_line": 423, "end_line": 428, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 6, "top_nesting_level": 1 }, { "name": "__rdiv__", "long_name": "__rdiv__( self , other )", "filename": "polynomial.py", "nloc": 6, "complexity": 2, "token_count": 46, "parameters": [ "self", "other" ], "start_line": 430, "end_line": 435, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 6, "top_nesting_level": 1 }, { "name": "__setattr__", "long_name": "__setattr__( self , key , val )", "filename": "polynomial.py", "nloc": 2, "complexity": 1, "token_count": 13, "parameters": [ "self", "key", "val" ], "start_line": 437, "end_line": 438, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 2, "top_nesting_level": 1 }, { "name": "__getattr__", "long_name": "__getattr__( self , key )", "filename": "polynomial.py", "nloc": 9, "complexity": 4, "token_count": 58, "parameters": [ "self", "key" ], "start_line": 440, "end_line": 448, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 9, "top_nesting_level": 1 }, { "name": "__getitem__", "long_name": "__getitem__( self , val )", "filename": "polynomial.py", "nloc": 7, "complexity": 3, "token_count": 37, "parameters": [ "self", "val" ], "start_line": 450, "end_line": 456, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 7, "top_nesting_level": 1 }, { "name": "__setitem__", "long_name": "__setitem__( self , key , val )", "filename": "polynomial.py", "nloc": 11, "complexity": 3, "token_count": 94, "parameters": [ "self", "key", "val" ], "start_line": 458, "end_line": 468, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 11, "top_nesting_level": 1 }, { "name": "integ", "long_name": "integ( self , m = 1 , k = 0 )", "filename": "polynomial.py", "nloc": 2, "complexity": 1, "token_count": 31, "parameters": [ "self", "m", "k" ], "start_line": 470, "end_line": 471, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 2, "top_nesting_level": 1 }, { "name": "deriv", "long_name": "deriv( self , m = 1 )", "filename": "polynomial.py", "nloc": 2, "complexity": 1, "token_count": 23, "parameters": [ "self", "m" ], "start_line": 473, "end_line": 474, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 2, "top_nesting_level": 1 } ], "methods_before": [ { "name": "get_eigval_func", "long_name": "get_eigval_func( )", "filename": "polynomial.py", "nloc": 17, "complexity": 4, "token_count": 52, "parameters": [], "start_line": 13, "end_line": 29, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 17, "top_nesting_level": 0 }, { "name": "poly", "long_name": "poly( seq_of_zeros )", "filename": "polynomial.py", "nloc": 23, "complexity": 9, "token_count": 195, "parameters": [ "seq_of_zeros" ], "start_line": 31, "end_line": 69, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 39, "top_nesting_level": 0 }, { "name": "roots", "long_name": "roots( p )", "filename": "polynomial.py", "nloc": 19, "complexity": 4, "token_count": 190, "parameters": [ "p" ], "start_line": 71, "end_line": 108, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 38, "top_nesting_level": 0 }, { "name": "polyint", "long_name": "polyint( p , m = 1 , k = None )", "filename": "polynomial.py", "nloc": 24, "complexity": 8, "token_count": 190, "parameters": [ "p", "m", "k" ], "start_line": 110, "end_line": 140, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 31, "top_nesting_level": 0 }, { "name": "polyder", "long_name": "polyder( p , m = 1 )", "filename": "polynomial.py", "nloc": 15, "complexity": 4, "token_count": 97, "parameters": [ "p", "m" ], "start_line": 142, "end_line": 158, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 17, "top_nesting_level": 0 }, { "name": "polyval", "long_name": "polyval( p , x )", "filename": "polynomial.py", "nloc": 10, "complexity": 3, "token_count": 72, "parameters": [ "p", "x" ], "start_line": 160, "end_line": 180, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 21, "top_nesting_level": 0 }, { "name": "polyadd", "long_name": "polyadd( a1 , a2 )", "filename": "polynomial.py", "nloc": 15, "complexity": 5, "token_count": 124, "parameters": [ "a1", "a2" ], "start_line": 182, "end_line": 198, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 17, "top_nesting_level": 0 }, { "name": "polysub", "long_name": "polysub( a1 , a2 )", "filename": "polynomial.py", "nloc": 15, "complexity": 5, "token_count": 124, "parameters": [ "a1", "a2" ], "start_line": 200, "end_line": 216, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 17, "top_nesting_level": 0 }, { "name": "polymul", "long_name": "polymul( a1 , a2 )", "filename": "polynomial.py", "nloc": 6, "complexity": 3, "token_count": 46, "parameters": [ "a1", "a2" ], "start_line": 219, "end_line": 226, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 8, "top_nesting_level": 0 }, { "name": "polydiv", "long_name": "polydiv( a1 , a2 )", "filename": "polynomial.py", "nloc": 8, "complexity": 5, "token_count": 94, "parameters": [ "a1", "a2" ], "start_line": 228, "end_line": 237, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 10, "top_nesting_level": 0 }, { "name": "deconvolve", "long_name": "deconvolve( signal , divisor )", "filename": "polynomial.py", "nloc": 18, "complexity": 3, "token_count": 115, "parameters": [ "signal", "divisor" ], "start_line": 239, "end_line": 258, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 20, "top_nesting_level": 0 }, { "name": "_raise_power", "long_name": "_raise_power( astr , wrap = 70 )", "filename": "polynomial.py", "nloc": 25, "complexity": 5, "token_count": 194, "parameters": [ "astr", "wrap" ], "start_line": 262, "end_line": 286, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 25, "top_nesting_level": 0 }, { "name": "__init__", "long_name": "__init__( self , c_or_r , r = 0 )", "filename": "polynomial.py", "nloc": 15, "complexity": 6, "token_count": 122, "parameters": [ "self", "c_or_r", "r" ], "start_line": 306, "end_line": 320, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 15, "top_nesting_level": 1 }, { "name": "__array__", "long_name": "__array__( self , t = None )", "filename": "polynomial.py", "nloc": 5, "complexity": 2, "token_count": 30, "parameters": [ "self", "t" ], "start_line": 322, "end_line": 326, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 5, "top_nesting_level": 1 }, { "name": "__coerce__", "long_name": "__coerce__( self , other )", "filename": "polynomial.py", "nloc": 2, "complexity": 1, "token_count": 9, "parameters": [ "self", "other" ], "start_line": 328, "end_line": 329, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 2, "top_nesting_level": 1 }, { "name": "__repr__", "long_name": "__repr__( self )", "filename": "polynomial.py", "nloc": 4, "complexity": 1, "token_count": 26, "parameters": [ "self" ], "start_line": 331, "end_line": 334, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 4, "top_nesting_level": 1 }, { "name": "__len__", "long_name": "__len__( self )", "filename": "polynomial.py", "nloc": 2, "complexity": 1, "token_count": 9, "parameters": [ "self" ], "start_line": 336, "end_line": 337, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 2, "top_nesting_level": 1 }, { "name": "__str__", "long_name": "__str__( self )", "filename": "polynomial.py", "nloc": 41, "complexity": 17, "token_count": 244, "parameters": [ "self" ], "start_line": 339, "end_line": 380, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 42, "top_nesting_level": 1 }, { "name": "__call__", "long_name": "__call__( self , val )", "filename": "polynomial.py", "nloc": 2, "complexity": 1, "token_count": 16, "parameters": [ "self", "val" ], "start_line": 383, "end_line": 384, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 2, "top_nesting_level": 1 }, { "name": "__mul__", "long_name": "__mul__( self , other )", "filename": "polynomial.py", "nloc": 6, "complexity": 2, "token_count": 44, "parameters": [ "self", "other" ], "start_line": 386, "end_line": 391, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 6, "top_nesting_level": 1 }, { "name": "__rmul__", "long_name": "__rmul__( self , other )", "filename": "polynomial.py", "nloc": 6, "complexity": 2, "token_count": 44, "parameters": [ "self", "other" ], "start_line": 393, "end_line": 398, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 6, "top_nesting_level": 1 }, { "name": "__add__", "long_name": "__add__( self , other )", "filename": "polynomial.py", "nloc": 3, "complexity": 1, "token_count": 27, "parameters": [ "self", "other" ], "start_line": 400, "end_line": 402, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 3, "top_nesting_level": 1 }, { "name": "__radd__", "long_name": "__radd__( self , other )", "filename": "polynomial.py", "nloc": 3, "complexity": 1, "token_count": 27, "parameters": [ "self", "other" ], "start_line": 404, "end_line": 406, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 3, "top_nesting_level": 1 }, { "name": "__pow__", "long_name": "__pow__( self , val )", "filename": "polynomial.py", "nloc": 7, "complexity": 5, "token_count": 57, "parameters": [ "self", "val" ], "start_line": 408, "end_line": 414, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 7, "top_nesting_level": 1 }, { "name": "__sub__", "long_name": "__sub__( self , other )", "filename": "polynomial.py", "nloc": 3, "complexity": 1, "token_count": 27, "parameters": [ "self", "other" ], "start_line": 416, "end_line": 418, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 3, "top_nesting_level": 1 }, { "name": "__rsub__", "long_name": "__rsub__( self , other )", "filename": "polynomial.py", "nloc": 3, "complexity": 1, "token_count": 27, "parameters": [ "self", "other" ], "start_line": 420, "end_line": 422, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 3, "top_nesting_level": 1 }, { "name": "__div__", "long_name": "__div__( self , other )", "filename": "polynomial.py", "nloc": 6, "complexity": 2, "token_count": 46, "parameters": [ "self", "other" ], "start_line": 424, "end_line": 429, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 6, "top_nesting_level": 1 }, { "name": "__rdiv__", "long_name": "__rdiv__( self , other )", "filename": "polynomial.py", "nloc": 6, "complexity": 2, "token_count": 46, "parameters": [ "self", "other" ], "start_line": 431, "end_line": 436, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 6, "top_nesting_level": 1 }, { "name": "__setattr__", "long_name": "__setattr__( self , key , val )", "filename": "polynomial.py", "nloc": 2, "complexity": 1, "token_count": 13, "parameters": [ "self", "key", "val" ], "start_line": 438, "end_line": 439, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 2, "top_nesting_level": 1 }, { "name": "__getattr__", "long_name": "__getattr__( self , key )", "filename": "polynomial.py", "nloc": 9, "complexity": 4, "token_count": 58, "parameters": [ "self", "key" ], "start_line": 441, "end_line": 449, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 9, "top_nesting_level": 1 }, { "name": "__getitem__", "long_name": "__getitem__( self , val )", "filename": "polynomial.py", "nloc": 7, "complexity": 3, "token_count": 37, "parameters": [ "self", "val" ], "start_line": 451, "end_line": 457, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 7, "top_nesting_level": 1 }, { "name": "__setitem__", "long_name": "__setitem__( self , key , val )", "filename": "polynomial.py", "nloc": 11, "complexity": 3, "token_count": 94, "parameters": [ "self", "key", "val" ], "start_line": 459, "end_line": 469, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 11, "top_nesting_level": 1 }, { "name": "integ", "long_name": "integ( self , m = 1 , k = 0 )", "filename": "polynomial.py", "nloc": 2, "complexity": 1, "token_count": 31, "parameters": [ "self", "m", "k" ], "start_line": 471, "end_line": 472, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 2, "top_nesting_level": 1 }, { "name": "deriv", "long_name": "deriv( self , m = 1 )", "filename": "polynomial.py", "nloc": 2, "complexity": 1, "token_count": 23, "parameters": [ "self", "m" ], "start_line": 474, "end_line": 475, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 2, "top_nesting_level": 1 } ], "changed_methods": [ { "name": "__setitem__", "long_name": "__setitem__( self , key , val )", "filename": "polynomial.py", "nloc": 11, "complexity": 3, "token_count": 94, "parameters": [ "self", "key", "val" ], "start_line": 458, "end_line": 468, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 11, "top_nesting_level": 1 }, { "name": "polymul", "long_name": "polymul( a1 , a2 )", "filename": "polynomial.py", "nloc": 6, "complexity": 3, "token_count": 46, "parameters": [ "a1", "a2" ], "start_line": 218, "end_line": 225, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 8, "top_nesting_level": 0 }, { "name": "__init__", "long_name": "__init__( self , c_or_r , r = 0 )", "filename": "polynomial.py", "nloc": 15, "complexity": 6, "token_count": 122, "parameters": [ "self", "c_or_r", "r" ], "start_line": 305, "end_line": 319, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 15, "top_nesting_level": 1 }, { "name": "polydiv", "long_name": "polydiv( a1 , a2 )", "filename": "polynomial.py", "nloc": 8, "complexity": 5, "token_count": 94, "parameters": [ "a1", "a2" ], "start_line": 227, "end_line": 236, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 10, "top_nesting_level": 0 }, { "name": "poly", "long_name": "poly( seq_of_zeros )", "filename": "polynomial.py", "nloc": 23, "complexity": 9, "token_count": 195, "parameters": [ "seq_of_zeros" ], "start_line": 31, "end_line": 69, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 39, "top_nesting_level": 0 }, { "name": "polysub", "long_name": "polysub( a1 , a2 )", "filename": "polynomial.py", "nloc": 15, "complexity": 5, "token_count": 124, "parameters": [ "a1", "a2" ], "start_line": 199, "end_line": 215, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 17, "top_nesting_level": 0 }, { "name": "polyadd", "long_name": "polyadd( a1 , a2 )", "filename": "polynomial.py", "nloc": 15, "complexity": 5, "token_count": 124, "parameters": [ "a1", "a2" ], "start_line": 181, "end_line": 197, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 17, "top_nesting_level": 0 }, { "name": "polyder", "long_name": "polyder( p , m = 1 )", "filename": "polynomial.py", "nloc": 15, "complexity": 4, "token_count": 97, "parameters": [ "p", "m" ], "start_line": 141, "end_line": 157, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 17, "top_nesting_level": 0 }, { "name": "polyint", "long_name": "polyint( p , m = 1 , k = None )", "filename": "polynomial.py", "nloc": 24, "complexity": 8, "token_count": 190, "parameters": [ "p", "m", "k" ], "start_line": 109, "end_line": 139, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 31, "top_nesting_level": 0 }, { "name": "polyval", "long_name": "polyval( p , x )", "filename": "polynomial.py", "nloc": 10, "complexity": 3, "token_count": 72, "parameters": [ "p", "x" ], "start_line": 159, "end_line": 179, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 21, "top_nesting_level": 0 }, { "name": "deconvolve", "long_name": "deconvolve( signal , divisor )", "filename": "polynomial.py", "nloc": 18, "complexity": 3, "token_count": 115, "parameters": [ "signal", "divisor" ], "start_line": 238, "end_line": 257, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 20, "top_nesting_level": 0 } ], "nloc": 370, "complexity": 117, "token_count": 2656, "diff_parsed": { "added": [ "import numerix as _nx", "from numerix import *", " k = _nx.zeros(m)", " k = k[0]*_nx.ones(m)", " y = _nx.zeros(len(p)+1,'d')", " y[:-1] = p*1.0/_nx.arange(len(p),0,-1)", " y = p[:-1] * _nx.arange(n,0,-1)", " y = _nx.zeros(x.shape,x.typecode())", " zr = _nx.zeros(diff)", " val = _nx.concatenate((zr,a1)) + a2", " zr = _nx.zeros(abs(diff))", " val = a1 + _nx.concatenate((zr,a2))", " zr = _nx.zeros(diff)", " val = _nx.concatenate((zr,a1)) - a2", " zr = _nx.zeros(abs(diff))", " val = a1 - _nx.concatenate((zr,a2))", " val = _nx.convolve(a1,a2)", " while _nx.allclose(r[0], 0, rtol=1e-14) and (r.shape[-1] > 1):", " input = _nx.ones(N-D+1,_nx.Float)", " rem = num - _nx.convolve(den,quot,mode=2)", " c_or_r = _nx.array([0])", " zr = _nx.zeros(key-self.order,self.coeffs.typecode())", " self.__dict__['coeffs'] = _nx.concatenate((zr,self.coeffs))" ], "deleted": [ "import Numeric", "from Numeric import *", "", " k = Numeric.zeros(m)", " k = k[0]*Numeric.ones(m)", " y = Numeric.zeros(len(p)+1,'d')", " y[:-1] = p*1.0/Numeric.arange(len(p),0,-1)", " y = p[:-1] * Numeric.arange(n,0,-1)", " y = Numeric.zeros(x.shape,x.typecode())", " zr = Numeric.zeros(diff)", " val = Numeric.concatenate((zr,a1)) + a2", " zr = Numeric.zeros(abs(diff))", " val = a1 + Numeric.concatenate((zr,a2))", " zr = Numeric.zeros(diff)", " val = Numeric.concatenate((zr,a1)) - a2", " zr = Numeric.zeros(abs(diff))", " val = a1 - Numeric.concatenate((zr,a2))", " val = Numeric.convolve(a1,a2)", " while Numeric.allclose(r[0], 0, rtol=1e-14) and (r.shape[-1] > 1):", " input = Numeric.ones(N-D+1,Numeric.Float)", " rem = num - Numeric.convolve(den,quot,mode=2)", " c_or_r = Numeric.array([0])", " zr = Numeric.zeros(key-self.order,self.coeffs.typecode())", " self.__dict__['coeffs'] = Numeric.concatenate((zr,self.coeffs))" ] } }, { "old_path": "scipy_base/scimath.py", "new_path": "scipy_base/scimath.py", "filename": "scimath.py", "extension": "py", "change_type": "MODIFY", "diff": "@@ -6,14 +6,13 @@\n __all__ = ['sqrt', 'log', 'log2','logn','log10', 'power', 'arccos',\n 'arcsin', 'arctanh']\n \n-import Numeric\n+import numerix as _nx\n+from numerix import *\n \n from type_check import isreal, asarray\n from function_base import any\n-import fastumath\n-from fastumath import *\n \n-__all__.extend([key for key in dir(fastumath) \\\n+__all__.extend([key for key in dir(_nx.fastumath) \\\n if key[0]!='_' and key not in __all__])\n \n def _tocomplex(arr):\n@@ -22,63 +21,56 @@ def _tocomplex(arr):\n else:\n return arr.astype('D')\n \n-def sqrt(x):\n+def _fix_real_lt_zero(x):\n x = asarray(x)\n- if isreal(x) and any(x<0):\n+ if any(isreal(x) & x<0):\n x = _tocomplex(x)\n- return fastumath.sqrt(x)\n+ return x\n \n-def log(x):\n+def _fix_real_abs_gt_1(x):\n x = asarray(x)\n- if isreal(x) and any(x<0):\n+ if any(isreal(x) & (abs(x)>1)):\n x = _tocomplex(x)\n+ return x\n+ \n+def sqrt(x):\n+ x = _fix_real_lt_zero(x)\n+ return fastumath.sqrt(x)\n+\n+def log(x):\n+ x = _fix_real_lt_zero(x)\n return fastumath.log(x)\n \n def log10(x):\n- x = asarray(x)\n- if isreal(x) and any(x<0):\n- x = _tocomplex(x)\n+ x = _fix_real_lt_zero(x)\n return fastumath.log10(x) \n \n def logn(n,x):\n \"\"\" Take log base n of x.\n \"\"\"\n- x = asarray(x)\n- if isreal(x) and any(x<0):\n- x = _tocomplex(x)\n- if isreal(n) and (n<0):\n- n = _tocomplex(n)\n+ x = _fix_real_lt_zero(x)\n+ n = _fix_real_lt_zero(n)\n return fastumath.log(x)/fastumath.log(n)\n \n def log2(x):\n \"\"\" Take log base 2 of x.\n \"\"\"\n- x = asarray(x)\n- if isreal(x) and any(x<0):\n- x = _tocomplex(x)\n+ x = _fix_real_lt_zero(x)\n return fastumath.log(x)/fastumath.log(2)\n \n-\n def power(x, p):\n- x = asarray(x)\n- if isreal(x) and any(x<0):\n- x = _tocomplex(x)\n+ x = _fix_real_lt_zero(x)\n return fastumath.power(x, p)\n- \n+\n+\n def arccos(x):\n- x = asarray(x)\n- if isreal(x) and any(abs(x)>1):\n- x = _tocomplex(x)\n+ x = _fix_real_abs_gt_1(x)\n return fastumath.arccos(x)\n \n def arcsin(x):\n- x = asarray(x)\n- if isreal(x) and any(abs(x)>1):\n- x = _tocomplex(x)\n+ x = _fix_real_abs_gt_1(x)\n return fastumath.arcsin(x)\n \n def arctanh(x):\n- x = asarray(x)\n- if isreal(x) and any(abs(x)>1):\n- x = _tocomplex(x)\n+ x = _fix_real_abs_gt_1(x)\n return fastumath.arctanh(x)\n", "added_lines": 26, "deleted_lines": 34, "source_code": "\"\"\"\nWrapper functions to more user-friendly calling of certain math functions\nwhose output is different than the input in certain domains of the input.\n\"\"\"\n\n__all__ = ['sqrt', 'log', 'log2','logn','log10', 'power', 'arccos',\n 'arcsin', 'arctanh']\n\nimport numerix as _nx\nfrom numerix import *\n\nfrom type_check import isreal, asarray\nfrom function_base import any\n\n__all__.extend([key for key in dir(_nx.fastumath) \\\n if key[0]!='_' and key not in __all__])\n\ndef _tocomplex(arr):\n if arr.typecode() in ['f', 's', 'b', '1','w']:\n return arr.astype('F')\n else:\n return arr.astype('D')\n\ndef _fix_real_lt_zero(x):\n x = asarray(x)\n if any(isreal(x) & x<0):\n x = _tocomplex(x)\n return x\n\ndef _fix_real_abs_gt_1(x):\n x = asarray(x)\n if any(isreal(x) & (abs(x)>1)):\n x = _tocomplex(x)\n return x\n \ndef sqrt(x):\n x = _fix_real_lt_zero(x)\n return fastumath.sqrt(x)\n\ndef log(x):\n x = _fix_real_lt_zero(x)\n return fastumath.log(x)\n\ndef log10(x):\n x = _fix_real_lt_zero(x)\n return fastumath.log10(x) \n\ndef logn(n,x):\n \"\"\" Take log base n of x.\n \"\"\"\n x = _fix_real_lt_zero(x)\n n = _fix_real_lt_zero(n)\n return fastumath.log(x)/fastumath.log(n)\n\ndef log2(x):\n \"\"\" Take log base 2 of x.\n \"\"\"\n x = _fix_real_lt_zero(x)\n return fastumath.log(x)/fastumath.log(2)\n\ndef power(x, p):\n x = _fix_real_lt_zero(x)\n return fastumath.power(x, p)\n\n\ndef arccos(x):\n x = _fix_real_abs_gt_1(x)\n return fastumath.arccos(x)\n\ndef arcsin(x):\n x = _fix_real_abs_gt_1(x)\n return fastumath.arcsin(x)\n\ndef arctanh(x):\n x = _fix_real_abs_gt_1(x)\n return fastumath.arctanh(x)\n", "source_code_before": "\"\"\"\nWrapper functions to more user-friendly calling of certain math functions\nwhose output is different than the input in certain domains of the input.\n\"\"\"\n\n__all__ = ['sqrt', 'log', 'log2','logn','log10', 'power', 'arccos',\n 'arcsin', 'arctanh']\n\nimport Numeric\n\nfrom type_check import isreal, asarray\nfrom function_base import any\nimport fastumath\nfrom fastumath import *\n\n__all__.extend([key for key in dir(fastumath) \\\n if key[0]!='_' and key not in __all__])\n\ndef _tocomplex(arr):\n if arr.typecode() in ['f', 's', 'b', '1','w']:\n return arr.astype('F')\n else:\n return arr.astype('D')\n\ndef sqrt(x):\n x = asarray(x)\n if isreal(x) and any(x<0):\n x = _tocomplex(x)\n return fastumath.sqrt(x)\n\ndef log(x):\n x = asarray(x)\n if isreal(x) and any(x<0):\n x = _tocomplex(x)\n return fastumath.log(x)\n\ndef log10(x):\n x = asarray(x)\n if isreal(x) and any(x<0):\n x = _tocomplex(x)\n return fastumath.log10(x) \n\ndef logn(n,x):\n \"\"\" Take log base n of x.\n \"\"\"\n x = asarray(x)\n if isreal(x) and any(x<0):\n x = _tocomplex(x)\n if isreal(n) and (n<0):\n n = _tocomplex(n)\n return fastumath.log(x)/fastumath.log(n)\n\ndef log2(x):\n \"\"\" Take log base 2 of x.\n \"\"\"\n x = asarray(x)\n if isreal(x) and any(x<0):\n x = _tocomplex(x)\n return fastumath.log(x)/fastumath.log(2)\n\n\ndef power(x, p):\n x = asarray(x)\n if isreal(x) and any(x<0):\n x = _tocomplex(x)\n return fastumath.power(x, p)\n \ndef arccos(x):\n x = asarray(x)\n if isreal(x) and any(abs(x)>1):\n x = _tocomplex(x)\n return fastumath.arccos(x)\n\ndef arcsin(x):\n x = asarray(x)\n if isreal(x) and any(abs(x)>1):\n x = _tocomplex(x)\n return fastumath.arcsin(x)\n\ndef arctanh(x):\n x = asarray(x)\n if isreal(x) and any(abs(x)>1):\n x = _tocomplex(x)\n return fastumath.arctanh(x)\n", "methods": [ { "name": "_tocomplex", "long_name": "_tocomplex( arr )", "filename": "scimath.py", "nloc": 5, "complexity": 2, "token_count": 40, "parameters": [ "arr" ], "start_line": 18, "end_line": 22, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 5, "top_nesting_level": 0 }, { "name": "_fix_real_lt_zero", "long_name": "_fix_real_lt_zero( x )", "filename": "scimath.py", "nloc": 5, "complexity": 2, "token_count": 32, "parameters": [ "x" ], "start_line": 24, "end_line": 28, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 5, "top_nesting_level": 0 }, { "name": "_fix_real_abs_gt_1", "long_name": "_fix_real_abs_gt_1( x )", "filename": "scimath.py", "nloc": 5, "complexity": 2, "token_count": 37, "parameters": [ "x" ], "start_line": 30, "end_line": 34, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 5, "top_nesting_level": 0 }, { "name": "sqrt", "long_name": "sqrt( x )", "filename": "scimath.py", "nloc": 3, "complexity": 1, "token_count": 18, "parameters": [ "x" ], "start_line": 36, "end_line": 38, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 3, "top_nesting_level": 0 }, { "name": "log", "long_name": "log( x )", "filename": "scimath.py", "nloc": 3, "complexity": 1, "token_count": 18, "parameters": [ "x" ], "start_line": 40, "end_line": 42, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 3, "top_nesting_level": 0 }, { "name": "log10", "long_name": "log10( x )", "filename": "scimath.py", "nloc": 3, "complexity": 1, "token_count": 18, "parameters": [ "x" ], "start_line": 44, "end_line": 46, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 3, "top_nesting_level": 0 }, { "name": "logn", "long_name": "logn( n , x )", "filename": "scimath.py", "nloc": 4, "complexity": 1, "token_count": 34, "parameters": [ "n", "x" ], "start_line": 48, "end_line": 53, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 6, "top_nesting_level": 0 }, { "name": "log2", "long_name": "log2( x )", "filename": "scimath.py", "nloc": 3, "complexity": 1, "token_count": 26, "parameters": [ "x" ], "start_line": 55, "end_line": 59, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 5, "top_nesting_level": 0 }, { "name": "power", "long_name": "power( x , p )", "filename": "scimath.py", "nloc": 3, "complexity": 1, "token_count": 22, "parameters": [ "x", "p" ], "start_line": 61, "end_line": 63, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 3, "top_nesting_level": 0 }, { "name": "arccos", "long_name": "arccos( x )", "filename": "scimath.py", "nloc": 3, "complexity": 1, "token_count": 18, "parameters": [ "x" ], "start_line": 66, "end_line": 68, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 3, "top_nesting_level": 0 }, { "name": "arcsin", "long_name": "arcsin( x )", "filename": "scimath.py", "nloc": 3, "complexity": 1, "token_count": 18, "parameters": [ "x" ], "start_line": 70, "end_line": 72, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 3, "top_nesting_level": 0 }, { "name": "arctanh", "long_name": "arctanh( x )", "filename": "scimath.py", "nloc": 3, "complexity": 1, "token_count": 18, "parameters": [ "x" ], "start_line": 74, "end_line": 76, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 3, "top_nesting_level": 0 } ], "methods_before": [ { "name": "_tocomplex", "long_name": "_tocomplex( arr )", "filename": "scimath.py", "nloc": 5, "complexity": 2, "token_count": 40, "parameters": [ "arr" ], "start_line": 19, "end_line": 23, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 5, "top_nesting_level": 0 }, { "name": "sqrt", "long_name": "sqrt( x )", "filename": "scimath.py", "nloc": 5, "complexity": 3, "token_count": 37, "parameters": [ "x" ], "start_line": 25, "end_line": 29, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 5, "top_nesting_level": 0 }, { "name": "log", "long_name": "log( x )", "filename": "scimath.py", "nloc": 5, "complexity": 3, "token_count": 37, "parameters": [ "x" ], "start_line": 31, "end_line": 35, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 5, "top_nesting_level": 0 }, { "name": "log10", "long_name": "log10( x )", "filename": "scimath.py", "nloc": 5, "complexity": 3, "token_count": 37, "parameters": [ "x" ], "start_line": 37, "end_line": 41, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 5, "top_nesting_level": 0 }, { "name": "logn", "long_name": "logn( n , x )", "filename": "scimath.py", "nloc": 7, "complexity": 5, "token_count": 65, "parameters": [ "n", "x" ], "start_line": 43, "end_line": 51, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 9, "top_nesting_level": 0 }, { "name": "log2", "long_name": "log2( x )", "filename": "scimath.py", "nloc": 5, "complexity": 3, "token_count": 45, "parameters": [ "x" ], "start_line": 53, "end_line": 59, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 7, "top_nesting_level": 0 }, { "name": "power", "long_name": "power( x , p )", "filename": "scimath.py", "nloc": 5, "complexity": 3, "token_count": 41, "parameters": [ "x", "p" ], "start_line": 62, "end_line": 66, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 5, "top_nesting_level": 0 }, { "name": "arccos", "long_name": "arccos( x )", "filename": "scimath.py", "nloc": 5, "complexity": 3, "token_count": 40, "parameters": [ "x" ], "start_line": 68, "end_line": 72, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 5, "top_nesting_level": 0 }, { "name": "arcsin", "long_name": "arcsin( x )", "filename": "scimath.py", "nloc": 5, "complexity": 3, "token_count": 40, "parameters": [ "x" ], "start_line": 74, "end_line": 78, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 5, "top_nesting_level": 0 }, { "name": "arctanh", "long_name": "arctanh( x )", "filename": "scimath.py", "nloc": 5, "complexity": 3, "token_count": 40, "parameters": [ "x" ], "start_line": 80, "end_line": 84, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 5, "top_nesting_level": 0 } ], "changed_methods": [ { "name": "arcsin", "long_name": "arcsin( x )", "filename": "scimath.py", "nloc": 3, "complexity": 1, "token_count": 18, "parameters": [ "x" ], "start_line": 70, "end_line": 72, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 3, "top_nesting_level": 0 }, { "name": "arctanh", "long_name": "arctanh( x )", "filename": "scimath.py", "nloc": 3, "complexity": 1, "token_count": 18, "parameters": [ "x" ], "start_line": 74, "end_line": 76, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 3, "top_nesting_level": 0 }, { "name": "_fix_real_lt_zero", "long_name": "_fix_real_lt_zero( x )", "filename": "scimath.py", "nloc": 5, "complexity": 2, "token_count": 32, "parameters": [ "x" ], "start_line": 24, "end_line": 28, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 5, "top_nesting_level": 0 }, { "name": "log", "long_name": "log( x )", "filename": "scimath.py", "nloc": 3, "complexity": 1, "token_count": 18, "parameters": [ "x" ], "start_line": 40, "end_line": 42, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 3, "top_nesting_level": 0 }, { "name": "_fix_real_abs_gt_1", "long_name": "_fix_real_abs_gt_1( x )", "filename": "scimath.py", "nloc": 5, "complexity": 2, "token_count": 37, "parameters": [ "x" ], "start_line": 30, "end_line": 34, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 5, "top_nesting_level": 0 }, { "name": "logn", "long_name": "logn( n , x )", "filename": "scimath.py", "nloc": 4, "complexity": 1, "token_count": 34, "parameters": [ "n", "x" ], "start_line": 48, "end_line": 53, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 6, "top_nesting_level": 0 }, { "name": "arccos", "long_name": "arccos( x )", "filename": "scimath.py", "nloc": 3, "complexity": 1, "token_count": 18, "parameters": [ "x" ], "start_line": 66, "end_line": 68, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 3, "top_nesting_level": 0 }, { "name": "power", "long_name": "power( x , p )", "filename": "scimath.py", "nloc": 3, "complexity": 1, "token_count": 22, "parameters": [ "x", "p" ], "start_line": 61, "end_line": 63, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 3, "top_nesting_level": 0 }, { "name": "log2", "long_name": "log2( x )", "filename": "scimath.py", "nloc": 3, "complexity": 1, "token_count": 26, "parameters": [ "x" ], "start_line": 55, "end_line": 59, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 5, "top_nesting_level": 0 }, { "name": "log10", "long_name": "log10( x )", "filename": "scimath.py", "nloc": 3, "complexity": 1, "token_count": 18, "parameters": [ "x" ], "start_line": 44, "end_line": 46, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 3, "top_nesting_level": 0 }, { "name": "sqrt", "long_name": "sqrt( x )", "filename": "scimath.py", "nloc": 3, "complexity": 1, "token_count": 18, "parameters": [ "x" ], "start_line": 36, "end_line": 38, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 3, "top_nesting_level": 0 } ], "nloc": 55, "complexity": 15, "token_count": 381, "diff_parsed": { "added": [ "import numerix as _nx", "from numerix import *", "__all__.extend([key for key in dir(_nx.fastumath) \\", "def _fix_real_lt_zero(x):", " if any(isreal(x) & x<0):", " return x", "def _fix_real_abs_gt_1(x):", " if any(isreal(x) & (abs(x)>1)):", " return x", "", "def sqrt(x):", " x = _fix_real_lt_zero(x)", " return fastumath.sqrt(x)", "", "def log(x):", " x = _fix_real_lt_zero(x)", " x = _fix_real_lt_zero(x)", " x = _fix_real_lt_zero(x)", " n = _fix_real_lt_zero(n)", " x = _fix_real_lt_zero(x)", " x = _fix_real_lt_zero(x)", "", "", " x = _fix_real_abs_gt_1(x)", " x = _fix_real_abs_gt_1(x)", " x = _fix_real_abs_gt_1(x)" ], "deleted": [ "import Numeric", "import fastumath", "from fastumath import *", "__all__.extend([key for key in dir(fastumath) \\", "def sqrt(x):", " if isreal(x) and any(x<0):", " return fastumath.sqrt(x)", "def log(x):", " if isreal(x) and any(x<0):", " x = asarray(x)", " if isreal(x) and any(x<0):", " x = _tocomplex(x)", " x = asarray(x)", " if isreal(x) and any(x<0):", " x = _tocomplex(x)", " if isreal(n) and (n<0):", " n = _tocomplex(n)", " x = asarray(x)", " if isreal(x) and any(x<0):", " x = _tocomplex(x)", "", " x = asarray(x)", " if isreal(x) and any(x<0):", " x = _tocomplex(x)", "", " x = asarray(x)", " if isreal(x) and any(abs(x)>1):", " x = _tocomplex(x)", " x = asarray(x)", " if isreal(x) and any(abs(x)>1):", " x = _tocomplex(x)", " x = asarray(x)", " if isreal(x) and any(abs(x)>1):", " x = _tocomplex(x)" ] } }, { "old_path": "scipy_base/setup_scipy_base.py", "new_path": "scipy_base/setup_scipy_base.py", "filename": "setup_scipy_base.py", "extension": "py", "change_type": "MODIFY", "diff": "@@ -1,9 +1,51 @@\n #!/usr/bin/env python\n-\n import os, sys\n from glob import glob\n import shutil\n \n+class _CleanUpFile:\n+ \"\"\"CleanUpFile deletes the specified filename when self is destroyed.\"\"\"\n+ def __init__(self, name):\n+ self.name = name\n+ def __del__(self):\n+ os.remove(self.name)\n+ # pass # leave source around for debugging\n+\n+def _temp_copy(_from, _to):\n+ \"\"\"temp_copy copies a named file into a named temporary file.\n+ The temporary will be deleted when the setupext module is destructed.\n+ \"\"\"\n+ # Copy the file data from _from to _to\n+ s = open(_from).read()\n+ open(_to,\"w+\").write(s)\n+ # Suppress object rebuild by preserving time stamps.\n+ stats = os.stat(_from)\n+ os.utime(_to, (stats.st_atime, stats.st_mtime))\n+ # Make an object to eliminate the temporary file at exit time.\n+ globals()[\"_cleanup_\"+_to] = _CleanUpFile(_to)\n+\n+def _config_compiled_base(package, local_path, numerix_prefix, macro, info):\n+ \"\"\"_config_compiled_base returns the Extension object for an\n+ Numeric or numarray specific version of _compiled_base.\n+ \"\"\"\n+ from scipy_distutils.system_info import dict_append\n+ from scipy_distutils.core import Extension\n+ from scipy_distutils.misc_util import dot_join\n+ module = numerix_prefix + \"_compiled_base\"\n+ source = module + '.c'\n+ _temp_copy(os.path.join(local_path, \"_compiled_base.c\"),\n+ os.path.join(local_path, source))\n+ sources = [source]\n+ sources = [os.path.join(local_path,x) for x in sources]\n+ depends = sources\n+ ext_args = {'name':dot_join(package, module),\n+ 'sources':sources,\n+ 'depends':depends,\n+ 'define_macros':[(macro,1)],\n+ }\n+ dict_append(ext_args,**info)\n+ return Extension(**ext_args)\n+ \n def configuration(parent_package='',parent_path=None):\n from scipy_distutils.system_info import get_info, dict_append\n from scipy_distutils.core import Extension\n@@ -24,7 +66,12 @@ def configuration(parent_package='',parent_path=None):\n # fastumath module\n # scipy_base.fastumath module\n umath_c_sources = ['fastumathmodule.c',\n- 'fastumath_unsigned.inc','fastumath_nounsigned.inc']\n+ 'fastumath_unsigned.inc',\n+ 'fastumath_nounsigned.inc',\n+ '_scipy_mapping.c',\n+ '_scipy_number.c']\n+ depends = umath_c_sources # ????\n+ depends = [os.path.join(local_path,x) for x in depends]\n umath_c_sources = [os.path.join(local_path,x) for x in umath_c_sources]\n umath_c = SourceGenerator(func = None,\n target = os.path.join(local_path,'fastumathmodule.c'),\n@@ -42,6 +89,7 @@ def configuration(parent_package='',parent_path=None):\n else:\n libraries.append('m')\n define_macros.append(('HAVE_INVERSE_HYPERBOLIC',None))\n+\n ext_args = {'name':dot_join(package,'fastumath'),\n 'sources':sources,\n 'define_macros': define_macros,\n@@ -52,18 +100,18 @@ def configuration(parent_package='',parent_path=None):\n dict_append(ext_args,**numpy_info)\n config['ext_modules'].append(Extension(**ext_args))\n \n- # _compiled_base module\n- sources = ['_compiled_base.c']\n- sources = [os.path.join(local_path,x) for x in sources]\n- depends = ['_scipy_mapping.c','_scipy_number.c']\n- depends = [os.path.join(local_path,x) for x in depends]\n-\n- ext_args = {'name':dot_join(package,'_compiled_base'),\n- 'sources':sources,\n- 'depends':depends}\n- dict_append(ext_args,**numpy_info)\n- config['ext_modules'].append(Extension(**ext_args))\n+ # _compiled_base module for Numeric: _nc_compiled_base\n+ _nc_compiled_base_ext = _config_compiled_base(\n+ package, local_path, \"_nc\", \"NUMERIC\", numpy_info)\n+ config['ext_modules'].append(_nc_compiled_base_ext)\n \n+ # _compiled_base module for numarray: _na_compiled_base\n+ numarray_info = get_info('numarray')\n+ if numarray_info:\n+ _na_compiled_base_ext = _config_compiled_base(\n+ package, local_path, \"_na\", \"NUMARRAY\", numarray_info)\n+ config['ext_modules'].append(_na_compiled_base_ext)\n+ \n # display_test module\n sources = [os.path.join(local_path,'src','display_test.c')]\n x11 = get_info('x11')\n", "added_lines": 61, "deleted_lines": 13, "source_code": "#!/usr/bin/env python\nimport os, sys\nfrom glob import glob\nimport shutil\n\nclass _CleanUpFile:\n \"\"\"CleanUpFile deletes the specified filename when self is destroyed.\"\"\"\n def __init__(self, name):\n self.name = name\n def __del__(self):\n os.remove(self.name)\n # pass # leave source around for debugging\n\ndef _temp_copy(_from, _to):\n \"\"\"temp_copy copies a named file into a named temporary file.\n The temporary will be deleted when the setupext module is destructed.\n \"\"\"\n # Copy the file data from _from to _to\n s = open(_from).read()\n open(_to,\"w+\").write(s)\n # Suppress object rebuild by preserving time stamps.\n stats = os.stat(_from)\n os.utime(_to, (stats.st_atime, stats.st_mtime))\n # Make an object to eliminate the temporary file at exit time.\n globals()[\"_cleanup_\"+_to] = _CleanUpFile(_to)\n\ndef _config_compiled_base(package, local_path, numerix_prefix, macro, info):\n \"\"\"_config_compiled_base returns the Extension object for an\n Numeric or numarray specific version of _compiled_base.\n \"\"\"\n from scipy_distutils.system_info import dict_append\n from scipy_distutils.core import Extension\n from scipy_distutils.misc_util import dot_join\n module = numerix_prefix + \"_compiled_base\"\n source = module + '.c'\n _temp_copy(os.path.join(local_path, \"_compiled_base.c\"),\n os.path.join(local_path, source))\n sources = [source]\n sources = [os.path.join(local_path,x) for x in sources]\n depends = sources\n ext_args = {'name':dot_join(package, module),\n 'sources':sources,\n 'depends':depends,\n 'define_macros':[(macro,1)],\n }\n dict_append(ext_args,**info)\n return Extension(**ext_args)\n \ndef configuration(parent_package='',parent_path=None):\n from scipy_distutils.system_info import get_info, dict_append\n from scipy_distutils.core import Extension\n from scipy_distutils.misc_util import get_path,default_config_dict,dot_join\n from scipy_distutils.misc_util import get_path,default_config_dict,\\\n dot_join,SourceGenerator\n\n package = 'scipy_base'\n local_path = get_path(__name__,parent_path)\n config = default_config_dict(package,parent_package)\n\n numpy_info = get_info('numpy',notfound_action=2)\n\n # extra_compile_args -- trying to find something that is binary compatible\n # with msvc for returning Py_complex from functions\n extra_compile_args=[]\n \n # fastumath module\n # scipy_base.fastumath module\n umath_c_sources = ['fastumathmodule.c',\n 'fastumath_unsigned.inc',\n 'fastumath_nounsigned.inc',\n '_scipy_mapping.c',\n '_scipy_number.c']\n depends = umath_c_sources # ????\n depends = [os.path.join(local_path,x) for x in depends]\n umath_c_sources = [os.path.join(local_path,x) for x in umath_c_sources]\n umath_c = SourceGenerator(func = None,\n target = os.path.join(local_path,'fastumathmodule.c'),\n sources = umath_c_sources)\n sources = [umath_c, os.path.join(local_path,'isnan.c')]\n define_macros = []\n undef_macros = []\n libraries = []\n if sys.byteorder == \"little\":\n define_macros.append(('USE_MCONF_LITE_LE',None))\n else:\n define_macros.append(('USE_MCONF_LITE_BE',None))\n if sys.platform in ['win32']:\n undef_macros.append('HAVE_INVERSE_HYPERBOLIC')\n else:\n libraries.append('m')\n define_macros.append(('HAVE_INVERSE_HYPERBOLIC',None))\n\n ext_args = {'name':dot_join(package,'fastumath'),\n 'sources':sources,\n 'define_macros': define_macros,\n 'undef_macros': undef_macros,\n 'libraries': libraries,\n 'extra_compile_args': extra_compile_args,\n 'depends': umath_c_sources}\n dict_append(ext_args,**numpy_info)\n config['ext_modules'].append(Extension(**ext_args))\n \n # _compiled_base module for Numeric: _nc_compiled_base\n _nc_compiled_base_ext = _config_compiled_base(\n package, local_path, \"_nc\", \"NUMERIC\", numpy_info)\n config['ext_modules'].append(_nc_compiled_base_ext)\n\n # _compiled_base module for numarray: _na_compiled_base\n numarray_info = get_info('numarray')\n if numarray_info:\n _na_compiled_base_ext = _config_compiled_base(\n package, local_path, \"_na\", \"NUMARRAY\", numarray_info)\n config['ext_modules'].append(_na_compiled_base_ext)\n \n # display_test module\n sources = [os.path.join(local_path,'src','display_test.c')]\n x11 = get_info('x11')\n if x11:\n x11['define_macros'] = [('HAVE_X11',None)]\n ext = Extension(dot_join(package,'display_test'), sources, **x11)\n config['ext_modules'].append(ext)\n\n return config\n\nif __name__ == '__main__':\n from scipy_base_version import scipy_base_version\n print 'scipy_base Version',scipy_base_version\n from scipy_distutils.core import setup\n\n setup(version = scipy_base_version,\n maintainer = \"SciPy Developers\",\n maintainer_email = \"scipy-dev@scipy.org\",\n description = \"SciPy base module\",\n url = \"http://www.scipy.org\",\n license = \"SciPy License (BSD Style)\",\n **configuration(parent_path='')\n )\n", "source_code_before": "#!/usr/bin/env python\n\nimport os, sys\nfrom glob import glob\nimport shutil\n\ndef configuration(parent_package='',parent_path=None):\n from scipy_distutils.system_info import get_info, dict_append\n from scipy_distutils.core import Extension\n from scipy_distutils.misc_util import get_path,default_config_dict,dot_join\n from scipy_distutils.misc_util import get_path,default_config_dict,\\\n dot_join,SourceGenerator\n\n package = 'scipy_base'\n local_path = get_path(__name__,parent_path)\n config = default_config_dict(package,parent_package)\n\n numpy_info = get_info('numpy',notfound_action=2)\n\n # extra_compile_args -- trying to find something that is binary compatible\n # with msvc for returning Py_complex from functions\n extra_compile_args=[]\n \n # fastumath module\n # scipy_base.fastumath module\n umath_c_sources = ['fastumathmodule.c',\n 'fastumath_unsigned.inc','fastumath_nounsigned.inc']\n umath_c_sources = [os.path.join(local_path,x) for x in umath_c_sources]\n umath_c = SourceGenerator(func = None,\n target = os.path.join(local_path,'fastumathmodule.c'),\n sources = umath_c_sources)\n sources = [umath_c, os.path.join(local_path,'isnan.c')]\n define_macros = []\n undef_macros = []\n libraries = []\n if sys.byteorder == \"little\":\n define_macros.append(('USE_MCONF_LITE_LE',None))\n else:\n define_macros.append(('USE_MCONF_LITE_BE',None))\n if sys.platform in ['win32']:\n undef_macros.append('HAVE_INVERSE_HYPERBOLIC')\n else:\n libraries.append('m')\n define_macros.append(('HAVE_INVERSE_HYPERBOLIC',None))\n ext_args = {'name':dot_join(package,'fastumath'),\n 'sources':sources,\n 'define_macros': define_macros,\n 'undef_macros': undef_macros,\n 'libraries': libraries,\n 'extra_compile_args': extra_compile_args,\n 'depends': umath_c_sources}\n dict_append(ext_args,**numpy_info)\n config['ext_modules'].append(Extension(**ext_args))\n \n # _compiled_base module\n sources = ['_compiled_base.c']\n sources = [os.path.join(local_path,x) for x in sources]\n depends = ['_scipy_mapping.c','_scipy_number.c']\n depends = [os.path.join(local_path,x) for x in depends]\n\n ext_args = {'name':dot_join(package,'_compiled_base'),\n 'sources':sources,\n 'depends':depends}\n dict_append(ext_args,**numpy_info)\n config['ext_modules'].append(Extension(**ext_args))\n\n # display_test module\n sources = [os.path.join(local_path,'src','display_test.c')]\n x11 = get_info('x11')\n if x11:\n x11['define_macros'] = [('HAVE_X11',None)]\n ext = Extension(dot_join(package,'display_test'), sources, **x11)\n config['ext_modules'].append(ext)\n\n return config\n\nif __name__ == '__main__':\n from scipy_base_version import scipy_base_version\n print 'scipy_base Version',scipy_base_version\n from scipy_distutils.core import setup\n\n setup(version = scipy_base_version,\n maintainer = \"SciPy Developers\",\n maintainer_email = \"scipy-dev@scipy.org\",\n description = \"SciPy base module\",\n url = \"http://www.scipy.org\",\n license = \"SciPy License (BSD Style)\",\n **configuration(parent_path='')\n )\n", "methods": [ { "name": "__init__", "long_name": "__init__( self , name )", "filename": "setup_scipy_base.py", "nloc": 2, "complexity": 1, "token_count": 12, "parameters": [ "self", "name" ], "start_line": 8, "end_line": 9, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 2, "top_nesting_level": 1 }, { "name": "__del__", "long_name": "__del__( self )", "filename": "setup_scipy_base.py", "nloc": 2, "complexity": 1, "token_count": 13, "parameters": [ "self" ], "start_line": 10, "end_line": 11, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 2, "top_nesting_level": 1 }, { "name": "_temp_copy", "long_name": "_temp_copy( _from , _to )", "filename": "setup_scipy_base.py", "nloc": 6, "complexity": 1, "token_count": 66, "parameters": [ "_from", "_to" ], "start_line": 14, "end_line": 25, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 12, "top_nesting_level": 0 }, { "name": "_config_compiled_base", "long_name": "_config_compiled_base( package , local_path , numerix_prefix , macro , info )", "filename": "setup_scipy_base.py", "nloc": 18, "complexity": 2, "token_count": 136, "parameters": [ "package", "local_path", "numerix_prefix", "macro", "info" ], "start_line": 27, "end_line": 47, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 21, "top_nesting_level": 0 }, { "name": "configuration", "long_name": "configuration( parent_package = '' , parent_path = None )", "filename": "setup_scipy_base.py", "nloc": 59, "complexity": 7, "token_count": 423, "parameters": [ "parent_package", "parent_path" ], "start_line": 49, "end_line": 123, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 75, "top_nesting_level": 0 } ], "methods_before": [ { "name": "configuration", "long_name": "configuration( parent_package = '' , parent_path = None )", "filename": "setup_scipy_base.py", "nloc": 55, "complexity": 7, "token_count": 431, "parameters": [ "parent_package", "parent_path" ], "start_line": 7, "end_line": 75, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 69, "top_nesting_level": 0 } ], "changed_methods": [ { "name": "_temp_copy", "long_name": "_temp_copy( _from , _to )", "filename": "setup_scipy_base.py", "nloc": 6, "complexity": 1, "token_count": 66, "parameters": [ "_from", "_to" ], "start_line": 14, "end_line": 25, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 12, "top_nesting_level": 0 }, { "name": "configuration", "long_name": "configuration( parent_package = '' , parent_path = None )", "filename": "setup_scipy_base.py", "nloc": 59, "complexity": 7, "token_count": 423, "parameters": [ "parent_package", "parent_path" ], "start_line": 49, "end_line": 123, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 75, "top_nesting_level": 0 }, { "name": "_config_compiled_base", "long_name": "_config_compiled_base( package , local_path , numerix_prefix , macro , info )", "filename": "setup_scipy_base.py", "nloc": 18, "complexity": 2, "token_count": 136, "parameters": [ "package", "local_path", "numerix_prefix", "macro", "info" ], "start_line": 27, "end_line": 47, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 21, "top_nesting_level": 0 }, { "name": "__del__", "long_name": "__del__( self )", "filename": "setup_scipy_base.py", "nloc": 2, "complexity": 1, "token_count": 13, "parameters": [ "self" ], "start_line": 10, "end_line": 11, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 2, "top_nesting_level": 1 }, { "name": "__init__", "long_name": "__init__( self , name )", "filename": "setup_scipy_base.py", "nloc": 2, "complexity": 1, "token_count": 12, "parameters": [ "self", "name" ], "start_line": 8, "end_line": 9, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 2, "top_nesting_level": 1 } ], "nloc": 104, "complexity": 12, "token_count": 722, "diff_parsed": { "added": [ "class _CleanUpFile:", " \"\"\"CleanUpFile deletes the specified filename when self is destroyed.\"\"\"", " def __init__(self, name):", " self.name = name", " def __del__(self):", " os.remove(self.name)", " # pass # leave source around for debugging", "", "def _temp_copy(_from, _to):", " \"\"\"temp_copy copies a named file into a named temporary file.", " The temporary will be deleted when the setupext module is destructed.", " \"\"\"", " # Copy the file data from _from to _to", " s = open(_from).read()", " open(_to,\"w+\").write(s)", " # Suppress object rebuild by preserving time stamps.", " stats = os.stat(_from)", " os.utime(_to, (stats.st_atime, stats.st_mtime))", " # Make an object to eliminate the temporary file at exit time.", " globals()[\"_cleanup_\"+_to] = _CleanUpFile(_to)", "", "def _config_compiled_base(package, local_path, numerix_prefix, macro, info):", " \"\"\"_config_compiled_base returns the Extension object for an", " Numeric or numarray specific version of _compiled_base.", " \"\"\"", " from scipy_distutils.system_info import dict_append", " from scipy_distutils.core import Extension", " from scipy_distutils.misc_util import dot_join", " module = numerix_prefix + \"_compiled_base\"", " source = module + '.c'", " _temp_copy(os.path.join(local_path, \"_compiled_base.c\"),", " os.path.join(local_path, source))", " sources = [source]", " sources = [os.path.join(local_path,x) for x in sources]", " depends = sources", " ext_args = {'name':dot_join(package, module),", " 'sources':sources,", " 'depends':depends,", " 'define_macros':[(macro,1)],", " }", " dict_append(ext_args,**info)", " return Extension(**ext_args)", "", " 'fastumath_unsigned.inc',", " 'fastumath_nounsigned.inc',", " '_scipy_mapping.c',", " '_scipy_number.c']", " depends = umath_c_sources # ????", " depends = [os.path.join(local_path,x) for x in depends]", "", " # _compiled_base module for Numeric: _nc_compiled_base", " _nc_compiled_base_ext = _config_compiled_base(", " package, local_path, \"_nc\", \"NUMERIC\", numpy_info)", " config['ext_modules'].append(_nc_compiled_base_ext)", " # _compiled_base module for numarray: _na_compiled_base", " numarray_info = get_info('numarray')", " if numarray_info:", " _na_compiled_base_ext = _config_compiled_base(", " package, local_path, \"_na\", \"NUMARRAY\", numarray_info)", " config['ext_modules'].append(_na_compiled_base_ext)", "" ], "deleted": [ "", " 'fastumath_unsigned.inc','fastumath_nounsigned.inc']", " # _compiled_base module", " sources = ['_compiled_base.c']", " sources = [os.path.join(local_path,x) for x in sources]", " depends = ['_scipy_mapping.c','_scipy_number.c']", " depends = [os.path.join(local_path,x) for x in depends]", "", " ext_args = {'name':dot_join(package,'_compiled_base'),", " 'sources':sources,", " 'depends':depends}", " dict_append(ext_args,**numpy_info)", " config['ext_modules'].append(Extension(**ext_args))" ] } }, { "old_path": "scipy_base/shape_base.py", "new_path": "scipy_base/shape_base.py", "filename": "shape_base.py", "extension": "py", "change_type": "MODIFY", "diff": "@@ -1,5 +1,6 @@\n-import Numeric\n-from Numeric import *\n+import numerix as _nx\n+from numerix import *\n+\n from type_check import isscalar, asarray\n \n __all__ = ['atleast_1d','atleast_2d','atleast_3d','vstack','hstack',\n@@ -20,20 +21,20 @@ def apply_along_axis(func1d,axis,arr,*args):\n and arr is an N-d array. i varies so as to apply the function\n along the given axis for each 1-d subarray in arr.\n \"\"\"\n- nd = Numeric.rank(arr)\n+ nd = _nx.rank(arr)\n if axis < 0: axis += nd\n if (axis >= nd):\n raise ValueError, \"axis must be less than the rank; \"+\\\n \"axis=%d, rank=%d.\" % (axis,)\n ind = [0]*(nd-1)\n- dims = Numeric.shape(arr)\n+ dims = _nx.shape(arr)\n i = zeros(nd,'O')\n indlist = range(nd)\n indlist.remove(axis)\n i[axis] = slice(None,None)\n outshape = take(shape(arr),indlist)\n put(i,indlist,ind)\n- res = func1d(arr[i],*args)\n+ res = func1d(arr[tuple(i)],*args)\n # if res is a number, then we have a smaller output array\n if isscalar(res):\n outarr = zeros(outshape,asarray(res).typecode())\n@@ -49,7 +50,7 @@ def apply_along_axis(func1d,axis,arr,*args):\n ind[n] = 0\n n -= 1\n put(i,indlist,ind)\n- res = func1d(arr[i],*args)\n+ res = func1d(arr[tuple(i)],*args)\n outarr[ind] = res\n k += 1\n return outarr\n@@ -59,7 +60,7 @@ def apply_along_axis(func1d,axis,arr,*args):\n outshape = list(shape(arr))\n outshape[axis] = len(res)\n outarr = zeros(outshape,asarray(res).typecode())\n- outarr[i] = res\n+ outarr[tuple(i)] = res\n k = 1\n while k < Ntot:\n # increment the index\n@@ -70,8 +71,8 @@ def apply_along_axis(func1d,axis,arr,*args):\n ind[n] = 0\n n -= 1\n put(i,indlist,ind)\n- res = func1d(arr[i],*args)\n- outarr[i] = res\n+ res = func1d(arr[tuple(i)],*args)\n+ outarr[tuple(i)] = res\n k += 1\n return outarr\n \n@@ -122,11 +123,9 @@ def atleast_1d(*arys):\n res = []\n for ary in arys:\n ary = asarray(ary)\n- if len(ary.shape) == 0: \n- result = Numeric.array([ary[0]])\n- else:\n- result = ary\n- res.append(result)\n+ if len(ary.shape) == 0:\n+ ary.shape = (1,)\n+ res.append(ary)\n if len(res) == 1:\n return res[0]\n else:\n@@ -147,8 +146,8 @@ def atleast_2d(*arys):\n res = []\n for ary in arys:\n ary = asarray(ary)\n- if len(ary.shape) == 0: \n- ary = Numeric.array([ary[0]])\n+ if len(ary.shape) == 0:\n+ ary.shape = (1,)\n if len(ary.shape) == 1: \n result = ary[NewAxis,:]\n else: \n@@ -178,7 +177,7 @@ def atleast_3d(*arys):\n for ary in arys:\n ary = asarray(ary)\n if len(ary.shape) == 0:\n- ary = Numeric.array([ary[0]])\n+ ary.shape = (1,)\n if len(ary.shape) == 1:\n result = ary[NewAxis,:,NewAxis]\n elif len(ary.shape) == 2:\n@@ -221,7 +220,7 @@ def vstack(tup):\n [4]])\n \n \"\"\"\n- return Numeric.concatenate(map(atleast_2d,tup),0)\n+ return _nx.concatenate(map(atleast_2d,tup),0)\n \n def hstack(tup):\n \"\"\" Stack arrays in sequence horizontally (column wise)\n@@ -248,7 +247,7 @@ def hstack(tup):\n [3, 4]])\n \n \"\"\"\n- return Numeric.concatenate(map(atleast_1d,tup),1)\n+ return _nx.concatenate(map(atleast_1d,tup),1)\n \n def column_stack(tup):\n \"\"\" Stack 1D arrays as columns into a 2D array\n@@ -270,8 +269,8 @@ def column_stack(tup):\n [3, 4]])\n \n \"\"\"\n- arrays = map(Numeric.transpose,map(atleast_2d,tup))\n- return Numeric.concatenate(arrays,1)\n+ arrays = map(_nx.transpose,map(atleast_2d,tup))\n+ return _nx.concatenate(arrays,1)\n \n def dstack(tup):\n \"\"\" Stack arrays in sequence depth wise (along third dimension)\n@@ -300,14 +299,14 @@ def dstack(tup):\n [ [2, 3]],\n [ [3, 4]]])\n \"\"\"\n- return Numeric.concatenate(map(atleast_3d,tup),2)\n+ return _nx.concatenate(map(atleast_3d,tup),2)\n \n def _replace_zero_by_x_arrays(sub_arys):\n for i in range(len(sub_arys)):\n- if len(Numeric.shape(sub_arys[i])) == 0:\n- sub_arys[i] = Numeric.array([])\n- elif Numeric.sometrue(Numeric.equal(Numeric.shape(sub_arys[i]),0)):\n- sub_arys[i] = Numeric.array([]) \n+ if len(_nx.shape(sub_arys[i])) == 0:\n+ sub_arys[i] = _nx.array([])\n+ elif _nx.sometrue(_nx.equal(_nx.shape(sub_arys[i]),0)):\n+ sub_arys[i] = _nx.array([]) \n return sub_arys\n \n def array_split(ary,indices_or_sections,axis = 0):\n@@ -358,13 +357,13 @@ def array_split(ary,indices_or_sections,axis = 0):\n section_sizes = [0] + \\\n extras * [Neach_section+1] + \\\n (Nsections-extras) * [Neach_section]\n- div_points = Numeric.add.accumulate(Numeric.array(section_sizes))\n+ div_points = _nx.add.accumulate(_nx.array(section_sizes))\n \n sub_arys = []\n- sary = Numeric.swapaxes(ary,axis,0)\n+ sary = _nx.swapaxes(ary,axis,0)\n for i in range(Nsections):\n st = div_points[i]; end = div_points[i+1]\n- sub_arys.append(Numeric.swapaxes(sary[st:end],axis,0))\n+ sub_arys.append(_nx.swapaxes(sary[st:end],axis,0))\n \n # there is a wierd issue with array slicing that allows\n # 0x10 arrays and other such things. The following cluge is needed\n@@ -452,7 +451,7 @@ def hsplit(ary,indices_or_sections):\n [3, 4]])]\n \n \"\"\"\n- if len(Numeric.shape(ary)) == 0:\n+ if len(_nx.shape(ary)) == 0:\n raise ValueError, 'hsplit only works on arrays of 1 or more dimensions'\n if len(ary.shape) > 1:\n return split(ary,indices_or_sections,1)\n@@ -497,7 +496,7 @@ def vsplit(ary,indices_or_sections):\n [array([ [1, 2, 3, 4]]), array([ [1, 2, 3, 4]])]\n \n \"\"\"\n- if len(Numeric.shape(ary)) < 2:\n+ if len(_nx.shape(ary)) < 2:\n raise ValueError, 'vsplit only works on arrays of 2 or more dimensions'\n return split(ary,indices_or_sections,0)\n \n@@ -534,7 +533,7 @@ def dsplit(ary,indices_or_sections):\n [3, 4]]])]\n \n \"\"\"\n- if len(Numeric.shape(ary)) < 3:\n+ if len(_nx.shape(ary)) < 3:\n raise ValueError, 'vsplit only works on arrays of 3 or more dimensions'\n return split(ary,indices_or_sections,2)\n \n", "added_lines": 31, "deleted_lines": 32, "source_code": "import numerix as _nx\nfrom numerix import *\n\nfrom type_check import isscalar, asarray\n\n__all__ = ['atleast_1d','atleast_2d','atleast_3d','vstack','hstack',\n 'column_stack','dstack','array_split','split','hsplit',\n 'vsplit','dsplit','squeeze','apply_over_axes','expand_dims',\n 'apply_along_axis']\n\ndef put(a,ind,v):\n # Cannot use Numeric.put because of Issue 202.\n j = 0\n for i in ind:\n a.flat[i] = v[j]\n j += 1\n return\n\ndef apply_along_axis(func1d,axis,arr,*args):\n \"\"\" Execute func1d(arr[i],*args) where func1d takes 1-D arrays\n and arr is an N-d array. i varies so as to apply the function\n along the given axis for each 1-d subarray in arr.\n \"\"\"\n nd = _nx.rank(arr)\n if axis < 0: axis += nd\n if (axis >= nd):\n raise ValueError, \"axis must be less than the rank; \"+\\\n \"axis=%d, rank=%d.\" % (axis,)\n ind = [0]*(nd-1)\n dims = _nx.shape(arr)\n i = zeros(nd,'O')\n indlist = range(nd)\n indlist.remove(axis)\n i[axis] = slice(None,None)\n outshape = take(shape(arr),indlist)\n put(i,indlist,ind)\n res = func1d(arr[tuple(i)],*args)\n # if res is a number, then we have a smaller output array\n if isscalar(res):\n outarr = zeros(outshape,asarray(res).typecode())\n outarr[ind] = res\n Ntot = product(outshape)\n k = 1\n while k < Ntot:\n # increment the index\n ind[-1] += 1\n n = -1\n while (ind[n] >= outshape[n]) and (n > (1-nd)):\n ind[n-1] += 1\n ind[n] = 0\n n -= 1\n put(i,indlist,ind)\n res = func1d(arr[tuple(i)],*args)\n outarr[ind] = res\n k += 1\n return outarr\n else:\n Ntot = product(outshape)\n holdshape = outshape\n outshape = list(shape(arr))\n outshape[axis] = len(res)\n outarr = zeros(outshape,asarray(res).typecode())\n outarr[tuple(i)] = res\n k = 1\n while k < Ntot:\n # increment the index\n ind[-1] += 1\n n = -1\n while (ind[n] >= holdshape[n]) and (n > (1-nd)):\n ind[n-1] += 1\n ind[n] = 0\n n -= 1\n put(i,indlist,ind)\n res = func1d(arr[tuple(i)],*args)\n outarr[tuple(i)] = res\n k += 1\n return outarr\n \n \ndef apply_over_axes(func, a, axes):\n \"\"\"Apply a function over multiple axes, keeping the same shape\n for the resulting array.\n \"\"\"\n val = asarray(a)\n N = len(val.shape)\n if not type(axes) in SequenceType:\n axes = (axes,)\n for axis in axes:\n if axis < 0: axis = N + axis\n args = (val, axis)\n val = expand_dims(func(*args),axis)\n return val\n\ndef expand_dims(a, axis):\n \"\"\"Expand the shape of a by including NewAxis before given axis.\n \"\"\"\n a = asarray(a)\n shape = a.shape\n if axis < 0:\n axis = axis + len(shape) + 1\n a.shape = shape[:axis] + (1,) + shape[axis:]\n return a\n\ndef squeeze(a):\n \"Returns a with any ones from the shape of a removed\"\n a = asarray(a)\n b = asarray(a.shape)\n val = reshape (a, tuple (compress (not_equal (b, 1), b)))\n return val\n\ndef atleast_1d(*arys):\n \"\"\" Force a sequence of arrays to each be at least 1D.\n\n Description:\n Force an array to be at least 1D. If an array is 0D, the \n array is converted to a single row of values. Otherwise,\n the array is unaltered.\n Arguments:\n *arys -- arrays to be converted to 1 or more dimensional array.\n Returns:\n input array converted to at least 1D array.\n \"\"\"\n res = []\n for ary in arys:\n ary = asarray(ary)\n if len(ary.shape) == 0:\n ary.shape = (1,)\n res.append(ary)\n if len(res) == 1:\n return res[0]\n else:\n return res\n\ndef atleast_2d(*arys):\n \"\"\" Force a sequence of arrays to each be at least 2D.\n\n Description:\n Force an array to each be at least 2D. If the array\n is 0D or 1D, the array is converted to a single\n row of values. Otherwise, the array is unaltered.\n Arguments:\n arys -- arrays to be converted to 2 or more dimensional array.\n Returns:\n input array converted to at least 2D array.\n \"\"\"\n res = []\n for ary in arys:\n ary = asarray(ary)\n if len(ary.shape) == 0:\n ary.shape = (1,)\n if len(ary.shape) == 1: \n result = ary[NewAxis,:]\n else: \n result = ary\n res.append(result)\n if len(res) == 1:\n return res[0]\n else:\n return res\n \ndef atleast_3d(*arys):\n \"\"\" Force a sequence of arrays to each be at least 3D.\n\n Description:\n Force an array each be at least 3D. If the array is 0D or 1D, \n the array is converted to a single 1xNx1 array of values where \n N is the orginal length of the array. If the array is 2D, the \n array is converted to a single MxNx1 array of values where MxN\n is the orginal shape of the array. Otherwise, the array is \n unaltered.\n Arguments:\n arys -- arrays to be converted to 3 or more dimensional array.\n Returns:\n input array converted to at least 3D array.\n \"\"\"\n res = []\n for ary in arys:\n ary = asarray(ary)\n if len(ary.shape) == 0:\n ary.shape = (1,)\n if len(ary.shape) == 1:\n result = ary[NewAxis,:,NewAxis]\n elif len(ary.shape) == 2:\n result = ary[:,:,NewAxis]\n else: \n result = ary\n res.append(result)\n if len(res) == 1:\n return res[0]\n else:\n return res\n\n\ndef vstack(tup):\n \"\"\" Stack arrays in sequence vertically (row wise)\n\n Description:\n Take a sequence of arrays and stack them veritcally\n to make a single array. All arrays in the sequence\n must have the same shape along all but the first axis. \n vstack will rebuild arrays divided by vsplit.\n Arguments:\n tup -- sequence of arrays. All arrays must have the same \n shape.\n Examples:\n >>> import scipy\n >>> a = array((1,2,3))\n >>> b = array((2,3,4))\n >>> scipy.vstack((a,b))\n array([[1, 2, 3],\n [2, 3, 4]])\n >>> a = array([[1],[2],[3]])\n >>> b = array([[2],[3],[4]])\n >>> scipy.vstack((a,b))\n array([[1],\n [2],\n [3],\n [2],\n [3],\n [4]])\n\n \"\"\"\n return _nx.concatenate(map(atleast_2d,tup),0)\n\ndef hstack(tup):\n \"\"\" Stack arrays in sequence horizontally (column wise)\n\n Description:\n Take a sequence of arrays and stack them horizontally\n to make a single array. All arrays in the sequence\n must have the same shape along all but the second axis.\n hstack will rebuild arrays divided by hsplit.\n Arguments:\n tup -- sequence of arrays. All arrays must have the same \n shape.\n Examples:\n >>> import scipy\n >>> a = array((1,2,3))\n >>> b = array((2,3,4))\n >>> scipy.hstack((a,b))\n array([1, 2, 3, 2, 3, 4])\n >>> a = array([[1],[2],[3]])\n >>> b = array([[2],[3],[4]])\n >>> scipy.hstack((a,b))\n array([[1, 2],\n [2, 3],\n [3, 4]])\n\n \"\"\"\n return _nx.concatenate(map(atleast_1d,tup),1)\n\ndef column_stack(tup):\n \"\"\" Stack 1D arrays as columns into a 2D array\n\n Description:\n Take a sequence of 1D arrays and stack them as columns\n to make a single 2D array. All arrays in the sequence\n must have the same length.\n Arguments:\n tup -- sequence of 1D arrays. All arrays must have the same \n length.\n Examples:\n >>> import scipy\n >>> a = array((1,2,3))\n >>> b = array((2,3,4))\n >>> scipy.vstack((a,b))\n array([[1, 2],\n [2, 3],\n [3, 4]])\n\n \"\"\"\n arrays = map(_nx.transpose,map(atleast_2d,tup))\n return _nx.concatenate(arrays,1)\n \ndef dstack(tup):\n \"\"\" Stack arrays in sequence depth wise (along third dimension)\n\n Description:\n Take a sequence of arrays and stack them along the third axis.\n All arrays in the sequence must have the same shape along all \n but the third axis. This is a simple way to stack 2D arrays \n (images) into a single 3D array for processing.\n dstack will rebuild arrays divided by dsplit.\n Arguments:\n tup -- sequence of arrays. All arrays must have the same \n shape.\n Examples:\n >>> import scipy\n >>> a = array((1,2,3))\n >>> b = array((2,3,4))\n >>> scipy.dstack((a,b))\n array([ [[1, 2],\n [2, 3],\n [3, 4]]])\n >>> a = array([[1],[2],[3]])\n >>> b = array([[2],[3],[4]])\n >>> scipy.dstack((a,b))\n array([[ [1, 2]],\n [ [2, 3]],\n [ [3, 4]]])\n \"\"\"\n return _nx.concatenate(map(atleast_3d,tup),2)\n\ndef _replace_zero_by_x_arrays(sub_arys):\n for i in range(len(sub_arys)):\n if len(_nx.shape(sub_arys[i])) == 0:\n sub_arys[i] = _nx.array([])\n elif _nx.sometrue(_nx.equal(_nx.shape(sub_arys[i]),0)):\n sub_arys[i] = _nx.array([]) \n return sub_arys\n \ndef array_split(ary,indices_or_sections,axis = 0):\n \"\"\" Divide an array into a list of sub-arrays.\n\n Description:\n Divide ary into a list of sub-arrays along the\n specified axis. If indices_or_sections is an integer,\n ary is divided into that many equally sized arrays.\n If it is impossible to make an equal split, each of the\n leading arrays in the list have one additional member. If\n indices_or_sections is a list of sorted integers, its\n entries define the indexes where ary is split.\n\n Arguments:\n ary -- N-D array.\n Array to be divided into sub-arrays.\n indices_or_sections -- integer or 1D array.\n If integer, defines the number of (close to) equal sized\n sub-arrays. If it is a 1D array of sorted indices, it\n defines the indexes at which ary is divided. Any empty\n list results in a single sub-array equal to the original\n array.\n axis -- integer. default=0.\n Specifies the axis along which to split ary.\n Caveats:\n Currently, the default for axis is 0. This\n means a 2D array is divided into multiple groups\n of rows. This seems like the appropriate default, but\n we've agreed most other functions should default to\n axis=-1. Perhaps we should use axis=-1 for consistency.\n However, we could also make the argument that SciPy\n works on \"rows\" by default. sum() sums up rows of\n values. split() will split data into rows. Opinions?\n \"\"\"\n try:\n Ntotal = ary.shape[axis]\n except AttributeError:\n Ntotal = len(ary)\n try: # handle scalar case.\n Nsections = len(indices_or_sections) + 1\n div_points = [0] + list(indices_or_sections) + [Ntotal]\n except TypeError: #indices_or_sections is a scalar, not an array.\n Nsections = int(indices_or_sections)\n if Nsections <= 0:\n raise ValueError, 'number sections must be larger than 0.'\n Neach_section,extras = divmod(Ntotal,Nsections)\n section_sizes = [0] + \\\n extras * [Neach_section+1] + \\\n (Nsections-extras) * [Neach_section]\n div_points = _nx.add.accumulate(_nx.array(section_sizes))\n\n sub_arys = []\n sary = _nx.swapaxes(ary,axis,0)\n for i in range(Nsections):\n st = div_points[i]; end = div_points[i+1]\n sub_arys.append(_nx.swapaxes(sary[st:end],axis,0))\n\n # there is a wierd issue with array slicing that allows\n # 0x10 arrays and other such things. The following cluge is needed\n # to get around this issue.\n sub_arys = _replace_zero_by_x_arrays(sub_arys)\n # end cluge.\n\n return sub_arys\n\ndef split(ary,indices_or_sections,axis=0):\n \"\"\" Divide an array into a list of sub-arrays.\n\n Description:\n Divide ary into a list of sub-arrays along the\n specified axis. If indices_or_sections is an integer,\n ary is divided into that many equally sized arrays.\n If it is impossible to make an equal split, an error is \n raised. This is the only way this function differs from\n the array_split() function. If indices_or_sections is a \n list of sorted integers, its entries define the indexes\n where ary is split.\n\n Arguments:\n ary -- N-D array.\n Array to be divided into sub-arrays.\n indices_or_sections -- integer or 1D array.\n If integer, defines the number of (close to) equal sized\n sub-arrays. If it is a 1D array of sorted indices, it\n defines the indexes at which ary is divided. Any empty\n list results in a single sub-array equal to the original\n array.\n axis -- integer. default=0.\n Specifies the axis along which to split ary.\n Caveats:\n Currently, the default for axis is 0. This\n means a 2D array is divided into multiple groups\n of rows. This seems like the appropriate default, but\n we've agreed most other functions should default to\n axis=-1. Perhaps we should use axis=-1 for consistency.\n However, we could also make the argument that SciPy\n works on \"rows\" by default. sum() sums up rows of\n values. split() will split data into rows. Opinions?\n \"\"\"\n try: len(indices_or_sections)\n except TypeError:\n sections = indices_or_sections\n N = ary.shape[axis]\n if N % sections:\n raise ValueError, 'array split does not result in an equal division'\n res = array_split(ary,indices_or_sections,axis)\n return res\n\ndef hsplit(ary,indices_or_sections):\n \"\"\" Split ary into multiple columns of sub-arrays\n\n Description:\n Split a single array into multiple sub arrays. The array is\n divided into groups of columns. If indices_or_sections is\n an integer, ary is divided into that many equally sized sub arrays.\n If it is impossible to make the sub-arrays equally sized, the\n operation throws a ValueError exception. See array_split and\n split for other options on indices_or_sections. \n Arguments:\n ary -- N-D array.\n Array to be divided into sub-arrays.\n indices_or_sections -- integer or 1D array.\n If integer, defines the number of (close to) equal sized\n sub-arrays. If it is a 1D array of sorted indices, it\n defines the indexes at which ary is divided. Any empty\n list results in a single sub-array equal to the original\n array.\n Returns:\n sequence of sub-arrays. The returned arrays have the same \n number of dimensions as the input array.\n Related:\n hstack, split, array_split, vsplit, dsplit. \n Examples:\n >>> import scipy\n >>> a= array((1,2,3,4))\n >>> scipy.hsplit(a,2)\n [array([1, 2]), array([3, 4])]\n >>> a = array([[1,2,3,4],[1,2,3,4]])\n [array([[1, 2],\n [1, 2]]), array([[3, 4],\n [3, 4]])]\n \n \"\"\"\n if len(_nx.shape(ary)) == 0:\n raise ValueError, 'hsplit only works on arrays of 1 or more dimensions'\n if len(ary.shape) > 1:\n return split(ary,indices_or_sections,1)\n else:\n return split(ary,indices_or_sections,0)\n \ndef vsplit(ary,indices_or_sections):\n \"\"\" Split ary into multiple rows of sub-arrays\n\n Description:\n Split a single array into multiple sub arrays. The array is\n divided into groups of rows. If indices_or_sections is\n an integer, ary is divided into that many equally sized sub arrays.\n If it is impossible to make the sub-arrays equally sized, the\n operation throws a ValueError exception. See array_split and\n split for other options on indices_or_sections.\n Arguments:\n ary -- N-D array.\n Array to be divided into sub-arrays.\n indices_or_sections -- integer or 1D array.\n If integer, defines the number of (close to) equal sized\n sub-arrays. If it is a 1D array of sorted indices, it\n defines the indexes at which ary is divided. Any empty\n list results in a single sub-array equal to the original\n array.\n Returns:\n sequence of sub-arrays. The returned arrays have the same \n number of dimensions as the input array. \n Caveats:\n How should we handle 1D arrays here? I am currently raising\n an error when I encounter them. Any better approach? \n \n Should we reduce the returned array to their minium dimensions\n by getting rid of any dimensions that are 1?\n Related:\n vstack, split, array_split, hsplit, dsplit.\n Examples:\n import scipy\n >>> a = array([[1,2,3,4],\n ... [1,2,3,4]])\n >>> scipy.vsplit(a)\n [array([ [1, 2, 3, 4]]), array([ [1, 2, 3, 4]])]\n \n \"\"\"\n if len(_nx.shape(ary)) < 2:\n raise ValueError, 'vsplit only works on arrays of 2 or more dimensions'\n return split(ary,indices_or_sections,0)\n\ndef dsplit(ary,indices_or_sections):\n \"\"\" Split ary into multiple sub-arrays along the 3rd axis (depth)\n\n Description:\n Split a single array into multiple sub arrays. The array is\n divided into groups along the 3rd axis. If indices_or_sections is\n an integer, ary is divided into that many equally sized sub arrays.\n If it is impossible to make the sub-arrays equally sized, the\n operation throws a ValueError exception. See array_split and\n split for other options on indices_or_sections. \n Arguments:\n ary -- N-D array.\n Array to be divided into sub-arrays.\n indices_or_sections -- integer or 1D array.\n If integer, defines the number of (close to) equal sized\n sub-arrays. If it is a 1D array of sorted indices, it\n defines the indexes at which ary is divided. Any empty\n list results in a single sub-array equal to the original\n array.\n Returns:\n sequence of sub-arrays. The returned arrays have the same \n number of dimensions as the input array.\n Caveats:\n See vsplit caveats. \n Related:\n dstack, split, array_split, hsplit, vsplit.\n Examples:\n >>> a = array([[[1,2,3,4],[1,2,3,4]]])\n [array([ [[1, 2],\n [1, 2]]]), array([ [[3, 4],\n [3, 4]]])]\n \n \"\"\"\n if len(_nx.shape(ary)) < 3:\n raise ValueError, 'vsplit only works on arrays of 3 or more dimensions'\n return split(ary,indices_or_sections,2)\n\n", "source_code_before": "import Numeric\nfrom Numeric import *\nfrom type_check import isscalar, asarray\n\n__all__ = ['atleast_1d','atleast_2d','atleast_3d','vstack','hstack',\n 'column_stack','dstack','array_split','split','hsplit',\n 'vsplit','dsplit','squeeze','apply_over_axes','expand_dims',\n 'apply_along_axis']\n\ndef put(a,ind,v):\n # Cannot use Numeric.put because of Issue 202.\n j = 0\n for i in ind:\n a.flat[i] = v[j]\n j += 1\n return\n\ndef apply_along_axis(func1d,axis,arr,*args):\n \"\"\" Execute func1d(arr[i],*args) where func1d takes 1-D arrays\n and arr is an N-d array. i varies so as to apply the function\n along the given axis for each 1-d subarray in arr.\n \"\"\"\n nd = Numeric.rank(arr)\n if axis < 0: axis += nd\n if (axis >= nd):\n raise ValueError, \"axis must be less than the rank; \"+\\\n \"axis=%d, rank=%d.\" % (axis,)\n ind = [0]*(nd-1)\n dims = Numeric.shape(arr)\n i = zeros(nd,'O')\n indlist = range(nd)\n indlist.remove(axis)\n i[axis] = slice(None,None)\n outshape = take(shape(arr),indlist)\n put(i,indlist,ind)\n res = func1d(arr[i],*args)\n # if res is a number, then we have a smaller output array\n if isscalar(res):\n outarr = zeros(outshape,asarray(res).typecode())\n outarr[ind] = res\n Ntot = product(outshape)\n k = 1\n while k < Ntot:\n # increment the index\n ind[-1] += 1\n n = -1\n while (ind[n] >= outshape[n]) and (n > (1-nd)):\n ind[n-1] += 1\n ind[n] = 0\n n -= 1\n put(i,indlist,ind)\n res = func1d(arr[i],*args)\n outarr[ind] = res\n k += 1\n return outarr\n else:\n Ntot = product(outshape)\n holdshape = outshape\n outshape = list(shape(arr))\n outshape[axis] = len(res)\n outarr = zeros(outshape,asarray(res).typecode())\n outarr[i] = res\n k = 1\n while k < Ntot:\n # increment the index\n ind[-1] += 1\n n = -1\n while (ind[n] >= holdshape[n]) and (n > (1-nd)):\n ind[n-1] += 1\n ind[n] = 0\n n -= 1\n put(i,indlist,ind)\n res = func1d(arr[i],*args)\n outarr[i] = res\n k += 1\n return outarr\n \n \ndef apply_over_axes(func, a, axes):\n \"\"\"Apply a function over multiple axes, keeping the same shape\n for the resulting array.\n \"\"\"\n val = asarray(a)\n N = len(val.shape)\n if not type(axes) in SequenceType:\n axes = (axes,)\n for axis in axes:\n if axis < 0: axis = N + axis\n args = (val, axis)\n val = expand_dims(func(*args),axis)\n return val\n\ndef expand_dims(a, axis):\n \"\"\"Expand the shape of a by including NewAxis before given axis.\n \"\"\"\n a = asarray(a)\n shape = a.shape\n if axis < 0:\n axis = axis + len(shape) + 1\n a.shape = shape[:axis] + (1,) + shape[axis:]\n return a\n\ndef squeeze(a):\n \"Returns a with any ones from the shape of a removed\"\n a = asarray(a)\n b = asarray(a.shape)\n val = reshape (a, tuple (compress (not_equal (b, 1), b)))\n return val\n\ndef atleast_1d(*arys):\n \"\"\" Force a sequence of arrays to each be at least 1D.\n\n Description:\n Force an array to be at least 1D. If an array is 0D, the \n array is converted to a single row of values. Otherwise,\n the array is unaltered.\n Arguments:\n *arys -- arrays to be converted to 1 or more dimensional array.\n Returns:\n input array converted to at least 1D array.\n \"\"\"\n res = []\n for ary in arys:\n ary = asarray(ary)\n if len(ary.shape) == 0: \n result = Numeric.array([ary[0]])\n else:\n result = ary\n res.append(result)\n if len(res) == 1:\n return res[0]\n else:\n return res\n\ndef atleast_2d(*arys):\n \"\"\" Force a sequence of arrays to each be at least 2D.\n\n Description:\n Force an array to each be at least 2D. If the array\n is 0D or 1D, the array is converted to a single\n row of values. Otherwise, the array is unaltered.\n Arguments:\n arys -- arrays to be converted to 2 or more dimensional array.\n Returns:\n input array converted to at least 2D array.\n \"\"\"\n res = []\n for ary in arys:\n ary = asarray(ary)\n if len(ary.shape) == 0: \n ary = Numeric.array([ary[0]])\n if len(ary.shape) == 1: \n result = ary[NewAxis,:]\n else: \n result = ary\n res.append(result)\n if len(res) == 1:\n return res[0]\n else:\n return res\n \ndef atleast_3d(*arys):\n \"\"\" Force a sequence of arrays to each be at least 3D.\n\n Description:\n Force an array each be at least 3D. If the array is 0D or 1D, \n the array is converted to a single 1xNx1 array of values where \n N is the orginal length of the array. If the array is 2D, the \n array is converted to a single MxNx1 array of values where MxN\n is the orginal shape of the array. Otherwise, the array is \n unaltered.\n Arguments:\n arys -- arrays to be converted to 3 or more dimensional array.\n Returns:\n input array converted to at least 3D array.\n \"\"\"\n res = []\n for ary in arys:\n ary = asarray(ary)\n if len(ary.shape) == 0:\n ary = Numeric.array([ary[0]])\n if len(ary.shape) == 1:\n result = ary[NewAxis,:,NewAxis]\n elif len(ary.shape) == 2:\n result = ary[:,:,NewAxis]\n else: \n result = ary\n res.append(result)\n if len(res) == 1:\n return res[0]\n else:\n return res\n\n\ndef vstack(tup):\n \"\"\" Stack arrays in sequence vertically (row wise)\n\n Description:\n Take a sequence of arrays and stack them veritcally\n to make a single array. All arrays in the sequence\n must have the same shape along all but the first axis. \n vstack will rebuild arrays divided by vsplit.\n Arguments:\n tup -- sequence of arrays. All arrays must have the same \n shape.\n Examples:\n >>> import scipy\n >>> a = array((1,2,3))\n >>> b = array((2,3,4))\n >>> scipy.vstack((a,b))\n array([[1, 2, 3],\n [2, 3, 4]])\n >>> a = array([[1],[2],[3]])\n >>> b = array([[2],[3],[4]])\n >>> scipy.vstack((a,b))\n array([[1],\n [2],\n [3],\n [2],\n [3],\n [4]])\n\n \"\"\"\n return Numeric.concatenate(map(atleast_2d,tup),0)\n\ndef hstack(tup):\n \"\"\" Stack arrays in sequence horizontally (column wise)\n\n Description:\n Take a sequence of arrays and stack them horizontally\n to make a single array. All arrays in the sequence\n must have the same shape along all but the second axis.\n hstack will rebuild arrays divided by hsplit.\n Arguments:\n tup -- sequence of arrays. All arrays must have the same \n shape.\n Examples:\n >>> import scipy\n >>> a = array((1,2,3))\n >>> b = array((2,3,4))\n >>> scipy.hstack((a,b))\n array([1, 2, 3, 2, 3, 4])\n >>> a = array([[1],[2],[3]])\n >>> b = array([[2],[3],[4]])\n >>> scipy.hstack((a,b))\n array([[1, 2],\n [2, 3],\n [3, 4]])\n\n \"\"\"\n return Numeric.concatenate(map(atleast_1d,tup),1)\n\ndef column_stack(tup):\n \"\"\" Stack 1D arrays as columns into a 2D array\n\n Description:\n Take a sequence of 1D arrays and stack them as columns\n to make a single 2D array. All arrays in the sequence\n must have the same length.\n Arguments:\n tup -- sequence of 1D arrays. All arrays must have the same \n length.\n Examples:\n >>> import scipy\n >>> a = array((1,2,3))\n >>> b = array((2,3,4))\n >>> scipy.vstack((a,b))\n array([[1, 2],\n [2, 3],\n [3, 4]])\n\n \"\"\"\n arrays = map(Numeric.transpose,map(atleast_2d,tup))\n return Numeric.concatenate(arrays,1)\n \ndef dstack(tup):\n \"\"\" Stack arrays in sequence depth wise (along third dimension)\n\n Description:\n Take a sequence of arrays and stack them along the third axis.\n All arrays in the sequence must have the same shape along all \n but the third axis. This is a simple way to stack 2D arrays \n (images) into a single 3D array for processing.\n dstack will rebuild arrays divided by dsplit.\n Arguments:\n tup -- sequence of arrays. All arrays must have the same \n shape.\n Examples:\n >>> import scipy\n >>> a = array((1,2,3))\n >>> b = array((2,3,4))\n >>> scipy.dstack((a,b))\n array([ [[1, 2],\n [2, 3],\n [3, 4]]])\n >>> a = array([[1],[2],[3]])\n >>> b = array([[2],[3],[4]])\n >>> scipy.dstack((a,b))\n array([[ [1, 2]],\n [ [2, 3]],\n [ [3, 4]]])\n \"\"\"\n return Numeric.concatenate(map(atleast_3d,tup),2)\n\ndef _replace_zero_by_x_arrays(sub_arys):\n for i in range(len(sub_arys)):\n if len(Numeric.shape(sub_arys[i])) == 0:\n sub_arys[i] = Numeric.array([])\n elif Numeric.sometrue(Numeric.equal(Numeric.shape(sub_arys[i]),0)):\n sub_arys[i] = Numeric.array([]) \n return sub_arys\n \ndef array_split(ary,indices_or_sections,axis = 0):\n \"\"\" Divide an array into a list of sub-arrays.\n\n Description:\n Divide ary into a list of sub-arrays along the\n specified axis. If indices_or_sections is an integer,\n ary is divided into that many equally sized arrays.\n If it is impossible to make an equal split, each of the\n leading arrays in the list have one additional member. If\n indices_or_sections is a list of sorted integers, its\n entries define the indexes where ary is split.\n\n Arguments:\n ary -- N-D array.\n Array to be divided into sub-arrays.\n indices_or_sections -- integer or 1D array.\n If integer, defines the number of (close to) equal sized\n sub-arrays. If it is a 1D array of sorted indices, it\n defines the indexes at which ary is divided. Any empty\n list results in a single sub-array equal to the original\n array.\n axis -- integer. default=0.\n Specifies the axis along which to split ary.\n Caveats:\n Currently, the default for axis is 0. This\n means a 2D array is divided into multiple groups\n of rows. This seems like the appropriate default, but\n we've agreed most other functions should default to\n axis=-1. Perhaps we should use axis=-1 for consistency.\n However, we could also make the argument that SciPy\n works on \"rows\" by default. sum() sums up rows of\n values. split() will split data into rows. Opinions?\n \"\"\"\n try:\n Ntotal = ary.shape[axis]\n except AttributeError:\n Ntotal = len(ary)\n try: # handle scalar case.\n Nsections = len(indices_or_sections) + 1\n div_points = [0] + list(indices_or_sections) + [Ntotal]\n except TypeError: #indices_or_sections is a scalar, not an array.\n Nsections = int(indices_or_sections)\n if Nsections <= 0:\n raise ValueError, 'number sections must be larger than 0.'\n Neach_section,extras = divmod(Ntotal,Nsections)\n section_sizes = [0] + \\\n extras * [Neach_section+1] + \\\n (Nsections-extras) * [Neach_section]\n div_points = Numeric.add.accumulate(Numeric.array(section_sizes))\n\n sub_arys = []\n sary = Numeric.swapaxes(ary,axis,0)\n for i in range(Nsections):\n st = div_points[i]; end = div_points[i+1]\n sub_arys.append(Numeric.swapaxes(sary[st:end],axis,0))\n\n # there is a wierd issue with array slicing that allows\n # 0x10 arrays and other such things. The following cluge is needed\n # to get around this issue.\n sub_arys = _replace_zero_by_x_arrays(sub_arys)\n # end cluge.\n\n return sub_arys\n\ndef split(ary,indices_or_sections,axis=0):\n \"\"\" Divide an array into a list of sub-arrays.\n\n Description:\n Divide ary into a list of sub-arrays along the\n specified axis. If indices_or_sections is an integer,\n ary is divided into that many equally sized arrays.\n If it is impossible to make an equal split, an error is \n raised. This is the only way this function differs from\n the array_split() function. If indices_or_sections is a \n list of sorted integers, its entries define the indexes\n where ary is split.\n\n Arguments:\n ary -- N-D array.\n Array to be divided into sub-arrays.\n indices_or_sections -- integer or 1D array.\n If integer, defines the number of (close to) equal sized\n sub-arrays. If it is a 1D array of sorted indices, it\n defines the indexes at which ary is divided. Any empty\n list results in a single sub-array equal to the original\n array.\n axis -- integer. default=0.\n Specifies the axis along which to split ary.\n Caveats:\n Currently, the default for axis is 0. This\n means a 2D array is divided into multiple groups\n of rows. This seems like the appropriate default, but\n we've agreed most other functions should default to\n axis=-1. Perhaps we should use axis=-1 for consistency.\n However, we could also make the argument that SciPy\n works on \"rows\" by default. sum() sums up rows of\n values. split() will split data into rows. Opinions?\n \"\"\"\n try: len(indices_or_sections)\n except TypeError:\n sections = indices_or_sections\n N = ary.shape[axis]\n if N % sections:\n raise ValueError, 'array split does not result in an equal division'\n res = array_split(ary,indices_or_sections,axis)\n return res\n\ndef hsplit(ary,indices_or_sections):\n \"\"\" Split ary into multiple columns of sub-arrays\n\n Description:\n Split a single array into multiple sub arrays. The array is\n divided into groups of columns. If indices_or_sections is\n an integer, ary is divided into that many equally sized sub arrays.\n If it is impossible to make the sub-arrays equally sized, the\n operation throws a ValueError exception. See array_split and\n split for other options on indices_or_sections. \n Arguments:\n ary -- N-D array.\n Array to be divided into sub-arrays.\n indices_or_sections -- integer or 1D array.\n If integer, defines the number of (close to) equal sized\n sub-arrays. If it is a 1D array of sorted indices, it\n defines the indexes at which ary is divided. Any empty\n list results in a single sub-array equal to the original\n array.\n Returns:\n sequence of sub-arrays. The returned arrays have the same \n number of dimensions as the input array.\n Related:\n hstack, split, array_split, vsplit, dsplit. \n Examples:\n >>> import scipy\n >>> a= array((1,2,3,4))\n >>> scipy.hsplit(a,2)\n [array([1, 2]), array([3, 4])]\n >>> a = array([[1,2,3,4],[1,2,3,4]])\n [array([[1, 2],\n [1, 2]]), array([[3, 4],\n [3, 4]])]\n \n \"\"\"\n if len(Numeric.shape(ary)) == 0:\n raise ValueError, 'hsplit only works on arrays of 1 or more dimensions'\n if len(ary.shape) > 1:\n return split(ary,indices_or_sections,1)\n else:\n return split(ary,indices_or_sections,0)\n \ndef vsplit(ary,indices_or_sections):\n \"\"\" Split ary into multiple rows of sub-arrays\n\n Description:\n Split a single array into multiple sub arrays. The array is\n divided into groups of rows. If indices_or_sections is\n an integer, ary is divided into that many equally sized sub arrays.\n If it is impossible to make the sub-arrays equally sized, the\n operation throws a ValueError exception. See array_split and\n split for other options on indices_or_sections.\n Arguments:\n ary -- N-D array.\n Array to be divided into sub-arrays.\n indices_or_sections -- integer or 1D array.\n If integer, defines the number of (close to) equal sized\n sub-arrays. If it is a 1D array of sorted indices, it\n defines the indexes at which ary is divided. Any empty\n list results in a single sub-array equal to the original\n array.\n Returns:\n sequence of sub-arrays. The returned arrays have the same \n number of dimensions as the input array. \n Caveats:\n How should we handle 1D arrays here? I am currently raising\n an error when I encounter them. Any better approach? \n \n Should we reduce the returned array to their minium dimensions\n by getting rid of any dimensions that are 1?\n Related:\n vstack, split, array_split, hsplit, dsplit.\n Examples:\n import scipy\n >>> a = array([[1,2,3,4],\n ... [1,2,3,4]])\n >>> scipy.vsplit(a)\n [array([ [1, 2, 3, 4]]), array([ [1, 2, 3, 4]])]\n \n \"\"\"\n if len(Numeric.shape(ary)) < 2:\n raise ValueError, 'vsplit only works on arrays of 2 or more dimensions'\n return split(ary,indices_or_sections,0)\n\ndef dsplit(ary,indices_or_sections):\n \"\"\" Split ary into multiple sub-arrays along the 3rd axis (depth)\n\n Description:\n Split a single array into multiple sub arrays. The array is\n divided into groups along the 3rd axis. If indices_or_sections is\n an integer, ary is divided into that many equally sized sub arrays.\n If it is impossible to make the sub-arrays equally sized, the\n operation throws a ValueError exception. See array_split and\n split for other options on indices_or_sections. \n Arguments:\n ary -- N-D array.\n Array to be divided into sub-arrays.\n indices_or_sections -- integer or 1D array.\n If integer, defines the number of (close to) equal sized\n sub-arrays. If it is a 1D array of sorted indices, it\n defines the indexes at which ary is divided. Any empty\n list results in a single sub-array equal to the original\n array.\n Returns:\n sequence of sub-arrays. The returned arrays have the same \n number of dimensions as the input array.\n Caveats:\n See vsplit caveats. \n Related:\n dstack, split, array_split, hsplit, vsplit.\n Examples:\n >>> a = array([[[1,2,3,4],[1,2,3,4]]])\n [array([ [[1, 2],\n [1, 2]]]), array([ [[3, 4],\n [3, 4]]])]\n \n \"\"\"\n if len(Numeric.shape(ary)) < 3:\n raise ValueError, 'vsplit only works on arrays of 3 or more dimensions'\n return split(ary,indices_or_sections,2)\n\n", "methods": [ { "name": "put", "long_name": "put( a , ind , v )", "filename": "shape_base.py", "nloc": 6, "complexity": 2, "token_count": 32, "parameters": [ "a", "ind", "v" ], "start_line": 11, "end_line": 17, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 7, "top_nesting_level": 0 }, { "name": "apply_along_axis", "long_name": "apply_along_axis( func1d , axis , arr , * args )", "filename": "shape_base.py", "nloc": 52, "complexity": 10, "token_count": 407, "parameters": [ "func1d", "axis", "arr", "args" ], "start_line": 19, "end_line": 77, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 59, "top_nesting_level": 0 }, { "name": "apply_over_axes", "long_name": "apply_over_axes( func , a , axes )", "filename": "shape_base.py", "nloc": 10, "complexity": 4, "token_count": 75, "parameters": [ "func", "a", "axes" ], "start_line": 80, "end_line": 92, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 13, "top_nesting_level": 0 }, { "name": "expand_dims", "long_name": "expand_dims( a , axis )", "filename": "shape_base.py", "nloc": 7, "complexity": 2, "token_count": 56, "parameters": [ "a", "axis" ], "start_line": 94, "end_line": 102, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 9, "top_nesting_level": 0 }, { "name": "squeeze", "long_name": "squeeze( a )", "filename": "shape_base.py", "nloc": 6, "complexity": 1, "token_count": 43, "parameters": [ "a" ], "start_line": 104, "end_line": 109, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 6, "top_nesting_level": 0 }, { "name": "atleast_1d", "long_name": "atleast_1d( * arys )", "filename": "shape_base.py", "nloc": 11, "complexity": 4, "token_count": 63, "parameters": [ "arys" ], "start_line": 111, "end_line": 132, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 22, "top_nesting_level": 0 }, { "name": "atleast_2d", "long_name": "atleast_2d( * arys )", "filename": "shape_base.py", "nloc": 15, "complexity": 5, "token_count": 86, "parameters": [ "arys" ], "start_line": 134, "end_line": 159, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 26, "top_nesting_level": 0 }, { "name": "atleast_3d", "long_name": "atleast_3d( * arys )", "filename": "shape_base.py", "nloc": 17, "complexity": 6, "token_count": 108, "parameters": [ "arys" ], "start_line": 161, "end_line": 191, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 31, "top_nesting_level": 0 }, { "name": "vstack", "long_name": "vstack( tup )", "filename": "shape_base.py", "nloc": 2, "complexity": 1, "token_count": 20, "parameters": [ "tup" ], "start_line": 194, "end_line": 223, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 30, "top_nesting_level": 0 }, { "name": "hstack", "long_name": "hstack( tup )", "filename": "shape_base.py", "nloc": 2, "complexity": 1, "token_count": 20, "parameters": [ "tup" ], "start_line": 225, "end_line": 250, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 26, "top_nesting_level": 0 }, { "name": "column_stack", "long_name": "column_stack( tup )", "filename": "shape_base.py", "nloc": 3, "complexity": 1, "token_count": 30, "parameters": [ "tup" ], "start_line": 252, "end_line": 273, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 22, "top_nesting_level": 0 }, { "name": "dstack", "long_name": "dstack( tup )", "filename": "shape_base.py", "nloc": 2, "complexity": 1, "token_count": 20, "parameters": [ "tup" ], "start_line": 275, "end_line": 302, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 28, "top_nesting_level": 0 }, { "name": "_replace_zero_by_x_arrays", "long_name": "_replace_zero_by_x_arrays( sub_arys )", "filename": "shape_base.py", "nloc": 7, "complexity": 4, "token_count": 81, "parameters": [ "sub_arys" ], "start_line": 304, "end_line": 310, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 7, "top_nesting_level": 0 }, { "name": "array_split", "long_name": "array_split( ary , indices_or_sections , axis = 0 )", "filename": "shape_base.py", "nloc": 24, "complexity": 5, "token_count": 190, "parameters": [ "ary", "indices_or_sections", "axis" ], "start_line": 312, "end_line": 374, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 63, "top_nesting_level": 0 }, { "name": "split", "long_name": "split( ary , indices_or_sections , axis = 0 )", "filename": "shape_base.py", "nloc": 9, "complexity": 3, "token_count": 53, "parameters": [ "ary", "indices_or_sections", "axis" ], "start_line": 376, "end_line": 417, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 42, "top_nesting_level": 0 }, { "name": "hsplit", "long_name": "hsplit( ary , indices_or_sections )", "filename": "shape_base.py", "nloc": 7, "complexity": 3, "token_count": 55, "parameters": [ "ary", "indices_or_sections" ], "start_line": 419, "end_line": 459, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 41, "top_nesting_level": 0 }, { "name": "vsplit", "long_name": "vsplit( ary , indices_or_sections )", "filename": "shape_base.py", "nloc": 4, "complexity": 2, "token_count": 34, "parameters": [ "ary", "indices_or_sections" ], "start_line": 461, "end_line": 501, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 41, "top_nesting_level": 0 }, { "name": "dsplit", "long_name": "dsplit( ary , indices_or_sections )", "filename": "shape_base.py", "nloc": 4, "complexity": 2, "token_count": 34, "parameters": [ "ary", "indices_or_sections" ], "start_line": 503, "end_line": 538, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 36, "top_nesting_level": 0 } ], "methods_before": [ { "name": "put", "long_name": "put( a , ind , v )", "filename": "shape_base.py", "nloc": 6, "complexity": 2, "token_count": 32, "parameters": [ "a", "ind", "v" ], "start_line": 10, "end_line": 16, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 7, "top_nesting_level": 0 }, { "name": "apply_along_axis", "long_name": "apply_along_axis( func1d , axis , arr , * args )", "filename": "shape_base.py", "nloc": 52, "complexity": 10, "token_count": 392, "parameters": [ "func1d", "axis", "arr", "args" ], "start_line": 18, "end_line": 76, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 59, "top_nesting_level": 0 }, { "name": "apply_over_axes", "long_name": "apply_over_axes( func , a , axes )", "filename": "shape_base.py", "nloc": 10, "complexity": 4, "token_count": 75, "parameters": [ "func", "a", "axes" ], "start_line": 79, "end_line": 91, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 13, "top_nesting_level": 0 }, { "name": "expand_dims", "long_name": "expand_dims( a , axis )", "filename": "shape_base.py", "nloc": 7, "complexity": 2, "token_count": 56, "parameters": [ "a", "axis" ], "start_line": 93, "end_line": 101, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 9, "top_nesting_level": 0 }, { "name": "squeeze", "long_name": "squeeze( a )", "filename": "shape_base.py", "nloc": 6, "complexity": 1, "token_count": 43, "parameters": [ "a" ], "start_line": 103, "end_line": 108, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 6, "top_nesting_level": 0 }, { "name": "atleast_1d", "long_name": "atleast_1d( * arys )", "filename": "shape_base.py", "nloc": 13, "complexity": 4, "token_count": 73, "parameters": [ "arys" ], "start_line": 110, "end_line": 133, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 24, "top_nesting_level": 0 }, { "name": "atleast_2d", "long_name": "atleast_2d( * arys )", "filename": "shape_base.py", "nloc": 15, "complexity": 5, "token_count": 91, "parameters": [ "arys" ], "start_line": 135, "end_line": 160, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 26, "top_nesting_level": 0 }, { "name": "atleast_3d", "long_name": "atleast_3d( * arys )", "filename": "shape_base.py", "nloc": 17, "complexity": 6, "token_count": 113, "parameters": [ "arys" ], "start_line": 162, "end_line": 192, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 31, "top_nesting_level": 0 }, { "name": "vstack", "long_name": "vstack( tup )", "filename": "shape_base.py", "nloc": 2, "complexity": 1, "token_count": 20, "parameters": [ "tup" ], "start_line": 195, "end_line": 224, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 30, "top_nesting_level": 0 }, { "name": "hstack", "long_name": "hstack( tup )", "filename": "shape_base.py", "nloc": 2, "complexity": 1, "token_count": 20, "parameters": [ "tup" ], "start_line": 226, "end_line": 251, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 26, "top_nesting_level": 0 }, { "name": "column_stack", "long_name": "column_stack( tup )", "filename": "shape_base.py", "nloc": 3, "complexity": 1, "token_count": 30, "parameters": [ "tup" ], "start_line": 253, "end_line": 274, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 22, "top_nesting_level": 0 }, { "name": "dstack", "long_name": "dstack( tup )", "filename": "shape_base.py", "nloc": 2, "complexity": 1, "token_count": 20, "parameters": [ "tup" ], "start_line": 276, "end_line": 303, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 28, "top_nesting_level": 0 }, { "name": "_replace_zero_by_x_arrays", "long_name": "_replace_zero_by_x_arrays( sub_arys )", "filename": "shape_base.py", "nloc": 7, "complexity": 4, "token_count": 81, "parameters": [ "sub_arys" ], "start_line": 305, "end_line": 311, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 7, "top_nesting_level": 0 }, { "name": "array_split", "long_name": "array_split( ary , indices_or_sections , axis = 0 )", "filename": "shape_base.py", "nloc": 24, "complexity": 5, "token_count": 190, "parameters": [ "ary", "indices_or_sections", "axis" ], "start_line": 313, "end_line": 375, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 63, "top_nesting_level": 0 }, { "name": "split", "long_name": "split( ary , indices_or_sections , axis = 0 )", "filename": "shape_base.py", "nloc": 9, "complexity": 3, "token_count": 53, "parameters": [ "ary", "indices_or_sections", "axis" ], "start_line": 377, "end_line": 418, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 42, "top_nesting_level": 0 }, { "name": "hsplit", "long_name": "hsplit( ary , indices_or_sections )", "filename": "shape_base.py", "nloc": 7, "complexity": 3, "token_count": 55, "parameters": [ "ary", "indices_or_sections" ], "start_line": 420, "end_line": 460, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 41, "top_nesting_level": 0 }, { "name": "vsplit", "long_name": "vsplit( ary , indices_or_sections )", "filename": "shape_base.py", "nloc": 4, "complexity": 2, "token_count": 34, "parameters": [ "ary", "indices_or_sections" ], "start_line": 462, "end_line": 502, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 41, "top_nesting_level": 0 }, { "name": "dsplit", "long_name": "dsplit( ary , indices_or_sections )", "filename": "shape_base.py", "nloc": 4, "complexity": 2, "token_count": 34, "parameters": [ "ary", "indices_or_sections" ], "start_line": 504, "end_line": 539, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 36, "top_nesting_level": 0 } ], "changed_methods": [ { "name": "vsplit", "long_name": "vsplit( ary , indices_or_sections )", "filename": "shape_base.py", "nloc": 4, "complexity": 2, "token_count": 34, "parameters": [ "ary", "indices_or_sections" ], "start_line": 461, "end_line": 501, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 41, "top_nesting_level": 0 }, { "name": "column_stack", "long_name": "column_stack( tup )", "filename": "shape_base.py", "nloc": 3, "complexity": 1, "token_count": 30, "parameters": [ "tup" ], "start_line": 252, "end_line": 273, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 22, "top_nesting_level": 0 }, { "name": "hstack", "long_name": "hstack( tup )", "filename": "shape_base.py", "nloc": 2, "complexity": 1, "token_count": 20, "parameters": [ "tup" ], "start_line": 225, "end_line": 250, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 26, "top_nesting_level": 0 }, { "name": "apply_along_axis", "long_name": "apply_along_axis( func1d , axis , arr , * args )", "filename": "shape_base.py", "nloc": 52, "complexity": 10, "token_count": 407, "parameters": [ "func1d", "axis", "arr", "args" ], "start_line": 19, "end_line": 77, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 59, "top_nesting_level": 0 }, { "name": "atleast_1d", "long_name": "atleast_1d( * arys )", "filename": "shape_base.py", "nloc": 11, "complexity": 4, "token_count": 63, "parameters": [ "arys" ], "start_line": 111, "end_line": 132, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 22, "top_nesting_level": 0 }, { "name": "dstack", "long_name": "dstack( tup )", "filename": "shape_base.py", "nloc": 2, "complexity": 1, "token_count": 20, "parameters": [ "tup" ], "start_line": 275, "end_line": 302, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 28, "top_nesting_level": 0 }, { "name": "array_split", "long_name": "array_split( ary , indices_or_sections , axis = 0 )", "filename": "shape_base.py", "nloc": 24, "complexity": 5, "token_count": 190, "parameters": [ "ary", "indices_or_sections", "axis" ], "start_line": 312, "end_line": 374, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 63, "top_nesting_level": 0 }, { "name": "hsplit", "long_name": "hsplit( ary , indices_or_sections )", "filename": "shape_base.py", "nloc": 7, "complexity": 3, "token_count": 55, "parameters": [ "ary", "indices_or_sections" ], "start_line": 419, "end_line": 459, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 41, "top_nesting_level": 0 }, { "name": "dsplit", "long_name": "dsplit( ary , indices_or_sections )", "filename": "shape_base.py", "nloc": 4, "complexity": 2, "token_count": 34, "parameters": [ "ary", "indices_or_sections" ], "start_line": 503, "end_line": 538, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 36, "top_nesting_level": 0 }, { "name": "vstack", "long_name": "vstack( tup )", "filename": "shape_base.py", "nloc": 2, "complexity": 1, "token_count": 20, "parameters": [ "tup" ], "start_line": 194, "end_line": 223, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 30, "top_nesting_level": 0 }, { "name": "atleast_2d", "long_name": "atleast_2d( * arys )", "filename": "shape_base.py", "nloc": 15, "complexity": 5, "token_count": 86, "parameters": [ "arys" ], "start_line": 134, "end_line": 159, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 26, "top_nesting_level": 0 }, { "name": "atleast_3d", "long_name": "atleast_3d( * arys )", "filename": "shape_base.py", "nloc": 17, "complexity": 6, "token_count": 108, "parameters": [ "arys" ], "start_line": 161, "end_line": 191, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 31, "top_nesting_level": 0 }, { "name": "_replace_zero_by_x_arrays", "long_name": "_replace_zero_by_x_arrays( sub_arys )", "filename": "shape_base.py", "nloc": 7, "complexity": 4, "token_count": 81, "parameters": [ "sub_arys" ], "start_line": 304, "end_line": 310, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 7, "top_nesting_level": 0 } ], "nloc": 195, "complexity": 57, "token_count": 1474, "diff_parsed": { "added": [ "import numerix as _nx", "from numerix import *", "", " nd = _nx.rank(arr)", " dims = _nx.shape(arr)", " res = func1d(arr[tuple(i)],*args)", " res = func1d(arr[tuple(i)],*args)", " outarr[tuple(i)] = res", " res = func1d(arr[tuple(i)],*args)", " outarr[tuple(i)] = res", " if len(ary.shape) == 0:", " ary.shape = (1,)", " res.append(ary)", " if len(ary.shape) == 0:", " ary.shape = (1,)", " ary.shape = (1,)", " return _nx.concatenate(map(atleast_2d,tup),0)", " return _nx.concatenate(map(atleast_1d,tup),1)", " arrays = map(_nx.transpose,map(atleast_2d,tup))", " return _nx.concatenate(arrays,1)", " return _nx.concatenate(map(atleast_3d,tup),2)", " if len(_nx.shape(sub_arys[i])) == 0:", " sub_arys[i] = _nx.array([])", " elif _nx.sometrue(_nx.equal(_nx.shape(sub_arys[i]),0)):", " sub_arys[i] = _nx.array([])", " div_points = _nx.add.accumulate(_nx.array(section_sizes))", " sary = _nx.swapaxes(ary,axis,0)", " sub_arys.append(_nx.swapaxes(sary[st:end],axis,0))", " if len(_nx.shape(ary)) == 0:", " if len(_nx.shape(ary)) < 2:", " if len(_nx.shape(ary)) < 3:" ], "deleted": [ "import Numeric", "from Numeric import *", " nd = Numeric.rank(arr)", " dims = Numeric.shape(arr)", " res = func1d(arr[i],*args)", " res = func1d(arr[i],*args)", " outarr[i] = res", " res = func1d(arr[i],*args)", " outarr[i] = res", " if len(ary.shape) == 0:", " result = Numeric.array([ary[0]])", " else:", " result = ary", " res.append(result)", " if len(ary.shape) == 0:", " ary = Numeric.array([ary[0]])", " ary = Numeric.array([ary[0]])", " return Numeric.concatenate(map(atleast_2d,tup),0)", " return Numeric.concatenate(map(atleast_1d,tup),1)", " arrays = map(Numeric.transpose,map(atleast_2d,tup))", " return Numeric.concatenate(arrays,1)", " return Numeric.concatenate(map(atleast_3d,tup),2)", " if len(Numeric.shape(sub_arys[i])) == 0:", " sub_arys[i] = Numeric.array([])", " elif Numeric.sometrue(Numeric.equal(Numeric.shape(sub_arys[i]),0)):", " sub_arys[i] = Numeric.array([])", " div_points = Numeric.add.accumulate(Numeric.array(section_sizes))", " sary = Numeric.swapaxes(ary,axis,0)", " sub_arys.append(Numeric.swapaxes(sary[st:end],axis,0))", " if len(Numeric.shape(ary)) == 0:", " if len(Numeric.shape(ary)) < 2:", " if len(Numeric.shape(ary)) < 3:" ] } }, { "old_path": "scipy_base/tests/test_function_base.py", "new_path": "scipy_base/tests/test_function_base.py", "filename": "test_function_base.py", "extension": "py", "change_type": "MODIFY", "diff": "@@ -69,8 +69,9 @@ def check_basic(self):\n b = [[3,6.0, 9.0],\n [4,10.0,5.0],\n [8,3.0,2.0]]\n- assert_equal(amax(b),[8.0,10.0,9.0])\n+ assert_equal(amax(b, axis=0),[8.0,10.0,9.0]) \n assert_equal(amax(b,axis=1),[9.0,10.0,8.0])\n+ assert_equal(amax(b,axis=-1),[9.0,10.0,8.0])\n \n class test_amin(unittest.TestCase):\n def check_basic(self):\n@@ -79,8 +80,9 @@ def check_basic(self):\n b = [[3,6.0, 9.0],\n [4,10.0,5.0],\n [8,3.0,2.0]]\n- assert_equal(amin(b),[3.0,3.0,2.0])\n+ assert_equal(amin(b,axis=0),[3.0,3.0,2.0])\n assert_equal(amin(b,axis=1),[3.0,4.0,2.0])\n+ assert_equal(amin(b),[3.0,4.0,2.0])\n \n class test_ptp(unittest.TestCase):\n def check_basic(self):\n", "added_lines": 4, "deleted_lines": 2, "source_code": "\nimport unittest\n\nimport sys\nfrom scipy_test.testing import *\nset_package_path()\nimport scipy_base;reload(scipy_base)\nfrom scipy_base import *\ndel sys.path[0]\n\nclass test_any(unittest.TestCase):\n def check_basic(self):\n y1 = [0,0,1,0]\n y2 = [0,0,0,0]\n y3 = [1,0,1,0]\n assert(any(y1))\n assert(any(y3))\n assert(not any(y2))\n\n def check_nd(self):\n y1 = [[0,0,0],[0,1,0],[1,1,0]]\n assert(any(y1))\n assert_array_equal(sometrue(y1),[1,1,0])\n assert_array_equal(sometrue(y1,axis=1),[0,1,1])\n \nclass test_all(unittest.TestCase):\n def check_basic(self):\n y1 = [0,1,1,0]\n y2 = [0,0,0,0]\n y3 = [1,1,1,1]\n assert(not all(y1))\n assert(all(y3))\n assert(not all(y2))\n assert(all(~array(y2)))\n\n def check_nd(self):\n y1 = [[0,0,1],[0,1,1],[1,1,1]]\n assert(not all(y1))\n assert_array_equal(alltrue(y1),[0,0,1])\n assert_array_equal(alltrue(y1,axis=1),[0,0,1])\n\nclass test_logspace(unittest.TestCase):\n def check_basic(self):\n y = logspace(0,6)\n assert(len(y)==50)\n y = logspace(0,6,num=100)\n assert(y[-1] == 10**6)\n y = logspace(0,6,endpoint=0)\n assert(y[-1] < 10**6)\n y = logspace(0,6,num=7)\n assert_array_equal(y,[1,10,100,1e3,1e4,1e5,1e6])\n\nclass test_linspace(unittest.TestCase):\n def check_basic(self):\n y = linspace(0,10)\n assert(len(y)==50)\n y = linspace(2,10,num=100)\n assert(y[-1] == 10)\n y = linspace(2,10,endpoint=0)\n assert(y[-1] < 10)\n y,st = linspace(2,10,retstep=1)\n assert_almost_equal(st,8/49.0)\n assert_array_almost_equal(y,mgrid[2:10:50j],13)\n\nclass test_amax(unittest.TestCase):\n def check_basic(self):\n a = [3,4,5,10,-3,-5,6.0]\n assert_equal(amax(a),10.0)\n b = [[3,6.0, 9.0],\n [4,10.0,5.0],\n [8,3.0,2.0]]\n assert_equal(amax(b, axis=0),[8.0,10.0,9.0]) \n assert_equal(amax(b,axis=1),[9.0,10.0,8.0])\n assert_equal(amax(b,axis=-1),[9.0,10.0,8.0])\n \nclass test_amin(unittest.TestCase):\n def check_basic(self):\n a = [3,4,5,10,-3,-5,6.0]\n assert_equal(amin(a),-5.0)\n b = [[3,6.0, 9.0],\n [4,10.0,5.0],\n [8,3.0,2.0]]\n assert_equal(amin(b,axis=0),[3.0,3.0,2.0])\n assert_equal(amin(b,axis=1),[3.0,4.0,2.0])\n assert_equal(amin(b),[3.0,4.0,2.0])\n\nclass test_ptp(unittest.TestCase):\n def check_basic(self):\n a = [3,4,5,10,-3,-5,6.0]\n assert_equal(ptp(a),15.0)\n b = [[3,6.0, 9.0],\n [4,10.0,5.0],\n [8,3.0,2.0]]\n assert_equal(ptp(b,axis=0),[5.0,7.0,7.0])\n assert_equal(ptp(b),[6.0,6.0,6.0])\n\nclass test_cumsum(unittest.TestCase):\n def check_basic(self):\n ba = [1,2,10,11,6,5,4]\n ba2 = [[1,2,3,4],[5,6,7,9],[10,3,4,5]]\n for ctype in ['1','b','s','i','l','f','d','F','D']:\n a = array(ba,ctype)\n a2 = array(ba2,ctype)\n assert_array_equal(cumsum(a), array([1,3,13,24,30,35,39],ctype))\n assert_array_equal(cumsum(a2,axis=0), array([[1,2,3,4],[6,8,10,13],\n [16,11,14,18]],ctype))\n assert_array_equal(cumsum(a2,axis=1),\n array([[1,3,6,10],\n [5,11,18,27],\n [10,13,17,22]],ctype))\n\nclass test_prod(unittest.TestCase):\n def check_basic(self):\n ba = [1,2,10,11,6,5,4]\n ba2 = [[1,2,3,4],[5,6,7,9],[10,3,4,5]]\n for ctype in ['1','b','s','i','l','f','d','F','D']:\n a = array(ba,ctype)\n a2 = array(ba2,ctype)\n if ctype in ['1', 'b']:\n self.failUnlessRaises(ArithmeticError, prod, a)\n self.failUnlessRaises(ArithmeticError, prod, a2, 1)\n self.failUnlessRaises(ArithmeticError, prod, a)\n else: \n assert_equal(prod(a),26400)\n assert_array_equal(prod(a2,axis=0), \n array([50,36,84,180],ctype))\n assert_array_equal(prod(a2),array([24, 1890, 600],ctype))\n\nclass test_cumprod(unittest.TestCase):\n def check_basic(self):\n ba = [1,2,10,11,6,5,4]\n ba2 = [[1,2,3,4],[5,6,7,9],[10,3,4,5]]\n for ctype in ['1','b','s','i','l','f','d','F','D']:\n a = array(ba,ctype)\n a2 = array(ba2,ctype)\n if ctype in ['1', 'b']:\n self.failUnlessRaises(ArithmeticError, cumprod, a)\n self.failUnlessRaises(ArithmeticError, cumprod, a2, 1)\n self.failUnlessRaises(ArithmeticError, cumprod, a)\n else: \n assert_array_equal(cumprod(a),\n array([1, 2, 20, 220,\n 1320, 6600, 26400],ctype))\n assert_array_equal(cumprod(a2,axis=0),\n array([[ 1, 2, 3, 4],\n [ 5, 12, 21, 36],\n [50, 36, 84, 180]],ctype))\n assert_array_equal(cumprod(a2),\n array([[ 1, 2, 6, 24],\n [ 5, 30, 210, 1890],\n [10, 30, 120, 600]],ctype))\n\nclass test_diff(unittest.TestCase):\n def check_basic(self):\n x = [1,4,6,7,12]\n out = array([3,2,1,5])\n out2 = array([-1,-1,4])\n out3 = array([0,5])\n assert_array_equal(diff(x),out)\n assert_array_equal(diff(x,n=2),out2)\n assert_array_equal(diff(x,n=3),out3)\n\n def check_nd(self):\n x = 20*rand(10,20,30)\n out1 = x[:,:,1:] - x[:,:,:-1]\n out2 = out1[:,:,1:] - out1[:,:,:-1]\n out3 = x[1:,:,:] - x[:-1,:,:]\n out4 = out3[1:,:,:] - out3[:-1,:,:]\n assert_array_equal(diff(x),out1)\n assert_array_equal(diff(x,n=2),out2)\n assert_array_equal(diff(x,axis=0),out3)\n assert_array_equal(diff(x,n=2,axis=0),out4)\n\nclass test_angle(unittest.TestCase):\n def check_basic(self):\n x = [1+3j,sqrt(2)/2.0+1j*sqrt(2)/2,1,1j,-1,-1j,1-3j,-1+3j]\n y = angle(x)\n yo = [arctan(3.0/1.0),arctan(1.0),0,pi/2,pi,-pi/2.0,\n -arctan(3.0/1.0),pi-arctan(3.0/1.0)]\n z = angle(x,deg=1)\n zo = array(yo)*180/pi\n assert_array_almost_equal(y,yo,11)\n assert_array_almost_equal(z,zo,11)\n\nclass test_trim_zeros(unittest.TestCase):\n \"\"\" only testing for integer splits.\n \"\"\"\n def check_basic(self):\n a= array([0,0,1,2,3,4,0])\n res = trim_zeros(a)\n assert_array_equal(res,array([1,2,3,4]))\n def check_leading_skip(self):\n a= array([0,0,1,0,2,3,4,0])\n res = trim_zeros(a)\n assert_array_equal(res,array([1,0,2,3,4]))\n def check_trailing_skip(self):\n a= array([0,0,1,0,2,3,0,4,0])\n res = trim_zeros(a)\n assert_array_equal(res,array([1,0,2,3,0,4]))\n\n\nclass test_extins(unittest.TestCase):\n def check_basic(self):\n a = array([1,3,2,1,2,3,3])\n b = extract(a>1,a)\n assert_array_equal(b,[3,2,2,3,3])\n def check_insert(self):\n a = array([1,4,3,2,5,8,7])\n insert(a,[0,1,0,1,0,1,0],[2,4,6])\n assert_array_equal(a,[1,2,3,4,5,6,7])\n def check_both(self):\n a = rand(10)\n mask = a > 0.5\n ac = a.copy()\n c = extract(mask, a)\n insert(a,mask,0)\n insert(a,mask,c)\n assert_array_equal(a,ac)\n \nclass test_vectorize(unittest.TestCase):\n def check_simple(self):\n def addsubtract(a,b):\n if a > b:\n return a - b\n else:\n return a + b\n f = vectorize(addsubtract)\n r = f([0,3,6,9],[1,3,5,7])\n assert_array_equal(r,[1,6,1,2])\n def check_scalar(self):\n def addsubtract(a,b):\n if a > b:\n return a - b\n else:\n return a + b\n f = vectorize(addsubtract)\n r = f([0,3,6,9],5)\n assert_array_equal(r,[5,8,1,4])\n \n\ndef compare_results(res,desired):\n for i in range(len(desired)):\n assert_array_equal(res[i],desired[i])\n\nif __name__ == \"__main__\":\n ScipyTest('scipy_base.function_base').run()\n", "source_code_before": "\nimport unittest\n\nimport sys\nfrom scipy_test.testing import *\nset_package_path()\nimport scipy_base;reload(scipy_base)\nfrom scipy_base import *\ndel sys.path[0]\n\nclass test_any(unittest.TestCase):\n def check_basic(self):\n y1 = [0,0,1,0]\n y2 = [0,0,0,0]\n y3 = [1,0,1,0]\n assert(any(y1))\n assert(any(y3))\n assert(not any(y2))\n\n def check_nd(self):\n y1 = [[0,0,0],[0,1,0],[1,1,0]]\n assert(any(y1))\n assert_array_equal(sometrue(y1),[1,1,0])\n assert_array_equal(sometrue(y1,axis=1),[0,1,1])\n \nclass test_all(unittest.TestCase):\n def check_basic(self):\n y1 = [0,1,1,0]\n y2 = [0,0,0,0]\n y3 = [1,1,1,1]\n assert(not all(y1))\n assert(all(y3))\n assert(not all(y2))\n assert(all(~array(y2)))\n\n def check_nd(self):\n y1 = [[0,0,1],[0,1,1],[1,1,1]]\n assert(not all(y1))\n assert_array_equal(alltrue(y1),[0,0,1])\n assert_array_equal(alltrue(y1,axis=1),[0,0,1])\n\nclass test_logspace(unittest.TestCase):\n def check_basic(self):\n y = logspace(0,6)\n assert(len(y)==50)\n y = logspace(0,6,num=100)\n assert(y[-1] == 10**6)\n y = logspace(0,6,endpoint=0)\n assert(y[-1] < 10**6)\n y = logspace(0,6,num=7)\n assert_array_equal(y,[1,10,100,1e3,1e4,1e5,1e6])\n\nclass test_linspace(unittest.TestCase):\n def check_basic(self):\n y = linspace(0,10)\n assert(len(y)==50)\n y = linspace(2,10,num=100)\n assert(y[-1] == 10)\n y = linspace(2,10,endpoint=0)\n assert(y[-1] < 10)\n y,st = linspace(2,10,retstep=1)\n assert_almost_equal(st,8/49.0)\n assert_array_almost_equal(y,mgrid[2:10:50j],13)\n\nclass test_amax(unittest.TestCase):\n def check_basic(self):\n a = [3,4,5,10,-3,-5,6.0]\n assert_equal(amax(a),10.0)\n b = [[3,6.0, 9.0],\n [4,10.0,5.0],\n [8,3.0,2.0]]\n assert_equal(amax(b),[8.0,10.0,9.0])\n assert_equal(amax(b,axis=1),[9.0,10.0,8.0])\n \nclass test_amin(unittest.TestCase):\n def check_basic(self):\n a = [3,4,5,10,-3,-5,6.0]\n assert_equal(amin(a),-5.0)\n b = [[3,6.0, 9.0],\n [4,10.0,5.0],\n [8,3.0,2.0]]\n assert_equal(amin(b),[3.0,3.0,2.0])\n assert_equal(amin(b,axis=1),[3.0,4.0,2.0])\n\nclass test_ptp(unittest.TestCase):\n def check_basic(self):\n a = [3,4,5,10,-3,-5,6.0]\n assert_equal(ptp(a),15.0)\n b = [[3,6.0, 9.0],\n [4,10.0,5.0],\n [8,3.0,2.0]]\n assert_equal(ptp(b,axis=0),[5.0,7.0,7.0])\n assert_equal(ptp(b),[6.0,6.0,6.0])\n\nclass test_cumsum(unittest.TestCase):\n def check_basic(self):\n ba = [1,2,10,11,6,5,4]\n ba2 = [[1,2,3,4],[5,6,7,9],[10,3,4,5]]\n for ctype in ['1','b','s','i','l','f','d','F','D']:\n a = array(ba,ctype)\n a2 = array(ba2,ctype)\n assert_array_equal(cumsum(a), array([1,3,13,24,30,35,39],ctype))\n assert_array_equal(cumsum(a2,axis=0), array([[1,2,3,4],[6,8,10,13],\n [16,11,14,18]],ctype))\n assert_array_equal(cumsum(a2,axis=1),\n array([[1,3,6,10],\n [5,11,18,27],\n [10,13,17,22]],ctype))\n\nclass test_prod(unittest.TestCase):\n def check_basic(self):\n ba = [1,2,10,11,6,5,4]\n ba2 = [[1,2,3,4],[5,6,7,9],[10,3,4,5]]\n for ctype in ['1','b','s','i','l','f','d','F','D']:\n a = array(ba,ctype)\n a2 = array(ba2,ctype)\n if ctype in ['1', 'b']:\n self.failUnlessRaises(ArithmeticError, prod, a)\n self.failUnlessRaises(ArithmeticError, prod, a2, 1)\n self.failUnlessRaises(ArithmeticError, prod, a)\n else: \n assert_equal(prod(a),26400)\n assert_array_equal(prod(a2,axis=0), \n array([50,36,84,180],ctype))\n assert_array_equal(prod(a2),array([24, 1890, 600],ctype))\n\nclass test_cumprod(unittest.TestCase):\n def check_basic(self):\n ba = [1,2,10,11,6,5,4]\n ba2 = [[1,2,3,4],[5,6,7,9],[10,3,4,5]]\n for ctype in ['1','b','s','i','l','f','d','F','D']:\n a = array(ba,ctype)\n a2 = array(ba2,ctype)\n if ctype in ['1', 'b']:\n self.failUnlessRaises(ArithmeticError, cumprod, a)\n self.failUnlessRaises(ArithmeticError, cumprod, a2, 1)\n self.failUnlessRaises(ArithmeticError, cumprod, a)\n else: \n assert_array_equal(cumprod(a),\n array([1, 2, 20, 220,\n 1320, 6600, 26400],ctype))\n assert_array_equal(cumprod(a2,axis=0),\n array([[ 1, 2, 3, 4],\n [ 5, 12, 21, 36],\n [50, 36, 84, 180]],ctype))\n assert_array_equal(cumprod(a2),\n array([[ 1, 2, 6, 24],\n [ 5, 30, 210, 1890],\n [10, 30, 120, 600]],ctype))\n\nclass test_diff(unittest.TestCase):\n def check_basic(self):\n x = [1,4,6,7,12]\n out = array([3,2,1,5])\n out2 = array([-1,-1,4])\n out3 = array([0,5])\n assert_array_equal(diff(x),out)\n assert_array_equal(diff(x,n=2),out2)\n assert_array_equal(diff(x,n=3),out3)\n\n def check_nd(self):\n x = 20*rand(10,20,30)\n out1 = x[:,:,1:] - x[:,:,:-1]\n out2 = out1[:,:,1:] - out1[:,:,:-1]\n out3 = x[1:,:,:] - x[:-1,:,:]\n out4 = out3[1:,:,:] - out3[:-1,:,:]\n assert_array_equal(diff(x),out1)\n assert_array_equal(diff(x,n=2),out2)\n assert_array_equal(diff(x,axis=0),out3)\n assert_array_equal(diff(x,n=2,axis=0),out4)\n\nclass test_angle(unittest.TestCase):\n def check_basic(self):\n x = [1+3j,sqrt(2)/2.0+1j*sqrt(2)/2,1,1j,-1,-1j,1-3j,-1+3j]\n y = angle(x)\n yo = [arctan(3.0/1.0),arctan(1.0),0,pi/2,pi,-pi/2.0,\n -arctan(3.0/1.0),pi-arctan(3.0/1.0)]\n z = angle(x,deg=1)\n zo = array(yo)*180/pi\n assert_array_almost_equal(y,yo,11)\n assert_array_almost_equal(z,zo,11)\n\nclass test_trim_zeros(unittest.TestCase):\n \"\"\" only testing for integer splits.\n \"\"\"\n def check_basic(self):\n a= array([0,0,1,2,3,4,0])\n res = trim_zeros(a)\n assert_array_equal(res,array([1,2,3,4]))\n def check_leading_skip(self):\n a= array([0,0,1,0,2,3,4,0])\n res = trim_zeros(a)\n assert_array_equal(res,array([1,0,2,3,4]))\n def check_trailing_skip(self):\n a= array([0,0,1,0,2,3,0,4,0])\n res = trim_zeros(a)\n assert_array_equal(res,array([1,0,2,3,0,4]))\n\n\nclass test_extins(unittest.TestCase):\n def check_basic(self):\n a = array([1,3,2,1,2,3,3])\n b = extract(a>1,a)\n assert_array_equal(b,[3,2,2,3,3])\n def check_insert(self):\n a = array([1,4,3,2,5,8,7])\n insert(a,[0,1,0,1,0,1,0],[2,4,6])\n assert_array_equal(a,[1,2,3,4,5,6,7])\n def check_both(self):\n a = rand(10)\n mask = a > 0.5\n ac = a.copy()\n c = extract(mask, a)\n insert(a,mask,0)\n insert(a,mask,c)\n assert_array_equal(a,ac)\n \nclass test_vectorize(unittest.TestCase):\n def check_simple(self):\n def addsubtract(a,b):\n if a > b:\n return a - b\n else:\n return a + b\n f = vectorize(addsubtract)\n r = f([0,3,6,9],[1,3,5,7])\n assert_array_equal(r,[1,6,1,2])\n def check_scalar(self):\n def addsubtract(a,b):\n if a > b:\n return a - b\n else:\n return a + b\n f = vectorize(addsubtract)\n r = f([0,3,6,9],5)\n assert_array_equal(r,[5,8,1,4])\n \n\ndef compare_results(res,desired):\n for i in range(len(desired)):\n assert_array_equal(res[i],desired[i])\n\nif __name__ == \"__main__\":\n ScipyTest('scipy_base.function_base').run()\n", "methods": [ { "name": "check_basic", "long_name": "check_basic( self )", "filename": "test_function_base.py", "nloc": 7, "complexity": 1, "token_count": 60, "parameters": [ "self" ], "start_line": 12, "end_line": 18, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 7, "top_nesting_level": 1 }, { "name": "check_nd", "long_name": "check_nd( self )", "filename": "test_function_base.py", "nloc": 5, "complexity": 1, "token_count": 73, "parameters": [ "self" ], "start_line": 20, "end_line": 24, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 5, "top_nesting_level": 1 }, { "name": "check_basic", "long_name": "check_basic( self )", "filename": "test_function_base.py", "nloc": 8, "complexity": 1, "token_count": 72, "parameters": [ "self" ], "start_line": 27, "end_line": 34, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 8, "top_nesting_level": 1 }, { "name": "check_nd", "long_name": "check_nd( self )", "filename": "test_function_base.py", "nloc": 5, "complexity": 1, "token_count": 74, "parameters": [ "self" ], "start_line": 36, "end_line": 40, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 5, "top_nesting_level": 1 }, { "name": "check_basic", "long_name": "check_basic( self )", "filename": "test_function_base.py", "nloc": 9, "complexity": 1, "token_count": 102, "parameters": [ "self" ], "start_line": 43, "end_line": 51, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 9, "top_nesting_level": 1 }, { "name": "check_basic", "long_name": "check_basic( self )", "filename": "test_function_base.py", "nloc": 10, "complexity": 1, "token_count": 105, "parameters": [ "self" ], "start_line": 54, "end_line": 63, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 10, "top_nesting_level": 1 }, { "name": "check_basic", "long_name": "check_basic( self )", "filename": "test_function_base.py", "nloc": 9, "complexity": 1, "token_count": 152, "parameters": [ "self" ], "start_line": 66, "end_line": 74, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 9, "top_nesting_level": 1 }, { "name": "check_basic", "long_name": "check_basic( self )", "filename": "test_function_base.py", "nloc": 9, "complexity": 1, "token_count": 148, "parameters": [ "self" ], "start_line": 77, "end_line": 85, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 9, "top_nesting_level": 1 }, { "name": "check_basic", "long_name": "check_basic( self )", "filename": "test_function_base.py", "nloc": 8, "complexity": 1, "token_count": 122, "parameters": [ "self" ], "start_line": 88, "end_line": 95, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 8, "top_nesting_level": 1 }, { "name": "check_basic", "long_name": "check_basic( self )", "filename": "test_function_base.py", "nloc": 13, "complexity": 2, "token_count": 218, "parameters": [ "self" ], "start_line": 98, "end_line": 110, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 13, "top_nesting_level": 1 }, { "name": "check_basic", "long_name": "check_basic( self )", "filename": "test_function_base.py", "nloc": 15, "complexity": 3, "token_count": 192, "parameters": [ "self" ], "start_line": 113, "end_line": 127, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 15, "top_nesting_level": 1 }, { "name": "check_basic", "long_name": "check_basic( self )", "filename": "test_function_base.py", "nloc": 22, "complexity": 3, "token_count": 257, "parameters": [ "self" ], "start_line": 130, "end_line": 151, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 22, "top_nesting_level": 1 }, { "name": "check_basic", "long_name": "check_basic( self )", "filename": "test_function_base.py", "nloc": 8, "complexity": 1, "token_count": 91, "parameters": [ "self" ], "start_line": 154, "end_line": 161, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 8, "top_nesting_level": 1 }, { "name": "check_nd", "long_name": "check_nd( self )", "filename": "test_function_base.py", "nloc": 10, "complexity": 1, "token_count": 157, "parameters": [ "self" ], "start_line": 163, "end_line": 172, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 10, "top_nesting_level": 1 }, { "name": "check_basic", "long_name": "check_basic( self )", "filename": "test_function_base.py", "nloc": 9, "complexity": 1, "token_count": 152, "parameters": [ "self" ], "start_line": 175, "end_line": 183, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 9, "top_nesting_level": 1 }, { "name": "check_basic", "long_name": "check_basic( self )", "filename": "test_function_base.py", "nloc": 4, "complexity": 1, "token_count": 48, "parameters": [ "self" ], "start_line": 188, "end_line": 191, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 4, "top_nesting_level": 1 }, { "name": "check_leading_skip", "long_name": "check_leading_skip( self )", "filename": "test_function_base.py", "nloc": 4, "complexity": 1, "token_count": 52, "parameters": [ "self" ], "start_line": 192, "end_line": 195, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 4, "top_nesting_level": 1 }, { "name": "check_trailing_skip", "long_name": "check_trailing_skip( self )", "filename": "test_function_base.py", "nloc": 4, "complexity": 1, "token_count": 56, "parameters": [ "self" ], "start_line": 196, "end_line": 199, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 4, "top_nesting_level": 1 }, { "name": "check_basic", "long_name": "check_basic( self )", "filename": "test_function_base.py", "nloc": 4, "complexity": 1, "token_count": 51, "parameters": [ "self" ], "start_line": 203, "end_line": 206, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 4, "top_nesting_level": 1 }, { "name": "check_insert", "long_name": "check_insert( self )", "filename": "test_function_base.py", "nloc": 4, "complexity": 1, "token_count": 73, "parameters": [ "self" ], "start_line": 207, "end_line": 210, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 4, "top_nesting_level": 1 }, { "name": "check_both", "long_name": "check_both( self )", "filename": "test_function_base.py", "nloc": 8, "complexity": 1, "token_count": 55, "parameters": [ "self" ], "start_line": 211, "end_line": 218, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 8, "top_nesting_level": 1 }, { "name": "check_simple.addsubtract", "long_name": "check_simple.addsubtract( a , b )", "filename": "test_function_base.py", "nloc": 5, "complexity": 2, "token_count": 22, "parameters": [ "a", "b" ], "start_line": 222, "end_line": 226, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 5, "top_nesting_level": 2 }, { "name": "check_simple", "long_name": "check_simple( self )", "filename": "test_function_base.py", "nloc": 5, "complexity": 1, "token_count": 51, "parameters": [ "self" ], "start_line": 221, "end_line": 229, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 9, "top_nesting_level": 1 }, { "name": "check_scalar.addsubtract", "long_name": "check_scalar.addsubtract( a , b )", "filename": "test_function_base.py", "nloc": 5, "complexity": 2, "token_count": 22, "parameters": [ "a", "b" ], "start_line": 231, "end_line": 235, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 5, "top_nesting_level": 2 }, { "name": "check_scalar", "long_name": "check_scalar( self )", "filename": "test_function_base.py", "nloc": 5, "complexity": 1, "token_count": 43, "parameters": [ "self" ], "start_line": 230, "end_line": 238, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 9, "top_nesting_level": 1 }, { "name": "compare_results", "long_name": "compare_results( res , desired )", "filename": "test_function_base.py", "nloc": 3, "complexity": 2, "token_count": 30, "parameters": [ "res", "desired" ], "start_line": 241, "end_line": 243, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 3, "top_nesting_level": 0 } ], "methods_before": [ { "name": "check_basic", "long_name": "check_basic( self )", "filename": "test_function_base.py", "nloc": 7, "complexity": 1, "token_count": 60, "parameters": [ "self" ], "start_line": 12, "end_line": 18, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 7, "top_nesting_level": 1 }, { "name": "check_nd", "long_name": "check_nd( self )", "filename": "test_function_base.py", "nloc": 5, "complexity": 1, "token_count": 73, "parameters": [ "self" ], "start_line": 20, "end_line": 24, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 5, "top_nesting_level": 1 }, { "name": "check_basic", "long_name": "check_basic( self )", "filename": "test_function_base.py", "nloc": 8, "complexity": 1, "token_count": 72, "parameters": [ "self" ], "start_line": 27, "end_line": 34, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 8, "top_nesting_level": 1 }, { "name": "check_nd", "long_name": "check_nd( self )", "filename": "test_function_base.py", "nloc": 5, "complexity": 1, "token_count": 74, "parameters": [ "self" ], "start_line": 36, "end_line": 40, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 5, "top_nesting_level": 1 }, { "name": "check_basic", "long_name": "check_basic( self )", "filename": "test_function_base.py", "nloc": 9, "complexity": 1, "token_count": 102, "parameters": [ "self" ], "start_line": 43, "end_line": 51, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 9, "top_nesting_level": 1 }, { "name": "check_basic", "long_name": "check_basic( self )", "filename": "test_function_base.py", "nloc": 10, "complexity": 1, "token_count": 105, "parameters": [ "self" ], "start_line": 54, "end_line": 63, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 10, "top_nesting_level": 1 }, { "name": "check_basic", "long_name": "check_basic( self )", "filename": "test_function_base.py", "nloc": 8, "complexity": 1, "token_count": 122, "parameters": [ "self" ], "start_line": 66, "end_line": 73, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 8, "top_nesting_level": 1 }, { "name": "check_basic", "long_name": "check_basic( self )", "filename": "test_function_base.py", "nloc": 8, "complexity": 1, "token_count": 123, "parameters": [ "self" ], "start_line": 76, "end_line": 83, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 8, "top_nesting_level": 1 }, { "name": "check_basic", "long_name": "check_basic( self )", "filename": "test_function_base.py", "nloc": 8, "complexity": 1, "token_count": 122, "parameters": [ "self" ], "start_line": 86, "end_line": 93, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 8, "top_nesting_level": 1 }, { "name": "check_basic", "long_name": "check_basic( self )", "filename": "test_function_base.py", "nloc": 13, "complexity": 2, "token_count": 218, "parameters": [ "self" ], "start_line": 96, "end_line": 108, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 13, "top_nesting_level": 1 }, { "name": "check_basic", "long_name": "check_basic( self )", "filename": "test_function_base.py", "nloc": 15, "complexity": 3, "token_count": 192, "parameters": [ "self" ], "start_line": 111, "end_line": 125, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 15, "top_nesting_level": 1 }, { "name": "check_basic", "long_name": "check_basic( self )", "filename": "test_function_base.py", "nloc": 22, "complexity": 3, "token_count": 257, "parameters": [ "self" ], "start_line": 128, "end_line": 149, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 22, "top_nesting_level": 1 }, { "name": "check_basic", "long_name": "check_basic( self )", "filename": "test_function_base.py", "nloc": 8, "complexity": 1, "token_count": 91, "parameters": [ "self" ], "start_line": 152, "end_line": 159, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 8, "top_nesting_level": 1 }, { "name": "check_nd", "long_name": "check_nd( self )", "filename": "test_function_base.py", "nloc": 10, "complexity": 1, "token_count": 157, "parameters": [ "self" ], "start_line": 161, "end_line": 170, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 10, "top_nesting_level": 1 }, { "name": "check_basic", "long_name": "check_basic( self )", "filename": "test_function_base.py", "nloc": 9, "complexity": 1, "token_count": 152, "parameters": [ "self" ], "start_line": 173, "end_line": 181, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 9, "top_nesting_level": 1 }, { "name": "check_basic", "long_name": "check_basic( self )", "filename": "test_function_base.py", "nloc": 4, "complexity": 1, "token_count": 48, "parameters": [ "self" ], "start_line": 186, "end_line": 189, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 4, "top_nesting_level": 1 }, { "name": "check_leading_skip", "long_name": "check_leading_skip( self )", "filename": "test_function_base.py", "nloc": 4, "complexity": 1, "token_count": 52, "parameters": [ "self" ], "start_line": 190, "end_line": 193, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 4, "top_nesting_level": 1 }, { "name": "check_trailing_skip", "long_name": "check_trailing_skip( self )", "filename": "test_function_base.py", "nloc": 4, "complexity": 1, "token_count": 56, "parameters": [ "self" ], "start_line": 194, "end_line": 197, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 4, "top_nesting_level": 1 }, { "name": "check_basic", "long_name": "check_basic( self )", "filename": "test_function_base.py", "nloc": 4, "complexity": 1, "token_count": 51, "parameters": [ "self" ], "start_line": 201, "end_line": 204, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 4, "top_nesting_level": 1 }, { "name": "check_insert", "long_name": "check_insert( self )", "filename": "test_function_base.py", "nloc": 4, "complexity": 1, "token_count": 73, "parameters": [ "self" ], "start_line": 205, "end_line": 208, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 4, "top_nesting_level": 1 }, { "name": "check_both", "long_name": "check_both( self )", "filename": "test_function_base.py", "nloc": 8, "complexity": 1, "token_count": 55, "parameters": [ "self" ], "start_line": 209, "end_line": 216, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 8, "top_nesting_level": 1 }, { "name": "check_simple.addsubtract", "long_name": "check_simple.addsubtract( a , b )", "filename": "test_function_base.py", "nloc": 5, "complexity": 2, "token_count": 22, "parameters": [ "a", "b" ], "start_line": 220, "end_line": 224, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 5, "top_nesting_level": 2 }, { "name": "check_simple", "long_name": "check_simple( self )", "filename": "test_function_base.py", "nloc": 5, "complexity": 1, "token_count": 51, "parameters": [ "self" ], "start_line": 219, "end_line": 227, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 9, "top_nesting_level": 1 }, { "name": "check_scalar.addsubtract", "long_name": "check_scalar.addsubtract( a , b )", "filename": "test_function_base.py", "nloc": 5, "complexity": 2, "token_count": 22, "parameters": [ "a", "b" ], "start_line": 229, "end_line": 233, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 5, "top_nesting_level": 2 }, { "name": "check_scalar", "long_name": "check_scalar( self )", "filename": "test_function_base.py", "nloc": 5, "complexity": 1, "token_count": 43, "parameters": [ "self" ], "start_line": 228, "end_line": 236, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 9, "top_nesting_level": 1 }, { "name": "compare_results", "long_name": "compare_results( res , desired )", "filename": "test_function_base.py", "nloc": 3, "complexity": 2, "token_count": 30, "parameters": [ "res", "desired" ], "start_line": 239, "end_line": 241, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 3, "top_nesting_level": 0 } ], "changed_methods": [ { "name": "check_basic", "long_name": "check_basic( self )", "filename": "test_function_base.py", "nloc": 9, "complexity": 1, "token_count": 152, "parameters": [ "self" ], "start_line": 66, "end_line": 74, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 9, "top_nesting_level": 1 } ], "nloc": 222, "complexity": 34, "token_count": 2665, "diff_parsed": { "added": [ " assert_equal(amax(b, axis=0),[8.0,10.0,9.0])", " assert_equal(amax(b,axis=-1),[9.0,10.0,8.0])", " assert_equal(amin(b,axis=0),[3.0,3.0,2.0])", " assert_equal(amin(b),[3.0,4.0,2.0])" ], "deleted": [ " assert_equal(amax(b),[8.0,10.0,9.0])", " assert_equal(amin(b),[3.0,3.0,2.0])" ] } }, { "old_path": "scipy_base/tests/test_type_check.py", "new_path": "scipy_base/tests/test_type_check.py", "filename": "test_type_check.py", "extension": "py", "change_type": "MODIFY", "diff": "@@ -7,6 +7,9 @@\n from scipy_base import *\n del sys.path[0]\n \n+def assert_all(x):\n+ assert(all(x)), x\n+ \n class test_mintypecode(ScipyTestCase):\n \n def check_default_1(self):\n@@ -121,60 +124,60 @@ class test_isnan(unittest.TestCase):\n def check_goodvalues(self):\n z = array((-1.,0.,1.))\n res = isnan(z) == 0\n- assert(alltrue(res)) \n+ assert_all(alltrue(res)) \n def check_posinf(self): \n- assert(isnan(array((1.,))/0.) == 0)\n+ assert_all(isnan(array((1.,))/0.) == 0)\n def check_neginf(self): \n- assert(isnan(array((-1.,))/0.) == 0)\n+ assert_all(isnan(array((-1.,))/0.) == 0)\n def check_ind(self): \n- assert(isnan(array((0.,))/0.) == 1)\n+ assert_all(isnan(array((0.,))/0.) == 1)\n #def check_qnan(self): log(-1) return pi*j now\n- # assert(isnan(log(-1.)) == 1)\n+ # assert_all(isnan(log(-1.)) == 1)\n def check_integer(self):\n- assert(isnan(1) == 0)\n+ assert_all(isnan(1) == 0)\n def check_complex(self):\n- assert(isnan(1+1j) == 0)\n+ assert_all(isnan(1+1j) == 0)\n def check_complex1(self):\n- assert(isnan(array(0+0j)/0.) == 1)\n+ assert_all(isnan(array(0+0j)/0.) == 1)\n \n class test_isfinite(unittest.TestCase):\n def check_goodvalues(self):\n z = array((-1.,0.,1.))\n res = isfinite(z) == 1\n- assert(alltrue(res)) \n+ assert_all(alltrue(res)) \n def check_posinf(self): \n- assert(isfinite(array((1.,))/0.) == 0)\n+ assert_all(isfinite(array((1.,))/0.) == 0)\n def check_neginf(self): \n- assert(isfinite(array((-1.,))/0.) == 0)\n+ assert_all(isfinite(array((-1.,))/0.) == 0)\n def check_ind(self): \n- assert(isfinite(array((0.,))/0.) == 0)\n+ assert_all(isfinite(array((0.,))/0.) == 0)\n #def check_qnan(self): \n- # assert(isfinite(log(-1.)) == 0)\n+ # assert_all(isfinite(log(-1.)) == 0)\n def check_integer(self):\n- assert(isfinite(1) == 1)\n+ assert_all(isfinite(1) == 1)\n def check_complex(self):\n- assert(isfinite(1+1j) == 1)\n+ assert_all(isfinite(1+1j) == 1)\n def check_complex1(self):\n- assert(isfinite(array(1+1j)/0.) == 0)\n+ assert_all(isfinite(array(1+1j)/0.) == 0)\n \n class test_isinf(unittest.TestCase):\n def check_goodvalues(self):\n z = array((-1.,0.,1.))\n res = isinf(z) == 0\n- assert(alltrue(res)) \n+ assert_all(alltrue(res)) \n def check_posinf(self): \n- assert(isinf(array((1.,))/0.) == 1)\n+ assert_all(isinf(array((1.,))/0.) == 1)\n def check_posinf_scalar(self): \n- assert(isinf(array(1.,)/0.) == 1)\n+ assert_all(isinf(array(1.,)/0.) == 1)\n def check_neginf(self): \n- assert(isinf(array((-1.,))/0.) == 1)\n+ assert_all(isinf(array((-1.,))/0.) == 1)\n def check_neginf_scalar(self): \n- assert(isinf(array(-1.)/0.) == 1)\n+ assert_all(isinf(array(-1.)/0.) == 1)\n def check_ind(self): \n- assert(isinf(array((0.,))/0.) == 0)\n+ assert_all(isinf(array((0.,))/0.) == 0)\n #def check_qnan(self): \n- # assert(isinf(log(-1.)) == 0)\n- # assert(isnan(log(-1.)) == 1)\n+ # assert_all(isinf(log(-1.)) == 0)\n+ # assert_all(isnan(log(-1.)) == 1)\n \n class test_isposinf(unittest.TestCase):\n def check_generic(self):\n@@ -193,43 +196,43 @@ def check_generic(self):\n class test_nan_to_num(unittest.TestCase):\n def check_generic(self):\n vals = nan_to_num(array((-1.,0,1))/0.)\n- assert(vals[0] < -1e10 and isfinite(vals[0]))\n+ assert_all(vals[0] < -1e10) and assert_all(isfinite(vals[0]))\n assert(vals[1] == 0)\n- assert(vals[2] > 1e10 and isfinite(vals[2]))\n+ assert_all(vals[2] > 1e10) and assert_all(isfinite(vals[2]))\n def check_integer(self):\n vals = nan_to_num(1)\n- assert(vals == 1)\n+ assert_all(vals == 1)\n def check_complex_good(self):\n vals = nan_to_num(1+1j)\n- assert(vals == 1+1j)\n+ assert_all(vals == 1+1j)\n def check_complex_bad(self):\n v = 1+1j\n v += array(0+1.j)/0.\n vals = nan_to_num(v)\n # !! This is actually (unexpectedly) zero\n- assert(vals.imag > 1e10 and isfinite(vals))\n+ assert_all(vals.imag > 1e10) and assert_all(isfinite(vals))\n def check_complex_bad2(self):\n v = 1+1j\n v += array(-1+1.j)/0.\n vals = nan_to_num(v)\n- assert(isfinite(vals)) \n- #assert(vals.imag > 1e10 and isfinite(vals)) \n+ assert_all(isfinite(vals)) \n+ #assert_all(vals.imag > 1e10) and assert_all(isfinite(vals)) \n # !! This is actually (unexpectedly) positive\n # !! inf. Comment out for now, and see if it\n # !! changes\n- #assert(vals.real < -1e10 and isfinite(vals)) \n+ #assert_all(vals.real < -1e10) and assert_all(isfinite(vals)) \n \n \n class test_real_if_close(unittest.TestCase):\n def check_basic(self):\n a = rand(10)\n b = real_if_close(a+1e-15j)\n- assert(isrealobj(b))\n+ assert_all(isrealobj(b))\n assert_array_equal(a,b)\n b = real_if_close(a+1e-7j)\n- assert(iscomplexobj(b))\n+ assert_all(iscomplexobj(b))\n b = real_if_close(a+1e-7j,tol=1e-6)\n- assert(isrealobj(b))\n+ assert_all(isrealobj(b))\n \n if __name__ == \"__main__\":\n ScipyTest('scipy_base.type_check').run()\n", "added_lines": 38, "deleted_lines": 35, "source_code": "\nimport unittest\nimport sys\nfrom scipy_test.testing import *\nset_package_path()\nimport scipy_base;reload(scipy_base);reload(scipy_base.type_check)\nfrom scipy_base import *\ndel sys.path[0]\n\ndef assert_all(x):\n assert(all(x)), x\n \nclass test_mintypecode(ScipyTestCase):\n\n def check_default_1(self):\n for itype in '1bcsuwil':\n assert_equal(mintypecode(itype),'d')\n assert_equal(mintypecode('f'),'f')\n assert_equal(mintypecode('d'),'d')\n assert_equal(mintypecode('F'),'F')\n assert_equal(mintypecode('D'),'D')\n\n def check_default_2(self):\n for itype in '1bcsuwil':\n assert_equal(mintypecode(itype+'f'),'f')\n assert_equal(mintypecode(itype+'d'),'d')\n assert_equal(mintypecode(itype+'F'),'F')\n assert_equal(mintypecode(itype+'D'),'D')\n assert_equal(mintypecode('ff'),'f')\n assert_equal(mintypecode('fd'),'d')\n assert_equal(mintypecode('fF'),'F')\n assert_equal(mintypecode('fD'),'D')\n assert_equal(mintypecode('df'),'d')\n assert_equal(mintypecode('dd'),'d')\n assert_equal(mintypecode('dF',savespace=1),'F')\n assert_equal(mintypecode('dF'),'D')\n assert_equal(mintypecode('dD'),'D')\n assert_equal(mintypecode('Ff'),'F')\n assert_equal(mintypecode('Fd',savespace=1),'F')\n assert_equal(mintypecode('Fd'),'D')\n assert_equal(mintypecode('FF'),'F')\n assert_equal(mintypecode('FD'),'D')\n assert_equal(mintypecode('Df'),'D')\n assert_equal(mintypecode('Dd'),'D')\n assert_equal(mintypecode('DF'),'D')\n assert_equal(mintypecode('DD'),'D')\n\n def check_default_3(self):\n assert_equal(mintypecode('fdF'),'D')\n assert_equal(mintypecode('fdF',savespace=1),'F')\n assert_equal(mintypecode('fdD'),'D')\n assert_equal(mintypecode('fFD'),'D')\n assert_equal(mintypecode('dFD'),'D')\n\n assert_equal(mintypecode('ifd'),'d')\n assert_equal(mintypecode('ifF'),'F')\n assert_equal(mintypecode('ifD'),'D')\n assert_equal(mintypecode('idF'),'D')\n assert_equal(mintypecode('idF',savespace=1),'F')\n assert_equal(mintypecode('idD'),'D')\n \nclass test_isscalar(unittest.TestCase):\n def check_basic(self):\n assert(isscalar(3))\n assert(not isscalar([3]))\n assert(not isscalar((3,)))\n assert(isscalar(3j))\n assert(isscalar(10L))\n assert(isscalar(4.0))\n\nclass test_real(unittest.TestCase):\n def check_real(self):\n y = rand(10,)\n assert_array_equal(y,real(y))\n\n def check_cmplx(self):\n y = rand(10,)+1j*rand(10,)\n assert_array_equal(y.real,real(y))\n\nclass test_imag(unittest.TestCase):\n def check_real(self):\n y = rand(10,)\n assert_array_equal(0,imag(y))\n\n def check_cmplx(self):\n y = rand(10,)+1j*rand(10,)\n assert_array_equal(y.imag,imag(y))\n\nclass test_iscomplex(unittest.TestCase):\n def check_fail(self):\n z = array([-1,0,1])\n res = iscomplex(z)\n assert(not sometrue(res))\n def check_pass(self):\n z = array([-1j,1,0])\n res = iscomplex(z)\n assert_array_equal(res,[1,0,0])\n\nclass test_isreal(unittest.TestCase):\n def check_pass(self):\n z = array([-1,0,1j])\n res = isreal(z)\n assert_array_equal(res,[1,1,0])\n def check_fail(self):\n z = array([-1j,1,0])\n res = isreal(z)\n assert_array_equal(res,[0,1,1])\n\nclass test_iscomplexobj(unittest.TestCase):\n def check_basic(self):\n z = array([-1,0,1])\n assert(not iscomplexobj(z))\n z = array([-1j,0,-1])\n assert(iscomplexobj(z))\n\nclass test_isrealobj(unittest.TestCase):\n def check_basic(self):\n z = array([-1,0,1])\n assert(isrealobj(z))\n z = array([-1j,0,-1])\n assert(not isrealobj(z))\n\nclass test_isnan(unittest.TestCase):\n def check_goodvalues(self):\n z = array((-1.,0.,1.))\n res = isnan(z) == 0\n assert_all(alltrue(res)) \n def check_posinf(self): \n assert_all(isnan(array((1.,))/0.) == 0)\n def check_neginf(self): \n assert_all(isnan(array((-1.,))/0.) == 0)\n def check_ind(self): \n assert_all(isnan(array((0.,))/0.) == 1)\n #def check_qnan(self): log(-1) return pi*j now\n # assert_all(isnan(log(-1.)) == 1)\n def check_integer(self):\n assert_all(isnan(1) == 0)\n def check_complex(self):\n assert_all(isnan(1+1j) == 0)\n def check_complex1(self):\n assert_all(isnan(array(0+0j)/0.) == 1)\n \nclass test_isfinite(unittest.TestCase):\n def check_goodvalues(self):\n z = array((-1.,0.,1.))\n res = isfinite(z) == 1\n assert_all(alltrue(res)) \n def check_posinf(self): \n assert_all(isfinite(array((1.,))/0.) == 0)\n def check_neginf(self): \n assert_all(isfinite(array((-1.,))/0.) == 0)\n def check_ind(self): \n assert_all(isfinite(array((0.,))/0.) == 0)\n #def check_qnan(self): \n # assert_all(isfinite(log(-1.)) == 0)\n def check_integer(self):\n assert_all(isfinite(1) == 1)\n def check_complex(self):\n assert_all(isfinite(1+1j) == 1)\n def check_complex1(self):\n assert_all(isfinite(array(1+1j)/0.) == 0)\n \nclass test_isinf(unittest.TestCase):\n def check_goodvalues(self):\n z = array((-1.,0.,1.))\n res = isinf(z) == 0\n assert_all(alltrue(res)) \n def check_posinf(self): \n assert_all(isinf(array((1.,))/0.) == 1)\n def check_posinf_scalar(self): \n assert_all(isinf(array(1.,)/0.) == 1)\n def check_neginf(self): \n assert_all(isinf(array((-1.,))/0.) == 1)\n def check_neginf_scalar(self): \n assert_all(isinf(array(-1.)/0.) == 1)\n def check_ind(self): \n assert_all(isinf(array((0.,))/0.) == 0)\n #def check_qnan(self): \n # assert_all(isinf(log(-1.)) == 0)\n # assert_all(isnan(log(-1.)) == 1)\n\nclass test_isposinf(unittest.TestCase):\n def check_generic(self):\n vals = isposinf(array((-1.,0,1))/0.)\n assert(vals[0] == 0)\n assert(vals[1] == 0)\n assert(vals[2] == 1)\n\nclass test_isneginf(unittest.TestCase):\n def check_generic(self):\n vals = isneginf(array((-1.,0,1))/0.)\n assert(vals[0] == 1)\n assert(vals[1] == 0)\n assert(vals[2] == 0)\n\nclass test_nan_to_num(unittest.TestCase):\n def check_generic(self):\n vals = nan_to_num(array((-1.,0,1))/0.)\n assert_all(vals[0] < -1e10) and assert_all(isfinite(vals[0]))\n assert(vals[1] == 0)\n assert_all(vals[2] > 1e10) and assert_all(isfinite(vals[2]))\n def check_integer(self):\n vals = nan_to_num(1)\n assert_all(vals == 1)\n def check_complex_good(self):\n vals = nan_to_num(1+1j)\n assert_all(vals == 1+1j)\n def check_complex_bad(self):\n v = 1+1j\n v += array(0+1.j)/0.\n vals = nan_to_num(v)\n # !! This is actually (unexpectedly) zero\n assert_all(vals.imag > 1e10) and assert_all(isfinite(vals))\n def check_complex_bad2(self):\n v = 1+1j\n v += array(-1+1.j)/0.\n vals = nan_to_num(v)\n assert_all(isfinite(vals)) \n #assert_all(vals.imag > 1e10) and assert_all(isfinite(vals)) \n # !! This is actually (unexpectedly) positive\n # !! inf. Comment out for now, and see if it\n # !! changes\n #assert_all(vals.real < -1e10) and assert_all(isfinite(vals)) \n\n\nclass test_real_if_close(unittest.TestCase):\n def check_basic(self):\n a = rand(10)\n b = real_if_close(a+1e-15j)\n assert_all(isrealobj(b))\n assert_array_equal(a,b)\n b = real_if_close(a+1e-7j)\n assert_all(iscomplexobj(b))\n b = real_if_close(a+1e-7j,tol=1e-6)\n assert_all(isrealobj(b))\n\nif __name__ == \"__main__\":\n ScipyTest('scipy_base.type_check').run()\n", "source_code_before": "\nimport unittest\nimport sys\nfrom scipy_test.testing import *\nset_package_path()\nimport scipy_base;reload(scipy_base);reload(scipy_base.type_check)\nfrom scipy_base import *\ndel sys.path[0]\n\nclass test_mintypecode(ScipyTestCase):\n\n def check_default_1(self):\n for itype in '1bcsuwil':\n assert_equal(mintypecode(itype),'d')\n assert_equal(mintypecode('f'),'f')\n assert_equal(mintypecode('d'),'d')\n assert_equal(mintypecode('F'),'F')\n assert_equal(mintypecode('D'),'D')\n\n def check_default_2(self):\n for itype in '1bcsuwil':\n assert_equal(mintypecode(itype+'f'),'f')\n assert_equal(mintypecode(itype+'d'),'d')\n assert_equal(mintypecode(itype+'F'),'F')\n assert_equal(mintypecode(itype+'D'),'D')\n assert_equal(mintypecode('ff'),'f')\n assert_equal(mintypecode('fd'),'d')\n assert_equal(mintypecode('fF'),'F')\n assert_equal(mintypecode('fD'),'D')\n assert_equal(mintypecode('df'),'d')\n assert_equal(mintypecode('dd'),'d')\n assert_equal(mintypecode('dF',savespace=1),'F')\n assert_equal(mintypecode('dF'),'D')\n assert_equal(mintypecode('dD'),'D')\n assert_equal(mintypecode('Ff'),'F')\n assert_equal(mintypecode('Fd',savespace=1),'F')\n assert_equal(mintypecode('Fd'),'D')\n assert_equal(mintypecode('FF'),'F')\n assert_equal(mintypecode('FD'),'D')\n assert_equal(mintypecode('Df'),'D')\n assert_equal(mintypecode('Dd'),'D')\n assert_equal(mintypecode('DF'),'D')\n assert_equal(mintypecode('DD'),'D')\n\n def check_default_3(self):\n assert_equal(mintypecode('fdF'),'D')\n assert_equal(mintypecode('fdF',savespace=1),'F')\n assert_equal(mintypecode('fdD'),'D')\n assert_equal(mintypecode('fFD'),'D')\n assert_equal(mintypecode('dFD'),'D')\n\n assert_equal(mintypecode('ifd'),'d')\n assert_equal(mintypecode('ifF'),'F')\n assert_equal(mintypecode('ifD'),'D')\n assert_equal(mintypecode('idF'),'D')\n assert_equal(mintypecode('idF',savespace=1),'F')\n assert_equal(mintypecode('idD'),'D')\n \nclass test_isscalar(unittest.TestCase):\n def check_basic(self):\n assert(isscalar(3))\n assert(not isscalar([3]))\n assert(not isscalar((3,)))\n assert(isscalar(3j))\n assert(isscalar(10L))\n assert(isscalar(4.0))\n\nclass test_real(unittest.TestCase):\n def check_real(self):\n y = rand(10,)\n assert_array_equal(y,real(y))\n\n def check_cmplx(self):\n y = rand(10,)+1j*rand(10,)\n assert_array_equal(y.real,real(y))\n\nclass test_imag(unittest.TestCase):\n def check_real(self):\n y = rand(10,)\n assert_array_equal(0,imag(y))\n\n def check_cmplx(self):\n y = rand(10,)+1j*rand(10,)\n assert_array_equal(y.imag,imag(y))\n\nclass test_iscomplex(unittest.TestCase):\n def check_fail(self):\n z = array([-1,0,1])\n res = iscomplex(z)\n assert(not sometrue(res))\n def check_pass(self):\n z = array([-1j,1,0])\n res = iscomplex(z)\n assert_array_equal(res,[1,0,0])\n\nclass test_isreal(unittest.TestCase):\n def check_pass(self):\n z = array([-1,0,1j])\n res = isreal(z)\n assert_array_equal(res,[1,1,0])\n def check_fail(self):\n z = array([-1j,1,0])\n res = isreal(z)\n assert_array_equal(res,[0,1,1])\n\nclass test_iscomplexobj(unittest.TestCase):\n def check_basic(self):\n z = array([-1,0,1])\n assert(not iscomplexobj(z))\n z = array([-1j,0,-1])\n assert(iscomplexobj(z))\n\nclass test_isrealobj(unittest.TestCase):\n def check_basic(self):\n z = array([-1,0,1])\n assert(isrealobj(z))\n z = array([-1j,0,-1])\n assert(not isrealobj(z))\n\nclass test_isnan(unittest.TestCase):\n def check_goodvalues(self):\n z = array((-1.,0.,1.))\n res = isnan(z) == 0\n assert(alltrue(res)) \n def check_posinf(self): \n assert(isnan(array((1.,))/0.) == 0)\n def check_neginf(self): \n assert(isnan(array((-1.,))/0.) == 0)\n def check_ind(self): \n assert(isnan(array((0.,))/0.) == 1)\n #def check_qnan(self): log(-1) return pi*j now\n # assert(isnan(log(-1.)) == 1)\n def check_integer(self):\n assert(isnan(1) == 0)\n def check_complex(self):\n assert(isnan(1+1j) == 0)\n def check_complex1(self):\n assert(isnan(array(0+0j)/0.) == 1)\n \nclass test_isfinite(unittest.TestCase):\n def check_goodvalues(self):\n z = array((-1.,0.,1.))\n res = isfinite(z) == 1\n assert(alltrue(res)) \n def check_posinf(self): \n assert(isfinite(array((1.,))/0.) == 0)\n def check_neginf(self): \n assert(isfinite(array((-1.,))/0.) == 0)\n def check_ind(self): \n assert(isfinite(array((0.,))/0.) == 0)\n #def check_qnan(self): \n # assert(isfinite(log(-1.)) == 0)\n def check_integer(self):\n assert(isfinite(1) == 1)\n def check_complex(self):\n assert(isfinite(1+1j) == 1)\n def check_complex1(self):\n assert(isfinite(array(1+1j)/0.) == 0)\n \nclass test_isinf(unittest.TestCase):\n def check_goodvalues(self):\n z = array((-1.,0.,1.))\n res = isinf(z) == 0\n assert(alltrue(res)) \n def check_posinf(self): \n assert(isinf(array((1.,))/0.) == 1)\n def check_posinf_scalar(self): \n assert(isinf(array(1.,)/0.) == 1)\n def check_neginf(self): \n assert(isinf(array((-1.,))/0.) == 1)\n def check_neginf_scalar(self): \n assert(isinf(array(-1.)/0.) == 1)\n def check_ind(self): \n assert(isinf(array((0.,))/0.) == 0)\n #def check_qnan(self): \n # assert(isinf(log(-1.)) == 0)\n # assert(isnan(log(-1.)) == 1)\n\nclass test_isposinf(unittest.TestCase):\n def check_generic(self):\n vals = isposinf(array((-1.,0,1))/0.)\n assert(vals[0] == 0)\n assert(vals[1] == 0)\n assert(vals[2] == 1)\n\nclass test_isneginf(unittest.TestCase):\n def check_generic(self):\n vals = isneginf(array((-1.,0,1))/0.)\n assert(vals[0] == 1)\n assert(vals[1] == 0)\n assert(vals[2] == 0)\n\nclass test_nan_to_num(unittest.TestCase):\n def check_generic(self):\n vals = nan_to_num(array((-1.,0,1))/0.)\n assert(vals[0] < -1e10 and isfinite(vals[0]))\n assert(vals[1] == 0)\n assert(vals[2] > 1e10 and isfinite(vals[2]))\n def check_integer(self):\n vals = nan_to_num(1)\n assert(vals == 1)\n def check_complex_good(self):\n vals = nan_to_num(1+1j)\n assert(vals == 1+1j)\n def check_complex_bad(self):\n v = 1+1j\n v += array(0+1.j)/0.\n vals = nan_to_num(v)\n # !! This is actually (unexpectedly) zero\n assert(vals.imag > 1e10 and isfinite(vals))\n def check_complex_bad2(self):\n v = 1+1j\n v += array(-1+1.j)/0.\n vals = nan_to_num(v)\n assert(isfinite(vals)) \n #assert(vals.imag > 1e10 and isfinite(vals)) \n # !! This is actually (unexpectedly) positive\n # !! inf. Comment out for now, and see if it\n # !! changes\n #assert(vals.real < -1e10 and isfinite(vals)) \n\n\nclass test_real_if_close(unittest.TestCase):\n def check_basic(self):\n a = rand(10)\n b = real_if_close(a+1e-15j)\n assert(isrealobj(b))\n assert_array_equal(a,b)\n b = real_if_close(a+1e-7j)\n assert(iscomplexobj(b))\n b = real_if_close(a+1e-7j,tol=1e-6)\n assert(isrealobj(b))\n\nif __name__ == \"__main__\":\n ScipyTest('scipy_base.type_check').run()\n", "methods": [ { "name": "assert_all", "long_name": "assert_all( x )", "filename": "test_type_check.py", "nloc": 2, "complexity": 1, "token_count": 14, "parameters": [ "x" ], "start_line": 10, "end_line": 11, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 2, "top_nesting_level": 0 }, { "name": "check_default_1", "long_name": "check_default_1( self )", "filename": "test_type_check.py", "nloc": 7, "complexity": 2, "token_count": 55, "parameters": [ "self" ], "start_line": 15, "end_line": 21, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 7, "top_nesting_level": 1 }, { "name": "check_default_2", "long_name": "check_default_2( self )", "filename": "test_type_check.py", "nloc": 24, "complexity": 2, "token_count": 224, "parameters": [ "self" ], "start_line": 23, "end_line": 46, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 24, "top_nesting_level": 1 }, { "name": "check_default_3", "long_name": "check_default_3( self )", "filename": "test_type_check.py", "nloc": 12, "complexity": 1, "token_count": 112, "parameters": [ "self" ], "start_line": 48, "end_line": 60, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 13, "top_nesting_level": 1 }, { "name": "check_basic", "long_name": "check_basic( self )", "filename": "test_type_check.py", "nloc": 7, "complexity": 1, "token_count": 56, "parameters": [ "self" ], "start_line": 63, "end_line": 69, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 7, "top_nesting_level": 1 }, { "name": "check_real", "long_name": "check_real( self )", "filename": "test_type_check.py", "nloc": 3, "complexity": 1, "token_count": 21, "parameters": [ "self" ], "start_line": 72, "end_line": 74, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 3, "top_nesting_level": 1 }, { "name": "check_cmplx", "long_name": "check_cmplx( self )", "filename": "test_type_check.py", "nloc": 3, "complexity": 1, "token_count": 31, "parameters": [ "self" ], "start_line": 76, "end_line": 78, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 3, "top_nesting_level": 1 }, { "name": "check_real", "long_name": "check_real( self )", "filename": "test_type_check.py", "nloc": 3, "complexity": 1, "token_count": 21, "parameters": [ "self" ], "start_line": 81, "end_line": 83, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 3, "top_nesting_level": 1 }, { "name": "check_cmplx", "long_name": "check_cmplx( self )", "filename": "test_type_check.py", "nloc": 3, "complexity": 1, "token_count": 31, "parameters": [ "self" ], "start_line": 85, "end_line": 87, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 3, "top_nesting_level": 1 }, { "name": "check_fail", "long_name": "check_fail( self )", "filename": "test_type_check.py", "nloc": 4, "complexity": 1, "token_count": 32, "parameters": [ "self" ], "start_line": 90, "end_line": 93, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 4, "top_nesting_level": 1 }, { "name": "check_pass", "long_name": "check_pass( self )", "filename": "test_type_check.py", "nloc": 4, "complexity": 1, "token_count": 36, "parameters": [ "self" ], "start_line": 94, "end_line": 97, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 4, "top_nesting_level": 1 }, { "name": "check_pass", "long_name": "check_pass( self )", "filename": "test_type_check.py", "nloc": 4, "complexity": 1, "token_count": 36, "parameters": [ "self" ], "start_line": 100, "end_line": 103, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 4, "top_nesting_level": 1 }, { "name": "check_fail", "long_name": "check_fail( self )", "filename": "test_type_check.py", "nloc": 4, "complexity": 1, "token_count": 36, "parameters": [ "self" ], "start_line": 104, "end_line": 107, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 4, "top_nesting_level": 1 }, { "name": "check_basic", "long_name": "check_basic( self )", "filename": "test_type_check.py", "nloc": 5, "complexity": 1, "token_count": 47, "parameters": [ "self" ], "start_line": 110, "end_line": 114, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 5, "top_nesting_level": 1 }, { "name": "check_basic", "long_name": "check_basic( self )", "filename": "test_type_check.py", "nloc": 5, "complexity": 1, "token_count": 47, "parameters": [ "self" ], "start_line": 117, "end_line": 121, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 5, "top_nesting_level": 1 }, { "name": "check_goodvalues", "long_name": "check_goodvalues( self )", "filename": "test_type_check.py", "nloc": 4, "complexity": 1, "token_count": 36, "parameters": [ "self" ], "start_line": 124, "end_line": 127, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 4, "top_nesting_level": 1 }, { "name": "check_posinf", "long_name": "check_posinf( self )", "filename": "test_type_check.py", "nloc": 2, "complexity": 1, "token_count": 24, "parameters": [ "self" ], "start_line": 128, "end_line": 129, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 2, "top_nesting_level": 1 }, { "name": "check_neginf", "long_name": "check_neginf( self )", "filename": "test_type_check.py", "nloc": 2, "complexity": 1, "token_count": 25, "parameters": [ "self" ], "start_line": 130, "end_line": 131, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 2, "top_nesting_level": 1 }, { "name": "check_ind", "long_name": "check_ind( self )", "filename": "test_type_check.py", "nloc": 2, "complexity": 1, "token_count": 24, "parameters": [ "self" ], "start_line": 132, "end_line": 133, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 2, "top_nesting_level": 1 }, { "name": "check_integer", "long_name": "check_integer( self )", "filename": "test_type_check.py", "nloc": 2, "complexity": 1, "token_count": 14, "parameters": [ "self" ], "start_line": 136, "end_line": 137, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 2, "top_nesting_level": 1 }, { "name": "check_complex", "long_name": "check_complex( self )", "filename": "test_type_check.py", "nloc": 2, "complexity": 1, "token_count": 16, "parameters": [ "self" ], "start_line": 138, "end_line": 139, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 2, "top_nesting_level": 1 }, { "name": "check_complex1", "long_name": "check_complex1( self )", "filename": "test_type_check.py", "nloc": 2, "complexity": 1, "token_count": 22, "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": "check_goodvalues", "long_name": "check_goodvalues( self )", "filename": "test_type_check.py", "nloc": 4, "complexity": 1, "token_count": 36, "parameters": [ "self" ], "start_line": 144, "end_line": 147, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 4, "top_nesting_level": 1 }, { "name": "check_posinf", "long_name": "check_posinf( self )", "filename": "test_type_check.py", "nloc": 2, "complexity": 1, "token_count": 24, "parameters": [ "self" ], "start_line": 148, "end_line": 149, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 2, "top_nesting_level": 1 }, { "name": "check_neginf", "long_name": "check_neginf( self )", "filename": "test_type_check.py", "nloc": 2, "complexity": 1, "token_count": 25, "parameters": [ "self" ], "start_line": 150, "end_line": 151, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 2, "top_nesting_level": 1 }, { "name": "check_ind", "long_name": "check_ind( self )", "filename": "test_type_check.py", "nloc": 2, "complexity": 1, "token_count": 24, "parameters": [ "self" ], "start_line": 152, "end_line": 153, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 2, "top_nesting_level": 1 }, { "name": "check_integer", "long_name": "check_integer( self )", "filename": "test_type_check.py", "nloc": 2, "complexity": 1, "token_count": 14, "parameters": [ "self" ], "start_line": 156, "end_line": 157, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 2, "top_nesting_level": 1 }, { "name": "check_complex", "long_name": "check_complex( self )", "filename": "test_type_check.py", "nloc": 2, "complexity": 1, "token_count": 16, "parameters": [ "self" ], "start_line": 158, "end_line": 159, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 2, "top_nesting_level": 1 }, { "name": "check_complex1", "long_name": "check_complex1( self )", "filename": "test_type_check.py", "nloc": 2, "complexity": 1, "token_count": 22, "parameters": [ "self" ], "start_line": 160, "end_line": 161, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 2, "top_nesting_level": 1 }, { "name": "check_goodvalues", "long_name": "check_goodvalues( self )", "filename": "test_type_check.py", "nloc": 4, "complexity": 1, "token_count": 36, "parameters": [ "self" ], "start_line": 164, "end_line": 167, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 4, "top_nesting_level": 1 }, { "name": "check_posinf", "long_name": "check_posinf( self )", "filename": "test_type_check.py", "nloc": 2, "complexity": 1, "token_count": 24, "parameters": [ "self" ], "start_line": 168, "end_line": 169, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 2, "top_nesting_level": 1 }, { "name": "check_posinf_scalar", "long_name": "check_posinf_scalar( self )", "filename": "test_type_check.py", "nloc": 2, "complexity": 1, "token_count": 22, "parameters": [ "self" ], "start_line": 170, "end_line": 171, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 2, "top_nesting_level": 1 }, { "name": "check_neginf", "long_name": "check_neginf( self )", "filename": "test_type_check.py", "nloc": 2, "complexity": 1, "token_count": 25, "parameters": [ "self" ], "start_line": 172, "end_line": 173, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 2, "top_nesting_level": 1 }, { "name": "check_neginf_scalar", "long_name": "check_neginf_scalar( self )", "filename": "test_type_check.py", "nloc": 2, "complexity": 1, "token_count": 22, "parameters": [ "self" ], "start_line": 174, "end_line": 175, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 2, "top_nesting_level": 1 }, { "name": "check_ind", "long_name": "check_ind( self )", "filename": "test_type_check.py", "nloc": 2, "complexity": 1, "token_count": 24, "parameters": [ "self" ], "start_line": 176, "end_line": 177, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 2, "top_nesting_level": 1 }, { "name": "check_generic", "long_name": "check_generic( self )", "filename": "test_type_check.py", "nloc": 5, "complexity": 1, "token_count": 52, "parameters": [ "self" ], "start_line": 183, "end_line": 187, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 5, "top_nesting_level": 1 }, { "name": "check_generic", "long_name": "check_generic( self )", "filename": "test_type_check.py", "nloc": 5, "complexity": 1, "token_count": 52, "parameters": [ "self" ], "start_line": 190, "end_line": 194, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 5, "top_nesting_level": 1 }, { "name": "check_generic", "long_name": "check_generic( self )", "filename": "test_type_check.py", "nloc": 5, "complexity": 3, "token_count": 75, "parameters": [ "self" ], "start_line": 197, "end_line": 201, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 5, "top_nesting_level": 1 }, { "name": "check_integer", "long_name": "check_integer( self )", "filename": "test_type_check.py", "nloc": 3, "complexity": 1, "token_count": 17, "parameters": [ "self" ], "start_line": 202, "end_line": 204, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 3, "top_nesting_level": 1 }, { "name": "check_complex_good", "long_name": "check_complex_good( self )", "filename": "test_type_check.py", "nloc": 3, "complexity": 1, "token_count": 21, "parameters": [ "self" ], "start_line": 205, "end_line": 207, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 3, "top_nesting_level": 1 }, { "name": "check_complex_bad", "long_name": "check_complex_bad( self )", "filename": "test_type_check.py", "nloc": 5, "complexity": 2, "token_count": 45, "parameters": [ "self" ], "start_line": 208, "end_line": 213, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 6, "top_nesting_level": 1 }, { "name": "check_complex_bad2", "long_name": "check_complex_bad2( self )", "filename": "test_type_check.py", "nloc": 5, "complexity": 1, "token_count": 37, "parameters": [ "self" ], "start_line": 214, "end_line": 218, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 5, "top_nesting_level": 1 }, { "name": "check_basic", "long_name": "check_basic( self )", "filename": "test_type_check.py", "nloc": 9, "complexity": 1, "token_count": 74, "parameters": [ "self" ], "start_line": 227, "end_line": 235, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 9, "top_nesting_level": 1 } ], "methods_before": [ { "name": "check_default_1", "long_name": "check_default_1( self )", "filename": "test_type_check.py", "nloc": 7, "complexity": 2, "token_count": 55, "parameters": [ "self" ], "start_line": 12, "end_line": 18, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 7, "top_nesting_level": 1 }, { "name": "check_default_2", "long_name": "check_default_2( self )", "filename": "test_type_check.py", "nloc": 24, "complexity": 2, "token_count": 224, "parameters": [ "self" ], "start_line": 20, "end_line": 43, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 24, "top_nesting_level": 1 }, { "name": "check_default_3", "long_name": "check_default_3( self )", "filename": "test_type_check.py", "nloc": 12, "complexity": 1, "token_count": 112, "parameters": [ "self" ], "start_line": 45, "end_line": 57, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 13, "top_nesting_level": 1 }, { "name": "check_basic", "long_name": "check_basic( self )", "filename": "test_type_check.py", "nloc": 7, "complexity": 1, "token_count": 56, "parameters": [ "self" ], "start_line": 60, "end_line": 66, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 7, "top_nesting_level": 1 }, { "name": "check_real", "long_name": "check_real( self )", "filename": "test_type_check.py", "nloc": 3, "complexity": 1, "token_count": 21, "parameters": [ "self" ], "start_line": 69, "end_line": 71, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 3, "top_nesting_level": 1 }, { "name": "check_cmplx", "long_name": "check_cmplx( self )", "filename": "test_type_check.py", "nloc": 3, "complexity": 1, "token_count": 31, "parameters": [ "self" ], "start_line": 73, "end_line": 75, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 3, "top_nesting_level": 1 }, { "name": "check_real", "long_name": "check_real( self )", "filename": "test_type_check.py", "nloc": 3, "complexity": 1, "token_count": 21, "parameters": [ "self" ], "start_line": 78, "end_line": 80, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 3, "top_nesting_level": 1 }, { "name": "check_cmplx", "long_name": "check_cmplx( self )", "filename": "test_type_check.py", "nloc": 3, "complexity": 1, "token_count": 31, "parameters": [ "self" ], "start_line": 82, "end_line": 84, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 3, "top_nesting_level": 1 }, { "name": "check_fail", "long_name": "check_fail( self )", "filename": "test_type_check.py", "nloc": 4, "complexity": 1, "token_count": 32, "parameters": [ "self" ], "start_line": 87, "end_line": 90, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 4, "top_nesting_level": 1 }, { "name": "check_pass", "long_name": "check_pass( self )", "filename": "test_type_check.py", "nloc": 4, "complexity": 1, "token_count": 36, "parameters": [ "self" ], "start_line": 91, "end_line": 94, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 4, "top_nesting_level": 1 }, { "name": "check_pass", "long_name": "check_pass( self )", "filename": "test_type_check.py", "nloc": 4, "complexity": 1, "token_count": 36, "parameters": [ "self" ], "start_line": 97, "end_line": 100, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 4, "top_nesting_level": 1 }, { "name": "check_fail", "long_name": "check_fail( self )", "filename": "test_type_check.py", "nloc": 4, "complexity": 1, "token_count": 36, "parameters": [ "self" ], "start_line": 101, "end_line": 104, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 4, "top_nesting_level": 1 }, { "name": "check_basic", "long_name": "check_basic( self )", "filename": "test_type_check.py", "nloc": 5, "complexity": 1, "token_count": 47, "parameters": [ "self" ], "start_line": 107, "end_line": 111, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 5, "top_nesting_level": 1 }, { "name": "check_basic", "long_name": "check_basic( self )", "filename": "test_type_check.py", "nloc": 5, "complexity": 1, "token_count": 47, "parameters": [ "self" ], "start_line": 114, "end_line": 118, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 5, "top_nesting_level": 1 }, { "name": "check_goodvalues", "long_name": "check_goodvalues( self )", "filename": "test_type_check.py", "nloc": 4, "complexity": 1, "token_count": 36, "parameters": [ "self" ], "start_line": 121, "end_line": 124, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 4, "top_nesting_level": 1 }, { "name": "check_posinf", "long_name": "check_posinf( self )", "filename": "test_type_check.py", "nloc": 2, "complexity": 1, "token_count": 24, "parameters": [ "self" ], "start_line": 125, "end_line": 126, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 2, "top_nesting_level": 1 }, { "name": "check_neginf", "long_name": "check_neginf( self )", "filename": "test_type_check.py", "nloc": 2, "complexity": 1, "token_count": 25, "parameters": [ "self" ], "start_line": 127, "end_line": 128, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 2, "top_nesting_level": 1 }, { "name": "check_ind", "long_name": "check_ind( self )", "filename": "test_type_check.py", "nloc": 2, "complexity": 1, "token_count": 24, "parameters": [ "self" ], "start_line": 129, "end_line": 130, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 2, "top_nesting_level": 1 }, { "name": "check_integer", "long_name": "check_integer( self )", "filename": "test_type_check.py", "nloc": 2, "complexity": 1, "token_count": 14, "parameters": [ "self" ], "start_line": 133, "end_line": 134, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 2, "top_nesting_level": 1 }, { "name": "check_complex", "long_name": "check_complex( self )", "filename": "test_type_check.py", "nloc": 2, "complexity": 1, "token_count": 16, "parameters": [ "self" ], "start_line": 135, "end_line": 136, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 2, "top_nesting_level": 1 }, { "name": "check_complex1", "long_name": "check_complex1( self )", "filename": "test_type_check.py", "nloc": 2, "complexity": 1, "token_count": 22, "parameters": [ "self" ], "start_line": 137, "end_line": 138, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 2, "top_nesting_level": 1 }, { "name": "check_goodvalues", "long_name": "check_goodvalues( self )", "filename": "test_type_check.py", "nloc": 4, "complexity": 1, "token_count": 36, "parameters": [ "self" ], "start_line": 141, "end_line": 144, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 4, "top_nesting_level": 1 }, { "name": "check_posinf", "long_name": "check_posinf( self )", "filename": "test_type_check.py", "nloc": 2, "complexity": 1, "token_count": 24, "parameters": [ "self" ], "start_line": 145, "end_line": 146, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 2, "top_nesting_level": 1 }, { "name": "check_neginf", "long_name": "check_neginf( self )", "filename": "test_type_check.py", "nloc": 2, "complexity": 1, "token_count": 25, "parameters": [ "self" ], "start_line": 147, "end_line": 148, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 2, "top_nesting_level": 1 }, { "name": "check_ind", "long_name": "check_ind( self )", "filename": "test_type_check.py", "nloc": 2, "complexity": 1, "token_count": 24, "parameters": [ "self" ], "start_line": 149, "end_line": 150, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 2, "top_nesting_level": 1 }, { "name": "check_integer", "long_name": "check_integer( self )", "filename": "test_type_check.py", "nloc": 2, "complexity": 1, "token_count": 14, "parameters": [ "self" ], "start_line": 153, "end_line": 154, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 2, "top_nesting_level": 1 }, { "name": "check_complex", "long_name": "check_complex( self )", "filename": "test_type_check.py", "nloc": 2, "complexity": 1, "token_count": 16, "parameters": [ "self" ], "start_line": 155, "end_line": 156, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 2, "top_nesting_level": 1 }, { "name": "check_complex1", "long_name": "check_complex1( self )", "filename": "test_type_check.py", "nloc": 2, "complexity": 1, "token_count": 22, "parameters": [ "self" ], "start_line": 157, "end_line": 158, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 2, "top_nesting_level": 1 }, { "name": "check_goodvalues", "long_name": "check_goodvalues( self )", "filename": "test_type_check.py", "nloc": 4, "complexity": 1, "token_count": 36, "parameters": [ "self" ], "start_line": 161, "end_line": 164, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 4, "top_nesting_level": 1 }, { "name": "check_posinf", "long_name": "check_posinf( self )", "filename": "test_type_check.py", "nloc": 2, "complexity": 1, "token_count": 24, "parameters": [ "self" ], "start_line": 165, "end_line": 166, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 2, "top_nesting_level": 1 }, { "name": "check_posinf_scalar", "long_name": "check_posinf_scalar( self )", "filename": "test_type_check.py", "nloc": 2, "complexity": 1, "token_count": 22, "parameters": [ "self" ], "start_line": 167, "end_line": 168, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 2, "top_nesting_level": 1 }, { "name": "check_neginf", "long_name": "check_neginf( self )", "filename": "test_type_check.py", "nloc": 2, "complexity": 1, "token_count": 25, "parameters": [ "self" ], "start_line": 169, "end_line": 170, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 2, "top_nesting_level": 1 }, { "name": "check_neginf_scalar", "long_name": "check_neginf_scalar( self )", "filename": "test_type_check.py", "nloc": 2, "complexity": 1, "token_count": 22, "parameters": [ "self" ], "start_line": 171, "end_line": 172, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 2, "top_nesting_level": 1 }, { "name": "check_ind", "long_name": "check_ind( self )", "filename": "test_type_check.py", "nloc": 2, "complexity": 1, "token_count": 24, "parameters": [ "self" ], "start_line": 173, "end_line": 174, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 2, "top_nesting_level": 1 }, { "name": "check_generic", "long_name": "check_generic( self )", "filename": "test_type_check.py", "nloc": 5, "complexity": 1, "token_count": 52, "parameters": [ "self" ], "start_line": 180, "end_line": 184, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 5, "top_nesting_level": 1 }, { "name": "check_generic", "long_name": "check_generic( self )", "filename": "test_type_check.py", "nloc": 5, "complexity": 1, "token_count": 52, "parameters": [ "self" ], "start_line": 187, "end_line": 191, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 5, "top_nesting_level": 1 }, { "name": "check_generic", "long_name": "check_generic( self )", "filename": "test_type_check.py", "nloc": 5, "complexity": 3, "token_count": 69, "parameters": [ "self" ], "start_line": 194, "end_line": 198, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 5, "top_nesting_level": 1 }, { "name": "check_integer", "long_name": "check_integer( self )", "filename": "test_type_check.py", "nloc": 3, "complexity": 1, "token_count": 17, "parameters": [ "self" ], "start_line": 199, "end_line": 201, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 3, "top_nesting_level": 1 }, { "name": "check_complex_good", "long_name": "check_complex_good( self )", "filename": "test_type_check.py", "nloc": 3, "complexity": 1, "token_count": 21, "parameters": [ "self" ], "start_line": 202, "end_line": 204, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 3, "top_nesting_level": 1 }, { "name": "check_complex_bad", "long_name": "check_complex_bad( self )", "filename": "test_type_check.py", "nloc": 5, "complexity": 2, "token_count": 42, "parameters": [ "self" ], "start_line": 205, "end_line": 210, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 6, "top_nesting_level": 1 }, { "name": "check_complex_bad2", "long_name": "check_complex_bad2( self )", "filename": "test_type_check.py", "nloc": 5, "complexity": 1, "token_count": 37, "parameters": [ "self" ], "start_line": 211, "end_line": 215, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 5, "top_nesting_level": 1 }, { "name": "check_basic", "long_name": "check_basic( self )", "filename": "test_type_check.py", "nloc": 9, "complexity": 1, "token_count": 74, "parameters": [ "self" ], "start_line": 224, "end_line": 232, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 9, "top_nesting_level": 1 } ], "changed_methods": [ { "name": "check_ind", "long_name": "check_ind( self )", "filename": "test_type_check.py", "nloc": 2, "complexity": 1, "token_count": 24, "parameters": [ "self" ], "start_line": 132, "end_line": 133, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 2, "top_nesting_level": 1 }, { "name": "assert_all", "long_name": "assert_all( x )", "filename": "test_type_check.py", "nloc": 2, "complexity": 1, "token_count": 14, "parameters": [ "x" ], "start_line": 10, "end_line": 11, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 2, "top_nesting_level": 0 }, { "name": "check_goodvalues", "long_name": "check_goodvalues( self )", "filename": "test_type_check.py", "nloc": 4, "complexity": 1, "token_count": 36, "parameters": [ "self" ], "start_line": 124, "end_line": 127, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 4, "top_nesting_level": 1 }, { "name": "check_complex", "long_name": "check_complex( self )", "filename": "test_type_check.py", "nloc": 2, "complexity": 1, "token_count": 16, "parameters": [ "self" ], "start_line": 138, "end_line": 139, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 2, "top_nesting_level": 1 }, { "name": "check_generic", "long_name": "check_generic( self )", "filename": "test_type_check.py", "nloc": 5, "complexity": 3, "token_count": 75, "parameters": [ "self" ], "start_line": 197, "end_line": 201, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 5, "top_nesting_level": 1 }, { "name": "check_complex_bad2", "long_name": "check_complex_bad2( self )", "filename": "test_type_check.py", "nloc": 5, "complexity": 1, "token_count": 37, "parameters": [ "self" ], "start_line": 214, "end_line": 218, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 5, "top_nesting_level": 1 }, { "name": "check_posinf_scalar", "long_name": "check_posinf_scalar( self )", "filename": "test_type_check.py", "nloc": 2, "complexity": 1, "token_count": 22, "parameters": [ "self" ], "start_line": 170, "end_line": 171, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 2, "top_nesting_level": 1 }, { "name": "check_neginf", "long_name": "check_neginf( self )", "filename": "test_type_check.py", "nloc": 2, "complexity": 1, "token_count": 25, "parameters": [ "self" ], "start_line": 130, "end_line": 131, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 2, "top_nesting_level": 1 }, { "name": "check_complex1", "long_name": "check_complex1( self )", "filename": "test_type_check.py", "nloc": 2, "complexity": 1, "token_count": 22, "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": "check_integer", "long_name": "check_integer( self )", "filename": "test_type_check.py", "nloc": 2, "complexity": 1, "token_count": 14, "parameters": [ "self" ], "start_line": 136, "end_line": 137, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 2, "top_nesting_level": 1 }, { "name": "check_basic", "long_name": "check_basic( self )", "filename": "test_type_check.py", "nloc": 9, "complexity": 1, "token_count": 74, "parameters": [ "self" ], "start_line": 227, "end_line": 235, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 9, "top_nesting_level": 1 }, { "name": "check_neginf_scalar", "long_name": "check_neginf_scalar( self )", "filename": "test_type_check.py", "nloc": 2, "complexity": 1, "token_count": 22, "parameters": [ "self" ], "start_line": 174, "end_line": 175, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 2, "top_nesting_level": 1 }, { "name": "check_posinf", "long_name": "check_posinf( self )", "filename": "test_type_check.py", "nloc": 2, "complexity": 1, "token_count": 24, "parameters": [ "self" ], "start_line": 128, "end_line": 129, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 2, "top_nesting_level": 1 }, { "name": "check_complex_bad", "long_name": "check_complex_bad( self )", "filename": "test_type_check.py", "nloc": 5, "complexity": 2, "token_count": 45, "parameters": [ "self" ], "start_line": 208, "end_line": 213, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 6, "top_nesting_level": 1 }, { "name": "check_complex_good", "long_name": "check_complex_good( self )", "filename": "test_type_check.py", "nloc": 3, "complexity": 1, "token_count": 21, "parameters": [ "self" ], "start_line": 205, "end_line": 207, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 3, "top_nesting_level": 1 } ], "nloc": 200, "complexity": 48, "token_count": 1859, "diff_parsed": { "added": [ "def assert_all(x):", " assert(all(x)), x", "", " assert_all(alltrue(res))", " assert_all(isnan(array((1.,))/0.) == 0)", " assert_all(isnan(array((-1.,))/0.) == 0)", " assert_all(isnan(array((0.,))/0.) == 1)", " # assert_all(isnan(log(-1.)) == 1)", " assert_all(isnan(1) == 0)", " assert_all(isnan(1+1j) == 0)", " assert_all(isnan(array(0+0j)/0.) == 1)", " assert_all(alltrue(res))", " assert_all(isfinite(array((1.,))/0.) == 0)", " assert_all(isfinite(array((-1.,))/0.) == 0)", " assert_all(isfinite(array((0.,))/0.) == 0)", " # assert_all(isfinite(log(-1.)) == 0)", " assert_all(isfinite(1) == 1)", " assert_all(isfinite(1+1j) == 1)", " assert_all(isfinite(array(1+1j)/0.) == 0)", " assert_all(alltrue(res))", " assert_all(isinf(array((1.,))/0.) == 1)", " assert_all(isinf(array(1.,)/0.) == 1)", " assert_all(isinf(array((-1.,))/0.) == 1)", " assert_all(isinf(array(-1.)/0.) == 1)", " assert_all(isinf(array((0.,))/0.) == 0)", " # assert_all(isinf(log(-1.)) == 0)", " # assert_all(isnan(log(-1.)) == 1)", " assert_all(vals[0] < -1e10) and assert_all(isfinite(vals[0]))", " assert_all(vals[2] > 1e10) and assert_all(isfinite(vals[2]))", " assert_all(vals == 1)", " assert_all(vals == 1+1j)", " assert_all(vals.imag > 1e10) and assert_all(isfinite(vals))", " assert_all(isfinite(vals))", " #assert_all(vals.imag > 1e10) and assert_all(isfinite(vals))", " #assert_all(vals.real < -1e10) and assert_all(isfinite(vals))", " assert_all(isrealobj(b))", " assert_all(iscomplexobj(b))", " assert_all(isrealobj(b))" ], "deleted": [ " assert(alltrue(res))", " assert(isnan(array((1.,))/0.) == 0)", " assert(isnan(array((-1.,))/0.) == 0)", " assert(isnan(array((0.,))/0.) == 1)", " # assert(isnan(log(-1.)) == 1)", " assert(isnan(1) == 0)", " assert(isnan(1+1j) == 0)", " assert(isnan(array(0+0j)/0.) == 1)", " assert(alltrue(res))", " assert(isfinite(array((1.,))/0.) == 0)", " assert(isfinite(array((-1.,))/0.) == 0)", " assert(isfinite(array((0.,))/0.) == 0)", " # assert(isfinite(log(-1.)) == 0)", " assert(isfinite(1) == 1)", " assert(isfinite(1+1j) == 1)", " assert(isfinite(array(1+1j)/0.) == 0)", " assert(alltrue(res))", " assert(isinf(array((1.,))/0.) == 1)", " assert(isinf(array(1.,)/0.) == 1)", " assert(isinf(array((-1.,))/0.) == 1)", " assert(isinf(array(-1.)/0.) == 1)", " assert(isinf(array((0.,))/0.) == 0)", " # assert(isinf(log(-1.)) == 0)", " # assert(isnan(log(-1.)) == 1)", " assert(vals[0] < -1e10 and isfinite(vals[0]))", " assert(vals[2] > 1e10 and isfinite(vals[2]))", " assert(vals == 1)", " assert(vals == 1+1j)", " assert(vals.imag > 1e10 and isfinite(vals))", " assert(isfinite(vals))", " #assert(vals.imag > 1e10 and isfinite(vals))", " #assert(vals.real < -1e10 and isfinite(vals))", " assert(isrealobj(b))", " assert(iscomplexobj(b))", " assert(isrealobj(b))" ] } }, { "old_path": "scipy_base/type_check.py", "new_path": "scipy_base/type_check.py", "filename": "type_check.py", "extension": "py", "change_type": "MODIFY", "diff": "@@ -1,19 +1,12 @@\n-\n import types\n-import Numeric\n-from fastumath import isinf, isnan, isfinite\n-from Numeric import ArrayType, array, multiarray\n-\n-try:\n- from Numeric import UfuncType\n-except ImportError:\n- UfuncType = type(Numeric.sin)\n+import numerix as _nx\n+from numerix import ArrayType, array, isinf, isnan, isfinite, UfuncType\n \n __all__ = ['ScalarType','iscomplexobj','isrealobj','imag','iscomplex',\n 'isscalar','isneginf','isposinf','isnan','isinf','isfinite',\n 'isreal','nan_to_num','real','real_if_close',\n 'typename','cast','common_type','typecodes', 'asarray',\n- 'asfarray', 'ArrayType', 'UfuncType','mintypecode']\n+ 'asfarray','ArrayType','UfuncType','mintypecode']\n \n _typecodes_by_elsize = 'DFdfluiwsb1c'\n def mintypecode(typecodes,typeset='DFdf',default='d',savespace=0):\n@@ -54,7 +47,7 @@ def asarray(a, typecode=None, savespace=None):\n if not (savespace is None or a.spacesaver()==savespace):\n r.savespace(savespace)\n return r\n- return multiarray.array(a,typecode,copy=0,savespace=savespace or 0)\n+ return array(a,typecode,copy=0,savespace=savespace or 0)\n \n def asfarray(a, typecode=None, savespace=None):\n \"\"\"asfarray(a,typecode=None, savespace=0) returns a as a NumPy float array.\"\"\"\n@@ -65,49 +58,49 @@ def asfarray(a, typecode=None, savespace=None):\n \n ScalarType = [types.IntType, types.LongType, types.FloatType, types.ComplexType]\n \n-typecodes = Numeric.typecodes\n+typecodes = _nx.typecodes\n typecodes['AllInteger'] = '1silbwu'\n \n try:\n- Char = Numeric.Character\n+ Char = _nx.Character\n except AttributeError:\n Char = 'c'\n \n toChar = lambda x: asarray(x).astype(Char)\n-toInt8 = lambda x: asarray(x).astype(Numeric.Int8)# or use variable names such as Byte\n-toUInt8 = lambda x: asarray(x).astype(Numeric.UnsignedInt8)\n+toInt8 = lambda x: asarray(x).astype(_nx.Int8)# or use variable names such as Byte\n+toUInt8 = lambda x: asarray(x).astype(_nx.UnsignedInt8)\n _unsigned = 0\n-if hasattr(Numeric,'UnsignedInt16'):\n- toUInt16 = lambda x: asarray(x).astype(Numeric.UnsignedInt16)\n- toUInt32 = lambda x: asarray(x).astype(Numeric.UnsignedInt32)\n+if hasattr(_nx,'UnsignedInt16'):\n+ toUInt16 = lambda x: asarray(x).astype(_nx.UnsignedInt16)\n+ toUInt32 = lambda x: asarray(x).astype(_nx.UnsignedInt32)\n _unsigned = 1\n \n-toInt16 = lambda x: asarray(x).astype(Numeric.Int16)\n-toInt32 = lambda x: asarray(x).astype(Numeric.Int32)\n-toInt = lambda x: asarray(x).astype(Numeric.Int)\n-toFloat32 = lambda x: asarray(x).astype(Numeric.Float32)\n-toFloat64 = lambda x: asarray(x).astype(Numeric.Float64)\n-toComplex32 = lambda x: asarray(x).astype(Numeric.Complex32)\n-toComplex64 = lambda x: asarray(x).astype(Numeric.Complex64)\n-\n-# This is for pre Numeric 21.x compatiblity. Adding it is harmless.\n-if not hasattr(Numeric,'Character'):\n- Numeric.Character = 'c'\n+toInt16 = lambda x: asarray(x).astype(_nx.Int16)\n+toInt32 = lambda x: asarray(x).astype(_nx.Int32)\n+toInt = lambda x: asarray(x).astype(_nx.Int)\n+toFloat32 = lambda x: asarray(x).astype(_nx.Float32)\n+toFloat64 = lambda x: asarray(x).astype(_nx.Float64)\n+toComplex32 = lambda x: asarray(x).astype(_nx.Complex32)\n+toComplex64 = lambda x: asarray(x).astype(_nx.Complex64)\n+\n+# This is for pre _nx 21.x compatiblity. Adding it is harmless.\n+if not hasattr(_nx,'Character'):\n+ _nx.Character = 'c'\n \n-cast = {Numeric.Character: toChar,\n- Numeric.UnsignedInt8: toUInt8,\n- Numeric.Int8: toInt8,\n- Numeric.Int16: toInt16,\n- Numeric.Int32: toInt32,\n- Numeric.Int: toInt,\n- Numeric.Float32: toFloat32,\n- Numeric.Float64: toFloat64,\n- Numeric.Complex32: toComplex32,\n- Numeric.Complex64: toComplex64}\n+cast = {_nx.Character: toChar,\n+ _nx.UnsignedInt8: toUInt8,\n+ _nx.Int8: toInt8,\n+ _nx.Int16: toInt16,\n+ _nx.Int32: toInt32,\n+ _nx.Int: toInt,\n+ _nx.Float32: toFloat32,\n+ _nx.Float64: toFloat64,\n+ _nx.Complex32: toComplex32,\n+ _nx.Complex64: toComplex64}\n \n if _unsigned:\n- cast[Numeric.UnsignedInt16] = toUInt16\n- cast[Numeric.UnsignedInt32] = toUInt32\n+ cast[_nx.UnsignedInt16] = toUInt16\n+ cast[_nx.UnsignedInt32] = toUInt32\n \n \n def isscalar(num):\n@@ -130,10 +123,10 @@ def imag(val):\n return array(0,aval.typecode())*aval\n \n def iscomplex(x):\n- return imag(x) != Numeric.zeros(asarray(x).shape)\n+ return imag(x) != _nx.zeros(asarray(x).shape)\n \n def isreal(x):\n- return imag(x) == Numeric.zeros(asarray(x).shape)\n+ return imag(x) == _nx.zeros(asarray(x).shape)\n \n def iscomplexobj(x):\n return asarray(x).typecode() in ['F', 'D']\n@@ -152,7 +145,7 @@ def isrealobj(x):\n ## if array_iscomplex(vals):\n ## r = array(map(ieee_754.isnan,real(vals))) \n ## i = array(map(ieee_754.isnan,imag(vals)))\n-## results = Numeric.logical_or(r,i)\n+## results = _nx.logical_or(r,i)\n ## else: \n ## results = array(map(ieee_754.isnan,vals))\n ## if isscalar(val):\n@@ -166,18 +159,18 @@ def isneginf(val):\n return isinf(val) & (val < 0)\n \n ##def isinf(val):\n-## return Numeric.logical_or(isposinf(val),isneginf(val))\n+## return _nx.logical_or(isposinf(val),isneginf(val))\n \n ##def isfinite(val):\n ## vals = asarray(val)\n ## if iscomplexobj(vals):\n ## r = isfinite(real(vals))\n ## i = isfinite(imag(vals))\n-## results = Numeric.logical_and(r,i)\n+## results = _nx.logical_and(r,i)\n ## else: \n-## fin = Numeric.logical_not(isinf(val))\n-## an = Numeric.logical_not(isnan(val))\n-## results = Numeric.logical_and(fin,an)\n+## fin = _nx.logical_not(isinf(val))\n+## an = _nx.logical_not(isnan(val))\n+## results = _nx.logical_and(fin,an)\n ## return results \n \n def nan_to_num(x):\n@@ -199,7 +192,7 @@ def nan_to_num(x):\n are_neg_inf = isneginf(x)\n are_nan = isnan(x)\n choose_array = are_neg_inf + are_nan * 2 + are_inf * 3\n- y = Numeric.choose(choose_array,\n+ y = _nx.choose(choose_array,\n (x,limits.double_min, 0., limits.double_max))\n return y\n \n@@ -207,7 +200,7 @@ def nan_to_num(x):\n \n def real_if_close(a,tol=1e-13):\n a = asarray(a)\n- if a.typecode() in ['F','D'] and Numeric.allclose(a.imag, 0, atol=tol):\n+ if a.typecode() in ['F','D'] and _nx.allclose(a.imag, 0, atol=tol):\n a = a.real\n return a\n \n", "added_lines": 44, "deleted_lines": 51, "source_code": "import types\nimport numerix as _nx\nfrom numerix import ArrayType, array, isinf, isnan, isfinite, UfuncType\n\n__all__ = ['ScalarType','iscomplexobj','isrealobj','imag','iscomplex',\n 'isscalar','isneginf','isposinf','isnan','isinf','isfinite',\n 'isreal','nan_to_num','real','real_if_close',\n 'typename','cast','common_type','typecodes', 'asarray',\n 'asfarray','ArrayType','UfuncType','mintypecode']\n\n_typecodes_by_elsize = 'DFdfluiwsb1c'\ndef mintypecode(typecodes,typeset='DFdf',default='d',savespace=0):\n \"\"\" Return a typecode in typeset such that for each\n t in typecodes\n array(typecode=typecode)[:] = array(typecode=t)\n is valid, looses no information, and array(typecode=typecode)\n element size is minimal unless when typecodes does not\n intersect with typeset then default is returned.\n As a special case, if savespace is False then 'D' is returned\n whenever typecodes contain 'F' and 'd'.\n If t in typecodes is not a string then t=t.typecode() is applied.\n \"\"\"\n typecodes = [(type(t) is type('') and t) or asarray(t).typecode()\\\n for t in typecodes]\n intersection = [t for t in typecodes if t in typeset]\n if not intersection:\n return default\n if not savespace and 'F' in intersection and 'd' in intersection:\n return 'D'\n l = []\n for t in intersection:\n i = _typecodes_by_elsize.index(t)\n l.append((i,t))\n l.sort()\n return l[0][1]\n\ndef asarray(a, typecode=None, savespace=None):\n \"\"\"asarray(a,typecode=None, savespace=0) returns a as a NumPy array.\n Unlike array(), no copy is performed if a is already an array.\n \"\"\"\n if type(a) is ArrayType:\n if typecode is None or typecode == a.typecode():\n if savespace is None or a.spacesaver()==savespace:\n return a\n else:\n r = a.astype(typecode)\n if not (savespace is None or a.spacesaver()==savespace):\n r.savespace(savespace)\n return r\n return array(a,typecode,copy=0,savespace=savespace or 0)\n\ndef asfarray(a, typecode=None, savespace=None):\n \"\"\"asfarray(a,typecode=None, savespace=0) returns a as a NumPy float array.\"\"\"\n a = asarray(a,typecode,savespace)\n if typecode is None and a.typecode() not in 'CFfd':\n return a.astype('d')\n return a\n\nScalarType = [types.IntType, types.LongType, types.FloatType, types.ComplexType]\n\ntypecodes = _nx.typecodes\ntypecodes['AllInteger'] = '1silbwu'\n\ntry:\n Char = _nx.Character\nexcept AttributeError:\n Char = 'c'\n\ntoChar = lambda x: asarray(x).astype(Char)\ntoInt8 = lambda x: asarray(x).astype(_nx.Int8)# or use variable names such as Byte\ntoUInt8 = lambda x: asarray(x).astype(_nx.UnsignedInt8)\n_unsigned = 0\nif hasattr(_nx,'UnsignedInt16'):\n toUInt16 = lambda x: asarray(x).astype(_nx.UnsignedInt16)\n toUInt32 = lambda x: asarray(x).astype(_nx.UnsignedInt32)\n _unsigned = 1\n \ntoInt16 = lambda x: asarray(x).astype(_nx.Int16)\ntoInt32 = lambda x: asarray(x).astype(_nx.Int32)\ntoInt = lambda x: asarray(x).astype(_nx.Int)\ntoFloat32 = lambda x: asarray(x).astype(_nx.Float32)\ntoFloat64 = lambda x: asarray(x).astype(_nx.Float64)\ntoComplex32 = lambda x: asarray(x).astype(_nx.Complex32)\ntoComplex64 = lambda x: asarray(x).astype(_nx.Complex64)\n\n# This is for pre _nx 21.x compatiblity. Adding it is harmless.\nif not hasattr(_nx,'Character'):\n _nx.Character = 'c'\n \ncast = {_nx.Character: toChar,\n _nx.UnsignedInt8: toUInt8,\n _nx.Int8: toInt8,\n _nx.Int16: toInt16,\n _nx.Int32: toInt32,\n _nx.Int: toInt,\n _nx.Float32: toFloat32,\n _nx.Float64: toFloat64,\n _nx.Complex32: toComplex32,\n _nx.Complex64: toComplex64}\n\nif _unsigned:\n cast[_nx.UnsignedInt16] = toUInt16\n cast[_nx.UnsignedInt32] = toUInt32\n \n\ndef isscalar(num):\n if isinstance(num, ArrayType):\n return len(num.shape) == 0 and num.typecode() != 'O'\n return type(num) in ScalarType\n\ndef real(val):\n aval = asarray(val)\n if aval.typecode() in ['F', 'D']:\n return aval.real\n else:\n return aval\n\ndef imag(val):\n aval = asarray(val)\n if aval.typecode() in ['F', 'D']:\n return aval.imag\n else:\n return array(0,aval.typecode())*aval\n\ndef iscomplex(x):\n return imag(x) != _nx.zeros(asarray(x).shape)\n\ndef isreal(x):\n return imag(x) == _nx.zeros(asarray(x).shape)\n\ndef iscomplexobj(x):\n return asarray(x).typecode() in ['F', 'D']\n\ndef isrealobj(x):\n return not asarray(x).typecode() in ['F', 'D']\n\n#-----------------------------------------------------------------------------\n\n##def isnan(val):\n## # fast, but apparently not portable (according to notes by Tim Peters)\n## #return val != val\n## # very slow -- should really use cephes methods or *something* different\n## import ieee_754\n## vals = ravel(val)\n## if array_iscomplex(vals):\n## r = array(map(ieee_754.isnan,real(vals))) \n## i = array(map(ieee_754.isnan,imag(vals)))\n## results = _nx.logical_or(r,i)\n## else: \n## results = array(map(ieee_754.isnan,vals))\n## if isscalar(val):\n## results = results[0]\n## return results\n\ndef isposinf(val):\n return isinf(val) & (val > 0)\n \ndef isneginf(val):\n return isinf(val) & (val < 0)\n \n##def isinf(val):\n## return _nx.logical_or(isposinf(val),isneginf(val))\n\n##def isfinite(val):\n## vals = asarray(val)\n## if iscomplexobj(vals):\n## r = isfinite(real(vals))\n## i = isfinite(imag(vals))\n## results = _nx.logical_and(r,i)\n## else: \n## fin = _nx.logical_not(isinf(val))\n## an = _nx.logical_not(isnan(val))\n## results = _nx.logical_and(fin,an)\n## return results \n\ndef nan_to_num(x):\n # mapping:\n # NaN -> 0\n # Inf -> limits.double_max\n # -Inf -> limits.double_min\n # complex not handled currently\n import limits\n try:\n t = x.typecode()\n except AttributeError:\n t = type(x)\n if t in [types.ComplexType,'F','D']: \n y = nan_to_num(x.real) + 1j * nan_to_num(x.imag)\n else: \n x = asarray(x)\n are_inf = isposinf(x)\n are_neg_inf = isneginf(x)\n are_nan = isnan(x)\n choose_array = are_neg_inf + are_nan * 2 + are_inf * 3\n y = _nx.choose(choose_array,\n (x,limits.double_min, 0., limits.double_max))\n return y\n\n#-----------------------------------------------------------------------------\n\ndef real_if_close(a,tol=1e-13):\n a = asarray(a)\n if a.typecode() in ['F','D'] and _nx.allclose(a.imag, 0, atol=tol):\n a = a.real\n return a\n\n\n#-----------------------------------------------------------------------------\n\n_namefromtype = {'c' : 'character',\n '1' : 'signed char',\n 'b' : 'unsigned char',\n 's' : 'short',\n 'w' : 'unsigned short',\n 'i' : 'integer',\n 'u' : 'unsigned integer',\n 'l' : 'long integer',\n 'f' : 'float',\n 'd' : 'double',\n 'F' : 'complex float',\n 'D' : 'complex double',\n 'O' : 'object'\n }\n\ndef typename(char):\n \"\"\"Return an english name for the given typecode character.\n \"\"\"\n return _namefromtype[char]\n\n#-----------------------------------------------------------------------------\n\n#determine the \"minimum common type code\" for a group of arrays.\narray_kind = {'i':0, 'l': 0, 'f': 0, 'd': 0, 'F': 1, 'D': 1}\narray_precision = {'i': 1, 'l': 1, 'f': 0, 'd': 1, 'F': 0, 'D': 1}\narray_type = [['f', 'd'], ['F', 'D']]\ndef common_type(*arrays):\n kind = 0\n precision = 0\n for a in arrays:\n t = a.typecode()\n kind = max(kind, array_kind[t])\n precision = max(precision, array_precision[t])\n return array_type[kind][precision]\n\nif __name__ == '__main__':\n print 'float epsilon:',float_epsilon\n print 'float tiny:',float_tiny\n print 'double epsilon:',double_epsilon\n print 'double tiny:',double_tiny\n", "source_code_before": "\nimport types\nimport Numeric\nfrom fastumath import isinf, isnan, isfinite\nfrom Numeric import ArrayType, array, multiarray\n\ntry:\n from Numeric import UfuncType\nexcept ImportError:\n UfuncType = type(Numeric.sin)\n\n__all__ = ['ScalarType','iscomplexobj','isrealobj','imag','iscomplex',\n 'isscalar','isneginf','isposinf','isnan','isinf','isfinite',\n 'isreal','nan_to_num','real','real_if_close',\n 'typename','cast','common_type','typecodes', 'asarray',\n 'asfarray', 'ArrayType', 'UfuncType','mintypecode']\n\n_typecodes_by_elsize = 'DFdfluiwsb1c'\ndef mintypecode(typecodes,typeset='DFdf',default='d',savespace=0):\n \"\"\" Return a typecode in typeset such that for each\n t in typecodes\n array(typecode=typecode)[:] = array(typecode=t)\n is valid, looses no information, and array(typecode=typecode)\n element size is minimal unless when typecodes does not\n intersect with typeset then default is returned.\n As a special case, if savespace is False then 'D' is returned\n whenever typecodes contain 'F' and 'd'.\n If t in typecodes is not a string then t=t.typecode() is applied.\n \"\"\"\n typecodes = [(type(t) is type('') and t) or asarray(t).typecode()\\\n for t in typecodes]\n intersection = [t for t in typecodes if t in typeset]\n if not intersection:\n return default\n if not savespace and 'F' in intersection and 'd' in intersection:\n return 'D'\n l = []\n for t in intersection:\n i = _typecodes_by_elsize.index(t)\n l.append((i,t))\n l.sort()\n return l[0][1]\n\ndef asarray(a, typecode=None, savespace=None):\n \"\"\"asarray(a,typecode=None, savespace=0) returns a as a NumPy array.\n Unlike array(), no copy is performed if a is already an array.\n \"\"\"\n if type(a) is ArrayType:\n if typecode is None or typecode == a.typecode():\n if savespace is None or a.spacesaver()==savespace:\n return a\n else:\n r = a.astype(typecode)\n if not (savespace is None or a.spacesaver()==savespace):\n r.savespace(savespace)\n return r\n return multiarray.array(a,typecode,copy=0,savespace=savespace or 0)\n\ndef asfarray(a, typecode=None, savespace=None):\n \"\"\"asfarray(a,typecode=None, savespace=0) returns a as a NumPy float array.\"\"\"\n a = asarray(a,typecode,savespace)\n if typecode is None and a.typecode() not in 'CFfd':\n return a.astype('d')\n return a\n\nScalarType = [types.IntType, types.LongType, types.FloatType, types.ComplexType]\n\ntypecodes = Numeric.typecodes\ntypecodes['AllInteger'] = '1silbwu'\n\ntry:\n Char = Numeric.Character\nexcept AttributeError:\n Char = 'c'\n\ntoChar = lambda x: asarray(x).astype(Char)\ntoInt8 = lambda x: asarray(x).astype(Numeric.Int8)# or use variable names such as Byte\ntoUInt8 = lambda x: asarray(x).astype(Numeric.UnsignedInt8)\n_unsigned = 0\nif hasattr(Numeric,'UnsignedInt16'):\n toUInt16 = lambda x: asarray(x).astype(Numeric.UnsignedInt16)\n toUInt32 = lambda x: asarray(x).astype(Numeric.UnsignedInt32)\n _unsigned = 1\n \ntoInt16 = lambda x: asarray(x).astype(Numeric.Int16)\ntoInt32 = lambda x: asarray(x).astype(Numeric.Int32)\ntoInt = lambda x: asarray(x).astype(Numeric.Int)\ntoFloat32 = lambda x: asarray(x).astype(Numeric.Float32)\ntoFloat64 = lambda x: asarray(x).astype(Numeric.Float64)\ntoComplex32 = lambda x: asarray(x).astype(Numeric.Complex32)\ntoComplex64 = lambda x: asarray(x).astype(Numeric.Complex64)\n\n# This is for pre Numeric 21.x compatiblity. Adding it is harmless.\nif not hasattr(Numeric,'Character'):\n Numeric.Character = 'c'\n \ncast = {Numeric.Character: toChar,\n Numeric.UnsignedInt8: toUInt8,\n Numeric.Int8: toInt8,\n Numeric.Int16: toInt16,\n Numeric.Int32: toInt32,\n Numeric.Int: toInt,\n Numeric.Float32: toFloat32,\n Numeric.Float64: toFloat64,\n Numeric.Complex32: toComplex32,\n Numeric.Complex64: toComplex64}\n\nif _unsigned:\n cast[Numeric.UnsignedInt16] = toUInt16\n cast[Numeric.UnsignedInt32] = toUInt32\n \n\ndef isscalar(num):\n if isinstance(num, ArrayType):\n return len(num.shape) == 0 and num.typecode() != 'O'\n return type(num) in ScalarType\n\ndef real(val):\n aval = asarray(val)\n if aval.typecode() in ['F', 'D']:\n return aval.real\n else:\n return aval\n\ndef imag(val):\n aval = asarray(val)\n if aval.typecode() in ['F', 'D']:\n return aval.imag\n else:\n return array(0,aval.typecode())*aval\n\ndef iscomplex(x):\n return imag(x) != Numeric.zeros(asarray(x).shape)\n\ndef isreal(x):\n return imag(x) == Numeric.zeros(asarray(x).shape)\n\ndef iscomplexobj(x):\n return asarray(x).typecode() in ['F', 'D']\n\ndef isrealobj(x):\n return not asarray(x).typecode() in ['F', 'D']\n\n#-----------------------------------------------------------------------------\n\n##def isnan(val):\n## # fast, but apparently not portable (according to notes by Tim Peters)\n## #return val != val\n## # very slow -- should really use cephes methods or *something* different\n## import ieee_754\n## vals = ravel(val)\n## if array_iscomplex(vals):\n## r = array(map(ieee_754.isnan,real(vals))) \n## i = array(map(ieee_754.isnan,imag(vals)))\n## results = Numeric.logical_or(r,i)\n## else: \n## results = array(map(ieee_754.isnan,vals))\n## if isscalar(val):\n## results = results[0]\n## return results\n\ndef isposinf(val):\n return isinf(val) & (val > 0)\n \ndef isneginf(val):\n return isinf(val) & (val < 0)\n \n##def isinf(val):\n## return Numeric.logical_or(isposinf(val),isneginf(val))\n\n##def isfinite(val):\n## vals = asarray(val)\n## if iscomplexobj(vals):\n## r = isfinite(real(vals))\n## i = isfinite(imag(vals))\n## results = Numeric.logical_and(r,i)\n## else: \n## fin = Numeric.logical_not(isinf(val))\n## an = Numeric.logical_not(isnan(val))\n## results = Numeric.logical_and(fin,an)\n## return results \n\ndef nan_to_num(x):\n # mapping:\n # NaN -> 0\n # Inf -> limits.double_max\n # -Inf -> limits.double_min\n # complex not handled currently\n import limits\n try:\n t = x.typecode()\n except AttributeError:\n t = type(x)\n if t in [types.ComplexType,'F','D']: \n y = nan_to_num(x.real) + 1j * nan_to_num(x.imag)\n else: \n x = asarray(x)\n are_inf = isposinf(x)\n are_neg_inf = isneginf(x)\n are_nan = isnan(x)\n choose_array = are_neg_inf + are_nan * 2 + are_inf * 3\n y = Numeric.choose(choose_array,\n (x,limits.double_min, 0., limits.double_max))\n return y\n\n#-----------------------------------------------------------------------------\n\ndef real_if_close(a,tol=1e-13):\n a = asarray(a)\n if a.typecode() in ['F','D'] and Numeric.allclose(a.imag, 0, atol=tol):\n a = a.real\n return a\n\n\n#-----------------------------------------------------------------------------\n\n_namefromtype = {'c' : 'character',\n '1' : 'signed char',\n 'b' : 'unsigned char',\n 's' : 'short',\n 'w' : 'unsigned short',\n 'i' : 'integer',\n 'u' : 'unsigned integer',\n 'l' : 'long integer',\n 'f' : 'float',\n 'd' : 'double',\n 'F' : 'complex float',\n 'D' : 'complex double',\n 'O' : 'object'\n }\n\ndef typename(char):\n \"\"\"Return an english name for the given typecode character.\n \"\"\"\n return _namefromtype[char]\n\n#-----------------------------------------------------------------------------\n\n#determine the \"minimum common type code\" for a group of arrays.\narray_kind = {'i':0, 'l': 0, 'f': 0, 'd': 0, 'F': 1, 'D': 1}\narray_precision = {'i': 1, 'l': 1, 'f': 0, 'd': 1, 'F': 0, 'D': 1}\narray_type = [['f', 'd'], ['F', 'D']]\ndef common_type(*arrays):\n kind = 0\n precision = 0\n for a in arrays:\n t = a.typecode()\n kind = max(kind, array_kind[t])\n precision = max(precision, array_precision[t])\n return array_type[kind][precision]\n\nif __name__ == '__main__':\n print 'float epsilon:',float_epsilon\n print 'float tiny:',float_tiny\n print 'double epsilon:',double_epsilon\n print 'double tiny:',double_tiny\n", "methods": [ { "name": "mintypecode", "long_name": "mintypecode( typecodes , typeset = 'DFdf' , default = 'd' , savespace = 0 )", "filename": "type_check.py", "nloc": 14, "complexity": 11, "token_count": 122, "parameters": [ "typecodes", "typeset", "default", "savespace" ], "start_line": 12, "end_line": 35, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 24, "top_nesting_level": 0 }, { "name": "asarray", "long_name": "asarray( a , typecode = None , savespace = None )", "filename": "type_check.py", "nloc": 11, "complexity": 9, "token_count": 101, "parameters": [ "a", "typecode", "savespace" ], "start_line": 37, "end_line": 50, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 14, "top_nesting_level": 0 }, { "name": "asfarray", "long_name": "asfarray( a , typecode = None , savespace = None )", "filename": "type_check.py", "nloc": 5, "complexity": 3, "token_count": 47, "parameters": [ "a", "typecode", "savespace" ], "start_line": 52, "end_line": 57, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 6, "top_nesting_level": 0 }, { "name": "isscalar", "long_name": "isscalar( num )", "filename": "type_check.py", "nloc": 4, "complexity": 3, "token_count": 37, "parameters": [ "num" ], "start_line": 106, "end_line": 109, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 4, "top_nesting_level": 0 }, { "name": "real", "long_name": "real( val )", "filename": "type_check.py", "nloc": 6, "complexity": 2, "token_count": 32, "parameters": [ "val" ], "start_line": 111, "end_line": 116, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 6, "top_nesting_level": 0 }, { "name": "imag", "long_name": "imag( val )", "filename": "type_check.py", "nloc": 6, "complexity": 2, "token_count": 43, "parameters": [ "val" ], "start_line": 118, "end_line": 123, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 6, "top_nesting_level": 0 }, { "name": "iscomplex", "long_name": "iscomplex( x )", "filename": "type_check.py", "nloc": 2, "complexity": 1, "token_count": 22, "parameters": [ "x" ], "start_line": 125, "end_line": 126, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 2, "top_nesting_level": 0 }, { "name": "isreal", "long_name": "isreal( x )", "filename": "type_check.py", "nloc": 2, "complexity": 1, "token_count": 22, "parameters": [ "x" ], "start_line": 128, "end_line": 129, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 2, "top_nesting_level": 0 }, { "name": "iscomplexobj", "long_name": "iscomplexobj( x )", "filename": "type_check.py", "nloc": 2, "complexity": 1, "token_count": 20, "parameters": [ "x" ], "start_line": 131, "end_line": 132, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 2, "top_nesting_level": 0 }, { "name": "isrealobj", "long_name": "isrealobj( x )", "filename": "type_check.py", "nloc": 2, "complexity": 1, "token_count": 21, "parameters": [ "x" ], "start_line": 134, "end_line": 135, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 2, "top_nesting_level": 0 }, { "name": "isposinf", "long_name": "isposinf( val )", "filename": "type_check.py", "nloc": 2, "complexity": 1, "token_count": 16, "parameters": [ "val" ], "start_line": 155, "end_line": 156, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 2, "top_nesting_level": 0 }, { "name": "isneginf", "long_name": "isneginf( val )", "filename": "type_check.py", "nloc": 2, "complexity": 1, "token_count": 16, "parameters": [ "val" ], "start_line": 158, "end_line": 159, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 2, "top_nesting_level": 0 }, { "name": "nan_to_num", "long_name": "nan_to_num( x )", "filename": "type_check.py", "nloc": 17, "complexity": 3, "token_count": 117, "parameters": [ "x" ], "start_line": 176, "end_line": 197, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 22, "top_nesting_level": 0 }, { "name": "real_if_close", "long_name": "real_if_close( a , tol = 1e - 13 )", "filename": "type_check.py", "nloc": 5, "complexity": 3, "token_count": 52, "parameters": [ "a", "tol" ], "start_line": 201, "end_line": 205, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 5, "top_nesting_level": 0 }, { "name": "typename", "long_name": "typename( char )", "filename": "type_check.py", "nloc": 2, "complexity": 1, "token_count": 11, "parameters": [ "char" ], "start_line": 225, "end_line": 228, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 4, "top_nesting_level": 0 }, { "name": "common_type", "long_name": "common_type( * arrays )", "filename": "type_check.py", "nloc": 8, "complexity": 2, "token_count": 54, "parameters": [ "arrays" ], "start_line": 236, "end_line": 243, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 8, "top_nesting_level": 0 } ], "methods_before": [ { "name": "mintypecode", "long_name": "mintypecode( typecodes , typeset = 'DFdf' , default = 'd' , savespace = 0 )", "filename": "type_check.py", "nloc": 14, "complexity": 11, "token_count": 122, "parameters": [ "typecodes", "typeset", "default", "savespace" ], "start_line": 19, "end_line": 42, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 24, "top_nesting_level": 0 }, { "name": "asarray", "long_name": "asarray( a , typecode = None , savespace = None )", "filename": "type_check.py", "nloc": 11, "complexity": 9, "token_count": 103, "parameters": [ "a", "typecode", "savespace" ], "start_line": 44, "end_line": 57, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 14, "top_nesting_level": 0 }, { "name": "asfarray", "long_name": "asfarray( a , typecode = None , savespace = None )", "filename": "type_check.py", "nloc": 5, "complexity": 3, "token_count": 47, "parameters": [ "a", "typecode", "savespace" ], "start_line": 59, "end_line": 64, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 6, "top_nesting_level": 0 }, { "name": "isscalar", "long_name": "isscalar( num )", "filename": "type_check.py", "nloc": 4, "complexity": 3, "token_count": 37, "parameters": [ "num" ], "start_line": 113, "end_line": 116, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 4, "top_nesting_level": 0 }, { "name": "real", "long_name": "real( val )", "filename": "type_check.py", "nloc": 6, "complexity": 2, "token_count": 32, "parameters": [ "val" ], "start_line": 118, "end_line": 123, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 6, "top_nesting_level": 0 }, { "name": "imag", "long_name": "imag( val )", "filename": "type_check.py", "nloc": 6, "complexity": 2, "token_count": 43, "parameters": [ "val" ], "start_line": 125, "end_line": 130, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 6, "top_nesting_level": 0 }, { "name": "iscomplex", "long_name": "iscomplex( x )", "filename": "type_check.py", "nloc": 2, "complexity": 1, "token_count": 22, "parameters": [ "x" ], "start_line": 132, "end_line": 133, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 2, "top_nesting_level": 0 }, { "name": "isreal", "long_name": "isreal( x )", "filename": "type_check.py", "nloc": 2, "complexity": 1, "token_count": 22, "parameters": [ "x" ], "start_line": 135, "end_line": 136, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 2, "top_nesting_level": 0 }, { "name": "iscomplexobj", "long_name": "iscomplexobj( x )", "filename": "type_check.py", "nloc": 2, "complexity": 1, "token_count": 20, "parameters": [ "x" ], "start_line": 138, "end_line": 139, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 2, "top_nesting_level": 0 }, { "name": "isrealobj", "long_name": "isrealobj( x )", "filename": "type_check.py", "nloc": 2, "complexity": 1, "token_count": 21, "parameters": [ "x" ], "start_line": 141, "end_line": 142, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 2, "top_nesting_level": 0 }, { "name": "isposinf", "long_name": "isposinf( val )", "filename": "type_check.py", "nloc": 2, "complexity": 1, "token_count": 16, "parameters": [ "val" ], "start_line": 162, "end_line": 163, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 2, "top_nesting_level": 0 }, { "name": "isneginf", "long_name": "isneginf( val )", "filename": "type_check.py", "nloc": 2, "complexity": 1, "token_count": 16, "parameters": [ "val" ], "start_line": 165, "end_line": 166, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 2, "top_nesting_level": 0 }, { "name": "nan_to_num", "long_name": "nan_to_num( x )", "filename": "type_check.py", "nloc": 17, "complexity": 3, "token_count": 117, "parameters": [ "x" ], "start_line": 183, "end_line": 204, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 22, "top_nesting_level": 0 }, { "name": "real_if_close", "long_name": "real_if_close( a , tol = 1e - 13 )", "filename": "type_check.py", "nloc": 5, "complexity": 3, "token_count": 52, "parameters": [ "a", "tol" ], "start_line": 208, "end_line": 212, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 5, "top_nesting_level": 0 }, { "name": "typename", "long_name": "typename( char )", "filename": "type_check.py", "nloc": 2, "complexity": 1, "token_count": 11, "parameters": [ "char" ], "start_line": 232, "end_line": 235, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 4, "top_nesting_level": 0 }, { "name": "common_type", "long_name": "common_type( * arrays )", "filename": "type_check.py", "nloc": 8, "complexity": 2, "token_count": 54, "parameters": [ "arrays" ], "start_line": 243, "end_line": 250, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 8, "top_nesting_level": 0 } ], "changed_methods": [ { "name": "real_if_close", "long_name": "real_if_close( a , tol = 1e - 13 )", "filename": "type_check.py", "nloc": 5, "complexity": 3, "token_count": 52, "parameters": [ "a", "tol" ], "start_line": 201, "end_line": 205, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 5, "top_nesting_level": 0 }, { "name": "asarray", "long_name": "asarray( a , typecode = None , savespace = None )", "filename": "type_check.py", "nloc": 11, "complexity": 9, "token_count": 101, "parameters": [ "a", "typecode", "savespace" ], "start_line": 37, "end_line": 50, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 14, "top_nesting_level": 0 }, { "name": "isreal", "long_name": "isreal( x )", "filename": "type_check.py", "nloc": 2, "complexity": 1, "token_count": 22, "parameters": [ "x" ], "start_line": 128, "end_line": 129, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 2, "top_nesting_level": 0 }, { "name": "iscomplex", "long_name": "iscomplex( x )", "filename": "type_check.py", "nloc": 2, "complexity": 1, "token_count": 22, "parameters": [ "x" ], "start_line": 125, "end_line": 126, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 2, "top_nesting_level": 0 }, { "name": "nan_to_num", "long_name": "nan_to_num( x )", "filename": "type_check.py", "nloc": 17, "complexity": 3, "token_count": 117, "parameters": [ "x" ], "start_line": 176, "end_line": 197, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 22, "top_nesting_level": 0 } ], "nloc": 158, "complexity": 45, "token_count": 1311, "diff_parsed": { "added": [ "import numerix as _nx", "from numerix import ArrayType, array, isinf, isnan, isfinite, UfuncType", " 'asfarray','ArrayType','UfuncType','mintypecode']", " return array(a,typecode,copy=0,savespace=savespace or 0)", "typecodes = _nx.typecodes", " Char = _nx.Character", "toInt8 = lambda x: asarray(x).astype(_nx.Int8)# or use variable names such as Byte", "toUInt8 = lambda x: asarray(x).astype(_nx.UnsignedInt8)", "if hasattr(_nx,'UnsignedInt16'):", " toUInt16 = lambda x: asarray(x).astype(_nx.UnsignedInt16)", " toUInt32 = lambda x: asarray(x).astype(_nx.UnsignedInt32)", "toInt16 = lambda x: asarray(x).astype(_nx.Int16)", "toInt32 = lambda x: asarray(x).astype(_nx.Int32)", "toInt = lambda x: asarray(x).astype(_nx.Int)", "toFloat32 = lambda x: asarray(x).astype(_nx.Float32)", "toFloat64 = lambda x: asarray(x).astype(_nx.Float64)", "toComplex32 = lambda x: asarray(x).astype(_nx.Complex32)", "toComplex64 = lambda x: asarray(x).astype(_nx.Complex64)", "", "# This is for pre _nx 21.x compatiblity. Adding it is harmless.", "if not hasattr(_nx,'Character'):", " _nx.Character = 'c'", "cast = {_nx.Character: toChar,", " _nx.UnsignedInt8: toUInt8,", " _nx.Int8: toInt8,", " _nx.Int16: toInt16,", " _nx.Int32: toInt32,", " _nx.Int: toInt,", " _nx.Float32: toFloat32,", " _nx.Float64: toFloat64,", " _nx.Complex32: toComplex32,", " _nx.Complex64: toComplex64}", " cast[_nx.UnsignedInt16] = toUInt16", " cast[_nx.UnsignedInt32] = toUInt32", " return imag(x) != _nx.zeros(asarray(x).shape)", " return imag(x) == _nx.zeros(asarray(x).shape)", "## results = _nx.logical_or(r,i)", "## return _nx.logical_or(isposinf(val),isneginf(val))", "## results = _nx.logical_and(r,i)", "## fin = _nx.logical_not(isinf(val))", "## an = _nx.logical_not(isnan(val))", "## results = _nx.logical_and(fin,an)", " y = _nx.choose(choose_array,", " if a.typecode() in ['F','D'] and _nx.allclose(a.imag, 0, atol=tol):" ], "deleted": [ "", "import Numeric", "from fastumath import isinf, isnan, isfinite", "from Numeric import ArrayType, array, multiarray", "", "try:", " from Numeric import UfuncType", "except ImportError:", " UfuncType = type(Numeric.sin)", " 'asfarray', 'ArrayType', 'UfuncType','mintypecode']", " return multiarray.array(a,typecode,copy=0,savespace=savespace or 0)", "typecodes = Numeric.typecodes", " Char = Numeric.Character", "toInt8 = lambda x: asarray(x).astype(Numeric.Int8)# or use variable names such as Byte", "toUInt8 = lambda x: asarray(x).astype(Numeric.UnsignedInt8)", "if hasattr(Numeric,'UnsignedInt16'):", " toUInt16 = lambda x: asarray(x).astype(Numeric.UnsignedInt16)", " toUInt32 = lambda x: asarray(x).astype(Numeric.UnsignedInt32)", "toInt16 = lambda x: asarray(x).astype(Numeric.Int16)", "toInt32 = lambda x: asarray(x).astype(Numeric.Int32)", "toInt = lambda x: asarray(x).astype(Numeric.Int)", "toFloat32 = lambda x: asarray(x).astype(Numeric.Float32)", "toFloat64 = lambda x: asarray(x).astype(Numeric.Float64)", "toComplex32 = lambda x: asarray(x).astype(Numeric.Complex32)", "toComplex64 = lambda x: asarray(x).astype(Numeric.Complex64)", "", "# This is for pre Numeric 21.x compatiblity. Adding it is harmless.", "if not hasattr(Numeric,'Character'):", " Numeric.Character = 'c'", "cast = {Numeric.Character: toChar,", " Numeric.UnsignedInt8: toUInt8,", " Numeric.Int8: toInt8,", " Numeric.Int16: toInt16,", " Numeric.Int32: toInt32,", " Numeric.Int: toInt,", " Numeric.Float32: toFloat32,", " Numeric.Float64: toFloat64,", " Numeric.Complex32: toComplex32,", " Numeric.Complex64: toComplex64}", " cast[Numeric.UnsignedInt16] = toUInt16", " cast[Numeric.UnsignedInt32] = toUInt32", " return imag(x) != Numeric.zeros(asarray(x).shape)", " return imag(x) == Numeric.zeros(asarray(x).shape)", "## results = Numeric.logical_or(r,i)", "## return Numeric.logical_or(isposinf(val),isneginf(val))", "## results = Numeric.logical_and(r,i)", "## fin = Numeric.logical_not(isinf(val))", "## an = Numeric.logical_not(isnan(val))", "## results = Numeric.logical_and(fin,an)", " y = Numeric.choose(choose_array,", " if a.typecode() in ['F','D'] and Numeric.allclose(a.imag, 0, atol=tol):" ] } }, { "old_path": "scipy_test/testing.py", "new_path": "scipy_test/testing.py", "filename": "testing.py", "extension": "py", "change_type": "MODIFY", "diff": "@@ -38,11 +38,10 @@\n # These are used by Numeric tests.\n # If Numeric and scipy_base are not available, then some of the\n # functions below will not be available.\n- from Numeric import alltrue,equal,shape,ravel,around,zeros,Float64,asarray,\\\n- less_equal,array2string,less\n- # `import scipy_base.fastumath as math` must be at the end of this file.\n-except ImportError,msg:\n- print msg\n+ from scipy_base.numerix import all, equal, shape, ravel, around, zeros, Float64, asarray\n+ from scipy_base.numerix import less_equal, array2string, less\n+except ImportError:\n+ pass\n \n DEBUG = 0\n \n@@ -644,7 +643,7 @@ def assert_equal(actual,desired,err_msg='',verbose=1):\n msg = msg \\\n + 'DESIRED: ' + repr(desired) \\\n + '\\nACTUAL: ' + repr(actual)\n- assert desired == actual, msg\n+ assert all(desired == actual), msg\n \n __all__.append('assert_almost_equal')\n def assert_almost_equal(actual,desired,decimal=7,err_msg='',verbose=1):\n@@ -661,7 +660,7 @@ def assert_almost_equal(actual,desired,decimal=7,err_msg='',verbose=1):\n msg = msg \\\n + 'DESIRED: ' + repr(desired) \\\n + '\\nACTUAL: ' + repr(actual)\n- assert round(abs(desired - actual),decimal) == 0, msg\n+ assert all(round(abs(desired - actual),decimal) == 0), msg\n \n __all__.append('assert_approx_equal')\n def assert_approx_equal(actual,desired,significant=7,err_msg='',verbose=1):\n@@ -692,7 +691,7 @@ def assert_approx_equal(actual,desired,significant=7,err_msg='',verbose=1):\n msg = msg \\\n + 'DESIRED: ' + repr(desired) \\\n + '\\nACTUAL: ' + repr(actual)\n- assert math.fabs(sc_desired - sc_actual) < pow(10.,-1*significant), msg\n+ assert all(math.fabs(sc_desired - sc_actual) < pow(10.,-1*significant)), msg\n \n \n __all__.append('assert_array_equal')\n@@ -702,11 +701,11 @@ def assert_array_equal(x,y,err_msg=''):\n try:\n assert 0 in [len(shape(x)),len(shape(y))] \\\n or (len(shape(x))==len(shape(y)) and \\\n- alltrue(equal(shape(x),shape(y)))),\\\n+ all(equal(shape(x),shape(y)))),\\\n msg + ' (shapes %s, %s mismatch):\\n\\t' \\\n % (shape(x),shape(y)) + err_msg\n reduced = ravel(equal(x,y))\n- cond = alltrue(reduced)\n+ cond = all(reduced)\n if not cond:\n s1 = array2string(x,precision=16)\n s2 = array2string(y,precision=16)\n@@ -725,13 +724,13 @@ def assert_array_almost_equal(x,y,decimal=6,err_msg=''):\n y = asarray(y)\n msg = '\\nArrays are not almost equal'\n try:\n- cond = alltrue(equal(shape(x),shape(y)))\n+ cond = all(equal(shape(x),shape(y)))\n if not cond:\n msg = msg + ' (shapes mismatch):\\n\\t'\\\n 'Shape of array 1: %s\\n\\tShape of array 2: %s' % (shape(x),shape(y))\n assert cond, msg + '\\n\\t' + err_msg\n reduced = ravel(equal(less_equal(around(abs(x-y),decimal),10.0**(-decimal)),1))\n- cond = alltrue(reduced)\n+ cond = all(reduced)\n if not cond:\n s1 = array2string(x,precision=decimal+1)\n s2 = array2string(y,precision=decimal+1)\n@@ -752,10 +751,10 @@ def assert_array_less(x,y,err_msg=''):\n x,y = asarray(x), asarray(y)\n msg = '\\nArrays are not less-ordered'\n try:\n- assert alltrue(equal(shape(x),shape(y))),\\\n+ assert all(equal(shape(x),shape(y))),\\\n msg + ' (shapes mismatch):\\n\\t' + err_msg\n reduced = ravel(less(x,y))\n- cond = alltrue(reduced)\n+ cond = all(reduced)\n if not cond:\n s1 = array2string(x,precision=16)\n s2 = array2string(y,precision=16)\n@@ -794,7 +793,7 @@ def output_exception():\n type = value = tb = None # clean up\n \n try:\n- import scipy_base.fastumath as math\n+ from scipy_base.numerix import fastumath as math\n except ImportError,msg:\n print msg\n import math\n", "added_lines": 14, "deleted_lines": 15, "source_code": "\"\"\"\nUnit-testing\n------------\n\n ScipyTest -- Scipy tests site manager\n ScipyTestCase -- unittest.TestCase with measure method\n IgnoreException -- raise when checking disabled feature ('ignoring' is displayed)\n set_package_path -- prepend package build directory to path\n set_local_path -- prepend local directory (to tests files) to path\n restore_path -- restore path after set_package_path\n\nTiming tools\n------------\n\n jiffies -- return 1/100ths of a second that the current process has used\n memusage -- virtual memory size in bytes of the running python [linux]\n\nUtility functions\n-----------------\n\n assert_equal -- assert equality\n assert_almost_equal -- assert equality with decimal tolerance\n assert_approx_equal -- assert equality with significant digits tolerance\n assert_array_equal -- assert arrays equality\n assert_array_almost_equal -- assert arrays equality with decimal tolerance\n assert_array_less -- assert arrays less-ordering\n rand -- array of random numbers from given shape\n\n\"\"\"\n\n__all__ = []\n\nimport os,sys,time,glob,string,traceback,unittest\nimport types\nimport imp\n\ntry:\n # These are used by Numeric tests.\n # If Numeric and scipy_base are not available, then some of the\n # functions below will not be available.\n from scipy_base.numerix import all, equal, shape, ravel, around, zeros, Float64, asarray\n from scipy_base.numerix import less_equal, array2string, less\nexcept ImportError:\n pass\n\nDEBUG = 0\n\n__all__.append('set_package_path')\ndef set_package_path(level=1):\n \"\"\" Prepend package directory to sys.path.\n\n set_package_path should be called from a test_file.py that\n satisfies the following tree structure:\n\n //test_file.py\n\n Then the first existing path name from the following list\n\n /build/lib.-\n /..\n\n is prepended to sys.path.\n The caller is responsible for removing this path by using\n\n restore_path()\n \"\"\"\n from distutils.util import get_platform\n from scipy_distutils.misc_util import get_frame\n f = get_frame(level)\n if f.f_locals['__name__']=='__main__':\n testfile = sys.argv[0]\n else:\n testfile = f.f_locals['__file__']\n d = os.path.dirname(os.path.dirname(os.path.abspath(testfile)))\n d1 = os.path.join(d,'build','lib.%s-%s'%(get_platform(),sys.version[:3]))\n if not os.path.isdir(d1):\n d1 = os.path.dirname(d)\n if DEBUG:\n print 'Inserting %r to sys.path' % (d1)\n sys.path.insert(0,d1)\n\n__all__.append('set_local_path')\ndef set_local_path(reldir='', level=1):\n \"\"\" Prepend local directory to sys.path.\n\n The caller is responsible for removing this path by using\n\n restore_path()\n \"\"\"\n from scipy_distutils.misc_util import get_frame\n f = get_frame(level)\n if f.f_locals['__name__']=='__main__':\n testfile = sys.argv[0]\n else:\n testfile = f.f_locals['__file__']\n local_path = os.path.join(os.path.dirname(os.path.abspath(testfile)),reldir)\n if DEBUG:\n print 'Inserting %r to sys.path' % (local_path)\n sys.path.insert(0,local_path)\n\n__all__.append('restore_path')\ndef restore_path():\n if DEBUG:\n print 'Removing %r from sys.path' % (sys.path[0])\n del sys.path[0]\n\n__all__.extend(['jiffies','memusage'])\nif sys.platform[:5]=='linux':\n def jiffies(_proc_pid_stat = '/proc/%s/stat'%(os.getpid()),\n _load_time=time.time()):\n \"\"\" Return number of jiffies (1/100ths of a second) that this\n process has been scheduled in user mode. See man 5 proc. \"\"\"\n try:\n f=open(_proc_pid_stat,'r')\n l = f.readline().split(' ')\n f.close()\n return int(l[13])\n except:\n return int(100*(time.time()-_load_time))\n\n def memusage(_proc_pid_stat = '/proc/%s/stat'%(os.getpid())):\n \"\"\" Return virtual memory size in bytes of the running python.\n \"\"\"\n try:\n f=open(_proc_pid_stat,'r')\n l = f.readline().split(' ')\n f.close()\n return int(l[22])\n except:\n return\nelse:\n # os.getpid is not in all platforms available.\n # Using time is safe but inaccurate, especially when process\n # was suspended or sleeping.\n def jiffies(_load_time=time.time()):\n \"\"\" Return number of jiffies (1/100ths of a second) that this\n process has been scheduled in user mode. [Emulation with time.time]. \"\"\"\n return int(100*(time.time()-_load_time))\n\n def memusage():\n \"\"\" Return memory usage of running python. [Not implemented]\"\"\"\n return\n\n__all__.append('ScipyTestCase')\nclass ScipyTestCase (unittest.TestCase):\n\n def measure(self,code_str,times=1):\n \"\"\" Return elapsed time for executing code_str in the\n namespace of the caller for given times.\n \"\"\"\n frame = sys._getframe(1)\n locs,globs = frame.f_locals,frame.f_globals\n code = compile(code_str,\n 'ScipyTestCase runner for '+self.__class__.__name__,\n 'exec')\n i = 0\n elapsed = jiffies()\n while i>> ScipyTest().test(level=1,verbosity=2)\n\n is package name or its module object.\n\n Package is supposed to contain a directory tests/\n with test_*.py files where * refers to the names of submodules.\n\n test_*.py files are supposed to define a classes, derived\n from ScipyTestCase or unittest.TestCase, with methods having\n names starting with test or bench or check.\n\n And that is it! No need to implement test or test_suite functions\n in each .py file.\n\n Also old styled test_suite(level=1) hooks are supported but\n soon to be removed.\n \"\"\"\n def __init__(self, package='__main__'):\n self.package = package\n\n def _module_str(self, module):\n filename = module.__file__[-30:]\n if filename!=module.__file__:\n filename = '...'+filename\n return '' % (`module.__name__`, `filename`)\n\n def _get_method_names(self,clsobj,level):\n names = []\n for mthname in _get_all_method_names(clsobj):\n if mthname[:5] not in ['bench','check'] \\\n and mthname[:4] not in ['test']:\n continue\n mth = getattr(clsobj, mthname)\n if type(mth) is not types.MethodType:\n continue\n d = mth.im_func.func_defaults\n if d is not None:\n mthlevel = d[0]\n else:\n mthlevel = 1\n if level>=mthlevel:\n if mthname not in names:\n names.append(mthname)\n for base in clsobj.__bases__:\n for n in self._get_method_names(base,level):\n if n not in names:\n names.append(n) \n return names\n\n def _get_module_tests(self,module,level):\n mstr = self._module_str\n d,f = os.path.split(module.__file__)\n\n short_module_name = os.path.splitext(os.path.basename(f))[0]\n if short_module_name=='__init__':\n short_module_name = module.__name__.split('.')[-1]\n\n test_dir = os.path.join(d,'tests')\n test_file = os.path.join(test_dir,'test_'+short_module_name+'.py')\n\n local_test_dir = os.path.join(os.getcwd(),'tests')\n local_test_file = os.path.join(local_test_dir,\n 'test_'+short_module_name+'.py')\n if os.path.basename(os.path.dirname(local_test_dir)) \\\n == os.path.basename(os.path.dirname(test_dir)) \\\n and os.path.isfile(local_test_file):\n test_file = local_test_file\n\n if not os.path.isfile(test_file):\n if short_module_name[:5]=='info_' \\\n and short_module_name[5:]==module.__name__.split('.')[-2]:\n return []\n if short_module_name in ['__cvs_version__','__svn_version__']:\n return []\n if short_module_name[-8:]=='_version' \\\n and short_module_name[:-8]==module.__name__.split('.')[-2]:\n return []\n print ' !! No test file %r found for %s' \\\n % (os.path.basename(test_file), mstr(module))\n return []\n\n try:\n if sys.version[:3]=='2.1':\n # Workaround for Python 2.1 .pyc file generator bug\n import random\n pref = '-nopyc'+`random.randint(1,100)`\n else:\n pref = ''\n f = open(test_file,'r')\n test_module = imp.load_module(\\\n module.__name__+'.test_'+short_module_name+pref,\n f, test_file+pref,('.py', 'r', 1))\n f.close()\n if sys.version[:3]=='2.1' and os.path.isfile(test_file+pref+'c'):\n os.remove(test_file+pref+'c')\n except:\n print ' !! FAILURE importing tests for ', mstr(module)\n print ' ',\n output_exception()\n return []\n return self._get_suite_list(test_module, level, module.__name__)\n\n def _get_suite_list(self, test_module, level, module_name='__main__'):\n mstr = self._module_str\n if hasattr(test_module,'test_suite'):\n # Using old styled test suite\n try:\n total_suite = test_module.test_suite(level)\n return total_suite._tests\n except:\n print ' !! FAILURE building tests for ', mstr(test_module)\n print ' ',\n output_exception()\n return []\n suite_list = []\n for name in dir(test_module):\n obj = getattr(test_module, name)\n if type(obj) is not type(unittest.TestCase) \\\n or not issubclass(obj, unittest.TestCase) \\\n or obj.__name__[:4] != 'test':\n continue\n for mthname in self._get_method_names(obj,level):\n suite = obj(mthname)\n if getattr(suite,'isrunnable',lambda mthname:1)(mthname):\n suite_list.append(suite)\n print ' Found',len(suite_list),'tests for',module_name\n return suite_list\n\n def _touch_ppimported(self, module):\n from scipy_base.ppimport import _ModuleLoader\n if os.path.isdir(os.path.join(os.path.dirname(module.__file__),'tests')):\n # only touching those modules that have tests/ directory\n try: module._pliuh_plauh\n except AttributeError: pass\n for name in dir(module):\n obj = getattr(module,name)\n if isinstance(obj,_ModuleLoader) \\\n and not hasattr(obj,'_ppimport_module') \\\n and not hasattr(obj,'_ppimport_exc_info'):\n self._touch_ppimported(obj)\n\n def test(self,level=1,verbosity=1):\n \"\"\" Run Scipy module test suite with level and verbosity.\n \"\"\"\n if type(self.package) is type(''):\n exec 'import %s as this_package' % (self.package)\n else:\n this_package = self.package\n\n self._touch_ppimported(this_package)\n\n package_name = this_package.__name__\n\n suites = []\n for name, module in sys.modules.items():\n if package_name != name[:len(package_name)] \\\n or module is None \\\n or os.path.basename(os.path.dirname(module.__file__))=='tests':\n continue\n suites.extend(self._get_module_tests(module, level))\n\n suites.extend(self._get_suite_list(sys.modules[package_name], level))\n\n all_tests = unittest.TestSuite(suites)\n runner = unittest.TextTestRunner(verbosity=verbosity)\n runner.run(all_tests)\n return runner\n\n def run(self):\n \"\"\" Run Scipy module test suite with level and verbosity\n taken from sys.argv. Requires optparse module.\n \"\"\"\n try:\n from optparse import OptionParser\n except ImportError:\n print 'Failed to import optparse module, ignoring.'\n return self.test()\n usage = r'usage: %prog [-v ] [-l ]'\n parser = OptionParser(usage)\n parser.add_option(\"-v\", \"--verbosity\",\n action=\"store\",\n dest=\"verbosity\",\n default=1,\n type='int')\n parser.add_option(\"-l\", \"--level\",\n action=\"store\",\n dest=\"level\",\n default=1,\n type='int')\n (options, args) = parser.parse_args()\n self.test(options.level,options.verbosity)\n\n#------------\n \ndef remove_ignored_patterns(files,pattern):\n from fnmatch import fnmatch\n good_files = []\n for file in files:\n if not fnmatch(file,pattern):\n good_files.append(file)\n return good_files\n\ndef remove_ignored_files(original,ignored_files,cur_dir):\n \"\"\" This is actually expanded to do pattern matching.\n\n \"\"\"\n if not ignored_files: ignored_files = []\n ignored_modules = map(lambda x: x+'.py',ignored_files)\n ignored_packages = ignored_files[:]\n # always ignore setup.py and __init__.py files\n ignored_files = ['setup.py','setup_*.py','__init__.py']\n ignored_files += ignored_modules + ignored_packages\n ignored_files = map(lambda x,cur_dir=cur_dir: os.path.join(cur_dir,x),\n ignored_files)\n #print 'ignored:', ignored_files\n #good_files = filter(lambda x,ignored = ignored_files: x not in ignored,\n # original)\n good_files = original\n for pattern in ignored_files:\n good_files = remove_ignored_patterns(good_files,pattern)\n\n return good_files\n\n__all__.append('harvest_modules')\ndef harvest_modules(package,ignore=None):\n \"\"\"* Retreive a list of all modules that live within a package.\n\n Only retreive files that are immediate children of the\n package -- do not recurse through child packages or\n directories. The returned list contains actual modules, not\n just their names.\n *\"\"\"\n d,f = os.path.split(package.__file__)\n\n # go through the directory and import every py file there.\n common_dir = os.path.join(d,'*.py')\n py_files = glob.glob(common_dir)\n #py_files.remove(os.path.join(d,'__init__.py'))\n #py_files.remove(os.path.join(d,'setup.py'))\n\n py_files = remove_ignored_files(py_files,ignore,d)\n #print 'py_files:', py_files\n try:\n prefix = package.__name__\n except:\n prefix = ''\n\n all_modules = []\n for file in py_files:\n d,f = os.path.split(file)\n base,ext = os.path.splitext(f)\n mod = prefix + '.' + base\n #print 'module: import ' + mod\n try:\n exec ('import ' + mod)\n all_modules.append(eval(mod))\n except:\n print 'FAILURE to import ' + mod\n output_exception()\n\n return all_modules\n\n__all__.append('harvest_packages')\ndef harvest_packages(package,ignore = None):\n \"\"\" Retreive a list of all sub-packages that live within a package.\n\n Only retreive packages that are immediate children of this\n package -- do not recurse through child packages or\n directories. The returned list contains actual package objects, not\n just their names.\n \"\"\"\n join = os.path.join\n\n d,f = os.path.split(package.__file__)\n\n common_dir = os.path.abspath(d)\n all_files = os.listdir(d)\n\n all_files = remove_ignored_files(all_files,ignore,'')\n #print 'all_files:', all_files\n try:\n prefix = package.__name__\n except:\n prefix = ''\n all_packages = []\n for directory in all_files:\n path = join(common_dir,directory)\n if os.path.isdir(path) and \\\n os.path.exists(join(path,'__init__.py')):\n sub_package = prefix + '.' + directory\n #print 'sub-package import ' + sub_package\n try:\n exec ('import ' + sub_package)\n all_packages.append(eval(sub_package))\n except:\n print 'FAILURE to import ' + sub_package\n output_exception()\n return all_packages\n\n__all__.append('harvest_modules_and_packages')\ndef harvest_modules_and_packages(package,ignore=None):\n \"\"\" Retreive list of all packages and modules that live within a package.\n\n See harvest_packages() and harvest_modules()\n \"\"\"\n all = harvest_modules(package,ignore) + harvest_packages(package,ignore)\n return all\n\n__all__.append('harvest_test_suites')\ndef harvest_test_suites(package,ignore = None,level=10):\n \"\"\"\n package -- the module to test. This is an actual module object\n (not a string)\n ignore -- a list of module names to omit from the tests\n level -- a value between 1 and 10. 1 will run the minimum number\n of tests. This is a fast \"smoke test\". Tests that take\n longer to run should have higher numbers ranging up to 10.\n \"\"\"\n suites=[]\n test_modules = harvest_modules_and_packages(package,ignore)\n #for i in test_modules:\n # print i.__name__\n for module in test_modules:\n if hasattr(module,'test_suite'):\n try:\n suite = module.test_suite(level=level)\n if suite:\n suites.append(suite)\n else:\n print \" !! FAILURE without error - shouldn't happen\",\n print module.__name__\n except:\n print ' !! FAILURE building test for ', module.__name__\n print ' ',\n output_exception()\n else:\n try:\n print 'No test suite found for ', module.__name__\n except AttributeError:\n # __version__.py getting replaced by a string throws a kink\n # in checking for modules, so we think is a module has\n # actually been overwritten\n print 'No test suite found for ', str(module)\n total_suite = unittest.TestSuite(suites)\n return total_suite\n\n__all__.append('module_test')\ndef module_test(mod_name,mod_file,level=10):\n \"\"\"*\n\n *\"\"\"\n #print 'testing', mod_name\n d,f = os.path.split(mod_file)\n\n # insert the tests directory to the python path\n test_dir = os.path.join(d,'tests')\n sys.path.insert(0,test_dir)\n\n # call the \"test_xxx.test()\" function for the appropriate\n # module.\n\n # This should deal with package naming issues correctly\n short_mod_name = string.split(mod_name,'.')[-1]\n test_module = 'test_' + short_mod_name\n test_string = 'import %s;reload(%s);%s.test(%d)' % \\\n ((test_module,)*3 + (level,))\n\n # This would be better cause it forces a reload of the orginal\n # module. It doesn't behave with packages however.\n #test_string = 'reload(%s);import %s;reload(%s);%s.test(%d)' % \\\n # ((mod_name,) + (test_module,)*3)\n exec(test_string)\n\n # remove test directory from python path.\n sys.path = sys.path[1:]\n\n__all__.append('module_test_suite')\ndef module_test_suite(mod_name,mod_file,level=10):\n #try:\n print ' creating test suite for:', mod_name\n d,f = os.path.split(mod_file)\n\n # insert the tests directory to the python path\n test_dir = os.path.join(d,'tests')\n sys.path.insert(0,test_dir)\n\n # call the \"test_xxx.test()\" function for the appropriate\n # module.\n\n # This should deal with package naming issues correctly\n short_mod_name = string.split(mod_name,'.')[-1]\n test_module = 'test_' + short_mod_name\n test_string = 'import %s;reload(%s);suite = %s.test_suite(%d)' % \\\n ((test_module,)*3+(level,))\n #print test_string\n exec(test_string)\n\n # remove test directory from python path.\n sys.path = sys.path[1:]\n return suite\n #except:\n # print ' !! FAILURE loading test suite from', test_module, ':'\n # print ' ',\n # output_exception()\n\n\n# Utility function to facilitate testing.\n\n__all__.append('assert_equal')\ndef assert_equal(actual,desired,err_msg='',verbose=1):\n \"\"\" Raise an assertion if two items are not\n equal. I think this should be part of unittest.py\n \"\"\"\n msg = '\\nItems are not equal:\\n' + err_msg\n try:\n if ( verbose and len(repr(desired)) < 100 and len(repr(actual)) ):\n msg = msg \\\n + 'DESIRED: ' + repr(desired) \\\n + '\\nACTUAL: ' + repr(actual)\n except:\n msg = msg \\\n + 'DESIRED: ' + repr(desired) \\\n + '\\nACTUAL: ' + repr(actual)\n assert all(desired == actual), msg\n\n__all__.append('assert_almost_equal')\ndef assert_almost_equal(actual,desired,decimal=7,err_msg='',verbose=1):\n \"\"\" Raise an assertion if two items are not\n equal. I think this should be part of unittest.py\n \"\"\"\n msg = '\\nItems are not equal:\\n' + err_msg\n try:\n if ( verbose and len(repr(desired)) < 100 and len(repr(actual)) ):\n msg = msg \\\n + 'DESIRED: ' + repr(desired) \\\n + '\\nACTUAL: ' + repr(actual)\n except:\n msg = msg \\\n + 'DESIRED: ' + repr(desired) \\\n + '\\nACTUAL: ' + repr(actual)\n assert all(round(abs(desired - actual),decimal) == 0), msg\n\n__all__.append('assert_approx_equal')\ndef assert_approx_equal(actual,desired,significant=7,err_msg='',verbose=1):\n \"\"\" Raise an assertion if two items are not\n equal. I think this should be part of unittest.py\n Approximately equal is defined as the number of significant digits\n correct\n \"\"\"\n msg = '\\nItems are not equal to %d significant digits:\\n' % significant\n msg += err_msg\n actual, desired = map(float, (actual, desired))\n # Normalized the numbers to be in range (-10.0,10.0)\n scale = pow(10,math.floor(math.log10(0.5*(abs(desired)+abs(actual)))))\n try:\n sc_desired = desired/scale\n except ZeroDivisionError:\n sc_desired = 0.0\n try:\n sc_actual = actual/scale\n except ZeroDivisionError:\n sc_actual = 0.0\n try:\n if ( verbose and len(repr(desired)) < 100 and len(repr(actual)) ):\n msg = msg \\\n + 'DESIRED: ' + repr(desired) \\\n + '\\nACTUAL: ' + repr(actual)\n except:\n msg = msg \\\n + 'DESIRED: ' + repr(desired) \\\n + '\\nACTUAL: ' + repr(actual)\n assert all(math.fabs(sc_desired - sc_actual) < pow(10.,-1*significant)), msg\n\n\n__all__.append('assert_array_equal')\ndef assert_array_equal(x,y,err_msg=''):\n x,y = asarray(x), asarray(y)\n msg = '\\nArrays are not equal'\n try:\n assert 0 in [len(shape(x)),len(shape(y))] \\\n or (len(shape(x))==len(shape(y)) and \\\n all(equal(shape(x),shape(y)))),\\\n msg + ' (shapes %s, %s mismatch):\\n\\t' \\\n % (shape(x),shape(y)) + err_msg\n reduced = ravel(equal(x,y))\n cond = all(reduced)\n if not cond:\n s1 = array2string(x,precision=16)\n s2 = array2string(y,precision=16)\n if len(s1)>120: s1 = s1[:120] + '...'\n if len(s2)>120: s2 = s2[:120] + '...'\n match = 100-100.0*reduced.tolist().count(1)/len(reduced)\n msg = msg + ' (mismatch %s%%):\\n\\tArray 1: %s\\n\\tArray 2: %s' % (match,s1,s2)\n assert cond,\\\n msg + '\\n\\t' + err_msg\n except ValueError:\n raise ValueError, msg\n\n__all__.append('assert_array_almost_equal')\ndef assert_array_almost_equal(x,y,decimal=6,err_msg=''):\n x = asarray(x)\n y = asarray(y)\n msg = '\\nArrays are not almost equal'\n try:\n cond = all(equal(shape(x),shape(y)))\n if not cond:\n msg = msg + ' (shapes mismatch):\\n\\t'\\\n 'Shape of array 1: %s\\n\\tShape of array 2: %s' % (shape(x),shape(y))\n assert cond, msg + '\\n\\t' + err_msg\n reduced = ravel(equal(less_equal(around(abs(x-y),decimal),10.0**(-decimal)),1))\n cond = all(reduced)\n if not cond:\n s1 = array2string(x,precision=decimal+1)\n s2 = array2string(y,precision=decimal+1)\n if len(s1)>120: s1 = s1[:120] + '...'\n if len(s2)>120: s2 = s2[:120] + '...'\n match = 100-100.0*reduced.tolist().count(1)/len(reduced)\n msg = msg + ' (mismatch %s%%):\\n\\tArray 1: %s\\n\\tArray 2: %s' % (match,s1,s2)\n assert cond,\\\n msg + '\\n\\t' + err_msg\n except ValueError:\n print sys.exc_value\n print shape(x),shape(y)\n print x, y\n raise ValueError, 'arrays are not almost equal'\n\n__all__.append('assert_array_less')\ndef assert_array_less(x,y,err_msg=''):\n x,y = asarray(x), asarray(y)\n msg = '\\nArrays are not less-ordered'\n try:\n assert all(equal(shape(x),shape(y))),\\\n msg + ' (shapes mismatch):\\n\\t' + err_msg\n reduced = ravel(less(x,y))\n cond = all(reduced)\n if not cond:\n s1 = array2string(x,precision=16)\n s2 = array2string(y,precision=16)\n if len(s1)>120: s1 = s1[:120] + '...'\n if len(s2)>120: s2 = s2[:120] + '...'\n match = 100-100.0*reduced.tolist().count(1)/len(reduced)\n msg = msg + ' (mismatch %s%%):\\n\\tArray 1: %s\\n\\tArray 2: %s' % (match,s1,s2)\n assert cond,\\\n msg + '\\n\\t' + err_msg\n except ValueError:\n print shape(x),shape(y)\n raise ValueError, 'arrays are not less-ordered'\n\n__all__.append('rand')\ndef rand(*args):\n \"\"\" Returns an array of random numbers with the given shape.\n used for testing\n \"\"\"\n import random\n results = zeros(args,Float64)\n f = results.flat\n for i in range(len(f)):\n f[i] = random.random()\n return results\n\ndef output_exception():\n try:\n type, value, tb = sys.exc_info()\n info = traceback.extract_tb(tb)\n #this is more verbose\n #traceback.print_exc()\n filename, lineno, function, text = info[-1] # last line only\n print \"%s:%d: %s: %s (in %s)\" %\\\n (filename, lineno, type.__name__, str(value), function)\n finally:\n type = value = tb = None # clean up\n\ntry:\n from scipy_base.numerix import fastumath as math\nexcept ImportError,msg:\n print msg\n import math\n", "source_code_before": "\"\"\"\nUnit-testing\n------------\n\n ScipyTest -- Scipy tests site manager\n ScipyTestCase -- unittest.TestCase with measure method\n IgnoreException -- raise when checking disabled feature ('ignoring' is displayed)\n set_package_path -- prepend package build directory to path\n set_local_path -- prepend local directory (to tests files) to path\n restore_path -- restore path after set_package_path\n\nTiming tools\n------------\n\n jiffies -- return 1/100ths of a second that the current process has used\n memusage -- virtual memory size in bytes of the running python [linux]\n\nUtility functions\n-----------------\n\n assert_equal -- assert equality\n assert_almost_equal -- assert equality with decimal tolerance\n assert_approx_equal -- assert equality with significant digits tolerance\n assert_array_equal -- assert arrays equality\n assert_array_almost_equal -- assert arrays equality with decimal tolerance\n assert_array_less -- assert arrays less-ordering\n rand -- array of random numbers from given shape\n\n\"\"\"\n\n__all__ = []\n\nimport os,sys,time,glob,string,traceback,unittest\nimport types\nimport imp\n\ntry:\n # These are used by Numeric tests.\n # If Numeric and scipy_base are not available, then some of the\n # functions below will not be available.\n from Numeric import alltrue,equal,shape,ravel,around,zeros,Float64,asarray,\\\n less_equal,array2string,less\n # `import scipy_base.fastumath as math` must be at the end of this file.\nexcept ImportError,msg:\n print msg\n\nDEBUG = 0\n\n__all__.append('set_package_path')\ndef set_package_path(level=1):\n \"\"\" Prepend package directory to sys.path.\n\n set_package_path should be called from a test_file.py that\n satisfies the following tree structure:\n\n //test_file.py\n\n Then the first existing path name from the following list\n\n /build/lib.-\n /..\n\n is prepended to sys.path.\n The caller is responsible for removing this path by using\n\n restore_path()\n \"\"\"\n from distutils.util import get_platform\n from scipy_distutils.misc_util import get_frame\n f = get_frame(level)\n if f.f_locals['__name__']=='__main__':\n testfile = sys.argv[0]\n else:\n testfile = f.f_locals['__file__']\n d = os.path.dirname(os.path.dirname(os.path.abspath(testfile)))\n d1 = os.path.join(d,'build','lib.%s-%s'%(get_platform(),sys.version[:3]))\n if not os.path.isdir(d1):\n d1 = os.path.dirname(d)\n if DEBUG:\n print 'Inserting %r to sys.path' % (d1)\n sys.path.insert(0,d1)\n\n__all__.append('set_local_path')\ndef set_local_path(reldir='', level=1):\n \"\"\" Prepend local directory to sys.path.\n\n The caller is responsible for removing this path by using\n\n restore_path()\n \"\"\"\n from scipy_distutils.misc_util import get_frame\n f = get_frame(level)\n if f.f_locals['__name__']=='__main__':\n testfile = sys.argv[0]\n else:\n testfile = f.f_locals['__file__']\n local_path = os.path.join(os.path.dirname(os.path.abspath(testfile)),reldir)\n if DEBUG:\n print 'Inserting %r to sys.path' % (local_path)\n sys.path.insert(0,local_path)\n\n__all__.append('restore_path')\ndef restore_path():\n if DEBUG:\n print 'Removing %r from sys.path' % (sys.path[0])\n del sys.path[0]\n\n__all__.extend(['jiffies','memusage'])\nif sys.platform[:5]=='linux':\n def jiffies(_proc_pid_stat = '/proc/%s/stat'%(os.getpid()),\n _load_time=time.time()):\n \"\"\" Return number of jiffies (1/100ths of a second) that this\n process has been scheduled in user mode. See man 5 proc. \"\"\"\n try:\n f=open(_proc_pid_stat,'r')\n l = f.readline().split(' ')\n f.close()\n return int(l[13])\n except:\n return int(100*(time.time()-_load_time))\n\n def memusage(_proc_pid_stat = '/proc/%s/stat'%(os.getpid())):\n \"\"\" Return virtual memory size in bytes of the running python.\n \"\"\"\n try:\n f=open(_proc_pid_stat,'r')\n l = f.readline().split(' ')\n f.close()\n return int(l[22])\n except:\n return\nelse:\n # os.getpid is not in all platforms available.\n # Using time is safe but inaccurate, especially when process\n # was suspended or sleeping.\n def jiffies(_load_time=time.time()):\n \"\"\" Return number of jiffies (1/100ths of a second) that this\n process has been scheduled in user mode. [Emulation with time.time]. \"\"\"\n return int(100*(time.time()-_load_time))\n\n def memusage():\n \"\"\" Return memory usage of running python. [Not implemented]\"\"\"\n return\n\n__all__.append('ScipyTestCase')\nclass ScipyTestCase (unittest.TestCase):\n\n def measure(self,code_str,times=1):\n \"\"\" Return elapsed time for executing code_str in the\n namespace of the caller for given times.\n \"\"\"\n frame = sys._getframe(1)\n locs,globs = frame.f_locals,frame.f_globals\n code = compile(code_str,\n 'ScipyTestCase runner for '+self.__class__.__name__,\n 'exec')\n i = 0\n elapsed = jiffies()\n while i>> ScipyTest().test(level=1,verbosity=2)\n\n is package name or its module object.\n\n Package is supposed to contain a directory tests/\n with test_*.py files where * refers to the names of submodules.\n\n test_*.py files are supposed to define a classes, derived\n from ScipyTestCase or unittest.TestCase, with methods having\n names starting with test or bench or check.\n\n And that is it! No need to implement test or test_suite functions\n in each .py file.\n\n Also old styled test_suite(level=1) hooks are supported but\n soon to be removed.\n \"\"\"\n def __init__(self, package='__main__'):\n self.package = package\n\n def _module_str(self, module):\n filename = module.__file__[-30:]\n if filename!=module.__file__:\n filename = '...'+filename\n return '' % (`module.__name__`, `filename`)\n\n def _get_method_names(self,clsobj,level):\n names = []\n for mthname in _get_all_method_names(clsobj):\n if mthname[:5] not in ['bench','check'] \\\n and mthname[:4] not in ['test']:\n continue\n mth = getattr(clsobj, mthname)\n if type(mth) is not types.MethodType:\n continue\n d = mth.im_func.func_defaults\n if d is not None:\n mthlevel = d[0]\n else:\n mthlevel = 1\n if level>=mthlevel:\n if mthname not in names:\n names.append(mthname)\n for base in clsobj.__bases__:\n for n in self._get_method_names(base,level):\n if n not in names:\n names.append(n) \n return names\n\n def _get_module_tests(self,module,level):\n mstr = self._module_str\n d,f = os.path.split(module.__file__)\n\n short_module_name = os.path.splitext(os.path.basename(f))[0]\n if short_module_name=='__init__':\n short_module_name = module.__name__.split('.')[-1]\n\n test_dir = os.path.join(d,'tests')\n test_file = os.path.join(test_dir,'test_'+short_module_name+'.py')\n\n local_test_dir = os.path.join(os.getcwd(),'tests')\n local_test_file = os.path.join(local_test_dir,\n 'test_'+short_module_name+'.py')\n if os.path.basename(os.path.dirname(local_test_dir)) \\\n == os.path.basename(os.path.dirname(test_dir)) \\\n and os.path.isfile(local_test_file):\n test_file = local_test_file\n\n if not os.path.isfile(test_file):\n if short_module_name[:5]=='info_' \\\n and short_module_name[5:]==module.__name__.split('.')[-2]:\n return []\n if short_module_name in ['__cvs_version__','__svn_version__']:\n return []\n if short_module_name[-8:]=='_version' \\\n and short_module_name[:-8]==module.__name__.split('.')[-2]:\n return []\n print ' !! No test file %r found for %s' \\\n % (os.path.basename(test_file), mstr(module))\n return []\n\n try:\n if sys.version[:3]=='2.1':\n # Workaround for Python 2.1 .pyc file generator bug\n import random\n pref = '-nopyc'+`random.randint(1,100)`\n else:\n pref = ''\n f = open(test_file,'r')\n test_module = imp.load_module(\\\n module.__name__+'.test_'+short_module_name+pref,\n f, test_file+pref,('.py', 'r', 1))\n f.close()\n if sys.version[:3]=='2.1' and os.path.isfile(test_file+pref+'c'):\n os.remove(test_file+pref+'c')\n except:\n print ' !! FAILURE importing tests for ', mstr(module)\n print ' ',\n output_exception()\n return []\n return self._get_suite_list(test_module, level, module.__name__)\n\n def _get_suite_list(self, test_module, level, module_name='__main__'):\n mstr = self._module_str\n if hasattr(test_module,'test_suite'):\n # Using old styled test suite\n try:\n total_suite = test_module.test_suite(level)\n return total_suite._tests\n except:\n print ' !! FAILURE building tests for ', mstr(test_module)\n print ' ',\n output_exception()\n return []\n suite_list = []\n for name in dir(test_module):\n obj = getattr(test_module, name)\n if type(obj) is not type(unittest.TestCase) \\\n or not issubclass(obj, unittest.TestCase) \\\n or obj.__name__[:4] != 'test':\n continue\n for mthname in self._get_method_names(obj,level):\n suite = obj(mthname)\n if getattr(suite,'isrunnable',lambda mthname:1)(mthname):\n suite_list.append(suite)\n print ' Found',len(suite_list),'tests for',module_name\n return suite_list\n\n def _touch_ppimported(self, module):\n from scipy_base.ppimport import _ModuleLoader\n if os.path.isdir(os.path.join(os.path.dirname(module.__file__),'tests')):\n # only touching those modules that have tests/ directory\n try: module._pliuh_plauh\n except AttributeError: pass\n for name in dir(module):\n obj = getattr(module,name)\n if isinstance(obj,_ModuleLoader) \\\n and not hasattr(obj,'_ppimport_module') \\\n and not hasattr(obj,'_ppimport_exc_info'):\n self._touch_ppimported(obj)\n\n def test(self,level=1,verbosity=1):\n \"\"\" Run Scipy module test suite with level and verbosity.\n \"\"\"\n if type(self.package) is type(''):\n exec 'import %s as this_package' % (self.package)\n else:\n this_package = self.package\n\n self._touch_ppimported(this_package)\n\n package_name = this_package.__name__\n\n suites = []\n for name, module in sys.modules.items():\n if package_name != name[:len(package_name)] \\\n or module is None \\\n or os.path.basename(os.path.dirname(module.__file__))=='tests':\n continue\n suites.extend(self._get_module_tests(module, level))\n\n suites.extend(self._get_suite_list(sys.modules[package_name], level))\n\n all_tests = unittest.TestSuite(suites)\n runner = unittest.TextTestRunner(verbosity=verbosity)\n runner.run(all_tests)\n return runner\n\n def run(self):\n \"\"\" Run Scipy module test suite with level and verbosity\n taken from sys.argv. Requires optparse module.\n \"\"\"\n try:\n from optparse import OptionParser\n except ImportError:\n print 'Failed to import optparse module, ignoring.'\n return self.test()\n usage = r'usage: %prog [-v ] [-l ]'\n parser = OptionParser(usage)\n parser.add_option(\"-v\", \"--verbosity\",\n action=\"store\",\n dest=\"verbosity\",\n default=1,\n type='int')\n parser.add_option(\"-l\", \"--level\",\n action=\"store\",\n dest=\"level\",\n default=1,\n type='int')\n (options, args) = parser.parse_args()\n self.test(options.level,options.verbosity)\n\n#------------\n \ndef remove_ignored_patterns(files,pattern):\n from fnmatch import fnmatch\n good_files = []\n for file in files:\n if not fnmatch(file,pattern):\n good_files.append(file)\n return good_files\n\ndef remove_ignored_files(original,ignored_files,cur_dir):\n \"\"\" This is actually expanded to do pattern matching.\n\n \"\"\"\n if not ignored_files: ignored_files = []\n ignored_modules = map(lambda x: x+'.py',ignored_files)\n ignored_packages = ignored_files[:]\n # always ignore setup.py and __init__.py files\n ignored_files = ['setup.py','setup_*.py','__init__.py']\n ignored_files += ignored_modules + ignored_packages\n ignored_files = map(lambda x,cur_dir=cur_dir: os.path.join(cur_dir,x),\n ignored_files)\n #print 'ignored:', ignored_files\n #good_files = filter(lambda x,ignored = ignored_files: x not in ignored,\n # original)\n good_files = original\n for pattern in ignored_files:\n good_files = remove_ignored_patterns(good_files,pattern)\n\n return good_files\n\n__all__.append('harvest_modules')\ndef harvest_modules(package,ignore=None):\n \"\"\"* Retreive a list of all modules that live within a package.\n\n Only retreive files that are immediate children of the\n package -- do not recurse through child packages or\n directories. The returned list contains actual modules, not\n just their names.\n *\"\"\"\n d,f = os.path.split(package.__file__)\n\n # go through the directory and import every py file there.\n common_dir = os.path.join(d,'*.py')\n py_files = glob.glob(common_dir)\n #py_files.remove(os.path.join(d,'__init__.py'))\n #py_files.remove(os.path.join(d,'setup.py'))\n\n py_files = remove_ignored_files(py_files,ignore,d)\n #print 'py_files:', py_files\n try:\n prefix = package.__name__\n except:\n prefix = ''\n\n all_modules = []\n for file in py_files:\n d,f = os.path.split(file)\n base,ext = os.path.splitext(f)\n mod = prefix + '.' + base\n #print 'module: import ' + mod\n try:\n exec ('import ' + mod)\n all_modules.append(eval(mod))\n except:\n print 'FAILURE to import ' + mod\n output_exception()\n\n return all_modules\n\n__all__.append('harvest_packages')\ndef harvest_packages(package,ignore = None):\n \"\"\" Retreive a list of all sub-packages that live within a package.\n\n Only retreive packages that are immediate children of this\n package -- do not recurse through child packages or\n directories. The returned list contains actual package objects, not\n just their names.\n \"\"\"\n join = os.path.join\n\n d,f = os.path.split(package.__file__)\n\n common_dir = os.path.abspath(d)\n all_files = os.listdir(d)\n\n all_files = remove_ignored_files(all_files,ignore,'')\n #print 'all_files:', all_files\n try:\n prefix = package.__name__\n except:\n prefix = ''\n all_packages = []\n for directory in all_files:\n path = join(common_dir,directory)\n if os.path.isdir(path) and \\\n os.path.exists(join(path,'__init__.py')):\n sub_package = prefix + '.' + directory\n #print 'sub-package import ' + sub_package\n try:\n exec ('import ' + sub_package)\n all_packages.append(eval(sub_package))\n except:\n print 'FAILURE to import ' + sub_package\n output_exception()\n return all_packages\n\n__all__.append('harvest_modules_and_packages')\ndef harvest_modules_and_packages(package,ignore=None):\n \"\"\" Retreive list of all packages and modules that live within a package.\n\n See harvest_packages() and harvest_modules()\n \"\"\"\n all = harvest_modules(package,ignore) + harvest_packages(package,ignore)\n return all\n\n__all__.append('harvest_test_suites')\ndef harvest_test_suites(package,ignore = None,level=10):\n \"\"\"\n package -- the module to test. This is an actual module object\n (not a string)\n ignore -- a list of module names to omit from the tests\n level -- a value between 1 and 10. 1 will run the minimum number\n of tests. This is a fast \"smoke test\". Tests that take\n longer to run should have higher numbers ranging up to 10.\n \"\"\"\n suites=[]\n test_modules = harvest_modules_and_packages(package,ignore)\n #for i in test_modules:\n # print i.__name__\n for module in test_modules:\n if hasattr(module,'test_suite'):\n try:\n suite = module.test_suite(level=level)\n if suite:\n suites.append(suite)\n else:\n print \" !! FAILURE without error - shouldn't happen\",\n print module.__name__\n except:\n print ' !! FAILURE building test for ', module.__name__\n print ' ',\n output_exception()\n else:\n try:\n print 'No test suite found for ', module.__name__\n except AttributeError:\n # __version__.py getting replaced by a string throws a kink\n # in checking for modules, so we think is a module has\n # actually been overwritten\n print 'No test suite found for ', str(module)\n total_suite = unittest.TestSuite(suites)\n return total_suite\n\n__all__.append('module_test')\ndef module_test(mod_name,mod_file,level=10):\n \"\"\"*\n\n *\"\"\"\n #print 'testing', mod_name\n d,f = os.path.split(mod_file)\n\n # insert the tests directory to the python path\n test_dir = os.path.join(d,'tests')\n sys.path.insert(0,test_dir)\n\n # call the \"test_xxx.test()\" function for the appropriate\n # module.\n\n # This should deal with package naming issues correctly\n short_mod_name = string.split(mod_name,'.')[-1]\n test_module = 'test_' + short_mod_name\n test_string = 'import %s;reload(%s);%s.test(%d)' % \\\n ((test_module,)*3 + (level,))\n\n # This would be better cause it forces a reload of the orginal\n # module. It doesn't behave with packages however.\n #test_string = 'reload(%s);import %s;reload(%s);%s.test(%d)' % \\\n # ((mod_name,) + (test_module,)*3)\n exec(test_string)\n\n # remove test directory from python path.\n sys.path = sys.path[1:]\n\n__all__.append('module_test_suite')\ndef module_test_suite(mod_name,mod_file,level=10):\n #try:\n print ' creating test suite for:', mod_name\n d,f = os.path.split(mod_file)\n\n # insert the tests directory to the python path\n test_dir = os.path.join(d,'tests')\n sys.path.insert(0,test_dir)\n\n # call the \"test_xxx.test()\" function for the appropriate\n # module.\n\n # This should deal with package naming issues correctly\n short_mod_name = string.split(mod_name,'.')[-1]\n test_module = 'test_' + short_mod_name\n test_string = 'import %s;reload(%s);suite = %s.test_suite(%d)' % \\\n ((test_module,)*3+(level,))\n #print test_string\n exec(test_string)\n\n # remove test directory from python path.\n sys.path = sys.path[1:]\n return suite\n #except:\n # print ' !! FAILURE loading test suite from', test_module, ':'\n # print ' ',\n # output_exception()\n\n\n# Utility function to facilitate testing.\n\n__all__.append('assert_equal')\ndef assert_equal(actual,desired,err_msg='',verbose=1):\n \"\"\" Raise an assertion if two items are not\n equal. I think this should be part of unittest.py\n \"\"\"\n msg = '\\nItems are not equal:\\n' + err_msg\n try:\n if ( verbose and len(repr(desired)) < 100 and len(repr(actual)) ):\n msg = msg \\\n + 'DESIRED: ' + repr(desired) \\\n + '\\nACTUAL: ' + repr(actual)\n except:\n msg = msg \\\n + 'DESIRED: ' + repr(desired) \\\n + '\\nACTUAL: ' + repr(actual)\n assert desired == actual, msg\n\n__all__.append('assert_almost_equal')\ndef assert_almost_equal(actual,desired,decimal=7,err_msg='',verbose=1):\n \"\"\" Raise an assertion if two items are not\n equal. I think this should be part of unittest.py\n \"\"\"\n msg = '\\nItems are not equal:\\n' + err_msg\n try:\n if ( verbose and len(repr(desired)) < 100 and len(repr(actual)) ):\n msg = msg \\\n + 'DESIRED: ' + repr(desired) \\\n + '\\nACTUAL: ' + repr(actual)\n except:\n msg = msg \\\n + 'DESIRED: ' + repr(desired) \\\n + '\\nACTUAL: ' + repr(actual)\n assert round(abs(desired - actual),decimal) == 0, msg\n\n__all__.append('assert_approx_equal')\ndef assert_approx_equal(actual,desired,significant=7,err_msg='',verbose=1):\n \"\"\" Raise an assertion if two items are not\n equal. I think this should be part of unittest.py\n Approximately equal is defined as the number of significant digits\n correct\n \"\"\"\n msg = '\\nItems are not equal to %d significant digits:\\n' % significant\n msg += err_msg\n actual, desired = map(float, (actual, desired))\n # Normalized the numbers to be in range (-10.0,10.0)\n scale = pow(10,math.floor(math.log10(0.5*(abs(desired)+abs(actual)))))\n try:\n sc_desired = desired/scale\n except ZeroDivisionError:\n sc_desired = 0.0\n try:\n sc_actual = actual/scale\n except ZeroDivisionError:\n sc_actual = 0.0\n try:\n if ( verbose and len(repr(desired)) < 100 and len(repr(actual)) ):\n msg = msg \\\n + 'DESIRED: ' + repr(desired) \\\n + '\\nACTUAL: ' + repr(actual)\n except:\n msg = msg \\\n + 'DESIRED: ' + repr(desired) \\\n + '\\nACTUAL: ' + repr(actual)\n assert math.fabs(sc_desired - sc_actual) < pow(10.,-1*significant), msg\n\n\n__all__.append('assert_array_equal')\ndef assert_array_equal(x,y,err_msg=''):\n x,y = asarray(x), asarray(y)\n msg = '\\nArrays are not equal'\n try:\n assert 0 in [len(shape(x)),len(shape(y))] \\\n or (len(shape(x))==len(shape(y)) and \\\n alltrue(equal(shape(x),shape(y)))),\\\n msg + ' (shapes %s, %s mismatch):\\n\\t' \\\n % (shape(x),shape(y)) + err_msg\n reduced = ravel(equal(x,y))\n cond = alltrue(reduced)\n if not cond:\n s1 = array2string(x,precision=16)\n s2 = array2string(y,precision=16)\n if len(s1)>120: s1 = s1[:120] + '...'\n if len(s2)>120: s2 = s2[:120] + '...'\n match = 100-100.0*reduced.tolist().count(1)/len(reduced)\n msg = msg + ' (mismatch %s%%):\\n\\tArray 1: %s\\n\\tArray 2: %s' % (match,s1,s2)\n assert cond,\\\n msg + '\\n\\t' + err_msg\n except ValueError:\n raise ValueError, msg\n\n__all__.append('assert_array_almost_equal')\ndef assert_array_almost_equal(x,y,decimal=6,err_msg=''):\n x = asarray(x)\n y = asarray(y)\n msg = '\\nArrays are not almost equal'\n try:\n cond = alltrue(equal(shape(x),shape(y)))\n if not cond:\n msg = msg + ' (shapes mismatch):\\n\\t'\\\n 'Shape of array 1: %s\\n\\tShape of array 2: %s' % (shape(x),shape(y))\n assert cond, msg + '\\n\\t' + err_msg\n reduced = ravel(equal(less_equal(around(abs(x-y),decimal),10.0**(-decimal)),1))\n cond = alltrue(reduced)\n if not cond:\n s1 = array2string(x,precision=decimal+1)\n s2 = array2string(y,precision=decimal+1)\n if len(s1)>120: s1 = s1[:120] + '...'\n if len(s2)>120: s2 = s2[:120] + '...'\n match = 100-100.0*reduced.tolist().count(1)/len(reduced)\n msg = msg + ' (mismatch %s%%):\\n\\tArray 1: %s\\n\\tArray 2: %s' % (match,s1,s2)\n assert cond,\\\n msg + '\\n\\t' + err_msg\n except ValueError:\n print sys.exc_value\n print shape(x),shape(y)\n print x, y\n raise ValueError, 'arrays are not almost equal'\n\n__all__.append('assert_array_less')\ndef assert_array_less(x,y,err_msg=''):\n x,y = asarray(x), asarray(y)\n msg = '\\nArrays are not less-ordered'\n try:\n assert alltrue(equal(shape(x),shape(y))),\\\n msg + ' (shapes mismatch):\\n\\t' + err_msg\n reduced = ravel(less(x,y))\n cond = alltrue(reduced)\n if not cond:\n s1 = array2string(x,precision=16)\n s2 = array2string(y,precision=16)\n if len(s1)>120: s1 = s1[:120] + '...'\n if len(s2)>120: s2 = s2[:120] + '...'\n match = 100-100.0*reduced.tolist().count(1)/len(reduced)\n msg = msg + ' (mismatch %s%%):\\n\\tArray 1: %s\\n\\tArray 2: %s' % (match,s1,s2)\n assert cond,\\\n msg + '\\n\\t' + err_msg\n except ValueError:\n print shape(x),shape(y)\n raise ValueError, 'arrays are not less-ordered'\n\n__all__.append('rand')\ndef rand(*args):\n \"\"\" Returns an array of random numbers with the given shape.\n used for testing\n \"\"\"\n import random\n results = zeros(args,Float64)\n f = results.flat\n for i in range(len(f)):\n f[i] = random.random()\n return results\n\ndef output_exception():\n try:\n type, value, tb = sys.exc_info()\n info = traceback.extract_tb(tb)\n #this is more verbose\n #traceback.print_exc()\n filename, lineno, function, text = info[-1] # last line only\n print \"%s:%d: %s: %s (in %s)\" %\\\n (filename, lineno, type.__name__, str(value), function)\n finally:\n type = value = tb = None # clean up\n\ntry:\n import scipy_base.fastumath as math\nexcept ImportError,msg:\n print msg\n import math\n", "methods": [ { "name": "set_package_path", "long_name": "set_package_path( level = 1 )", "filename": "testing.py", "nloc": 15, "complexity": 4, "token_count": 146, "parameters": [ "level" ], "start_line": 49, "end_line": 80, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 32, "top_nesting_level": 0 }, { "name": "set_local_path", "long_name": "set_local_path( reldir = '' , level = 1 )", "filename": "testing.py", "nloc": 11, "complexity": 3, "token_count": 97, "parameters": [ "reldir", "level" ], "start_line": 83, "end_line": 99, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 17, "top_nesting_level": 0 }, { "name": "restore_path", "long_name": "restore_path( )", "filename": "testing.py", "nloc": 4, "complexity": 2, "token_count": 25, "parameters": [], "start_line": 102, "end_line": 105, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 4, "top_nesting_level": 0 }, { "name": "jiffies", "long_name": "jiffies( _proc_pid_stat = '/proc/%s/stat' % ( os . getpid ( )", "filename": "testing.py", "nloc": 2, "complexity": 1, "token_count": 23, "parameters": [ "_proc_pid_stat" ], "start_line": 109, "end_line": 110, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 2, "top_nesting_level": 1 }, { "name": "memusage", "long_name": "memusage( _proc_pid_stat = '/proc/%s/stat' % ( os . getpid ( )", "filename": "testing.py", "nloc": 10, "complexity": 2, "token_count": 54, "parameters": [ "_proc_pid_stat" ], "start_line": 121, "end_line": 130, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 10, "top_nesting_level": 1 }, { "name": "jiffies", "long_name": "jiffies( _load_time = time . time ( )", "filename": "testing.py", "nloc": 4, "complexity": 1, "token_count": 27, "parameters": [ "_load_time" ], "start_line": 135, "end_line": 138, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 4, "top_nesting_level": 1 }, { "name": "memusage", "long_name": "memusage( )", "filename": "testing.py", "nloc": 2, "complexity": 1, "token_count": 6, "parameters": [], "start_line": 140, "end_line": 142, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 3, "top_nesting_level": 1 }, { "name": "measure", "long_name": "measure( self , code_str , times = 1 )", "filename": "testing.py", "nloc": 13, "complexity": 2, "token_count": 82, "parameters": [ "self", "code_str", "times" ], "start_line": 147, "end_line": 162, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 16, "top_nesting_level": 1 }, { "name": "__call__", "long_name": "__call__( self , result = None )", "filename": "testing.py", "nloc": 24, "complexity": 6, "token_count": 224, "parameters": [ "self", "result" ], "start_line": 164, "end_line": 188, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 25, "top_nesting_level": 1 }, { "name": "__init__", "long_name": "__init__( self , stream )", "filename": "testing.py", "nloc": 3, "complexity": 1, "token_count": 18, "parameters": [ "self", "stream" ], "start_line": 191, "end_line": 193, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 3, "top_nesting_level": 1 }, { "name": "write", "long_name": "write( self , message )", "filename": "testing.py", "nloc": 6, "complexity": 3, "token_count": 47, "parameters": [ "self", "message" ], "start_line": 194, "end_line": 199, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 6, "top_nesting_level": 1 }, { "name": "writeln", "long_name": "writeln( self , message )", "filename": "testing.py", "nloc": 2, "complexity": 1, "token_count": 15, "parameters": [ "self", "message" ], "start_line": 200, "end_line": 201, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 2, "top_nesting_level": 1 }, { "name": "_get_all_method_names", "long_name": "_get_all_method_names( cls )", "filename": "testing.py", "nloc": 8, "complexity": 5, "token_count": 56, "parameters": [ "cls" ], "start_line": 209, "end_line": 216, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 8, "top_nesting_level": 0 }, { "name": "__init__", "long_name": "__init__( self , package = '__main__' )", "filename": "testing.py", "nloc": 2, "complexity": 1, "token_count": 14, "parameters": [ "self", "package" ], "start_line": 240, "end_line": 241, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 2, "top_nesting_level": 1 }, { "name": "_module_str", "long_name": "_module_str( self , module )", "filename": "testing.py", "nloc": 5, "complexity": 2, "token_count": 43, "parameters": [ "self", "module" ], "start_line": 243, "end_line": 247, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 5, "top_nesting_level": 1 }, { "name": "_get_method_names", "long_name": "_get_method_names( self , clsobj , level )", "filename": "testing.py", "nloc": 22, "complexity": 11, "token_count": 142, "parameters": [ "self", "clsobj", "level" ], "start_line": 249, "end_line": 270, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 22, "top_nesting_level": 1 }, { "name": "_get_module_tests", "long_name": "_get_module_tests( self , module , level )", "filename": "testing.py", "nloc": 46, "complexity": 14, "token_count": 428, "parameters": [ "self", "module", "level" ], "start_line": 272, "end_line": 323, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 52, "top_nesting_level": 1 }, { "name": "_get_suite_list", "long_name": "_get_suite_list( self , test_module , level , module_name = '__main__' )", "filename": "testing.py", "nloc": 24, "complexity": 9, "token_count": 168, "parameters": [ "self", "test_module", "level", "module_name" ], "start_line": 325, "end_line": 349, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 25, "top_nesting_level": 1 }, { "name": "_touch_ppimported", "long_name": "_touch_ppimported( self , module )", "filename": "testing.py", "nloc": 11, "complexity": 7, "token_count": 98, "parameters": [ "self", "module" ], "start_line": 351, "end_line": 362, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 12, "top_nesting_level": 1 }, { "name": "test", "long_name": "test( self , level = 1 , verbosity = 1 )", "filename": "testing.py", "nloc": 19, "complexity": 6, "token_count": 166, "parameters": [ "self", "level", "verbosity" ], "start_line": 364, "end_line": 389, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 26, "top_nesting_level": 1 }, { "name": "run", "long_name": "run( self )", "filename": "testing.py", "nloc": 20, "complexity": 2, "token_count": 104, "parameters": [ "self" ], "start_line": 391, "end_line": 413, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 23, "top_nesting_level": 1 }, { "name": "remove_ignored_patterns", "long_name": "remove_ignored_patterns( files , pattern )", "filename": "testing.py", "nloc": 7, "complexity": 3, "token_count": 37, "parameters": [ "files", "pattern" ], "start_line": 417, "end_line": 423, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 7, "top_nesting_level": 0 }, { "name": "remove_ignored_files", "long_name": "remove_ignored_files( original , ignored_files , cur_dir )", "filename": "testing.py", "nloc": 12, "complexity": 3, "token_count": 93, "parameters": [ "original", "ignored_files", "cur_dir" ], "start_line": 425, "end_line": 444, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 20, "top_nesting_level": 0 }, { "name": "harvest_modules", "long_name": "harvest_modules( package , ignore = None )", "filename": "testing.py", "nloc": 21, "complexity": 4, "token_count": 134, "parameters": [ "package", "ignore" ], "start_line": 447, "end_line": 483, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 37, "top_nesting_level": 0 }, { "name": "harvest_packages", "long_name": "harvest_packages( package , ignore = None )", "filename": "testing.py", "nloc": 23, "complexity": 6, "token_count": 148, "parameters": [ "package", "ignore" ], "start_line": 486, "end_line": 520, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 35, "top_nesting_level": 0 }, { "name": "harvest_modules_and_packages", "long_name": "harvest_modules_and_packages( package , ignore = None )", "filename": "testing.py", "nloc": 3, "complexity": 1, "token_count": 27, "parameters": [ "package", "ignore" ], "start_line": 523, "end_line": 529, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 7, "top_nesting_level": 0 }, { "name": "harvest_test_suites", "long_name": "harvest_test_suites( package , ignore = None , level = 10 )", "filename": "testing.py", "nloc": 23, "complexity": 6, "token_count": 113, "parameters": [ "package", "ignore", "level" ], "start_line": 532, "end_line": 567, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 36, "top_nesting_level": 0 }, { "name": "module_test", "long_name": "module_test( mod_name , mod_file , level = 10 )", "filename": "testing.py", "nloc": 10, "complexity": 1, "token_count": 98, "parameters": [ "mod_name", "mod_file", "level" ], "start_line": 570, "end_line": 597, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 28, "top_nesting_level": 0 }, { "name": "module_test_suite", "long_name": "module_test_suite( mod_name , mod_file , level = 10 )", "filename": "testing.py", "nloc": 12, "complexity": 1, "token_count": 103, "parameters": [ "mod_name", "mod_file", "level" ], "start_line": 600, "end_line": 622, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 23, "top_nesting_level": 0 }, { "name": "assert_equal", "long_name": "assert_equal( actual , desired , err_msg = '' , verbose = 1 )", "filename": "testing.py", "nloc": 12, "complexity": 5, "token_count": 95, "parameters": [ "actual", "desired", "err_msg", "verbose" ], "start_line": 632, "end_line": 646, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 15, "top_nesting_level": 0 }, { "name": "assert_almost_equal", "long_name": "assert_almost_equal( actual , desired , decimal = 7 , err_msg = '' , verbose = 1 )", "filename": "testing.py", "nloc": 12, "complexity": 5, "token_count": 109, "parameters": [ "actual", "desired", "decimal", "err_msg", "verbose" ], "start_line": 649, "end_line": 663, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 15, "top_nesting_level": 0 }, { "name": "assert_approx_equal", "long_name": "assert_approx_equal( actual , desired , significant = 7 , err_msg = '' , verbose = 1 )", "filename": "testing.py", "nloc": 23, "complexity": 7, "token_count": 194, "parameters": [ "actual", "desired", "significant", "err_msg", "verbose" ], "start_line": 666, "end_line": 694, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 29, "top_nesting_level": 0 }, { "name": "assert_array_equal", "long_name": "assert_array_equal( x , y , err_msg = '' )", "filename": "testing.py", "nloc": 22, "complexity": 7, "token_count": 232, "parameters": [ "x", "y", "err_msg" ], "start_line": 698, "end_line": 719, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 22, "top_nesting_level": 0 }, { "name": "assert_array_almost_equal", "long_name": "assert_array_almost_equal( x , y , decimal = 6 , err_msg = '' )", "filename": "testing.py", "nloc": 26, "complexity": 6, "token_count": 251, "parameters": [ "x", "y", "decimal", "err_msg" ], "start_line": 722, "end_line": 747, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 26, "top_nesting_level": 0 }, { "name": "assert_array_less", "long_name": "assert_array_less( x , y , err_msg = '' )", "filename": "testing.py", "nloc": 20, "complexity": 5, "token_count": 189, "parameters": [ "x", "y", "err_msg" ], "start_line": 750, "end_line": 769, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 20, "top_nesting_level": 0 }, { "name": "rand", "long_name": "rand( * args )", "filename": "testing.py", "nloc": 7, "complexity": 2, "token_count": 45, "parameters": [ "args" ], "start_line": 772, "end_line": 781, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 10, "top_nesting_level": 0 }, { "name": "output_exception", "long_name": "output_exception( )", "filename": "testing.py", "nloc": 9, "complexity": 2, "token_count": 67, "parameters": [], "start_line": 783, "end_line": 793, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 11, "top_nesting_level": 0 } ], "methods_before": [ { "name": "set_package_path", "long_name": "set_package_path( level = 1 )", "filename": "testing.py", "nloc": 15, "complexity": 4, "token_count": 146, "parameters": [ "level" ], "start_line": 50, "end_line": 81, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 32, "top_nesting_level": 0 }, { "name": "set_local_path", "long_name": "set_local_path( reldir = '' , level = 1 )", "filename": "testing.py", "nloc": 11, "complexity": 3, "token_count": 97, "parameters": [ "reldir", "level" ], "start_line": 84, "end_line": 100, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 17, "top_nesting_level": 0 }, { "name": "restore_path", "long_name": "restore_path( )", "filename": "testing.py", "nloc": 4, "complexity": 2, "token_count": 25, "parameters": [], "start_line": 103, "end_line": 106, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 4, "top_nesting_level": 0 }, { "name": "jiffies", "long_name": "jiffies( _proc_pid_stat = '/proc/%s/stat' % ( os . getpid ( )", "filename": "testing.py", "nloc": 2, "complexity": 1, "token_count": 23, "parameters": [ "_proc_pid_stat" ], "start_line": 110, "end_line": 111, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 2, "top_nesting_level": 1 }, { "name": "memusage", "long_name": "memusage( _proc_pid_stat = '/proc/%s/stat' % ( os . getpid ( )", "filename": "testing.py", "nloc": 10, "complexity": 2, "token_count": 54, "parameters": [ "_proc_pid_stat" ], "start_line": 122, "end_line": 131, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 10, "top_nesting_level": 1 }, { "name": "jiffies", "long_name": "jiffies( _load_time = time . time ( )", "filename": "testing.py", "nloc": 4, "complexity": 1, "token_count": 27, "parameters": [ "_load_time" ], "start_line": 136, "end_line": 139, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 4, "top_nesting_level": 1 }, { "name": "memusage", "long_name": "memusage( )", "filename": "testing.py", "nloc": 2, "complexity": 1, "token_count": 6, "parameters": [], "start_line": 141, "end_line": 143, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 3, "top_nesting_level": 1 }, { "name": "measure", "long_name": "measure( self , code_str , times = 1 )", "filename": "testing.py", "nloc": 13, "complexity": 2, "token_count": 82, "parameters": [ "self", "code_str", "times" ], "start_line": 148, "end_line": 163, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 16, "top_nesting_level": 1 }, { "name": "__call__", "long_name": "__call__( self , result = None )", "filename": "testing.py", "nloc": 24, "complexity": 6, "token_count": 224, "parameters": [ "self", "result" ], "start_line": 165, "end_line": 189, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 25, "top_nesting_level": 1 }, { "name": "__init__", "long_name": "__init__( self , stream )", "filename": "testing.py", "nloc": 3, "complexity": 1, "token_count": 18, "parameters": [ "self", "stream" ], "start_line": 192, "end_line": 194, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 3, "top_nesting_level": 1 }, { "name": "write", "long_name": "write( self , message )", "filename": "testing.py", "nloc": 6, "complexity": 3, "token_count": 47, "parameters": [ "self", "message" ], "start_line": 195, "end_line": 200, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 6, "top_nesting_level": 1 }, { "name": "writeln", "long_name": "writeln( self , message )", "filename": "testing.py", "nloc": 2, "complexity": 1, "token_count": 15, "parameters": [ "self", "message" ], "start_line": 201, "end_line": 202, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 2, "top_nesting_level": 1 }, { "name": "_get_all_method_names", "long_name": "_get_all_method_names( cls )", "filename": "testing.py", "nloc": 8, "complexity": 5, "token_count": 56, "parameters": [ "cls" ], "start_line": 210, "end_line": 217, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 8, "top_nesting_level": 0 }, { "name": "__init__", "long_name": "__init__( self , package = '__main__' )", "filename": "testing.py", "nloc": 2, "complexity": 1, "token_count": 14, "parameters": [ "self", "package" ], "start_line": 241, "end_line": 242, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 2, "top_nesting_level": 1 }, { "name": "_module_str", "long_name": "_module_str( self , module )", "filename": "testing.py", "nloc": 5, "complexity": 2, "token_count": 43, "parameters": [ "self", "module" ], "start_line": 244, "end_line": 248, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 5, "top_nesting_level": 1 }, { "name": "_get_method_names", "long_name": "_get_method_names( self , clsobj , level )", "filename": "testing.py", "nloc": 22, "complexity": 11, "token_count": 142, "parameters": [ "self", "clsobj", "level" ], "start_line": 250, "end_line": 271, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 22, "top_nesting_level": 1 }, { "name": "_get_module_tests", "long_name": "_get_module_tests( self , module , level )", "filename": "testing.py", "nloc": 46, "complexity": 14, "token_count": 428, "parameters": [ "self", "module", "level" ], "start_line": 273, "end_line": 324, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 52, "top_nesting_level": 1 }, { "name": "_get_suite_list", "long_name": "_get_suite_list( self , test_module , level , module_name = '__main__' )", "filename": "testing.py", "nloc": 24, "complexity": 9, "token_count": 168, "parameters": [ "self", "test_module", "level", "module_name" ], "start_line": 326, "end_line": 350, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 25, "top_nesting_level": 1 }, { "name": "_touch_ppimported", "long_name": "_touch_ppimported( self , module )", "filename": "testing.py", "nloc": 11, "complexity": 7, "token_count": 98, "parameters": [ "self", "module" ], "start_line": 352, "end_line": 363, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 12, "top_nesting_level": 1 }, { "name": "test", "long_name": "test( self , level = 1 , verbosity = 1 )", "filename": "testing.py", "nloc": 19, "complexity": 6, "token_count": 166, "parameters": [ "self", "level", "verbosity" ], "start_line": 365, "end_line": 390, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 26, "top_nesting_level": 1 }, { "name": "run", "long_name": "run( self )", "filename": "testing.py", "nloc": 20, "complexity": 2, "token_count": 104, "parameters": [ "self" ], "start_line": 392, "end_line": 414, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 23, "top_nesting_level": 1 }, { "name": "remove_ignored_patterns", "long_name": "remove_ignored_patterns( files , pattern )", "filename": "testing.py", "nloc": 7, "complexity": 3, "token_count": 37, "parameters": [ "files", "pattern" ], "start_line": 418, "end_line": 424, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 7, "top_nesting_level": 0 }, { "name": "remove_ignored_files", "long_name": "remove_ignored_files( original , ignored_files , cur_dir )", "filename": "testing.py", "nloc": 12, "complexity": 3, "token_count": 93, "parameters": [ "original", "ignored_files", "cur_dir" ], "start_line": 426, "end_line": 445, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 20, "top_nesting_level": 0 }, { "name": "harvest_modules", "long_name": "harvest_modules( package , ignore = None )", "filename": "testing.py", "nloc": 21, "complexity": 4, "token_count": 134, "parameters": [ "package", "ignore" ], "start_line": 448, "end_line": 484, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 37, "top_nesting_level": 0 }, { "name": "harvest_packages", "long_name": "harvest_packages( package , ignore = None )", "filename": "testing.py", "nloc": 23, "complexity": 6, "token_count": 148, "parameters": [ "package", "ignore" ], "start_line": 487, "end_line": 521, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 35, "top_nesting_level": 0 }, { "name": "harvest_modules_and_packages", "long_name": "harvest_modules_and_packages( package , ignore = None )", "filename": "testing.py", "nloc": 3, "complexity": 1, "token_count": 27, "parameters": [ "package", "ignore" ], "start_line": 524, "end_line": 530, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 7, "top_nesting_level": 0 }, { "name": "harvest_test_suites", "long_name": "harvest_test_suites( package , ignore = None , level = 10 )", "filename": "testing.py", "nloc": 23, "complexity": 6, "token_count": 113, "parameters": [ "package", "ignore", "level" ], "start_line": 533, "end_line": 568, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 36, "top_nesting_level": 0 }, { "name": "module_test", "long_name": "module_test( mod_name , mod_file , level = 10 )", "filename": "testing.py", "nloc": 10, "complexity": 1, "token_count": 98, "parameters": [ "mod_name", "mod_file", "level" ], "start_line": 571, "end_line": 598, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 28, "top_nesting_level": 0 }, { "name": "module_test_suite", "long_name": "module_test_suite( mod_name , mod_file , level = 10 )", "filename": "testing.py", "nloc": 12, "complexity": 1, "token_count": 103, "parameters": [ "mod_name", "mod_file", "level" ], "start_line": 601, "end_line": 623, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 23, "top_nesting_level": 0 }, { "name": "assert_equal", "long_name": "assert_equal( actual , desired , err_msg = '' , verbose = 1 )", "filename": "testing.py", "nloc": 12, "complexity": 5, "token_count": 92, "parameters": [ "actual", "desired", "err_msg", "verbose" ], "start_line": 633, "end_line": 647, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 15, "top_nesting_level": 0 }, { "name": "assert_almost_equal", "long_name": "assert_almost_equal( actual , desired , decimal = 7 , err_msg = '' , verbose = 1 )", "filename": "testing.py", "nloc": 12, "complexity": 5, "token_count": 106, "parameters": [ "actual", "desired", "decimal", "err_msg", "verbose" ], "start_line": 650, "end_line": 664, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 15, "top_nesting_level": 0 }, { "name": "assert_approx_equal", "long_name": "assert_approx_equal( actual , desired , significant = 7 , err_msg = '' , verbose = 1 )", "filename": "testing.py", "nloc": 23, "complexity": 7, "token_count": 191, "parameters": [ "actual", "desired", "significant", "err_msg", "verbose" ], "start_line": 667, "end_line": 695, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 29, "top_nesting_level": 0 }, { "name": "assert_array_equal", "long_name": "assert_array_equal( x , y , err_msg = '' )", "filename": "testing.py", "nloc": 22, "complexity": 7, "token_count": 232, "parameters": [ "x", "y", "err_msg" ], "start_line": 699, "end_line": 720, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 22, "top_nesting_level": 0 }, { "name": "assert_array_almost_equal", "long_name": "assert_array_almost_equal( x , y , decimal = 6 , err_msg = '' )", "filename": "testing.py", "nloc": 26, "complexity": 6, "token_count": 251, "parameters": [ "x", "y", "decimal", "err_msg" ], "start_line": 723, "end_line": 748, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 26, "top_nesting_level": 0 }, { "name": "assert_array_less", "long_name": "assert_array_less( x , y , err_msg = '' )", "filename": "testing.py", "nloc": 20, "complexity": 5, "token_count": 189, "parameters": [ "x", "y", "err_msg" ], "start_line": 751, "end_line": 770, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 20, "top_nesting_level": 0 }, { "name": "rand", "long_name": "rand( * args )", "filename": "testing.py", "nloc": 7, "complexity": 2, "token_count": 45, "parameters": [ "args" ], "start_line": 773, "end_line": 782, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 10, "top_nesting_level": 0 }, { "name": "output_exception", "long_name": "output_exception( )", "filename": "testing.py", "nloc": 9, "complexity": 2, "token_count": 67, "parameters": [], "start_line": 784, "end_line": 794, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 11, "top_nesting_level": 0 } ], "changed_methods": [ { "name": "assert_array_less", "long_name": "assert_array_less( x , y , err_msg = '' )", "filename": "testing.py", "nloc": 20, "complexity": 5, "token_count": 189, "parameters": [ "x", "y", "err_msg" ], "start_line": 750, "end_line": 769, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 20, "top_nesting_level": 0 }, { "name": "assert_equal", "long_name": "assert_equal( actual , desired , err_msg = '' , verbose = 1 )", "filename": "testing.py", "nloc": 12, "complexity": 5, "token_count": 95, "parameters": [ "actual", "desired", "err_msg", "verbose" ], "start_line": 632, "end_line": 646, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 15, "top_nesting_level": 0 }, { "name": "assert_almost_equal", "long_name": "assert_almost_equal( actual , desired , decimal = 7 , err_msg = '' , verbose = 1 )", "filename": "testing.py", "nloc": 12, "complexity": 5, "token_count": 109, "parameters": [ "actual", "desired", "decimal", "err_msg", "verbose" ], "start_line": 649, "end_line": 663, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 15, "top_nesting_level": 0 }, { "name": "assert_approx_equal", "long_name": "assert_approx_equal( actual , desired , significant = 7 , err_msg = '' , verbose = 1 )", "filename": "testing.py", "nloc": 23, "complexity": 7, "token_count": 194, "parameters": [ "actual", "desired", "significant", "err_msg", "verbose" ], "start_line": 666, "end_line": 694, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 29, "top_nesting_level": 0 }, { "name": "assert_array_almost_equal", "long_name": "assert_array_almost_equal( x , y , decimal = 6 , err_msg = '' )", "filename": "testing.py", "nloc": 26, "complexity": 6, "token_count": 251, "parameters": [ "x", "y", "decimal", "err_msg" ], "start_line": 722, "end_line": 747, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 26, "top_nesting_level": 0 }, { "name": "assert_array_equal", "long_name": "assert_array_equal( x , y , err_msg = '' )", "filename": "testing.py", "nloc": 22, "complexity": 7, "token_count": 232, "parameters": [ "x", "y", "err_msg" ], "start_line": 698, "end_line": 719, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 22, "top_nesting_level": 0 } ], "nloc": 595, "complexity": 148, "token_count": 4248, "diff_parsed": { "added": [ " from scipy_base.numerix import all, equal, shape, ravel, around, zeros, Float64, asarray", " from scipy_base.numerix import less_equal, array2string, less", "except ImportError:", " pass", " assert all(desired == actual), msg", " assert all(round(abs(desired - actual),decimal) == 0), msg", " assert all(math.fabs(sc_desired - sc_actual) < pow(10.,-1*significant)), msg", " all(equal(shape(x),shape(y)))),\\", " cond = all(reduced)", " cond = all(equal(shape(x),shape(y)))", " cond = all(reduced)", " assert all(equal(shape(x),shape(y))),\\", " cond = all(reduced)", " from scipy_base.numerix import fastumath as math" ], "deleted": [ " from Numeric import alltrue,equal,shape,ravel,around,zeros,Float64,asarray,\\", " less_equal,array2string,less", " # `import scipy_base.fastumath as math` must be at the end of this file.", "except ImportError,msg:", " print msg", " assert desired == actual, msg", " assert round(abs(desired - actual),decimal) == 0, msg", " assert math.fabs(sc_desired - sc_actual) < pow(10.,-1*significant), msg", " alltrue(equal(shape(x),shape(y)))),\\", " cond = alltrue(reduced)", " cond = alltrue(equal(shape(x),shape(y)))", " cond = alltrue(reduced)", " assert alltrue(equal(shape(x),shape(y))),\\", " cond = alltrue(reduced)", " import scipy_base.fastumath as math" ] } } ] }, { "hash": "64b26de9e3563a6ecac306770267656168f47ea6", "msg": "Fixed parenthesizing problem in _fix_real_lt_zero revealed by\nscipy-level self tests.", "author": { "name": "jmiller", "email": "jmiller@localhost" }, "committer": { "name": "jmiller", "email": "jmiller@localhost" }, "author_date": "2004-12-06T19:31:18+00:00", "author_timezone": 0, "committer_date": "2004-12-06T19:31:18+00:00", "committer_timezone": 0, "branches": [ "main" ], "in_main_branch": true, "merge": false, "parents": [ "5b13d29c4a5612eb182418e5de55c8374619ee5c" ], "project_name": "repo_copy", "project_path": "/tmp/tmpqop781_j/repo_copy", "deletions": 1, "insertions": 1, "lines": 2, "files": 1, "dmm_unit_size": null, "dmm_unit_complexity": null, "dmm_unit_interfacing": null, "modified_files": [ { "old_path": "scipy_base/scimath.py", "new_path": "scipy_base/scimath.py", "filename": "scimath.py", "extension": "py", "change_type": "MODIFY", "diff": "@@ -23,7 +23,7 @@ def _tocomplex(arr):\n \n def _fix_real_lt_zero(x):\n x = asarray(x)\n- if any(isreal(x) & x<0):\n+ if any(isreal(x) & (x<0)):\n x = _tocomplex(x)\n return x\n \n", "added_lines": 1, "deleted_lines": 1, "source_code": "\"\"\"\nWrapper functions to more user-friendly calling of certain math functions\nwhose output is different than the input in certain domains of the input.\n\"\"\"\n\n__all__ = ['sqrt', 'log', 'log2','logn','log10', 'power', 'arccos',\n 'arcsin', 'arctanh']\n\nimport numerix as _nx\nfrom numerix import *\n\nfrom type_check import isreal, asarray\nfrom function_base import any\n\n__all__.extend([key for key in dir(_nx.fastumath) \\\n if key[0]!='_' and key not in __all__])\n\ndef _tocomplex(arr):\n if arr.typecode() in ['f', 's', 'b', '1','w']:\n return arr.astype('F')\n else:\n return arr.astype('D')\n\ndef _fix_real_lt_zero(x):\n x = asarray(x)\n if any(isreal(x) & (x<0)):\n x = _tocomplex(x)\n return x\n\ndef _fix_real_abs_gt_1(x):\n x = asarray(x)\n if any(isreal(x) & (abs(x)>1)):\n x = _tocomplex(x)\n return x\n \ndef sqrt(x):\n x = _fix_real_lt_zero(x)\n return fastumath.sqrt(x)\n\ndef log(x):\n x = _fix_real_lt_zero(x)\n return fastumath.log(x)\n\ndef log10(x):\n x = _fix_real_lt_zero(x)\n return fastumath.log10(x) \n\ndef logn(n,x):\n \"\"\" Take log base n of x.\n \"\"\"\n x = _fix_real_lt_zero(x)\n n = _fix_real_lt_zero(n)\n return fastumath.log(x)/fastumath.log(n)\n\ndef log2(x):\n \"\"\" Take log base 2 of x.\n \"\"\"\n x = _fix_real_lt_zero(x)\n return fastumath.log(x)/fastumath.log(2)\n\ndef power(x, p):\n x = _fix_real_lt_zero(x)\n return fastumath.power(x, p)\n\n\ndef arccos(x):\n x = _fix_real_abs_gt_1(x)\n return fastumath.arccos(x)\n\ndef arcsin(x):\n x = _fix_real_abs_gt_1(x)\n return fastumath.arcsin(x)\n\ndef arctanh(x):\n x = _fix_real_abs_gt_1(x)\n return fastumath.arctanh(x)\n", "source_code_before": "\"\"\"\nWrapper functions to more user-friendly calling of certain math functions\nwhose output is different than the input in certain domains of the input.\n\"\"\"\n\n__all__ = ['sqrt', 'log', 'log2','logn','log10', 'power', 'arccos',\n 'arcsin', 'arctanh']\n\nimport numerix as _nx\nfrom numerix import *\n\nfrom type_check import isreal, asarray\nfrom function_base import any\n\n__all__.extend([key for key in dir(_nx.fastumath) \\\n if key[0]!='_' and key not in __all__])\n\ndef _tocomplex(arr):\n if arr.typecode() in ['f', 's', 'b', '1','w']:\n return arr.astype('F')\n else:\n return arr.astype('D')\n\ndef _fix_real_lt_zero(x):\n x = asarray(x)\n if any(isreal(x) & x<0):\n x = _tocomplex(x)\n return x\n\ndef _fix_real_abs_gt_1(x):\n x = asarray(x)\n if any(isreal(x) & (abs(x)>1)):\n x = _tocomplex(x)\n return x\n \ndef sqrt(x):\n x = _fix_real_lt_zero(x)\n return fastumath.sqrt(x)\n\ndef log(x):\n x = _fix_real_lt_zero(x)\n return fastumath.log(x)\n\ndef log10(x):\n x = _fix_real_lt_zero(x)\n return fastumath.log10(x) \n\ndef logn(n,x):\n \"\"\" Take log base n of x.\n \"\"\"\n x = _fix_real_lt_zero(x)\n n = _fix_real_lt_zero(n)\n return fastumath.log(x)/fastumath.log(n)\n\ndef log2(x):\n \"\"\" Take log base 2 of x.\n \"\"\"\n x = _fix_real_lt_zero(x)\n return fastumath.log(x)/fastumath.log(2)\n\ndef power(x, p):\n x = _fix_real_lt_zero(x)\n return fastumath.power(x, p)\n\n\ndef arccos(x):\n x = _fix_real_abs_gt_1(x)\n return fastumath.arccos(x)\n\ndef arcsin(x):\n x = _fix_real_abs_gt_1(x)\n return fastumath.arcsin(x)\n\ndef arctanh(x):\n x = _fix_real_abs_gt_1(x)\n return fastumath.arctanh(x)\n", "methods": [ { "name": "_tocomplex", "long_name": "_tocomplex( arr )", "filename": "scimath.py", "nloc": 5, "complexity": 2, "token_count": 40, "parameters": [ "arr" ], "start_line": 18, "end_line": 22, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 5, "top_nesting_level": 0 }, { "name": "_fix_real_lt_zero", "long_name": "_fix_real_lt_zero( x )", "filename": "scimath.py", "nloc": 5, "complexity": 2, "token_count": 34, "parameters": [ "x" ], "start_line": 24, "end_line": 28, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 5, "top_nesting_level": 0 }, { "name": "_fix_real_abs_gt_1", "long_name": "_fix_real_abs_gt_1( x )", "filename": "scimath.py", "nloc": 5, "complexity": 2, "token_count": 37, "parameters": [ "x" ], "start_line": 30, "end_line": 34, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 5, "top_nesting_level": 0 }, { "name": "sqrt", "long_name": "sqrt( x )", "filename": "scimath.py", "nloc": 3, "complexity": 1, "token_count": 18, "parameters": [ "x" ], "start_line": 36, "end_line": 38, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 3, "top_nesting_level": 0 }, { "name": "log", "long_name": "log( x )", "filename": "scimath.py", "nloc": 3, "complexity": 1, "token_count": 18, "parameters": [ "x" ], "start_line": 40, "end_line": 42, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 3, "top_nesting_level": 0 }, { "name": "log10", "long_name": "log10( x )", "filename": "scimath.py", "nloc": 3, "complexity": 1, "token_count": 18, "parameters": [ "x" ], "start_line": 44, "end_line": 46, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 3, "top_nesting_level": 0 }, { "name": "logn", "long_name": "logn( n , x )", "filename": "scimath.py", "nloc": 4, "complexity": 1, "token_count": 34, "parameters": [ "n", "x" ], "start_line": 48, "end_line": 53, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 6, "top_nesting_level": 0 }, { "name": "log2", "long_name": "log2( x )", "filename": "scimath.py", "nloc": 3, "complexity": 1, "token_count": 26, "parameters": [ "x" ], "start_line": 55, "end_line": 59, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 5, "top_nesting_level": 0 }, { "name": "power", "long_name": "power( x , p )", "filename": "scimath.py", "nloc": 3, "complexity": 1, "token_count": 22, "parameters": [ "x", "p" ], "start_line": 61, "end_line": 63, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 3, "top_nesting_level": 0 }, { "name": "arccos", "long_name": "arccos( x )", "filename": "scimath.py", "nloc": 3, "complexity": 1, "token_count": 18, "parameters": [ "x" ], "start_line": 66, "end_line": 68, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 3, "top_nesting_level": 0 }, { "name": "arcsin", "long_name": "arcsin( x )", "filename": "scimath.py", "nloc": 3, "complexity": 1, "token_count": 18, "parameters": [ "x" ], "start_line": 70, "end_line": 72, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 3, "top_nesting_level": 0 }, { "name": "arctanh", "long_name": "arctanh( x )", "filename": "scimath.py", "nloc": 3, "complexity": 1, "token_count": 18, "parameters": [ "x" ], "start_line": 74, "end_line": 76, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 3, "top_nesting_level": 0 } ], "methods_before": [ { "name": "_tocomplex", "long_name": "_tocomplex( arr )", "filename": "scimath.py", "nloc": 5, "complexity": 2, "token_count": 40, "parameters": [ "arr" ], "start_line": 18, "end_line": 22, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 5, "top_nesting_level": 0 }, { "name": "_fix_real_lt_zero", "long_name": "_fix_real_lt_zero( x )", "filename": "scimath.py", "nloc": 5, "complexity": 2, "token_count": 32, "parameters": [ "x" ], "start_line": 24, "end_line": 28, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 5, "top_nesting_level": 0 }, { "name": "_fix_real_abs_gt_1", "long_name": "_fix_real_abs_gt_1( x )", "filename": "scimath.py", "nloc": 5, "complexity": 2, "token_count": 37, "parameters": [ "x" ], "start_line": 30, "end_line": 34, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 5, "top_nesting_level": 0 }, { "name": "sqrt", "long_name": "sqrt( x )", "filename": "scimath.py", "nloc": 3, "complexity": 1, "token_count": 18, "parameters": [ "x" ], "start_line": 36, "end_line": 38, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 3, "top_nesting_level": 0 }, { "name": "log", "long_name": "log( x )", "filename": "scimath.py", "nloc": 3, "complexity": 1, "token_count": 18, "parameters": [ "x" ], "start_line": 40, "end_line": 42, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 3, "top_nesting_level": 0 }, { "name": "log10", "long_name": "log10( x )", "filename": "scimath.py", "nloc": 3, "complexity": 1, "token_count": 18, "parameters": [ "x" ], "start_line": 44, "end_line": 46, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 3, "top_nesting_level": 0 }, { "name": "logn", "long_name": "logn( n , x )", "filename": "scimath.py", "nloc": 4, "complexity": 1, "token_count": 34, "parameters": [ "n", "x" ], "start_line": 48, "end_line": 53, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 6, "top_nesting_level": 0 }, { "name": "log2", "long_name": "log2( x )", "filename": "scimath.py", "nloc": 3, "complexity": 1, "token_count": 26, "parameters": [ "x" ], "start_line": 55, "end_line": 59, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 5, "top_nesting_level": 0 }, { "name": "power", "long_name": "power( x , p )", "filename": "scimath.py", "nloc": 3, "complexity": 1, "token_count": 22, "parameters": [ "x", "p" ], "start_line": 61, "end_line": 63, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 3, "top_nesting_level": 0 }, { "name": "arccos", "long_name": "arccos( x )", "filename": "scimath.py", "nloc": 3, "complexity": 1, "token_count": 18, "parameters": [ "x" ], "start_line": 66, "end_line": 68, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 3, "top_nesting_level": 0 }, { "name": "arcsin", "long_name": "arcsin( x )", "filename": "scimath.py", "nloc": 3, "complexity": 1, "token_count": 18, "parameters": [ "x" ], "start_line": 70, "end_line": 72, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 3, "top_nesting_level": 0 }, { "name": "arctanh", "long_name": "arctanh( x )", "filename": "scimath.py", "nloc": 3, "complexity": 1, "token_count": 18, "parameters": [ "x" ], "start_line": 74, "end_line": 76, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 3, "top_nesting_level": 0 } ], "changed_methods": [ { "name": "_fix_real_lt_zero", "long_name": "_fix_real_lt_zero( x )", "filename": "scimath.py", "nloc": 5, "complexity": 2, "token_count": 34, "parameters": [ "x" ], "start_line": 24, "end_line": 28, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 5, "top_nesting_level": 0 } ], "nloc": 55, "complexity": 15, "token_count": 383, "diff_parsed": { "added": [ " if any(isreal(x) & (x<0)):" ], "deleted": [ " if any(isreal(x) & x<0):" ] } } ] }, { "hash": "8ab36c8b444c934c2aeefc624717dada6288ee5d", "msg": "Fixed missing import for isfinite() by qualifying with _nx.", "author": { "name": "jmiller", "email": "jmiller@localhost" }, "committer": { "name": "jmiller", "email": "jmiller@localhost" }, "author_date": "2004-12-06T19:31:57+00:00", "author_timezone": 0, "committer_date": "2004-12-06T19:31:57+00:00", "committer_timezone": 0, "branches": [ "main" ], "in_main_branch": true, "merge": false, "parents": [ "64b26de9e3563a6ecac306770267656168f47ea6" ], "project_name": "repo_copy", "project_path": "/tmp/tmpqop781_j/repo_copy", "deletions": 1, "insertions": 1, "lines": 2, "files": 1, "dmm_unit_size": null, "dmm_unit_complexity": null, "dmm_unit_interfacing": null, "modified_files": [ { "old_path": "scipy_base/function_base.py", "new_path": "scipy_base/function_base.py", "filename": "function_base.py", "extension": "py", "change_type": "MODIFY", "diff": "@@ -23,7 +23,7 @@ def asarray_chkfinite(x):\n \"\"\"Like asarray except it checks to be sure no NaNs or Infs are present.\n \"\"\"\n x = asarray(x)\n- if not all(isfinite(x)):\n+ if not all(_nx.isfinite(x)):\n raise ValueError, \"Array must not contain infs or nans.\"\n return x \n \n", "added_lines": 1, "deleted_lines": 1, "source_code": "import types\nimport numerix as _nx\nfrom numerix import ravel, nonzero, array, choose, ones, zeros, \\\n sometrue, alltrue, reshape, alter_numeric, restore_numeric, arraymap, \\\n pi, _insert, multiply, add, arctan2, maximum, minimum\nfrom type_check import ScalarType, isscalar, asarray\nfrom shape_base import squeeze, atleast_1d\n\n__all__ = ['round','any','all','logspace','linspace','fix','mod',\n 'select','trim_zeros','amax','amin', 'alen', 'ptp','cumsum','take',\n 'copy', 'prod','cumprod','diff','angle','unwrap','sort_complex',\n 'disp','unique','extract','insert','nansum','nanmax','nanargmax',\n 'nanargmin','nanmin','sum','vectorize','asarray_chkfinite',\n 'alter_numeric', 'restore_numeric','isaltered']\n\ndef isaltered():\n val = str(type(_nx.array([1])))\n return 'scipy' in val\n\nround = _nx.around\n\ndef asarray_chkfinite(x):\n \"\"\"Like asarray except it checks to be sure no NaNs or Infs are present.\n \"\"\"\n x = asarray(x)\n if not all(_nx.isfinite(x)):\n raise ValueError, \"Array must not contain infs or nans.\"\n return x \n\ndef any(x):\n \"\"\"Return true if any elements of x are true: sometrue(ravel(x))\n \"\"\"\n return sometrue(ravel(x))\n\n\ndef all(x):\n \"\"\"Return true if all elements of x are true: alltrue(ravel(x))\n \"\"\"\n return alltrue(ravel(x))\n\n# Need this to change array type for low precision values\ndef sum(x,axis=0): # could change default axis here\n x = asarray(x)\n if x.typecode() in ['1','s','b','w']:\n x = x.astype('l')\n return _nx.sum(x,axis)\n \n\ndef logspace(start,stop,num=50,endpoint=1):\n \"\"\" Evenly spaced samples on a logarithmic scale.\n\n Return num evenly spaced samples from 10**start to 10**stop. If\n endpoint=1 then last sample is 10**stop.\n \"\"\"\n if num <= 0: return array([])\n if endpoint:\n step = (stop-start)/float((num-1))\n y = _nx.arange(0,num) * step + start\n else:\n step = (stop-start)/float(num)\n y = _nx.arange(0,num) * step + start\n return _nx.power(10.0,y)\n\ndef linspace(start,stop,num=50,endpoint=1,retstep=0):\n \"\"\" Evenly spaced samples.\n \n Return num evenly spaced samples from start to stop. If endpoint=1 then\n last sample is stop. If retstep is 1 then return the step value used.\n \"\"\"\n if num <= 0: return array([])\n if endpoint:\n step = (stop-start)/float((num-1))\n y = _nx.arange(0,num) * step + start \n else:\n step = (stop-start)/float(num)\n y = _nx.arange(0,num) * step + start\n if retstep:\n return y, step\n else:\n return y\n\ndef fix(x):\n \"\"\" Round x to nearest integer towards zero.\n \"\"\"\n x = asarray(x)\n y = _nx.floor(x)\n return _nx.where(x<0,y+1,y)\n\ndef mod(x,y):\n \"\"\" x - y*floor(x/y)\n \n For numeric arrays, x % y has the same sign as x while\n mod(x,y) has the same sign as y.\n \"\"\"\n return x - y*_nx.floor(x*1.0/y)\n\ndef select(condlist, choicelist, default=0):\n \"\"\" Returns an array comprised from different elements of choicelist\n depending on the list of conditions.\n\n condlist is a list of condition arrays containing ones or zeros\n \n choicelist is a list of choice matrices (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 the 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):\n \"\"\"Ensure 1d array for one array.\n \"\"\"\n m = asarray(arr)\n if len(m.shape)==0:\n m = reshape(m,(1,))\n return m\n\ndef copy(a):\n \"\"\"Return an array copy of the object.\n \"\"\"\n return array(a,copy=1)\n\ndef take(a, indices, axis=0):\n \"\"\"Selects the elements in indices from array a along given axis.\n \"\"\"\n try:\n a = _nx.take(a,indices,axis)\n except ValueError: # a is scalar\n pass\n return a\n\ndef _no_axis_is_all(function, m, axis):\n if axis is None:\n m = ravel(m)\n axis = 0\n else:\n m = _asarray1d(m)\n if _nx.which[0] == \"numeric\":\n r = function(m, axis)\n else:\n import numarray as _na\n _na.Error.pushMode(overflow=\"raise\")\n try:\n r = function(m, axis)\n finally:\n _na.Error.popMode()\n return r\n \n# Basic operations\ndef amax(m,axis=-1): \n \"\"\"Returns the maximum of m along dimension axis. \n \"\"\"\n return _no_axis_is_all(maximum.reduce, m, axis)\n\ndef amin(m,axis=-1):\n \"\"\"Returns the minimum of m along dimension axis.\n \"\"\"\n return _no_axis_is_all(minimum.reduce, m, axis)\n\ndef alen(m):\n \"\"\"Returns the length of a Python object interpreted as an array\n \"\"\"\n return len(asarray(m))\n\n# Actually from Basis, but it fits in so naturally here...\n\ndef _amin_amax(m, axis):\n return amax(m,axis)-amin(m,axis)\n\ndef ptp(m,axis=-1):\n \"\"\"Returns the maximum - minimum along the the given dimension\n \"\"\"\n return _no_axis_is_all(_amin_amax, m, axis)\n\ndef cumsum(m,axis=-1):\n \"\"\"Returns the cumulative sum of the elements along the given axis\n \"\"\"\n return _no_axis_is_all(add.accumulate, m, axis)\n\ndef prod(m,axis=-1):\n \"\"\"Returns the product of the elements along the given axis\n \"\"\"\n return _no_axis_is_all(multiply.reduce, m, axis)\n\ndef cumprod(m,axis=-1):\n \"\"\"Returns the cumulative product of the elments along the given axis\n \"\"\"\n return _no_axis_is_all(multiply.accumulate, m, axis)\n\ndef diff(x, n=1,axis=-1):\n \"\"\"Calculates the nth order, discrete difference along given axis.\n \"\"\"\n if n==0:\n return x\n if n<0:\n raise ValueError,'Order must be non-negative but got ' + `n`\n x = _asarray1d(x)\n nd = len(x.shape)\n slice1 = [slice(None)]*nd\n slice2 = [slice(None)]*nd\n slice1[axis] = slice(1,None)\n slice2[axis] = slice(None,-1)\n if n > 1:\n return diff(x[slice1]-x[slice2], n-1, axis=axis)\n else:\n return x[slice1]-x[slice2]\n \ndef angle(z,deg=0):\n \"\"\"Return the angle of complex argument z.\"\"\"\n if deg:\n fact = 180/pi\n else:\n fact = 1.0\n z = asarray(z)\n if z.typecode() in ['D','F']:\n zimag = z.imag\n zreal = z.real\n else:\n zimag = 0\n zreal = z\n return arctan2(zimag,zreal) * fact\n\ndef unwrap(p,discont=pi,axis=-1):\n \"\"\"unwraps radian phase p by changing absolute jumps greater than\n discont to their 2*pi complement along the given axis.\n \"\"\"\n p = asarray(p)\n nd = len(p.shape)\n dd = diff(p,axis=axis)\n slice1 = [slice(None,None)]*nd # full slices\n slice1[axis] = slice(1,None)\n ddmod = mod(dd+pi,2*pi)-pi\n _nx.putmask(ddmod,(ddmod==-pi) & (dd > 0),pi)\n ph_correct = ddmod - dd;\n _nx.putmask(ph_correct,abs(dd)>> import scipy\n >>> a = array((0,0,0,1,2,3,2,1,0))\n >>> scipy.trim_zeros(a)\n array([1, 2, 3, 2, 1])\n \"\"\"\n first = 0\n if 'f' in trim or '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 or 'B' in trim:\n for i in filt[::-1]:\n if i != 0.: break\n else: last = last - 1\n return filt[first:last]\n\ndef unique(inseq):\n \"\"\"Returns unique items in 1-dimensional sequence.\n \"\"\"\n set = {}\n for item in inseq:\n set[item] = None\n return asarray(set.keys())\n\ndef where(condition,x=None,y=None):\n \"\"\"If x and y are both None, then return the (1-d equivalent) indices\n where condition is true. Otherwise, return an array shaped like\n condition with elements of x and y in the places where condition is\n true or false respectively.\n \"\"\"\n if (x is None) and (y is None):\n # Needs work for multidimensional arrays\n return nonzero(ravel(condition))\n else:\n return choose(not_equal(condition, 0), (y,x))\n \ndef extract(condition, arr):\n \"\"\"Elements of ravel(condition) where ravel(condition) is true (1-d)\n\n Equivalent of compress(ravel(condition), ravel(arr))\n \"\"\"\n return _nx.take(ravel(arr), nonzero(ravel(condition)))\n\ndef insert(arr, mask, vals):\n \"\"\"Similar to putmask arr[mask] = vals but 1d array vals has the\n same number of elements as the non-zero values of mask. Inverse of extract.\n \"\"\"\n return _nx._insert(arr, mask, vals)\n\ndef nansum(x,axis=-1):\n \"\"\"Sum the array over the given axis treating nans as missing values.\n \"\"\"\n x = _asarray1d(x).copy()\n _nx.putmask(x,isnan(x),0)\n return _nx.sum(x,axis)\n\ndef nanmin(x,axis=-1):\n \"\"\"Find the minimium over the given axis ignoring nans.\n \"\"\"\n x = _asarray1d(x).copy()\n _nx.putmask(x,isnan(x),inf)\n return amin(x,axis)\n\ndef nanargmin(x,axis=-1):\n \"\"\"Find the indices of the minimium over the given axis ignoring nans.\n \"\"\"\n x = _asarray1d(x).copy()\n _nx.putmask(x,isnan(x),inf)\n return argmin(x,axis)\n \n\ndef nanmax(x,axis=-1):\n \"\"\"Find the maximum over the given axis ignoring nans.\n \"\"\"\n x = _asarray1d(x).copy()\n _nx.putmask(x,isnan(x),-inf)\n return amax(x,axis)\n\ndef nanargmax(x,axis=-1):\n \"\"\"Find the maximum over the given axis ignoring nans.\n \"\"\"\n x = _asarray1d(x).copy()\n _nx.putmask(x,isnan(x),-inf)\n return argmax(x,axis)\n\ndef disp(mesg, device=None, linefeed=1):\n \"\"\"Display a message to device (default is sys.stdout) with(out) linefeed.\n \"\"\"\n if device is None:\n import sys\n device = sys.stdout\n if linefeed:\n device.write('%s\\n' % mesg)\n else:\n device.write('%s' % mesg)\n device.flush()\n return\n\nclass vectorize:\n \"\"\"\n vectorize(somefunction) Generalized Function class.\n\n Description:\n \n Define a vectorized function which takes nested sequence\n objects or numerix arrays as inputs and returns a\n numerix 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 numerix Python.\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=None,doc=None):\n if not callable(pyfunc) or type(pyfunc) is types.ClassType:\n raise TypeError, \"Object is not a callable Python object.\"\n self.thefunc = pyfunc\n if doc is None:\n self.__doc__ = pyfunc.__doc__\n else:\n self.__doc__ = doc\n if otypes is None:\n self.otypes=''\n else:\n if isinstance(otypes,types.StringType):\n self.otypes=otypes\n else:\n raise ValueError, \"Output types must be a string.\"\n\n def __call__(self,*args):\n try:\n return squeeze(arraymap(self.thefunc,args,self.otypes))\n except IndexError:\n return self.zerocall(*args)\n\n def zerocall(self,*args):\n # one of the args was a zeros array\n # return zeros for each output\n # first --- find number of outputs\n # get it from self.otypes if possible\n # otherwise evaluate function at 0.9\n N = len(self.otypes)\n if N==1:\n return zeros((0,),'d')\n elif N !=0:\n return (zeros((0,),'d'),)*N\n newargs = []\n args = atleast_1d(args)\n for arg in args:\n if arg.typecode() != 'O':\n newargs.append(0.9)\n else:\n newargs.append(arg[0])\n newargs = tuple(newargs)\n try:\n res = self.thefunc(*newargs)\n except:\n raise ValueError, \"Zerocall is failing. \"\\\n \"Try using otypes in vectorize.\"\n if isscalar(res):\n return zeros((0,),'d')\n else:\n return (zeros((0,),'d'),)*len(res)\n\n", "source_code_before": "import types\nimport numerix as _nx\nfrom numerix import ravel, nonzero, array, choose, ones, zeros, \\\n sometrue, alltrue, reshape, alter_numeric, restore_numeric, arraymap, \\\n pi, _insert, multiply, add, arctan2, maximum, minimum\nfrom type_check import ScalarType, isscalar, asarray\nfrom shape_base import squeeze, atleast_1d\n\n__all__ = ['round','any','all','logspace','linspace','fix','mod',\n 'select','trim_zeros','amax','amin', 'alen', 'ptp','cumsum','take',\n 'copy', 'prod','cumprod','diff','angle','unwrap','sort_complex',\n 'disp','unique','extract','insert','nansum','nanmax','nanargmax',\n 'nanargmin','nanmin','sum','vectorize','asarray_chkfinite',\n 'alter_numeric', 'restore_numeric','isaltered']\n\ndef isaltered():\n val = str(type(_nx.array([1])))\n return 'scipy' in val\n\nround = _nx.around\n\ndef asarray_chkfinite(x):\n \"\"\"Like asarray except it checks to be sure no NaNs or Infs are present.\n \"\"\"\n x = asarray(x)\n if not all(isfinite(x)):\n raise ValueError, \"Array must not contain infs or nans.\"\n return x \n\ndef any(x):\n \"\"\"Return true if any elements of x are true: sometrue(ravel(x))\n \"\"\"\n return sometrue(ravel(x))\n\n\ndef all(x):\n \"\"\"Return true if all elements of x are true: alltrue(ravel(x))\n \"\"\"\n return alltrue(ravel(x))\n\n# Need this to change array type for low precision values\ndef sum(x,axis=0): # could change default axis here\n x = asarray(x)\n if x.typecode() in ['1','s','b','w']:\n x = x.astype('l')\n return _nx.sum(x,axis)\n \n\ndef logspace(start,stop,num=50,endpoint=1):\n \"\"\" Evenly spaced samples on a logarithmic scale.\n\n Return num evenly spaced samples from 10**start to 10**stop. If\n endpoint=1 then last sample is 10**stop.\n \"\"\"\n if num <= 0: return array([])\n if endpoint:\n step = (stop-start)/float((num-1))\n y = _nx.arange(0,num) * step + start\n else:\n step = (stop-start)/float(num)\n y = _nx.arange(0,num) * step + start\n return _nx.power(10.0,y)\n\ndef linspace(start,stop,num=50,endpoint=1,retstep=0):\n \"\"\" Evenly spaced samples.\n \n Return num evenly spaced samples from start to stop. If endpoint=1 then\n last sample is stop. If retstep is 1 then return the step value used.\n \"\"\"\n if num <= 0: return array([])\n if endpoint:\n step = (stop-start)/float((num-1))\n y = _nx.arange(0,num) * step + start \n else:\n step = (stop-start)/float(num)\n y = _nx.arange(0,num) * step + start\n if retstep:\n return y, step\n else:\n return y\n\ndef fix(x):\n \"\"\" Round x to nearest integer towards zero.\n \"\"\"\n x = asarray(x)\n y = _nx.floor(x)\n return _nx.where(x<0,y+1,y)\n\ndef mod(x,y):\n \"\"\" x - y*floor(x/y)\n \n For numeric arrays, x % y has the same sign as x while\n mod(x,y) has the same sign as y.\n \"\"\"\n return x - y*_nx.floor(x*1.0/y)\n\ndef select(condlist, choicelist, default=0):\n \"\"\" Returns an array comprised from different elements of choicelist\n depending on the list of conditions.\n\n condlist is a list of condition arrays containing ones or zeros\n \n choicelist is a list of choice matrices (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 the 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):\n \"\"\"Ensure 1d array for one array.\n \"\"\"\n m = asarray(arr)\n if len(m.shape)==0:\n m = reshape(m,(1,))\n return m\n\ndef copy(a):\n \"\"\"Return an array copy of the object.\n \"\"\"\n return array(a,copy=1)\n\ndef take(a, indices, axis=0):\n \"\"\"Selects the elements in indices from array a along given axis.\n \"\"\"\n try:\n a = _nx.take(a,indices,axis)\n except ValueError: # a is scalar\n pass\n return a\n\ndef _no_axis_is_all(function, m, axis):\n if axis is None:\n m = ravel(m)\n axis = 0\n else:\n m = _asarray1d(m)\n if _nx.which[0] == \"numeric\":\n r = function(m, axis)\n else:\n import numarray as _na\n _na.Error.pushMode(overflow=\"raise\")\n try:\n r = function(m, axis)\n finally:\n _na.Error.popMode()\n return r\n \n# Basic operations\ndef amax(m,axis=-1): \n \"\"\"Returns the maximum of m along dimension axis. \n \"\"\"\n return _no_axis_is_all(maximum.reduce, m, axis)\n\ndef amin(m,axis=-1):\n \"\"\"Returns the minimum of m along dimension axis.\n \"\"\"\n return _no_axis_is_all(minimum.reduce, m, axis)\n\ndef alen(m):\n \"\"\"Returns the length of a Python object interpreted as an array\n \"\"\"\n return len(asarray(m))\n\n# Actually from Basis, but it fits in so naturally here...\n\ndef _amin_amax(m, axis):\n return amax(m,axis)-amin(m,axis)\n\ndef ptp(m,axis=-1):\n \"\"\"Returns the maximum - minimum along the the given dimension\n \"\"\"\n return _no_axis_is_all(_amin_amax, m, axis)\n\ndef cumsum(m,axis=-1):\n \"\"\"Returns the cumulative sum of the elements along the given axis\n \"\"\"\n return _no_axis_is_all(add.accumulate, m, axis)\n\ndef prod(m,axis=-1):\n \"\"\"Returns the product of the elements along the given axis\n \"\"\"\n return _no_axis_is_all(multiply.reduce, m, axis)\n\ndef cumprod(m,axis=-1):\n \"\"\"Returns the cumulative product of the elments along the given axis\n \"\"\"\n return _no_axis_is_all(multiply.accumulate, m, axis)\n\ndef diff(x, n=1,axis=-1):\n \"\"\"Calculates the nth order, discrete difference along given axis.\n \"\"\"\n if n==0:\n return x\n if n<0:\n raise ValueError,'Order must be non-negative but got ' + `n`\n x = _asarray1d(x)\n nd = len(x.shape)\n slice1 = [slice(None)]*nd\n slice2 = [slice(None)]*nd\n slice1[axis] = slice(1,None)\n slice2[axis] = slice(None,-1)\n if n > 1:\n return diff(x[slice1]-x[slice2], n-1, axis=axis)\n else:\n return x[slice1]-x[slice2]\n \ndef angle(z,deg=0):\n \"\"\"Return the angle of complex argument z.\"\"\"\n if deg:\n fact = 180/pi\n else:\n fact = 1.0\n z = asarray(z)\n if z.typecode() in ['D','F']:\n zimag = z.imag\n zreal = z.real\n else:\n zimag = 0\n zreal = z\n return arctan2(zimag,zreal) * fact\n\ndef unwrap(p,discont=pi,axis=-1):\n \"\"\"unwraps radian phase p by changing absolute jumps greater than\n discont to their 2*pi complement along the given axis.\n \"\"\"\n p = asarray(p)\n nd = len(p.shape)\n dd = diff(p,axis=axis)\n slice1 = [slice(None,None)]*nd # full slices\n slice1[axis] = slice(1,None)\n ddmod = mod(dd+pi,2*pi)-pi\n _nx.putmask(ddmod,(ddmod==-pi) & (dd > 0),pi)\n ph_correct = ddmod - dd;\n _nx.putmask(ph_correct,abs(dd)>> import scipy\n >>> a = array((0,0,0,1,2,3,2,1,0))\n >>> scipy.trim_zeros(a)\n array([1, 2, 3, 2, 1])\n \"\"\"\n first = 0\n if 'f' in trim or '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 or 'B' in trim:\n for i in filt[::-1]:\n if i != 0.: break\n else: last = last - 1\n return filt[first:last]\n\ndef unique(inseq):\n \"\"\"Returns unique items in 1-dimensional sequence.\n \"\"\"\n set = {}\n for item in inseq:\n set[item] = None\n return asarray(set.keys())\n\ndef where(condition,x=None,y=None):\n \"\"\"If x and y are both None, then return the (1-d equivalent) indices\n where condition is true. Otherwise, return an array shaped like\n condition with elements of x and y in the places where condition is\n true or false respectively.\n \"\"\"\n if (x is None) and (y is None):\n # Needs work for multidimensional arrays\n return nonzero(ravel(condition))\n else:\n return choose(not_equal(condition, 0), (y,x))\n \ndef extract(condition, arr):\n \"\"\"Elements of ravel(condition) where ravel(condition) is true (1-d)\n\n Equivalent of compress(ravel(condition), ravel(arr))\n \"\"\"\n return _nx.take(ravel(arr), nonzero(ravel(condition)))\n\ndef insert(arr, mask, vals):\n \"\"\"Similar to putmask arr[mask] = vals but 1d array vals has the\n same number of elements as the non-zero values of mask. Inverse of extract.\n \"\"\"\n return _nx._insert(arr, mask, vals)\n\ndef nansum(x,axis=-1):\n \"\"\"Sum the array over the given axis treating nans as missing values.\n \"\"\"\n x = _asarray1d(x).copy()\n _nx.putmask(x,isnan(x),0)\n return _nx.sum(x,axis)\n\ndef nanmin(x,axis=-1):\n \"\"\"Find the minimium over the given axis ignoring nans.\n \"\"\"\n x = _asarray1d(x).copy()\n _nx.putmask(x,isnan(x),inf)\n return amin(x,axis)\n\ndef nanargmin(x,axis=-1):\n \"\"\"Find the indices of the minimium over the given axis ignoring nans.\n \"\"\"\n x = _asarray1d(x).copy()\n _nx.putmask(x,isnan(x),inf)\n return argmin(x,axis)\n \n\ndef nanmax(x,axis=-1):\n \"\"\"Find the maximum over the given axis ignoring nans.\n \"\"\"\n x = _asarray1d(x).copy()\n _nx.putmask(x,isnan(x),-inf)\n return amax(x,axis)\n\ndef nanargmax(x,axis=-1):\n \"\"\"Find the maximum over the given axis ignoring nans.\n \"\"\"\n x = _asarray1d(x).copy()\n _nx.putmask(x,isnan(x),-inf)\n return argmax(x,axis)\n\ndef disp(mesg, device=None, linefeed=1):\n \"\"\"Display a message to device (default is sys.stdout) with(out) linefeed.\n \"\"\"\n if device is None:\n import sys\n device = sys.stdout\n if linefeed:\n device.write('%s\\n' % mesg)\n else:\n device.write('%s' % mesg)\n device.flush()\n return\n\nclass vectorize:\n \"\"\"\n vectorize(somefunction) Generalized Function class.\n\n Description:\n \n Define a vectorized function which takes nested sequence\n objects or numerix arrays as inputs and returns a\n numerix 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 numerix Python.\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=None,doc=None):\n if not callable(pyfunc) or type(pyfunc) is types.ClassType:\n raise TypeError, \"Object is not a callable Python object.\"\n self.thefunc = pyfunc\n if doc is None:\n self.__doc__ = pyfunc.__doc__\n else:\n self.__doc__ = doc\n if otypes is None:\n self.otypes=''\n else:\n if isinstance(otypes,types.StringType):\n self.otypes=otypes\n else:\n raise ValueError, \"Output types must be a string.\"\n\n def __call__(self,*args):\n try:\n return squeeze(arraymap(self.thefunc,args,self.otypes))\n except IndexError:\n return self.zerocall(*args)\n\n def zerocall(self,*args):\n # one of the args was a zeros array\n # return zeros for each output\n # first --- find number of outputs\n # get it from self.otypes if possible\n # otherwise evaluate function at 0.9\n N = len(self.otypes)\n if N==1:\n return zeros((0,),'d')\n elif N !=0:\n return (zeros((0,),'d'),)*N\n newargs = []\n args = atleast_1d(args)\n for arg in args:\n if arg.typecode() != 'O':\n newargs.append(0.9)\n else:\n newargs.append(arg[0])\n newargs = tuple(newargs)\n try:\n res = self.thefunc(*newargs)\n except:\n raise ValueError, \"Zerocall is failing. \"\\\n \"Try using otypes in vectorize.\"\n if isscalar(res):\n return zeros((0,),'d')\n else:\n return (zeros((0,),'d'),)*len(res)\n\n", "methods": [ { "name": "isaltered", "long_name": "isaltered( )", "filename": "function_base.py", "nloc": 3, "complexity": 1, "token_count": 24, "parameters": [], "start_line": 16, "end_line": 18, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 3, "top_nesting_level": 0 }, { "name": "asarray_chkfinite", "long_name": "asarray_chkfinite( x )", "filename": "function_base.py", "nloc": 5, "complexity": 2, "token_count": 30, "parameters": [ "x" ], "start_line": 22, "end_line": 28, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 7, "top_nesting_level": 0 }, { "name": "any", "long_name": "any( x )", "filename": "function_base.py", "nloc": 2, "complexity": 1, "token_count": 14, "parameters": [ "x" ], "start_line": 30, "end_line": 33, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 4, "top_nesting_level": 0 }, { "name": "all", "long_name": "all( x )", "filename": "function_base.py", "nloc": 2, "complexity": 1, "token_count": 14, "parameters": [ "x" ], "start_line": 36, "end_line": 39, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 4, "top_nesting_level": 0 }, { "name": "sum", "long_name": "sum( x , axis = 0 )", "filename": "function_base.py", "nloc": 5, "complexity": 2, "token_count": 49, "parameters": [ "x", "axis" ], "start_line": 42, "end_line": 46, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 5, "top_nesting_level": 0 }, { "name": "logspace", "long_name": "logspace( start , stop , num = 50 , endpoint = 1 )", "filename": "function_base.py", "nloc": 9, "complexity": 3, "token_count": 99, "parameters": [ "start", "stop", "num", "endpoint" ], "start_line": 49, "end_line": 62, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 14, "top_nesting_level": 0 }, { "name": "linspace", "long_name": "linspace( start , stop , num = 50 , endpoint = 1 , retstep = 0 )", "filename": "function_base.py", "nloc": 12, "complexity": 4, "token_count": 103, "parameters": [ "start", "stop", "num", "endpoint", "retstep" ], "start_line": 64, "end_line": 80, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 17, "top_nesting_level": 0 }, { "name": "fix", "long_name": "fix( x )", "filename": "function_base.py", "nloc": 4, "complexity": 1, "token_count": 35, "parameters": [ "x" ], "start_line": 82, "end_line": 87, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 6, "top_nesting_level": 0 }, { "name": "mod", "long_name": "mod( x , y )", "filename": "function_base.py", "nloc": 2, "complexity": 1, "token_count": 25, "parameters": [ "x", "y" ], "start_line": 89, "end_line": 95, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 7, "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": 97, "end_line": 143, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 47, "top_nesting_level": 0 }, { "name": "_asarray1d", "long_name": "_asarray1d( arr )", "filename": "function_base.py", "nloc": 5, "complexity": 2, "token_count": 35, "parameters": [ "arr" ], "start_line": 145, "end_line": 151, "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": 153, "end_line": 156, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 4, "top_nesting_level": 0 }, { "name": "take", "long_name": "take( a , indices , axis = 0 )", "filename": "function_base.py", "nloc": 6, "complexity": 2, "token_count": 32, "parameters": [ "a", "indices", "axis" ], "start_line": 158, "end_line": 165, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 8, "top_nesting_level": 0 }, { "name": "_no_axis_is_all", "long_name": "_no_axis_is_all( function , m , axis )", "filename": "function_base.py", "nloc": 16, "complexity": 4, "token_count": 86, "parameters": [ "function", "m", "axis" ], "start_line": 167, "end_line": 182, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 16, "top_nesting_level": 0 }, { "name": "amax", "long_name": "amax( m , axis = - 1 )", "filename": "function_base.py", "nloc": 2, "complexity": 1, "token_count": 22, "parameters": [ "m", "axis" ], "start_line": 185, "end_line": 188, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 4, "top_nesting_level": 0 }, { "name": "amin", "long_name": "amin( m , axis = - 1 )", "filename": "function_base.py", "nloc": 2, "complexity": 1, "token_count": 22, "parameters": [ "m", "axis" ], "start_line": 190, "end_line": 193, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 4, "top_nesting_level": 0 }, { "name": "alen", "long_name": "alen( m )", "filename": "function_base.py", "nloc": 2, "complexity": 1, "token_count": 14, "parameters": [ "m" ], "start_line": 195, "end_line": 198, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 4, "top_nesting_level": 0 }, { "name": "_amin_amax", "long_name": "_amin_amax( m , axis )", "filename": "function_base.py", "nloc": 2, "complexity": 1, "token_count": 21, "parameters": [ "m", "axis" ], "start_line": 202, "end_line": 203, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 2, "top_nesting_level": 0 }, { "name": "ptp", "long_name": "ptp( m , axis = - 1 )", "filename": "function_base.py", "nloc": 2, "complexity": 1, "token_count": 20, "parameters": [ "m", "axis" ], "start_line": 205, "end_line": 208, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 4, "top_nesting_level": 0 }, { "name": "cumsum", "long_name": "cumsum( m , axis = - 1 )", "filename": "function_base.py", "nloc": 2, "complexity": 1, "token_count": 22, "parameters": [ "m", "axis" ], "start_line": 210, "end_line": 213, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 4, "top_nesting_level": 0 }, { "name": "prod", "long_name": "prod( m , axis = - 1 )", "filename": "function_base.py", "nloc": 2, "complexity": 1, "token_count": 22, "parameters": [ "m", "axis" ], "start_line": 215, "end_line": 218, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 4, "top_nesting_level": 0 }, { "name": "cumprod", "long_name": "cumprod( m , axis = - 1 )", "filename": "function_base.py", "nloc": 2, "complexity": 1, "token_count": 22, "parameters": [ "m", "axis" ], "start_line": 220, "end_line": 223, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 4, "top_nesting_level": 0 }, { "name": "diff", "long_name": "diff( x , n = 1 , axis = - 1 )", "filename": "function_base.py", "nloc": 15, "complexity": 4, "token_count": 130, "parameters": [ "x", "n", "axis" ], "start_line": 225, "end_line": 241, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 17, "top_nesting_level": 0 }, { "name": "angle", "long_name": "angle( z , deg = 0 )", "filename": "function_base.py", "nloc": 13, "complexity": 3, "token_count": 71, "parameters": [ "z", "deg" ], "start_line": 243, "end_line": 256, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 14, "top_nesting_level": 0 }, { "name": "unwrap", "long_name": "unwrap( p , discont = pi , axis = - 1 )", "filename": "function_base.py", "nloc": 13, "complexity": 1, "token_count": 150, "parameters": [ "p", "discont", "axis" ], "start_line": 258, "end_line": 273, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 16, "top_nesting_level": 0 }, { "name": "sort_complex.complex_cmp", "long_name": "sort_complex.complex_cmp( x , y )", "filename": "function_base.py", "nloc": 5, "complexity": 2, "token_count": 38, "parameters": [ "x", "y" ], "start_line": 279, "end_line": 283, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 5, "top_nesting_level": 1 }, { "name": "sort_complex", "long_name": "sort_complex( a )", "filename": "function_base.py", "nloc": 6, "complexity": 1, "token_count": 44, "parameters": [ "a" ], "start_line": 275, "end_line": 286, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 12, "top_nesting_level": 0 }, { "name": "trim_zeros", "long_name": "trim_zeros( filt , trim = 'fb' )", "filename": "function_base.py", "nloc": 12, "complexity": 9, "token_count": 87, "parameters": [ "filt", "trim" ], "start_line": 288, "end_line": 307, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 20, "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": 309, "end_line": 315, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 7, "top_nesting_level": 0 }, { "name": "where", "long_name": "where( condition , x = None , y = None )", "filename": "function_base.py", "nloc": 5, "complexity": 3, "token_count": 53, "parameters": [ "condition", "x", "y" ], "start_line": 317, "end_line": 327, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 11, "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": 329, "end_line": 334, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 6, "top_nesting_level": 0 }, { "name": "insert", "long_name": "insert( arr , mask , vals )", "filename": "function_base.py", "nloc": 2, "complexity": 1, "token_count": 21, "parameters": [ "arr", "mask", "vals" ], "start_line": 336, "end_line": 340, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 5, "top_nesting_level": 0 }, { "name": "nansum", "long_name": "nansum( x , axis = - 1 )", "filename": "function_base.py", "nloc": 4, "complexity": 1, "token_count": 43, "parameters": [ "x", "axis" ], "start_line": 342, "end_line": 347, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 6, "top_nesting_level": 0 }, { "name": "nanmin", "long_name": "nanmin( x , axis = - 1 )", "filename": "function_base.py", "nloc": 4, "complexity": 1, "token_count": 41, "parameters": [ "x", "axis" ], "start_line": 349, "end_line": 354, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 6, "top_nesting_level": 0 }, { "name": "nanargmin", "long_name": "nanargmin( x , axis = - 1 )", "filename": "function_base.py", "nloc": 4, "complexity": 1, "token_count": 41, "parameters": [ "x", "axis" ], "start_line": 356, "end_line": 361, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 6, "top_nesting_level": 0 }, { "name": "nanmax", "long_name": "nanmax( x , axis = - 1 )", "filename": "function_base.py", "nloc": 4, "complexity": 1, "token_count": 42, "parameters": [ "x", "axis" ], "start_line": 364, "end_line": 369, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 6, "top_nesting_level": 0 }, { "name": "nanargmax", "long_name": "nanargmax( x , axis = - 1 )", "filename": "function_base.py", "nloc": 4, "complexity": 1, "token_count": 42, "parameters": [ "x", "axis" ], "start_line": 371, "end_line": 376, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 6, "top_nesting_level": 0 }, { "name": "disp", "long_name": "disp( mesg , device = None , linefeed = 1 )", "filename": "function_base.py", "nloc": 10, "complexity": 3, "token_count": 53, "parameters": [ "mesg", "device", "linefeed" ], "start_line": 378, "end_line": 389, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 12, "top_nesting_level": 0 }, { "name": "__init__", "long_name": "__init__( self , pyfunc , otypes = None , doc = None )", "filename": "function_base.py", "nloc": 15, "complexity": 6, "token_count": 92, "parameters": [ "self", "pyfunc", "otypes", "doc" ], "start_line": 421, "end_line": 435, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 15, "top_nesting_level": 1 }, { "name": "__call__", "long_name": "__call__( self , * args )", "filename": "function_base.py", "nloc": 5, "complexity": 2, "token_count": 37, "parameters": [ "self", "args" ], "start_line": 437, "end_line": 441, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 5, "top_nesting_level": 1 }, { "name": "zerocall", "long_name": "zerocall( self , * args )", "filename": "function_base.py", "nloc": 23, "complexity": 7, "token_count": 155, "parameters": [ "self", "args" ], "start_line": 443, "end_line": 470, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 28, "top_nesting_level": 1 } ], "methods_before": [ { "name": "isaltered", "long_name": "isaltered( )", "filename": "function_base.py", "nloc": 3, "complexity": 1, "token_count": 24, "parameters": [], "start_line": 16, "end_line": 18, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 3, "top_nesting_level": 0 }, { "name": "asarray_chkfinite", "long_name": "asarray_chkfinite( x )", "filename": "function_base.py", "nloc": 5, "complexity": 2, "token_count": 28, "parameters": [ "x" ], "start_line": 22, "end_line": 28, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 7, "top_nesting_level": 0 }, { "name": "any", "long_name": "any( x )", "filename": "function_base.py", "nloc": 2, "complexity": 1, "token_count": 14, "parameters": [ "x" ], "start_line": 30, "end_line": 33, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 4, "top_nesting_level": 0 }, { "name": "all", "long_name": "all( x )", "filename": "function_base.py", "nloc": 2, "complexity": 1, "token_count": 14, "parameters": [ "x" ], "start_line": 36, "end_line": 39, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 4, "top_nesting_level": 0 }, { "name": "sum", "long_name": "sum( x , axis = 0 )", "filename": "function_base.py", "nloc": 5, "complexity": 2, "token_count": 49, "parameters": [ "x", "axis" ], "start_line": 42, "end_line": 46, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 5, "top_nesting_level": 0 }, { "name": "logspace", "long_name": "logspace( start , stop , num = 50 , endpoint = 1 )", "filename": "function_base.py", "nloc": 9, "complexity": 3, "token_count": 99, "parameters": [ "start", "stop", "num", "endpoint" ], "start_line": 49, "end_line": 62, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 14, "top_nesting_level": 0 }, { "name": "linspace", "long_name": "linspace( start , stop , num = 50 , endpoint = 1 , retstep = 0 )", "filename": "function_base.py", "nloc": 12, "complexity": 4, "token_count": 103, "parameters": [ "start", "stop", "num", "endpoint", "retstep" ], "start_line": 64, "end_line": 80, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 17, "top_nesting_level": 0 }, { "name": "fix", "long_name": "fix( x )", "filename": "function_base.py", "nloc": 4, "complexity": 1, "token_count": 35, "parameters": [ "x" ], "start_line": 82, "end_line": 87, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 6, "top_nesting_level": 0 }, { "name": "mod", "long_name": "mod( x , y )", "filename": "function_base.py", "nloc": 2, "complexity": 1, "token_count": 25, "parameters": [ "x", "y" ], "start_line": 89, "end_line": 95, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 7, "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": 97, "end_line": 143, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 47, "top_nesting_level": 0 }, { "name": "_asarray1d", "long_name": "_asarray1d( arr )", "filename": "function_base.py", "nloc": 5, "complexity": 2, "token_count": 35, "parameters": [ "arr" ], "start_line": 145, "end_line": 151, "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": 153, "end_line": 156, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 4, "top_nesting_level": 0 }, { "name": "take", "long_name": "take( a , indices , axis = 0 )", "filename": "function_base.py", "nloc": 6, "complexity": 2, "token_count": 32, "parameters": [ "a", "indices", "axis" ], "start_line": 158, "end_line": 165, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 8, "top_nesting_level": 0 }, { "name": "_no_axis_is_all", "long_name": "_no_axis_is_all( function , m , axis )", "filename": "function_base.py", "nloc": 16, "complexity": 4, "token_count": 86, "parameters": [ "function", "m", "axis" ], "start_line": 167, "end_line": 182, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 16, "top_nesting_level": 0 }, { "name": "amax", "long_name": "amax( m , axis = - 1 )", "filename": "function_base.py", "nloc": 2, "complexity": 1, "token_count": 22, "parameters": [ "m", "axis" ], "start_line": 185, "end_line": 188, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 4, "top_nesting_level": 0 }, { "name": "amin", "long_name": "amin( m , axis = - 1 )", "filename": "function_base.py", "nloc": 2, "complexity": 1, "token_count": 22, "parameters": [ "m", "axis" ], "start_line": 190, "end_line": 193, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 4, "top_nesting_level": 0 }, { "name": "alen", "long_name": "alen( m )", "filename": "function_base.py", "nloc": 2, "complexity": 1, "token_count": 14, "parameters": [ "m" ], "start_line": 195, "end_line": 198, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 4, "top_nesting_level": 0 }, { "name": "_amin_amax", "long_name": "_amin_amax( m , axis )", "filename": "function_base.py", "nloc": 2, "complexity": 1, "token_count": 21, "parameters": [ "m", "axis" ], "start_line": 202, "end_line": 203, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 2, "top_nesting_level": 0 }, { "name": "ptp", "long_name": "ptp( m , axis = - 1 )", "filename": "function_base.py", "nloc": 2, "complexity": 1, "token_count": 20, "parameters": [ "m", "axis" ], "start_line": 205, "end_line": 208, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 4, "top_nesting_level": 0 }, { "name": "cumsum", "long_name": "cumsum( m , axis = - 1 )", "filename": "function_base.py", "nloc": 2, "complexity": 1, "token_count": 22, "parameters": [ "m", "axis" ], "start_line": 210, "end_line": 213, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 4, "top_nesting_level": 0 }, { "name": "prod", "long_name": "prod( m , axis = - 1 )", "filename": "function_base.py", "nloc": 2, "complexity": 1, "token_count": 22, "parameters": [ "m", "axis" ], "start_line": 215, "end_line": 218, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 4, "top_nesting_level": 0 }, { "name": "cumprod", "long_name": "cumprod( m , axis = - 1 )", "filename": "function_base.py", "nloc": 2, "complexity": 1, "token_count": 22, "parameters": [ "m", "axis" ], "start_line": 220, "end_line": 223, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 4, "top_nesting_level": 0 }, { "name": "diff", "long_name": "diff( x , n = 1 , axis = - 1 )", "filename": "function_base.py", "nloc": 15, "complexity": 4, "token_count": 130, "parameters": [ "x", "n", "axis" ], "start_line": 225, "end_line": 241, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 17, "top_nesting_level": 0 }, { "name": "angle", "long_name": "angle( z , deg = 0 )", "filename": "function_base.py", "nloc": 13, "complexity": 3, "token_count": 71, "parameters": [ "z", "deg" ], "start_line": 243, "end_line": 256, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 14, "top_nesting_level": 0 }, { "name": "unwrap", "long_name": "unwrap( p , discont = pi , axis = - 1 )", "filename": "function_base.py", "nloc": 13, "complexity": 1, "token_count": 150, "parameters": [ "p", "discont", "axis" ], "start_line": 258, "end_line": 273, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 16, "top_nesting_level": 0 }, { "name": "sort_complex.complex_cmp", "long_name": "sort_complex.complex_cmp( x , y )", "filename": "function_base.py", "nloc": 5, "complexity": 2, "token_count": 38, "parameters": [ "x", "y" ], "start_line": 279, "end_line": 283, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 5, "top_nesting_level": 1 }, { "name": "sort_complex", "long_name": "sort_complex( a )", "filename": "function_base.py", "nloc": 6, "complexity": 1, "token_count": 44, "parameters": [ "a" ], "start_line": 275, "end_line": 286, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 12, "top_nesting_level": 0 }, { "name": "trim_zeros", "long_name": "trim_zeros( filt , trim = 'fb' )", "filename": "function_base.py", "nloc": 12, "complexity": 9, "token_count": 87, "parameters": [ "filt", "trim" ], "start_line": 288, "end_line": 307, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 20, "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": 309, "end_line": 315, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 7, "top_nesting_level": 0 }, { "name": "where", "long_name": "where( condition , x = None , y = None )", "filename": "function_base.py", "nloc": 5, "complexity": 3, "token_count": 53, "parameters": [ "condition", "x", "y" ], "start_line": 317, "end_line": 327, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 11, "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": 329, "end_line": 334, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 6, "top_nesting_level": 0 }, { "name": "insert", "long_name": "insert( arr , mask , vals )", "filename": "function_base.py", "nloc": 2, "complexity": 1, "token_count": 21, "parameters": [ "arr", "mask", "vals" ], "start_line": 336, "end_line": 340, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 5, "top_nesting_level": 0 }, { "name": "nansum", "long_name": "nansum( x , axis = - 1 )", "filename": "function_base.py", "nloc": 4, "complexity": 1, "token_count": 43, "parameters": [ "x", "axis" ], "start_line": 342, "end_line": 347, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 6, "top_nesting_level": 0 }, { "name": "nanmin", "long_name": "nanmin( x , axis = - 1 )", "filename": "function_base.py", "nloc": 4, "complexity": 1, "token_count": 41, "parameters": [ "x", "axis" ], "start_line": 349, "end_line": 354, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 6, "top_nesting_level": 0 }, { "name": "nanargmin", "long_name": "nanargmin( x , axis = - 1 )", "filename": "function_base.py", "nloc": 4, "complexity": 1, "token_count": 41, "parameters": [ "x", "axis" ], "start_line": 356, "end_line": 361, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 6, "top_nesting_level": 0 }, { "name": "nanmax", "long_name": "nanmax( x , axis = - 1 )", "filename": "function_base.py", "nloc": 4, "complexity": 1, "token_count": 42, "parameters": [ "x", "axis" ], "start_line": 364, "end_line": 369, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 6, "top_nesting_level": 0 }, { "name": "nanargmax", "long_name": "nanargmax( x , axis = - 1 )", "filename": "function_base.py", "nloc": 4, "complexity": 1, "token_count": 42, "parameters": [ "x", "axis" ], "start_line": 371, "end_line": 376, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 6, "top_nesting_level": 0 }, { "name": "disp", "long_name": "disp( mesg , device = None , linefeed = 1 )", "filename": "function_base.py", "nloc": 10, "complexity": 3, "token_count": 53, "parameters": [ "mesg", "device", "linefeed" ], "start_line": 378, "end_line": 389, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 12, "top_nesting_level": 0 }, { "name": "__init__", "long_name": "__init__( self , pyfunc , otypes = None , doc = None )", "filename": "function_base.py", "nloc": 15, "complexity": 6, "token_count": 92, "parameters": [ "self", "pyfunc", "otypes", "doc" ], "start_line": 421, "end_line": 435, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 15, "top_nesting_level": 1 }, { "name": "__call__", "long_name": "__call__( self , * args )", "filename": "function_base.py", "nloc": 5, "complexity": 2, "token_count": 37, "parameters": [ "self", "args" ], "start_line": 437, "end_line": 441, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 5, "top_nesting_level": 1 }, { "name": "zerocall", "long_name": "zerocall( self , * args )", "filename": "function_base.py", "nloc": 23, "complexity": 7, "token_count": 155, "parameters": [ "self", "args" ], "start_line": 443, "end_line": 470, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 28, "top_nesting_level": 1 } ], "changed_methods": [ { "name": "asarray_chkfinite", "long_name": "asarray_chkfinite( x )", "filename": "function_base.py", "nloc": 5, "complexity": 2, "token_count": 30, "parameters": [ "x" ], "start_line": 22, "end_line": 28, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 7, "top_nesting_level": 0 } ], "nloc": 301, "complexity": 90, "token_count": 2274, "diff_parsed": { "added": [ " if not all(_nx.isfinite(x)):" ], "deleted": [ " if not all(isfinite(x)):" ] } } ] }, { "hash": "bc05123388bec5c8b554eee92ae99d01b7cc64ec", "msg": "Fixed assert_almost_equal by using around() instead of round().", "author": { "name": "jmiller", "email": "jmiller@localhost" }, "committer": { "name": "jmiller", "email": "jmiller@localhost" }, "author_date": "2004-12-06T22:26:04+00:00", "author_timezone": 0, "committer_date": "2004-12-06T22:26:04+00:00", "committer_timezone": 0, "branches": [ "main" ], "in_main_branch": true, "merge": false, "parents": [ "8ab36c8b444c934c2aeefc624717dada6288ee5d" ], "project_name": "repo_copy", "project_path": "/tmp/tmpqop781_j/repo_copy", "deletions": 1, "insertions": 1, "lines": 2, "files": 1, "dmm_unit_size": null, "dmm_unit_complexity": null, "dmm_unit_interfacing": null, "modified_files": [ { "old_path": "scipy_test/testing.py", "new_path": "scipy_test/testing.py", "filename": "testing.py", "extension": "py", "change_type": "MODIFY", "diff": "@@ -660,7 +660,7 @@ def assert_almost_equal(actual,desired,decimal=7,err_msg='',verbose=1):\n msg = msg \\\n + 'DESIRED: ' + repr(desired) \\\n + '\\nACTUAL: ' + repr(actual)\n- assert all(round(abs(desired - actual),decimal) == 0), msg\n+ assert all(around(abs(desired - actual),decimal) == 0), msg\n \n __all__.append('assert_approx_equal')\n def assert_approx_equal(actual,desired,significant=7,err_msg='',verbose=1):\n", "added_lines": 1, "deleted_lines": 1, "source_code": "\"\"\"\nUnit-testing\n------------\n\n ScipyTest -- Scipy tests site manager\n ScipyTestCase -- unittest.TestCase with measure method\n IgnoreException -- raise when checking disabled feature ('ignoring' is displayed)\n set_package_path -- prepend package build directory to path\n set_local_path -- prepend local directory (to tests files) to path\n restore_path -- restore path after set_package_path\n\nTiming tools\n------------\n\n jiffies -- return 1/100ths of a second that the current process has used\n memusage -- virtual memory size in bytes of the running python [linux]\n\nUtility functions\n-----------------\n\n assert_equal -- assert equality\n assert_almost_equal -- assert equality with decimal tolerance\n assert_approx_equal -- assert equality with significant digits tolerance\n assert_array_equal -- assert arrays equality\n assert_array_almost_equal -- assert arrays equality with decimal tolerance\n assert_array_less -- assert arrays less-ordering\n rand -- array of random numbers from given shape\n\n\"\"\"\n\n__all__ = []\n\nimport os,sys,time,glob,string,traceback,unittest\nimport types\nimport imp\n\ntry:\n # These are used by Numeric tests.\n # If Numeric and scipy_base are not available, then some of the\n # functions below will not be available.\n from scipy_base.numerix import all, equal, shape, ravel, around, zeros, Float64, asarray\n from scipy_base.numerix import less_equal, array2string, less\nexcept ImportError:\n pass\n\nDEBUG = 0\n\n__all__.append('set_package_path')\ndef set_package_path(level=1):\n \"\"\" Prepend package directory to sys.path.\n\n set_package_path should be called from a test_file.py that\n satisfies the following tree structure:\n\n //test_file.py\n\n Then the first existing path name from the following list\n\n /build/lib.-\n /..\n\n is prepended to sys.path.\n The caller is responsible for removing this path by using\n\n restore_path()\n \"\"\"\n from distutils.util import get_platform\n from scipy_distutils.misc_util import get_frame\n f = get_frame(level)\n if f.f_locals['__name__']=='__main__':\n testfile = sys.argv[0]\n else:\n testfile = f.f_locals['__file__']\n d = os.path.dirname(os.path.dirname(os.path.abspath(testfile)))\n d1 = os.path.join(d,'build','lib.%s-%s'%(get_platform(),sys.version[:3]))\n if not os.path.isdir(d1):\n d1 = os.path.dirname(d)\n if DEBUG:\n print 'Inserting %r to sys.path' % (d1)\n sys.path.insert(0,d1)\n\n__all__.append('set_local_path')\ndef set_local_path(reldir='', level=1):\n \"\"\" Prepend local directory to sys.path.\n\n The caller is responsible for removing this path by using\n\n restore_path()\n \"\"\"\n from scipy_distutils.misc_util import get_frame\n f = get_frame(level)\n if f.f_locals['__name__']=='__main__':\n testfile = sys.argv[0]\n else:\n testfile = f.f_locals['__file__']\n local_path = os.path.join(os.path.dirname(os.path.abspath(testfile)),reldir)\n if DEBUG:\n print 'Inserting %r to sys.path' % (local_path)\n sys.path.insert(0,local_path)\n\n__all__.append('restore_path')\ndef restore_path():\n if DEBUG:\n print 'Removing %r from sys.path' % (sys.path[0])\n del sys.path[0]\n\n__all__.extend(['jiffies','memusage'])\nif sys.platform[:5]=='linux':\n def jiffies(_proc_pid_stat = '/proc/%s/stat'%(os.getpid()),\n _load_time=time.time()):\n \"\"\" Return number of jiffies (1/100ths of a second) that this\n process has been scheduled in user mode. See man 5 proc. \"\"\"\n try:\n f=open(_proc_pid_stat,'r')\n l = f.readline().split(' ')\n f.close()\n return int(l[13])\n except:\n return int(100*(time.time()-_load_time))\n\n def memusage(_proc_pid_stat = '/proc/%s/stat'%(os.getpid())):\n \"\"\" Return virtual memory size in bytes of the running python.\n \"\"\"\n try:\n f=open(_proc_pid_stat,'r')\n l = f.readline().split(' ')\n f.close()\n return int(l[22])\n except:\n return\nelse:\n # os.getpid is not in all platforms available.\n # Using time is safe but inaccurate, especially when process\n # was suspended or sleeping.\n def jiffies(_load_time=time.time()):\n \"\"\" Return number of jiffies (1/100ths of a second) that this\n process has been scheduled in user mode. [Emulation with time.time]. \"\"\"\n return int(100*(time.time()-_load_time))\n\n def memusage():\n \"\"\" Return memory usage of running python. [Not implemented]\"\"\"\n return\n\n__all__.append('ScipyTestCase')\nclass ScipyTestCase (unittest.TestCase):\n\n def measure(self,code_str,times=1):\n \"\"\" Return elapsed time for executing code_str in the\n namespace of the caller for given times.\n \"\"\"\n frame = sys._getframe(1)\n locs,globs = frame.f_locals,frame.f_globals\n code = compile(code_str,\n 'ScipyTestCase runner for '+self.__class__.__name__,\n 'exec')\n i = 0\n elapsed = jiffies()\n while i>> ScipyTest().test(level=1,verbosity=2)\n\n is package name or its module object.\n\n Package is supposed to contain a directory tests/\n with test_*.py files where * refers to the names of submodules.\n\n test_*.py files are supposed to define a classes, derived\n from ScipyTestCase or unittest.TestCase, with methods having\n names starting with test or bench or check.\n\n And that is it! No need to implement test or test_suite functions\n in each .py file.\n\n Also old styled test_suite(level=1) hooks are supported but\n soon to be removed.\n \"\"\"\n def __init__(self, package='__main__'):\n self.package = package\n\n def _module_str(self, module):\n filename = module.__file__[-30:]\n if filename!=module.__file__:\n filename = '...'+filename\n return '' % (`module.__name__`, `filename`)\n\n def _get_method_names(self,clsobj,level):\n names = []\n for mthname in _get_all_method_names(clsobj):\n if mthname[:5] not in ['bench','check'] \\\n and mthname[:4] not in ['test']:\n continue\n mth = getattr(clsobj, mthname)\n if type(mth) is not types.MethodType:\n continue\n d = mth.im_func.func_defaults\n if d is not None:\n mthlevel = d[0]\n else:\n mthlevel = 1\n if level>=mthlevel:\n if mthname not in names:\n names.append(mthname)\n for base in clsobj.__bases__:\n for n in self._get_method_names(base,level):\n if n not in names:\n names.append(n) \n return names\n\n def _get_module_tests(self,module,level):\n mstr = self._module_str\n d,f = os.path.split(module.__file__)\n\n short_module_name = os.path.splitext(os.path.basename(f))[0]\n if short_module_name=='__init__':\n short_module_name = module.__name__.split('.')[-1]\n\n test_dir = os.path.join(d,'tests')\n test_file = os.path.join(test_dir,'test_'+short_module_name+'.py')\n\n local_test_dir = os.path.join(os.getcwd(),'tests')\n local_test_file = os.path.join(local_test_dir,\n 'test_'+short_module_name+'.py')\n if os.path.basename(os.path.dirname(local_test_dir)) \\\n == os.path.basename(os.path.dirname(test_dir)) \\\n and os.path.isfile(local_test_file):\n test_file = local_test_file\n\n if not os.path.isfile(test_file):\n if short_module_name[:5]=='info_' \\\n and short_module_name[5:]==module.__name__.split('.')[-2]:\n return []\n if short_module_name in ['__cvs_version__','__svn_version__']:\n return []\n if short_module_name[-8:]=='_version' \\\n and short_module_name[:-8]==module.__name__.split('.')[-2]:\n return []\n print ' !! No test file %r found for %s' \\\n % (os.path.basename(test_file), mstr(module))\n return []\n\n try:\n if sys.version[:3]=='2.1':\n # Workaround for Python 2.1 .pyc file generator bug\n import random\n pref = '-nopyc'+`random.randint(1,100)`\n else:\n pref = ''\n f = open(test_file,'r')\n test_module = imp.load_module(\\\n module.__name__+'.test_'+short_module_name+pref,\n f, test_file+pref,('.py', 'r', 1))\n f.close()\n if sys.version[:3]=='2.1' and os.path.isfile(test_file+pref+'c'):\n os.remove(test_file+pref+'c')\n except:\n print ' !! FAILURE importing tests for ', mstr(module)\n print ' ',\n output_exception()\n return []\n return self._get_suite_list(test_module, level, module.__name__)\n\n def _get_suite_list(self, test_module, level, module_name='__main__'):\n mstr = self._module_str\n if hasattr(test_module,'test_suite'):\n # Using old styled test suite\n try:\n total_suite = test_module.test_suite(level)\n return total_suite._tests\n except:\n print ' !! FAILURE building tests for ', mstr(test_module)\n print ' ',\n output_exception()\n return []\n suite_list = []\n for name in dir(test_module):\n obj = getattr(test_module, name)\n if type(obj) is not type(unittest.TestCase) \\\n or not issubclass(obj, unittest.TestCase) \\\n or obj.__name__[:4] != 'test':\n continue\n for mthname in self._get_method_names(obj,level):\n suite = obj(mthname)\n if getattr(suite,'isrunnable',lambda mthname:1)(mthname):\n suite_list.append(suite)\n print ' Found',len(suite_list),'tests for',module_name\n return suite_list\n\n def _touch_ppimported(self, module):\n from scipy_base.ppimport import _ModuleLoader\n if os.path.isdir(os.path.join(os.path.dirname(module.__file__),'tests')):\n # only touching those modules that have tests/ directory\n try: module._pliuh_plauh\n except AttributeError: pass\n for name in dir(module):\n obj = getattr(module,name)\n if isinstance(obj,_ModuleLoader) \\\n and not hasattr(obj,'_ppimport_module') \\\n and not hasattr(obj,'_ppimport_exc_info'):\n self._touch_ppimported(obj)\n\n def test(self,level=1,verbosity=1):\n \"\"\" Run Scipy module test suite with level and verbosity.\n \"\"\"\n if type(self.package) is type(''):\n exec 'import %s as this_package' % (self.package)\n else:\n this_package = self.package\n\n self._touch_ppimported(this_package)\n\n package_name = this_package.__name__\n\n suites = []\n for name, module in sys.modules.items():\n if package_name != name[:len(package_name)] \\\n or module is None \\\n or os.path.basename(os.path.dirname(module.__file__))=='tests':\n continue\n suites.extend(self._get_module_tests(module, level))\n\n suites.extend(self._get_suite_list(sys.modules[package_name], level))\n\n all_tests = unittest.TestSuite(suites)\n runner = unittest.TextTestRunner(verbosity=verbosity)\n runner.run(all_tests)\n return runner\n\n def run(self):\n \"\"\" Run Scipy module test suite with level and verbosity\n taken from sys.argv. Requires optparse module.\n \"\"\"\n try:\n from optparse import OptionParser\n except ImportError:\n print 'Failed to import optparse module, ignoring.'\n return self.test()\n usage = r'usage: %prog [-v ] [-l ]'\n parser = OptionParser(usage)\n parser.add_option(\"-v\", \"--verbosity\",\n action=\"store\",\n dest=\"verbosity\",\n default=1,\n type='int')\n parser.add_option(\"-l\", \"--level\",\n action=\"store\",\n dest=\"level\",\n default=1,\n type='int')\n (options, args) = parser.parse_args()\n self.test(options.level,options.verbosity)\n\n#------------\n \ndef remove_ignored_patterns(files,pattern):\n from fnmatch import fnmatch\n good_files = []\n for file in files:\n if not fnmatch(file,pattern):\n good_files.append(file)\n return good_files\n\ndef remove_ignored_files(original,ignored_files,cur_dir):\n \"\"\" This is actually expanded to do pattern matching.\n\n \"\"\"\n if not ignored_files: ignored_files = []\n ignored_modules = map(lambda x: x+'.py',ignored_files)\n ignored_packages = ignored_files[:]\n # always ignore setup.py and __init__.py files\n ignored_files = ['setup.py','setup_*.py','__init__.py']\n ignored_files += ignored_modules + ignored_packages\n ignored_files = map(lambda x,cur_dir=cur_dir: os.path.join(cur_dir,x),\n ignored_files)\n #print 'ignored:', ignored_files\n #good_files = filter(lambda x,ignored = ignored_files: x not in ignored,\n # original)\n good_files = original\n for pattern in ignored_files:\n good_files = remove_ignored_patterns(good_files,pattern)\n\n return good_files\n\n__all__.append('harvest_modules')\ndef harvest_modules(package,ignore=None):\n \"\"\"* Retreive a list of all modules that live within a package.\n\n Only retreive files that are immediate children of the\n package -- do not recurse through child packages or\n directories. The returned list contains actual modules, not\n just their names.\n *\"\"\"\n d,f = os.path.split(package.__file__)\n\n # go through the directory and import every py file there.\n common_dir = os.path.join(d,'*.py')\n py_files = glob.glob(common_dir)\n #py_files.remove(os.path.join(d,'__init__.py'))\n #py_files.remove(os.path.join(d,'setup.py'))\n\n py_files = remove_ignored_files(py_files,ignore,d)\n #print 'py_files:', py_files\n try:\n prefix = package.__name__\n except:\n prefix = ''\n\n all_modules = []\n for file in py_files:\n d,f = os.path.split(file)\n base,ext = os.path.splitext(f)\n mod = prefix + '.' + base\n #print 'module: import ' + mod\n try:\n exec ('import ' + mod)\n all_modules.append(eval(mod))\n except:\n print 'FAILURE to import ' + mod\n output_exception()\n\n return all_modules\n\n__all__.append('harvest_packages')\ndef harvest_packages(package,ignore = None):\n \"\"\" Retreive a list of all sub-packages that live within a package.\n\n Only retreive packages that are immediate children of this\n package -- do not recurse through child packages or\n directories. The returned list contains actual package objects, not\n just their names.\n \"\"\"\n join = os.path.join\n\n d,f = os.path.split(package.__file__)\n\n common_dir = os.path.abspath(d)\n all_files = os.listdir(d)\n\n all_files = remove_ignored_files(all_files,ignore,'')\n #print 'all_files:', all_files\n try:\n prefix = package.__name__\n except:\n prefix = ''\n all_packages = []\n for directory in all_files:\n path = join(common_dir,directory)\n if os.path.isdir(path) and \\\n os.path.exists(join(path,'__init__.py')):\n sub_package = prefix + '.' + directory\n #print 'sub-package import ' + sub_package\n try:\n exec ('import ' + sub_package)\n all_packages.append(eval(sub_package))\n except:\n print 'FAILURE to import ' + sub_package\n output_exception()\n return all_packages\n\n__all__.append('harvest_modules_and_packages')\ndef harvest_modules_and_packages(package,ignore=None):\n \"\"\" Retreive list of all packages and modules that live within a package.\n\n See harvest_packages() and harvest_modules()\n \"\"\"\n all = harvest_modules(package,ignore) + harvest_packages(package,ignore)\n return all\n\n__all__.append('harvest_test_suites')\ndef harvest_test_suites(package,ignore = None,level=10):\n \"\"\"\n package -- the module to test. This is an actual module object\n (not a string)\n ignore -- a list of module names to omit from the tests\n level -- a value between 1 and 10. 1 will run the minimum number\n of tests. This is a fast \"smoke test\". Tests that take\n longer to run should have higher numbers ranging up to 10.\n \"\"\"\n suites=[]\n test_modules = harvest_modules_and_packages(package,ignore)\n #for i in test_modules:\n # print i.__name__\n for module in test_modules:\n if hasattr(module,'test_suite'):\n try:\n suite = module.test_suite(level=level)\n if suite:\n suites.append(suite)\n else:\n print \" !! FAILURE without error - shouldn't happen\",\n print module.__name__\n except:\n print ' !! FAILURE building test for ', module.__name__\n print ' ',\n output_exception()\n else:\n try:\n print 'No test suite found for ', module.__name__\n except AttributeError:\n # __version__.py getting replaced by a string throws a kink\n # in checking for modules, so we think is a module has\n # actually been overwritten\n print 'No test suite found for ', str(module)\n total_suite = unittest.TestSuite(suites)\n return total_suite\n\n__all__.append('module_test')\ndef module_test(mod_name,mod_file,level=10):\n \"\"\"*\n\n *\"\"\"\n #print 'testing', mod_name\n d,f = os.path.split(mod_file)\n\n # insert the tests directory to the python path\n test_dir = os.path.join(d,'tests')\n sys.path.insert(0,test_dir)\n\n # call the \"test_xxx.test()\" function for the appropriate\n # module.\n\n # This should deal with package naming issues correctly\n short_mod_name = string.split(mod_name,'.')[-1]\n test_module = 'test_' + short_mod_name\n test_string = 'import %s;reload(%s);%s.test(%d)' % \\\n ((test_module,)*3 + (level,))\n\n # This would be better cause it forces a reload of the orginal\n # module. It doesn't behave with packages however.\n #test_string = 'reload(%s);import %s;reload(%s);%s.test(%d)' % \\\n # ((mod_name,) + (test_module,)*3)\n exec(test_string)\n\n # remove test directory from python path.\n sys.path = sys.path[1:]\n\n__all__.append('module_test_suite')\ndef module_test_suite(mod_name,mod_file,level=10):\n #try:\n print ' creating test suite for:', mod_name\n d,f = os.path.split(mod_file)\n\n # insert the tests directory to the python path\n test_dir = os.path.join(d,'tests')\n sys.path.insert(0,test_dir)\n\n # call the \"test_xxx.test()\" function for the appropriate\n # module.\n\n # This should deal with package naming issues correctly\n short_mod_name = string.split(mod_name,'.')[-1]\n test_module = 'test_' + short_mod_name\n test_string = 'import %s;reload(%s);suite = %s.test_suite(%d)' % \\\n ((test_module,)*3+(level,))\n #print test_string\n exec(test_string)\n\n # remove test directory from python path.\n sys.path = sys.path[1:]\n return suite\n #except:\n # print ' !! FAILURE loading test suite from', test_module, ':'\n # print ' ',\n # output_exception()\n\n\n# Utility function to facilitate testing.\n\n__all__.append('assert_equal')\ndef assert_equal(actual,desired,err_msg='',verbose=1):\n \"\"\" Raise an assertion if two items are not\n equal. I think this should be part of unittest.py\n \"\"\"\n msg = '\\nItems are not equal:\\n' + err_msg\n try:\n if ( verbose and len(repr(desired)) < 100 and len(repr(actual)) ):\n msg = msg \\\n + 'DESIRED: ' + repr(desired) \\\n + '\\nACTUAL: ' + repr(actual)\n except:\n msg = msg \\\n + 'DESIRED: ' + repr(desired) \\\n + '\\nACTUAL: ' + repr(actual)\n assert all(desired == actual), msg\n\n__all__.append('assert_almost_equal')\ndef assert_almost_equal(actual,desired,decimal=7,err_msg='',verbose=1):\n \"\"\" Raise an assertion if two items are not\n equal. I think this should be part of unittest.py\n \"\"\"\n msg = '\\nItems are not equal:\\n' + err_msg\n try:\n if ( verbose and len(repr(desired)) < 100 and len(repr(actual)) ):\n msg = msg \\\n + 'DESIRED: ' + repr(desired) \\\n + '\\nACTUAL: ' + repr(actual)\n except:\n msg = msg \\\n + 'DESIRED: ' + repr(desired) \\\n + '\\nACTUAL: ' + repr(actual)\n assert all(around(abs(desired - actual),decimal) == 0), msg\n\n__all__.append('assert_approx_equal')\ndef assert_approx_equal(actual,desired,significant=7,err_msg='',verbose=1):\n \"\"\" Raise an assertion if two items are not\n equal. I think this should be part of unittest.py\n Approximately equal is defined as the number of significant digits\n correct\n \"\"\"\n msg = '\\nItems are not equal to %d significant digits:\\n' % significant\n msg += err_msg\n actual, desired = map(float, (actual, desired))\n # Normalized the numbers to be in range (-10.0,10.0)\n scale = pow(10,math.floor(math.log10(0.5*(abs(desired)+abs(actual)))))\n try:\n sc_desired = desired/scale\n except ZeroDivisionError:\n sc_desired = 0.0\n try:\n sc_actual = actual/scale\n except ZeroDivisionError:\n sc_actual = 0.0\n try:\n if ( verbose and len(repr(desired)) < 100 and len(repr(actual)) ):\n msg = msg \\\n + 'DESIRED: ' + repr(desired) \\\n + '\\nACTUAL: ' + repr(actual)\n except:\n msg = msg \\\n + 'DESIRED: ' + repr(desired) \\\n + '\\nACTUAL: ' + repr(actual)\n assert all(math.fabs(sc_desired - sc_actual) < pow(10.,-1*significant)), msg\n\n\n__all__.append('assert_array_equal')\ndef assert_array_equal(x,y,err_msg=''):\n x,y = asarray(x), asarray(y)\n msg = '\\nArrays are not equal'\n try:\n assert 0 in [len(shape(x)),len(shape(y))] \\\n or (len(shape(x))==len(shape(y)) and \\\n all(equal(shape(x),shape(y)))),\\\n msg + ' (shapes %s, %s mismatch):\\n\\t' \\\n % (shape(x),shape(y)) + err_msg\n reduced = ravel(equal(x,y))\n cond = all(reduced)\n if not cond:\n s1 = array2string(x,precision=16)\n s2 = array2string(y,precision=16)\n if len(s1)>120: s1 = s1[:120] + '...'\n if len(s2)>120: s2 = s2[:120] + '...'\n match = 100-100.0*reduced.tolist().count(1)/len(reduced)\n msg = msg + ' (mismatch %s%%):\\n\\tArray 1: %s\\n\\tArray 2: %s' % (match,s1,s2)\n assert cond,\\\n msg + '\\n\\t' + err_msg\n except ValueError:\n raise ValueError, msg\n\n__all__.append('assert_array_almost_equal')\ndef assert_array_almost_equal(x,y,decimal=6,err_msg=''):\n x = asarray(x)\n y = asarray(y)\n msg = '\\nArrays are not almost equal'\n try:\n cond = all(equal(shape(x),shape(y)))\n if not cond:\n msg = msg + ' (shapes mismatch):\\n\\t'\\\n 'Shape of array 1: %s\\n\\tShape of array 2: %s' % (shape(x),shape(y))\n assert cond, msg + '\\n\\t' + err_msg\n reduced = ravel(equal(less_equal(around(abs(x-y),decimal),10.0**(-decimal)),1))\n cond = all(reduced)\n if not cond:\n s1 = array2string(x,precision=decimal+1)\n s2 = array2string(y,precision=decimal+1)\n if len(s1)>120: s1 = s1[:120] + '...'\n if len(s2)>120: s2 = s2[:120] + '...'\n match = 100-100.0*reduced.tolist().count(1)/len(reduced)\n msg = msg + ' (mismatch %s%%):\\n\\tArray 1: %s\\n\\tArray 2: %s' % (match,s1,s2)\n assert cond,\\\n msg + '\\n\\t' + err_msg\n except ValueError:\n print sys.exc_value\n print shape(x),shape(y)\n print x, y\n raise ValueError, 'arrays are not almost equal'\n\n__all__.append('assert_array_less')\ndef assert_array_less(x,y,err_msg=''):\n x,y = asarray(x), asarray(y)\n msg = '\\nArrays are not less-ordered'\n try:\n assert all(equal(shape(x),shape(y))),\\\n msg + ' (shapes mismatch):\\n\\t' + err_msg\n reduced = ravel(less(x,y))\n cond = all(reduced)\n if not cond:\n s1 = array2string(x,precision=16)\n s2 = array2string(y,precision=16)\n if len(s1)>120: s1 = s1[:120] + '...'\n if len(s2)>120: s2 = s2[:120] + '...'\n match = 100-100.0*reduced.tolist().count(1)/len(reduced)\n msg = msg + ' (mismatch %s%%):\\n\\tArray 1: %s\\n\\tArray 2: %s' % (match,s1,s2)\n assert cond,\\\n msg + '\\n\\t' + err_msg\n except ValueError:\n print shape(x),shape(y)\n raise ValueError, 'arrays are not less-ordered'\n\n__all__.append('rand')\ndef rand(*args):\n \"\"\" Returns an array of random numbers with the given shape.\n used for testing\n \"\"\"\n import random\n results = zeros(args,Float64)\n f = results.flat\n for i in range(len(f)):\n f[i] = random.random()\n return results\n\ndef output_exception():\n try:\n type, value, tb = sys.exc_info()\n info = traceback.extract_tb(tb)\n #this is more verbose\n #traceback.print_exc()\n filename, lineno, function, text = info[-1] # last line only\n print \"%s:%d: %s: %s (in %s)\" %\\\n (filename, lineno, type.__name__, str(value), function)\n finally:\n type = value = tb = None # clean up\n\ntry:\n from scipy_base.numerix import fastumath as math\nexcept ImportError,msg:\n print msg\n import math\n", "source_code_before": "\"\"\"\nUnit-testing\n------------\n\n ScipyTest -- Scipy tests site manager\n ScipyTestCase -- unittest.TestCase with measure method\n IgnoreException -- raise when checking disabled feature ('ignoring' is displayed)\n set_package_path -- prepend package build directory to path\n set_local_path -- prepend local directory (to tests files) to path\n restore_path -- restore path after set_package_path\n\nTiming tools\n------------\n\n jiffies -- return 1/100ths of a second that the current process has used\n memusage -- virtual memory size in bytes of the running python [linux]\n\nUtility functions\n-----------------\n\n assert_equal -- assert equality\n assert_almost_equal -- assert equality with decimal tolerance\n assert_approx_equal -- assert equality with significant digits tolerance\n assert_array_equal -- assert arrays equality\n assert_array_almost_equal -- assert arrays equality with decimal tolerance\n assert_array_less -- assert arrays less-ordering\n rand -- array of random numbers from given shape\n\n\"\"\"\n\n__all__ = []\n\nimport os,sys,time,glob,string,traceback,unittest\nimport types\nimport imp\n\ntry:\n # These are used by Numeric tests.\n # If Numeric and scipy_base are not available, then some of the\n # functions below will not be available.\n from scipy_base.numerix import all, equal, shape, ravel, around, zeros, Float64, asarray\n from scipy_base.numerix import less_equal, array2string, less\nexcept ImportError:\n pass\n\nDEBUG = 0\n\n__all__.append('set_package_path')\ndef set_package_path(level=1):\n \"\"\" Prepend package directory to sys.path.\n\n set_package_path should be called from a test_file.py that\n satisfies the following tree structure:\n\n //test_file.py\n\n Then the first existing path name from the following list\n\n /build/lib.-\n /..\n\n is prepended to sys.path.\n The caller is responsible for removing this path by using\n\n restore_path()\n \"\"\"\n from distutils.util import get_platform\n from scipy_distutils.misc_util import get_frame\n f = get_frame(level)\n if f.f_locals['__name__']=='__main__':\n testfile = sys.argv[0]\n else:\n testfile = f.f_locals['__file__']\n d = os.path.dirname(os.path.dirname(os.path.abspath(testfile)))\n d1 = os.path.join(d,'build','lib.%s-%s'%(get_platform(),sys.version[:3]))\n if not os.path.isdir(d1):\n d1 = os.path.dirname(d)\n if DEBUG:\n print 'Inserting %r to sys.path' % (d1)\n sys.path.insert(0,d1)\n\n__all__.append('set_local_path')\ndef set_local_path(reldir='', level=1):\n \"\"\" Prepend local directory to sys.path.\n\n The caller is responsible for removing this path by using\n\n restore_path()\n \"\"\"\n from scipy_distutils.misc_util import get_frame\n f = get_frame(level)\n if f.f_locals['__name__']=='__main__':\n testfile = sys.argv[0]\n else:\n testfile = f.f_locals['__file__']\n local_path = os.path.join(os.path.dirname(os.path.abspath(testfile)),reldir)\n if DEBUG:\n print 'Inserting %r to sys.path' % (local_path)\n sys.path.insert(0,local_path)\n\n__all__.append('restore_path')\ndef restore_path():\n if DEBUG:\n print 'Removing %r from sys.path' % (sys.path[0])\n del sys.path[0]\n\n__all__.extend(['jiffies','memusage'])\nif sys.platform[:5]=='linux':\n def jiffies(_proc_pid_stat = '/proc/%s/stat'%(os.getpid()),\n _load_time=time.time()):\n \"\"\" Return number of jiffies (1/100ths of a second) that this\n process has been scheduled in user mode. See man 5 proc. \"\"\"\n try:\n f=open(_proc_pid_stat,'r')\n l = f.readline().split(' ')\n f.close()\n return int(l[13])\n except:\n return int(100*(time.time()-_load_time))\n\n def memusage(_proc_pid_stat = '/proc/%s/stat'%(os.getpid())):\n \"\"\" Return virtual memory size in bytes of the running python.\n \"\"\"\n try:\n f=open(_proc_pid_stat,'r')\n l = f.readline().split(' ')\n f.close()\n return int(l[22])\n except:\n return\nelse:\n # os.getpid is not in all platforms available.\n # Using time is safe but inaccurate, especially when process\n # was suspended or sleeping.\n def jiffies(_load_time=time.time()):\n \"\"\" Return number of jiffies (1/100ths of a second) that this\n process has been scheduled in user mode. [Emulation with time.time]. \"\"\"\n return int(100*(time.time()-_load_time))\n\n def memusage():\n \"\"\" Return memory usage of running python. [Not implemented]\"\"\"\n return\n\n__all__.append('ScipyTestCase')\nclass ScipyTestCase (unittest.TestCase):\n\n def measure(self,code_str,times=1):\n \"\"\" Return elapsed time for executing code_str in the\n namespace of the caller for given times.\n \"\"\"\n frame = sys._getframe(1)\n locs,globs = frame.f_locals,frame.f_globals\n code = compile(code_str,\n 'ScipyTestCase runner for '+self.__class__.__name__,\n 'exec')\n i = 0\n elapsed = jiffies()\n while i>> ScipyTest().test(level=1,verbosity=2)\n\n is package name or its module object.\n\n Package is supposed to contain a directory tests/\n with test_*.py files where * refers to the names of submodules.\n\n test_*.py files are supposed to define a classes, derived\n from ScipyTestCase or unittest.TestCase, with methods having\n names starting with test or bench or check.\n\n And that is it! No need to implement test or test_suite functions\n in each .py file.\n\n Also old styled test_suite(level=1) hooks are supported but\n soon to be removed.\n \"\"\"\n def __init__(self, package='__main__'):\n self.package = package\n\n def _module_str(self, module):\n filename = module.__file__[-30:]\n if filename!=module.__file__:\n filename = '...'+filename\n return '' % (`module.__name__`, `filename`)\n\n def _get_method_names(self,clsobj,level):\n names = []\n for mthname in _get_all_method_names(clsobj):\n if mthname[:5] not in ['bench','check'] \\\n and mthname[:4] not in ['test']:\n continue\n mth = getattr(clsobj, mthname)\n if type(mth) is not types.MethodType:\n continue\n d = mth.im_func.func_defaults\n if d is not None:\n mthlevel = d[0]\n else:\n mthlevel = 1\n if level>=mthlevel:\n if mthname not in names:\n names.append(mthname)\n for base in clsobj.__bases__:\n for n in self._get_method_names(base,level):\n if n not in names:\n names.append(n) \n return names\n\n def _get_module_tests(self,module,level):\n mstr = self._module_str\n d,f = os.path.split(module.__file__)\n\n short_module_name = os.path.splitext(os.path.basename(f))[0]\n if short_module_name=='__init__':\n short_module_name = module.__name__.split('.')[-1]\n\n test_dir = os.path.join(d,'tests')\n test_file = os.path.join(test_dir,'test_'+short_module_name+'.py')\n\n local_test_dir = os.path.join(os.getcwd(),'tests')\n local_test_file = os.path.join(local_test_dir,\n 'test_'+short_module_name+'.py')\n if os.path.basename(os.path.dirname(local_test_dir)) \\\n == os.path.basename(os.path.dirname(test_dir)) \\\n and os.path.isfile(local_test_file):\n test_file = local_test_file\n\n if not os.path.isfile(test_file):\n if short_module_name[:5]=='info_' \\\n and short_module_name[5:]==module.__name__.split('.')[-2]:\n return []\n if short_module_name in ['__cvs_version__','__svn_version__']:\n return []\n if short_module_name[-8:]=='_version' \\\n and short_module_name[:-8]==module.__name__.split('.')[-2]:\n return []\n print ' !! No test file %r found for %s' \\\n % (os.path.basename(test_file), mstr(module))\n return []\n\n try:\n if sys.version[:3]=='2.1':\n # Workaround for Python 2.1 .pyc file generator bug\n import random\n pref = '-nopyc'+`random.randint(1,100)`\n else:\n pref = ''\n f = open(test_file,'r')\n test_module = imp.load_module(\\\n module.__name__+'.test_'+short_module_name+pref,\n f, test_file+pref,('.py', 'r', 1))\n f.close()\n if sys.version[:3]=='2.1' and os.path.isfile(test_file+pref+'c'):\n os.remove(test_file+pref+'c')\n except:\n print ' !! FAILURE importing tests for ', mstr(module)\n print ' ',\n output_exception()\n return []\n return self._get_suite_list(test_module, level, module.__name__)\n\n def _get_suite_list(self, test_module, level, module_name='__main__'):\n mstr = self._module_str\n if hasattr(test_module,'test_suite'):\n # Using old styled test suite\n try:\n total_suite = test_module.test_suite(level)\n return total_suite._tests\n except:\n print ' !! FAILURE building tests for ', mstr(test_module)\n print ' ',\n output_exception()\n return []\n suite_list = []\n for name in dir(test_module):\n obj = getattr(test_module, name)\n if type(obj) is not type(unittest.TestCase) \\\n or not issubclass(obj, unittest.TestCase) \\\n or obj.__name__[:4] != 'test':\n continue\n for mthname in self._get_method_names(obj,level):\n suite = obj(mthname)\n if getattr(suite,'isrunnable',lambda mthname:1)(mthname):\n suite_list.append(suite)\n print ' Found',len(suite_list),'tests for',module_name\n return suite_list\n\n def _touch_ppimported(self, module):\n from scipy_base.ppimport import _ModuleLoader\n if os.path.isdir(os.path.join(os.path.dirname(module.__file__),'tests')):\n # only touching those modules that have tests/ directory\n try: module._pliuh_plauh\n except AttributeError: pass\n for name in dir(module):\n obj = getattr(module,name)\n if isinstance(obj,_ModuleLoader) \\\n and not hasattr(obj,'_ppimport_module') \\\n and not hasattr(obj,'_ppimport_exc_info'):\n self._touch_ppimported(obj)\n\n def test(self,level=1,verbosity=1):\n \"\"\" Run Scipy module test suite with level and verbosity.\n \"\"\"\n if type(self.package) is type(''):\n exec 'import %s as this_package' % (self.package)\n else:\n this_package = self.package\n\n self._touch_ppimported(this_package)\n\n package_name = this_package.__name__\n\n suites = []\n for name, module in sys.modules.items():\n if package_name != name[:len(package_name)] \\\n or module is None \\\n or os.path.basename(os.path.dirname(module.__file__))=='tests':\n continue\n suites.extend(self._get_module_tests(module, level))\n\n suites.extend(self._get_suite_list(sys.modules[package_name], level))\n\n all_tests = unittest.TestSuite(suites)\n runner = unittest.TextTestRunner(verbosity=verbosity)\n runner.run(all_tests)\n return runner\n\n def run(self):\n \"\"\" Run Scipy module test suite with level and verbosity\n taken from sys.argv. Requires optparse module.\n \"\"\"\n try:\n from optparse import OptionParser\n except ImportError:\n print 'Failed to import optparse module, ignoring.'\n return self.test()\n usage = r'usage: %prog [-v ] [-l ]'\n parser = OptionParser(usage)\n parser.add_option(\"-v\", \"--verbosity\",\n action=\"store\",\n dest=\"verbosity\",\n default=1,\n type='int')\n parser.add_option(\"-l\", \"--level\",\n action=\"store\",\n dest=\"level\",\n default=1,\n type='int')\n (options, args) = parser.parse_args()\n self.test(options.level,options.verbosity)\n\n#------------\n \ndef remove_ignored_patterns(files,pattern):\n from fnmatch import fnmatch\n good_files = []\n for file in files:\n if not fnmatch(file,pattern):\n good_files.append(file)\n return good_files\n\ndef remove_ignored_files(original,ignored_files,cur_dir):\n \"\"\" This is actually expanded to do pattern matching.\n\n \"\"\"\n if not ignored_files: ignored_files = []\n ignored_modules = map(lambda x: x+'.py',ignored_files)\n ignored_packages = ignored_files[:]\n # always ignore setup.py and __init__.py files\n ignored_files = ['setup.py','setup_*.py','__init__.py']\n ignored_files += ignored_modules + ignored_packages\n ignored_files = map(lambda x,cur_dir=cur_dir: os.path.join(cur_dir,x),\n ignored_files)\n #print 'ignored:', ignored_files\n #good_files = filter(lambda x,ignored = ignored_files: x not in ignored,\n # original)\n good_files = original\n for pattern in ignored_files:\n good_files = remove_ignored_patterns(good_files,pattern)\n\n return good_files\n\n__all__.append('harvest_modules')\ndef harvest_modules(package,ignore=None):\n \"\"\"* Retreive a list of all modules that live within a package.\n\n Only retreive files that are immediate children of the\n package -- do not recurse through child packages or\n directories. The returned list contains actual modules, not\n just their names.\n *\"\"\"\n d,f = os.path.split(package.__file__)\n\n # go through the directory and import every py file there.\n common_dir = os.path.join(d,'*.py')\n py_files = glob.glob(common_dir)\n #py_files.remove(os.path.join(d,'__init__.py'))\n #py_files.remove(os.path.join(d,'setup.py'))\n\n py_files = remove_ignored_files(py_files,ignore,d)\n #print 'py_files:', py_files\n try:\n prefix = package.__name__\n except:\n prefix = ''\n\n all_modules = []\n for file in py_files:\n d,f = os.path.split(file)\n base,ext = os.path.splitext(f)\n mod = prefix + '.' + base\n #print 'module: import ' + mod\n try:\n exec ('import ' + mod)\n all_modules.append(eval(mod))\n except:\n print 'FAILURE to import ' + mod\n output_exception()\n\n return all_modules\n\n__all__.append('harvest_packages')\ndef harvest_packages(package,ignore = None):\n \"\"\" Retreive a list of all sub-packages that live within a package.\n\n Only retreive packages that are immediate children of this\n package -- do not recurse through child packages or\n directories. The returned list contains actual package objects, not\n just their names.\n \"\"\"\n join = os.path.join\n\n d,f = os.path.split(package.__file__)\n\n common_dir = os.path.abspath(d)\n all_files = os.listdir(d)\n\n all_files = remove_ignored_files(all_files,ignore,'')\n #print 'all_files:', all_files\n try:\n prefix = package.__name__\n except:\n prefix = ''\n all_packages = []\n for directory in all_files:\n path = join(common_dir,directory)\n if os.path.isdir(path) and \\\n os.path.exists(join(path,'__init__.py')):\n sub_package = prefix + '.' + directory\n #print 'sub-package import ' + sub_package\n try:\n exec ('import ' + sub_package)\n all_packages.append(eval(sub_package))\n except:\n print 'FAILURE to import ' + sub_package\n output_exception()\n return all_packages\n\n__all__.append('harvest_modules_and_packages')\ndef harvest_modules_and_packages(package,ignore=None):\n \"\"\" Retreive list of all packages and modules that live within a package.\n\n See harvest_packages() and harvest_modules()\n \"\"\"\n all = harvest_modules(package,ignore) + harvest_packages(package,ignore)\n return all\n\n__all__.append('harvest_test_suites')\ndef harvest_test_suites(package,ignore = None,level=10):\n \"\"\"\n package -- the module to test. This is an actual module object\n (not a string)\n ignore -- a list of module names to omit from the tests\n level -- a value between 1 and 10. 1 will run the minimum number\n of tests. This is a fast \"smoke test\". Tests that take\n longer to run should have higher numbers ranging up to 10.\n \"\"\"\n suites=[]\n test_modules = harvest_modules_and_packages(package,ignore)\n #for i in test_modules:\n # print i.__name__\n for module in test_modules:\n if hasattr(module,'test_suite'):\n try:\n suite = module.test_suite(level=level)\n if suite:\n suites.append(suite)\n else:\n print \" !! FAILURE without error - shouldn't happen\",\n print module.__name__\n except:\n print ' !! FAILURE building test for ', module.__name__\n print ' ',\n output_exception()\n else:\n try:\n print 'No test suite found for ', module.__name__\n except AttributeError:\n # __version__.py getting replaced by a string throws a kink\n # in checking for modules, so we think is a module has\n # actually been overwritten\n print 'No test suite found for ', str(module)\n total_suite = unittest.TestSuite(suites)\n return total_suite\n\n__all__.append('module_test')\ndef module_test(mod_name,mod_file,level=10):\n \"\"\"*\n\n *\"\"\"\n #print 'testing', mod_name\n d,f = os.path.split(mod_file)\n\n # insert the tests directory to the python path\n test_dir = os.path.join(d,'tests')\n sys.path.insert(0,test_dir)\n\n # call the \"test_xxx.test()\" function for the appropriate\n # module.\n\n # This should deal with package naming issues correctly\n short_mod_name = string.split(mod_name,'.')[-1]\n test_module = 'test_' + short_mod_name\n test_string = 'import %s;reload(%s);%s.test(%d)' % \\\n ((test_module,)*3 + (level,))\n\n # This would be better cause it forces a reload of the orginal\n # module. It doesn't behave with packages however.\n #test_string = 'reload(%s);import %s;reload(%s);%s.test(%d)' % \\\n # ((mod_name,) + (test_module,)*3)\n exec(test_string)\n\n # remove test directory from python path.\n sys.path = sys.path[1:]\n\n__all__.append('module_test_suite')\ndef module_test_suite(mod_name,mod_file,level=10):\n #try:\n print ' creating test suite for:', mod_name\n d,f = os.path.split(mod_file)\n\n # insert the tests directory to the python path\n test_dir = os.path.join(d,'tests')\n sys.path.insert(0,test_dir)\n\n # call the \"test_xxx.test()\" function for the appropriate\n # module.\n\n # This should deal with package naming issues correctly\n short_mod_name = string.split(mod_name,'.')[-1]\n test_module = 'test_' + short_mod_name\n test_string = 'import %s;reload(%s);suite = %s.test_suite(%d)' % \\\n ((test_module,)*3+(level,))\n #print test_string\n exec(test_string)\n\n # remove test directory from python path.\n sys.path = sys.path[1:]\n return suite\n #except:\n # print ' !! FAILURE loading test suite from', test_module, ':'\n # print ' ',\n # output_exception()\n\n\n# Utility function to facilitate testing.\n\n__all__.append('assert_equal')\ndef assert_equal(actual,desired,err_msg='',verbose=1):\n \"\"\" Raise an assertion if two items are not\n equal. I think this should be part of unittest.py\n \"\"\"\n msg = '\\nItems are not equal:\\n' + err_msg\n try:\n if ( verbose and len(repr(desired)) < 100 and len(repr(actual)) ):\n msg = msg \\\n + 'DESIRED: ' + repr(desired) \\\n + '\\nACTUAL: ' + repr(actual)\n except:\n msg = msg \\\n + 'DESIRED: ' + repr(desired) \\\n + '\\nACTUAL: ' + repr(actual)\n assert all(desired == actual), msg\n\n__all__.append('assert_almost_equal')\ndef assert_almost_equal(actual,desired,decimal=7,err_msg='',verbose=1):\n \"\"\" Raise an assertion if two items are not\n equal. I think this should be part of unittest.py\n \"\"\"\n msg = '\\nItems are not equal:\\n' + err_msg\n try:\n if ( verbose and len(repr(desired)) < 100 and len(repr(actual)) ):\n msg = msg \\\n + 'DESIRED: ' + repr(desired) \\\n + '\\nACTUAL: ' + repr(actual)\n except:\n msg = msg \\\n + 'DESIRED: ' + repr(desired) \\\n + '\\nACTUAL: ' + repr(actual)\n assert all(round(abs(desired - actual),decimal) == 0), msg\n\n__all__.append('assert_approx_equal')\ndef assert_approx_equal(actual,desired,significant=7,err_msg='',verbose=1):\n \"\"\" Raise an assertion if two items are not\n equal. I think this should be part of unittest.py\n Approximately equal is defined as the number of significant digits\n correct\n \"\"\"\n msg = '\\nItems are not equal to %d significant digits:\\n' % significant\n msg += err_msg\n actual, desired = map(float, (actual, desired))\n # Normalized the numbers to be in range (-10.0,10.0)\n scale = pow(10,math.floor(math.log10(0.5*(abs(desired)+abs(actual)))))\n try:\n sc_desired = desired/scale\n except ZeroDivisionError:\n sc_desired = 0.0\n try:\n sc_actual = actual/scale\n except ZeroDivisionError:\n sc_actual = 0.0\n try:\n if ( verbose and len(repr(desired)) < 100 and len(repr(actual)) ):\n msg = msg \\\n + 'DESIRED: ' + repr(desired) \\\n + '\\nACTUAL: ' + repr(actual)\n except:\n msg = msg \\\n + 'DESIRED: ' + repr(desired) \\\n + '\\nACTUAL: ' + repr(actual)\n assert all(math.fabs(sc_desired - sc_actual) < pow(10.,-1*significant)), msg\n\n\n__all__.append('assert_array_equal')\ndef assert_array_equal(x,y,err_msg=''):\n x,y = asarray(x), asarray(y)\n msg = '\\nArrays are not equal'\n try:\n assert 0 in [len(shape(x)),len(shape(y))] \\\n or (len(shape(x))==len(shape(y)) and \\\n all(equal(shape(x),shape(y)))),\\\n msg + ' (shapes %s, %s mismatch):\\n\\t' \\\n % (shape(x),shape(y)) + err_msg\n reduced = ravel(equal(x,y))\n cond = all(reduced)\n if not cond:\n s1 = array2string(x,precision=16)\n s2 = array2string(y,precision=16)\n if len(s1)>120: s1 = s1[:120] + '...'\n if len(s2)>120: s2 = s2[:120] + '...'\n match = 100-100.0*reduced.tolist().count(1)/len(reduced)\n msg = msg + ' (mismatch %s%%):\\n\\tArray 1: %s\\n\\tArray 2: %s' % (match,s1,s2)\n assert cond,\\\n msg + '\\n\\t' + err_msg\n except ValueError:\n raise ValueError, msg\n\n__all__.append('assert_array_almost_equal')\ndef assert_array_almost_equal(x,y,decimal=6,err_msg=''):\n x = asarray(x)\n y = asarray(y)\n msg = '\\nArrays are not almost equal'\n try:\n cond = all(equal(shape(x),shape(y)))\n if not cond:\n msg = msg + ' (shapes mismatch):\\n\\t'\\\n 'Shape of array 1: %s\\n\\tShape of array 2: %s' % (shape(x),shape(y))\n assert cond, msg + '\\n\\t' + err_msg\n reduced = ravel(equal(less_equal(around(abs(x-y),decimal),10.0**(-decimal)),1))\n cond = all(reduced)\n if not cond:\n s1 = array2string(x,precision=decimal+1)\n s2 = array2string(y,precision=decimal+1)\n if len(s1)>120: s1 = s1[:120] + '...'\n if len(s2)>120: s2 = s2[:120] + '...'\n match = 100-100.0*reduced.tolist().count(1)/len(reduced)\n msg = msg + ' (mismatch %s%%):\\n\\tArray 1: %s\\n\\tArray 2: %s' % (match,s1,s2)\n assert cond,\\\n msg + '\\n\\t' + err_msg\n except ValueError:\n print sys.exc_value\n print shape(x),shape(y)\n print x, y\n raise ValueError, 'arrays are not almost equal'\n\n__all__.append('assert_array_less')\ndef assert_array_less(x,y,err_msg=''):\n x,y = asarray(x), asarray(y)\n msg = '\\nArrays are not less-ordered'\n try:\n assert all(equal(shape(x),shape(y))),\\\n msg + ' (shapes mismatch):\\n\\t' + err_msg\n reduced = ravel(less(x,y))\n cond = all(reduced)\n if not cond:\n s1 = array2string(x,precision=16)\n s2 = array2string(y,precision=16)\n if len(s1)>120: s1 = s1[:120] + '...'\n if len(s2)>120: s2 = s2[:120] + '...'\n match = 100-100.0*reduced.tolist().count(1)/len(reduced)\n msg = msg + ' (mismatch %s%%):\\n\\tArray 1: %s\\n\\tArray 2: %s' % (match,s1,s2)\n assert cond,\\\n msg + '\\n\\t' + err_msg\n except ValueError:\n print shape(x),shape(y)\n raise ValueError, 'arrays are not less-ordered'\n\n__all__.append('rand')\ndef rand(*args):\n \"\"\" Returns an array of random numbers with the given shape.\n used for testing\n \"\"\"\n import random\n results = zeros(args,Float64)\n f = results.flat\n for i in range(len(f)):\n f[i] = random.random()\n return results\n\ndef output_exception():\n try:\n type, value, tb = sys.exc_info()\n info = traceback.extract_tb(tb)\n #this is more verbose\n #traceback.print_exc()\n filename, lineno, function, text = info[-1] # last line only\n print \"%s:%d: %s: %s (in %s)\" %\\\n (filename, lineno, type.__name__, str(value), function)\n finally:\n type = value = tb = None # clean up\n\ntry:\n from scipy_base.numerix import fastumath as math\nexcept ImportError,msg:\n print msg\n import math\n", "methods": [ { "name": "set_package_path", "long_name": "set_package_path( level = 1 )", "filename": "testing.py", "nloc": 15, "complexity": 4, "token_count": 146, "parameters": [ "level" ], "start_line": 49, "end_line": 80, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 32, "top_nesting_level": 0 }, { "name": "set_local_path", "long_name": "set_local_path( reldir = '' , level = 1 )", "filename": "testing.py", "nloc": 11, "complexity": 3, "token_count": 97, "parameters": [ "reldir", "level" ], "start_line": 83, "end_line": 99, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 17, "top_nesting_level": 0 }, { "name": "restore_path", "long_name": "restore_path( )", "filename": "testing.py", "nloc": 4, "complexity": 2, "token_count": 25, "parameters": [], "start_line": 102, "end_line": 105, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 4, "top_nesting_level": 0 }, { "name": "jiffies", "long_name": "jiffies( _proc_pid_stat = '/proc/%s/stat' % ( os . getpid ( )", "filename": "testing.py", "nloc": 2, "complexity": 1, "token_count": 23, "parameters": [ "_proc_pid_stat" ], "start_line": 109, "end_line": 110, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 2, "top_nesting_level": 1 }, { "name": "memusage", "long_name": "memusage( _proc_pid_stat = '/proc/%s/stat' % ( os . getpid ( )", "filename": "testing.py", "nloc": 10, "complexity": 2, "token_count": 54, "parameters": [ "_proc_pid_stat" ], "start_line": 121, "end_line": 130, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 10, "top_nesting_level": 1 }, { "name": "jiffies", "long_name": "jiffies( _load_time = time . time ( )", "filename": "testing.py", "nloc": 4, "complexity": 1, "token_count": 27, "parameters": [ "_load_time" ], "start_line": 135, "end_line": 138, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 4, "top_nesting_level": 1 }, { "name": "memusage", "long_name": "memusage( )", "filename": "testing.py", "nloc": 2, "complexity": 1, "token_count": 6, "parameters": [], "start_line": 140, "end_line": 142, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 3, "top_nesting_level": 1 }, { "name": "measure", "long_name": "measure( self , code_str , times = 1 )", "filename": "testing.py", "nloc": 13, "complexity": 2, "token_count": 82, "parameters": [ "self", "code_str", "times" ], "start_line": 147, "end_line": 162, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 16, "top_nesting_level": 1 }, { "name": "__call__", "long_name": "__call__( self , result = None )", "filename": "testing.py", "nloc": 24, "complexity": 6, "token_count": 224, "parameters": [ "self", "result" ], "start_line": 164, "end_line": 188, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 25, "top_nesting_level": 1 }, { "name": "__init__", "long_name": "__init__( self , stream )", "filename": "testing.py", "nloc": 3, "complexity": 1, "token_count": 18, "parameters": [ "self", "stream" ], "start_line": 191, "end_line": 193, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 3, "top_nesting_level": 1 }, { "name": "write", "long_name": "write( self , message )", "filename": "testing.py", "nloc": 6, "complexity": 3, "token_count": 47, "parameters": [ "self", "message" ], "start_line": 194, "end_line": 199, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 6, "top_nesting_level": 1 }, { "name": "writeln", "long_name": "writeln( self , message )", "filename": "testing.py", "nloc": 2, "complexity": 1, "token_count": 15, "parameters": [ "self", "message" ], "start_line": 200, "end_line": 201, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 2, "top_nesting_level": 1 }, { "name": "_get_all_method_names", "long_name": "_get_all_method_names( cls )", "filename": "testing.py", "nloc": 8, "complexity": 5, "token_count": 56, "parameters": [ "cls" ], "start_line": 209, "end_line": 216, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 8, "top_nesting_level": 0 }, { "name": "__init__", "long_name": "__init__( self , package = '__main__' )", "filename": "testing.py", "nloc": 2, "complexity": 1, "token_count": 14, "parameters": [ "self", "package" ], "start_line": 240, "end_line": 241, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 2, "top_nesting_level": 1 }, { "name": "_module_str", "long_name": "_module_str( self , module )", "filename": "testing.py", "nloc": 5, "complexity": 2, "token_count": 43, "parameters": [ "self", "module" ], "start_line": 243, "end_line": 247, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 5, "top_nesting_level": 1 }, { "name": "_get_method_names", "long_name": "_get_method_names( self , clsobj , level )", "filename": "testing.py", "nloc": 22, "complexity": 11, "token_count": 142, "parameters": [ "self", "clsobj", "level" ], "start_line": 249, "end_line": 270, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 22, "top_nesting_level": 1 }, { "name": "_get_module_tests", "long_name": "_get_module_tests( self , module , level )", "filename": "testing.py", "nloc": 46, "complexity": 14, "token_count": 428, "parameters": [ "self", "module", "level" ], "start_line": 272, "end_line": 323, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 52, "top_nesting_level": 1 }, { "name": "_get_suite_list", "long_name": "_get_suite_list( self , test_module , level , module_name = '__main__' )", "filename": "testing.py", "nloc": 24, "complexity": 9, "token_count": 168, "parameters": [ "self", "test_module", "level", "module_name" ], "start_line": 325, "end_line": 349, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 25, "top_nesting_level": 1 }, { "name": "_touch_ppimported", "long_name": "_touch_ppimported( self , module )", "filename": "testing.py", "nloc": 11, "complexity": 7, "token_count": 98, "parameters": [ "self", "module" ], "start_line": 351, "end_line": 362, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 12, "top_nesting_level": 1 }, { "name": "test", "long_name": "test( self , level = 1 , verbosity = 1 )", "filename": "testing.py", "nloc": 19, "complexity": 6, "token_count": 166, "parameters": [ "self", "level", "verbosity" ], "start_line": 364, "end_line": 389, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 26, "top_nesting_level": 1 }, { "name": "run", "long_name": "run( self )", "filename": "testing.py", "nloc": 20, "complexity": 2, "token_count": 104, "parameters": [ "self" ], "start_line": 391, "end_line": 413, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 23, "top_nesting_level": 1 }, { "name": "remove_ignored_patterns", "long_name": "remove_ignored_patterns( files , pattern )", "filename": "testing.py", "nloc": 7, "complexity": 3, "token_count": 37, "parameters": [ "files", "pattern" ], "start_line": 417, "end_line": 423, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 7, "top_nesting_level": 0 }, { "name": "remove_ignored_files", "long_name": "remove_ignored_files( original , ignored_files , cur_dir )", "filename": "testing.py", "nloc": 12, "complexity": 3, "token_count": 93, "parameters": [ "original", "ignored_files", "cur_dir" ], "start_line": 425, "end_line": 444, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 20, "top_nesting_level": 0 }, { "name": "harvest_modules", "long_name": "harvest_modules( package , ignore = None )", "filename": "testing.py", "nloc": 21, "complexity": 4, "token_count": 134, "parameters": [ "package", "ignore" ], "start_line": 447, "end_line": 483, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 37, "top_nesting_level": 0 }, { "name": "harvest_packages", "long_name": "harvest_packages( package , ignore = None )", "filename": "testing.py", "nloc": 23, "complexity": 6, "token_count": 148, "parameters": [ "package", "ignore" ], "start_line": 486, "end_line": 520, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 35, "top_nesting_level": 0 }, { "name": "harvest_modules_and_packages", "long_name": "harvest_modules_and_packages( package , ignore = None )", "filename": "testing.py", "nloc": 3, "complexity": 1, "token_count": 27, "parameters": [ "package", "ignore" ], "start_line": 523, "end_line": 529, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 7, "top_nesting_level": 0 }, { "name": "harvest_test_suites", "long_name": "harvest_test_suites( package , ignore = None , level = 10 )", "filename": "testing.py", "nloc": 23, "complexity": 6, "token_count": 113, "parameters": [ "package", "ignore", "level" ], "start_line": 532, "end_line": 567, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 36, "top_nesting_level": 0 }, { "name": "module_test", "long_name": "module_test( mod_name , mod_file , level = 10 )", "filename": "testing.py", "nloc": 10, "complexity": 1, "token_count": 98, "parameters": [ "mod_name", "mod_file", "level" ], "start_line": 570, "end_line": 597, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 28, "top_nesting_level": 0 }, { "name": "module_test_suite", "long_name": "module_test_suite( mod_name , mod_file , level = 10 )", "filename": "testing.py", "nloc": 12, "complexity": 1, "token_count": 103, "parameters": [ "mod_name", "mod_file", "level" ], "start_line": 600, "end_line": 622, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 23, "top_nesting_level": 0 }, { "name": "assert_equal", "long_name": "assert_equal( actual , desired , err_msg = '' , verbose = 1 )", "filename": "testing.py", "nloc": 12, "complexity": 5, "token_count": 95, "parameters": [ "actual", "desired", "err_msg", "verbose" ], "start_line": 632, "end_line": 646, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 15, "top_nesting_level": 0 }, { "name": "assert_almost_equal", "long_name": "assert_almost_equal( actual , desired , decimal = 7 , err_msg = '' , verbose = 1 )", "filename": "testing.py", "nloc": 12, "complexity": 5, "token_count": 109, "parameters": [ "actual", "desired", "decimal", "err_msg", "verbose" ], "start_line": 649, "end_line": 663, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 15, "top_nesting_level": 0 }, { "name": "assert_approx_equal", "long_name": "assert_approx_equal( actual , desired , significant = 7 , err_msg = '' , verbose = 1 )", "filename": "testing.py", "nloc": 23, "complexity": 7, "token_count": 194, "parameters": [ "actual", "desired", "significant", "err_msg", "verbose" ], "start_line": 666, "end_line": 694, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 29, "top_nesting_level": 0 }, { "name": "assert_array_equal", "long_name": "assert_array_equal( x , y , err_msg = '' )", "filename": "testing.py", "nloc": 22, "complexity": 7, "token_count": 232, "parameters": [ "x", "y", "err_msg" ], "start_line": 698, "end_line": 719, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 22, "top_nesting_level": 0 }, { "name": "assert_array_almost_equal", "long_name": "assert_array_almost_equal( x , y , decimal = 6 , err_msg = '' )", "filename": "testing.py", "nloc": 26, "complexity": 6, "token_count": 251, "parameters": [ "x", "y", "decimal", "err_msg" ], "start_line": 722, "end_line": 747, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 26, "top_nesting_level": 0 }, { "name": "assert_array_less", "long_name": "assert_array_less( x , y , err_msg = '' )", "filename": "testing.py", "nloc": 20, "complexity": 5, "token_count": 189, "parameters": [ "x", "y", "err_msg" ], "start_line": 750, "end_line": 769, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 20, "top_nesting_level": 0 }, { "name": "rand", "long_name": "rand( * args )", "filename": "testing.py", "nloc": 7, "complexity": 2, "token_count": 45, "parameters": [ "args" ], "start_line": 772, "end_line": 781, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 10, "top_nesting_level": 0 }, { "name": "output_exception", "long_name": "output_exception( )", "filename": "testing.py", "nloc": 9, "complexity": 2, "token_count": 67, "parameters": [], "start_line": 783, "end_line": 793, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 11, "top_nesting_level": 0 } ], "methods_before": [ { "name": "set_package_path", "long_name": "set_package_path( level = 1 )", "filename": "testing.py", "nloc": 15, "complexity": 4, "token_count": 146, "parameters": [ "level" ], "start_line": 49, "end_line": 80, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 32, "top_nesting_level": 0 }, { "name": "set_local_path", "long_name": "set_local_path( reldir = '' , level = 1 )", "filename": "testing.py", "nloc": 11, "complexity": 3, "token_count": 97, "parameters": [ "reldir", "level" ], "start_line": 83, "end_line": 99, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 17, "top_nesting_level": 0 }, { "name": "restore_path", "long_name": "restore_path( )", "filename": "testing.py", "nloc": 4, "complexity": 2, "token_count": 25, "parameters": [], "start_line": 102, "end_line": 105, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 4, "top_nesting_level": 0 }, { "name": "jiffies", "long_name": "jiffies( _proc_pid_stat = '/proc/%s/stat' % ( os . getpid ( )", "filename": "testing.py", "nloc": 2, "complexity": 1, "token_count": 23, "parameters": [ "_proc_pid_stat" ], "start_line": 109, "end_line": 110, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 2, "top_nesting_level": 1 }, { "name": "memusage", "long_name": "memusage( _proc_pid_stat = '/proc/%s/stat' % ( os . getpid ( )", "filename": "testing.py", "nloc": 10, "complexity": 2, "token_count": 54, "parameters": [ "_proc_pid_stat" ], "start_line": 121, "end_line": 130, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 10, "top_nesting_level": 1 }, { "name": "jiffies", "long_name": "jiffies( _load_time = time . time ( )", "filename": "testing.py", "nloc": 4, "complexity": 1, "token_count": 27, "parameters": [ "_load_time" ], "start_line": 135, "end_line": 138, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 4, "top_nesting_level": 1 }, { "name": "memusage", "long_name": "memusage( )", "filename": "testing.py", "nloc": 2, "complexity": 1, "token_count": 6, "parameters": [], "start_line": 140, "end_line": 142, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 3, "top_nesting_level": 1 }, { "name": "measure", "long_name": "measure( self , code_str , times = 1 )", "filename": "testing.py", "nloc": 13, "complexity": 2, "token_count": 82, "parameters": [ "self", "code_str", "times" ], "start_line": 147, "end_line": 162, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 16, "top_nesting_level": 1 }, { "name": "__call__", "long_name": "__call__( self , result = None )", "filename": "testing.py", "nloc": 24, "complexity": 6, "token_count": 224, "parameters": [ "self", "result" ], "start_line": 164, "end_line": 188, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 25, "top_nesting_level": 1 }, { "name": "__init__", "long_name": "__init__( self , stream )", "filename": "testing.py", "nloc": 3, "complexity": 1, "token_count": 18, "parameters": [ "self", "stream" ], "start_line": 191, "end_line": 193, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 3, "top_nesting_level": 1 }, { "name": "write", "long_name": "write( self , message )", "filename": "testing.py", "nloc": 6, "complexity": 3, "token_count": 47, "parameters": [ "self", "message" ], "start_line": 194, "end_line": 199, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 6, "top_nesting_level": 1 }, { "name": "writeln", "long_name": "writeln( self , message )", "filename": "testing.py", "nloc": 2, "complexity": 1, "token_count": 15, "parameters": [ "self", "message" ], "start_line": 200, "end_line": 201, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 2, "top_nesting_level": 1 }, { "name": "_get_all_method_names", "long_name": "_get_all_method_names( cls )", "filename": "testing.py", "nloc": 8, "complexity": 5, "token_count": 56, "parameters": [ "cls" ], "start_line": 209, "end_line": 216, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 8, "top_nesting_level": 0 }, { "name": "__init__", "long_name": "__init__( self , package = '__main__' )", "filename": "testing.py", "nloc": 2, "complexity": 1, "token_count": 14, "parameters": [ "self", "package" ], "start_line": 240, "end_line": 241, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 2, "top_nesting_level": 1 }, { "name": "_module_str", "long_name": "_module_str( self , module )", "filename": "testing.py", "nloc": 5, "complexity": 2, "token_count": 43, "parameters": [ "self", "module" ], "start_line": 243, "end_line": 247, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 5, "top_nesting_level": 1 }, { "name": "_get_method_names", "long_name": "_get_method_names( self , clsobj , level )", "filename": "testing.py", "nloc": 22, "complexity": 11, "token_count": 142, "parameters": [ "self", "clsobj", "level" ], "start_line": 249, "end_line": 270, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 22, "top_nesting_level": 1 }, { "name": "_get_module_tests", "long_name": "_get_module_tests( self , module , level )", "filename": "testing.py", "nloc": 46, "complexity": 14, "token_count": 428, "parameters": [ "self", "module", "level" ], "start_line": 272, "end_line": 323, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 52, "top_nesting_level": 1 }, { "name": "_get_suite_list", "long_name": "_get_suite_list( self , test_module , level , module_name = '__main__' )", "filename": "testing.py", "nloc": 24, "complexity": 9, "token_count": 168, "parameters": [ "self", "test_module", "level", "module_name" ], "start_line": 325, "end_line": 349, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 25, "top_nesting_level": 1 }, { "name": "_touch_ppimported", "long_name": "_touch_ppimported( self , module )", "filename": "testing.py", "nloc": 11, "complexity": 7, "token_count": 98, "parameters": [ "self", "module" ], "start_line": 351, "end_line": 362, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 12, "top_nesting_level": 1 }, { "name": "test", "long_name": "test( self , level = 1 , verbosity = 1 )", "filename": "testing.py", "nloc": 19, "complexity": 6, "token_count": 166, "parameters": [ "self", "level", "verbosity" ], "start_line": 364, "end_line": 389, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 26, "top_nesting_level": 1 }, { "name": "run", "long_name": "run( self )", "filename": "testing.py", "nloc": 20, "complexity": 2, "token_count": 104, "parameters": [ "self" ], "start_line": 391, "end_line": 413, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 23, "top_nesting_level": 1 }, { "name": "remove_ignored_patterns", "long_name": "remove_ignored_patterns( files , pattern )", "filename": "testing.py", "nloc": 7, "complexity": 3, "token_count": 37, "parameters": [ "files", "pattern" ], "start_line": 417, "end_line": 423, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 7, "top_nesting_level": 0 }, { "name": "remove_ignored_files", "long_name": "remove_ignored_files( original , ignored_files , cur_dir )", "filename": "testing.py", "nloc": 12, "complexity": 3, "token_count": 93, "parameters": [ "original", "ignored_files", "cur_dir" ], "start_line": 425, "end_line": 444, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 20, "top_nesting_level": 0 }, { "name": "harvest_modules", "long_name": "harvest_modules( package , ignore = None )", "filename": "testing.py", "nloc": 21, "complexity": 4, "token_count": 134, "parameters": [ "package", "ignore" ], "start_line": 447, "end_line": 483, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 37, "top_nesting_level": 0 }, { "name": "harvest_packages", "long_name": "harvest_packages( package , ignore = None )", "filename": "testing.py", "nloc": 23, "complexity": 6, "token_count": 148, "parameters": [ "package", "ignore" ], "start_line": 486, "end_line": 520, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 35, "top_nesting_level": 0 }, { "name": "harvest_modules_and_packages", "long_name": "harvest_modules_and_packages( package , ignore = None )", "filename": "testing.py", "nloc": 3, "complexity": 1, "token_count": 27, "parameters": [ "package", "ignore" ], "start_line": 523, "end_line": 529, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 7, "top_nesting_level": 0 }, { "name": "harvest_test_suites", "long_name": "harvest_test_suites( package , ignore = None , level = 10 )", "filename": "testing.py", "nloc": 23, "complexity": 6, "token_count": 113, "parameters": [ "package", "ignore", "level" ], "start_line": 532, "end_line": 567, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 36, "top_nesting_level": 0 }, { "name": "module_test", "long_name": "module_test( mod_name , mod_file , level = 10 )", "filename": "testing.py", "nloc": 10, "complexity": 1, "token_count": 98, "parameters": [ "mod_name", "mod_file", "level" ], "start_line": 570, "end_line": 597, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 28, "top_nesting_level": 0 }, { "name": "module_test_suite", "long_name": "module_test_suite( mod_name , mod_file , level = 10 )", "filename": "testing.py", "nloc": 12, "complexity": 1, "token_count": 103, "parameters": [ "mod_name", "mod_file", "level" ], "start_line": 600, "end_line": 622, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 23, "top_nesting_level": 0 }, { "name": "assert_equal", "long_name": "assert_equal( actual , desired , err_msg = '' , verbose = 1 )", "filename": "testing.py", "nloc": 12, "complexity": 5, "token_count": 95, "parameters": [ "actual", "desired", "err_msg", "verbose" ], "start_line": 632, "end_line": 646, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 15, "top_nesting_level": 0 }, { "name": "assert_almost_equal", "long_name": "assert_almost_equal( actual , desired , decimal = 7 , err_msg = '' , verbose = 1 )", "filename": "testing.py", "nloc": 12, "complexity": 5, "token_count": 109, "parameters": [ "actual", "desired", "decimal", "err_msg", "verbose" ], "start_line": 649, "end_line": 663, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 15, "top_nesting_level": 0 }, { "name": "assert_approx_equal", "long_name": "assert_approx_equal( actual , desired , significant = 7 , err_msg = '' , verbose = 1 )", "filename": "testing.py", "nloc": 23, "complexity": 7, "token_count": 194, "parameters": [ "actual", "desired", "significant", "err_msg", "verbose" ], "start_line": 666, "end_line": 694, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 29, "top_nesting_level": 0 }, { "name": "assert_array_equal", "long_name": "assert_array_equal( x , y , err_msg = '' )", "filename": "testing.py", "nloc": 22, "complexity": 7, "token_count": 232, "parameters": [ "x", "y", "err_msg" ], "start_line": 698, "end_line": 719, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 22, "top_nesting_level": 0 }, { "name": "assert_array_almost_equal", "long_name": "assert_array_almost_equal( x , y , decimal = 6 , err_msg = '' )", "filename": "testing.py", "nloc": 26, "complexity": 6, "token_count": 251, "parameters": [ "x", "y", "decimal", "err_msg" ], "start_line": 722, "end_line": 747, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 26, "top_nesting_level": 0 }, { "name": "assert_array_less", "long_name": "assert_array_less( x , y , err_msg = '' )", "filename": "testing.py", "nloc": 20, "complexity": 5, "token_count": 189, "parameters": [ "x", "y", "err_msg" ], "start_line": 750, "end_line": 769, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 20, "top_nesting_level": 0 }, { "name": "rand", "long_name": "rand( * args )", "filename": "testing.py", "nloc": 7, "complexity": 2, "token_count": 45, "parameters": [ "args" ], "start_line": 772, "end_line": 781, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 10, "top_nesting_level": 0 }, { "name": "output_exception", "long_name": "output_exception( )", "filename": "testing.py", "nloc": 9, "complexity": 2, "token_count": 67, "parameters": [], "start_line": 783, "end_line": 793, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 11, "top_nesting_level": 0 } ], "changed_methods": [ { "name": "assert_almost_equal", "long_name": "assert_almost_equal( actual , desired , decimal = 7 , err_msg = '' , verbose = 1 )", "filename": "testing.py", "nloc": 12, "complexity": 5, "token_count": 109, "parameters": [ "actual", "desired", "decimal", "err_msg", "verbose" ], "start_line": 649, "end_line": 663, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 15, "top_nesting_level": 0 } ], "nloc": 595, "complexity": 148, "token_count": 4248, "diff_parsed": { "added": [ " assert all(around(abs(desired - actual),decimal) == 0), msg" ], "deleted": [ " assert all(round(abs(desired - actual),decimal) == 0), msg" ] } } ] }, { "hash": "6f8a23d5a780568bc05ff238c724409214d2ba52", "msg": "Reverted switch from alltrue() to all() after Pearu pointed out that\nthe arrays in question were already raveled so the two calls are\nequivalent. Added code so that assert_equal() and assert_almost_equal()\nwill defer to assert_array_equal(), etc. for array parameters.", "author": { "name": "jmiller", "email": "jmiller@localhost" }, "committer": { "name": "jmiller", "email": "jmiller@localhost" }, "author_date": "2004-12-17T18:20:28+00:00", "author_timezone": 0, "committer_date": "2004-12-17T18:20:28+00:00", "committer_timezone": 0, "branches": [ "main" ], "in_main_branch": true, "merge": false, "parents": [ "bc05123388bec5c8b554eee92ae99d01b7cc64ec" ], "project_name": "repo_copy", "project_path": "/tmp/tmpqop781_j/repo_copy", "deletions": 11, "insertions": 15, "lines": 26, "files": 1, "dmm_unit_size": 1.0, "dmm_unit_complexity": 0.0, "dmm_unit_interfacing": 0.0, "modified_files": [ { "old_path": "scipy_test/testing.py", "new_path": "scipy_test/testing.py", "filename": "testing.py", "extension": "py", "change_type": "MODIFY", "diff": "@@ -38,8 +38,8 @@\n # These are used by Numeric tests.\n # If Numeric and scipy_base are not available, then some of the\n # functions below will not be available.\n- from scipy_base.numerix import all, equal, shape, ravel, around, zeros, Float64, asarray\n- from scipy_base.numerix import less_equal, array2string, less\n+ from scipy_base.numerix import alltrue, equal, shape, ravel, around, zeros, Float64, asarray\n+ from scipy_base.numerix import less_equal, array2string, less, ArrayType\n except ImportError:\n pass\n \n@@ -633,6 +633,8 @@ def assert_equal(actual,desired,err_msg='',verbose=1):\n \"\"\" Raise an assertion if two items are not\n equal. I think this should be part of unittest.py\n \"\"\"\n+ if isinstance(actual, ArrayType):\n+ return assert_array_equal(actual, desired, err_msg)\n msg = '\\nItems are not equal:\\n' + err_msg\n try:\n if ( verbose and len(repr(desired)) < 100 and len(repr(actual)) ):\n@@ -643,13 +645,15 @@ def assert_equal(actual,desired,err_msg='',verbose=1):\n msg = msg \\\n + 'DESIRED: ' + repr(desired) \\\n + '\\nACTUAL: ' + repr(actual)\n- assert all(desired == actual), msg\n+ assert desired == actual, msg\n \n __all__.append('assert_almost_equal')\n def assert_almost_equal(actual,desired,decimal=7,err_msg='',verbose=1):\n \"\"\" Raise an assertion if two items are not\n equal. I think this should be part of unittest.py\n \"\"\"\n+ if isinstance(actual, ArrayType):\n+ return assert_array_almost_equal(actual, desired, decimal, err_msg)\n msg = '\\nItems are not equal:\\n' + err_msg\n try:\n if ( verbose and len(repr(desired)) < 100 and len(repr(actual)) ):\n@@ -660,7 +664,7 @@ def assert_almost_equal(actual,desired,decimal=7,err_msg='',verbose=1):\n msg = msg \\\n + 'DESIRED: ' + repr(desired) \\\n + '\\nACTUAL: ' + repr(actual)\n- assert all(around(abs(desired - actual),decimal) == 0), msg\n+ assert round(abs(desired - actual),decimal) == 0, msg\n \n __all__.append('assert_approx_equal')\n def assert_approx_equal(actual,desired,significant=7,err_msg='',verbose=1):\n@@ -691,7 +695,7 @@ def assert_approx_equal(actual,desired,significant=7,err_msg='',verbose=1):\n msg = msg \\\n + 'DESIRED: ' + repr(desired) \\\n + '\\nACTUAL: ' + repr(actual)\n- assert all(math.fabs(sc_desired - sc_actual) < pow(10.,-1*significant)), msg\n+ assert math.fabs(sc_desired - sc_actual) < pow(10.,-1*significant), msg\n \n \n __all__.append('assert_array_equal')\n@@ -701,11 +705,11 @@ def assert_array_equal(x,y,err_msg=''):\n try:\n assert 0 in [len(shape(x)),len(shape(y))] \\\n or (len(shape(x))==len(shape(y)) and \\\n- all(equal(shape(x),shape(y)))),\\\n+ alltrue(equal(shape(x),shape(y)))),\\\n msg + ' (shapes %s, %s mismatch):\\n\\t' \\\n % (shape(x),shape(y)) + err_msg\n reduced = ravel(equal(x,y))\n- cond = all(reduced)\n+ cond = alltrue(reduced)\n if not cond:\n s1 = array2string(x,precision=16)\n s2 = array2string(y,precision=16)\n@@ -724,13 +728,13 @@ def assert_array_almost_equal(x,y,decimal=6,err_msg=''):\n y = asarray(y)\n msg = '\\nArrays are not almost equal'\n try:\n- cond = all(equal(shape(x),shape(y)))\n+ cond = alltrue(equal(shape(x),shape(y)))\n if not cond:\n msg = msg + ' (shapes mismatch):\\n\\t'\\\n 'Shape of array 1: %s\\n\\tShape of array 2: %s' % (shape(x),shape(y))\n assert cond, msg + '\\n\\t' + err_msg\n reduced = ravel(equal(less_equal(around(abs(x-y),decimal),10.0**(-decimal)),1))\n- cond = all(reduced)\n+ cond = alltrue(reduced)\n if not cond:\n s1 = array2string(x,precision=decimal+1)\n s2 = array2string(y,precision=decimal+1)\n@@ -751,10 +755,10 @@ def assert_array_less(x,y,err_msg=''):\n x,y = asarray(x), asarray(y)\n msg = '\\nArrays are not less-ordered'\n try:\n- assert all(equal(shape(x),shape(y))),\\\n+ assert alltrue(equal(shape(x),shape(y))),\\\n msg + ' (shapes mismatch):\\n\\t' + err_msg\n reduced = ravel(less(x,y))\n- cond = all(reduced)\n+ cond = alltrue(reduced)\n if not cond:\n s1 = array2string(x,precision=16)\n s2 = array2string(y,precision=16)\n", "added_lines": 15, "deleted_lines": 11, "source_code": "\"\"\"\nUnit-testing\n------------\n\n ScipyTest -- Scipy tests site manager\n ScipyTestCase -- unittest.TestCase with measure method\n IgnoreException -- raise when checking disabled feature ('ignoring' is displayed)\n set_package_path -- prepend package build directory to path\n set_local_path -- prepend local directory (to tests files) to path\n restore_path -- restore path after set_package_path\n\nTiming tools\n------------\n\n jiffies -- return 1/100ths of a second that the current process has used\n memusage -- virtual memory size in bytes of the running python [linux]\n\nUtility functions\n-----------------\n\n assert_equal -- assert equality\n assert_almost_equal -- assert equality with decimal tolerance\n assert_approx_equal -- assert equality with significant digits tolerance\n assert_array_equal -- assert arrays equality\n assert_array_almost_equal -- assert arrays equality with decimal tolerance\n assert_array_less -- assert arrays less-ordering\n rand -- array of random numbers from given shape\n\n\"\"\"\n\n__all__ = []\n\nimport os,sys,time,glob,string,traceback,unittest\nimport types\nimport imp\n\ntry:\n # These are used by Numeric tests.\n # If Numeric and scipy_base are not available, then some of the\n # functions below will not be available.\n from scipy_base.numerix import alltrue, equal, shape, ravel, around, zeros, Float64, asarray\n from scipy_base.numerix import less_equal, array2string, less, ArrayType\nexcept ImportError:\n pass\n\nDEBUG = 0\n\n__all__.append('set_package_path')\ndef set_package_path(level=1):\n \"\"\" Prepend package directory to sys.path.\n\n set_package_path should be called from a test_file.py that\n satisfies the following tree structure:\n\n //test_file.py\n\n Then the first existing path name from the following list\n\n /build/lib.-\n /..\n\n is prepended to sys.path.\n The caller is responsible for removing this path by using\n\n restore_path()\n \"\"\"\n from distutils.util import get_platform\n from scipy_distutils.misc_util import get_frame\n f = get_frame(level)\n if f.f_locals['__name__']=='__main__':\n testfile = sys.argv[0]\n else:\n testfile = f.f_locals['__file__']\n d = os.path.dirname(os.path.dirname(os.path.abspath(testfile)))\n d1 = os.path.join(d,'build','lib.%s-%s'%(get_platform(),sys.version[:3]))\n if not os.path.isdir(d1):\n d1 = os.path.dirname(d)\n if DEBUG:\n print 'Inserting %r to sys.path' % (d1)\n sys.path.insert(0,d1)\n\n__all__.append('set_local_path')\ndef set_local_path(reldir='', level=1):\n \"\"\" Prepend local directory to sys.path.\n\n The caller is responsible for removing this path by using\n\n restore_path()\n \"\"\"\n from scipy_distutils.misc_util import get_frame\n f = get_frame(level)\n if f.f_locals['__name__']=='__main__':\n testfile = sys.argv[0]\n else:\n testfile = f.f_locals['__file__']\n local_path = os.path.join(os.path.dirname(os.path.abspath(testfile)),reldir)\n if DEBUG:\n print 'Inserting %r to sys.path' % (local_path)\n sys.path.insert(0,local_path)\n\n__all__.append('restore_path')\ndef restore_path():\n if DEBUG:\n print 'Removing %r from sys.path' % (sys.path[0])\n del sys.path[0]\n\n__all__.extend(['jiffies','memusage'])\nif sys.platform[:5]=='linux':\n def jiffies(_proc_pid_stat = '/proc/%s/stat'%(os.getpid()),\n _load_time=time.time()):\n \"\"\" Return number of jiffies (1/100ths of a second) that this\n process has been scheduled in user mode. See man 5 proc. \"\"\"\n try:\n f=open(_proc_pid_stat,'r')\n l = f.readline().split(' ')\n f.close()\n return int(l[13])\n except:\n return int(100*(time.time()-_load_time))\n\n def memusage(_proc_pid_stat = '/proc/%s/stat'%(os.getpid())):\n \"\"\" Return virtual memory size in bytes of the running python.\n \"\"\"\n try:\n f=open(_proc_pid_stat,'r')\n l = f.readline().split(' ')\n f.close()\n return int(l[22])\n except:\n return\nelse:\n # os.getpid is not in all platforms available.\n # Using time is safe but inaccurate, especially when process\n # was suspended or sleeping.\n def jiffies(_load_time=time.time()):\n \"\"\" Return number of jiffies (1/100ths of a second) that this\n process has been scheduled in user mode. [Emulation with time.time]. \"\"\"\n return int(100*(time.time()-_load_time))\n\n def memusage():\n \"\"\" Return memory usage of running python. [Not implemented]\"\"\"\n return\n\n__all__.append('ScipyTestCase')\nclass ScipyTestCase (unittest.TestCase):\n\n def measure(self,code_str,times=1):\n \"\"\" Return elapsed time for executing code_str in the\n namespace of the caller for given times.\n \"\"\"\n frame = sys._getframe(1)\n locs,globs = frame.f_locals,frame.f_globals\n code = compile(code_str,\n 'ScipyTestCase runner for '+self.__class__.__name__,\n 'exec')\n i = 0\n elapsed = jiffies()\n while i>> ScipyTest().test(level=1,verbosity=2)\n\n is package name or its module object.\n\n Package is supposed to contain a directory tests/\n with test_*.py files where * refers to the names of submodules.\n\n test_*.py files are supposed to define a classes, derived\n from ScipyTestCase or unittest.TestCase, with methods having\n names starting with test or bench or check.\n\n And that is it! No need to implement test or test_suite functions\n in each .py file.\n\n Also old styled test_suite(level=1) hooks are supported but\n soon to be removed.\n \"\"\"\n def __init__(self, package='__main__'):\n self.package = package\n\n def _module_str(self, module):\n filename = module.__file__[-30:]\n if filename!=module.__file__:\n filename = '...'+filename\n return '' % (`module.__name__`, `filename`)\n\n def _get_method_names(self,clsobj,level):\n names = []\n for mthname in _get_all_method_names(clsobj):\n if mthname[:5] not in ['bench','check'] \\\n and mthname[:4] not in ['test']:\n continue\n mth = getattr(clsobj, mthname)\n if type(mth) is not types.MethodType:\n continue\n d = mth.im_func.func_defaults\n if d is not None:\n mthlevel = d[0]\n else:\n mthlevel = 1\n if level>=mthlevel:\n if mthname not in names:\n names.append(mthname)\n for base in clsobj.__bases__:\n for n in self._get_method_names(base,level):\n if n not in names:\n names.append(n) \n return names\n\n def _get_module_tests(self,module,level):\n mstr = self._module_str\n d,f = os.path.split(module.__file__)\n\n short_module_name = os.path.splitext(os.path.basename(f))[0]\n if short_module_name=='__init__':\n short_module_name = module.__name__.split('.')[-1]\n\n test_dir = os.path.join(d,'tests')\n test_file = os.path.join(test_dir,'test_'+short_module_name+'.py')\n\n local_test_dir = os.path.join(os.getcwd(),'tests')\n local_test_file = os.path.join(local_test_dir,\n 'test_'+short_module_name+'.py')\n if os.path.basename(os.path.dirname(local_test_dir)) \\\n == os.path.basename(os.path.dirname(test_dir)) \\\n and os.path.isfile(local_test_file):\n test_file = local_test_file\n\n if not os.path.isfile(test_file):\n if short_module_name[:5]=='info_' \\\n and short_module_name[5:]==module.__name__.split('.')[-2]:\n return []\n if short_module_name in ['__cvs_version__','__svn_version__']:\n return []\n if short_module_name[-8:]=='_version' \\\n and short_module_name[:-8]==module.__name__.split('.')[-2]:\n return []\n print ' !! No test file %r found for %s' \\\n % (os.path.basename(test_file), mstr(module))\n return []\n\n try:\n if sys.version[:3]=='2.1':\n # Workaround for Python 2.1 .pyc file generator bug\n import random\n pref = '-nopyc'+`random.randint(1,100)`\n else:\n pref = ''\n f = open(test_file,'r')\n test_module = imp.load_module(\\\n module.__name__+'.test_'+short_module_name+pref,\n f, test_file+pref,('.py', 'r', 1))\n f.close()\n if sys.version[:3]=='2.1' and os.path.isfile(test_file+pref+'c'):\n os.remove(test_file+pref+'c')\n except:\n print ' !! FAILURE importing tests for ', mstr(module)\n print ' ',\n output_exception()\n return []\n return self._get_suite_list(test_module, level, module.__name__)\n\n def _get_suite_list(self, test_module, level, module_name='__main__'):\n mstr = self._module_str\n if hasattr(test_module,'test_suite'):\n # Using old styled test suite\n try:\n total_suite = test_module.test_suite(level)\n return total_suite._tests\n except:\n print ' !! FAILURE building tests for ', mstr(test_module)\n print ' ',\n output_exception()\n return []\n suite_list = []\n for name in dir(test_module):\n obj = getattr(test_module, name)\n if type(obj) is not type(unittest.TestCase) \\\n or not issubclass(obj, unittest.TestCase) \\\n or obj.__name__[:4] != 'test':\n continue\n for mthname in self._get_method_names(obj,level):\n suite = obj(mthname)\n if getattr(suite,'isrunnable',lambda mthname:1)(mthname):\n suite_list.append(suite)\n print ' Found',len(suite_list),'tests for',module_name\n return suite_list\n\n def _touch_ppimported(self, module):\n from scipy_base.ppimport import _ModuleLoader\n if os.path.isdir(os.path.join(os.path.dirname(module.__file__),'tests')):\n # only touching those modules that have tests/ directory\n try: module._pliuh_plauh\n except AttributeError: pass\n for name in dir(module):\n obj = getattr(module,name)\n if isinstance(obj,_ModuleLoader) \\\n and not hasattr(obj,'_ppimport_module') \\\n and not hasattr(obj,'_ppimport_exc_info'):\n self._touch_ppimported(obj)\n\n def test(self,level=1,verbosity=1):\n \"\"\" Run Scipy module test suite with level and verbosity.\n \"\"\"\n if type(self.package) is type(''):\n exec 'import %s as this_package' % (self.package)\n else:\n this_package = self.package\n\n self._touch_ppimported(this_package)\n\n package_name = this_package.__name__\n\n suites = []\n for name, module in sys.modules.items():\n if package_name != name[:len(package_name)] \\\n or module is None \\\n or os.path.basename(os.path.dirname(module.__file__))=='tests':\n continue\n suites.extend(self._get_module_tests(module, level))\n\n suites.extend(self._get_suite_list(sys.modules[package_name], level))\n\n all_tests = unittest.TestSuite(suites)\n runner = unittest.TextTestRunner(verbosity=verbosity)\n runner.run(all_tests)\n return runner\n\n def run(self):\n \"\"\" Run Scipy module test suite with level and verbosity\n taken from sys.argv. Requires optparse module.\n \"\"\"\n try:\n from optparse import OptionParser\n except ImportError:\n print 'Failed to import optparse module, ignoring.'\n return self.test()\n usage = r'usage: %prog [-v ] [-l ]'\n parser = OptionParser(usage)\n parser.add_option(\"-v\", \"--verbosity\",\n action=\"store\",\n dest=\"verbosity\",\n default=1,\n type='int')\n parser.add_option(\"-l\", \"--level\",\n action=\"store\",\n dest=\"level\",\n default=1,\n type='int')\n (options, args) = parser.parse_args()\n self.test(options.level,options.verbosity)\n\n#------------\n \ndef remove_ignored_patterns(files,pattern):\n from fnmatch import fnmatch\n good_files = []\n for file in files:\n if not fnmatch(file,pattern):\n good_files.append(file)\n return good_files\n\ndef remove_ignored_files(original,ignored_files,cur_dir):\n \"\"\" This is actually expanded to do pattern matching.\n\n \"\"\"\n if not ignored_files: ignored_files = []\n ignored_modules = map(lambda x: x+'.py',ignored_files)\n ignored_packages = ignored_files[:]\n # always ignore setup.py and __init__.py files\n ignored_files = ['setup.py','setup_*.py','__init__.py']\n ignored_files += ignored_modules + ignored_packages\n ignored_files = map(lambda x,cur_dir=cur_dir: os.path.join(cur_dir,x),\n ignored_files)\n #print 'ignored:', ignored_files\n #good_files = filter(lambda x,ignored = ignored_files: x not in ignored,\n # original)\n good_files = original\n for pattern in ignored_files:\n good_files = remove_ignored_patterns(good_files,pattern)\n\n return good_files\n\n__all__.append('harvest_modules')\ndef harvest_modules(package,ignore=None):\n \"\"\"* Retreive a list of all modules that live within a package.\n\n Only retreive files that are immediate children of the\n package -- do not recurse through child packages or\n directories. The returned list contains actual modules, not\n just their names.\n *\"\"\"\n d,f = os.path.split(package.__file__)\n\n # go through the directory and import every py file there.\n common_dir = os.path.join(d,'*.py')\n py_files = glob.glob(common_dir)\n #py_files.remove(os.path.join(d,'__init__.py'))\n #py_files.remove(os.path.join(d,'setup.py'))\n\n py_files = remove_ignored_files(py_files,ignore,d)\n #print 'py_files:', py_files\n try:\n prefix = package.__name__\n except:\n prefix = ''\n\n all_modules = []\n for file in py_files:\n d,f = os.path.split(file)\n base,ext = os.path.splitext(f)\n mod = prefix + '.' + base\n #print 'module: import ' + mod\n try:\n exec ('import ' + mod)\n all_modules.append(eval(mod))\n except:\n print 'FAILURE to import ' + mod\n output_exception()\n\n return all_modules\n\n__all__.append('harvest_packages')\ndef harvest_packages(package,ignore = None):\n \"\"\" Retreive a list of all sub-packages that live within a package.\n\n Only retreive packages that are immediate children of this\n package -- do not recurse through child packages or\n directories. The returned list contains actual package objects, not\n just their names.\n \"\"\"\n join = os.path.join\n\n d,f = os.path.split(package.__file__)\n\n common_dir = os.path.abspath(d)\n all_files = os.listdir(d)\n\n all_files = remove_ignored_files(all_files,ignore,'')\n #print 'all_files:', all_files\n try:\n prefix = package.__name__\n except:\n prefix = ''\n all_packages = []\n for directory in all_files:\n path = join(common_dir,directory)\n if os.path.isdir(path) and \\\n os.path.exists(join(path,'__init__.py')):\n sub_package = prefix + '.' + directory\n #print 'sub-package import ' + sub_package\n try:\n exec ('import ' + sub_package)\n all_packages.append(eval(sub_package))\n except:\n print 'FAILURE to import ' + sub_package\n output_exception()\n return all_packages\n\n__all__.append('harvest_modules_and_packages')\ndef harvest_modules_and_packages(package,ignore=None):\n \"\"\" Retreive list of all packages and modules that live within a package.\n\n See harvest_packages() and harvest_modules()\n \"\"\"\n all = harvest_modules(package,ignore) + harvest_packages(package,ignore)\n return all\n\n__all__.append('harvest_test_suites')\ndef harvest_test_suites(package,ignore = None,level=10):\n \"\"\"\n package -- the module to test. This is an actual module object\n (not a string)\n ignore -- a list of module names to omit from the tests\n level -- a value between 1 and 10. 1 will run the minimum number\n of tests. This is a fast \"smoke test\". Tests that take\n longer to run should have higher numbers ranging up to 10.\n \"\"\"\n suites=[]\n test_modules = harvest_modules_and_packages(package,ignore)\n #for i in test_modules:\n # print i.__name__\n for module in test_modules:\n if hasattr(module,'test_suite'):\n try:\n suite = module.test_suite(level=level)\n if suite:\n suites.append(suite)\n else:\n print \" !! FAILURE without error - shouldn't happen\",\n print module.__name__\n except:\n print ' !! FAILURE building test for ', module.__name__\n print ' ',\n output_exception()\n else:\n try:\n print 'No test suite found for ', module.__name__\n except AttributeError:\n # __version__.py getting replaced by a string throws a kink\n # in checking for modules, so we think is a module has\n # actually been overwritten\n print 'No test suite found for ', str(module)\n total_suite = unittest.TestSuite(suites)\n return total_suite\n\n__all__.append('module_test')\ndef module_test(mod_name,mod_file,level=10):\n \"\"\"*\n\n *\"\"\"\n #print 'testing', mod_name\n d,f = os.path.split(mod_file)\n\n # insert the tests directory to the python path\n test_dir = os.path.join(d,'tests')\n sys.path.insert(0,test_dir)\n\n # call the \"test_xxx.test()\" function for the appropriate\n # module.\n\n # This should deal with package naming issues correctly\n short_mod_name = string.split(mod_name,'.')[-1]\n test_module = 'test_' + short_mod_name\n test_string = 'import %s;reload(%s);%s.test(%d)' % \\\n ((test_module,)*3 + (level,))\n\n # This would be better cause it forces a reload of the orginal\n # module. It doesn't behave with packages however.\n #test_string = 'reload(%s);import %s;reload(%s);%s.test(%d)' % \\\n # ((mod_name,) + (test_module,)*3)\n exec(test_string)\n\n # remove test directory from python path.\n sys.path = sys.path[1:]\n\n__all__.append('module_test_suite')\ndef module_test_suite(mod_name,mod_file,level=10):\n #try:\n print ' creating test suite for:', mod_name\n d,f = os.path.split(mod_file)\n\n # insert the tests directory to the python path\n test_dir = os.path.join(d,'tests')\n sys.path.insert(0,test_dir)\n\n # call the \"test_xxx.test()\" function for the appropriate\n # module.\n\n # This should deal with package naming issues correctly\n short_mod_name = string.split(mod_name,'.')[-1]\n test_module = 'test_' + short_mod_name\n test_string = 'import %s;reload(%s);suite = %s.test_suite(%d)' % \\\n ((test_module,)*3+(level,))\n #print test_string\n exec(test_string)\n\n # remove test directory from python path.\n sys.path = sys.path[1:]\n return suite\n #except:\n # print ' !! FAILURE loading test suite from', test_module, ':'\n # print ' ',\n # output_exception()\n\n\n# Utility function to facilitate testing.\n\n__all__.append('assert_equal')\ndef assert_equal(actual,desired,err_msg='',verbose=1):\n \"\"\" Raise an assertion if two items are not\n equal. I think this should be part of unittest.py\n \"\"\"\n if isinstance(actual, ArrayType):\n return assert_array_equal(actual, desired, err_msg)\n msg = '\\nItems are not equal:\\n' + err_msg\n try:\n if ( verbose and len(repr(desired)) < 100 and len(repr(actual)) ):\n msg = msg \\\n + 'DESIRED: ' + repr(desired) \\\n + '\\nACTUAL: ' + repr(actual)\n except:\n msg = msg \\\n + 'DESIRED: ' + repr(desired) \\\n + '\\nACTUAL: ' + repr(actual)\n assert desired == actual, msg\n\n__all__.append('assert_almost_equal')\ndef assert_almost_equal(actual,desired,decimal=7,err_msg='',verbose=1):\n \"\"\" Raise an assertion if two items are not\n equal. I think this should be part of unittest.py\n \"\"\"\n if isinstance(actual, ArrayType):\n return assert_array_almost_equal(actual, desired, decimal, err_msg)\n msg = '\\nItems are not equal:\\n' + err_msg\n try:\n if ( verbose and len(repr(desired)) < 100 and len(repr(actual)) ):\n msg = msg \\\n + 'DESIRED: ' + repr(desired) \\\n + '\\nACTUAL: ' + repr(actual)\n except:\n msg = msg \\\n + 'DESIRED: ' + repr(desired) \\\n + '\\nACTUAL: ' + repr(actual)\n assert round(abs(desired - actual),decimal) == 0, msg\n\n__all__.append('assert_approx_equal')\ndef assert_approx_equal(actual,desired,significant=7,err_msg='',verbose=1):\n \"\"\" Raise an assertion if two items are not\n equal. I think this should be part of unittest.py\n Approximately equal is defined as the number of significant digits\n correct\n \"\"\"\n msg = '\\nItems are not equal to %d significant digits:\\n' % significant\n msg += err_msg\n actual, desired = map(float, (actual, desired))\n # Normalized the numbers to be in range (-10.0,10.0)\n scale = pow(10,math.floor(math.log10(0.5*(abs(desired)+abs(actual)))))\n try:\n sc_desired = desired/scale\n except ZeroDivisionError:\n sc_desired = 0.0\n try:\n sc_actual = actual/scale\n except ZeroDivisionError:\n sc_actual = 0.0\n try:\n if ( verbose and len(repr(desired)) < 100 and len(repr(actual)) ):\n msg = msg \\\n + 'DESIRED: ' + repr(desired) \\\n + '\\nACTUAL: ' + repr(actual)\n except:\n msg = msg \\\n + 'DESIRED: ' + repr(desired) \\\n + '\\nACTUAL: ' + repr(actual)\n assert math.fabs(sc_desired - sc_actual) < pow(10.,-1*significant), msg\n\n\n__all__.append('assert_array_equal')\ndef assert_array_equal(x,y,err_msg=''):\n x,y = asarray(x), asarray(y)\n msg = '\\nArrays are not equal'\n try:\n assert 0 in [len(shape(x)),len(shape(y))] \\\n or (len(shape(x))==len(shape(y)) and \\\n alltrue(equal(shape(x),shape(y)))),\\\n msg + ' (shapes %s, %s mismatch):\\n\\t' \\\n % (shape(x),shape(y)) + err_msg\n reduced = ravel(equal(x,y))\n cond = alltrue(reduced)\n if not cond:\n s1 = array2string(x,precision=16)\n s2 = array2string(y,precision=16)\n if len(s1)>120: s1 = s1[:120] + '...'\n if len(s2)>120: s2 = s2[:120] + '...'\n match = 100-100.0*reduced.tolist().count(1)/len(reduced)\n msg = msg + ' (mismatch %s%%):\\n\\tArray 1: %s\\n\\tArray 2: %s' % (match,s1,s2)\n assert cond,\\\n msg + '\\n\\t' + err_msg\n except ValueError:\n raise ValueError, msg\n\n__all__.append('assert_array_almost_equal')\ndef assert_array_almost_equal(x,y,decimal=6,err_msg=''):\n x = asarray(x)\n y = asarray(y)\n msg = '\\nArrays are not almost equal'\n try:\n cond = alltrue(equal(shape(x),shape(y)))\n if not cond:\n msg = msg + ' (shapes mismatch):\\n\\t'\\\n 'Shape of array 1: %s\\n\\tShape of array 2: %s' % (shape(x),shape(y))\n assert cond, msg + '\\n\\t' + err_msg\n reduced = ravel(equal(less_equal(around(abs(x-y),decimal),10.0**(-decimal)),1))\n cond = alltrue(reduced)\n if not cond:\n s1 = array2string(x,precision=decimal+1)\n s2 = array2string(y,precision=decimal+1)\n if len(s1)>120: s1 = s1[:120] + '...'\n if len(s2)>120: s2 = s2[:120] + '...'\n match = 100-100.0*reduced.tolist().count(1)/len(reduced)\n msg = msg + ' (mismatch %s%%):\\n\\tArray 1: %s\\n\\tArray 2: %s' % (match,s1,s2)\n assert cond,\\\n msg + '\\n\\t' + err_msg\n except ValueError:\n print sys.exc_value\n print shape(x),shape(y)\n print x, y\n raise ValueError, 'arrays are not almost equal'\n\n__all__.append('assert_array_less')\ndef assert_array_less(x,y,err_msg=''):\n x,y = asarray(x), asarray(y)\n msg = '\\nArrays are not less-ordered'\n try:\n assert alltrue(equal(shape(x),shape(y))),\\\n msg + ' (shapes mismatch):\\n\\t' + err_msg\n reduced = ravel(less(x,y))\n cond = alltrue(reduced)\n if not cond:\n s1 = array2string(x,precision=16)\n s2 = array2string(y,precision=16)\n if len(s1)>120: s1 = s1[:120] + '...'\n if len(s2)>120: s2 = s2[:120] + '...'\n match = 100-100.0*reduced.tolist().count(1)/len(reduced)\n msg = msg + ' (mismatch %s%%):\\n\\tArray 1: %s\\n\\tArray 2: %s' % (match,s1,s2)\n assert cond,\\\n msg + '\\n\\t' + err_msg\n except ValueError:\n print shape(x),shape(y)\n raise ValueError, 'arrays are not less-ordered'\n\n__all__.append('rand')\ndef rand(*args):\n \"\"\" Returns an array of random numbers with the given shape.\n used for testing\n \"\"\"\n import random\n results = zeros(args,Float64)\n f = results.flat\n for i in range(len(f)):\n f[i] = random.random()\n return results\n\ndef output_exception():\n try:\n type, value, tb = sys.exc_info()\n info = traceback.extract_tb(tb)\n #this is more verbose\n #traceback.print_exc()\n filename, lineno, function, text = info[-1] # last line only\n print \"%s:%d: %s: %s (in %s)\" %\\\n (filename, lineno, type.__name__, str(value), function)\n finally:\n type = value = tb = None # clean up\n\ntry:\n from scipy_base.numerix import fastumath as math\nexcept ImportError,msg:\n print msg\n import math\n", "source_code_before": "\"\"\"\nUnit-testing\n------------\n\n ScipyTest -- Scipy tests site manager\n ScipyTestCase -- unittest.TestCase with measure method\n IgnoreException -- raise when checking disabled feature ('ignoring' is displayed)\n set_package_path -- prepend package build directory to path\n set_local_path -- prepend local directory (to tests files) to path\n restore_path -- restore path after set_package_path\n\nTiming tools\n------------\n\n jiffies -- return 1/100ths of a second that the current process has used\n memusage -- virtual memory size in bytes of the running python [linux]\n\nUtility functions\n-----------------\n\n assert_equal -- assert equality\n assert_almost_equal -- assert equality with decimal tolerance\n assert_approx_equal -- assert equality with significant digits tolerance\n assert_array_equal -- assert arrays equality\n assert_array_almost_equal -- assert arrays equality with decimal tolerance\n assert_array_less -- assert arrays less-ordering\n rand -- array of random numbers from given shape\n\n\"\"\"\n\n__all__ = []\n\nimport os,sys,time,glob,string,traceback,unittest\nimport types\nimport imp\n\ntry:\n # These are used by Numeric tests.\n # If Numeric and scipy_base are not available, then some of the\n # functions below will not be available.\n from scipy_base.numerix import all, equal, shape, ravel, around, zeros, Float64, asarray\n from scipy_base.numerix import less_equal, array2string, less\nexcept ImportError:\n pass\n\nDEBUG = 0\n\n__all__.append('set_package_path')\ndef set_package_path(level=1):\n \"\"\" Prepend package directory to sys.path.\n\n set_package_path should be called from a test_file.py that\n satisfies the following tree structure:\n\n //test_file.py\n\n Then the first existing path name from the following list\n\n /build/lib.-\n /..\n\n is prepended to sys.path.\n The caller is responsible for removing this path by using\n\n restore_path()\n \"\"\"\n from distutils.util import get_platform\n from scipy_distutils.misc_util import get_frame\n f = get_frame(level)\n if f.f_locals['__name__']=='__main__':\n testfile = sys.argv[0]\n else:\n testfile = f.f_locals['__file__']\n d = os.path.dirname(os.path.dirname(os.path.abspath(testfile)))\n d1 = os.path.join(d,'build','lib.%s-%s'%(get_platform(),sys.version[:3]))\n if not os.path.isdir(d1):\n d1 = os.path.dirname(d)\n if DEBUG:\n print 'Inserting %r to sys.path' % (d1)\n sys.path.insert(0,d1)\n\n__all__.append('set_local_path')\ndef set_local_path(reldir='', level=1):\n \"\"\" Prepend local directory to sys.path.\n\n The caller is responsible for removing this path by using\n\n restore_path()\n \"\"\"\n from scipy_distutils.misc_util import get_frame\n f = get_frame(level)\n if f.f_locals['__name__']=='__main__':\n testfile = sys.argv[0]\n else:\n testfile = f.f_locals['__file__']\n local_path = os.path.join(os.path.dirname(os.path.abspath(testfile)),reldir)\n if DEBUG:\n print 'Inserting %r to sys.path' % (local_path)\n sys.path.insert(0,local_path)\n\n__all__.append('restore_path')\ndef restore_path():\n if DEBUG:\n print 'Removing %r from sys.path' % (sys.path[0])\n del sys.path[0]\n\n__all__.extend(['jiffies','memusage'])\nif sys.platform[:5]=='linux':\n def jiffies(_proc_pid_stat = '/proc/%s/stat'%(os.getpid()),\n _load_time=time.time()):\n \"\"\" Return number of jiffies (1/100ths of a second) that this\n process has been scheduled in user mode. See man 5 proc. \"\"\"\n try:\n f=open(_proc_pid_stat,'r')\n l = f.readline().split(' ')\n f.close()\n return int(l[13])\n except:\n return int(100*(time.time()-_load_time))\n\n def memusage(_proc_pid_stat = '/proc/%s/stat'%(os.getpid())):\n \"\"\" Return virtual memory size in bytes of the running python.\n \"\"\"\n try:\n f=open(_proc_pid_stat,'r')\n l = f.readline().split(' ')\n f.close()\n return int(l[22])\n except:\n return\nelse:\n # os.getpid is not in all platforms available.\n # Using time is safe but inaccurate, especially when process\n # was suspended or sleeping.\n def jiffies(_load_time=time.time()):\n \"\"\" Return number of jiffies (1/100ths of a second) that this\n process has been scheduled in user mode. [Emulation with time.time]. \"\"\"\n return int(100*(time.time()-_load_time))\n\n def memusage():\n \"\"\" Return memory usage of running python. [Not implemented]\"\"\"\n return\n\n__all__.append('ScipyTestCase')\nclass ScipyTestCase (unittest.TestCase):\n\n def measure(self,code_str,times=1):\n \"\"\" Return elapsed time for executing code_str in the\n namespace of the caller for given times.\n \"\"\"\n frame = sys._getframe(1)\n locs,globs = frame.f_locals,frame.f_globals\n code = compile(code_str,\n 'ScipyTestCase runner for '+self.__class__.__name__,\n 'exec')\n i = 0\n elapsed = jiffies()\n while i>> ScipyTest().test(level=1,verbosity=2)\n\n is package name or its module object.\n\n Package is supposed to contain a directory tests/\n with test_*.py files where * refers to the names of submodules.\n\n test_*.py files are supposed to define a classes, derived\n from ScipyTestCase or unittest.TestCase, with methods having\n names starting with test or bench or check.\n\n And that is it! No need to implement test or test_suite functions\n in each .py file.\n\n Also old styled test_suite(level=1) hooks are supported but\n soon to be removed.\n \"\"\"\n def __init__(self, package='__main__'):\n self.package = package\n\n def _module_str(self, module):\n filename = module.__file__[-30:]\n if filename!=module.__file__:\n filename = '...'+filename\n return '' % (`module.__name__`, `filename`)\n\n def _get_method_names(self,clsobj,level):\n names = []\n for mthname in _get_all_method_names(clsobj):\n if mthname[:5] not in ['bench','check'] \\\n and mthname[:4] not in ['test']:\n continue\n mth = getattr(clsobj, mthname)\n if type(mth) is not types.MethodType:\n continue\n d = mth.im_func.func_defaults\n if d is not None:\n mthlevel = d[0]\n else:\n mthlevel = 1\n if level>=mthlevel:\n if mthname not in names:\n names.append(mthname)\n for base in clsobj.__bases__:\n for n in self._get_method_names(base,level):\n if n not in names:\n names.append(n) \n return names\n\n def _get_module_tests(self,module,level):\n mstr = self._module_str\n d,f = os.path.split(module.__file__)\n\n short_module_name = os.path.splitext(os.path.basename(f))[0]\n if short_module_name=='__init__':\n short_module_name = module.__name__.split('.')[-1]\n\n test_dir = os.path.join(d,'tests')\n test_file = os.path.join(test_dir,'test_'+short_module_name+'.py')\n\n local_test_dir = os.path.join(os.getcwd(),'tests')\n local_test_file = os.path.join(local_test_dir,\n 'test_'+short_module_name+'.py')\n if os.path.basename(os.path.dirname(local_test_dir)) \\\n == os.path.basename(os.path.dirname(test_dir)) \\\n and os.path.isfile(local_test_file):\n test_file = local_test_file\n\n if not os.path.isfile(test_file):\n if short_module_name[:5]=='info_' \\\n and short_module_name[5:]==module.__name__.split('.')[-2]:\n return []\n if short_module_name in ['__cvs_version__','__svn_version__']:\n return []\n if short_module_name[-8:]=='_version' \\\n and short_module_name[:-8]==module.__name__.split('.')[-2]:\n return []\n print ' !! No test file %r found for %s' \\\n % (os.path.basename(test_file), mstr(module))\n return []\n\n try:\n if sys.version[:3]=='2.1':\n # Workaround for Python 2.1 .pyc file generator bug\n import random\n pref = '-nopyc'+`random.randint(1,100)`\n else:\n pref = ''\n f = open(test_file,'r')\n test_module = imp.load_module(\\\n module.__name__+'.test_'+short_module_name+pref,\n f, test_file+pref,('.py', 'r', 1))\n f.close()\n if sys.version[:3]=='2.1' and os.path.isfile(test_file+pref+'c'):\n os.remove(test_file+pref+'c')\n except:\n print ' !! FAILURE importing tests for ', mstr(module)\n print ' ',\n output_exception()\n return []\n return self._get_suite_list(test_module, level, module.__name__)\n\n def _get_suite_list(self, test_module, level, module_name='__main__'):\n mstr = self._module_str\n if hasattr(test_module,'test_suite'):\n # Using old styled test suite\n try:\n total_suite = test_module.test_suite(level)\n return total_suite._tests\n except:\n print ' !! FAILURE building tests for ', mstr(test_module)\n print ' ',\n output_exception()\n return []\n suite_list = []\n for name in dir(test_module):\n obj = getattr(test_module, name)\n if type(obj) is not type(unittest.TestCase) \\\n or not issubclass(obj, unittest.TestCase) \\\n or obj.__name__[:4] != 'test':\n continue\n for mthname in self._get_method_names(obj,level):\n suite = obj(mthname)\n if getattr(suite,'isrunnable',lambda mthname:1)(mthname):\n suite_list.append(suite)\n print ' Found',len(suite_list),'tests for',module_name\n return suite_list\n\n def _touch_ppimported(self, module):\n from scipy_base.ppimport import _ModuleLoader\n if os.path.isdir(os.path.join(os.path.dirname(module.__file__),'tests')):\n # only touching those modules that have tests/ directory\n try: module._pliuh_plauh\n except AttributeError: pass\n for name in dir(module):\n obj = getattr(module,name)\n if isinstance(obj,_ModuleLoader) \\\n and not hasattr(obj,'_ppimport_module') \\\n and not hasattr(obj,'_ppimport_exc_info'):\n self._touch_ppimported(obj)\n\n def test(self,level=1,verbosity=1):\n \"\"\" Run Scipy module test suite with level and verbosity.\n \"\"\"\n if type(self.package) is type(''):\n exec 'import %s as this_package' % (self.package)\n else:\n this_package = self.package\n\n self._touch_ppimported(this_package)\n\n package_name = this_package.__name__\n\n suites = []\n for name, module in sys.modules.items():\n if package_name != name[:len(package_name)] \\\n or module is None \\\n or os.path.basename(os.path.dirname(module.__file__))=='tests':\n continue\n suites.extend(self._get_module_tests(module, level))\n\n suites.extend(self._get_suite_list(sys.modules[package_name], level))\n\n all_tests = unittest.TestSuite(suites)\n runner = unittest.TextTestRunner(verbosity=verbosity)\n runner.run(all_tests)\n return runner\n\n def run(self):\n \"\"\" Run Scipy module test suite with level and verbosity\n taken from sys.argv. Requires optparse module.\n \"\"\"\n try:\n from optparse import OptionParser\n except ImportError:\n print 'Failed to import optparse module, ignoring.'\n return self.test()\n usage = r'usage: %prog [-v ] [-l ]'\n parser = OptionParser(usage)\n parser.add_option(\"-v\", \"--verbosity\",\n action=\"store\",\n dest=\"verbosity\",\n default=1,\n type='int')\n parser.add_option(\"-l\", \"--level\",\n action=\"store\",\n dest=\"level\",\n default=1,\n type='int')\n (options, args) = parser.parse_args()\n self.test(options.level,options.verbosity)\n\n#------------\n \ndef remove_ignored_patterns(files,pattern):\n from fnmatch import fnmatch\n good_files = []\n for file in files:\n if not fnmatch(file,pattern):\n good_files.append(file)\n return good_files\n\ndef remove_ignored_files(original,ignored_files,cur_dir):\n \"\"\" This is actually expanded to do pattern matching.\n\n \"\"\"\n if not ignored_files: ignored_files = []\n ignored_modules = map(lambda x: x+'.py',ignored_files)\n ignored_packages = ignored_files[:]\n # always ignore setup.py and __init__.py files\n ignored_files = ['setup.py','setup_*.py','__init__.py']\n ignored_files += ignored_modules + ignored_packages\n ignored_files = map(lambda x,cur_dir=cur_dir: os.path.join(cur_dir,x),\n ignored_files)\n #print 'ignored:', ignored_files\n #good_files = filter(lambda x,ignored = ignored_files: x not in ignored,\n # original)\n good_files = original\n for pattern in ignored_files:\n good_files = remove_ignored_patterns(good_files,pattern)\n\n return good_files\n\n__all__.append('harvest_modules')\ndef harvest_modules(package,ignore=None):\n \"\"\"* Retreive a list of all modules that live within a package.\n\n Only retreive files that are immediate children of the\n package -- do not recurse through child packages or\n directories. The returned list contains actual modules, not\n just their names.\n *\"\"\"\n d,f = os.path.split(package.__file__)\n\n # go through the directory and import every py file there.\n common_dir = os.path.join(d,'*.py')\n py_files = glob.glob(common_dir)\n #py_files.remove(os.path.join(d,'__init__.py'))\n #py_files.remove(os.path.join(d,'setup.py'))\n\n py_files = remove_ignored_files(py_files,ignore,d)\n #print 'py_files:', py_files\n try:\n prefix = package.__name__\n except:\n prefix = ''\n\n all_modules = []\n for file in py_files:\n d,f = os.path.split(file)\n base,ext = os.path.splitext(f)\n mod = prefix + '.' + base\n #print 'module: import ' + mod\n try:\n exec ('import ' + mod)\n all_modules.append(eval(mod))\n except:\n print 'FAILURE to import ' + mod\n output_exception()\n\n return all_modules\n\n__all__.append('harvest_packages')\ndef harvest_packages(package,ignore = None):\n \"\"\" Retreive a list of all sub-packages that live within a package.\n\n Only retreive packages that are immediate children of this\n package -- do not recurse through child packages or\n directories. The returned list contains actual package objects, not\n just their names.\n \"\"\"\n join = os.path.join\n\n d,f = os.path.split(package.__file__)\n\n common_dir = os.path.abspath(d)\n all_files = os.listdir(d)\n\n all_files = remove_ignored_files(all_files,ignore,'')\n #print 'all_files:', all_files\n try:\n prefix = package.__name__\n except:\n prefix = ''\n all_packages = []\n for directory in all_files:\n path = join(common_dir,directory)\n if os.path.isdir(path) and \\\n os.path.exists(join(path,'__init__.py')):\n sub_package = prefix + '.' + directory\n #print 'sub-package import ' + sub_package\n try:\n exec ('import ' + sub_package)\n all_packages.append(eval(sub_package))\n except:\n print 'FAILURE to import ' + sub_package\n output_exception()\n return all_packages\n\n__all__.append('harvest_modules_and_packages')\ndef harvest_modules_and_packages(package,ignore=None):\n \"\"\" Retreive list of all packages and modules that live within a package.\n\n See harvest_packages() and harvest_modules()\n \"\"\"\n all = harvest_modules(package,ignore) + harvest_packages(package,ignore)\n return all\n\n__all__.append('harvest_test_suites')\ndef harvest_test_suites(package,ignore = None,level=10):\n \"\"\"\n package -- the module to test. This is an actual module object\n (not a string)\n ignore -- a list of module names to omit from the tests\n level -- a value between 1 and 10. 1 will run the minimum number\n of tests. This is a fast \"smoke test\". Tests that take\n longer to run should have higher numbers ranging up to 10.\n \"\"\"\n suites=[]\n test_modules = harvest_modules_and_packages(package,ignore)\n #for i in test_modules:\n # print i.__name__\n for module in test_modules:\n if hasattr(module,'test_suite'):\n try:\n suite = module.test_suite(level=level)\n if suite:\n suites.append(suite)\n else:\n print \" !! FAILURE without error - shouldn't happen\",\n print module.__name__\n except:\n print ' !! FAILURE building test for ', module.__name__\n print ' ',\n output_exception()\n else:\n try:\n print 'No test suite found for ', module.__name__\n except AttributeError:\n # __version__.py getting replaced by a string throws a kink\n # in checking for modules, so we think is a module has\n # actually been overwritten\n print 'No test suite found for ', str(module)\n total_suite = unittest.TestSuite(suites)\n return total_suite\n\n__all__.append('module_test')\ndef module_test(mod_name,mod_file,level=10):\n \"\"\"*\n\n *\"\"\"\n #print 'testing', mod_name\n d,f = os.path.split(mod_file)\n\n # insert the tests directory to the python path\n test_dir = os.path.join(d,'tests')\n sys.path.insert(0,test_dir)\n\n # call the \"test_xxx.test()\" function for the appropriate\n # module.\n\n # This should deal with package naming issues correctly\n short_mod_name = string.split(mod_name,'.')[-1]\n test_module = 'test_' + short_mod_name\n test_string = 'import %s;reload(%s);%s.test(%d)' % \\\n ((test_module,)*3 + (level,))\n\n # This would be better cause it forces a reload of the orginal\n # module. It doesn't behave with packages however.\n #test_string = 'reload(%s);import %s;reload(%s);%s.test(%d)' % \\\n # ((mod_name,) + (test_module,)*3)\n exec(test_string)\n\n # remove test directory from python path.\n sys.path = sys.path[1:]\n\n__all__.append('module_test_suite')\ndef module_test_suite(mod_name,mod_file,level=10):\n #try:\n print ' creating test suite for:', mod_name\n d,f = os.path.split(mod_file)\n\n # insert the tests directory to the python path\n test_dir = os.path.join(d,'tests')\n sys.path.insert(0,test_dir)\n\n # call the \"test_xxx.test()\" function for the appropriate\n # module.\n\n # This should deal with package naming issues correctly\n short_mod_name = string.split(mod_name,'.')[-1]\n test_module = 'test_' + short_mod_name\n test_string = 'import %s;reload(%s);suite = %s.test_suite(%d)' % \\\n ((test_module,)*3+(level,))\n #print test_string\n exec(test_string)\n\n # remove test directory from python path.\n sys.path = sys.path[1:]\n return suite\n #except:\n # print ' !! FAILURE loading test suite from', test_module, ':'\n # print ' ',\n # output_exception()\n\n\n# Utility function to facilitate testing.\n\n__all__.append('assert_equal')\ndef assert_equal(actual,desired,err_msg='',verbose=1):\n \"\"\" Raise an assertion if two items are not\n equal. I think this should be part of unittest.py\n \"\"\"\n msg = '\\nItems are not equal:\\n' + err_msg\n try:\n if ( verbose and len(repr(desired)) < 100 and len(repr(actual)) ):\n msg = msg \\\n + 'DESIRED: ' + repr(desired) \\\n + '\\nACTUAL: ' + repr(actual)\n except:\n msg = msg \\\n + 'DESIRED: ' + repr(desired) \\\n + '\\nACTUAL: ' + repr(actual)\n assert all(desired == actual), msg\n\n__all__.append('assert_almost_equal')\ndef assert_almost_equal(actual,desired,decimal=7,err_msg='',verbose=1):\n \"\"\" Raise an assertion if two items are not\n equal. I think this should be part of unittest.py\n \"\"\"\n msg = '\\nItems are not equal:\\n' + err_msg\n try:\n if ( verbose and len(repr(desired)) < 100 and len(repr(actual)) ):\n msg = msg \\\n + 'DESIRED: ' + repr(desired) \\\n + '\\nACTUAL: ' + repr(actual)\n except:\n msg = msg \\\n + 'DESIRED: ' + repr(desired) \\\n + '\\nACTUAL: ' + repr(actual)\n assert all(around(abs(desired - actual),decimal) == 0), msg\n\n__all__.append('assert_approx_equal')\ndef assert_approx_equal(actual,desired,significant=7,err_msg='',verbose=1):\n \"\"\" Raise an assertion if two items are not\n equal. I think this should be part of unittest.py\n Approximately equal is defined as the number of significant digits\n correct\n \"\"\"\n msg = '\\nItems are not equal to %d significant digits:\\n' % significant\n msg += err_msg\n actual, desired = map(float, (actual, desired))\n # Normalized the numbers to be in range (-10.0,10.0)\n scale = pow(10,math.floor(math.log10(0.5*(abs(desired)+abs(actual)))))\n try:\n sc_desired = desired/scale\n except ZeroDivisionError:\n sc_desired = 0.0\n try:\n sc_actual = actual/scale\n except ZeroDivisionError:\n sc_actual = 0.0\n try:\n if ( verbose and len(repr(desired)) < 100 and len(repr(actual)) ):\n msg = msg \\\n + 'DESIRED: ' + repr(desired) \\\n + '\\nACTUAL: ' + repr(actual)\n except:\n msg = msg \\\n + 'DESIRED: ' + repr(desired) \\\n + '\\nACTUAL: ' + repr(actual)\n assert all(math.fabs(sc_desired - sc_actual) < pow(10.,-1*significant)), msg\n\n\n__all__.append('assert_array_equal')\ndef assert_array_equal(x,y,err_msg=''):\n x,y = asarray(x), asarray(y)\n msg = '\\nArrays are not equal'\n try:\n assert 0 in [len(shape(x)),len(shape(y))] \\\n or (len(shape(x))==len(shape(y)) and \\\n all(equal(shape(x),shape(y)))),\\\n msg + ' (shapes %s, %s mismatch):\\n\\t' \\\n % (shape(x),shape(y)) + err_msg\n reduced = ravel(equal(x,y))\n cond = all(reduced)\n if not cond:\n s1 = array2string(x,precision=16)\n s2 = array2string(y,precision=16)\n if len(s1)>120: s1 = s1[:120] + '...'\n if len(s2)>120: s2 = s2[:120] + '...'\n match = 100-100.0*reduced.tolist().count(1)/len(reduced)\n msg = msg + ' (mismatch %s%%):\\n\\tArray 1: %s\\n\\tArray 2: %s' % (match,s1,s2)\n assert cond,\\\n msg + '\\n\\t' + err_msg\n except ValueError:\n raise ValueError, msg\n\n__all__.append('assert_array_almost_equal')\ndef assert_array_almost_equal(x,y,decimal=6,err_msg=''):\n x = asarray(x)\n y = asarray(y)\n msg = '\\nArrays are not almost equal'\n try:\n cond = all(equal(shape(x),shape(y)))\n if not cond:\n msg = msg + ' (shapes mismatch):\\n\\t'\\\n 'Shape of array 1: %s\\n\\tShape of array 2: %s' % (shape(x),shape(y))\n assert cond, msg + '\\n\\t' + err_msg\n reduced = ravel(equal(less_equal(around(abs(x-y),decimal),10.0**(-decimal)),1))\n cond = all(reduced)\n if not cond:\n s1 = array2string(x,precision=decimal+1)\n s2 = array2string(y,precision=decimal+1)\n if len(s1)>120: s1 = s1[:120] + '...'\n if len(s2)>120: s2 = s2[:120] + '...'\n match = 100-100.0*reduced.tolist().count(1)/len(reduced)\n msg = msg + ' (mismatch %s%%):\\n\\tArray 1: %s\\n\\tArray 2: %s' % (match,s1,s2)\n assert cond,\\\n msg + '\\n\\t' + err_msg\n except ValueError:\n print sys.exc_value\n print shape(x),shape(y)\n print x, y\n raise ValueError, 'arrays are not almost equal'\n\n__all__.append('assert_array_less')\ndef assert_array_less(x,y,err_msg=''):\n x,y = asarray(x), asarray(y)\n msg = '\\nArrays are not less-ordered'\n try:\n assert all(equal(shape(x),shape(y))),\\\n msg + ' (shapes mismatch):\\n\\t' + err_msg\n reduced = ravel(less(x,y))\n cond = all(reduced)\n if not cond:\n s1 = array2string(x,precision=16)\n s2 = array2string(y,precision=16)\n if len(s1)>120: s1 = s1[:120] + '...'\n if len(s2)>120: s2 = s2[:120] + '...'\n match = 100-100.0*reduced.tolist().count(1)/len(reduced)\n msg = msg + ' (mismatch %s%%):\\n\\tArray 1: %s\\n\\tArray 2: %s' % (match,s1,s2)\n assert cond,\\\n msg + '\\n\\t' + err_msg\n except ValueError:\n print shape(x),shape(y)\n raise ValueError, 'arrays are not less-ordered'\n\n__all__.append('rand')\ndef rand(*args):\n \"\"\" Returns an array of random numbers with the given shape.\n used for testing\n \"\"\"\n import random\n results = zeros(args,Float64)\n f = results.flat\n for i in range(len(f)):\n f[i] = random.random()\n return results\n\ndef output_exception():\n try:\n type, value, tb = sys.exc_info()\n info = traceback.extract_tb(tb)\n #this is more verbose\n #traceback.print_exc()\n filename, lineno, function, text = info[-1] # last line only\n print \"%s:%d: %s: %s (in %s)\" %\\\n (filename, lineno, type.__name__, str(value), function)\n finally:\n type = value = tb = None # clean up\n\ntry:\n from scipy_base.numerix import fastumath as math\nexcept ImportError,msg:\n print msg\n import math\n", "methods": [ { "name": "set_package_path", "long_name": "set_package_path( level = 1 )", "filename": "testing.py", "nloc": 15, "complexity": 4, "token_count": 146, "parameters": [ "level" ], "start_line": 49, "end_line": 80, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 32, "top_nesting_level": 0 }, { "name": "set_local_path", "long_name": "set_local_path( reldir = '' , level = 1 )", "filename": "testing.py", "nloc": 11, "complexity": 3, "token_count": 97, "parameters": [ "reldir", "level" ], "start_line": 83, "end_line": 99, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 17, "top_nesting_level": 0 }, { "name": "restore_path", "long_name": "restore_path( )", "filename": "testing.py", "nloc": 4, "complexity": 2, "token_count": 25, "parameters": [], "start_line": 102, "end_line": 105, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 4, "top_nesting_level": 0 }, { "name": "jiffies", "long_name": "jiffies( _proc_pid_stat = '/proc/%s/stat' % ( os . getpid ( )", "filename": "testing.py", "nloc": 2, "complexity": 1, "token_count": 23, "parameters": [ "_proc_pid_stat" ], "start_line": 109, "end_line": 110, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 2, "top_nesting_level": 1 }, { "name": "memusage", "long_name": "memusage( _proc_pid_stat = '/proc/%s/stat' % ( os . getpid ( )", "filename": "testing.py", "nloc": 10, "complexity": 2, "token_count": 54, "parameters": [ "_proc_pid_stat" ], "start_line": 121, "end_line": 130, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 10, "top_nesting_level": 1 }, { "name": "jiffies", "long_name": "jiffies( _load_time = time . time ( )", "filename": "testing.py", "nloc": 4, "complexity": 1, "token_count": 27, "parameters": [ "_load_time" ], "start_line": 135, "end_line": 138, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 4, "top_nesting_level": 1 }, { "name": "memusage", "long_name": "memusage( )", "filename": "testing.py", "nloc": 2, "complexity": 1, "token_count": 6, "parameters": [], "start_line": 140, "end_line": 142, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 3, "top_nesting_level": 1 }, { "name": "measure", "long_name": "measure( self , code_str , times = 1 )", "filename": "testing.py", "nloc": 13, "complexity": 2, "token_count": 82, "parameters": [ "self", "code_str", "times" ], "start_line": 147, "end_line": 162, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 16, "top_nesting_level": 1 }, { "name": "__call__", "long_name": "__call__( self , result = None )", "filename": "testing.py", "nloc": 24, "complexity": 6, "token_count": 224, "parameters": [ "self", "result" ], "start_line": 164, "end_line": 188, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 25, "top_nesting_level": 1 }, { "name": "__init__", "long_name": "__init__( self , stream )", "filename": "testing.py", "nloc": 3, "complexity": 1, "token_count": 18, "parameters": [ "self", "stream" ], "start_line": 191, "end_line": 193, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 3, "top_nesting_level": 1 }, { "name": "write", "long_name": "write( self , message )", "filename": "testing.py", "nloc": 6, "complexity": 3, "token_count": 47, "parameters": [ "self", "message" ], "start_line": 194, "end_line": 199, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 6, "top_nesting_level": 1 }, { "name": "writeln", "long_name": "writeln( self , message )", "filename": "testing.py", "nloc": 2, "complexity": 1, "token_count": 15, "parameters": [ "self", "message" ], "start_line": 200, "end_line": 201, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 2, "top_nesting_level": 1 }, { "name": "_get_all_method_names", "long_name": "_get_all_method_names( cls )", "filename": "testing.py", "nloc": 8, "complexity": 5, "token_count": 56, "parameters": [ "cls" ], "start_line": 209, "end_line": 216, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 8, "top_nesting_level": 0 }, { "name": "__init__", "long_name": "__init__( self , package = '__main__' )", "filename": "testing.py", "nloc": 2, "complexity": 1, "token_count": 14, "parameters": [ "self", "package" ], "start_line": 240, "end_line": 241, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 2, "top_nesting_level": 1 }, { "name": "_module_str", "long_name": "_module_str( self , module )", "filename": "testing.py", "nloc": 5, "complexity": 2, "token_count": 43, "parameters": [ "self", "module" ], "start_line": 243, "end_line": 247, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 5, "top_nesting_level": 1 }, { "name": "_get_method_names", "long_name": "_get_method_names( self , clsobj , level )", "filename": "testing.py", "nloc": 22, "complexity": 11, "token_count": 142, "parameters": [ "self", "clsobj", "level" ], "start_line": 249, "end_line": 270, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 22, "top_nesting_level": 1 }, { "name": "_get_module_tests", "long_name": "_get_module_tests( self , module , level )", "filename": "testing.py", "nloc": 46, "complexity": 14, "token_count": 428, "parameters": [ "self", "module", "level" ], "start_line": 272, "end_line": 323, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 52, "top_nesting_level": 1 }, { "name": "_get_suite_list", "long_name": "_get_suite_list( self , test_module , level , module_name = '__main__' )", "filename": "testing.py", "nloc": 24, "complexity": 9, "token_count": 168, "parameters": [ "self", "test_module", "level", "module_name" ], "start_line": 325, "end_line": 349, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 25, "top_nesting_level": 1 }, { "name": "_touch_ppimported", "long_name": "_touch_ppimported( self , module )", "filename": "testing.py", "nloc": 11, "complexity": 7, "token_count": 98, "parameters": [ "self", "module" ], "start_line": 351, "end_line": 362, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 12, "top_nesting_level": 1 }, { "name": "test", "long_name": "test( self , level = 1 , verbosity = 1 )", "filename": "testing.py", "nloc": 19, "complexity": 6, "token_count": 166, "parameters": [ "self", "level", "verbosity" ], "start_line": 364, "end_line": 389, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 26, "top_nesting_level": 1 }, { "name": "run", "long_name": "run( self )", "filename": "testing.py", "nloc": 20, "complexity": 2, "token_count": 104, "parameters": [ "self" ], "start_line": 391, "end_line": 413, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 23, "top_nesting_level": 1 }, { "name": "remove_ignored_patterns", "long_name": "remove_ignored_patterns( files , pattern )", "filename": "testing.py", "nloc": 7, "complexity": 3, "token_count": 37, "parameters": [ "files", "pattern" ], "start_line": 417, "end_line": 423, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 7, "top_nesting_level": 0 }, { "name": "remove_ignored_files", "long_name": "remove_ignored_files( original , ignored_files , cur_dir )", "filename": "testing.py", "nloc": 12, "complexity": 3, "token_count": 93, "parameters": [ "original", "ignored_files", "cur_dir" ], "start_line": 425, "end_line": 444, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 20, "top_nesting_level": 0 }, { "name": "harvest_modules", "long_name": "harvest_modules( package , ignore = None )", "filename": "testing.py", "nloc": 21, "complexity": 4, "token_count": 134, "parameters": [ "package", "ignore" ], "start_line": 447, "end_line": 483, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 37, "top_nesting_level": 0 }, { "name": "harvest_packages", "long_name": "harvest_packages( package , ignore = None )", "filename": "testing.py", "nloc": 23, "complexity": 6, "token_count": 148, "parameters": [ "package", "ignore" ], "start_line": 486, "end_line": 520, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 35, "top_nesting_level": 0 }, { "name": "harvest_modules_and_packages", "long_name": "harvest_modules_and_packages( package , ignore = None )", "filename": "testing.py", "nloc": 3, "complexity": 1, "token_count": 27, "parameters": [ "package", "ignore" ], "start_line": 523, "end_line": 529, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 7, "top_nesting_level": 0 }, { "name": "harvest_test_suites", "long_name": "harvest_test_suites( package , ignore = None , level = 10 )", "filename": "testing.py", "nloc": 23, "complexity": 6, "token_count": 113, "parameters": [ "package", "ignore", "level" ], "start_line": 532, "end_line": 567, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 36, "top_nesting_level": 0 }, { "name": "module_test", "long_name": "module_test( mod_name , mod_file , level = 10 )", "filename": "testing.py", "nloc": 10, "complexity": 1, "token_count": 98, "parameters": [ "mod_name", "mod_file", "level" ], "start_line": 570, "end_line": 597, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 28, "top_nesting_level": 0 }, { "name": "module_test_suite", "long_name": "module_test_suite( mod_name , mod_file , level = 10 )", "filename": "testing.py", "nloc": 12, "complexity": 1, "token_count": 103, "parameters": [ "mod_name", "mod_file", "level" ], "start_line": 600, "end_line": 622, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 23, "top_nesting_level": 0 }, { "name": "assert_equal", "long_name": "assert_equal( actual , desired , err_msg = '' , verbose = 1 )", "filename": "testing.py", "nloc": 14, "complexity": 6, "token_count": 109, "parameters": [ "actual", "desired", "err_msg", "verbose" ], "start_line": 632, "end_line": 648, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 17, "top_nesting_level": 0 }, { "name": "assert_almost_equal", "long_name": "assert_almost_equal( actual , desired , decimal = 7 , err_msg = '' , verbose = 1 )", "filename": "testing.py", "nloc": 14, "complexity": 6, "token_count": 125, "parameters": [ "actual", "desired", "decimal", "err_msg", "verbose" ], "start_line": 651, "end_line": 667, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 17, "top_nesting_level": 0 }, { "name": "assert_approx_equal", "long_name": "assert_approx_equal( actual , desired , significant = 7 , err_msg = '' , verbose = 1 )", "filename": "testing.py", "nloc": 23, "complexity": 7, "token_count": 191, "parameters": [ "actual", "desired", "significant", "err_msg", "verbose" ], "start_line": 670, "end_line": 698, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 29, "top_nesting_level": 0 }, { "name": "assert_array_equal", "long_name": "assert_array_equal( x , y , err_msg = '' )", "filename": "testing.py", "nloc": 22, "complexity": 7, "token_count": 232, "parameters": [ "x", "y", "err_msg" ], "start_line": 702, "end_line": 723, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 22, "top_nesting_level": 0 }, { "name": "assert_array_almost_equal", "long_name": "assert_array_almost_equal( x , y , decimal = 6 , err_msg = '' )", "filename": "testing.py", "nloc": 26, "complexity": 6, "token_count": 251, "parameters": [ "x", "y", "decimal", "err_msg" ], "start_line": 726, "end_line": 751, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 26, "top_nesting_level": 0 }, { "name": "assert_array_less", "long_name": "assert_array_less( x , y , err_msg = '' )", "filename": "testing.py", "nloc": 20, "complexity": 5, "token_count": 189, "parameters": [ "x", "y", "err_msg" ], "start_line": 754, "end_line": 773, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 20, "top_nesting_level": 0 }, { "name": "rand", "long_name": "rand( * args )", "filename": "testing.py", "nloc": 7, "complexity": 2, "token_count": 45, "parameters": [ "args" ], "start_line": 776, "end_line": 785, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 10, "top_nesting_level": 0 }, { "name": "output_exception", "long_name": "output_exception( )", "filename": "testing.py", "nloc": 9, "complexity": 2, "token_count": 67, "parameters": [], "start_line": 787, "end_line": 797, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 11, "top_nesting_level": 0 } ], "methods_before": [ { "name": "set_package_path", "long_name": "set_package_path( level = 1 )", "filename": "testing.py", "nloc": 15, "complexity": 4, "token_count": 146, "parameters": [ "level" ], "start_line": 49, "end_line": 80, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 32, "top_nesting_level": 0 }, { "name": "set_local_path", "long_name": "set_local_path( reldir = '' , level = 1 )", "filename": "testing.py", "nloc": 11, "complexity": 3, "token_count": 97, "parameters": [ "reldir", "level" ], "start_line": 83, "end_line": 99, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 17, "top_nesting_level": 0 }, { "name": "restore_path", "long_name": "restore_path( )", "filename": "testing.py", "nloc": 4, "complexity": 2, "token_count": 25, "parameters": [], "start_line": 102, "end_line": 105, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 4, "top_nesting_level": 0 }, { "name": "jiffies", "long_name": "jiffies( _proc_pid_stat = '/proc/%s/stat' % ( os . getpid ( )", "filename": "testing.py", "nloc": 2, "complexity": 1, "token_count": 23, "parameters": [ "_proc_pid_stat" ], "start_line": 109, "end_line": 110, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 2, "top_nesting_level": 1 }, { "name": "memusage", "long_name": "memusage( _proc_pid_stat = '/proc/%s/stat' % ( os . getpid ( )", "filename": "testing.py", "nloc": 10, "complexity": 2, "token_count": 54, "parameters": [ "_proc_pid_stat" ], "start_line": 121, "end_line": 130, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 10, "top_nesting_level": 1 }, { "name": "jiffies", "long_name": "jiffies( _load_time = time . time ( )", "filename": "testing.py", "nloc": 4, "complexity": 1, "token_count": 27, "parameters": [ "_load_time" ], "start_line": 135, "end_line": 138, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 4, "top_nesting_level": 1 }, { "name": "memusage", "long_name": "memusage( )", "filename": "testing.py", "nloc": 2, "complexity": 1, "token_count": 6, "parameters": [], "start_line": 140, "end_line": 142, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 3, "top_nesting_level": 1 }, { "name": "measure", "long_name": "measure( self , code_str , times = 1 )", "filename": "testing.py", "nloc": 13, "complexity": 2, "token_count": 82, "parameters": [ "self", "code_str", "times" ], "start_line": 147, "end_line": 162, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 16, "top_nesting_level": 1 }, { "name": "__call__", "long_name": "__call__( self , result = None )", "filename": "testing.py", "nloc": 24, "complexity": 6, "token_count": 224, "parameters": [ "self", "result" ], "start_line": 164, "end_line": 188, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 25, "top_nesting_level": 1 }, { "name": "__init__", "long_name": "__init__( self , stream )", "filename": "testing.py", "nloc": 3, "complexity": 1, "token_count": 18, "parameters": [ "self", "stream" ], "start_line": 191, "end_line": 193, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 3, "top_nesting_level": 1 }, { "name": "write", "long_name": "write( self , message )", "filename": "testing.py", "nloc": 6, "complexity": 3, "token_count": 47, "parameters": [ "self", "message" ], "start_line": 194, "end_line": 199, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 6, "top_nesting_level": 1 }, { "name": "writeln", "long_name": "writeln( self , message )", "filename": "testing.py", "nloc": 2, "complexity": 1, "token_count": 15, "parameters": [ "self", "message" ], "start_line": 200, "end_line": 201, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 2, "top_nesting_level": 1 }, { "name": "_get_all_method_names", "long_name": "_get_all_method_names( cls )", "filename": "testing.py", "nloc": 8, "complexity": 5, "token_count": 56, "parameters": [ "cls" ], "start_line": 209, "end_line": 216, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 8, "top_nesting_level": 0 }, { "name": "__init__", "long_name": "__init__( self , package = '__main__' )", "filename": "testing.py", "nloc": 2, "complexity": 1, "token_count": 14, "parameters": [ "self", "package" ], "start_line": 240, "end_line": 241, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 2, "top_nesting_level": 1 }, { "name": "_module_str", "long_name": "_module_str( self , module )", "filename": "testing.py", "nloc": 5, "complexity": 2, "token_count": 43, "parameters": [ "self", "module" ], "start_line": 243, "end_line": 247, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 5, "top_nesting_level": 1 }, { "name": "_get_method_names", "long_name": "_get_method_names( self , clsobj , level )", "filename": "testing.py", "nloc": 22, "complexity": 11, "token_count": 142, "parameters": [ "self", "clsobj", "level" ], "start_line": 249, "end_line": 270, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 22, "top_nesting_level": 1 }, { "name": "_get_module_tests", "long_name": "_get_module_tests( self , module , level )", "filename": "testing.py", "nloc": 46, "complexity": 14, "token_count": 428, "parameters": [ "self", "module", "level" ], "start_line": 272, "end_line": 323, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 52, "top_nesting_level": 1 }, { "name": "_get_suite_list", "long_name": "_get_suite_list( self , test_module , level , module_name = '__main__' )", "filename": "testing.py", "nloc": 24, "complexity": 9, "token_count": 168, "parameters": [ "self", "test_module", "level", "module_name" ], "start_line": 325, "end_line": 349, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 25, "top_nesting_level": 1 }, { "name": "_touch_ppimported", "long_name": "_touch_ppimported( self , module )", "filename": "testing.py", "nloc": 11, "complexity": 7, "token_count": 98, "parameters": [ "self", "module" ], "start_line": 351, "end_line": 362, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 12, "top_nesting_level": 1 }, { "name": "test", "long_name": "test( self , level = 1 , verbosity = 1 )", "filename": "testing.py", "nloc": 19, "complexity": 6, "token_count": 166, "parameters": [ "self", "level", "verbosity" ], "start_line": 364, "end_line": 389, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 26, "top_nesting_level": 1 }, { "name": "run", "long_name": "run( self )", "filename": "testing.py", "nloc": 20, "complexity": 2, "token_count": 104, "parameters": [ "self" ], "start_line": 391, "end_line": 413, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 23, "top_nesting_level": 1 }, { "name": "remove_ignored_patterns", "long_name": "remove_ignored_patterns( files , pattern )", "filename": "testing.py", "nloc": 7, "complexity": 3, "token_count": 37, "parameters": [ "files", "pattern" ], "start_line": 417, "end_line": 423, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 7, "top_nesting_level": 0 }, { "name": "remove_ignored_files", "long_name": "remove_ignored_files( original , ignored_files , cur_dir )", "filename": "testing.py", "nloc": 12, "complexity": 3, "token_count": 93, "parameters": [ "original", "ignored_files", "cur_dir" ], "start_line": 425, "end_line": 444, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 20, "top_nesting_level": 0 }, { "name": "harvest_modules", "long_name": "harvest_modules( package , ignore = None )", "filename": "testing.py", "nloc": 21, "complexity": 4, "token_count": 134, "parameters": [ "package", "ignore" ], "start_line": 447, "end_line": 483, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 37, "top_nesting_level": 0 }, { "name": "harvest_packages", "long_name": "harvest_packages( package , ignore = None )", "filename": "testing.py", "nloc": 23, "complexity": 6, "token_count": 148, "parameters": [ "package", "ignore" ], "start_line": 486, "end_line": 520, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 35, "top_nesting_level": 0 }, { "name": "harvest_modules_and_packages", "long_name": "harvest_modules_and_packages( package , ignore = None )", "filename": "testing.py", "nloc": 3, "complexity": 1, "token_count": 27, "parameters": [ "package", "ignore" ], "start_line": 523, "end_line": 529, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 7, "top_nesting_level": 0 }, { "name": "harvest_test_suites", "long_name": "harvest_test_suites( package , ignore = None , level = 10 )", "filename": "testing.py", "nloc": 23, "complexity": 6, "token_count": 113, "parameters": [ "package", "ignore", "level" ], "start_line": 532, "end_line": 567, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 36, "top_nesting_level": 0 }, { "name": "module_test", "long_name": "module_test( mod_name , mod_file , level = 10 )", "filename": "testing.py", "nloc": 10, "complexity": 1, "token_count": 98, "parameters": [ "mod_name", "mod_file", "level" ], "start_line": 570, "end_line": 597, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 28, "top_nesting_level": 0 }, { "name": "module_test_suite", "long_name": "module_test_suite( mod_name , mod_file , level = 10 )", "filename": "testing.py", "nloc": 12, "complexity": 1, "token_count": 103, "parameters": [ "mod_name", "mod_file", "level" ], "start_line": 600, "end_line": 622, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 23, "top_nesting_level": 0 }, { "name": "assert_equal", "long_name": "assert_equal( actual , desired , err_msg = '' , verbose = 1 )", "filename": "testing.py", "nloc": 12, "complexity": 5, "token_count": 95, "parameters": [ "actual", "desired", "err_msg", "verbose" ], "start_line": 632, "end_line": 646, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 15, "top_nesting_level": 0 }, { "name": "assert_almost_equal", "long_name": "assert_almost_equal( actual , desired , decimal = 7 , err_msg = '' , verbose = 1 )", "filename": "testing.py", "nloc": 12, "complexity": 5, "token_count": 109, "parameters": [ "actual", "desired", "decimal", "err_msg", "verbose" ], "start_line": 649, "end_line": 663, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 15, "top_nesting_level": 0 }, { "name": "assert_approx_equal", "long_name": "assert_approx_equal( actual , desired , significant = 7 , err_msg = '' , verbose = 1 )", "filename": "testing.py", "nloc": 23, "complexity": 7, "token_count": 194, "parameters": [ "actual", "desired", "significant", "err_msg", "verbose" ], "start_line": 666, "end_line": 694, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 29, "top_nesting_level": 0 }, { "name": "assert_array_equal", "long_name": "assert_array_equal( x , y , err_msg = '' )", "filename": "testing.py", "nloc": 22, "complexity": 7, "token_count": 232, "parameters": [ "x", "y", "err_msg" ], "start_line": 698, "end_line": 719, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 22, "top_nesting_level": 0 }, { "name": "assert_array_almost_equal", "long_name": "assert_array_almost_equal( x , y , decimal = 6 , err_msg = '' )", "filename": "testing.py", "nloc": 26, "complexity": 6, "token_count": 251, "parameters": [ "x", "y", "decimal", "err_msg" ], "start_line": 722, "end_line": 747, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 26, "top_nesting_level": 0 }, { "name": "assert_array_less", "long_name": "assert_array_less( x , y , err_msg = '' )", "filename": "testing.py", "nloc": 20, "complexity": 5, "token_count": 189, "parameters": [ "x", "y", "err_msg" ], "start_line": 750, "end_line": 769, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 20, "top_nesting_level": 0 }, { "name": "rand", "long_name": "rand( * args )", "filename": "testing.py", "nloc": 7, "complexity": 2, "token_count": 45, "parameters": [ "args" ], "start_line": 772, "end_line": 781, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 10, "top_nesting_level": 0 }, { "name": "output_exception", "long_name": "output_exception( )", "filename": "testing.py", "nloc": 9, "complexity": 2, "token_count": 67, "parameters": [], "start_line": 783, "end_line": 793, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 11, "top_nesting_level": 0 } ], "changed_methods": [ { "name": "assert_array_less", "long_name": "assert_array_less( x , y , err_msg = '' )", "filename": "testing.py", "nloc": 20, "complexity": 5, "token_count": 189, "parameters": [ "x", "y", "err_msg" ], "start_line": 754, "end_line": 773, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 20, "top_nesting_level": 0 }, { "name": "assert_equal", "long_name": "assert_equal( actual , desired , err_msg = '' , verbose = 1 )", "filename": "testing.py", "nloc": 14, "complexity": 6, "token_count": 109, "parameters": [ "actual", "desired", "err_msg", "verbose" ], "start_line": 632, "end_line": 648, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 17, "top_nesting_level": 0 }, { "name": "assert_almost_equal", "long_name": "assert_almost_equal( actual , desired , decimal = 7 , err_msg = '' , verbose = 1 )", "filename": "testing.py", "nloc": 14, "complexity": 6, "token_count": 125, "parameters": [ "actual", "desired", "decimal", "err_msg", "verbose" ], "start_line": 651, "end_line": 667, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 17, "top_nesting_level": 0 }, { "name": "assert_approx_equal", "long_name": "assert_approx_equal( actual , desired , significant = 7 , err_msg = '' , verbose = 1 )", "filename": "testing.py", "nloc": 23, "complexity": 7, "token_count": 191, "parameters": [ "actual", "desired", "significant", "err_msg", "verbose" ], "start_line": 670, "end_line": 698, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 29, "top_nesting_level": 0 }, { "name": "assert_array_almost_equal", "long_name": "assert_array_almost_equal( x , y , decimal = 6 , err_msg = '' )", "filename": "testing.py", "nloc": 26, "complexity": 6, "token_count": 251, "parameters": [ "x", "y", "decimal", "err_msg" ], "start_line": 726, "end_line": 751, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 26, "top_nesting_level": 0 }, { "name": "assert_array_equal", "long_name": "assert_array_equal( x , y , err_msg = '' )", "filename": "testing.py", "nloc": 22, "complexity": 7, "token_count": 232, "parameters": [ "x", "y", "err_msg" ], "start_line": 702, "end_line": 723, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 22, "top_nesting_level": 0 } ], "nloc": 599, "complexity": 150, "token_count": 4277, "diff_parsed": { "added": [ " from scipy_base.numerix import alltrue, equal, shape, ravel, around, zeros, Float64, asarray", " from scipy_base.numerix import less_equal, array2string, less, ArrayType", " if isinstance(actual, ArrayType):", " return assert_array_equal(actual, desired, err_msg)", " assert desired == actual, msg", " if isinstance(actual, ArrayType):", " return assert_array_almost_equal(actual, desired, decimal, err_msg)", " assert round(abs(desired - actual),decimal) == 0, msg", " assert math.fabs(sc_desired - sc_actual) < pow(10.,-1*significant), msg", " alltrue(equal(shape(x),shape(y)))),\\", " cond = alltrue(reduced)", " cond = alltrue(equal(shape(x),shape(y)))", " cond = alltrue(reduced)", " assert alltrue(equal(shape(x),shape(y))),\\", " cond = alltrue(reduced)" ], "deleted": [ " from scipy_base.numerix import all, equal, shape, ravel, around, zeros, Float64, asarray", " from scipy_base.numerix import less_equal, array2string, less", " assert all(desired == actual), msg", " assert all(around(abs(desired - actual),decimal) == 0), msg", " assert all(math.fabs(sc_desired - sc_actual) < pow(10.,-1*significant)), msg", " all(equal(shape(x),shape(y)))),\\", " cond = all(reduced)", " cond = all(equal(shape(x),shape(y)))", " cond = all(reduced)", " assert all(equal(shape(x),shape(y))),\\", " cond = all(reduced)" ] } } ] }, { "hash": "f29481bbf2ec6ece13670e0f419c6dcb6da8bad0", "msg": "Try harder to find ATLAS version.", "author": { "name": "Pearu Peterson", "email": "pearu.peterson@gmail.com" }, "committer": { "name": "Pearu Peterson", "email": "pearu.peterson@gmail.com" }, "author_date": "2004-12-21T09:10:42+00:00", "author_timezone": 0, "committer_date": "2004-12-21T09:10:42+00:00", "committer_timezone": 0, "branches": [ "main" ], "in_main_branch": true, "merge": false, "parents": [ "7d87fa78d5658ae8ea96e3676970c1fbfd5f4743" ], "project_name": "repo_copy", "project_path": "/tmp/tmpqop781_j/repo_copy", "deletions": 1, "insertions": 1, "lines": 2, "files": 1, "dmm_unit_size": null, "dmm_unit_complexity": null, "dmm_unit_interfacing": null, "modified_files": [ { "old_path": "scipy_distutils/system_info.py", "new_path": "scipy_distutils/system_info.py", "filename": "system_info.py", "extension": "py", "change_type": "MODIFY", "diff": "@@ -903,7 +903,7 @@ def atlas_version_c(extension, build_dir,magic=magic):\n s,o = exec_command(cmd,execute_in=os.path.dirname(target),use_tee=0)\n atlas_version = None\n if not s:\n- m = re.match(r'ATLAS version (?P\\d+[.]\\d+[.]\\d+)',o)\n+ m = re.search(r'ATLAS version (?P\\d+[.]\\d+[.]\\d+)',o)\n if m:\n atlas_version = m.group('version')\n if atlas_version is None:\n", "added_lines": 1, "deleted_lines": 1, "source_code": "#!/usr/bin/env python\n\"\"\"\nThis file defines a set of system_info classes for getting\ninformation about various resources (libraries, library directories,\ninclude directories, etc.) in the system. Currently, the following\nclasses are available:\n\n atlas_info\n atlas_threads_info\n atlas_blas_info\n atlas_blas_threads_info\n lapack_atlas_info\n blas_info\n lapack_info\n blas_opt_info # usage recommended\n lapack_opt_info # usage recommended\n fftw_info,dfftw_info,sfftw_info\n fftw_threads_info,dfftw_threads_info,sfftw_threads_info\n djbfft_info\n x11_info\n lapack_src_info\n blas_src_info\n numpy_info\n numarray_info\n boost_python_info\n agg2_info\n wx_info\n gdk_pixbuf_xlib_2_info\n gdk_pixbuf_2_info\n gdk_x11_2_info\n gtkp_x11_2_info\n gtkp_2_info\n xft_info\n freetype2_info\n\nUsage:\n info_dict = get_info()\n where is a string 'atlas','x11','fftw','lapack','blas',\n 'lapack_src', 'blas_src', etc. For a complete list of allowed names,\n see the definition of get_info() function below.\n\n Returned info_dict is a dictionary which is compatible with\n distutils.setup keyword arguments. If info_dict == {}, then the\n asked resource is not available (system_info could not find it).\n\n Several *_info classes specify an environment variable to specify\n the locations of software. When setting the corresponding environment\n variable to 'None' then the software will be ignored, even when it\n is available in system.\n\nGlobal parameters:\n system_info.search_static_first - search static libraries (.a)\n in precedence to shared ones (.so, .sl) if enabled.\n system_info.verbosity - output the results to stdout if enabled.\n\nThe file 'site.cfg' in the same directory as this module is read\nfor configuration options. The format is that used by ConfigParser (i.e.,\nWindows .INI style). The section DEFAULT has options that are the default\nfor each section. The available sections are fftw, atlas, and x11. Appropiate\ndefaults are used if nothing is specified.\n\nThe order of finding the locations of resources is the following:\n 1. environment variable\n 2. section in site.cfg\n 3. DEFAULT section in site.cfg\nOnly the first complete match is returned.\n\nExample:\n----------\n[DEFAULT]\nlibrary_dirs = /usr/lib:/usr/local/lib:/opt/lib\ninclude_dirs = /usr/include:/usr/local/include:/opt/include\nsrc_dirs = /usr/local/src:/opt/src\n# search static libraries (.a) in preference to shared ones (.so)\nsearch_static_first = 0\n\n[fftw]\nfftw_libs = rfftw, fftw\nfftw_opt_libs = rfftw_threaded, fftw_threaded\n# if the above aren't found, look for {s,d}fftw_libs and {s,d}fftw_opt_libs\n\n[atlas]\nlibrary_dirs = /usr/lib/3dnow:/usr/lib/3dnow/atlas\n# for overriding the names of the atlas libraries\natlas_libs = lapack, f77blas, cblas, atlas\n\n[x11]\nlibrary_dirs = /usr/X11R6/lib\ninclude_dirs = /usr/X11R6/include\n----------\n\nAuthors:\n Pearu Peterson , February 2002\n David M. Cooke , April 2002\n\nCopyright 2002 Pearu Peterson all rights reserved,\nPearu Peterson \nPermission to use, modify, and distribute this software is given under the \nterms of the SciPy (BSD style) license. See LICENSE.txt that came with\nthis distribution for specifics.\n\nNO WARRANTY IS EXPRESSED OR IMPLIED. USE AT YOUR OWN RISK.\n\"\"\"\n\n__revision__ = '$Id$'\n\nimport sys,os,re,types\nimport warnings\nfrom distutils.errors import DistutilsError\nfrom glob import glob\nimport ConfigParser\nfrom exec_command import find_executable, exec_command\n\nfrom distutils.sysconfig import get_config_vars\n\nif sys.platform == 'win32':\n default_lib_dirs = ['C:\\\\'] # probably not very helpful...\n default_include_dirs = []\n default_src_dirs = ['.']\n default_x11_lib_dirs = []\n default_x11_include_dirs = []\nelse:\n default_lib_dirs = ['/usr/local/lib', '/opt/lib', '/usr/lib',\n '/sw/lib']\n default_include_dirs = ['/usr/local/include',\n '/opt/include', '/usr/include',\n '/sw/include']\n default_src_dirs = ['.','/usr/local/src', '/opt/src','/sw/src']\n default_x11_lib_dirs = ['/usr/X11R6/lib','/usr/X11/lib','/usr/lib']\n default_x11_include_dirs = ['/usr/X11R6/include','/usr/X11/include',\n '/usr/include']\n\nif os.path.join(sys.prefix, 'lib') not in default_lib_dirs:\n default_lib_dirs.insert(0,os.path.join(sys.prefix, 'lib'))\n default_include_dirs.append(os.path.join(sys.prefix, 'include'))\n default_src_dirs.append(os.path.join(sys.prefix, 'src'))\n\ndefault_lib_dirs = filter(os.path.isdir, default_lib_dirs)\ndefault_include_dirs = filter(os.path.isdir, default_include_dirs)\ndefault_src_dirs = filter(os.path.isdir, default_src_dirs)\n\nso_ext = get_config_vars('SO')[0] or ''\n\ndef get_info(name,notfound_action=0):\n \"\"\"\n notfound_action:\n 0 - do nothing\n 1 - display warning message\n 2 - raise error\n \"\"\"\n cl = {'atlas':atlas_info, # use lapack_opt or blas_opt instead\n 'atlas_threads':atlas_threads_info, # ditto\n 'atlas_blas':atlas_blas_info,\n 'atlas_blas_threads':atlas_blas_threads_info,\n 'lapack_atlas':lapack_atlas_info, # use lapack_opt instead\n 'lapack_atlas_threads':lapack_atlas_threads_info, # ditto\n 'x11':x11_info,\n 'fftw':fftw_info,\n 'dfftw':dfftw_info,\n 'sfftw':sfftw_info,\n 'fftw_threads':fftw_threads_info,\n 'dfftw_threads':dfftw_threads_info,\n 'sfftw_threads':sfftw_threads_info,\n 'djbfft':djbfft_info,\n 'blas':blas_info, # use blas_opt instead\n 'lapack':lapack_info, # use lapack_opt instead\n 'lapack_src':lapack_src_info,\n 'blas_src':blas_src_info,\n 'numpy':numpy_info,\n 'numarray':numarray_info,\n 'lapack_opt':lapack_opt_info,\n 'blas_opt':blas_opt_info,\n 'boost_python':boost_python_info,\n 'agg2':agg2_info,\n 'wx':wx_info,\n 'gdk_pixbuf_xlib_2':gdk_pixbuf_xlib_2_info,\n 'gdk-pixbuf-xlib-2.0':gdk_pixbuf_xlib_2_info,\n 'gdk_pixbuf_2':gdk_pixbuf_2_info,\n 'gdk-pixbuf-2.0':gdk_pixbuf_2_info,\n 'gdk':gdk_info,\n 'gdk_2':gdk_2_info,\n 'gdk-2.0':gdk_2_info,\n 'gdk_x11_2':gdk_x11_2_info,\n 'gdk-x11-2.0':gdk_x11_2_info,\n 'gtkp_x11_2':gtkp_x11_2_info,\n 'gtk+-x11-2.0':gtkp_x11_2_info,\n 'gtkp_2':gtkp_2_info,\n 'gtk+-2.0':gtkp_2_info,\n 'xft':xft_info,\n 'freetype2':freetype2_info,\n }.get(name.lower(),system_info)\n return cl().get_info(notfound_action)\n\nclass NotFoundError(DistutilsError):\n \"\"\"Some third-party program or library is not found.\"\"\"\n\nclass AtlasNotFoundError(NotFoundError):\n \"\"\"\n Atlas (http://math-atlas.sourceforge.net/) libraries not found.\n Directories to search for the libraries can be specified in the\n scipy_distutils/site.cfg file (section [atlas]) or by setting\n the ATLAS environment variable.\"\"\"\n\nclass LapackNotFoundError(NotFoundError):\n \"\"\"\n Lapack (http://www.netlib.org/lapack/) libraries not found.\n Directories to search for the libraries can be specified in the\n scipy_distutils/site.cfg file (section [lapack]) or by setting\n the LAPACK environment variable.\"\"\"\n\nclass LapackSrcNotFoundError(LapackNotFoundError):\n \"\"\"\n Lapack (http://www.netlib.org/lapack/) sources not found.\n Directories to search for the sources can be specified in the\n scipy_distutils/site.cfg file (section [lapack_src]) or by setting\n the LAPACK_SRC environment variable.\"\"\"\n\nclass BlasNotFoundError(NotFoundError):\n \"\"\"\n Blas (http://www.netlib.org/blas/) libraries not found.\n Directories to search for the libraries can be specified in the\n scipy_distutils/site.cfg file (section [blas]) or by setting\n the BLAS environment variable.\"\"\"\n\nclass BlasSrcNotFoundError(BlasNotFoundError):\n \"\"\"\n Blas (http://www.netlib.org/blas/) sources not found.\n Directories to search for the sources can be specified in the\n scipy_distutils/site.cfg file (section [blas_src]) or by setting\n the BLAS_SRC environment variable.\"\"\"\n\nclass FFTWNotFoundError(NotFoundError):\n \"\"\"\n FFTW (http://www.fftw.org/) libraries not found.\n Directories to search for the libraries can be specified in the\n scipy_distutils/site.cfg file (section [fftw]) or by setting\n the FFTW environment variable.\"\"\"\n\nclass DJBFFTNotFoundError(NotFoundError):\n \"\"\"\n DJBFFT (http://cr.yp.to/djbfft.html) libraries not found.\n Directories to search for the libraries can be specified in the\n scipy_distutils/site.cfg file (section [djbfft]) or by setting\n the DJBFFT environment variable.\"\"\"\n\nclass F2pyNotFoundError(NotFoundError):\n \"\"\"\n f2py2e (http://cens.ioc.ee/projects/f2py2e/) module not found.\n Get it from above location, install it, and retry setup.py.\"\"\"\n\nclass NumericNotFoundError(NotFoundError):\n \"\"\"\n Numeric (http://www.numpy.org/) module not found.\n Get it from above location, install it, and retry setup.py.\"\"\"\n\nclass X11NotFoundError(NotFoundError):\n \"\"\"X11 libraries not found.\"\"\"\n\nclass system_info:\n\n \"\"\" get_info() is the only public method. Don't use others.\n \"\"\"\n section = 'DEFAULT'\n dir_env_var = None\n search_static_first = 0 # XXX: disabled by default, may disappear in\n # future unless it is proved to be useful.\n verbosity = 1\n saved_results = {}\n\n notfounderror = NotFoundError\n\n def __init__ (self,\n default_lib_dirs=default_lib_dirs,\n default_include_dirs=default_include_dirs,\n verbosity = 1,\n ):\n self.__class__.info = {}\n self.local_prefixes = []\n defaults = {}\n defaults['libraries'] = ''\n defaults['library_dirs'] = os.pathsep.join(default_lib_dirs)\n defaults['include_dirs'] = os.pathsep.join(default_include_dirs)\n defaults['src_dirs'] = os.pathsep.join(default_src_dirs)\n defaults['search_static_first'] = str(self.search_static_first)\n self.cp = ConfigParser.ConfigParser(defaults)\n try:\n __file__\n except NameError:\n __file__ = sys.argv[0]\n cf = os.path.join(os.path.split(os.path.abspath(__file__))[0],\n 'site.cfg')\n self.cp.read([cf])\n if not self.cp.has_section(self.section):\n self.cp.add_section(self.section)\n self.search_static_first = self.cp.getboolean(self.section,\n 'search_static_first')\n assert isinstance(self.search_static_first, type(0))\n\n def calc_libraries_info(self):\n libs = self.get_libraries()\n dirs = self.get_lib_dirs()\n info = {}\n for lib in libs:\n i = None\n for d in dirs:\n i = self.check_libs(d,[lib]) \n if i is not None:\n break\n if i is not None:\n dict_append(info,**i)\n else:\n print 'Library %s was not found. Ignoring' % (lib)\n return info\n\n def set_info(self,**info):\n if info: \n lib_info = self.calc_libraries_info()\n dict_append(info,**lib_info)\n self.saved_results[self.__class__.__name__] = info\n\n def has_info(self):\n return self.saved_results.has_key(self.__class__.__name__)\n\n def get_info(self,notfound_action=0):\n \"\"\" Return a dictonary with items that are compatible\n with scipy_distutils.setup keyword arguments.\n \"\"\"\n flag = 0\n if not self.has_info():\n flag = 1\n if self.verbosity>0:\n print self.__class__.__name__ + ':'\n if hasattr(self, 'calc_info'):\n self.calc_info()\n if notfound_action:\n if not self.has_info():\n if notfound_action==1:\n warnings.warn(self.notfounderror.__doc__)\n elif notfound_action==2:\n raise self.notfounderror,self.notfounderror.__doc__\n else:\n raise ValueError,`notfound_action`\n\n if self.verbosity>0:\n if not self.has_info():\n print ' NOT AVAILABLE'\n self.set_info()\n else:\n print ' FOUND:'\n \n res = self.saved_results.get(self.__class__.__name__)\n if self.verbosity>0 and flag:\n for k,v in res.items():\n v = str(v)\n if k=='sources' and len(v)>200: v = v[:60]+' ...\\n... '+v[-60:]\n print ' %s = %s'%(k,v)\n print\n \n return res\n\n def get_paths(self, section, key):\n dirs = self.cp.get(section, key).split(os.pathsep)\n env_var = self.dir_env_var\n if env_var:\n if type(env_var) is type([]):\n e0 = env_var[-1]\n for e in env_var:\n if os.environ.has_key(e):\n e0 = e\n break\n if not env_var[0]==e0:\n print 'Setting %s=%s' % (env_var[0],e0)\n env_var = e0\n if env_var and os.environ.has_key(env_var):\n d = os.environ[env_var]\n if d=='None':\n print 'Disabled',self.__class__.__name__,'(%s is None)' \\\n % (self.dir_env_var)\n return []\n if os.path.isfile(d):\n dirs = [os.path.dirname(d)] + dirs\n l = getattr(self,'_lib_names',[])\n if len(l)==1:\n b = os.path.basename(d)\n b = os.path.splitext(b)[0]\n if b[:3]=='lib':\n print 'Replacing _lib_names[0]==%r with %r' \\\n % (self._lib_names[0], b[3:])\n self._lib_names[0] = b[3:]\n else:\n ds = d.split(os.pathsep)\n ds2 = []\n for d in ds:\n if os.path.isdir(d):\n ds2.append(d)\n for dd in ['include','lib']:\n d1 = os.path.join(d,dd)\n if os.path.isdir(d1):\n ds2.append(d1)\n dirs = ds2 + dirs\n default_dirs = self.cp.get('DEFAULT', key).split(os.pathsep)\n dirs.extend(default_dirs)\n ret = []\n [ret.append(d) for d in dirs if os.path.isdir(d) and d not in ret]\n if self.verbosity>1:\n print '(',key,'=',':'.join(ret),')'\n return ret\n\n def get_lib_dirs(self, key='library_dirs'):\n return self.get_paths(self.section, key)\n\n def get_include_dirs(self, key='include_dirs'):\n return self.get_paths(self.section, key)\n\n def get_src_dirs(self, key='src_dirs'):\n return self.get_paths(self.section, key)\n\n def get_libs(self, key, default):\n try:\n libs = self.cp.get(self.section, key)\n except ConfigParser.NoOptionError:\n if not default:\n return []\n if type(default) is type(''):\n return [default]\n return default\n return [b for b in [a.strip() for a in libs.split(',')] if b]\n\n def get_libraries(self, key='libraries'):\n return self.get_libs(key,'')\n\n def check_libs(self,lib_dir,libs,opt_libs =[]):\n \"\"\" If static or shared libraries are available then return\n their info dictionary. \"\"\"\n if self.search_static_first:\n exts = ['.a',so_ext]\n else:\n exts = [so_ext,'.a']\n if sys.platform=='cygwin':\n exts.append('.dll.a')\n for ext in exts:\n info = self._check_libs(lib_dir,libs,opt_libs,ext)\n if info is not None: return info\n return\n\n def _lib_list(self, lib_dir, libs, ext):\n assert type(lib_dir) is type('')\n liblist = []\n for l in libs:\n p = self.combine_paths(lib_dir, 'lib'+l+ext)\n if p:\n assert len(p)==1\n liblist.append(p[0])\n return liblist\n\n def _extract_lib_names(self,libs):\n return [os.path.splitext(os.path.basename(p))[0][3:] \\\n for p in libs]\n\n def _check_libs(self,lib_dir,libs, opt_libs, ext):\n found_libs = self._lib_list(lib_dir, libs, ext)\n if len(found_libs) == len(libs):\n found_libs = self._extract_lib_names(found_libs)\n info = {'libraries' : found_libs, 'library_dirs' : [lib_dir]}\n opt_found_libs = self._lib_list(lib_dir, opt_libs, ext)\n if len(opt_found_libs) == len(opt_libs):\n opt_found_libs = self._extract_lib_names(opt_found_libs)\n info['libraries'].extend(opt_found_libs)\n return info\n\n def combine_paths(self,*args):\n return combine_paths(*args,**{'verbosity':self.verbosity})\n\nclass fftw_info(system_info):\n section = 'fftw'\n dir_env_var = 'FFTW'\n libs = ['rfftw', 'fftw']\n includes = ['fftw.h','rfftw.h']\n macros = [('SCIPY_FFTW_H',None)]\n notfounderror = FFTWNotFoundError\n\n def __init__(self):\n system_info.__init__(self)\n\n def calc_info(self):\n lib_dirs = self.get_lib_dirs()\n incl_dirs = self.get_include_dirs()\n incl_dir = None\n libs = self.get_libs(self.section+'_libs', self.libs)\n info = None\n for d in lib_dirs:\n r = self.check_libs(d,libs)\n if r is not None:\n info = r\n break\n if info is not None:\n flag = 0\n for d in incl_dirs:\n if len(self.combine_paths(d,self.includes))==2:\n dict_append(info,include_dirs=[d])\n flag = 1\n incl_dirs = [d]\n incl_dir = d\n break\n if flag:\n dict_append(info,define_macros=self.macros)\n else:\n info = None\n if info is not None:\n self.set_info(**info)\n\nclass dfftw_info(fftw_info):\n section = 'fftw'\n dir_env_var = 'FFTW'\n libs = ['drfftw','dfftw']\n includes = ['dfftw.h','drfftw.h']\n macros = [('SCIPY_DFFTW_H',None)]\n\nclass sfftw_info(fftw_info):\n section = 'fftw'\n dir_env_var = 'FFTW'\n libs = ['srfftw','sfftw']\n includes = ['sfftw.h','srfftw.h']\n macros = [('SCIPY_SFFTW_H',None)]\n\nclass fftw_threads_info(fftw_info):\n section = 'fftw'\n dir_env_var = 'FFTW'\n libs = ['rfftw_threads','fftw_threads']\n includes = ['fftw_threads.h','rfftw_threads.h']\n macros = [('SCIPY_FFTW_THREADS_H',None)]\n\nclass dfftw_threads_info(fftw_info):\n section = 'fftw'\n dir_env_var = 'FFTW'\n libs = ['drfftw_threads','dfftw_threads']\n includes = ['dfftw_threads.h','drfftw_threads.h']\n macros = [('SCIPY_DFFTW_THREADS_H',None)]\n\nclass sfftw_threads_info(fftw_info):\n section = 'fftw'\n dir_env_var = 'FFTW'\n libs = ['srfftw_threads','sfftw_threads']\n includes = ['sfftw_threads.h','srfftw_threads.h']\n macros = [('SCIPY_SFFTW_THREADS_H',None)]\n\nclass djbfft_info(system_info):\n section = 'djbfft'\n dir_env_var = 'DJBFFT'\n notfounderror = DJBFFTNotFoundError\n\n def get_paths(self, section, key):\n pre_dirs = system_info.get_paths(self, section, key)\n dirs = []\n for d in pre_dirs:\n dirs.extend(self.combine_paths(d,['djbfft'])+[d])\n return [ d for d in dirs if os.path.isdir(d) ]\n\n def calc_info(self):\n lib_dirs = self.get_lib_dirs()\n incl_dirs = self.get_include_dirs()\n info = None\n for d in lib_dirs:\n p = self.combine_paths (d,['djbfft.a'])\n if p:\n info = {'extra_objects':p}\n break\n p = self.combine_paths (d,['libdjbfft.a'])\n if p:\n info = {'libraries':['djbfft'],'library_dirs':[d]}\n break\n if info is None:\n return\n for d in incl_dirs:\n if len(self.combine_paths(d,['fftc8.h','fftfreq.h']))==2:\n dict_append(info,include_dirs=[d],\n define_macros=[('SCIPY_DJBFFT_H',None)])\n self.set_info(**info)\n return\n return\n\nclass atlas_info(system_info):\n section = 'atlas'\n dir_env_var = 'ATLAS'\n _lib_names = ['f77blas','cblas']\n if sys.platform[:7]=='freebsd':\n _lib_atlas = ['atlas_r']\n _lib_lapack = ['alapack_r']\n else:\n _lib_atlas = ['atlas']\n _lib_lapack = ['lapack']\n\n notfounderror = AtlasNotFoundError\n\n def get_paths(self, section, key):\n pre_dirs = system_info.get_paths(self, section, key)\n dirs = []\n for d in pre_dirs:\n dirs.extend(self.combine_paths(d,['atlas*','ATLAS*',\n 'sse','3dnow','sse2'])+[d])\n return [ d for d in dirs if os.path.isdir(d) ]\n\n def calc_info(self):\n lib_dirs = self.get_lib_dirs()\n info = {}\n atlas_libs = self.get_libs('atlas_libs',\n self._lib_names + self._lib_atlas)\n lapack_libs = self.get_libs('lapack_libs',self._lib_lapack)\n atlas = None\n lapack = None\n atlas_1 = None\n for d in lib_dirs:\n atlas = self.check_libs(d,atlas_libs,[])\n lapack_atlas = self.check_libs(d,['lapack_atlas'],[])\n if atlas is not None:\n lib_dirs2 = self.combine_paths(d,['atlas*','ATLAS*'])+[d]\n for d2 in lib_dirs2:\n lapack = self.check_libs(d2,lapack_libs,[])\n if lapack is not None:\n break\n else:\n lapack = None\n if lapack is not None:\n break\n if atlas:\n atlas_1 = atlas\n print self.__class__\n if atlas is None:\n atlas = atlas_1\n if atlas is None:\n return\n include_dirs = self.get_include_dirs()\n h = (self.combine_paths(lib_dirs+include_dirs,'cblas.h') or [None])[0]\n if h:\n h = os.path.dirname(h)\n dict_append(info,include_dirs=[h])\n info['language'] = 'c'\n if lapack is not None:\n dict_append(info,**lapack)\n dict_append(info,**atlas)\n elif 'lapack_atlas' in atlas['libraries']:\n dict_append(info,**atlas)\n dict_append(info,define_macros=[('ATLAS_WITH_LAPACK_ATLAS',None)])\n self.set_info(**info)\n return\n else:\n dict_append(info,**atlas)\n dict_append(info,define_macros=[('ATLAS_WITHOUT_LAPACK',None)])\n message = \"\"\"\n*********************************************************************\n Could not find lapack library within the ATLAS installation.\n*********************************************************************\n\"\"\"\n warnings.warn(message)\n self.set_info(**info)\n return\n \n # Check if lapack library is complete, only warn if it is not.\n lapack_dir = lapack['library_dirs'][0]\n lapack_name = lapack['libraries'][0]\n lapack_lib = None\n for e in ['.a',so_ext]:\n fn = os.path.join(lapack_dir,'lib'+lapack_name+e)\n if os.path.exists(fn):\n lapack_lib = fn\n break\n if lapack_lib is not None:\n sz = os.stat(lapack_lib)[6]\n if sz <= 4000*1024:\n message = \"\"\"\n*********************************************************************\n Lapack library (from ATLAS) is probably incomplete:\n size of %s is %sk (expected >4000k)\n\n Follow the instructions in the KNOWN PROBLEMS section of the file\n scipy/INSTALL.txt.\n*********************************************************************\n\"\"\" % (lapack_lib,sz/1024)\n warnings.warn(message)\n else:\n info['language'] = 'f77'\n\n self.set_info(**info)\n\nclass atlas_blas_info(atlas_info):\n _lib_names = ['f77blas','cblas']\n\n def calc_info(self):\n lib_dirs = self.get_lib_dirs()\n info = {}\n atlas_libs = self.get_libs('atlas_libs',\n self._lib_names + self._lib_atlas)\n atlas = None\n for d in lib_dirs:\n atlas = self.check_libs(d,atlas_libs,[])\n if atlas is not None:\n break\n if atlas is None:\n return\n include_dirs = self.get_include_dirs()\n h = (self.combine_paths(lib_dirs+include_dirs,'cblas.h') or [None])[0]\n if h:\n h = os.path.dirname(h)\n dict_append(info,include_dirs=[h])\n info['language'] = 'c'\n\n dict_append(info,**atlas)\n\n self.set_info(**info)\n return\n\n\nclass atlas_threads_info(atlas_info):\n dir_env_var = ['PTATLAS','ATLAS']\n _lib_names = ['ptf77blas','ptcblas']\n\nclass atlas_blas_threads_info(atlas_blas_info):\n dir_env_var = ['PTATLAS','ATLAS']\n _lib_names = ['ptf77blas','ptcblas']\n\nclass lapack_atlas_info(atlas_info):\n _lib_names = ['lapack_atlas'] + atlas_info._lib_names\n\nclass lapack_atlas_threads_info(atlas_threads_info):\n _lib_names = ['lapack_atlas'] + atlas_threads_info._lib_names\n\nclass lapack_info(system_info):\n section = 'lapack'\n dir_env_var = 'LAPACK'\n _lib_names = ['lapack']\n notfounderror = LapackNotFoundError\n\n def calc_info(self):\n lib_dirs = self.get_lib_dirs()\n\n lapack_libs = self.get_libs('lapack_libs', self._lib_names)\n for d in lib_dirs:\n lapack = self.check_libs(d,lapack_libs,[])\n if lapack is not None:\n info = lapack \n break\n else:\n return\n info['language'] = 'f77'\n self.set_info(**info)\n\nclass lapack_src_info(system_info):\n section = 'lapack_src'\n dir_env_var = 'LAPACK_SRC'\n notfounderror = LapackSrcNotFoundError\n\n def get_paths(self, section, key):\n pre_dirs = system_info.get_paths(self, section, key)\n dirs = []\n for d in pre_dirs:\n dirs.extend([d] + self.combine_paths(d,['LAPACK*/SRC','SRC']))\n return [ d for d in dirs if os.path.isdir(d) ]\n\n def calc_info(self):\n src_dirs = self.get_src_dirs()\n src_dir = ''\n for d in src_dirs:\n if os.path.isfile(os.path.join(d,'dgesv.f')):\n src_dir = d\n break\n if not src_dir:\n #XXX: Get sources from netlib. May be ask first.\n return\n # The following is extracted from LAPACK-3.0/SRC/Makefile\n allaux='''\n ilaenv ieeeck lsame lsamen xerbla\n ''' # *.f\n laux = '''\n bdsdc bdsqr disna labad lacpy ladiv lae2 laebz laed0 laed1\n laed2 laed3 laed4 laed5 laed6 laed7 laed8 laed9 laeda laev2\n lagtf lagts lamch lamrg lanst lapy2 lapy3 larnv larrb larre\n larrf lartg laruv las2 lascl lasd0 lasd1 lasd2 lasd3 lasd4\n lasd5 lasd6 lasd7 lasd8 lasd9 lasda lasdq lasdt laset lasq1\n lasq2 lasq3 lasq4 lasq5 lasq6 lasr lasrt lassq lasv2 pttrf\n stebz stedc steqr sterf\n ''' # [s|d]*.f\n lasrc = '''\n gbbrd gbcon gbequ gbrfs gbsv gbsvx gbtf2 gbtrf gbtrs gebak\n gebal gebd2 gebrd gecon geequ gees geesx geev geevx gegs gegv\n gehd2 gehrd gelq2 gelqf gels gelsd gelss gelsx gelsy geql2\n geqlf geqp3 geqpf geqr2 geqrf gerfs gerq2 gerqf gesc2 gesdd\n gesv gesvd gesvx getc2 getf2 getrf getri getrs ggbak ggbal\n gges ggesx ggev ggevx ggglm gghrd gglse ggqrf ggrqf ggsvd\n ggsvp gtcon gtrfs gtsv gtsvx gttrf gttrs gtts2 hgeqz hsein\n hseqr labrd lacon laein lags2 lagtm lahqr lahrd laic1 lals0\n lalsa lalsd langb lange langt lanhs lansb lansp lansy lantb\n lantp lantr lapll lapmt laqgb laqge laqp2 laqps laqsb laqsp\n laqsy lar1v lar2v larf larfb larfg larft larfx largv larrv\n lartv larz larzb larzt laswp lasyf latbs latdf latps latrd\n latrs latrz latzm lauu2 lauum pbcon pbequ pbrfs pbstf pbsv\n pbsvx pbtf2 pbtrf pbtrs pocon poequ porfs posv posvx potf2\n potrf potri potrs ppcon ppequ pprfs ppsv ppsvx pptrf pptri\n pptrs ptcon pteqr ptrfs ptsv ptsvx pttrs ptts2 spcon sprfs\n spsv spsvx sptrf sptri sptrs stegr stein sycon syrfs sysv\n sysvx sytf2 sytrf sytri sytrs tbcon tbrfs tbtrs tgevc tgex2\n tgexc tgsen tgsja tgsna tgsy2 tgsyl tpcon tprfs tptri tptrs\n trcon trevc trexc trrfs trsen trsna trsyl trti2 trtri trtrs\n tzrqf tzrzf\n ''' # [s|c|d|z]*.f\n sd_lasrc = '''\n laexc lag2 lagv2 laln2 lanv2 laqtr lasy2 opgtr opmtr org2l\n org2r orgbr orghr orgl2 orglq orgql orgqr orgr2 orgrq orgtr\n orm2l orm2r ormbr ormhr orml2 ormlq ormql ormqr ormr2 ormr3\n ormrq ormrz ormtr rscl sbev sbevd sbevx sbgst sbgv sbgvd sbgvx\n sbtrd spev spevd spevx spgst spgv spgvd spgvx sptrd stev stevd\n stevr stevx syev syevd syevr syevx sygs2 sygst sygv sygvd\n sygvx sytd2 sytrd\n ''' # [s|d]*.f\n cz_lasrc = '''\n bdsqr hbev hbevd hbevx hbgst hbgv hbgvd hbgvx hbtrd hecon heev\n heevd heevr heevx hegs2 hegst hegv hegvd hegvx herfs hesv\n hesvx hetd2 hetf2 hetrd hetrf hetri hetrs hpcon hpev hpevd\n hpevx hpgst hpgv hpgvd hpgvx hprfs hpsv hpsvx hptrd hptrf\n hptri hptrs lacgv lacp2 lacpy lacrm lacrt ladiv laed0 laed7\n laed8 laesy laev2 lahef lanhb lanhe lanhp lanht laqhb laqhe\n laqhp larcm larnv lartg lascl laset lasr lassq pttrf rot spmv\n spr stedc steqr symv syr ung2l ung2r ungbr unghr ungl2 unglq\n ungql ungqr ungr2 ungrq ungtr unm2l unm2r unmbr unmhr unml2\n unmlq unmql unmqr unmr2 unmr3 unmrq unmrz unmtr upgtr upmtr\n ''' # [c|z]*.f\n #######\n sclaux = laux + ' econd ' # s*.f\n dzlaux = laux + ' secnd ' # d*.f\n slasrc = lasrc + sd_lasrc # s*.f\n dlasrc = lasrc + sd_lasrc # d*.f\n clasrc = lasrc + cz_lasrc + ' srot srscl ' # c*.f\n zlasrc = lasrc + cz_lasrc + ' drot drscl ' # z*.f\n oclasrc = ' icmax1 scsum1 ' # *.f\n ozlasrc = ' izmax1 dzsum1 ' # *.f\n sources = ['s%s.f'%f for f in (sclaux+slasrc).split()] \\\n + ['d%s.f'%f for f in (dzlaux+dlasrc).split()] \\\n + ['c%s.f'%f for f in (clasrc).split()] \\\n + ['z%s.f'%f for f in (zlasrc).split()] \\\n + ['%s.f'%f for f in (allaux+oclasrc+ozlasrc).split()]\n sources = [os.path.join(src_dir,f) for f in sources]\n #XXX: should we check here actual existence of source files?\n info = {'sources':sources,'language':'f77'}\n self.set_info(**info)\n\natlas_version_c_text = r'''\n/* This file is generated from scipy_distutils/system_info.py */\n#ifdef __CPLUSPLUS__\nextern \"C\" {\n#endif\n#include \"Python.h\"\nstatic PyMethodDef module_methods[] = { {NULL,NULL} };\nDL_EXPORT(void) initatlas_version(void) {\n void ATL_buildinfo(void);\n ATL_buildinfo();\n Py_InitModule(\"atlas_version\", module_methods);\n}\n#ifdef __CPLUSCPLUS__\n}\n#endif\n'''\n\ndef get_atlas_version(**config):\n from core import Extension, setup\n from misc_util import get_build_temp\n import log\n magic = hex(hash(`config`))\n def atlas_version_c(extension, build_dir,magic=magic):\n source = os.path.join(build_dir,'atlas_version_%s.c' % (magic))\n if os.path.isfile(source):\n from distutils.dep_util import newer\n if newer(source,__file__):\n return source\n f = open(source,'w')\n f.write(atlas_version_c_text)\n f.close()\n return source\n ext = Extension('atlas_version',\n sources=[atlas_version_c],\n **config)\n extra_args = ['--build-lib',get_build_temp()]\n for a in sys.argv:\n if re.match('[-][-]compiler[=]',a):\n extra_args.append(a)\n try:\n dist = setup(ext_modules=[ext],\n script_name = 'get_atlas_version',\n script_args = ['build_src','build_ext']+extra_args)\n except Exception,msg:\n print \"##### msg: %s\" % msg\n if not msg:\n msg = \"Unknown Exception\"\n log.warn(msg)\n return None\n\n from distutils.sysconfig import get_config_var\n so_ext = get_config_var('SO')\n build_ext = dist.get_command_obj('build_ext')\n target = os.path.join(build_ext.build_lib,'atlas_version'+so_ext)\n from exec_command import exec_command,get_pythonexe\n cmd = [get_pythonexe(),'-c',\n '\"import imp;imp.load_dynamic(\\\\\"atlas_version\\\\\",\\\\\"%s\\\\\")\"'\\\n % (os.path.basename(target))]\n s,o = exec_command(cmd,execute_in=os.path.dirname(target),use_tee=0)\n atlas_version = None\n if not s:\n m = re.search(r'ATLAS version (?P\\d+[.]\\d+[.]\\d+)',o)\n if m:\n atlas_version = m.group('version')\n if atlas_version is None:\n if re.search(r'undefined symbol: ATL_buildinfo',o,re.M):\n atlas_version = '3.2.1_pre3.3.6'\n else:\n print 'Command:',' '.join(cmd)\n print 'Status:',s\n print 'Output:',o\n return atlas_version\n\n\nclass lapack_opt_info(system_info):\n \n def calc_info(self):\n\n if sys.platform=='darwin' and not os.environ.get('ATLAS',None):\n args = []\n link_args = []\n if os.path.exists('/System/Library/Frameworks/Accelerate.framework/'):\n args.extend(['-faltivec','-framework','Accelerate'])\n link_args.extend(['-Wl,-framework','-Wl,Accelerate'])\n elif os.path.exists('/System/Library/Frameworks/vecLib.framework/'):\n args.extend(['-faltivec','-framework','vecLib'])\n link_args.extend(['-Wl,-framework','-Wl,vecLib'])\n if args:\n self.set_info(extra_compile_args=args,\n extra_link_args=link_args,\n define_macros=[('NO_ATLAS_INFO',3)])\n return\n\n atlas_info = get_info('atlas_threads')\n if not atlas_info:\n atlas_info = get_info('atlas')\n #atlas_info = {} ## uncomment for testing\n atlas_version = None\n need_lapack = 0\n need_blas = 0\n info = {}\n if atlas_info:\n version_info = atlas_info.copy()\n atlas_version = get_atlas_version(**version_info)\n if not atlas_info.has_key('define_macros'):\n atlas_info['define_macros'] = []\n if atlas_version is None:\n atlas_info['define_macros'].append(('NO_ATLAS_INFO',2))\n else:\n atlas_info['define_macros'].append(('ATLAS_INFO',\n '\"\\\\\"%s\\\\\"\"' % atlas_version))\n\t\tif atlas_version=='3.2.1_pre3.3.6':\n\t\t atlas_info['define_macros'].append(('NO_ATLAS_INFO',4))\n l = atlas_info.get('define_macros',[])\n if ('ATLAS_WITH_LAPACK_ATLAS',None) in l \\\n or ('ATLAS_WITHOUT_LAPACK',None) in l:\n need_lapack = 1\n info = atlas_info\n else:\n warnings.warn(AtlasNotFoundError.__doc__)\n need_blas = 1\n need_lapack = 1\n dict_append(info,define_macros=[('NO_ATLAS_INFO',1)])\n\n if need_lapack:\n lapack_info = get_info('lapack')\n #lapack_info = {} ## uncomment for testing\n if lapack_info:\n dict_append(info,**lapack_info)\n else:\n warnings.warn(LapackNotFoundError.__doc__)\n lapack_src_info = get_info('lapack_src')\n if not lapack_src_info:\n warnings.warn(LapackSrcNotFoundError.__doc__)\n return\n dict_append(info,libraries=[('flapack_src',lapack_src_info)])\n\n if need_blas:\n blas_info = get_info('blas')\n #blas_info = {} ## uncomment for testing\n if blas_info:\n dict_append(info,**blas_info)\n else:\n warnings.warn(BlasNotFoundError.__doc__)\n blas_src_info = get_info('blas_src')\n if not blas_src_info:\n warnings.warn(BlasSrcNotFoundError.__doc__)\n return\n dict_append(info,libraries=[('fblas_src',blas_src_info)])\n\n self.set_info(**info)\n return\n\n\nclass blas_opt_info(system_info):\n \n def calc_info(self):\n\n if sys.platform=='darwin' and not os.environ.get('ATLAS',None):\n args = []\n link_args = []\n if os.path.exists('/System/Library/Frameworks/Accelerate.framework/'):\n args.extend(['-faltivec','-framework','Accelerate'])\n link_args.extend(['-Wl,-framework','-Wl,Accelerate'])\n elif os.path.exists('/System/Library/Frameworks/vecLib.framework/'):\n args.extend(['-faltivec','-framework','vecLib'])\n link_args.extend(['-Wl,-framework','-Wl,vecLib'])\n if args:\n self.set_info(extra_compile_args=args,\n extra_link_args=link_args,\n define_macros=[('NO_ATLAS_INFO',3)])\n return\n\n atlas_info = get_info('atlas_blas_threads')\n if not atlas_info:\n atlas_info = get_info('atlas_blas')\n atlas_version = None\n need_blas = 0\n info = {}\n if atlas_info:\n version_info = atlas_info.copy()\n atlas_version = get_atlas_version(**version_info)\n if not atlas_info.has_key('define_macros'):\n atlas_info['define_macros'] = []\n if atlas_version is None:\n atlas_info['define_macros'].append(('NO_ATLAS_INFO',2))\n else:\n atlas_info['define_macros'].append(('ATLAS_INFO',\n '\"\\\\\"%s\\\\\"\"' % atlas_version))\n info = atlas_info\n else:\n warnings.warn(AtlasNotFoundError.__doc__)\n need_blas = 1\n dict_append(info,define_macros=[('NO_ATLAS_INFO',1)])\n\n if need_blas:\n blas_info = get_info('blas')\n if blas_info:\n dict_append(info,**blas_info)\n else:\n warnings.warn(BlasNotFoundError.__doc__)\n blas_src_info = get_info('blas_src')\n if not blas_src_info:\n warnings.warn(BlasSrcNotFoundError.__doc__)\n return\n dict_append(info,libraries=[('fblas_src',blas_src_info)])\n\n self.set_info(**info)\n return\n\n\nclass blas_info(system_info):\n section = 'blas'\n dir_env_var = 'BLAS'\n _lib_names = ['blas']\n notfounderror = BlasNotFoundError\n\n def calc_info(self):\n lib_dirs = self.get_lib_dirs()\n\n blas_libs = self.get_libs('blas_libs', self._lib_names)\n for d in lib_dirs:\n blas = self.check_libs(d,blas_libs,[])\n if blas is not None:\n info = blas \n break\n else:\n return\n info['language'] = 'f77' # XXX: is it generally true?\n self.set_info(**info)\n\n\nclass blas_src_info(system_info):\n section = 'blas_src'\n dir_env_var = 'BLAS_SRC'\n notfounderror = BlasSrcNotFoundError\n\n def get_paths(self, section, key):\n pre_dirs = system_info.get_paths(self, section, key)\n dirs = []\n for d in pre_dirs:\n dirs.extend([d] + self.combine_paths(d,['blas']))\n return [ d for d in dirs if os.path.isdir(d) ]\n\n def calc_info(self):\n src_dirs = self.get_src_dirs()\n src_dir = ''\n for d in src_dirs:\n if os.path.isfile(os.path.join(d,'daxpy.f')):\n src_dir = d\n break\n if not src_dir:\n #XXX: Get sources from netlib. May be ask first.\n return\n blas1 = '''\n caxpy csscal dnrm2 dzasum saxpy srotg zdotc ccopy cswap drot\n dznrm2 scasum srotm zdotu cdotc dasum drotg icamax scnrm2\n srotmg zdrot cdotu daxpy drotm idamax scopy sscal zdscal crotg\n dcabs1 drotmg isamax sdot sswap zrotg cscal dcopy dscal izamax\n snrm2 zaxpy zscal csrot ddot dswap sasum srot zcopy zswap\n '''\n blas2 = '''\n cgbmv chpmv ctrsv dsymv dtrsv sspr2 strmv zhemv ztpmv cgemv\n chpr dgbmv dsyr lsame ssymv strsv zher ztpsv cgerc chpr2 dgemv\n dsyr2 sgbmv ssyr xerbla zher2 ztrmv cgeru ctbmv dger dtbmv\n sgemv ssyr2 zgbmv zhpmv ztrsv chbmv ctbsv dsbmv dtbsv sger\n stbmv zgemv zhpr chemv ctpmv dspmv dtpmv ssbmv stbsv zgerc\n zhpr2 cher ctpsv dspr dtpsv sspmv stpmv zgeru ztbmv cher2\n ctrmv dspr2 dtrmv sspr stpsv zhbmv ztbsv\n '''\n blas3 = '''\n cgemm csymm ctrsm dsyrk sgemm strmm zhemm zsyr2k chemm csyr2k\n dgemm dtrmm ssymm strsm zher2k zsyrk cher2k csyrk dsymm dtrsm\n ssyr2k zherk ztrmm cherk ctrmm dsyr2k ssyrk zgemm zsymm ztrsm\n '''\n sources = [os.path.join(src_dir,f+'.f') \\\n for f in (blas1+blas2+blas3).split()]\n #XXX: should we check here actual existence of source files?\n info = {'sources':sources,'language':'f77'}\n self.set_info(**info)\n\nclass x11_info(system_info):\n section = 'x11'\n notfounderror = X11NotFoundError\n\n def __init__(self):\n system_info.__init__(self,\n default_lib_dirs=default_x11_lib_dirs,\n default_include_dirs=default_x11_include_dirs)\n\n def calc_info(self):\n if sys.platform in ['win32']:\n return\n lib_dirs = self.get_lib_dirs()\n include_dirs = self.get_include_dirs()\n x11_libs = self.get_libs('x11_libs', ['X11'])\n for lib_dir in lib_dirs:\n info = self.check_libs(lib_dir, x11_libs, [])\n if info is not None:\n break\n else:\n return\n inc_dir = None\n for d in include_dirs:\n if self.combine_paths(d, 'X11/X.h'):\n inc_dir = d\n break\n if inc_dir is not None:\n dict_append(info, include_dirs=[inc_dir])\n self.set_info(**info)\n\nclass numpy_info(system_info):\n section = 'numpy'\n modulename = 'Numeric'\n notfounderror = NumericNotFoundError\n\n def __init__(self):\n from distutils.sysconfig import get_python_inc\n include_dirs = []\n try:\n module = __import__(self.modulename)\n prefix = []\n for name in module.__file__.split(os.sep):\n if name=='lib':\n break\n prefix.append(name)\n include_dirs.append(get_python_inc(prefix=os.sep.join(prefix)))\n except ImportError:\n pass\n py_incl_dir = get_python_inc()\n include_dirs.append(py_incl_dir)\n for d in default_include_dirs:\n d = os.path.join(d, os.path.basename(py_incl_dir))\n if d not in include_dirs:\n include_dirs.append(d)\n system_info.__init__(self,\n default_lib_dirs=[],\n default_include_dirs=include_dirs)\n\n def calc_info(self):\n try:\n module = __import__(self.modulename)\n except ImportError:\n return\n info = {}\n macros = [(self.modulename.upper()+'_VERSION',\n '\"\\\\\"%s\\\\\"\"' % (module.__version__))]\n## try:\n## macros.append(\n## (self.modulename.upper()+'_VERSION_HEX',\n## hex(vstr2hex(module.__version__))),\n## )\n## except Exception,msg:\n## print msg\n dict_append(info, define_macros = macros)\n include_dirs = self.get_include_dirs()\n inc_dir = None\n for d in include_dirs:\n if self.combine_paths(d,\n os.path.join(self.modulename,\n 'arrayobject.h')):\n inc_dir = d\n break\n if inc_dir is not None:\n dict_append(info, include_dirs=[inc_dir])\n if info:\n self.set_info(**info)\n return\n\nclass numarray_info(numpy_info):\n section = 'numarray'\n modulename = 'numarray'\n\nclass boost_python_info(system_info):\n section = 'boost_python'\n dir_env_var = 'BOOST'\n\n def get_paths(self, section, key):\n pre_dirs = system_info.get_paths(self, section, key)\n dirs = []\n for d in pre_dirs:\n dirs.extend([d] + self.combine_paths(d,['boost*']))\n return [ d for d in dirs if os.path.isdir(d) ]\n\n def calc_info(self):\n from distutils.sysconfig import get_python_inc\n src_dirs = self.get_src_dirs()\n src_dir = ''\n for d in src_dirs:\n if os.path.isfile(os.path.join(d,'libs','python','src','module.cpp')):\n src_dir = d\n break\n if not src_dir:\n return\n py_incl_dir = get_python_inc()\n srcs_dir = os.path.join(src_dir,'libs','python','src')\n bpl_srcs = glob(os.path.join(srcs_dir,'*.cpp'))\n bpl_srcs += glob(os.path.join(srcs_dir,'*','*.cpp'))\n info = {'libraries':[('boost_python_src',{'include_dirs':[src_dir,py_incl_dir],\n 'sources':bpl_srcs})],\n 'include_dirs':[src_dir],\n }\n if info:\n self.set_info(**info)\n return\n\nclass agg2_info(system_info):\n section = 'agg2'\n dir_env_var = 'AGG2'\n\n def get_paths(self, section, key):\n pre_dirs = system_info.get_paths(self, section, key)\n dirs = []\n for d in pre_dirs:\n dirs.extend([d] + self.combine_paths(d,['agg2*']))\n return [ d for d in dirs if os.path.isdir(d) ]\n\n def calc_info(self):\n src_dirs = self.get_src_dirs()\n src_dir = ''\n for d in src_dirs:\n if os.path.isfile(os.path.join(d,'src','agg_affine_matrix.cpp')):\n src_dir = d\n break\n if not src_dir:\n return\n if sys.platform=='win32':\n agg2_srcs = glob(os.path.join(src_dir,'src','platform','win32','agg_win32_bmp.cpp'))\n else:\n agg2_srcs = glob(os.path.join(src_dir,'src','*.cpp'))\n agg2_srcs += [os.path.join(src_dir,'src','platform','X11','agg_platform_support.cpp')]\n \n info = {'libraries':[('agg2_src',{'sources':agg2_srcs,\n 'include_dirs':[os.path.join(src_dir,'include')],\n })],\n 'include_dirs':[os.path.join(src_dir,'include')],\n }\n if info:\n self.set_info(**info)\n return\n\nclass _pkg_config_info(system_info):\n section = None\n config_env_var = 'PKG_CONFIG'\n default_config_exe = 'pkg-config'\n append_config_exe = ''\n version_macro_name = None\n release_macro_name = None\n version_flag = '--modversion'\n cflags_flag = '--cflags'\n\n def get_config_exe(self):\n if os.environ.has_key(self.config_env_var):\n return os.environ[self.config_env_var]\n return self.default_config_exe\n def get_config_output(self, config_exe, option):\n s,o = exec_command(config_exe+' '+self.append_config_exe+' '+option,use_tee=0)\n if not s:\n return o\n\n def calc_info(self):\n config_exe = find_executable(self.get_config_exe())\n if not os.path.isfile(config_exe):\n print 'File not found: %s. Cannot determine %s info.' \\\n % (config_exe, self.section)\n return\n info = {}\n macros = []\n libraries = []\n library_dirs = []\n include_dirs = []\n extra_link_args = []\n extra_compile_args = []\n version = self.get_config_output(config_exe,self.version_flag)\n if version:\n macros.append((self.__class__.__name__.split('.')[-1].upper(),\n '\"\\\\\"%s\\\\\"\"' % (version)))\n if self.version_macro_name:\n macros.append((self.version_macro_name+'_%s' % (version.replace('.','_')),None))\n if self.release_macro_name:\n release = self.get_config_output(config_exe,'--release')\n if release:\n macros.append((self.release_macro_name+'_%s' % (release.replace('.','_')),None))\n opts = self.get_config_output(config_exe,'--libs')\n if opts:\n for opt in opts.split():\n if opt[:2]=='-l':\n libraries.append(opt[2:])\n elif opt[:2]=='-L':\n library_dirs.append(opt[2:])\n else:\n extra_link_args.append(opt)\n opts = self.get_config_output(config_exe,self.cflags_flag)\n if opts:\n for opt in opts.split():\n if opt[:2]=='-I':\n include_dirs.append(opt[2:])\n elif opt[:2]=='-D':\n if '=' in opt:\n n,v = opt[2:].split('=')\n macros.append((n,v))\n else:\n macros.append((opt[2:],None))\n else:\n extra_compile_args.append(opt)\n if macros: dict_append(info, define_macros = macros)\n if libraries: dict_append(info, libraries = libraries)\n if library_dirs: dict_append(info, library_dirs = library_dirs)\n if include_dirs: dict_append(info, include_dirs = include_dirs)\n if extra_link_args: dict_append(info, extra_link_args = extra_link_args)\n if extra_compile_args: dict_append(info, extra_compile_args = extra_compile_args)\n if info:\n self.set_info(**info)\n return\n\nclass wx_info(_pkg_config_info):\n section = 'wx'\n config_env_var = 'WX_CONFIG'\n default_config_exe = 'wx-config'\n append_config_exe = ''\n version_macro_name = 'WX_VERSION'\n release_macro_name = 'WX_RELEASE'\n version_flag = '--version'\n cflags_flag = '--cxxflags'\n\nclass gdk_pixbuf_xlib_2_info(_pkg_config_info):\n section = 'gdk_pixbuf_xlib_2'\n append_config_exe = 'gdk-pixbuf-xlib-2.0'\n version_macro_name = 'GDK_PIXBUF_XLIB_VERSION'\n\nclass gdk_pixbuf_2_info(_pkg_config_info):\n section = 'gdk_pixbuf_2'\n append_config_exe = 'gdk-pixbuf-2.0'\n version_macro_name = 'GDK_PIXBUF_VERSION'\n\nclass gdk_x11_2_info(_pkg_config_info):\n section = 'gdk_x11_2'\n append_config_exe = 'gdk-x11-2.0'\n version_macro_name = 'GDK_X11_VERSION'\n\nclass gdk_2_info(_pkg_config_info):\n section = 'gdk_2'\n append_config_exe = 'gdk-2.0'\n version_macro_name = 'GDK_VERSION'\n\nclass gdk_info(_pkg_config_info):\n section = 'gdk'\n append_config_exe = 'gdk'\n version_macro_name = 'GDK_VERSION'\n\nclass gtkp_x11_2_info(_pkg_config_info):\n section = 'gtkp_x11_2'\n append_config_exe = 'gtk+-x11-2.0'\n version_macro_name = 'GTK_X11_VERSION'\n\n\nclass gtkp_2_info(_pkg_config_info):\n section = 'gtkp_2'\n append_config_exe = 'gtk+-2.0'\n version_macro_name = 'GTK_VERSION'\n\nclass xft_info(_pkg_config_info):\n section = 'xft'\n append_config_exe = 'xft'\n version_macro_name = 'XFT_VERSION'\n\nclass freetype2_info(_pkg_config_info):\n section = 'freetype2'\n append_config_exe = 'freetype2'\n version_macro_name = 'FREETYPE2_VERSION'\n\n## def vstr2hex(version):\n## bits = []\n## n = [24,16,8,4,0]\n## r = 0\n## for s in version.split('.'):\n## r |= int(s) << n[0]\n## del n[0]\n## return r\n\n#--------------------------------------------------------------------\n\ndef combine_paths(*args,**kws):\n \"\"\" Return a list of existing paths composed by all combinations of\n items from arguments.\n \"\"\"\n r = []\n for a in args:\n if not a: continue\n if type(a) is types.StringType:\n a = [a]\n r.append(a)\n args = r\n if not args: return []\n if len(args)==1:\n result = reduce(lambda a,b:a+b,map(glob,args[0]),[])\n elif len (args)==2:\n result = []\n for a0 in args[0]:\n for a1 in args[1]:\n result.extend(glob(os.path.join(a0,a1)))\n else:\n result = combine_paths(*(combine_paths(args[0],args[1])+args[2:]))\n verbosity = kws.get('verbosity',1)\n if verbosity>1 and result:\n print '(','paths:',','.join(result),')'\n return result\n\nlanguage_map = {'c':0,'c++':1,'f77':2,'f90':3}\ninv_language_map = {0:'c',1:'c++',2:'f77',3:'f90'}\ndef dict_append(d,**kws):\n languages = []\n for k,v in kws.items():\n if k=='language':\n languages.append(v)\n continue\n if d.has_key(k):\n if k in ['library_dirs','include_dirs','define_macros']:\n [d[k].append(vv) for vv in v if vv not in d[k]]\n else:\n d[k].extend(v)\n else:\n d[k] = v\n if languages:\n l = inv_language_map[max([language_map.get(l,0) for l in languages])]\n d['language'] = l\n return\n\ndef show_all():\n import system_info\n import pprint\n match_info = re.compile(r'.*?_info').match\n show_only = []\n for n in sys.argv[1:]:\n if n[-5:] != '_info':\n n = n + '_info'\n show_only.append(n)\n show_all = not show_only\n for n in filter(match_info,dir(system_info)):\n if n in ['system_info','get_info']: continue\n if not show_all:\n if n not in show_only: continue\n del show_only[show_only.index(n)]\n c = getattr(system_info,n)()\n c.verbosity = 2\n r = c.get_info()\n if show_only:\n print 'Info classes not defined:',','.join(show_only)\nif __name__ == \"__main__\":\n show_all()\n", "source_code_before": "#!/usr/bin/env python\n\"\"\"\nThis file defines a set of system_info classes for getting\ninformation about various resources (libraries, library directories,\ninclude directories, etc.) in the system. Currently, the following\nclasses are available:\n\n atlas_info\n atlas_threads_info\n atlas_blas_info\n atlas_blas_threads_info\n lapack_atlas_info\n blas_info\n lapack_info\n blas_opt_info # usage recommended\n lapack_opt_info # usage recommended\n fftw_info,dfftw_info,sfftw_info\n fftw_threads_info,dfftw_threads_info,sfftw_threads_info\n djbfft_info\n x11_info\n lapack_src_info\n blas_src_info\n numpy_info\n numarray_info\n boost_python_info\n agg2_info\n wx_info\n gdk_pixbuf_xlib_2_info\n gdk_pixbuf_2_info\n gdk_x11_2_info\n gtkp_x11_2_info\n gtkp_2_info\n xft_info\n freetype2_info\n\nUsage:\n info_dict = get_info()\n where is a string 'atlas','x11','fftw','lapack','blas',\n 'lapack_src', 'blas_src', etc. For a complete list of allowed names,\n see the definition of get_info() function below.\n\n Returned info_dict is a dictionary which is compatible with\n distutils.setup keyword arguments. If info_dict == {}, then the\n asked resource is not available (system_info could not find it).\n\n Several *_info classes specify an environment variable to specify\n the locations of software. When setting the corresponding environment\n variable to 'None' then the software will be ignored, even when it\n is available in system.\n\nGlobal parameters:\n system_info.search_static_first - search static libraries (.a)\n in precedence to shared ones (.so, .sl) if enabled.\n system_info.verbosity - output the results to stdout if enabled.\n\nThe file 'site.cfg' in the same directory as this module is read\nfor configuration options. The format is that used by ConfigParser (i.e.,\nWindows .INI style). The section DEFAULT has options that are the default\nfor each section. The available sections are fftw, atlas, and x11. Appropiate\ndefaults are used if nothing is specified.\n\nThe order of finding the locations of resources is the following:\n 1. environment variable\n 2. section in site.cfg\n 3. DEFAULT section in site.cfg\nOnly the first complete match is returned.\n\nExample:\n----------\n[DEFAULT]\nlibrary_dirs = /usr/lib:/usr/local/lib:/opt/lib\ninclude_dirs = /usr/include:/usr/local/include:/opt/include\nsrc_dirs = /usr/local/src:/opt/src\n# search static libraries (.a) in preference to shared ones (.so)\nsearch_static_first = 0\n\n[fftw]\nfftw_libs = rfftw, fftw\nfftw_opt_libs = rfftw_threaded, fftw_threaded\n# if the above aren't found, look for {s,d}fftw_libs and {s,d}fftw_opt_libs\n\n[atlas]\nlibrary_dirs = /usr/lib/3dnow:/usr/lib/3dnow/atlas\n# for overriding the names of the atlas libraries\natlas_libs = lapack, f77blas, cblas, atlas\n\n[x11]\nlibrary_dirs = /usr/X11R6/lib\ninclude_dirs = /usr/X11R6/include\n----------\n\nAuthors:\n Pearu Peterson , February 2002\n David M. Cooke , April 2002\n\nCopyright 2002 Pearu Peterson all rights reserved,\nPearu Peterson \nPermission to use, modify, and distribute this software is given under the \nterms of the SciPy (BSD style) license. See LICENSE.txt that came with\nthis distribution for specifics.\n\nNO WARRANTY IS EXPRESSED OR IMPLIED. USE AT YOUR OWN RISK.\n\"\"\"\n\n__revision__ = '$Id$'\n\nimport sys,os,re,types\nimport warnings\nfrom distutils.errors import DistutilsError\nfrom glob import glob\nimport ConfigParser\nfrom exec_command import find_executable, exec_command\n\nfrom distutils.sysconfig import get_config_vars\n\nif sys.platform == 'win32':\n default_lib_dirs = ['C:\\\\'] # probably not very helpful...\n default_include_dirs = []\n default_src_dirs = ['.']\n default_x11_lib_dirs = []\n default_x11_include_dirs = []\nelse:\n default_lib_dirs = ['/usr/local/lib', '/opt/lib', '/usr/lib',\n '/sw/lib']\n default_include_dirs = ['/usr/local/include',\n '/opt/include', '/usr/include',\n '/sw/include']\n default_src_dirs = ['.','/usr/local/src', '/opt/src','/sw/src']\n default_x11_lib_dirs = ['/usr/X11R6/lib','/usr/X11/lib','/usr/lib']\n default_x11_include_dirs = ['/usr/X11R6/include','/usr/X11/include',\n '/usr/include']\n\nif os.path.join(sys.prefix, 'lib') not in default_lib_dirs:\n default_lib_dirs.insert(0,os.path.join(sys.prefix, 'lib'))\n default_include_dirs.append(os.path.join(sys.prefix, 'include'))\n default_src_dirs.append(os.path.join(sys.prefix, 'src'))\n\ndefault_lib_dirs = filter(os.path.isdir, default_lib_dirs)\ndefault_include_dirs = filter(os.path.isdir, default_include_dirs)\ndefault_src_dirs = filter(os.path.isdir, default_src_dirs)\n\nso_ext = get_config_vars('SO')[0] or ''\n\ndef get_info(name,notfound_action=0):\n \"\"\"\n notfound_action:\n 0 - do nothing\n 1 - display warning message\n 2 - raise error\n \"\"\"\n cl = {'atlas':atlas_info, # use lapack_opt or blas_opt instead\n 'atlas_threads':atlas_threads_info, # ditto\n 'atlas_blas':atlas_blas_info,\n 'atlas_blas_threads':atlas_blas_threads_info,\n 'lapack_atlas':lapack_atlas_info, # use lapack_opt instead\n 'lapack_atlas_threads':lapack_atlas_threads_info, # ditto\n 'x11':x11_info,\n 'fftw':fftw_info,\n 'dfftw':dfftw_info,\n 'sfftw':sfftw_info,\n 'fftw_threads':fftw_threads_info,\n 'dfftw_threads':dfftw_threads_info,\n 'sfftw_threads':sfftw_threads_info,\n 'djbfft':djbfft_info,\n 'blas':blas_info, # use blas_opt instead\n 'lapack':lapack_info, # use lapack_opt instead\n 'lapack_src':lapack_src_info,\n 'blas_src':blas_src_info,\n 'numpy':numpy_info,\n 'numarray':numarray_info,\n 'lapack_opt':lapack_opt_info,\n 'blas_opt':blas_opt_info,\n 'boost_python':boost_python_info,\n 'agg2':agg2_info,\n 'wx':wx_info,\n 'gdk_pixbuf_xlib_2':gdk_pixbuf_xlib_2_info,\n 'gdk-pixbuf-xlib-2.0':gdk_pixbuf_xlib_2_info,\n 'gdk_pixbuf_2':gdk_pixbuf_2_info,\n 'gdk-pixbuf-2.0':gdk_pixbuf_2_info,\n 'gdk':gdk_info,\n 'gdk_2':gdk_2_info,\n 'gdk-2.0':gdk_2_info,\n 'gdk_x11_2':gdk_x11_2_info,\n 'gdk-x11-2.0':gdk_x11_2_info,\n 'gtkp_x11_2':gtkp_x11_2_info,\n 'gtk+-x11-2.0':gtkp_x11_2_info,\n 'gtkp_2':gtkp_2_info,\n 'gtk+-2.0':gtkp_2_info,\n 'xft':xft_info,\n 'freetype2':freetype2_info,\n }.get(name.lower(),system_info)\n return cl().get_info(notfound_action)\n\nclass NotFoundError(DistutilsError):\n \"\"\"Some third-party program or library is not found.\"\"\"\n\nclass AtlasNotFoundError(NotFoundError):\n \"\"\"\n Atlas (http://math-atlas.sourceforge.net/) libraries not found.\n Directories to search for the libraries can be specified in the\n scipy_distutils/site.cfg file (section [atlas]) or by setting\n the ATLAS environment variable.\"\"\"\n\nclass LapackNotFoundError(NotFoundError):\n \"\"\"\n Lapack (http://www.netlib.org/lapack/) libraries not found.\n Directories to search for the libraries can be specified in the\n scipy_distutils/site.cfg file (section [lapack]) or by setting\n the LAPACK environment variable.\"\"\"\n\nclass LapackSrcNotFoundError(LapackNotFoundError):\n \"\"\"\n Lapack (http://www.netlib.org/lapack/) sources not found.\n Directories to search for the sources can be specified in the\n scipy_distutils/site.cfg file (section [lapack_src]) or by setting\n the LAPACK_SRC environment variable.\"\"\"\n\nclass BlasNotFoundError(NotFoundError):\n \"\"\"\n Blas (http://www.netlib.org/blas/) libraries not found.\n Directories to search for the libraries can be specified in the\n scipy_distutils/site.cfg file (section [blas]) or by setting\n the BLAS environment variable.\"\"\"\n\nclass BlasSrcNotFoundError(BlasNotFoundError):\n \"\"\"\n Blas (http://www.netlib.org/blas/) sources not found.\n Directories to search for the sources can be specified in the\n scipy_distutils/site.cfg file (section [blas_src]) or by setting\n the BLAS_SRC environment variable.\"\"\"\n\nclass FFTWNotFoundError(NotFoundError):\n \"\"\"\n FFTW (http://www.fftw.org/) libraries not found.\n Directories to search for the libraries can be specified in the\n scipy_distutils/site.cfg file (section [fftw]) or by setting\n the FFTW environment variable.\"\"\"\n\nclass DJBFFTNotFoundError(NotFoundError):\n \"\"\"\n DJBFFT (http://cr.yp.to/djbfft.html) libraries not found.\n Directories to search for the libraries can be specified in the\n scipy_distutils/site.cfg file (section [djbfft]) or by setting\n the DJBFFT environment variable.\"\"\"\n\nclass F2pyNotFoundError(NotFoundError):\n \"\"\"\n f2py2e (http://cens.ioc.ee/projects/f2py2e/) module not found.\n Get it from above location, install it, and retry setup.py.\"\"\"\n\nclass NumericNotFoundError(NotFoundError):\n \"\"\"\n Numeric (http://www.numpy.org/) module not found.\n Get it from above location, install it, and retry setup.py.\"\"\"\n\nclass X11NotFoundError(NotFoundError):\n \"\"\"X11 libraries not found.\"\"\"\n\nclass system_info:\n\n \"\"\" get_info() is the only public method. Don't use others.\n \"\"\"\n section = 'DEFAULT'\n dir_env_var = None\n search_static_first = 0 # XXX: disabled by default, may disappear in\n # future unless it is proved to be useful.\n verbosity = 1\n saved_results = {}\n\n notfounderror = NotFoundError\n\n def __init__ (self,\n default_lib_dirs=default_lib_dirs,\n default_include_dirs=default_include_dirs,\n verbosity = 1,\n ):\n self.__class__.info = {}\n self.local_prefixes = []\n defaults = {}\n defaults['libraries'] = ''\n defaults['library_dirs'] = os.pathsep.join(default_lib_dirs)\n defaults['include_dirs'] = os.pathsep.join(default_include_dirs)\n defaults['src_dirs'] = os.pathsep.join(default_src_dirs)\n defaults['search_static_first'] = str(self.search_static_first)\n self.cp = ConfigParser.ConfigParser(defaults)\n try:\n __file__\n except NameError:\n __file__ = sys.argv[0]\n cf = os.path.join(os.path.split(os.path.abspath(__file__))[0],\n 'site.cfg')\n self.cp.read([cf])\n if not self.cp.has_section(self.section):\n self.cp.add_section(self.section)\n self.search_static_first = self.cp.getboolean(self.section,\n 'search_static_first')\n assert isinstance(self.search_static_first, type(0))\n\n def calc_libraries_info(self):\n libs = self.get_libraries()\n dirs = self.get_lib_dirs()\n info = {}\n for lib in libs:\n i = None\n for d in dirs:\n i = self.check_libs(d,[lib]) \n if i is not None:\n break\n if i is not None:\n dict_append(info,**i)\n else:\n print 'Library %s was not found. Ignoring' % (lib)\n return info\n\n def set_info(self,**info):\n if info: \n lib_info = self.calc_libraries_info()\n dict_append(info,**lib_info)\n self.saved_results[self.__class__.__name__] = info\n\n def has_info(self):\n return self.saved_results.has_key(self.__class__.__name__)\n\n def get_info(self,notfound_action=0):\n \"\"\" Return a dictonary with items that are compatible\n with scipy_distutils.setup keyword arguments.\n \"\"\"\n flag = 0\n if not self.has_info():\n flag = 1\n if self.verbosity>0:\n print self.__class__.__name__ + ':'\n if hasattr(self, 'calc_info'):\n self.calc_info()\n if notfound_action:\n if not self.has_info():\n if notfound_action==1:\n warnings.warn(self.notfounderror.__doc__)\n elif notfound_action==2:\n raise self.notfounderror,self.notfounderror.__doc__\n else:\n raise ValueError,`notfound_action`\n\n if self.verbosity>0:\n if not self.has_info():\n print ' NOT AVAILABLE'\n self.set_info()\n else:\n print ' FOUND:'\n \n res = self.saved_results.get(self.__class__.__name__)\n if self.verbosity>0 and flag:\n for k,v in res.items():\n v = str(v)\n if k=='sources' and len(v)>200: v = v[:60]+' ...\\n... '+v[-60:]\n print ' %s = %s'%(k,v)\n print\n \n return res\n\n def get_paths(self, section, key):\n dirs = self.cp.get(section, key).split(os.pathsep)\n env_var = self.dir_env_var\n if env_var:\n if type(env_var) is type([]):\n e0 = env_var[-1]\n for e in env_var:\n if os.environ.has_key(e):\n e0 = e\n break\n if not env_var[0]==e0:\n print 'Setting %s=%s' % (env_var[0],e0)\n env_var = e0\n if env_var and os.environ.has_key(env_var):\n d = os.environ[env_var]\n if d=='None':\n print 'Disabled',self.__class__.__name__,'(%s is None)' \\\n % (self.dir_env_var)\n return []\n if os.path.isfile(d):\n dirs = [os.path.dirname(d)] + dirs\n l = getattr(self,'_lib_names',[])\n if len(l)==1:\n b = os.path.basename(d)\n b = os.path.splitext(b)[0]\n if b[:3]=='lib':\n print 'Replacing _lib_names[0]==%r with %r' \\\n % (self._lib_names[0], b[3:])\n self._lib_names[0] = b[3:]\n else:\n ds = d.split(os.pathsep)\n ds2 = []\n for d in ds:\n if os.path.isdir(d):\n ds2.append(d)\n for dd in ['include','lib']:\n d1 = os.path.join(d,dd)\n if os.path.isdir(d1):\n ds2.append(d1)\n dirs = ds2 + dirs\n default_dirs = self.cp.get('DEFAULT', key).split(os.pathsep)\n dirs.extend(default_dirs)\n ret = []\n [ret.append(d) for d in dirs if os.path.isdir(d) and d not in ret]\n if self.verbosity>1:\n print '(',key,'=',':'.join(ret),')'\n return ret\n\n def get_lib_dirs(self, key='library_dirs'):\n return self.get_paths(self.section, key)\n\n def get_include_dirs(self, key='include_dirs'):\n return self.get_paths(self.section, key)\n\n def get_src_dirs(self, key='src_dirs'):\n return self.get_paths(self.section, key)\n\n def get_libs(self, key, default):\n try:\n libs = self.cp.get(self.section, key)\n except ConfigParser.NoOptionError:\n if not default:\n return []\n if type(default) is type(''):\n return [default]\n return default\n return [b for b in [a.strip() for a in libs.split(',')] if b]\n\n def get_libraries(self, key='libraries'):\n return self.get_libs(key,'')\n\n def check_libs(self,lib_dir,libs,opt_libs =[]):\n \"\"\" If static or shared libraries are available then return\n their info dictionary. \"\"\"\n if self.search_static_first:\n exts = ['.a',so_ext]\n else:\n exts = [so_ext,'.a']\n if sys.platform=='cygwin':\n exts.append('.dll.a')\n for ext in exts:\n info = self._check_libs(lib_dir,libs,opt_libs,ext)\n if info is not None: return info\n return\n\n def _lib_list(self, lib_dir, libs, ext):\n assert type(lib_dir) is type('')\n liblist = []\n for l in libs:\n p = self.combine_paths(lib_dir, 'lib'+l+ext)\n if p:\n assert len(p)==1\n liblist.append(p[0])\n return liblist\n\n def _extract_lib_names(self,libs):\n return [os.path.splitext(os.path.basename(p))[0][3:] \\\n for p in libs]\n\n def _check_libs(self,lib_dir,libs, opt_libs, ext):\n found_libs = self._lib_list(lib_dir, libs, ext)\n if len(found_libs) == len(libs):\n found_libs = self._extract_lib_names(found_libs)\n info = {'libraries' : found_libs, 'library_dirs' : [lib_dir]}\n opt_found_libs = self._lib_list(lib_dir, opt_libs, ext)\n if len(opt_found_libs) == len(opt_libs):\n opt_found_libs = self._extract_lib_names(opt_found_libs)\n info['libraries'].extend(opt_found_libs)\n return info\n\n def combine_paths(self,*args):\n return combine_paths(*args,**{'verbosity':self.verbosity})\n\nclass fftw_info(system_info):\n section = 'fftw'\n dir_env_var = 'FFTW'\n libs = ['rfftw', 'fftw']\n includes = ['fftw.h','rfftw.h']\n macros = [('SCIPY_FFTW_H',None)]\n notfounderror = FFTWNotFoundError\n\n def __init__(self):\n system_info.__init__(self)\n\n def calc_info(self):\n lib_dirs = self.get_lib_dirs()\n incl_dirs = self.get_include_dirs()\n incl_dir = None\n libs = self.get_libs(self.section+'_libs', self.libs)\n info = None\n for d in lib_dirs:\n r = self.check_libs(d,libs)\n if r is not None:\n info = r\n break\n if info is not None:\n flag = 0\n for d in incl_dirs:\n if len(self.combine_paths(d,self.includes))==2:\n dict_append(info,include_dirs=[d])\n flag = 1\n incl_dirs = [d]\n incl_dir = d\n break\n if flag:\n dict_append(info,define_macros=self.macros)\n else:\n info = None\n if info is not None:\n self.set_info(**info)\n\nclass dfftw_info(fftw_info):\n section = 'fftw'\n dir_env_var = 'FFTW'\n libs = ['drfftw','dfftw']\n includes = ['dfftw.h','drfftw.h']\n macros = [('SCIPY_DFFTW_H',None)]\n\nclass sfftw_info(fftw_info):\n section = 'fftw'\n dir_env_var = 'FFTW'\n libs = ['srfftw','sfftw']\n includes = ['sfftw.h','srfftw.h']\n macros = [('SCIPY_SFFTW_H',None)]\n\nclass fftw_threads_info(fftw_info):\n section = 'fftw'\n dir_env_var = 'FFTW'\n libs = ['rfftw_threads','fftw_threads']\n includes = ['fftw_threads.h','rfftw_threads.h']\n macros = [('SCIPY_FFTW_THREADS_H',None)]\n\nclass dfftw_threads_info(fftw_info):\n section = 'fftw'\n dir_env_var = 'FFTW'\n libs = ['drfftw_threads','dfftw_threads']\n includes = ['dfftw_threads.h','drfftw_threads.h']\n macros = [('SCIPY_DFFTW_THREADS_H',None)]\n\nclass sfftw_threads_info(fftw_info):\n section = 'fftw'\n dir_env_var = 'FFTW'\n libs = ['srfftw_threads','sfftw_threads']\n includes = ['sfftw_threads.h','srfftw_threads.h']\n macros = [('SCIPY_SFFTW_THREADS_H',None)]\n\nclass djbfft_info(system_info):\n section = 'djbfft'\n dir_env_var = 'DJBFFT'\n notfounderror = DJBFFTNotFoundError\n\n def get_paths(self, section, key):\n pre_dirs = system_info.get_paths(self, section, key)\n dirs = []\n for d in pre_dirs:\n dirs.extend(self.combine_paths(d,['djbfft'])+[d])\n return [ d for d in dirs if os.path.isdir(d) ]\n\n def calc_info(self):\n lib_dirs = self.get_lib_dirs()\n incl_dirs = self.get_include_dirs()\n info = None\n for d in lib_dirs:\n p = self.combine_paths (d,['djbfft.a'])\n if p:\n info = {'extra_objects':p}\n break\n p = self.combine_paths (d,['libdjbfft.a'])\n if p:\n info = {'libraries':['djbfft'],'library_dirs':[d]}\n break\n if info is None:\n return\n for d in incl_dirs:\n if len(self.combine_paths(d,['fftc8.h','fftfreq.h']))==2:\n dict_append(info,include_dirs=[d],\n define_macros=[('SCIPY_DJBFFT_H',None)])\n self.set_info(**info)\n return\n return\n\nclass atlas_info(system_info):\n section = 'atlas'\n dir_env_var = 'ATLAS'\n _lib_names = ['f77blas','cblas']\n if sys.platform[:7]=='freebsd':\n _lib_atlas = ['atlas_r']\n _lib_lapack = ['alapack_r']\n else:\n _lib_atlas = ['atlas']\n _lib_lapack = ['lapack']\n\n notfounderror = AtlasNotFoundError\n\n def get_paths(self, section, key):\n pre_dirs = system_info.get_paths(self, section, key)\n dirs = []\n for d in pre_dirs:\n dirs.extend(self.combine_paths(d,['atlas*','ATLAS*',\n 'sse','3dnow','sse2'])+[d])\n return [ d for d in dirs if os.path.isdir(d) ]\n\n def calc_info(self):\n lib_dirs = self.get_lib_dirs()\n info = {}\n atlas_libs = self.get_libs('atlas_libs',\n self._lib_names + self._lib_atlas)\n lapack_libs = self.get_libs('lapack_libs',self._lib_lapack)\n atlas = None\n lapack = None\n atlas_1 = None\n for d in lib_dirs:\n atlas = self.check_libs(d,atlas_libs,[])\n lapack_atlas = self.check_libs(d,['lapack_atlas'],[])\n if atlas is not None:\n lib_dirs2 = self.combine_paths(d,['atlas*','ATLAS*'])+[d]\n for d2 in lib_dirs2:\n lapack = self.check_libs(d2,lapack_libs,[])\n if lapack is not None:\n break\n else:\n lapack = None\n if lapack is not None:\n break\n if atlas:\n atlas_1 = atlas\n print self.__class__\n if atlas is None:\n atlas = atlas_1\n if atlas is None:\n return\n include_dirs = self.get_include_dirs()\n h = (self.combine_paths(lib_dirs+include_dirs,'cblas.h') or [None])[0]\n if h:\n h = os.path.dirname(h)\n dict_append(info,include_dirs=[h])\n info['language'] = 'c'\n if lapack is not None:\n dict_append(info,**lapack)\n dict_append(info,**atlas)\n elif 'lapack_atlas' in atlas['libraries']:\n dict_append(info,**atlas)\n dict_append(info,define_macros=[('ATLAS_WITH_LAPACK_ATLAS',None)])\n self.set_info(**info)\n return\n else:\n dict_append(info,**atlas)\n dict_append(info,define_macros=[('ATLAS_WITHOUT_LAPACK',None)])\n message = \"\"\"\n*********************************************************************\n Could not find lapack library within the ATLAS installation.\n*********************************************************************\n\"\"\"\n warnings.warn(message)\n self.set_info(**info)\n return\n \n # Check if lapack library is complete, only warn if it is not.\n lapack_dir = lapack['library_dirs'][0]\n lapack_name = lapack['libraries'][0]\n lapack_lib = None\n for e in ['.a',so_ext]:\n fn = os.path.join(lapack_dir,'lib'+lapack_name+e)\n if os.path.exists(fn):\n lapack_lib = fn\n break\n if lapack_lib is not None:\n sz = os.stat(lapack_lib)[6]\n if sz <= 4000*1024:\n message = \"\"\"\n*********************************************************************\n Lapack library (from ATLAS) is probably incomplete:\n size of %s is %sk (expected >4000k)\n\n Follow the instructions in the KNOWN PROBLEMS section of the file\n scipy/INSTALL.txt.\n*********************************************************************\n\"\"\" % (lapack_lib,sz/1024)\n warnings.warn(message)\n else:\n info['language'] = 'f77'\n\n self.set_info(**info)\n\nclass atlas_blas_info(atlas_info):\n _lib_names = ['f77blas','cblas']\n\n def calc_info(self):\n lib_dirs = self.get_lib_dirs()\n info = {}\n atlas_libs = self.get_libs('atlas_libs',\n self._lib_names + self._lib_atlas)\n atlas = None\n for d in lib_dirs:\n atlas = self.check_libs(d,atlas_libs,[])\n if atlas is not None:\n break\n if atlas is None:\n return\n include_dirs = self.get_include_dirs()\n h = (self.combine_paths(lib_dirs+include_dirs,'cblas.h') or [None])[0]\n if h:\n h = os.path.dirname(h)\n dict_append(info,include_dirs=[h])\n info['language'] = 'c'\n\n dict_append(info,**atlas)\n\n self.set_info(**info)\n return\n\n\nclass atlas_threads_info(atlas_info):\n dir_env_var = ['PTATLAS','ATLAS']\n _lib_names = ['ptf77blas','ptcblas']\n\nclass atlas_blas_threads_info(atlas_blas_info):\n dir_env_var = ['PTATLAS','ATLAS']\n _lib_names = ['ptf77blas','ptcblas']\n\nclass lapack_atlas_info(atlas_info):\n _lib_names = ['lapack_atlas'] + atlas_info._lib_names\n\nclass lapack_atlas_threads_info(atlas_threads_info):\n _lib_names = ['lapack_atlas'] + atlas_threads_info._lib_names\n\nclass lapack_info(system_info):\n section = 'lapack'\n dir_env_var = 'LAPACK'\n _lib_names = ['lapack']\n notfounderror = LapackNotFoundError\n\n def calc_info(self):\n lib_dirs = self.get_lib_dirs()\n\n lapack_libs = self.get_libs('lapack_libs', self._lib_names)\n for d in lib_dirs:\n lapack = self.check_libs(d,lapack_libs,[])\n if lapack is not None:\n info = lapack \n break\n else:\n return\n info['language'] = 'f77'\n self.set_info(**info)\n\nclass lapack_src_info(system_info):\n section = 'lapack_src'\n dir_env_var = 'LAPACK_SRC'\n notfounderror = LapackSrcNotFoundError\n\n def get_paths(self, section, key):\n pre_dirs = system_info.get_paths(self, section, key)\n dirs = []\n for d in pre_dirs:\n dirs.extend([d] + self.combine_paths(d,['LAPACK*/SRC','SRC']))\n return [ d for d in dirs if os.path.isdir(d) ]\n\n def calc_info(self):\n src_dirs = self.get_src_dirs()\n src_dir = ''\n for d in src_dirs:\n if os.path.isfile(os.path.join(d,'dgesv.f')):\n src_dir = d\n break\n if not src_dir:\n #XXX: Get sources from netlib. May be ask first.\n return\n # The following is extracted from LAPACK-3.0/SRC/Makefile\n allaux='''\n ilaenv ieeeck lsame lsamen xerbla\n ''' # *.f\n laux = '''\n bdsdc bdsqr disna labad lacpy ladiv lae2 laebz laed0 laed1\n laed2 laed3 laed4 laed5 laed6 laed7 laed8 laed9 laeda laev2\n lagtf lagts lamch lamrg lanst lapy2 lapy3 larnv larrb larre\n larrf lartg laruv las2 lascl lasd0 lasd1 lasd2 lasd3 lasd4\n lasd5 lasd6 lasd7 lasd8 lasd9 lasda lasdq lasdt laset lasq1\n lasq2 lasq3 lasq4 lasq5 lasq6 lasr lasrt lassq lasv2 pttrf\n stebz stedc steqr sterf\n ''' # [s|d]*.f\n lasrc = '''\n gbbrd gbcon gbequ gbrfs gbsv gbsvx gbtf2 gbtrf gbtrs gebak\n gebal gebd2 gebrd gecon geequ gees geesx geev geevx gegs gegv\n gehd2 gehrd gelq2 gelqf gels gelsd gelss gelsx gelsy geql2\n geqlf geqp3 geqpf geqr2 geqrf gerfs gerq2 gerqf gesc2 gesdd\n gesv gesvd gesvx getc2 getf2 getrf getri getrs ggbak ggbal\n gges ggesx ggev ggevx ggglm gghrd gglse ggqrf ggrqf ggsvd\n ggsvp gtcon gtrfs gtsv gtsvx gttrf gttrs gtts2 hgeqz hsein\n hseqr labrd lacon laein lags2 lagtm lahqr lahrd laic1 lals0\n lalsa lalsd langb lange langt lanhs lansb lansp lansy lantb\n lantp lantr lapll lapmt laqgb laqge laqp2 laqps laqsb laqsp\n laqsy lar1v lar2v larf larfb larfg larft larfx largv larrv\n lartv larz larzb larzt laswp lasyf latbs latdf latps latrd\n latrs latrz latzm lauu2 lauum pbcon pbequ pbrfs pbstf pbsv\n pbsvx pbtf2 pbtrf pbtrs pocon poequ porfs posv posvx potf2\n potrf potri potrs ppcon ppequ pprfs ppsv ppsvx pptrf pptri\n pptrs ptcon pteqr ptrfs ptsv ptsvx pttrs ptts2 spcon sprfs\n spsv spsvx sptrf sptri sptrs stegr stein sycon syrfs sysv\n sysvx sytf2 sytrf sytri sytrs tbcon tbrfs tbtrs tgevc tgex2\n tgexc tgsen tgsja tgsna tgsy2 tgsyl tpcon tprfs tptri tptrs\n trcon trevc trexc trrfs trsen trsna trsyl trti2 trtri trtrs\n tzrqf tzrzf\n ''' # [s|c|d|z]*.f\n sd_lasrc = '''\n laexc lag2 lagv2 laln2 lanv2 laqtr lasy2 opgtr opmtr org2l\n org2r orgbr orghr orgl2 orglq orgql orgqr orgr2 orgrq orgtr\n orm2l orm2r ormbr ormhr orml2 ormlq ormql ormqr ormr2 ormr3\n ormrq ormrz ormtr rscl sbev sbevd sbevx sbgst sbgv sbgvd sbgvx\n sbtrd spev spevd spevx spgst spgv spgvd spgvx sptrd stev stevd\n stevr stevx syev syevd syevr syevx sygs2 sygst sygv sygvd\n sygvx sytd2 sytrd\n ''' # [s|d]*.f\n cz_lasrc = '''\n bdsqr hbev hbevd hbevx hbgst hbgv hbgvd hbgvx hbtrd hecon heev\n heevd heevr heevx hegs2 hegst hegv hegvd hegvx herfs hesv\n hesvx hetd2 hetf2 hetrd hetrf hetri hetrs hpcon hpev hpevd\n hpevx hpgst hpgv hpgvd hpgvx hprfs hpsv hpsvx hptrd hptrf\n hptri hptrs lacgv lacp2 lacpy lacrm lacrt ladiv laed0 laed7\n laed8 laesy laev2 lahef lanhb lanhe lanhp lanht laqhb laqhe\n laqhp larcm larnv lartg lascl laset lasr lassq pttrf rot spmv\n spr stedc steqr symv syr ung2l ung2r ungbr unghr ungl2 unglq\n ungql ungqr ungr2 ungrq ungtr unm2l unm2r unmbr unmhr unml2\n unmlq unmql unmqr unmr2 unmr3 unmrq unmrz unmtr upgtr upmtr\n ''' # [c|z]*.f\n #######\n sclaux = laux + ' econd ' # s*.f\n dzlaux = laux + ' secnd ' # d*.f\n slasrc = lasrc + sd_lasrc # s*.f\n dlasrc = lasrc + sd_lasrc # d*.f\n clasrc = lasrc + cz_lasrc + ' srot srscl ' # c*.f\n zlasrc = lasrc + cz_lasrc + ' drot drscl ' # z*.f\n oclasrc = ' icmax1 scsum1 ' # *.f\n ozlasrc = ' izmax1 dzsum1 ' # *.f\n sources = ['s%s.f'%f for f in (sclaux+slasrc).split()] \\\n + ['d%s.f'%f for f in (dzlaux+dlasrc).split()] \\\n + ['c%s.f'%f for f in (clasrc).split()] \\\n + ['z%s.f'%f for f in (zlasrc).split()] \\\n + ['%s.f'%f for f in (allaux+oclasrc+ozlasrc).split()]\n sources = [os.path.join(src_dir,f) for f in sources]\n #XXX: should we check here actual existence of source files?\n info = {'sources':sources,'language':'f77'}\n self.set_info(**info)\n\natlas_version_c_text = r'''\n/* This file is generated from scipy_distutils/system_info.py */\n#ifdef __CPLUSPLUS__\nextern \"C\" {\n#endif\n#include \"Python.h\"\nstatic PyMethodDef module_methods[] = { {NULL,NULL} };\nDL_EXPORT(void) initatlas_version(void) {\n void ATL_buildinfo(void);\n ATL_buildinfo();\n Py_InitModule(\"atlas_version\", module_methods);\n}\n#ifdef __CPLUSCPLUS__\n}\n#endif\n'''\n\ndef get_atlas_version(**config):\n from core import Extension, setup\n from misc_util import get_build_temp\n import log\n magic = hex(hash(`config`))\n def atlas_version_c(extension, build_dir,magic=magic):\n source = os.path.join(build_dir,'atlas_version_%s.c' % (magic))\n if os.path.isfile(source):\n from distutils.dep_util import newer\n if newer(source,__file__):\n return source\n f = open(source,'w')\n f.write(atlas_version_c_text)\n f.close()\n return source\n ext = Extension('atlas_version',\n sources=[atlas_version_c],\n **config)\n extra_args = ['--build-lib',get_build_temp()]\n for a in sys.argv:\n if re.match('[-][-]compiler[=]',a):\n extra_args.append(a)\n try:\n dist = setup(ext_modules=[ext],\n script_name = 'get_atlas_version',\n script_args = ['build_src','build_ext']+extra_args)\n except Exception,msg:\n print \"##### msg: %s\" % msg\n if not msg:\n msg = \"Unknown Exception\"\n log.warn(msg)\n return None\n\n from distutils.sysconfig import get_config_var\n so_ext = get_config_var('SO')\n build_ext = dist.get_command_obj('build_ext')\n target = os.path.join(build_ext.build_lib,'atlas_version'+so_ext)\n from exec_command import exec_command,get_pythonexe\n cmd = [get_pythonexe(),'-c',\n '\"import imp;imp.load_dynamic(\\\\\"atlas_version\\\\\",\\\\\"%s\\\\\")\"'\\\n % (os.path.basename(target))]\n s,o = exec_command(cmd,execute_in=os.path.dirname(target),use_tee=0)\n atlas_version = None\n if not s:\n m = re.match(r'ATLAS version (?P\\d+[.]\\d+[.]\\d+)',o)\n if m:\n atlas_version = m.group('version')\n if atlas_version is None:\n if re.search(r'undefined symbol: ATL_buildinfo',o,re.M):\n atlas_version = '3.2.1_pre3.3.6'\n else:\n print 'Command:',' '.join(cmd)\n print 'Status:',s\n print 'Output:',o\n return atlas_version\n\n\nclass lapack_opt_info(system_info):\n \n def calc_info(self):\n\n if sys.platform=='darwin' and not os.environ.get('ATLAS',None):\n args = []\n link_args = []\n if os.path.exists('/System/Library/Frameworks/Accelerate.framework/'):\n args.extend(['-faltivec','-framework','Accelerate'])\n link_args.extend(['-Wl,-framework','-Wl,Accelerate'])\n elif os.path.exists('/System/Library/Frameworks/vecLib.framework/'):\n args.extend(['-faltivec','-framework','vecLib'])\n link_args.extend(['-Wl,-framework','-Wl,vecLib'])\n if args:\n self.set_info(extra_compile_args=args,\n extra_link_args=link_args,\n define_macros=[('NO_ATLAS_INFO',3)])\n return\n\n atlas_info = get_info('atlas_threads')\n if not atlas_info:\n atlas_info = get_info('atlas')\n #atlas_info = {} ## uncomment for testing\n atlas_version = None\n need_lapack = 0\n need_blas = 0\n info = {}\n if atlas_info:\n version_info = atlas_info.copy()\n atlas_version = get_atlas_version(**version_info)\n if not atlas_info.has_key('define_macros'):\n atlas_info['define_macros'] = []\n if atlas_version is None:\n atlas_info['define_macros'].append(('NO_ATLAS_INFO',2))\n else:\n atlas_info['define_macros'].append(('ATLAS_INFO',\n '\"\\\\\"%s\\\\\"\"' % atlas_version))\n\t\tif atlas_version=='3.2.1_pre3.3.6':\n\t\t atlas_info['define_macros'].append(('NO_ATLAS_INFO',4))\n l = atlas_info.get('define_macros',[])\n if ('ATLAS_WITH_LAPACK_ATLAS',None) in l \\\n or ('ATLAS_WITHOUT_LAPACK',None) in l:\n need_lapack = 1\n info = atlas_info\n else:\n warnings.warn(AtlasNotFoundError.__doc__)\n need_blas = 1\n need_lapack = 1\n dict_append(info,define_macros=[('NO_ATLAS_INFO',1)])\n\n if need_lapack:\n lapack_info = get_info('lapack')\n #lapack_info = {} ## uncomment for testing\n if lapack_info:\n dict_append(info,**lapack_info)\n else:\n warnings.warn(LapackNotFoundError.__doc__)\n lapack_src_info = get_info('lapack_src')\n if not lapack_src_info:\n warnings.warn(LapackSrcNotFoundError.__doc__)\n return\n dict_append(info,libraries=[('flapack_src',lapack_src_info)])\n\n if need_blas:\n blas_info = get_info('blas')\n #blas_info = {} ## uncomment for testing\n if blas_info:\n dict_append(info,**blas_info)\n else:\n warnings.warn(BlasNotFoundError.__doc__)\n blas_src_info = get_info('blas_src')\n if not blas_src_info:\n warnings.warn(BlasSrcNotFoundError.__doc__)\n return\n dict_append(info,libraries=[('fblas_src',blas_src_info)])\n\n self.set_info(**info)\n return\n\n\nclass blas_opt_info(system_info):\n \n def calc_info(self):\n\n if sys.platform=='darwin' and not os.environ.get('ATLAS',None):\n args = []\n link_args = []\n if os.path.exists('/System/Library/Frameworks/Accelerate.framework/'):\n args.extend(['-faltivec','-framework','Accelerate'])\n link_args.extend(['-Wl,-framework','-Wl,Accelerate'])\n elif os.path.exists('/System/Library/Frameworks/vecLib.framework/'):\n args.extend(['-faltivec','-framework','vecLib'])\n link_args.extend(['-Wl,-framework','-Wl,vecLib'])\n if args:\n self.set_info(extra_compile_args=args,\n extra_link_args=link_args,\n define_macros=[('NO_ATLAS_INFO',3)])\n return\n\n atlas_info = get_info('atlas_blas_threads')\n if not atlas_info:\n atlas_info = get_info('atlas_blas')\n atlas_version = None\n need_blas = 0\n info = {}\n if atlas_info:\n version_info = atlas_info.copy()\n atlas_version = get_atlas_version(**version_info)\n if not atlas_info.has_key('define_macros'):\n atlas_info['define_macros'] = []\n if atlas_version is None:\n atlas_info['define_macros'].append(('NO_ATLAS_INFO',2))\n else:\n atlas_info['define_macros'].append(('ATLAS_INFO',\n '\"\\\\\"%s\\\\\"\"' % atlas_version))\n info = atlas_info\n else:\n warnings.warn(AtlasNotFoundError.__doc__)\n need_blas = 1\n dict_append(info,define_macros=[('NO_ATLAS_INFO',1)])\n\n if need_blas:\n blas_info = get_info('blas')\n if blas_info:\n dict_append(info,**blas_info)\n else:\n warnings.warn(BlasNotFoundError.__doc__)\n blas_src_info = get_info('blas_src')\n if not blas_src_info:\n warnings.warn(BlasSrcNotFoundError.__doc__)\n return\n dict_append(info,libraries=[('fblas_src',blas_src_info)])\n\n self.set_info(**info)\n return\n\n\nclass blas_info(system_info):\n section = 'blas'\n dir_env_var = 'BLAS'\n _lib_names = ['blas']\n notfounderror = BlasNotFoundError\n\n def calc_info(self):\n lib_dirs = self.get_lib_dirs()\n\n blas_libs = self.get_libs('blas_libs', self._lib_names)\n for d in lib_dirs:\n blas = self.check_libs(d,blas_libs,[])\n if blas is not None:\n info = blas \n break\n else:\n return\n info['language'] = 'f77' # XXX: is it generally true?\n self.set_info(**info)\n\n\nclass blas_src_info(system_info):\n section = 'blas_src'\n dir_env_var = 'BLAS_SRC'\n notfounderror = BlasSrcNotFoundError\n\n def get_paths(self, section, key):\n pre_dirs = system_info.get_paths(self, section, key)\n dirs = []\n for d in pre_dirs:\n dirs.extend([d] + self.combine_paths(d,['blas']))\n return [ d for d in dirs if os.path.isdir(d) ]\n\n def calc_info(self):\n src_dirs = self.get_src_dirs()\n src_dir = ''\n for d in src_dirs:\n if os.path.isfile(os.path.join(d,'daxpy.f')):\n src_dir = d\n break\n if not src_dir:\n #XXX: Get sources from netlib. May be ask first.\n return\n blas1 = '''\n caxpy csscal dnrm2 dzasum saxpy srotg zdotc ccopy cswap drot\n dznrm2 scasum srotm zdotu cdotc dasum drotg icamax scnrm2\n srotmg zdrot cdotu daxpy drotm idamax scopy sscal zdscal crotg\n dcabs1 drotmg isamax sdot sswap zrotg cscal dcopy dscal izamax\n snrm2 zaxpy zscal csrot ddot dswap sasum srot zcopy zswap\n '''\n blas2 = '''\n cgbmv chpmv ctrsv dsymv dtrsv sspr2 strmv zhemv ztpmv cgemv\n chpr dgbmv dsyr lsame ssymv strsv zher ztpsv cgerc chpr2 dgemv\n dsyr2 sgbmv ssyr xerbla zher2 ztrmv cgeru ctbmv dger dtbmv\n sgemv ssyr2 zgbmv zhpmv ztrsv chbmv ctbsv dsbmv dtbsv sger\n stbmv zgemv zhpr chemv ctpmv dspmv dtpmv ssbmv stbsv zgerc\n zhpr2 cher ctpsv dspr dtpsv sspmv stpmv zgeru ztbmv cher2\n ctrmv dspr2 dtrmv sspr stpsv zhbmv ztbsv\n '''\n blas3 = '''\n cgemm csymm ctrsm dsyrk sgemm strmm zhemm zsyr2k chemm csyr2k\n dgemm dtrmm ssymm strsm zher2k zsyrk cher2k csyrk dsymm dtrsm\n ssyr2k zherk ztrmm cherk ctrmm dsyr2k ssyrk zgemm zsymm ztrsm\n '''\n sources = [os.path.join(src_dir,f+'.f') \\\n for f in (blas1+blas2+blas3).split()]\n #XXX: should we check here actual existence of source files?\n info = {'sources':sources,'language':'f77'}\n self.set_info(**info)\n\nclass x11_info(system_info):\n section = 'x11'\n notfounderror = X11NotFoundError\n\n def __init__(self):\n system_info.__init__(self,\n default_lib_dirs=default_x11_lib_dirs,\n default_include_dirs=default_x11_include_dirs)\n\n def calc_info(self):\n if sys.platform in ['win32']:\n return\n lib_dirs = self.get_lib_dirs()\n include_dirs = self.get_include_dirs()\n x11_libs = self.get_libs('x11_libs', ['X11'])\n for lib_dir in lib_dirs:\n info = self.check_libs(lib_dir, x11_libs, [])\n if info is not None:\n break\n else:\n return\n inc_dir = None\n for d in include_dirs:\n if self.combine_paths(d, 'X11/X.h'):\n inc_dir = d\n break\n if inc_dir is not None:\n dict_append(info, include_dirs=[inc_dir])\n self.set_info(**info)\n\nclass numpy_info(system_info):\n section = 'numpy'\n modulename = 'Numeric'\n notfounderror = NumericNotFoundError\n\n def __init__(self):\n from distutils.sysconfig import get_python_inc\n include_dirs = []\n try:\n module = __import__(self.modulename)\n prefix = []\n for name in module.__file__.split(os.sep):\n if name=='lib':\n break\n prefix.append(name)\n include_dirs.append(get_python_inc(prefix=os.sep.join(prefix)))\n except ImportError:\n pass\n py_incl_dir = get_python_inc()\n include_dirs.append(py_incl_dir)\n for d in default_include_dirs:\n d = os.path.join(d, os.path.basename(py_incl_dir))\n if d not in include_dirs:\n include_dirs.append(d)\n system_info.__init__(self,\n default_lib_dirs=[],\n default_include_dirs=include_dirs)\n\n def calc_info(self):\n try:\n module = __import__(self.modulename)\n except ImportError:\n return\n info = {}\n macros = [(self.modulename.upper()+'_VERSION',\n '\"\\\\\"%s\\\\\"\"' % (module.__version__))]\n## try:\n## macros.append(\n## (self.modulename.upper()+'_VERSION_HEX',\n## hex(vstr2hex(module.__version__))),\n## )\n## except Exception,msg:\n## print msg\n dict_append(info, define_macros = macros)\n include_dirs = self.get_include_dirs()\n inc_dir = None\n for d in include_dirs:\n if self.combine_paths(d,\n os.path.join(self.modulename,\n 'arrayobject.h')):\n inc_dir = d\n break\n if inc_dir is not None:\n dict_append(info, include_dirs=[inc_dir])\n if info:\n self.set_info(**info)\n return\n\nclass numarray_info(numpy_info):\n section = 'numarray'\n modulename = 'numarray'\n\nclass boost_python_info(system_info):\n section = 'boost_python'\n dir_env_var = 'BOOST'\n\n def get_paths(self, section, key):\n pre_dirs = system_info.get_paths(self, section, key)\n dirs = []\n for d in pre_dirs:\n dirs.extend([d] + self.combine_paths(d,['boost*']))\n return [ d for d in dirs if os.path.isdir(d) ]\n\n def calc_info(self):\n from distutils.sysconfig import get_python_inc\n src_dirs = self.get_src_dirs()\n src_dir = ''\n for d in src_dirs:\n if os.path.isfile(os.path.join(d,'libs','python','src','module.cpp')):\n src_dir = d\n break\n if not src_dir:\n return\n py_incl_dir = get_python_inc()\n srcs_dir = os.path.join(src_dir,'libs','python','src')\n bpl_srcs = glob(os.path.join(srcs_dir,'*.cpp'))\n bpl_srcs += glob(os.path.join(srcs_dir,'*','*.cpp'))\n info = {'libraries':[('boost_python_src',{'include_dirs':[src_dir,py_incl_dir],\n 'sources':bpl_srcs})],\n 'include_dirs':[src_dir],\n }\n if info:\n self.set_info(**info)\n return\n\nclass agg2_info(system_info):\n section = 'agg2'\n dir_env_var = 'AGG2'\n\n def get_paths(self, section, key):\n pre_dirs = system_info.get_paths(self, section, key)\n dirs = []\n for d in pre_dirs:\n dirs.extend([d] + self.combine_paths(d,['agg2*']))\n return [ d for d in dirs if os.path.isdir(d) ]\n\n def calc_info(self):\n src_dirs = self.get_src_dirs()\n src_dir = ''\n for d in src_dirs:\n if os.path.isfile(os.path.join(d,'src','agg_affine_matrix.cpp')):\n src_dir = d\n break\n if not src_dir:\n return\n if sys.platform=='win32':\n agg2_srcs = glob(os.path.join(src_dir,'src','platform','win32','agg_win32_bmp.cpp'))\n else:\n agg2_srcs = glob(os.path.join(src_dir,'src','*.cpp'))\n agg2_srcs += [os.path.join(src_dir,'src','platform','X11','agg_platform_support.cpp')]\n \n info = {'libraries':[('agg2_src',{'sources':agg2_srcs,\n 'include_dirs':[os.path.join(src_dir,'include')],\n })],\n 'include_dirs':[os.path.join(src_dir,'include')],\n }\n if info:\n self.set_info(**info)\n return\n\nclass _pkg_config_info(system_info):\n section = None\n config_env_var = 'PKG_CONFIG'\n default_config_exe = 'pkg-config'\n append_config_exe = ''\n version_macro_name = None\n release_macro_name = None\n version_flag = '--modversion'\n cflags_flag = '--cflags'\n\n def get_config_exe(self):\n if os.environ.has_key(self.config_env_var):\n return os.environ[self.config_env_var]\n return self.default_config_exe\n def get_config_output(self, config_exe, option):\n s,o = exec_command(config_exe+' '+self.append_config_exe+' '+option,use_tee=0)\n if not s:\n return o\n\n def calc_info(self):\n config_exe = find_executable(self.get_config_exe())\n if not os.path.isfile(config_exe):\n print 'File not found: %s. Cannot determine %s info.' \\\n % (config_exe, self.section)\n return\n info = {}\n macros = []\n libraries = []\n library_dirs = []\n include_dirs = []\n extra_link_args = []\n extra_compile_args = []\n version = self.get_config_output(config_exe,self.version_flag)\n if version:\n macros.append((self.__class__.__name__.split('.')[-1].upper(),\n '\"\\\\\"%s\\\\\"\"' % (version)))\n if self.version_macro_name:\n macros.append((self.version_macro_name+'_%s' % (version.replace('.','_')),None))\n if self.release_macro_name:\n release = self.get_config_output(config_exe,'--release')\n if release:\n macros.append((self.release_macro_name+'_%s' % (release.replace('.','_')),None))\n opts = self.get_config_output(config_exe,'--libs')\n if opts:\n for opt in opts.split():\n if opt[:2]=='-l':\n libraries.append(opt[2:])\n elif opt[:2]=='-L':\n library_dirs.append(opt[2:])\n else:\n extra_link_args.append(opt)\n opts = self.get_config_output(config_exe,self.cflags_flag)\n if opts:\n for opt in opts.split():\n if opt[:2]=='-I':\n include_dirs.append(opt[2:])\n elif opt[:2]=='-D':\n if '=' in opt:\n n,v = opt[2:].split('=')\n macros.append((n,v))\n else:\n macros.append((opt[2:],None))\n else:\n extra_compile_args.append(opt)\n if macros: dict_append(info, define_macros = macros)\n if libraries: dict_append(info, libraries = libraries)\n if library_dirs: dict_append(info, library_dirs = library_dirs)\n if include_dirs: dict_append(info, include_dirs = include_dirs)\n if extra_link_args: dict_append(info, extra_link_args = extra_link_args)\n if extra_compile_args: dict_append(info, extra_compile_args = extra_compile_args)\n if info:\n self.set_info(**info)\n return\n\nclass wx_info(_pkg_config_info):\n section = 'wx'\n config_env_var = 'WX_CONFIG'\n default_config_exe = 'wx-config'\n append_config_exe = ''\n version_macro_name = 'WX_VERSION'\n release_macro_name = 'WX_RELEASE'\n version_flag = '--version'\n cflags_flag = '--cxxflags'\n\nclass gdk_pixbuf_xlib_2_info(_pkg_config_info):\n section = 'gdk_pixbuf_xlib_2'\n append_config_exe = 'gdk-pixbuf-xlib-2.0'\n version_macro_name = 'GDK_PIXBUF_XLIB_VERSION'\n\nclass gdk_pixbuf_2_info(_pkg_config_info):\n section = 'gdk_pixbuf_2'\n append_config_exe = 'gdk-pixbuf-2.0'\n version_macro_name = 'GDK_PIXBUF_VERSION'\n\nclass gdk_x11_2_info(_pkg_config_info):\n section = 'gdk_x11_2'\n append_config_exe = 'gdk-x11-2.0'\n version_macro_name = 'GDK_X11_VERSION'\n\nclass gdk_2_info(_pkg_config_info):\n section = 'gdk_2'\n append_config_exe = 'gdk-2.0'\n version_macro_name = 'GDK_VERSION'\n\nclass gdk_info(_pkg_config_info):\n section = 'gdk'\n append_config_exe = 'gdk'\n version_macro_name = 'GDK_VERSION'\n\nclass gtkp_x11_2_info(_pkg_config_info):\n section = 'gtkp_x11_2'\n append_config_exe = 'gtk+-x11-2.0'\n version_macro_name = 'GTK_X11_VERSION'\n\n\nclass gtkp_2_info(_pkg_config_info):\n section = 'gtkp_2'\n append_config_exe = 'gtk+-2.0'\n version_macro_name = 'GTK_VERSION'\n\nclass xft_info(_pkg_config_info):\n section = 'xft'\n append_config_exe = 'xft'\n version_macro_name = 'XFT_VERSION'\n\nclass freetype2_info(_pkg_config_info):\n section = 'freetype2'\n append_config_exe = 'freetype2'\n version_macro_name = 'FREETYPE2_VERSION'\n\n## def vstr2hex(version):\n## bits = []\n## n = [24,16,8,4,0]\n## r = 0\n## for s in version.split('.'):\n## r |= int(s) << n[0]\n## del n[0]\n## return r\n\n#--------------------------------------------------------------------\n\ndef combine_paths(*args,**kws):\n \"\"\" Return a list of existing paths composed by all combinations of\n items from arguments.\n \"\"\"\n r = []\n for a in args:\n if not a: continue\n if type(a) is types.StringType:\n a = [a]\n r.append(a)\n args = r\n if not args: return []\n if len(args)==1:\n result = reduce(lambda a,b:a+b,map(glob,args[0]),[])\n elif len (args)==2:\n result = []\n for a0 in args[0]:\n for a1 in args[1]:\n result.extend(glob(os.path.join(a0,a1)))\n else:\n result = combine_paths(*(combine_paths(args[0],args[1])+args[2:]))\n verbosity = kws.get('verbosity',1)\n if verbosity>1 and result:\n print '(','paths:',','.join(result),')'\n return result\n\nlanguage_map = {'c':0,'c++':1,'f77':2,'f90':3}\ninv_language_map = {0:'c',1:'c++',2:'f77',3:'f90'}\ndef dict_append(d,**kws):\n languages = []\n for k,v in kws.items():\n if k=='language':\n languages.append(v)\n continue\n if d.has_key(k):\n if k in ['library_dirs','include_dirs','define_macros']:\n [d[k].append(vv) for vv in v if vv not in d[k]]\n else:\n d[k].extend(v)\n else:\n d[k] = v\n if languages:\n l = inv_language_map[max([language_map.get(l,0) for l in languages])]\n d['language'] = l\n return\n\ndef show_all():\n import system_info\n import pprint\n match_info = re.compile(r'.*?_info').match\n show_only = []\n for n in sys.argv[1:]:\n if n[-5:] != '_info':\n n = n + '_info'\n show_only.append(n)\n show_all = not show_only\n for n in filter(match_info,dir(system_info)):\n if n in ['system_info','get_info']: continue\n if not show_all:\n if n not in show_only: continue\n del show_only[show_only.index(n)]\n c = getattr(system_info,n)()\n c.verbosity = 2\n r = c.get_info()\n if show_only:\n print 'Info classes not defined:',','.join(show_only)\nif __name__ == \"__main__\":\n show_all()\n", "methods": [ { "name": "get_info", "long_name": "get_info( name , notfound_action = 0 )", "filename": "system_info.py", "nloc": 43, "complexity": 1, "token_count": 194, "parameters": [ "name", "notfound_action" ], "start_line": 144, "end_line": 192, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 49, "top_nesting_level": 0 }, { "name": "__init__", "long_name": "__init__( self , default_lib_dirs = default_lib_dirs , default_include_dirs = default_include_dirs , verbosity = 1 , )", "filename": "system_info.py", "nloc": 26, "complexity": 3, "token_count": 206, "parameters": [ "self", "default_lib_dirs", "default_include_dirs", "verbosity" ], "start_line": 272, "end_line": 297, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 26, "top_nesting_level": 1 }, { "name": "calc_libraries_info", "long_name": "calc_libraries_info( self )", "filename": "system_info.py", "nloc": 15, "complexity": 5, "token_count": 78, "parameters": [ "self" ], "start_line": 299, "end_line": 313, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 15, "top_nesting_level": 1 }, { "name": "set_info", "long_name": "set_info( self , ** info )", "filename": "system_info.py", "nloc": 5, "complexity": 2, "token_count": 37, "parameters": [ "self", "info" ], "start_line": 315, "end_line": 319, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 5, "top_nesting_level": 1 }, { "name": "has_info", "long_name": "has_info( self )", "filename": "system_info.py", "nloc": 2, "complexity": 1, "token_count": 18, "parameters": [ "self" ], "start_line": 321, "end_line": 322, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 2, "top_nesting_level": 1 }, { "name": "get_info", "long_name": "get_info( self , notfound_action = 0 )", "filename": "system_info.py", "nloc": 30, "complexity": 15, "token_count": 206, "parameters": [ "self", "notfound_action" ], "start_line": 324, "end_line": 359, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 36, "top_nesting_level": 1 }, { "name": "get_paths", "long_name": "get_paths( self , section , key )", "filename": "system_info.py", "nloc": 47, "complexity": 20, "token_count": 405, "parameters": [ "self", "section", "key" ], "start_line": 361, "end_line": 407, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 47, "top_nesting_level": 1 }, { "name": "get_lib_dirs", "long_name": "get_lib_dirs( self , key = 'library_dirs' )", "filename": "system_info.py", "nloc": 2, "complexity": 1, "token_count": 20, "parameters": [ "self", "key" ], "start_line": 409, "end_line": 410, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 2, "top_nesting_level": 1 }, { "name": "get_include_dirs", "long_name": "get_include_dirs( self , key = 'include_dirs' )", "filename": "system_info.py", "nloc": 2, "complexity": 1, "token_count": 20, "parameters": [ "self", "key" ], "start_line": 412, "end_line": 413, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 2, "top_nesting_level": 1 }, { "name": "get_src_dirs", "long_name": "get_src_dirs( self , key = 'src_dirs' )", "filename": "system_info.py", "nloc": 2, "complexity": 1, "token_count": 20, "parameters": [ "self", "key" ], "start_line": 415, "end_line": 416, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 2, "top_nesting_level": 1 }, { "name": "get_libs", "long_name": "get_libs( self , key , default )", "filename": "system_info.py", "nloc": 10, "complexity": 7, "token_count": 79, "parameters": [ "self", "key", "default" ], "start_line": 418, "end_line": 427, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 10, "top_nesting_level": 1 }, { "name": "get_libraries", "long_name": "get_libraries( self , key = 'libraries' )", "filename": "system_info.py", "nloc": 2, "complexity": 1, "token_count": 18, "parameters": [ "self", "key" ], "start_line": 429, "end_line": 430, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 2, "top_nesting_level": 1 }, { "name": "check_libs", "long_name": "check_libs( self , lib_dir , libs , opt_libs = [ ] )", "filename": "system_info.py", "nloc": 11, "complexity": 5, "token_count": 77, "parameters": [ "self", "lib_dir", "libs", "opt_libs" ], "start_line": 432, "end_line": 444, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 13, "top_nesting_level": 1 }, { "name": "_lib_list", "long_name": "_lib_list( self , lib_dir , libs , ext )", "filename": "system_info.py", "nloc": 9, "complexity": 3, "token_count": 65, "parameters": [ "self", "lib_dir", "libs", "ext" ], "start_line": 446, "end_line": 454, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 9, "top_nesting_level": 1 }, { "name": "_extract_lib_names", "long_name": "_extract_lib_names( self , libs )", "filename": "system_info.py", "nloc": 3, "complexity": 2, "token_count": 37, "parameters": [ "self", "libs" ], "start_line": 456, "end_line": 458, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 3, "top_nesting_level": 1 }, { "name": "_check_libs", "long_name": "_check_libs( self , lib_dir , libs , opt_libs , ext )", "filename": "system_info.py", "nloc": 10, "complexity": 3, "token_count": 99, "parameters": [ "self", "lib_dir", "libs", "opt_libs", "ext" ], "start_line": 460, "end_line": 469, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 10, "top_nesting_level": 1 }, { "name": "combine_paths", "long_name": "combine_paths( self , * args )", "filename": "system_info.py", "nloc": 2, "complexity": 1, "token_count": 23, "parameters": [ "self", "args" ], "start_line": 471, "end_line": 472, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 2, "top_nesting_level": 1 }, { "name": "__init__", "long_name": "__init__( self )", "filename": "system_info.py", "nloc": 2, "complexity": 1, "token_count": 11, "parameters": [ "self" ], "start_line": 482, "end_line": 483, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 2, "top_nesting_level": 1 }, { "name": "calc_info", "long_name": "calc_info( self )", "filename": "system_info.py", "nloc": 26, "complexity": 8, "token_count": 150, "parameters": [ "self" ], "start_line": 485, "end_line": 510, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 26, "top_nesting_level": 1 }, { "name": "get_paths", "long_name": "get_paths( self , section , key )", "filename": "system_info.py", "nloc": 6, "complexity": 4, "token_count": 66, "parameters": [ "self", "section", "key" ], "start_line": 552, "end_line": 557, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 6, "top_nesting_level": 1 }, { "name": "calc_info", "long_name": "calc_info( self )", "filename": "system_info.py", "nloc": 22, "complexity": 7, "token_count": 140, "parameters": [ "self" ], "start_line": 559, "end_line": 580, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 22, "top_nesting_level": 1 }, { "name": "get_paths", "long_name": "get_paths( self , section , key )", "filename": "system_info.py", "nloc": 7, "complexity": 4, "token_count": 74, "parameters": [ "self", "section", "key" ], "start_line": 595, "end_line": 601, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 7, "top_nesting_level": 1 }, { "name": "calc_info", "long_name": "calc_info( self )", "filename": "system_info.py", "nloc": 78, "complexity": 17, "token_count": 441, "parameters": [ "self" ], "start_line": 603, "end_line": 683, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 81, "top_nesting_level": 1 }, { "name": "calc_info", "long_name": "calc_info( self )", "filename": "system_info.py", "nloc": 21, "complexity": 6, "token_count": 138, "parameters": [ "self" ], "start_line": 688, "end_line": 710, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 23, "top_nesting_level": 1 }, { "name": "calc_info", "long_name": "calc_info( self )", "filename": "system_info.py", "nloc": 12, "complexity": 3, "token_count": 68, "parameters": [ "self" ], "start_line": 733, "end_line": 745, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 13, "top_nesting_level": 1 }, { "name": "get_paths", "long_name": "get_paths( self , section , key )", "filename": "system_info.py", "nloc": 6, "complexity": 4, "token_count": 68, "parameters": [ "self", "section", "key" ], "start_line": 752, "end_line": 757, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 6, "top_nesting_level": 1 }, { "name": "calc_info", "long_name": "calc_info( self )", "filename": "system_info.py", "nloc": 81, "complexity": 10, "token_count": 232, "parameters": [ "self" ], "start_line": 759, "end_line": 843, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 85, "top_nesting_level": 1 }, { "name": "get_atlas_version.atlas_version_c", "long_name": "get_atlas_version.atlas_version_c( extension , build_dir , magic = magic )", "filename": "system_info.py", "nloc": 10, "complexity": 3, "token_count": 74, "parameters": [ "extension", "build_dir", "magic" ], "start_line": 867, "end_line": 876, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 10, "top_nesting_level": 1 }, { "name": "get_atlas_version", "long_name": "get_atlas_version( ** config )", "filename": "system_info.py", "nloc": 45, "complexity": 9, "token_count": 289, "parameters": [ "config" ], "start_line": 862, "end_line": 916, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 55, "top_nesting_level": 0 }, { "name": "calc_info", "long_name": "calc_info( self )", "filename": "system_info.py", "nloc": 68, "complexity": 19, "token_count": 434, "parameters": [ "self" ], "start_line": 921, "end_line": 996, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 76, "top_nesting_level": 1 }, { "name": "calc_info", "long_name": "calc_info( self )", "filename": "system_info.py", "nloc": 49, "complexity": 13, "token_count": 316, "parameters": [ "self" ], "start_line": 1001, "end_line": 1053, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 53, "top_nesting_level": 1 }, { "name": "calc_info", "long_name": "calc_info( self )", "filename": "system_info.py", "nloc": 12, "complexity": 3, "token_count": 68, "parameters": [ "self" ], "start_line": 1062, "end_line": 1074, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 13, "top_nesting_level": 1 }, { "name": "get_paths", "long_name": "get_paths( self , section , key )", "filename": "system_info.py", "nloc": 6, "complexity": 4, "token_count": 66, "parameters": [ "self", "section", "key" ], "start_line": 1082, "end_line": 1087, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 6, "top_nesting_level": 1 }, { "name": "calc_info", "long_name": "calc_info( self )", "filename": "system_info.py", "nloc": 34, "complexity": 5, "token_count": 106, "parameters": [ "self" ], "start_line": 1089, "end_line": 1124, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 36, "top_nesting_level": 1 }, { "name": "__init__", "long_name": "__init__( self )", "filename": "system_info.py", "nloc": 4, "complexity": 1, "token_count": 19, "parameters": [ "self" ], "start_line": 1130, "end_line": 1133, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 4, "top_nesting_level": 1 }, { "name": "calc_info", "long_name": "calc_info( self )", "filename": "system_info.py", "nloc": 20, "complexity": 7, "token_count": 114, "parameters": [ "self" ], "start_line": 1135, "end_line": 1154, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 20, "top_nesting_level": 1 }, { "name": "__init__", "long_name": "__init__( self )", "filename": "system_info.py", "nloc": 22, "complexity": 6, "token_count": 139, "parameters": [ "self" ], "start_line": 1161, "end_line": 1182, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 22, "top_nesting_level": 1 }, { "name": "calc_info", "long_name": "calc_info( self )", "filename": "system_info.py", "nloc": 22, "complexity": 6, "token_count": 121, "parameters": [ "self" ], "start_line": 1184, "end_line": 1212, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 29, "top_nesting_level": 1 }, { "name": "get_paths", "long_name": "get_paths( self , section , key )", "filename": "system_info.py", "nloc": 6, "complexity": 4, "token_count": 66, "parameters": [ "self", "section", "key" ], "start_line": 1222, "end_line": 1227, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 6, "top_nesting_level": 1 }, { "name": "calc_info", "long_name": "calc_info( self )", "filename": "system_info.py", "nloc": 21, "complexity": 5, "token_count": 156, "parameters": [ "self" ], "start_line": 1229, "end_line": 1249, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 21, "top_nesting_level": 1 }, { "name": "get_paths", "long_name": "get_paths( self , section , key )", "filename": "system_info.py", "nloc": 6, "complexity": 4, "token_count": 66, "parameters": [ "self", "section", "key" ], "start_line": 1255, "end_line": 1260, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 6, "top_nesting_level": 1 }, { "name": "calc_info", "long_name": "calc_info( self )", "filename": "system_info.py", "nloc": 22, "complexity": 6, "token_count": 177, "parameters": [ "self" ], "start_line": 1262, "end_line": 1284, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 23, "top_nesting_level": 1 }, { "name": "get_config_exe", "long_name": "get_config_exe( self )", "filename": "system_info.py", "nloc": 4, "complexity": 2, "token_count": 30, "parameters": [ "self" ], "start_line": 1296, "end_line": 1299, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 4, "top_nesting_level": 1 }, { "name": "get_config_output", "long_name": "get_config_output( self , config_exe , option )", "filename": "system_info.py", "nloc": 4, "complexity": 2, "token_count": 37, "parameters": [ "self", "config_exe", "option" ], "start_line": 1300, "end_line": 1303, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 4, "top_nesting_level": 1 }, { "name": "calc_info", "long_name": "calc_info( self )", "filename": "system_info.py", "nloc": 54, "complexity": 22, "token_count": 435, "parameters": [ "self" ], "start_line": 1305, "end_line": 1358, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 54, "top_nesting_level": 1 }, { "name": "combine_paths", "long_name": "combine_paths( * args , ** kws )", "filename": "system_info.py", "nloc": 22, "complexity": 11, "token_count": 195, "parameters": [ "args", "kws" ], "start_line": 1427, "end_line": 1451, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 25, "top_nesting_level": 0 }, { "name": "dict_append", "long_name": "dict_append( d , ** kws )", "filename": "system_info.py", "nloc": 17, "complexity": 9, "token_count": 128, "parameters": [ "d", "kws" ], "start_line": 1455, "end_line": 1471, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 17, "top_nesting_level": 0 }, { "name": "show_all", "long_name": "show_all( )", "filename": "system_info.py", "nloc": 20, "complexity": 8, "token_count": 137, "parameters": [], "start_line": 1473, "end_line": 1492, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 20, "top_nesting_level": 0 } ], "methods_before": [ { "name": "get_info", "long_name": "get_info( name , notfound_action = 0 )", "filename": "system_info.py", "nloc": 43, "complexity": 1, "token_count": 194, "parameters": [ "name", "notfound_action" ], "start_line": 144, "end_line": 192, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 49, "top_nesting_level": 0 }, { "name": "__init__", "long_name": "__init__( self , default_lib_dirs = default_lib_dirs , default_include_dirs = default_include_dirs , verbosity = 1 , )", "filename": "system_info.py", "nloc": 26, "complexity": 3, "token_count": 206, "parameters": [ "self", "default_lib_dirs", "default_include_dirs", "verbosity" ], "start_line": 272, "end_line": 297, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 26, "top_nesting_level": 1 }, { "name": "calc_libraries_info", "long_name": "calc_libraries_info( self )", "filename": "system_info.py", "nloc": 15, "complexity": 5, "token_count": 78, "parameters": [ "self" ], "start_line": 299, "end_line": 313, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 15, "top_nesting_level": 1 }, { "name": "set_info", "long_name": "set_info( self , ** info )", "filename": "system_info.py", "nloc": 5, "complexity": 2, "token_count": 37, "parameters": [ "self", "info" ], "start_line": 315, "end_line": 319, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 5, "top_nesting_level": 1 }, { "name": "has_info", "long_name": "has_info( self )", "filename": "system_info.py", "nloc": 2, "complexity": 1, "token_count": 18, "parameters": [ "self" ], "start_line": 321, "end_line": 322, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 2, "top_nesting_level": 1 }, { "name": "get_info", "long_name": "get_info( self , notfound_action = 0 )", "filename": "system_info.py", "nloc": 30, "complexity": 15, "token_count": 206, "parameters": [ "self", "notfound_action" ], "start_line": 324, "end_line": 359, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 36, "top_nesting_level": 1 }, { "name": "get_paths", "long_name": "get_paths( self , section , key )", "filename": "system_info.py", "nloc": 47, "complexity": 20, "token_count": 405, "parameters": [ "self", "section", "key" ], "start_line": 361, "end_line": 407, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 47, "top_nesting_level": 1 }, { "name": "get_lib_dirs", "long_name": "get_lib_dirs( self , key = 'library_dirs' )", "filename": "system_info.py", "nloc": 2, "complexity": 1, "token_count": 20, "parameters": [ "self", "key" ], "start_line": 409, "end_line": 410, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 2, "top_nesting_level": 1 }, { "name": "get_include_dirs", "long_name": "get_include_dirs( self , key = 'include_dirs' )", "filename": "system_info.py", "nloc": 2, "complexity": 1, "token_count": 20, "parameters": [ "self", "key" ], "start_line": 412, "end_line": 413, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 2, "top_nesting_level": 1 }, { "name": "get_src_dirs", "long_name": "get_src_dirs( self , key = 'src_dirs' )", "filename": "system_info.py", "nloc": 2, "complexity": 1, "token_count": 20, "parameters": [ "self", "key" ], "start_line": 415, "end_line": 416, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 2, "top_nesting_level": 1 }, { "name": "get_libs", "long_name": "get_libs( self , key , default )", "filename": "system_info.py", "nloc": 10, "complexity": 7, "token_count": 79, "parameters": [ "self", "key", "default" ], "start_line": 418, "end_line": 427, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 10, "top_nesting_level": 1 }, { "name": "get_libraries", "long_name": "get_libraries( self , key = 'libraries' )", "filename": "system_info.py", "nloc": 2, "complexity": 1, "token_count": 18, "parameters": [ "self", "key" ], "start_line": 429, "end_line": 430, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 2, "top_nesting_level": 1 }, { "name": "check_libs", "long_name": "check_libs( self , lib_dir , libs , opt_libs = [ ] )", "filename": "system_info.py", "nloc": 11, "complexity": 5, "token_count": 77, "parameters": [ "self", "lib_dir", "libs", "opt_libs" ], "start_line": 432, "end_line": 444, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 13, "top_nesting_level": 1 }, { "name": "_lib_list", "long_name": "_lib_list( self , lib_dir , libs , ext )", "filename": "system_info.py", "nloc": 9, "complexity": 3, "token_count": 65, "parameters": [ "self", "lib_dir", "libs", "ext" ], "start_line": 446, "end_line": 454, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 9, "top_nesting_level": 1 }, { "name": "_extract_lib_names", "long_name": "_extract_lib_names( self , libs )", "filename": "system_info.py", "nloc": 3, "complexity": 2, "token_count": 37, "parameters": [ "self", "libs" ], "start_line": 456, "end_line": 458, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 3, "top_nesting_level": 1 }, { "name": "_check_libs", "long_name": "_check_libs( self , lib_dir , libs , opt_libs , ext )", "filename": "system_info.py", "nloc": 10, "complexity": 3, "token_count": 99, "parameters": [ "self", "lib_dir", "libs", "opt_libs", "ext" ], "start_line": 460, "end_line": 469, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 10, "top_nesting_level": 1 }, { "name": "combine_paths", "long_name": "combine_paths( self , * args )", "filename": "system_info.py", "nloc": 2, "complexity": 1, "token_count": 23, "parameters": [ "self", "args" ], "start_line": 471, "end_line": 472, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 2, "top_nesting_level": 1 }, { "name": "__init__", "long_name": "__init__( self )", "filename": "system_info.py", "nloc": 2, "complexity": 1, "token_count": 11, "parameters": [ "self" ], "start_line": 482, "end_line": 483, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 2, "top_nesting_level": 1 }, { "name": "calc_info", "long_name": "calc_info( self )", "filename": "system_info.py", "nloc": 26, "complexity": 8, "token_count": 150, "parameters": [ "self" ], "start_line": 485, "end_line": 510, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 26, "top_nesting_level": 1 }, { "name": "get_paths", "long_name": "get_paths( self , section , key )", "filename": "system_info.py", "nloc": 6, "complexity": 4, "token_count": 66, "parameters": [ "self", "section", "key" ], "start_line": 552, "end_line": 557, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 6, "top_nesting_level": 1 }, { "name": "calc_info", "long_name": "calc_info( self )", "filename": "system_info.py", "nloc": 22, "complexity": 7, "token_count": 140, "parameters": [ "self" ], "start_line": 559, "end_line": 580, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 22, "top_nesting_level": 1 }, { "name": "get_paths", "long_name": "get_paths( self , section , key )", "filename": "system_info.py", "nloc": 7, "complexity": 4, "token_count": 74, "parameters": [ "self", "section", "key" ], "start_line": 595, "end_line": 601, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 7, "top_nesting_level": 1 }, { "name": "calc_info", "long_name": "calc_info( self )", "filename": "system_info.py", "nloc": 78, "complexity": 17, "token_count": 441, "parameters": [ "self" ], "start_line": 603, "end_line": 683, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 81, "top_nesting_level": 1 }, { "name": "calc_info", "long_name": "calc_info( self )", "filename": "system_info.py", "nloc": 21, "complexity": 6, "token_count": 138, "parameters": [ "self" ], "start_line": 688, "end_line": 710, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 23, "top_nesting_level": 1 }, { "name": "calc_info", "long_name": "calc_info( self )", "filename": "system_info.py", "nloc": 12, "complexity": 3, "token_count": 68, "parameters": [ "self" ], "start_line": 733, "end_line": 745, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 13, "top_nesting_level": 1 }, { "name": "get_paths", "long_name": "get_paths( self , section , key )", "filename": "system_info.py", "nloc": 6, "complexity": 4, "token_count": 68, "parameters": [ "self", "section", "key" ], "start_line": 752, "end_line": 757, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 6, "top_nesting_level": 1 }, { "name": "calc_info", "long_name": "calc_info( self )", "filename": "system_info.py", "nloc": 81, "complexity": 10, "token_count": 232, "parameters": [ "self" ], "start_line": 759, "end_line": 843, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 85, "top_nesting_level": 1 }, { "name": "get_atlas_version.atlas_version_c", "long_name": "get_atlas_version.atlas_version_c( extension , build_dir , magic = magic )", "filename": "system_info.py", "nloc": 10, "complexity": 3, "token_count": 74, "parameters": [ "extension", "build_dir", "magic" ], "start_line": 867, "end_line": 876, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 10, "top_nesting_level": 1 }, { "name": "get_atlas_version", "long_name": "get_atlas_version( ** config )", "filename": "system_info.py", "nloc": 45, "complexity": 9, "token_count": 289, "parameters": [ "config" ], "start_line": 862, "end_line": 916, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 55, "top_nesting_level": 0 }, { "name": "calc_info", "long_name": "calc_info( self )", "filename": "system_info.py", "nloc": 68, "complexity": 19, "token_count": 434, "parameters": [ "self" ], "start_line": 921, "end_line": 996, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 76, "top_nesting_level": 1 }, { "name": "calc_info", "long_name": "calc_info( self )", "filename": "system_info.py", "nloc": 49, "complexity": 13, "token_count": 316, "parameters": [ "self" ], "start_line": 1001, "end_line": 1053, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 53, "top_nesting_level": 1 }, { "name": "calc_info", "long_name": "calc_info( self )", "filename": "system_info.py", "nloc": 12, "complexity": 3, "token_count": 68, "parameters": [ "self" ], "start_line": 1062, "end_line": 1074, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 13, "top_nesting_level": 1 }, { "name": "get_paths", "long_name": "get_paths( self , section , key )", "filename": "system_info.py", "nloc": 6, "complexity": 4, "token_count": 66, "parameters": [ "self", "section", "key" ], "start_line": 1082, "end_line": 1087, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 6, "top_nesting_level": 1 }, { "name": "calc_info", "long_name": "calc_info( self )", "filename": "system_info.py", "nloc": 34, "complexity": 5, "token_count": 106, "parameters": [ "self" ], "start_line": 1089, "end_line": 1124, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 36, "top_nesting_level": 1 }, { "name": "__init__", "long_name": "__init__( self )", "filename": "system_info.py", "nloc": 4, "complexity": 1, "token_count": 19, "parameters": [ "self" ], "start_line": 1130, "end_line": 1133, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 4, "top_nesting_level": 1 }, { "name": "calc_info", "long_name": "calc_info( self )", "filename": "system_info.py", "nloc": 20, "complexity": 7, "token_count": 114, "parameters": [ "self" ], "start_line": 1135, "end_line": 1154, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 20, "top_nesting_level": 1 }, { "name": "__init__", "long_name": "__init__( self )", "filename": "system_info.py", "nloc": 22, "complexity": 6, "token_count": 139, "parameters": [ "self" ], "start_line": 1161, "end_line": 1182, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 22, "top_nesting_level": 1 }, { "name": "calc_info", "long_name": "calc_info( self )", "filename": "system_info.py", "nloc": 22, "complexity": 6, "token_count": 121, "parameters": [ "self" ], "start_line": 1184, "end_line": 1212, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 29, "top_nesting_level": 1 }, { "name": "get_paths", "long_name": "get_paths( self , section , key )", "filename": "system_info.py", "nloc": 6, "complexity": 4, "token_count": 66, "parameters": [ "self", "section", "key" ], "start_line": 1222, "end_line": 1227, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 6, "top_nesting_level": 1 }, { "name": "calc_info", "long_name": "calc_info( self )", "filename": "system_info.py", "nloc": 21, "complexity": 5, "token_count": 156, "parameters": [ "self" ], "start_line": 1229, "end_line": 1249, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 21, "top_nesting_level": 1 }, { "name": "get_paths", "long_name": "get_paths( self , section , key )", "filename": "system_info.py", "nloc": 6, "complexity": 4, "token_count": 66, "parameters": [ "self", "section", "key" ], "start_line": 1255, "end_line": 1260, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 6, "top_nesting_level": 1 }, { "name": "calc_info", "long_name": "calc_info( self )", "filename": "system_info.py", "nloc": 22, "complexity": 6, "token_count": 177, "parameters": [ "self" ], "start_line": 1262, "end_line": 1284, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 23, "top_nesting_level": 1 }, { "name": "get_config_exe", "long_name": "get_config_exe( self )", "filename": "system_info.py", "nloc": 4, "complexity": 2, "token_count": 30, "parameters": [ "self" ], "start_line": 1296, "end_line": 1299, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 4, "top_nesting_level": 1 }, { "name": "get_config_output", "long_name": "get_config_output( self , config_exe , option )", "filename": "system_info.py", "nloc": 4, "complexity": 2, "token_count": 37, "parameters": [ "self", "config_exe", "option" ], "start_line": 1300, "end_line": 1303, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 4, "top_nesting_level": 1 }, { "name": "calc_info", "long_name": "calc_info( self )", "filename": "system_info.py", "nloc": 54, "complexity": 22, "token_count": 435, "parameters": [ "self" ], "start_line": 1305, "end_line": 1358, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 54, "top_nesting_level": 1 }, { "name": "combine_paths", "long_name": "combine_paths( * args , ** kws )", "filename": "system_info.py", "nloc": 22, "complexity": 11, "token_count": 195, "parameters": [ "args", "kws" ], "start_line": 1427, "end_line": 1451, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 25, "top_nesting_level": 0 }, { "name": "dict_append", "long_name": "dict_append( d , ** kws )", "filename": "system_info.py", "nloc": 17, "complexity": 9, "token_count": 128, "parameters": [ "d", "kws" ], "start_line": 1455, "end_line": 1471, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 17, "top_nesting_level": 0 }, { "name": "show_all", "long_name": "show_all( )", "filename": "system_info.py", "nloc": 20, "complexity": 8, "token_count": 137, "parameters": [], "start_line": 1473, "end_line": 1492, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 20, "top_nesting_level": 0 } ], "changed_methods": [ { "name": "get_atlas_version", "long_name": "get_atlas_version( ** config )", "filename": "system_info.py", "nloc": 45, "complexity": 9, "token_count": 289, "parameters": [ "config" ], "start_line": 862, "end_line": 916, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 55, "top_nesting_level": 0 } ], "nloc": 1320, "complexity": 285, "token_count": 7302, "diff_parsed": { "added": [ " m = re.search(r'ATLAS version (?P\\d+[.]\\d+[.]\\d+)',o)" ], "deleted": [ " m = re.match(r'ATLAS version (?P\\d+[.]\\d+[.]\\d+)',o)" ] } } ] }, { "hash": "bbeded3ab95b718b3f4da97db7bcba900059744b", "msg": "Removed try/except from imports because it masks problems in the\n\"numerix era\".", "author": { "name": "jmiller", "email": "jmiller@localhost" }, "committer": { "name": "jmiller", "email": "jmiller@localhost" }, "author_date": "2004-12-22T19:27:16+00:00", "author_timezone": 0, "committer_date": "2004-12-22T19:27:16+00:00", "committer_timezone": 0, "branches": [ "main" ], "in_main_branch": true, "merge": false, "parents": [ "6f8a23d5a780568bc05ff238c724409214d2ba52" ], "project_name": "repo_copy", "project_path": "/tmp/tmpqop781_j/repo_copy", "deletions": 8, "insertions": 5, "lines": 13, "files": 1, "dmm_unit_size": null, "dmm_unit_complexity": null, "dmm_unit_interfacing": null, "modified_files": [ { "old_path": "scipy_test/testing.py", "new_path": "scipy_test/testing.py", "filename": "testing.py", "extension": "py", "change_type": "MODIFY", "diff": "@@ -34,14 +34,11 @@\n import types\n import imp\n \n-try:\n- # These are used by Numeric tests.\n- # If Numeric and scipy_base are not available, then some of the\n- # functions below will not be available.\n- from scipy_base.numerix import alltrue, equal, shape, ravel, around, zeros, Float64, asarray\n- from scipy_base.numerix import less_equal, array2string, less, ArrayType\n-except ImportError:\n- pass\n+# These are used by Numeric tests.\n+# If Numeric and scipy_base are not available, then some of the\n+# functions below will not be available.\n+from scipy_base.numerix import alltrue, equal, shape, ravel, around, zeros, Float64, asarray\n+from scipy_base.numerix import less_equal, array2string, less, ArrayType\n \n DEBUG = 0\n \n", "added_lines": 5, "deleted_lines": 8, "source_code": "\"\"\"\nUnit-testing\n------------\n\n ScipyTest -- Scipy tests site manager\n ScipyTestCase -- unittest.TestCase with measure method\n IgnoreException -- raise when checking disabled feature ('ignoring' is displayed)\n set_package_path -- prepend package build directory to path\n set_local_path -- prepend local directory (to tests files) to path\n restore_path -- restore path after set_package_path\n\nTiming tools\n------------\n\n jiffies -- return 1/100ths of a second that the current process has used\n memusage -- virtual memory size in bytes of the running python [linux]\n\nUtility functions\n-----------------\n\n assert_equal -- assert equality\n assert_almost_equal -- assert equality with decimal tolerance\n assert_approx_equal -- assert equality with significant digits tolerance\n assert_array_equal -- assert arrays equality\n assert_array_almost_equal -- assert arrays equality with decimal tolerance\n assert_array_less -- assert arrays less-ordering\n rand -- array of random numbers from given shape\n\n\"\"\"\n\n__all__ = []\n\nimport os,sys,time,glob,string,traceback,unittest\nimport types\nimport imp\n\n# These are used by Numeric tests.\n# If Numeric and scipy_base are not available, then some of the\n# functions below will not be available.\nfrom scipy_base.numerix import alltrue, equal, shape, ravel, around, zeros, Float64, asarray\nfrom scipy_base.numerix import less_equal, array2string, less, ArrayType\n\nDEBUG = 0\n\n__all__.append('set_package_path')\ndef set_package_path(level=1):\n \"\"\" Prepend package directory to sys.path.\n\n set_package_path should be called from a test_file.py that\n satisfies the following tree structure:\n\n //test_file.py\n\n Then the first existing path name from the following list\n\n /build/lib.-\n /..\n\n is prepended to sys.path.\n The caller is responsible for removing this path by using\n\n restore_path()\n \"\"\"\n from distutils.util import get_platform\n from scipy_distutils.misc_util import get_frame\n f = get_frame(level)\n if f.f_locals['__name__']=='__main__':\n testfile = sys.argv[0]\n else:\n testfile = f.f_locals['__file__']\n d = os.path.dirname(os.path.dirname(os.path.abspath(testfile)))\n d1 = os.path.join(d,'build','lib.%s-%s'%(get_platform(),sys.version[:3]))\n if not os.path.isdir(d1):\n d1 = os.path.dirname(d)\n if DEBUG:\n print 'Inserting %r to sys.path' % (d1)\n sys.path.insert(0,d1)\n\n__all__.append('set_local_path')\ndef set_local_path(reldir='', level=1):\n \"\"\" Prepend local directory to sys.path.\n\n The caller is responsible for removing this path by using\n\n restore_path()\n \"\"\"\n from scipy_distutils.misc_util import get_frame\n f = get_frame(level)\n if f.f_locals['__name__']=='__main__':\n testfile = sys.argv[0]\n else:\n testfile = f.f_locals['__file__']\n local_path = os.path.join(os.path.dirname(os.path.abspath(testfile)),reldir)\n if DEBUG:\n print 'Inserting %r to sys.path' % (local_path)\n sys.path.insert(0,local_path)\n\n__all__.append('restore_path')\ndef restore_path():\n if DEBUG:\n print 'Removing %r from sys.path' % (sys.path[0])\n del sys.path[0]\n\n__all__.extend(['jiffies','memusage'])\nif sys.platform[:5]=='linux':\n def jiffies(_proc_pid_stat = '/proc/%s/stat'%(os.getpid()),\n _load_time=time.time()):\n \"\"\" Return number of jiffies (1/100ths of a second) that this\n process has been scheduled in user mode. See man 5 proc. \"\"\"\n try:\n f=open(_proc_pid_stat,'r')\n l = f.readline().split(' ')\n f.close()\n return int(l[13])\n except:\n return int(100*(time.time()-_load_time))\n\n def memusage(_proc_pid_stat = '/proc/%s/stat'%(os.getpid())):\n \"\"\" Return virtual memory size in bytes of the running python.\n \"\"\"\n try:\n f=open(_proc_pid_stat,'r')\n l = f.readline().split(' ')\n f.close()\n return int(l[22])\n except:\n return\nelse:\n # os.getpid is not in all platforms available.\n # Using time is safe but inaccurate, especially when process\n # was suspended or sleeping.\n def jiffies(_load_time=time.time()):\n \"\"\" Return number of jiffies (1/100ths of a second) that this\n process has been scheduled in user mode. [Emulation with time.time]. \"\"\"\n return int(100*(time.time()-_load_time))\n\n def memusage():\n \"\"\" Return memory usage of running python. [Not implemented]\"\"\"\n return\n\n__all__.append('ScipyTestCase')\nclass ScipyTestCase (unittest.TestCase):\n\n def measure(self,code_str,times=1):\n \"\"\" Return elapsed time for executing code_str in the\n namespace of the caller for given times.\n \"\"\"\n frame = sys._getframe(1)\n locs,globs = frame.f_locals,frame.f_globals\n code = compile(code_str,\n 'ScipyTestCase runner for '+self.__class__.__name__,\n 'exec')\n i = 0\n elapsed = jiffies()\n while i>> ScipyTest().test(level=1,verbosity=2)\n\n is package name or its module object.\n\n Package is supposed to contain a directory tests/\n with test_*.py files where * refers to the names of submodules.\n\n test_*.py files are supposed to define a classes, derived\n from ScipyTestCase or unittest.TestCase, with methods having\n names starting with test or bench or check.\n\n And that is it! No need to implement test or test_suite functions\n in each .py file.\n\n Also old styled test_suite(level=1) hooks are supported but\n soon to be removed.\n \"\"\"\n def __init__(self, package='__main__'):\n self.package = package\n\n def _module_str(self, module):\n filename = module.__file__[-30:]\n if filename!=module.__file__:\n filename = '...'+filename\n return '' % (`module.__name__`, `filename`)\n\n def _get_method_names(self,clsobj,level):\n names = []\n for mthname in _get_all_method_names(clsobj):\n if mthname[:5] not in ['bench','check'] \\\n and mthname[:4] not in ['test']:\n continue\n mth = getattr(clsobj, mthname)\n if type(mth) is not types.MethodType:\n continue\n d = mth.im_func.func_defaults\n if d is not None:\n mthlevel = d[0]\n else:\n mthlevel = 1\n if level>=mthlevel:\n if mthname not in names:\n names.append(mthname)\n for base in clsobj.__bases__:\n for n in self._get_method_names(base,level):\n if n not in names:\n names.append(n) \n return names\n\n def _get_module_tests(self,module,level):\n mstr = self._module_str\n d,f = os.path.split(module.__file__)\n\n short_module_name = os.path.splitext(os.path.basename(f))[0]\n if short_module_name=='__init__':\n short_module_name = module.__name__.split('.')[-1]\n\n test_dir = os.path.join(d,'tests')\n test_file = os.path.join(test_dir,'test_'+short_module_name+'.py')\n\n local_test_dir = os.path.join(os.getcwd(),'tests')\n local_test_file = os.path.join(local_test_dir,\n 'test_'+short_module_name+'.py')\n if os.path.basename(os.path.dirname(local_test_dir)) \\\n == os.path.basename(os.path.dirname(test_dir)) \\\n and os.path.isfile(local_test_file):\n test_file = local_test_file\n\n if not os.path.isfile(test_file):\n if short_module_name[:5]=='info_' \\\n and short_module_name[5:]==module.__name__.split('.')[-2]:\n return []\n if short_module_name in ['__cvs_version__','__svn_version__']:\n return []\n if short_module_name[-8:]=='_version' \\\n and short_module_name[:-8]==module.__name__.split('.')[-2]:\n return []\n print ' !! No test file %r found for %s' \\\n % (os.path.basename(test_file), mstr(module))\n return []\n\n try:\n if sys.version[:3]=='2.1':\n # Workaround for Python 2.1 .pyc file generator bug\n import random\n pref = '-nopyc'+`random.randint(1,100)`\n else:\n pref = ''\n f = open(test_file,'r')\n test_module = imp.load_module(\\\n module.__name__+'.test_'+short_module_name+pref,\n f, test_file+pref,('.py', 'r', 1))\n f.close()\n if sys.version[:3]=='2.1' and os.path.isfile(test_file+pref+'c'):\n os.remove(test_file+pref+'c')\n except:\n print ' !! FAILURE importing tests for ', mstr(module)\n print ' ',\n output_exception()\n return []\n return self._get_suite_list(test_module, level, module.__name__)\n\n def _get_suite_list(self, test_module, level, module_name='__main__'):\n mstr = self._module_str\n if hasattr(test_module,'test_suite'):\n # Using old styled test suite\n try:\n total_suite = test_module.test_suite(level)\n return total_suite._tests\n except:\n print ' !! FAILURE building tests for ', mstr(test_module)\n print ' ',\n output_exception()\n return []\n suite_list = []\n for name in dir(test_module):\n obj = getattr(test_module, name)\n if type(obj) is not type(unittest.TestCase) \\\n or not issubclass(obj, unittest.TestCase) \\\n or obj.__name__[:4] != 'test':\n continue\n for mthname in self._get_method_names(obj,level):\n suite = obj(mthname)\n if getattr(suite,'isrunnable',lambda mthname:1)(mthname):\n suite_list.append(suite)\n print ' Found',len(suite_list),'tests for',module_name\n return suite_list\n\n def _touch_ppimported(self, module):\n from scipy_base.ppimport import _ModuleLoader\n if os.path.isdir(os.path.join(os.path.dirname(module.__file__),'tests')):\n # only touching those modules that have tests/ directory\n try: module._pliuh_plauh\n except AttributeError: pass\n for name in dir(module):\n obj = getattr(module,name)\n if isinstance(obj,_ModuleLoader) \\\n and not hasattr(obj,'_ppimport_module') \\\n and not hasattr(obj,'_ppimport_exc_info'):\n self._touch_ppimported(obj)\n\n def test(self,level=1,verbosity=1):\n \"\"\" Run Scipy module test suite with level and verbosity.\n \"\"\"\n if type(self.package) is type(''):\n exec 'import %s as this_package' % (self.package)\n else:\n this_package = self.package\n\n self._touch_ppimported(this_package)\n\n package_name = this_package.__name__\n\n suites = []\n for name, module in sys.modules.items():\n if package_name != name[:len(package_name)] \\\n or module is None \\\n or os.path.basename(os.path.dirname(module.__file__))=='tests':\n continue\n suites.extend(self._get_module_tests(module, level))\n\n suites.extend(self._get_suite_list(sys.modules[package_name], level))\n\n all_tests = unittest.TestSuite(suites)\n runner = unittest.TextTestRunner(verbosity=verbosity)\n runner.run(all_tests)\n return runner\n\n def run(self):\n \"\"\" Run Scipy module test suite with level and verbosity\n taken from sys.argv. Requires optparse module.\n \"\"\"\n try:\n from optparse import OptionParser\n except ImportError:\n print 'Failed to import optparse module, ignoring.'\n return self.test()\n usage = r'usage: %prog [-v ] [-l ]'\n parser = OptionParser(usage)\n parser.add_option(\"-v\", \"--verbosity\",\n action=\"store\",\n dest=\"verbosity\",\n default=1,\n type='int')\n parser.add_option(\"-l\", \"--level\",\n action=\"store\",\n dest=\"level\",\n default=1,\n type='int')\n (options, args) = parser.parse_args()\n self.test(options.level,options.verbosity)\n\n#------------\n \ndef remove_ignored_patterns(files,pattern):\n from fnmatch import fnmatch\n good_files = []\n for file in files:\n if not fnmatch(file,pattern):\n good_files.append(file)\n return good_files\n\ndef remove_ignored_files(original,ignored_files,cur_dir):\n \"\"\" This is actually expanded to do pattern matching.\n\n \"\"\"\n if not ignored_files: ignored_files = []\n ignored_modules = map(lambda x: x+'.py',ignored_files)\n ignored_packages = ignored_files[:]\n # always ignore setup.py and __init__.py files\n ignored_files = ['setup.py','setup_*.py','__init__.py']\n ignored_files += ignored_modules + ignored_packages\n ignored_files = map(lambda x,cur_dir=cur_dir: os.path.join(cur_dir,x),\n ignored_files)\n #print 'ignored:', ignored_files\n #good_files = filter(lambda x,ignored = ignored_files: x not in ignored,\n # original)\n good_files = original\n for pattern in ignored_files:\n good_files = remove_ignored_patterns(good_files,pattern)\n\n return good_files\n\n__all__.append('harvest_modules')\ndef harvest_modules(package,ignore=None):\n \"\"\"* Retreive a list of all modules that live within a package.\n\n Only retreive files that are immediate children of the\n package -- do not recurse through child packages or\n directories. The returned list contains actual modules, not\n just their names.\n *\"\"\"\n d,f = os.path.split(package.__file__)\n\n # go through the directory and import every py file there.\n common_dir = os.path.join(d,'*.py')\n py_files = glob.glob(common_dir)\n #py_files.remove(os.path.join(d,'__init__.py'))\n #py_files.remove(os.path.join(d,'setup.py'))\n\n py_files = remove_ignored_files(py_files,ignore,d)\n #print 'py_files:', py_files\n try:\n prefix = package.__name__\n except:\n prefix = ''\n\n all_modules = []\n for file in py_files:\n d,f = os.path.split(file)\n base,ext = os.path.splitext(f)\n mod = prefix + '.' + base\n #print 'module: import ' + mod\n try:\n exec ('import ' + mod)\n all_modules.append(eval(mod))\n except:\n print 'FAILURE to import ' + mod\n output_exception()\n\n return all_modules\n\n__all__.append('harvest_packages')\ndef harvest_packages(package,ignore = None):\n \"\"\" Retreive a list of all sub-packages that live within a package.\n\n Only retreive packages that are immediate children of this\n package -- do not recurse through child packages or\n directories. The returned list contains actual package objects, not\n just their names.\n \"\"\"\n join = os.path.join\n\n d,f = os.path.split(package.__file__)\n\n common_dir = os.path.abspath(d)\n all_files = os.listdir(d)\n\n all_files = remove_ignored_files(all_files,ignore,'')\n #print 'all_files:', all_files\n try:\n prefix = package.__name__\n except:\n prefix = ''\n all_packages = []\n for directory in all_files:\n path = join(common_dir,directory)\n if os.path.isdir(path) and \\\n os.path.exists(join(path,'__init__.py')):\n sub_package = prefix + '.' + directory\n #print 'sub-package import ' + sub_package\n try:\n exec ('import ' + sub_package)\n all_packages.append(eval(sub_package))\n except:\n print 'FAILURE to import ' + sub_package\n output_exception()\n return all_packages\n\n__all__.append('harvest_modules_and_packages')\ndef harvest_modules_and_packages(package,ignore=None):\n \"\"\" Retreive list of all packages and modules that live within a package.\n\n See harvest_packages() and harvest_modules()\n \"\"\"\n all = harvest_modules(package,ignore) + harvest_packages(package,ignore)\n return all\n\n__all__.append('harvest_test_suites')\ndef harvest_test_suites(package,ignore = None,level=10):\n \"\"\"\n package -- the module to test. This is an actual module object\n (not a string)\n ignore -- a list of module names to omit from the tests\n level -- a value between 1 and 10. 1 will run the minimum number\n of tests. This is a fast \"smoke test\". Tests that take\n longer to run should have higher numbers ranging up to 10.\n \"\"\"\n suites=[]\n test_modules = harvest_modules_and_packages(package,ignore)\n #for i in test_modules:\n # print i.__name__\n for module in test_modules:\n if hasattr(module,'test_suite'):\n try:\n suite = module.test_suite(level=level)\n if suite:\n suites.append(suite)\n else:\n print \" !! FAILURE without error - shouldn't happen\",\n print module.__name__\n except:\n print ' !! FAILURE building test for ', module.__name__\n print ' ',\n output_exception()\n else:\n try:\n print 'No test suite found for ', module.__name__\n except AttributeError:\n # __version__.py getting replaced by a string throws a kink\n # in checking for modules, so we think is a module has\n # actually been overwritten\n print 'No test suite found for ', str(module)\n total_suite = unittest.TestSuite(suites)\n return total_suite\n\n__all__.append('module_test')\ndef module_test(mod_name,mod_file,level=10):\n \"\"\"*\n\n *\"\"\"\n #print 'testing', mod_name\n d,f = os.path.split(mod_file)\n\n # insert the tests directory to the python path\n test_dir = os.path.join(d,'tests')\n sys.path.insert(0,test_dir)\n\n # call the \"test_xxx.test()\" function for the appropriate\n # module.\n\n # This should deal with package naming issues correctly\n short_mod_name = string.split(mod_name,'.')[-1]\n test_module = 'test_' + short_mod_name\n test_string = 'import %s;reload(%s);%s.test(%d)' % \\\n ((test_module,)*3 + (level,))\n\n # This would be better cause it forces a reload of the orginal\n # module. It doesn't behave with packages however.\n #test_string = 'reload(%s);import %s;reload(%s);%s.test(%d)' % \\\n # ((mod_name,) + (test_module,)*3)\n exec(test_string)\n\n # remove test directory from python path.\n sys.path = sys.path[1:]\n\n__all__.append('module_test_suite')\ndef module_test_suite(mod_name,mod_file,level=10):\n #try:\n print ' creating test suite for:', mod_name\n d,f = os.path.split(mod_file)\n\n # insert the tests directory to the python path\n test_dir = os.path.join(d,'tests')\n sys.path.insert(0,test_dir)\n\n # call the \"test_xxx.test()\" function for the appropriate\n # module.\n\n # This should deal with package naming issues correctly\n short_mod_name = string.split(mod_name,'.')[-1]\n test_module = 'test_' + short_mod_name\n test_string = 'import %s;reload(%s);suite = %s.test_suite(%d)' % \\\n ((test_module,)*3+(level,))\n #print test_string\n exec(test_string)\n\n # remove test directory from python path.\n sys.path = sys.path[1:]\n return suite\n #except:\n # print ' !! FAILURE loading test suite from', test_module, ':'\n # print ' ',\n # output_exception()\n\n\n# Utility function to facilitate testing.\n\n__all__.append('assert_equal')\ndef assert_equal(actual,desired,err_msg='',verbose=1):\n \"\"\" Raise an assertion if two items are not\n equal. I think this should be part of unittest.py\n \"\"\"\n if isinstance(actual, ArrayType):\n return assert_array_equal(actual, desired, err_msg)\n msg = '\\nItems are not equal:\\n' + err_msg\n try:\n if ( verbose and len(repr(desired)) < 100 and len(repr(actual)) ):\n msg = msg \\\n + 'DESIRED: ' + repr(desired) \\\n + '\\nACTUAL: ' + repr(actual)\n except:\n msg = msg \\\n + 'DESIRED: ' + repr(desired) \\\n + '\\nACTUAL: ' + repr(actual)\n assert desired == actual, msg\n\n__all__.append('assert_almost_equal')\ndef assert_almost_equal(actual,desired,decimal=7,err_msg='',verbose=1):\n \"\"\" Raise an assertion if two items are not\n equal. I think this should be part of unittest.py\n \"\"\"\n if isinstance(actual, ArrayType):\n return assert_array_almost_equal(actual, desired, decimal, err_msg)\n msg = '\\nItems are not equal:\\n' + err_msg\n try:\n if ( verbose and len(repr(desired)) < 100 and len(repr(actual)) ):\n msg = msg \\\n + 'DESIRED: ' + repr(desired) \\\n + '\\nACTUAL: ' + repr(actual)\n except:\n msg = msg \\\n + 'DESIRED: ' + repr(desired) \\\n + '\\nACTUAL: ' + repr(actual)\n assert round(abs(desired - actual),decimal) == 0, msg\n\n__all__.append('assert_approx_equal')\ndef assert_approx_equal(actual,desired,significant=7,err_msg='',verbose=1):\n \"\"\" Raise an assertion if two items are not\n equal. I think this should be part of unittest.py\n Approximately equal is defined as the number of significant digits\n correct\n \"\"\"\n msg = '\\nItems are not equal to %d significant digits:\\n' % significant\n msg += err_msg\n actual, desired = map(float, (actual, desired))\n # Normalized the numbers to be in range (-10.0,10.0)\n scale = pow(10,math.floor(math.log10(0.5*(abs(desired)+abs(actual)))))\n try:\n sc_desired = desired/scale\n except ZeroDivisionError:\n sc_desired = 0.0\n try:\n sc_actual = actual/scale\n except ZeroDivisionError:\n sc_actual = 0.0\n try:\n if ( verbose and len(repr(desired)) < 100 and len(repr(actual)) ):\n msg = msg \\\n + 'DESIRED: ' + repr(desired) \\\n + '\\nACTUAL: ' + repr(actual)\n except:\n msg = msg \\\n + 'DESIRED: ' + repr(desired) \\\n + '\\nACTUAL: ' + repr(actual)\n assert math.fabs(sc_desired - sc_actual) < pow(10.,-1*significant), msg\n\n\n__all__.append('assert_array_equal')\ndef assert_array_equal(x,y,err_msg=''):\n x,y = asarray(x), asarray(y)\n msg = '\\nArrays are not equal'\n try:\n assert 0 in [len(shape(x)),len(shape(y))] \\\n or (len(shape(x))==len(shape(y)) and \\\n alltrue(equal(shape(x),shape(y)))),\\\n msg + ' (shapes %s, %s mismatch):\\n\\t' \\\n % (shape(x),shape(y)) + err_msg\n reduced = ravel(equal(x,y))\n cond = alltrue(reduced)\n if not cond:\n s1 = array2string(x,precision=16)\n s2 = array2string(y,precision=16)\n if len(s1)>120: s1 = s1[:120] + '...'\n if len(s2)>120: s2 = s2[:120] + '...'\n match = 100-100.0*reduced.tolist().count(1)/len(reduced)\n msg = msg + ' (mismatch %s%%):\\n\\tArray 1: %s\\n\\tArray 2: %s' % (match,s1,s2)\n assert cond,\\\n msg + '\\n\\t' + err_msg\n except ValueError:\n raise ValueError, msg\n\n__all__.append('assert_array_almost_equal')\ndef assert_array_almost_equal(x,y,decimal=6,err_msg=''):\n x = asarray(x)\n y = asarray(y)\n msg = '\\nArrays are not almost equal'\n try:\n cond = alltrue(equal(shape(x),shape(y)))\n if not cond:\n msg = msg + ' (shapes mismatch):\\n\\t'\\\n 'Shape of array 1: %s\\n\\tShape of array 2: %s' % (shape(x),shape(y))\n assert cond, msg + '\\n\\t' + err_msg\n reduced = ravel(equal(less_equal(around(abs(x-y),decimal),10.0**(-decimal)),1))\n cond = alltrue(reduced)\n if not cond:\n s1 = array2string(x,precision=decimal+1)\n s2 = array2string(y,precision=decimal+1)\n if len(s1)>120: s1 = s1[:120] + '...'\n if len(s2)>120: s2 = s2[:120] + '...'\n match = 100-100.0*reduced.tolist().count(1)/len(reduced)\n msg = msg + ' (mismatch %s%%):\\n\\tArray 1: %s\\n\\tArray 2: %s' % (match,s1,s2)\n assert cond,\\\n msg + '\\n\\t' + err_msg\n except ValueError:\n print sys.exc_value\n print shape(x),shape(y)\n print x, y\n raise ValueError, 'arrays are not almost equal'\n\n__all__.append('assert_array_less')\ndef assert_array_less(x,y,err_msg=''):\n x,y = asarray(x), asarray(y)\n msg = '\\nArrays are not less-ordered'\n try:\n assert alltrue(equal(shape(x),shape(y))),\\\n msg + ' (shapes mismatch):\\n\\t' + err_msg\n reduced = ravel(less(x,y))\n cond = alltrue(reduced)\n if not cond:\n s1 = array2string(x,precision=16)\n s2 = array2string(y,precision=16)\n if len(s1)>120: s1 = s1[:120] + '...'\n if len(s2)>120: s2 = s2[:120] + '...'\n match = 100-100.0*reduced.tolist().count(1)/len(reduced)\n msg = msg + ' (mismatch %s%%):\\n\\tArray 1: %s\\n\\tArray 2: %s' % (match,s1,s2)\n assert cond,\\\n msg + '\\n\\t' + err_msg\n except ValueError:\n print shape(x),shape(y)\n raise ValueError, 'arrays are not less-ordered'\n\n__all__.append('rand')\ndef rand(*args):\n \"\"\" Returns an array of random numbers with the given shape.\n used for testing\n \"\"\"\n import random\n results = zeros(args,Float64)\n f = results.flat\n for i in range(len(f)):\n f[i] = random.random()\n return results\n\ndef output_exception():\n try:\n type, value, tb = sys.exc_info()\n info = traceback.extract_tb(tb)\n #this is more verbose\n #traceback.print_exc()\n filename, lineno, function, text = info[-1] # last line only\n print \"%s:%d: %s: %s (in %s)\" %\\\n (filename, lineno, type.__name__, str(value), function)\n finally:\n type = value = tb = None # clean up\n\ntry:\n from scipy_base.numerix import fastumath as math\nexcept ImportError,msg:\n print msg\n import math\n", "source_code_before": "\"\"\"\nUnit-testing\n------------\n\n ScipyTest -- Scipy tests site manager\n ScipyTestCase -- unittest.TestCase with measure method\n IgnoreException -- raise when checking disabled feature ('ignoring' is displayed)\n set_package_path -- prepend package build directory to path\n set_local_path -- prepend local directory (to tests files) to path\n restore_path -- restore path after set_package_path\n\nTiming tools\n------------\n\n jiffies -- return 1/100ths of a second that the current process has used\n memusage -- virtual memory size in bytes of the running python [linux]\n\nUtility functions\n-----------------\n\n assert_equal -- assert equality\n assert_almost_equal -- assert equality with decimal tolerance\n assert_approx_equal -- assert equality with significant digits tolerance\n assert_array_equal -- assert arrays equality\n assert_array_almost_equal -- assert arrays equality with decimal tolerance\n assert_array_less -- assert arrays less-ordering\n rand -- array of random numbers from given shape\n\n\"\"\"\n\n__all__ = []\n\nimport os,sys,time,glob,string,traceback,unittest\nimport types\nimport imp\n\ntry:\n # These are used by Numeric tests.\n # If Numeric and scipy_base are not available, then some of the\n # functions below will not be available.\n from scipy_base.numerix import alltrue, equal, shape, ravel, around, zeros, Float64, asarray\n from scipy_base.numerix import less_equal, array2string, less, ArrayType\nexcept ImportError:\n pass\n\nDEBUG = 0\n\n__all__.append('set_package_path')\ndef set_package_path(level=1):\n \"\"\" Prepend package directory to sys.path.\n\n set_package_path should be called from a test_file.py that\n satisfies the following tree structure:\n\n //test_file.py\n\n Then the first existing path name from the following list\n\n /build/lib.-\n /..\n\n is prepended to sys.path.\n The caller is responsible for removing this path by using\n\n restore_path()\n \"\"\"\n from distutils.util import get_platform\n from scipy_distutils.misc_util import get_frame\n f = get_frame(level)\n if f.f_locals['__name__']=='__main__':\n testfile = sys.argv[0]\n else:\n testfile = f.f_locals['__file__']\n d = os.path.dirname(os.path.dirname(os.path.abspath(testfile)))\n d1 = os.path.join(d,'build','lib.%s-%s'%(get_platform(),sys.version[:3]))\n if not os.path.isdir(d1):\n d1 = os.path.dirname(d)\n if DEBUG:\n print 'Inserting %r to sys.path' % (d1)\n sys.path.insert(0,d1)\n\n__all__.append('set_local_path')\ndef set_local_path(reldir='', level=1):\n \"\"\" Prepend local directory to sys.path.\n\n The caller is responsible for removing this path by using\n\n restore_path()\n \"\"\"\n from scipy_distutils.misc_util import get_frame\n f = get_frame(level)\n if f.f_locals['__name__']=='__main__':\n testfile = sys.argv[0]\n else:\n testfile = f.f_locals['__file__']\n local_path = os.path.join(os.path.dirname(os.path.abspath(testfile)),reldir)\n if DEBUG:\n print 'Inserting %r to sys.path' % (local_path)\n sys.path.insert(0,local_path)\n\n__all__.append('restore_path')\ndef restore_path():\n if DEBUG:\n print 'Removing %r from sys.path' % (sys.path[0])\n del sys.path[0]\n\n__all__.extend(['jiffies','memusage'])\nif sys.platform[:5]=='linux':\n def jiffies(_proc_pid_stat = '/proc/%s/stat'%(os.getpid()),\n _load_time=time.time()):\n \"\"\" Return number of jiffies (1/100ths of a second) that this\n process has been scheduled in user mode. See man 5 proc. \"\"\"\n try:\n f=open(_proc_pid_stat,'r')\n l = f.readline().split(' ')\n f.close()\n return int(l[13])\n except:\n return int(100*(time.time()-_load_time))\n\n def memusage(_proc_pid_stat = '/proc/%s/stat'%(os.getpid())):\n \"\"\" Return virtual memory size in bytes of the running python.\n \"\"\"\n try:\n f=open(_proc_pid_stat,'r')\n l = f.readline().split(' ')\n f.close()\n return int(l[22])\n except:\n return\nelse:\n # os.getpid is not in all platforms available.\n # Using time is safe but inaccurate, especially when process\n # was suspended or sleeping.\n def jiffies(_load_time=time.time()):\n \"\"\" Return number of jiffies (1/100ths of a second) that this\n process has been scheduled in user mode. [Emulation with time.time]. \"\"\"\n return int(100*(time.time()-_load_time))\n\n def memusage():\n \"\"\" Return memory usage of running python. [Not implemented]\"\"\"\n return\n\n__all__.append('ScipyTestCase')\nclass ScipyTestCase (unittest.TestCase):\n\n def measure(self,code_str,times=1):\n \"\"\" Return elapsed time for executing code_str in the\n namespace of the caller for given times.\n \"\"\"\n frame = sys._getframe(1)\n locs,globs = frame.f_locals,frame.f_globals\n code = compile(code_str,\n 'ScipyTestCase runner for '+self.__class__.__name__,\n 'exec')\n i = 0\n elapsed = jiffies()\n while i>> ScipyTest().test(level=1,verbosity=2)\n\n is package name or its module object.\n\n Package is supposed to contain a directory tests/\n with test_*.py files where * refers to the names of submodules.\n\n test_*.py files are supposed to define a classes, derived\n from ScipyTestCase or unittest.TestCase, with methods having\n names starting with test or bench or check.\n\n And that is it! No need to implement test or test_suite functions\n in each .py file.\n\n Also old styled test_suite(level=1) hooks are supported but\n soon to be removed.\n \"\"\"\n def __init__(self, package='__main__'):\n self.package = package\n\n def _module_str(self, module):\n filename = module.__file__[-30:]\n if filename!=module.__file__:\n filename = '...'+filename\n return '' % (`module.__name__`, `filename`)\n\n def _get_method_names(self,clsobj,level):\n names = []\n for mthname in _get_all_method_names(clsobj):\n if mthname[:5] not in ['bench','check'] \\\n and mthname[:4] not in ['test']:\n continue\n mth = getattr(clsobj, mthname)\n if type(mth) is not types.MethodType:\n continue\n d = mth.im_func.func_defaults\n if d is not None:\n mthlevel = d[0]\n else:\n mthlevel = 1\n if level>=mthlevel:\n if mthname not in names:\n names.append(mthname)\n for base in clsobj.__bases__:\n for n in self._get_method_names(base,level):\n if n not in names:\n names.append(n) \n return names\n\n def _get_module_tests(self,module,level):\n mstr = self._module_str\n d,f = os.path.split(module.__file__)\n\n short_module_name = os.path.splitext(os.path.basename(f))[0]\n if short_module_name=='__init__':\n short_module_name = module.__name__.split('.')[-1]\n\n test_dir = os.path.join(d,'tests')\n test_file = os.path.join(test_dir,'test_'+short_module_name+'.py')\n\n local_test_dir = os.path.join(os.getcwd(),'tests')\n local_test_file = os.path.join(local_test_dir,\n 'test_'+short_module_name+'.py')\n if os.path.basename(os.path.dirname(local_test_dir)) \\\n == os.path.basename(os.path.dirname(test_dir)) \\\n and os.path.isfile(local_test_file):\n test_file = local_test_file\n\n if not os.path.isfile(test_file):\n if short_module_name[:5]=='info_' \\\n and short_module_name[5:]==module.__name__.split('.')[-2]:\n return []\n if short_module_name in ['__cvs_version__','__svn_version__']:\n return []\n if short_module_name[-8:]=='_version' \\\n and short_module_name[:-8]==module.__name__.split('.')[-2]:\n return []\n print ' !! No test file %r found for %s' \\\n % (os.path.basename(test_file), mstr(module))\n return []\n\n try:\n if sys.version[:3]=='2.1':\n # Workaround for Python 2.1 .pyc file generator bug\n import random\n pref = '-nopyc'+`random.randint(1,100)`\n else:\n pref = ''\n f = open(test_file,'r')\n test_module = imp.load_module(\\\n module.__name__+'.test_'+short_module_name+pref,\n f, test_file+pref,('.py', 'r', 1))\n f.close()\n if sys.version[:3]=='2.1' and os.path.isfile(test_file+pref+'c'):\n os.remove(test_file+pref+'c')\n except:\n print ' !! FAILURE importing tests for ', mstr(module)\n print ' ',\n output_exception()\n return []\n return self._get_suite_list(test_module, level, module.__name__)\n\n def _get_suite_list(self, test_module, level, module_name='__main__'):\n mstr = self._module_str\n if hasattr(test_module,'test_suite'):\n # Using old styled test suite\n try:\n total_suite = test_module.test_suite(level)\n return total_suite._tests\n except:\n print ' !! FAILURE building tests for ', mstr(test_module)\n print ' ',\n output_exception()\n return []\n suite_list = []\n for name in dir(test_module):\n obj = getattr(test_module, name)\n if type(obj) is not type(unittest.TestCase) \\\n or not issubclass(obj, unittest.TestCase) \\\n or obj.__name__[:4] != 'test':\n continue\n for mthname in self._get_method_names(obj,level):\n suite = obj(mthname)\n if getattr(suite,'isrunnable',lambda mthname:1)(mthname):\n suite_list.append(suite)\n print ' Found',len(suite_list),'tests for',module_name\n return suite_list\n\n def _touch_ppimported(self, module):\n from scipy_base.ppimport import _ModuleLoader\n if os.path.isdir(os.path.join(os.path.dirname(module.__file__),'tests')):\n # only touching those modules that have tests/ directory\n try: module._pliuh_plauh\n except AttributeError: pass\n for name in dir(module):\n obj = getattr(module,name)\n if isinstance(obj,_ModuleLoader) \\\n and not hasattr(obj,'_ppimport_module') \\\n and not hasattr(obj,'_ppimport_exc_info'):\n self._touch_ppimported(obj)\n\n def test(self,level=1,verbosity=1):\n \"\"\" Run Scipy module test suite with level and verbosity.\n \"\"\"\n if type(self.package) is type(''):\n exec 'import %s as this_package' % (self.package)\n else:\n this_package = self.package\n\n self._touch_ppimported(this_package)\n\n package_name = this_package.__name__\n\n suites = []\n for name, module in sys.modules.items():\n if package_name != name[:len(package_name)] \\\n or module is None \\\n or os.path.basename(os.path.dirname(module.__file__))=='tests':\n continue\n suites.extend(self._get_module_tests(module, level))\n\n suites.extend(self._get_suite_list(sys.modules[package_name], level))\n\n all_tests = unittest.TestSuite(suites)\n runner = unittest.TextTestRunner(verbosity=verbosity)\n runner.run(all_tests)\n return runner\n\n def run(self):\n \"\"\" Run Scipy module test suite with level and verbosity\n taken from sys.argv. Requires optparse module.\n \"\"\"\n try:\n from optparse import OptionParser\n except ImportError:\n print 'Failed to import optparse module, ignoring.'\n return self.test()\n usage = r'usage: %prog [-v ] [-l ]'\n parser = OptionParser(usage)\n parser.add_option(\"-v\", \"--verbosity\",\n action=\"store\",\n dest=\"verbosity\",\n default=1,\n type='int')\n parser.add_option(\"-l\", \"--level\",\n action=\"store\",\n dest=\"level\",\n default=1,\n type='int')\n (options, args) = parser.parse_args()\n self.test(options.level,options.verbosity)\n\n#------------\n \ndef remove_ignored_patterns(files,pattern):\n from fnmatch import fnmatch\n good_files = []\n for file in files:\n if not fnmatch(file,pattern):\n good_files.append(file)\n return good_files\n\ndef remove_ignored_files(original,ignored_files,cur_dir):\n \"\"\" This is actually expanded to do pattern matching.\n\n \"\"\"\n if not ignored_files: ignored_files = []\n ignored_modules = map(lambda x: x+'.py',ignored_files)\n ignored_packages = ignored_files[:]\n # always ignore setup.py and __init__.py files\n ignored_files = ['setup.py','setup_*.py','__init__.py']\n ignored_files += ignored_modules + ignored_packages\n ignored_files = map(lambda x,cur_dir=cur_dir: os.path.join(cur_dir,x),\n ignored_files)\n #print 'ignored:', ignored_files\n #good_files = filter(lambda x,ignored = ignored_files: x not in ignored,\n # original)\n good_files = original\n for pattern in ignored_files:\n good_files = remove_ignored_patterns(good_files,pattern)\n\n return good_files\n\n__all__.append('harvest_modules')\ndef harvest_modules(package,ignore=None):\n \"\"\"* Retreive a list of all modules that live within a package.\n\n Only retreive files that are immediate children of the\n package -- do not recurse through child packages or\n directories. The returned list contains actual modules, not\n just their names.\n *\"\"\"\n d,f = os.path.split(package.__file__)\n\n # go through the directory and import every py file there.\n common_dir = os.path.join(d,'*.py')\n py_files = glob.glob(common_dir)\n #py_files.remove(os.path.join(d,'__init__.py'))\n #py_files.remove(os.path.join(d,'setup.py'))\n\n py_files = remove_ignored_files(py_files,ignore,d)\n #print 'py_files:', py_files\n try:\n prefix = package.__name__\n except:\n prefix = ''\n\n all_modules = []\n for file in py_files:\n d,f = os.path.split(file)\n base,ext = os.path.splitext(f)\n mod = prefix + '.' + base\n #print 'module: import ' + mod\n try:\n exec ('import ' + mod)\n all_modules.append(eval(mod))\n except:\n print 'FAILURE to import ' + mod\n output_exception()\n\n return all_modules\n\n__all__.append('harvest_packages')\ndef harvest_packages(package,ignore = None):\n \"\"\" Retreive a list of all sub-packages that live within a package.\n\n Only retreive packages that are immediate children of this\n package -- do not recurse through child packages or\n directories. The returned list contains actual package objects, not\n just their names.\n \"\"\"\n join = os.path.join\n\n d,f = os.path.split(package.__file__)\n\n common_dir = os.path.abspath(d)\n all_files = os.listdir(d)\n\n all_files = remove_ignored_files(all_files,ignore,'')\n #print 'all_files:', all_files\n try:\n prefix = package.__name__\n except:\n prefix = ''\n all_packages = []\n for directory in all_files:\n path = join(common_dir,directory)\n if os.path.isdir(path) and \\\n os.path.exists(join(path,'__init__.py')):\n sub_package = prefix + '.' + directory\n #print 'sub-package import ' + sub_package\n try:\n exec ('import ' + sub_package)\n all_packages.append(eval(sub_package))\n except:\n print 'FAILURE to import ' + sub_package\n output_exception()\n return all_packages\n\n__all__.append('harvest_modules_and_packages')\ndef harvest_modules_and_packages(package,ignore=None):\n \"\"\" Retreive list of all packages and modules that live within a package.\n\n See harvest_packages() and harvest_modules()\n \"\"\"\n all = harvest_modules(package,ignore) + harvest_packages(package,ignore)\n return all\n\n__all__.append('harvest_test_suites')\ndef harvest_test_suites(package,ignore = None,level=10):\n \"\"\"\n package -- the module to test. This is an actual module object\n (not a string)\n ignore -- a list of module names to omit from the tests\n level -- a value between 1 and 10. 1 will run the minimum number\n of tests. This is a fast \"smoke test\". Tests that take\n longer to run should have higher numbers ranging up to 10.\n \"\"\"\n suites=[]\n test_modules = harvest_modules_and_packages(package,ignore)\n #for i in test_modules:\n # print i.__name__\n for module in test_modules:\n if hasattr(module,'test_suite'):\n try:\n suite = module.test_suite(level=level)\n if suite:\n suites.append(suite)\n else:\n print \" !! FAILURE without error - shouldn't happen\",\n print module.__name__\n except:\n print ' !! FAILURE building test for ', module.__name__\n print ' ',\n output_exception()\n else:\n try:\n print 'No test suite found for ', module.__name__\n except AttributeError:\n # __version__.py getting replaced by a string throws a kink\n # in checking for modules, so we think is a module has\n # actually been overwritten\n print 'No test suite found for ', str(module)\n total_suite = unittest.TestSuite(suites)\n return total_suite\n\n__all__.append('module_test')\ndef module_test(mod_name,mod_file,level=10):\n \"\"\"*\n\n *\"\"\"\n #print 'testing', mod_name\n d,f = os.path.split(mod_file)\n\n # insert the tests directory to the python path\n test_dir = os.path.join(d,'tests')\n sys.path.insert(0,test_dir)\n\n # call the \"test_xxx.test()\" function for the appropriate\n # module.\n\n # This should deal with package naming issues correctly\n short_mod_name = string.split(mod_name,'.')[-1]\n test_module = 'test_' + short_mod_name\n test_string = 'import %s;reload(%s);%s.test(%d)' % \\\n ((test_module,)*3 + (level,))\n\n # This would be better cause it forces a reload of the orginal\n # module. It doesn't behave with packages however.\n #test_string = 'reload(%s);import %s;reload(%s);%s.test(%d)' % \\\n # ((mod_name,) + (test_module,)*3)\n exec(test_string)\n\n # remove test directory from python path.\n sys.path = sys.path[1:]\n\n__all__.append('module_test_suite')\ndef module_test_suite(mod_name,mod_file,level=10):\n #try:\n print ' creating test suite for:', mod_name\n d,f = os.path.split(mod_file)\n\n # insert the tests directory to the python path\n test_dir = os.path.join(d,'tests')\n sys.path.insert(0,test_dir)\n\n # call the \"test_xxx.test()\" function for the appropriate\n # module.\n\n # This should deal with package naming issues correctly\n short_mod_name = string.split(mod_name,'.')[-1]\n test_module = 'test_' + short_mod_name\n test_string = 'import %s;reload(%s);suite = %s.test_suite(%d)' % \\\n ((test_module,)*3+(level,))\n #print test_string\n exec(test_string)\n\n # remove test directory from python path.\n sys.path = sys.path[1:]\n return suite\n #except:\n # print ' !! FAILURE loading test suite from', test_module, ':'\n # print ' ',\n # output_exception()\n\n\n# Utility function to facilitate testing.\n\n__all__.append('assert_equal')\ndef assert_equal(actual,desired,err_msg='',verbose=1):\n \"\"\" Raise an assertion if two items are not\n equal. I think this should be part of unittest.py\n \"\"\"\n if isinstance(actual, ArrayType):\n return assert_array_equal(actual, desired, err_msg)\n msg = '\\nItems are not equal:\\n' + err_msg\n try:\n if ( verbose and len(repr(desired)) < 100 and len(repr(actual)) ):\n msg = msg \\\n + 'DESIRED: ' + repr(desired) \\\n + '\\nACTUAL: ' + repr(actual)\n except:\n msg = msg \\\n + 'DESIRED: ' + repr(desired) \\\n + '\\nACTUAL: ' + repr(actual)\n assert desired == actual, msg\n\n__all__.append('assert_almost_equal')\ndef assert_almost_equal(actual,desired,decimal=7,err_msg='',verbose=1):\n \"\"\" Raise an assertion if two items are not\n equal. I think this should be part of unittest.py\n \"\"\"\n if isinstance(actual, ArrayType):\n return assert_array_almost_equal(actual, desired, decimal, err_msg)\n msg = '\\nItems are not equal:\\n' + err_msg\n try:\n if ( verbose and len(repr(desired)) < 100 and len(repr(actual)) ):\n msg = msg \\\n + 'DESIRED: ' + repr(desired) \\\n + '\\nACTUAL: ' + repr(actual)\n except:\n msg = msg \\\n + 'DESIRED: ' + repr(desired) \\\n + '\\nACTUAL: ' + repr(actual)\n assert round(abs(desired - actual),decimal) == 0, msg\n\n__all__.append('assert_approx_equal')\ndef assert_approx_equal(actual,desired,significant=7,err_msg='',verbose=1):\n \"\"\" Raise an assertion if two items are not\n equal. I think this should be part of unittest.py\n Approximately equal is defined as the number of significant digits\n correct\n \"\"\"\n msg = '\\nItems are not equal to %d significant digits:\\n' % significant\n msg += err_msg\n actual, desired = map(float, (actual, desired))\n # Normalized the numbers to be in range (-10.0,10.0)\n scale = pow(10,math.floor(math.log10(0.5*(abs(desired)+abs(actual)))))\n try:\n sc_desired = desired/scale\n except ZeroDivisionError:\n sc_desired = 0.0\n try:\n sc_actual = actual/scale\n except ZeroDivisionError:\n sc_actual = 0.0\n try:\n if ( verbose and len(repr(desired)) < 100 and len(repr(actual)) ):\n msg = msg \\\n + 'DESIRED: ' + repr(desired) \\\n + '\\nACTUAL: ' + repr(actual)\n except:\n msg = msg \\\n + 'DESIRED: ' + repr(desired) \\\n + '\\nACTUAL: ' + repr(actual)\n assert math.fabs(sc_desired - sc_actual) < pow(10.,-1*significant), msg\n\n\n__all__.append('assert_array_equal')\ndef assert_array_equal(x,y,err_msg=''):\n x,y = asarray(x), asarray(y)\n msg = '\\nArrays are not equal'\n try:\n assert 0 in [len(shape(x)),len(shape(y))] \\\n or (len(shape(x))==len(shape(y)) and \\\n alltrue(equal(shape(x),shape(y)))),\\\n msg + ' (shapes %s, %s mismatch):\\n\\t' \\\n % (shape(x),shape(y)) + err_msg\n reduced = ravel(equal(x,y))\n cond = alltrue(reduced)\n if not cond:\n s1 = array2string(x,precision=16)\n s2 = array2string(y,precision=16)\n if len(s1)>120: s1 = s1[:120] + '...'\n if len(s2)>120: s2 = s2[:120] + '...'\n match = 100-100.0*reduced.tolist().count(1)/len(reduced)\n msg = msg + ' (mismatch %s%%):\\n\\tArray 1: %s\\n\\tArray 2: %s' % (match,s1,s2)\n assert cond,\\\n msg + '\\n\\t' + err_msg\n except ValueError:\n raise ValueError, msg\n\n__all__.append('assert_array_almost_equal')\ndef assert_array_almost_equal(x,y,decimal=6,err_msg=''):\n x = asarray(x)\n y = asarray(y)\n msg = '\\nArrays are not almost equal'\n try:\n cond = alltrue(equal(shape(x),shape(y)))\n if not cond:\n msg = msg + ' (shapes mismatch):\\n\\t'\\\n 'Shape of array 1: %s\\n\\tShape of array 2: %s' % (shape(x),shape(y))\n assert cond, msg + '\\n\\t' + err_msg\n reduced = ravel(equal(less_equal(around(abs(x-y),decimal),10.0**(-decimal)),1))\n cond = alltrue(reduced)\n if not cond:\n s1 = array2string(x,precision=decimal+1)\n s2 = array2string(y,precision=decimal+1)\n if len(s1)>120: s1 = s1[:120] + '...'\n if len(s2)>120: s2 = s2[:120] + '...'\n match = 100-100.0*reduced.tolist().count(1)/len(reduced)\n msg = msg + ' (mismatch %s%%):\\n\\tArray 1: %s\\n\\tArray 2: %s' % (match,s1,s2)\n assert cond,\\\n msg + '\\n\\t' + err_msg\n except ValueError:\n print sys.exc_value\n print shape(x),shape(y)\n print x, y\n raise ValueError, 'arrays are not almost equal'\n\n__all__.append('assert_array_less')\ndef assert_array_less(x,y,err_msg=''):\n x,y = asarray(x), asarray(y)\n msg = '\\nArrays are not less-ordered'\n try:\n assert alltrue(equal(shape(x),shape(y))),\\\n msg + ' (shapes mismatch):\\n\\t' + err_msg\n reduced = ravel(less(x,y))\n cond = alltrue(reduced)\n if not cond:\n s1 = array2string(x,precision=16)\n s2 = array2string(y,precision=16)\n if len(s1)>120: s1 = s1[:120] + '...'\n if len(s2)>120: s2 = s2[:120] + '...'\n match = 100-100.0*reduced.tolist().count(1)/len(reduced)\n msg = msg + ' (mismatch %s%%):\\n\\tArray 1: %s\\n\\tArray 2: %s' % (match,s1,s2)\n assert cond,\\\n msg + '\\n\\t' + err_msg\n except ValueError:\n print shape(x),shape(y)\n raise ValueError, 'arrays are not less-ordered'\n\n__all__.append('rand')\ndef rand(*args):\n \"\"\" Returns an array of random numbers with the given shape.\n used for testing\n \"\"\"\n import random\n results = zeros(args,Float64)\n f = results.flat\n for i in range(len(f)):\n f[i] = random.random()\n return results\n\ndef output_exception():\n try:\n type, value, tb = sys.exc_info()\n info = traceback.extract_tb(tb)\n #this is more verbose\n #traceback.print_exc()\n filename, lineno, function, text = info[-1] # last line only\n print \"%s:%d: %s: %s (in %s)\" %\\\n (filename, lineno, type.__name__, str(value), function)\n finally:\n type = value = tb = None # clean up\n\ntry:\n from scipy_base.numerix import fastumath as math\nexcept ImportError,msg:\n print msg\n import math\n", "methods": [ { "name": "set_package_path", "long_name": "set_package_path( level = 1 )", "filename": "testing.py", "nloc": 15, "complexity": 4, "token_count": 146, "parameters": [ "level" ], "start_line": 46, "end_line": 77, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 32, "top_nesting_level": 0 }, { "name": "set_local_path", "long_name": "set_local_path( reldir = '' , level = 1 )", "filename": "testing.py", "nloc": 11, "complexity": 3, "token_count": 97, "parameters": [ "reldir", "level" ], "start_line": 80, "end_line": 96, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 17, "top_nesting_level": 0 }, { "name": "restore_path", "long_name": "restore_path( )", "filename": "testing.py", "nloc": 4, "complexity": 2, "token_count": 25, "parameters": [], "start_line": 99, "end_line": 102, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 4, "top_nesting_level": 0 }, { "name": "jiffies", "long_name": "jiffies( _proc_pid_stat = '/proc/%s/stat' % ( os . getpid ( )", "filename": "testing.py", "nloc": 2, "complexity": 1, "token_count": 23, "parameters": [ "_proc_pid_stat" ], "start_line": 106, "end_line": 107, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 2, "top_nesting_level": 1 }, { "name": "memusage", "long_name": "memusage( _proc_pid_stat = '/proc/%s/stat' % ( os . getpid ( )", "filename": "testing.py", "nloc": 10, "complexity": 2, "token_count": 54, "parameters": [ "_proc_pid_stat" ], "start_line": 118, "end_line": 127, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 10, "top_nesting_level": 1 }, { "name": "jiffies", "long_name": "jiffies( _load_time = time . time ( )", "filename": "testing.py", "nloc": 4, "complexity": 1, "token_count": 27, "parameters": [ "_load_time" ], "start_line": 132, "end_line": 135, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 4, "top_nesting_level": 1 }, { "name": "memusage", "long_name": "memusage( )", "filename": "testing.py", "nloc": 2, "complexity": 1, "token_count": 6, "parameters": [], "start_line": 137, "end_line": 139, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 3, "top_nesting_level": 1 }, { "name": "measure", "long_name": "measure( self , code_str , times = 1 )", "filename": "testing.py", "nloc": 13, "complexity": 2, "token_count": 82, "parameters": [ "self", "code_str", "times" ], "start_line": 144, "end_line": 159, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 16, "top_nesting_level": 1 }, { "name": "__call__", "long_name": "__call__( self , result = None )", "filename": "testing.py", "nloc": 24, "complexity": 6, "token_count": 224, "parameters": [ "self", "result" ], "start_line": 161, "end_line": 185, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 25, "top_nesting_level": 1 }, { "name": "__init__", "long_name": "__init__( self , stream )", "filename": "testing.py", "nloc": 3, "complexity": 1, "token_count": 18, "parameters": [ "self", "stream" ], "start_line": 188, "end_line": 190, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 3, "top_nesting_level": 1 }, { "name": "write", "long_name": "write( self , message )", "filename": "testing.py", "nloc": 6, "complexity": 3, "token_count": 47, "parameters": [ "self", "message" ], "start_line": 191, "end_line": 196, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 6, "top_nesting_level": 1 }, { "name": "writeln", "long_name": "writeln( self , message )", "filename": "testing.py", "nloc": 2, "complexity": 1, "token_count": 15, "parameters": [ "self", "message" ], "start_line": 197, "end_line": 198, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 2, "top_nesting_level": 1 }, { "name": "_get_all_method_names", "long_name": "_get_all_method_names( cls )", "filename": "testing.py", "nloc": 8, "complexity": 5, "token_count": 56, "parameters": [ "cls" ], "start_line": 206, "end_line": 213, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 8, "top_nesting_level": 0 }, { "name": "__init__", "long_name": "__init__( self , package = '__main__' )", "filename": "testing.py", "nloc": 2, "complexity": 1, "token_count": 14, "parameters": [ "self", "package" ], "start_line": 237, "end_line": 238, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 2, "top_nesting_level": 1 }, { "name": "_module_str", "long_name": "_module_str( self , module )", "filename": "testing.py", "nloc": 5, "complexity": 2, "token_count": 43, "parameters": [ "self", "module" ], "start_line": 240, "end_line": 244, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 5, "top_nesting_level": 1 }, { "name": "_get_method_names", "long_name": "_get_method_names( self , clsobj , level )", "filename": "testing.py", "nloc": 22, "complexity": 11, "token_count": 142, "parameters": [ "self", "clsobj", "level" ], "start_line": 246, "end_line": 267, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 22, "top_nesting_level": 1 }, { "name": "_get_module_tests", "long_name": "_get_module_tests( self , module , level )", "filename": "testing.py", "nloc": 46, "complexity": 14, "token_count": 428, "parameters": [ "self", "module", "level" ], "start_line": 269, "end_line": 320, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 52, "top_nesting_level": 1 }, { "name": "_get_suite_list", "long_name": "_get_suite_list( self , test_module , level , module_name = '__main__' )", "filename": "testing.py", "nloc": 24, "complexity": 9, "token_count": 168, "parameters": [ "self", "test_module", "level", "module_name" ], "start_line": 322, "end_line": 346, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 25, "top_nesting_level": 1 }, { "name": "_touch_ppimported", "long_name": "_touch_ppimported( self , module )", "filename": "testing.py", "nloc": 11, "complexity": 7, "token_count": 98, "parameters": [ "self", "module" ], "start_line": 348, "end_line": 359, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 12, "top_nesting_level": 1 }, { "name": "test", "long_name": "test( self , level = 1 , verbosity = 1 )", "filename": "testing.py", "nloc": 19, "complexity": 6, "token_count": 166, "parameters": [ "self", "level", "verbosity" ], "start_line": 361, "end_line": 386, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 26, "top_nesting_level": 1 }, { "name": "run", "long_name": "run( self )", "filename": "testing.py", "nloc": 20, "complexity": 2, "token_count": 104, "parameters": [ "self" ], "start_line": 388, "end_line": 410, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 23, "top_nesting_level": 1 }, { "name": "remove_ignored_patterns", "long_name": "remove_ignored_patterns( files , pattern )", "filename": "testing.py", "nloc": 7, "complexity": 3, "token_count": 37, "parameters": [ "files", "pattern" ], "start_line": 414, "end_line": 420, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 7, "top_nesting_level": 0 }, { "name": "remove_ignored_files", "long_name": "remove_ignored_files( original , ignored_files , cur_dir )", "filename": "testing.py", "nloc": 12, "complexity": 3, "token_count": 93, "parameters": [ "original", "ignored_files", "cur_dir" ], "start_line": 422, "end_line": 441, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 20, "top_nesting_level": 0 }, { "name": "harvest_modules", "long_name": "harvest_modules( package , ignore = None )", "filename": "testing.py", "nloc": 21, "complexity": 4, "token_count": 134, "parameters": [ "package", "ignore" ], "start_line": 444, "end_line": 480, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 37, "top_nesting_level": 0 }, { "name": "harvest_packages", "long_name": "harvest_packages( package , ignore = None )", "filename": "testing.py", "nloc": 23, "complexity": 6, "token_count": 148, "parameters": [ "package", "ignore" ], "start_line": 483, "end_line": 517, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 35, "top_nesting_level": 0 }, { "name": "harvest_modules_and_packages", "long_name": "harvest_modules_and_packages( package , ignore = None )", "filename": "testing.py", "nloc": 3, "complexity": 1, "token_count": 27, "parameters": [ "package", "ignore" ], "start_line": 520, "end_line": 526, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 7, "top_nesting_level": 0 }, { "name": "harvest_test_suites", "long_name": "harvest_test_suites( package , ignore = None , level = 10 )", "filename": "testing.py", "nloc": 23, "complexity": 6, "token_count": 113, "parameters": [ "package", "ignore", "level" ], "start_line": 529, "end_line": 564, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 36, "top_nesting_level": 0 }, { "name": "module_test", "long_name": "module_test( mod_name , mod_file , level = 10 )", "filename": "testing.py", "nloc": 10, "complexity": 1, "token_count": 98, "parameters": [ "mod_name", "mod_file", "level" ], "start_line": 567, "end_line": 594, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 28, "top_nesting_level": 0 }, { "name": "module_test_suite", "long_name": "module_test_suite( mod_name , mod_file , level = 10 )", "filename": "testing.py", "nloc": 12, "complexity": 1, "token_count": 103, "parameters": [ "mod_name", "mod_file", "level" ], "start_line": 597, "end_line": 619, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 23, "top_nesting_level": 0 }, { "name": "assert_equal", "long_name": "assert_equal( actual , desired , err_msg = '' , verbose = 1 )", "filename": "testing.py", "nloc": 14, "complexity": 6, "token_count": 109, "parameters": [ "actual", "desired", "err_msg", "verbose" ], "start_line": 629, "end_line": 645, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 17, "top_nesting_level": 0 }, { "name": "assert_almost_equal", "long_name": "assert_almost_equal( actual , desired , decimal = 7 , err_msg = '' , verbose = 1 )", "filename": "testing.py", "nloc": 14, "complexity": 6, "token_count": 125, "parameters": [ "actual", "desired", "decimal", "err_msg", "verbose" ], "start_line": 648, "end_line": 664, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 17, "top_nesting_level": 0 }, { "name": "assert_approx_equal", "long_name": "assert_approx_equal( actual , desired , significant = 7 , err_msg = '' , verbose = 1 )", "filename": "testing.py", "nloc": 23, "complexity": 7, "token_count": 191, "parameters": [ "actual", "desired", "significant", "err_msg", "verbose" ], "start_line": 667, "end_line": 695, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 29, "top_nesting_level": 0 }, { "name": "assert_array_equal", "long_name": "assert_array_equal( x , y , err_msg = '' )", "filename": "testing.py", "nloc": 22, "complexity": 7, "token_count": 232, "parameters": [ "x", "y", "err_msg" ], "start_line": 699, "end_line": 720, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 22, "top_nesting_level": 0 }, { "name": "assert_array_almost_equal", "long_name": "assert_array_almost_equal( x , y , decimal = 6 , err_msg = '' )", "filename": "testing.py", "nloc": 26, "complexity": 6, "token_count": 251, "parameters": [ "x", "y", "decimal", "err_msg" ], "start_line": 723, "end_line": 748, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 26, "top_nesting_level": 0 }, { "name": "assert_array_less", "long_name": "assert_array_less( x , y , err_msg = '' )", "filename": "testing.py", "nloc": 20, "complexity": 5, "token_count": 189, "parameters": [ "x", "y", "err_msg" ], "start_line": 751, "end_line": 770, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 20, "top_nesting_level": 0 }, { "name": "rand", "long_name": "rand( * args )", "filename": "testing.py", "nloc": 7, "complexity": 2, "token_count": 45, "parameters": [ "args" ], "start_line": 773, "end_line": 782, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 10, "top_nesting_level": 0 }, { "name": "output_exception", "long_name": "output_exception( )", "filename": "testing.py", "nloc": 9, "complexity": 2, "token_count": 67, "parameters": [], "start_line": 784, "end_line": 794, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 11, "top_nesting_level": 0 } ], "methods_before": [ { "name": "set_package_path", "long_name": "set_package_path( level = 1 )", "filename": "testing.py", "nloc": 15, "complexity": 4, "token_count": 146, "parameters": [ "level" ], "start_line": 49, "end_line": 80, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 32, "top_nesting_level": 0 }, { "name": "set_local_path", "long_name": "set_local_path( reldir = '' , level = 1 )", "filename": "testing.py", "nloc": 11, "complexity": 3, "token_count": 97, "parameters": [ "reldir", "level" ], "start_line": 83, "end_line": 99, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 17, "top_nesting_level": 0 }, { "name": "restore_path", "long_name": "restore_path( )", "filename": "testing.py", "nloc": 4, "complexity": 2, "token_count": 25, "parameters": [], "start_line": 102, "end_line": 105, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 4, "top_nesting_level": 0 }, { "name": "jiffies", "long_name": "jiffies( _proc_pid_stat = '/proc/%s/stat' % ( os . getpid ( )", "filename": "testing.py", "nloc": 2, "complexity": 1, "token_count": 23, "parameters": [ "_proc_pid_stat" ], "start_line": 109, "end_line": 110, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 2, "top_nesting_level": 1 }, { "name": "memusage", "long_name": "memusage( _proc_pid_stat = '/proc/%s/stat' % ( os . getpid ( )", "filename": "testing.py", "nloc": 10, "complexity": 2, "token_count": 54, "parameters": [ "_proc_pid_stat" ], "start_line": 121, "end_line": 130, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 10, "top_nesting_level": 1 }, { "name": "jiffies", "long_name": "jiffies( _load_time = time . time ( )", "filename": "testing.py", "nloc": 4, "complexity": 1, "token_count": 27, "parameters": [ "_load_time" ], "start_line": 135, "end_line": 138, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 4, "top_nesting_level": 1 }, { "name": "memusage", "long_name": "memusage( )", "filename": "testing.py", "nloc": 2, "complexity": 1, "token_count": 6, "parameters": [], "start_line": 140, "end_line": 142, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 3, "top_nesting_level": 1 }, { "name": "measure", "long_name": "measure( self , code_str , times = 1 )", "filename": "testing.py", "nloc": 13, "complexity": 2, "token_count": 82, "parameters": [ "self", "code_str", "times" ], "start_line": 147, "end_line": 162, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 16, "top_nesting_level": 1 }, { "name": "__call__", "long_name": "__call__( self , result = None )", "filename": "testing.py", "nloc": 24, "complexity": 6, "token_count": 224, "parameters": [ "self", "result" ], "start_line": 164, "end_line": 188, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 25, "top_nesting_level": 1 }, { "name": "__init__", "long_name": "__init__( self , stream )", "filename": "testing.py", "nloc": 3, "complexity": 1, "token_count": 18, "parameters": [ "self", "stream" ], "start_line": 191, "end_line": 193, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 3, "top_nesting_level": 1 }, { "name": "write", "long_name": "write( self , message )", "filename": "testing.py", "nloc": 6, "complexity": 3, "token_count": 47, "parameters": [ "self", "message" ], "start_line": 194, "end_line": 199, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 6, "top_nesting_level": 1 }, { "name": "writeln", "long_name": "writeln( self , message )", "filename": "testing.py", "nloc": 2, "complexity": 1, "token_count": 15, "parameters": [ "self", "message" ], "start_line": 200, "end_line": 201, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 2, "top_nesting_level": 1 }, { "name": "_get_all_method_names", "long_name": "_get_all_method_names( cls )", "filename": "testing.py", "nloc": 8, "complexity": 5, "token_count": 56, "parameters": [ "cls" ], "start_line": 209, "end_line": 216, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 8, "top_nesting_level": 0 }, { "name": "__init__", "long_name": "__init__( self , package = '__main__' )", "filename": "testing.py", "nloc": 2, "complexity": 1, "token_count": 14, "parameters": [ "self", "package" ], "start_line": 240, "end_line": 241, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 2, "top_nesting_level": 1 }, { "name": "_module_str", "long_name": "_module_str( self , module )", "filename": "testing.py", "nloc": 5, "complexity": 2, "token_count": 43, "parameters": [ "self", "module" ], "start_line": 243, "end_line": 247, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 5, "top_nesting_level": 1 }, { "name": "_get_method_names", "long_name": "_get_method_names( self , clsobj , level )", "filename": "testing.py", "nloc": 22, "complexity": 11, "token_count": 142, "parameters": [ "self", "clsobj", "level" ], "start_line": 249, "end_line": 270, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 22, "top_nesting_level": 1 }, { "name": "_get_module_tests", "long_name": "_get_module_tests( self , module , level )", "filename": "testing.py", "nloc": 46, "complexity": 14, "token_count": 428, "parameters": [ "self", "module", "level" ], "start_line": 272, "end_line": 323, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 52, "top_nesting_level": 1 }, { "name": "_get_suite_list", "long_name": "_get_suite_list( self , test_module , level , module_name = '__main__' )", "filename": "testing.py", "nloc": 24, "complexity": 9, "token_count": 168, "parameters": [ "self", "test_module", "level", "module_name" ], "start_line": 325, "end_line": 349, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 25, "top_nesting_level": 1 }, { "name": "_touch_ppimported", "long_name": "_touch_ppimported( self , module )", "filename": "testing.py", "nloc": 11, "complexity": 7, "token_count": 98, "parameters": [ "self", "module" ], "start_line": 351, "end_line": 362, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 12, "top_nesting_level": 1 }, { "name": "test", "long_name": "test( self , level = 1 , verbosity = 1 )", "filename": "testing.py", "nloc": 19, "complexity": 6, "token_count": 166, "parameters": [ "self", "level", "verbosity" ], "start_line": 364, "end_line": 389, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 26, "top_nesting_level": 1 }, { "name": "run", "long_name": "run( self )", "filename": "testing.py", "nloc": 20, "complexity": 2, "token_count": 104, "parameters": [ "self" ], "start_line": 391, "end_line": 413, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 23, "top_nesting_level": 1 }, { "name": "remove_ignored_patterns", "long_name": "remove_ignored_patterns( files , pattern )", "filename": "testing.py", "nloc": 7, "complexity": 3, "token_count": 37, "parameters": [ "files", "pattern" ], "start_line": 417, "end_line": 423, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 7, "top_nesting_level": 0 }, { "name": "remove_ignored_files", "long_name": "remove_ignored_files( original , ignored_files , cur_dir )", "filename": "testing.py", "nloc": 12, "complexity": 3, "token_count": 93, "parameters": [ "original", "ignored_files", "cur_dir" ], "start_line": 425, "end_line": 444, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 20, "top_nesting_level": 0 }, { "name": "harvest_modules", "long_name": "harvest_modules( package , ignore = None )", "filename": "testing.py", "nloc": 21, "complexity": 4, "token_count": 134, "parameters": [ "package", "ignore" ], "start_line": 447, "end_line": 483, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 37, "top_nesting_level": 0 }, { "name": "harvest_packages", "long_name": "harvest_packages( package , ignore = None )", "filename": "testing.py", "nloc": 23, "complexity": 6, "token_count": 148, "parameters": [ "package", "ignore" ], "start_line": 486, "end_line": 520, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 35, "top_nesting_level": 0 }, { "name": "harvest_modules_and_packages", "long_name": "harvest_modules_and_packages( package , ignore = None )", "filename": "testing.py", "nloc": 3, "complexity": 1, "token_count": 27, "parameters": [ "package", "ignore" ], "start_line": 523, "end_line": 529, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 7, "top_nesting_level": 0 }, { "name": "harvest_test_suites", "long_name": "harvest_test_suites( package , ignore = None , level = 10 )", "filename": "testing.py", "nloc": 23, "complexity": 6, "token_count": 113, "parameters": [ "package", "ignore", "level" ], "start_line": 532, "end_line": 567, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 36, "top_nesting_level": 0 }, { "name": "module_test", "long_name": "module_test( mod_name , mod_file , level = 10 )", "filename": "testing.py", "nloc": 10, "complexity": 1, "token_count": 98, "parameters": [ "mod_name", "mod_file", "level" ], "start_line": 570, "end_line": 597, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 28, "top_nesting_level": 0 }, { "name": "module_test_suite", "long_name": "module_test_suite( mod_name , mod_file , level = 10 )", "filename": "testing.py", "nloc": 12, "complexity": 1, "token_count": 103, "parameters": [ "mod_name", "mod_file", "level" ], "start_line": 600, "end_line": 622, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 23, "top_nesting_level": 0 }, { "name": "assert_equal", "long_name": "assert_equal( actual , desired , err_msg = '' , verbose = 1 )", "filename": "testing.py", "nloc": 14, "complexity": 6, "token_count": 109, "parameters": [ "actual", "desired", "err_msg", "verbose" ], "start_line": 632, "end_line": 648, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 17, "top_nesting_level": 0 }, { "name": "assert_almost_equal", "long_name": "assert_almost_equal( actual , desired , decimal = 7 , err_msg = '' , verbose = 1 )", "filename": "testing.py", "nloc": 14, "complexity": 6, "token_count": 125, "parameters": [ "actual", "desired", "decimal", "err_msg", "verbose" ], "start_line": 651, "end_line": 667, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 17, "top_nesting_level": 0 }, { "name": "assert_approx_equal", "long_name": "assert_approx_equal( actual , desired , significant = 7 , err_msg = '' , verbose = 1 )", "filename": "testing.py", "nloc": 23, "complexity": 7, "token_count": 191, "parameters": [ "actual", "desired", "significant", "err_msg", "verbose" ], "start_line": 670, "end_line": 698, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 29, "top_nesting_level": 0 }, { "name": "assert_array_equal", "long_name": "assert_array_equal( x , y , err_msg = '' )", "filename": "testing.py", "nloc": 22, "complexity": 7, "token_count": 232, "parameters": [ "x", "y", "err_msg" ], "start_line": 702, "end_line": 723, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 22, "top_nesting_level": 0 }, { "name": "assert_array_almost_equal", "long_name": "assert_array_almost_equal( x , y , decimal = 6 , err_msg = '' )", "filename": "testing.py", "nloc": 26, "complexity": 6, "token_count": 251, "parameters": [ "x", "y", "decimal", "err_msg" ], "start_line": 726, "end_line": 751, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 26, "top_nesting_level": 0 }, { "name": "assert_array_less", "long_name": "assert_array_less( x , y , err_msg = '' )", "filename": "testing.py", "nloc": 20, "complexity": 5, "token_count": 189, "parameters": [ "x", "y", "err_msg" ], "start_line": 754, "end_line": 773, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 20, "top_nesting_level": 0 }, { "name": "rand", "long_name": "rand( * args )", "filename": "testing.py", "nloc": 7, "complexity": 2, "token_count": 45, "parameters": [ "args" ], "start_line": 776, "end_line": 785, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 10, "top_nesting_level": 0 }, { "name": "output_exception", "long_name": "output_exception( )", "filename": "testing.py", "nloc": 9, "complexity": 2, "token_count": 67, "parameters": [], "start_line": 787, "end_line": 797, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 11, "top_nesting_level": 0 } ], "changed_methods": [], "nloc": 596, "complexity": 150, "token_count": 4271, "diff_parsed": { "added": [ "# These are used by Numeric tests.", "# If Numeric and scipy_base are not available, then some of the", "# functions below will not be available.", "from scipy_base.numerix import alltrue, equal, shape, ravel, around, zeros, Float64, asarray", "from scipy_base.numerix import less_equal, array2string, less, ArrayType" ], "deleted": [ "try:", " # These are used by Numeric tests.", " # If Numeric and scipy_base are not available, then some of the", " # functions below will not be available.", " from scipy_base.numerix import alltrue, equal, shape, ravel, around, zeros, Float64, asarray", " from scipy_base.numerix import less_equal, array2string, less, ArrayType", "except ImportError:", " pass" ] } } ] }, { "hash": "7486383fcac6a24b7bad9caff08c2dcdd7573353", "msg": "Added cross_correlate, array2string, ArrayType.", "author": { "name": "jmiller", "email": "jmiller@localhost" }, "committer": { "name": "jmiller", "email": "jmiller@localhost" }, "author_date": "2004-12-22T19:29:29+00:00", "author_timezone": 0, "committer_date": "2004-12-22T19:29:29+00:00", "committer_timezone": 0, "branches": [ "main" ], "in_main_branch": true, "merge": false, "parents": [ "bbeded3ab95b718b3f4da97db7bcba900059744b" ], "project_name": "repo_copy", "project_path": "/tmp/tmpqop781_j/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": "scipy_base/_na_imports.py", "new_path": "scipy_base/_na_imports.py", "filename": "_na_imports.py", "extension": "py", "change_type": "MODIFY", "diff": "@@ -28,7 +28,8 @@\n from numarray.fft import fft\n from numarray.matrix import Matrix\n from numarray.linear_algebra import inverse, eigenvectors\n-from numarray.convolve import convolve\n+from numarray.convolve import convolve, cross_correlate\n+from numarray.arrayprint import array2string\n \n # LinearAlgebra = ppimport(\"numarray.linear_algebra\")\n # MLab = ppimport(\"numarray.mlab\")\n@@ -66,6 +67,8 @@ def restore_numeric():\n UnsignedInt16 = UInt16\n UnsignedInt32 = UInt32\n \n+ArrayType = arraytype\n+\n NUMERIX_HEADER = \"numarray/arrayobject.h\"\n \n class UfuncType(object):\n", "added_lines": 4, "deleted_lines": 1, "source_code": "\"\"\"Imports from numarray for numerix, the numarray/Numeric interchangeability\nmodule. These array functions are used when numarray is chosen.\n\"\"\"\nfrom ppimport import ppimport, ppimport_attr\nimport numarray as _na\nfrom numarray.numeric import *\nimport numarray.ufunc as fastumath\n\nimport _na_compiled_base\nfrom _na_compiled_base import arraymap, _unique, _insert\n\nfrom numarray.ieeespecial import isinf, isnan, isfinite\nfrom numarray.ieeespecial import \\\n plus_inf as PINF, \\\n minus_inf as NINF, \\\n plus_zero as PZERO, \\\n minus_zero as NZERO, \\\n inf, \\\n inf as infty, \\\n inf as Infinity, \\\n nan, \\\n nan as NAN, \\\n nan as Nan\n\nimport numarray.linear_algebra as LinearAlgebra\nimport numarray.linear_algebra.mlab as MLab\nimport numarray.random_array as RandomArray\nfrom numarray.fft import fft\nfrom numarray.matrix import Matrix\nfrom numarray.linear_algebra import inverse, eigenvectors\nfrom numarray.convolve import convolve, cross_correlate\nfrom numarray.arrayprint import array2string\n\n# LinearAlgebra = ppimport(\"numarray.linear_algebra\")\n# MLab = ppimport(\"numarray.mlab\")\n# inverse = ppimport_from(\"numarray.linear_algebra.inverse\")\n# eigenvectors = ppimport_from(\"numarray.linear_algebra.eigenvectors\")\n# convolve = ppimport_from(\"numarray.convolve.convolve\")\n# fft = ppimport_from(\"numarray.fft.fft\")\n# Matrix = ppimport_from(\"numarray.matrix.Matrix\")\n# RandomArray = ppimport(\"numarray.random_array\")\n\nclass _TypeNamespace:\n \"\"\"Numeric compatible type aliases for use with extension functions.\"\"\"\n Int8 = typecode[Int8]\n UInt8 = typecode[UInt8]\n Int16 = typecode[Int16]\n UInt16 = typecode[UInt16]\n Int32 = typecode[Int32]\n UInt32 = typecode[UInt32] \n Float32 = typecode[Float32]\n Float64 = typecode[Float64]\n Complex32 = typecode[Complex32]\n Complex64 = typecode[Complex64]\n\nnx = _TypeNamespace()\n\ndef alter_numeric():\n pass\n\ndef restore_numeric():\n pass\n\nconj = conjugate\n\nUnsignedInt8 = UInt8\nUnsignedInt16 = UInt16\nUnsignedInt32 = UInt32\n\nArrayType = arraytype\n\nNUMERIX_HEADER = \"numarray/arrayobject.h\"\n\nclass UfuncType(object):\n \"\"\"numarray ufuncs work differently than Numeric ufuncs and\n have no single UfuncType... TBD\"\"\"\n pass\n\n\ndef zeros(shape, typecode='l', savespace=0):\n \"\"\"scipy version of numarray.zeros() which supports creation of object\n arrays as well as numerical arrays.\n \"\"\"\n if typecode == 'O':\n import numarray.objects as obj\n z = obj.ObjectArray(shape=shape)\n z[:] = 0\n else:\n z = _na.zeros(shape=shape, type=typecode)\n return z\n\n# _Error.setMode(dividebyzero=\"ignore\", invalid=\"ignore\")\nError.setMode(all=\"ignore\")\n\n# Must appear after all public definititions\n__all__ = []\nfor k in globals().keys():\n if k[0] != \"_\":\n __all__.append(k)\n__all__.append(\"_insert\")\n__all__.append(\"_unique\")\n\n\n", "source_code_before": "\"\"\"Imports from numarray for numerix, the numarray/Numeric interchangeability\nmodule. These array functions are used when numarray is chosen.\n\"\"\"\nfrom ppimport import ppimport, ppimport_attr\nimport numarray as _na\nfrom numarray.numeric import *\nimport numarray.ufunc as fastumath\n\nimport _na_compiled_base\nfrom _na_compiled_base import arraymap, _unique, _insert\n\nfrom numarray.ieeespecial import isinf, isnan, isfinite\nfrom numarray.ieeespecial import \\\n plus_inf as PINF, \\\n minus_inf as NINF, \\\n plus_zero as PZERO, \\\n minus_zero as NZERO, \\\n inf, \\\n inf as infty, \\\n inf as Infinity, \\\n nan, \\\n nan as NAN, \\\n nan as Nan\n\nimport numarray.linear_algebra as LinearAlgebra\nimport numarray.linear_algebra.mlab as MLab\nimport numarray.random_array as RandomArray\nfrom numarray.fft import fft\nfrom numarray.matrix import Matrix\nfrom numarray.linear_algebra import inverse, eigenvectors\nfrom numarray.convolve import convolve\n\n# LinearAlgebra = ppimport(\"numarray.linear_algebra\")\n# MLab = ppimport(\"numarray.mlab\")\n# inverse = ppimport_from(\"numarray.linear_algebra.inverse\")\n# eigenvectors = ppimport_from(\"numarray.linear_algebra.eigenvectors\")\n# convolve = ppimport_from(\"numarray.convolve.convolve\")\n# fft = ppimport_from(\"numarray.fft.fft\")\n# Matrix = ppimport_from(\"numarray.matrix.Matrix\")\n# RandomArray = ppimport(\"numarray.random_array\")\n\nclass _TypeNamespace:\n \"\"\"Numeric compatible type aliases for use with extension functions.\"\"\"\n Int8 = typecode[Int8]\n UInt8 = typecode[UInt8]\n Int16 = typecode[Int16]\n UInt16 = typecode[UInt16]\n Int32 = typecode[Int32]\n UInt32 = typecode[UInt32] \n Float32 = typecode[Float32]\n Float64 = typecode[Float64]\n Complex32 = typecode[Complex32]\n Complex64 = typecode[Complex64]\n\nnx = _TypeNamespace()\n\ndef alter_numeric():\n pass\n\ndef restore_numeric():\n pass\n\nconj = conjugate\n\nUnsignedInt8 = UInt8\nUnsignedInt16 = UInt16\nUnsignedInt32 = UInt32\n\nNUMERIX_HEADER = \"numarray/arrayobject.h\"\n\nclass UfuncType(object):\n \"\"\"numarray ufuncs work differently than Numeric ufuncs and\n have no single UfuncType... TBD\"\"\"\n pass\n\n\ndef zeros(shape, typecode='l', savespace=0):\n \"\"\"scipy version of numarray.zeros() which supports creation of object\n arrays as well as numerical arrays.\n \"\"\"\n if typecode == 'O':\n import numarray.objects as obj\n z = obj.ObjectArray(shape=shape)\n z[:] = 0\n else:\n z = _na.zeros(shape=shape, type=typecode)\n return z\n\n# _Error.setMode(dividebyzero=\"ignore\", invalid=\"ignore\")\nError.setMode(all=\"ignore\")\n\n# Must appear after all public definititions\n__all__ = []\nfor k in globals().keys():\n if k[0] != \"_\":\n __all__.append(k)\n__all__.append(\"_insert\")\n__all__.append(\"_unique\")\n\n\n", "methods": [ { "name": "alter_numeric", "long_name": "alter_numeric( )", "filename": "_na_imports.py", "nloc": 2, "complexity": 1, "token_count": 5, "parameters": [], "start_line": 58, "end_line": 59, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 2, "top_nesting_level": 0 }, { "name": "restore_numeric", "long_name": "restore_numeric( )", "filename": "_na_imports.py", "nloc": 2, "complexity": 1, "token_count": 5, "parameters": [], "start_line": 61, "end_line": 62, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 2, "top_nesting_level": 0 }, { "name": "zeros", "long_name": "zeros( shape , typecode = 'l' , savespace = 0 )", "filename": "_na_imports.py", "nloc": 8, "complexity": 2, "token_count": 59, "parameters": [ "shape", "typecode", "savespace" ], "start_line": 80, "end_line": 90, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 11, "top_nesting_level": 0 } ], "methods_before": [ { "name": "alter_numeric", "long_name": "alter_numeric( )", "filename": "_na_imports.py", "nloc": 2, "complexity": 1, "token_count": 5, "parameters": [], "start_line": 57, "end_line": 58, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 2, "top_nesting_level": 0 }, { "name": "restore_numeric", "long_name": "restore_numeric( )", "filename": "_na_imports.py", "nloc": 2, "complexity": 1, "token_count": 5, "parameters": [], "start_line": 60, "end_line": 61, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 2, "top_nesting_level": 0 }, { "name": "zeros", "long_name": "zeros( shape , typecode = 'l' , savespace = 0 )", "filename": "_na_imports.py", "nloc": 8, "complexity": 2, "token_count": 59, "parameters": [ "shape", "typecode", "savespace" ], "start_line": 77, "end_line": 87, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 11, "top_nesting_level": 0 } ], "changed_methods": [], "nloc": 71, "complexity": 4, "token_count": 363, "diff_parsed": { "added": [ "from numarray.convolve import convolve, cross_correlate", "from numarray.arrayprint import array2string", "ArrayType = arraytype", "" ], "deleted": [ "from numarray.convolve import convolve" ] } } ] }, { "hash": "246665b81b2954a63c0400f870d85aeac111117e", "msg": "Backed out numarray \"fixes\" to avoid confusing issues; numarray doesn't\nneed these changes per see, scipy as a whole does.", "author": { "name": "jmiller", "email": "jmiller@localhost" }, "committer": { "name": "jmiller", "email": "jmiller@localhost" }, "author_date": "2004-12-22T20:06:09+00:00", "author_timezone": 0, "committer_date": "2004-12-22T20:06:09+00:00", "committer_timezone": 0, "branches": [ "main" ], "in_main_branch": true, "merge": false, "parents": [ "7486383fcac6a24b7bad9caff08c2dcdd7573353" ], "project_name": "repo_copy", "project_path": "/tmp/tmpqop781_j/repo_copy", "deletions": 4, "insertions": 2, "lines": 6, "files": 1, "dmm_unit_size": 0.0, "dmm_unit_complexity": 0.0, "dmm_unit_interfacing": 0.0, "modified_files": [ { "old_path": "scipy_base/tests/test_function_base.py", "new_path": "scipy_base/tests/test_function_base.py", "filename": "test_function_base.py", "extension": "py", "change_type": "MODIFY", "diff": "@@ -69,9 +69,8 @@ def check_basic(self):\n b = [[3,6.0, 9.0],\n [4,10.0,5.0],\n [8,3.0,2.0]]\n- assert_equal(amax(b, axis=0),[8.0,10.0,9.0]) \n+ assert_equal(amax(b),[8.0,10.0,9.0])\n assert_equal(amax(b,axis=1),[9.0,10.0,8.0])\n- assert_equal(amax(b,axis=-1),[9.0,10.0,8.0])\n \n class test_amin(unittest.TestCase):\n def check_basic(self):\n@@ -80,9 +79,8 @@ def check_basic(self):\n b = [[3,6.0, 9.0],\n [4,10.0,5.0],\n [8,3.0,2.0]]\n- assert_equal(amin(b,axis=0),[3.0,3.0,2.0])\n+ assert_equal(amin(b),[3.0,3.0,2.0])\n assert_equal(amin(b,axis=1),[3.0,4.0,2.0])\n- assert_equal(amin(b),[3.0,4.0,2.0])\n \n class test_ptp(unittest.TestCase):\n def check_basic(self):\n", "added_lines": 2, "deleted_lines": 4, "source_code": "\nimport unittest\n\nimport sys\nfrom scipy_test.testing import *\nset_package_path()\nimport scipy_base;reload(scipy_base)\nfrom scipy_base import *\ndel sys.path[0]\n\nclass test_any(unittest.TestCase):\n def check_basic(self):\n y1 = [0,0,1,0]\n y2 = [0,0,0,0]\n y3 = [1,0,1,0]\n assert(any(y1))\n assert(any(y3))\n assert(not any(y2))\n\n def check_nd(self):\n y1 = [[0,0,0],[0,1,0],[1,1,0]]\n assert(any(y1))\n assert_array_equal(sometrue(y1),[1,1,0])\n assert_array_equal(sometrue(y1,axis=1),[0,1,1])\n \nclass test_all(unittest.TestCase):\n def check_basic(self):\n y1 = [0,1,1,0]\n y2 = [0,0,0,0]\n y3 = [1,1,1,1]\n assert(not all(y1))\n assert(all(y3))\n assert(not all(y2))\n assert(all(~array(y2)))\n\n def check_nd(self):\n y1 = [[0,0,1],[0,1,1],[1,1,1]]\n assert(not all(y1))\n assert_array_equal(alltrue(y1),[0,0,1])\n assert_array_equal(alltrue(y1,axis=1),[0,0,1])\n\nclass test_logspace(unittest.TestCase):\n def check_basic(self):\n y = logspace(0,6)\n assert(len(y)==50)\n y = logspace(0,6,num=100)\n assert(y[-1] == 10**6)\n y = logspace(0,6,endpoint=0)\n assert(y[-1] < 10**6)\n y = logspace(0,6,num=7)\n assert_array_equal(y,[1,10,100,1e3,1e4,1e5,1e6])\n\nclass test_linspace(unittest.TestCase):\n def check_basic(self):\n y = linspace(0,10)\n assert(len(y)==50)\n y = linspace(2,10,num=100)\n assert(y[-1] == 10)\n y = linspace(2,10,endpoint=0)\n assert(y[-1] < 10)\n y,st = linspace(2,10,retstep=1)\n assert_almost_equal(st,8/49.0)\n assert_array_almost_equal(y,mgrid[2:10:50j],13)\n\nclass test_amax(unittest.TestCase):\n def check_basic(self):\n a = [3,4,5,10,-3,-5,6.0]\n assert_equal(amax(a),10.0)\n b = [[3,6.0, 9.0],\n [4,10.0,5.0],\n [8,3.0,2.0]]\n assert_equal(amax(b),[8.0,10.0,9.0])\n assert_equal(amax(b,axis=1),[9.0,10.0,8.0])\n \nclass test_amin(unittest.TestCase):\n def check_basic(self):\n a = [3,4,5,10,-3,-5,6.0]\n assert_equal(amin(a),-5.0)\n b = [[3,6.0, 9.0],\n [4,10.0,5.0],\n [8,3.0,2.0]]\n assert_equal(amin(b),[3.0,3.0,2.0])\n assert_equal(amin(b,axis=1),[3.0,4.0,2.0])\n\nclass test_ptp(unittest.TestCase):\n def check_basic(self):\n a = [3,4,5,10,-3,-5,6.0]\n assert_equal(ptp(a),15.0)\n b = [[3,6.0, 9.0],\n [4,10.0,5.0],\n [8,3.0,2.0]]\n assert_equal(ptp(b,axis=0),[5.0,7.0,7.0])\n assert_equal(ptp(b),[6.0,6.0,6.0])\n\nclass test_cumsum(unittest.TestCase):\n def check_basic(self):\n ba = [1,2,10,11,6,5,4]\n ba2 = [[1,2,3,4],[5,6,7,9],[10,3,4,5]]\n for ctype in ['1','b','s','i','l','f','d','F','D']:\n a = array(ba,ctype)\n a2 = array(ba2,ctype)\n assert_array_equal(cumsum(a), array([1,3,13,24,30,35,39],ctype))\n assert_array_equal(cumsum(a2,axis=0), array([[1,2,3,4],[6,8,10,13],\n [16,11,14,18]],ctype))\n assert_array_equal(cumsum(a2,axis=1),\n array([[1,3,6,10],\n [5,11,18,27],\n [10,13,17,22]],ctype))\n\nclass test_prod(unittest.TestCase):\n def check_basic(self):\n ba = [1,2,10,11,6,5,4]\n ba2 = [[1,2,3,4],[5,6,7,9],[10,3,4,5]]\n for ctype in ['1','b','s','i','l','f','d','F','D']:\n a = array(ba,ctype)\n a2 = array(ba2,ctype)\n if ctype in ['1', 'b']:\n self.failUnlessRaises(ArithmeticError, prod, a)\n self.failUnlessRaises(ArithmeticError, prod, a2, 1)\n self.failUnlessRaises(ArithmeticError, prod, a)\n else: \n assert_equal(prod(a),26400)\n assert_array_equal(prod(a2,axis=0), \n array([50,36,84,180],ctype))\n assert_array_equal(prod(a2),array([24, 1890, 600],ctype))\n\nclass test_cumprod(unittest.TestCase):\n def check_basic(self):\n ba = [1,2,10,11,6,5,4]\n ba2 = [[1,2,3,4],[5,6,7,9],[10,3,4,5]]\n for ctype in ['1','b','s','i','l','f','d','F','D']:\n a = array(ba,ctype)\n a2 = array(ba2,ctype)\n if ctype in ['1', 'b']:\n self.failUnlessRaises(ArithmeticError, cumprod, a)\n self.failUnlessRaises(ArithmeticError, cumprod, a2, 1)\n self.failUnlessRaises(ArithmeticError, cumprod, a)\n else: \n assert_array_equal(cumprod(a),\n array([1, 2, 20, 220,\n 1320, 6600, 26400],ctype))\n assert_array_equal(cumprod(a2,axis=0),\n array([[ 1, 2, 3, 4],\n [ 5, 12, 21, 36],\n [50, 36, 84, 180]],ctype))\n assert_array_equal(cumprod(a2),\n array([[ 1, 2, 6, 24],\n [ 5, 30, 210, 1890],\n [10, 30, 120, 600]],ctype))\n\nclass test_diff(unittest.TestCase):\n def check_basic(self):\n x = [1,4,6,7,12]\n out = array([3,2,1,5])\n out2 = array([-1,-1,4])\n out3 = array([0,5])\n assert_array_equal(diff(x),out)\n assert_array_equal(diff(x,n=2),out2)\n assert_array_equal(diff(x,n=3),out3)\n\n def check_nd(self):\n x = 20*rand(10,20,30)\n out1 = x[:,:,1:] - x[:,:,:-1]\n out2 = out1[:,:,1:] - out1[:,:,:-1]\n out3 = x[1:,:,:] - x[:-1,:,:]\n out4 = out3[1:,:,:] - out3[:-1,:,:]\n assert_array_equal(diff(x),out1)\n assert_array_equal(diff(x,n=2),out2)\n assert_array_equal(diff(x,axis=0),out3)\n assert_array_equal(diff(x,n=2,axis=0),out4)\n\nclass test_angle(unittest.TestCase):\n def check_basic(self):\n x = [1+3j,sqrt(2)/2.0+1j*sqrt(2)/2,1,1j,-1,-1j,1-3j,-1+3j]\n y = angle(x)\n yo = [arctan(3.0/1.0),arctan(1.0),0,pi/2,pi,-pi/2.0,\n -arctan(3.0/1.0),pi-arctan(3.0/1.0)]\n z = angle(x,deg=1)\n zo = array(yo)*180/pi\n assert_array_almost_equal(y,yo,11)\n assert_array_almost_equal(z,zo,11)\n\nclass test_trim_zeros(unittest.TestCase):\n \"\"\" only testing for integer splits.\n \"\"\"\n def check_basic(self):\n a= array([0,0,1,2,3,4,0])\n res = trim_zeros(a)\n assert_array_equal(res,array([1,2,3,4]))\n def check_leading_skip(self):\n a= array([0,0,1,0,2,3,4,0])\n res = trim_zeros(a)\n assert_array_equal(res,array([1,0,2,3,4]))\n def check_trailing_skip(self):\n a= array([0,0,1,0,2,3,0,4,0])\n res = trim_zeros(a)\n assert_array_equal(res,array([1,0,2,3,0,4]))\n\n\nclass test_extins(unittest.TestCase):\n def check_basic(self):\n a = array([1,3,2,1,2,3,3])\n b = extract(a>1,a)\n assert_array_equal(b,[3,2,2,3,3])\n def check_insert(self):\n a = array([1,4,3,2,5,8,7])\n insert(a,[0,1,0,1,0,1,0],[2,4,6])\n assert_array_equal(a,[1,2,3,4,5,6,7])\n def check_both(self):\n a = rand(10)\n mask = a > 0.5\n ac = a.copy()\n c = extract(mask, a)\n insert(a,mask,0)\n insert(a,mask,c)\n assert_array_equal(a,ac)\n \nclass test_vectorize(unittest.TestCase):\n def check_simple(self):\n def addsubtract(a,b):\n if a > b:\n return a - b\n else:\n return a + b\n f = vectorize(addsubtract)\n r = f([0,3,6,9],[1,3,5,7])\n assert_array_equal(r,[1,6,1,2])\n def check_scalar(self):\n def addsubtract(a,b):\n if a > b:\n return a - b\n else:\n return a + b\n f = vectorize(addsubtract)\n r = f([0,3,6,9],5)\n assert_array_equal(r,[5,8,1,4])\n \n\ndef compare_results(res,desired):\n for i in range(len(desired)):\n assert_array_equal(res[i],desired[i])\n\nif __name__ == \"__main__\":\n ScipyTest('scipy_base.function_base').run()\n", "source_code_before": "\nimport unittest\n\nimport sys\nfrom scipy_test.testing import *\nset_package_path()\nimport scipy_base;reload(scipy_base)\nfrom scipy_base import *\ndel sys.path[0]\n\nclass test_any(unittest.TestCase):\n def check_basic(self):\n y1 = [0,0,1,0]\n y2 = [0,0,0,0]\n y3 = [1,0,1,0]\n assert(any(y1))\n assert(any(y3))\n assert(not any(y2))\n\n def check_nd(self):\n y1 = [[0,0,0],[0,1,0],[1,1,0]]\n assert(any(y1))\n assert_array_equal(sometrue(y1),[1,1,0])\n assert_array_equal(sometrue(y1,axis=1),[0,1,1])\n \nclass test_all(unittest.TestCase):\n def check_basic(self):\n y1 = [0,1,1,0]\n y2 = [0,0,0,0]\n y3 = [1,1,1,1]\n assert(not all(y1))\n assert(all(y3))\n assert(not all(y2))\n assert(all(~array(y2)))\n\n def check_nd(self):\n y1 = [[0,0,1],[0,1,1],[1,1,1]]\n assert(not all(y1))\n assert_array_equal(alltrue(y1),[0,0,1])\n assert_array_equal(alltrue(y1,axis=1),[0,0,1])\n\nclass test_logspace(unittest.TestCase):\n def check_basic(self):\n y = logspace(0,6)\n assert(len(y)==50)\n y = logspace(0,6,num=100)\n assert(y[-1] == 10**6)\n y = logspace(0,6,endpoint=0)\n assert(y[-1] < 10**6)\n y = logspace(0,6,num=7)\n assert_array_equal(y,[1,10,100,1e3,1e4,1e5,1e6])\n\nclass test_linspace(unittest.TestCase):\n def check_basic(self):\n y = linspace(0,10)\n assert(len(y)==50)\n y = linspace(2,10,num=100)\n assert(y[-1] == 10)\n y = linspace(2,10,endpoint=0)\n assert(y[-1] < 10)\n y,st = linspace(2,10,retstep=1)\n assert_almost_equal(st,8/49.0)\n assert_array_almost_equal(y,mgrid[2:10:50j],13)\n\nclass test_amax(unittest.TestCase):\n def check_basic(self):\n a = [3,4,5,10,-3,-5,6.0]\n assert_equal(amax(a),10.0)\n b = [[3,6.0, 9.0],\n [4,10.0,5.0],\n [8,3.0,2.0]]\n assert_equal(amax(b, axis=0),[8.0,10.0,9.0]) \n assert_equal(amax(b,axis=1),[9.0,10.0,8.0])\n assert_equal(amax(b,axis=-1),[9.0,10.0,8.0])\n \nclass test_amin(unittest.TestCase):\n def check_basic(self):\n a = [3,4,5,10,-3,-5,6.0]\n assert_equal(amin(a),-5.0)\n b = [[3,6.0, 9.0],\n [4,10.0,5.0],\n [8,3.0,2.0]]\n assert_equal(amin(b,axis=0),[3.0,3.0,2.0])\n assert_equal(amin(b,axis=1),[3.0,4.0,2.0])\n assert_equal(amin(b),[3.0,4.0,2.0])\n\nclass test_ptp(unittest.TestCase):\n def check_basic(self):\n a = [3,4,5,10,-3,-5,6.0]\n assert_equal(ptp(a),15.0)\n b = [[3,6.0, 9.0],\n [4,10.0,5.0],\n [8,3.0,2.0]]\n assert_equal(ptp(b,axis=0),[5.0,7.0,7.0])\n assert_equal(ptp(b),[6.0,6.0,6.0])\n\nclass test_cumsum(unittest.TestCase):\n def check_basic(self):\n ba = [1,2,10,11,6,5,4]\n ba2 = [[1,2,3,4],[5,6,7,9],[10,3,4,5]]\n for ctype in ['1','b','s','i','l','f','d','F','D']:\n a = array(ba,ctype)\n a2 = array(ba2,ctype)\n assert_array_equal(cumsum(a), array([1,3,13,24,30,35,39],ctype))\n assert_array_equal(cumsum(a2,axis=0), array([[1,2,3,4],[6,8,10,13],\n [16,11,14,18]],ctype))\n assert_array_equal(cumsum(a2,axis=1),\n array([[1,3,6,10],\n [5,11,18,27],\n [10,13,17,22]],ctype))\n\nclass test_prod(unittest.TestCase):\n def check_basic(self):\n ba = [1,2,10,11,6,5,4]\n ba2 = [[1,2,3,4],[5,6,7,9],[10,3,4,5]]\n for ctype in ['1','b','s','i','l','f','d','F','D']:\n a = array(ba,ctype)\n a2 = array(ba2,ctype)\n if ctype in ['1', 'b']:\n self.failUnlessRaises(ArithmeticError, prod, a)\n self.failUnlessRaises(ArithmeticError, prod, a2, 1)\n self.failUnlessRaises(ArithmeticError, prod, a)\n else: \n assert_equal(prod(a),26400)\n assert_array_equal(prod(a2,axis=0), \n array([50,36,84,180],ctype))\n assert_array_equal(prod(a2),array([24, 1890, 600],ctype))\n\nclass test_cumprod(unittest.TestCase):\n def check_basic(self):\n ba = [1,2,10,11,6,5,4]\n ba2 = [[1,2,3,4],[5,6,7,9],[10,3,4,5]]\n for ctype in ['1','b','s','i','l','f','d','F','D']:\n a = array(ba,ctype)\n a2 = array(ba2,ctype)\n if ctype in ['1', 'b']:\n self.failUnlessRaises(ArithmeticError, cumprod, a)\n self.failUnlessRaises(ArithmeticError, cumprod, a2, 1)\n self.failUnlessRaises(ArithmeticError, cumprod, a)\n else: \n assert_array_equal(cumprod(a),\n array([1, 2, 20, 220,\n 1320, 6600, 26400],ctype))\n assert_array_equal(cumprod(a2,axis=0),\n array([[ 1, 2, 3, 4],\n [ 5, 12, 21, 36],\n [50, 36, 84, 180]],ctype))\n assert_array_equal(cumprod(a2),\n array([[ 1, 2, 6, 24],\n [ 5, 30, 210, 1890],\n [10, 30, 120, 600]],ctype))\n\nclass test_diff(unittest.TestCase):\n def check_basic(self):\n x = [1,4,6,7,12]\n out = array([3,2,1,5])\n out2 = array([-1,-1,4])\n out3 = array([0,5])\n assert_array_equal(diff(x),out)\n assert_array_equal(diff(x,n=2),out2)\n assert_array_equal(diff(x,n=3),out3)\n\n def check_nd(self):\n x = 20*rand(10,20,30)\n out1 = x[:,:,1:] - x[:,:,:-1]\n out2 = out1[:,:,1:] - out1[:,:,:-1]\n out3 = x[1:,:,:] - x[:-1,:,:]\n out4 = out3[1:,:,:] - out3[:-1,:,:]\n assert_array_equal(diff(x),out1)\n assert_array_equal(diff(x,n=2),out2)\n assert_array_equal(diff(x,axis=0),out3)\n assert_array_equal(diff(x,n=2,axis=0),out4)\n\nclass test_angle(unittest.TestCase):\n def check_basic(self):\n x = [1+3j,sqrt(2)/2.0+1j*sqrt(2)/2,1,1j,-1,-1j,1-3j,-1+3j]\n y = angle(x)\n yo = [arctan(3.0/1.0),arctan(1.0),0,pi/2,pi,-pi/2.0,\n -arctan(3.0/1.0),pi-arctan(3.0/1.0)]\n z = angle(x,deg=1)\n zo = array(yo)*180/pi\n assert_array_almost_equal(y,yo,11)\n assert_array_almost_equal(z,zo,11)\n\nclass test_trim_zeros(unittest.TestCase):\n \"\"\" only testing for integer splits.\n \"\"\"\n def check_basic(self):\n a= array([0,0,1,2,3,4,0])\n res = trim_zeros(a)\n assert_array_equal(res,array([1,2,3,4]))\n def check_leading_skip(self):\n a= array([0,0,1,0,2,3,4,0])\n res = trim_zeros(a)\n assert_array_equal(res,array([1,0,2,3,4]))\n def check_trailing_skip(self):\n a= array([0,0,1,0,2,3,0,4,0])\n res = trim_zeros(a)\n assert_array_equal(res,array([1,0,2,3,0,4]))\n\n\nclass test_extins(unittest.TestCase):\n def check_basic(self):\n a = array([1,3,2,1,2,3,3])\n b = extract(a>1,a)\n assert_array_equal(b,[3,2,2,3,3])\n def check_insert(self):\n a = array([1,4,3,2,5,8,7])\n insert(a,[0,1,0,1,0,1,0],[2,4,6])\n assert_array_equal(a,[1,2,3,4,5,6,7])\n def check_both(self):\n a = rand(10)\n mask = a > 0.5\n ac = a.copy()\n c = extract(mask, a)\n insert(a,mask,0)\n insert(a,mask,c)\n assert_array_equal(a,ac)\n \nclass test_vectorize(unittest.TestCase):\n def check_simple(self):\n def addsubtract(a,b):\n if a > b:\n return a - b\n else:\n return a + b\n f = vectorize(addsubtract)\n r = f([0,3,6,9],[1,3,5,7])\n assert_array_equal(r,[1,6,1,2])\n def check_scalar(self):\n def addsubtract(a,b):\n if a > b:\n return a - b\n else:\n return a + b\n f = vectorize(addsubtract)\n r = f([0,3,6,9],5)\n assert_array_equal(r,[5,8,1,4])\n \n\ndef compare_results(res,desired):\n for i in range(len(desired)):\n assert_array_equal(res[i],desired[i])\n\nif __name__ == \"__main__\":\n ScipyTest('scipy_base.function_base').run()\n", "methods": [ { "name": "check_basic", "long_name": "check_basic( self )", "filename": "test_function_base.py", "nloc": 7, "complexity": 1, "token_count": 60, "parameters": [ "self" ], "start_line": 12, "end_line": 18, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 7, "top_nesting_level": 1 }, { "name": "check_nd", "long_name": "check_nd( self )", "filename": "test_function_base.py", "nloc": 5, "complexity": 1, "token_count": 73, "parameters": [ "self" ], "start_line": 20, "end_line": 24, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 5, "top_nesting_level": 1 }, { "name": "check_basic", "long_name": "check_basic( self )", "filename": "test_function_base.py", "nloc": 8, "complexity": 1, "token_count": 72, "parameters": [ "self" ], "start_line": 27, "end_line": 34, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 8, "top_nesting_level": 1 }, { "name": "check_nd", "long_name": "check_nd( self )", "filename": "test_function_base.py", "nloc": 5, "complexity": 1, "token_count": 74, "parameters": [ "self" ], "start_line": 36, "end_line": 40, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 5, "top_nesting_level": 1 }, { "name": "check_basic", "long_name": "check_basic( self )", "filename": "test_function_base.py", "nloc": 9, "complexity": 1, "token_count": 102, "parameters": [ "self" ], "start_line": 43, "end_line": 51, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 9, "top_nesting_level": 1 }, { "name": "check_basic", "long_name": "check_basic( self )", "filename": "test_function_base.py", "nloc": 10, "complexity": 1, "token_count": 105, "parameters": [ "self" ], "start_line": 54, "end_line": 63, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 10, "top_nesting_level": 1 }, { "name": "check_basic", "long_name": "check_basic( self )", "filename": "test_function_base.py", "nloc": 8, "complexity": 1, "token_count": 122, "parameters": [ "self" ], "start_line": 66, "end_line": 73, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 8, "top_nesting_level": 1 }, { "name": "check_basic", "long_name": "check_basic( self )", "filename": "test_function_base.py", "nloc": 8, "complexity": 1, "token_count": 123, "parameters": [ "self" ], "start_line": 76, "end_line": 83, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 8, "top_nesting_level": 1 }, { "name": "check_basic", "long_name": "check_basic( self )", "filename": "test_function_base.py", "nloc": 8, "complexity": 1, "token_count": 122, "parameters": [ "self" ], "start_line": 86, "end_line": 93, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 8, "top_nesting_level": 1 }, { "name": "check_basic", "long_name": "check_basic( self )", "filename": "test_function_base.py", "nloc": 13, "complexity": 2, "token_count": 218, "parameters": [ "self" ], "start_line": 96, "end_line": 108, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 13, "top_nesting_level": 1 }, { "name": "check_basic", "long_name": "check_basic( self )", "filename": "test_function_base.py", "nloc": 15, "complexity": 3, "token_count": 192, "parameters": [ "self" ], "start_line": 111, "end_line": 125, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 15, "top_nesting_level": 1 }, { "name": "check_basic", "long_name": "check_basic( self )", "filename": "test_function_base.py", "nloc": 22, "complexity": 3, "token_count": 257, "parameters": [ "self" ], "start_line": 128, "end_line": 149, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 22, "top_nesting_level": 1 }, { "name": "check_basic", "long_name": "check_basic( self )", "filename": "test_function_base.py", "nloc": 8, "complexity": 1, "token_count": 91, "parameters": [ "self" ], "start_line": 152, "end_line": 159, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 8, "top_nesting_level": 1 }, { "name": "check_nd", "long_name": "check_nd( self )", "filename": "test_function_base.py", "nloc": 10, "complexity": 1, "token_count": 157, "parameters": [ "self" ], "start_line": 161, "end_line": 170, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 10, "top_nesting_level": 1 }, { "name": "check_basic", "long_name": "check_basic( self )", "filename": "test_function_base.py", "nloc": 9, "complexity": 1, "token_count": 152, "parameters": [ "self" ], "start_line": 173, "end_line": 181, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 9, "top_nesting_level": 1 }, { "name": "check_basic", "long_name": "check_basic( self )", "filename": "test_function_base.py", "nloc": 4, "complexity": 1, "token_count": 48, "parameters": [ "self" ], "start_line": 186, "end_line": 189, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 4, "top_nesting_level": 1 }, { "name": "check_leading_skip", "long_name": "check_leading_skip( self )", "filename": "test_function_base.py", "nloc": 4, "complexity": 1, "token_count": 52, "parameters": [ "self" ], "start_line": 190, "end_line": 193, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 4, "top_nesting_level": 1 }, { "name": "check_trailing_skip", "long_name": "check_trailing_skip( self )", "filename": "test_function_base.py", "nloc": 4, "complexity": 1, "token_count": 56, "parameters": [ "self" ], "start_line": 194, "end_line": 197, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 4, "top_nesting_level": 1 }, { "name": "check_basic", "long_name": "check_basic( self )", "filename": "test_function_base.py", "nloc": 4, "complexity": 1, "token_count": 51, "parameters": [ "self" ], "start_line": 201, "end_line": 204, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 4, "top_nesting_level": 1 }, { "name": "check_insert", "long_name": "check_insert( self )", "filename": "test_function_base.py", "nloc": 4, "complexity": 1, "token_count": 73, "parameters": [ "self" ], "start_line": 205, "end_line": 208, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 4, "top_nesting_level": 1 }, { "name": "check_both", "long_name": "check_both( self )", "filename": "test_function_base.py", "nloc": 8, "complexity": 1, "token_count": 55, "parameters": [ "self" ], "start_line": 209, "end_line": 216, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 8, "top_nesting_level": 1 }, { "name": "check_simple.addsubtract", "long_name": "check_simple.addsubtract( a , b )", "filename": "test_function_base.py", "nloc": 5, "complexity": 2, "token_count": 22, "parameters": [ "a", "b" ], "start_line": 220, "end_line": 224, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 5, "top_nesting_level": 2 }, { "name": "check_simple", "long_name": "check_simple( self )", "filename": "test_function_base.py", "nloc": 5, "complexity": 1, "token_count": 51, "parameters": [ "self" ], "start_line": 219, "end_line": 227, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 9, "top_nesting_level": 1 }, { "name": "check_scalar.addsubtract", "long_name": "check_scalar.addsubtract( a , b )", "filename": "test_function_base.py", "nloc": 5, "complexity": 2, "token_count": 22, "parameters": [ "a", "b" ], "start_line": 229, "end_line": 233, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 5, "top_nesting_level": 2 }, { "name": "check_scalar", "long_name": "check_scalar( self )", "filename": "test_function_base.py", "nloc": 5, "complexity": 1, "token_count": 43, "parameters": [ "self" ], "start_line": 228, "end_line": 236, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 9, "top_nesting_level": 1 }, { "name": "compare_results", "long_name": "compare_results( res , desired )", "filename": "test_function_base.py", "nloc": 3, "complexity": 2, "token_count": 30, "parameters": [ "res", "desired" ], "start_line": 239, "end_line": 241, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 3, "top_nesting_level": 0 } ], "methods_before": [ { "name": "check_basic", "long_name": "check_basic( self )", "filename": "test_function_base.py", "nloc": 7, "complexity": 1, "token_count": 60, "parameters": [ "self" ], "start_line": 12, "end_line": 18, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 7, "top_nesting_level": 1 }, { "name": "check_nd", "long_name": "check_nd( self )", "filename": "test_function_base.py", "nloc": 5, "complexity": 1, "token_count": 73, "parameters": [ "self" ], "start_line": 20, "end_line": 24, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 5, "top_nesting_level": 1 }, { "name": "check_basic", "long_name": "check_basic( self )", "filename": "test_function_base.py", "nloc": 8, "complexity": 1, "token_count": 72, "parameters": [ "self" ], "start_line": 27, "end_line": 34, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 8, "top_nesting_level": 1 }, { "name": "check_nd", "long_name": "check_nd( self )", "filename": "test_function_base.py", "nloc": 5, "complexity": 1, "token_count": 74, "parameters": [ "self" ], "start_line": 36, "end_line": 40, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 5, "top_nesting_level": 1 }, { "name": "check_basic", "long_name": "check_basic( self )", "filename": "test_function_base.py", "nloc": 9, "complexity": 1, "token_count": 102, "parameters": [ "self" ], "start_line": 43, "end_line": 51, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 9, "top_nesting_level": 1 }, { "name": "check_basic", "long_name": "check_basic( self )", "filename": "test_function_base.py", "nloc": 10, "complexity": 1, "token_count": 105, "parameters": [ "self" ], "start_line": 54, "end_line": 63, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 10, "top_nesting_level": 1 }, { "name": "check_basic", "long_name": "check_basic( self )", "filename": "test_function_base.py", "nloc": 9, "complexity": 1, "token_count": 152, "parameters": [ "self" ], "start_line": 66, "end_line": 74, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 9, "top_nesting_level": 1 }, { "name": "check_basic", "long_name": "check_basic( self )", "filename": "test_function_base.py", "nloc": 9, "complexity": 1, "token_count": 148, "parameters": [ "self" ], "start_line": 77, "end_line": 85, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 9, "top_nesting_level": 1 }, { "name": "check_basic", "long_name": "check_basic( self )", "filename": "test_function_base.py", "nloc": 8, "complexity": 1, "token_count": 122, "parameters": [ "self" ], "start_line": 88, "end_line": 95, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 8, "top_nesting_level": 1 }, { "name": "check_basic", "long_name": "check_basic( self )", "filename": "test_function_base.py", "nloc": 13, "complexity": 2, "token_count": 218, "parameters": [ "self" ], "start_line": 98, "end_line": 110, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 13, "top_nesting_level": 1 }, { "name": "check_basic", "long_name": "check_basic( self )", "filename": "test_function_base.py", "nloc": 15, "complexity": 3, "token_count": 192, "parameters": [ "self" ], "start_line": 113, "end_line": 127, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 15, "top_nesting_level": 1 }, { "name": "check_basic", "long_name": "check_basic( self )", "filename": "test_function_base.py", "nloc": 22, "complexity": 3, "token_count": 257, "parameters": [ "self" ], "start_line": 130, "end_line": 151, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 22, "top_nesting_level": 1 }, { "name": "check_basic", "long_name": "check_basic( self )", "filename": "test_function_base.py", "nloc": 8, "complexity": 1, "token_count": 91, "parameters": [ "self" ], "start_line": 154, "end_line": 161, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 8, "top_nesting_level": 1 }, { "name": "check_nd", "long_name": "check_nd( self )", "filename": "test_function_base.py", "nloc": 10, "complexity": 1, "token_count": 157, "parameters": [ "self" ], "start_line": 163, "end_line": 172, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 10, "top_nesting_level": 1 }, { "name": "check_basic", "long_name": "check_basic( self )", "filename": "test_function_base.py", "nloc": 9, "complexity": 1, "token_count": 152, "parameters": [ "self" ], "start_line": 175, "end_line": 183, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 9, "top_nesting_level": 1 }, { "name": "check_basic", "long_name": "check_basic( self )", "filename": "test_function_base.py", "nloc": 4, "complexity": 1, "token_count": 48, "parameters": [ "self" ], "start_line": 188, "end_line": 191, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 4, "top_nesting_level": 1 }, { "name": "check_leading_skip", "long_name": "check_leading_skip( self )", "filename": "test_function_base.py", "nloc": 4, "complexity": 1, "token_count": 52, "parameters": [ "self" ], "start_line": 192, "end_line": 195, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 4, "top_nesting_level": 1 }, { "name": "check_trailing_skip", "long_name": "check_trailing_skip( self )", "filename": "test_function_base.py", "nloc": 4, "complexity": 1, "token_count": 56, "parameters": [ "self" ], "start_line": 196, "end_line": 199, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 4, "top_nesting_level": 1 }, { "name": "check_basic", "long_name": "check_basic( self )", "filename": "test_function_base.py", "nloc": 4, "complexity": 1, "token_count": 51, "parameters": [ "self" ], "start_line": 203, "end_line": 206, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 4, "top_nesting_level": 1 }, { "name": "check_insert", "long_name": "check_insert( self )", "filename": "test_function_base.py", "nloc": 4, "complexity": 1, "token_count": 73, "parameters": [ "self" ], "start_line": 207, "end_line": 210, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 4, "top_nesting_level": 1 }, { "name": "check_both", "long_name": "check_both( self )", "filename": "test_function_base.py", "nloc": 8, "complexity": 1, "token_count": 55, "parameters": [ "self" ], "start_line": 211, "end_line": 218, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 8, "top_nesting_level": 1 }, { "name": "check_simple.addsubtract", "long_name": "check_simple.addsubtract( a , b )", "filename": "test_function_base.py", "nloc": 5, "complexity": 2, "token_count": 22, "parameters": [ "a", "b" ], "start_line": 222, "end_line": 226, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 5, "top_nesting_level": 2 }, { "name": "check_simple", "long_name": "check_simple( self )", "filename": "test_function_base.py", "nloc": 5, "complexity": 1, "token_count": 51, "parameters": [ "self" ], "start_line": 221, "end_line": 229, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 9, "top_nesting_level": 1 }, { "name": "check_scalar.addsubtract", "long_name": "check_scalar.addsubtract( a , b )", "filename": "test_function_base.py", "nloc": 5, "complexity": 2, "token_count": 22, "parameters": [ "a", "b" ], "start_line": 231, "end_line": 235, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 5, "top_nesting_level": 2 }, { "name": "check_scalar", "long_name": "check_scalar( self )", "filename": "test_function_base.py", "nloc": 5, "complexity": 1, "token_count": 43, "parameters": [ "self" ], "start_line": 230, "end_line": 238, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 9, "top_nesting_level": 1 }, { "name": "compare_results", "long_name": "compare_results( res , desired )", "filename": "test_function_base.py", "nloc": 3, "complexity": 2, "token_count": 30, "parameters": [ "res", "desired" ], "start_line": 241, "end_line": 243, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 3, "top_nesting_level": 0 } ], "changed_methods": [ { "name": "check_basic", "long_name": "check_basic( self )", "filename": "test_function_base.py", "nloc": 8, "complexity": 1, "token_count": 122, "parameters": [ "self" ], "start_line": 66, "end_line": 73, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 8, "top_nesting_level": 1 } ], "nloc": 220, "complexity": 34, "token_count": 2610, "diff_parsed": { "added": [ " assert_equal(amax(b),[8.0,10.0,9.0])", " assert_equal(amin(b),[3.0,3.0,2.0])" ], "deleted": [ " assert_equal(amax(b, axis=0),[8.0,10.0,9.0])", " assert_equal(amax(b,axis=-1),[9.0,10.0,8.0])", " assert_equal(amin(b,axis=0),[3.0,3.0,2.0])", " assert_equal(amin(b),[3.0,4.0,2.0])" ] } } ] }, { "hash": "f4dfb7000c7ffa57f5bc8a557d193e8178089b49", "msg": "Applied Todd's patch.", "author": { "name": "Pearu Peterson", "email": "pearu.peterson@gmail.com" }, "committer": { "name": "Pearu Peterson", "email": "pearu.peterson@gmail.com" }, "author_date": "2005-01-05T09:16:19+00:00", "author_timezone": 0, "committer_date": "2005-01-05T09:16:19+00:00", "committer_timezone": 0, "branches": [ "main" ], "in_main_branch": true, "merge": false, "parents": [ "f29481bbf2ec6ece13670e0f419c6dcb6da8bad0" ], "project_name": "repo_copy", "project_path": "/tmp/tmpqop781_j/repo_copy", "deletions": 1, "insertions": 5, "lines": 6, "files": 1, "dmm_unit_size": 1.0, "dmm_unit_complexity": 0.0, "dmm_unit_interfacing": 0.0, "modified_files": [ { "old_path": "scipy_test/testing.py", "new_path": "scipy_test/testing.py", "filename": "testing.py", "extension": "py", "change_type": "MODIFY", "diff": "@@ -39,7 +39,7 @@\n # If Numeric and scipy_base are not available, then some of the\n # functions below will not be available.\n from Numeric import alltrue,equal,shape,ravel,around,zeros,Float64,asarray,\\\n- less_equal,array2string,less\n+ less_equal,array2string,less,ArrayType\n # `import scipy_base.fastumath as math` must be at the end of this file.\n except ImportError,msg:\n print msg\n@@ -634,6 +634,8 @@ def assert_equal(actual,desired,err_msg='',verbose=1):\n \"\"\" Raise an assertion if two items are not\n equal. I think this should be part of unittest.py\n \"\"\"\n+ if isinstance(actual, ArrayType) or isinstance(desired, ArrayType):\n+ return assert_array_equal(actual, desired, err_msg)\n msg = '\\nItems are not equal:\\n' + err_msg\n try:\n if ( verbose and len(repr(desired)) < 100 and len(repr(actual)) ):\n@@ -651,6 +653,8 @@ def assert_almost_equal(actual,desired,decimal=7,err_msg='',verbose=1):\n \"\"\" Raise an assertion if two items are not\n equal. I think this should be part of unittest.py\n \"\"\"\n+ if isinstance(actual, ArrayType) or isinstance(desired, ArrayType):\n+ return assert_array_almost_equal(actual, desired, decimal, err_msg)\n msg = '\\nItems are not equal:\\n' + err_msg\n try:\n if ( verbose and len(repr(desired)) < 100 and len(repr(actual)) ):\n", "added_lines": 5, "deleted_lines": 1, "source_code": "\"\"\"\nUnit-testing\n------------\n\n ScipyTest -- Scipy tests site manager\n ScipyTestCase -- unittest.TestCase with measure method\n IgnoreException -- raise when checking disabled feature ('ignoring' is displayed)\n set_package_path -- prepend package build directory to path\n set_local_path -- prepend local directory (to tests files) to path\n restore_path -- restore path after set_package_path\n\nTiming tools\n------------\n\n jiffies -- return 1/100ths of a second that the current process has used\n memusage -- virtual memory size in bytes of the running python [linux]\n\nUtility functions\n-----------------\n\n assert_equal -- assert equality\n assert_almost_equal -- assert equality with decimal tolerance\n assert_approx_equal -- assert equality with significant digits tolerance\n assert_array_equal -- assert arrays equality\n assert_array_almost_equal -- assert arrays equality with decimal tolerance\n assert_array_less -- assert arrays less-ordering\n rand -- array of random numbers from given shape\n\n\"\"\"\n\n__all__ = []\n\nimport os,sys,time,glob,string,traceback,unittest\nimport types\nimport imp\n\ntry:\n # These are used by Numeric tests.\n # If Numeric and scipy_base are not available, then some of the\n # functions below will not be available.\n from Numeric import alltrue,equal,shape,ravel,around,zeros,Float64,asarray,\\\n less_equal,array2string,less,ArrayType\n # `import scipy_base.fastumath as math` must be at the end of this file.\nexcept ImportError,msg:\n print msg\n\nDEBUG = 0\n\n__all__.append('set_package_path')\ndef set_package_path(level=1):\n \"\"\" Prepend package directory to sys.path.\n\n set_package_path should be called from a test_file.py that\n satisfies the following tree structure:\n\n //test_file.py\n\n Then the first existing path name from the following list\n\n /build/lib.-\n /..\n\n is prepended to sys.path.\n The caller is responsible for removing this path by using\n\n restore_path()\n \"\"\"\n from distutils.util import get_platform\n from scipy_distutils.misc_util import get_frame\n f = get_frame(level)\n if f.f_locals['__name__']=='__main__':\n testfile = sys.argv[0]\n else:\n testfile = f.f_locals['__file__']\n d = os.path.dirname(os.path.dirname(os.path.abspath(testfile)))\n d1 = os.path.join(d,'build','lib.%s-%s'%(get_platform(),sys.version[:3]))\n if not os.path.isdir(d1):\n d1 = os.path.dirname(d)\n if DEBUG:\n print 'Inserting %r to sys.path' % (d1)\n sys.path.insert(0,d1)\n\n__all__.append('set_local_path')\ndef set_local_path(reldir='', level=1):\n \"\"\" Prepend local directory to sys.path.\n\n The caller is responsible for removing this path by using\n\n restore_path()\n \"\"\"\n from scipy_distutils.misc_util import get_frame\n f = get_frame(level)\n if f.f_locals['__name__']=='__main__':\n testfile = sys.argv[0]\n else:\n testfile = f.f_locals['__file__']\n local_path = os.path.join(os.path.dirname(os.path.abspath(testfile)),reldir)\n if DEBUG:\n print 'Inserting %r to sys.path' % (local_path)\n sys.path.insert(0,local_path)\n\n__all__.append('restore_path')\ndef restore_path():\n if DEBUG:\n print 'Removing %r from sys.path' % (sys.path[0])\n del sys.path[0]\n\n__all__.extend(['jiffies','memusage'])\nif sys.platform[:5]=='linux':\n def jiffies(_proc_pid_stat = '/proc/%s/stat'%(os.getpid()),\n _load_time=time.time()):\n \"\"\" Return number of jiffies (1/100ths of a second) that this\n process has been scheduled in user mode. See man 5 proc. \"\"\"\n try:\n f=open(_proc_pid_stat,'r')\n l = f.readline().split(' ')\n f.close()\n return int(l[13])\n except:\n return int(100*(time.time()-_load_time))\n\n def memusage(_proc_pid_stat = '/proc/%s/stat'%(os.getpid())):\n \"\"\" Return virtual memory size in bytes of the running python.\n \"\"\"\n try:\n f=open(_proc_pid_stat,'r')\n l = f.readline().split(' ')\n f.close()\n return int(l[22])\n except:\n return\nelse:\n # os.getpid is not in all platforms available.\n # Using time is safe but inaccurate, especially when process\n # was suspended or sleeping.\n def jiffies(_load_time=time.time()):\n \"\"\" Return number of jiffies (1/100ths of a second) that this\n process has been scheduled in user mode. [Emulation with time.time]. \"\"\"\n return int(100*(time.time()-_load_time))\n\n def memusage():\n \"\"\" Return memory usage of running python. [Not implemented]\"\"\"\n return\n\n__all__.append('ScipyTestCase')\nclass ScipyTestCase (unittest.TestCase):\n\n def measure(self,code_str,times=1):\n \"\"\" Return elapsed time for executing code_str in the\n namespace of the caller for given times.\n \"\"\"\n frame = sys._getframe(1)\n locs,globs = frame.f_locals,frame.f_globals\n code = compile(code_str,\n 'ScipyTestCase runner for '+self.__class__.__name__,\n 'exec')\n i = 0\n elapsed = jiffies()\n while i>> ScipyTest().test(level=1,verbosity=2)\n\n is package name or its module object.\n\n Package is supposed to contain a directory tests/\n with test_*.py files where * refers to the names of submodules.\n\n test_*.py files are supposed to define a classes, derived\n from ScipyTestCase or unittest.TestCase, with methods having\n names starting with test or bench or check.\n\n And that is it! No need to implement test or test_suite functions\n in each .py file.\n\n Also old styled test_suite(level=1) hooks are supported but\n soon to be removed.\n \"\"\"\n def __init__(self, package='__main__'):\n self.package = package\n\n def _module_str(self, module):\n filename = module.__file__[-30:]\n if filename!=module.__file__:\n filename = '...'+filename\n return '' % (`module.__name__`, `filename`)\n\n def _get_method_names(self,clsobj,level):\n names = []\n for mthname in _get_all_method_names(clsobj):\n if mthname[:5] not in ['bench','check'] \\\n and mthname[:4] not in ['test']:\n continue\n mth = getattr(clsobj, mthname)\n if type(mth) is not types.MethodType:\n continue\n d = mth.im_func.func_defaults\n if d is not None:\n mthlevel = d[0]\n else:\n mthlevel = 1\n if level>=mthlevel:\n if mthname not in names:\n names.append(mthname)\n for base in clsobj.__bases__:\n for n in self._get_method_names(base,level):\n if n not in names:\n names.append(n) \n return names\n\n def _get_module_tests(self,module,level):\n mstr = self._module_str\n d,f = os.path.split(module.__file__)\n\n short_module_name = os.path.splitext(os.path.basename(f))[0]\n if short_module_name=='__init__':\n short_module_name = module.__name__.split('.')[-1]\n\n test_dir = os.path.join(d,'tests')\n test_file = os.path.join(test_dir,'test_'+short_module_name+'.py')\n\n local_test_dir = os.path.join(os.getcwd(),'tests')\n local_test_file = os.path.join(local_test_dir,\n 'test_'+short_module_name+'.py')\n if os.path.basename(os.path.dirname(local_test_dir)) \\\n == os.path.basename(os.path.dirname(test_dir)) \\\n and os.path.isfile(local_test_file):\n test_file = local_test_file\n\n if not os.path.isfile(test_file):\n if short_module_name[:5]=='info_' \\\n and short_module_name[5:]==module.__name__.split('.')[-2]:\n return []\n if short_module_name in ['__cvs_version__','__svn_version__']:\n return []\n if short_module_name[-8:]=='_version' \\\n and short_module_name[:-8]==module.__name__.split('.')[-2]:\n return []\n print ' !! No test file %r found for %s' \\\n % (os.path.basename(test_file), mstr(module))\n return []\n\n try:\n if sys.version[:3]=='2.1':\n # Workaround for Python 2.1 .pyc file generator bug\n import random\n pref = '-nopyc'+`random.randint(1,100)`\n else:\n pref = ''\n f = open(test_file,'r')\n test_module = imp.load_module(\\\n module.__name__+'.test_'+short_module_name+pref,\n f, test_file+pref,('.py', 'r', 1))\n f.close()\n if sys.version[:3]=='2.1' and os.path.isfile(test_file+pref+'c'):\n os.remove(test_file+pref+'c')\n except:\n print ' !! FAILURE importing tests for ', mstr(module)\n print ' ',\n output_exception()\n return []\n return self._get_suite_list(test_module, level, module.__name__)\n\n def _get_suite_list(self, test_module, level, module_name='__main__'):\n mstr = self._module_str\n if hasattr(test_module,'test_suite'):\n # Using old styled test suite\n try:\n total_suite = test_module.test_suite(level)\n return total_suite._tests\n except:\n print ' !! FAILURE building tests for ', mstr(test_module)\n print ' ',\n output_exception()\n return []\n suite_list = []\n for name in dir(test_module):\n obj = getattr(test_module, name)\n if type(obj) is not type(unittest.TestCase) \\\n or not issubclass(obj, unittest.TestCase) \\\n or obj.__name__[:4] != 'test':\n continue\n for mthname in self._get_method_names(obj,level):\n suite = obj(mthname)\n if getattr(suite,'isrunnable',lambda mthname:1)(mthname):\n suite_list.append(suite)\n print ' Found',len(suite_list),'tests for',module_name\n return suite_list\n\n def _touch_ppimported(self, module):\n from scipy_base.ppimport import _ModuleLoader\n if os.path.isdir(os.path.join(os.path.dirname(module.__file__),'tests')):\n # only touching those modules that have tests/ directory\n try: module._pliuh_plauh\n except AttributeError: pass\n for name in dir(module):\n obj = getattr(module,name)\n if isinstance(obj,_ModuleLoader) \\\n and not hasattr(obj,'_ppimport_module') \\\n and not hasattr(obj,'_ppimport_exc_info'):\n self._touch_ppimported(obj)\n\n def test(self,level=1,verbosity=1):\n \"\"\" Run Scipy module test suite with level and verbosity.\n \"\"\"\n if type(self.package) is type(''):\n exec 'import %s as this_package' % (self.package)\n else:\n this_package = self.package\n\n self._touch_ppimported(this_package)\n\n package_name = this_package.__name__\n\n suites = []\n for name, module in sys.modules.items():\n if package_name != name[:len(package_name)] \\\n or module is None \\\n or os.path.basename(os.path.dirname(module.__file__))=='tests':\n continue\n suites.extend(self._get_module_tests(module, level))\n\n suites.extend(self._get_suite_list(sys.modules[package_name], level))\n\n all_tests = unittest.TestSuite(suites)\n runner = unittest.TextTestRunner(verbosity=verbosity)\n runner.run(all_tests)\n return runner\n\n def run(self):\n \"\"\" Run Scipy module test suite with level and verbosity\n taken from sys.argv. Requires optparse module.\n \"\"\"\n try:\n from optparse import OptionParser\n except ImportError:\n print 'Failed to import optparse module, ignoring.'\n return self.test()\n usage = r'usage: %prog [-v ] [-l ]'\n parser = OptionParser(usage)\n parser.add_option(\"-v\", \"--verbosity\",\n action=\"store\",\n dest=\"verbosity\",\n default=1,\n type='int')\n parser.add_option(\"-l\", \"--level\",\n action=\"store\",\n dest=\"level\",\n default=1,\n type='int')\n (options, args) = parser.parse_args()\n self.test(options.level,options.verbosity)\n\n#------------\n \ndef remove_ignored_patterns(files,pattern):\n from fnmatch import fnmatch\n good_files = []\n for file in files:\n if not fnmatch(file,pattern):\n good_files.append(file)\n return good_files\n\ndef remove_ignored_files(original,ignored_files,cur_dir):\n \"\"\" This is actually expanded to do pattern matching.\n\n \"\"\"\n if not ignored_files: ignored_files = []\n ignored_modules = map(lambda x: x+'.py',ignored_files)\n ignored_packages = ignored_files[:]\n # always ignore setup.py and __init__.py files\n ignored_files = ['setup.py','setup_*.py','__init__.py']\n ignored_files += ignored_modules + ignored_packages\n ignored_files = map(lambda x,cur_dir=cur_dir: os.path.join(cur_dir,x),\n ignored_files)\n #print 'ignored:', ignored_files\n #good_files = filter(lambda x,ignored = ignored_files: x not in ignored,\n # original)\n good_files = original\n for pattern in ignored_files:\n good_files = remove_ignored_patterns(good_files,pattern)\n\n return good_files\n\n__all__.append('harvest_modules')\ndef harvest_modules(package,ignore=None):\n \"\"\"* Retreive a list of all modules that live within a package.\n\n Only retreive files that are immediate children of the\n package -- do not recurse through child packages or\n directories. The returned list contains actual modules, not\n just their names.\n *\"\"\"\n d,f = os.path.split(package.__file__)\n\n # go through the directory and import every py file there.\n common_dir = os.path.join(d,'*.py')\n py_files = glob.glob(common_dir)\n #py_files.remove(os.path.join(d,'__init__.py'))\n #py_files.remove(os.path.join(d,'setup.py'))\n\n py_files = remove_ignored_files(py_files,ignore,d)\n #print 'py_files:', py_files\n try:\n prefix = package.__name__\n except:\n prefix = ''\n\n all_modules = []\n for file in py_files:\n d,f = os.path.split(file)\n base,ext = os.path.splitext(f)\n mod = prefix + '.' + base\n #print 'module: import ' + mod\n try:\n exec ('import ' + mod)\n all_modules.append(eval(mod))\n except:\n print 'FAILURE to import ' + mod\n output_exception()\n\n return all_modules\n\n__all__.append('harvest_packages')\ndef harvest_packages(package,ignore = None):\n \"\"\" Retreive a list of all sub-packages that live within a package.\n\n Only retreive packages that are immediate children of this\n package -- do not recurse through child packages or\n directories. The returned list contains actual package objects, not\n just their names.\n \"\"\"\n join = os.path.join\n\n d,f = os.path.split(package.__file__)\n\n common_dir = os.path.abspath(d)\n all_files = os.listdir(d)\n\n all_files = remove_ignored_files(all_files,ignore,'')\n #print 'all_files:', all_files\n try:\n prefix = package.__name__\n except:\n prefix = ''\n all_packages = []\n for directory in all_files:\n path = join(common_dir,directory)\n if os.path.isdir(path) and \\\n os.path.exists(join(path,'__init__.py')):\n sub_package = prefix + '.' + directory\n #print 'sub-package import ' + sub_package\n try:\n exec ('import ' + sub_package)\n all_packages.append(eval(sub_package))\n except:\n print 'FAILURE to import ' + sub_package\n output_exception()\n return all_packages\n\n__all__.append('harvest_modules_and_packages')\ndef harvest_modules_and_packages(package,ignore=None):\n \"\"\" Retreive list of all packages and modules that live within a package.\n\n See harvest_packages() and harvest_modules()\n \"\"\"\n all = harvest_modules(package,ignore) + harvest_packages(package,ignore)\n return all\n\n__all__.append('harvest_test_suites')\ndef harvest_test_suites(package,ignore = None,level=10):\n \"\"\"\n package -- the module to test. This is an actual module object\n (not a string)\n ignore -- a list of module names to omit from the tests\n level -- a value between 1 and 10. 1 will run the minimum number\n of tests. This is a fast \"smoke test\". Tests that take\n longer to run should have higher numbers ranging up to 10.\n \"\"\"\n suites=[]\n test_modules = harvest_modules_and_packages(package,ignore)\n #for i in test_modules:\n # print i.__name__\n for module in test_modules:\n if hasattr(module,'test_suite'):\n try:\n suite = module.test_suite(level=level)\n if suite:\n suites.append(suite)\n else:\n print \" !! FAILURE without error - shouldn't happen\",\n print module.__name__\n except:\n print ' !! FAILURE building test for ', module.__name__\n print ' ',\n output_exception()\n else:\n try:\n print 'No test suite found for ', module.__name__\n except AttributeError:\n # __version__.py getting replaced by a string throws a kink\n # in checking for modules, so we think is a module has\n # actually been overwritten\n print 'No test suite found for ', str(module)\n total_suite = unittest.TestSuite(suites)\n return total_suite\n\n__all__.append('module_test')\ndef module_test(mod_name,mod_file,level=10):\n \"\"\"*\n\n *\"\"\"\n #print 'testing', mod_name\n d,f = os.path.split(mod_file)\n\n # insert the tests directory to the python path\n test_dir = os.path.join(d,'tests')\n sys.path.insert(0,test_dir)\n\n # call the \"test_xxx.test()\" function for the appropriate\n # module.\n\n # This should deal with package naming issues correctly\n short_mod_name = string.split(mod_name,'.')[-1]\n test_module = 'test_' + short_mod_name\n test_string = 'import %s;reload(%s);%s.test(%d)' % \\\n ((test_module,)*3 + (level,))\n\n # This would be better cause it forces a reload of the orginal\n # module. It doesn't behave with packages however.\n #test_string = 'reload(%s);import %s;reload(%s);%s.test(%d)' % \\\n # ((mod_name,) + (test_module,)*3)\n exec(test_string)\n\n # remove test directory from python path.\n sys.path = sys.path[1:]\n\n__all__.append('module_test_suite')\ndef module_test_suite(mod_name,mod_file,level=10):\n #try:\n print ' creating test suite for:', mod_name\n d,f = os.path.split(mod_file)\n\n # insert the tests directory to the python path\n test_dir = os.path.join(d,'tests')\n sys.path.insert(0,test_dir)\n\n # call the \"test_xxx.test()\" function for the appropriate\n # module.\n\n # This should deal with package naming issues correctly\n short_mod_name = string.split(mod_name,'.')[-1]\n test_module = 'test_' + short_mod_name\n test_string = 'import %s;reload(%s);suite = %s.test_suite(%d)' % \\\n ((test_module,)*3+(level,))\n #print test_string\n exec(test_string)\n\n # remove test directory from python path.\n sys.path = sys.path[1:]\n return suite\n #except:\n # print ' !! FAILURE loading test suite from', test_module, ':'\n # print ' ',\n # output_exception()\n\n\n# Utility function to facilitate testing.\n\n__all__.append('assert_equal')\ndef assert_equal(actual,desired,err_msg='',verbose=1):\n \"\"\" Raise an assertion if two items are not\n equal. I think this should be part of unittest.py\n \"\"\"\n if isinstance(actual, ArrayType) or isinstance(desired, ArrayType):\n return assert_array_equal(actual, desired, err_msg)\n msg = '\\nItems are not equal:\\n' + err_msg\n try:\n if ( verbose and len(repr(desired)) < 100 and len(repr(actual)) ):\n msg = msg \\\n + 'DESIRED: ' + repr(desired) \\\n + '\\nACTUAL: ' + repr(actual)\n except:\n msg = msg \\\n + 'DESIRED: ' + repr(desired) \\\n + '\\nACTUAL: ' + repr(actual)\n assert desired == actual, msg\n\n__all__.append('assert_almost_equal')\ndef assert_almost_equal(actual,desired,decimal=7,err_msg='',verbose=1):\n \"\"\" Raise an assertion if two items are not\n equal. I think this should be part of unittest.py\n \"\"\"\n if isinstance(actual, ArrayType) or isinstance(desired, ArrayType):\n return assert_array_almost_equal(actual, desired, decimal, err_msg)\n msg = '\\nItems are not equal:\\n' + err_msg\n try:\n if ( verbose and len(repr(desired)) < 100 and len(repr(actual)) ):\n msg = msg \\\n + 'DESIRED: ' + repr(desired) \\\n + '\\nACTUAL: ' + repr(actual)\n except:\n msg = msg \\\n + 'DESIRED: ' + repr(desired) \\\n + '\\nACTUAL: ' + repr(actual)\n assert round(abs(desired - actual),decimal) == 0, msg\n\n__all__.append('assert_approx_equal')\ndef assert_approx_equal(actual,desired,significant=7,err_msg='',verbose=1):\n \"\"\" Raise an assertion if two items are not\n equal. I think this should be part of unittest.py\n Approximately equal is defined as the number of significant digits\n correct\n \"\"\"\n msg = '\\nItems are not equal to %d significant digits:\\n' % significant\n msg += err_msg\n actual, desired = map(float, (actual, desired))\n # Normalized the numbers to be in range (-10.0,10.0)\n scale = pow(10,math.floor(math.log10(0.5*(abs(desired)+abs(actual)))))\n try:\n sc_desired = desired/scale\n except ZeroDivisionError:\n sc_desired = 0.0\n try:\n sc_actual = actual/scale\n except ZeroDivisionError:\n sc_actual = 0.0\n try:\n if ( verbose and len(repr(desired)) < 100 and len(repr(actual)) ):\n msg = msg \\\n + 'DESIRED: ' + repr(desired) \\\n + '\\nACTUAL: ' + repr(actual)\n except:\n msg = msg \\\n + 'DESIRED: ' + repr(desired) \\\n + '\\nACTUAL: ' + repr(actual)\n assert math.fabs(sc_desired - sc_actual) < pow(10.,-1*significant), msg\n\n\n__all__.append('assert_array_equal')\ndef assert_array_equal(x,y,err_msg=''):\n x,y = asarray(x), asarray(y)\n msg = '\\nArrays are not equal'\n try:\n assert 0 in [len(shape(x)),len(shape(y))] \\\n or (len(shape(x))==len(shape(y)) and \\\n alltrue(equal(shape(x),shape(y)))),\\\n msg + ' (shapes %s, %s mismatch):\\n\\t' \\\n % (shape(x),shape(y)) + err_msg\n reduced = ravel(equal(x,y))\n cond = alltrue(reduced)\n if not cond:\n s1 = array2string(x,precision=16)\n s2 = array2string(y,precision=16)\n if len(s1)>120: s1 = s1[:120] + '...'\n if len(s2)>120: s2 = s2[:120] + '...'\n match = 100-100.0*reduced.tolist().count(1)/len(reduced)\n msg = msg + ' (mismatch %s%%):\\n\\tArray 1: %s\\n\\tArray 2: %s' % (match,s1,s2)\n assert cond,\\\n msg + '\\n\\t' + err_msg\n except ValueError:\n raise ValueError, msg\n\n__all__.append('assert_array_almost_equal')\ndef assert_array_almost_equal(x,y,decimal=6,err_msg=''):\n x = asarray(x)\n y = asarray(y)\n msg = '\\nArrays are not almost equal'\n try:\n cond = alltrue(equal(shape(x),shape(y)))\n if not cond:\n msg = msg + ' (shapes mismatch):\\n\\t'\\\n 'Shape of array 1: %s\\n\\tShape of array 2: %s' % (shape(x),shape(y))\n assert cond, msg + '\\n\\t' + err_msg\n reduced = ravel(equal(less_equal(around(abs(x-y),decimal),10.0**(-decimal)),1))\n cond = alltrue(reduced)\n if not cond:\n s1 = array2string(x,precision=decimal+1)\n s2 = array2string(y,precision=decimal+1)\n if len(s1)>120: s1 = s1[:120] + '...'\n if len(s2)>120: s2 = s2[:120] + '...'\n match = 100-100.0*reduced.tolist().count(1)/len(reduced)\n msg = msg + ' (mismatch %s%%):\\n\\tArray 1: %s\\n\\tArray 2: %s' % (match,s1,s2)\n assert cond,\\\n msg + '\\n\\t' + err_msg\n except ValueError:\n print sys.exc_value\n print shape(x),shape(y)\n print x, y\n raise ValueError, 'arrays are not almost equal'\n\n__all__.append('assert_array_less')\ndef assert_array_less(x,y,err_msg=''):\n x,y = asarray(x), asarray(y)\n msg = '\\nArrays are not less-ordered'\n try:\n assert alltrue(equal(shape(x),shape(y))),\\\n msg + ' (shapes mismatch):\\n\\t' + err_msg\n reduced = ravel(less(x,y))\n cond = alltrue(reduced)\n if not cond:\n s1 = array2string(x,precision=16)\n s2 = array2string(y,precision=16)\n if len(s1)>120: s1 = s1[:120] + '...'\n if len(s2)>120: s2 = s2[:120] + '...'\n match = 100-100.0*reduced.tolist().count(1)/len(reduced)\n msg = msg + ' (mismatch %s%%):\\n\\tArray 1: %s\\n\\tArray 2: %s' % (match,s1,s2)\n assert cond,\\\n msg + '\\n\\t' + err_msg\n except ValueError:\n print shape(x),shape(y)\n raise ValueError, 'arrays are not less-ordered'\n\n__all__.append('rand')\ndef rand(*args):\n \"\"\" Returns an array of random numbers with the given shape.\n used for testing\n \"\"\"\n import random\n results = zeros(args,Float64)\n f = results.flat\n for i in range(len(f)):\n f[i] = random.random()\n return results\n\ndef output_exception():\n try:\n type, value, tb = sys.exc_info()\n info = traceback.extract_tb(tb)\n #this is more verbose\n #traceback.print_exc()\n filename, lineno, function, text = info[-1] # last line only\n print \"%s:%d: %s: %s (in %s)\" %\\\n (filename, lineno, type.__name__, str(value), function)\n finally:\n type = value = tb = None # clean up\n\ntry:\n import scipy_base.fastumath as math\nexcept ImportError,msg:\n print msg\n import math\n", "source_code_before": "\"\"\"\nUnit-testing\n------------\n\n ScipyTest -- Scipy tests site manager\n ScipyTestCase -- unittest.TestCase with measure method\n IgnoreException -- raise when checking disabled feature ('ignoring' is displayed)\n set_package_path -- prepend package build directory to path\n set_local_path -- prepend local directory (to tests files) to path\n restore_path -- restore path after set_package_path\n\nTiming tools\n------------\n\n jiffies -- return 1/100ths of a second that the current process has used\n memusage -- virtual memory size in bytes of the running python [linux]\n\nUtility functions\n-----------------\n\n assert_equal -- assert equality\n assert_almost_equal -- assert equality with decimal tolerance\n assert_approx_equal -- assert equality with significant digits tolerance\n assert_array_equal -- assert arrays equality\n assert_array_almost_equal -- assert arrays equality with decimal tolerance\n assert_array_less -- assert arrays less-ordering\n rand -- array of random numbers from given shape\n\n\"\"\"\n\n__all__ = []\n\nimport os,sys,time,glob,string,traceback,unittest\nimport types\nimport imp\n\ntry:\n # These are used by Numeric tests.\n # If Numeric and scipy_base are not available, then some of the\n # functions below will not be available.\n from Numeric import alltrue,equal,shape,ravel,around,zeros,Float64,asarray,\\\n less_equal,array2string,less\n # `import scipy_base.fastumath as math` must be at the end of this file.\nexcept ImportError,msg:\n print msg\n\nDEBUG = 0\n\n__all__.append('set_package_path')\ndef set_package_path(level=1):\n \"\"\" Prepend package directory to sys.path.\n\n set_package_path should be called from a test_file.py that\n satisfies the following tree structure:\n\n //test_file.py\n\n Then the first existing path name from the following list\n\n /build/lib.-\n /..\n\n is prepended to sys.path.\n The caller is responsible for removing this path by using\n\n restore_path()\n \"\"\"\n from distutils.util import get_platform\n from scipy_distutils.misc_util import get_frame\n f = get_frame(level)\n if f.f_locals['__name__']=='__main__':\n testfile = sys.argv[0]\n else:\n testfile = f.f_locals['__file__']\n d = os.path.dirname(os.path.dirname(os.path.abspath(testfile)))\n d1 = os.path.join(d,'build','lib.%s-%s'%(get_platform(),sys.version[:3]))\n if not os.path.isdir(d1):\n d1 = os.path.dirname(d)\n if DEBUG:\n print 'Inserting %r to sys.path' % (d1)\n sys.path.insert(0,d1)\n\n__all__.append('set_local_path')\ndef set_local_path(reldir='', level=1):\n \"\"\" Prepend local directory to sys.path.\n\n The caller is responsible for removing this path by using\n\n restore_path()\n \"\"\"\n from scipy_distutils.misc_util import get_frame\n f = get_frame(level)\n if f.f_locals['__name__']=='__main__':\n testfile = sys.argv[0]\n else:\n testfile = f.f_locals['__file__']\n local_path = os.path.join(os.path.dirname(os.path.abspath(testfile)),reldir)\n if DEBUG:\n print 'Inserting %r to sys.path' % (local_path)\n sys.path.insert(0,local_path)\n\n__all__.append('restore_path')\ndef restore_path():\n if DEBUG:\n print 'Removing %r from sys.path' % (sys.path[0])\n del sys.path[0]\n\n__all__.extend(['jiffies','memusage'])\nif sys.platform[:5]=='linux':\n def jiffies(_proc_pid_stat = '/proc/%s/stat'%(os.getpid()),\n _load_time=time.time()):\n \"\"\" Return number of jiffies (1/100ths of a second) that this\n process has been scheduled in user mode. See man 5 proc. \"\"\"\n try:\n f=open(_proc_pid_stat,'r')\n l = f.readline().split(' ')\n f.close()\n return int(l[13])\n except:\n return int(100*(time.time()-_load_time))\n\n def memusage(_proc_pid_stat = '/proc/%s/stat'%(os.getpid())):\n \"\"\" Return virtual memory size in bytes of the running python.\n \"\"\"\n try:\n f=open(_proc_pid_stat,'r')\n l = f.readline().split(' ')\n f.close()\n return int(l[22])\n except:\n return\nelse:\n # os.getpid is not in all platforms available.\n # Using time is safe but inaccurate, especially when process\n # was suspended or sleeping.\n def jiffies(_load_time=time.time()):\n \"\"\" Return number of jiffies (1/100ths of a second) that this\n process has been scheduled in user mode. [Emulation with time.time]. \"\"\"\n return int(100*(time.time()-_load_time))\n\n def memusage():\n \"\"\" Return memory usage of running python. [Not implemented]\"\"\"\n return\n\n__all__.append('ScipyTestCase')\nclass ScipyTestCase (unittest.TestCase):\n\n def measure(self,code_str,times=1):\n \"\"\" Return elapsed time for executing code_str in the\n namespace of the caller for given times.\n \"\"\"\n frame = sys._getframe(1)\n locs,globs = frame.f_locals,frame.f_globals\n code = compile(code_str,\n 'ScipyTestCase runner for '+self.__class__.__name__,\n 'exec')\n i = 0\n elapsed = jiffies()\n while i>> ScipyTest().test(level=1,verbosity=2)\n\n is package name or its module object.\n\n Package is supposed to contain a directory tests/\n with test_*.py files where * refers to the names of submodules.\n\n test_*.py files are supposed to define a classes, derived\n from ScipyTestCase or unittest.TestCase, with methods having\n names starting with test or bench or check.\n\n And that is it! No need to implement test or test_suite functions\n in each .py file.\n\n Also old styled test_suite(level=1) hooks are supported but\n soon to be removed.\n \"\"\"\n def __init__(self, package='__main__'):\n self.package = package\n\n def _module_str(self, module):\n filename = module.__file__[-30:]\n if filename!=module.__file__:\n filename = '...'+filename\n return '' % (`module.__name__`, `filename`)\n\n def _get_method_names(self,clsobj,level):\n names = []\n for mthname in _get_all_method_names(clsobj):\n if mthname[:5] not in ['bench','check'] \\\n and mthname[:4] not in ['test']:\n continue\n mth = getattr(clsobj, mthname)\n if type(mth) is not types.MethodType:\n continue\n d = mth.im_func.func_defaults\n if d is not None:\n mthlevel = d[0]\n else:\n mthlevel = 1\n if level>=mthlevel:\n if mthname not in names:\n names.append(mthname)\n for base in clsobj.__bases__:\n for n in self._get_method_names(base,level):\n if n not in names:\n names.append(n) \n return names\n\n def _get_module_tests(self,module,level):\n mstr = self._module_str\n d,f = os.path.split(module.__file__)\n\n short_module_name = os.path.splitext(os.path.basename(f))[0]\n if short_module_name=='__init__':\n short_module_name = module.__name__.split('.')[-1]\n\n test_dir = os.path.join(d,'tests')\n test_file = os.path.join(test_dir,'test_'+short_module_name+'.py')\n\n local_test_dir = os.path.join(os.getcwd(),'tests')\n local_test_file = os.path.join(local_test_dir,\n 'test_'+short_module_name+'.py')\n if os.path.basename(os.path.dirname(local_test_dir)) \\\n == os.path.basename(os.path.dirname(test_dir)) \\\n and os.path.isfile(local_test_file):\n test_file = local_test_file\n\n if not os.path.isfile(test_file):\n if short_module_name[:5]=='info_' \\\n and short_module_name[5:]==module.__name__.split('.')[-2]:\n return []\n if short_module_name in ['__cvs_version__','__svn_version__']:\n return []\n if short_module_name[-8:]=='_version' \\\n and short_module_name[:-8]==module.__name__.split('.')[-2]:\n return []\n print ' !! No test file %r found for %s' \\\n % (os.path.basename(test_file), mstr(module))\n return []\n\n try:\n if sys.version[:3]=='2.1':\n # Workaround for Python 2.1 .pyc file generator bug\n import random\n pref = '-nopyc'+`random.randint(1,100)`\n else:\n pref = ''\n f = open(test_file,'r')\n test_module = imp.load_module(\\\n module.__name__+'.test_'+short_module_name+pref,\n f, test_file+pref,('.py', 'r', 1))\n f.close()\n if sys.version[:3]=='2.1' and os.path.isfile(test_file+pref+'c'):\n os.remove(test_file+pref+'c')\n except:\n print ' !! FAILURE importing tests for ', mstr(module)\n print ' ',\n output_exception()\n return []\n return self._get_suite_list(test_module, level, module.__name__)\n\n def _get_suite_list(self, test_module, level, module_name='__main__'):\n mstr = self._module_str\n if hasattr(test_module,'test_suite'):\n # Using old styled test suite\n try:\n total_suite = test_module.test_suite(level)\n return total_suite._tests\n except:\n print ' !! FAILURE building tests for ', mstr(test_module)\n print ' ',\n output_exception()\n return []\n suite_list = []\n for name in dir(test_module):\n obj = getattr(test_module, name)\n if type(obj) is not type(unittest.TestCase) \\\n or not issubclass(obj, unittest.TestCase) \\\n or obj.__name__[:4] != 'test':\n continue\n for mthname in self._get_method_names(obj,level):\n suite = obj(mthname)\n if getattr(suite,'isrunnable',lambda mthname:1)(mthname):\n suite_list.append(suite)\n print ' Found',len(suite_list),'tests for',module_name\n return suite_list\n\n def _touch_ppimported(self, module):\n from scipy_base.ppimport import _ModuleLoader\n if os.path.isdir(os.path.join(os.path.dirname(module.__file__),'tests')):\n # only touching those modules that have tests/ directory\n try: module._pliuh_plauh\n except AttributeError: pass\n for name in dir(module):\n obj = getattr(module,name)\n if isinstance(obj,_ModuleLoader) \\\n and not hasattr(obj,'_ppimport_module') \\\n and not hasattr(obj,'_ppimport_exc_info'):\n self._touch_ppimported(obj)\n\n def test(self,level=1,verbosity=1):\n \"\"\" Run Scipy module test suite with level and verbosity.\n \"\"\"\n if type(self.package) is type(''):\n exec 'import %s as this_package' % (self.package)\n else:\n this_package = self.package\n\n self._touch_ppimported(this_package)\n\n package_name = this_package.__name__\n\n suites = []\n for name, module in sys.modules.items():\n if package_name != name[:len(package_name)] \\\n or module is None \\\n or os.path.basename(os.path.dirname(module.__file__))=='tests':\n continue\n suites.extend(self._get_module_tests(module, level))\n\n suites.extend(self._get_suite_list(sys.modules[package_name], level))\n\n all_tests = unittest.TestSuite(suites)\n runner = unittest.TextTestRunner(verbosity=verbosity)\n runner.run(all_tests)\n return runner\n\n def run(self):\n \"\"\" Run Scipy module test suite with level and verbosity\n taken from sys.argv. Requires optparse module.\n \"\"\"\n try:\n from optparse import OptionParser\n except ImportError:\n print 'Failed to import optparse module, ignoring.'\n return self.test()\n usage = r'usage: %prog [-v ] [-l ]'\n parser = OptionParser(usage)\n parser.add_option(\"-v\", \"--verbosity\",\n action=\"store\",\n dest=\"verbosity\",\n default=1,\n type='int')\n parser.add_option(\"-l\", \"--level\",\n action=\"store\",\n dest=\"level\",\n default=1,\n type='int')\n (options, args) = parser.parse_args()\n self.test(options.level,options.verbosity)\n\n#------------\n \ndef remove_ignored_patterns(files,pattern):\n from fnmatch import fnmatch\n good_files = []\n for file in files:\n if not fnmatch(file,pattern):\n good_files.append(file)\n return good_files\n\ndef remove_ignored_files(original,ignored_files,cur_dir):\n \"\"\" This is actually expanded to do pattern matching.\n\n \"\"\"\n if not ignored_files: ignored_files = []\n ignored_modules = map(lambda x: x+'.py',ignored_files)\n ignored_packages = ignored_files[:]\n # always ignore setup.py and __init__.py files\n ignored_files = ['setup.py','setup_*.py','__init__.py']\n ignored_files += ignored_modules + ignored_packages\n ignored_files = map(lambda x,cur_dir=cur_dir: os.path.join(cur_dir,x),\n ignored_files)\n #print 'ignored:', ignored_files\n #good_files = filter(lambda x,ignored = ignored_files: x not in ignored,\n # original)\n good_files = original\n for pattern in ignored_files:\n good_files = remove_ignored_patterns(good_files,pattern)\n\n return good_files\n\n__all__.append('harvest_modules')\ndef harvest_modules(package,ignore=None):\n \"\"\"* Retreive a list of all modules that live within a package.\n\n Only retreive files that are immediate children of the\n package -- do not recurse through child packages or\n directories. The returned list contains actual modules, not\n just their names.\n *\"\"\"\n d,f = os.path.split(package.__file__)\n\n # go through the directory and import every py file there.\n common_dir = os.path.join(d,'*.py')\n py_files = glob.glob(common_dir)\n #py_files.remove(os.path.join(d,'__init__.py'))\n #py_files.remove(os.path.join(d,'setup.py'))\n\n py_files = remove_ignored_files(py_files,ignore,d)\n #print 'py_files:', py_files\n try:\n prefix = package.__name__\n except:\n prefix = ''\n\n all_modules = []\n for file in py_files:\n d,f = os.path.split(file)\n base,ext = os.path.splitext(f)\n mod = prefix + '.' + base\n #print 'module: import ' + mod\n try:\n exec ('import ' + mod)\n all_modules.append(eval(mod))\n except:\n print 'FAILURE to import ' + mod\n output_exception()\n\n return all_modules\n\n__all__.append('harvest_packages')\ndef harvest_packages(package,ignore = None):\n \"\"\" Retreive a list of all sub-packages that live within a package.\n\n Only retreive packages that are immediate children of this\n package -- do not recurse through child packages or\n directories. The returned list contains actual package objects, not\n just their names.\n \"\"\"\n join = os.path.join\n\n d,f = os.path.split(package.__file__)\n\n common_dir = os.path.abspath(d)\n all_files = os.listdir(d)\n\n all_files = remove_ignored_files(all_files,ignore,'')\n #print 'all_files:', all_files\n try:\n prefix = package.__name__\n except:\n prefix = ''\n all_packages = []\n for directory in all_files:\n path = join(common_dir,directory)\n if os.path.isdir(path) and \\\n os.path.exists(join(path,'__init__.py')):\n sub_package = prefix + '.' + directory\n #print 'sub-package import ' + sub_package\n try:\n exec ('import ' + sub_package)\n all_packages.append(eval(sub_package))\n except:\n print 'FAILURE to import ' + sub_package\n output_exception()\n return all_packages\n\n__all__.append('harvest_modules_and_packages')\ndef harvest_modules_and_packages(package,ignore=None):\n \"\"\" Retreive list of all packages and modules that live within a package.\n\n See harvest_packages() and harvest_modules()\n \"\"\"\n all = harvest_modules(package,ignore) + harvest_packages(package,ignore)\n return all\n\n__all__.append('harvest_test_suites')\ndef harvest_test_suites(package,ignore = None,level=10):\n \"\"\"\n package -- the module to test. This is an actual module object\n (not a string)\n ignore -- a list of module names to omit from the tests\n level -- a value between 1 and 10. 1 will run the minimum number\n of tests. This is a fast \"smoke test\". Tests that take\n longer to run should have higher numbers ranging up to 10.\n \"\"\"\n suites=[]\n test_modules = harvest_modules_and_packages(package,ignore)\n #for i in test_modules:\n # print i.__name__\n for module in test_modules:\n if hasattr(module,'test_suite'):\n try:\n suite = module.test_suite(level=level)\n if suite:\n suites.append(suite)\n else:\n print \" !! FAILURE without error - shouldn't happen\",\n print module.__name__\n except:\n print ' !! FAILURE building test for ', module.__name__\n print ' ',\n output_exception()\n else:\n try:\n print 'No test suite found for ', module.__name__\n except AttributeError:\n # __version__.py getting replaced by a string throws a kink\n # in checking for modules, so we think is a module has\n # actually been overwritten\n print 'No test suite found for ', str(module)\n total_suite = unittest.TestSuite(suites)\n return total_suite\n\n__all__.append('module_test')\ndef module_test(mod_name,mod_file,level=10):\n \"\"\"*\n\n *\"\"\"\n #print 'testing', mod_name\n d,f = os.path.split(mod_file)\n\n # insert the tests directory to the python path\n test_dir = os.path.join(d,'tests')\n sys.path.insert(0,test_dir)\n\n # call the \"test_xxx.test()\" function for the appropriate\n # module.\n\n # This should deal with package naming issues correctly\n short_mod_name = string.split(mod_name,'.')[-1]\n test_module = 'test_' + short_mod_name\n test_string = 'import %s;reload(%s);%s.test(%d)' % \\\n ((test_module,)*3 + (level,))\n\n # This would be better cause it forces a reload of the orginal\n # module. It doesn't behave with packages however.\n #test_string = 'reload(%s);import %s;reload(%s);%s.test(%d)' % \\\n # ((mod_name,) + (test_module,)*3)\n exec(test_string)\n\n # remove test directory from python path.\n sys.path = sys.path[1:]\n\n__all__.append('module_test_suite')\ndef module_test_suite(mod_name,mod_file,level=10):\n #try:\n print ' creating test suite for:', mod_name\n d,f = os.path.split(mod_file)\n\n # insert the tests directory to the python path\n test_dir = os.path.join(d,'tests')\n sys.path.insert(0,test_dir)\n\n # call the \"test_xxx.test()\" function for the appropriate\n # module.\n\n # This should deal with package naming issues correctly\n short_mod_name = string.split(mod_name,'.')[-1]\n test_module = 'test_' + short_mod_name\n test_string = 'import %s;reload(%s);suite = %s.test_suite(%d)' % \\\n ((test_module,)*3+(level,))\n #print test_string\n exec(test_string)\n\n # remove test directory from python path.\n sys.path = sys.path[1:]\n return suite\n #except:\n # print ' !! FAILURE loading test suite from', test_module, ':'\n # print ' ',\n # output_exception()\n\n\n# Utility function to facilitate testing.\n\n__all__.append('assert_equal')\ndef assert_equal(actual,desired,err_msg='',verbose=1):\n \"\"\" Raise an assertion if two items are not\n equal. I think this should be part of unittest.py\n \"\"\"\n msg = '\\nItems are not equal:\\n' + err_msg\n try:\n if ( verbose and len(repr(desired)) < 100 and len(repr(actual)) ):\n msg = msg \\\n + 'DESIRED: ' + repr(desired) \\\n + '\\nACTUAL: ' + repr(actual)\n except:\n msg = msg \\\n + 'DESIRED: ' + repr(desired) \\\n + '\\nACTUAL: ' + repr(actual)\n assert desired == actual, msg\n\n__all__.append('assert_almost_equal')\ndef assert_almost_equal(actual,desired,decimal=7,err_msg='',verbose=1):\n \"\"\" Raise an assertion if two items are not\n equal. I think this should be part of unittest.py\n \"\"\"\n msg = '\\nItems are not equal:\\n' + err_msg\n try:\n if ( verbose and len(repr(desired)) < 100 and len(repr(actual)) ):\n msg = msg \\\n + 'DESIRED: ' + repr(desired) \\\n + '\\nACTUAL: ' + repr(actual)\n except:\n msg = msg \\\n + 'DESIRED: ' + repr(desired) \\\n + '\\nACTUAL: ' + repr(actual)\n assert round(abs(desired - actual),decimal) == 0, msg\n\n__all__.append('assert_approx_equal')\ndef assert_approx_equal(actual,desired,significant=7,err_msg='',verbose=1):\n \"\"\" Raise an assertion if two items are not\n equal. I think this should be part of unittest.py\n Approximately equal is defined as the number of significant digits\n correct\n \"\"\"\n msg = '\\nItems are not equal to %d significant digits:\\n' % significant\n msg += err_msg\n actual, desired = map(float, (actual, desired))\n # Normalized the numbers to be in range (-10.0,10.0)\n scale = pow(10,math.floor(math.log10(0.5*(abs(desired)+abs(actual)))))\n try:\n sc_desired = desired/scale\n except ZeroDivisionError:\n sc_desired = 0.0\n try:\n sc_actual = actual/scale\n except ZeroDivisionError:\n sc_actual = 0.0\n try:\n if ( verbose and len(repr(desired)) < 100 and len(repr(actual)) ):\n msg = msg \\\n + 'DESIRED: ' + repr(desired) \\\n + '\\nACTUAL: ' + repr(actual)\n except:\n msg = msg \\\n + 'DESIRED: ' + repr(desired) \\\n + '\\nACTUAL: ' + repr(actual)\n assert math.fabs(sc_desired - sc_actual) < pow(10.,-1*significant), msg\n\n\n__all__.append('assert_array_equal')\ndef assert_array_equal(x,y,err_msg=''):\n x,y = asarray(x), asarray(y)\n msg = '\\nArrays are not equal'\n try:\n assert 0 in [len(shape(x)),len(shape(y))] \\\n or (len(shape(x))==len(shape(y)) and \\\n alltrue(equal(shape(x),shape(y)))),\\\n msg + ' (shapes %s, %s mismatch):\\n\\t' \\\n % (shape(x),shape(y)) + err_msg\n reduced = ravel(equal(x,y))\n cond = alltrue(reduced)\n if not cond:\n s1 = array2string(x,precision=16)\n s2 = array2string(y,precision=16)\n if len(s1)>120: s1 = s1[:120] + '...'\n if len(s2)>120: s2 = s2[:120] + '...'\n match = 100-100.0*reduced.tolist().count(1)/len(reduced)\n msg = msg + ' (mismatch %s%%):\\n\\tArray 1: %s\\n\\tArray 2: %s' % (match,s1,s2)\n assert cond,\\\n msg + '\\n\\t' + err_msg\n except ValueError:\n raise ValueError, msg\n\n__all__.append('assert_array_almost_equal')\ndef assert_array_almost_equal(x,y,decimal=6,err_msg=''):\n x = asarray(x)\n y = asarray(y)\n msg = '\\nArrays are not almost equal'\n try:\n cond = alltrue(equal(shape(x),shape(y)))\n if not cond:\n msg = msg + ' (shapes mismatch):\\n\\t'\\\n 'Shape of array 1: %s\\n\\tShape of array 2: %s' % (shape(x),shape(y))\n assert cond, msg + '\\n\\t' + err_msg\n reduced = ravel(equal(less_equal(around(abs(x-y),decimal),10.0**(-decimal)),1))\n cond = alltrue(reduced)\n if not cond:\n s1 = array2string(x,precision=decimal+1)\n s2 = array2string(y,precision=decimal+1)\n if len(s1)>120: s1 = s1[:120] + '...'\n if len(s2)>120: s2 = s2[:120] + '...'\n match = 100-100.0*reduced.tolist().count(1)/len(reduced)\n msg = msg + ' (mismatch %s%%):\\n\\tArray 1: %s\\n\\tArray 2: %s' % (match,s1,s2)\n assert cond,\\\n msg + '\\n\\t' + err_msg\n except ValueError:\n print sys.exc_value\n print shape(x),shape(y)\n print x, y\n raise ValueError, 'arrays are not almost equal'\n\n__all__.append('assert_array_less')\ndef assert_array_less(x,y,err_msg=''):\n x,y = asarray(x), asarray(y)\n msg = '\\nArrays are not less-ordered'\n try:\n assert alltrue(equal(shape(x),shape(y))),\\\n msg + ' (shapes mismatch):\\n\\t' + err_msg\n reduced = ravel(less(x,y))\n cond = alltrue(reduced)\n if not cond:\n s1 = array2string(x,precision=16)\n s2 = array2string(y,precision=16)\n if len(s1)>120: s1 = s1[:120] + '...'\n if len(s2)>120: s2 = s2[:120] + '...'\n match = 100-100.0*reduced.tolist().count(1)/len(reduced)\n msg = msg + ' (mismatch %s%%):\\n\\tArray 1: %s\\n\\tArray 2: %s' % (match,s1,s2)\n assert cond,\\\n msg + '\\n\\t' + err_msg\n except ValueError:\n print shape(x),shape(y)\n raise ValueError, 'arrays are not less-ordered'\n\n__all__.append('rand')\ndef rand(*args):\n \"\"\" Returns an array of random numbers with the given shape.\n used for testing\n \"\"\"\n import random\n results = zeros(args,Float64)\n f = results.flat\n for i in range(len(f)):\n f[i] = random.random()\n return results\n\ndef output_exception():\n try:\n type, value, tb = sys.exc_info()\n info = traceback.extract_tb(tb)\n #this is more verbose\n #traceback.print_exc()\n filename, lineno, function, text = info[-1] # last line only\n print \"%s:%d: %s: %s (in %s)\" %\\\n (filename, lineno, type.__name__, str(value), function)\n finally:\n type = value = tb = None # clean up\n\ntry:\n import scipy_base.fastumath as math\nexcept ImportError,msg:\n print msg\n import math\n", "methods": [ { "name": "set_package_path", "long_name": "set_package_path( level = 1 )", "filename": "testing.py", "nloc": 15, "complexity": 4, "token_count": 146, "parameters": [ "level" ], "start_line": 50, "end_line": 81, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 32, "top_nesting_level": 0 }, { "name": "set_local_path", "long_name": "set_local_path( reldir = '' , level = 1 )", "filename": "testing.py", "nloc": 11, "complexity": 3, "token_count": 97, "parameters": [ "reldir", "level" ], "start_line": 84, "end_line": 100, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 17, "top_nesting_level": 0 }, { "name": "restore_path", "long_name": "restore_path( )", "filename": "testing.py", "nloc": 4, "complexity": 2, "token_count": 25, "parameters": [], "start_line": 103, "end_line": 106, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 4, "top_nesting_level": 0 }, { "name": "jiffies", "long_name": "jiffies( _proc_pid_stat = '/proc/%s/stat' % ( os . getpid ( )", "filename": "testing.py", "nloc": 2, "complexity": 1, "token_count": 23, "parameters": [ "_proc_pid_stat" ], "start_line": 110, "end_line": 111, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 2, "top_nesting_level": 1 }, { "name": "memusage", "long_name": "memusage( _proc_pid_stat = '/proc/%s/stat' % ( os . getpid ( )", "filename": "testing.py", "nloc": 10, "complexity": 2, "token_count": 54, "parameters": [ "_proc_pid_stat" ], "start_line": 122, "end_line": 131, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 10, "top_nesting_level": 1 }, { "name": "jiffies", "long_name": "jiffies( _load_time = time . time ( )", "filename": "testing.py", "nloc": 4, "complexity": 1, "token_count": 27, "parameters": [ "_load_time" ], "start_line": 136, "end_line": 139, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 4, "top_nesting_level": 1 }, { "name": "memusage", "long_name": "memusage( )", "filename": "testing.py", "nloc": 2, "complexity": 1, "token_count": 6, "parameters": [], "start_line": 141, "end_line": 143, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 3, "top_nesting_level": 1 }, { "name": "measure", "long_name": "measure( self , code_str , times = 1 )", "filename": "testing.py", "nloc": 13, "complexity": 2, "token_count": 82, "parameters": [ "self", "code_str", "times" ], "start_line": 148, "end_line": 163, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 16, "top_nesting_level": 1 }, { "name": "__call__", "long_name": "__call__( self , result = None )", "filename": "testing.py", "nloc": 24, "complexity": 6, "token_count": 224, "parameters": [ "self", "result" ], "start_line": 165, "end_line": 189, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 25, "top_nesting_level": 1 }, { "name": "__init__", "long_name": "__init__( self , stream )", "filename": "testing.py", "nloc": 3, "complexity": 1, "token_count": 18, "parameters": [ "self", "stream" ], "start_line": 192, "end_line": 194, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 3, "top_nesting_level": 1 }, { "name": "write", "long_name": "write( self , message )", "filename": "testing.py", "nloc": 6, "complexity": 3, "token_count": 47, "parameters": [ "self", "message" ], "start_line": 195, "end_line": 200, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 6, "top_nesting_level": 1 }, { "name": "writeln", "long_name": "writeln( self , message )", "filename": "testing.py", "nloc": 2, "complexity": 1, "token_count": 15, "parameters": [ "self", "message" ], "start_line": 201, "end_line": 202, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 2, "top_nesting_level": 1 }, { "name": "_get_all_method_names", "long_name": "_get_all_method_names( cls )", "filename": "testing.py", "nloc": 8, "complexity": 5, "token_count": 56, "parameters": [ "cls" ], "start_line": 210, "end_line": 217, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 8, "top_nesting_level": 0 }, { "name": "__init__", "long_name": "__init__( self , package = '__main__' )", "filename": "testing.py", "nloc": 2, "complexity": 1, "token_count": 14, "parameters": [ "self", "package" ], "start_line": 241, "end_line": 242, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 2, "top_nesting_level": 1 }, { "name": "_module_str", "long_name": "_module_str( self , module )", "filename": "testing.py", "nloc": 5, "complexity": 2, "token_count": 43, "parameters": [ "self", "module" ], "start_line": 244, "end_line": 248, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 5, "top_nesting_level": 1 }, { "name": "_get_method_names", "long_name": "_get_method_names( self , clsobj , level )", "filename": "testing.py", "nloc": 22, "complexity": 11, "token_count": 142, "parameters": [ "self", "clsobj", "level" ], "start_line": 250, "end_line": 271, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 22, "top_nesting_level": 1 }, { "name": "_get_module_tests", "long_name": "_get_module_tests( self , module , level )", "filename": "testing.py", "nloc": 46, "complexity": 14, "token_count": 428, "parameters": [ "self", "module", "level" ], "start_line": 273, "end_line": 324, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 52, "top_nesting_level": 1 }, { "name": "_get_suite_list", "long_name": "_get_suite_list( self , test_module , level , module_name = '__main__' )", "filename": "testing.py", "nloc": 24, "complexity": 9, "token_count": 168, "parameters": [ "self", "test_module", "level", "module_name" ], "start_line": 326, "end_line": 350, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 25, "top_nesting_level": 1 }, { "name": "_touch_ppimported", "long_name": "_touch_ppimported( self , module )", "filename": "testing.py", "nloc": 11, "complexity": 7, "token_count": 98, "parameters": [ "self", "module" ], "start_line": 352, "end_line": 363, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 12, "top_nesting_level": 1 }, { "name": "test", "long_name": "test( self , level = 1 , verbosity = 1 )", "filename": "testing.py", "nloc": 19, "complexity": 6, "token_count": 166, "parameters": [ "self", "level", "verbosity" ], "start_line": 365, "end_line": 390, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 26, "top_nesting_level": 1 }, { "name": "run", "long_name": "run( self )", "filename": "testing.py", "nloc": 20, "complexity": 2, "token_count": 104, "parameters": [ "self" ], "start_line": 392, "end_line": 414, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 23, "top_nesting_level": 1 }, { "name": "remove_ignored_patterns", "long_name": "remove_ignored_patterns( files , pattern )", "filename": "testing.py", "nloc": 7, "complexity": 3, "token_count": 37, "parameters": [ "files", "pattern" ], "start_line": 418, "end_line": 424, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 7, "top_nesting_level": 0 }, { "name": "remove_ignored_files", "long_name": "remove_ignored_files( original , ignored_files , cur_dir )", "filename": "testing.py", "nloc": 12, "complexity": 3, "token_count": 93, "parameters": [ "original", "ignored_files", "cur_dir" ], "start_line": 426, "end_line": 445, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 20, "top_nesting_level": 0 }, { "name": "harvest_modules", "long_name": "harvest_modules( package , ignore = None )", "filename": "testing.py", "nloc": 21, "complexity": 4, "token_count": 134, "parameters": [ "package", "ignore" ], "start_line": 448, "end_line": 484, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 37, "top_nesting_level": 0 }, { "name": "harvest_packages", "long_name": "harvest_packages( package , ignore = None )", "filename": "testing.py", "nloc": 23, "complexity": 6, "token_count": 148, "parameters": [ "package", "ignore" ], "start_line": 487, "end_line": 521, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 35, "top_nesting_level": 0 }, { "name": "harvest_modules_and_packages", "long_name": "harvest_modules_and_packages( package , ignore = None )", "filename": "testing.py", "nloc": 3, "complexity": 1, "token_count": 27, "parameters": [ "package", "ignore" ], "start_line": 524, "end_line": 530, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 7, "top_nesting_level": 0 }, { "name": "harvest_test_suites", "long_name": "harvest_test_suites( package , ignore = None , level = 10 )", "filename": "testing.py", "nloc": 23, "complexity": 6, "token_count": 113, "parameters": [ "package", "ignore", "level" ], "start_line": 533, "end_line": 568, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 36, "top_nesting_level": 0 }, { "name": "module_test", "long_name": "module_test( mod_name , mod_file , level = 10 )", "filename": "testing.py", "nloc": 10, "complexity": 1, "token_count": 98, "parameters": [ "mod_name", "mod_file", "level" ], "start_line": 571, "end_line": 598, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 28, "top_nesting_level": 0 }, { "name": "module_test_suite", "long_name": "module_test_suite( mod_name , mod_file , level = 10 )", "filename": "testing.py", "nloc": 12, "complexity": 1, "token_count": 103, "parameters": [ "mod_name", "mod_file", "level" ], "start_line": 601, "end_line": 623, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 23, "top_nesting_level": 0 }, { "name": "assert_equal", "long_name": "assert_equal( actual , desired , err_msg = '' , verbose = 1 )", "filename": "testing.py", "nloc": 14, "complexity": 7, "token_count": 116, "parameters": [ "actual", "desired", "err_msg", "verbose" ], "start_line": 633, "end_line": 649, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 17, "top_nesting_level": 0 }, { "name": "assert_almost_equal", "long_name": "assert_almost_equal( actual , desired , decimal = 7 , err_msg = '' , verbose = 1 )", "filename": "testing.py", "nloc": 14, "complexity": 7, "token_count": 132, "parameters": [ "actual", "desired", "decimal", "err_msg", "verbose" ], "start_line": 652, "end_line": 668, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 17, "top_nesting_level": 0 }, { "name": "assert_approx_equal", "long_name": "assert_approx_equal( actual , desired , significant = 7 , err_msg = '' , verbose = 1 )", "filename": "testing.py", "nloc": 23, "complexity": 7, "token_count": 191, "parameters": [ "actual", "desired", "significant", "err_msg", "verbose" ], "start_line": 671, "end_line": 699, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 29, "top_nesting_level": 0 }, { "name": "assert_array_equal", "long_name": "assert_array_equal( x , y , err_msg = '' )", "filename": "testing.py", "nloc": 22, "complexity": 7, "token_count": 232, "parameters": [ "x", "y", "err_msg" ], "start_line": 703, "end_line": 724, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 22, "top_nesting_level": 0 }, { "name": "assert_array_almost_equal", "long_name": "assert_array_almost_equal( x , y , decimal = 6 , err_msg = '' )", "filename": "testing.py", "nloc": 26, "complexity": 6, "token_count": 251, "parameters": [ "x", "y", "decimal", "err_msg" ], "start_line": 727, "end_line": 752, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 26, "top_nesting_level": 0 }, { "name": "assert_array_less", "long_name": "assert_array_less( x , y , err_msg = '' )", "filename": "testing.py", "nloc": 20, "complexity": 5, "token_count": 189, "parameters": [ "x", "y", "err_msg" ], "start_line": 755, "end_line": 774, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 20, "top_nesting_level": 0 }, { "name": "rand", "long_name": "rand( * args )", "filename": "testing.py", "nloc": 7, "complexity": 2, "token_count": 45, "parameters": [ "args" ], "start_line": 777, "end_line": 786, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 10, "top_nesting_level": 0 }, { "name": "output_exception", "long_name": "output_exception( )", "filename": "testing.py", "nloc": 9, "complexity": 2, "token_count": 67, "parameters": [], "start_line": 788, "end_line": 798, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 11, "top_nesting_level": 0 } ], "methods_before": [ { "name": "set_package_path", "long_name": "set_package_path( level = 1 )", "filename": "testing.py", "nloc": 15, "complexity": 4, "token_count": 146, "parameters": [ "level" ], "start_line": 50, "end_line": 81, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 32, "top_nesting_level": 0 }, { "name": "set_local_path", "long_name": "set_local_path( reldir = '' , level = 1 )", "filename": "testing.py", "nloc": 11, "complexity": 3, "token_count": 97, "parameters": [ "reldir", "level" ], "start_line": 84, "end_line": 100, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 17, "top_nesting_level": 0 }, { "name": "restore_path", "long_name": "restore_path( )", "filename": "testing.py", "nloc": 4, "complexity": 2, "token_count": 25, "parameters": [], "start_line": 103, "end_line": 106, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 4, "top_nesting_level": 0 }, { "name": "jiffies", "long_name": "jiffies( _proc_pid_stat = '/proc/%s/stat' % ( os . getpid ( )", "filename": "testing.py", "nloc": 2, "complexity": 1, "token_count": 23, "parameters": [ "_proc_pid_stat" ], "start_line": 110, "end_line": 111, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 2, "top_nesting_level": 1 }, { "name": "memusage", "long_name": "memusage( _proc_pid_stat = '/proc/%s/stat' % ( os . getpid ( )", "filename": "testing.py", "nloc": 10, "complexity": 2, "token_count": 54, "parameters": [ "_proc_pid_stat" ], "start_line": 122, "end_line": 131, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 10, "top_nesting_level": 1 }, { "name": "jiffies", "long_name": "jiffies( _load_time = time . time ( )", "filename": "testing.py", "nloc": 4, "complexity": 1, "token_count": 27, "parameters": [ "_load_time" ], "start_line": 136, "end_line": 139, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 4, "top_nesting_level": 1 }, { "name": "memusage", "long_name": "memusage( )", "filename": "testing.py", "nloc": 2, "complexity": 1, "token_count": 6, "parameters": [], "start_line": 141, "end_line": 143, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 3, "top_nesting_level": 1 }, { "name": "measure", "long_name": "measure( self , code_str , times = 1 )", "filename": "testing.py", "nloc": 13, "complexity": 2, "token_count": 82, "parameters": [ "self", "code_str", "times" ], "start_line": 148, "end_line": 163, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 16, "top_nesting_level": 1 }, { "name": "__call__", "long_name": "__call__( self , result = None )", "filename": "testing.py", "nloc": 24, "complexity": 6, "token_count": 224, "parameters": [ "self", "result" ], "start_line": 165, "end_line": 189, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 25, "top_nesting_level": 1 }, { "name": "__init__", "long_name": "__init__( self , stream )", "filename": "testing.py", "nloc": 3, "complexity": 1, "token_count": 18, "parameters": [ "self", "stream" ], "start_line": 192, "end_line": 194, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 3, "top_nesting_level": 1 }, { "name": "write", "long_name": "write( self , message )", "filename": "testing.py", "nloc": 6, "complexity": 3, "token_count": 47, "parameters": [ "self", "message" ], "start_line": 195, "end_line": 200, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 6, "top_nesting_level": 1 }, { "name": "writeln", "long_name": "writeln( self , message )", "filename": "testing.py", "nloc": 2, "complexity": 1, "token_count": 15, "parameters": [ "self", "message" ], "start_line": 201, "end_line": 202, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 2, "top_nesting_level": 1 }, { "name": "_get_all_method_names", "long_name": "_get_all_method_names( cls )", "filename": "testing.py", "nloc": 8, "complexity": 5, "token_count": 56, "parameters": [ "cls" ], "start_line": 210, "end_line": 217, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 8, "top_nesting_level": 0 }, { "name": "__init__", "long_name": "__init__( self , package = '__main__' )", "filename": "testing.py", "nloc": 2, "complexity": 1, "token_count": 14, "parameters": [ "self", "package" ], "start_line": 241, "end_line": 242, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 2, "top_nesting_level": 1 }, { "name": "_module_str", "long_name": "_module_str( self , module )", "filename": "testing.py", "nloc": 5, "complexity": 2, "token_count": 43, "parameters": [ "self", "module" ], "start_line": 244, "end_line": 248, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 5, "top_nesting_level": 1 }, { "name": "_get_method_names", "long_name": "_get_method_names( self , clsobj , level )", "filename": "testing.py", "nloc": 22, "complexity": 11, "token_count": 142, "parameters": [ "self", "clsobj", "level" ], "start_line": 250, "end_line": 271, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 22, "top_nesting_level": 1 }, { "name": "_get_module_tests", "long_name": "_get_module_tests( self , module , level )", "filename": "testing.py", "nloc": 46, "complexity": 14, "token_count": 428, "parameters": [ "self", "module", "level" ], "start_line": 273, "end_line": 324, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 52, "top_nesting_level": 1 }, { "name": "_get_suite_list", "long_name": "_get_suite_list( self , test_module , level , module_name = '__main__' )", "filename": "testing.py", "nloc": 24, "complexity": 9, "token_count": 168, "parameters": [ "self", "test_module", "level", "module_name" ], "start_line": 326, "end_line": 350, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 25, "top_nesting_level": 1 }, { "name": "_touch_ppimported", "long_name": "_touch_ppimported( self , module )", "filename": "testing.py", "nloc": 11, "complexity": 7, "token_count": 98, "parameters": [ "self", "module" ], "start_line": 352, "end_line": 363, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 12, "top_nesting_level": 1 }, { "name": "test", "long_name": "test( self , level = 1 , verbosity = 1 )", "filename": "testing.py", "nloc": 19, "complexity": 6, "token_count": 166, "parameters": [ "self", "level", "verbosity" ], "start_line": 365, "end_line": 390, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 26, "top_nesting_level": 1 }, { "name": "run", "long_name": "run( self )", "filename": "testing.py", "nloc": 20, "complexity": 2, "token_count": 104, "parameters": [ "self" ], "start_line": 392, "end_line": 414, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 23, "top_nesting_level": 1 }, { "name": "remove_ignored_patterns", "long_name": "remove_ignored_patterns( files , pattern )", "filename": "testing.py", "nloc": 7, "complexity": 3, "token_count": 37, "parameters": [ "files", "pattern" ], "start_line": 418, "end_line": 424, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 7, "top_nesting_level": 0 }, { "name": "remove_ignored_files", "long_name": "remove_ignored_files( original , ignored_files , cur_dir )", "filename": "testing.py", "nloc": 12, "complexity": 3, "token_count": 93, "parameters": [ "original", "ignored_files", "cur_dir" ], "start_line": 426, "end_line": 445, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 20, "top_nesting_level": 0 }, { "name": "harvest_modules", "long_name": "harvest_modules( package , ignore = None )", "filename": "testing.py", "nloc": 21, "complexity": 4, "token_count": 134, "parameters": [ "package", "ignore" ], "start_line": 448, "end_line": 484, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 37, "top_nesting_level": 0 }, { "name": "harvest_packages", "long_name": "harvest_packages( package , ignore = None )", "filename": "testing.py", "nloc": 23, "complexity": 6, "token_count": 148, "parameters": [ "package", "ignore" ], "start_line": 487, "end_line": 521, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 35, "top_nesting_level": 0 }, { "name": "harvest_modules_and_packages", "long_name": "harvest_modules_and_packages( package , ignore = None )", "filename": "testing.py", "nloc": 3, "complexity": 1, "token_count": 27, "parameters": [ "package", "ignore" ], "start_line": 524, "end_line": 530, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 7, "top_nesting_level": 0 }, { "name": "harvest_test_suites", "long_name": "harvest_test_suites( package , ignore = None , level = 10 )", "filename": "testing.py", "nloc": 23, "complexity": 6, "token_count": 113, "parameters": [ "package", "ignore", "level" ], "start_line": 533, "end_line": 568, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 36, "top_nesting_level": 0 }, { "name": "module_test", "long_name": "module_test( mod_name , mod_file , level = 10 )", "filename": "testing.py", "nloc": 10, "complexity": 1, "token_count": 98, "parameters": [ "mod_name", "mod_file", "level" ], "start_line": 571, "end_line": 598, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 28, "top_nesting_level": 0 }, { "name": "module_test_suite", "long_name": "module_test_suite( mod_name , mod_file , level = 10 )", "filename": "testing.py", "nloc": 12, "complexity": 1, "token_count": 103, "parameters": [ "mod_name", "mod_file", "level" ], "start_line": 601, "end_line": 623, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 23, "top_nesting_level": 0 }, { "name": "assert_equal", "long_name": "assert_equal( actual , desired , err_msg = '' , verbose = 1 )", "filename": "testing.py", "nloc": 12, "complexity": 5, "token_count": 92, "parameters": [ "actual", "desired", "err_msg", "verbose" ], "start_line": 633, "end_line": 647, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 15, "top_nesting_level": 0 }, { "name": "assert_almost_equal", "long_name": "assert_almost_equal( actual , desired , decimal = 7 , err_msg = '' , verbose = 1 )", "filename": "testing.py", "nloc": 12, "complexity": 5, "token_count": 106, "parameters": [ "actual", "desired", "decimal", "err_msg", "verbose" ], "start_line": 650, "end_line": 664, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 15, "top_nesting_level": 0 }, { "name": "assert_approx_equal", "long_name": "assert_approx_equal( actual , desired , significant = 7 , err_msg = '' , verbose = 1 )", "filename": "testing.py", "nloc": 23, "complexity": 7, "token_count": 191, "parameters": [ "actual", "desired", "significant", "err_msg", "verbose" ], "start_line": 667, "end_line": 695, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 29, "top_nesting_level": 0 }, { "name": "assert_array_equal", "long_name": "assert_array_equal( x , y , err_msg = '' )", "filename": "testing.py", "nloc": 22, "complexity": 7, "token_count": 232, "parameters": [ "x", "y", "err_msg" ], "start_line": 699, "end_line": 720, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 22, "top_nesting_level": 0 }, { "name": "assert_array_almost_equal", "long_name": "assert_array_almost_equal( x , y , decimal = 6 , err_msg = '' )", "filename": "testing.py", "nloc": 26, "complexity": 6, "token_count": 251, "parameters": [ "x", "y", "decimal", "err_msg" ], "start_line": 723, "end_line": 748, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 26, "top_nesting_level": 0 }, { "name": "assert_array_less", "long_name": "assert_array_less( x , y , err_msg = '' )", "filename": "testing.py", "nloc": 20, "complexity": 5, "token_count": 189, "parameters": [ "x", "y", "err_msg" ], "start_line": 751, "end_line": 770, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 20, "top_nesting_level": 0 }, { "name": "rand", "long_name": "rand( * args )", "filename": "testing.py", "nloc": 7, "complexity": 2, "token_count": 45, "parameters": [ "args" ], "start_line": 773, "end_line": 782, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 10, "top_nesting_level": 0 }, { "name": "output_exception", "long_name": "output_exception( )", "filename": "testing.py", "nloc": 9, "complexity": 2, "token_count": 67, "parameters": [], "start_line": 784, "end_line": 794, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 11, "top_nesting_level": 0 } ], "changed_methods": [ { "name": "assert_equal", "long_name": "assert_equal( actual , desired , err_msg = '' , verbose = 1 )", "filename": "testing.py", "nloc": 14, "complexity": 7, "token_count": 116, "parameters": [ "actual", "desired", "err_msg", "verbose" ], "start_line": 633, "end_line": 649, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 17, "top_nesting_level": 0 }, { "name": "assert_almost_equal", "long_name": "assert_almost_equal( actual , desired , decimal = 7 , err_msg = '' , verbose = 1 )", "filename": "testing.py", "nloc": 14, "complexity": 7, "token_count": 132, "parameters": [ "actual", "desired", "decimal", "err_msg", "verbose" ], "start_line": 652, "end_line": 668, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 17, "top_nesting_level": 0 } ], "nloc": 599, "complexity": 152, "token_count": 4287, "diff_parsed": { "added": [ " less_equal,array2string,less,ArrayType", " if isinstance(actual, ArrayType) or isinstance(desired, ArrayType):", " return assert_array_equal(actual, desired, err_msg)", " if isinstance(actual, ArrayType) or isinstance(desired, ArrayType):", " return assert_array_almost_equal(actual, desired, decimal, err_msg)" ], "deleted": [ " less_equal,array2string,less" ] } } ] }, { "hash": "5d776d8493fd3981f0349df78bccd09a593e3fbf", "msg": "Fixed test failures.", "author": { "name": "Pearu Peterson", "email": "pearu.peterson@gmail.com" }, "committer": { "name": "Pearu Peterson", "email": "pearu.peterson@gmail.com" }, "author_date": "2005-01-05T10:19:40+00:00", "author_timezone": 0, "committer_date": "2005-01-05T10:19:40+00:00", "committer_timezone": 0, "branches": [ "main" ], "in_main_branch": true, "merge": false, "parents": [ "f4dfb7000c7ffa57f5bc8a557d193e8178089b49" ], "project_name": "repo_copy", "project_path": "/tmp/tmpqop781_j/repo_copy", "deletions": 2, "insertions": 2, "lines": 4, "files": 1, "dmm_unit_size": null, "dmm_unit_complexity": null, "dmm_unit_interfacing": null, "modified_files": [ { "old_path": "scipy_base/tests/test_function_base.py", "new_path": "scipy_base/tests/test_function_base.py", "filename": "test_function_base.py", "extension": "py", "change_type": "MODIFY", "diff": "@@ -69,7 +69,7 @@ def check_basic(self):\n b = [[3,6.0, 9.0],\n [4,10.0,5.0],\n [8,3.0,2.0]]\n- assert_equal(amax(b),[8.0,10.0,9.0])\n+ assert_equal(amax(b,axis=0),[8.0,10.0,9.0])\n assert_equal(amax(b,axis=1),[9.0,10.0,8.0])\n \n class test_amin(unittest.TestCase):\n@@ -79,7 +79,7 @@ def check_basic(self):\n b = [[3,6.0, 9.0],\n [4,10.0,5.0],\n [8,3.0,2.0]]\n- assert_equal(amin(b),[3.0,3.0,2.0])\n+ assert_equal(amin(b,axis=0),[3.0,3.0,2.0])\n assert_equal(amin(b,axis=1),[3.0,4.0,2.0])\n \n class test_ptp(unittest.TestCase):\n", "added_lines": 2, "deleted_lines": 2, "source_code": "\nimport unittest\n\nimport sys\nfrom scipy_test.testing import *\nset_package_path()\nimport scipy_base;reload(scipy_base)\nfrom scipy_base import *\ndel sys.path[0]\n\nclass test_any(unittest.TestCase):\n def check_basic(self):\n y1 = [0,0,1,0]\n y2 = [0,0,0,0]\n y3 = [1,0,1,0]\n assert(any(y1))\n assert(any(y3))\n assert(not any(y2))\n\n def check_nd(self):\n y1 = [[0,0,0],[0,1,0],[1,1,0]]\n assert(any(y1))\n assert_array_equal(sometrue(y1),[1,1,0])\n assert_array_equal(sometrue(y1,axis=1),[0,1,1])\n \nclass test_all(unittest.TestCase):\n def check_basic(self):\n y1 = [0,1,1,0]\n y2 = [0,0,0,0]\n y3 = [1,1,1,1]\n assert(not all(y1))\n assert(all(y3))\n assert(not all(y2))\n assert(all(~array(y2)))\n\n def check_nd(self):\n y1 = [[0,0,1],[0,1,1],[1,1,1]]\n assert(not all(y1))\n assert_array_equal(alltrue(y1),[0,0,1])\n assert_array_equal(alltrue(y1,axis=1),[0,0,1])\n\nclass test_logspace(unittest.TestCase):\n def check_basic(self):\n y = logspace(0,6)\n assert(len(y)==50)\n y = logspace(0,6,num=100)\n assert(y[-1] == 10**6)\n y = logspace(0,6,endpoint=0)\n assert(y[-1] < 10**6)\n y = logspace(0,6,num=7)\n assert_array_equal(y,[1,10,100,1e3,1e4,1e5,1e6])\n\nclass test_linspace(unittest.TestCase):\n def check_basic(self):\n y = linspace(0,10)\n assert(len(y)==50)\n y = linspace(2,10,num=100)\n assert(y[-1] == 10)\n y = linspace(2,10,endpoint=0)\n assert(y[-1] < 10)\n y,st = linspace(2,10,retstep=1)\n assert_almost_equal(st,8/49.0)\n assert_array_almost_equal(y,mgrid[2:10:50j],13)\n\nclass test_amax(unittest.TestCase):\n def check_basic(self):\n a = [3,4,5,10,-3,-5,6.0]\n assert_equal(amax(a),10.0)\n b = [[3,6.0, 9.0],\n [4,10.0,5.0],\n [8,3.0,2.0]]\n assert_equal(amax(b,axis=0),[8.0,10.0,9.0])\n assert_equal(amax(b,axis=1),[9.0,10.0,8.0])\n \nclass test_amin(unittest.TestCase):\n def check_basic(self):\n a = [3,4,5,10,-3,-5,6.0]\n assert_equal(amin(a),-5.0)\n b = [[3,6.0, 9.0],\n [4,10.0,5.0],\n [8,3.0,2.0]]\n assert_equal(amin(b,axis=0),[3.0,3.0,2.0])\n assert_equal(amin(b,axis=1),[3.0,4.0,2.0])\n\nclass test_ptp(unittest.TestCase):\n def check_basic(self):\n a = [3,4,5,10,-3,-5,6.0]\n assert_equal(ptp(a),15.0)\n b = [[3,6.0, 9.0],\n [4,10.0,5.0],\n [8,3.0,2.0]]\n assert_equal(ptp(b,axis=0),[5.0,7.0,7.0])\n assert_equal(ptp(b),[6.0,6.0,6.0])\n\nclass test_cumsum(unittest.TestCase):\n def check_basic(self):\n ba = [1,2,10,11,6,5,4]\n ba2 = [[1,2,3,4],[5,6,7,9],[10,3,4,5]]\n for ctype in ['1','b','s','i','l','f','d','F','D']:\n a = array(ba,ctype)\n a2 = array(ba2,ctype)\n assert_array_equal(cumsum(a), array([1,3,13,24,30,35,39],ctype))\n assert_array_equal(cumsum(a2,axis=0), array([[1,2,3,4],[6,8,10,13],\n [16,11,14,18]],ctype))\n assert_array_equal(cumsum(a2,axis=1),\n array([[1,3,6,10],\n [5,11,18,27],\n [10,13,17,22]],ctype))\n\nclass test_prod(unittest.TestCase):\n def check_basic(self):\n ba = [1,2,10,11,6,5,4]\n ba2 = [[1,2,3,4],[5,6,7,9],[10,3,4,5]]\n for ctype in ['1','b','s','i','l','f','d','F','D']:\n a = array(ba,ctype)\n a2 = array(ba2,ctype)\n if ctype in ['1', 'b']:\n self.failUnlessRaises(ArithmeticError, prod, a)\n self.failUnlessRaises(ArithmeticError, prod, a2, 1)\n self.failUnlessRaises(ArithmeticError, prod, a)\n else: \n assert_equal(prod(a),26400)\n assert_array_equal(prod(a2,axis=0), \n array([50,36,84,180],ctype))\n assert_array_equal(prod(a2),array([24, 1890, 600],ctype))\n\nclass test_cumprod(unittest.TestCase):\n def check_basic(self):\n ba = [1,2,10,11,6,5,4]\n ba2 = [[1,2,3,4],[5,6,7,9],[10,3,4,5]]\n for ctype in ['1','b','s','i','l','f','d','F','D']:\n a = array(ba,ctype)\n a2 = array(ba2,ctype)\n if ctype in ['1', 'b']:\n self.failUnlessRaises(ArithmeticError, cumprod, a)\n self.failUnlessRaises(ArithmeticError, cumprod, a2, 1)\n self.failUnlessRaises(ArithmeticError, cumprod, a)\n else: \n assert_array_equal(cumprod(a),\n array([1, 2, 20, 220,\n 1320, 6600, 26400],ctype))\n assert_array_equal(cumprod(a2,axis=0),\n array([[ 1, 2, 3, 4],\n [ 5, 12, 21, 36],\n [50, 36, 84, 180]],ctype))\n assert_array_equal(cumprod(a2),\n array([[ 1, 2, 6, 24],\n [ 5, 30, 210, 1890],\n [10, 30, 120, 600]],ctype))\n\nclass test_diff(unittest.TestCase):\n def check_basic(self):\n x = [1,4,6,7,12]\n out = array([3,2,1,5])\n out2 = array([-1,-1,4])\n out3 = array([0,5])\n assert_array_equal(diff(x),out)\n assert_array_equal(diff(x,n=2),out2)\n assert_array_equal(diff(x,n=3),out3)\n\n def check_nd(self):\n x = 20*rand(10,20,30)\n out1 = x[:,:,1:] - x[:,:,:-1]\n out2 = out1[:,:,1:] - out1[:,:,:-1]\n out3 = x[1:,:,:] - x[:-1,:,:]\n out4 = out3[1:,:,:] - out3[:-1,:,:]\n assert_array_equal(diff(x),out1)\n assert_array_equal(diff(x,n=2),out2)\n assert_array_equal(diff(x,axis=0),out3)\n assert_array_equal(diff(x,n=2,axis=0),out4)\n\nclass test_angle(unittest.TestCase):\n def check_basic(self):\n x = [1+3j,sqrt(2)/2.0+1j*sqrt(2)/2,1,1j,-1,-1j,1-3j,-1+3j]\n y = angle(x)\n yo = [arctan(3.0/1.0),arctan(1.0),0,pi/2,pi,-pi/2.0,\n -arctan(3.0/1.0),pi-arctan(3.0/1.0)]\n z = angle(x,deg=1)\n zo = array(yo)*180/pi\n assert_array_almost_equal(y,yo,11)\n assert_array_almost_equal(z,zo,11)\n\nclass test_trim_zeros(unittest.TestCase):\n \"\"\" only testing for integer splits.\n \"\"\"\n def check_basic(self):\n a= array([0,0,1,2,3,4,0])\n res = trim_zeros(a)\n assert_array_equal(res,array([1,2,3,4]))\n def check_leading_skip(self):\n a= array([0,0,1,0,2,3,4,0])\n res = trim_zeros(a)\n assert_array_equal(res,array([1,0,2,3,4]))\n def check_trailing_skip(self):\n a= array([0,0,1,0,2,3,0,4,0])\n res = trim_zeros(a)\n assert_array_equal(res,array([1,0,2,3,0,4]))\n\n\nclass test_extins(unittest.TestCase):\n def check_basic(self):\n a = array([1,3,2,1,2,3,3])\n b = extract(a>1,a)\n assert_array_equal(b,[3,2,2,3,3])\n def check_insert(self):\n a = array([1,4,3,2,5,8,7])\n insert(a,[0,1,0,1,0,1,0],[2,4,6])\n assert_array_equal(a,[1,2,3,4,5,6,7])\n def check_both(self):\n a = rand(10)\n mask = a > 0.5\n ac = a.copy()\n c = extract(mask, a)\n insert(a,mask,0)\n insert(a,mask,c)\n assert_array_equal(a,ac)\n \nclass test_vectorize(unittest.TestCase):\n def check_simple(self):\n def addsubtract(a,b):\n if a > b:\n return a - b\n else:\n return a + b\n f = vectorize(addsubtract)\n r = f([0,3,6,9],[1,3,5,7])\n assert_array_equal(r,[1,6,1,2])\n def check_scalar(self):\n def addsubtract(a,b):\n if a > b:\n return a - b\n else:\n return a + b\n f = vectorize(addsubtract)\n r = f([0,3,6,9],5)\n assert_array_equal(r,[5,8,1,4])\n \n\ndef compare_results(res,desired):\n for i in range(len(desired)):\n assert_array_equal(res[i],desired[i])\n\nif __name__ == \"__main__\":\n ScipyTest('scipy_base.function_base').run()\n", "source_code_before": "\nimport unittest\n\nimport sys\nfrom scipy_test.testing import *\nset_package_path()\nimport scipy_base;reload(scipy_base)\nfrom scipy_base import *\ndel sys.path[0]\n\nclass test_any(unittest.TestCase):\n def check_basic(self):\n y1 = [0,0,1,0]\n y2 = [0,0,0,0]\n y3 = [1,0,1,0]\n assert(any(y1))\n assert(any(y3))\n assert(not any(y2))\n\n def check_nd(self):\n y1 = [[0,0,0],[0,1,0],[1,1,0]]\n assert(any(y1))\n assert_array_equal(sometrue(y1),[1,1,0])\n assert_array_equal(sometrue(y1,axis=1),[0,1,1])\n \nclass test_all(unittest.TestCase):\n def check_basic(self):\n y1 = [0,1,1,0]\n y2 = [0,0,0,0]\n y3 = [1,1,1,1]\n assert(not all(y1))\n assert(all(y3))\n assert(not all(y2))\n assert(all(~array(y2)))\n\n def check_nd(self):\n y1 = [[0,0,1],[0,1,1],[1,1,1]]\n assert(not all(y1))\n assert_array_equal(alltrue(y1),[0,0,1])\n assert_array_equal(alltrue(y1,axis=1),[0,0,1])\n\nclass test_logspace(unittest.TestCase):\n def check_basic(self):\n y = logspace(0,6)\n assert(len(y)==50)\n y = logspace(0,6,num=100)\n assert(y[-1] == 10**6)\n y = logspace(0,6,endpoint=0)\n assert(y[-1] < 10**6)\n y = logspace(0,6,num=7)\n assert_array_equal(y,[1,10,100,1e3,1e4,1e5,1e6])\n\nclass test_linspace(unittest.TestCase):\n def check_basic(self):\n y = linspace(0,10)\n assert(len(y)==50)\n y = linspace(2,10,num=100)\n assert(y[-1] == 10)\n y = linspace(2,10,endpoint=0)\n assert(y[-1] < 10)\n y,st = linspace(2,10,retstep=1)\n assert_almost_equal(st,8/49.0)\n assert_array_almost_equal(y,mgrid[2:10:50j],13)\n\nclass test_amax(unittest.TestCase):\n def check_basic(self):\n a = [3,4,5,10,-3,-5,6.0]\n assert_equal(amax(a),10.0)\n b = [[3,6.0, 9.0],\n [4,10.0,5.0],\n [8,3.0,2.0]]\n assert_equal(amax(b),[8.0,10.0,9.0])\n assert_equal(amax(b,axis=1),[9.0,10.0,8.0])\n \nclass test_amin(unittest.TestCase):\n def check_basic(self):\n a = [3,4,5,10,-3,-5,6.0]\n assert_equal(amin(a),-5.0)\n b = [[3,6.0, 9.0],\n [4,10.0,5.0],\n [8,3.0,2.0]]\n assert_equal(amin(b),[3.0,3.0,2.0])\n assert_equal(amin(b,axis=1),[3.0,4.0,2.0])\n\nclass test_ptp(unittest.TestCase):\n def check_basic(self):\n a = [3,4,5,10,-3,-5,6.0]\n assert_equal(ptp(a),15.0)\n b = [[3,6.0, 9.0],\n [4,10.0,5.0],\n [8,3.0,2.0]]\n assert_equal(ptp(b,axis=0),[5.0,7.0,7.0])\n assert_equal(ptp(b),[6.0,6.0,6.0])\n\nclass test_cumsum(unittest.TestCase):\n def check_basic(self):\n ba = [1,2,10,11,6,5,4]\n ba2 = [[1,2,3,4],[5,6,7,9],[10,3,4,5]]\n for ctype in ['1','b','s','i','l','f','d','F','D']:\n a = array(ba,ctype)\n a2 = array(ba2,ctype)\n assert_array_equal(cumsum(a), array([1,3,13,24,30,35,39],ctype))\n assert_array_equal(cumsum(a2,axis=0), array([[1,2,3,4],[6,8,10,13],\n [16,11,14,18]],ctype))\n assert_array_equal(cumsum(a2,axis=1),\n array([[1,3,6,10],\n [5,11,18,27],\n [10,13,17,22]],ctype))\n\nclass test_prod(unittest.TestCase):\n def check_basic(self):\n ba = [1,2,10,11,6,5,4]\n ba2 = [[1,2,3,4],[5,6,7,9],[10,3,4,5]]\n for ctype in ['1','b','s','i','l','f','d','F','D']:\n a = array(ba,ctype)\n a2 = array(ba2,ctype)\n if ctype in ['1', 'b']:\n self.failUnlessRaises(ArithmeticError, prod, a)\n self.failUnlessRaises(ArithmeticError, prod, a2, 1)\n self.failUnlessRaises(ArithmeticError, prod, a)\n else: \n assert_equal(prod(a),26400)\n assert_array_equal(prod(a2,axis=0), \n array([50,36,84,180],ctype))\n assert_array_equal(prod(a2),array([24, 1890, 600],ctype))\n\nclass test_cumprod(unittest.TestCase):\n def check_basic(self):\n ba = [1,2,10,11,6,5,4]\n ba2 = [[1,2,3,4],[5,6,7,9],[10,3,4,5]]\n for ctype in ['1','b','s','i','l','f','d','F','D']:\n a = array(ba,ctype)\n a2 = array(ba2,ctype)\n if ctype in ['1', 'b']:\n self.failUnlessRaises(ArithmeticError, cumprod, a)\n self.failUnlessRaises(ArithmeticError, cumprod, a2, 1)\n self.failUnlessRaises(ArithmeticError, cumprod, a)\n else: \n assert_array_equal(cumprod(a),\n array([1, 2, 20, 220,\n 1320, 6600, 26400],ctype))\n assert_array_equal(cumprod(a2,axis=0),\n array([[ 1, 2, 3, 4],\n [ 5, 12, 21, 36],\n [50, 36, 84, 180]],ctype))\n assert_array_equal(cumprod(a2),\n array([[ 1, 2, 6, 24],\n [ 5, 30, 210, 1890],\n [10, 30, 120, 600]],ctype))\n\nclass test_diff(unittest.TestCase):\n def check_basic(self):\n x = [1,4,6,7,12]\n out = array([3,2,1,5])\n out2 = array([-1,-1,4])\n out3 = array([0,5])\n assert_array_equal(diff(x),out)\n assert_array_equal(diff(x,n=2),out2)\n assert_array_equal(diff(x,n=3),out3)\n\n def check_nd(self):\n x = 20*rand(10,20,30)\n out1 = x[:,:,1:] - x[:,:,:-1]\n out2 = out1[:,:,1:] - out1[:,:,:-1]\n out3 = x[1:,:,:] - x[:-1,:,:]\n out4 = out3[1:,:,:] - out3[:-1,:,:]\n assert_array_equal(diff(x),out1)\n assert_array_equal(diff(x,n=2),out2)\n assert_array_equal(diff(x,axis=0),out3)\n assert_array_equal(diff(x,n=2,axis=0),out4)\n\nclass test_angle(unittest.TestCase):\n def check_basic(self):\n x = [1+3j,sqrt(2)/2.0+1j*sqrt(2)/2,1,1j,-1,-1j,1-3j,-1+3j]\n y = angle(x)\n yo = [arctan(3.0/1.0),arctan(1.0),0,pi/2,pi,-pi/2.0,\n -arctan(3.0/1.0),pi-arctan(3.0/1.0)]\n z = angle(x,deg=1)\n zo = array(yo)*180/pi\n assert_array_almost_equal(y,yo,11)\n assert_array_almost_equal(z,zo,11)\n\nclass test_trim_zeros(unittest.TestCase):\n \"\"\" only testing for integer splits.\n \"\"\"\n def check_basic(self):\n a= array([0,0,1,2,3,4,0])\n res = trim_zeros(a)\n assert_array_equal(res,array([1,2,3,4]))\n def check_leading_skip(self):\n a= array([0,0,1,0,2,3,4,0])\n res = trim_zeros(a)\n assert_array_equal(res,array([1,0,2,3,4]))\n def check_trailing_skip(self):\n a= array([0,0,1,0,2,3,0,4,0])\n res = trim_zeros(a)\n assert_array_equal(res,array([1,0,2,3,0,4]))\n\n\nclass test_extins(unittest.TestCase):\n def check_basic(self):\n a = array([1,3,2,1,2,3,3])\n b = extract(a>1,a)\n assert_array_equal(b,[3,2,2,3,3])\n def check_insert(self):\n a = array([1,4,3,2,5,8,7])\n insert(a,[0,1,0,1,0,1,0],[2,4,6])\n assert_array_equal(a,[1,2,3,4,5,6,7])\n def check_both(self):\n a = rand(10)\n mask = a > 0.5\n ac = a.copy()\n c = extract(mask, a)\n insert(a,mask,0)\n insert(a,mask,c)\n assert_array_equal(a,ac)\n \nclass test_vectorize(unittest.TestCase):\n def check_simple(self):\n def addsubtract(a,b):\n if a > b:\n return a - b\n else:\n return a + b\n f = vectorize(addsubtract)\n r = f([0,3,6,9],[1,3,5,7])\n assert_array_equal(r,[1,6,1,2])\n def check_scalar(self):\n def addsubtract(a,b):\n if a > b:\n return a - b\n else:\n return a + b\n f = vectorize(addsubtract)\n r = f([0,3,6,9],5)\n assert_array_equal(r,[5,8,1,4])\n \n\ndef compare_results(res,desired):\n for i in range(len(desired)):\n assert_array_equal(res[i],desired[i])\n\nif __name__ == \"__main__\":\n ScipyTest('scipy_base.function_base').run()\n", "methods": [ { "name": "check_basic", "long_name": "check_basic( self )", "filename": "test_function_base.py", "nloc": 7, "complexity": 1, "token_count": 60, "parameters": [ "self" ], "start_line": 12, "end_line": 18, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 7, "top_nesting_level": 1 }, { "name": "check_nd", "long_name": "check_nd( self )", "filename": "test_function_base.py", "nloc": 5, "complexity": 1, "token_count": 73, "parameters": [ "self" ], "start_line": 20, "end_line": 24, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 5, "top_nesting_level": 1 }, { "name": "check_basic", "long_name": "check_basic( self )", "filename": "test_function_base.py", "nloc": 8, "complexity": 1, "token_count": 72, "parameters": [ "self" ], "start_line": 27, "end_line": 34, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 8, "top_nesting_level": 1 }, { "name": "check_nd", "long_name": "check_nd( self )", "filename": "test_function_base.py", "nloc": 5, "complexity": 1, "token_count": 74, "parameters": [ "self" ], "start_line": 36, "end_line": 40, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 5, "top_nesting_level": 1 }, { "name": "check_basic", "long_name": "check_basic( self )", "filename": "test_function_base.py", "nloc": 9, "complexity": 1, "token_count": 102, "parameters": [ "self" ], "start_line": 43, "end_line": 51, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 9, "top_nesting_level": 1 }, { "name": "check_basic", "long_name": "check_basic( self )", "filename": "test_function_base.py", "nloc": 10, "complexity": 1, "token_count": 105, "parameters": [ "self" ], "start_line": 54, "end_line": 63, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 10, "top_nesting_level": 1 }, { "name": "check_basic", "long_name": "check_basic( self )", "filename": "test_function_base.py", "nloc": 8, "complexity": 1, "token_count": 126, "parameters": [ "self" ], "start_line": 66, "end_line": 73, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 8, "top_nesting_level": 1 }, { "name": "check_basic", "long_name": "check_basic( self )", "filename": "test_function_base.py", "nloc": 8, "complexity": 1, "token_count": 127, "parameters": [ "self" ], "start_line": 76, "end_line": 83, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 8, "top_nesting_level": 1 }, { "name": "check_basic", "long_name": "check_basic( self )", "filename": "test_function_base.py", "nloc": 8, "complexity": 1, "token_count": 122, "parameters": [ "self" ], "start_line": 86, "end_line": 93, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 8, "top_nesting_level": 1 }, { "name": "check_basic", "long_name": "check_basic( self )", "filename": "test_function_base.py", "nloc": 13, "complexity": 2, "token_count": 218, "parameters": [ "self" ], "start_line": 96, "end_line": 108, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 13, "top_nesting_level": 1 }, { "name": "check_basic", "long_name": "check_basic( self )", "filename": "test_function_base.py", "nloc": 15, "complexity": 3, "token_count": 192, "parameters": [ "self" ], "start_line": 111, "end_line": 125, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 15, "top_nesting_level": 1 }, { "name": "check_basic", "long_name": "check_basic( self )", "filename": "test_function_base.py", "nloc": 22, "complexity": 3, "token_count": 257, "parameters": [ "self" ], "start_line": 128, "end_line": 149, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 22, "top_nesting_level": 1 }, { "name": "check_basic", "long_name": "check_basic( self )", "filename": "test_function_base.py", "nloc": 8, "complexity": 1, "token_count": 91, "parameters": [ "self" ], "start_line": 152, "end_line": 159, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 8, "top_nesting_level": 1 }, { "name": "check_nd", "long_name": "check_nd( self )", "filename": "test_function_base.py", "nloc": 10, "complexity": 1, "token_count": 157, "parameters": [ "self" ], "start_line": 161, "end_line": 170, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 10, "top_nesting_level": 1 }, { "name": "check_basic", "long_name": "check_basic( self )", "filename": "test_function_base.py", "nloc": 9, "complexity": 1, "token_count": 152, "parameters": [ "self" ], "start_line": 173, "end_line": 181, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 9, "top_nesting_level": 1 }, { "name": "check_basic", "long_name": "check_basic( self )", "filename": "test_function_base.py", "nloc": 4, "complexity": 1, "token_count": 48, "parameters": [ "self" ], "start_line": 186, "end_line": 189, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 4, "top_nesting_level": 1 }, { "name": "check_leading_skip", "long_name": "check_leading_skip( self )", "filename": "test_function_base.py", "nloc": 4, "complexity": 1, "token_count": 52, "parameters": [ "self" ], "start_line": 190, "end_line": 193, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 4, "top_nesting_level": 1 }, { "name": "check_trailing_skip", "long_name": "check_trailing_skip( self )", "filename": "test_function_base.py", "nloc": 4, "complexity": 1, "token_count": 56, "parameters": [ "self" ], "start_line": 194, "end_line": 197, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 4, "top_nesting_level": 1 }, { "name": "check_basic", "long_name": "check_basic( self )", "filename": "test_function_base.py", "nloc": 4, "complexity": 1, "token_count": 51, "parameters": [ "self" ], "start_line": 201, "end_line": 204, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 4, "top_nesting_level": 1 }, { "name": "check_insert", "long_name": "check_insert( self )", "filename": "test_function_base.py", "nloc": 4, "complexity": 1, "token_count": 73, "parameters": [ "self" ], "start_line": 205, "end_line": 208, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 4, "top_nesting_level": 1 }, { "name": "check_both", "long_name": "check_both( self )", "filename": "test_function_base.py", "nloc": 8, "complexity": 1, "token_count": 55, "parameters": [ "self" ], "start_line": 209, "end_line": 216, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 8, "top_nesting_level": 1 }, { "name": "check_simple.addsubtract", "long_name": "check_simple.addsubtract( a , b )", "filename": "test_function_base.py", "nloc": 5, "complexity": 2, "token_count": 22, "parameters": [ "a", "b" ], "start_line": 220, "end_line": 224, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 5, "top_nesting_level": 2 }, { "name": "check_simple", "long_name": "check_simple( self )", "filename": "test_function_base.py", "nloc": 5, "complexity": 1, "token_count": 51, "parameters": [ "self" ], "start_line": 219, "end_line": 227, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 9, "top_nesting_level": 1 }, { "name": "check_scalar.addsubtract", "long_name": "check_scalar.addsubtract( a , b )", "filename": "test_function_base.py", "nloc": 5, "complexity": 2, "token_count": 22, "parameters": [ "a", "b" ], "start_line": 229, "end_line": 233, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 5, "top_nesting_level": 2 }, { "name": "check_scalar", "long_name": "check_scalar( self )", "filename": "test_function_base.py", "nloc": 5, "complexity": 1, "token_count": 43, "parameters": [ "self" ], "start_line": 228, "end_line": 236, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 9, "top_nesting_level": 1 }, { "name": "compare_results", "long_name": "compare_results( res , desired )", "filename": "test_function_base.py", "nloc": 3, "complexity": 2, "token_count": 30, "parameters": [ "res", "desired" ], "start_line": 239, "end_line": 241, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 3, "top_nesting_level": 0 } ], "methods_before": [ { "name": "check_basic", "long_name": "check_basic( self )", "filename": "test_function_base.py", "nloc": 7, "complexity": 1, "token_count": 60, "parameters": [ "self" ], "start_line": 12, "end_line": 18, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 7, "top_nesting_level": 1 }, { "name": "check_nd", "long_name": "check_nd( self )", "filename": "test_function_base.py", "nloc": 5, "complexity": 1, "token_count": 73, "parameters": [ "self" ], "start_line": 20, "end_line": 24, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 5, "top_nesting_level": 1 }, { "name": "check_basic", "long_name": "check_basic( self )", "filename": "test_function_base.py", "nloc": 8, "complexity": 1, "token_count": 72, "parameters": [ "self" ], "start_line": 27, "end_line": 34, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 8, "top_nesting_level": 1 }, { "name": "check_nd", "long_name": "check_nd( self )", "filename": "test_function_base.py", "nloc": 5, "complexity": 1, "token_count": 74, "parameters": [ "self" ], "start_line": 36, "end_line": 40, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 5, "top_nesting_level": 1 }, { "name": "check_basic", "long_name": "check_basic( self )", "filename": "test_function_base.py", "nloc": 9, "complexity": 1, "token_count": 102, "parameters": [ "self" ], "start_line": 43, "end_line": 51, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 9, "top_nesting_level": 1 }, { "name": "check_basic", "long_name": "check_basic( self )", "filename": "test_function_base.py", "nloc": 10, "complexity": 1, "token_count": 105, "parameters": [ "self" ], "start_line": 54, "end_line": 63, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 10, "top_nesting_level": 1 }, { "name": "check_basic", "long_name": "check_basic( self )", "filename": "test_function_base.py", "nloc": 8, "complexity": 1, "token_count": 122, "parameters": [ "self" ], "start_line": 66, "end_line": 73, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 8, "top_nesting_level": 1 }, { "name": "check_basic", "long_name": "check_basic( self )", "filename": "test_function_base.py", "nloc": 8, "complexity": 1, "token_count": 123, "parameters": [ "self" ], "start_line": 76, "end_line": 83, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 8, "top_nesting_level": 1 }, { "name": "check_basic", "long_name": "check_basic( self )", "filename": "test_function_base.py", "nloc": 8, "complexity": 1, "token_count": 122, "parameters": [ "self" ], "start_line": 86, "end_line": 93, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 8, "top_nesting_level": 1 }, { "name": "check_basic", "long_name": "check_basic( self )", "filename": "test_function_base.py", "nloc": 13, "complexity": 2, "token_count": 218, "parameters": [ "self" ], "start_line": 96, "end_line": 108, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 13, "top_nesting_level": 1 }, { "name": "check_basic", "long_name": "check_basic( self )", "filename": "test_function_base.py", "nloc": 15, "complexity": 3, "token_count": 192, "parameters": [ "self" ], "start_line": 111, "end_line": 125, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 15, "top_nesting_level": 1 }, { "name": "check_basic", "long_name": "check_basic( self )", "filename": "test_function_base.py", "nloc": 22, "complexity": 3, "token_count": 257, "parameters": [ "self" ], "start_line": 128, "end_line": 149, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 22, "top_nesting_level": 1 }, { "name": "check_basic", "long_name": "check_basic( self )", "filename": "test_function_base.py", "nloc": 8, "complexity": 1, "token_count": 91, "parameters": [ "self" ], "start_line": 152, "end_line": 159, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 8, "top_nesting_level": 1 }, { "name": "check_nd", "long_name": "check_nd( self )", "filename": "test_function_base.py", "nloc": 10, "complexity": 1, "token_count": 157, "parameters": [ "self" ], "start_line": 161, "end_line": 170, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 10, "top_nesting_level": 1 }, { "name": "check_basic", "long_name": "check_basic( self )", "filename": "test_function_base.py", "nloc": 9, "complexity": 1, "token_count": 152, "parameters": [ "self" ], "start_line": 173, "end_line": 181, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 9, "top_nesting_level": 1 }, { "name": "check_basic", "long_name": "check_basic( self )", "filename": "test_function_base.py", "nloc": 4, "complexity": 1, "token_count": 48, "parameters": [ "self" ], "start_line": 186, "end_line": 189, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 4, "top_nesting_level": 1 }, { "name": "check_leading_skip", "long_name": "check_leading_skip( self )", "filename": "test_function_base.py", "nloc": 4, "complexity": 1, "token_count": 52, "parameters": [ "self" ], "start_line": 190, "end_line": 193, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 4, "top_nesting_level": 1 }, { "name": "check_trailing_skip", "long_name": "check_trailing_skip( self )", "filename": "test_function_base.py", "nloc": 4, "complexity": 1, "token_count": 56, "parameters": [ "self" ], "start_line": 194, "end_line": 197, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 4, "top_nesting_level": 1 }, { "name": "check_basic", "long_name": "check_basic( self )", "filename": "test_function_base.py", "nloc": 4, "complexity": 1, "token_count": 51, "parameters": [ "self" ], "start_line": 201, "end_line": 204, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 4, "top_nesting_level": 1 }, { "name": "check_insert", "long_name": "check_insert( self )", "filename": "test_function_base.py", "nloc": 4, "complexity": 1, "token_count": 73, "parameters": [ "self" ], "start_line": 205, "end_line": 208, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 4, "top_nesting_level": 1 }, { "name": "check_both", "long_name": "check_both( self )", "filename": "test_function_base.py", "nloc": 8, "complexity": 1, "token_count": 55, "parameters": [ "self" ], "start_line": 209, "end_line": 216, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 8, "top_nesting_level": 1 }, { "name": "check_simple.addsubtract", "long_name": "check_simple.addsubtract( a , b )", "filename": "test_function_base.py", "nloc": 5, "complexity": 2, "token_count": 22, "parameters": [ "a", "b" ], "start_line": 220, "end_line": 224, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 5, "top_nesting_level": 2 }, { "name": "check_simple", "long_name": "check_simple( self )", "filename": "test_function_base.py", "nloc": 5, "complexity": 1, "token_count": 51, "parameters": [ "self" ], "start_line": 219, "end_line": 227, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 9, "top_nesting_level": 1 }, { "name": "check_scalar.addsubtract", "long_name": "check_scalar.addsubtract( a , b )", "filename": "test_function_base.py", "nloc": 5, "complexity": 2, "token_count": 22, "parameters": [ "a", "b" ], "start_line": 229, "end_line": 233, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 5, "top_nesting_level": 2 }, { "name": "check_scalar", "long_name": "check_scalar( self )", "filename": "test_function_base.py", "nloc": 5, "complexity": 1, "token_count": 43, "parameters": [ "self" ], "start_line": 228, "end_line": 236, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 9, "top_nesting_level": 1 }, { "name": "compare_results", "long_name": "compare_results( res , desired )", "filename": "test_function_base.py", "nloc": 3, "complexity": 2, "token_count": 30, "parameters": [ "res", "desired" ], "start_line": 239, "end_line": 241, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 3, "top_nesting_level": 0 } ], "changed_methods": [ { "name": "check_basic", "long_name": "check_basic( self )", "filename": "test_function_base.py", "nloc": 8, "complexity": 1, "token_count": 126, "parameters": [ "self" ], "start_line": 66, "end_line": 73, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 8, "top_nesting_level": 1 } ], "nloc": 220, "complexity": 34, "token_count": 2618, "diff_parsed": { "added": [ " assert_equal(amax(b,axis=0),[8.0,10.0,9.0])", " assert_equal(amin(b,axis=0),[3.0,3.0,2.0])" ], "deleted": [ " assert_equal(amax(b),[8.0,10.0,9.0])", " assert_equal(amin(b),[3.0,3.0,2.0])" ] } } ] }, { "hash": "54e300d091cdb40e194855b258d5721920df7191", "msg": "Switch to -O2 for gcc <= 3.3.3 rather than gcc == 3.3.3.", "author": { "name": "jmiller", "email": "jmiller@localhost" }, "committer": { "name": "jmiller", "email": "jmiller@localhost" }, "author_date": "2005-01-07T20:42:22+00:00", "author_timezone": 0, "committer_date": "2005-01-07T20:42:22+00:00", "committer_timezone": 0, "branches": [ "main" ], "in_main_branch": true, "merge": false, "parents": [ "246665b81b2954a63c0400f870d85aeac111117e" ], "project_name": "repo_copy", "project_path": "/tmp/tmpqop781_j/repo_copy", "deletions": 1, "insertions": 1, "lines": 2, "files": 1, "dmm_unit_size": null, "dmm_unit_complexity": null, "dmm_unit_interfacing": null, "modified_files": [ { "old_path": "scipy_distutils/gnufcompiler.py", "new_path": "scipy_distutils/gnufcompiler.py", "filename": "gnufcompiler.py", "extension": "py", "change_type": "MODIFY", "diff": "@@ -102,7 +102,7 @@ def get_flags_debug(self):\n return ['-g']\n \n def get_flags_opt(self):\n- if self.get_version()=='3.3.3':\n+ if self.get_version()<='3.3.3':\n # With this compiler version building Fortran BLAS/LAPACK\n # with -O3 caused failures in lib.lapack heevr,syevr tests.\n opt = ['-O2']\n", "added_lines": 1, "deleted_lines": 1, "source_code": "\nimport re\nimport os\nimport sys\n\nfrom cpuinfo import cpu\nfrom fcompiler import FCompiler\nfrom exec_command import exec_command, find_executable\n\nclass GnuFCompiler(FCompiler):\n\n compiler_type = 'gnu'\n version_pattern = r'GNU Fortran ((\\(GCC[^\\)]*(\\)\\)|\\)))|)\\s*'\\\n '(?P[^\\s*\\)]+)'\n\n # 'g77 --version' results\n # SunOS: GNU Fortran (GCC 3.2) 3.2 20020814 (release)\n # Debian: GNU Fortran (GCC) 3.3.3 20040110 (prerelease) (Debian)\n # GNU Fortran (GCC) 3.3.3 (Debian 20040401)\n # GNU Fortran 0.5.25 20010319 (prerelease)\n # Redhat: GNU Fortran (GCC 3.2.2 20030222 (Red Hat Linux 3.2.2-5)) 3.2.2 20030222 (Red Hat Linux 3.2.2-5)\n\n for fc_exe in map(find_executable,['g77','f77']):\n if os.path.isfile(fc_exe):\n break\n executables = {\n 'version_cmd' : [fc_exe,\"--version\"],\n 'compiler_f77' : [fc_exe,\"-Wall\",\"-fno-second-underscore\"],\n 'compiler_f90' : None,\n 'compiler_fix' : None,\n 'linker_so' : [fc_exe],\n 'archiver' : [\"ar\", \"-cr\"],\n 'ranlib' : [\"ranlib\"],\n }\n module_dir_switch = None\n module_include_switch = None\n\n # Cygwin: f771: warning: -fPIC ignored for target (all code is position independent)\n if os.name != 'nt' and sys.platform!='cygwin':\n pic_flags = ['-fPIC']\n\n #def get_linker_so(self):\n # # win32 linking should be handled by standard linker\n # # Darwin g77 cannot be used as a linker.\n # #if re.match(r'(darwin)', sys.platform):\n # # return\n # return FCompiler.get_linker_so(self)\n\n def get_flags_linker_so(self):\n opt = []\n if sys.platform=='darwin':\n if os.path.realpath(sys.executable).startswith('/System'):\n # This is when Python is from Apple framework\n opt.extend([\"-Wl,-framework\",\"-Wl,Python\"])\n #else we are running in Fink python.\n opt.extend([\"-lcc_dynamic\",\"-bundle\"])\n else:\n opt.append(\"-shared\")\n if sys.platform[:5]=='sunos':\n # SunOS often has dynamically loaded symbols defined in the\n # static library libg2c.a The linker doesn't like this. To\n # ignore the problem, use the -mimpure-text flag. It isn't\n # the safest thing, but seems to work. 'man gcc' says:\n # \".. Instead of using -mimpure-text, you should compile all\n # source code with -fpic or -fPIC.\"\n opt.append('-mimpure-text')\n return opt\n\n def get_libgcc_dir(self):\n status, output = exec_command('%s -print-libgcc-file-name' \\\n % (self.compiler_f77[0]),use_tee=0) \n if not status:\n return os.path.dirname(output)\n return\n\n def get_library_dirs(self):\n opt = []\n if sys.platform[:5] != 'linux':\n d = self.get_libgcc_dir()\n if d:\n opt.append(d)\n return opt\n\n def get_libraries(self):\n opt = []\n d = self.get_libgcc_dir()\n if d is not None:\n g2c = 'g2c-pic'\n f = self.static_lib_format % (g2c, self.static_lib_extension)\n if not os.path.isfile(os.path.join(d,f)):\n g2c = 'g2c'\n else:\n g2c = 'g2c'\n \n if sys.platform=='win32':\n opt.append('gcc')\n if g2c is not None:\n opt.append(g2c)\n return opt\n\n def get_flags_debug(self):\n return ['-g']\n\n def get_flags_opt(self):\n if self.get_version()<='3.3.3':\n # With this compiler version building Fortran BLAS/LAPACK\n # with -O3 caused failures in lib.lapack heevr,syevr tests.\n opt = ['-O2']\n else:\n opt = ['-O3']\n opt.append('-funroll-loops')\n return opt\n\n def get_flags_arch(self):\n opt = []\n if sys.platform=='darwin':\n if os.name != 'posix':\n # this should presumably correspond to Apple\n if cpu.is_ppc():\n opt.append('-arch ppc')\n elif cpu.is_i386():\n opt.append('-arch i386')\n for a in '601 602 603 603e 604 604e 620 630 740 7400 7450 750'\\\n '403 505 801 821 823 860'.split():\n if getattr(cpu,'is_ppc%s'%a)():\n opt.append('-mcpu='+a)\n opt.append('-mtune='+a)\n break \n return opt\n march_flag = 1\n # 0.5.25 corresponds to 2.95.x\n if self.get_version() == '0.5.26': # gcc 3.0\n if cpu.is_AthlonK6():\n opt.append('-march=k6')\n elif cpu.is_AthlonK7():\n opt.append('-march=athlon')\n else:\n march_flag = 0\n # Note: gcc 3.2 on win32 has breakage with -march specified\n elif self.get_version() >= '3.1.1' \\\n and not sys.platform=='win32': # gcc >= 3.1.1\n if cpu.is_AthlonK6():\n opt.append('-march=k6')\n elif cpu.is_AthlonK6_2():\n opt.append('-march=k6-2')\n elif cpu.is_AthlonK6_3():\n opt.append('-march=k6-3')\n elif cpu.is_AthlonK7():\n opt.append('-march=athlon')\n elif cpu.is_AthlonMP():\n opt.append('-march=athlon-mp')\n # there's also: athlon-tbird, athlon-4, athlon-xp\n elif cpu.is_PentiumIV():\n opt.append('-march=pentium4')\n elif cpu.is_PentiumIII():\n opt.append('-march=pentium3')\n elif cpu.is_PentiumII():\n opt.append('-march=pentium2')\n else:\n march_flag = 0\n if self.get_version() >= '3.4' and not march_flag:\n march_flag = 1\n if cpu.is_Opteron():\n opt.append('-march=opteron')\n elif cpu.is_Athlon64():\n opt.append('-march=athlon64')\n else:\n march_flag = 0\n if cpu.has_mmx(): opt.append('-mmmx') \n if self.get_version() > '3.2.2':\n if cpu.has_sse2(): opt.append('-msse2')\n if cpu.has_sse(): opt.append('-msse')\n if self.get_version() >= '3.4':\n if cpu.has_sse3(): opt.append('-msse3')\n if cpu.has_3dnow(): opt.append('-m3dnow')\n else:\n march_flag = 0\n if march_flag:\n pass\n elif cpu.is_i686():\n opt.append('-march=i686')\n elif cpu.is_i586():\n opt.append('-march=i586')\n elif cpu.is_i486():\n opt.append('-march=i486')\n elif cpu.is_i386():\n opt.append('-march=i386')\n if cpu.is_Intel():\n opt.extend(['-malign-double','-fomit-frame-pointer'])\n return opt\n\nif __name__ == '__main__':\n from scipy_distutils import log\n log.set_verbosity(2)\n from fcompiler import new_fcompiler\n #compiler = new_fcompiler(compiler='gnu')\n compiler = GnuFCompiler()\n compiler.customize()\n print compiler.get_version()\n", "source_code_before": "\nimport re\nimport os\nimport sys\n\nfrom cpuinfo import cpu\nfrom fcompiler import FCompiler\nfrom exec_command import exec_command, find_executable\n\nclass GnuFCompiler(FCompiler):\n\n compiler_type = 'gnu'\n version_pattern = r'GNU Fortran ((\\(GCC[^\\)]*(\\)\\)|\\)))|)\\s*'\\\n '(?P[^\\s*\\)]+)'\n\n # 'g77 --version' results\n # SunOS: GNU Fortran (GCC 3.2) 3.2 20020814 (release)\n # Debian: GNU Fortran (GCC) 3.3.3 20040110 (prerelease) (Debian)\n # GNU Fortran (GCC) 3.3.3 (Debian 20040401)\n # GNU Fortran 0.5.25 20010319 (prerelease)\n # Redhat: GNU Fortran (GCC 3.2.2 20030222 (Red Hat Linux 3.2.2-5)) 3.2.2 20030222 (Red Hat Linux 3.2.2-5)\n\n for fc_exe in map(find_executable,['g77','f77']):\n if os.path.isfile(fc_exe):\n break\n executables = {\n 'version_cmd' : [fc_exe,\"--version\"],\n 'compiler_f77' : [fc_exe,\"-Wall\",\"-fno-second-underscore\"],\n 'compiler_f90' : None,\n 'compiler_fix' : None,\n 'linker_so' : [fc_exe],\n 'archiver' : [\"ar\", \"-cr\"],\n 'ranlib' : [\"ranlib\"],\n }\n module_dir_switch = None\n module_include_switch = None\n\n # Cygwin: f771: warning: -fPIC ignored for target (all code is position independent)\n if os.name != 'nt' and sys.platform!='cygwin':\n pic_flags = ['-fPIC']\n\n #def get_linker_so(self):\n # # win32 linking should be handled by standard linker\n # # Darwin g77 cannot be used as a linker.\n # #if re.match(r'(darwin)', sys.platform):\n # # return\n # return FCompiler.get_linker_so(self)\n\n def get_flags_linker_so(self):\n opt = []\n if sys.platform=='darwin':\n if os.path.realpath(sys.executable).startswith('/System'):\n # This is when Python is from Apple framework\n opt.extend([\"-Wl,-framework\",\"-Wl,Python\"])\n #else we are running in Fink python.\n opt.extend([\"-lcc_dynamic\",\"-bundle\"])\n else:\n opt.append(\"-shared\")\n if sys.platform[:5]=='sunos':\n # SunOS often has dynamically loaded symbols defined in the\n # static library libg2c.a The linker doesn't like this. To\n # ignore the problem, use the -mimpure-text flag. It isn't\n # the safest thing, but seems to work. 'man gcc' says:\n # \".. Instead of using -mimpure-text, you should compile all\n # source code with -fpic or -fPIC.\"\n opt.append('-mimpure-text')\n return opt\n\n def get_libgcc_dir(self):\n status, output = exec_command('%s -print-libgcc-file-name' \\\n % (self.compiler_f77[0]),use_tee=0) \n if not status:\n return os.path.dirname(output)\n return\n\n def get_library_dirs(self):\n opt = []\n if sys.platform[:5] != 'linux':\n d = self.get_libgcc_dir()\n if d:\n opt.append(d)\n return opt\n\n def get_libraries(self):\n opt = []\n d = self.get_libgcc_dir()\n if d is not None:\n g2c = 'g2c-pic'\n f = self.static_lib_format % (g2c, self.static_lib_extension)\n if not os.path.isfile(os.path.join(d,f)):\n g2c = 'g2c'\n else:\n g2c = 'g2c'\n \n if sys.platform=='win32':\n opt.append('gcc')\n if g2c is not None:\n opt.append(g2c)\n return opt\n\n def get_flags_debug(self):\n return ['-g']\n\n def get_flags_opt(self):\n if self.get_version()=='3.3.3':\n # With this compiler version building Fortran BLAS/LAPACK\n # with -O3 caused failures in lib.lapack heevr,syevr tests.\n opt = ['-O2']\n else:\n opt = ['-O3']\n opt.append('-funroll-loops')\n return opt\n\n def get_flags_arch(self):\n opt = []\n if sys.platform=='darwin':\n if os.name != 'posix':\n # this should presumably correspond to Apple\n if cpu.is_ppc():\n opt.append('-arch ppc')\n elif cpu.is_i386():\n opt.append('-arch i386')\n for a in '601 602 603 603e 604 604e 620 630 740 7400 7450 750'\\\n '403 505 801 821 823 860'.split():\n if getattr(cpu,'is_ppc%s'%a)():\n opt.append('-mcpu='+a)\n opt.append('-mtune='+a)\n break \n return opt\n march_flag = 1\n # 0.5.25 corresponds to 2.95.x\n if self.get_version() == '0.5.26': # gcc 3.0\n if cpu.is_AthlonK6():\n opt.append('-march=k6')\n elif cpu.is_AthlonK7():\n opt.append('-march=athlon')\n else:\n march_flag = 0\n # Note: gcc 3.2 on win32 has breakage with -march specified\n elif self.get_version() >= '3.1.1' \\\n and not sys.platform=='win32': # gcc >= 3.1.1\n if cpu.is_AthlonK6():\n opt.append('-march=k6')\n elif cpu.is_AthlonK6_2():\n opt.append('-march=k6-2')\n elif cpu.is_AthlonK6_3():\n opt.append('-march=k6-3')\n elif cpu.is_AthlonK7():\n opt.append('-march=athlon')\n elif cpu.is_AthlonMP():\n opt.append('-march=athlon-mp')\n # there's also: athlon-tbird, athlon-4, athlon-xp\n elif cpu.is_PentiumIV():\n opt.append('-march=pentium4')\n elif cpu.is_PentiumIII():\n opt.append('-march=pentium3')\n elif cpu.is_PentiumII():\n opt.append('-march=pentium2')\n else:\n march_flag = 0\n if self.get_version() >= '3.4' and not march_flag:\n march_flag = 1\n if cpu.is_Opteron():\n opt.append('-march=opteron')\n elif cpu.is_Athlon64():\n opt.append('-march=athlon64')\n else:\n march_flag = 0\n if cpu.has_mmx(): opt.append('-mmmx') \n if self.get_version() > '3.2.2':\n if cpu.has_sse2(): opt.append('-msse2')\n if cpu.has_sse(): opt.append('-msse')\n if self.get_version() >= '3.4':\n if cpu.has_sse3(): opt.append('-msse3')\n if cpu.has_3dnow(): opt.append('-m3dnow')\n else:\n march_flag = 0\n if march_flag:\n pass\n elif cpu.is_i686():\n opt.append('-march=i686')\n elif cpu.is_i586():\n opt.append('-march=i586')\n elif cpu.is_i486():\n opt.append('-march=i486')\n elif cpu.is_i386():\n opt.append('-march=i386')\n if cpu.is_Intel():\n opt.extend(['-malign-double','-fomit-frame-pointer'])\n return opt\n\nif __name__ == '__main__':\n from scipy_distutils import log\n log.set_verbosity(2)\n from fcompiler import new_fcompiler\n #compiler = new_fcompiler(compiler='gnu')\n compiler = GnuFCompiler()\n compiler.customize()\n print compiler.get_version()\n", "methods": [ { "name": "get_flags_linker_so", "long_name": "get_flags_linker_so( self )", "filename": "gnufcompiler.py", "nloc": 11, "complexity": 4, "token_count": 80, "parameters": [ "self" ], "start_line": 49, "end_line": 67, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 19, "top_nesting_level": 1 }, { "name": "get_libgcc_dir", "long_name": "get_libgcc_dir( self )", "filename": "gnufcompiler.py", "nloc": 6, "complexity": 2, "token_count": 41, "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": "get_library_dirs", "long_name": "get_library_dirs( self )", "filename": "gnufcompiler.py", "nloc": 7, "complexity": 3, "token_count": 38, "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": "get_libraries", "long_name": "get_libraries( self )", "filename": "gnufcompiler.py", "nloc": 15, "complexity": 5, "token_count": 93, "parameters": [ "self" ], "start_line": 84, "end_line": 99, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 16, "top_nesting_level": 1 }, { "name": "get_flags_debug", "long_name": "get_flags_debug( self )", "filename": "gnufcompiler.py", "nloc": 2, "complexity": 1, "token_count": 9, "parameters": [ "self" ], "start_line": 101, "end_line": 102, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 2, "top_nesting_level": 1 }, { "name": "get_flags_opt", "long_name": "get_flags_opt( self )", "filename": "gnufcompiler.py", "nloc": 7, "complexity": 2, "token_count": 34, "parameters": [ "self" ], "start_line": 104, "end_line": 112, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 9, "top_nesting_level": 1 }, { "name": "get_flags_arch", "long_name": "get_flags_arch( self )", "filename": "gnufcompiler.py", "nloc": 73, "complexity": 37, "token_count": 469, "parameters": [ "self" ], "start_line": 114, "end_line": 190, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 77, "top_nesting_level": 1 } ], "methods_before": [ { "name": "get_flags_linker_so", "long_name": "get_flags_linker_so( self )", "filename": "gnufcompiler.py", "nloc": 11, "complexity": 4, "token_count": 80, "parameters": [ "self" ], "start_line": 49, "end_line": 67, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 19, "top_nesting_level": 1 }, { "name": "get_libgcc_dir", "long_name": "get_libgcc_dir( self )", "filename": "gnufcompiler.py", "nloc": 6, "complexity": 2, "token_count": 41, "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": "get_library_dirs", "long_name": "get_library_dirs( self )", "filename": "gnufcompiler.py", "nloc": 7, "complexity": 3, "token_count": 38, "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": "get_libraries", "long_name": "get_libraries( self )", "filename": "gnufcompiler.py", "nloc": 15, "complexity": 5, "token_count": 93, "parameters": [ "self" ], "start_line": 84, "end_line": 99, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 16, "top_nesting_level": 1 }, { "name": "get_flags_debug", "long_name": "get_flags_debug( self )", "filename": "gnufcompiler.py", "nloc": 2, "complexity": 1, "token_count": 9, "parameters": [ "self" ], "start_line": 101, "end_line": 102, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 2, "top_nesting_level": 1 }, { "name": "get_flags_opt", "long_name": "get_flags_opt( self )", "filename": "gnufcompiler.py", "nloc": 7, "complexity": 2, "token_count": 34, "parameters": [ "self" ], "start_line": 104, "end_line": 112, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 9, "top_nesting_level": 1 }, { "name": "get_flags_arch", "long_name": "get_flags_arch( self )", "filename": "gnufcompiler.py", "nloc": 73, "complexity": 37, "token_count": 469, "parameters": [ "self" ], "start_line": 114, "end_line": 190, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 77, "top_nesting_level": 1 } ], "changed_methods": [ { "name": "get_flags_opt", "long_name": "get_flags_opt( self )", "filename": "gnufcompiler.py", "nloc": 7, "complexity": 2, "token_count": 34, "parameters": [ "self" ], "start_line": 104, "end_line": 112, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 9, "top_nesting_level": 1 } ], "nloc": 154, "complexity": 54, "token_count": 940, "diff_parsed": { "added": [ " if self.get_version()<='3.3.3':" ], "deleted": [ " if self.get_version()=='3.3.3':" ] } } ] }, { "hash": "bbc46872ab69ba9334580288c1f86788007ad424", "msg": "Pearu's ATLAS detection fix for Python built in debug mode. In debug\nmode there's extra ref count output which was screwing things up.", "author": { "name": "jmiller", "email": "jmiller@localhost" }, "committer": { "name": "jmiller", "email": "jmiller@localhost" }, "author_date": "2005-01-10T18:07:42+00:00", "author_timezone": 0, "committer_date": "2005-01-10T18:07:42+00:00", "committer_timezone": 0, "branches": [ "main" ], "in_main_branch": true, "merge": false, "parents": [ "54e300d091cdb40e194855b258d5721920df7191" ], "project_name": "repo_copy", "project_path": "/tmp/tmpqop781_j/repo_copy", "deletions": 1, "insertions": 1, "lines": 2, "files": 1, "dmm_unit_size": null, "dmm_unit_complexity": null, "dmm_unit_interfacing": null, "modified_files": [ { "old_path": "scipy_distutils/system_info.py", "new_path": "scipy_distutils/system_info.py", "filename": "system_info.py", "extension": "py", "change_type": "MODIFY", "diff": "@@ -903,7 +903,7 @@ def atlas_version_c(extension, build_dir,magic=magic):\n s,o = exec_command(cmd,execute_in=os.path.dirname(target),use_tee=0)\n atlas_version = None\n if not s:\n- m = re.match(r'ATLAS version (?P\\d+[.]\\d+[.]\\d+)',o)\n+ m = re.search(r'ATLAS version (?P\\d+[.]\\d+[.]\\d+)',o)\n if m:\n atlas_version = m.group('version')\n if atlas_version is None:\n", "added_lines": 1, "deleted_lines": 1, "source_code": "#!/usr/bin/env python\n\"\"\"\nThis file defines a set of system_info classes for getting\ninformation about various resources (libraries, library directories,\ninclude directories, etc.) in the system. Currently, the following\nclasses are available:\n\n atlas_info\n atlas_threads_info\n atlas_blas_info\n atlas_blas_threads_info\n lapack_atlas_info\n blas_info\n lapack_info\n blas_opt_info # usage recommended\n lapack_opt_info # usage recommended\n fftw_info,dfftw_info,sfftw_info\n fftw_threads_info,dfftw_threads_info,sfftw_threads_info\n djbfft_info\n x11_info\n lapack_src_info\n blas_src_info\n numpy_info\n numarray_info\n boost_python_info\n agg2_info\n wx_info\n gdk_pixbuf_xlib_2_info\n gdk_pixbuf_2_info\n gdk_x11_2_info\n gtkp_x11_2_info\n gtkp_2_info\n xft_info\n freetype2_info\n\nUsage:\n info_dict = get_info()\n where is a string 'atlas','x11','fftw','lapack','blas',\n 'lapack_src', 'blas_src', etc. For a complete list of allowed names,\n see the definition of get_info() function below.\n\n Returned info_dict is a dictionary which is compatible with\n distutils.setup keyword arguments. If info_dict == {}, then the\n asked resource is not available (system_info could not find it).\n\n Several *_info classes specify an environment variable to specify\n the locations of software. When setting the corresponding environment\n variable to 'None' then the software will be ignored, even when it\n is available in system.\n\nGlobal parameters:\n system_info.search_static_first - search static libraries (.a)\n in precedence to shared ones (.so, .sl) if enabled.\n system_info.verbosity - output the results to stdout if enabled.\n\nThe file 'site.cfg' in the same directory as this module is read\nfor configuration options. The format is that used by ConfigParser (i.e.,\nWindows .INI style). The section DEFAULT has options that are the default\nfor each section. The available sections are fftw, atlas, and x11. Appropiate\ndefaults are used if nothing is specified.\n\nThe order of finding the locations of resources is the following:\n 1. environment variable\n 2. section in site.cfg\n 3. DEFAULT section in site.cfg\nOnly the first complete match is returned.\n\nExample:\n----------\n[DEFAULT]\nlibrary_dirs = /usr/lib:/usr/local/lib:/opt/lib\ninclude_dirs = /usr/include:/usr/local/include:/opt/include\nsrc_dirs = /usr/local/src:/opt/src\n# search static libraries (.a) in preference to shared ones (.so)\nsearch_static_first = 0\n\n[fftw]\nfftw_libs = rfftw, fftw\nfftw_opt_libs = rfftw_threaded, fftw_threaded\n# if the above aren't found, look for {s,d}fftw_libs and {s,d}fftw_opt_libs\n\n[atlas]\nlibrary_dirs = /usr/lib/3dnow:/usr/lib/3dnow/atlas\n# for overriding the names of the atlas libraries\natlas_libs = lapack, f77blas, cblas, atlas\n\n[x11]\nlibrary_dirs = /usr/X11R6/lib\ninclude_dirs = /usr/X11R6/include\n----------\n\nAuthors:\n Pearu Peterson , February 2002\n David M. Cooke , April 2002\n\nCopyright 2002 Pearu Peterson all rights reserved,\nPearu Peterson \nPermission to use, modify, and distribute this software is given under the \nterms of the SciPy (BSD style) license. See LICENSE.txt that came with\nthis distribution for specifics.\n\nNO WARRANTY IS EXPRESSED OR IMPLIED. USE AT YOUR OWN RISK.\n\"\"\"\n\n__revision__ = '$Id$'\n\nimport sys,os,re,types\nimport warnings\nfrom distutils.errors import DistutilsError\nfrom glob import glob\nimport ConfigParser\nfrom exec_command import find_executable, exec_command\n\nfrom distutils.sysconfig import get_config_vars\n\nif sys.platform == 'win32':\n default_lib_dirs = ['C:\\\\'] # probably not very helpful...\n default_include_dirs = []\n default_src_dirs = ['.']\n default_x11_lib_dirs = []\n default_x11_include_dirs = []\nelse:\n default_lib_dirs = ['/usr/local/lib', '/opt/lib', '/usr/lib',\n '/sw/lib']\n default_include_dirs = ['/usr/local/include',\n '/opt/include', '/usr/include',\n '/sw/include']\n default_src_dirs = ['.','/usr/local/src', '/opt/src','/sw/src']\n default_x11_lib_dirs = ['/usr/X11R6/lib','/usr/X11/lib','/usr/lib']\n default_x11_include_dirs = ['/usr/X11R6/include','/usr/X11/include',\n '/usr/include']\n\nif os.path.join(sys.prefix, 'lib') not in default_lib_dirs:\n default_lib_dirs.insert(0,os.path.join(sys.prefix, 'lib'))\n default_include_dirs.append(os.path.join(sys.prefix, 'include'))\n default_src_dirs.append(os.path.join(sys.prefix, 'src'))\n\ndefault_lib_dirs = filter(os.path.isdir, default_lib_dirs)\ndefault_include_dirs = filter(os.path.isdir, default_include_dirs)\ndefault_src_dirs = filter(os.path.isdir, default_src_dirs)\n\nso_ext = get_config_vars('SO')[0] or ''\n\ndef get_info(name,notfound_action=0):\n \"\"\"\n notfound_action:\n 0 - do nothing\n 1 - display warning message\n 2 - raise error\n \"\"\"\n cl = {'atlas':atlas_info, # use lapack_opt or blas_opt instead\n 'atlas_threads':atlas_threads_info, # ditto\n 'atlas_blas':atlas_blas_info,\n 'atlas_blas_threads':atlas_blas_threads_info,\n 'lapack_atlas':lapack_atlas_info, # use lapack_opt instead\n 'lapack_atlas_threads':lapack_atlas_threads_info, # ditto\n 'x11':x11_info,\n 'fftw':fftw_info,\n 'dfftw':dfftw_info,\n 'sfftw':sfftw_info,\n 'fftw_threads':fftw_threads_info,\n 'dfftw_threads':dfftw_threads_info,\n 'sfftw_threads':sfftw_threads_info,\n 'djbfft':djbfft_info,\n 'blas':blas_info, # use blas_opt instead\n 'lapack':lapack_info, # use lapack_opt instead\n 'lapack_src':lapack_src_info,\n 'blas_src':blas_src_info,\n 'numpy':numpy_info,\n 'numarray':numarray_info,\n 'lapack_opt':lapack_opt_info,\n 'blas_opt':blas_opt_info,\n 'boost_python':boost_python_info,\n 'agg2':agg2_info,\n 'wx':wx_info,\n 'gdk_pixbuf_xlib_2':gdk_pixbuf_xlib_2_info,\n 'gdk-pixbuf-xlib-2.0':gdk_pixbuf_xlib_2_info,\n 'gdk_pixbuf_2':gdk_pixbuf_2_info,\n 'gdk-pixbuf-2.0':gdk_pixbuf_2_info,\n 'gdk':gdk_info,\n 'gdk_2':gdk_2_info,\n 'gdk-2.0':gdk_2_info,\n 'gdk_x11_2':gdk_x11_2_info,\n 'gdk-x11-2.0':gdk_x11_2_info,\n 'gtkp_x11_2':gtkp_x11_2_info,\n 'gtk+-x11-2.0':gtkp_x11_2_info,\n 'gtkp_2':gtkp_2_info,\n 'gtk+-2.0':gtkp_2_info,\n 'xft':xft_info,\n 'freetype2':freetype2_info,\n }.get(name.lower(),system_info)\n return cl().get_info(notfound_action)\n\nclass NotFoundError(DistutilsError):\n \"\"\"Some third-party program or library is not found.\"\"\"\n\nclass AtlasNotFoundError(NotFoundError):\n \"\"\"\n Atlas (http://math-atlas.sourceforge.net/) libraries not found.\n Directories to search for the libraries can be specified in the\n scipy_distutils/site.cfg file (section [atlas]) or by setting\n the ATLAS environment variable.\"\"\"\n\nclass LapackNotFoundError(NotFoundError):\n \"\"\"\n Lapack (http://www.netlib.org/lapack/) libraries not found.\n Directories to search for the libraries can be specified in the\n scipy_distutils/site.cfg file (section [lapack]) or by setting\n the LAPACK environment variable.\"\"\"\n\nclass LapackSrcNotFoundError(LapackNotFoundError):\n \"\"\"\n Lapack (http://www.netlib.org/lapack/) sources not found.\n Directories to search for the sources can be specified in the\n scipy_distutils/site.cfg file (section [lapack_src]) or by setting\n the LAPACK_SRC environment variable.\"\"\"\n\nclass BlasNotFoundError(NotFoundError):\n \"\"\"\n Blas (http://www.netlib.org/blas/) libraries not found.\n Directories to search for the libraries can be specified in the\n scipy_distutils/site.cfg file (section [blas]) or by setting\n the BLAS environment variable.\"\"\"\n\nclass BlasSrcNotFoundError(BlasNotFoundError):\n \"\"\"\n Blas (http://www.netlib.org/blas/) sources not found.\n Directories to search for the sources can be specified in the\n scipy_distutils/site.cfg file (section [blas_src]) or by setting\n the BLAS_SRC environment variable.\"\"\"\n\nclass FFTWNotFoundError(NotFoundError):\n \"\"\"\n FFTW (http://www.fftw.org/) libraries not found.\n Directories to search for the libraries can be specified in the\n scipy_distutils/site.cfg file (section [fftw]) or by setting\n the FFTW environment variable.\"\"\"\n\nclass DJBFFTNotFoundError(NotFoundError):\n \"\"\"\n DJBFFT (http://cr.yp.to/djbfft.html) libraries not found.\n Directories to search for the libraries can be specified in the\n scipy_distutils/site.cfg file (section [djbfft]) or by setting\n the DJBFFT environment variable.\"\"\"\n\nclass F2pyNotFoundError(NotFoundError):\n \"\"\"\n f2py2e (http://cens.ioc.ee/projects/f2py2e/) module not found.\n Get it from above location, install it, and retry setup.py.\"\"\"\n\nclass NumericNotFoundError(NotFoundError):\n \"\"\"\n Numeric (http://www.numpy.org/) module not found.\n Get it from above location, install it, and retry setup.py.\"\"\"\n\nclass X11NotFoundError(NotFoundError):\n \"\"\"X11 libraries not found.\"\"\"\n\nclass system_info:\n\n \"\"\" get_info() is the only public method. Don't use others.\n \"\"\"\n section = 'DEFAULT'\n dir_env_var = None\n search_static_first = 0 # XXX: disabled by default, may disappear in\n # future unless it is proved to be useful.\n verbosity = 1\n saved_results = {}\n\n notfounderror = NotFoundError\n\n def __init__ (self,\n default_lib_dirs=default_lib_dirs,\n default_include_dirs=default_include_dirs,\n verbosity = 1,\n ):\n self.__class__.info = {}\n self.local_prefixes = []\n defaults = {}\n defaults['libraries'] = ''\n defaults['library_dirs'] = os.pathsep.join(default_lib_dirs)\n defaults['include_dirs'] = os.pathsep.join(default_include_dirs)\n defaults['src_dirs'] = os.pathsep.join(default_src_dirs)\n defaults['search_static_first'] = str(self.search_static_first)\n self.cp = ConfigParser.ConfigParser(defaults)\n try:\n __file__\n except NameError:\n __file__ = sys.argv[0]\n cf = os.path.join(os.path.split(os.path.abspath(__file__))[0],\n 'site.cfg')\n self.cp.read([cf])\n if not self.cp.has_section(self.section):\n self.cp.add_section(self.section)\n self.search_static_first = self.cp.getboolean(self.section,\n 'search_static_first')\n assert isinstance(self.search_static_first, type(0))\n\n def calc_libraries_info(self):\n libs = self.get_libraries()\n dirs = self.get_lib_dirs()\n info = {}\n for lib in libs:\n i = None\n for d in dirs:\n i = self.check_libs(d,[lib]) \n if i is not None:\n break\n if i is not None:\n dict_append(info,**i)\n else:\n print 'Library %s was not found. Ignoring' % (lib)\n return info\n\n def set_info(self,**info):\n if info: \n lib_info = self.calc_libraries_info()\n dict_append(info,**lib_info)\n self.saved_results[self.__class__.__name__] = info\n\n def has_info(self):\n return self.saved_results.has_key(self.__class__.__name__)\n\n def get_info(self,notfound_action=0):\n \"\"\" Return a dictonary with items that are compatible\n with scipy_distutils.setup keyword arguments.\n \"\"\"\n flag = 0\n if not self.has_info():\n flag = 1\n if self.verbosity>0:\n print self.__class__.__name__ + ':'\n if hasattr(self, 'calc_info'):\n self.calc_info()\n if notfound_action:\n if not self.has_info():\n if notfound_action==1:\n warnings.warn(self.notfounderror.__doc__)\n elif notfound_action==2:\n raise self.notfounderror,self.notfounderror.__doc__\n else:\n raise ValueError,`notfound_action`\n\n if self.verbosity>0:\n if not self.has_info():\n print ' NOT AVAILABLE'\n self.set_info()\n else:\n print ' FOUND:'\n \n res = self.saved_results.get(self.__class__.__name__)\n if self.verbosity>0 and flag:\n for k,v in res.items():\n v = str(v)\n if k=='sources' and len(v)>200: v = v[:60]+' ...\\n... '+v[-60:]\n print ' %s = %s'%(k,v)\n print\n \n return res\n\n def get_paths(self, section, key):\n dirs = self.cp.get(section, key).split(os.pathsep)\n env_var = self.dir_env_var\n if env_var:\n if type(env_var) is type([]):\n e0 = env_var[-1]\n for e in env_var:\n if os.environ.has_key(e):\n e0 = e\n break\n if not env_var[0]==e0:\n print 'Setting %s=%s' % (env_var[0],e0)\n env_var = e0\n if env_var and os.environ.has_key(env_var):\n d = os.environ[env_var]\n if d=='None':\n print 'Disabled',self.__class__.__name__,'(%s is None)' \\\n % (self.dir_env_var)\n return []\n if os.path.isfile(d):\n dirs = [os.path.dirname(d)] + dirs\n l = getattr(self,'_lib_names',[])\n if len(l)==1:\n b = os.path.basename(d)\n b = os.path.splitext(b)[0]\n if b[:3]=='lib':\n print 'Replacing _lib_names[0]==%r with %r' \\\n % (self._lib_names[0], b[3:])\n self._lib_names[0] = b[3:]\n else:\n ds = d.split(os.pathsep)\n ds2 = []\n for d in ds:\n if os.path.isdir(d):\n ds2.append(d)\n for dd in ['include','lib']:\n d1 = os.path.join(d,dd)\n if os.path.isdir(d1):\n ds2.append(d1)\n dirs = ds2 + dirs\n default_dirs = self.cp.get('DEFAULT', key).split(os.pathsep)\n dirs.extend(default_dirs)\n ret = []\n [ret.append(d) for d in dirs if os.path.isdir(d) and d not in ret]\n if self.verbosity>1:\n print '(',key,'=',':'.join(ret),')'\n return ret\n\n def get_lib_dirs(self, key='library_dirs'):\n return self.get_paths(self.section, key)\n\n def get_include_dirs(self, key='include_dirs'):\n return self.get_paths(self.section, key)\n\n def get_src_dirs(self, key='src_dirs'):\n return self.get_paths(self.section, key)\n\n def get_libs(self, key, default):\n try:\n libs = self.cp.get(self.section, key)\n except ConfigParser.NoOptionError:\n if not default:\n return []\n if type(default) is type(''):\n return [default]\n return default\n return [b for b in [a.strip() for a in libs.split(',')] if b]\n\n def get_libraries(self, key='libraries'):\n return self.get_libs(key,'')\n\n def check_libs(self,lib_dir,libs,opt_libs =[]):\n \"\"\" If static or shared libraries are available then return\n their info dictionary. \"\"\"\n if self.search_static_first:\n exts = ['.a',so_ext]\n else:\n exts = [so_ext,'.a']\n if sys.platform=='cygwin':\n exts.append('.dll.a')\n for ext in exts:\n info = self._check_libs(lib_dir,libs,opt_libs,ext)\n if info is not None: return info\n return\n\n def _lib_list(self, lib_dir, libs, ext):\n assert type(lib_dir) is type('')\n liblist = []\n for l in libs:\n p = self.combine_paths(lib_dir, 'lib'+l+ext)\n if p:\n assert len(p)==1\n liblist.append(p[0])\n return liblist\n\n def _extract_lib_names(self,libs):\n return [os.path.splitext(os.path.basename(p))[0][3:] \\\n for p in libs]\n\n def _check_libs(self,lib_dir,libs, opt_libs, ext):\n found_libs = self._lib_list(lib_dir, libs, ext)\n if len(found_libs) == len(libs):\n found_libs = self._extract_lib_names(found_libs)\n info = {'libraries' : found_libs, 'library_dirs' : [lib_dir]}\n opt_found_libs = self._lib_list(lib_dir, opt_libs, ext)\n if len(opt_found_libs) == len(opt_libs):\n opt_found_libs = self._extract_lib_names(opt_found_libs)\n info['libraries'].extend(opt_found_libs)\n return info\n\n def combine_paths(self,*args):\n return combine_paths(*args,**{'verbosity':self.verbosity})\n\nclass fftw_info(system_info):\n section = 'fftw'\n dir_env_var = 'FFTW'\n libs = ['rfftw', 'fftw']\n includes = ['fftw.h','rfftw.h']\n macros = [('SCIPY_FFTW_H',None)]\n notfounderror = FFTWNotFoundError\n\n def __init__(self):\n system_info.__init__(self)\n\n def calc_info(self):\n lib_dirs = self.get_lib_dirs()\n incl_dirs = self.get_include_dirs()\n incl_dir = None\n libs = self.get_libs(self.section+'_libs', self.libs)\n info = None\n for d in lib_dirs:\n r = self.check_libs(d,libs)\n if r is not None:\n info = r\n break\n if info is not None:\n flag = 0\n for d in incl_dirs:\n if len(self.combine_paths(d,self.includes))==2:\n dict_append(info,include_dirs=[d])\n flag = 1\n incl_dirs = [d]\n incl_dir = d\n break\n if flag:\n dict_append(info,define_macros=self.macros)\n else:\n info = None\n if info is not None:\n self.set_info(**info)\n\nclass dfftw_info(fftw_info):\n section = 'fftw'\n dir_env_var = 'FFTW'\n libs = ['drfftw','dfftw']\n includes = ['dfftw.h','drfftw.h']\n macros = [('SCIPY_DFFTW_H',None)]\n\nclass sfftw_info(fftw_info):\n section = 'fftw'\n dir_env_var = 'FFTW'\n libs = ['srfftw','sfftw']\n includes = ['sfftw.h','srfftw.h']\n macros = [('SCIPY_SFFTW_H',None)]\n\nclass fftw_threads_info(fftw_info):\n section = 'fftw'\n dir_env_var = 'FFTW'\n libs = ['rfftw_threads','fftw_threads']\n includes = ['fftw_threads.h','rfftw_threads.h']\n macros = [('SCIPY_FFTW_THREADS_H',None)]\n\nclass dfftw_threads_info(fftw_info):\n section = 'fftw'\n dir_env_var = 'FFTW'\n libs = ['drfftw_threads','dfftw_threads']\n includes = ['dfftw_threads.h','drfftw_threads.h']\n macros = [('SCIPY_DFFTW_THREADS_H',None)]\n\nclass sfftw_threads_info(fftw_info):\n section = 'fftw'\n dir_env_var = 'FFTW'\n libs = ['srfftw_threads','sfftw_threads']\n includes = ['sfftw_threads.h','srfftw_threads.h']\n macros = [('SCIPY_SFFTW_THREADS_H',None)]\n\nclass djbfft_info(system_info):\n section = 'djbfft'\n dir_env_var = 'DJBFFT'\n notfounderror = DJBFFTNotFoundError\n\n def get_paths(self, section, key):\n pre_dirs = system_info.get_paths(self, section, key)\n dirs = []\n for d in pre_dirs:\n dirs.extend(self.combine_paths(d,['djbfft'])+[d])\n return [ d for d in dirs if os.path.isdir(d) ]\n\n def calc_info(self):\n lib_dirs = self.get_lib_dirs()\n incl_dirs = self.get_include_dirs()\n info = None\n for d in lib_dirs:\n p = self.combine_paths (d,['djbfft.a'])\n if p:\n info = {'extra_objects':p}\n break\n p = self.combine_paths (d,['libdjbfft.a'])\n if p:\n info = {'libraries':['djbfft'],'library_dirs':[d]}\n break\n if info is None:\n return\n for d in incl_dirs:\n if len(self.combine_paths(d,['fftc8.h','fftfreq.h']))==2:\n dict_append(info,include_dirs=[d],\n define_macros=[('SCIPY_DJBFFT_H',None)])\n self.set_info(**info)\n return\n return\n\nclass atlas_info(system_info):\n section = 'atlas'\n dir_env_var = 'ATLAS'\n _lib_names = ['f77blas','cblas']\n if sys.platform[:7]=='freebsd':\n _lib_atlas = ['atlas_r']\n _lib_lapack = ['alapack_r']\n else:\n _lib_atlas = ['atlas']\n _lib_lapack = ['lapack']\n\n notfounderror = AtlasNotFoundError\n\n def get_paths(self, section, key):\n pre_dirs = system_info.get_paths(self, section, key)\n dirs = []\n for d in pre_dirs:\n dirs.extend(self.combine_paths(d,['atlas*','ATLAS*',\n 'sse','3dnow','sse2'])+[d])\n return [ d for d in dirs if os.path.isdir(d) ]\n\n def calc_info(self):\n lib_dirs = self.get_lib_dirs()\n info = {}\n atlas_libs = self.get_libs('atlas_libs',\n self._lib_names + self._lib_atlas)\n lapack_libs = self.get_libs('lapack_libs',self._lib_lapack)\n atlas = None\n lapack = None\n atlas_1 = None\n for d in lib_dirs:\n atlas = self.check_libs(d,atlas_libs,[])\n lapack_atlas = self.check_libs(d,['lapack_atlas'],[])\n if atlas is not None:\n lib_dirs2 = self.combine_paths(d,['atlas*','ATLAS*'])+[d]\n for d2 in lib_dirs2:\n lapack = self.check_libs(d2,lapack_libs,[])\n if lapack is not None:\n break\n else:\n lapack = None\n if lapack is not None:\n break\n if atlas:\n atlas_1 = atlas\n print self.__class__\n if atlas is None:\n atlas = atlas_1\n if atlas is None:\n return\n include_dirs = self.get_include_dirs()\n h = (self.combine_paths(lib_dirs+include_dirs,'cblas.h') or [None])[0]\n if h:\n h = os.path.dirname(h)\n dict_append(info,include_dirs=[h])\n info['language'] = 'c'\n if lapack is not None:\n dict_append(info,**lapack)\n dict_append(info,**atlas)\n elif 'lapack_atlas' in atlas['libraries']:\n dict_append(info,**atlas)\n dict_append(info,define_macros=[('ATLAS_WITH_LAPACK_ATLAS',None)])\n self.set_info(**info)\n return\n else:\n dict_append(info,**atlas)\n dict_append(info,define_macros=[('ATLAS_WITHOUT_LAPACK',None)])\n message = \"\"\"\n*********************************************************************\n Could not find lapack library within the ATLAS installation.\n*********************************************************************\n\"\"\"\n warnings.warn(message)\n self.set_info(**info)\n return\n \n # Check if lapack library is complete, only warn if it is not.\n lapack_dir = lapack['library_dirs'][0]\n lapack_name = lapack['libraries'][0]\n lapack_lib = None\n for e in ['.a',so_ext]:\n fn = os.path.join(lapack_dir,'lib'+lapack_name+e)\n if os.path.exists(fn):\n lapack_lib = fn\n break\n if lapack_lib is not None:\n sz = os.stat(lapack_lib)[6]\n if sz <= 4000*1024:\n message = \"\"\"\n*********************************************************************\n Lapack library (from ATLAS) is probably incomplete:\n size of %s is %sk (expected >4000k)\n\n Follow the instructions in the KNOWN PROBLEMS section of the file\n scipy/INSTALL.txt.\n*********************************************************************\n\"\"\" % (lapack_lib,sz/1024)\n warnings.warn(message)\n else:\n info['language'] = 'f77'\n\n self.set_info(**info)\n\nclass atlas_blas_info(atlas_info):\n _lib_names = ['f77blas','cblas']\n\n def calc_info(self):\n lib_dirs = self.get_lib_dirs()\n info = {}\n atlas_libs = self.get_libs('atlas_libs',\n self._lib_names + self._lib_atlas)\n atlas = None\n for d in lib_dirs:\n atlas = self.check_libs(d,atlas_libs,[])\n if atlas is not None:\n break\n if atlas is None:\n return\n include_dirs = self.get_include_dirs()\n h = (self.combine_paths(lib_dirs+include_dirs,'cblas.h') or [None])[0]\n if h:\n h = os.path.dirname(h)\n dict_append(info,include_dirs=[h])\n info['language'] = 'c'\n\n dict_append(info,**atlas)\n\n self.set_info(**info)\n return\n\n\nclass atlas_threads_info(atlas_info):\n dir_env_var = ['PTATLAS','ATLAS']\n _lib_names = ['ptf77blas','ptcblas']\n\nclass atlas_blas_threads_info(atlas_blas_info):\n dir_env_var = ['PTATLAS','ATLAS']\n _lib_names = ['ptf77blas','ptcblas']\n\nclass lapack_atlas_info(atlas_info):\n _lib_names = ['lapack_atlas'] + atlas_info._lib_names\n\nclass lapack_atlas_threads_info(atlas_threads_info):\n _lib_names = ['lapack_atlas'] + atlas_threads_info._lib_names\n\nclass lapack_info(system_info):\n section = 'lapack'\n dir_env_var = 'LAPACK'\n _lib_names = ['lapack']\n notfounderror = LapackNotFoundError\n\n def calc_info(self):\n lib_dirs = self.get_lib_dirs()\n\n lapack_libs = self.get_libs('lapack_libs', self._lib_names)\n for d in lib_dirs:\n lapack = self.check_libs(d,lapack_libs,[])\n if lapack is not None:\n info = lapack \n break\n else:\n return\n info['language'] = 'f77'\n self.set_info(**info)\n\nclass lapack_src_info(system_info):\n section = 'lapack_src'\n dir_env_var = 'LAPACK_SRC'\n notfounderror = LapackSrcNotFoundError\n\n def get_paths(self, section, key):\n pre_dirs = system_info.get_paths(self, section, key)\n dirs = []\n for d in pre_dirs:\n dirs.extend([d] + self.combine_paths(d,['LAPACK*/SRC','SRC']))\n return [ d for d in dirs if os.path.isdir(d) ]\n\n def calc_info(self):\n src_dirs = self.get_src_dirs()\n src_dir = ''\n for d in src_dirs:\n if os.path.isfile(os.path.join(d,'dgesv.f')):\n src_dir = d\n break\n if not src_dir:\n #XXX: Get sources from netlib. May be ask first.\n return\n # The following is extracted from LAPACK-3.0/SRC/Makefile\n allaux='''\n ilaenv ieeeck lsame lsamen xerbla\n ''' # *.f\n laux = '''\n bdsdc bdsqr disna labad lacpy ladiv lae2 laebz laed0 laed1\n laed2 laed3 laed4 laed5 laed6 laed7 laed8 laed9 laeda laev2\n lagtf lagts lamch lamrg lanst lapy2 lapy3 larnv larrb larre\n larrf lartg laruv las2 lascl lasd0 lasd1 lasd2 lasd3 lasd4\n lasd5 lasd6 lasd7 lasd8 lasd9 lasda lasdq lasdt laset lasq1\n lasq2 lasq3 lasq4 lasq5 lasq6 lasr lasrt lassq lasv2 pttrf\n stebz stedc steqr sterf\n ''' # [s|d]*.f\n lasrc = '''\n gbbrd gbcon gbequ gbrfs gbsv gbsvx gbtf2 gbtrf gbtrs gebak\n gebal gebd2 gebrd gecon geequ gees geesx geev geevx gegs gegv\n gehd2 gehrd gelq2 gelqf gels gelsd gelss gelsx gelsy geql2\n geqlf geqp3 geqpf geqr2 geqrf gerfs gerq2 gerqf gesc2 gesdd\n gesv gesvd gesvx getc2 getf2 getrf getri getrs ggbak ggbal\n gges ggesx ggev ggevx ggglm gghrd gglse ggqrf ggrqf ggsvd\n ggsvp gtcon gtrfs gtsv gtsvx gttrf gttrs gtts2 hgeqz hsein\n hseqr labrd lacon laein lags2 lagtm lahqr lahrd laic1 lals0\n lalsa lalsd langb lange langt lanhs lansb lansp lansy lantb\n lantp lantr lapll lapmt laqgb laqge laqp2 laqps laqsb laqsp\n laqsy lar1v lar2v larf larfb larfg larft larfx largv larrv\n lartv larz larzb larzt laswp lasyf latbs latdf latps latrd\n latrs latrz latzm lauu2 lauum pbcon pbequ pbrfs pbstf pbsv\n pbsvx pbtf2 pbtrf pbtrs pocon poequ porfs posv posvx potf2\n potrf potri potrs ppcon ppequ pprfs ppsv ppsvx pptrf pptri\n pptrs ptcon pteqr ptrfs ptsv ptsvx pttrs ptts2 spcon sprfs\n spsv spsvx sptrf sptri sptrs stegr stein sycon syrfs sysv\n sysvx sytf2 sytrf sytri sytrs tbcon tbrfs tbtrs tgevc tgex2\n tgexc tgsen tgsja tgsna tgsy2 tgsyl tpcon tprfs tptri tptrs\n trcon trevc trexc trrfs trsen trsna trsyl trti2 trtri trtrs\n tzrqf tzrzf\n ''' # [s|c|d|z]*.f\n sd_lasrc = '''\n laexc lag2 lagv2 laln2 lanv2 laqtr lasy2 opgtr opmtr org2l\n org2r orgbr orghr orgl2 orglq orgql orgqr orgr2 orgrq orgtr\n orm2l orm2r ormbr ormhr orml2 ormlq ormql ormqr ormr2 ormr3\n ormrq ormrz ormtr rscl sbev sbevd sbevx sbgst sbgv sbgvd sbgvx\n sbtrd spev spevd spevx spgst spgv spgvd spgvx sptrd stev stevd\n stevr stevx syev syevd syevr syevx sygs2 sygst sygv sygvd\n sygvx sytd2 sytrd\n ''' # [s|d]*.f\n cz_lasrc = '''\n bdsqr hbev hbevd hbevx hbgst hbgv hbgvd hbgvx hbtrd hecon heev\n heevd heevr heevx hegs2 hegst hegv hegvd hegvx herfs hesv\n hesvx hetd2 hetf2 hetrd hetrf hetri hetrs hpcon hpev hpevd\n hpevx hpgst hpgv hpgvd hpgvx hprfs hpsv hpsvx hptrd hptrf\n hptri hptrs lacgv lacp2 lacpy lacrm lacrt ladiv laed0 laed7\n laed8 laesy laev2 lahef lanhb lanhe lanhp lanht laqhb laqhe\n laqhp larcm larnv lartg lascl laset lasr lassq pttrf rot spmv\n spr stedc steqr symv syr ung2l ung2r ungbr unghr ungl2 unglq\n ungql ungqr ungr2 ungrq ungtr unm2l unm2r unmbr unmhr unml2\n unmlq unmql unmqr unmr2 unmr3 unmrq unmrz unmtr upgtr upmtr\n ''' # [c|z]*.f\n #######\n sclaux = laux + ' econd ' # s*.f\n dzlaux = laux + ' secnd ' # d*.f\n slasrc = lasrc + sd_lasrc # s*.f\n dlasrc = lasrc + sd_lasrc # d*.f\n clasrc = lasrc + cz_lasrc + ' srot srscl ' # c*.f\n zlasrc = lasrc + cz_lasrc + ' drot drscl ' # z*.f\n oclasrc = ' icmax1 scsum1 ' # *.f\n ozlasrc = ' izmax1 dzsum1 ' # *.f\n sources = ['s%s.f'%f for f in (sclaux+slasrc).split()] \\\n + ['d%s.f'%f for f in (dzlaux+dlasrc).split()] \\\n + ['c%s.f'%f for f in (clasrc).split()] \\\n + ['z%s.f'%f for f in (zlasrc).split()] \\\n + ['%s.f'%f for f in (allaux+oclasrc+ozlasrc).split()]\n sources = [os.path.join(src_dir,f) for f in sources]\n #XXX: should we check here actual existence of source files?\n info = {'sources':sources,'language':'f77'}\n self.set_info(**info)\n\natlas_version_c_text = r'''\n/* This file is generated from scipy_distutils/system_info.py */\n#ifdef __CPLUSPLUS__\nextern \"C\" {\n#endif\n#include \"Python.h\"\nstatic PyMethodDef module_methods[] = { {NULL,NULL} };\nDL_EXPORT(void) initatlas_version(void) {\n void ATL_buildinfo(void);\n ATL_buildinfo();\n Py_InitModule(\"atlas_version\", module_methods);\n}\n#ifdef __CPLUSCPLUS__\n}\n#endif\n'''\n\ndef get_atlas_version(**config):\n from core import Extension, setup\n from misc_util import get_build_temp\n import log\n magic = hex(hash(`config`))\n def atlas_version_c(extension, build_dir,magic=magic):\n source = os.path.join(build_dir,'atlas_version_%s.c' % (magic))\n if os.path.isfile(source):\n from distutils.dep_util import newer\n if newer(source,__file__):\n return source\n f = open(source,'w')\n f.write(atlas_version_c_text)\n f.close()\n return source\n ext = Extension('atlas_version',\n sources=[atlas_version_c],\n **config)\n extra_args = ['--build-lib',get_build_temp()]\n for a in sys.argv:\n if re.match('[-][-]compiler[=]',a):\n extra_args.append(a)\n try:\n dist = setup(ext_modules=[ext],\n script_name = 'get_atlas_version',\n script_args = ['build_src','build_ext']+extra_args)\n except Exception,msg:\n print \"##### msg: %s\" % msg\n if not msg:\n msg = \"Unknown Exception\"\n log.warn(msg)\n return None\n\n from distutils.sysconfig import get_config_var\n so_ext = get_config_var('SO')\n build_ext = dist.get_command_obj('build_ext')\n target = os.path.join(build_ext.build_lib,'atlas_version'+so_ext)\n from exec_command import exec_command,get_pythonexe\n cmd = [get_pythonexe(),'-c',\n '\"import imp;imp.load_dynamic(\\\\\"atlas_version\\\\\",\\\\\"%s\\\\\")\"'\\\n % (os.path.basename(target))]\n s,o = exec_command(cmd,execute_in=os.path.dirname(target),use_tee=0)\n atlas_version = None\n if not s:\n m = re.search(r'ATLAS version (?P\\d+[.]\\d+[.]\\d+)',o)\n if m:\n atlas_version = m.group('version')\n if atlas_version is None:\n if re.search(r'undefined symbol: ATL_buildinfo',o,re.M):\n atlas_version = '3.2.1_pre3.3.6'\n else:\n print 'Command:',' '.join(cmd)\n print 'Status:',s\n print 'Output:',o\n return atlas_version\n\n\nclass lapack_opt_info(system_info):\n \n def calc_info(self):\n\n if sys.platform=='darwin' and not os.environ.get('ATLAS',None):\n args = []\n link_args = []\n if os.path.exists('/System/Library/Frameworks/Accelerate.framework/'):\n args.extend(['-faltivec','-framework','Accelerate'])\n link_args.extend(['-Wl,-framework','-Wl,Accelerate'])\n elif os.path.exists('/System/Library/Frameworks/vecLib.framework/'):\n args.extend(['-faltivec','-framework','vecLib'])\n link_args.extend(['-Wl,-framework','-Wl,vecLib'])\n if args:\n self.set_info(extra_compile_args=args,\n extra_link_args=link_args,\n define_macros=[('NO_ATLAS_INFO',3)])\n return\n\n atlas_info = get_info('atlas_threads')\n if not atlas_info:\n atlas_info = get_info('atlas')\n #atlas_info = {} ## uncomment for testing\n atlas_version = None\n need_lapack = 0\n need_blas = 0\n info = {}\n if atlas_info:\n version_info = atlas_info.copy()\n atlas_version = get_atlas_version(**version_info)\n if not atlas_info.has_key('define_macros'):\n atlas_info['define_macros'] = []\n if atlas_version is None:\n atlas_info['define_macros'].append(('NO_ATLAS_INFO',2))\n else:\n atlas_info['define_macros'].append(('ATLAS_INFO',\n '\"\\\\\"%s\\\\\"\"' % atlas_version))\n\t\tif atlas_version=='3.2.1_pre3.3.6':\n\t\t atlas_info['define_macros'].append(('NO_ATLAS_INFO',4))\n l = atlas_info.get('define_macros',[])\n if ('ATLAS_WITH_LAPACK_ATLAS',None) in l \\\n or ('ATLAS_WITHOUT_LAPACK',None) in l:\n need_lapack = 1\n info = atlas_info\n else:\n warnings.warn(AtlasNotFoundError.__doc__)\n need_blas = 1\n need_lapack = 1\n dict_append(info,define_macros=[('NO_ATLAS_INFO',1)])\n\n if need_lapack:\n lapack_info = get_info('lapack')\n #lapack_info = {} ## uncomment for testing\n if lapack_info:\n dict_append(info,**lapack_info)\n else:\n warnings.warn(LapackNotFoundError.__doc__)\n lapack_src_info = get_info('lapack_src')\n if not lapack_src_info:\n warnings.warn(LapackSrcNotFoundError.__doc__)\n return\n dict_append(info,libraries=[('flapack_src',lapack_src_info)])\n\n if need_blas:\n blas_info = get_info('blas')\n #blas_info = {} ## uncomment for testing\n if blas_info:\n dict_append(info,**blas_info)\n else:\n warnings.warn(BlasNotFoundError.__doc__)\n blas_src_info = get_info('blas_src')\n if not blas_src_info:\n warnings.warn(BlasSrcNotFoundError.__doc__)\n return\n dict_append(info,libraries=[('fblas_src',blas_src_info)])\n\n self.set_info(**info)\n return\n\n\nclass blas_opt_info(system_info):\n \n def calc_info(self):\n\n if sys.platform=='darwin' and not os.environ.get('ATLAS',None):\n args = []\n link_args = []\n if os.path.exists('/System/Library/Frameworks/Accelerate.framework/'):\n args.extend(['-faltivec','-framework','Accelerate'])\n link_args.extend(['-Wl,-framework','-Wl,Accelerate'])\n elif os.path.exists('/System/Library/Frameworks/vecLib.framework/'):\n args.extend(['-faltivec','-framework','vecLib'])\n link_args.extend(['-Wl,-framework','-Wl,vecLib'])\n if args:\n self.set_info(extra_compile_args=args,\n extra_link_args=link_args,\n define_macros=[('NO_ATLAS_INFO',3)])\n return\n\n atlas_info = get_info('atlas_blas_threads')\n if not atlas_info:\n atlas_info = get_info('atlas_blas')\n atlas_version = None\n need_blas = 0\n info = {}\n if atlas_info:\n version_info = atlas_info.copy()\n atlas_version = get_atlas_version(**version_info)\n if not atlas_info.has_key('define_macros'):\n atlas_info['define_macros'] = []\n if atlas_version is None:\n atlas_info['define_macros'].append(('NO_ATLAS_INFO',2))\n else:\n atlas_info['define_macros'].append(('ATLAS_INFO',\n '\"\\\\\"%s\\\\\"\"' % atlas_version))\n info = atlas_info\n else:\n warnings.warn(AtlasNotFoundError.__doc__)\n need_blas = 1\n dict_append(info,define_macros=[('NO_ATLAS_INFO',1)])\n\n if need_blas:\n blas_info = get_info('blas')\n if blas_info:\n dict_append(info,**blas_info)\n else:\n warnings.warn(BlasNotFoundError.__doc__)\n blas_src_info = get_info('blas_src')\n if not blas_src_info:\n warnings.warn(BlasSrcNotFoundError.__doc__)\n return\n dict_append(info,libraries=[('fblas_src',blas_src_info)])\n\n self.set_info(**info)\n return\n\n\nclass blas_info(system_info):\n section = 'blas'\n dir_env_var = 'BLAS'\n _lib_names = ['blas']\n notfounderror = BlasNotFoundError\n\n def calc_info(self):\n lib_dirs = self.get_lib_dirs()\n\n blas_libs = self.get_libs('blas_libs', self._lib_names)\n for d in lib_dirs:\n blas = self.check_libs(d,blas_libs,[])\n if blas is not None:\n info = blas \n break\n else:\n return\n info['language'] = 'f77' # XXX: is it generally true?\n self.set_info(**info)\n\n\nclass blas_src_info(system_info):\n section = 'blas_src'\n dir_env_var = 'BLAS_SRC'\n notfounderror = BlasSrcNotFoundError\n\n def get_paths(self, section, key):\n pre_dirs = system_info.get_paths(self, section, key)\n dirs = []\n for d in pre_dirs:\n dirs.extend([d] + self.combine_paths(d,['blas']))\n return [ d for d in dirs if os.path.isdir(d) ]\n\n def calc_info(self):\n src_dirs = self.get_src_dirs()\n src_dir = ''\n for d in src_dirs:\n if os.path.isfile(os.path.join(d,'daxpy.f')):\n src_dir = d\n break\n if not src_dir:\n #XXX: Get sources from netlib. May be ask first.\n return\n blas1 = '''\n caxpy csscal dnrm2 dzasum saxpy srotg zdotc ccopy cswap drot\n dznrm2 scasum srotm zdotu cdotc dasum drotg icamax scnrm2\n srotmg zdrot cdotu daxpy drotm idamax scopy sscal zdscal crotg\n dcabs1 drotmg isamax sdot sswap zrotg cscal dcopy dscal izamax\n snrm2 zaxpy zscal csrot ddot dswap sasum srot zcopy zswap\n '''\n blas2 = '''\n cgbmv chpmv ctrsv dsymv dtrsv sspr2 strmv zhemv ztpmv cgemv\n chpr dgbmv dsyr lsame ssymv strsv zher ztpsv cgerc chpr2 dgemv\n dsyr2 sgbmv ssyr xerbla zher2 ztrmv cgeru ctbmv dger dtbmv\n sgemv ssyr2 zgbmv zhpmv ztrsv chbmv ctbsv dsbmv dtbsv sger\n stbmv zgemv zhpr chemv ctpmv dspmv dtpmv ssbmv stbsv zgerc\n zhpr2 cher ctpsv dspr dtpsv sspmv stpmv zgeru ztbmv cher2\n ctrmv dspr2 dtrmv sspr stpsv zhbmv ztbsv\n '''\n blas3 = '''\n cgemm csymm ctrsm dsyrk sgemm strmm zhemm zsyr2k chemm csyr2k\n dgemm dtrmm ssymm strsm zher2k zsyrk cher2k csyrk dsymm dtrsm\n ssyr2k zherk ztrmm cherk ctrmm dsyr2k ssyrk zgemm zsymm ztrsm\n '''\n sources = [os.path.join(src_dir,f+'.f') \\\n for f in (blas1+blas2+blas3).split()]\n #XXX: should we check here actual existence of source files?\n info = {'sources':sources,'language':'f77'}\n self.set_info(**info)\n\nclass x11_info(system_info):\n section = 'x11'\n notfounderror = X11NotFoundError\n\n def __init__(self):\n system_info.__init__(self,\n default_lib_dirs=default_x11_lib_dirs,\n default_include_dirs=default_x11_include_dirs)\n\n def calc_info(self):\n if sys.platform in ['win32']:\n return\n lib_dirs = self.get_lib_dirs()\n include_dirs = self.get_include_dirs()\n x11_libs = self.get_libs('x11_libs', ['X11'])\n for lib_dir in lib_dirs:\n info = self.check_libs(lib_dir, x11_libs, [])\n if info is not None:\n break\n else:\n return\n inc_dir = None\n for d in include_dirs:\n if self.combine_paths(d, 'X11/X.h'):\n inc_dir = d\n break\n if inc_dir is not None:\n dict_append(info, include_dirs=[inc_dir])\n self.set_info(**info)\n\nclass numpy_info(system_info):\n section = 'numpy'\n modulename = 'Numeric'\n notfounderror = NumericNotFoundError\n\n def __init__(self):\n from distutils.sysconfig import get_python_inc\n include_dirs = []\n try:\n module = __import__(self.modulename)\n prefix = []\n for name in module.__file__.split(os.sep):\n if name=='lib':\n break\n prefix.append(name)\n include_dirs.append(get_python_inc(prefix=os.sep.join(prefix)))\n except ImportError:\n pass\n py_incl_dir = get_python_inc()\n include_dirs.append(py_incl_dir)\n for d in default_include_dirs:\n d = os.path.join(d, os.path.basename(py_incl_dir))\n if d not in include_dirs:\n include_dirs.append(d)\n system_info.__init__(self,\n default_lib_dirs=[],\n default_include_dirs=include_dirs)\n\n def calc_info(self):\n try:\n module = __import__(self.modulename)\n except ImportError:\n return\n info = {}\n macros = [(self.modulename.upper()+'_VERSION',\n '\"\\\\\"%s\\\\\"\"' % (module.__version__))]\n## try:\n## macros.append(\n## (self.modulename.upper()+'_VERSION_HEX',\n## hex(vstr2hex(module.__version__))),\n## )\n## except Exception,msg:\n## print msg\n dict_append(info, define_macros = macros)\n include_dirs = self.get_include_dirs()\n inc_dir = None\n for d in include_dirs:\n if self.combine_paths(d,\n os.path.join(self.modulename,\n 'arrayobject.h')):\n inc_dir = d\n break\n if inc_dir is not None:\n dict_append(info, include_dirs=[inc_dir])\n if info:\n self.set_info(**info)\n return\n\nclass numarray_info(numpy_info):\n section = 'numarray'\n modulename = 'numarray'\n\nclass boost_python_info(system_info):\n section = 'boost_python'\n dir_env_var = 'BOOST'\n\n def get_paths(self, section, key):\n pre_dirs = system_info.get_paths(self, section, key)\n dirs = []\n for d in pre_dirs:\n dirs.extend([d] + self.combine_paths(d,['boost*']))\n return [ d for d in dirs if os.path.isdir(d) ]\n\n def calc_info(self):\n from distutils.sysconfig import get_python_inc\n src_dirs = self.get_src_dirs()\n src_dir = ''\n for d in src_dirs:\n if os.path.isfile(os.path.join(d,'libs','python','src','module.cpp')):\n src_dir = d\n break\n if not src_dir:\n return\n py_incl_dir = get_python_inc()\n srcs_dir = os.path.join(src_dir,'libs','python','src')\n bpl_srcs = glob(os.path.join(srcs_dir,'*.cpp'))\n bpl_srcs += glob(os.path.join(srcs_dir,'*','*.cpp'))\n info = {'libraries':[('boost_python_src',{'include_dirs':[src_dir,py_incl_dir],\n 'sources':bpl_srcs})],\n 'include_dirs':[src_dir],\n }\n if info:\n self.set_info(**info)\n return\n\nclass agg2_info(system_info):\n section = 'agg2'\n dir_env_var = 'AGG2'\n\n def get_paths(self, section, key):\n pre_dirs = system_info.get_paths(self, section, key)\n dirs = []\n for d in pre_dirs:\n dirs.extend([d] + self.combine_paths(d,['agg2*']))\n return [ d for d in dirs if os.path.isdir(d) ]\n\n def calc_info(self):\n src_dirs = self.get_src_dirs()\n src_dir = ''\n for d in src_dirs:\n if os.path.isfile(os.path.join(d,'src','agg_affine_matrix.cpp')):\n src_dir = d\n break\n if not src_dir:\n return\n if sys.platform=='win32':\n agg2_srcs = glob(os.path.join(src_dir,'src','platform','win32','agg_win32_bmp.cpp'))\n else:\n agg2_srcs = glob(os.path.join(src_dir,'src','*.cpp'))\n agg2_srcs += [os.path.join(src_dir,'src','platform','X11','agg_platform_support.cpp')]\n \n info = {'libraries':[('agg2_src',{'sources':agg2_srcs,\n 'include_dirs':[os.path.join(src_dir,'include')],\n })],\n 'include_dirs':[os.path.join(src_dir,'include')],\n }\n if info:\n self.set_info(**info)\n return\n\nclass _pkg_config_info(system_info):\n section = None\n config_env_var = 'PKG_CONFIG'\n default_config_exe = 'pkg-config'\n append_config_exe = ''\n version_macro_name = None\n release_macro_name = None\n version_flag = '--modversion'\n cflags_flag = '--cflags'\n\n def get_config_exe(self):\n if os.environ.has_key(self.config_env_var):\n return os.environ[self.config_env_var]\n return self.default_config_exe\n def get_config_output(self, config_exe, option):\n s,o = exec_command(config_exe+' '+self.append_config_exe+' '+option,use_tee=0)\n if not s:\n return o\n\n def calc_info(self):\n config_exe = find_executable(self.get_config_exe())\n if not os.path.isfile(config_exe):\n print 'File not found: %s. Cannot determine %s info.' \\\n % (config_exe, self.section)\n return\n info = {}\n macros = []\n libraries = []\n library_dirs = []\n include_dirs = []\n extra_link_args = []\n extra_compile_args = []\n version = self.get_config_output(config_exe,self.version_flag)\n if version:\n macros.append((self.__class__.__name__.split('.')[-1].upper(),\n '\"\\\\\"%s\\\\\"\"' % (version)))\n if self.version_macro_name:\n macros.append((self.version_macro_name+'_%s' % (version.replace('.','_')),None))\n if self.release_macro_name:\n release = self.get_config_output(config_exe,'--release')\n if release:\n macros.append((self.release_macro_name+'_%s' % (release.replace('.','_')),None))\n opts = self.get_config_output(config_exe,'--libs')\n if opts:\n for opt in opts.split():\n if opt[:2]=='-l':\n libraries.append(opt[2:])\n elif opt[:2]=='-L':\n library_dirs.append(opt[2:])\n else:\n extra_link_args.append(opt)\n opts = self.get_config_output(config_exe,self.cflags_flag)\n if opts:\n for opt in opts.split():\n if opt[:2]=='-I':\n include_dirs.append(opt[2:])\n elif opt[:2]=='-D':\n if '=' in opt:\n n,v = opt[2:].split('=')\n macros.append((n,v))\n else:\n macros.append((opt[2:],None))\n else:\n extra_compile_args.append(opt)\n if macros: dict_append(info, define_macros = macros)\n if libraries: dict_append(info, libraries = libraries)\n if library_dirs: dict_append(info, library_dirs = library_dirs)\n if include_dirs: dict_append(info, include_dirs = include_dirs)\n if extra_link_args: dict_append(info, extra_link_args = extra_link_args)\n if extra_compile_args: dict_append(info, extra_compile_args = extra_compile_args)\n if info:\n self.set_info(**info)\n return\n\nclass wx_info(_pkg_config_info):\n section = 'wx'\n config_env_var = 'WX_CONFIG'\n default_config_exe = 'wx-config'\n append_config_exe = ''\n version_macro_name = 'WX_VERSION'\n release_macro_name = 'WX_RELEASE'\n version_flag = '--version'\n cflags_flag = '--cxxflags'\n\nclass gdk_pixbuf_xlib_2_info(_pkg_config_info):\n section = 'gdk_pixbuf_xlib_2'\n append_config_exe = 'gdk-pixbuf-xlib-2.0'\n version_macro_name = 'GDK_PIXBUF_XLIB_VERSION'\n\nclass gdk_pixbuf_2_info(_pkg_config_info):\n section = 'gdk_pixbuf_2'\n append_config_exe = 'gdk-pixbuf-2.0'\n version_macro_name = 'GDK_PIXBUF_VERSION'\n\nclass gdk_x11_2_info(_pkg_config_info):\n section = 'gdk_x11_2'\n append_config_exe = 'gdk-x11-2.0'\n version_macro_name = 'GDK_X11_VERSION'\n\nclass gdk_2_info(_pkg_config_info):\n section = 'gdk_2'\n append_config_exe = 'gdk-2.0'\n version_macro_name = 'GDK_VERSION'\n\nclass gdk_info(_pkg_config_info):\n section = 'gdk'\n append_config_exe = 'gdk'\n version_macro_name = 'GDK_VERSION'\n\nclass gtkp_x11_2_info(_pkg_config_info):\n section = 'gtkp_x11_2'\n append_config_exe = 'gtk+-x11-2.0'\n version_macro_name = 'GTK_X11_VERSION'\n\n\nclass gtkp_2_info(_pkg_config_info):\n section = 'gtkp_2'\n append_config_exe = 'gtk+-2.0'\n version_macro_name = 'GTK_VERSION'\n\nclass xft_info(_pkg_config_info):\n section = 'xft'\n append_config_exe = 'xft'\n version_macro_name = 'XFT_VERSION'\n\nclass freetype2_info(_pkg_config_info):\n section = 'freetype2'\n append_config_exe = 'freetype2'\n version_macro_name = 'FREETYPE2_VERSION'\n\n## def vstr2hex(version):\n## bits = []\n## n = [24,16,8,4,0]\n## r = 0\n## for s in version.split('.'):\n## r |= int(s) << n[0]\n## del n[0]\n## return r\n\n#--------------------------------------------------------------------\n\ndef combine_paths(*args,**kws):\n \"\"\" Return a list of existing paths composed by all combinations of\n items from arguments.\n \"\"\"\n r = []\n for a in args:\n if not a: continue\n if type(a) is types.StringType:\n a = [a]\n r.append(a)\n args = r\n if not args: return []\n if len(args)==1:\n result = reduce(lambda a,b:a+b,map(glob,args[0]),[])\n elif len (args)==2:\n result = []\n for a0 in args[0]:\n for a1 in args[1]:\n result.extend(glob(os.path.join(a0,a1)))\n else:\n result = combine_paths(*(combine_paths(args[0],args[1])+args[2:]))\n verbosity = kws.get('verbosity',1)\n if verbosity>1 and result:\n print '(','paths:',','.join(result),')'\n return result\n\nlanguage_map = {'c':0,'c++':1,'f77':2,'f90':3}\ninv_language_map = {0:'c',1:'c++',2:'f77',3:'f90'}\ndef dict_append(d,**kws):\n languages = []\n for k,v in kws.items():\n if k=='language':\n languages.append(v)\n continue\n if d.has_key(k):\n if k in ['library_dirs','include_dirs','define_macros']:\n [d[k].append(vv) for vv in v if vv not in d[k]]\n else:\n d[k].extend(v)\n else:\n d[k] = v\n if languages:\n l = inv_language_map[max([language_map.get(l,0) for l in languages])]\n d['language'] = l\n return\n\ndef show_all():\n import system_info\n import pprint\n match_info = re.compile(r'.*?_info').match\n show_only = []\n for n in sys.argv[1:]:\n if n[-5:] != '_info':\n n = n + '_info'\n show_only.append(n)\n show_all = not show_only\n for n in filter(match_info,dir(system_info)):\n if n in ['system_info','get_info']: continue\n if not show_all:\n if n not in show_only: continue\n del show_only[show_only.index(n)]\n c = getattr(system_info,n)()\n c.verbosity = 2\n r = c.get_info()\n if show_only:\n print 'Info classes not defined:',','.join(show_only)\nif __name__ == \"__main__\":\n show_all()\n", "source_code_before": "#!/usr/bin/env python\n\"\"\"\nThis file defines a set of system_info classes for getting\ninformation about various resources (libraries, library directories,\ninclude directories, etc.) in the system. Currently, the following\nclasses are available:\n\n atlas_info\n atlas_threads_info\n atlas_blas_info\n atlas_blas_threads_info\n lapack_atlas_info\n blas_info\n lapack_info\n blas_opt_info # usage recommended\n lapack_opt_info # usage recommended\n fftw_info,dfftw_info,sfftw_info\n fftw_threads_info,dfftw_threads_info,sfftw_threads_info\n djbfft_info\n x11_info\n lapack_src_info\n blas_src_info\n numpy_info\n numarray_info\n boost_python_info\n agg2_info\n wx_info\n gdk_pixbuf_xlib_2_info\n gdk_pixbuf_2_info\n gdk_x11_2_info\n gtkp_x11_2_info\n gtkp_2_info\n xft_info\n freetype2_info\n\nUsage:\n info_dict = get_info()\n where is a string 'atlas','x11','fftw','lapack','blas',\n 'lapack_src', 'blas_src', etc. For a complete list of allowed names,\n see the definition of get_info() function below.\n\n Returned info_dict is a dictionary which is compatible with\n distutils.setup keyword arguments. If info_dict == {}, then the\n asked resource is not available (system_info could not find it).\n\n Several *_info classes specify an environment variable to specify\n the locations of software. When setting the corresponding environment\n variable to 'None' then the software will be ignored, even when it\n is available in system.\n\nGlobal parameters:\n system_info.search_static_first - search static libraries (.a)\n in precedence to shared ones (.so, .sl) if enabled.\n system_info.verbosity - output the results to stdout if enabled.\n\nThe file 'site.cfg' in the same directory as this module is read\nfor configuration options. The format is that used by ConfigParser (i.e.,\nWindows .INI style). The section DEFAULT has options that are the default\nfor each section. The available sections are fftw, atlas, and x11. Appropiate\ndefaults are used if nothing is specified.\n\nThe order of finding the locations of resources is the following:\n 1. environment variable\n 2. section in site.cfg\n 3. DEFAULT section in site.cfg\nOnly the first complete match is returned.\n\nExample:\n----------\n[DEFAULT]\nlibrary_dirs = /usr/lib:/usr/local/lib:/opt/lib\ninclude_dirs = /usr/include:/usr/local/include:/opt/include\nsrc_dirs = /usr/local/src:/opt/src\n# search static libraries (.a) in preference to shared ones (.so)\nsearch_static_first = 0\n\n[fftw]\nfftw_libs = rfftw, fftw\nfftw_opt_libs = rfftw_threaded, fftw_threaded\n# if the above aren't found, look for {s,d}fftw_libs and {s,d}fftw_opt_libs\n\n[atlas]\nlibrary_dirs = /usr/lib/3dnow:/usr/lib/3dnow/atlas\n# for overriding the names of the atlas libraries\natlas_libs = lapack, f77blas, cblas, atlas\n\n[x11]\nlibrary_dirs = /usr/X11R6/lib\ninclude_dirs = /usr/X11R6/include\n----------\n\nAuthors:\n Pearu Peterson , February 2002\n David M. Cooke , April 2002\n\nCopyright 2002 Pearu Peterson all rights reserved,\nPearu Peterson \nPermission to use, modify, and distribute this software is given under the \nterms of the SciPy (BSD style) license. See LICENSE.txt that came with\nthis distribution for specifics.\n\nNO WARRANTY IS EXPRESSED OR IMPLIED. USE AT YOUR OWN RISK.\n\"\"\"\n\n__revision__ = '$Id$'\n\nimport sys,os,re,types\nimport warnings\nfrom distutils.errors import DistutilsError\nfrom glob import glob\nimport ConfigParser\nfrom exec_command import find_executable, exec_command\n\nfrom distutils.sysconfig import get_config_vars\n\nif sys.platform == 'win32':\n default_lib_dirs = ['C:\\\\'] # probably not very helpful...\n default_include_dirs = []\n default_src_dirs = ['.']\n default_x11_lib_dirs = []\n default_x11_include_dirs = []\nelse:\n default_lib_dirs = ['/usr/local/lib', '/opt/lib', '/usr/lib',\n '/sw/lib']\n default_include_dirs = ['/usr/local/include',\n '/opt/include', '/usr/include',\n '/sw/include']\n default_src_dirs = ['.','/usr/local/src', '/opt/src','/sw/src']\n default_x11_lib_dirs = ['/usr/X11R6/lib','/usr/X11/lib','/usr/lib']\n default_x11_include_dirs = ['/usr/X11R6/include','/usr/X11/include',\n '/usr/include']\n\nif os.path.join(sys.prefix, 'lib') not in default_lib_dirs:\n default_lib_dirs.insert(0,os.path.join(sys.prefix, 'lib'))\n default_include_dirs.append(os.path.join(sys.prefix, 'include'))\n default_src_dirs.append(os.path.join(sys.prefix, 'src'))\n\ndefault_lib_dirs = filter(os.path.isdir, default_lib_dirs)\ndefault_include_dirs = filter(os.path.isdir, default_include_dirs)\ndefault_src_dirs = filter(os.path.isdir, default_src_dirs)\n\nso_ext = get_config_vars('SO')[0] or ''\n\ndef get_info(name,notfound_action=0):\n \"\"\"\n notfound_action:\n 0 - do nothing\n 1 - display warning message\n 2 - raise error\n \"\"\"\n cl = {'atlas':atlas_info, # use lapack_opt or blas_opt instead\n 'atlas_threads':atlas_threads_info, # ditto\n 'atlas_blas':atlas_blas_info,\n 'atlas_blas_threads':atlas_blas_threads_info,\n 'lapack_atlas':lapack_atlas_info, # use lapack_opt instead\n 'lapack_atlas_threads':lapack_atlas_threads_info, # ditto\n 'x11':x11_info,\n 'fftw':fftw_info,\n 'dfftw':dfftw_info,\n 'sfftw':sfftw_info,\n 'fftw_threads':fftw_threads_info,\n 'dfftw_threads':dfftw_threads_info,\n 'sfftw_threads':sfftw_threads_info,\n 'djbfft':djbfft_info,\n 'blas':blas_info, # use blas_opt instead\n 'lapack':lapack_info, # use lapack_opt instead\n 'lapack_src':lapack_src_info,\n 'blas_src':blas_src_info,\n 'numpy':numpy_info,\n 'numarray':numarray_info,\n 'lapack_opt':lapack_opt_info,\n 'blas_opt':blas_opt_info,\n 'boost_python':boost_python_info,\n 'agg2':agg2_info,\n 'wx':wx_info,\n 'gdk_pixbuf_xlib_2':gdk_pixbuf_xlib_2_info,\n 'gdk-pixbuf-xlib-2.0':gdk_pixbuf_xlib_2_info,\n 'gdk_pixbuf_2':gdk_pixbuf_2_info,\n 'gdk-pixbuf-2.0':gdk_pixbuf_2_info,\n 'gdk':gdk_info,\n 'gdk_2':gdk_2_info,\n 'gdk-2.0':gdk_2_info,\n 'gdk_x11_2':gdk_x11_2_info,\n 'gdk-x11-2.0':gdk_x11_2_info,\n 'gtkp_x11_2':gtkp_x11_2_info,\n 'gtk+-x11-2.0':gtkp_x11_2_info,\n 'gtkp_2':gtkp_2_info,\n 'gtk+-2.0':gtkp_2_info,\n 'xft':xft_info,\n 'freetype2':freetype2_info,\n }.get(name.lower(),system_info)\n return cl().get_info(notfound_action)\n\nclass NotFoundError(DistutilsError):\n \"\"\"Some third-party program or library is not found.\"\"\"\n\nclass AtlasNotFoundError(NotFoundError):\n \"\"\"\n Atlas (http://math-atlas.sourceforge.net/) libraries not found.\n Directories to search for the libraries can be specified in the\n scipy_distutils/site.cfg file (section [atlas]) or by setting\n the ATLAS environment variable.\"\"\"\n\nclass LapackNotFoundError(NotFoundError):\n \"\"\"\n Lapack (http://www.netlib.org/lapack/) libraries not found.\n Directories to search for the libraries can be specified in the\n scipy_distutils/site.cfg file (section [lapack]) or by setting\n the LAPACK environment variable.\"\"\"\n\nclass LapackSrcNotFoundError(LapackNotFoundError):\n \"\"\"\n Lapack (http://www.netlib.org/lapack/) sources not found.\n Directories to search for the sources can be specified in the\n scipy_distutils/site.cfg file (section [lapack_src]) or by setting\n the LAPACK_SRC environment variable.\"\"\"\n\nclass BlasNotFoundError(NotFoundError):\n \"\"\"\n Blas (http://www.netlib.org/blas/) libraries not found.\n Directories to search for the libraries can be specified in the\n scipy_distutils/site.cfg file (section [blas]) or by setting\n the BLAS environment variable.\"\"\"\n\nclass BlasSrcNotFoundError(BlasNotFoundError):\n \"\"\"\n Blas (http://www.netlib.org/blas/) sources not found.\n Directories to search for the sources can be specified in the\n scipy_distutils/site.cfg file (section [blas_src]) or by setting\n the BLAS_SRC environment variable.\"\"\"\n\nclass FFTWNotFoundError(NotFoundError):\n \"\"\"\n FFTW (http://www.fftw.org/) libraries not found.\n Directories to search for the libraries can be specified in the\n scipy_distutils/site.cfg file (section [fftw]) or by setting\n the FFTW environment variable.\"\"\"\n\nclass DJBFFTNotFoundError(NotFoundError):\n \"\"\"\n DJBFFT (http://cr.yp.to/djbfft.html) libraries not found.\n Directories to search for the libraries can be specified in the\n scipy_distutils/site.cfg file (section [djbfft]) or by setting\n the DJBFFT environment variable.\"\"\"\n\nclass F2pyNotFoundError(NotFoundError):\n \"\"\"\n f2py2e (http://cens.ioc.ee/projects/f2py2e/) module not found.\n Get it from above location, install it, and retry setup.py.\"\"\"\n\nclass NumericNotFoundError(NotFoundError):\n \"\"\"\n Numeric (http://www.numpy.org/) module not found.\n Get it from above location, install it, and retry setup.py.\"\"\"\n\nclass X11NotFoundError(NotFoundError):\n \"\"\"X11 libraries not found.\"\"\"\n\nclass system_info:\n\n \"\"\" get_info() is the only public method. Don't use others.\n \"\"\"\n section = 'DEFAULT'\n dir_env_var = None\n search_static_first = 0 # XXX: disabled by default, may disappear in\n # future unless it is proved to be useful.\n verbosity = 1\n saved_results = {}\n\n notfounderror = NotFoundError\n\n def __init__ (self,\n default_lib_dirs=default_lib_dirs,\n default_include_dirs=default_include_dirs,\n verbosity = 1,\n ):\n self.__class__.info = {}\n self.local_prefixes = []\n defaults = {}\n defaults['libraries'] = ''\n defaults['library_dirs'] = os.pathsep.join(default_lib_dirs)\n defaults['include_dirs'] = os.pathsep.join(default_include_dirs)\n defaults['src_dirs'] = os.pathsep.join(default_src_dirs)\n defaults['search_static_first'] = str(self.search_static_first)\n self.cp = ConfigParser.ConfigParser(defaults)\n try:\n __file__\n except NameError:\n __file__ = sys.argv[0]\n cf = os.path.join(os.path.split(os.path.abspath(__file__))[0],\n 'site.cfg')\n self.cp.read([cf])\n if not self.cp.has_section(self.section):\n self.cp.add_section(self.section)\n self.search_static_first = self.cp.getboolean(self.section,\n 'search_static_first')\n assert isinstance(self.search_static_first, type(0))\n\n def calc_libraries_info(self):\n libs = self.get_libraries()\n dirs = self.get_lib_dirs()\n info = {}\n for lib in libs:\n i = None\n for d in dirs:\n i = self.check_libs(d,[lib]) \n if i is not None:\n break\n if i is not None:\n dict_append(info,**i)\n else:\n print 'Library %s was not found. Ignoring' % (lib)\n return info\n\n def set_info(self,**info):\n if info: \n lib_info = self.calc_libraries_info()\n dict_append(info,**lib_info)\n self.saved_results[self.__class__.__name__] = info\n\n def has_info(self):\n return self.saved_results.has_key(self.__class__.__name__)\n\n def get_info(self,notfound_action=0):\n \"\"\" Return a dictonary with items that are compatible\n with scipy_distutils.setup keyword arguments.\n \"\"\"\n flag = 0\n if not self.has_info():\n flag = 1\n if self.verbosity>0:\n print self.__class__.__name__ + ':'\n if hasattr(self, 'calc_info'):\n self.calc_info()\n if notfound_action:\n if not self.has_info():\n if notfound_action==1:\n warnings.warn(self.notfounderror.__doc__)\n elif notfound_action==2:\n raise self.notfounderror,self.notfounderror.__doc__\n else:\n raise ValueError,`notfound_action`\n\n if self.verbosity>0:\n if not self.has_info():\n print ' NOT AVAILABLE'\n self.set_info()\n else:\n print ' FOUND:'\n \n res = self.saved_results.get(self.__class__.__name__)\n if self.verbosity>0 and flag:\n for k,v in res.items():\n v = str(v)\n if k=='sources' and len(v)>200: v = v[:60]+' ...\\n... '+v[-60:]\n print ' %s = %s'%(k,v)\n print\n \n return res\n\n def get_paths(self, section, key):\n dirs = self.cp.get(section, key).split(os.pathsep)\n env_var = self.dir_env_var\n if env_var:\n if type(env_var) is type([]):\n e0 = env_var[-1]\n for e in env_var:\n if os.environ.has_key(e):\n e0 = e\n break\n if not env_var[0]==e0:\n print 'Setting %s=%s' % (env_var[0],e0)\n env_var = e0\n if env_var and os.environ.has_key(env_var):\n d = os.environ[env_var]\n if d=='None':\n print 'Disabled',self.__class__.__name__,'(%s is None)' \\\n % (self.dir_env_var)\n return []\n if os.path.isfile(d):\n dirs = [os.path.dirname(d)] + dirs\n l = getattr(self,'_lib_names',[])\n if len(l)==1:\n b = os.path.basename(d)\n b = os.path.splitext(b)[0]\n if b[:3]=='lib':\n print 'Replacing _lib_names[0]==%r with %r' \\\n % (self._lib_names[0], b[3:])\n self._lib_names[0] = b[3:]\n else:\n ds = d.split(os.pathsep)\n ds2 = []\n for d in ds:\n if os.path.isdir(d):\n ds2.append(d)\n for dd in ['include','lib']:\n d1 = os.path.join(d,dd)\n if os.path.isdir(d1):\n ds2.append(d1)\n dirs = ds2 + dirs\n default_dirs = self.cp.get('DEFAULT', key).split(os.pathsep)\n dirs.extend(default_dirs)\n ret = []\n [ret.append(d) for d in dirs if os.path.isdir(d) and d not in ret]\n if self.verbosity>1:\n print '(',key,'=',':'.join(ret),')'\n return ret\n\n def get_lib_dirs(self, key='library_dirs'):\n return self.get_paths(self.section, key)\n\n def get_include_dirs(self, key='include_dirs'):\n return self.get_paths(self.section, key)\n\n def get_src_dirs(self, key='src_dirs'):\n return self.get_paths(self.section, key)\n\n def get_libs(self, key, default):\n try:\n libs = self.cp.get(self.section, key)\n except ConfigParser.NoOptionError:\n if not default:\n return []\n if type(default) is type(''):\n return [default]\n return default\n return [b for b in [a.strip() for a in libs.split(',')] if b]\n\n def get_libraries(self, key='libraries'):\n return self.get_libs(key,'')\n\n def check_libs(self,lib_dir,libs,opt_libs =[]):\n \"\"\" If static or shared libraries are available then return\n their info dictionary. \"\"\"\n if self.search_static_first:\n exts = ['.a',so_ext]\n else:\n exts = [so_ext,'.a']\n if sys.platform=='cygwin':\n exts.append('.dll.a')\n for ext in exts:\n info = self._check_libs(lib_dir,libs,opt_libs,ext)\n if info is not None: return info\n return\n\n def _lib_list(self, lib_dir, libs, ext):\n assert type(lib_dir) is type('')\n liblist = []\n for l in libs:\n p = self.combine_paths(lib_dir, 'lib'+l+ext)\n if p:\n assert len(p)==1\n liblist.append(p[0])\n return liblist\n\n def _extract_lib_names(self,libs):\n return [os.path.splitext(os.path.basename(p))[0][3:] \\\n for p in libs]\n\n def _check_libs(self,lib_dir,libs, opt_libs, ext):\n found_libs = self._lib_list(lib_dir, libs, ext)\n if len(found_libs) == len(libs):\n found_libs = self._extract_lib_names(found_libs)\n info = {'libraries' : found_libs, 'library_dirs' : [lib_dir]}\n opt_found_libs = self._lib_list(lib_dir, opt_libs, ext)\n if len(opt_found_libs) == len(opt_libs):\n opt_found_libs = self._extract_lib_names(opt_found_libs)\n info['libraries'].extend(opt_found_libs)\n return info\n\n def combine_paths(self,*args):\n return combine_paths(*args,**{'verbosity':self.verbosity})\n\nclass fftw_info(system_info):\n section = 'fftw'\n dir_env_var = 'FFTW'\n libs = ['rfftw', 'fftw']\n includes = ['fftw.h','rfftw.h']\n macros = [('SCIPY_FFTW_H',None)]\n notfounderror = FFTWNotFoundError\n\n def __init__(self):\n system_info.__init__(self)\n\n def calc_info(self):\n lib_dirs = self.get_lib_dirs()\n incl_dirs = self.get_include_dirs()\n incl_dir = None\n libs = self.get_libs(self.section+'_libs', self.libs)\n info = None\n for d in lib_dirs:\n r = self.check_libs(d,libs)\n if r is not None:\n info = r\n break\n if info is not None:\n flag = 0\n for d in incl_dirs:\n if len(self.combine_paths(d,self.includes))==2:\n dict_append(info,include_dirs=[d])\n flag = 1\n incl_dirs = [d]\n incl_dir = d\n break\n if flag:\n dict_append(info,define_macros=self.macros)\n else:\n info = None\n if info is not None:\n self.set_info(**info)\n\nclass dfftw_info(fftw_info):\n section = 'fftw'\n dir_env_var = 'FFTW'\n libs = ['drfftw','dfftw']\n includes = ['dfftw.h','drfftw.h']\n macros = [('SCIPY_DFFTW_H',None)]\n\nclass sfftw_info(fftw_info):\n section = 'fftw'\n dir_env_var = 'FFTW'\n libs = ['srfftw','sfftw']\n includes = ['sfftw.h','srfftw.h']\n macros = [('SCIPY_SFFTW_H',None)]\n\nclass fftw_threads_info(fftw_info):\n section = 'fftw'\n dir_env_var = 'FFTW'\n libs = ['rfftw_threads','fftw_threads']\n includes = ['fftw_threads.h','rfftw_threads.h']\n macros = [('SCIPY_FFTW_THREADS_H',None)]\n\nclass dfftw_threads_info(fftw_info):\n section = 'fftw'\n dir_env_var = 'FFTW'\n libs = ['drfftw_threads','dfftw_threads']\n includes = ['dfftw_threads.h','drfftw_threads.h']\n macros = [('SCIPY_DFFTW_THREADS_H',None)]\n\nclass sfftw_threads_info(fftw_info):\n section = 'fftw'\n dir_env_var = 'FFTW'\n libs = ['srfftw_threads','sfftw_threads']\n includes = ['sfftw_threads.h','srfftw_threads.h']\n macros = [('SCIPY_SFFTW_THREADS_H',None)]\n\nclass djbfft_info(system_info):\n section = 'djbfft'\n dir_env_var = 'DJBFFT'\n notfounderror = DJBFFTNotFoundError\n\n def get_paths(self, section, key):\n pre_dirs = system_info.get_paths(self, section, key)\n dirs = []\n for d in pre_dirs:\n dirs.extend(self.combine_paths(d,['djbfft'])+[d])\n return [ d for d in dirs if os.path.isdir(d) ]\n\n def calc_info(self):\n lib_dirs = self.get_lib_dirs()\n incl_dirs = self.get_include_dirs()\n info = None\n for d in lib_dirs:\n p = self.combine_paths (d,['djbfft.a'])\n if p:\n info = {'extra_objects':p}\n break\n p = self.combine_paths (d,['libdjbfft.a'])\n if p:\n info = {'libraries':['djbfft'],'library_dirs':[d]}\n break\n if info is None:\n return\n for d in incl_dirs:\n if len(self.combine_paths(d,['fftc8.h','fftfreq.h']))==2:\n dict_append(info,include_dirs=[d],\n define_macros=[('SCIPY_DJBFFT_H',None)])\n self.set_info(**info)\n return\n return\n\nclass atlas_info(system_info):\n section = 'atlas'\n dir_env_var = 'ATLAS'\n _lib_names = ['f77blas','cblas']\n if sys.platform[:7]=='freebsd':\n _lib_atlas = ['atlas_r']\n _lib_lapack = ['alapack_r']\n else:\n _lib_atlas = ['atlas']\n _lib_lapack = ['lapack']\n\n notfounderror = AtlasNotFoundError\n\n def get_paths(self, section, key):\n pre_dirs = system_info.get_paths(self, section, key)\n dirs = []\n for d in pre_dirs:\n dirs.extend(self.combine_paths(d,['atlas*','ATLAS*',\n 'sse','3dnow','sse2'])+[d])\n return [ d for d in dirs if os.path.isdir(d) ]\n\n def calc_info(self):\n lib_dirs = self.get_lib_dirs()\n info = {}\n atlas_libs = self.get_libs('atlas_libs',\n self._lib_names + self._lib_atlas)\n lapack_libs = self.get_libs('lapack_libs',self._lib_lapack)\n atlas = None\n lapack = None\n atlas_1 = None\n for d in lib_dirs:\n atlas = self.check_libs(d,atlas_libs,[])\n lapack_atlas = self.check_libs(d,['lapack_atlas'],[])\n if atlas is not None:\n lib_dirs2 = self.combine_paths(d,['atlas*','ATLAS*'])+[d]\n for d2 in lib_dirs2:\n lapack = self.check_libs(d2,lapack_libs,[])\n if lapack is not None:\n break\n else:\n lapack = None\n if lapack is not None:\n break\n if atlas:\n atlas_1 = atlas\n print self.__class__\n if atlas is None:\n atlas = atlas_1\n if atlas is None:\n return\n include_dirs = self.get_include_dirs()\n h = (self.combine_paths(lib_dirs+include_dirs,'cblas.h') or [None])[0]\n if h:\n h = os.path.dirname(h)\n dict_append(info,include_dirs=[h])\n info['language'] = 'c'\n if lapack is not None:\n dict_append(info,**lapack)\n dict_append(info,**atlas)\n elif 'lapack_atlas' in atlas['libraries']:\n dict_append(info,**atlas)\n dict_append(info,define_macros=[('ATLAS_WITH_LAPACK_ATLAS',None)])\n self.set_info(**info)\n return\n else:\n dict_append(info,**atlas)\n dict_append(info,define_macros=[('ATLAS_WITHOUT_LAPACK',None)])\n message = \"\"\"\n*********************************************************************\n Could not find lapack library within the ATLAS installation.\n*********************************************************************\n\"\"\"\n warnings.warn(message)\n self.set_info(**info)\n return\n \n # Check if lapack library is complete, only warn if it is not.\n lapack_dir = lapack['library_dirs'][0]\n lapack_name = lapack['libraries'][0]\n lapack_lib = None\n for e in ['.a',so_ext]:\n fn = os.path.join(lapack_dir,'lib'+lapack_name+e)\n if os.path.exists(fn):\n lapack_lib = fn\n break\n if lapack_lib is not None:\n sz = os.stat(lapack_lib)[6]\n if sz <= 4000*1024:\n message = \"\"\"\n*********************************************************************\n Lapack library (from ATLAS) is probably incomplete:\n size of %s is %sk (expected >4000k)\n\n Follow the instructions in the KNOWN PROBLEMS section of the file\n scipy/INSTALL.txt.\n*********************************************************************\n\"\"\" % (lapack_lib,sz/1024)\n warnings.warn(message)\n else:\n info['language'] = 'f77'\n\n self.set_info(**info)\n\nclass atlas_blas_info(atlas_info):\n _lib_names = ['f77blas','cblas']\n\n def calc_info(self):\n lib_dirs = self.get_lib_dirs()\n info = {}\n atlas_libs = self.get_libs('atlas_libs',\n self._lib_names + self._lib_atlas)\n atlas = None\n for d in lib_dirs:\n atlas = self.check_libs(d,atlas_libs,[])\n if atlas is not None:\n break\n if atlas is None:\n return\n include_dirs = self.get_include_dirs()\n h = (self.combine_paths(lib_dirs+include_dirs,'cblas.h') or [None])[0]\n if h:\n h = os.path.dirname(h)\n dict_append(info,include_dirs=[h])\n info['language'] = 'c'\n\n dict_append(info,**atlas)\n\n self.set_info(**info)\n return\n\n\nclass atlas_threads_info(atlas_info):\n dir_env_var = ['PTATLAS','ATLAS']\n _lib_names = ['ptf77blas','ptcblas']\n\nclass atlas_blas_threads_info(atlas_blas_info):\n dir_env_var = ['PTATLAS','ATLAS']\n _lib_names = ['ptf77blas','ptcblas']\n\nclass lapack_atlas_info(atlas_info):\n _lib_names = ['lapack_atlas'] + atlas_info._lib_names\n\nclass lapack_atlas_threads_info(atlas_threads_info):\n _lib_names = ['lapack_atlas'] + atlas_threads_info._lib_names\n\nclass lapack_info(system_info):\n section = 'lapack'\n dir_env_var = 'LAPACK'\n _lib_names = ['lapack']\n notfounderror = LapackNotFoundError\n\n def calc_info(self):\n lib_dirs = self.get_lib_dirs()\n\n lapack_libs = self.get_libs('lapack_libs', self._lib_names)\n for d in lib_dirs:\n lapack = self.check_libs(d,lapack_libs,[])\n if lapack is not None:\n info = lapack \n break\n else:\n return\n info['language'] = 'f77'\n self.set_info(**info)\n\nclass lapack_src_info(system_info):\n section = 'lapack_src'\n dir_env_var = 'LAPACK_SRC'\n notfounderror = LapackSrcNotFoundError\n\n def get_paths(self, section, key):\n pre_dirs = system_info.get_paths(self, section, key)\n dirs = []\n for d in pre_dirs:\n dirs.extend([d] + self.combine_paths(d,['LAPACK*/SRC','SRC']))\n return [ d for d in dirs if os.path.isdir(d) ]\n\n def calc_info(self):\n src_dirs = self.get_src_dirs()\n src_dir = ''\n for d in src_dirs:\n if os.path.isfile(os.path.join(d,'dgesv.f')):\n src_dir = d\n break\n if not src_dir:\n #XXX: Get sources from netlib. May be ask first.\n return\n # The following is extracted from LAPACK-3.0/SRC/Makefile\n allaux='''\n ilaenv ieeeck lsame lsamen xerbla\n ''' # *.f\n laux = '''\n bdsdc bdsqr disna labad lacpy ladiv lae2 laebz laed0 laed1\n laed2 laed3 laed4 laed5 laed6 laed7 laed8 laed9 laeda laev2\n lagtf lagts lamch lamrg lanst lapy2 lapy3 larnv larrb larre\n larrf lartg laruv las2 lascl lasd0 lasd1 lasd2 lasd3 lasd4\n lasd5 lasd6 lasd7 lasd8 lasd9 lasda lasdq lasdt laset lasq1\n lasq2 lasq3 lasq4 lasq5 lasq6 lasr lasrt lassq lasv2 pttrf\n stebz stedc steqr sterf\n ''' # [s|d]*.f\n lasrc = '''\n gbbrd gbcon gbequ gbrfs gbsv gbsvx gbtf2 gbtrf gbtrs gebak\n gebal gebd2 gebrd gecon geequ gees geesx geev geevx gegs gegv\n gehd2 gehrd gelq2 gelqf gels gelsd gelss gelsx gelsy geql2\n geqlf geqp3 geqpf geqr2 geqrf gerfs gerq2 gerqf gesc2 gesdd\n gesv gesvd gesvx getc2 getf2 getrf getri getrs ggbak ggbal\n gges ggesx ggev ggevx ggglm gghrd gglse ggqrf ggrqf ggsvd\n ggsvp gtcon gtrfs gtsv gtsvx gttrf gttrs gtts2 hgeqz hsein\n hseqr labrd lacon laein lags2 lagtm lahqr lahrd laic1 lals0\n lalsa lalsd langb lange langt lanhs lansb lansp lansy lantb\n lantp lantr lapll lapmt laqgb laqge laqp2 laqps laqsb laqsp\n laqsy lar1v lar2v larf larfb larfg larft larfx largv larrv\n lartv larz larzb larzt laswp lasyf latbs latdf latps latrd\n latrs latrz latzm lauu2 lauum pbcon pbequ pbrfs pbstf pbsv\n pbsvx pbtf2 pbtrf pbtrs pocon poequ porfs posv posvx potf2\n potrf potri potrs ppcon ppequ pprfs ppsv ppsvx pptrf pptri\n pptrs ptcon pteqr ptrfs ptsv ptsvx pttrs ptts2 spcon sprfs\n spsv spsvx sptrf sptri sptrs stegr stein sycon syrfs sysv\n sysvx sytf2 sytrf sytri sytrs tbcon tbrfs tbtrs tgevc tgex2\n tgexc tgsen tgsja tgsna tgsy2 tgsyl tpcon tprfs tptri tptrs\n trcon trevc trexc trrfs trsen trsna trsyl trti2 trtri trtrs\n tzrqf tzrzf\n ''' # [s|c|d|z]*.f\n sd_lasrc = '''\n laexc lag2 lagv2 laln2 lanv2 laqtr lasy2 opgtr opmtr org2l\n org2r orgbr orghr orgl2 orglq orgql orgqr orgr2 orgrq orgtr\n orm2l orm2r ormbr ormhr orml2 ormlq ormql ormqr ormr2 ormr3\n ormrq ormrz ormtr rscl sbev sbevd sbevx sbgst sbgv sbgvd sbgvx\n sbtrd spev spevd spevx spgst spgv spgvd spgvx sptrd stev stevd\n stevr stevx syev syevd syevr syevx sygs2 sygst sygv sygvd\n sygvx sytd2 sytrd\n ''' # [s|d]*.f\n cz_lasrc = '''\n bdsqr hbev hbevd hbevx hbgst hbgv hbgvd hbgvx hbtrd hecon heev\n heevd heevr heevx hegs2 hegst hegv hegvd hegvx herfs hesv\n hesvx hetd2 hetf2 hetrd hetrf hetri hetrs hpcon hpev hpevd\n hpevx hpgst hpgv hpgvd hpgvx hprfs hpsv hpsvx hptrd hptrf\n hptri hptrs lacgv lacp2 lacpy lacrm lacrt ladiv laed0 laed7\n laed8 laesy laev2 lahef lanhb lanhe lanhp lanht laqhb laqhe\n laqhp larcm larnv lartg lascl laset lasr lassq pttrf rot spmv\n spr stedc steqr symv syr ung2l ung2r ungbr unghr ungl2 unglq\n ungql ungqr ungr2 ungrq ungtr unm2l unm2r unmbr unmhr unml2\n unmlq unmql unmqr unmr2 unmr3 unmrq unmrz unmtr upgtr upmtr\n ''' # [c|z]*.f\n #######\n sclaux = laux + ' econd ' # s*.f\n dzlaux = laux + ' secnd ' # d*.f\n slasrc = lasrc + sd_lasrc # s*.f\n dlasrc = lasrc + sd_lasrc # d*.f\n clasrc = lasrc + cz_lasrc + ' srot srscl ' # c*.f\n zlasrc = lasrc + cz_lasrc + ' drot drscl ' # z*.f\n oclasrc = ' icmax1 scsum1 ' # *.f\n ozlasrc = ' izmax1 dzsum1 ' # *.f\n sources = ['s%s.f'%f for f in (sclaux+slasrc).split()] \\\n + ['d%s.f'%f for f in (dzlaux+dlasrc).split()] \\\n + ['c%s.f'%f for f in (clasrc).split()] \\\n + ['z%s.f'%f for f in (zlasrc).split()] \\\n + ['%s.f'%f for f in (allaux+oclasrc+ozlasrc).split()]\n sources = [os.path.join(src_dir,f) for f in sources]\n #XXX: should we check here actual existence of source files?\n info = {'sources':sources,'language':'f77'}\n self.set_info(**info)\n\natlas_version_c_text = r'''\n/* This file is generated from scipy_distutils/system_info.py */\n#ifdef __CPLUSPLUS__\nextern \"C\" {\n#endif\n#include \"Python.h\"\nstatic PyMethodDef module_methods[] = { {NULL,NULL} };\nDL_EXPORT(void) initatlas_version(void) {\n void ATL_buildinfo(void);\n ATL_buildinfo();\n Py_InitModule(\"atlas_version\", module_methods);\n}\n#ifdef __CPLUSCPLUS__\n}\n#endif\n'''\n\ndef get_atlas_version(**config):\n from core import Extension, setup\n from misc_util import get_build_temp\n import log\n magic = hex(hash(`config`))\n def atlas_version_c(extension, build_dir,magic=magic):\n source = os.path.join(build_dir,'atlas_version_%s.c' % (magic))\n if os.path.isfile(source):\n from distutils.dep_util import newer\n if newer(source,__file__):\n return source\n f = open(source,'w')\n f.write(atlas_version_c_text)\n f.close()\n return source\n ext = Extension('atlas_version',\n sources=[atlas_version_c],\n **config)\n extra_args = ['--build-lib',get_build_temp()]\n for a in sys.argv:\n if re.match('[-][-]compiler[=]',a):\n extra_args.append(a)\n try:\n dist = setup(ext_modules=[ext],\n script_name = 'get_atlas_version',\n script_args = ['build_src','build_ext']+extra_args)\n except Exception,msg:\n print \"##### msg: %s\" % msg\n if not msg:\n msg = \"Unknown Exception\"\n log.warn(msg)\n return None\n\n from distutils.sysconfig import get_config_var\n so_ext = get_config_var('SO')\n build_ext = dist.get_command_obj('build_ext')\n target = os.path.join(build_ext.build_lib,'atlas_version'+so_ext)\n from exec_command import exec_command,get_pythonexe\n cmd = [get_pythonexe(),'-c',\n '\"import imp;imp.load_dynamic(\\\\\"atlas_version\\\\\",\\\\\"%s\\\\\")\"'\\\n % (os.path.basename(target))]\n s,o = exec_command(cmd,execute_in=os.path.dirname(target),use_tee=0)\n atlas_version = None\n if not s:\n m = re.match(r'ATLAS version (?P\\d+[.]\\d+[.]\\d+)',o)\n if m:\n atlas_version = m.group('version')\n if atlas_version is None:\n if re.search(r'undefined symbol: ATL_buildinfo',o,re.M):\n atlas_version = '3.2.1_pre3.3.6'\n else:\n print 'Command:',' '.join(cmd)\n print 'Status:',s\n print 'Output:',o\n return atlas_version\n\n\nclass lapack_opt_info(system_info):\n \n def calc_info(self):\n\n if sys.platform=='darwin' and not os.environ.get('ATLAS',None):\n args = []\n link_args = []\n if os.path.exists('/System/Library/Frameworks/Accelerate.framework/'):\n args.extend(['-faltivec','-framework','Accelerate'])\n link_args.extend(['-Wl,-framework','-Wl,Accelerate'])\n elif os.path.exists('/System/Library/Frameworks/vecLib.framework/'):\n args.extend(['-faltivec','-framework','vecLib'])\n link_args.extend(['-Wl,-framework','-Wl,vecLib'])\n if args:\n self.set_info(extra_compile_args=args,\n extra_link_args=link_args,\n define_macros=[('NO_ATLAS_INFO',3)])\n return\n\n atlas_info = get_info('atlas_threads')\n if not atlas_info:\n atlas_info = get_info('atlas')\n #atlas_info = {} ## uncomment for testing\n atlas_version = None\n need_lapack = 0\n need_blas = 0\n info = {}\n if atlas_info:\n version_info = atlas_info.copy()\n atlas_version = get_atlas_version(**version_info)\n if not atlas_info.has_key('define_macros'):\n atlas_info['define_macros'] = []\n if atlas_version is None:\n atlas_info['define_macros'].append(('NO_ATLAS_INFO',2))\n else:\n atlas_info['define_macros'].append(('ATLAS_INFO',\n '\"\\\\\"%s\\\\\"\"' % atlas_version))\n\t\tif atlas_version=='3.2.1_pre3.3.6':\n\t\t atlas_info['define_macros'].append(('NO_ATLAS_INFO',4))\n l = atlas_info.get('define_macros',[])\n if ('ATLAS_WITH_LAPACK_ATLAS',None) in l \\\n or ('ATLAS_WITHOUT_LAPACK',None) in l:\n need_lapack = 1\n info = atlas_info\n else:\n warnings.warn(AtlasNotFoundError.__doc__)\n need_blas = 1\n need_lapack = 1\n dict_append(info,define_macros=[('NO_ATLAS_INFO',1)])\n\n if need_lapack:\n lapack_info = get_info('lapack')\n #lapack_info = {} ## uncomment for testing\n if lapack_info:\n dict_append(info,**lapack_info)\n else:\n warnings.warn(LapackNotFoundError.__doc__)\n lapack_src_info = get_info('lapack_src')\n if not lapack_src_info:\n warnings.warn(LapackSrcNotFoundError.__doc__)\n return\n dict_append(info,libraries=[('flapack_src',lapack_src_info)])\n\n if need_blas:\n blas_info = get_info('blas')\n #blas_info = {} ## uncomment for testing\n if blas_info:\n dict_append(info,**blas_info)\n else:\n warnings.warn(BlasNotFoundError.__doc__)\n blas_src_info = get_info('blas_src')\n if not blas_src_info:\n warnings.warn(BlasSrcNotFoundError.__doc__)\n return\n dict_append(info,libraries=[('fblas_src',blas_src_info)])\n\n self.set_info(**info)\n return\n\n\nclass blas_opt_info(system_info):\n \n def calc_info(self):\n\n if sys.platform=='darwin' and not os.environ.get('ATLAS',None):\n args = []\n link_args = []\n if os.path.exists('/System/Library/Frameworks/Accelerate.framework/'):\n args.extend(['-faltivec','-framework','Accelerate'])\n link_args.extend(['-Wl,-framework','-Wl,Accelerate'])\n elif os.path.exists('/System/Library/Frameworks/vecLib.framework/'):\n args.extend(['-faltivec','-framework','vecLib'])\n link_args.extend(['-Wl,-framework','-Wl,vecLib'])\n if args:\n self.set_info(extra_compile_args=args,\n extra_link_args=link_args,\n define_macros=[('NO_ATLAS_INFO',3)])\n return\n\n atlas_info = get_info('atlas_blas_threads')\n if not atlas_info:\n atlas_info = get_info('atlas_blas')\n atlas_version = None\n need_blas = 0\n info = {}\n if atlas_info:\n version_info = atlas_info.copy()\n atlas_version = get_atlas_version(**version_info)\n if not atlas_info.has_key('define_macros'):\n atlas_info['define_macros'] = []\n if atlas_version is None:\n atlas_info['define_macros'].append(('NO_ATLAS_INFO',2))\n else:\n atlas_info['define_macros'].append(('ATLAS_INFO',\n '\"\\\\\"%s\\\\\"\"' % atlas_version))\n info = atlas_info\n else:\n warnings.warn(AtlasNotFoundError.__doc__)\n need_blas = 1\n dict_append(info,define_macros=[('NO_ATLAS_INFO',1)])\n\n if need_blas:\n blas_info = get_info('blas')\n if blas_info:\n dict_append(info,**blas_info)\n else:\n warnings.warn(BlasNotFoundError.__doc__)\n blas_src_info = get_info('blas_src')\n if not blas_src_info:\n warnings.warn(BlasSrcNotFoundError.__doc__)\n return\n dict_append(info,libraries=[('fblas_src',blas_src_info)])\n\n self.set_info(**info)\n return\n\n\nclass blas_info(system_info):\n section = 'blas'\n dir_env_var = 'BLAS'\n _lib_names = ['blas']\n notfounderror = BlasNotFoundError\n\n def calc_info(self):\n lib_dirs = self.get_lib_dirs()\n\n blas_libs = self.get_libs('blas_libs', self._lib_names)\n for d in lib_dirs:\n blas = self.check_libs(d,blas_libs,[])\n if blas is not None:\n info = blas \n break\n else:\n return\n info['language'] = 'f77' # XXX: is it generally true?\n self.set_info(**info)\n\n\nclass blas_src_info(system_info):\n section = 'blas_src'\n dir_env_var = 'BLAS_SRC'\n notfounderror = BlasSrcNotFoundError\n\n def get_paths(self, section, key):\n pre_dirs = system_info.get_paths(self, section, key)\n dirs = []\n for d in pre_dirs:\n dirs.extend([d] + self.combine_paths(d,['blas']))\n return [ d for d in dirs if os.path.isdir(d) ]\n\n def calc_info(self):\n src_dirs = self.get_src_dirs()\n src_dir = ''\n for d in src_dirs:\n if os.path.isfile(os.path.join(d,'daxpy.f')):\n src_dir = d\n break\n if not src_dir:\n #XXX: Get sources from netlib. May be ask first.\n return\n blas1 = '''\n caxpy csscal dnrm2 dzasum saxpy srotg zdotc ccopy cswap drot\n dznrm2 scasum srotm zdotu cdotc dasum drotg icamax scnrm2\n srotmg zdrot cdotu daxpy drotm idamax scopy sscal zdscal crotg\n dcabs1 drotmg isamax sdot sswap zrotg cscal dcopy dscal izamax\n snrm2 zaxpy zscal csrot ddot dswap sasum srot zcopy zswap\n '''\n blas2 = '''\n cgbmv chpmv ctrsv dsymv dtrsv sspr2 strmv zhemv ztpmv cgemv\n chpr dgbmv dsyr lsame ssymv strsv zher ztpsv cgerc chpr2 dgemv\n dsyr2 sgbmv ssyr xerbla zher2 ztrmv cgeru ctbmv dger dtbmv\n sgemv ssyr2 zgbmv zhpmv ztrsv chbmv ctbsv dsbmv dtbsv sger\n stbmv zgemv zhpr chemv ctpmv dspmv dtpmv ssbmv stbsv zgerc\n zhpr2 cher ctpsv dspr dtpsv sspmv stpmv zgeru ztbmv cher2\n ctrmv dspr2 dtrmv sspr stpsv zhbmv ztbsv\n '''\n blas3 = '''\n cgemm csymm ctrsm dsyrk sgemm strmm zhemm zsyr2k chemm csyr2k\n dgemm dtrmm ssymm strsm zher2k zsyrk cher2k csyrk dsymm dtrsm\n ssyr2k zherk ztrmm cherk ctrmm dsyr2k ssyrk zgemm zsymm ztrsm\n '''\n sources = [os.path.join(src_dir,f+'.f') \\\n for f in (blas1+blas2+blas3).split()]\n #XXX: should we check here actual existence of source files?\n info = {'sources':sources,'language':'f77'}\n self.set_info(**info)\n\nclass x11_info(system_info):\n section = 'x11'\n notfounderror = X11NotFoundError\n\n def __init__(self):\n system_info.__init__(self,\n default_lib_dirs=default_x11_lib_dirs,\n default_include_dirs=default_x11_include_dirs)\n\n def calc_info(self):\n if sys.platform in ['win32']:\n return\n lib_dirs = self.get_lib_dirs()\n include_dirs = self.get_include_dirs()\n x11_libs = self.get_libs('x11_libs', ['X11'])\n for lib_dir in lib_dirs:\n info = self.check_libs(lib_dir, x11_libs, [])\n if info is not None:\n break\n else:\n return\n inc_dir = None\n for d in include_dirs:\n if self.combine_paths(d, 'X11/X.h'):\n inc_dir = d\n break\n if inc_dir is not None:\n dict_append(info, include_dirs=[inc_dir])\n self.set_info(**info)\n\nclass numpy_info(system_info):\n section = 'numpy'\n modulename = 'Numeric'\n notfounderror = NumericNotFoundError\n\n def __init__(self):\n from distutils.sysconfig import get_python_inc\n include_dirs = []\n try:\n module = __import__(self.modulename)\n prefix = []\n for name in module.__file__.split(os.sep):\n if name=='lib':\n break\n prefix.append(name)\n include_dirs.append(get_python_inc(prefix=os.sep.join(prefix)))\n except ImportError:\n pass\n py_incl_dir = get_python_inc()\n include_dirs.append(py_incl_dir)\n for d in default_include_dirs:\n d = os.path.join(d, os.path.basename(py_incl_dir))\n if d not in include_dirs:\n include_dirs.append(d)\n system_info.__init__(self,\n default_lib_dirs=[],\n default_include_dirs=include_dirs)\n\n def calc_info(self):\n try:\n module = __import__(self.modulename)\n except ImportError:\n return\n info = {}\n macros = [(self.modulename.upper()+'_VERSION',\n '\"\\\\\"%s\\\\\"\"' % (module.__version__))]\n## try:\n## macros.append(\n## (self.modulename.upper()+'_VERSION_HEX',\n## hex(vstr2hex(module.__version__))),\n## )\n## except Exception,msg:\n## print msg\n dict_append(info, define_macros = macros)\n include_dirs = self.get_include_dirs()\n inc_dir = None\n for d in include_dirs:\n if self.combine_paths(d,\n os.path.join(self.modulename,\n 'arrayobject.h')):\n inc_dir = d\n break\n if inc_dir is not None:\n dict_append(info, include_dirs=[inc_dir])\n if info:\n self.set_info(**info)\n return\n\nclass numarray_info(numpy_info):\n section = 'numarray'\n modulename = 'numarray'\n\nclass boost_python_info(system_info):\n section = 'boost_python'\n dir_env_var = 'BOOST'\n\n def get_paths(self, section, key):\n pre_dirs = system_info.get_paths(self, section, key)\n dirs = []\n for d in pre_dirs:\n dirs.extend([d] + self.combine_paths(d,['boost*']))\n return [ d for d in dirs if os.path.isdir(d) ]\n\n def calc_info(self):\n from distutils.sysconfig import get_python_inc\n src_dirs = self.get_src_dirs()\n src_dir = ''\n for d in src_dirs:\n if os.path.isfile(os.path.join(d,'libs','python','src','module.cpp')):\n src_dir = d\n break\n if not src_dir:\n return\n py_incl_dir = get_python_inc()\n srcs_dir = os.path.join(src_dir,'libs','python','src')\n bpl_srcs = glob(os.path.join(srcs_dir,'*.cpp'))\n bpl_srcs += glob(os.path.join(srcs_dir,'*','*.cpp'))\n info = {'libraries':[('boost_python_src',{'include_dirs':[src_dir,py_incl_dir],\n 'sources':bpl_srcs})],\n 'include_dirs':[src_dir],\n }\n if info:\n self.set_info(**info)\n return\n\nclass agg2_info(system_info):\n section = 'agg2'\n dir_env_var = 'AGG2'\n\n def get_paths(self, section, key):\n pre_dirs = system_info.get_paths(self, section, key)\n dirs = []\n for d in pre_dirs:\n dirs.extend([d] + self.combine_paths(d,['agg2*']))\n return [ d for d in dirs if os.path.isdir(d) ]\n\n def calc_info(self):\n src_dirs = self.get_src_dirs()\n src_dir = ''\n for d in src_dirs:\n if os.path.isfile(os.path.join(d,'src','agg_affine_matrix.cpp')):\n src_dir = d\n break\n if not src_dir:\n return\n if sys.platform=='win32':\n agg2_srcs = glob(os.path.join(src_dir,'src','platform','win32','agg_win32_bmp.cpp'))\n else:\n agg2_srcs = glob(os.path.join(src_dir,'src','*.cpp'))\n agg2_srcs += [os.path.join(src_dir,'src','platform','X11','agg_platform_support.cpp')]\n \n info = {'libraries':[('agg2_src',{'sources':agg2_srcs,\n 'include_dirs':[os.path.join(src_dir,'include')],\n })],\n 'include_dirs':[os.path.join(src_dir,'include')],\n }\n if info:\n self.set_info(**info)\n return\n\nclass _pkg_config_info(system_info):\n section = None\n config_env_var = 'PKG_CONFIG'\n default_config_exe = 'pkg-config'\n append_config_exe = ''\n version_macro_name = None\n release_macro_name = None\n version_flag = '--modversion'\n cflags_flag = '--cflags'\n\n def get_config_exe(self):\n if os.environ.has_key(self.config_env_var):\n return os.environ[self.config_env_var]\n return self.default_config_exe\n def get_config_output(self, config_exe, option):\n s,o = exec_command(config_exe+' '+self.append_config_exe+' '+option,use_tee=0)\n if not s:\n return o\n\n def calc_info(self):\n config_exe = find_executable(self.get_config_exe())\n if not os.path.isfile(config_exe):\n print 'File not found: %s. Cannot determine %s info.' \\\n % (config_exe, self.section)\n return\n info = {}\n macros = []\n libraries = []\n library_dirs = []\n include_dirs = []\n extra_link_args = []\n extra_compile_args = []\n version = self.get_config_output(config_exe,self.version_flag)\n if version:\n macros.append((self.__class__.__name__.split('.')[-1].upper(),\n '\"\\\\\"%s\\\\\"\"' % (version)))\n if self.version_macro_name:\n macros.append((self.version_macro_name+'_%s' % (version.replace('.','_')),None))\n if self.release_macro_name:\n release = self.get_config_output(config_exe,'--release')\n if release:\n macros.append((self.release_macro_name+'_%s' % (release.replace('.','_')),None))\n opts = self.get_config_output(config_exe,'--libs')\n if opts:\n for opt in opts.split():\n if opt[:2]=='-l':\n libraries.append(opt[2:])\n elif opt[:2]=='-L':\n library_dirs.append(opt[2:])\n else:\n extra_link_args.append(opt)\n opts = self.get_config_output(config_exe,self.cflags_flag)\n if opts:\n for opt in opts.split():\n if opt[:2]=='-I':\n include_dirs.append(opt[2:])\n elif opt[:2]=='-D':\n if '=' in opt:\n n,v = opt[2:].split('=')\n macros.append((n,v))\n else:\n macros.append((opt[2:],None))\n else:\n extra_compile_args.append(opt)\n if macros: dict_append(info, define_macros = macros)\n if libraries: dict_append(info, libraries = libraries)\n if library_dirs: dict_append(info, library_dirs = library_dirs)\n if include_dirs: dict_append(info, include_dirs = include_dirs)\n if extra_link_args: dict_append(info, extra_link_args = extra_link_args)\n if extra_compile_args: dict_append(info, extra_compile_args = extra_compile_args)\n if info:\n self.set_info(**info)\n return\n\nclass wx_info(_pkg_config_info):\n section = 'wx'\n config_env_var = 'WX_CONFIG'\n default_config_exe = 'wx-config'\n append_config_exe = ''\n version_macro_name = 'WX_VERSION'\n release_macro_name = 'WX_RELEASE'\n version_flag = '--version'\n cflags_flag = '--cxxflags'\n\nclass gdk_pixbuf_xlib_2_info(_pkg_config_info):\n section = 'gdk_pixbuf_xlib_2'\n append_config_exe = 'gdk-pixbuf-xlib-2.0'\n version_macro_name = 'GDK_PIXBUF_XLIB_VERSION'\n\nclass gdk_pixbuf_2_info(_pkg_config_info):\n section = 'gdk_pixbuf_2'\n append_config_exe = 'gdk-pixbuf-2.0'\n version_macro_name = 'GDK_PIXBUF_VERSION'\n\nclass gdk_x11_2_info(_pkg_config_info):\n section = 'gdk_x11_2'\n append_config_exe = 'gdk-x11-2.0'\n version_macro_name = 'GDK_X11_VERSION'\n\nclass gdk_2_info(_pkg_config_info):\n section = 'gdk_2'\n append_config_exe = 'gdk-2.0'\n version_macro_name = 'GDK_VERSION'\n\nclass gdk_info(_pkg_config_info):\n section = 'gdk'\n append_config_exe = 'gdk'\n version_macro_name = 'GDK_VERSION'\n\nclass gtkp_x11_2_info(_pkg_config_info):\n section = 'gtkp_x11_2'\n append_config_exe = 'gtk+-x11-2.0'\n version_macro_name = 'GTK_X11_VERSION'\n\n\nclass gtkp_2_info(_pkg_config_info):\n section = 'gtkp_2'\n append_config_exe = 'gtk+-2.0'\n version_macro_name = 'GTK_VERSION'\n\nclass xft_info(_pkg_config_info):\n section = 'xft'\n append_config_exe = 'xft'\n version_macro_name = 'XFT_VERSION'\n\nclass freetype2_info(_pkg_config_info):\n section = 'freetype2'\n append_config_exe = 'freetype2'\n version_macro_name = 'FREETYPE2_VERSION'\n\n## def vstr2hex(version):\n## bits = []\n## n = [24,16,8,4,0]\n## r = 0\n## for s in version.split('.'):\n## r |= int(s) << n[0]\n## del n[0]\n## return r\n\n#--------------------------------------------------------------------\n\ndef combine_paths(*args,**kws):\n \"\"\" Return a list of existing paths composed by all combinations of\n items from arguments.\n \"\"\"\n r = []\n for a in args:\n if not a: continue\n if type(a) is types.StringType:\n a = [a]\n r.append(a)\n args = r\n if not args: return []\n if len(args)==1:\n result = reduce(lambda a,b:a+b,map(glob,args[0]),[])\n elif len (args)==2:\n result = []\n for a0 in args[0]:\n for a1 in args[1]:\n result.extend(glob(os.path.join(a0,a1)))\n else:\n result = combine_paths(*(combine_paths(args[0],args[1])+args[2:]))\n verbosity = kws.get('verbosity',1)\n if verbosity>1 and result:\n print '(','paths:',','.join(result),')'\n return result\n\nlanguage_map = {'c':0,'c++':1,'f77':2,'f90':3}\ninv_language_map = {0:'c',1:'c++',2:'f77',3:'f90'}\ndef dict_append(d,**kws):\n languages = []\n for k,v in kws.items():\n if k=='language':\n languages.append(v)\n continue\n if d.has_key(k):\n if k in ['library_dirs','include_dirs','define_macros']:\n [d[k].append(vv) for vv in v if vv not in d[k]]\n else:\n d[k].extend(v)\n else:\n d[k] = v\n if languages:\n l = inv_language_map[max([language_map.get(l,0) for l in languages])]\n d['language'] = l\n return\n\ndef show_all():\n import system_info\n import pprint\n match_info = re.compile(r'.*?_info').match\n show_only = []\n for n in sys.argv[1:]:\n if n[-5:] != '_info':\n n = n + '_info'\n show_only.append(n)\n show_all = not show_only\n for n in filter(match_info,dir(system_info)):\n if n in ['system_info','get_info']: continue\n if not show_all:\n if n not in show_only: continue\n del show_only[show_only.index(n)]\n c = getattr(system_info,n)()\n c.verbosity = 2\n r = c.get_info()\n if show_only:\n print 'Info classes not defined:',','.join(show_only)\nif __name__ == \"__main__\":\n show_all()\n", "methods": [ { "name": "get_info", "long_name": "get_info( name , notfound_action = 0 )", "filename": "system_info.py", "nloc": 43, "complexity": 1, "token_count": 194, "parameters": [ "name", "notfound_action" ], "start_line": 144, "end_line": 192, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 49, "top_nesting_level": 0 }, { "name": "__init__", "long_name": "__init__( self , default_lib_dirs = default_lib_dirs , default_include_dirs = default_include_dirs , verbosity = 1 , )", "filename": "system_info.py", "nloc": 26, "complexity": 3, "token_count": 206, "parameters": [ "self", "default_lib_dirs", "default_include_dirs", "verbosity" ], "start_line": 272, "end_line": 297, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 26, "top_nesting_level": 1 }, { "name": "calc_libraries_info", "long_name": "calc_libraries_info( self )", "filename": "system_info.py", "nloc": 15, "complexity": 5, "token_count": 78, "parameters": [ "self" ], "start_line": 299, "end_line": 313, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 15, "top_nesting_level": 1 }, { "name": "set_info", "long_name": "set_info( self , ** info )", "filename": "system_info.py", "nloc": 5, "complexity": 2, "token_count": 37, "parameters": [ "self", "info" ], "start_line": 315, "end_line": 319, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 5, "top_nesting_level": 1 }, { "name": "has_info", "long_name": "has_info( self )", "filename": "system_info.py", "nloc": 2, "complexity": 1, "token_count": 18, "parameters": [ "self" ], "start_line": 321, "end_line": 322, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 2, "top_nesting_level": 1 }, { "name": "get_info", "long_name": "get_info( self , notfound_action = 0 )", "filename": "system_info.py", "nloc": 30, "complexity": 15, "token_count": 206, "parameters": [ "self", "notfound_action" ], "start_line": 324, "end_line": 359, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 36, "top_nesting_level": 1 }, { "name": "get_paths", "long_name": "get_paths( self , section , key )", "filename": "system_info.py", "nloc": 47, "complexity": 20, "token_count": 405, "parameters": [ "self", "section", "key" ], "start_line": 361, "end_line": 407, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 47, "top_nesting_level": 1 }, { "name": "get_lib_dirs", "long_name": "get_lib_dirs( self , key = 'library_dirs' )", "filename": "system_info.py", "nloc": 2, "complexity": 1, "token_count": 20, "parameters": [ "self", "key" ], "start_line": 409, "end_line": 410, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 2, "top_nesting_level": 1 }, { "name": "get_include_dirs", "long_name": "get_include_dirs( self , key = 'include_dirs' )", "filename": "system_info.py", "nloc": 2, "complexity": 1, "token_count": 20, "parameters": [ "self", "key" ], "start_line": 412, "end_line": 413, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 2, "top_nesting_level": 1 }, { "name": "get_src_dirs", "long_name": "get_src_dirs( self , key = 'src_dirs' )", "filename": "system_info.py", "nloc": 2, "complexity": 1, "token_count": 20, "parameters": [ "self", "key" ], "start_line": 415, "end_line": 416, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 2, "top_nesting_level": 1 }, { "name": "get_libs", "long_name": "get_libs( self , key , default )", "filename": "system_info.py", "nloc": 10, "complexity": 7, "token_count": 79, "parameters": [ "self", "key", "default" ], "start_line": 418, "end_line": 427, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 10, "top_nesting_level": 1 }, { "name": "get_libraries", "long_name": "get_libraries( self , key = 'libraries' )", "filename": "system_info.py", "nloc": 2, "complexity": 1, "token_count": 18, "parameters": [ "self", "key" ], "start_line": 429, "end_line": 430, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 2, "top_nesting_level": 1 }, { "name": "check_libs", "long_name": "check_libs( self , lib_dir , libs , opt_libs = [ ] )", "filename": "system_info.py", "nloc": 11, "complexity": 5, "token_count": 77, "parameters": [ "self", "lib_dir", "libs", "opt_libs" ], "start_line": 432, "end_line": 444, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 13, "top_nesting_level": 1 }, { "name": "_lib_list", "long_name": "_lib_list( self , lib_dir , libs , ext )", "filename": "system_info.py", "nloc": 9, "complexity": 3, "token_count": 65, "parameters": [ "self", "lib_dir", "libs", "ext" ], "start_line": 446, "end_line": 454, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 9, "top_nesting_level": 1 }, { "name": "_extract_lib_names", "long_name": "_extract_lib_names( self , libs )", "filename": "system_info.py", "nloc": 3, "complexity": 2, "token_count": 37, "parameters": [ "self", "libs" ], "start_line": 456, "end_line": 458, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 3, "top_nesting_level": 1 }, { "name": "_check_libs", "long_name": "_check_libs( self , lib_dir , libs , opt_libs , ext )", "filename": "system_info.py", "nloc": 10, "complexity": 3, "token_count": 99, "parameters": [ "self", "lib_dir", "libs", "opt_libs", "ext" ], "start_line": 460, "end_line": 469, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 10, "top_nesting_level": 1 }, { "name": "combine_paths", "long_name": "combine_paths( self , * args )", "filename": "system_info.py", "nloc": 2, "complexity": 1, "token_count": 23, "parameters": [ "self", "args" ], "start_line": 471, "end_line": 472, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 2, "top_nesting_level": 1 }, { "name": "__init__", "long_name": "__init__( self )", "filename": "system_info.py", "nloc": 2, "complexity": 1, "token_count": 11, "parameters": [ "self" ], "start_line": 482, "end_line": 483, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 2, "top_nesting_level": 1 }, { "name": "calc_info", "long_name": "calc_info( self )", "filename": "system_info.py", "nloc": 26, "complexity": 8, "token_count": 150, "parameters": [ "self" ], "start_line": 485, "end_line": 510, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 26, "top_nesting_level": 1 }, { "name": "get_paths", "long_name": "get_paths( self , section , key )", "filename": "system_info.py", "nloc": 6, "complexity": 4, "token_count": 66, "parameters": [ "self", "section", "key" ], "start_line": 552, "end_line": 557, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 6, "top_nesting_level": 1 }, { "name": "calc_info", "long_name": "calc_info( self )", "filename": "system_info.py", "nloc": 22, "complexity": 7, "token_count": 140, "parameters": [ "self" ], "start_line": 559, "end_line": 580, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 22, "top_nesting_level": 1 }, { "name": "get_paths", "long_name": "get_paths( self , section , key )", "filename": "system_info.py", "nloc": 7, "complexity": 4, "token_count": 74, "parameters": [ "self", "section", "key" ], "start_line": 595, "end_line": 601, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 7, "top_nesting_level": 1 }, { "name": "calc_info", "long_name": "calc_info( self )", "filename": "system_info.py", "nloc": 78, "complexity": 17, "token_count": 441, "parameters": [ "self" ], "start_line": 603, "end_line": 683, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 81, "top_nesting_level": 1 }, { "name": "calc_info", "long_name": "calc_info( self )", "filename": "system_info.py", "nloc": 21, "complexity": 6, "token_count": 138, "parameters": [ "self" ], "start_line": 688, "end_line": 710, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 23, "top_nesting_level": 1 }, { "name": "calc_info", "long_name": "calc_info( self )", "filename": "system_info.py", "nloc": 12, "complexity": 3, "token_count": 68, "parameters": [ "self" ], "start_line": 733, "end_line": 745, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 13, "top_nesting_level": 1 }, { "name": "get_paths", "long_name": "get_paths( self , section , key )", "filename": "system_info.py", "nloc": 6, "complexity": 4, "token_count": 68, "parameters": [ "self", "section", "key" ], "start_line": 752, "end_line": 757, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 6, "top_nesting_level": 1 }, { "name": "calc_info", "long_name": "calc_info( self )", "filename": "system_info.py", "nloc": 81, "complexity": 10, "token_count": 232, "parameters": [ "self" ], "start_line": 759, "end_line": 843, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 85, "top_nesting_level": 1 }, { "name": "get_atlas_version.atlas_version_c", "long_name": "get_atlas_version.atlas_version_c( extension , build_dir , magic = magic )", "filename": "system_info.py", "nloc": 10, "complexity": 3, "token_count": 74, "parameters": [ "extension", "build_dir", "magic" ], "start_line": 867, "end_line": 876, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 10, "top_nesting_level": 1 }, { "name": "get_atlas_version", "long_name": "get_atlas_version( ** config )", "filename": "system_info.py", "nloc": 45, "complexity": 9, "token_count": 289, "parameters": [ "config" ], "start_line": 862, "end_line": 916, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 55, "top_nesting_level": 0 }, { "name": "calc_info", "long_name": "calc_info( self )", "filename": "system_info.py", "nloc": 68, "complexity": 19, "token_count": 434, "parameters": [ "self" ], "start_line": 921, "end_line": 996, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 76, "top_nesting_level": 1 }, { "name": "calc_info", "long_name": "calc_info( self )", "filename": "system_info.py", "nloc": 49, "complexity": 13, "token_count": 316, "parameters": [ "self" ], "start_line": 1001, "end_line": 1053, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 53, "top_nesting_level": 1 }, { "name": "calc_info", "long_name": "calc_info( self )", "filename": "system_info.py", "nloc": 12, "complexity": 3, "token_count": 68, "parameters": [ "self" ], "start_line": 1062, "end_line": 1074, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 13, "top_nesting_level": 1 }, { "name": "get_paths", "long_name": "get_paths( self , section , key )", "filename": "system_info.py", "nloc": 6, "complexity": 4, "token_count": 66, "parameters": [ "self", "section", "key" ], "start_line": 1082, "end_line": 1087, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 6, "top_nesting_level": 1 }, { "name": "calc_info", "long_name": "calc_info( self )", "filename": "system_info.py", "nloc": 34, "complexity": 5, "token_count": 106, "parameters": [ "self" ], "start_line": 1089, "end_line": 1124, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 36, "top_nesting_level": 1 }, { "name": "__init__", "long_name": "__init__( self )", "filename": "system_info.py", "nloc": 4, "complexity": 1, "token_count": 19, "parameters": [ "self" ], "start_line": 1130, "end_line": 1133, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 4, "top_nesting_level": 1 }, { "name": "calc_info", "long_name": "calc_info( self )", "filename": "system_info.py", "nloc": 20, "complexity": 7, "token_count": 114, "parameters": [ "self" ], "start_line": 1135, "end_line": 1154, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 20, "top_nesting_level": 1 }, { "name": "__init__", "long_name": "__init__( self )", "filename": "system_info.py", "nloc": 22, "complexity": 6, "token_count": 139, "parameters": [ "self" ], "start_line": 1161, "end_line": 1182, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 22, "top_nesting_level": 1 }, { "name": "calc_info", "long_name": "calc_info( self )", "filename": "system_info.py", "nloc": 22, "complexity": 6, "token_count": 121, "parameters": [ "self" ], "start_line": 1184, "end_line": 1212, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 29, "top_nesting_level": 1 }, { "name": "get_paths", "long_name": "get_paths( self , section , key )", "filename": "system_info.py", "nloc": 6, "complexity": 4, "token_count": 66, "parameters": [ "self", "section", "key" ], "start_line": 1222, "end_line": 1227, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 6, "top_nesting_level": 1 }, { "name": "calc_info", "long_name": "calc_info( self )", "filename": "system_info.py", "nloc": 21, "complexity": 5, "token_count": 156, "parameters": [ "self" ], "start_line": 1229, "end_line": 1249, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 21, "top_nesting_level": 1 }, { "name": "get_paths", "long_name": "get_paths( self , section , key )", "filename": "system_info.py", "nloc": 6, "complexity": 4, "token_count": 66, "parameters": [ "self", "section", "key" ], "start_line": 1255, "end_line": 1260, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 6, "top_nesting_level": 1 }, { "name": "calc_info", "long_name": "calc_info( self )", "filename": "system_info.py", "nloc": 22, "complexity": 6, "token_count": 177, "parameters": [ "self" ], "start_line": 1262, "end_line": 1284, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 23, "top_nesting_level": 1 }, { "name": "get_config_exe", "long_name": "get_config_exe( self )", "filename": "system_info.py", "nloc": 4, "complexity": 2, "token_count": 30, "parameters": [ "self" ], "start_line": 1296, "end_line": 1299, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 4, "top_nesting_level": 1 }, { "name": "get_config_output", "long_name": "get_config_output( self , config_exe , option )", "filename": "system_info.py", "nloc": 4, "complexity": 2, "token_count": 37, "parameters": [ "self", "config_exe", "option" ], "start_line": 1300, "end_line": 1303, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 4, "top_nesting_level": 1 }, { "name": "calc_info", "long_name": "calc_info( self )", "filename": "system_info.py", "nloc": 54, "complexity": 22, "token_count": 435, "parameters": [ "self" ], "start_line": 1305, "end_line": 1358, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 54, "top_nesting_level": 1 }, { "name": "combine_paths", "long_name": "combine_paths( * args , ** kws )", "filename": "system_info.py", "nloc": 22, "complexity": 11, "token_count": 195, "parameters": [ "args", "kws" ], "start_line": 1427, "end_line": 1451, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 25, "top_nesting_level": 0 }, { "name": "dict_append", "long_name": "dict_append( d , ** kws )", "filename": "system_info.py", "nloc": 17, "complexity": 9, "token_count": 128, "parameters": [ "d", "kws" ], "start_line": 1455, "end_line": 1471, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 17, "top_nesting_level": 0 }, { "name": "show_all", "long_name": "show_all( )", "filename": "system_info.py", "nloc": 20, "complexity": 8, "token_count": 137, "parameters": [], "start_line": 1473, "end_line": 1492, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 20, "top_nesting_level": 0 } ], "methods_before": [ { "name": "get_info", "long_name": "get_info( name , notfound_action = 0 )", "filename": "system_info.py", "nloc": 43, "complexity": 1, "token_count": 194, "parameters": [ "name", "notfound_action" ], "start_line": 144, "end_line": 192, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 49, "top_nesting_level": 0 }, { "name": "__init__", "long_name": "__init__( self , default_lib_dirs = default_lib_dirs , default_include_dirs = default_include_dirs , verbosity = 1 , )", "filename": "system_info.py", "nloc": 26, "complexity": 3, "token_count": 206, "parameters": [ "self", "default_lib_dirs", "default_include_dirs", "verbosity" ], "start_line": 272, "end_line": 297, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 26, "top_nesting_level": 1 }, { "name": "calc_libraries_info", "long_name": "calc_libraries_info( self )", "filename": "system_info.py", "nloc": 15, "complexity": 5, "token_count": 78, "parameters": [ "self" ], "start_line": 299, "end_line": 313, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 15, "top_nesting_level": 1 }, { "name": "set_info", "long_name": "set_info( self , ** info )", "filename": "system_info.py", "nloc": 5, "complexity": 2, "token_count": 37, "parameters": [ "self", "info" ], "start_line": 315, "end_line": 319, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 5, "top_nesting_level": 1 }, { "name": "has_info", "long_name": "has_info( self )", "filename": "system_info.py", "nloc": 2, "complexity": 1, "token_count": 18, "parameters": [ "self" ], "start_line": 321, "end_line": 322, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 2, "top_nesting_level": 1 }, { "name": "get_info", "long_name": "get_info( self , notfound_action = 0 )", "filename": "system_info.py", "nloc": 30, "complexity": 15, "token_count": 206, "parameters": [ "self", "notfound_action" ], "start_line": 324, "end_line": 359, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 36, "top_nesting_level": 1 }, { "name": "get_paths", "long_name": "get_paths( self , section , key )", "filename": "system_info.py", "nloc": 47, "complexity": 20, "token_count": 405, "parameters": [ "self", "section", "key" ], "start_line": 361, "end_line": 407, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 47, "top_nesting_level": 1 }, { "name": "get_lib_dirs", "long_name": "get_lib_dirs( self , key = 'library_dirs' )", "filename": "system_info.py", "nloc": 2, "complexity": 1, "token_count": 20, "parameters": [ "self", "key" ], "start_line": 409, "end_line": 410, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 2, "top_nesting_level": 1 }, { "name": "get_include_dirs", "long_name": "get_include_dirs( self , key = 'include_dirs' )", "filename": "system_info.py", "nloc": 2, "complexity": 1, "token_count": 20, "parameters": [ "self", "key" ], "start_line": 412, "end_line": 413, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 2, "top_nesting_level": 1 }, { "name": "get_src_dirs", "long_name": "get_src_dirs( self , key = 'src_dirs' )", "filename": "system_info.py", "nloc": 2, "complexity": 1, "token_count": 20, "parameters": [ "self", "key" ], "start_line": 415, "end_line": 416, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 2, "top_nesting_level": 1 }, { "name": "get_libs", "long_name": "get_libs( self , key , default )", "filename": "system_info.py", "nloc": 10, "complexity": 7, "token_count": 79, "parameters": [ "self", "key", "default" ], "start_line": 418, "end_line": 427, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 10, "top_nesting_level": 1 }, { "name": "get_libraries", "long_name": "get_libraries( self , key = 'libraries' )", "filename": "system_info.py", "nloc": 2, "complexity": 1, "token_count": 18, "parameters": [ "self", "key" ], "start_line": 429, "end_line": 430, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 2, "top_nesting_level": 1 }, { "name": "check_libs", "long_name": "check_libs( self , lib_dir , libs , opt_libs = [ ] )", "filename": "system_info.py", "nloc": 11, "complexity": 5, "token_count": 77, "parameters": [ "self", "lib_dir", "libs", "opt_libs" ], "start_line": 432, "end_line": 444, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 13, "top_nesting_level": 1 }, { "name": "_lib_list", "long_name": "_lib_list( self , lib_dir , libs , ext )", "filename": "system_info.py", "nloc": 9, "complexity": 3, "token_count": 65, "parameters": [ "self", "lib_dir", "libs", "ext" ], "start_line": 446, "end_line": 454, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 9, "top_nesting_level": 1 }, { "name": "_extract_lib_names", "long_name": "_extract_lib_names( self , libs )", "filename": "system_info.py", "nloc": 3, "complexity": 2, "token_count": 37, "parameters": [ "self", "libs" ], "start_line": 456, "end_line": 458, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 3, "top_nesting_level": 1 }, { "name": "_check_libs", "long_name": "_check_libs( self , lib_dir , libs , opt_libs , ext )", "filename": "system_info.py", "nloc": 10, "complexity": 3, "token_count": 99, "parameters": [ "self", "lib_dir", "libs", "opt_libs", "ext" ], "start_line": 460, "end_line": 469, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 10, "top_nesting_level": 1 }, { "name": "combine_paths", "long_name": "combine_paths( self , * args )", "filename": "system_info.py", "nloc": 2, "complexity": 1, "token_count": 23, "parameters": [ "self", "args" ], "start_line": 471, "end_line": 472, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 2, "top_nesting_level": 1 }, { "name": "__init__", "long_name": "__init__( self )", "filename": "system_info.py", "nloc": 2, "complexity": 1, "token_count": 11, "parameters": [ "self" ], "start_line": 482, "end_line": 483, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 2, "top_nesting_level": 1 }, { "name": "calc_info", "long_name": "calc_info( self )", "filename": "system_info.py", "nloc": 26, "complexity": 8, "token_count": 150, "parameters": [ "self" ], "start_line": 485, "end_line": 510, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 26, "top_nesting_level": 1 }, { "name": "get_paths", "long_name": "get_paths( self , section , key )", "filename": "system_info.py", "nloc": 6, "complexity": 4, "token_count": 66, "parameters": [ "self", "section", "key" ], "start_line": 552, "end_line": 557, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 6, "top_nesting_level": 1 }, { "name": "calc_info", "long_name": "calc_info( self )", "filename": "system_info.py", "nloc": 22, "complexity": 7, "token_count": 140, "parameters": [ "self" ], "start_line": 559, "end_line": 580, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 22, "top_nesting_level": 1 }, { "name": "get_paths", "long_name": "get_paths( self , section , key )", "filename": "system_info.py", "nloc": 7, "complexity": 4, "token_count": 74, "parameters": [ "self", "section", "key" ], "start_line": 595, "end_line": 601, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 7, "top_nesting_level": 1 }, { "name": "calc_info", "long_name": "calc_info( self )", "filename": "system_info.py", "nloc": 78, "complexity": 17, "token_count": 441, "parameters": [ "self" ], "start_line": 603, "end_line": 683, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 81, "top_nesting_level": 1 }, { "name": "calc_info", "long_name": "calc_info( self )", "filename": "system_info.py", "nloc": 21, "complexity": 6, "token_count": 138, "parameters": [ "self" ], "start_line": 688, "end_line": 710, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 23, "top_nesting_level": 1 }, { "name": "calc_info", "long_name": "calc_info( self )", "filename": "system_info.py", "nloc": 12, "complexity": 3, "token_count": 68, "parameters": [ "self" ], "start_line": 733, "end_line": 745, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 13, "top_nesting_level": 1 }, { "name": "get_paths", "long_name": "get_paths( self , section , key )", "filename": "system_info.py", "nloc": 6, "complexity": 4, "token_count": 68, "parameters": [ "self", "section", "key" ], "start_line": 752, "end_line": 757, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 6, "top_nesting_level": 1 }, { "name": "calc_info", "long_name": "calc_info( self )", "filename": "system_info.py", "nloc": 81, "complexity": 10, "token_count": 232, "parameters": [ "self" ], "start_line": 759, "end_line": 843, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 85, "top_nesting_level": 1 }, { "name": "get_atlas_version.atlas_version_c", "long_name": "get_atlas_version.atlas_version_c( extension , build_dir , magic = magic )", "filename": "system_info.py", "nloc": 10, "complexity": 3, "token_count": 74, "parameters": [ "extension", "build_dir", "magic" ], "start_line": 867, "end_line": 876, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 10, "top_nesting_level": 1 }, { "name": "get_atlas_version", "long_name": "get_atlas_version( ** config )", "filename": "system_info.py", "nloc": 45, "complexity": 9, "token_count": 289, "parameters": [ "config" ], "start_line": 862, "end_line": 916, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 55, "top_nesting_level": 0 }, { "name": "calc_info", "long_name": "calc_info( self )", "filename": "system_info.py", "nloc": 68, "complexity": 19, "token_count": 434, "parameters": [ "self" ], "start_line": 921, "end_line": 996, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 76, "top_nesting_level": 1 }, { "name": "calc_info", "long_name": "calc_info( self )", "filename": "system_info.py", "nloc": 49, "complexity": 13, "token_count": 316, "parameters": [ "self" ], "start_line": 1001, "end_line": 1053, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 53, "top_nesting_level": 1 }, { "name": "calc_info", "long_name": "calc_info( self )", "filename": "system_info.py", "nloc": 12, "complexity": 3, "token_count": 68, "parameters": [ "self" ], "start_line": 1062, "end_line": 1074, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 13, "top_nesting_level": 1 }, { "name": "get_paths", "long_name": "get_paths( self , section , key )", "filename": "system_info.py", "nloc": 6, "complexity": 4, "token_count": 66, "parameters": [ "self", "section", "key" ], "start_line": 1082, "end_line": 1087, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 6, "top_nesting_level": 1 }, { "name": "calc_info", "long_name": "calc_info( self )", "filename": "system_info.py", "nloc": 34, "complexity": 5, "token_count": 106, "parameters": [ "self" ], "start_line": 1089, "end_line": 1124, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 36, "top_nesting_level": 1 }, { "name": "__init__", "long_name": "__init__( self )", "filename": "system_info.py", "nloc": 4, "complexity": 1, "token_count": 19, "parameters": [ "self" ], "start_line": 1130, "end_line": 1133, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 4, "top_nesting_level": 1 }, { "name": "calc_info", "long_name": "calc_info( self )", "filename": "system_info.py", "nloc": 20, "complexity": 7, "token_count": 114, "parameters": [ "self" ], "start_line": 1135, "end_line": 1154, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 20, "top_nesting_level": 1 }, { "name": "__init__", "long_name": "__init__( self )", "filename": "system_info.py", "nloc": 22, "complexity": 6, "token_count": 139, "parameters": [ "self" ], "start_line": 1161, "end_line": 1182, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 22, "top_nesting_level": 1 }, { "name": "calc_info", "long_name": "calc_info( self )", "filename": "system_info.py", "nloc": 22, "complexity": 6, "token_count": 121, "parameters": [ "self" ], "start_line": 1184, "end_line": 1212, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 29, "top_nesting_level": 1 }, { "name": "get_paths", "long_name": "get_paths( self , section , key )", "filename": "system_info.py", "nloc": 6, "complexity": 4, "token_count": 66, "parameters": [ "self", "section", "key" ], "start_line": 1222, "end_line": 1227, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 6, "top_nesting_level": 1 }, { "name": "calc_info", "long_name": "calc_info( self )", "filename": "system_info.py", "nloc": 21, "complexity": 5, "token_count": 156, "parameters": [ "self" ], "start_line": 1229, "end_line": 1249, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 21, "top_nesting_level": 1 }, { "name": "get_paths", "long_name": "get_paths( self , section , key )", "filename": "system_info.py", "nloc": 6, "complexity": 4, "token_count": 66, "parameters": [ "self", "section", "key" ], "start_line": 1255, "end_line": 1260, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 6, "top_nesting_level": 1 }, { "name": "calc_info", "long_name": "calc_info( self )", "filename": "system_info.py", "nloc": 22, "complexity": 6, "token_count": 177, "parameters": [ "self" ], "start_line": 1262, "end_line": 1284, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 23, "top_nesting_level": 1 }, { "name": "get_config_exe", "long_name": "get_config_exe( self )", "filename": "system_info.py", "nloc": 4, "complexity": 2, "token_count": 30, "parameters": [ "self" ], "start_line": 1296, "end_line": 1299, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 4, "top_nesting_level": 1 }, { "name": "get_config_output", "long_name": "get_config_output( self , config_exe , option )", "filename": "system_info.py", "nloc": 4, "complexity": 2, "token_count": 37, "parameters": [ "self", "config_exe", "option" ], "start_line": 1300, "end_line": 1303, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 4, "top_nesting_level": 1 }, { "name": "calc_info", "long_name": "calc_info( self )", "filename": "system_info.py", "nloc": 54, "complexity": 22, "token_count": 435, "parameters": [ "self" ], "start_line": 1305, "end_line": 1358, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 54, "top_nesting_level": 1 }, { "name": "combine_paths", "long_name": "combine_paths( * args , ** kws )", "filename": "system_info.py", "nloc": 22, "complexity": 11, "token_count": 195, "parameters": [ "args", "kws" ], "start_line": 1427, "end_line": 1451, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 25, "top_nesting_level": 0 }, { "name": "dict_append", "long_name": "dict_append( d , ** kws )", "filename": "system_info.py", "nloc": 17, "complexity": 9, "token_count": 128, "parameters": [ "d", "kws" ], "start_line": 1455, "end_line": 1471, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 17, "top_nesting_level": 0 }, { "name": "show_all", "long_name": "show_all( )", "filename": "system_info.py", "nloc": 20, "complexity": 8, "token_count": 137, "parameters": [], "start_line": 1473, "end_line": 1492, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 20, "top_nesting_level": 0 } ], "changed_methods": [ { "name": "get_atlas_version", "long_name": "get_atlas_version( ** config )", "filename": "system_info.py", "nloc": 45, "complexity": 9, "token_count": 289, "parameters": [ "config" ], "start_line": 862, "end_line": 916, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 55, "top_nesting_level": 0 } ], "nloc": 1320, "complexity": 285, "token_count": 7302, "diff_parsed": { "added": [ " m = re.search(r'ATLAS version (?P\\d+[.]\\d+[.]\\d+)',o)" ], "deleted": [ " m = re.match(r'ATLAS version (?P\\d+[.]\\d+[.]\\d+)',o)" ] } } ] }, { "hash": "ab288fa1426e8a48bee09c517c90964882ddbef1", "msg": "Merged numarray branch onto the main trunk.", "author": { "name": "jmiller", "email": "jmiller@localhost" }, "committer": { "name": "jmiller", "email": "jmiller@localhost" }, "author_date": "2005-01-10T19:28:55+00:00", "author_timezone": 0, "committer_date": "2005-01-10T19:28:55+00:00", "committer_timezone": 0, "branches": [ "main" ], "in_main_branch": true, "merge": true, "parents": [ "5d776d8493fd3981f0349df78bccd09a593e3fbf", "bbc46872ab69ba9334580288c1f86788007ad424" ], "project_name": "repo_copy", "project_path": "/tmp/tmpqop781_j/repo_copy", "deletions": 626, "insertions": 963, "lines": 1589, "files": 23, "dmm_unit_size": null, "dmm_unit_complexity": null, "dmm_unit_interfacing": null } ]