numbox.core.vector
Overview
Generic growable numba vector backed by a numpy array.
Compared to numba.typed.List:
Listsupports arbitrary element types (including other structrefs) and exposes a richer API (append,pop,insert,remove, slicing).Vectoris restricted to scalar element types wherestr(elem_type)matches a numpy dtype (float64,int64, etc.).make_vectormemoises instances byelem_type.key, so cached code keeps the same type identity across processes. Storage is a singlenumpy.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:
StructRefSingle module-level class, parameterized per elem_type via field-tuple instances.
- numbox.core.vector.vector.make_vector(elem_type)[source]
Return
(create, type_instance)forVector[elem_type].create: an@njitfactory taking a singlecapacityargument. Dtype is locked by the type — callers cannot pass a mismatched buffer.type_instance: theVectorTypeinstance with resolved field types.
Results are memoized in
_vector_cachekeyed byelem_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 wherestr()does not match a numpy dtype name are unsupported.Initial
capacitymust be>= 1. Thecreatefactory asserts this. Zero-capacity construction is rejected because the geometric growth invector_push/vector_extendwould produce0 * 2 = 0and either OOB or infinite-loop. Vectors only grow, never shrink, so a positive initial capacity guarantees a positive capacity for all time.