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 (); |
2407
|
70 |
2376
|
71 retval = ComplexMatrix (matrix.index (i, j)); |
|
72 } |
|
73 break; |
|
74 |
|
75 case 1: |
|
76 { |
|
77 idx_vector i = idx (0).index_vector (); |
2407
|
78 |
2376
|
79 retval = ComplexMatrix (matrix.index (i)); |
|
80 } |
|
81 break; |
|
82 |
|
83 default: |
|
84 error ("invalid number of indices (%d) for complex matrix value", len); |
|
85 break; |
|
86 } |
|
87 |
|
88 return retval; |
|
89 } |
|
90 |
|
91 void |
|
92 octave_complex_matrix::assign (const octave_value_list& idx, |
|
93 const ComplexMatrix& rhs) |
|
94 { |
|
95 int len = idx.length (); |
|
96 |
|
97 switch (len) |
|
98 { |
|
99 case 2: |
|
100 { |
|
101 idx_vector i = idx (0).index_vector (); |
|
102 idx_vector j = idx (1).index_vector (); |
|
103 |
|
104 matrix.set_index (i); |
|
105 matrix.set_index (j); |
|
106 |
|
107 ::assign (matrix, rhs); |
|
108 } |
|
109 break; |
|
110 |
|
111 case 1: |
|
112 { |
|
113 idx_vector i = idx (0).index_vector (); |
|
114 |
|
115 matrix.set_index (i); |
|
116 |
|
117 ::assign (matrix, rhs); |
|
118 } |
|
119 break; |
|
120 |
|
121 default: |
|
122 error ("invalid number of indices (%d) for indexed matrix assignment", |
|
123 len); |
|
124 break; |
|
125 } |
|
126 } |
|
127 |
|
128 extern void assign (Array2<Complex>&, const Array2<double>&); |
|
129 |
|
130 void |
|
131 octave_complex_matrix::assign (const octave_value_list& idx, |
|
132 const Matrix& rhs) |
|
133 { |
|
134 int len = idx.length (); |
|
135 |
|
136 switch (len) |
|
137 { |
|
138 case 2: |
|
139 { |
|
140 idx_vector i = idx (0).index_vector (); |
|
141 idx_vector j = idx (1).index_vector (); |
|
142 |
|
143 matrix.set_index (i); |
|
144 matrix.set_index (j); |
|
145 |
|
146 ::assign (matrix, rhs); |
|
147 } |
|
148 break; |
|
149 |
|
150 case 1: |
|
151 { |
|
152 idx_vector i = idx (0).index_vector (); |
|
153 |
|
154 matrix.set_index (i); |
|
155 |
|
156 ::assign (matrix, rhs); |
|
157 } |
|
158 break; |
|
159 |
|
160 default: |
|
161 error ("invalid number of indices (%d) for indexed matrix assignment", |
|
162 len); |
|
163 break; |
|
164 } |
|
165 } |
|
166 |
|
167 bool |
|
168 octave_complex_matrix::valid_as_scalar_index (void) const |
|
169 { |
|
170 // XXX FIXME XXX |
|
171 return false; |
|
172 } |
|
173 |
|
174 bool |
|
175 octave_complex_matrix::valid_as_zero_index (void) const |
|
176 { |
|
177 // XXX FIXME XXX |
|
178 return false; |
|
179 } |
|
180 |
|
181 bool |
|
182 octave_complex_matrix::is_true (void) const |
|
183 { |
|
184 bool retval = false; |
|
185 |
|
186 if (rows () == 0 || columns () == 0) |
|
187 { |
|
188 int flag = Vpropagate_empty_matrices; |
|
189 |
|
190 if (flag < 0) |
|
191 warning ("empty matrix used in conditional expression"); |
|
192 else if (flag == 0) |
|
193 error ("empty matrix used in conditional expression"); |
|
194 } |
|
195 else |
|
196 { |
|
197 Matrix m = (matrix.all ()) . all (); |
|
198 |
|
199 retval = (m.rows () == 1 && m.columns () == 1 && m (0, 0) != 0.0); |
|
200 } |
|
201 |
|
202 return retval; |
|
203 } |
|
204 |
|
205 double |
|
206 octave_complex_matrix::double_value (bool force_conversion) const |
|
207 { |
|
208 double retval = octave_NaN; |
|
209 |
|
210 int flag = force_conversion; |
|
211 |
|
212 if (! flag) |
|
213 flag = Vok_to_lose_imaginary_part; |
|
214 |
|
215 if (flag < 0) |
|
216 gripe_implicit_conversion ("complex matrix", "real scalar"); |
|
217 |
|
218 if (flag) |
|
219 { |
|
220 if ((rows () == 1 && columns () == 1) |
|
221 || (Vdo_fortran_indexing && rows () > 0 && columns () > 0)) |
|
222 retval = ::real (matrix (0, 0)); |
|
223 else |
|
224 gripe_invalid_conversion ("complex matrix", "real scalar"); |
|
225 } |
|
226 else |
|
227 gripe_invalid_conversion ("complex matrix", "real scalar"); |
|
228 |
|
229 return retval; |
|
230 } |
|
231 |
|
232 Matrix |
|
233 octave_complex_matrix::matrix_value (bool force_conversion) const |
|
234 { |
|
235 Matrix retval; |
|
236 |
|
237 int flag = force_conversion; |
|
238 |
|
239 if (! flag) |
|
240 flag = Vok_to_lose_imaginary_part; |
|
241 |
|
242 if (flag < 0) |
|
243 gripe_implicit_conversion ("complex matrix", "real matrix"); |
|
244 |
|
245 if (flag) |
|
246 retval = ::real (matrix); |
|
247 else |
|
248 gripe_invalid_conversion ("complex matrix", "real matrix"); |
|
249 |
|
250 return retval; |
|
251 } |
|
252 |
|
253 Complex |
|
254 octave_complex_matrix::complex_value (bool) const |
|
255 { |
|
256 Complex retval (octave_NaN, octave_NaN); |
|
257 |
|
258 if ((rows () == 1 && columns () == 1) |
|
259 || (Vdo_fortran_indexing && rows () > 0 && columns () > 0)) |
|
260 retval = matrix (0, 0); |
|
261 else |
|
262 gripe_invalid_conversion ("complex matrix", "complex scalar"); |
|
263 |
|
264 return retval; |
|
265 } |
|
266 |
|
267 ComplexMatrix |
|
268 octave_complex_matrix::complex_matrix_value (bool) const |
|
269 { |
|
270 return matrix; |
|
271 } |
|
272 |
|
273 void |
|
274 octave_complex_matrix::print (ostream& os) |
|
275 { |
|
276 octave_print_internal (os, matrix, false, struct_indent); |
|
277 } |
|
278 |
|
279 /* |
|
280 ;;; Local Variables: *** |
|
281 ;;; mode: C++ *** |
|
282 ;;; End: *** |
|
283 */ |