mlpack / ensmallen

A header-only C++ library for numerical optimization --
http://ensmallen.org
Other
742 stars 120 forks source link

Fix some callbacks that ignored return values #384

Closed rcurtin closed 11 months ago

rcurtin commented 11 months ago

I was debugging #377 further when I noticed that several of the callback functions (Evaluate(), Gradient(), EvaluateConstraint(), and others) actually don't use the return value of the callback.

Any overload of those callbacks would call:

    return (const_cast<CallbackType&>(callback).Evaluate(
        optimizer, function, coordinates, objective), false);

which always returns false. The fix for this was to adjust the traits for each callback type to provide ::hasBool and ::hasVoid members, and then use the return value for the ::hasBool version, just like StepTaken() does (and a couple other callbacks).

I also modified all our existing callbacks to return bool instead of void.

Once this PR is merged, the example in #377 works, and we should do a release.