Nonconvex constrained optimization
Loading...
Searching...
No Matches
problem-counters.cpp
Go to the documentation of this file.
2
3#include <iomanip>
4#include <iostream>
5
6namespace alpaqa {
7
8namespace {
9struct CountResult {
10 unsigned count;
11 std::chrono::nanoseconds time;
12};
13std::ostream &operator<<(std::ostream &os, const CountResult &t) {
14 auto sec = [](auto t) { return std::chrono::duration<double>(t).count(); };
15 os << std::setw(8);
16 if (t.count > 0) {
17 os << t.count << " (";
18 auto old = os.flags();
19 auto prec = os.precision(3);
20 os << std::scientific << std::setw(9) << 1e6 * sec(t.time) << " µs, "
21 << std::setw(9) << 1e6 * sec(t.time) / static_cast<double>(t.count)
22 << " µs/call)\r\n";
23 os.precision(prec);
24 os.flags(old);
25 } else {
26 os << '-' << "\r\n";
27 }
28 return os;
29}
30} // namespace
31
32#define ALPAQA_STRINGIFY(a) ALPAQA_STRINGIFY_IMPL(a)
33#define ALPAQA_STRINGIFY_IMPL(a) #a
34#define ALPAQA_PRINT_EVAL(x) \
35 do { \
36 total.count += c.x; \
37 total.time += c.time.x; \
38 os << std::setw(53) << ALPAQA_STRINGIFY(x) ":" \
39 << CountResult{c.x, c.time.x}; \
40 } while (false)
41
42std::ostream &operator<<(std::ostream &os, const EvalCounter &c) {
43 CountResult total{{}, {}};
44 ALPAQA_PRINT_EVAL(projecting_difference_constraints);
45 ALPAQA_PRINT_EVAL(projection_multipliers);
46 ALPAQA_PRINT_EVAL(proximal_gradient_step);
47 ALPAQA_PRINT_EVAL(inactive_indices_res_lna);
48 ALPAQA_PRINT_EVAL(prox_jacobian_diag);
49 ALPAQA_PRINT_EVAL(objective);
50 ALPAQA_PRINT_EVAL(objective_gradient);
51 ALPAQA_PRINT_EVAL(objective_and_gradient);
52 ALPAQA_PRINT_EVAL(objective_and_constraints);
53 ALPAQA_PRINT_EVAL(objective_gradient_and_constraints_gradient_product);
54 ALPAQA_PRINT_EVAL(constraints);
55 ALPAQA_PRINT_EVAL(constraints_gradient_product);
56 ALPAQA_PRINT_EVAL(grad_gi);
57 ALPAQA_PRINT_EVAL(constraints_jacobian);
58 ALPAQA_PRINT_EVAL(lagrangian_gradient);
59 ALPAQA_PRINT_EVAL(lagrangian_hessian_product);
60 ALPAQA_PRINT_EVAL(lagrangian_hessian);
61 ALPAQA_PRINT_EVAL(augmented_lagrangian_hessian_product);
62 ALPAQA_PRINT_EVAL(augmented_lagrangian_hessian);
63 ALPAQA_PRINT_EVAL(augmented_lagrangian);
64 ALPAQA_PRINT_EVAL(augmented_lagrangian_gradient);
65 ALPAQA_PRINT_EVAL(augmented_lagrangian_and_gradient);
66 os << "+ --------------------------------------------------:\n"
67 << std::setw(53) << "total:" << total;
68 return os;
69}
70
71} // namespace alpaqa
std::ostream & operator<<(std::ostream &os, PANOCStopCrit s)
#define ALPAQA_PRINT_EVAL(x)