Skip to content

Commit

Permalink
Merge pull request #159 from zoq/lookahead-maxiterations
Browse files Browse the repository at this point in the history
Fix Lookahead MaxIterations() check
  • Loading branch information
rcurtin authored Jan 15, 2020
2 parents 4a35fd6 + fe9c6f3 commit 226352a
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 10 deletions.
3 changes: 3 additions & 0 deletions HISTORY.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,9 @@
* Minor test stability fixes on i386
([#156](https://github.com/mlpack/ensmallen/pull/156)).

* Fix Lookahead MaxIterations() check.
([#159](https://github.com/mlpack/ensmallen/pull/159)).

### ensmallen 2.11.1: "The Poster Session Is Full"
###### 2019-12-28
* Fix Lookahead Synchronization period type
Expand Down
25 changes: 25 additions & 0 deletions include/ensmallen_bits/lookahead/lookahead.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -188,6 +188,31 @@ class Lookahead
bool& ExactObjective() { return exactObjective; }

private:
/**
* Set the maximum number of iterations if the given optimizer implements
* MaxIterations().
*
* @param optimizer Optimizer to check for MaxIterations().
* @param k The number of iterations.
*/
template<typename OptimizerType>
static typename std::enable_if<traits::HasMaxIterationsSignature<
OptimizerType>::value, void>::type
SetMaxIterations(OptimizerType& optimizer, const size_t k)
{
optimizer.MaxIterations() = k;
}

template<typename OptimizerType>
static typename std::enable_if<!traits::HasMaxIterationsSignature<
OptimizerType>::value, void>::type
SetMaxIterations(const OptimizerType& /* optimizer */, const size_t /* k */)
{
Warn << "The base optimizer does not have a definition of "
<< "MaxIterations(), the base optimizer will have its configuration "
<< "unchanged.";
}

//! The base optimizer for the forward step.
BaseOptimizerType baseOptimizer;

Expand Down
11 changes: 1 addition & 10 deletions include/ensmallen_bits/lookahead/lookahead_impl.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -98,16 +98,7 @@ Lookahead<BaseOptimizerType, DecayPolicyType>::Optimize(

// Check if the optimizer implements HasMaxIterations() and override the
// parameter with k.
if (traits::HasMaxIterationsSignature<BaseOptimizerType>::value)
{
baseOptimizer.MaxIterations() = k;
}
else
{
Warn << "The base optimizer does not have a definition of "
<< "MaxIterations(), the base optimizer will have its configuration "
<< "unchanged.";
}
SetMaxIterations(baseOptimizer, k);

// Check if the optimizer implements ResetPolicy() and override the reset
// policy.
Expand Down

0 comments on commit 226352a

Please sign in to comment.