15 std::floating_point
auto value,
18 int n = print(buf.data(), buf.size(), fmt, precision, value);
19 assert((
size_t)n < buf.size());
20 return {buf.data(), (size_t)n};
24template <std::
floating_po
int F>
27 int precision = std::numeric_limits<F>::max_digits10) {
28 auto begin = buf.data();
29 if (!std::signbit(value))
31 auto [end, _] = std::to_chars(begin, buf.data() + buf.size(), value,
32 std::chars_format::scientific, precision);
33 return std::string_view{buf.data(), end};
36#pragma message "Using std::snprintf as a fallback to replace std::to_chars"
38inline std::string_view
40 int precision = std::numeric_limits<double>::max_digits10) {
44inline std::string_view
46 int precision = std::numeric_limits<float>::max_digits10) {
50 auto &buf,
long double value,
51 int precision = std::numeric_limits<long double>::max_digits10) {
57#ifdef ALPAQA_WITH_QUAD_PRECISION
60 int precision = std::numeric_limits<__float128>::max_digits10) {
66template <std::
floating_po
int F>
68 std::array<char, 64> buf;
72template <std::
floating_po
int F>
77template <std::
floating_po
int F>
78void print_elem(
auto &buf, std::complex<F> value, std::ostream &os) {
84std::ostream &
print_csv_impl(std::ostream &os,
const T &M, std::string_view sep,
85 std::string_view begin, std::string_view end) {
86 std::array<char, 64> buf;
89 for (
decltype(M.rows()) r{}; r < M.rows(); ++r) {
91 if (r != M.rows() - 1)
96 for (
decltype(M.rows()) r{}; r < M.rows(); ++r) {
98 for (
decltype(M.cols()) c{}; c < M.cols(); ++c) {
100 if (c != M.cols() - 1)
111 std::string_view end) {
113 return print_csv_impl<T>(os, M,
" ",
"[",
"]") << end;
116 std::array<char, 64> buf;
117 for (
decltype(M.rows()) r{}; r < M.rows(); ++r) {
118 for (
decltype(M.cols()) c{}; c < M.cols(); ++c) {
120 if (c != M.cols() - 1)
123 if (r != M.rows() - 1)
126 return os <<
']' << end;
132 std::string_view end) {
134 return print_csv_impl<T>(os, M,
", ",
"[",
"]") << end;
137 std::array<char, 64> buf;
138 for (
decltype(M.rows()) r{}; r < M.rows(); ++r) {
139 for (
decltype(M.cols()) c{}; c < M.cols(); ++c) {
141 if (c != M.cols() - 1)
144 if (r != M.rows() - 1)
147 return os <<
"]]" << end;
std::string_view float_to_str_vw_snprintf(auto &&print, auto &buf, std::floating_point auto value, int precision, const char *fmt)
std::ostream & print_matlab_impl(std::ostream &os, const T &M, std::string_view end)
std::ostream & print_python_impl(std::ostream &os, const T &M, std::string_view end)
std::string_view float_to_str_vw(auto &buf, double value, int precision=std::numeric_limits< double >::max_digits10)
void print_elem(auto &buf, F value, std::ostream &os)
std::string float_to_str(F value, int precision)
std::ostream & print_csv_impl(std::ostream &os, const T &M, std::string_view sep, std::string_view begin, std::string_view end)