Mercurial > octave-nkf
comparison libinterp/dldfcn/chol.cc @ 20591:0650b8431037
eliminate more simple uses of error_state
* besselj.cc, bitfcns.cc, utils.cc, chol.cc, ov-java.cc:
Eliminate simple uses of error_state.
author | John W. Eaton <jwe@octave.org> |
---|---|
date | Mon, 05 Oct 2015 21:37:03 -0400 |
parents | 5ce959c55cc0 |
children | 10ec79b47808 |
comparison
equal
deleted
inserted
replaced
20590:1a0a433c8263 | 20591:0650b8431037 |
---|---|
158 print_usage (); | 158 print_usage (); |
159 return retval; | 159 return retval; |
160 } | 160 } |
161 | 161 |
162 int n = 1; | 162 int n = 1; |
163 while (n < nargin && ! error_state) | 163 while (n < nargin) |
164 { | 164 { |
165 std::string tmp = args(n++).string_value (); | 165 std::string tmp = args(n++).string_value (); |
166 | 166 |
167 if (! error_state) | 167 if (! error_state) |
168 { | 168 { |
177 } | 177 } |
178 else | 178 else |
179 error ("chol: expecting trailing string arguments"); | 179 error ("chol: expecting trailing string arguments"); |
180 } | 180 } |
181 | 181 |
182 if (! error_state) | 182 octave_value arg = args(0); |
183 { | 183 |
184 octave_value arg = args(0); | 184 octave_idx_type nr = arg.rows (); |
185 | 185 octave_idx_type nc = arg.columns (); |
186 octave_idx_type nr = arg.rows (); | 186 |
187 octave_idx_type nc = arg.columns (); | 187 int arg_is_empty = empty_arg ("chol", nr, nc); |
188 | 188 |
189 int arg_is_empty = empty_arg ("chol", nr, nc); | 189 if (arg_is_empty < 0) |
190 | 190 return retval; |
191 if (arg_is_empty < 0) | 191 if (arg_is_empty > 0) |
192 return retval; | 192 return octave_value (Matrix ()); |
193 if (arg_is_empty > 0) | 193 |
194 return octave_value (Matrix ()); | 194 if (arg.is_sparse_type ()) |
195 | 195 { |
196 if (arg.is_sparse_type ()) | 196 octave_idx_type info; |
197 bool natural = (nargout != 3); | |
198 bool force = nargout > 1; | |
199 | |
200 if (arg.is_real_type ()) | |
197 { | 201 { |
198 octave_idx_type info; | 202 SparseMatrix m = arg.sparse_matrix_value (); |
199 bool natural = (nargout != 3); | 203 |
200 bool force = nargout > 1; | 204 SparseCHOL fact (m, info, natural, force); |
201 | 205 |
202 if (arg.is_real_type ()) | 206 if (nargout == 3) |
203 { | 207 { |
204 SparseMatrix m = arg.sparse_matrix_value (); | 208 if (vecout) |
205 | 209 retval(2) = fact.perm (); |
206 if (! error_state) | 210 else |
207 { | 211 retval(2) = fact.Q (); |
208 SparseCHOL fact (m, info, natural, force); | 212 } |
209 | 213 |
210 if (nargout == 3) | 214 if (nargout > 1 || info == 0) |
211 { | 215 { |
212 if (vecout) | 216 retval(1) = info; |
213 retval(2) = fact.perm (); | 217 if (LLt) |
214 else | 218 retval(0) = fact.L (); |
215 retval(2) = fact.Q (); | 219 else |
216 } | 220 retval(0) = fact.R (); |
217 | |
218 if (nargout > 1 || info == 0) | |
219 { | |
220 retval(1) = info; | |
221 if (LLt) | |
222 retval(0) = fact.L (); | |
223 else | |
224 retval(0) = fact.R (); | |
225 } | |
226 else | |
227 error ("chol: input matrix must be positive definite"); | |
228 } | |
229 } | |
230 else if (arg.is_complex_type ()) | |
231 { | |
232 SparseComplexMatrix m = arg.sparse_complex_matrix_value (); | |
233 | |
234 if (! error_state) | |
235 { | |
236 SparseComplexCHOL fact (m, info, natural, force); | |
237 | |
238 if (nargout == 3) | |
239 { | |
240 if (vecout) | |
241 retval(2) = fact.perm (); | |
242 else | |
243 retval(2) = fact.Q (); | |
244 } | |
245 | |
246 if (nargout > 1 || info == 0) | |
247 { | |
248 retval(1) = info; | |
249 if (LLt) | |
250 retval(0) = fact.L (); | |
251 else | |
252 retval(0) = fact.R (); | |
253 } | |
254 else | |
255 error ("chol: input matrix must be positive definite"); | |
256 } | |
257 } | 221 } |
258 else | 222 else |
259 gripe_wrong_type_arg ("chol", arg); | 223 error ("chol: input matrix must be positive definite"); |
260 } | 224 } |
261 else if (arg.is_single_type ()) | 225 else if (arg.is_complex_type ()) |
262 { | 226 { |
263 if (arg.is_real_type ()) | 227 SparseComplexMatrix m = arg.sparse_complex_matrix_value (); |
264 { | 228 |
265 FloatMatrix m = arg.float_matrix_value (); | 229 SparseComplexCHOL fact (m, info, natural, force); |
266 | 230 |
267 if (! error_state) | 231 if (nargout == 3) |
268 { | 232 { |
269 octave_idx_type info; | 233 if (vecout) |
270 | 234 retval(2) = fact.perm (); |
271 FloatCHOL fact; | 235 else |
272 fact = FloatCHOL (m, info, LLt != true); | 236 retval(2) = fact.Q (); |
273 | 237 } |
274 if (nargout == 2 || info == 0) | 238 |
275 { | 239 if (nargout > 1 || info == 0) |
276 retval(1) = info; | 240 { |
277 retval(0) = get_chol (fact); | 241 retval(1) = info; |
278 } | 242 if (LLt) |
279 else | 243 retval(0) = fact.L (); |
280 error ("chol: input matrix must be positive definite"); | 244 else |
281 } | 245 retval(0) = fact.R (); |
282 } | |
283 else if (arg.is_complex_type ()) | |
284 { | |
285 FloatComplexMatrix m = arg.float_complex_matrix_value (); | |
286 | |
287 if (! error_state) | |
288 { | |
289 octave_idx_type info; | |
290 | |
291 FloatComplexCHOL fact; | |
292 if (LLt) | |
293 fact = FloatComplexCHOL (m.transpose (), info); | |
294 else | |
295 fact = FloatComplexCHOL (m, info); | |
296 | |
297 if (nargout == 2 || info == 0) | |
298 { | |
299 retval(1) = info; | |
300 if (LLt) | |
301 retval(0) = get_chol_l (fact); | |
302 else | |
303 retval(0) = get_chol_r (fact); | |
304 } | |
305 else | |
306 error ("chol: input matrix must be positive definite"); | |
307 } | |
308 } | 246 } |
309 else | 247 else |
310 gripe_wrong_type_arg ("chol", arg); | 248 error ("chol: input matrix must be positive definite"); |
311 } | 249 } |
312 else | 250 else |
251 gripe_wrong_type_arg ("chol", arg); | |
252 } | |
253 else if (arg.is_single_type ()) | |
254 { | |
255 if (arg.is_real_type ()) | |
313 { | 256 { |
314 if (arg.is_real_type ()) | 257 FloatMatrix m = arg.float_matrix_value (); |
315 { | 258 |
316 Matrix m = arg.matrix_value (); | 259 octave_idx_type info; |
317 | 260 |
318 if (! error_state) | 261 FloatCHOL fact; |
319 { | 262 fact = FloatCHOL (m, info, LLt != true); |
320 octave_idx_type info; | 263 |
321 | 264 if (nargout == 2 || info == 0) |
322 CHOL fact; | 265 { |
323 fact = CHOL (m, info, LLt != true); | 266 retval(1) = info; |
324 | 267 retval(0) = get_chol (fact); |
325 if (nargout == 2 || info == 0) | |
326 { | |
327 retval(1) = info; | |
328 retval(0) = get_chol (fact); | |
329 } | |
330 else | |
331 error ("chol: input matrix must be positive definite"); | |
332 } | |
333 } | |
334 else if (arg.is_complex_type ()) | |
335 { | |
336 ComplexMatrix m = arg.complex_matrix_value (); | |
337 | |
338 if (! error_state) | |
339 { | |
340 octave_idx_type info; | |
341 | |
342 ComplexCHOL fact; | |
343 fact = ComplexCHOL (m, info, LLt != true); | |
344 | |
345 if (nargout == 2 || info == 0) | |
346 { | |
347 retval(1) = info; | |
348 retval(0) = get_chol (fact); | |
349 } | |
350 else | |
351 error ("chol: input matrix must be positive definite"); | |
352 } | |
353 } | 268 } |
354 else | 269 else |
355 gripe_wrong_type_arg ("chol", arg); | 270 error ("chol: input matrix must be positive definite"); |
356 } | 271 } |
272 else if (arg.is_complex_type ()) | |
273 { | |
274 FloatComplexMatrix m = arg.float_complex_matrix_value (); | |
275 | |
276 octave_idx_type info; | |
277 | |
278 FloatComplexCHOL fact; | |
279 if (LLt) | |
280 fact = FloatComplexCHOL (m.transpose (), info); | |
281 else | |
282 fact = FloatComplexCHOL (m, info); | |
283 | |
284 if (nargout == 2 || info == 0) | |
285 { | |
286 retval(1) = info; | |
287 if (LLt) | |
288 retval(0) = get_chol_l (fact); | |
289 else | |
290 retval(0) = get_chol_r (fact); | |
291 } | |
292 else | |
293 error ("chol: input matrix must be positive definite"); | |
294 } | |
295 else | |
296 gripe_wrong_type_arg ("chol", arg); | |
297 } | |
298 else | |
299 { | |
300 if (arg.is_real_type ()) | |
301 { | |
302 Matrix m = arg.matrix_value (); | |
303 | |
304 octave_idx_type info; | |
305 | |
306 CHOL fact; | |
307 fact = CHOL (m, info, LLt != true); | |
308 | |
309 if (nargout == 2 || info == 0) | |
310 { | |
311 retval(1) = info; | |
312 retval(0) = get_chol (fact); | |
313 } | |
314 else | |
315 error ("chol: input matrix must be positive definite"); | |
316 } | |
317 else if (arg.is_complex_type ()) | |
318 { | |
319 ComplexMatrix m = arg.complex_matrix_value (); | |
320 | |
321 octave_idx_type info; | |
322 | |
323 ComplexCHOL fact; | |
324 fact = ComplexCHOL (m, info, LLt != true); | |
325 | |
326 if (nargout == 2 || info == 0) | |
327 { | |
328 retval(1) = info; | |
329 retval(0) = get_chol (fact); | |
330 } | |
331 else | |
332 error ("chol: input matrix must be positive definite"); | |
333 } | |
334 else | |
335 gripe_wrong_type_arg ("chol", arg); | |
357 } | 336 } |
358 | 337 |
359 return retval; | 338 return retval; |
360 } | 339 } |
361 | 340 |
403 | 382 |
404 if (arg.is_real_type ()) | 383 if (arg.is_real_type ()) |
405 { | 384 { |
406 SparseMatrix m = arg.sparse_matrix_value (); | 385 SparseMatrix m = arg.sparse_matrix_value (); |
407 | 386 |
408 if (! error_state) | 387 SparseCHOL chol (m, info); |
409 { | 388 |
410 SparseCHOL chol (m, info); | 389 if (info == 0) |
411 | 390 retval = chol.inverse (); |
412 if (info == 0) | 391 else |
413 retval = chol.inverse (); | 392 error ("cholinv: A must be positive definite"); |
414 else | |
415 error ("cholinv: A must be positive definite"); | |
416 } | |
417 } | 393 } |
418 else if (arg.is_complex_type ()) | 394 else if (arg.is_complex_type ()) |
419 { | 395 { |
420 SparseComplexMatrix m = arg.sparse_complex_matrix_value (); | 396 SparseComplexMatrix m = arg.sparse_complex_matrix_value (); |
421 | 397 |
422 if (! error_state) | 398 SparseComplexCHOL chol (m, info); |
423 { | 399 |
424 SparseComplexCHOL chol (m, info); | 400 if (info == 0) |
425 | 401 retval = chol.inverse (); |
426 if (info == 0) | 402 else |
427 retval = chol.inverse (); | 403 error ("cholinv: A must be positive definite"); |
428 else | |
429 error ("cholinv: A must be positive definite"); | |
430 } | |
431 } | 404 } |
432 else | 405 else |
433 gripe_wrong_type_arg ("cholinv", arg); | 406 gripe_wrong_type_arg ("cholinv", arg); |
434 } | 407 } |
435 else if (arg.is_single_type ()) | 408 else if (arg.is_single_type ()) |
436 { | 409 { |
437 if (arg.is_real_type ()) | 410 if (arg.is_real_type ()) |
438 { | 411 { |
439 FloatMatrix m = arg.float_matrix_value (); | 412 FloatMatrix m = arg.float_matrix_value (); |
440 | 413 |
441 if (! error_state) | 414 octave_idx_type info; |
442 { | 415 FloatCHOL chol (m, info); |
443 octave_idx_type info; | 416 if (info == 0) |
444 FloatCHOL chol (m, info); | 417 retval = chol.inverse (); |
445 if (info == 0) | 418 else |
446 retval = chol.inverse (); | 419 error ("cholinv: A must be positive definite"); |
447 else | |
448 error ("cholinv: A must be positive definite"); | |
449 } | |
450 } | 420 } |
451 else if (arg.is_complex_type ()) | 421 else if (arg.is_complex_type ()) |
452 { | 422 { |
453 FloatComplexMatrix m = arg.float_complex_matrix_value (); | 423 FloatComplexMatrix m = arg.float_complex_matrix_value (); |
454 | 424 |
455 if (! error_state) | 425 octave_idx_type info; |
456 { | 426 FloatComplexCHOL chol (m, info); |
457 octave_idx_type info; | 427 if (info == 0) |
458 FloatComplexCHOL chol (m, info); | 428 retval = chol.inverse (); |
459 if (info == 0) | 429 else |
460 retval = chol.inverse (); | 430 error ("cholinv: A must be positive definite"); |
461 else | |
462 error ("cholinv: A must be positive definite"); | |
463 } | |
464 } | 431 } |
465 else | 432 else |
466 gripe_wrong_type_arg ("chol", arg); | 433 gripe_wrong_type_arg ("chol", arg); |
467 } | 434 } |
468 else | 435 else |
469 { | 436 { |
470 if (arg.is_real_type ()) | 437 if (arg.is_real_type ()) |
471 { | 438 { |
472 Matrix m = arg.matrix_value (); | 439 Matrix m = arg.matrix_value (); |
473 | 440 |
474 if (! error_state) | 441 octave_idx_type info; |
475 { | 442 CHOL chol (m, info); |
476 octave_idx_type info; | 443 if (info == 0) |
477 CHOL chol (m, info); | 444 retval = chol.inverse (); |
478 if (info == 0) | 445 else |
479 retval = chol.inverse (); | 446 error ("cholinv: A must be positive definite"); |
480 else | |
481 error ("cholinv: A must be positive definite"); | |
482 } | |
483 } | 447 } |
484 else if (arg.is_complex_type ()) | 448 else if (arg.is_complex_type ()) |
485 { | 449 { |
486 ComplexMatrix m = arg.complex_matrix_value (); | 450 ComplexMatrix m = arg.complex_matrix_value (); |
487 | 451 |
488 if (! error_state) | 452 octave_idx_type info; |
489 { | 453 ComplexCHOL chol (m, info); |
490 octave_idx_type info; | 454 if (info == 0) |
491 ComplexCHOL chol (m, info); | 455 retval = chol.inverse (); |
492 if (info == 0) | 456 else |
493 retval = chol.inverse (); | 457 error ("cholinv: A must be positive definite"); |
494 else | |
495 error ("cholinv: A must be positive definite"); | |
496 } | |
497 } | 458 } |
498 else | 459 else |
499 gripe_wrong_type_arg ("chol", arg); | 460 gripe_wrong_type_arg ("chol", arg); |
500 } | 461 } |
501 } | 462 } |
552 { | 513 { |
553 if (arg.is_real_type ()) | 514 if (arg.is_real_type ()) |
554 { | 515 { |
555 SparseMatrix r = arg.sparse_matrix_value (); | 516 SparseMatrix r = arg.sparse_matrix_value (); |
556 | 517 |
557 if (! error_state) | 518 retval = chol2inv (r); |
558 retval = chol2inv (r); | |
559 } | 519 } |
560 else if (arg.is_complex_type ()) | 520 else if (arg.is_complex_type ()) |
561 { | 521 { |
562 SparseComplexMatrix r = arg.sparse_complex_matrix_value (); | 522 SparseComplexMatrix r = arg.sparse_complex_matrix_value (); |
563 | 523 |
564 if (! error_state) | 524 retval = chol2inv (r); |
565 retval = chol2inv (r); | |
566 } | 525 } |
567 else | 526 else |
568 gripe_wrong_type_arg ("chol2inv", arg); | 527 gripe_wrong_type_arg ("chol2inv", arg); |
569 } | 528 } |
570 else if (arg.is_single_type ()) | 529 else if (arg.is_single_type ()) |
571 { | 530 { |
572 if (arg.is_real_type ()) | 531 if (arg.is_real_type ()) |
573 { | 532 { |
574 FloatMatrix r = arg.float_matrix_value (); | 533 FloatMatrix r = arg.float_matrix_value (); |
575 | 534 |
576 if (! error_state) | 535 retval = chol2inv (r); |
577 retval = chol2inv (r); | |
578 } | 536 } |
579 else if (arg.is_complex_type ()) | 537 else if (arg.is_complex_type ()) |
580 { | 538 { |
581 FloatComplexMatrix r = arg.float_complex_matrix_value (); | 539 FloatComplexMatrix r = arg.float_complex_matrix_value (); |
582 | 540 |
583 if (! error_state) | 541 retval = chol2inv (r); |
584 retval = chol2inv (r); | |
585 } | 542 } |
586 else | 543 else |
587 gripe_wrong_type_arg ("chol2inv", arg); | 544 gripe_wrong_type_arg ("chol2inv", arg); |
588 | 545 |
589 } | 546 } |
591 { | 548 { |
592 if (arg.is_real_type ()) | 549 if (arg.is_real_type ()) |
593 { | 550 { |
594 Matrix r = arg.matrix_value (); | 551 Matrix r = arg.matrix_value (); |
595 | 552 |
596 if (! error_state) | 553 retval = chol2inv (r); |
597 retval = chol2inv (r); | |
598 } | 554 } |
599 else if (arg.is_complex_type ()) | 555 else if (arg.is_complex_type ()) |
600 { | 556 { |
601 ComplexMatrix r = arg.complex_matrix_value (); | 557 ComplexMatrix r = arg.complex_matrix_value (); |
602 | 558 |
603 if (! error_state) | 559 retval = chol2inv (r); |
604 retval = chol2inv (r); | |
605 } | 560 } |
606 else | 561 else |
607 gripe_wrong_type_arg ("chol2inv", arg); | 562 gripe_wrong_type_arg ("chol2inv", arg); |
608 } | 563 } |
609 } | 564 } |