Mercurial > hg > octave-nkf
annotate liboctave/mx-op-defs.h @ 9550:3d6a9aea2aea
refactor binary & bool ops in liboctave
author | Jaroslav Hajek <highegg@gmail.com> |
---|---|
date | Wed, 19 Aug 2009 22:55:15 +0200 |
parents | a48fba01e4ac |
children | 0c72d9284087 |
rev | line source |
---|---|
2829 | 1 /* |
2 | |
8920 | 3 Copyright (C) 2008, 2009 Jaroslav Hajek |
7017 | 4 Copyright (C) 1996, 1997, 1998, 2000, 2001, 2003, 2004, 2005, 2006, |
5 2007 John W. Eaton | |
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 | |
8774
b756ce0002db
split implementation and interface in mx-op-defs and MArray-defs
Jaroslav Hajek <highegg@gmail.com>
parents:
8397
diff
changeset
|
28 #include "mx-op-decl.h" |
2829 | 29 #include "mx-inlines.cc" |
30 | |
9550
3d6a9aea2aea
refactor binary & bool ops in liboctave
Jaroslav Hajek <highegg@gmail.com>
parents:
8998
diff
changeset
|
31 #define ND_LOGICAL_NAN_CHECK(X) \ |
3d6a9aea2aea
refactor binary & bool ops in liboctave
Jaroslav Hajek <highegg@gmail.com>
parents:
8998
diff
changeset
|
32 if (mx_inline_any_nan ((X).numel (), (X).data ())) \ |
3d6a9aea2aea
refactor binary & bool ops in liboctave
Jaroslav Hajek <highegg@gmail.com>
parents:
8998
diff
changeset
|
33 gripe_nan_to_logical_conversion () |
3d6a9aea2aea
refactor binary & bool ops in liboctave
Jaroslav Hajek <highegg@gmail.com>
parents:
8998
diff
changeset
|
34 |
3d6a9aea2aea
refactor binary & bool ops in liboctave
Jaroslav Hajek <highegg@gmail.com>
parents:
8998
diff
changeset
|
35 #define SC_LOGICAL_NAN_CHECK(X) \ |
3d6a9aea2aea
refactor binary & bool ops in liboctave
Jaroslav Hajek <highegg@gmail.com>
parents:
8998
diff
changeset
|
36 if (xisnan(X)) \ |
3d6a9aea2aea
refactor binary & bool ops in liboctave
Jaroslav Hajek <highegg@gmail.com>
parents:
8998
diff
changeset
|
37 gripe_nan_to_logical_conversion () |
3d6a9aea2aea
refactor binary & bool ops in liboctave
Jaroslav Hajek <highegg@gmail.com>
parents:
8998
diff
changeset
|
38 |
2870 | 39 // vector by scalar operations. |
40 | |
41 #define VS_BIN_OP(R, F, OP, V, S) \ | |
42 R \ | |
43 F (const V& v, const S& s) \ | |
44 { \ | |
8380
dbe67764e628
fix & improve speed of diagonal matrix multiplication
Jaroslav Hajek <highegg@gmail.com>
parents:
8375
diff
changeset
|
45 octave_idx_type len = v.length (); \ |
2870 | 46 \ |
47 R r (len); \ | |
48 \ | |
8380
dbe67764e628
fix & improve speed of diagonal matrix multiplication
Jaroslav Hajek <highegg@gmail.com>
parents:
8375
diff
changeset
|
49 for (octave_idx_type i = 0; i < len; i++) \ |
2870 | 50 r.elem(i) = v.elem(i) OP s; \ |
51 \ | |
52 return r; \ | |
53 } | |
54 | |
55 #define VS_BIN_OPS(R, V, S) \ | |
56 VS_BIN_OP (R, operator +, +, V, S) \ | |
57 VS_BIN_OP (R, operator -, -, V, S) \ | |
58 VS_BIN_OP (R, operator *, *, V, S) \ | |
59 VS_BIN_OP (R, operator /, /, V, S) | |
60 | |
61 // scalar by vector by operations. | |
62 | |
63 #define SV_BIN_OP(R, F, OP, S, V) \ | |
64 R \ | |
65 F (const S& s, const V& v) \ | |
66 { \ | |
8380
dbe67764e628
fix & improve speed of diagonal matrix multiplication
Jaroslav Hajek <highegg@gmail.com>
parents:
8375
diff
changeset
|
67 octave_idx_type len = v.length (); \ |
2870 | 68 \ |
69 R r (len); \ | |
70 \ | |
8380
dbe67764e628
fix & improve speed of diagonal matrix multiplication
Jaroslav Hajek <highegg@gmail.com>
parents:
8375
diff
changeset
|
71 for (octave_idx_type i = 0; i < len; i++) \ |
2870 | 72 r.elem(i) = s OP v.elem(i); \ |
73 \ | |
74 return r; \ | |
75 } | |
76 | |
77 #define SV_BIN_OPS(R, S, V) \ | |
78 SV_BIN_OP (R, operator +, +, S, V) \ | |
79 SV_BIN_OP (R, operator -, -, S, V) \ | |
80 SV_BIN_OP (R, operator *, *, S, V) \ | |
81 SV_BIN_OP (R, operator /, /, S, V) | |
82 | |
83 // vector by vector operations. | |
84 | |
85 #define VV_BIN_OP(R, F, OP, V1, V2) \ | |
86 R \ | |
87 F (const V1& v1, const V2& v2) \ | |
88 { \ | |
89 R r; \ | |
90 \ | |
8380
dbe67764e628
fix & improve speed of diagonal matrix multiplication
Jaroslav Hajek <highegg@gmail.com>
parents:
8375
diff
changeset
|
91 octave_idx_type v1_len = v1.length (); \ |
dbe67764e628
fix & improve speed of diagonal matrix multiplication
Jaroslav Hajek <highegg@gmail.com>
parents:
8375
diff
changeset
|
92 octave_idx_type v2_len = v2.length (); \ |
2870 | 93 \ |
94 if (v1_len != v2_len) \ | |
95 gripe_nonconformant (#OP, v1_len, v2_len); \ | |
96 else \ | |
97 { \ | |
98 r.resize (v1_len); \ | |
99 \ | |
8380
dbe67764e628
fix & improve speed of diagonal matrix multiplication
Jaroslav Hajek <highegg@gmail.com>
parents:
8375
diff
changeset
|
100 for (octave_idx_type i = 0; i < v1_len; i++) \ |
2870 | 101 r.elem(i) = v1.elem(i) OP v2.elem(i); \ |
102 } \ | |
103 \ | |
104 return r; \ | |
105 } | |
106 | |
107 #define VV_BIN_OPS(R, V1, V2) \ | |
108 VV_BIN_OP (R, operator +, +, V1, V2) \ | |
109 VV_BIN_OP (R, operator -, -, V1, V2) \ | |
110 VV_BIN_OP (R, product, *, V1, V2) \ | |
111 VV_BIN_OP (R, quotient, /, V1, V2) | |
112 | |
113 // matrix by scalar operations. | |
114 | |
115 #define MS_BIN_OP(R, OP, M, S, F) \ | |
2829 | 116 R \ |
117 OP (const M& m, const S& s) \ | |
118 { \ | |
9550
3d6a9aea2aea
refactor binary & bool ops in liboctave
Jaroslav Hajek <highegg@gmail.com>
parents:
8998
diff
changeset
|
119 return do_ms_binary_op<R, M, S> (m, s, F); \ |
2829 | 120 } |
121 | |
2870 | 122 #define MS_BIN_OPS(R, M, S) \ |
3769 | 123 MS_BIN_OP (R, operator +, M, S, mx_inline_add) \ |
9550
3d6a9aea2aea
refactor binary & bool ops in liboctave
Jaroslav Hajek <highegg@gmail.com>
parents:
8998
diff
changeset
|
124 MS_BIN_OP (R, operator -, M, S, mx_inline_sub) \ |
3d6a9aea2aea
refactor binary & bool ops in liboctave
Jaroslav Hajek <highegg@gmail.com>
parents:
8998
diff
changeset
|
125 MS_BIN_OP (R, operator *, M, S, mx_inline_mul) \ |
3d6a9aea2aea
refactor binary & bool ops in liboctave
Jaroslav Hajek <highegg@gmail.com>
parents:
8998
diff
changeset
|
126 MS_BIN_OP (R, operator /, M, S, mx_inline_div) |
2870 | 127 |
4826 | 128 #define MS_CMP_OP(F, OP, M, MC, S, SC) \ |
2870 | 129 boolMatrix \ |
130 F (const M& m, const S& s) \ | |
131 { \ | |
132 boolMatrix r; \ | |
133 \ | |
8380
dbe67764e628
fix & improve speed of diagonal matrix multiplication
Jaroslav Hajek <highegg@gmail.com>
parents:
8375
diff
changeset
|
134 octave_idx_type nr = m.rows (); \ |
dbe67764e628
fix & improve speed of diagonal matrix multiplication
Jaroslav Hajek <highegg@gmail.com>
parents:
8375
diff
changeset
|
135 octave_idx_type nc = m.cols (); \ |
2870 | 136 \ |
4826 | 137 r.resize (nr, nc); \ |
138 \ | |
139 if (nr > 0 && nc > 0) \ | |
2870 | 140 { \ |
8380
dbe67764e628
fix & improve speed of diagonal matrix multiplication
Jaroslav Hajek <highegg@gmail.com>
parents:
8375
diff
changeset
|
141 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
|
142 for (octave_idx_type i = 0; i < nr; i++) \ |
2870 | 143 r.elem(i, j) = MC (m.elem(i, j)) OP SC (s); \ |
144 } \ | |
145 \ | |
146 return r; \ | |
147 } | |
2829 | 148 |
2870 | 149 #define MS_CMP_OPS(M, CM, S, CS) \ |
4826 | 150 MS_CMP_OP (mx_el_lt, <, M, CM, S, CS) \ |
151 MS_CMP_OP (mx_el_le, <=, M, CM, S, CS) \ | |
152 MS_CMP_OP (mx_el_ge, >=, M, CM, S, CS) \ | |
153 MS_CMP_OP (mx_el_gt, >, M, CM, S, CS) \ | |
154 MS_CMP_OP (mx_el_eq, ==, M, , S, ) \ | |
155 MS_CMP_OP (mx_el_ne, !=, M, , S, ) | |
2870 | 156 |
9550
3d6a9aea2aea
refactor binary & bool ops in liboctave
Jaroslav Hajek <highegg@gmail.com>
parents:
8998
diff
changeset
|
157 #define MS_BOOL_OP(F, OP, M, S) \ |
2870 | 158 boolMatrix \ |
159 F (const M& m, const S& s) \ | |
160 { \ | |
9550
3d6a9aea2aea
refactor binary & bool ops in liboctave
Jaroslav Hajek <highegg@gmail.com>
parents:
8998
diff
changeset
|
161 ND_LOGICAL_NAN_CHECK (m); \ |
3d6a9aea2aea
refactor binary & bool ops in liboctave
Jaroslav Hajek <highegg@gmail.com>
parents:
8998
diff
changeset
|
162 SC_LOGICAL_NAN_CHECK (s); \ |
3d6a9aea2aea
refactor binary & bool ops in liboctave
Jaroslav Hajek <highegg@gmail.com>
parents:
8998
diff
changeset
|
163 return do_ms_binary_op<boolMatrix, M, S> (m, s, OP); \ |
2870 | 164 } |
165 | |
9550
3d6a9aea2aea
refactor binary & bool ops in liboctave
Jaroslav Hajek <highegg@gmail.com>
parents:
8998
diff
changeset
|
166 #define MS_BOOL_OPS(M, S) \ |
3d6a9aea2aea
refactor binary & bool ops in liboctave
Jaroslav Hajek <highegg@gmail.com>
parents:
8998
diff
changeset
|
167 MS_BOOL_OP (mx_el_and, mx_inline_and, M, S) \ |
3d6a9aea2aea
refactor binary & bool ops in liboctave
Jaroslav Hajek <highegg@gmail.com>
parents:
8998
diff
changeset
|
168 MS_BOOL_OP (mx_el_or, mx_inline_or, M, S) |
2870 | 169 |
170 // scalar by matrix operations. | |
171 | |
172 #define SM_BIN_OP(R, OP, S, M, F) \ | |
2829 | 173 R \ |
174 OP (const S& s, const M& m) \ | |
175 { \ | |
9550
3d6a9aea2aea
refactor binary & bool ops in liboctave
Jaroslav Hajek <highegg@gmail.com>
parents:
8998
diff
changeset
|
176 return do_sm_binary_op<R, S, M> (s, m, F); \ |
2829 | 177 } |
178 | |
2870 | 179 #define SM_BIN_OPS(R, S, M) \ |
3769 | 180 SM_BIN_OP (R, operator +, S, M, mx_inline_add) \ |
9550
3d6a9aea2aea
refactor binary & bool ops in liboctave
Jaroslav Hajek <highegg@gmail.com>
parents:
8998
diff
changeset
|
181 SM_BIN_OP (R, operator -, S, M, mx_inline_sub) \ |
3d6a9aea2aea
refactor binary & bool ops in liboctave
Jaroslav Hajek <highegg@gmail.com>
parents:
8998
diff
changeset
|
182 SM_BIN_OP (R, operator *, S, M, mx_inline_mul) \ |
3d6a9aea2aea
refactor binary & bool ops in liboctave
Jaroslav Hajek <highegg@gmail.com>
parents:
8998
diff
changeset
|
183 SM_BIN_OP (R, operator /, S, M, mx_inline_div) |
2870 | 184 |
4826 | 185 #define SM_CMP_OP(F, OP, S, SC, M, MC) \ |
2870 | 186 boolMatrix \ |
187 F (const S& s, const M& m) \ | |
188 { \ | |
189 boolMatrix r; \ | |
190 \ | |
8380
dbe67764e628
fix & improve speed of diagonal matrix multiplication
Jaroslav Hajek <highegg@gmail.com>
parents:
8375
diff
changeset
|
191 octave_idx_type nr = m.rows (); \ |
dbe67764e628
fix & improve speed of diagonal matrix multiplication
Jaroslav Hajek <highegg@gmail.com>
parents:
8375
diff
changeset
|
192 octave_idx_type nc = m.cols (); \ |
2870 | 193 \ |
4826 | 194 r.resize (nr, nc); \ |
195 \ | |
196 if (nr > 0 && nc > 0) \ | |
2870 | 197 { \ |
8380
dbe67764e628
fix & improve speed of diagonal matrix multiplication
Jaroslav Hajek <highegg@gmail.com>
parents:
8375
diff
changeset
|
198 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
|
199 for (octave_idx_type i = 0; i < nr; i++) \ |
2870 | 200 r.elem(i, j) = SC (s) OP MC (m.elem(i, j)); \ |
201 } \ | |
202 \ | |
203 return r; \ | |
204 } | |
2829 | 205 |
2870 | 206 #define SM_CMP_OPS(S, CS, M, CM) \ |
4826 | 207 SM_CMP_OP (mx_el_lt, <, S, CS, M, CM) \ |
208 SM_CMP_OP (mx_el_le, <=, S, CS, M, CM) \ | |
209 SM_CMP_OP (mx_el_ge, >=, S, CS, M, CM) \ | |
210 SM_CMP_OP (mx_el_gt, >, S, CS, M, CM) \ | |
211 SM_CMP_OP (mx_el_eq, ==, S, , M, ) \ | |
212 SM_CMP_OP (mx_el_ne, !=, S, , M, ) | |
2870 | 213 |
9550
3d6a9aea2aea
refactor binary & bool ops in liboctave
Jaroslav Hajek <highegg@gmail.com>
parents:
8998
diff
changeset
|
214 #define SM_BOOL_OP(F, OP, S, M) \ |
2870 | 215 boolMatrix \ |
216 F (const S& s, const M& m) \ | |
217 { \ | |
9550
3d6a9aea2aea
refactor binary & bool ops in liboctave
Jaroslav Hajek <highegg@gmail.com>
parents:
8998
diff
changeset
|
218 SC_LOGICAL_NAN_CHECK (s); \ |
3d6a9aea2aea
refactor binary & bool ops in liboctave
Jaroslav Hajek <highegg@gmail.com>
parents:
8998
diff
changeset
|
219 ND_LOGICAL_NAN_CHECK (m); \ |
3d6a9aea2aea
refactor binary & bool ops in liboctave
Jaroslav Hajek <highegg@gmail.com>
parents:
8998
diff
changeset
|
220 return do_sm_binary_op<boolMatrix, S, M> (s, m, OP); \ |
2870 | 221 } |
222 | |
9550
3d6a9aea2aea
refactor binary & bool ops in liboctave
Jaroslav Hajek <highegg@gmail.com>
parents:
8998
diff
changeset
|
223 #define SM_BOOL_OPS(S, M) \ |
3d6a9aea2aea
refactor binary & bool ops in liboctave
Jaroslav Hajek <highegg@gmail.com>
parents:
8998
diff
changeset
|
224 SM_BOOL_OP (mx_el_and, mx_inline_and, S, M) \ |
3d6a9aea2aea
refactor binary & bool ops in liboctave
Jaroslav Hajek <highegg@gmail.com>
parents:
8998
diff
changeset
|
225 SM_BOOL_OP (mx_el_or, mx_inline_or, S, M) |
2870 | 226 |
227 // matrix by matrix operations. | |
228 | |
229 #define MM_BIN_OP(R, OP, M1, M2, F) \ | |
2829 | 230 R \ |
231 OP (const M1& m1, const M2& m2) \ | |
232 { \ | |
9550
3d6a9aea2aea
refactor binary & bool ops in liboctave
Jaroslav Hajek <highegg@gmail.com>
parents:
8998
diff
changeset
|
233 return do_mm_binary_op<R, M1, M2> (m1, m2, F, #OP); \ |
2829 | 234 } |
235 | |
2870 | 236 #define MM_BIN_OPS(R, M1, M2) \ |
3769 | 237 MM_BIN_OP (R, operator +, M1, M2, mx_inline_add) \ |
9550
3d6a9aea2aea
refactor binary & bool ops in liboctave
Jaroslav Hajek <highegg@gmail.com>
parents:
8998
diff
changeset
|
238 MM_BIN_OP (R, operator -, M1, M2, mx_inline_sub) \ |
3d6a9aea2aea
refactor binary & bool ops in liboctave
Jaroslav Hajek <highegg@gmail.com>
parents:
8998
diff
changeset
|
239 MM_BIN_OP (R, product, M1, M2, mx_inline_mul) \ |
3d6a9aea2aea
refactor binary & bool ops in liboctave
Jaroslav Hajek <highegg@gmail.com>
parents:
8998
diff
changeset
|
240 MM_BIN_OP (R, quotient, M1, M2, mx_inline_div) |
2870 | 241 |
4826 | 242 #define MM_CMP_OP(F, OP, M1, C1, M2, C2) \ |
2870 | 243 boolMatrix \ |
244 F (const M1& m1, const M2& m2) \ | |
245 { \ | |
246 boolMatrix r; \ | |
247 \ | |
8380
dbe67764e628
fix & improve speed of diagonal matrix multiplication
Jaroslav Hajek <highegg@gmail.com>
parents:
8375
diff
changeset
|
248 octave_idx_type m1_nr = m1.rows (); \ |
dbe67764e628
fix & improve speed of diagonal matrix multiplication
Jaroslav Hajek <highegg@gmail.com>
parents:
8375
diff
changeset
|
249 octave_idx_type m1_nc = m1.cols (); \ |
2870 | 250 \ |
8380
dbe67764e628
fix & improve speed of diagonal matrix multiplication
Jaroslav Hajek <highegg@gmail.com>
parents:
8375
diff
changeset
|
251 octave_idx_type m2_nr = m2.rows (); \ |
dbe67764e628
fix & improve speed of diagonal matrix multiplication
Jaroslav Hajek <highegg@gmail.com>
parents:
8375
diff
changeset
|
252 octave_idx_type m2_nc = m2.cols (); \ |
2870 | 253 \ |
254 if (m1_nr == m2_nr && m1_nc == m2_nc) \ | |
255 { \ | |
4826 | 256 r.resize (m1_nr, m1_nc); \ |
2870 | 257 \ |
8380
dbe67764e628
fix & improve speed of diagonal matrix multiplication
Jaroslav Hajek <highegg@gmail.com>
parents:
8375
diff
changeset
|
258 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
|
259 for (octave_idx_type i = 0; i < m1_nr; i++) \ |
4826 | 260 r.elem(i, j) = C1 (m1.elem(i, j)) OP C2 (m2.elem(i, j)); \ |
2870 | 261 } \ |
262 else \ | |
4826 | 263 gripe_nonconformant (#F, m1_nr, m1_nc, m2_nr, m2_nc); \ |
2870 | 264 \ |
265 return r; \ | |
266 } | |
2829 | 267 |
2870 | 268 #define MM_CMP_OPS(M1, C1, M2, C2) \ |
4826 | 269 MM_CMP_OP (mx_el_lt, <, M1, C1, M2, C2) \ |
270 MM_CMP_OP (mx_el_le, <=, M1, C1, M2, C2) \ | |
271 MM_CMP_OP (mx_el_ge, >=, M1, C1, M2, C2) \ | |
272 MM_CMP_OP (mx_el_gt, >, M1, C1, M2, C2) \ | |
273 MM_CMP_OP (mx_el_eq, ==, M1, , M2, ) \ | |
274 MM_CMP_OP (mx_el_ne, !=, M1, , M2, ) | |
2870 | 275 |
9550
3d6a9aea2aea
refactor binary & bool ops in liboctave
Jaroslav Hajek <highegg@gmail.com>
parents:
8998
diff
changeset
|
276 #define MM_BOOL_OP(F, OP, M1, M2) \ |
2870 | 277 boolMatrix \ |
278 F (const M1& m1, const M2& m2) \ | |
279 { \ | |
9550
3d6a9aea2aea
refactor binary & bool ops in liboctave
Jaroslav Hajek <highegg@gmail.com>
parents:
8998
diff
changeset
|
280 ND_LOGICAL_NAN_CHECK(m1); \ |
3d6a9aea2aea
refactor binary & bool ops in liboctave
Jaroslav Hajek <highegg@gmail.com>
parents:
8998
diff
changeset
|
281 ND_LOGICAL_NAN_CHECK(m2); \ |
3d6a9aea2aea
refactor binary & bool ops in liboctave
Jaroslav Hajek <highegg@gmail.com>
parents:
8998
diff
changeset
|
282 return do_mm_binary_op<boolMatrix, M1, M2> (m1, m2, OP, #F); \ |
2870 | 283 } |
284 | |
9550
3d6a9aea2aea
refactor binary & bool ops in liboctave
Jaroslav Hajek <highegg@gmail.com>
parents:
8998
diff
changeset
|
285 #define MM_BOOL_OPS(M1, M2) \ |
3d6a9aea2aea
refactor binary & bool ops in liboctave
Jaroslav Hajek <highegg@gmail.com>
parents:
8998
diff
changeset
|
286 MM_BOOL_OP (mx_el_and, mx_inline_and, M1, M2) \ |
3d6a9aea2aea
refactor binary & bool ops in liboctave
Jaroslav Hajek <highegg@gmail.com>
parents:
8998
diff
changeset
|
287 MM_BOOL_OP (mx_el_or, mx_inline_or, M1, M2) |
2870 | 288 |
4543 | 289 // N-d matrix by scalar operations. |
290 | |
291 #define NDS_BIN_OP(R, OP, ND, S, F) \ | |
292 R \ | |
293 OP (const ND& m, const S& s) \ | |
294 { \ | |
9550
3d6a9aea2aea
refactor binary & bool ops in liboctave
Jaroslav Hajek <highegg@gmail.com>
parents:
8998
diff
changeset
|
295 return do_ms_binary_op<R, ND, S> (m, s, F); \ |
4543 | 296 } |
297 | |
298 #define NDS_BIN_OPS(R, ND, S) \ | |
299 NDS_BIN_OP (R, operator +, ND, S, mx_inline_add) \ | |
9550
3d6a9aea2aea
refactor binary & bool ops in liboctave
Jaroslav Hajek <highegg@gmail.com>
parents:
8998
diff
changeset
|
300 NDS_BIN_OP (R, operator -, ND, S, mx_inline_sub) \ |
3d6a9aea2aea
refactor binary & bool ops in liboctave
Jaroslav Hajek <highegg@gmail.com>
parents:
8998
diff
changeset
|
301 NDS_BIN_OP (R, operator *, ND, S, mx_inline_mul) \ |
3d6a9aea2aea
refactor binary & bool ops in liboctave
Jaroslav Hajek <highegg@gmail.com>
parents:
8998
diff
changeset
|
302 NDS_BIN_OP (R, operator /, ND, S, mx_inline_div) |
4543 | 303 |
4826 | 304 #define NDS_CMP_OP(F, OP, ND, NDC, S, SC) \ |
4543 | 305 boolNDArray \ |
306 F (const ND& m, const S& s) \ | |
307 { \ | |
8983
e781ab1aee39
optimize comparison ops
Jaroslav Hajek <highegg@gmail.com>
parents:
8982
diff
changeset
|
308 boolNDArray r (m.dims ()); \ |
4543 | 309 \ |
8380
dbe67764e628
fix & improve speed of diagonal matrix multiplication
Jaroslav Hajek <highegg@gmail.com>
parents:
8375
diff
changeset
|
310 octave_idx_type len = m.length (); \ |
4543 | 311 \ |
8983
e781ab1aee39
optimize comparison ops
Jaroslav Hajek <highegg@gmail.com>
parents:
8982
diff
changeset
|
312 if (s == S ()) \ |
e781ab1aee39
optimize comparison ops
Jaroslav Hajek <highegg@gmail.com>
parents:
8982
diff
changeset
|
313 { \ |
e781ab1aee39
optimize comparison ops
Jaroslav Hajek <highegg@gmail.com>
parents:
8982
diff
changeset
|
314 for (octave_idx_type i = 0; i < len; i++) \ |
e781ab1aee39
optimize comparison ops
Jaroslav Hajek <highegg@gmail.com>
parents:
8982
diff
changeset
|
315 r.xelem(i) = NDC (m.elem(i)) OP SC (S ()); \ |
e781ab1aee39
optimize comparison ops
Jaroslav Hajek <highegg@gmail.com>
parents:
8982
diff
changeset
|
316 } \ |
e781ab1aee39
optimize comparison ops
Jaroslav Hajek <highegg@gmail.com>
parents:
8982
diff
changeset
|
317 else \ |
e781ab1aee39
optimize comparison ops
Jaroslav Hajek <highegg@gmail.com>
parents:
8982
diff
changeset
|
318 { \ |
e781ab1aee39
optimize comparison ops
Jaroslav Hajek <highegg@gmail.com>
parents:
8982
diff
changeset
|
319 for (octave_idx_type i = 0; i < len; i++) \ |
e781ab1aee39
optimize comparison ops
Jaroslav Hajek <highegg@gmail.com>
parents:
8982
diff
changeset
|
320 r.xelem(i) = NDC (m.elem(i)) OP SC (s); \ |
e781ab1aee39
optimize comparison ops
Jaroslav Hajek <highegg@gmail.com>
parents:
8982
diff
changeset
|
321 } \ |
4543 | 322 \ |
323 return r; \ | |
324 } | |
325 | |
326 #define NDS_CMP_OPS(ND, NDC, S, SC) \ | |
4826 | 327 NDS_CMP_OP (mx_el_lt, <, ND, NDC, S, SC) \ |
328 NDS_CMP_OP (mx_el_le, <=, ND, NDC, S, SC) \ | |
329 NDS_CMP_OP (mx_el_ge, >=, ND, NDC, S, SC) \ | |
330 NDS_CMP_OP (mx_el_gt, >, ND, NDC, S, SC) \ | |
331 NDS_CMP_OP (mx_el_eq, ==, ND, , S, ) \ | |
332 NDS_CMP_OP (mx_el_ne, !=, ND, , S, ) | |
4543 | 333 |
6119 | 334 #define NDS_CMP_OP1(F, OP, ND, NDC, S, SC, SPEC) \ |
335 boolNDArray \ | |
336 F (const ND& m, const S& s) \ | |
337 { \ | |
8983
e781ab1aee39
optimize comparison ops
Jaroslav Hajek <highegg@gmail.com>
parents:
8982
diff
changeset
|
338 boolNDArray r (m.dims ()); \ |
6119 | 339 \ |
8380
dbe67764e628
fix & improve speed of diagonal matrix multiplication
Jaroslav Hajek <highegg@gmail.com>
parents:
8375
diff
changeset
|
340 octave_idx_type len = m.length (); \ |
6119 | 341 \ |
8380
dbe67764e628
fix & improve speed of diagonal matrix multiplication
Jaroslav Hajek <highegg@gmail.com>
parents:
8375
diff
changeset
|
342 for (octave_idx_type i = 0; i < len; i++) \ |
6119 | 343 r.elem(i) = operator OP <SPEC> (NDC (m.elem(i)), SC (s)); \ |
344 \ | |
345 return r; \ | |
346 } | |
347 | |
348 #define NDS_CMP_OPS1(ND, NDC, S, SC, SPEC) \ | |
349 NDS_CMP_OP1 (mx_el_lt, <, ND, NDC, S, SC, SPEC) \ | |
350 NDS_CMP_OP1 (mx_el_le, <=, ND, NDC, S, SC, SPEC) \ | |
351 NDS_CMP_OP1 (mx_el_ge, >=, ND, NDC, S, SC, SPEC) \ | |
352 NDS_CMP_OP1 (mx_el_gt, >, ND, NDC, S, SC, SPEC) \ | |
353 NDS_CMP_OP1 (mx_el_eq, ==, ND, , S, , SPEC) \ | |
354 NDS_CMP_OP1 (mx_el_ne, !=, ND, , S, , SPEC) | |
355 | |
356 #define NDS_CMP_OP2(F, OP, ND, NDC, S, SC, SPEC1, SPEC2) \ | |
357 boolNDArray \ | |
358 F (const ND& m, const S& s) \ | |
359 { \ | |
360 boolNDArray r; \ | |
361 \ | |
8380
dbe67764e628
fix & improve speed of diagonal matrix multiplication
Jaroslav Hajek <highegg@gmail.com>
parents:
8375
diff
changeset
|
362 octave_idx_type len = m.length (); \ |
6119 | 363 \ |
364 r.resize (m.dims ()); \ | |
365 \ | |
8380
dbe67764e628
fix & improve speed of diagonal matrix multiplication
Jaroslav Hajek <highegg@gmail.com>
parents:
8375
diff
changeset
|
366 for (octave_idx_type i = 0; i < len; i++) \ |
6119 | 367 r.elem(i) = operator OP <SPEC1,SPEC2> (NDC (m.elem(i)), SC (s)); \ |
368 \ | |
369 return r; \ | |
370 } | |
371 | |
372 #define NDS_CMP_OPS2(ND, NDC, S, SC, SPEC1, SPEC2) \ | |
373 NDS_CMP_OP2 (mx_el_lt, <, ND, NDC, S, SC, SPEC1, SPEC2) \ | |
374 NDS_CMP_OP2 (mx_el_le, <=, ND, NDC, S, SC, SPEC1, SPEC2) \ | |
375 NDS_CMP_OP2 (mx_el_ge, >=, ND, NDC, S, SC, SPEC1, SPEC2) \ | |
376 NDS_CMP_OP2 (mx_el_gt, >, ND, NDC, S, SC, SPEC1, SPEC2) \ | |
377 NDS_CMP_OP2 (mx_el_eq, ==, ND, , S, , SPEC1, SPEC2) \ | |
378 NDS_CMP_OP2 (mx_el_ne, !=, ND, , S, , SPEC1, SPEC2) | |
379 | |
9550
3d6a9aea2aea
refactor binary & bool ops in liboctave
Jaroslav Hajek <highegg@gmail.com>
parents:
8998
diff
changeset
|
380 #define NDS_BOOL_OP(F, OP, ND, S) \ |
4543 | 381 boolNDArray \ |
382 F (const ND& m, const S& s) \ | |
383 { \ | |
9550
3d6a9aea2aea
refactor binary & bool ops in liboctave
Jaroslav Hajek <highegg@gmail.com>
parents:
8998
diff
changeset
|
384 ND_LOGICAL_NAN_CHECK (m); \ |
3d6a9aea2aea
refactor binary & bool ops in liboctave
Jaroslav Hajek <highegg@gmail.com>
parents:
8998
diff
changeset
|
385 SC_LOGICAL_NAN_CHECK (s); \ |
3d6a9aea2aea
refactor binary & bool ops in liboctave
Jaroslav Hajek <highegg@gmail.com>
parents:
8998
diff
changeset
|
386 return do_ms_binary_op<boolNDArray, ND, S> (m, s, OP); \ |
4543 | 387 } |
388 | |
9550
3d6a9aea2aea
refactor binary & bool ops in liboctave
Jaroslav Hajek <highegg@gmail.com>
parents:
8998
diff
changeset
|
389 #define NDS_BOOL_OPS(ND, S) \ |
3d6a9aea2aea
refactor binary & bool ops in liboctave
Jaroslav Hajek <highegg@gmail.com>
parents:
8998
diff
changeset
|
390 NDS_BOOL_OP (mx_el_and, mx_inline_and, ND, S) \ |
3d6a9aea2aea
refactor binary & bool ops in liboctave
Jaroslav Hajek <highegg@gmail.com>
parents:
8998
diff
changeset
|
391 NDS_BOOL_OP (mx_el_or, mx_inline_or, ND, S) \ |
3d6a9aea2aea
refactor binary & bool ops in liboctave
Jaroslav Hajek <highegg@gmail.com>
parents:
8998
diff
changeset
|
392 NDS_BOOL_OP (mx_el_not_and, mx_inline_not_and, ND, S) \ |
3d6a9aea2aea
refactor binary & bool ops in liboctave
Jaroslav Hajek <highegg@gmail.com>
parents:
8998
diff
changeset
|
393 NDS_BOOL_OP (mx_el_not_or, mx_inline_not_or, ND, S) \ |
3d6a9aea2aea
refactor binary & bool ops in liboctave
Jaroslav Hajek <highegg@gmail.com>
parents:
8998
diff
changeset
|
394 NDS_BOOL_OP (mx_el_and_not, mx_inline_and_not, ND, S) \ |
3d6a9aea2aea
refactor binary & bool ops in liboctave
Jaroslav Hajek <highegg@gmail.com>
parents:
8998
diff
changeset
|
395 NDS_BOOL_OP (mx_el_or_not, mx_inline_or_not, ND, S) |
4543 | 396 |
397 // scalar by N-d matrix operations. | |
398 | |
399 #define SND_BIN_OP(R, OP, S, ND, F) \ | |
400 R \ | |
401 OP (const S& s, const ND& m) \ | |
402 { \ | |
9550
3d6a9aea2aea
refactor binary & bool ops in liboctave
Jaroslav Hajek <highegg@gmail.com>
parents:
8998
diff
changeset
|
403 return do_sm_binary_op<R, S, ND> (s, m, F); \ |
4543 | 404 } |
405 | |
406 #define SND_BIN_OPS(R, S, ND) \ | |
407 SND_BIN_OP (R, operator +, S, ND, mx_inline_add) \ | |
9550
3d6a9aea2aea
refactor binary & bool ops in liboctave
Jaroslav Hajek <highegg@gmail.com>
parents:
8998
diff
changeset
|
408 SND_BIN_OP (R, operator -, S, ND, mx_inline_sub) \ |
3d6a9aea2aea
refactor binary & bool ops in liboctave
Jaroslav Hajek <highegg@gmail.com>
parents:
8998
diff
changeset
|
409 SND_BIN_OP (R, operator *, S, ND, mx_inline_mul) \ |
3d6a9aea2aea
refactor binary & bool ops in liboctave
Jaroslav Hajek <highegg@gmail.com>
parents:
8998
diff
changeset
|
410 SND_BIN_OP (R, operator /, S, ND, mx_inline_div) |
4543 | 411 |
4826 | 412 #define SND_CMP_OP(F, OP, S, SC, ND, NDC) \ |
4543 | 413 boolNDArray \ |
414 F (const S& s, const ND& m) \ | |
415 { \ | |
8983
e781ab1aee39
optimize comparison ops
Jaroslav Hajek <highegg@gmail.com>
parents:
8982
diff
changeset
|
416 boolNDArray r (m.dims ()); \ |
4543 | 417 \ |
8380
dbe67764e628
fix & improve speed of diagonal matrix multiplication
Jaroslav Hajek <highegg@gmail.com>
parents:
8375
diff
changeset
|
418 octave_idx_type len = m.length (); \ |
4543 | 419 \ |
8983
e781ab1aee39
optimize comparison ops
Jaroslav Hajek <highegg@gmail.com>
parents:
8982
diff
changeset
|
420 if (s == S ()) \ |
e781ab1aee39
optimize comparison ops
Jaroslav Hajek <highegg@gmail.com>
parents:
8982
diff
changeset
|
421 { \ |
e781ab1aee39
optimize comparison ops
Jaroslav Hajek <highegg@gmail.com>
parents:
8982
diff
changeset
|
422 for (octave_idx_type i = 0; i < len; i++) \ |
e781ab1aee39
optimize comparison ops
Jaroslav Hajek <highegg@gmail.com>
parents:
8982
diff
changeset
|
423 r.xelem(i) = SC (S ()) OP NDC (m.elem(i)); \ |
e781ab1aee39
optimize comparison ops
Jaroslav Hajek <highegg@gmail.com>
parents:
8982
diff
changeset
|
424 } \ |
e781ab1aee39
optimize comparison ops
Jaroslav Hajek <highegg@gmail.com>
parents:
8982
diff
changeset
|
425 else \ |
e781ab1aee39
optimize comparison ops
Jaroslav Hajek <highegg@gmail.com>
parents:
8982
diff
changeset
|
426 { \ |
e781ab1aee39
optimize comparison ops
Jaroslav Hajek <highegg@gmail.com>
parents:
8982
diff
changeset
|
427 for (octave_idx_type i = 0; i < len; i++) \ |
e781ab1aee39
optimize comparison ops
Jaroslav Hajek <highegg@gmail.com>
parents:
8982
diff
changeset
|
428 r.xelem(i) = SC (s) OP NDC (m.elem(i)); \ |
e781ab1aee39
optimize comparison ops
Jaroslav Hajek <highegg@gmail.com>
parents:
8982
diff
changeset
|
429 } \ |
4543 | 430 \ |
431 return r; \ | |
432 } | |
433 | |
434 #define SND_CMP_OPS(S, CS, ND, CND) \ | |
4826 | 435 SND_CMP_OP (mx_el_lt, <, S, CS, ND, CND) \ |
436 SND_CMP_OP (mx_el_le, <=, S, CS, ND, CND) \ | |
437 SND_CMP_OP (mx_el_ge, >=, S, CS, ND, CND) \ | |
438 SND_CMP_OP (mx_el_gt, >, S, CS, ND, CND) \ | |
439 SND_CMP_OP (mx_el_eq, ==, S, , ND, ) \ | |
440 SND_CMP_OP (mx_el_ne, !=, S, , ND, ) | |
4543 | 441 |
6119 | 442 #define SND_CMP_OP1(F, OP, S, SC, ND, NDC, SPEC) \ |
443 boolNDArray \ | |
444 F (const S& s, const ND& m) \ | |
445 { \ | |
8983
e781ab1aee39
optimize comparison ops
Jaroslav Hajek <highegg@gmail.com>
parents:
8982
diff
changeset
|
446 boolNDArray r (m.dims ()); \ |
6119 | 447 \ |
8380
dbe67764e628
fix & improve speed of diagonal matrix multiplication
Jaroslav Hajek <highegg@gmail.com>
parents:
8375
diff
changeset
|
448 octave_idx_type len = m.length (); \ |
6119 | 449 \ |
8380
dbe67764e628
fix & improve speed of diagonal matrix multiplication
Jaroslav Hajek <highegg@gmail.com>
parents:
8375
diff
changeset
|
450 for (octave_idx_type i = 0; i < len; i++) \ |
6119 | 451 r.elem(i) = operator OP <SPEC> (SC (s), NDC (m.elem(i))); \ |
452 \ | |
453 return r; \ | |
454 } | |
455 | |
456 #define SND_CMP_OPS1(S, CS, ND, CND, SPEC) \ | |
457 SND_CMP_OP1 (mx_el_lt, <, S, CS, ND, CND, SPEC) \ | |
458 SND_CMP_OP1 (mx_el_le, <=, S, CS, ND, CND, SPEC) \ | |
459 SND_CMP_OP1 (mx_el_ge, >=, S, CS, ND, CND, SPEC) \ | |
460 SND_CMP_OP1 (mx_el_gt, >, S, CS, ND, CND, SPEC) \ | |
461 SND_CMP_OP1 (mx_el_eq, ==, S, , ND, , SPEC) \ | |
462 SND_CMP_OP1 (mx_el_ne, !=, S, , ND, , SPEC) | |
463 | |
464 #define SND_CMP_OP2(F, OP, S, SC, ND, NDC, SPEC1, SPEC2) \ | |
465 boolNDArray \ | |
466 F (const S& s, const ND& m) \ | |
467 { \ | |
8983
e781ab1aee39
optimize comparison ops
Jaroslav Hajek <highegg@gmail.com>
parents:
8982
diff
changeset
|
468 boolNDArray r (m.dims ()); \ |
6119 | 469 \ |
8380
dbe67764e628
fix & improve speed of diagonal matrix multiplication
Jaroslav Hajek <highegg@gmail.com>
parents:
8375
diff
changeset
|
470 octave_idx_type len = m.length (); \ |
6119 | 471 \ |
8380
dbe67764e628
fix & improve speed of diagonal matrix multiplication
Jaroslav Hajek <highegg@gmail.com>
parents:
8375
diff
changeset
|
472 for (octave_idx_type i = 0; i < len; i++) \ |
6119 | 473 r.elem(i) = operator OP <SPEC1, SPEC2> (SC (s), NDC (m.elem(i))); \ |
474 \ | |
475 return r; \ | |
476 } | |
477 | |
478 #define SND_CMP_OPS2(S, CS, ND, CND, SPEC1, SPEC2) \ | |
479 SND_CMP_OP2 (mx_el_lt, <, S, CS, ND, CND, SPEC1, SPEC2) \ | |
480 SND_CMP_OP2 (mx_el_le, <=, S, CS, ND, CND, SPEC1, SPEC2) \ | |
481 SND_CMP_OP2 (mx_el_ge, >=, S, CS, ND, CND, SPEC1, SPEC2) \ | |
482 SND_CMP_OP2 (mx_el_gt, >, S, CS, ND, CND, SPEC1, SPEC2) \ | |
483 SND_CMP_OP2 (mx_el_eq, ==, S, , ND, , SPEC1, SPEC2) \ | |
484 SND_CMP_OP2 (mx_el_ne, !=, S, , ND, , SPEC1, SPEC2) | |
485 | |
9550
3d6a9aea2aea
refactor binary & bool ops in liboctave
Jaroslav Hajek <highegg@gmail.com>
parents:
8998
diff
changeset
|
486 #define SND_BOOL_OP(F, OP, S, ND) \ |
4543 | 487 boolNDArray \ |
488 F (const S& s, const ND& m) \ | |
489 { \ | |
9550
3d6a9aea2aea
refactor binary & bool ops in liboctave
Jaroslav Hajek <highegg@gmail.com>
parents:
8998
diff
changeset
|
490 SC_LOGICAL_NAN_CHECK (s); \ |
3d6a9aea2aea
refactor binary & bool ops in liboctave
Jaroslav Hajek <highegg@gmail.com>
parents:
8998
diff
changeset
|
491 ND_LOGICAL_NAN_CHECK (m); \ |
3d6a9aea2aea
refactor binary & bool ops in liboctave
Jaroslav Hajek <highegg@gmail.com>
parents:
8998
diff
changeset
|
492 return do_sm_binary_op<boolNDArray, S, ND> (s, m, OP); \ |
4543 | 493 } |
494 | |
9550
3d6a9aea2aea
refactor binary & bool ops in liboctave
Jaroslav Hajek <highegg@gmail.com>
parents:
8998
diff
changeset
|
495 #define SND_BOOL_OPS(S, ND) \ |
3d6a9aea2aea
refactor binary & bool ops in liboctave
Jaroslav Hajek <highegg@gmail.com>
parents:
8998
diff
changeset
|
496 SND_BOOL_OP (mx_el_and, mx_inline_and, S, ND) \ |
3d6a9aea2aea
refactor binary & bool ops in liboctave
Jaroslav Hajek <highegg@gmail.com>
parents:
8998
diff
changeset
|
497 SND_BOOL_OP (mx_el_or, mx_inline_or, S, ND) \ |
3d6a9aea2aea
refactor binary & bool ops in liboctave
Jaroslav Hajek <highegg@gmail.com>
parents:
8998
diff
changeset
|
498 SND_BOOL_OP (mx_el_not_and, mx_inline_not_and, S, ND) \ |
3d6a9aea2aea
refactor binary & bool ops in liboctave
Jaroslav Hajek <highegg@gmail.com>
parents:
8998
diff
changeset
|
499 SND_BOOL_OP (mx_el_not_or, mx_inline_not_or, S, ND) \ |
3d6a9aea2aea
refactor binary & bool ops in liboctave
Jaroslav Hajek <highegg@gmail.com>
parents:
8998
diff
changeset
|
500 SND_BOOL_OP (mx_el_and_not, mx_inline_and_not, S, ND) \ |
3d6a9aea2aea
refactor binary & bool ops in liboctave
Jaroslav Hajek <highegg@gmail.com>
parents:
8998
diff
changeset
|
501 SND_BOOL_OP (mx_el_or_not, mx_inline_or_not, S, ND) |
4543 | 502 |
503 // N-d matrix by N-d matrix operations. | |
504 | |
505 #define NDND_BIN_OP(R, OP, ND1, ND2, F) \ | |
506 R \ | |
507 OP (const ND1& m1, const ND2& m2) \ | |
508 { \ | |
9550
3d6a9aea2aea
refactor binary & bool ops in liboctave
Jaroslav Hajek <highegg@gmail.com>
parents:
8998
diff
changeset
|
509 return do_mm_binary_op<R, ND1, ND2> (m1, m2, F, #OP); \ |
4543 | 510 } |
511 | |
512 #define NDND_BIN_OPS(R, ND1, ND2) \ | |
513 NDND_BIN_OP (R, operator +, ND1, ND2, mx_inline_add) \ | |
9550
3d6a9aea2aea
refactor binary & bool ops in liboctave
Jaroslav Hajek <highegg@gmail.com>
parents:
8998
diff
changeset
|
514 NDND_BIN_OP (R, operator -, ND1, ND2, mx_inline_sub) \ |
3d6a9aea2aea
refactor binary & bool ops in liboctave
Jaroslav Hajek <highegg@gmail.com>
parents:
8998
diff
changeset
|
515 NDND_BIN_OP (R, product, ND1, ND2, mx_inline_mul) \ |
3d6a9aea2aea
refactor binary & bool ops in liboctave
Jaroslav Hajek <highegg@gmail.com>
parents:
8998
diff
changeset
|
516 NDND_BIN_OP (R, quotient, ND1, ND2, mx_inline_div) |
4543 | 517 |
4826 | 518 #define NDND_CMP_OP(F, OP, ND1, C1, ND2, C2) \ |
4543 | 519 boolNDArray \ |
520 F (const ND1& m1, const ND2& m2) \ | |
521 { \ | |
522 boolNDArray r; \ | |
523 \ | |
524 dim_vector m1_dims = m1.dims (); \ | |
525 dim_vector m2_dims = m2.dims (); \ | |
526 \ | |
527 if (m1_dims == m2_dims) \ | |
528 { \ | |
8983
e781ab1aee39
optimize comparison ops
Jaroslav Hajek <highegg@gmail.com>
parents:
8982
diff
changeset
|
529 r = boolNDArray (m1_dims); \ |
4543 | 530 \ |
8380
dbe67764e628
fix & improve speed of diagonal matrix multiplication
Jaroslav Hajek <highegg@gmail.com>
parents:
8375
diff
changeset
|
531 for (octave_idx_type i = 0; i < m1.length (); i++) \ |
8983
e781ab1aee39
optimize comparison ops
Jaroslav Hajek <highegg@gmail.com>
parents:
8982
diff
changeset
|
532 r.xelem(i) = C1 (m1.elem(i)) OP C2 (m2.elem(i)); \ |
4543 | 533 } \ |
534 else \ | |
4826 | 535 gripe_nonconformant (#F, m1_dims, m2_dims); \ |
4543 | 536 \ |
537 return r; \ | |
538 } | |
539 | |
540 #define NDND_CMP_OPS(ND1, C1, ND2, C2) \ | |
4826 | 541 NDND_CMP_OP (mx_el_lt, <, ND1, C1, ND2, C2) \ |
542 NDND_CMP_OP (mx_el_le, <=, ND1, C1, ND2, C2) \ | |
543 NDND_CMP_OP (mx_el_ge, >=, ND1, C1, ND2, C2) \ | |
544 NDND_CMP_OP (mx_el_gt, >, ND1, C1, ND2, C2) \ | |
545 NDND_CMP_OP (mx_el_eq, ==, ND1, , ND2, ) \ | |
546 NDND_CMP_OP (mx_el_ne, !=, ND1, , ND2, ) | |
4543 | 547 |
9550
3d6a9aea2aea
refactor binary & bool ops in liboctave
Jaroslav Hajek <highegg@gmail.com>
parents:
8998
diff
changeset
|
548 #define NDND_BOOL_OP(F, OP, ND1, ND2) \ |
4543 | 549 boolNDArray \ |
550 F (const ND1& m1, const ND2& m2) \ | |
551 { \ | |
9550
3d6a9aea2aea
refactor binary & bool ops in liboctave
Jaroslav Hajek <highegg@gmail.com>
parents:
8998
diff
changeset
|
552 ND_LOGICAL_NAN_CHECK(m1); \ |
3d6a9aea2aea
refactor binary & bool ops in liboctave
Jaroslav Hajek <highegg@gmail.com>
parents:
8998
diff
changeset
|
553 ND_LOGICAL_NAN_CHECK(m2); \ |
3d6a9aea2aea
refactor binary & bool ops in liboctave
Jaroslav Hajek <highegg@gmail.com>
parents:
8998
diff
changeset
|
554 return do_mm_binary_op<boolNDArray, ND1, ND2> (m1, m2, OP, #F); \ |
4543 | 555 } |
556 | |
9550
3d6a9aea2aea
refactor binary & bool ops in liboctave
Jaroslav Hajek <highegg@gmail.com>
parents:
8998
diff
changeset
|
557 #define NDND_BOOL_OPS(ND1, ND2) \ |
3d6a9aea2aea
refactor binary & bool ops in liboctave
Jaroslav Hajek <highegg@gmail.com>
parents:
8998
diff
changeset
|
558 NDND_BOOL_OP (mx_el_and, mx_inline_and, ND1, ND2) \ |
3d6a9aea2aea
refactor binary & bool ops in liboctave
Jaroslav Hajek <highegg@gmail.com>
parents:
8998
diff
changeset
|
559 NDND_BOOL_OP (mx_el_or, mx_inline_or, ND1, ND2) \ |
3d6a9aea2aea
refactor binary & bool ops in liboctave
Jaroslav Hajek <highegg@gmail.com>
parents:
8998
diff
changeset
|
560 NDND_BOOL_OP (mx_el_not_and, mx_inline_not_and, ND1, ND2) \ |
3d6a9aea2aea
refactor binary & bool ops in liboctave
Jaroslav Hajek <highegg@gmail.com>
parents:
8998
diff
changeset
|
561 NDND_BOOL_OP (mx_el_not_or, mx_inline_not_or, ND1, ND2) \ |
3d6a9aea2aea
refactor binary & bool ops in liboctave
Jaroslav Hajek <highegg@gmail.com>
parents:
8998
diff
changeset
|
562 NDND_BOOL_OP (mx_el_and_not, mx_inline_and_not, ND1, ND2) \ |
3d6a9aea2aea
refactor binary & bool ops in liboctave
Jaroslav Hajek <highegg@gmail.com>
parents:
8998
diff
changeset
|
563 NDND_BOOL_OP (mx_el_or_not, mx_inline_or_not, ND1, ND2) |
4543 | 564 |
2870 | 565 // scalar by diagonal matrix operations. |
566 | |
567 #define SDM_BIN_OP(R, OP, S, DM, OPEQ) \ | |
2829 | 568 R \ |
569 OP (const S& s, const DM& dm) \ | |
570 { \ | |
8380
dbe67764e628
fix & improve speed of diagonal matrix multiplication
Jaroslav Hajek <highegg@gmail.com>
parents:
8375
diff
changeset
|
571 octave_idx_type nr = dm.rows (); \ |
dbe67764e628
fix & improve speed of diagonal matrix multiplication
Jaroslav Hajek <highegg@gmail.com>
parents:
8375
diff
changeset
|
572 octave_idx_type nc = dm.cols (); \ |
2829 | 573 \ |
574 R r (nr, nc, s); \ | |
575 \ | |
8380
dbe67764e628
fix & improve speed of diagonal matrix multiplication
Jaroslav Hajek <highegg@gmail.com>
parents:
8375
diff
changeset
|
576 for (octave_idx_type i = 0; i < dm.length (); i++) \ |
2870 | 577 r.elem(i, i) OPEQ dm.elem(i, i); \ |
2829 | 578 \ |
579 return r; \ | |
580 } | |
581 | |
2870 | 582 #define SDM_BIN_OPS(R, S, DM) \ |
583 SDM_BIN_OP (R, operator +, S, DM, +=) \ | |
584 SDM_BIN_OP (R, operator -, S, DM, -=) | |
585 | |
586 // diagonal matrix by scalar operations. | |
587 | |
588 #define DMS_BIN_OP(R, OP, DM, S, SGN) \ | |
2829 | 589 R \ |
590 OP (const DM& dm, const S& s) \ | |
591 { \ | |
8380
dbe67764e628
fix & improve speed of diagonal matrix multiplication
Jaroslav Hajek <highegg@gmail.com>
parents:
8375
diff
changeset
|
592 octave_idx_type nr = dm.rows (); \ |
dbe67764e628
fix & improve speed of diagonal matrix multiplication
Jaroslav Hajek <highegg@gmail.com>
parents:
8375
diff
changeset
|
593 octave_idx_type nc = dm.cols (); \ |
2829 | 594 \ |
595 R r (nr, nc, SGN s); \ | |
596 \ | |
8380
dbe67764e628
fix & improve speed of diagonal matrix multiplication
Jaroslav Hajek <highegg@gmail.com>
parents:
8375
diff
changeset
|
597 for (octave_idx_type i = 0; i < dm.length (); i++) \ |
2870 | 598 r.elem(i, i) += dm.elem(i, i); \ |
2829 | 599 \ |
600 return r; \ | |
601 } | |
602 | |
2870 | 603 #define DMS_BIN_OPS(R, DM, S) \ |
604 DMS_BIN_OP (R, operator +, DM, S, ) \ | |
605 DMS_BIN_OP (R, operator -, DM, S, -) | |
606 | |
607 // matrix by diagonal matrix operations. | |
608 | |
609 #define MDM_BIN_OP(R, OP, M, DM, OPEQ) \ | |
2829 | 610 R \ |
611 OP (const M& m, const DM& dm) \ | |
612 { \ | |
613 R r; \ | |
614 \ | |
8380
dbe67764e628
fix & improve speed of diagonal matrix multiplication
Jaroslav Hajek <highegg@gmail.com>
parents:
8375
diff
changeset
|
615 octave_idx_type m_nr = m.rows (); \ |
dbe67764e628
fix & improve speed of diagonal matrix multiplication
Jaroslav Hajek <highegg@gmail.com>
parents:
8375
diff
changeset
|
616 octave_idx_type m_nc = m.cols (); \ |
2829 | 617 \ |
8380
dbe67764e628
fix & improve speed of diagonal matrix multiplication
Jaroslav Hajek <highegg@gmail.com>
parents:
8375
diff
changeset
|
618 octave_idx_type dm_nr = dm.rows (); \ |
dbe67764e628
fix & improve speed of diagonal matrix multiplication
Jaroslav Hajek <highegg@gmail.com>
parents:
8375
diff
changeset
|
619 octave_idx_type dm_nc = dm.cols (); \ |
2829 | 620 \ |
621 if (m_nr != dm_nr || m_nc != dm_nc) \ | |
622 gripe_nonconformant (#OP, m_nr, m_nc, dm_nr, dm_nc); \ | |
623 else \ | |
624 { \ | |
625 r.resize (m_nr, m_nc); \ | |
626 \ | |
627 if (m_nr > 0 && m_nc > 0) \ | |
628 { \ | |
3585 | 629 r = R (m); \ |
2829 | 630 \ |
8380
dbe67764e628
fix & improve speed of diagonal matrix multiplication
Jaroslav Hajek <highegg@gmail.com>
parents:
8375
diff
changeset
|
631 octave_idx_type len = dm.length (); \ |
2829 | 632 \ |
8380
dbe67764e628
fix & improve speed of diagonal matrix multiplication
Jaroslav Hajek <highegg@gmail.com>
parents:
8375
diff
changeset
|
633 for (octave_idx_type i = 0; i < len; i++) \ |
2870 | 634 r.elem(i, i) OPEQ dm.elem(i, i); \ |
2829 | 635 } \ |
636 } \ | |
637 \ | |
638 return r; \ | |
639 } | |
640 | |
5030 | 641 #define MDM_MULTIPLY_OP(R, M, DM, R_ZERO) \ |
2829 | 642 R \ |
643 operator * (const M& m, const DM& dm) \ | |
644 { \ | |
645 R r; \ | |
646 \ | |
8380
dbe67764e628
fix & improve speed of diagonal matrix multiplication
Jaroslav Hajek <highegg@gmail.com>
parents:
8375
diff
changeset
|
647 octave_idx_type m_nr = m.rows (); \ |
dbe67764e628
fix & improve speed of diagonal matrix multiplication
Jaroslav Hajek <highegg@gmail.com>
parents:
8375
diff
changeset
|
648 octave_idx_type m_nc = m.cols (); \ |
2829 | 649 \ |
8380
dbe67764e628
fix & improve speed of diagonal matrix multiplication
Jaroslav Hajek <highegg@gmail.com>
parents:
8375
diff
changeset
|
650 octave_idx_type dm_nr = dm.rows (); \ |
dbe67764e628
fix & improve speed of diagonal matrix multiplication
Jaroslav Hajek <highegg@gmail.com>
parents:
8375
diff
changeset
|
651 octave_idx_type dm_nc = dm.cols (); \ |
2829 | 652 \ |
653 if (m_nc != dm_nr) \ | |
654 gripe_nonconformant ("operator *", m_nr, m_nc, dm_nr, dm_nc); \ | |
655 else \ | |
656 { \ | |
8366
8b1a2555c4e2
implement diagonal matrix objects
Jaroslav Hajek <highegg@gmail.com>
parents:
7922
diff
changeset
|
657 r = R (m_nr, dm_nc); \ |
8380
dbe67764e628
fix & improve speed of diagonal matrix multiplication
Jaroslav Hajek <highegg@gmail.com>
parents:
8375
diff
changeset
|
658 R::element_type *rd = r.fortran_vec (); \ |
dbe67764e628
fix & improve speed of diagonal matrix multiplication
Jaroslav Hajek <highegg@gmail.com>
parents:
8375
diff
changeset
|
659 const M::element_type *md = m.data (); \ |
dbe67764e628
fix & improve speed of diagonal matrix multiplication
Jaroslav Hajek <highegg@gmail.com>
parents:
8375
diff
changeset
|
660 const DM::element_type *dd = dm.data (); \ |
4543 | 661 \ |
8380
dbe67764e628
fix & improve speed of diagonal matrix multiplication
Jaroslav Hajek <highegg@gmail.com>
parents:
8375
diff
changeset
|
662 octave_idx_type len = dm.length (); \ |
dbe67764e628
fix & improve speed of diagonal matrix multiplication
Jaroslav Hajek <highegg@gmail.com>
parents:
8375
diff
changeset
|
663 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
|
664 { \ |
9550
3d6a9aea2aea
refactor binary & bool ops in liboctave
Jaroslav Hajek <highegg@gmail.com>
parents:
8998
diff
changeset
|
665 mx_inline_mul (m_nr, rd, md, dd[i]); \ |
8380
dbe67764e628
fix & improve speed of diagonal matrix multiplication
Jaroslav Hajek <highegg@gmail.com>
parents:
8375
diff
changeset
|
666 rd += m_nr; md += m_nr; \ |
dbe67764e628
fix & improve speed of diagonal matrix multiplication
Jaroslav Hajek <highegg@gmail.com>
parents:
8375
diff
changeset
|
667 } \ |
9550
3d6a9aea2aea
refactor binary & bool ops in liboctave
Jaroslav Hajek <highegg@gmail.com>
parents:
8998
diff
changeset
|
668 mx_inline_fill (m_nr * (dm_nc - len), rd, R_ZERO); \ |
2829 | 669 } \ |
670 \ | |
671 return r; \ | |
672 } | |
673 | |
5030 | 674 #define MDM_BIN_OPS(R, M, DM, R_ZERO) \ |
2870 | 675 MDM_BIN_OP (R, operator +, M, DM, +=) \ |
676 MDM_BIN_OP (R, operator -, M, DM, -=) \ | |
5030 | 677 MDM_MULTIPLY_OP (R, M, DM, R_ZERO) |
2829 | 678 |
2870 | 679 // diagonal matrix by matrix operations. |
680 | |
3585 | 681 #define DMM_BIN_OP(R, OP, DM, M, OPEQ, PREOP) \ |
2829 | 682 R \ |
683 OP (const DM& dm, const M& m) \ | |
684 { \ | |
685 R r; \ | |
686 \ | |
8380
dbe67764e628
fix & improve speed of diagonal matrix multiplication
Jaroslav Hajek <highegg@gmail.com>
parents:
8375
diff
changeset
|
687 octave_idx_type dm_nr = dm.rows (); \ |
dbe67764e628
fix & improve speed of diagonal matrix multiplication
Jaroslav Hajek <highegg@gmail.com>
parents:
8375
diff
changeset
|
688 octave_idx_type dm_nc = dm.cols (); \ |
2829 | 689 \ |
8380
dbe67764e628
fix & improve speed of diagonal matrix multiplication
Jaroslav Hajek <highegg@gmail.com>
parents:
8375
diff
changeset
|
690 octave_idx_type m_nr = m.rows (); \ |
dbe67764e628
fix & improve speed of diagonal matrix multiplication
Jaroslav Hajek <highegg@gmail.com>
parents:
8375
diff
changeset
|
691 octave_idx_type m_nc = m.cols (); \ |
2829 | 692 \ |
693 if (dm_nr != m_nr || dm_nc != m_nc) \ | |
694 gripe_nonconformant (#OP, dm_nr, dm_nc, m_nr, m_nc); \ | |
695 else \ | |
696 { \ | |
697 if (m_nr > 0 && m_nc > 0) \ | |
698 { \ | |
3585 | 699 r = R (PREOP m); \ |
2829 | 700 \ |
8380
dbe67764e628
fix & improve speed of diagonal matrix multiplication
Jaroslav Hajek <highegg@gmail.com>
parents:
8375
diff
changeset
|
701 octave_idx_type len = dm.length (); \ |
2829 | 702 \ |
8380
dbe67764e628
fix & improve speed of diagonal matrix multiplication
Jaroslav Hajek <highegg@gmail.com>
parents:
8375
diff
changeset
|
703 for (octave_idx_type i = 0; i < len; i++) \ |
2870 | 704 r.elem(i, i) OPEQ dm.elem(i, i); \ |
2829 | 705 } \ |
706 else \ | |
707 r.resize (m_nr, m_nc); \ | |
708 } \ | |
709 \ | |
710 return r; \ | |
711 } | |
712 | |
5030 | 713 #define DMM_MULTIPLY_OP(R, DM, M, R_ZERO) \ |
2829 | 714 R \ |
715 operator * (const DM& dm, const M& m) \ | |
716 { \ | |
717 R r; \ | |
718 \ | |
8380
dbe67764e628
fix & improve speed of diagonal matrix multiplication
Jaroslav Hajek <highegg@gmail.com>
parents:
8375
diff
changeset
|
719 octave_idx_type dm_nr = dm.rows (); \ |
dbe67764e628
fix & improve speed of diagonal matrix multiplication
Jaroslav Hajek <highegg@gmail.com>
parents:
8375
diff
changeset
|
720 octave_idx_type dm_nc = dm.cols (); \ |
2829 | 721 \ |
8380
dbe67764e628
fix & improve speed of diagonal matrix multiplication
Jaroslav Hajek <highegg@gmail.com>
parents:
8375
diff
changeset
|
722 octave_idx_type m_nr = m.rows (); \ |
dbe67764e628
fix & improve speed of diagonal matrix multiplication
Jaroslav Hajek <highegg@gmail.com>
parents:
8375
diff
changeset
|
723 octave_idx_type m_nc = m.cols (); \ |
2829 | 724 \ |
725 if (dm_nc != m_nr) \ | |
726 gripe_nonconformant ("operator *", dm_nr, dm_nc, m_nr, m_nc); \ | |
727 else \ | |
728 { \ | |
8366
8b1a2555c4e2
implement diagonal matrix objects
Jaroslav Hajek <highegg@gmail.com>
parents:
7922
diff
changeset
|
729 r = R (dm_nr, m_nc); \ |
8380
dbe67764e628
fix & improve speed of diagonal matrix multiplication
Jaroslav Hajek <highegg@gmail.com>
parents:
8375
diff
changeset
|
730 R::element_type *rd = r.fortran_vec (); \ |
dbe67764e628
fix & improve speed of diagonal matrix multiplication
Jaroslav Hajek <highegg@gmail.com>
parents:
8375
diff
changeset
|
731 const M::element_type *md = m.data (); \ |
dbe67764e628
fix & improve speed of diagonal matrix multiplication
Jaroslav Hajek <highegg@gmail.com>
parents:
8375
diff
changeset
|
732 const DM::element_type *dd = dm.data (); \ |
4543 | 733 \ |
8380
dbe67764e628
fix & improve speed of diagonal matrix multiplication
Jaroslav Hajek <highegg@gmail.com>
parents:
8375
diff
changeset
|
734 octave_idx_type len = dm.length (); \ |
dbe67764e628
fix & improve speed of diagonal matrix multiplication
Jaroslav Hajek <highegg@gmail.com>
parents:
8375
diff
changeset
|
735 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
|
736 { \ |
9550
3d6a9aea2aea
refactor binary & bool ops in liboctave
Jaroslav Hajek <highegg@gmail.com>
parents:
8998
diff
changeset
|
737 mx_inline_mul (len, rd, md, dd); \ |
8380
dbe67764e628
fix & improve speed of diagonal matrix multiplication
Jaroslav Hajek <highegg@gmail.com>
parents:
8375
diff
changeset
|
738 rd += len; md += m_nr; \ |
9550
3d6a9aea2aea
refactor binary & bool ops in liboctave
Jaroslav Hajek <highegg@gmail.com>
parents:
8998
diff
changeset
|
739 mx_inline_fill (dm_nr - len, rd, R_ZERO); \ |
8380
dbe67764e628
fix & improve speed of diagonal matrix multiplication
Jaroslav Hajek <highegg@gmail.com>
parents:
8375
diff
changeset
|
740 rd += dm_nr - len; \ |
dbe67764e628
fix & improve speed of diagonal matrix multiplication
Jaroslav Hajek <highegg@gmail.com>
parents:
8375
diff
changeset
|
741 } \ |
2829 | 742 } \ |
743 \ | |
744 return r; \ | |
745 } | |
746 | |
5030 | 747 #define DMM_BIN_OPS(R, DM, M, R_ZERO) \ |
3585 | 748 DMM_BIN_OP (R, operator +, DM, M, +=, ) \ |
749 DMM_BIN_OP (R, operator -, DM, M, +=, -) \ | |
5030 | 750 DMM_MULTIPLY_OP (R, DM, M, R_ZERO) |
2829 | 751 |
2870 | 752 // diagonal matrix by diagonal matrix operations. |
2829 | 753 |
2870 | 754 #define DMDM_BIN_OP(R, OP, DM1, DM2, F) \ |
2829 | 755 R \ |
756 OP (const DM1& dm1, const DM2& dm2) \ | |
757 { \ | |
758 R r; \ | |
759 \ | |
8380
dbe67764e628
fix & improve speed of diagonal matrix multiplication
Jaroslav Hajek <highegg@gmail.com>
parents:
8375
diff
changeset
|
760 octave_idx_type dm1_nr = dm1.rows (); \ |
dbe67764e628
fix & improve speed of diagonal matrix multiplication
Jaroslav Hajek <highegg@gmail.com>
parents:
8375
diff
changeset
|
761 octave_idx_type dm1_nc = dm1.cols (); \ |
2829 | 762 \ |
8380
dbe67764e628
fix & improve speed of diagonal matrix multiplication
Jaroslav Hajek <highegg@gmail.com>
parents:
8375
diff
changeset
|
763 octave_idx_type dm2_nr = dm2.rows (); \ |
dbe67764e628
fix & improve speed of diagonal matrix multiplication
Jaroslav Hajek <highegg@gmail.com>
parents:
8375
diff
changeset
|
764 octave_idx_type dm2_nc = dm2.cols (); \ |
2829 | 765 \ |
766 if (dm1_nr != dm2_nr || dm1_nc != dm2_nc) \ | |
767 gripe_nonconformant (#OP, dm1_nr, dm1_nc, dm2_nr, dm2_nc); \ | |
768 else \ | |
769 { \ | |
770 r.resize (dm1_nr, dm1_nc); \ | |
771 \ | |
772 if (dm1_nr > 0 && dm1_nc > 0) \ | |
9550
3d6a9aea2aea
refactor binary & bool ops in liboctave
Jaroslav Hajek <highegg@gmail.com>
parents:
8998
diff
changeset
|
773 F (dm1.length (), r.fortran_vec (), dm1.data (), dm2.data ()); \ |
2829 | 774 } \ |
775 \ | |
776 return r; \ | |
777 } | |
778 | |
2870 | 779 #define DMDM_BIN_OPS(R, DM1, DM2) \ |
3769 | 780 DMDM_BIN_OP (R, operator +, DM1, DM2, mx_inline_add) \ |
9550
3d6a9aea2aea
refactor binary & bool ops in liboctave
Jaroslav Hajek <highegg@gmail.com>
parents:
8998
diff
changeset
|
781 DMDM_BIN_OP (R, operator -, DM1, DM2, mx_inline_sub) \ |
3d6a9aea2aea
refactor binary & bool ops in liboctave
Jaroslav Hajek <highegg@gmail.com>
parents:
8998
diff
changeset
|
782 DMDM_BIN_OP (R, product, DM1, DM2, mx_inline_mul) |
2870 | 783 |
8774
b756ce0002db
split implementation and interface in mx-op-defs and MArray-defs
Jaroslav Hajek <highegg@gmail.com>
parents:
8397
diff
changeset
|
784 // scalar by N-d array min/max ops |
3582 | 785 |
7189 | 786 #define SND_MINMAX_FCN(FCN, OP, T) \ |
787 T ## NDArray \ | |
788 FCN (octave_ ## T d, const T ## NDArray& m) \ | |
789 { \ | |
790 dim_vector dv = m.dims (); \ | |
791 octave_idx_type nel = dv.numel (); \ | |
792 \ | |
793 if (nel == 0) \ | |
794 return T ## NDArray (dv); \ | |
795 \ | |
796 T ## NDArray result (dv); \ | |
797 \ | |
798 for (octave_idx_type i = 0; i < nel; i++) \ | |
799 { \ | |
800 OCTAVE_QUIT; \ | |
801 result (i) = d OP m (i) ? d : m(i); \ | |
802 } \ | |
803 \ | |
804 return result; \ | |
805 } | |
806 | |
807 #define NDS_MINMAX_FCN(FCN, OP, T) \ | |
808 T ## NDArray \ | |
809 FCN (const T ## NDArray& m, octave_ ## T d) \ | |
810 { \ | |
811 dim_vector dv = m.dims (); \ | |
812 octave_idx_type nel = dv.numel (); \ | |
813 \ | |
814 if (nel == 0) \ | |
815 return T ## NDArray (dv); \ | |
816 \ | |
817 T ## NDArray result (dv); \ | |
818 \ | |
819 for (octave_idx_type i = 0; i < nel; i++) \ | |
820 { \ | |
821 OCTAVE_QUIT; \ | |
822 result (i) = m (i) OP d ? m(i) : d; \ | |
823 } \ | |
824 \ | |
825 return result; \ | |
826 } | |
827 | |
828 #define NDND_MINMAX_FCN(FCN, OP, T) \ | |
829 T ## NDArray \ | |
830 FCN (const T ## NDArray& a, const T ## NDArray& b) \ | |
831 { \ | |
832 dim_vector dv = a.dims (); \ | |
833 octave_idx_type nel = dv.numel (); \ | |
834 \ | |
835 if (dv != b.dims ()) \ | |
836 { \ | |
837 (*current_liboctave_error_handler) \ | |
838 ("two-arg min expecting args of same size"); \ | |
839 return T ## NDArray (); \ | |
840 } \ | |
841 \ | |
842 if (nel == 0) \ | |
843 return T ## NDArray (dv); \ | |
844 \ | |
845 T ## NDArray result (dv); \ | |
846 \ | |
847 for (octave_idx_type i = 0; i < nel; i++) \ | |
848 { \ | |
849 OCTAVE_QUIT; \ | |
850 result (i) = a(i) OP b(i) ? a(i) : b(i); \ | |
851 } \ | |
852 \ | |
853 return result; \ | |
854 } | |
855 | |
856 #define MINMAX_FCNS(T) \ | |
857 SND_MINMAX_FCN (min, <, T) \ | |
858 NDS_MINMAX_FCN (min, <, T) \ | |
859 NDND_MINMAX_FCN (min, <, T) \ | |
860 SND_MINMAX_FCN (max, >, T) \ | |
861 NDS_MINMAX_FCN (max, >, T) \ | |
862 NDND_MINMAX_FCN (max, >, T) | |
863 | |
8774
b756ce0002db
split implementation and interface in mx-op-defs and MArray-defs
Jaroslav Hajek <highegg@gmail.com>
parents:
8397
diff
changeset
|
864 // permutation matrix by matrix ops and vice versa |
7189 | 865 |
8367
445d27d79f4e
support permutation matrix objects
Jaroslav Hajek <highegg@gmail.com>
parents:
8366
diff
changeset
|
866 #define PMM_MULTIPLY_OP(PM, M) \ |
445d27d79f4e
support permutation matrix objects
Jaroslav Hajek <highegg@gmail.com>
parents:
8366
diff
changeset
|
867 M operator * (const PM& p, const M& x) \ |
445d27d79f4e
support permutation matrix objects
Jaroslav Hajek <highegg@gmail.com>
parents:
8366
diff
changeset
|
868 { \ |
445d27d79f4e
support permutation matrix objects
Jaroslav Hajek <highegg@gmail.com>
parents:
8366
diff
changeset
|
869 octave_idx_type nr = x.rows (), nc = x.columns (); \ |
445d27d79f4e
support permutation matrix objects
Jaroslav Hajek <highegg@gmail.com>
parents:
8366
diff
changeset
|
870 M result; \ |
445d27d79f4e
support permutation matrix objects
Jaroslav Hajek <highegg@gmail.com>
parents:
8366
diff
changeset
|
871 if (p.columns () != nr) \ |
445d27d79f4e
support permutation matrix objects
Jaroslav Hajek <highegg@gmail.com>
parents:
8366
diff
changeset
|
872 gripe_nonconformant ("operator *", p.rows (), p.columns (), nr, nc); \ |
445d27d79f4e
support permutation matrix objects
Jaroslav Hajek <highegg@gmail.com>
parents:
8366
diff
changeset
|
873 else \ |
445d27d79f4e
support permutation matrix objects
Jaroslav Hajek <highegg@gmail.com>
parents:
8366
diff
changeset
|
874 { \ |
445d27d79f4e
support permutation matrix objects
Jaroslav Hajek <highegg@gmail.com>
parents:
8366
diff
changeset
|
875 if (p.is_col_perm ()) \ |
445d27d79f4e
support permutation matrix objects
Jaroslav Hajek <highegg@gmail.com>
parents:
8366
diff
changeset
|
876 { \ |
445d27d79f4e
support permutation matrix objects
Jaroslav Hajek <highegg@gmail.com>
parents:
8366
diff
changeset
|
877 result = M (nr, nc); \ |
8375
e3c9102431a9
fix design problems of diag & perm matrix classes
Jaroslav Hajek <highegg@gmail.com>
parents:
8367
diff
changeset
|
878 result.assign (p.pvec (), idx_vector::colon, x); \ |
8367
445d27d79f4e
support permutation matrix objects
Jaroslav Hajek <highegg@gmail.com>
parents:
8366
diff
changeset
|
879 } \ |
445d27d79f4e
support permutation matrix objects
Jaroslav Hajek <highegg@gmail.com>
parents:
8366
diff
changeset
|
880 else \ |
8375
e3c9102431a9
fix design problems of diag & perm matrix classes
Jaroslav Hajek <highegg@gmail.com>
parents:
8367
diff
changeset
|
881 result = x.index (p.pvec (), idx_vector::colon); \ |
8367
445d27d79f4e
support permutation matrix objects
Jaroslav Hajek <highegg@gmail.com>
parents:
8366
diff
changeset
|
882 } \ |
445d27d79f4e
support permutation matrix objects
Jaroslav Hajek <highegg@gmail.com>
parents:
8366
diff
changeset
|
883 \ |
445d27d79f4e
support permutation matrix objects
Jaroslav Hajek <highegg@gmail.com>
parents:
8366
diff
changeset
|
884 return result; \ |
445d27d79f4e
support permutation matrix objects
Jaroslav Hajek <highegg@gmail.com>
parents:
8366
diff
changeset
|
885 } |
445d27d79f4e
support permutation matrix objects
Jaroslav Hajek <highegg@gmail.com>
parents:
8366
diff
changeset
|
886 |
445d27d79f4e
support permutation matrix objects
Jaroslav Hajek <highegg@gmail.com>
parents:
8366
diff
changeset
|
887 #define MPM_MULTIPLY_OP(M, PM) \ |
445d27d79f4e
support permutation matrix objects
Jaroslav Hajek <highegg@gmail.com>
parents:
8366
diff
changeset
|
888 M operator * (const M& x, const PM& p) \ |
445d27d79f4e
support permutation matrix objects
Jaroslav Hajek <highegg@gmail.com>
parents:
8366
diff
changeset
|
889 { \ |
445d27d79f4e
support permutation matrix objects
Jaroslav Hajek <highegg@gmail.com>
parents:
8366
diff
changeset
|
890 octave_idx_type nr = x.rows (), nc = x.columns (); \ |
445d27d79f4e
support permutation matrix objects
Jaroslav Hajek <highegg@gmail.com>
parents:
8366
diff
changeset
|
891 M result; \ |
445d27d79f4e
support permutation matrix objects
Jaroslav Hajek <highegg@gmail.com>
parents:
8366
diff
changeset
|
892 if (p.rows () != nc) \ |
445d27d79f4e
support permutation matrix objects
Jaroslav Hajek <highegg@gmail.com>
parents:
8366
diff
changeset
|
893 gripe_nonconformant ("operator *", nr, nc, p.rows (), p.columns ()); \ |
445d27d79f4e
support permutation matrix objects
Jaroslav Hajek <highegg@gmail.com>
parents:
8366
diff
changeset
|
894 else \ |
445d27d79f4e
support permutation matrix objects
Jaroslav Hajek <highegg@gmail.com>
parents:
8366
diff
changeset
|
895 { \ |
445d27d79f4e
support permutation matrix objects
Jaroslav Hajek <highegg@gmail.com>
parents:
8366
diff
changeset
|
896 if (p.is_col_perm ()) \ |
8375
e3c9102431a9
fix design problems of diag & perm matrix classes
Jaroslav Hajek <highegg@gmail.com>
parents:
8367
diff
changeset
|
897 result = x.index (idx_vector::colon, p.pvec ()); \ |
8367
445d27d79f4e
support permutation matrix objects
Jaroslav Hajek <highegg@gmail.com>
parents:
8366
diff
changeset
|
898 else \ |
445d27d79f4e
support permutation matrix objects
Jaroslav Hajek <highegg@gmail.com>
parents:
8366
diff
changeset
|
899 { \ |
445d27d79f4e
support permutation matrix objects
Jaroslav Hajek <highegg@gmail.com>
parents:
8366
diff
changeset
|
900 result = M (nr, nc); \ |
8375
e3c9102431a9
fix design problems of diag & perm matrix classes
Jaroslav Hajek <highegg@gmail.com>
parents:
8367
diff
changeset
|
901 result.assign (idx_vector::colon, p.pvec (), x); \ |
8367
445d27d79f4e
support permutation matrix objects
Jaroslav Hajek <highegg@gmail.com>
parents:
8366
diff
changeset
|
902 } \ |
445d27d79f4e
support permutation matrix objects
Jaroslav Hajek <highegg@gmail.com>
parents:
8366
diff
changeset
|
903 } \ |
445d27d79f4e
support permutation matrix objects
Jaroslav Hajek <highegg@gmail.com>
parents:
8366
diff
changeset
|
904 \ |
445d27d79f4e
support permutation matrix objects
Jaroslav Hajek <highegg@gmail.com>
parents:
8366
diff
changeset
|
905 return result; \ |
445d27d79f4e
support permutation matrix objects
Jaroslav Hajek <highegg@gmail.com>
parents:
8366
diff
changeset
|
906 } |
445d27d79f4e
support permutation matrix objects
Jaroslav Hajek <highegg@gmail.com>
parents:
8366
diff
changeset
|
907 |
445d27d79f4e
support permutation matrix objects
Jaroslav Hajek <highegg@gmail.com>
parents:
8366
diff
changeset
|
908 #define PMM_BIN_OPS(R, PM, M) \ |
445d27d79f4e
support permutation matrix objects
Jaroslav Hajek <highegg@gmail.com>
parents:
8366
diff
changeset
|
909 PMM_MULTIPLY_OP(PM, M); |
445d27d79f4e
support permutation matrix objects
Jaroslav Hajek <highegg@gmail.com>
parents:
8366
diff
changeset
|
910 |
445d27d79f4e
support permutation matrix objects
Jaroslav Hajek <highegg@gmail.com>
parents:
8366
diff
changeset
|
911 #define MPM_BIN_OPS(R, M, PM) \ |
445d27d79f4e
support permutation matrix objects
Jaroslav Hajek <highegg@gmail.com>
parents:
8366
diff
changeset
|
912 MPM_MULTIPLY_OP(M, PM); |
445d27d79f4e
support permutation matrix objects
Jaroslav Hajek <highegg@gmail.com>
parents:
8366
diff
changeset
|
913 |
8998
a48fba01e4ac
optimize isnan/isinf/isfinite mappers
Jaroslav Hajek <highegg@gmail.com>
parents:
8983
diff
changeset
|
914 #define NDND_MAPPER_BODY(R, NAME) \ |
a48fba01e4ac
optimize isnan/isinf/isfinite mappers
Jaroslav Hajek <highegg@gmail.com>
parents:
8983
diff
changeset
|
915 R retval (dims ()); \ |
a48fba01e4ac
optimize isnan/isinf/isfinite mappers
Jaroslav Hajek <highegg@gmail.com>
parents:
8983
diff
changeset
|
916 octave_idx_type n = numel (); \ |
a48fba01e4ac
optimize isnan/isinf/isfinite mappers
Jaroslav Hajek <highegg@gmail.com>
parents:
8983
diff
changeset
|
917 for (octave_idx_type i = 0; i < n; i++) \ |
a48fba01e4ac
optimize isnan/isinf/isfinite mappers
Jaroslav Hajek <highegg@gmail.com>
parents:
8983
diff
changeset
|
918 retval.xelem (i) = NAME (elem (i)); \ |
a48fba01e4ac
optimize isnan/isinf/isfinite mappers
Jaroslav Hajek <highegg@gmail.com>
parents:
8983
diff
changeset
|
919 return retval; |
a48fba01e4ac
optimize isnan/isinf/isfinite mappers
Jaroslav Hajek <highegg@gmail.com>
parents:
8983
diff
changeset
|
920 |
8774
b756ce0002db
split implementation and interface in mx-op-defs and MArray-defs
Jaroslav Hajek <highegg@gmail.com>
parents:
8397
diff
changeset
|
921 #endif |
b756ce0002db
split implementation and interface in mx-op-defs and MArray-defs
Jaroslav Hajek <highegg@gmail.com>
parents:
8397
diff
changeset
|
922 |
7189 | 923 |
2829 | 924 /* |
925 ;;; Local Variables: *** | |
926 ;;; mode: C++ *** | |
927 ;;; End: *** | |
928 */ |