17#include <fmt/ostream.h>
18#include <fmt/format.h>
31 bool scientific =
false)
35 ss << std::setprecision(precision);
37 ss << std::scientific;
61 template <
class T,
int M,
int N,
int options = AutoAlign | ((M == 1 &&
N != 1) ? Eigen ::RowMajor : M != 1 ||
N == 1 ? Eigen ::ColMajor
63 int max_m = M,
int max_n =
N>
67 using Base = Matrix<T, M, N, options, max_m, max_n>;
77 template <
class T,
int M>
81 template <
class T,
int N>
94 template <
int M,
int N,
int options,
int max_m,
int max_n>
102 const bool v = is_real_eigen_fmt_safe_matrix_v<Eigen::MatrixFMTSafe<real, 3, 3>>;
109template <
typename T,
typename Char>
110struct fmt::formatter<T, Char,
111 std::enable_if_t<DNDS::Meta::is_eigen_dense_v<std::remove_cv_t<T>> ||
112 DNDS::Meta::is_real_eigen_fmt_safe_matrix_v<std::remove_cv_t<T>>>>
117 using TMat = std::remove_cv_t<T>;
123 std::string formatSpecC =
"{}";
125 auto parse(fmt::format_parse_context &ctx)
127 auto it = ctx.begin(), end = ctx.end();
128 bool afterDot =
false;
129 while (it != end && *it !=
'}')
157 if (*it >=
'0' && *it <=
'9')
161 while (it != end && *it >=
'0' && *it <=
'9')
164 precision = std::stoi(
v);
166 width = std::stoi(
v);
175 formatSpecC = fmt::format(FMT_STRING(
"{{:{0}{1}.{3}{4}}}"), align, sign, width, precision, type);
177 formatSpecC = fmt::format(FMT_STRING(
"{{:{0}{1}{2}.{3}{4}}}"), align, sign, width, precision, type);
184 buf.reserve(mat.size() * 10);
186 for (Eigen::Index
i = 0;
i < mat.rows(); ++
i)
188 for (Eigen::Index
j = 0;
j < mat.cols(); ++
j)
192 fmt::format_to(std::back_inserter(buf), formatSpecC, mat(
i,
j));
194 if (
i < mat.rows() - 1)
198 return fmt::format_to(ctx.out(),
"{}", buf);
205 template <DeviceBackend B,
typename t_scalar,
int M,
int N>
209 static_assert(M >= 0 || M == Eigen::Dynamic,
"M needs to be a valid eigen size");
210 static_assert(
N >= 0 ||
N == Eigen::Dynamic,
"N needs to be a valid eigen size");
211 using t_matrix = Eigen::Matrix<std::remove_cv_t<t_scalar>, M,
N>;
213 using t_map = std::conditional_t<std::is_const_v<t_scalar>,
237 if constexpr (M >= 0)
245 if constexpr (
N >= 0)
262 static_assert(std::is_trivially_copyable_v<EigenMatrixView<DeviceBackend::Host, real, Eigen::Dynamic, Eigen::Dynamic>>);
264 template <
typename t_scalar,
int M,
int N>
284 if constexpr (
M >= 0)
292 if constexpr (
N >= 0)
305 if constexpr (
M >= 0)
309 if constexpr (
N >= 0)
321 template <DeviceBackend B>
334 template <DeviceBackend B>
338 "data not on this backend");
345 case DeviceBackend::CUDA:
Core type aliases, constants, and metaprogramming utilities for the DNDS framework.
#define DNDS_DEVICE_TRIVIAL_COPY_DEFINE(T, T_Self)
#define DNDS_DEVICE_CALLABLE
Device memory abstraction layer with backend-specific storage and factory creation.
Pre-compiled-header style shim that includes the heavy Eigen headers under DNDSR's warning suppressio...
#define DNDS_assert_info(expr, info)
Debug-only assertion with an extra std::string info message.
#define DNDS_assert(expr)
Debug-only assertion (compiled out when DNDS_NDEBUG is defined). Prints the expression + file/line + ...
Eigen::Matrix< real, 3, 3 > m
Host-device vector types with optional GPU storage and device-side views.
std::conditional_t< std::is_const_v< t_scalar >, t_map_const, Eigen::Map< t_matrix > > t_map
DNDS_DEVICE_CALLABLE rowsize cols() const
DNDS_DEVICE_CALLABLE rowsize rows() const
DNDS_DEVICE_CALLABLE t_map_const map() const
Eigen::Map< const t_matrix > t_map_const
DNDS_DEVICE_CALLABLE t_scalar * data() const
Eigen::Matrix< std::remove_cv_t< t_scalar >, M, N > t_matrix
DNDS_DEVICE_CALLABLE t_map map()
void resize(int m, int n)
t_deviceView< B > deviceView()
Eigen::Map< t_matrix > t_map
void to_device(DeviceBackend B)
host_device_vector< t_scalar > h_data
Eigen::Matrix< t_scalar, M, N > t_matrix
EigenMatrixView< B, t_scalar, M, N > t_deviceView
the host side operators are provided as implemented
DeviceBackend
Enumerates the backends a DeviceStorage / Array can live on.
@ Unknown
Unset / sentinel.
const char * device_backend_name(DeviceBackend B)
Canonical string name for a DeviceBackend (used in log messages).
int32_t rowsize
Row-width / per-row element-count type (signed 32-bit).
std::string to_string(const Eigen::DenseBase< dir > &v, int precision=5, bool scientific=false)
Render an Eigen::DenseBase to a string via operator<<.
Eigen::Matrix wrapper that hides begin/end from fmt.
void begin()=delete
Deleted to hide range interface from fmt.
Matrix< T, M, N, options, max_m, max_n > Base
void end()=delete
Deleted to hide range interface from fmt.
Eigen::Matrix< real, 5, 1 > v
Eigen::Vector3d n(1.0, 0.0, 0.0)