60
60
//! fn main() -> Result<(), Infallible> {
61
61
//! let problem = Rosenbrock { n: 2 };
62
62
//! let nm = NelderMead::default();
63
- //! let mut m = Minimizer::new(&nm , 2);
63
+ //! let mut m = Minimizer::new(Box::new(nm) , 2);
64
64
//! let x0 = &[2.0, 2.0];
65
65
//! m.minimize(&problem, x0, &mut ())?;
66
66
//! println!("{}", m.status);
@@ -183,7 +183,6 @@ use std::{
183
183
} ,
184
184
} ;
185
185
186
- use dyn_clone:: DynClone ;
187
186
use fastrand:: Rng ;
188
187
use fastrand_contrib:: RngExt ;
189
188
use lazy_static:: lazy_static;
@@ -733,7 +732,7 @@ impl Display for Status {
733
732
///
734
733
/// This trait is implemented for the algorithms found in the [`algorithms`] module, and contains
735
734
/// all the methods needed to be run by a [`Minimizer`].
736
- pub trait Algorithm < U , E > : DynClone {
735
+ pub trait Algorithm < U , E > {
737
736
/// Any setup work done before the main steps of the algorithm should be done here.
738
737
///
739
738
/// # Errors
@@ -795,7 +794,6 @@ pub trait Algorithm<U, E>: DynClone {
795
794
Ok ( ( ) )
796
795
}
797
796
}
798
- dyn_clone:: clone_trait_object!( <U , E > Algorithm <U , E >) ;
799
797
800
798
/// A trait which holds a [`callback`](`Observer::callback`) function that can be used to check an
801
799
/// [`Algorithm`]'s [`Status`] during a minimization.
@@ -824,21 +822,9 @@ impl<U, E> Display for Minimizer<U, E> {
824
822
825
823
impl < U , E > Minimizer < U , E > {
826
824
const DEFAULT_MAX_STEPS : usize = 4000 ;
827
- /// Creates a new [`Minimizer`] with the given [`Algorithm`] and `dimension` set to the number
828
- /// of free parameters in the minimization problem.
829
- pub fn new < A : Algorithm < U , E > + ' static > ( algorithm : & A , dimension : usize ) -> Self {
830
- Self {
831
- status : Status :: default ( ) ,
832
- algorithm : Box :: new ( dyn_clone:: clone ( algorithm) ) ,
833
- bounds : None ,
834
- max_steps : Self :: DEFAULT_MAX_STEPS ,
835
- observers : Vec :: default ( ) ,
836
- dimension,
837
- }
838
- }
839
825
/// Creates a new [`Minimizer`] with the given (boxed) [`Algorithm`] and `dimension` set to the number
840
826
/// of free parameters in the minimization problem.
841
- pub fn new_from_box ( algorithm : Box < dyn Algorithm < U , E > > , dimension : usize ) -> Self {
827
+ pub fn new ( algorithm : Box < dyn Algorithm < U , E > > , dimension : usize ) -> Self {
842
828
Self {
843
829
status : Status :: default ( ) ,
844
830
algorithm,
@@ -855,11 +841,6 @@ impl<U, E> Minimizer<U, E> {
855
841
} ;
856
842
self . status = new_status;
857
843
}
858
- /// Set the [`Algorithm`] used by the [`Minimizer`].
859
- pub fn with_algorithm < A : Algorithm < U , E > + ' static > ( mut self , algorithm : & A ) -> Self {
860
- self . algorithm = Box :: new ( dyn_clone:: clone ( algorithm) ) ;
861
- self
862
- }
863
844
/// Set the maximum number of steps to perform before failure (default: 4000).
864
845
pub const fn with_max_steps ( mut self , max_steps : usize ) -> Self {
865
846
self . max_steps = max_steps;
@@ -998,14 +979,13 @@ impl<U, E> Minimizer<U, E> {
998
979
mod tests {
999
980
use std:: convert:: Infallible ;
1000
981
1001
- use crate :: { algorithms:: LBFGSB , Algorithm , Minimizer } ;
982
+ use crate :: { algorithms:: LBFGSB , Minimizer } ;
1002
983
1003
984
#[ test]
1004
985
#[ allow( unused_variables) ]
1005
- fn test_minimizer_constructors ( ) {
986
+ fn test_minimizer_constructor ( ) {
987
+ #[ allow( clippy:: box_default) ]
1006
988
let algo: LBFGSB < ( ) , Infallible > = LBFGSB :: default ( ) ;
1007
- let minimizer = Minimizer :: new ( & algo, 5 ) ;
1008
- let algo_boxed: Box < dyn Algorithm < ( ) , Infallible > > = Box :: new ( algo) ;
1009
- let minimizer_from_box = Minimizer :: new_from_box ( algo_boxed, 5 ) ;
989
+ let minimizer = Minimizer :: new ( Box :: new ( algo) , 5 ) ;
1010
990
}
1011
991
}
0 commit comments