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