File tree Expand file tree Collapse file tree 1 file changed +7
-5
lines changed
Expand file tree Collapse file tree 1 file changed +7
-5
lines changed Original file line number Diff line number Diff line change @@ -105,11 +105,13 @@ VectorXd C3Plus::SolveSingleProjection(const MatrixXd& U,
105105
106106 // Extract the weight vectors for lambda and eta from the diagonal of the cost
107107 // matrix U.
108- // Use absolute values to ensure numerical safety when taking square roots,
109- // in case the user inadvertently supplies negative weights.
110- VectorXd w_eta_vec =
111- U.block (n_ + m_ + k_, n_ + m_ + k_, m_, m_).diagonal ().cwiseAbs ();
112- VectorXd w_lambda_vec = U.block (n_, n_, m_, m_).diagonal ().cwiseAbs ();
108+ VectorXd w_eta_vec = U.block (n_ + m_ + k_, n_ + m_ + k_, m_, m_).diagonal ();
109+ VectorXd w_lambda_vec = U.block (n_, n_, m_, m_).diagonal ();
110+
111+ // Throw an error if any weights are negative.
112+ if (w_eta_vec.minCoeff () < 0 || w_lambda_vec.minCoeff () < 0 ) {
113+ throw std::runtime_error (" Negative weights in the cost matrix U are not allowed." );
114+ }
113115
114116 VectorXd lambda_c = delta_c.segment (n_, m_);
115117 VectorXd eta_c = delta_c.segment (n_ + m_ + k_, m_);
You can’t perform that action at this time.
0 commit comments