npx.npx_var#

Var#

class onnx_array_api.npx.npx_var.Var(*inputs: List[Any], op: Callable | str | Tuple[str, str] | FunctionProto | ModelProto | NodeProto | None = None, dtype: type | DType | None = None, inline: bool = False, n_var_outputs: int = 1, input_indices: List[int] | None = None, **kwargs)[source]#

Defines a variable, a result…

Parameters:
  • inputs – list of inputs

  • op – apply on operator on the inputs

  • inline – True to reduce the use of function and inline small functions, this only applies if op is a function

  • n_var_outputs – number of the operator outputs

  • input_indices – to select a specific output from the input operator

  • kwargs – operator attributes

Private attribute:

Parameters:

onnx_input_type – names given to the variables

property T: Var#

Transpose.

property annotation#

Returns a type if known for the Var itself.

astype(dtype) Var[source]#

Cast

copy() Var[source]#

Returns a copy of self (use of Identity node).

flatten() Var[source]#

Flattens a matrix (see numpy.ndarray.flatten()).

Parameters:

axis – only flatten from axis to the end.

Returns:

Var

get(index: int) Var[source]#

If an operator or a function returns more than one output, this takes only one.

Parameters:

index – index of the output to select

Returns:

Var

property is_function#

Tells if this variable encapsulate a function.

max(axis: TensorType_I__DT7 | None = None, keepdims: ParTypeint = 0) Var[source]#

See numpy.max().

mean(axis: OptParTypeTupleType_int | None = None, keepdims: ParTypeint = 0) Var[source]#

See numpy.mean().

min(axis: TensorType_I__DT7 | None = None, keepdims: ParTypeint = 0) Var[source]#

See numpy.min().

prod(axis: TensorType_I__DT7 | None = None, keepdims: ParTypeint = 0) Var[source]#

See numpy.prod().

reduce_function(reduce_op, axis: OptTensorType_I__DT7 | None = None, keepdims: ParTypeint = 0) Var[source]#

See numpy.sum() or any other reduce function.

replace_inputs(new_inputs: List[Var], input_indices: List[int] | None = None) Var[source]#

Replaces inputs by new ones. It creates a copy. It is needed when inlining functions.

reshape(shape: Var) Var[source]#

Reshape

property self_var#

Returns itself or the variable corresponding to its state after a call to __setitem__.

set_onnx_name(prefix: str)[source]#

Forces this variable to get this name during

Parameters:

prefix – prefix

property shape: Var#

Shape

sum(axis: TensorType_I__DT7 | None = None, keepdims: ParTypeint = 0) Var[source]#

See numpy.sum().

to_onnx(target_opsets: Dict[str, int] | None = None, as_function: bool = False, name: str | None = None, domain: str | None = None, attributes: List[str] | None = None, constraints: Dict[Any, TensorType] | None = None, ir_version: int | None = None) ModelProto | FunctionProto | List[Any][source]#

Converts the recursive graph to ONNX.

Parameters:
  • target_opsets – dictionary {opset: version}

  • as_function – conversion to onnx.FunctionProto or onnx.ModelProto

  • name – function name if as_function is True

  • domain – function domain if as_function is True

  • attributes – function attributes if any

  • constraints – specifies a precise type for the type constraints when a function allows more than one type, this works if there is only one variable to be converted

Returns:

ModelProto, FunctionProto

Cst, Input#

class onnx_array_api.npx.npx_var.Cst(cst: Any)[source]#

Defines a constant.

class onnx_array_api.npx.npx_var.Input(name: str | None = None, annotation: type | None = None)[source]#

Defines an input, a placeholder.

Parameters:
  • name – input name or None if undefined

  • annotation – annotation if any is available

property annotation#

Returns a type if known for the Var itself.

ManyIdentity#

class onnx_array_api.npx.npx_var.ManyIdentity(*inputs, input_indices=None)[source]#

Holds several instances of Var.

to_onnx(target_opsets: Dict[str, int] | None = None, as_function: bool = False, name: str | None = None, domain: str | None = None, attributes: List[str] | None = None, constraints: Dict[Any, TensorType] | None = None, ir_version: int | None = None) ModelProto | FunctionProto | List[Any][source]#

Converts the recursive graph to ONNX.

Parameters:
  • target_opsets – dictionary {opset: version}, if None, it is replaced by DEFAULT_OPSETS

  • as_function – conversion to onnx.FunctionProto or onnx.ModelProto

  • name – function name if as_function is True

  • domain – function domain if as_function is True

  • attributes – function attributes if any

  • constraints – specifies a precise type for the type constraints when a function allows more than one type, this works if there is only one variable to be converted

Returns:

ModelProto, FunctionProto

Par#

class onnx_array_api.npx.npx_var.Par(name: str, dtype: ParType, value: Any | None = None, parent_op: Tuple[str, str, int] | None = None)[source]#

Defines a named parameter.

Parameters:
  • name – parameter name

  • dtype – parameter type (bool, int, str, float)

  • value – value of the parameter if known

  • parent_op – node type it belongs to

property onnx_type#

Returns the corresponding onnx type.