source: proiecte/pmake3d/make3d_original/Make3dSingleImageStanford_version0.1/third_party/lightspeed/maxdiff.m @ 37

Last change on this file since 37 was 37, checked in by (none), 14 years ago

Added original make3d

  • Property svn:executable set to *
File size: 1.4 KB
Line 
1function e = maxdiff(a,b,rel)
2% MAXDIFF(A,B) returns the maximum difference in any field or element.
3% Matching infinities or NaNs do not count.
4%
5% MAXDIFF(A,B,REL) measures the per-element relative difference (A-B)/(REL + A)
6%
7% Examples:
8%   maxdiff([1 2 3 nan inf -inf],[1 2 4 nan inf -inf]) % = 1
9
10% Written by Tom Minka
11% (c) Microsoft Corporation. All rights reserved.
12
13if nargin < 3
14  rel = [];
15end
16
17e = 0;
18if ~isequal(class(a), class(b))
19  fprintf('maxdiff: incompatible types\n');
20  e = Inf;
21  return
22end
23if isa(a,'struct')
24  for f = fieldnames(a)'
25    field = char(f);
26    if ~isfield(b,field)
27      fprintf('maxdiff: second argument lacks field %s\n', field);
28      e = Inf;
29      return
30    end
31    e = max(e,maxdiff(a.(field), b.(field), rel));
32  end
33  return
34end
35if ~isequal(size(a),size(b))
36  fprintf('maxdiff: size mismatch\n');
37  e = Inf;
38  return
39end
40a = a(:);
41b = b(:);
42if iscell(a)
43  for i = 1:numel(a)
44    e = max(e,maxdiff(a{i},b{i}));
45  end
46  return
47end
48i = isnan(a);
49if any(i ~= isnan(b))
50  % mismatched NaNs
51  e = Inf;
52  return
53elseif sum(i) > 0
54  a = a(~i);
55  b = b(~i);
56end
57i = ~isfinite(a);
58if any(i ~= ~isfinite(b))
59  % mismatched infs
60  e = Inf;
61  return
62elseif ~isequal(a(i),b(i))
63  e = Inf;
64  return
65else
66  a = a(~i);
67  b = b(~i);
68end
69if isempty(a)
70  e = 0;
71  return
72end
73e = abs(a(:) - b(:));
74if ~isempty(rel)
75  e = e ./ (rel + abs(a(:)));
76end
77e = max(e);
Note: See TracBrowser for help on using the repository browser.