Skip to content

Commit 83cc6c9

Browse files
Copilotmmcky
andcommitted
Complete migration: convert all remaining np.dot to @ operator in test files and markov module
Co-authored-by: mmcky <[email protected]>
1 parent ded5b78 commit 83cc6c9

File tree

7 files changed

+12
-12
lines changed

7 files changed

+12
-12
lines changed

quantecon/markov/gth_solve.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -83,12 +83,12 @@ def gth_solve(A, overwrite=False, use_jit=True):
8383
break
8484
A1[k+1:n, k] /= scale
8585

86-
A1[k+1:n, k+1:n] += np.dot(A1[k+1:n, k:k+1], A1[k:k+1, k+1:n])
86+
A1[k+1:n, k+1:n] += A1[k+1:n, k:k+1] @ A1[k:k+1, k+1:n]
8787

8888
# === Backward substitution === #
8989
x[n-1] = 1
9090
for k in range(n-2, -1, -1):
91-
x[k] = np.dot(x[k+1:n], A1[k+1:n, k])
91+
x[k] = x[k+1:n] @ A1[k+1:n, k]
9292

9393
# === Normalization === #
9494
x /= np.sum(x)

quantecon/markov/tests/test_core.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -225,12 +225,12 @@ def test_left_eigen_vec(self):
225225
stationary_distributions = self.stationary
226226

227227
if self.n_stat_dists == 1:
228-
assert_allclose(np.dot(stationary_distributions, mc.P),
228+
assert_allclose(stationary_distributions @ mc.P,
229229
stationary_distributions, atol=self.TOL)
230230
else:
231231
for i in range(self.n_stat_dists):
232232
curr_v = stationary_distributions[i, :]
233-
assert_allclose(np.dot(curr_v, mc.P), curr_v, atol=self.TOL)
233+
assert_allclose(curr_v @ mc.P, curr_v, atol=self.TOL)
234234

235235

236236
def test_simulate_shape():

quantecon/markov/tests/test_gth_solve.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -108,7 +108,7 @@ def __call__(self, x):
108108

109109
class StationaryDistLeftEigenVec(AddDescription):
110110
def __call__(self, A, x):
111-
assert_allclose(np.dot(x, A), x, atol=TOL)
111+
assert_allclose(x @ A, x, atol=TOL)
112112

113113

114114
class StationaryDistEqualToKnown(AddDescription):

quantecon/tests/test_kalman.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,8 @@ def setup_method(self):
1717
self.G = np.eye(2) * .5
1818
self.H = np.eye(2) * np.sqrt(0.2)
1919

20-
self.Q = np.dot(self.C, self.C.T)
21-
self.R = np.dot(self.H, self.H.T)
20+
self.Q = self.C @ self.C.T
21+
self.R = self.H @ self.H.T
2222

2323
ss = LinearStateSpace(self.A, self.C, self.G, self.H)
2424

@@ -42,7 +42,7 @@ def test_stationarity(self):
4242

4343
# Compute the kalmain gain and sigma infinity according to the
4444
# recursive equations and compare
45-
kal_recursion = np.dot(A, sig_inf).dot(G.T).dot(mat_inv)
45+
kal_recursion = (A @ sig_inf).dot(G.T).dot(mat_inv)
4646
sig_recursion = (A.dot(sig_inf).dot(A.T) -
4747
kal_recursion.dot(G).dot(sig_inf).dot(A.T) + Q)
4848

@@ -76,7 +76,7 @@ def test_update_nonstationary(self):
7676
kf.update(y_observed)
7777

7878
mat_inv = np.linalg.inv(G.dot(curr_sigma).dot(G.T) + R)
79-
curr_k = np.dot(A, curr_sigma).dot(G.T).dot(mat_inv)
79+
curr_k = (A @ curr_sigma).dot(G.T).dot(mat_inv)
8080
new_sigma = (A.dot(curr_sigma).dot(A.T) -
8181
curr_k.dot(G).dot(curr_sigma).dot(A.T) + Q)
8282

quantecon/tests/test_lqcontrol.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,7 @@ def test_stationary_mat(self):
8383

8484
for method in self.methods:
8585
P, F, d = lq_mat.stationary_values(method=method)
86-
val_func_lq = np.dot(x0, P).dot(x0)
86+
val_func_lq = (x0 @ P).dot(x0)
8787

8888
assert_allclose(f_answer, F, atol=1e-3)
8989
assert_allclose(val_func_lq, val_func_answer, atol=1e-3)

quantecon/tests/test_matrix_eqn.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,5 +34,5 @@ def test_solve_discrete_lyapunov_complex():
3434

3535
X = qme.solve_discrete_lyapunov(A, B)
3636

37-
assert_allclose(np.dot(np.dot(A, X), A.conj().transpose()) - X, -B,
37+
assert_allclose((A @ X @ A.conj().transpose()) - X, -B,
3838
atol=1e-15)

quantecon/tests/test_ricatti.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ def dare_tjm_3(method):
6262
B = I
6363
R = [[1, r],
6464
[r, r*r]]
65-
Q = I - np.dot(A.T, A) + np.dot(A.T, np.linalg.solve(R + I, A))
65+
Q = I - (A.T @ A) + (A.T @ np.linalg.solve(R + I, A))
6666
X = solve_discrete_riccati(A, B, Q, R, method=method)
6767
Y = np.identity(2)
6868
assert_allclose(X, Y, atol=1e-07)

0 commit comments

Comments
 (0)