Skip to content

Commit 2402749

Browse files
authored
Merge pull request #475 from QBatista/fix_error_lss
FIX: Raise correct error when `A` is not square in `LinearStateSpace`
2 parents 1e757ec + fc629de commit 2402749

File tree

2 files changed

+16
-5
lines changed

2 files changed

+16
-5
lines changed

quantecon/lss.py

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -110,16 +110,17 @@ def __init__(self, A, C, G, H=None, mu_0=None, Sigma_0=None):
110110
ni, nj = self.A.shape
111111
if ni != nj:
112112
raise ValueError(
113-
"Matrix A (shape: %s) needs to be square" % (self.A.shape))
113+
"Matrix A (shape: %s) needs to be square" % (self.A.shape, ))
114114
if ni != self.C.shape[0]:
115115
raise ValueError(
116-
"Matrix C (shape: %s) does not have compatible dimensions with A. "
117-
"It should be shape: %s" % (self.C.shape, (ni, 1)))
116+
"Matrix C (shape: %s) does not have compatible dimensions "
117+
"with A. It should be shape: %s" % (self.C.shape, (ni, 1)))
118118
self.m = self.C.shape[1]
119119
self.k, self.n = self.G.shape
120120
if self.n != ni:
121-
raise ValueError("Matrix G (shape: %s) does not have compatible dimensions with A (%s)"%(
122-
self.G.shape, self.A.shape))
121+
raise ValueError("Matrix G (shape: %s) does not have compatible"
122+
"dimensions with A (%s)" % (self.G.shape,
123+
self.A.shape))
123124
if H is None:
124125
self.H = None
125126
self.l = None

quantecon/tests/test_lss.py

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
import numpy as np
88
from numpy.testing import assert_allclose
99
from quantecon.lss import LinearStateSpace
10+
from nose.tools import raises
1011

1112

1213
class TestLinearStateSpace(unittest.TestCase):
@@ -65,6 +66,15 @@ def test_replicate_with_seed(self):
6566
assert_allclose(yval[0], expected_output)
6667

6768

69+
@raises(ValueError)
70+
def test_non_square_A():
71+
A = np.zeros((1, 2))
72+
C = np.zeros((1, 1))
73+
G = np.zeros((1, 1))
74+
75+
LinearStateSpace(A, C, G)
76+
77+
6878
if __name__ == '__main__':
6979
suite = unittest.TestLoader().loadTestsFromTestCase(TestLinearStateSpace)
7080
unittest.TextTestRunner(verbosity=2, stream=sys.stderr).run(suite)

0 commit comments

Comments
 (0)