Skip to content
Merged
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
3 changes: 1 addition & 2 deletions slycot/tests/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,12 +1,11 @@
set(PYSOURCE

__init__.py
test.py
test_ab08n.py
test_ag08bd.py
test_mb.py
test_mc.py
test_sb10jd.py
test_sb.py
test_sg02ad.py
test_sg03ad.py
test_tb05ad.py
Expand Down
48 changes: 0 additions & 48 deletions slycot/tests/test.py

This file was deleted.

34 changes: 19 additions & 15 deletions slycot/tests/test_ag08bd.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
from slycot import analysis
import numpy as np

from numpy.testing import assert_raises, assert_almost_equal, assert_equal
from numpy.testing import assert_almost_equal, assert_equal

# test1 input parameters

Expand All @@ -27,7 +27,7 @@
[0, 0, 0, 0, 0, 0, 0, 0, 0],
[0, 0, 0, 0, 0, 0, 1, 0, 0],
[0, 0, 0, 0, 0, 0, 0, 1, 0]])

test1_B = np.array([[-1, 0, 0],
[ 0, 0, 0],
[ 0, 0, 0],
Expand All @@ -46,13 +46,17 @@
[ 0, -1, -2],
[ 0, 0, 0]])


class test_tg01fd(unittest.TestCase):
""" test1 to 4: Verify ag08bd with input parameters according to example in documentation """
""" Verify ag08bd with input parameters according to example in documentation """

def test1_ag08bd(self):
#test [A-lambda*E]
#B,C,D must have correct dimensions according to l,n,m and p, but cannot have zero length in any dimenstion. Then the wrapper will complain. The length is then set to one.
"""test [A-lambda*E]

B,C,D must have correct dimensions according to l,n,m and p, but cannot
have zero length in any dimenstion. Then the wrapper will complain.
The length is then set to one.
"""

Af,Ef,nrank,niz,infz,kronr,infe,kronl = analysis.ag08bd(l=test1_l,n=test1_n,m=0,p=0,A=test1_A,E=test1_E,B=np.zeros((test1_l,1)),C=np.zeros((1,test1_n)),D=np.zeros((1,1)),equil=test1_equil, tol=test1_tol)

Expand All @@ -66,8 +70,10 @@ def test1_ag08bd(self):
assert_equal(kronl, [])

def test2_ag08bd(self):
#test [A-lambda*E;C]
#B,D must have correct dimensions as before
"""test [A-lambda*E;C]

B,D must have correct dimensions as before
"""

Af,Ef,nrank,niz,infz,kronr,infe,kronl = analysis.ag08bd(l=test1_l,n=test1_n,m=0,p=test1_p,A=test1_A,E=test1_E,B=np.zeros((test1_l,1)),C=test1_C,D=np.zeros((test1_p,1)),equil=test1_equil, tol=test1_tol)

Expand All @@ -81,8 +87,10 @@ def test2_ag08bd(self):
assert_equal(kronl, [0,1,1])

def test3_ag08bd(self):
#test [A-lambda*E,B]
#C,D must have correct dimensions as before
"""test [A-lambda*E,B]

C,D must have correct dimensions as before
"""

Af,Ef,nrank,niz,infz,kronr,infe,kronl = analysis.ag08bd(l=test1_l,n=test1_n,m=test1_m,p=0,A=test1_A,E=test1_E,B=test1_B,C=np.zeros((1,test1_n)),D=np.zeros((1,test1_m)),equil=test1_equil, tol=test1_tol)

Expand All @@ -96,7 +104,7 @@ def test3_ag08bd(self):
assert_equal(kronl, [])

def test4_ag08bd(self):
#test [A-lambda*E,B;C,D]
"""test [A-lambda*E,B;C,D]"""

Af,Ef,nrank,niz,infz,kronr,infe,kronl = analysis.ag08bd(l=test1_l,n=test1_n,m=test1_m,p=test1_p,A=test1_A,E=test1_E,B=test1_B,C=test1_C,D=test1_D,equil=test1_equil, tol=test1_tol)

Expand All @@ -108,10 +116,6 @@ def test4_ag08bd(self):
assert_equal(kronr, [2])
assert_equal(infe, [1,1,1,1,3])
assert_equal(kronl, [1])


def suite():
return unittest.TestLoader().loadTestsFromTestCase(TestConvert)


if __name__ == "__main__":
Expand Down
1 change: 1 addition & 0 deletions slycot/tests/test_mb.py
Original file line number Diff line number Diff line change
Expand Up @@ -154,6 +154,7 @@ def test_mb03wd_ex(self):

