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