Exemplo n.º 1
0
    def test(self):
        """ Test for matrixes of which size are 2 to 100.

        This method checks;

          1. minimum diagonal value of PD is not changed,
          2. all diagonal values are different,
          3. condition number of output PD is same as the desired value.
        """
        for size in range(2, 101):
            PU = PV = np.identity(size)
            while True:
                PD = helpers.randdiag(size)
                if helpers.mindiag(PD) != helpers.maxdiag(PD):
                    break
            cond = 73

            res = helpers.adjust_cond(PU, PD, PV, cond)
            self.assertAlmostEqual(helpers.mindiag(res), helpers.mindiag(PD))
            self.assertNotEqual(helpers.mindiag(res), helpers.maxdiag(res))
            self.assertAlmostEqual(numpy.linalg.cond(res), cond)
Exemplo n.º 2
0
    def test_mat_funcs(self):

        for P in self.Plist:
            PU, PD, PV = hp.schur(P)
            # ensure that PD is a diagonal matrix
            self.assertTrue(np.array_equal(PD, np.diag(np.diag(PD))), repr(PD))
            # raise Exception(PU*PD*PV, np.dot(PU, np.dot(PD, PV)))
            self.assertTrue(np.allclose(PU * PD * PV, np.dot(PU, np.dot(PD, PV))))

        for P in self.Plist:
            self.assertEqual(hp.mindiag(P), min(
                P[i, i] for i in range(min(P.shape))))
            self.assertEqual(hp.maxdiag(P), max(
                P[i, i] for i in range(min(P.shape))))
Exemplo n.º 3
0
    def test_non_convex(self):
        """ Test for non convex cases.
        """
        for size in range(2, 101):
            cond = random.randint(1, 100)

            numpy.random.seed(cond)
            res = helpers.gen_general_obj(size, False, cond, 1)

            self.assertEqual(res.shape, (size, size))
            if size > 50:
                self.assertLess(helpers.mindiag(res), 0)
            self.assertAlmostEqual(numpy.linalg.cond(res), cond)

            numpy.random.seed(cond)
            half = helpers.gen_general_obj(size, False, cond, 0.5)
            self.assertTrue(np.allclose(res, half * 2))
Exemplo n.º 4
0
 def test_min_max_diag(self):
     for M in self.Mlist:
         self.assertEqual(hp.mindiag(M), min(
             M[i, i] for i in range(min(M.shape))))
         self.assertEqual(hp.maxdiag(M), max(
             M[i, i] for i in range(min(M.shape))))
Exemplo n.º 5
0
 def test(self):
     """ Test with a simple input.
     """
     m = helpers.rand(100, 100)
     ans = m.diagonal().min()
     self.assertEqual(helpers.mindiag(m), ans)