Blame numpy/dual.py

Packit 7a8e5e
"""
Packit 7a8e5e
Aliases for functions which may be accelerated by Scipy.
Packit 7a8e5e
Packit 7a8e5e
Scipy_ can be built to use accelerated or otherwise improved libraries
Packit 7a8e5e
for FFTs, linear algebra, and special functions. This module allows
Packit 7a8e5e
developers to transparently support these accelerated functions when
Packit 7a8e5e
scipy is available but still support users who have only installed
Packit 7a8e5e
NumPy.
Packit 7a8e5e
Packit 7a8e5e
.. _Scipy : http://www.scipy.org
Packit 7a8e5e
Packit 7a8e5e
"""
Packit 7a8e5e
from __future__ import division, absolute_import, print_function
Packit 7a8e5e
Packit 7a8e5e
# This module should be used for functions both in numpy and scipy if
Packit 7a8e5e
#  you want to use the numpy version if available but the scipy version
Packit 7a8e5e
#  otherwise.
Packit 7a8e5e
#  Usage  --- from numpy.dual import fft, inv
Packit 7a8e5e
Packit 7a8e5e
__all__ = ['fft', 'ifft', 'fftn', 'ifftn', 'fft2', 'ifft2',
Packit 7a8e5e
           'norm', 'inv', 'svd', 'solve', 'det', 'eig', 'eigvals',
Packit 7a8e5e
           'eigh', 'eigvalsh', 'lstsq', 'pinv', 'cholesky', 'i0']
Packit 7a8e5e
Packit 7a8e5e
import numpy.linalg as linpkg
Packit 7a8e5e
import numpy.fft as fftpkg
Packit 7a8e5e
from numpy.lib import i0
Packit 7a8e5e
import sys
Packit 7a8e5e
Packit 7a8e5e
Packit 7a8e5e
fft = fftpkg.fft
Packit 7a8e5e
ifft = fftpkg.ifft
Packit 7a8e5e
fftn = fftpkg.fftn
Packit 7a8e5e
ifftn = fftpkg.ifftn
Packit 7a8e5e
fft2 = fftpkg.fft2
Packit 7a8e5e
ifft2 = fftpkg.ifft2
Packit 7a8e5e
Packit 7a8e5e
norm = linpkg.norm
Packit 7a8e5e
inv = linpkg.inv
Packit 7a8e5e
svd = linpkg.svd
Packit 7a8e5e
solve = linpkg.solve
Packit 7a8e5e
det = linpkg.det
Packit 7a8e5e
eig = linpkg.eig
Packit 7a8e5e
eigvals = linpkg.eigvals
Packit 7a8e5e
eigh = linpkg.eigh
Packit 7a8e5e
eigvalsh = linpkg.eigvalsh
Packit 7a8e5e
lstsq = linpkg.lstsq
Packit 7a8e5e
pinv = linpkg.pinv
Packit 7a8e5e
cholesky = linpkg.cholesky
Packit 7a8e5e
Packit 7a8e5e
_restore_dict = {}
Packit 7a8e5e
Packit 7a8e5e
def register_func(name, func):
Packit 7a8e5e
    if name not in __all__:
Packit 7a8e5e
        raise ValueError("%s not a dual function." % name)
Packit 7a8e5e
    f = sys._getframe(0).f_globals
Packit 7a8e5e
    _restore_dict[name] = f[name]
Packit 7a8e5e
    f[name] = func
Packit 7a8e5e
Packit 7a8e5e
def restore_func(name):
Packit 7a8e5e
    if name not in __all__:
Packit 7a8e5e
        raise ValueError("%s not a dual function." % name)
Packit 7a8e5e
    try:
Packit 7a8e5e
        val = _restore_dict[name]
Packit 7a8e5e
    except KeyError:
Packit 7a8e5e
        return
Packit 7a8e5e
    else:
Packit 7a8e5e
        sys._getframe(0).f_globals[name] = val
Packit 7a8e5e
Packit 7a8e5e
def restore_all():
Packit 7a8e5e
    for name in _restore_dict.keys():
Packit 7a8e5e
        restore_func(name)