comparison src/DLD-FUNCTIONS/svd.cc @ 10154:40dfc0c99116

DLD-FUNCTIONS/*.cc: untabify
author John W. Eaton <jwe@octave.org>
date Wed, 20 Jan 2010 17:33:41 -0500
parents 09da0bd91412
children d0ce5e973937
comparison
equal deleted inserted replaced
10153:2c28f9d0360f 10154:40dfc0c99116
137 bool isfloat = arg.is_single_type (); 137 bool isfloat = arg.is_single_type ();
138 138
139 if (nr == 0 || nc == 0) 139 if (nr == 0 || nc == 0)
140 { 140 {
141 if (isfloat) 141 if (isfloat)
142 { 142 {
143 if (nargout == 3) 143 if (nargout == 3)
144 { 144 {
145 retval(3) = float_identity_matrix (nr, nr); 145 retval(3) = float_identity_matrix (nr, nr);
146 retval(2) = FloatMatrix (nr, nc); 146 retval(2) = FloatMatrix (nr, nc);
147 retval(1) = float_identity_matrix (nc, nc); 147 retval(1) = float_identity_matrix (nc, nc);
148 } 148 }
149 else 149 else
150 retval(0) = FloatMatrix (0, 1); 150 retval(0) = FloatMatrix (0, 1);
151 } 151 }
152 else 152 else
153 { 153 {
154 if (nargout == 3) 154 if (nargout == 3)
155 { 155 {
156 retval(3) = identity_matrix (nr, nr); 156 retval(3) = identity_matrix (nr, nr);
157 retval(2) = Matrix (nr, nc); 157 retval(2) = Matrix (nr, nc);
158 retval(1) = identity_matrix (nc, nc); 158 retval(1) = identity_matrix (nc, nc);
159 } 159 }
160 else 160 else
161 retval(0) = Matrix (0, 1); 161 retval(0) = Matrix (0, 1);
162 } 162 }
163 } 163 }
164 else 164 else
165 { 165 {
166 SVD::type type = ((nargout == 0 || nargout == 1) 166 SVD::type type = ((nargout == 0 || nargout == 1)
167 ? SVD::sigma_only 167 ? SVD::sigma_only
168 : (nargin == 2) ? SVD::economy : SVD::std); 168 : (nargin == 2) ? SVD::economy : SVD::std);
169 169
170 if (isfloat) 170 if (isfloat)
171 { 171 {
172 if (arg.is_real_type ()) 172 if (arg.is_real_type ())
173 { 173 {
174 FloatMatrix tmp = arg.float_matrix_value (); 174 FloatMatrix tmp = arg.float_matrix_value ();
175 175
176 if (! error_state) 176 if (! error_state)
177 { 177 {
178 if (tmp.any_element_is_inf_or_nan ()) 178 if (tmp.any_element_is_inf_or_nan ())
179 { 179 {
180 error ("svd: cannot take SVD of matrix containing Inf or NaN values"); 180 error ("svd: cannot take SVD of matrix containing Inf or NaN values");
181 return retval; 181 return retval;
182 } 182 }
183 183
184 FloatSVD result (tmp, type); 184 FloatSVD result (tmp, type);
185 185
186 FloatDiagMatrix sigma = result.singular_values (); 186 FloatDiagMatrix sigma = result.singular_values ();
187 187
188 if (nargout == 0 || nargout == 1) 188 if (nargout == 0 || nargout == 1)
189 { 189 {
190 retval(0) = sigma.diag (); 190 retval(0) = sigma.diag ();
191 } 191 }
192 else 192 else
193 { 193 {
194 retval(2) = result.right_singular_matrix (); 194 retval(2) = result.right_singular_matrix ();
195 retval(1) = sigma; 195 retval(1) = sigma;
196 retval(0) = result.left_singular_matrix (); 196 retval(0) = result.left_singular_matrix ();
197 } 197 }
198 } 198 }
199 } 199 }
200 else if (arg.is_complex_type ()) 200 else if (arg.is_complex_type ())
201 { 201 {
202 FloatComplexMatrix ctmp = arg.float_complex_matrix_value (); 202 FloatComplexMatrix ctmp = arg.float_complex_matrix_value ();
203 203
204 if (! error_state) 204 if (! error_state)
205 { 205 {
206 if (ctmp.any_element_is_inf_or_nan ()) 206 if (ctmp.any_element_is_inf_or_nan ())
207 { 207 {
208 error ("svd: cannot take SVD of matrix containing Inf or NaN values"); 208 error ("svd: cannot take SVD of matrix containing Inf or NaN values");
209 return retval; 209 return retval;
210 } 210 }
211 211
212 FloatComplexSVD result (ctmp, type); 212 FloatComplexSVD result (ctmp, type);
213 213
214 FloatDiagMatrix sigma = result.singular_values (); 214 FloatDiagMatrix sigma = result.singular_values ();
215 215
216 if (nargout == 0 || nargout == 1) 216 if (nargout == 0 || nargout == 1)
217 { 217 {
218 retval(0) = sigma.diag (); 218 retval(0) = sigma.diag ();
219 } 219 }
220 else 220 else
221 { 221 {
222 retval(2) = result.right_singular_matrix (); 222 retval(2) = result.right_singular_matrix ();
223 retval(1) = sigma; 223 retval(1) = sigma;
224 retval(0) = result.left_singular_matrix (); 224 retval(0) = result.left_singular_matrix ();
225 } 225 }
226 } 226 }
227 } 227 }
228 } 228 }
229 else 229 else
230 { 230 {
231 if (arg.is_real_type ()) 231 if (arg.is_real_type ())
232 { 232 {
233 Matrix tmp = arg.matrix_value (); 233 Matrix tmp = arg.matrix_value ();
234 234
235 if (! error_state) 235 if (! error_state)
236 { 236 {
237 if (tmp.any_element_is_inf_or_nan ()) 237 if (tmp.any_element_is_inf_or_nan ())
238 { 238 {
239 error ("svd: cannot take SVD of matrix containing Inf or NaN values"); 239 error ("svd: cannot take SVD of matrix containing Inf or NaN values");
240 return retval; 240 return retval;
241 } 241 }
242 242
243 SVD result (tmp, type); 243 SVD result (tmp, type);
244 244
245 DiagMatrix sigma = result.singular_values (); 245 DiagMatrix sigma = result.singular_values ();
246 246
247 if (nargout == 0 || nargout == 1) 247 if (nargout == 0 || nargout == 1)
248 { 248 {
249 retval(0) = sigma.diag (); 249 retval(0) = sigma.diag ();
250 } 250 }
251 else 251 else
252 { 252 {
253 retval(2) = result.right_singular_matrix (); 253 retval(2) = result.right_singular_matrix ();
254 retval(1) = sigma; 254 retval(1) = sigma;
255 retval(0) = result.left_singular_matrix (); 255 retval(0) = result.left_singular_matrix ();
256 } 256 }
257 } 257 }
258 } 258 }
259 else if (arg.is_complex_type ()) 259 else if (arg.is_complex_type ())
260 { 260 {
261 ComplexMatrix ctmp = arg.complex_matrix_value (); 261 ComplexMatrix ctmp = arg.complex_matrix_value ();
262 262
263 if (! error_state) 263 if (! error_state)
264 { 264 {
265 if (ctmp.any_element_is_inf_or_nan ()) 265 if (ctmp.any_element_is_inf_or_nan ())
266 { 266 {
267 error ("svd: cannot take SVD of matrix containing Inf or NaN values"); 267 error ("svd: cannot take SVD of matrix containing Inf or NaN values");
268 return retval; 268 return retval;
269 } 269 }
270 270
271 ComplexSVD result (ctmp, type); 271 ComplexSVD result (ctmp, type);
272 272
273 DiagMatrix sigma = result.singular_values (); 273 DiagMatrix sigma = result.singular_values ();
274 274
275 if (nargout == 0 || nargout == 1) 275 if (nargout == 0 || nargout == 1)
276 { 276 {
277 retval(0) = sigma.diag (); 277 retval(0) = sigma.diag ();
278 } 278 }
279 else 279 else
280 { 280 {
281 retval(2) = result.right_singular_matrix (); 281 retval(2) = result.right_singular_matrix ();
282 retval(1) = sigma; 282 retval(1) = sigma;
283 retval(0) = result.left_singular_matrix (); 283 retval(0) = result.left_singular_matrix ();
284 } 284 }
285 } 285 }
286 } 286 }
287 else 287 else
288 { 288 {
289 gripe_wrong_type_arg ("svd", arg); 289 gripe_wrong_type_arg ("svd", arg);
290 return retval; 290 return retval;
291 } 291 }
292 } 292 }
293 } 293 }
294 294
295 return retval; 295 return retval;
296 } 296 }
297 297