2829
|
1 /* |
|
2 |
2847
|
3 Copyright (C) 1996, 1997 John W. Eaton |
2829
|
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 (octave_mx_op_defs_h) |
|
24 #define octave_mx_op_defs_h 1 |
|
25 |
|
26 #include "mx-inlines.cc" |
|
27 |
|
28 #define BIN_OP_DECL(R, OP, X, Y) \ |
|
29 extern R OP (const X&, const Y&) |
|
30 |
2870
|
31 class boolMatrix; |
4543
|
32 class boolNDArray; |
2870
|
33 |
|
34 #define CMP_OP_DECL(OP, X, Y) \ |
|
35 extern boolMatrix OP (const X&, const Y&) |
|
36 |
4543
|
37 #define NDCMP_OP_DECL(OP, X, Y) \ |
|
38 extern boolNDArray OP (const X&, const Y&) |
|
39 |
2870
|
40 #define BOOL_OP_DECL(OP, X, Y) \ |
|
41 extern boolMatrix OP (const X&, const Y&) |
|
42 |
4543
|
43 #define NDBOOL_OP_DECL(OP, X, Y) \ |
|
44 extern boolNDArray OP (const X&, const Y&) |
|
45 |
2870
|
46 // vector by scalar operations. |
|
47 |
|
48 #define VS_BIN_OP_DECLS(R, V, S) \ |
|
49 BIN_OP_DECL (R, operator +, V, S); \ |
|
50 BIN_OP_DECL (R, operator -, V, S); \ |
|
51 BIN_OP_DECL (R, operator *, V, S); \ |
|
52 BIN_OP_DECL (R, operator /, V, S); |
|
53 |
|
54 #define VS_BIN_OP(R, F, OP, V, S) \ |
|
55 R \ |
|
56 F (const V& v, const S& s) \ |
|
57 { \ |
|
58 int len = v.length (); \ |
|
59 \ |
|
60 R r (len); \ |
|
61 \ |
3582
|
62 for (int i = 0; i < len; i++) \ |
2870
|
63 r.elem(i) = v.elem(i) OP s; \ |
|
64 \ |
|
65 return r; \ |
|
66 } |
|
67 |
|
68 #define VS_BIN_OPS(R, V, S) \ |
|
69 VS_BIN_OP (R, operator +, +, V, S) \ |
|
70 VS_BIN_OP (R, operator -, -, V, S) \ |
|
71 VS_BIN_OP (R, operator *, *, V, S) \ |
|
72 VS_BIN_OP (R, operator /, /, V, S) |
|
73 |
3582
|
74 #define VS_OP_DECLS(R, V, S) \ |
|
75 VS_BIN_OP_DECLS(R, V, S) |
|
76 |
2870
|
77 // scalar by vector by operations. |
|
78 |
|
79 #define SV_BIN_OP_DECLS(R, S, V) \ |
|
80 BIN_OP_DECL (R, operator +, S, V); \ |
|
81 BIN_OP_DECL (R, operator -, S, V); \ |
|
82 BIN_OP_DECL (R, operator *, S, V); \ |
|
83 BIN_OP_DECL (R, operator /, S, V); |
|
84 |
|
85 #define SV_BIN_OP(R, F, OP, S, V) \ |
|
86 R \ |
|
87 F (const S& s, const V& v) \ |
|
88 { \ |
|
89 int len = v.length (); \ |
|
90 \ |
|
91 R r (len); \ |
|
92 \ |
3582
|
93 for (int i = 0; i < len; i++) \ |
2870
|
94 r.elem(i) = s OP v.elem(i); \ |
|
95 \ |
|
96 return r; \ |
|
97 } |
|
98 |
|
99 #define SV_BIN_OPS(R, S, V) \ |
|
100 SV_BIN_OP (R, operator +, +, S, V) \ |
|
101 SV_BIN_OP (R, operator -, -, S, V) \ |
|
102 SV_BIN_OP (R, operator *, *, S, V) \ |
|
103 SV_BIN_OP (R, operator /, /, S, V) |
|
104 |
3582
|
105 #define SV_OP_DECLS(R, S, V) \ |
|
106 SV_BIN_OP_DECLS(R, S, V) |
|
107 |
2870
|
108 // vector by vector operations. |
|
109 |
|
110 #define VV_BIN_OP_DECLS(R, V1, V2) \ |
|
111 BIN_OP_DECL (R, operator +, V1, V2); \ |
|
112 BIN_OP_DECL (R, operator -, V1, V2); \ |
|
113 BIN_OP_DECL (R, product, V1, V2); \ |
|
114 BIN_OP_DECL (R, quotient, V1, V2); |
|
115 |
|
116 #define VV_BIN_OP(R, F, OP, V1, V2) \ |
|
117 R \ |
|
118 F (const V1& v1, const V2& v2) \ |
|
119 { \ |
|
120 R r; \ |
|
121 \ |
|
122 int v1_len = v1.length (); \ |
|
123 int v2_len = v2.length (); \ |
|
124 \ |
|
125 if (v1_len != v2_len) \ |
|
126 gripe_nonconformant (#OP, v1_len, v2_len); \ |
|
127 else \ |
|
128 { \ |
|
129 r.resize (v1_len); \ |
|
130 \ |
3582
|
131 for (int i = 0; i < v1_len; i++) \ |
2870
|
132 r.elem(i) = v1.elem(i) OP v2.elem(i); \ |
|
133 } \ |
|
134 \ |
|
135 return r; \ |
|
136 } |
|
137 |
|
138 #define VV_BIN_OPS(R, V1, V2) \ |
|
139 VV_BIN_OP (R, operator +, +, V1, V2) \ |
|
140 VV_BIN_OP (R, operator -, -, V1, V2) \ |
|
141 VV_BIN_OP (R, product, *, V1, V2) \ |
|
142 VV_BIN_OP (R, quotient, /, V1, V2) |
|
143 |
3582
|
144 #define VV_OP_DECLS(R, V1, V2) \ |
|
145 VV_BIN_OP_DECLS(R, V1, V2) |
2870
|
146 |
|
147 // matrix by scalar operations. |
|
148 |
|
149 #define MS_BIN_OP_DECLS(R, M, S) \ |
2829
|
150 BIN_OP_DECL (R, operator +, M, S); \ |
|
151 BIN_OP_DECL (R, operator -, M, S); \ |
|
152 BIN_OP_DECL (R, operator *, M, S); \ |
|
153 BIN_OP_DECL (R, operator /, M, S); |
|
154 |
2870
|
155 #define MS_BIN_OP(R, OP, M, S, F) \ |
2829
|
156 R \ |
|
157 OP (const M& m, const S& s) \ |
|
158 { \ |
|
159 int nr = m.rows (); \ |
|
160 int nc = m.cols (); \ |
|
161 \ |
|
162 R r (nr, nc); \ |
|
163 \ |
|
164 if (nr > 0 && nc > 0) \ |
|
165 F ## _vs (r.fortran_vec (), m.data (), nr * nc, s); \ |
|
166 \ |
|
167 return r; \ |
|
168 } |
|
169 |
2870
|
170 #define MS_BIN_OPS(R, M, S) \ |
3769
|
171 MS_BIN_OP (R, operator +, M, S, mx_inline_add) \ |
|
172 MS_BIN_OP (R, operator -, M, S, mx_inline_subtract) \ |
|
173 MS_BIN_OP (R, operator *, M, S, mx_inline_multiply) \ |
|
174 MS_BIN_OP (R, operator /, M, S, mx_inline_divide) |
2870
|
175 |
|
176 #define MS_CMP_OP_DECLS(M, S) \ |
|
177 CMP_OP_DECL (mx_el_lt, M, S); \ |
|
178 CMP_OP_DECL (mx_el_le, M, S); \ |
|
179 CMP_OP_DECL (mx_el_ge, M, S); \ |
|
180 CMP_OP_DECL (mx_el_gt, M, S); \ |
|
181 CMP_OP_DECL (mx_el_eq, M, S); \ |
|
182 CMP_OP_DECL (mx_el_ne, M, S); |
|
183 |
4826
|
184 #define MS_CMP_OP(F, OP, M, MC, S, SC) \ |
2870
|
185 boolMatrix \ |
|
186 F (const M& m, const S& s) \ |
|
187 { \ |
|
188 boolMatrix r; \ |
|
189 \ |
|
190 int nr = m.rows (); \ |
|
191 int nc = m.cols (); \ |
|
192 \ |
4826
|
193 r.resize (nr, nc); \ |
|
194 \ |
|
195 if (nr > 0 && nc > 0) \ |
2870
|
196 { \ |
|
197 for (int j = 0; j < nc; j++) \ |
|
198 for (int i = 0; i < nr; i++) \ |
|
199 r.elem(i, j) = MC (m.elem(i, j)) OP SC (s); \ |
|
200 } \ |
|
201 \ |
|
202 return r; \ |
|
203 } |
2829
|
204 |
2870
|
205 #define MS_CMP_OPS(M, CM, S, CS) \ |
4826
|
206 MS_CMP_OP (mx_el_lt, <, M, CM, S, CS) \ |
|
207 MS_CMP_OP (mx_el_le, <=, M, CM, S, CS) \ |
|
208 MS_CMP_OP (mx_el_ge, >=, M, CM, S, CS) \ |
|
209 MS_CMP_OP (mx_el_gt, >, M, CM, S, CS) \ |
|
210 MS_CMP_OP (mx_el_eq, ==, M, , S, ) \ |
|
211 MS_CMP_OP (mx_el_ne, !=, M, , S, ) |
2870
|
212 |
|
213 #define MS_BOOL_OP_DECLS(M, S) \ |
|
214 BOOL_OP_DECL (mx_el_and, M, S); \ |
|
215 BOOL_OP_DECL (mx_el_or, M, S); \ |
|
216 |
3504
|
217 #define MS_BOOL_OP(F, OP, M, S, ZERO) \ |
2870
|
218 boolMatrix \ |
|
219 F (const M& m, const S& s) \ |
|
220 { \ |
|
221 boolMatrix r; \ |
|
222 \ |
|
223 int nr = m.rows (); \ |
|
224 int nc = m.cols (); \ |
|
225 \ |
|
226 if (nr != 0 && nc != 0) \ |
|
227 { \ |
|
228 r.resize (nr, nc); \ |
|
229 \ |
|
230 for (int j = 0; j < nc; j++) \ |
|
231 for (int i = 0; i < nr; i++) \ |
3504
|
232 r.elem(i, j) = (m.elem(i, j) != ZERO) OP (s != ZERO); \ |
2870
|
233 } \ |
|
234 \ |
|
235 return r; \ |
|
236 } |
|
237 |
3504
|
238 #define MS_BOOL_OPS(M, S, ZERO) \ |
|
239 MS_BOOL_OP (mx_el_and, &&, M, S, ZERO) \ |
|
240 MS_BOOL_OP (mx_el_or, ||, M, S, ZERO) |
2870
|
241 |
|
242 #define MS_OP_DECLS(R, M, S) \ |
|
243 MS_BIN_OP_DECLS (R, M, S) \ |
|
244 MS_CMP_OP_DECLS (M, S) \ |
|
245 MS_BOOL_OP_DECLS (M, S) \ |
|
246 |
|
247 // scalar by matrix operations. |
|
248 |
|
249 #define SM_BIN_OP_DECLS(R, S, M) \ |
|
250 BIN_OP_DECL (R, operator +, S, M); \ |
|
251 BIN_OP_DECL (R, operator -, S, M); \ |
|
252 BIN_OP_DECL (R, operator *, S, M); \ |
|
253 BIN_OP_DECL (R, operator /, S, M); |
|
254 |
|
255 #define SM_BIN_OP(R, OP, S, M, F) \ |
2829
|
256 R \ |
|
257 OP (const S& s, const M& m) \ |
|
258 { \ |
|
259 int nr = m.rows (); \ |
|
260 int nc = m.cols (); \ |
|
261 \ |
|
262 R r (nr, nc); \ |
|
263 \ |
|
264 if (nr > 0 && nc > 0) \ |
|
265 F ## _sv (r.fortran_vec (), s, m.data (), nr * nc); \ |
|
266 \ |
|
267 return r; \ |
|
268 } |
|
269 |
2870
|
270 #define SM_BIN_OPS(R, S, M) \ |
3769
|
271 SM_BIN_OP (R, operator +, S, M, mx_inline_add) \ |
|
272 SM_BIN_OP (R, operator -, S, M, mx_inline_subtract) \ |
|
273 SM_BIN_OP (R, operator *, S, M, mx_inline_multiply) \ |
|
274 SM_BIN_OP (R, operator /, S, M, mx_inline_divide) |
2870
|
275 |
|
276 #define SM_CMP_OP_DECLS(S, M) \ |
|
277 CMP_OP_DECL (mx_el_lt, S, M); \ |
|
278 CMP_OP_DECL (mx_el_le, S, M); \ |
|
279 CMP_OP_DECL (mx_el_ge, S, M); \ |
|
280 CMP_OP_DECL (mx_el_gt, S, M); \ |
|
281 CMP_OP_DECL (mx_el_eq, S, M); \ |
|
282 CMP_OP_DECL (mx_el_ne, S, M); |
|
283 |
4826
|
284 #define SM_CMP_OP(F, OP, S, SC, M, MC) \ |
2870
|
285 boolMatrix \ |
|
286 F (const S& s, const M& m) \ |
|
287 { \ |
|
288 boolMatrix r; \ |
|
289 \ |
|
290 int nr = m.rows (); \ |
|
291 int nc = m.cols (); \ |
|
292 \ |
4826
|
293 r.resize (nr, nc); \ |
|
294 \ |
|
295 if (nr > 0 && nc > 0) \ |
2870
|
296 { \ |
|
297 for (int j = 0; j < nc; j++) \ |
|
298 for (int i = 0; i < nr; i++) \ |
|
299 r.elem(i, j) = SC (s) OP MC (m.elem(i, j)); \ |
|
300 } \ |
|
301 \ |
|
302 return r; \ |
|
303 } |
2829
|
304 |
2870
|
305 #define SM_CMP_OPS(S, CS, M, CM) \ |
4826
|
306 SM_CMP_OP (mx_el_lt, <, S, CS, M, CM) \ |
|
307 SM_CMP_OP (mx_el_le, <=, S, CS, M, CM) \ |
|
308 SM_CMP_OP (mx_el_ge, >=, S, CS, M, CM) \ |
|
309 SM_CMP_OP (mx_el_gt, >, S, CS, M, CM) \ |
|
310 SM_CMP_OP (mx_el_eq, ==, S, , M, ) \ |
|
311 SM_CMP_OP (mx_el_ne, !=, S, , M, ) |
2870
|
312 |
|
313 #define SM_BOOL_OP_DECLS(S, M) \ |
|
314 BOOL_OP_DECL (mx_el_and, S, M); \ |
|
315 BOOL_OP_DECL (mx_el_or, S, M); \ |
|
316 |
3504
|
317 #define SM_BOOL_OP(F, OP, S, M, ZERO) \ |
2870
|
318 boolMatrix \ |
|
319 F (const S& s, const M& m) \ |
|
320 { \ |
|
321 boolMatrix r; \ |
|
322 \ |
|
323 int nr = m.rows (); \ |
|
324 int nc = m.cols (); \ |
|
325 \ |
|
326 if (nr != 0 && nc != 0) \ |
|
327 { \ |
|
328 r.resize (nr, nc); \ |
|
329 \ |
|
330 for (int j = 0; j < nc; j++) \ |
|
331 for (int i = 0; i < nr; i++) \ |
3504
|
332 r.elem(i, j) = (s != ZERO) OP (m.elem(i, j) != ZERO); \ |
2870
|
333 } \ |
|
334 \ |
|
335 return r; \ |
|
336 } |
|
337 |
3504
|
338 #define SM_BOOL_OPS(S, M, ZERO) \ |
|
339 SM_BOOL_OP (mx_el_and, &&, S, M, ZERO) \ |
|
340 SM_BOOL_OP (mx_el_or, ||, S, M, ZERO) |
2870
|
341 |
|
342 #define SM_OP_DECLS(R, S, M) \ |
|
343 SM_BIN_OP_DECLS (R, S, M) \ |
|
344 SM_CMP_OP_DECLS (S, M) \ |
|
345 SM_BOOL_OP_DECLS (S, M) \ |
|
346 |
|
347 // matrix by matrix operations. |
|
348 |
|
349 #define MM_BIN_OP_DECLS(R, M1, M2) \ |
|
350 BIN_OP_DECL (R, operator +, M1, M2); \ |
|
351 BIN_OP_DECL (R, operator -, M1, M2); \ |
|
352 BIN_OP_DECL (R, product, M1, M2); \ |
|
353 BIN_OP_DECL (R, quotient, M1, M2); |
|
354 |
|
355 #define MM_BIN_OP(R, OP, M1, M2, F) \ |
2829
|
356 R \ |
|
357 OP (const M1& m1, const M2& m2) \ |
|
358 { \ |
|
359 R r; \ |
|
360 \ |
|
361 int m1_nr = m1.rows (); \ |
|
362 int m1_nc = m1.cols (); \ |
|
363 \ |
|
364 int m2_nr = m2.rows (); \ |
|
365 int m2_nc = m2.cols (); \ |
|
366 \ |
|
367 if (m1_nr != m2_nr || m1_nc != m2_nc) \ |
|
368 gripe_nonconformant (#OP, m1_nr, m1_nc, m2_nr, m2_nc); \ |
|
369 else \ |
|
370 { \ |
|
371 r.resize (m1_nr, m1_nc); \ |
|
372 \ |
|
373 if (m1_nr > 0 && m1_nc > 0) \ |
|
374 F ## _vv (r.fortran_vec (), m1.data (), m2.data (), m1_nr * m1_nc); \ |
|
375 } \ |
|
376 \ |
|
377 return r; \ |
|
378 } |
|
379 |
2870
|
380 #define MM_BIN_OPS(R, M1, M2) \ |
3769
|
381 MM_BIN_OP (R, operator +, M1, M2, mx_inline_add) \ |
|
382 MM_BIN_OP (R, operator -, M1, M2, mx_inline_subtract) \ |
|
383 MM_BIN_OP (R, product, M1, M2, mx_inline_multiply) \ |
|
384 MM_BIN_OP (R, quotient, M1, M2, mx_inline_divide) |
2870
|
385 |
|
386 #define MM_CMP_OP_DECLS(M1, M2) \ |
|
387 CMP_OP_DECL (mx_el_lt, M1, M2); \ |
|
388 CMP_OP_DECL (mx_el_le, M1, M2); \ |
|
389 CMP_OP_DECL (mx_el_ge, M1, M2); \ |
|
390 CMP_OP_DECL (mx_el_gt, M1, M2); \ |
|
391 CMP_OP_DECL (mx_el_eq, M1, M2); \ |
|
392 CMP_OP_DECL (mx_el_ne, M1, M2); |
|
393 |
4826
|
394 #define MM_CMP_OP(F, OP, M1, C1, M2, C2) \ |
2870
|
395 boolMatrix \ |
|
396 F (const M1& m1, const M2& m2) \ |
|
397 { \ |
|
398 boolMatrix r; \ |
|
399 \ |
|
400 int m1_nr = m1.rows (); \ |
|
401 int m1_nc = m1.cols (); \ |
|
402 \ |
|
403 int m2_nr = m2.rows (); \ |
|
404 int m2_nc = m2.cols (); \ |
|
405 \ |
|
406 if (m1_nr == m2_nr && m1_nc == m2_nc) \ |
|
407 { \ |
4826
|
408 r.resize (m1_nr, m1_nc); \ |
2870
|
409 \ |
4826
|
410 for (int j = 0; j < m1_nc; j++) \ |
|
411 for (int i = 0; i < m1_nr; i++) \ |
|
412 r.elem(i, j) = C1 (m1.elem(i, j)) OP C2 (m2.elem(i, j)); \ |
2870
|
413 } \ |
|
414 else \ |
4826
|
415 gripe_nonconformant (#F, m1_nr, m1_nc, m2_nr, m2_nc); \ |
2870
|
416 \ |
|
417 return r; \ |
|
418 } |
2829
|
419 |
2870
|
420 #define MM_CMP_OPS(M1, C1, M2, C2) \ |
4826
|
421 MM_CMP_OP (mx_el_lt, <, M1, C1, M2, C2) \ |
|
422 MM_CMP_OP (mx_el_le, <=, M1, C1, M2, C2) \ |
|
423 MM_CMP_OP (mx_el_ge, >=, M1, C1, M2, C2) \ |
|
424 MM_CMP_OP (mx_el_gt, >, M1, C1, M2, C2) \ |
|
425 MM_CMP_OP (mx_el_eq, ==, M1, , M2, ) \ |
|
426 MM_CMP_OP (mx_el_ne, !=, M1, , M2, ) |
2870
|
427 |
|
428 #define MM_BOOL_OP_DECLS(M1, M2) \ |
|
429 BOOL_OP_DECL (mx_el_and, M1, M2); \ |
|
430 BOOL_OP_DECL (mx_el_or, M1, M2); |
|
431 |
3504
|
432 #define MM_BOOL_OP(F, OP, M1, M2, ZERO) \ |
2870
|
433 boolMatrix \ |
|
434 F (const M1& m1, const M2& m2) \ |
|
435 { \ |
|
436 boolMatrix r; \ |
|
437 \ |
|
438 int m1_nr = m1.rows (); \ |
|
439 int m1_nc = m1.cols (); \ |
|
440 \ |
|
441 int m2_nr = m2.rows (); \ |
|
442 int m2_nc = m2.cols (); \ |
|
443 \ |
|
444 if (m1_nr == m2_nr && m1_nc == m2_nc) \ |
|
445 { \ |
|
446 if (m1_nr != 0 || m1_nc != 0) \ |
|
447 { \ |
|
448 r.resize (m1_nr, m1_nc); \ |
|
449 \ |
|
450 for (int j = 0; j < m1_nc; j++) \ |
|
451 for (int i = 0; i < m1_nr; i++) \ |
3504
|
452 r.elem(i, j) = (m1.elem(i, j) != ZERO) \ |
|
453 OP (m2.elem(i, j) != ZERO); \ |
2870
|
454 } \ |
|
455 } \ |
|
456 else \ |
|
457 { \ |
|
458 if ((m1_nr != 0 || m1_nc != 0) && (m2_nr != 0 || m2_nc != 0)) \ |
|
459 gripe_nonconformant (#F, m1_nr, m1_nc, m2_nr, m2_nc); \ |
|
460 } \ |
|
461 \ |
|
462 return r; \ |
|
463 } |
|
464 |
3504
|
465 #define MM_BOOL_OPS(M1, M2, ZERO) \ |
|
466 MM_BOOL_OP (mx_el_and, &&, M1, M2, ZERO) \ |
|
467 MM_BOOL_OP (mx_el_or, ||, M1, M2, ZERO) |
2870
|
468 |
|
469 #define MM_OP_DECLS(R, M1, M2) \ |
|
470 MM_BIN_OP_DECLS (R, M1, M2) \ |
|
471 MM_CMP_OP_DECLS (M1, M2) \ |
|
472 MM_BOOL_OP_DECLS (M1, M2) |
|
473 |
4543
|
474 // N-d matrix by scalar operations. |
|
475 |
|
476 #define NDS_BIN_OP_DECLS(R, ND, S) \ |
|
477 BIN_OP_DECL (R, operator +, ND, S); \ |
|
478 BIN_OP_DECL (R, operator -, ND, S); \ |
|
479 BIN_OP_DECL (R, operator *, ND, S); \ |
|
480 BIN_OP_DECL (R, operator /, ND, S); |
|
481 |
|
482 #define NDS_BIN_OP(R, OP, ND, S, F) \ |
|
483 R \ |
|
484 OP (const ND& m, const S& s) \ |
|
485 { \ |
|
486 R r (m.dims ()); \ |
|
487 \ |
|
488 int len = m.length (); \ |
|
489 \ |
|
490 if (len > 0) \ |
|
491 F ## _vs (r.fortran_vec (), m.data (), len, s); \ |
|
492 \ |
|
493 return r; \ |
|
494 } |
|
495 |
|
496 #define NDS_BIN_OPS(R, ND, S) \ |
|
497 NDS_BIN_OP (R, operator +, ND, S, mx_inline_add) \ |
|
498 NDS_BIN_OP (R, operator -, ND, S, mx_inline_subtract) \ |
|
499 NDS_BIN_OP (R, operator *, ND, S, mx_inline_multiply) \ |
|
500 NDS_BIN_OP (R, operator /, ND, S, mx_inline_divide) |
|
501 |
|
502 #define NDS_CMP_OP_DECLS(ND, S) \ |
|
503 NDCMP_OP_DECL (mx_el_lt, ND, S); \ |
|
504 NDCMP_OP_DECL (mx_el_le, ND, S); \ |
|
505 NDCMP_OP_DECL (mx_el_ge, ND, S); \ |
|
506 NDCMP_OP_DECL (mx_el_gt, ND, S); \ |
|
507 NDCMP_OP_DECL (mx_el_eq, ND, S); \ |
|
508 NDCMP_OP_DECL (mx_el_ne, ND, S); |
|
509 |
4826
|
510 #define NDS_CMP_OP(F, OP, ND, NDC, S, SC) \ |
4543
|
511 boolNDArray \ |
|
512 F (const ND& m, const S& s) \ |
|
513 { \ |
|
514 boolNDArray r; \ |
|
515 \ |
|
516 int len = m.length (); \ |
|
517 \ |
4826
|
518 r.resize (m.dims ()); \ |
4543
|
519 \ |
4826
|
520 for (int i = 0; i < len; i++) \ |
|
521 r.elem(i) = NDC (m.elem(i)) OP SC (s); \ |
4543
|
522 \ |
|
523 return r; \ |
|
524 } |
|
525 |
|
526 #define NDS_CMP_OPS(ND, NDC, S, SC) \ |
4826
|
527 NDS_CMP_OP (mx_el_lt, <, ND, NDC, S, SC) \ |
|
528 NDS_CMP_OP (mx_el_le, <=, ND, NDC, S, SC) \ |
|
529 NDS_CMP_OP (mx_el_ge, >=, ND, NDC, S, SC) \ |
|
530 NDS_CMP_OP (mx_el_gt, >, ND, NDC, S, SC) \ |
|
531 NDS_CMP_OP (mx_el_eq, ==, ND, , S, ) \ |
|
532 NDS_CMP_OP (mx_el_ne, !=, ND, , S, ) |
4543
|
533 |
|
534 #define NDS_BOOL_OP_DECLS(ND, S) \ |
|
535 NDBOOL_OP_DECL (mx_el_and, ND, S); \ |
|
536 NDBOOL_OP_DECL (mx_el_or, ND, S); |
|
537 |
|
538 #define NDS_BOOL_OP(F, OP, ND, S, ZERO) \ |
|
539 boolNDArray \ |
|
540 F (const ND& m, const S& s) \ |
|
541 { \ |
|
542 boolNDArray r; \ |
|
543 \ |
|
544 int len = m.length (); \ |
|
545 \ |
|
546 if (len > 0) \ |
|
547 { \ |
|
548 r.resize (m.dims ()); \ |
|
549 \ |
|
550 for (int i = 0; i < len; i++) \ |
|
551 r.elem(i) = (m.elem(i) != ZERO) OP (s != ZERO); \ |
|
552 } \ |
|
553 \ |
|
554 return r; \ |
|
555 } |
|
556 |
|
557 #define NDS_BOOL_OPS(ND, S, ZERO) \ |
|
558 NDS_BOOL_OP (mx_el_and, &&, ND, S, ZERO) \ |
|
559 NDS_BOOL_OP (mx_el_or, ||, ND, S, ZERO) |
|
560 |
|
561 #define NDS_OP_DECLS(R, ND, S) \ |
|
562 NDS_BIN_OP_DECLS (R, ND, S) \ |
|
563 NDS_CMP_OP_DECLS (ND, S) \ |
|
564 NDS_BOOL_OP_DECLS (ND, S) |
|
565 |
|
566 // scalar by N-d matrix operations. |
|
567 |
|
568 #define SND_BIN_OP_DECLS(R, S, ND) \ |
|
569 BIN_OP_DECL (R, operator +, S, ND); \ |
|
570 BIN_OP_DECL (R, operator -, S, ND); \ |
|
571 BIN_OP_DECL (R, operator *, S, ND); \ |
|
572 BIN_OP_DECL (R, operator /, S, ND); |
|
573 |
|
574 #define SND_BIN_OP(R, OP, S, ND, F) \ |
|
575 R \ |
|
576 OP (const S& s, const ND& m) \ |
|
577 { \ |
|
578 R r (m.dims ()); \ |
|
579 \ |
|
580 int len = m.length (); \ |
|
581 \ |
|
582 if (len > 0) \ |
|
583 F ## _sv (r.fortran_vec (), s, m.data (), len); \ |
|
584 \ |
|
585 return r; \ |
|
586 } |
|
587 |
|
588 #define SND_BIN_OPS(R, S, ND) \ |
|
589 SND_BIN_OP (R, operator +, S, ND, mx_inline_add) \ |
|
590 SND_BIN_OP (R, operator -, S, ND, mx_inline_subtract) \ |
|
591 SND_BIN_OP (R, operator *, S, ND, mx_inline_multiply) \ |
|
592 SND_BIN_OP (R, operator /, S, ND, mx_inline_divide) |
|
593 |
|
594 #define SND_CMP_OP_DECLS(S, ND) \ |
|
595 NDCMP_OP_DECL (mx_el_lt, S, ND); \ |
|
596 NDCMP_OP_DECL (mx_el_le, S, ND); \ |
|
597 NDCMP_OP_DECL (mx_el_ge, S, ND); \ |
|
598 NDCMP_OP_DECL (mx_el_gt, S, ND); \ |
|
599 NDCMP_OP_DECL (mx_el_eq, S, ND); \ |
|
600 NDCMP_OP_DECL (mx_el_ne, S, ND); |
|
601 |
4826
|
602 #define SND_CMP_OP(F, OP, S, SC, ND, NDC) \ |
4543
|
603 boolNDArray \ |
|
604 F (const S& s, const ND& m) \ |
|
605 { \ |
|
606 boolNDArray r; \ |
|
607 \ |
|
608 int len = m.length (); \ |
|
609 \ |
4826
|
610 r.resize (m.dims ()); \ |
4543
|
611 \ |
4826
|
612 for (int i = 0; i < len; i++) \ |
|
613 r.elem(i) = SC (s) OP NDC (m.elem(i)); \ |
4543
|
614 \ |
|
615 return r; \ |
|
616 } |
|
617 |
|
618 #define SND_CMP_OPS(S, CS, ND, CND) \ |
4826
|
619 SND_CMP_OP (mx_el_lt, <, S, CS, ND, CND) \ |
|
620 SND_CMP_OP (mx_el_le, <=, S, CS, ND, CND) \ |
|
621 SND_CMP_OP (mx_el_ge, >=, S, CS, ND, CND) \ |
|
622 SND_CMP_OP (mx_el_gt, >, S, CS, ND, CND) \ |
|
623 SND_CMP_OP (mx_el_eq, ==, S, , ND, ) \ |
|
624 SND_CMP_OP (mx_el_ne, !=, S, , ND, ) |
4543
|
625 |
|
626 #define SND_BOOL_OP_DECLS(S, ND) \ |
|
627 NDBOOL_OP_DECL (mx_el_and, S, ND); \ |
|
628 NDBOOL_OP_DECL (mx_el_or, S, ND); |
|
629 |
|
630 #define SND_BOOL_OP(F, OP, S, ND, ZERO) \ |
|
631 boolNDArray \ |
|
632 F (const S& s, const ND& m) \ |
|
633 { \ |
|
634 boolNDArray r; \ |
|
635 \ |
|
636 int len = m.length (); \ |
|
637 \ |
|
638 if (len > 0) \ |
|
639 { \ |
|
640 r.resize (m.dims ()); \ |
|
641 \ |
|
642 for (int i = 0; i < len; i++) \ |
|
643 r.elem(i) = (s != ZERO) OP (m.elem(i) != ZERO); \ |
|
644 } \ |
|
645 \ |
|
646 return r; \ |
|
647 } |
|
648 |
|
649 #define SND_BOOL_OPS(S, ND, ZERO) \ |
|
650 SND_BOOL_OP (mx_el_and, &&, S, ND, ZERO) \ |
|
651 SND_BOOL_OP (mx_el_or, ||, S, ND, ZERO) |
|
652 |
|
653 #define SND_OP_DECLS(R, S, ND) \ |
|
654 SND_BIN_OP_DECLS (R, S, ND) \ |
|
655 SND_CMP_OP_DECLS (S, ND) \ |
|
656 SND_BOOL_OP_DECLS (S, ND) |
|
657 |
|
658 // N-d matrix by N-d matrix operations. |
|
659 |
|
660 #define NDND_BIN_OP_DECLS(R, ND1, ND2) \ |
|
661 BIN_OP_DECL (R, operator +, ND1, ND2); \ |
|
662 BIN_OP_DECL (R, operator -, ND1, ND2); \ |
|
663 BIN_OP_DECL (R, product, ND1, ND2); \ |
|
664 BIN_OP_DECL (R, quotient, ND1, ND2); |
|
665 |
|
666 #define NDND_BIN_OP(R, OP, ND1, ND2, F) \ |
|
667 R \ |
|
668 OP (const ND1& m1, const ND2& m2) \ |
|
669 { \ |
|
670 R r; \ |
|
671 \ |
|
672 dim_vector m1_dims = m1.dims (); \ |
|
673 dim_vector m2_dims = m2.dims (); \ |
|
674 \ |
|
675 if (m1_dims != m2_dims) \ |
|
676 gripe_nonconformant (#OP, m1_dims, m2_dims); \ |
|
677 else \ |
|
678 { \ |
|
679 r.resize (m1_dims); \ |
|
680 \ |
|
681 int len = m1.length (); \ |
|
682 \ |
|
683 if (len > 0) \ |
|
684 F ## _vv (r.fortran_vec (), m1.data (), m2.data (), len); \ |
|
685 } \ |
|
686 \ |
|
687 return r; \ |
|
688 } |
|
689 |
|
690 #define NDND_BIN_OPS(R, ND1, ND2) \ |
|
691 NDND_BIN_OP (R, operator +, ND1, ND2, mx_inline_add) \ |
|
692 NDND_BIN_OP (R, operator -, ND1, ND2, mx_inline_subtract) \ |
|
693 NDND_BIN_OP (R, product, ND1, ND2, mx_inline_multiply) \ |
|
694 NDND_BIN_OP (R, quotient, ND1, ND2, mx_inline_divide) |
|
695 |
|
696 #define NDND_CMP_OP_DECLS(ND1, ND2) \ |
|
697 NDCMP_OP_DECL (mx_el_lt, ND1, ND2); \ |
|
698 NDCMP_OP_DECL (mx_el_le, ND1, ND2); \ |
|
699 NDCMP_OP_DECL (mx_el_ge, ND1, ND2); \ |
|
700 NDCMP_OP_DECL (mx_el_gt, ND1, ND2); \ |
|
701 NDCMP_OP_DECL (mx_el_eq, ND1, ND2); \ |
|
702 NDCMP_OP_DECL (mx_el_ne, ND1, ND2); |
|
703 |
4826
|
704 #define NDND_CMP_OP(F, OP, ND1, C1, ND2, C2) \ |
4543
|
705 boolNDArray \ |
|
706 F (const ND1& m1, const ND2& m2) \ |
|
707 { \ |
|
708 boolNDArray r; \ |
|
709 \ |
|
710 dim_vector m1_dims = m1.dims (); \ |
|
711 dim_vector m2_dims = m2.dims (); \ |
|
712 \ |
|
713 if (m1_dims == m2_dims) \ |
|
714 { \ |
4826
|
715 r.resize (m1_dims); \ |
4543
|
716 \ |
4826
|
717 for (int i = 0; i < m1.length (); i++) \ |
|
718 r.elem(i) = C1 (m1.elem(i)) OP C2 (m2.elem(i)); \ |
4543
|
719 } \ |
|
720 else \ |
4826
|
721 gripe_nonconformant (#F, m1_dims, m2_dims); \ |
4543
|
722 \ |
|
723 return r; \ |
|
724 } |
|
725 |
|
726 #define NDND_CMP_OPS(ND1, C1, ND2, C2) \ |
4826
|
727 NDND_CMP_OP (mx_el_lt, <, ND1, C1, ND2, C2) \ |
|
728 NDND_CMP_OP (mx_el_le, <=, ND1, C1, ND2, C2) \ |
|
729 NDND_CMP_OP (mx_el_ge, >=, ND1, C1, ND2, C2) \ |
|
730 NDND_CMP_OP (mx_el_gt, >, ND1, C1, ND2, C2) \ |
|
731 NDND_CMP_OP (mx_el_eq, ==, ND1, , ND2, ) \ |
|
732 NDND_CMP_OP (mx_el_ne, !=, ND1, , ND2, ) |
4543
|
733 |
|
734 #define NDND_BOOL_OP_DECLS(ND1, ND2) \ |
|
735 NDBOOL_OP_DECL (mx_el_and, ND1, ND2); \ |
|
736 NDBOOL_OP_DECL (mx_el_or, ND1, ND2); |
|
737 |
|
738 #define NDND_BOOL_OP(F, OP, ND1, ND2, ZERO) \ |
|
739 boolNDArray \ |
|
740 F (const ND1& m1, const ND2& m2) \ |
|
741 { \ |
|
742 boolNDArray r; \ |
|
743 \ |
|
744 dim_vector m1_dims = m1.dims (); \ |
|
745 dim_vector m2_dims = m2.dims (); \ |
|
746 \ |
|
747 if (m1_dims == m2_dims) \ |
|
748 { \ |
|
749 if (! m1_dims.all_zero ()) \ |
|
750 { \ |
|
751 r.resize (m1_dims); \ |
|
752 \ |
|
753 for (int i = 0; i < m1.length (); i++) \ |
|
754 r.elem(i) = (m1.elem(i) != ZERO) OP (m2.elem(i) != ZERO); \ |
|
755 } \ |
|
756 } \ |
|
757 else \ |
|
758 gripe_nonconformant (#F, m1_dims, m2_dims); \ |
|
759 \ |
|
760 return r; \ |
|
761 } |
|
762 |
|
763 #define NDND_BOOL_OPS(ND1, ND2, ZERO) \ |
|
764 NDND_BOOL_OP (mx_el_and, &&, ND1, ND2, ZERO) \ |
|
765 NDND_BOOL_OP (mx_el_or, ||, ND1, ND2, ZERO) |
|
766 |
|
767 #define NDND_OP_DECLS(R, ND1, ND2) \ |
|
768 NDND_BIN_OP_DECLS (R, ND1, ND2) \ |
|
769 NDND_CMP_OP_DECLS (ND1, ND2) \ |
|
770 NDND_BOOL_OP_DECLS (ND1, ND2) |
|
771 |
2870
|
772 // scalar by diagonal matrix operations. |
|
773 |
|
774 #define SDM_BIN_OP_DECLS(R, S, DM) \ |
|
775 BIN_OP_DECL (R, operator +, S, DM); \ |
|
776 BIN_OP_DECL (R, operator -, S, DM); |
|
777 |
|
778 #define SDM_BIN_OP(R, OP, S, DM, OPEQ) \ |
2829
|
779 R \ |
|
780 OP (const S& s, const DM& dm) \ |
|
781 { \ |
|
782 int nr = dm.rows (); \ |
|
783 int nc = dm.cols (); \ |
|
784 \ |
|
785 R r (nr, nc, s); \ |
|
786 \ |
4543
|
787 for (int i = 0; i < dm.length (); i++) \ |
2870
|
788 r.elem(i, i) OPEQ dm.elem(i, i); \ |
2829
|
789 \ |
|
790 return r; \ |
|
791 } |
|
792 |
2870
|
793 #define SDM_BIN_OPS(R, S, DM) \ |
|
794 SDM_BIN_OP (R, operator +, S, DM, +=) \ |
|
795 SDM_BIN_OP (R, operator -, S, DM, -=) |
|
796 |
|
797 #define SDM_OP_DECLS(R, S, DM) \ |
|
798 SDM_BIN_OP_DECLS(R, S, DM) |
2829
|
799 |
2870
|
800 // diagonal matrix by scalar operations. |
|
801 |
|
802 #define DMS_BIN_OP_DECLS(R, DM, S) \ |
|
803 BIN_OP_DECL (R, operator +, DM, S); \ |
|
804 BIN_OP_DECL (R, operator -, DM, S); |
|
805 |
|
806 #define DMS_BIN_OP(R, OP, DM, S, SGN) \ |
2829
|
807 R \ |
|
808 OP (const DM& dm, const S& s) \ |
|
809 { \ |
|
810 int nr = dm.rows (); \ |
|
811 int nc = dm.cols (); \ |
|
812 \ |
|
813 R r (nr, nc, SGN s); \ |
|
814 \ |
4543
|
815 for (int i = 0; i < dm.length (); i++) \ |
2870
|
816 r.elem(i, i) += dm.elem(i, i); \ |
2829
|
817 \ |
|
818 return r; \ |
|
819 } |
|
820 |
2870
|
821 #define DMS_BIN_OPS(R, DM, S) \ |
|
822 DMS_BIN_OP (R, operator +, DM, S, ) \ |
|
823 DMS_BIN_OP (R, operator -, DM, S, -) |
|
824 |
|
825 #define DMS_OP_DECLS(R, DM, S) \ |
|
826 DMS_BIN_OP_DECLS(R, DM, S) |
2829
|
827 |
2870
|
828 // matrix by diagonal matrix operations. |
|
829 |
|
830 #define MDM_BIN_OP_DECLS(R, M, DM) \ |
|
831 BIN_OP_DECL (R, operator +, M, DM); \ |
|
832 BIN_OP_DECL (R, operator -, M, DM); \ |
|
833 BIN_OP_DECL (R, operator *, M, DM); |
|
834 |
|
835 #define MDM_BIN_OP(R, OP, M, DM, OPEQ) \ |
2829
|
836 R \ |
|
837 OP (const M& m, const DM& dm) \ |
|
838 { \ |
|
839 R r; \ |
|
840 \ |
|
841 int m_nr = m.rows (); \ |
|
842 int m_nc = m.cols (); \ |
|
843 \ |
|
844 int dm_nr = dm.rows (); \ |
|
845 int dm_nc = dm.cols (); \ |
|
846 \ |
|
847 if (m_nr != dm_nr || m_nc != dm_nc) \ |
|
848 gripe_nonconformant (#OP, m_nr, m_nc, dm_nr, dm_nc); \ |
|
849 else \ |
|
850 { \ |
|
851 r.resize (m_nr, m_nc); \ |
|
852 \ |
|
853 if (m_nr > 0 && m_nc > 0) \ |
|
854 { \ |
3585
|
855 r = R (m); \ |
2829
|
856 \ |
|
857 int len = dm.length (); \ |
|
858 \ |
|
859 for (int i = 0; i < len; i++) \ |
2870
|
860 r.elem(i, i) OPEQ dm.elem(i, i); \ |
2829
|
861 } \ |
|
862 } \ |
|
863 \ |
|
864 return r; \ |
|
865 } |
|
866 |
3504
|
867 #define MDM_MULTIPLY_OP(R, M, DM, ZERO) \ |
2829
|
868 R \ |
|
869 operator * (const M& m, const DM& dm) \ |
|
870 { \ |
|
871 R r; \ |
|
872 \ |
|
873 int m_nr = m.rows (); \ |
|
874 int m_nc = m.cols (); \ |
|
875 \ |
|
876 int dm_nr = dm.rows (); \ |
|
877 int dm_nc = dm.cols (); \ |
|
878 \ |
|
879 if (m_nc != dm_nr) \ |
|
880 gripe_nonconformant ("operator *", m_nr, m_nc, dm_nr, dm_nc); \ |
|
881 else \ |
|
882 { \ |
3504
|
883 r.resize (m_nr, dm_nc, ZERO); \ |
2829
|
884 \ |
3176
|
885 if (m_nr > 0 && m_nc > 0 && dm_nc > 0) \ |
2829
|
886 { \ |
4543
|
887 int len = dm.length (); \ |
|
888 \ |
|
889 for (int j = 0; j < len; j++) \ |
2829
|
890 { \ |
2870
|
891 if (dm.elem(j, j) == 1.0) \ |
2829
|
892 { \ |
|
893 for (int i = 0; i < m_nr; i++) \ |
2870
|
894 r.elem(i, j) = m.elem(i, j); \ |
2829
|
895 } \ |
3504
|
896 else if (dm.elem(j, j) != ZERO) \ |
2829
|
897 { \ |
|
898 for (int i = 0; i < m_nr; i++) \ |
2870
|
899 r.elem(i, j) = dm.elem(j, j) * m.elem(i, j); \ |
2829
|
900 } \ |
|
901 } \ |
|
902 } \ |
|
903 } \ |
|
904 \ |
|
905 return r; \ |
|
906 } |
|
907 |
3504
|
908 #define MDM_BIN_OPS(R, M, DM, ZERO) \ |
2870
|
909 MDM_BIN_OP (R, operator +, M, DM, +=) \ |
|
910 MDM_BIN_OP (R, operator -, M, DM, -=) \ |
3504
|
911 MDM_MULTIPLY_OP (R, M, DM, ZERO) |
2829
|
912 |
2870
|
913 #define MDM_OP_DECLS(R, M, DM) \ |
|
914 MDM_BIN_OP_DECLS(R, M, DM) |
|
915 |
|
916 // diagonal matrix by matrix operations. |
|
917 |
|
918 #define DMM_BIN_OP_DECLS(R, DM, M) \ |
|
919 BIN_OP_DECL (R, operator +, DM, M); \ |
|
920 BIN_OP_DECL (R, operator -, DM, M); \ |
|
921 BIN_OP_DECL (R, operator *, DM, M); |
|
922 |
3585
|
923 #define DMM_BIN_OP(R, OP, DM, M, OPEQ, PREOP) \ |
2829
|
924 R \ |
|
925 OP (const DM& dm, const M& m) \ |
|
926 { \ |
|
927 R r; \ |
|
928 \ |
|
929 int dm_nr = dm.rows (); \ |
|
930 int dm_nc = dm.cols (); \ |
|
931 \ |
|
932 int m_nr = m.rows (); \ |
|
933 int m_nc = m.cols (); \ |
|
934 \ |
|
935 if (dm_nr != m_nr || dm_nc != m_nc) \ |
|
936 gripe_nonconformant (#OP, dm_nr, dm_nc, m_nr, m_nc); \ |
|
937 else \ |
|
938 { \ |
|
939 if (m_nr > 0 && m_nc > 0) \ |
|
940 { \ |
3585
|
941 r = R (PREOP m); \ |
2829
|
942 \ |
|
943 int len = dm.length (); \ |
|
944 \ |
|
945 for (int i = 0; i < len; i++) \ |
2870
|
946 r.elem(i, i) OPEQ dm.elem(i, i); \ |
2829
|
947 } \ |
|
948 else \ |
|
949 r.resize (m_nr, m_nc); \ |
|
950 } \ |
|
951 \ |
|
952 return r; \ |
|
953 } |
|
954 |
3504
|
955 #define DMM_MULTIPLY_OP(R, DM, M, ZERO) \ |
2829
|
956 R \ |
|
957 operator * (const DM& dm, const M& m) \ |
|
958 { \ |
|
959 R r; \ |
|
960 \ |
|
961 int dm_nr = dm.rows (); \ |
|
962 int dm_nc = dm.cols (); \ |
|
963 \ |
|
964 int m_nr = m.rows (); \ |
|
965 int m_nc = m.cols (); \ |
|
966 \ |
|
967 if (dm_nc != m_nr) \ |
|
968 gripe_nonconformant ("operator *", dm_nr, dm_nc, m_nr, m_nc); \ |
|
969 else \ |
|
970 { \ |
3504
|
971 r.resize (dm_nr, m_nc, ZERO); \ |
2829
|
972 \ |
|
973 if (dm_nr > 0 && dm_nc > 0 && m_nc > 0) \ |
|
974 { \ |
4543
|
975 int len = dm.length (); \ |
|
976 \ |
|
977 for (int i = 0; i < len; i++) \ |
2829
|
978 { \ |
2870
|
979 if (dm.elem(i, i) == 1.0) \ |
2829
|
980 { \ |
|
981 for (int j = 0; j < m_nc; j++) \ |
2870
|
982 r.elem(i, j) = m.elem(i, j); \ |
2829
|
983 } \ |
3504
|
984 else if (dm.elem(i, i) != ZERO) \ |
2829
|
985 { \ |
|
986 for (int j = 0; j < m_nc; j++) \ |
2870
|
987 r.elem(i, j) = dm.elem(i, i) * m.elem(i, j); \ |
2829
|
988 } \ |
|
989 } \ |
|
990 } \ |
|
991 } \ |
|
992 \ |
|
993 return r; \ |
|
994 } |
|
995 |
3504
|
996 #define DMM_BIN_OPS(R, DM, M, ZERO) \ |
3585
|
997 DMM_BIN_OP (R, operator +, DM, M, +=, ) \ |
|
998 DMM_BIN_OP (R, operator -, DM, M, +=, -) \ |
|
999 DMM_MULTIPLY_OP (R, DM, M, ZERO) |
2829
|
1000 |
2870
|
1001 #define DMM_OP_DECLS(R, DM, M) \ |
|
1002 DMM_BIN_OP_DECLS(R, DM, M) |
|
1003 |
|
1004 // diagonal matrix by diagonal matrix operations. |
2829
|
1005 |
2870
|
1006 #define DMDM_BIN_OP_DECLS(R, DM1, DM2) \ |
|
1007 BIN_OP_DECL (R, operator +, DM1, DM2); \ |
|
1008 BIN_OP_DECL (R, operator -, DM1, DM2); \ |
|
1009 BIN_OP_DECL (R, product, DM1, DM2); |
|
1010 |
|
1011 #define DMDM_BIN_OP(R, OP, DM1, DM2, F) \ |
2829
|
1012 R \ |
|
1013 OP (const DM1& dm1, const DM2& dm2) \ |
|
1014 { \ |
|
1015 R r; \ |
|
1016 \ |
|
1017 int dm1_nr = dm1.rows (); \ |
|
1018 int dm1_nc = dm1.cols (); \ |
|
1019 \ |
|
1020 int dm2_nr = dm2.rows (); \ |
|
1021 int dm2_nc = dm2.cols (); \ |
|
1022 \ |
|
1023 if (dm1_nr != dm2_nr || dm1_nc != dm2_nc) \ |
|
1024 gripe_nonconformant (#OP, dm1_nr, dm1_nc, dm2_nr, dm2_nc); \ |
|
1025 else \ |
|
1026 { \ |
|
1027 r.resize (dm1_nr, dm1_nc); \ |
|
1028 \ |
|
1029 if (dm1_nr > 0 && dm1_nc > 0) \ |
|
1030 F ## _vv (r.fortran_vec (), dm1.data (), dm2.data (), \ |
|
1031 dm1_nr * dm2_nc); \ |
|
1032 } \ |
|
1033 \ |
|
1034 return r; \ |
|
1035 } |
|
1036 |
2870
|
1037 #define DMDM_BIN_OPS(R, DM1, DM2) \ |
3769
|
1038 DMDM_BIN_OP (R, operator +, DM1, DM2, mx_inline_add) \ |
|
1039 DMDM_BIN_OP (R, operator -, DM1, DM2, mx_inline_subtract) \ |
|
1040 DMDM_BIN_OP (R, product, DM1, DM2, mx_inline_multiply) |
2870
|
1041 |
|
1042 #define DMDM_OP_DECLS(R, DM1, DM2) \ |
|
1043 DMDM_BIN_OP_DECLS (R, DM1, DM2) |
2829
|
1044 |
3582
|
1045 #endif |
|
1046 |
2829
|
1047 /* |
|
1048 ;;; Local Variables: *** |
|
1049 ;;; mode: C++ *** |
|
1050 ;;; End: *** |
|
1051 */ |