Loading...
Searching...
No Matches
Go to the documentation of this file.
5TEMPLATE(i, int, 0 , 1 ) \
6TEMPLATE(d, double, 0.0, 1.0) \
7TEMPLATE(z, Rcomplex, Matrix_zzero, Matrix_zone)
9#define TEMPLATE(_PREFIX_, _CTYPE_, _ZERO_, _ONE_) \
10static void _PREFIX_ ## \
11swap(int n, _CTYPE_ *x, int incx, _CTYPE_ *y, int incy) \
26#define TEMPLATE(_PREFIX_, _CTYPE_, _ZERO_, _ONE_) \
27static void _PREFIX_ ## \
28syswapr(char uplo, int n, _CTYPE_ *x, int k0, int k1) \
30 _CTYPE_ *x0 = x + (R_xlen_t) k0 * n, *x1 = x + (R_xlen_t) k1 * n, \
33 _PREFIX_ ## swap(k0, x0, 1, x1, 1); \
37 _PREFIX_ ## swap(k1 - k0 - 1, x0 + k0 + n, n, x1 + k0 + 1, 1); \
38 _PREFIX_ ## swap(n - k1 - 1, x1 + k0 + n, n, x1 + k1 + n, n); \
40 _PREFIX_ ## swap(k0, x + k0, n, x + k1, n); \
44 _PREFIX_ ## swap(k1 - k0 - 1, x0 + k0 + 1, 1, x0 + k1 + n, n); \
45 _PREFIX_ ## swap(n - k1 - 1, x0 + k1 + 1, 1, x1 + k1 + 1, 1); \
52#define TEMPLATE(_PREFIX_, _CTYPE_, _ZERO_, _ONE_) \
54rowperm2(_CTYPE_ *x, int m, int n, int *p, int off, int invert) \
57 for (i = 0; i < m; ++i) \
58 p[i] = -(p[i] - off + 1); \
60 for (i = 0; i < m; ++i) { \
67 _PREFIX_ ## swap(n, x + k0, m, x + k1, m); \
74 for (i = 0; i < m; ++i) { \
81 _PREFIX_ ## swap(n, x + k0, m, x + k1, m); \
87 for (i = 0; i < m; ++i) \
88 p[i] = p[i] + off - 1; \
94#define TEMPLATE(_PREFIX_, _CTYPE_, _ZERO_, _ONE_) \
96symperm2(_CTYPE_ *x, int n, char uplo, int *p, int off, int invert) \
99 for (i = 0; i < n; ++i) \
100 p[i] = -(p[i] - off + 1); \
102 for (i = 0; i < n; ++i) { \
108 while (p[k1] < 0) { \
110 _PREFIX_ ## syswapr(uplo, n, x, k0, k1); \
112 _PREFIX_ ## syswapr(uplo, n, x, k1, k0); \
119 for (i = 0; i < n; ++i) { \
127 _PREFIX_ ## syswapr(uplo, n, x, k0, k1); \
129 _PREFIX_ ## syswapr(uplo, n, x, k1, k0); \
135 for (i = 0; i < n; ++i) \
136 p[i] = p[i] + off - 1; \
142#define TEMPLATE(_PREFIX_, _CTYPE_, _ZERO_, _ONE_) \
144pack2(_CTYPE_ *dest, const _CTYPE_ *src, int n, char uplo, char diag) \
147 R_xlen_t dpos = 0, spos = 0; \
149 for (j = 0; j < n; spos += n-(++j)) \
150 for (i = 0; i <= j; ++i) \
151 dest[dpos++] = src[spos++]; \
154 for (j = 0; j < n; dpos += (++j)+1) \
155 dest[dpos] = _ONE_; \
158 for (j = 0; j < n; spos += (++j)) \
159 for (i = j; i < n; ++i) \
160 dest[dpos++] = src[spos++]; \
163 for (j = 0; j < n; dpos += n-(j++)) \
164 dest[dpos] = _ONE_; \
172#define TEMPLATE(_PREFIX_, _CTYPE_, _ZERO_, _ONE_) \
174unpack1(_CTYPE_ *dest, const _CTYPE_ *src, int n, char uplo, char diag) \
177 R_xlen_t dpos = 0, spos = 0; \
179 for (j = 0; j < n; dpos += n-(++j)) \
180 for (i = 0; i <= j; ++i) \
181 dest[dpos++] = src[spos++]; \
183 for (j = 0; j < n; dpos += (++j)) \
184 for (i = j; i < n; ++i) \
185 dest[dpos++] = src[spos++]; \
189 R_xlen_t n1a = (R_xlen_t) n + 1; \
190 for (j = 0; j < n; ++j, dpos += n1a) \
191 dest[dpos] = _ONE_; \
198#define TEMPLATE(_PREFIX_, _CTYPE_, _ZERO_, _ONE_) \
200transpose2(_CTYPE_ *dest, const _CTYPE_ *src, int m, int n) \
202 R_xlen_t mn1s = (R_xlen_t) m * n - 1; \
204 for (j = 0; j < m; ++j, src -= mn1s) \
205 for (i = 0; i < n; ++i, src += m) \
212#define TEMPLATE(_PREFIX_, _CTYPE_, _ZERO_, _ONE_) \
214transpose1(_CTYPE_ *dest, const _CTYPE_ *src, int n, char uplo) \
218 for (j = 0; j < n; ++j) \
219 for (i = j; i < n; ++i) \
220 *(dest++) = *(src + PACKED_AR21_UP(j, i)); \
222 R_xlen_t n2 = (R_xlen_t) n * 2; \
223 for (j = 0; j < n; ++j) \
224 for (i = 0; i <= j; ++i) \
225 *(dest++) = *(src + PACKED_AR21_LO(j, i, n2)); \
232#define ASSIGN_JJ_i(_X_)
233#define ASSIGN_JJ_d(_X_)
234#define ASSIGN_JJ_z(_X_) \
236#define ASSIGN_JI_i(_X_, _Y_) \
238#define ASSIGN_JI_d(_X_, _Y_) \
240#define ASSIGN_JI_z(_X_, _Y_) \
246#define TEMPLATE(_PREFIX_, _CTYPE_, _ZERO_, _ONE_) \
248syforce2(_CTYPE_ *x, int n, char uplo) \
253 for (j = 0; j < n; ++j) { \
254 ASSIGN_JJ_ ## _PREFIX_((*x)); \
257 for (i = j + 1; i < n; ++i) { \
258 ASSIGN_JI_ ## _PREFIX_((*x), (*y)); \
265 for (j = 0; j < n; ++j) { \
266 ASSIGN_JJ_ ## _PREFIX_((*y)); \
269 for (i = j + 1; i < n; ++i) { \
270 ASSIGN_JI_ ## _PREFIX_((*y), (*x)); \
289#define TEMPLATE(_PREFIX_, _CTYPE_, _ZERO_, _ONE_) \
291trforce2(_CTYPE_ *x, int m, int n, char uplo, char diag) \
294 int i, j, r = (m < n) ? m : n; \
296 for (j = 0; j < r; ++j) { \
297 for (i = j + 1; i < m; ++i) \
302 for (j = 0; j < r; ++j) { \
303 for (i = 0; i < j; ++i) \
307 for (j = r; j < n; ++j) \
308 for (i = 0; i < m; ++i) \
312 R_xlen_t m1a = (R_xlen_t) m + 1; \
313 for (j = 0; j < r; ++j) { \
323#define TEMPLATE(_PREFIX_, _CTYPE_, _ZERO_, _ONE_) \
325band2(_CTYPE_ *x, int m, int n, int a, int b, char diag) \
327 if (m == 0 || n == 0) \
329 if (a > b || a >= n || b <= -m) { \
330 Matrix_memset(x, 0, (R_xlen_t) m * n, sizeof(_CTYPE_)); \
333 if (a <= -m) a = 1-m; \
334 if (b >= n) b = n-1; \
337 j0 = (a < 0) ? 0 : a, \
338 j1 = (b < n-m) ? m+b : n; \
341 R_xlen_t dx = (R_xlen_t) m * j0; \
342 Matrix_memset(x, 0, dx, sizeof(_CTYPE_)); \
345 for (j = j0; j < j1; ++j, x += m) { \
348 for (i = 0; i < i0; ++i) \
350 for (i = i1; i < m; ++i) \
354 Matrix_memset(x, 0, (R_xlen_t) m * (n - j1), sizeof(_CTYPE_)); \
355 if (diag != 'N' && a <= 0 && b >= 0) { \
356 x -= m * (R_xlen_t) j; \
357 R_xlen_t m1a = (R_xlen_t) m + 1; \
358 for (j = 0; j < n; ++j, x += m1a) \
366#define TEMPLATE(_PREFIX_, _CTYPE_, _ZERO_, _ONE_) \
368band1(_CTYPE_ *x, int n, int a, int b, char uplo, char diag) \
372 if (a > b || a >= n || b <= -n) { \
373 Matrix_memset(x, 0, PACKED_LENGTH(n), sizeof(_CTYPE_)); \
378 if (b >= n) b = n-1; \
381 if (a <= -n) a = 1-n; \
385 j0 = (a < 0) ? 0 : a, \
386 j1 = (b < 0) ? n+b : n; \
391 Matrix_memset(x, 0, dx = PACKED_LENGTH(j0), \
395 for (j = j0; j < j1; x += (++j)) { \
398 for (i = 0; i < i0; ++i) \
400 for (i = i1; i <= j; ++i) \
404 Matrix_memset(x, 0, PACKED_LENGTH(n) - PACKED_LENGTH(j1), \
406 if (diag != 'N' && a == 0) { \
407 x -= PACKED_LENGTH(j); \
408 for (j = 0; j < n; x += (++j)+1) \
413 R_xlen_t dx = PACKED_LENGTH(n) - PACKED_LENGTH(j0); \
414 Matrix_memset(x, 0, dx, sizeof(_CTYPE_)); \
417 for (j = j0; j < j1; x += n-(j++)) { \
420 for (i = j; i < i0; ++i) \
421 *(x + i - j) = _ZERO_; \
422 for (i = i1; i < n; ++i) \
423 *(x + i - j) = _ZERO_; \
426 Matrix_memset(x, 0, PACKED_LENGTH(n - j1), \
428 if (diag != 'N' && b == 0) { \
429 x -= PACKED_LENGTH(n) - PACKED_LENGTH(j); \
430 for (j = 0; j < n; x += n-(j++)) \
439#define TEMPLATE(_PREFIX_, _CTYPE_, _ZERO_, _ONE_) \
441dcpy2(_CTYPE_ *dest, const _CTYPE_ *src, int n, R_xlen_t length, \
442 char uplo, char diag) \
445 R_xlen_t n1a = (R_xlen_t) n + 1; \
447 for (j = 0; j < n; ++j, dest += n1a) \
449 } else if (length == n) { \
451 for (j = 0; j < n; ++j, dest += n1a, ++src) \
453 } else if (length == (n * n1a) / 2) { \
456 for (j = 0; j < n; dest += n1a, src += (++j)+1) \
459 for (j = 0; j < n; dest += n1a, src += n-(j++)) \
462 } else if (length == (R_xlen_t) n * n) { \
464 for (j = 0; j < n; ++j, dest += n1a, src += n1a) \
467 error(_("incompatible '%s' and '%s' in '%s'"), \
468 "n", "length", __func__); \
475#define TEMPLATE(_PREFIX_, _CTYPE_, _ZERO_, _ONE_) \
477dcpy1(_CTYPE_ *dest, const _CTYPE_ *src, int n, R_xlen_t length, \
478 char uplo_dest, char uplo_src, char diag) \
482 if (uplo_dest == 'U') { \
483 for (j = 0; j < n; dest += (++j)+1) \
486 for (j = 0; j < n; dest += n-(j++)) \
489 } else if (length == n) { \
491 if (uplo_dest == 'U') { \
492 for (j = 0; j < n; dest += (++j)+1, ++src) \
495 for (j = 0; j < n; dest += n-(j++), ++src) \
498 } else if (length == PACKED_LENGTH(n)) { \
500 if (uplo_dest == 'U') { \
501 if (uplo_src == 'U') { \
502 for (j = 0; j < n; src += (++j)+1, dest += j+1) \
505 for (j = 0; j < n; src += n-j, dest += (++j)+1) \
509 if (uplo_src == 'U') { \
510 for (j = 0; j < n; dest += n-(j++), src += j+1) \
513 for (j = 0; j < n; dest += n-j, src += n-(j++)) \
517 } else if (length == (R_xlen_t) n * n) { \
519 R_xlen_t n1a = (R_xlen_t) n + 1; \
520 if (uplo_dest == 'U') { \
521 for (j = 0; j < n; dest += (++j)+1, src += n1a) \
524 for (j = 0; j < n; dest += n-(j++), src += n1a) \
528 error(_("incompatible '%s' and '%s' in '%s'"), \
529 "n", "length", __func__); \