MATLAB中的flops函数
(2012-11-20 16:52:27)
标签:
杂谈 |
关于高版本的matlab中不再有查看浮点运算次数的函数flops,以及不再有相应的替代函数。这是为什么呢?
相关消息如下:
This is an obsolete function. With
the incorporation of LAPACK in MATLAB version 6,
Remove all existing instances of
flops. With the incorporation of LAPACK in MATLAB version 6,
counting floating-point operations is no longer
practical.
相关资料显示:
%FLOPS Floating
point operation count.
% FLOPS returns
the cumulative number of floating point
operations.
%
% FLOPS(0) resets
the count to zero.
%
% It is not
feasible to count absolutely all floating point
% operations, but
most of the important ones are counted.
% Additions and
subtractions are one flop if real and two if
% complex.
Multiplications and divisions count one flop
each
% if the result
is real and six flops if it is not.
% Elementary
functions count one if real and more if
complex.
%
% Some examples.
If A and B are real N-by-N matrices, then
% A + B counts
N^2 flops,
% A * B counts
2*N^3 flops,
% LU(A) counts
roughly (2/3)*N^3 flops.
% A ^ P counts
2*C*N^3 flops where, for integer P and
% D = DEC2BIN(P),
C = length(D)+sum(D=='1')-1.
% Copyright (c)
1984-98 by The MathWorks, Inc.
% $Revision: 5.6
$ $Date: 1997/11/21 23:28:51 $
% Built-in
function.
这是5.3中的M文件中的内容
下载lightspeed工具包最新版
1.flops的值是可以估算的,和算法里面算O(n)之类的差不多。
2.圡办法:
自己搞个计数器,每有一次浮点表达式的时候就把这个计数器加n,n为表达式中浮点运
算的次数。
缺点1是圡,2是如果MATLAB对表达式优化的话(比如共同子表达式替换),这个计数值
和实际的flops会有出入。

加载中…