Skip to content

Commit 5b28121

Browse files
committed
replace ndarray.dot in tests
1 parent de85969 commit 5b28121

File tree

5 files changed

+67
-67
lines changed

5 files changed

+67
-67
lines changed

control/tests/canonical_test.py

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -29,9 +29,9 @@ def test_reachable_form(self):
2929
[-0.74855725, -0.39136285, -0.18142339, -0.50356997],
3030
[-0.40688007, 0.81416369, 0.38002113, -0.16483334],
3131
[-0.44769516, 0.15654653, -0.50060858, 0.72419146]])
32-
A = np.linalg.solve(T_true, A_true).dot(T_true)
32+
A = np.linalg.solve(T_true, A_true) @ T_true
3333
B = np.linalg.solve(T_true, B_true)
34-
C = C_true.dot(T_true)
34+
C = C_true @ T_true
3535
D = D_true
3636

3737
# Create a state space system and convert it to the reachable canonical form
@@ -77,9 +77,9 @@ def test_observable_form(self):
7777
[-0.74855725, -0.39136285, -0.18142339, -0.50356997],
7878
[-0.40688007, 0.81416369, 0.38002113, -0.16483334],
7979
[-0.44769516, 0.15654653, -0.50060858, 0.72419146]])
80-
A = np.linalg.solve(T_true, A_true).dot(T_true)
80+
A = np.linalg.solve(T_true, A_true) @ T_true
8181
B = np.linalg.solve(T_true, B_true)
82-
C = C_true.dot(T_true)
82+
C = C_true @ T_true
8383
D = D_true
8484

8585
# Create a state space system and convert it to the observable canonical form
@@ -266,7 +266,7 @@ def test_bdschur_ref(eigvals, condmax, blksizes):
266266
bdiag_b = scipy.linalg.block_diag(*extract_bdiag(b, test_blksizes))
267267
np.testing.assert_array_almost_equal(bdiag_b, b)
268268

269-
np.testing.assert_array_almost_equal(solve(t, a).dot(t), b)
269+
np.testing.assert_array_almost_equal(solve(t, a) @ t, b)
270270

271271

272272
@slycotonly
@@ -357,9 +357,9 @@ def test_modal_form(A_true, B_true, C_true, D_true):
357357
[-0.74855725, -0.39136285, -0.18142339, -0.50356997],
358358
[-0.40688007, 0.81416369, 0.38002113, -0.16483334],
359359
[-0.44769516, 0.15654653, -0.50060858, 0.72419146]])
360-
A = np.linalg.solve(T_true, A_true).dot(T_true)
360+
A = np.linalg.solve(T_true, A_true) @ T_true
361361
B = np.linalg.solve(T_true, B_true)
362-
C = C_true.dot(T_true)
362+
C = C_true @ T_true
363363
D = D_true
364364

365365
# Create a state space system and convert it to modal canonical form
@@ -370,7 +370,7 @@ def test_modal_form(A_true, B_true, C_true, D_true):
370370
np.testing.assert_array_almost_equal(sys_check.A, a_bds)
371371
np.testing.assert_array_almost_equal(T_check, t_bds)
372372
np.testing.assert_array_almost_equal(sys_check.B, np.linalg.solve(t_bds, B))
373-
np.testing.assert_array_almost_equal(sys_check.C, C.dot(t_bds))
373+
np.testing.assert_array_almost_equal(sys_check.C, C @ t_bds)
374374
np.testing.assert_array_almost_equal(sys_check.D, D)
375375

376376
# canonical_form(...,'modal') is the same as modal_form with default parameters
@@ -403,7 +403,7 @@ def test_modal_form_condmax(condmax, len_blksizes):
403403
np.testing.assert_array_almost_equal(zsys.A, amodal)
404404
np.testing.assert_array_almost_equal(t, tmodal)
405405
np.testing.assert_array_almost_equal(zsys.B, np.linalg.solve(tmodal, xsys.B))
406-
np.testing.assert_array_almost_equal(zsys.C, xsys.C.dot(tmodal))
406+
np.testing.assert_array_almost_equal(zsys.C, xsys.C @ tmodal)
407407
np.testing.assert_array_almost_equal(zsys.D, xsys.D)
408408

