2376
|
1 /* |
|
2 |
2847
|
3 Copyright (C) 1996, 1997 John W. Eaton |
2376
|
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 |
3503
|
31 #include <iostream> |
2901
|
32 |
2376
|
33 #include "lo-ieee.h" |
|
34 #include "mx-base.h" |
|
35 |
|
36 #include "gripes.h" |
|
37 #include "oct-obj.h" |
2410
|
38 #include "ops.h" |
3219
|
39 #include "ov-base.h" |
|
40 #include "ov-base-mat.h" |
|
41 #include "ov-base-mat.cc" |
2410
|
42 #include "ov-complex.h" |
2376
|
43 #include "ov-cx-mat.h" |
2410
|
44 #include "ov-re-mat.h" |
|
45 #include "ov-scalar.h" |
2376
|
46 #include "pr-output.h" |
|
47 |
3219
|
48 template class octave_base_matrix<ComplexMatrix>; |
2376
|
49 |
3219
|
50 DEFINE_OCTAVE_ALLOCATOR (octave_complex_matrix); |
2477
|
51 |
3219
|
52 DEFINE_OV_TYPEID_FUNCTIONS_AND_DATA (octave_complex_matrix, "complex matrix"); |
2376
|
53 |
2410
|
54 octave_value * |
|
55 octave_complex_matrix::try_narrowing_conversion (void) |
|
56 { |
|
57 octave_value *retval = 0; |
|
58 |
|
59 int nr = matrix.rows (); |
|
60 int nc = matrix.cols (); |
|
61 |
|
62 if (nr == 1 && nc == 1) |
|
63 { |
|
64 Complex c = matrix (0, 0); |
|
65 |
|
66 if (imag (c) == 0.0) |
3775
|
67 retval = new octave_scalar (std::real (c)); |
2410
|
68 else |
|
69 retval = new octave_complex (c); |
|
70 } |
3760
|
71 else if (nr == 0 || nc == 0) |
|
72 retval = new octave_matrix (Matrix (nr, nc)); |
2410
|
73 else if (matrix.all_elements_are_real ()) |
|
74 retval = new octave_matrix (::real (matrix)); |
|
75 |
|
76 return retval; |
|
77 } |
2376
|
78 |
3109
|
79 #if !defined (CXX_NEW_FRIEND_TEMPLATE_DECL) |
2410
|
80 extern void assign (Array2<Complex>&, const Array2<Complex>&); |
3107
|
81 #endif |
2410
|
82 |
2376
|
83 void |
|
84 octave_complex_matrix::assign (const octave_value_list& idx, |
|
85 const ComplexMatrix& rhs) |
|
86 { |
|
87 int len = idx.length (); |
|
88 |
|
89 switch (len) |
|
90 { |
|
91 case 2: |
|
92 { |
|
93 idx_vector i = idx (0).index_vector (); |
|
94 idx_vector j = idx (1).index_vector (); |
|
95 |
|
96 matrix.set_index (i); |
|
97 matrix.set_index (j); |
|
98 |
|
99 ::assign (matrix, rhs); |
|
100 } |
|
101 break; |
|
102 |
|
103 case 1: |
|
104 { |
|
105 idx_vector i = idx (0).index_vector (); |
|
106 |
|
107 matrix.set_index (i); |
|
108 |
|
109 ::assign (matrix, rhs); |
|
110 } |
|
111 break; |
|
112 |
|
113 default: |
|
114 error ("invalid number of indices (%d) for indexed matrix assignment", |
|
115 len); |
|
116 break; |
|
117 } |
|
118 } |
|
119 |
3109
|
120 #if !defined (CXX_NEW_FRIEND_TEMPLATE_DECL) |
2376
|
121 extern void assign (Array2<Complex>&, const Array2<double>&); |
3107
|
122 #endif |
2376
|
123 |
|
124 void |
|
125 octave_complex_matrix::assign (const octave_value_list& idx, |
|
126 const Matrix& rhs) |
|
127 { |
|
128 int len = idx.length (); |
|
129 |
|
130 switch (len) |
|
131 { |
|
132 case 2: |
|
133 { |
|
134 idx_vector i = idx (0).index_vector (); |
|
135 idx_vector j = idx (1).index_vector (); |
|
136 |
|
137 matrix.set_index (i); |
|
138 matrix.set_index (j); |
|
139 |
|
140 ::assign (matrix, rhs); |
|
141 } |
|
142 break; |
|
143 |
|
144 case 1: |
|
145 { |
|
146 idx_vector i = idx (0).index_vector (); |
|
147 |
|
148 matrix.set_index (i); |
|
149 |
|
150 ::assign (matrix, rhs); |
|
151 } |
|
152 break; |
|
153 |
|
154 default: |
|
155 error ("invalid number of indices (%d) for indexed matrix assignment", |
|
156 len); |
|
157 break; |
|
158 } |
|
159 } |
|
160 |
|
161 bool |
|
162 octave_complex_matrix::valid_as_scalar_index (void) const |
|
163 { |
|
164 // XXX FIXME XXX |
|
165 return false; |
|
166 } |
|
167 |
|
168 double |
|
169 octave_complex_matrix::double_value (bool force_conversion) const |
|
170 { |
|
171 double retval = octave_NaN; |
|
172 |
|
173 int flag = force_conversion; |
|
174 |
|
175 if (! flag) |
|
176 flag = Vok_to_lose_imaginary_part; |
|
177 |
|
178 if (flag < 0) |
|
179 gripe_implicit_conversion ("complex matrix", "real scalar"); |
|
180 |
|
181 if (flag) |
|
182 { |
|
183 if ((rows () == 1 && columns () == 1) |
|
184 || (Vdo_fortran_indexing && rows () > 0 && columns () > 0)) |
3775
|
185 retval = std::real (matrix (0, 0)); |
2376
|
186 else |
|
187 gripe_invalid_conversion ("complex matrix", "real scalar"); |
|
188 } |
|
189 else |
|
190 gripe_invalid_conversion ("complex matrix", "real scalar"); |
|
191 |
|
192 return retval; |
|
193 } |
|
194 |
|
195 Matrix |
|
196 octave_complex_matrix::matrix_value (bool force_conversion) const |
|
197 { |
|
198 Matrix retval; |
|
199 |
|
200 int flag = force_conversion; |
|
201 |
|
202 if (! flag) |
|
203 flag = Vok_to_lose_imaginary_part; |
|
204 |
|
205 if (flag < 0) |
|
206 gripe_implicit_conversion ("complex matrix", "real matrix"); |
|
207 |
|
208 if (flag) |
|
209 retval = ::real (matrix); |
|
210 else |
|
211 gripe_invalid_conversion ("complex matrix", "real matrix"); |
|
212 |
|
213 return retval; |
|
214 } |
|
215 |
|
216 Complex |
|
217 octave_complex_matrix::complex_value (bool) const |
|
218 { |
|
219 Complex retval (octave_NaN, octave_NaN); |
|
220 |
|
221 if ((rows () == 1 && columns () == 1) |
|
222 || (Vdo_fortran_indexing && rows () > 0 && columns () > 0)) |
|
223 retval = matrix (0, 0); |
|
224 else |
|
225 gripe_invalid_conversion ("complex matrix", "complex scalar"); |
|
226 |
|
227 return retval; |
|
228 } |
|
229 |
|
230 ComplexMatrix |
|
231 octave_complex_matrix::complex_matrix_value (bool) const |
|
232 { |
|
233 return matrix; |
|
234 } |
|
235 |
|
236 /* |
|
237 ;;; Local Variables: *** |
|
238 ;;; mode: C++ *** |
|
239 ;;; End: *** |
|
240 */ |