Class Vectors¶
Thin wrappers over std::vector<T> for the element types anira’s
C++ API exposes. Each Vector* class shares the same surface
(size, push, get, destroy) and inherits from
VectorBase.
Note
Construct via the Class AniraWeb factory in most cases:
aniraWeb.VectorSizeT([2, 1]) rather than
new VectorSizeT(...). The factory threads the WASM instance
through for you, and most constructors accept a plain JS array as
a convenience initializer.
Common Surface¶
Every Vector* class supports:
size()→number— element count.push(value)— append one element. Element type depends on the class (see table below). Object-vectorpushaccepts either a wrapper instance or its raw pointer.get(index)— read one element. Primitive vectors return the element by value; object vectors return a non-owning raw pointer to the underlying C++ element.destroy()— free the underlying C++ object. See Lifecycle and Cleanup.
Most constructors also accept a JS array of initial values that is pushed eagerly during construction.
The Vector Family¶
Class |
Underlying C++ type |
Element type |
|
|---|---|---|---|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
alias of |
same as |
same as |
|
|
Class ModelData / pointer |
n/a — push-only |
|
|
Class TensorShape / pointer |
n/a — push-only |
|
|
Class RingBuffer / pointer |
|
|
|
Class BufferF / pointer |
|
VectorVectorInt64 accepts several convenience forms during
construction:
number[][]— each inner array is auto-converted tobigintand wrapped in a temporaryVectorInt64Tthat is destroyed after the inner copy is taken.bigint[][]— same thing, used as-is.(VectorInt64T | number)[]— existing wrapper instances or raw pointers; the C++ side copies each inner vector.
TensorShapeList is identical to VectorVectorInt64; it exists
purely so call sites that build tensor shapes read more naturally.
Typical Use¶
// Primitive vectors initialised from a JS array.
const channels = aniraWeb.VectorSizeT([2, 1])
const sizes = aniraWeb.VectorSizeT([512, 0])
// Object vector: pass wrapper instances directly.
const modelData = aniraWeb.ModelData(modelBuffer, aniraWeb.InferenceBackend.ONNX)
const vectorModelData = aniraWeb.VectorModelData([modelData])
// Nested-int64 vector: nested JS array, auto-converted.
const shapes = aniraWeb.TensorShapeList([[1, 2, 512], [1]])