Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Switch Calloc,Free to R_Calloc,R_Free for STRICT_R_HEADERS #40

Merged
merged 1 commit into from
Jan 6, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
102 changes: 51 additions & 51 deletions src/binomial.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -259,21 +259,21 @@ RcppExport SEXP cdfit_binomial_ssr(SEXP X_, SEXP y_, SEXP row_idx_,
}

arma::sp_mat beta = arma::sp_mat(p, L); //beta
double *a = Calloc(p, double); //Beta from previous iteration
double *a = R_Calloc(p, double); //Beta from previous iteration
double a0 = 0.0; //beta0 from previousiteration
double *w = Calloc(n, double);
double *s = Calloc(n, double); //y_i - pi_i
double *eta = Calloc(n, double);
int *e1 = Calloc(p, int); //ever-active set
int *e2 = Calloc(p, int); //strong set
double *w = R_Calloc(n, double);
double *s = R_Calloc(n, double); //y_i - pi_i
double *eta = R_Calloc(n, double);
int *e1 = R_Calloc(p, int); //ever-active set
int *e2 = R_Calloc(p, int); //strong set
double xwr, xwx, pi, u, v, cutoff, l1, l2, shift, si;
double max_update, update, thresh; // for convergence check
int i, j, jj, l, violations, lstart;

double ybar = sum(y, n) / n;
a0 = beta0[0] = log(ybar / (1-ybar));
double nullDev = 0;
double *r = Calloc(n, double);
double *r = R_Calloc(n, double);
for (i = 0; i < n; i++) {
r[i] = y[i];
nullDev = nullDev - y[i]*log(ybar) - (1-y[i])*log(1-ybar);
Expand Down Expand Up @@ -328,7 +328,7 @@ RcppExport SEXP cdfit_binomial_ssr(SEXP X_, SEXP y_, SEXP row_idx_,
}
if (nv > dfmax) {
for (int ll=l; ll<L; ll++) iter[ll] = NA_INTEGER;
Free(s); Free(w); Free(a); Free(r); Free(e1); Free(e2); Free(eta);
R_Free(s); R_Free(w); R_Free(a); R_Free(r); R_Free(e1); R_Free(e2); R_Free(eta);
return List::create(beta0, beta, center, scale, lambda, Dev,
iter, n_reject, Rcpp::wrap(col_idx));
}
Expand Down Expand Up @@ -385,7 +385,7 @@ RcppExport SEXP cdfit_binomial_ssr(SEXP X_, SEXP y_, SEXP row_idx_,
if (Dev[l] / nullDev < .01) {
if (warn) warning("Model saturated; exiting...");
for (int ll=l; ll<L; ll++) iter[ll] = NA_INTEGER;
Free(s); Free(w); Free(a); Free(r); Free(e1); Free(e2); Free(eta);
R_Free(s); R_Free(w); R_Free(a); R_Free(r); R_Free(e1); R_Free(e2); R_Free(eta);
return List::create(beta0, beta, center, scale, lambda, Dev,
iter, n_reject, Rcpp::wrap(col_idx));
}
Expand Down Expand Up @@ -441,7 +441,7 @@ RcppExport SEXP cdfit_binomial_ssr(SEXP X_, SEXP y_, SEXP row_idx_,
if (violations==0) break;
}
}
Free(s); Free(w); Free(a); Free(r); Free(e1); Free(e2); Free(eta);
R_Free(s); R_Free(w); R_Free(a); R_Free(r); R_Free(e1); R_Free(e2); R_Free(eta);
return List::create(beta0, beta, center, scale, lambda, Dev, iter, n_reject, Rcpp::wrap(col_idx));

}
Expand Down Expand Up @@ -518,21 +518,21 @@ RcppExport SEXP cdfit_binomial_ssr_approx(SEXP X_, SEXP y_, SEXP row_idx_,
}

