Repository: scipy/scipy
File: scipy/signal/tests/test_cont2discrete.py (Python)

Code before:

        tf1 = (tf[0][0], tf[1])
        num1, den1, dt1 = c2d(tf1, ts)

        tf2 = (tf[0][1], tf[1])
        num2, den2, dt2 = c2d(tf2, ts)

        # Sanity checks
        assert dt == dt1
        assert dt == dt2

        # Check that we get the same results
        xp_assert_close(num, np.vstack((num1, num2)), rtol=1e-13)

        # Single input, so the denominator should
        # not be multidimensional like the numerator
        xp_assert_close(den, den1, rtol=1e-13)
        xp_assert_close(den, den2, rtol=1e-13)

@skip_xp_backends(np_only=True, reason="lti currently not supported")
class TestC2dLti:
    def test_c2d_ss(self, xp):
        # StateSpace
        A = np.array([[-0.3, 0.1], [0.2, -0.7]])
        B = np.array([[0.], [1.]])
        C = np.array([[1., 0.]])
        D = 0
        dt = 0.05

        A_res = np.array([[0.985136404135682, 0.004876671474795],
                          [0.009753342949590, 0.965629718236502]])
        B_res = np.array([[0.000122937599964], [0.049135527547844]])

        sys_ssc = lti(A, B, C, D)
        sys_ssd = sys_ssc.to_discrete(dt=dt)

        xp_assert_close(sys_ssd.A, A_res)
        xp_assert_close(sys_ssd.B, B_res)
        xp_assert_close(sys_ssd.C, C)
        xp_assert_close(sys_ssd.D, np.zeros_like(sys_ssd.D))

        sys_ssd2 = c2d(sys_ssc, dt=dt)

        xp_assert_close(sys_ssd2.A, A_res)
        xp_assert_close(sys_ssd2.B, B_res)
        xp_assert_close(sys_ssd2.C, C)
        xp_assert_close(sys_ssd2.D, np.zeros_like(sys_ssd2.D))

    def test_c2d_tf(self, xp):

        sys = lti([0.5, 0.3], [1.0, 0.4])

Review comment (suggestion):
Do I understand it right that the code change is backwards compatible: if `A` was integer, after `abcd_normalize` it will become float64? If so, the test does not need changing. 

Code after:

        tf1 = (tf[0][0], tf[1])
        num1, den1, dt1 = c2d(tf1, ts)

        tf2 = (tf[0][1], tf[1])
        num2, den2, dt2 = c2d(tf2, ts)

        # Sanity checks
        assert dt == dt1
        assert dt == dt2

        # Check that we get the same results
        xp_assert_close(num, np.vstack((num1, num2)), rtol=1e-13)

        # Single input, so the denominator should
        # not be multidimensional like the numerator
        xp_assert_close(den, den1, rtol=1e-13)
        xp_assert_close(den, den2, rtol=1e-13)

@skip_xp_backends(np_only=True, reason="lti currently not supported")
class TestC2dLti:
    def test_c2d_ss(self, xp):
        # StateSpace
        A = np.array([[-0.3, 0.1], [0.2, -0.7]])
        B = np.array([[0], [1]])
        C = np.array([[1, 0]])
        D = 0
        dt = 0.05

        A_res = np.array([[0.985136404135682, 0.004876671474795],
                          [0.009753342949590, 0.965629718236502]])
        B_res = np.array([[0.000122937599964], [0.049135527547844]])
        # Resulting A, B, C, D are arrays of the same dtype due to abcd_normalize() use:
        C_res = np.astype(C, A_res.dtype)

        sys_ssc = lti(A, B, C, D)
        sys_ssd = sys_ssc.to_discrete(dt=dt)

        xp_assert_close(sys_ssd.A, A_res)
        xp_assert_close(sys_ssd.B, B_res)
        xp_assert_close(sys_ssd.C, C_res)
        xp_assert_close(sys_ssd.D, np.zeros_like(sys_ssd.D))

        sys_ssd2 = c2d(sys_ssc, dt=dt)

        xp_assert_close(sys_ssd2.A, A_res)
        xp_assert_close(sys_ssd2.B, B_res)
        xp_assert_close(sys_ssd2.C, C_res)
        xp_assert_close(sys_ssd2.D, np.zeros_like(sys_ssd.D))

    def test_c2d_tf(self, xp):