12 #ifndef MLPACK_TESTS_SERIALIZATION_CATCH_HPP 13 #define MLPACK_TESTS_SERIALIZATION_CATCH_HPP 23 template<
typename CubeType,
24 typename IArchiveType,
25 typename OArchiveType>
30 std::string fileName =
FilterFileName(
typeid(IArchiveType).name());
41 arma::Cube<CubeType> orig(x);
50 remove(fileName.c_str());
52 REQUIRE(x.n_rows == orig.n_rows);
53 REQUIRE(x.n_cols == orig.n_cols);
54 REQUIRE(x.n_elem_slice == orig.n_elem_slice);
55 REQUIRE(x.n_slices == orig.n_slices);
56 REQUIRE(x.n_elem == orig.n_elem);
58 for (
size_t slice = 0; slice != x.n_slices; ++slice)
60 const auto& origSlice = orig.slice(slice);
61 const auto& xSlice = x.slice(slice);
62 for (
size_t i = 0; i < x.n_cols; ++i)
64 for (
size_t j = 0; j < x.n_rows; ++j)
66 if (
double(origSlice(j, i)) == 0.0)
67 REQUIRE(
double(xSlice(j, i)) == Approx(0.0).margin(1e-8 / 100));
69 REQUIRE(
double(origSlice(j, i)) ==
70 Approx(
double(xSlice(j, i))).epsilon(1e-8 / 100));
77 template<
typename CubeType>
81 cereal::XMLOutputArchive>(x);
83 cereal::JSONOutputArchive>(x);
85 cereal::BinaryOutputArchive>(x);
89 template<
typename MatType,
90 typename IArchiveType,
91 typename OArchiveType>
95 std::string fileName =
FilterFileName(
typeid(IArchiveType).name());
115 remove(fileName.c_str());
117 REQUIRE(x.n_rows == orig.n_rows);
118 REQUIRE(x.n_cols == orig.n_cols);
119 REQUIRE(x.n_elem == orig.n_elem);
121 for (
size_t i = 0; i < x.n_cols; ++i)
122 for (
size_t j = 0; j < x.n_rows; ++j)
123 if (
double(orig(j, i)) == 0.0)
124 REQUIRE(
double(x(j, i)) == Approx(0.0).margin(1e-8 / 100));
126 REQUIRE(
double(orig(j, i)) ==
127 Approx(
double(x(j, i))).epsilon(1e-8 / 100));
131 template<
typename MatType>
135 cereal::XMLOutputArchive>(x);
137 cereal::JSONOutputArchive>(x);
139 cereal::BinaryOutputArchive>(x);
144 template<
typename T,
typename IArchiveType,
typename OArchiveType>
167 remove(fileName.c_str());
175 cereal::XMLOutputArchive>(t, xmlT);
177 cereal::JSONOutputArchive>(t, jsonT);
179 cereal::BinaryOutputArchive>(t, binaryT);
183 template<
typename T,
typename IArchiveType,
typename OArchiveType>
202 remove(fileName.c_str());
209 cereal::JSONOutputArchive>(t, jsonT);
211 cereal::BinaryOutputArchive>(t, binaryT);
213 cereal::XMLOutputArchive>(t, xmlT);
218 const arma::mat& xmlX,
219 const arma::mat& jsonX,
220 const arma::mat& binaryX);
223 const arma::Mat<size_t>& xmlX,
224 const arma::Mat<size_t>& jsonX,
225 const arma::Mat<size_t>& binaryX);
228 const arma::cube& xmlX,
229 const arma::cube& jsonX,
230 const arma::cube& binaryX);
void SerializePointerObject(T *t, T *&newT)
void CheckMatrices(const arma::mat &x, const arma::mat &xmlX, const arma::mat &jsonX, const arma::mat &binaryX)
Linear algebra utility functions, generally performed on matrices or vectors.
void TestArmadilloSerialization(arma::Cube< CubeType > &x)
void SerializePointerObjectAll(T *t, T *&xmlT, T *&jsonT, T *&binaryT)
Include all of the base components required to write mlpack methods, and the main mlpack Doxygen docu...
void SerializeObject(T &t, T &newT)
void TestAllArmadilloSerialization(arma::Cube< CubeType > &x)
#define CEREAL_POINTER(T)
Cereal does not support the serialization of raw pointer.
void SerializeObjectAll(T &t, T &xmlT, T &jsonT, T &binaryT)