简体   繁体   English

在Octave中保存/加载大型矩阵

[英]Save/load a large matrix in Octave

I'm playing with large pointcloud data in Octave (different files ranging from [10^5 to 10^7, 4] elements) and I'm looking for ways to optimize the code. 我正在使用Octave中的大型点云数据(范围从[10 ^ 5到10 ^ 7,4]元素的不同文件),正在寻找优化代码的方法。

Right now I am trying to save the data into a .mat file as I've read somewhere ( confirmation needed ) that loading from a .mat file is much faster than loading the actual data.txt file every time. 现在,我正在尝试将数据保存到.mat文件中,因为我已经读过某处( 需要确认 ),从.mat文件加载比每次加载实际data.txt文件快得多。

save -ascii myfile data works fine needs since it's only numerical values I want to store but save -ascii myfile data可以很好地满足需要,因为它只是我要存储的数值,但

load('myfile.mat') brings up a 1x1 matrix containing all the values instead of having a nx4 matrix, which is strange because when I use load('data.txt') I get a full nx4 matrix. load('myfile.mat')出包含所有值的1x1矩阵,而不是nx4矩阵,这很奇怪,因为当我使用load('data.txt')我得到了完整的nx4矩阵。

The problem seems to be with the save syntax. 问题似乎出在save语法上。 Any way I can save the file so I can load it with its original dimensions? 有什么方法可以保存文件,以便以原始尺寸加载文件? Or do I have to manipulate the resulting 1x1 variable somehow? 还是我必须以某种方式操纵结果1x1变量?

Bonus question: 奖励问题:
Browsing through some answers I kinda got the feeling that working with the transpose matrix instead of the nx4 would improve runtime considerably. 浏览一些答案后,我有种感觉,使用转置矩阵而不是nx4可以大大改善运行时间。 Is that true? 真的吗?

Use a binary format if speed matters. 如果速度很重要,请使用二进制格式。 Below a little speed comparison 下面比较一点速度

a = rand (1e6, 4);
fn = tmpnam;

tic; save ("-ascii", fn, "a"); toc;
tic; load ("-ascii", fn); toc;
stat (fn).size

tic; save ("-v7", fn, "a"); toc;
tic; load ("-v7", fn); toc;
stat (fn).size

tic; save ("-v6", fn, "a"); toc;
tic; load ("-v6", fn); toc;
stat (fn).size

tic; save ("-binary", fn, "a"); toc;
tic; load ("-binary", fn); toc;
stat (fn).size

which gives 这使

Elapsed time is 2.82237 seconds.
Elapsed time is 6.28686 seconds.
ans =  61000000
Elapsed time is 1.54074 seconds.
Elapsed time is 0.252718 seconds.
ans =  30192558
Elapsed time is 0.030833 seconds.
Elapsed time is 0.047183 seconds.
ans =  32000184
Elapsed time is 0.116342 seconds.
Elapsed time is 0.0523431 seconds.
ans =  32000045

As you can see -v6 is much faster than -ascii 如您所见,-v6比-ascii快得多

EDIT: also keep in mind that "-ascii" only uses single precision floats 编辑:还请记住,“-ascii”仅使用单精度浮点数

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM