@@ -39,8 +39,9 @@ _freq(w, te::Discrete) = cis(w*te.Ts)
3939@autovec () function freqresp (sys:: AbstractStateSpace , w_vec:: AbstractVector{W} ) where W <: Real
4040 ny, nu = size (sys)
4141 T = promote_type (Complex{real (eltype (sys. A))}, Complex{W})
42+ PDT = PermutedDimsArray{T,3 ,(3 ,1 ,2 ),(2 ,3 ,1 ),Array{T,3 }}
4243 if sys. nx == 0 # Only D-matrix
43- return PermutedDimsArray (repeat (T .(sys. D), 1 , 1 , length (w_vec)), ( 3 , 1 , 2 ))
44+ return PDT (repeat (T .(sys. D), 1 , 1 , length (w_vec)))
4445 end
4546 local F, Q
4647 try
@@ -68,7 +69,7 @@ _freq(w, te::Discrete) = cis(w*te.Ts)
6869 ldiv! (A, Bc, shift = w) # B += (A - w*I)\B # solve (A-wI)X = B, storing result in B
6970 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)
7071 end
71- PermutedDimsArray (R, ( 3 , 1 , 2 ) ) # PermutedDimsArray doesn't allocate to perform the permutation
72+ PDT (R ) # PermutedDimsArray doesn't allocate to perform the permutation
7273end
7374
7475"""
@@ -82,8 +83,9 @@ freqresp_nohess
8283 ny, nu = size (sys)
8384 nx = sys. nx
8485 T = promote_type (Complex{real (eltype (sys. A))}, Complex{W})
86+ PDT = PermutedDimsArray{T,3 ,(3 ,1 ,2 ),(2 ,3 ,1 ),Array{T,3 }}
8587 if nx == 0 # Only D-matrix
86- return PermutedDimsArray (repeat (T .(sys. D), 1 , 1 , length (w_vec)), ( 3 , 1 , 2 ))
88+ return PDT (repeat (T .(sys. D), 1 , 1 , length (w_vec)))
8789 end
8890 A,B,C,D = ssdata (sys)
8991 te = sys. timeevol
@@ -100,7 +102,7 @@ freqresp_nohess
100102 Bc = Ac \ B # Bc = (A - w*I)\B # avoid inplace to handle sparse matrices etc.
101103 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)
102104 end
103- PermutedDimsArray (R, ( 3 , 1 , 2 ) ) # PermutedDimsArray doesn't allocate to perform the permutation
105+ PDT (R ) # PermutedDimsArray doesn't allocate to perform the permutation
104106end
105107
106108
0 commit comments