5#define MK(_FORMAT_ ) mkString(_FORMAT_ )
6#define MS(_FORMAT_, ...) Matrix_sprintf(_FORMAT_, __VA_ARGS__)
8#define RMK(_FORMAT_ ) \
10#define RMS(_FORMAT_, ...) \
11 return MS(_FORMAT_, __VA_ARGS__)
12#define RMKMS(_FORMAT_, ...) \
13 return MK(MS(_FORMAT_, __VA_ARGS__))
15#define FRMKMS(_FORMAT_, ...) \
17 Matrix_Free(work, lwork); \
18 RMKMS(_FORMAT_, __VA_ARGS__); \
28 if (TYPEOF(dim) != INTSXP)
29 RMS(
_(
"'%s' slot is not of type \"%s\""),
"Dim",
"integer");
30 if (XLENGTH(dim) != 2)
31 RMS(
_(
"'%s' slot does not have length %d"),
"Dim", 2);
32 int *pdim = INTEGER(dim), m = pdim[0], n = pdim[1];
33 if (m == NA_INTEGER || n == NA_INTEGER)
34 RMS(
_(
"'%s' slot contains NA"),
"Dim");
36 RMS(
_(
"'%s' slot has negative elements"),
"Dim");
44 return (msg) ? mkString(msg) : ScalarLogical(1);
49 if (TYPEOF(dimnames) != VECSXP)
50 RMS(
_(
"'%s' slot is not a list"),
"Dimnames");
51 if (XLENGTH(dimnames) != 2)
52 RMS(
_(
"'%s' slot does not have length %d"),
"Dimnames", 2);
63 for (i = 0; i < 2; ++i) {
64 s = VECTOR_ELT(dimnames, i);
68 RMS(
_(
"%s[[%d]] is not NULL or a vector"),
"Dimnames", i + 1);
70 if (ns != pdim[i] && ns != 0)
71 RMS(
_(
"length of %s[[%d]] (%lld) is not equal to %s[%d] (%d)"),
72 "Dimnames", i + 1, (
long long) ns,
73 "Dim" , i + 1, pdim[i]);
82 return (msg) ? mkString(msg) : ScalarLogical(1);
89 for (i = 0; i < 2 && !fixup; ++i)
91 (s = VECTOR_ELT(dimnames, i)) != R_NilValue &&
92 (LENGTH(s) == 0 || TYPEOF(s) != STRSXP);
95 SEXP dimnames_ = PROTECT(allocVector(VECSXP, 2));
96 for (i = 0; i < 2; ++i) {
97 if ((s = VECTOR_ELT(dimnames, i)) == R_NilValue || LENGTH(s) == 0)
99 if (TYPEOF(s) == STRSXP)
101 else if (TYPEOF(s) == INTSXP && inherits(s,
"factor"))
102 PROTECT(s = asCharacterFactor(s));
104 PROTECT(s = coerceVector(s, STRSXP));
105 SET_ATTRIB(s, R_NilValue);
108 SET_VECTOR_ELT(dimnames_, i, s);
111 s = getAttrib(dimnames, R_NamesSymbol);
112 if (s != R_NilValue) {
114 setAttrib(dimnames_, R_NamesSymbol, s);
137 return (msg) ? mkString(msg) : ScalarLogical(1);
145#define KINDMATRIX_VALIDATE(_PREFIX_, _SEXPTYPE_) \
146SEXP _PREFIX_ ## Matrix_validate(SEXP obj) \
148 SEXP x = GET_SLOT(obj, Matrix_xSym); \
149 if (TYPEOF(x) != _SEXPTYPE_) \
150 RMKMS(_("'%s' slot is not of type \"%s\""), "x", type2char(_SEXPTYPE_)); \
151 return ScalarLogical(1); \
158#undef KINDMATRIX_VALIDATE
163 if (TYPEOF(factors) != VECSXP)
164 RMKMS(
_(
"'%s' slot is not a list"),
"factors");
165 if (XLENGTH(factors) > 0) {
167 SEXP nms = getAttrib(factors, R_NamesSymbol);
169 if (nms == R_NilValue)
170 RMKMS(
_(
"'%s' slot has no '%s' attribute"),
"factors",
"names");
173 return ScalarLogical(1);
179 int *pdim = INTEGER(dim), n = pdim[0];
181 RMKMS(
_(
"%s[1] != %s[2] (matrix is not square)"),
"Dim",
"Dim");
183#ifdef ENFORCE_SYMMETRIC_DIMNAMES
192# define ANY_TO_STRING(x) \
193 ((TYPEOF(x) == INTSXP && inherits(x, "factor")) \
194 ? asCharacterFactor(x) \
195 : coerceVector(x, STRSXP))
198 ndn = getAttrib(dn, R_NamesSymbol);
201 const char *ndn0, *ndn1;
202 if (ndn != R_NilValue &&
203 *(ndn0 = CHAR(STRING_ELT(ndn, 0))) !=
'\0' &&
204 *(ndn1 = CHAR(STRING_ELT(ndn, 1))) !=
'\0' &&
205 strcmp(ndn0, ndn1) != 0)
206 RMKMS(
_(
"%s[1] differs from %s[2]"),
"Dimnames",
"Dimnames");
210 if ((rn = VECTOR_ELT(dn, 0)) != R_NilValue &&
211 (cn = VECTOR_ELT(dn, 1)) != R_NilValue &&
212 LENGTH(rn) == n && LENGTH(cn) == n && rn != cn) {
215 PROTECT(rn = ANY_TO_STRING(rn));
216 PROTECT(cn = ANY_TO_STRING(cn));
219 RMKMS(
_(
"%s[1] differs from %s[2]"),
"Dimnames",
"Dimnames");
228 if (TYPEOF(uplo) != STRSXP)
229 RMKMS(
_(
"'%s' slot is not of type \"%s\""),
"uplo",
"character");
230 if (XLENGTH(uplo) != 1)
231 RMKMS(
_(
"'%s' slot does not have length %d"),
"uplo", 1);
232 const char *ul = CHAR(STRING_ELT(uplo, 0));
233 if (ul[0] ==
'\0' || ul[1] !=
'\0' || (ul[0] !=
'U' && ul[0] !=
'L'))
234 RMKMS(
_(
"'%s' slot is not \"%s\" or \"%s\""),
"uplo",
"U",
"L");
242 int *pdim = INTEGER(dim), n = pdim[0];
244 RMKMS(
_(
"%s[1] != %s[2] (matrix is not square)"),
"Dim",
"Dim");
247 if (TYPEOF(uplo) != STRSXP)
248 RMKMS(
_(
"'%s' slot is not of type \"%s\""),
"uplo",
"character");
249 if (XLENGTH(uplo) != 1)
250 RMKMS(
_(
"'%s' slot does not have length %d"),
"uplo", 1);
251 const char *ul = CHAR(STRING_ELT(uplo, 0));
252 if (ul[0] ==
'\0' || ul[1] !=
'\0' || (ul[0] !=
'U' && ul[0] !=
'L'))
253 RMKMS(
_(
"'%s' slot is not \"%s\" or \"%s\""),
"uplo",
"U",
"L");
256 if (TYPEOF(diag) != STRSXP)
257 RMKMS(
_(
"'%s' slot is not of type \"%s\""),
"diag",
"character");
258 if (XLENGTH(diag) != 1)
259 RMKMS(
_(
"'%s' slot does not have length %d"),
"diag", 1);
260 const char *di = CHAR(STRING_ELT(diag, 0));
261 if (di[0] ==
'\0' || di[1] !=
'\0' || (di[0] !=
'N' && di[0] !=
'U'))
262 RMKMS(
_(
"'%s' slot is not \"%s\" or \"%s\""),
"diag",
"N",
"U");
264 return ScalarLogical(1);
272 int *pdim = INTEGER(dim), m = pdim[0], n = pdim[1];
274 RMKMS(
_(
"'%s' slot does not have length %s"),
"x",
"prod(Dim)");
275 return ScalarLogical(1);
283 int n = INTEGER(dim)[0];
285 RMKMS(
_(
"'%s' slot does not have length %s"),
"x",
"Dim[1]*(Dim[1]+1)/2");
286 return ScalarLogical(1);
292 int *pdim = INTEGER(dim), m = pdim[0], n = pdim[1];
298 if (TYPEOF(p) != INTSXP)
299 RMKMS(
_(
"'%s' slot is not of type \"%s\""),
"p",
"integer");
300 if (XLENGTH(p) - 1 != n)
301 RMKMS(
_(
"'%s' slot does not have length %s"),
"p",
"Dim[2]+1");
302 int *pp = INTEGER(p);
304 RMKMS(
_(
"first element of '%s' slot is not 0"),
"p");
306 for (j = 1; j <= n; ++j) {
307 if (pp[j] == NA_INTEGER)
308 RMKMS(
_(
"'%s' slot contains NA"),
"p");
309 if (pp[j] < pp[j - 1])
310 RMKMS(
_(
"'%s' slot is not nondecreasing"),
"p");
311 if (pp[j] - pp[j - 1] > m)
312 RMKMS(
_(
"first differences of '%s' slot exceed %s"),
"p",
"Dim[1]");
315 if (TYPEOF(i) != INTSXP)
316 RMKMS(
_(
"'%s' slot is not of type \"%s\""),
"i",
"integer");
317 if (XLENGTH(i) < pp[n])
318 RMKMS(
_(
"'%s' slot has length less than %s"),
"i",
"p[length(p)]");
319 int *pi = INTEGER(i), k, kend, ik, i0;
320 for (j = 1, k = 0; j <= n; ++j) {
325 if (ik == NA_INTEGER)
326 RMKMS(
_(
"'%s' slot contains NA"),
"i");
327 if (ik < 0 || ik >= m)
328 RMKMS(
_(
"'%s' slot has elements not in {%s}"),
329 "i",
"0,...,Dim[1]-1");
331 RMKMS(
_(
"'%s' slot is not increasing within columns"),
"i");
337 return ScalarLogical(1);
343 int *pdim = INTEGER(dim), m = pdim[0], n = pdim[1];
349 if (TYPEOF(p) != INTSXP)
350 RMKMS(
_(
"'%s' slot is not of type \"%s\""),
"p",
"integer");
351 if (XLENGTH(p) - 1 != m)
352 RMKMS(
_(
"'%s' slot does not have length %s"),
"p",
"Dim[1]+1");
353 int *pp = INTEGER(p);
355 RMKMS(
_(
"first element of '%s' slot is not 0"),
"p");
357 for (i = 1; i <= m; ++i) {
358 if (pp[i] == NA_INTEGER)
359 RMKMS(
_(
"'%s' slot contains NA"),
"p");
360 if (pp[i] < pp[i - 1])
361 RMKMS(
_(
"'%s' slot is not nondecreasing"),
"p");
362 if (pp[i] - pp[i - 1] > n)
363 RMKMS(
_(
"first differences of '%s' slot exceed %s"),
"p",
"Dim[2]");
366 if (TYPEOF(j) != INTSXP)
367 RMKMS(
_(
"'%s' slot is not of type \"%s\""),
"j",
"integer");
368 if (XLENGTH(j) < pp[m])
369 RMKMS(
_(
"'%s' slot has length less than %s"),
"j",
"p[length(p)]");
370 int *pj = INTEGER(j), k, kend, jk, j0;
371 for (i = 1, k = 0; i <= m; ++i) {
376 if (jk == NA_INTEGER)
377 RMKMS(
_(
"'%s' slot contains NA"),
"j");
378 if (jk < 0 || jk >= n)
379 RMKMS(
_(
"'%s' slot has elements not in {%s}"),
380 "j",
"0,...,Dim[2]-1");
382 RMKMS(
_(
"'%s' slot is not increasing within rows"),
"j");
388 return ScalarLogical(1);
394 int *pdim = INTEGER(dim), m = pdim[0], n = pdim[1];
400 if (TYPEOF(i) != INTSXP)
401 RMKMS(
_(
"'%s' slot is not of type \"%s\""),
"i",
"integer");
402 if (TYPEOF(j) != INTSXP)
403 RMKMS(
_(
"'%s' slot is not of type \"%s\""),
"j",
"integer");
404 R_xlen_t nnz = XLENGTH(i);
405 if (XLENGTH(j) != nnz)
406 RMKMS(
_(
"'%s' and '%s' slots do not have equal length"),
"i",
"j");
408 if (m == 0 || n == 0)
409 RMKMS(
_(
"'%s' slot has nonzero length but %s is 0"),
"i",
"prod(Dim)");
410 int *pi = INTEGER(i), *pj = INTEGER(j);
412 if (*pi == NA_LOGICAL)
413 RMKMS(
_(
"'%s' slot contains NA"),
"i");
414 if (*pj == NA_LOGICAL)
415 RMKMS(
_(
"'%s' slot contains NA"),
"j");
416 if (*pi < 0 || *pi >= m)
417 RMKMS(
_(
"'%s' slot has elements not in {%s}"),
418 "i",
"0,...,Dim[1]-1");
419 if (*pj < 0 || *pj >= n)
420 RMKMS(
_(
"'%s' slot has elements not in {%s}"),
421 "j",
"0,...,Dim[2]-1");
427 return ScalarLogical(1);
433 int *pdim = INTEGER(dim), n = pdim[0];
435 RMKMS(
_(
"%s[1] != %s[2] (matrix is not square)"),
"Dim",
"Dim");
438 if (TYPEOF(diag) != STRSXP)
439 RMKMS(
_(
"'%s' slot is not of type \"%s\""),
"diag",
"character");
440 if (XLENGTH(diag) != 1)
441 RMKMS(
_(
"'%s' slot does not have length %d"),
"diag", 1);
442 const char *di = CHAR(STRING_ELT(diag, 0));
443 if (di[0] ==
'\0' || di[1] !=
'\0' || (di[0] !=
'N' && di[0] !=
'U'))
444 RMKMS(
_(
"'%s' slot is not \"%s\" or \"%s\""),
"diag",
"N",
"U");
445 int nonunit = di[0] ==
'N';
450 RMKMS(
_(
"'%s' slot is \"%s\" but '%s' slot does not have length %s"),
451 "diag",
"N",
"x",
"Dim[1]");
454 RMKMS(
_(
"'%s' slot is \"%s\" but '%s' slot does not have length %s"),
455 "diag",
"U",
"x",
"0");
458 return ScalarLogical(1);
464 if (TYPEOF(margin) != INTSXP)
465 RMKMS(
_(
"'%s' slot is not of type \"%s\""),
"margin",
"integer");
466 if (XLENGTH(margin) != 1)
467 RMKMS(
_(
"'%s' slot does not have length %d"),
"margin", 1);
468 int mg = INTEGER(margin)[0] - 1;
469 if (mg != 0 && mg != 1)
470 RMKMS(
_(
"'%s' slot is not %d or %d"),
"margin", 1, 2);
473 int *pdim = INTEGER(dim), m = pdim[mg], n = pdim[!mg];
474 if (m > 0 && n == 0) {
476 RMKMS(
_(
"%s-by-%s %s invalid for positive '%s' when %s=%d"),
477 "m",
"0",
"indMatrix",
"m",
"margin", 1);
479 RMKMS(
_(
"%s-by-%s %s invalid for positive '%s' when %s=%d"),
480 "0",
"n",
"indMatrix",
"n",
"margin", 2);
484 if (TYPEOF(perm) != INTSXP)
485 RMKMS(
_(
"'%s' slot is not of type \"%s\""),
"perm",
"integer");
486 if (XLENGTH(perm) != m)
487 RMKMS(
_(
"'%s' slot does not have length %s"),
"perm",
"Dim[margin]");
488 int *pperm = INTEGER(perm);
490 if (*pperm == NA_INTEGER)
491 RMKMS(
_(
"'%s' slot contains NA"),
"perm");
492 if (*pperm < 1 || *pperm > n)
493 RMKMS(
_(
"'%s' slot has elements not in {%s}"),
494 "perm",
"1,...,Dim[1+margin%%2]");
498 return ScalarLogical(1);
504 int *pdim = INTEGER(dim), n = pdim[0];
506 RMKMS(
_(
"%s[1] != %s[2] (matrix is not square)"),
"Dim",
"Dim");
513 int j, *pperm = INTEGER(perm);
514 for (j = 0; j < n; ++j) {
515 if (work[*pperm - 1])
516 FRMKMS(
_(
"'%s' slot contains duplicates"),
"perm");
517 work[*(pperm++) - 1] = 1;
522 return ScalarLogical(1);
528 int *pp = INTEGER(p), n = (int) (XLENGTH(p) - 1);
533 char ul = *CHAR(STRING_ELT(uplo, 0));
536 int *pi = INTEGER(i), j, k, kend;
540 for (j = 0, k = 0; j < n; ++j) {
544 RMKMS(
_(
"%s=\"%s\" but there are entries below the diagonal"),
550 for (j = 0, k = 0; j < n; ++j) {
554 RMKMS(
_(
"%s=\"%s\" but there are entries above the diagonal"),
562 return ScalarLogical(1);
568 char di = *CHAR(STRING_ELT(diag, 0));
573 int *pp = INTEGER(p), n = (int) (XLENGTH(p) - 1);
578 char ul = *CHAR(STRING_ELT(uplo, 0));
581 int *pi = INTEGER(i), j, k, kend;
585 for (j = 0, k = 0; j < n; ++j) {
589 RMKMS(
_(
"%s=\"%s\" but there are entries below the diagonal"),
592 RMKMS(
_(
"%s=\"%s\" but there are entries on the diagonal"),
598 for (j = 0, k = 0; j < n; ++j) {
602 RMKMS(
_(
"%s=\"%s\" but there are entries above the diagonal"),
605 RMKMS(
_(
"%s=\"%s\" but there are entries on the diagonal"),
613 return ScalarLogical(1);
619 int *pp = INTEGER(p), m = (int) (XLENGTH(p) - 1);
624 char ul = *CHAR(STRING_ELT(uplo, 0));
627 int *pj = INTEGER(j), i, k, kend;
631 for (i = 0, k = 0; i < m; ++i) {
635 RMKMS(
_(
"%s=\"%s\" but there are entries below the diagonal"),
641 for (i = 0, k = 0; i < m; ++i) {
645 RMKMS(
_(
"%s=\"%s\" but there are entries above the diagonal"),
653 return ScalarLogical(1);
659 char di = *CHAR(STRING_ELT(diag, 0));
664 int *pp = INTEGER(p), m = (int) (XLENGTH(p) - 1);
669 char ul = *CHAR(STRING_ELT(uplo, 0));
672 int *pj = INTEGER(j), i, k, kend;
676 for (i = 0, k = 0; i < m; ++i) {
680 RMKMS(
_(
"%s=\"%s\" but there are entries below the diagonal"),
683 RMKMS(
_(
"%s=\"%s\" but there are entries on the diagonal"),
689 for (i = 0, k = 0; i < m; ++i) {
693 RMKMS(
_(
"%s=\"%s\" but there are entries above the diagonal"),
696 RMKMS(
_(
"%s=\"%s\" but there are entries on the diagonal"),
704 return ScalarLogical(1);
710 R_xlen_t nnz = XLENGTH(i);
715 char ul = *CHAR(STRING_ELT(uplo, 0));
718 int *pi = INTEGER(i), *pj = INTEGER(j);
723 if (*(pi++) > *(pj++))
724 RMKMS(
_(
"%s=\"%s\" but there are entries below the diagonal"),
728 if (*(pi++) < *(pj++))
729 RMKMS(
_(
"%s=\"%s\" but there are entries above the diagonal"),
734 return ScalarLogical(1);
740 char di = *CHAR(STRING_ELT(diag, 0));
745 R_xlen_t nnz = XLENGTH(i);
750 char ul = *CHAR(STRING_ELT(uplo, 0));
753 int *pi = INTEGER(i), *pj = INTEGER(j);
759 RMKMS(
_(
"%s=\"%s\" but there are entries below the diagonal"),
762 RMKMS(
_(
"%s=\"%s\" but there are entries on the diagonal"),
770 RMKMS(
_(
"%s=\"%s\" but there are entries above the diagonal"),
773 RMKMS(
_(
"%s=\"%s\" but there are entries on the diagonal"),
781 return ScalarLogical(1);
789 if (XLENGTH(x) != XLENGTH(i))
790 RMKMS(
_(
"'%s' and '%s' slots do not have equal length"),
"i",
"x");
791 return ScalarLogical(1);
797 if (TYPEOF(val) != STRSXP)
805 if (TYPEOF(val) != STRSXP)
815 if (XLENGTH(x) != XLENGTH(j))
816 RMKMS(
_(
"'%s' and '%s' slots do not have equal length"),
"j",
"x");
817 return ScalarLogical(1);
823 if (TYPEOF(val) != STRSXP)
831 if (TYPEOF(val) != STRSXP)
841 if (XLENGTH(x) != XLENGTH(i))
842 RMKMS(
_(
"'%s' and '%s' slots do not have equal length"),
"i",
"x");
843 return ScalarLogical(1);
849 if (TYPEOF(val) != STRSXP)
857 if (TYPEOF(val) != STRSXP)
870 int j, n = INTEGER(dim)[0];
871 R_xlen_t n1a = (R_xlen_t) n + 1;
875 double *px = REAL(x);
876 for (j = 0; j < n; ++j, px += n1a)
877 if (!ISNAN(*px) && *px < 0.0)
878 RMK(
_(
"matrix has negative diagonal elements"));
880 return ScalarLogical(1);
891 int j, n = INTEGER(dim)[0];
894 char ul = *CHAR(STRING_ELT(uplo, 0));
898 double *px = REAL(x);
900 for (j = 0; j < n; px += (++j)+1)
901 if (!ISNAN(*px) && *px < 0.0)
902 RMK(
_(
"matrix has negative diagonal elements"));
904 for (j = 0; j < n; px += n-(j++))
905 if (!ISNAN(*px) && *px < 0.0)
906 RMK(
_(
"matrix has negative diagonal elements"));
909 return ScalarLogical(1);
915 int j, n = INTEGER(dim)[0];
916 R_xlen_t n1a = (R_xlen_t) n + 1;
919 double *px = REAL(x);
920 for (j = 0; j < n; ++j, px += n1a)
921 if (ISNAN(*px) || *px != 1.0)
922 RMK(
_(
"matrix has nonunit diagonal elements"));
925 if (TYPEOF(sd) != REALSXP)
926 RMKMS(
_(
"'%s' slot is not of type \"%s\""),
"sd",
"double");
927 if (XLENGTH(sd) != n)
928 RMKMS(
_(
"'%s' slot does not have length %s"),
"sd",
"Dim[1]");
929 double *psd = REAL(sd);
930 for (j = 0; j < n; ++j)
931 if (!ISNAN(psd[j]) && psd[j] < 0.0)
932 RMKMS(
_(
"'%s' slot has negative elements"),
"sd");
934 return ScalarLogical(1);
940 int j, n = INTEGER(dim)[0];
943 char ul = *CHAR(STRING_ELT(uplo, 0));
946 double *px = REAL(x);
948 for (j = 0; j < n; px += (++j)+1)
949 if (ISNAN(*px) || *px != 1.0)
950 RMK(
_(
"matrix has nonunit diagonal elements"));
952 for (j = 0; j < n; px += n-(j++))
953 if (ISNAN(*px) || *px != 1.0)
954 RMK(
_(
"matrix has nonunit diagonal elements"));
958 if (TYPEOF(sd) != REALSXP)
959 RMKMS(
_(
"'%s' slot is not of type \"%s\""),
"sd",
"double");
960 if (XLENGTH(sd) != n)
961 RMKMS(
_(
"'%s' slot does not have length %s"),
"sd",
"Dim[1]");
962 double *psd = REAL(sd);
963 for (j = 0; j < n; ++j)
964 if (!ISNAN(psd[j]) && psd[j] < 0.0)
965 RMKMS(
_(
"'%s' slot has negative elements"),
"sd");
967 return ScalarLogical(1);
973 if (TYPEOF(length) != INTSXP && TYPEOF(length) != REALSXP)
974 RMKMS(
_(
"'%s' slot is not of type \"%s\" or \"%s\""),
975 "length",
"integer",
"double");
976 if (XLENGTH(length) != 1)
977 RMKMS(
_(
"'%s' slot does not have length %d"),
"length", 1);
979 if (TYPEOF(length) == INTSXP) {
980 int n_ = INTEGER(length)[0];
981 if (n_ == NA_INTEGER)
982 RMKMS(
_(
"'%s' slot is NA"),
"length");
984 RMKMS(
_(
"'%s' slot is negative"),
"length");
987 double n_ = REAL(length)[0];
989 RMKMS(
_(
"'%s' slot is NA"),
"length");
991 RMKMS(
_(
"'%s' slot is negative"),
"length");
993 RMKMS(
_(
"'%s' slot exceeds %s"),
"length",
"2^53");
998 if (TYPEOF(i) != INTSXP && TYPEOF(i) != REALSXP)
999 RMKMS(
_(
"'%s' slot is not of type \"%s\" or \"%s\""),
1000 "i",
"integer",
"double");
1001 R_xlen_t nnz = XLENGTH(i);
1003 RMKMS(
_(
"'%s' slot has length greater than '%s' slot"),
"i",
"length");
1004 if (TYPEOF(i) == INTSXP) {
1005 int *pi = INTEGER(i), max = (n > INT_MAX) ? INT_MAX : (int) n, last = 0;
1007 if (*pi == NA_INTEGER)
1008 RMKMS(
_(
"'%s' slot contains NA"),
"i");
1009 if (*pi < 1 || *pi > max)
1010 RMKMS(
_(
"'%s' slot has elements not in {%s}"),
1011 "i",
"1,...,length");
1013 RMKMS(
_(
"'%s' slot is not increasing"),
"i");
1017 double *pi = REAL(i), max = (double) n, last = 0.0, tmp;
1020 RMKMS(
_(
"'%s' slot contains NA"),
"i");
1021 tmp = trunc(*(pi++));
1022 if (tmp < 1.0 || tmp > max)
1023 RMKMS(
_(
"'%s' slot has elements not in {%s} after truncation towards zero"),
1024 "i",
"1,...,length");
1026 RMKMS(
_(
"'%s' slot is not increasing after truncation towards zero"),
"i");
1031 return ScalarLogical(1);
1034#define KINDVECTOR_VALIDATE(_PREFIX_, _SEXPTYPE_) \
1035SEXP _PREFIX_ ## sparseVector_validate(SEXP obj) \
1037 SEXP x = PROTECT(GET_SLOT(obj, Matrix_xSym)), \
1038 i = PROTECT(GET_SLOT(obj, Matrix_iSym)); \
1040 if (TYPEOF(x) != _SEXPTYPE_) \
1041 RMKMS(_("'%s' slot is not of type \"%s\""), "x", type2char(_SEXPTYPE_)); \
1042 if (XLENGTH(x) != XLENGTH(i)) \
1043 RMKMS(_("'%s' and '%s' slots do not have equal length"), "i", "x"); \
1044 return ScalarLogical(1); \
1050#undef KINDVECTOR_VALIDATE
1057 int *pdim = INTEGER(dim), m = pdim[0], n = pdim[1], r = (m < n) ? m : n;
1060 if (TYPEOF(perm) != INTSXP)
1061 RMKMS(
_(
"'%s' slot is not of type \"%s\""),
"perm",
"integer");
1062 if (XLENGTH(perm) != r)
1063 RMKMS(
_(
"'%s' slot does not have length %s"),
"perm",
"min(Dim)");
1064 int *pperm = INTEGER(perm);
1066 if (*pperm == NA_INTEGER)
1067 RMKMS(
_(
"'%s' slot contains NA"),
"perm");
1068 if (*pperm < 1 || *pperm > m)
1069 RMKMS(
_(
"'%s' slot has elements not in {%s}"),
1070 "perm",
"1,...,Dim[1]");
1074 return ScalarLogical(1);
1080 int *pdim = INTEGER(dim), n = pdim[0];
1082 RMKMS(
_(
"%s[1] != %s[2] (matrix is not square)"),
"Dim",
"Dim");
1090 pdim = INTEGER(dim);
1091 if (pdim[0] != n || pdim[1] != n)
1092 RMKMS(
_(
"dimensions of '%s' slot are not identical to '%s'"),
"L",
"Dim");
1093 if (*CHAR(STRING_ELT(uplo, 0)) ==
'U')
1094 RMKMS(
_(
"'%s' slot is upper (not lower) triangular"),
"L");
1095 if (*CHAR(STRING_ELT(diag, 0)) ==
'N') {
1102 int *pp = INTEGER(p), *pi = INTEGER(i), j, k, kend;
1103 double *px = REAL(x);
1104 for (j = 0, k = 0; j < n; ++j) {
1106 if (kend == k || pi[k] != j || px[k] != 1.0)
1107 RMKMS(
_(
"'%s' slot has nonunit diagonal elements"),
"L");
1117 pdim = INTEGER(dim);
1118 if (pdim[0] != n || pdim[1] != n)
1119 RMKMS(
_(
"dimensions of '%s' slot are not identical to '%s'"),
"U",
"Dim");
1120 if (*CHAR(STRING_ELT(uplo, 0)) !=
'U')
1121 RMKMS(
_(
"'%s' slot is lower (not upper) triangular"),
"U");
1126 if (TYPEOF(p) != INTSXP)
1127 RMKMS(
_(
"'%s' slot is not of type \"%s\""),
"p",
"integer");
1128 if (TYPEOF(q) != INTSXP)
1129 RMKMS(
_(
"'%s' slot is not of type \"%s\""),
"q",
"integer");
1130 if (XLENGTH(p) != n)
1131 RMKMS(
_(
"'%s' slot does not have length %s"),
"p",
"Dim[1]");
1132 if (XLENGTH(q) != n && XLENGTH(q) != 0)
1133 RMKMS(
_(
"'%s' slot does not have length %s or length %s"),
"q",
"Dim[2]",
"0");
1137 int j, *pp = INTEGER(p);
1138 for (j = 0; j < n; ++j) {
1139 if (*pp == NA_INTEGER)
1140 FRMKMS(
_(
"'%s' slot contains NA"),
"p");
1141 if (*pp < 0 || *pp >= n)
1142 FRMKMS(
_(
"'%s' slot has elements not in {%s}"),
1143 "p",
"0,...,Dim[1]-1");
1145 FRMKMS(
_(
"'%s' slot contains duplicates"),
"p");
1148 if (LENGTH(q) == n) {
1149 int *pq = INTEGER(q);
1150 for (j = 0; j < n; ++j) {
1151 if (*pq == NA_INTEGER)
1152 FRMKMS(
_(
"'%s' slot contains NA"),
"q");
1153 if (*pq < 0 || *pq >= n)
1154 FRMKMS(
_(
"'%s' slot has elements not in {%s}"),
1155 "q",
"0,...,Dim[2]-1");
1157 FRMKMS(
_(
"'%s' slot contains duplicates"),
"q");
1163 return ScalarLogical(1);
1171 int *pdim = INTEGER(dim), m = pdim[0], n = pdim[1];
1173 RMK(
_(
"matrix has more columns than rows"));
1176 if (TYPEOF(beta) != REALSXP)
1177 RMKMS(
_(
"'%s' slot is not of type \"%s\""),
"beta",
"double");
1178 if (XLENGTH(beta) != n)
1179 RMKMS(
_(
"'%s' slot does not have length %s"),
"beta",
"Dim[2]");
1182 int *pp, *pi, *pq, j, k, kend;
1190 pdim = INTEGER(dim);
1193 RMKMS(
_(
"'%s' slot has fewer than %s rows"),
"V",
"Dim[1]");
1195 RMKMS(
_(
"'%s' slot has more than %s rows"),
"V",
"Dim[1]+Dim[2]");
1197 RMKMS(
_(
"'%s' slot does not have %s columns"),
"V",
"Dim[2]");
1200 for (j = 0, k = 0; j < n; ++j) {
1204 RMKMS(
_(
"'%s' slot must be lower trapezoidal but has entries above the diagonal"),
"V");
1215 pdim = INTEGER(dim);
1217 RMKMS(
_(
"'%s' slot does not have %s row"),
"R",
"nrow(V)");
1219 RMKMS(
_(
"'%s' slot does not have %s columns"),
"R",
"Dim[2]");
1222 for (j = 0, k = 0; j < n; ++j) {
1225 if (pi[kend - 1] > j)
1226 RMKMS(
_(
"'%s' slot must be upper trapezoidal but has entries below the diagonal"),
"R");
1228 if (pi[kend - 1] == j &&
1229 !ISNAN(px[kend - 1]) && px[kend - 1] < 0.0)
1230 RMKMS(
_(
"'%s' slot has negative diagonal elements"),
"R");
1239 if (TYPEOF(p) != INTSXP)
1240 RMKMS(
_(
"'%s' slot is not of type \"%s\""),
"p",
"integer");
1241 if (TYPEOF(q) != INTSXP)
1242 RMKMS(
_(
"'%s' slot is not of type \"%s\""),
"q",
"integer");
1243 if (XLENGTH(p) != m0)
1244 RMKMS(
_(
"'%s' slot does not have length %s"),
"p",
"nrow(V)");
1245 if (XLENGTH(q) != n && XLENGTH(q) != 0)
1246 RMKMS(
_(
"'%s' slot does not have length %s or length %s"),
"q",
"Dim[2]",
"0");
1251 for (j = 0; j < m0; ++j) {
1252 if (*pp == NA_INTEGER)
1253 FRMKMS(
_(
"'%s' slot contains NA"),
"p");
1254 if (*pp < 0 || *pp >= m0)
1255 FRMKMS(
_(
"'%s' slot has elements not in {%s}"),
1256 "p",
"0,...,nrow(V)-1");
1258 FRMKMS(
_(
"'%s' slot contains duplicates"),
"p");
1261 if (LENGTH(q) == n) {
1263 for (j = 0; j < n; ++j) {
1264 if (*pq == NA_INTEGER)
1265 FRMKMS(
_(
"'%s' slot contains NA"),
"q");
1266 if (*pq < 0 || *pq >= n)
1267 FRMKMS(
_(
"'%s' slot has elements not in {%s}"),
1268 "q",
"0,...,Dim[2]-1");
1270 FRMKMS(
_(
"'%s' slot contains duplicates"),
"q");
1276 return ScalarLogical(1);
1284 int n = INTEGER(dim)[0];
1287 if (TYPEOF(perm) != INTSXP)
1288 RMKMS(
_(
"'%s' slot is not of type \"%s\""),
"perm",
"integer");
1289 if (XLENGTH(perm) != n)
1290 RMKMS(
_(
"'%s' slot does not have length %s"),
"perm",
"Dim[1]");
1291 int n_ = n, *pperm = INTEGER(perm);
1293 if (*pperm == NA_INTEGER)
1294 RMKMS(
_(
"'%s' slot contains NA"),
"perm");
1295 if (*pperm < -n || *pperm == 0 || *pperm > n)
1296 RMKMS(
_(
"'%s' slot has elements not in {%s}\\{%s}"),
1297 "perm",
"-Dim[1],...,Dim[1]",
"0");
1301 }
else if (n_ > 1 && *(pperm + 1) == *pperm) {
1305 RMKMS(
_(
"'%s' slot has unpaired negative elements"),
"perm");
1308 return ScalarLogical(1);
1323 int j, n = INTEGER(dim)[0];
1324 R_xlen_t n1a = (R_xlen_t) n + 1;
1328 double *px = REAL(x);
1329 for (j = 0; j < n; ++j, px += n1a)
1330 if (!ISNAN(*px) && *px < 0.0)
1331 RMK(
_(
"Cholesky factor has negative diagonal elements"));
1334 if (TYPEOF(perm) != INTSXP)
1335 RMKMS(
_(
"'%s' slot is not of type \"%s\""),
"perm",
"integer");
1336 if (XLENGTH(perm) != n && XLENGTH(perm) != 0)
1337 RMKMS(
_(
"'%s' slot does not have length %s or length %s"),
"perm",
"Dim[1]",
"0");
1338 if (LENGTH(perm) == n) {
1342 int *pperm = INTEGER(perm);
1343 for (j = 0; j < n; ++j) {
1344 if (*pperm == NA_INTEGER)
1345 FRMKMS(
_(
"'%s' slot contains NA"),
"perm");
1346 if (*pperm < 0 || *pperm >= n)
1347 FRMKMS(
_(
"'%s' slot has elements not in {%s}"),
1348 "perm",
"0,...,Dim[1]-1");
1350 FRMKMS(
_(
"'%s' slot contains duplicates"),
"perm");
1351 work[*(pperm++)] = 1;
1356 return ScalarLogical(1);
1364 int j, n = INTEGER(dim)[0];
1367 char ul = *CHAR(STRING_ELT(uplo, 0));
1371 double *px = REAL(x);
1373 for (j = 0; j < n; px += (++j)+1)
1374 if (!ISNAN(*px) && *px < 0.0)
1375 RMK(
_(
"Cholesky factor has negative diagonal elements"));
1377 for (j = 0; j < n; px += n-(j++))
1378 if (!ISNAN(*px) && *px < 0.0)
1379 RMK(
_(
"Cholesky factor has negative diagonal elements"));
1383 if (TYPEOF(perm) != INTSXP)
1384 RMKMS(
_(
"'%s' slot is not of type \"%s\""),
"perm",
"integer");
1385 if (XLENGTH(perm) != n && XLENGTH(perm) != 0)
1386 RMKMS(
_(
"'%s' slot does not have length %s or length %s"),
"perm",
"Dim[1]",
"0");
1387 if (LENGTH(perm) == n) {
1391 int *pperm = INTEGER(perm);
1392 for (j = 0; j < n; ++j) {
1393 if (*pperm == NA_INTEGER)
1394 FRMKMS(
_(
"'%s' slot contains NA"),
"perm");
1395 if (*pperm < 0 || *pperm >= n)
1396 FRMKMS(
_(
"'%s' slot has elements not in {%s}"),
1397 "perm",
"0,...,Dim[1]-1");
1399 FRMKMS(
_(
"'%s' slot contains duplicates"),
"perm");
1400 work[*(pperm++)] = 1;
1405 return ScalarLogical(1);
1411 int *pdim = INTEGER(dim), n = pdim[0];
1413 RMKMS(
_(
"%s[1] != %s[2] (matrix is not square)"),
"Dim",
"Dim");
1415 SEXP type =
GET_SLOT(obj, install(
"type"));
1416 if (TYPEOF(type) != INTSXP)
1417 RMKMS(
_(
"'%s' slot is not of type \"%s\""),
"type",
"integer");
1418 if (XLENGTH(type) != 6)
1419 RMKMS(
_(
"'%s' slot does not have length %d"),
"type", 6);
1420 int order = INTEGER(type)[0];
1421 if (order < 0 || order > 4)
1422 RMKMS(
_(
"%s[%d] (%s) is not in %s"),
1423 "type", 1,
"cholmod_factor.ordering",
"0:4");
1425 SEXP colcount =
GET_SLOT(obj, install(
"colcount"));
1426 if (TYPEOF(colcount) != INTSXP)
1427 RMKMS(
_(
"'%s' slot is not of type \"%s\""),
"colcount",
"integer");
1428 if (XLENGTH(colcount) != n)
1429 RMKMS(
_(
"'%s' slot does not have length %s"),
"colcount",
"Dim[2]");
1430 int j, *pcolcount = INTEGER(colcount);
1431 for (j = 0; j < n; ++j) {
1432 if (pcolcount[j] == NA_INTEGER)
1433 RMKMS(
_(
"'%s' slot contains NA"),
"colcount");
1434 if (pcolcount[j] < 0 || pcolcount[j] > n - j)
1435 RMKMS(
_(
"%s is not in {%s}"),
"colcount[j]",
"0,...,Dim[1]-j+1");
1439 if (TYPEOF(perm) != INTSXP)
1440 RMKMS(
_(
"'%s' slot is not of type \"%s\""),
"perm",
"integer");
1442 if (XLENGTH(perm) != 0)
1443 RMKMS(
_(
"'%s' slot does not have length %d"),
"perm", 0);
1445 if (XLENGTH(perm) != n)
1446 RMKMS(
_(
"'%s' slot does not have length %s"),
"perm",
"Dim[1]");
1450 int *pperm = INTEGER(perm);
1451 for (j = 0; j < n; ++j) {
1452 if (*pperm == NA_INTEGER)
1453 FRMKMS(
_(
"'%s' slot contains NA"),
"perm");
1454 if (*pperm < 0 || *pperm >= n)
1455 FRMKMS(
_(
"'%s' slot has elements not in {%s}"),
1456 "perm",
"0,...,Dim[1]-1");
1458 FRMKMS(
_(
"'%s' slot contains duplicates"),
"perm");
1459 work[*(pperm++)] = 1;
1464 return ScalarLogical(1);
1470 int n = INTEGER(dim)[0];
1472 RMKMS(
_(
"%s is not representable as \"%s\""),
"Dim[1]+1",
"integer");
1474 SEXP type =
GET_SLOT(obj, install(
"type"));
1475 int *ptype = INTEGER(type), mono = ptype[3];
1476 if (ptype[1] != 0 && ptype[1] != 1)
1477 RMKMS(
_(
"%s[%d] (%s) is not %d or %d"),
1478 "type", 2,
"cholmod_factor.is_ll", 0, 1);
1480 RMKMS(
_(
"%s[%d] (%s) is not %d"),
1481 "type", 3,
"cholmod_factor.is_super", 0);
1482 if (ptype[3] != 0 && ptype[3] != 1)
1483 RMKMS(
_(
"%s[%d] (%s) is not %d or %d"),
1484 "type", 4,
"cholmod_factor.is_monotonic", 0, 1);
1486 SEXP nxt = PROTECT(
GET_SLOT(obj, install(
"nxt"))),
1487 prv = PROTECT(
GET_SLOT(obj, install(
"prv"))),
1488 nz = PROTECT(
GET_SLOT(obj, install(
"nz"))),
1493 if (TYPEOF(nxt) != INTSXP)
1494 RMKMS(
_(
"'%s' slot is not of type \"%s\""),
"nxt",
"integer");
1495 if (TYPEOF(prv) != INTSXP)
1496 RMKMS(
_(
"'%s' slot is not of type \"%s\""),
"prv",
"integer");
1497 if (XLENGTH(nxt) - 2 != n)
1498 RMKMS(
_(
"'%s' slot does not have length %s"),
"nxt",
"Dim[2]+2");
1499 if (XLENGTH(prv) - 2 != n)
1500 RMKMS(
_(
"'%s' slot does not have length %s"),
"prv",
"Dim[2]+2");
1501 int *pnxt = INTEGER(nxt), *pprv = INTEGER(prv),
1502 j1 = pnxt[n + 1], j2 = pprv[n], count = n + 1;
1504 if (j1 < 0 || j1 > n)
1505 RMKMS(
_(
"%s has elements not in {%s}"),
1506 "nxt[-(Dim[2]+1)]",
"0,...,Dim[2]");
1507 if (j2 < 0 || j2 > n + 1 || j2 == n)
1508 RMKMS(
_(
"%s has elements not in {%s}\\{%s}"),
1509 "prv[-(Dim[2]+2)]",
"0,...,Dim[2]+1",
"Dim[2]");
1510 if ((count > 1) && mono && (pnxt[j1] != j1 + 1 || pprv[j2] != j2 - 1))
1511 RMKMS(
_(
"%s is %d but columns are not stored in increasing order"),
1513 if ((count >= 1) ? j1 == n : j1 != n)
1514 RMKMS(
_(
"traversal of '%s' slot does not complete in exactly %s steps"),
1515 "nxt",
"length(nxt)");
1516 if ((count >= 1) ? j2 == n + 1 : j2 != n + 1)
1517 RMKMS(
_(
"traversal of '%s' slot does not complete in exactly %s steps"),
1518 "prv",
"length(prv)");
1523 RMKMS(
_(
"%s is not %d"),
"nxt[Dim[2]+1]", -1);
1525 RMKMS(
_(
"%s is not %d"),
"prv[Dim[2]+2]", -1);
1527 if (TYPEOF(nz) != INTSXP)
1528 RMKMS(
_(
"'%s' slot is not of type \"%s\""),
"nz",
"integer");
1529 if (XLENGTH(nz) != n)
1530 RMKMS(
_(
"'%s' slot does not have length %s"),
"nz",
"Dim[2]");
1531 int j, *pnz = INTEGER(nz);
1532 for (j = 0; j < n; ++j) {
1533 if (pnz[j] == NA_INTEGER)
1534 RMKMS(
_(
"'%s' slot contains NA"),
"nz");
1535 if (pnz[j] < 1 || pnz[j] > n - j)
1536 RMKMS(
_(
"%s is not in {%s}"),
"nz[j]",
"1,...,Dim[1]-j+1");
1539 if (TYPEOF(p) != INTSXP)
1540 RMKMS(
_(
"'%s' slot is not of type \"%s\""),
"p",
"integer");
1541 if (XLENGTH(p) - 1 != n)
1542 RMKMS(
_(
"'%s' slot does not have length %s"),
"p",
"Dim[2]+1");
1544 int *pp = INTEGER(p);
1546 RMKMS(
_(
"column '%s' is stored first but %s is not 0"),
"j",
"p[j]");
1547 for (j = 0; j < n; ++j) {
1549 if (pp[j2] == NA_INTEGER)
1550 RMKMS(
_(
"'%s' slot contains NA"),
"p");
1551 if (pp[j2] < pp[j1])
1552 RMKMS(
_(
"'%s' slot is not increasing when traversed in stored column order"),
"p");
1553 if (pp[j2] - pp[j1] < pnz[j1])
1554 RMKMS(
_(
"'%s' slot allocates fewer than %s elements for column '%s'"),
1556 if (pp[j2] - pp[j1] > n - j1)
1557 RMKMS(
_(
"'%s' slot allocates more than %s elements for column '%s'"),
1558 "i",
"Dim[2]-j+1",
"j");
1562 if (TYPEOF(i) != INTSXP)
1563 RMKMS(
_(
"'%s' slot is not of type \"%s\""),
"i",
"integer");
1564 if (XLENGTH(i) != pp[n])
1565 RMKMS(
_(
"'%s' slot does not have length %s"),
"i",
"p[length(p)]");
1566 int *pi = INTEGER(i), *pi_, k;
1568 for (j = 0; j < n; ++j) {
1571 RMKMS(
_(
"first entry in column '%s' does not have row index '%s'"),
1573 for (k = 1; k < pnz[j1]; ++k) {
1574 if (pi_[k] == NA_INTEGER)
1575 RMKMS(
_(
"'%s' slot contains NA"),
"i");
1576 if (pi_[k] < 0 || pi_[k] >= n)
1577 RMKMS(
_(
"'%s' slot has elements not in {%s}"),
1578 "i",
"0,...,Dim[1]-1");
1579 if (pi_[k] <= pi_[k - 1])
1580 RMKMS(
_(
"'%s' slot is not increasing within columns"),
"i");
1585 return ScalarLogical(1);
1591 int n = INTEGER(dim)[0];
1593 SEXP type =
GET_SLOT(obj, install(
"type"));
1594 int *ptype = INTEGER(type);
1596 RMKMS(
_(
"%s[%d] (%s) is not %d"),
1597 "type", 2,
"cholmod_factor.is_ll", 1);
1599 RMKMS(
_(
"%s[%d] (%s) is not %d"),
1600 "type", 3,
"cholmod_factor.is_super", 1);
1602 RMKMS(
_(
"%s[%d] (%s) is not %d"),
1603 "type", 4,
"cholmod_factor.is_monotonic", 1);
1605 RMKMS(
_(
"%s[%d] (%s) is negative"),
1606 "type", 5,
"cholmod_factor.maxcsize");
1608 RMKMS(
_(
"%s[%d] (%s) is negative"),
1609 "type", 6,
"cholmod_factor.maxesize");
1610 if (n > 0 && ptype[5] >= n)
1611 RMKMS(
_(
"%s[%d] (%s) is not less than %s"),
1612 "type", 6,
"cholmod_factor.maxesize",
"Dim[1]");
1619 SEXP super = PROTECT(
GET_SLOT(obj, install(
"super"))),
1620 pi = PROTECT(
GET_SLOT(obj, install(
"pi"))),
1621 px = PROTECT(
GET_SLOT(obj, install(
"px"))),
1622 s = PROTECT(
GET_SLOT(obj, install(
"s")));
1625 if (TYPEOF(super) != INTSXP)
1626 RMKMS(
_(
"'%s' slot is not of type \"%s\""),
"super",
"integer");
1627 R_xlen_t nsuper1a = XLENGTH(super);
1628 if (nsuper1a - 1 < ((n > 0) ? 1 : 0))
1629 RMKMS(
_(
"'%s' slot has length less than %d"),
"super", 2);
1630 if (nsuper1a - 1 > n)
1631 RMKMS(
_(
"'%s' slot has length greater than %s"),
"super",
"Dim[2]+1");
1632 int k, nsuper = (int) (nsuper1a - 1), *psuper = INTEGER(super);
1634 RMKMS(
_(
"first element of '%s' slot is not 0"),
"super");
1635 if (psuper[nsuper] != n)
1636 RMKMS(
_(
"last element of '%s' slot is not %s"),
"super",
"Dim[2]");
1637 for (k = 1; k <= nsuper; ++k) {
1638 if (psuper[k] == NA_INTEGER)
1639 RMKMS(
_(
"'%s' slot contains NA"),
"super");
1640 if (psuper[k] <= psuper[k - 1])
1641 RMKMS(
_(
"'%s' slot is not increasing"),
"super");
1644 if (TYPEOF(pi) != INTSXP)
1645 RMKMS(
_(
"'%s' slot is not of type \"%s\""),
"pi",
"integer");
1646 if (TYPEOF(px) != INTSXP)
1647 RMKMS(
_(
"'%s' slot is not of type \"%s\""),
"px",
"integer");
1648 if (XLENGTH(pi) != nsuper1a)
1649 RMKMS(
_(
"'%s' and '%s' slots do not have equal length"),
"pi",
"super");
1650 if (XLENGTH(px) != nsuper1a)
1651 RMKMS(
_(
"'%s' and '%s' slots do not have equal length"),
"px",
"super");
1652 int *ppi = INTEGER(pi), *ppx = INTEGER(px), nr, nc;
1654 RMKMS(
_(
"first element of '%s' slot is not 0"),
"pi");
1656 RMKMS(
_(
"first element of '%s' slot is not 0"),
"px");
1657 for (k = 1; k <= nsuper; ++k) {
1658 if (ppi[k] == NA_INTEGER)
1659 RMKMS(
_(
"'%s' slot contains NA"),
"pi");
1660 if (ppx[k] == NA_INTEGER)
1661 RMKMS(
_(
"'%s' slot contains NA"),
"px");
1662 if (ppi[k] <= ppi[k - 1])
1663 RMKMS(
_(
"'%s' slot is not increasing"),
"pi");
1664 if (ppx[k] <= ppx[k - 1])
1665 RMKMS(
_(
"'%s' slot is not increasing"),
"px");
1666 nr = ppi[k] - ppi[k - 1];
1667 nc = psuper[k] - psuper[k - 1];
1669 RMKMS(
_(
"first differences of '%s' slot are less than those of '%s' slot"),
1672 RMKMS(
_(
"supernode lengths exceed %s"),
"2^31-1");
1673 if (ppx[k] - ppx[k - 1] != nr * nc)
1674 RMKMS(
_(
"first differences of '%s' slot are not equal to supernode lengths"),
1678 if (TYPEOF(s) != INTSXP)
1679 RMKMS(
_(
"'%s' slot is not of type \"%s\""),
"s",
"integer");
1680 if (XLENGTH(s) != ppi[nsuper])
1681 RMKMS(
_(
"'%s' slot does not have length %s"),
"s",
"pi[length(pi)]");
1682 int i, j, *ps = INTEGER(s);
1683 for (k = 1; k <= nsuper; ++k) {
1684 nr = ppi[k] - ppi[k-1];
1685 nc = psuper[k] - (j = psuper[k-1]);
1686 for (i = 0; i < nr; ++i) {
1687 if (ps[i] == NA_INTEGER)
1688 RMKMS(
_(
"'%s' slot contains NA"),
"s");
1689 if (ps[i] < 0 || ps[i] >= n)
1690 RMKMS(
_(
"'%s' slot has elements not in {%s}"),
1691 "s",
"0,...,Dim[1]-1");
1694 RMKMS(
_(
"'%s' slot is wrong within diagonal blocks (row and column indices do not coincide)"),
"s");
1696 if (ps[i] <= ps[i-1])
1697 RMKMS(
_(
"'%s' slot is not increasing within supernodes"),
"s");
1703 return ScalarLogical(1);
1710 type = PROTECT(
GET_SLOT(obj, install(
"type")));
1713 if (TYPEOF(x) != REALSXP)
1714 RMKMS(
_(
"'%s' slot is not of type \"%s\""),
"x",
"double");
1716 int *pp = INTEGER(p), n = (int) (XLENGTH(p) - 1);
1717 if (XLENGTH(x) != pp[n])
1718 RMKMS(
_(
"'%s' slot does not have length %s"),
"x",
"p[length(p)]");
1720 if (INTEGER(type)[1]) {
1722 double *px = REAL(x);
1725 for (j = 0; j < n; ++j)
1726 if (!ISNAN(px[pp[j]]) && px[pp[j]] < 0.0)
1727 RMK(
_(
"Cholesky factor has negative diagonal elements"));
1730 return ScalarLogical(1);
1736 px = PROTECT(
GET_SLOT(obj, install(
"px"))),
1737 pi = PROTECT(
GET_SLOT(obj, install(
"pi"))),
1738 super = PROTECT(
GET_SLOT(obj, install(
"super")));
1741 if (TYPEOF(x) != REALSXP)
1742 RMKMS(
_(
"'%s' slot is not of type \"%s\""),
"x",
"double");
1744 int *ppx = INTEGER(px), nsuper = (int) (XLENGTH(px) - 1);
1745 if (XLENGTH(x) != ppx[nsuper])
1746 RMKMS(
_(
"'%s' slot does not have length %s"),
"x",
"px[length(px)]");
1748 int *ppi = INTEGER(pi), *psuper = INTEGER(super), k, j, nc;
1749 double *pu = REAL(x), *pv;
1753 for (k = 0; k < nsuper; ++k) {
1754 nc = psuper[k+1] - psuper[k];
1755 nr1a = (R_xlen_t) (ppi[k+1] - ppi[k]) + 1;
1757 for (j = 0; j < nc; ++j) {
1758 if (!ISNAN(*pv) && *pv < 0.0)
1759 RMK(
_(
"Cholesky factor has negative diagonal elements"));
1764 return ScalarLogical(1);
1772 int *pdim = INTEGER(dim), n = pdim[0];
1774 RMKMS(
_(
"%s[1] != %s[2] (matrix is not square)"),
"Dim",
"Dim");
1778 pdim = INTEGER(dim);
1780 if (pdim[0] != n || pdim[1] != n)
1781 RMKMS(
_(
"dimensions of '%s' slot are not identical to '%s'"),
"Q",
"Dim");
1785 pdim = INTEGER(dim);
1787 if (pdim[0] != n || pdim[1] != n)
1788 RMKMS(
_(
"dimensions of '%s' slot are not identical to '%s'"),
"T",
"Dim");
1790 SEXP v =
GET_SLOT(obj, install(
"EValues"));
1791 SEXPTYPE tv = TYPEOF(v);
1792 if (tv != REALSXP && tv != CPLXSXP)
1793 RMKMS(
_(
"'%s' slot is not of type \"%s\" or \"%s\""),
1794 "EValues",
"double",
"complex");
1795 if (XLENGTH(v) != n)
1796 RMKMS(
_(
"'%s' slot does not have length %s"),
"EValues",
"Dim[1]");
1798 return ScalarLogical(1);
1804#ifndef MATRIX_DISABLE_VALIDITY
1808# define IS_VALID(_CLASS_) \
1810 status = _CLASS_ ## _validate(obj); \
1811 if (TYPEOF(status) == STRSXP) \
1812 error(_("invalid class \"%s\" object: %s"), \
1813 cl, CHAR(STRING_ELT(status, 0))); \
1816#define IS_VALID_SPARSE(_C_) \
1818 IS_VALID(_C_ ## sparseMatrix); \
1819 if (cl[0] == 'n') { \
1821 IS_VALID(s ## _C_ ## Matrix); \
1822 else if (cl[1] == 't') \
1823 IS_VALID(t ## _C_ ## Matrix); \
1826 IS_VALID(xg ## _C_ ## Matrix); \
1827 else if (cl[1] == 's') \
1828 IS_VALID(xs ## _C_ ## Matrix); \
1829 else if (cl[1] == 't') \
1830 IS_VALID(xt ## _C_ ## Matrix); \
1836 if ((
cl[0] ==
'i' &&
cl[1] ==
'n' &&
cl[2] ==
'd') ||
1837 (
cl[0] ==
'p' &&
cl[1] !=
'c')) {
1844 const char *cl_ =
cl;
1847 else if (
cl[0] ==
'p' &&
cl[1] ==
'c')
1850 if (
cl[0] ==
'n' &&
cl[2] !=
'C' &&
cl[2] !=
'R' &&
cl[2] !=
'T')
1852 else if (
cl[0] ==
'l')
1854 else if (
cl[0] ==
'i')
1856 else if (
cl[0] ==
'd')
1858 else if (
cl[0] ==
'z')
1861 if (
cl[1] ==
's' ||
cl[1] ==
'p')
1863 else if (
cl[1] ==
't')
1865 else if (
cl[1] ==
'd') {
1872 else if (
cl[2] ==
'R')
1874 else if (
cl[2] ==
'T')
1876 else if (
cl[2] !=
'p') {
1892# undef IS_VALID_SPARSE
long long Matrix_int_fast64_t
#define Matrix_Free(_VAR_, _N_)
#define GET_SLOT(x, what)
#define Matrix_Calloc(_VAR_, _N_, _CTYPE_)
int equal_character_vectors(SEXP s1, SEXP s2, int n)
SEXP triangularMatrix_validate(SEXP obj)
SEXP MatrixFactorization_validate(SEXP obj)
SEXP CHMfactor_validate(SEXP obj)
SEXP symmetricMatrix_validate(SEXP obj)
SEXP tCMatrix_validate(SEXP obj)
SEXP CHMsuper_validate(SEXP obj)
char * Dim_validate(SEXP dim)
SEXP TsparseMatrix_validate(SEXP obj)
SEXP corMatrix_validate(SEXP obj)
SEXP pMatrix_validate(SEXP obj)
SEXP RsparseMatrix_validate(SEXP obj)
SEXP xgCMatrix_validate(SEXP obj)
char * DimNames_validate(SEXP dimnames, int *pdim)
SEXP diagonalMatrix_validate(SEXP obj)
SEXP copMatrix_validate(SEXP obj)
#define FRMKMS(_FORMAT_,...)
SEXP tRMatrix_validate(SEXP obj)
SEXP Schur_validate(SEXP obj)
void validObject(SEXP obj, const char *cl)
SEXP sCMatrix_validate(SEXP obj)
#define RMS(_FORMAT_,...)
SEXP CHMsimpl_validate(SEXP obj)
SEXP sparseQR_validate(SEXP obj)
SEXP BunchKaufman_validate(SEXP obj)
SEXP sparseVector_validate(SEXP obj)
SEXP packedMatrix_validate(SEXP obj)
SEXP sRMatrix_validate(SEXP obj)
SEXP xgRMatrix_validate(SEXP obj)
SEXP R_Dim_validate(SEXP dim)
SEXP sparseLU_validate(SEXP obj)
SEXP xsTMatrix_validate(SEXP obj)
SEXP Matrix_validate(SEXP obj)
SEXP R_DimNames_fixup(SEXP dimnames)
SEXP xtCMatrix_validate(SEXP obj)
#define RMKMS(_FORMAT_,...)
#define KINDMATRIX_VALIDATE(_PREFIX_, _SEXPTYPE_)
SEXP dpoMatrix_validate(SEXP obj)
SEXP R_DimNames_validate(SEXP dimnames, SEXP dim)
#define KINDVECTOR_VALIDATE(_PREFIX_, _SEXPTYPE_)
SEXP dCHMsuper_validate(SEXP obj)
#define IS_VALID_SPARSE(_C_)
SEXP xgTMatrix_validate(SEXP obj)
SEXP unpackedMatrix_validate(SEXP obj)
SEXP generalMatrix_validate(SEXP obj)
SEXP xtTMatrix_validate(SEXP obj)
SEXP xsRMatrix_validate(SEXP obj)
SEXP CsparseMatrix_validate(SEXP obj)
SEXP tTMatrix_validate(SEXP obj)
SEXP pBunchKaufman_validate(SEXP obj)
SEXP xtRMatrix_validate(SEXP obj)
SEXP indMatrix_validate(SEXP obj)
SEXP denseLU_validate(SEXP obj)
SEXP dppMatrix_validate(SEXP obj)
SEXP dCHMsimpl_validate(SEXP obj)
SEXP pCholesky_validate(SEXP obj)
SEXP sTMatrix_validate(SEXP obj)
SEXP Cholesky_validate(SEXP obj)
#define IS_VALID(_CLASS_)
SEXP xsCMatrix_validate(SEXP obj)