409409

@@ -421,13 +421,13 @@ def test_modal_form_sort(sys_type):
421421
xsys = ss(a, [[1],[0],[0],[0],], [0,0,0,1], 0, dt)
422422
zsys, t = modal_form(xsys, sort=True)
423423

424-
my_amodal = np.linalg.solve(tmodal, a).dot(tmodal)
424+
my_amodal = np.linalg.solve(tmodal, a) @ tmodal
425425
np.testing.assert_array_almost_equal(amodal, my_amodal)
426426

427427
np.testing.assert_array_almost_equal(t, tmodal)
428428
np.testing.assert_array_almost_equal(zsys.A, amodal)
429429
np.testing.assert_array_almost_equal(zsys.B, np.linalg.solve(tmodal, xsys.B))
430-
np.testing.assert_array_almost_equal(zsys.C, xsys.C.dot(tmodal))
430+
np.testing.assert_array_almost_equal(zsys.C, xsys.C @ tmodal)
431431
np.testing.assert_array_almost_equal(zsys.D, xsys.D)
432432

433433

control/tests/mateqn_test.py

Lines changed: 38 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -52,58 +52,58 @@ def test_lyap(self):
5252
Q = array([[1,0],[0,1]])
5353
X = lyap(A,Q)
5454
# print("The solution obtained is ", X)
55-
assert_array_almost_equal(A.dot(X) + X.dot(A.T) + Q, zeros((2,2)))
55+
assert_array_almost_equal(A @ X + X @ A.T + Q, zeros((2,2)))
5656

5757
A = array([[1, 2],[-3, -4]])
5858
Q = array([[3, 1],[1, 1]])
5959
X = lyap(A,Q)
6060
# print("The solution obtained is ", X)
61-
assert_array_almost_equal(A.dot(X) + X.dot(A.T) + Q, zeros((2,2)))
61+
assert_array_almost_equal(A @ X + X @ A.T + Q, zeros((2,2)))
6262

6363
def test_lyap_sylvester(self):
6464
A = 5
6565
B = array([[4, 3], [4, 3]])
6666
C = array([2, 1])
6767
X = lyap(A,B,C)
6868
# print("The solution obtained is ", X)
69-
assert_array_almost_equal(A * X + X.dot(B) + C, zeros((1,2)))
69+
assert_array_almost_equal(A * X + X @ B + C, zeros((1,2)))
7070

7171
A = array([[2,1],[1,2]])
7272
B = array([[1,2],[0.5,0.1]])
7373
C = array([[1,0],[0,1]])
7474
X = lyap(A,B,C)
7575
# print("The solution obtained is ", X)
76-
assert_array_almost_equal(A.dot(X) + X.dot(B) + C, zeros((2,2)))
76+
assert_array_almost_equal(A @ X + X @ B + C, zeros((2,2)))
7777

