1 """This is a compatibility module, allowing python to work
2 with either scipy, Numeric, or numarray.
3 It tries to import them, in that order, only reporting
4 an error if none are available.
5
6 Note that this does not pretend to solve all compatibility
7 problems; it just tries importing all three, so you can only
8 count on the lowest common denominator.
9 """
10
13 self.name = name
14 self.mod = None
15 self.aliases = aliases
16
18 mod = object.__getattribute__(self, 'mod')
19 if mod is None:
20 mname = object.__getattribute__(self, 'name')
21 mod = __import__(mname)
22 a = mname.split('.')
23 for dot in a[1:]:
24 mod = getattr(mod, dot)
25 self.mod = mod
26 for (nn, on) in object.__getattribute__(self, 'aliases'):
27 setattr(mod, nn, getattr(mod, on))
28 return getattr(mod, aname)
29
30
31 array = None
32 try:
33 from numpy import *
34 LA = _delayed_import('numpy.linalg',
35 [
36 ('linear_least_squares', 'lstsq'),
37 ('singular_value_decomposition', 'svd')
38 ]
39 )
40 RA = _delayed_import('numpy.random')
41 FFT = _delayed_import('numpy.fft',
42 [
43 ('inverse_fft', 'ifft'), ('real_fft', 'rfft'),
44 ('inverse_real_fft', 'irfft')
45 ]
46 )
47 Float = double
48 float = float
49 Int = int0
50 Int32 = int32
51 Int16 = int16
52 Int8 = int8
53 Complex = complex_
54 arrayrange = arange
55 matrixmultiply = dot
56 outerproduct = outer
57 NewAxis = newaxis
58 except ImportError:
59 pass
60
61 if array is None:
62 try:
63 from Numeric import *
64 RA = _delayed_import('RandomArray')
65 LA = _delayed_import('LinearAlgebra')
66 FFT = _delayed_import('FFT')
67 except ImportError:
68 pass
69
70
71
72 if array is None:
73 try:
74 from numarray import *
75 except ImportError:
76 raise ImportError, "No module named either numpy, Numeric or numarray"
77
78 assert FFT
79 assert LA
80 assert RA
81