1 #ifndef UMBRIDGEMODPIECE
2 #define UMBRIDGEMODPIECE
62 static const std::vector<double> EigenvectordToStdVector(
const Eigen::VectorXd& vector) {
63 const std::vector<double> vec(vector.data(), vector.data() + vector.rows());
67 double* ptr_data = &vector[0];
68 Eigen::VectorXd vec = Eigen::Map<Eigen::VectorXd, Eigen::Unaligned>(ptr_data, vector.size());
72 const double* ptr_data = &vector[0];
73 const Eigen::VectorXd vec = Eigen::Map<const Eigen::VectorXd, Eigen::Unaligned>(ptr_data, vector.size());
77 static std::vector<std::vector<double>> EigenvectordsToStdVectors(std::vector<Eigen::VectorXd>
const& inputs) {
78 std::vector<std::vector<double>> vecs(inputs.size());
79 for (
int i = 0; i < inputs.size(); i++)
80 vecs[i] = EigenvectordToStdVector(inputs[i]);
84 std::vector<std::vector<double>> vecs(inputs.size());
85 for (
int i = 0; i < inputs.size(); i++)
86 vecs[i] = EigenvectordToStdVector(inputs[i]);
90 std::vector<Eigen::VectorXd> vec(vector.size());
91 for (
int i = 0; i < vector.size(); i++) {
97 static std::vector<std::size_t> EigenvectoriToStdVector(
const Eigen::VectorXi& vector) {
98 std::vector<std::size_t> vec(vector.data(), vector.data() + vector.rows());
102 Eigen::VectorXi vec(vector.size());
103 for (
int i = 0; i < vector.size(); i++)
110 Eigen::VectorXi
read_input_size(
const std::string host, std::string
name,
const httplib::Headers& headers);
112 Eigen::VectorXi
read_output_size(
const std::string host, std::string
name,
const httplib::Headers& headers);
119 Eigen::VectorXd
const& sens)
override;
124 Eigen::VectorXd
const& vec)
override;
130 Eigen::VectorXd
const& sens,
131 Eigen::VectorXd
const& vec)
override;
Provides an abstract interface for defining vector-valued model components.
A ModPiece connecting to a model via the UM-Bridge HTTP protocol.
void GradientImpl(unsigned int outWrt, unsigned int inWrt, muq::Modeling::ref_vector< Eigen::VectorXd > const &inputs, Eigen::VectorXd const &sens) override
Eigen::VectorXi read_input_size(const std::string host, std::string name, const httplib::Headers &headers)
static Eigen::VectorXd StdVectorToEigenvectord(std::vector< double > &vector)
UMBridgeModPiece(const std::string host, std::string name, json config=json(), httplib::Headers headers=httplib::Headers())
Construct UMBridgeModPiece, connecting to model server.
void ApplyJacobianImpl(unsigned int outWrt, unsigned int inWrt, muq::Modeling::ref_vector< Eigen::VectorXd > const &inputs, Eigen::VectorXd const &vec) override
void EvaluateImpl(muq::Modeling::ref_vector< Eigen::VectorXd > const &inputs) override
umbridge::HTTPModel client
static std::vector< Eigen::VectorXd > StdVectorsToEigenvectords(std::vector< std::vector< double >> vector)
void ApplyHessianImpl(unsigned int outWrt, unsigned int inWrt1, unsigned int inWrt2, muq::Modeling::ref_vector< Eigen::VectorXd > const &inputs, Eigen::VectorXd const &sens, Eigen::VectorXd const &vec) override
Eigen::VectorXi read_output_size(const std::string host, std::string name, const httplib::Headers &headers)
static const Eigen::VectorXd StdVectorToEigenvectord(const std::vector< double > &vector)
static Eigen::VectorXi StdVectorToEigenvectori(const std::vector< std::size_t > &vector)
std::string name
A unique name for this WorkPiece. Defaults to <ClassName>_<id>
a class to store JSON values
std::vector< std::reference_wrapper< const T > > ref_vector
A vector of references to something ...