Deprecate the versions that return tuples.

This commit is contained in:
Ryan Curtin
2024-09-25 22:47:40 -04:00
parent defe9df2a4
commit cb95340b2a
3 changed files with 32 additions and 19 deletions
+3 -1
View File
@@ -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
+4
View File
@@ -349,6 +349,7 @@ void Split(const MatType& input,
*/
template<typename T, typename LabelsType,
typename = std::enable_if_t<arma::is_arma_type<LabelsType>::value> >
[[deprecated("Will be removed in mlpack 5.0.0; use other overloads instead")]]
std::tuple<arma::Mat<T>, arma::Mat<T>, LabelsType, LabelsType>
Split(const arma::Mat<T>& input,
const LabelsType& inputLabel,
@@ -397,6 +398,7 @@ Split(const arma::Mat<T>& input,
* and testData (arma::Mat<T>).
*/
template<typename T>
[[deprecated("Will be removed in mlpack 5.0.0; use other overloads instead")]]
std::tuple<arma::Mat<T>, arma::Mat<T>>
Split(const arma::Mat<T>& input,
const double testRatio,
@@ -553,6 +555,7 @@ template <class FieldType, typename T,
class = std::enable_if_t<
arma::is_Col<typename FieldType::object_type>::value ||
arma::is_Mat_only<typename FieldType::object_type>::value>>
[[deprecated("Will be removed in mlpack 5.0.0; use other overloads instead")]]
std::tuple<FieldType, FieldType, arma::field<T>, arma::field<T>>
Split(const FieldType& input,
const arma::field<T>& inputLabel,
@@ -600,6 +603,7 @@ template <class FieldType,
class = std::enable_if_t<
arma::is_Col<typename FieldType::object_type>::value ||
arma::is_Mat_only<typename FieldType::object_type>::value>>
[[deprecated("Will be removed in mlpack 5.0.0; use other overloads instead")]]
std::tuple<FieldType, FieldType>
Split(const FieldType& input,
const double testRatio,
@@ -156,40 +156,47 @@ void BINDING_FUNCTION(util::Params& params, util::Timers& timers)
arma::Row<size_t> labelsRow = labels.row(0);
timers.Start("splitting_data");
const auto value =
data::Split(data, labelsRow, testRatio, !shuffleData, stratifyData);
arma::mat trainData, testData;
arma::Row<size_t> 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<arma::mat>("training") = std::move(get<0>(value));
params.Get<arma::mat>("training") = std::move(trainData);
if (params.Has("test"))
params.Get<arma::mat>("test") = std::move(get<1>(value));
params.Get<arma::mat>("test") = std::move(testData);
if (params.Has("training_labels"))
params.Get<arma::Mat<size_t>>("training_labels") =
std::move(get<2>(value));
params.Get<arma::Mat<size_t>>("training_labels") = std::move(trainLabels);
if (params.Has("test_labels"))
params.Get<arma::Mat<size_t>>("test_labels") =
std::move(get<3>(value));
params.Get<arma::Mat<size_t>>("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<arma::mat>("training") = std::move(get<0>(value));
params.Get<arma::mat>("training") = std::move(trainData);
if (params.Has("test"))
params.Get<arma::mat>("test") = std::move(get<1>(value));
params.Get<arma::mat>("test") = std::move(testData);
}
}