20 #ifndef TENSOR_MMULT_SPARSE_TENSOR_H
21 #define TENSOR_MMULT_SPARSE_TENSOR_H
27 template<
typename elt_t>
29 mult_sp_t(elt_t *dest,
30 const index *row_start,
const index *column,
const elt_t *matrix,
32 index i_len, index j_len, index k_len, index l_len)
37 for (; l_len; l_len--, vector+=j_len) {
38 for (index i = 0; i < i_len; i++) {
40 for (index j = row_start[i]; j < row_start[i+1]; j++) {
41 accum += matrix[j] * vector[column[j]];
47 for (; l_len; l_len--, vector+=j_len) {
48 const elt_t *m = matrix;
49 const index *c = column;
50 for (index i = 0; i < i_len; i++) {
52 for (index j = row_start[i+1] - row_start[i]; j; j--) {
53 accum += *(m++) * vector[*(c++)];
61 for (index l = 0; l < l_len; l++) {
62 const elt_t *v = vector + l*(k_len*j_len);
63 for (index k = 0; k < k_len; k++, v++) {
64 for (index i = 0; i < i_len; i++) {
66 for (index j = row_start[i]; j < row_start[i+1]; j++) {
67 accum += matrix[j] * v[column[j] * k_len];
80 template<
typename elt_t>
81 static inline const Tensor<elt_t>
82 do_mmult(
const Sparse<elt_t> &m1,
const Tensor<elt_t> &m2)
84 Indices dims(m2.rank());
86 for (index k = 1, N = m2.rank(); k < N; k++) {
87 dims.at(k) = m2.dimension(k);
90 index j_len = m2.dimension(0);
91 index i_len = dims.at(0) = m1.rows();
93 if (j_len != m1.columns()) {
95 "In mmult(S,T), the first index of tensor T does not match the number of\n"
96 "columns in sparse matrix S.";
102 mult_sp_t<elt_t>(output.begin(),
103 m1.priv_row_start().begin(), m1.priv_column().begin(),
104 m1.priv_data().begin(),
106 i_len, j_len, 1, l_len);
static const Tensor< elt_t > zeros(index rows)
Matrix of zeros.