napistu_torch.vertex_tensor

VertexTensor - Container for vertex-aligned tensors with metadata.

This module provides a container class for storing vertex-aligned tensors with metadata to validate alignment and interpret features.

Classes

VertexTensor

Container for vertex-aligned tensors with metadata.

Classes

VertexTensor(data, feature_names, ...[, ...])

Container for vertex-aligned tensors with metadata.

class napistu_torch.vertex_tensor.VertexTensor(data: torch.Tensor, feature_names: List[str], vertex_names: Series, name: str, description: str | None = None)

Bases: object

Container for vertex-aligned tensors with metadata.

Keeps tensors aligned with NapistuGraph vertices, storing the necessary metadata to validate alignment and interpret features.

data

The vertex-aligned tensor with shape [num_vertices, num_features]

Type:

torch.Tensor

feature_names

Names of features (columns)

Type:

List[str]

vertex_names

Vertex names aligned with tensor rows

Type:

pd.Series

name

Name/identifier for this tensor (e.g., “pathway_memberships”)

Type:

str

description

Human-readable description of what this tensor represents

Type:

Optional[str]

Public Methods
--------------
save(filepath)

Save the VertexTensor to disk

load(filepath, map_location='cpu')

Load a VertexTensor from disk

align_to_napistu_data(napistu_data, inplace=True)

Align this VertexTensor to match the vertex ordering in NapistuData

classmethod load(filepath: str | Path, map_location: str = 'cpu') VertexTensor

Load from disk.

__init__(data: torch.Tensor, feature_names: List[str], vertex_names: Series, name: str, description: str | None = None)
align_to_napistu_data(napistu_data: NapistuData, inplace: bool = True) VertexTensor

Align this VertexTensor to match the vertex ordering in NapistuData.

Validates that vertex names match and reorders the tensor data if necessary to align with the NapistuData vertex ordering.

Parameters:
  • napistu_data (NapistuData) – The NapistuData object to align to

  • inplace (bool, default=True) – If True, modify this VertexTensor in place. If False, return a new VertexTensor with the alignment applied.

Returns:

The aligned VertexTensor (self if inplace=True, new instance otherwise)

Return type:

VertexTensor

Raises:

ValueError – If the number of vertices don’t match or if vertex names don’t match

copy() VertexTensor

Create a deep copy of this VertexTensor.

save(filepath: str | Path) None

Save to disk.