1 ////////////////////////////////////////////////////////////////////////
2 //
3 // Copyright (C) 1996-2021 The Octave Project Developers
4 //
5 // See the file COPYRIGHT.md in the top-level directory of this
6 // distribution or <https://octave.org/copyright/>.
7 //
8 // This file is part of Octave.
9 //
10 // Octave is free software: you can redistribute it and/or modify it
11 // under the terms of the GNU General Public License as published by
12 // the Free Software Foundation, either version 3 of the License, or
13 // (at your option) any later version.
14 //
15 // Octave is distributed in the hope that it will be useful, but
16 // WITHOUT ANY WARRANTY; without even the implied warranty of
17 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18 // GNU General Public License for more details.
19 //
20 // You should have received a copy of the GNU General Public License
21 // along with Octave; see the file COPYING.  If not, see
22 // <https://www.gnu.org/licenses/>.
23 //
24 ////////////////////////////////////////////////////////////////////////
25 
26 #if ! defined (octave_mx_op_decl_h)
27 #define octave_mx_op_decl_h 1
28 
29 #include "octave-config.h"
30 
31 #define BIN_OP_DECL(R, OP, X, Y, API)           \
32   extern API R OP (const X&, const Y&)
33 
34 class boolMatrix;
35 class boolNDArray;
36 
37 #define CMP_OP_DECL(OP, X, Y, API)              \
38   extern API boolMatrix OP (const X&, const Y&)
39 
40 #define NDCMP_OP_DECL(OP, X, Y, API)                    \
41   extern API boolNDArray OP (const X&, const Y&)
42 
43 #define BOOL_OP_DECL(OP, X, Y, API)             \
44   extern API boolMatrix OP (const X&, const Y&)
45 
46 #define NDBOOL_OP_DECL(OP, X, Y, API)                   \
47   extern API boolNDArray OP (const X&, const Y&)
48 
49 // vector by scalar operations.
50 
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);
56 
57 #define VS_OP_DECLS(R, V, S, API)               \
58   VS_BIN_OP_DECLS(R, V, S, API)
59 
60 // scalar by vector by operations.
61 
62 #define SV_BIN_OP_DECLS(R, S, V, API)           \
63   BIN_OP_DECL (R, operator +, S, V, API);       \
64   BIN_OP_DECL (R, operator -, S, V, API);       \
65   BIN_OP_DECL (R, operator *, S, V, API);       \
66   BIN_OP_DECL (R, operator /, S, V, API);
67 
68 #define SV_OP_DECLS(R, S, V, API)               \
69   SV_BIN_OP_DECLS(R, S, V, API)
70 
71 // vector by vector operations.
72 
73 #define VV_BIN_OP_DECLS(R, V1, V2, API)         \
74   BIN_OP_DECL (R, operator +, V1, V2, API);     \
75   BIN_OP_DECL (R, operator -, V1, V2, API);     \
76   BIN_OP_DECL (R, product,    V1, V2, API);     \
77   BIN_OP_DECL (R, quotient,   V1, V2, API);
78 
79 #define VV_OP_DECLS(R, V1, V2, API)             \
80   VV_BIN_OP_DECLS(R, V1, V2, API)
81 
82 // matrix by scalar operations.
83 
84 #define MS_BIN_OP_DECLS(R, M, S, API)           \
85   BIN_OP_DECL (R, operator +, M, S, API);       \
86   BIN_OP_DECL (R, operator -, M, S, API);       \
87   BIN_OP_DECL (R, operator *, M, S, API);       \
88   BIN_OP_DECL (R, operator /, M, S, API);
89 
90 #define MS_CMP_OP_DECLS(M, S, API)              \
91   CMP_OP_DECL (mx_el_lt, M, S, API);            \
92   CMP_OP_DECL (mx_el_le, M, S, API);            \
93   CMP_OP_DECL (mx_el_ge, M, S, API);            \
94   CMP_OP_DECL (mx_el_gt, M, S, API);            \
95   CMP_OP_DECL (mx_el_eq, M, S, API);            \
96   CMP_OP_DECL (mx_el_ne, M, S, API);
97 
98 #define MS_BOOL_OP_DECLS(M, S, API)             \
99   BOOL_OP_DECL (mx_el_and, M, S, API);          \
100   BOOL_OP_DECL (mx_el_or,  M, S, API);          \
101 
102 #define MS_OP_DECLS(R, M, S, API)               \
103   MS_BIN_OP_DECLS (R, M, S, API)                \
104   MS_CMP_OP_DECLS (M, S, API)                   \
105   MS_BOOL_OP_DECLS (M, S, API)                  \
106 
107 // scalar by matrix operations.
108 
109 #define SM_BIN_OP_DECLS(R, S, M, API)           \
110   BIN_OP_DECL (R, operator +, S, M, API);       \
111   BIN_OP_DECL (R, operator -, S, M, API);       \
112   BIN_OP_DECL (R, operator *, S, M, API);       \
113   BIN_OP_DECL (R, operator /, S, M, API);
114 
115 #define SM_CMP_OP_DECLS(S, M, API)              \
116   CMP_OP_DECL (mx_el_lt, S, M, API);            \
117   CMP_OP_DECL (mx_el_le, S, M, API);            \
118   CMP_OP_DECL (mx_el_ge, S, M, API);            \
119   CMP_OP_DECL (mx_el_gt, S, M, API);            \
120   CMP_OP_DECL (mx_el_eq, S, M, API);            \
121   CMP_OP_DECL (mx_el_ne, S, M, API);
122 
123 #define SM_BOOL_OP_DECLS(S, M, API)             \
124   BOOL_OP_DECL (mx_el_and, S, M, API);          \
125   BOOL_OP_DECL (mx_el_or,  S, M, API);          \
126 
127 #define SM_OP_DECLS(R, S, M, API)               \
128   SM_BIN_OP_DECLS (R, S, M, API)                \
129   SM_CMP_OP_DECLS (S, M, API)                   \
130   SM_BOOL_OP_DECLS (S, M, API)                  \
131 
132 // matrix by matrix operations.
133 
134 #define MM_BIN_OP_DECLS(R, M1, M2, API)         \
135   BIN_OP_DECL (R, operator +, M1, M2, API);     \
136   BIN_OP_DECL (R, operator -, M1, M2, API);     \
137   BIN_OP_DECL (R, product,    M1, M2, API);     \
138   BIN_OP_DECL (R, quotient,   M1, M2, API);
139 
140 #define MM_CMP_OP_DECLS(M1, M2, API)            \
141   CMP_OP_DECL (mx_el_lt, M1, M2, API);          \
142   CMP_OP_DECL (mx_el_le, M1, M2, API);          \
143   CMP_OP_DECL (mx_el_ge, M1, M2, API);          \
144   CMP_OP_DECL (mx_el_gt, M1, M2, API);          \
145   CMP_OP_DECL (mx_el_eq, M1, M2, API);          \
146   CMP_OP_DECL (mx_el_ne, M1, M2, API);
147 
148 #define MM_BOOL_OP_DECLS(M1, M2, API)           \
149   BOOL_OP_DECL (mx_el_and, M1, M2, API);        \
150   BOOL_OP_DECL (mx_el_or,  M1, M2, API);
151 
152 #define MM_OP_DECLS(R, M1, M2, API)             \
153   MM_BIN_OP_DECLS (R, M1, M2, API)              \
154   MM_CMP_OP_DECLS (M1, M2, API)                 \
155   MM_BOOL_OP_DECLS (M1, M2, API)
156 
157 // N-D matrix by scalar operations.
158 
159 #define NDS_BIN_OP_DECLS(R, ND, S, API)         \
160   BIN_OP_DECL (R, operator +, ND, S, API);      \
161   BIN_OP_DECL (R, operator -, ND, S, API);      \
162   BIN_OP_DECL (R, operator *, ND, S, API);      \
163   BIN_OP_DECL (R, operator /, ND, S, API);
164 
165 #define NDS_CMP_OP_DECLS(ND, S, API)            \
166   NDCMP_OP_DECL (mx_el_lt, ND, S, API);         \
167   NDCMP_OP_DECL (mx_el_le, ND, S, API);         \
168   NDCMP_OP_DECL (mx_el_ge, ND, S, API);         \
169   NDCMP_OP_DECL (mx_el_gt, ND, S, API);         \
170   NDCMP_OP_DECL (mx_el_eq, ND, S, API);         \
171   NDCMP_OP_DECL (mx_el_ne, ND, S, API);
172 
173 #define NDS_BOOL_OP_DECLS(ND, S, API)           \
174   NDBOOL_OP_DECL (mx_el_and, ND, S, API);       \
175   NDBOOL_OP_DECL (mx_el_or,  ND, S, API);       \
176   NDBOOL_OP_DECL (mx_el_not_and, ND, S, API);   \
177   NDBOOL_OP_DECL (mx_el_not_or,  ND, S, API);
178 
179 #define NDS_OP_DECLS(R, ND, S, API)             \
180   NDS_BIN_OP_DECLS (R, ND, S, API)              \
181   NDS_CMP_OP_DECLS (ND, S, API)                 \
182   NDS_BOOL_OP_DECLS (ND, S, API)
183 
184 // scalar by N-D matrix operations.
185 
186 #define SND_BIN_OP_DECLS(R, S, ND, API)         \
187   BIN_OP_DECL (R, operator +, S, ND, API);      \
188   BIN_OP_DECL (R, operator -, S, ND, API);      \
189   BIN_OP_DECL (R, operator *, S, ND, API);      \
190   BIN_OP_DECL (R, operator /, S, ND, API);
191 
192 #define SND_CMP_OP_DECLS(S, ND, API)            \
193   NDCMP_OP_DECL (mx_el_lt, S, ND, API);         \
194   NDCMP_OP_DECL (mx_el_le, S, ND, API);         \
195   NDCMP_OP_DECL (mx_el_ge, S, ND, API);         \
196   NDCMP_OP_DECL (mx_el_gt, S, ND, API);         \
197   NDCMP_OP_DECL (mx_el_eq, S, ND, API);         \
198   NDCMP_OP_DECL (mx_el_ne, S, ND, API);
199 
200 #define SND_BOOL_OP_DECLS(S, ND, API)           \
201   NDBOOL_OP_DECL (mx_el_and, S, ND, API);       \
202   NDBOOL_OP_DECL (mx_el_or,  S, ND, API);       \
203   NDBOOL_OP_DECL (mx_el_and_not, S, ND, API);   \
204   NDBOOL_OP_DECL (mx_el_or_not,  S, ND, API);
205 
206 #define SND_OP_DECLS(R, S, ND, API)             \
207   SND_BIN_OP_DECLS (R, S, ND, API)              \
208   SND_CMP_OP_DECLS (S, ND, API)                 \
209   SND_BOOL_OP_DECLS (S, ND, API)
210 
211 // N-D matrix by N-D matrix operations.
212 
213 #define NDND_BIN_OP_DECLS(R, ND1, ND2, API)     \
214   BIN_OP_DECL (R, operator +, ND1, ND2, API);   \
215   BIN_OP_DECL (R, operator -, ND1, ND2, API);   \
216   BIN_OP_DECL (R, product,    ND1, ND2, API);   \
217   BIN_OP_DECL (R, quotient,   ND1, ND2, API);
218 
219 #define NDND_CMP_OP_DECLS(ND1, ND2, API)        \
220   NDCMP_OP_DECL (mx_el_lt, ND1, ND2, API);      \
221   NDCMP_OP_DECL (mx_el_le, ND1, ND2, API);      \
222   NDCMP_OP_DECL (mx_el_ge, ND1, ND2, API);      \
223   NDCMP_OP_DECL (mx_el_gt, ND1, ND2, API);      \
224   NDCMP_OP_DECL (mx_el_eq, ND1, ND2, API);      \
225   NDCMP_OP_DECL (mx_el_ne, ND1, ND2, API);
226 
227 #define NDND_BOOL_OP_DECLS(ND1, ND2, API)               \
228   NDBOOL_OP_DECL (mx_el_and, ND1, ND2, API);            \
229   NDBOOL_OP_DECL (mx_el_or,  ND1, ND2, API);            \
230   NDBOOL_OP_DECL (mx_el_and_not, ND1, ND2, API);        \
231   NDBOOL_OP_DECL (mx_el_or_not,  ND1, ND2, API);        \
232   NDBOOL_OP_DECL (mx_el_not_and, ND1, ND2, API);        \
233   NDBOOL_OP_DECL (mx_el_not_or,  ND1, ND2, API);
234 
235 #define NDND_OP_DECLS(R, ND1, ND2, API)         \
236   NDND_BIN_OP_DECLS (R, ND1, ND2, API)          \
237   NDND_CMP_OP_DECLS (ND1, ND2, API)             \
238   NDND_BOOL_OP_DECLS (ND1, ND2, API)
239 
240 // scalar by diagonal matrix operations.
241 
242 #define SDM_BIN_OP_DECLS(R, S, DM, API)         \
243   BIN_OP_DECL (R, operator *, S, DM, API);      \
244 
245 #define SDM_OP_DECLS(R, S, DM, API)             \
246   SDM_BIN_OP_DECLS(R, S, DM, API)
247 
248 // diagonal matrix by scalar operations.
249 
250 #define DMS_BIN_OP_DECLS(R, DM, S, API)         \
251   BIN_OP_DECL (R, operator *, DM, S, API);      \
252   BIN_OP_DECL (R, operator /, DM, S, API);
253 
254 #define DMS_OP_DECLS(R, DM, S, API)             \
255   DMS_BIN_OP_DECLS(R, DM, S, API)
256 
257 // matrix by diagonal matrix operations.
258 
259 #define MDM_BIN_OP_DECLS(R, M, DM, API)         \
260   BIN_OP_DECL (R, operator +, M, DM, API);      \
261   BIN_OP_DECL (R, operator -, M, DM, API);      \
262   BIN_OP_DECL (R, operator *, M, DM, API);
263 
264 #define MDM_OP_DECLS(R, M, DM, API)             \
265   MDM_BIN_OP_DECLS(R, M, DM, API)
266 
267 // diagonal matrix by matrix operations.
268 
269 #define DMM_BIN_OP_DECLS(R, DM, M, API)         \
270   BIN_OP_DECL (R, operator +, DM, M, API);      \
271   BIN_OP_DECL (R, operator -, DM, M, API);      \
272   BIN_OP_DECL (R, operator *, DM, M, API);
273 
274 #define DMM_OP_DECLS(R, DM, M, API)             \
275   DMM_BIN_OP_DECLS(R, DM, M, API)
276 
277 // diagonal matrix by diagonal matrix operations.
278 
279 #define DMDM_BIN_OP_DECLS(R, DM1, DM2, API)     \
280   BIN_OP_DECL (R, operator +, DM1, DM2, API);   \
281   BIN_OP_DECL (R, operator -, DM1, DM2, API);   \
282   BIN_OP_DECL (R, product, DM1, DM2, API);
283 
284 #define DMDM_OP_DECLS(R, DM1, DM2, API)         \
285   DMDM_BIN_OP_DECLS (R, DM1, DM2, API)
286 
287 // scalar by N-D array min/max ops
288 
289 #define MINMAX_DECLS(T, S, API)                 \
290   extern API T min (S d, const T& m);           \
291   extern API T min (const T& m, S d);           \
292   extern API T min (const T& a, const T& b);    \
293   extern API T max (S d, const T& m);           \
294   extern API T max (const T& m, S d);           \
295   extern API T max (const T& a, const T& b);
296 
297 // permutation matrix by matrix ops and vice versa
298 
299 #define PMM_BIN_OP_DECLS(R, PM, M, API)         \
300   BIN_OP_DECL (R, operator *, PM, M, API);
301 
302 #define MPM_BIN_OP_DECLS(R, M, PM, API)         \
303   BIN_OP_DECL (R, operator *, M, PM, API);
304 
305 #endif
306