-
Notifications
You must be signed in to change notification settings - Fork 30
/
Copy pathsave.cpp
74 lines (56 loc) · 1.98 KB
/
save.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
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
/******************************************************************************/
// SLOW
// [[Rcpp::export]]
void crossprodCpp(SEXP res, SEXP pBigMat,
const IntegerVector& rowInd,
const NumericVector& mean,
const NumericVector& sd) {
XPtr<BigMatrix> xpRes(res);
MatrixAccessor<double> macc2(*xpRes);
XPtr<BigMatrix> xpMat(pBigMat);
MatrixAccessor<char> macc(*xpMat);
int n = rowInd.size();
int m = xpMat->ncol();
int l;
for (int j = 0; j < m; j++) {
if (j % 100 == 0) printf("%d ", j);
for (int i = 0; i <= j; i++) {
macc2[j][i] = 0;
for (int k = 0; k < n; k++) {
l = rowInd[k] - 1;
macc2[j][i] += (macc[j][l] - mean[j]) *
(macc[i][l] - mean[i]) / (sd[j] * sd[i]);
}
}
}
return;
}
/******************************************************************************/
// doesn't work with a sub.big.matrix
// [[Rcpp::export]]
void crossprodEigen2(SEXP res,
const Eigen::Map<Eigen::MatrixXd> X,
const Eigen::Map<Eigen::MatrixXd> Y) {
XPtr<BigMatrix> xpMatRes(res);
Eigen::Map<Eigen::MatrixXd> bMRes =
Eigen::Map<Eigen::MatrixXd>((double*)xpMatRes->matrix(),
xpMatRes->nrow(),
xpMatRes->ncol());
bMRes = X.transpose() * Y;
return;
}
/******************************************************************************/
// doesn't work with a sub.big.matrix
// [[Rcpp::export]]
void crossprodEigen3(SEXP res,
const Eigen::Map<Eigen::MatrixXd> X,
const Eigen::Map<Eigen::MatrixXd> Y) {
XPtr<BigMatrix> xpMatRes(res);
Eigen::Map<Eigen::MatrixXd> bMRes =
Eigen::Map<Eigen::MatrixXd>((double*)xpMatRes->matrix(),
xpMatRes->nrow(),
xpMatRes->ncol());
bMRes = X.adjoint() * Y;
return;
}
/******************************************************************************/