Skip to content

Commit a487a1d

Browse files
committed
handle exotic types in balance
1 parent 7266a8c commit a487a1d

File tree

2 files changed

+11
-1
lines changed

2 files changed

+11
-1
lines changed

lib/ControlSystemsBase/src/matrix_comps.jl

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -542,7 +542,7 @@ Compute a similarity transform `T = S*P` resulting in `B = T\\A*T` such that the
542542
and column norms of `B` are approximately equivalent. If `perm=false`, the
543543
transformation will only scale `A` using diagonal `S`, and not permute `A` (i.e., set `P=I`).
544544
"""
545-
function balance(A, perm::Bool=true)
545+
function balance(A::AbstractMatrix{<:LinearAlgebra.BlasFloat}, perm::Bool=true)
546546
n = LinearAlgebra.checksquare(A)
547547
B = copy(A)
548548
job = perm ? 'B' : 'S'
@@ -570,6 +570,11 @@ function cswap!(i::Integer, j::Integer, X::StridedMatrix)
570570
end
571571
end
572572

573+
function balance(A::AbstractMatrix, perm::Bool=true)
574+
Ac = Float64.(A)
575+
balance(Ac, perm)
576+
end
577+
573578

574579

575580
"""

lib/ControlSystemsBase/test/test_matrix_comps.jl

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,11 @@ sysb,T = ControlSystemsBase.balance_statespace(sys)
1515
@test similarity_transform(sysb, T) sys
1616
Ab,Bb,Cb,T = ControlSystemsBase.balance_statespace(A,B,C)
1717

18+
sysbb,Tb = ControlSystemsBase.balance_statespace(big(1.0)*sys)
19+
@test Tb T
20+
@test sysbb sysb
21+
22+
1823
@test Ab*T T*A
1924
@test Bb T*B
2025
@test Cb*T C

0 commit comments

Comments
 (0)