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 |
2825
|
31 #include "mx-cm-m.h" |
|
32 #include "mx-m-cm.h" |
|
33 |
2376
|
34 #include "gripes.h" |
|
35 #include "ov.h" |
|
36 #include "ov-cx-mat.h" |
|
37 #include "ov-re-mat.h" |
|
38 #include "ov-typeinfo.h" |
|
39 #include "op-cm-m.h" |
|
40 #include "ops.h" |
|
41 #include "xdiv.h" |
|
42 #include "xpow.h" |
|
43 |
|
44 // complex matrix by matrix ops. |
|
45 |
|
46 static octave_value |
|
47 add (const octave_value& a1, const octave_value& a2) |
|
48 { |
|
49 CAST_BINOP_ARGS (const octave_complex_matrix&, const octave_matrix&); |
|
50 |
|
51 return octave_value (v1.complex_matrix_value () + v2.matrix_value ()); |
|
52 } |
|
53 |
|
54 static octave_value |
|
55 sub (const octave_value& a1, const octave_value& a2) |
|
56 { |
|
57 CAST_BINOP_ARGS (const octave_complex_matrix&, const octave_matrix&); |
|
58 |
|
59 return octave_value (v1.complex_matrix_value () - v2.matrix_value ()); |
|
60 } |
|
61 |
|
62 static octave_value |
|
63 mul (const octave_value& a1, const octave_value& a2) |
|
64 { |
|
65 CAST_BINOP_ARGS (const octave_complex_matrix&, const octave_matrix&); |
|
66 |
|
67 return octave_value (v1.complex_matrix_value () * v2.matrix_value ()); |
|
68 } |
|
69 |
|
70 static octave_value |
|
71 div (const octave_value& a1, const octave_value& a2) |
|
72 { |
|
73 CAST_BINOP_ARGS (const octave_complex_matrix&, const octave_matrix&); |
|
74 |
|
75 return xdiv (v1.complex_matrix_value (), v2.matrix_value ()); |
|
76 } |
|
77 |
|
78 static octave_value |
|
79 pow (const octave_value&, const octave_value&) |
|
80 { |
|
81 error ("can't do A ^ B for A and B both matrices"); |
|
82 return octave_value (); |
|
83 } |
|
84 |
|
85 static octave_value |
|
86 ldiv (const octave_value& a1, const octave_value& a2) |
|
87 { |
|
88 CAST_BINOP_ARGS (const octave_complex_matrix&, const octave_matrix&); |
|
89 |
|
90 return xleftdiv (v1.complex_matrix_value (), v2.matrix_value ()); |
|
91 } |
|
92 |
2613
|
93 #define BOOL_OP(OP, ONE_EMPTY_RESULT, TWO_EMPTY_RESULT) \ |
2376
|
94 MX_MX_BOOL_OP (ComplexMatrix, m1, v1.complex_matrix_value (), \ |
|
95 Matrix, m2, v2.matrix_value (), \ |
2613
|
96 real (m1 (i, j)) OP m2 (i, j), #OP, \ |
|
97 ONE_EMPTY_RESULT, TWO_EMPTY_RESULT) |
2376
|
98 |
|
99 static octave_value |
|
100 lt (const octave_value& a1, const octave_value& a2) |
|
101 { |
|
102 CAST_BINOP_ARGS (const octave_complex_matrix&, const octave_matrix&); |
|
103 |
2825
|
104 BOOL_OP (<, boolMatrix (), boolMatrix ()); |
2376
|
105 } |
|
106 |
|
107 static octave_value |
|
108 le (const octave_value& a1, const octave_value& a2) |
|
109 { |
|
110 CAST_BINOP_ARGS (const octave_complex_matrix&, const octave_matrix&); |
|
111 |
2825
|
112 BOOL_OP (<=, boolMatrix (), boolMatrix ()); |
2376
|
113 } |
|
114 |
|
115 static octave_value |
|
116 eq (const octave_value& a1, const octave_value& a2) |
|
117 { |
|
118 CAST_BINOP_ARGS (const octave_complex_matrix&, const octave_matrix&); |
|
119 |
2613
|
120 MX_MX_BOOL_OP (ComplexMatrix, m1, v1.complex_matrix_value (), |
|
121 Matrix, m2, v2.matrix_value (), |
|
122 m1 (i, j) == m2 (i, j), "==", |
|
123 0.0, 1.0); |
2376
|
124 } |
|
125 |
|
126 static octave_value |
|
127 ge (const octave_value& a1, const octave_value& a2) |
|
128 { |
|
129 CAST_BINOP_ARGS (const octave_complex_matrix&, const octave_matrix&); |
|
130 |
2825
|
131 BOOL_OP (>=, boolMatrix (), boolMatrix ()); |
2376
|
132 } |
|
133 |
|
134 static octave_value |
|
135 gt (const octave_value& a1, const octave_value& a2) |
|
136 { |
|
137 CAST_BINOP_ARGS (const octave_complex_matrix&, const octave_matrix&); |
|
138 |
2825
|
139 BOOL_OP (>, boolMatrix (), boolMatrix ()); |
2376
|
140 } |
|
141 |
|
142 static octave_value |
|
143 ne (const octave_value& a1, const octave_value& a2) |
|
144 { |
|
145 CAST_BINOP_ARGS (const octave_complex_matrix&, const octave_matrix&); |
|
146 |
2613
|
147 MX_MX_BOOL_OP (ComplexMatrix, m1, v1.complex_matrix_value (), |
|
148 Matrix, m2, v2.matrix_value (), |
|
149 m1 (i, j) != m2 (i, j), "!=", |
|
150 1.0, 0.0); |
2376
|
151 } |
|
152 |
|
153 static octave_value |
|
154 el_mul (const octave_value& a1, const octave_value& a2) |
|
155 { |
|
156 CAST_BINOP_ARGS (const octave_complex_matrix&, const octave_matrix&); |
|
157 |
|
158 return product (v1.complex_matrix_value (), v2.matrix_value ()); |
|
159 } |
|
160 |
|
161 static octave_value |
|
162 el_div (const octave_value& a1, const octave_value& a2) |
|
163 { |
|
164 CAST_BINOP_ARGS (const octave_complex_matrix&, const octave_matrix&); |
|
165 |
|
166 return quotient (v1.complex_matrix_value (), v2.matrix_value ()); |
|
167 } |
|
168 |
|
169 static octave_value |
|
170 el_pow (const octave_value& a1, const octave_value& a2) |
|
171 { |
|
172 CAST_BINOP_ARGS (const octave_complex_matrix&, const octave_matrix&); |
|
173 |
|
174 return elem_xpow (v1.complex_matrix_value (), v2.matrix_value ()); |
|
175 } |
|
176 |
|
177 static octave_value |
|
178 el_ldiv (const octave_value& a1, const octave_value& a2) |
|
179 { |
|
180 CAST_BINOP_ARGS (const octave_complex_matrix&, const octave_matrix&); |
|
181 |
|
182 return quotient (v2.matrix_value (), v1.complex_matrix_value ()); |
|
183 } |
|
184 |
|
185 static octave_value |
|
186 el_and (const octave_value& a1, const octave_value& a2) |
|
187 { |
|
188 CAST_BINOP_ARGS (const octave_complex_matrix&, const octave_matrix&); |
|
189 |
2613
|
190 MX_MX_BOOL_OP (ComplexMatrix, m1, v1.complex_matrix_value (), |
|
191 Matrix, m2, v2.matrix_value (), |
|
192 m1 (i, j) != 0.0 && m2 (i, j), "&", |
2825
|
193 boolMatrix (), boolMatrix ()); |
2376
|
194 } |
|
195 |
|
196 static octave_value |
|
197 el_or (const octave_value& a1, const octave_value& a2) |
|
198 { |
|
199 CAST_BINOP_ARGS (const octave_complex_matrix&, const octave_matrix&); |
|
200 |
2613
|
201 MX_MX_BOOL_OP (ComplexMatrix, m1, v1.complex_matrix_value (), |
|
202 Matrix, m2, v2.matrix_value (), |
|
203 m1 (i, j) != 0.0 || m2 (i, j), "|", |
2825
|
204 boolMatrix (), boolMatrix ()); |
2376
|
205 } |
|
206 |
|
207 static octave_value |
|
208 assign (octave_value& a1, const octave_value_list& idx, |
|
209 const octave_value& a2) |
|
210 { |
|
211 CAST_BINOP_ARGS (octave_complex_matrix&, const octave_matrix&); |
|
212 |
|
213 v1.assign (idx, v2.complex_matrix_value ()); |
|
214 return octave_value (); |
|
215 } |
|
216 |
|
217 void |
|
218 install_cm_m_ops (void) |
|
219 { |
|
220 INSTALL_BINOP (add, octave_complex_matrix, octave_matrix, add); |
|
221 INSTALL_BINOP (sub, octave_complex_matrix, octave_matrix, sub); |
|
222 INSTALL_BINOP (mul, octave_complex_matrix, octave_matrix, mul); |
|
223 INSTALL_BINOP (div, octave_complex_matrix, octave_matrix, div); |
|
224 INSTALL_BINOP (pow, octave_complex_matrix, octave_matrix, pow); |
|
225 INSTALL_BINOP (ldiv, octave_complex_matrix, octave_matrix, ldiv); |
|
226 INSTALL_BINOP (lt, octave_complex_matrix, octave_matrix, lt); |
|
227 INSTALL_BINOP (le, octave_complex_matrix, octave_matrix, le); |
|
228 INSTALL_BINOP (eq, octave_complex_matrix, octave_matrix, eq); |
|
229 INSTALL_BINOP (ge, octave_complex_matrix, octave_matrix, ge); |
|
230 INSTALL_BINOP (gt, octave_complex_matrix, octave_matrix, gt); |
|
231 INSTALL_BINOP (ne, octave_complex_matrix, octave_matrix, ne); |
|
232 INSTALL_BINOP (el_mul, octave_complex_matrix, octave_matrix, el_mul); |
|
233 INSTALL_BINOP (el_div, octave_complex_matrix, octave_matrix, el_div); |
|
234 INSTALL_BINOP (el_pow, octave_complex_matrix, octave_matrix, el_pow); |
|
235 INSTALL_BINOP (el_ldiv, octave_complex_matrix, octave_matrix, el_ldiv); |
|
236 INSTALL_BINOP (el_and, octave_complex_matrix, octave_matrix, el_and); |
|
237 INSTALL_BINOP (el_or, octave_complex_matrix, octave_matrix, el_or); |
|
238 |
|
239 INSTALL_ASSIGNOP (octave_complex_matrix, octave_matrix, assign); |
|
240 } |
|
241 |
|
242 /* |
|
243 ;;; Local Variables: *** |
|
244 ;;; mode: C++ *** |
|
245 ;;; End: *** |
|
246 */ |