From ab2cd12915401263358a3c2f39cbffd6f4379df6 Mon Sep 17 00:00:00 2001 From: Davis King Date: Fri, 8 Jan 2016 18:15:15 -0500 Subject: [PATCH] Made running_gradient serializable. --- dlib/statistics/running_gradient.h | 23 +++++++++++++++++++++ dlib/statistics/running_gradient_abstract.h | 16 ++++++++++++++ 2 files changed, 39 insertions(+) diff --git a/dlib/statistics/running_gradient.h b/dlib/statistics/running_gradient.h index bbe4c9064..3150c4aac 100644 --- a/dlib/statistics/running_gradient.h +++ b/dlib/statistics/running_gradient.h @@ -5,6 +5,7 @@ #include "running_gradient_abstract.h" #include "../algs.h" +#include "../serialize.h" #include #include "../matrix.h" @@ -115,6 +116,28 @@ namespace dlib return 1-probability_gradient_less_than(thresh); } + friend void serialize (const running_gradient& item, std::ostream& out) + { + int version = 1; + serialize(version, out); + serialize(item.n, out); + serialize(item.R, out); + serialize(item.w, out); + serialize(item.residual_squared, out); + } + + friend void deserialize (running_gradient& item, std::ostream& in) + { + int version = 0; + deserialize(version, in); + if (version != 1) + throw serialization_error("Unexpected version found while deserializing dlib::running_gradient."); + deserialize(item.n, in); + deserialize(item.R, in); + deserialize(item.w, in); + deserialize(item.residual_squared, in); + } + private: static double normal_cfd(double value, double mean, double stddev) diff --git a/dlib/statistics/running_gradient_abstract.h b/dlib/statistics/running_gradient_abstract.h index 146cd1922..4af416fa3 100644 --- a/dlib/statistics/running_gradient_abstract.h +++ b/dlib/statistics/running_gradient_abstract.h @@ -100,6 +100,22 @@ namespace dlib !*/ }; + + void serialize ( + const running_gradient& item, + std::ostream& out + ); + /*! + provides serialization support + !*/ + + void deserialize ( + running_gradient& item, + std::istream& in + ); + /*! + provides serialization support + !*/ } #endif // DLIB_RuNNING_GRADIENT_ABSTRACT_Hh_