~ubuntu-branches/ubuntu/feisty/python-numpy/feisty

« back to all changes in this revision

Viewing changes to numpy/dual.py

  • Committer: Bazaar Package Importer
  • Author(s): Matthias Klose
  • Date: 2006-07-12 10:00:24 UTC
  • Revision ID: james.westby@ubuntu.com-20060712100024-5lw9q2yczlisqcrt
Tags: upstream-0.9.8
ImportĀ upstreamĀ versionĀ 0.9.8

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
# This module should be used for functions both in numpy and scipy if
 
2
#  you want to use the numpy version if available but the scipy version
 
3
#  otherwise.
 
4
#  Usage  --- from numpy.dual import fft, inv
 
5
 
 
6
__all__ = ['fft','ifft','fftn','ifftn','fft2','ifft2',
 
7
           'norm','inv','svd','solve','det','eig','eigvals',
 
8
           'eigh','eigvalsh','lstsq', 'pinv','cholesky','i0']
 
9
 
 
10
import numpy.linalg as linpkg
 
11
import numpy.dft as fftpkg
 
12
from numpy.lib import i0
 
13
import sys
 
14
 
 
15
 
 
16
fft = fftpkg.fft
 
17
ifft = fftpkg.ifft
 
18
fftn = fftpkg.fftn
 
19
ifftn = fftpkg.ifftn
 
20
fft2 = fftpkg.fft2
 
21
ifft2 = fftpkg.ifft2
 
22
 
 
23
norm = linpkg.norm
 
24
inv = linpkg.inv
 
25
svd = linpkg.svd
 
26
solve = linpkg.solve
 
27
det = linpkg.det
 
28
eig = linpkg.eig
 
29
eigvals = linpkg.eigvals
 
30
eigh = linpkg.eigh
 
31
eigvalsh = linpkg.eigvalsh
 
32
lstsq = linpkg.lstsq
 
33
pinv = linpkg.pinv
 
34
cholesky = linpkg.cholesky
 
35
 
 
36
_restore_dict = {}
 
37
 
 
38
def register_func(name, func):
 
39
    if name not in __all__:
 
40
        raise ValueError, "%s not a dual function." % name
 
41
    f = sys._getframe(0).f_globals
 
42
    _restore_dict[name] = f[name]
 
43
    f[name] = func
 
44
 
 
45
def restore_func(name):
 
46
    if name not in __all__:
 
47
        raise ValueError, "%s not a dual function." % name
 
48
    try:
 
49
        val = _restore_dict[name]
 
50
    except KeyError:
 
51
        return
 
52
    else:
 
53
        sys._getframe(0).f_globals[name] = val
 
54
 
 
55
def restore_all():
 
56
    for name in _restore_dict.keys():
 
57
        restore_func(name)