1 --- ./PyDDE/__init__.py
2 +++ ./PyDDE/__init__.py (refactored)
5 -print "Loaded package PyDDE, Version 0.2.2."
6 +print("Loaded package PyDDE, Version 0.2.2.")
8 +++ ./PyDDE/pydde.py (refactored)
16 from Numeric import array, zeros, concatenate
19 from numpy import array, zeros, concatenate
21 - print "Error: could not import either Numeric or SciPy."
22 - print "Please check that at least one of these is installed before using PyDDE."
23 - raise ImportError, 'PyDDE.pydde'
24 + print("Error: could not import either Numeric or SciPy.")
25 + print("Please check that at least one of these is installed before using PyDDE.")
26 + raise ImportError('PyDDE.pydde')
29 import PyDDE.ddesolve as _ddesolve
31 - print "Error: could not import the ddesolve integration routines! The solver is non-functional."
32 + print("Error: could not import the ddesolve integration routines! The solver is non-functional.")
34 - raise ImportError, 'PyDDE.pydde'
35 + raise ImportError('PyDDE.pydde')
43 - print "DDE Warning: something went wrong during initialisation."
44 + print("DDE Warning: something went wrong during initialisation.")
50 # Check that the supplied functions are callable.
52 - if not(callable(grad)):
53 - raise(TypeError,"grad")
54 - if not(callable(switchfunctions)):
55 - raise(TypeError,"switchfunctions")
56 - if not(callable(maps)):
57 - raise(TypeError,"maps")
58 - if not(callable(storehistory)):
59 - raise(TypeError,"storehistory")
60 - except TypeError, errstr:
61 - print "DDE Error: User supplied function not callable:", errstr
62 - print "DDE Error: Problem initialisation failed!"
63 + if not(isinstance(grad, collections.Callable)):
65 + if not(isinstance(switchfunctions, collections.Callable)):
67 + if not(isinstance(maps, collections.Callable)):
69 + if not(isinstance(storehistory, collections.Callable)):
71 + except TypeError as errstr:
72 + print("DDE Error: User supplied function not callable:", errstr)
73 + print("DDE Error: Problem initialisation failed!")
76 # Check that the number of constants and variables are reasonable.
79 - raise(TypeError, "no_vars")
80 - except TypeError, errstr:
81 - print "DDE Error: Number of state variables not positive:", errstr
83 + except TypeError as errstr:
84 + print("DDE Error: Number of state variables not positive:", errstr)
87 if (no_cons != len(c)):
88 - print "DDE Warning: Number of constants no_cons reset to agree with length of constants array c."
89 + print("DDE Warning: Number of constants no_cons reset to agree with length of constants array c.")
92 # check that the state scale is of the appropriate length
95 g = grad(initstate,c,t0)
96 if (len(g) != no_vars):
97 - raise(IndexError,"grad")
100 sw = switchfunctions(initstate,c,t0)
102 - raise(IndexError,"switchfunctions")
105 ms,mc = maps(initstate,c,t0,i)
106 if ((len(ms) != no_vars) or (len(mc) != no_cons)):
107 - raise(IndexError,"maps")
108 - except IndexError, errstr:
109 - print "DDE Error: Output of user supplied function incorrect:", errstr
110 - print "DDE Error: Problem initialisation failed!"
112 + except IndexError as errstr:
113 + print("DDE Error: Output of user supplied function incorrect:", errstr)
114 + print("DDE Error: Problem initialisation failed!")
118 self.PROB = (int(no_vars), int(no_cons), # number of variables and constants
119 int(no_vars), int(nlag), int(nsw), int(len(otimes)),
120 float(t0), float(t1),
121 - array(map(float,initstate)), array(map(float,c)), array(map(float,otimes)),
122 + array(list(map(float,initstate))), array(list(map(float,c))), array(list(map(float,otimes))),
123 grad, switchfunctions, maps, storehistory)
125 - print "DDE Error: Something is wrong: perhaps one of the supplied variables has the wrong type?"
126 - print "DDE Error: Problem initialisation failed!"
127 + print("DDE Error: Something is wrong: perhaps one of the supplied variables has the wrong type?")
128 + print("DDE Error: Problem initialisation failed!")
132 @@ -207,10 +208,10 @@
134 self.SOLVER = (float(tol), int(hbsize),
135 float(dt), # output and integration timesteps
136 - array(map(float,statescale)))
137 + array(list(map(float,statescale))))
139 - print "DDE Error: Something is wrong: perhaps one of the supplied variables has the wrong type?"
140 - print "DDE Error: Solver initialisation failed!"
141 + print("DDE Error: Something is wrong: perhaps one of the supplied variables has the wrong type?")
142 + print("DDE Error: Solver initialisation failed!")
146 @@ -237,16 +238,16 @@
152 - print "DDE Error: Solver thinks the solution is already given in the <instance>.data.\n \
153 - To force the solver to run again, use <instance>.solve(again=1)"
154 + print(self._solved)
156 + print("DDE Error: Solver thinks the solution is already given in the <instance>.data.\n \
157 + To force the solver to run again, use <instance>.solve(again=1)")
159 except AssertionError:
160 - print "DDE Error: The DDE has not been properly initialised!"
161 + print("DDE Error: The DDE has not been properly initialised!")
164 - print "DDE Error: Solution failed!"
165 + print("DDE Error: Solution failed!")
171 assert(_ddesolve.clean(wipe))
172 except AssertionError:
173 - print "DDE Error: Problem cleaning up after the solver."
174 + print("DDE Error: Problem cleaning up after the solver.")
178 --- ./PyDDE/test/test.py
179 +++ ./PyDDE/test/test.py (refactored)
182 from Numeric import *
184 - print "Could not import Numeric, numpy and scipy. Test cannot run."
185 - raise StandardError, "PyDDE test script."
186 + print("Could not import Numeric, numpy and scipy. Test cannot run.")
187 + raise Exception("PyDDE test script.")
190 import PyDDE.pydde as p
192 - print "Could not import PyDDE.pydde. Test cannot run."
193 - raise StandardError, "PyDDE test script."
194 + print("Could not import PyDDE.pydde. Test cannot run.")
195 + raise Exception("PyDDE test script.")
201 - print "Could not import timing module. No timing of tests will occur."
202 + print("Could not import timing module. No timing of tests will occur.")
210 - print "DDE Test: Running for the first time..."
211 + print("DDE Test: Running for the first time...")
219 - print "DDE Test: Running for the first time..."
220 + print("DDE Test: Running for the first time...")
228 - print "DDE Test: Running for the first time..."
229 + print("DDE Test: Running for the first time...")
237 - print str(timing.seconds())+"."+str(timing.milli())+" seconds"
238 + print(str(timing.seconds())+"."+str(timing.milli())+" seconds")
243 sddepp.writeEPSfile("../test/sdde_eg.eps")
246 - print "DDE Test: Could not import PyX! Cannot print output from examples."
248 - print "DDE Test: An error occured during attempt to plot data."
249 + print("DDE Test: Could not import PyX! Cannot print output from examples.")
251 + print("DDE Test: An error occured during attempt to plot data.")