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