csr
Compressed Sparse Row (CSR) utilities for variable-length data.
Classes
CSRArray
CSR representation for variable-length node data.
Attributes
| Name | Type | Description |
|---|---|---|
| _data | — | — |
| _indptr | — | — |
| _ram_data | NDArray[] | None | — |
| _ram_indptr | NDArray[] | None | — |
| data | NDArray[] | Return data, using RAM cache if available. |
| indptr | NDArray[] | Return indptr, using RAM cache if available. |
| is_cached | bool | Return True if data is cached in RAM. |
Methods
__init__(self, indptr: NDArray[], data: NDArray[]) → NoneParameters
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]]) → CSRArrayBuild CSR from sequence of sequences.
Parameters
clssequences: 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') → CSRArrayLoad from files.
Parameters
clspath_prefix: strmmap_mode: str= 'r'
memory_usage_bytes(self) → intReturn memory used by RAM cache, or 0 if not cached.
preload_to_ram(self) → NoneLoad CSR data into RAM for faster access.
release_cache(self) → NoneRelease RAM cache, returning to mmap-only access.
save(self, path_prefix: str) → NoneSave to {path_prefix}_indptr.npy and {path_prefix}_data.npy
Parameters
path_prefix: str
CSRArrayWithValues
(CSRArray)CSR with associated values (for edge features with values).
Attributes
| Name | Type | Description |
|---|---|---|
| indices | — | — |
| values | — | — |
Methods
__init__(self, indptr: NDArray[], indices: NDArray[], values: NDArray[Any]) → NoneParameters
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') → CSRArrayWithValuesBuild from dict[int, dict[int, value]].
Parameters
clsdata: dict[(int, dict[(int, Any)])]num_rows: intvalue_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') → CSRArrayWithValuesLoad from files (with string decoding if needed).
Parameters
clspath_prefix: strmmap_mode: str= 'r'
save(self, path_prefix: str) → NoneSave to files including values (with string encoding if needed).
Parameters
path_prefix: str