def test_create_from_rows(self): matrix = Matrix.from_rows([[1, 2], [3, 4], [5, 6]]) assert matrix.size() == (3, 2) assert matrix.get_row(0) == [1, 2] assert matrix.get_row(1) == [3, 4] assert matrix.get_row(2) == [5, 6] assert matrix.get_col(0) == [1, 3, 5] assert matrix.get_col(1) == [2, 4, 6]
def test_householder_row(self): vec = [5, 4, 3, 2, 1] householder = Householder(vec) row_matrix = Matrix.from_rows([vec]) product = householder.multiply_right(row_matrix) assert product.num_rows() == 1 assert product.get(0, 0) == pytest.approx(row_matrix.frobenius_norm()) for elem in product.get_row(0)[1:]: assert elem == pytest.approx(0)
def test_create_fail(self): with pytest.raises(ValueError): Matrix.from_cols([[1, 2], [3], [5, 6]]) with pytest.raises(ValueError): Matrix.from_rows([[1, 2], [3, 4], [6]])