Skip to content

Commit

Permalink
refactor!: rename SolveError to TestingError
Browse files Browse the repository at this point in the history
  • Loading branch information
pnevyk committed Nov 12, 2023
1 parent 9ea04f0 commit 7e72ec7
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 10 deletions.
2 changes: 1 addition & 1 deletion src/solver/nelder_mead.rs
Original file line number Diff line number Diff line change
Expand Up @@ -629,7 +629,7 @@ mod tests {
// outside the bounds.
assert!(matches!(
solve(&f, &dom, solver, x, 5, eps),
Err(SolveError::Solver(NelderMeadError::SimplexCollapsed))
Err(TestingError::Inner(NelderMeadError::SimplexCollapsed))
));
}

Expand Down
4 changes: 2 additions & 2 deletions src/solver/trust_region.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1115,7 +1115,7 @@ mod tests {
// the bounds.
assert!(matches!(
solve(&f, &dom, solver, x, 50, eps),
Err(SolveError::Solver(TrustRegionError::NoProgress)) | Err(SolveError::Termination)
Err(TestingError::Inner(TrustRegionError::NoProgress)) | Err(TestingError::Termination)
));
}

Expand All @@ -1129,7 +1129,7 @@ mod tests {
let solver = TrustRegion::new(&f, &dom);
assert!(match solve(&f, &dom, solver, x, 25, eps) {
Ok(root) => f.is_root(&root, eps),
Err(SolveError::Solver(TrustRegionError::NoValidStep)) => true,
Err(TestingError::Inner(TrustRegionError::NoValidStep)) => true,
Err(error) => panic!("{:?}", error),
});
}
Expand Down
15 changes: 8 additions & 7 deletions src/testing.rs
Original file line number Diff line number Diff line change
Expand Up @@ -654,12 +654,13 @@ impl TestProblem for InfiniteSolutions {

impl TestSystem for InfiniteSolutions {}

/// Solving error of the testing solver driver (see [`solve`]).
/// Solving or optimization error of the testing solver/optimizer driver (see
/// [`solve`] and [`optimize`]).
#[derive(Debug, Error)]
pub enum SolveError<E: StdError + 'static> {
pub enum TestingError<E: StdError + 'static> {
/// Error of the solver used.
#[error("{0}")]
Solver(#[from] E),
Inner(#[from] E),
/// Solver did not terminate.
#[error("solver did not terminate")]
Termination,
Expand All @@ -673,7 +674,7 @@ pub fn solve<F: TestSystem, S: Solver<F>>(
mut x: OVector<F::Scalar, F::Dim>,
max_iters: usize,
tolerance: F::Scalar,
) -> Result<OVector<F::Scalar, F::Dim>, SolveError<S::Error>>
) -> Result<OVector<F::Scalar, F::Dim>, TestingError<S::Error>>
where
DefaultAllocator: Allocator<F::Scalar, F::Dim>,
S::Error: StdError,
Expand All @@ -689,7 +690,7 @@ where
}

if iter == max_iters {
return Err(SolveError::Termination);
return Err(TestingError::Termination);
} else {
iter += 1;
}
Expand All @@ -705,7 +706,7 @@ pub fn optimize<F: Function, O: Optimizer<F>>(
min: F::Scalar,
max_iters: usize,
tolerance: F::Scalar,
) -> Result<OVector<F::Scalar, F::Dim>, SolveError<O::Error>>
) -> Result<OVector<F::Scalar, F::Dim>, TestingError<O::Error>>
where
DefaultAllocator: Allocator<F::Scalar, F::Dim>,
O::Error: StdError,
Expand All @@ -721,7 +722,7 @@ where
}

if iter == max_iters {
return Err(SolveError::Termination);
return Err(TestingError::Termination);
} else {
iter += 1;
}
Expand Down

0 comments on commit 7e72ec7

Please sign in to comment.