Skip to content

Commit

Permalink
ENH: Wrap new variant of itkLBFGS2Optimizerv4
Browse files Browse the repository at this point in the history
The new optimizer is based on modern c++ code rather than converted
fortran code.  The new optimizer also has a few interesting modes
that are not available in the original fortran implementation.

The LBFGS2 optimizer is only wrappable for double precision
internal computation type due to current limitations of the
core library only being able to be compiled for one data
type at a time.

Add static_assert to more clearly present this limitation
at compiletime.
  • Loading branch information
hjmjohnson authored and dzenanz committed Mar 7, 2024
1 parent 267876b commit 44c06f6
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 11 deletions.
10 changes: 5 additions & 5 deletions Modules/Numerics/Optimizersv4/include/itkLBFGS2Optimizerv4.h
Original file line number Diff line number Diff line change
Expand Up @@ -183,7 +183,8 @@ class ITK_TEMPLATE_EXPORT LBFGS2Optimizerv4Template
* define so lbfgs.h uses the correct version
**/
using PrecisionType = double;

static_assert(std::is_same<TInternalComputationValueType, double>::value,
"LBFGS2Optimizerv4Template only supports double precision");
/** Standard "Self" type alias. */
using Self = LBFGS2Optimizerv4Template;
using Superclass = GradientDescentOptimizerv4Template<TInternalComputationValueType>;
Expand Down Expand Up @@ -518,20 +519,19 @@ class ITK_TEMPLATE_EXPORT LBFGS2Optimizerv4Template
/**
* itkGradientDecentOptimizerv4Template specific non supported methods.
*/
void
SetMinimumConvergenceValue(double) override
void SetMinimumConvergenceValue(PrecisionType) override
{
itkWarningMacro("Not supported. Please use LBFGS specific convergence methods.");
};
void SetConvergenceWindowSize(SizeValueType) override
{
itkWarningMacro("Not supported. Please use LBFGS specific convergence methods.");
};
const double &
const PrecisionType &
GetConvergenceValue() const override
{
itkWarningMacro("Not supported. Please use LBFGS specific convergence methods.");
static double value = 0;
static PrecisionType value{};
return value;
};

Expand Down
8 changes: 2 additions & 6 deletions Modules/Numerics/Optimizersv4/src/itkLBFGS2Optimizerv4.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -27,15 +27,11 @@ operator<<(std::ostream & out, const LBFGS2Optimizerv4Enums::LineSearchMethod va
switch (value)
{
case LBFGS2Optimizerv4Enums::LineSearchMethod::LINESEARCH_DEFAULT:
return "itk::LBFGS2Optimizerv4Enums::LineSearchMethod::LINESEARCH_DEFAULT";
// case LBFGS2Optimizerv4Enums::LineSearchMethod::LINESEARCH_MORETHUENTE:
// return "itk::LBFGS2Optimizerv4Enums::LineSearchMethod::LINESEARCH_MORETHUENTE";
return "itk::LBFGS2Optimizerv4Enums::LineSearchMethod::LINESEARCH_DEFAULT (LINESEARCH_MORETHUENTE)";
case LBFGS2Optimizerv4Enums::LineSearchMethod::LINESEARCH_BACKTRACKING_ARMIJO:
return "itk::LBFGS2Optimizerv4Enums::LineSearchMethod::LINESEARCH_BACKTRACKING_ARMIJO";
case LBFGS2Optimizerv4Enums::LineSearchMethod::LINESEARCH_BACKTRACKING:
return "itk::LBFGS2Optimizerv4Enums::LineSearchMethod::LINESEARCH_BACKTRACKING";
// case LBFGS2Optimizerv4Enums::LineSearchMethod::LINESEARCH_BACKTRACKING_WOLFE:
// return "itk::LBFGS2Optimizerv4Enums::LineSearchMethod::LINESEARCH_BACKTRACKING_WOLFE";
return "itk::LBFGS2Optimizerv4Enums::LineSearchMethod::LINESEARCH_BACKTRACKING (LINESEARCH_BACKTRACKING_WOLFE)";
case LBFGS2Optimizerv4Enums::LineSearchMethod::LINESEARCH_BACKTRACKING_STRONG_WOLFE:
return "itk::LBFGS2Optimizerv4Enums::LineSearchMethod::LINESEARCH_BACKTRACKING_STRONG_WOLFE";
default:
Expand Down
13 changes: 13 additions & 0 deletions Modules/Numerics/Optimizersv4/wrapping/itkLBFGS2Optimizerv4.wrap
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
set(WRAPPER_AUTO_INCLUDE_HEADERS OFF)
itk_wrap_include("itkLBFGS2Optimizerv4.h")

itk_wrap_simple_class("itk::LBFGS2Optimizerv4Enums")

# only double supported at the momemnt unique(types "D;${WRAP_ITK_REAL}")
unique(types "D")

itk_wrap_class("itk::LBFGS2Optimizerv4Template" POINTER_WITH_CONST_POINTER)
foreach(t ${types})
itk_wrap_template("${ITKM_${t}}" "${ITKT_${t}}")
endforeach()
itk_end_wrap_class()

0 comments on commit 44c06f6

Please sign in to comment.