Mercurial > octave
comparison libinterp/corefcn/lu.cc @ 21271:7e67c7f82fc1
better use of templates for lu factorization classes
* liboctave/numeric/lu.h, liboctave/numeric/lu.cc:
New files generated from base-lu.h, base-lu.cc, CmplxLU.cc, CmplxLU.h,
dbleLU.cc, dbleLU.h, fCmplxLU.cc, fCmplxLU.h, floatLU.cc, and
floatLU.h and converted to templates.
* liboctave/numeric/module.mk: Update.
* lu.cc, mx-defs.h, mx-ext.h, eigs-base.cc: Use new classes.
author | John W. Eaton <jwe@octave.org> |
---|---|
date | Tue, 16 Feb 2016 12:58:32 -0500 |
parents | fcac5dbbf9ed |
children | 40de9f8f23a6 |
comparison
equal
deleted
inserted
replaced
21270:230e186e292d | 21271:7e67c7f82fc1 |
---|---|
22 | 22 |
23 #ifdef HAVE_CONFIG_H | 23 #ifdef HAVE_CONFIG_H |
24 # include <config.h> | 24 # include <config.h> |
25 #endif | 25 #endif |
26 | 26 |
27 #include "CmplxLU.h" | 27 #include "lu.h" |
28 #include "dbleLU.h" | |
29 #include "fCmplxLU.h" | |
30 #include "floatLU.h" | |
31 #include "sparse-lu.h" | 28 #include "sparse-lu.h" |
32 | 29 |
33 #include "defun.h" | 30 #include "defun.h" |
34 #include "error.h" | 31 #include "error.h" |
35 #include "errwarn.h" | 32 #include "errwarn.h" |
38 #include "ov-re-sparse.h" | 35 #include "ov-re-sparse.h" |
39 #include "ov-cx-sparse.h" | 36 #include "ov-cx-sparse.h" |
40 | 37 |
41 template <typename MT> | 38 template <typename MT> |
42 static octave_value | 39 static octave_value |
43 get_lu_l (const base_lu<MT>& fact) | 40 get_lu_l (const lu<MT>& fact) |
44 { | 41 { |
45 MT L = fact.L (); | 42 MT L = fact.L (); |
46 if (L.is_square ()) | 43 if (L.is_square ()) |
47 return octave_value (L, MatrixType (MatrixType::Lower)); | 44 return octave_value (L, MatrixType (MatrixType::Lower)); |
48 else | 45 else |
49 return L; | 46 return L; |
50 } | 47 } |
51 | 48 |
52 template <typename MT> | 49 template <typename MT> |
53 static octave_value | 50 static octave_value |
54 get_lu_u (const base_lu<MT>& fact) | 51 get_lu_u (const lu<MT>& fact) |
55 { | 52 { |
56 MT U = fact.U (); | 53 MT U = fact.U (); |
57 if (U.is_square () && fact.regular ()) | 54 if (U.is_square () && fact.regular ()) |
58 return octave_value (U, MatrixType (MatrixType::Upper)); | 55 return octave_value (U, MatrixType (MatrixType::Upper)); |
59 else | 56 else |
342 { | 339 { |
343 if (arg.is_single_type ()) | 340 if (arg.is_single_type ()) |
344 { | 341 { |
345 FloatMatrix m = arg.float_matrix_value (); | 342 FloatMatrix m = arg.float_matrix_value (); |
346 | 343 |
347 FloatLU fact (m); | 344 lu<FloatMatrix> fact (m); |
348 | 345 |
349 switch (nargout) | 346 switch (nargout) |
350 { | 347 { |
351 case 0: | 348 case 0: |
352 case 1: | 349 case 1: |
376 } | 373 } |
377 else | 374 else |
378 { | 375 { |
379 Matrix m = arg.matrix_value (); | 376 Matrix m = arg.matrix_value (); |
380 | 377 |
381 LU fact (m); | 378 lu<Matrix> fact (m); |
382 | 379 |
383 switch (nargout) | 380 switch (nargout) |
384 { | 381 { |
385 case 0: | 382 case 0: |
386 case 1: | 383 case 1: |
413 { | 410 { |
414 if (arg.is_single_type ()) | 411 if (arg.is_single_type ()) |
415 { | 412 { |
416 FloatComplexMatrix m = arg.float_complex_matrix_value (); | 413 FloatComplexMatrix m = arg.float_complex_matrix_value (); |
417 | 414 |
418 FloatComplexLU fact (m); | 415 lu<FloatComplexMatrix> fact (m); |
419 | 416 |
420 switch (nargout) | 417 switch (nargout) |
421 { | 418 { |
422 case 0: | 419 case 0: |
423 case 1: | 420 case 1: |
447 } | 444 } |
448 else | 445 else |
449 { | 446 { |
450 ComplexMatrix m = arg.complex_matrix_value (); | 447 ComplexMatrix m = arg.complex_matrix_value (); |
451 | 448 |
452 ComplexLU fact (m); | 449 lu<ComplexMatrix> fact (m); |
453 | 450 |
454 switch (nargout) | 451 switch (nargout) |
455 { | 452 { |
456 case 0: | 453 case 0: |
457 case 1: | 454 case 1: |
648 FloatMatrix L = argl.float_matrix_value (); | 645 FloatMatrix L = argl.float_matrix_value (); |
649 FloatMatrix U = argu.float_matrix_value (); | 646 FloatMatrix U = argu.float_matrix_value (); |
650 FloatMatrix x = argx.float_matrix_value (); | 647 FloatMatrix x = argx.float_matrix_value (); |
651 FloatMatrix y = argy.float_matrix_value (); | 648 FloatMatrix y = argy.float_matrix_value (); |
652 | 649 |
653 FloatLU fact (L, U, P); | 650 lu<FloatMatrix> fact (L, U, P); |
654 if (pivoted) | 651 if (pivoted) |
655 fact.update_piv (x, y); | 652 fact.update_piv (x, y); |
656 else | 653 else |
657 fact.update (x, y); | 654 fact.update (x, y); |
658 | 655 |
666 Matrix L = argl.matrix_value (); | 663 Matrix L = argl.matrix_value (); |
667 Matrix U = argu.matrix_value (); | 664 Matrix U = argu.matrix_value (); |
668 Matrix x = argx.matrix_value (); | 665 Matrix x = argx.matrix_value (); |
669 Matrix y = argy.matrix_value (); | 666 Matrix y = argy.matrix_value (); |
670 | 667 |
671 LU fact (L, U, P); | 668 lu<Matrix> fact (L, U, P); |
672 if (pivoted) | 669 if (pivoted) |
673 fact.update_piv (x, y); | 670 fact.update_piv (x, y); |
674 else | 671 else |
675 fact.update (x, y); | 672 fact.update (x, y); |
676 | 673 |
689 FloatComplexMatrix L = argl.float_complex_matrix_value (); | 686 FloatComplexMatrix L = argl.float_complex_matrix_value (); |
690 FloatComplexMatrix U = argu.float_complex_matrix_value (); | 687 FloatComplexMatrix U = argu.float_complex_matrix_value (); |
691 FloatComplexMatrix x = argx.float_complex_matrix_value (); | 688 FloatComplexMatrix x = argx.float_complex_matrix_value (); |
692 FloatComplexMatrix y = argy.float_complex_matrix_value (); | 689 FloatComplexMatrix y = argy.float_complex_matrix_value (); |
693 | 690 |
694 FloatComplexLU fact (L, U, P); | 691 lu<FloatComplexMatrix> fact (L, U, P); |
695 if (pivoted) | 692 if (pivoted) |
696 fact.update_piv (x, y); | 693 fact.update_piv (x, y); |
697 else | 694 else |
698 fact.update (x, y); | 695 fact.update (x, y); |
699 | 696 |
707 ComplexMatrix L = argl.complex_matrix_value (); | 704 ComplexMatrix L = argl.complex_matrix_value (); |
708 ComplexMatrix U = argu.complex_matrix_value (); | 705 ComplexMatrix U = argu.complex_matrix_value (); |
709 ComplexMatrix x = argx.complex_matrix_value (); | 706 ComplexMatrix x = argx.complex_matrix_value (); |
710 ComplexMatrix y = argy.complex_matrix_value (); | 707 ComplexMatrix y = argy.complex_matrix_value (); |
711 | 708 |
712 ComplexLU fact (L, U, P); | 709 lu<ComplexMatrix> fact (L, U, P); |
713 if (pivoted) | 710 if (pivoted) |
714 fact.update_piv (x, y); | 711 fact.update_piv (x, y); |
715 else | 712 else |
716 fact.update (x, y); | 713 fact.update (x, y); |
717 | 714 |