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 |
4192
|
23 #if defined (__GNUG__) && defined (USE_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 |
4513
|
48 template class octave_base_matrix<ComplexNDArray>; |
2376
|
49 |
3219
|
50 DEFINE_OCTAVE_ALLOCATOR (octave_complex_matrix); |
2477
|
51 |
4612
|
52 DEFINE_OV_TYPEID_FUNCTIONS_AND_DATA (octave_complex_matrix, |
|
53 "complex matrix", "double"); |
2376
|
54 |
2410
|
55 octave_value * |
|
56 octave_complex_matrix::try_narrowing_conversion (void) |
|
57 { |
|
58 octave_value *retval = 0; |
|
59 |
4513
|
60 if (matrix.ndims () == 2) |
|
61 { |
|
62 ComplexMatrix cm = matrix.matrix_value (); |
2410
|
63 |
4513
|
64 int nr = cm.rows (); |
|
65 int nc = cm.cols (); |
|
66 |
|
67 if (nr == 1 && nc == 1) |
|
68 { |
|
69 Complex c = matrix (0, 0); |
2410
|
70 |
4513
|
71 if (imag (c) == 0.0) |
|
72 retval = new octave_scalar (std::real (c)); |
|
73 else |
|
74 retval = new octave_complex (c); |
|
75 } |
|
76 else if (nr == 0 || nc == 0) |
|
77 retval = new octave_matrix (Matrix (nr, nc)); |
|
78 else if (cm.all_elements_are_real ()) |
|
79 retval = new octave_matrix (::real (cm)); |
2410
|
80 } |
|
81 |
|
82 return retval; |
|
83 } |
2376
|
84 |
|
85 void |
|
86 octave_complex_matrix::assign (const octave_value_list& idx, |
4686
|
87 const ComplexNDArray& rhs) |
4418
|
88 { |
4513
|
89 octave_base_matrix<ComplexNDArray>::assign (idx, rhs); |
4418
|
90 } |
|
91 |
|
92 void |
|
93 octave_complex_matrix::assign (const octave_value_list& idx, |
4686
|
94 const NDArray& rhs) |
2376
|
95 { |
|
96 int len = idx.length (); |
|
97 |
4513
|
98 for (int i = 0; i < len; i++) |
|
99 matrix.set_index (idx(i).index_vector ()); |
2376
|
100 |
4513
|
101 ::assign (matrix, rhs); |
2376
|
102 } |
|
103 |
|
104 bool |
|
105 octave_complex_matrix::valid_as_scalar_index (void) const |
|
106 { |
|
107 // XXX FIXME XXX |
|
108 return false; |
|
109 } |
|
110 |
|
111 double |
|
112 octave_complex_matrix::double_value (bool force_conversion) const |
|
113 { |
4102
|
114 double retval = lo_ieee_nan_value (); |
2376
|
115 |
4451
|
116 if (! force_conversion && Vwarn_imag_to_real) |
2376
|
117 gripe_implicit_conversion ("complex matrix", "real scalar"); |
|
118 |
4455
|
119 // XXX FIXME XXX -- maybe this should be a function, valid_as_scalar() |
|
120 if (rows () > 0 && columns () > 0) |
|
121 { |
|
122 // XXX FIXME XXX -- is warn_fortran_indexing the right variable here? |
|
123 if (Vwarn_fortran_indexing) |
|
124 gripe_implicit_conversion ("complex matrix", "real scalar"); |
|
125 |
|
126 retval = std::real (matrix (0, 0)); |
|
127 } |
2376
|
128 else |
|
129 gripe_invalid_conversion ("complex matrix", "real scalar"); |
|
130 |
|
131 return retval; |
|
132 } |
|
133 |
|
134 Matrix |
|
135 octave_complex_matrix::matrix_value (bool force_conversion) const |
|
136 { |
|
137 Matrix retval; |
|
138 |
4451
|
139 if (! force_conversion && Vwarn_imag_to_real) |
2376
|
140 gripe_implicit_conversion ("complex matrix", "real matrix"); |
|
141 |
4513
|
142 retval = ::real (matrix.matrix_value ()); |
2376
|
143 |
|
144 return retval; |
|
145 } |
|
146 |
|
147 Complex |
|
148 octave_complex_matrix::complex_value (bool) const |
|
149 { |
4102
|
150 double tmp = lo_ieee_nan_value (); |
|
151 |
|
152 Complex retval (tmp, tmp); |
2376
|
153 |
4455
|
154 // XXX FIXME XXX -- maybe this should be a function, valid_as_scalar() |
|
155 if (rows () > 0 && columns () > 0) |
|
156 { |
|
157 // XXX FIXME XXX -- is warn_fortran_indexing the right variable here? |
|
158 if (Vwarn_fortran_indexing) |
|
159 gripe_implicit_conversion ("complex matrix", "complex scalar"); |
|
160 |
|
161 retval = matrix (0, 0); |
|
162 } |
2376
|
163 else |
|
164 gripe_invalid_conversion ("complex matrix", "complex scalar"); |
|
165 |
|
166 return retval; |
|
167 } |
|
168 |
|
169 ComplexMatrix |
|
170 octave_complex_matrix::complex_matrix_value (bool) const |
|
171 { |
4513
|
172 return matrix.matrix_value (); |
2376
|
173 } |
|
174 |
4643
|
175 void |
|
176 octave_complex_matrix::print_raw (std::ostream& os, |
|
177 bool pr_as_read_syntax) const |
|
178 { |
|
179 octave_print_internal (os, matrix, pr_as_read_syntax, |
|
180 current_print_indent_level ()); |
|
181 } |
|
182 |
2376
|
183 /* |
|
184 ;;; Local Variables: *** |
|
185 ;;; mode: C++ *** |
|
186 ;;; End: *** |
|
187 */ |