arma::sp_mat beta = arma::sp_mat(p, L); //beta
double *a = Calloc(p, double); //Beta from previous iteration
double *a = R_Calloc(p, double); //Beta from previous iteration
double a0 = 0.0; //beta0 from previousiteration
double *w = Calloc(n, double);
double *s = Calloc(n, double); //y_i - pi_i
double *eta = Calloc(n, double);
int *e1 = Calloc(p, int); //ever-active set
int *e2 = Calloc(p, int); //strong set
double *w = R_Calloc(n, double);
double *s = R_Calloc(n, double); //y_i - pi_i
double *eta = R_Calloc(n, double);
int *e1 = R_Calloc(p, int); //ever-active set
int *e2 = R_Calloc(p, int); //strong set
double xwr, xwx, pi, u, v, cutoff, l1, l2, shift, si;
double max_update, update, thresh; // for convergence check
int i, j, jj, l, violations, lstart; // temp index

double ybar = sum(y, n)/n;
a0 = beta0[0] = log(ybar/(1-ybar));
double nullDev = 0;
double *r = Calloc(n, double);
double *r = R_Calloc(n, double);
for (i = 0; i < n; i++) {
r[i] = y[i];
nullDev = nullDev - y[i] * log(ybar) - (1 - y[i]) * log(1 - ybar);
Expand Down Expand Up @@ -580,7 +580,7 @@ RcppExport SEXP cdfit_binomial_ssr_approx(SEXP X_, SEXP y_, SEXP row_idx_,
}
if (nv > dfmax) {
for (int ll=l; ll<L; ll++) iter[ll] = NA_INTEGER;
Free(s); Free(w); Free(a); Free(r); Free(e1); Free(e2); Free(eta);
R_Free(s); R_Free(w); R_Free(a); R_Free(r); R_Free(e1); R_Free(e2); R_Free(eta);
return List::create(beta0, beta, center, scale, lambda, Dev,
iter, n_reject, Rcpp::wrap(col_idx));
}
Expand Down Expand Up @@ -634,7 +634,7 @@ RcppExport SEXP cdfit_binomial_ssr_approx(SEXP X_, SEXP y_, SEXP row_idx_,
if (Dev[l] / nullDev < .01) {
if (warn) warning("Model saturated; exiting...");
for (int ll = l; ll < L; ll++) iter[ll] = NA_INTEGER;
Free(s); Free(w); Free(a); Free(r); Free(e1); Free(e2); Free(eta);
R_Free(s); R_Free(w); R_Free(a); R_Free(r); R_Free(e1); R_Free(e2); R_Free(eta);
return List::create(beta0, beta, center, scale, lambda, Dev,
iter, n_reject, Rcpp::wrap(col_idx));
}
Expand Down Expand Up @@ -696,7 +696,7 @@ RcppExport SEXP cdfit_binomial_ssr_approx(SEXP X_, SEXP y_, SEXP row_idx_,
}
}

Free(s); Free(w); Free(a); Free(r); Free(e1); Free(e2); Free(eta);
R_Free(s); R_Free(w); R_Free(a); R_Free(r); R_Free(e1); R_Free(e2); R_Free(eta);
return List::create(beta0, beta, center, scale, lambda, Dev, iter, n_reject, Rcpp::wrap(col_idx));
}

Expand Down Expand Up @@ -778,21 +778,21 @@ RcppExport SEXP cdfit_binomial_slores_ssr(SEXP X_, SEXP y_, SEXP n_pos_, SEXP yl
}

arma::sp_mat beta = arma::sp_mat(p, L); //beta
double *a = Calloc(p, double); //Beta from previous iteration
double *a = R_Calloc(p, double); //Beta from previous iteration
double a0 = 0.0; //beta0 from previousiteration
double *w = Calloc(n, double);
double *s = Calloc(n, double); //y_i - pi_i
double *eta = Calloc(n, double);
int *e1 = Calloc(p, int); //ever-active set
int *e2 = Calloc(p, int); //strong set
double *w = R_Calloc(n, double);
double *s = R_Calloc(n, double); //y_i - pi_i
double *eta = R_Calloc(n, double);
int *e1 = R_Calloc(p, int); //ever-active set
int *e2 = R_Calloc(p, int); //strong set
double xwr, xwx, pi, u, v, cutoff, l1, l2, shift, si;
double max_update, update, thresh; // for convergence check
int i, j, jj, l, violations, lstart;

