diff options
author | Travis Oliphant <oliphant@enthought.com> | 2006-01-19 02:44:55 +0000 |
---|---|---|
committer | Travis Oliphant <oliphant@enthought.com> | 2006-01-19 02:44:55 +0000 |
commit | 107c7d31a655be8fdf0c58ea7274ec98149d56fd (patch) | |
tree | 6a26ab63afa3104cb8717cc31b697e44125aad45 /numpy/dual.py | |
parent | f7d8a57f0818f294fdd49c5025273075dd168704 (diff) | |
download | numpy-107c7d31a655be8fdf0c58ea7274ec98149d56fd.tar.gz |
Use a register_func system for altering functions in numpy.dual
Diffstat (limited to 'numpy/dual.py')
-rw-r--r-- | numpy/dual.py | 43 |
1 files changed, 22 insertions, 21 deletions
diff --git a/numpy/dual.py b/numpy/dual.py index 0dc289e38..00a1f04fa 100644 --- a/numpy/dual.py +++ b/numpy/dual.py @@ -7,27 +7,11 @@ __all__ = ['fft','ifft','fftn','ifftn','fft2','ifft2', 'inv','svd','solve','det','eig','eigvals','lstsq', 'pinv','cholesky','i0'] -# First check to see that scipy is "new" scipy -# Perhaps we could check to see if the functions actually work in -# the scipy that will be imported. - - -have_scipy = 0 -try: - import scipy - if getattr(scipy, '__version__', None) >= '0.4.4': - have_scipy = 1 -except ImportError: - pass - -if have_scipy: - import scipy.linalg as linpkg - import scipy.fftpack as fftpkg - from scipy.special import i0 -else: - import numpy.linalg as linpkg - import numpy.dft as fftpkg - from numpy.lib import i0 +import numpy.linalg as linpkg +import numpy.dft as fftpkg +from numpy.lib import i0 +import sys + fft = fftpkg.fft ifft = fftpkg.ifft @@ -46,3 +30,20 @@ lstsq = linpkg.lstsq pinv = linpkg.pinv cholesky = linpkg.cholesky +_restore_dict = {} + +def register_func(name, func): + if name not in __all__: + raise ValueError, "%s not a dual function." % name + f = sys._getframe(0).f_globals + _restore_dict[name] = f[name] + f[name] = func + +def restore_func(name): + if name not in __all__: + raise ValueError, "%s not a dual function." % name + try: + sys._getframe(0).f_globals[name] = _restore_dict[name] + except KeyError: + pass + |