Skip to content

Commit 6b96c7f

Browse files
committed
replace ndarray.dot() with @
1 parent 19cc79a commit 6b96c7f

File tree

5 files changed

+44
-44
lines changed

5 files changed

+44
-44
lines changed

control/canonical.py

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88

99
import numpy as np
1010

11-
from numpy import zeros, zeros_like, shape, poly, iscomplex, vstack, hstack, dot, \
11+
from numpy import zeros, zeros_like, shape, poly, iscomplex, vstack, hstack, \
1212
transpose, empty, finfo, float64
1313
from numpy.linalg import solve, matrix_rank, eig
1414

@@ -149,7 +149,7 @@ def observable_form(xsys):
149149
raise ValueError("Transformation matrix singular to working precision.")
150150

151151
# Finally, compute the output matrix
152-
zsys.B = Tzx.dot(xsys.B)
152+
zsys.B = Tzx @ xsys.B
153153

154154
return zsys, Tzx
155155

@@ -189,13 +189,13 @@ def rsolve(M, y):
189189

190190
# Update the system matrices
191191
if not inverse:
192-
zsys.A = rsolve(T, dot(T, zsys.A)) / timescale
193-
zsys.B = dot(T, zsys.B) / timescale
192+
zsys.A = rsolve(T, T @ zsys.A) / timescale
193+
zsys.B = T @ zsys.B / timescale
194194
zsys.C = rsolve(T, zsys.C)
195195
else:
196-
zsys.A = solve(T, zsys.A).dot(T) / timescale
196+
zsys.A = solve(T, zsys.A) @ T / timescale
197197
zsys.B = solve(T, zsys.B) / timescale
198-
zsys.C = zsys.C.dot(T)
198+
zsys.C = zsys.C @ T
199199

200200
return zsys
201201

@@ -405,8 +405,8 @@ def bdschur(a, condmax=None, sort=None):
405405
permidx = np.hstack([blkidxs[i] for i in sortidx])
406406
rperm = np.eye(amodal.shape[0])[permidx]
407407

408-
tmodal = tmodal.dot(rperm)
409-
amodal = rperm.dot(amodal).dot(rperm.T)
408+
tmodal = tmodal @ rperm
409+
amodal = rperm @ amodal @ rperm.T
410410
blksizes = blksizes[sortidx]
411411

412412
elif sort is None:

control/frdata.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@
4747
from warnings import warn
4848
import numpy as np
4949
from numpy import angle, array, empty, ones, \
50-
real, imag, absolute, eye, linalg, where, dot, sort
50+
real, imag, absolute, eye, linalg, where, sort
5151
from scipy.interpolate import splprep, splev
5252
from .lti import LTI, _process_frequency_response
5353
from . import config
@@ -301,7 +301,7 @@ def __mul__(self, other):
301301
fresp = empty((outputs, inputs, len(self.omega)),
302302
dtype=self.fresp.dtype)
303303
for i in range(len(self.omega)):
304-
fresp[:, :, i] = dot(self.fresp[:, :, i], other.fresp[:, :, i])
304+
fresp[:, :, i] = self.fresp[:, :, i] @ other.fresp[:, :, i]
305305
return FRD(fresp, self.omega,
306306
smooth=(self.ifunc is not None) and
307307
(other.ifunc is not None))
@@ -329,7 +329,7 @@ def __rmul__(self, other):
329329
fresp = empty((outputs, inputs, len(self.omega)),
330330
dtype=self.fresp.dtype)
331331
for i in range(len(self.omega)):
332-
fresp[:, :, i] = dot(other.fresp[:, :, i], self.fresp[:, :, i])
332+
fresp[:, :, i] = other.fresp[:, :, i] @ self.fresp[:, :, i]
333333
return FRD(fresp, self.omega,
334334
smooth=(self.ifunc is not None) and
335335
(other.ifunc is not None))

control/mateqn.py

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@
3535
# OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
3636
# SUCH DAMAGE.
3737

38-
from numpy import shape, size, asarray, copy, zeros, eye, dot, \
38+
from numpy import shape, size, asarray, copy, zeros, eye, \
3939
finfo, inexact, atleast_2d
4040
from scipy.linalg import eigvals, solve_discrete_are, solve
4141
from .exception import ControlSlycot, ControlArgument
@@ -624,9 +624,9 @@ def care(A, B, Q, R=None, S=None, E=None, stabilizing=True):
624624

625625
# Calculate the gain matrix G
626626
if size(R_b) == 1:
627-
G = dot(dot(1/(R_ba), asarray(B_ba).T), X)
627+
G = 1/(R_ba) * asarray(B_ba).T @ X
628628
else:
629-
G = dot(solve(R_ba, asarray(B_ba).T), X)
629+
G = solve(R_ba, asarray(B_ba).T) @ X
630630

