spmm.h 1.02 KB
Newer Older
1
2
3
4
5
6
7
8
9
/**
 *  Copyright (c) 2022 by Contributors
 * @file sparse/spmm.h
 * @brief DGL C++ SpMM operator.
 */
#ifndef SPARSE_SPMM_H_
#define SPARSE_SPMM_H_

#include <sparse/sparse_matrix.h>
10
#include <torch/script.h>
11
12
13
14
15
16

namespace dgl {
namespace sparse {

/**
 * @brief Perform a matrix multiplication of the sparse matrix and dense
17
18
19
20
21
22
23
 * matrix. The SpMM can be batched, where the batch dimension is the last
 * dimension for both sparse and dense matrices.
 *
 * There are three cases for sparse, dense, and output matrix shapes:
 *   (1) (n, m), (m, k), and (n, k);
 *   (2) (n, m), (m,), and (n,);
 *   (3) (n, m, b), (m, k, b), and (n, k, b).
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
 *
 * This function supports autograd for both the sparse and dense matrix but does
 * not support higher order gradient.
 *
 * @param sparse_mat The sparse matrix.
 * @param dense_mat The dense matrix.
 *
 * @return Dense matrix.
 */
torch::Tensor SpMM(
    const c10::intrusive_ptr<SparseMatrix>& sparse_mat,
    torch::Tensor dense_mat);

}  // namespace sparse
}  // namespace dgl

#endif  // SPARSE_SPMM_H_