python_binding.cc 1.38 KB
Newer Older
Hongzhi (Steve), Chen's avatar
Hongzhi (Steve), Chen committed
1
/**
2
3
 *  Copyright (c) 2022 by Contributors
 * @file python_binding.cc
czkkkkkk's avatar
czkkkkkk committed
4
 * @brief DGL sparse library Python binding.
5
 */
czkkkkkk's avatar
czkkkkkk committed
6
7
8
9
// clang-format off
#include <sparse/dgl_headers.h>
// clang-format on

10
#include <sparse/elementwise_op.h>
11
#include <sparse/reduction.h>
12
#include <sparse/sddmm.h>
13
#include <sparse/sparse_matrix.h>
14
#include <sparse/spmm.h>
15
#include <sparse/spspmm.h>
16
17
18
19
20
21
22
23
24
25
26
27
28
29
#include <torch/custom_class.h>
#include <torch/script.h>

namespace dgl {
namespace sparse {

TORCH_LIBRARY(dgl_sparse, m) {
  m.class_<SparseMatrix>("SparseMatrix")
      .def("val", &SparseMatrix::value)
      .def("nnz", &SparseMatrix::nnz)
      .def("device", &SparseMatrix::device)
      .def("shape", &SparseMatrix::shape)
      .def("coo", &SparseMatrix::COOTensors)
      .def("csr", &SparseMatrix::CSRTensors)
30
      .def("csc", &SparseMatrix::CSCTensors)
31
      .def("transpose", &SparseMatrix::Transpose);
32
33
34
  m.def("create_from_coo", &CreateFromCOO)
      .def("create_from_csr", &CreateFromCSR)
      .def("create_from_csc", &CreateFromCSC)
35
      .def("spsp_add", &SpSpAdd)
36
37
38
39
40
41
      .def("reduce", &Reduce)
      .def("sum", &ReduceSum)
      .def("smean", &ReduceMean)
      .def("smin", &ReduceMin)
      .def("smax", &ReduceMax)
      .def("sprod", &ReduceProd)
42
43
      .def("val_like", &CreateValLike)
      .def("spmm", &SpMM)
44
45
      .def("sddmm", &SDDMM)
      .def("spspmm", &SpSpMM);
46
47
48
49
}

}  // namespace sparse
}  // namespace dgl