Skip to content

Commit e2dea34

Browse files
committed
add a few error hints for factorizations on exotic number types
1 parent aa299b7 commit e2dea34

File tree

3 files changed

+10
-1
lines changed

3 files changed

+10
-1
lines changed

docs/src/examples/automatic_differentiation.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -308,7 +308,7 @@ The following issues are currently known to exist when using AD through ControlS
308308

309309
### ForwardDiff
310310
[ForwardDiff.jl](https://github.com/JuliaDiff/ForwardDiff.jl) works for a lot of workflows without any intervention required from the user. The following known limitations exist:
311-
- The function [`c2d`](@ref) with the default `:zoh` discretization method makes a call to `LinearAlgebra.exp!`, which is not defined for `ForwardDiff.Dual` numbers. A forward rule for this function exist in ChainRules, which can be enabled using ForwardDiffChainRules.jl, but [this PR](https://github.com/ThummeTo/ForwardDiffChainRules.jl/pull/16) must be merged and released before it will work as intended. A workaround is to use the `:tustin` method instead, or [manually defining this method](https://github.com/JuliaControl/ControlSystems.jl/blob/master/docs/src/examples/automatic_differentiation.md?plain=1#LL2C1-L25C4).
311+
- The function [`c2d`](@ref) with the default `:zoh` discretization method makes a call to `LinearAlgebra.exp!`, which is not defined for `ForwardDiff.Dual` numbers. A forward rule for this function exist in ChainRules, which can be enabled using ForwardDiffChainRules.jl. One may also define `LinearAlgebra.exp!(A::AbstractMatrix{<:ForwardDiff.Dual}) = ExponentialUtilities.exponential!(A)`.
312312
- The function `svdvals` does not have a forward rule defined. This means that the functions [`sigma`](@ref) and `opnorm` will not work for MIMO systems with ForwardDiff. SISO, MISO and SIMO systems will, however, work.
313313
- [`hinfnorm`](@ref) requires ImplicitDifferentiation.jl and ComponentArrays.jl to be manually loaded by the user, after which there are implicit differentiation rules defined for [`hinfnorm`](@ref). The implicit rule calls `opnorm`, and is thus affected by the first limitation above for MIMO systems. [`hinfnorm`](@ref) has a reverse rule defined in RobustAndOptimalControl.jl, which is not affected by this limitation.
314314
- [`are`](@ref), [`lqr`](@ref) and [`kalman`](@ref) all require ImplicitDifferentiation.jl and ComponentArrays.jl to be manually loaded by the user, after which there are implicit differentiation rules defined. To invoke the correct method of these functions, it is important that the second matrix (corresponding to input or measurement) has the `Dual` number type, i.e., the `R` matrix in `lqr(P, Q, R)` or `lqr(Continuous, A, B, Q, R)`

lib/ControlSystemsBase/src/ControlSystemsBase.jl

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -252,6 +252,10 @@ function __init__()
252252
print(io, " for automatic discretization (applicable to systems without delays or nonlinearities only).")
253253
elseif exc.f (eigvals!, ) && argtypes[1] <: AbstractMatrix{<:Number}
254254
printstyled(io, "\nComputing eigenvalues of a matrix with exotic element types may require `using GenericSchur`.", color=:green, bold=true)
255+
elseif (exc.f === svdvals! || exc.f === svd!) && length(argtypes) >= 1 && argtypes[1] <: AbstractMatrix{<:Number}
256+
printstyled(io, "\nComputing the SVD of a matrix with exotic element types may require `using GenericLinearAlgebra`.", color=:green, bold=true)
257+
elseif exc.f === schur! && length(argtypes) >= 1 && argtypes[1] <: AbstractMatrix{<:Number}
258+
printstyled(io, "\nComputing Schur decomposition of a matrix with exotic element types may require `using GenericSchur`.", color=:green, bold=true)
255259
end
256260
plots_id = Base.PkgId(UUID("91a5bcdd-55d7-5caf-9e0b-520d859cae80"), "Plots")
257261
if exc.f isa Function && nameof(exc.f) === :plot && parentmodule(argtypes[1]) == @__MODULE__() && !haskey(Base.loaded_modules, plots_id)

lib/ControlSystemsBase/test/runtests.jl

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,11 @@ using Aqua
1212
)
1313
end
1414

15+
BIGMAT = big(1.0)*randn(3,3)
16+
@test_throws MethodError svd(BIGMAT)
17+
@test_throws MethodError eigvals(BIGMAT)
18+
@test_throws MethodError schur(BIGMAT)
19+
1520

1621
include("framework.jl")
1722

0 commit comments

Comments
 (0)