alpaqa 1.0.0a16
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#include <utility>
11
12#include <Eigen/Core>
13
14namespace alpaqa {
15
16template <std::floating_point F>
17ALPAQA_EXPORT std::string
18float_to_str(F value, int precision = std::numeric_limits<F>::max_digits10);
19
20namespace detail {
21
22template <class T>
23ALPAQA_EXPORT std::ostream &
24print_csv_impl(std::ostream &os, const T &M, std::string_view sep = ",",
25 std::string_view begin = "", std::string_view end = "\n");
26
27template <class T>
28ALPAQA_EXPORT std::ostream &print_matlab_impl(std::ostream &os, const T &M,
29 std::string_view end = ";\n");
30
31template <class T>
32ALPAQA_EXPORT std::ostream &print_python_impl(std::ostream &os, const T &M,
33 std::string_view end = "\n");
34
35#define ALPAQA_PRINT_OVL_IMPL(name, type) \
36 template <class... Args> \
37 std::ostream &print_##name##_helper( \
38 std::ostream &os, const Eigen::Ref<const Eigen::MatrixX<type>> &M, \
39 Args &&...args) { \
40 return print_##name##_impl(os, M, std::forward<Args>(args)...); \
41 }
42#define ALPAQA_PRINT_OVL(type) \
43 ALPAQA_PRINT_OVL_IMPL(csv, type) \
44 ALPAQA_PRINT_OVL_IMPL(matlab, type) \
45 ALPAQA_PRINT_OVL_IMPL(python, type)
50ALPAQA_PRINT_OVL(long double)
51#ifdef ALPAQA_WITH_QUAD_PRECISION
53#endif
54
55} // namespace detail
56
57#define ALPAQA_PRINT_CVT(name) \
58 template <class Derived, class... Args> \
59 std::ostream &print_##name(std::ostream &os, \
60 const Eigen::DenseBase<Derived> &M, \
61 Args &&...args) { \
62 using R = Eigen::Ref<const Eigen::MatrixX<typename Derived::Scalar>>; \
63 return detail::print_##name##_helper(os, static_cast<const R &>(M), \
64 std::forward<Args>(args)...); \
65 }
66
70
71#undef ALPAQA_PRINT_CVT
72#undef ALPAQA_PRINT_OVL
73#undef ALPAQA_PRINT_OVL_IMPL
74
75} // namespace alpaqa
std::ostream & print_matlab_impl(std::ostream &os, const T &M, std::string_view end)
Definition print.tpp:117
std::ostream & print_python_impl(std::ostream &os, const T &M, std::string_view end)
Definition print.tpp:138
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:91
constexpr const auto inf
Definition config.hpp:98
std::string float_to_str(F value, int precision)
Definition print.tpp:67
#define ALPAQA_PRINT_OVL(type)
Definition print.hpp:42
#define ALPAQA_PRINT_CVT(name)
Definition print.hpp:57