Skip to content

Commit

Permalink
write custom matrix copy function
Browse files Browse the repository at this point in the history
  • Loading branch information
boennecd committed Mar 30, 2019
1 parent ceb7daa commit 6cd2ea8
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 3 deletions.
2 changes: 1 addition & 1 deletion NEWS.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# pargm 0.1.3
* Fix bug found by Valgrind.
* Fix bug found with Valgrind.

# pargm 0.1.2
* Minor changes in implementation.
Expand Down
16 changes: 14 additions & 2 deletions src/parallel_glm.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
#include "R_BLAS_LAPACK.h"
#include <memory>

/* #define PARGLM_PROF */
#ifdef PARGLM_PROF
#include <gperftools/profiler.h>
#include <iostream>
Expand Down Expand Up @@ -66,6 +65,19 @@ const double double_one = 1., double_zero = 0.;
const int int_one = 1;
char char_N = 'N', char_U = 'U', char_T = 'T';

inline void inplace_copy
(arma::mat &X, const arma::mat &Y, const arma::uword start,
const arma::uword end)
{
double *x = X.begin();
const double *y = Y.begin() + start;

std::size_t n_ele = end - start + 1L;
for(unsigned int i = 0; i < X.n_cols;
++i, x += X.n_rows, y += Y.n_rows)
std::memcpy(x, y, n_ele * sizeof(double));
}

/* Class to fit glm using QR updated in chunks */
class parallelglm_class_QR {
using uword = arma::uword;
Expand Down Expand Up @@ -126,7 +138,7 @@ class parallelglm_class_QR {

const arma::uword p = data.X.n_cols;
arma::mat X(data.X_work_mem.get() + i_start * p, n, p, false, true);
X = data.X.rows(i_start, i_end);
inplace_copy(X, data.X, i_start, i_end);
X.each_col() %= w;
z %= w;

Expand Down

0 comments on commit 6cd2ea8

Please sign in to comment.