Skip to content

Commit 26ff0f9

Browse files
committed
streamline scalars in src
1 parent f37eb38 commit 26ff0f9

File tree

4 files changed

+4
-25
lines changed

4 files changed

+4
-25
lines changed

src/logmeanexp.c

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -5,11 +5,9 @@
55
// Compute log(mean(exp(X))) accurately,
66
// optionally with one element dropped
77
SEXP logmeanexp (const SEXP X, const SEXP Drop) {
8-
SEXP ans;
9-
PROTECT(ans = NEW_NUMERIC(1));
108
int j, n = LENGTH(X);
119
int k = *INTEGER(Drop)-1; // zero-based index
12-
double *x = REAL(X), *a = REAL(ans);
10+
double *x = REAL(X);
1311
long double m = R_NegInf;
1412
long double s = 0;
1513
for (j = 0; j < n; j++) {
@@ -21,7 +19,5 @@ SEXP logmeanexp (const SEXP X, const SEXP Drop) {
2119
s += expl((long double) x[j] - m);
2220
}
2321
if (k >= 0 && k < n) n--;
24-
*a = m + log(s/n);
25-
UNPROTECT(1);
26-
return ans;
22+
return ScalarReal(m + log(s/n));
2723
}

src/pomp_internal.h

Lines changed: 0 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -14,20 +14,4 @@
1414
#define err(...) errorcall(R_NilValue,__VA_ARGS__)
1515
#define warn(...) warningcall(R_NilValue,__VA_ARGS__)
1616

17-
static R_INLINE SEXP trueSEXP (void) {
18-
SEXP x;
19-
PROTECT(x = NEW_LOGICAL(1));
20-
*LOGICAL(x) = 1;
21-
UNPROTECT(1);
22-
return x;
23-
}
24-
25-
static R_INLINE SEXP falseSEXP (void) {
26-
SEXP x;
27-
PROTECT(x = NEW_LOGICAL(1));
28-
*LOGICAL(x) = 0;
29-
UNPROTECT(1);
30-
return x;
31-
}
32-
3317
#endif

src/rinit.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -258,7 +258,7 @@ static SEXP pomp_default_rinit (SEXP params, SEXP Pnames,
258258

259259
// extract names of IVPs using 'grep'
260260
PROTECT(pat = mkString("[\\_\\.]0$"));
261-
PROTECT(fcall = LCONS(trueSEXP(),R_NilValue));
261+
PROTECT(fcall = LCONS(ScalarLogical(1),R_NilValue));
262262
SET_TAG(fcall,install("value"));
263263
PROTECT(fcall = LCONS(Pnames,fcall));
264264
SET_TAG(fcall,install("x"));

src/wpfilter.c

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -55,8 +55,7 @@ SEXP wpfilter (SEXP X, SEXP Params, SEXP Weights, SEXP W, SEXP Trigger, SEXP Tar
5555

5656
if (ISNAN(*xW) || *xW == R_PosInf) { // check the weights
5757
SEXP rv;
58-
PROTECT(rv = NEW_INTEGER(1)); nprotect++;
59-
*INTEGER(rv) = k+1; // return the index of the peccant particle
58+
PROTECT(rv = ScalarInteger(k+1)); nprotect++;
6059
UNPROTECT(nprotect);
6160
return rv;
6261
}

0 commit comments

Comments
 (0)