summaryrefslogtreecommitdiff
path: root/src/utilities.cc
diff options
context:
space:
mode:
authorCedric Nugteren <web@cedricnugteren.nl>2016-05-24 14:06:16 +0200
committerCedric Nugteren <web@cedricnugteren.nl>2016-05-24 14:06:16 +0200
commitac1575056e0f3d7406cc7bcbbdbe71b08feb58ce (patch)
treeba5fe26db8342969b684a900841218e2ab64018e /src/utilities.cc
parentae7d705d6fcf00ff11bed774df1741e5f65424de (diff)
Added proper argument handling and displaying for half-precision data-types
Diffstat (limited to 'src/utilities.cc')
-rw-r--r--src/utilities.cc15
1 files changed, 10 insertions, 5 deletions
diff --git a/src/utilities.cc b/src/utilities.cc
index 477f4a5f..1a7c8e45 100644
--- a/src/utilities.cc
+++ b/src/utilities.cc
@@ -79,7 +79,6 @@ std::string ToString(T value) {
}
template std::string ToString<int>(int value);
template std::string ToString<size_t>(size_t value);
-template std::string ToString<half>(half value);
template std::string ToString<float>(float value);
template std::string ToString<double>(double value);
@@ -99,6 +98,12 @@ std::string ToString(double2 value) {
return real.str()+"+"+imag.str()+"i";
}
+// If not possible directly: special case for half-precision
+template <>
+std::string ToString(half value) {
+ return std::to_string(HalfToFloat(value));
+}
+
// If not possible directly: special cases for CLBlast data-types
template <>
std::string ToString(Layout value) {
@@ -157,7 +162,7 @@ T ConvertArgument(const char* value) {
return static_cast<T>(std::stoi(value));
}
template <> half ConvertArgument(const char* value) {
- return static_cast<half>(std::stod(value));
+ return FloatToHalf(static_cast<float>(std::stod(value)));
}
template <> float ConvertArgument(const char* value) {
return static_cast<float>(std::stod(value));
@@ -285,11 +290,11 @@ void PopulateVector(std::vector<double2> &vector) {
// Specialized versions of the above for half-precision
template <>
void PopulateVector(std::vector<half> &vector) {
- auto lower_limit = static_cast<float>(kTestDataLowerLimit);
- auto upper_limit = static_cast<float>(kTestDataUpperLimit);
+ const auto lower_limit = static_cast<float>(kTestDataLowerLimit);
+ const auto upper_limit = static_cast<float>(kTestDataUpperLimit);
std::mt19937 mt(GetRandomSeed());
std::uniform_real_distribution<float> dist(lower_limit, upper_limit);
- for (auto &element: vector) { element = static_cast<half>(dist(mt)); }
+ for (auto &element: vector) { element = FloatToHalf(dist(mt)); }
}
// =================================================================================================