diff --git a/cpp/iterative-inl.h b/cpp/iterative-inl.h index 6a8ac6869..cb325b6df 100644 --- a/cpp/iterative-inl.h +++ b/cpp/iterative-inl.h @@ -115,14 +115,16 @@ namespace gtsam { V conjugateGradients(const S& Ab, V x, bool verbose, double epsilon, double epsilon_abs, size_t maxIterations, bool steepest = false) { - CGState state(Ab, x, verbose, epsilon, epsilon_abs, maxIterations, - steepest); - if (state.gamma < state.threshold) return x; - + CGState state(Ab, x, verbose, epsilon, epsilon_abs, maxIterations,steepest); if (verbose) cout << "CG: epsilon = " << epsilon << ", maxIterations = " << state.maxIterations << ", ||g0||^2 = " << state.gamma << ", threshold = " << state.threshold << endl; + if (state.gamma < state.threshold) { + if (verbose) cout << "||g0||^2 < threshold, exiting immediately !" << endl; + return x; + } + // loop maxIterations times while (!state.step(Ab, x)) ;