Skip to content

Commit

Permalink
clean up 'pomp.h'; full coverage
Browse files Browse the repository at this point in the history
  • Loading branch information
kingaa committed Jul 27, 2017
1 parent 446bb6c commit 186bc41
Show file tree
Hide file tree
Showing 5 changed files with 36 additions and 9 deletions.
2 changes: 1 addition & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ matrix:
- jimhester/covr
after_success:
- grep -q -R "warning" "${RCHECK_DIR}/00install.out"
- travis_wait 30 Rscript -e 'covr::codecov(line_exclusions="src/pomp.h")'
- travis_wait 30 Rscript -e 'covr::codecov()'
- os: linux
env: RVERSION=3.1.2
after_success:
Expand Down
3 changes: 0 additions & 3 deletions inst/include/pomp.h
Original file line number Diff line number Diff line change
Expand Up @@ -143,9 +143,6 @@ static R_INLINE double deulermultinom (int m, double size, const double *rate,
if ((n > 0) && (p > 0)) {
if (rate[k] > p) p = rate[k];
ff += dbinom(trans[k],n,rate[k]/p,1);
} else if (trans[k] > 0.0) {
ff = R_NegInf;
return ff;
}
n -= trans[k];
p -= rate[k];
Expand Down
3 changes: 0 additions & 3 deletions src/pomp.h
Original file line number Diff line number Diff line change
Expand Up @@ -143,9 +143,6 @@ static R_INLINE double deulermultinom (int m, double size, const double *rate,
if ((n > 0) && (p > 0)) {
if (rate[k] > p) p = rate[k];
ff += dbinom(trans[k],n,rate[k]/p,1);
} else if (trans[k] > 0.0) {
ff = R_NegInf;
return ff;
}
n -= trans[k];
p -= rate[k];
Expand Down
7 changes: 6 additions & 1 deletion tests/eulermultinom.R
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,17 @@ reulermultinom(n=1,size=100,rate=c(1,2e400,3),dt=0.1)
reulermultinom(n=1,size=100,rate=c(1,2,3),dt=c(0.1,0.2,0.3,Inf))
reulermultinom(n=1,size=c(100,200,300),rate=c(1,2,3),dt=0.2)
reulermultinom(n=1,size=0,rate=c(1,2,3),dt=0.2)
reulermultinom(n=1,size=10,rate=c(1,Inf,1),0.1)
reulermultinom(n=1,size=Inf,rate=c(1,100,1),0.1)
x <- reulermultinom(n=3,size=100,rate=c(3,2,1),dt=0.1)
try(deulermultinom(rbind(x,c(0,1,0)),size=100,rate=c(3,2,1),dt=0.1))
deulermultinom(x,size=c(100,NA),rate=c(3,2,1),dt=0.1)
deulermultinom(x,size=100,rate=c(3,2,1),dt=c(0.1,0.2,0.3,Inf))
deulermultinom(x,size=100,rate=c(3,2,1),dt=Inf)
deulermultinom(x=c(3,4,0),size=10,rate=c(1,1,1),dt=0-.1)
deulermultinom(x=c(3,4,0),size=10,rate=c(1,1,-1),dt=0.1)
deulermultinom(x=c(3,-4,0),size=10,rate=c(1,1,1),dt=0.1)
deulermultinom(x=c(3,6,3),size=10,rate=c(1,1,0),dt=0.1,log=TRUE)
rgammawn(n=5,sigma=2,dt=0.1)
rgammawn(n=5,sigma=1:5,dt=0.1)
rgammawn(n=5,sigma=1,dt=rep(1,5))
Expand All @@ -26,4 +32,3 @@ rgammawn(n=2,sigma=-5,dt=1)
rgammawn(n=2,sigma=10,dt=-1)
rgammawn(n=2,sigma=0,dt=1)
try(rgammawn(n=-5,sigma=-5,dt=-1))

30 changes: 29 additions & 1 deletion tests/eulermultinom.Rout.save
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,23 @@ in 'reulermultinom': only the first element of 'size' is meaningful
[1,] 0
[2,] 0
[3,] 0
> reulermultinom(n=1,size=10,rate=c(1,Inf,1),0.1)
[,1]
[1,] 0
[2,] NaN
[3,] NaN
Warning messages:
1: in 'reulermultinom': result of binomial draw is not finite
2: in 'reulermultinom': result of binomial draw is not finite
> reulermultinom(n=1,size=Inf,rate=c(1,100,1),0.1)
[,1]
[1,] 0
[2,] 0
[3,] NaN
Warning messages:
1: in 'reulermultinom': result of binomial draw is not finite
2: in 'reulermultinom': result of binomial draw is not finite
3: in 'reulermultinom': result of binomial draw is not finite
> x <- reulermultinom(n=3,size=100,rate=c(3,2,1),dt=0.1)
> try(deulermultinom(rbind(x,c(0,1,0)),size=100,rate=c(3,2,1),dt=0.1))
Error : in ‘deulermultinom’: NROW('x') should match length of 'rate'
Expand All @@ -93,6 +110,18 @@ Warning message:
in 'deulermultinom': only the first element of 'dt' is meaningful
> deulermultinom(x,size=100,rate=c(3,2,1),dt=Inf)
[1] 0 0 0
> deulermultinom(x=c(3,4,0),size=10,rate=c(1,1,1),dt=0-.1)
[1] NaN
Warning message:
in 'deulermultinom': NaNs produced
> deulermultinom(x=c(3,4,0),size=10,rate=c(1,1,-1),dt=0.1)
[1] NaN
Warning message:
in 'deulermultinom': NaNs produced
> deulermultinom(x=c(3,-4,0),size=10,rate=c(1,1,1),dt=0.1)
[1] 0
> deulermultinom(x=c(3,6,3),size=10,rate=c(1,1,0),dt=0.1,log=TRUE)
[1] -Inf
> rgammawn(n=5,sigma=2,dt=0.1)
[1] 2.593438e-18 2.417425e-05 5.489565e-25 1.344180e-18 3.775061e-03
> rgammawn(n=5,sigma=1:5,dt=0.1)
Expand All @@ -110,4 +139,3 @@ in 'deulermultinom': only the first element of 'dt' is meaningful
> try(rgammawn(n=-5,sigma=-5,dt=-1))
Error : in ‘rgammwn’: negative length vectors are not allowed
>
>

0 comments on commit 186bc41

Please sign in to comment.