2 #include <dlprim/json.hpp> 3 #include <dlprim/definitions.hpp> 7 template<
typename T,
size_t S>
8 T parse_enum(json::value
const &v,std::string
const &name,
char const *(&names)[S],T def)
10 if(v.find(name).is_undefined())
12 std::string val = v.get<std::string>(name);
13 for(
size_t i=0;i<S;i++) {
15 return static_cast<T
>(i);
17 throw ValidationError(
"Invalid value " + val +
" for filed " + name);
19 template<
typename T,
size_t S>
20 void get_1dNd_from_json(json::value
const &v,std::string
const &name,T (&vals)[S],
bool required=
false)
22 json::value
const &tmp = v.find(name);
23 if(tmp.is_undefined()) {
25 throw ValidationError(
"Missing value in json " + name);
29 T val = tmp.get_value<T>();
30 for(
size_t i=0;i<S;i++)
34 auto ar = tmp.get_value<std::vector<T> >();
36 throw ValidationError(
"Array size of filed " + name +
" must be " + std::to_string(S));
37 for(
size_t i=0;i<S;i++)
41 throw ValidationError(
"Invalid filed value for " + name);
46 return activation_from_name(v.get(
"activation",
"identity"));
array value
Definition: json.hpp:601
Mane namespace.
Definition: context.hpp:9
StandardActivations
Parameterless Activations that can be embedded to general kernels like inner product or convolution...
Definition: definitions.hpp:266
numeric value
Definition: json.hpp:598