Skip to content

Commit

Permalink
Translated rest of UpdateRPlee11_cpp() (#11)
Browse files Browse the repository at this point in the history
  • Loading branch information
wleoncio committed Oct 23, 2024
1 parent cbc7c66 commit 8d0cb86
Showing 1 changed file with 21 additions and 19 deletions.
40 changes: 21 additions & 19 deletions src/UpdateRPlee11_cpp.cpp
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
#include <RcppArmadillo.h>
#include "misc.h"
#include "updateRP_genomic_cpp.h"
// [[Rcpp::depends(RcppArmadillo)]]
// [[Rcpp::export]]
Expand Down Expand Up @@ -28,6 +29,8 @@ Rcpp::List UpdateRPlee11_cpp(
arma::field<arma::mat> ind_r_d(S);
arma::field<arma::vec> h(S);

Rcpp::List erg;

if (method == "Pooled" && MRF_G) {
x.slice(0) = Rcpp::as<arma::mat>(sobj["X"]);
be_ini.col(0) = Rcpp::as<arma::vec>(ini["beta.ini"]);
Expand All @@ -41,7 +44,7 @@ Rcpp::List UpdateRPlee11_cpp(
double be_prop_sd_scale_value = be_prop_sd_scale(0); // Extract the first element
h(0) = Rcpp::as<arma::vec>(ini["h"]);

Rcpp::List erg = updateRP_genomic_cpp(
erg = updateRP_genomic_cpp(
p, x.slice(0), J(0), ind_r(0), ind_d(0), ind_r_d(0),
be_ini.col(0), be_prop_sd_scale_value, ga_ini.col(0),
h(0), tau, cb
Expand All @@ -50,27 +53,26 @@ Rcpp::List UpdateRPlee11_cpp(
beta_ini.col(0) = Rcpp::as<arma::vec>(erg["be.ini"]);
acceptlee.col(0) = Rcpp::as<arma::uvec>(erg["acceptl"]);
} else {
x = list_to_cube(sobj["X"]);
J = arma::conv_to<arma::uvec>::from(list_to_vector(hyperpar["J"]));
be_ini = list_to_matrix(ini["beta.ini"]);
be_prop_sd_scale = list_to_vector(hyperpar["be.prop.sd.scale"]);
ga_ini = list_to_matrix(ini["gamma.ini"]);
for (uint g = 0; g < S; ++g) { // loop through subgroups
// Basically the same as the above block, but with the g-th element of
// each. Everything is a list :()

// x <- sobj$X[[g]]
// J <- hyperpar$J[[g]]
// ind.r <- hyperpar$ind.r[[g]]
// ind.d <- hyperpar$ind.d[[g]]
// ind.r_d <- hyperpar$ind.r_d[[g]]
// be.ini <- ini$beta.ini[[g]]
// be.prop.sd.scale <- hyperpar$be.prop.sd.scale[[g]]
// ga.ini <- ini$gamma.ini[[g]]
// h <- ini$h[[g]]
double be_prop_sd_scale_value = be_prop_sd_scale(g);
h(g) = list_to_vector(ini["h"]);
ind_r(g) = list_to_matrix(hyperpar["ind.r"]);
ind_d(g) = list_to_matrix(hyperpar["ind.d"]);
ind_r_d(g) = list_to_matrix(hyperpar["ind.r_d"]);

// erg <- updateRP_genomic_cpp(
// p, x, J, ind.r, ind.d, ind.r_d,
// be.ini, be.prop.sd.scale, ga.ini, h, tau, cb
// )
erg = updateRP_genomic_cpp(
p, x.slice(g), J(g), ind_r(g), ind_d(g), ind_r_d(g),
be_ini.col(g), be_prop_sd_scale_value, ga_ini.col(g),
h(g), tau, cb
);

// beta.ini[[g]] <- as.vector(erg$be.ini)
// acceptlee[[g]] <- erg$acceptl
beta_ini.col(g) = Rcpp::as<arma::vec>(erg["be.ini"]);
acceptlee.col(g) = Rcpp::as<arma::uvec>(erg["acceptl"]);
}
}
Rcpp::List out = Rcpp::List::create(
Expand Down

0 comments on commit 8d0cb86

Please sign in to comment.