Documentation

csr

Compressed Sparse Row (CSR) utilities for variable-length data.

Classes

class

CSRArray

CSR representation for variable-length node data.

CSR representation for variable-length node data. For data where each node maps to a variable number of values (e.g., oslots, edges, levUp/levDown). Attributes ---------- indptr : np.ndarray Index pointers. Row i contains data[indptr[i]:indptr[i+1]] data : np.ndarray Concatenated row data

Attributes

NameTypeDescription
_data
_indptr
_ram_dataNDArray[] | None
_ram_indptrNDArray[] | None
dataNDArray[]Return data, using RAM cache if available.
indptrNDArray[]Return indptr, using RAM cache if available.
is_cachedboolReturn True if data is cached in RAM.

Methods

__init__(self, indptr: NDArray[], data: NDArray[]) None
Parameters
  • indptr: NDArray[]
  • data: NDArray[]
filter_sources_with_targets_in(self, sources: set[int], target_set: set[int]) tuple[(set[int], set[int])]

Filter sources that have at least one target in target_set.

Parameters
  • sources: set[int]
  • target_set: set[int]
from_sequences(cls, sequences: Sequence[Sequence[int]]) CSRArray

Build CSR from sequence of sequences.

Parameters
  • cls
  • sequences: Sequence[Sequence[int]]
get_all_targets(self, sources: set[int]) set[int]

Get union of all targets for a set of source nodes.

Parameters
  • sources: set[int]
get_as_tuple(self, i: int) tuple[(int, ...)]

Get data for row i as tuple (alias for __getitem__).

Parameters
  • i: int
load(cls, path_prefix: str, mmap_mode: str = 'r') CSRArray

Load from files.

Parameters
  • cls
  • path_prefix: str
  • mmap_mode: str= 'r'
memory_usage_bytes(self) int

Return memory used by RAM cache, or 0 if not cached.

preload_to_ram(self) None

Load CSR data into RAM for faster access.

release_cache(self) None

Release RAM cache, returning to mmap-only access.

save(self, path_prefix: str) None

Save to {path_prefix}_indptr.npy and {path_prefix}_data.npy

Parameters
  • path_prefix: str
class

CSRArrayWithValues

(CSRArray)

CSR with associated values (for edge features with values).

Attributes

NameTypeDescription
indices
values

Methods

__init__(self, indptr: NDArray[], indices: NDArray[], values: NDArray[Any]) None
Parameters
  • indptr: NDArray[]
  • indices: NDArray[]
  • values: NDArray[Any]
from_dict_of_dicts(cls, data: dict[(int, dict[(int, Any)])], num_rows: int, value_dtype: str = 'int32') CSRArrayWithValues

Build from dict[int, dict[int, value]].

Parameters
  • cls
  • data: dict[(int, dict[(int, Any)])]
  • num_rows: int
  • value_dtype: str= 'int32'
get_as_dict(self, i: int) dict[(int, Any)]

Get as {index: value} dict for row i.

Parameters
  • i: int
load(cls, path_prefix: str, mmap_mode: str = 'r') CSRArrayWithValues

Load from files (with string decoding if needed).

Parameters
  • cls
  • path_prefix: str
  • mmap_mode: str= 'r'
save(self, path_prefix: str) None

Save to files including values (with string encoding if needed).

Parameters
  • path_prefix: str