17#include <fmt/ostream.h>
18#include <fmt/format.h>
31 bool scientific =
false)
35 ss << std::setprecision(precision);
37 ss << std::scientific;
58 template <
class T,
int M,
int N,
int options = AutoAlign | ((M == 1 &&
N != 1) ? Eigen ::RowMajor : !(M == 1 &&
N != 1) ? Eigen ::ColMajor
60 int max_m = M,
int max_n =
N>
63 using Base = Matrix<T, M, N, options, max_m, max_n>;
73 template <
class T,
int M>
77 template <
class T,
int N>
90 template <
int M,
int N,
int options,
int max_m,
int max_n>
98 const bool v = is_real_eigen_fmt_safe_matrix_v<Eigen::MatrixFMTSafe<real, 3, 3>>;
105template <
typename T,
typename Char>
106struct fmt::formatter<T, Char,
107 std::enable_if_t<DNDS::Meta::is_eigen_dense_v<std::remove_cv_t<T>> ||
108 DNDS::Meta::is_real_eigen_fmt_safe_matrix_v<std::remove_cv_t<T>>>>
113 using TMat = std::remove_cv_t<T>;
119 std::string formatSpecC =
"{}";
121 auto parse(fmt::format_parse_context &ctx)
123 auto it = ctx.begin(), end = ctx.end();
124 bool afterDot =
false;
125 while (it != end && *it !=
'}')
153 if (*it >=
'0' && *it <=
'9')
157 while (it != end && *it >=
'0' && *it <=
'9')
160 precision = std::stoi(
v);
162 width = std::stoi(
v);
171 formatSpecC = fmt::format(FMT_STRING(
"{{:{0}{1}.{3}{4}}}"), align, sign, width, precision, type);
173 formatSpecC = fmt::format(FMT_STRING(
"{{:{0}{1}{2}.{3}{4}}}"), align, sign, width, precision, type);
180 buf.reserve(mat.size() * 10);
182 for (Eigen::Index i = 0; i < mat.rows(); ++i)
184 for (Eigen::Index j = 0; j < mat.cols(); ++j)
188 fmt::format_to(std::back_inserter(buf), formatSpecC, mat(i, j));
190 if (i < mat.rows() - 1)
194 return fmt::format_to(ctx.out(),
"{}", buf);
201 template <DeviceBackend B,
typename t_scalar,
int M,
int N>
205 static_assert(M >= 0 || M == Eigen::Dynamic,
"M needs to be a valid eigen size");
206 static_assert(
N >= 0 ||
N == Eigen::Dynamic,
"N needs to be a valid eigen size");
207 using t_matrix = Eigen::Matrix<std::remove_cv_t<t_scalar>, M,
N>;
209 using t_map = std::conditional_t<std::is_const_v<t_scalar>,
233 if constexpr (M >= 0)
241 if constexpr (
N >= 0)
258 static_assert(std::is_trivially_copyable_v<EigenMatrixView<DeviceBackend::Host, real, Eigen::Dynamic, Eigen::Dynamic>>);
260 template <
typename t_scalar,
int M,
int N>
280 if constexpr (
M >= 0)
288 if constexpr (
N >= 0)
301 if constexpr (
M >= 0)
305 if constexpr (
N >= 0)
317 template <DeviceBackend B>
330 template <DeviceBackend B>
334 "data not on this backend");
341 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 + ...
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)