Skip to content

Commit cff25f2

Browse files
committed
Avoid arma::cube
1 parent 67f0faf commit cff25f2

File tree

7 files changed

+163
-167
lines changed

7 files changed

+163
-167
lines changed

DESCRIPTION

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
Package: bootUR
22
Type: Package
33
Title: Bootstrap Unit Root Tests
4-
Version: 1.0.1
4+
Version: 1.0.2
55
Authors@R: c(
66
person("Stephan", "Smeekes", email = "s.smeekes@maastrichtuniversity.nl", role = c("cre", "aut"),
77
comment = c(ORCID = "0000-0002-0157-639X")),

NEWS.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
1-
## Version 1.0.1
1+
## Version 1.0.2
22

33
### Bug Fixes
4-
* Fixed the CRAN check Additional Issues.
4+
* Fixed the CRAN check Additional Issues LTO warnings by avoiding the use of arma::cube in C++ code.
55

66
## Version 1.0.0
77

R/RcppExports.R

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -17,12 +17,12 @@ bootstrap_cpp <- function(B, u, e, boot, l, s, ar, ar_est, y0, pmin, pmax, ic, d
1717
.Call(`_bootUR_bootstrap_cpp`, B, u, e, boot, l, s, ar, ar_est, y0, pmin, pmax, ic, dc, detr, ic_scale, h_rs, range, joint, do_parallel, show_progress)
1818
}
1919

20-
scaling_factors_cpp <- function(u, prob) {
21-
.Call(`_bootUR_scaling_factors_cpp`, u, prob)
20+
scaling_factors_cpp <- function(u, D, prob) {
21+
.Call(`_bootUR_scaling_factors_cpp`, u, D, prob)
2222
}
2323

24-
union_tests_cpp <- function(t, s) {
25-
.Call(`_bootUR_union_tests_cpp`, t, s)
24+
union_tests_cpp <- function(t, D, s) {
25+
.Call(`_bootUR_union_tests_cpp`, t, D, s)
2626
}
2727

2828
union_test_cpp <- function(t, s) {

R/auxiliary.R

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -97,12 +97,15 @@ do_tests_and_bootstrap <- function(data, boot_sqt_test, boot_ur_test, level, boo
9797
u_boot[is.nan(u_boot)] <- NA
9898
res <- panel_est$res
9999
ar_est <- panel_est$par[-1, , drop = FALSE]
100-
t_star <- bootstrap_cpp(B = B, boot = boot, u = u_boot, e = res, l = l, s = s_DWB,
100+
t_star_mat <- bootstrap_cpp(B = B, boot = boot, u = u_boot, e = res, l = l, s = s_DWB,
101101
ar = ar_AWB, ar_est = ar_est, y0 = matrix(0, ncol = N),
102102
pmin = min_lag, pmax = max_lag, ic = ic, dc = dc, detr = detr_int,
103103
ic_scale = criterion_scale, h_rs = h_rs, range = range_nonmiss,
104104
joint = joint, show_progress = show_progress,
105105
do_parallel = do_parallel)
106+
107+
D <- length(dc) * length(detr_int)
108+
t_star <- array(t_star_mat, dim = c(B, D * N))
106109

107110
tests <- adf_tests_panel_cpp(data, pmin = min_lag, pmax = max_lag, ic = ic,
108111
dc = dc, detr = detr_int, ic_scale = criterion_scale,
@@ -112,19 +115,16 @@ do_tests_and_bootstrap <- function(data, boot_sqt_test, boot_ur_test, level, boo
112115
lags_ind <- tests$lags # Selected lag lengths
113116

114117
pvals <- matrix(iADF_cpp(matrix(tests_ind, nrow = 1),
115-
matrix(t_star, nrow = B)), nrow = N, ncol = 4, byrow = TRUE)
118+
matrix(t_star, nrow = B)), nrow = N, ncol = D, byrow = TRUE)
116119
if (union) {
117-
pvals <- matrix(iADF_cpp(matrix(tests_ind, nrow = 1),
118-
matrix(t_star, nrow = B)), nrow = N, ncol = 4, byrow = TRUE)
119-
scaling <- scaling_factors_cpp(t_star, level)
120+
scaling <- scaling_factors_cpp(t_star, D, level)
120121
if (N > 1) {
121-
test_stats_star <- union_tests_cpp(t_star, scaling)
122-
test_stats <- union_tests_cpp(array(tests_ind, dim = c(1, length(dc) * length(detr_int), N)),
122+
test_stats_star <- union_tests_cpp(t_star, D, scaling)
123+
test_stats <- union_tests_cpp(array(tests_ind, dim = c(1, D * N)), D,
123124
scaling)
124125
} else {
125-
test_stats_star <- union_test_cpp(t_star[, , 1], scaling)
126-
test_stats <- union_test_cpp(array(tests_ind,
127-
dim = c(1, length(dc) * length(detr_int))), scaling)
126+
test_stats_star <- union_test_cpp(t_star, scaling)
127+
test_stats <- union_test_cpp(array(tests_ind, dim = c(1, D)), scaling)
128128
}
129129
} else {
130130
pvals <- matrix(iADF_cpp(matrix(tests_ind, nrow = 1),

R/bootURtests.R

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -155,7 +155,7 @@ boot_ur <- function(data, data_name = NULL, bootstrap = "AWB", B = 1999, block_l
155155
function(x,y){paste0(x, "/", y)})))
156156
} else { # No union test
157157
iADFout <- iADF_cpp(test_i = matrix(inputs$indiv_test_stats[1, ], nrow = 1),
158-
t_star = matrix(inputs$t_star[ , 1, ], nrow = B))
158+
t_star = matrix(inputs$t_star, nrow = B))
159159
iADFout <- cbind(t(inputs$indiv_par_est), t(inputs$indiv_test_stats), iADFout)
160160
# Parameter estimates, tstats and p-values
161161

@@ -513,7 +513,7 @@ boot_fdr <- function(data, data_name = NULL, bootstrap = "AWB", B = 1999, block_
513513
function(x,y){paste0(x, "/", y)})))
514514
} else { # No Union Tests
515515
bFDRout <- FDR_cpp(test_i = matrix(inputs$indiv_test_stats[1, ], nrow = 1),
516-
t_star = inputs$t_star[ , 1,], level = inputs$level)
516+
t_star = inputs$t_star, level = inputs$level)
517517
estimates <- t(inputs$indiv_par_est)
518518
tstats <- drop(inputs$tests_i[1, ])
519519
method_name <- paste0(bootstrap, " bootstrap ", inputs$inputs$name, " tests (with " ,
@@ -683,7 +683,7 @@ boot_sqt <- function(data, data_name = NULL, steps = 0:NCOL(data), bootstrap = "
683683
} else { # No Union Tests
684684
BSQTout <- BSQT_cpp(pvec = inputs$p_vec,
685685
test_i = matrix(inputs$indiv_test_stats[1, ], nrow = 1),
686-
t_star = inputs$t_star[ , 1,], level = inputs$level)
686+
t_star = inputs$t_star, level = inputs$level)
687687
estimates <- t(inputs$indiv_par_est)
688688
tstats <- drop(inputs$indiv_test_stats)
689689
method_name <- paste0(bootstrap, " bootstrap sequential quantile ",

src/RcppExports.cpp

Lines changed: 13 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@ BEGIN_RCPP
7171
END_RCPP
7272
}
7373
// bootstrap_cpp
74-
arma::cube bootstrap_cpp(const int& B, const arma::mat& u, const arma::mat& e, const int& boot, const int& l, const arma::mat& s, const double& ar, const arma::mat& ar_est, const arma::mat& y0, const int& pmin, const int& pmax, const int& ic, const arma::vec& dc, const arma::vec& detr, const bool& ic_scale, const double& h_rs, const arma::umat& range, const bool& joint, const bool& do_parallel, const bool& show_progress);
74+
arma::mat bootstrap_cpp(const int& B, const arma::mat& u, const arma::mat& e, const int& boot, const int& l, const arma::mat& s, const double& ar, const arma::mat& ar_est, const arma::mat& y0, const int& pmin, const int& pmax, const int& ic, const arma::vec& dc, const arma::vec& detr, const bool& ic_scale, const double& h_rs, const arma::umat& range, const bool& joint, const bool& do_parallel, const bool& show_progress);
7575
RcppExport SEXP _bootUR_bootstrap_cpp(SEXP BSEXP, SEXP uSEXP, SEXP eSEXP, SEXP bootSEXP, SEXP lSEXP, SEXP sSEXP, SEXP arSEXP, SEXP ar_estSEXP, SEXP y0SEXP, SEXP pminSEXP, SEXP pmaxSEXP, SEXP icSEXP, SEXP dcSEXP, SEXP detrSEXP, SEXP ic_scaleSEXP, SEXP h_rsSEXP, SEXP rangeSEXP, SEXP jointSEXP, SEXP do_parallelSEXP, SEXP show_progressSEXP) {
7676
BEGIN_RCPP
7777
Rcpp::RObject rcpp_result_gen;
@@ -101,26 +101,28 @@ BEGIN_RCPP
101101
END_RCPP
102102
}
103103
// scaling_factors_cpp
104-
arma::mat scaling_factors_cpp(const arma::cube& u, const double& prob);
105-
RcppExport SEXP _bootUR_scaling_factors_cpp(SEXP uSEXP, SEXP probSEXP) {
104+
arma::mat scaling_factors_cpp(const arma::mat& u, const int& D, const double& prob);
105+
RcppExport SEXP _bootUR_scaling_factors_cpp(SEXP uSEXP, SEXP DSEXP, SEXP probSEXP) {
106106
BEGIN_RCPP
107107
Rcpp::RObject rcpp_result_gen;
108108
Rcpp::RNGScope rcpp_rngScope_gen;
109-
Rcpp::traits::input_parameter< const arma::cube& >::type u(uSEXP);
109+
Rcpp::traits::input_parameter< const arma::mat& >::type u(uSEXP);
110+
Rcpp::traits::input_parameter< const int& >::type D(DSEXP);
110111
Rcpp::traits::input_parameter< const double& >::type prob(probSEXP);
111-
rcpp_result_gen = Rcpp::wrap(scaling_factors_cpp(u, prob));
112+
rcpp_result_gen = Rcpp::wrap(scaling_factors_cpp(u, D, prob));
112113
return rcpp_result_gen;
113114
END_RCPP
114115
}
115116
// union_tests_cpp
116-
arma::mat union_tests_cpp(const arma::cube& t, arma::mat& s);
117-
RcppExport SEXP _bootUR_union_tests_cpp(SEXP tSEXP, SEXP sSEXP) {
117+
arma::mat union_tests_cpp(const arma::mat& t, const int& D, arma::mat& s);
118+
RcppExport SEXP _bootUR_union_tests_cpp(SEXP tSEXP, SEXP DSEXP, SEXP sSEXP) {
118119
BEGIN_RCPP
119120
Rcpp::RObject rcpp_result_gen;
120121
Rcpp::RNGScope rcpp_rngScope_gen;
121-
Rcpp::traits::input_parameter< const arma::cube& >::type t(tSEXP);
122+
Rcpp::traits::input_parameter< const arma::mat& >::type t(tSEXP);
123+
Rcpp::traits::input_parameter< const int& >::type D(DSEXP);
122124
Rcpp::traits::input_parameter< arma::mat& >::type s(sSEXP);
123-
rcpp_result_gen = Rcpp::wrap(union_tests_cpp(t, s));
125+
rcpp_result_gen = Rcpp::wrap(union_tests_cpp(t, D, s));
124126
return rcpp_result_gen;
125127
END_RCPP
126128
}
@@ -199,8 +201,8 @@ static const R_CallMethodDef CallEntries[] = {
199201
{"_bootUR_adf_tests_panel_cpp", (DL_FUNC) &_bootUR_adf_tests_panel_cpp, 9},
200202
{"_bootUR_adf_panel_bootstrap_dgp_cpp", (DL_FUNC) &_bootUR_adf_panel_bootstrap_dgp_cpp, 10},
201203
{"_bootUR_bootstrap_cpp", (DL_FUNC) &_bootUR_bootstrap_cpp, 20},
202-
{"_bootUR_scaling_factors_cpp", (DL_FUNC) &_bootUR_scaling_factors_cpp, 2},
203-
{"_bootUR_union_tests_cpp", (DL_FUNC) &_bootUR_union_tests_cpp, 2},
204+
{"_bootUR_scaling_factors_cpp", (DL_FUNC) &_bootUR_scaling_factors_cpp, 3},
205+
{"_bootUR_union_tests_cpp", (DL_FUNC) &_bootUR_union_tests_cpp, 3},
204206
{"_bootUR_union_test_cpp", (DL_FUNC) &_bootUR_union_test_cpp, 2},
205207
{"_bootUR_BSQT_cpp", (DL_FUNC) &_bootUR_BSQT_cpp, 4},
206208
{"_bootUR_iADF_cpp", (DL_FUNC) &_bootUR_iADF_cpp, 2},

0 commit comments

Comments
 (0)