Create a graph from a :class:`cugraph.Graph` object. Parameters ---------- cugraph_graph : cugraph.Graph The cugraph graph object holding the graph structure. Node and edge attributes are dropped. If the input graph is undirected, DGL converts it to a directed g
(cugraph_graph)
| 1935 | |
| 1936 | |
| 1937 | def from_cugraph(cugraph_graph): |
| 1938 | """Create a graph from a :class:`cugraph.Graph` object. |
| 1939 | |
| 1940 | Parameters |
| 1941 | ---------- |
| 1942 | cugraph_graph : cugraph.Graph |
| 1943 | The cugraph graph object holding the graph structure. Node and edge attributes are |
| 1944 | dropped. |
| 1945 | |
| 1946 | If the input graph is undirected, DGL converts it to a directed graph |
| 1947 | by :func:`cugraph.Graph.to_directed`. |
| 1948 | |
| 1949 | Returns |
| 1950 | ------- |
| 1951 | DGLGraph |
| 1952 | The created graph. |
| 1953 | |
| 1954 | Examples |
| 1955 | -------- |
| 1956 | |
| 1957 | The following example uses PyTorch backend. |
| 1958 | |
| 1959 | >>> import dgl |
| 1960 | >>> import cugraph |
| 1961 | >>> import cudf |
| 1962 | |
| 1963 | Create a cugraph graph. |
| 1964 | >>> cugraph_g = cugraph.Graph(directed=True) |
| 1965 | >>> df = cudf.DataFrame({"source":[0, 1, 2, 3], |
| 1966 | "destination":[1, 2, 3, 0]}) |
| 1967 | >>> cugraph_g.from_cudf_edgelist(df) |
| 1968 | |
| 1969 | Convert it into a DGLGraph |
| 1970 | >>> g = dgl.from_cugraph(cugraph_g) |
| 1971 | >>> g.edges() |
| 1972 | (tensor([1, 2, 3, 0], device='cuda:0'), tensor([2, 3, 0, 1], device='cuda:0')) |
| 1973 | """ |
| 1974 | if not cugraph_graph.is_directed(): |
| 1975 | cugraph_graph = cugraph_graph.to_directed() |
| 1976 | |
| 1977 | edges = cugraph_graph.edges() |
| 1978 | src_t = F.zerocopy_from_dlpack(edges["src"].to_dlpack()) |
| 1979 | dst_t = F.zerocopy_from_dlpack(edges["dst"].to_dlpack()) |
| 1980 | g = graph((src_t, dst_t)) |
| 1981 | |
| 1982 | return g |
| 1983 | |
| 1984 | |
| 1985 | ############################################################ |