8000 Change comparisons to None · basicmachines/python-control@60aba3a · GitHub
[go: up one dir, main page]

Skip to content

Commit 60aba3a

Browse files
committed
Change comparisons to None
Comparisons like if A == None: give a FutureWarning: comparison to `None` will result in an elementwise object comparison in the future. This resuits in a bunch of warnings when running nosetests, so this commit changes these to if A is None:
1 parent fb5ebf6 commit 60aba3a

File tree

3 files changed

+35
-35
lines changed

3 files changed

+35
-35
lines changed

control/freqplot.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -121,7 +121,7 @@ def bode_plot(syslist, omega=None, dB=None, Hz=None, deg=None,
121121
#TODO: Add MIMO bode plots.
122122
raise NotImplementedError("Bode is currently only implemented for SISO systems.")
123123
else:
124-
if (omega == None):
124+
if omega is None:
125125
# Select a default range if none is provided
126126
omega = default_frequency_range(syslist)
127127

@@ -211,7 +211,7 @@ def nyquist_plot(syslist, omega=None, Plot=True, color='b',
211211
syslist = (syslist,)
212212

213213
# Select a default range if none is provided
214-
if (omega == None):
214+
if omega is None:
215215
#! TODO: think about doing something smarter for discrete
216216
omega = default_frequency_range(syslist)
217217

@@ -294,7 +294,7 @@ def gangof4_plot(P, C, omega=None):
294294

295295
# Select a default range if none is provided
296296
#! TODO: This needs to be made more intelligent
297-
if (omega == None):
297+
if omega is None:
298298
omega = default_frequency_range((P,C))
299299

300300
# Compute the senstivity functions

control/mateqn.py

Lines changed: 21 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -88,10 +88,10 @@ def lyap(A,Q,C=None,E=None):
8888
if len(shape(Q)) == 1:
8989
Q = Q.reshape(1,Q.size)
9090

91-
if C != None and len(shape(C)) == 1:
91+
if C is not None and len(shape(C)) == 1:
9292
C = C.reshape(1,C.size)
9393

94-
if E != None and len(shape(E)) == 1:
94+
if E is not None and len(shape(E)) == 1:
9595
E = E.reshape(1,E.size)
9696

9797
# Determine main dimensions
@@ -106,7 +106,7 @@ def lyap(A,Q,C=None,E=None):
106106
m = size(Q,0)
107107

108108
# Solve standard Lyapunov equation
109-
if C==None and E==None:
109+
if C is None and E is None:
110110
# Check input data for consistency
111111
if shape(A) != shape(Q):
112112
raise ControlArgument("A and Q must be matrices of identical \
@@ -139,7 +139,7 @@ def lyap(A,Q,C=None,E=None):
139139
raise e
140140

141141
# Solve the Sylvester equation
142-
elif C != None and E==None:
142+
elif C is not None and E is None:
143143
# Check input data for consistency
144144
if size(A) > 1 and shape(A)[0] != shape(A)[1]:
145145
raise ControlArgument("A must be a quadratic matrix.")
@@ -170,7 +170,7 @@ def lyap(A,Q,C=None,E=None):
170170
raise e
171171

172172
# Solve the generalized Lyapunov equation
173-
elif C == None and E != None:
173+
elif C is None and E is not None:
174174
# Check input data for consistency
175175
if (size(Q) > 1 and shape(Q)[0] != shape(Q)[1]) or \
176176
(size(Q) > 1 and shape(Q)[0] != n) or \
@@ -275,10 +275,10 @@ def dlyap(A,Q,C=None,E=None):
275275
if len(shape(Q)) == 1:
276276
Q = Q.reshape(1,Q.size)
277277

278-
if C != None and len(shape(C)) == 1:
278+
if C is not None and len(shape(C)) == 1:
279279
C = C.reshape(1,C.size)
280280

281-
if E != None and len(shape(E)) == 1:
281+
if E is not None and len(shape(E)) == 1:
282282
E = E.reshape(1,E.size)
283283

284284
# Determine main dimensions
@@ -293,7 +293,7 @@ def dlyap(A,Q,C=None,E=None):
293293
m = size(Q,0)
294294

295295
# Solve standard Lyapunov equation
296-
if C==None and E==None:
296+
if C is None and E is None:
297297
# Check input data for consistency
298298
if shape(A) != shape(Q):
299299
raise ControlArgument("A and Q must be matrices of identical \
@@ -322,7 +322,7 @@ def dlyap(A,Q,C=None,E=None):
322322
raise e
323323

324324
# Solve the Sylvester equation
325-
elif C != None and E==None:
325+
elif C is not None and E is None:
326326
# Check input data for consistency
327327
if size(A) > 1 and shape(A)[0] != shape(A)[1]:
328328
raise ControlArgument("A must be a quadratic matrix")
@@ -353,7 +353,7 @@ def dlyap(A,Q,C=None,E=None):
353353
raise e
354354

355355
# Solve the generalized Lyapunov equation
356-
elif C == None and E != None:
356+
elif C is None and E is not None:
357357
# Check input data for consistency
358358
if (size(Q) > 1 and shape(Q)[0] != shape(Q)[1]) or \
359359
(size(Q) > 1 and shape(Q)[0] != n) or \
@@ -458,13 +458,13 @@ def care(A,B,Q,R=None,S=None,E=None):
458458
if len(shape(Q)) == 1:
459459
Q = Q.reshape(1,Q.size)
460460

461-
if R != None and len(shape(R)) == 1:
461+
if R is not None and len(shape(R)) == 1:
462462
R = R.reshape(1,R.size)
463463

464-
if S != None and len(shape(S)) == 1:
464+
if S is not None and len(shape(S)) == 1:
465465
S = S.reshape(1,S.size)
466466

467-
if E != None and len(shape(E)) == 1:
467+
if E is not None and len(shape(E)) == 1:
468468
E = E.reshape(1,E.size)
469469

470470
# Determine main dimensions
@@ -477,11 +477,11 @@ def care(A,B,Q,R=None,S=None,E=None):
477477
m = 1
478478
else:
479479
m = size(B,1)
480-
if R==None:
480+
if R is None:
481481
R = eye(m,m)
482482

483483
# Solve the standard algebraic Riccati equation
484-
if S==None and E==None:
484+
if S is None and E is None:
485485
# Check input data for consistency
486486
if size(A) > 1 and shape(A)[0] != shape(A)[1]:
487487
raise ControlArgument("A must be a quadratic matrix.")
@@ -562,7 +562,7 @@ def care(A,B,Q,R=None,S=None,E=None):
562562
return (X , w[:n] , G )
563563

564564
# Solve the generalized algebraic Riccati equation
565-
elif S != None and E != None:
565+
elif S is not None and E is not None:
566566
# Check input data for consistency
567567
if size(A) > 1 and shape(A)[0] != shape(A)[1]:
568568
raise ControlArgument("A must be a quadratic matrix.")
@@ -728,13 +728,13 @@ def dare_old(A,B,Q,R,S=None,E=None):
728728
if len(shape(Q)) == 1:
729729
Q = Q.reshape(1,Q.size)
730730

731-
if R != None and len(shape(R)) == 1:
731+
if R is not None and len(shape(R)) == 1:
732732
R = R.reshape(1,R.size)
733733

734-
if S != None and len(shape(S)) == 1:
734+
if S is not None and len(shape(S)) == 1:
735735
S = S.reshape(1,S.size)
736736

737-
if E != None and len(shape(E)) == 1:
737+
if E is not None and len(shape(E)) == 1:
738738
E = E.reshape(1,E.size)
739739

740740
# Determine main dimensions
@@ -749,7 +749,7 @@ def dare_old(A,B,Q,R,S=None,E=None):
749749
m = size(B,1)
750750

751751
# Solve the standard algebraic Riccati equation
752-
if S==None and E==None:
752+
if S is None and E is None:
753753
# Check input data for consistency
754754
if size(A) > 1 and shape(A)[0] != shape(A)[1]:
755755
raise ControlArgument("A must be a quadratic matrix.")
@@ -833,7 +833,7 @@ def dare_old(A,B,Q,R,S=None,E=None):
833833
return (X , w[:n] , G)
834834

835835
# Solve the generalized algebraic Riccati equation
836-
elif S != None and E != None:
836+
elif S is not None and E is not None:
837837
# Check input data for consistency
838838
if size(A) > 1 and shape(A)[0] != shape(A)[1]:
839839
raise ControlArgument("A must be a quadratic matrix.")

control/phaseplot.py

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -119,20 +119,20 @@ def phase_plot(odefun, X=None, Y=None, scale=1, X0=None, T=None,
119119
#
120120
#! TODO: need to add error checking to arguments
121121
autoFlag = False; logtimeFlag = False; timeptsFlag = False; Narrows = 0;
122-
if (lingrid != None):
122+
if lingrid is not None:
123123
autoFlag = True;
124124
Narrows = lingrid;
125125
if (verbose):
126126
print('Using auto arrows\n')
127127

128-
elif (logtime != None):
128+
elif logtime is not None:
129129
logtimeFlag = True;
130130
Narrows = logtime[0];
131131
timefactor = logtime[1];
132132
if (verbose):
133133
print('Using logtime arrows\n')
134134

135-
elif (timepts != None):
135+
elif timepts is not None:
136136
timeptsFlag = True;
137137
Narrows = len(timepts);
138138

@@ -153,7 +153,7 @@ def phase_plot(odefun, X=None, Y=None, scale=1, X0=None, T=None,
153153

154154
# Plot the quiver plot
155155
#! TODO: figure out arguments to make arrows show up correctly
156-
if (scale == None):
156+
if scale is None:
157157
mpl.quiver(x1, x2, dx[:,:,1], dx[:,:,2], angles='xy')
158158
elif (scale != 0):
159159
#! TODO: optimize parameters for arrows
@@ -168,7 +168,7 @@ def phase_plot(odefun, X=None, Y=None, scale=1, X0=None, T=None,
168168
mpl.xlabel('x1'); mpl.ylabel('x2');
169169

170170
# See if we should also generate the streamlines
171-
if (X0 == None or len(X0) == 0):
171+
if X0 is None or len(X0) == 0:
172172
return
173173

174174
# Convert initial conditions to a numpy array
@@ -180,7 +180,7 @@ def phase_plot(odefun, X=None, Y=None, scale=1, X0=None, T=None,
180180
dx = np.empty((nr, Narrows, 2))
181181

182182
# See if we were passed a simulation time
183-
if (T == None):
183+
if T is None:
184184
T = 50
185185

186186
# Parse the time we were passed
@@ -189,7 +189,7 @@ def phase_plot(odefun, X=None, Y=None, scale=1, X0=None, T=None,
189189
TSPAN = np.linspace(0, T, 100);
190190

191191
# Figure out the limits for the plot
192-
if (scale == None):
192+
if scale is None:
193193
# Assume that the current axis are set as we want them
194194
alim = mpl.axis();
195195
xmin = alim[0]; xmax = alim[1];
@@ -216,7 +216,7 @@ def phase_plot(odefun, X=None, Y=None, scale=1, X0=None, T=None,
216216
for j in range(Narrows):
217217

218218
# Figure out starting index; headless arrows start at 0
219-
k = -1 if scale == None else 0;
219+
k = -1 if scale is None else 0;
220220

221221
# Figure out what time index to use for the next point
222222
if (autoFlag):
@@ -234,15 +234,15 @@ def phase_plot(odefun, X=None, Y=None, scale=1, X0=None, T=None,
234234
tind = tarr[-1] if len(tarr) else 0;
235235

236236
# For tailless arrows, skip the first point
237-
if (tind == 0 and scale == None):
237+
if tind == 0 and scale is None:
238238
continue;
239239

240240
# Figure out the arrow at this point on the curve
241241
x1[i,j] = state[tind, 0];
242242
x2[i,j] = state[tind, 1];
243243

244244
# Skip arrows outside of initial condition box
245-
if (scale != None or
245+
if (scale is not None or
246246
(x1[i,j] <= xmax and x1[i,j] >= xmin and
247247
x2[i,j] <= ymax and x2[i,j] >= ymin)):
248248
v = odefun((x1[i,j], x2[i,j]), 0, *parms)
@@ -259,7 +259,7 @@ def phase_plot(odefun, X=None, Y=None, scale=1, X0=None, T=None,
259259
# set(a, 'Box', 'on');
260260

261261
# Plot arrows on the streamlines
262-
if (scale == None and Narrows > 0):
262+
if scale is None and Narrows > 0:
263263
# Use a tailless arrow
264264
#! TODO: figure out arguments to make arrows show up correctly
265265
mpl.quiver(x1, x2, dx[:,:,0], dx[:,:,1], angles='xy')

0 commit comments

Comments
 (0)
0