4int isPerm(
const int *p,
int n,
int off)
12 for (i = 0; i < n; ++i) {
13 if (p[i] == NA_INTEGER || (j = p[i] - off) < 0 || j >= n || work[j]) {
26 error(
_(
"attempt to get sign of non-permutation"));
41 while (pos < n && work[pos])
48void invertPerm(
const int *p,
int *ip,
int n,
int off,
int ioff)
51 error(
_(
"attempt to invert non-permutation"));
53 for (j = 0; j < n; ++j)
54 ip[p[j] - off] = j + ioff;
58void asPerm(
const int *p,
int *ip,
int m,
int n,
int off,
int ioff)
61 for (i = 0; i < n; ++i)
63 for (i = 0; i < m; ++i) {
66 error(
_(
"invalid transposition vector"));
78 if (TYPEOF(p) != INTSXP)
79 error(
_(
"'%s' is not of type \"%s\""),
"p",
"integer");
80 if (TYPEOF(off) != INTSXP)
81 error(
_(
"'%s' is not of type \"%s\""),
"off",
"integer");
82 if (XLENGTH(off) != 1)
83 error(
_(
"'%s' does not have length %d"),
"off", 1);
84 int off_ = INTEGER(off)[0];
85 if (off_ == NA_INTEGER)
86 error(
_(
"'%s' is NA"),
"off");
87 R_xlen_t n_ = XLENGTH(p);
89 return ScalarLogical(0);
90 return ScalarLogical(
isPerm(INTEGER(p), (
int) n_, off_));
95 if (TYPEOF(p) != INTSXP)
96 error(
_(
"'%s' is not of type \"%s\""),
"p",
"integer");
97 if (TYPEOF(off) != INTSXP)
98 error(
_(
"'%s' is not of type \"%s\""),
"off",
"integer");
99 if (XLENGTH(off) != 1)
100 error(
_(
"'%s' does not have length %d"),
"off", 1);
101 int off_ = INTEGER(off)[0];
102 if (off_ == NA_INTEGER)
103 error(
_(
"'%s' is NA"),
"off");
104 R_xlen_t n_ = XLENGTH(p);
106 error(
_(
"attempt to get sign of non-permutation"));
107 return ScalarInteger(
signPerm(INTEGER(p), (
int) n_, off_));
112 if (TYPEOF(p) != INTSXP)
113 error(
_(
"'%s' is not of type \"%s\""),
"p",
"integer");
114 if (TYPEOF(off) != INTSXP || TYPEOF(ioff) != INTSXP)
115 error(
_(
"'%s' or '%s' is not of type \"%s\""),
"off",
"ioff",
"integer");
116 if (XLENGTH(off) != 1 || XLENGTH(ioff) != 1)
117 error(
_(
"'%s' or '%s' does not have length %d"),
"off",
"ioff", 1);
118 int off_ = INTEGER(off)[0], ioff_ = INTEGER(ioff)[0];
119 if (off_ == NA_INTEGER || ioff_ == NA_INTEGER)
120 error(
_(
"'%s' or '%s' is NA"),
"off",
"ioff");
121 R_xlen_t n_ = XLENGTH(p);
123 error(
_(
"attempt to invert non-permutation"));
124 SEXP ip = PROTECT(allocVector(INTSXP, n_));
125 invertPerm(INTEGER(p), INTEGER(ip), (
int) n_, off_, ioff_);
132 if (TYPEOF(p) != INTSXP)
133 error(
_(
"'%s' is not of type \"%s\""),
"p",
"integer");
134 R_xlen_t m_ = XLENGTH(p);
136 error(
_(
"'%s' has length exceeding %s"),
"p",
"2^31-1");
137 if (TYPEOF(off) != INTSXP || TYPEOF(ioff) != INTSXP)
138 error(
_(
"'%s' or '%s' is not of type \"%s\""),
"off",
"ioff",
"integer");
139 if (XLENGTH(off) != 1 || XLENGTH(ioff) != 1)
140 error(
_(
"'%s' or '%s' does not have length %d"),
"off",
"ioff", 1);
141 int off_ = INTEGER(off)[0], ioff_ = INTEGER(ioff)[0];
142 if (off_ == NA_INTEGER || ioff_ == NA_INTEGER)
143 error(
_(
"'%s' or '%s' is NA"),
"off",
"ioff");
144 if (TYPEOF(n) != INTSXP)
145 error(
_(
"'%s' is not of type \"%s\""),
"n",
"integer");
147 error(
_(
"'%s' does not have length %d"),
"n", 1);
148 int n_ = INTEGER(n)[0];
149 if (n_ == NA_INTEGER || n_ < m_)
150 error(
_(
"'%s' is NA or less than %s"),
"n",
"length(p)");
151 SEXP ip = PROTECT(allocVector(INTSXP, n_));
152 asPerm(INTEGER(p), INTEGER(ip), (
int) m_, n_, off_, ioff_);
#define Matrix_Free(_VAR_, _N_)
#define Matrix_Calloc(_VAR_, _N_, _CTYPE_)
void asPerm(const int *p, int *ip, int m, int n, int off, int ioff)
int isPerm(const int *p, int n, int off)
SEXP R_invertPerm(SEXP p, SEXP off, SEXP ioff)
void invertPerm(const int *p, int *ip, int n, int off, int ioff)
int signPerm(const int *p, int n, int off)
SEXP R_isPerm(SEXP p, SEXP off)
SEXP R_asPerm(SEXP p, SEXP off, SEXP ioff, SEXP n)
SEXP R_signPerm(SEXP p, SEXP off)