yobx.builder.light – Variables#

class yobx.builder.light._var.BaseVar(parent: OnnxGraph)[source]#

Base class for Var and Vars.

Parameters:

parent – the OnnxGraph that owns this variable

bring(*vars: Any) Var | Vars[source]#

Combines variables into a Vars (or a single Var).

Parameters:

vars – variable names or Var instances

Returns:

Var or Vars

cst(value: ndarray, name: str | None = None) Var[source]#

Adds a constant initializer.

Parameters:
  • value – constant numpy array

  • name – optional name

Returns:

Var

left_bring(*vars: Any) Vars[source]#

Creates Vars with *vars first, then self.

make_node(op_type: str, *inputs: Any, domain: str = '', n_outputs: int = 1, output_names: List[str] | None = None, **kwargs: Any) Var | Vars[source]#

Creates a node using inputs and returns the resulting Var (single output) or Vars (multiple outputs).

Parameters:
  • op_type – operator type

  • inputs – input Var instances or numpy arrays

  • domain – operator domain

  • n_outputs – number of output tensors

  • output_names – explicit output names

  • kwargs – operator attributes

Returns:

Var or Vars

right_bring(*vars: Any) Vars[source]#

Creates Vars with self first, then *vars.

to_onnx()[source]#

Delegates to the parent graph’s OnnxGraph.to_onnx().

v(name: str) Var[source]#

Retrieves a variable by name from the parent graph.

Parameters:

name – variable name

Returns:

Var

vin(name: str, elem_type: int = 1, shape: Any | None = None) Var[source]#

Declares a new graph input.

Parameters:
  • name – input name

  • elem_type – ONNX element type integer

  • shape – optional shape

Returns:

Var

vout(**kwargs: Dict[str, Any]) Var | Vars[source]#

Declare outputs - must be overridden in subclasses.

class yobx.builder.light.Var(parent: OnnxGraph, name: str, elem_type: int | None = 1, shape: Any | None = None)[source]#

Represents a single ONNX variable (input, constant, node output, or graph output).

Parameters:
  • parent – the owning OnnxGraph

  • name – variable name

  • elem_type – ONNX element type integer (default: TensorProto.FLOAT)

  • shape – optional shape tuple

astype(to: int) Var[source]#

Casts to another ONNX element type (alias for to()).

property name: str#

Returns the current (possibly renamed) name.

rename(new_name: str) Var[source]#

Renames this variable.

Parameters:

new_name – new name

Returns:

self (the variable now answers to the new name)

reshape(new_shape: Any) Var[source]#

Reshapes the variable.

to(to: int) Var[source]#

Casts to another ONNX element type.

vout(elem_type: int = 1, shape: Any | None = None) Var[source]#

Declares this variable as a graph output.

Parameters:
  • elem_type – ONNX element type integer

  • shape – optional shape

Returns:

self

class yobx.builder.light.Vars(parent: OnnxGraph, *vars: Any)[source]#

Represents a tuple of Var instances to feed into a multi-input operator.

Parameters:
  • parent – the owning OnnxGraph

  • varsVar instances or variable names

rename(*new_names: str) Vars[source]#

Renames each variable.

Parameters:

new_names – one new name per variable

Returns:

self

vout(elem_type: int = 1, shape: Any | None = None) Vars[source]#

Declares all variables as graph outputs.

Parameters:
  • elem_type – ONNX element type integer

  • shape – optional shape (applied to all outputs)

Returns:

self