Skip to content

Commit

Permalink
const ref
Browse files Browse the repository at this point in the history
  • Loading branch information
ssloy committed Jan 31, 2023
1 parent 5333e83 commit f129398
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 6 deletions.
8 changes: 4 additions & 4 deletions linesearch.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,11 @@
#include "linesearch.h"

namespace STLBFGS {
bool sufficient_decrease(Sample phi0, Sample phia, double mu) {
bool sufficient_decrease(const Sample &phi0, const Sample &phia, double mu) {
return phia.f <= phi0.f + mu*phia.a*phi0.d;
}

bool curvature_condition(Sample phi0, Sample phia, double eta) {
bool curvature_condition(const Sample &phi0, const Sample &phia, double eta) {
return std::abs(phia.d) <= eta*std::abs(phi0.d);
}

Expand Down Expand Up @@ -70,7 +70,7 @@ namespace STLBFGS {
return std::make_tuple(res, 4);
}

bool line_search_more_thuente(const linesearch_function phi, const Sample phi0, double &at, const double mu, const double eta, const int lsmaxfev) {
bool line_search_more_thuente(const linesearch_function phi, const Sample &phi0, double &at, const double mu, const double eta, const int lsmaxfev) {
double init_step = at;
bool stage1 = true; // use function psi instead if phi
bool bracketed = false;
Expand Down Expand Up @@ -150,7 +150,7 @@ namespace STLBFGS {
}

// a version of line search by Nocedal and Wright, Numerical optimization (2006)
bool line_search_backtracking(const linesearch_function phi, const Sample phi0, double &at, const double mu, const double eta, const int lsmaxfev) {
bool line_search_backtracking(const linesearch_function phi, const Sample &phi0, double &at, const double mu, const double eta, const int lsmaxfev) {
double init_step = at;
Sample phil = phi0;
Sample phiu = { 0, 0, 0 };
Expand Down
4 changes: 2 additions & 2 deletions linesearch.h
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@ namespace STLBFGS {
typedef std::function<Sample (const double alpha)> linesearch_function;

// lsmaxfev must be > 0. Search fails when the number of calls to phi exceeds lsmaxfev.
bool line_search_more_thuente(const linesearch_function phi, const Sample phi0, double &at, const double mu, const double eta, const int lsmaxfev=20);
bool line_search_backtracking(const linesearch_function phi, const Sample phi0, double &at, const double mu, const double eta, const int lsmaxfev=30);
bool line_search_more_thuente(const linesearch_function phi, const Sample &phi0, double &at, const double mu, const double eta, const int lsmaxfev=20);
bool line_search_backtracking(const linesearch_function phi, const Sample &phi0, double &at, const double mu, const double eta, const int lsmaxfev=30);
}

#endif //__LINESEARCH_H__
Expand Down

0 comments on commit f129398

Please sign in to comment.