18#include <unordered_map>
30 using std::runtime_error::runtime_error;
38 const std::string & value) {
39 std::vector<std::string> names;
40 for (
const auto &
entry : options) names.push_back(
entry.first);
41 std::sort(names.begin(), names.end());
43 for (
const auto & name : names)
list += (
list.empty() ?
"" :
", ") + name;
44 return InputError(key +
" = \"" + value +
"\" is not one of: " +
list +
".");
53inline rtype as_real(
const toml::value & v,
const std::string & key) {
54 if (v.is_floating())
return static_cast<rtype>(v.as_floating());
55 if (v.is_integer())
return static_cast<rtype>(v.as_integer());
56 throw InputError(toml::format_error(key +
" must be a number", v,
"here"));
60inline double as_double(
const toml::value & v,
const std::string & key) {
61 if (v.is_floating())
return v.as_floating();
62 if (v.is_integer())
return static_cast<double>(v.as_integer());
63 throw InputError(toml::format_error(key +
" must be a number", v,
"here"));
66inline double find_double(
const toml::value & v,
const std::string & key) {
67 if (!v.contains(key))
throw InputError(
"missing " + key +
".");
76 if (!v.contains(key))
throw InputError(
"missing " + key +
".");
80inline rtype find_real(
const toml::value & v,
const std::string & table,
const std::string & key) {
81 if (!v.contains(table))
throw InputError(
"missing [" + table +
"].");
82 if (!v.at(table).contains(key))
throw InputError(
"missing " + table +
"." + key +
".");
83 return as_real(v.at(table).at(key), table +
"." + key);
90inline rtype find_real_or(
const toml::value & v,
const std::string & table,
const std::string & key,
92 if (!v.contains(table) || !v.at(table).contains(key))
return fallback;
93 return as_real(v.at(table).at(key), table +
"." + key);
96inline std::vector<rtype>
find_real_vector(
const toml::value & v,
const std::string & key) {
97 if (!v.contains(key))
throw InputError(
"missing " + key +
".");
98 std::vector<rtype>
out;
99 for (
const auto & item : v.at(key).as_array())
out.push_back(
as_real(item, key));
103inline std::vector<rtype>
find_real_vector(
const toml::value & v,
const std::string & table,
const std::string & key) {
104 if (!v.contains(table))
throw InputError(
"missing [" + table +
"].");
105 if (!v.at(table).contains(key))
throw InputError(
"missing " + table +
"." + key +
".");
106 std::vector<rtype>
out;
107 for (
const auto & item : v.at(table).at(key).as_array())
out.push_back(
as_real(item, table +
"." + key));
KOKKOS_INLINE_FUNCTION rtype dot(const rtype *a, const rtype *b)
Compute the dot product of two arrays.
Definition common_math.h:32
Typedefs for common types.
float rtype
Definition common_typedef.h:39
TableBatchT< Space > out
Definition teno_setup.cpp:681