Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Feature] Reimplement Immutable graph index in DGL #342

Merged
merged 76 commits into from
Jan 17, 2019
Merged
Show file tree
Hide file tree
Changes from 53 commits
Commits
Show all changes
76 commits
Select commit Hold shift + click to select a range
bce55d1
init.
zheng-da Dec 27, 2018
3e63c70
it's compiled.
zheng-da Dec 28, 2018
34c1d73
add immutable graph constructor.
zheng-da Dec 28, 2018
7aeebd8
add immutable graph API.
zheng-da Dec 28, 2018
7b0c433
fix.
zheng-da Jan 4, 2019
665c4c0
impl get adjacency matrix.
zheng-da Jan 4, 2019
21c8e8e
fix.
zheng-da Jan 4, 2019
78b9f29
fix graph_index from scipy matrix.
zheng-da Jan 4, 2019
4c59690
add neighbor sampling.
zheng-da Jan 7, 2019
4cce9c7
remap vertex ids.
zheng-da Jan 7, 2019
11f6a7c
fix.
zheng-da Jan 7, 2019
304c1e6
move sampler test.
zheng-da Jan 7, 2019
f594e48
fix tests.
zheng-da Jan 7, 2019
51fc4a9
add comments
zheng-da Jan 7, 2019
2a5d7b1
remove mxnet-specific immutable graph.
zheng-da Jan 7, 2019
88aeaca
fix.
zheng-da Jan 7, 2019
a35df30
fix lint.
zheng-da Jan 7, 2019
e8fdc5c
fix.
zheng-da Jan 7, 2019
79da05b
try to fix windows compile error.
zheng-da Jan 7, 2019
54e695b
fix.
zheng-da Jan 8, 2019
1f65daf
fix.
zheng-da Jan 8, 2019
092e88d
add test.
zheng-da Jan 8, 2019
3b70ed8
unify Graph and ImmutableGraph.
zheng-da Jan 10, 2019
bd16487
fix bugs.
zheng-da Jan 10, 2019
cfaa487
fix compile.
zheng-da Jan 10, 2019
d06bda7
move immutable graph.
zheng-da Jan 10, 2019
9e47818
fix.
zheng-da Jan 10, 2019
c63516f
remove print.
zheng-da Jan 10, 2019
550ceaa
fix lint.
zheng-da Jan 10, 2019
a5f6544
fix
zheng-da Jan 10, 2019
0d3c3c5
fix lint.
zheng-da Jan 10, 2019
b9a260a
fix lint.
zheng-da Jan 10, 2019
16e1231
fix test.
zheng-da Jan 11, 2019
3ada031
fix comments.
zheng-da Jan 11, 2019
7301fa9
merge GraphIndex and ImmutableGraphIndex.
zheng-da Jan 13, 2019
5207599
temp fix.
zheng-da Jan 14, 2019
61ff441
impl GetAdj.
zheng-da Jan 14, 2019
f6440bc
fix lint
zheng-da Jan 14, 2019
a174391
fix.
zheng-da Jan 14, 2019
c483664
fix.
zheng-da Jan 14, 2019
5e34778
fix.
zheng-da Jan 14, 2019
2a60e45
fix.
zheng-da Jan 14, 2019
4042b3d
fix.
zheng-da Jan 14, 2019
8e24bb0
use csr only for readonly graph.
zheng-da Jan 14, 2019
6ef6b7a
Revert "use csr only for readonly graph."
zheng-da Jan 14, 2019
c02a1ea
remove code.
zheng-da Jan 14, 2019
0dbf525
fix.
zheng-da Jan 14, 2019
4ba49b5
fix.
zheng-da Jan 14, 2019
7da4512
fix.
zheng-da Jan 14, 2019
1eea27d
fix.
zheng-da Jan 14, 2019
c843626
fix.
zheng-da Jan 14, 2019
fb8e8a0
fix.
zheng-da Jan 14, 2019
3abbf81
Merge branch 'master' into immutable_graph
zheng-da Jan 14, 2019
52b8022
address comments.
zheng-da Jan 15, 2019
6350408
fix for comments.
zheng-da Jan 15, 2019
439a7eb
fix comments.
zheng-da Jan 15, 2019
2cffc7c
revert.
zheng-da Jan 15, 2019
18b2ea8
move test_graph_index to compute.
zheng-da Jan 15, 2019
95fc799
fix.
zheng-da Jan 15, 2019
582b677
fix.
zheng-da Jan 15, 2019
fd3c512
impl GetAdj for coo.
zheng-da Jan 15, 2019
b15a19e
fix.
zheng-da Jan 15, 2019
905c820
fix tests.
zheng-da Jan 15, 2019
224122e
address comments.
zheng-da Jan 15, 2019
d6d5f1e
address comments.
zheng-da Jan 15, 2019
a18b61d
fix comment.
zheng-da Jan 15, 2019
67587da
address comments.
zheng-da Jan 16, 2019
ecf4980
use lambda.
zheng-da Jan 16, 2019
2b0eb6d
other comments.
zheng-da Jan 16, 2019
43392d2
address comments.
zheng-da Jan 16, 2019
edd1b82
modify the semantics of edges.
zheng-da Jan 16, 2019
5c1a947
fix order.
zheng-da Jan 16, 2019
697a7e8
use DGLIdIter
zheng-da Jan 16, 2019
e43b917
fix.
zheng-da Jan 16, 2019
5ed4ff1
remove NotImplemented.
zheng-da Jan 16, 2019
cefb8e9
revert some code.
zheng-da Jan 16, 2019
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
98 changes: 55 additions & 43 deletions include/dgl/graph.h
Original file line number Diff line number Diff line change
Expand Up @@ -10,26 +10,18 @@
#include <cstdint>
#include <utility>
#include <tuple>
#include "runtime/ndarray.h"

