Exemple #1
0
    def test_vectorize_unvectorize(self, tol):
        """Test vectorize and unvectorize utility function"""
        cutoff = 4

        dm = np.random.rand(*[cutoff] * 8) + 1j * np.random.rand(
            *[cutoff] * 8
        )  # 4^8 -> (4^2)^4 -> 4^8
        dm2 = np.random.rand(*[cutoff] * 4) + 1j * np.random.rand(
            *[cutoff] * 4
        )  # (2^2)^4 -> 2^8 -> (2^2)^4

        assert np.allclose(dm, utils._unvectorize(utils._vectorize(dm), 2), atol=tol, rtol=0)
        assert np.allclose(dm2, utils._vectorize(utils._unvectorize(dm2, 2)), atol=tol, rtol=0)
Exemple #2
0
    def test_vectorize_unvectorize(self):
        """Test vectorize utility function"""
        self.logTestName()

        cutoff = 4

        dm = np.random.rand(*[cutoff] * 8) + 1j * np.random.rand(
            *[cutoff] * 8)  # 4^8 -> (4^2)^4 -> 4^8
        dm2 = np.random.rand(*[cutoff] * 4) + 1j * np.random.rand(
            *[cutoff] * 4)  # (2^2)^4 -> 2^8 -> (2^2)^4
        self.assertAllAlmostEqual(dm,
                                  _unvectorize(_vectorize(dm), 2),
                                  delta=self.tol)
        self.assertAllAlmostEqual(dm2,
                                  _vectorize(_unvectorize(dm2, 2)),
                                  delta=self.tol)