7878
def test_lyap_g(self):
7979
A = array([[-1, 2],[-3, -4]])
8080
Q = array([[3, 1],[1, 1]])
8181
E = array([[1,2],[2,1]])
8282
X = lyap(A,Q,None,E)
8383
# print("The solution obtained is ", X)
84-
assert_array_almost_equal(A.dot(X).dot(E.T) + E.dot(X).dot(A.T) + Q,
84+
assert_array_almost_equal(A @ X @ E.T + E @ X @ A.T + Q,
8585
zeros((2,2)))
8686

8787
def test_dlyap(self):
8888
A = array([[-0.6, 0],[-0.1, -0.4]])
8989
Q = array([[1,0],[0,1]])
9090
X = dlyap(A,Q)
9191
# print("The solution obtained is ", X)
92-
assert_array_almost_equal(A.dot(X).dot(A.T) - X + Q, zeros((2,2)))
92+
assert_array_almost_equal(A @ X @ A.T - X + Q, zeros((2,2)))
9393

9494
A = array([[-0.6, 0],[-0.1, -0.4]])
9595
Q = array([[3, 1],[1, 1]])
9696
X = dlyap(A,Q)
9797
# print("The solution obtained is ", X)
98-
assert_array_almost_equal(A.dot(X).dot(A.T) - X + Q, zeros((2,2)))
98+
assert_array_almost_equal(A @ X @ A.T - X + Q, zeros((2,2)))
9999

100100
def test_dlyap_g(self):
101101
A = array([[-0.6, 0],[-0.1, -0.4]])
102102
Q = array([[3, 1],[1, 1]])
103103
E = array([[1, 1],[2, 1]])
104104
X = dlyap(A,Q,None,E)
105105
# print("The solution obtained is ", X)
106-
assert_array_almost_equal(A.dot(X).dot(A.T) - E.dot(X).dot(E.T) + Q,
106+
assert_array_almost_equal(A @ X @ A.T - E @ X @ E.T + Q,
107107
zeros((2,2)))
108108

109109
def test_dlyap_sylvester(self):
@@ -112,14 +112,14 @@ def test_dlyap_sylvester(self):
112112
C = array([2, 1])
113113
X = dlyap(A,B,C)
114114
# print("The solution obtained is ", X)
115-
assert_array_almost_equal(A * X.dot(B.T) - X + C, zeros((1,2)))
115+
assert_array_almost_equal(A * X @ B.T - X + C, zeros((1,2)))
116116

117117
A = array([[2,1],[1,2]])
118118
B = array([[1,2],[0.5,0.1]])
119119
C = array([[1,0],[0,1]])
120120
X = dlyap(A,B,C)
121121
# print("The solution obtained is ", X)
122-
assert_array_almost_equal(A.dot(X).dot(B.T) - X + C, zeros((2,2)))
122+
assert_array_almost_equal(A @ X @ B.T - X + C, zeros((2,2)))
123123

124124
def test_care(self):
125125
A = array([[-2, -1],[-1, -1]])
@@ -128,10 +128,10 @@ def test_care(self):
128128

129129
X,L,G = care(A,B,Q)
130130
# print("The solution obtained is", X)
131-
M = A.T.dot(X) + X.dot(A) - X.dot(B).dot(B.T).dot(X) + Q
131+
M = A.T @ X + X @ A - X @ B @ B.T @ X + Q
132132
assert_array_almost_equal(M,
133133
zeros((2,2)))
134-
assert_array_almost_equal(B.T.dot(X), G)
134+
assert_array_almost_equal(B.T @ X, G)
135135

136136
def test_care_g(self):
137137
A = array([[-2, -1],[-1, -1]])
@@ -143,11 +143,11 @@ def test_care_g(self):
143143

144144
X,L,G = care(A,B,Q,R,S,E)
145145
# print("The solution obtained is", X)
146-
Gref = solve(R, B.T.dot(X).dot(E) + S.T)
146+
Gref = solve(R, B.T @ X @ E + S.T)
147147
assert_array_almost_equal(Gref, G)
148148
assert_array_almost_equal(
149-
A.T.dot(X).dot(E) + E.T.dot(X).dot(A)
150-
- (E.T.dot(X).dot(B) + S).dot(Gref) + Q,
149+
A.T @ X @ E + E.T @ X @ A
150+
- (E.T @ X @ B + S) @ Gref + Q,
151151
zeros((2,2)))
152152

153153
def test_care_g2(self):
@@ -160,10 +160,10 @@ def test_care_g2(self):
160160

161161
X,L,G = care(A,B,Q,R,S,E)
162162
# print("The solution obtained is", X)
163-
Gref = 1/R * (B.T.dot(X).dot(E) + S.T)
163+
Gref = 1/R * (B.T @ X @ E + S.T)
164164
assert_array_almost_equal(
165-
A.T.dot(X).dot(E) + E.T.dot(X).dot(A)
166-
- (E.T.dot(X).dot(B) + S).dot(Gref) + Q ,
165+
A.T @ X @ E + E.T @ X @ A
166+
- (E.T @ X @ B + S) @ Gref + Q ,
167167
zeros((2,2)))
168168
assert_array_almost_equal(Gref , G)
169169

@@ -175,12 +175,12 @@ def test_dare(self):
175175

176176
X,L,G = dare(A,B,Q,R)
177177
# print("The solution obtained is", X)
178-
Gref = solve(B.T.dot(X).dot(B) + R, B.T.dot(X).dot(A))
178+
Gref = solve(B.T @ X @ B + R, B.T @ X @ A)
179179
assert_array_almost_equal(Gref, G)
180180
assert_array_almost_equal(
181-
X, A.T.dot(X).dot(A) - A.T.dot(X).dot(B).dot(Gref) + Q)
181+
X, A.T @ X @ A - A.T @ X @ B @ Gref + Q)
182182
# check for stable closed loop
183-
lam = eigvals(A - B.dot(G))
183+
lam = eigvals(A - B @ G)
184184
assert_array_less(abs(lam), 1.0)
185185

186186
A = array([[1, 0],[-1, 1]])
@@ -190,15 +190,15 @@ def test_dare(self):
190190

191191
X,L,G = dare(A,B,Q,R)
192192
# print("The solution obtained is", X)
193-
AtXA = A.T.dot(X).dot(A)
194-
AtXB = A.T.dot(X).dot(B)
195-
BtXA = B.T.dot(X).dot(A)
196-
BtXB = B.T.dot(X).dot(B)
193+
AtXA = A.T @ X @ A
194+
AtXB = A.T @ X @ B
195+
BtXA = B.T @ X @ A
196+
BtXB = B.T @ X @ B
197197
assert_array_almost_equal(
198-
X, AtXA - AtXB.dot(solve(BtXB + R, BtXA)) + Q)
198+
X, AtXA - AtXB @ solve(BtXB + R, BtXA) + Q)
199199
assert_array_almost_equal(BtXA / (BtXB + R), G)
200200
# check for stable closed loop
201-
lam = eigvals(A - B.dot(G))
201+
lam = eigvals(A - B @ G)
202202
assert_array_less(abs(lam), 1.0)
203203

