comparison src/DLD-FUNCTIONS/chol.cc @ 9715:9f27172fbd1e

auto-set MatrixType from certain functions
author Jaroslav Hajek <highegg@gmail.com>
date Mon, 12 Oct 2009 14:23:20 +0200
parents 5fcf008c7c41
children 09da0bd91412
comparison
equal deleted inserted replaced
9714:0407883e1a33 9715:9f27172fbd1e
42 #include "defun-dld.h" 42 #include "defun-dld.h"
43 #include "error.h" 43 #include "error.h"
44 #include "gripes.h" 44 #include "gripes.h"
45 #include "oct-obj.h" 45 #include "oct-obj.h"
46 #include "utils.h" 46 #include "utils.h"
47
48 template <class CHOLT>
49 static octave_value
50 get_chol_r (const CHOLT& fact)
51 {
52 return octave_value (fact.chol_matrix (),
53 MatrixType (MatrixType::Upper));
54 }
47 55
48 DEFUN_DLD (chol, args, nargout, 56 DEFUN_DLD (chol, args, nargout,
49 "-*- texinfo -*-\n\ 57 "-*- texinfo -*-\n\
50 @deftypefn {Loadable Function} {@var{r} =} chol (@var{a})\n\ 58 @deftypefn {Loadable Function} {@var{r} =} chol (@var{a})\n\
51 @deftypefnx {Loadable Function} {[@var{r}, @var{p}] =} chol (@var{a})\n\ 59 @deftypefnx {Loadable Function} {[@var{r}, @var{p}] =} chol (@var{a})\n\
245 { 253 {
246 retval(1) = static_cast<float> (info); 254 retval(1) = static_cast<float> (info);
247 if (LLt) 255 if (LLt)
248 retval(0) = fact.chol_matrix ().transpose (); 256 retval(0) = fact.chol_matrix ().transpose ();
249 else 257 else
250 retval(0) = fact.chol_matrix (); 258 retval(0) = get_chol_r (fact);
251 } 259 }
252 else 260 else
253 error ("chol: matrix not positive definite"); 261 error ("chol: matrix not positive definite");
254 } 262 }
255 } 263 }
265 { 273 {
266 retval(1) = static_cast<float> (info); 274 retval(1) = static_cast<float> (info);
267 if (LLt) 275 if (LLt)
268 retval(0) = fact.chol_matrix ().hermitian (); 276 retval(0) = fact.chol_matrix ().hermitian ();
269 else 277 else
270 retval(0) = fact.chol_matrix (); 278 retval(0) = get_chol_r (fact);
271 } 279 }
272 else 280 else
273 error ("chol: matrix not positive definite"); 281 error ("chol: matrix not positive definite");
274 } 282 }
275 } 283 }
290 { 298 {
291 retval(1) = static_cast<double> (info); 299 retval(1) = static_cast<double> (info);
292 if (LLt) 300 if (LLt)
293 retval(0) = fact.chol_matrix ().transpose (); 301 retval(0) = fact.chol_matrix ().transpose ();
294 else 302 else
295 retval(0) = fact.chol_matrix (); 303 retval(0) = get_chol_r (fact);
296 } 304 }
297 else 305 else
298 error ("chol: matrix not positive definite"); 306 error ("chol: matrix not positive definite");
299 } 307 }
300 } 308 }
310 { 318 {
311 retval(1) = static_cast<double> (info); 319 retval(1) = static_cast<double> (info);
312 if (LLt) 320 if (LLt)
313 retval(0) = fact.chol_matrix ().hermitian (); 321 retval(0) = fact.chol_matrix ().hermitian ();
314 else 322 else
315 retval(0) = fact.chol_matrix (); 323 retval(0) = get_chol_r (fact);
316 } 324 }
317 else 325 else
318 error ("chol: matrix not positive definite"); 326 error ("chol: matrix not positive definite");
319 } 327 }
320 } 328 }
646 if (down) 654 if (down)
647 err = fact.downdate (u); 655 err = fact.downdate (u);
648 else 656 else
649 fact.update (u); 657 fact.update (u);
650 658
651 retval(0) = fact.chol_matrix (); 659 retval(0) = get_chol_r (fact);
652 } 660 }
653 else 661 else
654 { 662 {
655 // complex case 663 // complex case
656 FloatComplexMatrix R = argr.float_complex_matrix_value (); 664 FloatComplexMatrix R = argr.float_complex_matrix_value ();
662 if (down) 670 if (down)
663 err = fact.downdate (u); 671 err = fact.downdate (u);
664 else 672 else
665 fact.update (u); 673 fact.update (u);
666 674
667 retval(0) = fact.chol_matrix (); 675 retval(0) = get_chol_r (fact);
668 } 676 }
669 } 677 }
670 else 678 else
671 { 679 {
672 if (argr.is_real_type () && argu.is_real_type ()) 680 if (argr.is_real_type () && argu.is_real_type ())
681 if (down) 689 if (down)
682 err = fact.downdate (u); 690 err = fact.downdate (u);
683 else 691 else
684 fact.update (u); 692 fact.update (u);
685 693
686 retval(0) = fact.chol_matrix (); 694 retval(0) = get_chol_r (fact);
687 } 695 }
688 else 696 else
689 { 697 {
690 // complex case 698 // complex case
691 ComplexMatrix R = argr.complex_matrix_value (); 699 ComplexMatrix R = argr.complex_matrix_value ();
697 if (down) 705 if (down)
698 err = fact.downdate (u); 706 err = fact.downdate (u);
699 else 707 else
700 fact.update (u); 708 fact.update (u);
701 709
702 retval(0) = fact.chol_matrix (); 710 retval(0) = get_chol_r (fact);
703 } 711 }
704 } 712 }
705 713
706 if (nargout > 1) 714 if (nargout > 1)
707 retval(1) = err; 715 retval(1) = err;
851 859
852 FloatCHOL fact; 860 FloatCHOL fact;
853 fact.set (R); 861 fact.set (R);
854 err = fact.insert_sym (u, j-1); 862 err = fact.insert_sym (u, j-1);
855 863
856 retval(0) = fact.chol_matrix (); 864 retval(0) = get_chol_r (fact);
857 } 865 }
858 else 866 else
859 { 867 {
860 // complex case 868 // complex case
861 FloatComplexMatrix R = argr.float_complex_matrix_value (); 869 FloatComplexMatrix R = argr.float_complex_matrix_value ();
863 871
864 FloatComplexCHOL fact; 872 FloatComplexCHOL fact;
865 fact.set (R); 873 fact.set (R);
866 err = fact.insert_sym (u, j-1); 874 err = fact.insert_sym (u, j-1);
867 875
868 retval(0) = fact.chol_matrix (); 876 retval(0) = get_chol_r (fact);
869 } 877 }
870 } 878 }
871 else 879 else
872 { 880 {
873 if (argr.is_real_type () && argu.is_real_type ()) 881 if (argr.is_real_type () && argu.is_real_type ())
878 886
879 CHOL fact; 887 CHOL fact;
880 fact.set (R); 888 fact.set (R);
881 err = fact.insert_sym (u, j-1); 889 err = fact.insert_sym (u, j-1);
882 890
883 retval(0) = fact.chol_matrix (); 891 retval(0) = get_chol_r (fact);
884 } 892 }
885 else 893 else
886 { 894 {
887 // complex case 895 // complex case
888 ComplexMatrix R = argr.complex_matrix_value (); 896 ComplexMatrix R = argr.complex_matrix_value ();
890 898
891 ComplexCHOL fact; 899 ComplexCHOL fact;
892 fact.set (R); 900 fact.set (R);
893 err = fact.insert_sym (u, j-1); 901 err = fact.insert_sym (u, j-1);
894 902
895 retval(0) = fact.chol_matrix (); 903 retval(0) = get_chol_r (fact);
896 } 904 }
897 } 905 }
898 906
899 if (nargout > 1) 907 if (nargout > 1)
900 retval(1) = err; 908 retval(1) = err;
1021 1029
1022 FloatCHOL fact; 1030 FloatCHOL fact;
1023 fact.set (R); 1031 fact.set (R);
1024 fact.delete_sym (j-1); 1032 fact.delete_sym (j-1);
1025 1033
1026 retval(0) = fact.chol_matrix (); 1034 retval(0) = get_chol_r (fact);
1027 } 1035 }
1028 else 1036 else
1029 { 1037 {
1030 // complex case 1038 // complex case
1031 FloatComplexMatrix R = argr.float_complex_matrix_value (); 1039 FloatComplexMatrix R = argr.float_complex_matrix_value ();
1032 1040
1033 FloatComplexCHOL fact; 1041 FloatComplexCHOL fact;
1034 fact.set (R); 1042 fact.set (R);
1035 fact.delete_sym (j-1); 1043 fact.delete_sym (j-1);
1036 1044
1037 retval(0) = fact.chol_matrix (); 1045 retval(0) = get_chol_r (fact);
1038 } 1046 }
1039 } 1047 }
1040 else 1048 else
1041 { 1049 {
1042 if (argr.is_real_type ()) 1050 if (argr.is_real_type ())
1046 1054
1047 CHOL fact; 1055 CHOL fact;
1048 fact.set (R); 1056 fact.set (R);
1049 fact.delete_sym (j-1); 1057 fact.delete_sym (j-1);
1050 1058
1051 retval(0) = fact.chol_matrix (); 1059 retval(0) = get_chol_r (fact);
1052 } 1060 }
1053 else 1061 else
1054 { 1062 {
1055 // complex case 1063 // complex case
1056 ComplexMatrix R = argr.complex_matrix_value (); 1064 ComplexMatrix R = argr.complex_matrix_value ();
1057 1065
1058 ComplexCHOL fact; 1066 ComplexCHOL fact;
1059 fact.set (R); 1067 fact.set (R);
1060 fact.delete_sym (j-1); 1068 fact.delete_sym (j-1);
1061 1069
1062 retval(0) = fact.chol_matrix (); 1070 retval(0) = get_chol_r (fact);
1063 } 1071 }
1064 } 1072 }
1065 } 1073 }
1066 else 1074 else
1067 error ("choldelete: index out of range"); 1075 error ("choldelete: index out of range");
1162 1170
1163 FloatCHOL fact; 1171 FloatCHOL fact;
1164 fact.set (R); 1172 fact.set (R);
1165 fact.shift_sym (i-1, j-1); 1173 fact.shift_sym (i-1, j-1);
1166 1174
1167 retval(0) = fact.chol_matrix (); 1175 retval(0) = get_chol_r (fact);
1168 } 1176 }
1169 else 1177 else
1170 { 1178 {
1171 // complex case 1179 // complex case
1172 FloatComplexMatrix R = argr.float_complex_matrix_value (); 1180 FloatComplexMatrix R = argr.float_complex_matrix_value ();
1173 1181
1174 FloatComplexCHOL fact; 1182 FloatComplexCHOL fact;
1175 fact.set (R); 1183 fact.set (R);
1176 fact.shift_sym (i-1, j-1); 1184 fact.shift_sym (i-1, j-1);
1177 1185
1178 retval(0) = fact.chol_matrix (); 1186 retval(0) = get_chol_r (fact);
1179 } 1187 }
1180 } 1188 }
1181 else 1189 else
1182 { 1190 {
1183 if (argr.is_real_type ()) 1191 if (argr.is_real_type ())
1187 1195
1188 CHOL fact; 1196 CHOL fact;
1189 fact.set (R); 1197 fact.set (R);
1190 fact.shift_sym (i-1, j-1); 1198 fact.shift_sym (i-1, j-1);
1191 1199
1192 retval(0) = fact.chol_matrix (); 1200 retval(0) = get_chol_r (fact);
1193 } 1201 }
1194 else 1202 else
1195 { 1203 {
1196 // complex case 1204 // complex case
1197 ComplexMatrix R = argr.complex_matrix_value (); 1205 ComplexMatrix R = argr.complex_matrix_value ();
1198 1206
1199 ComplexCHOL fact; 1207 ComplexCHOL fact;
1200 fact.set (R); 1208 fact.set (R);
1201 fact.shift_sym (i-1, j-1); 1209 fact.shift_sym (i-1, j-1);
1202 1210
1203 retval(0) = fact.chol_matrix (); 1211 retval(0) = get_chol_r (fact);
1204 } 1212 }
1205 } 1213 }
1206 } 1214 }
1207 else 1215 else
1208 error ("cholshift: index out of range"); 1216 error ("cholshift: index out of range");