Exemplo n.º 1
0
 def test_scalar(self):
     """ Test for a single value i.e. n = 1.
     """
     m = helpers.randdiag(1)
     self.assertEqual(m.shape, (1, 1))
     self.assertGreaterEqual(m[0, 0], 0)
     self.assertLessEqual(m[0, 0], 1)
Exemplo n.º 2
0
 def test_matrix(self):
     """ Test for a matrix i.e. n > 1.
     """
     size = 100
     m = helpers.randdiag(size)
     self.assertEqual(m.shape, (size, size))
     for i in range(size):
         for j in range(size):
             if i == j:
                 self.assertGreaterEqual(m[i, j], 0)
                 self.assertLessEqual(m[i, j], 1)
             else:
                 self.assertEqual(m[i, j], 0)
Exemplo n.º 3
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)