MCPcopy
hub / github.com/pyg-team/pytorch_geometric / Data

Class Data

torch_geometric/data/data.py:472–1249  ·  view source on GitHub ↗

r"""A data object describing a homogeneous graph. The data object can hold node-level, link-level and graph-level attributes. In general, :class:`~torch_geometric.data.Data` tries to mimic the behavior of a regular :python:`Python` dictionary. In addition, it provides useful function

Source from the content-addressed store, hash-verified

470
471
472class Data(BaseData, FeatureStore, GraphStore):
473 r"""A data object describing a homogeneous graph.
474 The data object can hold node-level, link-level and graph-level attributes.
475 In general, :class:`~torch_geometric.data.Data` tries to mimic the
476 behavior of a regular :python:`Python` dictionary.
477 In addition, it provides useful functionality for analyzing graph
478 structures, and provides basic PyTorch tensor functionalities.
479 See `here <https://pytorch-geometric.readthedocs.io/en/latest/get_started/
480 introduction.html#data-handling-of-graphs>`__ for the accompanying
481 tutorial.
482
483 .. code-block:: python
484
485 from torch_geometric.data import Data
486
487 data = Data(x=x, edge_index=edge_index, ...)
488
489 # Add additional arguments to `data`:
490 data.train_idx = torch.tensor([...], dtype=torch.long)
491 data.test_mask = torch.tensor([...], dtype=torch.bool)
492
493 # Analyzing the graph structure:
494 data.num_nodes
495 >>> 23
496
497 data.is_directed()
498 >>> False
499
500 # PyTorch tensor functionality:
501 data = data.pin_memory()
502 data = data.to('cuda:0', non_blocking=True)
503
504 Args:
505 x (torch.Tensor, optional): Node feature matrix with shape
506 :obj:`[num_nodes, num_node_features]`. (default: :obj:`None`)
507 edge_index (LongTensor, optional): Graph connectivity in COO format
508 with shape :obj:`[2, num_edges]`. (default: :obj:`None`)
509 edge_attr (torch.Tensor, optional): Edge feature matrix with shape
510 :obj:`[num_edges, num_edge_features]`. (default: :obj:`None`)
511 y (torch.Tensor, optional): Graph-level or node-level ground-truth
512 labels with arbitrary shape. (default: :obj:`None`)
513 pos (torch.Tensor, optional): Node position matrix with shape
514 :obj:`[num_nodes, num_dimensions]`. (default: :obj:`None`)
515 time (torch.Tensor, optional): The timestamps for each event with shape
516 :obj:`[num_edges]` or :obj:`[num_nodes]`. (default: :obj:`None`)
517 **kwargs (optional): Additional attributes.
518 """
519 def __init__(
520 self,
521 x: Optional[Tensor] = None,
522 edge_index: OptTensor = None,
523 edge_attr: OptTensor = None,
524 y: Optional[Union[Tensor, int, float]] = None,
525 pos: OptTensor = None,
526 time: OptTensor = None,
527 **kwargs,
528 ):
529 # `Data` doesn't support group_name, so we need to adjust `TensorAttr`

Callers 15

test_to_networkxFunction · 0.90
test_from_networkxFunction · 0.90
test_trimesh_vice_versaFunction · 0.90
test_to_trimeshFunction · 0.90
test_to_dgl_graphFunction · 0.90
test_to_dgl_sparseFunction · 0.90

Calls

no outgoing calls

Tested by 15

test_to_networkxFunction · 0.72
test_from_networkxFunction · 0.72
test_trimesh_vice_versaFunction · 0.72
test_to_trimeshFunction · 0.72
test_to_dgl_graphFunction · 0.72
test_to_dgl_sparseFunction · 0.72