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_adjust_cond(self):
     for M in self.Mlist:
         MU, MD, MV = hp.svd(M)
         M2 = hp.adjust_cond(MU, MD, MV, 20)
         self.assertAlmostEqual(np.linalg.cond(M2), 20)