comparison scripts/linear-algebra/onenormest.m @ 7795:df9519e9990c

Handle single precision eps values
author David Bateman <dbateman@free.fr>
date Mon, 12 May 2008 22:57:11 +0200
parents b48a21816f2e
children bc982528de11
comparison
equal deleted inserted replaced
7794:2b458dfe31ae 7795:df9519e9990c
109 if (size (varargin) > 1) 109 if (size (varargin) > 1)
110 t = varargin{2}; 110 t = varargin{2};
111 else 111 else
112 t = min (n, default_t); 112 t = min (n, default_t);
113 endif 113 endif
114 issing = isa (varargin {1}, "single");
114 else 115 else
115 if (size (varargin, 2) < 3) 116 if (size (varargin, 2) < 3)
116 print_usage(); 117 print_usage();
117 endif 118 endif
118 n = varargin{3}; 119 n = varargin{3};
121 if (size (varargin) > 3) 122 if (size (varargin) > 3)
122 t = varargin{4}; 123 t = varargin{4};
123 else 124 else
124 t = default_t; 125 t = default_t;
125 endif 126 endif
127 issing = isa (varargin {3}, "single");
126 endif 128 endif
127 129
128 ## Initial test vectors X. 130 ## Initial test vectors X.
129 X = rand (n, t); 131 X = rand (n, t);
130 X = X ./ (ones (n,1) * sum (abs (X), 1)); 132 X = X ./ (ones (n,1) * sum (abs (X), 1));
131 133
132 been_there = zeros (n, 1); # Track if a vertex has been visited. 134 been_there = zeros (n, 1); # Track if a vertex has been visited.
133 est_old = 0; # To check if the estimate has increased. 135 est_old = 0; # To check if the estimate has increased.
134 S = zeros (n, t); # Normalized vector of signs. The normalization is 136 S = zeros (n, t); # Normalized vector of signs. The normalization is
137
138 if (issing)
139 myeps = eps ("single");
140 X = single (X);
141 else
142 myeps = eps;
143 endif
135 144
136 for iter = 1 : itmax + 1 145 for iter = 1 : itmax + 1
137 Y = feval (apply, X); 146 Y = feval (apply, X);
138 147
139 ## Find the initial estimate as the largest A*x. 148 ## Find the initial estimate as the largest A*x.