Esempio n. 1
0
    def householder_test(self):
        """Test the householder transformation to get a matrix in bidiagonalization."""
        # set up test
        c = [
                [4, 3, 0],
                [2, 1, 2],
                [4, 4, 0]
        ]
        matrix = Matrix(3, 3)
        matrix.initialize(c, rowBased=True)

        # execute householder transformation
        u, bidiag, v = matrix.householder()

        # expect, that multiplication works correctly.
        res = u * bidiag * v
        # res should be equal with c (except some rounding errors)
        for row in range(res.get_height()):
            for col in range(res.get_width()):
                self.assertAlmostEqual(res.get_value(col, row), c[row][col], PRECISION)
        # bidiag matrix should have 0 values below the diagonal
        self.assertAlmostEqual(bidiag.get_value(0, 1), 0, PRECISION)
        self.assertAlmostEqual(bidiag.get_value(0, 2), 0, PRECISION)
        self.assertAlmostEqual(bidiag.get_value(1, 2), 0, PRECISION)

        self.assertAlmostEqual(bidiag.get_value(2, 0), 0, PRECISION)
Esempio n. 2
0
    def householder_with_zero_column_test(self):
        """Test the householder transformation of a Matrix with a 0 column

        All values of the 2nd column are 0."""
        # set up test
        c = [[3, 0, 3, 2], [0, 0, 5, 6], [4, 0, 4, 7], [8, 0, 3, 9]]
        matrix = Matrix(4, 4)
        matrix.initialize(c, rowBased=True)

        # execute householder transformation
        u, bidiag, v = matrix.householder()

        # expect, that multiplication works correctly.
        res = u * bidiag * v
        # res should be equal with c (except some rounding errors)
        for row in range(res.get_height()):
            for col in range(res.get_width()):
                self.assertAlmostEqual(res.get_value(col, row), c[row][col],
                                       PRECISION)
Esempio n. 3
0
    def householder_with_zero_column_test(self):
        """Test the householder transformation of a Matrix with a 0 column

        All values of the 2nd column are 0."""
        # set up test
        c = [
                [3, 0, 3, 2],
                [0, 0, 5, 6],
                [4, 0, 4, 7],
                [8, 0, 3, 9]
            ]
        matrix = Matrix(4, 4)
        matrix.initialize(c, rowBased=True)

        # execute householder transformation
        u, bidiag, v = matrix.householder()

        # expect, that multiplication works correctly.
        res = u * bidiag * v
        # res should be equal with c (except some rounding errors)
        for row in range(res.get_height()):
            for col in range(res.get_width()):
                self.assertAlmostEqual(res.get_value(col, row), c[row][col], PRECISION)
Esempio n. 4
0
    def householder_test(self):
        """Test the householder transformation to get a matrix in bidiagonalization."""
        # set up test
        c = [[4, 3, 0], [2, 1, 2], [4, 4, 0]]
        matrix = Matrix(3, 3)
        matrix.initialize(c, rowBased=True)

        # execute householder transformation
        u, bidiag, v = matrix.householder()

        # expect, that multiplication works correctly.
        res = u * bidiag * v
        # res should be equal with c (except some rounding errors)
        for row in range(res.get_height()):
            for col in range(res.get_width()):
                self.assertAlmostEqual(res.get_value(col, row), c[row][col],
                                       PRECISION)
        # bidiag matrix should have 0 values below the diagonal
        self.assertAlmostEqual(bidiag.get_value(0, 1), 0, PRECISION)
        self.assertAlmostEqual(bidiag.get_value(0, 2), 0, PRECISION)
        self.assertAlmostEqual(bidiag.get_value(1, 2), 0, PRECISION)

        self.assertAlmostEqual(bidiag.get_value(2, 0), 0, PRECISION)