6#define JSON_ASSERT DNDS_assert
7#include <nlohmann/json.hpp>
33 ret.resize(arr.size());
34 for (
int i = 0; i < ret.size(); i++)
35 ret(i) = arr.at(i).get<
double>();
41 return Eigen::VectorXd{0};
54 ret.resize(arr.size());
55 for (
int i = 0; i < ret.size(); i++)
56 ret(i) = arr.at(i).get<
double>();
71 for (
size_t i = 0; i < ve.size(); i++)
73 return nlohmann::json(
v);
81 for (
size_t i = 0; i < ve.size(); i++)
83 return nlohmann::json(
v);
98#define __DNDS__json_to_config(name) \
103 ((name) = jsonObj.at(#name).template get<decltype(name)>()); \
105 catch (const std::exception &v) \
107 std::cerr << v.what() << std::endl; \
108 DNDS_assert_info(false, #name); \
111 (jsonObj[#name] = (name)); \
118#define DNDS_NLOHMANN_DEFINE_TYPE_INTRUSIVE_WITH_ORDERED_JSON(Type, ...) \
119 friend void to_json(nlohmann::ordered_json &nlohmann_json_j, const Type &nlohmann_json_t) { NLOHMANN_JSON_EXPAND(NLOHMANN_JSON_PASTE(NLOHMANN_JSON_TO, __VA_ARGS__)) } \
120 friend void from_json(const nlohmann::ordered_json &nlohmann_json_j, Type &nlohmann_json_t) { NLOHMANN_JSON_EXPAND(NLOHMANN_JSON_PASTE(NLOHMANN_JSON_FROM, __VA_ARGS__)) }
125#define DNDS_NLOHMANN_DEFINE_TYPE_INTRUSIVE_WITH_ORDERED_AND_UNORDERED_JSON(Type, ...) \
126 friend void to_json(nlohmann::ordered_json &nlohmann_json_j, const Type &nlohmann_json_t) { NLOHMANN_JSON_EXPAND(NLOHMANN_JSON_PASTE(NLOHMANN_JSON_TO, __VA_ARGS__)) } \
127 friend void from_json(const nlohmann::ordered_json &nlohmann_json_j, Type &nlohmann_json_t) { NLOHMANN_JSON_EXPAND(NLOHMANN_JSON_PASTE(NLOHMANN_JSON_FROM, __VA_ARGS__)) } \
128 friend void to_json(nlohmann::json &nlohmann_json_j, const Type &nlohmann_json_t) { NLOHMANN_JSON_EXPAND(NLOHMANN_JSON_PASTE(NLOHMANN_JSON_TO, __VA_ARGS__)) } \
129 friend void from_json(const nlohmann::json &nlohmann_json_j, Type &nlohmann_json_t) { NLOHMANN_JSON_EXPAND(NLOHMANN_JSON_PASTE(NLOHMANN_JSON_FROM, __VA_ARGS__)) }
134 inline void to_json(nlohmann::json &j,
const VectorXd &
v)
144 inline void to_json(nlohmann::ordered_json &j,
const VectorXd &
v)
149 inline void from_json(
const nlohmann::ordered_json &j, VectorXd &
v)
164 inline void to_json(nlohmann::ordered_json &j,
const Vector3d &
v)
169 inline void from_json(
const nlohmann::ordered_json &j, Vector3d &
v)
179 std::vector<real> v_vec = (std::vector<real>)(
v);
185 std::vector<real> v_vec = j;
Core type aliases, constants, and metaprogramming utilities for the DNDS framework.
Device memory abstraction layer with backend-specific storage and factory creation.
Eigen extensions: to_string, an fmt-safe wrapper, and fmt formatter specialisations for dense Eigen m...
#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.
Host + optional device vector of trivially copyable T.
the host side operators are provided as implemented
auto EigenVectorFMTSafeGetJson(const Eigen::VectorFMTSafe< real, -1 > &ve)
Dump an Eigen::VectorFMTSafe into a JSON array of doubles.
Eigen::VectorXd JsonGetEigenVector(const nlohmann::json &arr)
Parse a JSON array into an Eigen::VectorXd. Throws a descriptive assertion on any JSON error.
void from_json(const nlohmann::ordered_json &j, host_device_vector< real > &v)
double real
Canonical floating-point scalar used throughout DNDSR (double precision).
nlohmann::ordered_json t_jsonconfig
Project-wide JSON type alias: nlohmann/json with ordered keys.
void to_json(nlohmann::ordered_json &j, const host_device_vector< real > &v)
Eigen::VectorFMTSafe< real, -1 > JsonGetEigenVectorFMTSafe(const nlohmann::json &arr)
Parse a JSON array into an Eigen::VectorFMTSafe (fixed-point-aware wrapper).
auto EigenVectorGetJson(const Eigen::VectorXd &ve)
Dump an Eigen::VectorXd into a JSON array of doubles.
void from_json(const nlohmann::json &j, VectorXd &v)
void to_json(nlohmann::json &j, const VectorXd &v)
Eigen::Matrix wrapper that hides begin/end from fmt.
Eigen::Matrix< real, 5, 1 > v