Skip to content

Commit 7781ff9

Browse files
author
olof3
committed
Minor fixes.
1 parent 6615224 commit 7781ff9

File tree

2 files changed

+29
-29
lines changed

2 files changed

+29
-29
lines changed

src/LyapTest.jl

Lines changed: 28 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ function _schurstructure(R::AbstractMatrix, ul=Val(:U)::Union{Val{:U}, Val{:L}})
4646
if j == n
4747
d[k] = 1
4848
else
49-
if ul == Val(:U)
49+
if ul === Val(:U)
5050
d[k] = iszero(R[j+1, j]) ? 1 : 2
5151
else
5252
d[k] = iszero(R[j, j+1]) ? 1 : 2
@@ -95,24 +95,24 @@ for small matrices (1x1, 1x2, 2x1, 2x2), overwriting the input `C`.
9595
@inline function _sylvc!(A::AbstractMatrix, B::AbstractMatrix, C::AbstractMatrix)
9696
M, N = size(C)
9797
if M == 2 && N == 2
98-
_sylvc!(A, B, C, Val{2}(), Val{2}())
98+
_sylvc!(A, B, C, Val(2), Val(2))
9999
elseif M == 2 && N == 1
100-
_sylvc!(A, B, C, Val{2}(), Val{1}())
100+
_sylvc!(A, B, C, Val(2), Val(1))
101101
elseif M == 1 && N == 2
102-
_sylvc!(A, B, C, Val{1}(), Val{2}())
102+
_sylvc!(A, B, C, Val(1), Val(2))
103103
elseif M == 1 && N == 1
104-
_sylvc!(A, B, C, Val{1}(), Val{1}())
104+
_sylvc!(A, B, C, Val(1), Val(1))
105105
else
106106
error("Matrix dimensionsins should not be greater than 2")
107107
end
108108
return C
109109
end
110110
@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
114114

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)
116116

117117
if any(!isfinite, Xv); error("Matrix equation has no solution, see ?sylvc or ?lyapc"); end
118118

@@ -132,24 +132,24 @@ for small matrices (1x1, 1x2, 2x1, 2x2), overwriting the input `C`.
132132
function _sylvd!(A::AbstractMatrix, B::AbstractMatrix, C::AbstractMatrix)
133133
M, N = size(C)
134134
if M == 2 && N == 2
135-
_sylvd!(A, B, C, Val{2}(), Val{2}())
135+
_sylvd!(A, B, C, Val(2), Val(2))
136136
elseif M == 2 && N == 1
137-
_sylvd!(A, B, C, Val{2}(), Val{1}())
137+
_sylvd!(A, B, C, Val(2), Val(1))
138138
elseif M == 1 && N == 2
139-
_sylvd!(A, B, C, Val{1}(), Val{2}())
139+
_sylvd!(A, B, C, Val(1), Val(2))
140140
elseif M == 1 && N == 1
141-
_sylvd!(A, B, C, Val{1}(), Val{1}())
141+
_sylvd!(A, B, C, Val(1), Val(1))
142142
else
143143
error("Matrix dimensionsins should not be greater than 2")
144144
end
145145
return C
146146
end
147147
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
151151

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)
153153

154154
if any(!isfinite, Xv); error("Matrix equation has no solution, see ?sylvd or ?lyapd"); end
155155

