Eigen 来自_json()的vectorXd?
我正在尝试使用eigen::VectorXd和nlohmann json库实现类的json序列化。将类存储为JSON字符串不是问题。如何从JSON解析VectorXd?是否有其他更适合此任务的库Eigen 来自_json()的vectorXd?,eigen,nlohmann-json,Eigen,Nlohmann Json,我正在尝试使用eigen::VectorXd和nlohmann json库实现类的json序列化。将类存储为JSON字符串不是问题。如何从JSON解析VectorXd?是否有其他更适合此任务的库 #include "json.hpp" class TransformationStep { public: VectorXd support_vector; int number; TransformationStep(int number_param, Vecto
#include "json.hpp"
class TransformationStep {
public:
VectorXd support_vector;
int number;
TransformationStep(int number_param, VectorXd support_vectorParam) {
number = number_param;
support_vector = support_vectorParam;
}
~TransformationStep() {
}
//json serialization
void to_json(nlohmann::json &j);
void from_json(const nlohmann::json &j);
};
void TransformationStep::to_json(nlohmann::json &j) {
j["number"] = number;
j["support_vector"] = support_vector;
}
void Ftf::from_json(const nlohmann::json &j)
{
number = (j.at("number").get<int>());
//support_vector = j["support_vector"].get<VectorXd>()); //???
}
我想出了
void vector_from_json(VectorXd& vector, const nlohmann::json &j) {
vector.resize(j.size());
size_t element_index=0;
for (const auto& element : j) {
vector(element_index++) = (double) element;
}
}
我想出了
void vector_from_json(VectorXd& vector, const nlohmann::json &j) {
vector.resize(j.size());
size_t element_index=0;
for (const auto& element : j) {
vector(element_index++) = (double) element;
}
}
你好,我也遇到了类似的问题。这里有一个链接可能对你有所帮助。你好,我也遇到了类似的问题。这里有一个链接可能对你有所帮助。