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