npx.npx_numpy_tensors#

class onnx_array_api.npx.npx_numpy_tensors.EagerNumpyTensor(tensor: ndarray)[source]#

Defines a value for a specific backend.

class onnx_array_api.npx.npx_numpy_tensors.JitNumpyTensor(tensor: ndarray)[source]#

Defines a value for a specific backend.

class onnx_array_api.npx.npx_numpy_tensors.NumpyTensor(tensor: ndarray)[source]#

Default backend based on onnx.reference.ReferenceEvaluator().

Parameters:
  • input_names – input names

  • onx – onnx model

class Evaluator(tensor_class: type, input_names: List[str], onx: ModelProto)[source]#

Wraps class onnx.reference.ReferenceEvaluator to have a signature closer to python function.

run(*inputs: List[NumpyTensor]) List[NumpyTensor][source]#

Executes the function.

Parameters:

inputs – function inputs

Returns:

outputs

const_cast(to: Any | None = None) EagerTensor[source]#

Casts a constant without any ONNX conversion.

classmethod create_function(input_names: List[str], onx: ModelProto) Callable[source]#

Creates a python function calling the onnx backend used by this class.

Parameters:

onx – onnx model

Returns:

python function

property dims#

Returns the dimensions of the tensor. First dimension is the batch dimension if the tensor has more than one dimension.

property dtype: Any#

Returns the element type of this tensor.

classmethod get_ir_version(ir_version)[source]#

Updates the IR version. This method should be overloaded. By default, it returns ir_version.

classmethod get_opsets(opsets)[source]#

Updates the opsets for a given backend. This method should be overloaded. By default, it returns opsets.

property key: Any#

Unique key for a tensor of the same type.

property ndim#

Returns the number of dimensions (rank).

numpy()[source]#

Returns the array converted into a numpy array.

property shape: Tuple[int, ...]#

Returns the shape of the tensor.

property tensor_type: TensorType#

Returns the tensor type of this tensor.

property tensor_type_dims: TensorType#

Returns the tensor type of this tensor. This property is used to define a key used to cache a jitted function. Same keys keys means same ONNX graph. Different keys usually means same ONNX graph but different input shapes.

property value: ndarray#

Returns the value of this tensor as a numpy array.