Skip to content

Latest commit

 

History

History
497 lines (371 loc) · 13.3 KB

AdjacencySpec.md

File metadata and controls

497 lines (371 loc) · 13.3 KB

tfgnn.AdjacencySpec

View source on GitHub

A type spec for tfgnn.Adjacency.

Inherits From: HyperAdjacencySpec

tfgnn.AdjacencySpec(
    data_spec: DataSpec,
    shape: tf.TensorShape,
    indices_dtype: tf.dtypes.DType,
    row_splits_dtype: tf.dtypes.DType,
    metadata: Metadata = None,
    check_consistent_indices_dtype: bool = False,
    check_consistent_row_splits_dtype: bool = False
)

Attributes

indices_dtype The dtype for graph items indexing. One of tf.int32 or tf.int64.
rank The rank of the GraphPiece. 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 of the GraphPiece.

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

source

source_name Returns the node set name for source nodes.
target
target_name Returns the node set name for target nodes.
total_size The total number of edges if known.
value_type The Python type for values that are compatible with this TypeSpec.

In particular, all values that are compatible with this TypeSpec must be an instance of this type.

Methods

experimental_as_proto

experimental_as_proto() -> struct_pb2.TypeSpecProto

Returns a proto representation of the TypeSpec instance.

Do NOT override for custom non-TF types.

experimental_from_proto

@classmethod
experimental_from_proto(
    proto: struct_pb2.TypeSpecProto
) -> 'TypeSpec'

Returns a TypeSpec instance based on the serialized proto.

Do NOT override for custom non-TF types.

Args
proto Proto generated using 'experimental_as_proto'.

experimental_type_proto

@classmethod
experimental_type_proto() -> Type[struct_pb2.TypeSpecProto]

Returns the type of proto associated with TypeSpec serialization.

Do NOT override for custom non-TF types.

from_incident_node_sets

View source

@classmethod
from_incident_node_sets(
    source_node_set: NodeSetName,
    target_node_set: NodeSetName,
    index_spec: tfgnn.FieldSpec = tf.TensorSpec((None,), const.default_indices_dtype)
) -> 'AdjacencySpec'

Constructs a new instance from the incident_node_sets.

Args
source_node_set The name of the source node set.
target_node_set The name of the target node set.
index_spec type spec for source and target index tensors of shape [*graph_shape, num_edges], where num_edges is the number of edges in each graph. If num_edges is not None or graph_shape.rank = 0 the spec must be of tf.TensorSpec type and of tf.RaggedTensorSpec type otherwise.
Returns
A AdjacencySpec TypeSpec.

from_value

View source

@classmethod
from_value(
    value: GraphPieceBase
)

Extension Types API: Factory method.

get_index_specs_dict

View source

get_index_specs_dict() -> Dict[IncidentNodeTag, Tuple[NodeSetName, FieldSpec]]

Returns copy of indices type specs as a dictionary.

is_compatible_with

is_compatible_with(
    spec_or_value
)

Returns true if spec_or_value is compatible with this TypeSpec.

Prefer using "is_subtype_of" and "most_specific_common_supertype" wherever possible.

Args
spec_or_value A TypeSpec or TypeSpec associated value to compare against.

is_subtype_of

is_subtype_of(
    other: trace.TraceType
) -> bool

Returns True if self is a subtype of other.

Implements the tf.types.experimental.func.TraceType interface.

If not overridden by a subclass, the default behavior is to assume the TypeSpec is covariant upon attributes that implement TraceType and invariant upon rest of the attributes as well as the structure and type of the TypeSpec.

Args
other A TraceType object.

most_specific_common_supertype

most_specific_common_supertype(
    others: Sequence[trace.TraceType]
) -> Optional['TypeSpec']

Returns the most specific supertype TypeSpec of self and others.

Implements the tf.types.experimental.func.TraceType interface.

If not overridden by a subclass, the default behavior is to assume the TypeSpec is covariant upon attributes that implement TraceType and invariant upon rest of the attributes as well as the structure and type of the TypeSpec.

Args
others A sequence of TraceTypes.

most_specific_compatible_type

most_specific_compatible_type(
    other: 'TypeSpec'
) -> 'TypeSpec'

Returns the most specific TypeSpec compatible with self and other. (deprecated)

Deprecated: THIS FUNCTION IS DEPRECATED. It will be removed in a future version. Instructions for updating: Use most_specific_common_supertype instead.

Deprecated. Please use most_specific_common_supertype instead. Do not override this function.

Args
other A TypeSpec.
Raises
ValueError If there is no TypeSpec that is compatible with both self and other.

node_set_name

View source

node_set_name(
    node_set_tag: IncidentNodeTag
) -> NodeSetName

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

relax

View source

relax(
    *, num_edges: bool = False
) -> 'AdjacencySpec'

Allows variable number of graph edges.

Calling with all default parameters keeps the spec unchanged.

Args
num_edges if True, allows a variable number of edges in each edge set. If False, returns spec unchanged.
Returns
Relaxed compatible spec.
Raises
ValueError if adjacency is not scalar (rank > 0).

with_indices_dtype

View source

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

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

with_row_splits_dtype

View source

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

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

with_shape

View source

with_shape(
    new_shape: ShapeLike
) -> 'GraphPieceSpecBase'

Enforce the common prefix shape on all the contained features.

__eq__

__eq__(
    other
) -> bool

Return self==value.

__getitem__

View source

__getitem__(
    node_set_tag: IncidentNodeTag
) -> tfgnn.FieldSpec

Returns an index tensor type spec for the given node set tag.

__ne__

__ne__(
    other
) -> bool

Return self!=value.