很好地打印矩阵 [英] nicely printf a matrix

查看:51
本文介绍了很好地打印矩阵的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好,


我的程序处理大量的大型矩阵。为了方便调试,

我希望能够将它们转储到文件中,这样我就可以轻松地导入其他软件(想想matlab,excel)我可以分析

的中间结果。为了确保其他程序可以理解数据,每个单元格之间需要包含一个空格,并且每行末尾返回一个

返回(行 - 主要订单)。因此,目前,

转储代码看起来像

每行


每个col

fprintf("%f \t"); //一个浮动后跟一个空格

结束

fprintf(" \ n"); //开始换行

结束


它运作正常,但正如我所说,矩阵相当大,所以它是

slooow。有没有什么好主意可以大大加快

流程?


谢谢


胜利者

Hi guys,

My program deals with with lots of large matrices. To easily debug it,
I would like to be able to dump them in files, so that I can easily
import then in other software (think matlab, excel) so I can analyse
the intermediate results. To make sure the data can be understood by
other programs, a space need to be included between each cell, and a
return at the end of each row (row-major order). Hence at the moment,
the dump code looks something like

for each row
for each col
fprintf("%f \t"); // a float followed by a space
end
fprintf("\n"); // to start a new line
end

It works ok, but as I said, the matrices are rather large, so it''s
slooow. Has anybody some good ideas to significantly speed up the
process?

Thanks

victor

推荐答案

vectorizo​​r写道:
vectorizor wrote:

我的程序处理大量的大型矩阵。为了方便调试,

我希望能够将它们转储到文件中,这样我就可以轻松地导入其他软件(想想matlab,excel)我可以分析

的中间结果。为了确保其他程序可以理解数据,每个单元格之间需要包含一个空格,并且每行末尾返回一个

返回(行 - 主要订单)。因此,目前,

转储代码看起来像

每行


每个col

fprintf("%f \t"); //一个浮动后跟一个空格

结束

fprintf(" \ n"); //开始换行

结束


它运作正常,但正如我所说,矩阵相当大,所以它是

slooow。
My program deals with with lots of large matrices. To easily debug it,
I would like to be able to dump them in files, so that I can easily
import then in other software (think matlab, excel) so I can analyse
the intermediate results. To make sure the data can be understood by
other programs, a space need to be included between each cell, and a
return at the end of each row (row-major order). Hence at the moment,
the dump code looks something like

for each row
for each col
fprintf("%f \t"); // a float followed by a space
end
fprintf("\n"); // to start a new line
end

It works ok, but as I said, the matrices are rather large, so it''s
slooow.



多大,多慢,你打印到哪里,

/实际代码/你是什么使用,你确定打印时间是花费时间吗,你有没有理由认为它可以更快,

是阵列稀疏?


-

报价设施包括缺乏原创思想。/华丽之夜/


Hewlett-Packard Limited注册办事处:Cain Road,Bracknell,

注册号:690597 England Berks RG12 1HN

How large, how slow, where are you printing them to, what''s the
/actual code/ you''re using, are you sure it''s the printing that''s
taking the time, have you any reason to think it can go faster,
are the arrays sparse?

--
"A facility for quotation covers the absence of original thought."/Gaudy Night/

Hewlett-Packard Limited registered office: Cain Road, Bracknell,
registered no: 690597 England Berks RG12 1HN


vectorizo​​r说:


< snip>
vectorizor said:

<snip>

转储代码看起来像

每行


每个col

fprintf("%f \t"); //一个浮动后跟一个空格

结束

fprintf(" \ n"); //开始换行

结束
the dump code looks something like

for each row
for each col
fprintf("%f \t"); // a float followed by a space
end
fprintf("\n"); // to start a new line
end



嗯,我希望它看起来不像那样。 :-)但我明白了。

Well, I hope it looks nothing like that. :-) But I get the idea.


>

它运作正常,但正如我所说,矩阵相当大,所以它是

slooow。有没有什么好主意可以大大加快

流程?
>
It works ok, but as I said, the matrices are rather large, so it''s
slooow. Has anybody some good ideas to significantly speed up the
process?



你的系统将是行缓冲,因此没有太多 - 如果有的话 -

从缓存写入中获得。如果你准备放弃

文本格式(并且我没有尽量减少痛苦 - 文本比二进制文件更有价值),使用fwrite写出数组可能会更快,更快,因为你正在跳过从

内部格式到文本的转换(以及返回,在加载时)。但成本很高 -

突然,你的数据格式受你实施的支配。


你是否可以做任何有效的事情而不会丢失文字

