diff --git a/memcheck.R b/memcheck.R index a427f729..3d6c54d5 100644 --- a/memcheck.R +++ b/memcheck.R @@ -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(), @@ -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) diff --git a/src/mvgam.dll b/src/mvgam.dll index 860343be..df036f39 100644 Binary files a/src/mvgam.dll and b/src/mvgam.dll differ diff --git a/src/trend_funs.cpp b/src/trend_funs.cpp index fe31d4c0..8e4e30c2 100644 --- a/src/trend_funs.cpp +++ b/src/trend_funs.cpp @@ -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)]; } diff --git a/src/trend_funs.o b/src/trend_funs.o index 5b5854bc..917270cf 100644 Binary files a/src/trend_funs.o and b/src/trend_funs.o differ