yobx.xtracing.numpy_array#

Proxy class for tracing numpy operations and converting them to ONNX.

Each NumpyArray wraps an ONNX tensor name inside a GraphBuilder. Arithmetic operators, numpy ufuncs and numpy array-functions performed on a NumpyArray are recorded as ONNX nodes in the underlying graph so that the resulting computation graph can later be exported to an ONNX model.

class yobx.xtracing.numpy_array.NumpyArray(name: str, graph_builder, dtype=None, shape=None)[source]#

Proxy for an ONNX tensor that traces numpy operations as ONNX graph nodes.

Instances are produced by trace_numpy_to_onnx() or directly by the FunctionTransformer converter when the input array is replaced by a symbolic placeholder. Every arithmetic operation, ufunc call, or reduction performed on a NumpyArray is recorded as an ONNX node in the underlying GraphBuilder.

The class follows the Python Array API standard and the numpy __array_ufunc__ / __array_function__ dispatch protocols so that plain numpy code can be traced without modification.

Parameters:
  • name – ONNX tensor name (a string handle in the graph).

  • graph_builder – the GraphBuilder that owns the graph being built.

  • dtype – optional numpy dtype for the tensor; used when creating scalar constants from Python literals.

  • shape – optional tensor shape.

property T: NumpyArray#

Transpose (reverses all axes).

astype(dtype) NumpyArray[source]#

Cast to dtype.

clip(a_min=None, a_max=None) NumpyArray[source]#

Clip values to [a_min, a_max].

property dtype: dtype | None#

Numpy dtype if known.

expand_dims(axis) NumpyArray[source]#

Add a size-1 dimension (numpy expand_dims).

flatten() NumpyArray[source]#

Flatten to a 1-D tensor.

max(axis=None, keepdims: bool = False) NumpyArray[source]#

Maximum along axis.

mean(axis=None, keepdims: bool = False) NumpyArray[source]#

Mean of elements along axis.

min(axis=None, keepdims: bool = False) NumpyArray[source]#

Minimum along axis.

property name: str#

ONNX tensor name.

prod(axis=None, keepdims: bool = False) NumpyArray[source]#

Product of elements along axis.

reshape(*shape) NumpyArray[source]#

Reshape the tensor.

property shape#

Tensor shape if known.

squeeze(axis=None) NumpyArray[source]#

Remove size-1 dimensions.

sum(axis=None, keepdims: bool = False) NumpyArray[source]#

Sum elements along axis.

transpose(*axes) NumpyArray[source]#

Transpose with optional axes permutation.