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 |
4066
|
23 #if defined (__GNUG__) && ! defined (NO_PRAGMA_INTERFACE_IMPLEMENTATION) |
2376
|
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 |
|
79 void |
|
80 octave_complex_matrix::assign (const octave_value_list& idx, |
|
81 const Matrix& rhs) |
|
82 { |
|
83 int len = idx.length (); |
|
84 |
|
85 switch (len) |
|
86 { |
|
87 case 2: |
|
88 { |
|
89 idx_vector i = idx (0).index_vector (); |
|
90 idx_vector j = idx (1).index_vector (); |
|
91 |
|
92 matrix.set_index (i); |
|
93 matrix.set_index (j); |
|
94 |
|
95 ::assign (matrix, rhs); |
|
96 } |
|
97 break; |
|
98 |
|
99 case 1: |
|
100 { |
|
101 idx_vector i = idx (0).index_vector (); |
|
102 |
|
103 matrix.set_index (i); |
|
104 |
|
105 ::assign (matrix, rhs); |
|
106 } |
|
107 break; |
|
108 |
|
109 default: |
|
110 error ("invalid number of indices (%d) for indexed matrix assignment", |
|
111 len); |
|
112 break; |
|
113 } |
|
114 } |
|
115 |
|
116 bool |
|
117 octave_complex_matrix::valid_as_scalar_index (void) const |
|
118 { |
|
119 // XXX FIXME XXX |
|
120 return false; |
|
121 } |
|
122 |
|
123 double |
|
124 octave_complex_matrix::double_value (bool force_conversion) const |
|
125 { |
|
126 double retval = octave_NaN; |
|
127 |
|
128 int flag = force_conversion; |
|
129 |
|
130 if (! flag) |
|
131 flag = Vok_to_lose_imaginary_part; |
|
132 |
|
133 if (flag < 0) |
|
134 gripe_implicit_conversion ("complex matrix", "real scalar"); |
|
135 |
|
136 if (flag) |
|
137 { |
|
138 if ((rows () == 1 && columns () == 1) |
|
139 || (Vdo_fortran_indexing && rows () > 0 && columns () > 0)) |
3775
|
140 retval = std::real (matrix (0, 0)); |
2376
|
141 else |
|
142 gripe_invalid_conversion ("complex matrix", "real scalar"); |
|
143 } |
|
144 else |
|
145 gripe_invalid_conversion ("complex matrix", "real scalar"); |
|
146 |
|
147 return retval; |
|
148 } |
|
149 |
|
150 Matrix |
|
151 octave_complex_matrix::matrix_value (bool force_conversion) const |
|
152 { |
|
153 Matrix retval; |
|
154 |
|
155 int flag = force_conversion; |
|
156 |
|
157 if (! flag) |
|
158 flag = Vok_to_lose_imaginary_part; |
|
159 |
|
160 if (flag < 0) |
|
161 gripe_implicit_conversion ("complex matrix", "real matrix"); |
|
162 |
|
163 if (flag) |
|
164 retval = ::real (matrix); |
|
165 else |
|
166 gripe_invalid_conversion ("complex matrix", "real matrix"); |
|
167 |
|
168 return retval; |
|
169 } |
|
170 |
|
171 Complex |
|
172 octave_complex_matrix::complex_value (bool) const |
|
173 { |
|
174 Complex retval (octave_NaN, octave_NaN); |
|
175 |
|
176 if ((rows () == 1 && columns () == 1) |
|
177 || (Vdo_fortran_indexing && rows () > 0 && columns () > 0)) |
|
178 retval = matrix (0, 0); |
|
179 else |
|
180 gripe_invalid_conversion ("complex matrix", "complex scalar"); |
|
181 |
|
182 return retval; |
|
183 } |
|
184 |
|
185 ComplexMatrix |
|
186 octave_complex_matrix::complex_matrix_value (bool) const |
|
187 { |
|
188 return matrix; |
|
189 } |
|
190 |
|
191 /* |
|
192 ;;; Local Variables: *** |
|
193 ;;; mode: C++ *** |
|
194 ;;; End: *** |
|
195 */ |