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