Mercurial > octave-nkf
annotate liboctave/mx-op-defs.h @ 8710:739141cde75a ss-3-1-52
fix typo in Array-f.cc
author | Jaroslav Hajek <highegg@gmail.com> |
---|---|
date | Mon, 09 Feb 2009 21:51:31 +0100 |
parents | 4780279e8094 |
children | b756ce0002db |
rev | line source |
---|---|
2829 | 1 /* |
2 | |
7017 | 3 Copyright (C) 1996, 1997, 1998, 2000, 2001, 2003, 2004, 2005, 2006, |
4 2007 John W. Eaton | |
8380
dbe67764e628
fix & improve speed of diagonal matrix multiplication
Jaroslav Hajek <highegg@gmail.com>
parents:
8375
diff
changeset
|
5 Copyright (C) 2008 Jaroslav Hajek |
2829 | 6 |
7 This file is part of Octave. | |
8 | |
9 Octave is free software; you can redistribute it and/or modify it | |
10 under the terms of the GNU General Public License as published by the | |
7016 | 11 Free Software Foundation; either version 3 of the License, or (at your |
12 option) any later version. | |
2829 | 13 |
14 Octave is distributed in the hope that it will be useful, but WITHOUT | |
15 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or | |
16 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License | |
17 for more details. | |
18 | |
19 You should have received a copy of the GNU General Public License | |
7016 | 20 along with Octave; see the file COPYING. If not, see |
21 <http://www.gnu.org/licenses/>. | |
2829 | 22 |
23 */ | |
24 | |
25 #if !defined (octave_mx_op_defs_h) | |
26 #define octave_mx_op_defs_h 1 | |
27 | |
8380
dbe67764e628
fix & improve speed of diagonal matrix multiplication
Jaroslav Hajek <highegg@gmail.com>
parents:
8375
diff
changeset
|
28 #include "oct-types.h" |
2829 | 29 #include "mx-inlines.cc" |
30 | |
6708 | 31 #define BIN_OP_DECL(R, OP, X, Y, API) \ |
32 extern API R OP (const X&, const Y&) | |
2829 | 33 |
2870 | 34 class boolMatrix; |
4543 | 35 class boolNDArray; |
2870 | 36 |
6708 | 37 #define CMP_OP_DECL(OP, X, Y, API) \ |
38 extern API boolMatrix OP (const X&, const Y&) | |
2870 | 39 |
6708 | 40 #define NDCMP_OP_DECL(OP, X, Y, API) \ |
41 extern API boolNDArray OP (const X&, const Y&) | |
4543 | 42 |
6708 | 43 #define BOOL_OP_DECL(OP, X, Y, API) \ |
44 extern API boolMatrix OP (const X&, const Y&) | |
2870 | 45 |
6708 | 46 #define NDBOOL_OP_DECL(OP, X, Y, API) \ |
47 extern API boolNDArray OP (const X&, const Y&) | |
4543 | 48 |
2870 | 49 // vector by scalar operations. |
50 | |
6708 | 51 #define VS_BIN_OP_DECLS(R, V, S, API) \ |
52 BIN_OP_DECL (R, operator +, V, S, API); \ | |
53 BIN_OP_DECL (R, operator -, V, S, API); \ | |
54 BIN_OP_DECL (R, operator *, V, S, API); \ | |
55 BIN_OP_DECL (R, operator /, V, S, API); | |
2870 | 56 |
57 #define VS_BIN_OP(R, F, OP, V, S) \ | |
58 R \ | |
59 F (const V& v, const S& s) \ | |
60 { \ | |
8380
dbe67764e628
fix & improve speed of diagonal matrix multiplication
Jaroslav Hajek <highegg@gmail.com>
parents:
8375
diff
changeset
|
61 octave_idx_type len = v.length (); \ |
2870 | 62 \ |
63 R r (len); \ | |
64 \ | |
8380
dbe67764e628
fix & improve speed of diagonal matrix multiplication
Jaroslav Hajek <highegg@gmail.com>
parents:
8375
diff
changeset
|
65 for (octave_idx_type i = 0; i < len; i++) \ |
2870 | 66 r.elem(i) = v.elem(i) OP s; \ |
67 \ | |
68 return r; \ | |
69 } | |
70 | |
71 #define VS_BIN_OPS(R, V, S) \ | |
72 VS_BIN_OP (R, operator +, +, V, S) \ | |
73 VS_BIN_OP (R, operator -, -, V, S) \ | |
74 VS_BIN_OP (R, operator *, *, V, S) \ | |
75 VS_BIN_OP (R, operator /, /, V, S) | |
76 | |
6708 | 77 #define VS_OP_DECLS(R, V, S, API) \ |
78 VS_BIN_OP_DECLS(R, V, S, API) | |
3582 | 79 |
2870 | 80 // scalar by vector by operations. |
81 | |
6708 | 82 #define SV_BIN_OP_DECLS(R, S, V, API) \ |
83 BIN_OP_DECL (R, operator +, S, V, API); \ | |
84 BIN_OP_DECL (R, operator -, S, V, API); \ | |
85 BIN_OP_DECL (R, operator *, S, V, API); \ | |
86 BIN_OP_DECL (R, operator /, S, V, API); | |
2870 | 87 |
88 #define SV_BIN_OP(R, F, OP, S, V) \ | |
89 R \ | |
90 F (const S& s, const V& v) \ | |
91 { \ | |
8380
dbe67764e628
fix & improve speed of diagonal matrix multiplication
Jaroslav Hajek <highegg@gmail.com>
parents:
8375
diff
changeset
|
92 octave_idx_type len = v.length (); \ |
2870 | 93 \ |
94 R r (len); \ | |
95 \ | |
8380
dbe67764e628
fix & improve speed of diagonal matrix multiplication
Jaroslav Hajek <highegg@gmail.com>
parents:
8375
diff
changeset
|
96 for (octave_idx_type i = 0; i < len; i++) \ |
2870 | 97 r.elem(i) = s OP v.elem(i); \ |
98 \ | |
99 return r; \ | |
100 } | |
101 | |
102 #define SV_BIN_OPS(R, S, V) \ | |
103 SV_BIN_OP (R, operator +, +, S, V) \ | |
104 SV_BIN_OP (R, operator -, -, S, V) \ | |
105 SV_BIN_OP (R, operator *, *, S, V) \ | |
106 SV_BIN_OP (R, operator /, /, S, V) | |
107 | |
6708 | 108 #define SV_OP_DECLS(R, S, V, API) \ |
109 SV_BIN_OP_DECLS(R, S, V, API) | |
3582 | 110 |
2870 | 111 // vector by vector operations. |
112 | |
6708 | 113 #define VV_BIN_OP_DECLS(R, V1, V2, API) \ |
114 BIN_OP_DECL (R, operator +, V1, V2, API); \ | |
115 BIN_OP_DECL (R, operator -, V1, V2, API); \ | |
116 BIN_OP_DECL (R, product, V1, V2, API); \ | |
117 BIN_OP_DECL (R, quotient, V1, V2, API); | |
2870 | 118 |
119 #define VV_BIN_OP(R, F, OP, V1, V2) \ | |
120 R \ | |
121 F (const V1& v1, const V2& v2) \ | |
122 { \ | |
123 R r; \ | |
124 \ | |
8380
dbe67764e628
fix & improve speed of diagonal matrix multiplication
Jaroslav Hajek <highegg@gmail.com>
parents:
8375
diff
changeset
|
125 octave_idx_type v1_len = v1.length (); \ |
dbe67764e628
fix & improve speed of diagonal matrix multiplication
Jaroslav Hajek <highegg@gmail.com>
parents:
8375
diff
changeset
|
126 octave_idx_type v2_len = v2.length (); \ |
2870 | 127 \ |
128 if (v1_len != v2_len) \ | |
129 gripe_nonconformant (#OP, v1_len, v2_len); \ | |
130 else \ | |
131 { \ | |
132 r.resize (v1_len); \ | |
133 \ | |
8380
dbe67764e628
fix & improve speed of diagonal matrix multiplication
Jaroslav Hajek <highegg@gmail.com>
parents:
8375
diff
changeset
|
134 for (octave_idx_type i = 0; i < v1_len; i++) \ |
2870 | 135 r.elem(i) = v1.elem(i) OP v2.elem(i); \ |
136 } \ | |
137 \ | |
138 return r; \ | |
139 } | |
140 | |
141 #define VV_BIN_OPS(R, V1, V2) \ | |
142 VV_BIN_OP (R, operator +, +, V1, V2) \ | |
143 VV_BIN_OP (R, operator -, -, V1, V2) \ | |
144 VV_BIN_OP (R, product, *, V1, V2) \ | |
145 VV_BIN_OP (R, quotient, /, V1, V2) | |
146 | |
6708 | 147 #define VV_OP_DECLS(R, V1, V2, API) \ |
148 VV_BIN_OP_DECLS(R, V1, V2, API) | |
2870 | 149 |
150 // matrix by scalar operations. | |
151 | |
6708 | 152 #define MS_BIN_OP_DECLS(R, M, S, API) \ |
153 BIN_OP_DECL (R, operator +, M, S, API); \ | |
154 BIN_OP_DECL (R, operator -, M, S, API); \ | |
155 BIN_OP_DECL (R, operator *, M, S, API); \ | |
156 BIN_OP_DECL (R, operator /, M, S, API); | |
2829 | 157 |
2870 | 158 #define MS_BIN_OP(R, OP, M, S, F) \ |
2829 | 159 R \ |
160 OP (const M& m, const S& s) \ | |
161 { \ | |
8380
dbe67764e628
fix & improve speed of diagonal matrix multiplication
Jaroslav Hajek <highegg@gmail.com>
parents:
8375
diff
changeset
|
162 octave_idx_type nr = m.rows (); \ |
dbe67764e628
fix & improve speed of diagonal matrix multiplication
Jaroslav Hajek <highegg@gmail.com>
parents:
8375
diff
changeset
|
163 octave_idx_type nc = m.cols (); \ |
2829 | 164 \ |
165 R r (nr, nc); \ | |
166 \ | |
167 if (nr > 0 && nc > 0) \ | |
168 F ## _vs (r.fortran_vec (), m.data (), nr * nc, s); \ | |
169 \ | |
170 return r; \ | |
171 } | |
172 | |
2870 | 173 #define MS_BIN_OPS(R, M, S) \ |
3769 | 174 MS_BIN_OP (R, operator +, M, S, mx_inline_add) \ |
175 MS_BIN_OP (R, operator -, M, S, mx_inline_subtract) \ | |
176 MS_BIN_OP (R, operator *, M, S, mx_inline_multiply) \ | |
177 MS_BIN_OP (R, operator /, M, S, mx_inline_divide) | |
2870 | 178 |
6708 | 179 #define MS_CMP_OP_DECLS(M, S, API) \ |
180 CMP_OP_DECL (mx_el_lt, M, S, API); \ | |
181 CMP_OP_DECL (mx_el_le, M, S, API); \ | |
182 CMP_OP_DECL (mx_el_ge, M, S, API); \ | |
183 CMP_OP_DECL (mx_el_gt, M, S, API); \ | |
184 CMP_OP_DECL (mx_el_eq, M, S, API); \ | |
185 CMP_OP_DECL (mx_el_ne, M, S, API); | |
2870 | 186 |
4826 | 187 #define MS_CMP_OP(F, OP, M, MC, S, SC) \ |
2870 | 188 boolMatrix \ |
189 F (const M& m, const S& s) \ | |
190 { \ | |
191 boolMatrix r; \ | |
192 \ | |
8380
dbe67764e628
fix & improve speed of diagonal matrix multiplication
Jaroslav Hajek <highegg@gmail.com>
parents:
8375
diff
changeset
|
193 octave_idx_type nr = m.rows (); \ |
dbe67764e628
fix & improve speed of diagonal matrix multiplication
Jaroslav Hajek <highegg@gmail.com>
parents:
8375
diff
changeset
|
194 octave_idx_type nc = m.cols (); \ |
2870 | 195 \ |
4826 | 196 r.resize (nr, nc); \ |
197 \ | |
198 if (nr > 0 && nc > 0) \ | |
2870 | 199 { \ |
8380
dbe67764e628
fix & improve speed of diagonal matrix multiplication
Jaroslav Hajek <highegg@gmail.com>
parents:
8375
diff
changeset
|
200 for (octave_idx_type j = 0; j < nc; j++) \ |
dbe67764e628
fix & improve speed of diagonal matrix multiplication
Jaroslav Hajek <highegg@gmail.com>
parents:
8375
diff
changeset
|
201 for (octave_idx_type i = 0; i < nr; i++) \ |
2870 | 202 r.elem(i, j) = MC (m.elem(i, j)) OP SC (s); \ |
203 } \ | |
204 \ | |
205 return r; \ | |
206 } | |
2829 | 207 |
2870 | 208 #define MS_CMP_OPS(M, CM, S, CS) \ |
4826 | 209 MS_CMP_OP (mx_el_lt, <, M, CM, S, CS) \ |
210 MS_CMP_OP (mx_el_le, <=, M, CM, S, CS) \ | |
211 MS_CMP_OP (mx_el_ge, >=, M, CM, S, CS) \ | |
212 MS_CMP_OP (mx_el_gt, >, M, CM, S, CS) \ | |
213 MS_CMP_OP (mx_el_eq, ==, M, , S, ) \ | |
214 MS_CMP_OP (mx_el_ne, !=, M, , S, ) | |
2870 | 215 |
6708 | 216 #define MS_BOOL_OP_DECLS(M, S, API) \ |
217 BOOL_OP_DECL (mx_el_and, M, S, API); \ | |
218 BOOL_OP_DECL (mx_el_or, M, S, API); \ | |
2870 | 219 |
5030 | 220 #define MS_BOOL_OP(F, OP, M, S, LHS_ZERO, RHS_ZERO) \ |
2870 | 221 boolMatrix \ |
222 F (const M& m, const S& s) \ | |
223 { \ | |
224 boolMatrix r; \ | |
225 \ | |
8380
dbe67764e628
fix & improve speed of diagonal matrix multiplication
Jaroslav Hajek <highegg@gmail.com>
parents:
8375
diff
changeset
|
226 octave_idx_type nr = m.rows (); \ |
dbe67764e628
fix & improve speed of diagonal matrix multiplication
Jaroslav Hajek <highegg@gmail.com>
parents:
8375
diff
changeset
|
227 octave_idx_type nc = m.cols (); \ |
2870 | 228 \ |
229 if (nr != 0 && nc != 0) \ | |
230 { \ | |
231 r.resize (nr, nc); \ | |
232 \ | |
7922
935be827eaf8
error for NaN values in & and | expressions
John W. Eaton <jwe@octave.org>
parents:
7789
diff
changeset
|
233 if (xisnan (s)) \ |
935be827eaf8
error for NaN values in & and | expressions
John W. Eaton <jwe@octave.org>
parents:
7789
diff
changeset
|
234 gripe_nan_to_logical_conversion (); \ |
935be827eaf8
error for NaN values in & and | expressions
John W. Eaton <jwe@octave.org>
parents:
7789
diff
changeset
|
235 else \ |
935be827eaf8
error for NaN values in & and | expressions
John W. Eaton <jwe@octave.org>
parents:
7789
diff
changeset
|
236 { \ |
935be827eaf8
error for NaN values in & and | expressions
John W. Eaton <jwe@octave.org>
parents:
7789
diff
changeset
|
237 \ |
8380
dbe67764e628
fix & improve speed of diagonal matrix multiplication
Jaroslav Hajek <highegg@gmail.com>
parents:
8375
diff
changeset
|
238 for (octave_idx_type j = 0; j < nc; j++) \ |
dbe67764e628
fix & improve speed of diagonal matrix multiplication
Jaroslav Hajek <highegg@gmail.com>
parents:
8375
diff
changeset
|
239 for (octave_idx_type i = 0; i < nr; i++) \ |
7922
935be827eaf8
error for NaN values in & and | expressions
John W. Eaton <jwe@octave.org>
parents:
7789
diff
changeset
|
240 if (xisnan (m.elem(i, j))) \ |
935be827eaf8
error for NaN values in & and | expressions
John W. Eaton <jwe@octave.org>
parents:
7789
diff
changeset
|
241 { \ |
935be827eaf8
error for NaN values in & and | expressions
John W. Eaton <jwe@octave.org>
parents:
7789
diff
changeset
|
242 gripe_nan_to_logical_conversion (); \ |
935be827eaf8
error for NaN values in & and | expressions
John W. Eaton <jwe@octave.org>
parents:
7789
diff
changeset
|
243 return r; \ |
935be827eaf8
error for NaN values in & and | expressions
John W. Eaton <jwe@octave.org>
parents:
7789
diff
changeset
|
244 } \ |
935be827eaf8
error for NaN values in & and | expressions
John W. Eaton <jwe@octave.org>
parents:
7789
diff
changeset
|
245 else \ |
935be827eaf8
error for NaN values in & and | expressions
John W. Eaton <jwe@octave.org>
parents:
7789
diff
changeset
|
246 r.elem(i, j) = (m.elem(i, j) != LHS_ZERO) OP (s != RHS_ZERO); \ |
935be827eaf8
error for NaN values in & and | expressions
John W. Eaton <jwe@octave.org>
parents:
7789
diff
changeset
|
247 } \ |
2870 | 248 } \ |
249 \ | |
250 return r; \ | |
251 } | |
252 | |
5030 | 253 #define MS_BOOL_OPS2(M, S, LHS_ZERO, RHS_ZERO) \ |
254 MS_BOOL_OP (mx_el_and, &&, M, S, LHS_ZERO, RHS_ZERO) \ | |
255 MS_BOOL_OP (mx_el_or, ||, M, S, LHS_ZERO, RHS_ZERO) | |
256 | |
3504 | 257 #define MS_BOOL_OPS(M, S, ZERO) \ |
5030 | 258 MS_BOOL_OPS2(M, S, ZERO, ZERO) |
2870 | 259 |
6708 | 260 #define MS_OP_DECLS(R, M, S, API) \ |
261 MS_BIN_OP_DECLS (R, M, S, API) \ | |
262 MS_CMP_OP_DECLS (M, S, API) \ | |
263 MS_BOOL_OP_DECLS (M, S, API) \ | |
2870 | 264 |
265 // scalar by matrix operations. | |
266 | |
6708 | 267 #define SM_BIN_OP_DECLS(R, S, M, API) \ |
268 BIN_OP_DECL (R, operator +, S, M, API); \ | |
269 BIN_OP_DECL (R, operator -, S, M, API); \ | |
270 BIN_OP_DECL (R, operator *, S, M, API); \ | |
271 BIN_OP_DECL (R, operator /, S, M, API); | |
2870 | 272 |
273 #define SM_BIN_OP(R, OP, S, M, F) \ | |
2829 | 274 R \ |
275 OP (const S& s, const M& m) \ | |
276 { \ | |
8380
dbe67764e628
fix & improve speed of diagonal matrix multiplication
Jaroslav Hajek <highegg@gmail.com>
parents:
8375
diff
changeset
|
277 octave_idx_type nr = m.rows (); \ |
dbe67764e628
fix & improve speed of diagonal matrix multiplication
Jaroslav Hajek <highegg@gmail.com>
parents:
8375
diff
changeset
|
278 octave_idx_type nc = m.cols (); \ |
2829 | 279 \ |
280 R r (nr, nc); \ | |
281 \ | |
282 if (nr > 0 && nc > 0) \ | |
283 F ## _sv (r.fortran_vec (), s, m.data (), nr * nc); \ | |
284 \ | |
285 return r; \ | |
286 } | |
287 | |
2870 | 288 #define SM_BIN_OPS(R, S, M) \ |
3769 | 289 SM_BIN_OP (R, operator +, S, M, mx_inline_add) \ |
290 SM_BIN_OP (R, operator -, S, M, mx_inline_subtract) \ | |
291 SM_BIN_OP (R, operator *, S, M, mx_inline_multiply) \ | |
292 SM_BIN_OP (R, operator /, S, M, mx_inline_divide) | |
2870 | 293 |
6708 | 294 #define SM_CMP_OP_DECLS(S, M, API) \ |
295 CMP_OP_DECL (mx_el_lt, S, M, API); \ | |
296 CMP_OP_DECL (mx_el_le, S, M, API); \ | |
297 CMP_OP_DECL (mx_el_ge, S, M, API); \ | |
298 CMP_OP_DECL (mx_el_gt, S, M, API); \ | |
299 CMP_OP_DECL (mx_el_eq, S, M, API); \ | |
300 CMP_OP_DECL (mx_el_ne, S, M, API); | |
2870 | 301 |
4826 | 302 #define SM_CMP_OP(F, OP, S, SC, M, MC) \ |
2870 | 303 boolMatrix \ |
304 F (const S& s, const M& m) \ | |
305 { \ | |
306 boolMatrix r; \ | |
307 \ | |
8380
dbe67764e628
fix & improve speed of diagonal matrix multiplication
Jaroslav Hajek <highegg@gmail.com>
parents:
8375
diff
changeset
|
308 octave_idx_type nr = m.rows (); \ |
dbe67764e628
fix & improve speed of diagonal matrix multiplication
Jaroslav Hajek <highegg@gmail.com>
parents:
8375
diff
changeset
|
309 octave_idx_type nc = m.cols (); \ |
2870 | 310 \ |
4826 | 311 r.resize (nr, nc); \ |
312 \ | |
313 if (nr > 0 && nc > 0) \ | |
2870 | 314 { \ |
8380
dbe67764e628
fix & improve speed of diagonal matrix multiplication
Jaroslav Hajek <highegg@gmail.com>
parents:
8375
diff
changeset
|
315 for (octave_idx_type j = 0; j < nc; j++) \ |
dbe67764e628
fix & improve speed of diagonal matrix multiplication
Jaroslav Hajek <highegg@gmail.com>
parents:
8375
diff
changeset
|
316 for (octave_idx_type i = 0; i < nr; i++) \ |
2870 | 317 r.elem(i, j) = SC (s) OP MC (m.elem(i, j)); \ |
318 } \ | |
319 \ | |
320 return r; \ | |
321 } | |
2829 | 322 |
2870 | 323 #define SM_CMP_OPS(S, CS, M, CM) \ |
4826 | 324 SM_CMP_OP (mx_el_lt, <, S, CS, M, CM) \ |
325 SM_CMP_OP (mx_el_le, <=, S, CS, M, CM) \ | |
326 SM_CMP_OP (mx_el_ge, >=, S, CS, M, CM) \ | |
327 SM_CMP_OP (mx_el_gt, >, S, CS, M, CM) \ | |
328 SM_CMP_OP (mx_el_eq, ==, S, , M, ) \ | |
329 SM_CMP_OP (mx_el_ne, !=, S, , M, ) | |
2870 | 330 |
6708 | 331 #define SM_BOOL_OP_DECLS(S, M, API) \ |
332 BOOL_OP_DECL (mx_el_and, S, M, API); \ | |
333 BOOL_OP_DECL (mx_el_or, S, M, API); \ | |
2870 | 334 |
5030 | 335 #define SM_BOOL_OP(F, OP, S, M, LHS_ZERO, RHS_ZERO) \ |
2870 | 336 boolMatrix \ |
337 F (const S& s, const M& m) \ | |
338 { \ | |
339 boolMatrix r; \ | |
340 \ | |
8380
dbe67764e628
fix & improve speed of diagonal matrix multiplication
Jaroslav Hajek <highegg@gmail.com>
parents:
8375
diff
changeset
|
341 octave_idx_type nr = m.rows (); \ |
dbe67764e628
fix & improve speed of diagonal matrix multiplication
Jaroslav Hajek <highegg@gmail.com>
parents:
8375
diff
changeset
|
342 octave_idx_type nc = m.cols (); \ |
2870 | 343 \ |
344 if (nr != 0 && nc != 0) \ | |
345 { \ | |
346 r.resize (nr, nc); \ | |
347 \ | |
7922
935be827eaf8
error for NaN values in & and | expressions
John W. Eaton <jwe@octave.org>
parents:
7789
diff
changeset
|
348 if (xisnan (s)) \ |
935be827eaf8
error for NaN values in & and | expressions
John W. Eaton <jwe@octave.org>
parents:
7789
diff
changeset
|
349 gripe_nan_to_logical_conversion (); \ |
935be827eaf8
error for NaN values in & and | expressions
John W. Eaton <jwe@octave.org>
parents:
7789
diff
changeset
|
350 else \ |
935be827eaf8
error for NaN values in & and | expressions
John W. Eaton <jwe@octave.org>
parents:
7789
diff
changeset
|
351 { \ |
8380
dbe67764e628
fix & improve speed of diagonal matrix multiplication
Jaroslav Hajek <highegg@gmail.com>
parents:
8375
diff
changeset
|
352 for (octave_idx_type j = 0; j < nc; j++) \ |
dbe67764e628
fix & improve speed of diagonal matrix multiplication
Jaroslav Hajek <highegg@gmail.com>
parents:
8375
diff
changeset
|
353 for (octave_idx_type i = 0; i < nr; i++) \ |
7922
935be827eaf8
error for NaN values in & and | expressions
John W. Eaton <jwe@octave.org>
parents:
7789
diff
changeset
|
354 if (xisnan (m.elem(i, j))) \ |
935be827eaf8
error for NaN values in & and | expressions
John W. Eaton <jwe@octave.org>
parents:
7789
diff
changeset
|
355 { \ |
935be827eaf8
error for NaN values in & and | expressions
John W. Eaton <jwe@octave.org>
parents:
7789
diff
changeset
|
356 gripe_nan_to_logical_conversion (); \ |
935be827eaf8
error for NaN values in & and | expressions
John W. Eaton <jwe@octave.org>
parents:
7789
diff
changeset
|
357 return r; \ |
935be827eaf8
error for NaN values in & and | expressions
John W. Eaton <jwe@octave.org>
parents:
7789
diff
changeset
|
358 } \ |
935be827eaf8
error for NaN values in & and | expressions
John W. Eaton <jwe@octave.org>
parents:
7789
diff
changeset
|
359 else \ |
935be827eaf8
error for NaN values in & and | expressions
John W. Eaton <jwe@octave.org>
parents:
7789
diff
changeset
|
360 r.elem(i, j) = (s != LHS_ZERO) OP (m.elem(i, j) != RHS_ZERO); \ |
935be827eaf8
error for NaN values in & and | expressions
John W. Eaton <jwe@octave.org>
parents:
7789
diff
changeset
|
361 } \ |
2870 | 362 } \ |
363 \ | |
364 return r; \ | |
365 } | |
366 | |
5030 | 367 #define SM_BOOL_OPS2(S, M, LHS_ZERO, RHS_ZERO) \ |
368 SM_BOOL_OP (mx_el_and, &&, S, M, LHS_ZERO, RHS_ZERO) \ | |
369 SM_BOOL_OP (mx_el_or, ||, S, M, LHS_ZERO, RHS_ZERO) | |
370 | |
3504 | 371 #define SM_BOOL_OPS(S, M, ZERO) \ |
5030 | 372 SM_BOOL_OPS2(S, M, ZERO, ZERO) |
2870 | 373 |
6708 | 374 #define SM_OP_DECLS(R, S, M, API) \ |
375 SM_BIN_OP_DECLS (R, S, M, API) \ | |
376 SM_CMP_OP_DECLS (S, M, API) \ | |
377 SM_BOOL_OP_DECLS (S, M, API) \ | |
2870 | 378 |
379 // matrix by matrix operations. | |
380 | |
6708 | 381 #define MM_BIN_OP_DECLS(R, M1, M2, API) \ |
382 BIN_OP_DECL (R, operator +, M1, M2, API); \ | |
383 BIN_OP_DECL (R, operator -, M1, M2, API); \ | |
384 BIN_OP_DECL (R, product, M1, M2, API); \ | |
385 BIN_OP_DECL (R, quotient, M1, M2, API); | |
2870 | 386 |
387 #define MM_BIN_OP(R, OP, M1, M2, F) \ | |
2829 | 388 R \ |
389 OP (const M1& m1, const M2& m2) \ | |
390 { \ | |
391 R r; \ | |
392 \ | |
8380
dbe67764e628
fix & improve speed of diagonal matrix multiplication
Jaroslav Hajek <highegg@gmail.com>
parents:
8375
diff
changeset
|
393 octave_idx_type m1_nr = m1.rows (); \ |
dbe67764e628
fix & improve speed of diagonal matrix multiplication
Jaroslav Hajek <highegg@gmail.com>
parents:
8375
diff
changeset
|
394 octave_idx_type m1_nc = m1.cols (); \ |
2829 | 395 \ |
8380
dbe67764e628
fix & improve speed of diagonal matrix multiplication
Jaroslav Hajek <highegg@gmail.com>
parents:
8375
diff
changeset
|
396 octave_idx_type m2_nr = m2.rows (); \ |
dbe67764e628
fix & improve speed of diagonal matrix multiplication
Jaroslav Hajek <highegg@gmail.com>
parents:
8375
diff
changeset
|
397 octave_idx_type m2_nc = m2.cols (); \ |
2829 | 398 \ |
399 if (m1_nr != m2_nr || m1_nc != m2_nc) \ | |
400 gripe_nonconformant (#OP, m1_nr, m1_nc, m2_nr, m2_nc); \ | |
401 else \ | |
402 { \ | |
403 r.resize (m1_nr, m1_nc); \ | |
404 \ | |
405 if (m1_nr > 0 && m1_nc > 0) \ | |
406 F ## _vv (r.fortran_vec (), m1.data (), m2.data (), m1_nr * m1_nc); \ | |
407 } \ | |
408 \ | |
409 return r; \ | |
410 } | |
411 | |
2870 | 412 #define MM_BIN_OPS(R, M1, M2) \ |
3769 | 413 MM_BIN_OP (R, operator +, M1, M2, mx_inline_add) \ |
414 MM_BIN_OP (R, operator -, M1, M2, mx_inline_subtract) \ | |
415 MM_BIN_OP (R, product, M1, M2, mx_inline_multiply) \ | |
416 MM_BIN_OP (R, quotient, M1, M2, mx_inline_divide) | |
2870 | 417 |
6708 | 418 #define MM_CMP_OP_DECLS(M1, M2, API) \ |
419 CMP_OP_DECL (mx_el_lt, M1, M2, API); \ | |
420 CMP_OP_DECL (mx_el_le, M1, M2, API); \ | |
421 CMP_OP_DECL (mx_el_ge, M1, M2, API); \ | |
422 CMP_OP_DECL (mx_el_gt, M1, M2, API); \ | |
423 CMP_OP_DECL (mx_el_eq, M1, M2, API); \ | |
424 CMP_OP_DECL (mx_el_ne, M1, M2, API); | |
2870 | 425 |
4826 | 426 #define MM_CMP_OP(F, OP, M1, C1, M2, C2) \ |
2870 | 427 boolMatrix \ |
428 F (const M1& m1, const M2& m2) \ | |
429 { \ | |
430 boolMatrix r; \ | |
431 \ | |
8380
dbe67764e628
fix & improve speed of diagonal matrix multiplication
Jaroslav Hajek <highegg@gmail.com>
parents:
8375
diff
changeset
|
432 octave_idx_type m1_nr = m1.rows (); \ |
dbe67764e628
fix & improve speed of diagonal matrix multiplication
Jaroslav Hajek <highegg@gmail.com>
parents:
8375
diff
changeset
|
433 octave_idx_type m1_nc = m1.cols (); \ |
2870 | 434 \ |
8380
dbe67764e628
fix & improve speed of diagonal matrix multiplication
Jaroslav Hajek <highegg@gmail.com>
parents:
8375
diff
changeset
|
435 octave_idx_type m2_nr = m2.rows (); \ |
dbe67764e628
fix & improve speed of diagonal matrix multiplication
Jaroslav Hajek <highegg@gmail.com>
parents:
8375
diff
changeset
|
436 octave_idx_type m2_nc = m2.cols (); \ |
2870 | 437 \ |
438 if (m1_nr == m2_nr && m1_nc == m2_nc) \ | |
439 { \ | |
4826 | 440 r.resize (m1_nr, m1_nc); \ |
2870 | 441 \ |
8380
dbe67764e628
fix & improve speed of diagonal matrix multiplication
Jaroslav Hajek <highegg@gmail.com>
parents:
8375
diff
changeset
|
442 for (octave_idx_type j = 0; j < m1_nc; j++) \ |
dbe67764e628
fix & improve speed of diagonal matrix multiplication
Jaroslav Hajek <highegg@gmail.com>
parents:
8375
diff
changeset
|
443 for (octave_idx_type i = 0; i < m1_nr; i++) \ |
4826 | 444 r.elem(i, j) = C1 (m1.elem(i, j)) OP C2 (m2.elem(i, j)); \ |
2870 | 445 } \ |
446 else \ | |
4826 | 447 gripe_nonconformant (#F, m1_nr, m1_nc, m2_nr, m2_nc); \ |
2870 | 448 \ |
449 return r; \ | |
450 } | |
2829 | 451 |
2870 | 452 #define MM_CMP_OPS(M1, C1, M2, C2) \ |
4826 | 453 MM_CMP_OP (mx_el_lt, <, M1, C1, M2, C2) \ |
454 MM_CMP_OP (mx_el_le, <=, M1, C1, M2, C2) \ | |
455 MM_CMP_OP (mx_el_ge, >=, M1, C1, M2, C2) \ | |
456 MM_CMP_OP (mx_el_gt, >, M1, C1, M2, C2) \ | |
457 MM_CMP_OP (mx_el_eq, ==, M1, , M2, ) \ | |
458 MM_CMP_OP (mx_el_ne, !=, M1, , M2, ) | |
2870 | 459 |
6708 | 460 #define MM_BOOL_OP_DECLS(M1, M2, API) \ |
461 BOOL_OP_DECL (mx_el_and, M1, M2, API); \ | |
462 BOOL_OP_DECL (mx_el_or, M1, M2, API); | |
2870 | 463 |
5030 | 464 #define MM_BOOL_OP(F, OP, M1, M2, LHS_ZERO, RHS_ZERO) \ |
2870 | 465 boolMatrix \ |
466 F (const M1& m1, const M2& m2) \ | |
467 { \ | |
468 boolMatrix r; \ | |
469 \ | |
8380
dbe67764e628
fix & improve speed of diagonal matrix multiplication
Jaroslav Hajek <highegg@gmail.com>
parents:
8375
diff
changeset
|
470 octave_idx_type m1_nr = m1.rows (); \ |
dbe67764e628
fix & improve speed of diagonal matrix multiplication
Jaroslav Hajek <highegg@gmail.com>
parents:
8375
diff
changeset
|
471 octave_idx_type m1_nc = m1.cols (); \ |
2870 | 472 \ |
8380
dbe67764e628
fix & improve speed of diagonal matrix multiplication
Jaroslav Hajek <highegg@gmail.com>
parents:
8375
diff
changeset
|
473 octave_idx_type m2_nr = m2.rows (); \ |
dbe67764e628
fix & improve speed of diagonal matrix multiplication
Jaroslav Hajek <highegg@gmail.com>
parents:
8375
diff
changeset
|
474 octave_idx_type m2_nc = m2.cols (); \ |
2870 | 475 \ |
476 if (m1_nr == m2_nr && m1_nc == m2_nc) \ | |
477 { \ | |
478 if (m1_nr != 0 || m1_nc != 0) \ | |
479 { \ | |
480 r.resize (m1_nr, m1_nc); \ | |
481 \ | |
8380
dbe67764e628
fix & improve speed of diagonal matrix multiplication
Jaroslav Hajek <highegg@gmail.com>
parents:
8375
diff
changeset
|
482 for (octave_idx_type j = 0; j < m1_nc; j++) \ |
dbe67764e628
fix & improve speed of diagonal matrix multiplication
Jaroslav Hajek <highegg@gmail.com>
parents:
8375
diff
changeset
|
483 for (octave_idx_type i = 0; i < m1_nr; i++) \ |
7922
935be827eaf8
error for NaN values in & and | expressions
John W. Eaton <jwe@octave.org>
parents:
7789
diff
changeset
|
484 if (xisnan (m1.elem(i, j)) || xisnan (m2.elem(i, j))) \ |
935be827eaf8
error for NaN values in & and | expressions
John W. Eaton <jwe@octave.org>
parents:
7789
diff
changeset
|
485 { \ |
935be827eaf8
error for NaN values in & and | expressions
John W. Eaton <jwe@octave.org>
parents:
7789
diff
changeset
|
486 gripe_nan_to_logical_conversion (); \ |
935be827eaf8
error for NaN values in & and | expressions
John W. Eaton <jwe@octave.org>
parents:
7789
diff
changeset
|
487 return r; \ |
935be827eaf8
error for NaN values in & and | expressions
John W. Eaton <jwe@octave.org>
parents:
7789
diff
changeset
|
488 } \ |
935be827eaf8
error for NaN values in & and | expressions
John W. Eaton <jwe@octave.org>
parents:
7789
diff
changeset
|
489 else \ |
935be827eaf8
error for NaN values in & and | expressions
John W. Eaton <jwe@octave.org>
parents:
7789
diff
changeset
|
490 r.elem(i, j) = (m1.elem(i, j) != LHS_ZERO) \ |
935be827eaf8
error for NaN values in & and | expressions
John W. Eaton <jwe@octave.org>
parents:
7789
diff
changeset
|
491 OP (m2.elem(i, j) != RHS_ZERO); \ |
2870 | 492 } \ |
493 } \ | |
494 else \ | |
495 { \ | |
496 if ((m1_nr != 0 || m1_nc != 0) && (m2_nr != 0 || m2_nc != 0)) \ | |
497 gripe_nonconformant (#F, m1_nr, m1_nc, m2_nr, m2_nc); \ | |
498 } \ | |
499 \ | |
500 return r; \ | |
501 } | |
502 | |
5030 | 503 #define MM_BOOL_OPS2(M1, M2, LHS_ZERO, RHS_ZERO) \ |
504 MM_BOOL_OP (mx_el_and, &&, M1, M2, LHS_ZERO, RHS_ZERO) \ | |
505 MM_BOOL_OP (mx_el_or, ||, M1, M2, LHS_ZERO, RHS_ZERO) | |
506 | |
3504 | 507 #define MM_BOOL_OPS(M1, M2, ZERO) \ |
5030 | 508 MM_BOOL_OPS2(M1, M2, ZERO, ZERO) |
2870 | 509 |
6708 | 510 #define MM_OP_DECLS(R, M1, M2, API) \ |
511 MM_BIN_OP_DECLS (R, M1, M2, API) \ | |
512 MM_CMP_OP_DECLS (M1, M2, API) \ | |
513 MM_BOOL_OP_DECLS (M1, M2, API) | |
2870 | 514 |
4543 | 515 // N-d matrix by scalar operations. |
516 | |
6708 | 517 #define NDS_BIN_OP_DECLS(R, ND, S, API) \ |
518 BIN_OP_DECL (R, operator +, ND, S, API); \ | |
519 BIN_OP_DECL (R, operator -, ND, S, API); \ | |
520 BIN_OP_DECL (R, operator *, ND, S, API); \ | |
521 BIN_OP_DECL (R, operator /, ND, S, API); | |
4543 | 522 |
523 #define NDS_BIN_OP(R, OP, ND, S, F) \ | |
524 R \ | |
525 OP (const ND& m, const S& s) \ | |
526 { \ | |
527 R r (m.dims ()); \ | |
528 \ | |
8380
dbe67764e628
fix & improve speed of diagonal matrix multiplication
Jaroslav Hajek <highegg@gmail.com>
parents:
8375
diff
changeset
|
529 octave_idx_type len = m.length (); \ |
4543 | 530 \ |
531 if (len > 0) \ | |
532 F ## _vs (r.fortran_vec (), m.data (), len, s); \ | |
533 \ | |
534 return r; \ | |
535 } | |
536 | |
537 #define NDS_BIN_OPS(R, ND, S) \ | |
538 NDS_BIN_OP (R, operator +, ND, S, mx_inline_add) \ | |
539 NDS_BIN_OP (R, operator -, ND, S, mx_inline_subtract) \ | |
540 NDS_BIN_OP (R, operator *, ND, S, mx_inline_multiply) \ | |
541 NDS_BIN_OP (R, operator /, ND, S, mx_inline_divide) | |
542 | |
6708 | 543 #define NDS_CMP_OP_DECLS(ND, S, API) \ |
544 NDCMP_OP_DECL (mx_el_lt, ND, S, API); \ | |
545 NDCMP_OP_DECL (mx_el_le, ND, S, API); \ | |
546 NDCMP_OP_DECL (mx_el_ge, ND, S, API); \ | |
547 NDCMP_OP_DECL (mx_el_gt, ND, S, API); \ | |
548 NDCMP_OP_DECL (mx_el_eq, ND, S, API); \ | |
549 NDCMP_OP_DECL (mx_el_ne, ND, S, API); | |
4543 | 550 |
4826 | 551 #define NDS_CMP_OP(F, OP, ND, NDC, S, SC) \ |
4543 | 552 boolNDArray \ |
553 F (const ND& m, const S& s) \ | |
554 { \ | |
555 boolNDArray r; \ | |
556 \ | |
8380
dbe67764e628
fix & improve speed of diagonal matrix multiplication
Jaroslav Hajek <highegg@gmail.com>
parents:
8375
diff
changeset
|
557 octave_idx_type len = m.length (); \ |
4543 | 558 \ |
4826 | 559 r.resize (m.dims ()); \ |
4543 | 560 \ |
8380
dbe67764e628
fix & improve speed of diagonal matrix multiplication
Jaroslav Hajek <highegg@gmail.com>
parents:
8375
diff
changeset
|
561 for (octave_idx_type i = 0; i < len; i++) \ |
4826 | 562 r.elem(i) = NDC (m.elem(i)) OP SC (s); \ |
4543 | 563 \ |
564 return r; \ | |
565 } | |
566 | |
567 #define NDS_CMP_OPS(ND, NDC, S, SC) \ | |
4826 | 568 NDS_CMP_OP (mx_el_lt, <, ND, NDC, S, SC) \ |
569 NDS_CMP_OP (mx_el_le, <=, ND, NDC, S, SC) \ | |
570 NDS_CMP_OP (mx_el_ge, >=, ND, NDC, S, SC) \ | |
571 NDS_CMP_OP (mx_el_gt, >, ND, NDC, S, SC) \ | |
572 NDS_CMP_OP (mx_el_eq, ==, ND, , S, ) \ | |
573 NDS_CMP_OP (mx_el_ne, !=, ND, , S, ) | |
4543 | 574 |
6119 | 575 #define NDS_CMP_OP1(F, OP, ND, NDC, S, SC, SPEC) \ |
576 boolNDArray \ | |
577 F (const ND& m, const S& s) \ | |
578 { \ | |
579 boolNDArray r; \ | |
580 \ | |
8380
dbe67764e628
fix & improve speed of diagonal matrix multiplication
Jaroslav Hajek <highegg@gmail.com>
parents:
8375
diff
changeset
|
581 octave_idx_type len = m.length (); \ |
6119 | 582 \ |
583 r.resize (m.dims ()); \ | |
584 \ | |
8380
dbe67764e628
fix & improve speed of diagonal matrix multiplication
Jaroslav Hajek <highegg@gmail.com>
parents:
8375
diff
changeset
|
585 for (octave_idx_type i = 0; i < len; i++) \ |
6119 | 586 r.elem(i) = operator OP <SPEC> (NDC (m.elem(i)), SC (s)); \ |
587 \ | |
588 return r; \ | |
589 } | |
590 | |
591 #define NDS_CMP_OPS1(ND, NDC, S, SC, SPEC) \ | |
592 NDS_CMP_OP1 (mx_el_lt, <, ND, NDC, S, SC, SPEC) \ | |
593 NDS_CMP_OP1 (mx_el_le, <=, ND, NDC, S, SC, SPEC) \ | |
594 NDS_CMP_OP1 (mx_el_ge, >=, ND, NDC, S, SC, SPEC) \ | |
595 NDS_CMP_OP1 (mx_el_gt, >, ND, NDC, S, SC, SPEC) \ | |
596 NDS_CMP_OP1 (mx_el_eq, ==, ND, , S, , SPEC) \ | |
597 NDS_CMP_OP1 (mx_el_ne, !=, ND, , S, , SPEC) | |
598 | |
599 #define NDS_CMP_OP2(F, OP, ND, NDC, S, SC, SPEC1, SPEC2) \ | |
600 boolNDArray \ | |
601 F (const ND& m, const S& s) \ | |
602 { \ | |
603 boolNDArray r; \ | |
604 \ | |
8380
dbe67764e628
fix & improve speed of diagonal matrix multiplication
Jaroslav Hajek <highegg@gmail.com>
parents:
8375
diff
changeset
|
605 octave_idx_type len = m.length (); \ |
6119 | 606 \ |
607 r.resize (m.dims ()); \ | |
608 \ | |
8380
dbe67764e628
fix & improve speed of diagonal matrix multiplication
Jaroslav Hajek <highegg@gmail.com>
parents:
8375
diff
changeset
|
609 for (octave_idx_type i = 0; i < len; i++) \ |
6119 | 610 r.elem(i) = operator OP <SPEC1,SPEC2> (NDC (m.elem(i)), SC (s)); \ |
611 \ | |
612 return r; \ | |
613 } | |
614 | |
615 #define NDS_CMP_OPS2(ND, NDC, S, SC, SPEC1, SPEC2) \ | |
616 NDS_CMP_OP2 (mx_el_lt, <, ND, NDC, S, SC, SPEC1, SPEC2) \ | |
617 NDS_CMP_OP2 (mx_el_le, <=, ND, NDC, S, SC, SPEC1, SPEC2) \ | |
618 NDS_CMP_OP2 (mx_el_ge, >=, ND, NDC, S, SC, SPEC1, SPEC2) \ | |
619 NDS_CMP_OP2 (mx_el_gt, >, ND, NDC, S, SC, SPEC1, SPEC2) \ | |
620 NDS_CMP_OP2 (mx_el_eq, ==, ND, , S, , SPEC1, SPEC2) \ | |
621 NDS_CMP_OP2 (mx_el_ne, !=, ND, , S, , SPEC1, SPEC2) | |
622 | |
6708 | 623 #define NDS_BOOL_OP_DECLS(ND, S, API) \ |
624 NDBOOL_OP_DECL (mx_el_and, ND, S, API); \ | |
625 NDBOOL_OP_DECL (mx_el_or, ND, S, API); | |
4543 | 626 |
5030 | 627 #define NDS_BOOL_OP(F, OP, ND, S, LHS_ZERO, RHS_ZERO) \ |
4543 | 628 boolNDArray \ |
629 F (const ND& m, const S& s) \ | |
630 { \ | |
631 boolNDArray r; \ | |
632 \ | |
8380
dbe67764e628
fix & improve speed of diagonal matrix multiplication
Jaroslav Hajek <highegg@gmail.com>
parents:
8375
diff
changeset
|
633 octave_idx_type len = m.length (); \ |
4543 | 634 \ |
635 if (len > 0) \ | |
636 { \ | |
637 r.resize (m.dims ()); \ | |
638 \ | |
7922
935be827eaf8
error for NaN values in & and | expressions
John W. Eaton <jwe@octave.org>
parents:
7789
diff
changeset
|
639 if (xisnan (s)) \ |
935be827eaf8
error for NaN values in & and | expressions
John W. Eaton <jwe@octave.org>
parents:
7789
diff
changeset
|
640 gripe_nan_to_logical_conversion (); \ |
935be827eaf8
error for NaN values in & and | expressions
John W. Eaton <jwe@octave.org>
parents:
7789
diff
changeset
|
641 else \ |
935be827eaf8
error for NaN values in & and | expressions
John W. Eaton <jwe@octave.org>
parents:
7789
diff
changeset
|
642 { \ |
8380
dbe67764e628
fix & improve speed of diagonal matrix multiplication
Jaroslav Hajek <highegg@gmail.com>
parents:
8375
diff
changeset
|
643 for (octave_idx_type i = 0; i < len; i++) \ |
7922
935be827eaf8
error for NaN values in & and | expressions
John W. Eaton <jwe@octave.org>
parents:
7789
diff
changeset
|
644 if (xisnan (m.elem(i))) \ |
935be827eaf8
error for NaN values in & and | expressions
John W. Eaton <jwe@octave.org>
parents:
7789
diff
changeset
|
645 { \ |
935be827eaf8
error for NaN values in & and | expressions
John W. Eaton <jwe@octave.org>
parents:
7789
diff
changeset
|
646 gripe_nan_to_logical_conversion (); \ |
935be827eaf8
error for NaN values in & and | expressions
John W. Eaton <jwe@octave.org>
parents:
7789
diff
changeset
|
647 return r; \ |
935be827eaf8
error for NaN values in & and | expressions
John W. Eaton <jwe@octave.org>
parents:
7789
diff
changeset
|
648 } \ |
935be827eaf8
error for NaN values in & and | expressions
John W. Eaton <jwe@octave.org>
parents:
7789
diff
changeset
|
649 else \ |
935be827eaf8
error for NaN values in & and | expressions
John W. Eaton <jwe@octave.org>
parents:
7789
diff
changeset
|
650 r.elem(i) = (m.elem(i) != LHS_ZERO) OP (s != RHS_ZERO); \ |
935be827eaf8
error for NaN values in & and | expressions
John W. Eaton <jwe@octave.org>
parents:
7789
diff
changeset
|
651 } \ |
4543 | 652 } \ |
653 \ | |
654 return r; \ | |
655 } | |
656 | |
5030 | 657 #define NDS_BOOL_OPS2(ND, S, LHS_ZERO, RHS_ZERO) \ |
658 NDS_BOOL_OP (mx_el_and, &&, ND, S, LHS_ZERO, RHS_ZERO) \ | |
659 NDS_BOOL_OP (mx_el_or, ||, ND, S, LHS_ZERO, RHS_ZERO) | |
660 | |
4543 | 661 #define NDS_BOOL_OPS(ND, S, ZERO) \ |
5030 | 662 NDS_BOOL_OPS2(ND, S, ZERO, ZERO) |
4543 | 663 |
6708 | 664 #define NDS_OP_DECLS(R, ND, S, API) \ |
665 NDS_BIN_OP_DECLS (R, ND, S, API) \ | |
666 NDS_CMP_OP_DECLS (ND, S, API) \ | |
667 NDS_BOOL_OP_DECLS (ND, S, API) | |
4543 | 668 |
669 // scalar by N-d matrix operations. | |
670 | |
6708 | 671 #define SND_BIN_OP_DECLS(R, S, ND, API) \ |
672 BIN_OP_DECL (R, operator +, S, ND, API); \ | |
673 BIN_OP_DECL (R, operator -, S, ND, API); \ | |
674 BIN_OP_DECL (R, operator *, S, ND, API); \ | |
675 BIN_OP_DECL (R, operator /, S, ND, API); | |
4543 | 676 |
677 #define SND_BIN_OP(R, OP, S, ND, F) \ | |
678 R \ | |
679 OP (const S& s, const ND& m) \ | |
680 { \ | |
681 R r (m.dims ()); \ | |
682 \ | |
8380
dbe67764e628
fix & improve speed of diagonal matrix multiplication
Jaroslav Hajek <highegg@gmail.com>
parents:
8375
diff
changeset
|
683 octave_idx_type len = m.length (); \ |
4543 | 684 \ |
685 if (len > 0) \ | |
686 F ## _sv (r.fortran_vec (), s, m.data (), len); \ | |
687 \ | |
688 return r; \ | |
689 } | |
690 | |
691 #define SND_BIN_OPS(R, S, ND) \ | |
692 SND_BIN_OP (R, operator +, S, ND, mx_inline_add) \ | |
693 SND_BIN_OP (R, operator -, S, ND, mx_inline_subtract) \ | |
694 SND_BIN_OP (R, operator *, S, ND, mx_inline_multiply) \ | |
695 SND_BIN_OP (R, operator /, S, ND, mx_inline_divide) | |
696 | |
6708 | 697 #define SND_CMP_OP_DECLS(S, ND, API) \ |
698 NDCMP_OP_DECL (mx_el_lt, S, ND, API); \ | |
699 NDCMP_OP_DECL (mx_el_le, S, ND, API); \ | |
700 NDCMP_OP_DECL (mx_el_ge, S, ND, API); \ | |
701 NDCMP_OP_DECL (mx_el_gt, S, ND, API); \ | |
702 NDCMP_OP_DECL (mx_el_eq, S, ND, API); \ | |
703 NDCMP_OP_DECL (mx_el_ne, S, ND, API); | |
4543 | 704 |
4826 | 705 #define SND_CMP_OP(F, OP, S, SC, ND, NDC) \ |
4543 | 706 boolNDArray \ |
707 F (const S& s, const ND& m) \ | |
708 { \ | |
709 boolNDArray r; \ | |
710 \ | |
8380
dbe67764e628
fix & improve speed of diagonal matrix multiplication
Jaroslav Hajek <highegg@gmail.com>
parents:
8375
diff
changeset
|
711 octave_idx_type len = m.length (); \ |
4543 | 712 \ |
4826 | 713 r.resize (m.dims ()); \ |
4543 | 714 \ |
8380
dbe67764e628
fix & improve speed of diagonal matrix multiplication
Jaroslav Hajek <highegg@gmail.com>
parents:
8375
diff
changeset
|
715 for (octave_idx_type i = 0; i < len; i++) \ |
4826 | 716 r.elem(i) = SC (s) OP NDC (m.elem(i)); \ |
4543 | 717 \ |
718 return r; \ | |
719 } | |
720 | |
721 #define SND_CMP_OPS(S, CS, ND, CND) \ | |
4826 | 722 SND_CMP_OP (mx_el_lt, <, S, CS, ND, CND) \ |
723 SND_CMP_OP (mx_el_le, <=, S, CS, ND, CND) \ | |
724 SND_CMP_OP (mx_el_ge, >=, S, CS, ND, CND) \ | |
725 SND_CMP_OP (mx_el_gt, >, S, CS, ND, CND) \ | |
726 SND_CMP_OP (mx_el_eq, ==, S, , ND, ) \ | |
727 SND_CMP_OP (mx_el_ne, !=, S, , ND, ) | |
4543 | 728 |
6119 | 729 #define SND_CMP_OP1(F, OP, S, SC, ND, NDC, SPEC) \ |
730 boolNDArray \ | |
731 F (const S& s, const ND& m) \ | |
732 { \ | |
733 boolNDArray r; \ | |
734 \ | |
8380
dbe67764e628
fix & improve speed of diagonal matrix multiplication
Jaroslav Hajek <highegg@gmail.com>
parents:
8375
diff
changeset
|
735 octave_idx_type len = m.length (); \ |
6119 | 736 \ |
737 r.resize (m.dims ()); \ | |
738 \ | |
8380
dbe67764e628
fix & improve speed of diagonal matrix multiplication
Jaroslav Hajek <highegg@gmail.com>
parents:
8375
diff
changeset
|
739 for (octave_idx_type i = 0; i < len; i++) \ |
6119 | 740 r.elem(i) = operator OP <SPEC> (SC (s), NDC (m.elem(i))); \ |
741 \ | |
742 return r; \ | |
743 } | |
744 | |
745 #define SND_CMP_OPS1(S, CS, ND, CND, SPEC) \ | |
746 SND_CMP_OP1 (mx_el_lt, <, S, CS, ND, CND, SPEC) \ | |
747 SND_CMP_OP1 (mx_el_le, <=, S, CS, ND, CND, SPEC) \ | |
748 SND_CMP_OP1 (mx_el_ge, >=, S, CS, ND, CND, SPEC) \ | |
749 SND_CMP_OP1 (mx_el_gt, >, S, CS, ND, CND, SPEC) \ | |
750 SND_CMP_OP1 (mx_el_eq, ==, S, , ND, , SPEC) \ | |
751 SND_CMP_OP1 (mx_el_ne, !=, S, , ND, , SPEC) | |
752 | |
753 #define SND_CMP_OP2(F, OP, S, SC, ND, NDC, SPEC1, SPEC2) \ | |
754 boolNDArray \ | |
755 F (const S& s, const ND& m) \ | |
756 { \ | |
757 boolNDArray r; \ | |
758 \ | |
8380
dbe67764e628
fix & improve speed of diagonal matrix multiplication
Jaroslav Hajek <highegg@gmail.com>
parents:
8375
diff
changeset
|
759 octave_idx_type len = m.length (); \ |
6119 | 760 \ |
761 r.resize (m.dims ()); \ | |
762 \ | |
8380
dbe67764e628
fix & improve speed of diagonal matrix multiplication
Jaroslav Hajek <highegg@gmail.com>
parents:
8375
diff
changeset
|
763 for (octave_idx_type i = 0; i < len; i++) \ |
6119 | 764 r.elem(i) = operator OP <SPEC1, SPEC2> (SC (s), NDC (m.elem(i))); \ |
765 \ | |
766 return r; \ | |
767 } | |
768 | |
769 #define SND_CMP_OPS2(S, CS, ND, CND, SPEC1, SPEC2) \ | |
770 SND_CMP_OP2 (mx_el_lt, <, S, CS, ND, CND, SPEC1, SPEC2) \ | |
771 SND_CMP_OP2 (mx_el_le, <=, S, CS, ND, CND, SPEC1, SPEC2) \ | |
772 SND_CMP_OP2 (mx_el_ge, >=, S, CS, ND, CND, SPEC1, SPEC2) \ | |
773 SND_CMP_OP2 (mx_el_gt, >, S, CS, ND, CND, SPEC1, SPEC2) \ | |
774 SND_CMP_OP2 (mx_el_eq, ==, S, , ND, , SPEC1, SPEC2) \ | |
775 SND_CMP_OP2 (mx_el_ne, !=, S, , ND, , SPEC1, SPEC2) | |
776 | |
6708 | 777 #define SND_BOOL_OP_DECLS(S, ND, API) \ |
778 NDBOOL_OP_DECL (mx_el_and, S, ND, API); \ | |
779 NDBOOL_OP_DECL (mx_el_or, S, ND, API); | |
4543 | 780 |
5030 | 781 #define SND_BOOL_OP(F, OP, S, ND, LHS_ZERO, RHS_ZERO) \ |
4543 | 782 boolNDArray \ |
783 F (const S& s, const ND& m) \ | |
784 { \ | |
785 boolNDArray r; \ | |
786 \ | |
8380
dbe67764e628
fix & improve speed of diagonal matrix multiplication
Jaroslav Hajek <highegg@gmail.com>
parents:
8375
diff
changeset
|
787 octave_idx_type len = m.length (); \ |
4543 | 788 \ |
789 if (len > 0) \ | |
790 { \ | |
791 r.resize (m.dims ()); \ | |
792 \ | |
7922
935be827eaf8
error for NaN values in & and | expressions
John W. Eaton <jwe@octave.org>
parents:
7789
diff
changeset
|
793 if (xisnan (s)) \ |
935be827eaf8
error for NaN values in & and | expressions
John W. Eaton <jwe@octave.org>
parents:
7789
diff
changeset
|
794 gripe_nan_to_logical_conversion (); \ |
935be827eaf8
error for NaN values in & and | expressions
John W. Eaton <jwe@octave.org>
parents:
7789
diff
changeset
|
795 else \ |
935be827eaf8
error for NaN values in & and | expressions
John W. Eaton <jwe@octave.org>
parents:
7789
diff
changeset
|
796 { \ |
8380
dbe67764e628
fix & improve speed of diagonal matrix multiplication
Jaroslav Hajek <highegg@gmail.com>
parents:
8375
diff
changeset
|
797 for (octave_idx_type i = 0; i < len; i++) \ |
7922
935be827eaf8
error for NaN values in & and | expressions
John W. Eaton <jwe@octave.org>
parents:
7789
diff
changeset
|
798 if (xisnan (m.elem(i))) \ |
935be827eaf8
error for NaN values in & and | expressions
John W. Eaton <jwe@octave.org>
parents:
7789
diff
changeset
|
799 { \ |
935be827eaf8
error for NaN values in & and | expressions
John W. Eaton <jwe@octave.org>
parents:
7789
diff
changeset
|
800 gripe_nan_to_logical_conversion (); \ |
935be827eaf8
error for NaN values in & and | expressions
John W. Eaton <jwe@octave.org>
parents:
7789
diff
changeset
|
801 return r; \ |
935be827eaf8
error for NaN values in & and | expressions
John W. Eaton <jwe@octave.org>
parents:
7789
diff
changeset
|
802 } \ |
935be827eaf8
error for NaN values in & and | expressions
John W. Eaton <jwe@octave.org>
parents:
7789
diff
changeset
|
803 else \ |
935be827eaf8
error for NaN values in & and | expressions
John W. Eaton <jwe@octave.org>
parents:
7789
diff
changeset
|
804 r.elem(i) = (s != LHS_ZERO) OP (m.elem(i) != RHS_ZERO); \ |
935be827eaf8
error for NaN values in & and | expressions
John W. Eaton <jwe@octave.org>
parents:
7789
diff
changeset
|
805 } \ |
4543 | 806 } \ |
807 \ | |
808 return r; \ | |
809 } | |
810 | |
5030 | 811 #define SND_BOOL_OPS2(S, ND, LHS_ZERO, RHS_ZERO) \ |
812 SND_BOOL_OP (mx_el_and, &&, S, ND, LHS_ZERO, RHS_ZERO) \ | |
813 SND_BOOL_OP (mx_el_or, ||, S, ND, LHS_ZERO, RHS_ZERO) | |
814 | |
4543 | 815 #define SND_BOOL_OPS(S, ND, ZERO) \ |
5030 | 816 SND_BOOL_OPS2(S, ND, ZERO, ZERO) |
4543 | 817 |
6708 | 818 #define SND_OP_DECLS(R, S, ND, API) \ |
819 SND_BIN_OP_DECLS (R, S, ND, API) \ | |
820 SND_CMP_OP_DECLS (S, ND, API) \ | |
821 SND_BOOL_OP_DECLS (S, ND, API) | |
4543 | 822 |
823 // N-d matrix by N-d matrix operations. | |
824 | |
6708 | 825 #define NDND_BIN_OP_DECLS(R, ND1, ND2, API) \ |
826 BIN_OP_DECL (R, operator +, ND1, ND2, API); \ | |
827 BIN_OP_DECL (R, operator -, ND1, ND2, API); \ | |
828 BIN_OP_DECL (R, product, ND1, ND2, API); \ | |
829 BIN_OP_DECL (R, quotient, ND1, ND2, API); | |
4543 | 830 |
831 #define NDND_BIN_OP(R, OP, ND1, ND2, F) \ | |
832 R \ | |
833 OP (const ND1& m1, const ND2& m2) \ | |
834 { \ | |
835 R r; \ | |
836 \ | |
837 dim_vector m1_dims = m1.dims (); \ | |
838 dim_vector m2_dims = m2.dims (); \ | |
839 \ | |
840 if (m1_dims != m2_dims) \ | |
841 gripe_nonconformant (#OP, m1_dims, m2_dims); \ | |
842 else \ | |
843 { \ | |
844 r.resize (m1_dims); \ | |
845 \ | |
8380
dbe67764e628
fix & improve speed of diagonal matrix multiplication
Jaroslav Hajek <highegg@gmail.com>
parents:
8375
diff
changeset
|
846 octave_idx_type len = m1.length (); \ |
4543 | 847 \ |
848 if (len > 0) \ | |
849 F ## _vv (r.fortran_vec (), m1.data (), m2.data (), len); \ | |
850 } \ | |
851 \ | |
852 return r; \ | |
853 } | |
854 | |
855 #define NDND_BIN_OPS(R, ND1, ND2) \ | |
856 NDND_BIN_OP (R, operator +, ND1, ND2, mx_inline_add) \ | |
857 NDND_BIN_OP (R, operator -, ND1, ND2, mx_inline_subtract) \ | |
858 NDND_BIN_OP (R, product, ND1, ND2, mx_inline_multiply) \ | |
859 NDND_BIN_OP (R, quotient, ND1, ND2, mx_inline_divide) | |
860 | |
6708 | 861 #define NDND_CMP_OP_DECLS(ND1, ND2, API) \ |
862 NDCMP_OP_DECL (mx_el_lt, ND1, ND2, API); \ | |
863 NDCMP_OP_DECL (mx_el_le, ND1, ND2, API); \ | |
864 NDCMP_OP_DECL (mx_el_ge, ND1, ND2, API); \ | |
865 NDCMP_OP_DECL (mx_el_gt, ND1, ND2, API); \ | |
866 NDCMP_OP_DECL (mx_el_eq, ND1, ND2, API); \ | |
867 NDCMP_OP_DECL (mx_el_ne, ND1, ND2, API); | |
4543 | 868 |
4826 | 869 #define NDND_CMP_OP(F, OP, ND1, C1, ND2, C2) \ |
4543 | 870 boolNDArray \ |
871 F (const ND1& m1, const ND2& m2) \ | |
872 { \ | |
873 boolNDArray r; \ | |
874 \ | |
875 dim_vector m1_dims = m1.dims (); \ | |
876 dim_vector m2_dims = m2.dims (); \ | |
877 \ | |
878 if (m1_dims == m2_dims) \ | |
879 { \ | |
4826 | 880 r.resize (m1_dims); \ |
4543 | 881 \ |
8380
dbe67764e628
fix & improve speed of diagonal matrix multiplication
Jaroslav Hajek <highegg@gmail.com>
parents:
8375
diff
changeset
|
882 for (octave_idx_type i = 0; i < m1.length (); i++) \ |
4826 | 883 r.elem(i) = C1 (m1.elem(i)) OP C2 (m2.elem(i)); \ |
4543 | 884 } \ |
885 else \ | |
4826 | 886 gripe_nonconformant (#F, m1_dims, m2_dims); \ |
4543 | 887 \ |
888 return r; \ | |
889 } | |
890 | |
891 #define NDND_CMP_OPS(ND1, C1, ND2, C2) \ | |
4826 | 892 NDND_CMP_OP (mx_el_lt, <, ND1, C1, ND2, C2) \ |
893 NDND_CMP_OP (mx_el_le, <=, ND1, C1, ND2, C2) \ | |
894 NDND_CMP_OP (mx_el_ge, >=, ND1, C1, ND2, C2) \ | |
895 NDND_CMP_OP (mx_el_gt, >, ND1, C1, ND2, C2) \ | |
896 NDND_CMP_OP (mx_el_eq, ==, ND1, , ND2, ) \ | |
897 NDND_CMP_OP (mx_el_ne, !=, ND1, , ND2, ) | |
4543 | 898 |
6708 | 899 #define NDND_BOOL_OP_DECLS(ND1, ND2, API) \ |
900 NDBOOL_OP_DECL (mx_el_and, ND1, ND2, API); \ | |
901 NDBOOL_OP_DECL (mx_el_or, ND1, ND2, API); | |
4543 | 902 |
5030 | 903 #define NDND_BOOL_OP(F, OP, ND1, ND2, LHS_ZERO, RHS_ZERO) \ |
4543 | 904 boolNDArray \ |
905 F (const ND1& m1, const ND2& m2) \ | |
906 { \ | |
907 boolNDArray r; \ | |
908 \ | |
909 dim_vector m1_dims = m1.dims (); \ | |
910 dim_vector m2_dims = m2.dims (); \ | |
911 \ | |
912 if (m1_dims == m2_dims) \ | |
913 { \ | |
914 if (! m1_dims.all_zero ()) \ | |
915 { \ | |
916 r.resize (m1_dims); \ | |
917 \ | |
8380
dbe67764e628
fix & improve speed of diagonal matrix multiplication
Jaroslav Hajek <highegg@gmail.com>
parents:
8375
diff
changeset
|
918 for (octave_idx_type i = 0; i < m1.length (); i++) \ |
7922
935be827eaf8
error for NaN values in & and | expressions
John W. Eaton <jwe@octave.org>
parents:
7789
diff
changeset
|
919 if (xisnan (m1.elem(i)) || xisnan (m2.elem(i))) \ |
935be827eaf8
error for NaN values in & and | expressions
John W. Eaton <jwe@octave.org>
parents:
7789
diff
changeset
|
920 { \ |
935be827eaf8
error for NaN values in & and | expressions
John W. Eaton <jwe@octave.org>
parents:
7789
diff
changeset
|
921 gripe_nan_to_logical_conversion (); \ |
935be827eaf8
error for NaN values in & and | expressions
John W. Eaton <jwe@octave.org>
parents:
7789
diff
changeset
|
922 return r; \ |
935be827eaf8
error for NaN values in & and | expressions
John W. Eaton <jwe@octave.org>
parents:
7789
diff
changeset
|
923 } \ |
935be827eaf8
error for NaN values in & and | expressions
John W. Eaton <jwe@octave.org>
parents:
7789
diff
changeset
|
924 else \ |
935be827eaf8
error for NaN values in & and | expressions
John W. Eaton <jwe@octave.org>
parents:
7789
diff
changeset
|
925 r.elem(i) = (m1.elem(i) != LHS_ZERO) OP (m2.elem(i) != RHS_ZERO); \ |
4543 | 926 } \ |
927 } \ | |
928 else \ | |
929 gripe_nonconformant (#F, m1_dims, m2_dims); \ | |
930 \ | |
931 return r; \ | |
932 } | |
933 | |
5030 | 934 #define NDND_BOOL_OPS2(ND1, ND2, LHS_ZERO, RHS_ZERO) \ |
935 NDND_BOOL_OP (mx_el_and, &&, ND1, ND2, LHS_ZERO, RHS_ZERO) \ | |
936 NDND_BOOL_OP (mx_el_or, ||, ND1, ND2, LHS_ZERO, RHS_ZERO) | |
937 | |
4543 | 938 #define NDND_BOOL_OPS(ND1, ND2, ZERO) \ |
5030 | 939 NDND_BOOL_OPS2(ND1, ND2, ZERO, ZERO) |
4543 | 940 |
6708 | 941 #define NDND_OP_DECLS(R, ND1, ND2, API) \ |
942 NDND_BIN_OP_DECLS (R, ND1, ND2, API) \ | |
943 NDND_CMP_OP_DECLS (ND1, ND2, API) \ | |
944 NDND_BOOL_OP_DECLS (ND1, ND2, API) | |
4543 | 945 |
2870 | 946 // scalar by diagonal matrix operations. |
947 | |
6708 | 948 #define SDM_BIN_OP_DECLS(R, S, DM, API) \ |
949 BIN_OP_DECL (R, operator +, S, DM, API); \ | |
950 BIN_OP_DECL (R, operator -, S, DM, API); | |
2870 | 951 |
952 #define SDM_BIN_OP(R, OP, S, DM, OPEQ) \ | |
2829 | 953 R \ |
954 OP (const S& s, const DM& dm) \ | |
955 { \ | |
8380
dbe67764e628
fix & improve speed of diagonal matrix multiplication
Jaroslav Hajek <highegg@gmail.com>
parents:
8375
diff
changeset
|
956 octave_idx_type nr = dm.rows (); \ |
dbe67764e628
fix & improve speed of diagonal matrix multiplication
Jaroslav Hajek <highegg@gmail.com>
parents:
8375
diff
changeset
|
957 octave_idx_type nc = dm.cols (); \ |
2829 | 958 \ |
959 R r (nr, nc, s); \ | |
960 \ | |
8380
dbe67764e628
fix & improve speed of diagonal matrix multiplication
Jaroslav Hajek <highegg@gmail.com>
parents:
8375
diff
changeset
|
961 for (octave_idx_type i = 0; i < dm.length (); i++) \ |
2870 | 962 r.elem(i, i) OPEQ dm.elem(i, i); \ |
2829 | 963 \ |
964 return r; \ | |
965 } | |
966 | |
2870 | 967 #define SDM_BIN_OPS(R, S, DM) \ |
968 SDM_BIN_OP (R, operator +, S, DM, +=) \ | |
969 SDM_BIN_OP (R, operator -, S, DM, -=) | |
970 | |
6708 | 971 #define SDM_OP_DECLS(R, S, DM, API) \ |
972 SDM_BIN_OP_DECLS(R, S, DM, API) | |
2829 | 973 |
2870 | 974 // diagonal matrix by scalar operations. |
975 | |
6708 | 976 #define DMS_BIN_OP_DECLS(R, DM, S, API) \ |
977 BIN_OP_DECL (R, operator +, DM, S, API); \ | |
978 BIN_OP_DECL (R, operator -, DM, S, API); | |
2870 | 979 |
980 #define DMS_BIN_OP(R, OP, DM, S, SGN) \ | |
2829 | 981 R \ |
982 OP (const DM& dm, const S& s) \ | |
983 { \ | |
8380
dbe67764e628
fix & improve speed of diagonal matrix multiplication
Jaroslav Hajek <highegg@gmail.com>
parents:
8375
diff
changeset
|
984 octave_idx_type nr = dm.rows (); \ |
dbe67764e628
fix & improve speed of diagonal matrix multiplication
Jaroslav Hajek <highegg@gmail.com>
parents:
8375
diff
changeset
|
985 octave_idx_type nc = dm.cols (); \ |
2829 | 986 \ |
987 R r (nr, nc, SGN s); \ | |
988 \ | |
8380
dbe67764e628
fix & improve speed of diagonal matrix multiplication
Jaroslav Hajek <highegg@gmail.com>
parents:
8375
diff
changeset
|
989 for (octave_idx_type i = 0; i < dm.length (); i++) \ |
2870 | 990 r.elem(i, i) += dm.elem(i, i); \ |
2829 | 991 \ |
992 return r; \ | |
993 } | |
994 | |
2870 | 995 #define DMS_BIN_OPS(R, DM, S) \ |
996 DMS_BIN_OP (R, operator +, DM, S, ) \ | |
997 DMS_BIN_OP (R, operator -, DM, S, -) | |
998 | |
6708 | 999 #define DMS_OP_DECLS(R, DM, S, API) \ |
1000 DMS_BIN_OP_DECLS(R, DM, S, API) | |
2829 | 1001 |
2870 | 1002 // matrix by diagonal matrix operations. |
1003 | |
6708 | 1004 #define MDM_BIN_OP_DECLS(R, M, DM, API) \ |
1005 BIN_OP_DECL (R, operator +, M, DM, API); \ | |
1006 BIN_OP_DECL (R, operator -, M, DM, API); \ | |
1007 BIN_OP_DECL (R, operator *, M, DM, API); | |
2870 | 1008 |
1009 #define MDM_BIN_OP(R, OP, M, DM, OPEQ) \ | |
2829 | 1010 R \ |
1011 OP (const M& m, const DM& dm) \ | |
1012 { \ | |
1013 R r; \ | |
1014 \ | |
8380
dbe67764e628
fix & improve speed of diagonal matrix multiplication
Jaroslav Hajek <highegg@gmail.com>
parents:
8375
diff
changeset
|
1015 octave_idx_type m_nr = m.rows (); \ |
dbe67764e628
fix & improve speed of diagonal matrix multiplication
Jaroslav Hajek <highegg@gmail.com>
parents:
8375
diff
changeset
|
1016 octave_idx_type m_nc = m.cols (); \ |
2829 | 1017 \ |
8380
dbe67764e628
fix & improve speed of diagonal matrix multiplication
Jaroslav Hajek <highegg@gmail.com>
parents:
8375
diff
changeset
|
1018 octave_idx_type dm_nr = dm.rows (); \ |
dbe67764e628
fix & improve speed of diagonal matrix multiplication
Jaroslav Hajek <highegg@gmail.com>
parents:
8375
diff
changeset
|
1019 octave_idx_type dm_nc = dm.cols (); \ |
2829 | 1020 \ |
1021 if (m_nr != dm_nr || m_nc != dm_nc) \ | |
1022 gripe_nonconformant (#OP, m_nr, m_nc, dm_nr, dm_nc); \ | |
1023 else \ | |
1024 { \ | |
1025 r.resize (m_nr, m_nc); \ | |
1026 \ | |
1027 if (m_nr > 0 && m_nc > 0) \ | |
1028 { \ | |
3585 | 1029 r = R (m); \ |
2829 | 1030 \ |
8380
dbe67764e628
fix & improve speed of diagonal matrix multiplication
Jaroslav Hajek <highegg@gmail.com>
parents:
8375
diff
changeset
|
1031 octave_idx_type len = dm.length (); \ |
2829 | 1032 \ |
8380
dbe67764e628
fix & improve speed of diagonal matrix multiplication
Jaroslav Hajek <highegg@gmail.com>
parents:
8375
diff
changeset
|
1033 for (octave_idx_type i = 0; i < len; i++) \ |
2870 | 1034 r.elem(i, i) OPEQ dm.elem(i, i); \ |
2829 | 1035 } \ |
1036 } \ | |
1037 \ | |
1038 return r; \ | |
1039 } | |
1040 | |
5030 | 1041 #define MDM_MULTIPLY_OP(R, M, DM, R_ZERO) \ |
2829 | 1042 R \ |
1043 operator * (const M& m, const DM& dm) \ | |
1044 { \ | |
1045 R r; \ | |
1046 \ | |
8380
dbe67764e628
fix & improve speed of diagonal matrix multiplication
Jaroslav Hajek <highegg@gmail.com>
parents:
8375
diff
changeset
|
1047 octave_idx_type m_nr = m.rows (); \ |
dbe67764e628
fix & improve speed of diagonal matrix multiplication
Jaroslav Hajek <highegg@gmail.com>
parents:
8375
diff
changeset
|
1048 octave_idx_type m_nc = m.cols (); \ |
2829 | 1049 \ |
8380
dbe67764e628
fix & improve speed of diagonal matrix multiplication
Jaroslav Hajek <highegg@gmail.com>
parents:
8375
diff
changeset
|
1050 octave_idx_type dm_nr = dm.rows (); \ |
dbe67764e628
fix & improve speed of diagonal matrix multiplication
Jaroslav Hajek <highegg@gmail.com>
parents:
8375
diff
changeset
|
1051 octave_idx_type dm_nc = dm.cols (); \ |
2829 | 1052 \ |
1053 if (m_nc != dm_nr) \ | |
1054 gripe_nonconformant ("operator *", m_nr, m_nc, dm_nr, dm_nc); \ | |
1055 else \ | |
1056 { \ | |
8366
8b1a2555c4e2
implement diagonal matrix objects
Jaroslav Hajek <highegg@gmail.com>
parents:
7922
diff
changeset
|
1057 r = R (m_nr, dm_nc); \ |
8380
dbe67764e628
fix & improve speed of diagonal matrix multiplication
Jaroslav Hajek <highegg@gmail.com>
parents:
8375
diff
changeset
|
1058 R::element_type *rd = r.fortran_vec (); \ |
dbe67764e628
fix & improve speed of diagonal matrix multiplication
Jaroslav Hajek <highegg@gmail.com>
parents:
8375
diff
changeset
|
1059 const M::element_type *md = m.data (); \ |
dbe67764e628
fix & improve speed of diagonal matrix multiplication
Jaroslav Hajek <highegg@gmail.com>
parents:
8375
diff
changeset
|
1060 const DM::element_type *dd = dm.data (); \ |
4543 | 1061 \ |
8380
dbe67764e628
fix & improve speed of diagonal matrix multiplication
Jaroslav Hajek <highegg@gmail.com>
parents:
8375
diff
changeset
|
1062 octave_idx_type len = dm.length (); \ |
dbe67764e628
fix & improve speed of diagonal matrix multiplication
Jaroslav Hajek <highegg@gmail.com>
parents:
8375
diff
changeset
|
1063 for (octave_idx_type i = 0; i < len; i++) \ |
dbe67764e628
fix & improve speed of diagonal matrix multiplication
Jaroslav Hajek <highegg@gmail.com>
parents:
8375
diff
changeset
|
1064 { \ |
dbe67764e628
fix & improve speed of diagonal matrix multiplication
Jaroslav Hajek <highegg@gmail.com>
parents:
8375
diff
changeset
|
1065 mx_inline_multiply_vs (rd, md, m_nr, dd[i]); \ |
dbe67764e628
fix & improve speed of diagonal matrix multiplication
Jaroslav Hajek <highegg@gmail.com>
parents:
8375
diff
changeset
|
1066 rd += m_nr; md += m_nr; \ |
dbe67764e628
fix & improve speed of diagonal matrix multiplication
Jaroslav Hajek <highegg@gmail.com>
parents:
8375
diff
changeset
|
1067 } \ |
dbe67764e628
fix & improve speed of diagonal matrix multiplication
Jaroslav Hajek <highegg@gmail.com>
parents:
8375
diff
changeset
|
1068 mx_inline_fill_vs (rd, m_nr * (dm_nc - len), R_ZERO); \ |
2829 | 1069 } \ |
1070 \ | |
1071 return r; \ | |
1072 } | |
1073 | |
5030 | 1074 #define MDM_BIN_OPS(R, M, DM, R_ZERO) \ |
2870 | 1075 MDM_BIN_OP (R, operator +, M, DM, +=) \ |
1076 MDM_BIN_OP (R, operator -, M, DM, -=) \ | |
5030 | 1077 MDM_MULTIPLY_OP (R, M, DM, R_ZERO) |
2829 | 1078 |
6708 | 1079 #define MDM_OP_DECLS(R, M, DM, API) \ |
1080 MDM_BIN_OP_DECLS(R, M, DM, API) | |
2870 | 1081 |
1082 // diagonal matrix by matrix operations. | |
1083 | |
6708 | 1084 #define DMM_BIN_OP_DECLS(R, DM, M, API) \ |
1085 BIN_OP_DECL (R, operator +, DM, M, API); \ | |
1086 BIN_OP_DECL (R, operator -, DM, M, API); \ | |
1087 BIN_OP_DECL (R, operator *, DM, M, API); | |
2870 | 1088 |
3585 | 1089 #define DMM_BIN_OP(R, OP, DM, M, OPEQ, PREOP) \ |
2829 | 1090 R \ |
1091 OP (const DM& dm, const M& m) \ | |
1092 { \ | |
1093 R r; \ | |
1094 \ | |
8380
dbe67764e628
fix & improve speed of diagonal matrix multiplication
Jaroslav Hajek <highegg@gmail.com>
parents:
8375
diff
changeset
|
1095 octave_idx_type dm_nr = dm.rows (); \ |
dbe67764e628
fix & improve speed of diagonal matrix multiplication
Jaroslav Hajek <highegg@gmail.com>
parents:
8375
diff
changeset
|
1096 octave_idx_type dm_nc = dm.cols (); \ |
2829 | 1097 \ |
8380
dbe67764e628
fix & improve speed of diagonal matrix multiplication
Jaroslav Hajek <highegg@gmail.com>
parents:
8375
diff
changeset
|
1098 octave_idx_type m_nr = m.rows (); \ |
dbe67764e628
fix & improve speed of diagonal matrix multiplication
Jaroslav Hajek <highegg@gmail.com>
parents:
8375
diff
changeset
|
1099 octave_idx_type m_nc = m.cols (); \ |
2829 | 1100 \ |
1101 if (dm_nr != m_nr || dm_nc != m_nc) \ | |
1102 gripe_nonconformant (#OP, dm_nr, dm_nc, m_nr, m_nc); \ | |
1103 else \ | |
1104 { \ | |
1105 if (m_nr > 0 && m_nc > 0) \ | |
1106 { \ | |
3585 | 1107 r = R (PREOP m); \ |
2829 | 1108 \ |
8380
dbe67764e628
fix & improve speed of diagonal matrix multiplication
Jaroslav Hajek <highegg@gmail.com>
parents:
8375
diff
changeset
|
1109 octave_idx_type len = dm.length (); \ |
2829 | 1110 \ |
8380
dbe67764e628
fix & improve speed of diagonal matrix multiplication
Jaroslav Hajek <highegg@gmail.com>
parents:
8375
diff
changeset
|
1111 for (octave_idx_type i = 0; i < len; i++) \ |
2870 | 1112 r.elem(i, i) OPEQ dm.elem(i, i); \ |
2829 | 1113 } \ |
1114 else \ | |
1115 r.resize (m_nr, m_nc); \ | |
1116 } \ | |
1117 \ | |
1118 return r; \ | |
1119 } | |
1120 | |
5030 | 1121 #define DMM_MULTIPLY_OP(R, DM, M, R_ZERO) \ |
2829 | 1122 R \ |
1123 operator * (const DM& dm, const M& m) \ | |
1124 { \ | |
1125 R r; \ | |
1126 \ | |
8380
dbe67764e628
fix & improve speed of diagonal matrix multiplication
Jaroslav Hajek <highegg@gmail.com>
parents:
8375
diff
changeset
|
1127 octave_idx_type dm_nr = dm.rows (); \ |
dbe67764e628
fix & improve speed of diagonal matrix multiplication
Jaroslav Hajek <highegg@gmail.com>
parents:
8375
diff
changeset
|
1128 octave_idx_type dm_nc = dm.cols (); \ |
2829 | 1129 \ |
8380
dbe67764e628
fix & improve speed of diagonal matrix multiplication
Jaroslav Hajek <highegg@gmail.com>
parents:
8375
diff
changeset
|
1130 octave_idx_type m_nr = m.rows (); \ |
dbe67764e628
fix & improve speed of diagonal matrix multiplication
Jaroslav Hajek <highegg@gmail.com>
parents:
8375
diff
changeset
|
1131 octave_idx_type m_nc = m.cols (); \ |
2829 | 1132 \ |
1133 if (dm_nc != m_nr) \ | |
1134 gripe_nonconformant ("operator *", dm_nr, dm_nc, m_nr, m_nc); \ | |
1135 else \ | |
1136 { \ | |
8366
8b1a2555c4e2
implement diagonal matrix objects
Jaroslav Hajek <highegg@gmail.com>
parents:
7922
diff
changeset
|
1137 r = R (dm_nr, m_nc); \ |
8380
dbe67764e628
fix & improve speed of diagonal matrix multiplication
Jaroslav Hajek <highegg@gmail.com>
parents:
8375
diff
changeset
|
1138 R::element_type *rd = r.fortran_vec (); \ |
dbe67764e628
fix & improve speed of diagonal matrix multiplication
Jaroslav Hajek <highegg@gmail.com>
parents:
8375
diff
changeset
|
1139 const M::element_type *md = m.data (); \ |
dbe67764e628
fix & improve speed of diagonal matrix multiplication
Jaroslav Hajek <highegg@gmail.com>
parents:
8375
diff
changeset
|
1140 const DM::element_type *dd = dm.data (); \ |
4543 | 1141 \ |
8380
dbe67764e628
fix & improve speed of diagonal matrix multiplication
Jaroslav Hajek <highegg@gmail.com>
parents:
8375
diff
changeset
|
1142 octave_idx_type len = dm.length (); \ |
dbe67764e628
fix & improve speed of diagonal matrix multiplication
Jaroslav Hajek <highegg@gmail.com>
parents:
8375
diff
changeset
|
1143 for (octave_idx_type i = 0; i < m_nc; i++) \ |
dbe67764e628
fix & improve speed of diagonal matrix multiplication
Jaroslav Hajek <highegg@gmail.com>
parents:
8375
diff
changeset
|
1144 { \ |
dbe67764e628
fix & improve speed of diagonal matrix multiplication
Jaroslav Hajek <highegg@gmail.com>
parents:
8375
diff
changeset
|
1145 mx_inline_multiply_vv (rd, md, dd, len); \ |
dbe67764e628
fix & improve speed of diagonal matrix multiplication
Jaroslav Hajek <highegg@gmail.com>
parents:
8375
diff
changeset
|
1146 rd += len; md += m_nr; \ |
dbe67764e628
fix & improve speed of diagonal matrix multiplication
Jaroslav Hajek <highegg@gmail.com>
parents:
8375
diff
changeset
|
1147 mx_inline_fill_vs (rd, dm_nr - len, R_ZERO); \ |
dbe67764e628
fix & improve speed of diagonal matrix multiplication
Jaroslav Hajek <highegg@gmail.com>
parents:
8375
diff
changeset
|
1148 rd += dm_nr - len; \ |
dbe67764e628
fix & improve speed of diagonal matrix multiplication
Jaroslav Hajek <highegg@gmail.com>
parents:
8375
diff
changeset
|
1149 } \ |
2829 | 1150 } \ |
1151 \ | |
1152 return r; \ | |
1153 } | |
1154 | |
5030 | 1155 #define DMM_BIN_OPS(R, DM, M, R_ZERO) \ |
3585 | 1156 DMM_BIN_OP (R, operator +, DM, M, +=, ) \ |
1157 DMM_BIN_OP (R, operator -, DM, M, +=, -) \ | |
5030 | 1158 DMM_MULTIPLY_OP (R, DM, M, R_ZERO) |
2829 | 1159 |
6708 | 1160 #define DMM_OP_DECLS(R, DM, M, API) \ |
1161 DMM_BIN_OP_DECLS(R, DM, M, API) | |
2870 | 1162 |
1163 // diagonal matrix by diagonal matrix operations. | |
2829 | 1164 |
6708 | 1165 #define DMDM_BIN_OP_DECLS(R, DM1, DM2, API) \ |
1166 BIN_OP_DECL (R, operator +, DM1, DM2, API); \ | |
1167 BIN_OP_DECL (R, operator -, DM1, DM2, API); \ | |
1168 BIN_OP_DECL (R, product, DM1, DM2, API); | |
2870 | 1169 |
1170 #define DMDM_BIN_OP(R, OP, DM1, DM2, F) \ | |
2829 | 1171 R \ |
1172 OP (const DM1& dm1, const DM2& dm2) \ | |
1173 { \ | |
1174 R r; \ | |
1175 \ | |
8380
dbe67764e628
fix & improve speed of diagonal matrix multiplication
Jaroslav Hajek <highegg@gmail.com>
parents:
8375
diff
changeset
|
1176 octave_idx_type dm1_nr = dm1.rows (); \ |
dbe67764e628
fix & improve speed of diagonal matrix multiplication
Jaroslav Hajek <highegg@gmail.com>
parents:
8375
diff
changeset
|
1177 octave_idx_type dm1_nc = dm1.cols (); \ |
2829 | 1178 \ |
8380
dbe67764e628
fix & improve speed of diagonal matrix multiplication
Jaroslav Hajek <highegg@gmail.com>
parents:
8375
diff
changeset
|
1179 octave_idx_type dm2_nr = dm2.rows (); \ |
dbe67764e628
fix & improve speed of diagonal matrix multiplication
Jaroslav Hajek <highegg@gmail.com>
parents:
8375
diff
changeset
|
1180 octave_idx_type dm2_nc = dm2.cols (); \ |
2829 | 1181 \ |
1182 if (dm1_nr != dm2_nr || dm1_nc != dm2_nc) \ | |
1183 gripe_nonconformant (#OP, dm1_nr, dm1_nc, dm2_nr, dm2_nc); \ | |
1184 else \ | |
1185 { \ | |
1186 r.resize (dm1_nr, dm1_nc); \ | |
1187 \ | |
1188 if (dm1_nr > 0 && dm1_nc > 0) \ | |
1189 F ## _vv (r.fortran_vec (), dm1.data (), dm2.data (), \ | |
8397 | 1190 dm1.length ()); \ |
2829 | 1191 } \ |
1192 \ | |
1193 return r; \ | |
1194 } | |
1195 | |
2870 | 1196 #define DMDM_BIN_OPS(R, DM1, DM2) \ |
3769 | 1197 DMDM_BIN_OP (R, operator +, DM1, DM2, mx_inline_add) \ |
1198 DMDM_BIN_OP (R, operator -, DM1, DM2, mx_inline_subtract) \ | |
1199 DMDM_BIN_OP (R, product, DM1, DM2, mx_inline_multiply) | |
2870 | 1200 |
6708 | 1201 #define DMDM_OP_DECLS(R, DM1, DM2, API) \ |
1202 DMDM_BIN_OP_DECLS (R, DM1, DM2, API) | |
2829 | 1203 |
3582 | 1204 #endif |
1205 | |
7189 | 1206 #define SND_MINMAX_FCN(FCN, OP, T) \ |
1207 T ## NDArray \ | |
1208 FCN (octave_ ## T d, const T ## NDArray& m) \ | |
1209 { \ | |
1210 dim_vector dv = m.dims (); \ | |
1211 octave_idx_type nel = dv.numel (); \ | |
1212 \ | |
1213 if (nel == 0) \ | |
1214 return T ## NDArray (dv); \ | |
1215 \ | |
1216 T ## NDArray result (dv); \ | |
1217 \ | |
1218 for (octave_idx_type i = 0; i < nel; i++) \ | |
1219 { \ | |
1220 OCTAVE_QUIT; \ | |
1221 result (i) = d OP m (i) ? d : m(i); \ | |
1222 } \ | |
1223 \ | |
1224 return result; \ | |
1225 } | |
1226 | |
1227 #define NDS_MINMAX_FCN(FCN, OP, T) \ | |
1228 T ## NDArray \ | |
1229 FCN (const T ## NDArray& m, octave_ ## T d) \ | |
1230 { \ | |
1231 dim_vector dv = m.dims (); \ | |
1232 octave_idx_type nel = dv.numel (); \ | |
1233 \ | |
1234 if (nel == 0) \ | |
1235 return T ## NDArray (dv); \ | |
1236 \ | |
1237 T ## NDArray result (dv); \ | |
1238 \ | |
1239 for (octave_idx_type i = 0; i < nel; i++) \ | |
1240 { \ | |
1241 OCTAVE_QUIT; \ | |
1242 result (i) = m (i) OP d ? m(i) : d; \ | |
1243 } \ | |
1244 \ | |
1245 return result; \ | |
1246 } | |
1247 | |
1248 #define NDND_MINMAX_FCN(FCN, OP, T) \ | |
1249 T ## NDArray \ | |
1250 FCN (const T ## NDArray& a, const T ## NDArray& b) \ | |
1251 { \ | |
1252 dim_vector dv = a.dims (); \ | |
1253 octave_idx_type nel = dv.numel (); \ | |
1254 \ | |
1255 if (dv != b.dims ()) \ | |
1256 { \ | |
1257 (*current_liboctave_error_handler) \ | |
1258 ("two-arg min expecting args of same size"); \ | |
1259 return T ## NDArray (); \ | |
1260 } \ | |
1261 \ | |
1262 if (nel == 0) \ | |
1263 return T ## NDArray (dv); \ | |
1264 \ | |
1265 T ## NDArray result (dv); \ | |
1266 \ | |
1267 for (octave_idx_type i = 0; i < nel; i++) \ | |
1268 { \ | |
1269 OCTAVE_QUIT; \ | |
1270 result (i) = a(i) OP b(i) ? a(i) : b(i); \ | |
1271 } \ | |
1272 \ | |
1273 return result; \ | |
1274 } | |
1275 | |
1276 #define MINMAX_FCNS(T) \ | |
1277 SND_MINMAX_FCN (min, <, T) \ | |
1278 NDS_MINMAX_FCN (min, <, T) \ | |
1279 NDND_MINMAX_FCN (min, <, T) \ | |
1280 SND_MINMAX_FCN (max, >, T) \ | |
1281 NDS_MINMAX_FCN (max, >, T) \ | |
1282 NDND_MINMAX_FCN (max, >, T) | |
1283 | |
1284 #define MINMAX_DECLS(T) \ | |
1285 extern OCTAVE_API T ## NDArray min (octave_ ## T d, const T ## NDArray& m); \ | |
1286 extern OCTAVE_API T ## NDArray min (const T ## NDArray& m, octave_ ## T d); \ | |
1287 extern OCTAVE_API T ## NDArray min (const T ## NDArray& a, \ | |
1288 const T ## NDArray& b); \ | |
1289 extern OCTAVE_API T ## NDArray max (octave_ ## T d, const T ## NDArray& m); \ | |
1290 extern OCTAVE_API T ## NDArray max (const T ## NDArray& m, octave_ ## T d); \ | |
1291 extern OCTAVE_API T ## NDArray max (const T ## NDArray& a, \ | |
1292 const T ## NDArray& b); | |
1293 | |
8367
445d27d79f4e
support permutation matrix objects
Jaroslav Hajek <highegg@gmail.com>
parents:
8366
diff
changeset
|
1294 #define PMM_MULTIPLY_OP(PM, M) \ |
445d27d79f4e
support permutation matrix objects
Jaroslav Hajek <highegg@gmail.com>
parents:
8366
diff
changeset
|
1295 M operator * (const PM& p, const M& x) \ |
445d27d79f4e
support permutation matrix objects
Jaroslav Hajek <highegg@gmail.com>
parents:
8366
diff
changeset
|
1296 { \ |
445d27d79f4e
support permutation matrix objects
Jaroslav Hajek <highegg@gmail.com>
parents:
8366
diff
changeset
|
1297 octave_idx_type nr = x.rows (), nc = x.columns (); \ |
445d27d79f4e
support permutation matrix objects
Jaroslav Hajek <highegg@gmail.com>
parents:
8366
diff
changeset
|
1298 M result; \ |
445d27d79f4e
support permutation matrix objects
Jaroslav Hajek <highegg@gmail.com>
parents:
8366
diff
changeset
|
1299 if (p.columns () != nr) \ |
445d27d79f4e
support permutation matrix objects
Jaroslav Hajek <highegg@gmail.com>
parents:
8366
diff
changeset
|
1300 gripe_nonconformant ("operator *", p.rows (), p.columns (), nr, nc); \ |
445d27d79f4e
support permutation matrix objects
Jaroslav Hajek <highegg@gmail.com>
parents:
8366
diff
changeset
|
1301 else \ |
445d27d79f4e
support permutation matrix objects
Jaroslav Hajek <highegg@gmail.com>
parents:
8366
diff
changeset
|
1302 { \ |
445d27d79f4e
support permutation matrix objects
Jaroslav Hajek <highegg@gmail.com>
parents:
8366
diff
changeset
|
1303 if (p.is_col_perm ()) \ |
445d27d79f4e
support permutation matrix objects
Jaroslav Hajek <highegg@gmail.com>
parents:
8366
diff
changeset
|
1304 { \ |
445d27d79f4e
support permutation matrix objects
Jaroslav Hajek <highegg@gmail.com>
parents:
8366
diff
changeset
|
1305 result = M (nr, nc); \ |
8375
e3c9102431a9
fix design problems of diag & perm matrix classes
Jaroslav Hajek <highegg@gmail.com>
parents:
8367
diff
changeset
|
1306 result.assign (p.pvec (), idx_vector::colon, x); \ |
8367
445d27d79f4e
support permutation matrix objects
Jaroslav Hajek <highegg@gmail.com>
parents:
8366
diff
changeset
|
1307 } \ |
445d27d79f4e
support permutation matrix objects
Jaroslav Hajek <highegg@gmail.com>
parents:
8366
diff
changeset
|
1308 else \ |
8375
e3c9102431a9
fix design problems of diag & perm matrix classes
Jaroslav Hajek <highegg@gmail.com>
parents:
8367
diff
changeset
|
1309 result = x.index (p.pvec (), idx_vector::colon); \ |
8367
445d27d79f4e
support permutation matrix objects
Jaroslav Hajek <highegg@gmail.com>
parents:
8366
diff
changeset
|
1310 } \ |
445d27d79f4e
support permutation matrix objects
Jaroslav Hajek <highegg@gmail.com>
parents:
8366
diff
changeset
|
1311 \ |
445d27d79f4e
support permutation matrix objects
Jaroslav Hajek <highegg@gmail.com>
parents:
8366
diff
changeset
|
1312 return result; \ |
445d27d79f4e
support permutation matrix objects
Jaroslav Hajek <highegg@gmail.com>
parents:
8366
diff
changeset
|
1313 } |
445d27d79f4e
support permutation matrix objects
Jaroslav Hajek <highegg@gmail.com>
parents:
8366
diff
changeset
|
1314 |
445d27d79f4e
support permutation matrix objects
Jaroslav Hajek <highegg@gmail.com>
parents:
8366
diff
changeset
|
1315 #define MPM_MULTIPLY_OP(M, PM) \ |
445d27d79f4e
support permutation matrix objects
Jaroslav Hajek <highegg@gmail.com>
parents:
8366
diff
changeset
|
1316 M operator * (const M& x, const PM& p) \ |
445d27d79f4e
support permutation matrix objects
Jaroslav Hajek <highegg@gmail.com>
parents:
8366
diff
changeset
|
1317 { \ |
445d27d79f4e
support permutation matrix objects
Jaroslav Hajek <highegg@gmail.com>
parents:
8366
diff
changeset
|
1318 octave_idx_type nr = x.rows (), nc = x.columns (); \ |
445d27d79f4e
support permutation matrix objects
Jaroslav Hajek <highegg@gmail.com>
parents:
8366
diff
changeset
|
1319 M result; \ |
445d27d79f4e
support permutation matrix objects
Jaroslav Hajek <highegg@gmail.com>
parents:
8366
diff
changeset
|
1320 if (p.rows () != nc) \ |
445d27d79f4e
support permutation matrix objects
Jaroslav Hajek <highegg@gmail.com>
parents:
8366
diff
changeset
|
1321 gripe_nonconformant ("operator *", nr, nc, p.rows (), p.columns ()); \ |
445d27d79f4e
support permutation matrix objects
Jaroslav Hajek <highegg@gmail.com>
parents:
8366
diff
changeset
|
1322 else \ |
445d27d79f4e
support permutation matrix objects
Jaroslav Hajek <highegg@gmail.com>
parents:
8366
diff
changeset
|
1323 { \ |
445d27d79f4e
support permutation matrix objects
Jaroslav Hajek <highegg@gmail.com>
parents:
8366
diff
changeset
|
1324 if (p.is_col_perm ()) \ |
8375
e3c9102431a9
fix design problems of diag & perm matrix classes
Jaroslav Hajek <highegg@gmail.com>
parents:
8367
diff
changeset
|
1325 result = x.index (idx_vector::colon, p.pvec ()); \ |
8367
445d27d79f4e
support permutation matrix objects
Jaroslav Hajek <highegg@gmail.com>
parents:
8366
diff
changeset
|
1326 else \ |
445d27d79f4e
support permutation matrix objects
Jaroslav Hajek <highegg@gmail.com>
parents:
8366
diff
changeset
|
1327 { \ |
445d27d79f4e
support permutation matrix objects
Jaroslav Hajek <highegg@gmail.com>
parents:
8366
diff
changeset
|
1328 result = M (nr, nc); \ |
8375
e3c9102431a9
fix design problems of diag & perm matrix classes
Jaroslav Hajek <highegg@gmail.com>
parents:
8367
diff
changeset
|
1329 result.assign (idx_vector::colon, p.pvec (), x); \ |
8367
445d27d79f4e
support permutation matrix objects
Jaroslav Hajek <highegg@gmail.com>
parents:
8366
diff
changeset
|
1330 } \ |
445d27d79f4e
support permutation matrix objects
Jaroslav Hajek <highegg@gmail.com>
parents:
8366
diff
changeset
|
1331 } \ |
445d27d79f4e
support permutation matrix objects
Jaroslav Hajek <highegg@gmail.com>
parents:
8366
diff
changeset
|
1332 \ |
445d27d79f4e
support permutation matrix objects
Jaroslav Hajek <highegg@gmail.com>
parents:
8366
diff
changeset
|
1333 return result; \ |
445d27d79f4e
support permutation matrix objects
Jaroslav Hajek <highegg@gmail.com>
parents:
8366
diff
changeset
|
1334 } |
445d27d79f4e
support permutation matrix objects
Jaroslav Hajek <highegg@gmail.com>
parents:
8366
diff
changeset
|
1335 |
445d27d79f4e
support permutation matrix objects
Jaroslav Hajek <highegg@gmail.com>
parents:
8366
diff
changeset
|
1336 #define PMM_BIN_OP_DECLS(R, PM, M, API) \ |
445d27d79f4e
support permutation matrix objects
Jaroslav Hajek <highegg@gmail.com>
parents:
8366
diff
changeset
|
1337 BIN_OP_DECL (R, operator *, PM, M, API); |
445d27d79f4e
support permutation matrix objects
Jaroslav Hajek <highegg@gmail.com>
parents:
8366
diff
changeset
|
1338 |
445d27d79f4e
support permutation matrix objects
Jaroslav Hajek <highegg@gmail.com>
parents:
8366
diff
changeset
|
1339 #define PMM_BIN_OPS(R, PM, M) \ |
445d27d79f4e
support permutation matrix objects
Jaroslav Hajek <highegg@gmail.com>
parents:
8366
diff
changeset
|
1340 PMM_MULTIPLY_OP(PM, M); |
445d27d79f4e
support permutation matrix objects
Jaroslav Hajek <highegg@gmail.com>
parents:
8366
diff
changeset
|
1341 |
445d27d79f4e
support permutation matrix objects
Jaroslav Hajek <highegg@gmail.com>
parents:
8366
diff
changeset
|
1342 #define MPM_BIN_OP_DECLS(R, M, PM, API) \ |
445d27d79f4e
support permutation matrix objects
Jaroslav Hajek <highegg@gmail.com>
parents:
8366
diff
changeset
|
1343 BIN_OP_DECL (R, operator *, M, PM, API); |
445d27d79f4e
support permutation matrix objects
Jaroslav Hajek <highegg@gmail.com>
parents:
8366
diff
changeset
|
1344 |
445d27d79f4e
support permutation matrix objects
Jaroslav Hajek <highegg@gmail.com>
parents:
8366
diff
changeset
|
1345 #define MPM_BIN_OPS(R, M, PM) \ |
445d27d79f4e
support permutation matrix objects
Jaroslav Hajek <highegg@gmail.com>
parents:
8366
diff
changeset
|
1346 MPM_MULTIPLY_OP(M, PM); |
445d27d79f4e
support permutation matrix objects
Jaroslav Hajek <highegg@gmail.com>
parents:
8366
diff
changeset
|
1347 |
7189 | 1348 |
2829 | 1349 /* |
1350 ;;; Local Variables: *** | |
1351 ;;; mode: C++ *** | |
1352 ;;; End: *** | |
1353 */ |