@@ -207,7 +207,7 @@ template <typename T>
207207double SequenceSolverT<T>::processPerFrameErrors_serial(
208208 SequenceSolverFunctionT<T>* fn,
209209 OnlineBandedHouseholderQR<T>& qrSolver,
210- ProgressBar& progress) {
210+ ProgressBar* progress) {
211211 double errorSum = 0 ;
212212 for (size_t iFrame = 0 ; iFrame < fn->getNumFrames (); ++iFrame) {
213213 auto [jacobian, residual, errorCur, nFunctions] = computePerFrameJacobian (fn, iFrame);
@@ -221,7 +221,9 @@ double SequenceSolverT<T>::processPerFrameErrors_serial(
221221 residual);
222222 }
223223
224- progress.increment (nFunctions);
224+ if (progress) {
225+ progress->increment (nFunctions);
226+ }
225227 }
226228 return errorSum;
227229}
@@ -259,7 +261,7 @@ double SequenceSolverT<T>::processErrorFunctions_parallel(
259261 OnlineBandedHouseholderQR<T>& qrSolver)>& processJac,
260262 SequenceSolverFunctionT<T>* fn,
261263 OnlineBandedHouseholderQR<T>& qrSolver,
262- ProgressBar& progress) {
264+ ProgressBar* progress) {
263265 const size_t end = fn->getNumFrames ();
264266
265267 // We will buffer at the end of the pipeline to ensure the universal parts of the matrices are
@@ -323,7 +325,9 @@ double SequenceSolverT<T>::processErrorFunctions_parallel(
323325 } else {
324326 qrSolver.addMutating (toProcess.jacobian , toProcess.residual );
325327 errorSum += toProcess.error ;
326- progress.increment (toProcess.nFunctions );
328+ if (progress) {
329+ progress->increment (toProcess.nFunctions );
330+ }
327331 }
328332 }
329333 }
@@ -338,7 +342,9 @@ double SequenceSolverT<T>::processErrorFunctions_parallel(
338342 while (!readyJacobians.empty ()) {
339343 qrSolver.addMutating (readyJacobians.front ().jacobian , readyJacobians.front ().residual );
340344 errorSum += readyJacobians.front ().error ;
341- progress.increment (readyJacobians.front ().nFunctions );
345+ if (progress) {
346+ progress->increment (readyJacobians.front ().nFunctions );
347+ }
342348 readyJacobians.pop_front ();
343349 }
344350 }
@@ -348,7 +354,9 @@ double SequenceSolverT<T>::processErrorFunctions_parallel(
348354 while (!reorderBuffer.empty ()) {
349355 qrSolver.addMutating (reorderBuffer.top ().jacobian , reorderBuffer.top ().residual );
350356 errorSum += reorderBuffer.top ().error ;
351- progress.increment (reorderBuffer.top ().nFunctions );
357+ if (progress) {
358+ progress->increment (reorderBuffer.top ().nFunctions );
359+ }
352360 reorderBuffer.pop ();
353361 }
354362 }
@@ -362,7 +370,7 @@ template <typename T>
362370double SequenceSolverT<T>::processPerFrameErrors_parallel(
363371 SequenceSolverFunctionT<T>* fn,
364372 OnlineBandedHouseholderQR<T>& qrSolver,
365- ProgressBar& progress) {
373+ ProgressBar* progress) {
366374 return processErrorFunctions_parallel (
367375 [](size_t iFrame,
368376 SequenceSolverFunctionT<T>* fn,
@@ -403,7 +411,7 @@ template <typename T>
403411double SequenceSolverT<T>::processSequenceErrors_serial(
404412 SequenceSolverFunctionT<T>* fn,
405413 OnlineBandedHouseholderQR<T>& qrSolver,
406- ProgressBar& progress) {
414+ ProgressBar* progress) {
407415 if (fn->numTotalSequenceErrorFunctions_ == 0 ) {
408416 return 0 ;
409417 }
@@ -434,7 +442,9 @@ double SequenceSolverT<T>::processSequenceErrors_serial(
434442 residual);
435443 }
436444
437- progress.increment (nFunctions);
445+ if (progress) {
446+ progress->increment (nFunctions);
447+ }
438448 }
439449 return errorSum;
440450}
@@ -454,20 +464,22 @@ void SequenceSolverT<T>::doIteration() {
454464
455465 fn->setFrameParametersFromJoinedParameterVector (this ->parameters_ );
456466
457- ProgressBar progress (
458- " Solving sequence" ,
459- fn->numTotalPerFrameErrorFunctions_ + fn->numTotalSequenceErrorFunctions_ ,
460- progressBar_);
467+ std::unique_ptr<ProgressBar> progress;
468+ if (progressBar_) {
469+ progress = std::make_unique<ProgressBar>(
470+ " Solving sequence" ,
471+ fn->numTotalPerFrameErrorFunctions_ + fn->numTotalSequenceErrorFunctions_ );
472+ }
461473
462474 this ->error_ = 0 ;
463475 if (this ->multithreaded_ ) {
464- this ->error_ += processPerFrameErrors_parallel (fn, qrSolver, progress);
476+ this ->error_ += processPerFrameErrors_parallel (fn, qrSolver, progress. get () );
465477
466478 // Sequence errors still have to be be processed serially, at least for now.
467- this ->error_ += processSequenceErrors_serial (fn, qrSolver, progress);
479+ this ->error_ += processSequenceErrors_serial (fn, qrSolver, progress. get () );
468480 } else {
469- this ->error_ += processPerFrameErrors_serial (fn, qrSolver, progress);
470- this ->error_ += processSequenceErrors_serial (fn, qrSolver, progress);
481+ this ->error_ += processPerFrameErrors_serial (fn, qrSolver, progress. get () );
482+ this ->error_ += processSequenceErrors_serial (fn, qrSolver, progress. get () );
471483 }
472484
473485 // Now, extract the delta:
0 commit comments