alpaqa 1.0.0a8
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#include <string_view>
10
11#include <Eigen/Core>
12
13namespace alpaqa {
14
15template <std::floating_point F>
16ALPAQA_EXPORT std::string
17float_to_str(F value, int precision = std::numeric_limits<F>::max_digits10);
18
19template <class T>
20ALPAQA_EXPORT std::ostream &
21print_csv_impl(std::ostream &os, const T &M, std::string_view sep = ",",
22 std::string_view begin = "", std::string_view end = "\n");
23
24template <class T>
25ALPAQA_EXPORT std::ostream &print_matlab_impl(std::ostream &os, const T &M,
26 std::string_view end = ";\n");
27
28template <class T>
29ALPAQA_EXPORT std::ostream &print_python_impl(std::ostream &os, const T &M,
30 std::string_view end = "\n");
31
32#define ALPAQA_PRINT_CSV_OVL_IMPL(type) \
33 inline std::ostream &print_csv( \
34 std::ostream &os, const Eigen::Ref<const Eigen::MatrixX<type>> &M, \
35 std::string_view sep, std::string_view begin, std::string_view end) { \
36 return print_csv_impl(os, M, sep, begin, end); \
37 } \
38 inline std::ostream &print_csv( \
39 std::ostream &os, const Eigen::Ref<const Eigen::MatrixX<type>> &M, \
40 std::string_view sep, std::string_view begin) { \
41 return print_csv_impl(os, M, sep, begin); \
42 } \
43 inline std::ostream &print_csv( \
44 std::ostream &os, const Eigen::Ref<const Eigen::MatrixX<type>> &M, \
45 std::string_view sep) { \
46 return print_csv_impl(os, M, sep); \
47 } \
48 inline std::ostream &print_csv( \
49 std::ostream &os, const Eigen::Ref<const Eigen::MatrixX<type>> &M) { \
50 return print_csv_impl(os, M); \
51 }
52#define ALPAQA_PRINT_OVL_IMPL(name, type) \
53 inline std::ostream &print_##name( \
54 std::ostream &os, const Eigen::Ref<const Eigen::MatrixX<type>> &M, \
55 std::string_view end) { \
56 return print_##name##_impl(os, M, end); \
57 } \
58 inline std::ostream &print_##name( \
59 std::ostream &os, const Eigen::Ref<const Eigen::MatrixX<type>> &M) { \
60 return print_##name##_impl(os, M); \
61 }
62#define ALPAQA_PRINT_OVL(type) \
63 ALPAQA_PRINT_CSV_OVL_IMPL(type) \
64 ALPAQA_PRINT_OVL_IMPL(matlab, type) \
65 ALPAQA_PRINT_OVL_IMPL(python, type)
66
69ALPAQA_PRINT_OVL(long double)
70#ifdef ALPAQA_WITH_QUAD_PRECISION
71ALPAQA_PRINT_OVL(__float128)
72#endif
73
74#undef ALPAQA_PRINT_OVL
75#undef ALPAQA_PRINT_OVL_IMPL
76#undef ALPAQA_PRINT_CSV_OVL_IMPL
77
78} // namespace alpaqa
std::ostream & print_matlab_impl(std::ostream &os, const T &M, std::string_view end)
Definition: print.tpp:110
std::ostream & print_python_impl(std::ostream &os, const T &M, std::string_view end)
Definition: print.tpp:131
std::string float_to_str(F value, int precision)
Definition: print.tpp:67
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:84
#define ALPAQA_PRINT_OVL(type)
Definition: print.hpp:62