-
Notifications
You must be signed in to change notification settings - Fork 0
/
Znew_gen2.cpp
49 lines (41 loc) · 1.2 KB
/
Znew_gen2.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
#define ARMA_64BIT_WORD
#include <RcppArmadillo.h>
// [[Rcpp::depends(BH, bigmemory, RcppArmadillo)]]
#include <bigmemory/MatrixAccessor.hpp>
#include <numeric>
using namespace Rcpp ;
// [[Rcpp::export]]
void Znew_gen2( const arma::mat& U, const arma::mat& Z, const arma::vec& g, const arma::vec& cols,
unsigned int n, unsigned int q, unsigned int d, SEXP pBigMat,
arma::sp_mat& J){
unsigned int i = 0;
unsigned int j = 0;
unsigned int nMC = U.n_rows;
unsigned int index = 0;
int gr = 0;
arma::mat Usub(1, q);
arma::mat Zsub(1, q);
arma::mat out(n*nMC, J.n_cols);
XPtr<BigMatrix> pMat(pBigMat);
MatrixAccessor<double> out2(*pMat);
Rprintf("First For Loop \n");
for(i = 0; i<n; i++){
gr = g(i);
for(index = 0;index<q; index++){
Zsub(0,index) = Z(i,cols(index)-1 + gr - 1);
}
for(j = 0; j < nMC; j++){
for(index = 0;index<q; index++){
Usub(0,index) = U(j,cols(index)-1 + gr - 1);
}
out.row((i*nMC + j)) = kron(Usub, Zsub) * J;
}
}
Rprintf("Second For Loop \n");
for(i = 0; i<n*nMC; i++){
for(j = 0; j<out.n_cols; j++){
out2[j][i] = out(i, j);
}
}
Rprintf("End of Function \n");
}