[mlpack-git] master: fix reference issue in DatasetMapper (1a908c2)
gitdub at mlpack.org
gitdub at mlpack.org
Mon Jul 25 12:19:02 EDT 2016
Repository : https://github.com/mlpack/mlpack
On branch : master
Link : https://github.com/mlpack/mlpack/compare/ecbfd24defe31d9f39708c0b4c6ad352cd46ed5c...7eec0609aa21cb12aeed3cbcaa1e411dad0359f2
>---------------------------------------------------------------
commit 1a908c2a7b014b825667da28526b30e45dfea084
Author: Keon Kim <kwk236 at gmail.com>
Date: Tue Jul 5 03:33:52 2016 +0900
fix reference issue in DatasetMapper
>---------------------------------------------------------------
1a908c2a7b014b825667da28526b30e45dfea084
src/mlpack/core/data/dataset_info.hpp | 2 +-
src/mlpack/core/data/dataset_info_impl.hpp | 4 ++--
src/mlpack/core/data/map_policies/missing_policy.hpp | 6 +++---
src/mlpack/tests/imputation_test.cpp | 20 ++++++++++----------
4 files changed, 16 insertions(+), 16 deletions(-)
diff --git a/src/mlpack/core/data/dataset_info.hpp b/src/mlpack/core/data/dataset_info.hpp
index 14f2e1c..f9aac15 100644
--- a/src/mlpack/core/data/dataset_info.hpp
+++ b/src/mlpack/core/data/dataset_info.hpp
@@ -114,7 +114,7 @@ class DatasetMapper
PolicyType& Policy();
//! Modify (Replace) the policy of the mapper with a new policy
- void Policy(PolicyType& policy);
+ void Policy(PolicyType&& policy);
private:
//! Types of each dimension.
diff --git a/src/mlpack/core/data/dataset_info_impl.hpp b/src/mlpack/core/data/dataset_info_impl.hpp
index 0f88688..d1bd1cf 100644
--- a/src/mlpack/core/data/dataset_info_impl.hpp
+++ b/src/mlpack/core/data/dataset_info_impl.hpp
@@ -126,9 +126,9 @@ inline PolicyType& DatasetMapper<PolicyType>::Policy()
}
template<typename PolicyType>
-inline void DatasetMapper<PolicyType>::Policy(PolicyType& policy)
+inline void DatasetMapper<PolicyType>::Policy(PolicyType&& policy)
{
- this->policy = std::move(policy);
+ this->policy = std::forward<PolicyType>(policy);
}
diff --git a/src/mlpack/core/data/map_policies/missing_policy.hpp b/src/mlpack/core/data/map_policies/missing_policy.hpp
index b041fe1..6b1fee9 100644
--- a/src/mlpack/core/data/map_policies/missing_policy.hpp
+++ b/src/mlpack/core/data/map_policies/missing_policy.hpp
@@ -56,16 +56,16 @@ class MissingPolicy
{
// This string does not exist yet.
size_t& numMappings = maps[dimension].second;
- numMappings++;
typedef boost::bimap<std::string, mapped_type>::value_type PairType;
maps[dimension].first.insert(PairType(string, NaN));
+
+ ++numMappings;
return NaN;
}
else
{
- // This string already exists in the mapping.
- //return maps[dimension].first.left.at(string);
+ // This string already exists in the mapping or .
return NaN;
}
}
diff --git a/src/mlpack/tests/imputation_test.cpp b/src/mlpack/tests/imputation_test.cpp
index 6f88ca2..9a37939 100644
--- a/src/mlpack/tests/imputation_test.cpp
+++ b/src/mlpack/tests/imputation_test.cpp
@@ -53,15 +53,15 @@ BOOST_AUTO_TEST_CASE(DatasetMapperImputerTest)
// Load check
// MissingPolicy should convert strings to nans
- BOOST_REQUIRE(std::isnan(output(0, 0)));
- BOOST_REQUIRE_CLOSE(output(0, 1), 5.0, 1e-5);
- BOOST_REQUIRE_CLOSE(output(0, 2), 8.0, 1e-5);
- BOOST_REQUIRE_CLOSE(output(1, 0), 2.0, 1e-5);
- BOOST_REQUIRE_CLOSE(output(1, 1), 6.0, 1e-5);
- BOOST_REQUIRE_CLOSE(output(1, 2), 9.0, 1e-5);
- BOOST_REQUIRE_CLOSE(output(2, 0), 3.0, 1e-5);
- BOOST_REQUIRE(std::isnan(output(2, 1)));
- BOOST_REQUIRE_CLOSE(output(2, 2), 10.0, 1e-5);
+ BOOST_REQUIRE(std::isnan(input(0, 0)) == true);
+ BOOST_REQUIRE_CLOSE(input(0, 1), 5.0, 1e-5);
+ BOOST_REQUIRE_CLOSE(input(0, 2), 8.0, 1e-5);
+ BOOST_REQUIRE_CLOSE(input(1, 0), 2.0, 1e-5);
+ BOOST_REQUIRE_CLOSE(input(1, 1), 6.0, 1e-5);
+ BOOST_REQUIRE_CLOSE(input(1, 2), 9.0, 1e-5);
+ BOOST_REQUIRE_CLOSE(input(2, 0), 3.0, 1e-5);
+ BOOST_REQUIRE(std::isnan(input(2, 1)) == true);
+ BOOST_REQUIRE_CLOSE(input(2, 2), 10.0, 1e-5);
Imputer<double,
DatasetMapper<MissingPolicy>,
@@ -76,7 +76,7 @@ BOOST_AUTO_TEST_CASE(DatasetMapperImputerTest)
BOOST_REQUIRE_CLOSE(output(1, 1), 6.0, 1e-5);
BOOST_REQUIRE_CLOSE(output(1, 2), 9.0, 1e-5);
BOOST_REQUIRE_CLOSE(output(2, 0), 3.0, 1e-5);
- BOOST_REQUIRE(std::isnan(output(2, 1))); // remains as NaN
+ BOOST_REQUIRE(std::isnan(output(2, 1)) == true); // remains as NaN
BOOST_REQUIRE_CLOSE(output(2, 2), 10.0, 1e-5);
// Remove the file.
More information about the mlpack-git
mailing list