alpaqa sparse
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)
49ALPAQA_PRINT_OVL(long double)
50#ifdef ALPAQA_WITH_QUAD_PRECISION
52#endif
53
54} // namespace detail
55
56#define ALPAQA_PRINT_CVT(name) \
57 template <class Derived, class... Args> \
58 std::ostream &print_##name(std::ostream &os, \
59 const Eigen::DenseBase<Derived> &M, \
60 Args &&...args) { \
61 using R = Eigen::Ref<const Eigen::MatrixX<typename Derived::Scalar>>; \
62 return detail::print_##name##_helper(os, static_cast<const R &>(M), \
63 std::forward<Args>(args)...); \
64 }
65
69
70#undef ALPAQA_PRINT_CVT
71#undef ALPAQA_PRINT_OVL
72#undef ALPAQA_PRINT_OVL_IMPL
73
74} // 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:85
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:56