Commit ebdca8d8 authored by Robert Kimball's avatar Robert Kimball Committed by Chris Sullivan

make serializer header not depend on json.hpp (#562)

This fixes the previously broken compilation of ngraph-mxnet which directly utilized serializer.hpp
parent 803c3b36
......@@ -75,6 +75,7 @@
#include "ngraph/ops/tan.hpp"
#include "ngraph/ops/tanh.hpp"
#include "ngraph/util.hpp"
#include "nlohmann/json.hpp"
#ifdef NGRAPH_DISTRIBUTED
#include "ngraph/ops/allreduce.hpp"
......@@ -84,6 +85,21 @@ using namespace ngraph;
using namespace std;
using json = nlohmann::json;
template <typename T>
T get_or_default(nlohmann::json& j, const std::string& key, const T& default_value)
{
T rc;
try
{
rc = j.at(key).get<T>();
}
catch (...)
{
rc = default_value;
}
return rc;
}
static std::shared_ptr<ngraph::Function>
read_function(const json&, std::unordered_map<std::string, std::shared_ptr<Function>>&);
......
......@@ -21,26 +21,10 @@
#include "ngraph/function.hpp"
#include "ngraph/node.hpp"
#include "nlohmann/json.hpp"
namespace ngraph
{
std::string serialize(std::shared_ptr<ngraph::Function>, size_t indent = 0);
std::shared_ptr<ngraph::Function> deserialize(std::istream&);
std::shared_ptr<ngraph::Function> deserialize(const std::string&);
template <typename T>
T get_or_default(nlohmann::json& j, const std::string& key, const T& default_value)
{
T rc;
try
{
rc = j.at(key).get<T>();
}
catch (...)
{
rc = default_value;
}
return rc;
}
}
......@@ -30,6 +30,21 @@ using namespace std;
using namespace ngraph;
using json = nlohmann::json;
template <typename T>
T get_or_default(nlohmann::json& j, const std::string& key, const T& default_value)
{
T rc;
try
{
rc = j.at(key).get<T>();
}
catch (...)
{
rc = default_value;
}
return rc;
}
TEST(serialize, main)
{
// First create "f(A,B,C) = (A+B)*C".
......
......@@ -13,6 +13,9 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*******************************************************************************/
#include <iomanip>
#include "benchmark.hpp"
#include "ngraph/runtime/backend.hpp"
#include "ngraph/runtime/call_frame.hpp"
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment