python_binding.cc 1.94 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
// clang-format off
#include <sparse/dgl_headers.h>
8
#include <sparse/torch_headers.h>
czkkkkkk's avatar
czkkkkkk committed
9
10
// clang-format on

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

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)
30
      .def("indices", &SparseMatrix::Indices)
31
      .def("csr", &SparseMatrix::CSRTensors)
32
      .def("csc", &SparseMatrix::CSCTensors)
33
34
      .def("transpose", &SparseMatrix::Transpose)
      .def("coalesce", &SparseMatrix::Coalesce)
35
      .def("has_duplicate", &SparseMatrix::HasDuplicate)
36
37
      .def("is_diag", &SparseMatrix::HasDiag)
      .def("index_select", &SparseMatrix::IndexSelect)
38
39
      .def("range_select", &SparseMatrix::RangeSelect)
      .def("sample", &SparseMatrix::Sample);
40
41
42
  m.def("from_coo", &SparseMatrix::FromCOO)
      .def("from_csr", &SparseMatrix::FromCSR)
      .def("from_csc", &SparseMatrix::FromCSC)
43
      .def("from_diag", &SparseMatrix::FromDiag)
44
      .def("spsp_add", &SpSpAdd)
czkkkkkk's avatar
czkkkkkk committed
45
      .def("spsp_mul", &SpSpMul)
czkkkkkk's avatar
czkkkkkk committed
46
      .def("spsp_div", &SpSpDiv)
47
48
49
50
51
52
      .def("reduce", &Reduce)
      .def("sum", &ReduceSum)
      .def("smean", &ReduceMean)
      .def("smin", &ReduceMin)
      .def("smax", &ReduceMax)
      .def("sprod", &ReduceProd)
53
      .def("val_like", &SparseMatrix::ValLike)
54
      .def("spmm", &SpMM)
55
      .def("sddmm", &SDDMM)
56
      .def("softmax", &Softmax)
57
58
      .def("spspmm", &SpSpMM)
      .def("compact", &Compact);
59
60
61
62
}

}  // namespace sparse
}  // namespace dgl