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