2376
|
1 /* |
|
2 |
|
3 Copyright (C) 1996 John W. Eaton |
|
4 |
|
5 This file is part of Octave. |
|
6 |
|
7 Octave is free software; you can redistribute it and/or modify it |
|
8 under the terms of the GNU General Public License as published by the |
|
9 Free Software Foundation; either version 2, or (at your option) any |
|
10 later version. |
|
11 |
|
12 Octave is distributed in the hope that it will be useful, but WITHOUT |
|
13 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
|
14 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
|
15 for more details. |
|
16 |
|
17 You should have received a copy of the GNU General Public License |
|
18 along with Octave; see the file COPYING. If not, write to the Free |
|
19 Software Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. |
|
20 |
|
21 */ |
|
22 |
|
23 #if defined (__GNUG__) |
|
24 #pragma implementation |
|
25 #endif |
|
26 |
|
27 #ifdef HAVE_CONFIG_H |
|
28 #include <config.h> |
|
29 #endif |
|
30 |
|
31 #include "lo-ieee.h" |
|
32 #include "mx-base.h" |
|
33 |
|
34 #include "gripes.h" |
|
35 #include "oct-obj.h" |
|
36 #include "ov-cx-mat.h" |
|
37 #include "pr-output.h" |
|
38 |
|
39 int octave_complex_matrix::t_id = -1; |
|
40 |
|
41 const string octave_complex_matrix::t_name ("complex matrix"); |
|
42 |
|
43 octave_complex_matrix::octave_complex_matrix (const ComplexRowVector& v, |
|
44 int pcv) |
|
45 : octave_base_value (), |
|
46 matrix ((pcv < 0 && Vprefer_column_vectors) || pcv |
|
47 ? ComplexMatrix (v.transpose ()) : ComplexMatrix (v)) { } |
|
48 |
|
49 octave_complex_matrix::octave_complex_matrix (const ComplexColumnVector& v, |
|
50 int pcv) |
|
51 : octave_base_value (), |
|
52 matrix ((pcv < 0 && Vprefer_column_vectors) || pcv |
|
53 ? ComplexMatrix (v) : ComplexMatrix (v.transpose ())) { } |
|
54 |
|
55 extern void assign (Array2<Complex>&, const Array2<Complex>&); |
|
56 |
|
57 octave_value |
|
58 octave_complex_matrix::index (const octave_value_list& idx) const |
|
59 { |
|
60 octave_value retval; |
|
61 |
|
62 int len = idx.length (); |
|
63 |
|
64 switch (len) |
|
65 { |
|
66 case 2: |
|
67 { |
|
68 idx_vector i = idx (0).index_vector (); |
|
69 idx_vector j = idx (1).index_vector (); |
|
70 retval = ComplexMatrix (matrix.index (i, j)); |
|
71 } |
|
72 break; |
|
73 |
|
74 case 1: |
|
75 { |
|
76 idx_vector i = idx (0).index_vector (); |
|
77 retval = ComplexMatrix (matrix.index (i)); |
|
78 } |
|
79 break; |
|
80 |
|
81 default: |
|
82 error ("invalid number of indices (%d) for complex matrix value", len); |
|
83 break; |
|
84 } |
|
85 |
|
86 return retval; |
|
87 } |
|
88 |
|
89 void |
|
90 octave_complex_matrix::assign (const octave_value_list& idx, |
|
91 const ComplexMatrix& rhs) |
|
92 { |
|
93 int len = idx.length (); |
|
94 |
|
95 switch (len) |
|
96 { |
|
97 case 2: |
|
98 { |
|
99 idx_vector i = idx (0).index_vector (); |
|
100 idx_vector j = idx (1).index_vector (); |
|
101 |
|
102 matrix.set_index (i); |
|
103 matrix.set_index (j); |
|
104 |
|
105 ::assign (matrix, rhs); |
|
106 } |
|
107 break; |
|
108 |
|
109 case 1: |
|
110 { |
|
111 idx_vector i = idx (0).index_vector (); |
|
112 |
|
113 matrix.set_index (i); |
|
114 |
|
115 ::assign (matrix, rhs); |
|
116 } |
|
117 break; |
|
118 |
|
119 default: |
|
120 error ("invalid number of indices (%d) for indexed matrix assignment", |
|
121 len); |
|
122 break; |
|
123 } |
|
124 } |
|
125 |
|
126 extern void assign (Array2<Complex>&, const Array2<double>&); |
|
127 |
|
128 void |
|
129 octave_complex_matrix::assign (const octave_value_list& idx, |
|
130 const Matrix& rhs) |
|
131 { |
|
132 int len = idx.length (); |
|
133 |
|
134 switch (len) |
|
135 { |
|
136 case 2: |
|
137 { |
|
138 idx_vector i = idx (0).index_vector (); |
|
139 idx_vector j = idx (1).index_vector (); |
|
140 |
|
141 matrix.set_index (i); |
|
142 matrix.set_index (j); |
|
143 |
|
144 ::assign (matrix, rhs); |
|
145 } |
|
146 break; |
|
147 |
|
148 case 1: |
|
149 { |
|
150 idx_vector i = idx (0).index_vector (); |
|
151 |
|
152 matrix.set_index (i); |
|
153 |
|
154 ::assign (matrix, rhs); |
|
155 } |
|
156 break; |
|
157 |
|
158 default: |
|
159 error ("invalid number of indices (%d) for indexed matrix assignment", |
|
160 len); |
|
161 break; |
|
162 } |
|
163 } |
|
164 |
|
165 bool |
|
166 octave_complex_matrix::valid_as_scalar_index (void) const |
|
167 { |
|
168 // XXX FIXME XXX |
|
169 return false; |
|
170 } |
|
171 |
|
172 bool |
|
173 octave_complex_matrix::valid_as_zero_index (void) const |
|
174 { |
|
175 // XXX FIXME XXX |
|
176 return false; |
|
177 } |
|
178 |
|
179 bool |
|
180 octave_complex_matrix::is_true (void) const |
|
181 { |
|
182 bool retval = false; |
|
183 |
|
184 if (rows () == 0 || columns () == 0) |
|
185 { |
|
186 int flag = Vpropagate_empty_matrices; |
|
187 |
|
188 if (flag < 0) |
|
189 warning ("empty matrix used in conditional expression"); |
|
190 else if (flag == 0) |
|
191 error ("empty matrix used in conditional expression"); |
|
192 } |
|
193 else |
|
194 { |
|
195 Matrix m = (matrix.all ()) . all (); |
|
196 |
|
197 retval = (m.rows () == 1 && m.columns () == 1 && m (0, 0) != 0.0); |
|
198 } |
|
199 |
|
200 return retval; |
|
201 } |
|
202 |
|
203 double |
|
204 octave_complex_matrix::double_value (bool force_conversion) const |
|
205 { |
|
206 double retval = octave_NaN; |
|
207 |
|
208 int flag = force_conversion; |
|
209 |
|
210 if (! flag) |
|
211 flag = Vok_to_lose_imaginary_part; |
|
212 |
|
213 if (flag < 0) |
|
214 gripe_implicit_conversion ("complex matrix", "real scalar"); |
|
215 |
|
216 if (flag) |
|
217 { |
|
218 if ((rows () == 1 && columns () == 1) |
|
219 || (Vdo_fortran_indexing && rows () > 0 && columns () > 0)) |
|
220 retval = ::real (matrix (0, 0)); |
|
221 else |
|
222 gripe_invalid_conversion ("complex matrix", "real scalar"); |
|
223 } |
|
224 else |
|
225 gripe_invalid_conversion ("complex matrix", "real scalar"); |
|
226 |
|
227 return retval; |
|
228 } |
|
229 |
|
230 Matrix |
|
231 octave_complex_matrix::matrix_value (bool force_conversion) const |
|
232 { |
|
233 Matrix retval; |
|
234 |
|
235 int flag = force_conversion; |
|
236 |
|
237 if (! flag) |
|
238 flag = Vok_to_lose_imaginary_part; |
|
239 |
|
240 if (flag < 0) |
|
241 gripe_implicit_conversion ("complex matrix", "real matrix"); |
|
242 |
|
243 if (flag) |
|
244 retval = ::real (matrix); |
|
245 else |
|
246 gripe_invalid_conversion ("complex matrix", "real matrix"); |
|
247 |
|
248 return retval; |
|
249 } |
|
250 |
|
251 Complex |
|
252 octave_complex_matrix::complex_value (bool) const |
|
253 { |
|
254 Complex retval (octave_NaN, octave_NaN); |
|
255 |
|
256 if ((rows () == 1 && columns () == 1) |
|
257 || (Vdo_fortran_indexing && rows () > 0 && columns () > 0)) |
|
258 retval = matrix (0, 0); |
|
259 else |
|
260 gripe_invalid_conversion ("complex matrix", "complex scalar"); |
|
261 |
|
262 return retval; |
|
263 } |
|
264 |
|
265 ComplexMatrix |
|
266 octave_complex_matrix::complex_matrix_value (bool) const |
|
267 { |
|
268 return matrix; |
|
269 } |
|
270 |
|
271 void |
|
272 octave_complex_matrix::print (ostream& os) |
|
273 { |
|
274 octave_print_internal (os, matrix, false, struct_indent); |
|
275 } |
|
276 |
|
277 /* |
|
278 ;;; Local Variables: *** |
|
279 ;;; mode: C++ *** |
|
280 ;;; End: *** |
|
281 */ |