Skip to content

Commit

Permalink
style
Browse files Browse the repository at this point in the history
  • Loading branch information
dylan-copeland committed May 18, 2024
1 parent 52878f9 commit 3dd2758
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 35 deletions.
6 changes: 3 additions & 3 deletions lib/linalg/Matrix.h
Original file line number Diff line number Diff line change
Expand Up @@ -918,15 +918,15 @@ class Matrix
*
* @return The Q of the QR factorization of this.
*/
std::unique_ptr<Matrix>
std::unique_ptr<Matrix>
qr_factorize() const;

/**
* @brief Computes and returns the Q and R factors of the QR factorization.
*
* @return The Q and R of the QR factorization of this.
*/
void qr_factorize(std::vector<std::unique_ptr<Matrix>> & QR) const;
void qr_factorize(std::vector<std::unique_ptr<Matrix>> & QR) const;

/**
* @brief Compute the leading numColumns() column pivots from a
Expand Down Expand Up @@ -1259,7 +1259,7 @@ class Matrix
* @return The Q and R of the QR factorization of this. If computeR is
* false, the R pointer will be nullptr.
*/
void qr_factorize(bool computeR, std::vector<Matrix*> & QR) const;
void qr_factorize(bool computeR, std::vector<Matrix*> & QR) const;

/**
* @brief The storage for the Matrix's values on this processor.
Expand Down
8 changes: 4 additions & 4 deletions unit_tests/test_HDFDatabase.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -820,7 +820,7 @@ TEST(BasisGeneratorIO, Scaling_test)
auto stop = steady_clock::now();
auto duration = duration_cast<milliseconds>(stop-start);
if (rank == 0)
printf("Base writeSnapshot- duration: %dms\n", duration.count());
printf("Base writeSnapshot- duration: %dms\n", duration.count());

MPI_Barrier(MPI_COMM_WORLD);
start = steady_clock::now();
Expand All @@ -829,7 +829,7 @@ TEST(BasisGeneratorIO, Scaling_test)
stop = steady_clock::now();
duration = duration_cast<milliseconds>(stop-start);
if (rank == 0)
printf("MPIO writeSnapshot- duration: %dms\n", duration.count());
printf("MPIO writeSnapshot- duration: %dms\n", duration.count());

MPI_Barrier(MPI_COMM_WORLD);
start = steady_clock::now();
Expand All @@ -838,7 +838,7 @@ TEST(BasisGeneratorIO, Scaling_test)
stop = steady_clock::now();
duration = duration_cast<milliseconds>(stop-start);
if (rank == 0)
printf("Base endSamples- duration: %dms\n", duration.count());
printf("Base endSamples- duration: %dms\n", duration.count());

MPI_Barrier(MPI_COMM_WORLD);
start = steady_clock::now();
Expand All @@ -847,7 +847,7 @@ TEST(BasisGeneratorIO, Scaling_test)
stop = steady_clock::now();
duration = duration_cast<milliseconds>(stop-start);
if (rank == 0)
printf("MPIO endSamples- duration: %dms\n", duration.count());
printf("MPIO endSamples- duration: %dms\n", duration.count());
}

int main(int argc, char* argv[])
Expand Down
56 changes: 28 additions & 28 deletions unit_tests/test_QR.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ TEST(QRfactorizeTest, Test_QR)
EXPECT_EQ(total_rows, num_total_rows);

double* q_data = new double[15] {
3.08158946098238906153E-01, -9.49897947980619661301E-02, -4.50691774108525788911E-01,
3.08158946098238906153E-01, -9.49897947980619661301E-02, -4.50691774108525788911E-01,
-1.43697905723455976457E-01, 9.53289043424090820622E-01, 8.77767692937209131898E-02,
-2.23655845793717528158E-02, -2.10628953513210204207E-01, 8.42235962392685943989E-01,
-7.29903965154318323805E-01, -1.90917141788945754488E-01, -2.77280930877637610266E-01,
Expand All @@ -59,41 +59,41 @@ TEST(QRfactorizeTest, Test_QR)

double* r_data = new double[9] {
-1.78651649346571794741E-01, 5.44387957786310106023E-01, -8.19588518467042281834E-01,
0.0, -3.13100149275943651084E-01, -9.50441422536040881122E-04,
0.0, 0.0, 5.72951792961765460355E-01
0.0, -3.13100149275943651084E-01, -9.50441422536040881122E-04,
0.0, 0.0, 5.72951792961765460355E-01
};

CAROM::Matrix exactQ(loc_num_rows, num_columns, true);
CAROM::Matrix exactR(r_data, num_columns, num_columns, false);

for (int i = 0; i < loc_num_rows; i++) {
for (int j = 0; j < num_columns; j++) {
exactQ(i, j) = q_data[((i + row_offset[rank]) * num_columns) + j];
}
for (int j = 0; j < num_columns; j++) {
exactQ(i, j) = q_data[((i + row_offset[rank]) * num_columns) + j];
}
}

EXPECT_EQ(exactQ.numRows(), loc_num_rows);
EXPECT_EQ(exactQ.numColumns(), num_columns);

// Verify that the columns of Q are orthonormal.
{
CAROM::Matrix *id = exactQ.transposeMult(exactQ);
CAROM::Matrix *id = exactQ.transposeMult(exactQ);

EXPECT_EQ(id->numRows(), num_columns);
EXPECT_EQ(id->numColumns(), num_columns);
EXPECT_EQ(id->numRows(), num_columns);
EXPECT_EQ(id->numColumns(), num_columns);

double maxError = 0.0;
for (int i = 0; i < num_columns; i++) {
for (int j = 0; j < num_columns; j++) {
const double delta_ij = i == j ? 1.0 : 0.0;
const double error = std::abs((*id)(i,j) - delta_ij);
maxError = std::max(maxError, error);
}
}
double maxError = 0.0;
for (int i = 0; i < num_columns; i++) {
for (int j = 0; j < num_columns; j++) {
const double delta_ij = i == j ? 1.0 : 0.0;
const double error = std::abs((*id)(i,j) - delta_ij);
maxError = std::max(maxError, error);
}
}

EXPECT_NEAR(maxError, 0.0, 1.0e-15);
EXPECT_NEAR(maxError, 0.0, 1.0e-15);

delete id;
delete id;
}

CAROM::Matrix *A = exactQ.mult(exactR); // Compute A = QR
Expand All @@ -113,24 +113,24 @@ TEST(QRfactorizeTest, Test_QR)

double maxError = 0.0;
for (int i = 0; i < loc_num_rows; i++) {
for (int j = 0; j < num_columns; j++) {
const double error = std::abs(exactQ(i, j) + (*Q)(i, j));
maxError = std::max(maxError, error);
}
for (int j = 0; j < num_columns; j++) {
const double error = std::abs(exactQ(i, j) + (*Q)(i, j));
maxError = std::max(maxError, error);
}
}

EXPECT_NEAR(maxError, 0.0, 1.0e-15);

if (rank > 0) return;

EXPECT_EQ(R->numRows(), num_columns);
EXPECT_EQ(R->numColumns(), num_columns);

for (int i = 0; i < num_columns; i++) {
for (int j = 0; j < num_columns; j++) {
const double error = std::abs(exactR(i, j) + (*R)(i, j));
maxError = std::max(maxError, error);
}
for (int j = 0; j < num_columns; j++) {
const double error = std::abs(exactR(i, j) + (*R)(i, j));
maxError = std::max(maxError, error);
}
}

EXPECT_NEAR(maxError, 0.0, 1.0e-15);
Expand Down

0 comments on commit 3dd2758

Please sign in to comment.