Skip to content

Commit

Permalink
fix valgrind issues
Browse files Browse the repository at this point in the history
  • Loading branch information
boennecd committed Mar 15, 2019
1 parent ce4fc66 commit 1299632
Show file tree
Hide file tree
Showing 4 changed files with 11 additions and 9 deletions.
2 changes: 1 addition & 1 deletion src/LAPACK_wrappers.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ arma::mat QR_factorization::qy(
}

arma::mat QR_factorization::qy(
arma::mat &&B, const bool transpose) const {
arma::mat &B, const bool transpose) const {
// take copy
int NRHS = B.n_cols, K = MIN(M, N);
if(B.n_rows != (unsigned int)M)
Expand Down
2 changes: 1 addition & 1 deletion src/LAPACK_wrappers.h
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ class QR_factorization {
QR_factorization(arma::mat&);

arma::mat qy(const arma::mat&, const bool transpose = false) const;
arma::mat qy(arma::mat&&, const bool) const;
arma::mat qy(arma::mat&, const bool) const;
arma::vec qy(const arma::vec&, const bool transpose = false) const;
arma::mat R() const;
arma::uvec pivot() const;
Expand Down
13 changes: 8 additions & 5 deletions src/parallel_glm.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -99,17 +99,17 @@ class parallelglm_class_QR {
arma::uvec good = arma::find((weight > 0) % (mu_eta_val != 0.));
const bool is_all_good = good.n_elem == n;

arma::vec z, w;
arma::vec var = data.family.variance(mu);

z = (eta - offset) + (y - mu) / mu_eta_val;
w = arma::sqrt(weight % arma::square(mu_eta_val) / var);
arma::vec z = (eta - offset) + (y - mu) / mu_eta_val,
w = arma::sqrt(weight % arma::square(mu_eta_val) / var);

/* ensure that bad entries has zero weight */
if(!is_all_good){
auto good_next = good.begin();
auto w_i = w.begin();
for(arma::uword i = 0; i < w.n_elem; ++i, ++w_i){
arma::uword i = 0;
for(; i < w.n_elem and good_next != good.end(); ++i, ++w_i){
if(i == *good_next){
++good_next;
continue;
Expand All @@ -119,6 +119,9 @@ class parallelglm_class_QR {
*w_i = 0.;

}

for(; i < w.n_elem; ++i, ++w_i)
*w_i = 0.;
}

const arma::uword p = data.X.n_cols;
Expand All @@ -127,7 +130,7 @@ class parallelglm_class_QR {
X.each_col() %= w;
z %= w;

arma::mat dev_mat; dev_mat = 0.; /* we compute this later */
arma::mat dev_mat(1L, 1L, arma::fill::zeros); /* we compute this later */

if(do_inner){
/* do not need to initalize when beta is zero. We do it anyway as we
Expand Down
3 changes: 1 addition & 2 deletions src/parallel_qr.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,7 @@ qr_parallel::worker::worker
R_F qr_parallel::worker::operator()(){
qr_work_chunk my_chunk = my_generator->get_chunk();
QR_factorization qr(my_chunk.X);
arma::mat F = qr.qy(
std::move(my_chunk.Y), true).rows(0, my_chunk.X.n_cols - 1);
arma::mat F = qr.qy(my_chunk.Y, true).rows(0, my_chunk.X.n_cols - 1);

return R_F { qr.R(), qr.pivot(), std::move(F), my_chunk.dev };
}
Expand Down

0 comments on commit 1299632

Please sign in to comment.