|
1 | | -# check if a matrix is square |
2 | | -@inline function issquare(A::AbstractMatrix) |
3 | | - return size(A, 1) == size(A, 2) |
4 | | -end |
5 | | - |
6 | 1 | for (Z, AZ) in ((:ContinuousIdentitySystem, :AbstractContinuousSystem), |
7 | 2 | (:DiscreteIdentitySystem, :AbstractDiscreteSystem)) |
8 | 3 | @eval begin |
@@ -120,7 +115,7 @@ for (Z, AZ) in ((:LinearContinuousSystem, :AbstractContinuousSystem), |
120 | 115 | struct $(Z){T,MT<:AbstractMatrix{T}} <: $(AZ) |
121 | 116 | A::MT |
122 | 117 | function $(Z)(A::MT) where {T,MT<:AbstractMatrix{T}} |
123 | | - @assert issquare(A) |
| 118 | + checksquare(A) |
124 | 119 | return new{T,MT}(A) |
125 | 120 | end |
126 | 121 | end |
@@ -183,7 +178,9 @@ for (Z, AZ) in ((:AffineContinuousSystem, :AbstractContinuousSystem), |
183 | 178 | A::MT |
184 | 179 | c::VT |
185 | 180 | function $(Z)(A::MT, c::VT) where {T,MT<:AbstractMatrix{T},VT<:AbstractVector{T}} |
186 | | - @assert checksquare(A) == length(c) |
| 181 | + if checksquare(A) != length(c) |
| 182 | + throw(DimensionMismatch("incompatible dimensions")) |
| 183 | + end |
187 | 184 | return new{T,MT,VT}(A, c) |
188 | 185 | end |
189 | 186 | end |
@@ -249,7 +246,9 @@ for (Z, AZ) in ((:LinearControlContinuousSystem, :AbstractContinuousSystem), |
249 | 246 | A::MTA |
250 | 247 | B::MTB |
251 | 248 | function $(Z)(A::MTA, B::MTB) where {T,MTA<:AbstractMatrix{T},MTB<:AbstractMatrix{T}} |
252 | | - @assert checksquare(A) == size(B, 1) |
| 249 | + if checksquare(A) != size(B, 1) |
| 250 | + throw(DimensionMismatch("incompatible dimensions")) |
| 251 | + end |
253 | 252 | return new{T,MTA,MTB}(A, B) |
254 | 253 | end |
255 | 254 | end |
@@ -315,7 +314,7 @@ for (Z, AZ) in ((:ConstrainedLinearContinuousSystem, :AbstractContinuousSystem), |
315 | 314 | A::MT |
316 | 315 | X::ST |
317 | 316 | function $(Z)(A::MT, X::ST) where {T,MT<:AbstractMatrix{T},ST} |
318 | | - @assert issquare(A) |
| 317 | + checksquare(A) |
319 | 318 | return new{T,MT,ST}(A, X) |
320 | 319 | end |
321 | 320 | end |
@@ -383,7 +382,9 @@ for (Z, AZ) in ((:ConstrainedAffineContinuousSystem, :AbstractContinuousSystem), |
383 | 382 | X::ST |
384 | 383 | function $(Z)(A::MT, c::VT, |
385 | 384 | X::ST) where {T,MT<:AbstractMatrix{T},VT<:AbstractVector{T},ST} |
386 | | - @assert checksquare(A) == length(c) |
| 385 | + if checksquare(A) != length(c) |
| 386 | + throw(DimensionMismatch("incompatible dimensions")) |
| 387 | + end |
387 | 388 | return new{T,MT,VT,ST}(A, c, X) |
388 | 389 | end |
389 | 390 | end |
@@ -455,7 +456,9 @@ for (Z, AZ) in ((:AffineControlContinuousSystem, :AbstractContinuousSystem), |
455 | 456 | function $(Z)(A::MTA, B::MTB, |
456 | 457 | c::VT) where {T,MTA<:AbstractMatrix{T},MTB<:AbstractMatrix{T}, |
457 | 458 | VT<:AbstractVector{T}} |
458 | | - @assert checksquare(A) == length(c) == size(B, 1) |
| 459 | + if !(checksquare(A) == length(c) == size(B, 1)) |
| 460 | + throw(DimensionMismatch("incompatible dimensions")) |
| 461 | + end |
459 | 462 | return new{T,MTA,MTB,VT}(A, B, c) |
460 | 463 | end |
461 | 464 | end |
@@ -530,7 +533,9 @@ for (Z, AZ) in ((:ConstrainedAffineControlContinuousSystem, :AbstractContinuousS |
530 | 533 | function $(Z)(A::MTA, B::MTB, c::VT, X::ST, |
531 | 534 | U::UT) where {T,MTA<:AbstractMatrix{T},MTB<:AbstractMatrix{T}, |
532 | 535 | VT<:AbstractVector{T},ST,UT} |
533 | | - @assert checksquare(A) == length(c) == size(B, 1) |
| 536 | + if !(checksquare(A) == length(c) == size(B, 1)) |
| 537 | + throw(DimensionMismatch("incompatible dimensions")) |
| 538 | + end |
534 | 539 | return new{T,MTA,MTB,VT,ST,UT}(A, B, c, X, U) |
535 | 540 | end |
536 | 541 | end |
@@ -608,7 +613,9 @@ for (Z, AZ) in ((:ConstrainedLinearControlContinuousSystem, :AbstractContinuousS |
608 | 613 | U::UT |
609 | 614 | function $(Z)(A::MTA, B::MTB, X::ST, |
610 | 615 | U::UT) where {T,MTA<:AbstractMatrix{T},MTB<:AbstractMatrix{T},ST,UT} |
611 | | - @assert checksquare(A) == size(B, 1) |
| 616 | + if checksquare(A) != size(B, 1) |
| 617 | + throw(DimensionMismatch("incompatible dimensions")) |
| 618 | + end |
612 | 619 | return new{T,MTA,MTB,ST,UT}(A, B, X, U) |
613 | 620 | end |
614 | 621 | end |
@@ -679,7 +686,9 @@ for (Z, AZ) in ((:LinearDescriptorContinuousSystem, :AbstractContinuousSystem), |
679 | 686 | A::MTA |
680 | 687 | E::MTE |
681 | 688 | function $(Z)(A::MTA, E::MTE) where {T,MTA<:AbstractMatrix{T},MTE<:AbstractMatrix{T}} |
682 | | - @assert size(A) == size(E) |
| 689 | + if size(A) != size(E) |
| 690 | + throw(DimensionMismatch("incompatible dimensions")) |
| 691 | + end |
683 | 692 | return new{T,MTA,MTE}(A, E) |
684 | 693 | end |
685 | 694 | end |
@@ -746,7 +755,9 @@ for (Z, AZ) in ((:ConstrainedLinearDescriptorContinuousSystem, :AbstractContinuo |
746 | 755 | X::ST |
747 | 756 | function $(Z)(A::MTA, E::MTE, |
748 | 757 | X::ST) where {T,MTA<:AbstractMatrix{T},MTE<:AbstractMatrix{T},ST} |
749 | | - @assert size(A) == size(E) |
| 758 | + if size(A) != size(E) |
| 759 | + throw(DimensionMismatch("incompatible dimensions")) |
| 760 | + end |
750 | 761 | return new{T,MTA,MTE,ST}(A, E, X) |
751 | 762 | end |
752 | 763 | end |
@@ -816,7 +827,9 @@ for (Z, AZ) in ((:PolynomialContinuousSystem, :AbstractContinuousSystem), |
816 | 827 | function $(Z)(p::VPT, |
817 | 828 | statedim::Int) where {T,PT<:AbstractPolynomialLike{T}, |
818 | 829 | VPT<:AbstractVector{PT}} |
819 | | - @assert statedim == MultivariatePolynomials.nvariables(p) "the state dimension $(statedim) does not match the number of state variables" |
| 830 | + if statedim != MultivariatePolynomials.nvariables(p) |
| 831 | + throw(DimensionMismatch("the state dimension $(statedim) does not match the number of state variables")) |
| 832 | + end |
820 | 833 | return new{T,PT,VPT}(p, statedim) |
821 | 834 | end |
822 | 835 | end |
@@ -887,7 +900,9 @@ for (Z, AZ) in ((:ConstrainedPolynomialContinuousSystem, :AbstractContinuousSyst |
887 | 900 | X::ST |
888 | 901 | function $(Z)(p::VPT, statedim::Int, |
889 | 902 | X::ST) where {T,PT<:AbstractPolynomialLike{T},VPT<:AbstractVector{PT},ST} |
890 | | - @assert statedim == MultivariatePolynomials.nvariables(p) "the state dimension $(statedim) does not match the number of state variables" |
| 903 | + if statedim != MultivariatePolynomials.nvariables(p) |
| 904 | + throw(DimensionMismatch("the state dimension $(statedim) does not match the number of state variables")) |
| 905 | + end |
891 | 906 | return new{T,PT,VPT,ST}(p, statedim, X) |
892 | 907 | end |
893 | 908 | end |
@@ -1213,7 +1228,9 @@ for (Z, AZ) in ((:NoisyLinearContinuousSystem, :AbstractContinuousSystem), |
1213 | 1228 | A::MTA |
1214 | 1229 | D::MTD |
1215 | 1230 | function $(Z)(A::MTA, D::MTD) where {T,MTA<:AbstractMatrix{T},MTD<:AbstractMatrix{T}} |
1216 | | - @assert checksquare(A) == size(D, 1) |
| 1231 | + if checksquare(A) != size(D, 1) |
| 1232 | + throw(DimensionMismatch("incompatible dimensions")) |
| 1233 | + end |
1217 | 1234 | return new{T,MTA,MTD}(A, D) |
1218 | 1235 | end |
1219 | 1236 | end |
@@ -1282,7 +1299,9 @@ for (Z, AZ) in ((:NoisyConstrainedLinearContinuousSystem, :AbstractContinuousSys |
1282 | 1299 | W::WT |
1283 | 1300 | function $(Z)(A::MTA, D::MTD, X::ST, |
1284 | 1301 | W::WT) where {T,MTA<:AbstractMatrix{T},MTD<:AbstractMatrix{T},ST,WT} |
1285 | | - @assert checksquare(A) == size(D, 1) |
| 1302 | + if checksquare(A) != size(D, 1) |
| 1303 | + throw(DimensionMismatch("incompatible dimensions")) |
| 1304 | + end |
1286 | 1305 | return new{T,MTA,MTD,ST,WT}(A, D, X, W) |
1287 | 1306 | end |
1288 | 1307 | end |
@@ -1357,7 +1376,9 @@ for (Z, AZ) in ((:NoisyLinearControlContinuousSystem, :AbstractContinuousSystem) |
1357 | 1376 | function $(Z)(A::MTA, B::MTB, |
1358 | 1377 | D::MTD) where {T,MTA<:AbstractMatrix{T},MTB<:AbstractMatrix{T}, |
1359 | 1378 | MTD<:AbstractMatrix{T}} |
1360 | | - @assert checksquare(A) == size(B, 1) == size(D, 1) |
| 1379 | + if !(checksquare(A) == size(B, 1) == size(D, 1)) |
| 1380 | + throw(DimensionMismatch("incompatible dimensions")) |
| 1381 | + end |
1361 | 1382 | return new{T,MTA,MTB,MTD}(A, B, D) |
1362 | 1383 | end |
1363 | 1384 | end |
@@ -1435,7 +1456,9 @@ for (Z, AZ) in ((:NoisyConstrainedLinearControlContinuousSystem, :AbstractContin |
1435 | 1456 | function $(Z)(A::MTA, B::MTB, D::MTD, X::ST, U::UT, |
1436 | 1457 | W::WT) where {T,MTA<:AbstractMatrix{T},MTB<:AbstractMatrix{T}, |
1437 | 1458 | MTD<:AbstractMatrix{T},ST,UT,WT} |
1438 | | - @assert checksquare(A) == size(B, 1) == size(D, 1) |
| 1459 | + if !(checksquare(A) == size(B, 1) == size(D, 1)) |
| 1460 | + throw(DimensionMismatch("incompatible dimensions")) |
| 1461 | + end |
1439 | 1462 | return new{T,MTA,MTB,MTD,ST,UT,WT}(A, B, D, X, U, W) |
1440 | 1463 | end |
1441 | 1464 | end |
@@ -1522,7 +1545,9 @@ for (Z, AZ) in ((:NoisyAffineControlContinuousSystem, :AbstractContinuousSystem) |
1522 | 1545 | function $(Z)(A::MTA, B::MTB, c::VT, |
1523 | 1546 | D::MTD) where {T,MTA<:AbstractMatrix{T},MTB<:AbstractMatrix{T}, |
1524 | 1547 | VT<:AbstractVector{T},MTD<:AbstractMatrix{T}} |
1525 | | - @assert checksquare(A) == length(c) == size(B, 1) == size(D, 1) |
| 1548 | + if !(checksquare(A) == length(c) == size(B, 1) == size(D, 1)) |
| 1549 | + throw(DimensionMismatch("incompatible dimensions")) |
| 1550 | + end |
1526 | 1551 | return new{T,MTA,MTB,VT,MTD}(A, B, c, D) |
1527 | 1552 | end |
1528 | 1553 | end |
@@ -1602,7 +1627,9 @@ for (Z, AZ) in ((:NoisyConstrainedAffineControlContinuousSystem, :AbstractContin |
1602 | 1627 | function $(Z)(A::MTA, B::MTB, c::VT, D::MTD, X::ST, U::UT, |
1603 | 1628 | W::WT) where {T,MTA<:AbstractMatrix{T},MTB<:AbstractMatrix{T}, |
1604 | 1629 | VT<:AbstractVector{T},MTD<:AbstractMatrix{T},ST,UT,WT} |
1605 | | - @assert checksquare(A) == length(c) == size(B, 1) == size(D, 1) |
| 1630 | + if !(checksquare(A) == length(c) == size(B, 1) == size(D, 1)) |
| 1631 | + throw(DimensionMismatch("incompatible dimensions")) |
| 1632 | + end |
1606 | 1633 | return new{T,MTA,MTB,VT,MTD,ST,UT,WT}(A, B, c, D, X, U, W) |
1607 | 1634 | end |
1608 | 1635 | end |
@@ -1867,7 +1894,9 @@ for (Z, AZ) in ((:SecondOrderLinearContinuousSystem, :AbstractContinuousSystem), |
1867 | 1894 | K::MTK) where {T,MTM<:AbstractMatrix{T}, |
1868 | 1895 | MTC<:AbstractMatrix{T}, |
1869 | 1896 | MTK<:AbstractMatrix{T}} |
1870 | | - @assert checksquare(M) == checksquare(C) == checksquare(K) |
| 1897 | + if !(checksquare(M) == checksquare(C) == checksquare(K)) |
| 1898 | + throw(DimensionMismatch("incompatible dimensions")) |
| 1899 | + end |
1871 | 1900 | return new{T,MTM,MTC,MTK}(M, C, K) |
1872 | 1901 | end |
1873 | 1902 | end |
@@ -1947,7 +1976,7 @@ for (Z, AZ) in ((:SecondOrderAffineContinuousSystem, :AbstractContinuousSystem), |
1947 | 1976 | MTC<:AbstractMatrix{T}, |
1948 | 1977 | MTK<:AbstractMatrix{T}, |
1949 | 1978 | VT<:AbstractVector{T}} |
1950 | | - @assert checksquare(M) == checksquare(C) == checksquare(K) == length(b) |
| 1979 | + checksquare(M) == checksquare(C) == checksquare(K) == length(b) |
1951 | 1980 | return new{T,MTM,MTC,MTK,VT}(M, C, K, b) |
1952 | 1981 | end |
1953 | 1982 | end |
@@ -2037,7 +2066,9 @@ for (Z, AZ) in ((:SecondOrderConstrainedLinearControlContinuousSystem, :Abstract |
2037 | 2066 | MTB<:AbstractMatrix{T}, |
2038 | 2067 | ST, |
2039 | 2068 | UT} |
2040 | | - @assert checksquare(M) == checksquare(C) == checksquare(K) == size(B, 1) |
| 2069 | + if !(checksquare(M) == checksquare(C) == checksquare(K) == size(B, 1)) |
| 2070 | + throw(DimensionMismatch("incompatible dimensions")) |
| 2071 | + end |
2041 | 2072 | return new{T,MTM,MTC,MTK,MTB,ST,UT}(M, C, K, B, X, U) |
2042 | 2073 | end |
2043 | 2074 | end |
@@ -2135,8 +2166,9 @@ for (Z, AZ) in ((:SecondOrderConstrainedAffineControlContinuousSystem, :Abstract |
2135 | 2166 | VT<:AbstractVector{T}, |
2136 | 2167 | ST, |
2137 | 2168 | UT} |
2138 | | - @assert checksquare(M) == checksquare(C) == checksquare(K) == size(B, 1) == |
2139 | | - length(d) |
| 2169 | + if !(checksquare(M) == checksquare(C) == checksquare(K) == size(B, 1) == length(d)) |
| 2170 | + throw(DimensionMismatch("incompatible dimensions")) |
| 2171 | + end |
2140 | 2172 | return new{T,MTM,MTC,MTK,MTB,VT,ST,UT}(M, C, K, B, d, X, U) |
2141 | 2173 | end |
2142 | 2174 | end |
@@ -2226,7 +2258,9 @@ for (Z, AZ) in ((:SecondOrderContinuousSystem, :AbstractContinuousSystem), |
2226 | 2258 | fe::FE |
2227 | 2259 | function $(Z)(M::MTM, C::MTC, fi::FI, |
2228 | 2260 | fe::FE) where {T,MTM<:AbstractMatrix{T},MTC<:AbstractMatrix{T},FI,FE} |
2229 | | - @assert checksquare(M) == checksquare(C) |
| 2261 | + if checksquare(M) != checksquare(C) |
| 2262 | + throw(DimensionMismatch("incompatible dimensions")) |
| 2263 | + end |
2230 | 2264 | return new{T,MTM,MTC,FI,FE}(M, C, fi, fe) |
2231 | 2265 | end |
2232 | 2266 | end |
@@ -2309,7 +2343,9 @@ for (Z, AZ) in ((:SecondOrderConstrainedContinuousSystem, :AbstractContinuousSys |
2309 | 2343 |
|
2310 | 2344 | function $(Z)(M::MTM, C::MTC, fi::FI, fe::FE, X::ST, |
2311 | 2345 | U::UT) where {T,MTM<:AbstractMatrix{T},MTC<:AbstractMatrix{T},FI,FE,ST,UT} |
2312 | | - @assert checksquare(M) == checksquare(C) |
| 2346 | + if checksquare(M) != checksquare(C) |
| 2347 | + throw(DimensionMismatch("incompatible dimensions")) |
| 2348 | + end |
2313 | 2349 | return new{T,MTM,MTC,FI,FE,ST,UT}(M, C, fi, fe, X, U) |
2314 | 2350 | end |
2315 | 2351 | end |
|
0 commit comments