|
1 | | -""" |
2 | | -numerix imports either Numeric or numarray based on various selectors. |
| 1 | +import sys |
3 | 2 |
|
4 | | -0. If the value "--numpy","--numarray" or "--Numeric" is specified on the |
5 | | - command line, then numerix imports the specified |
6 | | - array package. |
7 | | -
|
8 | | -1. The value of numerix in matplotlibrc: either Numeric or numarray |
9 | | -
|
10 | | -2. If none of the above is done, the default array package is Numeric. |
11 | | - Because the matplotlibrc always provides *some* value for numerix |
12 | | - (it has it's own system of default values), this default is most |
13 | | - likely never used. |
14 | | -
|
15 | | -To summarize: the commandline is examined first, the rc file second, |
16 | | -and the default array package is Numeric. |
17 | | -""" |
18 | | - |
19 | | -import sys, os, struct |
20 | | -from matplotlib import rcParams, verbose |
21 | | - |
22 | | -which = None, None |
23 | 3 | use_maskedarray = None |
24 | 4 |
|
25 | | -# First, see if --numarray or --Numeric was specified on the command |
26 | | -# line: |
27 | | - |
28 | 5 | for a in sys.argv: |
29 | | - if a in ["--Numeric", "--numeric", "--NUMERIC", |
30 | | - "--Numarray", "--numarray", "--NUMARRAY", |
31 | | - "--NumPy", "--numpy", "--NUMPY", "--Numpy", |
32 | | - ]: |
33 | | - which = a[2:], "command line" |
34 | 6 | if a == "--maskedarray": |
35 | 7 | use_maskedarray = True |
36 | 8 | if a == "--ma": |
37 | 9 | use_maskedarray = False |
38 | 10 | del a |
39 | 11 |
|
40 | | -if which[0] is None: |
41 | | - try: # In theory, rcParams always has *some* value for numerix. |
42 | | - which = rcParams['numerix'], "rc" |
43 | | - except KeyError: |
44 | | - pass |
45 | | - |
46 | 12 | if use_maskedarray is None: |
| 13 | + import matplotlib |
47 | 14 | try: |
48 | | - use_maskedarray = rcParams['maskedarray'] |
| 15 | + use_maskedarray = matplotlib.rcParams['maskedarray'] |
49 | 16 | except KeyError: |
50 | 17 | use_maskedarray = False |
51 | 18 |
|
52 | | -# If all the above fail, default to Numeric. Most likely not used. |
53 | | -if which[0] is None: |
54 | | - which = "numeric", "defaulted" |
55 | | - |
56 | | -which = which[0].strip().lower(), which[1] |
57 | | -if which[0] not in ["numeric", "numarray", "numpy"]: |
58 | | - raise ValueError("numerix selector must be either 'Numeric', 'numarray', or 'numpy' but the value obtained from the %s was '%s'." % (which[1], which[0])) |
59 | | - |
60 | | -if which[0] == "numarray": |
61 | | - import warnings |
62 | | - warnings.warn("numarray use as a numerix backed for matplotlib is deprecated", |
63 | | - DeprecationWarning, stacklevel=1) |
64 | | - |
65 | | - #from na_imports import * |
66 | | - from numarray import * |
67 | | - from _na_imports import nx, inf, infinity, Infinity, Matrix, isnan, all |
68 | | - from numarray.numeric import nonzero |
69 | | - from numarray.convolve import cross_correlate, convolve |
70 | | - import numarray |
71 | | - version = 'numarray %s'%numarray.__version__ |
72 | | - nan = struct.unpack('d', struct.pack('Q', 0x7ff8000000000000))[0] |
| 19 | +######################### |
73 | 20 |
|
74 | | -elif which[0] == "numeric": |
75 | | - import warnings |
76 | | - warnings.warn("Numeric use as a numerix backed for matplotlib is deprecated", |
77 | | - DeprecationWarning, stacklevel=1) |
| 21 | +from numpy import * |
78 | 22 |
|
79 | | - #from nc_imports import * |
80 | | - from Numeric import * |
81 | | - from _nc_imports import nx, inf, infinity, Infinity, isnan, all, any |
82 | | - from Matrix import Matrix |
83 | | - import Numeric |
84 | | - version = 'Numeric %s'%Numeric.__version__ |
85 | | - nan = struct.unpack('d', struct.pack('Q', 0x7ff8000000000000))[0] |
| 23 | +######################### |
86 | 24 |
|
87 | | -elif which[0] == "numpy": |
88 | | - try: |
89 | | - import numpy.oldnumeric as numpy |
90 | | - from numpy.oldnumeric import * |
91 | | - except ImportError: |
92 | | - import numpy |
93 | | - from numpy import * |
94 | | - print 'except asarray', asarray |
95 | | - from _sp_imports import nx, infinity, rand, randn, isnan, all, any |
96 | | - from _sp_imports import UInt8, UInt16, UInt32, Infinity |
97 | | - try: |
98 | | - from numpy.oldnumeric.matrix import Matrix |
99 | | - except ImportError: |
100 | | - Matrix = matrix |
101 | | - version = 'numpy %s' % numpy.__version__ |
102 | | - from numpy import nan |
103 | | -else: |
104 | | - raise RuntimeError("invalid numerix selector") |
105 | | - |
106 | | - |
107 | | -# Some changes are only applicable to the new numpy: |
108 | | -if (which[0] == 'numarray' or |
109 | | - which[0] == 'numeric'): |
110 | | - from mlab import amin, amax |
111 | | - newaxis = NewAxis |
112 | | - def typecode(a): |
113 | | - return a.typecode() |
114 | | - def iscontiguous(a): |
115 | | - return a.iscontiguous() |
116 | | - def byteswapped(a): |
117 | | - return a.byteswapped() |
118 | | - def itemsize(a): |
119 | | - return a.itemsize() |
120 | | - def angle(a): |
121 | | - return arctan2(a.imag, a.real) |
122 | | - |
123 | | -else: |
124 | | - # We've already checked for a valid numerix selector, |
125 | | - # so assume numpy. |
126 | | - from mlab import amin, amax |
127 | | - newaxis = NewAxis |
128 | | - from numpy import angle |
129 | | - def typecode(a): |
130 | | - return a.dtype.char |
131 | | - def iscontiguous(a): |
132 | | - return a.flags.contiguous |
133 | | - def byteswapped(a): |
134 | | - return a.byteswap() |
135 | | - def itemsize(a): |
136 | | - return a.itemsize |
137 | | - |
138 | | -verbose.report('numerix %s'%version) |
139 | | -# a bug fix for blas numeric suggested by Fernando Perez |
140 | | -matrixmultiply=dot |
141 | 25 | asum = sum |
142 | | - |
143 | | - |
144 | | -def _import_fail_message(module, version): |
145 | | - """Prints a message when the array package specific version of an extension |
146 | | - fails to import correctly. |
147 | | - """ |
148 | | - _dict = { "which" : which[0], |
149 | | - "module" : module, |
150 | | - "specific" : version + module |
151 | | - } |
152 | | - print """ |
153 | | -The import of the %(which)s version of the %(module)s module, |
154 | | -%(specific)s, failed. This is is either because %(which)s was |
155 | | -unavailable when matplotlib was compiled, because a dependency of |
156 | | -%(specific)s could not be satisfied, or because the build flag for |
157 | | -this module was turned off in setup.py. If it appears that |
158 | | -%(specific)s was not built, make sure you have a working copy of |
159 | | -%(which)s and then re-install matplotlib. Otherwise, the following |
160 | | -traceback gives more details:\n""" % _dict |
161 | | - |
162 | | -g = globals() |
163 | | -l = locals() |
164 | | -__import__('ma', g, l) |
165 | | -__import__('fft', g, l) |
166 | | -__import__('linear_algebra', g, l) |
167 | | -__import__('random_array', g, l) |
168 | | -__import__('mlab', g, l) |
169 | | - |
170 | | -la = linear_algebra |
171 | | -ra = random_array |
| 26 | +matrixmultiply = dot |
| 27 | + |
| 28 | +#from numpy.oldnumeric import * |
| 29 | +from numpy.oldnumeric import \ |
| 30 | + ArrayType, cross_correlate, NewAxis, \ |
| 31 | + arrayrange, innerproduct, outerproduct |
| 32 | + |
| 33 | +newaxis = NewAxis |
| 34 | + |
| 35 | +from numpy.oldnumeric import Int8, UInt8, \ |
| 36 | + Int16, UInt16, \ |
| 37 | + Int32, UInt32, \ |
| 38 | + Float32, Float64, \ |
| 39 | + Complex32, Complex64, \ |
| 40 | + Float, Int, Complex |
| 41 | + |
| 42 | +from numpy.oldnumeric.matrix import Matrix |
| 43 | + |
| 44 | +from numpy.oldnumeric.mlab import min as amin |
| 45 | +from numpy.oldnumeric.mlab import max as amax |
| 46 | + |
| 47 | +def typecode(a): |
| 48 | + return a.dtype.char |
| 49 | +def iscontiguous(a): |
| 50 | + return a.flags.contiguous |
| 51 | +def byteswapped(a): |
| 52 | + return a.byteswap() |
| 53 | +def itemsize(a): |
| 54 | + return a.itemsize |
0 commit comments