Skip to content

Cache

Cache helpers from annnet.core._Matrix.

Use G.cache for graph-owned cache helpers. Direct imports from underscore modules follow the internal API policy.

annnet.core._Matrix.CacheManager

The named sparse formats of one graph, over the one matrix cache.

G.B and the rest are built by :class:_matrices.MatrixCache, which keeps them against the clock of the store and extends a cached matrix when a write only appended edges at the frontier. The CSR form, the CSC form and the boundary-filtered adjacency are derived from those, and they used to be kept here instead, against a second clock the graph advanced itself. So one matrix could be current in one cache and stale in the other, and the two between them held the same entries twice.

This holds nothing. Every format below is an entry of the one cache, and dropping that cache drops these with it.

Attributes

csr property
csr

Return the CSR (Compressed Sparse Row) incidence matrix.

Returns:

Type Description
csr_matrix
csc property
csc

Return the CSC (Compressed Sparse Column) incidence matrix.

Returns:

Type Description
csc_matrix
adjacency property
adjacency

Return the adjacency matrix computed from incidence.

Returns:

Type Description
sparray
Notes

For incidence matrix B, adjacency is computed as A = B @ B.T. A boundary edge names one endpoint and no partner, and the is_boundary edge attribute flags it. Those columns leave B first, so they add neither a link between two nodes that share nothing nor a diagonal term that reads as a self-loop.

Functions

has_csr
has_csr()

Check whether a valid CSR cache exists.

Returns:

Type Description
bool
has_csc
has_csc()

Check whether a valid CSC cache exists.

Returns:

Type Description
bool
has_adjacency
has_adjacency()

Check whether a valid adjacency cache exists.

Returns:

Type Description
bool
get_csr
get_csr()

Return the cached CSR matrix.

Returns:

Type Description
csr_matrix
get_csc
get_csc()

Return the cached CSC matrix.

Returns:

Type Description
csc_matrix
get_adjacency
get_adjacency()

Return the cached adjacency matrix.

Returns:

Type Description
sparray
invalidate
invalidate(formats=None)

Invalidate cached formats.

Parameters:

Name Type Description Default
formats list[str]

Formats to invalidate ('csr', 'csc', 'adjacency'). If None, invalidate all.

None

Returns:

Type Description
None
build
build(formats=None)

Pre-build specified formats (eager caching).

Parameters:

Name Type Description Default
formats list[str]

Formats to build ('csr', 'csc', 'adjacency'). If None, build all.

None

Returns:

Type Description
None
clear
clear()

Clear all caches.

Returns:

Type Description
None
info
info()

Get cache status and memory usage.

Returns:

Type Description
dict

Status and size information for each cached format.