numbox.core.vector

Overview

Generic growable numba vector backed by a numpy array.

Compared to numba.typed.List:

  • List supports arbitrary element types (including other structrefs) and exposes a richer API (append, pop, insert, remove, slicing).

  • Vector is restricted to scalar element types where str(elem_type) matches a numpy dtype (float64, int64, etc.). make_vector memoises instances by elem_type.key, so cached code keeps the same type identity across processes. Storage is a single numpy.ndarray, so per-element overhead is the scalar itself plus amortised geometric growth.

Modules

numbox.core.vector.vector

class numbox.core.vector.vector.Vector(*args, **kwargs)[source]

Bases: StructRefProxy

property buf
property size
class numbox.core.vector.vector.VectorTypeClass(*args, **kwargs)[source]

Bases: StructRef

Single module-level class, parameterized per elem_type via field-tuple instances.

preprocess_fields(fields)[source]

Subclasses can override this to do additional clean up on fields.

The default is an identity function.

Parameters:

fields : Sequence[Tuple[str, Type]]

numbox.core.vector.vector.make_vector(elem_type)[source]

Return (create, type_instance) for Vector[elem_type].

  • create: an @njit factory taking a single capacity argument. Dtype is locked by the type — callers cannot pass a mismatched buffer.

  • type_instance: the VectorType instance with resolved field types.

Results are memoized in _vector_cache keyed by elem_type.key.

The numpy dtype is derived from str(elem_type) at build time. Works for standard scalar numba types (float64, int64, etc.). Exotic types where str() does not match a numpy dtype name are unsupported.

Initial capacity must be >= 1. The create factory asserts this. Zero-capacity construction is rejected because the geometric growth in vector_push / vector_extend would produce 0 * 2 = 0 and either OOB or infinite-loop. Vectors only grow, never shrink, so a positive initial capacity guarantees a positive capacity for all time.

numbox.core.vector.vector.vector_extend(dst, src)[source]
numbox.core.vector.vector.vector_push(v, val)[source]