@@ -302,11 +302,11 @@ function _sylvc_schur!(A::Matrix, B::Matrix, C::Matrix, alg::Union{Val{:sylv},Va
302302
# The user should preferably use sylvc_schur! and lyapc_schur!
303303
# I.e., this method does not check whether C is hermitian
304304
# 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
306306
# after which an Hermitian view is applied
307307

308308
# get block indices and nbr of blocks
309-
if schurtype == Val(:real)
309+
if schurtype === Val(:real)
310310
_, ba, nblocksa = _schurstructure(A, Val(:L)) # A is assumed upper triangualar
311311
_, bb, nblocksb = _schurstructure(B, Val(:U))
312312
else
@@ -315,15 +315,15 @@ function _sylvc_schur!(A::Matrix, B::Matrix, C::Matrix, alg::Union{Val{:sylv},Va
315315
end
316316

317317
@inbounds for j=1:nblocksb
318-
i0 = (alg == Val(:lyap) ? j : 1)
318+
i0 = (alg === Val(:lyap) ? j : 1)
319319
for i=i0:nblocksa
320-
if schurtype == Val(:complex)
320+
if schurtype === Val(:complex)
321321
if i > 1; C[i,j] -= sum(A[i, k] * C[k, j] for k=1:i-1); end
322322
if j > 1; C[i,j] -= sum(C[i, k] * B[k, j] for k=1:j-1); end
323323

324324
C[i,j] = sylvc(A[i, i], B[j, j], C[i, j]) # C[i,j] now contains solution Y[i,j]
325325

326-
if alg == Val(:lyap) && i > j
326+
if alg === Val(:lyap) && i > j
327327
C[j,i] = conj(C[i,j])
328328
end
329329
else
@@ -336,7 +336,7 @@ function _sylvc_schur!(A::Matrix, B::Matrix, C::Matrix, alg::Union{Val{:sylv},Va
336336

337337
_sylvc!(Aii, Bjj, Cij) # Cij now contains the solution Yij
338338

339-
if alg == Val(:lyap) && i > j
339+
if alg === Val(:lyap) && i > j
340340
for l=bb[j], k=ba[i]
341341
C[l,k] = conj(C[k,l])
342342
end
@@ -378,7 +378,7 @@ function _sylvd_schur!(A::Matrix, B::Matrix, C::Matrix, alg::Union{Val{:sylv},Va
378378
G = zeros(eltype(C), size(A,1), size(B, 1)) # Keep track of A*X for improved performance
379379

380380
# get block dimensions, block indices, nbr of blocks
381-
if schurtype == Val(:real)
381+
if schurtype === Val(:real)
382382
_, ba, nblocksa = _schurstructure(A, Val(:L)) # A is assumed upper triangualar
383383
_, bb, nblocksb = _schurstructure(B, Val(:U))
384384
else
@@ -387,17 +387,17 @@ function _sylvd_schur!(A::Matrix, B::Matrix, C::Matrix, alg::Union{Val{:sylv},Va
387387
end
388388

389389
@inbounds for j=1:nblocksb
390-
i0 = (alg == Val(:lyap) ? j : 1)
390+
i0 = (alg === Val(:lyap) ? j : 1)
391391
for i=i0:nblocksa
392-
if schurtype == Val(:complex)
392+
if schurtype === Val(:complex)
393393
# Compute Gij up to the contribution from Aii*Yij which is added at the end of each iteration
394394
if i > 1; G[i,j] += sum(A[i,k] * C[k,j] for k=1:i-1); end
395395

396396
C[i,j] -= sum(G[i,k] * B[k,j] for k=1:j)
397397

398398
C[i,j] = sylvd(A[i,i], B[j,j], C[i,j]) # C[i,j] now contains solution Y[i,j]
399399

400-
if alg == Val(:lyap) && i > j
400+
if alg === Val(:lyap) && i > j
401401
C[j,i] = conj(C[i,j])
402402
end
403403

@@ -417,7 +417,7 @@ function _sylvd_schur!(A::Matrix, B::Matrix, C::Matrix, alg::Union{Val{:sylv},Va
417417

418418
_sylvd!(Aii, Bjj, Cij) # Cij now contains the solution Yij
419419

420-
if alg == Val(:lyap) && i > j
420+
if alg === Val(:lyap) && i > j
421421
for l=bb[j], k=ba[i] # Avoids aliasing of copyto!
422422
C[l,k] = conj(C[k,l])
423423
end

test/test_matrix_equations.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ using MatrixEquations
88
Random.seed!(0)
99

1010

11-
include("src/LyapTest.jl")
11+
include("../src/LyapTest.jl")
1212

1313
# Test _schurstructure
1414
R = diagm(0 => [1, 1, 1, 1, 1, 1, 1, 1], -1 => [1, 0, 0, 0, 1, 0, 0])

0 commit comments

Comments
 (0)