kaptive.core.collections¶
Protocol contracts for Structure-of-Arrays (SoA) and batched containers.
This module defines formal protocols (BatchedContainer
and RaggedArrayContainer) that govern high-performance,
vectorized containers across Kaptive.
Classes:
-
BatchedContainerβA formal contract for Structure-of-Arrays (SoA) and batched containers in Kaptive.
-
RaggedArrayContainerβA formal contract for ragged Structure-of-Arrays (SoA) containers.
BatchedContainer
¶
flowchart TD
kaptive.core.collections.BatchedContainer[BatchedContainer]
click kaptive.core.collections.BatchedContainer href "" "kaptive.core.collections.BatchedContainer"
A formal contract for Structure-of-Arrays (SoA) and batched containers in Kaptive.
This protocol ensures that all high-performance vectorized collections provide a standard interface for instantiation, concatenation, and indexing without relying on slow dynamic mixins or runtime type introspection.
Class Type Parameters:
-
βT¶The scalar record type returned when accessing a single index.
-
βS¶The batched container type returned when indexing with slices or array masks.
Methods:
-
__getitem__βAccess records by index, slice, or boolean/integer array mask.
-
__len__βReturn the number of records in the batch.
-
concatβConcatenate multiple collections into a single, larger collection.
-
emptyβCreate an empty, 0-length collection with correctly typed arrays.
__getitem__
¶
Access records by index, slice, or boolean/integer array mask.
Parameters:
Returns:
-
T | SβT | S: A single scalar record (
T) if an integer index is provided, or a new batched collection (S) if a slice or mask is provided.
Raises:
-
IndexErrorβIf an integer index is out of bounds.
Source code in src/kaptive/core/collections.py
__len__
¶
__len__() -> int
Return the number of records in the batch.
Returns:
-
int(int) βThe total count of items in the container.
concat
classmethod
¶
Concatenate multiple collections into a single, larger collection.
Parameters:
Returns:
-
S(Self) βA new, combined collection.
Raises:
-
ValueErrorβIf the input iterable is empty or contains incompatible batches.
Source code in src/kaptive/core/collections.py
RaggedArrayContainer
¶
flowchart TD
kaptive.core.collections.RaggedArrayContainer[RaggedArrayContainer]
kaptive.core.collections.BatchedContainer[BatchedContainer]
kaptive.core.collections.BatchedContainer --> kaptive.core.collections.RaggedArrayContainer
click kaptive.core.collections.RaggedArrayContainer href "" "kaptive.core.collections.RaggedArrayContainer"
click kaptive.core.collections.BatchedContainer href "" "kaptive.core.collections.BatchedContainer"
A formal contract for ragged Structure-of-Arrays (SoA) containers.
Ragged containers store variable-length data (such as sequences or CIGAR operations) in a flat,
contiguous memory layout, managing sequence boundaries using offsets and lengths arrays.
Attributes:
-
offsets(NDArray[int32]) βStarting indices into the flat data array for each record.
-
lengths(NDArray[int32]) βNumber of elements in the flat array for each record.
Methods:
-
__getitem__βAccess records by index, slice, or boolean/integer array mask.
-
__len__βReturn the number of records in the batch.
-
concatβConcatenate multiple collections into a single, larger collection.
-
emptyβCreate an empty, 0-length collection with correctly typed arrays.
__getitem__
¶
Access records by index, slice, or boolean/integer array mask.
Parameters:
Returns:
-
T | SβT | S: A single scalar record (
T) if an integer index is provided, or a new batched collection (S) if a slice or mask is provided.
Raises:
-
IndexErrorβIf an integer index is out of bounds.
Source code in src/kaptive/core/collections.py
__len__
¶
__len__() -> int
Return the number of records in the batch.
Returns:
-
int(int) βThe total count of items in the container.
concat
classmethod
¶
Concatenate multiple collections into a single, larger collection.
Parameters:
Returns:
-
S(Self) βA new, combined collection.
Raises:
-
ValueErrorβIf the input iterable is empty or contains incompatible batches.