You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: src/freqresp.jl
+66-9Lines changed: 66 additions & 9 deletions
Original file line number
Diff line number
Diff line change
@@ -67,34 +67,90 @@ end
67
67
@inboundsfor i ineachindex(w_vec)
68
68
R[:,:,i] .= sys.D
69
69
end
70
-
returnPDT(R)
70
+
returnPDT(R)::PDT
71
71
end
72
72
local F, Q
73
73
try
74
74
F =hessenberg(sys.A)
75
75
Q =Matrix(F.Q)
76
76
catch e
77
77
# For matrix types that do not have a hessenberg implementation, we call the standard version of freqresp.
78
-
e isa MethodError &&returnfreqresp_nohess!(R, sys, w_vec)
78
+
e isa Union{MethodError, ErrorException} &&returnfreqresp_nohess!(R, sys, w_vec)
79
+
# ErrorException appears if we try to access Q on a type which does not have Q as a field or property, notably HessenbergFactorization from GenericLinearAlgebra
79
80
rethrow()
80
81
end
81
82
A = F.H
82
-
C = sys.C*Q
83
+
C =complex.(sys.C*Q) # We make C complex in order to not incur allocations in mul! below
83
84
B = Q\sys.B
84
85
D = sys.D
85
86
86
87
te = sys.timeevol
87
88
Bc =similar(B, T) # for storage
89
+
w =-_freq(w_vec[1], te)
90
+
u =Vector{typeof(zero(eltype(A.data))+w)}(undef, sys.nx)
91
+
cs =Vector{Tuple{real(eltype(u)),eltype(u)}}(undef, length(u)) # store Givens rotations
88
92
@inboundsfor i ineachindex(w_vec)
89
-
Ri =@viewsR[:,:,i]
93
+
Ri =@view(R[:, :, i])
90
94
copyto!(Ri,D) # start with the D-matrix
91
95
isinf(w_vec[i]) &&continue
92
96
copyto!(Bc,B) # initialize storage to B
93
97
w =-_freq(w_vec[i], te)
94
-
ldiv!(A, Bc, shift = w) # B += (A - w*I)\B # solve (A-wI)X = B, storing result in B
98
+
ldiv2!(u, cs, A, Bc, shift = w) # B += (A - w*I)\B # solve (A-wI)X = B, storing result in B
95
99
mul!(Ri, C, Bc, -1, 1) # use of 5-arg mul to subtract from D already in Ri. - rather than + since (A - w*I) instead of (w*I - A)
96
100
end
97
-
PDT(R) # PermutedDimsArray doesn't allocate to perform the permutation
101
+
PDT(R)::PDT# PermutedDimsArray doesn't allocate to perform the permutation
102
+
end
103
+
104
+
#=
105
+
Custom implementation of hessenberg ldiv to allow reuse of u and cs
106
+
With this method, the following benchmark goes from
0 commit comments