From 26d3a57782205e41736fbcd64aea25d70cfab107 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ricardo=20Monta=C3=B1ana=20G=C3=B3mez?= Date: Sun, 19 Nov 2023 23:02:28 +0100 Subject: [PATCH] Add info to invalid hyperparameter exception --- src/Platform/HyperParameters.cc | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/src/Platform/HyperParameters.cc b/src/Platform/HyperParameters.cc index c7d8bcd..3875fe6 100644 --- a/src/Platform/HyperParameters.cc +++ b/src/Platform/HyperParameters.cc @@ -1,5 +1,6 @@ #include "HyperParameters.h" #include +#include #include namespace platform { @@ -10,6 +11,14 @@ namespace platform { hyperparameters[item] = hyperparameters_; } } + // https://www.techiedelight.com/implode-a-vector-of-strings-into-a-comma-separated-string-in-cpp/ + std::string join(std::vector const& strings, std::string delim) + { + std::stringstream ss; + std::copy(strings.begin(), strings.end(), + std::ostream_iterator(ss, delim.c_str())); + return ss.str(); + } HyperParameters::HyperParameters(const std::vector& datasets, const std::string& hyperparameters_file) { // Check if file exists @@ -34,7 +43,8 @@ namespace platform { json result = hyperparameters.at(fileName); for (const auto& item : result.items()) { if (find(valid.begin(), valid.end(), item.key()) == valid.end()) { - throw std::invalid_argument("Hyperparameter " + item.key() + " is not valid. Passed Hyperparameters are: " + result.dump(4)); + throw std::invalid_argument("Hyperparameter " + item.key() + " is not valid. Passed Hyperparameters are: " + + result.dump(4) + "\n Valid hyperparameters are: {" + join(valid, ",") + "}"); } } }