From eca3bd047f9a53e4f92f51ab753edf195a937e85 Mon Sep 17 00:00:00 2001 From: b92paul Date: Thu, 8 Mar 2018 15:02:51 +0800 Subject: [PATCH] Fixed bug and optimize code in TRON::tron Variable "iter" and "w" won't change in the while loop of function TRON::tron when the direction does not lead to sufficient function-value decrease, so using expression "iter == 1" as a flag to initialize variables will cause problems in the first step. We introduce a new variable "delta_adjusted" to fix the bug. The function call "fun_obj->get_diagH(M)" and the calculation of "(1-alpha_pcg) I + alpha_pcg M" can be saved if "iter" and "w" remains the same. We move some lines of code to save the calculation. --- tron.cpp | 19 ++++++++++++------- 1 file changed, 12 insertions(+), 7 deletions(-) diff --git a/tron.cpp b/tron.cpp index d662d99..2d93dc3 100644 --- a/tron.cpp +++ b/tron.cpp @@ -103,17 +103,16 @@ void TRON::tron(double *w) if (gnorm <= eps*gnorm0) search = 0; - iter = 1; + fun_obj->get_diagH(M); + for(i=0; iget_diagH(M); - for(i=0; igrad(w, g); + fun_obj->get_diagH(M); + for(i=0; i