Skip to content

Latest commit

 

History

History
299 lines (230 loc) · 8.64 KB

Adjacency.md

File metadata and controls

299 lines (230 loc) · 8.64 KB

tfgnn.Adjacency

View source on GitHub

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.

Args

data Nest of Field or subclasses of GraphPieceBase.
spec A subclass of GraphPieceSpecBase with a _data_spec that matches data.

Attributes

indices_dtype The dtype for graph items indexing. One of tf.int32 or tf.int64.
rank The rank of this Tensor. Guaranteed not to be None.
row_splits_dtype The dtype for ragged row partitions. One of tf.int32 or tf.int64.
shape A possibly-partial shape specification for this Tensor.

The returned tf.TensorShape is guaranteed to have a known rank and no unknown dimensions except possibly the outermost.

source The indices of source nodes.
source_name The node set name of source nodes.
spec The public type specification of this tensor.
target The indices of target nodes.
target_name The node set name of target nodes.

Methods

from_indices

View source

@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.

Example 1:

# 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]))

Example 2:

# 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

View source

get_indices_dict() -> Dict[IncidentNodeTag, Tuple[NodeSetName, Field]]

Returns copy of indices as a dictionary.

node_set_name

View source

node_set_name(
    node_set_tag: IncidentNodeTag
) -> NodeSetName

Returns a node set name for the given node set tag.

set_shape

View source

set_shape(
    new_shape: ShapeLike
) -> 'GraphPieceBase'

Deprecated. Use with_shape().

with_indices_dtype

View source

with_indices_dtype(
    dtype: tf.dtypes.DType
) -> 'GraphPieceBase'

Returns a copy of this piece with the given indices dtype.

with_row_splits_dtype

View source

with_row_splits_dtype(
    dtype: tf.dtypes.DType
) -> 'GraphPieceBase'

Returns a copy of this piece with the given row splits dtype.

with_shape

View source

with_shape(
    new_shape: ShapeLike
) -> 'GraphPieceBase'

Enforce the common prefix shape on all the contained features.

__getitem__

View source

__getitem__(
    node_set_tag: IncidentNodeTag
) -> tfgnn.Field

Returns an index tensor for the given node set tag.