Skip to content

Commit

Permalink
Merge branch 'bitwise-instead-of-logical' of github.com:/catavallejos…
Browse files Browse the repository at this point in the history
…/BASiCS into bitwise-instead-of-logical
  • Loading branch information
alanocallaghan committed May 28, 2024
2 parents 3a3e2b3 + de5a0e1 commit f343d35
Show file tree
Hide file tree
Showing 8 changed files with 22 additions and 22 deletions.
4 changes: 2 additions & 2 deletions src/MCMC.h
Original file line number Diff line number Diff line change
Expand Up @@ -337,7 +337,7 @@ Rcpp::List BASiCS_MCMCcpp(
}

// STORAGE OF DRAWS
if((i%Thin==0) & (i>=Burn)) {
if((i%Thin==0) && (i>=Burn)) {
mu.col(i/Thin - Burn/Thin) = muAux.col(0);
delta.col(i/Thin - Burn/Thin) = deltaAux.col(0);
phi.col(i/Thin - Burn/Thin) = phiAux;
Expand All @@ -355,7 +355,7 @@ Rcpp::List BASiCS_MCMCcpp(
}

// PRINT IN CONSOLE SAMPLED VALUES FOR FEW SELECTED PARAMETERS
if((i%(2*Thin) == 0) & (PrintProgress == 1)) {
if((i%(2*Thin) == 0) && (PrintProgress == 1)) {
CurrentIter(i, N);
Rcout << "mu (gene 1): " << muAux(0,0) << std::endl;
Rcout << "delta (gene 1): " << deltaAux(0,0) << std::endl;
Expand Down
4 changes: 2 additions & 2 deletions src/MCMCNoSpikes.h
Original file line number Diff line number Diff line change
Expand Up @@ -352,7 +352,7 @@ Rcpp::List BASiCS_MCMCcppNoSpikes(
}

// STORAGE OF DRAWS
if((i%Thin==0) & (i>=Burn)) {
if((i%Thin==0) && (i>=Burn)) {
mu.row(i/Thin - Burn/Thin) = muAux.col(0).t();
delta.row(i/Thin - Burn/Thin) = deltaAux.col(0).t();
s.row(i/Thin - Burn/Thin) = sAux.t();
Expand All @@ -369,7 +369,7 @@ Rcpp::List BASiCS_MCMCcppNoSpikes(


// PRINT IN CONSOLE SAMPLED VALUES FOR FEW SELECTED PARAMETERS
if((i%(2*Thin) == 0) & (PrintProgress == 1)) {
if((i%(2*Thin) == 0) && (PrintProgress == 1)) {
CurrentIter(i, N);
Rcpp::Rcout << "mu (gene 1): " << muAux(0,0) << std::endl;
Rcpp::Rcout << "delta (gene 1): " << deltaAux(0,0) << std::endl;
Expand Down
6 changes: 3 additions & 3 deletions src/MCMCReg.h
Original file line number Diff line number Diff line change
Expand Up @@ -380,7 +380,7 @@ Rcpp::List BASiCS_MCMCcppReg(
V1 = (inv_V0 * globalExponent) + X.t() * diagmat(lambdaAux) * X;
VAux = inv(V1);

if ((det(V1) != 0) & all(arma::eig_sym(sigma2Aux * VAux) > 0)) {
if ((det(V1) != 0) && all(arma::eig_sym(sigma2Aux * VAux) > 0)) {
mAux = X.t() * (lambdaAux % log(deltaAux.col(0))) + (InvVm0 * globalExponent);
mAux = VAux*mAux;

Expand Down Expand Up @@ -454,7 +454,7 @@ Rcpp::List BASiCS_MCMCcppReg(
}

// STORAGE OF DRAWS
if((i%Thin==0) & (i>=Burn)) {
if((i%Thin==0) && (i>=Burn)) {
mu.col(i/Thin - Burn/Thin) = muAux.col(0);
delta.col(i/Thin - Burn/Thin) = deltaAux.col(0);
phi.col(i/Thin - Burn/Thin) = phiAux;
Expand All @@ -478,7 +478,7 @@ Rcpp::List BASiCS_MCMCcppReg(
}

// PRINT IN CONSOLE SAMPLED VALUES FOR FEW SELECTED PARAMETERS
if((i%(2*Thin) == 0) & (PrintProgress == 1)) {
if((i%(2*Thin) == 0) && (PrintProgress == 1)) {
CurrentIter(i, N);
Rcout << "mu (gene 1): " << muAux(0,0) << std::endl;
Rcout << "delta (gene 1): " << deltaAux(0,0) << std::endl;
Expand Down
6 changes: 3 additions & 3 deletions src/MCMCRegNoSpikes.h
Original file line number Diff line number Diff line change
Expand Up @@ -379,7 +379,7 @@ Rcpp::List BASiCS_MCMCcppRegNoSpikes(
// UPDATES OF REGRESSION RELATED PARAMETERS
V1 = (inv_V0 * geneExponent) + X.t() * diagmat(lambdaAux) * X;
VAux = inv(V1);
if((det(V1)!=0) & all(arma::eig_sym(sigma2Aux * VAux) > 0)) {
if((det(V1)!=0) && all(arma::eig_sym(sigma2Aux * VAux) > 0)) {
mAux = X.t() * (lambdaAux % log(deltaAux.col(0))) + (InvVm0 * geneExponent);
mAux = VAux * mAux;

Expand Down Expand Up @@ -450,7 +450,7 @@ Rcpp::List BASiCS_MCMCcppRegNoSpikes(
}

// STORAGE OF DRAWS
if((i%Thin==0) & (i>=Burn)) {
if((i%Thin==0) && (i>=Burn)) {
mu.col(i/Thin - Burn/Thin) = muAux.col(0);
delta.col(i/Thin - Burn/Thin) = deltaAux.col(0);
s.col(i/Thin - Burn/Thin) = sAux;
Expand All @@ -472,7 +472,7 @@ Rcpp::List BASiCS_MCMCcppRegNoSpikes(
}

// PRINT IN CONSOLE SAMPLED VALUES FOR FEW SELECTED PARAMETERS
if((i%(2*Thin) == 0) & (PrintProgress == 1)) {
if((i%(2*Thin) == 0) && (PrintProgress == 1)) {
CurrentIter(i, N);
Rcout << "mu (gene 1): " << muAux(0,0) << std::endl;
Rcout << "delta (gene 1): " << deltaAux(0,0) << std::endl;
Expand Down
10 changes: 5 additions & 5 deletions src/updates.h
Original file line number Diff line number Diff line change
Expand Up @@ -160,9 +160,9 @@ Rcpp::List phiUpdate(
double u = R::runif(0,1);

// ACCEPT/REJECT STEP (REJECT VALUES OUTSIDE VALID RANGE)
if(all(prop_var * phi1 < 2.5327372760800758e+305) &
all(prop_var * phi0 < 2.5327372760800758e+305) &
all(phi1 > 0) & all(phi0 > 0)) {
if(all(prop_var * phi1 < 2.5327372760800758e+305) &&
all(prop_var * phi0 < 2.5327372760800758e+305) &&
all(phi1 > 0) && all(phi0 > 0)) {
// There is an extra -1 but it cancels out with the proposal component
double log_aux = sum(
(sum_bygene_bio + (aphi * exponent)) % (log(phi1) - log(phi0))
Expand Down Expand Up @@ -255,15 +255,15 @@ arma::vec sUpdateBatch(
arma::vec chi = 2 * nu / thetaBatch;
for (int j = 0; j < n; j++) {
if (!R_IsNA(lambda(j))) {
if (!R_IsNA(chi(j)) & (chi(j) > 0)) {
if (!R_IsNA(chi(j)) && (chi(j) > 0)) {
s1(j) = Rcpp::as<double>(Rgig(1, lambda(j), chi(j), psi));
/* DEBUG: break in case of undefined values */
if (R_IsNA(s1(j))) {
Rcpp::Rcout << "Error when updating s" << j << std::endl;
Rcpp::stop("Please consider additional filter of the input dataset.");
}
} else {
if (!(chi(j) < 0) & (lambda(j) > 0)) {
if (!(chi(j) < 0) && (lambda(j) > 0)) {
s1(j) = Rcpp::as<double>(Rgig(1, lambda(j), chi(j), psi));
}
}
Expand Down
4 changes: 2 additions & 2 deletions src/updatesNoSpikes.h
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ arma::mat muUpdateNoSpikes(
(pow(log(mu0(iAux)) - aux,2)) * exponent;

// ACCEPT REJECT
if ((log(u(iAux)) < log_aux(iAux)) & (mu1(iAux) > mintol)) {
if ((log(u(iAux)) < log_aux(iAux)) && (mu1(iAux) > mintol)) {
ind(iAux) = 1;
sumAux += log(mu1(iAux)) - log(mu0(iAux));
} else {
Expand All @@ -99,7 +99,7 @@ arma::mat muUpdateNoSpikes(
) * exponent;

// ACCEPT REJECT
if ((log(u(iAux)) < log_aux(iAux)) & (mu1(iAux) > mintol)) {
if ((log(u(iAux)) < log_aux(iAux)) && (mu1(iAux) > mintol)) {
ind(iAux) = 1;
} else {
ind(iAux) = 0;
Expand Down
2 changes: 1 addition & 1 deletion src/updatesRegNoSpikes.h
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,7 @@ arma::mat muUpdateRegNoSpikes(
) * exponent;

// ACCEPT REJECT
if ((log(u(iAux)) < log_aux(iAux)) & (mu1(iAux) > mintol)) {
if ((log(u(iAux)) < log_aux(iAux)) && (mu1(iAux) > mintol)) {
ind(iAux) = 1;
} else{
ind(iAux) = 0; mu1(iAux) = mu0(iAux);
Expand Down
8 changes: 4 additions & 4 deletions src/utils.h
Original file line number Diff line number Diff line change
Expand Up @@ -161,7 +161,7 @@ NumericVector Rgig(const int n,
{
NumericVector samps(n);
/* special case which is basically a gamma distribution */
if ((chi < ZTOL) & (lambda > 0.0)) {
if ((chi < ZTOL) && (lambda > 0.0)) {
int i;
for (i = 0; i < n; i++) {
samps(i) = R::rgamma(lambda, 2.0/psi);
Expand All @@ -170,7 +170,7 @@ NumericVector Rgig(const int n,
}

/* special cases which is basically an inverse gamma distribution */
if ((psi < ZTOL) & (lambda < 0.0)) {
if ((psi < ZTOL) && (lambda < 0.0)) {
int i;
for (i = 0; i < n; i++) {
samps(i) = 1.0/R::rgamma(0.0-lambda, 2.0/chi);
Expand Down Expand Up @@ -354,8 +354,8 @@ arma::vec DegubInd(arma::vec ind,
std::string const& param)
{
for (int i=0; i < q; i++) {
if( arma::is_finite(log_aux(i)) & arma::is_finite(y(i)) ) {
if((log(u(i)) < log_aux(i)) & (y(i) > threshold)) { ind(i) = 1; }
if( arma::is_finite(log_aux(i)) && arma::is_finite(y(i)) ) {
if((log(u(i)) < log_aux(i)) && (y(i) > threshold)) { ind(i) = 1; }
else{ind(i) = 0;}
}
else {
Expand Down

0 comments on commit f343d35

Please sign in to comment.