Skip to content

Commit d5e1f3c

Browse files
Joris Bayerstefan-k
authored andcommitted
Solver::NAME -> Solver::name()
1 parent 44687c5 commit d5e1f3c

File tree

31 files changed

+90
-33
lines changed

31 files changed

+90
-33
lines changed

crates/argmin/src/core/executor.rs

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -179,7 +179,8 @@ where
179179
let kv = kv.unwrap_or(kv![]);
180180

181181
// Observe after init
182-
self.observers.observe_init(S::NAME, &state, &kv)?;
182+
self.observers
183+
.observe_init(self.solver.name(), &state, &kv)?;
183184
}
184185

185186
state.func_counts(&self.problem);
@@ -680,7 +681,9 @@ mod tests {
680681
P: Clone,
681682
F: ArgminFloat,
682683
{
683-
const NAME: &'static str = "OptimizationAlgorithm";
684+
fn name(&self) -> &str {
685+
"OptimizationAlgorithm"
686+
}
684687

685688
// Only resets internal_state to 1
686689
fn init(

crates/argmin/src/core/result.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -124,7 +124,7 @@ where
124124
{
125125
fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
126126
writeln!(f, "OptimizationResult:")?;
127-
writeln!(f, " Solver: {}", S::NAME)?;
127+
writeln!(f, " Solver: {}", self.solver.name())?;
128128
writeln!(
129129
f,
130130
" param (best): {}",

crates/argmin/src/core/solver.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ use crate::core::{Error, Problem, State, TerminationReason, TerminationStatus, K
3333
/// P: Clone,
3434
/// F: ArgminFloat
3535
/// {
36-
/// const NAME: &'static str = "OptimizationAlgorithm";
36+
/// fn name(&self) -> &str { "OptimizationAlgorithm" }
3737
///
3838
/// fn init(
3939
/// &mut self,
@@ -64,7 +64,7 @@ use crate::core::{Error, Problem, State, TerminationReason, TerminationStatus, K
6464
/// ```
6565
pub trait Solver<O, I: State> {
6666
/// Name of the solver. Mainly used in [Observers](`crate::core::observers::Observe`).
67-
const NAME: &'static str;
67+
fn name(&self) -> &str;
6868

6969
/// Initializes the algorithm.
7070
///

crates/argmin/src/core/test_utils.rs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -327,7 +327,9 @@ impl TestSolver {
327327
}
328328

329329
impl<O> Solver<O, IterState<Vec<f64>, (), (), (), (), f64>> for TestSolver {
330-
const NAME: &'static str = "TestSolver";
330+
fn name(&self) -> &str {
331+
"TestSolver"
332+
}
331333

332334
fn next_iter(
333335
&mut self,

crates/argmin/src/solver/brent/brentopt.rs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -102,7 +102,9 @@ where
102102
O: CostFunction<Param = F, Output = F>,
103103
F: ArgminFloat,
104104
{
105-
const NAME: &'static str = "BrentOpt";
105+
fn name(&self) -> &str {
106+
"BrentOpt"
107+
}
106108

107109
fn init(
108110
&mut self,

crates/argmin/src/solver/brent/brentroot.rs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,9 @@ where
8080
O: CostFunction<Param = F, Output = F>,
8181
F: ArgminFloat,
8282
{
83-
const NAME: &'static str = "BrentRoot";
83+
fn name(&self) -> &str {
84+
"BrentRoot"
85+
}
8486

8587
fn init(
8688
&mut self,

crates/argmin/src/solver/conjugategradient/cg.rs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,9 @@ where
9191
R: ArgminMul<F, R> + ArgminMul<F, P> + ArgminConj + ArgminDot<R, F> + ArgminScaledAdd<P, F, R>,
9292
F: ArgminFloat + ArgminL2Norm<F>,
9393
{
94-
const NAME: &'static str = "Conjugate Gradient";
94+
fn name(&self) -> &str {
95+
"Conjugate Gradient"
96+
}
9597

9698
fn init(
9799
&mut self,

crates/argmin/src/solver/conjugategradient/nonlinear_cg.rs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -128,7 +128,9 @@ where
128128
B: NLCGBetaUpdate<G, P, F>,
129129
F: ArgminFloat,
130130
{
131-
const NAME: &'static str = "Nonlinear Conjugate Gradient";
131+
fn name(&self) -> &str {
132+
"Nonlinear Conjugate Gradient"
133+
}
132134

133135
fn init(
134136
&mut self,

crates/argmin/src/solver/gaussnewton/gaussnewton_linesearch.rs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,9 @@ where
9696
F: ArgminFloat,
9797
R: Clone,
9898
{
99-
const NAME: &'static str = "Gauss-Newton method with line search";
99+
fn name(&self) -> &str {
100+
"Gauss-Newton method with line search"
101+
}
100102

101103
fn next_iter(
102104
&mut self,

crates/argmin/src/solver/gaussnewton/gaussnewton_method.rs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -122,7 +122,9 @@ where
122122
+ ArgminDot<P, P>,
123123
F: ArgminFloat,
124124
{
125-
const NAME: &'static str = "Gauss-Newton method";
125+
fn name(&self) -> &str {
126+
"Gauss-Newton method"
127+
}
126128

127129
fn init(
128130
&mut self,

0 commit comments

Comments
 (0)