diff --git a/HISTORY.md b/HISTORY.md index 81689fcada..e527d1aa1e 100644 --- a/HISTORY.md +++ b/HISTORY.md @@ -4,8 +4,10 @@ _????-??-??_ - * Fix compilation with clang 19 (#3799) + * Fix compilation with clang 19 (#3799). + * Deprecate version of `data::Split()` that returns a `std::tuple` for + consistency; use other overloads instead (#3803). ## mlpack 4.5.0 diff --git a/src/mlpack/core/data/split_data.hpp b/src/mlpack/core/data/split_data.hpp index f11956d313..412e871d26 100644 --- a/src/mlpack/core/data/split_data.hpp +++ b/src/mlpack/core/data/split_data.hpp @@ -349,6 +349,7 @@ void Split(const MatType& input, */ template::value> > +[[deprecated("Will be removed in mlpack 5.0.0; use other overloads instead")]] std::tuple, arma::Mat, LabelsType, LabelsType> Split(const arma::Mat& input, const LabelsType& inputLabel, @@ -397,6 +398,7 @@ Split(const arma::Mat& input, * and testData (arma::Mat). */ template +[[deprecated("Will be removed in mlpack 5.0.0; use other overloads instead")]] std::tuple, arma::Mat> Split(const arma::Mat& input, const double testRatio, @@ -553,6 +555,7 @@ template ::value || arma::is_Mat_only::value>> +[[deprecated("Will be removed in mlpack 5.0.0; use other overloads instead")]] std::tuple, arma::field> Split(const FieldType& input, const arma::field& inputLabel, @@ -600,6 +603,7 @@ template ::value || arma::is_Mat_only::value>> +[[deprecated("Will be removed in mlpack 5.0.0; use other overloads instead")]] std::tuple Split(const FieldType& input, const double testRatio, diff --git a/src/mlpack/methods/preprocess/preprocess_split_main.cpp b/src/mlpack/methods/preprocess/preprocess_split_main.cpp index 4410cedb15..5f122a9572 100644 --- a/src/mlpack/methods/preprocess/preprocess_split_main.cpp +++ b/src/mlpack/methods/preprocess/preprocess_split_main.cpp @@ -156,40 +156,47 @@ void BINDING_FUNCTION(util::Params& params, util::Timers& timers) arma::Row labelsRow = labels.row(0); timers.Start("splitting_data"); - const auto value = - data::Split(data, labelsRow, testRatio, !shuffleData, stratifyData); + arma::mat trainData, testData; + arma::Row trainLabels, testLabels; + if (stratifyData) + { + data::StratifiedSplit(data, labelsRow, trainData, testData, trainLabels, + testLabels, testRatio, !shuffleData); + } + else + { + data::Split(data, labelsRow, trainData, testData, trainLabels, testLabels, + testRatio, !shuffleData); + } timers.Stop("splitting_data"); - Log::Info << "Training data contains " - << get<0>(value).n_cols << " points." << endl; - Log::Info << "Test data contains " - << get<1>(value).n_cols << " points." << endl; + Log::Info << "Training data contains " << trainData.n_cols << " points." + << endl; + Log::Info << "Test data contains " << testData.n_cols << " points." << endl; if (params.Has("training")) - params.Get("training") = std::move(get<0>(value)); + params.Get("training") = std::move(trainData); if (params.Has("test")) - params.Get("test") = std::move(get<1>(value)); + params.Get("test") = std::move(testData); if (params.Has("training_labels")) - params.Get>("training_labels") = - std::move(get<2>(value)); + params.Get>("training_labels") = std::move(trainLabels); if (params.Has("test_labels")) - params.Get>("test_labels") = - std::move(get<3>(value)); + params.Get>("test_labels") = std::move(testLabels); } else // We have no labels, so just split the dataset. { timers.Start("splitting_data"); - const auto value = data::Split(data, testRatio, !shuffleData); + arma::mat trainData, testData; + data::Split(data, trainData, testData, testRatio, !shuffleData); timers.Stop("splitting_data"); - Log::Info << "Training data contains " << get<0>(value).n_cols << " points." - << endl; - Log::Info << "Test data contains " << get<1>(value).n_cols << " points." + Log::Info << "Training data contains " << trainData.n_cols << " points." << endl; + Log::Info << "Test data contains " << testData.n_cols << " points." << endl; if (params.Has("training")) - params.Get("training") = std::move(get<0>(value)); + params.Get("training") = std::move(trainData); if (params.Has("test")) - params.Get("test") = std::move(get<1>(value)); + params.Get("test") = std::move(testData); } }