diff options
author | Pearu Peterson <pearu.peterson@gmail.com> | 2006-02-24 16:56:59 +0000 |
---|---|---|
committer | Pearu Peterson <pearu.peterson@gmail.com> | 2006-02-24 16:56:59 +0000 |
commit | 00f2295ec55239ce35687a20a7c58d1583b068f1 (patch) | |
tree | 0b9be469665fc81943ccac5667467627723dc95e /numpy | |
parent | ec53dd5cac4175116048d847f74076e05b6b1a6a (diff) | |
download | numpy-00f2295ec55239ce35687a20a7c58d1583b068f1.tar.gz |
Added more debugging hooks to PackageLoader: NUMPY_IMPORT_DEBUG. Avoid initiating Scipy/NumpyTest during imports.
Diffstat (limited to 'numpy')
-rw-r--r-- | numpy/__init__.py | 7 | ||||
-rw-r--r-- | numpy/_import_tools.py | 14 | ||||
-rw-r--r-- | numpy/core/__init__.py | 5 | ||||
-rw-r--r-- | numpy/dft/__init__.py | 6 | ||||
-rw-r--r-- | numpy/lib/__init__.py | 5 | ||||
-rw-r--r-- | numpy/lib/function_base.py | 1 | ||||
-rw-r--r-- | numpy/linalg/__init__.py | 5 | ||||
-rw-r--r-- | numpy/linalg/linalg.py | 7 | ||||
-rw-r--r-- | numpy/random/__init__.py | 5 | ||||
-rw-r--r-- | numpy/testing/info.py | 2 | ||||
-rw-r--r-- | numpy/testing/utils.py | 17 |
11 files changed, 51 insertions, 23 deletions
diff --git a/numpy/__init__.py b/numpy/__init__.py index a945c75a5..00acd3f40 100644 --- a/numpy/__init__.py +++ b/numpy/__init__.py @@ -31,7 +31,8 @@ else: del _os from _import_tools import PackageLoader pkgload = PackageLoader() - pkgload('testing','core','linalg','lib','dft','random','f2py','distutils', + pkgload('testing','core','lib','linalg','dft','random','f2py', + 'distutils', verbose=NUMPY_IMPORT_VERBOSE,postpone=False) __doc__ += """ @@ -41,7 +42,9 @@ Available subpackages """ __doc__ += pkgload.get_pkgdocs() - test = ScipyTest('numpy').test + def test(level=1, verbosity=1): + return NumpyTest('numpy').test(level, verbosity) + import add_newdocs __doc__ += """ diff --git a/numpy/_import_tools.py b/numpy/_import_tools.py index 5d4e66de1..4989ab340 100644 --- a/numpy/_import_tools.py +++ b/numpy/_import_tools.py @@ -327,3 +327,17 @@ class PackageLoader: self._format_titles(symbols,'-->') return retstr + +class PackageLoaderDebug(PackageLoader): + def _execcmd(self,cmdstr): + """ Execute command in parent_frame.""" + frame = self.parent_frame + print 'Executing',`cmdstr`,'...', + sys.stdout.flush() + exec (cmdstr, frame.f_globals,frame.f_locals) + print 'ok' + sys.stdout.flush() + return + +if int(os.environ.get('NUMPY_IMPORT_DEBUG','0')): + PackageLoader = PackageLoaderDebug diff --git a/numpy/core/__init__.py b/numpy/core/__init__.py index af57f0f69..429e423c5 100644 --- a/numpy/core/__init__.py +++ b/numpy/core/__init__.py @@ -25,5 +25,6 @@ __all__ += defmatrix.__all__ __all__ += rec.__all__ __all__ += char.__all__ -from numpy.testing import ScipyTest -test = ScipyTest().test +def test(level=1, verbosity=1): + from numpy.testing import NumpyTest + return NumpyTest().test(level, verbosity) diff --git a/numpy/dft/__init__.py b/numpy/dft/__init__.py index 236aefdcb..817c99bc8 100644 --- a/numpy/dft/__init__.py +++ b/numpy/dft/__init__.py @@ -4,5 +4,7 @@ from info import __doc__ from fftpack import * from helper import * -from numpy.testing import ScipyTest -test = ScipyTest().test +def test(level=1, verbosity=1): + from numpy.testing import NumpyTest + return NumpyTest().test(level, verbosity) + diff --git a/numpy/lib/__init__.py b/numpy/lib/__init__.py index 8b470d07f..a7de2e13f 100644 --- a/numpy/lib/__init__.py +++ b/numpy/lib/__init__.py @@ -30,5 +30,6 @@ __all__ += getlimits.__all__ __all__ += utils.__all__ __all__ += arraysetops.__all__ -from numpy.testing import ScipyTest -test = ScipyTest().test +def test(level=1, verbosity=1): + from numpy.testing import NumpyTest + return NumpyTest().test(level, verbosity) diff --git a/numpy/lib/function_base.py b/numpy/lib/function_base.py index cee17b0aa..4aa891c4e 100644 --- a/numpy/lib/function_base.py +++ b/numpy/lib/function_base.py @@ -11,7 +11,6 @@ __all__ = ['logspace', 'linspace', ] import types -import math import numpy.core.numeric as _nx from numpy.core.numeric import ones, zeros, arange, concatenate, array, \ asarray, empty, empty_like, asanyarray diff --git a/numpy/linalg/__init__.py b/numpy/linalg/__init__.py index 42df37663..287b3959e 100644 --- a/numpy/linalg/__init__.py +++ b/numpy/linalg/__init__.py @@ -3,5 +3,6 @@ from info import __doc__ from linalg import * -from numpy.testing import ScipyTest -test = ScipyTest().test +def test(level=1, verbosity=1): + from numpy.testing import NumpyTest + return NumpyTest().test(level, verbosity) diff --git a/numpy/linalg/linalg.py b/numpy/linalg/linalg.py index 3c92d7d77..58bc9fbff 100644 --- a/numpy/linalg/linalg.py +++ b/numpy/linalg/linalg.py @@ -10,12 +10,12 @@ __all__ = ['LinAlgError', 'solve_linear_equations', 'solve', 'inverse', 'inv', 'cholesky_decomposition', 'cholesky', 'eigenvalues', 'eigvals', 'Heigenvalues', 'eigvalsh', 'generalized_inverse', 'pinv', 'determinant', 'det', 'singular_value_decomposition', 'svd', - 'eigenvectors', 'eig', 'Heigenvectors', 'eigh','lstsq', 'linear_least_squares' + 'eigenvectors', 'eig', 'Heigenvectors', 'eigh','lstsq', + 'linear_least_squares' ] -from numpy import * +from numpy.core import * import lapack_lite -import math # Error object class LinAlgError(Exception): @@ -422,6 +422,7 @@ the number of rows, then residuals will be returned as an empty array otherwise resids = sum((b-dot(A,x)**2). Singular values less than s[0]*rcond are treated as zero. """ + import math a = asarray(a) b, wrap = _makearray(b) one_eq = len(b.shape) == 1 diff --git a/numpy/random/__init__.py b/numpy/random/__init__.py index 8dc354e81..13d0e3a22 100644 --- a/numpy/random/__init__.py +++ b/numpy/random/__init__.py @@ -13,5 +13,6 @@ def __RandomState_ctor(): """ return RandomState() -from numpy.testing import ScipyTest -test = ScipyTest().test +def test(level=1, verbosity=1): + from numpy.testing import NumpyTest + return NumpyTest().test(level, verbosity) diff --git a/numpy/testing/info.py b/numpy/testing/info.py index 9b5caa074..80dc00ddf 100644 --- a/numpy/testing/info.py +++ b/numpy/testing/info.py @@ -27,4 +27,4 @@ Utility functions """ -global_symbols = ['ScipyTest'] +global_symbols = ['ScipyTest','NumpyTest'] diff --git a/numpy/testing/utils.py b/numpy/testing/utils.py index 4ea19c270..fe3a3c093 100644 --- a/numpy/testing/utils.py +++ b/numpy/testing/utils.py @@ -4,8 +4,6 @@ Utility function to facilitate testing. import os import sys -import time -import math __all__ = ['assert_equal', 'assert_almost_equal','assert_approx_equal', 'assert_array_equal', 'assert_array_less', @@ -27,16 +25,19 @@ def rand(*args): if sys.platform[:5]=='linux': def jiffies(_proc_pid_stat = '/proc/%s/stat'%(os.getpid()), - _load_time=time.time()): + _load_time=[]): """ Return number of jiffies (1/100ths of a second) that this process has been scheduled in user mode. See man 5 proc. """ + import time + if not _load_time: + _load_time.append(time.time()) try: f=open(_proc_pid_stat,'r') l = f.readline().split(' ') f.close() return int(l[13]) except: - return int(100*(time.time()-_load_time)) + return int(100*(time.time()-_load_time[0])) def memusage(_proc_pid_stat = '/proc/%s/stat'%(os.getpid())): """ Return virtual memory size in bytes of the running python. @@ -52,10 +53,13 @@ else: # os.getpid is not in all platforms available. # Using time is safe but inaccurate, especially when process # was suspended or sleeping. - def jiffies(_load_time=time.time()): + def jiffies(_load_time=[]): """ Return number of jiffies (1/100ths of a second) that this process has been scheduled in user mode. [Emulation with time.time]. """ - return int(100*(time.time()-_load_time)) + import time + if not _load_time: + _load_time.append(time.time()) + return int(100*(time.time()-_load_time[0])) def memusage(): """ Return memory usage of running python. [Not implemented]""" return @@ -150,6 +154,7 @@ def assert_approx_equal(actual,desired,significant=7,err_msg='',verbose=1): Approximately equal is defined as the number of significant digits correct """ + import math msg = '\nItems are not equal to %d significant digits:\n' % significant msg += err_msg actual, desired = map(float, (actual, desired)) |