Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added PassMetaInfo method in MLRunner.h #9

Closed
wants to merge 11 commits into from
33 changes: 33 additions & 0 deletions include/MLModelRunner/MLModelRunner.h
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@
#include "SerDes/jsonSerDes.h"

#include <cstdlib>
#include <fstream>
#include <future>
#include <memory>
#include <string>
Expand All @@ -55,6 +56,7 @@ namespace MLBridge {
/// MLModelRunner - The main interface for interacting with the ML models.
class MLModelRunner {
public:
std::ofstream of;
// Disallows copy and assign.
MLModelRunner(const MLModelRunner &) = delete;
MLModelRunner &operator=(const MLModelRunner &) = delete;
Expand Down Expand Up @@ -89,6 +91,33 @@ class MLModelRunner {
virtual void requestExit() = 0;
std::promise<void> *exit_requested;

template <typename T, typename... Types>
void passMetaInfo(std::pair<std::string, T> &var1,
std::pair<std::string, Types> &...var2) {
of.open("observation.txt", std::ios::app);
of << var1.first << ": " << var1.second << "\n";
of.close();
passMetaInfo(var2...);
}

void passMetaInfo() {}

template <typename T> void dumpFeature(std::pair<std::string, T> &var1) {
of.open("observation.txt", std::ios::app);
of << var1.first << ": " << var1.second << "\n";
of.close();
}

template <typename T>
void dumpFeature(std::pair<std::string, std::vector<T>> &var1) {
of.open("observation.txt", std::ios::app);
of << var1.first << ": ";
for (const auto &elem : var1.second) {
of << elem << " ";
}
of << "\n";
of.close();
}
/// User-facing interface for setting the features to be sent to the model.
/// The features are passed as a list of key-value pairs.
/// The key is the name of the feature and the value is the value of the
Expand All @@ -97,6 +126,10 @@ class MLModelRunner {
void populateFeatures(std::pair<std::string, T> &var1,
std::pair<std::string, Types> &...var2) {
SerDes->setFeature(var1.first, var1.second);
dumpFeature(var1);
// of.open("observation.txt",std::ios::app);
// of << var1.first << ": " << reinterpret_cast<T>(var1.second) << "\n";
// of.close();
populateFeatures(var2...);
}

Expand Down
Loading