Skip to content

Commit

Permalink
fixed compiler warnings. Changed mp_results to be initialized in stru…
Browse files Browse the repository at this point in the history
…ct instead of memset
  • Loading branch information
Arthur Glowacki committed Nov 30, 2023
1 parent 6fd555c commit 78fc406
Show file tree
Hide file tree
Showing 8 changed files with 55 additions and 42 deletions.
2 changes: 1 addition & 1 deletion src/data_struct/detector.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -190,7 +190,7 @@ void Detector<T_real>::update_element_quants(Fitting_Routines routine,
}
else
{
eq_itr.e_cal_ratio += 1.0e-10;
eq_itr.e_cal_ratio += (T_real)1.0e-10;
}
}
}
Expand Down
2 changes: 1 addition & 1 deletion src/fitting/models/base_model.h
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ class DLL_EXPORT Base_Model
/**
* @brief ~Base_Model : Destructor
*/
~Base_Model() {}
virtual ~Base_Model() {}

/**
* @brief fit_parameters : returns Fit_Parameters class of the required fit parameters to run a fitting
Expand Down
2 changes: 1 addition & 1 deletion src/fitting/models/gaussian_model.h
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ class DLL_EXPORT Gaussian_Model: public Base_Model<T_real>
public:
Gaussian_Model();

~Gaussian_Model();
virtual ~Gaussian_Model();

virtual const Fit_Parameters<T_real>& fit_parameters() const { return _fit_parameters; }

Expand Down
2 changes: 1 addition & 1 deletion src/fitting/optimizers/lmfit_optimizer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -441,7 +441,7 @@ OPTIMIZER_OUTCOME LMFit_Optimizer<T_real>::minimize_quantification(Fit_Parameter
std::vector<T_real> perror(fitp_arr.size());

lm_status_struct<T_real> status;
lmmin( fitp_arr.size(), &fitp_arr[0], quant_map->size(), (const void*) &ud, quantification_residuals_lmfit, &_options, &status );
lmmin( fitp_arr.size(), &fitp_arr[0], ud.quant_map.size(), (const void*) &ud, quantification_residuals_lmfit, &_options, &status );
logI << "\nOutcome: " << lm_infmsg[status.outcome] << "\nNum iter: " << status.nfev << "\nNorm of the residue vector: " << status.fnorm << "\n";
this->_last_outcome = status.outcome;
fit_params->from_array(fitp_arr);
Expand Down
23 changes: 10 additions & 13 deletions src/fitting/optimizers/mpfit_optimizer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -192,17 +192,17 @@ MPFit_Optimizer<T_real>::MPFit_Optimizer() : Optimizer<T_real>()
//_options { 1e-10, 1e-10, 1e-10, MP_MACHEP0, 100.0, 1.0e-14, 2000, 0, 0, 0, 0, 0 };
if (std::is_same<T_real, float>::value)
{
_options.ftol = 1.192e-10; // Relative chi-square convergence criterium Default: 1e-10
_options.xtol = 1.192e-10; // Relative parameter convergence criterium Default: 1e-10
_options.gtol = 1.192e-10; // Orthogonality convergence criterium Default: 1e-10
_options.epsfcn = FP_MP_MACHEP0; // Finite derivative step size Default: MP_MACHEP0
_options.ftol = (T_real)1.192e-10; // Relative chi-square convergence criterium Default: 1e-10
_options.xtol = (T_real)1.192e-10; // Relative parameter convergence criterium Default: 1e-10
_options.gtol = (T_real)1.192e-10; // Orthogonality convergence criterium Default: 1e-10
_options.epsfcn = (T_real)FP_MP_MACHEP0; // Finite derivative step size Default: MP_MACHEP0
}
else if (std::is_same<T_real, double>::value)
{
_options.ftol = 1.192e-10; // Relative chi-square convergence criterium Default: 1e-10
_options.xtol = 1.192e-10; // Relative parameter convergence criterium Default: 1e-10
_options.gtol = 1.192e-10; // Orthogonality convergence criterium Default: 1e-10
_options.epsfcn = DP_MP_MACHEP0; // Finite derivative step size Default: MP_MACHEP0
_options.ftol = (T_real)1.192e-10; // Relative chi-square convergence criterium Default: 1e-10
_options.xtol = (T_real)1.192e-10; // Relative parameter convergence criterium Default: 1e-10
_options.gtol = (T_real)1.192e-10; // Orthogonality convergence criterium Default: 1e-10
_options.epsfcn = (T_real)DP_MP_MACHEP0; // Finite derivative step size Default: MP_MACHEP0
}
_options.stepfactor = (T_real)100.0; // Initial step bound Default: 100.0
_options.covtol = (T_real)1.0e-14; // Range tolerance for covariance calculation Default: 1e-14
Expand Down Expand Up @@ -475,7 +475,6 @@ OPTIMIZER_OUTCOME MPFit_Optimizer<T_real>::minimize(Fit_Parameters<T_real>*fit_p
_fill_limits(fit_params, par);

mp_result<T_real> result;
memset(&result,0,sizeof(mp_result<T_real>));
result.xerror = &perror[0];
result.resid = &resid[0];
result.covar = &covar[0];
Expand Down Expand Up @@ -620,7 +619,6 @@ OPTIMIZER_OUTCOME MPFit_Optimizer<T_real>::minimize_func(Fit_Parameters<T_real>
_fill_limits(fit_params, par);

mp_result<T_real> result;
memset(&result,0,sizeof(mp_result<T_real>));
result.xerror = &perror[0];
result.resid = &resid[0];

Expand Down Expand Up @@ -723,7 +721,7 @@ OPTIMIZER_OUTCOME MPFit_Optimizer<T_real>::minimize_quantification(Fit_Parameter

std::vector<T_real> fitp_arr = fit_params->to_array();
std::vector<T_real> perror(fitp_arr.size());
std::vector<T_real> resid(quant_map->size());
std::vector<T_real> resid(ud.quant_map.size());

/*
/////// init config ////////////
Expand Down Expand Up @@ -758,7 +756,6 @@ OPTIMIZER_OUTCOME MPFit_Optimizer<T_real>::minimize_quantification(Fit_Parameter
_options.maxfev = _options.maxiter * (fitp_arr.size() + 1);

mp_result<T_real> result;
memset(&result,0,sizeof(mp_result<T_real>));
result.xerror = &perror[0];
result.resid = &resid[0];
// struct mp_par<T_real> *mp_par = nullptr;
Expand All @@ -769,7 +766,7 @@ OPTIMIZER_OUTCOME MPFit_Optimizer<T_real>::minimize_quantification(Fit_Parameter
par.resize(fitp_arr.size());
_fill_limits(fit_params, par);

this->_last_outcome = mpfit(quantification_residuals_mpfit<T_real>, quant_map->size(), fitp_arr.size(), &fitp_arr[0], &par[0], &_options, (void *) &ud, &result);
this->_last_outcome = mpfit(quantification_residuals_mpfit<T_real>, ud.quant_map.size(), fitp_arr.size(), &fitp_arr[0], &par[0], &_options, (void *) &ud, &result);
logI << "\nOutcome: " << optimizer_outcome_to_str(this->_outcome_map[this->_last_outcome]) << "\nNum iter: " << result.niter << "\n Norm of the residue vector: " << *result.resid << "\n";

logI << detailed_outcome(this->_last_outcome);
Expand Down
44 changes: 30 additions & 14 deletions src/support/cmpfit-1.3a/mpfit.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,22 @@ struct mp_config
template <typename _T>
struct mp_result
{
mp_result()
{
bestnorm = (_T)0.;
orignorm = (_T)0.;
niter = 0;
nfev = 0;
status = 0;
npar = 0;
nfree = 0;
npegged = 0;
nfunc = 0;
resid = nullptr;;
xerror = nullptr;
covar = nullptr;
}

_T bestnorm; /* Final chi^2 */
_T orignorm; /* Starting value of chi^2 */
int niter; /* Number of iterations */
Expand Down Expand Up @@ -434,11 +450,11 @@ int mp_fdjac2(int (*mp_func)(int m, int n, _T *x, _T *fvec, _T **dvec, void *pri
_T MP_MACHEP0;
if (std::is_same<_T, float>::value)
{
MP_MACHEP0 = FP_MP_MACHEP0;
MP_MACHEP0 = (_T)FP_MP_MACHEP0;
}
else if (std::is_same<_T, double>::value)
{
MP_MACHEP0 = DP_MP_MACHEP0;
MP_MACHEP0 = (_T)DP_MP_MACHEP0;
}

temp = std::max<_T>(epsfcn,MP_MACHEP0);
Expand Down Expand Up @@ -681,11 +697,11 @@ void mp_qrfac(int m, int n, _T *a, int lda,
_T MP_MACHEP0;
if (std::is_same<_T, float>::value)
{
MP_MACHEP0 = FP_MP_MACHEP0;
MP_MACHEP0 = (_T)FP_MP_MACHEP0;
}
else if (std::is_same<_T, double>::value)
{
MP_MACHEP0 = DP_MP_MACHEP0;
MP_MACHEP0 = (_T)DP_MP_MACHEP0;
}

lda = 0; /* Prevent compiler warning */
Expand Down Expand Up @@ -1147,11 +1163,11 @@ void mp_lmpar(int n, _T *r, int ldr, int *ipvt, int *ifree, _T *diag,
_T MP_DWARF;
if (std::is_same<_T, float>::value)
{
MP_DWARF = FP_MP_DWARF;
MP_DWARF = (_T)FP_MP_DWARF;
}
else if (std::is_same<_T, double>::value)
{
MP_DWARF = DP_MP_DWARF;
MP_DWARF = (_T)DP_MP_DWARF;
}

/*
Expand Down Expand Up @@ -1747,11 +1763,11 @@ int mpfit(int (*mp_func)(int m, int n, _T *x, _T *fvec, _T **dvec, void *private
_T MP_MACHEP0;
if (std::is_same<_T, float>::value)
{
MP_MACHEP0 = FP_MP_MACHEP0;
MP_MACHEP0 = (_T)FP_MP_MACHEP0;
}
else if (std::is_same<_T, double>::value)
{
MP_MACHEP0 = DP_MP_MACHEP0;
MP_MACHEP0 = (_T)DP_MP_MACHEP0;
}

int ij,jj,l;
Expand Down Expand Up @@ -1781,16 +1797,16 @@ int mpfit(int (*mp_func)(int m, int n, _T *x, _T *fvec, _T **dvec, void *private
int ldfjac;

/* Default configuration */
conf.ftol = 1e-10;
conf.xtol = 1e-10;
conf.gtol = 1e-10;
conf.stepfactor = 100.0;
conf.ftol = (_T)1e-10;
conf.xtol = (_T)1e-10;
conf.gtol = (_T)1e-10;
conf.stepfactor = (_T)100.0;
conf.nprint = 1;
conf.epsfcn = MP_MACHEP0;
conf.epsfcn = (_T)MP_MACHEP0;
conf.maxiter = 200;
conf.douserscale = 0;
conf.maxfev = 0;
conf.covtol = 1e-14;
conf.covtol = (_T)1e-14;
conf.nofinitecheck = 0;

if (config) {
Expand Down
14 changes: 7 additions & 7 deletions src/support/lmfit_6.1/lmmin.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -790,21 +790,21 @@ void lmmin(const int n, _T* x, const int m, const void* data,
_T LM_MACHEP;
if (std::is_same<_T, float>::value)
{
LM_DWARF = FP_LM_DWARF;
LM_MACHEP = FP_LM_MACHEP;
LM_DWARF = (_T)FP_LM_DWARF;
LM_MACHEP = (_T)FP_LM_MACHEP;
}
else if (std::is_same<_T, double>::value)
{
LM_DWARF = DP_LM_DWARF;
LM_MACHEP = DP_LM_MACHEP;
LM_DWARF = (_T)DP_LM_DWARF;
LM_MACHEP = (_T)DP_LM_MACHEP;
}

int maxfev = C->patience * (n+1);

int inner_success; /* flag for loop control */
_T lmpar = 0; /* Levenberg-Marquardt parameter */
_T delta = 0;
_T xnorm = 0;
_T lmpar = (_T)0.; /* Levenberg-Marquardt parameter */
_T delta = (_T)0.;
_T xnorm = (_T)0.;
_T eps = sqrt(MAX(C->epsilon, LM_MACHEP)); /* for forward differences */

int nout = C->n_maxpri == -1 ? n : MIN(C->n_maxpri, n);
Expand Down
8 changes: 4 additions & 4 deletions src/support/nnls/nnls.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -51,10 +51,10 @@ namespace nsNNLS
fset = 0;
// convergence controlling parameters
M = 100;
beta = 1.0;
decay = 0.9;
pgtol = 1e-3;
sigma = .01;
beta = (_T)1.0;
decay = (_T)0.9;
pgtol = (_T)1e-3;
sigma = (_T).01;
}

nnls(Eigen::Matrix<_T, Eigen::Dynamic, Eigen::Dynamic> *A, TArrayXr *b, TArrayXr* x0, int maxit)
Expand Down

0 comments on commit 78fc406

Please sign in to comment.