NumPy-style operations

Shapes are static, have rank at most six, and use positive dimensions. Arrays are immutable. Unsupported operations are rejected rather than forwarded to NumPy. Device admission also depends on the selected backend and dtype.

A deliberately small NumPy-style tensor namespace.

Eager calls are an explicit CPU reference implementation. Traced calls construct TOSA-compatible primitives. Unsupported functions are not forwarded to NumPy.

virtio_accel.numpy.asarray(a, dtype=None)

Create an immutable array or reuse an existing compatible Array.

FP16, BF16, FP32, FP8 E4M3FN/E5M2, INT8 and INT32 are supported. Host inputs are copied; symbolic values retain their trace. Use dtype to request an explicit conversion.

virtio_accel.numpy.array(a, dtype=None)

Create an immutable array; equivalent to asarray().

virtio_accel.numpy.zeros(shape, dtype=<class 'numpy.float32'>)

Create a static array filled with zeros; default dtype is FP32.

virtio_accel.numpy.ones(shape, dtype=<class 'numpy.float32'>)

Create a static array filled with ones; default dtype is FP32.

virtio_accel.numpy.full(shape, fill_value, dtype=<class 'numpy.float32'>)

Create a constant with a static shape and scalar fill value.

Dimensions must be positive and rank at most six; default dtype is FP32.

virtio_accel.numpy.add(a, b)

Add arrays elementwise with broadcasting and frontend dtype promotion.

virtio_accel.numpy.subtract(a, b)

Subtract arrays elementwise with broadcasting and frontend dtype promotion.

virtio_accel.numpy.multiply(a, b)

Multiply arrays elementwise with broadcasting and frontend dtype promotion.

virtio_accel.numpy.maximum(a, b)

Select elementwise maxima with broadcasting and dtype promotion.

virtio_accel.numpy.minimum(a, b)

Select elementwise minima with broadcasting and dtype promotion.

virtio_accel.numpy.negative(a)

Negate each element, preserving shape and dtype.

virtio_accel.numpy.abs(a)

Compute absolute values elementwise, preserving shape and dtype.

virtio_accel.numpy.exp(a)

Compute the exponential elementwise, preserving shape and dtype.

virtio_accel.numpy.log(a)

Compute the natural logarithm elementwise, preserving shape and dtype.

virtio_accel.numpy.tanh(a)

Compute the hyperbolic tangent elementwise, preserving shape and dtype.

virtio_accel.numpy.sin(a)

Compute sine elementwise in radians, preserving shape and dtype.

virtio_accel.numpy.cos(a)

Compute cosine elementwise in radians, preserving shape and dtype.

virtio_accel.numpy.matmul(a, b)

Multiply two matrices or two batches with matching batch counts.

Both operands must have the same rank, either two or three, with matching inner dimensions. Batch broadcasting and vector inputs are unsupported. INT8 operands produce exact INT32 output (zero points are zero). BF16 operands produce FP32 accumulator output; other output dtypes follow frontend promotion.

virtio_accel.numpy.reshape(a, shape)

Change shape without changing the element count.

One dimension may be -1 for inference; all resolved dimensions must be positive. The resulting rank must not exceed six.

virtio_accel.numpy.transpose(a, axes=None)

Permute dimensions; reverse all dimensions when axes is None.

Explicit axes must be a complete permutation; negative axes are accepted.

virtio_accel.numpy.astype(a, dtype)

Explicitly cast an array; integer casts are limited to INT8 widening.

virtio_accel.numpy.sum(a, axis=None, dtype=None, out=None, keepdims=False)

Sum over all dimensions or the specified integer/tuple of axes.

Negative axes are accepted; duplicates are rejected. keepdims retains reduced dimensions of size one. dtype explicitly selects the result dtype; out must be None because arrays are immutable.

virtio_accel.numpy.mean(a, axis=None, dtype=None, out=None, keepdims=False)

Average over all dimensions or specified integer/tuple of axes.

Uses the same axis, dtype and keepdims rules as sum(). out must be None. Backend admission depends on the selected dtype.

Dtypes

virtio_accel.numpy.float16

Half-precision floating-point number type.

Character code:

'e'

Canonical name:

numpy.half

Alias on this platform (Linux x86_64):

numpy.float16: 16-bit-precision floating-point number type: sign bit, 5 bits exponent, 10 bits mantissa.

NumPy binary16 dtype; a supported frontend storage and arithmetic type.

virtio_accel.numpy.bfloat16

bfloat16 floating-point values

ml_dtypes.bfloat16; BF16 MATMUL produces FP32 accumulator output.

virtio_accel.numpy.float32

Single-precision floating-point number type, compatible with C float.

Character code:

'f'

Canonical name:

numpy.single

Alias on this platform (Linux x86_64):

numpy.float32: 32-bit-precision floating-point number type: sign bit, 8 bits exponent, 23 bits mantissa.

NumPy binary32 dtype; backend support must still be checked.

virtio_accel.numpy.float8_e4m3fn

float8_e4m3fn floating-point values

ml_dtypes.float8_e4m3fn; one-byte E4M3FN storage, casts and movement. Widen explicitly before arithmetic.

virtio_accel.numpy.float8_e5m2

float8_e5m2 floating-point values

ml_dtypes.float8_e5m2; one-byte E5M2 storage, casts and movement.

virtio_accel.numpy.int8

Signed integer type, compatible with C char.

Character code:

'b'

Canonical name:

numpy.byte

Alias on this platform (Linux x86_64):

numpy.int8: 8-bit signed integer (-128 to 127).

Signed INT8 storage and MATMUL operands; also a raw NVFP4 byte carrier.

virtio_accel.numpy.int32

Signed integer type, compatible with C int.

Character code:

'i'

Canonical name:

numpy.intc

Alias on this platform (Linux x86_64):

numpy.int32: 32-bit signed integer (-2_147_483_648 to 2_147_483_647).

Signed INT32 storage and integer MATMUL output. No implicit float promotion.