Matrix r5059
Loading...
Searching...
No Matches
M5.h
Go to the documentation of this file.
1#ifndef MATRIX_M5_H
2#define MATRIX_M5_H
3
4#include <R_ext/Error.h>
5
6#define nTYPE int
7#define lTYPE int
8#define iTYPE int
9#define dTYPE double
10#define zTYPE Rcomplex
11
12#define nTYPESXP LGLSXP
13#define lTYPESXP LGLSXP
14#define iTYPESXP INTSXP
15#define dTYPESXP REALSXP
16#define zTYPESXP CPLXSXP
17
18#define nPTR LOGICAL
19#define lPTR LOGICAL
20#define iPTR INTEGER
21#define dPTR REAL
22#define zPTR COMPLEX
23
24#define nZERO 0
25#define lZERO 0
26#define iZERO 0
27#define dZERO 0.0
28#define zZERO Matrix_zzero
29
30#define nUNIT 1
31#define lUNIT 1
32#define iUNIT 1
33#define dUNIT 1.0
34#define zUNIT Matrix_zunit
35
36#define nNA 1
37#define lNA NA_LOGICAL
38#define iNA NA_INTEGER
39#define dNA NA_REAL
40#define zNA Matrix_zna
41
42#define nNAME(s) i ## s
43#define lNAME(s) i ## s
44#define iNAME(s) i ## s
45#define dNAME(s) d ## s
46#define zNAME(s) z ## s
47
48#define nIF_NPATTERN(...)
49#define lIF_NPATTERN(...) __VA_ARGS__
50#define iIF_NPATTERN(...) __VA_ARGS__
51#define dIF_NPATTERN(...) __VA_ARGS__
52#define zIF_NPATTERN(...) __VA_ARGS__
53
54#define nIFELSE_NPATTERN(x, y) y
55#define lIFELSE_NPATTERN(x, y) x
56#define iIFELSE_NPATTERN(x, y) x
57#define dIFELSE_NPATTERN(x, y) x
58#define zIFELSE_NPATTERN(x, y) x
59
60#define nNOT_ZERO(x) ((x) != 0)
61#define lNOT_ZERO(x) ((x) != 0)
62#define iNOT_ZERO(x) ((x) != 0)
63#define dNOT_ZERO(x) ((x) != 0.0)
64#define zNOT_ZERO(x) ((x).r != 0.0 || (x).i != 0.0)
65
66#define nNOT_ZERO_REAL(x) ((x) != 0)
67#define lNOT_ZERO_REAL(x) ((x) != 0)
68#define iNOT_ZERO_REAL(x) ((x) != 0)
69#define dNOT_ZERO_REAL(x) ((x) != 0.0)
70#define zNOT_ZERO_REAL(x) ((x).r != 0.0)
71
72#define nNOT_ZERO_IMAG(x) (0)
73#define lNOT_ZERO_IMAG(x) (0)
74#define iNOT_ZERO_IMAG(x) (0)
75#define dNOT_ZERO_IMAG(x) (0)
76#define zNOT_ZERO_IMAG(x) ((x).i != 0.0)
77
78#define nNOT_ZERO_TOL(x, tol) ((x) != 0)
79#define lNOT_ZERO_TOL(x, tol) ((x) != 0)
80#define iNOT_ZERO_TOL(x, tol) ((x) != 0)
81#define dNOT_ZERO_TOL(x, tol) (ISNAN(x) || fabs(x) > tol)
82#define zNOT_ZERO_TOL(x, tol) (ISNAN((x).r) || ISNAN((x).i) || hypot((x).r, (x).i) > tol)
83
84#define nNOT_UNIT(x) ((x) == 0)
85#define lNOT_UNIT(x) ((x) == 0 || (x) == NA_LOGICAL)
86#define iNOT_UNIT(x) ((x) != 1)
87#define dNOT_UNIT(x) ((x) != 1.0)
88#define zNOT_UNIT(x) ((x).r != 1.0 || (x).i != 0.0)
89
90#define nNOT_NA(x) (1)
91#define lNOT_NA(x) ((x) != NA_LOGICAL)
92#define iNOT_NA(x) ((x) != NA_INTEGER)
93#define dNOT_NA(x) (!ISNAN(x))
94#define zNOT_NA(x) (!ISNAN((x).r) && !ISNAN((x).i))
95
96#define nNOT_IDEN(x, y) \
97 (((x) != 0) != ((y) != 0))
98#define lNOT_IDEN(x, y) \
99 ((x) != (y))
100#define iNOT_IDEN(x, y) \
101 ((x) != (y))
102#define dNOT_IDEN(x, y) \
103 ((ISNAN(x)) ? !ISNAN(y) : ISNAN(y) || (x) != (y))
104#define zNOT_IDEN(x, y) \
105 (((ISNAN((x).r)) ? !ISNAN((y).r) : ISNAN((y).r) || (x).r != (y).r) || \
106 ((ISNAN((x).i)) ? !ISNAN((y).i) : ISNAN((y).i) || (x).i != (y).i))
107
108#define nNOT_CONJ(x, y) \
109 ((x != 0) != (y != 0))
110#define lNOT_CONJ(x, y) \
111 (x != y)
112#define iNOT_CONJ(x, y) \
113 (x != y)
114#define dNOT_CONJ(x, y) \
115 ((ISNAN(x)) ? !ISNAN(y) : ISNAN(y) || x != y)
116#define zNOT_CONJ(x, y) \
117 (((ISNAN((x).r)) ? !ISNAN((y).r) : ISNAN((y).r) || (x).r != (y).r) || \
118 ((ISNAN((x).i)) ? !ISNAN((y).i) : ISNAN((y).i) || (x).i != -(y).i))
119
120#define nSET_ZERO(x) ((x) = 0)
121#define lSET_ZERO(x) ((x) = 0)
122#define iSET_ZERO(x) ((x) = 0)
123#define dSET_ZERO(x) ((x) = 0.0)
124#define zSET_ZERO(x) ((x) = Matrix_zzero)
125
126#define nSET_UNIT(x) ((x) = 1)
127#define lSET_UNIT(x) ((x) = 1)
128#define iSET_UNIT(x) ((x) = 1)
129#define dSET_UNIT(x) ((x) = 1.0)
130#define zSET_UNIT(x) ((x) = Matrix_zunit)
131
132#define nSET_NA(x) ((x) = 1)
133#define lSET_NA(x) ((x) = NA_LOGICAL)
134#define iSET_NA(x) ((x) = NA_INTEGER)
135#define dSET_NA(x) ((x) = NA_REAL)
136#define zSET_NA(x) ((x) = Matrix_zna)
137
138#define nSET_IDEN(x)
139#define lSET_IDEN(x)
140#define iSET_IDEN(x)
141#define dSET_IDEN(x)
142#define zSET_IDEN(x)
143
144#define nSET_CONJ(x)
145#define lSET_CONJ(x)
146#define iSET_CONJ(x)
147#define dSET_CONJ(x)
148#define zSET_CONJ(x) ((x).i = -(x).i)
149
150#define nSET_PROJ_REAL(x)
151#define lSET_PROJ_REAL(x)
152#define iSET_PROJ_REAL(x)
153#define dSET_PROJ_REAL(x)
154#define zSET_PROJ_REAL(x) ((x).i = 0.0)
155
156#define nSET_PROJ_IMAG(x) ((x) = 0)
157#define lSET_PROJ_IMAG(x) ((x) = 0)
158#define iSET_PROJ_IMAG(x) ((x) = 0)
159#define dSET_PROJ_IMAG(x) ((x) = 0.0)
160#define zSET_PROJ_IMAG(x) ((x).r = 0.0)
161
162#define nASSIGN_IDEN(x, y) ((x) = (y))
163#define lASSIGN_IDEN(x, y) ((x) = (y))
164#define iASSIGN_IDEN(x, y) ((x) = (y))
165#define dASSIGN_IDEN(x, y) ((x) = (y))
166#define zASSIGN_IDEN(x, y) ((x) = (y))
167
168#define nASSIGN_CONJ(x, y) ((x) = (y))
169#define lASSIGN_CONJ(x, y) ((x) = (y))
170#define iASSIGN_CONJ(x, y) ((x) = (y))
171#define dASSIGN_CONJ(x, y) ((x) = (y))
172#define zASSIGN_CONJ(x, y) ((x).r = (y).r, (x).i = -(y).i)
173
174#define nASSIGN_PROJ_REAL(x, y) ((x) = (y))
175#define lASSIGN_PROJ_REAL(x, y) ((x) = (y))
176#define iASSIGN_PROJ_REAL(x, y) ((x) = (y))
177#define dASSIGN_PROJ_REAL(x, y) ((x) = (y))
178#define zASSIGN_PROJ_REAL(x, y) ((x).r = (y).r, (x).i = 0.0)
179
180#define nASSIGN_PROJ_IMAG(x, y) ((x) = 0)
181#define lASSIGN_PROJ_IMAG(x, y) ((x) = 0)
182#define iASSIGN_PROJ_IMAG(x, y) ((x) = 0)
183#define dASSIGN_PROJ_IMAG(x, y) ((x) = 0.0)
184#define zASSIGN_PROJ_IMAG(x, y) ((x).r = 0.0, (x).i = (y).i)
185
186#define nINCREMENT_IDEN(x, y) \
187 do { \
188 (x) = 1; \
189 } while (0)
190#define lINCREMENT_IDEN(x, y) \
191 do { \
192 if ((y) == NA_LOGICAL) { \
193 if ((x) == 0) \
194 (x) = NA_LOGICAL; \
195 } \
196 else if ((y) != 0) \
197 (x) = 1; \
198 } while (0)
199#define iINCREMENT_IDEN(x, y) \
200 do { \
201 if ((x) != NA_INTEGER) { \
202 if ((y) == NA_INTEGER) \
203 (x) = NA_INTEGER; \
204 else if ((y) != 0) { \
205 if (((y) > 0) \
206 ? ((x) > INT_MAX - (y)) \
207 : ((x) <= INT_MIN - (y))) { \
208 Rf_warning(_("NAs produced by integer overflow")); \
209 (x) = NA_INTEGER; \
210 } \
211 else \
212 (x) += (y); \
213 } \
214 } \
215 } while (0)
216#define dINCREMENT_IDEN(x, y) \
217 do { \
218 (x) += (y); \
219 } while (0)
220#define zINCREMENT_IDEN(x, y) \
221 do { \
222 (x).r += (y).r; \
223 (x).i += (y).i; \
224 } while (0)
225
226#define nINCREMENT_CONJ(x, y) nINCREMENT_IDEN(x, y)
227#define lINCREMENT_CONJ(x, y) lINCREMENT_IDEN(x, y)
228#define iINCREMENT_CONJ(x, y) iINCREMENT_IDEN(x, y)
229#define dINCREMENT_CONJ(x, y) dINCREMENT_IDEN(x, y)
230#define zINCREMENT_CONJ(x, y) do { (x).r += (y).r; (x).i -= (y).i; } while (0)
231
232#define nDECREMENT_IDEN(x, y)
233#define lDECREMENT_IDEN(x, y) \
234 do { \
235 if ((y) == NA_LOGICAL) { \
236 if ((x) == 0) \
237 (x) = NA_LOGICAL; \
238 } \
239 else if ((y) == 0) \
240 (x) = 1; \
241 } while (0)
242#define iDECREMENT_IDEN(x, y) \
243 do { \
244 if ((x) != NA_INTEGER) { \
245 if ((y) == NA_INTEGER) \
246 (x) = NA_INTEGER; \
247 else if ((y) != 0) { \
248 if (((y) < 0) \
249 ? ((x) > INT_MAX + (y)) \
250 : ((x) <= INT_MIN + (y))) { \
251 Rf_warning(_("NAs produced by integer overflow")); \
252 (x) = NA_INTEGER; \
253 } \
254 else \
255 (x) -= (y); \
256 } \
257 } \
258 } while (0)
259#define dDECREMENT_IDEN(x, y) \
260 do { \
261 (x) -= (y); \
262 } while (0)
263#define zDECREMENT_IDEN(x, y) \
264 do { \
265 (x).r -= (y).r; \
266 (x).i -= (y).i; \
267 } while (0)
268
269#define nDECREMENT_CONJ(x, y) nDECREMENT_IDEN(x, y)
270#define lDECREMENT_CONJ(x, y) lDECREMENT_IDEN(x, y)
271#define iDECREMENT_CONJ(x, y) iDECREMENT_IDEN(x, y)
272#define dDECREMENT_CONJ(x, y) dDECREMENT_IDEN(x, y)
273#define zDECREMENT_CONJ(x, y) do { (x).r -= (y).r; (x).i += (y).i; } while (0)
274
275#define nMULTIPLY(x, a) /* unused hence no-op for now */
276#define lMULTIPLY(x, a) /* ditto */
277#define iMULTIPLY(x, a) /* ditto */
278#define dMULTIPLY(x, a) \
279 do { (x) *= a; } while (0)
280#define zMULTIPLY(x, a) \
281 do { (x).r *= a; (x).i *= a; } while (0)
282
283#define nDIVIDE(x, a) /* unused hence no-op for now */
284#define lDIVIDE(x, a) /* ditto */
285#define iDIVIDE(x, a) /* ditto */
286#define dDIVIDE(x, a) \
287 do { (x) /= a; } while (0)
288#define zDIVIDE(x, a) \
289 do { (x).r /= a; (x).i /= a; } while (0)
290
291#define SWITCH2(c, template) \
292do { \
293 switch ((c)) { \
294 case 'n': \
295 case 'l': \
296 case 'i': \
297 case 'd': template(d); break; \
298 case 'z': template(z); break; \
299 default: break; \
300 } \
301} while (0)
302
303#define SWITCH3(c, template) \
304do { \
305 switch ((c)) { \
306 case 'n': \
307 case 'l': \
308 case 'i': template(i); break; \
309 case 'd': template(d); break; \
310 case 'z': template(z); break; \
311 default: break; \
312 } \
313} while (0)
314
315#define SWITCH4(c, template) \
316do { \
317 switch ((c)) { \
318 case 'n': \
319 case 'l': template(l); break; \
320 case 'i': template(i); break; \
321 case 'd': template(d); break; \
322 case 'z': template(z); break; \
323 default: break; \
324 } \
325} while (0)
326
327#define SWITCH5(c, template) \
328do { \
329 switch ((c)) { \
330 case 'n': template(n); break; \
331 case 'l': template(l); break; \
332 case 'i': template(i); break; \
333 case 'd': template(d); break; \
334 case 'z': template(z); break; \
335 default: break; \
336 } \
337} while (0)
338
339#endif /* MATRIX_M5_H */