@@ -46,7 +46,7 @@ function _schurstructure(R::AbstractMatrix, ul=Val(:U)::Union{Val{:U}, Val{:L}})
46
46
if j == n
47
47
d[k] = 1
48
48
else
49
- if ul == Val (:U )
49
+ if ul === Val (:U )
50
50
d[k] = iszero (R[j+ 1 , j]) ? 1 : 2
51
51
else
52
52
d[k] = iszero (R[j, j+ 1 ]) ? 1 : 2
@@ -95,24 +95,24 @@ for small matrices (1x1, 1x2, 2x1, 2x2), overwriting the input `C`.
95
95
@inline function _sylvc! (A:: AbstractMatrix , B:: AbstractMatrix , C:: AbstractMatrix )
96
96
M, N = size (C)
97
97
if M == 2 && N == 2
98
- _sylvc! (A, B, C, Val {2} ( ), Val {2} ( ))
98
+ _sylvc! (A, B, C, Val ( 2 ), Val ( 2 ))
99
99
elseif M == 2 && N == 1
100
- _sylvc! (A, B, C, Val {2} ( ), Val {1} ( ))
100
+ _sylvc! (A, B, C, Val ( 2 ), Val ( 1 ))
101
101
elseif M == 1 && N == 2
102
- _sylvc! (A, B, C, Val {1} ( ), Val {2} ( ))
102
+ _sylvc! (A, B, C, Val ( 1 ), Val ( 2 ))
103
103
elseif M == 1 && N == 1
104
- _sylvc! (A, B, C, Val {1} ( ), Val {1} ( ))
104
+ _sylvc! (A, B, C, Val ( 1 ), Val ( 1 ))
105
105
else
106
106
error (" Matrix dimensionsins should not be greater than 2" )
107
107
end
108
108
return C
109
109
end
110
110
@inline function _sylvc! (A:: AbstractMatrix , B:: AbstractMatrix , C:: AbstractMatrix , :: Val{M} , :: Val{N} ) where {T <: Number , M, N}
111
- A′ = SMatrix {M,M} (A)
112
- B′ = SMatrix {N,N} (B)
113
- Cv = SMatrix {M,N} (C)[:] # vectorization of C
111
+ As = SMatrix {M,M} (A)
112
+ Bs = SMatrix {N,N} (B)
113
+ Cvs = SMatrix {M,N} (C)[:] # vectorization of C
114
114
115
- Xv = lu (kron (SMatrix {N,N} (I), A′ ) + kron (transpose (B′ ), SMatrix {M,M} (I))) \ Cv # using the vectorization identity vec(AXB) = kron(B'*A)*vec(X) (with A = I or B = I)
115
+ Xv = lu (kron (SMatrix {N,N} (I), As ) + kron (transpose (Bs ), SMatrix {M,M} (I))) \ Cvs # using the vectorization identity vec(AXB) = kron(B'*A)*vec(X) (with A = I or B = I)
116
116
117
117
if any (! isfinite, Xv); error (" Matrix equation has no solution, see ?sylvc or ?lyapc" ); end
118
118
@@ -132,24 +132,24 @@ for small matrices (1x1, 1x2, 2x1, 2x2), overwriting the input `C`.
132
132
function _sylvd! (A:: AbstractMatrix , B:: AbstractMatrix , C:: AbstractMatrix )
133
133
M, N = size (C)
134
134
if M == 2 && N == 2
135
- _sylvd! (A, B, C, Val {2} ( ), Val {2} ( ))
135
+ _sylvd! (A, B, C, Val ( 2 ), Val ( 2 ))
136
136
elseif M == 2 && N == 1
137
- _sylvd! (A, B, C, Val {2} ( ), Val {1} ( ))
137
+ _sylvd! (A, B, C, Val ( 2 ), Val ( 1 ))
138
138
elseif M == 1 && N == 2
139
- _sylvd! (A, B, C, Val {1} ( ), Val {2} ( ))
139
+ _sylvd! (A, B, C, Val ( 1 ), Val ( 2 ))
140
140
elseif M == 1 && N == 1
141
- _sylvd! (A, B, C, Val {1} ( ), Val {1} ( ))
141
+ _sylvd! (A, B, C, Val ( 1 ), Val ( 1 ))
142
142
else
143
143
error (" Matrix dimensionsins should not be greater than 2" )
144
144
end
145
145
return C
146
146
end
147
147
function _sylvd! (A:: AbstractMatrix , B:: AbstractMatrix , C:: AbstractMatrix , :: Val{M} , :: Val{N} ) where {T <: Number , M, N}
148
- A′ = SMatrix {M,M} (A)
149
- B′ = SMatrix {N,N} (B)
150
- Cv = SMatrix {M,N} (C)[:] # vectorization of C
148
+ As = SMatrix {M,M} (A)
149
+ Bs = SMatrix {N,N} (B)
150
+ Cvs = SMatrix {M,N} (C)[:] # vectorization of C
151
151
152
- Xv = (kron (transpose (B′ ), A′ ) - I) \ Cv # using the vectorization identity vec(AXB) = kron(B'*A)*vec(X)
152
+ Xv = (kron (transpose (Bs ), As ) - SMatrix {M*N,M*N} (I)) \ Cvs # using the vectorization identity vec(AXB) = kron(B'*A)*vec(X)
153
153
154
154
if any (! isfinite, Xv); error (" Matrix equation has no solution, see ?sylvd or ?lyapd" ); end
155
155
@@ -302,11 +302,11 @@ function _sylvc_schur!(A::Matrix, B::Matrix, C::Matrix, alg::Union{Val{:sylv},Va
302
302
# The user should preferably use sylvc_schur! and lyapc_schur!
303
303
# I.e., this method does not check whether C is hermitian
304
304
# The matrix C is successively replaced with the solution X
305
- # if alg == Val(:lyap), only the lower triangle of C is computed
305
+ # if alg === Val(:lyap), only the lower triangle of C is computed
306
306
# after which an Hermitian view is applied
307
307
308
308
# get block indices and nbr of blocks
309
- if schurtype == Val (:real )
309
+ if schurtype === Val (:real )
310
310
_, ba, nblocksa = _schurstructure (A, Val (:L )) # A is assumed upper triangualar
311
311
_, bb, nblocksb = _schurstructure (B, Val (:U ))
312
312
else
@@ -315,15 +315,15 @@ function _sylvc_schur!(A::Matrix, B::Matrix, C::Matrix, alg::Union{Val{:sylv},Va
315
315
end
316
316
317
317
@inbounds for j= 1 : nblocksb
318
- i0 = (alg == Val (:lyap ) ? j : 1 )
318
+ i0 = (alg === Val (:lyap ) ? j : 1 )
319
319
for i= i0: nblocksa
320
- if schurtype == Val (:complex )
320
+ if schurtype === Val (:complex )
321
321
if i > 1 ; C[i,j] -= sum (A[i, k] * C[k, j] for k= 1 : i- 1 ); end
322
322
if j > 1 ; C[i,j] -= sum (C[i, k] * B[k, j] for k= 1 : j- 1 ); end
323
323
324
324
C[i,j] = sylvc (A[i, i], B[j, j], C[i, j]) # C[i,j] now contains solution Y[i,j]
325
325
326
- if alg == Val (:lyap ) && i > j
326
+ if alg === Val (:lyap ) && i > j
327
327
C[j,i] = conj (C[i,j])
328
328
end
329
329
else
@@ -336,7 +336,7 @@ function _sylvc_schur!(A::Matrix, B::Matrix, C::Matrix, alg::Union{Val{:sylv},Va
336
336
337
337
_sylvc! (Aii, Bjj, Cij) # Cij now contains the solution Yij
338
338
339
- if alg == Val (:lyap ) && i > j
339
+ if alg === Val (:lyap ) && i > j
340
340
for l= bb[j], k= ba[i]
341
341
C[l,k] = conj (C[k,l])
342
342
end
@@ -378,7 +378,7 @@ function _sylvd_schur!(A::Matrix, B::Matrix, C::Matrix, alg::Union{Val{:sylv},Va
378
378
G = zeros (eltype (C), size (A,1 ), size (B, 1 )) # Keep track of A*X for improved performance
379
379
380
380
# get block dimensions, block indices, nbr of blocks
381
- if schurtype == Val (:real )
381
+ if schurtype === Val (:real )
382
382
_, ba, nblocksa = _schurstructure (A, Val (:L )) # A is assumed upper triangualar
383
383
_, bb, nblocksb = _schurstructure (B, Val (:U ))
384
384
else
@@ -387,17 +387,17 @@ function _sylvd_schur!(A::Matrix, B::Matrix, C::Matrix, alg::Union{Val{:sylv},Va
387
387
end
388
388
389
389
@inbounds for j= 1 : nblocksb
390
- i0 = (alg == Val (:lyap ) ? j : 1 )
390
+ i0 = (alg === Val (:lyap ) ? j : 1 )
391
391
for i= i0: nblocksa
392
- if schurtype == Val (:complex )
392
+ if schurtype === Val (:complex )
393
393
# Compute Gij up to the contribution from Aii*Yij which is added at the end of each iteration
394
394
if i > 1 ; G[i,j] += sum (A[i,k] * C[k,j] for k= 1 : i- 1 ); end
395
395
396
396
C[i,j] -= sum (G[i,k] * B[k,j] for k= 1 : j)
397
397
398
398
C[i,j] = sylvd (A[i,i], B[j,j], C[i,j]) # C[i,j] now contains solution Y[i,j]
399
399
400
- if alg == Val (:lyap ) && i > j
400
+ if alg === Val (:lyap ) && i > j
401
401
C[j,i] = conj (C[i,j])
402
402
end
403
403
@@ -417,7 +417,7 @@ function _sylvd_schur!(A::Matrix, B::Matrix, C::Matrix, alg::Union{Val{:sylv},Va
417
417
418
418
_sylvd! (Aii, Bjj, Cij) # Cij now contains the solution Yij
419
419
420
- if alg == Val (:lyap ) && i > j
420
+ if alg === Val (:lyap ) && i > j
421
421
for l= bb[j], k= ba[i] # Avoids aliasing of copyto!
422
422
C[l,k] = conj (C[k,l])
423
423
end
0 commit comments