Skip to content

Commit

Permalink
QB fixed
Browse files Browse the repository at this point in the history
  • Loading branch information
TeachRaccooon committed Apr 26, 2024
1 parent 3382c24 commit 700cccd
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 27 deletions.
28 changes: 9 additions & 19 deletions RandLAPACK/comps/rl_qb.hh
Original file line number Diff line number Diff line change
Expand Up @@ -161,8 +161,9 @@ int QB<T, RNG>::call(
// Allocate buffers
T* QtQi = ( T * ) calloc( b_sz * b_sz, sizeof( T ) );
T* A_cpy = ( T * ) calloc( m * n, sizeof( T ) );
T* Q_i = ( T * ) calloc( m * b_sz, sizeof( T ) );
T* BT_i = ( T * ) calloc( b_sz * n, sizeof( T ) );
// Declate pointers to the iteration buffers.
T* Q_i;
T* BT_i;

// pre-compute nrom
T norm_A = lapack::lange(Norm::Fro, m, n, A, m);
Expand All @@ -179,18 +180,21 @@ int QB<T, RNG>::call(
// Allocate more space in Q, B, QtQi buffer if needed.
if (curr_sz != 0) {
Q = ( T * ) realloc(Q, next_sz * m * sizeof( T ));
BT = ( T * ) realloc(BT, next_sz * n * sizeof( T ));
BT = ( T * ) realloc(BT, next_sz * n * sizeof( T ));
QtQi = ( T * ) realloc(QtQi, next_sz * b_sz * sizeof( T ));
}

// Avoid extra buffer allocation, but be careful about pointing to the
// correct location.
Q_i = &Q[m * curr_sz];
BT_i = &BT[n * curr_sz];

// Calling RangeFinder
if(this->RF_Obj.call(m, n, A_cpy, b_sz, Q_i, state)) {
// RF failed
k = curr_sz;
free(A_cpy);
free(QtQi);
free(Q_i);
free(BT_i);
return 6;
}

Expand All @@ -200,8 +204,6 @@ int QB<T, RNG>::call(
k = curr_sz;
free(A_cpy);
free(QtQi);
free(Q_i);
free(BT_i);
return 4;
}
}
Expand Down Expand Up @@ -230,23 +232,15 @@ int QB<T, RNG>::call(
k = curr_sz;
free(A_cpy);
free(QtQi);
free(Q_i);
free(BT_i);
return 2;
}

// Update the matrices Q and B
lapack::lacpy(MatrixType::General, m, b_sz, Q_i, m, &Q[m * curr_sz], m);
lapack::lacpy(MatrixType::General, n, b_sz, BT_i, n, &BT[n * curr_sz], n);

if(this->orth_check) {
if (util::orthogonality_check(m, next_sz, next_sz, Q, this->verbosity)) {
// Lost orthonormality of Q
k = curr_sz;
free(A_cpy);
free(QtQi);
free(Q_i);
free(BT_i);
return 5;
}
}
Expand All @@ -260,8 +254,6 @@ int QB<T, RNG>::call(
k = curr_sz;
free(A_cpy);
free(QtQi);
free(Q_i);
free(BT_i);
return 0;
}

Expand All @@ -272,8 +264,6 @@ int QB<T, RNG>::call(

free(A_cpy);
free(QtQi);
free(Q_i);
free(BT_i);

// Reached expected rank without achieving the tolerance
return 3;
Expand Down
8 changes: 0 additions & 8 deletions test/comps/test_qb.cc
Original file line number Diff line number Diff line change
Expand Up @@ -230,14 +230,6 @@ class TestQB : public ::testing::Test
EXPECT_TRUE(norm_test_1 <= (tol * norm_A));
}
}

void rand_fun(int* &ptr)
{
ptr = (int*) realloc(ptr, 3 * sizeof(int));
ptr[0] = 1;
ptr[2] = 2;
ptr[3] = 3;
}
};

TEST_F(TestQB, Polynomial_Decay_general1)
Expand Down

0 comments on commit 700cccd

Please sign in to comment.