Skip to content

Commit

Permalink
ensure all c++ functions are checked in memcheck
Browse files Browse the repository at this point in the history
  • Loading branch information
Nicholas Clark committed May 9, 2024
1 parent d247299 commit 3a79793
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 9 deletions.
5 changes: 5 additions & 0 deletions memcheck.R
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
devtools::load_all()
library(testthat)

# Test the c++ functions, which can all be done using sim_mvgam()
# and forecast()
capture_output(sim_mvgam(family = gaussian(),
trend_model = RW()))
capture_output(sim_mvgam(family = gaussian(),
Expand All @@ -12,3 +15,5 @@ capture_output(sim_mvgam(family = gaussian(),
trend_model = VAR()))
capture_output(sim_mvgam(family = gaussian(),
trend_model = VAR(cor = TRUE)))
fc <- forecast(mvgam:::mvgam_example1,
newdata = mvgam:::mvgam_examp_dat$data_test)
Binary file modified src/mvgam.dll
Binary file not shown.
18 changes: 9 additions & 9 deletions src/trend_funs.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,17 +16,17 @@ Rcpp::NumericVector ar3_recursC(double drift, double ar1,

int T = h + 3;
Rcpp::NumericVector states(T);
states[0] = last_trends[0];
states[1] = last_trends[1];
states[2] = last_trends[2];
states(0) = last_trends(0);
states(1) = last_trends(1);
states(2) = last_trends(2);

for(int t = 3; t < T; ++t) {
states[t] = drift +
ar1 * (states[t - 1] - linpreds[t - 1]) +
ar2 * (states[t - 2] - linpreds[t - 2]) +
ar3 * (states[t - 3] - linpreds[t - 3]) +
linpreds[t] +
errors[t];
states(t) = drift +
ar1 * (states(t - 1) - linpreds(t - 1)) +
ar2 * (states(t - 2) - linpreds(t - 2)) +
ar3 * (states(t - 3) - linpreds(t - 3)) +
linpreds(t) +
errors(t);
}
return states[Rcpp::Range(3, T-1)];
}
Expand Down
Binary file modified src/trend_funs.o
Binary file not shown.

0 comments on commit 3a79793

Please sign in to comment.