1
|
1 // tc-hess.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 |
|
24 #ifdef __GNUG__ |
|
25 #pragma implementation |
|
26 #endif |
|
27 |
|
28 #include "Matrix.h" |
|
29 |
|
30 #include "tree-const.h" |
|
31 #include "user-prefs.h" |
|
32 #include "error.h" |
|
33 #include "gripes.h" |
|
34 |
|
35 #ifdef WITH_DLD |
|
36 tree_constant * |
|
37 builtin_hess_2 (tree_constant *args, int nargin, int nargout) |
|
38 { |
|
39 return hess (args, nargin, nargout); |
|
40 } |
|
41 #endif |
|
42 |
|
43 tree_constant * |
|
44 hess (tree_constant *args, int nargin, int nargout) |
|
45 { |
|
46 tree_constant *retval = NULL_TREE_CONST; |
|
47 |
|
48 tree_constant arg = args[1].make_numeric (); |
|
49 |
|
50 int a_nr = arg.rows (); |
|
51 int a_nc = arg.columns (); |
|
52 |
|
53 if (a_nr == 0 || a_nc == 0) |
|
54 { |
|
55 int flag = user_pref.propagate_empty_matrices; |
|
56 if (flag != 0) |
|
57 { |
|
58 if (flag < 0) |
|
59 warning ("hess: argument is empty matrix"); |
|
60 Matrix m; |
|
61 retval = new tree_constant [3]; |
|
62 retval[0] = tree_constant (m); |
|
63 retval[1] = tree_constant (m); |
|
64 } |
|
65 else |
|
66 error ("hess: empty matrix is invalid as argument"); |
|
67 |
|
68 return retval; |
|
69 } |
|
70 |
|
71 if (a_nr != a_nc) |
|
72 { |
|
73 gripe_square_matrix_required ("hess"); |
|
74 return retval; |
|
75 } |
|
76 |
|
77 Matrix tmp; |
|
78 ComplexMatrix ctmp; |
|
79 |
|
80 switch (arg.const_type ()) |
|
81 { |
|
82 case tree_constant_rep::matrix_constant: |
|
83 { |
|
84 tmp = arg.matrix_value (); |
|
85 |
|
86 HESS result (tmp); |
|
87 |
|
88 if (nargout == 1) |
|
89 { |
|
90 retval = new tree_constant [2]; |
|
91 retval[0] = tree_constant (result.hess_matrix ()); |
|
92 } |
|
93 else |
|
94 { |
|
95 retval = new tree_constant [3]; |
|
96 retval[0] = tree_constant (result.unitary_hess_matrix ()); |
|
97 retval[1] = tree_constant (result.hess_matrix ()); |
|
98 } |
|
99 } |
|
100 break; |
|
101 case tree_constant_rep::complex_matrix_constant: |
|
102 { |
|
103 ctmp = arg.complex_matrix_value (); |
|
104 |
|
105 ComplexHESS result (ctmp); |
|
106 |
|
107 if (nargout == 1) |
|
108 { |
|
109 retval = new tree_constant [2]; |
|
110 retval[0] = tree_constant (result.hess_matrix ()); |
|
111 } |
|
112 else |
|
113 { |
|
114 retval = new tree_constant [3]; |
|
115 retval[0] = tree_constant (result.unitary_hess_matrix ()); |
|
116 retval[1] = tree_constant (result.hess_matrix ()); |
|
117 } |
|
118 } |
|
119 break; |
|
120 case tree_constant_rep::scalar_constant: |
|
121 { |
|
122 double d = arg.double_value (); |
|
123 if (nargout == 1) |
|
124 { |
|
125 retval = new tree_constant [2]; |
|
126 retval[0] = tree_constant (d); |
|
127 } |
|
128 else |
|
129 { |
|
130 retval = new tree_constant [3]; |
|
131 retval[0] = tree_constant (1); |
|
132 retval[1] = tree_constant (d); |
|
133 } |
|
134 } |
|
135 break; |
|
136 case tree_constant_rep::complex_scalar_constant: |
|
137 { |
|
138 Complex c = arg.complex_value (); |
|
139 if (nargout == 1) |
|
140 { |
|
141 retval = new tree_constant [2]; |
|
142 retval[0] = tree_constant (c); |
|
143 } |
|
144 else |
|
145 { |
|
146 retval = new tree_constant [3]; |
|
147 retval[0] = tree_constant (1); |
|
148 retval[1] = tree_constant (c); |
|
149 } |
|
150 } |
|
151 break; |
|
152 default: |
|
153 panic_impossible (); |
|
154 break; |
|
155 } |
|
156 return retval; |
|
157 } |
|
158 |
|
159 /* |
|
160 ;;; Local Variables: *** |
|
161 ;;; mode: C++ *** |
|
162 ;;; page-delimiter: "^/\\*" *** |
|
163 ;;; End: *** |
|
164 */ |