204204
def test_dare_g(self):
@@ -211,13 +211,13 @@ def test_dare_g(self):
211211

212212
X,L,G = dare(A,B,Q,R,S,E)
213213
# print("The solution obtained is", X)
214-
Gref = solve(B.T.dot(X).dot(B) + R, B.T.dot(X).dot(A) + S.T)
214+
Gref = solve(B.T @ X @ B + R, B.T @ X @ A + S.T)
215215
assert_array_almost_equal(Gref, G)
216216
assert_array_almost_equal(
217-
E.T.dot(X).dot(E),
218-
A.T.dot(X).dot(A) - (A.T.dot(X).dot(B) + S).dot(Gref) + Q)
217+
E.T @ X @ E,
218+
A.T @ X @ A - (A.T @ X @ B + S) @ Gref + Q)
219219
# check for stable closed loop
220-
lam = eigvals(A - B.dot(G), E)
220+
lam = eigvals(A - B @ G, E)
221221
assert_array_less(abs(lam), 1.0)
222222

223223
def test_dare_g2(self):
@@ -230,16 +230,16 @@ def test_dare_g2(self):
230230

231231
X, L, G = dare(A, B, Q, R, S, E)
232232
# print("The solution obtained is", X)
233-
AtXA = A.T.dot(X).dot(A)
234-
AtXB = A.T.dot(X).dot(B)
235-
BtXA = B.T.dot(X).dot(A)
236-
BtXB = B.T.dot(X).dot(B)
237-
EtXE = E.T.dot(X).dot(E)
233+
AtXA = A.T @ X @ A
234+
AtXB = A.T @ X @ B
235+
BtXA = B.T @ X @ A
236+
BtXB = B.T @ X @ B
237+
EtXE = E.T @ X @ E
238238
assert_array_almost_equal(
239-
EtXE, AtXA - (AtXB + S).dot(solve(BtXB + R, BtXA + S.T)) + Q)
239+
EtXE, AtXA - (AtXB + S) @ solve(BtXB + R, BtXA + S.T) + Q)
240240
assert_array_almost_equal((BtXA + S.T) / (BtXB + R), G)
241241
# check for stable closed loop
242-
lam = eigvals(A - B.dot(G), E)
242+
lam = eigvals(A - B @ G, E)
243243
assert_array_less(abs(lam), 1.0)
244244

