36template <
class Rep,
class Period>
39template <
class Duration>
44 "Invalid value " +
to_string(
j) +
" for type '" +
46 std::string value =
j;
51 "Invalid value '" + value +
"' for type '" +
53 std::string(std::string_view(value.data(), e.
result.ptr)));
56 "Invalid units '" + std::string(e.units) +
"' for type '" +
61template <
class Duration>
64 namespace chr = std::chrono;
67 if (
dur.count() == 0) {
71 result += std::to_string(d.count()) +
"h";
75 result += std::to_string(d.count()) +
"min";
79 result += std::to_string(d.count()) +
"s";
83 result += std::to_string(d.count()) +
"ms";
87 result += std::to_string(d.count()) +
"µs";
91 result += std::to_string(d.count()) +
"ns";
95 s = std::move(result);
103 "' (expected an array, but got " +
104 j.type_name() +
')');
109 }
catch (json::exception &e) {
111 " (expected a number, but got " +
112 j.type_name() +
"): " + e.what());
115 std::ranges::transform(
j,
v.begin(),
convert);
122 std::ifstream f(
fpath);
128 auto r = alpaqa::csv::read_row_std_vector<real_t<config_t>>(f);
130 if (
v.expected_size >= 0 &&
r_size !=
v.expected_size)
132 "Incorrect size in '" +
fpath +
"' (expected " +
133 std::to_string(
v.expected_size) +
", but got " +
134 std::to_string(r.size()) +
")");
138 "': alpaqa::csv::read_error: " + e.what());
140 }
else if (
j.is_array()) {
142 if (
v.expected_size >= 0 &&
v.value->size() !=
v.expected_size)
144 "Incorrect size in " +
to_string(
j) +
"' (expected " +
145 std::to_string(
v.expected_size) +
", but got " +
146 std::to_string(
v.value->size()) +
')');
150 "' (expected string or array, but got " +
151 j.type_name() +
')');
165 "' (expected boolean, but got " +
166 j.type_name() +
')');
167 t =
static_cast<bool>(
j);
175 "' (expected string, but got " +
176 j.type_name() +
')');
177 t =
static_cast<std::string
>(
j);
180template <std::
integral T>
181 requires(!std::same_as<T, bool>)
183 if (std::unsigned_integral<T> && !
j.is_number_unsigned())
186 "' (expected unsigned integer, but got " +
187 j.type_name() +
')');
188 if (!
j.is_number_integer())
191 "' (expected integer, but got " +
192 j.type_name() +
')');
193 t =
static_cast<T>(
j);
196template <std::
floating_po
int T>
200 t = std::numeric_limits<T>::quiet_NaN();
201 }
else if (
j ==
"inf" ||
j ==
"+inf") {
202 t = std::numeric_limits<T>::infinity();
203 }
else if (
j ==
"-inf") {
204 t = -std::numeric_limits<T>::infinity();
209 "' (expected number or any of "
210 "\"nan\", \"inf\", \"+inf\", \"-inf\")");
212 }
else if (
j.is_number()) {
213 t =
static_cast<T>(
j);
217 "' (expected number, but got " +
218 j.type_name() +
')');
223 requires(std::integral<T> || std::same_as<T, bool> ||
224 std::same_as<T, std::string>)
229template <std::
floating_po
int T>
233 else if (t == +std::numeric_limits<T>::infinity())
235 else if (t == -std::numeric_limits<T>::infinity())
256template <
class... Ts>
258template <
class... Ts>
261#define ALPAQA_GET_PARAM_INST(...) \
262 template void ALPAQA_EXPORT get_param( \
263 const util::possible_alias_t<__VA_ARGS__> &, json &)
264#define ALPAQA_GETSET_PARAM_INST(...) \
265 template void ALPAQA_EXPORT set_param( \
266 util::possible_alias_t<__VA_ARGS__> &, const json &); \
267 template void ALPAQA_EXPORT get_param( \
268 const util::possible_alias_t<__VA_ARGS__> &, json &)
293#define ALPAQA_GETSET_PARAM_INST_INT(...) \
294 ALPAQA_GETSET_PARAM_INST(__VA_ARGS__, int8_t, uint8_t, int16_t, uint16_t, \
295 int32_t, int64_t, uint32_t, uint64_t)
308 unsigned int,
unsigned short);
std::string demangled_typename(const std::type_info &t)
Get the pretty name of the given type as a string.
Parameters for the Augmented Lagrangian solver.
Parameters for the AndersonAccel class.
Parameters for the AndersonDirection class.
Parameters for the ConvexNewtonDirection class.
Parameters for the ConvexNewtonDirection class.
Tuning parameters for the FISTA algorithm.
Parameters for the LBFGSDirection class.
Parameters for the LBFGS class.
Parameters for the estimation of the Lipschitz constant of the gradient of the smooth term of the cos...
Parameters for the NewtonTRDirection class.
Tuning parameters for the PANOC algorithm.
Tuning parameters for the PANOC algorithm.
Tuning parameters for the PANTR algorithm.
Parameters for SteihaugCG.
Parameters for the StructuredNewtonDirection class.
Parameters for the StructuredNewtonDirection class.
Tuning parameters for the ZeroFPR algorithm.
#define ALPAQA_GETSET_PARAM_INST(...)
#define ALPAQA_GETSET_PARAM_INST_INT(...)
#define ALPAQA_GET_PARAM_INST(...)
void get_param(const T &, json &j)
Get the first argument as a JSON object j.
void get_param_default(const T &t, json &j)
void set_param_default(T &t, const json &j)
constexpr bool is_duration
void set_param(T &, const json &j)
Update/overwrite the first argument based on the JSON object j.
Unused unique type tag for template specializations that were rejected because some types were not di...
void parse_duration(std::chrono::duration< Rep, Period > &t, std::string_view s)
Adds the sum of the durations in the string s to the duration t.
typename Conf::real_t real_t
typename Conf::length_t length_t
typename Conf::cmvec cmvec
LBFGSStepSize
Which method to use to select the L-BFGS step size.
Parameters for the StructuredLBFGSDirection class.
Custom parameter parsing exception.
std::from_chars_result result