double ybar = sum(y, n) / n;
a0 = beta0[0] = log(ybar / (1-ybar));
double nullDev = 0;
double *r = Calloc(n, double);
double *r = R_Calloc(n, double);
for (i = 0; i < n; i++) {
r[i] = y[i];
nullDev = nullDev - y[i]*log(ybar) - (1-y[i])*log(1-ybar);
Expand Down Expand Up @@ -836,8 +836,8 @@ RcppExport SEXP cdfit_binomial_slores_ssr(SEXP X_, SEXP y_, SEXP n_pos_, SEXP yl
vector<double> X_theta_lam_xi_pos;
vector<double> prod_PX_Pxmax_xi_pos;
vector<double> cutoff_xi_pos;
int *slores_reject = Calloc(p, int);
int *slores_reject_old = Calloc(p, int);
int *slores_reject = R_Calloc(p, int);
int *slores_reject_old = R_Calloc(p, int);
for (int j = 0; j < p; j++) slores_reject_old[j] = 1;

int slores; // if 0, don't perform Slores rule
Expand Down Expand Up @@ -877,8 +877,8 @@ RcppExport SEXP cdfit_binomial_slores_ssr(SEXP X_, SEXP y_, SEXP n_pos_, SEXP yl
}
if (nv > dfmax) {
for (int ll=l; ll<L; ll++) iter[ll] = NA_INTEGER;
Free(slores_reject); Free(slores_reject_old);
Free(s); Free(w); Free(a); Free(r); Free(e1); Free(e2); Free(eta);
R_Free(slores_reject); R_Free(slores_reject_old);
R_Free(s); R_Free(w); R_Free(a); R_Free(r); R_Free(e1); R_Free(e2); R_Free(eta);
//ProfilerStop();
return List::create(beta0, beta, center, scale, lambda, Dev,
iter, n_reject, Rcpp::wrap(col_idx));
Expand Down Expand Up @@ -952,8 +952,8 @@ RcppExport SEXP cdfit_binomial_slores_ssr(SEXP X_, SEXP y_, SEXP n_pos_, SEXP yl
if (Dev[l] / nullDev < .01) {
if (warn) warning("Model saturated; exiting...");
for (int ll=l; ll<L; ll++) iter[ll] = NA_INTEGER;
Free(slores_reject); Free(slores_reject_old);
Free(s); Free(w); Free(a); Free(r); Free(e1); Free(e2); Free(eta);
R_Free(slores_reject); R_Free(slores_reject_old);
R_Free(s); R_Free(w); R_Free(a); R_Free(r); R_Free(e1); R_Free(e2); R_Free(eta);
return List::create(beta0, beta, center, scale, lambda, Dev, iter, n_reject, n_slores_reject, Rcpp::wrap(col_idx));
}
// Intercept
Expand Down Expand Up @@ -1012,8 +1012,8 @@ RcppExport SEXP cdfit_binomial_slores_ssr(SEXP X_, SEXP y_, SEXP n_pos_, SEXP yl
}
}
}
Free(slores_reject); Free(slores_reject_old);
Free(s); Free(w); Free(a); Free(r); Free(e1); Free(e2); Free(eta);
R_Free(slores_reject); R_Free(slores_reject_old);
R_Free(s); R_Free(w); R_Free(a); R_Free(r); R_Free(e1); R_Free(e2); R_Free(eta);
//ProfilerStop();
return List::create(beta0, beta, center, scale, lambda, Dev, iter, n_reject, n_slores_reject, Rcpp::wrap(col_idx));
}
Expand Down Expand Up @@ -1097,21 +1097,21 @@ RcppExport SEXP cdfit_binomial_ada_slores_ssr(SEXP X_, SEXP y_, SEXP n_pos_, SEX
}

arma::sp_mat beta = arma::sp_mat(p, L); //beta
double *a = Calloc(p, double); //Beta from previous iteration
double *a = R_Calloc(p, double); //Beta from previous iteration
double a0 = 0.0; //beta0 from previousiteration
double *w = Calloc(n, double);
double *s = Calloc(n, double); //y_i - pi_i
double *eta = Calloc(n, double);
int *e1 = Calloc(p, int); //ever-active set
int *e2 = Calloc(p, int); //strong set
double *w = R_Calloc(n, double);
double *s = R_Calloc(n, double); //y_i - pi_i
double *eta = R_Calloc(n, double);
int *e1 = R_Calloc(p, int); //ever-active set
int *e2 = R_Calloc(p, int); //strong set
double xwr, xwx, pi, u, v, cutoff, l1, l2, shift, si;
double max_update, update, thresh; // for convergence check
int i, j, jj, l, violations, lstart;

double ybar = sum(y, n) / n;
a0 = beta0[0] = log(ybar / (1-ybar));
double nullDev = 0;
double *r = Calloc(n, double);
double *r = R_Calloc(n, double);
for (i = 0; i < n; i++) {
r[i] = y[i];
nullDev = nullDev - y[i]*log(ybar) - (1-y[i])*log(1-ybar);
Expand Down Expand Up @@ -1155,8 +1155,8 @@ RcppExport SEXP cdfit_binomial_ada_slores_ssr(SEXP X_, SEXP y_, SEXP n_pos_, SEX
vector<double> X_theta_lam_xi_pos;
vector<double> prod_PX_Pxmax_xi_pos;
vector<double> cutoff_xi_pos;
int *slores_reject = Calloc(p, int);
int *slores_reject_old = Calloc(p, int);
int *slores_reject = R_Calloc(p, int);
int *slores_reject_old = R_Calloc(p, int);
for (int j = 0; j < p; j++) slores_reject_old[j] = 1;
int l_prev = lstart;
double gain = 0.0;
Expand Down Expand Up @@ -1201,8 +1201,8 @@ RcppExport SEXP cdfit_binomial_ada_slores_ssr(SEXP X_, SEXP y_, SEXP n_pos_, SEX
}
if (nv > dfmax) {
for (int ll=l; ll<L; ll++) iter[ll] = NA_INTEGER;
Free(slores_reject); Free(slores_reject_old);
Free(s); Free(w); Free(a); Free(r); Free(e1); Free(e2); Free(eta);
R_Free(slores_reject); R_Free(slores_reject_old);
R_Free(s); R_Free(w); R_Free(a); R_Free(r); R_Free(e1); R_Free(e2); R_Free(eta);
//ProfilerStop();
return List::create(beta0, beta, center, scale, lambda, Dev,
iter, n_reject, Rcpp::wrap(col_idx));
Expand Down Expand Up @@ -1301,8 +1301,8 @@ RcppExport SEXP cdfit_binomial_ada_slores_ssr(SEXP X_, SEXP y_, SEXP n_pos_, SEX
if (Dev[l] / nullDev < .01) {
if (warn) warning("Model saturated; exiting...");
for (int ll=l; ll<L; ll++) iter[ll] = NA_INTEGER;
Free(slores_reject); Free(slores_reject_old);
Free(s); Free(w); Free(a); Free(r); Free(e1); Free(e2); Free(eta);
R_Free(slores_reject); R_Free(slores_reject_old);
R_Free(s); R_Free(w); R_Free(a); R_Free(r); R_Free(e1); R_Free(e2); R_Free(eta);
return List::create(beta0, beta, center, scale, lambda, Dev, iter, n_reject, n_slores_reject, Rcpp::wrap(col_idx));
}
// Intercept
Expand Down Expand Up @@ -1373,8 +1373,8 @@ RcppExport SEXP cdfit_binomial_ada_slores_ssr(SEXP X_, SEXP y_, SEXP n_pos_, SEX
}*/
}
}
Free(slores_reject); Free(slores_reject_old);
Free(s); Free(w); Free(a); Free(r); Free(e1); Free(e2); Free(eta);
R_Free(slores_reject); R_Free(slores_reject_old);
R_Free(s); R_Free(w); R_Free(a); R_Free(r); R_Free(e1); R_Free(e2); R_Free(eta);
//ProfilerStop();
return List::create(beta0, beta, center, scale, lambda, Dev, iter, n_reject, n_slores_reject, Rcpp::wrap(col_idx));
}
}
Loading