245245
def test_raise(self):

control/tests/statefbk_test.py

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -203,7 +203,7 @@ def testPlace(self, matarrayin):
203203
P = matarrayin([-0.5 + 1j, -0.5 - 1j, -5.0566, -8.6659])
204204
K = place(A, B, P)
205205
assert ismatarrayout(K)
206-
P_placed = np.linalg.eigvals(A - B.dot(K))
206+
P_placed = np.linalg.eigvals(A - B @ K)
207207
self.checkPlaced(P, P_placed)
208208

209209
# Test that the dimension checks work.
@@ -228,7 +228,7 @@ def testPlace_varga_continuous(self, matarrayin):
228228

229229
P = [-2., -2.]
230230
K = place_varga(A, B, P)
231-
P_placed = np.linalg.eigvals(A - B.dot(K))
231+
P_placed = np.linalg.eigvals(A - B @ K)
232232
self.checkPlaced(P, P_placed)
233233

234234
# Test that the dimension checks work.
@@ -241,7 +241,7 @@ def testPlace_varga_continuous(self, matarrayin):
241241
B = matarrayin([[0], [1]])
242242
P = matarrayin([-20 + 10*1j, -20 - 10*1j])
243243
K = place_varga(A, B, P)
244-
P_placed = np.linalg.eigvals(A - B.dot(K))
244+
P_placed = np.linalg.eigvals(A - B @ K)
245245
self.checkPlaced(P, P_placed)
246246

247247

@@ -261,7 +261,7 @@ def testPlace_varga_continuous_partial_eigs(self, matarrayin):
261261
alpha = -1.5
262262
K = place_varga(A, B, P, alpha=alpha)
263263

264-
P_placed = np.linalg.eigvals(A - B.dot(K))
264+
P_placed = np.linalg.eigvals(A - B @ K)
265265
# No guarantee of the ordering, so sort them
266266
self.checkPlaced(P_expected, P_placed)
267267

@@ -275,7 +275,7 @@ def testPlace_varga_discrete(self, matarrayin):
275275

276276
P = matarrayin([0.5, 0.5])
277277
K = place_varga(A, B, P, dtime=True)
278-
P_placed = np.linalg.eigvals(A - B.dot(K))
278+
P_placed = np.linalg.eigvals(A - B @ K)
279279
# No guarantee of the ordering, so sort them
280280
self.checkPlaced(P, P_placed)
281281

@@ -293,12 +293,12 @@ def testPlace_varga_discrete_partial_eigs(self, matarrayin):
293293
P_expected = np.array([0.5, 0.6])
294294
alpha = 0.51
295295
K = place_varga(A, B, P, dtime=True, alpha=alpha)
296-
P_placed = np.linalg.eigvals(A - B.dot(K))
296+
P_placed = np.linalg.eigvals(A - B @ K)
297297
self.checkPlaced(P_expected, P_placed)
298298

299299

300300
def check_LQR(self, K, S, poles, Q, R):
301-
S_expected = asmatarrayout(np.sqrt(Q.dot(R)))
301+
S_expected = asmatarrayout(np.sqrt(Q @ R))
302302
K_expected = asmatarrayout(S_expected / R)
303303
poles_expected = -np.squeeze(np.asarray(K_expected))
304304
np.testing.assert_array_almost_equal(S, S_expected)
@@ -373,7 +373,7 @@ def test_lqr_call_format(self):
373373
K, S, E = lqr(sys.A, sys.B, sys.C, R, Q)
374374

375375
def check_LQE(self, L, P, poles, G, QN, RN):
376-
P_expected = asmatarrayout(np.sqrt(G.dot(QN.dot(G).dot(RN))))
376+
P_expected = asmatarrayout(np.sqrt(G @ QN @ G @ RN))
377377
L_expected = asmatarrayout(P_expected / RN)
378378
poles_expected = -np.squeeze(np.asarray(L_expected))
379379
np.testing.assert_array_almost_equal(P, P_expected)

0 commit comments

Comments
 (0)