| 192 | // ---------------------------------------------------------------------------------------- |
| 193 | |
| 194 | void test_serialization() |
| 195 | { |
| 196 | tfidf_transformer<sparse_type> tfidf; |
| 197 | tfidf.set_max_vocabulary_size(3); |
| 198 | tfidf.use_sublinear_tf(true); |
| 199 | tfidf.train(corpus()); |
| 200 | |
| 201 | std::ostringstream out; |
| 202 | serialize(tfidf, out); |
| 203 | tfidf_transformer<sparse_type> copy; |
| 204 | std::istringstream in(out.str()); |
| 205 | deserialize(copy, in); |
| 206 | |
| 207 | DLIB_TEST(copy.max_vocabulary_size() == 3); |
| 208 | DLIB_TEST(copy.uses_sublinear_tf()); |
| 209 | DLIB_TEST(copy.vocabulary() == tfidf.vocabulary()); |
| 210 | DLIB_TEST(copy.idf() == tfidf.idf()); |
| 211 | for (const auto& d : corpus()) |
| 212 | DLIB_TEST(copy(d) == tfidf(d)); |
| 213 | } |
| 214 | |
| 215 | // ---------------------------------------------------------------------------------------- |
| 216 |
no test coverage detected