Eigen - 如何创建最小的序列化 MatrixXf

Eigen - How to create the smallest serialized MatrixXf

本文关键字:序列化 MatrixXf 创建 何创建 Eigen      更新时间:2023-10-16

我正在通过与此类似的代码将相对较大的MatrixXf序列化为文件 - https://github.com/github188/vidy_old/blob/01c0aa4242299f7f1056edf0aa60b92177dfcfe6/3rdparty/openbr/core/eigenutils.h

当我使用 Qt 执行此操作时,它会根据矩阵创建 3-30MB 的文件。

如果节省空间是我的#1目标,我可以考虑做哪些事情?

  1. 是否有另一种形式的序列化,我希望看到更小的文件大小? (我可能会尝试提升以查看其有何不同 - https://gist.github.com/ShigekiKarita/4db2b0ffb207322c1324(
  2. 似乎序列化矩阵可以压缩一点,如果我能忍受浮点精度的小数位较少,这样它就不必在磁盘上存储那么多。 有谁知道这样的技术?

谢谢,

Boost 序列化与压缩一起使用 Boost 的 iostream 过滤应该会为您提供一个灵活的解决方案,文件大小较小。

Boost 序列化的binary_archive非常紧凑,并允许文件版本控制,这可能很方便。

独立于您使用的序列化,boost 提供过滤流,其工作方式与常规 istream 和 ostream 完全相同,但会动态添加压缩。您可以简单地将示例中的流替换为过滤后的流,并且应该具有工作压缩。

http://www.boost.org/doc/libs/1_64_0/libs/iostreams/doc/classes/gzip.html

#include <fstream>
#include <iostream>
#include <boost/iostreams/filtering_streambuf.hpp>
#include <boost/iostreams/copy.hpp>
#include <boost/iostreams/filter/gzip.hpp>
int main() 
{
using namespace std;
ifstream file("hello.gz", ios_base::in | ios_base::binary);
filtering_streambuf<input> in;
in.push(gzip_decompressor());
in.push(file);
boost::iostreams::copy(in, cout);
}