180
|
1 // f-chol.cc -*- C++ -*- |
|
2 /* |
|
3 |
1009
|
4 Copyright (C) 1993, 1994, 1995 John W. Eaton |
180
|
5 |
|
6 This file is part of Octave. |
|
7 |
|
8 Octave is free software; you can redistribute it and/or modify it |
|
9 under the terms of the GNU General Public License as published by the |
|
10 Free Software Foundation; either version 2, or (at your option) any |
|
11 later version. |
|
12 |
|
13 Octave is distributed in the hope that it will be useful, but WITHOUT |
|
14 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
|
15 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
|
16 for more details. |
|
17 |
|
18 You should have received a copy of the GNU General Public License |
|
19 along with Octave; see the file COPYING. If not, write to the Free |
|
20 Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA. |
|
21 |
|
22 */ |
|
23 |
240
|
24 #ifdef HAVE_CONFIG_H |
1192
|
25 #include <config.h> |
180
|
26 #endif |
|
27 |
453
|
28 #include "dbleCHOL.h" |
|
29 #include "CmplxCHOL.h" |
180
|
30 |
|
31 #include "tree-const.h" |
|
32 #include "user-prefs.h" |
|
33 #include "gripes.h" |
|
34 #include "error.h" |
636
|
35 #include "utils.h" |
544
|
36 #include "help.h" |
519
|
37 #include "defun-dld.h" |
180
|
38 |
701
|
39 DEFUN_DLD_BUILTIN ("chol", Fchol, Schol, 2, 1, |
519
|
40 "R = chol (X): cholesky factorization") |
180
|
41 { |
519
|
42 Octave_object retval; |
|
43 |
712
|
44 int nargin = args.length (); |
|
45 |
|
46 if (nargin != 1 || nargout > 1) |
519
|
47 { |
|
48 print_usage ("chol"); |
|
49 return retval; |
|
50 } |
180
|
51 |
712
|
52 tree_constant arg = args(0); |
180
|
53 |
636
|
54 int nr = arg.rows (); |
|
55 int nc = arg.columns (); |
180
|
56 |
718
|
57 int arg_is_empty = empty_arg ("chol", nr, nc); |
|
58 |
|
59 if (arg_is_empty < 0) |
636
|
60 return retval; |
718
|
61 if (arg_is_empty > 0) |
|
62 return Matrix (); |
519
|
63 |
636
|
64 if (arg.is_real_type ()) |
620
|
65 { |
636
|
66 Matrix m = arg.matrix_value (); |
|
67 |
|
68 if (! error_state) |
|
69 { |
|
70 int info; |
|
71 CHOL fact (m, info); |
|
72 if (info != 0) |
|
73 error ("chol: matrix not positive definite"); |
|
74 else |
|
75 retval = fact.chol_matrix (); |
|
76 } |
620
|
77 } |
636
|
78 else if (arg.is_complex_type ()) |
180
|
79 { |
636
|
80 ComplexMatrix m = arg.complex_matrix_value (); |
|
81 |
|
82 if (! error_state) |
|
83 { |
|
84 int info; |
|
85 ComplexCHOL fact (m, info); |
|
86 if (info != 0) |
|
87 error ("chol: matrix not positive definite"); |
|
88 else |
|
89 retval = fact.chol_matrix (); |
|
90 } |
620
|
91 } |
|
92 else |
|
93 { |
636
|
94 gripe_wrong_type_arg ("chol", arg); |
620
|
95 } |
|
96 |
180
|
97 return retval; |
|
98 } |
|
99 |
|
100 /* |
|
101 ;;; Local Variables: *** |
|
102 ;;; mode: C++ *** |
|
103 ;;; page-delimiter: "^/\\*" *** |
|
104 ;;; End: *** |
|
105 */ |
|
106 |