631631
# Return the solution X, the closed-loop eigenvalues L and
632632
# the gain matrix G
@@ -732,9 +732,9 @@ def care(A, B, Q, R=None, S=None, E=None, stabilizing=True):
732732

733733
# Calculate the gain matrix G
734734
if size(R_b) == 1:
735-
G = dot(1/(R_b), dot(asarray(B_b).T, dot(X, E_b)) + asarray(S_b).T)
735+
G = 1/(R_b) * (asarray(B_b).T @ X @ E_b + asarray(S_b).T)
736736
else:
737-
G = solve(R_b, dot(asarray(B_b).T, dot(X, E_b)) + asarray(S_b).T)
737+
G = solve(R_b, asarray(B_b).T @ X @ E_b + asarray(S_b).T)
738738

739739
# Return the solution X, the closed-loop eigenvalues L and
740740
# the gain matrix G
@@ -794,8 +794,8 @@ def dare(A, B, Q, R, S=None, E=None, stabilizing=True):
794794
Rmat = _ssmatrix(R)
795795
Qmat = _ssmatrix(Q)
796796
X = solve_discrete_are(A, B, Qmat, Rmat)
797-
G = solve(B.T.dot(X).dot(B) + Rmat, B.T.dot(X).dot(A))
798-
L = eigvals(A - B.dot(G))
797+
G = solve(B.T @ X @ B + Rmat, B.T @ X @ A)
798+
L = eigvals(A - B @ G)
799799
return _ssmatrix(X), L, _ssmatrix(G)
800800

801801

@@ -926,11 +926,11 @@ def dare_old(A, B, Q, R, S=None, E=None, stabilizing=True):
926926

927927
# Calculate the gain matrix G
928928
if size(R_b) == 1:
929-
G = dot(1/(dot(asarray(B_ba).T, dot(X, B_ba)) + R_ba),
930-
dot(asarray(B_ba).T, dot(X, A_ba)))
929+
G = (1/(asarray(B_ba).T @ X @ B_ba + R_ba) *
930+
asarray(B_ba).T @ X @ A_ba)
931931
else:
932-
G = solve(dot(asarray(B_ba).T, dot(X, B_ba)) + R_ba,
933-
dot(asarray(B_ba).T, dot(X, A_ba)))
932+
G = solve(asarray(B_ba).T @ X @ B_ba + R_ba,
933+
asarray(B_ba).T @ X @ A_ba)
934934

935935
# Return the solution X, the closed-loop eigenvalues L and
936936
# the gain matrix G
@@ -1036,11 +1036,11 @@ def dare_old(A, B, Q, R, S=None, E=None, stabilizing=True):
10361036

10371037
# Calculate the gain matrix G
10381038
if size(R_b) == 1:
1039-
G = dot(1/(dot(asarray(B_b).T, dot(X, B_b)) + R_b),
1040-
dot(asarray(B_b).T, dot(X, A_b)) + asarray(S_b).T)
1039+
G = (1/(asarray(B_b).T @ X @ B_b + R_b) *
1040+
(asarray(B_b).T @ X @ A_b + asarray(S_b).T))
10411041
else:
1042-
G = solve(dot(asarray(B_b).T, dot(X, B_b)) + R_b,
1043-
dot(asarray(B_b).T, dot(X, A_b)) + asarray(S_b).T)
1042+
G = solve(asarray(B_b).T @ X @ B_b + R_b,
1043+
asarray(B_b).T @ X @ A_b + asarray(S_b).T)
10441044

10451045
# Return the solution X, the closed-loop eigenvalues L and
10461046
# the gain matrix G

control/statesp.py

Lines changed: 17 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -49,8 +49,8 @@
4949

5050
import math
5151
import numpy as np
52-
from numpy import any, array, asarray, concatenate, cos, delete, \
53-
dot, empty, exp, eye, isinf, ones, pad, sin, zeros, squeeze, pi
52+
from numpy import any, asarray, concatenate, cos, delete, \
53+
empty, exp, eye, isinf, ones, pad, sin, zeros, squeeze
5454
from numpy.random import rand, randn
5555
from numpy.linalg import solve, eigvals, matrix_rank
5656
from numpy.linalg.linalg import LinAlgError
@@ -1126,23 +1126,23 @@ def lft(self, other, nu=-1, ny=-1):
11261126
H22 = TH[ny:, self.nstates + other.nstates + self.ninputs - nu:]
11271127

