Skip to content

Commit b68d5dc

Browse files
committed
perf: avoid copying BATS state histories
1 parent e971c34 commit b68d5dc

4 files changed

Lines changed: 7 additions & 14 deletions

File tree

R/RcppExports.R

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
# Generator token: 10BE3573-1514-4C36-9D1C-5A225CD40393
33

44
calcBATS <- function(y, yHat, wTranspose, F, x, g, e) {
5-
.Call(`_forecast_calcBATS`, y, yHat, wTranspose, F, x, g, e)
5+
invisible(.Call(`_forecast_calcBATS`, y, yHat, wTranspose, F, x, g, e))
66
}
77

88
calcBATSFaster <- function(y, yHat, wTranspose, F, x, g, e, xNought, sPeriods, beta, tau, p, q) {

R/fitBATS.R

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -516,7 +516,7 @@ calcModel <- function(y, x.nought, F, g, w) {
516516
x[, 1] <- F %*% x.nought + g %*% e[, 1]
517517
y <- matrix(y, nrow = 1, ncol = length.ts)
518518

519-
loop <- calcBATS(
519+
calcBATS(
520520
y = y,
521521
yHat = y.hat,
522522
wTranspose = w$w.transpose,
@@ -526,7 +526,7 @@ calcModel <- function(y, x.nought, F, g, w) {
526526
e = e
527527
)
528528

529-
list(y.hat = loop$y.hat, e = loop$e, x = loop$x)
529+
list(y.hat = y.hat, e = e, x = x)
530530
}
531531

532532
calcLikelihood <- function(

src/RcppExports.cpp

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,10 +12,9 @@ Rcpp::Rostream<false>& Rcpp::Rcerr = Rcpp::Rcpp_cerr_get();
1212
#endif
1313

1414
// calcBATS
15-
List calcBATS(const arma::mat& y, arma::mat& yHat, const arma::mat& wTranspose, const arma::mat& F, arma::mat& x, const arma::mat& g, arma::mat& e);
15+
void calcBATS(const arma::mat& y, arma::mat& yHat, const arma::mat& wTranspose, const arma::mat& F, arma::mat& x, const arma::mat& g, arma::mat& e);
1616
RcppExport SEXP _forecast_calcBATS(SEXP ySEXP, SEXP yHatSEXP, SEXP wTransposeSEXP, SEXP FSEXP, SEXP xSEXP, SEXP gSEXP, SEXP eSEXP) {
1717
BEGIN_RCPP
18-
Rcpp::RObject rcpp_result_gen;
1918
Rcpp::RNGScope rcpp_rngScope_gen;
2019
Rcpp::traits::input_parameter< const arma::mat& >::type y(ySEXP);
2120
Rcpp::traits::input_parameter< arma::mat& >::type yHat(yHatSEXP);
@@ -24,8 +23,8 @@ BEGIN_RCPP
2423
Rcpp::traits::input_parameter< arma::mat& >::type x(xSEXP);
2524
Rcpp::traits::input_parameter< const arma::mat& >::type g(gSEXP);
2625
Rcpp::traits::input_parameter< arma::mat& >::type e(eSEXP);
27-
rcpp_result_gen = Rcpp::wrap(calcBATS(y, yHat, wTranspose, F, x, g, e));
28-
return rcpp_result_gen;
26+
calcBATS(y, yHat, wTranspose, F, x, g, e);
27+
return R_NilValue;
2928
END_RCPP
3029
}
3130
// calcBATSFaster

src/calcBATS.cpp

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
using namespace Rcpp;
55

66
// [[Rcpp::export]]
7-
List calcBATS(const arma::mat& y,
7+
void calcBATS(const arma::mat& y,
88
arma::mat& yHat,
99
const arma::mat& wTranspose,
1010
const arma::mat& F,
@@ -16,12 +16,6 @@ List calcBATS(const arma::mat& y,
1616
e(0, t) = y(0, t) - yHat(0, t);
1717
x.col(t) = F * x.col(t - 1) + g * e(0, t);
1818
}
19-
20-
return List::create(
21-
Named("y.hat") = yHat,
22-
Named("e") = e,
23-
Named("x") = x
24-
);
2519
}
2620

2721
// [[Rcpp::export]]

0 commit comments

Comments
 (0)