From e81d7432f4ce01f39e544aa31bc2e5f7bfb81609 Mon Sep 17 00:00:00 2001 From: Ryan Curtin Date: Wed, 4 Oct 2017 15:57:09 -0400 Subject: [PATCH] Fix ShuffleData() implementation errors. --- src/mlpack/core/math/shuffle_data.hpp | 4 +++- src/mlpack/tests/math_test.cpp | 4 ++-- 2 files changed, 5 insertions(+), 3 deletions(-) diff --git a/src/mlpack/core/math/shuffle_data.hpp b/src/mlpack/core/math/shuffle_data.hpp index 1cb76a58df..22cbb824a4 100644 --- a/src/mlpack/core/math/shuffle_data.hpp +++ b/src/mlpack/core/math/shuffle_data.hpp @@ -69,7 +69,9 @@ void ShuffleData(const MatType& inputPoints, outputPoints = MatType(locations, values, inputPoints.n_rows, inputPoints.n_cols, true); - outputLabels = inputLabels.cols(ordering); + outputLabels.set_size(inputLabels.n_elem); + for (size_t i = 0; i < inputLabels.n_elem; ++i) + outputLabels[ordering[i]] = inputLabels[i]; } } // namespace math diff --git a/src/mlpack/tests/math_test.cpp b/src/mlpack/tests/math_test.cpp index b5ff5a640f..7f2a3f48d3 100644 --- a/src/mlpack/tests/math_test.cpp +++ b/src/mlpack/tests/math_test.cpp @@ -609,7 +609,7 @@ BOOST_AUTO_TEST_CASE(ShuffleTest) arma::Row counts(10, arma::fill::zeros); for (size_t i = 0; i < 10; ++i) { - BOOST_REQUIRE_EQUAL((size_t) outputData(0, i), labels[i]); + BOOST_REQUIRE_EQUAL((size_t) outputData(0, i), outputLabels[i]); BOOST_REQUIRE_SMALL(outputData(1, i), 1e-5); BOOST_REQUIRE_SMALL(outputData(2, i), 1e-5); counts[labels[i]]++; @@ -645,7 +645,7 @@ BOOST_AUTO_TEST_CASE(SparseShuffleTest) arma::Row counts(10, arma::fill::zeros); for (size_t i = 0; i < 10; ++i) { - BOOST_REQUIRE_EQUAL((size_t) outputData(0, i), labels[i]); + BOOST_REQUIRE_EQUAL((size_t) outputData(0, i), outputLabels[i]); BOOST_REQUIRE_SMALL((double) outputData(1, i), 1e-5); BOOST_REQUIRE_SMALL((double) outputData(2, i), 1e-5); counts[labels[i]]++;