11281128
Ares = np.block([
1129-
[A + B2.dot(T21), B2.dot(T22)],
1130-
[Bbar1.dot(T11), Abar + Bbar1.dot(T12)]
1129+
[A + B2 @ T21, B2 @ T22],
1130+
[Bbar1 @ T11, Abar + Bbar1 @ T12]
11311131
])
11321132

11331133
Bres = np.block([
1134-
[B1 + B2.dot(H21), B2.dot(H22)],
1135-
[Bbar1.dot(H11), Bbar2 + Bbar1.dot(H12)]
1134+
[B1 + B2 @ H21, B2 @ H22],
1135+
[Bbar1 @ H11, Bbar2 + Bbar1 @ H12]
11361136
])
11371137

11381138
Cres = np.block([
1139-
[C1 + D12.dot(T21), D12.dot(T22)],
1140-
[Dbar21.dot(T11), Cbar2 + Dbar21.dot(T12)]
1139+
[C1 + D12 @ T21, D12 @ T22],
1140+
[Dbar21 @ T11, Cbar2 + Dbar21 @ T12]
11411141
])
11421142

11431143
Dres = np.block([
1144-
[D11 + D12.dot(H21), D12.dot(H22)],
1145-
[Dbar21.dot(H11), Dbar22 + Dbar21.dot(H12)]
1144+
[D11 + D12 @ H21, D12 @ H22],
1145+
[Dbar21 @ H11, Dbar22 + Dbar21 @ H12]
11461146
])
11471147
return StateSpace(Ares, Bres, Cres, Dres, dt)
11481148

@@ -1381,13 +1381,13 @@ def dynamics(self, t, x, u=None):
13811381
if np.size(x) != self.nstates:
13821382
raise ValueError("len(x) must be equal to number of states")
13831383
if u is None:
1384-
return self.A.dot(x).reshape((-1,)) # return as row vector
1384+
return (self.A @ x).reshape((-1,)) # return as row vector
13851385
else: # received t, x, and u, ignore t
13861386
u = np.reshape(u, (-1, 1)) # force to column in case matrix
13871387
if np.size(u) != self.ninputs:
13881388
raise ValueError("len(u) must be equal to number of inputs")
1389-
return self.A.dot(x).reshape((-1,)) \
1390-
+ self.B.dot(u).reshape((-1,)) # return as row vector
1389+
return (self.A @ x).reshape((-1,)) \
1390+
+ (self.B @ u).reshape((-1,)) # return as row vector
13911391

13921392
def output(self, t, x, u=None):
13931393
"""Compute the output of the system
@@ -1424,13 +1424,13 @@ def output(self, t, x, u=None):
14241424
raise ValueError("len(x) must be equal to number of states")
14251425

14261426
if u is None:
1427-
return self.C.dot(x).reshape((-1,)) # return as row vector
1427+
return (self.C @ x).reshape((-1,)) # return as row vector
14281428
else: # received t, x, and u, ignore t
14291429
u = np.reshape(u, (-1, 1)) # force to a column in case matrix
14301430
if np.size(u) != self.ninputs:
14311431
raise ValueError("len(u) must be equal to number of inputs")
1432-
return self.C.dot(x).reshape((-1,)) \
1433-
+ self.D.dot(u).reshape((-1,)) # return as row vector
1432+
return (self.C @ x).reshape((-1,)) \
1433+
+ (self.D @ u).reshape((-1,)) # return as row vector
14341434

14351435
def _isstatic(self):
14361436
"""True if and only if the system has no dynamics, that is,
@@ -1623,7 +1623,7 @@ def _rss_generate(states, inputs, outputs, cdtype, strictly_proper=False):
16231623
while True:
16241624
T = randn(states, states)
16251625
try:
1626-
A = dot(solve(T, A), T) # A = T \ A * T
1626+
A = solve(T, A) @ T # A = T \ A @ T
16271627
break
16281628
except LinAlgError:
16291629
# In the unlikely event that T is rank-deficient, iterate again.

control/timeresp.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1972,7 +1972,7 @@ def _ideal_tfinal_and_dt(sys, is_step=True):
19721972
# Incorporate balancing to outer factors
19731973
l[perm, :] *= np.reciprocal(sca)[:, None]
19741974
r[perm, :] *= sca[:, None]
1975-
w, v = sys_ss.C.dot(r), l.T.conj().dot(sys_ss.B)
1975+
w, v = sys_ss.C @ r, l.T.conj() @ sys_ss.B
19761976

19771977
origin = False
19781978
# Computing the "size" of the response of each simple mode

0 commit comments

Comments
 (0)