Skip to content

Commit

Permalink
Getting rid of SET_TYPEOF here.
Browse files Browse the repository at this point in the history
  • Loading branch information
SebKrantz committed Jun 25, 2024
1 parent 1fc385c commit dbbf6cd
Showing 1 changed file with 11 additions and 16 deletions.
27 changes: 11 additions & 16 deletions src/flag.cpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
#include <Rcpp.h>
using namespace Rcpp;

LogicalVector intToLogical(IntegerVector x) {
return LogicalVector(x.begin(), x.end());
}

// 7th version: Irregular time series and panels supported !
template <int RTYPE>
Expand Down Expand Up @@ -569,17 +572,15 @@ List flagleadlCpp(const List& x, const IntegerVector& n = 1, const SEXP& fill =
while(i != np) outjp[i++] = ff;
for( ; i != row; ++i) outjp[i] = column[i - np];
SHALLOW_DUPLICATE_ATTRIB(outjp, column);
if(txj == LGLSXP) SET_TYPEOF(outjp, LGLSXP);
out[pos] = outjp;
out[pos] = txj == LGLSXP ? intToLogical(outjp) : outjp;
} else if(np<0) {
IntegerVector outjp = no_init_vector(row);
if(names) nam[pos] = "F" + nc[p] + "." + na[j];
int i = row, st = row+np;
while(i != st) outjp[--i] = ff;
for( ; i--; ) outjp[i] = column[i - np];
SHALLOW_DUPLICATE_ATTRIB(outjp, column);
if(txj == LGLSXP) SET_TYPEOF(outjp, LGLSXP);
out[pos] = outjp;
out[pos] = txj == LGLSXP ? intToLogical(outjp) : outjp;
} else {
if(names) nam[pos] = na[j];
out[pos] = x[j];
Expand Down Expand Up @@ -702,8 +703,7 @@ List flagleadlCpp(const List& x, const IntegerVector& n = 1, const SEXP& fill =
}
}
SHALLOW_DUPLICATE_ATTRIB(outjp, column);
if(txj == LGLSXP) SET_TYPEOF(outjp, LGLSXP);
out[pos] = outjp;
out[pos] = txj == LGLSXP ? intToLogical(outjp) : outjp;
} else if(np<0) {
IntegerVector outjp = no_init_vector(os);
if(names) nam[pos] = "F" + nc[p] + "." + na[j];
Expand All @@ -715,8 +715,7 @@ List flagleadlCpp(const List& x, const IntegerVector& n = 1, const SEXP& fill =
}
}
SHALLOW_DUPLICATE_ATTRIB(outjp, column);
if(txj == LGLSXP) SET_TYPEOF(outjp, LGLSXP);
out[pos] = outjp;
out[pos] = txj == LGLSXP ? intToLogical(outjp) : outjp;
} else {
if(names) nam[pos] = na[j];
out[pos] = x[j];
Expand Down Expand Up @@ -840,8 +839,7 @@ List flagleadlCpp(const List& x, const IntegerVector& n = 1, const SEXP& fill =
}
}
SHALLOW_DUPLICATE_ATTRIB(outjp, column);
if(txj == LGLSXP) SET_TYPEOF(outjp, LGLSXP);
out[pos] = outjp;
out[pos] = txj == LGLSXP ? intToLogical(outjp) : outjp;
} else if(np<0) {
IntegerVector outjp = no_init_vector(gss);
if(names) nam[pos] = "F" + nc[p] + "." + na[j];
Expand All @@ -855,8 +853,7 @@ List flagleadlCpp(const List& x, const IntegerVector& n = 1, const SEXP& fill =
}
}
SHALLOW_DUPLICATE_ATTRIB(outjp, column);
if(txj == LGLSXP) SET_TYPEOF(outjp, LGLSXP);
out[pos] = outjp;
out[pos] = txj == LGLSXP ? intToLogical(outjp) : outjp;
} else {
if(names) nam[pos] = na[j];
out[pos] = x[j];
Expand Down Expand Up @@ -1009,8 +1006,7 @@ List flagleadlCpp(const List& x, const IntegerVector& n = 1, const SEXP& fill =
}
}
SHALLOW_DUPLICATE_ATTRIB(outjp, column);
if(txj == LGLSXP) SET_TYPEOF(outjp, LGLSXP);
out[pos] = outjp;
out[pos] = txj == LGLSXP ? intToLogical(outjp) : outjp;
} else if(np<0) {
IntegerVector outjp = no_init_vector(gss);
if(names) nam[pos] = "F" + nc[p] + "." + na[j];
Expand All @@ -1022,8 +1018,7 @@ List flagleadlCpp(const List& x, const IntegerVector& n = 1, const SEXP& fill =
}
}
SHALLOW_DUPLICATE_ATTRIB(outjp, column);
if(txj == LGLSXP) SET_TYPEOF(outjp, LGLSXP);
out[pos] = outjp;
out[pos] = txj == LGLSXP ? intToLogical(outjp) : outjp;
} else {
if(names) nam[pos] = na[j];
out[pos] = x[j];
Expand Down

0 comments on commit dbbf6cd

Please sign in to comment.