namespace dgl {
#include "graph_interface.h"

typedef uint64_t dgl_id_t;
typedef dgl::runtime::NDArray IdArray;
typedef dgl::runtime::NDArray DegreeArray;
typedef dgl::runtime::NDArray BoolArray;
typedef dgl::runtime::NDArray IntArray;
namespace dgl {

class Graph;
class GraphOp;
struct Subgraph;

/*!
* \brief Base dgl graph index class.
*
* DGL's graph is directed. Vertices are integers enumerated from zero. Edges
* are uniquely identified by the two endpoints. Multi-edge is currently not
* supported.
* DGL's graph is directed. Vertices are integers enumerated from zero.
*
* Removal of vertices/edges is not allowed. Instead, the graph can only be "cleared"
* by removing all the vertices and edges.
Expand All @@ -40,17 +32,14 @@ struct Subgraph;
* If the length of src id array is one, it represents one-many connections.
* If the length of dst id array is one, it represents many-one connections.
*/
class Graph {
class Graph: public GraphInterface {
public:
/* \brief structure used to represent a list of edges */
typedef struct {
/* \brief the two endpoints and the id of the edge */
IdArray src, dst, id;
} EdgeArray;

/*! \brief default constructor */
explicit Graph(bool multigraph = false) : is_multigraph_(multigraph) {}

Graph(IdArray src_ids, IdArray dst_ids, IdArray edge_ids, size_t num_nodes,
bool multigraph = false);
zheng-da marked this conversation as resolved.
Show resolved Hide resolved

/*! \brief default copy constructor */
Graph(const Graph& other) = default;

Expand Down Expand Up @@ -118,6 +107,13 @@ class Graph {
return is_multigraph_;
}

/*!
* \return whether the graph is read-only
*/
virtual bool IsReadonly() const {
return false;
}

/*! \return the number of vertices in the graph.*/
uint64_t NumVertices() const {
return adjlist_.size();
Expand Down Expand Up @@ -311,42 +307,74 @@ class Graph {
*
* \return the reversed graph
*/
Graph Reverse() const;
GraphInterface::ptr Reverse() const;

/*!
* \brief Return the successor vector
* \param vid The vertex id.
* \return the successor vector
*/
const std::vector<dgl_id_t>& SuccVec(dgl_id_t vid) const {
return adjlist_[vid].succ;
DGLIdIters SuccVec(dgl_id_t vid) const {
return DGLIdIters(adjlist_[vid].succ.begin(), adjlist_[vid].succ.end());
}

/*!
* \brief Return the out edge id vector
* \param vid The vertex id.
* \return the out edge id vector
*/
const std::vector<dgl_id_t>& OutEdgeVec(dgl_id_t vid) const {
return adjlist_[vid].edge_id;
DGLIdIters OutEdgeVec(dgl_id_t vid) const {
return DGLIdIters(adjlist_[vid].edge_id.begin(), adjlist_[vid].edge_id.end());
}

/*!
* \brief Return the predecessor vector
* \param vid The vertex id.
* \return the predecessor vector
*/
const std::vector<dgl_id_t>& PredVec(dgl_id_t vid) const {
return reverse_adjlist_[vid].succ;
DGLIdIters PredVec(dgl_id_t vid) const {
return DGLIdIters(reverse_adjlist_[vid].succ.begin(), reverse_adjlist_[vid].succ.end());
}

/*!
* \brief Return the in edge id vector
* \param vid The vertex id.
* \return the in edge id vector
*/
const std::vector<dgl_id_t>& InEdgeVec(dgl_id_t vid) const {
return reverse_adjlist_[vid].edge_id;
DGLIdIters InEdgeVec(dgl_id_t vid) const {
return DGLIdIters(reverse_adjlist_[vid].edge_id.begin(),
reverse_adjlist_[vid].edge_id.end());
}

/*!
* \brief Reset the data in the graph and move its data to the returned graph object.
* \return a raw pointer to the graph object.
*/
virtual GraphInterface *Reset() {
Graph* gptr = new Graph();
*gptr = std::move(*this);
return gptr;
}

/*!
* \brief Get the adjacency matrix of the graph.
*
* By default, a row of returned adjacency matrix represents the destination
* of an edge and the column represents the source.
* \param transpose A flag to transpose the returned adjacency matrix.
* \param fmt the format of the returned adjacency matrix.
* \return a vector of three IdArray.
*/
virtual std::vector<IdArray> GetAdj(bool transpose, const std::string &fmt) const;

/*!
* \brief Sample a subgraph from the seed vertices with neighbor sampling.
* The neighbors are sampled with a uniformly distribution.
zheng-da marked this conversation as resolved.
Show resolved Hide resolved
* \return a subgraph
*/
virtual SampledSubgraph NeighborUniformSample(IdArray seeds, const std::string &neigh_type,
int num_hops, int expand_factor) const {
throw NotImplemented("NeighborUniformSample");
}

protected:
Expand Down Expand Up @@ -382,22 +410,6 @@ class Graph {
uint64_t num_edges_ = 0;
};

/*! \brief Subgraph data structure */
struct Subgraph {
/*! \brief The graph. */
Graph graph;
/*!
* \brief The induced vertex ids.
* \note This is also a map from the new vertex id to the vertex id in the parent graph.
*/
IdArray induced_vertices;
/*!
* \brief The induced edge ids.
* \note This is also a map from the new edge id to the edge id in the parent graph.
*/
IdArray induced_edges;
};

} // namespace dgl

#endif // DGL_GRAPH_H_
Loading