Skip to content

Commit

Permalink
Use OpenMP in sign choice computation
Browse files Browse the repository at this point in the history
  • Loading branch information
Martin D. Weinberg committed Feb 14, 2025
1 parent f19fcd4 commit 55a6190
Showing 1 changed file with 9 additions and 21 deletions.
30 changes: 9 additions & 21 deletions expui/SvdSignChoice.cc
Original file line number Diff line number Diff line change
Expand Up @@ -57,20 +57,15 @@ namespace MSSA {
sL.setZero();
sR.setZero();

// Working, non-const instance
auto S1 = S;

// Get projections from left and right singular vectors onto data
// matrix
//
#pragma omp parallel for
for (int k=0; k<K; k++) {
// Remove all but target dimension for numerical stability
S1(k) = 0.0;
auto S1 = S; S1(k) = 0.0;
auto Y = X - U * S1.asDiagonal() * V.transpose();

// Restore the value
S1(k) = S(k);

// d_j = U^T_k * Y_j
Eigen::VectorXd dL = Y.transpose() * U.col(k);

Expand All @@ -91,6 +86,7 @@ namespace MSSA {

// Determine and apply the sign correction
//
#pragma omp parallel for
for (int k=0; k<K; k++) {
// If signs are opposite, flip the one with the smaller absolute
// value
Expand Down Expand Up @@ -142,20 +138,15 @@ namespace MSSA {
sL.setZero();
sR.setZero();

// Working, non-const instance
auto S1 = S;

// Get projections from left and right singular vectors onto data
// matrix
//
#pragma omp parallel for
for (int k=0; k<K; k++) {
// Remove all but target dimension for numerical stability
S1(k) = 0.0;
auto S1 = S; S1(k) = 0.0;
auto Y = X - U * S1.asDiagonal() * V.transpose();

// Restore the value
S1(k) = S(k);

// d_j = U^T_k * Y_j
Eigen::VectorXd dL = Y.transpose() * U.col(k);

Expand All @@ -176,6 +167,7 @@ namespace MSSA {

// Determine and apply the sign correction
//
#pragma omp parallel for
for (int k=0; k<K; k++) {
// If signs are opposite, flip the one with the smaller absolute
// value
Expand Down Expand Up @@ -226,20 +218,15 @@ namespace MSSA {
sL.setZero();
sR.setZero();

// Working, non-const instance
auto S1 = S;

// Get projections from left and right singular vectors onto data
// matrix
//
#pragma omp parallel for
for (int k=0; k<K; k++) {
// Remove all but target dimension for numerical stability
S1(k) = 0.0;
auto S1 = S; S1(k) = 0.0;
auto Y = X - U * S1.asDiagonal() * V.transpose();

// Restore the value
S1(k) = S(k);

// d_j = U^T_k * Y_j
Eigen::VectorXd dL = Y.transpose() * U.col(k);

Expand All @@ -260,6 +247,7 @@ namespace MSSA {

// Determine and apply the sign correction
//
#pragma omp parallel for
for (int k=0; k<K; k++) {
// If signs are opposite, flip the one with the smaller absolute
// value
Expand Down

0 comments on commit 55a6190

Please sign in to comment.