Indexing
Indexing and topology helpers from annnet.core._Matrix.
Use G.idx for graph-owned row/column lookup operations. Direct imports from
underscore modules follow the internal API policy.
annnet.core._Matrix.IndexManager
Namespace for entity-row and edge-column lookups.
The manager exposes the incidence-matrix indexing layer without surfacing the internal storage dicts directly. It is the preferred public path for translating between graph identifiers and matrix coordinates.
Functions
entity_to_row
Map an entity ID to its matrix row index.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
entity_id
|
str
|
Entity identifier. |
required |
Returns:
| Type | Description |
|---|---|
int
|
Row index for the entity. |
Raises:
| Type | Description |
|---|---|
KeyError
|
If the entity is not found. |
row_to_entity
Map a matrix row index to its entity ID.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
row
|
int
|
Row index. |
required |
Returns:
| Type | Description |
|---|---|
str
|
Entity identifier. |
Raises:
| Type | Description |
|---|---|
KeyError
|
If the row index is not found. |
entities_to_rows
Batch convert entity IDs to row indices.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
entity_ids
|
Iterable[str]
|
Entity identifiers. |
required |
Returns:
| Type | Description |
|---|---|
list[int]
|
|
rows_to_entities
Batch convert row indices to entity IDs.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
rows
|
Iterable[int]
|
Row indices. |
required |
Returns:
| Type | Description |
|---|---|
list[str]
|
|
edge_to_col
Map an edge ID to its matrix column index.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
edge_id
|
str
|
Edge identifier. |
required |
Returns:
| Type | Description |
|---|---|
int
|
Column index for the edge. |
Raises:
| Type | Description |
|---|---|
KeyError
|
If the edge is not found. |
col_to_edge
Map a matrix column index to its edge ID.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
col
|
int
|
Column index. |
required |
Returns:
| Type | Description |
|---|---|
str
|
Edge identifier. |
Raises:
| Type | Description |
|---|---|
KeyError
|
If the column index is not found. |
edges_to_cols
Batch convert edge IDs to column indices.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
edge_ids
|
Iterable[str]
|
Edge identifiers. |
required |
Returns:
| Type | Description |
|---|---|
list[int]
|
|
cols_to_edges
Batch convert column indices to edge IDs.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
cols
|
Iterable[int]
|
Column indices. |
required |
Returns:
| Type | Description |
|---|---|
list[str]
|
|
entity_type
Get the entity type for an ID.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
entity_id
|
str
|
Entity identifier. |
required |
Returns:
| Type | Description |
|---|---|
str
|
|
Raises:
| Type | Description |
|---|---|
KeyError
|
If the entity is not found. |
is_vertex
Check whether an entity ID refers to a vertex.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
entity_id
|
str
|
Entity identifier. |
required |
Returns:
| Type | Description |
|---|---|
bool
|
|
is_edge_entity
Check whether an entity ID refers to an edge-entity.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
entity_id
|
str
|
Entity identifier. |
required |
Returns:
| Type | Description |
|---|---|
bool
|
|
has_entity
Check if an ID exists as any entity.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
entity_id
|
str
|
Entity identifier. |
required |
Returns:
| Type | Description |
|---|---|
bool
|
|
has_vertex
Check if an ID exists and is a vertex.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
vertex_id
|
str
|
Vertex identifier. |
required |
Returns:
| Type | Description |
|---|---|
bool
|
|
has_edge_id
Check if an edge ID exists.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
edge_id
|
str
|
Edge identifier. |
required |
Returns:
| Type | Description |
|---|---|
bool
|
|
entity_count
Return the number of entities (vertices + edge-entities).
Returns:
| Type | Description |
|---|---|
int
|
|
vertex_count
Return the number of true vertices (excludes edge-entities).
Returns:
| Type | Description |
|---|---|
int
|
|
annnet.core._Matrix.IndexMapping
Internal indexing helpers used by :class:annnet.core.graph.AnnNet.