Exemple #1
0
    def test_qr_with_padding(self, m_shape, b_shape):
        """Tests qr_blocked with padding"""
        np.set_printoptions(precision=2)
        np.random.seed(8)

        m2b_ds = random_array(m_shape, b_shape)

        (q, r) = qr(m2b_ds, mode='full')

        q = q.collect()
        r = r.collect()

        # check if Q matrix is orthogonal
        self.assertTrue(np.allclose(q.dot(q.T), np.identity(m_shape[0])))
        # check if R matrix is upper triangular
        self.assertTrue(np.allclose(np.triu(r), r))
        # check if the product Q * R is the original matrix
        self.assertTrue(np.allclose(q.dot(r), m2b_ds.collect()))

        (q, r) = qr(m2b_ds, mode="economic")

        q = q.collect()
        r = r.collect()
        m2b = m2b_ds.collect()

        # check if Q matrix is orthogonal
        self.assertTrue(np.allclose(q.T.dot(q), np.identity(m_shape[1])))
        # check if R matrix is upper triangular
        self.assertTrue(np.allclose(np.triu(r), r))
        # check if the product Q * R is the original matrix
        self.assertTrue(np.allclose(q.dot(r), m2b))
        # check the dimensions of Q
        self.assertTrue(q.shape == (m_shape[0], m_shape[1]))
        # check the dimensions of R
        self.assertTrue(r.shape == (m_shape[1], m_shape[1]))
Exemple #2
0
    def test_economic_overwrite(self):
        """Tests economic qr with overwrite = True"""
        np.set_printoptions(precision=2)
        np.random.seed(8)
        m_size = 25
        n_size = 10
        b_size = 5
        m2b_ds = random_array((m_size, n_size), (b_size, b_size))
        (q, r) = qr(m2b_ds, mode="economic", overwrite_a=True)

        q = q.collect()
        r = r.collect()
        m2b = m2b_ds.collect()

        # check if arrays original and r arrays are different
        # as it is not possible to overwrite the original matrix in the
        # economic mode
        self.assertFalse(np.array_equal(m2b, r))

        # check if Q matrix is orthogonal
        self.assertTrue(np.allclose(q.T.dot(q), np.identity(n_size)))
        # check if R matrix is upper triangular
        self.assertTrue(np.allclose(np.triu(r), r))
        # check if the product Q * R is the original matrix
        self.assertTrue(np.allclose(q.dot(r), m2b))
        # check the dimensions of Q
        self.assertTrue(q.shape == (m_size, n_size))
        # check the dimensions of R
        self.assertTrue(r.shape == (n_size, n_size))
Exemple #3
0
    def test_qr_r(self, m_size, n_size, b_size):
        """Tests qr_blocked r mode"""
        np.set_printoptions(precision=2)
        np.random.seed(8)

        shape = (m_size * b_size, n_size * b_size)
        m2b_ds = random_array(shape, (b_size, b_size))

        r = qr(m2b_ds, mode="r")
        _, r_full = qr(m2b_ds, mode="full")

        r = r.collect()
        r_full = r_full.collect()

        # check if R matrix is upper triangular
        self.assertTrue(np.allclose(np.triu(r), r))
        # check if R matrix is the same as when the full mode is applied
        self.assertTrue(np.allclose(r, r_full))
Exemple #4
0
    def test_exceptions(self):
        m2b_ds = random_array((100, 100), (10, 10))
        with self.assertRaises(ValueError):
            # unsupported mode
            qr(m2b_ds, mode="x")

        m2b_ds = random_array((50, 100), (10, 10))
        with self.assertRaises(ValueError):
            # m > n is required for matrices m x n
            qr(m2b_ds)

        m2b_ds = random_array((100, 100), (10, 5))
        with self.assertRaises(ValueError):
            # Square blocks are required
            qr(m2b_ds)

        m2b_ds = random_array((100, 100), (10, 10))
        m2b_ds = m2b_ds[:, 0:5]
        with self.assertRaises(ValueError):
            qr(m2b_ds)
Exemple #5
0
    def test_qr(self, m_size, n_size, b_size):
        """Tests qr_blocked full mode"""
        np.set_printoptions(precision=2)
        np.random.seed(8)

        shape = (m_size * b_size, n_size * b_size)
        m2b_ds = random_array(shape, (b_size, b_size))

        (q, r) = qr(m2b_ds)

        q = q.collect()
        r = r.collect()
        m2b = m2b_ds.collect()

        # check if Q matrix is orthogonal
        self.assertTrue(np.allclose(q.dot(q.T), np.identity(m_size * b_size)))
        # check if R matrix is upper triangular
        self.assertTrue(np.allclose(np.triu(r), r))
        # check if the product Q * R is the original matrix
        self.assertTrue(np.allclose(q.dot(r), m2b))