-
Notifications
You must be signed in to change notification settings - Fork 2
/
Matrix.cpp
78 lines (62 loc) · 2.13 KB
/
Matrix.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
75
76
77
78
#include "Matrix.h"
int Matrix_t::nnz() {
return( (is_dense) ? nrow*ncol : rowptr[nrow] );
}
void Matrix_t::kron_mult( const char transA,
const char transB,
const Matrix_t A,
const Matrix_t B,
const double yin[],
double xout[]) {
const int nrow_A = A.nrow;
const int ncol_A = A.ncol;
const int nrow_B = B.nrow;
const int ncol_B = B.ncol;
const double *aval = &(A.val[0]);
const double *bval = &(B.val[0]);
const bool is_dense_A = A.is_dense;
const bool is_dense_B = B.is_dense;
const bool is_sparse_A = !is_dense_A;
const bool is_sparse_B = !is_dense_B;
if (is_dense_A) {
if (is_dense_B) {
den_kron_mult(
transA, transB,
nrow_A, ncol_A, aval,
nrow_B, ncol_B, bval,
yin, xout );
}
else {
// B is sparse
const int *browptr = &(B.rowptr[0]);
const int *bcol = &(B.col[0]);
den_csr_kron_mult(
transA, transB,
nrow_A, ncol_A, aval,
nrow_B, ncol_B, browptr, bcol, bval,
yin, xout );
}
}
else {
// A is sparse
const int *arowptr = &(A.rowptr[0]);
const int *acol = &(A.col[0]);
if (is_dense_B) {
csr_den_kron_mult(
transA, transB,
nrow_A, ncol_A, arowptr, acol, aval,
nrow_B, ncol_B, bval,
yin, xout );
}
else {
// B is sparse
const int *browptr = &(B.rowptr[0]);
const int *bcol = &(B.col[0]);
csr_kron_mult(
transA, transB,
nrow_A, ncol_A, arowptr, acol, aval,
nrow_B, ncol_B, browptr, bcol, bval,
yin, xout );
};
};
} // kron_mult