格式在很大程度上取决于数据。


这件事发生在我身上,有点儿。我不得不将一个大型机

程序的状态保存到一个文件中,以便它可以传输到PC上,以便更容易调试(如果你曾经有过的话)在大型机上调试,你会知道为什么!b。b。知道为什么!)。


有一些价值要转移的文件,而且它已经过时了/>
长 - 时间的迷雾对我很好,但肯定是很好的

很多分钟。然后我看了看数据,并意识到几乎每个值都是0美元!我的意思是,是的,有数百个非零

值,但实际上还有(!?!)零值的零值。


所以我以这样的方式编写代码,它只会转储非零值。

突然,整个过程 - 保存状态,转移,加载状态 - 只有

花了几秒钟。完成工作。


您可能会发现同样的技巧或类似技巧也适合您。


-

Richard Heathfield

Usenet是一个奇怪的地方 - dmr 29/7/1999
http://www.cpax.org.uk

电子邮件:rjh在上述域名中, - www。

Your system will be line-buffering, so there isn''t much - if anything -
to be gained from caching the writes. If you are prepared to give up
text format (and I do not minimise the pain - text is so much more
useful than binary), writing the arrays out using fwrite is likely to
be much, much quicker because you''re skipping the conversion from
internal format to text (and back, on the load). But the cost is high -
suddenly, your data format is at the mercy of your implementation.

Whether you can do anything seriously effective without losing text
format very much depends on the data.

This happened to me once, kinda. I had to save the state of a mainframe
program to a file so that it could be transferred down to the PC for
easier debugging (and if you''ve ever debugged on a mainframe, you''ll
know why!).

There were brazillions of values to transfer, and it was taking way too
long - the mists of time are kind to me, but it was certainly a great
many minutes. Then I took a look at the data, and realised that almost
every value was 0! I mean, yes, there were many hundreds of non-zero
values, but there were literally(!?!) squillions of zero values too.

So I wrote the code in such a way that it only dumped non-zero values.
Suddenly, the whole process - save state, transfer, load state - only
took a few seconds. Job done.

You may find that the same trick, or a similar one, works for you, too.

--
Richard Heathfield
"Usenet is a strange place" - dmr 29/7/1999
http://www.cpax.org.uk
email: rjh at the above domain, - www.


vectorizo​​r写于05/03/07 10:39, :
vectorizor wrote On 05/03/07 10:39,:

大家好,


我的程序处理很多大型矩阵。为了方便调试,

我希望能够将它们转储到文件中,这样我就可以轻松地导入其他软件(想想matlab,excel)我可以分析

的中间结果。为了确保其他程序可以理解数据,每个单元格之间需要包含一个空格,并且每行末尾返回一个

返回(行 - 主要订单)。因此,目前,

转储代码看起来像

每行


每个col

fprintf("%f \t"); //一个浮动后跟一个空格

结束

fprintf(" \ n"); //开始换行

结束


它运作正常,但正如我所说,矩阵相当大,所以它是

slooow。有没有什么好主意可以大大加快

流程?
Hi guys,

My program deals with with lots of large matrices. To easily debug it,
I would like to be able to dump them in files, so that I can easily
import then in other software (think matlab, excel) so I can analyse
the intermediate results. To make sure the data can be understood by
other programs, a space need to be included between each cell, and a
return at the end of each row (row-major order). Hence at the moment,
the dump code looks something like

for each row
for each col
fprintf("%f \t"); // a float followed by a space
end
fprintf("\n"); // to start a new line
end

It works ok, but as I said, the matrices are rather large, so it''s
slooow. Has anybody some good ideas to significantly speed up the
process?



购买更快的磁盘? I / O操作大约需要六个或者几个数量级,比CPU的运行时间多七个数量级,因此重新安排CPU的计算将是

很少改善整体时间。你最大的
改进可能来自消除空间
或制表符(假设你实际上并不需要

):如果矩阵是一千行或一千个b $ b列,这将为你节省一兆字节的I / O.


一个*可能*例外以上所有涉及

缓冲。您是否有机会将此输出发送给stderr流?

?默认情况下,该流不是缓冲的,因此您可能会产生大量的

部分阻止。写入而不是较少数量的

完整块写道。如果这是问题的根源,至少有两种方法来改善事物:使用

setvbuf()或setbuf()来改变stderr的缓冲

(你必须在*使用任何其他

方式的流之前执行此操作),或将输出发送到另一个打开的流

用fopen()。我会推荐第二个更强大的

并且更容易管理。


-
Er ********* @ sun.com


这篇关于很好地打印矩阵的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