From fad498cae06cebbe5a21e2ea768a2fd0d38ce722 Mon Sep 17 00:00:00 2001 From: Ryan Curtin Date: Mon, 6 Apr 2020 16:34:20 -0400 Subject: [PATCH] Add a test case. --- src/mlpack/tests/logistic_regression_test.cpp | 21 +++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/src/mlpack/tests/logistic_regression_test.cpp b/src/mlpack/tests/logistic_regression_test.cpp index d603004a28..f3bbe6b32d 100644 --- a/src/mlpack/tests/logistic_regression_test.cpp +++ b/src/mlpack/tests/logistic_regression_test.cpp @@ -1002,4 +1002,25 @@ BOOST_AUTO_TEST_CASE(LogisticRegressionTrainReturnObjective) BOOST_REQUIRE_EQUAL(std::isfinite(objVal), true); } +/** + * Test that construction *then* training works fine. Thanks @Trento89 for the + * test case (see #2358). + */ +BOOST_AUTO_TEST_CASE(ConstructionThenTraining) +{ + arma::mat myMatrix; + + // Four points, three dimensions. + myMatrix << 0.555950 << 0.274690 << 0.540605 << 0.798938 << arma::endr + << 0.948014 << 0.973234 << 0.216504 << 0.883152 << arma::endr + << 0.023787 << 0.675382 << 0.231751 << 0.450332 << arma::endr; + + arma::Row myTargets("1 0 1 0"); + + regression::LogisticRegression<> lr; + + // Make sure that training doesn't crash with invalid parameter sizes. + BOOST_REQUIRE_NO_THROW(lr.Train(myMatrix, myTargets)); +} + BOOST_AUTO_TEST_SUITE_END();