diff --git a/Project.toml b/Project.toml index d58d884e0..8a950c0c8 100644 --- a/Project.toml +++ b/Project.toml @@ -1,6 +1,6 @@ name = "ModelPredictiveControl" uuid = "61f9bdb8-6ae4-484a-811f-bbf86720c31c" -version = "2.16.5" +version = "2.16.6" authors = ["Francis Gagnon"] [deps] diff --git a/src/controller/construct.jl b/src/controller/construct.jl index d010cfe41..3b5cdc278 100644 --- a/src/controller/construct.jl +++ b/src/controller/construct.jl @@ -97,7 +97,13 @@ function ControllerWeights( model::SimModel{NT}, Hp, Hc, M_Hp, N_Hc, L_Hp, Cwt=Inf, Ewt=0 ) where {NT<:Real} validate_weights(model, Hp, Hc, M_Hp, N_Hc, L_Hp, Cwt, Ewt) - M_Hp, N_Hc, L_Hp = NT.(M_Hp), NT.(N_Hc), NT.(L_Hp) + M_Hp = eltype(M_Hp) == NT ? M_Hp : NT.(M_Hp) + N_Hc = eltype(N_Hc) == NT ? N_Hc : NT.(N_Hc) + L_Hp = eltype(L_Hp) == NT ? L_Hp : NT.(L_Hp) + # Hermitian wrappers are added in the inner constructor, remove it to avoid duplicates: + M_Hp = M_Hp isa Hermitian ? parent(M_Hp) : M_Hp + N_Hc = N_Hc isa Hermitian ? parent(N_Hc) : N_Hc + L_Hp = L_Hp isa Hermitian ? parent(L_Hp) : L_Hp return ControllerWeights{NT}(M_Hp, N_Hc, L_Hp, Cwt, Ewt) end diff --git a/src/estimator/construct.jl b/src/estimator/construct.jl index 7091ccb8f..2f089a3f7 100644 --- a/src/estimator/construct.jl +++ b/src/estimator/construct.jl @@ -141,8 +141,15 @@ function KalmanCovariances( model::SimModel{NT}, i_ym, nint_u, nint_ym, Q̂, R̂, P̂_0=nothing, He=1 ) where {NT<:Real} validate_kfcov(model, i_ym, nint_u, nint_ym, Q̂, R̂, P̂_0) - Q̂, R̂ = NT.(Q̂), NT.(R̂) - !isnothing(P̂_0) && (P̂_0 = NT.(P̂_0)) + Q̂ = eltype(Q̂) == NT ? Q̂ : NT.(Q̂) + R̂ = eltype(R̂) == NT ? R̂ : NT.(R̂) + # Hermitian wrappers are added in the inner constructor, remove it to avoid duplicates: + Q̂ = Q̂ isa Hermitian ? parent(Q̂) : Q̂ + R̂ = R̂ isa Hermitian ? parent(R̂) : R̂ + if !isnothing(P̂_0) + P̂_0 = eltype(P̂_0) == NT ? P̂_0 : NT.(P̂_0) + P̂_0 = P̂_0 isa Hermitian ? parent(P̂_0) : P̂_0 + end return KalmanCovariances{NT}(Q̂, R̂, P̂_0, He) end