Make sure GetPrintable doesn't produce output during the call.
#3838
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
@shrit noticed that the
mlpack_knnbinding would produce strange output when loading data:You can see from the output that the first message is actually two messages being printed at the same time.
I dug into this and it is a strange artifact of how the command-line bindings work---the problem does not show up for other binding types. The issue is this:
data::Load()the first time a parameter is accessed (e.g.params.Get<arma::mat>("matrix")orparams.GetPrintable<arma::mat>("matrix")), and that call todata::Load()will produce output.GetPrintable<>is used to print a status message.GetPrintable<>is called on a matrix parameter before the data has been loaded, then thedata::Load()message will be printed while thatGetPrintable<>call happens... leading to the duplicate message.So, I found all bindings where this situation happens, and where possible I changed things around so that
GetPrintable<>was not the first call that would trigger the load of a matrix. So long as the first call is something likeparams.Get<arma::mat>("matrix"), then the load happens separately and there is no duplicate output.After this PR the output of the program command above is:
which is what we would hope for.