def test_mb05md(self):
""" test_mb05md: verify Matrix exponential with slicot doc example

data from http://slicot.org/objects/software/shared/doc/MB05MD.html
"""
A = np.array([[ 0.5, 0., 2.3, -2.6],
Expand Down
99 changes: 99 additions & 0 deletions slycot/tests/test_sb.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,99 @@
# ===================================================
# sb* synthesis tests

from slycot import synthesis
from numpy import array, eye, zeros
from numpy.testing import assert_allclose


def test_sb02mt():
"""Test if sb02mt is callable

This is a dummy test, not really checking the wrapper of the FORTRAN
function
"""
out = synthesis.sb02mt(1, 1, 1., 1.)
assert(len(out) == 8)


def test_sb10ad():
"""Test sb10ad, Hinf synthesis"""
a = array([[-1]])
b = array([[1, 1]])
c = array([[1],
[1]])
d = array([[0, 1],
[1, 0]])

n = 1
m = 2
np = 2
ncon = 1
nmeas = 1
gamma = 10

gamma_est, Ak, Bk, Ck, Dk, Ac, Bc, Cc, Dc, rcond = synthesis.sb10ad(
n, m, np, ncon, nmeas, gamma, a, b, c, d)
# from Octave, which also uses SB10AD:
# a= -1; b1= 1; b2= 1; c1= 1; c2= 1; d11= 0; d12= 1; d21= 1; d22= 0;
# g = ss(a,[b1,b2],[c1;c2],[d11,d12;d21,d22]);
# [k,cl] = hinfsyn(g,1,1);
# k.a is Ak, cl.a is Ac
# gamma values don't match; not sure that's critical
# this is a bit fragile
# a simpler, more robust check might be to check stability of Ac
assert_allclose(Ak, array([[-3.]]))
assert_allclose(Ac, array([[-1., -1.],
[1., -3.]]))


def test_sb10jd():
""" verify the output of sb10jd for a descriptor system """

# test1 input parameters
n = 6
m = 1
np = 6

A = array([[ 0, 0, 0, -1, 1, 0],
[ 0, 32, 0, 0, -1, 1],
[ 0, 0, 1, 0, 0, 0],
[ 0, 0, 0, 1, 0, 0],
[-1, 1, 0, 0, 0, 0],
[ 0, -1, 1, 0, 0, 0]])
E = array([[ 0, 0, 0, 0, 0, 0],
[ 0, 0, 0, 0, 0, 0],
[ 0, 0, 0, -10, 0, 10],
[ 0, 0, 0, 0, 0, 0],
[ 0, 0, 0, 0, 0, 0],
[ 0, 0, 0, 0, 0, 0]])
B = array([[-7.1],
[ 0. ],
[ 0. ],
[ 0. ],
[ 0. ],
[ 0. ]])
C = eye(6)
D = zeros((7, 1))

# test1 expected results
Aexp = array([[-0.003125]])
Bexp = array([[ 0.059000]])
Cexp = array([[-1.17519e-02],
[-1.17519e-02],
[-1.17519e-02],
[ 0. ],
[ 0. ],
[ 3.76060e-01]])
Dexp = array([[ 2.21875e-01],
[ 2.21875e-01],
[ 2.21875e-01],
[ 0. ],
[ 7.100000+00],
[ 0. ]])

A_r, B_r, C_r, D_r = synthesis.sb10jd(n, m, np, A, B, C, D, E)
assert_allclose(A_r, Aexp, atol=1e-5)
assert_allclose(B_r, Bexp, atol=1e-5)
assert_allclose(C_r, Cexp, atol=1e-5)
assert_allclose(D_r, Dexp, atol=1e-5)
72 changes: 0 additions & 72 deletions slycot/tests/test_sb10jd.py

This file was deleted.

29 changes: 14 additions & 15 deletions slycot/tests/test_sg02ad.py
100644 → 100755
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
#!/usr/bin/env python
#
# test_sg02ad.py - test suite for ricatti equation solving
# RvP, 19 Jun 2017
Expand All @@ -7,21 +6,23 @@
import unittest
from slycot import synthesis
import numpy as np
from numpy import linalg

from numpy.testing import assert_raises, assert_almost_equal
from numpy.testing import assert_almost_equal


class test_sg02ad(unittest.TestCase):

class test_sg03ad(unittest.TestCase):

def test_sg02ad_case1(self):
n = 3
m = 1
# from a discussion here:
# https://github.com/scipy/scipy/issues/2251
A = np.array([[ 0.63399379, 0.54906824, 0.76253406],
[ 0.5404729 , 0.53745766, 0.08731853],
[ 0.27524045, 0.84922129, 0.4681622 ]])
B = np.array([[ 0.96861695],[ 0.05532739],[ 0.78934047]])
[ 0.5404729 , 0.53745766, 0.08731853],
[ 0.27524045, 0.84922129, 0.4681622 ]])
B = np.array([[ 0.96861695],
[ 0.05532739],
[ 0.78934047]])
Q = np.eye(3)
E = np.eye(3)
R = np.ones((1,1), dtype=float)
Expand All @@ -33,14 +34,12 @@ def test_sg02ad_case1(self):
synthesis.sg02ad('D', 'B', 'N', 'U', 'Z', 'N', 'S', 'R',
n, m, 1,
A, E, B, Q, R, L)
LATXB = L + A.T.dot(X).dot(B)
assert_almost_equal(
A.T.dot(X).dot(A) - E.T.dot(X).dot(E) -
(L + A.T.dot(X).dot(B)) .dot( np.linalg.solve (R+B.T.dot(X).dot(B), (L+A.T.dot(X).dot(B)).T) ) +
Q,
np.zeros((n,n)))

def suite():
return unittest.TestLoader().loadTestsFromTestCase(TestConvert)
A.T.dot(X).dot(A) -
E.T.dot(X).dot(E) -
LATXB.dot(np.linalg.solve(R+B.T.dot(X).dot(B), LATXB.T)) + Q,
np.zeros((n, n)))


if __name__ == "__main__":
Expand Down
Loading