jpayne@69: """ jpayne@69: .. deprecated:: 1.20 jpayne@69: jpayne@69: *This module is deprecated. Instead of importing functions from* jpayne@69: ``numpy.dual``, *the functions should be imported directly from NumPy jpayne@69: or SciPy*. jpayne@69: jpayne@69: Aliases for functions which may be accelerated by SciPy. jpayne@69: jpayne@69: SciPy_ can be built to use accelerated or otherwise improved libraries jpayne@69: for FFTs, linear algebra, and special functions. This module allows jpayne@69: developers to transparently support these accelerated functions when jpayne@69: SciPy is available but still support users who have only installed jpayne@69: NumPy. jpayne@69: jpayne@69: .. _SciPy : https://www.scipy.org jpayne@69: jpayne@69: """ jpayne@69: import warnings jpayne@69: jpayne@69: jpayne@69: warnings.warn('The module numpy.dual is deprecated. Instead of using dual, ' jpayne@69: 'use the functions directly from numpy or scipy.', jpayne@69: category=DeprecationWarning, jpayne@69: stacklevel=2) jpayne@69: jpayne@69: # This module should be used for functions both in numpy and scipy if jpayne@69: # you want to use the numpy version if available but the scipy version jpayne@69: # otherwise. jpayne@69: # Usage --- from numpy.dual import fft, inv jpayne@69: jpayne@69: __all__ = ['fft', 'ifft', 'fftn', 'ifftn', 'fft2', 'ifft2', jpayne@69: 'norm', 'inv', 'svd', 'solve', 'det', 'eig', 'eigvals', jpayne@69: 'eigh', 'eigvalsh', 'lstsq', 'pinv', 'cholesky', 'i0'] jpayne@69: jpayne@69: import numpy.linalg as linpkg jpayne@69: import numpy.fft as fftpkg jpayne@69: from numpy.lib import i0 jpayne@69: import sys jpayne@69: jpayne@69: jpayne@69: fft = fftpkg.fft jpayne@69: ifft = fftpkg.ifft jpayne@69: fftn = fftpkg.fftn jpayne@69: ifftn = fftpkg.ifftn jpayne@69: fft2 = fftpkg.fft2 jpayne@69: ifft2 = fftpkg.ifft2 jpayne@69: jpayne@69: norm = linpkg.norm jpayne@69: inv = linpkg.inv jpayne@69: svd = linpkg.svd jpayne@69: solve = linpkg.solve jpayne@69: det = linpkg.det jpayne@69: eig = linpkg.eig jpayne@69: eigvals = linpkg.eigvals jpayne@69: eigh = linpkg.eigh jpayne@69: eigvalsh = linpkg.eigvalsh jpayne@69: lstsq = linpkg.lstsq jpayne@69: pinv = linpkg.pinv jpayne@69: cholesky = linpkg.cholesky jpayne@69: jpayne@69: _restore_dict = {} jpayne@69: jpayne@69: def register_func(name, func): jpayne@69: if name not in __all__: jpayne@69: raise ValueError("{} not a dual function.".format(name)) jpayne@69: f = sys._getframe(0).f_globals jpayne@69: _restore_dict[name] = f[name] jpayne@69: f[name] = func jpayne@69: jpayne@69: def restore_func(name): jpayne@69: if name not in __all__: jpayne@69: raise ValueError("{} not a dual function.".format(name)) jpayne@69: try: jpayne@69: val = _restore_dict[name] jpayne@69: except KeyError: jpayne@69: return jpayne@69: else: jpayne@69: sys._getframe(0).f_globals[name] = val jpayne@69: jpayne@69: def restore_all(): jpayne@69: for name in _restore_dict.keys(): jpayne@69: restore_func(name)