alpaqa pantr
Nonconvex constrained optimization
Loading...
Searching...
No Matches
print.hpp
Go to the documentation of this file.
1#pragma once
2
3#include <alpaqa/export.hpp>
5
6#include <iosfwd>
7#include <limits>
8#include <string>
9
10#include <Eigen/Core>
11
12namespace alpaqa {
13
14template <std::floating_point F>
15ALPAQA_EXPORT std::string
16float_to_str(F value, int precision = std::numeric_limits<F>::max_digits10);
17
18template <class T>
19ALPAQA_EXPORT std::ostream &
20print_csv_impl(std::ostream &os, const T &M, std::string_view sep = ",",
21 std::string_view begin = "", std::string_view end = "\n");
22
23template <class T>
24ALPAQA_EXPORT std::ostream &print_matlab_impl(std::ostream &os, const T &M,
25 std::string_view end = ";\n");
26
27template <class T>
28ALPAQA_EXPORT std::ostream &print_python_impl(std::ostream &os, const T &M,
29 std::string_view end = "\n");
30
31#define ALPAQA_PRINT_CSV_OVL_IMPL(type) \
32 inline std::ostream &print_csv( \
33 std::ostream &os, const Eigen::Ref<const Eigen::MatrixX<type>> &M, \
34 std::string_view sep, std::string_view begin, std::string_view end) { \
35 return print_csv_impl(os, M, sep, begin, end); \
36 } \
37 inline std::ostream &print_csv( \
38 std::ostream &os, const Eigen::Ref<const Eigen::MatrixX<type>> &M, \
39 std::string_view sep, std::string_view begin) { \
40 return print_csv_impl(os, M, sep, begin); \
41 } \
42 inline std::ostream &print_csv( \
43 std::ostream &os, const Eigen::Ref<const Eigen::MatrixX<type>> &M, \
44 std::string_view sep) { \
45 return print_csv_impl(os, M, sep); \
46 } \
47 inline std::ostream &print_csv( \
48 std::ostream &os, const Eigen::Ref<const Eigen::MatrixX<type>> &M) { \
49 return print_csv_impl(os, M); \
50 }
51#define ALPAQA_PRINT_OVL_IMPL(name, type) \
52 inline std::ostream &print_##name( \
53 std::ostream &os, const Eigen::Ref<const Eigen::MatrixX<type>> &M, \
54 std::string_view end) { \
55 return print_##name##_impl(os, M, end); \
56 } \
57 inline std::ostream &print_##name( \
58 std::ostream &os, const Eigen::Ref<const Eigen::MatrixX<type>> &M) { \
59 return print_##name##_impl(os, M); \
60 }
61#define ALPAQA_PRINT_OVL(type) \
62 ALPAQA_PRINT_CSV_OVL_IMPL(type) \
63 ALPAQA_PRINT_OVL_IMPL(matlab, type) \
64 ALPAQA_PRINT_OVL_IMPL(python, type)
65
68ALPAQA_PRINT_OVL(long double)
69#ifdef ALPAQA_WITH_QUAD_PRECISION
70ALPAQA_PRINT_OVL(__float128)
71#endif
72
73#undef ALPAQA_PRINT_OVL
74#undef ALPAQA_PRINT_OVL_IMPL
75#undef ALPAQA_PRINT_CSV_OVL_IMPL
76
77} // namespace alpaqa
std::ostream & print_matlab_impl(std::ostream &os, const T &M, std::string_view end)
Definition: print.tpp:109
std::ostream & print_python_impl(std::ostream &os, const T &M, std::string_view end)
Definition: print.tpp:129
std::string float_to_str(F value, int precision)
Definition: print.tpp:66
std::ostream & print_csv_impl(std::ostream &os, const T &M, std::string_view sep, std::string_view begin, std::string_view end)
Definition: print.tpp:83
#define ALPAQA_PRINT_OVL(type)
Definition: print.hpp:61