Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

#634 - Integrate ReachabilityBase.expm #703

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion Project.toml
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ IntervalMatrices = "0.6 - 0.8"
LazySets = "2.3"
MathematicalSystems = "0.11 - 0.13"
Parameters = "0.10 - 0.12"
ReachabilityBase = "0.1"
ReachabilityBase = "0.1.8"
RecipesBase = "0.6 - 0.8, 1"
RecursiveArrayTools = "2"
Reexport = "0.2, 1"
Expand Down
16 changes: 8 additions & 8 deletions src/Discretization/exponentiation.jl
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using LinearAlgebra: checksquare
using ReachabilityBase.Expm: expm

# ==========================
# Exponentiation functions
Expand Down Expand Up @@ -100,8 +101,7 @@ const PadeExp = PadeExpAlg()
_alias(alg::Val{:pade}) = PadeExp

# general case: convert to Matrix
@inline _exp(A::AbstractMatrix, ::BaseExpAlg) = exp(Matrix(A))
@inline _exp(A::Matrix, ::BaseExpAlg) = exp(A)
@inline _exp(A::AbstractMatrix, ::BaseExpAlg) = expm(A)

# static arrays have their own exp method
@inline _exp(A::StaticArray, ::BaseExpAlg) = exp(A)
Expand Down Expand Up @@ -182,7 +182,7 @@ evaluated with an external library such as `ExponentialUtilities.jl` or
`Expokit.jl`.
"""
function _exp(A::AbstractMatrix, δ, alg::AbstractExpAlg=BaseExp)
n = checksquare(A)
checksquare(A)
return _exp(A * δ, alg)
end

Expand Down Expand Up @@ -287,7 +287,7 @@ function _Φ₁_inv(A::AbstractMatrix, δ, alg, Φ=nothing)
if isnothing(Φ)
Φ = _exp(A, δ, alg)
end
n = size(A, 1)
n = checksquare(A)
N = eltype(A)
In = Matrix(one(N) * I, n, n)
Ainv = inv(A)
Expand Down Expand Up @@ -419,7 +419,7 @@ function _Φ₂_inv(A::AbstractMatrix, δ, alg, Φ=nothing)
if isnothing(Φ)
Φ = _exp(Aδ, alg)
end
n = size(A, 1)
n = checksquare(A)
N = eltype(A)
In = Matrix(one(N) * I, n, n)
B = Φ - In - Aδ
Expand All @@ -437,7 +437,7 @@ function _Φ₂_inv(A::IdentityMultiple, δ, alg, Φ=nothing)
return IdentityMultiple(α, size(A, 1))
end

function _Eplus(A::SparseMatrixCSC{N,D}, X0::AbstractHyperrectangle{N}, δt; m=min(30, size(A, 1)),
function _Eplus(A::SparseMatrixCSC{N,D}, X0::AbstractHyperrectangle{N}, δt; m=min(30, checksquare(A)),
tol=1e-7) where {N,D}
n = dim(X0)
A2 = A * A # fast if A sparse
Expand All @@ -458,7 +458,7 @@ end
@inline function _elementwise_abs(A::SparseMatrixCSC)
return SparseMatrixCSC(A.m, A.n, A.colptr, A.rowval, abs.(nonzeros(A)))
end
@inline _elementwise_abs(A::IdentityMultiple) = IdentityMultiple(abs(A.M.λ), size(A, 1))
@inline _elementwise_abs(A::IdentityMultiple) = IdentityMultiple(abs(A.M.λ), checksquare(A))

# ====================================
# Exponentiation of interval matrices
Expand All @@ -468,7 +468,7 @@ end

# compute Iδ + 1/2 * δ^2 * A + 1/6 * δ^3 * A² + ... + 1/(η+1)! * δ^(η+1) * A^η + E(δ) * δ
function _Cδ(A, δ, order)
n = size(A, 1)
n = checksquare(A)
A² = A * A
if isa(A, IntervalMatrix)
Iδ = IntervalMatrix(Diagonal(fill(IA.Interval(δ), n)))
Expand Down
Loading