Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
cargo fmt
  • Loading branch information
alphaville committed Mar 27, 2026
commit bfa66241133c45caa102397daab5dcf59b9f204e
41 changes: 20 additions & 21 deletions src/alm/alm_optimizer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -764,13 +764,14 @@ where
// This function will panic is there is no akkt_tolerance
// This should never happen because we set the AKKT tolerance
// in the constructor and can never become `None` again
let criterion_3 = cache
.panoc_cache
.akkt_tolerance
.ok_or(SolverError::InvalidProblemState(
"missing inner AKKT tolerance while checking the exit criterion",
))?
<= self.epsilon_tolerance + SMALL_EPSILON;
let criterion_3 =
cache
.panoc_cache
.akkt_tolerance
.ok_or(SolverError::InvalidProblemState(
"missing inner AKKT tolerance while checking the exit criterion",
))?
<= self.epsilon_tolerance + SMALL_EPSILON;
Ok(criterion_1 && criterion_2 && criterion_3)
}

Expand Down Expand Up @@ -811,12 +812,13 @@ where
fn update_inner_akkt_tolerance(&mut self) -> FunctionCallResult {
let cache = &mut self.alm_cache;
// epsilon_{nu+1} := max(epsilon, beta*epsilon_nu)
let akkt_tolerance = cache
.panoc_cache
.akkt_tolerance
.ok_or(SolverError::InvalidProblemState(
"missing inner AKKT tolerance while updating it",
))?;
let akkt_tolerance =
cache
.panoc_cache
.akkt_tolerance
.ok_or(SolverError::InvalidProblemState(
"missing inner AKKT tolerance while updating it",
))?;
cache.panoc_cache.set_akkt_tolerance(f64::max(
akkt_tolerance * self.epsilon_update_factor,
self.epsilon_tolerance,
Expand Down Expand Up @@ -992,14 +994,11 @@ where
.with_penalty(c)
.with_cost(cost);
if self.alm_problem.n1 > 0 {
let status = status.with_lagrange_multipliers(
self.alm_cache
.y_plus
.as_ref()
.ok_or(SolverError::InvalidProblemState(
"missing Lagrange multipliers at the ALM solution",
))?,
);
let status = status.with_lagrange_multipliers(self.alm_cache.y_plus.as_ref().ok_or(
SolverError::InvalidProblemState(
"missing Lagrange multipliers at the ALM solution",
),
)?);
Ok(status)
} else {
Ok(status)
Expand Down
9 changes: 3 additions & 6 deletions src/constraints/affine_space.rs
Original file line number Diff line number Diff line change
Expand Up @@ -86,12 +86,9 @@ impl Constraint for AffineSpace {
assert!(x.len() == n, "x has wrong dimension");

// Step 1: Compute e = Ax - b
let a = ArrayView2::from_shape((self.n_rows, self.n_cols), &self.a_mat)
.map_err(|_| {
SolverError::InvalidProblemState(
"failed to construct the affine-space matrix view",
)
})?;
let a = ArrayView2::from_shape((self.n_rows, self.n_cols), &self.a_mat).map_err(|_| {
SolverError::InvalidProblemState("failed to construct the affine-space matrix view")
})?;
let x_view = ArrayView1::from(&x[..]);
let b = ArrayView1::from(&self.b_vec[..]);
let e = a.dot(&x_view) - b;
Expand Down
9 changes: 6 additions & 3 deletions src/core/panoc/panoc_engine.rs
Original file line number Diff line number Diff line change
Expand Up @@ -264,7 +264,8 @@ where
// point `u_plus`
(self.problem.cost)(&self.cache.u_plus, &mut self.cache.cost_value)?;
(self.problem.gradf)(&self.cache.u_plus, &mut self.cache.gradient_u)?;
if !self.cache.cost_value.is_finite() || !matrix_operations::is_finite(&self.cache.gradient_u)
if !self.cache.cost_value.is_finite()
|| !matrix_operations::is_finite(&self.cache.gradient_u)
{
return Err(SolverError::NotFiniteComputation(
"line-search candidate produced a non-finite cost or gradient",
Expand All @@ -287,7 +288,8 @@ where
u_current.copy_from_slice(&self.cache.u_half_step); // set u_current ← u_half_step
(self.problem.cost)(u_current, &mut self.cache.cost_value)?; // cost value
(self.problem.gradf)(u_current, &mut self.cache.gradient_u)?; // compute gradient
if !self.cache.cost_value.is_finite() || !matrix_operations::is_finite(&self.cache.gradient_u)
if !self.cache.cost_value.is_finite()
|| !matrix_operations::is_finite(&self.cache.gradient_u)
{
return Err(SolverError::NotFiniteComputation(
"first PANOC iterate produced a non-finite cost or gradient",
Expand Down Expand Up @@ -389,7 +391,8 @@ where
self.cache.reset();
(self.problem.cost)(u_current, &mut self.cache.cost_value)?; // cost value
self.estimate_loc_lip(u_current)?; // computes the gradient as well! (self.cache.gradient_u)
if !self.cache.cost_value.is_finite() || !matrix_operations::is_finite(&self.cache.gradient_u)
if !self.cache.cost_value.is_finite()
|| !matrix_operations::is_finite(&self.cache.gradient_u)
{
return Err(SolverError::NotFiniteComputation(
"initial PANOC cost or gradient is non-finite",
Expand Down
Loading