def setUp(self):
        """Set up a MIMO system to test operations on."""
        use_numpy_matrix(False)

        # sys1: 3-states square system (2 inputs x 2 outputs)
        A322 = [[-3., 4., 2.], [-1., -3., 0.], [2., 5., 3.]]
        B322 = [[1., 4.], [-3., -3.], [-2., 1.]]
        C322 = [[4., 2., -3.], [1., 4., 3.]]
        D322 = [[-2., 4.], [0., 1.]]
        self.sys322 = StateSpace(A322, B322, C322, D322)

        # sys1: 2-states square system (2 inputs x 2 outputs)
        A222 = [[4., 1.], [2., -3]]
        B222 = [[5., 2.], [-3., -3.]]
        C222 = [[2., -4], [0., 1.]]
        D222 = [[3., 2.], [1., -1.]]
        self.sys222 = StateSpace(A222, B222, C222, D222)

        # sys3: 6 states non square system (2 inputs x 3 outputs)
        A623 = np.array([[1, 0, 0, 0, 0, 0], [0, 1, 0, 0, 0, 0],
                         [0, 0, 3, 0, 0, 0], [0, 0, 0, -4, 0, 0],
                         [0, 0, 0, 0, -1, 0], [0, 0, 0, 0, 0, 3]])
        B623 = np.array([[0, -1], [-1, 0], [1, -1], [0, 0], [0, 1], [-1, -1]])
        C623 = np.array([[1, 0, 0, 1, 0, 0], [0, 1, 0, 1, 0, 1],
                         [0, 0, 1, 0, 0, 1]])
        D623 = np.zeros((3, 2))
        self.sys623 = StateSpace(A623, B623, C623, D623)
    def setUp(self):
        use_numpy_matrix(False)

        # Number of times to run each of the randomized tests.
        self.numTests = 100
        # Maximum number of states to test + 1
        self.maxStates = 10
        # Maximum number of inputs and outputs to test + 1
        self.maxIO = 5
    def setUp(self):
        # Use array instead of matrix (and save old value to restore at end)
        use_numpy_matrix(False)

        # Maximum number of states to test + 1
        self.maxStates = 5
        # Maximum number of inputs and outputs to test + 1
        self.maxTries = 4
        # Set to True to print systems to the output.
        self.debug = False
        # get consistent test results
        np.random.seed(0)
    def test_obsv_siso_deprecated(self):
        A = np.array([[1., 2.], [3., 4.]])
        C = np.array([[5., 7.]])

        # Check that default type generates a warning
        # TODO: remove this check with matrix type is deprecated
        with warnings.catch_warnings(record=True) as w:
            use_numpy_matrix(True, warn=False) # warnings off
            self.assertEqual(len(w), 0)
            
            Wo = obsv(A, C)
            self.assertTrue(isinstance(Wo, np.matrix))
            use_numpy_matrix(False)
 def test_ctrb_siso_deprecated(self):
     A = np.array([[1., 2.], [3., 4.]])
     B = np.array([[5.], [7.]])
     
     # Check that default using np.matrix generates a warning
     # TODO: remove this check with matrix type is deprecated
     warnings.resetwarnings()
     with warnings.catch_warnings(record=True) as w:
         use_numpy_matrix(True)
         self.assertTrue(issubclass(w[-1].category, UserWarning))
         
         Wc = ctrb(A, B)
         self.assertTrue(isinstance(Wc, np.matrix))
         self.assertTrue(issubclass(w[-1].category,
                                    PendingDeprecationWarning))
         use_numpy_matrix(False)
    def test_gram_wc_deprecated(self):
        A = np.array([[1., -2.], [3., -4.]])
        B = np.array([[5., 6.], [7., 8.]])
        C = np.array([[4., 5.], [6., 7.]])
        D = np.array([[13., 14.], [15., 16.]])
        sys = ss(A, B, C, D)

        # Check that default type generates a warning
        # TODO: remove this check with matrix type is deprecated
        with warnings.catch_warnings(record=True) as w:
            use_numpy_matrix(True)
            self.assertTrue(issubclass(w[-1].category, UserWarning))
            
            Wc = gram(sys, 'c')
            self.assertTrue(isinstance(Wc, np.ndarray))
            use_numpy_matrix(False)