84 char op_ul,
char op_ct)
90 ul0 =
'\0', ul1 =
'U',
91 ct0 =
'\0', ct1 = (
class[0] ==
'z') ?
'C' :
'\0',
94 ul0 = ul1 =
UPLO(from);
95 if (
class[1] ==
's' &&
class[0] ==
'z')
96 ct0 = ct1 =
TRANS(from);
104 if (
class[1] ==
's' && ul0 == ul1 && ct0 == ct1)
107 char cl[] =
".s.Matrix";
112 int *pdim =
DIM(from), n = pdim[1];
114 Rf_error(
_(
"attempt to symmetrize a non-square matrix"));
119 if (ct1 !=
'C' && ct1 !=
'\0')
122 int up = (
class[0] !=
'R') == (ul1 ==
'U');
124 if (
class[2] !=
'T') {
129 int *pp0 = INTEGER(p0), *pi0 = INTEGER(i0),
130 j, k, kend, nnz0 = pp0[n], nnz1 = 0;
133 if ((
class[1] ==
's' && ul0 == ul1) ||
134 (
class[1] ==
't' && ul0 == ul1 && nu0 ==
'N')) {
139 if (
class[0] !=
'n') {
141 if (
class[1] !=
's' || ct0 !=
'C')
144 SEXP x1 = PROTECT(Rf_allocVector(CPLXSXP, nnz0));
145 Rcomplex *px0 = COMPLEX(x0), *px1 = COMPLEX(x1);
146 for (j = 0, k = 0; j < n; ++j) {
164 SEXP p1 = PROTECT(Rf_allocVector(INTSXP, XLENGTH(p0)));
165 int *pp1 = INTEGER(p1);
170 for (j = 0, k = 0; j < n; ++j) {
173 if ((up) ? pi0[k] <= j : pi0[k] >= j)
179 else if (
class[1] ==
's')
182 for (j = 0, k = 0; j < n; ++j) {
184 if (k < kend && pi0[(up) ? k : kend - 1] == j)
189 else if (ul0 == ul1) {
190 for (j = 0; j < n; ++j)
191 pp1[j] = ++nnz1 + pp0[j];
195 for (j = 0; j < n; ++j)
198 SEXP i1 = PROTECT(Rf_allocVector(INTSXP, nnz1));
199 int *pi1 = INTEGER(i1);
204 c##TYPE *px0 = NULL, *px1 = NULL; \
206 SEXP x0 = PROTECT(GET_SLOT(from, Matrix_xSym)), \
207 x1 = PROTECT(Rf_allocVector(c##TYPESXP, nnz1)); \
210 SET_SLOT(to, Matrix_xSym, x1); \
213 if (class[1] == 'g') \
214 for (j = 0, k = 0; j < n; ++j) { \
217 if ((up) ? pi0[k] <= j : pi0[k] >= j) { \
226 else if (class[1] == 's') { \
228 Matrix_Calloc(iwork, n, int); \
229 c##csptrans(pp1, pi1, px1, pp0, pi0, px0, n, n, ct0, iwork); \
230 Matrix_Free(iwork, n); \
232 for (j = 0, k = 0; j < n; ++j) { \
234 if (k < kend && pi1[(up) ? kend - 1 : k] == j) \
235 c##SET_PROJ_REAL(px1[(up) ? kend - 1 : k]); \
239 else if (nu0 == 'N') \
240 for (j = 0, k = 0; j < n; ++j) { \
242 if (k < kend && pi0[(up) ? k : kend - 1] == j) { \
245 *(px1++) = px0[(up) ? k : kend - 1]; \
250 else if (ul0 == ul1) \
251 for (j = 0, k = 0; j < n; ++j) { \
256 *(px1++) = c##UNIT; \
269 *(px1++) = c##UNIT; \
274 for (j = 0; j < n; ++j) { \
277 *(px1++) = c##UNIT; \
296 int *pi0 = INTEGER(i0), *pj0 = INTEGER(j0);
297 R_xlen_t k, nnz0 = XLENGTH(i0), nnz1 = 0;
299 if ((
class[1] ==
's') ||
300 (
class[1] ==
't' && ul0 == ul1 && nu0 ==
'N')) {
302 if (
class[1] !=
's' || ul0 == ul1) {
310 if (
class[0] !=
'n') {
312 if (
class[1] !=
's' || ct0 !=
'C')
315 SEXP x1 = PROTECT(Rf_allocVector(CPLXSXP, XLENGTH(x0)));
316 Rcomplex *px0 = COMPLEX(x0), *px1 = COMPLEX(x1);
317 for (k = 0; k < nnz0; ++k)
318 if (pi0[k] == pj0[k])
332 if (
class[1] ==
'g' || nu0 ==
'N') {
333 for (k = 0; k < nnz0; ++k)
334 if ((up) ? pi0[k] <= pj0[k] : pi0[k] >= pj0[k])
338 nnz1 = (ul0 == ul1) ? n + nnz0 : n;
340 SEXP i1 = PROTECT(Rf_allocVector(INTSXP, nnz1)),
341 j1 = PROTECT(Rf_allocVector(INTSXP, nnz1));
342 int *pi1 = INTEGER(i1), *pj1 = INTEGER(j1), j;
349 SEXP x0 = PROTECT(GET_SLOT(from, Matrix_xSym)), \
350 x1 = PROTECT(Rf_allocVector(c##TYPESXP, nnz1)); \
351 c##TYPE *px0 = c##PTR(x0), *px1 = c##PTR(x1); \
352 SET_SLOT(to, Matrix_xSym, x1); \
355 if (class[1] == 'g' || nu0 == 'N') \
356 for (k = 0; k < nnz0; ++k) { \
357 if ((up) ? pi0[k] <= pj0[k] : pi0[k] >= pj0[k]) { \
367 memcpy(pi1, pi0, sizeof( int) * (size_t) nnz0); \
368 memcpy(pj1, pj0, sizeof( int) * (size_t) nnz0); \
372 memcpy(px1, px0, sizeof(c##TYPE) * (size_t) nnz0); \
376 for (j = 0; j < n; ++j) { \
377 *(pi1++) = *(pj1++) = j; \
379 *(px1++) = c##UNIT; \