"git@developer.sourcefind.cn:OpenDAS/dgl.git" did not exist on "1ea0bcf4863f1f4c259b8da1134b868055b14078"
python_binding.cc 3.4 KB
Newer Older
1
2
3
4
5
6
/**
 *  Copyright (c) 2023 by Contributors
 * @file python_binding.cc
 * @brief Graph bolt library Python binding.
 */

7
#include <graphbolt/fused_csc_sampling_graph.h>
8
#include <graphbolt/isin.h>
9
#include <graphbolt/serialize.h>
10
#include <graphbolt/unique_and_compact.h>
11

12
#include "./index_select.h"
13
#include "./random.h"
14

15
16
17
18
namespace graphbolt {
namespace sampling {

TORCH_LIBRARY(graphbolt, m) {
19
  m.class_<FusedSampledSubgraph>("FusedSampledSubgraph")
20
      .def(torch::init<>())
21
22
      .def_readwrite("indptr", &FusedSampledSubgraph::indptr)
      .def_readwrite("indices", &FusedSampledSubgraph::indices)
23
      .def_readwrite(
24
          "original_row_node_ids", &FusedSampledSubgraph::original_row_node_ids)
25
      .def_readwrite(
26
          "original_column_node_ids",
27
28
29
30
          &FusedSampledSubgraph::original_column_node_ids)
      .def_readwrite(
          "original_edge_ids", &FusedSampledSubgraph::original_edge_ids)
      .def_readwrite("type_per_edge", &FusedSampledSubgraph::type_per_edge);
31
32
33
34
35
36
37
  m.class_<FusedCSCSamplingGraph>("FusedCSCSamplingGraph")
      .def("num_nodes", &FusedCSCSamplingGraph::NumNodes)
      .def("num_edges", &FusedCSCSamplingGraph::NumEdges)
      .def("csc_indptr", &FusedCSCSamplingGraph::CSCIndptr)
      .def("indices", &FusedCSCSamplingGraph::Indices)
      .def("node_type_offset", &FusedCSCSamplingGraph::NodeTypeOffset)
      .def("type_per_edge", &FusedCSCSamplingGraph::TypePerEdge)
38
39
      .def("node_type_to_id", &FusedCSCSamplingGraph::NodeTypeToID)
      .def("edge_type_to_id", &FusedCSCSamplingGraph::EdgeTypeToID)
40
41
42
43
44
      .def("edge_attributes", &FusedCSCSamplingGraph::EdgeAttributes)
      .def("set_csc_indptr", &FusedCSCSamplingGraph::SetCSCIndptr)
      .def("set_indices", &FusedCSCSamplingGraph::SetIndices)
      .def("set_node_type_offset", &FusedCSCSamplingGraph::SetNodeTypeOffset)
      .def("set_type_per_edge", &FusedCSCSamplingGraph::SetTypePerEdge)
45
46
      .def("set_node_type_to_id", &FusedCSCSamplingGraph::SetNodeTypeToID)
      .def("set_edge_type_to_id", &FusedCSCSamplingGraph::SetEdgeTypeToID)
47
48
49
      .def("set_edge_attributes", &FusedCSCSamplingGraph::SetEdgeAttributes)
      .def("in_subgraph", &FusedCSCSamplingGraph::InSubgraph)
      .def("sample_neighbors", &FusedCSCSamplingGraph::SampleNeighbors)
50
51
      .def(
          "sample_negative_edges_uniform",
52
53
          &FusedCSCSamplingGraph::SampleNegativeEdgesUniform)
      .def("copy_to_shared_memory", &FusedCSCSamplingGraph::CopyToSharedMemory)
54
55
      .def_pickle(
          // __getstate__
56
          [](const c10::intrusive_ptr<FusedCSCSamplingGraph>& self)
57
58
59
60
61
62
              -> torch::Dict<
                  std::string, torch::Dict<std::string, torch::Tensor>> {
            return self->GetState();
          },
          // __setstate__
          [](torch::Dict<std::string, torch::Dict<std::string, torch::Tensor>>
63
64
                 state) -> c10::intrusive_ptr<FusedCSCSamplingGraph> {
            auto g = c10::make_intrusive<FusedCSCSamplingGraph>();
65
66
67
            g->SetState(state);
            return g;
          });
68
  m.def("fused_csc_sampling_graph", &FusedCSCSamplingGraph::Create);
69
70
  m.def(
      "load_from_shared_memory", &FusedCSCSamplingGraph::LoadFromSharedMemory);
71
  m.def("unique_and_compact", &UniqueAndCompact);
72
  m.def("isin", &IsIn);
73
  m.def("index_select", &ops::IndexSelect);
74
  m.def("index_select_csc", &ops::IndexSelectCSC);
75
  m.def("set_seed", &RandomEngine::SetManualSeed);
76
77
78
79
}

}  // namespace sampling
}  // namespace graphbolt