4#include <guanaqo/duration-parse.hpp>
5#include <guanaqo/from_chars-wrapper.hpp>
6#include <guanaqo/io/csv.hpp>
7#include <guanaqo/possible-alias.hpp>
25#include <guanaqo/dl-flags.hpp>
34 throw std::invalid_argument(
"Cannot set value of std::monostate");
45 throw std::invalid_argument(
46 "Invalid value '" + std::string(s.
value) +
47 "' for type 'bool' in '" + std::string(s.
full_key) +
49 "possible values are: '0', '1', 'true', 'false'");
65 requires((std::floating_point<T> || std::integral<T>) &&
66 !std::is_enum_v<T> && !std::is_same_v<T, bool>)
69 const auto *val_end = s.
value.data() + s.
value.size();
70 auto res = guanaqo::from_chars(s.
value.data(), val_end, f);
71 if (res.ec != std::errc())
72 throw std::invalid_argument(
73 "Invalid value '" + std::string(s.
value) +
"' for type '" +
74 guanaqo::demangled_typename(
typeid(T)) +
"' in '" +
76 "': " + std::make_error_code(res.ec).message());
77 if (res.ptr != val_end)
78 throw std::invalid_argument(
79 "Invalid suffix '" + std::string(res.ptr, val_end) +
80 "' for type '" + guanaqo::demangled_typename(
typeid(T)) +
"' in '" +
84#ifdef ALPAQA_WITH_QUAD_PRECISION
89 f =
static_cast<__float128
>(ld);
95 v.resize(std::count(s.
value.begin(), s.
value.end(),
',') + 1);
96 std::string_view value, remainder = s.
value;
98 std::tie(value, remainder) =
split_key(remainder,
',');
106 if (s.
value.starts_with(
'@')) {
107 std::string fpath{s.
value.substr(1)};
108 std::ifstream f(fpath);
110 throw std::invalid_argument(
"Unable to open file '" + fpath +
111 "' in '" + std::string(s.
full_key) +
114 auto r = guanaqo::io::csv_read_row_std_vector<real_t<config_t>>(f);
117 throw std::invalid_argument(
118 "Incorrect size in '" + std::string(s.
full_key) +
120 ", but got " + std::to_string(r.size()) +
')');
122 }
catch (guanaqo::io::csv_read_error &e) {
123 throw std::invalid_argument(
124 "Unable to read from file '" + fpath +
"' in '" +
126 "': alpaqa::csv::read_error: " + e.what());
131 throw std::invalid_argument(
132 "Incorrect size in '" + std::string(s.
full_key) +
134 ", but got " + std::to_string(v.
value->size()) +
')');
140template <
class Rep,
class Period>
143template <
class Duration>
148 guanaqo::parse_duration(t = {}, s.
value);
149 }
catch (guanaqo::invalid_duration_value &e) {
151 "Invalid value '" + std::string(s.
value) +
"' for type '" +
152 guanaqo::demangled_typename(
typeid(Duration)) +
"': error at '" +
153 std::string(std::string_view(s.
value.data(), e.result.ptr)));
154 }
catch (guanaqo::invalid_duration_units &e) {
155 throw invalid_param(
"Invalid units '" + std::string(e.units) +
157 guanaqo::demangled_typename(
typeid(Duration)) +
158 "' in '" + std::string(s.
value) +
"'");
173template <
class... Ts>
176#define ALPAQA_SET_PARAM_INST(...) \
177 template void ALPAQA_EXPORT set_param( \
178 guanaqo::possible_alias_t<__VA_ARGS__> &, ParamString)
199#define ALPAQA_SET_PARAM_INST_INT(...) \
200 ALPAQA_SET_PARAM_INST(__VA_ARGS__, int8_t, uint8_t, int16_t, uint16_t, \
201 int32_t, int64_t, uint32_t, uint64_t)
214 unsigned int,
unsigned short);
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 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.
void set_param_default(T &t, const json &j)
constexpr bool is_duration
void assert_key_empty(ParamString s)
Throw a meaningful error when s.key is not empty, to indicate that the given type T is not of struct ...
std::string_view full_key
Full key string, used for diagnostics.
auto split_key(std::string_view full, char tok='.')
Split the string full on the first occurrence of tok.
void set_param(T &, const json &j)
Update/overwrite the first argument based on the JSON object j.
std::optional< vec > value
std::string_view value
The value of the parameter to store.
Represents a parameter value encoded as a string in the format abc.def.key=value.
typename Conf::length_t length_t
typename Conf::cmvec cmvec
LBFGSStepSize
Which method to use to select the L-BFGS step size.
#define ALPAQA_SET_PARAM_INST(...)
#define ALPAQA_SET_PARAM_INST_INT(...)
Parameters for the StructuredLBFGSDirection class.
Custom parameter parsing exception.