Skip to content
This repository has been archived by the owner on Jun 21, 2024. It is now read-only.

Commit

Permalink
fix: BidiagonalizationMethod
Browse files Browse the repository at this point in the history
  • Loading branch information
tiankaima committed Jan 3, 2024
1 parent dfc9ec7 commit 8c4177e
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 11 deletions.
5 changes: 2 additions & 3 deletions lib/HouseholderMethod/Bidiagonalization.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,7 @@

Bidiagonalization_Result BidiagonalizationMethod(const Matrix &matrix) {
#ifdef DEBUG
// TODO: I'm limiting rows > cols + 1 for now, should have been rows >= cols
if (matrix.rows <= matrix.cols + 1) {
if (matrix.rows < matrix.cols) {
throw std::invalid_argument("BidiagonalizationMethod requires rows >= cols");
}
#endif
Expand Down Expand Up @@ -36,7 +35,7 @@ Bidiagonalization_Result BidiagonalizationMethod(const Matrix &matrix) {
auto Q = Matrix::identity(n);
auto Q_sub = Matrix::identity(n - k - 1) - product(v, v) * beta;
Q.set(k + 1, n, k + 1, n, Q_sub);
V = Q * V;
V = V * Q;

auto A_sub = B.sub_matrix(k, m, k + 1, n);
A_sub = A_sub - A_sub * product(v, v) * beta;
Expand Down
12 changes: 4 additions & 8 deletions main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,12 @@

// homework 8 (SVD):
int main() {
auto A = Matrix(8, 5, 1, 10);
A = BidiagonalizationMethod(A).B;
A.matrix[1][0] = 5;

A.print();

auto r = WilkinsonShiftIteration(A);
auto A = Matrix(8, 8, 1, 10);
auto r = BidiagonalizationMethod(A);

r.B.print();
(r.P * A * r.Q).print();

(r.U * A * r.V).print();

return 0;
}

0 comments on commit 8c4177e

Please sign in to comment.