Stores how edges connect pairs of nodes from source and target node sets.
Inherits From: HyperAdjacency
tfgnn.Adjacency(
data: Data, spec: 'GraphPieceSpecBase'
)
Each hyper-edge connect one node from the source node set with one node from
the target node sets. The source and target node sets could be the same.
The adjacency information is a pair of integer tensors containing indices of
nodes in source and target node sets. Those tensors are indexed by
edges, have the same type spec and shape of [*graph_shape, num_edges]
,
where num_edges
is the number of edges in the edge set (could be potentially
ragged). The index tensors are of tf.Tensor
type if num_edges
is not
None
or graph_shape.rank = 0
and oftf.RaggedTensor
type otherwise.
The Adjacency is a composite tensor and a special case of tfgnn.HyperAdjacency
class with tfgnn.SOURCE
and tfgnn.TARGET
node tags used for the source and
target nodes correspondingly.
data
|
Nest of Field or subclasses of GraphPieceBase. |
spec
|
A subclass of GraphPieceSpecBase with a _data_spec that matches
data .
|
@classmethod
from_indices( source:
tfgnn.Field
, target:tfgnn.Field
, *_, validate: Optional[bool] = None ) -> 'Adjacency'
Constructs a new instance from the source
and target
node indices.
# Single graph (rank is 0). Connects pairs of nodes (a[0], b[2]),
# (a[1], b[1]), (a[2], b[0]) from node sets a and b.
tfgnn.Adjacency.from_indices(('a', [0, 1, 2]),
('b', [2, 1, 0]))
# Batch of two graphs (rank is 1). Connects pairs of nodes in
# graph 0: (a[0], b[2]), (a[1], b[1]); graph 1: (a[2], b[0]).
tfgnn.Adjacency.from_indices(('a', tf.ragged.constant([[0, 1], [2]])),
('b', tf.ragged.constant([[2, 1], [0]])))
Args | |
---|---|
source
|
The tuple of node set name and nodes index integer tensor. The
index must have shape of [*graph_shape, num_edges] , where num_edges
is the number of edges in each graph (could be ragged). It has
tf.Tensor type if num_edges is not None or graph_shape.rank = 0
and tf.RaggedTensor type otherwise.
|
target
|
Like source field, but for target edge endpoint. Index tensor
must have the same type spec as for the source .
|
validate
|
If True , checks that source and target indices have the same
type spec.
|
Returns | |
---|---|
An Adjacency tensor with a shape and an indices_dtype being inferred
from the indices values.
|
get_indices_dict() -> Dict[IncidentNodeTag, Tuple[NodeSetName, Field]]
Returns copy of indices as a dictionary.
node_set_name(
node_set_tag: IncidentNodeTag
) -> NodeSetName
Returns a node set name for the given node set tag.
set_shape(
new_shape: ShapeLike
) -> 'GraphPieceBase'
Deprecated. Use with_shape()
.
with_indices_dtype(
dtype: tf.dtypes.DType
) -> 'GraphPieceBase'
Returns a copy of this piece with the given indices dtype.
with_row_splits_dtype(
dtype: tf.dtypes.DType
) -> 'GraphPieceBase'
Returns a copy of this piece with the given row splits dtype.
with_shape(
new_shape: ShapeLike
) -> 'GraphPieceBase'
Enforce the common prefix shape on all the contained features.
__getitem__(
node_set_tag: IncidentNodeTag
) -> tfgnn.Field
Returns an index tensor for the given node set tag.