1
function fl = luflops (L, U)
5
% Given a sparse LU factorization (L and U), return the flop count required
6
% by a conventional LU factorization algorithm to compute it. L and U can
7
% be either sparse or full matrices. L must be lower triangular and U must
8
% be upper triangular. Do not attempt to use this on the permuted L from
9
% [L,U] = lu (A). Instead, use [L,U,P] = lu (A) or [L,U,P,Q] = lu (A).
11
% Note that there is a subtle undercount in this estimate. Suppose A is
12
% completely dense, but during LU factorization exact cancellation occurs,
13
% causing some of the entries in L and U to become identically zero. The
14
% flop count returned by this routine is an undercount. There is a simple
15
% way to fix this (L = spones (L) + spones (tril (A))), but the fix is partial.
16
% It can also occur that some entry in L is a "symbolic" fill-in (zero in
17
% A, but a fill-in entry and thus must be computed), but numerically
18
% zero. The only way to get a reliable LU factorization would be to do a
19
% purely symbolic factorization of A. This cannot be done with
20
% symbfact (A, 'col').
22
% See NA Digest, Vol 00, #50, Tuesday, Dec. 5, 2000
24
% Tim Davis, Sept. 23, 2002. Written for MATLAB 6.5.
26
Lnz = full (sum (spones (L))) - 1 ; % off diagonal nz in cols of L
27
Unz = full (sum (spones (U')))' - 1 ; % off diagonal nz in rows of U
28
fl = 2*Lnz*Unz + sum (Lnz) ;