180
|
1 // f-chol.cc -*- C++ -*- |
|
2 /* |
|
3 |
453
|
4 Copyright (C) 1993, 1994 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 |
|
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" |
|
35 #include "f-chol.h" |
|
36 |
|
37 #ifdef WITH_DLD |
497
|
38 Octave_object* |
506
|
39 builtin_chol_2 (const Octave_object& args, int nargout) |
180
|
40 { |
497
|
41 Octave_object retval (1); |
|
42 retval(0) = chol (args(1)); |
|
43 return retval; |
180
|
44 } |
|
45 #endif |
|
46 |
497
|
47 tree_constant |
|
48 chol (const tree_constant& a) |
180
|
49 { |
497
|
50 tree_constant retval; |
180
|
51 |
497
|
52 tree_constant tmp = a.make_numeric ();; |
180
|
53 |
|
54 int nr = tmp.rows (); |
|
55 int nc = tmp.columns (); |
|
56 |
|
57 if (nr == 0 || nc == 0) |
|
58 { |
|
59 int flag = user_pref.propagate_empty_matrices; |
|
60 if (flag != 0) |
|
61 { |
|
62 if (flag < 0) |
|
63 gripe_empty_arg ("chol", 0); |
|
64 Matrix m; |
516
|
65 retval = m; |
180
|
66 } |
|
67 else |
|
68 gripe_empty_arg ("chol", 1); |
|
69 |
|
70 return retval; |
|
71 } |
|
72 |
|
73 switch (tmp.const_type ()) |
|
74 { |
|
75 case tree_constant_rep::matrix_constant: |
|
76 { |
|
77 Matrix m = tmp.matrix_value (); |
|
78 int info; |
|
79 CHOL fact (m, info); |
|
80 if (info != 0) |
|
81 error ("chol: matrix not positive definite"); |
|
82 else |
516
|
83 retval = fact.chol_matrix (); |
180
|
84 } |
|
85 break; |
|
86 case tree_constant_rep::complex_matrix_constant: |
|
87 { |
|
88 ComplexMatrix m = tmp.complex_matrix_value (); |
|
89 int info; |
|
90 ComplexCHOL fact (m, info); |
|
91 if (info != 0) |
|
92 error ("chol: matrix not positive definite"); |
|
93 else |
516
|
94 retval = fact.chol_matrix (); |
180
|
95 } |
|
96 break; |
|
97 case tree_constant_rep::scalar_constant: |
|
98 { |
|
99 double d = tmp.double_value (); |
516
|
100 retval = d; |
180
|
101 } |
|
102 break; |
|
103 case tree_constant_rep::complex_scalar_constant: |
|
104 { |
|
105 Complex c = tmp.complex_value (); |
516
|
106 retval = c; |
180
|
107 } |
|
108 break; |
|
109 default: |
|
110 break; |
|
111 } |
|
112 return retval; |
|
113 } |
|
114 |
|
115 /* |
|
116 ;;; Local Variables: *** |
|
117 ;;; mode: C++ *** |
|
118 ;;; page-delimiter: "^/\\*" *** |
|
119 ;;; End: *** |
|
120 */ |
|
121 |