Skip to content

Commit

Permalink
Translated a bit of hh_nlambda_loop() to C++ (#17)
Browse files Browse the repository at this point in the history
  • Loading branch information
wleoncio committed Jan 26, 2024
1 parent 08918bd commit 1ebe86d
Showing 1 changed file with 12 additions and 13 deletions.
25 changes: 12 additions & 13 deletions src/hh_nlambda_loop_cpp.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ Rcpp::List hh_nlambda_loop_cpp(
const Rcpp::List tree,
const bool my_print,
const Rcpp::List invmat,
const arma::vec gg,
const arma::mat gg,
const double tol,
const bool parallel,
const bool pal,
Expand All @@ -44,7 +44,7 @@ Rcpp::List hh_nlambda_loop_cpp(
Rcpp::List lam_list;
unsigned int hh = 1;
while (hh <= nlambda) {
// lambda <- lam[hh, ]
arma::vec lambda = lam.row(hh);

// start_time <- Sys.time()
// if (pal == 1) {
Expand All @@ -61,26 +61,24 @@ Rcpp::List hh_nlambda_loop_cpp(
// theta0 <- my_values$theta0 ### iteration
// beta_hat <- my_values$beta_hat
// y_hat <- my_values$y_hat
// }
// cost_time <- Sys.time() - start_time
// print(cost_time)
// if (parallel && pal == 0) {
}
if (parallel && pal == 0) {
// beta <- my_values[hh, ]$beta
// theta <- my_values[hh, ]$theta
// my_obj[[hh]] <- list(my_values[hh, ]$obj)
// beta0 <- my_values[hh, ]$beta0
// theta0 <- my_values[hh, ]$theta0 ### iteration
// beta_hat <- my_values[hh, ]$beta_hat
// y_hat <- my_values[hh, ]$y_hat
// } else if (parallel && pal == 0) {
} else if (parallel && pal == 0) {
// beta <- my_values[[hh]]$beta
// theta <- my_values[[hh]]$theta
// my_obj[[hh]] <- list(my_values[[hh]]$obj)
// beta0 <- my_values[[hh]]$beta0
// theta0 <- my_values[[hh]]$theta0 ### iteration
// beta_hat <- my_values[[hh]]$beta_hat
// y_hat <- my_values[[hh]]$y_hat
// }
}

// beta1 <- as(beta * (abs(beta) > tol), "sparseMatrix")
// theta1 <- as.sparse3Darray(theta * (abs(theta) > tol))
Expand All @@ -91,6 +89,7 @@ Rcpp::List hh_nlambda_loop_cpp(
// n_main_terms <- (c(n_main_terms, count_nonzero_a((beta1))))

// obj1 <- (sum(as.vector((y - y_hat)^2))) / (D * N)
double obj1 = 0; // TEMP
// obj <- c(obj, obj1)

// non_zero_theta <- (c(non_zero_theta, n_interaction_terms))
Expand All @@ -104,11 +103,11 @@ Rcpp::List hh_nlambda_loop_cpp(
// Y_HAT[[hh]] <- y_hat
// THETA[[hh]] <- as.sparse3Darray(theta1)

// if (hh == 1) {
// print(c(hh, (n_main_terms[hh]), non_zero_theta[hh], obj1))
// } else {
// print(c(hh, (n_main_terms[hh]), non_zero_theta[hh], obj[hh - 1], obj1))
// }
if (hh == 1) {
Rcpp::Rcout << hh << n_main_terms[hh] << non_zero_theta[hh] << obj1 << std::endl;
} else {
Rcpp::Rcout << hh << n_main_terms[hh] << non_zero_theta[hh] << obj[hh - 1] << obj1 << std::endl;
}
hh += 1;
}
Rcpp::List out = Rcpp::List::create(
Expand Down

0 comments on commit 1ebe86d

Please sign in to comment.